Skip to content

Commit a1359d0

Browse files
committed
feat: generalize Mathlib.Algebra.Order + Polynomial (#23153)
This is one of a series of PRs that generalizes type classes across Mathlib. These are generated using a new linter that tries to re-elaborate theorem definitions with more general type classes to see if it succeeds. It will accept the generalization if deleting the entire type class causes the theorem to fail to compile, and the old type class can not simply be re-synthesized with the new declaration. Otherwise, the generalization is rejected as the type class is not being generalized, but can simply be replaced by implicit type class synthesis or an implicit type class in a variable block being pulled in. The linter currently output debug statements indicating source file positions where type classes should be generalized, and a script then makes those edits. This file contains a subset of those generalizations. The linter and the script performing re-writes is available in commit 5e2b704. Also see discussion on Zulip here: https://leanprover.zulipchat.com/#narrow/channel/270676-lean4/topic/Elab.20to.20generalize.20type.20classes.20for.20theorems/near/498862988 https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/Elab.20to.20generalize.20type.20classes.20for.20theorems/near/501288855
1 parent 7618879 commit a1359d0

File tree

20 files changed

+35
-35
lines changed

20 files changed

+35
-35
lines changed

Mathlib/Algebra/Order/AddTorsor.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ instance [CommMonoid G] [PartialOrder G] [IsOrderedMonoid G] : IsOrderedSMul G G
7474
smul_le_smul_right _ _ := mul_le_mul_right'
7575

7676
@[to_additive]
77-
theorem IsOrderedSMul.smul_le_smul [Preorder G] [Preorder P] [SMul G P] [IsOrderedSMul G P]
77+
theorem IsOrderedSMul.smul_le_smul [LE G] [Preorder P] [SMul G P] [IsOrderedSMul G P]
7878
{a b : G} {c d : P} (hab : a ≤ b) (hcd : c ≤ d) : a • c ≤ b • d :=
7979
(IsOrderedSMul.smul_le_smul_left _ _ hcd _).trans (IsOrderedSMul.smul_le_smul_right _ _ hab _)
8080

Mathlib/Algebra/Order/BigOperators/Group/List.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ lemma prod_min_le [LinearOrder M] [MulLeftMono M]
140140
end Monoid
141141

142142
-- TODO: develop theory of tropical rings
143-
lemma sum_le_foldr_max [AddMonoid M] [AddMonoid N] [LinearOrder N] (f : M → N) (h0 : f 00)
143+
lemma sum_le_foldr_max [AddZeroClass M] [Zero N] [LinearOrder N] (f : M → N) (h0 : f 00)
144144
(hadd : ∀ x y, f (x + y) ≤ max (f x) (f y)) (l : List M) : f l.sum ≤ (l.map f).foldr max 0 := by
145145
induction' l with hd tl IH
146146
· simpa using h0

Mathlib/Algebra/Order/Hom/Basic.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,22 +118,22 @@ attribute [simp] apply_nonneg
118118
variable [FunLike F α β]
119119

120120
@[to_additive]
121-
theorem le_map_mul_map_div [Group α] [CommSemigroup β] [LE β] [SubmultiplicativeHomClass F α β]
121+
theorem le_map_mul_map_div [Group α] [CommMagma β] [LE β] [SubmultiplicativeHomClass F α β]
122122
(f : F) (a b : α) : f a ≤ f b * f (a / b) := by
123123
simpa only [mul_comm, div_mul_cancel] using map_mul_le_mul f (a / b) b
124124

125125
@[to_additive existing]
126-
theorem le_map_add_map_div [Group α] [AddCommSemigroup β] [LE β] [MulLEAddHomClass F α β] (f : F)
126+
theorem le_map_add_map_div [Group α] [AddCommMagma β] [LE β] [MulLEAddHomClass F α β] (f : F)
127127
(a b : α) : f a ≤ f b + f (a / b) := by
128128
simpa only [add_comm, div_mul_cancel] using map_mul_le_add f (a / b) b
129129

130130
@[to_additive]
131-
theorem le_map_div_mul_map_div [Group α] [CommSemigroup β] [LE β] [SubmultiplicativeHomClass F α β]
131+
theorem le_map_div_mul_map_div [Group α] [Mul β] [LE β] [SubmultiplicativeHomClass F α β]
132132
(f : F) (a b c : α) : f (a / c) ≤ f (a / b) * f (b / c) := by
133133
simpa only [div_mul_div_cancel] using map_mul_le_mul f (a / b) (b / c)
134134

135135
@[to_additive existing]
136-
theorem le_map_div_add_map_div [Group α] [AddCommSemigroup β] [LE β] [MulLEAddHomClass F α β]
136+
theorem le_map_div_add_map_div [Group α] [Add β] [LE β] [MulLEAddHomClass F α β]
137137
(f : F) (a b c : α) : f (a / c) ≤ f (a / b) + f (b / c) := by
138138
simpa only [div_mul_div_cancel] using map_mul_le_add f (a / b) (b / c)
139139

Mathlib/Algebra/Order/Monoid/Unbundled/Basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,7 @@ theorem Contravariant.MulLECancellable [Mul α] [LE α] [MulLeftReflectLE α]
13441344
fun _ _ => le_of_mul_le_mul_left'
13451345

13461346
@[to_additive (attr := simp)]
1347-
theorem mulLECancellable_one [Monoid α] [LE α] : MulLECancellable (1 : α) := fun a b => by
1347+
theorem mulLECancellable_one [MulOneClass α] [LE α] : MulLECancellable (1 : α) := fun a b => by
13481348
simpa only [one_mul] using id
13491349

13501350
namespace MulLECancellable

Mathlib/Algebra/Order/Ring/Idempotent.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ instance [CommMonoid α] [AddCommMonoid α] :
2323
HasCompl {a : α × α // a.1 * a.2 = 0 ∧ a.1 + a.2 = 1} where
2424
compl a := ⟨(a.1.2, a.1.1), (mul_comm ..).trans a.2.1, (add_comm ..).trans a.2.2
2525

26-
lemma eq_of_mul_eq_add_eq_one [Semiring α] (a : α) {b c : α}
26+
lemma eq_of_mul_eq_add_eq_one [NonAssocSemiring α] (a : α) {b c : α}
2727
(mul : a * b = c * a) (add_ab : a + b = 1) (add_ac : a + c = 1) :
2828
b = c :=
2929
calc b = (a + c) * b := by rw [add_ac, one_mul]

Mathlib/Algebra/Order/Ring/Star.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ example {R : Type*} [OrderedSemiring R] [StarRing R] [StarOrderedRing R] {x y :
3232

3333
/- This will be implied by the instance below, we only prove it to avoid duplicating the
3434
argument in the instance below for `mul_le_mul_of_nonneg_right`. -/
35-
private lemma mul_le_mul_of_nonneg_left {R : Type*} [CommSemiring R] [PartialOrder R]
35+
private lemma mul_le_mul_of_nonneg_left {R : Type*} [NonUnitalCommSemiring R] [PartialOrder R]
3636
[StarRing R] [StarOrderedRing R] {a b c : R} (hab : a ≤ b) (hc : 0 ≤ c) : c * a ≤ c * b := by
3737
rw [StarOrderedRing.nonneg_iff] at hc
3838
induction hc using AddSubmonoid.closure_induction with

Mathlib/Algebra/Order/Ring/Unbundled/Basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ variable {α : Type u} {β : Type*}
124124
`zero_le_one` field. -/
125125

126126

127-
theorem add_one_le_two_mul [LE α] [Semiring α] [AddLeftMono α] {a : α}
127+
theorem add_one_le_two_mul [LE α] [NonAssocSemiring α] [AddLeftMono α] {a : α}
128128
(a1 : 1 ≤ a) : a + 12 * a :=
129129
calc
130130
a + 1 ≤ a + a := add_le_add_left a1 a

Mathlib/Algebra/Order/Sub/Unbundled/Hom.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ theorem le_mul_tsub {R : Type*} [Distrib R] [Preorder R] [Sub R] [OrderedSub R]
2727
[MulLeftMono R] {a b c : R} : a * b - a * c ≤ a * (b - c) :=
2828
(AddHom.mulLeft a).le_map_tsub (monotone_id.const_mul' a) _ _
2929

30-
theorem le_tsub_mul {R : Type*} [CommSemiring R] [Preorder R] [Sub R] [OrderedSub R]
30+
theorem le_tsub_mul {R : Type*} [NonUnitalCommSemiring R] [Preorder R] [Sub R] [OrderedSub R]
3131
[MulLeftMono R] {a b c : R} : a * c - b * c ≤ (a - b) * c := by
3232
simpa only [mul_comm _ c] using le_mul_tsub
3333

@@ -51,7 +51,7 @@ section Preorder
5151
variable [Preorder α]
5252
variable [AddCommMonoid α] [Sub α] [OrderedSub α]
5353

54-
theorem AddMonoidHom.le_map_tsub [Preorder β] [AddCommMonoid β] [Sub β] [OrderedSub β] (f : α →+ β)
54+
theorem AddMonoidHom.le_map_tsub [Preorder β] [AddZeroClass β] [Sub β] [OrderedSub β] (f : α →+ β)
5555
(hf : Monotone f) (a b : α) : f a - f b ≤ f (a - b) :=
5656
f.toAddHom.le_map_tsub hf a b
5757

Mathlib/Algebra/Order/WithTop/Untop0.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ end Zero
5050
## Simplifying Lemmas in cases where α is an AddMonoid
5151
-/
5252
@[simp]
53-
lemma untopD_add [AddMonoid α] {a b : WithTop α} {c : α} (ha : a ≠ ⊤) (hb : b ≠ ⊤) :
53+
lemma untopD_add [Add α] {a b : WithTop α} {c : α} (ha : a ≠ ⊤) (hb : b ≠ ⊤) :
5454
(a + b).untopD c = a.untopD c + b.untopD c := by
5555
lift a to α using ha
5656
lift b to α using hb
5757
simp [← coe_add]
5858

5959
@[simp]
60-
lemma untop₀_add [AddMonoid α] {a b : WithTop α} (ha : a ≠ ⊤) (hb : b ≠ ⊤) :
60+
lemma untop₀_add [AddZeroClass α] {a b : WithTop α} (ha : a ≠ ⊤) (hb : b ≠ ⊤) :
6161
(a + b).untop₀ = a.untop₀ + b.untop₀ := untopD_add ha hb
6262

6363
/-!

Mathlib/Algebra/Polynomial/Basic.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ theorem toFinsupp_pow (a : R[X]) (n : ℕ) : (a ^ n).toFinsupp = a.toFinsupp ^ n
233233
cases a
234234
rw [← ofFinsupp_pow]
235235

236-
theorem _root_.IsSMulRegular.polynomial {S : Type*} [Monoid S] [DistribMulAction S R] {a : S}
236+
theorem _root_.IsSMulRegular.polynomial {S : Type*} [SMulZeroClass S R] {a : S}
237237
(ha : IsSMulRegular R a) : IsSMulRegular R[X] a
238238
| ⟨_x⟩, ⟨_y⟩, h => congr_arg _ <| ha.finsupp (Polynomial.ofFinsupp.inj h)
239239

@@ -725,14 +725,14 @@ theorem addSubmonoid_closure_setOf_eq_monomial :
725725
rintro _ ⟨n, a, rfl⟩
726726
exact ⟨n, a, Polynomial.ofFinsupp_single _ _⟩
727727

728-
theorem addHom_ext {M : Type*} [AddMonoid M] {f g : R[X] →+ M}
728+
theorem addHom_ext {M : Type*} [AddZeroClass M] {f g : R[X] →+ M}
729729
(h : ∀ n a, f (monomial n a) = g (monomial n a)) : f = g :=
730730
AddMonoidHom.eq_of_eqOn_denseM addSubmonoid_closure_setOf_eq_monomial <| by
731731
rintro p ⟨n, a, rfl⟩
732732
exact h n a
733733

734734
@[ext high]
735-
theorem addHom_ext' {M : Type*} [AddMonoid M] {f g : R[X] →+ M}
735+
theorem addHom_ext' {M : Type*} [AddZeroClass M] {f g : R[X] →+ M}
736736
(h : ∀ n, f.comp (monomial n).toAddMonoidHom = g.comp (monomial n).toAddMonoidHom) : f = g :=
737737
addHom_ext fun n => DFunLike.congr_fun (h n)
738738

0 commit comments

Comments
 (0)