Skip to content

Commit aa7a291

Browse files
committed
chore(Algebra/Regular/Basic): generalize to IsCancelMul (#8428)
This lets lemmas about cancellative monoids work for cancellative semigroups Some docstrings have been rewritten, as adjusting the wording was too awkward. The new `.all` names are intended to match `Commute.all`.
1 parent 0cacf07 commit aa7a291

File tree

8 files changed

+51
-62
lines changed

8 files changed

+51
-62
lines changed

Mathlib/Algebra/CovariantAndContravariant.lean

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ relation (typically `(≤)` or `(<)`), these are the only two typeclasses that I
3131
The general approach is to formulate the lemma that you are interested in and prove it, with the
3232
`Ordered[...]` typeclass of your liking. After that, you convert the single typeclass,
3333
say `[OrderedCancelMonoid M]`, into three typeclasses, e.g.
34-
`[LeftCancelSemigroup M] [PartialOrder M] [CovariantClass M M (Function.swap (*)) (≤)]`
34+
`[CancelMonoid M] [PartialOrder M] [CovariantClass M M (Function.swap (*)) (≤)]`
3535
and have a go at seeing if the proof still works!
3636
3737
Note that it is possible to combine several `Co(ntra)variantClass` assumptions together.
@@ -362,27 +362,27 @@ theorem contravariant_le_of_contravariant_eq_and_lt [PartialOrder N]
362362
then the following four instances (actually eight) can be removed in favor of the above two. -/
363363

364364
@[to_additive]
365-
instance LeftCancelSemigroup.covariant_mul_lt_of_covariant_mul_le [LeftCancelSemigroup N]
365+
instance IsLeftCancelMul.covariant_mul_lt_of_covariant_mul_le [Mul N] [IsLeftCancelMul N]
366366
[PartialOrder N] [CovariantClass N N (· * ·) (· ≤ ·)] :
367367
CovariantClass N N (· * ·) (· < ·) where
368368
elim a _ _ bc := (CovariantClass.elim a bc.le).lt_of_ne ((mul_ne_mul_right a).mpr bc.ne)
369369

370370
@[to_additive]
371-
instance RightCancelSemigroup.covariant_swap_mul_lt_of_covariant_swap_mul_le
372-
[RightCancelSemigroup N] [PartialOrder N] [CovariantClass N N (swap (· * ·)) (· ≤ ·)] :
371+
instance IsRightCancelMul.covariant_swap_mul_lt_of_covariant_swap_mul_le
372+
[Mul N] [IsRightCancelMul N] [PartialOrder N] [CovariantClass N N (swap (· * ·)) (· ≤ ·)] :
373373
CovariantClass N N (swap (· * ·)) (· < ·) where
374374
elim a _ _ bc := (CovariantClass.elim a bc.le).lt_of_ne ((mul_ne_mul_left a).mpr bc.ne)
375375

376376
@[to_additive]
377-
instance LeftCancelSemigroup.contravariant_mul_le_of_contravariant_mul_lt [LeftCancelSemigroup N]
377+
instance IsLeftCancelMul.contravariant_mul_le_of_contravariant_mul_lt [Mul N] [IsLeftCancelMul N]
378378
[PartialOrder N] [ContravariantClass N N (· * ·) (· < ·)] :
379379
ContravariantClass N N (· * ·) (· ≤ ·) where
380380
elim := (contravariant_le_iff_contravariant_lt_and_eq N N _).mpr
381381
⟨ContravariantClass.elim, fun _ ↦ mul_left_cancel⟩
382382

383383
@[to_additive]
384-
instance RightCancelSemigroup.contravariant_swap_mul_le_of_contravariant_swap_mul_lt
385-
[RightCancelSemigroup N] [PartialOrder N] [ContravariantClass N N (swap (· * ·)) (· < ·)] :
384+
instance IsRightCancelMul.contravariant_swap_mul_le_of_contravariant_swap_mul_lt
385+
[Mul N] [IsRightCancelMul N] [PartialOrder N] [ContravariantClass N N (swap (· * ·)) (· < ·)] :
386386
ContravariantClass N N (swap (· * ·)) (· ≤ ·) where
387387
elim := (contravariant_le_iff_contravariant_lt_and_eq N N _).mpr
388388
⟨ContravariantClass.elim, fun _ ↦ mul_right_cancel⟩

Mathlib/Algebra/Group/Embedding.lean

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,29 @@ import Mathlib.Logic.Embedding.Basic
1313
-/
1414

1515

16-
variable {R : Type*}
16+
variable {G : Type*}
1717

1818
section LeftOrRightCancelSemigroup
1919

20-
/-- The embedding of a left cancellative semigroup into itself
21-
by left multiplication by a fixed element.
22-
-/
20+
/-- If left-multiplication by any element is cancellative, left-multiplication by `g` is an
21+
embedding. -/
2322
@[to_additive (attr := simps)
24-
"The embedding of a left cancellative additive semigroup into itself
25-
by left translation by a fixed element." ]
26-
def mulLeftEmbedding {G : Type*} [LeftCancelSemigroup G] (g : G) : G ↪ G where
23+
"If left-addition by any element is cancellative, left-addition by `g` is an
24+
embedding."]
25+
def mulLeftEmbedding [Mul G] [IsLeftCancelMul G] (g : G) : G ↪ G where
2726
toFun h := g * h
2827
inj' := mul_right_injective g
2928
#align mul_left_embedding mulLeftEmbedding
3029
#align add_left_embedding addLeftEmbedding
3130
#align add_left_embedding_apply addLeftEmbedding_apply
3231
#align mul_left_embedding_apply mulLeftEmbedding_apply
3332

34-
/-- The embedding of a right cancellative semigroup into itself
35-
by right multiplication by a fixed element.
36-
-/
33+
/-- If right-multiplication by any element is cancellative, right-multiplication by `g` is an
34+
embedding. -/
3735
@[to_additive (attr := simps)
38-
"The embedding of a right cancellative additive semigroup into itself
39-
by right translation by a fixed element."]
40-
def mulRightEmbedding {G : Type*} [RightCancelSemigroup G] (g : G) : G ↪ G where
36+
"If right-addition by any element is cancellative, right-addition by `g` is an
37+
embedding."]
38+
def mulRightEmbedding [Mul G] [IsRightCancelMul G] (g : G) : G ↪ G where
4139
toFun h := h * g
4240
inj' := mul_left_injective g
4341
#align mul_right_embedding mulRightEmbedding
@@ -46,7 +44,7 @@ def mulRightEmbedding {G : Type*} [RightCancelSemigroup G] (g : G) : G ↪ G whe
4644
#align add_right_embedding_apply addRightEmbedding_apply
4745

4846
@[to_additive]
49-
theorem mulLeftEmbedding_eq_mulRightEmbedding {G : Type*} [CancelCommMonoid G] (g : G) :
47+
theorem mulLeftEmbedding_eq_mulRightEmbedding [CommSemigroup G] [IsCancelMul G] (g : G) :
5048
mulLeftEmbedding g = mulRightEmbedding g := by
5149
ext
5250
exact mul_comm _ _

Mathlib/Algebra/MonoidAlgebra/Support.lean

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,21 @@ theorem support_mul [Mul G] [DecidableEq G] (a b : MonoidAlgebra k G) :
7979
Subset.trans support_sum <| biUnion_mono fun _a₂ _ => support_single_subset
8080
#align monoid_algebra.support_mul MonoidAlgebra.support_mul
8181

82-
theorem support_mul_single [RightCancelSemigroup G] (f : MonoidAlgebra k G) (r : k)
82+
theorem support_mul_single [Mul G] [IsRightCancelMul G] (f : MonoidAlgebra k G) (r : k)
8383
(hr : ∀ y, y * r = 0 ↔ y = 0) (x : G) :
8484
(f * single x r).support = f.support.map (mulRightEmbedding x) := by
8585
classical
8686
ext
87-
simp only [support_mul_single_eq_image f hr (isRightRegular_of_rightCancelSemigroup x),
87+
simp only [support_mul_single_eq_image f hr (IsRightRegular.all x),
8888
mem_image, mem_map, mulRightEmbedding_apply]
8989
#align monoid_algebra.support_mul_single MonoidAlgebra.support_mul_single
9090

91-
theorem support_single_mul [LeftCancelSemigroup G] (f : MonoidAlgebra k G) (r : k)
91+
theorem support_single_mul [Mul G] [IsLeftCancelMul G] (f : MonoidAlgebra k G) (r : k)
9292
(hr : ∀ y, r * y = 0 ↔ y = 0) (x : G) :
9393
(single x r * f : MonoidAlgebra k G).support = f.support.map (mulLeftEmbedding x) := by
9494
classical
9595
ext
96-
simp only [support_single_mul_eq_image f hr (isLeftRegular_of_leftCancelSemigroup x), mem_image,
96+
simp only [support_single_mul_eq_image f hr (IsLeftRegular.all x), mem_image,
9797
mem_map, mulLeftEmbedding_apply]
9898
#align monoid_algebra.support_single_mul MonoidAlgebra.support_single_mul
9999

@@ -122,16 +122,16 @@ theorem support_mul [DecidableEq G] [Add G] (a b : k[G]) :
122122
@MonoidAlgebra.support_mul k (Multiplicative G) _ _ _ _ _
123123
#align add_monoid_algebra.support_mul AddMonoidAlgebra.support_mul
124124

125-
theorem support_mul_single [AddRightCancelSemigroup G] (f : k[G]) (r : k)
125+
theorem support_mul_single [Add G] [IsRightCancelAdd G] (f : k[G]) (r : k)
126126
(hr : ∀ y, y * r = 0 ↔ y = 0) (x : G) :
127127
(f * single x r : k[G]).support = f.support.map (addRightEmbedding x) :=
128-
@MonoidAlgebra.support_mul_single k (Multiplicative G) _ _ _ _ hr _
128+
MonoidAlgebra.support_mul_single (G := Multiplicative G) _ _ hr _
129129
#align add_monoid_algebra.support_mul_single AddMonoidAlgebra.support_mul_single
130130

131-
theorem support_single_mul [AddLeftCancelSemigroup G] (f : k[G]) (r : k)
131+
theorem support_single_mul [Add G] [IsLeftCancelAdd G] (f : k[G]) (r : k)
132132
(hr : ∀ y, r * y = 0 ↔ y = 0) (x : G) :
133133
(single x r * f : k[G]).support = f.support.map (addLeftEmbedding x) :=
134-
@MonoidAlgebra.support_single_mul k (Multiplicative G) _ _ _ _ hr _
134+
MonoidAlgebra.support_single_mul (G := Multiplicative G) _ _ hr _
135135
#align add_monoid_algebra.support_single_mul AddMonoidAlgebra.support_single_mul
136136

137137
section Span

Mathlib/Algebra/Order/Group/Defs.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ instance (priority := 100) OrderedCommGroup.toOrderedCancelCommMonoid [OrderedCo
6060
#align ordered_add_comm_group.to_ordered_cancel_add_comm_monoid OrderedAddCommGroup.toOrderedCancelAddCommMonoid
6161

6262
example (α : Type u) [OrderedAddCommGroup α] : CovariantClass α α (swap (· + ·)) (· < ·) :=
63-
AddRightCancelSemigroup.covariant_swap_add_lt_of_covariant_swap_add_le α
63+
IsRightCancelAdd.covariant_swap_add_lt_of_covariant_swap_add_le α
6464

6565
-- Porting note: this instance is not used,
6666
-- and causes timeouts after lean4#2210.

Mathlib/Algebra/Order/WithZero.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ theorem mul_lt_right₀ (c : α) (h : a < b) (hc : c ≠ 0) : a * c < b * c := b
208208
theorem inv_lt_inv₀ (ha : a ≠ 0) (hb : b ≠ 0) : a⁻¹ < b⁻¹ ↔ b < a :=
209209
show (Units.mk0 a ha)⁻¹ < (Units.mk0 b hb)⁻¹ ↔ Units.mk0 b hb < Units.mk0 a ha from
210210
have : CovariantClass αˣ αˣ (· * ·) (· < ·) :=
211-
LeftCancelSemigroup.covariant_mul_lt_of_covariant_mul_le αˣ
211+
IsLeftCancelMul.covariant_mul_lt_of_covariant_mul_le αˣ
212212
inv_lt_inv_iff
213213
#align inv_lt_inv₀ inv_lt_inv₀
214214

Mathlib/Algebra/Regular/Basic.lean

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -343,35 +343,26 @@ theorem IsUnit.isRegular (ua : IsUnit a) : IsRegular a := by
343343

344344
end Monoid
345345

346-
/-- Elements of a left cancel semigroup are left regular. -/
347-
@[to_additive "Elements of an add left cancel semigroup are add-left-regular."]
348-
theorem isLeftRegular_of_leftCancelSemigroup [LeftCancelSemigroup R]
349-
(g : R) : IsLeftRegular g :=
346+
/-- If all multiplications cancel on the left then every element is left-regular. -/
347+
@[to_additive "If all additions cancel on the left then every element is add-left-regular."]
348+
theorem IsLeftRegular.all [Mul R] [IsLeftCancelMul R] (g : R) : IsLeftRegular g :=
350349
mul_right_injective g
351-
#align is_left_regular_of_left_cancel_semigroup isLeftRegular_of_leftCancelSemigroup
352-
#align is_add_left_regular_of_left_cancel_add_semigroup isAddLeftRegular_of_addLeftCancelSemigroup
350+
#align is_left_regular_of_left_cancel_semigroup IsLeftRegular.all
351+
#align is_add_left_regular_of_left_cancel_add_semigroup IsAddLeftRegular.all
353352

354-
/-- Elements of a right cancel semigroup are right regular. -/
355-
@[to_additive "Elements of an add right cancel semigroup are add-right-regular"]
356-
theorem isRightRegular_of_rightCancelSemigroup [RightCancelSemigroup R]
357-
(g : R) : IsRightRegular g :=
353+
/-- If all multiplications cancel on the right then every element is right-regular. -/
354+
@[to_additive "If all additions cancel on the right then every element is add-right-regular."]
355+
theorem IsRightRegular.all [Mul R] [IsRightCancelMul R] (g : R) : IsRightRegular g :=
358356
mul_left_injective g
359-
#align is_right_regular_of_right_cancel_semigroup isRightRegular_of_rightCancelSemigroup
360-
#align is_add_right_regular_of_right_cancel_add_semigroup isAddRightRegular_of_addRightCancelSemigroup
357+
#align is_right_regular_of_right_cancel_semigroup IsRightRegular.all
358+
#align is_add_right_regular_of_right_cancel_add_semigroup IsLeftRegular.all
361359

362-
section CancelMonoid
363-
364-
variable [CancelMonoid R]
365-
366-
/-- Elements of a cancel monoid are regular. Cancel semigroups do not appear to exist. -/
367-
@[to_additive "Elements of an add cancel monoid are regular.
368-
Add cancel semigroups do not appear to exist."]
369-
theorem isRegular_of_cancelMonoid (g : R) : IsRegular g :=
360+
/-- If all multiplications cancel then every element is regular. -/
361+
@[to_additive "If all additions cancel then every element is add-regular."]
362+
theorem IsRegular.all [Mul R] [IsCancelMul R] (g : R) : IsRegular g :=
370363
⟨mul_right_injective g, mul_left_injective g⟩
371-
#align is_regular_of_cancel_monoid isRegular_of_cancelMonoid
372-
#align is_add_regular_of_cancel_add_monoid isAddRegular_of_addCancelMonoid
373-
374-
end CancelMonoid
364+
#align is_regular_of_cancel_monoid IsRegular.all
365+
#align is_add_regular_of_cancel_add_monoid IsAddRegular.all
375366

376367
section CancelMonoidWithZero
377368

Mathlib/Data/Finset/Pointwise.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,9 +1869,9 @@ theorem op_smul_finset_mul_eq_mul_smul_finset (a : α) (s : Finset α) (t : Fins
18691869

18701870
end Semigroup
18711871

1872-
section LeftCancelSemigroup
1872+
section IsLeftCancelMul
18731873

1874-
variable [LeftCancelSemigroup α] [DecidableEq α] (s t : Finset α) (a : α)
1874+
variable [Mul α] [IsLeftCancelMul α] [DecidableEq α] (s t : Finset α) (a : α)
18751875

18761876
@[to_additive]
18771877
theorem pairwiseDisjoint_smul_iff {s : Set α} {t : Finset α} :
@@ -1898,11 +1898,11 @@ theorem card_le_card_mul_left {s : Finset α} (hs : s.Nonempty) : t.card ≤ (s
18981898
#align finset.card_le_card_mul_left Finset.card_le_card_mul_left
18991899
#align finset.card_le_card_add_left Finset.card_le_card_add_left
19001900

1901-
end LeftCancelSemigroup
1901+
end IsLeftCancelMul
19021902

19031903
section
19041904

1905-
variable [RightCancelSemigroup α] [DecidableEq α] (s t : Finset α) (a : α)
1905+
variable [Mul α] [IsRightCancelMul α] [DecidableEq α] (s t : Finset α) (a : α)
19061906

19071907
@[to_additive (attr := simp)]
19081908
theorem card_mul_singleton : (s * {a}).card = s.card :=

Mathlib/Data/Set/Pointwise/SMul.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -857,9 +857,9 @@ theorem op_smul_set_mul_eq_mul_smul_set (a : α) (s : Set α) (t : Set α) :
857857

858858
end Semigroup
859859

860-
section LeftCancelSemigroup
860+
section IsLeftCancelMul
861861

862-
variable [LeftCancelSemigroup α] {s t : Set α}
862+
variable [Mul α] [IsLeftCancelMul α] {s t : Set α}
863863

864864
@[to_additive]
865865
theorem pairwiseDisjoint_smul_iff :
@@ -868,7 +868,7 @@ theorem pairwiseDisjoint_smul_iff :
868868
#align set.pairwise_disjoint_smul_iff Set.pairwiseDisjoint_smul_iff
869869
#align set.pairwise_disjoint_vadd_iff Set.pairwiseDisjoint_vadd_iff
870870

871-
end LeftCancelSemigroup
871+
end IsLeftCancelMul
872872

873873
section Group
874874

0 commit comments

Comments
 (0)