Skip to content

Commit b4e2ffb

Browse files
committed
chore(GroupTheory): erw cleanup (#23406)
Some more proof refactoring so that we can get rid of `erw`s. One issue appearing in a few places is `SetLike.coeSort_coe` (saying coercing to a set, then to a sort is the same as the generic `SetLike` coercion to sort) making it impossible to apply lemmas involving elements of subgroups coerced to sets coerced to types. Maybe remove it from the `dsimp` set?
1 parent 8bd5208 commit b4e2ffb

File tree

8 files changed

+41
-53
lines changed

8 files changed

+41
-53
lines changed

Mathlib/GroupTheory/CoprodI.lean

+4-5
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ variable {N : Type*} [Monoid N]
134134
theorem ext_hom (f g : CoprodI M →* N) (h : ∀ i, f.comp (of : M i →* _) = g.comp of) : f = g :=
135135
(MonoidHom.cancel_right Con.mk'_surjective).mp <|
136136
FreeMonoid.hom_eq fun ⟨i, x⟩ => by
137-
-- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644
138-
erw [MonoidHom.comp_apply, MonoidHom.comp_apply, ← of_apply, ← MonoidHom.comp_apply, ←
139-
MonoidHom.comp_apply, h]; rfl
137+
rw [MonoidHom.comp_apply, MonoidHom.comp_apply, ← of_apply]
138+
unfold CoprodI
139+
rw [← MonoidHom.comp_apply, ← MonoidHom.comp_apply, h]
140140

141141
/-- A map out of the free product corresponds to a family of maps out of the summands. This is the
142142
universal property of the free product, characterizing it as a categorical coproduct. -/
@@ -151,8 +151,7 @@ def lift : (∀ i, M i →* N) ≃ (CoprodI M →* N) where
151151
left_inv := by
152152
intro fi
153153
ext i x
154-
-- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644
155-
erw [MonoidHom.comp_apply, of_apply, Con.lift_mk', FreeMonoid.lift_eval_of]
154+
rfl
156155
right_inv := by
157156
intro f
158157
ext i x

Mathlib/GroupTheory/FreeGroup/NielsenSchreier.lean

+3-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,9 @@ lemma endIsFree : IsFreeGroup (End (root' T)) :=
219219
refine ⟨F'.mapEnd _, ?_, ?_⟩
220220
· suffices ∀ {x y} (q : x ⟶ y), F'.map (loopOfHom T q) = (F'.map q : X) by
221221
rintro ⟨⟨a, b, e⟩, h⟩
222-
erw [Functor.mapEnd_apply, this, hF']
222+
-- Work around the defeq `X = End (F'.obj (IsFreeGroupoid.SpanningTree.root' T))`
223+
erw [Functor.mapEnd_apply]
224+
rw [this, hF']
223225
exact dif_neg h
224226
intros x y q
225227
suffices ∀ {a} (p : Path (root T) a), F'.map (homOfPath T p) = 1 by

Mathlib/GroupTheory/GroupAction/Defs.lean

+5-2
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ theorem smul_mem_orbit_smul (g h : G) (a : α) : g • a ∈ orbit G (h • a) :
237237
instance instMulAction (H : Subgroup G) : MulAction H α :=
238238
inferInstanceAs (MulAction H.toSubmonoid α)
239239

240+
@[to_additive]
241+
lemma subgroup_smul_def {H : Subgroup G} (a : H) (b : α) : a • b = (a : G) • b := rfl
242+
240243
@[to_additive]
241244
lemma orbit_subgroup_subset (H : Subgroup G) (a : α) : orbit H a ⊆ orbit G a :=
242245
orbit_submonoid_subset H.toSubmonoid a
@@ -258,7 +261,7 @@ lemma mem_subgroup_orbit_iff {H : Subgroup G} {x : α} {a b : orbit G x} :
258261
exact MulAction.mem_orbit _ g
259262
· rcases h with ⟨g, h⟩
260263
dsimp at h
261-
erw [← orbit.coe_smul, ← Subtype.ext_iff] at h
264+
rw [subgroup_smul_def, ← orbit.coe_smul, ← Subtype.ext_iff] at h
262265
subst h
263266
exact MulAction.mem_orbit _ g
264267

@@ -422,7 +425,7 @@ lemma orbitRel.Quotient.mem_subgroup_orbit_iff {H : Subgroup G} {x : orbitRel.Qu
422425
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
423426
· rcases h with ⟨g, h⟩
424427
dsimp at h
425-
erw [← orbit.coe_smul, ← Subtype.ext_iff] at h
428+
rw [subgroup_smul_def, ← orbit.coe_smul, ← Subtype.ext_iff] at h
426429
subst h
427430
exact MulAction.mem_orbit _ g
428431
· rcases h with ⟨g, rfl⟩

Mathlib/GroupTheory/HNNExtension.lean

+15-21
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,7 @@ theorem toSubgroupEquiv_neg_one : toSubgroupEquiv φ (-1) = φ.symm := rfl
167167
theorem toSubgroupEquiv_neg_apply (u : ℤˣ) (a : toSubgroup A B u) :
168168
(toSubgroupEquiv φ (-u) (toSubgroupEquiv φ u a) : G) = a := by
169169
rcases Int.units_eq_one_or u with rfl | rfl
170-
· -- This used to be `simp` before https://github.com/leanprover/lean4/pull/2644
171-
simp; erw [MulEquiv.symm_apply_apply]
170+
· simp [toSubgroup]
172171
· simp only [toSubgroup_neg_one, toSubgroupEquiv_neg_one, SetLike.coe_eq_coe]
173172
exact φ.apply_symm_apply a
174173

@@ -419,10 +418,8 @@ theorem unitsSMul_neg (u : ℤˣ) (w : NormalWord d) :
419418
· have hncan : ¬ Cancels u w := (unitsSMul_cancels_iff _ _ _).1 hcan
420419
unfold unitsSMul
421420
simp only [dif_neg hncan]
422-
simp [unitsSMulWithCancel, unitsSMulGroup, (d.compl u).equiv_snd_eq_inv_mul]
423-
-- This used to be the end of the proof before https://github.com/leanprover/lean4/pull/2644
424-
erw [(d.compl u).equiv_snd_eq_inv_mul]
425-
simp
421+
simp [unitsSMulWithCancel, unitsSMulGroup, (d.compl u).equiv_snd_eq_inv_mul,
422+
-SetLike.coe_sort_coe]
426423
· have hcan2 : Cancels u w := not_not.1 (mt (unitsSMul_cancels_iff _ _ _).2 hcan)
427424
unfold unitsSMul at hcan ⊢
428425
simp only [dif_pos hcan2] at hcan ⊢
@@ -445,10 +442,8 @@ theorem unitsSMul_neg (u : ℤˣ) (w : NormalWord d) :
445442
· -- The next two lines were not needed before https://github.com/leanprover/lean4/pull/2644
446443
dsimp
447444
conv_lhs => erw [IsComplement.equiv_mul_left]
448-
simp [mul_assoc, Units.ext_iff, (d.compl (-u)).equiv_snd_eq_inv_mul, this]
449-
-- The next two lines were not needed before https://github.com/leanprover/lean4/pull/2644
450-
erw [(d.compl (-u)).equiv_snd_eq_inv_mul, this]
451-
simp
445+
simp [mul_assoc, Units.ext_iff, (d.compl (-u)).equiv_snd_eq_inv_mul, this,
446+
-SetLike.coe_sort_coe]
452447

453448
/-- the equivalence given by multiplication on the left by `t` -/
454449
@[simps]
@@ -562,15 +557,12 @@ theorem prod_smul_empty (w : NormalWord d) :
562557
rw [prod_cons, ← mul_assoc, mul_smul, ih, mul_smul, t_pow_smul_eq_unitsSMul,
563558
of_smul_eq_smul, unitsSMul]
564559
rw [dif_neg (not_cancels_of_cons_hyp u w h2)]
565-
-- The next 3 lines were a single `simp [...]` before https://github.com/leanprover/lean4/pull/2644
566-
simp only [unitsSMulGroup]
567-
simp_rw [SetLike.coe_sort_coe]
568-
erw [(d.compl _).equiv_fst_eq_one_of_mem_of_one_mem (one_mem _) h1]
569-
ext <;> simp
570-
-- The next 4 were not needed before https://github.com/leanprover/lean4/pull/2644
571-
erw [(d.compl _).equiv_snd_eq_inv_mul]
572-
simp_rw [SetLike.coe_sort_coe]
573-
erw [(d.compl _).equiv_fst_eq_one_of_mem_of_one_mem (one_mem _) h1]
560+
simp [unitsSMulGroup, (d.compl _).equiv_fst_eq_one_of_mem_of_one_mem (one_mem _) h1,
561+
-SetLike.coe_sort_coe]
562+
ext <;> simp [-SetLike.coe_sort_coe]
563+
-- The next 3 lines were not needed before https://github.com/leanprover/lean4/pull/2644
564+
rw [(d.compl _).equiv_snd_eq_inv_mul,
565+
(d.compl _).equiv_fst_eq_one_of_mem_of_one_mem (one_mem _) h1]
574566
simp
575567

576568
variable (d)
@@ -650,8 +642,10 @@ theorem exists_normalWord_prod_eq
650642
(List.head?_eq_head _) hS
651643
rwa [List.head?_eq_head hl, Option.map_some', ← this, Option.some_inj] at hx'
652644
simp at this
653-
erw [List.map_cons, mul_smul, of_smul_eq_smul, NormalWord.group_smul_def,
654-
t_pow_smul_eq_unitsSMul, unitsSMul, dif_neg this, ← hw'2]
645+
rw [List.map_cons, mul_smul, of_smul_eq_smul, NormalWord.group_smul_def,
646+
t_pow_smul_eq_unitsSMul, unitsSMul]
647+
erw [dif_neg this]
648+
rw [← hw'2]
655649
simp [mul_assoc, unitsSMulGroup, (d.compl _).coe_equiv_snd_eq_one_iff_mem]
656650

657651
/-- Two reduced words representing the same element of the `HNNExtension G A B φ` have the same

Mathlib/GroupTheory/Perm/Cycle/Basic.lean

+4-14
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ noncomputable def IsCycle.zpowersEquivSupport {σ : Perm α} (hσ : IsCycle σ)
314314
(fun (τ : ↥ ((Subgroup.zpowers σ) : Set (Perm α))) =>
315315
⟨(τ : Perm α) (Classical.choose hσ), by
316316
obtain ⟨τ, n, rfl⟩ := τ
317-
erw [Finset.mem_coe, Subtype.coe_mk, zpow_apply_mem_support, mem_support]
317+
rw [Subtype.coe_mk, zpow_apply_mem_support, mem_support]
318318
exact (Classical.choose_spec hσ).1⟩)
319319
(by
320320
constructor
@@ -326,7 +326,7 @@ noncomputable def IsCycle.zpowersEquivSupport {σ : Perm α} (hσ : IsCycle σ)
326326
rw [Subtype.coe_mk, Subtype.coe_mk, zpow_apply_comm σ m i, zpow_apply_comm σ n i]
327327
exact congr_arg _ (Subtype.ext_iff.mp h)
328328
· rintro ⟨y, hy⟩
329-
erw [Finset.mem_coe, mem_support] at hy
329+
rw [mem_support] at hy
330330
obtain ⟨n, rfl⟩ := (Classical.choose_spec hσ).2 hy
331331
exact ⟨⟨σ ^ n, n, rfl⟩, rfl⟩)
332332

@@ -647,14 +647,7 @@ theorem IsCycle.isConj (hσ : IsCycle σ) (hτ : IsCycle τ) (h : #σ.support =
647647
intro x hx
648648
simp only [Perm.mul_apply, Equiv.trans_apply, Equiv.sumCongr_apply]
649649
obtain ⟨n, rfl⟩ := hσ.exists_pow_eq (Classical.choose_spec hσ).1 (mem_support.1 hx)
650-
erw [hσ.zpowersEquivSupport_symm_apply n]
651-
simp only [← Perm.mul_apply, ← pow_succ']
652-
erw [hσ.zpowersEquivSupport_symm_apply (n + 1)]
653-
-- This used to be a `simp only` before https://github.com/leanprover/lean4/pull/2644
654-
erw [zpowersEquivZPowers_apply, zpowersEquivZPowers_apply, zpowersEquivSupport_apply]
655-
-- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644
656-
simp_rw [pow_succ', Perm.mul_apply]
657-
rfl
650+
simp [← Perm.mul_apply, ← pow_succ']
658651

659652
theorem IsCycle.isConj_iff (hσ : IsCycle σ) (hτ : IsCycle τ) :
660653
IsConj σ τ ↔ #σ.support = #τ.support where
@@ -774,10 +767,7 @@ theorem IsCycleOn.pow_apply_eq {s : Finset α} (hf : f.IsCycleOn s) (ha : a ∈
774767
rw [← this, orderOf_dvd_iff_pow_eq_one,
775768
(hf.isCycle_subtypePerm hs).pow_eq_one_iff'
776769
(ne_of_apply_ne ((↑) : s → α) <| hf.apply_ne hs (⟨a, ha⟩ : s).2)]
777-
simp
778-
-- This used to be the end of the proof before https://github.com/leanprover/lean4/pull/2644
779-
erw [subtypePerm_apply]
780-
simp
770+
simp [-coe_sort_coe]
781771

782772
theorem IsCycleOn.zpow_apply_eq {s : Finset α} (hf : f.IsCycleOn s) (ha : a ∈ s) :
783773
∀ {n : ℤ}, (f ^ n) a = a ↔ (#s : ℤ) ∣ n

Mathlib/GroupTheory/Perm/Fin.lean

+3-4
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,9 @@ theorem cycleRange_of_le {n : ℕ} [NeZero n] {i j : Fin n} (h : j ≤ i) :
153153
have : j = (Fin.castLE (Nat.succ_le_of_lt i.is_lt))
154154
⟨j, lt_of_le_of_lt h (Nat.lt_succ_self i)⟩ := by simp
155155
ext
156-
erw [this, cycleRange, ofLeftInverse'_eq_ofInjective, ←
157-
Function.Embedding.toEquivRange_eq_ofInjective, ← viaFintypeEmbedding,
158-
viaFintypeEmbedding_apply_image, Function.Embedding.coeFn_mk,
159-
coe_castLE, coe_finRotate]
156+
rw [this, cycleRange, ofLeftInverse'_eq_ofInjective, ←
157+
Function.Embedding.toEquivRange_eq_ofInjective, ← viaFintypeEmbedding, ← coe_castLEEmb,
158+
viaFintypeEmbedding_apply_image, coe_castLEEmb, coe_castLE, coe_finRotate]
160159
simp only [Fin.ext_iff, val_last, val_mk, val_zero, Fin.eta, castLE_mk]
161160
split_ifs with heq
162161
· rfl

Mathlib/GroupTheory/Perm/Finite.lean

+5-5
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,12 @@ theorem mem_sumCongrHom_range_of_perm_mapsTo_inl {m n : Type*} [Finite m] [Finit
142142
· rw [Equiv.sumCongr_apply, Sum.map_inl, permCongr_apply, Equiv.symm_symm,
143143
apply_ofInjective_symm Sum.inl_injective]
144144
rw [ofInjective_apply, Subtype.coe_mk, Subtype.coe_mk]
145-
-- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644
146-
erw [subtypePerm_apply]
145+
dsimp [Set.range]
146+
rw [subtypePerm_apply]
147147
· rw [Equiv.sumCongr_apply, Sum.map_inr, permCongr_apply, Equiv.symm_symm,
148-
apply_ofInjective_symm Sum.inr_injective]
149-
erw [subtypePerm_apply]
150-
rw [ofInjective_apply, Subtype.coe_mk, Subtype.coe_mk]
148+
apply_ofInjective_symm Sum.inr_injective, ofInjective_apply]
149+
dsimp [Set.range]
150+
rw [subtypePerm_apply]
151151

152152
nonrec theorem Disjoint.orderOf {σ τ : Perm α} (hστ : Disjoint σ τ) :
153153
orderOf (σ * τ) = Nat.lcm (orderOf σ) (orderOf τ) :=

Mathlib/GroupTheory/Torsion.lean

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ noncomputable def IsTorsion.group [Monoid G] (tG : IsTorsion G) : Group G :=
6666
{ ‹Monoid G› with
6767
inv := fun g => g ^ (orderOf g - 1)
6868
inv_mul_cancel := fun g => by
69-
erw [← pow_succ, tsub_add_cancel_of_le, pow_orderOf_eq_one]
69+
dsimp only
70+
rw [← pow_succ, tsub_add_cancel_of_le, pow_orderOf_eq_one]
7071
exact (tG g).orderOf_pos }
7172

7273
section Group

0 commit comments

Comments
 (0)