Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 46302c7

Browse files
adomaniurkud
andcommitted
refactor(algebra/group/defs): remove left-right_cancel_comm_monoids (#7134)
There were 6 distinct classes * `(add_)left_cancel_comm_monoid`, * `(add_)right_cancel_comm_monoid`, * `(add_)cancel_comm_monoid`. I removed them all, except for the last 2: * `(add_)cancel_comm_monoid`. The new typeclass `cancel_comm_monoid` requires only `a * b = a * c → b = c`, and deduces the other version from commutativity. Co-authored-by: Yury G. Kudryashov <urkud@urkud.name>
1 parent 92d5cab commit 46302c7

File tree

14 files changed

+47
-106
lines changed

14 files changed

+47
-106
lines changed

src/algebra/group/defs.lean

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,13 @@ by rw [←one_mul c, ←hba, mul_assoc, hac, mul_one b]
240240

241241
end monoid
242242

243-
/-- A commutative monoid is a monoid with commutative `(*)`. -/
244-
@[protect_proj, ancestor monoid comm_semigroup]
245-
class comm_monoid (M : Type u) extends monoid M, comm_semigroup M
246-
247243
/-- An additive commutative monoid is an additive monoid with commutative `(+)`. -/
248244
@[protect_proj, ancestor add_monoid add_comm_semigroup]
249245
class add_comm_monoid (M : Type u) extends add_monoid M, add_comm_semigroup M
250-
attribute [to_additive] comm_monoid
246+
247+
/-- A commutative monoid is a monoid with commutative `(*)`. -/
248+
@[protect_proj, ancestor monoid comm_semigroup, to_additive]
249+
class comm_monoid (M : Type u) extends monoid M, comm_semigroup M
251250

252251
section left_cancel_monoid
253252

@@ -256,21 +255,11 @@ Main examples are `ℕ` and groups. This is the right typeclass for many sum lem
256255
is useful to define the sum over the empty set, so `add_left_cancel_semigroup` is not enough. -/
257256
@[protect_proj, ancestor add_left_cancel_semigroup add_monoid]
258257
class add_left_cancel_monoid (M : Type u) extends add_left_cancel_semigroup M, add_monoid M
259-
-- TODO: I found 1 (one) lemma assuming `[add_left_cancel_monoid]`.
260-
-- Should we port more lemmas to this typeclass?
261258

262259
/-- A monoid in which multiplication is left-cancellative. -/
263260
@[protect_proj, ancestor left_cancel_semigroup monoid, to_additive add_left_cancel_monoid]
264261
class left_cancel_monoid (M : Type u) extends left_cancel_semigroup M, monoid M
265262

266-
/-- Commutative version of add_left_cancel_monoid. -/
267-
@[protect_proj, ancestor add_left_cancel_monoid add_comm_monoid]
268-
class add_left_cancel_comm_monoid (M : Type u) extends add_left_cancel_monoid M, add_comm_monoid M
269-
270-
/-- Commutative version of left_cancel_monoid. -/
271-
@[protect_proj, ancestor left_cancel_monoid comm_monoid, to_additive add_left_cancel_comm_monoid]
272-
class left_cancel_comm_monoid (M : Type u) extends left_cancel_monoid M, comm_monoid M
273-
274263
end left_cancel_monoid
275264

276265
section right_cancel_monoid
@@ -285,14 +274,6 @@ class add_right_cancel_monoid (M : Type u) extends add_right_cancel_semigroup M,
285274
@[protect_proj, ancestor right_cancel_semigroup monoid, to_additive add_right_cancel_monoid]
286275
class right_cancel_monoid (M : Type u) extends right_cancel_semigroup M, monoid M
287276

288-
/-- Commutative version of add_right_cancel_monoid. -/
289-
@[protect_proj, ancestor add_right_cancel_monoid add_comm_monoid]
290-
class add_right_cancel_comm_monoid (M : Type u) extends add_right_cancel_monoid M, add_comm_monoid M
291-
292-
/-- Commutative version of right_cancel_monoid. -/
293-
@[protect_proj, ancestor right_cancel_monoid comm_monoid, to_additive add_right_cancel_comm_monoid]
294-
class right_cancel_comm_monoid (M : Type u) extends right_cancel_monoid M, comm_monoid M
295-
296277
end right_cancel_monoid
297278

298279
section cancel_monoid
@@ -309,14 +290,18 @@ class add_cancel_monoid (M : Type u)
309290
class cancel_monoid (M : Type u) extends left_cancel_monoid M, right_cancel_monoid M
310291

311292
/-- Commutative version of add_cancel_monoid. -/
312-
@[protect_proj, ancestor add_left_cancel_comm_monoid add_right_cancel_comm_monoid]
313-
class add_cancel_comm_monoid (M : Type u)
314-
extends add_left_cancel_comm_monoid M, add_right_cancel_comm_monoid M
293+
@[protect_proj, ancestor add_left_cancel_monoid add_comm_monoid]
294+
class add_cancel_comm_monoid (M : Type u) extends add_left_cancel_monoid M, add_comm_monoid M
315295

316296
/-- Commutative version of cancel_monoid. -/
317-
@[protect_proj, ancestor left_cancel_comm_monoid right_cancel_comm_monoid,
318-
to_additive add_cancel_comm_monoid]
319-
class cancel_comm_monoid (M : Type u) extends left_cancel_comm_monoid M, right_cancel_comm_monoid M
297+
@[protect_proj, ancestor left_cancel_monoid comm_monoid, to_additive add_cancel_comm_monoid]
298+
class cancel_comm_monoid (M : Type u) extends left_cancel_monoid M, comm_monoid M
299+
300+
@[priority 100, to_additive] -- see Note [lower instance priority]
301+
instance cancel_comm_monoid.to_cancel_monoid (M : Type u) [cancel_comm_monoid M] :
302+
cancel_monoid M :=
303+
{ mul_right_cancel := λ a b c h, mul_left_cancel $ by rw [mul_comm, h, mul_comm],
304+
.. ‹cancel_comm_monoid M› }
320305

321306
end cancel_monoid
322307

src/algebra/group/inj_surj.lean

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ protected def comm_monoid [comm_monoid M₂] (f : M₁ → M₂) (hf : injective
123123
comm_monoid M₁ :=
124124
{ .. hf.comm_semigroup f mul, .. hf.monoid f one mul }
125125

126+
/-- A type endowed with `1` and `*` is a cancel commutative monoid,
127+
if it admits an injective map that preserves `1` and `*` to a cancel commutative monoid. -/
128+
@[to_additive add_cancel_comm_monoid
129+
"A type endowed with `0` and `+` is an additive cancel commutative monoid,
130+
if it admits an injective map that preserves `0` and `+` to an additive cancel commutative monoid."]
131+
protected def cancel_comm_monoid [cancel_comm_monoid M₂] (f : M₁ → M₂) (hf : injective f)
132+
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) :
133+
cancel_comm_monoid M₁ :=
134+
{ .. hf.left_cancel_semigroup f mul, .. hf.comm_monoid f one mul }
135+
126136
variables [has_inv M₁] [has_div M₁]
127137

128138
/-- A type endowed with `1`, `*`, `⁻¹`, and `/` is a `div_inv_monoid`

src/algebra/group/prod.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ instance [comm_monoid M] [comm_monoid N] : comm_monoid (M × N) :=
137137

138138
@[to_additive]
139139
instance [cancel_comm_monoid M] [cancel_comm_monoid N] : cancel_comm_monoid (M × N) :=
140-
{ .. prod.left_cancel_monoid, .. prod.right_cancel_monoid, .. prod.comm_monoid }
140+
{ .. prod.left_cancel_monoid, .. prod.comm_monoid }
141141

142142
instance [monoid_with_zero M] [monoid_with_zero N] : monoid_with_zero (M × N) :=
143143
{ .. prod.monoid, .. prod.mul_zero_class }

src/algebra/ordered_group.lean

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ instance ordered_comm_group.to_ordered_cancel_comm_monoid (α : Type u)
7373
[s : ordered_comm_group α] :
7474
ordered_cancel_comm_monoid α :=
7575
{ mul_left_cancel := @mul_left_cancel α _,
76-
mul_right_cancel := @mul_right_cancel α _,
7776
le_of_mul_le_mul_left := @ordered_comm_group.le_of_mul_le_mul_left α _,
7877
..s }
7978

@@ -587,7 +586,6 @@ instance linear_ordered_comm_group.to_linear_ordered_cancel_comm_monoid :
587586
linear_ordered_cancel_comm_monoid α :=
588587
{ le_of_mul_le_mul_left := λ x y z, le_of_mul_le_mul_left',
589588
mul_left_cancel := λ x y z, mul_left_cancel,
590-
mul_right_cancel := λ x y z, mul_right_cancel,
591589
..‹linear_ordered_comm_group α› }
592590

593591
/-- Pullback a `linear_ordered_comm_group` under an injective map. -/

src/algebra/ordered_monoid.lean

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,6 @@ def function.injective.ordered_cancel_comm_monoid {β : Type*}
10691069
{ le_of_mul_le_mul_left := λ a b c (ab : f (a * b) ≤ f (a * c)),
10701070
(by { rw [mul, mul] at ab, exact le_of_mul_le_mul_left' ab }),
10711071
..hf.left_cancel_semigroup f mul,
1072-
..hf.right_cancel_semigroup f mul,
10731072
..hf.ordered_comm_monoid f one mul }
10741073

10751074
section mono
@@ -1224,7 +1223,6 @@ instance [ordered_comm_monoid α] : ordered_comm_monoid (order_dual α) :=
12241223
instance [ordered_cancel_comm_monoid α] : ordered_cancel_comm_monoid (order_dual α) :=
12251224
{ le_of_mul_le_mul_left := λ a b c : α, le_of_mul_le_mul_left',
12261225
mul_left_cancel := @mul_left_cancel α _,
1227-
mul_right_cancel := @mul_right_cancel α _,
12281226
..order_dual.ordered_comm_monoid }
12291227

12301228
@[to_additive]
@@ -1244,8 +1242,7 @@ instance [ordered_cancel_comm_monoid M] [ordered_cancel_comm_monoid N] :
12441242
ordered_cancel_comm_monoid (M × N) :=
12451243
{ mul_le_mul_left := λ a b h c, ⟨mul_le_mul_left' h.1 _, mul_le_mul_left' h.2 _⟩,
12461244
le_of_mul_le_mul_left := λ a b c h, ⟨le_of_mul_le_mul_left' h.1, le_of_mul_le_mul_left' h.2⟩,
1247-
.. prod.comm_monoid, .. prod.left_cancel_semigroup, .. prod.right_cancel_semigroup,
1248-
.. prod.partial_order M N }
1245+
.. prod.cancel_comm_monoid, .. prod.partial_order M N }
12491246

12501247
end prod
12511248

@@ -1272,13 +1269,11 @@ instance [ordered_comm_monoid α] : ordered_add_comm_monoid (additive α) :=
12721269

12731270
instance [ordered_cancel_add_comm_monoid α] : ordered_cancel_comm_monoid (multiplicative α) :=
12741271
{ le_of_mul_le_mul_left := @ordered_cancel_add_comm_monoid.le_of_add_le_add_left α _,
1275-
..multiplicative.right_cancel_semigroup,
12761272
..multiplicative.left_cancel_semigroup,
12771273
..multiplicative.ordered_comm_monoid }
12781274

12791275
instance [ordered_cancel_comm_monoid α] : ordered_cancel_add_comm_monoid (additive α) :=
12801276
{ le_of_add_le_add_left := @ordered_cancel_comm_monoid.le_of_mul_le_mul_left α _,
1281-
..additive.add_right_cancel_semigroup,
12821277
..additive.add_left_cancel_semigroup,
12831278
..additive.ordered_add_comm_monoid }
12841279

src/algebra/ordered_ring.lean

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,6 @@ instance ordered_ring.to_ordered_semiring : ordered_semiring α :=
630630
{ mul_zero := mul_zero,
631631
zero_mul := zero_mul,
632632
add_left_cancel := @add_left_cancel α _,
633-
add_right_cancel := @add_right_cancel α _,
634633
le_of_add_le_add_left := @le_of_add_le_add_left α _,
635634
mul_lt_mul_of_pos_left := @ordered_ring.mul_lt_mul_of_pos_left α _,
636635
mul_lt_mul_of_pos_right := @ordered_ring.mul_lt_mul_of_pos_right α _,
@@ -719,7 +718,6 @@ instance linear_ordered_ring.to_linear_ordered_semiring : linear_ordered_semirin
719718
{ mul_zero := mul_zero,
720719
zero_mul := zero_mul,
721720
add_left_cancel := @add_left_cancel α _,
722-
add_right_cancel := @add_right_cancel α _,
723721
le_of_add_le_add_left := @le_of_add_le_add_left α _,
724722
mul_lt_mul_of_pos_left := @mul_lt_mul_of_pos_left α _,
725723
mul_lt_mul_of_pos_right := @mul_lt_mul_of_pos_right α _,
@@ -920,7 +918,6 @@ let s : linear_ordered_semiring α := @linear_ordered_ring.to_linear_ordered_sem
920918
{ zero_mul := @linear_ordered_semiring.zero_mul α s,
921919
mul_zero := @linear_ordered_semiring.mul_zero α s,
922920
add_left_cancel := @linear_ordered_semiring.add_left_cancel α s,
923-
add_right_cancel := @linear_ordered_semiring.add_right_cancel α s,
924921
le_of_add_le_add_left := @linear_ordered_semiring.le_of_add_le_add_left α s,
925922
mul_lt_mul_of_pos_left := @linear_ordered_semiring.mul_lt_mul_of_pos_left α s,
926923
mul_lt_mul_of_pos_right := @linear_ordered_semiring.mul_lt_mul_of_pos_right α s,
@@ -942,7 +939,6 @@ let s : linear_ordered_semiring α := @linear_ordered_ring.to_linear_ordered_sem
942939
{ zero_mul := @linear_ordered_semiring.zero_mul α s,
943940
mul_zero := @linear_ordered_semiring.mul_zero α s,
944941
add_left_cancel := @linear_ordered_semiring.add_left_cancel α s,
945-
add_right_cancel := @linear_ordered_semiring.add_right_cancel α s,
946942
le_of_add_le_add_left := @linear_ordered_semiring.le_of_add_le_add_left α s,
947943
mul_lt_mul_of_pos_left := @linear_ordered_semiring.mul_lt_mul_of_pos_left α s,
948944
mul_lt_mul_of_pos_right := @linear_ordered_semiring.mul_lt_mul_of_pos_right α s,

src/algebra/punit_instances.lean

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ intros; trivial
6060

6161
instance : linear_ordered_cancel_add_comm_monoid punit :=
6262
{ add_left_cancel := λ _ _ _ _, subsingleton.elim _ _,
63-
add_right_cancel := λ _ _ _ _, subsingleton.elim _ _,
6463
le_of_add_le_add_left := λ _ _ _ _, trivial,
6564
le_total := λ _ _, or.inl trivial,
6665
decidable_le := λ _ _, decidable.true,

src/data/finsupp/basic.lean

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2262,21 +2262,11 @@ instance [partial_order M] [has_zero M] : partial_order (α →₀ M) :=
22622262
{ le_antisymm := λ f g hfg hgf, ext $ λ s, le_antisymm (hfg s) (hgf s),
22632263
.. finsupp.preorder }
22642264

2265-
instance [ordered_cancel_add_comm_monoid M] : add_left_cancel_semigroup (α →₀ M) :=
2266-
{ add_left_cancel := λ a b c h, ext $ λ s,
2267-
by { rw ext_iff at h, exact add_left_cancel (h s) },
2268-
.. finsupp.add_monoid }
2269-
2270-
instance [ordered_cancel_add_comm_monoid M] : add_right_cancel_semigroup (α →₀ M) :=
2271-
{ add_right_cancel := λ a b c h, ext $ λ s,
2272-
by { rw ext_iff at h, exact add_right_cancel (h s) },
2273-
.. finsupp.add_monoid }
2274-
22752265
instance [ordered_cancel_add_comm_monoid M] : ordered_cancel_add_comm_monoid (α →₀ M) :=
22762266
{ add_le_add_left := λ a b h c s, add_le_add_left (h s) (c s),
22772267
le_of_add_le_add_left := λ a b c h s, le_of_add_le_add_left (h s),
2278-
.. finsupp.add_comm_monoid, .. finsupp.partial_order,
2279-
.. finsupp.add_left_cancel_semigroup, .. finsupp.add_right_cancel_semigroup }
2268+
add_left_cancel := λ a b c h, ext $ λ s, add_left_cancel (ext_iff.1 h s),
2269+
.. finsupp.add_comm_monoid, .. finsupp.partial_order }
22802270

22812271
lemma le_def [preorder M] [has_zero M] {f g : α →₀ M} : f ≤ g ↔ ∀ x, f x ≤ g x := iff.rfl
22822272

src/data/multiset/basic.lean

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,6 @@ instance : ordered_cancel_add_comm_monoid (multiset α) :=
375375
zero_add := multiset.zero_add,
376376
add_zero := λ s, by rw [multiset.add_comm, multiset.zero_add],
377377
add_left_cancel := multiset.add_left_cancel,
378-
add_right_cancel := λ s₁ s₂ s₃ h, multiset.add_left_cancel s₂ $
379-
by simpa [multiset.add_comm] using h,
380378
add_le_add_left := λ s₁ s₂ h s₃, (multiset.add_le_add_left _).2 h,
381379
le_of_add_le_add_left := λ s₁ s₂ s₃, (multiset.add_le_add_left _).1,
382380
..@multiset.partial_order α }

src/data/nat/basic.lean

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ instance : comm_semiring nat :=
4848

4949
instance : linear_ordered_semiring nat :=
5050
{ add_left_cancel := @nat.add_left_cancel,
51-
add_right_cancel := @nat.add_right_cancel,
5251
lt := nat.lt,
5352
add_le_add_left := @nat.add_le_add_left,
5453
le_of_add_le_add_left := @nat.le_of_add_le_add_left,

0 commit comments

Comments
 (0)