Skip to content

Commit cc31026

Browse files
committed
RFC/chore(Algebra/GCDMonoid): should we un-@[simp] normalize_apply? (#18006)
The lemma `normalize_apply` feels to me like it exposes the implementation detail that `normalize` is defined in terms of `normUnit`. I think the `normalize` function itself is much more familiar so it doesn't really seem like a simplification to insert `normUnit` instead. Indeed there are quite a few `simp [-normalize_apply]` in Mathlib. Moreover, there were some `simp` lemmas about `normalize` that had to be given higher priority since e.g. `normalize (a * b) = normalize a * normalize b` but `normUnit (a * b)` does not necessarily equal `normUnit a * normUnit b`. A few downstream fixes are needed where a `@[simp]` lemma is proved for `normUnit` and not for `normalize`, otherwise everything goes very smoothly.
1 parent 8b008cb commit cc31026

File tree

4 files changed

+19
-24
lines changed

4 files changed

+19
-24
lines changed

Mathlib/Algebra/GCDMonoid/Basic.lean

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -116,21 +116,16 @@ theorem normalize_associated_iff {x y : α} : Associated (normalize x) y ↔ Ass
116116
theorem Associates.mk_normalize (x : α) : Associates.mk (normalize x) = Associates.mk x :=
117117
Associates.mk_eq_mk_iff_associated.2 (normalize_associated _)
118118

119-
@[simp]
120119
theorem normalize_apply (x : α) : normalize x = x * normUnit x :=
121120
rfl
122121

123-
-- Porting note (#10618): `simp` can prove this
124-
-- @[simp]
125122
theorem normalize_zero : normalize (0 : α) = 0 :=
126123
normalize.map_zero
127124

128-
-- Porting note (#10618): `simp` can prove this
129-
-- @[simp]
130125
theorem normalize_one : normalize (1 : α) = 1 :=
131126
normalize.map_one
132127

133-
theorem normalize_coe_units (u : αˣ) : normalize (u : α) = 1 := by simp
128+
theorem normalize_coe_units (u : αˣ) : normalize (u : α) = 1 := by simp [normalize_apply]
134129

135130
theorem normalize_eq_zero {x : α} : normalize x = 0 ↔ x = 0 :=
136131
fun hx => (associated_zero_iff_eq_zero x).1 <| hx ▸ associated_normalize _, by
@@ -147,7 +142,8 @@ theorem normUnit_mul_normUnit (a : α) : normUnit (a * normUnit a) = 1 := by
147142
· rw [normUnit_zero, zero_mul, normUnit_zero]
148143
· rw [normUnit_mul h (Units.ne_zero _), normUnit_coe_units, mul_inv_eq_one]
149144

150-
theorem normalize_idem (x : α) : normalize (normalize x) = normalize x := by simp
145+
@[simp]
146+
theorem normalize_idem (x : α) : normalize (normalize x) = normalize x := by simp [normalize_apply]
151147

152148
theorem normalize_eq_normalize {a b : α} (hab : a ∣ b) (hba : b ∣ a) :
153149
normalize a = normalize b := by
@@ -173,11 +169,11 @@ theorem Associated.eq_of_normalized
173169
a = b :=
174170
dvd_antisymm_of_normalize_eq ha hb h.dvd h.dvd'
175171

176-
--can be proven by simp
172+
@[simp]
177173
theorem dvd_normalize_iff {a b : α} : a ∣ normalize b ↔ a ∣ b :=
178174
Units.dvd_mul_right
179175

180-
--can be proven by simp
176+
@[simp]
181177
theorem normalize_dvd_iff {a b : α} : normalize a ∣ b ↔ a ∣ b :=
182178
Units.mul_right_dvd
183179

@@ -216,8 +212,7 @@ theorem out_dvd_iff (a : α) (b : Associates α) : b.out ∣ a ↔ b ≤ Associa
216212
theorem out_top : (⊤ : Associates α).out = 0 :=
217213
normalize_zero
218214

219-
-- Porting note: lower priority to avoid linter complaints about simp-normal form
220-
@[simp 1100]
215+
@[simp]
221216
theorem normalize_out (a : Associates α) : normalize a.out = a.out :=
222217
Quotient.inductionOn a normalize_idem
223218

@@ -287,8 +282,7 @@ theorem gcd_isUnit_iff_isRelPrime [GCDMonoid α] {a b : α} :
287282
IsUnit (gcd a b) ↔ IsRelPrime a b :=
288283
fun h _ ha hb ↦ isUnit_of_dvd_unit (dvd_gcd ha hb) h, (· (gcd_dvd_left a b) (gcd_dvd_right a b))⟩
289284

290-
-- Porting note: lower priority to avoid linter complaints about simp-normal form
291-
@[simp 1100]
285+
@[simp]
292286
theorem normalize_gcd [NormalizedGCDMonoid α] : ∀ a b : α, normalize (gcd a b) = gcd a b :=
293287
NormalizedGCDMonoid.normalize_gcd
294288

@@ -399,7 +393,7 @@ theorem gcd_mul_left [NormalizedGCDMonoid α] (a b c : α) :
399393
gcd (a * b) (a * c) = normalize a * gcd b c :=
400394
(by_cases (by rintro rfl; simp only [zero_mul, gcd_zero_left, normalize_zero]))
401395
fun ha : a ≠ 0 =>
402-
suffices gcd (a * b) (a * c) = normalize (a * gcd b c) by simpa [- normalize_apply]
396+
suffices gcd (a * b) (a * c) = normalize (a * gcd b c) by simpa
403397
let ⟨d, eq⟩ := dvd_gcd (dvd_mul_right a b) (dvd_mul_right a c)
404398
gcd_eq_normalize
405399
(eq.symm ▸ mul_dvd_mul_left a
@@ -689,8 +683,7 @@ theorem lcm_eq_zero_iff [GCDMonoid α] (a b : α) : lcm a b = 0 ↔ a = 0 ∨ b
689683
rwa [← mul_eq_zero, ← associated_zero_iff_eq_zero])
690684
(by rintro (rfl | rfl) <;> [apply lcm_zero_left; apply lcm_zero_right])
691685

692-
-- Porting note: lower priority to avoid linter complaints about simp-normal form
693-
@[simp 1100]
686+
@[simp]
694687
theorem normalize_lcm [NormalizedGCDMonoid α] (a b : α) : normalize (lcm a b) = lcm a b :=
695688
NormalizedGCDMonoid.normalize_lcm a b
696689

@@ -766,7 +759,7 @@ theorem lcm_mul_left [NormalizedGCDMonoid α] (a b c : α) :
766759
lcm (a * b) (a * c) = normalize a * lcm b c :=
767760
(by_cases (by rintro rfl; simp only [zero_mul, lcm_zero_left, normalize_zero]))
768761
fun ha : a ≠ 0 =>
769-
suffices lcm (a * b) (a * c) = normalize (a * lcm b c) by simpa [- normalize_apply]
762+
suffices lcm (a * b) (a * c) = normalize (a * lcm b c) by simpa
770763
have : a ∣ lcm (a * b) (a * c) := (dvd_mul_right _ _).trans (dvd_lcm_left _ _)
771764
let ⟨_, eq⟩ := this
772765
lcm_eq_normalize
@@ -866,8 +859,7 @@ instance subsingleton_normalizedGCDMonoid_of_unique_units : Subsingleton (Normal
866859
theorem normUnit_eq_one (x : α) : normUnit x = 1 :=
867860
rfl
868861

869-
-- Porting note (#10618): `simp` can prove this
870-
-- @[simp]
862+
@[simp]
871863
theorem normalize_eq (x : α) : normalize x = x :=
872864
mul_one x
873865

Mathlib/Algebra/GCDMonoid/Nat.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ theorem normalize_coe_nat (n : ℕ) : normalize (n : ℤ) = n :=
7979

8080
theorem abs_eq_normalize (z : ℤ) : |z| = normalize z := by
8181
cases le_total 0 z <;>
82-
simp [-normalize_apply, abs_of_nonneg, abs_of_nonpos, normalize_of_nonneg, normalize_of_nonpos, *]
82+
simp [abs_of_nonneg, abs_of_nonpos, normalize_of_nonneg, normalize_of_nonpos, *]
8383

8484
theorem nonneg_of_normalize_eq_self {z : ℤ} (hz : normalize z = z) : 0 ≤ z := by
8585
by_cases h : 0 ≤ z
@@ -147,7 +147,7 @@ def associatesIntEquivNat : Associates ℤ ≃ ℕ := by
147147
refine ⟨(·.out.natAbs), (Associates.mk ·), ?_, fun n ↦ ?_⟩
148148
· refine Associates.forall_associated.2 fun a ↦ ?_
149149
refine Associates.mk_eq_mk_iff_associated.2 <| Associated.symm <| ⟨normUnit a, ?_⟩
150-
simp [Int.abs_eq_normalize]
150+
simp [Int.abs_eq_normalize, normalize_apply]
151151
· dsimp only [Associates.out_mk]
152152
rw [← Int.abs_eq_normalize, Int.natAbs_abs, Int.natAbs_ofNat]
153153

Mathlib/Algebra/Polynomial/FieldDivision.lean

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,9 @@ instance instNormalizationMonoid : NormalizationMonoid R[X] where
195195
theorem coe_normUnit {p : R[X]} : (normUnit p : R[X]) = C ↑(normUnit p.leadingCoeff) := by
196196
simp [normUnit]
197197

198+
@[simp]
198199
theorem leadingCoeff_normalize (p : R[X]) :
199-
leadingCoeff (normalize p) = normalize (leadingCoeff p) := by simp
200+
leadingCoeff (normalize p) = normalize (leadingCoeff p) := by simp [normalize_apply]
200201

201202
theorem Monic.normalize_eq_self {p : R[X]} (hp : p.Monic) : normalize p = p := by
202203
simp only [Polynomial.coe_normUnit, normalize_apply, hp.leadingCoeff, normUnit_one,
@@ -536,7 +537,9 @@ theorem map_dvd_map' [Field k] (f : R →+* k) {x y : R[X]} : x.map f ∣ y.map
536537
leadingCoeff_map, ← map_inv₀ f, ← map_C, ← Polynomial.map_mul,
537538
map_dvd_map _ f.injective (monic_mul_leadingCoeff_inv H)]
538539

539-
theorem degree_normalize [DecidableEq R] : degree (normalize p) = degree p := by simp
540+
@[simp]
541+
theorem degree_normalize [DecidableEq R] : degree (normalize p) = degree p := by
542+
simp [normalize_apply]
540543

541544
theorem prime_of_degree_eq_one (hp1 : degree p = 1) : Prime p := by
542545
classical

Mathlib/RingTheory/DedekindDomain/Ideal.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,7 @@ theorem count_span_normalizedFactors_eq_of_normUnit {r X : R}
14291429
(hr : r ≠ 0) (hX₁ : normUnit X = 1) (hX : Prime X) :
14301430
Multiset.count (Ideal.span {X} : Ideal R) (normalizedFactors (Ideal.span {r})) =
14311431
Multiset.count X (normalizedFactors r) := by
1432-
simpa [hX₁] using count_span_normalizedFactors_eq hr hX
1432+
simpa [hX₁, normalize_apply] using count_span_normalizedFactors_eq hr hX
14331433

14341434
end NormalizationMonoid
14351435

0 commit comments

Comments
 (0)