mathlib4 review helperopen PRs by @wwylele on leanprover-community/mathlib4

← queue

#45394 feat(RingTheory/Valuation): equivalence between ValuativeRel and ValuationSubring

blocked-by-other-PR t-ring-theory CI success

+212 −0 · 4 files · 4 commits · head ca14a76 · updated 36 days ago · Files changed on GitHub

PR description

... and propose for future refactoring with the new def ValuativeRel.integer and ValuativeRel.valuationSubring. Based on my understanding, mathlib introduced ValuativeRel because it expresses the equivalences of valuation better, so it should be treated as the more fundamental object, and we should build more API around it without going through Valuation.


The original goal of this was to have a way to write IsLocalRing.ResidueField for a valuative relation without going through the associated Valuation, but I ended up also showing the equivalence.

Related discussion: #Is there code for X? > maximal valued fields

Conversation on GitHub 6
github-actions[bot] · comment · 2026-10-27
PR summary ca14a76362
Import changes for modified files

No significant changes to the import graph

<details><summary>Import changes for all files</summary>

|Files|Import difference| |-|-| | Mathlib.RingTheory.Valuation.ValuativeRel.Integer (new file)|1325| | Mathlib.RingTheory.Valuation.ValuativeRel.ValuationSubring (new file)|2003|

</details>


<details><summary>

Declarations diff (regex)

</summary>

+ equivValuationSubring + integer + integer_eq_valuationInteger + mem_integer_iff + mem_valuationSubring_iff + neg_veq_iff + neg_veq_self + neg_vle_iff + neg_vle_self + neg_vlt_iff + ofValuationSubring + ofValuationSubring.vle_def + ofValuationSubring.vle_iff_exists + ofValuation_valuationSubringValuation_eq_ofValuationSubring + self_vle_neg + valuationInteger_valuation_eq_integer + valuationSubring + valuationSubring_eq_valuationValuationSubring + valuationValuationSubring_valuation_eq_valuationSubring + veq_neg_iff + vle_neg_iff + vle_one_or_inv_vle_one + vle_one_or_inv_vlt_one + vlt_neg_iff <details> <summary>You can run this locally as follows</summary>

## from your `mathlib4` directory:
git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci

## summary with just the declaration names:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh <optional_commit>

## more verbose report:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh long <optional_commit>

</details>

The doc-module for scripts/pr_summary/declarations_diff.sh in the undefined repository contains some details about this script.

</details>

<details><summary>

Declarations diff (Lean)

</summary>

✅ Lean-aware diff — post-build, computed from the Lean environment (commit ca14a76).

  • +26 new declarations
  • −0 removed declarations
+ValuativeRel.equivValuationSubring
+ValuativeRel.equivValuationSubring_apply
+ValuativeRel.equivValuationSubring_symm_apply
+ValuativeRel.integer
+ValuativeRel.integer_eq_valuationInteger
+ValuativeRel.mem_integer_iff
+ValuativeRel.mem_valuationSubring_iff
+ValuativeRel.neg_veq_iff
+ValuativeRel.neg_veq_self
+ValuativeRel.neg_vle_iff
+ValuativeRel.neg_vle_self
+ValuativeRel.neg_vlt_iff
+ValuativeRel.ofValuationSubring
+ValuativeRel.ofValuationSubring.vle_def
+ValuativeRel.ofValuationSubring.vle_iff_exists
+ValuativeRel.ofValuation_valuationSubringValuation_eq_ofValuationSubring
+ValuativeRel.self_vle_neg
+ValuativeRel.valuationInteger_valuation_eq_integer
+ValuativeRel.valuationSubring
+ValuativeRel.valuationSubring_eq_valuationValuationSubring
+ValuativeRel.valuationValuationSubring_valuation_eq_valuationSubring
+ValuativeRel.veq_neg_iff
+ValuativeRel.vle_neg_iff
+ValuativeRel.vle_one_or_inv_vle_one
+ValuativeRel.vle_one_or_inv_vlt_one
+ValuativeRel.vlt_neg_iff

