Skip to content

Commit 45df823

Browse files
kim-emYaelDillies
andcommitted
chore: refactor of Algebra/Group/Defs to reduce imports (#9606)
We are not that far from the point that `Algebra/Group/Defs` depends on nothing significant besides `simps` and `to_additive`. This removes from `Mathlib.Algebra.Group.Defs` the dependencies on * `Mathlib.Tactic.Basic` (which is a grab-bag of random stuff) * `Mathlib.Init.Algebra.Classes` (which is ancient and half-baked) * `Mathlib.Logic.Function.Basic` (not particularly important, but it is barely used in this file) The goal is to avoid all unnecessary imports to set up the *definitions* of basic algebraic structures. We also separate out `Mathlib.Tactic.TypeStar` and `Mathlib.Tactic.Lemma` as prerequisites to `Mathlib.Tactic.Basic`, but which can be imported separately when the rest of `Mathlib.Tactic.Basic` is not needed. Co-authored-by: Scott Morrison <scott.morrison@gmail.com> Co-authored-by: Yaël Dillies <yael.dillies@gmail.com>
1 parent b075cdd commit 45df823

File tree

25 files changed

+186
-108
lines changed

25 files changed

+186
-108
lines changed

Mathlib.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3364,6 +3364,7 @@ import Mathlib.Tactic.InferParam
33643364
import Mathlib.Tactic.Inhabit
33653365
import Mathlib.Tactic.IntervalCases
33663366
import Mathlib.Tactic.IrreducibleDef
3367+
import Mathlib.Tactic.Lemma
33673368
import Mathlib.Tactic.LibrarySearch
33683369
import Mathlib.Tactic.Lift
33693370
import Mathlib.Tactic.LiftLets
@@ -3465,6 +3466,7 @@ import Mathlib.Tactic.ToLevel
34653466
import Mathlib.Tactic.Trace
34663467
import Mathlib.Tactic.TryThis
34673468
import Mathlib.Tactic.TypeCheck
3469+
import Mathlib.Tactic.TypeStar
34683470
import Mathlib.Tactic.UnsetOption
34693471
import Mathlib.Tactic.Use
34703472
import Mathlib.Tactic.Variable

Mathlib/Algebra/CharZero/Defs.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Mathlib.Init.Data.Nat.Lemmas
77
import Mathlib.Data.Int.Cast.Defs
88
import Mathlib.Tactic.Cases
99
import Mathlib.Algebra.NeZero
10+
import Mathlib.Logic.Function.Basic
1011

1112
#align_import algebra.char_zero.defs from "leanprover-community/mathlib"@"d6aae1bcbd04b8de2022b9b83a5b5b10e10c777d"
1213

Mathlib/Algebra/CovariantAndContravariant.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Copyright (c) 2021 Damiano Testa. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Damiano Testa
55
-/
6-
import Mathlib.Algebra.Group.Defs
6+
import Mathlib.Algebra.Group.Basic
77
import Mathlib.Order.Basic
88
import Mathlib.Order.Monotone.Basic
99

Mathlib/Algebra/Group/Basic.lean

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Jeremy Avigad, Leonardo de Moura, Simon Hudon, Mario Carneiro
55
-/
66
import Mathlib.Algebra.Group.Defs
7+
import Mathlib.Logic.Function.Basic
78
import Mathlib.Tactic.Cases
89
import Mathlib.Tactic.SimpRw
910
import Mathlib.Tactic.SplitIfs
@@ -25,14 +26,66 @@ universe u
2526

2627
variable {α β G : Type*}
2728

29+
section IsLeftCancelMul
30+
31+
variable [Mul G] [IsLeftCancelMul G]
32+
33+
@[to_additive]
34+
theorem mul_right_injective (a : G) : Injective (a * ·) := fun _ _ ↦ mul_left_cancel
35+
#align mul_right_injective mul_right_injective
36+
#align add_right_injective add_right_injective
37+
38+
@[to_additive (attr := simp)]
39+
theorem mul_right_inj (a : G) {b c : G} : a * b = a * c ↔ b = c :=
40+
(mul_right_injective a).eq_iff
41+
#align mul_right_inj mul_right_inj
42+
#align add_right_inj add_right_inj
43+
44+
@[to_additive]
45+
theorem mul_ne_mul_right (a : G) {b c : G} : a * b ≠ a * c ↔ b ≠ c :=
46+
(mul_right_injective a).ne_iff
47+
#align mul_ne_mul_right mul_ne_mul_right
48+
#align add_ne_add_right add_ne_add_right
49+
50+
end IsLeftCancelMul
51+
52+
section IsRightCancelMul
53+
54+
variable [Mul G] [IsRightCancelMul G]
55+
56+
@[to_additive]
57+
theorem mul_left_injective (a : G) : Function.Injective (· * a) := fun _ _ ↦ mul_right_cancel
58+
#align mul_left_injective mul_left_injective
59+
#align add_left_injective add_left_injective
60+
61+
@[to_additive (attr := simp)]
62+
theorem mul_left_inj (a : G) {b c : G} : b * a = c * a ↔ b = c :=
63+
(mul_left_injective a).eq_iff
64+
#align mul_left_inj mul_left_inj
65+
#align add_left_inj add_left_inj
66+
67+
@[to_additive]
68+
theorem mul_ne_mul_left (a : G) {b c : G} : b * a ≠ c * a ↔ b ≠ c :=
69+
(mul_left_injective a).ne_iff
70+
#align mul_ne_mul_left mul_ne_mul_left
71+
#align add_ne_add_left add_ne_add_left
72+
73+
end IsRightCancelMul
74+
2875
section Semigroup
76+
variable [Semigroup α]
77+
78+
@[to_additive]
79+
instance Semigroup.to_isAssociative : IsAssociative α (· * ·) := ⟨mul_assoc⟩
80+
#align semigroup.to_is_associative Semigroup.to_isAssociative
81+
#align add_semigroup.to_is_associative AddSemigroup.to_isAssociative
2982

3083
/-- Composing two multiplications on the left by `y` then `x`
3184
is equal to a multiplication on the left by `x * y`.
3285
-/
3386
@[to_additive (attr := simp) "Composing two additions on the left by `y` then `x`
3487
is equal to an addition on the left by `x + y`."]
35-
theorem comp_mul_left [Semigroup α] (x y : α) : (x * ·) ∘ (y * ·) = (x * y * ·) := by
88+
theorem comp_mul_left (x y : α) : (x * ·) ∘ (y * ·) = (x * y * ·) := by
3689
ext z
3790
simp [mul_assoc]
3891
#align comp_mul_left comp_mul_left
@@ -43,14 +96,19 @@ is equal to a multiplication on the right by `y * x`.
4396
-/
4497
@[to_additive (attr := simp) "Composing two additions on the right by `y` and `x`
4598
is equal to an addition on the right by `y + x`."]
46-
theorem comp_mul_right [Semigroup α] (x y : α) : (· * x) ∘ (· * y) = (· * (y * x)) := by
99+
theorem comp_mul_right (x y : α) : (· * x) ∘ (· * y) = (· * (y * x)) := by
47100
ext z
48101
simp [mul_assoc]
49102
#align comp_mul_right comp_mul_right
50103
#align comp_add_right comp_add_right
51104

52105
end Semigroup
53106

107+
@[to_additive]
108+
instance CommMagma.to_isCommutative [CommMagma G] : IsCommutative G (· * ·) := ⟨mul_comm⟩
109+
#align comm_semigroup.to_is_commutative CommMagma.to_isCommutative
110+
#align add_comm_semigroup.to_is_commutative AddCommMagma.to_isCommutative
111+
54112
section MulOneClass
55113

56114
variable {M : Type u} [MulOneClass M]

Mathlib/Algebra/Group/Commute/Defs.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Authors: Neil Strickland, Yury Kudryashov
55
-/
66
import Mathlib.Algebra.Group.Semiconj.Defs
77
import Mathlib.Data.Nat.Defs
8+
import Mathlib.Init.Algebra.Classes
89

910
#align_import algebra.group.commute from "leanprover-community/mathlib"@"05101c3df9d9cfe9430edc205860c79b6d660102"
1011

Mathlib/Algebra/Group/Defs.lean

Lines changed: 11 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ Copyright (c) 2014 Jeremy Avigad. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Jeremy Avigad, Leonardo de Moura, Simon Hudon, Mario Carneiro
55
-/
6-
import Mathlib.Init.ZeroOne
76
import Mathlib.Init.Data.Int.Basic
8-
import Mathlib.Logic.Function.Basic
9-
import Mathlib.Tactic.Basic
107
import Mathlib.Init.ZeroOne
8+
import Mathlib.Tactic.Lemma
9+
import Mathlib.Tactic.TypeStar
10+
import Mathlib.Tactic.Simps.Basic
11+
import Mathlib.Tactic.ToAdditive
12+
import Mathlib.Util.AssertExists
1113

1214
#align_import algebra.group.defs from "leanprover-community/mathlib"@"48fb5b5280e7c81672afc9524185ae994553ebf4"
1315

@@ -221,27 +223,10 @@ theorem mul_left_cancel : a * b = a * c → b = c :=
221223

222224
@[to_additive]
223225
theorem mul_left_cancel_iff : a * b = a * c ↔ b = c :=
224-
⟨mul_left_cancel, congr_arg _⟩
226+
⟨mul_left_cancel, congrArg _⟩
225227
#align mul_left_cancel_iff mul_left_cancel_iff
226228
#align add_left_cancel_iff add_left_cancel_iff
227229

228-
@[to_additive]
229-
theorem mul_right_injective (a : G) : Injective (a * ·) := fun _ _ ↦ mul_left_cancel
230-
#align mul_right_injective mul_right_injective
231-
#align add_right_injective add_right_injective
232-
233-
@[to_additive (attr := simp)]
234-
theorem mul_right_inj (a : G) {b c : G} : a * b = a * c ↔ b = c :=
235-
(mul_right_injective a).eq_iff
236-
#align mul_right_inj mul_right_inj
237-
#align add_right_inj add_right_inj
238-
239-
@[to_additive]
240-
theorem mul_ne_mul_right (a : G) {b c : G} : a * b ≠ a * c ↔ b ≠ c :=
241-
(mul_right_injective a).ne_iff
242-
#align mul_ne_mul_right mul_ne_mul_right
243-
#align add_ne_add_right add_ne_add_right
244-
245230
end IsLeftCancelMul
246231

247232
section IsRightCancelMul
@@ -256,27 +241,10 @@ theorem mul_right_cancel : a * b = c * b → a = c :=
256241

257242
@[to_additive]
258243
theorem mul_right_cancel_iff : b * a = c * a ↔ b = c :=
259-
⟨mul_right_cancel, congr_arg (· * a)⟩
244+
⟨mul_right_cancel, congrArg (· * a)⟩
260245
#align mul_right_cancel_iff mul_right_cancel_iff
261246
#align add_right_cancel_iff add_right_cancel_iff
262247

263-
@[to_additive]
264-
theorem mul_left_injective (a : G) : Function.Injective (· * a) := fun _ _ ↦ mul_right_cancel
265-
#align mul_left_injective mul_left_injective
266-
#align add_left_injective add_left_injective
267-
268-
@[to_additive (attr := simp)]
269-
theorem mul_left_inj (a : G) {b c : G} : b * a = c * a ↔ b = c :=
270-
(mul_left_injective a).eq_iff
271-
#align mul_left_inj mul_left_inj
272-
#align add_left_inj add_left_inj
273-
274-
@[to_additive]
275-
theorem mul_ne_mul_left (a : G) {b c : G} : b * a ≠ c * a ↔ b ≠ c :=
276-
(mul_left_injective a).ne_iff
277-
#align mul_ne_mul_left mul_ne_mul_left
278-
#align add_ne_add_left add_ne_add_left
279-
280248
end IsRightCancelMul
281249

282250
end Mul
@@ -311,12 +279,6 @@ theorem mul_assoc : ∀ a b c : G, a * b * c = a * (b * c) :=
311279
#align mul_assoc mul_assoc
312280
#align add_assoc add_assoc
313281

314-
@[to_additive]
315-
instance Semigroup.to_isAssociative : IsAssociative G (· * ·) :=
316-
⟨mul_assoc⟩
317-
#align semigroup.to_is_associative Semigroup.to_isAssociative
318-
#align add_semigroup.to_is_associative AddSemigroup.to_isAssociative
319-
320282
end Semigroup
321283

322284
/-- A commutative addition is a type with an addition which commutes-/
@@ -359,11 +321,6 @@ theorem mul_comm : ∀ a b : G, a * b = b * a := CommMagma.mul_comm
359321
#align mul_comm mul_comm
360322
#align add_comm add_comm
361323

362-
@[to_additive]
363-
instance CommMagma.to_isCommutative : IsCommutative G (· * ·) := ⟨mul_comm⟩
364-
#align comm_semigroup.to_is_commutative CommMagma.to_isCommutative
365-
#align add_comm_semigroup.to_is_commutative AddCommMagma.to_isCommutative
366-
367324
/-- Any `CommMagma G` that satisfies `IsRightCancelMul G` also satisfies `IsLeftCancelMul G`. -/
368325
@[to_additive AddCommMagma.IsRightCancelAdd.toIsLeftCancelAdd "Any `AddCommMagma G` that satisfies
369326
`IsRightCancelAdd G` also satisfies `IsLeftCancelAdd G`."]
@@ -993,7 +950,7 @@ theorem zpow_ofNat (a : G) : ∀ n : ℕ, a ^ (n : ℤ) = a ^ n
993950
| 0 => (zpow_zero _).trans (pow_zero _).symm
994951
| n + 1 => calc
995952
a ^ (↑(n + 1) : ℤ) = a * a ^ (n : ℤ) := DivInvMonoid.zpow_succ' _ _
996-
_ = a * a ^ n := congr_arg (a * ·) (zpow_ofNat a n)
953+
_ = a * a ^ n := congrArg (a * ·) (zpow_ofNat a n)
997954
_ = a ^ (n + 1) := (pow_succ _ _).symm
998955
#align zpow_coe_nat zpow_ofNat
999956
#align zpow_of_nat zpow_ofNat
@@ -1231,12 +1188,6 @@ instance (priority := 100) Group.toCancelMonoid : CancelMonoid G :=
12311188

12321189
end Group
12331190

1234-
@[to_additive]
1235-
theorem Group.toDivInvMonoid_injective {G : Type*} :
1236-
Function.Injective (@Group.toDivInvMonoid G) := by rintro ⟨⟩ ⟨⟩ ⟨⟩; rfl
1237-
#align group.to_div_inv_monoid_injective Group.toDivInvMonoid_injective
1238-
#align add_group.to_sub_neg_add_monoid_injective AddGroup.toSubNegAddMonoid_injective
1239-
12401191
/-- An additive commutative group is an additive group with commutative `(+)`. -/
12411192
class AddCommGroup (G : Type u) extends AddGroup G, AddCommMonoid G
12421193
#align add_comm_group AddCommGroup
@@ -1248,12 +1199,6 @@ class CommGroup (G : Type u) extends Group G, CommMonoid G
12481199

12491200
attribute [to_additive existing] CommGroup.toCommMonoid
12501201

1251-
@[to_additive]
1252-
theorem CommGroup.toGroup_injective {G : Type u} : Function.Injective (@CommGroup.toGroup G) := by
1253-
rintro ⟨⟩ ⟨⟩ ⟨⟩; rfl
1254-
#align comm_group.to_group_injective CommGroup.toGroup_injective
1255-
#align add_comm_group.to_add_group_injective AddCommGroup.toAddGroup_injective
1256-
12571202
section CommGroup
12581203

12591204
variable [CommGroup G]
@@ -1318,3 +1263,6 @@ initialize_simps_projections Group
13181263
initialize_simps_projections AddGroup
13191264
initialize_simps_projections CommGroup
13201265
initialize_simps_projections AddCommGroup
1266+
1267+
assert_not_exists Function.Injective
1268+
assert_not_exists IsCommutative

Mathlib/Algebra/Group/Embedding.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Copyright (c) 2021 Damiano Testa. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Damiano Testa
55
-/
6-
import Mathlib.Algebra.Group.Defs
6+
import Mathlib.Algebra.Group.Basic
77
import Mathlib.Logic.Embedding.Basic
88

99
#align_import algebra.hom.embedding from "leanprover-community/mathlib"@"70d50ecfd4900dd6d328da39ab7ebd516abe4025"

Mathlib/Algebra/Group/Ext.lean

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ former uses `HMul.hMul` which is the canonical spelling.
2727
monoid, group, extensionality
2828
-/
2929

30+
open Function
31+
3032
universe u
3133

3234
@[to_additive (attr := ext)]
@@ -152,6 +154,12 @@ theorem DivInvMonoid.ext {M : Type*} ⦃m₁ m₂ : DivInvMonoid M⦄
152154
#align div_inv_monoid.ext DivInvMonoid.ext
153155
#align sub_neg_monoid.ext SubNegMonoid.ext
154156

157+
@[to_additive]
158+
lemma Group.toDivInvMonoid_injective {G : Type*} : Injective (@Group.toDivInvMonoid G) := by
159+
rintro ⟨⟩ ⟨⟩ ⟨⟩; rfl
160+
#align group.to_div_inv_monoid_injective Group.toDivInvMonoid_injective
161+
#align add_group.to_sub_neg_add_monoid_injective AddGroup.toSubNegAddMonoid_injective
162+
155163
@[to_additive (attr := ext)]
156164
theorem Group.ext {G : Type*} ⦃g₁ g₂ : Group G⦄ (h_mul : g₁.mul = g₂.mul) : g₁ = g₂ := by
157165
have h₁ : g₁.one = g₂.one := congr_arg (·.one) (Monoid.ext h_mul)
@@ -165,6 +173,12 @@ theorem Group.ext {G : Type*} ⦃g₁ g₂ : Group G⦄ (h_mul : g₁.mul = g₂
165173
#align group.ext Group.ext
166174
#align add_group.ext AddGroup.ext
167175

176+
@[to_additive]
177+
lemma CommGroup.toGroup_injective {G : Type*} : Injective (@CommGroup.toGroup G) := by
178+
rintro ⟨⟩ ⟨⟩ ⟨⟩; rfl
179+
#align comm_group.to_group_injective CommGroup.toGroup_injective
180+
#align add_comm_group.to_add_group_injective AddCommGroup.toAddGroup_injective
181+
168182
@[to_additive (attr := ext)]
169183
theorem CommGroup.ext {G : Type*} ⦃g₁ g₂ : CommGroup G⦄ (h_mul : g₁.mul = g₂.mul) : g₁ = g₂ :=
170184
CommGroup.toGroup_injective <| Group.ext h_mul

Mathlib/Algebra/Group/Semiconj/Defs.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Authors: Yury Kudryashov
66
Some proofs and docs came from `algebra/commute` (c) Neil Strickland
77
-/
88
import Mathlib.Algebra.Group.Defs
9+
import Mathlib.Init.Logic
910
import Mathlib.Tactic.Cases
1011

1112
#align_import algebra.group.semiconj from "leanprover-community/mathlib"@"a148d797a1094ab554ad4183a4ad6f130358ef64"

Mathlib/Algebra/Group/WithOne/Defs.lean

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ Copyright (c) 2018 Mario Carneiro. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Mario Carneiro, Johan Commelin
55
-/
6-
import Mathlib.Order.WithBot
76
import Mathlib.Algebra.Ring.Defs
7+
import Mathlib.Order.WithBot
88

99
#align_import algebra.group.with_one.defs from "leanprover-community/mathlib"@"995b47e555f1b6297c7cf16855f1023e355219fb"
1010

@@ -187,20 +187,28 @@ instance mulOneClass [Mul α] : MulOneClass (WithOne α) where
187187
one_mul := (Option.liftOrGet_isLeftId _).1
188188
mul_one := (Option.liftOrGet_isRightId _).1
189189

190-
@[to_additive]
191-
instance monoid [Semigroup α] : Monoid (WithOne α) :=
192-
{ WithOne.mulOneClass with mul_assoc := (Option.liftOrGet_isAssociative _).1 }
193-
194-
@[to_additive]
195-
instance commMonoid [CommSemigroup α] : CommMonoid (WithOne α) :=
196-
{ WithOne.monoid with mul_comm := (Option.liftOrGet_isCommutative _).1 }
197-
198190
@[to_additive (attr := simp, norm_cast)]
199-
theorem coe_mul [Mul α] (a b : α) : ((a * b : α) : WithOne α) = a * b :=
200-
rfl
191+
lemma coe_mul [Mul α] (a b : α) : (↑(a * b) : WithOne α) = a * b := rfl
201192
#align with_one.coe_mul WithOne.coe_mul
202193
#align with_zero.coe_add WithZero.coe_add
203194

195+
@[to_additive]
196+
instance monoid [Semigroup α] : Monoid (WithOne α) where
197+
__ := mulOneClass
198+
mul_assoc a b c := match a, b, c with
199+
| 1, b, c => by simp
200+
| (a : α), 1, c => by simp
201+
| (a : α), (b : α), 1 => by simp
202+
| (a : α), (b : α), (c : α) => by simp_rw [← coe_mul, mul_assoc]
203+
204+
@[to_additive]
205+
instance commMonoid [CommSemigroup α] : CommMonoid (WithOne α) where
206+
mul_comm := fun a b => match a, b with
207+
| (a : α), (b : α) => congr_arg some (mul_comm a b)
208+
| (_ : α), 1 => rfl
209+
| 1, (_ : α) => rfl
210+
| 1, 1 => rfl
211+
204212
@[to_additive (attr := simp, norm_cast)]
205213
theorem coe_inv [Inv α] (a : α) : ((a⁻¹ : α) : WithOne α) = (a : WithOne α)⁻¹ :=
206214
rfl
@@ -392,3 +400,9 @@ instance semiring [Semiring α] : Semiring (WithZero α) :=
392400
WithZero.monoidWithZero, WithZero.instDistrib with }
393401

394402
end WithZero
403+
404+
-- Check that we haven't needed to import all the basic lemmas about groups,
405+
-- by asserting a random sample don't exist here:
406+
assert_not_exists inv_involutive
407+
assert_not_exists div_right_inj
408+
assert_not_exists pow_ite

0 commit comments

Comments
 (0)