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

Commit 2e0975f

Browse files
committed
refactor(algebra/group/defs): use is_left_cancel_mul etc (#17884)
The Lean 4 version is here: leanprover-community/mathlib4#945.
1 parent 955890d commit 2e0975f

7 files changed

Lines changed: 93 additions & 99 deletions

File tree

src/algebra/group/defs.lean

Lines changed: 58 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,57 @@ class is_cancel_add (G : Type u) [has_add G]
133133

134134
attribute [to_additive] is_cancel_mul
135135

136+
section is_left_cancel_mul
137+
variables [is_left_cancel_mul G] {a b c : G}
138+
139+
@[to_additive]
140+
lemma mul_left_cancel : a * b = a * c → b = c :=
141+
is_left_cancel_mul.mul_left_cancel a b c
142+
143+
@[to_additive]
144+
lemma mul_left_cancel_iff : a * b = a * c ↔ b = c :=
145+
⟨mul_left_cancel, congr_arg _⟩
146+
147+
@[to_additive]
148+
theorem mul_right_injective (a : G) : function.injective ((*) a) :=
149+
λ b c, mul_left_cancel
150+
151+
@[simp, to_additive]
152+
theorem mul_right_inj (a : G) {b c : G} : a * b = a * c ↔ b = c :=
153+
(mul_right_injective a).eq_iff
154+
155+
@[to_additive]
156+
theorem mul_ne_mul_right (a : G) {b c : G} : a * b ≠ a * c ↔ b ≠ c :=
157+
(mul_right_injective a).ne_iff
158+
159+
end is_left_cancel_mul
160+
161+
section is_right_cancel_mul
162+
163+
variables [is_right_cancel_mul G] {a b c : G}
164+
165+
@[to_additive]
166+
lemma mul_right_cancel : a * b = c * b → a = c :=
167+
is_right_cancel_mul.mul_right_cancel a b c
168+
169+
@[to_additive]
170+
lemma mul_right_cancel_iff : b * a = c * a ↔ b = c :=
171+
⟨mul_right_cancel, congr_arg _⟩
172+
173+
@[to_additive]
174+
theorem mul_left_injective (a : G) : function.injective (λ x, x * a) :=
175+
λ b c, mul_right_cancel
176+
177+
@[simp, to_additive]
178+
theorem mul_left_inj (a : G) {b c : G} : b * a = c * a ↔ b = c :=
179+
(mul_left_injective a).eq_iff
180+
181+
@[to_additive]
182+
theorem mul_ne_mul_left (a : G) {b c : G} : b * a ≠ c * a ↔ b ≠ c :=
183+
(mul_left_injective a).ne_iff
184+
185+
end is_right_cancel_mul
186+
136187
end has_mul
137188

138189
/-- A semigroup is a type with an associative `(*)`. -/
@@ -185,11 +236,7 @@ instance comm_semigroup.to_is_commutative : is_commutative G (*) :=
185236
`is_right_cancel_add G`."]
186237
lemma comm_semigroup.is_right_cancel_mul.to_is_left_cancel_mul (G : Type u) [comm_semigroup G]
187238
[is_right_cancel_mul G] : is_left_cancel_mul G :=
188-
{ mul_left_cancel := λ a b c h,
189-
begin
190-
rw [mul_comm a b, mul_comm a c] at h,
191-
exact is_right_cancel_mul.mul_right_cancel _ _ _ h
192-
end }
239+
⟨λ a b c h, mul_right_cancel $ (mul_comm _ _).trans (h.trans $ mul_comm _ _)⟩
193240

194241
/-- Any `comm_semigroup G` that satisfies `is_left_cancel_mul G` also satisfies
195242
`is_right_cancel_mul G`. -/
@@ -198,37 +245,23 @@ lemma comm_semigroup.is_right_cancel_mul.to_is_left_cancel_mul (G : Type u) [com
198245
`is_left_cancel_add G`."]
199246
lemma comm_semigroup.is_left_cancel_mul.to_is_right_cancel_mul (G : Type u) [comm_semigroup G]
200247
[is_left_cancel_mul G] : is_right_cancel_mul G :=
201-
{ mul_right_cancel := λ a b c h,
202-
begin
203-
rw [mul_comm a b, mul_comm c b] at h,
204-
exact is_left_cancel_mul.mul_left_cancel _ _ _ h
205-
end }
248+
⟨λ a b c h, mul_left_cancel $ (mul_comm _ _).trans (h.trans $ mul_comm _ _)⟩
206249

207250
/-- Any `comm_semigroup G` that satisfies `is_left_cancel_mul G` also satisfies
208251
`is_cancel_mul G`. -/
209252
@[to_additive add_comm_semigroup.is_left_cancel_add.to_is_cancel_add "Any `add_comm_semigroup G`
210253
that satisfies `is_left_cancel_add G` also satisfies `is_cancel_add G`."]
211254
lemma comm_semigroup.is_left_cancel_mul.to_is_cancel_mul (G : Type u) [comm_semigroup G]
212255
[is_left_cancel_mul G] : is_cancel_mul G :=
213-
{ mul_left_cancel := is_left_cancel_mul.mul_left_cancel,
214-
mul_right_cancel := λ a b c h,
215-
begin
216-
rw [mul_comm a b, mul_comm c b] at h,
217-
exact is_left_cancel_mul.mul_left_cancel _ _ _ h
218-
end }
256+
{ .. ‹is_left_cancel_mul G›, .. comm_semigroup.is_left_cancel_mul.to_is_right_cancel_mul G }
219257

220258
/-- Any `comm_semigroup G` that satisfies `is_right_cancel_mul G` also satisfies
221259
`is_cancel_mul G`. -/
222260
@[to_additive add_comm_semigroup.is_right_cancel_add.to_is_cancel_add "Any `add_comm_semigroup G`
223261
that satisfies `is_right_cancel_add G` also satisfies `is_cancel_add G`."]
224262
lemma comm_semigroup.is_right_cancel_mul.to_is_cancel_mul (G : Type u) [comm_semigroup G]
225263
[is_right_cancel_mul G] : is_cancel_mul G :=
226-
{ mul_left_cancel := λ a b c h,
227-
begin
228-
rw [mul_comm a b, mul_comm a c] at h,
229-
exact is_right_cancel_mul.mul_right_cancel _ _ _ h
230-
end,
231-
mul_right_cancel := is_right_cancel_mul.mul_right_cancel }
264+
{ .. ‹is_right_cancel_mul G›, .. comm_semigroup.is_right_cancel_mul.to_is_left_cancel_mul G }
232265

233266
end comm_semigroup
234267

@@ -243,37 +276,12 @@ class add_left_cancel_semigroup (G : Type u) extends add_semigroup G :=
243276
(add_left_cancel : ∀ a b c : G, a + b = a + c → b = c)
244277
attribute [to_additive add_left_cancel_semigroup] left_cancel_semigroup
245278

246-
section left_cancel_semigroup
247-
variables [left_cancel_semigroup G] {a b c : G}
248-
249-
@[to_additive]
250-
lemma mul_left_cancel : a * b = a * c → b = c :=
251-
left_cancel_semigroup.mul_left_cancel a b c
252-
253-
@[to_additive]
254-
lemma mul_left_cancel_iff : a * b = a * c ↔ b = c :=
255-
⟨mul_left_cancel, congr_arg _⟩
256-
257-
@[to_additive]
258-
theorem mul_right_injective (a : G) : function.injective ((*) a) :=
259-
λ b c, mul_left_cancel
260-
261-
@[simp, to_additive]
262-
theorem mul_right_inj (a : G) {b c : G} : a * b = a * c ↔ b = c :=
263-
(mul_right_injective a).eq_iff
264-
265-
@[to_additive]
266-
theorem mul_ne_mul_right (a : G) {b c : G} : a * b ≠ a * c ↔ b ≠ c :=
267-
(mul_right_injective a).ne_iff
268-
269279
/-- Any `left_cancel_semigroup` satisfies `is_left_cancel_mul`. -/
270280
@[priority 100, to_additive "Any `add_left_cancel_semigroup` satisfies `is_left_cancel_add`."]
271281
instance left_cancel_semigroup.to_is_left_cancel_mul (G : Type u) [left_cancel_semigroup G] :
272282
is_left_cancel_mul G :=
273283
{ mul_left_cancel := left_cancel_semigroup.mul_left_cancel }
274284

275-
end left_cancel_semigroup
276-
277285
/-- A `right_cancel_semigroup` is a semigroup such that `a * b = c * b` implies `a = c`. -/
278286
@[protect_proj, ancestor semigroup, ext]
279287
class right_cancel_semigroup (G : Type u) extends semigroup G :=
@@ -286,37 +294,12 @@ class add_right_cancel_semigroup (G : Type u) extends add_semigroup G :=
286294
(add_right_cancel : ∀ a b c : G, a + b = c + b → a = c)
287295
attribute [to_additive add_right_cancel_semigroup] right_cancel_semigroup
288296

289-
section right_cancel_semigroup
290-
variables [right_cancel_semigroup G] {a b c : G}
291-
292-
@[to_additive]
293-
lemma mul_right_cancel : a * b = c * b → a = c :=
294-
right_cancel_semigroup.mul_right_cancel a b c
295-
296-
@[to_additive]
297-
lemma mul_right_cancel_iff : b * a = c * a ↔ b = c :=
298-
⟨mul_right_cancel, congr_arg _⟩
299-
300-
@[to_additive]
301-
theorem mul_left_injective (a : G) : function.injective (λ x, x * a) :=
302-
λ b c, mul_right_cancel
303-
304-
@[simp, to_additive]
305-
theorem mul_left_inj (a : G) {b c : G} : b * a = c * a ↔ b = c :=
306-
(mul_left_injective a).eq_iff
307-
308-
@[to_additive]
309-
theorem mul_ne_mul_left (a : G) {b c : G} : b * a ≠ c * a ↔ b ≠ c :=
310-
(mul_left_injective a).ne_iff
311-
312297
/-- Any `right_cancel_semigroup` satisfies `is_right_cancel_mul`. -/
313298
@[priority 100, to_additive "Any `add_right_cancel_semigroup` satisfies `is_right_cancel_add`."]
314-
instance right_cancel_semigroup.to_is_right_cancel_mul (G : Type u)
315-
[right_cancel_semigroup G] : is_right_cancel_mul G :=
299+
instance right_cancel_semigroup.to_is_right_cancel_mul (G : Type u) [right_cancel_semigroup G] :
300+
is_right_cancel_mul G :=
316301
{ mul_right_cancel := right_cancel_semigroup.mul_right_cancel }
317302

318-
end right_cancel_semigroup
319-
320303
/-- Typeclass for expressing that a type `M` with multiplication and a one satisfies
321304
`1 * a = a` and `a * 1 = a` for all `a : M`. -/
322305
@[ancestor has_one has_mul]
@@ -362,8 +345,6 @@ instance mul_one_class.to_is_right_id : is_right_id M (*) 1 :=
362345

363346
end mul_one_class
364347

365-
366-
367348
section
368349
variables {M : Type u}
369350

@@ -580,8 +561,7 @@ class cancel_comm_monoid (M : Type u) extends left_cancel_monoid M, comm_monoid
580561
@[priority 100, to_additive] -- see Note [lower instance priority]
581562
instance cancel_comm_monoid.to_cancel_monoid (M : Type u) [cancel_comm_monoid M] :
582563
cancel_monoid M :=
583-
{ mul_right_cancel := λ a b c h, mul_left_cancel $ by rw [mul_comm, h, mul_comm],
584-
.. ‹cancel_comm_monoid M› }
564+
{ .. ‹cancel_comm_monoid M›, .. comm_semigroup.is_left_cancel_mul.to_is_right_cancel_mul M }
585565

586566
/-- Any `cancel_monoid M` satisfies `is_cancel_mul M`. -/
587567
@[priority 100, to_additive "Any `add_cancel_monoid M` satisfies `is_cancel_add M`."]

src/algebra/group/type_tags.lean

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,21 +124,35 @@ instance [add_comm_semigroup α] : comm_semigroup (multiplicative α) :=
124124
{ mul_comm := @add_comm _ _,
125125
..multiplicative.semigroup }
126126

127+
instance [has_mul α] [is_left_cancel_mul α] : is_left_cancel_add (additive α) :=
128+
{ add_left_cancel := @mul_left_cancel α _ _ }
129+
130+
instance [has_add α] [is_left_cancel_add α] : is_left_cancel_mul (multiplicative α) :=
131+
{ mul_left_cancel := @add_left_cancel α _ _ }
132+
133+
instance [has_mul α] [is_right_cancel_mul α] : is_right_cancel_add (additive α) :=
134+
{ add_right_cancel := @mul_right_cancel α _ _ }
135+
136+
instance [has_add α] [is_right_cancel_add α] : is_right_cancel_mul (multiplicative α) :=
137+
{ mul_right_cancel := @add_right_cancel α _ _ }
138+
139+
instance [has_mul α] [is_cancel_mul α] : is_cancel_add (additive α) :=
140+
{ ..additive.is_left_cancel_add, ..additive.is_right_cancel_add }
141+
142+
instance [has_add α] [is_cancel_add α] : is_cancel_mul (multiplicative α) :=
143+
{ ..multiplicative.is_left_cancel_mul, ..multiplicative.is_right_cancel_mul }
144+
127145
instance [left_cancel_semigroup α] : add_left_cancel_semigroup (additive α) :=
128-
{ add_left_cancel := @mul_left_cancel _ _,
129-
..additive.add_semigroup }
146+
{ ..additive.add_semigroup, ..additive.is_left_cancel_add }
130147

131148
instance [add_left_cancel_semigroup α] : left_cancel_semigroup (multiplicative α) :=
132-
{ mul_left_cancel := @add_left_cancel _ _,
133-
..multiplicative.semigroup }
149+
{ ..multiplicative.semigroup, ..multiplicative.is_left_cancel_mul }
134150

135151
instance [right_cancel_semigroup α] : add_right_cancel_semigroup (additive α) :=
136-
{ add_right_cancel := @mul_right_cancel _ _,
137-
..additive.add_semigroup }
152+
{ ..additive.add_semigroup, ..additive.is_right_cancel_add }
138153

139154
instance [add_right_cancel_semigroup α] : right_cancel_semigroup (multiplicative α) :=
140-
{ mul_right_cancel := @add_right_cancel _ _,
141-
..multiplicative.semigroup }
155+
{ ..multiplicative.semigroup, ..multiplicative.is_right_cancel_mul }
142156

143157
instance [has_one α] : has_zero (additive α) := ⟨additive.of_mul 1
144158

src/data/nat/modeq.lean

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,9 @@ end
323323

324324
lemma div_mod_eq_mod_mul_div (a b c : ℕ) : a / b % c = a % (b * c) / b :=
325325
if hb0 : b = 0 then by simp [hb0]
326-
else by rw [← @add_right_cancel_iff _ _ (c * (a / b / c)), mod_add_div, nat.div_div_eq_div_mul,
327-
← mul_right_inj' hb0, ← @add_left_cancel_iff _ _ (a % b), mod_add_div,
328-
mul_add, ← @add_left_cancel_iff _ _ (a % (b * c) % b), add_left_comm,
326+
else by rw [← @add_right_cancel_iff _ _ _ (c * (a / b / c)), mod_add_div, nat.div_div_eq_div_mul,
327+
← mul_right_inj' hb0, ← @add_left_cancel_iff _ _ _ (a % b), mod_add_div,
328+
mul_add, ← @add_left_cancel_iff _ _ _ (a % (b * c) % b), add_left_comm,
329329
← add_assoc (a % (b * c) % b), mod_add_div, ← mul_assoc, mod_add_div, mod_mul_right_mod]
330330

331331
lemma add_mod_add_ite (a b c : ℕ) :
@@ -342,7 +342,7 @@ else
342342
exact add_lt_add (nat.mod_lt _ (nat.pos_of_ne_zero hc0))
343343
(nat.mod_lt _ (nat.pos_of_ne_zero hc0))),
344344
have h0 : 0 < (a % c + b % c) / c, from nat.div_pos h (nat.pos_of_ne_zero hc0),
345-
rw [← @add_right_cancel_iff _ _ (c * ((a % c + b % c) / c)), add_comm _ c, add_assoc,
345+
rw [← @add_right_cancel_iff _ _ _ (c * ((a % c + b % c) / c)), add_comm _ c, add_assoc,
346346
mod_add_div, le_antisymm (le_of_lt_succ h2) h0, mul_one, add_comm] },
347347
{ rw [nat.mod_eq_of_lt (lt_of_not_ge h), add_zero] }
348348
end
@@ -358,7 +358,7 @@ by rw [← add_mod_add_ite, if_pos hc]
358358
lemma add_div {a b c : ℕ} (hc0 : 0 < c) : (a + b) / c = a / c + b / c +
359359
if c ≤ a % c + b % c then 1 else 0 :=
360360
begin
361-
rw [← mul_right_inj' hc0.ne', ← @add_left_cancel_iff _ _ ((a + b) % c + a % c + b % c)],
361+
rw [← mul_right_inj' hc0.ne', ← @add_left_cancel_iff _ _ _ ((a + b) % c + a % c + b % c)],
362362
suffices : (a + b) % c + c * ((a + b) / c) + a % c + b % c =
363363
a % c + c * (a / c) + (b % c + c * (b / c)) + c * (if c ≤ a % c + b % c then 1 else 0) +
364364
(a + b) % c,

src/data/nat/order/lemmas.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ end
6161

6262
protected lemma div_eq_zero_iff {a b : ℕ} (hb : 0 < b) : a / b = 0 ↔ a < b :=
6363
⟨λ h, by rw [← mod_add_div a b, h, mul_zero, add_zero]; exact mod_lt _ hb,
64-
λ h, by rw [← mul_right_inj' hb.ne', ← @add_left_cancel_iff _ _ (a % b), mod_add_div,
64+
λ h, by rw [← mul_right_inj' hb.ne', ← @add_left_cancel_iff _ _ _ (a % b), mod_add_div,
6565
mod_eq_of_lt h, mul_zero, add_zero]⟩
6666

6767
protected lemma div_eq_zero {a b : ℕ} (hb : a < b) : a / b = 0 :=

src/linear_algebra/finite_dimensional.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ noncomputable def linear_equiv.quot_equiv_of_equiv
850850
(f₁ : p ≃ₗ[K] q) (f₂ : V ≃ₗ[K] V₂) : (V ⧸ p) ≃ₗ[K] (V₂ ⧸ q) :=
851851
linear_equiv.of_finrank_eq _ _
852852
begin
853-
rw [← @add_right_cancel_iff _ _ (finrank K p), submodule.finrank_quotient_add_finrank,
853+
rw [← @add_right_cancel_iff _ _ _ (finrank K p), submodule.finrank_quotient_add_finrank,
854854
linear_equiv.finrank_eq f₁, submodule.finrank_quotient_add_finrank,
855855
linear_equiv.finrank_eq f₂],
856856
end

src/set_theory/game/impartial.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ lemma add_self : G + G ≈ 0 :=
143143

144144
/-- This lemma doesn't require `H` to be impartial. -/
145145
lemma equiv_iff_add_equiv_zero (H : pgame) : H ≈ G ↔ H + G ≈ 0 :=
146-
by { rw [equiv_iff_game_eq, equiv_iff_game_eq, ←@add_right_cancel_iff _ _ (-⟦G⟧)], simpa }
146+
by { rw [equiv_iff_game_eq, equiv_iff_game_eq, ←@add_right_cancel_iff _ _ _ (-⟦G⟧)], simpa }
147147

148148
/-- This lemma doesn't require `H` to be impartial. -/
149149
lemma equiv_iff_add_equiv_zero' (H : pgame) : G ≈ H ↔ G + H ≈ 0 :=
150-
by { rw [equiv_iff_game_eq, equiv_iff_game_eq, ←@add_left_cancel_iff _ _ (-⟦G⟧), eq_comm], simpa }
150+
by { rw [equiv_iff_game_eq, equiv_iff_game_eq, ←@add_left_cancel_iff _ _ _ (-⟦G⟧), eq_comm], simpa }
151151

152152
lemma le_zero_iff {G : pgame} [G.impartial] : G ≤ 00 ≤ G :=
153153
by rw [←zero_le_neg_iff, le_congr_right (neg_equiv_self G)]

src/set_theory/ordinal/natural_ops.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,12 +312,12 @@ theorem nadd_le_nadd_iff_right : ∀ a {b c}, b ♯ a ≤ c ♯ a ↔ b ≤ c :=
312312
@_root_.add_le_add_iff_right nat_ordinal _ _ _ _
313313

314314
theorem nadd_left_cancel : ∀ {a b c}, a ♯ b = a ♯ c → b = c :=
315-
@_root_.add_left_cancel nat_ordinal _
315+
@_root_.add_left_cancel nat_ordinal _ _
316316
theorem nadd_right_cancel : ∀ {a b c}, a ♯ b = c ♯ b → a = c :=
317-
@_root_.add_right_cancel nat_ordinal _
317+
@_root_.add_right_cancel nat_ordinal _ _
318318
theorem nadd_left_cancel_iff : ∀ {a b c}, a ♯ b = a ♯ c ↔ b = c :=
319-
@add_left_cancel_iff nat_ordinal _
319+
@add_left_cancel_iff nat_ordinal _ _
320320
theorem nadd_right_cancel_iff : ∀ {a b c}, b ♯ a = c ♯ a ↔ b = c :=
321-
@add_right_cancel_iff nat_ordinal _
321+
@add_right_cancel_iff nat_ordinal _ _
322322

323323
end ordinal

0 commit comments

Comments
 (0)