</details>


No changes to strong technical debt. No changes to weak technical debt.

Current commit ca14a76362 Reference commit 0d3fb85496

This script lives in the undefined repository. To run it locally, from your mathlib4 directory:

git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci
../mathlib-ci/scripts/reporting/technical-debt-metrics.py pr_summary
  • The relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).
copilot-pull-request-reviewer[bot] · commented · 2026-10-27
🟢 Approval recommended

No active review issues block approval of the correspondence between valuative relations and valuation subrings.

No open issues 🎉

<details> <summary><strong>What changed in this PR</strong></summary>

Adds a direct correspondence between valuative relations and valuation subrings over a field, supporting access to residue fields without first constructing an associated valuation.

Changes:

  • Defines integer subrings and valuation subrings directly from valuative relations.
  • Constructs the inverse relation from a valuation subring and proves the equivalence.
  • Adds supporting negation and inverse comparison lemmas and exports the new module.

| File | Description | | ---- | ----------- | | Mathlib/​RingTheory/​Valuation/​ValuativeRel/​ValuationSubring.lean | Defines the subring constructions and proves their compatibility with valuations and the equivalence. | | Mathlib/​RingTheory/​Valuation/​ValuativeRel/​Basic.lean | Adds negation and inverse comparison lemmas used by the constructions. | | Mathlib.lean | Imports the new module into the library-wide entry point. | </details>

<sub>Review effort: Balanced</sub>

copilot-pull-request-reviewer[bot] · commented · 2026-10-28
🟡 Changes recommended

An active review finding identifies a typo on line 18 of ValuationSubring.lean: “Further more” should be “Furthermore.”

<details open> <summary><strong>1 open issue</strong></summary>

</details>

<sub>Review effort: Balanced</sub>

Copilot · on Mathlib/RingTheory/Valuation/ValuativeRel/ValuationSubring.lean:18 (outdated) · 2026-10-28

“Further more” should be written as the single word “Furthermore.”

wwylele · comment · 2026-10-31

After trying some proposed refactor myself, I understand that this is a more radical change that I thought. The new Valuative.integer is not defeq to the existing one, and consequently 𝒪[R] (seen as a type), 𝓂[R] and 𝓀[R] are downgraded from defeq to their Valued counterparts to mere equivalence, so a lot of downstream lemma needs a rewrite. I still hold the opinion that this refactor is good given we want to get rid of Valued, but I am good with parking this for a while if the direction is not very clear yet. Meanwhile I am going to extract some less controversial lemma into separate PR

mathlib-dependent-issues[bot] · comment · 2026-10-31

This PR/issue depends on:

  • leanprover-community/mathlib4#45537

By Dependent Issues (🤖). Happy coding!

Mathlib.lean +2 −0

public import Mathlib.RingTheory.Valuation.RankOne
7439public import Mathlib.RingTheory.Valuation.ValuationRing
7440public import Mathlib.RingTheory.Valuation.ValuationSubring
7441public import Mathlib.RingTheory.Valuation.ValuativeRel.Basic
7442public import Mathlib.RingTheory.Valuation.ValuativeRel.Integer
7443public import Mathlib.RingTheory.Valuation.ValuativeRel.Trivial
7444public import Mathlib.RingTheory.Valuation.ValuativeRel.ValuationSubring
7445public import Mathlib.RingTheory.WittVector.Basic
7446public import Mathlib.RingTheory.WittVector.Compare
7447public import Mathlib.RingTheory.WittVector.Complete

Mathlib/RingTheory/Valuation/ValuativeRel/Basic.lean +47 −0

theorem vle_add_cases (x y : R) : x + y ≤ᵥ x ∨ x + y ≤ᵥ y :=
295 grw [show (0 : R) = x * 0 by simp, veq_mul_comm, veq_mul_comm x] at hy
296 exact vle_mul_cancel hx hy
298section Ring
300variable {R : Type*} [Ring R] [ValuativeRel R]
lemma neg_vle_self newL302–305
302lemma neg_vle_self (x : R) : -x ≤ᵥ x := by
303 rcases vle_total (-x) x with h | h
304 · exact h
305 · simpa using mul_vle_mul_left h (-1)
lemma self_vle_neg newL307–307
307lemma self_vle_neg (x : R) : x ≤ᵥ -x := by simpa using neg_vle_self (-x)
lemma neg_veq_self newL309–309
309lemma neg_veq_self (x : R) : -x =ᵥ x := ⟨neg_vle_self x, self_vle_neg x⟩
lemma neg_vle_iff newL311–314
311@[simp]
312lemma neg_vle_iff {x y : R} : -x ≤ᵥ y ↔ x ≤ᵥ y where
vihdzp · 2026-10-28

Can we have these for vlt and veq too? I've been using these on the CGT repo for a while, I wasn't aware they were more general theorems on valued rings...

313 mp h := vle_trans (self_vle_neg x) h
314 mpr h := vle_trans (neg_vle_self x) h
lemma vle_neg_iff newL316–319
316@[simp]
317lemma vle_neg_iff {x y : R} : x ≤ᵥ -y ↔ x ≤ᵥ y where
318 mp h := vle_trans h (neg_vle_self y)
319 mpr h := vle_trans h (self_vle_neg y)
lemma neg_vlt_iff newL321–322
321@[simp]
322lemma neg_vlt_iff {x y : R} : -x <ᵥ y ↔ x <ᵥ y := by simp [← not_vle]
lemma vlt_neg_iff newL324–325
324@[simp]
325lemma vlt_neg_iff {x y : R} : x <ᵥ -y ↔ x <ᵥ y := by simp [← not_vle]
lemma neg_veq_iff newL327–328
327@[simp]
328lemma neg_veq_iff {x y : R} : -x =ᵥ y ↔ x =ᵥ y := by simp [veq_def]
lemma veq_neg_iff newL330–331
330@[simp]
331lemma veq_neg_iff {x y : R} : x =ᵥ -y ↔ x =ᵥ y := by simp [veq_def]
333end Ring
335variable (R) in
336/-- The submonoid of elements `x : R` whose valuation is positive. -/
337def posSubmonoid : Submonoid R where
lemma inv_vlt_one (hx : x ≠ 0) : x⁻¹ <ᵥ 1 ↔ 1 <ᵥ x :=
960lemma one_vlt_inv (hx : x ≠ 0) : 1 <ᵥ x⁻¹ ↔ x <ᵥ 1 :=
961 (inv_vle_one hx).not
lemma vle_one_or_inv_vlt_one newL963–966
963lemma vle_one_or_inv_vlt_one : x ≤ᵥ 1 ∨ x⁻¹ <ᵥ 1 := by
964 by_cases h : x = 0
965 · simp [h]
966 · simp [or_iff_not_imp_right, one_vle_inv h]
lemma vle_one_or_inv_vle_one newL968–971
968lemma vle_one_or_inv_vle_one : x ≤ᵥ 1 ∨ x⁻¹ ≤ᵥ 1 := by
969 by_cases h : x = 0
970 · simp [h]
971 · simpa [inv_vle_one h] using vle_total x 1
973end DivisionRing
975open NNReal in variable (R) in

Mathlib/RingTheory/Valuation/ValuativeRel/Integer.lean +52 −0 new file

1/-
2Copyright (c) 2026 Weiyi Wang. All rights reserved.
3Released under Apache 2.0 license as described in the file LICENSE.
4Authors: Weiyi Wang
5-/
6
7module
8
9public import Mathlib.RingTheory.Valuation.Integers
10public import Mathlib.RingTheory.Valuation.ValuativeRel.Basic
12/-!
13# Integers of valuative relations
15This file introduces `ValuativeRel.integer` analog to `Valuation.integer`, the subring of elements
16valuatively less or equal to 1.
18TODO: existing usage of `(ValuativeRel.valuation R).integer` should be converted to
19`ValuativeRel.integer R`, including those under notations `𝒪[K]` and such.
20-/
22public section
24namespace ValuativeRel
25variable {R : Type*} [Ring R] [ValuativeRel R]
27variable (R) in
def integer newL28–37
28/-- The ring of integers under a given `ValuativeRel` is the subring of elements valuatively
29less or equal to 1. -/
30@[expose]
31def integer : Subring R where
32 carrier := { x | x ≤ᵥ 1 }
33 one_mem' := by simp
34 mul_mem' {x y} hx hy := by simpa using mul_vle_mul hx hy
35 zero_mem' := by simp
36 add_mem' {x y} hx hy := vle_add hx hy
37 neg_mem' {x} hx := by simpa using hx
theorem mem_integer_iff newL39–39
39theorem mem_integer_iff {x : R} : x ∈ integer R ↔ x ≤ᵥ 1 := by rfl
theorem integer_eq_valuationInteger newL41–45
41theorem integer_eq_valuationInteger {Γ₀ : Type*} [LinearOrderedCommGroupWithZero Γ₀]
42 (v : Valuation R Γ₀) [v.Compatible] :
43 integer R = v.integer := by
44 ext x
45 simp [mem_integer_iff, v.mem_integer_iff, v.vle_iff_le]
47variable (R) in
theorem valuationInteger_valuation_eq_integer newL48–50
48@[simp]
49theorem valuationInteger_valuation_eq_integer : (ValuativeRel.valuation R).integer = integer R :=
50 (integer_eq_valuationInteger (ValuativeRel.valuation R)).symm
52end ValuativeRel

Mathlib/RingTheory/Valuation/ValuativeRel/ValuationSubring.lean +111 −0 new file

1/-
2Copyright (c) 2026 Weiyi Wang. All rights reserved.
3Released under Apache 2.0 license as described in the file LICENSE.
4Authors: Weiyi Wang
5-/
6
7module
8
9public import Mathlib.RingTheory.Valuation.ValuationSubring
vihdzp · 2026-10-28

Is this a heavy enough import that it doesn't make sense to put both in the same file?

wwylele · 2026-10-28

The split was just following the existing the file structure in Valuation. I noticed that downstream files that only cares about rings only imports Valuation.Integers, so I anticipate that it will also only import ValuativeRel.Integers after the refactoring.

10public import Mathlib.RingTheory.Valuation.ValuativeRel.Integer
12/-!
13# Valuation subrings and valuative relations
15This file introduces `ValuativeRel.valuationSubring` analog to `Valuation.valuationSubring`. It
16upgrades `ValuativeRel.integer` to a `ValuationSubring` for fields.
18Furthermore, we show that the type `ValuativeRel R` and the type `ValuationSubring R` are
19equivalent at `ValuativeRel.equivValuationSubring`.
20-/
22public section
24namespace ValuativeRel
25variable {K : Type*} [Field K] [ValuativeRel K]
27variable (K) in
def valuationSubring newL28–33
28/-- The valuation subring associated to a `ValuativeRel`, consisting of elements valuatively
29less or equal to 1. -/
30@[expose]
31def valuationSubring : ValuationSubring K where
32 __ := integer K
33 mem_or_inv_mem' x := by simpa [mem_integer_iff] using vle_one_or_inv_vle_one
theorem mem_valuationSubring_iff newL35–35
35theorem mem_valuationSubring_iff {x : K} : x ∈ valuationSubring K ↔ x ≤ᵥ 1 := by rfl
theorem valuationSubring_eq_valuationValuationSubring newL37–41
37theorem valuationSubring_eq_valuationValuationSubring {Γ₀ : Type*}
38 [LinearOrderedCommGroupWithZero Γ₀] (v : Valuation K Γ₀) [v.Compatible] :
39 valuationSubring K = v.valuationSubring := by
40 ext x
41 simp [mem_valuationSubring_iff, v.mem_valuationSubring_iff, v.vle_iff_le]
43variable (K) in
theorem valuationValuationSubring_valuation_eq_valuationSubring newL44–47
44@[simp]
45theorem valuationValuationSubring_valuation_eq_valuationSubring :
46 (ValuativeRel.valuation K).valuationSubring = valuationSubring K :=
47 (valuationSubring_eq_valuationValuationSubring (ValuativeRel.valuation K)).symm
def ofValuationSubring newL49–74
49/-- The `ValuativeRel` induced by a valuation subring. -/
50@[instance_reducible, expose]
51def ofValuationSubring (r : ValuationSubring K) : ValuativeRel K where
52 vle x y := x = 0 ∨ y ≠ 0 ∧ x / y ∈ r
53 vle_total x y := by
54 by_cases hx : x = 0
55 · simp [hx]
56 by_cases hy : y = 0
57 · simp [hy]
58 simpa [hx, hy] using r.mem_or_inv_mem (x / y)
59 vle_trans {z y x} hxy hyz := by
60 rcases hxy with hxy | hxy
61 · simp [hxy]
62 rcases hyz with hyz | hyz
63 · simp [hxy.1] at hyz
64 · simp [(div_mul_div_cancel₀ hxy.1) ▸ (mul_mem hxy.2 hyz.2), hyz.1]
65 vle_add {x y z} hxy hyz := by aesop (add simp [add_div])
66 mul_vle_mul_left {x y} hxy z := by
67 by_cases h : z = 0
68 · simp [h]
69 · simpa [mul_div_mul_right _ _ h, h] using hxy
70 vle_mul_cancel {x y z} hz hxy := by
71 have h : z ≠ 0 := by simpa using hz
72 simpa [mul_div_mul_right _ _ h, h] using hxy
73 not_vle_one_zero := by simp
74 vle_mul_comm {x y} := by by_cases h : x * y = 0 <;> simp [h, mul_comm y x]
76omit [ValuativeRel K] in
theorem ofValuationSubring.vle_def newL77–80
77theorem ofValuationSubring.vle_def (r : ValuationSubring K) {x y : K} :
78 letI := ofValuationSubring r
79 x ≤ᵥ y ↔ x = 0 ∨ y ≠ 0 ∧ x / y ∈ r := by
80 rfl
82omit [ValuativeRel K] in
theorem ofValuationSubring.vle_iff_exists newL83–86
83theorem ofValuationSubring.vle_iff_exists (r : ValuationSubring K) {x y : K} :
84 letI := ofValuationSubring r
85 x ≤ᵥ y ↔ ∃ a ∈ r, a * y = x := by
86 by_cases h : x = 0 <;> aesop (add simp [vle_def])
88omit [ValuativeRel K] in
theorem ofValuation_valuationSubringValuation_eq_ofValuationSubring newL89–95
89@[simp]
90theorem ofValuation_valuationSubringValuation_eq_ofValuationSubring (r : ValuationSubring K) :
91 ofValuation r.valuation = ofValuationSubring r := by
92 ext x y
93 let := ofValuation r.valuation
94 simp [ofValuationSubring.vle_iff_exists, Valuation.vle_iff_le r.valuation,
95 ValuationSubring.valuation_le_iff]
97variable (K) in
def equivValuationSubring newL98–109
98/-- The correspondence between `ValuativeRel` and `ValuationSubring` of a given field. -/
99@[expose, simps]
100def equivValuationSubring : ValuativeRel K ≃ ValuationSubring K where
101 toFun v := valuationSubring K
102 invFun := ofValuationSubring
103 left_inv v := by
104 ext x y
105 by_cases hy : y = 0
106 · simp [ofValuationSubring.vle_def, hy]
107 aesop (add simp [mem_valuationSubring_iff, ofValuationSubring.vle_def, div_vle_one_iff])
108 right_inv r := by
109 aesop (add simp [mem_valuationSubring_iff, ofValuationSubring.vle_def])
111end ValuativeRel
0/24 declarations checked

Your review, as Markdown

Paste it as a comment or a review on the PR. Line links to the head commit unfold into code snippets on GitHub.