path
stringlengths
11
71
content
stringlengths
75
124k
GroupTheory\Index.lean
/- Copyright (c) 2021 Thomas Browning. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning -/ import Mathlib.Algebra.BigOperators.GroupWithZero.Finset import Mathlib.GroupTheory.Finiteness import Mathlib.GroupTheory.GroupAction.Quotient /-! # Index of a Subgroup In this file we define the index of a subgroup, and prove several divisibility properties. Several theorems proved in this file are known as Lagrange's theorem. ## Main definitions - `H.index` : the index of `H : Subgroup G` as a natural number, and returns 0 if the index is infinite. - `H.relindex K` : the relative index of `H : Subgroup G` in `K : Subgroup G` as a natural number, and returns 0 if the relative index is infinite. # Main results - `card_mul_index` : `Nat.card H * H.index = Nat.card G` - `index_mul_card` : `H.index * Fintype.card H = Fintype.card G` - `index_dvd_card` : `H.index ∣ Fintype.card G` - `relindex_mul_index` : If `H ≤ K`, then `H.relindex K * K.index = H.index` - `index_dvd_of_le` : If `H ≤ K`, then `K.index ∣ H.index` - `relindex_mul_relindex` : `relindex` is multiplicative in towers -/ namespace Subgroup open Cardinal variable {G G' : Type*} [Group G] [Group G'] (H K L : Subgroup G) /-- The index of a subgroup as a natural number, and returns 0 if the index is infinite. -/ @[to_additive "The index of a subgroup as a natural number, and returns 0 if the index is infinite."] noncomputable def index : ℕ := Nat.card (G ⧸ H) /-- The relative index of a subgroup as a natural number, and returns 0 if the relative index is infinite. -/ @[to_additive "The relative index of a subgroup as a natural number, and returns 0 if the relative index is infinite."] noncomputable def relindex : ℕ := (H.subgroupOf K).index @[to_additive] theorem index_comap_of_surjective {f : G' →* G} (hf : Function.Surjective f) : (H.comap f).index = H.index := by letI := QuotientGroup.leftRel H letI := QuotientGroup.leftRel (H.comap f) have key : ∀ x y : G', Setoid.r x y ↔ Setoid.r (f x) (f y) := by simp only [QuotientGroup.leftRel_apply] exact fun x y => iff_of_eq (congr_arg (· ∈ H) (by rw [f.map_mul, f.map_inv])) refine Cardinal.toNat_congr (Equiv.ofBijective (Quotient.map' f fun x y => (key x y).mp) ⟨?_, ?_⟩) · simp_rw [← Quotient.eq''] at key refine Quotient.ind' fun x => ?_ refine Quotient.ind' fun y => ?_ exact (key x y).mpr · refine Quotient.ind' fun x => ?_ obtain ⟨y, hy⟩ := hf x exact ⟨y, (Quotient.map'_mk'' f _ y).trans (congr_arg Quotient.mk'' hy)⟩ @[to_additive] theorem index_comap (f : G' →* G) : (H.comap f).index = H.relindex f.range := Eq.trans (congr_arg index (by rfl)) ((H.subgroupOf f.range).index_comap_of_surjective f.rangeRestrict_surjective) @[to_additive] theorem relindex_comap (f : G' →* G) (K : Subgroup G') : relindex (comap f H) K = relindex H (map f K) := by rw [relindex, subgroupOf, comap_comap, index_comap, ← f.map_range, K.subtype_range] variable {H K L} @[to_additive relindex_mul_index] theorem relindex_mul_index (h : H ≤ K) : H.relindex K * K.index = H.index := ((mul_comm _ _).trans (Cardinal.toNat_mul _ _).symm).trans (congr_arg Cardinal.toNat (Equiv.cardinal_eq (quotientEquivProdOfLE h))).symm @[to_additive] theorem index_dvd_of_le (h : H ≤ K) : K.index ∣ H.index := dvd_of_mul_left_eq (H.relindex K) (relindex_mul_index h) @[to_additive] theorem relindex_dvd_index_of_le (h : H ≤ K) : H.relindex K ∣ H.index := dvd_of_mul_right_eq K.index (relindex_mul_index h) @[to_additive] theorem relindex_subgroupOf (hKL : K ≤ L) : (H.subgroupOf L).relindex (K.subgroupOf L) = H.relindex K := ((index_comap (H.subgroupOf L) (inclusion hKL)).trans (congr_arg _ (inclusion_range hKL))).symm variable (H K L) @[to_additive relindex_mul_relindex] theorem relindex_mul_relindex (hHK : H ≤ K) (hKL : K ≤ L) : H.relindex K * K.relindex L = H.relindex L := by rw [← relindex_subgroupOf hKL] exact relindex_mul_index fun x hx => hHK hx @[to_additive] theorem inf_relindex_right : (H ⊓ K).relindex K = H.relindex K := by rw [relindex, relindex, inf_subgroupOf_right] @[to_additive] theorem inf_relindex_left : (H ⊓ K).relindex H = K.relindex H := by rw [inf_comm, inf_relindex_right] @[to_additive relindex_inf_mul_relindex] theorem relindex_inf_mul_relindex : H.relindex (K ⊓ L) * K.relindex L = (H ⊓ K).relindex L := by rw [← inf_relindex_right H (K ⊓ L), ← inf_relindex_right K L, ← inf_relindex_right (H ⊓ K) L, inf_assoc, relindex_mul_relindex (H ⊓ (K ⊓ L)) (K ⊓ L) L inf_le_right inf_le_right] @[to_additive (attr := simp)] theorem relindex_sup_right [K.Normal] : K.relindex (H ⊔ K) = K.relindex H := Nat.card_congr (QuotientGroup.quotientInfEquivProdNormalQuotient H K).toEquiv.symm @[to_additive (attr := simp)] theorem relindex_sup_left [K.Normal] : K.relindex (K ⊔ H) = K.relindex H := by rw [sup_comm, relindex_sup_right] @[to_additive] theorem relindex_dvd_index_of_normal [H.Normal] : H.relindex K ∣ H.index := relindex_sup_right K H ▸ relindex_dvd_index_of_le le_sup_right variable {H K} @[to_additive] theorem relindex_dvd_of_le_left (hHK : H ≤ K) : K.relindex L ∣ H.relindex L := inf_of_le_left hHK ▸ dvd_of_mul_left_eq _ (relindex_inf_mul_relindex _ _ _) /-- A subgroup has index two if and only if there exists `a` such that for all `b`, exactly one of `b * a` and `b` belong to `H`. -/ @[to_additive "An additive subgroup has index two if and only if there exists `a` such that for all `b`, exactly one of `b + a` and `b` belong to `H`."] theorem index_eq_two_iff : H.index = 2 ↔ ∃ a, ∀ b, Xor' (b * a ∈ H) (b ∈ H) := by simp only [index, Nat.card_eq_two_iff' ((1 : G) : G ⧸ H), ExistsUnique, inv_mem_iff, QuotientGroup.exists_mk, QuotientGroup.forall_mk, Ne, QuotientGroup.eq, mul_one, xor_iff_iff_not] refine exists_congr fun a => ⟨fun ha b => ⟨fun hba hb => ?_, fun hb => ?_⟩, fun ha => ⟨?_, fun b hb => ?_⟩⟩ · exact ha.1 ((mul_mem_cancel_left hb).1 hba) · exact inv_inv b ▸ ha.2 _ (mt (inv_mem_iff (x := b)).1 hb) · rw [← inv_mem_iff (x := a), ← ha, inv_mul_self] exact one_mem _ · rwa [ha, inv_mem_iff (x := b)] @[to_additive] theorem mul_mem_iff_of_index_two (h : H.index = 2) {a b : G} : a * b ∈ H ↔ (a ∈ H ↔ b ∈ H) := by by_cases ha : a ∈ H; · simp only [ha, true_iff_iff, mul_mem_cancel_left ha] by_cases hb : b ∈ H; · simp only [hb, iff_true_iff, mul_mem_cancel_right hb] simp only [ha, hb, iff_self_iff, iff_true_iff] rcases index_eq_two_iff.1 h with ⟨c, hc⟩ refine (hc _).or.resolve_left ?_ rwa [mul_assoc, mul_mem_cancel_right ((hc _).or.resolve_right hb)] @[to_additive] theorem mul_self_mem_of_index_two (h : H.index = 2) (a : G) : a * a ∈ H := by rw [mul_mem_iff_of_index_two h] @[to_additive two_smul_mem_of_index_two] theorem sq_mem_of_index_two (h : H.index = 2) (a : G) : a ^ 2 ∈ H := (pow_two a).symm ▸ mul_self_mem_of_index_two h a variable (H K) -- Porting note: had to replace `Cardinal.toNat_eq_one_iff_unique` with `Nat.card_eq_one_iff_unique` @[to_additive (attr := simp)] theorem index_top : (⊤ : Subgroup G).index = 1 := Nat.card_eq_one_iff_unique.mpr ⟨QuotientGroup.subsingleton_quotient_top, ⟨1⟩⟩ @[to_additive (attr := simp)] theorem index_bot : (⊥ : Subgroup G).index = Nat.card G := Cardinal.toNat_congr QuotientGroup.quotientBot.toEquiv @[deprecated (since := "2024-06-15")] alias index_bot_eq_card := index_bot @[to_additive (attr := simp)] theorem relindex_top_left : (⊤ : Subgroup G).relindex H = 1 := index_top @[to_additive (attr := simp)] theorem relindex_top_right : H.relindex ⊤ = H.index := by rw [← relindex_mul_index (show H ≤ ⊤ from le_top), index_top, mul_one] @[to_additive (attr := simp)] theorem relindex_bot_left : (⊥ : Subgroup G).relindex H = Nat.card H := by rw [relindex, bot_subgroupOf, index_bot] @[deprecated (since := "2024-06-15")] alias relindex_bot_left_eq_card := relindex_bot_left @[to_additive (attr := simp)] theorem relindex_bot_right : H.relindex ⊥ = 1 := by rw [relindex, subgroupOf_bot_eq_top, index_top] @[to_additive (attr := simp)] theorem relindex_self : H.relindex H = 1 := by rw [relindex, subgroupOf_self, index_top] @[to_additive] theorem index_ker (f : G →* G') : f.ker.index = Nat.card (Set.range f) := by rw [← MonoidHom.comap_bot, index_comap, relindex_bot_left] rfl @[to_additive] theorem relindex_ker (f : G →* G') (K : Subgroup G) : f.ker.relindex K = Nat.card (f '' K) := by rw [← MonoidHom.comap_bot, relindex_comap, relindex_bot_left] rfl @[to_additive (attr := simp) card_mul_index] theorem card_mul_index : Nat.card H * H.index = Nat.card G := by rw [← relindex_bot_left, ← index_bot] exact relindex_mul_index bot_le @[deprecated (since := "2024-06-15")] alias nat_card_dvd_of_injective := card_dvd_of_injective @[deprecated (since := "2024-06-15")] alias nat_card_dvd_of_le := card_dvd_of_le @[to_additive] theorem card_dvd_of_surjective (f : G →* G') (hf : Function.Surjective f) : Nat.card G' ∣ Nat.card G := by rw [← Nat.card_congr (QuotientGroup.quotientKerEquivOfSurjective f hf).toEquiv] exact Dvd.intro_left (Nat.card f.ker) f.ker.card_mul_index @[deprecated (since := "2024-06-15")] alias nat_card_dvd_of_surjective := card_dvd_of_surjective @[to_additive] theorem index_map (f : G →* G') : (H.map f).index = (H ⊔ f.ker).index * f.range.index := by rw [← comap_map_eq, index_comap, relindex_mul_index (H.map_le_range f)] @[to_additive] theorem index_map_dvd {f : G →* G'} (hf : Function.Surjective f) : (H.map f).index ∣ H.index := by rw [index_map, f.range_top_of_surjective hf, index_top, mul_one] exact index_dvd_of_le le_sup_left @[to_additive] theorem dvd_index_map {f : G →* G'} (hf : f.ker ≤ H) : H.index ∣ (H.map f).index := by rw [index_map, sup_of_le_left hf] apply dvd_mul_right @[to_additive] theorem index_map_eq {f : G →* G'} (hf1 : Function.Surjective f) (hf2 : f.ker ≤ H) : (H.map f).index = H.index := Nat.dvd_antisymm (H.index_map_dvd hf1) (H.dvd_index_map hf2) @[to_additive] theorem index_eq_card : H.index = Nat.card (G ⧸ H) := rfl @[to_additive index_mul_card] theorem index_mul_card : H.index * Nat.card H = Nat.card G := by rw [mul_comm, card_mul_index] @[to_additive] theorem index_dvd_card : H.index ∣ Nat.card G := ⟨Nat.card H, H.index_mul_card.symm⟩ variable {H K L} @[to_additive] theorem relindex_eq_zero_of_le_left (hHK : H ≤ K) (hKL : K.relindex L = 0) : H.relindex L = 0 := eq_zero_of_zero_dvd (hKL ▸ relindex_dvd_of_le_left L hHK) @[to_additive] theorem relindex_eq_zero_of_le_right (hKL : K ≤ L) (hHK : H.relindex K = 0) : H.relindex L = 0 := Finite.card_eq_zero_of_embedding (quotientSubgroupOfEmbeddingOfLE H hKL) hHK @[to_additive] theorem index_eq_zero_of_relindex_eq_zero (h : H.relindex K = 0) : H.index = 0 := H.relindex_top_right.symm.trans (relindex_eq_zero_of_le_right le_top h) @[to_additive] theorem relindex_le_of_le_left (hHK : H ≤ K) (hHL : H.relindex L ≠ 0) : K.relindex L ≤ H.relindex L := Nat.le_of_dvd (Nat.pos_of_ne_zero hHL) (relindex_dvd_of_le_left L hHK) @[to_additive] theorem relindex_le_of_le_right (hKL : K ≤ L) (hHL : H.relindex L ≠ 0) : H.relindex K ≤ H.relindex L := Finite.card_le_of_embedding' (quotientSubgroupOfEmbeddingOfLE H hKL) fun h => (hHL h).elim @[to_additive] theorem relindex_ne_zero_trans (hHK : H.relindex K ≠ 0) (hKL : K.relindex L ≠ 0) : H.relindex L ≠ 0 := fun h => mul_ne_zero (mt (relindex_eq_zero_of_le_right (show K ⊓ L ≤ K from inf_le_left)) hHK) hKL ((relindex_inf_mul_relindex H K L).trans (relindex_eq_zero_of_le_left inf_le_left h)) @[to_additive] theorem relindex_inf_ne_zero (hH : H.relindex L ≠ 0) (hK : K.relindex L ≠ 0) : (H ⊓ K).relindex L ≠ 0 := by replace hH : H.relindex (K ⊓ L) ≠ 0 := mt (relindex_eq_zero_of_le_right inf_le_right) hH rw [← inf_relindex_right] at hH hK ⊢ rw [inf_assoc] exact relindex_ne_zero_trans hH hK @[to_additive] theorem index_inf_ne_zero (hH : H.index ≠ 0) (hK : K.index ≠ 0) : (H ⊓ K).index ≠ 0 := by rw [← relindex_top_right] at hH hK ⊢ exact relindex_inf_ne_zero hH hK @[to_additive] theorem relindex_inf_le : (H ⊓ K).relindex L ≤ H.relindex L * K.relindex L := by by_cases h : H.relindex L = 0 · exact (le_of_eq (relindex_eq_zero_of_le_left inf_le_left h)).trans (zero_le _) rw [← inf_relindex_right, inf_assoc, ← relindex_mul_relindex _ _ L inf_le_right inf_le_right, inf_relindex_right, inf_relindex_right] exact mul_le_mul_right' (relindex_le_of_le_right inf_le_right h) (K.relindex L) @[to_additive] theorem index_inf_le : (H ⊓ K).index ≤ H.index * K.index := by simp_rw [← relindex_top_right, relindex_inf_le] @[to_additive] theorem relindex_iInf_ne_zero {ι : Type*} [_hι : Finite ι] {f : ι → Subgroup G} (hf : ∀ i, (f i).relindex L ≠ 0) : (⨅ i, f i).relindex L ≠ 0 := haveI := Fintype.ofFinite ι (Finset.prod_ne_zero_iff.mpr fun i _hi => hf i) ∘ Nat.card_pi.symm.trans ∘ Finite.card_eq_zero_of_embedding (quotientiInfSubgroupOfEmbedding f L) @[to_additive] theorem relindex_iInf_le {ι : Type*} [Fintype ι] (f : ι → Subgroup G) : (⨅ i, f i).relindex L ≤ ∏ i, (f i).relindex L := le_of_le_of_eq (Finite.card_le_of_embedding' (quotientiInfSubgroupOfEmbedding f L) fun h => let ⟨i, _hi, h⟩ := Finset.prod_eq_zero_iff.mp (Nat.card_pi.symm.trans h) relindex_eq_zero_of_le_left (iInf_le f i) h) Nat.card_pi @[to_additive] theorem index_iInf_ne_zero {ι : Type*} [Finite ι] {f : ι → Subgroup G} (hf : ∀ i, (f i).index ≠ 0) : (⨅ i, f i).index ≠ 0 := by simp_rw [← relindex_top_right] at hf ⊢ exact relindex_iInf_ne_zero hf @[to_additive] theorem index_iInf_le {ι : Type*} [Fintype ι] (f : ι → Subgroup G) : (⨅ i, f i).index ≤ ∏ i, (f i).index := by simp_rw [← relindex_top_right, relindex_iInf_le] -- Porting note: had to replace `Cardinal.toNat_eq_one_iff_unique` with `Nat.card_eq_one_iff_unique` @[to_additive (attr := simp) index_eq_one] theorem index_eq_one : H.index = 1 ↔ H = ⊤ := ⟨fun h => QuotientGroup.subgroup_eq_top_of_subsingleton H (Nat.card_eq_one_iff_unique.mp h).1, fun h => (congr_arg index h).trans index_top⟩ @[to_additive (attr := simp) relindex_eq_one] theorem relindex_eq_one : H.relindex K = 1 ↔ K ≤ H := index_eq_one.trans subgroupOf_eq_top @[to_additive (attr := simp) card_eq_one] theorem card_eq_one : Nat.card H = 1 ↔ H = ⊥ := H.relindex_bot_left ▸ relindex_eq_one.trans le_bot_iff @[to_additive] theorem index_ne_zero_of_finite [hH : Finite (G ⧸ H)] : H.index ≠ 0 := by cases nonempty_fintype (G ⧸ H) rw [index_eq_card] exact Nat.card_pos.ne' -- Porting note: changed due to error with `Cardinal.toNat_apply_of_aleph0_le` /-- Finite index implies finite quotient. -/ @[to_additive "Finite index implies finite quotient."] noncomputable def fintypeOfIndexNeZero (hH : H.index ≠ 0) : Fintype (G ⧸ H) := @Fintype.ofFinite _ (Nat.finite_of_card_ne_zero hH) @[to_additive] lemma index_eq_zero_iff_infinite : H.index = 0 ↔ Infinite (G ⧸ H) := by simp [index_eq_card, Nat.card_eq_zero] @[to_additive one_lt_index_of_ne_top] theorem one_lt_index_of_ne_top [Finite (G ⧸ H)] (hH : H ≠ ⊤) : 1 < H.index := Nat.one_lt_iff_ne_zero_and_ne_one.mpr ⟨index_ne_zero_of_finite, mt index_eq_one.mp hH⟩ @[to_additive] lemma finite_quotient_of_finite_quotient_of_index_ne_zero {X : Type*} [MulAction G X] [Finite <| MulAction.orbitRel.Quotient G X] (hi : H.index ≠ 0) : Finite <| MulAction.orbitRel.Quotient H X := by have := fintypeOfIndexNeZero hi exact MulAction.finite_quotient_of_finite_quotient_of_finite_quotient @[to_additive] lemma finite_quotient_of_pretransitive_of_index_ne_zero {X : Type*} [MulAction G X] [MulAction.IsPretransitive G X] (hi : H.index ≠ 0) : Finite <| MulAction.orbitRel.Quotient H X := by have := (MulAction.pretransitive_iff_subsingleton_quotient G X).1 inferInstance exact finite_quotient_of_finite_quotient_of_index_ne_zero hi section FiniteIndex variable (H K) /-- Typeclass for finite index subgroups. -/ class FiniteIndex : Prop where /-- The subgroup has finite index -/ finiteIndex : H.index ≠ 0 /-- Typeclass for finite index subgroups. -/ class _root_.AddSubgroup.FiniteIndex {G : Type*} [AddGroup G] (H : AddSubgroup G) : Prop where /-- The additive subgroup has finite index -/ finiteIndex : H.index ≠ 0 /-- A finite index subgroup has finite quotient. -/ @[to_additive "A finite index subgroup has finite quotient"] noncomputable def fintypeQuotientOfFiniteIndex [FiniteIndex H] : Fintype (G ⧸ H) := fintypeOfIndexNeZero FiniteIndex.finiteIndex @[to_additive] instance finite_quotient_of_finiteIndex [FiniteIndex H] : Finite (G ⧸ H) := H.fintypeQuotientOfFiniteIndex.finite @[to_additive] theorem finiteIndex_of_finite_quotient [Finite (G ⧸ H)] : FiniteIndex H := ⟨index_ne_zero_of_finite⟩ -- Porting note: had to manually provide finite instance for quotient when it should be automatic @[to_additive] instance (priority := 100) finiteIndex_of_finite [Finite G] : FiniteIndex H := @finiteIndex_of_finite_quotient _ _ H (Quotient.finite _) @[to_additive] instance : FiniteIndex (⊤ : Subgroup G) := ⟨ne_of_eq_of_ne index_top one_ne_zero⟩ @[to_additive] instance [FiniteIndex H] [FiniteIndex K] : FiniteIndex (H ⊓ K) := ⟨index_inf_ne_zero FiniteIndex.finiteIndex FiniteIndex.finiteIndex⟩ @[to_additive] theorem finiteIndex_iInf {ι : Type*} [Finite ι] {f : ι → Subgroup G} (hf : ∀ i, (f i).FiniteIndex) : (⨅ i, f i).FiniteIndex := ⟨index_iInf_ne_zero fun i => (hf i).finiteIndex⟩ @[to_additive] theorem finiteIndex_iInf' {ι : Type*} {s : Finset ι} (f : ι → Subgroup G) (hs : ∀ i ∈ s, (f i).FiniteIndex) : (⨅ i ∈ s, f i).FiniteIndex := by rw [iInf_subtype'] exact finiteIndex_iInf fun ⟨i, hi⟩ => hs i hi @[to_additive] instance instFiniteIndex_subgroupOf (H K : Subgroup G) [H.FiniteIndex] : (H.subgroupOf K).FiniteIndex := ⟨fun h => H.index_ne_zero_of_finite <| H.index_eq_zero_of_relindex_eq_zero h⟩ variable {H K} @[to_additive] theorem finiteIndex_of_le [FiniteIndex H] (h : H ≤ K) : FiniteIndex K := ⟨ne_zero_of_dvd_ne_zero FiniteIndex.finiteIndex (index_dvd_of_le h)⟩ variable (H K) @[to_additive] instance finiteIndex_ker {G' : Type*} [Group G'] (f : G →* G') [Finite f.range] : f.ker.FiniteIndex := @finiteIndex_of_finite_quotient G _ f.ker (Finite.of_equiv f.range (QuotientGroup.quotientKerEquivRange f).symm) instance finiteIndex_normalCore [H.FiniteIndex] : H.normalCore.FiniteIndex := by rw [normalCore_eq_ker] infer_instance variable (G) instance finiteIndex_center [Finite (commutatorSet G)] [Group.FG G] : FiniteIndex (center G) := by obtain ⟨S, -, hS⟩ := Group.rank_spec G exact ⟨mt (Finite.card_eq_zero_of_embedding (quotientCenterEmbedding hS)) Finite.card_pos.ne'⟩ theorem index_center_le_pow [Finite (commutatorSet G)] [Group.FG G] : (center G).index ≤ Nat.card (commutatorSet G) ^ Group.rank G := by obtain ⟨S, hS1, hS2⟩ := Group.rank_spec G rw [← hS1, ← Fintype.card_coe, ← Nat.card_eq_fintype_card, ← Finset.coe_sort_coe, ← Nat.card_fun] exact Finite.card_le_of_embedding (quotientCenterEmbedding hS2) end FiniteIndex end Subgroup namespace MonoidHom open Finset variable {G M F : Type*} [Group G] [Fintype G] [Monoid M] [DecidableEq M] [FunLike F G M] [MonoidHomClass F G M] @[to_additive] lemma card_fiber_eq_of_mem_range (f : F) {x y : M} (hx : x ∈ Set.range f) (hy : y ∈ Set.range f) : (univ.filter <| fun g => f g = x).card = (univ.filter <| fun g => f g = y).card := by rcases hx with ⟨x, rfl⟩ rcases hy with ⟨y, rfl⟩ rcases mul_left_surjective x y with ⟨y, rfl⟩ conv_lhs => rw [← map_univ_equiv (Equiv.mulRight y⁻¹), filter_map, card_map] congr 2 with g simp only [Function.comp, Equiv.toEmbedding_apply, Equiv.coe_mulRight, map_mul] let f' := MonoidHomClass.toMonoidHom f show f' g * f' y⁻¹ = f' x ↔ f' g = f' x * f' y rw [← f'.coe_toHomUnits y⁻¹, map_inv, Units.mul_inv_eq_iff_eq_mul, f'.coe_toHomUnits] end MonoidHom
GroupTheory\Nilpotent.lean
/- Copyright (c) 2021 Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, Ines Wright, Joachim Breitner -/ import Mathlib.GroupTheory.Solvable import Mathlib.GroupTheory.Sylow import Mathlib.Algebra.Group.Subgroup.Order /-! # Nilpotent groups An API for nilpotent groups, that is, groups for which the upper central series reaches `⊤`. ## Main definitions Recall that if `H K : Subgroup G` then `⁅H, K⁆ : Subgroup G` is the subgroup of `G` generated by the commutators `hkh⁻¹k⁻¹`. Recall also Lean's conventions that `⊤` denotes the subgroup `G` of `G`, and `⊥` denotes the trivial subgroup `{1}`. * `upperCentralSeries G : ℕ → Subgroup G` : the upper central series of a group `G`. This is an increasing sequence of normal subgroups `H n` of `G` with `H 0 = ⊥` and `H (n + 1) / H n` is the centre of `G / H n`. * `lowerCentralSeries G : ℕ → Subgroup G` : the lower central series of a group `G`. This is a decreasing sequence of normal subgroups `H n` of `G` with `H 0 = ⊤` and `H (n + 1) = ⁅H n, G⁆`. * `IsNilpotent` : A group G is nilpotent if its upper central series reaches `⊤`, or equivalently if its lower central series reaches `⊥`. * `nilpotency_class` : the length of the upper central series of a nilpotent group. * `IsAscendingCentralSeries (H : ℕ → Subgroup G) : Prop` and * `IsDescendingCentralSeries (H : ℕ → Subgroup G) : Prop` : Note that in the literature a "central series" for a group is usually defined to be a *finite* sequence of normal subgroups `H 0`, `H 1`, ..., starting at `⊤`, finishing at `⊥`, and with each `H n / H (n + 1)` central in `G / H (n + 1)`. In this formalisation it is convenient to have two weaker predicates on an infinite sequence of subgroups `H n` of `G`: we say a sequence is a *descending central series* if it starts at `G` and `⁅H n, ⊤⁆ ⊆ H (n + 1)` for all `n`. Note that this series may not terminate at `⊥`, and the `H i` need not be normal. Similarly a sequence is an *ascending central series* if `H 0 = ⊥` and `⁅H (n + 1), ⊤⁆ ⊆ H n` for all `n`, again with no requirement that the series reaches `⊤` or that the `H i` are normal. ## Main theorems `G` is *defined* to be nilpotent if the upper central series reaches `⊤`. * `nilpotent_iff_finite_ascending_central_series` : `G` is nilpotent iff some ascending central series reaches `⊤`. * `nilpotent_iff_finite_descending_central_series` : `G` is nilpotent iff some descending central series reaches `⊥`. * `nilpotent_iff_lower` : `G` is nilpotent iff the lower central series reaches `⊥`. * The `nilpotency_class` can likewise be obtained from these equivalent definitions, see `least_ascending_central_series_length_eq_nilpotencyClass`, `least_descending_central_series_length_eq_nilpotencyClass` and `lowerCentralSeries_length_eq_nilpotencyClass`. * If `G` is nilpotent, then so are its subgroups, images, quotients and preimages. Binary and finite products of nilpotent groups are nilpotent. Infinite products are nilpotent if their nilpotent class is bounded. Corresponding lemmas about the `nilpotency_class` are provided. * The `nilpotency_class` of `G ⧸ center G` is given explicitly, and an induction principle is derived from that. * `IsNilpotent.to_isSolvable`: If `G` is nilpotent, it is solvable. ## Warning A "central series" is usually defined to be a finite sequence of normal subgroups going from `⊥` to `⊤` with the property that each subquotient is contained within the centre of the associated quotient of `G`. This means that if `G` is not nilpotent, then none of what we have called `upperCentralSeries G`, `lowerCentralSeries G` or the sequences satisfying `IsAscendingCentralSeries` or `IsDescendingCentralSeries` are actually central series. Note that the fact that the upper and lower central series are not central series if `G` is not nilpotent is a standard abuse of notation. -/ open Subgroup section WithGroup variable {G : Type*} [Group G] (H : Subgroup G) [Normal H] /-- If `H` is a normal subgroup of `G`, then the set `{x : G | ∀ y : G, x*y*x⁻¹*y⁻¹ ∈ H}` is a subgroup of `G` (because it is the preimage in `G` of the centre of the quotient group `G/H`.) -/ def upperCentralSeriesStep : Subgroup G where carrier := { x : G | ∀ y : G, x * y * x⁻¹ * y⁻¹ ∈ H } one_mem' y := by simp [Subgroup.one_mem] mul_mem' {a b ha hb y} := by convert Subgroup.mul_mem _ (ha (b * y * b⁻¹)) (hb y) using 1 group inv_mem' {x hx y} := by specialize hx y⁻¹ rw [mul_assoc, inv_inv] at hx ⊢ exact Subgroup.Normal.mem_comm inferInstance hx theorem mem_upperCentralSeriesStep (x : G) : x ∈ upperCentralSeriesStep H ↔ ∀ y, x * y * x⁻¹ * y⁻¹ ∈ H := Iff.rfl open QuotientGroup /-- The proof that `upperCentralSeriesStep H` is the preimage of the centre of `G/H` under the canonical surjection. -/ theorem upperCentralSeriesStep_eq_comap_center : upperCentralSeriesStep H = Subgroup.comap (mk' H) (center (G ⧸ H)) := by ext rw [mem_comap, mem_center_iff, forall_mk] apply forall_congr' intro y rw [coe_mk', ← QuotientGroup.mk_mul, ← QuotientGroup.mk_mul, eq_comm, eq_iff_div_mem, div_eq_mul_inv, mul_inv_rev, mul_assoc] instance : Normal (upperCentralSeriesStep H) := by rw [upperCentralSeriesStep_eq_comap_center] infer_instance variable (G) /-- An auxiliary type-theoretic definition defining both the upper central series of a group, and a proof that it is normal, all in one go. -/ def upperCentralSeriesAux : ℕ → Σ'H : Subgroup G, Normal H | 0 => ⟨⊥, inferInstance⟩ | n + 1 => let un := upperCentralSeriesAux n let _un_normal := un.2 ⟨upperCentralSeriesStep un.1, inferInstance⟩ /-- `upperCentralSeries G n` is the `n`th term in the upper central series of `G`. -/ def upperCentralSeries (n : ℕ) : Subgroup G := (upperCentralSeriesAux G n).1 instance upperCentralSeries_normal (n : ℕ) : Normal (upperCentralSeries G n) := (upperCentralSeriesAux G n).2 @[simp] theorem upperCentralSeries_zero : upperCentralSeries G 0 = ⊥ := rfl @[simp] theorem upperCentralSeries_one : upperCentralSeries G 1 = center G := by ext simp only [upperCentralSeries, upperCentralSeriesAux, upperCentralSeriesStep, Subgroup.mem_center_iff, mem_mk, mem_bot, Set.mem_setOf_eq] exact forall_congr' fun y => by rw [mul_inv_eq_one, mul_inv_eq_iff_eq_mul, eq_comm] /-- The `n+1`st term of the upper central series `H i` has underlying set equal to the `x` such that `⁅x,G⁆ ⊆ H n`-/ theorem mem_upperCentralSeries_succ_iff (n : ℕ) (x : G) : x ∈ upperCentralSeries G (n + 1) ↔ ∀ y : G, x * y * x⁻¹ * y⁻¹ ∈ upperCentralSeries G n := Iff.rfl -- is_nilpotent is already defined in the root namespace (for elements of rings). /-- A group `G` is nilpotent if its upper central series is eventually `G`. -/ class Group.IsNilpotent (G : Type*) [Group G] : Prop where nilpotent' : ∃ n : ℕ, upperCentralSeries G n = ⊤ -- Porting note: add lemma since infer kinds are unsupported in the definition of `IsNilpotent` lemma Group.IsNilpotent.nilpotent (G : Type*) [Group G] [IsNilpotent G] : ∃ n : ℕ, upperCentralSeries G n = ⊤ := Group.IsNilpotent.nilpotent' open Group variable {G} /-- A sequence of subgroups of `G` is an ascending central series if `H 0` is trivial and `⁅H (n + 1), G⁆ ⊆ H n` for all `n`. Note that we do not require that `H n = G` for some `n`. -/ def IsAscendingCentralSeries (H : ℕ → Subgroup G) : Prop := H 0 = ⊥ ∧ ∀ (x : G) (n : ℕ), x ∈ H (n + 1) → ∀ g, x * g * x⁻¹ * g⁻¹ ∈ H n /-- A sequence of subgroups of `G` is a descending central series if `H 0` is `G` and `⁅H n, G⁆ ⊆ H (n + 1)` for all `n`. Note that we do not require that `H n = {1}` for some `n`. -/ def IsDescendingCentralSeries (H : ℕ → Subgroup G) := H 0 = ⊤ ∧ ∀ (x : G) (n : ℕ), x ∈ H n → ∀ g, x * g * x⁻¹ * g⁻¹ ∈ H (n + 1) /-- Any ascending central series for a group is bounded above by the upper central series. -/ theorem ascending_central_series_le_upper (H : ℕ → Subgroup G) (hH : IsAscendingCentralSeries H) : ∀ n : ℕ, H n ≤ upperCentralSeries G n | 0 => hH.1.symm ▸ le_refl ⊥ | n + 1 => by intro x hx rw [mem_upperCentralSeries_succ_iff] exact fun y => ascending_central_series_le_upper H hH n (hH.2 x n hx y) variable (G) /-- The upper central series of a group is an ascending central series. -/ theorem upperCentralSeries_isAscendingCentralSeries : IsAscendingCentralSeries (upperCentralSeries G) := ⟨rfl, fun _x _n h => h⟩ theorem upperCentralSeries_mono : Monotone (upperCentralSeries G) := by refine monotone_nat_of_le_succ ?_ intro n x hx y rw [mul_assoc, mul_assoc, ← mul_assoc y x⁻¹ y⁻¹] exact mul_mem hx (Normal.conj_mem (upperCentralSeries_normal G n) x⁻¹ (inv_mem hx) y) /-- A group `G` is nilpotent iff there exists an ascending central series which reaches `G` in finitely many steps. -/ theorem nilpotent_iff_finite_ascending_central_series : IsNilpotent G ↔ ∃ n : ℕ, ∃ H : ℕ → Subgroup G, IsAscendingCentralSeries H ∧ H n = ⊤ := by constructor · rintro ⟨n, nH⟩ exact ⟨_, _, upperCentralSeries_isAscendingCentralSeries G, nH⟩ · rintro ⟨n, H, hH, hn⟩ use n rw [eq_top_iff, ← hn] exact ascending_central_series_le_upper H hH n theorem is_decending_rev_series_of_is_ascending {H : ℕ → Subgroup G} {n : ℕ} (hn : H n = ⊤) (hasc : IsAscendingCentralSeries H) : IsDescendingCentralSeries fun m : ℕ => H (n - m) := by cases' hasc with h0 hH refine ⟨hn, fun x m hx g => ?_⟩ dsimp at hx by_cases hm : n ≤ m · rw [tsub_eq_zero_of_le hm, h0, Subgroup.mem_bot] at hx subst hx rw [show (1 : G) * g * (1⁻¹ : G) * g⁻¹ = 1 by group] exact Subgroup.one_mem _ · push_neg at hm apply hH convert hx using 1 rw [tsub_add_eq_add_tsub (Nat.succ_le_of_lt hm), Nat.succ_eq_add_one, Nat.add_sub_add_right] theorem is_ascending_rev_series_of_is_descending {H : ℕ → Subgroup G} {n : ℕ} (hn : H n = ⊥) (hdesc : IsDescendingCentralSeries H) : IsAscendingCentralSeries fun m : ℕ => H (n - m) := by cases' hdesc with h0 hH refine ⟨hn, fun x m hx g => ?_⟩ dsimp only at hx ⊢ by_cases hm : n ≤ m · have hnm : n - m = 0 := tsub_eq_zero_iff_le.mpr hm rw [hnm, h0] exact mem_top _ · push_neg at hm convert hH x _ hx g using 1 rw [tsub_add_eq_add_tsub (Nat.succ_le_of_lt hm), Nat.succ_eq_add_one, Nat.add_sub_add_right] /-- A group `G` is nilpotent iff there exists a descending central series which reaches the trivial group in a finite time. -/ theorem nilpotent_iff_finite_descending_central_series : IsNilpotent G ↔ ∃ n : ℕ, ∃ H : ℕ → Subgroup G, IsDescendingCentralSeries H ∧ H n = ⊥ := by rw [nilpotent_iff_finite_ascending_central_series] constructor · rintro ⟨n, H, hH, hn⟩ refine ⟨n, fun m => H (n - m), is_decending_rev_series_of_is_ascending G hn hH, ?_⟩ dsimp only rw [tsub_self] exact hH.1 · rintro ⟨n, H, hH, hn⟩ refine ⟨n, fun m => H (n - m), is_ascending_rev_series_of_is_descending G hn hH, ?_⟩ dsimp only rw [tsub_self] exact hH.1 /-- The lower central series of a group `G` is a sequence `H n` of subgroups of `G`, defined by `H 0` is all of `G` and for `n≥1`, `H (n + 1) = ⁅H n, G⁆` -/ def lowerCentralSeries (G : Type*) [Group G] : ℕ → Subgroup G | 0 => ⊤ | n + 1 => ⁅lowerCentralSeries G n, ⊤⁆ variable {G} @[simp] theorem lowerCentralSeries_zero : lowerCentralSeries G 0 = ⊤ := rfl @[simp] theorem lowerCentralSeries_one : lowerCentralSeries G 1 = commutator G := rfl theorem mem_lowerCentralSeries_succ_iff (n : ℕ) (q : G) : q ∈ lowerCentralSeries G (n + 1) ↔ q ∈ closure { x | ∃ p ∈ lowerCentralSeries G n, ∃ q ∈ (⊤ : Subgroup G), p * q * p⁻¹ * q⁻¹ = x } := Iff.rfl theorem lowerCentralSeries_succ (n : ℕ) : lowerCentralSeries G (n + 1) = closure { x | ∃ p ∈ lowerCentralSeries G n, ∃ q ∈ (⊤ : Subgroup G), p * q * p⁻¹ * q⁻¹ = x } := rfl instance lowerCentralSeries_normal (n : ℕ) : Normal (lowerCentralSeries G n) := by induction' n with d hd · exact (⊤ : Subgroup G).normal_of_characteristic · exact @Subgroup.commutator_normal _ _ (lowerCentralSeries G d) ⊤ hd _ theorem lowerCentralSeries_antitone : Antitone (lowerCentralSeries G) := by refine antitone_nat_of_succ_le fun n x hx => ?_ simp only [mem_lowerCentralSeries_succ_iff, exists_prop, mem_top, exists_true_left, true_and_iff] at hx refine closure_induction hx ?_ (Subgroup.one_mem _) (@Subgroup.mul_mem _ _ _) (@Subgroup.inv_mem _ _ _) rintro y ⟨z, hz, a, ha⟩ rw [← ha, mul_assoc, mul_assoc, ← mul_assoc a z⁻¹ a⁻¹] exact mul_mem hz (Normal.conj_mem (lowerCentralSeries_normal n) z⁻¹ (inv_mem hz) a) /-- The lower central series of a group is a descending central series. -/ theorem lowerCentralSeries_isDescendingCentralSeries : IsDescendingCentralSeries (lowerCentralSeries G) := by constructor · rfl intro x n hxn g exact commutator_mem_commutator hxn (mem_top g) /-- Any descending central series for a group is bounded below by the lower central series. -/ theorem descending_central_series_ge_lower (H : ℕ → Subgroup G) (hH : IsDescendingCentralSeries H) : ∀ n : ℕ, lowerCentralSeries G n ≤ H n | 0 => hH.1.symm ▸ le_refl ⊤ | n + 1 => commutator_le.mpr fun x hx q _ => hH.2 x n (descending_central_series_ge_lower H hH n hx) q /-- A group is nilpotent if and only if its lower central series eventually reaches the trivial subgroup. -/ theorem nilpotent_iff_lowerCentralSeries : IsNilpotent G ↔ ∃ n, lowerCentralSeries G n = ⊥ := by rw [nilpotent_iff_finite_descending_central_series] constructor · rintro ⟨n, H, ⟨h0, hs⟩, hn⟩ use n rw [eq_bot_iff, ← hn] exact descending_central_series_ge_lower H ⟨h0, hs⟩ n · rintro ⟨n, hn⟩ exact ⟨n, lowerCentralSeries G, lowerCentralSeries_isDescendingCentralSeries, hn⟩ section Classical open scoped Classical variable [hG : IsNilpotent G] variable (G) /-- The nilpotency class of a nilpotent group is the smallest natural `n` such that the `n`'th term of the upper central series is `G`. -/ noncomputable def Group.nilpotencyClass : ℕ := Nat.find (IsNilpotent.nilpotent G) variable {G} @[simp] theorem upperCentralSeries_nilpotencyClass : upperCentralSeries G (Group.nilpotencyClass G) = ⊤ := Nat.find_spec (IsNilpotent.nilpotent G) theorem upperCentralSeries_eq_top_iff_nilpotencyClass_le {n : ℕ} : upperCentralSeries G n = ⊤ ↔ Group.nilpotencyClass G ≤ n := by constructor · intro h exact Nat.find_le h · intro h rw [eq_top_iff, ← upperCentralSeries_nilpotencyClass] exact upperCentralSeries_mono _ h /-- The nilpotency class of a nilpotent `G` is equal to the smallest `n` for which an ascending central series reaches `G` in its `n`'th term. -/ theorem least_ascending_central_series_length_eq_nilpotencyClass : Nat.find ((nilpotent_iff_finite_ascending_central_series G).mp hG) = Group.nilpotencyClass G := by refine le_antisymm (Nat.find_mono ?_) (Nat.find_mono ?_) · intro n hn exact ⟨upperCentralSeries G, upperCentralSeries_isAscendingCentralSeries G, hn⟩ · rintro n ⟨H, ⟨hH, hn⟩⟩ rw [← top_le_iff, ← hn] exact ascending_central_series_le_upper H hH n /-- The nilpotency class of a nilpotent `G` is equal to the smallest `n` for which the descending central series reaches `⊥` in its `n`'th term. -/ theorem least_descending_central_series_length_eq_nilpotencyClass : Nat.find ((nilpotent_iff_finite_descending_central_series G).mp hG) = Group.nilpotencyClass G := by rw [← least_ascending_central_series_length_eq_nilpotencyClass] refine le_antisymm (Nat.find_mono ?_) (Nat.find_mono ?_) · rintro n ⟨H, ⟨hH, hn⟩⟩ refine ⟨fun m => H (n - m), is_decending_rev_series_of_is_ascending G hn hH, ?_⟩ dsimp only rw [tsub_self] exact hH.1 · rintro n ⟨H, ⟨hH, hn⟩⟩ refine ⟨fun m => H (n - m), is_ascending_rev_series_of_is_descending G hn hH, ?_⟩ dsimp only rw [tsub_self] exact hH.1 /-- The nilpotency class of a nilpotent `G` is equal to the length of the lower central series. -/ theorem lowerCentralSeries_length_eq_nilpotencyClass : Nat.find (nilpotent_iff_lowerCentralSeries.mp hG) = Group.nilpotencyClass (G := G) := by rw [← least_descending_central_series_length_eq_nilpotencyClass] refine le_antisymm (Nat.find_mono ?_) (Nat.find_mono ?_) · rintro n ⟨H, ⟨hH, hn⟩⟩ rw [← le_bot_iff, ← hn] exact descending_central_series_ge_lower H hH n · rintro n h exact ⟨lowerCentralSeries G, ⟨lowerCentralSeries_isDescendingCentralSeries, h⟩⟩ @[simp] theorem lowerCentralSeries_nilpotencyClass : lowerCentralSeries G (Group.nilpotencyClass G) = ⊥ := by rw [← lowerCentralSeries_length_eq_nilpotencyClass] exact Nat.find_spec (nilpotent_iff_lowerCentralSeries.mp hG) theorem lowerCentralSeries_eq_bot_iff_nilpotencyClass_le {n : ℕ} : lowerCentralSeries G n = ⊥ ↔ Group.nilpotencyClass G ≤ n := by constructor · intro h rw [← lowerCentralSeries_length_eq_nilpotencyClass] exact Nat.find_le h · intro h rw [eq_bot_iff, ← lowerCentralSeries_nilpotencyClass] exact lowerCentralSeries_antitone h end Classical theorem lowerCentralSeries_map_subtype_le (H : Subgroup G) (n : ℕ) : (lowerCentralSeries H n).map H.subtype ≤ lowerCentralSeries G n := by induction' n with d hd · simp · rw [lowerCentralSeries_succ, lowerCentralSeries_succ, MonoidHom.map_closure] apply Subgroup.closure_mono rintro x1 ⟨x2, ⟨x3, hx3, x4, _hx4, rfl⟩, rfl⟩ exact ⟨x3, hd (mem_map.mpr ⟨x3, hx3, rfl⟩), x4, by simp⟩ /-- A subgroup of a nilpotent group is nilpotent -/ instance Subgroup.isNilpotent (H : Subgroup G) [hG : IsNilpotent G] : IsNilpotent H := by rw [nilpotent_iff_lowerCentralSeries] at * rcases hG with ⟨n, hG⟩ use n have := lowerCentralSeries_map_subtype_le H n simp only [hG, SetLike.le_def, mem_map, forall_apply_eq_imp_iff₂, exists_imp] at this exact eq_bot_iff.mpr fun x hx => Subtype.ext (this x ⟨hx, rfl⟩) /-- The nilpotency class of a subgroup is less or equal to the nilpotency class of the group -/ theorem Subgroup.nilpotencyClass_le (H : Subgroup G) [hG : IsNilpotent G] : Group.nilpotencyClass H ≤ Group.nilpotencyClass G := by repeat rw [← lowerCentralSeries_length_eq_nilpotencyClass] --- Porting note: Lean needs to be told that predicates are decidable refine @Nat.find_mono _ _ (Classical.decPred _) (Classical.decPred _) ?_ _ _ intro n hG have := lowerCentralSeries_map_subtype_le H n simp only [hG, SetLike.le_def, mem_map, forall_apply_eq_imp_iff₂, exists_imp] at this exact eq_bot_iff.mpr fun x hx => Subtype.ext (this x ⟨hx, rfl⟩) instance (priority := 100) Group.isNilpotent_of_subsingleton [Subsingleton G] : IsNilpotent G := nilpotent_iff_lowerCentralSeries.2 ⟨0, Subsingleton.elim ⊤ ⊥⟩ theorem upperCentralSeries.map {H : Type*} [Group H] {f : G →* H} (h : Function.Surjective f) (n : ℕ) : Subgroup.map f (upperCentralSeries G n) ≤ upperCentralSeries H n := by induction' n with d hd · simp · rintro _ ⟨x, hx : x ∈ upperCentralSeries G d.succ, rfl⟩ y' rcases h y' with ⟨y, rfl⟩ simpa using hd (mem_map_of_mem f (hx y)) theorem lowerCentralSeries.map {H : Type*} [Group H] (f : G →* H) (n : ℕ) : Subgroup.map f (lowerCentralSeries G n) ≤ lowerCentralSeries H n := by induction' n with d hd · simp [Nat.zero_eq] · rintro a ⟨x, hx : x ∈ lowerCentralSeries G d.succ, rfl⟩ refine closure_induction hx ?_ (by simp [f.map_one, Subgroup.one_mem _]) (fun y z hy hz => by simp [MonoidHom.map_mul, Subgroup.mul_mem _ hy hz]) (fun y hy => by rw [f.map_inv]; exact Subgroup.inv_mem _ hy) rintro a ⟨y, hy, z, ⟨-, rfl⟩⟩ apply mem_closure.mpr exact fun K hK => hK ⟨f y, hd (mem_map_of_mem f hy), by simp [commutatorElement_def]⟩ theorem lowerCentralSeries_succ_eq_bot {n : ℕ} (h : lowerCentralSeries G n ≤ center G) : lowerCentralSeries G (n + 1) = ⊥ := by rw [lowerCentralSeries_succ, closure_eq_bot_iff, Set.subset_singleton_iff] rintro x ⟨y, hy1, z, ⟨⟩, rfl⟩ rw [mul_assoc, ← mul_inv_rev, mul_inv_eq_one, eq_comm] exact mem_center_iff.mp (h hy1) z /-- The preimage of a nilpotent group is nilpotent if the kernel of the homomorphism is contained in the center -/ theorem isNilpotent_of_ker_le_center {H : Type*} [Group H] (f : G →* H) (hf1 : f.ker ≤ center G) (hH : IsNilpotent H) : IsNilpotent G := by rw [nilpotent_iff_lowerCentralSeries] at * rcases hH with ⟨n, hn⟩ use n + 1 refine lowerCentralSeries_succ_eq_bot (le_trans ((Subgroup.map_eq_bot_iff _).mp ?_) hf1) exact eq_bot_iff.mpr (hn ▸ lowerCentralSeries.map f n) theorem nilpotencyClass_le_of_ker_le_center {H : Type*} [Group H] (f : G →* H) (hf1 : f.ker ≤ center G) (hH : IsNilpotent H) : Group.nilpotencyClass (hG := isNilpotent_of_ker_le_center f hf1 hH) ≤ Group.nilpotencyClass H + 1 := by haveI : IsNilpotent G := isNilpotent_of_ker_le_center f hf1 hH rw [← lowerCentralSeries_length_eq_nilpotencyClass] -- Porting note: Lean needs to be told that predicates are decidable refine @Nat.find_min' _ (Classical.decPred _) _ _ ?_ refine lowerCentralSeries_succ_eq_bot (le_trans ((Subgroup.map_eq_bot_iff _).mp ?_) hf1) rw [eq_bot_iff] apply le_trans (lowerCentralSeries.map f _) simp only [lowerCentralSeries_nilpotencyClass, le_bot_iff] /-- The range of a surjective homomorphism from a nilpotent group is nilpotent -/ theorem nilpotent_of_surjective {G' : Type*} [Group G'] [h : IsNilpotent G] (f : G →* G') (hf : Function.Surjective f) : IsNilpotent G' := by rcases h with ⟨n, hn⟩ use n apply eq_top_iff.mpr calc ⊤ = f.range := symm (f.range_top_of_surjective hf) _ = Subgroup.map f ⊤ := MonoidHom.range_eq_map _ _ = Subgroup.map f (upperCentralSeries G n) := by rw [hn] _ ≤ upperCentralSeries G' n := upperCentralSeries.map hf n /-- The nilpotency class of the range of a surjective homomorphism from a nilpotent group is less or equal the nilpotency class of the domain -/ theorem nilpotencyClass_le_of_surjective {G' : Type*} [Group G'] (f : G →* G') (hf : Function.Surjective f) [h : IsNilpotent G] : Group.nilpotencyClass (hG := nilpotent_of_surjective _ hf) ≤ Group.nilpotencyClass G := by -- Porting note: Lean needs to be told that predicates are decidable refine @Nat.find_mono _ _ (Classical.decPred _) (Classical.decPred _) ?_ _ _ intro n hn rw [eq_top_iff] calc ⊤ = f.range := symm (f.range_top_of_surjective hf) _ = Subgroup.map f ⊤ := MonoidHom.range_eq_map _ _ = Subgroup.map f (upperCentralSeries G n) := by rw [hn] _ ≤ upperCentralSeries G' n := upperCentralSeries.map hf n /-- Nilpotency respects isomorphisms -/ theorem nilpotent_of_mulEquiv {G' : Type*} [Group G'] [_h : IsNilpotent G] (f : G ≃* G') : IsNilpotent G' := nilpotent_of_surjective f.toMonoidHom (MulEquiv.surjective f) /-- A quotient of a nilpotent group is nilpotent -/ instance nilpotent_quotient_of_nilpotent (H : Subgroup G) [H.Normal] [_h : IsNilpotent G] : IsNilpotent (G ⧸ H) := nilpotent_of_surjective (QuotientGroup.mk' H) QuotientGroup.mk_surjective /-- The nilpotency class of a quotient of `G` is less or equal the nilpotency class of `G` -/ theorem nilpotencyClass_quotient_le (H : Subgroup G) [H.Normal] [_h : IsNilpotent G] : Group.nilpotencyClass (G ⧸ H) ≤ Group.nilpotencyClass G := nilpotencyClass_le_of_surjective (QuotientGroup.mk' H) QuotientGroup.mk_surjective -- This technical lemma helps with rewriting the subgroup, which occurs in indices private theorem comap_center_subst {H₁ H₂ : Subgroup G} [Normal H₁] [Normal H₂] (h : H₁ = H₂) : comap (mk' H₁) (center (G ⧸ H₁)) = comap (mk' H₂) (center (G ⧸ H₂)) := by subst h; rfl theorem comap_upperCentralSeries_quotient_center (n : ℕ) : comap (mk' (center G)) (upperCentralSeries (G ⧸ center G) n) = upperCentralSeries G n.succ := by induction' n with n ih · simp only [Nat.zero_eq, upperCentralSeries_zero, MonoidHom.comap_bot, ker_mk', (upperCentralSeries_one G).symm] · let Hn := upperCentralSeries (G ⧸ center G) n calc comap (mk' (center G)) (upperCentralSeriesStep Hn) = comap (mk' (center G)) (comap (mk' Hn) (center ((G ⧸ center G) ⧸ Hn))) := by rw [upperCentralSeriesStep_eq_comap_center] _ = comap (mk' (comap (mk' (center G)) Hn)) (center (G ⧸ comap (mk' (center G)) Hn)) := QuotientGroup.comap_comap_center _ = comap (mk' (upperCentralSeries G n.succ)) (center (G ⧸ upperCentralSeries G n.succ)) := (comap_center_subst ih) _ = upperCentralSeriesStep (upperCentralSeries G n.succ) := symm (upperCentralSeriesStep_eq_comap_center _) theorem nilpotencyClass_zero_iff_subsingleton [IsNilpotent G] : Group.nilpotencyClass G = 0 ↔ Subsingleton G := by -- Porting note: Lean needs to be told that predicates are decidable rw [Group.nilpotencyClass, @Nat.find_eq_zero _ (Classical.decPred _), upperCentralSeries_zero, subsingleton_iff_bot_eq_top, Subgroup.subsingleton_iff] /-- Quotienting the `center G` reduces the nilpotency class by 1 -/ theorem nilpotencyClass_quotient_center [hH : IsNilpotent G] : Group.nilpotencyClass (G ⧸ center G) = Group.nilpotencyClass G - 1 := by generalize hn : Group.nilpotencyClass G = n rcases n with (rfl | n) · simp [nilpotencyClass_zero_iff_subsingleton] at * exact Quotient.instSubsingletonQuotient (leftRel (center G)) · suffices Group.nilpotencyClass (G ⧸ center G) = n by simpa apply le_antisymm · apply upperCentralSeries_eq_top_iff_nilpotencyClass_le.mp apply comap_injective (f := (mk' (center G))) (surjective_quot_mk _) rw [comap_upperCentralSeries_quotient_center, comap_top, Nat.succ_eq_add_one, ← hn] exact upperCentralSeries_nilpotencyClass · apply le_of_add_le_add_right calc n + 1 = Group.nilpotencyClass G := hn.symm _ ≤ Group.nilpotencyClass (G ⧸ center G) + 1 := nilpotencyClass_le_of_ker_le_center _ (le_of_eq (ker_mk' _)) _ /-- The nilpotency class of a non-trivial group is one more than its quotient by the center -/ theorem nilpotencyClass_eq_quotient_center_plus_one [hH : IsNilpotent G] [Nontrivial G] : Group.nilpotencyClass G = Group.nilpotencyClass (G ⧸ center G) + 1 := by rw [nilpotencyClass_quotient_center] rcases h : Group.nilpotencyClass G with ⟨⟩ · exfalso rw [nilpotencyClass_zero_iff_subsingleton] at h apply false_of_nontrivial_of_subsingleton G · simp /-- If the quotient by `center G` is nilpotent, then so is G. -/ theorem of_quotient_center_nilpotent (h : IsNilpotent (G ⧸ center G)) : IsNilpotent G := by obtain ⟨n, hn⟩ := h.nilpotent use n.succ simp [← comap_upperCentralSeries_quotient_center, hn] /-- A custom induction principle for nilpotent groups. The base case is a trivial group (`subsingleton G`), and in the induction step, one can assume the hypothesis for the group quotiented by its center. -/ @[elab_as_elim] theorem nilpotent_center_quotient_ind {P : ∀ (G) [Group G] [IsNilpotent G], Prop} (G : Type*) [Group G] [IsNilpotent G] (hbase : ∀ (G) [Group G] [Subsingleton G], P G) (hstep : ∀ (G) [Group G] [IsNilpotent G], P (G ⧸ center G) → P G) : P G := by obtain ⟨n, h⟩ : ∃ n, Group.nilpotencyClass G = n := ⟨_, rfl⟩ induction' n with n ih generalizing G · haveI := nilpotencyClass_zero_iff_subsingleton.mp h exact hbase _ · have hn : Group.nilpotencyClass (G ⧸ center G) = n := by simp [nilpotencyClass_quotient_center, h] exact hstep _ (ih _ hn) theorem derived_le_lower_central (n : ℕ) : derivedSeries G n ≤ lowerCentralSeries G n := by induction' n with i ih · simp · apply commutator_mono ih simp /-- Abelian groups are nilpotent -/ instance (priority := 100) CommGroup.isNilpotent {G : Type*} [CommGroup G] : IsNilpotent G := by use 1 rw [upperCentralSeries_one] apply CommGroup.center_eq_top /-- Abelian groups have nilpotency class at most one -/ theorem CommGroup.nilpotencyClass_le_one {G : Type*} [CommGroup G] : Group.nilpotencyClass G ≤ 1 := by rw [← upperCentralSeries_eq_top_iff_nilpotencyClass_le, upperCentralSeries_one] apply CommGroup.center_eq_top /-- Groups with nilpotency class at most one are abelian -/ def commGroupOfNilpotencyClass [IsNilpotent G] (h : Group.nilpotencyClass G ≤ 1) : CommGroup G := Group.commGroupOfCenterEqTop <| by rw [← upperCentralSeries_one] exact upperCentralSeries_eq_top_iff_nilpotencyClass_le.mpr h section Prod variable {G₁ G₂ : Type*} [Group G₁] [Group G₂] theorem lowerCentralSeries_prod (n : ℕ) : lowerCentralSeries (G₁ × G₂) n = (lowerCentralSeries G₁ n).prod (lowerCentralSeries G₂ n) := by induction' n with n ih · simp · calc lowerCentralSeries (G₁ × G₂) n.succ = ⁅lowerCentralSeries (G₁ × G₂) n, ⊤⁆ := rfl _ = ⁅(lowerCentralSeries G₁ n).prod (lowerCentralSeries G₂ n), ⊤⁆ := by rw [ih] _ = ⁅(lowerCentralSeries G₁ n).prod (lowerCentralSeries G₂ n), (⊤ : Subgroup G₁).prod ⊤⁆ := by simp _ = ⁅lowerCentralSeries G₁ n, (⊤ : Subgroup G₁)⁆.prod ⁅lowerCentralSeries G₂ n, ⊤⁆ := (commutator_prod_prod _ _ _ _) _ = (lowerCentralSeries G₁ n.succ).prod (lowerCentralSeries G₂ n.succ) := rfl /-- Products of nilpotent groups are nilpotent -/ instance isNilpotent_prod [IsNilpotent G₁] [IsNilpotent G₂] : IsNilpotent (G₁ × G₂) := by rw [nilpotent_iff_lowerCentralSeries] refine ⟨max (Group.nilpotencyClass G₁) (Group.nilpotencyClass G₂), ?_⟩ rw [lowerCentralSeries_prod, lowerCentralSeries_eq_bot_iff_nilpotencyClass_le.mpr (le_max_left _ _), lowerCentralSeries_eq_bot_iff_nilpotencyClass_le.mpr (le_max_right _ _), bot_prod_bot] /-- The nilpotency class of a product is the max of the nilpotency classes of the factors -/ theorem nilpotencyClass_prod [IsNilpotent G₁] [IsNilpotent G₂] : Group.nilpotencyClass (G₁ × G₂) = max (Group.nilpotencyClass G₁) (Group.nilpotencyClass G₂) := by refine eq_of_forall_ge_iff fun k => ?_ simp only [max_le_iff, ← lowerCentralSeries_eq_bot_iff_nilpotencyClass_le, lowerCentralSeries_prod, prod_eq_bot_iff] end Prod section BoundedPi -- First the case of infinite products with bounded nilpotency class variable {η : Type*} {Gs : η → Type*} [∀ i, Group (Gs i)] theorem lowerCentralSeries_pi_le (n : ℕ) : lowerCentralSeries (∀ i, Gs i) n ≤ Subgroup.pi Set.univ fun i => lowerCentralSeries (Gs i) n := by let pi := fun f : ∀ i, Subgroup (Gs i) => Subgroup.pi Set.univ f induction' n with n ih · simp [pi_top] · calc lowerCentralSeries (∀ i, Gs i) n.succ = ⁅lowerCentralSeries (∀ i, Gs i) n, ⊤⁆ := rfl _ ≤ ⁅pi fun i => lowerCentralSeries (Gs i) n, ⊤⁆ := commutator_mono ih (le_refl _) _ = ⁅pi fun i => lowerCentralSeries (Gs i) n, pi fun i => ⊤⁆ := by simp [pi, pi_top] _ ≤ pi fun i => ⁅lowerCentralSeries (Gs i) n, ⊤⁆ := commutator_pi_pi_le _ _ _ = pi fun i => lowerCentralSeries (Gs i) n.succ := rfl /-- products of nilpotent groups are nilpotent if their nilpotency class is bounded -/ theorem isNilpotent_pi_of_bounded_class [∀ i, IsNilpotent (Gs i)] (n : ℕ) (h : ∀ i, Group.nilpotencyClass (Gs i) ≤ n) : IsNilpotent (∀ i, Gs i) := by rw [nilpotent_iff_lowerCentralSeries] refine ⟨n, ?_⟩ rw [eq_bot_iff] apply le_trans (lowerCentralSeries_pi_le _) rw [← eq_bot_iff, pi_eq_bot_iff] intro i apply lowerCentralSeries_eq_bot_iff_nilpotencyClass_le.mpr (h i) end BoundedPi section FinitePi -- Now for finite products variable {η : Type*} {Gs : η → Type*} [∀ i, Group (Gs i)] theorem lowerCentralSeries_pi_of_finite [Finite η] (n : ℕ) : lowerCentralSeries (∀ i, Gs i) n = Subgroup.pi Set.univ fun i => lowerCentralSeries (Gs i) n := by let pi := fun f : ∀ i, Subgroup (Gs i) => Subgroup.pi Set.univ f induction' n with n ih · simp [pi_top] · calc lowerCentralSeries (∀ i, Gs i) n.succ = ⁅lowerCentralSeries (∀ i, Gs i) n, ⊤⁆ := rfl _ = ⁅pi fun i => lowerCentralSeries (Gs i) n, ⊤⁆ := by rw [ih] _ = ⁅pi fun i => lowerCentralSeries (Gs i) n, pi fun i => ⊤⁆ := by simp [pi, pi_top] _ = pi fun i => ⁅lowerCentralSeries (Gs i) n, ⊤⁆ := commutator_pi_pi_of_finite _ _ _ = pi fun i => lowerCentralSeries (Gs i) n.succ := rfl /-- n-ary products of nilpotent groups are nilpotent -/ instance isNilpotent_pi [Finite η] [∀ i, IsNilpotent (Gs i)] : IsNilpotent (∀ i, Gs i) := by cases nonempty_fintype η rw [nilpotent_iff_lowerCentralSeries] refine ⟨Finset.univ.sup fun i => Group.nilpotencyClass (Gs i), ?_⟩ rw [lowerCentralSeries_pi_of_finite, pi_eq_bot_iff] intro i rw [lowerCentralSeries_eq_bot_iff_nilpotencyClass_le] exact Finset.le_sup (f := fun i => Group.nilpotencyClass (Gs i)) (Finset.mem_univ i) /-- The nilpotency class of an n-ary product is the sup of the nilpotency classes of the factors -/ theorem nilpotencyClass_pi [Fintype η] [∀ i, IsNilpotent (Gs i)] : Group.nilpotencyClass (∀ i, Gs i) = Finset.univ.sup fun i => Group.nilpotencyClass (Gs i) := by apply eq_of_forall_ge_iff intro k simp only [Finset.sup_le_iff, ← lowerCentralSeries_eq_bot_iff_nilpotencyClass_le, lowerCentralSeries_pi_of_finite, pi_eq_bot_iff, Finset.mem_univ, true_imp_iff] end FinitePi /-- A nilpotent subgroup is solvable -/ instance (priority := 100) IsNilpotent.to_isSolvable [h : IsNilpotent G] : IsSolvable G := by obtain ⟨n, hn⟩ := nilpotent_iff_lowerCentralSeries.1 h use n rw [eq_bot_iff, ← hn] exact derived_le_lower_central n theorem normalizerCondition_of_isNilpotent [h : IsNilpotent G] : NormalizerCondition G := by -- roughly based on https://groupprops.subwiki.org/wiki/Nilpotent_implies_normalizer_condition rw [normalizerCondition_iff_only_full_group_self_normalizing] apply @nilpotent_center_quotient_ind _ G _ _ <;> clear! G · intro G _ _ H _ exact @Subsingleton.elim _ Unique.instSubsingleton _ _ · intro G _ _ ih H hH have hch : center G ≤ H := Subgroup.center_le_normalizer.trans (le_of_eq hH) have hkh : (mk' (center G)).ker ≤ H := by simpa using hch have hsur : Function.Surjective (mk' (center G)) := surjective_quot_mk _ let H' := H.map (mk' (center G)) have hH' : H'.normalizer = H' := by apply comap_injective hsur rw [comap_normalizer_eq_of_surjective _ hsur, comap_map_eq_self hkh] exact hH apply map_injective_of_ker_le (mk' (center G)) hkh le_top exact (ih H' hH').trans (symm (map_top_of_surjective _ hsur)) end WithGroup section WithFiniteGroup open Group Fintype variable {G : Type*} [hG : Group G] /-- A p-group is nilpotent -/ theorem IsPGroup.isNilpotent [Finite G] {p : ℕ} [hp : Fact (Nat.Prime p)] (h : IsPGroup p G) : IsNilpotent G := by cases' nonempty_fintype G classical revert hG apply @Fintype.induction_subsingleton_or_nontrivial _ G _ · intro _ _ _ _ infer_instance · intro G _ _ ih _ h have hcq : Fintype.card (G ⧸ center G) < Fintype.card G := by simp only [← Nat.card_eq_fintype_card] rw [card_eq_card_quotient_mul_card_subgroup (center G)] simp only [Nat.card_eq_fintype_card] apply lt_mul_of_one_lt_right · exact Fintype.card_pos_iff.mpr One.instNonempty · simp only [← Nat.card_eq_fintype_card] exact (Subgroup.one_lt_card_iff_ne_bot _).mpr (ne_of_gt h.bot_lt_center) have hnq : IsNilpotent (G ⧸ center G) := ih _ hcq (h.to_quotient (center G)) exact of_quotient_center_nilpotent hnq variable [Finite G] /-- If a finite group is the direct product of its Sylow groups, it is nilpotent -/ theorem isNilpotent_of_product_of_sylow_group (e : (∀ p : (Nat.card G).primeFactors, ∀ P : Sylow p G, (↑P : Subgroup G)) ≃* G) : IsNilpotent G := by classical let ps := (Nat.card G).primeFactors have : ∀ (p : ps) (P : Sylow p G), IsNilpotent (↑P : Subgroup G) := by intro p P haveI : Fact (Nat.Prime ↑p) := Fact.mk <| Nat.prime_of_mem_primeFactors p.2 exact P.isPGroup'.isNilpotent exact nilpotent_of_mulEquiv e /-- A finite group is nilpotent iff the normalizer condition holds, and iff all maximal groups are normal and iff all Sylow groups are normal and iff the group is the direct product of its Sylow groups. -/ theorem isNilpotent_of_finite_tfae : List.TFAE [IsNilpotent G, NormalizerCondition G, ∀ H : Subgroup G, IsCoatom H → H.Normal, ∀ (p : ℕ) (_hp : Fact p.Prime) (P : Sylow p G), (↑P : Subgroup G).Normal, Nonempty ((∀ p : (Nat.card G).primeFactors, ∀ P : Sylow p G, (↑P : Subgroup G)) ≃* G)] := by tfae_have 1 → 2 · exact @normalizerCondition_of_isNilpotent _ _ tfae_have 2 → 3 · exact fun h H => NormalizerCondition.normal_of_coatom H h tfae_have 3 → 4 · intro h p _ P; exact Sylow.normal_of_all_max_subgroups_normal h _ tfae_have 4 → 5 · exact fun h => Nonempty.intro (Sylow.directProductOfNormal fun {p hp hP} => h p hp hP) tfae_have 5 → 1 · rintro ⟨e⟩; exact isNilpotent_of_product_of_sylow_group e tfae_finish @[deprecated (since := "2024-06-05")] alias isNilpotent_of_finite_tFAE := isNilpotent_of_finite_tfae end WithFiniteGroup
GroupTheory\NoncommCoprod.lean
/- Copyright (c) 2023 Antoine Chambert-Loir. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Antoine Chambert-Loir -/ import Mathlib.Algebra.Group.Commute.Hom import Mathlib.Algebra.Group.Prod /-! # Canonical homomorphism from a pair of monoids This file defines the construction of the canonical homomorphism from a pair of monoids. Given two morphisms of monoids `f : M →* P` and `g : N →* P` where elements in the images of the two morphisms commute, we obtain a canonical morphism `MonoidHom.noncommCoprod : M × N →* P` whose composition with `inl M N` coincides with `f` and whose composition with `inr M N` coincides with `g`. There is an analogue `MulHom.noncommCoprod` when `f` and `g` are only `MulHom`s. ## Main theorems: * `noncommCoprod_comp_inr` and `noncommCoprod_comp_inl` prove that the compositions of `MonoidHom.noncommCoprod f g _` with `inl M N` and `inr M N` coincide with `f` and `g`. * `comp_noncommCoprod` proves that the composition of a morphism of monoids `h` with `noncommCoprod f g _` coincides with `noncommCoprod (h.comp f) (h.comp g)`. For a product of a family of morphisms of monoids, see `MonoidHom.noncommPiCoprod`. -/ assert_not_exists MonoidWithZero namespace MulHom variable {M N P : Type*} [Mul M] [Mul N] [Semigroup P] (f : M →ₙ* P) (g : N →ₙ* P) /-- Coproduct of two `MulHom`s with the same codomain with `Commute` assumption: `f.noncommCoprod g _ (p : M × N) = f p.1 * g p.2`. (For the commutative case, use `MulHom.coprod`) -/ @[to_additive (attr := simps) "Coproduct of two `AddHom`s with the same codomain with `AddCommute` assumption: `f.noncommCoprod g _ (p : M × N) = f p.1 + g p.2`. (For the commutative case, use `AddHom.coprod`)"] def noncommCoprod (comm : ∀ m n, Commute (f m) (g n)) : M × N →ₙ* P where toFun mn := f mn.fst * g mn.snd map_mul' mn mn' := by simpa using (comm _ _).mul_mul_mul_comm _ _ @[to_additive] theorem comp_noncommCoprod {Q : Type*} [Semigroup Q] (h : P →ₙ* Q) (comm : ∀ m n, Commute (f m) (g n)) : h.comp (f.noncommCoprod g comm) = (h.comp f).noncommCoprod (h.comp g) (fun m n ↦ (comm m n).map h) := ext fun _ => map_mul h _ _ end MulHom namespace MonoidHom variable {M N P : Type*} [MulOneClass M] [MulOneClass N] [Monoid P] (f : M →* P) (g : N →* P) (comm : ∀ m n, Commute (f m) (g n)) /-- Coproduct of two `MonoidHom`s with the same codomain, with a commutation assumption: `f.noncommCoprod g _ (p : M × N) = f p.1 * g p.2`. (Noncommutative case; in the commutative case, use `MonoidHom.coprod`.)-/ @[to_additive (attr := simps) "Coproduct of two `AddMonoidHom`s with the same codomain, with a commutation assumption: `f.noncommCoprod g (p : M × N) = f p.1 + g p.2`. (Noncommutative case; in the commutative case, use `AddHom.coprod`.)"] def noncommCoprod : M × N →* P where toFun := fun mn ↦ (f mn.fst) * (g mn.snd) map_one' := by simp only [Prod.fst_one, Prod.snd_one, map_one, mul_one] __ := f.toMulHom.noncommCoprod g.toMulHom comm @[to_additive (attr := simp)] theorem noncommCoprod_comp_inl : (f.noncommCoprod g comm).comp (inl M N) = f := ext fun x => by simp @[to_additive (attr := simp)] theorem noncommCoprod_comp_inr : (f.noncommCoprod g comm).comp (inr M N) = g := ext fun x => by simp @[to_additive (attr := simp)] theorem noncommCoprod_unique (f : M × N →* P) : (f.comp (inl M N)).noncommCoprod (f.comp (inr M N)) (fun _ _ => (commute_inl_inr _ _).map f) = f := ext fun x => by simp [coprod_apply, inl_apply, inr_apply, ← map_mul] @[to_additive (attr := simp)] theorem noncommCoprod_inl_inr {M N : Type*} [Monoid M] [Monoid N] : (inl M N).noncommCoprod (inr M N) commute_inl_inr = id (M × N) := noncommCoprod_unique <| .id (M × N) @[to_additive] theorem comp_noncommCoprod {Q : Type*} [Monoid Q] (h : P →* Q) : h.comp (f.noncommCoprod g comm) = (h.comp f).noncommCoprod (h.comp g) (fun m n ↦ (comm m n).map h) := ext fun x => by simp end MonoidHom
GroupTheory\NoncommPiCoprod.lean
/- Copyright (c) 2022 Joachim Breitner. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joachim Breitner -/ import Mathlib.GroupTheory.OrderOfElement import Mathlib.Data.Nat.GCD.BigOperators import Mathlib.Order.SupIndep /-! # Canonical homomorphism from a finite family of monoids This file defines the construction of the canonical homomorphism from a family of monoids. Given a family of morphisms `ϕ i : N i →* M` for each `i : ι` where elements in the images of different morphisms commute, we obtain a canonical morphism `MonoidHom.noncommPiCoprod : (Π i, N i) →* M` that coincides with `ϕ` ## Main definitions * `MonoidHom.noncommPiCoprod : (Π i, N i) →* M` is the main homomorphism * `Subgroup.noncommPiCoprod : (Π i, H i) →* G` is the specialization to `H i : Subgroup G` and the subgroup embedding. ## Main theorems * `MonoidHom.noncommPiCoprod` coincides with `ϕ i` when restricted to `N i` * `MonoidHom.noncommPiCoprod_mrange`: The range of `MonoidHom.noncommPiCoprod` is `⨆ (i : ι), (ϕ i).mrange` * `MonoidHom.noncommPiCoprod_range`: The range of `MonoidHom.noncommPiCoprod` is `⨆ (i : ι), (ϕ i).range` * `Subgroup.noncommPiCoprod_range`: The range of `Subgroup.noncommPiCoprod` is `⨆ (i : ι), H i`. * `MonoidHom.injective_noncommPiCoprod_of_independent`: in the case of groups, `pi_hom.hom` is injective if the `ϕ` are injective and the ranges of the `ϕ` are independent. * `MonoidHom.independent_range_of_coprime_order`: If the `N i` have coprime orders, then the ranges of the `ϕ` are independent. * `Subgroup.independent_of_coprime_order`: If commuting normal subgroups `H i` have coprime orders, they are independent. -/ namespace Subgroup variable {G : Type*} [Group G] /-- `Finset.noncommProd` is “injective” in `f` if `f` maps into independent subgroups. This generalizes (one direction of) `Subgroup.disjoint_iff_mul_eq_one`. -/ @[to_additive "`Finset.noncommSum` is “injective” in `f` if `f` maps into independent subgroups. This generalizes (one direction of) `AddSubgroup.disjoint_iff_add_eq_zero`. "] theorem eq_one_of_noncommProd_eq_one_of_independent {ι : Type*} (s : Finset ι) (f : ι → G) (comm) (K : ι → Subgroup G) (hind : CompleteLattice.Independent K) (hmem : ∀ x ∈ s, f x ∈ K x) (heq1 : s.noncommProd f comm = 1) : ∀ i ∈ s, f i = 1 := by classical revert heq1 induction' s using Finset.induction_on with i s hnmem ih · simp · have hcomm := comm.mono (Finset.coe_subset.2 <| Finset.subset_insert _ _) simp only [Finset.forall_mem_insert] at hmem have hmem_bsupr : s.noncommProd f hcomm ∈ ⨆ i ∈ (s : Set ι), K i := by refine Subgroup.noncommProd_mem _ _ ?_ intro x hx have : K x ≤ ⨆ i ∈ (s : Set ι), K i := le_iSup₂ (f := fun i _ => K i) x hx exact this (hmem.2 x hx) intro heq1 rw [Finset.noncommProd_insert_of_not_mem _ _ _ _ hnmem] at heq1 have hnmem' : i ∉ (s : Set ι) := by simpa obtain ⟨heq1i : f i = 1, heq1S : s.noncommProd f _ = 1⟩ := Subgroup.disjoint_iff_mul_eq_one.mp (hind.disjoint_biSup hnmem') hmem.1 hmem_bsupr heq1 intro i h simp only [Finset.mem_insert] at h rcases h with (rfl | h) · exact heq1i · refine ih hcomm hmem.2 heq1S _ h end Subgroup section FamilyOfMonoids variable {M : Type*} [Monoid M] -- We have a family of monoids -- The fintype assumption is not always used, but declared here, to keep things in order variable {ι : Type*} [Fintype ι] variable {N : ι → Type*} [∀ i, Monoid (N i)] -- And morphisms ϕ into G variable (ϕ : ∀ i : ι, N i →* M) -- We assume that the elements of different morphism commute variable (hcomm : Pairwise fun i j => ∀ x y, Commute (ϕ i x) (ϕ j y)) -- We use `f` and `g` to denote elements of `Π (i : ι), N i` variable (f g : ∀ i : ι, N i) namespace MonoidHom /-- The canonical homomorphism from a family of monoids. -/ @[to_additive "The canonical homomorphism from a family of additive monoids. See also `LinearMap.lsum` for a linear version without the commutativity assumption."] def noncommPiCoprod : (∀ i : ι, N i) →* M where toFun f := Finset.univ.noncommProd (fun i => ϕ i (f i)) fun i _ j _ h => hcomm h _ _ map_one' := by apply (Finset.noncommProd_eq_pow_card _ _ _ _ _).trans (one_pow _) simp map_mul' f g := by classical simp only convert @Finset.noncommProd_mul_distrib _ _ _ _ (fun i => ϕ i (f i)) (fun i => ϕ i (g i)) _ _ _ · exact map_mul _ _ _ · rintro i - j - h exact hcomm h _ _ variable {hcomm} @[to_additive (attr := simp)] theorem noncommPiCoprod_mulSingle [DecidableEq ι] (i : ι) (y : N i) : noncommPiCoprod ϕ hcomm (Pi.mulSingle i y) = ϕ i y := by change Finset.univ.noncommProd (fun j => ϕ j (Pi.mulSingle i y j)) (fun _ _ _ _ h => hcomm h _ _) = ϕ i y rw [← Finset.insert_erase (Finset.mem_univ i)] rw [Finset.noncommProd_insert_of_not_mem _ _ _ _ (Finset.not_mem_erase i _)] rw [Pi.mulSingle_eq_same] rw [Finset.noncommProd_eq_pow_card] · rw [one_pow] exact mul_one _ · intro j hj simp only [Finset.mem_erase] at hj simp [hj] /-- The universal property of `MonoidHom.noncommPiCoprod` -/ @[to_additive "The universal property of `AddMonoidHom.noncommPiCoprod`"] def noncommPiCoprodEquiv [DecidableEq ι] : { ϕ : ∀ i, N i →* M // Pairwise fun i j => ∀ x y, Commute (ϕ i x) (ϕ j y) } ≃ ((∀ i, N i) →* M) where toFun ϕ := noncommPiCoprod ϕ.1 ϕ.2 invFun f := ⟨fun i => f.comp (MonoidHom.mulSingle N i), fun i j hij x y => Commute.map (Pi.mulSingle_commute hij x y) f⟩ left_inv ϕ := by ext simp only [coe_comp, Function.comp_apply, mulSingle_apply, noncommPiCoprod_mulSingle] right_inv f := pi_ext fun i x => by simp only [noncommPiCoprod_mulSingle, coe_comp, Function.comp_apply, mulSingle_apply] @[to_additive] theorem noncommPiCoprod_mrange : MonoidHom.mrange (noncommPiCoprod ϕ hcomm) = ⨆ i : ι, MonoidHom.mrange (ϕ i) := by letI := Classical.decEq ι apply le_antisymm · rintro x ⟨f, rfl⟩ refine Submonoid.noncommProd_mem _ _ _ (fun _ _ _ _ h => hcomm h _ _) (fun i _ => ?_) apply Submonoid.mem_sSup_of_mem · use i simp · refine iSup_le ?_ rintro i x ⟨y, rfl⟩ exact ⟨Pi.mulSingle i y, noncommPiCoprod_mulSingle _ _ _⟩ end MonoidHom end FamilyOfMonoids section FamilyOfGroups variable {G : Type*} [Group G] variable {ι : Type*} variable {H : ι → Type*} [∀ i, Group (H i)] variable (ϕ : ∀ i : ι, H i →* G) -- We use `f` and `g` to denote elements of `Π (i : ι), H i` variable (f g : ∀ i : ι, H i) namespace MonoidHom -- The subgroup version of `MonoidHom.noncommPiCoprod_mrange` @[to_additive] theorem noncommPiCoprod_range [Fintype ι] {hcomm : Pairwise fun i j : ι => ∀ (x : H i) (y : H j), Commute (ϕ i x) (ϕ j y)} : (noncommPiCoprod ϕ hcomm).range = ⨆ i : ι, (ϕ i).range := by letI := Classical.decEq ι apply le_antisymm · rintro x ⟨f, rfl⟩ refine Subgroup.noncommProd_mem _ (fun _ _ _ _ h => hcomm h _ _) ?_ intro i _hi apply Subgroup.mem_sSup_of_mem · use i simp · refine iSup_le ?_ rintro i x ⟨y, rfl⟩ exact ⟨Pi.mulSingle i y, noncommPiCoprod_mulSingle _ _ _⟩ @[to_additive] theorem injective_noncommPiCoprod_of_independent [Fintype ι] {hcomm : Pairwise fun i j : ι => ∀ (x : H i) (y : H j), Commute (ϕ i x) (ϕ j y)} (hind : CompleteLattice.Independent fun i => (ϕ i).range) (hinj : ∀ i, Function.Injective (ϕ i)) : Function.Injective (noncommPiCoprod ϕ hcomm) := by classical apply (MonoidHom.ker_eq_bot_iff _).mp rw [eq_bot_iff] intro f heq1 have : ∀ i, i ∈ Finset.univ → ϕ i (f i) = 1 := Subgroup.eq_one_of_noncommProd_eq_one_of_independent _ _ (fun _ _ _ _ h => hcomm h _ _) _ hind (by simp) heq1 ext i apply hinj simp [this i (Finset.mem_univ i)] @[to_additive] theorem independent_range_of_coprime_order (hcomm : Pairwise fun i j : ι => ∀ (x : H i) (y : H j), Commute (ϕ i x) (ϕ j y)) [Finite ι] [∀ i, Fintype (H i)] (hcoprime : Pairwise fun i j => Nat.Coprime (Fintype.card (H i)) (Fintype.card (H j))) : CompleteLattice.Independent fun i => (ϕ i).range := by cases nonempty_fintype ι letI := Classical.decEq ι rintro i rw [disjoint_iff_inf_le] rintro f ⟨hxi, hxp⟩ dsimp at hxi hxp rw [iSup_subtype', ← noncommPiCoprod_range] at hxp rotate_left · intro _ _ hj apply hcomm exact hj ∘ Subtype.ext cases' hxp with g hgf cases' hxi with g' hg'f have hxi : orderOf f ∣ Fintype.card (H i) := by rw [← hg'f] exact (orderOf_map_dvd _ _).trans orderOf_dvd_card have hxp : orderOf f ∣ ∏ j : { j // j ≠ i }, Fintype.card (H j) := by rw [← hgf, ← Fintype.card_pi] exact (orderOf_map_dvd _ _).trans orderOf_dvd_card change f = 1 rw [← pow_one f, ← orderOf_dvd_iff_pow_eq_one] -- Porting note: ouch, had to replace an ugly `convert` obtain ⟨c, hc⟩ := Nat.dvd_gcd hxp hxi use c rw [← hc] symm rw [← Nat.coprime_iff_gcd_eq_one, Nat.coprime_fintype_prod_left_iff, Subtype.forall] intro j h exact hcoprime h end MonoidHom end FamilyOfGroups namespace Subgroup -- We have a family of subgroups variable {G : Type*} [Group G] variable {ι : Type*} {H : ι → Subgroup G} -- Elements of `Π (i : ι), H i` are called `f` and `g` here variable (f g : ∀ i : ι, H i) section CommutingSubgroups -- We assume that the elements of different subgroups commute -- with `hcomm : Pairwise fun i j : ι => ∀ x y : G, x ∈ H i → y ∈ H j → Commute x y` @[to_additive] theorem commute_subtype_of_commute (hcomm : Pairwise fun i j : ι => ∀ x y : G, x ∈ H i → y ∈ H j → Commute x y) (i j : ι) (hne : i ≠ j) : ∀ (x : H i) (y : H j), Commute ((H i).subtype x) ((H j).subtype y) := by rintro ⟨x, hx⟩ ⟨y, hy⟩ exact hcomm hne x y hx hy @[to_additive] theorem independent_of_coprime_order (hcomm : Pairwise fun i j : ι => ∀ x y : G, x ∈ H i → y ∈ H j → Commute x y) [Finite ι] [∀ i, Fintype (H i)] (hcoprime : Pairwise fun i j => Nat.Coprime (Fintype.card (H i)) (Fintype.card (H j))) : CompleteLattice.Independent H := by simpa using MonoidHom.independent_range_of_coprime_order (fun i => (H i).subtype) (commute_subtype_of_commute hcomm) hcoprime variable [Fintype ι] /-- The canonical homomorphism from a family of subgroups where elements from different subgroups commute -/ @[to_additive "The canonical homomorphism from a family of additive subgroups where elements from different subgroups commute"] def noncommPiCoprod (hcomm : Pairwise fun i j : ι => ∀ x y : G, x ∈ H i → y ∈ H j → Commute x y) : (∀ i : ι, H i) →* G := MonoidHom.noncommPiCoprod (fun i => (H i).subtype) (commute_subtype_of_commute hcomm) @[to_additive (attr := simp)] theorem noncommPiCoprod_mulSingle [DecidableEq ι] {hcomm : Pairwise fun i j : ι => ∀ x y : G, x ∈ H i → y ∈ H j → Commute x y}(i : ι) (y : H i) : noncommPiCoprod hcomm (Pi.mulSingle i y) = y := by apply MonoidHom.noncommPiCoprod_mulSingle @[to_additive] theorem noncommPiCoprod_range {hcomm : Pairwise fun i j : ι => ∀ x y : G, x ∈ H i → y ∈ H j → Commute x y} : (noncommPiCoprod hcomm).range = ⨆ i : ι, H i := by simp [noncommPiCoprod, MonoidHom.noncommPiCoprod_range] @[to_additive] theorem injective_noncommPiCoprod_of_independent {hcomm : Pairwise fun i j : ι => ∀ x y : G, x ∈ H i → y ∈ H j → Commute x y} (hind : CompleteLattice.Independent H) : Function.Injective (noncommPiCoprod hcomm) := by apply MonoidHom.injective_noncommPiCoprod_of_independent · simpa using hind · intro i exact Subtype.coe_injective end CommutingSubgroups end Subgroup
GroupTheory\OrderOfElement.lean
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Julian Kuelshammer -/ import Mathlib.Algebra.CharP.Defs import Mathlib.GroupTheory.Index import Mathlib.Order.Interval.Set.Infinite /-! # Order of an element This file defines the order of an element of a finite group. For a finite group `G` the order of `x ∈ G` is the minimal `n ≥ 1` such that `x ^ n = 1`. ## Main definitions * `IsOfFinOrder` is a predicate on an element `x` of a monoid `G` saying that `x` is of finite order. * `IsOfFinAddOrder` is the additive analogue of `IsOfFinOrder`. * `orderOf x` defines the order of an element `x` of a monoid `G`, by convention its value is `0` if `x` has infinite order. * `addOrderOf` is the additive analogue of `orderOf`. ## Tags order of an element -/ open Function Fintype Nat Pointwise Subgroup Submonoid variable {G H A α β : Type*} section Monoid variable [Monoid G] {a b x y : G} {n m : ℕ} section IsOfFinOrder -- Porting note(#12129): additional beta reduction needed @[to_additive] theorem isPeriodicPt_mul_iff_pow_eq_one (x : G) : IsPeriodicPt (x * ·) n 1 ↔ x ^ n = 1 := by rw [IsPeriodicPt, IsFixedPt, mul_left_iterate]; beta_reduce; rw [mul_one] /-- `IsOfFinOrder` is a predicate on an element `x` of a monoid to be of finite order, i.e. there exists `n ≥ 1` such that `x ^ n = 1`. -/ @[to_additive "`IsOfFinAddOrder` is a predicate on an element `a` of an additive monoid to be of finite order, i.e. there exists `n ≥ 1` such that `n • a = 0`."] def IsOfFinOrder (x : G) : Prop := (1 : G) ∈ periodicPts (x * ·) theorem isOfFinAddOrder_ofMul_iff : IsOfFinAddOrder (Additive.ofMul x) ↔ IsOfFinOrder x := Iff.rfl theorem isOfFinOrder_ofAdd_iff {α : Type*} [AddMonoid α] {x : α} : IsOfFinOrder (Multiplicative.ofAdd x) ↔ IsOfFinAddOrder x := Iff.rfl @[to_additive] theorem isOfFinOrder_iff_pow_eq_one : IsOfFinOrder x ↔ ∃ n, 0 < n ∧ x ^ n = 1 := by simp [IsOfFinOrder, mem_periodicPts, isPeriodicPt_mul_iff_pow_eq_one] @[to_additive] alias ⟨IsOfFinOrder.exists_pow_eq_one, _⟩ := isOfFinOrder_iff_pow_eq_one @[to_additive] lemma isOfFinOrder_iff_zpow_eq_one {G} [Group G] {x : G} : IsOfFinOrder x ↔ ∃ (n : ℤ), n ≠ 0 ∧ x ^ n = 1 := by rw [isOfFinOrder_iff_pow_eq_one] refine ⟨fun ⟨n, hn, hn'⟩ ↦ ⟨n, Int.natCast_ne_zero_iff_pos.mpr hn, zpow_natCast x n ▸ hn'⟩, fun ⟨n, hn, hn'⟩ ↦ ⟨n.natAbs, Int.natAbs_pos.mpr hn, ?_⟩⟩ cases' (Int.natAbs_eq_iff (a := n)).mp rfl with h h · rwa [h, zpow_natCast] at hn' · rwa [h, zpow_neg, inv_eq_one, zpow_natCast] at hn' /-- See also `injective_pow_iff_not_isOfFinOrder`. -/ @[to_additive "See also `injective_nsmul_iff_not_isOfFinAddOrder`."] theorem not_isOfFinOrder_of_injective_pow {x : G} (h : Injective fun n : ℕ => x ^ n) : ¬IsOfFinOrder x := by simp_rw [isOfFinOrder_iff_pow_eq_one, not_exists, not_and] intro n hn_pos hnx rw [← pow_zero x] at hnx rw [h hnx] at hn_pos exact irrefl 0 hn_pos lemma IsOfFinOrder.pow {n : ℕ} : IsOfFinOrder a → IsOfFinOrder (a ^ n) := by simp_rw [isOfFinOrder_iff_pow_eq_one] rintro ⟨m, hm, ha⟩ exact ⟨m, hm, by simp [pow_right_comm _ n, ha]⟩ /-- Elements of finite order are of finite order in submonoids. -/ @[to_additive "Elements of finite order are of finite order in submonoids."] theorem Submonoid.isOfFinOrder_coe {H : Submonoid G} {x : H} : IsOfFinOrder (x : G) ↔ IsOfFinOrder x := by rw [isOfFinOrder_iff_pow_eq_one, isOfFinOrder_iff_pow_eq_one] norm_cast /-- The image of an element of finite order has finite order. -/ @[to_additive "The image of an element of finite additive order has finite additive order."] theorem MonoidHom.isOfFinOrder [Monoid H] (f : G →* H) {x : G} (h : IsOfFinOrder x) : IsOfFinOrder <| f x := isOfFinOrder_iff_pow_eq_one.mpr <| by obtain ⟨n, npos, hn⟩ := h.exists_pow_eq_one exact ⟨n, npos, by rw [← f.map_pow, hn, f.map_one]⟩ /-- If a direct product has finite order then so does each component. -/ @[to_additive "If a direct product has finite additive order then so does each component."] theorem IsOfFinOrder.apply {η : Type*} {Gs : η → Type*} [∀ i, Monoid (Gs i)] {x : ∀ i, Gs i} (h : IsOfFinOrder x) : ∀ i, IsOfFinOrder (x i) := by obtain ⟨n, npos, hn⟩ := h.exists_pow_eq_one exact fun _ => isOfFinOrder_iff_pow_eq_one.mpr ⟨n, npos, (congr_fun hn.symm _).symm⟩ /-- 1 is of finite order in any monoid. -/ @[to_additive "0 is of finite order in any additive monoid."] theorem isOfFinOrder_one : IsOfFinOrder (1 : G) := isOfFinOrder_iff_pow_eq_one.mpr ⟨1, Nat.one_pos, one_pow 1⟩ /-- The submonoid generated by an element is a group if that element has finite order. -/ @[to_additive "The additive submonoid generated by an element is an additive group if that element has finite order."] noncomputable abbrev IsOfFinOrder.groupPowers (hx : IsOfFinOrder x) : Group (Submonoid.powers x) := by obtain ⟨hpos, hx⟩ := hx.exists_pow_eq_one.choose_spec exact Submonoid.groupPowers hpos hx end IsOfFinOrder /-- `orderOf x` is the order of the element `x`, i.e. the `n ≥ 1`, s.t. `x ^ n = 1` if it exists. Otherwise, i.e. if `x` is of infinite order, then `orderOf x` is `0` by convention. -/ @[to_additive "`addOrderOf a` is the order of the element `a`, i.e. the `n ≥ 1`, s.t. `n • a = 0` if it exists. Otherwise, i.e. if `a` is of infinite order, then `addOrderOf a` is `0` by convention."] noncomputable def orderOf (x : G) : ℕ := minimalPeriod (x * ·) 1 @[simp] theorem addOrderOf_ofMul_eq_orderOf (x : G) : addOrderOf (Additive.ofMul x) = orderOf x := rfl @[simp] lemma orderOf_ofAdd_eq_addOrderOf {α : Type*} [AddMonoid α] (a : α) : orderOf (Multiplicative.ofAdd a) = addOrderOf a := rfl @[to_additive] protected lemma IsOfFinOrder.orderOf_pos (h : IsOfFinOrder x) : 0 < orderOf x := minimalPeriod_pos_of_mem_periodicPts h @[to_additive addOrderOf_nsmul_eq_zero] theorem pow_orderOf_eq_one (x : G) : x ^ orderOf x = 1 := by convert Eq.trans _ (isPeriodicPt_minimalPeriod (x * ·) 1) -- Porting note(#12129): additional beta reduction needed in the middle of the rewrite rw [orderOf, mul_left_iterate]; beta_reduce; rw [mul_one] @[to_additive] theorem orderOf_eq_zero (h : ¬IsOfFinOrder x) : orderOf x = 0 := by rwa [orderOf, minimalPeriod, dif_neg] @[to_additive] theorem orderOf_eq_zero_iff : orderOf x = 0 ↔ ¬IsOfFinOrder x := ⟨fun h H ↦ H.orderOf_pos.ne' h, orderOf_eq_zero⟩ @[to_additive] theorem orderOf_eq_zero_iff' : orderOf x = 0 ↔ ∀ n : ℕ, 0 < n → x ^ n ≠ 1 := by simp_rw [orderOf_eq_zero_iff, isOfFinOrder_iff_pow_eq_one, not_exists, not_and] @[to_additive] theorem orderOf_eq_iff {n} (h : 0 < n) : orderOf x = n ↔ x ^ n = 1 ∧ ∀ m, m < n → 0 < m → x ^ m ≠ 1 := by simp_rw [Ne, ← isPeriodicPt_mul_iff_pow_eq_one, orderOf, minimalPeriod] split_ifs with h1 · classical rw [find_eq_iff] simp only [h, true_and] push_neg rfl · rw [iff_false_left h.ne] rintro ⟨h', -⟩ exact h1 ⟨n, h, h'⟩ /-- A group element has finite order iff its order is positive. -/ @[to_additive "A group element has finite additive order iff its order is positive."] theorem orderOf_pos_iff : 0 < orderOf x ↔ IsOfFinOrder x := by rw [iff_not_comm.mp orderOf_eq_zero_iff, pos_iff_ne_zero] @[to_additive] theorem IsOfFinOrder.mono [Monoid β] {y : β} (hx : IsOfFinOrder x) (h : orderOf y ∣ orderOf x) : IsOfFinOrder y := by rw [← orderOf_pos_iff] at hx ⊢; exact Nat.pos_of_dvd_of_pos h hx @[to_additive] theorem pow_ne_one_of_lt_orderOf (n0 : n ≠ 0) (h : n < orderOf x) : x ^ n ≠ 1 := fun j => not_isPeriodicPt_of_pos_of_lt_minimalPeriod n0 h ((isPeriodicPt_mul_iff_pow_eq_one x).mpr j) @[deprecated (since := "2024-07-20")] alias pow_ne_one_of_lt_orderOf' := pow_ne_one_of_lt_orderOf @[deprecated (since := "2024-07-20")] alias nsmul_ne_zero_of_lt_addOrderOf' := nsmul_ne_zero_of_lt_addOrderOf @[to_additive] theorem orderOf_le_of_pow_eq_one (hn : 0 < n) (h : x ^ n = 1) : orderOf x ≤ n := IsPeriodicPt.minimalPeriod_le hn (by rwa [isPeriodicPt_mul_iff_pow_eq_one]) @[to_additive (attr := simp)] theorem orderOf_one : orderOf (1 : G) = 1 := by rw [orderOf, ← minimalPeriod_id (x := (1 : G)), ← one_mul_eq_id] @[to_additive (attr := simp) AddMonoid.addOrderOf_eq_one_iff] theorem orderOf_eq_one_iff : orderOf x = 1 ↔ x = 1 := by rw [orderOf, minimalPeriod_eq_one_iff_isFixedPt, IsFixedPt, mul_one] @[to_additive (attr := simp) mod_addOrderOf_nsmul] lemma pow_mod_orderOf (x : G) (n : ℕ) : x ^ (n % orderOf x) = x ^ n := calc x ^ (n % orderOf x) = x ^ (n % orderOf x + orderOf x * (n / orderOf x)) := by simp [pow_add, pow_mul, pow_orderOf_eq_one] _ = x ^ n := by rw [Nat.mod_add_div] @[to_additive] theorem orderOf_dvd_of_pow_eq_one (h : x ^ n = 1) : orderOf x ∣ n := IsPeriodicPt.minimalPeriod_dvd ((isPeriodicPt_mul_iff_pow_eq_one _).mpr h) @[to_additive] theorem orderOf_dvd_iff_pow_eq_one {n : ℕ} : orderOf x ∣ n ↔ x ^ n = 1 := ⟨fun h => by rw [← pow_mod_orderOf, Nat.mod_eq_zero_of_dvd h, _root_.pow_zero], orderOf_dvd_of_pow_eq_one⟩ @[to_additive addOrderOf_smul_dvd] theorem orderOf_pow_dvd (n : ℕ) : orderOf (x ^ n) ∣ orderOf x := by rw [orderOf_dvd_iff_pow_eq_one, pow_right_comm, pow_orderOf_eq_one, one_pow] @[to_additive] lemma pow_injOn_Iio_orderOf : (Set.Iio <| orderOf x).InjOn (x ^ ·) := by simpa only [mul_left_iterate, mul_one] using iterate_injOn_Iio_minimalPeriod (f := (x * ·)) (x := 1) @[to_additive] protected lemma IsOfFinOrder.mem_powers_iff_mem_range_orderOf [DecidableEq G] (hx : IsOfFinOrder x) : y ∈ Submonoid.powers x ↔ y ∈ (Finset.range (orderOf x)).image (x ^ ·) := Finset.mem_range_iff_mem_finset_range_of_mod_eq' hx.orderOf_pos <| pow_mod_orderOf _ @[to_additive] protected lemma IsOfFinOrder.powers_eq_image_range_orderOf [DecidableEq G] (hx : IsOfFinOrder x) : (Submonoid.powers x : Set G) = (Finset.range (orderOf x)).image (x ^ ·) := Set.ext fun _ ↦ hx.mem_powers_iff_mem_range_orderOf @[deprecated (since := "2024-02-21")] alias IsOfFinAddOrder.powers_eq_image_range_orderOf := IsOfFinAddOrder.multiples_eq_image_range_addOrderOf @[to_additive] theorem pow_eq_one_iff_modEq : x ^ n = 1 ↔ n ≡ 0 [MOD orderOf x] := by rw [modEq_zero_iff_dvd, orderOf_dvd_iff_pow_eq_one] @[to_additive] theorem orderOf_map_dvd {H : Type*} [Monoid H] (ψ : G →* H) (x : G) : orderOf (ψ x) ∣ orderOf x := by apply orderOf_dvd_of_pow_eq_one rw [← map_pow, pow_orderOf_eq_one] apply map_one @[to_additive] theorem exists_pow_eq_self_of_coprime (h : n.Coprime (orderOf x)) : ∃ m : ℕ, (x ^ n) ^ m = x := by by_cases h0 : orderOf x = 0 · rw [h0, coprime_zero_right] at h exact ⟨1, by rw [h, pow_one, pow_one]⟩ by_cases h1 : orderOf x = 1 · exact ⟨0, by rw [orderOf_eq_one_iff.mp h1, one_pow, one_pow]⟩ obtain ⟨m, h⟩ := exists_mul_emod_eq_one_of_coprime h (one_lt_iff_ne_zero_and_ne_one.mpr ⟨h0, h1⟩) exact ⟨m, by rw [← pow_mul, ← pow_mod_orderOf, h, pow_one]⟩ /-- If `x^n = 1`, but `x^(n/p) ≠ 1` for all prime factors `p` of `n`, then `x` has order `n` in `G`. -/ @[to_additive addOrderOf_eq_of_nsmul_and_div_prime_nsmul "If `n * x = 0`, but `n/p * x ≠ 0` for all prime factors `p` of `n`, then `x` has order `n` in `G`."] theorem orderOf_eq_of_pow_and_pow_div_prime (hn : 0 < n) (hx : x ^ n = 1) (hd : ∀ p : ℕ, p.Prime → p ∣ n → x ^ (n / p) ≠ 1) : orderOf x = n := by -- Let `a` be `n/(orderOf x)`, and show `a = 1` cases' exists_eq_mul_right_of_dvd (orderOf_dvd_of_pow_eq_one hx) with a ha suffices a = 1 by simp [this, ha] -- Assume `a` is not one... by_contra h have a_min_fac_dvd_p_sub_one : a.minFac ∣ n := by obtain ⟨b, hb⟩ : ∃ b : ℕ, a = b * a.minFac := exists_eq_mul_left_of_dvd a.minFac_dvd rw [hb, ← mul_assoc] at ha exact Dvd.intro_left (orderOf x * b) ha.symm -- Use the minimum prime factor of `a` as `p`. refine hd a.minFac (Nat.minFac_prime h) a_min_fac_dvd_p_sub_one ?_ rw [← orderOf_dvd_iff_pow_eq_one, Nat.dvd_div_iff_mul_dvd a_min_fac_dvd_p_sub_one, ha, mul_comm, Nat.mul_dvd_mul_iff_left (IsOfFinOrder.orderOf_pos _)] · exact Nat.minFac_dvd a · rw [isOfFinOrder_iff_pow_eq_one] exact Exists.intro n (id ⟨hn, hx⟩) @[to_additive] theorem orderOf_eq_orderOf_iff {H : Type*} [Monoid H] {y : H} : orderOf x = orderOf y ↔ ∀ n : ℕ, x ^ n = 1 ↔ y ^ n = 1 := by simp_rw [← isPeriodicPt_mul_iff_pow_eq_one, ← minimalPeriod_eq_minimalPeriod_iff, orderOf] /-- An injective homomorphism of monoids preserves orders of elements. -/ @[to_additive "An injective homomorphism of additive monoids preserves orders of elements."] theorem orderOf_injective {H : Type*} [Monoid H] (f : G →* H) (hf : Function.Injective f) (x : G) : orderOf (f x) = orderOf x := by simp_rw [orderOf_eq_orderOf_iff, ← f.map_pow, ← f.map_one, hf.eq_iff, forall_const] /-- A multiplicative equivalence preserves orders of elements. -/ @[to_additive (attr := simp) "An additive equivalence preserves orders of elements."] lemma MulEquiv.orderOf_eq {H : Type*} [Monoid H] (e : G ≃* H) (x : G) : orderOf (e x) = orderOf x := orderOf_injective e e.injective x @[to_additive] theorem Function.Injective.isOfFinOrder_iff [Monoid H] {f : G →* H} (hf : Injective f) : IsOfFinOrder (f x) ↔ IsOfFinOrder x := by rw [← orderOf_pos_iff, orderOf_injective f hf x, ← orderOf_pos_iff] @[to_additive (attr := norm_cast, simp)] theorem orderOf_submonoid {H : Submonoid G} (y : H) : orderOf (y : G) = orderOf y := orderOf_injective H.subtype Subtype.coe_injective y @[to_additive] theorem orderOf_units {y : Gˣ} : orderOf (y : G) = orderOf y := orderOf_injective (Units.coeHom G) Units.ext y /-- If the order of `x` is finite, then `x` is a unit with inverse `x ^ (orderOf x - 1)`. -/ @[simps] noncomputable def IsOfFinOrder.unit {M} [Monoid M] {x : M} (hx : IsOfFinOrder x) : Mˣ := ⟨x, x ^ (orderOf x - 1), by rw [← _root_.pow_succ', tsub_add_cancel_of_le (by exact hx.orderOf_pos), pow_orderOf_eq_one], by rw [← _root_.pow_succ, tsub_add_cancel_of_le (by exact hx.orderOf_pos), pow_orderOf_eq_one]⟩ lemma IsOfFinOrder.isUnit {M} [Monoid M] {x : M} (hx : IsOfFinOrder x) : IsUnit x := ⟨hx.unit, rfl⟩ variable (x) @[to_additive] theorem orderOf_pow' (h : n ≠ 0) : orderOf (x ^ n) = orderOf x / gcd (orderOf x) n := by unfold orderOf rw [← minimalPeriod_iterate_eq_div_gcd h, mul_left_iterate] @[to_additive] lemma orderOf_pow_of_dvd {x : G} {n : ℕ} (hn : n ≠ 0) (dvd : n ∣ orderOf x) : orderOf (x ^ n) = orderOf x / n := by rw [orderOf_pow' _ hn, Nat.gcd_eq_right dvd] @[to_additive] lemma orderOf_pow_orderOf_div {x : G} {n : ℕ} (hx : orderOf x ≠ 0) (hn : n ∣ orderOf x) : orderOf (x ^ (orderOf x / n)) = n := by rw [orderOf_pow_of_dvd _ (Nat.div_dvd_of_dvd hn), Nat.div_div_self hn hx] rw [← Nat.div_mul_cancel hn] at hx; exact left_ne_zero_of_mul hx variable (n) @[to_additive] protected lemma IsOfFinOrder.orderOf_pow (h : IsOfFinOrder x) : orderOf (x ^ n) = orderOf x / gcd (orderOf x) n := by unfold orderOf rw [← minimalPeriod_iterate_eq_div_gcd' h, mul_left_iterate] @[to_additive] lemma Nat.Coprime.orderOf_pow (h : (orderOf y).Coprime m) : orderOf (y ^ m) = orderOf y := by by_cases hg : IsOfFinOrder y · rw [hg.orderOf_pow y m , h.gcd_eq_one, Nat.div_one] · rw [m.coprime_zero_left.1 (orderOf_eq_zero hg ▸ h), pow_one] @[to_additive] lemma IsOfFinOrder.natCard_powers_le_orderOf (ha : IsOfFinOrder a) : Nat.card (powers a : Set G) ≤ orderOf a := by classical simpa [ha.powers_eq_image_range_orderOf, Finset.card_range, Nat.Iio_eq_range] using Finset.card_image_le (s := Finset.range (orderOf a)) @[to_additive] lemma IsOfFinOrder.finite_powers (ha : IsOfFinOrder a) : (powers a : Set G).Finite := by classical rw [ha.powers_eq_image_range_orderOf]; exact Finset.finite_toSet _ namespace Commute variable {x} @[to_additive] theorem orderOf_mul_dvd_lcm (h : Commute x y) : orderOf (x * y) ∣ Nat.lcm (orderOf x) (orderOf y) := by rw [orderOf, ← comp_mul_left] exact Function.Commute.minimalPeriod_of_comp_dvd_lcm h.function_commute_mul_left @[to_additive] theorem orderOf_dvd_lcm_mul (h : Commute x y): orderOf y ∣ Nat.lcm (orderOf x) (orderOf (x * y)) := by by_cases h0 : orderOf x = 0 · rw [h0, lcm_zero_left] apply dvd_zero conv_lhs => rw [← one_mul y, ← pow_orderOf_eq_one x, ← succ_pred_eq_of_pos (Nat.pos_of_ne_zero h0), _root_.pow_succ, mul_assoc] exact (((Commute.refl x).mul_right h).pow_left _).orderOf_mul_dvd_lcm.trans (lcm_dvd_iff.2 ⟨(orderOf_pow_dvd _).trans (dvd_lcm_left _ _), dvd_lcm_right _ _⟩) @[to_additive addOrderOf_add_dvd_mul_addOrderOf] theorem orderOf_mul_dvd_mul_orderOf (h : Commute x y): orderOf (x * y) ∣ orderOf x * orderOf y := dvd_trans h.orderOf_mul_dvd_lcm (lcm_dvd_mul _ _) @[to_additive addOrderOf_add_eq_mul_addOrderOf_of_coprime] theorem orderOf_mul_eq_mul_orderOf_of_coprime (h : Commute x y) (hco : (orderOf x).Coprime (orderOf y)) : orderOf (x * y) = orderOf x * orderOf y := by rw [orderOf, ← comp_mul_left] exact h.function_commute_mul_left.minimalPeriod_of_comp_eq_mul_of_coprime hco /-- Commuting elements of finite order are closed under multiplication. -/ @[to_additive "Commuting elements of finite additive order are closed under addition."] theorem isOfFinOrder_mul (h : Commute x y) (hx : IsOfFinOrder x) (hy : IsOfFinOrder y) : IsOfFinOrder (x * y) := orderOf_pos_iff.mp <| pos_of_dvd_of_pos h.orderOf_mul_dvd_mul_orderOf <| mul_pos hx.orderOf_pos hy.orderOf_pos /-- If each prime factor of `orderOf x` has higher multiplicity in `orderOf y`, and `x` commutes with `y`, then `x * y` has the same order as `y`. -/ @[to_additive addOrderOf_add_eq_right_of_forall_prime_mul_dvd "If each prime factor of `addOrderOf x` has higher multiplicity in `addOrderOf y`, and `x` commutes with `y`, then `x + y` has the same order as `y`."] theorem orderOf_mul_eq_right_of_forall_prime_mul_dvd (h : Commute x y) (hy : IsOfFinOrder y) (hdvd : ∀ p : ℕ, p.Prime → p ∣ orderOf x → p * orderOf x ∣ orderOf y) : orderOf (x * y) = orderOf y := by have hoy := hy.orderOf_pos have hxy := dvd_of_forall_prime_mul_dvd hdvd apply orderOf_eq_of_pow_and_pow_div_prime hoy <;> simp only [Ne, ← orderOf_dvd_iff_pow_eq_one] · exact h.orderOf_mul_dvd_lcm.trans (lcm_dvd hxy dvd_rfl) refine fun p hp hpy hd => hp.ne_one ?_ rw [← Nat.dvd_one, ← mul_dvd_mul_iff_right hoy.ne', one_mul, ← dvd_div_iff_mul_dvd hpy] refine (orderOf_dvd_lcm_mul h).trans (lcm_dvd ((dvd_div_iff_mul_dvd hpy).2 ?_) hd) by_cases h : p ∣ orderOf x exacts [hdvd p hp h, (hp.coprime_iff_not_dvd.2 h).mul_dvd_of_dvd_of_dvd hpy hxy] end Commute section PPrime variable {x n} {p : ℕ} [hp : Fact p.Prime] @[to_additive] theorem orderOf_eq_prime (hg : x ^ p = 1) (hg1 : x ≠ 1) : orderOf x = p := minimalPeriod_eq_prime ((isPeriodicPt_mul_iff_pow_eq_one _).mpr hg) (by rwa [IsFixedPt, mul_one]) @[to_additive addOrderOf_eq_prime_pow] theorem orderOf_eq_prime_pow (hnot : ¬x ^ p ^ n = 1) (hfin : x ^ p ^ (n + 1) = 1) : orderOf x = p ^ (n + 1) := by apply minimalPeriod_eq_prime_pow <;> rwa [isPeriodicPt_mul_iff_pow_eq_one] @[to_additive exists_addOrderOf_eq_prime_pow_iff] theorem exists_orderOf_eq_prime_pow_iff : (∃ k : ℕ, orderOf x = p ^ k) ↔ ∃ m : ℕ, x ^ (p : ℕ) ^ m = 1 := ⟨fun ⟨k, hk⟩ => ⟨k, by rw [← hk, pow_orderOf_eq_one]⟩, fun ⟨_, hm⟩ => by obtain ⟨k, _, hk⟩ := (Nat.dvd_prime_pow hp.elim).mp (orderOf_dvd_of_pow_eq_one hm) exact ⟨k, hk⟩⟩ end PPrime end Monoid section CancelMonoid variable [LeftCancelMonoid G] {x y : G} {a : G} {m n : ℕ} @[to_additive] theorem pow_eq_pow_iff_modEq : x ^ n = x ^ m ↔ n ≡ m [MOD orderOf x] := by wlog hmn : m ≤ n generalizing m n · rw [eq_comm, ModEq.comm, this (le_of_not_le hmn)] obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le hmn rw [← mul_one (x ^ m), pow_add, mul_left_cancel_iff, pow_eq_one_iff_modEq] exact ⟨fun h => Nat.ModEq.add_left _ h, fun h => Nat.ModEq.add_left_cancel' _ h⟩ @[to_additive (attr := simp)] lemma injective_pow_iff_not_isOfFinOrder : Injective (fun n : ℕ ↦ x ^ n) ↔ ¬IsOfFinOrder x := by refine ⟨fun h => not_isOfFinOrder_of_injective_pow h, fun h n m hnm => ?_⟩ rwa [pow_eq_pow_iff_modEq, orderOf_eq_zero_iff.mpr h, modEq_zero_iff] at hnm @[to_additive] lemma pow_inj_mod {n m : ℕ} : x ^ n = x ^ m ↔ n % orderOf x = m % orderOf x := pow_eq_pow_iff_modEq @[to_additive] theorem pow_inj_iff_of_orderOf_eq_zero (h : orderOf x = 0) {n m : ℕ} : x ^ n = x ^ m ↔ n = m := by rw [pow_eq_pow_iff_modEq, h, modEq_zero_iff] @[to_additive] theorem infinite_not_isOfFinOrder {x : G} (h : ¬IsOfFinOrder x) : { y : G | ¬IsOfFinOrder y }.Infinite := by let s := { n | 0 < n }.image fun n : ℕ => x ^ n have hs : s ⊆ { y : G | ¬IsOfFinOrder y } := by rintro - ⟨n, hn : 0 < n, rfl⟩ (contra : IsOfFinOrder (x ^ n)) apply h rw [isOfFinOrder_iff_pow_eq_one] at contra ⊢ obtain ⟨m, hm, hm'⟩ := contra exact ⟨n * m, mul_pos hn hm, by rwa [pow_mul]⟩ suffices s.Infinite by exact this.mono hs contrapose! h have : ¬Injective fun n : ℕ => x ^ n := by have := Set.not_injOn_infinite_finite_image (Set.Ioi_infinite 0) (Set.not_infinite.mp h) contrapose! this exact Set.injOn_of_injective this rwa [injective_pow_iff_not_isOfFinOrder, Classical.not_not] at this @[to_additive (attr := simp)] lemma finite_powers : (powers a : Set G).Finite ↔ IsOfFinOrder a := by refine ⟨fun h ↦ ?_, IsOfFinOrder.finite_powers⟩ obtain ⟨m, n, hmn, ha⟩ := h.exists_lt_map_eq_of_forall_mem (f := fun n : ℕ ↦ a ^ n) (fun n ↦ by simp [mem_powers_iff]) refine isOfFinOrder_iff_pow_eq_one.2 ⟨n - m, tsub_pos_iff_lt.2 hmn, ?_⟩ rw [← mul_left_cancel_iff (a := a ^ m), ← pow_add, add_tsub_cancel_of_le hmn.le, ha, mul_one] @[to_additive (attr := simp)] lemma infinite_powers : (powers a : Set G).Infinite ↔ ¬ IsOfFinOrder a := finite_powers.not /-- The equivalence between `Fin (orderOf x)` and `Submonoid.powers x`, sending `i` to `x ^ i`."-/ @[to_additive "The equivalence between `Fin (addOrderOf a)` and `AddSubmonoid.multiples a`, sending `i` to `i • a`."] noncomputable def finEquivPowers (x : G) (hx : IsOfFinOrder x) : Fin (orderOf x) ≃ powers x := Equiv.ofBijective (fun n ↦ ⟨x ^ (n : ℕ), ⟨n, rfl⟩⟩) ⟨fun ⟨_, h₁⟩ ⟨_, h₂⟩ ij ↦ Fin.ext (pow_injOn_Iio_orderOf h₁ h₂ (Subtype.mk_eq_mk.1 ij)), fun ⟨_, i, rfl⟩ ↦ ⟨⟨i % orderOf x, mod_lt _ hx.orderOf_pos⟩, Subtype.eq <| pow_mod_orderOf _ _⟩⟩ @[to_additive (attr := simp)] lemma finEquivPowers_apply (x : G) (hx) {n : Fin (orderOf x)} : finEquivPowers x hx n = ⟨x ^ (n : ℕ), n, rfl⟩ := rfl @[to_additive (attr := simp)] lemma finEquivPowers_symm_apply (x : G) (hx) (n : ℕ) {hn : ∃ m : ℕ, x ^ m = x ^ n} : (finEquivPowers x hx).symm ⟨x ^ n, hn⟩ = ⟨n % orderOf x, Nat.mod_lt _ hx.orderOf_pos⟩ := by rw [Equiv.symm_apply_eq, finEquivPowers_apply, Subtype.mk_eq_mk, ← pow_mod_orderOf, Fin.val_mk] /-- See also `orderOf_eq_card_powers`. -/ @[to_additive "See also `addOrder_eq_card_multiples`."] lemma Nat.card_submonoidPowers : Nat.card (powers a) = orderOf a := by classical by_cases ha : IsOfFinOrder a · exact (Nat.card_congr (finEquivPowers _ ha).symm).trans <| by simp · have := (infinite_powers.2 ha).to_subtype rw [orderOf_eq_zero ha, Nat.card_eq_zero_of_infinite] end CancelMonoid section Group variable [Group G] {x y : G} {i : ℤ} /-- Inverses of elements of finite order have finite order. -/ @[to_additive (attr := simp) "Inverses of elements of finite additive order have finite additive order."] theorem isOfFinOrder_inv_iff {x : G} : IsOfFinOrder x⁻¹ ↔ IsOfFinOrder x := by simp [isOfFinOrder_iff_pow_eq_one] @[to_additive] alias ⟨IsOfFinOrder.of_inv, IsOfFinOrder.inv⟩ := isOfFinOrder_inv_iff @[to_additive] theorem orderOf_dvd_iff_zpow_eq_one : (orderOf x : ℤ) ∣ i ↔ x ^ i = 1 := by rcases Int.eq_nat_or_neg i with ⟨i, rfl | rfl⟩ · rw [Int.natCast_dvd_natCast, orderOf_dvd_iff_pow_eq_one, zpow_natCast] · rw [dvd_neg, Int.natCast_dvd_natCast, zpow_neg, inv_eq_one, zpow_natCast, orderOf_dvd_iff_pow_eq_one] @[to_additive (attr := simp)] theorem orderOf_inv (x : G) : orderOf x⁻¹ = orderOf x := by simp [orderOf_eq_orderOf_iff] namespace Subgroup variable {H : Subgroup G} @[to_additive (attr := norm_cast)] -- Porting note (#10618): simp can prove this (so removed simp) lemma orderOf_coe (a : H) : orderOf (a : G) = orderOf a := orderOf_injective H.subtype Subtype.coe_injective _ @[to_additive (attr := simp)] lemma orderOf_mk (a : G) (ha) : orderOf (⟨a, ha⟩ : H) = orderOf a := (orderOf_coe _).symm end Subgroup @[to_additive mod_addOrderOf_zsmul] lemma zpow_mod_orderOf (x : G) (z : ℤ) : x ^ (z % (orderOf x : ℤ)) = x ^ z := calc x ^ (z % (orderOf x : ℤ)) = x ^ (z % orderOf x + orderOf x * (z / orderOf x) : ℤ) := by simp [zpow_add, zpow_mul, pow_orderOf_eq_one] _ = x ^ z := by rw [Int.emod_add_ediv] @[to_additive (attr := simp) zsmul_smul_addOrderOf] theorem zpow_pow_orderOf : (x ^ i) ^ orderOf x = 1 := by by_cases h : IsOfFinOrder x · rw [← zpow_natCast, ← zpow_mul, mul_comm, zpow_mul, zpow_natCast, pow_orderOf_eq_one, one_zpow] · rw [orderOf_eq_zero h, _root_.pow_zero] @[to_additive] theorem IsOfFinOrder.zpow (h : IsOfFinOrder x) {i : ℤ} : IsOfFinOrder (x ^ i) := isOfFinOrder_iff_pow_eq_one.mpr ⟨orderOf x, h.orderOf_pos, zpow_pow_orderOf⟩ @[to_additive] theorem IsOfFinOrder.of_mem_zpowers (h : IsOfFinOrder x) (h' : y ∈ Subgroup.zpowers x) : IsOfFinOrder y := by obtain ⟨k, rfl⟩ := Subgroup.mem_zpowers_iff.mp h' exact h.zpow @[to_additive] theorem orderOf_dvd_of_mem_zpowers (h : y ∈ Subgroup.zpowers x) : orderOf y ∣ orderOf x := by obtain ⟨k, rfl⟩ := Subgroup.mem_zpowers_iff.mp h rw [orderOf_dvd_iff_pow_eq_one] exact zpow_pow_orderOf theorem smul_eq_self_of_mem_zpowers {α : Type*} [MulAction G α] (hx : x ∈ Subgroup.zpowers y) {a : α} (hs : y • a = a) : x • a = a := by obtain ⟨k, rfl⟩ := Subgroup.mem_zpowers_iff.mp hx rw [← MulAction.toPerm_apply, ← MulAction.toPermHom_apply, MonoidHom.map_zpow _ y k, MulAction.toPermHom_apply] exact Function.IsFixedPt.perm_zpow (by exact hs) k -- Porting note: help elab'n with `by exact` theorem vadd_eq_self_of_mem_zmultiples {α G : Type*} [AddGroup G] [AddAction G α] {x y : G} (hx : x ∈ AddSubgroup.zmultiples y) {a : α} (hs : y +ᵥ a = a) : x +ᵥ a = a := @smul_eq_self_of_mem_zpowers (Multiplicative G) _ _ _ α _ hx a hs attribute [to_additive existing] smul_eq_self_of_mem_zpowers @[to_additive] lemma IsOfFinOrder.mem_powers_iff_mem_zpowers (hx : IsOfFinOrder x) : y ∈ powers x ↔ y ∈ zpowers x := ⟨fun ⟨n, hn⟩ ↦ ⟨n, by simp_all⟩, fun ⟨i, hi⟩ ↦ ⟨(i % orderOf x).natAbs, by dsimp only rwa [← zpow_natCast, Int.natAbs_of_nonneg <| Int.emod_nonneg _ <| Int.natCast_ne_zero_iff_pos.2 <| hx.orderOf_pos, zpow_mod_orderOf]⟩⟩ @[to_additive] lemma IsOfFinOrder.powers_eq_zpowers (hx : IsOfFinOrder x) : (powers x : Set G) = zpowers x := Set.ext fun _ ↦ hx.mem_powers_iff_mem_zpowers @[to_additive] lemma IsOfFinOrder.mem_zpowers_iff_mem_range_orderOf [DecidableEq G] (hx : IsOfFinOrder x) : y ∈ zpowers x ↔ y ∈ (Finset.range (orderOf x)).image (x ^ ·) := hx.mem_powers_iff_mem_zpowers.symm.trans hx.mem_powers_iff_mem_range_orderOf /-- The equivalence between `Fin (orderOf x)` and `Subgroup.zpowers x`, sending `i` to `x ^ i`. -/ @[to_additive "The equivalence between `Fin (addOrderOf a)` and `Subgroup.zmultiples a`, sending `i` to `i • a`."] noncomputable def finEquivZPowers (x : G) (hx : IsOfFinOrder x) : Fin (orderOf x) ≃ (zpowers x : Set G) := (finEquivPowers x hx).trans <| Equiv.Set.ofEq hx.powers_eq_zpowers -- This lemma has always been bad, but the linter only noticed after leaprover/lean4#2644. @[to_additive (attr := simp, nolint simpNF)] lemma finEquivZPowers_apply (hx) {n : Fin (orderOf x)} : finEquivZPowers x hx n = ⟨x ^ (n : ℕ), n, zpow_natCast x n⟩ := rfl -- This lemma has always been bad, but the linter only noticed after leanprover/lean4#2644. @[to_additive (attr := simp, nolint simpNF)] lemma finEquivZPowers_symm_apply (x : G) (hx) (n : ℕ) : (finEquivZPowers x hx).symm ⟨x ^ n, ⟨n, by simp⟩⟩ = ⟨n % orderOf x, Nat.mod_lt _ hx.orderOf_pos⟩ := by rw [finEquivZPowers, Equiv.symm_trans_apply]; exact finEquivPowers_symm_apply x _ n end Group section CommMonoid variable [CommMonoid G] {x y : G} /-- Elements of finite order are closed under multiplication. -/ @[to_additive "Elements of finite additive order are closed under addition."] theorem IsOfFinOrder.mul (hx : IsOfFinOrder x) (hy : IsOfFinOrder y) : IsOfFinOrder (x * y) := (Commute.all x y).isOfFinOrder_mul hx hy end CommMonoid section FiniteMonoid variable [Monoid G] {x : G} {n : ℕ} @[to_additive] theorem sum_card_orderOf_eq_card_pow_eq_one [Fintype G] [DecidableEq G] (hn : n ≠ 0) : (∑ m ∈ (Finset.range n.succ).filter (· ∣ n), (Finset.univ.filter fun x : G => orderOf x = m).card) = (Finset.univ.filter fun x : G => x ^ n = 1).card := calc (∑ m ∈ (Finset.range n.succ).filter (· ∣ n), (Finset.univ.filter fun x : G => orderOf x = m).card) = _ := (Finset.card_biUnion (by intros apply Finset.disjoint_filter.2 rintro _ _ rfl; assumption)).symm _ = _ := congr_arg Finset.card (Finset.ext (by intro x suffices orderOf x ≤ n ∧ orderOf x ∣ n ↔ x ^ n = 1 by simpa [Nat.lt_succ_iff] exact ⟨fun h => by let ⟨m, hm⟩ := h.2 rw [hm, pow_mul, pow_orderOf_eq_one, one_pow], fun h => ⟨orderOf_le_of_pow_eq_one hn.bot_lt h, orderOf_dvd_of_pow_eq_one h⟩⟩)) @[to_additive] theorem orderOf_le_card_univ [Fintype G] : orderOf x ≤ Fintype.card G := Finset.le_card_of_inj_on_range (x ^ ·) (fun _ _ ↦ Finset.mem_univ _) pow_injOn_Iio_orderOf end FiniteMonoid section FiniteCancelMonoid variable [LeftCancelMonoid G] -- TODO: Of course everything also works for `RightCancelMonoid`. section Finite variable [Finite G] {x y : G} {n : ℕ} -- TODO: Use this to show that a finite left cancellative monoid is a group. @[to_additive] lemma isOfFinOrder_of_finite (x : G) : IsOfFinOrder x := by by_contra h; exact infinite_not_isOfFinOrder h <| Set.toFinite _ /-- This is the same as `IsOfFinOrder.orderOf_pos` but with one fewer explicit assumption since this is automatic in case of a finite cancellative monoid. -/ @[to_additive "This is the same as `IsOfFinAddOrder.addOrderOf_pos` but with one fewer explicit assumption since this is automatic in case of a finite cancellative additive monoid."] lemma orderOf_pos (x : G) : 0 < orderOf x := (isOfFinOrder_of_finite x).orderOf_pos /-- This is the same as `orderOf_pow'` and `orderOf_pow''` but with one assumption less which is automatic in the case of a finite cancellative monoid. -/ @[to_additive "This is the same as `addOrderOf_nsmul'` and `addOrderOf_nsmul` but with one assumption less which is automatic in the case of a finite cancellative additive monoid."] theorem orderOf_pow (x : G) : orderOf (x ^ n) = orderOf x / gcd (orderOf x) n := (isOfFinOrder_of_finite _).orderOf_pow _ @[to_additive] theorem mem_powers_iff_mem_range_orderOf [DecidableEq G] : y ∈ powers x ↔ y ∈ (Finset.range (orderOf x)).image (x ^ ·) := Finset.mem_range_iff_mem_finset_range_of_mod_eq' (orderOf_pos x) <| pow_mod_orderOf _ /-- The equivalence between `Submonoid.powers` of two elements `x, y` of the same order, mapping `x ^ i` to `y ^ i`. -/ @[to_additive "The equivalence between `Submonoid.multiples` of two elements `a, b` of the same additive order, mapping `i • a` to `i • b`."] noncomputable def powersEquivPowers (h : orderOf x = orderOf y) : powers x ≃ powers y := (finEquivPowers x <| isOfFinOrder_of_finite _).symm.trans <| (finCongr h).trans <| finEquivPowers y <| isOfFinOrder_of_finite _ @[to_additive (attr := simp)] theorem powersEquivPowers_apply (h : orderOf x = orderOf y) (n : ℕ) : powersEquivPowers h ⟨x ^ n, n, rfl⟩ = ⟨y ^ n, n, rfl⟩ := by rw [powersEquivPowers, Equiv.trans_apply, Equiv.trans_apply, finEquivPowers_symm_apply, ← Equiv.eq_symm_apply, finEquivPowers_symm_apply] simp [h] end Finite variable [Fintype G] {x : G} @[to_additive] lemma orderOf_eq_card_powers : orderOf x = Fintype.card (powers x : Set G) := (Fintype.card_fin (orderOf x)).symm.trans <| Fintype.card_eq.2 ⟨finEquivPowers x <| isOfFinOrder_of_finite _⟩ end FiniteCancelMonoid section FiniteGroup variable [Group G] {x y : G} @[to_additive] theorem zpow_eq_one_iff_modEq {n : ℤ} : x ^ n = 1 ↔ n ≡ 0 [ZMOD orderOf x] := by rw [Int.modEq_zero_iff_dvd, orderOf_dvd_iff_zpow_eq_one] @[to_additive] theorem zpow_eq_zpow_iff_modEq {m n : ℤ} : x ^ m = x ^ n ↔ m ≡ n [ZMOD orderOf x] := by rw [← mul_inv_eq_one, ← zpow_sub, zpow_eq_one_iff_modEq, Int.modEq_iff_dvd, Int.modEq_iff_dvd, zero_sub, neg_sub] @[to_additive (attr := simp)] theorem injective_zpow_iff_not_isOfFinOrder : (Injective fun n : ℤ => x ^ n) ↔ ¬IsOfFinOrder x := by refine ⟨?_, fun h n m hnm => ?_⟩ · simp_rw [isOfFinOrder_iff_pow_eq_one] rintro h ⟨n, hn, hx⟩ exact Nat.cast_ne_zero.2 hn.ne' (h <| by simpa using hx) rwa [zpow_eq_zpow_iff_modEq, orderOf_eq_zero_iff.2 h, Nat.cast_zero, Int.modEq_zero_iff] at hnm section Finite variable [Finite G] @[to_additive] theorem exists_zpow_eq_one (x : G) : ∃ (i : ℤ) (_ : i ≠ 0), x ^ (i : ℤ) = 1 := by obtain ⟨w, hw1, hw2⟩ := isOfFinOrder_of_finite x refine ⟨w, Int.natCast_ne_zero.mpr (_root_.ne_of_gt hw1), ?_⟩ rw [zpow_natCast] exact (isPeriodicPt_mul_iff_pow_eq_one _).mp hw2 @[to_additive] lemma mem_powers_iff_mem_zpowers : y ∈ powers x ↔ y ∈ zpowers x := (isOfFinOrder_of_finite _).mem_powers_iff_mem_zpowers @[to_additive] lemma powers_eq_zpowers (x : G) : (powers x : Set G) = zpowers x := (isOfFinOrder_of_finite _).powers_eq_zpowers @[to_additive] lemma mem_zpowers_iff_mem_range_orderOf [DecidableEq G] : y ∈ zpowers x ↔ y ∈ (Finset.range (orderOf x)).image (x ^ ·) := (isOfFinOrder_of_finite _).mem_zpowers_iff_mem_range_orderOf /-- The equivalence between `Subgroup.zpowers` of two elements `x, y` of the same order, mapping `x ^ i` to `y ^ i`. -/ @[to_additive "The equivalence between `Subgroup.zmultiples` of two elements `a, b` of the same additive order, mapping `i • a` to `i • b`."] noncomputable def zpowersEquivZPowers (h : orderOf x = orderOf y) : (Subgroup.zpowers x : Set G) ≃ (Subgroup.zpowers y : Set G) := (finEquivZPowers x <| isOfFinOrder_of_finite _).symm.trans <| (finCongr h).trans <| finEquivZPowers y <| isOfFinOrder_of_finite _ -- Porting note: the simpNF linter complains that simp can change the LHS to something -- that looks the same as the current LHS even with `pp.explicit` @[to_additive (attr := simp, nolint simpNF) zmultiples_equiv_zmultiples_apply] theorem zpowersEquivZPowers_apply (h : orderOf x = orderOf y) (n : ℕ) : zpowersEquivZPowers h ⟨x ^ n, n, zpow_natCast x n⟩ = ⟨y ^ n, n, zpow_natCast y n⟩ := by rw [zpowersEquivZPowers, Equiv.trans_apply, Equiv.trans_apply, finEquivZPowers_symm_apply, ← Equiv.eq_symm_apply, finEquivZPowers_symm_apply] simp [h] end Finite variable [Fintype G] {x : G} {n : ℕ} /-- See also `Nat.card_addSubgroupZPowers`. -/ @[to_additive "See also `Nat.card_subgroup`."] theorem Fintype.card_zpowers : Fintype.card (zpowers x) = orderOf x := (Fintype.card_eq.2 ⟨finEquivZPowers x <| isOfFinOrder_of_finite _⟩).symm.trans <| Fintype.card_fin (orderOf x) @[to_additive] theorem card_zpowers_le (a : G) {k : ℕ} (k_pos : k ≠ 0) (ha : a ^ k = 1) : Fintype.card (Subgroup.zpowers a) ≤ k := by rw [Fintype.card_zpowers] apply orderOf_le_of_pow_eq_one k_pos.bot_lt ha open QuotientGroup @[to_additive] theorem orderOf_dvd_card : orderOf x ∣ Fintype.card G := by classical have ft_prod : Fintype ((G ⧸ zpowers x) × zpowers x) := Fintype.ofEquiv G groupEquivQuotientProdSubgroup have ft_s : Fintype (zpowers x) := @Fintype.prodRight _ _ _ ft_prod _ have ft_cosets : Fintype (G ⧸ zpowers x) := @Fintype.prodLeft _ _ _ ft_prod ⟨⟨1, (zpowers x).one_mem⟩⟩ have eq₁ : Fintype.card G = @Fintype.card _ ft_cosets * @Fintype.card _ ft_s := calc Fintype.card G = @Fintype.card _ ft_prod := @Fintype.card_congr _ _ _ ft_prod groupEquivQuotientProdSubgroup _ = @Fintype.card _ (@instFintypeProd _ _ ft_cosets ft_s) := congr_arg (@Fintype.card _) <| Subsingleton.elim _ _ _ = @Fintype.card _ ft_cosets * @Fintype.card _ ft_s := @Fintype.card_prod _ _ ft_cosets ft_s have eq₂ : orderOf x = @Fintype.card _ ft_s := calc orderOf x = _ := Fintype.card_zpowers.symm _ = _ := congr_arg (@Fintype.card _) <| Subsingleton.elim _ _ exact Dvd.intro (@Fintype.card (G ⧸ Subgroup.zpowers x) ft_cosets) (by rw [eq₁, eq₂, mul_comm]) @[to_additive] theorem orderOf_dvd_natCard {G : Type*} [Group G] (x : G) : orderOf x ∣ Nat.card G := by cases' fintypeOrInfinite G with h h · simp only [Nat.card_eq_fintype_card, orderOf_dvd_card] · simp only [card_eq_zero_of_infinite, dvd_zero] @[to_additive] nonrec lemma Subgroup.orderOf_dvd_natCard {G : Type*} [Group G] (s : Subgroup G) {x} (hx : x ∈ s) : orderOf x ∣ Nat.card s := by simpa using orderOf_dvd_natCard (⟨x, hx⟩ : s) @[to_additive] lemma Subgroup.orderOf_le_card {G : Type*} [Group G] (s : Subgroup G) (hs : (s : Set G).Finite) {x} (hx : x ∈ s) : orderOf x ≤ Nat.card s := le_of_dvd (Nat.card_pos_iff.2 <| ⟨s.coe_nonempty.to_subtype, hs.to_subtype⟩) <| s.orderOf_dvd_natCard hx @[to_additive] lemma Submonoid.orderOf_le_card {G : Type*} [Group G] (s : Submonoid G) (hs : (s : Set G).Finite) {x} (hx : x ∈ s) : orderOf x ≤ Nat.card s := by rw [← Nat.card_submonoidPowers]; exact Nat.card_mono hs <| powers_le.2 hx @[to_additive (attr := simp) card_nsmul_eq_zero'] theorem pow_card_eq_one' {G : Type*} [Group G] {x : G} : x ^ Nat.card G = 1 := orderOf_dvd_iff_pow_eq_one.mp <| orderOf_dvd_natCard _ @[to_additive (attr := simp) card_nsmul_eq_zero] theorem pow_card_eq_one : x ^ Fintype.card G = 1 := by rw [← Nat.card_eq_fintype_card, pow_card_eq_one'] @[to_additive] theorem Subgroup.pow_index_mem {G : Type*} [Group G] (H : Subgroup G) [Normal H] (g : G) : g ^ index H ∈ H := by rw [← eq_one_iff, QuotientGroup.mk_pow H, index, pow_card_eq_one'] @[to_additive (attr := simp) mod_card_nsmul] lemma pow_mod_card (a : G) (n : ℕ) : a ^ (n % card G) = a ^ n := by rw [eq_comm, ← pow_mod_orderOf, ← Nat.mod_mod_of_dvd n orderOf_dvd_card, pow_mod_orderOf] @[to_additive (attr := simp) mod_card_zsmul] theorem zpow_mod_card (a : G) (n : ℤ) : a ^ (n % Fintype.card G : ℤ) = a ^ n := by rw [eq_comm, ← zpow_mod_orderOf, ← Int.emod_emod_of_dvd n (Int.natCast_dvd_natCast.2 orderOf_dvd_card), zpow_mod_orderOf] @[to_additive (attr := simp) mod_natCard_nsmul] lemma pow_mod_natCard {G} [Group G] (a : G) (n : ℕ) : a ^ (n % Nat.card G) = a ^ n := by rw [eq_comm, ← pow_mod_orderOf, ← Nat.mod_mod_of_dvd n $ orderOf_dvd_natCard _, pow_mod_orderOf] @[to_additive (attr := simp) mod_natCard_zsmul] lemma zpow_mod_natCard {G} [Group G] (a : G) (n : ℤ) : a ^ (n % Nat.card G : ℤ) = a ^ n := by rw [eq_comm, ← zpow_mod_orderOf, ← Int.emod_emod_of_dvd n $ Int.natCast_dvd_natCast.2 $ orderOf_dvd_natCard _, zpow_mod_orderOf] /-- If `gcd(|G|,n)=1` then the `n`th power map is a bijection -/ @[to_additive (attr := simps) "If `gcd(|G|,n)=1` then the smul by `n` is a bijection"] noncomputable def powCoprime {G : Type*} [Group G] (h : (Nat.card G).Coprime n) : G ≃ G where toFun g := g ^ n invFun g := g ^ (Nat.card G).gcdB n left_inv g := by have key := congr_arg (g ^ ·) ((Nat.card G).gcd_eq_gcd_ab n) dsimp only at key rwa [zpow_add, zpow_mul, zpow_mul, zpow_natCast, zpow_natCast, zpow_natCast, h.gcd_eq_one, pow_one, pow_card_eq_one', one_zpow, one_mul, eq_comm] at key right_inv g := by have key := congr_arg (g ^ ·) ((Nat.card G).gcd_eq_gcd_ab n) dsimp only at key rwa [zpow_add, zpow_mul, zpow_mul', zpow_natCast, zpow_natCast, zpow_natCast, h.gcd_eq_one, pow_one, pow_card_eq_one', one_zpow, one_mul, eq_comm] at key @[to_additive] -- Porting note (#10618): simp can prove this (so removed simp) theorem powCoprime_one {G : Type*} [Group G] (h : (Nat.card G).Coprime n) : powCoprime h 1 = 1 := one_pow n @[to_additive] -- Porting note (#10618): simp can prove this (so removed simp) theorem powCoprime_inv {G : Type*} [Group G] (h : (Nat.card G).Coprime n) {g : G} : powCoprime h g⁻¹ = (powCoprime h g)⁻¹ := inv_pow g n @[to_additive Nat.Coprime.nsmul_right_bijective] lemma Nat.Coprime.pow_left_bijective {G} [Group G] (hn : (Nat.card G).Coprime n) : Bijective (· ^ n : G → G) := (powCoprime hn).bijective @[to_additive add_inf_eq_bot_of_coprime] theorem inf_eq_bot_of_coprime {G : Type*} [Group G] {H K : Subgroup G} (h : Nat.Coprime (Nat.card H) (Nat.card K)) : H ⊓ K = ⊥ := card_eq_one.mp (Nat.eq_one_of_dvd_coprimes h (card_dvd_of_le inf_le_left) (card_dvd_of_le inf_le_right)) /- TODO: Generalise to `Submonoid.powers`. -/ @[to_additive] theorem image_range_orderOf [DecidableEq G] : Finset.image (fun i => x ^ i) (Finset.range (orderOf x)) = (zpowers x : Set G).toFinset := by ext x rw [Set.mem_toFinset, SetLike.mem_coe, mem_zpowers_iff_mem_range_orderOf] /- TODO: Generalise to `Finite` + `CancelMonoid`. -/ @[to_additive gcd_nsmul_card_eq_zero_iff] theorem pow_gcd_card_eq_one_iff : x ^ n = 1 ↔ x ^ gcd n (Fintype.card G) = 1 := ⟨fun h => pow_gcd_eq_one _ h <| pow_card_eq_one, fun h => by let ⟨m, hm⟩ := gcd_dvd_left n (Fintype.card G) rw [hm, pow_mul, h, one_pow]⟩ end FiniteGroup section PowIsSubgroup /-- A nonempty idempotent subset of a finite cancellative monoid is a submonoid -/ @[to_additive "A nonempty idempotent subset of a finite cancellative add monoid is a submonoid"] def submonoidOfIdempotent {M : Type*} [LeftCancelMonoid M] [Finite M] (S : Set M) (hS1 : S.Nonempty) (hS2 : S * S = S) : Submonoid M := have pow_mem : ∀ a : M, a ∈ S → ∀ n : ℕ, a ^ (n + 1) ∈ S := fun a ha => Nat.rec (by rwa [Nat.zero_eq, zero_add, pow_one]) fun n ih => (congr_arg₂ (· ∈ ·) (pow_succ a (n + 1)).symm hS2).mp (Set.mul_mem_mul ih ha) { carrier := S one_mem' := by obtain ⟨a, ha⟩ := hS1 rw [← pow_orderOf_eq_one a, ← tsub_add_cancel_of_le (succ_le_of_lt (orderOf_pos a))] exact pow_mem a ha (orderOf a - 1) mul_mem' := fun ha hb => (congr_arg₂ (· ∈ ·) rfl hS2).mp (Set.mul_mem_mul ha hb) } /-- A nonempty idempotent subset of a finite group is a subgroup -/ @[to_additive "A nonempty idempotent subset of a finite add group is a subgroup"] def subgroupOfIdempotent {G : Type*} [Group G] [Finite G] (S : Set G) (hS1 : S.Nonempty) (hS2 : S * S = S) : Subgroup G := { submonoidOfIdempotent S hS1 hS2 with carrier := S inv_mem' := fun {a} ha => show a⁻¹ ∈ submonoidOfIdempotent S hS1 hS2 by rw [← one_mul a⁻¹, ← pow_one a, ← pow_orderOf_eq_one a, ← pow_sub a (orderOf_pos a)] exact pow_mem ha (orderOf a - 1) } /-- If `S` is a nonempty subset of a finite group `G`, then `S ^ |G|` is a subgroup -/ @[to_additive (attr := simps!) smulCardAddSubgroup "If `S` is a nonempty subset of a finite add group `G`, then `|G| • S` is a subgroup"] def powCardSubgroup {G : Type*} [Group G] [Fintype G] (S : Set G) (hS : S.Nonempty) : Subgroup G := have one_mem : (1 : G) ∈ S ^ Fintype.card G := by obtain ⟨a, ha⟩ := hS rw [← pow_card_eq_one] exact Set.pow_mem_pow ha (Fintype.card G) subgroupOfIdempotent (S ^ Fintype.card G) ⟨1, one_mem⟩ <| by classical apply (Set.eq_of_subset_of_card_le (Set.subset_mul_left _ one_mem) (ge_of_eq _)).symm simp_rw [← pow_add, Group.card_pow_eq_card_pow_card_univ S (Fintype.card G + Fintype.card G) le_add_self] end PowIsSubgroup section LinearOrderedSemiring variable [LinearOrderedSemiring G] {a : G} protected lemma IsOfFinOrder.eq_one (ha₀ : 0 ≤ a) (ha : IsOfFinOrder a) : a = 1 := by obtain ⟨n, hn, ha⟩ := ha.exists_pow_eq_one exact (pow_eq_one_iff_of_nonneg ha₀ hn.ne').1 ha end LinearOrderedSemiring section LinearOrderedRing variable [LinearOrderedRing G] {a x : G} protected lemma IsOfFinOrder.eq_neg_one (ha₀ : a ≤ 0) (ha : IsOfFinOrder a) : a = -1 := (sq_eq_one_iff.1 <| ha.pow.eq_one <| sq_nonneg a).resolve_left <| by rintro rfl; exact one_pos.not_le ha₀ theorem orderOf_abs_ne_one (h : |x| ≠ 1) : orderOf x = 0 := by rw [orderOf_eq_zero_iff'] intro n hn hx replace hx : |x| ^ n = 1 := by simpa only [abs_one, abs_pow] using congr_arg abs hx cases' h.lt_or_lt with h h · exact ((pow_lt_one (abs_nonneg x) h hn.ne').ne hx).elim · exact ((one_lt_pow h hn.ne').ne' hx).elim theorem LinearOrderedRing.orderOf_le_two : orderOf x ≤ 2 := by cases' ne_or_eq |x| 1 with h h · simp [orderOf_abs_ne_one h] rcases eq_or_eq_neg_of_abs_eq h with (rfl | rfl) · simp apply orderOf_le_of_pow_eq_one <;> norm_num end LinearOrderedRing section Prod variable [Monoid α] [Monoid β] {x : α × β} {a : α} {b : β} @[to_additive] protected theorem Prod.orderOf (x : α × β) : orderOf x = (orderOf x.1).lcm (orderOf x.2) := minimalPeriod_prod_map _ _ _ @[deprecated (since := "2024-02-21")] alias Prod.add_orderOf := Prod.addOrderOf @[to_additive] theorem orderOf_fst_dvd_orderOf : orderOf x.1 ∣ orderOf x := minimalPeriod_fst_dvd @[deprecated (since := "2024-02-21")] alias add_orderOf_fst_dvd_add_orderOf := addOrderOf_fst_dvd_addOrderOf @[to_additive] theorem orderOf_snd_dvd_orderOf : orderOf x.2 ∣ orderOf x := minimalPeriod_snd_dvd @[deprecated (since := "2024-02-21")] alias add_orderOf_snd_dvd_add_orderOf := addOrderOf_snd_dvd_addOrderOf @[to_additive] theorem IsOfFinOrder.fst {x : α × β} (hx : IsOfFinOrder x) : IsOfFinOrder x.1 := hx.mono orderOf_fst_dvd_orderOf @[to_additive] theorem IsOfFinOrder.snd {x : α × β} (hx : IsOfFinOrder x) : IsOfFinOrder x.2 := hx.mono orderOf_snd_dvd_orderOf @[to_additive IsOfFinAddOrder.prod_mk] theorem IsOfFinOrder.prod_mk : IsOfFinOrder a → IsOfFinOrder b → IsOfFinOrder (a, b) := by simpa only [← orderOf_pos_iff, Prod.orderOf] using Nat.lcm_pos @[to_additive] lemma Prod.orderOf_mk : orderOf (a, b) = Nat.lcm (orderOf a) (orderOf b) := (a, b).orderOf end Prod -- TODO: Corresponding `pi` lemmas. We cannot currently state them here because of import cycles @[simp] lemma Nat.cast_card_eq_zero (R) [AddGroupWithOne R] [Fintype R] : (Fintype.card R : R) = 0 := by rw [← nsmul_one, card_nsmul_eq_zero] section NonAssocRing variable (R : Type*) [NonAssocRing R] (p : ℕ) lemma CharP.addOrderOf_one : CharP R (addOrderOf (1 : R)) where cast_eq_zero_iff' n := by rw [← Nat.smul_one_eq_cast, addOrderOf_dvd_iff_nsmul_eq_zero] variable [Fintype R] variable {R} in lemma charP_of_ne_zero (hn : card R = p) (hR : ∀ i < p, (i : R) = 0 → i = 0) : CharP R p where cast_eq_zero_iff' n := by have H : (p : R) = 0 := by rw [← hn, Nat.cast_card_eq_zero] constructor · intro h rw [← Nat.mod_add_div n p, Nat.cast_add, Nat.cast_mul, H, zero_mul, add_zero] at h rw [Nat.dvd_iff_mod_eq_zero] apply hR _ (Nat.mod_lt _ _) h rw [← hn, gt_iff_lt, Fintype.card_pos_iff] exact ⟨0⟩ · rintro ⟨n, rfl⟩ rw [Nat.cast_mul, H, zero_mul] end NonAssocRing lemma charP_of_prime_pow_injective (R) [Ring R] [Fintype R] (p n : ℕ) [hp : Fact p.Prime] (hn : card R = p ^ n) (hR : ∀ i ≤ n, (p : R) ^ i = 0 → i = n) : CharP R (p ^ n) := by obtain ⟨c, hc⟩ := CharP.exists R have hcpn : c ∣ p ^ n := by rw [← CharP.cast_eq_zero_iff R c, ← hn, Nat.cast_card_eq_zero] obtain ⟨i, hi, rfl⟩ : ∃ i ≤ n, c = p ^ i := by rwa [Nat.dvd_prime_pow hp.1] at hcpn obtain rfl : i = n := hR i hi $ by rw [← Nat.cast_pow, CharP.cast_eq_zero] assumption namespace SemiconjBy @[to_additive] lemma orderOf_eq [Group G] (a : G) {x y : G} (h : SemiconjBy a x y) : orderOf x = orderOf y := by rw [orderOf_eq_orderOf_iff] intro n exact (h.pow_right n).eq_one_iff end SemiconjBy
GroupTheory\PGroup.lean
/- Copyright (c) 2018 . All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Thomas Browning -/ import Mathlib.GroupTheory.Perm.Cycle.Type import Mathlib.GroupTheory.SpecificGroups.Cyclic /-! # p-groups This file contains a proof that if `G` is a `p`-group acting on a finite set `α`, then the number of fixed points of the action is congruent mod `p` to the cardinality of `α`. It also contains proofs of some corollaries of this lemma about existence of fixed points. -/ open Fintype MulAction variable (p : ℕ) (G : Type*) [Group G] /-- A p-group is a group in which every element has prime power order -/ def IsPGroup : Prop := ∀ g : G, ∃ k : ℕ, g ^ p ^ k = 1 variable {p} {G} namespace IsPGroup theorem iff_orderOf [hp : Fact p.Prime] : IsPGroup p G ↔ ∀ g : G, ∃ k : ℕ, orderOf g = p ^ k := forall_congr' fun g => ⟨fun ⟨k, hk⟩ => Exists.imp (fun _ h => h.right) ((Nat.dvd_prime_pow hp.out).mp (orderOf_dvd_of_pow_eq_one hk)), Exists.imp fun k hk => by rw [← hk, pow_orderOf_eq_one]⟩ theorem of_card {n : ℕ} (hG : Nat.card G = p ^ n) : IsPGroup p G := fun g => ⟨n, by rw [← hG, pow_card_eq_one']⟩ theorem of_bot : IsPGroup p (⊥ : Subgroup G) := of_card (by rw [Subgroup.card_bot, pow_zero]) theorem iff_card [Fact p.Prime] [Finite G] : IsPGroup p G ↔ ∃ n : ℕ, Nat.card G = p ^ n := by have hG : Nat.card G ≠ 0 := Nat.card_pos.ne' refine ⟨fun h => ?_, fun ⟨n, hn⟩ => of_card hn⟩ suffices ∀ q ∈ (Nat.card G).primeFactorsList, q = p by use (Nat.card G).primeFactorsList.length rw [← List.prod_replicate, ← List.eq_replicate_of_mem this, Nat.prod_primeFactorsList hG] intro q hq obtain ⟨hq1, hq2⟩ := (Nat.mem_primeFactorsList hG).mp hq haveI : Fact q.Prime := ⟨hq1⟩ obtain ⟨g, hg⟩ := exists_prime_orderOf_dvd_card' q hq2 obtain ⟨k, hk⟩ := (iff_orderOf.mp h) g exact (hq1.pow_eq_iff.mp (hg.symm.trans hk).symm).1.symm alias ⟨exists_card_eq, _⟩ := iff_card section GIsPGroup variable (hG : IsPGroup p G) theorem of_injective {H : Type*} [Group H] (ϕ : H →* G) (hϕ : Function.Injective ϕ) : IsPGroup p H := by simp_rw [IsPGroup, ← hϕ.eq_iff, ϕ.map_pow, ϕ.map_one] exact fun h => hG (ϕ h) theorem to_subgroup (H : Subgroup G) : IsPGroup p H := hG.of_injective H.subtype Subtype.coe_injective theorem of_surjective {H : Type*} [Group H] (ϕ : G →* H) (hϕ : Function.Surjective ϕ) : IsPGroup p H := by refine fun h => Exists.elim (hϕ h) fun g hg => Exists.imp (fun k hk => ?_) (hG g) rw [← hg, ← ϕ.map_pow, hk, ϕ.map_one] theorem to_quotient (H : Subgroup G) [H.Normal] : IsPGroup p (G ⧸ H) := hG.of_surjective (QuotientGroup.mk' H) Quotient.surjective_Quotient_mk'' theorem of_equiv {H : Type*} [Group H] (ϕ : G ≃* H) : IsPGroup p H := hG.of_surjective ϕ.toMonoidHom ϕ.surjective theorem orderOf_coprime {n : ℕ} (hn : p.Coprime n) (g : G) : (orderOf g).Coprime n := let ⟨k, hk⟩ := hG g (hn.pow_left k).coprime_dvd_left (orderOf_dvd_of_pow_eq_one hk) /-- If `gcd(p,n) = 1`, then the `n`th power map is a bijection. -/ noncomputable def powEquiv {n : ℕ} (hn : p.Coprime n) : G ≃ G := let h : ∀ g : G, (Nat.card (Subgroup.zpowers g)).Coprime n := fun g => (Nat.card_zpowers g).symm ▸ hG.orderOf_coprime hn g { toFun := (· ^ n) invFun := fun g => (powCoprime (h g)).symm ⟨g, Subgroup.mem_zpowers g⟩ left_inv := fun g => Subtype.ext_iff.1 <| (powCoprime (h (g ^ n))).left_inv ⟨g, _, Subtype.ext_iff.1 <| (powCoprime (h g)).left_inv ⟨g, Subgroup.mem_zpowers g⟩⟩ right_inv := fun g => Subtype.ext_iff.1 <| (powCoprime (h g)).right_inv ⟨g, Subgroup.mem_zpowers g⟩ } @[simp] theorem powEquiv_apply {n : ℕ} (hn : p.Coprime n) (g : G) : hG.powEquiv hn g = g ^ n := rfl @[simp] theorem powEquiv_symm_apply {n : ℕ} (hn : p.Coprime n) (g : G) : (hG.powEquiv hn).symm g = g ^ (orderOf g).gcdB n := by rw [← Nat.card_zpowers]; rfl variable [hp : Fact p.Prime] /-- If `p ∤ n`, then the `n`th power map is a bijection. -/ noncomputable abbrev powEquiv' {n : ℕ} (hn : ¬p ∣ n) : G ≃ G := powEquiv hG (hp.out.coprime_iff_not_dvd.mpr hn) theorem index (H : Subgroup G) [H.FiniteIndex] : ∃ n : ℕ, H.index = p ^ n := by obtain ⟨n, hn⟩ := iff_card.mp (hG.to_quotient H.normalCore) obtain ⟨k, _, hk2⟩ := (Nat.dvd_prime_pow hp.out).mp ((congr_arg _ (H.normalCore.index_eq_card.trans hn)).mp (Subgroup.index_dvd_of_le H.normalCore_le)) exact ⟨k, hk2⟩ theorem card_eq_or_dvd : Nat.card G = 1 ∨ p ∣ Nat.card G := by cases finite_or_infinite G · obtain ⟨n, hn⟩ := iff_card.mp hG rw [hn] cases' n with n n · exact Or.inl rfl · exact Or.inr ⟨p ^ n, by rw [pow_succ']⟩ · rw [Nat.card_eq_zero_of_infinite] exact Or.inr ⟨0, rfl⟩ theorem nontrivial_iff_card [Finite G] : Nontrivial G ↔ ∃ n > 0, Nat.card G = p ^ n := ⟨fun hGnt => let ⟨k, hk⟩ := iff_card.1 hG ⟨k, Nat.pos_of_ne_zero fun hk0 => by rw [hk0, pow_zero] at hk; exact Finite.one_lt_card.ne' hk, hk⟩, fun ⟨k, hk0, hk⟩ => Finite.one_lt_card_iff_nontrivial.1 <| hk.symm ▸ one_lt_pow (Fact.out (p := p.Prime)).one_lt (ne_of_gt hk0)⟩ variable {α : Type*} [MulAction G α] theorem card_orbit (a : α) [Finite (orbit G a)] : ∃ n : ℕ, Nat.card (orbit G a) = p ^ n := by let ϕ := orbitEquivQuotientStabilizer G a haveI := Finite.of_equiv (orbit G a) ϕ haveI := (stabilizer G a).finiteIndex_of_finite_quotient rw [Nat.card_congr ϕ] exact hG.index (stabilizer G a) variable (α) [Finite α] /-- If `G` is a `p`-group acting on a finite set `α`, then the number of fixed points of the action is congruent mod `p` to the cardinality of `α` -/ theorem card_modEq_card_fixedPoints : Nat.card α ≡ Nat.card (fixedPoints G α) [MOD p] := by have := Fintype.ofFinite α have := Fintype.ofFinite (fixedPoints G α) rw [Nat.card_eq_fintype_card, Nat.card_eq_fintype_card] classical calc card α = card (Σy : Quotient (orbitRel G α), { x // Quotient.mk'' x = y }) := card_congr (Equiv.sigmaFiberEquiv (@Quotient.mk'' _ (orbitRel G α))).symm _ = ∑ a : Quotient (orbitRel G α), card { x // Quotient.mk'' x = a } := card_sigma _ ≡ ∑ _a : fixedPoints G α, 1 [MOD p] := ?_ _ = _ := by simp rw [← ZMod.eq_iff_modEq_nat p, Nat.cast_sum, Nat.cast_sum] have key : ∀ x, card { y // (Quotient.mk'' y : Quotient (orbitRel G α)) = Quotient.mk'' x } = card (orbit G x) := fun x => by simp only [Quotient.eq'']; congr refine Eq.symm (Finset.sum_bij_ne_zero (fun a _ _ => Quotient.mk'' a.1) (fun _ _ _ => Finset.mem_univ _) (fun a₁ _ _ a₂ _ _ h => Subtype.eq (mem_fixedPoints'.mp a₂.2 a₁.1 (Quotient.exact' h))) (fun b => Quotient.inductionOn' b fun b _ hb => ?_) fun a ha _ => by rw [key, mem_fixedPoints_iff_card_orbit_eq_one.mp a.2]) obtain ⟨k, hk⟩ := hG.card_orbit b rw [Nat.card_eq_fintype_card] at hk have : k = 0 := by contrapose! hb simp [-Quotient.eq'', key, hk, hb] exact ⟨⟨b, mem_fixedPoints_iff_card_orbit_eq_one.2 <| by rw [hk, this, pow_zero]⟩, Finset.mem_univ _, ne_of_eq_of_ne Nat.cast_one one_ne_zero, rfl⟩ /-- If a p-group acts on `α` and the cardinality of `α` is not a multiple of `p` then the action has a fixed point. -/ theorem nonempty_fixed_point_of_prime_not_dvd_card (α) [MulAction G α] (hpα : ¬p ∣ Nat.card α) : (fixedPoints G α).Nonempty := have : Finite α := Nat.finite_of_card_ne_zero (fun h ↦ (h ▸ hpα) (dvd_zero p)) @Set.nonempty_of_nonempty_subtype _ _ (by rw [← Finite.card_pos_iff, pos_iff_ne_zero] contrapose! hpα rw [← Nat.modEq_zero_iff_dvd, ← hpα] exact hG.card_modEq_card_fixedPoints α) /-- If a p-group acts on `α` and the cardinality of `α` is a multiple of `p`, and the action has one fixed point, then it has another fixed point. -/ theorem exists_fixed_point_of_prime_dvd_card_of_fixed_point (hpα : p ∣ Nat.card α) {a : α} (ha : a ∈ fixedPoints G α) : ∃ b, b ∈ fixedPoints G α ∧ a ≠ b := by have hpf : p ∣ Nat.card (fixedPoints G α) := Nat.modEq_zero_iff_dvd.mp ((hG.card_modEq_card_fixedPoints α).symm.trans hpα.modEq_zero_nat) have hα : 1 < Nat.card (fixedPoints G α) := (Fact.out (p := p.Prime)).one_lt.trans_le (Nat.le_of_dvd (Finite.card_pos_iff.2 ⟨⟨a, ha⟩⟩) hpf) rw [Finite.one_lt_card_iff_nontrivial] at hα exact let ⟨⟨b, hb⟩, hba⟩ := exists_ne (⟨a, ha⟩ : fixedPoints G α) ⟨b, hb, fun hab => hba (by simp_rw [hab])⟩ theorem center_nontrivial [Nontrivial G] [Finite G] : Nontrivial (Subgroup.center G) := by classical have := (hG.of_equiv ConjAct.toConjAct).exists_fixed_point_of_prime_dvd_card_of_fixed_point G rw [ConjAct.fixedPoints_eq_center] at this have dvd : p ∣ Nat.card G := by obtain ⟨n, hn0, hn⟩ := hG.nontrivial_iff_card.mp inferInstance exact hn.symm ▸ dvd_pow_self _ (ne_of_gt hn0) obtain ⟨g, hg⟩ := this dvd (Subgroup.center G).one_mem exact ⟨⟨1, ⟨g, hg.1⟩, mt Subtype.ext_iff.mp hg.2⟩⟩ theorem bot_lt_center [Nontrivial G] [Finite G] : ⊥ < Subgroup.center G := by haveI := center_nontrivial hG classical exact bot_lt_iff_ne_bot.mpr ((Subgroup.center G).one_lt_card_iff_ne_bot.mp Finite.one_lt_card) end GIsPGroup theorem to_le {H K : Subgroup G} (hK : IsPGroup p K) (hHK : H ≤ K) : IsPGroup p H := hK.of_injective (Subgroup.inclusion hHK) fun a b h => Subtype.ext (by change ((Subgroup.inclusion hHK) a : G) = (Subgroup.inclusion hHK) b apply Subtype.ext_iff.mp h) theorem to_inf_left {H K : Subgroup G} (hH : IsPGroup p H) : IsPGroup p (H ⊓ K : Subgroup G) := hH.to_le inf_le_left theorem to_inf_right {H K : Subgroup G} (hK : IsPGroup p K) : IsPGroup p (H ⊓ K : Subgroup G) := hK.to_le inf_le_right theorem map {H : Subgroup G} (hH : IsPGroup p H) {K : Type*} [Group K] (ϕ : G →* K) : IsPGroup p (H.map ϕ) := by rw [← H.subtype_range, MonoidHom.map_range] exact hH.of_surjective (ϕ.restrict H).rangeRestrict (ϕ.restrict H).rangeRestrict_surjective theorem comap_of_ker_isPGroup {H : Subgroup G} (hH : IsPGroup p H) {K : Type*} [Group K] (ϕ : K →* G) (hϕ : IsPGroup p ϕ.ker) : IsPGroup p (H.comap ϕ) := by intro g obtain ⟨j, hj⟩ := hH ⟨ϕ g.1, g.2⟩ rw [Subtype.ext_iff, H.coe_pow, Subtype.coe_mk, ← ϕ.map_pow] at hj obtain ⟨k, hk⟩ := hϕ ⟨g.1 ^ p ^ j, hj⟩ rw [Subtype.ext_iff, ϕ.ker.coe_pow, Subtype.coe_mk, ← pow_mul, ← pow_add] at hk exact ⟨j + k, by rwa [Subtype.ext_iff, (H.comap ϕ).coe_pow]⟩ theorem ker_isPGroup_of_injective {K : Type*} [Group K] {ϕ : K →* G} (hϕ : Function.Injective ϕ) : IsPGroup p ϕ.ker := (congr_arg (fun Q : Subgroup K => IsPGroup p Q) (ϕ.ker_eq_bot_iff.mpr hϕ)).mpr IsPGroup.of_bot theorem comap_of_injective {H : Subgroup G} (hH : IsPGroup p H) {K : Type*} [Group K] (ϕ : K →* G) (hϕ : Function.Injective ϕ) : IsPGroup p (H.comap ϕ) := hH.comap_of_ker_isPGroup ϕ (ker_isPGroup_of_injective hϕ) theorem comap_subtype {H : Subgroup G} (hH : IsPGroup p H) {K : Subgroup G} : IsPGroup p (H.comap K.subtype) := hH.comap_of_injective K.subtype Subtype.coe_injective theorem to_sup_of_normal_right {H K : Subgroup G} (hH : IsPGroup p H) (hK : IsPGroup p K) [K.Normal] : IsPGroup p (H ⊔ K : Subgroup G) := by rw [← QuotientGroup.ker_mk' K, ← Subgroup.comap_map_eq] apply (hH.map (QuotientGroup.mk' K)).comap_of_ker_isPGroup rwa [QuotientGroup.ker_mk'] theorem to_sup_of_normal_left {H K : Subgroup G} (hH : IsPGroup p H) (hK : IsPGroup p K) [H.Normal] : IsPGroup p (H ⊔ K : Subgroup G) := sup_comm H K ▸ to_sup_of_normal_right hK hH theorem to_sup_of_normal_right' {H K : Subgroup G} (hH : IsPGroup p H) (hK : IsPGroup p K) (hHK : H ≤ K.normalizer) : IsPGroup p (H ⊔ K : Subgroup G) := let hHK' := to_sup_of_normal_right (hH.of_equiv (Subgroup.subgroupOfEquivOfLe hHK).symm) (hK.of_equiv (Subgroup.subgroupOfEquivOfLe Subgroup.le_normalizer).symm) ((congr_arg (fun H : Subgroup K.normalizer => IsPGroup p H) (Subgroup.sup_subgroupOf_eq hHK Subgroup.le_normalizer)).mp hHK').of_equiv (Subgroup.subgroupOfEquivOfLe (sup_le hHK Subgroup.le_normalizer)) theorem to_sup_of_normal_left' {H K : Subgroup G} (hH : IsPGroup p H) (hK : IsPGroup p K) (hHK : K ≤ H.normalizer) : IsPGroup p (H ⊔ K : Subgroup G) := sup_comm H K ▸ to_sup_of_normal_right' hK hH hHK /-- finite p-groups with different p have coprime orders -/ theorem coprime_card_of_ne {G₂ : Type*} [Group G₂] (p₁ p₂ : ℕ) [hp₁ : Fact p₁.Prime] [hp₂ : Fact p₂.Prime] (hne : p₁ ≠ p₂) (H₁ : Subgroup G) (H₂ : Subgroup G₂) [Finite H₁] [Finite H₂] (hH₁ : IsPGroup p₁ H₁) (hH₂ : IsPGroup p₂ H₂) : Nat.Coprime (Nat.card H₁) (Nat.card H₂) := by obtain ⟨n₁, heq₁⟩ := iff_card.mp hH₁; rw [heq₁]; clear heq₁ obtain ⟨n₂, heq₂⟩ := iff_card.mp hH₂; rw [heq₂]; clear heq₂ exact Nat.coprime_pow_primes _ _ hp₁.elim hp₂.elim hne /-- p-groups with different p are disjoint -/ theorem disjoint_of_ne (p₁ p₂ : ℕ) [hp₁ : Fact p₁.Prime] [hp₂ : Fact p₂.Prime] (hne : p₁ ≠ p₂) (H₁ H₂ : Subgroup G) (hH₁ : IsPGroup p₁ H₁) (hH₂ : IsPGroup p₂ H₂) : Disjoint H₁ H₂ := by rw [Subgroup.disjoint_def] intro x hx₁ hx₂ obtain ⟨n₁, hn₁⟩ := iff_orderOf.mp hH₁ ⟨x, hx₁⟩ obtain ⟨n₂, hn₂⟩ := iff_orderOf.mp hH₂ ⟨x, hx₂⟩ rw [Subgroup.orderOf_mk] at hn₁ hn₂ have : p₁ ^ n₁ = p₂ ^ n₂ := by rw [← hn₁, ← hn₂] rcases n₁.eq_zero_or_pos with (rfl | hn₁) · simpa using hn₁ · exact absurd (eq_of_prime_pow_eq hp₁.out.prime hp₂.out.prime hn₁ this) hne section P2comm variable [Fact p.Prime] {n : ℕ} open Subgroup /-- The cardinality of the `center` of a `p`-group is `p ^ k` where `k` is positive. -/ theorem card_center_eq_prime_pow (hGpn : Nat.card G = p ^ n) (hn : 0 < n) : ∃ k > 0, Nat.card (center G) = p ^ k := by have : Finite G := Nat.finite_of_card_ne_zero (hGpn ▸ pow_ne_zero n (NeZero.ne p)) have hcG := to_subgroup (of_card hGpn) (center G) rcases iff_card.1 hcG with _ haveI : Nontrivial G := (nontrivial_iff_card <| of_card hGpn).2 ⟨n, hn, hGpn⟩ exact (nontrivial_iff_card hcG).mp (center_nontrivial (of_card hGpn)) /-- The quotient by the center of a group of cardinality `p ^ 2` is cyclic. -/ theorem cyclic_center_quotient_of_card_eq_prime_sq (hG : Nat.card G = p ^ 2) : IsCyclic (G ⧸ center G) := by apply isCyclic_of_card_dvd_prime (p := p) rw [← mul_dvd_mul_iff_left (NeZero.ne p), ← sq, ← hG, ← (center G).card_mul_index] apply mul_dvd_mul_right rcases card_center_eq_prime_pow hG zero_lt_two with ⟨k, hk0, hk⟩ rw [hk] exact dvd_pow_self p hk0.ne' /-- A group of order `p ^ 2` is commutative. See also `IsPGroup.commutative_of_card_eq_prime_sq` for just the proof that `∀ a b, a * b = b * a` -/ def commGroupOfCardEqPrimeSq (hG : Nat.card G = p ^ 2) : CommGroup G := @commGroupOfCycleCenterQuotient _ _ _ _ (cyclic_center_quotient_of_card_eq_prime_sq hG) _ (QuotientGroup.ker_mk' (center G)).le /-- A group of order `p ^ 2` is commutative. See also `IsPGroup.commGroupOfCardEqPrimeSq` for the `CommGroup` instance. -/ theorem commutative_of_card_eq_prime_sq (hG : Nat.card G = p ^ 2) : ∀ a b : G, a * b = b * a := (commGroupOfCardEqPrimeSq hG).mul_comm end P2comm end IsPGroup
GroupTheory\PresentedGroup.lean
/- Copyright (c) 2019 Michael Howes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Howes, Newell Jensen -/ import Mathlib.GroupTheory.FreeGroup.Basic import Mathlib.GroupTheory.QuotientGroup /-! # Defining a group given by generators and relations Given a subset `rels` of relations of the free group on a type `α`, this file constructs the group given by generators `x : α` and relations `r ∈ rels`. ## Main definitions * `PresentedGroup rels`: the quotient group of the free group on a type `α` by a subset `rels` of relations of the free group on `α`. * `of`: The canonical map from `α` to a presented group with generators `α`. * `toGroup f`: the canonical group homomorphism `PresentedGroup rels → G`, given a function `f : α → G` from a type `α` to a group `G` which satisfies the relations `rels`. ## Tags generators, relations, group presentations -/ variable {α : Type*} /-- Given a set of relations, `rels`, over a type `α`, `PresentedGroup` constructs the group with generators `x : α` and relations `rels` as a quotient of `FreeGroup α`. -/ def PresentedGroup (rels : Set (FreeGroup α)) := FreeGroup α ⧸ Subgroup.normalClosure rels namespace PresentedGroup instance (rels : Set (FreeGroup α)) : Group (PresentedGroup rels) := QuotientGroup.Quotient.group _ /-- `of` is the canonical map from `α` to a presented group with generators `x : α`. The term `x` is mapped to the equivalence class of the image of `x` in `FreeGroup α`. -/ def of {rels : Set (FreeGroup α)} (x : α) : PresentedGroup rels := QuotientGroup.mk (FreeGroup.of x) /-- The generators of a presented group generate the presented group. That is, the subgroup closure of the set of generators equals `⊤`. -/ @[simp] theorem closure_range_of (rels : Set (FreeGroup α)) : Subgroup.closure (Set.range (PresentedGroup.of : α → PresentedGroup rels)) = ⊤ := by have : (PresentedGroup.of : α → PresentedGroup rels) = QuotientGroup.mk' _ ∘ FreeGroup.of := rfl rw [this, Set.range_comp, ← MonoidHom.map_closure (QuotientGroup.mk' _), FreeGroup.closure_range_of, ← MonoidHom.range_eq_map] exact MonoidHom.range_top_of_surjective _ (QuotientGroup.mk'_surjective _) section ToGroup /- Presented groups satisfy a universal property. If `G` is a group and `f : α → G` is a map such that the images of `f` satisfy all the given relations, then `f` extends uniquely to a group homomorphism from `PresentedGroup rels` to `G`. -/ variable {G : Type*} [Group G] {f : α → G} {rels : Set (FreeGroup α)} local notation "F" => FreeGroup.lift f theorem closure_rels_subset_ker (h : ∀ r ∈ rels, FreeGroup.lift f r = 1) : Subgroup.normalClosure rels ≤ MonoidHom.ker F := Subgroup.normalClosure_le_normal fun x w ↦ (MonoidHom.mem_ker _).2 (h x w) theorem to_group_eq_one_of_mem_closure (h : ∀ r ∈ rels, FreeGroup.lift f r = 1) : ∀ x ∈ Subgroup.normalClosure rels, F x = 1 := fun _ w ↦ (MonoidHom.mem_ker _).1 <| closure_rels_subset_ker h w /-- The extension of a map `f : α → G` that satisfies the given relations to a group homomorphism from `PresentedGroup rels → G`. -/ def toGroup (h : ∀ r ∈ rels, FreeGroup.lift f r = 1) : PresentedGroup rels →* G := QuotientGroup.lift (Subgroup.normalClosure rels) F (to_group_eq_one_of_mem_closure h) @[simp] theorem toGroup.of (h : ∀ r ∈ rels, FreeGroup.lift f r = 1) {x : α} : toGroup h (of x) = f x := FreeGroup.lift.of theorem toGroup.unique (h : ∀ r ∈ rels, FreeGroup.lift f r = 1) (g : PresentedGroup rels →* G) (hg : ∀ x : α, g (PresentedGroup.of x) = f x) : ∀ {x}, g x = toGroup h x := by intro x refine QuotientGroup.induction_on x ?_ exact fun _ ↦ FreeGroup.lift.unique (g.comp (QuotientGroup.mk' _)) hg @[ext] theorem ext {φ ψ : PresentedGroup rels →* G} (hx : ∀ (x : α), φ (.of x) = ψ (.of x)) : φ = ψ := by unfold PresentedGroup ext apply hx variable {β : Type*} /-- Presented groups of isomorphic types are isomorphic. -/ def equivPresentedGroup (rels : Set (FreeGroup α)) (e : α ≃ β) : PresentedGroup rels ≃* PresentedGroup (FreeGroup.freeGroupCongr e '' rels) := QuotientGroup.congr (Subgroup.normalClosure rels) (Subgroup.normalClosure ((FreeGroup.freeGroupCongr e) '' rels)) (FreeGroup.freeGroupCongr e) (Subgroup.map_normalClosure rels (FreeGroup.freeGroupCongr e).toMonoidHom (FreeGroup.freeGroupCongr e).surjective) theorem equivPresentedGroup_apply_of (x : α) (rels : Set (FreeGroup α)) (e : α ≃ β) : equivPresentedGroup rels e (PresentedGroup.of x) = PresentedGroup.of (rels := FreeGroup.freeGroupCongr e '' rels) (e x) := rfl theorem equivPresentedGroup_symm_apply_of (x : β) (rels : Set (FreeGroup α)) (e : α ≃ β) : (equivPresentedGroup rels e).symm (PresentedGroup.of x) = PresentedGroup.of (rels := rels) (e.symm x) := rfl end ToGroup instance (rels : Set (FreeGroup α)) : Inhabited (PresentedGroup rels) := ⟨1⟩ end PresentedGroup
GroupTheory\PushoutI.lean
/- Copyright (c) 2023 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.GroupTheory.CoprodI import Mathlib.GroupTheory.Coprod.Basic import Mathlib.GroupTheory.Complement /-! ## Pushouts of Monoids and Groups This file defines wide pushouts of monoids and groups and proves some properties of the amalgamated product of groups (i.e. the special case where all the maps in the diagram are injective). ## Main definitions - `Monoid.PushoutI`: the pushout of a diagram of monoids indexed by a type `ι` - `Monoid.PushoutI.base`: the map from the amalgamating monoid to the pushout - `Monoid.PushoutI.of`: the map from each Monoid in the family to the pushout - `Monoid.PushoutI.lift`: the universal property used to define homomorphisms out of the pushout. - `Monoid.PushoutI.NormalWord`: a normal form for words in the pushout - `Monoid.PushoutI.of_injective`: if all the maps in the diagram are injective in a pushout of groups then so is `of` - `Monoid.PushoutI.Reduced.eq_empty_of_mem_range`: For any word `w` in the coproduct, if `w` is reduced (i.e none its letters are in the image of the base monoid), and nonempty, then `w` itself is not in the image of the base monoid. ## References * The normal form theorem follows these [notes](https://webspace.maths.qmul.ac.uk/i.m.chiswell/ggt/lecture_notes/lecture2.pdf) from Queen Mary University ## Tags amalgamated product, pushout, group -/ namespace Monoid open CoprodI Subgroup Coprod Function List variable {ι : Type*} {G : ι → Type*} {H : Type*} {K : Type*} [Monoid K] /-- The relation we quotient by to form the pushout -/ def PushoutI.con [∀ i, Monoid (G i)] [Monoid H] (φ : ∀ i, H →* G i) : Con (Coprod (CoprodI G) H) := conGen (fun x y : Coprod (CoprodI G) H => ∃ i x', x = inl (of (φ i x')) ∧ y = inr x') /-- The indexed pushout of monoids, which is the pushout in the category of monoids, or the category of groups. -/ def PushoutI [∀ i, Monoid (G i)] [Monoid H] (φ : ∀ i, H →* G i) : Type _ := (PushoutI.con φ).Quotient namespace PushoutI section Monoid variable [∀ i, Monoid (G i)] [Monoid H] {φ : ∀ i, H →* G i} protected instance mul : Mul (PushoutI φ) := by delta PushoutI; infer_instance protected instance one : One (PushoutI φ) := by delta PushoutI; infer_instance instance monoid : Monoid (PushoutI φ) := { Con.monoid _ with toMul := PushoutI.mul toOne := PushoutI.one } /-- The map from each indexing group into the pushout -/ def of (i : ι) : G i →* PushoutI φ := (Con.mk' _).comp <| inl.comp CoprodI.of variable (φ) in /-- The map from the base monoid into the pushout -/ def base : H →* PushoutI φ := (Con.mk' _).comp inr theorem of_comp_eq_base (i : ι) : (of i).comp (φ i) = (base φ) := by ext x apply (Con.eq _).2 refine ConGen.Rel.of _ _ ?_ simp only [MonoidHom.comp_apply, Set.mem_iUnion, Set.mem_range] exact ⟨_, _, rfl, rfl⟩ variable (φ) in theorem of_apply_eq_base (i : ι) (x : H) : of i (φ i x) = base φ x := by rw [← MonoidHom.comp_apply, of_comp_eq_base] /-- Define a homomorphism out of the pushout of monoids be defining it on each object in the diagram -/ def lift (f : ∀ i, G i →* K) (k : H →* K) (hf : ∀ i, (f i).comp (φ i) = k) : PushoutI φ →* K := Con.lift _ (Coprod.lift (CoprodI.lift f) k) <| by apply Con.conGen_le fun x y => ?_ rintro ⟨i, x', rfl, rfl⟩ simp only [DFunLike.ext_iff, MonoidHom.coe_comp, comp_apply] at hf simp [hf] @[simp] theorem lift_of (f : ∀ i, G i →* K) (k : H →* K) (hf : ∀ i, (f i).comp (φ i) = k) {i : ι} (g : G i) : (lift f k hf) (of i g : PushoutI φ) = f i g := by delta PushoutI lift of simp only [MonoidHom.coe_comp, Con.coe_mk', comp_apply, Con.lift_coe, lift_apply_inl, CoprodI.lift_of] @[simp] theorem lift_base (f : ∀ i, G i →* K) (k : H →* K) (hf : ∀ i, (f i).comp (φ i) = k) (g : H) : (lift f k hf) (base φ g : PushoutI φ) = k g := by delta PushoutI lift base simp only [MonoidHom.coe_comp, Con.coe_mk', comp_apply, Con.lift_coe, lift_apply_inr] -- `ext` attribute should be lower priority then `hom_ext_nonempty` @[ext 1199] theorem hom_ext {f g : PushoutI φ →* K} (h : ∀ i, f.comp (of i : G i →* _) = g.comp (of i : G i →* _)) (hbase : f.comp (base φ) = g.comp (base φ)) : f = g := (MonoidHom.cancel_right Con.mk'_surjective).mp <| Coprod.hom_ext (CoprodI.ext_hom _ _ h) hbase @[ext high] theorem hom_ext_nonempty [hn : Nonempty ι] {f g : PushoutI φ →* K} (h : ∀ i, f.comp (of i : G i →* _) = g.comp (of i : G i →* _)) : f = g := hom_ext h <| by cases hn with | intro i => ext rw [← of_comp_eq_base i, ← MonoidHom.comp_assoc, h, MonoidHom.comp_assoc] /-- The equivalence that is part of the universal property of the pushout. A hom out of the pushout is just a morphism out of all groups in the pushout that satisfies a commutativity condition. -/ @[simps] def homEquiv : (PushoutI φ →* K) ≃ { f : (Π i, G i →* K) × (H →* K) // ∀ i, (f.1 i).comp (φ i) = f.2 } := { toFun := fun f => ⟨(fun i => f.comp (of i), f.comp (base φ)), fun i => by rw [MonoidHom.comp_assoc, of_comp_eq_base]⟩ invFun := fun f => lift f.1.1 f.1.2 f.2, left_inv := fun _ => hom_ext (by simp [DFunLike.ext_iff]) (by simp [DFunLike.ext_iff]) right_inv := fun ⟨⟨_, _⟩, _⟩ => by simp [DFunLike.ext_iff, Function.funext_iff] } /-- The map from the coproduct into the pushout -/ def ofCoprodI : CoprodI G →* PushoutI φ := CoprodI.lift of @[simp] theorem ofCoprodI_of (i : ι) (g : G i) : (ofCoprodI (CoprodI.of g) : PushoutI φ) = of i g := by simp [ofCoprodI] theorem induction_on {motive : PushoutI φ → Prop} (x : PushoutI φ) (of : ∀ (i : ι) (g : G i), motive (of i g)) (base : ∀ h, motive (base φ h)) (mul : ∀ x y, motive x → motive y → motive (x * y)) : motive x := by delta PushoutI PushoutI.of PushoutI.base at * induction x using Con.induction_on with | H x => induction x using Coprod.induction_on with | inl g => induction g using CoprodI.induction_on with | h_of i g => exact of i g | h_mul x y ihx ihy => rw [map_mul] exact mul _ _ ihx ihy | h_one => simpa using base 1 | inr h => exact base h | mul x y ihx ihy => exact mul _ _ ihx ihy end Monoid variable [∀ i, Group (G i)] [Group H] {φ : ∀ i, H →* G i} instance : Group (PushoutI φ) := { Con.group (PushoutI.con φ) with toMonoid := PushoutI.monoid } namespace NormalWord /- In this section we show that there is a normal form for words in the amalgamated product. To have a normal form, we need to pick canonical choice of element of each right coset of the base group. The choice of element in the base group itself is `1`. Given a choice of element of each right coset, given by the type `Transversal φ` we can find a normal form. The normal form for an element is an element of the base group, multiplied by a word in the coproduct, where each letter in the word is the canonical choice of element of its coset. We then show that all groups in the diagram act faithfully on the normal form. This implies that the maps into the coproduct are injective. We demonstrate the action is faithful using the equivalence `equivPair`. We show that `G i` acts faithfully on `Pair d i` and that `Pair d i` is isomorphic to `NormalWord d`. Here, `d` is a `Transversal`. A `Pair d i` is a word in the coproduct, `Coprod G`, the `tail`, and an element of the group `G i`, the `head`. The first letter of the `tail` must not be an element of `G i`. Note that the `head` may be `1` Every letter in the `tail` must be in the transversal given by `d`. We then show that the equivalence between `NormalWord` and `PushoutI`, between the set of normal words and the elements of the amalgamated product. The key to this is the theorem `prod_smul_empty`, which says that going from `NormalWord` to `PushoutI` and back is the identity. This is proven by induction on the word using `consRecOn`. -/ variable (φ) /-- The data we need to pick a normal form for words in the pushout. We need to pick a canonical element of each coset. We also need all the maps in the diagram to be injective -/ structure Transversal : Type _ where /-- All maps in the diagram are injective -/ injective : ∀ i, Injective (φ i) /-- The underlying set, containing exactly one element of each coset of the base group -/ set : ∀ i, Set (G i) /-- The chosen element of the base group itself is the identity -/ one_mem : ∀ i, 1 ∈ set i /-- We have exactly one element of each coset of the base group -/ compl : ∀ i, IsComplement (φ i).range (set i) theorem transversal_nonempty (hφ : ∀ i, Injective (φ i)) : Nonempty (Transversal φ) := by choose t ht using fun i => (φ i).range.exists_right_transversal 1 apply Nonempty.intro exact { injective := hφ set := t one_mem := fun i => (ht i).2 compl := fun i => (ht i).1 } variable {φ} /-- The normal form for words in the pushout. Every element of the pushout is the product of an element of the base group and a word made up of letters each of which is in the transversal. -/ structure _root_.Monoid.PushoutI.NormalWord (d : Transversal φ) extends CoprodI.Word G where /-- Every `NormalWord` is the product of an element of the base group and a word made up of letters each of which is in the transversal. `head` is that element of the base group. -/ head : H /-- All letter in the word are in the transversal. -/ normalized : ∀ i g, ⟨i, g⟩ ∈ toList → g ∈ d.set i /-- A `Pair d i` is a word in the coproduct, `Coprod G`, the `tail`, and an element of the group `G i`, the `head`. The first letter of the `tail` must not be an element of `G i`. Note that the `head` may be `1` Every letter in the `tail` must be in the transversal given by `d`. Similar to `Monoid.CoprodI.Pair` except every letter must be in the transversal (not including the head letter). -/ structure Pair (d : Transversal φ) (i : ι) extends CoprodI.Word.Pair G i where /-- All letters in the word are in the transversal. -/ normalized : ∀ i g, ⟨i, g⟩ ∈ tail.toList → g ∈ d.set i variable {d : Transversal φ} /-- The empty normalized word, representing the identity element of the group. -/ @[simps!] def empty : NormalWord d := ⟨CoprodI.Word.empty, 1, fun i g => by simp [CoprodI.Word.empty]⟩ instance : Inhabited (NormalWord d) := ⟨NormalWord.empty⟩ instance (i : ι) : Inhabited (Pair d i) := ⟨{ (empty : NormalWord d) with head := 1, fstIdx_ne := fun h => by cases h }⟩ @[ext] theorem ext {w₁ w₂ : NormalWord d} (hhead : w₁.head = w₂.head) (hlist : w₁.toList = w₂.toList) : w₁ = w₂ := by rcases w₁ with ⟨⟨_, _, _⟩, _, _⟩ rcases w₂ with ⟨⟨_, _, _⟩, _, _⟩ simp_all open Subgroup.IsComplement instance baseAction : MulAction H (NormalWord d) := { smul := fun h w => { w with head := h * w.head }, one_smul := by simp [instHSMul] mul_smul := by simp [instHSMul, mul_assoc] } theorem base_smul_def' (h : H) (w : NormalWord d) : h • w = { w with head := h * w.head } := rfl /-- Take the product of a normal word as an element of the `PushoutI`. We show that this is bijective, in `NormalWord.equiv`. -/ def prod (w : NormalWord d) : PushoutI φ := base φ w.head * ofCoprodI (w.toWord).prod @[simp] theorem prod_base_smul (h : H) (w : NormalWord d) : (h • w).prod = base φ h * w.prod := by simp only [base_smul_def', prod, map_mul, mul_assoc] @[simp] theorem prod_empty : (empty : NormalWord d).prod = 1 := by simp [prod, empty] /-- A constructor that multiplies a `NormalWord` by an element, with condition to make sure the underlying list does get longer. -/ @[simps!] noncomputable def cons {i} (g : G i) (w : NormalWord d) (hmw : w.fstIdx ≠ some i) (hgr : g ∉ (φ i).range) : NormalWord d := letI n := (d.compl i).equiv (g * (φ i w.head)) letI w' := Word.cons (n.2 : G i) w.toWord hmw (mt (coe_equiv_snd_eq_one_iff_mem _ (d.one_mem _)).1 (mt (mul_mem_cancel_right (by simp)).1 hgr)) { toWord := w' head := (MonoidHom.ofInjective (d.injective i)).symm n.1 normalized := fun i g hg => by simp only [w', Word.cons, mem_cons, Sigma.mk.inj_iff] at hg rcases hg with ⟨rfl, hg | hg⟩ · simp · exact w.normalized _ _ (by assumption) } @[simp] theorem prod_cons {i} (g : G i) (w : NormalWord d) (hmw : w.fstIdx ≠ some i) (hgr : g ∉ (φ i).range) : (cons g w hmw hgr).prod = of i g * w.prod := by simp only [prod, cons, Word.prod, List.map, ← of_apply_eq_base φ i, equiv_fst_eq_mul_inv, mul_assoc, MonoidHom.apply_ofInjective_symm, List.prod_cons, map_mul, map_inv, ofCoprodI_of, inv_mul_cancel_left] variable [DecidableEq ι] [∀ i, DecidableEq (G i)] /-- Given a word in `CoprodI`, if every letter is in the transversal and when we multiply by an element of the base group it still has this property, then the element of the base group we multiplied by was one. -/ theorem eq_one_of_smul_normalized (w : CoprodI.Word G) {i : ι} (h : H) (hw : ∀ i g, ⟨i, g⟩ ∈ w.toList → g ∈ d.set i) (hφw : ∀ j g, ⟨j, g⟩ ∈ (CoprodI.of (φ i h) • w).toList → g ∈ d.set j) : h = 1 := by simp only [← (d.compl _).equiv_snd_eq_self_iff_mem (one_mem _)] at hw hφw have hhead : ((d.compl i).equiv (Word.equivPair i w).head).2 = (Word.equivPair i w).head := by rw [Word.equivPair_head] split_ifs with h · rcases h with ⟨_, rfl⟩ exact hw _ _ (List.head_mem _) · rw [equiv_one (d.compl i) (one_mem _) (d.one_mem _)] by_contra hh1 have := hφw i (φ i h * (Word.equivPair i w).head) ?_ · apply hh1 rw [equiv_mul_left_of_mem (d.compl i) ⟨_, rfl⟩, hhead] at this simpa [((injective_iff_map_eq_one' _).1 (d.injective i))] using this · simp only [Word.mem_smul_iff, not_true, false_and, ne_eq, Option.mem_def, mul_right_inj, exists_eq_right', mul_right_eq_self, exists_prop, true_and, false_or] constructor · intro h apply_fun (d.compl i).equiv at h simp only [Prod.ext_iff, equiv_one (d.compl i) (one_mem _) (d.one_mem _), equiv_mul_left_of_mem (d.compl i) ⟨_, rfl⟩ , hhead, Subtype.ext_iff, Prod.ext_iff, Subgroup.coe_mul] at h rcases h with ⟨h₁, h₂⟩ rw [h₂, equiv_one (d.compl i) (one_mem _) (d.one_mem _), mul_one, ((injective_iff_map_eq_one' _).1 (d.injective i))] at h₁ contradiction · rw [Word.equivPair_head] dsimp split_ifs with hep · rcases hep with ⟨hnil, rfl⟩ rw [head?_eq_head hnil] simp_all · push_neg at hep by_cases hw : w.toList = [] · simp [hw, Word.fstIdx] · simp [head?_eq_head hw, Word.fstIdx, hep hw] theorem ext_smul {w₁ w₂ : NormalWord d} (i : ι) (h : CoprodI.of (φ i w₁.head) • w₁.toWord = CoprodI.of (φ i w₂.head) • w₂.toWord) : w₁ = w₂ := by rcases w₁ with ⟨w₁, h₁, hw₁⟩ rcases w₂ with ⟨w₂, h₂, hw₂⟩ dsimp at * rw [smul_eq_iff_eq_inv_smul, ← mul_smul] at h subst h simp only [← map_inv, ← map_mul] at hw₁ have : h₁⁻¹ * h₂ = 1 := eq_one_of_smul_normalized w₂ (h₁⁻¹ * h₂) hw₂ hw₁ rw [inv_mul_eq_one] at this; subst this simp /-- Given a pair `(head, tail)`, we can form a word by prepending `head` to `tail`, but putting head into normal form first, by making sure it is expressed as an element of the base group multiplied by an element of the transversal. -/ noncomputable def rcons (i : ι) (p : Pair d i) : NormalWord d := letI n := (d.compl i).equiv p.head let w := (Word.equivPair i).symm { p.toPair with head := n.2 } { toWord := w head := (MonoidHom.ofInjective (d.injective i)).symm n.1 normalized := fun i g hg => by dsimp [w] at hg rw [Word.equivPair_symm, Word.mem_rcons_iff] at hg rcases hg with hg | ⟨_, rfl, rfl⟩ · exact p.normalized _ _ hg · simp } theorem rcons_injective {i : ι} : Function.Injective (rcons (d := d) i) := by rintro ⟨⟨head₁, tail₁⟩, _⟩ ⟨⟨head₂, tail₂⟩, _⟩ simp only [rcons, NormalWord.mk.injEq, EmbeddingLike.apply_eq_iff_eq, Word.Pair.mk.injEq, Pair.mk.injEq, and_imp] intro h₁ h₂ h₃ subst h₂ rw [← equiv_fst_mul_equiv_snd (d.compl i) head₁, ← equiv_fst_mul_equiv_snd (d.compl i) head₂, h₁, h₃] simp /-- The equivalence between `NormalWord`s and pairs. We can turn a `NormalWord` into a pair by taking the head of the `List` if it is in `G i` and multiplying it by the element of the base group. -/ noncomputable def equivPair (i) : NormalWord d ≃ Pair d i := letI toFun : NormalWord d → Pair d i := fun w => letI p := Word.equivPair i (CoprodI.of (φ i w.head) • w.toWord) { toPair := p normalized := fun j g hg => by dsimp only [p] at hg rw [Word.of_smul_def, ← Word.equivPair_symm, Equiv.apply_symm_apply] at hg dsimp at hg exact w.normalized _ _ (Word.mem_of_mem_equivPair_tail _ hg) } haveI leftInv : Function.LeftInverse (rcons i) toFun := fun w => ext_smul i <| by simp only [rcons, Word.equivPair_symm, Word.equivPair_smul_same, Word.equivPair_tail_eq_inv_smul, Word.rcons_eq_smul, MonoidHom.apply_ofInjective_symm, equiv_fst_eq_mul_inv, mul_assoc, map_mul, map_inv, mul_smul, inv_smul_smul, smul_inv_smul] { toFun := toFun invFun := rcons i left_inv := leftInv right_inv := fun _ => rcons_injective (leftInv _) } noncomputable instance summandAction (i : ι) : MulAction (G i) (NormalWord d) := { smul := fun g w => (equivPair i).symm { equivPair i w with head := g * (equivPair i w).head } one_smul := fun _ => by dsimp [instHSMul] rw [one_mul] exact (equivPair i).symm_apply_apply _ mul_smul := fun _ _ _ => by dsimp [instHSMul] simp [mul_assoc, Equiv.apply_symm_apply, Function.End.mul_def] } theorem summand_smul_def' {i : ι} (g : G i) (w : NormalWord d) : g • w = (equivPair i).symm { equivPair i w with head := g * (equivPair i w).head } := rfl noncomputable instance mulAction : MulAction (PushoutI φ) (NormalWord d) := MulAction.ofEndHom <| lift (fun i => MulAction.toEndHom) MulAction.toEndHom <| by intro i simp only [MulAction.toEndHom, DFunLike.ext_iff, MonoidHom.coe_comp, MonoidHom.coe_mk, OneHom.coe_mk, comp_apply] intro h funext w apply NormalWord.ext_smul i simp only [summand_smul_def', equivPair, rcons, Word.equivPair_symm, Equiv.coe_fn_mk, Equiv.coe_fn_symm_mk, Word.equivPair_smul_same, Word.equivPair_tail_eq_inv_smul, Word.rcons_eq_smul, equiv_fst_eq_mul_inv, map_mul, map_inv, mul_smul, inv_smul_smul, smul_inv_smul, base_smul_def', MonoidHom.apply_ofInjective_symm] theorem base_smul_def (h : H) (w : NormalWord d) : base φ h • w = { w with head := h * w.head } := by dsimp [NormalWord.mulAction, instHSMul, SMul.smul] rw [lift_base] rfl theorem summand_smul_def {i : ι} (g : G i) (w : NormalWord d) : of (φ := φ) i g • w = (equivPair i).symm { equivPair i w with head := g * (equivPair i w).head } := by dsimp [NormalWord.mulAction, instHSMul, SMul.smul] rw [lift_of] rfl theorem of_smul_eq_smul {i : ι} (g : G i) (w : NormalWord d) : of (φ := φ) i g • w = g • w := by rw [summand_smul_def, summand_smul_def'] theorem base_smul_eq_smul (h : H) (w : NormalWord d) : base φ h • w = h • w := by rw [base_smul_def, base_smul_def'] /-- Induction principle for `NormalWord`, that corresponds closely to inducting on the underlying list. -/ @[elab_as_elim] noncomputable def consRecOn {motive : NormalWord d → Sort _} (w : NormalWord d) (h_empty : motive empty) (h_cons : ∀ (i : ι) (g : G i) (w : NormalWord d) (hmw : w.fstIdx ≠ some i) (_hgn : g ∈ d.set i) (hgr : g ∉ (φ i).range) (_hw1 : w.head = 1), motive w → motive (cons g w hmw hgr)) (h_base : ∀ (h : H) (w : NormalWord d), w.head = 1 → motive w → motive (base φ h • w)) : motive w := by rcases w with ⟨w, head, h3⟩ convert h_base head ⟨w, 1, h3⟩ rfl ?_ · simp [base_smul_def] · induction w using Word.consRecOn with | h_empty => exact h_empty | h_cons i g w h1 hg1 ih => convert h_cons i g ⟨w, 1, fun _ _ h => h3 _ _ (List.mem_cons_of_mem _ h)⟩ h1 (h3 _ _ (List.mem_cons_self _ _)) ?_ rfl (ih ?_) · ext simp only [Word.cons, Option.mem_def, cons, map_one, mul_one, (equiv_snd_eq_self_iff_mem (d.compl i) (one_mem _)).2 (h3 _ _ (List.mem_cons_self _ _))] · apply d.injective i simp only [cons, equiv_fst_eq_mul_inv, MonoidHom.apply_ofInjective_symm, map_one, mul_one, mul_right_inv, (equiv_snd_eq_self_iff_mem (d.compl i) (one_mem _)).2 (h3 _ _ (List.mem_cons_self _ _))] · rwa [← SetLike.mem_coe, ← coe_equiv_snd_eq_one_iff_mem (d.compl i) (d.one_mem _), (equiv_snd_eq_self_iff_mem (d.compl i) (one_mem _)).2 (h3 _ _ (List.mem_cons_self _ _))] theorem cons_eq_smul {i : ι} (g : G i) (w : NormalWord d) (hmw : w.fstIdx ≠ some i) (hgr : g ∉ (φ i).range) : cons g w hmw hgr = of (φ := φ) i g • w := by apply ext_smul i simp only [cons, ne_eq, Word.cons_eq_smul, MonoidHom.apply_ofInjective_symm, equiv_fst_eq_mul_inv, mul_assoc, map_mul, map_inv, mul_smul, inv_smul_smul, summand_smul_def, equivPair, rcons, Word.equivPair_symm, Word.rcons_eq_smul, Equiv.coe_fn_mk, Word.equivPair_tail_eq_inv_smul, Equiv.coe_fn_symm_mk, smul_inv_smul] @[simp] theorem prod_summand_smul {i : ι} (g : G i) (w : NormalWord d) : (g • w).prod = of i g * w.prod := by simp only [prod, summand_smul_def', equivPair, rcons, Word.equivPair_symm, Equiv.coe_fn_mk, Equiv.coe_fn_symm_mk, Word.equivPair_smul_same, Word.equivPair_tail_eq_inv_smul, Word.rcons_eq_smul, ← of_apply_eq_base φ i, MonoidHom.apply_ofInjective_symm, equiv_fst_eq_mul_inv, mul_assoc, map_mul, map_inv, Word.prod_smul, ofCoprodI_of, inv_mul_cancel_left, mul_inv_cancel_left] @[simp] theorem prod_smul (g : PushoutI φ) (w : NormalWord d) : (g • w).prod = g * w.prod := by induction g using PushoutI.induction_on generalizing w with | of i g => rw [of_smul_eq_smul, prod_summand_smul] | base h => rw [base_smul_eq_smul, prod_base_smul] | mul x y ihx ihy => rw [mul_smul, ihx, ihy, mul_assoc] theorem prod_smul_empty (w : NormalWord d) : w.prod • empty = w := by induction w using consRecOn with | h_empty => simp | h_cons i g w _ _ _ _ ih => rw [prod_cons, mul_smul, ih, cons_eq_smul] | h_base h w _ ih => rw [prod_smul, mul_smul, ih] /-- The equivalence between normal forms and elements of the pushout -/ noncomputable def equiv : PushoutI φ ≃ NormalWord d := { toFun := fun g => g • .empty invFun := fun w => w.prod left_inv := fun g => by simp only [prod_smul, prod_empty, mul_one] right_inv := fun w => prod_smul_empty w } theorem prod_injective : Function.Injective (prod : NormalWord d → PushoutI φ) := by letI := Classical.decEq ι letI := fun i => Classical.decEq (G i) classical exact equiv.symm.injective instance : FaithfulSMul (PushoutI φ) (NormalWord d) := ⟨fun h => by simpa using congr_arg prod (h empty)⟩ instance (i : ι) : FaithfulSMul (G i) (NormalWord d) := ⟨by simp [summand_smul_def']⟩ instance : FaithfulSMul H (NormalWord d) := ⟨by simp [base_smul_def']⟩ end NormalWord open NormalWord /-- All maps into the `PushoutI`, or amalgamated product of groups are injective, provided all maps in the diagram are injective. See also `base_injective` -/ theorem of_injective (hφ : ∀ i, Function.Injective (φ i)) (i : ι) : Function.Injective (of (φ := φ) i) := by rcases transversal_nonempty φ hφ with ⟨d⟩ let _ := Classical.decEq ι let _ := fun i => Classical.decEq (G i) refine Function.Injective.of_comp (f := ((· • ·) : PushoutI φ → NormalWord d → NormalWord d)) ?_ intros _ _ h exact eq_of_smul_eq_smul (fun w : NormalWord d => by simp_all [Function.funext_iff, of_smul_eq_smul]) theorem base_injective (hφ : ∀ i, Function.Injective (φ i)) : Function.Injective (base φ) := by rcases transversal_nonempty φ hφ with ⟨d⟩ let _ := Classical.decEq ι let _ := fun i => Classical.decEq (G i) refine Function.Injective.of_comp (f := ((· • ·) : PushoutI φ → NormalWord d → NormalWord d)) ?_ intros _ _ h exact eq_of_smul_eq_smul (fun w : NormalWord d => by simp_all [Function.funext_iff, base_smul_eq_smul]) section Reduced open NormalWord variable (φ) /-- A word in `CoprodI` is reduced if none of its letters are in the base group. -/ def Reduced (w : Word G) : Prop := ∀ g, g ∈ w.toList → g.2 ∉ (φ g.1).range variable {φ} theorem Reduced.exists_normalWord_prod_eq (d : Transversal φ) {w : Word G} (hw : Reduced φ w) : ∃ w' : NormalWord d, w'.prod = ofCoprodI w.prod ∧ w'.toList.map Sigma.fst = w.toList.map Sigma.fst := by classical induction w using Word.consRecOn with | h_empty => exact ⟨empty, by simp, rfl⟩ | h_cons i g w hIdx hg1 ih => rcases ih (fun _ hg => hw _ (List.mem_cons_of_mem _ hg)) with ⟨w', hw'prod, hw'map⟩ refine ⟨cons g w' ?_ ?_, ?_⟩ · rwa [Word.fstIdx, ← List.head?_map, hw'map, List.head?_map] · exact hw _ (List.mem_cons_self _ _) · simp [hw'prod, hw'map] /-- For any word `w` in the coproduct, if `w` is reduced (i.e none its letters are in the image of the base monoid), and nonempty, then `w` itself is not in the image of the base group. -/ theorem Reduced.eq_empty_of_mem_range (hφ : ∀ i, Injective (φ i)) {w : Word G} (hw : Reduced φ w) (h : ofCoprodI w.prod ∈ (base φ).range) : w = .empty := by rcases transversal_nonempty φ hφ with ⟨d⟩ rcases hw.exists_normalWord_prod_eq d with ⟨w', hw'prod, hw'map⟩ rcases h with ⟨h, heq⟩ have : (NormalWord.prod (d := d) ⟨.empty, h, by simp⟩) = base φ h := by simp [NormalWord.prod] rw [← hw'prod, ← this] at heq suffices w'.toWord = .empty by simp [this, @eq_comm _ []] at hw'map ext simp [hw'map] rw [← prod_injective heq] end Reduced /-- The intersection of the images of the maps from any two distinct groups in the diagram into the amalgamated product is the image of the map from the base group in the diagram. -/ theorem inf_of_range_eq_base_range (hφ : ∀ i, Injective (φ i)) {i j : ι} (hij : i ≠ j) : (of i).range ⊓ (of j).range = (base φ).range := le_antisymm (by intro x ⟨⟨g₁, hg₁⟩, ⟨g₂, hg₂⟩⟩ by_contra hx have hx1 : x ≠ 1 := by rintro rfl; simp_all only [ne_eq, one_mem, not_true_eq_false] have hg₁1 : g₁ ≠ 1 := ne_of_apply_ne (of (φ := φ) i) (by simp_all) have hg₂1 : g₂ ≠ 1 := ne_of_apply_ne (of (φ := φ) j) (by simp_all) have hg₁r : g₁ ∉ (φ i).range := by rintro ⟨y, rfl⟩ subst hg₁ exact hx (of_apply_eq_base φ i y ▸ MonoidHom.mem_range.2 ⟨y, rfl⟩) have hg₂r : g₂ ∉ (φ j).range := by rintro ⟨y, rfl⟩ subst hg₂ exact hx (of_apply_eq_base φ j y ▸ MonoidHom.mem_range.2 ⟨y, rfl⟩) let w : Word G := ⟨[⟨_, g₁⟩, ⟨_, g₂⁻¹⟩], by simp_all, by simp_all⟩ have hw : Reduced φ w := by simp only [not_exists, ne_eq, Reduced, List.find?, List.mem_cons, List.mem_singleton, forall_eq_or_imp, not_false_eq_true, forall_const, forall_eq, true_and, hg₁r, hg₂r, List.mem_nil_iff, false_imp_iff, imp_true_iff, and_true, inv_mem_iff] have := hw.eq_empty_of_mem_range hφ (by simp only [Word.prod, List.map_cons, List.prod_cons, List.prod_nil, List.map_nil, map_mul, ofCoprodI_of, hg₁, hg₂, map_inv, map_one, mul_one, mul_inv_self, one_mem]) simp [w, Word.empty] at this) (le_inf (by rw [← of_comp_eq_base i] rintro _ ⟨h, rfl⟩ exact MonoidHom.mem_range.2 ⟨φ i h, rfl⟩) (by rw [← of_comp_eq_base j] rintro _ ⟨h, rfl⟩ exact MonoidHom.mem_range.2 ⟨φ j h, rfl⟩)) end PushoutI end Monoid
GroupTheory\QuotientGroup.lean
/- Copyright (c) 2018 Kevin Buzzard, Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, Patrick Massot This file is to a certain extent based on `quotient_module.lean` by Johannes Hölzl. -/ import Mathlib.Algebra.Group.Subgroup.Finite import Mathlib.Algebra.Group.Subgroup.Pointwise import Mathlib.GroupTheory.Congruence.Basic import Mathlib.GroupTheory.Coset /-! # Quotients of groups by normal subgroups This files develops the basic theory of quotients of groups by normal subgroups. In particular it proves Noether's first and second isomorphism theorems. ## Main definitions * `mk'`: the canonical group homomorphism `G →* G/N` given a normal subgroup `N` of `G`. * `lift φ`: the group homomorphism `G/N →* H` given a group homomorphism `φ : G →* H` such that `N ⊆ ker φ`. * `map f`: the group homomorphism `G/N →* H/M` given a group homomorphism `f : G →* H` such that `N ⊆ f⁻¹(M)`. ## Main statements * `QuotientGroup.quotientKerEquivRange`: Noether's first isomorphism theorem, an explicit isomorphism `G/ker φ → range φ` for every group homomorphism `φ : G →* H`. * `QuotientGroup.quotientInfEquivProdNormalQuotient`: Noether's second isomorphism theorem, an explicit isomorphism between `H/(H ∩ N)` and `(HN)/N` given a subgroup `H` and a normal subgroup `N` of a group `G`. * `QuotientGroup.quotientQuotientEquivQuotient`: Noether's third isomorphism theorem, the canonical isomorphism between `(G / N) / (M / N)` and `G / M`, where `N ≤ M`. ## Tags isomorphism theorems, quotient groups -/ open Function open scoped Pointwise universe u v w x namespace QuotientGroup variable {G : Type u} [Group G] (N : Subgroup G) [nN : N.Normal] {H : Type v} [Group H] {M : Type x} [Monoid M] /-- The congruence relation generated by a normal subgroup. -/ @[to_additive "The additive congruence relation generated by a normal additive subgroup."] protected def con : Con G where toSetoid := leftRel N mul' := @fun a b c d hab hcd => by rw [leftRel_eq] at hab hcd ⊢ dsimp only calc (a * c)⁻¹ * (b * d) = c⁻¹ * (a⁻¹ * b) * c⁻¹⁻¹ * (c⁻¹ * d) := by simp only [mul_inv_rev, mul_assoc, inv_mul_cancel_left] _ ∈ N := N.mul_mem (nN.conj_mem _ hab _) hcd @[to_additive] instance Quotient.group : Group (G ⧸ N) := (QuotientGroup.con N).group /-- The group homomorphism from `G` to `G/N`. -/ @[to_additive "The additive group homomorphism from `G` to `G/N`."] def mk' : G →* G ⧸ N := MonoidHom.mk' QuotientGroup.mk fun _ _ => rfl @[to_additive (attr := simp)] theorem coe_mk' : (mk' N : G → G ⧸ N) = mk := rfl @[to_additive (attr := simp)] theorem mk'_apply (x : G) : mk' N x = x := rfl @[to_additive] theorem mk'_surjective : Surjective <| mk' N := @mk_surjective _ _ N @[to_additive] theorem mk'_eq_mk' {x y : G} : mk' N x = mk' N y ↔ ∃ z ∈ N, x * z = y := QuotientGroup.eq.trans <| by simp only [← _root_.eq_inv_mul_iff_mul_eq, exists_prop, exists_eq_right] open scoped Pointwise in @[to_additive] theorem sound (U : Set (G ⧸ N)) (g : N.op) : g • (mk' N) ⁻¹' U = (mk' N) ⁻¹' U := by ext x simp only [Set.mem_preimage, Set.mem_smul_set_iff_inv_smul_mem] congr! 1 exact Quotient.sound ⟨g⁻¹, rfl⟩ /-- Two `MonoidHom`s from a quotient group are equal if their compositions with `QuotientGroup.mk'` are equal. See note [partially-applied ext lemmas]. -/ @[to_additive (attr := ext 1100) "Two `AddMonoidHom`s from an additive quotient group are equal if their compositions with `AddQuotientGroup.mk'` are equal. See note [partially-applied ext lemmas]. "] theorem monoidHom_ext ⦃f g : G ⧸ N →* M⦄ (h : f.comp (mk' N) = g.comp (mk' N)) : f = g := MonoidHom.ext fun x => QuotientGroup.induction_on x <| (DFunLike.congr_fun h : _) @[to_additive (attr := simp)] theorem eq_one_iff {N : Subgroup G} [nN : N.Normal] (x : G) : (x : G ⧸ N) = 1 ↔ x ∈ N := by refine QuotientGroup.eq.trans ?_ rw [mul_one, Subgroup.inv_mem_iff] @[to_additive] theorem ker_le_range_iff {I : Type w} [Group I] (f : G →* H) [f.range.Normal] (g : H →* I) : g.ker ≤ f.range ↔ (mk' f.range).comp g.ker.subtype = 1 := ⟨fun h => MonoidHom.ext fun ⟨_, hx⟩ => (eq_one_iff _).mpr <| h hx, fun h x hx => (eq_one_iff _).mp <| by exact DFunLike.congr_fun h ⟨x, hx⟩⟩ @[to_additive (attr := simp)] theorem ker_mk' : MonoidHom.ker (QuotientGroup.mk' N : G →* G ⧸ N) = N := Subgroup.ext eq_one_iff -- Porting note: I think this is misnamed without the prime @[to_additive] theorem eq_iff_div_mem {N : Subgroup G} [nN : N.Normal] {x y : G} : (x : G ⧸ N) = y ↔ x / y ∈ N := by refine eq_comm.trans (QuotientGroup.eq.trans ?_) rw [nN.mem_comm_iff, div_eq_mul_inv] -- for commutative groups we don't need normality assumption @[to_additive] instance Quotient.commGroup {G : Type*} [CommGroup G] (N : Subgroup G) : CommGroup (G ⧸ N) := { toGroup := have := N.normal_of_comm; QuotientGroup.Quotient.group N mul_comm := fun a b => Quotient.inductionOn₂' a b fun a b => congr_arg mk (mul_comm a b) } local notation " Q " => G ⧸ N @[to_additive (attr := simp)] theorem mk_one : ((1 : G) : Q) = 1 := rfl @[to_additive (attr := simp)] theorem mk_mul (a b : G) : ((a * b : G) : Q) = a * b := rfl @[to_additive (attr := simp)] theorem mk_inv (a : G) : ((a⁻¹ : G) : Q) = (a : Q)⁻¹ := rfl @[to_additive (attr := simp)] theorem mk_div (a b : G) : ((a / b : G) : Q) = a / b := rfl @[to_additive (attr := simp)] theorem mk_pow (a : G) (n : ℕ) : ((a ^ n : G) : Q) = (a : Q) ^ n := rfl @[to_additive (attr := simp)] theorem mk_zpow (a : G) (n : ℤ) : ((a ^ n : G) : Q) = (a : Q) ^ n := rfl @[to_additive (attr := simp)] theorem mk_prod {G ι : Type*} [CommGroup G] (N : Subgroup G) (s : Finset ι) {f : ι → G} : ((Finset.prod s f : G) : G ⧸ N) = Finset.prod s (fun i => (f i : G ⧸ N)) := map_prod (QuotientGroup.mk' N) _ _ @[to_additive (attr := simp)] lemma map_mk'_self : N.map (mk' N) = ⊥ := by aesop /-- A group homomorphism `φ : G →* M` with `N ⊆ ker(φ)` descends (i.e. `lift`s) to a group homomorphism `G/N →* M`. -/ @[to_additive "An `AddGroup` homomorphism `φ : G →+ M` with `N ⊆ ker(φ)` descends (i.e. `lift`s) to a group homomorphism `G/N →* M`."] def lift (φ : G →* M) (HN : N ≤ φ.ker) : Q →* M := (QuotientGroup.con N).lift φ fun x y h => by simp only [QuotientGroup.con, leftRel_apply, Con.rel_mk] at h rw [Con.ker_rel] calc φ x = φ (y * (x⁻¹ * y)⁻¹) := by rw [mul_inv_rev, inv_inv, mul_inv_cancel_left] _ = φ y := by rw [φ.map_mul, HN (N.inv_mem h), mul_one] @[to_additive (attr := simp)] theorem lift_mk {φ : G →* M} (HN : N ≤ φ.ker) (g : G) : lift N φ HN (g : Q) = φ g := rfl @[to_additive (attr := simp)] theorem lift_mk' {φ : G →* M} (HN : N ≤ φ.ker) (g : G) : lift N φ HN (mk g : Q) = φ g := rfl -- TODO: replace `mk` with `mk'`) @[to_additive (attr := simp)] theorem lift_quot_mk {φ : G →* M} (HN : N ≤ φ.ker) (g : G) : lift N φ HN (Quot.mk _ g : Q) = φ g := rfl /-- A group homomorphism `f : G →* H` induces a map `G/N →* H/M` if `N ⊆ f⁻¹(M)`. -/ @[to_additive "An `AddGroup` homomorphism `f : G →+ H` induces a map `G/N →+ H/M` if `N ⊆ f⁻¹(M)`."] def map (M : Subgroup H) [M.Normal] (f : G →* H) (h : N ≤ M.comap f) : G ⧸ N →* H ⧸ M := by refine QuotientGroup.lift N ((mk' M).comp f) ?_ intro x hx refine QuotientGroup.eq.2 ?_ rw [mul_one, Subgroup.inv_mem_iff] exact h hx @[to_additive (attr := simp)] theorem map_mk (M : Subgroup H) [M.Normal] (f : G →* H) (h : N ≤ M.comap f) (x : G) : map N M f h ↑x = ↑(f x) := rfl @[to_additive] theorem map_mk' (M : Subgroup H) [M.Normal] (f : G →* H) (h : N ≤ M.comap f) (x : G) : map N M f h (mk' _ x) = ↑(f x) := rfl @[to_additive] theorem map_id_apply (h : N ≤ Subgroup.comap (MonoidHom.id _) N := (Subgroup.comap_id N).le) (x) : map N N (MonoidHom.id _) h x = x := induction_on x fun _x => rfl @[to_additive (attr := simp)] theorem map_id (h : N ≤ Subgroup.comap (MonoidHom.id _) N := (Subgroup.comap_id N).le) : map N N (MonoidHom.id _) h = MonoidHom.id _ := MonoidHom.ext (map_id_apply N h) @[to_additive (attr := simp)] theorem map_map {I : Type*} [Group I] (M : Subgroup H) (O : Subgroup I) [M.Normal] [O.Normal] (f : G →* H) (g : H →* I) (hf : N ≤ Subgroup.comap f M) (hg : M ≤ Subgroup.comap g O) (hgf : N ≤ Subgroup.comap (g.comp f) O := hf.trans ((Subgroup.comap_mono hg).trans_eq (Subgroup.comap_comap _ _ _))) (x : G ⧸ N) : map M O g hg (map N M f hf x) = map N O (g.comp f) hgf x := by refine induction_on x fun x => ?_ simp only [map_mk, MonoidHom.comp_apply] @[to_additive (attr := simp)] theorem map_comp_map {I : Type*} [Group I] (M : Subgroup H) (O : Subgroup I) [M.Normal] [O.Normal] (f : G →* H) (g : H →* I) (hf : N ≤ Subgroup.comap f M) (hg : M ≤ Subgroup.comap g O) (hgf : N ≤ Subgroup.comap (g.comp f) O := hf.trans ((Subgroup.comap_mono hg).trans_eq (Subgroup.comap_comap _ _ _))) : (map M O g hg).comp (map N M f hf) = map N O (g.comp f) hgf := MonoidHom.ext (map_map N M O f g hf hg hgf) section Pointwise open Set @[to_additive (attr := simp)] lemma image_coe : ((↑) : G → Q) '' N = 1 := congr_arg ((↑) : Subgroup Q → Set Q) <| map_mk'_self N @[to_additive] lemma preimage_image_coe (s : Set G) : ((↑) : G → Q) ⁻¹' ((↑) '' s) = N * s := by ext a constructor · rintro ⟨b, hb, h⟩ refine ⟨a / b, (QuotientGroup.eq_one_iff _).1 ?_, b, hb, div_mul_cancel _ _⟩ simp only [h, QuotientGroup.mk_div, div_self'] · rintro ⟨a, ha, b, hb, rfl⟩ refine ⟨b, hb, ?_⟩ simpa only [QuotientGroup.mk_mul, self_eq_mul_left, QuotientGroup.eq_one_iff] @[to_additive] lemma image_coe_inj {s t : Set G} : ((↑) : G → Q) '' s = ((↑) : G → Q) '' t ↔ ↑N * s = N * t := by simp_rw [← preimage_image_coe] exact QuotientGroup.mk_surjective.preimage_injective.eq_iff.symm end Pointwise section congr variable (G' : Subgroup G) (H' : Subgroup H) [Subgroup.Normal G'] [Subgroup.Normal H'] /-- `QuotientGroup.congr` lifts the isomorphism `e : G ≃ H` to `G ⧸ G' ≃ H ⧸ H'`, given that `e` maps `G` to `H`. -/ @[to_additive "`QuotientAddGroup.congr` lifts the isomorphism `e : G ≃ H` to `G ⧸ G' ≃ H ⧸ H'`, given that `e` maps `G` to `H`."] def congr (e : G ≃* H) (he : G'.map e = H') : G ⧸ G' ≃* H ⧸ H' := { map G' H' e (he ▸ G'.le_comap_map (e : G →* H)) with toFun := map G' H' e (he ▸ G'.le_comap_map (e : G →* H)) invFun := map H' G' e.symm (he ▸ (G'.map_equiv_eq_comap_symm e).le) left_inv := fun x => by rw [map_map G' H' G' e e.symm (he ▸ G'.le_comap_map (e : G →* H)) (he ▸ (G'.map_equiv_eq_comap_symm e).le)] simp only [map_map, ← MulEquiv.coe_monoidHom_trans, MulEquiv.self_trans_symm, MulEquiv.coe_monoidHom_refl, map_id_apply] right_inv := fun x => by rw [map_map H' G' H' e.symm e (he ▸ (G'.map_equiv_eq_comap_symm e).le) (he ▸ G'.le_comap_map (e : G →* H)) ] simp only [← MulEquiv.coe_monoidHom_trans, MulEquiv.symm_trans_self, MulEquiv.coe_monoidHom_refl, map_id_apply] } @[simp] theorem congr_mk (e : G ≃* H) (he : G'.map ↑e = H') (x) : congr G' H' e he (mk x) = e x := rfl theorem congr_mk' (e : G ≃* H) (he : G'.map ↑e = H') (x) : congr G' H' e he (mk' G' x) = mk' H' (e x) := rfl @[simp] theorem congr_apply (e : G ≃* H) (he : G'.map ↑e = H') (x : G) : congr G' H' e he x = mk' H' (e x) := rfl @[simp] theorem congr_refl (he : G'.map (MulEquiv.refl G : G →* G) = G' := Subgroup.map_id G') : congr G' G' (MulEquiv.refl G) he = MulEquiv.refl (G ⧸ G') := by ext ⟨x⟩ rfl @[simp] theorem congr_symm (e : G ≃* H) (he : G'.map ↑e = H') : (congr G' H' e he).symm = congr H' G' e.symm ((Subgroup.map_symm_eq_iff_map_eq _).mpr he) := rfl end congr variable (φ : G →* H) open MonoidHom /-- The induced map from the quotient by the kernel to the codomain. -/ @[to_additive "The induced map from the quotient by the kernel to the codomain."] def kerLift : G ⧸ ker φ →* H := lift _ φ fun _g => φ.mem_ker.mp @[to_additive (attr := simp)] theorem kerLift_mk (g : G) : (kerLift φ) g = φ g := lift_mk _ _ _ @[to_additive (attr := simp)] theorem kerLift_mk' (g : G) : (kerLift φ) (mk g) = φ g := lift_mk' _ _ _ @[to_additive] theorem kerLift_injective : Injective (kerLift φ) := fun a b => Quotient.inductionOn₂' a b fun a b (h : φ a = φ b) => Quotient.sound' <| by rw [leftRel_apply, mem_ker, φ.map_mul, ← h, φ.map_inv, inv_mul_self] -- Note that `ker φ` isn't definitionally `ker (φ.rangeRestrict)` -- so there is a bit of annoying code duplication here /-- The induced map from the quotient by the kernel to the range. -/ @[to_additive "The induced map from the quotient by the kernel to the range."] def rangeKerLift : G ⧸ ker φ →* φ.range := lift _ φ.rangeRestrict fun g hg => (mem_ker _).mp <| by rwa [ker_rangeRestrict] @[to_additive] theorem rangeKerLift_injective : Injective (rangeKerLift φ) := fun a b => Quotient.inductionOn₂' a b fun a b (h : φ.rangeRestrict a = φ.rangeRestrict b) => Quotient.sound' <| by rw [leftRel_apply, ← ker_rangeRestrict, mem_ker, φ.rangeRestrict.map_mul, ← h, φ.rangeRestrict.map_inv, inv_mul_self] @[to_additive] theorem rangeKerLift_surjective : Surjective (rangeKerLift φ) := by rintro ⟨_, g, rfl⟩ use mk g rfl /-- **Noether's first isomorphism theorem** (a definition): the canonical isomorphism between `G/(ker φ)` to `range φ`. -/ @[to_additive "The first isomorphism theorem (a definition): the canonical isomorphism between `G/(ker φ)` to `range φ`."] noncomputable def quotientKerEquivRange : G ⧸ ker φ ≃* range φ := MulEquiv.ofBijective (rangeKerLift φ) ⟨rangeKerLift_injective φ, rangeKerLift_surjective φ⟩ /-- The canonical isomorphism `G/(ker φ) ≃* H` induced by a homomorphism `φ : G →* H` with a right inverse `ψ : H → G`. -/ @[to_additive (attr := simps) "The canonical isomorphism `G/(ker φ) ≃+ H` induced by a homomorphism `φ : G →+ H` with a right inverse `ψ : H → G`."] def quotientKerEquivOfRightInverse (ψ : H → G) (hφ : RightInverse ψ φ) : G ⧸ ker φ ≃* H := { kerLift φ with toFun := kerLift φ invFun := mk ∘ ψ left_inv := fun x => kerLift_injective φ (by rw [Function.comp_apply, kerLift_mk', hφ]) right_inv := hφ } /-- The canonical isomorphism `G/⊥ ≃* G`. -/ @[to_additive (attr := simps!) "The canonical isomorphism `G/⊥ ≃+ G`."] def quotientBot : G ⧸ (⊥ : Subgroup G) ≃* G := quotientKerEquivOfRightInverse (MonoidHom.id G) id fun _x => rfl /-- The canonical isomorphism `G/(ker φ) ≃* H` induced by a surjection `φ : G →* H`. For a `computable` version, see `QuotientGroup.quotientKerEquivOfRightInverse`. -/ @[to_additive "The canonical isomorphism `G/(ker φ) ≃+ H` induced by a surjection `φ : G →+ H`. For a `computable` version, see `QuotientAddGroup.quotientKerEquivOfRightInverse`."] noncomputable def quotientKerEquivOfSurjective (hφ : Surjective φ) : G ⧸ ker φ ≃* H := quotientKerEquivOfRightInverse φ _ hφ.hasRightInverse.choose_spec /-- If two normal subgroups `M` and `N` of `G` are the same, their quotient groups are isomorphic. -/ @[to_additive "If two normal subgroups `M` and `N` of `G` are the same, their quotient groups are isomorphic."] def quotientMulEquivOfEq {M N : Subgroup G} [M.Normal] [N.Normal] (h : M = N) : G ⧸ M ≃* G ⧸ N := { Subgroup.quotientEquivOfEq h with map_mul' := fun q r => Quotient.inductionOn₂' q r fun _g _h => rfl } @[to_additive (attr := simp)] theorem quotientMulEquivOfEq_mk {M N : Subgroup G} [M.Normal] [N.Normal] (h : M = N) (x : G) : QuotientGroup.quotientMulEquivOfEq h (QuotientGroup.mk x) = QuotientGroup.mk x := rfl /-- Let `A', A, B', B` be subgroups of `G`. If `A' ≤ B'` and `A ≤ B`, then there is a map `A / (A' ⊓ A) →* B / (B' ⊓ B)` induced by the inclusions. -/ @[to_additive "Let `A', A, B', B` be subgroups of `G`. If `A' ≤ B'` and `A ≤ B`, then there is a map `A / (A' ⊓ A) →+ B / (B' ⊓ B)` induced by the inclusions."] def quotientMapSubgroupOfOfLe {A' A B' B : Subgroup G} [_hAN : (A'.subgroupOf A).Normal] [_hBN : (B'.subgroupOf B).Normal] (h' : A' ≤ B') (h : A ≤ B) : A ⧸ A'.subgroupOf A →* B ⧸ B'.subgroupOf B := map _ _ (Subgroup.inclusion h) <| Subgroup.comap_mono h' @[to_additive (attr := simp)] theorem quotientMapSubgroupOfOfLe_mk {A' A B' B : Subgroup G} [_hAN : (A'.subgroupOf A).Normal] [_hBN : (B'.subgroupOf B).Normal] (h' : A' ≤ B') (h : A ≤ B) (x : A) : quotientMapSubgroupOfOfLe h' h x = ↑(Subgroup.inclusion h x : B) := rfl /-- Let `A', A, B', B` be subgroups of `G`. If `A' = B'` and `A = B`, then the quotients `A / (A' ⊓ A)` and `B / (B' ⊓ B)` are isomorphic. Applying this equiv is nicer than rewriting along the equalities, since the type of `(A'.subgroupOf A : Subgroup A)` depends on `A`. -/ @[to_additive "Let `A', A, B', B` be subgroups of `G`. If `A' = B'` and `A = B`, then the quotients `A / (A' ⊓ A)` and `B / (B' ⊓ B)` are isomorphic. Applying this equiv is nicer than rewriting along the equalities, since the type of `(A'.addSubgroupOf A : AddSubgroup A)` depends on on `A`. "] def equivQuotientSubgroupOfOfEq {A' A B' B : Subgroup G} [hAN : (A'.subgroupOf A).Normal] [hBN : (B'.subgroupOf B).Normal] (h' : A' = B') (h : A = B) : A ⧸ A'.subgroupOf A ≃* B ⧸ B'.subgroupOf B := MonoidHom.toMulEquiv (quotientMapSubgroupOfOfLe h'.le h.le) (quotientMapSubgroupOfOfLe h'.ge h.ge) (by ext ⟨x, hx⟩; rfl) (by ext ⟨x, hx⟩; rfl) section ZPow variable {A B C : Type u} [CommGroup A] [CommGroup B] [CommGroup C] variable (f : A →* B) (g : B →* A) (e : A ≃* B) (d : B ≃* C) (n : ℤ) /-- The map of quotients by powers of an integer induced by a group homomorphism. -/ @[to_additive "The map of quotients by multiples of an integer induced by an additive group homomorphism."] def homQuotientZPowOfHom : A ⧸ (zpowGroupHom n : A →* A).range →* B ⧸ (zpowGroupHom n : B →* B).range := lift _ ((mk' _).comp f) fun g ⟨h, (hg : h ^ n = g)⟩ => (eq_one_iff _).mpr ⟨f h, by simp only [← hg, map_zpow, zpowGroupHom_apply]⟩ @[to_additive (attr := simp)] theorem homQuotientZPowOfHom_id : homQuotientZPowOfHom (MonoidHom.id A) n = MonoidHom.id _ := monoidHom_ext _ rfl @[to_additive (attr := simp)] theorem homQuotientZPowOfHom_comp : homQuotientZPowOfHom (f.comp g) n = (homQuotientZPowOfHom f n).comp (homQuotientZPowOfHom g n) := monoidHom_ext _ rfl @[to_additive (attr := simp)] theorem homQuotientZPowOfHom_comp_of_rightInverse (i : Function.RightInverse g f) : (homQuotientZPowOfHom f n).comp (homQuotientZPowOfHom g n) = MonoidHom.id _ := monoidHom_ext _ <| MonoidHom.ext fun x => congrArg _ <| i x /-- The equivalence of quotients by powers of an integer induced by a group isomorphism. -/ @[to_additive "The equivalence of quotients by multiples of an integer induced by an additive group isomorphism."] def equivQuotientZPowOfEquiv : A ⧸ (zpowGroupHom n : A →* A).range ≃* B ⧸ (zpowGroupHom n : B →* B).range := MonoidHom.toMulEquiv _ _ (homQuotientZPowOfHom_comp_of_rightInverse (e.symm : B →* A) (e : A →* B) n e.left_inv) (homQuotientZPowOfHom_comp_of_rightInverse (e : A →* B) (e.symm : B →* A) n e.right_inv) -- Porting note: had to explicitly coerce the `MulEquiv`s to `MonoidHom`s @[to_additive (attr := simp)] theorem equivQuotientZPowOfEquiv_refl : MulEquiv.refl (A ⧸ (zpowGroupHom n : A →* A).range) = equivQuotientZPowOfEquiv (MulEquiv.refl A) n := by ext x rw [← Quotient.out_eq' x] rfl @[to_additive (attr := simp)] theorem equivQuotientZPowOfEquiv_symm : (equivQuotientZPowOfEquiv e n).symm = equivQuotientZPowOfEquiv e.symm n := rfl @[to_additive (attr := simp)] theorem equivQuotientZPowOfEquiv_trans : (equivQuotientZPowOfEquiv e n).trans (equivQuotientZPowOfEquiv d n) = equivQuotientZPowOfEquiv (e.trans d) n := by ext x rw [← Quotient.out_eq' x] rfl end ZPow section SndIsomorphismThm open Subgroup /-- **Noether's second isomorphism theorem**: given two subgroups `H` and `N` of a group `G`, where `N` is normal, defines an isomorphism between `H/(H ∩ N)` and `(HN)/N`. -/ @[to_additive "The second isomorphism theorem: given two subgroups `H` and `N` of a group `G`, where `N` is normal, defines an isomorphism between `H/(H ∩ N)` and `(H + N)/N`"] noncomputable def quotientInfEquivProdNormalQuotient (H N : Subgroup G) [N.Normal] : H ⧸ N.subgroupOf H ≃* _ ⧸ N.subgroupOf (H ⊔ N) := let φ :-- φ is the natural homomorphism H →* (HN)/N. H →* _ ⧸ N.subgroupOf (H ⊔ N) := (mk' <| N.subgroupOf (H ⊔ N)).comp (inclusion le_sup_left) have φ_surjective : Surjective φ := fun x => x.inductionOn' <| by rintro ⟨y, hy : y ∈ (H ⊔ N)⟩ rw [← SetLike.mem_coe] at hy rw [mul_normal H N] at hy rcases hy with ⟨h, hh, n, hn, rfl⟩ use ⟨h, hh⟩ let _ : Setoid ↑(H ⊔ N) := (@leftRel ↑(H ⊔ N) (H ⊔ N : Subgroup G).toGroup (N.subgroupOf (H ⊔ N))) -- Porting note: Lean couldn't find this automatically refine Quotient.eq.mpr ?_ change Setoid.r _ _ rw [leftRel_apply] change h⁻¹ * (h * n) ∈ N rwa [← mul_assoc, inv_mul_self, one_mul] (quotientMulEquivOfEq (by simp [φ, ← comap_ker])).trans (quotientKerEquivOfSurjective φ φ_surjective) end SndIsomorphismThm section ThirdIsoThm variable (M : Subgroup G) [nM : M.Normal] @[to_additive] instance map_normal : (M.map (QuotientGroup.mk' N)).Normal := nM.map _ mk_surjective variable (h : N ≤ M) /-- The map from the third isomorphism theorem for groups: `(G / N) / (M / N) → G / M`. -/ @[to_additive "The map from the third isomorphism theorem for additive groups: `(A / N) / (M / N) → A / M`."] def quotientQuotientEquivQuotientAux : (G ⧸ N) ⧸ M.map (mk' N) →* G ⧸ M := lift (M.map (mk' N)) (map N M (MonoidHom.id G) h) (by rintro _ ⟨x, hx, rfl⟩ rw [mem_ker, map_mk' N M _ _ x] exact (QuotientGroup.eq_one_iff _).mpr hx) @[to_additive (attr := simp)] theorem quotientQuotientEquivQuotientAux_mk (x : G ⧸ N) : quotientQuotientEquivQuotientAux N M h x = QuotientGroup.map N M (MonoidHom.id G) h x := QuotientGroup.lift_mk' _ _ x @[to_additive] theorem quotientQuotientEquivQuotientAux_mk_mk (x : G) : quotientQuotientEquivQuotientAux N M h (x : G ⧸ N) = x := QuotientGroup.lift_mk' (M.map (mk' N)) _ x /-- **Noether's third isomorphism theorem** for groups: `(G / N) / (M / N) ≃* G / M`. -/ @[to_additive "**Noether's third isomorphism theorem** for additive groups: `(A / N) / (M / N) ≃+ A / M`."] def quotientQuotientEquivQuotient : (G ⧸ N) ⧸ M.map (QuotientGroup.mk' N) ≃* G ⧸ M := MonoidHom.toMulEquiv (quotientQuotientEquivQuotientAux N M h) (QuotientGroup.map _ _ (QuotientGroup.mk' N) (Subgroup.le_comap_map _ _)) (by ext; simp) (by ext; simp) end ThirdIsoThm section trivial @[to_additive] theorem subsingleton_quotient_top : Subsingleton (G ⧸ (⊤ : Subgroup G)) := by dsimp [HasQuotient.Quotient, QuotientGroup.instHasQuotientSubgroup, Quotient] rw [leftRel_eq] exact Trunc.instSubsingletonTrunc /-- If the quotient by a subgroup gives a singleton then the subgroup is the whole group. -/ @[to_additive "If the quotient by an additive subgroup gives a singleton then the additive subgroup is the whole additive group."] theorem subgroup_eq_top_of_subsingleton (H : Subgroup G) (h : Subsingleton (G ⧸ H)) : H = ⊤ := top_unique fun x _ => by have this : 1⁻¹ * x ∈ H := QuotientGroup.eq.1 (Subsingleton.elim _ _) rwa [inv_one, one_mul] at this end trivial @[to_additive] theorem comap_comap_center {H₁ : Subgroup G} [H₁.Normal] {H₂ : Subgroup (G ⧸ H₁)} [H₂.Normal] : ((Subgroup.center ((G ⧸ H₁) ⧸ H₂)).comap (mk' H₂)).comap (mk' H₁) = (Subgroup.center (G ⧸ H₂.comap (mk' H₁))).comap (mk' (H₂.comap (mk' H₁))) := by ext x simp only [mk'_apply, Subgroup.mem_comap, Subgroup.mem_center_iff, forall_mk, ← mk_mul, eq_iff_div_mem, mk_div] end QuotientGroup namespace Group open scoped Classical open QuotientGroup Subgroup variable {F G H : Type u} [Group F] [Group G] [Group H] [Fintype F] [Fintype H] variable (f : F →* G) (g : G →* H) /-- If `F` and `H` are finite such that `ker(G →* H) ≤ im(F →* G)`, then `G` is finite. -/ @[to_additive "If `F` and `H` are finite such that `ker(G →+ H) ≤ im(F →+ G)`, then `G` is finite."] noncomputable def fintypeOfKerLeRange (h : g.ker ≤ f.range) : Fintype G := @Fintype.ofEquiv _ _ (@instFintypeProd _ _ (Fintype.ofInjective _ <| kerLift_injective g) <| Fintype.ofInjective _ <| inclusion_injective h) groupEquivQuotientProdSubgroup.symm /-- If `F` and `H` are finite such that `ker(G →* H) = im(F →* G)`, then `G` is finite. -/ @[to_additive "If `F` and `H` are finite such that `ker(G →+ H) = im(F →+ G)`, then `G` is finite."] noncomputable def fintypeOfKerEqRange (h : g.ker = f.range) : Fintype G := fintypeOfKerLeRange _ _ h.le /-- If `ker(G →* H)` and `H` are finite, then `G` is finite. -/ @[to_additive "If `ker(G →+ H)` and `H` are finite, then `G` is finite."] noncomputable def fintypeOfKerOfCodom [Fintype g.ker] : Fintype G := fintypeOfKerLeRange ((topEquiv : _ ≃* G).toMonoidHom.comp <| inclusion le_top) g fun x hx => ⟨⟨x, hx⟩, rfl⟩ /-- If `F` and `coker(F →* G)` are finite, then `G` is finite. -/ @[to_additive "If `F` and `coker(F →+ G)` are finite, then `G` is finite."] noncomputable def fintypeOfDomOfCoker [Normal f.range] [Fintype <| G ⧸ f.range] : Fintype G := fintypeOfKerLeRange _ (mk' f.range) fun x => (eq_one_iff x).mp end Group
GroupTheory\Schreier.lean
/- Copyright (c) 2022 Thomas Browning. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning -/ import Mathlib.GroupTheory.Abelianization import Mathlib.GroupTheory.Transfer /-! # Schreier's Lemma In this file we prove Schreier's lemma. ## Main results - `closure_mul_image_eq` : **Schreier's Lemma**: If `R : Set G` is a right_transversal of `H : Subgroup G` with `1 ∈ R`, and if `G` is generated by `S : Set G`, then `H` is generated by the `Set` `(R * S).image (fun g ↦ g * (toFun hR g)⁻¹)`. - `fg_of_index_ne_zero` : **Schreier's Lemma**: A finite index subgroup of a finitely generated group is finitely generated. - `card_commutator_le_of_finite_commutatorSet`: A theorem of Schur: The size of the commutator subgroup is bounded in terms of the number of commutators. -/ open scoped Pointwise section CommGroup open Subgroup open scoped Classical variable (G : Type*) [CommGroup G] [Group.FG G] @[to_additive] theorem card_dvd_exponent_pow_rank : Nat.card G ∣ Monoid.exponent G ^ Group.rank G := by obtain ⟨S, hS1, hS2⟩ := Group.rank_spec G rw [← hS1, ← Fintype.card_coe, ← Finset.card_univ, ← Finset.prod_const] let f : (∀ g : S, zpowers (g : G)) →* G := noncommPiCoprod fun s t _ x y _ _ => mul_comm x _ have hf : Function.Surjective f := by rw [← MonoidHom.range_top_iff_surjective, eq_top_iff, ← hS2, closure_le] exact fun g hg => ⟨Pi.mulSingle ⟨g, hg⟩ ⟨g, mem_zpowers g⟩, noncommPiCoprod_mulSingle _ _⟩ replace hf := card_dvd_of_surjective f hf rw [Nat.card_pi] at hf refine hf.trans (Finset.prod_dvd_prod_of_dvd _ _ fun g _ => ?_) rw [Nat.card_zpowers] exact Monoid.order_dvd_exponent (g : G) @[to_additive] theorem card_dvd_exponent_pow_rank' {n : ℕ} (hG : ∀ g : G, g ^ n = 1) : Nat.card G ∣ n ^ Group.rank G := (card_dvd_exponent_pow_rank G).trans (pow_dvd_pow_of_dvd (Monoid.exponent_dvd_of_forall_pow_eq_one hG) (Group.rank G)) end CommGroup namespace Subgroup open MemRightTransversals variable {G : Type*} [Group G] {H : Subgroup G} {R S : Set G} theorem closure_mul_image_mul_eq_top (hR : R ∈ rightTransversals (H : Set G)) (hR1 : (1 : G) ∈ R) (hS : closure S = ⊤) : (closure ((R * S).image fun g => g * (toFun hR g : G)⁻¹)) * R = ⊤ := by let f : G → R := fun g => toFun hR g let U : Set G := (R * S).image fun g => g * (f g : G)⁻¹ change (closure U : Set G) * R = ⊤ refine top_le_iff.mp fun g _ => ?_ refine closure_induction_right ?_ ?_ ?_ (eq_top_iff.mp hS (mem_top g)) · exact ⟨1, (closure U).one_mem, 1, hR1, one_mul 1⟩ · rintro - - s hs ⟨u, hu, r, hr, rfl⟩ rw [show u * r * s = u * (r * s * (f (r * s) : G)⁻¹) * f (r * s) by group] refine Set.mul_mem_mul ((closure U).mul_mem hu ?_) (f (r * s)).coe_prop exact subset_closure ⟨r * s, Set.mul_mem_mul hr hs, rfl⟩ · rintro - - s hs ⟨u, hu, r, hr, rfl⟩ rw [show u * r * s⁻¹ = u * (f (r * s⁻¹) * s * r⁻¹)⁻¹ * f (r * s⁻¹) by group] refine Set.mul_mem_mul ((closure U).mul_mem hu ((closure U).inv_mem ?_)) (f (r * s⁻¹)).2 refine subset_closure ⟨f (r * s⁻¹) * s, Set.mul_mem_mul (f (r * s⁻¹)).2 hs, ?_⟩ rw [mul_right_inj, inv_inj, ← Subtype.coe_mk r hr, ← Subtype.ext_iff, Subtype.coe_mk] apply (mem_rightTransversals_iff_existsUnique_mul_inv_mem.mp hR (f (r * s⁻¹) * s)).unique (mul_inv_toFun_mem hR (f (r * s⁻¹) * s)) rw [mul_assoc, ← inv_inv s, ← mul_inv_rev, inv_inv] exact toFun_mul_inv_mem hR (r * s⁻¹) /-- **Schreier's Lemma**: If `R : Set G` is a `rightTransversal` of `H : Subgroup G` with `1 ∈ R`, and if `G` is generated by `S : Set G`, then `H` is generated by the `Set` `(R * S).image (fun g ↦ g * (toFun hR g)⁻¹)`. -/ theorem closure_mul_image_eq (hR : R ∈ rightTransversals (H : Set G)) (hR1 : (1 : G) ∈ R) (hS : closure S = ⊤) : closure ((R * S).image fun g => g * (toFun hR g : G)⁻¹) = H := by have hU : closure ((R * S).image fun g => g * (toFun hR g : G)⁻¹) ≤ H := by rw [closure_le] rintro - ⟨g, -, rfl⟩ exact mul_inv_toFun_mem hR g refine le_antisymm hU fun h hh => ?_ obtain ⟨g, hg, r, hr, rfl⟩ := show h ∈ _ from eq_top_iff.mp (closure_mul_image_mul_eq_top hR hR1 hS) (mem_top h) suffices (⟨r, hr⟩ : R) = (⟨1, hR1⟩ : R) by simpa only [show r = 1 from Subtype.ext_iff.mp this, mul_one] apply (mem_rightTransversals_iff_existsUnique_mul_inv_mem.mp hR r).unique · rw [Subtype.coe_mk, mul_inv_self] exact H.one_mem · rw [Subtype.coe_mk, inv_one, mul_one] exact (H.mul_mem_cancel_left (hU hg)).mp hh /-- **Schreier's Lemma**: If `R : Set G` is a `rightTransversal` of `H : Subgroup G` with `1 ∈ R`, and if `G` is generated by `S : Set G`, then `H` is generated by the `Set` `(R * S).image (fun g ↦ g * (toFun hR g)⁻¹)`. -/ theorem closure_mul_image_eq_top (hR : R ∈ rightTransversals (H : Set G)) (hR1 : (1 : G) ∈ R) (hS : closure S = ⊤) : closure ((R * S).image fun g => ⟨g * (toFun hR g : G)⁻¹, mul_inv_toFun_mem hR g⟩ : Set H) = ⊤ := by rw [eq_top_iff, ← map_subtype_le_map_subtype, MonoidHom.map_closure, Set.image_image] exact (map_subtype_le ⊤).trans (ge_of_eq (closure_mul_image_eq hR hR1 hS)) /-- **Schreier's Lemma**: If `R : Finset G` is a `rightTransversal` of `H : Subgroup G` with `1 ∈ R`, and if `G` is generated by `S : Finset G`, then `H` is generated by the `Finset` `(R * S).image (fun g ↦ g * (toFun hR g)⁻¹)`. -/ theorem closure_mul_image_eq_top' [DecidableEq G] {R S : Finset G} (hR : (R : Set G) ∈ rightTransversals (H : Set G)) (hR1 : (1 : G) ∈ R) (hS : closure (S : Set G) = ⊤) : closure (((R * S).image fun g => ⟨_, mul_inv_toFun_mem hR g⟩ : Finset H) : Set H) = ⊤ := by rw [Finset.coe_image, Finset.coe_mul] exact closure_mul_image_eq_top hR hR1 hS variable (H) theorem exists_finset_card_le_mul [FiniteIndex H] {S : Finset G} (hS : closure (S : Set G) = ⊤) : ∃ T : Finset H, T.card ≤ H.index * S.card ∧ closure (T : Set H) = ⊤ := by letI := H.fintypeQuotientOfFiniteIndex haveI : DecidableEq G := Classical.decEq G obtain ⟨R₀, hR, hR1⟩ := H.exists_right_transversal 1 haveI : Fintype R₀ := Fintype.ofEquiv _ (toEquiv hR) let R : Finset G := Set.toFinset R₀ replace hR : (R : Set G) ∈ rightTransversals (H : Set G) := by rwa [Set.coe_toFinset] replace hR1 : (1 : G) ∈ R := by rwa [Set.mem_toFinset] refine ⟨_, ?_, closure_mul_image_eq_top' hR hR1 hS⟩ calc _ ≤ (R * S).card := Finset.card_image_le _ ≤ (R ×ˢ S).card := Finset.card_image_le _ = R.card * S.card := R.card_product S _ = H.index * S.card := congr_arg (· * S.card) ?_ calc R.card = Fintype.card R := (Fintype.card_coe R).symm _ = _ := (Fintype.card_congr (toEquiv hR)).symm _ = Fintype.card (G ⧸ H) := QuotientGroup.card_quotient_rightRel H _ = H.index := by rw [index_eq_card, Nat.card_eq_fintype_card] /-- **Schreier's Lemma**: A finite index subgroup of a finitely generated group is finitely generated. -/ instance fg_of_index_ne_zero [hG : Group.FG G] [FiniteIndex H] : Group.FG H := by obtain ⟨S, hS⟩ := hG.1 obtain ⟨T, -, hT⟩ := exists_finset_card_le_mul H hS exact ⟨⟨T, hT⟩⟩ theorem rank_le_index_mul_rank [hG : Group.FG G] [FiniteIndex H] : Group.rank H ≤ H.index * Group.rank G := by haveI := H.fg_of_index_ne_zero obtain ⟨S, hS₀, hS⟩ := Group.rank_spec G obtain ⟨T, hT₀, hT⟩ := exists_finset_card_le_mul H hS calc Group.rank H ≤ T.card := Group.rank_le H hT _ ≤ H.index * S.card := hT₀ _ = H.index * Group.rank G := congr_arg (H.index * ·) hS₀ variable (G) /-- If `G` has `n` commutators `[g₁, g₂]`, then `|G'| ∣ [G : Z(G)] ^ ([G : Z(G)] * n + 1)`, where `G'` denotes the commutator of `G`. -/ theorem card_commutator_dvd_index_center_pow [Finite (commutatorSet G)] : Nat.card (_root_.commutator G) ∣ (center G).index ^ ((center G).index * Nat.card (commutatorSet G) + 1) := by -- First handle the case when `Z(G)` has infinite index and `[G : Z(G)]` is defined to be `0` by_cases hG : (center G).index = 0 · simp_rw [hG, zero_mul, zero_add, pow_one, dvd_zero] haveI : FiniteIndex (center G) := ⟨hG⟩ -- Rewrite as `|Z(G) ∩ G'| * [G' : Z(G) ∩ G'] ∣ [G : Z(G)] ^ ([G : Z(G)] * n) * [G : Z(G)]` rw [← ((center G).subgroupOf (_root_.commutator G)).card_mul_index, pow_succ] -- We have `h1 : [G' : Z(G) ∩ G'] ∣ [G : Z(G)]` have h1 := relindex_dvd_index_of_normal (center G) (_root_.commutator G) -- So we can reduce to proving `|Z(G) ∩ G'| ∣ [G : Z(G)] ^ ([G : Z(G)] * n)` refine mul_dvd_mul ?_ h1 -- We know that `[G' : Z(G) ∩ G'] < ∞` by `h1` and `hG` haveI : FiniteIndex ((center G).subgroupOf (_root_.commutator G)) := ⟨ne_zero_of_dvd_ne_zero hG h1⟩ -- We have `h2 : rank (Z(G) ∩ G') ≤ [G' : Z(G) ∩ G'] * rank G'` by Schreier's lemma have h2 := rank_le_index_mul_rank ((center G).subgroupOf (_root_.commutator G)) -- We have `h3 : [G' : Z(G) ∩ G'] * rank G' ≤ [G : Z(G)] * n` by `h1` and `rank G' ≤ n` have h3 := Nat.mul_le_mul (Nat.le_of_dvd (Nat.pos_of_ne_zero hG) h1) (rank_commutator_le_card G) -- So we can reduce to proving `|Z(G) ∩ G'| ∣ [G : Z(G)] ^ rank (Z(G) ∩ G')` refine dvd_trans ?_ (pow_dvd_pow (center G).index (h2.trans h3)) -- `Z(G) ∩ G'` is abelian, so it enough to prove that `g ^ [G : Z(G)] = 1` for `g ∈ Z(G) ∩ G'` apply card_dvd_exponent_pow_rank' intro g -- `Z(G)` is abelian, so `g ∈ Z(G) ∩ G' ≤ G' ≤ ker (transfer : G → Z(G))` have := Abelianization.commutator_subset_ker (MonoidHom.transferCenterPow G) g.1.2 -- `transfer g` is defeq to `g ^ [G : Z(G)]`, so we are done simpa only [MonoidHom.mem_ker, Subtype.ext_iff] using this /-- A bound for the size of the commutator subgroup in terms of the number of commutators. -/ def cardCommutatorBound (n : ℕ) := (n ^ (2 * n)) ^ (n ^ (2 * n + 1) + 1) /-- A theorem of Schur: The size of the commutator subgroup is bounded in terms of the number of commutators. -/ theorem card_commutator_le_of_finite_commutatorSet [Finite (commutatorSet G)] : Nat.card (_root_.commutator G) ≤ cardCommutatorBound (Nat.card (commutatorSet G)) := by have h1 := index_center_le_pow (closureCommutatorRepresentatives G) have h2 := card_commutator_dvd_index_center_pow (closureCommutatorRepresentatives G) rw [card_commutatorSet_closureCommutatorRepresentatives] at h1 h2 rw [card_commutator_closureCommutatorRepresentatives] at h2 replace h1 := h1.trans (Nat.pow_le_pow_of_le_right Finite.card_pos (rank_closureCommutatorRepresentatives_le G)) replace h2 := h2.trans (pow_dvd_pow _ (add_le_add_right (mul_le_mul_right' h1 _) 1)) rw [← pow_succ] at h2 refine (Nat.le_of_dvd ?_ h2).trans (Nat.pow_le_pow_left h1 _) exact pow_pos (Nat.pos_of_ne_zero FiniteIndex.finiteIndex) _ /-- A theorem of Schur: A group with finitely many commutators has finite commutator subgroup. -/ instance [Finite (commutatorSet G)] : Finite (_root_.commutator G) := by have h2 := card_commutator_dvd_index_center_pow (closureCommutatorRepresentatives G) refine Nat.finite_of_card_ne_zero fun h => ?_ rw [card_commutator_closureCommutatorRepresentatives, h, zero_dvd_iff] at h2 exact FiniteIndex.finiteIndex (pow_eq_zero h2) end Subgroup
GroupTheory\SchurZassenhaus.lean
/- Copyright (c) 2021 Thomas Browning. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning -/ import Mathlib.GroupTheory.Transfer /-! # The Schur-Zassenhaus Theorem In this file we prove the Schur-Zassenhaus theorem. ## Main results - `exists_right_complement'_of_coprime`: The **Schur-Zassenhaus** theorem: If `H : Subgroup G` is normal and has order coprime to its index, then there exists a subgroup `K` which is a (right) complement of `H`. - `exists_left_complement'_of_coprime`: The **Schur-Zassenhaus** theorem: If `H : Subgroup G` is normal and has order coprime to its index, then there exists a subgroup `K` which is a (left) complement of `H`. -/ namespace Subgroup section SchurZassenhausAbelian open MulOpposite MulAction Subgroup.leftTransversals MemLeftTransversals variable {G : Type*} [Group G] (H : Subgroup G) [IsCommutative H] [FiniteIndex H] (α β : leftTransversals (H : Set G)) /-- The quotient of the transversals of an abelian normal `N` by the `diff` relation. -/ def QuotientDiff := Quotient (Setoid.mk (fun α β => diff (MonoidHom.id H) α β = 1) ⟨fun α => diff_self (MonoidHom.id H) α, fun h => by rw [← diff_inv, h, inv_one], fun h h' => by rw [← diff_mul_diff, h, h', one_mul]⟩) instance : Inhabited H.QuotientDiff := by dsimp [QuotientDiff] -- Porting note: Added `dsimp` infer_instance theorem smul_diff_smul' [hH : Normal H] (g : Gᵐᵒᵖ) : diff (MonoidHom.id H) (g • α) (g • β) = ⟨g.unop⁻¹ * (diff (MonoidHom.id H) α β : H) * g.unop, hH.mem_comm ((congr_arg (· ∈ H) (mul_inv_cancel_left _ _)).mpr (SetLike.coe_mem _))⟩ := by letI := H.fintypeQuotientOfFiniteIndex let ϕ : H →* H := { toFun := fun h => ⟨g.unop⁻¹ * h * g.unop, hH.mem_comm ((congr_arg (· ∈ H) (mul_inv_cancel_left _ _)).mpr (SetLike.coe_mem _))⟩ map_one' := by rw [Subtype.ext_iff, coe_mk, coe_one, mul_one, inv_mul_self] map_mul' := fun h₁ h₂ => by simp only [Subtype.ext_iff, coe_mk, coe_mul, mul_assoc, mul_inv_cancel_left] } refine (Fintype.prod_equiv (MulAction.toPerm g).symm _ _ fun x ↦ ?_).trans (map_prod ϕ _ _).symm simp only [ϕ, smul_apply_eq_smul_apply_inv_smul, smul_eq_mul_unop, mul_inv_rev, mul_assoc, MonoidHom.id_apply, toPerm_symm_apply, MonoidHom.coe_mk, OneHom.coe_mk] variable {H} variable [Normal H] noncomputable instance : MulAction G H.QuotientDiff where smul g := Quotient.map' (fun α => op g⁻¹ • α) fun α β h => Subtype.ext (by rwa [smul_diff_smul', coe_mk, coe_one, mul_eq_one_iff_eq_inv, mul_right_eq_self, ← coe_one, ← Subtype.ext_iff]) mul_smul g₁ g₂ q := Quotient.inductionOn' q fun T => congr_arg Quotient.mk'' (by rw [mul_inv_rev]; exact mul_smul (op g₁⁻¹) (op g₂⁻¹) T) one_smul q := Quotient.inductionOn' q fun T => congr_arg Quotient.mk'' (by rw [inv_one]; apply one_smul Gᵐᵒᵖ T) theorem smul_diff' (h : H) : diff (MonoidHom.id H) α (op (h : G) • β) = diff (MonoidHom.id H) α β * h ^ H.index := by letI := H.fintypeQuotientOfFiniteIndex rw [diff, diff, index_eq_card, Nat.card_eq_fintype_card, ← Finset.card_univ, ← Finset.prod_const, ← Finset.prod_mul_distrib] refine Finset.prod_congr rfl fun q _ => ?_ simp_rw [Subtype.ext_iff, MonoidHom.id_apply, coe_mul, mul_assoc, mul_right_inj] rw [smul_apply_eq_smul_apply_inv_smul, smul_eq_mul_unop, MulOpposite.unop_op, mul_left_inj, ← Subtype.ext_iff, Equiv.apply_eq_iff_eq, inv_smul_eq_iff] exact self_eq_mul_right.mpr ((QuotientGroup.eq_one_iff _).mpr h.2) theorem eq_one_of_smul_eq_one (hH : Nat.Coprime (Nat.card H) H.index) (α : H.QuotientDiff) (h : H) : h • α = α → h = 1 := Quotient.inductionOn' α fun α hα => (powCoprime hH).injective <| calc h ^ H.index = diff (MonoidHom.id H) (op ((h⁻¹ : H) : G) • α) α := by rw [← diff_inv, smul_diff', diff_self, one_mul, inv_pow, inv_inv] _ = 1 ^ H.index := (Quotient.exact' hα).trans (one_pow H.index).symm theorem exists_smul_eq (hH : Nat.Coprime (Nat.card H) H.index) (α β : H.QuotientDiff) : ∃ h : H, h • α = β := Quotient.inductionOn' α (Quotient.inductionOn' β fun β α => Exists.imp (fun n => Quotient.sound') ⟨(powCoprime hH).symm (diff (MonoidHom.id H) β α), (diff_inv _ _ _).symm.trans (inv_eq_one.mpr ((smul_diff' β α ((powCoprime hH).symm (diff (MonoidHom.id H) β α))⁻¹).trans (by rw [inv_pow, ← powCoprime_apply hH, Equiv.apply_symm_apply, mul_inv_self])))⟩) theorem isComplement'_stabilizer_of_coprime {α : H.QuotientDiff} (hH : Nat.Coprime (Nat.card H) H.index) : IsComplement' H (stabilizer G α) := isComplement'_stabilizer α (eq_one_of_smul_eq_one hH α) fun g => exists_smul_eq hH (g • α) α /-- Do not use this lemma: It is made obsolete by `exists_right_complement'_of_coprime` -/ private theorem exists_right_complement'_of_coprime_aux (hH : Nat.Coprime (Nat.card H) H.index) : ∃ K : Subgroup G, IsComplement' H K := have ne : Nonempty (QuotientDiff H) := inferInstance ne.elim fun α => ⟨stabilizer G α, isComplement'_stabilizer_of_coprime hH⟩ end SchurZassenhausAbelian open scoped Classical universe u namespace SchurZassenhausInduction /-! ## Proof of the Schur-Zassenhaus theorem In this section, we prove the Schur-Zassenhaus theorem. The proof is by contradiction. We assume that `G` is a minimal counterexample to the theorem. -/ variable {G : Type u} [Group G] [Finite G] {N : Subgroup G} [Normal N] (h1 : Nat.Coprime (Nat.card N) N.index) (h2 : ∀ (G' : Type u) [Group G'] [Finite G'], Nat.card G' < Nat.card G → ∀ {N' : Subgroup G'} [N'.Normal], Nat.Coprime (Nat.card N') N'.index → ∃ H' : Subgroup G', IsComplement' N' H') (h3 : ∀ H : Subgroup G, ¬IsComplement' N H) /-! We will arrive at a contradiction via the following steps: * step 0: `N` (the normal Hall subgroup) is nontrivial. * step 1: If `K` is a subgroup of `G` with `K ⊔ N = ⊤`, then `K = ⊤`. * step 2: `N` is a minimal normal subgroup, phrased in terms of subgroups of `G`. * step 3: `N` is a minimal normal subgroup, phrased in terms of subgroups of `N`. * step 4: `p` (`min_fact (Fintype.card N)`) is prime (follows from step0). * step 5: `P` (a Sylow `p`-subgroup of `N`) is nontrivial. * step 6: `N` is a `p`-group (applies step 1 to the normalizer of `P` in `G`). * step 7: `N` is abelian (applies step 3 to the center of `N`). -/ /-- Do not use this lemma: It is made obsolete by `exists_right_complement'_of_coprime` -/ private theorem step0 : N ≠ ⊥ := by rintro rfl exact h3 ⊤ isComplement'_bot_top /-- Do not use this lemma: It is made obsolete by `exists_right_complement'_of_coprime` -/ private theorem step1 (K : Subgroup G) (hK : K ⊔ N = ⊤) : K = ⊤ := by contrapose! h3 have h4 : (N.comap K.subtype).index = N.index := by rw [← N.relindex_top_right, ← hK] exact (relindex_sup_right K N).symm have h5 : Nat.card K < Nat.card G := by rw [← K.index_mul_card] exact lt_mul_of_one_lt_left Nat.card_pos (one_lt_index_of_ne_top h3) have h6 : Nat.Coprime (Nat.card (N.comap K.subtype)) (N.comap K.subtype).index := by rw [h4] exact h1.coprime_dvd_left (card_comap_dvd_of_injective N K.subtype Subtype.coe_injective) obtain ⟨H, hH⟩ := h2 K h5 h6 replace hH : Nat.card (H.map K.subtype) = N.index := by rw [← relindex_bot_left, ← relindex_comap, MonoidHom.comap_bot, Subgroup.ker_subtype, relindex_bot_left, ← IsComplement'.index_eq_card (IsComplement'.symm hH), index_comap, subtype_range, ← relindex_sup_right, hK, relindex_top_right] have h7 : Nat.card N * Nat.card (H.map K.subtype) = Nat.card G := by rw [hH, ← N.index_mul_card, mul_comm] have h8 : (Nat.card N).Coprime (Nat.card (H.map K.subtype)) := by rwa [hH] exact ⟨H.map K.subtype, isComplement'_of_coprime h7 h8⟩ /-- Do not use this lemma: It is made obsolete by `exists_right_complement'_of_coprime` -/ private theorem step2 (K : Subgroup G) [K.Normal] (hK : K ≤ N) : K = ⊥ ∨ K = N := by have : Function.Surjective (QuotientGroup.mk' K) := Quotient.surjective_Quotient_mk'' have h4 := step1 h1 h2 h3 contrapose! h4 have h5 : Nat.card (G ⧸ K) < Nat.card G := by rw [← index_eq_card, ← K.index_mul_card] refine lt_mul_of_one_lt_right (Nat.pos_of_ne_zero index_ne_zero_of_finite) (K.one_lt_card_iff_ne_bot.mpr h4.1) have h6 : (Nat.card (N.map (QuotientGroup.mk' K))).Coprime (N.map (QuotientGroup.mk' K)).index := by have index_map := N.index_map_eq this (by rwa [QuotientGroup.ker_mk']) have index_pos : 0 < N.index := Nat.pos_of_ne_zero index_ne_zero_of_finite rw [index_map] refine h1.coprime_dvd_left ?_ rw [← Nat.mul_dvd_mul_iff_left index_pos, index_mul_card, ← index_map, index_mul_card] exact K.card_quotient_dvd_card obtain ⟨H, hH⟩ := h2 (G ⧸ K) h5 h6 refine ⟨H.comap (QuotientGroup.mk' K), ?_, ?_⟩ · have key : (N.map (QuotientGroup.mk' K)).comap (QuotientGroup.mk' K) = N := by refine comap_map_eq_self ?_ rwa [QuotientGroup.ker_mk'] rwa [← key, comap_sup_eq, hH.symm.sup_eq_top, comap_top] · rw [← comap_top (QuotientGroup.mk' K)] intro hH' rw [comap_injective this hH', isComplement'_top_right, map_eq_bot_iff, QuotientGroup.ker_mk'] at hH exact h4.2 (le_antisymm hK hH) /-- Do not use this lemma: It is made obsolete by `exists_right_complement'_of_coprime` -/ private theorem step3 (K : Subgroup N) [(K.map N.subtype).Normal] : K = ⊥ ∨ K = ⊤ := by have key := step2 h1 h2 h3 (K.map N.subtype) (map_subtype_le K) rw [← map_bot N.subtype] at key conv at key => rhs rhs rw [← N.subtype_range, N.subtype.range_eq_map] have inj := map_injective N.subtype_injective rwa [inj.eq_iff, inj.eq_iff] at key /-- Do not use this lemma: It is made obsolete by `exists_right_complement'_of_coprime` -/ private theorem step4 : (Nat.card N).minFac.Prime := Nat.minFac_prime (N.one_lt_card_iff_ne_bot.mpr (step0 h1 h3)).ne' /-- Do not use this lemma: It is made obsolete by `exists_right_complement'_of_coprime` -/ private theorem step5 {P : Sylow (Nat.card N).minFac N} : P.1 ≠ ⊥ := by haveI : Fact (Nat.card N).minFac.Prime := ⟨step4 h1 h3⟩ apply P.ne_bot_of_dvd_card exact (Nat.card N).minFac_dvd /-- Do not use this lemma: It is made obsolete by `exists_right_complement'_of_coprime` -/ private theorem step6 : IsPGroup (Nat.card N).minFac N := by haveI : Fact (Nat.card N).minFac.Prime := ⟨step4 h1 h3⟩ refine Sylow.nonempty.elim fun P => P.2.of_surjective P.1.subtype ?_ rw [← MonoidHom.range_top_iff_surjective, subtype_range] haveI : (P.1.map N.subtype).Normal := normalizer_eq_top.mp (step1 h1 h2 h3 (P.1.map N.subtype).normalizer P.normalizer_sup_eq_top) exact (step3 h1 h2 h3 P.1).resolve_left (step5 h1 h3) /-- Do not use this lemma: It is made obsolete by `exists_right_complement'_of_coprime` -/ theorem step7 : IsCommutative N := by haveI := N.bot_or_nontrivial.resolve_left (step0 h1 h3) haveI : Fact (Nat.card N).minFac.Prime := ⟨step4 h1 h3⟩ exact ⟨⟨fun g h => ((eq_top_iff.mp ((step3 h1 h2 h3 (center N)).resolve_left (step6 h1 h2 h3).bot_lt_center.ne') (mem_top h)).comm g).symm⟩⟩ end SchurZassenhausInduction variable {n : ℕ} {G : Type u} [Group G] /-- Do not use this lemma: It is made obsolete by `exists_right_complement'_of_coprime` -/ private theorem exists_right_complement'_of_coprime_aux' [Finite G] (hG : Nat.card G = n) {N : Subgroup G} [N.Normal] (hN : Nat.Coprime (Nat.card N) N.index) : ∃ H : Subgroup G, IsComplement' N H := by revert G apply Nat.strongInductionOn n rintro n ih G _ _ rfl N _ hN refine not_forall_not.mp fun h3 => ?_ haveI := SchurZassenhausInduction.step7 hN (fun G' _ _ hG' => by apply ih _ hG'; rfl) h3 exact not_exists_of_forall_not h3 (exists_right_complement'_of_coprime_aux hN) /-- **Schur-Zassenhaus** for normal subgroups: If `H : Subgroup G` is normal, and has order coprime to its index, then there exists a subgroup `K` which is a (right) complement of `H`. -/ theorem exists_right_complement'_of_coprime {N : Subgroup G} [N.Normal] (hN : Nat.Coprime (Nat.card N) N.index) : ∃ H : Subgroup G, IsComplement' N H := by by_cases hN1 : Nat.card N = 0 · rw [hN1, Nat.coprime_zero_left, index_eq_one] at hN rw [hN] exact ⟨⊥, isComplement'_top_bot⟩ by_cases hN2 : N.index = 0 · rw [hN2, Nat.coprime_zero_right] at hN haveI := (Cardinal.toNat_eq_one_iff_unique.mp hN).1 rw [N.eq_bot_of_subsingleton] exact ⟨⊤, isComplement'_bot_top⟩ have hN3 : Nat.card G ≠ 0 := by rw [← N.card_mul_index] exact mul_ne_zero hN1 hN2 haveI := (Cardinal.lt_aleph0_iff_fintype.mp (lt_of_not_ge (mt Cardinal.toNat_apply_of_aleph0_le hN3))).some exact exists_right_complement'_of_coprime_aux' rfl hN /-- **Schur-Zassenhaus** for normal subgroups: If `H : Subgroup G` is normal, and has order coprime to its index, then there exists a subgroup `K` which is a (left) complement of `H`. -/ theorem exists_left_complement'_of_coprime {N : Subgroup G} [N.Normal] (hN : Nat.Coprime (Nat.card N) N.index) : ∃ H : Subgroup G, IsComplement' H N := Exists.imp (fun _ => IsComplement'.symm) (exists_right_complement'_of_coprime hN) end Subgroup
GroupTheory\SemidirectProduct.lean
/- Copyright (c) 2020 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Algebra.Group.Subgroup.Basic /-! # Semidirect product This file defines semidirect products of groups, and the canonical maps in and out of the semidirect product. The semidirect product of `N` and `G` given a hom `φ` from `G` to the automorphism group of `N` is the product of sets with the group `⟨n₁, g₁⟩ * ⟨n₂, g₂⟩ = ⟨n₁ * φ g₁ n₂, g₁ * g₂⟩` ## Key definitions There are two homs into the semidirect product `inl : N →* N ⋊[φ] G` and `inr : G →* N ⋊[φ] G`, and `lift` can be used to define maps `N ⋊[φ] G →* H` out of the semidirect product given maps `f₁ : N →* H` and `f₂ : G →* H` that satisfy the condition `∀ n g, f₁ (φ g n) = f₂ g * f₁ n * f₂ g⁻¹` ## Notation This file introduces the global notation `N ⋊[φ] G` for `SemidirectProduct N G φ` ## Tags group, semidirect product -/ variable (N : Type*) (G : Type*) {H : Type*} [Group N] [Group G] [Group H] /-- The semidirect product of groups `N` and `G`, given a map `φ` from `G` to the automorphism group of `N`. It the product of sets with the group operation `⟨n₁, g₁⟩ * ⟨n₂, g₂⟩ = ⟨n₁ * φ g₁ n₂, g₁ * g₂⟩` -/ @[ext] structure SemidirectProduct (φ : G →* MulAut N) where /-- The element of N -/ left : N /-- The element of G -/ right : G deriving DecidableEq -- Porting note: these lemmas are autogenerated by the inductive definition and are not -- in simple form due to the existence of mk_eq_inl_mul_inr attribute [nolint simpNF] SemidirectProduct.mk.injEq attribute [nolint simpNF] SemidirectProduct.mk.sizeOf_spec -- Porting note: unknown attribute -- attribute [pp_using_anonymous_constructor] SemidirectProduct @[inherit_doc] notation:35 N " ⋊[" φ:35 "] " G:35 => SemidirectProduct N G φ namespace SemidirectProduct variable {N G} variable {φ : G →* MulAut N} instance : Mul (SemidirectProduct N G φ) where mul a b := ⟨a.1 * φ a.2 b.1, a.2 * b.2⟩ lemma mul_def (a b : SemidirectProduct N G φ) : a * b = ⟨a.1 * φ a.2 b.1, a.2 * b.2⟩ := rfl @[simp] theorem mul_left (a b : N ⋊[φ] G) : (a * b).left = a.left * φ a.right b.left := rfl @[simp] theorem mul_right (a b : N ⋊[φ] G) : (a * b).right = a.right * b.right := rfl instance : One (SemidirectProduct N G φ) where one := ⟨1, 1⟩ @[simp] theorem one_left : (1 : N ⋊[φ] G).left = 1 := rfl @[simp] theorem one_right : (1 : N ⋊[φ] G).right = 1 := rfl instance : Inv (SemidirectProduct N G φ) where inv x := ⟨φ x.2⁻¹ x.1⁻¹, x.2⁻¹⟩ @[simp] theorem inv_left (a : N ⋊[φ] G) : a⁻¹.left = φ a.right⁻¹ a.left⁻¹ := rfl @[simp] theorem inv_right (a : N ⋊[φ] G) : a⁻¹.right = a.right⁻¹ := rfl instance : Group (N ⋊[φ] G) where mul_assoc a b c := SemidirectProduct.ext (by simp [mul_assoc]) (by simp [mul_assoc]) one_mul a := SemidirectProduct.ext (by simp) (one_mul a.2) mul_one a := SemidirectProduct.ext (by simp) (mul_one _) mul_left_inv a := SemidirectProduct.ext (by simp) (by simp) instance : Inhabited (N ⋊[φ] G) := ⟨1⟩ /-- The canonical map `N →* N ⋊[φ] G` sending `n` to `⟨n, 1⟩` -/ def inl : N →* N ⋊[φ] G where toFun n := ⟨n, 1⟩ map_one' := rfl map_mul' := by intros; ext <;> simp only [mul_left, map_one, MulAut.one_apply, mul_right, mul_one] @[simp] theorem left_inl (n : N) : (inl n : N ⋊[φ] G).left = n := rfl @[simp] theorem right_inl (n : N) : (inl n : N ⋊[φ] G).right = 1 := rfl theorem inl_injective : Function.Injective (inl : N → N ⋊[φ] G) := Function.injective_iff_hasLeftInverse.2 ⟨left, left_inl⟩ @[simp] theorem inl_inj {n₁ n₂ : N} : (inl n₁ : N ⋊[φ] G) = inl n₂ ↔ n₁ = n₂ := inl_injective.eq_iff /-- The canonical map `G →* N ⋊[φ] G` sending `g` to `⟨1, g⟩` -/ def inr : G →* N ⋊[φ] G where toFun g := ⟨1, g⟩ map_one' := rfl map_mul' := by intros; ext <;> simp @[simp] theorem left_inr (g : G) : (inr g : N ⋊[φ] G).left = 1 := rfl @[simp] theorem right_inr (g : G) : (inr g : N ⋊[φ] G).right = g := rfl theorem inr_injective : Function.Injective (inr : G → N ⋊[φ] G) := Function.injective_iff_hasLeftInverse.2 ⟨right, right_inr⟩ @[simp] theorem inr_inj {g₁ g₂ : G} : (inr g₁ : N ⋊[φ] G) = inr g₂ ↔ g₁ = g₂ := inr_injective.eq_iff theorem inl_aut (g : G) (n : N) : (inl (φ g n) : N ⋊[φ] G) = inr g * inl n * inr g⁻¹ := by ext <;> simp theorem inl_aut_inv (g : G) (n : N) : (inl ((φ g)⁻¹ n) : N ⋊[φ] G) = inr g⁻¹ * inl n * inr g := by rw [← MonoidHom.map_inv, inl_aut, inv_inv] @[simp] theorem mk_eq_inl_mul_inr (g : G) (n : N) : (⟨n, g⟩ : N ⋊[φ] G) = inl n * inr g := by ext <;> simp @[simp] theorem inl_left_mul_inr_right (x : N ⋊[φ] G) : inl x.left * inr x.right = x := by ext <;> simp /-- The canonical projection map `N ⋊[φ] G →* G`, as a group hom. -/ def rightHom : N ⋊[φ] G →* G where toFun := SemidirectProduct.right map_one' := rfl map_mul' _ _ := rfl @[simp] theorem rightHom_eq_right : (rightHom : N ⋊[φ] G → G) = right := rfl @[simp] theorem rightHom_comp_inl : (rightHom : N ⋊[φ] G →* G).comp inl = 1 := by ext; simp [rightHom] @[simp] theorem rightHom_comp_inr : (rightHom : N ⋊[φ] G →* G).comp inr = MonoidHom.id _ := by ext; simp [rightHom] @[simp] theorem rightHom_inl (n : N) : rightHom (inl n : N ⋊[φ] G) = 1 := by simp [rightHom] @[simp] theorem rightHom_inr (g : G) : rightHom (inr g : N ⋊[φ] G) = g := by simp [rightHom] theorem rightHom_surjective : Function.Surjective (rightHom : N ⋊[φ] G → G) := Function.surjective_iff_hasRightInverse.2 ⟨inr, rightHom_inr⟩ theorem range_inl_eq_ker_rightHom : (inl : N →* N ⋊[φ] G).range = rightHom.ker := le_antisymm (fun _ ↦ by simp (config := { contextual := true }) [MonoidHom.mem_ker, eq_comm]) fun x hx ↦ ⟨x.left, by ext <;> simp_all [MonoidHom.mem_ker]⟩ section lift variable (f₁ : N →* H) (f₂ : G →* H) (h : ∀ g, f₁.comp (φ g).toMonoidHom = (MulAut.conj (f₂ g)).toMonoidHom.comp f₁) /-- Define a group hom `N ⋊[φ] G →* H`, by defining maps `N →* H` and `G →* H` -/ def lift (f₁ : N →* H) (f₂ : G →* H) (h : ∀ g, f₁.comp (φ g).toMonoidHom = (MulAut.conj (f₂ g)).toMonoidHom.comp f₁) : N ⋊[φ] G →* H where toFun a := f₁ a.1 * f₂ a.2 map_one' := by simp map_mul' a b := by have := fun n g ↦ DFunLike.ext_iff.1 (h n) g simp only [MulAut.conj_apply, MonoidHom.comp_apply, MulEquiv.coe_toMonoidHom] at this simp only [mul_left, mul_right, map_mul, this, mul_assoc, inv_mul_cancel_left] @[simp] theorem lift_inl (n : N) : lift f₁ f₂ h (inl n) = f₁ n := by simp [lift] @[simp] theorem lift_comp_inl : (lift f₁ f₂ h).comp inl = f₁ := by ext; simp @[simp] theorem lift_inr (g : G) : lift f₁ f₂ h (inr g) = f₂ g := by simp [lift] @[simp] theorem lift_comp_inr : (lift f₁ f₂ h).comp inr = f₂ := by ext; simp theorem lift_unique (F : N ⋊[φ] G →* H) : F = lift (F.comp inl) (F.comp inr) fun _ ↦ by ext; simp [inl_aut] := by rw [DFunLike.ext_iff] simp only [lift, MonoidHom.comp_apply, MonoidHom.coe_mk, OneHom.coe_mk, ← map_mul, inl_left_mul_inr_right, forall_const] /-- Two maps out of the semidirect product are equal if they're equal after composition with both `inl` and `inr` -/ theorem hom_ext {f g : N ⋊[φ] G →* H} (hl : f.comp inl = g.comp inl) (hr : f.comp inr = g.comp inr) : f = g := by rw [lift_unique f, lift_unique g] simp only [*] end lift section Map variable {N₁ : Type*} {G₁ : Type*} [Group N₁] [Group G₁] {φ₁ : G₁ →* MulAut N₁} /-- Define a map from `N ⋊[φ] G` to `N₁ ⋊[φ₁] G₁` given maps `N →* N₁` and `G →* G₁` that satisfy a commutativity condition `∀ n g, f₁ (φ g n) = φ₁ (f₂ g) (f₁ n)`. -/ def map (f₁ : N →* N₁) (f₂ : G →* G₁) (h : ∀ g : G, f₁.comp (φ g).toMonoidHom = (φ₁ (f₂ g)).toMonoidHom.comp f₁) : N ⋊[φ] G →* N₁ ⋊[φ₁] G₁ where toFun x := ⟨f₁ x.1, f₂ x.2⟩ map_one' := by simp map_mul' x y := by replace h := DFunLike.ext_iff.1 (h x.right) y.left ext <;> simp_all variable (f₁ : N →* N₁) (f₂ : G →* G₁) (h : ∀ g : G, f₁.comp (φ g).toMonoidHom = (φ₁ (f₂ g)).toMonoidHom.comp f₁) @[simp] theorem map_left (g : N ⋊[φ] G) : (map f₁ f₂ h g).left = f₁ g.left := rfl @[simp] theorem map_right (g : N ⋊[φ] G) : (map f₁ f₂ h g).right = f₂ g.right := rfl @[simp] theorem rightHom_comp_map : rightHom.comp (map f₁ f₂ h) = f₂.comp rightHom := rfl @[simp] theorem map_inl (n : N) : map f₁ f₂ h (inl n) = inl (f₁ n) := by simp [map] @[simp] theorem map_comp_inl : (map f₁ f₂ h).comp inl = inl.comp f₁ := by ext <;> simp @[simp] theorem map_inr (g : G) : map f₁ f₂ h (inr g) = inr (f₂ g) := by simp [map] @[simp] theorem map_comp_inr : (map f₁ f₂ h).comp inr = inr.comp f₂ := by ext <;> simp [map] end Map end SemidirectProduct
GroupTheory\Solvable.lean
/- Copyright (c) 2021 Jordan Brown, Thomas Browning, Patrick Lutz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jordan Brown, Thomas Browning, Patrick Lutz -/ import Mathlib.GroupTheory.Abelianization import Mathlib.GroupTheory.Perm.ViaEmbedding import Mathlib.GroupTheory.Subgroup.Simple /-! # Solvable Groups In this file we introduce the notion of a solvable group. We define a solvable group as one whose derived series is eventually trivial. This requires defining the commutator of two subgroups and the derived series of a group. ## Main definitions * `derivedSeries G n` : the `n`th term in the derived series of `G`, defined by iterating `general_commutator` starting with the top subgroup * `IsSolvable G` : the group `G` is solvable -/ open Subgroup variable {G G' : Type*} [Group G] [Group G'] {f : G →* G'} section derivedSeries variable (G) /-- The derived series of the group `G`, obtained by starting from the subgroup `⊤` and repeatedly taking the commutator of the previous subgroup with itself for `n` times. -/ def derivedSeries : ℕ → Subgroup G | 0 => ⊤ | n + 1 => ⁅derivedSeries n, derivedSeries n⁆ @[simp] theorem derivedSeries_zero : derivedSeries G 0 = ⊤ := rfl @[simp] theorem derivedSeries_succ (n : ℕ) : derivedSeries G (n + 1) = ⁅derivedSeries G n, derivedSeries G n⁆ := rfl -- Porting note: had to provide inductive hypothesis explicitly theorem derivedSeries_normal (n : ℕ) : (derivedSeries G n).Normal := by induction' n with n ih · exact (⊤ : Subgroup G).normal_of_characteristic · exact @Subgroup.commutator_normal G _ (derivedSeries G n) (derivedSeries G n) ih ih -- Porting note: higher simp priority to restore Lean 3 behavior @[simp 1100] theorem derivedSeries_one : derivedSeries G 1 = commutator G := rfl end derivedSeries section CommutatorMap section DerivedSeriesMap variable (f) theorem map_derivedSeries_le_derivedSeries (n : ℕ) : (derivedSeries G n).map f ≤ derivedSeries G' n := by induction' n with n ih · exact le_top · simp only [derivedSeries_succ, map_commutator, commutator_mono, ih] variable {f} theorem derivedSeries_le_map_derivedSeries (hf : Function.Surjective f) (n : ℕ) : derivedSeries G' n ≤ (derivedSeries G n).map f := by induction' n with n ih · exact (map_top_of_surjective f hf).ge · exact commutator_le_map_commutator ih ih theorem map_derivedSeries_eq (hf : Function.Surjective f) (n : ℕ) : (derivedSeries G n).map f = derivedSeries G' n := le_antisymm (map_derivedSeries_le_derivedSeries f n) (derivedSeries_le_map_derivedSeries hf n) end DerivedSeriesMap end CommutatorMap section Solvable variable (G) /-- A group `G` is solvable if its derived series is eventually trivial. We use this definition because it's the most convenient one to work with. -/ @[mk_iff isSolvable_def] class IsSolvable : Prop where /-- A group `G` is solvable if its derived series is eventually trivial. -/ solvable : ∃ n : ℕ, derivedSeries G n = ⊥ instance (priority := 100) CommGroup.isSolvable {G : Type*} [CommGroup G] : IsSolvable G := ⟨⟨1, le_bot_iff.mp (Abelianization.commutator_subset_ker (MonoidHom.id G))⟩⟩ theorem isSolvable_of_comm {G : Type*} [hG : Group G] (h : ∀ a b : G, a * b = b * a) : IsSolvable G := by letI hG' : CommGroup G := { hG with mul_comm := h } cases hG exact CommGroup.isSolvable theorem isSolvable_of_top_eq_bot (h : (⊤ : Subgroup G) = ⊥) : IsSolvable G := ⟨⟨0, h⟩⟩ instance (priority := 100) isSolvable_of_subsingleton [Subsingleton G] : IsSolvable G := isSolvable_of_top_eq_bot G (by simp [eq_iff_true_of_subsingleton]) variable {G} theorem solvable_of_ker_le_range {G' G'' : Type*} [Group G'] [Group G''] (f : G' →* G) (g : G →* G'') (hfg : g.ker ≤ f.range) [hG' : IsSolvable G'] [hG'' : IsSolvable G''] : IsSolvable G := by obtain ⟨n, hn⟩ := id hG'' obtain ⟨m, hm⟩ := id hG' refine ⟨⟨n + m, le_bot_iff.mp (Subgroup.map_bot f ▸ hm ▸ ?_)⟩⟩ clear hm induction' m with m hm · exact f.range_eq_map ▸ ((derivedSeries G n).map_eq_bot_iff.mp (le_bot_iff.mp ((map_derivedSeries_le_derivedSeries g n).trans hn.le))).trans hfg · exact commutator_le_map_commutator hm hm theorem solvable_of_solvable_injective (hf : Function.Injective f) [IsSolvable G'] : IsSolvable G := solvable_of_ker_le_range (1 : G' →* G) f ((f.ker_eq_bot_iff.mpr hf).symm ▸ bot_le) instance subgroup_solvable_of_solvable (H : Subgroup G) [IsSolvable G] : IsSolvable H := solvable_of_solvable_injective H.subtype_injective theorem solvable_of_surjective (hf : Function.Surjective f) [IsSolvable G] : IsSolvable G' := solvable_of_ker_le_range f (1 : G' →* G) ((f.range_top_of_surjective hf).symm ▸ le_top) instance solvable_quotient_of_solvable (H : Subgroup G) [H.Normal] [IsSolvable G] : IsSolvable (G ⧸ H) := solvable_of_surjective (QuotientGroup.mk'_surjective H) instance solvable_prod {G' : Type*} [Group G'] [IsSolvable G] [IsSolvable G'] : IsSolvable (G × G') := solvable_of_ker_le_range (MonoidHom.inl G G') (MonoidHom.snd G G') fun x hx => ⟨x.1, Prod.ext rfl hx.symm⟩ end Solvable section IsSimpleGroup variable [IsSimpleGroup G] theorem IsSimpleGroup.derivedSeries_succ {n : ℕ} : derivedSeries G n.succ = commutator G := by induction' n with n ih · exact derivedSeries_one G rw [_root_.derivedSeries_succ, ih, _root_.commutator] cases' (commutator_normal (⊤ : Subgroup G) (⊤ : Subgroup G)).eq_bot_or_eq_top with h h · rw [h, commutator_bot_left] · rwa [h] theorem IsSimpleGroup.comm_iff_isSolvable : (∀ a b : G, a * b = b * a) ↔ IsSolvable G := ⟨isSolvable_of_comm, fun ⟨⟨n, hn⟩⟩ => by cases n · intro a b refine (mem_bot.1 ?_).trans (mem_bot.1 ?_).symm <;> · rw [← hn] exact mem_top _ · rw [IsSimpleGroup.derivedSeries_succ] at hn intro a b rw [← mul_inv_eq_one, mul_inv_rev, ← mul_assoc, ← mem_bot, ← hn, commutator_eq_closure] exact subset_closure ⟨a, b, rfl⟩⟩ end IsSimpleGroup section PermNotSolvable theorem not_solvable_of_mem_derivedSeries {g : G} (h1 : g ≠ 1) (h2 : ∀ n : ℕ, g ∈ derivedSeries G n) : ¬IsSolvable G := mt (isSolvable_def _).mp (not_exists_of_forall_not fun n h => h1 (Subgroup.mem_bot.mp ((congr_arg (Membership.mem g) h).mp (h2 n)))) theorem Equiv.Perm.fin_5_not_solvable : ¬IsSolvable (Equiv.Perm (Fin 5)) := by let x : Equiv.Perm (Fin 5) := ⟨![1, 2, 0, 3, 4], ![2, 0, 1, 3, 4], by decide, by decide⟩ let y : Equiv.Perm (Fin 5) := ⟨![3, 4, 2, 0, 1], ![3, 4, 2, 0, 1], by decide, by decide⟩ let z : Equiv.Perm (Fin 5) := ⟨![0, 3, 2, 1, 4], ![0, 3, 2, 1, 4], by decide, by decide⟩ have key : x = z * ⁅x, y * x * y⁻¹⁆ * z⁻¹ := by unfold_let; decide refine not_solvable_of_mem_derivedSeries (show x ≠ 1 by decide) fun n => ?_ induction' n with n ih · exact mem_top x · rw [key, (derivedSeries_normal _ _).mem_comm_iff, inv_mul_cancel_left] exact commutator_mem_commutator ih ((derivedSeries_normal _ _).conj_mem _ ih _) theorem Equiv.Perm.not_solvable (X : Type*) (hX : 5 ≤ Cardinal.mk X) : ¬IsSolvable (Equiv.Perm X) := by intro h have key : Nonempty (Fin 5 ↪ X) := by rwa [← Cardinal.lift_mk_le, Cardinal.mk_fin, Cardinal.lift_natCast, Cardinal.lift_id] exact Equiv.Perm.fin_5_not_solvable (solvable_of_solvable_injective (Equiv.Perm.viaEmbeddingHom_injective (Nonempty.some key))) end PermNotSolvable
GroupTheory\Sylow.lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Thomas Browning -/ import Mathlib.Data.SetLike.Fintype import Mathlib.GroupTheory.PGroup import Mathlib.GroupTheory.NoncommPiCoprod /-! # Sylow theorems The Sylow theorems are the following results for every finite group `G` and every prime number `p`. * There exists a Sylow `p`-subgroup of `G`. * All Sylow `p`-subgroups of `G` are conjugate to each other. * Let `nₚ` be the number of Sylow `p`-subgroups of `G`, then `nₚ` divides the index of the Sylow `p`-subgroup, `nₚ ≡ 1 [MOD p]`, and `nₚ` is equal to the index of the normalizer of the Sylow `p`-subgroup in `G`. ## Main definitions * `Sylow p G` : The type of Sylow `p`-subgroups of `G`. ## Main statements * `exists_subgroup_card_pow_prime`: A generalization of Sylow's first theorem: For every prime power `pⁿ` dividing the cardinality of `G`, there exists a subgroup of `G` of order `pⁿ`. * `IsPGroup.exists_le_sylow`: A generalization of Sylow's first theorem: Every `p`-subgroup is contained in a Sylow `p`-subgroup. * `Sylow.card_eq_multiplicity`: The cardinality of a Sylow subgroup is `p ^ n` where `n` is the multiplicity of `p` in the group order. * `sylow_conjugate`: A generalization of Sylow's second theorem: If the number of Sylow `p`-subgroups is finite, then all Sylow `p`-subgroups are conjugate. * `card_sylow_modEq_one`: A generalization of Sylow's third theorem: If the number of Sylow `p`-subgroups is finite, then it is congruent to `1` modulo `p`. -/ open MulAction Subgroup section InfiniteSylow variable (p : ℕ) (G : Type*) [Group G] /-- A Sylow `p`-subgroup is a maximal `p`-subgroup. -/ structure Sylow extends Subgroup G where isPGroup' : IsPGroup p toSubgroup is_maximal' : ∀ {Q : Subgroup G}, IsPGroup p Q → toSubgroup ≤ Q → Q = toSubgroup variable {p} {G} namespace Sylow attribute [coe] Sylow.toSubgroup -- Porting note: Changed to `CoeOut` instance : CoeOut (Sylow p G) (Subgroup G) := ⟨Sylow.toSubgroup⟩ -- Porting note: syntactic tautology -- @[simp] -- theorem toSubgroup_eq_coe {P : Sylow p G} : P.toSubgroup = ↑P := -- rfl @[ext] theorem ext {P Q : Sylow p G} (h : (P : Subgroup G) = Q) : P = Q := by cases P; cases Q; congr instance : SetLike (Sylow p G) G where coe := (↑) coe_injective' _ _ h := ext (SetLike.coe_injective h) instance : SubgroupClass (Sylow p G) G where mul_mem := Subgroup.mul_mem _ one_mem _ := Subgroup.one_mem _ inv_mem := Subgroup.inv_mem _ variable (P : Sylow p G) /-- The action by a Sylow subgroup is the action by the underlying group. -/ instance mulActionLeft {α : Type*} [MulAction G α] : MulAction P α := inferInstanceAs (MulAction (P : Subgroup G) α) variable {K : Type*} [Group K] (ϕ : K →* G) {N : Subgroup G} /-- The preimage of a Sylow subgroup under a p-group-kernel homomorphism is a Sylow subgroup. -/ def comapOfKerIsPGroup (hϕ : IsPGroup p ϕ.ker) (h : ↑P ≤ ϕ.range) : Sylow p K := { P.1.comap ϕ with isPGroup' := P.2.comap_of_ker_isPGroup ϕ hϕ is_maximal' := fun {Q} hQ hle => by show Q = P.1.comap ϕ rw [← P.3 (hQ.map ϕ) (le_trans (ge_of_eq (map_comap_eq_self h)) (map_mono hle))] exact (comap_map_eq_self ((P.1.ker_le_comap ϕ).trans hle)).symm } @[simp] theorem coe_comapOfKerIsPGroup (hϕ : IsPGroup p ϕ.ker) (h : ↑P ≤ ϕ.range) : (P.comapOfKerIsPGroup ϕ hϕ h : Subgroup K) = Subgroup.comap ϕ ↑P := rfl /-- The preimage of a Sylow subgroup under an injective homomorphism is a Sylow subgroup. -/ def comapOfInjective (hϕ : Function.Injective ϕ) (h : ↑P ≤ ϕ.range) : Sylow p K := P.comapOfKerIsPGroup ϕ (IsPGroup.ker_isPGroup_of_injective hϕ) h @[simp] theorem coe_comapOfInjective (hϕ : Function.Injective ϕ) (h : ↑P ≤ ϕ.range) : ↑(P.comapOfInjective ϕ hϕ h) = Subgroup.comap ϕ ↑P := rfl /-- A sylow subgroup of G is also a sylow subgroup of a subgroup of G. -/ protected def subtype (h : ↑P ≤ N) : Sylow p N := P.comapOfInjective N.subtype Subtype.coe_injective (by rwa [subtype_range]) @[simp] theorem coe_subtype (h : ↑P ≤ N) : ↑(P.subtype h) = subgroupOf (↑P) N := rfl theorem subtype_injective {P Q : Sylow p G} {hP : ↑P ≤ N} {hQ : ↑Q ≤ N} (h : P.subtype hP = Q.subtype hQ) : P = Q := by rw [SetLike.ext_iff] at h ⊢ exact fun g => ⟨fun hg => (h ⟨g, hP hg⟩).mp hg, fun hg => (h ⟨g, hQ hg⟩).mpr hg⟩ end Sylow /-- A generalization of **Sylow's first theorem**. Every `p`-subgroup is contained in a Sylow `p`-subgroup. -/ theorem IsPGroup.exists_le_sylow {P : Subgroup G} (hP : IsPGroup p P) : ∃ Q : Sylow p G, P ≤ Q := Exists.elim (zorn_nonempty_partialOrder₀ { Q : Subgroup G | IsPGroup p Q } (fun c hc1 hc2 Q hQ => ⟨{ carrier := ⋃ R : c, R one_mem' := ⟨Q, ⟨⟨Q, hQ⟩, rfl⟩, Q.one_mem⟩ inv_mem' := fun {g} ⟨_, ⟨R, rfl⟩, hg⟩ => ⟨R, ⟨R, rfl⟩, R.1.inv_mem hg⟩ mul_mem' := fun {g} h ⟨_, ⟨R, rfl⟩, hg⟩ ⟨_, ⟨S, rfl⟩, hh⟩ => (hc2.total R.2 S.2).elim (fun T => ⟨S, ⟨S, rfl⟩, S.1.mul_mem (T hg) hh⟩) fun T => ⟨R, ⟨R, rfl⟩, R.1.mul_mem hg (T hh)⟩ }, fun ⟨g, _, ⟨S, rfl⟩, hg⟩ => by refine Exists.imp (fun k hk => ?_) (hc1 S.2 ⟨g, hg⟩) rwa [Subtype.ext_iff, coe_pow] at hk ⊢, fun M hM g hg => ⟨M, ⟨⟨M, hM⟩, rfl⟩, hg⟩⟩) P hP) fun {Q} ⟨hQ1, hQ2, hQ3⟩ => ⟨⟨Q, hQ1, hQ3 _⟩, hQ2⟩ instance Sylow.nonempty : Nonempty (Sylow p G) := nonempty_of_exists IsPGroup.of_bot.exists_le_sylow noncomputable instance Sylow.inhabited : Inhabited (Sylow p G) := Classical.inhabited_of_nonempty Sylow.nonempty theorem Sylow.exists_comap_eq_of_ker_isPGroup {H : Type*} [Group H] (P : Sylow p H) {f : H →* G} (hf : IsPGroup p f.ker) : ∃ Q : Sylow p G, (Q : Subgroup G).comap f = P := Exists.imp (fun Q hQ => P.3 (Q.2.comap_of_ker_isPGroup f hf) (map_le_iff_le_comap.mp hQ)) (P.2.map f).exists_le_sylow theorem Sylow.exists_comap_eq_of_injective {H : Type*} [Group H] (P : Sylow p H) {f : H →* G} (hf : Function.Injective f) : ∃ Q : Sylow p G, (Q : Subgroup G).comap f = P := P.exists_comap_eq_of_ker_isPGroup (IsPGroup.ker_isPGroup_of_injective hf) theorem Sylow.exists_comap_subtype_eq {H : Subgroup G} (P : Sylow p H) : ∃ Q : Sylow p G, (Q : Subgroup G).comap H.subtype = P := P.exists_comap_eq_of_injective Subtype.coe_injective /-- If the kernel of `f : H →* G` is a `p`-group, then `Finite (Sylow p G)` implies `Finite (Sylow p H)`. -/ theorem Sylow.finite_of_ker_is_pGroup {H : Type*} [Group H] {f : H →* G} (hf : IsPGroup p f.ker) [Finite (Sylow p G)] : Finite (Sylow p H) := let h_exists := fun P : Sylow p H => P.exists_comap_eq_of_ker_isPGroup hf let g : Sylow p H → Sylow p G := fun P => Classical.choose (h_exists P) have hg : ∀ P : Sylow p H, (g P).1.comap f = P := fun P => Classical.choose_spec (h_exists P) Finite.of_injective g fun P Q h => Sylow.ext (by rw [← hg, h]; exact (h_exists Q).choose_spec) /-- If `f : H →* G` is injective, then `Finite (Sylow p G)` implies `Finite (Sylow p H)`. -/ theorem Sylow.finite_of_injective {H : Type*} [Group H] {f : H →* G} (hf : Function.Injective f) [Finite (Sylow p G)] : Finite (Sylow p H) := Sylow.finite_of_ker_is_pGroup (IsPGroup.ker_isPGroup_of_injective hf) /-- If `H` is a subgroup of `G`, then `Finite (Sylow p G)` implies `Finite (Sylow p H)`. -/ instance (H : Subgroup G) [Finite (Sylow p G)] : Finite (Sylow p H) := Sylow.finite_of_injective H.subtype_injective open Pointwise /-- `Subgroup.pointwiseMulAction` preserves Sylow subgroups. -/ instance Sylow.pointwiseMulAction {α : Type*} [Group α] [MulDistribMulAction α G] : MulAction α (Sylow p G) where smul g P := ⟨(g • P.toSubgroup : Subgroup G), P.2.map _, fun {Q} hQ hS => inv_smul_eq_iff.mp (P.3 (hQ.map _) fun s hs => (congr_arg (· ∈ g⁻¹ • Q) (inv_smul_smul g s)).mp (smul_mem_pointwise_smul (g • s) g⁻¹ Q (hS (smul_mem_pointwise_smul s g P hs))))⟩ one_smul P := Sylow.ext (one_smul α P.toSubgroup) mul_smul g h P := Sylow.ext (mul_smul g h P.toSubgroup) theorem Sylow.pointwise_smul_def {α : Type*} [Group α] [MulDistribMulAction α G] {g : α} {P : Sylow p G} : ↑(g • P) = g • (P : Subgroup G) := rfl instance Sylow.mulAction : MulAction G (Sylow p G) := compHom _ MulAut.conj theorem Sylow.smul_def {g : G} {P : Sylow p G} : g • P = MulAut.conj g • P := rfl theorem Sylow.coe_subgroup_smul {g : G} {P : Sylow p G} : ↑(g • P) = MulAut.conj g • (P : Subgroup G) := rfl theorem Sylow.coe_smul {g : G} {P : Sylow p G} : ↑(g • P) = MulAut.conj g • (P : Set G) := rfl theorem Sylow.smul_le {P : Sylow p G} {H : Subgroup G} (hP : ↑P ≤ H) (h : H) : ↑(h • P) ≤ H := Subgroup.conj_smul_le_of_le hP h theorem Sylow.smul_subtype {P : Sylow p G} {H : Subgroup G} (hP : ↑P ≤ H) (h : H) : h • P.subtype hP = (h • P).subtype (Sylow.smul_le hP h) := Sylow.ext (Subgroup.conj_smul_subgroupOf hP h) theorem Sylow.smul_eq_iff_mem_normalizer {g : G} {P : Sylow p G} : g • P = P ↔ g ∈ (P : Subgroup G).normalizer := by rw [eq_comm, SetLike.ext_iff, ← inv_mem_iff (G := G) (H := normalizer P.toSubgroup), mem_normalizer_iff, inv_inv] exact forall_congr' fun h => iff_congr Iff.rfl ⟨fun ⟨a, b, c⟩ => c ▸ by simpa [mul_assoc] using b, fun hh => ⟨(MulAut.conj g)⁻¹ h, hh, MulAut.apply_inv_self G (MulAut.conj g) h⟩⟩ theorem Sylow.smul_eq_of_normal {g : G} {P : Sylow p G} [h : (P : Subgroup G).Normal] : g • P = P := by simp only [Sylow.smul_eq_iff_mem_normalizer, normalizer_eq_top.mpr h, mem_top] theorem Subgroup.sylow_mem_fixedPoints_iff (H : Subgroup G) {P : Sylow p G} : P ∈ fixedPoints H (Sylow p G) ↔ H ≤ (P : Subgroup G).normalizer := by simp_rw [SetLike.le_def, ← Sylow.smul_eq_iff_mem_normalizer]; exact Subtype.forall theorem IsPGroup.inf_normalizer_sylow {P : Subgroup G} (hP : IsPGroup p P) (Q : Sylow p G) : P ⊓ (Q : Subgroup G).normalizer = P ⊓ Q := le_antisymm (le_inf inf_le_left (sup_eq_right.mp (Q.3 (hP.to_inf_left.to_sup_of_normal_right' Q.2 inf_le_right) le_sup_right))) (inf_le_inf_left P le_normalizer) theorem IsPGroup.sylow_mem_fixedPoints_iff {P : Subgroup G} (hP : IsPGroup p P) {Q : Sylow p G} : Q ∈ fixedPoints P (Sylow p G) ↔ P ≤ Q := by rw [P.sylow_mem_fixedPoints_iff, ← inf_eq_left, hP.inf_normalizer_sylow, inf_eq_left] /-- A generalization of **Sylow's second theorem**. If the number of Sylow `p`-subgroups is finite, then all Sylow `p`-subgroups are conjugate. -/ instance [hp : Fact p.Prime] [Finite (Sylow p G)] : IsPretransitive G (Sylow p G) := ⟨fun P Q => by classical have H := fun {R : Sylow p G} {S : orbit G P} => calc S ∈ fixedPoints R (orbit G P) ↔ S.1 ∈ fixedPoints R (Sylow p G) := forall_congr' fun a => Subtype.ext_iff _ ↔ R.1 ≤ S := R.2.sylow_mem_fixedPoints_iff _ ↔ S.1.1 = R := ⟨fun h => R.3 S.1.2 h, ge_of_eq⟩ suffices Set.Nonempty (fixedPoints Q (orbit G P)) by exact Exists.elim this fun R hR => by rw [← Sylow.ext (H.mp hR)] exact R.2 apply Q.2.nonempty_fixed_point_of_prime_not_dvd_card refine fun h => hp.out.not_dvd_one (Nat.modEq_zero_iff_dvd.mp ?_) calc 1 = Nat.card (fixedPoints P (orbit G P)) := ?_ _ ≡ Nat.card (orbit G P) [MOD p] := (P.2.card_modEq_card_fixedPoints (orbit G P)).symm _ ≡ 0 [MOD p] := Nat.modEq_zero_iff_dvd.mpr h rw [← Nat.card_unique (α := ({⟨P, mem_orbit_self P⟩} : Set (orbit G P))), eq_comm] congr rw [Set.eq_singleton_iff_unique_mem] exact ⟨H.mpr rfl, fun R h => Subtype.ext (Sylow.ext (H.mp h))⟩⟩ variable (p) (G) /-- A generalization of **Sylow's third theorem**. If the number of Sylow `p`-subgroups is finite, then it is congruent to `1` modulo `p`. -/ theorem card_sylow_modEq_one [Fact p.Prime] [Finite (Sylow p G)] : Nat.card (Sylow p G) ≡ 1 [MOD p] := by refine Sylow.nonempty.elim fun P : Sylow p G => ?_ have : fixedPoints P.1 (Sylow p G) = {P} := Set.ext fun Q : Sylow p G => calc Q ∈ fixedPoints P (Sylow p G) ↔ P.1 ≤ Q := P.2.sylow_mem_fixedPoints_iff _ ↔ Q.1 = P.1 := ⟨P.3 Q.2, ge_of_eq⟩ _ ↔ Q ∈ {P} := Sylow.ext_iff.symm.trans Set.mem_singleton_iff.symm have : Nat.card (fixedPoints P.1 (Sylow p G)) = 1 := by simp [this] exact (P.2.card_modEq_card_fixedPoints (Sylow p G)).trans (by rw [this]) theorem not_dvd_card_sylow [hp : Fact p.Prime] [Finite (Sylow p G)] : ¬p ∣ Nat.card (Sylow p G) := fun h => hp.1.ne_one (Nat.dvd_one.mp ((Nat.modEq_iff_dvd' zero_le_one).mp ((Nat.modEq_zero_iff_dvd.mpr h).symm.trans (card_sylow_modEq_one p G)))) variable {p} {G} /-- Sylow subgroups are isomorphic -/ nonrec def Sylow.equivSMul (P : Sylow p G) (g : G) : P ≃* (g • P : Sylow p G) := equivSMul (MulAut.conj g) P.toSubgroup /-- Sylow subgroups are isomorphic -/ noncomputable def Sylow.equiv [Fact p.Prime] [Finite (Sylow p G)] (P Q : Sylow p G) : P ≃* Q := by rw [← Classical.choose_spec (exists_smul_eq G P Q)] exact P.equivSMul (Classical.choose (exists_smul_eq G P Q)) @[simp] theorem Sylow.orbit_eq_top [Fact p.Prime] [Finite (Sylow p G)] (P : Sylow p G) : orbit G P = ⊤ := top_le_iff.mp fun Q _ => exists_smul_eq G P Q theorem Sylow.stabilizer_eq_normalizer (P : Sylow p G) : stabilizer G P = (P : Subgroup G).normalizer := by ext; simp [Sylow.smul_eq_iff_mem_normalizer] theorem Sylow.conj_eq_normalizer_conj_of_mem_centralizer [Fact p.Prime] [Finite (Sylow p G)] (P : Sylow p G) (x g : G) (hx : x ∈ centralizer (P : Set G)) (hy : g⁻¹ * x * g ∈ centralizer (P : Set G)) : ∃ n ∈ (P : Subgroup G).normalizer, g⁻¹ * x * g = n⁻¹ * x * n := by have h1 : ↑P ≤ centralizer (zpowers x : Set G) := by rwa [le_centralizer_iff, zpowers_le] have h2 : ↑(g • P) ≤ centralizer (zpowers x : Set G) := by rw [le_centralizer_iff, zpowers_le] rintro - ⟨z, hz, rfl⟩ specialize hy z hz rwa [← mul_assoc, ← eq_mul_inv_iff_mul_eq, mul_assoc, mul_assoc, mul_assoc, ← mul_assoc, eq_inv_mul_iff_mul_eq, ← mul_assoc, ← mul_assoc] at hy obtain ⟨h, hh⟩ := exists_smul_eq (centralizer (zpowers x : Set G)) ((g • P).subtype h2) (P.subtype h1) simp_rw [Sylow.smul_subtype, Subgroup.smul_def, smul_smul] at hh refine ⟨h * g, Sylow.smul_eq_iff_mem_normalizer.mp (Sylow.subtype_injective hh), ?_⟩ rw [← mul_assoc, Commute.right_comm (h.prop x (mem_zpowers x)), mul_inv_rev, inv_mul_cancel_right] theorem Sylow.conj_eq_normalizer_conj_of_mem [Fact p.Prime] [Finite (Sylow p G)] (P : Sylow p G) [_hP : (P : Subgroup G).IsCommutative] (x g : G) (hx : x ∈ P) (hy : g⁻¹ * x * g ∈ P) : ∃ n ∈ (P : Subgroup G).normalizer, g⁻¹ * x * g = n⁻¹ * x * n := P.conj_eq_normalizer_conj_of_mem_centralizer x g (le_centralizer P hx) (le_centralizer P hy) /-- Sylow `p`-subgroups are in bijection with cosets of the normalizer of a Sylow `p`-subgroup -/ noncomputable def Sylow.equivQuotientNormalizer [Fact p.Prime] [Finite (Sylow p G)] (P : Sylow p G) : Sylow p G ≃ G ⧸ (P : Subgroup G).normalizer := calc Sylow p G ≃ (⊤ : Set (Sylow p G)) := (Equiv.Set.univ (Sylow p G)).symm _ ≃ orbit G P := Equiv.setCongr P.orbit_eq_top.symm _ ≃ G ⧸ stabilizer G P := orbitEquivQuotientStabilizer G P _ ≃ G ⧸ (P : Subgroup G).normalizer := by rw [P.stabilizer_eq_normalizer] instance [Fact p.Prime] [Finite (Sylow p G)] (P : Sylow p G) : Finite (G ⧸ (P : Subgroup G).normalizer) := Finite.of_equiv (Sylow p G) P.equivQuotientNormalizer theorem card_sylow_eq_card_quotient_normalizer [Fact p.Prime] [Finite (Sylow p G)] (P : Sylow p G) : Nat.card (Sylow p G) = Nat.card (G ⧸ (P : Subgroup G).normalizer) := Nat.card_congr P.equivQuotientNormalizer theorem card_sylow_eq_index_normalizer [Fact p.Prime] [Finite (Sylow p G)] (P : Sylow p G) : Nat.card (Sylow p G) = (P : Subgroup G).normalizer.index := card_sylow_eq_card_quotient_normalizer P theorem card_sylow_dvd_index [Fact p.Prime] [Finite (Sylow p G)] (P : Sylow p G) : Nat.card (Sylow p G) ∣ (P : Subgroup G).index := ((congr_arg _ (card_sylow_eq_index_normalizer P)).mp dvd_rfl).trans (index_dvd_of_le le_normalizer) theorem not_dvd_index_sylow' [hp : Fact p.Prime] (P : Sylow p G) [(P : Subgroup G).Normal] [fP : FiniteIndex (P : Subgroup G)] : ¬p ∣ (P : Subgroup G).index := by intro h rw [index_eq_card (P : Subgroup G)] at h obtain ⟨x, hx⟩ := exists_prime_orderOf_dvd_card' (G := G ⧸ (P : Subgroup G)) p h have h := IsPGroup.of_card (((Nat.card_zpowers x).trans hx).trans (pow_one p).symm) let Q := (zpowers x).comap (QuotientGroup.mk' (P : Subgroup G)) have hQ : IsPGroup p Q := by apply h.comap_of_ker_isPGroup rw [QuotientGroup.ker_mk'] exact P.2 replace hp := mt orderOf_eq_one_iff.mpr (ne_of_eq_of_ne hx hp.1.ne_one) rw [← zpowers_eq_bot, ← Ne, ← bot_lt_iff_ne_bot, ← comap_lt_comap_of_surjective (QuotientGroup.mk'_surjective _), MonoidHom.comap_bot, QuotientGroup.ker_mk'] at hp exact hp.ne' (P.3 hQ hp.le) theorem not_dvd_index_sylow [hp : Fact p.Prime] [Finite (Sylow p G)] (P : Sylow p G) (hP : relindex ↑P (P : Subgroup G).normalizer ≠ 0) : ¬p ∣ (P : Subgroup G).index := by rw [← relindex_mul_index le_normalizer, ← card_sylow_eq_index_normalizer] haveI : (P.subtype le_normalizer : Subgroup (P : Subgroup G).normalizer).Normal := Subgroup.normal_in_normalizer haveI : FiniteIndex ↑(P.subtype le_normalizer : Subgroup (P : Subgroup G).normalizer) := ⟨hP⟩ replace hP := not_dvd_index_sylow' (P.subtype le_normalizer) exact hp.1.not_dvd_mul hP (not_dvd_card_sylow p G) /-- **Frattini's Argument**: If `N` is a normal subgroup of `G`, and if `P` is a Sylow `p`-subgroup of `N`, then `N_G(P) ⊔ N = G`. -/ theorem Sylow.normalizer_sup_eq_top {p : ℕ} [Fact p.Prime] {N : Subgroup G} [N.Normal] [Finite (Sylow p N)] (P : Sylow p N) : ((↑P : Subgroup N).map N.subtype).normalizer ⊔ N = ⊤ := by refine top_le_iff.mp fun g _ => ?_ obtain ⟨n, hn⟩ := exists_smul_eq N ((MulAut.conjNormal g : MulAut N) • P) P rw [← inv_mul_cancel_left (↑n) g, sup_comm] apply mul_mem_sup (N.inv_mem n.2) rw [Sylow.smul_def, ← mul_smul, ← MulAut.conjNormal_val, ← MulAut.conjNormal.map_mul, Sylow.ext_iff, Sylow.pointwise_smul_def, Subgroup.pointwise_smul_def] at hn have : Function.Injective (MulAut.conj (n * g)).toMonoidHom := (MulAut.conj (n * g)).injective refine fun x ↦ (mem_map_iff_mem this).symm.trans ?_ rw [map_map, ← congr_arg (map N.subtype) hn, map_map] rfl /-- **Frattini's Argument**: If `N` is a normal subgroup of `G`, and if `P` is a Sylow `p`-subgroup of `N`, then `N_G(P) ⊔ N = G`. -/ theorem Sylow.normalizer_sup_eq_top' {p : ℕ} [Fact p.Prime] {N : Subgroup G} [N.Normal] [Finite (Sylow p N)] (P : Sylow p G) (hP : ↑P ≤ N) : (P : Subgroup G).normalizer ⊔ N = ⊤ := by rw [← Sylow.normalizer_sup_eq_top (P.subtype hP), P.coe_subtype, subgroupOf_map_subtype, inf_of_le_left hP] end InfiniteSylow open Equiv Equiv.Perm Finset Function List QuotientGroup universe u v w variable {G : Type u} {α : Type v} {β : Type w} [Group G] theorem QuotientGroup.card_preimage_mk (s : Subgroup G) (t : Set (G ⧸ s)) : Nat.card (QuotientGroup.mk ⁻¹' t) = Nat.card s * Nat.card t := by rw [← Nat.card_prod, Nat.card_congr (preimageMkEquivSubgroupProdSet _ _)] namespace Sylow theorem mem_fixedPoints_mul_left_cosets_iff_mem_normalizer {H : Subgroup G} [Finite (H : Set G)] {x : G} : (x : G ⧸ H) ∈ MulAction.fixedPoints H (G ⧸ H) ↔ x ∈ normalizer H := ⟨fun hx => have ha : ∀ {y : G ⧸ H}, y ∈ orbit H (x : G ⧸ H) → y = x := mem_fixedPoints'.1 hx _ (inv_mem_iff (G := G)).1 (mem_normalizer_fintype fun n (hn : n ∈ H) => have : (n⁻¹ * x)⁻¹ * x ∈ H := QuotientGroup.eq.1 (ha ⟨⟨n⁻¹, inv_mem hn⟩, rfl⟩) show _ ∈ H by rw [mul_inv_rev, inv_inv] at this convert this rw [inv_inv]), fun hx : ∀ n : G, n ∈ H ↔ x * n * x⁻¹ ∈ H => mem_fixedPoints'.2 fun y => Quotient.inductionOn' y fun y hy => QuotientGroup.eq.2 (let ⟨⟨b, hb₁⟩, hb₂⟩ := hy have hb₂ : (b * x)⁻¹ * y ∈ H := QuotientGroup.eq.1 hb₂ (inv_mem_iff (G := G)).1 <| (hx _).2 <| (mul_mem_cancel_left (inv_mem hb₁)).1 <| by rw [hx] at hb₂; simpa [mul_inv_rev, mul_assoc] using hb₂)⟩ /-- The fixed points of the action of `H` on its cosets correspond to `normalizer H / H`. -/ def fixedPointsMulLeftCosetsEquivQuotient (H : Subgroup G) [Finite (H : Set G)] : MulAction.fixedPoints H (G ⧸ H) ≃ normalizer H ⧸ Subgroup.comap ((normalizer H).subtype : normalizer H →* G) H := @subtypeQuotientEquivQuotientSubtype G (normalizer H : Set G) (_) (_) (MulAction.fixedPoints H (G ⧸ H)) (fun a => (@mem_fixedPoints_mul_left_cosets_iff_mem_normalizer _ _ _ ‹_› _).symm) (by intros unfold_projs rw [leftRel_apply (α := normalizer H), leftRel_apply] rfl) /-- If `H` is a `p`-subgroup of `G`, then the index of `H` inside its normalizer is congruent mod `p` to the index of `H`. -/ theorem card_quotient_normalizer_modEq_card_quotient [Finite G] {p : ℕ} {n : ℕ} [hp : Fact p.Prime] {H : Subgroup G} (hH : Nat.card H = p ^ n) : Nat.card (normalizer H ⧸ Subgroup.comap ((normalizer H).subtype : normalizer H →* G) H) ≡ Nat.card (G ⧸ H) [MOD p] := by rw [← Nat.card_congr (fixedPointsMulLeftCosetsEquivQuotient H)] exact ((IsPGroup.of_card hH).card_modEq_card_fixedPoints _).symm /-- If `H` is a subgroup of `G` of cardinality `p ^ n`, then the cardinality of the normalizer of `H` is congruent mod `p ^ (n + 1)` to the cardinality of `G`. -/ theorem card_normalizer_modEq_card [Finite G] {p : ℕ} {n : ℕ} [hp : Fact p.Prime] {H : Subgroup G} (hH : Nat.card H = p ^ n) : Nat.card (normalizer H) ≡ Nat.card G [MOD p ^ (n + 1)] := by have : H.subgroupOf (normalizer H) ≃ H := (subgroupOfEquivOfLe le_normalizer).toEquiv rw [card_eq_card_quotient_mul_card_subgroup H, card_eq_card_quotient_mul_card_subgroup (H.subgroupOf (normalizer H)), Nat.card_congr this, hH, pow_succ'] exact (card_quotient_normalizer_modEq_card_quotient hH).mul_right' _ /-- If `H` is a `p`-subgroup but not a Sylow `p`-subgroup, then `p` divides the index of `H` inside its normalizer. -/ theorem prime_dvd_card_quotient_normalizer [Finite G] {p : ℕ} {n : ℕ} [hp : Fact p.Prime] (hdvd : p ^ (n + 1) ∣ Nat.card G) {H : Subgroup G} (hH : Nat.card H = p ^ n) : p ∣ Nat.card (normalizer H ⧸ Subgroup.comap ((normalizer H).subtype : normalizer H →* G) H) := let ⟨s, hs⟩ := exists_eq_mul_left_of_dvd hdvd have hcard : Nat.card (G ⧸ H) = s * p := (mul_left_inj' (show Nat.card H ≠ 0 from Nat.card_pos.ne')).1 (by rw [← card_eq_card_quotient_mul_card_subgroup H, hH, hs, pow_succ', mul_assoc, mul_comm p]) have hm : s * p % p = Nat.card (normalizer H ⧸ Subgroup.comap ((normalizer H).subtype : normalizer H →* G) H) % p := hcard ▸ (card_quotient_normalizer_modEq_card_quotient hH).symm Nat.dvd_of_mod_eq_zero (by rwa [Nat.mod_eq_zero_of_dvd (dvd_mul_left _ _), eq_comm] at hm) /-- If `H` is a `p`-subgroup but not a Sylow `p`-subgroup of cardinality `p ^ n`, then `p ^ (n + 1)` divides the cardinality of the normalizer of `H`. -/ theorem prime_pow_dvd_card_normalizer [Finite G] {p : ℕ} {n : ℕ} [_hp : Fact p.Prime] (hdvd : p ^ (n + 1) ∣ Nat.card G) {H : Subgroup G} (hH : Nat.card H = p ^ n) : p ^ (n + 1) ∣ Nat.card (normalizer H) := Nat.modEq_zero_iff_dvd.1 ((card_normalizer_modEq_card hH).trans hdvd.modEq_zero_nat) /-- If `H` is a subgroup of `G` of cardinality `p ^ n`, then `H` is contained in a subgroup of cardinality `p ^ (n + 1)` if `p ^ (n + 1)` divides the cardinality of `G` -/ theorem exists_subgroup_card_pow_succ [Finite G] {p : ℕ} {n : ℕ} [hp : Fact p.Prime] (hdvd : p ^ (n + 1) ∣ Nat.card G) {H : Subgroup G} (hH : Nat.card H = p ^ n) : ∃ K : Subgroup G, Nat.card K = p ^ (n + 1) ∧ H ≤ K := let ⟨s, hs⟩ := exists_eq_mul_left_of_dvd hdvd have hcard : Nat.card (G ⧸ H) = s * p := (mul_left_inj' (show Nat.card H ≠ 0 from Nat.card_pos.ne')).1 (by rw [← card_eq_card_quotient_mul_card_subgroup H, hH, hs, pow_succ', mul_assoc, mul_comm p]) have hm : s * p % p = Nat.card (normalizer H ⧸ H.subgroupOf H.normalizer) % p := Nat.card_congr (fixedPointsMulLeftCosetsEquivQuotient H) ▸ hcard ▸ (IsPGroup.of_card hH).card_modEq_card_fixedPoints _ have hm' : p ∣ Nat.card (normalizer H ⧸ H.subgroupOf H.normalizer) := Nat.dvd_of_mod_eq_zero (by rwa [Nat.mod_eq_zero_of_dvd (dvd_mul_left _ _), eq_comm] at hm) let ⟨x, hx⟩ := @exists_prime_orderOf_dvd_card' _ (QuotientGroup.Quotient.group _) _ _ hp hm' have hequiv : H ≃ H.subgroupOf H.normalizer := (subgroupOfEquivOfLe le_normalizer).symm.toEquiv ⟨Subgroup.map (normalizer H).subtype (Subgroup.comap (mk' (H.subgroupOf H.normalizer)) (zpowers x)), by show Nat.card (Subgroup.map H.normalizer.subtype (comap (mk' (H.subgroupOf H.normalizer)) (Subgroup.zpowers x))) = p ^ (n + 1) suffices Nat.card (Subtype.val '' (Subgroup.comap (mk' (H.subgroupOf H.normalizer)) (zpowers x) : Set H.normalizer)) = p ^ (n + 1) by convert this using 2 rw [Nat.card_image_of_injective Subtype.val_injective (Subgroup.comap (mk' (H.subgroupOf H.normalizer)) (zpowers x) : Set H.normalizer), pow_succ, ← hH, Nat.card_congr hequiv, ← hx, ← Nat.card_zpowers, ← Nat.card_prod] exact Nat.card_congr (preimageMkEquivSubgroupProdSet (H.subgroupOf H.normalizer) (zpowers x)), by intro y hy simp only [exists_prop, Subgroup.coeSubtype, mk'_apply, Subgroup.mem_map, Subgroup.mem_comap] refine ⟨⟨y, le_normalizer hy⟩, ⟨0, ?_⟩, rfl⟩ dsimp only rw [zpow_zero, eq_comm, QuotientGroup.eq_one_iff] simpa using hy⟩ /-- If `H` is a subgroup of `G` of cardinality `p ^ n`, then `H` is contained in a subgroup of cardinality `p ^ m` if `n ≤ m` and `p ^ m` divides the cardinality of `G` -/ theorem exists_subgroup_card_pow_prime_le [Finite G] (p : ℕ) : ∀ {n m : ℕ} [_hp : Fact p.Prime] (_hdvd : p ^ m ∣ Nat.card G) (H : Subgroup G) (_hH : Nat.card H = p ^ n) (_hnm : n ≤ m), ∃ K : Subgroup G, Nat.card K = p ^ m ∧ H ≤ K | n, m => fun {hdvd H hH hnm} => (lt_or_eq_of_le hnm).elim (fun hnm : n < m => have h0m : 0 < m := lt_of_le_of_lt n.zero_le hnm have _wf : m - 1 < m := Nat.sub_lt h0m zero_lt_one have hnm1 : n ≤ m - 1 := le_tsub_of_add_le_right hnm let ⟨K, hK⟩ := @exists_subgroup_card_pow_prime_le _ _ n (m - 1) _ (Nat.pow_dvd_of_le_of_pow_dvd tsub_le_self hdvd) H hH hnm1 have hdvd' : p ^ (m - 1 + 1) ∣ Nat.card G := by rwa [tsub_add_cancel_of_le h0m.nat_succ_le] let ⟨K', hK'⟩ := @exists_subgroup_card_pow_succ _ _ _ _ _ _ hdvd' K hK.1 ⟨K', by rw [hK'.1, tsub_add_cancel_of_le h0m.nat_succ_le], le_trans hK.2 hK'.2⟩) fun hnm : n = m => ⟨H, by simp [hH, hnm]⟩ /-- A generalisation of **Sylow's first theorem**. If `p ^ n` divides the cardinality of `G`, then there is a subgroup of cardinality `p ^ n` -/ theorem exists_subgroup_card_pow_prime [Finite G] (p : ℕ) {n : ℕ} [Fact p.Prime] (hdvd : p ^ n ∣ Nat.card G) : ∃ K : Subgroup G, Nat.card K = p ^ n := let ⟨K, hK⟩ := exists_subgroup_card_pow_prime_le p hdvd ⊥ (by rw [card_bot, pow_zero]) n.zero_le ⟨K, hK.1⟩ /-- A special case of **Sylow's first theorem**. If `G` is a `p`-group of size at least `p ^ n` then there is a subgroup of cardinality `p ^ n`. -/ lemma exists_subgroup_card_pow_prime_of_le_card {n p : ℕ} (hp : p.Prime) (h : IsPGroup p G) (hn : p ^ n ≤ Nat.card G) : ∃ H : Subgroup G, Nat.card H = p ^ n := by have : Fact p.Prime := ⟨hp⟩ have : Finite G := Nat.finite_of_card_ne_zero <| by linarith [Nat.one_le_pow n p hp.pos] obtain ⟨m, hm⟩ := h.exists_card_eq refine exists_subgroup_card_pow_prime _ ?_ rw [hm] at hn ⊢ exact pow_dvd_pow _ <| (pow_le_pow_iff_right hp.one_lt).1 hn /-- A special case of **Sylow's first theorem**. If `G` is a `p`-group and `H` a subgroup of size at least `p ^ n` then there is a subgroup of `H` of cardinality `p ^ n`. -/ lemma exists_subgroup_le_card_pow_prime_of_le_card {n p : ℕ} (hp : p.Prime) (h : IsPGroup p G) {H : Subgroup G} (hn : p ^ n ≤ Nat.card H) : ∃ H' ≤ H, Nat.card H' = p ^ n := by obtain ⟨H', H'card⟩ := exists_subgroup_card_pow_prime_of_le_card hp (h.to_subgroup H) hn refine ⟨H'.map H.subtype, map_subtype_le _, ?_⟩ rw [← H'card] let e : H' ≃* H'.map H.subtype := H'.equivMapOfInjective (Subgroup.subtype H) H.subtype_injective exact Nat.card_congr e.symm.toEquiv /-- A special case of **Sylow's first theorem**. If `G` is a `p`-group and `H` a subgroup of size at least `k` then there is a subgroup of `H` of cardinality between `k / p` and `k`. -/ lemma exists_subgroup_le_card_le {k p : ℕ} (hp : p.Prime) (h : IsPGroup p G) {H : Subgroup G} (hk : k ≤ Nat.card H) (hk₀ : k ≠ 0) : ∃ H' ≤ H, Nat.card H' ≤ k ∧ k < p * Nat.card H' := by obtain ⟨m, hmk, hkm⟩ : ∃ s, p ^ s ≤ k ∧ k < p ^ (s + 1) := exists_nat_pow_near (Nat.one_le_iff_ne_zero.2 hk₀) hp.one_lt obtain ⟨H', H'H, H'card⟩ := exists_subgroup_le_card_pow_prime_of_le_card hp h (hmk.trans hk) refine ⟨H', H'H, ?_⟩ simpa only [pow_succ', H'card] using And.intro hmk hkm theorem pow_dvd_card_of_pow_dvd_card [Finite G] {p n : ℕ} [hp : Fact p.Prime] (P : Sylow p G) (hdvd : p ^ n ∣ Nat.card G) : p ^ n ∣ Nat.card P := by rw [← index_mul_card P.1] at hdvd exact (hp.1.coprime_pow_of_not_dvd (not_dvd_index_sylow P index_ne_zero_of_finite)).symm.dvd_of_dvd_mul_left hdvd theorem dvd_card_of_dvd_card [Finite G] {p : ℕ} [Fact p.Prime] (P : Sylow p G) (hdvd : p ∣ Nat.card G) : p ∣ Nat.card P := by rw [← pow_one p] at hdvd have key := P.pow_dvd_card_of_pow_dvd_card hdvd rwa [pow_one] at key /-- Sylow subgroups are Hall subgroups. -/ theorem card_coprime_index [Finite G] {p : ℕ} [hp : Fact p.Prime] (P : Sylow p G) : (Nat.card P).Coprime (index (P : Subgroup G)) := let ⟨_n, hn⟩ := IsPGroup.iff_card.mp P.2 hn.symm ▸ (hp.1.coprime_pow_of_not_dvd (not_dvd_index_sylow P index_ne_zero_of_finite)).symm theorem ne_bot_of_dvd_card [Finite G] {p : ℕ} [hp : Fact p.Prime] (P : Sylow p G) (hdvd : p ∣ Nat.card G) : (P : Subgroup G) ≠ ⊥ := by refine fun h => hp.out.not_dvd_one ?_ have key : p ∣ Nat.card (P : Subgroup G) := P.dvd_card_of_dvd_card hdvd rwa [h, card_bot] at key /-- The cardinality of a Sylow subgroup is `p ^ n` where `n` is the multiplicity of `p` in the group order. -/ theorem card_eq_multiplicity [Finite G] {p : ℕ} [hp : Fact p.Prime] (P : Sylow p G) : Nat.card P = p ^ Nat.factorization (Nat.card G) p := by obtain ⟨n, heq : Nat.card P = _⟩ := IsPGroup.iff_card.mp P.isPGroup' refine Nat.dvd_antisymm ?_ (P.pow_dvd_card_of_pow_dvd_card (Nat.ord_proj_dvd _ p)) rw [heq, ← hp.out.pow_dvd_iff_dvd_ord_proj (show Nat.card G ≠ 0 from Nat.card_pos.ne'), ← heq] exact P.1.card_subgroup_dvd_card /-- A subgroup with cardinality `p ^ n` is a Sylow subgroup where `n` is the multiplicity of `p` in the group order. -/ def ofCard [Finite G] {p : ℕ} [Fact p.Prime] (H : Subgroup G) (card_eq : Nat.card H = p ^ (Nat.card G).factorization p) : Sylow p G where toSubgroup := H isPGroup' := IsPGroup.of_card card_eq is_maximal' := by obtain ⟨P, hHP⟩ := (IsPGroup.of_card card_eq).exists_le_sylow exact SetLike.ext' (Set.Finite.eq_of_subset_of_card_le (inferInstanceAs (Finite P)) hHP (P.card_eq_multiplicity.trans card_eq.symm).le).symm ▸ P.3 @[simp, norm_cast] theorem coe_ofCard [Finite G] {p : ℕ} [Fact p.Prime] (H : Subgroup G) (card_eq : Nat.card H = p ^ (Nat.card G).factorization p) : ↑(ofCard H card_eq) = H := rfl /-- If `G` has a normal Sylow `p`-subgroup, then it is the only Sylow `p`-subgroup. -/ noncomputable def unique_of_normal {p : ℕ} [Fact p.Prime] [Finite (Sylow p G)] (P : Sylow p G) (h : (P : Subgroup G).Normal) : Unique (Sylow p G) := by refine { uniq := fun Q ↦ ?_ } obtain ⟨x, h1⟩ := exists_smul_eq G P Q obtain ⟨x, h2⟩ := exists_smul_eq G P default rw [Sylow.smul_eq_of_normal] at h1 h2 rw [← h1, ← h2] section Pointwise open Pointwise theorem characteristic_of_normal {p : ℕ} [Fact p.Prime] [Finite (Sylow p G)] (P : Sylow p G) (h : (P : Subgroup G).Normal) : (P : Subgroup G).Characteristic := by haveI := Sylow.unique_of_normal P h rw [characteristic_iff_map_eq] intro Φ show (Φ • P).toSubgroup = P.toSubgroup congr simp [eq_iff_true_of_subsingleton] end Pointwise theorem normal_of_normalizer_normal {p : ℕ} [Fact p.Prime] [Finite (Sylow p G)] (P : Sylow p G) (hn : (↑P : Subgroup G).normalizer.Normal) : (↑P : Subgroup G).Normal := by rw [← normalizer_eq_top, ← normalizer_sup_eq_top' P le_normalizer, sup_idem] @[simp] theorem normalizer_normalizer {p : ℕ} [Fact p.Prime] [Finite (Sylow p G)] (P : Sylow p G) : (↑P : Subgroup G).normalizer.normalizer = (↑P : Subgroup G).normalizer := by have := normal_of_normalizer_normal (P.subtype (le_normalizer.trans le_normalizer)) simp_rw [← normalizer_eq_top, Sylow.coe_subtype, ← subgroupOf_normalizer_eq le_normalizer, ← subgroupOf_normalizer_eq le_rfl, subgroupOf_self] at this rw [← subtype_range (P : Subgroup G).normalizer.normalizer, MonoidHom.range_eq_map, ← this trivial] exact map_comap_eq_self (le_normalizer.trans (ge_of_eq (subtype_range _))) theorem normal_of_all_max_subgroups_normal [Finite G] (hnc : ∀ H : Subgroup G, IsCoatom H → H.Normal) {p : ℕ} [Fact p.Prime] [Finite (Sylow p G)] (P : Sylow p G) : (↑P : Subgroup G).Normal := normalizer_eq_top.mp (by rcases eq_top_or_exists_le_coatom (↑P : Subgroup G).normalizer with (heq | ⟨K, hK, hNK⟩) · exact heq · haveI := hnc _ hK have hPK : ↑P ≤ K := le_trans le_normalizer hNK refine (hK.1 ?_).elim rw [← sup_of_le_right hNK, P.normalizer_sup_eq_top' hPK]) theorem normal_of_normalizerCondition (hnc : NormalizerCondition G) {p : ℕ} [Fact p.Prime] [Finite (Sylow p G)] (P : Sylow p G) : (↑P : Subgroup G).Normal := normalizer_eq_top.mp <| normalizerCondition_iff_only_full_group_self_normalizing.mp hnc _ <| normalizer_normalizer _ /-- If all its Sylow subgroups are normal, then a finite group is isomorphic to the direct product of these Sylow subgroups. -/ noncomputable def directProductOfNormal [Finite G] (hn : ∀ {p : ℕ} [Fact p.Prime] (P : Sylow p G), (↑P : Subgroup G).Normal) : (∀ p : (Nat.card G).primeFactors, ∀ P : Sylow p G, (↑P : Subgroup G)) ≃* G := by have := Fintype.ofFinite G set ps := (Nat.card G).primeFactors -- “The” Sylow subgroup for p let P : ∀ p, Sylow p G := default have : ∀ p, Fintype (P p) := fun p ↦ Fintype.ofFinite (P p) have hcomm : Pairwise fun p₁ p₂ : ps => ∀ x y : G, x ∈ P p₁ → y ∈ P p₂ → Commute x y := by rintro ⟨p₁, hp₁⟩ ⟨p₂, hp₂⟩ hne haveI hp₁' := Fact.mk (Nat.prime_of_mem_primeFactors hp₁) haveI hp₂' := Fact.mk (Nat.prime_of_mem_primeFactors hp₂) have hne' : p₁ ≠ p₂ := by simpa using hne apply Subgroup.commute_of_normal_of_disjoint _ _ (hn (P p₁)) (hn (P p₂)) apply IsPGroup.disjoint_of_ne p₁ p₂ hne' _ _ (P p₁).isPGroup' (P p₂).isPGroup' refine MulEquiv.trans (N := ∀ p : ps, P p) ?_ ?_ -- There is only one Sylow subgroup for each p, so the inner product is trivial · -- here we need to help the elaborator with an explicit instantiation apply @MulEquiv.piCongrRight ps (fun p => ∀ P : Sylow p G, P) (fun p => P p) _ _ rintro ⟨p, hp⟩ haveI hp' := Fact.mk (Nat.prime_of_mem_primeFactors hp) letI := unique_of_normal _ (hn (P p)) apply MulEquiv.piUnique apply MulEquiv.ofBijective (Subgroup.noncommPiCoprod hcomm) apply (Fintype.bijective_iff_injective_and_card _).mpr constructor · apply Subgroup.injective_noncommPiCoprod_of_independent apply independent_of_coprime_order hcomm rintro ⟨p₁, hp₁⟩ ⟨p₂, hp₂⟩ hne haveI hp₁' := Fact.mk (Nat.prime_of_mem_primeFactors hp₁) haveI hp₂' := Fact.mk (Nat.prime_of_mem_primeFactors hp₂) have hne' : p₁ ≠ p₂ := by simpa using hne simp only [← Nat.card_eq_fintype_card] apply IsPGroup.coprime_card_of_ne p₁ p₂ hne' _ _ (P p₁).isPGroup' (P p₂).isPGroup' · simp only [← Nat.card_eq_fintype_card] calc Nat.card (∀ p : ps, P p) = ∏ p : ps, Nat.card (P p) := Nat.card_pi _ = ∏ p : ps, p.1 ^ (Nat.card G).factorization p.1 := by congr 1 with ⟨p, hp⟩ exact @card_eq_multiplicity _ _ _ p ⟨Nat.prime_of_mem_primeFactors hp⟩ (P p) _ = ∏ p ∈ ps, p ^ (Nat.card G).factorization p := (Finset.prod_finset_coe (fun p => p ^ (Nat.card G).factorization p) _) _ = (Nat.card G).factorization.prod (· ^ ·) := rfl _ = Nat.card G := Nat.factorization_prod_pow_eq_self Nat.card_pos.ne' end Sylow
GroupTheory\Torsion.lean
/- Copyright (c) 2022 Julian Berman. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Julian Berman -/ import Mathlib.GroupTheory.PGroup /-! # Torsion groups This file defines torsion groups, i.e. groups where all elements have finite order. ## Main definitions * `Monoid.IsTorsion` a predicate asserting `G` is torsion, i.e. that all elements are of finite order. * `CommGroup.torsion G`, the torsion subgroup of an abelian group `G` * `CommMonoid.torsion G`, the above stated for commutative monoids * `Monoid.IsTorsionFree`, asserting no nontrivial elements have finite order in `G` * `AddMonoid.IsTorsion` and `AddMonoid.IsTorsionFree` the additive versions of the above ## Implementation All torsion monoids are really groups (which is proven here as `Monoid.IsTorsion.group`), but since the definition can be stated on monoids it is implemented on `Monoid` to match other declarations in the group theory library. ## Tags periodic group, aperiodic group, torsion subgroup, torsion abelian group ## Future work * generalize to π-torsion(-free) groups for a set of primes π * free, free solvable and free abelian groups are torsion free * complete direct and free products of torsion free groups are torsion free * groups which are residually finite p-groups with respect to 2 distinct primes are torsion free -/ variable {G H : Type*} namespace Monoid variable (G) [Monoid G] /-- A predicate on a monoid saying that all elements are of finite order. -/ @[to_additive "A predicate on an additive monoid saying that all elements are of finite order."] def IsTorsion := ∀ g : G, IsOfFinOrder g /-- A monoid is not a torsion monoid if it has an element of infinite order. -/ @[to_additive (attr := simp) "An additive monoid is not a torsion monoid if it has an element of infinite order."] theorem not_isTorsion_iff : ¬IsTorsion G ↔ ∃ g : G, ¬IsOfFinOrder g := by rw [IsTorsion, not_forall] end Monoid open Monoid /-- Torsion monoids are really groups. -/ @[to_additive "Torsion additive monoids are really additive groups"] noncomputable def IsTorsion.group [Monoid G] (tG : IsTorsion G) : Group G := { ‹Monoid G› with inv := fun g => g ^ (orderOf g - 1) mul_left_inv := fun g => by erw [← pow_succ, tsub_add_cancel_of_le, pow_orderOf_eq_one] exact (tG g).orderOf_pos } section Group variable [Group G] {N : Subgroup G} [Group H] /-- Subgroups of torsion groups are torsion groups. -/ @[to_additive "Subgroups of additive torsion groups are additive torsion groups."] theorem IsTorsion.subgroup (tG : IsTorsion G) (H : Subgroup G) : IsTorsion H := fun h => Submonoid.isOfFinOrder_coe.1 <| tG h /-- The image of a surjective torsion group homomorphism is torsion. -/ @[to_additive AddIsTorsion.of_surjective "The image of a surjective additive torsion group homomorphism is torsion."] theorem IsTorsion.of_surjective {f : G →* H} (hf : Function.Surjective f) (tG : IsTorsion G) : IsTorsion H := fun h => by obtain ⟨g, hg⟩ := hf h rw [← hg] exact f.isOfFinOrder (tG g) /-- Torsion groups are closed under extensions. -/ @[to_additive AddIsTorsion.extension_closed "Additive torsion groups are closed under extensions."] theorem IsTorsion.extension_closed {f : G →* H} (hN : N = f.ker) (tH : IsTorsion H) (tN : IsTorsion N) : IsTorsion G := fun g => by obtain ⟨ngn, ngnpos, hngn⟩ := (tH <| f g).exists_pow_eq_one have hmem := f.mem_ker.mpr ((f.map_pow g ngn).trans hngn) lift g ^ ngn to N using hN.symm ▸ hmem with gn h obtain ⟨nn, nnpos, hnn⟩ := (tN gn).exists_pow_eq_one exact isOfFinOrder_iff_pow_eq_one.mpr <| ⟨ngn * nn, mul_pos ngnpos nnpos, by rw [pow_mul, ← h, ← Subgroup.coe_pow, hnn, Subgroup.coe_one]⟩ /-- The image of a quotient is torsion iff the group is torsion. -/ @[to_additive AddIsTorsion.quotient_iff "The image of a quotient is additively torsion iff the group is torsion."] theorem IsTorsion.quotient_iff {f : G →* H} (hf : Function.Surjective f) (hN : N = f.ker) (tN : IsTorsion N) : IsTorsion H ↔ IsTorsion G := ⟨fun tH => IsTorsion.extension_closed hN tH tN, fun tG => IsTorsion.of_surjective hf tG⟩ /-- If a group exponent exists, the group is torsion. -/ @[to_additive ExponentExists.is_add_torsion "If a group exponent exists, the group is additively torsion."] theorem ExponentExists.isTorsion (h : ExponentExists G) : IsTorsion G := fun g => by obtain ⟨n, npos, hn⟩ := h exact isOfFinOrder_iff_pow_eq_one.mpr ⟨n, npos, hn g⟩ /-- The group exponent exists for any bounded torsion group. -/ @[to_additive IsAddTorsion.exponentExists "The group exponent exists for any bounded additive torsion group."] theorem IsTorsion.exponentExists (tG : IsTorsion G) (bounded : (Set.range fun g : G => orderOf g).Finite) : ExponentExists G := exponent_ne_zero.mp <| (exponent_ne_zero_iff_range_orderOf_finite fun g => (tG g).orderOf_pos).mpr bounded /-- Finite groups are torsion groups. -/ @[to_additive is_add_torsion_of_finite "Finite additive groups are additive torsion groups."] theorem isTorsion_of_finite [Finite G] : IsTorsion G := ExponentExists.isTorsion .of_finite end Group section Module -- A (semi/)ring of scalars and a commutative monoid of elements variable (R M : Type*) [AddCommMonoid M] namespace AddMonoid /-- A module whose scalars are additively torsion is additively torsion. -/ theorem IsTorsion.module_of_torsion [Semiring R] [Module R M] (tR : IsTorsion R) : IsTorsion M := fun f => isOfFinAddOrder_iff_nsmul_eq_zero.mpr <| by obtain ⟨n, npos, hn⟩ := (tR 1).exists_nsmul_eq_zero exact ⟨n, npos, by simp only [← Nat.cast_smul_eq_nsmul R _ f, ← nsmul_one, hn, zero_smul]⟩ /-- A module with a finite ring of scalars is additively torsion. -/ theorem IsTorsion.module_of_finite [Ring R] [Finite R] [Module R M] : IsTorsion M := (is_add_torsion_of_finite : IsTorsion R).module_of_torsion _ _ end AddMonoid end Module section CommMonoid variable (G) [CommMonoid G] namespace CommMonoid /-- The torsion submonoid of a commutative monoid. (Note that by `Monoid.IsTorsion.group` torsion monoids are truthfully groups.) -/ @[to_additive addTorsion "The torsion submonoid of an additive commutative monoid."] def torsion : Submonoid G where carrier := { x | IsOfFinOrder x } one_mem' := isOfFinOrder_one mul_mem' hx hy := hx.mul hy variable {G} /-- Torsion submonoids are torsion. -/ @[to_additive "Additive torsion submonoids are additively torsion."] theorem torsion.isTorsion : IsTorsion <| torsion G := fun ⟨x, n, npos, hn⟩ => ⟨n, npos, Subtype.ext <| by dsimp rw [mul_left_iterate] change _ * 1 = 1 rw [_root_.mul_one, SubmonoidClass.coe_pow, Subtype.coe_mk, (isPeriodicPt_mul_iff_pow_eq_one _).mp hn]⟩ variable (G) (p : ℕ) [hp : Fact p.Prime] /-- The `p`-primary component is the submonoid of elements with order prime-power of `p`. -/ @[to_additive (attr := simps) "The `p`-primary component is the submonoid of elements with additive order prime-power of `p`."] def primaryComponent : Submonoid G where carrier := { g | ∃ n : ℕ, orderOf g = p ^ n } one_mem' := ⟨0, by rw [pow_zero, orderOf_one]⟩ mul_mem' hg₁ hg₂ := exists_orderOf_eq_prime_pow_iff.mpr <| by obtain ⟨m, hm⟩ := exists_orderOf_eq_prime_pow_iff.mp hg₁ obtain ⟨n, hn⟩ := exists_orderOf_eq_prime_pow_iff.mp hg₂ exact ⟨m + n, by rw [mul_pow, pow_add, pow_mul, hm, one_pow, Monoid.one_mul, mul_comm, pow_mul, hn, one_pow]⟩ variable {G} {p} /-- Elements of the `p`-primary component have order `p^n` for some `n`. -/ @[to_additive primaryComponent.exists_orderOf_eq_prime_nsmul "Elements of the `p`-primary component have additive order `p^n` for some `n`"] theorem primaryComponent.exists_orderOf_eq_prime_pow (g : CommMonoid.primaryComponent G p) : ∃ n : ℕ, orderOf g = p ^ n := by simpa [primaryComponent] using g.property /-- The `p`- and `q`-primary components are disjoint for `p ≠ q`. -/ @[to_additive "The `p`- and `q`-primary components are disjoint for `p ≠ q`."] theorem primaryComponent.disjoint {p' : ℕ} [hp' : Fact p'.Prime] (hne : p ≠ p') : Disjoint (CommMonoid.primaryComponent G p) (CommMonoid.primaryComponent G p') := Submonoid.disjoint_def.mpr <| by rintro g ⟨_ | n, hn⟩ ⟨n', hn'⟩ · rwa [pow_zero, orderOf_eq_one_iff] at hn · exact absurd (eq_of_prime_pow_eq hp.out.prime hp'.out.prime n.succ_pos (hn.symm.trans hn')) hne end CommMonoid open CommMonoid (torsion) namespace Monoid.IsTorsion variable {G} /-- The torsion submonoid of a torsion monoid is `⊤`. -/ @[to_additive (attr := simp) "The additive torsion submonoid of an additive torsion monoid is `⊤`."] theorem torsion_eq_top (tG : IsTorsion G) : torsion G = ⊤ := by ext; tauto /-- A torsion monoid is isomorphic to its torsion submonoid. -/ @[to_additive "An additive torsion monoid is isomorphic to its torsion submonoid."] def torsionMulEquiv (tG : IsTorsion G) : torsion G ≃* G := (MulEquiv.submonoidCongr tG.torsion_eq_top).trans Submonoid.topEquiv @[to_additive] theorem torsionMulEquiv_apply (tG : IsTorsion G) (a : torsion G) : tG.torsionMulEquiv a = MulEquiv.submonoidCongr tG.torsion_eq_top a := rfl @[to_additive] theorem torsionMulEquiv_symm_apply_coe (tG : IsTorsion G) (a : G) : tG.torsionMulEquiv.symm a = ⟨Submonoid.topEquiv.symm a, tG _⟩ := rfl end Monoid.IsTorsion /-- Torsion submonoids of a torsion submonoid are isomorphic to the submonoid. -/ @[to_additive (attr := simp) AddCommMonoid.Torsion.ofTorsion "Additive torsion submonoids of an additive torsion submonoid are isomorphic to the submonoid."] def Torsion.ofTorsion : torsion (torsion G) ≃* torsion G := Monoid.IsTorsion.torsionMulEquiv CommMonoid.torsion.isTorsion end CommMonoid section CommGroup variable (G) [CommGroup G] namespace CommGroup /-- The torsion subgroup of an abelian group. -/ @[to_additive "The torsion subgroup of an additive abelian group."] def torsion : Subgroup G := { CommMonoid.torsion G with inv_mem' := fun hx => IsOfFinOrder.inv hx } /-- The torsion submonoid of an abelian group equals the torsion subgroup as a submonoid. -/ @[to_additive add_torsion_eq_add_torsion_submonoid "The additive torsion submonoid of an abelian group equals the torsion subgroup as a submonoid."] theorem torsion_eq_torsion_submonoid : CommMonoid.torsion G = (torsion G).toSubmonoid := rfl @[to_additive] theorem mem_torsion (g : G) : g ∈ torsion G ↔ IsOfFinOrder g := Iff.rfl variable (p : ℕ) [hp : Fact p.Prime] /-- The `p`-primary component is the subgroup of elements with order prime-power of `p`. -/ @[to_additive (attr := simps!) "The `p`-primary component is the subgroup of elements with additive order prime-power of `p`."] def primaryComponent : Subgroup G := { CommMonoid.primaryComponent G p with inv_mem' := fun {g} ⟨n, hn⟩ => ⟨n, (orderOf_inv g).trans hn⟩ } variable {G} {p} /-- The `p`-primary component is a `p` group. -/ theorem primaryComponent.isPGroup : IsPGroup p <| primaryComponent G p := fun g => (propext exists_orderOf_eq_prime_pow_iff.symm).mpr (CommMonoid.primaryComponent.exists_orderOf_eq_prime_pow g) end CommGroup end CommGroup namespace Monoid variable (G) [Monoid G] /-- A predicate on a monoid saying that only 1 is of finite order. -/ @[to_additive "A predicate on an additive monoid saying that only 0 is of finite order."] def IsTorsionFree := ∀ g : G, g ≠ 1 → ¬IsOfFinOrder g variable {G} /-- A nontrivial monoid is not torsion-free if any nontrivial element has finite order. -/ @[to_additive (attr := simp) "An additive monoid is not torsion free if any nontrivial element has finite order."] theorem not_isTorsionFree_iff : ¬IsTorsionFree G ↔ ∃ g : G, g ≠ 1 ∧ IsOfFinOrder g := by simp_rw [IsTorsionFree, Ne, not_forall, Classical.not_not, exists_prop] @[to_additive (attr := simp)] lemma isTorsionFree_of_subsingleton [Subsingleton G] : IsTorsionFree G := fun _a ha _ => ha <| Subsingleton.elim _ _ @[to_additive] lemma isTorsionFree_iff_torsion_eq_bot {G} [CommGroup G] : IsTorsionFree G ↔ CommGroup.torsion G = ⊥ := by rw [IsTorsionFree, eq_bot_iff, SetLike.le_def] simp [not_imp_not, CommGroup.mem_torsion] end Monoid section Group open Monoid variable [Group G] /-- A nontrivial torsion group is not torsion-free. -/ @[to_additive AddMonoid.IsTorsion.not_torsion_free "A nontrivial additive torsion group is not torsion-free."] theorem IsTorsion.not_torsion_free [hN : Nontrivial G] : IsTorsion G → ¬IsTorsionFree G := fun tG => not_isTorsionFree_iff.mpr <| by obtain ⟨x, hx⟩ := (nontrivial_iff_exists_ne (1 : G)).mp hN exact ⟨x, hx, tG x⟩ /-- A nontrivial torsion-free group is not torsion. -/ @[to_additive AddMonoid.IsTorsionFree.not_torsion "A nontrivial torsion-free additive group is not torsion."] theorem IsTorsionFree.not_torsion [hN : Nontrivial G] : IsTorsionFree G → ¬IsTorsion G := fun tfG => (not_isTorsion_iff _).mpr <| by obtain ⟨x, hx⟩ := (nontrivial_iff_exists_ne (1 : G)).mp hN exact ⟨x, (tfG x) hx⟩ /-- Subgroups of torsion-free groups are torsion-free. -/ @[to_additive "Subgroups of additive torsion-free groups are additively torsion-free."] theorem IsTorsionFree.subgroup (tG : IsTorsionFree G) (H : Subgroup G) : IsTorsionFree H := fun h hne ↦ Submonoid.isOfFinOrder_coe.not.1 <| tG h <| by norm_cast /-- Direct products of torsion free groups are torsion free. -/ @[to_additive AddMonoid.IsTorsionFree.prod "Direct products of additive torsion free groups are torsion free."] theorem IsTorsionFree.prod {η : Type*} {Gs : η → Type*} [∀ i, Group (Gs i)] (tfGs : ∀ i, IsTorsionFree (Gs i)) : IsTorsionFree <| ∀ i, Gs i := fun w hne h => hne <| funext fun i => Classical.not_not.mp <| mt (tfGs i (w i)) <| Classical.not_not.mpr <| h.apply i end Group section CommGroup open Monoid (IsTorsionFree) open CommGroup (torsion) variable (G) [CommGroup G] /-- Quotienting a group by its torsion subgroup yields a torsion free group. -/ @[to_additive AddIsTorsionFree.quotient_torsion "Quotienting a group by its additive torsion subgroup yields an additive torsion free group."] theorem IsTorsionFree.quotient_torsion : IsTorsionFree <| G ⧸ torsion G := fun g hne hfin => hne <| by induction' g using QuotientGroup.induction_on with g obtain ⟨m, mpos, hm⟩ := hfin.exists_pow_eq_one obtain ⟨n, npos, hn⟩ := ((QuotientGroup.eq_one_iff _).mp hm).exists_pow_eq_one exact (QuotientGroup.eq_one_iff g).mpr (isOfFinOrder_iff_pow_eq_one.mpr ⟨m * n, mul_pos mpos npos, (pow_mul g m n).symm ▸ hn⟩) end CommGroup lemma isTorsionFree_iff_noZeroSMulDivisors_nat {M : Type*} [AddMonoid M] : AddMonoid.IsTorsionFree M ↔ NoZeroSMulDivisors ℕ M := by simp_rw [AddMonoid.IsTorsionFree, isOfFinAddOrder_iff_nsmul_eq_zero, not_exists, not_and, pos_iff_ne_zero, noZeroSMulDivisors_iff, forall_swap (β := ℕ)] exact forall₂_congr fun _ _ ↦ by tauto lemma isTorsionFree_iff_noZeroSMulDivisors_int [AddGroup G] : AddMonoid.IsTorsionFree G ↔ NoZeroSMulDivisors ℤ G := by simp_rw [AddMonoid.IsTorsionFree, isOfFinAddOrder_iff_zsmul_eq_zero, not_exists, not_and, noZeroSMulDivisors_iff, forall_swap (β := ℤ)] exact forall₂_congr fun _ _ ↦ by tauto @[deprecated (since := "2024-02-29")] alias AddMonoid.IsTorsionFree_iff_noZeroSMulDivisors := isTorsionFree_iff_noZeroSMulDivisors_int lemma IsTorsionFree.of_noZeroSMulDivisors {M : Type*} [AddMonoid M] [NoZeroSMulDivisors ℕ M] : AddMonoid.IsTorsionFree M := isTorsionFree_iff_noZeroSMulDivisors_nat.2 ‹_›
GroupTheory\Transfer.lean
/- Copyright (c) 2022 Thomas Browning. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning -/ import Mathlib.GroupTheory.Complement import Mathlib.GroupTheory.Sylow /-! # The Transfer Homomorphism In this file we construct the transfer homomorphism. ## Main definitions - `diff ϕ S T` : The difference of two left transversals `S` and `T` under the homomorphism `ϕ`. - `transfer ϕ` : The transfer homomorphism induced by `ϕ`. - `transferCenterPow`: The transfer homomorphism `G →* center G`. ## Main results - `transferCenterPow_apply`: The transfer homomorphism `G →* center G` is given by `g ↦ g ^ (center G).index`. - `ker_transferSylow_isComplement'`: Burnside's transfer (or normal `p`-complement) theorem: If `hP : N(P) ≤ C(P)`, then `(transfer P hP).ker` is a normal `p`-complement. -/ variable {G : Type*} [Group G] {H : Subgroup G} {A : Type*} [CommGroup A] (ϕ : H →* A) namespace Subgroup namespace leftTransversals open Finset MulAction open scoped Pointwise variable (R S T : leftTransversals (H : Set G)) [FiniteIndex H] /-- The difference of two left transversals -/ @[to_additive "The difference of two left transversals"] noncomputable def diff : A := let α := MemLeftTransversals.toEquiv S.2 let β := MemLeftTransversals.toEquiv T.2 (@Finset.univ (G ⧸ H) H.fintypeQuotientOfFiniteIndex).prod fun q => ϕ ⟨(α q : G)⁻¹ * β q, QuotientGroup.leftRel_apply.mp <| Quotient.exact' ((α.symm_apply_apply q).trans (β.symm_apply_apply q).symm)⟩ @[to_additive] theorem diff_mul_diff : diff ϕ R S * diff ϕ S T = diff ϕ R T := prod_mul_distrib.symm.trans (prod_congr rfl fun q _ => (ϕ.map_mul _ _).symm.trans (congr_arg ϕ (by simp_rw [Subtype.ext_iff, coe_mul, mul_assoc, mul_inv_cancel_left]))) @[to_additive] theorem diff_self : diff ϕ T T = 1 := mul_right_eq_self.mp (diff_mul_diff ϕ T T T) @[to_additive] theorem diff_inv : (diff ϕ S T)⁻¹ = diff ϕ T S := inv_eq_of_mul_eq_one_right <| (diff_mul_diff ϕ S T S).trans <| diff_self ϕ S @[to_additive] theorem smul_diff_smul (g : G) : diff ϕ (g • S) (g • T) = diff ϕ S T := let _ := H.fintypeQuotientOfFiniteIndex Fintype.prod_equiv (MulAction.toPerm g).symm _ _ fun _ ↦ by simp only [smul_apply_eq_smul_apply_inv_smul, smul_eq_mul, mul_inv_rev, mul_assoc, inv_mul_cancel_left, toPerm_symm_apply] end leftTransversals end Subgroup namespace MonoidHom open MulAction Subgroup Subgroup.leftTransversals /-- Given `ϕ : H →* A` from `H : Subgroup G` to a commutative group `A`, the transfer homomorphism is `transfer ϕ : G →* A`. -/ @[to_additive "Given `ϕ : H →+ A` from `H : AddSubgroup G` to an additive commutative group `A`, the transfer homomorphism is `transfer ϕ : G →+ A`."] noncomputable def transfer [FiniteIndex H] : G →* A := let T : leftTransversals (H : Set G) := Inhabited.default { toFun := fun g => diff ϕ T (g • T) -- Porting note(#12129): additional beta reduction needed map_one' := by beta_reduce; rw [one_smul, diff_self] -- Porting note: added `simp only` (not just beta reduction) map_mul' := fun g h => by simp only; rw [mul_smul, ← diff_mul_diff, smul_diff_smul] } variable (T : leftTransversals (H : Set G)) @[to_additive] theorem transfer_def [FiniteIndex H] (g : G) : transfer ϕ g = diff ϕ T (g • T) := by rw [transfer, ← diff_mul_diff, ← smul_diff_smul, mul_comm, diff_mul_diff] <;> rfl /-- Explicit computation of the transfer homomorphism. -/ theorem transfer_eq_prod_quotient_orbitRel_zpowers_quot [FiniteIndex H] (g : G) [Fintype (Quotient (orbitRel (zpowers g) (G ⧸ H)))] : transfer ϕ g = ∏ q : Quotient (orbitRel (zpowers g) (G ⧸ H)), ϕ ⟨q.out'.out'⁻¹ * g ^ Function.minimalPeriod (g • ·) q.out' * q.out'.out', QuotientGroup.out'_conj_pow_minimalPeriod_mem H g q.out'⟩ := by classical letI := H.fintypeQuotientOfFiniteIndex calc transfer ϕ g = ∏ q : G ⧸ H, _ := transfer_def ϕ (transferTransversal H g) g _ = _ := ((quotientEquivSigmaZMod H g).symm.prod_comp _).symm _ = _ := Finset.prod_sigma _ _ _ _ = _ := by refine Fintype.prod_congr _ _ (fun q => ?_) simp only [quotientEquivSigmaZMod_symm_apply, transferTransversal_apply', transferTransversal_apply''] rw [Fintype.prod_eq_single (0 : ZMod (Function.minimalPeriod (g • ·) q.out')) _] · simp only [if_pos, ZMod.cast_zero, zpow_zero, one_mul, mul_assoc] · intro k hk simp only [if_neg hk, inv_mul_self] exact map_one ϕ /-- Auxiliary lemma in order to state `transfer_eq_pow`. -/ theorem transfer_eq_pow_aux (g : G) (key : ∀ (k : ℕ) (g₀ : G), g₀⁻¹ * g ^ k * g₀ ∈ H → g₀⁻¹ * g ^ k * g₀ = g ^ k) : g ^ H.index ∈ H := by by_cases hH : H.index = 0 · rw [hH, pow_zero] exact H.one_mem letI := fintypeOfIndexNeZero hH classical replace key : ∀ (k : ℕ) (g₀ : G), g₀⁻¹ * g ^ k * g₀ ∈ H → g ^ k ∈ H := fun k g₀ hk => (congr_arg (· ∈ H) (key k g₀ hk)).mp hk replace key : ∀ q : G ⧸ H, g ^ Function.minimalPeriod (g • ·) q ∈ H := fun q => key (Function.minimalPeriod (g • ·) q) q.out' (QuotientGroup.out'_conj_pow_minimalPeriod_mem H g q) let f : Quotient (orbitRel (zpowers g) (G ⧸ H)) → zpowers g := fun q => (⟨g, mem_zpowers g⟩ : zpowers g) ^ Function.minimalPeriod (g • ·) q.out' have hf : ∀ q, f q ∈ H.subgroupOf (zpowers g) := fun q => key q.out' replace key := Subgroup.prod_mem (H.subgroupOf (zpowers g)) fun q (_ : q ∈ Finset.univ) => hf q simpa only [f, minimalPeriod_eq_card, Finset.prod_pow_eq_pow_sum, Fintype.card_sigma, Fintype.card_congr (selfEquivSigmaOrbits (zpowers g) (G ⧸ H)), index_eq_card, Nat.card_eq_fintype_card] using key theorem transfer_eq_pow [FiniteIndex H] (g : G) (key : ∀ (k : ℕ) (g₀ : G), g₀⁻¹ * g ^ k * g₀ ∈ H → g₀⁻¹ * g ^ k * g₀ = g ^ k) : transfer ϕ g = ϕ ⟨g ^ H.index, transfer_eq_pow_aux g key⟩ := by classical letI := H.fintypeQuotientOfFiniteIndex change ∀ (k g₀) (hk : g₀⁻¹ * g ^ k * g₀ ∈ H), ↑(⟨g₀⁻¹ * g ^ k * g₀, hk⟩ : H) = g ^ k at key rw [transfer_eq_prod_quotient_orbitRel_zpowers_quot, ← Finset.prod_to_list] refine (List.prod_map_hom _ _ _).trans ?_ -- Porting note: this used to be in the `rw` refine congrArg ϕ (Subtype.coe_injective ?_) simp only -- Porting note: added `simp only` rw [H.coe_mk, ← (zpowers g).coe_mk g (mem_zpowers g), ← (zpowers g).coe_pow, index_eq_card, Nat.card_eq_fintype_card, Fintype.card_congr (selfEquivSigmaOrbits (zpowers g) (G ⧸ H)), Fintype.card_sigma, ← Finset.prod_pow_eq_pow_sum, ← Finset.prod_to_list] simp only [Subgroup.val_list_prod, List.map_map, ← minimalPeriod_eq_card] congr funext apply key theorem transfer_center_eq_pow [FiniteIndex (center G)] (g : G) : transfer (MonoidHom.id (center G)) g = ⟨g ^ (center G).index, (center G).pow_index_mem g⟩ := transfer_eq_pow (id (center G)) g fun k _ hk => by rw [← mul_right_inj, ← hk.comm, mul_inv_cancel_right] variable (G) /-- The transfer homomorphism `G →* center G`. -/ noncomputable def transferCenterPow [FiniteIndex (center G)] : G →* center G where toFun g := ⟨g ^ (center G).index, (center G).pow_index_mem g⟩ map_one' := Subtype.ext (one_pow (center G).index) map_mul' a b := by simp_rw [← show ∀ _, (_ : center G) = _ from transfer_center_eq_pow, map_mul] variable {G} @[simp] theorem transferCenterPow_apply [FiniteIndex (center G)] (g : G) : ↑(transferCenterPow G g) = g ^ (center G).index := rfl section BurnsideTransfer variable {p : ℕ} (P : Sylow p G) (hP : (P : Subgroup G).normalizer ≤ centralizer (P : Set G)) /-- The homomorphism `G →* P` in Burnside's transfer theorem. -/ noncomputable def transferSylow [FiniteIndex (P : Subgroup G)] : G →* (P : Subgroup G) := @transfer G _ P P (@Subgroup.IsCommutative.commGroup G _ P ⟨⟨fun a b => Subtype.ext (hP (le_normalizer b.2) a a.2)⟩⟩) (MonoidHom.id P) _ variable [Fact p.Prime] [Finite (Sylow p G)] /-- Auxiliary lemma in order to state `transferSylow_eq_pow`. -/ theorem transferSylow_eq_pow_aux (g : G) (hg : g ∈ P) (k : ℕ) (g₀ : G) (h : g₀⁻¹ * g ^ k * g₀ ∈ P) : g₀⁻¹ * g ^ k * g₀ = g ^ k := by haveI : (P : Subgroup G).IsCommutative := ⟨⟨fun a b => Subtype.ext (hP (le_normalizer b.2) a a.2)⟩⟩ replace hg := (P : Subgroup G).pow_mem hg k obtain ⟨n, hn, h⟩ := P.conj_eq_normalizer_conj_of_mem (g ^ k) g₀ hg h exact h.trans (Commute.inv_mul_cancel (hP hn (g ^ k) hg).symm) variable [FiniteIndex (P : Subgroup G)] theorem transferSylow_eq_pow (g : G) (hg : g ∈ P) : transferSylow P hP g = ⟨g ^ (P : Subgroup G).index, transfer_eq_pow_aux g (transferSylow_eq_pow_aux P hP g hg)⟩ := @transfer_eq_pow G _ P P (@Subgroup.IsCommutative.commGroup G _ P ⟨⟨fun a b => Subtype.ext (hP (le_normalizer b.2) a a.2)⟩⟩) _ _ g (transferSylow_eq_pow_aux P hP g hg) -- Porting note: apply used to do this automatically theorem transferSylow_restrict_eq_pow : ⇑((transferSylow P hP).restrict (P : Subgroup G)) = (fun x : P => x ^ (P : Subgroup G).index) := funext fun g => transferSylow_eq_pow P hP g g.2 /-- **Burnside's normal p-complement theorem**: If `N(P) ≤ C(P)`, then `P` has a normal complement. -/ theorem ker_transferSylow_isComplement' : IsComplement' (transferSylow P hP).ker P := by have hf : Function.Bijective ((transferSylow P hP).restrict (P : Subgroup G)) := (transferSylow_restrict_eq_pow P hP).symm ▸ (P.2.powEquiv' (not_dvd_index_sylow P (mt index_eq_zero_of_relindex_eq_zero index_ne_zero_of_finite))).bijective rw [Function.Bijective, ← range_top_iff_surjective, restrict_range] at hf have := range_top_iff_surjective.mp (top_le_iff.mp (hf.2.ge.trans (map_le_range (transferSylow P hP) P))) rw [← (comap_injective this).eq_iff, comap_top, comap_map_eq, sup_comm, SetLike.ext'_iff, normal_mul, ← ker_eq_bot_iff, ← (map_injective (P : Subgroup G).subtype_injective).eq_iff, ker_restrict, subgroupOf_map_subtype, Subgroup.map_bot, coe_top] at hf exact isComplement'_of_disjoint_and_mul_eq_univ (disjoint_iff.2 hf.1) hf.2 theorem not_dvd_card_ker_transferSylow : ¬p ∣ Nat.card (transferSylow P hP).ker := (ker_transferSylow_isComplement' P hP).index_eq_card ▸ not_dvd_index_sylow P <| mt index_eq_zero_of_relindex_eq_zero index_ne_zero_of_finite theorem ker_transferSylow_disjoint (Q : Subgroup G) (hQ : IsPGroup p Q) : Disjoint (transferSylow P hP).ker Q := disjoint_iff.mpr <| card_eq_one.mp <| (hQ.to_le inf_le_right).card_eq_or_dvd.resolve_right fun h => not_dvd_card_ker_transferSylow P hP <| h.trans <| card_dvd_of_le inf_le_left end BurnsideTransfer end MonoidHom
GroupTheory\Congruence\Basic.lean
/- Copyright (c) 2019 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Amelia Livingston -/ import Mathlib.Algebra.Group.Equiv.Basic import Mathlib.Algebra.Group.Submonoid.Operations import Mathlib.Algebra.GroupWithZero.Action.Defs import Mathlib.Data.Setoid.Basic /-! # Congruence relations This file defines congruence relations: equivalence relations that preserve a binary operation, which in this case is multiplication or addition. The principal definition is a `structure` extending a `Setoid` (an equivalence relation), and the inductive definition of the smallest congruence relation containing a binary relation is also given (see `ConGen`). The file also proves basic properties of the quotient of a type by a congruence relation, and the complete lattice of congruence relations on a type. We then establish an order-preserving bijection between the set of congruence relations containing a congruence relation `c` and the set of congruence relations on the quotient by `c`. The second half of the file concerns congruence relations on monoids, in which case the quotient by the congruence relation is also a monoid. There are results about the universal property of quotients of monoids, and the isomorphism theorems for monoids. ## Implementation notes The inductive definition of a congruence relation could be a nested inductive type, defined using the equivalence closure of a binary relation `EqvGen`, but the recursor generated does not work. A nested inductive definition could conceivably shorten proofs, because they would allow invocation of the corresponding lemmas about `EqvGen`. The lemmas `refl`, `symm` and `trans` are not tagged with `@[refl]`, `@[symm]`, and `@[trans]` respectively as these tags do not work on a structure coerced to a binary relation. There is a coercion from elements of a type to the element's equivalence class under a congruence relation. A congruence relation on a monoid `M` can be thought of as a submonoid of `M × M` for which membership is an equivalence relation, but whilst this fact is established in the file, it is not used, since this perspective adds more layers of definitional unfolding. ## Tags congruence, congruence relation, quotient, quotient by congruence relation, monoid, quotient monoid, isomorphism theorems -/ variable (M : Type*) {N : Type*} {P : Type*} open Function Setoid /-- A congruence relation on a type with an addition is an equivalence relation which preserves addition. -/ structure AddCon [Add M] extends Setoid M where /-- Additive congruence relations are closed under addition -/ add' : ∀ {w x y z}, r w x → r y z → r (w + y) (x + z) /-- A congruence relation on a type with a multiplication is an equivalence relation which preserves multiplication. -/ @[to_additive AddCon] structure Con [Mul M] extends Setoid M where /-- Congruence relations are closed under multiplication -/ mul' : ∀ {w x y z}, r w x → r y z → r (w * y) (x * z) /-- The equivalence relation underlying an additive congruence relation. -/ add_decl_doc AddCon.toSetoid /-- The equivalence relation underlying a multiplicative congruence relation. -/ add_decl_doc Con.toSetoid variable {M} /-- The inductively defined smallest additive congruence relation containing a given binary relation. -/ inductive AddConGen.Rel [Add M] (r : M → M → Prop) : M → M → Prop | of : ∀ x y, r x y → AddConGen.Rel r x y | refl : ∀ x, AddConGen.Rel r x x | symm : ∀ {x y}, AddConGen.Rel r x y → AddConGen.Rel r y x | trans : ∀ {x y z}, AddConGen.Rel r x y → AddConGen.Rel r y z → AddConGen.Rel r x z | add : ∀ {w x y z}, AddConGen.Rel r w x → AddConGen.Rel r y z → AddConGen.Rel r (w + y) (x + z) /-- The inductively defined smallest multiplicative congruence relation containing a given binary relation. -/ @[to_additive AddConGen.Rel] inductive ConGen.Rel [Mul M] (r : M → M → Prop) : M → M → Prop | of : ∀ x y, r x y → ConGen.Rel r x y | refl : ∀ x, ConGen.Rel r x x | symm : ∀ {x y}, ConGen.Rel r x y → ConGen.Rel r y x | trans : ∀ {x y z}, ConGen.Rel r x y → ConGen.Rel r y z → ConGen.Rel r x z | mul : ∀ {w x y z}, ConGen.Rel r w x → ConGen.Rel r y z → ConGen.Rel r (w * y) (x * z) /-- The inductively defined smallest multiplicative congruence relation containing a given binary relation. -/ @[to_additive addConGen "The inductively defined smallest additive congruence relation containing a given binary relation."] def conGen [Mul M] (r : M → M → Prop) : Con M := ⟨⟨ConGen.Rel r, ⟨ConGen.Rel.refl, ConGen.Rel.symm, ConGen.Rel.trans⟩⟩, ConGen.Rel.mul⟩ namespace Con section variable [Mul M] [Mul N] [Mul P] (c : Con M) @[to_additive] instance : Inhabited (Con M) := ⟨conGen EmptyRelation⟩ -- Porting note: upgraded to FunLike /-- A coercion from a congruence relation to its underlying binary relation. -/ @[to_additive "A coercion from an additive congruence relation to its underlying binary relation."] instance : FunLike (Con M) M (M → Prop) where coe c := c.r coe_injective' := fun x y h => by rcases x with ⟨⟨x, _⟩, _⟩ rcases y with ⟨⟨y, _⟩, _⟩ have : x = y := h subst x; rfl @[to_additive (attr := simp)] theorem rel_eq_coe (c : Con M) : c.r = c := rfl /-- Congruence relations are reflexive. -/ @[to_additive "Additive congruence relations are reflexive."] protected theorem refl (x) : c x x := c.toSetoid.refl' x /-- Congruence relations are symmetric. -/ @[to_additive "Additive congruence relations are symmetric."] protected theorem symm {x y} : c x y → c y x := c.toSetoid.symm' /-- Congruence relations are transitive. -/ @[to_additive "Additive congruence relations are transitive."] protected theorem trans {x y z} : c x y → c y z → c x z := c.toSetoid.trans' /-- Multiplicative congruence relations preserve multiplication. -/ @[to_additive "Additive congruence relations preserve addition."] protected theorem mul {w x y z} : c w x → c y z → c (w * y) (x * z) := c.mul' @[to_additive (attr := simp)] theorem rel_mk {s : Setoid M} {h a b} : Con.mk s h a b ↔ r a b := Iff.rfl /-- Given a type `M` with a multiplication, a congruence relation `c` on `M`, and elements of `M` `x, y`, `(x, y) ∈ M × M` iff `x` is related to `y` by `c`. -/ @[to_additive "Given a type `M` with an addition, `x, y ∈ M`, and an additive congruence relation `c` on `M`, `(x, y) ∈ M × M` iff `x` is related to `y` by `c`."] instance : Membership (M × M) (Con M) := ⟨fun x c => c x.1 x.2⟩ variable {c} /-- The map sending a congruence relation to its underlying binary relation is injective. -/ @[to_additive "The map sending an additive congruence relation to its underlying binary relation is injective."] theorem ext' {c d : Con M} (H : ⇑c = ⇑d) : c = d := DFunLike.coe_injective H /-- Extensionality rule for congruence relations. -/ @[to_additive (attr := ext) "Extensionality rule for additive congruence relations."] theorem ext {c d : Con M} (H : ∀ x y, c x y ↔ d x y) : c = d := ext' <| by ext; apply H /-- The map sending a congruence relation to its underlying equivalence relation is injective. -/ @[to_additive "The map sending an additive congruence relation to its underlying equivalence relation is injective."] theorem toSetoid_inj {c d : Con M} (H : c.toSetoid = d.toSetoid) : c = d := ext <| ext_iff.1 H /-- Two congruence relations are equal iff their underlying binary relations are equal. -/ @[to_additive "Two additive congruence relations are equal iff their underlying binary relations are equal."] theorem coe_inj {c d : Con M} : ⇑c = ⇑d ↔ c = d := DFunLike.coe_injective.eq_iff /-- The kernel of a multiplication-preserving function as a congruence relation. -/ @[to_additive "The kernel of an addition-preserving function as an additive congruence relation."] def mulKer (f : M → P) (h : ∀ x y, f (x * y) = f x * f y) : Con M where toSetoid := Setoid.ker f mul' h1 h2 := by dsimp [Setoid.ker, onFun] at * rw [h, h1, h2, h] /-- Given types with multiplications `M, N`, the product of two congruence relations `c` on `M` and `d` on `N`: `(x₁, x₂), (y₁, y₂) ∈ M × N` are related by `c.prod d` iff `x₁` is related to `y₁` by `c` and `x₂` is related to `y₂` by `d`. -/ @[to_additive prod "Given types with additions `M, N`, the product of two congruence relations `c` on `M` and `d` on `N`: `(x₁, x₂), (y₁, y₂) ∈ M × N` are related by `c.prod d` iff `x₁` is related to `y₁` by `c` and `x₂` is related to `y₂` by `d`."] protected def prod (c : Con M) (d : Con N) : Con (M × N) := { c.toSetoid.prod d.toSetoid with mul' := fun h1 h2 => ⟨c.mul h1.1 h2.1, d.mul h1.2 h2.2⟩ } /-- The product of an indexed collection of congruence relations. -/ @[to_additive "The product of an indexed collection of additive congruence relations."] def pi {ι : Type*} {f : ι → Type*} [∀ i, Mul (f i)] (C : ∀ i, Con (f i)) : Con (∀ i, f i) := { @piSetoid _ _ fun i => (C i).toSetoid with mul' := fun h1 h2 i => (C i).mul (h1 i) (h2 i) } variable (c) -- Quotients /-- Defining the quotient by a congruence relation of a type with a multiplication. -/ @[to_additive "Defining the quotient by an additive congruence relation of a type with an addition."] protected def Quotient := Quotient c.toSetoid -- Porting note: made implicit variable {c} /-- The morphism into the quotient by a congruence relation -/ @[to_additive (attr := coe) "The morphism into the quotient by an additive congruence relation"] def toQuotient : M → c.Quotient := Quotient.mk'' variable (c) -- Porting note: was `priority 0`. why? /-- Coercion from a type with a multiplication to its quotient by a congruence relation. See Note [use has_coe_t]. -/ @[to_additive "Coercion from a type with an addition to its quotient by an additive congruence relation"] instance (priority := 10) : CoeTC M c.Quotient := ⟨toQuotient⟩ -- Lower the priority since it unifies with any quotient type. /-- The quotient by a decidable congruence relation has decidable equality. -/ @[to_additive "The quotient by a decidable additive congruence relation has decidable equality."] instance (priority := 500) [∀ a b, Decidable (c a b)] : DecidableEq c.Quotient := inferInstanceAs (DecidableEq (Quotient c.toSetoid)) @[to_additive (attr := simp)] theorem quot_mk_eq_coe {M : Type*} [Mul M] (c : Con M) (x : M) : Quot.mk c x = (x : c.Quotient) := rfl -- Porting note (#11215): TODO: restore `elab_as_elim` /-- The function on the quotient by a congruence relation `c` induced by a function that is constant on `c`'s equivalence classes. -/ @[to_additive "The function on the quotient by a congruence relation `c` induced by a function that is constant on `c`'s equivalence classes."] protected def liftOn {β} {c : Con M} (q : c.Quotient) (f : M → β) (h : ∀ a b, c a b → f a = f b) : β := Quotient.liftOn' q f h -- Porting note (#11215): TODO: restore `elab_as_elim` /-- The binary function on the quotient by a congruence relation `c` induced by a binary function that is constant on `c`'s equivalence classes. -/ @[to_additive "The binary function on the quotient by a congruence relation `c` induced by a binary function that is constant on `c`'s equivalence classes."] protected def liftOn₂ {β} {c : Con M} (q r : c.Quotient) (f : M → M → β) (h : ∀ a₁ a₂ b₁ b₂, c a₁ b₁ → c a₂ b₂ → f a₁ a₂ = f b₁ b₂) : β := Quotient.liftOn₂' q r f h /-- A version of `Quotient.hrecOn₂'` for quotients by `Con`. -/ @[to_additive "A version of `Quotient.hrecOn₂'` for quotients by `AddCon`."] protected def hrecOn₂ {cM : Con M} {cN : Con N} {φ : cM.Quotient → cN.Quotient → Sort*} (a : cM.Quotient) (b : cN.Quotient) (f : ∀ (x : M) (y : N), φ x y) (h : ∀ x y x' y', cM x x' → cN y y' → HEq (f x y) (f x' y')) : φ a b := Quotient.hrecOn₂' a b f h @[to_additive (attr := simp)] theorem hrec_on₂_coe {cM : Con M} {cN : Con N} {φ : cM.Quotient → cN.Quotient → Sort*} (a : M) (b : N) (f : ∀ (x : M) (y : N), φ x y) (h : ∀ x y x' y', cM x x' → cN y y' → HEq (f x y) (f x' y')) : Con.hrecOn₂ (↑a) (↑b) f h = f a b := rfl variable {c} /-- The inductive principle used to prove propositions about the elements of a quotient by a congruence relation. -/ @[to_additive (attr := elab_as_elim) "The inductive principle used to prove propositions about the elements of a quotient by an additive congruence relation."] protected theorem induction_on {C : c.Quotient → Prop} (q : c.Quotient) (H : ∀ x : M, C x) : C q := Quotient.inductionOn' q H /-- A version of `Con.induction_on` for predicates which take two arguments. -/ @[to_additive (attr := elab_as_elim) "A version of `AddCon.induction_on` for predicates which take two arguments."] protected theorem induction_on₂ {d : Con N} {C : c.Quotient → d.Quotient → Prop} (p : c.Quotient) (q : d.Quotient) (H : ∀ (x : M) (y : N), C x y) : C p q := Quotient.inductionOn₂' p q H variable (c) /-- Two elements are related by a congruence relation `c` iff they are represented by the same element of the quotient by `c`. -/ @[to_additive (attr := simp) "Two elements are related by an additive congruence relation `c` iff they are represented by the same element of the quotient by `c`."] protected theorem eq {a b : M} : (a : c.Quotient) = (b : c.Quotient) ↔ c a b := Quotient.eq'' /-- The multiplication induced on the quotient by a congruence relation on a type with a multiplication. -/ @[to_additive "The addition induced on the quotient by an additive congruence relation on a type with an addition."] instance hasMul : Mul c.Quotient := ⟨Quotient.map₂' (· * ·) fun _ _ h1 _ _ h2 => c.mul h1 h2⟩ /-- The kernel of the quotient map induced by a congruence relation `c` equals `c`. -/ @[to_additive (attr := simp) "The kernel of the quotient map induced by an additive congruence relation `c` equals `c`."] theorem mul_ker_mk_eq : (mulKer ((↑) : M → c.Quotient) fun _ _ => rfl) = c := ext fun _ _ => Quotient.eq'' variable {c} /-- The coercion to the quotient of a congruence relation commutes with multiplication (by definition). -/ @[to_additive (attr := simp) "The coercion to the quotient of an additive congruence relation commutes with addition (by definition)."] theorem coe_mul (x y : M) : (↑(x * y) : c.Quotient) = ↑x * ↑y := rfl /-- Definition of the function on the quotient by a congruence relation `c` induced by a function that is constant on `c`'s equivalence classes. -/ @[to_additive (attr := simp) "Definition of the function on the quotient by an additive congruence relation `c` induced by a function that is constant on `c`'s equivalence classes."] protected theorem liftOn_coe {β} (c : Con M) (f : M → β) (h : ∀ a b, c a b → f a = f b) (x : M) : Con.liftOn (x : c.Quotient) f h = f x := rfl /-- Makes an isomorphism of quotients by two congruence relations, given that the relations are equal. -/ @[to_additive "Makes an additive isomorphism of quotients by two additive congruence relations, given that the relations are equal."] protected def congr {c d : Con M} (h : c = d) : c.Quotient ≃* d.Quotient := { Quotient.congr (Equiv.refl M) <| by apply Con.ext_iff.mp h with map_mul' := fun x y => by rcases x with ⟨⟩; rcases y with ⟨⟩; rfl } -- The complete lattice of congruence relations on a type /-- For congruence relations `c, d` on a type `M` with a multiplication, `c ≤ d` iff `∀ x y ∈ M`, `x` is related to `y` by `d` if `x` is related to `y` by `c`. -/ @[to_additive "For additive congruence relations `c, d` on a type `M` with an addition, `c ≤ d` iff `∀ x y ∈ M`, `x` is related to `y` by `d` if `x` is related to `y` by `c`."] instance : LE (Con M) where le c d := ∀ ⦃x y⦄, c x y → d x y /-- Definition of `≤` for congruence relations. -/ @[to_additive "Definition of `≤` for additive congruence relations."] theorem le_def {c d : Con M} : c ≤ d ↔ ∀ {x y}, c x y → d x y := Iff.rfl /-- The infimum of a set of congruence relations on a given type with a multiplication. -/ @[to_additive "The infimum of a set of additive congruence relations on a given type with an addition."] instance : InfSet (Con M) where sInf S := { r := fun x y => ∀ c : Con M, c ∈ S → c x y iseqv := ⟨fun x c _ => c.refl x, fun h c hc => c.symm <| h c hc, fun h1 h2 c hc => c.trans (h1 c hc) <| h2 c hc⟩ mul' := fun h1 h2 c hc => c.mul (h1 c hc) <| h2 c hc } /-- The infimum of a set of congruence relations is the same as the infimum of the set's image under the map to the underlying equivalence relation. -/ @[to_additive "The infimum of a set of additive congruence relations is the same as the infimum of the set's image under the map to the underlying equivalence relation."] theorem sInf_toSetoid (S : Set (Con M)) : (sInf S).toSetoid = sInf (toSetoid '' S) := Setoid.ext' fun x y => ⟨fun h r ⟨c, hS, hr⟩ => by rw [← hr]; exact h c hS, fun h c hS => h c.toSetoid ⟨c, hS, rfl⟩⟩ /-- The infimum of a set of congruence relations is the same as the infimum of the set's image under the map to the underlying binary relation. -/ @[to_additive (attr := simp, norm_cast) "The infimum of a set of additive congruence relations is the same as the infimum of the set's image under the map to the underlying binary relation."] theorem coe_sInf (S : Set (Con M)) : ⇑(sInf S) = sInf ((⇑) '' S) := by ext simp only [sInf_image, iInf_apply, iInf_Prop_eq] rfl @[to_additive (attr := simp, norm_cast)] theorem coe_iInf {ι : Sort*} (f : ι → Con M) : ⇑(iInf f) = ⨅ i, ⇑(f i) := by rw [iInf, coe_sInf, ← Set.range_comp, sInf_range, Function.comp] @[to_additive] instance : PartialOrder (Con M) where le_refl _ _ _ := id le_trans _ _ _ h1 h2 _ _ h := h2 <| h1 h le_antisymm _ _ hc hd := ext fun _ _ => ⟨fun h => hc h, fun h => hd h⟩ /-- The complete lattice of congruence relations on a given type with a multiplication. -/ @[to_additive "The complete lattice of additive congruence relations on a given type with an addition."] instance : CompleteLattice (Con M) where __ := completeLatticeOfInf (Con M) fun s => ⟨fun r hr x y h => (h : ∀ r ∈ s, (r : Con M) x y) r hr, fun r hr x y h r' hr' => hr hr' h⟩ inf c d := ⟨c.toSetoid ⊓ d.toSetoid, fun h1 h2 => ⟨c.mul h1.1 h2.1, d.mul h1.2 h2.2⟩⟩ inf_le_left _ _ := fun _ _ h => h.1 inf_le_right _ _ := fun _ _ h => h.2 le_inf _ _ _ hb hc := fun _ _ h => ⟨hb h, hc h⟩ top := { Setoid.completeLattice.top with mul' := by tauto } le_top _ := fun _ _ _ => trivial bot := { Setoid.completeLattice.bot with mul' := fun h1 h2 => h1 ▸ h2 ▸ rfl } bot_le c := fun x y h => h ▸ c.refl x /-- The infimum of two congruence relations equals the infimum of the underlying binary operations. -/ @[to_additive (attr := simp, norm_cast) "The infimum of two additive congruence relations equals the infimum of the underlying binary operations."] theorem coe_inf {c d : Con M} : ⇑(c ⊓ d) = ⇑c ⊓ ⇑d := rfl /-- Definition of the infimum of two congruence relations. -/ @[to_additive "Definition of the infimum of two additive congruence relations."] theorem inf_iff_and {c d : Con M} {x y} : (c ⊓ d) x y ↔ c x y ∧ d x y := Iff.rfl /-- The inductively defined smallest congruence relation containing a binary relation `r` equals the infimum of the set of congruence relations containing `r`. -/ @[to_additive addConGen_eq "The inductively defined smallest additive congruence relation containing a binary relation `r` equals the infimum of the set of additive congruence relations containing `r`."] theorem conGen_eq (r : M → M → Prop) : conGen r = sInf { s : Con M | ∀ x y, r x y → s x y } := le_antisymm (le_sInf (fun s hs x y (hxy : (conGen r) x y) => show s x y by apply ConGen.Rel.recOn (motive := fun x y _ => s x y) hxy · exact fun x y h => hs x y h · exact s.refl' · exact fun _ => s.symm' · exact fun _ _ => s.trans' · exact fun _ _ => s.mul)) (sInf_le ConGen.Rel.of) /-- The smallest congruence relation containing a binary relation `r` is contained in any congruence relation containing `r`. -/ @[to_additive addConGen_le "The smallest additive congruence relation containing a binary relation `r` is contained in any additive congruence relation containing `r`."] theorem conGen_le {r : M → M → Prop} {c : Con M} (h : ∀ x y, r x y → c x y) : conGen r ≤ c := by rw [conGen_eq]; exact sInf_le h /-- Given binary relations `r, s` with `r` contained in `s`, the smallest congruence relation containing `s` contains the smallest congruence relation containing `r`. -/ @[to_additive addConGen_mono "Given binary relations `r, s` with `r` contained in `s`, the smallest additive congruence relation containing `s` contains the smallest additive congruence relation containing `r`."] theorem conGen_mono {r s : M → M → Prop} (h : ∀ x y, r x y → s x y) : conGen r ≤ conGen s := conGen_le fun x y hr => ConGen.Rel.of _ _ <| h x y hr /-- Congruence relations equal the smallest congruence relation in which they are contained. -/ @[to_additive (attr := simp) addConGen_of_addCon "Additive congruence relations equal the smallest additive congruence relation in which they are contained."] theorem conGen_of_con (c : Con M) : conGen c = c := le_antisymm (by rw [conGen_eq]; exact sInf_le fun _ _ => id) ConGen.Rel.of -- Porting note: removing simp, simp can prove it /-- The map sending a binary relation to the smallest congruence relation in which it is contained is idempotent. -/ @[to_additive addConGen_idem "The map sending a binary relation to the smallest additive congruence relation in which it is contained is idempotent."] theorem conGen_idem (r : M → M → Prop) : conGen (conGen r) = conGen r := conGen_of_con _ /-- The supremum of congruence relations `c, d` equals the smallest congruence relation containing the binary relation '`x` is related to `y` by `c` or `d`'. -/ @[to_additive sup_eq_addConGen "The supremum of additive congruence relations `c, d` equals the smallest additive congruence relation containing the binary relation '`x` is related to `y` by `c` or `d`'."] theorem sup_eq_conGen (c d : Con M) : c ⊔ d = conGen fun x y => c x y ∨ d x y := by rw [conGen_eq] apply congr_arg sInf simp only [le_def, or_imp, ← forall_and] /-- The supremum of two congruence relations equals the smallest congruence relation containing the supremum of the underlying binary operations. -/ @[to_additive "The supremum of two additive congruence relations equals the smallest additive congruence relation containing the supremum of the underlying binary operations."] theorem sup_def {c d : Con M} : c ⊔ d = conGen (⇑c ⊔ ⇑d) := by rw [sup_eq_conGen]; rfl /-- The supremum of a set of congruence relations `S` equals the smallest congruence relation containing the binary relation 'there exists `c ∈ S` such that `x` is related to `y` by `c`'. -/ @[to_additive sSup_eq_addConGen "The supremum of a set of additive congruence relations `S` equals the smallest additive congruence relation containing the binary relation 'there exists `c ∈ S` such that `x` is related to `y` by `c`'."] theorem sSup_eq_conGen (S : Set (Con M)) : sSup S = conGen fun x y => ∃ c : Con M, c ∈ S ∧ c x y := by rw [conGen_eq] apply congr_arg sInf ext exact ⟨fun h _ _ ⟨r, hr⟩ => h hr.1 hr.2, fun h r hS _ _ hr => h _ _ ⟨r, hS, hr⟩⟩ /-- The supremum of a set of congruence relations is the same as the smallest congruence relation containing the supremum of the set's image under the map to the underlying binary relation. -/ @[to_additive "The supremum of a set of additive congruence relations is the same as the smallest additive congruence relation containing the supremum of the set's image under the map to the underlying binary relation."] theorem sSup_def {S : Set (Con M)} : sSup S = conGen (sSup ((⇑) '' S)) := by rw [sSup_eq_conGen, sSup_image] congr with (x y) simp only [sSup_image, iSup_apply, iSup_Prop_eq, exists_prop, rel_eq_coe] variable (M) /-- There is a Galois insertion of congruence relations on a type with a multiplication `M` into binary relations on `M`. -/ @[to_additive "There is a Galois insertion of additive congruence relations on a type with an addition `M` into binary relations on `M`."] protected def gi : @GaloisInsertion (M → M → Prop) (Con M) _ _ conGen DFunLike.coe where choice r _ := conGen r gc _ c := ⟨fun H _ _ h => H <| ConGen.Rel.of _ _ h, @fun H => conGen_of_con c ▸ conGen_mono H⟩ le_l_u x := (conGen_of_con x).symm ▸ le_refl x choice_eq _ _ := rfl variable {M} (c) /-- Given a function `f`, the smallest congruence relation containing the binary relation on `f`'s image defined by '`x ≈ y` iff the elements of `f⁻¹(x)` are related to the elements of `f⁻¹(y)` by a congruence relation `c`.' -/ @[to_additive "Given a function `f`, the smallest additive congruence relation containing the binary relation on `f`'s image defined by '`x ≈ y` iff the elements of `f⁻¹(x)` are related to the elements of `f⁻¹(y)` by an additive congruence relation `c`.'"] def mapGen (f : M → N) : Con N := conGen fun x y => ∃ a b, f a = x ∧ f b = y ∧ c a b /-- Given a surjective multiplicative-preserving function `f` whose kernel is contained in a congruence relation `c`, the congruence relation on `f`'s codomain defined by '`x ≈ y` iff the elements of `f⁻¹(x)` are related to the elements of `f⁻¹(y)` by `c`.' -/ @[to_additive "Given a surjective addition-preserving function `f` whose kernel is contained in an additive congruence relation `c`, the additive congruence relation on `f`'s codomain defined by '`x ≈ y` iff the elements of `f⁻¹(x)` are related to the elements of `f⁻¹(y)` by `c`.'"] def mapOfSurjective (f : M → N) (H : ∀ x y, f (x * y) = f x * f y) (h : mulKer f H ≤ c) (hf : Surjective f) : Con N := { c.toSetoid.mapOfSurjective f h hf with mul' := fun h₁ h₂ => by rcases h₁ with ⟨a, b, rfl, rfl, h1⟩ rcases h₂ with ⟨p, q, rfl, rfl, h2⟩ exact ⟨a * p, b * q, by rw [H], by rw [H], c.mul h1 h2⟩ } /-- A specialization of 'the smallest congruence relation containing a congruence relation `c` equals `c`'. -/ @[to_additive "A specialization of 'the smallest additive congruence relation containing an additive congruence relation `c` equals `c`'."] theorem mapOfSurjective_eq_mapGen {c : Con M} {f : M → N} (H : ∀ x y, f (x * y) = f x * f y) (h : mulKer f H ≤ c) (hf : Surjective f) : c.mapGen f = c.mapOfSurjective f H h hf := by rw [← conGen_of_con (c.mapOfSurjective f H h hf)]; rfl /-- Given types with multiplications `M, N` and a congruence relation `c` on `N`, a multiplication-preserving map `f : M → N` induces a congruence relation on `f`'s domain defined by '`x ≈ y` iff `f(x)` is related to `f(y)` by `c`.' -/ @[to_additive "Given types with additions `M, N` and an additive congruence relation `c` on `N`, an addition-preserving map `f : M → N` induces an additive congruence relation on `f`'s domain defined by '`x ≈ y` iff `f(x)` is related to `f(y)` by `c`.' "] def comap (f : M → N) (H : ∀ x y, f (x * y) = f x * f y) (c : Con N) : Con M := { c.toSetoid.comap f with mul' := @fun w x y z h1 h2 => show c (f (w * y)) (f (x * z)) by rw [H, H]; exact c.mul h1 h2 } @[to_additive (attr := simp)] theorem comap_rel {f : M → N} (H : ∀ x y, f (x * y) = f x * f y) {c : Con N} {x y : M} : comap f H c x y ↔ c (f x) (f y) := Iff.rfl section open Quotient /-- Given a congruence relation `c` on a type `M` with a multiplication, the order-preserving bijection between the set of congruence relations containing `c` and the congruence relations on the quotient of `M` by `c`. -/ @[to_additive "Given an additive congruence relation `c` on a type `M` with an addition, the order-preserving bijection between the set of additive congruence relations containing `c` and the additive congruence relations on the quotient of `M` by `c`."] def correspondence : { d // c ≤ d } ≃o Con c.Quotient where toFun d := d.1.mapOfSurjective (↑) (fun x y => rfl) (by rw [mul_ker_mk_eq]; exact d.2) <| @Quotient.exists_rep _ c.toSetoid invFun d := ⟨comap ((↑) : M → c.Quotient) (fun x y => rfl) d, fun x y h => show d x y by rw [c.eq.2 h]; exact d.refl _⟩ left_inv d := -- Porting note: by exact needed for unknown reason by exact Subtype.ext_iff_val.2 <| ext fun x y => ⟨fun h => let ⟨a, b, hx, hy, H⟩ := h d.1.trans (d.1.symm <| d.2 <| c.eq.1 hx) <| d.1.trans H <| d.2 <| c.eq.1 hy, fun h => ⟨_, _, rfl, rfl, h⟩⟩ right_inv d := -- Porting note: by exact needed for unknown reason by exact ext fun x y => ⟨fun h => let ⟨_, _, hx, hy, H⟩ := h hx ▸ hy ▸ H, Con.induction_on₂ x y fun w z h => ⟨w, z, rfl, rfl, h⟩⟩ map_rel_iff' := @fun s t => by constructor · intros h x y hs rcases h ⟨x, y, rfl, rfl, hs⟩ with ⟨a, b, hx, hy, ht⟩ exact t.1.trans (t.1.symm <| t.2 <| Quotient.eq_rel.1 hx) (t.1.trans ht (t.2 <| Quotient.eq_rel.1 hy)) · intros h _ _ hs rcases hs with ⟨a, b, hx, hy, Hs⟩ exact ⟨a, b, hx, hy, h Hs⟩ end end section MulOneClass variable [MulOneClass M] [MulOneClass N] [MulOneClass P] (c : Con M) /-- The quotient of a monoid by a congruence relation is a monoid. -/ @[to_additive "The quotient of an `AddMonoid` by an additive congruence relation is an `AddMonoid`."] instance mulOneClass : MulOneClass c.Quotient where one := ((1 : M) : c.Quotient) mul_one x := Quotient.inductionOn' x fun _ => congr_arg ((↑) : M → c.Quotient) <| mul_one _ one_mul x := Quotient.inductionOn' x fun _ => congr_arg ((↑) : M → c.Quotient) <| one_mul _ variable {c} /-- The 1 of the quotient of a monoid by a congruence relation is the equivalence class of the monoid's 1. -/ @[to_additive (attr := simp) "The 0 of the quotient of an `AddMonoid` by an additive congruence relation is the equivalence class of the `AddMonoid`'s 0."] theorem coe_one : ((1 : M) : c.Quotient) = 1 := rfl variable (c) -- Porting note: made M implicit /-- The submonoid of `M × M` defined by a congruence relation on a monoid `M`. -/ @[to_additive (attr := coe) "The `AddSubmonoid` of `M × M` defined by an additive congruence relation on an `AddMonoid` `M`."] protected def submonoid : Submonoid (M × M) where carrier := { x | c x.1 x.2 } one_mem' := c.iseqv.1 1 mul_mem' := c.mul variable {c} /-- The congruence relation on a monoid `M` from a submonoid of `M × M` for which membership is an equivalence relation. -/ @[to_additive "The additive congruence relation on an `AddMonoid` `M` from an `AddSubmonoid` of `M × M` for which membership is an equivalence relation."] def ofSubmonoid (N : Submonoid (M × M)) (H : Equivalence fun x y => (x, y) ∈ N) : Con M where r x y := (x, y) ∈ N iseqv := H mul' := N.mul_mem /-- Coercion from a congruence relation `c` on a monoid `M` to the submonoid of `M × M` whose elements are `(x, y)` such that `x` is related to `y` by `c`. -/ @[to_additive "Coercion from a congruence relation `c` on an `AddMonoid` `M` to the `AddSubmonoid` of `M × M` whose elements are `(x, y)` such that `x` is related to `y` by `c`."] instance toSubmonoid : Coe (Con M) (Submonoid (M × M)) := ⟨fun c => c.submonoid⟩ @[to_additive] theorem mem_coe {c : Con M} {x y} : (x, y) ∈ (↑c : Submonoid (M × M)) ↔ (x, y) ∈ c := Iff.rfl @[to_additive] theorem to_submonoid_inj (c d : Con M) (H : (c : Submonoid (M × M)) = d) : c = d := ext fun x y => show (x, y) ∈ c.submonoid ↔ (x, y) ∈ d from H ▸ Iff.rfl @[to_additive] theorem le_iff {c d : Con M} : c ≤ d ↔ (c : Submonoid (M × M)) ≤ d := ⟨fun h _ H => h H, fun h x y hc => h <| show (x, y) ∈ c from hc⟩ /-- The kernel of a monoid homomorphism as a congruence relation. -/ @[to_additive "The kernel of an `AddMonoid` homomorphism as an additive congruence relation."] def ker (f : M →* P) : Con M := mulKer f (map_mul f) /-- The definition of the congruence relation defined by a monoid homomorphism's kernel. -/ @[to_additive (attr := simp) "The definition of the additive congruence relation defined by an `AddMonoid` homomorphism's kernel."] theorem ker_rel (f : M →* P) {x y} : ker f x y ↔ f x = f y := Iff.rfl /-- There exists an element of the quotient of a monoid by a congruence relation (namely 1). -/ @[to_additive "There exists an element of the quotient of an `AddMonoid` by a congruence relation (namely 0)."] instance Quotient.inhabited : Inhabited c.Quotient := ⟨((1 : M) : c.Quotient)⟩ variable (c) /-- The natural homomorphism from a monoid to its quotient by a congruence relation. -/ @[to_additive "The natural homomorphism from an `AddMonoid` to its quotient by an additive congruence relation."] def mk' : M →* c.Quotient := { toFun := (↑) map_one' := rfl map_mul' := fun _ _ => rfl } variable (x y : M) /-- The kernel of the natural homomorphism from a monoid to its quotient by a congruence relation `c` equals `c`. -/ @[to_additive (attr := simp) "The kernel of the natural homomorphism from an `AddMonoid` to its quotient by an additive congruence relation `c` equals `c`."] theorem mk'_ker : ker c.mk' = c := ext fun _ _ => c.eq variable {c} /-- The natural homomorphism from a monoid to its quotient by a congruence relation is surjective. -/ @[to_additive "The natural homomorphism from an `AddMonoid` to its quotient by a congruence relation is surjective."] theorem mk'_surjective : Surjective c.mk' := Quotient.surjective_Quotient_mk'' @[to_additive (attr := simp)] theorem coe_mk' : (c.mk' : M → c.Quotient) = ((↑) : M → c.Quotient) := rfl @[to_additive (attr := simp)] -- Porting note: removed dot notation theorem mrange_mk' : MonoidHom.mrange c.mk' = ⊤ := MonoidHom.mrange_top_iff_surjective.2 mk'_surjective -- Porting note: used to abuse defeq between sets and predicates @[to_additive] theorem ker_apply {f : M →* P} {x y} : ker f x y ↔ f x = f y := Iff.rfl /-- Given a monoid homomorphism `f : N → M` and a congruence relation `c` on `M`, the congruence relation induced on `N` by `f` equals the kernel of `c`'s quotient homomorphism composed with `f`. -/ @[to_additive "Given an `AddMonoid` homomorphism `f : N → M` and an additive congruence relation `c` on `M`, the additive congruence relation induced on `N` by `f` equals the kernel of `c`'s quotient homomorphism composed with `f`."] theorem comap_eq {f : N →* M} : comap f f.map_mul c = ker (c.mk'.comp f) := ext fun x y => show c _ _ ↔ c.mk' _ = c.mk' _ by rw [← c.eq]; rfl variable (c) (f : M →* P) /-- The homomorphism on the quotient of a monoid by a congruence relation `c` induced by a homomorphism constant on `c`'s equivalence classes. -/ @[to_additive "The homomorphism on the quotient of an `AddMonoid` by an additive congruence relation `c` induced by a homomorphism constant on `c`'s equivalence classes."] def lift (H : c ≤ ker f) : c.Quotient →* P where toFun x := (Con.liftOn x f) fun _ _ h => H h map_one' := by rw [← f.map_one]; rfl map_mul' x y := Con.induction_on₂ x y fun m n => by dsimp only [← coe_mul, Con.liftOn_coe] rw [map_mul] variable {c f} /-- The diagram describing the universal property for quotients of monoids commutes. -/ @[to_additive "The diagram describing the universal property for quotients of `AddMonoid`s commutes."] theorem lift_mk' (H : c ≤ ker f) (x) : c.lift f H (c.mk' x) = f x := rfl /-- The diagram describing the universal property for quotients of monoids commutes. -/ @[to_additive (attr := simp) "The diagram describing the universal property for quotients of `AddMonoid`s commutes."] theorem lift_coe (H : c ≤ ker f) (x : M) : c.lift f H x = f x := rfl /-- The diagram describing the universal property for quotients of monoids commutes. -/ @[to_additive (attr := simp) "The diagram describing the universal property for quotients of `AddMonoid`s commutes."] theorem lift_comp_mk' (H : c ≤ ker f) : (c.lift f H).comp c.mk' = f := by ext; rfl /-- Given a homomorphism `f` from the quotient of a monoid by a congruence relation, `f` equals the homomorphism on the quotient induced by `f` composed with the natural map from the monoid to the quotient. -/ @[to_additive (attr := simp) "Given a homomorphism `f` from the quotient of an `AddMonoid` by an additive congruence relation, `f` equals the homomorphism on the quotient induced by `f` composed with the natural map from the `AddMonoid` to the quotient."] theorem lift_apply_mk' (f : c.Quotient →* P) : (c.lift (f.comp c.mk') fun x y h => show f ↑x = f ↑y by rw [c.eq.2 h]) = f := by ext x; rcases x with ⟨⟩; rfl /-- Homomorphisms on the quotient of a monoid by a congruence relation are equal if they are equal on elements that are coercions from the monoid. -/ @[to_additive "Homomorphisms on the quotient of an `AddMonoid` by an additive congruence relation are equal if they are equal on elements that are coercions from the `AddMonoid`."] theorem lift_funext (f g : c.Quotient →* P) (h : ∀ a : M, f a = g a) : f = g := by rw [← lift_apply_mk' f, ← lift_apply_mk' g] congr 1 exact DFunLike.ext_iff.2 h /-- The uniqueness part of the universal property for quotients of monoids. -/ @[to_additive "The uniqueness part of the universal property for quotients of `AddMonoid`s."] theorem lift_unique (H : c ≤ ker f) (g : c.Quotient →* P) (Hg : g.comp c.mk' = f) : g = c.lift f H := (lift_funext g (c.lift f H)) fun x => by subst f rfl /-- Given a congruence relation `c` on a monoid and a homomorphism `f` constant on `c`'s equivalence classes, `f` has the same image as the homomorphism that `f` induces on the quotient. -/ @[to_additive "Given an additive congruence relation `c` on an `AddMonoid` and a homomorphism `f` constant on `c`'s equivalence classes, `f` has the same image as the homomorphism that `f` induces on the quotient."] theorem lift_range (H : c ≤ ker f) : MonoidHom.mrange (c.lift f H) = MonoidHom.mrange f := Submonoid.ext fun x => ⟨by rintro ⟨⟨y⟩, hy⟩; exact ⟨y, hy⟩, fun ⟨y, hy⟩ => ⟨↑y, hy⟩⟩ /-- Surjective monoid homomorphisms constant on a congruence relation `c`'s equivalence classes induce a surjective homomorphism on `c`'s quotient. -/ @[to_additive "Surjective `AddMonoid` homomorphisms constant on an additive congruence relation `c`'s equivalence classes induce a surjective homomorphism on `c`'s quotient."] theorem lift_surjective_of_surjective (h : c ≤ ker f) (hf : Surjective f) : Surjective (c.lift f h) := fun y => (Exists.elim (hf y)) fun w hw => ⟨w, (lift_mk' h w).symm ▸ hw⟩ variable (c f) /-- Given a monoid homomorphism `f` from `M` to `P`, the kernel of `f` is the unique congruence relation on `M` whose induced map from the quotient of `M` to `P` is injective. -/ @[to_additive "Given an `AddMonoid` homomorphism `f` from `M` to `P`, the kernel of `f` is the unique additive congruence relation on `M` whose induced map from the quotient of `M` to `P` is injective."] theorem ker_eq_lift_of_injective (H : c ≤ ker f) (h : Injective (c.lift f H)) : ker f = c := toSetoid_inj <| Setoid.ker_eq_lift_of_injective f H h variable {c} /-- The homomorphism induced on the quotient of a monoid by the kernel of a monoid homomorphism. -/ @[to_additive "The homomorphism induced on the quotient of an `AddMonoid` by the kernel of an `AddMonoid` homomorphism."] def kerLift : (ker f).Quotient →* P := ((ker f).lift f) fun _ _ => id variable {f} /-- The diagram described by the universal property for quotients of monoids, when the congruence relation is the kernel of the homomorphism, commutes. -/ @[to_additive (attr := simp) "The diagram described by the universal property for quotients of `AddMonoid`s, when the additive congruence relation is the kernel of the homomorphism, commutes."] theorem kerLift_mk (x : M) : kerLift f x = f x := rfl /-- Given a monoid homomorphism `f`, the induced homomorphism on the quotient by `f`'s kernel has the same image as `f`. -/ @[to_additive (attr := simp) "Given an `AddMonoid` homomorphism `f`, the induced homomorphism on the quotient by `f`'s kernel has the same image as `f`."] theorem kerLift_range_eq : MonoidHom.mrange (kerLift f) = MonoidHom.mrange f := lift_range fun _ _ => id /-- A monoid homomorphism `f` induces an injective homomorphism on the quotient by `f`'s kernel. -/ @[to_additive "An `AddMonoid` homomorphism `f` induces an injective homomorphism on the quotient by `f`'s kernel."] theorem kerLift_injective (f : M →* P) : Injective (kerLift f) := fun x y => Quotient.inductionOn₂' x y fun _ _ => (ker f).eq.2 /-- Given congruence relations `c, d` on a monoid such that `d` contains `c`, `d`'s quotient map induces a homomorphism from the quotient by `c` to the quotient by `d`. -/ @[to_additive "Given additive congruence relations `c, d` on an `AddMonoid` such that `d` contains `c`, `d`'s quotient map induces a homomorphism from the quotient by `c` to the quotient by `d`."] def map (c d : Con M) (h : c ≤ d) : c.Quotient →* d.Quotient := (c.lift d.mk') fun x y hc => show (ker d.mk') x y from (mk'_ker d).symm ▸ h hc /-- Given congruence relations `c, d` on a monoid such that `d` contains `c`, the definition of the homomorphism from the quotient by `c` to the quotient by `d` induced by `d`'s quotient map. -/ @[to_additive "Given additive congruence relations `c, d` on an `AddMonoid` such that `d` contains `c`, the definition of the homomorphism from the quotient by `c` to the quotient by `d` induced by `d`'s quotient map."] theorem map_apply {c d : Con M} (h : c ≤ d) (x) : c.map d h x = c.lift d.mk' (fun _ _ hc => d.eq.2 <| h hc) x := rfl variable (c) /-- The **first isomorphism theorem for monoids**. -/ @[to_additive "The first isomorphism theorem for `AddMonoid`s."] noncomputable def quotientKerEquivRange (f : M →* P) : (ker f).Quotient ≃* MonoidHom.mrange f := { Equiv.ofBijective ((@MulEquiv.toMonoidHom (MonoidHom.mrange (kerLift f)) _ _ _ <| MulEquiv.submonoidCongr kerLift_range_eq).comp (kerLift f).mrangeRestrict) <| ((Equiv.bijective (@MulEquiv.toEquiv (MonoidHom.mrange (kerLift f)) _ _ _ <| MulEquiv.submonoidCongr kerLift_range_eq)).comp ⟨fun x y h => kerLift_injective f <| by rcases x with ⟨⟩; rcases y with ⟨⟩; injections, fun ⟨w, z, hz⟩ => ⟨z, by rcases hz with ⟨⟩; rfl⟩⟩) with map_mul' := MonoidHom.map_mul _ } /-- The first isomorphism theorem for monoids in the case of a homomorphism with right inverse. -/ @[to_additive (attr := simps) "The first isomorphism theorem for `AddMonoid`s in the case of a homomorphism with right inverse."] def quotientKerEquivOfRightInverse (f : M →* P) (g : P → M) (hf : Function.RightInverse g f) : (ker f).Quotient ≃* P := { kerLift f with toFun := kerLift f invFun := (↑) ∘ g left_inv := fun x => kerLift_injective _ (by rw [Function.comp_apply, kerLift_mk, hf]) right_inv := fun x => by (conv_rhs => rw [← hf x]); rfl } /-- The first isomorphism theorem for Monoids in the case of a surjective homomorphism. For a `computable` version, see `Con.quotientKerEquivOfRightInverse`. -/ @[to_additive "The first isomorphism theorem for `AddMonoid`s in the case of a surjective homomorphism. For a `computable` version, see `AddCon.quotientKerEquivOfRightInverse`. "] noncomputable def quotientKerEquivOfSurjective (f : M →* P) (hf : Surjective f) : (ker f).Quotient ≃* P := quotientKerEquivOfRightInverse _ _ hf.hasRightInverse.choose_spec /-- The **second isomorphism theorem for monoids**. -/ @[to_additive "The second isomorphism theorem for `AddMonoid`s."] noncomputable def comapQuotientEquiv (f : N →* M) : (comap f f.map_mul c).Quotient ≃* MonoidHom.mrange (c.mk'.comp f) := (Con.congr comap_eq).trans <| quotientKerEquivRange <| c.mk'.comp f /-- The **third isomorphism theorem for monoids**. -/ @[to_additive "The third isomorphism theorem for `AddMonoid`s."] def quotientQuotientEquivQuotient (c d : Con M) (h : c ≤ d) : (ker (c.map d h)).Quotient ≃* d.Quotient := { Setoid.quotientQuotientEquivQuotient c.toSetoid d.toSetoid h with map_mul' := fun x y => Con.induction_on₂ x y fun w z => Con.induction_on₂ w z fun a b => show _ = d.mk' a * d.mk' b by rw [← d.mk'.map_mul]; rfl } end MulOneClass section Monoids /-- Multiplicative congruence relations preserve natural powers. -/ @[to_additive "Additive congruence relations preserve natural scaling."] protected theorem pow {M : Type*} [Monoid M] (c : Con M) : ∀ (n : ℕ) {w x}, c w x → c (w ^ n) (x ^ n) | 0, w, x, _ => by simpa using c.refl _ | Nat.succ n, w, x, h => by simpa [pow_succ] using c.mul (Con.pow c n h) h @[to_additive] instance one [MulOneClass M] (c : Con M) : One c.Quotient where -- Using Quotient.mk'' here instead of c.toQuotient -- since c.toQuotient is not reducible. -- This would lead to non-defeq diamonds since this instance ends up in -- quotients modulo ideals. one := Quotient.mk'' (1 : M) -- one := ((1 : M) : c.Quotient) @[to_additive] theorem smul {α M : Type*} [MulOneClass M] [SMul α M] [IsScalarTower α M M] (c : Con M) (a : α) {w x : M} (h : c w x) : c (a • w) (a • x) := by simpa only [smul_one_mul] using c.mul (c.refl' (a • (1 : M) : M)) h instance _root_.AddCon.Quotient.nsmul {M : Type*} [AddMonoid M] (c : AddCon M) : SMul ℕ c.Quotient where smul n := (Quotient.map' (n • ·)) fun _ _ => c.nsmul n @[to_additive existing AddCon.Quotient.nsmul] instance {M : Type*} [Monoid M] (c : Con M) : Pow c.Quotient ℕ where pow x n := Quotient.map' (fun x => x ^ n) (fun _ _ => c.pow n) x /-- The quotient of a semigroup by a congruence relation is a semigroup. -/ @[to_additive "The quotient of an `AddSemigroup` by an additive congruence relation is an `AddSemigroup`."] instance semigroup {M : Type*} [Semigroup M] (c : Con M) : Semigroup c.Quotient := { (Function.Surjective.semigroup _ Quotient.surjective_Quotient_mk'' fun _ _ => rfl : Semigroup c.Quotient) with /- The `toMul` field is given explicitly for performance reasons. This avoids any need to unfold `Function.Surjective.semigroup` when the type checker is checking that instance diagrams commute -/ toMul := Con.hasMul _ } /-- The quotient of a commutative semigroup by a congruence relation is a semigroup. -/ @[to_additive "The quotient of an `AddCommSemigroup` by an additive congruence relation is an `AddCommSemigroup`."] instance commSemigroup {M : Type*} [CommSemigroup M] (c : Con M) : CommSemigroup c.Quotient := { (Function.Surjective.commSemigroup _ Quotient.surjective_Quotient_mk'' fun _ _ => rfl : CommSemigroup c.Quotient) with /- The `toSemigroup` field is given explicitly for performance reasons. This avoids any need to unfold `Function.Surjective.commSemigroup` when the type checker is checking that instance diagrams commute -/ toSemigroup := Con.semigroup _ } /-- The quotient of a monoid by a congruence relation is a monoid. -/ @[to_additive "The quotient of an `AddMonoid` by an additive congruence relation is an `AddMonoid`."] instance monoid {M : Type*} [Monoid M] (c : Con M) : Monoid c.Quotient := { (Function.Surjective.monoid _ Quotient.surjective_Quotient_mk'' rfl (fun _ _ => rfl) fun _ _ => rfl : Monoid c.Quotient) with /- The `toSemigroup` and `toOne` fields are given explicitly for performance reasons. This avoids any need to unfold `Function.Surjective.monoid` when the type checker is checking that instance diagrams commute -/ toSemigroup := Con.semigroup _ toOne := Con.one _ } /-- The quotient of a `CommMonoid` by a congruence relation is a `CommMonoid`. -/ @[to_additive "The quotient of an `AddCommMonoid` by an additive congruence relation is an `AddCommMonoid`."] instance commMonoid {M : Type*} [CommMonoid M] (c : Con M) : CommMonoid c.Quotient := { (Function.Surjective.commMonoid _ Quotient.surjective_Quotient_mk'' rfl (fun _ _ => rfl) fun _ _ => rfl : CommMonoid c.Quotient) with /- The `toMonoid` field is given explicitly for performance reasons. This avoids any need to unfold `Function.Surjective.commMonoid` when the type checker is checking that instance diagrams commute -/ toMonoid := Con.monoid _ } /-- Sometimes, a group is defined as a quotient of a monoid by a congruence relation. Usually, the inverse operation is defined as `Setoid.map f _` for some `f`. This lemma allows to avoid code duplication in the definition of the inverse operation: instead of proving both `∀ x y, c x y → c (f x) (f y)` (to define the operation) and `∀ x, c (f x * x) 1` (to prove the group laws), one can only prove the latter. -/ @[to_additive "Sometimes, an additive group is defined as a quotient of a monoid by an additive congruence relation. Usually, the inverse operation is defined as `Setoid.map f _` for some `f`. This lemma allows to avoid code duplication in the definition of the inverse operation: instead of proving both `∀ x y, c x y → c (f x) (f y)` (to define the operation) and `∀ x, c (f x + x) 0` (to prove the group laws), one can only prove the latter."] theorem map_of_mul_left_rel_one [Monoid M] (c : Con M) (f : M → M) (hf : ∀ x, c (f x * x) 1) {x y} (h : c x y) : c (f x) (f y) := by simp only [← Con.eq, coe_one, coe_mul] at * have hf' : ∀ x : M, (x : c.Quotient) * f x = 1 := fun x ↦ calc (x : c.Quotient) * f x = f (f x) * f x * (x * f x) := by simp [hf] _ = f (f x) * (f x * x) * f x := by ac_rfl _ = 1 := by simp [hf] have : (⟨_, _, hf' x, hf x⟩ : c.Quotientˣ) = ⟨_, _, hf' y, hf y⟩ := Units.ext h exact congr_arg Units.inv this end Monoids section Groups variable [Group M] [Group N] [Group P] (c : Con M) /-- Multiplicative congruence relations preserve inversion. -/ @[to_additive "Additive congruence relations preserve negation."] protected theorem inv {x y} (h : c x y) : c x⁻¹ y⁻¹ := c.map_of_mul_left_rel_one Inv.inv (fun x => by simp only [mul_left_inv, c.refl 1]) h /-- Multiplicative congruence relations preserve division. -/ @[to_additive "Additive congruence relations preserve subtraction."] protected theorem div : ∀ {w x y z}, c w x → c y z → c (w / y) (x / z) := @fun w x y z h1 h2 => by simpa only [div_eq_mul_inv] using c.mul h1 (c.inv h2) /-- Multiplicative congruence relations preserve integer powers. -/ @[to_additive "Additive congruence relations preserve integer scaling."] protected theorem zpow : ∀ (n : ℤ) {w x}, c w x → c (w ^ n) (x ^ n) | Int.ofNat n, w, x, h => by simpa only [zpow_natCast, Int.ofNat_eq_coe] using c.pow n h | Int.negSucc n, w, x, h => by simpa only [zpow_negSucc] using c.inv (c.pow _ h) /-- The inversion induced on the quotient by a congruence relation on a type with an inversion. -/ @[to_additive "The negation induced on the quotient by an additive congruence relation on a type with a negation."] instance hasInv : Inv c.Quotient := ⟨(Quotient.map' Inv.inv) fun _ _ => c.inv⟩ /-- The division induced on the quotient by a congruence relation on a type with a division. -/ @[to_additive "The subtraction induced on the quotient by an additive congruence relation on a type with a subtraction."] instance hasDiv : Div c.Quotient := ⟨(Quotient.map₂' (· / ·)) fun _ _ h₁ _ _ h₂ => c.div h₁ h₂⟩ /-- The integer scaling induced on the quotient by a congruence relation on a type with a subtraction. -/ instance _root_.AddCon.Quotient.zsmul {M : Type*} [AddGroup M] (c : AddCon M) : SMul ℤ c.Quotient := ⟨fun z => (Quotient.map' (z • ·)) fun _ _ => c.zsmul z⟩ /-- The integer power induced on the quotient by a congruence relation on a type with a division. -/ @[to_additive existing AddCon.Quotient.zsmul] instance zpowinst : Pow c.Quotient ℤ := ⟨fun x z => Quotient.map' (fun x => x ^ z) (fun _ _ h => c.zpow z h) x⟩ /-- The quotient of a group by a congruence relation is a group. -/ @[to_additive "The quotient of an `AddGroup` by an additive congruence relation is an `AddGroup`."] instance group : Group c.Quotient := { (Function.Surjective.group Quotient.mk'' Quotient.surjective_Quotient_mk'' rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl : Group c.Quotient) with toMonoid := Con.monoid _ toInv := Con.hasInv _ toDiv := Con.hasDiv _ } end Groups section Units variable {α : Type*} [Monoid M] {c : Con M} /-- In order to define a function `(Con.Quotient c)ˣ → α` on the units of `Con.Quotient c`, where `c : Con M` is a multiplicative congruence on a monoid, it suffices to define a function `f` that takes elements `x y : M` with proofs of `c (x * y) 1` and `c (y * x) 1`, and returns an element of `α` provided that `f x y _ _ = f x' y' _ _` whenever `c x x'` and `c y y'`. -/ @[to_additive] def liftOnUnits (u : Units c.Quotient) (f : ∀ x y : M, c (x * y) 1 → c (y * x) 1 → α) (Hf : ∀ x y hxy hyx x' y' hxy' hyx', c x x' → c y y' → f x y hxy hyx = f x' y' hxy' hyx') : α := by refine Con.hrecOn₂ (cN := c) (φ := fun x y => x * y = 1 → y * x = 1 → α) (u : c.Quotient) (↑u⁻¹ : c.Quotient) (fun (x y : M) (hxy : (x * y : c.Quotient) = 1) (hyx : (y * x : c.Quotient) = 1) => f x y (c.eq.1 hxy) (c.eq.1 hyx)) (fun x y x' y' hx hy => ?_) u.3 u.4 refine Function.hfunext ?_ ?_ · rw [c.eq.2 hx, c.eq.2 hy] · rintro Hxy Hxy' - refine Function.hfunext ?_ ?_ · rw [c.eq.2 hx, c.eq.2 hy] · rintro Hyx Hyx' - exact heq_of_eq (Hf _ _ _ _ _ _ _ _ hx hy) /-- In order to define a function `(Con.Quotient c)ˣ → α` on the units of `Con.Quotient c`, where `c : Con M` is a multiplicative congruence on a monoid, it suffices to define a function `f` that takes elements `x y : M` with proofs of `c (x * y) 1` and `c (y * x) 1`, and returns an element of `α` provided that `f x y _ _ = f x' y' _ _` whenever `c x x'` and `c y y'`. -/ add_decl_doc AddCon.liftOnAddUnits @[to_additive (attr := simp)] theorem liftOnUnits_mk (f : ∀ x y : M, c (x * y) 1 → c (y * x) 1 → α) (Hf : ∀ x y hxy hyx x' y' hxy' hyx', c x x' → c y y' → f x y hxy hyx = f x' y' hxy' hyx') (x y : M) (hxy hyx) : liftOnUnits ⟨(x : c.Quotient), y, hxy, hyx⟩ f Hf = f x y (c.eq.1 hxy) (c.eq.1 hyx) := rfl @[to_additive (attr := elab_as_elim)] theorem induction_on_units {p : Units c.Quotient → Prop} (u : Units c.Quotient) (H : ∀ (x y : M) (hxy : c (x * y) 1) (hyx : c (y * x) 1), p ⟨x, y, c.eq.2 hxy, c.eq.2 hyx⟩) : p u := by rcases u with ⟨⟨x⟩, ⟨y⟩, h₁, h₂⟩ exact H x y (c.eq.1 h₁) (c.eq.1 h₂) end Units section Actions @[to_additive] instance instSMul {α M : Type*} [MulOneClass M] [SMul α M] [IsScalarTower α M M] (c : Con M) : SMul α c.Quotient where smul a := (Quotient.map' (a • ·)) fun _ _ => c.smul a @[to_additive] theorem coe_smul {α M : Type*} [MulOneClass M] [SMul α M] [IsScalarTower α M M] (c : Con M) (a : α) (x : M) : (↑(a • x) : c.Quotient) = a • (x : c.Quotient) := rfl @[to_additive] instance mulAction {α M : Type*} [Monoid α] [MulOneClass M] [MulAction α M] [IsScalarTower α M M] (c : Con M) : MulAction α c.Quotient where one_smul := Quotient.ind' fun _ => congr_arg Quotient.mk'' <| one_smul _ _ mul_smul _ _ := Quotient.ind' fun _ => congr_arg Quotient.mk'' <| mul_smul _ _ _ instance mulDistribMulAction {α M : Type*} [Monoid α] [Monoid M] [MulDistribMulAction α M] [IsScalarTower α M M] (c : Con M) : MulDistribMulAction α c.Quotient := { smul_one := fun _ => congr_arg Quotient.mk'' <| smul_one _ smul_mul := fun _ => Quotient.ind₂' fun _ _ => congr_arg Quotient.mk'' <| smul_mul' _ _ _ } end Actions end Con
GroupTheory\Congruence\BigOperators.lean
/- Copyright (c) 2019 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Amelia Livingston -/ import Mathlib.GroupTheory.Congruence.Basic import Mathlib.Algebra.BigOperators.Group.Finset import Mathlib.Algebra.BigOperators.Group.Multiset import Mathlib.Algebra.BigOperators.Group.List /-! # Interactions between `∑, ∏` and `(Add)Con` -/ namespace Con /-- Multiplicative congruence relations preserve product indexed by a list. -/ @[to_additive "Additive congruence relations preserve sum indexed by a list."] protected theorem list_prod {ι M : Type*} [Monoid M] (c : Con M) {l : List ι} {f g : ι → M} (h : ∀ x ∈ l, c (f x) (g x)) : c (l.map f).prod (l.map g).prod := by induction l with | nil => simpa only [List.map_nil, List.prod_nil] using c.refl 1 | cons x xs ih => rw [List.map_cons, List.map_cons, List.prod_cons, List.prod_cons] exact c.mul (h _ <| .head _) <| ih fun k hk ↦ h _ (.tail _ hk) /-- Multiplicative congruence relations preserve product indexed by a multiset. -/ @[to_additive "Additive congruence relations preserve sum indexed by a multiset."] protected theorem multiset_prod {ι M : Type*} [CommMonoid M] (c : Con M) {s : Multiset ι} {f g : ι → M} (h : ∀ x ∈ s, c (f x) (g x)) : c (s.map f).prod (s.map g).prod := by rcases s; simpa using c.list_prod h /-- Multiplicative congruence relations preserve finite product. -/ @[to_additive "Additive congruence relations preserve finite sum."] protected theorem finset_prod {ι M : Type*} [CommMonoid M] (c : Con M) (s : Finset ι) {f g : ι → M} (h : ∀ i ∈ s, c (f i) (g i)) : c (s.prod f) (s.prod g) := c.multiset_prod h end Con
GroupTheory\Congruence\Opposite.lean
/- Copyright (c) 2019 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Amelia Livingston -/ import Mathlib.GroupTheory.Congruence.Basic import Mathlib.Algebra.Opposites /-! # Congruences on the opposite of a group This file defines the order isomorphism between the congruences on a group `G` and the congruences on the opposite group `Gᵒᵖ`. -/ variable {M : Type*} [Mul M] namespace Con /-- If `c` is a multiplicative congruence on `M`, then `(a, b) ↦ c b.unop a.unop` is a multiplicative congruence on `Mᵐᵒᵖ`-/ @[to_additive "If `c` is an additive congruence on `M`, then `(a, b) ↦ c b.unop a.unop` is an additive congruence on `Mᵃᵒᵖ`"] def op (c : Con M) : Con Mᵐᵒᵖ where r a b := c b.unop a.unop iseqv := { refl := fun a ↦ c.refl a.unop symm := c.symm trans := fun h1 h2 ↦ c.trans h2 h1 } mul' h1 h2 := c.mul h2 h1 /-- If `c` is a multiplicative congruence on `Mᵐᵒᵖ`, then `(a, b) ↦ c bᵒᵖ aᵒᵖ` is a multiplicative congruence on `M`-/ @[to_additive "If `c` is an additive congruence on `Mᵃᵒᵖ`, then `(a, b) ↦ c bᵒᵖ aᵒᵖ` is an additive congruence on `M`"] def unop (c : Con Mᵐᵒᵖ) : Con M where r a b := c (.op b) (.op a) iseqv := { refl := fun a ↦ c.refl (.op a) symm := c.symm trans := fun h1 h2 ↦ c.trans h2 h1 } mul' h1 h2 := c.mul h2 h1 /-- The multiplicative congruences on `M` bijects to the multiplicative congruences on `Mᵐᵒᵖ` -/ @[to_additive (attr := simps) "The additive congruences on `M` bijects to the additive congruences on `Mᵃᵒᵖ`"] def orderIsoOp : Con M ≃o Con Mᵐᵒᵖ where toFun := op invFun := unop left_inv _ := rfl right_inv _ := rfl map_rel_iff' {c d} := by rw [le_def, le_def]; constructor <;> intro h _ _ h' <;> exact h h' end Con
GroupTheory\Coprod\Basic.lean
/- Copyright (c) 2023 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.Group.Subgroup.Basic import Mathlib.Algebra.Group.Submonoid.Membership import Mathlib.Algebra.PUnitInstances.Algebra import Mathlib.GroupTheory.Congruence.Basic /-! # Coproduct (free product) of two monoids or groups In this file we define `Monoid.Coprod M N` (notation: `M ∗ N`) to be the coproduct (a.k.a. free product) of two monoids. The same type is used for the coproduct of two monoids and for the coproduct of two groups. The coproduct `M ∗ N` has the following universal property: for any monoid `P` and homomorphisms `f : M →* P`, `g : N →* P`, there exists a unique homomorphism `fg : M ∗ N →* P` such that `fg ∘ Monoid.Coprod.inl = f` and `fg ∘ Monoid.Coprod.inr = g`, where `Monoid.Coprod.inl : M →* M ∗ N` and `Monoid.Coprod.inr : N →* M ∗ N` are canonical embeddings. This homomorphism `fg` is given by `Monoid.Coprod.lift f g`. We also define some homomorphisms and isomorphisms about `M ∗ N`, and provide additive versions of all definitions and theorems. ## Main definitions ### Types * `Monoid.Coprod M N` (a.k.a. `M ∗ N`): the free product (a.k.a. coproduct) of two monoids `M` and `N`. * `AddMonoid.Coprod M N` (no notation): the additive version of `Monoid.Coprod`. In other sections, we only list multiplicative definitions. ### Instances * `MulOneClass`, `Monoid`, and `Group` structures on the coproduct `M ∗ N`. ### Monoid homomorphisms * `Monoid.Coprod.mk`: the projection `FreeMonoid (M ⊕ N) →* M ∗ N`. * `Monoid.Coprod.inl`, `Monoid.Coprod.inr`: canonical embeddings `M →* M ∗ N` and `N →* M ∗ N`. * `Monoid.Coprod.lift`: construct a monoid homomorphism `M ∗ N →* P` from homomorphisms `M →* P` and `N →* P`; see also `Monoid.Coprod.liftEquiv`. * `Monoid.Coprod.clift`: a constructor for homomorphisms `M ∗ N →* P` that allows the user to control the computational behavior. * `Monoid.Coprod.map`: combine two homomorphisms `f : M →* N` and `g : M' →* N'` into `M ∗ M' →* N ∗ N'`. * `Monoid.Coprod.swap`: the natural homomorphism `M ∗ N →* N ∗ M`. * `Monoid.Coprod.fst`, `Monoid.Coprod.snd`, and `Monoid.Coprod.toProd`: natural projections `M ∗ N →* M`, `M ∗ N →* N`, and `M ∗ N →* M × N`. ### Monoid isomorphisms * `MulEquiv.coprodCongr`: a `MulEquiv` version of `Monoid.Coprod.map`. * `MulEquiv.coprodComm`: a `MulEquiv` version of `Monoid.Coprod.swap`. * `MulEquiv.coprodAssoc`: associativity of the coproduct. * `MulEquiv.coprodPUnit`, `MulEquiv.punitCoprod`: free product by `PUnit` on the left or on the right is isomorphic to the original monoid. ## Main results The universal property of the coproduct is given by the definition `Monoid.Coprod.lift` and the lemma `Monoid.Coprod.lift_unique`. We also prove a slightly more general extensionality lemma `Monoid.Coprod.hom_ext` for homomorphisms `M ∗ N →* P` and prove lots of basic lemmas like `Monoid.Coprod.fst_comp_inl`. ## Implementation details The definition of the coproduct of an indexed family of monoids is formalized in `Monoid.CoprodI`. While mathematically `M ∗ N` is a particular case of the coproduct of an indexed family of monoids, it is easier to build API from scratch instead of using something like ``` def Monoid.Coprod M N := Monoid.CoprodI ![M, N] ``` or ``` def Monoid.Coprod M N := Monoid.CoprodI (fun b : Bool => cond b M N) ``` There are several reasons to build an API from scratch. - API about `Con` makes it easy to define the required type and prove the universal property, so there is little overhead compared to transferring API from `Monoid.CoprodI`. - If `M` and `N` live in different universes, then the definition has to add `ULift`s; this makes it harder to transfer API and definitions. - As of now, we have no way to automatically build an instance of `(k : Fin 2) → Monoid (![M, N] k)` from `[Monoid M]` and `[Monoid N]`, not even speaking about more advanced typeclass assumptions that involve both `M` and `N`. - Using a list of `M ⊕ N` instead of, e.g., a list of `Σ k : Fin 2, ![M, N] k` as the underlying type makes it possible to write computationally effective code (though this point is not tested yet). ## TODO - Prove `Monoid.CoprodI (f : Fin 2 → Type*) ≃* f 0 ∗ f 1` and `Monoid.CoprodI (f : Bool → Type*) ≃* f false ∗ f true`. ## Tags group, monoid, coproduct, free product -/ open FreeMonoid Function List Set namespace Monoid /-- The minimal congruence relation `c` on `FreeMonoid (M ⊕ N)` such that `FreeMonoid.of ∘ Sum.inl` and `FreeMonoid.of ∘ Sum.inr` are monoid homomorphisms to the quotient by `c`. -/ @[to_additive "The minimal additive congruence relation `c` on `FreeAddMonoid (M ⊕ N)` such that `FreeAddMonoid.of ∘ Sum.inl` and `FreeAddMonoid.of ∘ Sum.inr` are additive monoid homomorphisms to the quotient by `c`."] def coprodCon (M N : Type*) [MulOneClass M] [MulOneClass N] : Con (FreeMonoid (M ⊕ N)) := sInf {c | (∀ x y : M, c (of (Sum.inl (x * y))) (of (Sum.inl x) * of (Sum.inl y))) ∧ (∀ x y : N, c (of (Sum.inr (x * y))) (of (Sum.inr x) * of (Sum.inr y))) ∧ c (of <| Sum.inl 1) 1 ∧ c (of <| Sum.inr 1) 1} /-- Coproduct of two monoids or groups. -/ @[to_additive "Coproduct of two additive monoids or groups."] def Coprod (M N : Type*) [MulOneClass M] [MulOneClass N] := (coprodCon M N).Quotient namespace Coprod @[inherit_doc] scoped infix:30 " ∗ " => Coprod section MulOneClass variable {M N M' N' P : Type*} [MulOneClass M] [MulOneClass N] [MulOneClass M'] [MulOneClass N'] [MulOneClass P] @[to_additive] protected instance : MulOneClass (M ∗ N) := Con.mulOneClass _ /-- The natural projection `FreeMonoid (M ⊕ N) →* M ∗ N`. -/ @[to_additive "The natural projection `FreeAddMonoid (M ⊕ N) →+ AddMonoid.Coprod M N`."] def mk : FreeMonoid (M ⊕ N) →* M ∗ N := Con.mk' _ @[to_additive (attr := simp)] theorem con_ker_mk : Con.ker mk = coprodCon M N := Con.mk'_ker _ @[to_additive] theorem mk_surjective : Surjective (@mk M N _ _) := surjective_quot_mk _ @[to_additive (attr := simp)] theorem mrange_mk : MonoidHom.mrange (@mk M N _ _) = ⊤ := Con.mrange_mk' @[to_additive] theorem mk_eq_mk {w₁ w₂ : FreeMonoid (M ⊕ N)} : mk w₁ = mk w₂ ↔ coprodCon M N w₁ w₂ := Con.eq _ /-- The natural embedding `M →* M ∗ N`. -/ @[to_additive "The natural embedding `M →+ AddMonoid.Coprod M N`."] def inl : M →* M ∗ N where toFun := fun x => mk (of (.inl x)) map_one' := mk_eq_mk.2 fun _c hc => hc.2.2.1 map_mul' := fun x y => mk_eq_mk.2 fun _c hc => hc.1 x y /-- The natural embedding `N →* M ∗ N`. -/ @[to_additive "The natural embedding `N →+ AddMonoid.Coprod M N`."] def inr : N →* M ∗ N where toFun := fun x => mk (of (.inr x)) map_one' := mk_eq_mk.2 fun _c hc => hc.2.2.2 map_mul' := fun x y => mk_eq_mk.2 fun _c hc => hc.2.1 x y @[to_additive (attr := simp)] theorem mk_of_inl (x : M) : (mk (of (.inl x)) : M ∗ N) = inl x := rfl @[to_additive (attr := simp)] theorem mk_of_inr (x : N) : (mk (of (.inr x)) : M ∗ N) = inr x := rfl @[to_additive (attr := elab_as_elim)] theorem induction_on' {C : M ∗ N → Prop} (m : M ∗ N) (one : C 1) (inl_mul : ∀ m x, C x → C (inl m * x)) (inr_mul : ∀ n x, C x → C (inr n * x)) : C m := by rcases mk_surjective m with ⟨x, rfl⟩ induction x with | h0 => exact one | ih x xs ih => cases x with | inl m => simpa using inl_mul m _ ih | inr n => simpa using inr_mul n _ ih @[to_additive (attr := elab_as_elim)] theorem induction_on {C : M ∗ N → Prop} (m : M ∗ N) (inl : ∀ m, C (inl m)) (inr : ∀ n, C (inr n)) (mul : ∀ x y, C x → C y → C (x * y)) : C m := induction_on' m (by simpa using inl 1) (fun _ _ ↦ mul _ _ (inl _)) fun _ _ ↦ mul _ _ (inr _) /-- Lift a monoid homomorphism `FreeMonoid (M ⊕ N) →* P` satisfying additional properties to `M ∗ N →* P`. In many cases, `Coprod.lift` is more convenient. Compared to `Coprod.lift`, this definition allows a user to provide a custom computational behavior. Also, it only needs `MulOneclass` assumptions while `Coprod.lift` needs a `Monoid` structure. -/ @[to_additive "Lift an additive monoid homomorphism `FreeAddMonoid (M ⊕ N) →+ P` satisfying additional properties to `AddMonoid.Coprod M N →+ P`. Compared to `AddMonoid.Coprod.lift`, this definition allows a user to provide a custom computational behavior. Also, it only needs `AddZeroclass` assumptions while `AddMonoid.Coprod.lift` needs an `AddMonoid` structure. "] def clift (f : FreeMonoid (M ⊕ N) →* P) (hM₁ : f (of (.inl 1)) = 1) (hN₁ : f (of (.inr 1)) = 1) (hM : ∀ x y, f (of (.inl (x * y))) = f (of (.inl x) * of (.inl y))) (hN : ∀ x y, f (of (.inr (x * y))) = f (of (.inr x) * of (.inr y))) : M ∗ N →* P := Con.lift _ f <| sInf_le ⟨hM, hN, hM₁.trans (map_one f).symm, hN₁.trans (map_one f).symm⟩ @[to_additive (attr := simp)] theorem clift_apply_inl (f : FreeMonoid (M ⊕ N) →* P) (hM₁ hN₁ hM hN) (x : M) : clift f hM₁ hN₁ hM hN (inl x) = f (of (.inl x)) := rfl @[to_additive (attr := simp)] theorem clift_apply_inr (f : FreeMonoid (M ⊕ N) →* P) (hM₁ hN₁ hM hN) (x : N) : clift f hM₁ hN₁ hM hN (inr x) = f (of (.inr x)) := rfl @[to_additive (attr := simp)] theorem clift_apply_mk (f : FreeMonoid (M ⊕ N) →* P) (hM₁ hN₁ hM hN w) : clift f hM₁ hN₁ hM hN (mk w) = f w := rfl @[to_additive (attr := simp)] theorem clift_comp_mk (f : FreeMonoid (M ⊕ N) →* P) (hM₁ hN₁ hM hN) : (clift f hM₁ hN₁ hM hN).comp mk = f := DFunLike.ext' rfl @[to_additive (attr := simp)] theorem mclosure_range_inl_union_inr : Submonoid.closure (range (inl : M →* M ∗ N) ∪ range (inr : N →* M ∗ N)) = ⊤ := by rw [← mrange_mk, MonoidHom.mrange_eq_map, ← closure_range_of, MonoidHom.map_mclosure, ← range_comp, Sum.range_eq]; rfl @[to_additive (attr := simp)] theorem mrange_inl_sup_mrange_inr : MonoidHom.mrange (inl : M →* M ∗ N) ⊔ MonoidHom.mrange (inr : N →* M ∗ N) = ⊤ := by rw [← mclosure_range_inl_union_inr, Submonoid.closure_union, ← MonoidHom.coe_mrange, ← MonoidHom.coe_mrange, Submonoid.closure_eq, Submonoid.closure_eq] @[to_additive] theorem codisjoint_mrange_inl_mrange_inr : Codisjoint (MonoidHom.mrange (inl : M →* M ∗ N)) (MonoidHom.mrange inr) := codisjoint_iff.2 mrange_inl_sup_mrange_inr @[to_additive] theorem mrange_eq (f : M ∗ N →* P) : MonoidHom.mrange f = MonoidHom.mrange (f.comp inl) ⊔ MonoidHom.mrange (f.comp inr) := by rw [MonoidHom.mrange_eq_map, ← mrange_inl_sup_mrange_inr, Submonoid.map_sup, MonoidHom.map_mrange, MonoidHom.map_mrange] /-- Extensionality lemma for monoid homomorphisms `M ∗ N →* P`. If two homomorphisms agree on the ranges of `Monoid.Coprod.inl` and `Monoid.Coprod.inr`, then they are equal. -/ @[to_additive (attr := ext 1100) "Extensionality lemma for additive monoid homomorphisms `AddMonoid.Coprod M N →+ P`. If two homomorphisms agree on the ranges of `AddMonoid.Coprod.inl` and `AddMonoid.Coprod.inr`, then they are equal."] theorem hom_ext {f g : M ∗ N →* P} (h₁ : f.comp inl = g.comp inl) (h₂ : f.comp inr = g.comp inr) : f = g := MonoidHom.eq_of_eqOn_denseM mclosure_range_inl_union_inr <| eqOn_union.2 ⟨eqOn_range.2 <| DFunLike.ext'_iff.1 h₁, eqOn_range.2 <| DFunLike.ext'_iff.1 h₂⟩ @[to_additive (attr := simp)] theorem clift_mk : clift (mk : FreeMonoid (M ⊕ N) →* M ∗ N) (map_one inl) (map_one inr) (map_mul inl) (map_mul inr) = .id _ := hom_ext rfl rfl /-- Map `M ∗ N` to `M' ∗ N'` by applying `Sum.map f g` to each element of the underlying list. -/ @[to_additive "Map `AddMonoid.Coprod M N` to `AddMonoid.Coprod M' N'` by applying `Sum.map f g` to each element of the underlying list."] def map (f : M →* M') (g : N →* N') : M ∗ N →* M' ∗ N' := clift (mk.comp <| FreeMonoid.map <| Sum.map f g) (by simp only [MonoidHom.comp_apply, map_of, Sum.map_inl, map_one, mk_of_inl]) (by simp only [MonoidHom.comp_apply, map_of, Sum.map_inr, map_one, mk_of_inr]) (fun x y => by simp only [MonoidHom.comp_apply, map_of, Sum.map_inl, map_mul, mk_of_inl]) fun x y => by simp only [MonoidHom.comp_apply, map_of, Sum.map_inr, map_mul, mk_of_inr] @[to_additive (attr := simp)] theorem map_mk_ofList (f : M →* M') (g : N →* N') (l : List (M ⊕ N)) : map f g (mk (ofList l)) = mk (ofList (l.map (Sum.map f g))) := rfl @[to_additive (attr := simp)] theorem map_apply_inl (f : M →* M') (g : N →* N') (x : M) : map f g (inl x) = inl (f x) := rfl @[to_additive (attr := simp)] theorem map_apply_inr (f : M →* M') (g : N →* N') (x : N) : map f g (inr x) = inr (g x) := rfl @[to_additive (attr := simp)] theorem map_comp_inl (f : M →* M') (g : N →* N') : (map f g).comp inl = inl.comp f := rfl @[to_additive (attr := simp)] theorem map_comp_inr (f : M →* M') (g : N →* N') : (map f g).comp inr = inr.comp g := rfl @[to_additive (attr := simp)] theorem map_id_id : map (.id M) (.id N) = .id (M ∗ N) := hom_ext rfl rfl @[to_additive] theorem map_comp_map {M'' N''} [MulOneClass M''] [MulOneClass N''] (f' : M' →* M'') (g' : N' →* N'') (f : M →* M') (g : N →* N') : (map f' g').comp (map f g) = map (f'.comp f) (g'.comp g) := hom_ext rfl rfl @[to_additive] theorem map_map {M'' N''} [MulOneClass M''] [MulOneClass N''] (f' : M' →* M'') (g' : N' →* N'') (f : M →* M') (g : N →* N') (x : M ∗ N) : map f' g' (map f g x) = map (f'.comp f) (g'.comp g) x := DFunLike.congr_fun (map_comp_map f' g' f g) x variable (M N) /-- Map `M ∗ N` to `N ∗ M` by applying `Sum.swap` to each element of the underlying list. See also `MulEquiv.coprodComm` for a `MulEquiv` version. -/ @[to_additive "Map `AddMonoid.Coprod M N` to `AddMonoid.Coprod N M` by applying `Sum.swap` to each element of the underlying list. See also `AddEquiv.coprodComm` for an `AddEquiv` version."] def swap : M ∗ N →* N ∗ M := clift (mk.comp <| FreeMonoid.map Sum.swap) (by simp only [MonoidHom.comp_apply, map_of, Sum.swap_inl, mk_of_inr, map_one]) (by simp only [MonoidHom.comp_apply, map_of, Sum.swap_inr, mk_of_inl, map_one]) (fun x y => by simp only [MonoidHom.comp_apply, map_of, Sum.swap_inl, mk_of_inr, map_mul]) (fun x y => by simp only [MonoidHom.comp_apply, map_of, Sum.swap_inr, mk_of_inl, map_mul]) @[to_additive (attr := simp)] theorem swap_comp_swap : (swap M N).comp (swap N M) = .id _ := hom_ext rfl rfl variable {M N} @[to_additive (attr := simp)] theorem swap_swap (x : M ∗ N) : swap N M (swap M N x) = x := DFunLike.congr_fun (swap_comp_swap _ _) x @[to_additive] theorem swap_comp_map (f : M →* M') (g : N →* N') : (swap M' N').comp (map f g) = (map g f).comp (swap M N) := hom_ext rfl rfl @[to_additive] theorem swap_map (f : M →* M') (g : N →* N') (x : M ∗ N) : swap M' N' (map f g x) = map g f (swap M N x) := DFunLike.congr_fun (swap_comp_map f g) x @[to_additive (attr := simp)] theorem swap_comp_inl : (swap M N).comp inl = inr := rfl @[to_additive (attr := simp)] theorem swap_inl (x : M) : swap M N (inl x) = inr x := rfl @[to_additive (attr := simp)] theorem swap_comp_inr : (swap M N).comp inr = inl := rfl @[to_additive (attr := simp)] theorem swap_inr (x : N) : swap M N (inr x) = inl x := rfl @[to_additive] theorem swap_injective : Injective (swap M N) := LeftInverse.injective swap_swap @[to_additive (attr := simp)] theorem swap_inj {x y : M ∗ N} : swap M N x = swap M N y ↔ x = y := swap_injective.eq_iff @[to_additive (attr := simp)] theorem swap_eq_one {x : M ∗ N} : swap M N x = 1 ↔ x = 1 := swap_injective.eq_iff' (map_one _) @[to_additive] theorem swap_surjective : Surjective (swap M N) := LeftInverse.surjective swap_swap @[to_additive] theorem swap_bijective : Bijective (swap M N) := ⟨swap_injective, swap_surjective⟩ @[to_additive (attr := simp)] theorem mker_swap : MonoidHom.mker (swap M N) = ⊥ := Submonoid.ext fun _ ↦ swap_eq_one @[to_additive (attr := simp)] theorem mrange_swap : MonoidHom.mrange (swap M N) = ⊤ := MonoidHom.mrange_top_of_surjective _ swap_surjective end MulOneClass section Lift variable {M N P : Type*} [MulOneClass M] [MulOneClass N] [Monoid P] /-- Lift a pair of monoid homomorphisms `f : M →* P`, `g : N →* P` to a monoid homomorphism `M ∗ N →* P`. See also `Coprod.clift` for a version that allows custom computational behavior and works for a `MulOneClass` codomain. -/ @[to_additive "Lift a pair of additive monoid homomorphisms `f : M →+ P`, `g : N →+ P` to an additive monoid homomorphism `AddMonoid.Coprod M N →+ P`. See also `AddMonoid.Coprod.clift` for a version that allows custom computational behavior and works for an `AddZeroClass` codomain."] def lift (f : M →* P) (g : N →* P) : (M ∗ N) →* P := clift (FreeMonoid.lift <| Sum.elim f g) (map_one f) (map_one g) (map_mul f) (map_mul g) @[to_additive (attr := simp)] theorem lift_apply_mk (f : M →* P) (g : N →* P) (x : FreeMonoid (M ⊕ N)) : lift f g (mk x) = FreeMonoid.lift (Sum.elim f g) x := rfl @[to_additive (attr := simp)] theorem lift_apply_inl (f : M →* P) (g : N →* P) (x : M) : lift f g (inl x) = f x := rfl @[to_additive] theorem lift_unique {f : M →* P} {g : N →* P} {fg : M ∗ N →* P} (h₁ : fg.comp inl = f) (h₂ : fg.comp inr = g) : fg = lift f g := hom_ext h₁ h₂ @[to_additive (attr := simp)] theorem lift_comp_inl (f : M →* P) (g : N →* P) : (lift f g).comp inl = f := rfl @[to_additive (attr := simp)] theorem lift_apply_inr (f : M →* P) (g : N →* P) (x : N) : lift f g (inr x) = g x := rfl @[to_additive (attr := simp)] theorem lift_comp_inr (f : M →* P) (g : N →* P) : (lift f g).comp inr = g := rfl @[to_additive (attr := simp)] theorem lift_comp_swap (f : M →* P) (g : N →* P) : (lift f g).comp (swap N M) = lift g f := hom_ext rfl rfl @[to_additive (attr := simp)] theorem lift_swap (f : M →* P) (g : N →* P) (x : N ∗ M) : lift f g (swap N M x) = lift g f x := DFunLike.congr_fun (lift_comp_swap f g) x @[to_additive] theorem comp_lift {P' : Type*} [Monoid P'] (f : P →* P') (g₁ : M →* P) (g₂ : N →* P) : f.comp (lift g₁ g₂) = lift (f.comp g₁) (f.comp g₂) := hom_ext (by rw [MonoidHom.comp_assoc, lift_comp_inl, lift_comp_inl]) <| by rw [MonoidHom.comp_assoc, lift_comp_inr, lift_comp_inr] /-- `Coprod.lift` as an equivalence. -/ @[to_additive "`AddMonoid.Coprod.lift` as an equivalence."] def liftEquiv : (M →* P) × (N →* P) ≃ (M ∗ N →* P) where toFun fg := lift fg.1 fg.2 invFun f := (f.comp inl, f.comp inr) left_inv _ := rfl right_inv _ := Eq.symm <| lift_unique rfl rfl @[to_additive (attr := simp)] theorem mrange_lift (f : M →* P) (g : N →* P) : MonoidHom.mrange (lift f g) = MonoidHom.mrange f ⊔ MonoidHom.mrange g := by simp [mrange_eq] end Lift section ToProd variable {M N : Type*} [Monoid M] [Monoid N] @[to_additive] instance : Monoid (M ∗ N) := { mul_assoc := (Con.monoid _).mul_assoc one_mul := (Con.monoid _).one_mul mul_one := (Con.monoid _).mul_one } /-- The natural projection `M ∗ N →* M`. -/ @[to_additive "The natural projection `AddMonoid.Coprod M N →+ M`."] def fst : M ∗ N →* M := lift (.id M) 1 /-- The natural projection `M ∗ N →* N`. -/ @[to_additive "The natural projection `AddMonoid.Coprod M N →+ N`."] def snd : M ∗ N →* N := lift 1 (.id N) /-- The natural projection `M ∗ N →* M × N`. -/ @[to_additive "The natural projection `AddMonoid.Coprod M N →+ M × N`."] def toProd : M ∗ N →* M × N := lift (.inl _ _) (.inr _ _) @[to_additive (attr := simp)] theorem fst_comp_inl : (fst : M ∗ N →* M).comp inl = .id _ := rfl @[to_additive (attr := simp)] theorem fst_apply_inl (x : M) : fst (inl x : M ∗ N) = x := rfl @[to_additive (attr := simp)] theorem fst_comp_inr : (fst : M ∗ N →* M).comp inr = 1 := rfl @[to_additive (attr := simp)] theorem fst_apply_inr (x : N) : fst (inr x : M ∗ N) = 1 := rfl @[to_additive (attr := simp)] theorem snd_comp_inl : (snd : M ∗ N →* N).comp inl = 1 := rfl @[to_additive (attr := simp)] theorem snd_apply_inl (x : M) : snd (inl x : M ∗ N) = 1 := rfl @[to_additive (attr := simp)] theorem snd_comp_inr : (snd : M ∗ N →* N).comp inr = .id _ := rfl @[to_additive (attr := simp)] theorem snd_apply_inr (x : N) : snd (inr x : M ∗ N) = x := rfl @[to_additive (attr := simp)] theorem toProd_comp_inl : (toProd : M ∗ N →* M × N).comp inl = .inl _ _ := rfl @[to_additive (attr := simp)] theorem toProd_comp_inr : (toProd : M ∗ N →* M × N).comp inr = .inr _ _ := rfl @[to_additive (attr := simp)] theorem toProd_apply_inl (x : M) : toProd (inl x : M ∗ N) = (x, 1) := rfl @[to_additive (attr := simp)] theorem toProd_apply_inr (x : N) : toProd (inr x : M ∗ N) = (1, x) := rfl @[to_additive (attr := simp)] theorem fst_prod_snd : (fst : M ∗ N →* M).prod snd = toProd := by ext1 <;> rfl @[to_additive (attr := simp)] theorem prod_mk_fst_snd (x : M ∗ N) : (fst x, snd x) = toProd x := by rw [← fst_prod_snd, MonoidHom.prod_apply] @[to_additive (attr := simp)] theorem fst_comp_toProd : (MonoidHom.fst M N).comp toProd = fst := by rw [← fst_prod_snd, MonoidHom.fst_comp_prod] @[to_additive (attr := simp)] theorem fst_toProd (x : M ∗ N) : (toProd x).1 = fst x := by rw [← fst_comp_toProd]; rfl @[to_additive (attr := simp)] theorem snd_comp_toProd : (MonoidHom.snd M N).comp toProd = snd := by rw [← fst_prod_snd, MonoidHom.snd_comp_prod] @[to_additive (attr := simp)] theorem snd_toProd (x : M ∗ N) : (toProd x).2 = snd x := by rw [← snd_comp_toProd]; rfl @[to_additive (attr := simp)] theorem fst_comp_swap : fst.comp (swap M N) = snd := lift_comp_swap _ _ @[to_additive (attr := simp)] theorem fst_swap (x : M ∗ N) : fst (swap M N x) = snd x := lift_swap _ _ _ @[to_additive (attr := simp)] theorem snd_comp_swap : snd.comp (swap M N) = fst := lift_comp_swap _ _ @[to_additive (attr := simp)] theorem snd_swap (x : M ∗ N) : snd (swap M N x) = fst x := lift_swap _ _ _ @[to_additive (attr := simp)] theorem lift_inr_inl : lift (inr : M →* N ∗ M) inl = swap M N := hom_ext rfl rfl @[to_additive (attr := simp)] theorem lift_inl_inr : lift (inl : M →* M ∗ N) inr = .id _ := hom_ext rfl rfl @[to_additive] theorem inl_injective : Injective (inl : M →* M ∗ N) := LeftInverse.injective fst_apply_inl @[to_additive] theorem inr_injective : Injective (inr : N →* M ∗ N) := LeftInverse.injective snd_apply_inr @[to_additive] theorem fst_surjective : Surjective (fst : M ∗ N →* M) := LeftInverse.surjective fst_apply_inl @[to_additive] theorem snd_surjective : Surjective (snd : M ∗ N →* N) := LeftInverse.surjective snd_apply_inr @[to_additive] theorem toProd_surjective : Surjective (toProd : M ∗ N →* M × N) := fun x => ⟨inl x.1 * inr x.2, by rw [map_mul, toProd_apply_inl, toProd_apply_inr, Prod.fst_mul_snd]⟩ end ToProd section Group variable {G H : Type*} [Group G] [Group H] @[to_additive] theorem mk_of_inv_mul : ∀ x : G ⊕ H, mk (of (x.map Inv.inv Inv.inv)) * mk (of x) = 1 | Sum.inl _ => map_mul_eq_one inl (mul_left_inv _) | Sum.inr _ => map_mul_eq_one inr (mul_left_inv _) @[to_additive] theorem con_mul_left_inv (x : FreeMonoid (G ⊕ H)) : coprodCon G H (ofList (x.toList.map (Sum.map Inv.inv Inv.inv)).reverse * x) 1 := by rw [← mk_eq_mk, map_mul, map_one] induction x with | h0 => simp [map_one mk] -- TODO: fails without `[map_one mk]` | ih x xs ihx => simp only [toList_of_mul, map_cons, reverse_cons, ofList_append, map_mul, ihx, ofList_singleton] rwa [mul_assoc, ← mul_assoc (mk (of _)), mk_of_inv_mul, one_mul] @[to_additive] instance : Inv (G ∗ H) where inv := Quotient.map' (fun w => ofList (w.toList.map (Sum.map Inv.inv Inv.inv)).reverse) fun _ _ ↦ (coprodCon G H).map_of_mul_left_rel_one _ con_mul_left_inv @[to_additive] theorem inv_def (w : FreeMonoid (G ⊕ H)) : (mk w)⁻¹ = mk (ofList (w.toList.map (Sum.map Inv.inv Inv.inv)).reverse) := rfl @[to_additive] instance : Group (G ∗ H) where mul_left_inv := mk_surjective.forall.2 fun x => mk_eq_mk.2 (con_mul_left_inv x) @[to_additive (attr := simp)] theorem closure_range_inl_union_inr : Subgroup.closure (range (inl : G →* G ∗ H) ∪ range inr) = ⊤ := Subgroup.closure_eq_top_of_mclosure_eq_top mclosure_range_inl_union_inr @[to_additive (attr := simp)] theorem range_inl_sup_range_inr : MonoidHom.range (inl : G →* G ∗ H) ⊔ MonoidHom.range inr = ⊤ := by rw [← closure_range_inl_union_inr, Subgroup.closure_union, ← MonoidHom.coe_range, ← MonoidHom.coe_range, Subgroup.closure_eq, Subgroup.closure_eq] @[to_additive] theorem codisjoint_range_inl_range_inr : Codisjoint (MonoidHom.range (inl : G →* G ∗ H)) (MonoidHom.range inr) := codisjoint_iff.2 range_inl_sup_range_inr @[to_additive (attr := simp)] theorem range_swap : MonoidHom.range (swap G H) = ⊤ := MonoidHom.range_top_of_surjective _ swap_surjective variable {K : Type*} [Group K] @[to_additive] theorem range_eq (f : G ∗ H →* K) : MonoidHom.range f = MonoidHom.range (f.comp inl) ⊔ MonoidHom.range (f.comp inr) := by rw [MonoidHom.range_eq_map, ← range_inl_sup_range_inr, Subgroup.map_sup, MonoidHom.map_range, MonoidHom.map_range] @[to_additive (attr := simp)] theorem range_lift (f : G →* K) (g : H →* K) : MonoidHom.range (lift f g) = MonoidHom.range f ⊔ MonoidHom.range g := by simp [range_eq] end Group end Coprod open Coprod namespace MulEquiv section MulOneClass variable {M N M' N' : Type*} [MulOneClass M] [MulOneClass N] [MulOneClass M'] [MulOneClass N'] /-- Lift two monoid equivalences `e : M ≃* N` and `e' : M' ≃* N'` to a monoid equivalence `(M ∗ M') ≃* (N ∗ N')`. -/ @[to_additive (attr := simps! (config := .asFn)) "Lift two additive monoid equivalences `e : M ≃+ N` and `e' : M' ≃+ N'` to an additive monoid equivalence `(AddMonoid.Coprod M M') ≃+ (AddMonoid.Coprod N N')`."] def coprodCongr (e : M ≃* N) (e' : M' ≃* N') : (M ∗ M') ≃* (N ∗ N') := (Coprod.map (e : M →* N) (e' : M' →* N')).toMulEquiv (Coprod.map e.symm e'.symm) (by ext <;> simp) (by ext <;> simp) variable (M N) /-- A `MulEquiv` version of `Coprod.swap`. -/ @[to_additive (attr := simps! (config := .asFn)) "An `AddEquiv` version of `AddMonoid.Coprod.swap`."] def coprodComm : M ∗ N ≃* N ∗ M := (Coprod.swap _ _).toMulEquiv (Coprod.swap _ _) (Coprod.swap_comp_swap _ _) (Coprod.swap_comp_swap _ _) end MulOneClass variable (M N P : Type*) [Monoid M] [Monoid N] [Monoid P] /-- A multiplicative equivalence between `(M ∗ N) ∗ P` and `M ∗ (N ∗ P)`. -/ @[to_additive "An additive equivalence between `AddMonoid.Coprod (AddMonoid.Coprod M N) P` and `AddMonoid.Coprod M (AddMonoid.Coprod N P)`."] def coprodAssoc : (M ∗ N) ∗ P ≃* M ∗ (N ∗ P) := MonoidHom.toMulEquiv (Coprod.lift (Coprod.map (.id M) inl) (inr.comp inr)) (Coprod.lift (inl.comp inl) (Coprod.map inr (.id P))) (by ext <;> rfl) (by ext <;> rfl) variable {M N P} @[to_additive (attr := simp)] theorem coprodAssoc_apply_inl_inl (x : M) : coprodAssoc M N P (inl (inl x)) = inl x := rfl @[to_additive (attr := simp)] theorem coprodAssoc_apply_inl_inr (x : N) : coprodAssoc M N P (inl (inr x)) = inr (inl x) := rfl @[to_additive (attr := simp)] theorem coprodAssoc_apply_inr (x : P) : coprodAssoc M N P (inr x) = inr (inr x) := rfl @[to_additive (attr := simp)] theorem coprodAssoc_symm_apply_inl (x : M) : (coprodAssoc M N P).symm (inl x) = inl (inl x) := rfl @[to_additive (attr := simp)] theorem coprodAssoc_symm_apply_inr_inl (x : N) : (coprodAssoc M N P).symm (inr (inl x)) = inl (inr x) := rfl @[to_additive (attr := simp)] theorem coprodAssoc_symm_apply_inr_inr (x : P) : (coprodAssoc M N P).symm (inr (inr x)) = inr x := rfl variable (M) /-- Isomorphism between `M ∗ PUnit` and `M`. -/ @[simps! (config := .asFn)] def coprodPUnit : M ∗ PUnit ≃* M := MonoidHom.toMulEquiv fst inl (hom_ext rfl <| Subsingleton.elim _ _) fst_comp_inl /-- Isomorphism between `PUnit ∗ M` and `M`. -/ @[simps! (config := .asFn)] def punitCoprod : PUnit ∗ M ≃* M := MonoidHom.toMulEquiv snd inr (hom_ext (Subsingleton.elim _ _) rfl) snd_comp_inr end MulEquiv -- TODO: use `to_additive` to generate the next 2 `AddEquiv`s namespace AddEquiv variable {M : Type*} [AddMonoid M] /-- Isomorphism between `M ∗ PUnit` and `M`. -/ @[simps! (config := .asFn)] def coprodUnit : AddMonoid.Coprod M PUnit ≃+ M := AddMonoidHom.toAddEquiv AddMonoid.Coprod.fst AddMonoid.Coprod.inl (AddMonoid.Coprod.hom_ext rfl <| Subsingleton.elim _ _) AddMonoid.Coprod.fst_comp_inl /-- Isomorphism between `PUnit ∗ M` and `M`. -/ @[simps! (config := .asFn)] def punitCoprod : AddMonoid.Coprod PUnit M ≃+ M := AddMonoidHom.toAddEquiv AddMonoid.Coprod.snd AddMonoid.Coprod.inr (AddMonoid.Coprod.hom_ext (Subsingleton.elim _ _) rfl) AddMonoid.Coprod.snd_comp_inr end AddEquiv end Monoid
GroupTheory\Coxeter\Basic.lean
/- Copyright (c) 2024 Newell Jensen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Newell Jensen, Mitchell Lee -/ import Mathlib.Algebra.Ring.Int import Mathlib.GroupTheory.PresentedGroup import Mathlib.GroupTheory.Coxeter.Matrix import Mathlib.Tactic.Ring import Mathlib.Tactic.Use /-! # Coxeter groups and Coxeter systems This file defines Coxeter groups and Coxeter systems. Let `B` be a (possibly infinite) type, and let $M = (M_{i,i'})_{i, i' \in B}$ be a matrix of natural numbers. Further assume that $M$ is a *Coxeter matrix* (`CoxeterMatrix`); that is, $M$ is symmetric and $M_{i,i'} = 1$ if and only if $i = i'$. The *Coxeter group* associated to $M$ (`CoxeterMatrix.group`) has the presentation $$\langle \{s_i\}_{i \in B} \vert \{(s_i s_{i'})^{M_{i, i'}}\}_{i, i' \in B} \rangle.$$ The elements $s_i$ are called the *simple reflections* (`CoxeterMatrix.simple`) of the Coxeter group. Note that every simple reflection is an involution. A *Coxeter system* (`CoxeterSystem`) is a group $W$, together with an isomorphism between $W$ and the Coxeter group associated to some Coxeter matrix $M$. By abuse of language, we also say that $W$ is a Coxeter group (`IsCoxeterGroup`), and we may speak of the simple reflections $s_i \in W$ (`CoxeterSystem.simple`). We state all of our results about Coxeter groups in terms of Coxeter systems where possible. Let $W$ be a group equipped with a Coxeter system. For all monoids $G$ and all functions $f \colon B \to G$ whose values satisfy the Coxeter relations, we may lift $f$ to a multiplicative homomorphism $W \to G$ (`CoxeterSystem.lift`) in a unique way. A *word* is a sequence of elements of $B$. The word $(i_1, \ldots, i_\ell)$ has a corresponding product $s_{i_1} \cdots s_{i_\ell} \in W$ (`CoxeterSystem.wordProd`). Every element of $W$ is the product of some word (`CoxeterSystem.wordProd_surjective`). The words that alternate between two elements of $B$ (`CoxeterSystem.alternatingWord`) are particularly important. ## Implementation details Much of the literature on Coxeter groups conflates the set $S = \{s_i : i \in B\} \subseteq W$ of simple reflections with the set $B$ that indexes the simple reflections. This is usually permissible because the simple reflections $s_i$ of any Coxeter group are all distinct (a nontrivial fact that we do not prove in this file). In contrast, we try not to refer to the set $S$ of simple reflections unless necessary; instead, we state our results in terms of $B$ wherever possible. ## Main definitions * `CoxeterMatrix.Group` * `CoxeterSystem` * `IsCoxeterGroup` * `CoxeterSystem.simple` : If `cs` is a Coxeter system on the group `W`, then `cs.simple i` is the simple reflection of `W` at the index `i`. * `CoxeterSystem.lift` : Extend a function `f : B → G` to a monoid homomorphism `f' : W → G` satisfying `f' (cs.simple i) = f i` for all `i`. * `CoxeterSystem.wordProd` * `CoxeterSystem.alternatingWord` ## References * [N. Bourbaki, *Lie Groups and Lie Algebras, Chapters 4--6*](bourbaki1968) chapter IV pages 4--5, 13--15 * [J. Baez, *Coxeter and Dynkin Diagrams*](https://math.ucr.edu/home/baez/twf_dynkin.pdf) ## TODO * The simple reflections of a Coxeter system are distinct. * Introduce some ways to actually construct some Coxeter groups. For example, given a Coxeter matrix $M : B \times B \to \mathbb{N}$, a real vector space $V$, a basis $\{\alpha_i : i \in B\}$ and a bilinear form $\langle \cdot, \cdot \rangle \colon V \times V \to \mathbb{R}$ satisfying $$\langle \alpha_i, \alpha_{i'}\rangle = - \cos(\pi / M_{i,i'}),$$ one can form the subgroup of $GL(V)$ generated by the reflections in the $\alpha_i$, and it is a Coxeter group. We can use this to combinatorially describe the Coxeter groups of type $A$, $B$, $D$, and $I$. * State and prove Matsumoto's theorem. * Classify the finite Coxeter groups. ## Tags coxeter system, coxeter group -/ open Function Set List /-! ### Coxeter groups -/ namespace CoxeterMatrix variable {B B' : Type*} (M : CoxeterMatrix B) (e : B ≃ B') /-- The Coxeter relation associated to a Coxeter matrix $M$ and two indices $i, i' \in B$. That is, the relation $(s_i s_{i'})^{M_{i, i'}}$, considered as an element of the free group on $\{s_i\}_{i \in B}$. If $M_{i, i'} = 0$, then this is the identity, indicating that there is no relation between $s_i$ and $s_{i'}$. -/ def relation (i i' : B) : FreeGroup B := (FreeGroup.of i * FreeGroup.of i') ^ M i i' /-- The set of all Coxeter relations associated to the Coxeter matrix $M$. -/ def relationsSet : Set (FreeGroup B) := range <| uncurry M.relation /-- The Coxeter group associated to a Coxeter matrix $M$; that is, the group $$\langle \{s_i\}_{i \in B} \vert \{(s_i s_{i'})^{M_{i, i'}}\}_{i, i' \in B} \rangle.$$ -/ protected def Group : Type _ := PresentedGroup M.relationsSet instance : Group M.Group := QuotientGroup.Quotient.group _ /-- The simple reflection of the Coxeter group `M.group` at the index `i`. -/ def simple (i : B) : M.Group := PresentedGroup.of i theorem reindex_relationsSet : (M.reindex e).relationsSet = FreeGroup.freeGroupCongr e '' M.relationsSet := let M' := M.reindex e; calc Set.range (uncurry M'.relation) _ = Set.range (uncurry M'.relation ∘ Prod.map e e) := by simp [Set.range_comp] _ = Set.range (FreeGroup.freeGroupCongr e ∘ uncurry M.relation) := by apply congrArg Set.range ext ⟨i, i'⟩ simp [relation, reindex_apply, M'] _ = _ := by simp [Set.range_comp, relationsSet] /-- The isomorphism between the Coxeter group associated to the reindexed matrix `M.reindex e` and the Coxeter group associated to `M`. -/ def reindexGroupEquiv : (M.reindex e).Group ≃* M.Group := .symm <| QuotientGroup.congr (Subgroup.normalClosure M.relationsSet) (Subgroup.normalClosure (M.reindex e).relationsSet) (FreeGroup.freeGroupCongr e) (by rw [reindex_relationsSet, Subgroup.map_normalClosure _ _ (by simpa using (FreeGroup.freeGroupCongr e).surjective), MonoidHom.coe_coe]) theorem reindexGroupEquiv_apply_simple (i : B') : (M.reindexGroupEquiv e) ((M.reindex e).simple i) = M.simple (e.symm i) := rfl theorem reindexGroupEquiv_symm_apply_simple (i : B) : (M.reindexGroupEquiv e).symm (M.simple i) = (M.reindex e).simple (e i) := rfl end CoxeterMatrix /-! ### Coxeter systems -/ section variable {B : Type*} (M : CoxeterMatrix B) /-- A Coxeter system `CoxeterSystem M W` is a structure recording the isomorphism between a group `W` and the Coxeter group associated to a Coxeter matrix `M`. -/ @[ext] structure CoxeterSystem (W : Type*) [Group W] where /-- The isomorphism between `W` and the Coxeter group associated to `M`. -/ mulEquiv : W ≃* M.Group /-- A group is a Coxeter group if it admits a Coxeter system for some Coxeter matrix `M`. -/ class IsCoxeterGroup.{u} (W : Type u) [Group W] : Prop where nonempty_system : ∃ B : Type u, ∃ M : CoxeterMatrix B, Nonempty (CoxeterSystem M W) /-- The canonical Coxeter system on the Coxeter group associated to `M`. -/ def CoxeterMatrix.toCoxeterSystem : CoxeterSystem M M.Group := ⟨.refl _⟩ end namespace CoxeterSystem open CoxeterMatrix variable {B B' : Type*} (e : B ≃ B') variable {W H : Type*} [Group W] [Group H] variable {M : CoxeterMatrix B} (cs : CoxeterSystem M W) /-- Reindex a Coxeter system through a bijection of the indexing sets. -/ @[simps] protected def reindex (e : B ≃ B') : CoxeterSystem (M.reindex e) W := ⟨cs.mulEquiv.trans (M.reindexGroupEquiv e).symm⟩ /-- Push a Coxeter system through a group isomorphism. -/ @[simps] protected def map (e : W ≃* H) : CoxeterSystem M H := ⟨e.symm.trans cs.mulEquiv⟩ /-! ### Simple reflections -/ /-- The simple reflection of `W` at the index `i`. -/ def simple (i : B) : W := cs.mulEquiv.symm (PresentedGroup.of i) @[simp] theorem _root_.CoxeterMatrix.toCoxeterSystem_simple (M : CoxeterMatrix B) : M.toCoxeterSystem.simple = M.simple := rfl @[simp] theorem reindex_simple (i' : B') : (cs.reindex e).simple i' = cs.simple (e.symm i') := rfl @[simp] theorem map_simple (e : W ≃* H) (i : B) : (cs.map e).simple i = e (cs.simple i) := rfl local prefix:100 "s" => cs.simple @[simp] theorem simple_mul_simple_self (i : B) : s i * s i = 1 := by have : (FreeGroup.of i) * (FreeGroup.of i) ∈ M.relationsSet := ⟨(i, i), by simp [relation]⟩ have : (QuotientGroup.mk (FreeGroup.of i * FreeGroup.of i) : M.Group) = 1 := (QuotientGroup.eq_one_iff _).mpr (Subgroup.subset_normalClosure this) unfold simple rw [← map_mul, PresentedGroup.of, ← QuotientGroup.mk_mul, this, map_one] @[simp] theorem simple_mul_simple_cancel_right {w : W} (i : B) : w * s i * s i = w := by simp [mul_assoc] @[simp] theorem simple_mul_simple_cancel_left {w : W} (i : B) : s i * (s i * w) = w := by simp [← mul_assoc] @[simp] theorem simple_sq (i : B) : s i ^ 2 = 1 := pow_two (s i) ▸ cs.simple_mul_simple_self i @[simp] theorem inv_simple (i : B) : (s i)⁻¹ = s i := (eq_inv_of_mul_eq_one_right (cs.simple_mul_simple_self i)).symm @[simp] theorem simple_mul_simple_pow (i i' : B) : (s i * s i') ^ M i i' = 1 := by have : (FreeGroup.of i * FreeGroup.of i') ^ M i i' ∈ M.relationsSet := ⟨(i, i'), rfl⟩ have : (QuotientGroup.mk ((FreeGroup.of i * FreeGroup.of i') ^ M i i') : M.Group) = 1 := (QuotientGroup.eq_one_iff _).mpr (Subgroup.subset_normalClosure this) unfold simple rw [← map_mul, ← map_pow, PresentedGroup.of, PresentedGroup.of, ← QuotientGroup.mk_mul, ← QuotientGroup.mk_pow, this, map_one] @[simp] theorem simple_mul_simple_pow' (i i' : B) : (s i' * s i) ^ M i i' = 1 := M.symmetric i' i ▸ cs.simple_mul_simple_pow i' i /-- The simple reflections of `W` generate `W` as a group. -/ theorem subgroup_closure_range_simple : Subgroup.closure (range cs.simple) = ⊤ := by have : cs.simple = cs.mulEquiv.symm ∘ PresentedGroup.of := rfl rw [this, Set.range_comp, ← MulEquiv.coe_toMonoidHom, ← MonoidHom.map_closure, PresentedGroup.closure_range_of, ← MonoidHom.range_eq_map] exact MonoidHom.range_top_of_surjective _ (MulEquiv.surjective _) /-- The simple reflections of `W` generate `W` as a monoid. -/ theorem submonoid_closure_range_simple : Submonoid.closure (range cs.simple) = ⊤ := by have : range cs.simple = range cs.simple ∪ (range cs.simple)⁻¹ := by simp_rw [inv_range, inv_simple, union_self] rw [this, ← Subgroup.closure_toSubmonoid, subgroup_closure_range_simple, Subgroup.top_toSubmonoid] /-! ### Induction principles for Coxeter systems -/ /-- If `p : W → Prop` holds for all simple reflections, it holds for the identity, and it is preserved under multiplication, then it holds for all elements of `W`. -/ theorem simple_induction {p : W → Prop} (w : W) (simple : ∀ i : B, p (s i)) (one : p 1) (mul : ∀ w w' : W, p w → p w' → p (w * w')) : p w := by have := cs.submonoid_closure_range_simple.symm ▸ Submonoid.mem_top w exact Submonoid.closure_induction this (fun x ⟨i, hi⟩ ↦ hi ▸ simple i) one mul /-- If `p : W → Prop` holds for the identity and it is preserved under multiplying on the left by a simple reflection, then it holds for all elements of `W`. -/ theorem simple_induction_left {p : W → Prop} (w : W) (one : p 1) (mul_simple_left : ∀ (w : W) (i : B), p w → p (s i * w)) : p w := by let p' : (w : W) → w ∈ Submonoid.closure (Set.range cs.simple) → Prop := fun w _ ↦ p w have := cs.submonoid_closure_range_simple.symm ▸ Submonoid.mem_top w apply Submonoid.closure_induction_left (p := p') · exact one · rintro _ ⟨i, rfl⟩ y _ exact mul_simple_left y i · exact this /-- If `p : W → Prop` holds for the identity and it is preserved under multiplying on the right by a simple reflection, then it holds for all elements of `W`. -/ theorem simple_induction_right {p : W → Prop} (w : W) (one : p 1) (mul_simple_right : ∀ (w : W) (i : B), p w → p (w * s i)) : p w := by let p' : ((w : W) → w ∈ Submonoid.closure (Set.range cs.simple) → Prop) := fun w _ ↦ p w have := cs.submonoid_closure_range_simple.symm ▸ Submonoid.mem_top w apply Submonoid.closure_induction_right (p := p') · exact one · rintro x _ _ ⟨i, rfl⟩ exact mul_simple_right x i · exact this /-! ### Homomorphisms from a Coxeter group -/ /-- If two homomorphisms with domain `W` agree on all simple reflections, then they are equal. -/ theorem ext_simple {G : Type*} [Monoid G] {φ₁ φ₂ : W →* G} (h : ∀ i : B, φ₁ (s i) = φ₂ (s i)) : φ₁ = φ₂ := MonoidHom.eq_of_eqOn_denseM cs.submonoid_closure_range_simple (fun _ ⟨i, hi⟩ ↦ hi ▸ h i) /-- The proposition that the values of the function `f : B → G` satisfy the Coxeter relations corresponding to the matrix `M`. -/ def _root_.CoxeterMatrix.IsLiftable {G : Type*} [Monoid G] (M : CoxeterMatrix B) (f : B → G) : Prop := ∀ i i', (f i * f i') ^ M i i' = 1 private theorem relations_liftable {G : Type*} [Group G] {f : B → G} (hf : IsLiftable M f) (r : FreeGroup B) (hr : r ∈ M.relationsSet) : (FreeGroup.lift f) r = 1 := by rcases hr with ⟨⟨i, i'⟩, rfl⟩ rw [uncurry, relation, map_pow, _root_.map_mul, FreeGroup.lift.of, FreeGroup.lift.of] exact hf i i' private def groupLift {G : Type*} [Group G] {f : B → G} (hf : IsLiftable M f) : W →* G := (PresentedGroup.toGroup (relations_liftable hf)).comp cs.mulEquiv.toMonoidHom private def restrictUnit {G : Type*} [Monoid G] {f : B → G} (hf : IsLiftable M f) (i : B) : Gˣ where val := f i inv := f i val_inv := pow_one (f i * f i) ▸ M.diagonal i ▸ hf i i inv_val := pow_one (f i * f i) ▸ M.diagonal i ▸ hf i i private theorem toMonoidHom_apply_symm_apply (a : PresentedGroup (M.relationsSet)) : (MulEquiv.toMonoidHom cs.mulEquiv : W →* PresentedGroup (M.relationsSet)) ((MulEquiv.symm cs.mulEquiv) a) = a := calc _ = cs.mulEquiv ((MulEquiv.symm cs.mulEquiv) a) := by rfl _ = _ := by rw [MulEquiv.apply_symm_apply] /-- The universal mapping property of Coxeter systems. For any monoid `G`, functions `f : B → G` whose values satisfy the Coxeter relations are equivalent to monoid homomorphisms `f' : W → G`. -/ def lift {G : Type*} [Monoid G] : {f : B → G // IsLiftable M f} ≃ (W →* G) where toFun f := MonoidHom.comp (Units.coeHom G) (cs.groupLift (show ∀ i i', ((restrictUnit f.property) i * (restrictUnit f.property) i') ^ M i i' = 1 from fun i i' ↦ Units.ext (f.property i i'))) invFun ι := ⟨ι ∘ cs.simple, fun i i' ↦ by rw [comp_apply, comp_apply, ← map_mul, ← map_pow, simple_mul_simple_pow, map_one]⟩ left_inv f := by ext i simp only [MonoidHom.comp_apply, comp_apply, mem_setOf_eq, groupLift, simple] rw [← MonoidHom.toFun_eq_coe, toMonoidHom_apply_symm_apply, PresentedGroup.toGroup.of, OneHom.toFun_eq_coe, MonoidHom.toOneHom_coe, Units.coeHom_apply, restrictUnit] right_inv ι := by apply cs.ext_simple intro i dsimp only rw [groupLift, simple, MonoidHom.comp_apply, MonoidHom.comp_apply, toMonoidHom_apply_symm_apply, PresentedGroup.toGroup.of, CoxeterSystem.restrictUnit, Units.coeHom_apply] simp only [comp_apply, simple] @[simp] theorem lift_apply_simple {G : Type*} [Monoid G] {f : B → G} (hf : IsLiftable M f) (i : B) : cs.lift ⟨f, hf⟩ (s i) = f i := congrFun (congrArg Subtype.val (cs.lift.left_inv ⟨f, hf⟩)) i /-- If two Coxeter systems on the same group `W` have the same Coxeter matrix `M : Matrix B B ℕ` and the same simple reflection map `B → W`, then they are identical. -/ theorem simple_determines_coxeterSystem : Injective (simple : CoxeterSystem M W → B → W) := by intro cs1 cs2 h apply CoxeterSystem.ext apply MulEquiv.toMonoidHom_injective apply cs1.ext_simple intro i nth_rw 2 [h] simp [simple] /-! ### Words -/ /-- The product of the simple reflections of `W` corresponding to the indices in `ω`. -/ def wordProd (ω : List B) : W := prod (map cs.simple ω) local prefix:100 "π" => cs.wordProd @[simp] theorem wordProd_nil : π [] = 1 := by simp [wordProd] theorem wordProd_cons (i : B) (ω : List B) : π (i :: ω) = s i * π ω := by simp [wordProd] @[simp] theorem wordProd_singleton (i : B) : π ([i]) = s i := by simp [wordProd] theorem wordProd_concat (i : B) (ω : List B) : π (ω.concat i) = π ω * s i := by simp [wordProd] theorem wordProd_append (ω ω' : List B) : π (ω ++ ω') = π ω * π ω' := by simp [wordProd] @[simp] theorem wordProd_reverse (ω : List B) : π (reverse ω) = (π ω)⁻¹ := by induction' ω with x ω' ih · simp · simpa [wordProd_cons, wordProd_append] using ih theorem wordProd_surjective : Surjective cs.wordProd := by intro w apply cs.simple_induction_left w · use [] rw [wordProd_nil] · rintro _ i ⟨ω, rfl⟩ use i :: ω rw [wordProd_cons] /-- The word of length `m` that alternates between `i` and `i'`, ending with `i'`. -/ def alternatingWord (i i' : B) (m : ℕ) : List B := match m with | 0 => [] | m+1 => (alternatingWord i' i m).concat i' /-- The word of length `M i i'` that alternates between `i` and `i'`, ending with `i'`. -/ abbrev braidWord (M : CoxeterMatrix B) (i i' : B) : List B := alternatingWord i i' (M i i') theorem alternatingWord_succ (i i' : B) (m : ℕ) : alternatingWord i i' (m + 1) = (alternatingWord i' i m).concat i' := rfl theorem alternatingWord_succ' (i i' : B) (m : ℕ) : alternatingWord i i' (m + 1) = (if Even m then i' else i) :: alternatingWord i i' m := by induction' m with m ih generalizing i i' · simp [alternatingWord] · rw [alternatingWord] nth_rw 1 [ih i' i] rw [alternatingWord] simp [Nat.even_add_one] @[simp] theorem length_alternatingWord (i i' : B) (m : ℕ) : List.length (alternatingWord i i' m) = m := by induction' m with m ih generalizing i i' · dsimp [alternatingWord] · simpa [alternatingWord] using ih i' i theorem prod_alternatingWord_eq_mul_pow (i i' : B) (m : ℕ) : π (alternatingWord i i' m) = (if Even m then 1 else s i') * (s i * s i') ^ (m / 2) := by induction' m with m ih · simp [alternatingWord] · rw [alternatingWord_succ', wordProd_cons, ih] by_cases hm : Even m · have h₁ : ¬ Even (m + 1) := by simp [hm, parity_simps] have h₂ : (m + 1) / 2 = m / 2 := Nat.succ_div_of_not_dvd <| by rwa [← even_iff_two_dvd] simp [hm, h₁, h₂] · have h₁ : Even (m + 1) := by simp [hm, parity_simps] have h₂ : (m + 1) / 2 = m / 2 + 1 := Nat.succ_div_of_dvd h₁.two_dvd simp [hm, h₁, h₂, ← pow_succ', ← mul_assoc] theorem prod_alternatingWord_eq_prod_alternatingWord_sub (i i' : B) (m : ℕ) (hm : m ≤ M i i' * 2) : π (alternatingWord i i' m) = π (alternatingWord i' i (M i i' * 2 - m)) := by simp_rw [prod_alternatingWord_eq_mul_pow, ← Int.even_coe_nat] /- Rewrite everything in terms of an integer m' which is equal to m. The resulting equation holds for all integers m'. -/ simp_rw [← zpow_natCast, Int.ofNat_ediv, Int.ofNat_sub hm] generalize (m : ℤ) = m' clear hm push_cast rcases Int.even_or_odd' m' with ⟨k, rfl | rfl⟩ · rw [if_pos (by use k; ring), if_pos (by use -k + (M i i'); ring), mul_comm 2 k, ← sub_mul] repeat rw [Int.mul_ediv_cancel _ (by norm_num)] rw [zpow_sub, zpow_natCast, simple_mul_simple_pow' cs i i', ← inv_zpow] simp · have : ¬Even (2 * k + 1) := Int.odd_iff_not_even.mp ⟨k, rfl⟩ rw [if_neg this] have : ¬Even (↑(M i i') * 2 - (2 * k + 1)) := Int.odd_iff_not_even.mp ⟨↑(M i i') - k - 1, by ring⟩ rw [if_neg this] rw [(by ring : ↑(M i i') * 2 - (2 * k + 1) = -1 + (-k + ↑(M i i')) * 2), (by ring : 2 * k + 1 = 1 + k * 2)] repeat rw [Int.add_mul_ediv_right _ _ (by norm_num)] norm_num rw [zpow_add, zpow_add, zpow_natCast, simple_mul_simple_pow', zpow_neg, ← inv_zpow, zpow_neg, ← inv_zpow] simp [← mul_assoc] /-- The two words of length `M i i'` that alternate between `i` and `i'` have the same product. This is known as the "braid relation" or "Artin-Tits relation". -/ theorem wordProd_braidWord_eq (i i' : B) : π (braidWord M i i') = π (braidWord M i' i) := by have := cs.prod_alternatingWord_eq_prod_alternatingWord_sub i i' (M i i') (Nat.le_mul_of_pos_right _ (by norm_num)) rw [tsub_eq_of_eq_add (mul_two (M i i'))] at this nth_rw 2 [M.symmetric i i'] at this exact this end CoxeterSystem
GroupTheory\Coxeter\Inversion.lean
/- Copyright (c) 2024 Mitchell Lee. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mitchell Lee -/ import Mathlib.GroupTheory.Coxeter.Length import Mathlib.Data.ZMod.Parity import Mathlib.Data.List.GetD /-! # Reflections, inversions, and inversion sequences Throughout this file, `B` is a type and `M : CoxeterMatrix B` is a Coxeter matrix. `cs : CoxeterSystem M W` is a Coxeter system; that is, `W` is a group, and `cs` holds the data of a group isomorphism `W ≃* M.group`, where `M.group` refers to the quotient of the free group on `B` by the Coxeter relations given by the matrix `M`. See `Mathlib/GroupTheory/Coxeter/Basic.lean` for more details. We define a *reflection* (`CoxeterSystem.IsReflection`) to be an element of the form $t = u s_i u^{-1}$, where $u \in W$ and $s_i$ is a simple reflection. We say that a reflection $t$ is a *left inversion* (`CoxeterSystem.IsLeftInversion`) of an element $w \in W$ if $\ell(t w) < \ell(w)$, and we say it is a *right inversion* (`CoxeterSystem.IsRightInversion`) of $w$ if $\ell(w t) > \ell(w)$. Here $\ell$ is the length function (see `Mathlib/GroupTheory/Coxeter/Length.lean`). Given a word, we define its *left inversion sequence* (`CoxeterSystem.leftInvSeq`) and its *right inversion sequence* (`CoxeterSystem.rightInvSeq`). We prove that if a word is reduced, then both of its inversion sequences contain no duplicates. In fact, the right (respectively, left) inversion sequence of a reduced word for $w$ consists of all of the right (respectively, left) inversions of $w$ in some order, but we do not prove that in this file. ## Main definitions * `CoxeterSystem.IsReflection` * `CoxeterSystem.IsLeftInversion` * `CoxeterSystem.IsRightInversion` * `CoxeterSystem.leftInvSeq` * `CoxeterSystem.rightInvSeq` ## References * [A. Björner and F. Brenti, *Combinatorics of Coxeter Groups*](bjorner2005) -/ namespace CoxeterSystem open List Matrix Function variable {B : Type*} variable {W : Type*} [Group W] variable {M : CoxeterMatrix B} (cs : CoxeterSystem M W) local prefix:100 "s" => cs.simple local prefix:100 "π" => cs.wordProd local prefix:100 "ℓ" => cs.length /-- `t : W` is a *reflection* of the Coxeter system `cs` if it is of the form $w s_i w^{-1}$, where $w \in W$ and $s_i$ is a simple reflection. -/ def IsReflection (t : W) : Prop := ∃ w i, t = w * s i * w⁻¹ theorem isReflection_simple (i : B) : cs.IsReflection (s i) := by use 1, i; simp namespace IsReflection variable {cs} variable {t : W} (ht : cs.IsReflection t) theorem pow_two : t ^ 2 = 1 := by rcases ht with ⟨w, i, rfl⟩ simp theorem mul_self : t * t = 1 := by rcases ht with ⟨w, i, rfl⟩ simp theorem inv : t⁻¹ = t := by rcases ht with ⟨w, i, rfl⟩ simp [mul_assoc] theorem isReflection_inv : cs.IsReflection t⁻¹ := by rwa [ht.inv] theorem odd_length : Odd (ℓ t) := by suffices cs.lengthParity t = Multiplicative.ofAdd 1 by simpa [lengthParity_eq_ofAdd_length, ZMod.eq_one_iff_odd] rcases ht with ⟨w, i, rfl⟩ simp [lengthParity_simple] theorem length_mul_left_ne (w : W) : ℓ (w * t) ≠ ℓ w := by suffices cs.lengthParity (w * t) ≠ cs.lengthParity w by contrapose! this simp only [lengthParity_eq_ofAdd_length, this] rcases ht with ⟨w, i, rfl⟩ simp [lengthParity_simple] theorem length_mul_right_ne (w : W) : ℓ (t * w) ≠ ℓ w := by suffices cs.lengthParity (t * w) ≠ cs.lengthParity w by contrapose! this simp only [lengthParity_eq_ofAdd_length, this] rcases ht with ⟨w, i, rfl⟩ simp [lengthParity_simple] theorem conj (w : W) : cs.IsReflection (w * t * w⁻¹) := by obtain ⟨u, i, rfl⟩ := ht use w * u, i group end IsReflection @[simp] theorem isReflection_conj_iff (w t : W) : cs.IsReflection (w * t * w⁻¹) ↔ cs.IsReflection t := by constructor · intro h simpa [← mul_assoc] using h.conj w⁻¹ · exact IsReflection.conj (w := w) /-- The proposition that `t` is a right inversion of `w`; i.e., `t` is a reflection and $\ell (w t) < \ell(w)$. -/ def IsRightInversion (w t : W) : Prop := cs.IsReflection t ∧ ℓ (w * t) < ℓ w /-- The proposition that `t` is a left inversion of `w`; i.e., `t` is a reflection and $\ell (t w) < \ell(w)$. -/ def IsLeftInversion (w t : W) : Prop := cs.IsReflection t ∧ ℓ (t * w) < ℓ w theorem isRightInversion_inv_iff {w t : W} : cs.IsRightInversion w⁻¹ t ↔ cs.IsLeftInversion w t := by apply and_congr_right intro ht rw [← length_inv, mul_inv_rev, inv_inv, ht.inv, cs.length_inv w] theorem isLeftInversion_inv_iff {w t : W} : cs.IsLeftInversion w⁻¹ t ↔ cs.IsRightInversion w t := by convert cs.isRightInversion_inv_iff.symm simp namespace IsReflection variable {cs} variable {t : W} (ht : cs.IsReflection t) theorem isRightInversion_mul_left_iff {w : W} : cs.IsRightInversion (w * t) t ↔ ¬cs.IsRightInversion w t := by unfold IsRightInversion simp only [mul_assoc, ht.inv, ht.mul_self, mul_one, ht, true_and, not_lt] constructor · exact le_of_lt · exact (lt_of_le_of_ne' · (ht.length_mul_left_ne w)) theorem not_isRightInversion_mul_left_iff {w : W} : ¬cs.IsRightInversion (w * t) t ↔ cs.IsRightInversion w t := ht.isRightInversion_mul_left_iff.not_left theorem isLeftInversion_mul_right_iff {w : W} : cs.IsLeftInversion (t * w) t ↔ ¬cs.IsLeftInversion w t := by rw [← isRightInversion_inv_iff, ← isRightInversion_inv_iff, mul_inv_rev, ht.inv, ht.isRightInversion_mul_left_iff] theorem not_isLeftInversion_mul_right_iff {w : W} : ¬cs.IsLeftInversion (t * w) t ↔ cs.IsLeftInversion w t := ht.isLeftInversion_mul_right_iff.not_left end IsReflection @[simp] theorem isRightInversion_simple_iff_isRightDescent (w : W) (i : B) : cs.IsRightInversion w (s i) ↔ cs.IsRightDescent w i := by simp [IsRightInversion, IsRightDescent, cs.isReflection_simple i] @[simp] theorem isLeftInversion_simple_iff_isLeftDescent (w : W) (i : B) : cs.IsLeftInversion w (s i) ↔ cs.IsLeftDescent w i := by simp [IsLeftInversion, IsLeftDescent, cs.isReflection_simple i] /-- The right inversion sequence of `ω`. The right inversion sequence of a word $s_{i_1} \cdots s_{i_\ell}$ is the sequence $$s_{i_\ell}\cdots s_{i_1}\cdots s_{i_\ell}, \ldots, s_{i_{\ell}}s_{i_{\ell - 1}}s_{i_{\ell - 2}}s_{i_{\ell - 1}}s_{i_\ell}, \ldots, s_{i_{\ell}}s_{i_{\ell - 1}}s_{i_\ell}, s_{i_\ell}.$$ -/ def rightInvSeq (ω : List B) : List W := match ω with | [] => [] | i :: ω => (π ω)⁻¹ * (s i) * (π ω) :: rightInvSeq ω /-- The left inversion sequence of `ω`. The left inversion sequence of a word $s_{i_1} \cdots s_{i_\ell}$ is the sequence $$s_{i_1}, s_{i_1}s_{i_2}s_{i_1}, s_{i_1}s_{i_2}s_{i_3}s_{i_2}s_{i_1}, \ldots, s_{i_1}\cdots s_{i_\ell}\cdots s_{i_1}.$$ -/ def leftInvSeq (ω : List B) : List W := match ω with | [] => [] | i :: ω => s i :: List.map (MulAut.conj (s i)) (leftInvSeq ω) local prefix:100 "ris" => cs.rightInvSeq local prefix:100 "lis" => cs.leftInvSeq @[simp] theorem rightInvSeq_nil : ris [] = [] := rfl @[simp] theorem leftInvSeq_nil : lis [] = [] := rfl @[simp] theorem rightInvSeq_singleton (i : B) : ris [i] = [s i] := by simp [rightInvSeq] @[simp] theorem leftInvSeq_singleton (i : B) : lis [i] = [s i] := rfl theorem rightInvSeq_concat (ω : List B) (i : B) : ris (ω.concat i) = (List.map (MulAut.conj (s i)) (ris ω)).concat (s i) := by induction' ω with j ω ih · simp · dsimp [rightInvSeq] rw [ih] simp only [concat_eq_append, wordProd_append, wordProd_cons, wordProd_nil, mul_one, mul_inv_rev, inv_simple, cons_append, cons.injEq, and_true] group private theorem leftInvSeq_eq_reverse_rightInvSeq_reverse (ω : List B) : lis ω = (ris ω.reverse).reverse := by induction' ω with i ω ih · simp · rw [leftInvSeq, reverse_cons, ← concat_eq_append, rightInvSeq_concat, ih] simp [map_reverse] theorem leftInvSeq_concat (ω : List B) (i : B) : lis (ω.concat i) = (lis ω).concat ((π ω) * (s i) * (π ω)⁻¹) := by simp [leftInvSeq_eq_reverse_rightInvSeq_reverse, rightInvSeq] theorem rightInvSeq_reverse (ω : List B) : ris (ω.reverse) = (lis ω).reverse := by simp [leftInvSeq_eq_reverse_rightInvSeq_reverse] theorem leftInvSeq_reverse (ω : List B) : lis (ω.reverse) = (ris ω).reverse := by simp [leftInvSeq_eq_reverse_rightInvSeq_reverse] @[simp] theorem length_rightInvSeq (ω : List B) : (ris ω).length = ω.length := by induction' ω with i ω ih · simp · simpa [rightInvSeq] @[simp] theorem length_leftInvSeq (ω : List B) : (lis ω).length = ω.length := by simp [leftInvSeq_eq_reverse_rightInvSeq_reverse] theorem getD_rightInvSeq (ω : List B) (j : ℕ) : (ris ω).getD j 1 = (π (ω.drop (j + 1)))⁻¹ * (Option.map (cs.simple) (ω.get? j)).getD 1 * π (ω.drop (j + 1)) := by induction' ω with i ω ih generalizing j · simp · dsimp only [rightInvSeq] rcases j with _ | j' · simp [getD_cons_zero] · simp only [getD_eq_getElem?_getD, get?_eq_getElem?] at ih simp [getD_cons_succ, ih j'] theorem getD_leftInvSeq (ω : List B) (j : ℕ) : (lis ω).getD j 1 = π (ω.take j) * (Option.map (cs.simple) (ω.get? j)).getD 1 * (π (ω.take j))⁻¹ := by induction' ω with i ω ih generalizing j · simp · dsimp [leftInvSeq] rcases j with _ | j' · simp [getD_cons_zero] · rw [getD_cons_succ] rw [(by simp : 1 = ⇑(MulAut.conj (s i)) 1)] rw [getD_map] rw [ih j'] simp [← mul_assoc, wordProd_cons] theorem getD_rightInvSeq_mul_self (ω : List B) (j : ℕ) : ((ris ω).getD j 1) * ((ris ω).getD j 1) = 1 := by simp_rw [getD_rightInvSeq, mul_assoc] rcases em (j < ω.length) with hj | nhj · rw [get?_eq_get hj] simp [← mul_assoc] · rw [get?_eq_none.mpr (by omega)] simp theorem getD_leftInvSeq_mul_self (ω : List B) (j : ℕ) : ((lis ω).getD j 1) * ((lis ω).getD j 1) = 1 := by simp_rw [getD_leftInvSeq, mul_assoc] rcases em (j < ω.length) with hj | nhj · rw [get?_eq_get hj] simp [← mul_assoc] · rw [get?_eq_none.mpr (by omega)] simp theorem rightInvSeq_drop (ω : List B) (j : ℕ) : ris (ω.drop j) = (ris ω).drop j := by induction' j with j ih₁ generalizing ω · simp · induction' ω with k ω _ · simp · rw [drop_succ_cons, ih₁ ω, rightInvSeq, drop_succ_cons] theorem leftInvSeq_take (ω : List B) (j : ℕ) : lis (ω.take j) = (lis ω).take j := by obtain le | ge := Nat.le_or_ge j ω.length · simp only [leftInvSeq_eq_reverse_rightInvSeq_reverse] rw [List.take_reverse (by simpa)] nth_rw 1 [← List.reverse_reverse ω] rw [List.take_reverse (by simpa)] simp [rightInvSeq_drop] · rw [take_of_length_le ge, take_of_length_le (by simpa)] theorem isReflection_of_mem_rightInvSeq (ω : List B) {t : W} (ht : t ∈ ris ω) : cs.IsReflection t := by induction' ω with i ω ih · simp at ht · dsimp [rightInvSeq] at ht rcases ht with _ | ⟨_, mem⟩ · use (π ω)⁻¹, i group · exact ih mem theorem isReflection_of_mem_leftInvSeq (ω : List B) {t : W} (ht : t ∈ lis ω) : cs.IsReflection t := by simp only [leftInvSeq_eq_reverse_rightInvSeq_reverse, mem_reverse] at ht exact cs.isReflection_of_mem_rightInvSeq ω.reverse ht theorem wordProd_mul_getD_rightInvSeq (ω : List B) (j : ℕ) : π ω * ((ris ω).getD j 1) = π (ω.eraseIdx j) := by rw [getD_rightInvSeq, eraseIdx_eq_take_drop_succ] nth_rw 1 [← take_append_drop (j + 1) ω] rw [take_succ] obtain lt | le := lt_or_le j ω.length · simp only [get?_eq_getElem?, getElem?_eq_getElem lt, wordProd_append, wordProd_cons, mul_assoc] simp · simp only [get?_eq_getElem?, getElem?_eq_none le] simp theorem getD_leftInvSeq_mul_wordProd (ω : List B) (j : ℕ) : ((lis ω).getD j 1) * π ω = π (ω.eraseIdx j) := by rw [getD_leftInvSeq, eraseIdx_eq_take_drop_succ] nth_rw 4 [← take_append_drop (j + 1) ω] rw [take_succ] obtain lt | le := lt_or_le j ω.length · simp only [get?_eq_getElem?, getElem?_eq_getElem lt, wordProd_append, wordProd_cons, mul_assoc] simp · simp only [get?_eq_getElem?, getElem?_eq_none le] simp theorem isRightInversion_of_mem_rightInvSeq {ω : List B} (hω : cs.IsReduced ω) {t : W} (ht : t ∈ ris ω) : cs.IsRightInversion (π ω) t := by constructor · exact cs.isReflection_of_mem_rightInvSeq ω ht · obtain ⟨⟨j, hj⟩, rfl⟩ := List.mem_iff_get.mp ht rw [← List.getD_eq_get _ 1 hj, wordProd_mul_getD_rightInvSeq] rw [cs.length_rightInvSeq] at hj calc ℓ (π (ω.eraseIdx j)) _ ≤ (ω.eraseIdx j).length := cs.length_wordProd_le _ _ < ω.length := by rw [← List.length_eraseIdx_add_one hj]; exact lt_add_one _ _ = ℓ (π ω) := hω.symm theorem isLeftInversion_of_mem_leftInvSeq {ω : List B} (hω : cs.IsReduced ω) {t : W} (ht : t ∈ lis ω) : cs.IsLeftInversion (π ω) t := by constructor · exact cs.isReflection_of_mem_leftInvSeq ω ht · obtain ⟨⟨j, hj⟩, rfl⟩ := List.mem_iff_get.mp ht rw [← List.getD_eq_get _ 1 hj, getD_leftInvSeq_mul_wordProd] rw [cs.length_leftInvSeq] at hj calc ℓ (π (ω.eraseIdx j)) _ ≤ (ω.eraseIdx j).length := cs.length_wordProd_le _ _ < ω.length := by rw [← List.length_eraseIdx_add_one hj]; exact lt_add_one _ _ = ℓ (π ω) := hω.symm theorem prod_rightInvSeq (ω : List B) : prod (ris ω) = (π ω)⁻¹ := by induction' ω with i ω ih · simp · simp [rightInvSeq, ih, wordProd_cons] theorem prod_leftInvSeq (ω : List B) : prod (lis ω) = (π ω)⁻¹ := by simp [leftInvSeq_eq_reverse_rightInvSeq_reverse, prod_reverse_noncomm] have : List.map (fun x ↦ x⁻¹) (ris ω.reverse) = ris ω.reverse := calc List.map (fun x ↦ x⁻¹) (ris ω.reverse) _ = List.map id (ris ω.reverse) := by apply List.map_congr_left intro t ht exact (cs.isReflection_of_mem_rightInvSeq _ ht).inv _ = ris ω.reverse := map_id _ rw [this] nth_rw 2 [← reverse_reverse ω] rw [wordProd_reverse] exact cs.prod_rightInvSeq _ theorem IsReduced.nodup_rightInvSeq {ω : List B} (rω : cs.IsReduced ω) : List.Nodup (ris ω) := by apply List.nodup_iff_get?_ne_get?.mpr intro j j' j_lt_j' j'_lt_length (dup : get? (rightInvSeq cs ω) j = get? (rightInvSeq cs ω) j') show False replace j'_lt_length : j' < List.length ω := by simpa using j'_lt_length rw [get?_eq_get (by simp; omega), get?_eq_get (by simp; omega)] at dup apply Option.some_injective at dup rw [← getD_eq_get _ 1, ← getD_eq_get _ 1] at dup set! t := (ris ω).getD j 1 with h₁ set! t' := (ris (ω.eraseIdx j)).getD (j' - 1) 1 with h₂ have h₃ : t' = (ris ω).getD j' 1 := by rw [h₂, cs.getD_rightInvSeq, cs.getD_rightInvSeq, (Nat.sub_add_cancel (by omega) : j' - 1 + 1 = j'), eraseIdx_eq_take_drop_succ, drop_append_eq_append_drop, drop_of_length_le (by simp [j_lt_j'.le]), length_take, drop_drop, nil_append, min_eq_left_of_lt (j_lt_j'.trans j'_lt_length), ← add_assoc, Nat.sub_add_cancel (by omega), mul_left_inj, mul_right_inj] congr 2 show get? (take j ω ++ drop (j + 1) ω) (j' - 1) = get? ω j' rw [get?_eq_getElem?, get?_eq_getElem?, getElem?_append_right (by simp [Nat.le_sub_one_of_lt j_lt_j']), getElem?_drop] congr show j + 1 + (j' - 1 - List.length (take j ω)) = j' rw [length_take] omega have h₄ : t * t' = 1 := by rw [h₁, h₃, dup] exact cs.getD_rightInvSeq_mul_self _ _ have h₅ := calc π ω = π ω * t * t' := by rw [mul_assoc, h₄]; group _ = (π (ω.eraseIdx j)) * t' := congrArg (· * t') (cs.wordProd_mul_getD_rightInvSeq _ _) _ = π ((ω.eraseIdx j).eraseIdx (j' - 1)) := cs.wordProd_mul_getD_rightInvSeq _ _ have h₆ := calc ω.length = ℓ (π ω) := rω.symm _ = ℓ (π ((ω.eraseIdx j).eraseIdx (j' - 1))) := congrArg cs.length h₅ _ ≤ ((ω.eraseIdx j).eraseIdx (j' - 1)).length := cs.length_wordProd_le _ have h₇ := add_le_add_right (add_le_add_right h₆ 1) 1 have h₈ : j' - 1 < List.length (eraseIdx ω j) := by apply (@Nat.add_lt_add_iff_right 1).mp rw [Nat.sub_add_cancel (by omega)] rw [length_eraseIdx_add_one (by omega)] omega rw [length_eraseIdx_add_one h₈] at h₇ rw [length_eraseIdx_add_one (by omega)] at h₇ omega theorem IsReduced.nodup_leftInvSeq {ω : List B} (rω : cs.IsReduced ω) : List.Nodup (lis ω) := by simp only [leftInvSeq_eq_reverse_rightInvSeq_reverse, nodup_reverse] apply nodup_rightInvSeq rwa [isReduced_reverse] end CoxeterSystem
GroupTheory\Coxeter\Length.lean
/- Copyright (c) 2024 Mitchell Lee. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mitchell Lee -/ import Mathlib.Data.ZMod.Basic import Mathlib.GroupTheory.Coxeter.Basic import Mathlib.Tactic.Zify /-! # The length function, reduced words, and descents Throughout this file, `B` is a type and `M : CoxeterMatrix B` is a Coxeter matrix. `cs : CoxeterSystem M W` is a Coxeter system; that is, `W` is a group, and `cs` holds the data of a group isomorphism `W ≃* M.group`, where `M.group` refers to the quotient of the free group on `B` by the Coxeter relations given by the matrix `M`. See `Mathlib/GroupTheory/Coxeter/Basic.lean` for more details. Given any element $w \in W$, its *length* (`CoxeterSystem.length`), denoted $\ell(w)$, is the minimum number $\ell$ such that $w$ can be written as a product of a sequence of $\ell$ simple reflections: $$w = s_{i_1} \cdots s_{i_\ell}.$$ We prove for all $w_1, w_2 \in W$ that $\ell (w_1 w_2) \leq \ell (w_1) + \ell (w_2)$ and that $\ell (w_1 w_2)$ has the same parity as $\ell (w_1) + \ell (w_2)$. We define a *reduced word* (`CoxeterSystem.IsReduced`) for an element $w \in W$ to be a way of writing $w$ as a product of exactly $\ell(w)$ simple reflections. Every element of $W$ has a reduced word. We say that $i \in B$ is a *left descent* (`CoxeterSystem.IsLeftDescent`) of $w \in W$ if $\ell(s_i w) < \ell(w)$. We show that if $i$ is a left descent of $w$, then $\ell(s_i w) + 1 = \ell(w)$. On the other hand, if $i$ is not a left descent of $w$, then $\ell(s_i w) = \ell(w) + 1$. We similarly define right descents (`CoxeterSystem.IsRightDescent`) and prove analogous results. ## Main definitions * `cs.length` * `cs.IsReduced` * `cs.IsLeftDescent` * `cs.IsRightDescent` ## References * [A. Björner and F. Brenti, *Combinatorics of Coxeter Groups*](bjorner2005) -/ namespace CoxeterSystem open List Matrix Function Classical variable {B : Type*} variable {W : Type*} [Group W] variable {M : CoxeterMatrix B} (cs : CoxeterSystem M W) local prefix:100 "s" => cs.simple local prefix:100 "π" => cs.wordProd /-! ### Length -/ private theorem exists_word_with_prod (w : W) : ∃ n ω, ω.length = n ∧ π ω = w := by rcases cs.wordProd_surjective w with ⟨ω, rfl⟩ use ω.length, ω /-- The length of `w`; i.e., the minimum number of simple reflections that must be multiplied to form `w`. -/ noncomputable def length (w : W) : ℕ := Nat.find (cs.exists_word_with_prod w) local prefix:100 "ℓ" => cs.length theorem exists_reduced_word (w : W) : ∃ ω, ω.length = ℓ w ∧ w = π ω := by have := Nat.find_spec (cs.exists_word_with_prod w) tauto theorem length_wordProd_le (ω : List B) : ℓ (π ω) ≤ ω.length := Nat.find_min' (cs.exists_word_with_prod (π ω)) ⟨ω, by tauto⟩ @[simp] theorem length_one : ℓ (1 : W) = 0 := Nat.eq_zero_of_le_zero (cs.length_wordProd_le []) @[simp] theorem length_eq_zero_iff {w : W} : ℓ w = 0 ↔ w = 1 := by constructor · intro h rcases cs.exists_reduced_word w with ⟨ω, hω, rfl⟩ have : ω = [] := eq_nil_of_length_eq_zero (hω.trans h) rw [this, wordProd_nil] · rintro rfl exact cs.length_one @[simp] theorem length_inv (w : W) : ℓ (w⁻¹) = ℓ w := by apply Nat.le_antisymm · rcases cs.exists_reduced_word w with ⟨ω, hω, rfl⟩ have := cs.length_wordProd_le (List.reverse ω) rwa [wordProd_reverse, length_reverse, hω] at this · rcases cs.exists_reduced_word w⁻¹ with ⟨ω, hω, h'ω⟩ have := cs.length_wordProd_le (List.reverse ω) rwa [wordProd_reverse, length_reverse, ← h'ω, hω, inv_inv] at this theorem length_mul_le (w₁ w₂ : W) : ℓ (w₁ * w₂) ≤ ℓ w₁ + ℓ w₂ := by rcases cs.exists_reduced_word w₁ with ⟨ω₁, hω₁, rfl⟩ rcases cs.exists_reduced_word w₂ with ⟨ω₂, hω₂, rfl⟩ have := cs.length_wordProd_le (ω₁ ++ ω₂) simpa [hω₁, hω₂, wordProd_append] using this theorem length_mul_ge_length_sub_length (w₁ w₂ : W) : ℓ w₁ - ℓ w₂ ≤ ℓ (w₁ * w₂) := by simpa [Nat.sub_le_of_le_add] using cs.length_mul_le (w₁ * w₂) w₂⁻¹ theorem length_mul_ge_length_sub_length' (w₁ w₂ : W) : ℓ w₂ - ℓ w₁ ≤ ℓ (w₁ * w₂) := by simpa [Nat.sub_le_of_le_add, add_comm] using cs.length_mul_le w₁⁻¹ (w₁ * w₂) theorem length_mul_ge_max (w₁ w₂ : W) : max (ℓ w₁ - ℓ w₂) (ℓ w₂ - ℓ w₁) ≤ ℓ (w₁ * w₂) := max_le_iff.mpr ⟨length_mul_ge_length_sub_length _ _ _, length_mul_ge_length_sub_length' _ _ _⟩ /-- The homomorphism that sends each element `w : W` to the parity of the length of `w`. (See `lengthParity_eq_ofAdd_length`.) -/ def lengthParity : W →* Multiplicative (ZMod 2) := cs.lift ⟨fun _ ↦ Multiplicative.ofAdd 1, by simp_rw [CoxeterMatrix.IsLiftable, ← ofAdd_add, (by decide : (1 + 1 : ZMod 2) = 0)] simp⟩ theorem lengthParity_simple (i : B) : cs.lengthParity (s i) = Multiplicative.ofAdd 1 := cs.lift_apply_simple _ _ theorem lengthParity_comp_simple : cs.lengthParity ∘ cs.simple = fun _ ↦ Multiplicative.ofAdd 1 := funext cs.lengthParity_simple theorem lengthParity_eq_ofAdd_length (w : W) : cs.lengthParity w = Multiplicative.ofAdd (↑(ℓ w)) := by rcases cs.exists_reduced_word w with ⟨ω, hω, rfl⟩ rw [← hω, wordProd, map_list_prod, List.map_map, lengthParity_comp_simple, map_const', prod_replicate, ← ofAdd_nsmul, nsmul_one] theorem length_mul_mod_two (w₁ w₂ : W) : ℓ (w₁ * w₂) % 2 = (ℓ w₁ + ℓ w₂) % 2 := by rw [← ZMod.natCast_eq_natCast_iff', Nat.cast_add] simpa only [lengthParity_eq_ofAdd_length, ofAdd_add] using map_mul cs.lengthParity w₁ w₂ @[simp] theorem length_simple (i : B) : ℓ (s i) = 1 := by apply Nat.le_antisymm · simpa using cs.length_wordProd_le [i] · by_contra! length_lt_one have : cs.lengthParity (s i) = Multiplicative.ofAdd 0 := by rw [lengthParity_eq_ofAdd_length, Nat.lt_one_iff.mp length_lt_one, Nat.cast_zero] have : Multiplicative.ofAdd (0 : ZMod 2) = Multiplicative.ofAdd 1 := this.symm.trans (cs.lengthParity_simple i) contradiction theorem length_eq_one_iff {w : W} : ℓ w = 1 ↔ ∃ i : B, w = s i := by constructor · intro h rcases cs.exists_reduced_word w with ⟨ω, hω, rfl⟩ rcases List.length_eq_one.mp (hω.trans h) with ⟨i, rfl⟩ exact ⟨i, cs.wordProd_singleton i⟩ · rintro ⟨i, rfl⟩ exact cs.length_simple i theorem length_mul_simple_ne (w : W) (i : B) : ℓ (w * s i) ≠ ℓ w := by intro eq have length_mod_two := cs.length_mul_mod_two w (s i) rw [eq, length_simple] at length_mod_two rcases Nat.mod_two_eq_zero_or_one (ℓ w) with even | odd · rw [even, Nat.succ_mod_two_eq_one_iff.mpr even] at length_mod_two contradiction · rw [odd, Nat.succ_mod_two_eq_zero_iff.mpr odd] at length_mod_two contradiction theorem length_simple_mul_ne (w : W) (i : B) : ℓ (s i * w) ≠ ℓ w := by convert cs.length_mul_simple_ne w⁻¹ i using 1 · convert cs.length_inv ?_ using 2 simp · simp theorem length_mul_simple (w : W) (i : B) : ℓ (w * s i) = ℓ w + 1 ∨ ℓ (w * s i) + 1 = ℓ w := by rcases Nat.lt_or_gt_of_ne (cs.length_mul_simple_ne w i) with lt | gt · -- lt : ℓ (w * s i) < ℓ w right have length_ge := cs.length_mul_ge_length_sub_length w (s i) simp only [length_simple, tsub_le_iff_right] at length_ge -- length_ge : ℓ w ≤ ℓ (w * s i) + 1 linarith · -- gt : ℓ w < ℓ (w * s i) left have length_le := cs.length_mul_le w (s i) simp only [length_simple] at length_le -- length_le : ℓ (w * s i) ≤ ℓ w + 1 linarith theorem length_simple_mul (w : W) (i : B) : ℓ (s i * w) = ℓ w + 1 ∨ ℓ (s i * w) + 1 = ℓ w := by have := cs.length_mul_simple w⁻¹ i rwa [(by simp : w⁻¹ * (s i) = ((s i) * w)⁻¹), length_inv, length_inv] at this /-! ### Reduced words -/ /-- The proposition that `ω` is reduced; that is, it has minimal length among all words that represent the same element of `W`. -/ def IsReduced (ω : List B) : Prop := ℓ (π ω) = ω.length @[simp] theorem isReduced_reverse (ω : List B) : cs.IsReduced (ω.reverse) ↔ cs.IsReduced ω := by simp [IsReduced] theorem exists_reduced_word' (w : W) : ∃ ω : List B, cs.IsReduced ω ∧ w = π ω := by rcases cs.exists_reduced_word w with ⟨ω, hω, rfl⟩ use ω tauto private theorem isReduced_take_and_drop {ω : List B} (hω : cs.IsReduced ω) (j : ℕ) : cs.IsReduced (ω.take j) ∧ cs.IsReduced (ω.drop j) := by have h₁ : ℓ (π (ω.take j)) ≤ (ω.take j).length := cs.length_wordProd_le (ω.take j) have h₂ : ℓ (π (ω.drop j)) ≤ (ω.drop j).length := cs.length_wordProd_le (ω.drop j) have h₃ := calc (ω.take j).length + (ω.drop j).length _ = ω.length := by rw [← List.length_append, ω.take_append_drop j] _ = ℓ (π ω) := hω.symm _ = ℓ (π (ω.take j) * π (ω.drop j)) := by rw [← cs.wordProd_append, ω.take_append_drop j] _ ≤ ℓ (π (ω.take j)) + ℓ (π (ω.drop j)) := cs.length_mul_le _ _ unfold IsReduced exact ⟨by linarith, by linarith⟩ theorem isReduced_take {ω : List B} (hω : cs.IsReduced ω) (j : ℕ) : cs.IsReduced (ω.take j) := (isReduced_take_and_drop _ hω _).1 theorem isReduced_drop {ω : List B} (hω : cs.IsReduced ω) (j : ℕ) : cs.IsReduced (ω.drop j) := (isReduced_take_and_drop _ hω _).2 theorem not_isReduced_alternatingWord (i i' : B) {m : ℕ} (hM : M i i' ≠ 0) (hm : m > M i i') : ¬cs.IsReduced (alternatingWord i i' m) := by induction' hm with m _ ih · -- Base case; m = M i i' + 1 suffices h : ℓ (π (alternatingWord i i' (M i i' + 1))) < M i i' + 1 by unfold IsReduced rw [Nat.succ_eq_add_one, length_alternatingWord] linarith have : M i i' + 1 ≤ M i i' * 2 := by linarith [Nat.one_le_iff_ne_zero.mpr hM] rw [cs.prod_alternatingWord_eq_prod_alternatingWord_sub i i' _ this] have : M i i' * 2 - (M i i' + 1) = M i i' - 1 := by apply (Nat.sub_eq_iff_eq_add' this).mpr rw [add_assoc, add_comm 1, Nat.sub_add_cancel (Nat.one_le_iff_ne_zero.mpr hM)] exact mul_two _ rw [this] calc ℓ (π (alternatingWord i' i (M i i' - 1))) _ ≤ (alternatingWord i' i (M i i' - 1)).length := cs.length_wordProd_le _ _ = M i i' - 1 := length_alternatingWord _ _ _ _ ≤ M i i' := Nat.sub_le _ _ _ < M i i' + 1 := Nat.lt_succ_self _ · -- Inductive step contrapose! ih rw [alternatingWord_succ'] at ih apply isReduced_drop (j := 1) at ih simpa using ih /-! ### Descents -/ /-- The proposition that `i` is a left descent of `w`; that is, $\ell(s_i w) < \ell(w)$. -/ def IsLeftDescent (w : W) (i : B) : Prop := ℓ (s i * w) < ℓ w /-- The proposition that `i` is a right descent of `w`; that is, $\ell(w s_i) < \ell(w)$. -/ def IsRightDescent (w : W) (i : B) : Prop := ℓ (w * s i) < ℓ w theorem not_isLeftDescent_one (i : B) : ¬cs.IsLeftDescent 1 i := by simp [IsLeftDescent] theorem not_isRightDescent_one (i : B) : ¬cs.IsRightDescent 1 i := by simp [IsRightDescent] theorem isLeftDescent_inv_iff {w : W} {i : B} : cs.IsLeftDescent w⁻¹ i ↔ cs.IsRightDescent w i := by unfold IsLeftDescent IsRightDescent nth_rw 1 [← length_inv] simp theorem isRightDescent_inv_iff {w : W} {i : B} : cs.IsRightDescent w⁻¹ i ↔ cs.IsLeftDescent w i := by simpa using (cs.isLeftDescent_inv_iff (w := w⁻¹)).symm theorem exists_leftDescent_of_ne_one {w : W} (hw : w ≠ 1) : ∃ i : B, cs.IsLeftDescent w i := by rcases cs.exists_reduced_word w with ⟨ω, h, rfl⟩ have h₁ : ω ≠ [] := by rintro rfl; simp at hw rcases List.exists_cons_of_ne_nil h₁ with ⟨i, ω', rfl⟩ use i rw [IsLeftDescent, ← h, wordProd_cons, simple_mul_simple_cancel_left] calc ℓ (π ω') ≤ ω'.length := cs.length_wordProd_le ω' _ < (i :: ω').length := by simp theorem exists_rightDescent_of_ne_one {w : W} (hw : w ≠ 1) : ∃ i : B, cs.IsRightDescent w i := by simp only [← isLeftDescent_inv_iff] apply exists_leftDescent_of_ne_one simpa theorem isLeftDescent_iff {w : W} {i : B} : cs.IsLeftDescent w i ↔ ℓ (s i * w) + 1 = ℓ w := by unfold IsLeftDescent constructor · intro _ exact (cs.length_simple_mul w i).resolve_left (by linarith) · intro _ linarith theorem not_isLeftDescent_iff {w : W} {i : B} : ¬cs.IsLeftDescent w i ↔ ℓ (s i * w) = ℓ w + 1 := by unfold IsLeftDescent constructor · intro _ exact (cs.length_simple_mul w i).resolve_right (by linarith) · intro _ linarith theorem isRightDescent_iff {w : W} {i : B} : cs.IsRightDescent w i ↔ ℓ (w * s i) + 1 = ℓ w := by unfold IsRightDescent constructor · intro _ exact (cs.length_mul_simple w i).resolve_left (by linarith) · intro _ linarith theorem not_isRightDescent_iff {w : W} {i : B} : ¬cs.IsRightDescent w i ↔ ℓ (w * s i) = ℓ w + 1 := by unfold IsRightDescent constructor · intro _ exact (cs.length_mul_simple w i).resolve_right (by linarith) · intro _ linarith theorem isLeftDescent_iff_not_isLeftDescent_mul {w : W} {i : B} : cs.IsLeftDescent w i ↔ ¬cs.IsLeftDescent (s i * w) i := by rw [isLeftDescent_iff, not_isLeftDescent_iff, simple_mul_simple_cancel_left] tauto theorem isRightDescent_iff_not_isRightDescent_mul {w : W} {i : B} : cs.IsRightDescent w i ↔ ¬cs.IsRightDescent (w * s i) i := by rw [isRightDescent_iff, not_isRightDescent_iff, simple_mul_simple_cancel_right] tauto end CoxeterSystem
GroupTheory\Coxeter\Matrix.lean
/- Copyright (c) 2024 Newell Jensen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Newell Jensen, Mitchell Lee -/ import Mathlib.Data.Matrix.Notation import Mathlib.LinearAlgebra.Matrix.Symmetric /-! # Coxeter matrices Let us say that a matrix (possibly an infinite matrix) is a *Coxeter matrix* (`CoxeterMatrix`) if its entries are natural numbers, it is symmetric, its diagonal entries are equal to 1, and its off-diagonal entries are not equal to 1. In this file, we define Coxeter matrices and provide some ways of constructing them. We also define the Coxeter matrices `CoxeterMatrix.Aₙ` (`n : ℕ`), `CoxeterMatrix.Bₙ` (`n : ℕ`), `CoxeterMatrix.Dₙ` (`n : ℕ`), `CoxeterMatrix.I₂ₘ` (`m : ℕ`), `CoxeterMatrix.E₆`, `CoxeterMatrix.E₇`, `CoxeterMatrix.E₈`, `CoxeterMatrix.F₄`, `CoxeterMatrix.G₂`, `CoxeterMatrix.H₃`, and `CoxeterMatrix.H₄`. Up to reindexing, these are exactly the Coxeter matrices whose corresponding Coxeter group (`CoxeterMatrix.coxeterGroup`) is finite and irreducible, although we do not prove that in this file. ## Implementation details In some texts on Coxeter groups, each entry $M_{i,i'}$ of a Coxeter matrix can be either a positive integer or $\infty$. In our treatment of Coxeter matrices, we use the value $0$ instead of $\infty$. This will turn out to have some fortunate consequences when defining the Coxeter group of a Coxeter matrix and the standard geometric representation of a Coxeter group. ## Main definitions * `CoxeterMatrix` : The type of symmetric matrices of natural numbers, with rows and columns indexed by a type `B`, whose diagonal entries are equal to 1 and whose off-diagonal entries are not equal to 1. * `CoxeterMatrix.reindex` : Reindexes a Coxeter matrix by a bijection on the index type. * `CoxeterMatrix.Aₙ` : Coxeter matrix for the symmetry group of the regular n-simplex. * `CoxeterMatrix.Bₙ` : Coxeter matrix for the symmetry group of the regular n-hypercube and its dual, the regular n-orthoplex (or n-cross-polytope). * `CoxeterMatrix.Dₙ` : Coxeter matrix for the symmetry group of the n-demicube. * `CoxeterMatrix.I₂ₘ` : Coxeter matrix for the symmetry group of the regular (m + 2)-gon. * `CoxeterMatrix.E₆` : Coxeter matrix for the symmetry group of the E₆ root polytope. * `CoxeterMatrix.E₇` : Coxeter matrix for the symmetry group of the E₇ root polytope. * `CoxeterMatrix.E₈` : Coxeter matrix for the symmetry group of the E₈ root polytope. * `CoxeterMatrix.F₄` : Coxeter matrix for the symmetry group of the regular 4-polytope, the 24-cell. * `CoxeterMatrix.G₂` : Coxeter matrix for the symmetry group of the regular hexagon. * `CoxeterMatrix.H₃` : Coxeter matrix for the symmetry group of the regular dodecahedron and icosahedron. * `CoxeterMatrix.H₄` : Coxeter matrix for the symmetry group of the regular 4-polytopes, the 120-cell and 600-cell. ## References * [N. Bourbaki, *Lie Groups and Lie Algebras, Chapters 4--6*](bourbaki1968) chapter IV pages 4--5, 13--15 * [J. Baez, *Coxeter and Dynkin Diagrams*](https://math.ucr.edu/home/baez/twf_dynkin.pdf) -/ /-- A *Coxeter matrix* is a symmetric matrix of natural numbers whose diagonal entries are equal to 1 and whose off-diagonal entries are not equal to 1. -/ @[ext] structure CoxeterMatrix (B : Type*) where /-- The underlying matrix of the Coxeter matrix. -/ M : Matrix B B ℕ isSymm : M.IsSymm := by decide diagonal i : M i i = 1 := by decide off_diagonal i i' : i ≠ i' → M i i' ≠ 1 := by decide namespace CoxeterMatrix variable {B : Type*} /-- A Coxeter matrix can be coerced to a matrix. -/ instance : CoeFun (CoxeterMatrix B) fun _ ↦ (Matrix B B ℕ) := ⟨M⟩ variable {B' : Type*} (e : B ≃ B') (M : CoxeterMatrix B) attribute [simp] diagonal theorem symmetric (i i' : B) : M i i' = M i' i := M.isSymm.apply i' i /-- The Coxeter matrix formed by reindexing via the bijection `e : B ≃ B'`. -/ protected def reindex : CoxeterMatrix B' where M := Matrix.reindex e e M isSymm := M.isSymm.submatrix _ diagonal i := M.diagonal (e.symm i) off_diagonal i i' h := M.off_diagonal (e.symm i) (e.symm i') (e.symm.injective.ne h) theorem reindex_apply (i i' : B') : M.reindex e i i' = M (e.symm i) (e.symm i') := rfl variable (n : ℕ) /-- The Coxeter matrix of type Aₙ. The corresponding Coxeter-Dynkin diagram is: ``` o --- o --- o ⬝ ⬝ ⬝ ⬝ o --- o ``` -/ def Aₙ : CoxeterMatrix (Fin n) where M := Matrix.of fun i j : Fin n ↦ if i = j then 1 else (if (j : ℕ) + 1 = i ∨ (i : ℕ) + 1 = j then 3 else 2) isSymm := by unfold Matrix.IsSymm; aesop diagonal := by simp off_diagonal := by aesop /-- The Coxeter matrix of type Bₙ. The corresponding Coxeter-Dynkin diagram is: ``` 4 o --- o --- o ⬝ ⬝ ⬝ ⬝ o --- o ``` -/ def Bₙ : CoxeterMatrix (Fin n) where M := Matrix.of fun i j : Fin n ↦ if i = j then 1 else (if i = n - 1 ∧ j = n - 2 ∨ j = n - 1 ∧ i = n - 2 then 4 else (if (j : ℕ) + 1 = i ∨ (i : ℕ) + 1 = j then 3 else 2)) isSymm := by unfold Matrix.IsSymm; aesop diagonal := by simp off_diagonal := by aesop /-- The Coxeter matrix of type Dₙ. The corresponding Coxeter-Dynkin diagram is: ``` o \ o --- o ⬝ ⬝ ⬝ ⬝ o --- o / o ``` -/ def Dₙ : CoxeterMatrix (Fin n) where M := Matrix.of fun i j : Fin n ↦ if i = j then 1 else (if i = n - 1 ∧ j = n - 3 ∨ j = n - 1 ∧ i = n - 3 then 3 else (if (j : ℕ) + 1 = i ∨ (i : ℕ) + 1 = j then 3 else 2)) isSymm := by unfold Matrix.IsSymm; aesop diagonal := by simp off_diagonal := by aesop /-- The Coxeter matrix of type I₂(m). The corresponding Coxeter-Dynkin diagram is: ``` m + 2 o --- o ``` -/ def I₂ₘ (m : ℕ) : CoxeterMatrix (Fin 2) where M := Matrix.of fun i j => if i = j then 1 else m + 2 isSymm := by unfold Matrix.IsSymm; aesop diagonal := by simp off_diagonal := by simp /-- The Coxeter matrix of type E₆. The corresponding Coxeter-Dynkin diagram is: ``` o | o --- o --- o --- o --- o ``` -/ def E₆ : CoxeterMatrix (Fin 6) where M := !![1, 2, 3, 2, 2, 2; 2, 1, 2, 3, 2, 2; 3, 2, 1, 3, 2, 2; 2, 3, 3, 1, 3, 2; 2, 2, 2, 3, 1, 3; 2, 2, 2, 2, 3, 1] /-- The Coxeter matrix of type E₇. The corresponding Coxeter-Dynkin diagram is: ``` o | o --- o --- o --- o --- o --- o ``` -/ def E₇ : CoxeterMatrix (Fin 7) where M := !![1, 2, 3, 2, 2, 2, 2; 2, 1, 2, 3, 2, 2, 2; 3, 2, 1, 3, 2, 2, 2; 2, 3, 3, 1, 3, 2, 2; 2, 2, 2, 3, 1, 3, 2; 2, 2, 2, 2, 3, 1, 3; 2, 2, 2, 2, 2, 3, 1] /-- The Coxeter matrix of type E₈. The corresponding Coxeter-Dynkin diagram is: ``` o | o --- o --- o --- o --- o --- o --- o ``` -/ def E₈ : CoxeterMatrix (Fin 8) where M := !![1, 2, 3, 2, 2, 2, 2, 2; 2, 1, 2, 3, 2, 2, 2, 2; 3, 2, 1, 3, 2, 2, 2, 2; 2, 3, 3, 1, 3, 2, 2, 2; 2, 2, 2, 3, 1, 3, 2, 2; 2, 2, 2, 2, 3, 1, 3, 2; 2, 2, 2, 2, 2, 3, 1, 3; 2, 2, 2, 2, 2, 2, 3, 1] /-- The Coxeter matrix of type F₄. The corresponding Coxeter-Dynkin diagram is: ``` 4 o --- o --- o --- o ``` -/ def F₄ : CoxeterMatrix (Fin 4) where M := !![1, 3, 2, 2; 3, 1, 4, 2; 2, 4, 1, 3; 2, 2, 3, 1] /-- The Coxeter matrix of type G₂. The corresponding Coxeter-Dynkin diagram is: ``` 6 o --- o ``` -/ def G₂ : CoxeterMatrix (Fin 2) where M := !![1, 6; 6, 1] /-- The Coxeter matrix of type H₃. The corresponding Coxeter-Dynkin diagram is: ``` 5 o --- o --- o ``` -/ def H₃ : CoxeterMatrix (Fin 3) where M := !![1, 3, 2; 3, 1, 5; 2, 5, 1] /-- The Coxeter matrix of type H₄. The corresponding Coxeter-Dynkin diagram is: ``` 5 o --- o --- o --- o ``` -/ def H₄ : CoxeterMatrix (Fin 4) where M := !![1, 3, 2, 2; 3, 1, 3, 2; 2, 3, 1, 5; 2, 2, 5, 1] end CoxeterMatrix
GroupTheory\FreeGroup\Basic.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.Group.Subgroup.Basic import Mathlib.Data.Fintype.Basic import Mathlib.Data.List.Sublists import Mathlib.Data.List.InsertNth /-! # Free groups This file defines free groups over a type. Furthermore, it is shown that the free group construction is an instance of a monad. For the result that `FreeGroup` is the left adjoint to the forgetful functor from groups to types, see `Algebra/Category/Group/Adjunctions`. ## Main definitions * `FreeGroup`/`FreeAddGroup`: the free group (resp. free additive group) associated to a type `α` defined as the words over `a : α × Bool` modulo the relation `a * x * x⁻¹ * b = a * b`. * `FreeGroup.mk`/`FreeAddGroup.mk`: the canonical quotient map `List (α × Bool) → FreeGroup α`. * `FreeGroup.of`/`FreeAddGroup.of`: the canonical injection `α → FreeGroup α`. * `FreeGroup.lift f`/`FreeAddGroup.lift`: the canonical group homomorphism `FreeGroup α →* G` given a group `G` and a function `f : α → G`. ## Main statements * `FreeGroup.Red.church_rosser`/`FreeAddGroup.Red.church_rosser`: The Church-Rosser theorem for word reduction (also known as Newman's diamond lemma). * `FreeGroup.freeGroupUnitEquivInt`: The free group over the one-point type is isomorphic to the integers. * The free group construction is an instance of a monad. ## Implementation details First we introduce the one step reduction relation `FreeGroup.Red.Step`: `w * x * x⁻¹ * v ~> w * v`, its reflexive transitive closure `FreeGroup.Red.trans` and prove that its join is an equivalence relation. Then we introduce `FreeGroup α` as a quotient over `FreeGroup.Red.Step`. For the additive version we introduce the same relation under a different name so that we can distinguish the quotient types more easily. ## Tags free group, Newman's diamond lemma, Church-Rosser theorem -/ open Relation universe u v w variable {α : Type u} attribute [local simp] List.append_eq_has_append -- Porting note: to_additive.map_namespace is not supported yet -- worked around it by putting a few extra manual mappings (but not too many all in all) -- run_cmd to_additive.map_namespace `FreeGroup `FreeAddGroup /-- Reduction step for the additive free group relation: `w + x + (-x) + v ~> w + v` -/ inductive FreeAddGroup.Red.Step : List (α × Bool) → List (α × Bool) → Prop | not {L₁ L₂ x b} : FreeAddGroup.Red.Step (L₁ ++ (x, b) :: (x, not b) :: L₂) (L₁ ++ L₂) attribute [simp] FreeAddGroup.Red.Step.not /-- Reduction step for the multiplicative free group relation: `w * x * x⁻¹ * v ~> w * v` -/ @[to_additive FreeAddGroup.Red.Step] inductive FreeGroup.Red.Step : List (α × Bool) → List (α × Bool) → Prop | not {L₁ L₂ x b} : FreeGroup.Red.Step (L₁ ++ (x, b) :: (x, not b) :: L₂) (L₁ ++ L₂) attribute [simp] FreeGroup.Red.Step.not namespace FreeGroup variable {L L₁ L₂ L₃ L₄ : List (α × Bool)} /-- Reflexive-transitive closure of `Red.Step` -/ @[to_additive FreeAddGroup.Red "Reflexive-transitive closure of `Red.Step`"] def Red : List (α × Bool) → List (α × Bool) → Prop := ReflTransGen Red.Step @[to_additive (attr := refl)] theorem Red.refl : Red L L := ReflTransGen.refl @[to_additive (attr := trans)] theorem Red.trans : Red L₁ L₂ → Red L₂ L₃ → Red L₁ L₃ := ReflTransGen.trans namespace Red /-- Predicate asserting that the word `w₁` can be reduced to `w₂` in one step, i.e. there are words `w₃ w₄` and letter `x` such that `w₁ = w₃xx⁻¹w₄` and `w₂ = w₃w₄` -/ @[to_additive "Predicate asserting that the word `w₁` can be reduced to `w₂` in one step, i.e. there are words `w₃ w₄` and letter `x` such that `w₁ = w₃ + x + (-x) + w₄` and `w₂ = w₃w₄`"] theorem Step.length : ∀ {L₁ L₂ : List (α × Bool)}, Step L₁ L₂ → L₂.length + 2 = L₁.length | _, _, @Red.Step.not _ L1 L2 x b => by rw [List.length_append, List.length_append]; rfl @[to_additive (attr := simp)] theorem Step.not_rev {x b} : Step (L₁ ++ (x, !b) :: (x, b) :: L₂) (L₁ ++ L₂) := by cases b <;> exact Step.not @[to_additive (attr := simp)] theorem Step.cons_not {x b} : Red.Step ((x, b) :: (x, !b) :: L) L := @Step.not _ [] _ _ _ @[to_additive (attr := simp)] theorem Step.cons_not_rev {x b} : Red.Step ((x, !b) :: (x, b) :: L) L := @Red.Step.not_rev _ [] _ _ _ @[to_additive] theorem Step.append_left : ∀ {L₁ L₂ L₃ : List (α × Bool)}, Step L₂ L₃ → Step (L₁ ++ L₂) (L₁ ++ L₃) | _, _, _, Red.Step.not => by rw [← List.append_assoc, ← List.append_assoc]; constructor @[to_additive] theorem Step.cons {x} (H : Red.Step L₁ L₂) : Red.Step (x :: L₁) (x :: L₂) := @Step.append_left _ [x] _ _ H @[to_additive] theorem Step.append_right : ∀ {L₁ L₂ L₃ : List (α × Bool)}, Step L₁ L₂ → Step (L₁ ++ L₃) (L₂ ++ L₃) | _, _, _, Red.Step.not => by simp @[to_additive] theorem not_step_nil : ¬Step [] L := by generalize h' : [] = L' intro h cases' h with L₁ L₂ simp [List.nil_eq_append] at h' @[to_additive] theorem Step.cons_left_iff {a : α} {b : Bool} : Step ((a, b) :: L₁) L₂ ↔ (∃ L, Step L₁ L ∧ L₂ = (a, b) :: L) ∨ L₁ = (a, ! b) :: L₂ := by constructor · generalize hL : ((a, b) :: L₁ : List _) = L rintro @⟨_ | ⟨p, s'⟩, e, a', b'⟩ · simp at hL simp [*] · simp at hL rcases hL with ⟨rfl, rfl⟩ refine Or.inl ⟨s' ++ e, Step.not, ?_⟩ simp · rintro (⟨L, h, rfl⟩ | rfl) · exact Step.cons h · exact Step.cons_not @[to_additive] theorem not_step_singleton : ∀ {p : α × Bool}, ¬Step [p] L | (a, b) => by simp [Step.cons_left_iff, not_step_nil] @[to_additive] theorem Step.cons_cons_iff : ∀ {p : α × Bool}, Step (p :: L₁) (p :: L₂) ↔ Step L₁ L₂ := by simp (config := { contextual := true }) [Step.cons_left_iff, iff_def, or_imp] @[to_additive] theorem Step.append_left_iff : ∀ L, Step (L ++ L₁) (L ++ L₂) ↔ Step L₁ L₂ | [] => by simp | p :: l => by simp [Step.append_left_iff l, Step.cons_cons_iff] @[to_additive] theorem Step.diamond_aux : ∀ {L₁ L₂ L₃ L₄ : List (α × Bool)} {x1 b1 x2 b2}, L₁ ++ (x1, b1) :: (x1, !b1) :: L₂ = L₃ ++ (x2, b2) :: (x2, !b2) :: L₄ → L₁ ++ L₂ = L₃ ++ L₄ ∨ ∃ L₅, Red.Step (L₁ ++ L₂) L₅ ∧ Red.Step (L₃ ++ L₄) L₅ | [], _, [], _, _, _, _, _, H => by injections; subst_vars; simp | [], _, [(x3, b3)], _, _, _, _, _, H => by injections; subst_vars; simp | [(x3, b3)], _, [], _, _, _, _, _, H => by injections; subst_vars; simp | [], _, (x3, b3) :: (x4, b4) :: tl, _, _, _, _, _, H => by injections; subst_vars; right; exact ⟨_, Red.Step.not, Red.Step.cons_not⟩ | (x3, b3) :: (x4, b4) :: tl, _, [], _, _, _, _, _, H => by injections; subst_vars; right; simpa using ⟨_, Red.Step.cons_not, Red.Step.not⟩ | (x3, b3) :: tl, _, (x4, b4) :: tl2, _, _, _, _, _, H => let ⟨H1, H2⟩ := List.cons.inj H match Step.diamond_aux H2 with | Or.inl H3 => Or.inl <| by simp [H1, H3] | Or.inr ⟨L₅, H3, H4⟩ => Or.inr ⟨_, Step.cons H3, by simpa [H1] using Step.cons H4⟩ @[to_additive] theorem Step.diamond : ∀ {L₁ L₂ L₃ L₄ : List (α × Bool)}, Red.Step L₁ L₃ → Red.Step L₂ L₄ → L₁ = L₂ → L₃ = L₄ ∨ ∃ L₅, Red.Step L₃ L₅ ∧ Red.Step L₄ L₅ | _, _, _, _, Red.Step.not, Red.Step.not, H => Step.diamond_aux H @[to_additive] theorem Step.to_red : Step L₁ L₂ → Red L₁ L₂ := ReflTransGen.single /-- **Church-Rosser theorem** for word reduction: If `w1 w2 w3` are words such that `w1` reduces to `w2` and `w3` respectively, then there is a word `w4` such that `w2` and `w3` reduce to `w4` respectively. This is also known as Newman's diamond lemma. -/ @[to_additive "**Church-Rosser theorem** for word reduction: If `w1 w2 w3` are words such that `w1` reduces to `w2` and `w3` respectively, then there is a word `w4` such that `w2` and `w3` reduce to `w4` respectively. This is also known as Newman's diamond lemma."] theorem church_rosser : Red L₁ L₂ → Red L₁ L₃ → Join Red L₂ L₃ := Relation.church_rosser fun a b c hab hac => match b, c, Red.Step.diamond hab hac rfl with | b, _, Or.inl rfl => ⟨b, by rfl, by rfl⟩ | b, c, Or.inr ⟨d, hbd, hcd⟩ => ⟨d, ReflGen.single hbd, hcd.to_red⟩ @[to_additive] theorem cons_cons {p} : Red L₁ L₂ → Red (p :: L₁) (p :: L₂) := ReflTransGen.lift (List.cons p) fun _ _ => Step.cons @[to_additive] theorem cons_cons_iff (p) : Red (p :: L₁) (p :: L₂) ↔ Red L₁ L₂ := Iff.intro (by generalize eq₁ : (p :: L₁ : List _) = LL₁ generalize eq₂ : (p :: L₂ : List _) = LL₂ intro h induction' h using Relation.ReflTransGen.head_induction_on with L₁ L₂ h₁₂ h ih generalizing L₁ L₂ · subst_vars cases eq₂ constructor · subst_vars cases' p with a b rw [Step.cons_left_iff] at h₁₂ rcases h₁₂ with (⟨L, h₁₂, rfl⟩ | rfl) · exact (ih rfl rfl).head h₁₂ · exact (cons_cons h).tail Step.cons_not_rev) cons_cons @[to_additive] theorem append_append_left_iff : ∀ L, Red (L ++ L₁) (L ++ L₂) ↔ Red L₁ L₂ | [] => Iff.rfl | p :: L => by simp [append_append_left_iff L, cons_cons_iff] @[to_additive] theorem append_append (h₁ : Red L₁ L₃) (h₂ : Red L₂ L₄) : Red (L₁ ++ L₂) (L₃ ++ L₄) := (h₁.lift (fun L => L ++ L₂) fun _ _ => Step.append_right).trans ((append_append_left_iff _).2 h₂) @[to_additive] theorem to_append_iff : Red L (L₁ ++ L₂) ↔ ∃ L₃ L₄, L = L₃ ++ L₄ ∧ Red L₃ L₁ ∧ Red L₄ L₂ := Iff.intro (by generalize eq : L₁ ++ L₂ = L₁₂ intro h induction' h with L' L₁₂ hLL' h ih generalizing L₁ L₂ · exact ⟨_, _, eq.symm, by rfl, by rfl⟩ · cases' h with s e a b rcases List.append_eq_append_iff.1 eq with (⟨s', rfl, rfl⟩ | ⟨e', rfl, rfl⟩) · have : L₁ ++ (s' ++ (a, b) :: (a, not b) :: e) = L₁ ++ s' ++ (a, b) :: (a, not b) :: e := by simp rcases ih this with ⟨w₁, w₂, rfl, h₁, h₂⟩ exact ⟨w₁, w₂, rfl, h₁, h₂.tail Step.not⟩ · have : s ++ (a, b) :: (a, not b) :: e' ++ L₂ = s ++ (a, b) :: (a, not b) :: (e' ++ L₂) := by simp rcases ih this with ⟨w₁, w₂, rfl, h₁, h₂⟩ exact ⟨w₁, w₂, rfl, h₁.tail Step.not, h₂⟩) fun ⟨L₃, L₄, Eq, h₃, h₄⟩ => Eq.symm ▸ append_append h₃ h₄ /-- The empty word `[]` only reduces to itself. -/ @[to_additive "The empty word `[]` only reduces to itself."] theorem nil_iff : Red [] L ↔ L = [] := reflTransGen_iff_eq fun _ => Red.not_step_nil /-- A letter only reduces to itself. -/ @[to_additive "A letter only reduces to itself."] theorem singleton_iff {x} : Red [x] L₁ ↔ L₁ = [x] := reflTransGen_iff_eq fun _ => not_step_singleton /-- If `x` is a letter and `w` is a word such that `xw` reduces to the empty word, then `w` reduces to `x⁻¹` -/ @[to_additive "If `x` is a letter and `w` is a word such that `x + w` reduces to the empty word, then `w` reduces to `-x`."] theorem cons_nil_iff_singleton {x b} : Red ((x, b) :: L) [] ↔ Red L [(x, not b)] := Iff.intro (fun h => by have h₁ : Red ((x, not b) :: (x, b) :: L) [(x, not b)] := cons_cons h have h₂ : Red ((x, not b) :: (x, b) :: L) L := ReflTransGen.single Step.cons_not_rev let ⟨L', h₁, h₂⟩ := church_rosser h₁ h₂ rw [singleton_iff] at h₁ subst L' assumption) fun h => (cons_cons h).tail Step.cons_not @[to_additive] theorem red_iff_irreducible {x1 b1 x2 b2} (h : (x1, b1) ≠ (x2, b2)) : Red [(x1, !b1), (x2, b2)] L ↔ L = [(x1, !b1), (x2, b2)] := by apply reflTransGen_iff_eq generalize eq : [(x1, not b1), (x2, b2)] = L' intro L h' cases h' simp [List.cons_eq_append, List.nil_eq_append] at eq rcases eq with ⟨rfl, ⟨rfl, rfl⟩, ⟨rfl, rfl⟩, rfl⟩ simp at h /-- If `x` and `y` are distinct letters and `w₁ w₂` are words such that `xw₁` reduces to `yw₂`, then `w₁` reduces to `x⁻¹yw₂`. -/ @[to_additive "If `x` and `y` are distinct letters and `w₁ w₂` are words such that `x + w₁` reduces to `y + w₂`, then `w₁` reduces to `-x + y + w₂`."] theorem inv_of_red_of_ne {x1 b1 x2 b2} (H1 : (x1, b1) ≠ (x2, b2)) (H2 : Red ((x1, b1) :: L₁) ((x2, b2) :: L₂)) : Red L₁ ((x1, not b1) :: (x2, b2) :: L₂) := by have : Red ((x1, b1) :: L₁) ([(x2, b2)] ++ L₂) := H2 rcases to_append_iff.1 this with ⟨_ | ⟨p, L₃⟩, L₄, eq, h₁, h₂⟩ · simp [nil_iff] at h₁ · cases eq show Red (L₃ ++ L₄) ([(x1, not b1), (x2, b2)] ++ L₂) apply append_append _ h₂ have h₁ : Red ((x1, not b1) :: (x1, b1) :: L₃) [(x1, not b1), (x2, b2)] := cons_cons h₁ have h₂ : Red ((x1, not b1) :: (x1, b1) :: L₃) L₃ := Step.cons_not_rev.to_red rcases church_rosser h₁ h₂ with ⟨L', h₁, h₂⟩ rw [red_iff_irreducible H1] at h₁ rwa [h₁] at h₂ open List -- for <+ notation @[to_additive] theorem Step.sublist (H : Red.Step L₁ L₂) : Sublist L₂ L₁ := by cases H; simp; constructor; constructor; rfl /-- If `w₁ w₂` are words such that `w₁` reduces to `w₂`, then `w₂` is a sublist of `w₁`. -/ @[to_additive "If `w₁ w₂` are words such that `w₁` reduces to `w₂`, then `w₂` is a sublist of `w₁`."] protected theorem sublist : Red L₁ L₂ → L₂ <+ L₁ := @reflTransGen_of_transitive_reflexive _ (fun a b => b <+ a) _ _ _ (fun l => List.Sublist.refl l) (fun _a _b _c hab hbc => List.Sublist.trans hbc hab) (fun _ _ => Red.Step.sublist) @[to_additive] theorem length_le (h : Red L₁ L₂) : L₂.length ≤ L₁.length := h.sublist.length_le @[to_additive] theorem sizeof_of_step : ∀ {L₁ L₂ : List (α × Bool)}, Step L₁ L₂ → sizeOf L₂ < sizeOf L₁ | _, _, @Step.not _ L1 L2 x b => by induction L1 with | nil => -- dsimp [sizeOf] dsimp simp only [Bool.sizeOf_eq_one] have H : 1 + (1 + 1) + (1 + (1 + 1) + sizeOf L2) = sizeOf L2 + (1 + ((1 + 1) + (1 + 1) + 1)) := by ac_rfl rw [H] apply Nat.lt_add_of_pos_right apply Nat.lt_add_right apply Nat.zero_lt_one | cons hd tl ih => dsimp exact Nat.add_lt_add_left ih _ @[to_additive] theorem length (h : Red L₁ L₂) : ∃ n, L₁.length = L₂.length + 2 * n := by induction' h with L₂ L₃ _h₁₂ h₂₃ ih · exact ⟨0, rfl⟩ · rcases ih with ⟨n, eq⟩ exists 1 + n simp [Nat.mul_add, eq, (Step.length h₂₃).symm, add_assoc] @[to_additive] theorem antisymm (h₁₂ : Red L₁ L₂) (h₂₁ : Red L₂ L₁) : L₁ = L₂ := h₂₁.sublist.antisymm h₁₂.sublist end Red @[to_additive FreeAddGroup.equivalence_join_red] theorem equivalence_join_red : Equivalence (Join (@Red α)) := equivalence_join_reflTransGen fun a b c hab hac => match b, c, Red.Step.diamond hab hac rfl with | b, _, Or.inl rfl => ⟨b, by rfl, by rfl⟩ | b, c, Or.inr ⟨d, hbd, hcd⟩ => ⟨d, ReflGen.single hbd, ReflTransGen.single hcd⟩ @[to_additive FreeAddGroup.join_red_of_step] theorem join_red_of_step (h : Red.Step L₁ L₂) : Join Red L₁ L₂ := join_of_single reflexive_reflTransGen h.to_red @[to_additive FreeAddGroup.eqvGen_step_iff_join_red] theorem eqvGen_step_iff_join_red : EqvGen Red.Step L₁ L₂ ↔ Join Red L₁ L₂ := Iff.intro (fun h => have : EqvGen (Join Red) L₁ L₂ := h.mono fun _ _ => join_red_of_step equivalence_join_red.eqvGen_iff.1 this) (join_of_equivalence (EqvGen.is_equivalence _) fun _ _ => reflTransGen_of_equivalence (EqvGen.is_equivalence _) EqvGen.rel) end FreeGroup /-- The free group over a type, i.e. the words formed by the elements of the type and their formal inverses, quotient by one step reduction. -/ @[to_additive "The free additive group over a type, i.e. the words formed by the elements of the type and their formal inverses, quotient by one step reduction."] def FreeGroup (α : Type u) : Type u := Quot <| @FreeGroup.Red.Step α namespace FreeGroup variable {L L₁ L₂ L₃ L₄ : List (α × Bool)} /-- The canonical map from `List (α × Bool)` to the free group on `α`. -/ @[to_additive "The canonical map from `list (α × bool)` to the free additive group on `α`."] def mk (L : List (α × Bool)) : FreeGroup α := Quot.mk Red.Step L @[to_additive (attr := simp)] theorem quot_mk_eq_mk : Quot.mk Red.Step L = mk L := rfl @[to_additive (attr := simp)] theorem quot_lift_mk (β : Type v) (f : List (α × Bool) → β) (H : ∀ L₁ L₂, Red.Step L₁ L₂ → f L₁ = f L₂) : Quot.lift f H (mk L) = f L := rfl @[to_additive (attr := simp)] theorem quot_liftOn_mk (β : Type v) (f : List (α × Bool) → β) (H : ∀ L₁ L₂, Red.Step L₁ L₂ → f L₁ = f L₂) : Quot.liftOn (mk L) f H = f L := rfl @[to_additive (attr := simp)] theorem quot_map_mk (β : Type v) (f : List (α × Bool) → List (β × Bool)) (H : (Red.Step ⇒ Red.Step) f f) : Quot.map f H (mk L) = mk (f L) := rfl @[to_additive] instance : One (FreeGroup α) := ⟨mk []⟩ @[to_additive] theorem one_eq_mk : (1 : FreeGroup α) = mk [] := rfl @[to_additive] instance : Inhabited (FreeGroup α) := ⟨1⟩ @[to_additive] instance [IsEmpty α] : Unique (FreeGroup α) := by unfold FreeGroup; infer_instance @[to_additive] instance : Mul (FreeGroup α) := ⟨fun x y => Quot.liftOn x (fun L₁ => Quot.liftOn y (fun L₂ => mk <| L₁ ++ L₂) fun _L₂ _L₃ H => Quot.sound <| Red.Step.append_left H) fun _L₁ _L₂ H => Quot.inductionOn y fun _L₃ => Quot.sound <| Red.Step.append_right H⟩ @[to_additive (attr := simp)] theorem mul_mk : mk L₁ * mk L₂ = mk (L₁ ++ L₂) := rfl /-- Transform a word representing a free group element into a word representing its inverse. -/ @[to_additive "Transform a word representing a free group element into a word representing its negative."] def invRev (w : List (α × Bool)) : List (α × Bool) := (List.map (fun g : α × Bool => (g.1, not g.2)) w).reverse @[to_additive (attr := simp)] theorem invRev_length : (invRev L₁).length = L₁.length := by simp [invRev] @[to_additive (attr := simp)] theorem invRev_invRev : invRev (invRev L₁) = L₁ := by simp [invRev, List.map_reverse, (· ∘ ·)] @[to_additive (attr := simp)] theorem invRev_empty : invRev ([] : List (α × Bool)) = [] := rfl @[to_additive] theorem invRev_involutive : Function.Involutive (@invRev α) := fun _ => invRev_invRev @[to_additive] theorem invRev_injective : Function.Injective (@invRev α) := invRev_involutive.injective @[to_additive] theorem invRev_surjective : Function.Surjective (@invRev α) := invRev_involutive.surjective @[to_additive] theorem invRev_bijective : Function.Bijective (@invRev α) := invRev_involutive.bijective @[to_additive] instance : Inv (FreeGroup α) := ⟨Quot.map invRev (by intro a b h cases h simp [invRev])⟩ @[to_additive (attr := simp)] theorem inv_mk : (mk L)⁻¹ = mk (invRev L) := rfl @[to_additive] theorem Red.Step.invRev {L₁ L₂ : List (α × Bool)} (h : Red.Step L₁ L₂) : Red.Step (FreeGroup.invRev L₁) (FreeGroup.invRev L₂) := by cases' h with a b x y simp [FreeGroup.invRev] @[to_additive] theorem Red.invRev {L₁ L₂ : List (α × Bool)} (h : Red L₁ L₂) : Red (invRev L₁) (invRev L₂) := Relation.ReflTransGen.lift _ (fun _a _b => Red.Step.invRev) h @[to_additive (attr := simp)] theorem Red.step_invRev_iff : Red.Step (FreeGroup.invRev L₁) (FreeGroup.invRev L₂) ↔ Red.Step L₁ L₂ := ⟨fun h => by simpa only [invRev_invRev] using h.invRev, fun h => h.invRev⟩ @[to_additive (attr := simp)] theorem red_invRev_iff : Red (invRev L₁) (invRev L₂) ↔ Red L₁ L₂ := ⟨fun h => by simpa only [invRev_invRev] using h.invRev, fun h => h.invRev⟩ @[to_additive] instance : Group (FreeGroup α) where mul := (· * ·) one := 1 inv := Inv.inv mul_assoc := by rintro ⟨L₁⟩ ⟨L₂⟩ ⟨L₃⟩; simp one_mul := by rintro ⟨L⟩; rfl mul_one := by rintro ⟨L⟩; simp [one_eq_mk] mul_left_inv := by rintro ⟨L⟩ exact List.recOn L rfl fun ⟨x, b⟩ tl ih => Eq.trans (Quot.sound <| by simp [invRev, one_eq_mk]) ih /-- `of` is the canonical injection from the type to the free group over that type by sending each element to the equivalence class of the letter that is the element. -/ @[to_additive "`of` is the canonical injection from the type to the free group over that type by sending each element to the equivalence class of the letter that is the element."] def of (x : α) : FreeGroup α := mk [(x, true)] @[to_additive] theorem Red.exact : mk L₁ = mk L₂ ↔ Join Red L₁ L₂ := calc mk L₁ = mk L₂ ↔ EqvGen Red.Step L₁ L₂ := Iff.intro (Quot.exact _) Quot.EqvGen_sound _ ↔ Join Red L₁ L₂ := eqvGen_step_iff_join_red /-- The canonical map from the type to the free group is an injection. -/ @[to_additive "The canonical map from the type to the additive free group is an injection."] theorem of_injective : Function.Injective (@of α) := fun _ _ H => by let ⟨L₁, hx, hy⟩ := Red.exact.1 H simp [Red.singleton_iff] at hx hy; aesop section lift variable {β : Type v} [Group β] (f : α → β) {x y : FreeGroup α} /-- Given `f : α → β` with `β` a group, the canonical map `List (α × Bool) → β` -/ @[to_additive "Given `f : α → β` with `β` an additive group, the canonical map `list (α × bool) → β`"] def Lift.aux : List (α × Bool) → β := fun L => List.prod <| L.map fun x => cond x.2 (f x.1) (f x.1)⁻¹ @[to_additive] theorem Red.Step.lift {f : α → β} (H : Red.Step L₁ L₂) : Lift.aux f L₁ = Lift.aux f L₂ := by cases' H with _ _ _ b; cases b <;> simp [Lift.aux] /-- If `β` is a group, then any function from `α` to `β` extends uniquely to a group homomorphism from the free group over `α` to `β` -/ @[to_additive (attr := simps symm_apply) "If `β` is an additive group, then any function from `α` to `β` extends uniquely to an additive group homomorphism from the free additive group over `α` to `β`"] def lift : (α → β) ≃ (FreeGroup α →* β) where toFun f := MonoidHom.mk' (Quot.lift (Lift.aux f) fun L₁ L₂ => Red.Step.lift) <| by rintro ⟨L₁⟩ ⟨L₂⟩; simp [Lift.aux] invFun g := g ∘ of left_inv f := one_mul _ right_inv g := MonoidHom.ext <| by rintro ⟨L⟩ exact List.recOn L (g.map_one.symm) (by rintro ⟨x, _ | _⟩ t (ih : _ = g (mk t)) · show _ = g ((of x)⁻¹ * mk t) simpa [Lift.aux] using ih · show _ = g (of x * mk t) simpa [Lift.aux] using ih) variable {f} @[to_additive (attr := simp)] theorem lift.mk : lift f (mk L) = List.prod (L.map fun x => cond x.2 (f x.1) (f x.1)⁻¹) := rfl @[to_additive (attr := simp)] theorem lift.of {x} : lift f (of x) = f x := one_mul _ @[to_additive] theorem lift.unique (g : FreeGroup α →* β) (hg : ∀ x, g (FreeGroup.of x) = f x) {x} : g x = FreeGroup.lift f x := DFunLike.congr_fun (lift.symm_apply_eq.mp (funext hg : g ∘ FreeGroup.of = f)) x /-- Two homomorphisms out of a free group are equal if they are equal on generators. See note [partially-applied ext lemmas]. -/ @[to_additive (attr := ext) "Two homomorphisms out of a free additive group are equal if they are equal on generators. See note [partially-applied ext lemmas]."] theorem ext_hom {G : Type*} [Group G] (f g : FreeGroup α →* G) (h : ∀ a, f (of a) = g (of a)) : f = g := lift.symm.injective <| funext h @[to_additive] theorem lift_of_eq_id (α) : lift of = MonoidHom.id (FreeGroup α) := lift.apply_symm_apply (MonoidHom.id _) @[to_additive] theorem lift.of_eq (x : FreeGroup α) : lift FreeGroup.of x = x := DFunLike.congr_fun (lift_of_eq_id α) x @[to_additive] theorem lift.range_le {s : Subgroup β} (H : Set.range f ⊆ s) : (lift f).range ≤ s := by rintro _ ⟨⟨L⟩, rfl⟩; exact List.recOn L s.one_mem fun ⟨x, b⟩ tl ih ↦ Bool.recOn b (by simpa using s.mul_mem (s.inv_mem <| H ⟨x, rfl⟩) ih) (by simpa using s.mul_mem (H ⟨x, rfl⟩) ih) @[to_additive] theorem lift.range_eq_closure : (lift f).range = Subgroup.closure (Set.range f) := by apply le_antisymm (lift.range_le Subgroup.subset_closure) rw [Subgroup.closure_le] rintro _ ⟨a, rfl⟩ exact ⟨FreeGroup.of a, by simp only [lift.of]⟩ /-- The generators of `FreeGroup α` generate `FreeGroup α`. That is, the subgroup closure of the set of generators equals `⊤`. -/ @[to_additive (attr := simp)] theorem closure_range_of (α) : Subgroup.closure (Set.range (FreeGroup.of : α → FreeGroup α)) = ⊤ := by rw [← lift.range_eq_closure, lift_of_eq_id] exact MonoidHom.range_top_of_surjective _ Function.surjective_id end lift section Map variable {β : Type v} (f : α → β) {x y : FreeGroup α} /-- Any function from `α` to `β` extends uniquely to a group homomorphism from the free group over `α` to the free group over `β`. -/ @[to_additive "Any function from `α` to `β` extends uniquely to an additive group homomorphism from the additive free group over `α` to the additive free group over `β`."] def map : FreeGroup α →* FreeGroup β := MonoidHom.mk' (Quot.map (List.map fun x => (f x.1, x.2)) fun L₁ L₂ H => by cases H; simp) (by rintro ⟨L₁⟩ ⟨L₂⟩; simp) variable {f} @[to_additive (attr := simp)] theorem map.mk : map f (mk L) = mk (L.map fun x => (f x.1, x.2)) := rfl @[to_additive (attr := simp)] theorem map.id (x : FreeGroup α) : map id x = x := by rcases x with ⟨L⟩; simp [List.map_id'] @[to_additive (attr := simp)] theorem map.id' (x : FreeGroup α) : map (fun z => z) x = x := map.id x @[to_additive] theorem map.comp {γ : Type w} (f : α → β) (g : β → γ) (x) : map g (map f x) = map (g ∘ f) x := by rcases x with ⟨L⟩; simp [(· ∘ ·)] @[to_additive (attr := simp)] theorem map.of {x} : map f (of x) = of (f x) := rfl @[to_additive] theorem map.unique (g : FreeGroup α →* FreeGroup β) (hg : ∀ x, g (FreeGroup.of x) = FreeGroup.of (f x)) : ∀ {x}, g x = map f x := by rintro ⟨L⟩ exact List.recOn L g.map_one fun ⟨x, b⟩ t (ih : g (FreeGroup.mk t) = map f (FreeGroup.mk t)) => Bool.recOn b (show g ((FreeGroup.of x)⁻¹ * FreeGroup.mk t) = FreeGroup.map f ((FreeGroup.of x)⁻¹ * FreeGroup.mk t) by simp [g.map_mul, g.map_inv, hg, ih]) (show g (FreeGroup.of x * FreeGroup.mk t) = FreeGroup.map f (FreeGroup.of x * FreeGroup.mk t) by simp [g.map_mul, hg, ih]) @[to_additive] theorem map_eq_lift : map f x = lift (of ∘ f) x := Eq.symm <| map.unique _ fun x => by simp /-- Equivalent types give rise to multiplicatively equivalent free groups. The converse can be found in `GroupTheory.FreeAbelianGroupFinsupp`, as `Equiv.of_freeGroupEquiv` -/ @[to_additive (attr := simps apply) "Equivalent types give rise to additively equivalent additive free groups."] def freeGroupCongr {α β} (e : α ≃ β) : FreeGroup α ≃* FreeGroup β where toFun := map e invFun := map e.symm left_inv x := by simp [Function.comp, map.comp] right_inv x := by simp [Function.comp, map.comp] map_mul' := MonoidHom.map_mul _ @[to_additive (attr := simp)] theorem freeGroupCongr_refl : freeGroupCongr (Equiv.refl α) = MulEquiv.refl _ := MulEquiv.ext map.id @[to_additive (attr := simp)] theorem freeGroupCongr_symm {α β} (e : α ≃ β) : (freeGroupCongr e).symm = freeGroupCongr e.symm := rfl @[to_additive] theorem freeGroupCongr_trans {α β γ} (e : α ≃ β) (f : β ≃ γ) : (freeGroupCongr e).trans (freeGroupCongr f) = freeGroupCongr (e.trans f) := MulEquiv.ext <| map.comp _ _ end Map section Prod variable [Group α] (x y : FreeGroup α) /-- If `α` is a group, then any function from `α` to `α` extends uniquely to a homomorphism from the free group over `α` to `α`. This is the multiplicative version of `FreeGroup.sum`. -/ @[to_additive "If `α` is an additive group, then any function from `α` to `α` extends uniquely to an additive homomorphism from the additive free group over `α` to `α`."] def prod : FreeGroup α →* α := lift id variable {x y} @[to_additive (attr := simp)] theorem prod_mk : prod (mk L) = List.prod (L.map fun x => cond x.2 x.1 x.1⁻¹) := rfl @[to_additive (attr := simp)] theorem prod.of {x : α} : prod (of x) = x := lift.of @[to_additive] theorem prod.unique (g : FreeGroup α →* α) (hg : ∀ x, g (FreeGroup.of x) = x) {x} : g x = prod x := lift.unique g hg end Prod @[to_additive] theorem lift_eq_prod_map {β : Type v} [Group β] {f : α → β} {x} : lift f x = prod (map f x) := by rw [← lift.unique (prod.comp (map f))] · rfl · simp section Sum variable [AddGroup α] (x y : FreeGroup α) /-- If `α` is a group, then any function from `α` to `α` extends uniquely to a homomorphism from the free group over `α` to `α`. This is the additive version of `Prod`. -/ def sum : α := @prod (Multiplicative _) _ x variable {x y} @[simp] theorem sum_mk : sum (mk L) = List.sum (L.map fun x => cond x.2 x.1 (-x.1)) := rfl @[simp] theorem sum.of {x : α} : sum (of x) = x := @prod.of _ (_) _ -- note: there are no bundled homs with different notation in the domain and codomain, so we copy -- these manually @[simp] theorem sum.map_mul : sum (x * y) = sum x + sum y := (@prod (Multiplicative _) _).map_mul _ _ @[simp] theorem sum.map_one : sum (1 : FreeGroup α) = 0 := (@prod (Multiplicative _) _).map_one @[simp] theorem sum.map_inv : sum x⁻¹ = -sum x := (prod : FreeGroup (Multiplicative α) →* Multiplicative α).map_inv _ end Sum /-- The bijection between the free group on the empty type, and a type with one element. -/ @[to_additive "The bijection between the additive free group on the empty type, and a type with one element."] def freeGroupEmptyEquivUnit : FreeGroup Empty ≃ Unit where toFun _ := () invFun _ := 1 left_inv := by rintro ⟨_ | ⟨⟨⟨⟩, _⟩, _⟩⟩; rfl right_inv := fun ⟨⟩ => rfl /-- The bijection between the free group on a singleton, and the integers. -/ def freeGroupUnitEquivInt : FreeGroup Unit ≃ ℤ where toFun x := sum (by revert x change (FreeGroup Unit →* FreeGroup ℤ) apply map fun _ => (1 : ℤ)) invFun x := of () ^ x left_inv := by rintro ⟨L⟩ simp only [quot_mk_eq_mk, map.mk, sum_mk, List.map_map] exact List.recOn L (by rfl) (fun ⟨⟨⟩, b⟩ tl ih => by cases b <;> simp [zpow_add] at ih ⊢ <;> rw [ih] <;> rfl) right_inv x := Int.induction_on x (by simp) (fun i ih => by simp only [zpow_natCast, map_pow, map.of] at ih simp [zpow_add, ih]) (fun i ih => by simp only [zpow_neg, zpow_natCast, map_inv, map_pow, map.of, sum.map_inv, neg_inj] at ih simp [zpow_add, ih, sub_eq_add_neg]) section Category variable {β : Type u} @[to_additive] instance : Monad FreeGroup.{u} where pure {_α} := of map {_α} {_β} {f} := map f bind {_α} {_β} {x} {f} := lift f x @[to_additive (attr := elab_as_elim, induction_eliminator)] protected theorem induction_on {C : FreeGroup α → Prop} (z : FreeGroup α) (C1 : C 1) (Cp : ∀ x, C <| pure x) (Ci : ∀ x, C (pure x) → C (pure x)⁻¹) (Cm : ∀ x y, C x → C y → C (x * y)) : C z := Quot.inductionOn z fun L => List.recOn L C1 fun ⟨x, b⟩ _tl ih => Bool.recOn b (Cm _ _ (Ci _ <| Cp x) ih) (Cm _ _ (Cp x) ih) -- porting note (#10618): simp can prove this: by simp only [@map_pure] @[to_additive] theorem map_pure (f : α → β) (x : α) : f <$> (pure x : FreeGroup α) = pure (f x) := map.of @[to_additive (attr := simp)] theorem map_one (f : α → β) : f <$> (1 : FreeGroup α) = 1 := (map f).map_one @[to_additive (attr := simp)] theorem map_mul (f : α → β) (x y : FreeGroup α) : f <$> (x * y) = f <$> x * f <$> y := (map f).map_mul x y @[to_additive (attr := simp)] theorem map_inv (f : α → β) (x : FreeGroup α) : f <$> x⁻¹ = (f <$> x)⁻¹ := (map f).map_inv x -- porting note (#10618): simp can prove this: by simp only [@pure_bind] @[to_additive] theorem pure_bind (f : α → FreeGroup β) (x) : pure x >>= f = f x := lift.of @[to_additive (attr := simp)] theorem one_bind (f : α → FreeGroup β) : 1 >>= f = 1 := (lift f).map_one @[to_additive (attr := simp)] theorem mul_bind (f : α → FreeGroup β) (x y : FreeGroup α) : x * y >>= f = (x >>= f) * (y >>= f) := (lift f).map_mul _ _ @[to_additive (attr := simp)] theorem inv_bind (f : α → FreeGroup β) (x : FreeGroup α) : x⁻¹ >>= f = (x >>= f)⁻¹ := (lift f).map_inv _ @[to_additive] instance : LawfulMonad FreeGroup.{u} := LawfulMonad.mk' (id_map := fun x => FreeGroup.induction_on x (map_one id) (fun x => map_pure id x) (fun x ih => by rw [map_inv, ih]) fun x y ihx ihy => by rw [map_mul, ihx, ihy]) (pure_bind := fun x f => pure_bind f x) (bind_assoc := fun x => FreeGroup.induction_on x (by intros; iterate 3 rw [one_bind]) (fun x => by intros; iterate 2 rw [pure_bind]) (fun x ih => by intros; (iterate 3 rw [inv_bind]); rw [ih]) (fun x y ihx ihy => by intros; (iterate 3 rw [mul_bind]); rw [ihx, ihy])) (bind_pure_comp := fun f x => FreeGroup.induction_on x (by rw [one_bind, map_one]) (fun x => by rw [pure_bind, map_pure]) (fun x ih => by rw [inv_bind, map_inv, ih]) fun x y ihx ihy => by rw [mul_bind, map_mul, ihx, ihy]) end Category section Reduce variable [DecidableEq α] /-- The maximal reduction of a word. It is computable iff `α` has decidable equality. -/ @[to_additive "The maximal reduction of a word. It is computable iff `α` has decidable equality."] def reduce : (L : List (α × Bool)) -> List (α × Bool) := List.rec [] fun hd1 _tl1 ih => List.casesOn ih [hd1] fun hd2 tl2 => if hd1.1 = hd2.1 ∧ hd1.2 = not hd2.2 then tl2 else hd1 :: hd2 :: tl2 @[to_additive (attr := simp)] theorem reduce.cons (x) : reduce (x :: L) = List.casesOn (reduce L) [x] fun hd tl => if x.1 = hd.1 ∧ x.2 = not hd.2 then tl else x :: hd :: tl := rfl /-- The first theorem that characterises the function `reduce`: a word reduces to its maximal reduction. -/ @[to_additive "The first theorem that characterises the function `reduce`: a word reduces to its maximal reduction."] theorem reduce.red : Red L (reduce L) := by induction L with | nil => constructor | cons hd1 tl1 ih => dsimp revert ih generalize htl : reduce tl1 = TL intro ih cases TL with | nil => exact Red.cons_cons ih | cons hd2 tl2 => dsimp only split_ifs with h · cases hd1 cases hd2 cases h dsimp at * subst_vars apply Red.trans (Red.cons_cons ih) exact Red.Step.cons_not_rev.to_red · exact Red.cons_cons ih @[to_additive] theorem reduce.not {p : Prop} : ∀ {L₁ L₂ L₃ : List (α × Bool)} {x b}, reduce L₁ = L₂ ++ (x, b) :: (x, !b) :: L₃ → p | [], L2, L3, _, _ => fun h => by cases L2 <;> injections | (x, b) :: L1, L2, L3, x', b' => by dsimp cases r : reduce L1 with | nil => dsimp; intro h exfalso have := congr_arg List.length h simp? [List.length] at this says simp only [List.length, zero_add, List.length_append] at this rw [add_comm, add_assoc, add_assoc, add_comm, <-add_assoc] at this omega | cons hd tail => cases' hd with y c dsimp only split_ifs with h <;> intro H · rw [H] at r exact @reduce.not _ L1 ((y, c) :: L2) L3 x' b' r rcases L2 with (_ | ⟨a, L2⟩) · injections; subst_vars simp at h · refine @reduce.not _ L1 L2 L3 x' b' ?_ injection H with _ H rw [r, H]; rfl /-- The second theorem that characterises the function `reduce`: the maximal reduction of a word only reduces to itself. -/ @[to_additive "The second theorem that characterises the function `reduce`: the maximal reduction of a word only reduces to itself."] theorem reduce.min (H : Red (reduce L₁) L₂) : reduce L₁ = L₂ := by induction' H with L1 L' L2 H1 H2 ih · rfl · cases' H1 with L4 L5 x b exact reduce.not H2 /-- `reduce` is idempotent, i.e. the maximal reduction of the maximal reduction of a word is the maximal reduction of the word. -/ @[to_additive (attr := simp) "`reduce` is idempotent, i.e. the maximal reduction of the maximal reduction of a word is the maximal reduction of the word."] theorem reduce.idem : reduce (reduce L) = reduce L := Eq.symm <| reduce.min reduce.red @[to_additive] theorem reduce.Step.eq (H : Red.Step L₁ L₂) : reduce L₁ = reduce L₂ := let ⟨_L₃, HR13, HR23⟩ := Red.church_rosser reduce.red (reduce.red.head H) (reduce.min HR13).trans (reduce.min HR23).symm /-- If a word reduces to another word, then they have a common maximal reduction. -/ @[to_additive "If a word reduces to another word, then they have a common maximal reduction."] theorem reduce.eq_of_red (H : Red L₁ L₂) : reduce L₁ = reduce L₂ := let ⟨_L₃, HR13, HR23⟩ := Red.church_rosser reduce.red (Red.trans H reduce.red) (reduce.min HR13).trans (reduce.min HR23).symm alias red.reduce_eq := reduce.eq_of_red alias freeAddGroup.red.reduce_eq := FreeAddGroup.reduce.eq_of_red @[to_additive] theorem Red.reduce_right (h : Red L₁ L₂) : Red L₁ (reduce L₂) := reduce.eq_of_red h ▸ reduce.red @[to_additive] theorem Red.reduce_left (h : Red L₁ L₂) : Red L₂ (reduce L₁) := (reduce.eq_of_red h).symm ▸ reduce.red /-- If two words correspond to the same element in the free group, then they have a common maximal reduction. This is the proof that the function that sends an element of the free group to its maximal reduction is well-defined. -/ @[to_additive "If two words correspond to the same element in the additive free group, then they have a common maximal reduction. This is the proof that the function that sends an element of the free group to its maximal reduction is well-defined."] theorem reduce.sound (H : mk L₁ = mk L₂) : reduce L₁ = reduce L₂ := let ⟨_L₃, H13, H23⟩ := Red.exact.1 H (reduce.eq_of_red H13).trans (reduce.eq_of_red H23).symm /-- If two words have a common maximal reduction, then they correspond to the same element in the free group. -/ @[to_additive "If two words have a common maximal reduction, then they correspond to the same element in the additive free group."] theorem reduce.exact (H : reduce L₁ = reduce L₂) : mk L₁ = mk L₂ := Red.exact.2 ⟨reduce L₂, H ▸ reduce.red, reduce.red⟩ /-- A word and its maximal reduction correspond to the same element of the free group. -/ @[to_additive "A word and its maximal reduction correspond to the same element of the additive free group."] theorem reduce.self : mk (reduce L) = mk L := reduce.exact reduce.idem /-- If words `w₁ w₂` are such that `w₁` reduces to `w₂`, then `w₂` reduces to the maximal reduction of `w₁`. -/ @[to_additive "If words `w₁ w₂` are such that `w₁` reduces to `w₂`, then `w₂` reduces to the maximal reduction of `w₁`."] theorem reduce.rev (H : Red L₁ L₂) : Red L₂ (reduce L₁) := (reduce.eq_of_red H).symm ▸ reduce.red /-- The function that sends an element of the free group to its maximal reduction. -/ @[to_additive "The function that sends an element of the additive free group to its maximal reduction."] def toWord : FreeGroup α → List (α × Bool) := Quot.lift reduce fun _L₁ _L₂ H => reduce.Step.eq H @[to_additive] theorem mk_toWord : ∀ {x : FreeGroup α}, mk (toWord x) = x := by rintro ⟨L⟩; exact reduce.self @[to_additive] theorem toWord_injective : Function.Injective (toWord : FreeGroup α → List (α × Bool)) := by rintro ⟨L₁⟩ ⟨L₂⟩; exact reduce.exact @[to_additive (attr := simp)] theorem toWord_inj {x y : FreeGroup α} : toWord x = toWord y ↔ x = y := toWord_injective.eq_iff @[to_additive (attr := simp)] theorem toWord_mk : (mk L₁).toWord = reduce L₁ := rfl @[to_additive (attr := simp)] theorem reduce_toWord : ∀ x : FreeGroup α, reduce (toWord x) = toWord x := by rintro ⟨L⟩ exact reduce.idem @[to_additive (attr := simp)] theorem toWord_one : (1 : FreeGroup α).toWord = [] := rfl @[to_additive (attr := simp)] theorem toWord_eq_nil_iff {x : FreeGroup α} : x.toWord = [] ↔ x = 1 := toWord_injective.eq_iff' toWord_one @[to_additive] theorem reduce_invRev {w : List (α × Bool)} : reduce (invRev w) = invRev (reduce w) := by apply reduce.min rw [← red_invRev_iff, invRev_invRev] apply Red.reduce_left have : Red (invRev (invRev w)) (invRev (reduce (invRev w))) := reduce.red.invRev rwa [invRev_invRev] at this @[to_additive] theorem toWord_inv {x : FreeGroup α} : x⁻¹.toWord = invRev x.toWord := by rcases x with ⟨L⟩ rw [quot_mk_eq_mk, inv_mk, toWord_mk, toWord_mk, reduce_invRev] /-- **Constructive Church-Rosser theorem** (compare `church_rosser`). -/ @[to_additive "**Constructive Church-Rosser theorem** (compare `church_rosser`)."] def reduce.churchRosser (H12 : Red L₁ L₂) (H13 : Red L₁ L₃) : { L₄ // Red L₂ L₄ ∧ Red L₃ L₄ } := ⟨reduce L₁, reduce.rev H12, reduce.rev H13⟩ @[to_additive] instance : DecidableEq (FreeGroup α) := toWord_injective.decidableEq -- TODO @[to_additive] doesn't succeed, possibly due to a bug instance Red.decidableRel : DecidableRel (@Red α) | [], [] => isTrue Red.refl | [], _hd2 :: _tl2 => isFalse fun H => List.noConfusion (Red.nil_iff.1 H) | (x, b) :: tl, [] => match Red.decidableRel tl [(x, not b)] with | isTrue H => isTrue <| Red.trans (Red.cons_cons H) <| (@Red.Step.not _ [] [] _ _).to_red | isFalse H => isFalse fun H2 => H <| Red.cons_nil_iff_singleton.1 H2 | (x1, b1) :: tl1, (x2, b2) :: tl2 => if h : (x1, b1) = (x2, b2) then match Red.decidableRel tl1 tl2 with | isTrue H => isTrue <| h ▸ Red.cons_cons H | isFalse H => isFalse fun H2 => H <| (Red.cons_cons_iff _).1 <| h.symm ▸ H2 else match Red.decidableRel tl1 ((x1, ! b1) :: (x2, b2) :: tl2) with | isTrue H => isTrue <| (Red.cons_cons H).tail Red.Step.cons_not | isFalse H => isFalse fun H2 => H <| Red.inv_of_red_of_ne h H2 /-- A list containing every word that `w₁` reduces to. -/ def Red.enum (L₁ : List (α × Bool)) : List (List (α × Bool)) := List.filter (Red L₁) (List.sublists L₁) theorem Red.enum.sound (H : L₂ ∈ List.filter (Red L₁) (List.sublists L₁)) : Red L₁ L₂ := of_decide_eq_true (@List.of_mem_filter _ _ L₂ _ H) theorem Red.enum.complete (H : Red L₁ L₂) : L₂ ∈ Red.enum L₁ := List.mem_filter_of_mem (List.mem_sublists.2 <| Red.sublist H) (decide_eq_true H) instance : Fintype { L₂ // Red L₁ L₂ } := Fintype.subtype (List.toFinset <| Red.enum L₁) fun _L₂ => ⟨fun H => Red.enum.sound <| List.mem_toFinset.1 H, fun H => List.mem_toFinset.2 <| Red.enum.complete H⟩ end Reduce section Metric variable [DecidableEq α] /-- The length of reduced words provides a norm on a free group. -/ @[to_additive "The length of reduced words provides a norm on an additive free group."] def norm (x : FreeGroup α) : ℕ := x.toWord.length @[to_additive (attr := simp)] theorem norm_inv_eq {x : FreeGroup α} : norm x⁻¹ = norm x := by simp only [norm, toWord_inv, invRev_length] @[to_additive (attr := simp)] theorem norm_eq_zero {x : FreeGroup α} : norm x = 0 ↔ x = 1 := by simp only [norm, List.length_eq_zero, toWord_eq_nil_iff] @[to_additive (attr := simp)] theorem norm_one : norm (1 : FreeGroup α) = 0 := rfl @[to_additive] theorem norm_mk_le : norm (mk L₁) ≤ L₁.length := reduce.red.length_le @[to_additive] theorem norm_mul_le (x y : FreeGroup α) : norm (x * y) ≤ norm x + norm y := calc norm (x * y) = norm (mk (x.toWord ++ y.toWord)) := by rw [← mul_mk, mk_toWord, mk_toWord] _ ≤ (x.toWord ++ y.toWord).length := norm_mk_le _ = norm x + norm y := List.length_append _ _ end Metric end FreeGroup
GroupTheory\FreeGroup\IsFreeGroup.lean
/- Copyright (c) 2021 David Wärn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Wärn, Eric Wieser, Joachim Breitner -/ import Mathlib.GroupTheory.FreeGroup.Basic /-! # Free groups structures on arbitrary types This file defines the notion of free basis of a group, which induces an isomorphism between the group and the free group generated by the basis. It also introduced a type class for groups which are free groups, i.e., for which some free basis exists. For the explicit construction of free groups, see `GroupTheory/FreeGroup`. ## Main definitions * `FreeGroupBasis ι G` : a function from `ι` to `G` such that `G` is free over its image. Equivalently, an isomorphism between `G` and `FreeGroup ι`. * `IsFreeGroup G` : a typeclass to indicate that `G` is free over some generators * `Generators G` : given a group satisfying `IsFreeGroup G`, some indexing type over which `G` is free. * `IsFreeGroup.of` : the canonical injection of `G`'s generators into `G` * `IsFreeGroup.lift` : the universal property of the free group ## Main results * `FreeGroupBasis.isFreeGroup`: a group admitting a free group basis is free. * `IsFreeGroup.toFreeGroup`: any free group with generators `A` is equivalent to `FreeGroup A`. * `IsFreeGroup.unique_lift`: the universal property of a free group. * `FreeGroupBasis.ofUniqueLift`: a group satisfying the universal property of a free group admits a free group basis. -/ universe u open Function Set noncomputable section /-- A free group basis `FreeGroupBasis ι G` is a structure recording the isomorphism between a group `G` and the free group over `ι`. One may think of such a basis as a function from `ι` to `G` (which is registered through a `FunLike` instance) together with the fact that the morphism induced by this function from `FreeGroup ι` to `G` is an isomorphism. -/ structure FreeGroupBasis (ι : Type*) (G : Type*) [Group G] where /-- `FreeGroupBasis.ofRepr` constructs a basis given an equivalence with a free group. -/ ofRepr :: /-- `repr` is the isomorphism between the group `G` and the free group generated by `ι`. -/ repr : G ≃* FreeGroup ι /-- A group is free if it admits a free group basis. In the definition, we require the basis to be in the same universe as `G`, although this property follows from the existence of a basis in any universe, see `FreeGroupBasis.isFreeGroup`. -/ class IsFreeGroup (G : Type u) [Group G] : Prop where nonempty_basis : ∃ (ι : Type u), Nonempty (FreeGroupBasis ι G) namespace FreeGroupBasis variable {ι ι' G H : Type*} [Group G] [Group H] /-- A free group basis for `G` over `ι` is associated to a map `ι → G` recording the images of the generators. -/ instance instFunLike : FunLike (FreeGroupBasis ι G) ι G where coe b := fun i ↦ b.repr.symm (FreeGroup.of i) coe_injective' := by rintro ⟨b⟩ ⟨b'⟩ hbb' have H : (b.symm : FreeGroup ι →* G) = (b'.symm : FreeGroup ι →* G) := by ext i; exact congr_fun hbb' i have : b.symm = b'.symm := by ext x; exact DFunLike.congr_fun H x rw [ofRepr.injEq, ← MulEquiv.symm_symm b, ← MulEquiv.symm_symm b', this] @[simp] lemma repr_apply_coe (b : FreeGroupBasis ι G) (i : ι) : b.repr (b i) = FreeGroup.of i := by change b.repr (b.repr.symm (FreeGroup.of i)) = FreeGroup.of i simp /-- The canonical basis of the free group over `X`. -/ def ofFreeGroup (X : Type*) : FreeGroupBasis X (FreeGroup X) := ofRepr (MulEquiv.refl _) @[simp] lemma ofFreeGroup_apply {X : Type*} (x : X) : FreeGroupBasis.ofFreeGroup X x = FreeGroup.of x := rfl /-- Reindex a free group basis through a bijection of the indexing sets. -/ protected def reindex (b : FreeGroupBasis ι G) (e : ι ≃ ι') : FreeGroupBasis ι' G := ofRepr (b.repr.trans (FreeGroup.freeGroupCongr e)) @[simp] lemma reindex_apply (b : FreeGroupBasis ι G) (e : ι ≃ ι') (x : ι') : b.reindex e x = b (e.symm x) := rfl /-- Pushing a free group basis through a group isomorphism. -/ protected def map (b : FreeGroupBasis ι G) (e : G ≃* H) : FreeGroupBasis ι H := ofRepr (e.symm.trans b.repr) @[simp] lemma map_apply (b : FreeGroupBasis ι G) (e : G ≃* H) (x : ι) : b.map e x = e (b x) := rfl protected lemma injective (b : FreeGroupBasis ι G) : Injective b := b.repr.symm.injective.comp FreeGroup.of_injective /-- A group admitting a free group basis is a free group. -/ lemma isFreeGroup (b : FreeGroupBasis ι G) : IsFreeGroup G := ⟨range b, ⟨b.reindex (Equiv.ofInjective (↑b) b.injective)⟩⟩ instance (X : Type*) : IsFreeGroup (FreeGroup X) := (ofFreeGroup X).isFreeGroup /-- Given a free group basis of `G` over `ι`, there is a canonical bijection between maps from `ι` to a group `H` and morphisms from `G` to `H`. -/ @[simps!] def lift (b : FreeGroupBasis ι G) : (ι → H) ≃ (G →* H) := FreeGroup.lift.trans { toFun := fun f => f.comp b.repr.toMonoidHom invFun := fun f => f.comp b.repr.symm.toMonoidHom left_inv := fun f => by ext simp right_inv := fun f => by ext simp } /-- If two morphisms on `G` coincide on the elements of a basis, then they coincide. -/ lemma ext_hom (b : FreeGroupBasis ι G) (f g : G →* H) (h : ∀ i, f (b i) = g (b i)) : f = g := b.lift.symm.injective <| funext h /-- If a group satisfies the universal property of a free group with respect to a given type, then it admits a free group basis based on this type. Here, the universal property is expressed as in `IsFreeGroup.lift` and its properties. -/ def ofLift {G : Type u} [Group G] (X : Type u) (of : X → G) (lift : ∀ {H : Type u} [Group H], (X → H) ≃ (G →* H)) (lift_of : ∀ {H : Type u} [Group H], ∀ (f : X → H) (a), lift f (of a) = f a) : FreeGroupBasis X G where repr := MulEquiv.symm <| MonoidHom.toMulEquiv (FreeGroup.lift of) (lift FreeGroup.of) (by apply FreeGroup.ext_hom; intro x simp only [MonoidHom.coe_comp, Function.comp_apply, MonoidHom.id_apply, FreeGroup.lift.of, lift_of]) (by let lift_symm_of : ∀ {H : Type u} [Group H], ∀ (f : G →* H) (a), lift.symm f a = f (of a) := by intro H _ f a; simp [← lift_of (lift.symm f)] apply lift.symm.injective; ext x simp only [MonoidHom.coe_comp, Function.comp_apply, MonoidHom.id_apply, FreeGroup.lift.of, lift_of, lift_symm_of]) /-- If a group satisfies the universal property of a free group with respect to a given type, then it admits a free group basis based on this type. Here the universal property is expressed as in `IsFreeGroup.unique_lift`. -/ def ofUniqueLift {G : Type u} [Group G] (X : Type u) (of : X → G) (h : ∀ {H : Type u} [Group H] (f : X → H), ∃! F : G →* H, ∀ a, F (of a) = f a) : FreeGroupBasis X G := let lift {H : Type u} [Group H] : (X → H) ≃ (G →* H) := { toFun := fun f => Classical.choose (h f) invFun := fun F => F ∘ of left_inv := fun f => funext (Classical.choose_spec (h f)).left right_inv := fun F => ((Classical.choose_spec (h (F ∘ of))).right F fun _ => rfl).symm } let lift_of {H : Type u} [Group H] (f : X → H) (a : X) : lift f (of a) = f a := congr_fun (lift.symm_apply_apply f) a ofLift X of @lift @lift_of end FreeGroupBasis namespace IsFreeGroup variable (G : Type*) [Group G] [IsFreeGroup G] /-- A set of generators of a free group, chosen arbitrarily -/ def Generators : Type _ := (IsFreeGroup.nonempty_basis (G := G)).choose /-- Any free group is isomorphic to "the" free group. -/ irreducible_def mulEquiv : FreeGroup (Generators G) ≃* G := (IsFreeGroup.nonempty_basis (G := G)).choose_spec.some.repr.symm /-- A free group basis of a free group `G`, over the set `Generators G`. -/ def basis : FreeGroupBasis (Generators G) G := FreeGroupBasis.ofRepr (mulEquiv G).symm /-- Any free group is isomorphic to "the" free group. -/ @[simps!] def toFreeGroup : G ≃* FreeGroup (Generators G) := (mulEquiv G).symm variable {G} /-- The canonical injection of G's generators into G -/ def of : Generators G → G := (mulEquiv G).toFun ∘ FreeGroup.of variable {H : Type*} [Group H] /-- The equivalence between functions on the generators and group homomorphisms from a free group given by those generators. -/ def lift : (Generators G → H) ≃ (G →* H) := (basis G).lift @[simp] theorem lift_of (f : Generators G → H) (a : Generators G) : lift f (of a) = f a := congr_fun (lift.symm_apply_apply f) a @[simp] theorem lift_symm_apply (f : G →* H) (a : Generators G) : (lift.symm f) a = f (of a) := rfl /- Do not register this as an ext lemma, as `Generators G` is not canonical. -/ theorem ext_hom ⦃f g : G →* H⦄ (h : ∀ a : Generators G, f (of a) = g (of a)) : f = g := lift.symm.injective (funext h) /-- The universal property of a free group: A function from the generators of `G` to another group extends in a unique way to a homomorphism from `G`. Note that since `IsFreeGroup.lift` is expressed as a bijection, it already expresses the universal property. -/ theorem unique_lift (f : Generators G → H) : ∃! F : G →* H, ∀ a, F (of a) = f a := by simpa only [Function.funext_iff] using lift.symm.bijective.existsUnique f /-- If a group satisfies the universal property of a free group with respect to a given type, then it is free. Here, the universal property is expressed as in `IsFreeGroup.lift` and its properties. -/ lemma ofLift {G : Type u} [Group G] (X : Type u) (of : X → G) (lift : ∀ {H : Type u} [Group H], (X → H) ≃ (G →* H)) (lift_of : ∀ {H : Type u} [Group H], ∀ (f : X → H) (a), lift f (of a) = f a) : IsFreeGroup G := (FreeGroupBasis.ofLift X of lift lift_of).isFreeGroup /-- If a group satisfies the universal property of a free group with respect to a given type, then it is free. Here the universal property is expressed as in `IsFreeGroup.unique_lift`. -/ lemma ofUniqueLift {G : Type u} [Group G] (X : Type u) (of : X → G) (h : ∀ {H : Type u} [Group H] (f : X → H), ∃! F : G →* H, ∀ a, F (of a) = f a) : IsFreeGroup G := (FreeGroupBasis.ofUniqueLift X of h).isFreeGroup lemma ofMulEquiv (e : G ≃* H) : IsFreeGroup H := ((basis G).map e).isFreeGroup end IsFreeGroup
GroupTheory\FreeGroup\NielsenSchreier.lean
/- Copyright (c) 2021 David Wärn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Wärn -/ import Mathlib.CategoryTheory.Action import Mathlib.Combinatorics.Quiver.Arborescence import Mathlib.Combinatorics.Quiver.ConnectedComponent import Mathlib.GroupTheory.FreeGroup.IsFreeGroup /-! # The Nielsen-Schreier theorem This file proves that a subgroup of a free group is itself free. ## Main result - `subgroupIsFreeOfIsFree H`: an instance saying that a subgroup of a free group is free. ## Proof overview The proof is analogous to the proof using covering spaces and fundamental groups of graphs, but we work directly with groupoids instead of topological spaces. Under this analogy, - `IsFreeGroupoid G` corresponds to saying that a space is a graph. - `endMulEquivSubgroup H` plays the role of replacing 'subgroup of fundamental group' with 'fundamental group of covering space'. - `actionGroupoidIsFree G A` corresponds to the fact that a covering of a (single-vertex) graph is a graph. - `endIsFree T` corresponds to the fact that, given a spanning tree `T` of a graph, its fundamental group is free (generated by loops from the complement of the tree). ## Implementation notes Our definition of `IsFreeGroupoid` is nonstandard. Normally one would require that functors `G ⥤ X` to any _groupoid_ `X` are given by graph homomorphisms from the generators, but we only consider _groups_ `X`. This simplifies the argument since functor equality is complicated in general, but simple for functors to single object categories. ## References https://ncatlab.org/nlab/show/Nielsen-Schreier+theorem ## Tags free group, free groupoid, Nielsen-Schreier -/ noncomputable section open scoped Classical universe v u /- Porting note: ./././Mathport/Syntax/Translate/Command.lean:229:11:unsupported: unusual advanced open style -/ open CategoryTheory CategoryTheory.ActionCategory CategoryTheory.SingleObj Quiver FreeGroup /-- `IsFreeGroupoid.Generators G` is a type synonym for `G`. We think of this as the vertices of the generating quiver of `G` when `G` is free. We can't use `G` directly, since `G` already has a quiver instance from being a groupoid. -/ -- Porting note(#5171): @[nolint has_nonempty_instance] @[nolint unusedArguments] def IsFreeGroupoid.Generators (G) [Groupoid G] := G /-- A groupoid `G` is free when we have the following data: - a quiver on `IsFreeGroupoid.Generators G` (a type synonym for `G`) - a function `of` taking a generating arrow to a morphism in `G` - such that a functor from `G` to any group `X` is uniquely determined by assigning labels in `X` to the generating arrows. This definition is nonstandard. Normally one would require that functors `G ⥤ X` to any _groupoid_ `X` are given by graph homomorphisms from `generators`. -/ class IsFreeGroupoid (G) [Groupoid.{v} G] where quiverGenerators : Quiver.{v + 1} (IsFreeGroupoid.Generators G) of : ∀ {a b : IsFreeGroupoid.Generators G}, (a ⟶ b) → ((show G from a) ⟶ b) unique_lift : ∀ {X : Type v} [Group X] (f : Labelling (IsFreeGroupoid.Generators G) X), ∃! F : G ⥤ CategoryTheory.SingleObj X, ∀ (a b) (g : a ⟶ b), F.map (of g) = f g attribute [nolint docBlame] IsFreeGroupoid.of IsFreeGroupoid.unique_lift namespace IsFreeGroupoid attribute [instance] quiverGenerators /-- Two functors from a free groupoid to a group are equal when they agree on the generating quiver. -/ @[ext] theorem ext_functor {G} [Groupoid.{v} G] [IsFreeGroupoid G] {X : Type v} [Group X] (f g : G ⥤ CategoryTheory.SingleObj X) (h : ∀ (a b) (e : a ⟶ b), f.map (of e) = g.map (of e)) : f = g := let ⟨_, _, u⟩ := @unique_lift G _ _ X _ fun (a b : Generators G) (e : a ⟶ b) => g.map (of e) _root_.trans (u _ h) (u _ fun _ _ _ => rfl).symm /-- An action groupoid over a free group is free. More generally, one could show that the groupoid of elements over a free groupoid is free, but this version is easier to prove and suffices for our purposes. Analogous to the fact that a covering space of a graph is a graph. (A free groupoid is like a graph, and a groupoid of elements is like a covering space.) -/ instance actionGroupoidIsFree {G A : Type u} [Group G] [IsFreeGroup G] [MulAction G A] : IsFreeGroupoid (ActionCategory G A) where quiverGenerators := ⟨fun a b => { e : IsFreeGroup.Generators G // IsFreeGroup.of e • a.back = b.back }⟩ of := fun (e : { e // _}) => ⟨IsFreeGroup.of e, e.property⟩ unique_lift := by intro X _ f let f' : IsFreeGroup.Generators G → (A → X) ⋊[mulAutArrow] G := fun e => ⟨fun b => @f ⟨(), _⟩ ⟨(), b⟩ ⟨e, smul_inv_smul _ b⟩, IsFreeGroup.of e⟩ rcases IsFreeGroup.unique_lift f' with ⟨F', hF', uF'⟩ refine ⟨uncurry F' ?_, ?_, ?_⟩ · suffices SemidirectProduct.rightHom.comp F' = MonoidHom.id _ by -- Porting note: `MonoidHom.ext_iff` has been deprecated. exact DFunLike.ext_iff.mp this apply IsFreeGroup.ext_hom (fun x ↦ ?_) rw [MonoidHom.comp_apply, hF'] rfl · rintro ⟨⟨⟩, a : A⟩ ⟨⟨⟩, b⟩ ⟨e, h : IsFreeGroup.of e • a = b⟩ change (F' (IsFreeGroup.of _)).left _ = _ rw [hF'] cases inv_smul_eq_iff.mpr h.symm rfl · intro E hE have : curry E = F' := by apply uF' intro e ext · convert hE _ _ _ rfl · rfl apply Functor.hext · intro apply Unit.ext · refine ActionCategory.cases ?_ intros simp only [← this, uncurry_map, curry_apply_left, coe_back, homOfPair.val] rfl namespace SpanningTree /- In this section, we suppose we have a free groupoid with a spanning tree for its generating quiver. The goal is to prove that the vertex group at the root is free. A picture to have in mind is that we are 'pulling' the endpoints of all the edges of the quiver along the spanning tree to the root. -/ variable {G : Type u} [Groupoid.{u} G] [IsFreeGroupoid G] (T : WideSubquiver (Symmetrify <| Generators G)) [Arborescence T] /-- The root of `T`, except its type is `G` instead of the type synonym `T`. -/ private def root' : G := show T from root T -- this has to be marked noncomputable, see issue #451. -- It might be nicer to define this in terms of `composePath` /-- A path in the tree gives a hom, by composition. -/ -- Porting note: removed noncomputable. This is already declared at the beginning of the section. def homOfPath : ∀ {a : G}, Path (root T) a → (root' T ⟶ a) | _, Path.nil => 𝟙 _ | _, Path.cons p f => homOfPath p ≫ Sum.recOn f.val (fun e => of e) fun e => inv (of e) /-- For every vertex `a`, there is a canonical hom from the root, given by the path in the tree. -/ def treeHom (a : G) : root' T ⟶ a := homOfPath T default /-- Any path to `a` gives `treeHom T a`, since paths in the tree are unique. -/ theorem treeHom_eq {a : G} (p : Path (root T) a) : treeHom T a = homOfPath T p := by rw [treeHom, Unique.default_eq] @[simp] theorem treeHom_root : treeHom T (root' T) = 𝟙 _ := -- this should just be `treeHom_eq T Path.nil`, but Lean treats `homOfPath` with suspicion. _root_.trans (treeHom_eq T Path.nil) rfl /-- Any hom in `G` can be made into a loop, by conjugating with `treeHom`s. -/ def loopOfHom {a b : G} (p : a ⟶ b) : End (root' T) := treeHom T a ≫ p ≫ inv (treeHom T b) /-- Turning an edge in the spanning tree into a loop gives the identity loop. -/ theorem loopOfHom_eq_id {a b : Generators G} (e) (H : e ∈ wideSubquiverSymmetrify T a b) : loopOfHom T (of e) = 𝟙 (root' T) := by rw [loopOfHom, ← Category.assoc, IsIso.comp_inv_eq, Category.id_comp] cases' H with H H · rw [treeHom_eq T (Path.cons default ⟨Sum.inl e, H⟩), homOfPath] rfl · rw [treeHom_eq T (Path.cons default ⟨Sum.inr e, H⟩), homOfPath] simp only [IsIso.inv_hom_id, Category.comp_id, Category.assoc, treeHom] /-- Since a hom gives a loop, any homomorphism from the vertex group at the root extends to a functor on the whole groupoid. -/ @[simps] def functorOfMonoidHom {X} [Monoid X] (f : End (root' T) →* X) : G ⥤ CategoryTheory.SingleObj X where obj _ := () map p := f (loopOfHom T p) map_id := by intro a dsimp only [loopOfHom] rw [Category.id_comp, IsIso.hom_inv_id, ← End.one_def, f.map_one, id_as_one] map_comp := by intros rw [comp_as_mul, ← f.map_mul] simp only [IsIso.inv_hom_id_assoc, loopOfHom, End.mul_def, Category.assoc] /-- Given a free groupoid and an arborescence of its generating quiver, the vertex group at the root is freely generated by loops coming from generating arrows in the complement of the tree. -/ lemma endIsFree : IsFreeGroup (End (root' T)) := IsFreeGroup.ofUniqueLift ((wideSubquiverEquivSetTotal <| wideSubquiverSymmetrify T)ᶜ : Set _) (fun e => loopOfHom T (of e.val.hom)) (by intro X _ f let f' : Labelling (Generators G) X := fun a b e => if h : e ∈ wideSubquiverSymmetrify T a b then 1 else f ⟨⟨a, b, e⟩, h⟩ rcases unique_lift f' with ⟨F', hF', uF'⟩ refine ⟨F'.mapEnd _, ?_, ?_⟩ · suffices ∀ {x y} (q : x ⟶ y), F'.map (loopOfHom T q) = (F'.map q : X) by rintro ⟨⟨a, b, e⟩, h⟩ erw [Functor.mapEnd_apply, this, hF'] exact dif_neg h intros x y q suffices ∀ {a} (p : Path (root T) a), F'.map (homOfPath T p) = 1 by simp only [this, treeHom, comp_as_mul, inv_as_inv, loopOfHom, inv_one, mul_one, one_mul, Functor.map_inv, Functor.map_comp] intro a p induction' p with b c p e ih · rw [homOfPath, F'.map_id, id_as_one] rw [homOfPath, F'.map_comp, comp_as_mul, ih, mul_one] rcases e with ⟨e | e, eT⟩ · rw [hF'] exact dif_pos (Or.inl eT) · rw [F'.map_inv, inv_as_inv, inv_eq_one, hF'] exact dif_pos (Or.inr eT) · intro E hE ext x suffices (functorOfMonoidHom T E).map x = F'.map x by simpa only [loopOfHom, functorOfMonoidHom, IsIso.inv_id, treeHom_root, Category.id_comp, Category.comp_id] using this congr apply uF' intro a b e change E (loopOfHom T _) = dite _ _ _ split_ifs with h · rw [loopOfHom_eq_id T e h, ← End.one_def, E.map_one] · exact hE ⟨⟨a, b, e⟩, h⟩) end SpanningTree /-- Another name for the identity function `G → G`, to help type checking. -/ private def symgen {G : Type u} [Groupoid.{v} G] [IsFreeGroupoid G] : G → Symmetrify (Generators G) := id /-- If there exists a morphism `a → b` in a free groupoid, then there also exists a zigzag from `a` to `b` in the generating quiver. -/ theorem path_nonempty_of_hom {G} [Groupoid.{u, u} G] [IsFreeGroupoid G] {a b : G} : Nonempty (a ⟶ b) → Nonempty (Path (symgen a) (symgen b)) := by rintro ⟨p⟩ rw [← @WeaklyConnectedComponent.eq (Generators G), eq_comm, ← FreeGroup.of_injective.eq_iff, ← mul_inv_eq_one] let X := FreeGroup (WeaklyConnectedComponent <| Generators G) let f : G → X := fun g => FreeGroup.of (WeaklyConnectedComponent.mk g) let F : G ⥤ CategoryTheory.SingleObj.{u} (X : Type u) := SingleObj.differenceFunctor f change (F.map p) = ((@CategoryTheory.Functor.const G _ _ (SingleObj.category X)).obj ()).map p congr; ext rw [Functor.const_obj_map, id_as_one, differenceFunctor_map, @mul_inv_eq_one _ _ (f _)] apply congr_arg FreeGroup.of apply (WeaklyConnectedComponent.eq _ _).mpr exact ⟨Hom.toPath (Sum.inr (by assumption))⟩ /-- Given a connected free groupoid, its generating quiver is rooted-connected. -/ instance generators_connected (G) [Groupoid.{u, u} G] [IsConnected G] [IsFreeGroupoid G] (r : G) : RootedConnected (symgen r) := ⟨fun b => path_nonempty_of_hom (CategoryTheory.nonempty_hom_of_preconnected_groupoid r b)⟩ /-- A vertex group in a free connected groupoid is free. With some work one could drop the connectedness assumption, by looking at connected components. -/ instance endIsFreeOfConnectedFree {G : Type u} [Groupoid G] [IsConnected G] [IsFreeGroupoid G] (r : G) : IsFreeGroup.{u} (End r) := SpanningTree.endIsFree <| geodesicSubtree (symgen r) end IsFreeGroupoid /-- The Nielsen-Schreier theorem: a subgroup of a free group is free. -/ instance subgroupIsFreeOfIsFree {G : Type u} [Group G] [IsFreeGroup G] (H : Subgroup G) : IsFreeGroup H := IsFreeGroup.ofMulEquiv (endMulEquivSubgroup H)
GroupTheory\GroupAction\Basic.lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Algebra.Group.Subgroup.Basic import Mathlib.Algebra.GroupWithZero.Action.Defs import Mathlib.Data.Fintype.Card import Mathlib.Data.Set.Finite import Mathlib.Data.Set.Pointwise.SMul import Mathlib.Data.Setoid.Basic import Mathlib.GroupTheory.GroupAction.Group /-! # Basic properties of group actions This file primarily concerns itself with orbits, stabilizers, and other objects defined in terms of actions. Despite this file being called `basic`, low-level helper lemmas for algebraic manipulation of `•` belong elsewhere. ## Main definitions * `MulAction.orbit` * `MulAction.fixedPoints` * `MulAction.fixedBy` * `MulAction.stabilizer` -/ universe u v open Pointwise open Function namespace MulAction variable (M : Type u) [Monoid M] (α : Type v) [MulAction M α] {β : Type*} [MulAction M β] section Orbit variable {α} /-- The orbit of an element under an action. -/ @[to_additive "The orbit of an element under an action."] def orbit (a : α) := Set.range fun m : M => m • a variable {M} @[to_additive] theorem mem_orbit_iff {a₁ a₂ : α} : a₂ ∈ orbit M a₁ ↔ ∃ x : M, x • a₁ = a₂ := Iff.rfl @[to_additive (attr := simp)] theorem mem_orbit (a : α) (m : M) : m • a ∈ orbit M a := ⟨m, rfl⟩ @[to_additive (attr := simp)] theorem mem_orbit_self (a : α) : a ∈ orbit M a := ⟨1, by simp [MulAction.one_smul]⟩ @[to_additive] theorem orbit_nonempty (a : α) : Set.Nonempty (orbit M a) := Set.range_nonempty _ @[to_additive] theorem mapsTo_smul_orbit (m : M) (a : α) : Set.MapsTo (m • ·) (orbit M a) (orbit M a) := Set.range_subset_iff.2 fun m' => ⟨m * m', mul_smul _ _ _⟩ @[to_additive] theorem smul_orbit_subset (m : M) (a : α) : m • orbit M a ⊆ orbit M a := (mapsTo_smul_orbit m a).image_subset @[to_additive] theorem orbit_smul_subset (m : M) (a : α) : orbit M (m • a) ⊆ orbit M a := Set.range_subset_iff.2 fun m' => mul_smul m' m a ▸ mem_orbit _ _ @[to_additive] instance {a : α} : MulAction M (orbit M a) where smul m := (mapsTo_smul_orbit m a).restrict _ _ _ one_smul m := Subtype.ext (one_smul M (m : α)) mul_smul m m' a' := Subtype.ext (mul_smul m m' (a' : α)) @[to_additive (attr := simp)] theorem orbit.coe_smul {a : α} {m : M} {a' : orbit M a} : ↑(m • a') = m • (a' : α) := rfl @[to_additive] lemma orbit_submonoid_subset (S : Submonoid M) (a : α) : orbit S a ⊆ orbit M a := by rintro b ⟨g, rfl⟩ exact mem_orbit _ _ @[to_additive] lemma mem_orbit_of_mem_orbit_submonoid {S : Submonoid M} {a b : α} (h : a ∈ orbit S b) : a ∈ orbit M b := orbit_submonoid_subset S _ h @[to_additive] lemma fst_mem_orbit_of_mem_orbit {x y : α × β} (h : x ∈ MulAction.orbit M y) : x.1 ∈ MulAction.orbit M y.1 := by rcases h with ⟨g, rfl⟩ exact mem_orbit _ _ @[to_additive] lemma snd_mem_orbit_of_mem_orbit {x y : α × β} (h : x ∈ MulAction.orbit M y) : x.2 ∈ MulAction.orbit M y.2 := by rcases h with ⟨g, rfl⟩ exact mem_orbit _ _ variable (M) @[to_additive] theorem orbit_eq_univ [IsPretransitive M α] (a : α) : orbit M a = Set.univ := (surjective_smul M a).range_eq end Orbit section FixedPoints /-- The set of elements fixed under the whole action. -/ @[to_additive "The set of elements fixed under the whole action."] def fixedPoints : Set α := { a : α | ∀ m : M, m • a = a } variable {M} /-- `fixedBy m` is the set of elements fixed by `m`. -/ @[to_additive "`fixedBy m` is the set of elements fixed by `m`."] def fixedBy (m : M) : Set α := { x | m • x = x } variable (M) @[to_additive] theorem fixed_eq_iInter_fixedBy : fixedPoints M α = ⋂ m : M, fixedBy α m := Set.ext fun _ => ⟨fun hx => Set.mem_iInter.2 fun m => hx m, fun hx m => (Set.mem_iInter.1 hx m : _)⟩ variable {M α} @[to_additive (attr := simp)] theorem mem_fixedPoints {a : α} : a ∈ fixedPoints M α ↔ ∀ m : M, m • a = a := Iff.rfl @[to_additive (attr := simp)] theorem mem_fixedBy {m : M} {a : α} : a ∈ fixedBy α m ↔ m • a = a := Iff.rfl @[to_additive] theorem mem_fixedPoints' {a : α} : a ∈ fixedPoints M α ↔ ∀ a', a' ∈ orbit M a → a' = a := ⟨fun h _ h₁ => let ⟨m, hm⟩ := mem_orbit_iff.1 h₁ hm ▸ h m, fun h _ => h _ (mem_orbit _ _)⟩ @[to_additive mem_fixedPoints_iff_card_orbit_eq_one] theorem mem_fixedPoints_iff_card_orbit_eq_one {a : α} [Fintype (orbit M a)] : a ∈ fixedPoints M α ↔ Fintype.card (orbit M a) = 1 := by rw [Fintype.card_eq_one_iff, mem_fixedPoints] constructor · exact fun h => ⟨⟨a, mem_orbit_self _⟩, fun ⟨a, ⟨x, hx⟩⟩ => Subtype.eq <| by simp [h x, hx.symm]⟩ · intro h x rcases h with ⟨⟨z, hz⟩, hz₁⟩ calc x • a = z := Subtype.mk.inj (hz₁ ⟨x • a, mem_orbit _ _⟩) _ = a := (Subtype.mk.inj (hz₁ ⟨a, mem_orbit_self _⟩)).symm end FixedPoints section Stabilizers variable {α} /-- The stabilizer of a point `a` as a submonoid of `M`. -/ @[to_additive "The stabilizer of a point `a` as an additive submonoid of `M`."] def stabilizerSubmonoid (a : α) : Submonoid M where carrier := { m | m • a = a } one_mem' := one_smul _ a mul_mem' {m m'} (ha : m • a = a) (hb : m' • a = a) := show (m * m') • a = a by rw [← smul_smul, hb, ha] variable {M} @[to_additive] instance [DecidableEq α] (a : α) : DecidablePred (· ∈ stabilizerSubmonoid M a) := fun _ => inferInstanceAs <| Decidable (_ = _) @[to_additive (attr := simp)] theorem mem_stabilizerSubmonoid_iff {a : α} {m : M} : m ∈ stabilizerSubmonoid M a ↔ m • a = a := Iff.rfl end Stabilizers end MulAction section FixedPoints variable (M : Type u) (α : Type v) [Monoid M] section Monoid variable [Monoid α] [MulDistribMulAction M α] /-- The submonoid of elements fixed under the whole action. -/ def FixedPoints.submonoid : Submonoid α where carrier := MulAction.fixedPoints M α one_mem' := smul_one mul_mem' ha hb _ := by rw [smul_mul', ha, hb] @[simp] lemma FixedPoints.mem_submonoid (a : α) : a ∈ submonoid M α ↔ ∀ m : M, m • a = a := Iff.rfl end Monoid section Group namespace FixedPoints variable [Group α] [MulDistribMulAction M α] /-- The subgroup of elements fixed under the whole action. -/ def subgroup : Subgroup α where __ := submonoid M α inv_mem' ha _ := by rw [smul_inv', ha] /-- The notation for `FixedPoints.subgroup`, chosen to resemble `αᴹ`. -/ scoped notation α "^*" M:51 => FixedPoints.subgroup M α @[simp] lemma mem_subgroup (a : α) : a ∈ α^*M ↔ ∀ m : M, m • a = a := Iff.rfl @[simp] lemma subgroup_toSubmonoid : (α^*M).toSubmonoid = submonoid M α := rfl end FixedPoints end Group section AddMonoid variable [AddMonoid α] [DistribMulAction M α] /-- The additive submonoid of elements fixed under the whole action. -/ def FixedPoints.addSubmonoid : AddSubmonoid α where carrier := MulAction.fixedPoints M α zero_mem' := smul_zero add_mem' ha hb _ := by rw [smul_add, ha, hb] @[simp] lemma FixedPoints.mem_addSubmonoid (a : α) : a ∈ addSubmonoid M α ↔ ∀ m : M, m • a = a := Iff.rfl end AddMonoid section AddGroup variable [AddGroup α] [DistribMulAction M α] /-- The additive subgroup of elements fixed under the whole action. -/ def FixedPoints.addSubgroup : AddSubgroup α where __ := addSubmonoid M α neg_mem' ha _ := by rw [smul_neg, ha] /-- The notation for `FixedPoints.addSubgroup`, chosen to resemble `αᴹ`. -/ notation α "^+" M:51 => FixedPoints.addSubgroup M α @[simp] lemma FixedPoints.mem_addSubgroup (a : α) : a ∈ α^+M ↔ ∀ m : M, m • a = a := Iff.rfl @[simp] lemma FixedPoints.addSubgroup_toAddSubmonoid : (α^+M).toAddSubmonoid = addSubmonoid M α := rfl end AddGroup end FixedPoints /-- `smul` by a `k : M` over a ring is injective, if `k` is not a zero divisor. The general theory of such `k` is elaborated by `IsSMulRegular`. The typeclass that restricts all terms of `M` to have this property is `NoZeroSMulDivisors`. -/ theorem smul_cancel_of_non_zero_divisor {M R : Type*} [Monoid M] [NonUnitalNonAssocRing R] [DistribMulAction M R] (k : M) (h : ∀ x : R, k • x = 0 → x = 0) {a b : R} (h' : k • a = k • b) : a = b := by rw [← sub_eq_zero] refine h _ ?_ rw [smul_sub, h', sub_self] namespace MulAction variable {G α β : Type*} [Group G] [MulAction G α] [MulAction G β] section Orbit @[to_additive (attr := simp)] theorem smul_orbit (g : G) (a : α) : g • orbit G a = orbit G a := (smul_orbit_subset g a).antisymm <| calc orbit G a = g • g⁻¹ • orbit G a := (smul_inv_smul _ _).symm _ ⊆ g • orbit G a := Set.image_subset _ (smul_orbit_subset _ _) @[to_additive (attr := simp)] theorem orbit_smul (g : G) (a : α) : orbit G (g • a) = orbit G a := (orbit_smul_subset g a).antisymm <| calc orbit G a = orbit G (g⁻¹ • g • a) := by rw [inv_smul_smul] _ ⊆ orbit G (g • a) := orbit_smul_subset _ _ /-- The action of a group on an orbit is transitive. -/ @[to_additive "The action of an additive group on an orbit is transitive."] instance (a : α) : IsPretransitive G (orbit G a) := ⟨by rintro ⟨_, g, rfl⟩ ⟨_, h, rfl⟩ use h * g⁻¹ ext1 simp [mul_smul]⟩ @[to_additive] theorem orbit_eq_iff {a b : α} : orbit G a = orbit G b ↔ a ∈ orbit G b := ⟨fun h => h ▸ mem_orbit_self _, fun ⟨_, hc⟩ => hc ▸ orbit_smul _ _⟩ @[to_additive] theorem mem_orbit_smul (g : G) (a : α) : a ∈ orbit G (g • a) := by simp only [orbit_smul, mem_orbit_self] @[to_additive] theorem smul_mem_orbit_smul (g h : G) (a : α) : g • a ∈ orbit G (h • a) := by simp only [orbit_smul, mem_orbit] @[to_additive] lemma orbit_subgroup_subset (H : Subgroup G) (a : α) : orbit H a ⊆ orbit G a := orbit_submonoid_subset H.toSubmonoid a @[to_additive] lemma mem_orbit_of_mem_orbit_subgroup {H : Subgroup G} {a b : α} (h : a ∈ orbit H b) : a ∈ orbit G b := orbit_subgroup_subset H _ h @[to_additive] lemma mem_orbit_symm {a₁ a₂ : α} : a₁ ∈ orbit G a₂ ↔ a₂ ∈ orbit G a₁ := by simp_rw [← orbit_eq_iff, eq_comm] @[to_additive] lemma mem_subgroup_orbit_iff {H : Subgroup G} {x : α} {a b : orbit G x} : a ∈ MulAction.orbit H b ↔ (a : α) ∈ MulAction.orbit H (b : α) := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rcases h with ⟨g, rfl⟩ simp_rw [Submonoid.smul_def, Subgroup.coe_toSubmonoid, orbit.coe_smul, ← Submonoid.smul_def] exact MulAction.mem_orbit _ g · rcases h with ⟨g, h⟩ simp_rw [Submonoid.smul_def, Subgroup.coe_toSubmonoid, ← orbit.coe_smul, ← Submonoid.smul_def, ← Subtype.ext_iff] at h subst h exact MulAction.mem_orbit _ g variable (G α) /-- The relation 'in the same orbit'. -/ @[to_additive "The relation 'in the same orbit'."] def orbitRel : Setoid α where r a b := a ∈ orbit G b iseqv := ⟨mem_orbit_self, fun {a b} => by simp [orbit_eq_iff.symm, eq_comm], fun {a b} => by simp (config := { contextual := true }) [orbit_eq_iff.symm, eq_comm]⟩ variable {G α} @[to_additive] theorem orbitRel_apply {a b : α} : (orbitRel G α).Rel a b ↔ a ∈ orbit G b := Iff.rfl @[to_additive] lemma orbitRel_r_apply {a b : α} : (orbitRel G _).r a b ↔ a ∈ orbit G b := Iff.rfl @[to_additive] lemma orbitRel_subgroup_le (H : Subgroup G) : orbitRel H α ≤ orbitRel G α := Setoid.le_def.2 mem_orbit_of_mem_orbit_subgroup /-- When you take a set `U` in `α`, push it down to the quotient, and pull back, you get the union of the orbit of `U` under `G`. -/ @[to_additive "When you take a set `U` in `α`, push it down to the quotient, and pull back, you get the union of the orbit of `U` under `G`."] theorem quotient_preimage_image_eq_union_mul (U : Set α) : letI := orbitRel G α Quotient.mk' ⁻¹' (Quotient.mk' '' U) = ⋃ g : G, (g • ·) '' U := by letI := orbitRel G α set f : α → Quotient (MulAction.orbitRel G α) := Quotient.mk' ext a constructor · rintro ⟨b, hb, hab⟩ obtain ⟨g, rfl⟩ := Quotient.exact hab rw [Set.mem_iUnion] exact ⟨g⁻¹, g • a, hb, inv_smul_smul g a⟩ · intro hx rw [Set.mem_iUnion] at hx obtain ⟨g, u, hu₁, hu₂⟩ := hx rw [Set.mem_preimage, Set.mem_image] refine ⟨g⁻¹ • a, ?_, by simp only [f, Quotient.eq']; use g⁻¹⟩ rw [← hu₂] convert hu₁ simp only [inv_smul_smul] @[to_additive] theorem disjoint_image_image_iff {U V : Set α} : letI := orbitRel G α Disjoint (Quotient.mk' '' U) (Quotient.mk' '' V) ↔ ∀ x ∈ U, ∀ g : G, g • x ∉ V := by letI := orbitRel G α set f : α → Quotient (MulAction.orbitRel G α) := Quotient.mk' refine ⟨fun h a a_in_U g g_in_V => h.le_bot ⟨⟨a, a_in_U, Quotient.sound ⟨g⁻¹, ?_⟩⟩, ⟨g • a, g_in_V, rfl⟩⟩, ?_⟩ · simp · intro h rw [Set.disjoint_left] rintro _ ⟨b, hb₁, hb₂⟩ ⟨c, hc₁, hc₂⟩ obtain ⟨g, rfl⟩ := Quotient.exact (hc₂.trans hb₂.symm) exact h b hb₁ g hc₁ @[to_additive] theorem image_inter_image_iff (U V : Set α) : letI := orbitRel G α Quotient.mk' '' U ∩ Quotient.mk' '' V = ∅ ↔ ∀ x ∈ U, ∀ g : G, g • x ∉ V := Set.disjoint_iff_inter_eq_empty.symm.trans disjoint_image_image_iff variable (G α) /-- The quotient by `MulAction.orbitRel`, given a name to enable dot notation. -/ @[to_additive (attr := reducible) "The quotient by `AddAction.orbitRel`, given a name to enable dot notation."] def orbitRel.Quotient : Type _ := _root_.Quotient <| orbitRel G α /-- An action is pretransitive if and only if the quotient by `MulAction.orbitRel` is a subsingleton. -/ @[to_additive "An additive action is pretransitive if and only if the quotient by `AddAction.orbitRel` is a subsingleton."] theorem pretransitive_iff_subsingleton_quotient : IsPretransitive G α ↔ Subsingleton (orbitRel.Quotient G α) := by refine ⟨fun _ ↦ ⟨fun a b ↦ ?_⟩, fun _ ↦ ⟨fun a b ↦ ?_⟩⟩ · refine Quot.inductionOn a (fun x ↦ ?_) exact Quot.inductionOn b (fun y ↦ Quot.sound <| exists_smul_eq G y x) · have h : Quotient.mk (orbitRel G α) b = ⟦a⟧ := Subsingleton.elim _ _ exact Quotient.eq_rel.mp h /-- If `α` is non-empty, an action is pretransitive if and only if the quotient has exactly one element. -/ @[to_additive "If `α` is non-empty, an additive action is pretransitive if and only if the quotient has exactly one element."] theorem pretransitive_iff_unique_quotient_of_nonempty [Nonempty α] : IsPretransitive G α ↔ Nonempty (Unique <| orbitRel.Quotient G α) := by rw [unique_iff_subsingleton_and_nonempty, pretransitive_iff_subsingleton_quotient, iff_self_and] exact fun _ ↦ (nonempty_quotient_iff _).mpr inferInstance variable {G α} /-- The orbit corresponding to an element of the quotient by `MulAction.orbitRel` -/ @[to_additive "The orbit corresponding to an element of the quotient by `AddAction.orbitRel`"] nonrec def orbitRel.Quotient.orbit (x : orbitRel.Quotient G α) : Set α := Quotient.liftOn' x (orbit G) fun _ _ => MulAction.orbit_eq_iff.2 @[to_additive (attr := simp)] theorem orbitRel.Quotient.orbit_mk (a : α) : orbitRel.Quotient.orbit (Quotient.mk'' a : orbitRel.Quotient G α) = MulAction.orbit G a := rfl @[to_additive] theorem orbitRel.Quotient.mem_orbit {a : α} {x : orbitRel.Quotient G α} : a ∈ x.orbit ↔ Quotient.mk'' a = x := by induction x using Quotient.inductionOn' rw [Quotient.eq''] rfl /-- Note that `hφ = Quotient.out_eq'` is a useful choice here. -/ @[to_additive "Note that `hφ = Quotient.out_eq'` is a useful choice here."] theorem orbitRel.Quotient.orbit_eq_orbit_out (x : orbitRel.Quotient G α) {φ : orbitRel.Quotient G α → α} (hφ : letI := orbitRel G α; RightInverse φ Quotient.mk') : orbitRel.Quotient.orbit x = MulAction.orbit G (φ x) := by conv_lhs => rw [← hφ x] rfl @[to_additive] lemma orbitRel.Quotient.orbit_injective : Injective (orbitRel.Quotient.orbit : orbitRel.Quotient G α → Set α) := by intro x y h simp_rw [orbitRel.Quotient.orbit_eq_orbit_out _ Quotient.out_eq', orbit_eq_iff, ← orbitRel_r_apply] at h simpa [← Quotient.eq''] using h @[to_additive (attr := simp)] lemma orbitRel.Quotient.orbit_inj {x y : orbitRel.Quotient G α} : x.orbit = y.orbit ↔ x = y := orbitRel.Quotient.orbit_injective.eq_iff @[to_additive] lemma orbitRel.quotient_eq_of_quotient_subgroup_eq {H : Subgroup G} {a b : α} (h : (⟦a⟧ : orbitRel.Quotient H α) = ⟦b⟧) : (⟦a⟧ : orbitRel.Quotient G α) = ⟦b⟧ := by rw [@Quotient.eq] at h ⊢ exact mem_orbit_of_mem_orbit_subgroup h @[to_additive] lemma orbitRel.quotient_eq_of_quotient_subgroup_eq' {H : Subgroup G} {a b : α} (h : (Quotient.mk'' a : orbitRel.Quotient H α) = Quotient.mk'' b) : (Quotient.mk'' a : orbitRel.Quotient G α) = Quotient.mk'' b := orbitRel.quotient_eq_of_quotient_subgroup_eq h @[to_additive] nonrec lemma orbitRel.Quotient.orbit_nonempty (x : orbitRel.Quotient G α) : Set.Nonempty x.orbit := by rw [orbitRel.Quotient.orbit_eq_orbit_out x Quotient.out_eq'] exact orbit_nonempty _ @[to_additive] nonrec lemma orbitRel.Quotient.mapsTo_smul_orbit (g : G) (x : orbitRel.Quotient G α) : Set.MapsTo (g • ·) x.orbit x.orbit := by rw [orbitRel.Quotient.orbit_eq_orbit_out x Quotient.out_eq'] exact mapsTo_smul_orbit g x.out' @[to_additive] instance (x : orbitRel.Quotient G α) : MulAction G x.orbit where smul g := (orbitRel.Quotient.mapsTo_smul_orbit g x).restrict _ _ _ one_smul a := Subtype.ext (one_smul G (a : α)) mul_smul g g' a' := Subtype.ext (mul_smul g g' (a' : α)) @[to_additive (attr := simp)] lemma orbitRel.Quotient.orbit.coe_smul {g : G} {x : orbitRel.Quotient G α} {a : x.orbit} : ↑(g • a) = g • (a : α) := rfl @[to_additive] instance (x : orbitRel.Quotient G α) : IsPretransitive G x.orbit where exists_smul_eq := by induction x using Quotient.inductionOn' rintro ⟨y, yh⟩ ⟨z, zh⟩ rw [orbitRel.Quotient.mem_orbit, Quotient.eq''] at yh zh rcases yh with ⟨g, rfl⟩ rcases zh with ⟨h, rfl⟩ refine ⟨h * g⁻¹, ?_⟩ ext simp [mul_smul] @[to_additive (attr := norm_cast, simp)] lemma orbitRel.Quotient.mem_subgroup_orbit_iff {H : Subgroup G} {x : orbitRel.Quotient G α} {a b : x.orbit} : (a : α) ∈ MulAction.orbit H (b : α) ↔ a ∈ MulAction.orbit H b := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rcases h with ⟨g, h⟩ simp_rw [Submonoid.smul_def, Subgroup.coe_toSubmonoid, ← orbit.coe_smul, ← Submonoid.smul_def, ← Subtype.ext_iff] at h subst h exact MulAction.mem_orbit _ g · rcases h with ⟨g, rfl⟩ simp_rw [Submonoid.smul_def, Subgroup.coe_toSubmonoid, orbit.coe_smul, ← Submonoid.smul_def] exact MulAction.mem_orbit _ g @[to_additive] lemma orbitRel.Quotient.subgroup_quotient_eq_iff {H : Subgroup G} {x : orbitRel.Quotient G α} {a b : x.orbit} : (⟦a⟧ : orbitRel.Quotient H x.orbit) = ⟦b⟧ ↔ (⟦↑a⟧ : orbitRel.Quotient H α) = ⟦↑b⟧ := by simp_rw [← @Quotient.mk''_eq_mk, Quotient.eq''] exact orbitRel.Quotient.mem_subgroup_orbit_iff.symm @[to_additive] lemma orbitRel.Quotient.mem_subgroup_orbit_iff' {H : Subgroup G} {x : orbitRel.Quotient G α} {a b : x.orbit} {c : α} (h : (⟦a⟧ : orbitRel.Quotient H x.orbit) = ⟦b⟧) : (a : α) ∈ MulAction.orbit H c ↔ (b : α) ∈ MulAction.orbit H c := by simp_rw [mem_orbit_symm (a₂ := c)] convert Iff.rfl using 2 rw [orbit_eq_iff] suffices hb : ↑b ∈ orbitRel.Quotient.orbit (⟦a⟧ : orbitRel.Quotient H x.orbit) by rw [orbitRel.Quotient.orbit_eq_orbit_out (⟦a⟧ : orbitRel.Quotient H x.orbit) Quotient.out_eq'] at hb rw [orbitRel.Quotient.mem_subgroup_orbit_iff] convert hb using 1 rw [orbit_eq_iff, ← orbitRel_r_apply, ← Quotient.eq'', Quotient.out_eq', @Quotient.mk''_eq_mk] rw [orbitRel.Quotient.mem_orbit, h, @Quotient.mk''_eq_mk] variable (G) (α) local notation "Ω" => orbitRel.Quotient G α /-- Decomposition of a type `X` as a disjoint union of its orbits under a group action. This version is expressed in terms of `MulAction.orbitRel.Quotient.orbit` instead of `MulAction.orbit`, to avoid mentioning `Quotient.out'`. -/ @[to_additive "Decomposition of a type `X` as a disjoint union of its orbits under an additive group action. This version is expressed in terms of `AddAction.orbitRel.Quotient.orbit` instead of `AddAction.orbit`, to avoid mentioning `Quotient.out'`. "] def selfEquivSigmaOrbits' : α ≃ Σω : Ω, ω.orbit := letI := orbitRel G α calc α ≃ Σω : Ω, { a // Quotient.mk' a = ω } := (Equiv.sigmaFiberEquiv Quotient.mk').symm _ ≃ Σω : Ω, ω.orbit := Equiv.sigmaCongrRight fun _ => Equiv.subtypeEquivRight fun _ => orbitRel.Quotient.mem_orbit.symm /-- Decomposition of a type `X` as a disjoint union of its orbits under a group action. -/ @[to_additive "Decomposition of a type `X` as a disjoint union of its orbits under an additive group action."] def selfEquivSigmaOrbits : α ≃ Σω : Ω, orbit G ω.out' := (selfEquivSigmaOrbits' G α).trans <| Equiv.sigmaCongrRight fun _ => Equiv.Set.ofEq <| orbitRel.Quotient.orbit_eq_orbit_out _ Quotient.out_eq' variable (β) @[to_additive] lemma orbitRel_le_fst : orbitRel G (α × β) ≤ (orbitRel G α).comap Prod.fst := Setoid.le_def.2 fst_mem_orbit_of_mem_orbit @[to_additive] lemma orbitRel_le_snd : orbitRel G (α × β) ≤ (orbitRel G β).comap Prod.snd := Setoid.le_def.2 snd_mem_orbit_of_mem_orbit end Orbit section Stabilizer variable (G) /-- The stabilizer of an element under an action, i.e. what sends the element to itself. A subgroup. -/ @[to_additive "The stabilizer of an element under an action, i.e. what sends the element to itself. An additive subgroup."] def stabilizer (a : α) : Subgroup G := { stabilizerSubmonoid G a with inv_mem' := fun {m} (ha : m • a = a) => show m⁻¹ • a = a by rw [inv_smul_eq_iff, ha] } variable {G} @[to_additive] instance [DecidableEq α] (a : α) : DecidablePred (· ∈ stabilizer G a) := fun _ => inferInstanceAs <| Decidable (_ = _) @[to_additive (attr := simp)] theorem mem_stabilizer_iff {a : α} {g : G} : g ∈ stabilizer G a ↔ g • a = a := Iff.rfl @[to_additive] lemma le_stabilizer_smul_left [SMul α β] [IsScalarTower G α β] (a : α) (b : β) : stabilizer G a ≤ stabilizer G (a • b) := by simp_rw [SetLike.le_def, mem_stabilizer_iff, ← smul_assoc]; rintro a h; rw [h] -- This lemma does not need `MulAction G α`, only `SMul G α`. -- We use `G'` instead of `G` to locally reduce the typeclass assumptions. @[to_additive] lemma le_stabilizer_smul_right {G'} [Group G'] [SMul α β] [MulAction G' β] [SMulCommClass G' α β] (a : α) (b : β) : stabilizer G' b ≤ stabilizer G' (a • b) := by simp_rw [SetLike.le_def, mem_stabilizer_iff, smul_comm]; rintro a h; rw [h] @[to_additive (attr := simp)] lemma stabilizer_smul_eq_left [SMul α β] [IsScalarTower G α β] (a : α) (b : β) (h : Injective (· • b : α → β)) : stabilizer G (a • b) = stabilizer G a := by refine (le_stabilizer_smul_left _ _).antisymm' fun a ha ↦ ?_ simpa only [mem_stabilizer_iff, ← smul_assoc, h.eq_iff] using ha @[to_additive (attr := simp)] lemma stabilizer_smul_eq_right {α} [Group α] [MulAction α β] [SMulCommClass G α β] (a : α) (b : β) : stabilizer G (a • b) = stabilizer G b := (le_stabilizer_smul_right _ _).antisymm' <| (le_stabilizer_smul_right a⁻¹ _).trans_eq <| by rw [inv_smul_smul] @[to_additive (attr := simp)] lemma stabilizer_mul_eq_left [Group α] [IsScalarTower G α α] (a b : α) : stabilizer G (a * b) = stabilizer G a := stabilizer_smul_eq_left a _ <| mul_left_injective _ @[to_additive (attr := simp)] lemma stabilizer_mul_eq_right [Group α] [SMulCommClass G α α] (a b : α) : stabilizer G (a * b) = stabilizer G b := stabilizer_smul_eq_right a _ /-- If the stabilizer of `a` is `S`, then the stabilizer of `g • a` is `gSg⁻¹`. -/ theorem stabilizer_smul_eq_stabilizer_map_conj (g : G) (a : α) : stabilizer G (g • a) = (stabilizer G a).map (MulAut.conj g).toMonoidHom := by ext h rw [mem_stabilizer_iff, ← smul_left_cancel_iff g⁻¹, smul_smul, smul_smul, smul_smul, mul_left_inv, one_smul, ← mem_stabilizer_iff, Subgroup.mem_map_equiv, MulAut.conj_symm_apply] /-- A bijection between the stabilizers of two elements in the same orbit. -/ noncomputable def stabilizerEquivStabilizerOfOrbitRel {a b : α} (h : (orbitRel G α).Rel a b) : stabilizer G a ≃* stabilizer G b := let g : G := Classical.choose h have hg : g • b = a := Classical.choose_spec h have this : stabilizer G a = (stabilizer G b).map (MulAut.conj g).toMonoidHom := by rw [← hg, stabilizer_smul_eq_stabilizer_map_conj] (MulEquiv.subgroupCongr this).trans ((MulAut.conj g).subgroupMap <| stabilizer G b).symm end Stabilizer end MulAction namespace AddAction variable {G α : Type*} [AddGroup G] [AddAction G α] /-- If the stabilizer of `x` is `S`, then the stabilizer of `g +ᵥ x` is `g + S + (-g)`. -/ theorem stabilizer_vadd_eq_stabilizer_map_conj (g : G) (a : α) : stabilizer G (g +ᵥ a) = (stabilizer G a).map (AddAut.conj g).toAddMonoidHom := by ext h rw [mem_stabilizer_iff, ← vadd_left_cancel_iff (-g), vadd_vadd, vadd_vadd, vadd_vadd, add_left_neg, zero_vadd, ← mem_stabilizer_iff, AddSubgroup.mem_map_equiv, AddAut.conj_symm_apply] /-- A bijection between the stabilizers of two elements in the same orbit. -/ noncomputable def stabilizerEquivStabilizerOfOrbitRel {a b : α} (h : (orbitRel G α).Rel a b) : stabilizer G a ≃+ stabilizer G b := let g : G := Classical.choose h have hg : g +ᵥ b = a := Classical.choose_spec h have this : stabilizer G a = (stabilizer G b).map (AddAut.conj g).toAddMonoidHom := by rw [← hg, stabilizer_vadd_eq_stabilizer_map_conj] (AddEquiv.addSubgroupCongr this).trans ((AddAut.conj g).addSubgroupMap <| stabilizer G b).symm end AddAction attribute [to_additive existing] MulAction.stabilizer_smul_eq_stabilizer_map_conj attribute [to_additive existing] MulAction.stabilizerEquivStabilizerOfOrbitRel theorem Equiv.swap_mem_stabilizer {α : Type*} [DecidableEq α] {S : Set α} {a b : α} : Equiv.swap a b ∈ MulAction.stabilizer (Equiv.Perm α) S ↔ (a ∈ S ↔ b ∈ S) := by rw [MulAction.mem_stabilizer_iff, Set.ext_iff, ← swap_inv] simp_rw [Set.mem_inv_smul_set_iff, Perm.smul_def, swap_apply_def] exact ⟨fun h ↦ by simpa [Iff.comm] using h a, by intros; split_ifs <;> simp [*]⟩ namespace MulAction variable {G : Type*} [Group G] {α : Type*} [MulAction G α] /-- To prove inclusion of a *subgroup* in a stabilizer, it is enough to prove inclusions.-/ theorem le_stabilizer_iff_smul_le (s : Set α) (H : Subgroup G) : H ≤ stabilizer G s ↔ ∀ g ∈ H, g • s ⊆ s := by constructor · intro hyp g hg apply Eq.subset rw [← mem_stabilizer_iff] exact hyp hg · intro hyp g hg rw [mem_stabilizer_iff] apply subset_antisymm (hyp g hg) intro x hx use g⁻¹ • x constructor · apply hyp g⁻¹ (inv_mem hg) simp only [Set.smul_mem_smul_set_iff, hx] · simp only [smul_inv_smul] /-- To prove membership to stabilizer of a *finite set*, it is enough to prove one inclusion. -/ theorem mem_stabilizer_of_finite_iff_smul_le (s : Set α) (hs : s.Finite) (g : G) : g ∈ stabilizer G s ↔ g • s ⊆ s := by haveI : Fintype s := Set.Finite.fintype hs haveI : Fintype (g • s : Set α) := Fintype.ofFinite _ rw [mem_stabilizer_iff] constructor · exact Eq.subset · rw [← Set.toFinset_inj, ← Set.toFinset_subset_toFinset] intro h apply Finset.eq_of_subset_of_card_le h apply le_of_eq suffices (g • s).toFinset = Finset.map ⟨_, MulAction.injective g⟩ hs.toFinset by rw [this, Finset.card_map, Set.toFinite_toFinset] rw [← Finset.coe_inj] simp only [Set.coe_toFinset, Set.toFinite_toFinset, Finset.coe_map, Function.Embedding.coeFn_mk, Set.image_smul] /-- To prove membership to stabilizer of a *finite set*, it is enough to prove one inclusion. -/ theorem mem_stabilizer_of_finite_iff_le_smul (s : Set α) (hs : s.Finite) (g : G) : g ∈ stabilizer G s ↔ s ⊆ g • s := by rw [← @inv_mem_iff, mem_stabilizer_of_finite_iff_smul_le s hs] exact Set.subset_set_smul_iff.symm end MulAction
GroupTheory\GroupAction\BigOperators.lean
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.BigOperators.Group.Finset import Mathlib.Algebra.GroupWithZero.Action.Defs import Mathlib.Data.Finset.Basic import Mathlib.Data.Multiset.Basic /-! # Lemmas about group actions on big operators Note that analogous lemmas for `Module`s like `Finset.sum_smul` appear in other files. -/ variable {α β γ : Type*} section variable [AddMonoid β] [DistribSMul α β] theorem List.smul_sum {r : α} {l : List β} : r • l.sum = (l.map (r • ·)).sum := map_list_sum (DistribSMul.toAddMonoidHom β r) l end section variable [Monoid α] [Monoid β] [MulDistribMulAction α β] theorem List.smul_prod {r : α} {l : List β} : r • l.prod = (l.map (r • ·)).prod := map_list_prod (MulDistribMulAction.toMonoidHom β r) l end section variable [AddCommMonoid β] [DistribSMul α β] theorem Multiset.smul_sum {r : α} {s : Multiset β} : r • s.sum = (s.map (r • ·)).sum := (DistribSMul.toAddMonoidHom β r).map_multiset_sum s theorem Finset.smul_sum {r : α} {f : γ → β} {s : Finset γ} : (r • ∑ x ∈ s, f x) = ∑ x ∈ s, r • f x := map_sum (DistribSMul.toAddMonoidHom β r) f s end section variable [Monoid α] [CommMonoid β] [MulDistribMulAction α β] theorem Multiset.smul_prod {r : α} {s : Multiset β} : r • s.prod = (s.map (r • ·)).prod := (MulDistribMulAction.toMonoidHom β r).map_multiset_prod s theorem Finset.smul_prod {r : α} {f : γ → β} {s : Finset γ} : (r • ∏ x ∈ s, f x) = ∏ x ∈ s, r • f x := map_prod (MulDistribMulAction.toMonoidHom β r) f s end
GroupTheory\GroupAction\Blocks.lean
/- Copyright (c) 2024 Antoine Chambert-Loir. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Antoine Chambert-Loir -/ import Mathlib.Data.Setoid.Partition import Mathlib.GroupTheory.GroupAction.Basic import Mathlib.GroupTheory.GroupAction.Pointwise import Mathlib.GroupTheory.GroupAction.SubMulAction /-! # Blocks Given `SMul G X`, an action of a type `G` on a type `X`, we define - the predicate `IsBlock G B` states that `B : Set X` is a block, which means that the sets `g • B`, for `g ∈ G`, are equal or disjoint. - a bunch of lemmas that give examples of “trivial” blocks : ⊥, ⊤, singletons, and non trivial blocks: orbit of the group, orbit of a normal subgroup… The non-existence of nontrivial blocks is the definition of primitive actions. ## References We follow [wieland1964]. -/ open scoped BigOperators Pointwise namespace MulAction section orbits variable {G : Type*} [Group G] {X : Type*} [MulAction G X] theorem orbit.eq_or_disjoint (a b : X) : orbit G a = orbit G b ∨ Disjoint (orbit G a) (orbit G b) := by apply (em (Disjoint (orbit G a) (orbit G b))).symm.imp _ id simp (config := { contextual := true }) only [Set.not_disjoint_iff, ← orbit_eq_iff, forall_exists_index, and_imp, eq_comm, implies_true] theorem orbit.pairwiseDisjoint : (Set.range fun x : X => orbit G x).PairwiseDisjoint id := by rintro s ⟨x, rfl⟩ t ⟨y, rfl⟩ h contrapose! h exact (orbit.eq_or_disjoint x y).resolve_right h /-- Orbits of an element form a partition -/ theorem IsPartition.of_orbits : Setoid.IsPartition (Set.range fun a : X => orbit G a) := by apply orbit.pairwiseDisjoint.isPartition_of_exists_of_ne_empty · intro x exact ⟨_, ⟨x, rfl⟩, mem_orbit_self x⟩ · rintro ⟨a, ha : orbit G a = ∅⟩ exact (MulAction.orbit_nonempty a).ne_empty ha end orbits section SMul variable (G : Type*) {X : Type*} [SMul G X] -- Change terminology : is_fully_invariant ? /-- For `SMul G X`, a fixed block is a `Set X` which is fully invariant: `g • B = B` for all `g : G` -/ def IsFixedBlock (B : Set X) := ∀ g : G, g • B = B /-- For `SMul G X`, an invariant block is a `Set X` which is stable: `g • B ⊆ B` for all `g : G` -/ def IsInvariantBlock (B : Set X) := ∀ g : G, g • B ⊆ B /-- A trivial block is a `Set X` which is either a subsingleton or ⊤ (it is not necessarily a block…) -/ def IsTrivialBlock (B : Set X) := B.Subsingleton ∨ B = ⊤ /-- `For SMul G X`, a block is a `Set X` whose translates are pairwise disjoint -/ def IsBlock (B : Set X) := (Set.range fun g : G => g • B).PairwiseDisjoint id variable {G} /-- A set B is a block iff for all g, g', the sets g • B and g' • B are either equal or disjoint -/ theorem IsBlock.def {B : Set X} : IsBlock G B ↔ ∀ g g' : G, g • B = g' • B ∨ Disjoint (g • B) (g' • B) := by apply Set.pairwiseDisjoint_range_iff /-- Alternate definition of a block -/ theorem IsBlock.mk_notempty {B : Set X} : IsBlock G B ↔ ∀ g g' : G, g • B ∩ g' • B ≠ ∅ → g • B = g' • B := by simp_rw [IsBlock.def, or_iff_not_imp_right, Set.disjoint_iff_inter_eq_empty] /-- A fixed block is a block -/ theorem IsFixedBlock.isBlock {B : Set X} (hfB : IsFixedBlock G B) : IsBlock G B := by simp [IsBlock.def, hfB _] variable (X) /-- The empty set is a block -/ theorem isBlock_empty : IsBlock G (⊥ : Set X) := by simp [IsBlock.def, Set.bot_eq_empty, Set.smul_set_empty] variable {X} theorem isBlock_singleton (a : X) : IsBlock G ({a} : Set X) := by simp [IsBlock.def, Classical.or_iff_not_imp_left] /-- Subsingletons are (trivial) blocks -/ theorem isBlock_subsingleton {B : Set X} (hB : B.Subsingleton) : IsBlock G B := hB.induction_on (isBlock_empty _) isBlock_singleton end SMul section Group variable {G : Type*} [Group G] {X : Type*} [MulAction G X] theorem IsBlock.smul_eq_or_disjoint {B : Set X} (hB : IsBlock G B) (g : G) : g • B = B ∨ Disjoint (g • B) B := by rw [IsBlock.def] at hB simpa only [one_smul] using hB g 1 theorem IsBlock.def_one {B : Set X} : IsBlock G B ↔ ∀ g : G, g • B = B ∨ Disjoint (g • B) B := by refine ⟨IsBlock.smul_eq_or_disjoint, ?_⟩ rw [IsBlock.def] intro hB g g' apply (hB (g'⁻¹ * g)).imp · rw [← smul_smul, ← eq_inv_smul_iff, inv_inv] exact id · intro h rw [Set.disjoint_iff] at h ⊢ rintro x hx suffices g'⁻¹ • x ∈ (g'⁻¹ * g) • B ∩ B by apply h this simp only [Set.mem_inter_iff, ← Set.mem_smul_set_iff_inv_smul_mem, ← smul_smul, smul_inv_smul] exact hx theorem IsBlock.mk_notempty_one {B : Set X} : IsBlock G B ↔ ∀ g : G, g • B ∩ B ≠ ∅ → g • B = B := by simp_rw [IsBlock.def_one, Set.disjoint_iff_inter_eq_empty, or_iff_not_imp_right] theorem IsBlock.mk_mem {B : Set X} : IsBlock G B ↔ ∀ (g : G) (a : X) (_ : a ∈ B) (_ : g • a ∈ B), g • B = B := by rw [IsBlock.mk_notempty_one] simp only [← Set.nonempty_iff_ne_empty, Set.nonempty_def, Set.mem_inter_iff, exists_imp, and_imp, Set.mem_smul_set_iff_inv_smul_mem] constructor · intro H g a ha hga apply H g (g • a) _ hga simpa only [inv_smul_smul] using ha · intro H g a ha hga rw [← eq_inv_smul_iff, eq_comm] exact H g⁻¹ a hga ha theorem IsBlock.def_mem {B : Set X} (hB : IsBlock G B) {a : X} {g : G} : a ∈ B → g • a ∈ B → g • B = B := IsBlock.mk_mem.mp hB g a theorem IsBlock.mk_subset {B : Set X} : IsBlock G B ↔ ∀ {g : G} {b : X} (_ : b ∈ B) (_ : b ∈ g • B), g • B ⊆ B := by simp_rw [IsBlock.mk_notempty_one, ← Set.nonempty_iff_ne_empty] constructor · intro hB g b hb hgb exact (hB g ⟨b, hgb, hb⟩).le · intro hB g ⟨b, hb', hb⟩ apply le_antisymm (hB hb hb') suffices g⁻¹ • B ≤ B by rw [Set.le_iff_subset] at this ⊢ rwa [← inv_inv g, ← Set.set_smul_subset_iff] exact hB (Set.mem_smul_set_iff_inv_smul_mem.mp hb') (Set.smul_mem_smul_set_iff.mpr hb) /-- An invariant block is a fixed block -/ theorem IsInvariantBlock.isFixedBlock {B : Set X} (hfB : IsInvariantBlock G B) : IsFixedBlock G B := by intro g apply le_antisymm (hfB g) intro x hx rw [Set.mem_smul_set_iff_inv_smul_mem] apply hfB g⁻¹ rwa [Set.smul_mem_smul_set_iff] /-- An invariant block is a block -/ theorem IsInvariantBlock.isBlock {B : Set X} (hfB : IsInvariantBlock G B) : IsBlock G B := hfB.isFixedBlock.isBlock /-- An orbit is a block -/ theorem isFixedBlock_orbit (a : X) : IsFixedBlock G (orbit G a) := (smul_orbit · a) /-- An orbit is a block -/ theorem isBlock_orbit (a : X) : IsBlock G (orbit G a) := (isFixedBlock_orbit a).isBlock variable (X) /-- The full set is a (trivial) block -/ theorem isFixedBlock_top : IsFixedBlock G (⊤ : Set X) := fun _ ↦ by simp only [Set.top_eq_univ, Set.smul_set_univ] /-- The full set is a (trivial) block -/ theorem isBlock_top : IsBlock G (⊤ : Set X) := (isFixedBlock_top _).isBlock variable {X} /-- Is `B` is a block for an action of `G`, it is a block for the action of any subgroup of `G` -/ theorem IsBlock.subgroup {H : Subgroup G} {B : Set X} (hfB : IsBlock G B) : IsBlock H B := by rw [IsBlock.def_one]; rintro ⟨g, _⟩ simpa only using hfB.smul_eq_or_disjoint g theorem IsBlock.preimage {H Y : Type*} [Group H] [MulAction H Y] {φ : H → G} (j : Y →ₑ[φ] X) {B : Set X} (hB : IsBlock G B) : IsBlock H (j ⁻¹' B) := by rw [IsBlock.def_one] intro g rw [← Group.preimage_smul_setₛₗ Y X φ j] apply (hB.smul_eq_or_disjoint (φ g)).imp · intro heq rw [heq] · exact Disjoint.preimage _ theorem IsBlock.image {H Y : Type*} [Group H] [MulAction H Y] {φ : G →* H} (j : X →ₑ[φ] Y) (hφ : Function.Surjective φ) (hj : Function.Injective j) {B : Set X} (hB : IsBlock G B) : IsBlock H (j '' B) := by rw [IsBlock.def] intro h h' obtain ⟨g, rfl⟩ := hφ h obtain ⟨g', rfl⟩ := hφ h' simp only [← image_smul_setₛₗ X Y φ j] cases' IsBlock.def.mp hB g g' with h h · left; rw [h] · right; exact Set.disjoint_image_of_injective hj h theorem IsBlock.subtype_val_preimage {C : SubMulAction G X} {B : Set X} (hB : IsBlock G B) : IsBlock G (Subtype.val ⁻¹' B : Set C) := hB.preimage C.inclusion theorem IsBlock.iff_subtype_val {C : SubMulAction G X} {B : Set C} : IsBlock G B ↔ IsBlock G (Subtype.val '' B : Set X) := by simp only [IsBlock.def_one] apply forall_congr' intro g rw [← SubMulAction.inclusion.coe_eq, ← image_smul_set _ _ _ C.inclusion g B, ← Set.image_eq_image Subtype.coe_injective] apply or_congr Iff.rfl simp only [Set.disjoint_iff, Set.subset_empty_iff, Set.image_eq_empty, ← C.inclusion_injective.injOn.image_inter (Set.subset_univ _) (Set.subset_univ _)] theorem IsBlock.iff_top (B : Set X) : IsBlock G B ↔ IsBlock (⊤ : Subgroup G) B := by simp only [IsBlock.def_one] constructor · intro h g; exact h g · intro h g; exact h ⟨g, Subgroup.mem_top g⟩ /-- The intersection of two blocks is a block -/ theorem IsBlock.inter {B₁ B₂ : Set X} (h₁ : IsBlock G B₁) (h₂ : IsBlock G B₂) : IsBlock G (B₁ ∩ B₂) := by rw [IsBlock.def_one] intro g rw [Set.smul_set_inter] cases' h₁.smul_eq_or_disjoint g with h₁ h₁ · cases' h₂.smul_eq_or_disjoint g with h₂ h₂ · left; rw [h₁, h₂] right apply Disjoint.inter_left'; apply Disjoint.inter_right' exact h₂ · right apply Disjoint.inter_left; apply Disjoint.inter_right exact h₁ /-- An intersection of blocks is a block -/ theorem IsBlock.iInter {ι : Type*} {B : ι → Set X} (hB : ∀ i : ι, IsBlock G (B i)) : IsBlock G (⋂ i, B i) := by by_cases hι : (IsEmpty ι) · -- ι = ∅, block = ⊤ suffices (⋂ i : ι, B i) = Set.univ by simpa only [this] using isBlock_top X simpa only [Set.top_eq_univ, Set.iInter_eq_univ] using (hι.elim' ·) rw [IsBlock.def_one] intro g rw [Set.smul_set_iInter] by_cases h : ∃ i : ι, Disjoint (g • B i) (B i) · right obtain ⟨j, hj⟩ := h refine Disjoint.mono ?_ ?_ hj <;> apply Set.iInter_subset · left simp only [not_exists] at h have : ∀ i : ι, g • B i = B i := fun i => ((hB i).smul_eq_or_disjoint g).resolve_right (h i) rw [Set.iInter_congr this] theorem IsBlock.of_subgroup_of_conjugate {B : Set X} {H : Subgroup G} (hB : IsBlock H B) (g : G) : IsBlock (Subgroup.map (MulEquiv.toMonoidHom (MulAut.conj g)) H) (g • B) := by rw [IsBlock.def_one] intro h' obtain ⟨h, hH, hh⟩ := Subgroup.mem_map.mp (SetLike.coe_mem h') simp only [MulEquiv.coe_toMonoidHom, MulAut.conj_apply] at hh suffices h' • g • B = g • h • B by simp only [this] apply (hB.smul_eq_or_disjoint ⟨h, hH⟩).imp · intro; congr · exact Set.disjoint_image_of_injective (MulAction.injective g) suffices (h' : G) • g • B = g • h • B by rw [← this]; rfl rw [← hh, smul_smul (g * h * g⁻¹) g B, smul_smul g h B, inv_mul_cancel_right] /-- A translate of a block is a block -/ theorem IsBlock.translate {B : Set X} (g : G) (hB : IsBlock G B) : IsBlock G (g • B) := by rw [IsBlock.iff_top] at hB ⊢ rw [← Subgroup.map_comap_eq_self_of_surjective (f := MulAut.conj g) (MulAut.conj g).surjective ⊤] apply IsBlock.of_subgroup_of_conjugate rwa [Subgroup.comap_top] variable (G) in /-- For `SMul G X`, a block system of `X` is a partition of `X` into blocks for the action of `G` -/ def IsBlockSystem (B : Set (Set X)) := Setoid.IsPartition B ∧ ∀ b : Set X, b ∈ B → IsBlock G b /-- Translates of a block form a `block_system` -/ theorem IsBlock.isBlockSystem [hGX : MulAction.IsPretransitive G X] {B : Set X} (hB : IsBlock G B) (hBe : B.Nonempty) : IsBlockSystem G (Set.range fun g : G => g • B) := by refine ⟨⟨?nonempty, ?cover⟩, ?mem_blocks⟩ case mem_blocks => rintro B' ⟨g, rfl⟩; exact hB.translate g · simp only [Set.mem_range, not_exists] intro g hg apply hBe.ne_empty simpa only [Set.smul_set_eq_empty] using hg · intro a obtain ⟨b : X, hb : b ∈ B⟩ := hBe obtain ⟨g, rfl⟩ := exists_smul_eq G b a use g • B simp only [Set.smul_mem_smul_set_iff, hb, exists_unique_iff_exists, Set.mem_range, exists_apply_eq_apply, exists_const, exists_prop, and_imp, forall_exists_index, forall_apply_eq_imp_iff, true_and] intro g' ha apply (IsBlock.def.mp hB g' g).resolve_right rw [Set.not_disjoint_iff] refine ⟨g • b, ha, ⟨b, hb, rfl⟩⟩ section Normal lemma smul_orbit_eq_orbit_smul (N : Subgroup G) [nN : N.Normal] (a : X) (g : G) : g • orbit N a = orbit N (g • a) := by simp only [orbit, Set.image_smul, Set.smul_set_range] ext simp only [Set.mem_range] constructor · rintro ⟨⟨k, hk⟩, rfl⟩ use ⟨g * k * g⁻¹, nN.conj_mem k hk g⟩ simp only [Submonoid.mk_smul] rw [smul_smul, inv_mul_cancel_right, ← smul_smul] · rintro ⟨⟨k, hk⟩, rfl⟩ use ⟨g⁻¹ * k * g, nN.conj_mem' k hk g⟩ simp only [Submonoid.mk_smul] simp only [← mul_assoc, ← smul_smul, smul_inv_smul, inv_inv] /-- An orbit of a normal subgroup is a block -/ theorem orbit.isBlock_of_normal {N : Subgroup G} [N.Normal] (a : X) : IsBlock G (orbit N a) := by rw [IsBlock.def_one] intro g rw [smul_orbit_eq_orbit_smul] apply orbit.eq_or_disjoint /-- The orbits of a normal subgroup form a block system -/ theorem IsBlockSystem.of_normal {N : Subgroup G} [N.Normal] : IsBlockSystem G (Set.range fun a : X => orbit N a) := by constructor · apply IsPartition.of_orbits · intro b; rintro ⟨a, rfl⟩ exact orbit.isBlock_of_normal a end Normal section Stabilizer /- For transitive actions, construction of the lattice equivalence `block_stabilizerOrderIso` between - blocks of `MulAction G X` containing a point `a ∈ X`, and - subgroups of G containing `stabilizer G a`. (Wielandt, th. 7.5) -/ /-- The orbit of `a` under a subgroup containing the stabilizer of `a` is a block -/ theorem IsBlock.of_orbit {H : Subgroup G} {a : X} (hH : stabilizer G a ≤ H) : IsBlock G (MulAction.orbit H a) := by simp_rw [IsBlock.def_one, or_iff_not_imp_right, Set.not_disjoint_iff] rintro g ⟨-, ⟨-, ⟨h₁, rfl⟩, h⟩, ⟨h₂, rfl⟩⟩ suffices g ∈ H by rw [← Subgroup.coe_mk H g this, ← H.smul_def, smul_orbit (⟨g, this⟩ : H) a] rw [← mul_mem_cancel_left h₂⁻¹.2, ← mul_mem_cancel_right h₁.2] apply hH simp only [mem_stabilizer_iff, InvMemClass.coe_inv, mul_smul, inv_smul_eq_iff] exact h /-- If `B` is a block containing `a`, then the stabilizer of `B` contains the stabilizer of `a` -/ theorem IsBlock.stabilizer_le {B : Set X} (hB : IsBlock G B) {a : X} (ha : a ∈ B) : stabilizer G a ≤ stabilizer G B := by intro g hg apply Or.resolve_right (hB.smul_eq_or_disjoint g) rw [Set.not_disjoint_iff] refine ⟨a, ?_, ha⟩ rw [← hg, Set.smul_mem_smul_set_iff] exact ha /-- A block containing `a` is the orbit of `a` under its stabilizer -/ theorem IsBlock.orbit_stabilizer_eq [htGX : IsPretransitive G X] {B : Set X} (hB : IsBlock G B) {a : X} (ha : a ∈ B) : MulAction.orbit (stabilizer G B) a = B := by ext x constructor · rintro ⟨⟨k, k_mem⟩, rfl⟩ simp only [Submonoid.mk_smul] rw [← k_mem, Set.smul_mem_smul_set_iff] exact ha · intro hx obtain ⟨k, rfl⟩ := exists_smul_eq G a x exact ⟨⟨k, hB.def_mem ha hx⟩, rfl⟩ /-- A subgroup containing the stabilizer of `a` is the stabilizer of the orbit of `a` under that subgroup -/ theorem stabilizer_orbit_eq {a : X} {H : Subgroup G} (hH : stabilizer G a ≤ H) : stabilizer G (orbit H a) = H := by ext g constructor · intro hg obtain ⟨-, ⟨b, rfl⟩, h⟩ := hg.symm ▸ mem_orbit_self a simp_rw [H.smul_def, ← mul_smul, ← mem_stabilizer_iff] at h exact (mul_mem_cancel_right b.2).mp (hH h) · intro hg rw [mem_stabilizer_iff, ← Subgroup.coe_mk H g hg, ← Submonoid.smul_def] apply smul_orbit variable (G) /-- Order equivalence between blocks in `X` containing a point `a` and subgroups of `G` containing the stabilizer of `a` (Wielandt, th. 7.5)-/ def block_stabilizerOrderIso [htGX : IsPretransitive G X] (a : X) : { B : Set X // a ∈ B ∧ IsBlock G B } ≃o Set.Ici (stabilizer G a) where toFun := fun ⟨B, ha, hB⟩ => ⟨stabilizer G B, hB.stabilizer_le ha⟩ invFun := fun ⟨H, hH⟩ => ⟨MulAction.orbit H a, MulAction.mem_orbit_self a, IsBlock.of_orbit hH⟩ left_inv := fun ⟨B, ha, hB⟩ => (id (propext Subtype.mk_eq_mk)).mpr (hB.orbit_stabilizer_eq ha) right_inv := fun ⟨H, hH⟩ => (id (propext Subtype.mk_eq_mk)).mpr (stabilizer_orbit_eq hH) map_rel_iff' := by rintro ⟨B, ha, hB⟩; rintro ⟨B', ha', hB'⟩ simp only [Equiv.coe_fn_mk, Subtype.mk_le_mk, Set.le_eq_subset] constructor · rintro hBB' b hb obtain ⟨k, rfl⟩ := htGX.exists_smul_eq a b suffices k ∈ stabilizer G B' by exact this.symm ▸ (Set.smul_mem_smul_set ha') exact hBB' (hB.def_mem ha hb) · intro hBB' g hgB apply IsBlock.def_mem hB' ha' exact hBB' <| hgB.symm ▸ (Set.smul_mem_smul_set ha) end Stabilizer end Group end MulAction
GroupTheory\GroupAction\ConjAct.lean
/- Copyright (c) 2021 . All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Algebra.Field.Defs import Mathlib.Algebra.Group.Subgroup.ZPowers import Mathlib.Algebra.Ring.Action.Basic import Mathlib.GroupTheory.GroupAction.Basic /-! # Conjugation action of a group on itself This file defines the conjugation action of a group on itself. See also `MulAut.conj` for the definition of conjugation as a homomorphism into the automorphism group. ## Main definitions A type alias `ConjAct G` is introduced for a group `G`. The group `ConjAct G` acts on `G` by conjugation. The group `ConjAct G` also acts on any normal subgroup of `G` by conjugation. As a generalization, this also allows: * `ConjAct Mˣ` to act on `M`, when `M` is a `Monoid` * `ConjAct G₀` to act on `G₀`, when `G₀` is a `GroupWithZero` ## Implementation Notes The scalar action in defined in this file can also be written using `MulAut.conj g • h`. This has the advantage of not using the type alias `ConjAct`, but the downside of this approach is that some theorems about the group actions will not apply when since this `MulAut.conj g • h` describes an action of `MulAut G` on `G`, and not an action of `G`. -/ variable (α M G G₀ R K : Type*) /-- A type alias for a group `G`. `ConjAct G` acts on `G` by conjugation -/ def ConjAct : Type _ := G namespace ConjAct open MulAction Subgroup variable {M G G₀ R K} instance [Group G] : Group (ConjAct G) := ‹Group G› instance [DivInvMonoid G] : DivInvMonoid (ConjAct G) := ‹DivInvMonoid G› instance [GroupWithZero G] : GroupWithZero (ConjAct G) := ‹GroupWithZero G› instance [Fintype G] : Fintype (ConjAct G) := ‹Fintype G› @[simp] theorem card [Fintype G] : Fintype.card (ConjAct G) = Fintype.card G := rfl section DivInvMonoid variable [DivInvMonoid G] instance : Inhabited (ConjAct G) := ⟨1⟩ /-- Reinterpret `g : ConjAct G` as an element of `G`. -/ def ofConjAct : ConjAct G ≃* G where toFun := id invFun := id left_inv := fun _ => rfl right_inv := fun _ => rfl map_mul' := fun _ _ => rfl /-- Reinterpret `g : G` as an element of `ConjAct G`. -/ def toConjAct : G ≃* ConjAct G := ofConjAct.symm /-- A recursor for `ConjAct`, for use as `induction x` when `x : ConjAct G`. -/ @[elab_as_elim, cases_eliminator, induction_eliminator] protected def rec {C : ConjAct G → Sort*} (h : ∀ g, C (toConjAct g)) : ∀ g, C g := h @[simp] theorem «forall» (p : ConjAct G → Prop) : (∀ x : ConjAct G, p x) ↔ ∀ x : G, p (toConjAct x) := id Iff.rfl @[simp] theorem of_mul_symm_eq : (@ofConjAct G _).symm = toConjAct := rfl @[simp] theorem to_mul_symm_eq : (@toConjAct G _).symm = ofConjAct := rfl @[simp] theorem toConjAct_ofConjAct (x : ConjAct G) : toConjAct (ofConjAct x) = x := rfl @[simp] theorem ofConjAct_toConjAct (x : G) : ofConjAct (toConjAct x) = x := rfl -- Porting note (#11119): removed `simp` attribute because `simpNF` says it can prove it theorem ofConjAct_one : ofConjAct (1 : ConjAct G) = 1 := rfl -- Porting note (#11119): removed `simp` attribute because `simpNF` says it can prove it theorem toConjAct_one : toConjAct (1 : G) = 1 := rfl @[simp] theorem ofConjAct_inv (x : ConjAct G) : ofConjAct x⁻¹ = (ofConjAct x)⁻¹ := rfl @[simp] theorem toConjAct_inv (x : G) : toConjAct x⁻¹ = (toConjAct x)⁻¹ := rfl -- Porting note (#11119): removed `simp` attribute because `simpNF` says it can prove it theorem ofConjAct_mul (x y : ConjAct G) : ofConjAct (x * y) = ofConjAct x * ofConjAct y := rfl -- Porting note (#11119): removed `simp` attribute because `simpNF` says it can prove it theorem toConjAct_mul (x y : G) : toConjAct (x * y) = toConjAct x * toConjAct y := rfl instance : SMul (ConjAct G) G where smul g h := ofConjAct g * h * (ofConjAct g)⁻¹ theorem smul_def (g : ConjAct G) (h : G) : g • h = ofConjAct g * h * (ofConjAct g)⁻¹ := rfl theorem toConjAct_smul (g h : G) : toConjAct g • h = g * h * g⁻¹ := rfl end DivInvMonoid section Units section Monoid variable [Monoid M] instance unitsScalar : SMul (ConjAct Mˣ) M where smul g h := ofConjAct g * h * ↑(ofConjAct g)⁻¹ theorem units_smul_def (g : ConjAct Mˣ) (h : M) : g • h = ofConjAct g * h * ↑(ofConjAct g)⁻¹ := rfl -- porting note (#11083): very slow without `simp only` and need to separate `units_smul_def` -- so that things trigger appropriately instance unitsMulDistribMulAction : MulDistribMulAction (ConjAct Mˣ) M where one_smul := by simp only [units_smul_def, ofConjAct_one, Units.val_one, one_mul, inv_one, mul_one, forall_const] mul_smul := by simp only [units_smul_def] simp only [map_mul, Units.val_mul, mul_assoc, mul_inv_rev, forall_const, «forall»] smul_mul := by simp only [units_smul_def] simp only [mul_assoc, Units.inv_mul_cancel_left, forall_const, «forall»] smul_one := by simp [units_smul_def, mul_one, Units.mul_inv, «forall», forall_const] instance unitsSMulCommClass [SMul α M] [SMulCommClass α M M] [IsScalarTower α M M] : SMulCommClass α (ConjAct Mˣ) M where smul_comm a um m := by rw [units_smul_def, units_smul_def, mul_smul_comm, smul_mul_assoc] instance unitsSMulCommClass' [SMul α M] [SMulCommClass M α M] [IsScalarTower α M M] : SMulCommClass (ConjAct Mˣ) α M := haveI : SMulCommClass α M M := SMulCommClass.symm _ _ _ SMulCommClass.symm _ _ _ end Monoid section Semiring variable [Semiring R] -- porting note (#11083): very slow without `simp only` and need to separate `units_smul_def` -- so that things trigger appropriately instance unitsMulSemiringAction : MulSemiringAction (ConjAct Rˣ) R := { ConjAct.unitsMulDistribMulAction with smul_zero := by simp only [units_smul_def, mul_zero, zero_mul, «forall», forall_const] smul_add := by simp only [units_smul_def] simp only [mul_add, add_mul, forall_const, «forall»] } end Semiring end Units section GroupWithZero variable [GroupWithZero G₀] -- Porting note (#11119): removed `simp` attribute because `simpNF` says it can prove it theorem ofConjAct_zero : ofConjAct (0 : ConjAct G₀) = 0 := rfl -- Porting note (#11119): removed `simp` attribute because `simpNF` says it can prove it theorem toConjAct_zero : toConjAct (0 : G₀) = 0 := rfl -- porting note (#11083): very slow without `simp only` and need to separate `smul_def` -- so that things trigger appropriately instance mulAction₀ : MulAction (ConjAct G₀) G₀ where one_smul := by simp only [smul_def] simp only [map_one, one_mul, inv_one, mul_one, forall_const] mul_smul := by simp only [smul_def] simp only [map_mul, mul_assoc, mul_inv_rev, forall_const, «forall»] instance smulCommClass₀ [SMul α G₀] [SMulCommClass α G₀ G₀] [IsScalarTower α G₀ G₀] : SMulCommClass α (ConjAct G₀) G₀ where smul_comm a ug g := by rw [smul_def, smul_def, mul_smul_comm, smul_mul_assoc] instance smulCommClass₀' [SMul α G₀] [SMulCommClass G₀ α G₀] [IsScalarTower α G₀ G₀] : SMulCommClass (ConjAct G₀) α G₀ := haveI := SMulCommClass.symm G₀ α G₀ SMulCommClass.symm _ _ _ end GroupWithZero section DivisionRing variable [DivisionRing K] -- porting note (#11083): very slow without `simp only` and need to separate `smul_def` -- so that things trigger appropriately instance distribMulAction₀ : DistribMulAction (ConjAct K) K := { ConjAct.mulAction₀ with smul_zero := by simp only [smul_def] simp only [mul_zero, zero_mul, «forall», forall_const] smul_add := by simp only [smul_def] simp only [mul_add, add_mul, forall_const, «forall»] } end DivisionRing variable [Group G] -- todo: this file is not in good order; I will refactor this after the PR -- porting note (#11083): very slow without `simp only` and need to separate `smul_def` -- so that things trigger appropriately instance : MulDistribMulAction (ConjAct G) G where smul_mul := by simp only [smul_def] simp only [mul_assoc, inv_mul_cancel_left, forall_const, «forall»] smul_one := by simp only [smul_def, mul_one, mul_right_inv, «forall», forall_const] one_smul := by simp only [smul_def, ofConjAct_one, one_mul, inv_one, mul_one, forall_const] mul_smul := by simp only [smul_def] simp only [map_mul, mul_assoc, mul_inv_rev, forall_const, «forall»] instance smulCommClass [SMul α G] [SMulCommClass α G G] [IsScalarTower α G G] : SMulCommClass α (ConjAct G) G where smul_comm a ug g := by rw [smul_def, smul_def, mul_smul_comm, smul_mul_assoc] instance smulCommClass' [SMul α G] [SMulCommClass G α G] [IsScalarTower α G G] : SMulCommClass (ConjAct G) α G := haveI := SMulCommClass.symm G α G SMulCommClass.symm _ _ _ theorem smul_eq_mulAut_conj (g : ConjAct G) (h : G) : g • h = MulAut.conj (ofConjAct g) h := rfl /-- The set of fixed points of the conjugation action of `G` on itself is the center of `G`. -/ theorem fixedPoints_eq_center : fixedPoints (ConjAct G) G = center G := by ext x simp [mem_center_iff, smul_def, mul_inv_eq_iff_eq_mul] @[simp] theorem mem_orbit_conjAct {g h : G} : g ∈ orbit (ConjAct G) h ↔ IsConj g h := by rw [isConj_comm, isConj_iff, mem_orbit_iff]; rfl theorem orbitRel_conjAct : (orbitRel (ConjAct G) G).Rel = IsConj := funext₂ fun g h => by rw [orbitRel_apply, mem_orbit_conjAct] theorem orbit_eq_carrier_conjClasses (g : G) : orbit (ConjAct G) g = (ConjClasses.mk g).carrier := by ext h rw [ConjClasses.mem_carrier_iff_mk_eq, ConjClasses.mk_eq_mk_iff_isConj, mem_orbit_conjAct] theorem stabilizer_eq_centralizer (g : G) : stabilizer (ConjAct G) g = centralizer (zpowers (toConjAct g) : Set (ConjAct G)) := le_antisymm (le_centralizer_iff.mp (zpowers_le.mpr fun _ => mul_inv_eq_iff_eq_mul.mp)) fun _ h => mul_inv_eq_of_eq_mul (h g (mem_zpowers g)).symm /-- As normal subgroups are closed under conjugation, they inherit the conjugation action of the underlying group. -/ instance Subgroup.conjAction {H : Subgroup G} [hH : H.Normal] : SMul (ConjAct G) H := ⟨fun g h => ⟨g • (h : G), hH.conj_mem h.1 h.2 (ofConjAct g)⟩⟩ theorem Subgroup.val_conj_smul {H : Subgroup G} [H.Normal] (g : ConjAct G) (h : H) : ↑(g • h) = g • (h : G) := rfl instance Subgroup.conjMulDistribMulAction {H : Subgroup G} [H.Normal] : MulDistribMulAction (ConjAct G) H := Subtype.coe_injective.mulDistribMulAction H.subtype Subgroup.val_conj_smul /-- Group conjugation on a normal subgroup. Analogous to `MulAut.conj`. -/ def _root_.MulAut.conjNormal {H : Subgroup G} [H.Normal] : G →* MulAut H := (MulDistribMulAction.toMulAut (ConjAct G) H).comp toConjAct.toMonoidHom @[simp] theorem _root_.MulAut.conjNormal_apply {H : Subgroup G} [H.Normal] (g : G) (h : H) : ↑(MulAut.conjNormal g h) = g * h * g⁻¹ := rfl @[simp] theorem _root_.MulAut.conjNormal_symm_apply {H : Subgroup G} [H.Normal] (g : G) (h : H) : ↑((MulAut.conjNormal g).symm h) = g⁻¹ * h * g := by change _ * _⁻¹⁻¹ = _ rw [inv_inv] rfl @[simp] theorem _root_.MulAut.conjNormal_inv_apply {H : Subgroup G} [H.Normal] (g : G) (h : H) : ↑((MulAut.conjNormal g)⁻¹ h) = g⁻¹ * h * g := MulAut.conjNormal_symm_apply g h theorem _root_.MulAut.conjNormal_val {H : Subgroup G} [H.Normal] {h : H} : MulAut.conjNormal ↑h = MulAut.conj h := MulEquiv.ext fun _ => rfl instance normal_of_characteristic_of_normal {H : Subgroup G} [hH : H.Normal] {K : Subgroup H} [h : K.Characteristic] : (K.map H.subtype).Normal := ⟨fun a ha b => by obtain ⟨a, ha, rfl⟩ := ha exact K.apply_coe_mem_map H.subtype ⟨_, (SetLike.ext_iff.mp (h.fixed (MulAut.conjNormal b)) a).mpr ha⟩⟩ end ConjAct section Units variable [Monoid M] /-- The stabilizer of `Mˣ` acting on itself by conjugation at `x : Mˣ` is exactly the units of the centralizer of `x : M`. -/ @[simps! apply_coe_val symm_apply_val_coe] def unitsCentralizerEquiv (x : Mˣ) : (Submonoid.centralizer ({↑x} : Set M))ˣ ≃* MulAction.stabilizer (ConjAct Mˣ) x := MulEquiv.symm { toFun := MonoidHom.toHomUnits <| { toFun := fun u ↦ ⟨↑(ConjAct.ofConjAct u.1 : Mˣ), by rintro x ⟨rfl⟩ have : (u : ConjAct Mˣ) • x = x := u.2 rwa [ConjAct.smul_def, mul_inv_eq_iff_eq_mul, Units.ext_iff, eq_comm] at this⟩, map_one' := rfl, map_mul' := fun a b ↦ rfl } invFun := fun u ↦ ⟨ConjAct.toConjAct (Units.map (Submonoid.centralizer ({↑x} : Set M)).subtype u), by change _ • _ = _ simp only [ConjAct.smul_def, ConjAct.ofConjAct_toConjAct, mul_inv_eq_iff_eq_mul] exact Units.ext <| (u.1.2 x <| Set.mem_singleton _).symm⟩ left_inv := fun _ ↦ by ext; rfl right_inv := fun _ ↦ by ext; rfl map_mul' := map_mul _ } end Units
GroupTheory\GroupAction\Embedding.lean
/- Copyright (c) 2022 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.Group.Action.Basic import Mathlib.Algebra.Group.Action.Pi /-! # Group actions on embeddings This file provides a `MulAction G (α ↪ β)` instance that agrees with the `MulAction G (α → β)` instances defined by `Pi.mulAction`. Note that unlike the `Pi` instance, this requires `G` to be a group. -/ universe u v w variable {G G' α β : Type*} namespace Function.Embedding @[to_additive] instance smul [Group G] [MulAction G β] : SMul G (α ↪ β) := ⟨fun g f => f.trans (MulAction.toPerm g).toEmbedding⟩ @[to_additive] theorem smul_def [Group G] [MulAction G β] (g : G) (f : α ↪ β) : g • f = f.trans (MulAction.toPerm g).toEmbedding := rfl @[to_additive (attr := simp)] theorem smul_apply [Group G] [MulAction G β] (g : G) (f : α ↪ β) (a : α) : (g • f) a = g • f a := rfl @[to_additive] theorem coe_smul [Group G] [MulAction G β] (g : G) (f : α ↪ β) : ⇑(g • f) = g • ⇑f := rfl instance [Group G] [Group G'] [SMul G G'] [MulAction G β] [MulAction G' β] [IsScalarTower G G' β] : IsScalarTower G G' (α ↪ β) := ⟨fun x y z => Function.Embedding.ext fun i => smul_assoc x y (z i)⟩ @[to_additive] instance [Group G] [Group G'] [MulAction G β] [MulAction G' β] [SMulCommClass G G' β] : SMulCommClass G G' (α ↪ β) := ⟨fun x y z => Function.Embedding.ext fun i => smul_comm x y (z i)⟩ instance [Group G] [MulAction G β] [MulAction Gᵐᵒᵖ β] [IsCentralScalar G β] : IsCentralScalar G (α ↪ β) := ⟨fun _ _ => Function.Embedding.ext fun _ => op_smul_eq_smul _ _⟩ @[to_additive] instance [Group G] [MulAction G β] : MulAction G (α ↪ β) := DFunLike.coe_injective.mulAction _ coe_smul end Function.Embedding
GroupTheory\GroupAction\FixedPoints.lean
/- Copyright (c) 2024 Emilie Burgun. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Emilie Burgun -/ import Mathlib.Algebra.Group.Commute.Basic import Mathlib.GroupTheory.GroupAction.Basic import Mathlib.Dynamics.PeriodicPts import Mathlib.Data.Set.Pointwise.SMul /-! # Properties of `fixedPoints` and `fixedBy` This module contains some useful properties of `MulAction.fixedPoints` and `MulAction.fixedBy` that don't directly belong to `Mathlib.GroupTheory.GroupAction.Basic`. ## Main theorems * `MulAction.fixedBy_mul`: `fixedBy α (g * h) ⊆ fixedBy α g ∪ fixedBy α h` * `MulAction.fixedBy_conj` and `MulAction.smul_fixedBy`: the pointwise group action of `h` on `fixedBy α g` is equal to the `fixedBy` set of the conjugation of `h` with `g` (`fixedBy α (h * g * h⁻¹)`). * `MulAction.set_mem_fixedBy_of_movedBy_subset` shows that if a set `s` is a superset of `(fixedBy α g)ᶜ`, then the group action of `g` cannot send elements of `s` outside of `s`. This is expressed as `s ∈ fixedBy (Set α) g`, and `MulAction.set_mem_fixedBy_iff` allows one to convert the relationship back to `g • x ∈ s ↔ x ∈ s`. * `MulAction.not_commute_of_disjoint_smul_movedBy` allows one to prove that `g` and `h` do not commute from the disjointness of the `(fixedBy α g)ᶜ` set and `h • (fixedBy α g)ᶜ`, which is a property used in the proof of Rubin's theorem. The theorems above are also available for `AddAction`. ## Pointwise group action and `fixedBy (Set α) g` Since `fixedBy α g = { x | g • x = x }` by definition, properties about the pointwise action of a set `s : Set α` can be expressed using `fixedBy (Set α) g`. To properly use theorems using `fixedBy (Set α) g`, you should `open Pointwise` in your file. `s ∈ fixedBy (Set α) g` means that `g • s = s`, which is equivalent to say that `∀ x, g • x ∈ s ↔ x ∈ s` (the translation can be done using `MulAction.set_mem_fixedBy_iff`). `s ∈ fixedBy (Set α) g` is a weaker statement than `s ⊆ fixedBy α g`: the latter requires that all points in `s` are fixed by `g`, whereas the former only requires that `g • x ∈ s`. -/ namespace MulAction open Pointwise variable {α : Type*} variable {G : Type*} [Group G] [MulAction G α] variable {M : Type*} [Monoid M] [MulAction M α] section FixedPoints variable (α) in /-- In a multiplicative group action, the points fixed by `g` are also fixed by `g⁻¹` -/ @[to_additive (attr := simp) "In an additive group action, the points fixed by `g` are also fixed by `g⁻¹`"] theorem fixedBy_inv (g : G) : fixedBy α g⁻¹ = fixedBy α g := by ext rw [mem_fixedBy, mem_fixedBy, inv_smul_eq_iff, eq_comm] @[to_additive] theorem smul_mem_fixedBy_iff_mem_fixedBy {a : α} {g : G} : g • a ∈ fixedBy α g ↔ a ∈ fixedBy α g := by rw [mem_fixedBy, smul_left_cancel_iff] rfl @[to_additive] theorem smul_inv_mem_fixedBy_iff_mem_fixedBy {a : α} {g : G} : g⁻¹ • a ∈ fixedBy α g ↔ a ∈ fixedBy α g := by rw [← fixedBy_inv, smul_mem_fixedBy_iff_mem_fixedBy, fixedBy_inv] @[to_additive minimalPeriod_eq_one_iff_fixedBy] theorem minimalPeriod_eq_one_iff_fixedBy {a : α} {g : G} : Function.minimalPeriod (fun x => g • x) a = 1 ↔ a ∈ fixedBy α g := Function.minimalPeriod_eq_one_iff_isFixedPt variable (α) in @[to_additive] theorem fixedBy_subset_fixedBy_zpow (g : G) (j : ℤ) : fixedBy α g ⊆ fixedBy α (g ^ j) := by intro a a_in_fixedBy rw [mem_fixedBy, zpow_smul_eq_iff_minimalPeriod_dvd, minimalPeriod_eq_one_iff_fixedBy.mpr a_in_fixedBy, Nat.cast_one] exact one_dvd j variable (M α) in @[to_additive (attr := simp)] theorem fixedBy_one_eq_univ : fixedBy α (1 : M) = Set.univ := Set.eq_univ_iff_forall.mpr <| one_smul M variable (α) in @[to_additive] theorem fixedBy_mul (m₁ m₂ : M) : fixedBy α m₁ ∩ fixedBy α m₂ ⊆ fixedBy α (m₁ * m₂) := by intro a ⟨h₁, h₂⟩ rw [mem_fixedBy, mul_smul, h₂, h₁] variable (α) in @[to_additive] theorem smul_fixedBy (g h : G) : h • fixedBy α g = fixedBy α (h * g * h⁻¹) := by ext a simp_rw [Set.mem_smul_set_iff_inv_smul_mem, mem_fixedBy, mul_smul, smul_eq_iff_eq_inv_smul h] end FixedPoints section Pointwise /-! ### `fixedBy` sets of the pointwise group action The theorems below need the `Pointwise` scoped to be opened (using `open Pointwise`) to be used effectively. -/ /-- If a set `s : Set α` is in `fixedBy (Set α) g`, then all points of `s` will stay in `s` after being moved by `g`. -/ @[to_additive "If a set `s : Set α` is in `fixedBy (Set α) g`, then all points of `s` will stay in `s` after being moved by `g`."] theorem set_mem_fixedBy_iff (s : Set α) (g : G) : s ∈ fixedBy (Set α) g ↔ ∀ x, g • x ∈ s ↔ x ∈ s := by simp_rw [mem_fixedBy, ← eq_inv_smul_iff, Set.ext_iff, Set.mem_inv_smul_set_iff, Iff.comm] theorem smul_mem_of_set_mem_fixedBy {s : Set α} {g : G} (s_in_fixedBy : s ∈ fixedBy (Set α) g) {x : α} : g • x ∈ s ↔ x ∈ s := (set_mem_fixedBy_iff s g).mp s_in_fixedBy x /-- If `s ⊆ fixedBy α g`, then `g • s = s`, which means that `s ∈ fixedBy (Set α) g`. Note that the reverse implication is in general not true, as `s ∈ fixedBy (Set α) g` is a weaker statement (it allows for points `x ∈ s` for which `g • x ≠ x` and `g • x ∈ s`). -/ @[to_additive "If `s ⊆ fixedBy α g`, then `g +ᵥ s = s`, which means that `s ∈ fixedBy (Set α) g`. Note that the reverse implication is in general not true, as `s ∈ fixedBy (Set α) g` is a weaker statement (it allows for points `x ∈ s` for which `g +ᵥ x ≠ x` and `g +ᵥ x ∈ s`)."] theorem set_mem_fixedBy_of_subset_fixedBy {s : Set α} {g : G} (s_ss_fixedBy : s ⊆ fixedBy α g) : s ∈ fixedBy (Set α) g := by rw [← fixedBy_inv] ext x rw [Set.mem_inv_smul_set_iff] refine ⟨fun gxs => ?xs, fun xs => (s_ss_fixedBy xs).symm ▸ xs⟩ rw [← fixedBy_inv] at s_ss_fixedBy rwa [← s_ss_fixedBy gxs, inv_smul_smul] at gxs theorem smul_subset_of_set_mem_fixedBy {s t : Set α} {g : G} (t_ss_s : t ⊆ s) (s_in_fixedBy : s ∈ fixedBy (Set α) g) : g • t ⊆ s := (Set.set_smul_subset_set_smul_iff.mpr t_ss_s).trans s_in_fixedBy.subset /-! If a set `s : Set α` is a superset of `(MulAction.fixedBy α g)ᶜ` (resp. `(AddAction.fixedBy α g)ᶜ`), then no point or subset of `s` can be moved outside of `s` by the group action of `g`. -/ /-- If `(fixedBy α g)ᶜ ⊆ s`, then `g` cannot move a point of `s` outside of `s`. -/ @[to_additive "If `(fixedBy α g)ᶜ ⊆ s`, then `g` cannot move a point of `s` outside of `s`."] theorem set_mem_fixedBy_of_movedBy_subset {s : Set α} {g : G} (s_subset : (fixedBy α g)ᶜ ⊆ s) : s ∈ fixedBy (Set α) g := by rw [← fixedBy_inv] ext a rw [Set.mem_inv_smul_set_iff] by_cases a ∈ fixedBy α g case pos a_fixed => rw [a_fixed] case neg a_moved => constructor <;> (intro; apply s_subset) · exact a_moved · rwa [Set.mem_compl_iff, smul_mem_fixedBy_iff_mem_fixedBy] end Pointwise section Commute /-! ## Pointwise image of the `fixedBy` set by a commuting group element If two group elements `g` and `h` commute, then `g` fixes `h • x` (resp. `h +ᵥ x`) if and only if `g` fixes `x`. This is equivalent to say that if `Commute g h`, then `fixedBy α g ∈ fixedBy (Set α) h` and `(fixedBy α g)ᶜ ∈ fixedBy (Set α) h`. -/ /-- If `g` and `h` commute, then `g` fixes `h • x` iff `g` fixes `x`. This is equivalent to say that the set `fixedBy α g` is fixed by `h`. -/ @[to_additive "If `g` and `h` commute, then `g` fixes `h +ᵥ x` iff `g` fixes `x`. This is equivalent to say that the set `fixedBy α g` is fixed by `h`. "] theorem fixedBy_mem_fixedBy_of_commute {g h : G} (comm : Commute g h) : (fixedBy α g) ∈ fixedBy (Set α) h := by ext x rw [Set.mem_smul_set_iff_inv_smul_mem, mem_fixedBy, ← mul_smul, comm.inv_right, mul_smul, smul_left_cancel_iff, mem_fixedBy] /-- If `g` and `h` commute, then `g` fixes `(h ^ j) • x` iff `g` fixes `x`. -/ @[to_additive "If `g` and `h` commute, then `g` fixes `(j • h) +ᵥ x` iff `g` fixes `x`."] theorem smul_zpow_fixedBy_eq_of_commute {g h : G} (comm : Commute g h) (j : ℤ) : h ^ j • fixedBy α g = fixedBy α g := fixedBy_subset_fixedBy_zpow (Set α) h j (fixedBy_mem_fixedBy_of_commute comm) /-- If `g` and `h` commute, then `g` moves `h • x` iff `g` moves `x`. This is equivalent to say that the set `(fixedBy α g)ᶜ` is fixed by `h`. -/ @[to_additive "If `g` and `h` commute, then `g` moves `h +ᵥ x` iff `g` moves `x`. This is equivalent to say that the set `(fixedBy α g)ᶜ` is fixed by `h`."] theorem movedBy_mem_fixedBy_of_commute {g h : G} (comm : Commute g h) : (fixedBy α g)ᶜ ∈ fixedBy (Set α) h := by rw [mem_fixedBy, Set.smul_set_compl, fixedBy_mem_fixedBy_of_commute comm] /-- If `g` and `h` commute, then `g` moves `h ^ j • x` iff `g` moves `x`. -/ @[to_additive "If `g` and `h` commute, then `g` moves `(j • h) +ᵥ x` iff `g` moves `x`."] theorem smul_zpow_movedBy_eq_of_commute {g h : G} (comm : Commute g h) (j : ℤ) : h ^ j • (fixedBy α g)ᶜ = (fixedBy α g)ᶜ := fixedBy_subset_fixedBy_zpow (Set α) h j (movedBy_mem_fixedBy_of_commute comm) end Commute section Faithful variable [FaithfulSMul G α] variable [FaithfulSMul M α] /-- If the multiplicative action of `M` on `α` is faithful, then `fixedBy α m = Set.univ` implies that `m = 1`. -/ @[to_additive "If the additive action of `M` on `α` is faithful, then `fixedBy α m = Set.univ` implies that `m = 1`."] theorem fixedBy_eq_univ_iff_eq_one {m : M} : fixedBy α m = Set.univ ↔ m = 1 := by rw [← (smul_left_injective' (M := M) (α := α)).eq_iff, Set.eq_univ_iff_forall] simp_rw [Function.funext_iff, one_smul, mem_fixedBy] /-- If the image of the `(fixedBy α g)ᶜ` set by the pointwise action of `h: G` is disjoint from `(fixedBy α g)ᶜ`, then `g` and `h` cannot commute. -/ @[to_additive "If the image of the `(fixedBy α g)ᶜ` set by the pointwise action of `h: G` is disjoint from `(fixedBy α g)ᶜ`, then `g` and `h` cannot commute."] theorem not_commute_of_disjoint_movedBy_preimage {g h : G} (ne_one : g ≠ 1) (disjoint : Disjoint (fixedBy α g)ᶜ (h • (fixedBy α g)ᶜ)) : ¬Commute g h := by contrapose! ne_one with comm rwa [movedBy_mem_fixedBy_of_commute comm, disjoint_self, Set.bot_eq_empty, ← Set.compl_univ, compl_inj_iff, fixedBy_eq_univ_iff_eq_one] at disjoint end Faithful end MulAction
GroupTheory\GroupAction\FixingSubgroup.lean
/- Copyright (c) 2022 Antoine Chambert-Loir. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Antoine Chambert-Loir -/ import Mathlib.Algebra.Group.Subgroup.Actions import Mathlib.GroupTheory.GroupAction.Basic import Mathlib.GroupTheory.GroupAction.FixedPoints /-! # Fixing submonoid, fixing subgroup of an action In the presence of an action of a monoid or a group, this file defines the fixing submonoid or the fixing subgroup, and relates it to the set of fixed points via a Galois connection. ## Main definitions * `fixingSubmonoid M s` : in the presence of `MulAction M α` (with `Monoid M`) it is the `Submonoid M` consisting of elements which fix `s : Set α` pointwise. * `fixingSubmonoid_fixedPoints_gc M α` is the `GaloisConnection` that relates `fixingSubmonoid` with `fixedPoints`. * `fixingSubgroup M s` : in the presence of `MulAction M α` (with `Group M`) it is the `Subgroup M` consisting of elements which fix `s : Set α` pointwise. * `fixingSubgroup_fixedPoints_gc M α` is the `GaloisConnection` that relates `fixingSubgroup` with `fixedPoints`. TODO : * Maybe other lemmas are useful * Treat semigroups ? * add `to_additive` for the various lemmas -/ section Monoid open MulAction variable (M : Type*) {α : Type*} [Monoid M] [MulAction M α] /-- The submonoid fixing a set under a `MulAction`. -/ @[to_additive " The additive submonoid fixing a set under an `AddAction`. "] def fixingSubmonoid (s : Set α) : Submonoid M where carrier := { ϕ : M | ∀ x : s, ϕ • (x : α) = x } one_mem' _ := one_smul _ _ mul_mem' {x y} hx hy z := by rw [mul_smul, hy z, hx z] theorem mem_fixingSubmonoid_iff {s : Set α} {m : M} : m ∈ fixingSubmonoid M s ↔ ∀ y ∈ s, m • y = y := ⟨fun hg y hy => hg ⟨y, hy⟩, fun h ⟨y, hy⟩ => h y hy⟩ variable (α) /-- The Galois connection between fixing submonoids and fixed points of a monoid action -/ theorem fixingSubmonoid_fixedPoints_gc : GaloisConnection (OrderDual.toDual ∘ fixingSubmonoid M) ((fun P : Submonoid M => fixedPoints P α) ∘ OrderDual.ofDual) := fun _s _P => ⟨fun h s hs p => h p.2 ⟨s, hs⟩, fun h p hp s => h s.2 ⟨p, hp⟩⟩ theorem fixingSubmonoid_antitone : Antitone fun s : Set α => fixingSubmonoid M s := (fixingSubmonoid_fixedPoints_gc M α).monotone_l theorem fixedPoints_antitone : Antitone fun P : Submonoid M => fixedPoints P α := (fixingSubmonoid_fixedPoints_gc M α).monotone_u.dual_left /-- Fixing submonoid of union is intersection -/ theorem fixingSubmonoid_union {s t : Set α} : fixingSubmonoid M (s ∪ t) = fixingSubmonoid M s ⊓ fixingSubmonoid M t := (fixingSubmonoid_fixedPoints_gc M α).l_sup /-- Fixing submonoid of iUnion is intersection -/ theorem fixingSubmonoid_iUnion {ι : Sort*} {s : ι → Set α} : fixingSubmonoid M (⋃ i, s i) = ⨅ i, fixingSubmonoid M (s i) := (fixingSubmonoid_fixedPoints_gc M α).l_iSup /-- Fixed points of sup of submonoids is intersection -/ theorem fixedPoints_submonoid_sup {P Q : Submonoid M} : fixedPoints (↥(P ⊔ Q)) α = fixedPoints P α ∩ fixedPoints Q α := (fixingSubmonoid_fixedPoints_gc M α).u_inf /-- Fixed points of iSup of submonoids is intersection -/ theorem fixedPoints_submonoid_iSup {ι : Sort*} {P : ι → Submonoid M} : fixedPoints (↥(iSup P)) α = ⋂ i, fixedPoints (P i) α := (fixingSubmonoid_fixedPoints_gc M α).u_iInf end Monoid section Group open MulAction variable (M : Type*) {α : Type*} [Group M] [MulAction M α] /-- The subgroup fixing a set under a `MulAction`. -/ @[to_additive " The additive subgroup fixing a set under an `AddAction`. "] def fixingSubgroup (s : Set α) : Subgroup M := { fixingSubmonoid M s with inv_mem' := fun hx z => by rw [inv_smul_eq_iff, hx z] } theorem mem_fixingSubgroup_iff {s : Set α} {m : M} : m ∈ fixingSubgroup M s ↔ ∀ y ∈ s, m • y = y := ⟨fun hg y hy => hg ⟨y, hy⟩, fun h ⟨y, hy⟩ => h y hy⟩ theorem mem_fixingSubgroup_iff_subset_fixedBy {s : Set α} {m : M} : m ∈ fixingSubgroup M s ↔ s ⊆ fixedBy α m := by simp_rw [mem_fixingSubgroup_iff, Set.subset_def, mem_fixedBy] theorem mem_fixingSubgroup_compl_iff_movedBy_subset {s : Set α} {m : M} : m ∈ fixingSubgroup M sᶜ ↔ (fixedBy α m)ᶜ ⊆ s := by rw [mem_fixingSubgroup_iff_subset_fixedBy, Set.compl_subset_comm] variable (α) /-- The Galois connection between fixing subgroups and fixed points of a group action -/ theorem fixingSubgroup_fixedPoints_gc : GaloisConnection (OrderDual.toDual ∘ fixingSubgroup M) ((fun P : Subgroup M => fixedPoints P α) ∘ OrderDual.ofDual) := fun _s _P => ⟨fun h s hs p => h p.2 ⟨s, hs⟩, fun h p hp s => h s.2 ⟨p, hp⟩⟩ theorem fixingSubgroup_antitone : Antitone (fixingSubgroup M : Set α → Subgroup M) := (fixingSubgroup_fixedPoints_gc M α).monotone_l theorem fixedPoints_subgroup_antitone : Antitone fun P : Subgroup M => fixedPoints P α := (fixingSubgroup_fixedPoints_gc M α).monotone_u.dual_left /-- Fixing subgroup of union is intersection -/ theorem fixingSubgroup_union {s t : Set α} : fixingSubgroup M (s ∪ t) = fixingSubgroup M s ⊓ fixingSubgroup M t := (fixingSubgroup_fixedPoints_gc M α).l_sup /-- Fixing subgroup of iUnion is intersection -/ theorem fixingSubgroup_iUnion {ι : Sort*} {s : ι → Set α} : fixingSubgroup M (⋃ i, s i) = ⨅ i, fixingSubgroup M (s i) := (fixingSubgroup_fixedPoints_gc M α).l_iSup /-- Fixed points of sup of subgroups is intersection -/ theorem fixedPoints_subgroup_sup {P Q : Subgroup M} : fixedPoints (↥(P ⊔ Q)) α = fixedPoints P α ∩ fixedPoints Q α := (fixingSubgroup_fixedPoints_gc M α).u_inf /-- Fixed points of iSup of subgroups is intersection -/ theorem fixedPoints_subgroup_iSup {ι : Sort*} {P : ι → Subgroup M} : fixedPoints (↥(iSup P)) α = ⋂ i, fixedPoints (P i) α := (fixingSubgroup_fixedPoints_gc M α).u_iInf /-- The orbit of the fixing subgroup of `sᶜ` (ie. the moving subgroup of `s`) is a subset of `s` -/ theorem orbit_fixingSubgroup_compl_subset {s : Set α} {a : α} (a_in_s : a ∈ s) : MulAction.orbit (fixingSubgroup M sᶜ) a ⊆ s := by intro b b_in_orbit let ⟨⟨g, g_fixing⟩, g_eq⟩ := MulAction.mem_orbit_iff.mp b_in_orbit rw [Submonoid.mk_smul] at g_eq rw [mem_fixingSubgroup_compl_iff_movedBy_subset] at g_fixing rwa [← g_eq, smul_mem_of_set_mem_fixedBy (set_mem_fixedBy_of_movedBy_subset g_fixing)] end Group
GroupTheory\GroupAction\Group.lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Algebra.Group.Action.Basic import Mathlib.Algebra.Group.Aut import Mathlib.Algebra.Group.Invertible.Basic import Mathlib.Algebra.GroupWithZero.Action.Units import Mathlib.Algebra.GroupWithZero.Units.Basic /-! # Group actions applied to various types of group This file contains lemmas about `SMul` on `GroupWithZero`, and `Group`. -/ universe u v w variable {α : Type u} {β : Type v} {γ : Type w} section MulAction /-- `Monoid.toMulAction` is faithful on nontrivial cancellative monoids with zero. -/ instance CancelMonoidWithZero.faithfulSMul [CancelMonoidWithZero α] [Nontrivial α] : FaithfulSMul α α := ⟨fun h => mul_left_injective₀ one_ne_zero (h 1)⟩ section Gwz variable [GroupWithZero α] [MulAction α β] {a : α} @[simp] theorem inv_smul_smul₀ {c : α} (hc : c ≠ 0) (x : β) : c⁻¹ • c • x = x := inv_smul_smul (Units.mk0 c hc) x @[simp] theorem smul_inv_smul₀ {c : α} (hc : c ≠ 0) (x : β) : c • c⁻¹ • x = x := smul_inv_smul (Units.mk0 c hc) x theorem inv_smul_eq_iff₀ {a : α} (ha : a ≠ 0) {x y : β} : a⁻¹ • x = y ↔ x = a • y := ⟨fun h => by rw [← h, smul_inv_smul₀ ha], fun h => by rw [h, inv_smul_smul₀ ha]⟩ theorem eq_inv_smul_iff₀ {a : α} (ha : a ≠ 0) {x y : β} : x = a⁻¹ • y ↔ a • x = y := (MulAction.toPerm (Units.mk0 a ha)).eq_symm_apply @[simp] theorem Commute.smul_right_iff₀ [Mul β] [SMulCommClass α β β] [IsScalarTower α β β] {a b : β} {c : α} (hc : c ≠ 0) : Commute a (c • b) ↔ Commute a b := Commute.smul_right_iff (g := Units.mk0 c hc) @[simp] theorem Commute.smul_left_iff₀ [Mul β] [SMulCommClass α β β] [IsScalarTower α β β] {a b : β} {c : α} (hc : c ≠ 0) : Commute (c • a) b ↔ Commute a b := Commute.smul_left_iff (g := Units.mk0 c hc) /-- Right scalar multiplication as an order isomorphism. -/ @[simps] def Equiv.smulRight (ha : a ≠ 0) : β ≃ β where toFun b := a • b invFun b := a⁻¹ • b left_inv := inv_smul_smul₀ ha right_inv := smul_inv_smul₀ ha protected theorem MulAction.bijective₀ (ha : a ≠ 0) : Function.Bijective (a • · : β → β) := MulAction.bijective <| Units.mk0 a ha protected theorem MulAction.injective₀ (ha : a ≠ 0) : Function.Injective (a • · : β → β) := (MulAction.bijective₀ ha).injective protected theorem MulAction.surjective₀ (ha : a ≠ 0) : Function.Surjective (a • · : β → β) := (MulAction.bijective₀ ha).surjective end Gwz end MulAction section DistribMulAction section Group variable [Group α] [AddMonoid β] [DistribMulAction α β] variable (β) /-- Each element of the group defines an additive monoid isomorphism. This is a stronger version of `MulAction.toPerm`. -/ @[simps (config := { simpRhs := true })] def DistribMulAction.toAddEquiv (x : α) : β ≃+ β := { DistribMulAction.toAddMonoidHom β x, MulAction.toPermHom α β x with } variable (α) /-- Each element of the group defines an additive monoid isomorphism. This is a stronger version of `MulAction.toPermHom`. -/ @[simps] def DistribMulAction.toAddAut : α →* AddAut β where toFun := DistribMulAction.toAddEquiv β map_one' := AddEquiv.ext (one_smul _) map_mul' _ _ := AddEquiv.ext (mul_smul _ _) /-- Each non-zero element of a `GroupWithZero` defines an additive monoid isomorphism of an `AddMonoid` on which it acts distributively. This is a stronger version of `DistribMulAction.toAddMonoidHom`. -/ def DistribMulAction.toAddEquiv₀ {α : Type*} (β : Type*) [GroupWithZero α] [AddMonoid β] [DistribMulAction α β] (x : α) (hx : x ≠ 0) : β ≃+ β := { DistribMulAction.toAddMonoidHom β x with invFun := fun b ↦ x⁻¹ • b left_inv := fun b ↦ inv_smul_smul₀ hx b right_inv := fun b ↦ smul_inv_smul₀ hx b } variable {α β} theorem smul_eq_zero_iff_eq (a : α) {x : β} : a • x = 0 ↔ x = 0 := ⟨fun h => by rw [← inv_smul_smul a x, h, smul_zero], fun h => h.symm ▸ smul_zero _⟩ theorem smul_ne_zero_iff_ne (a : α) {x : β} : a • x ≠ 0 ↔ x ≠ 0 := not_congr <| smul_eq_zero_iff_eq a end Group end DistribMulAction section MulDistribMulAction variable [Group α] [Monoid β] [MulDistribMulAction α β] variable (β) /-- Each element of the group defines a multiplicative monoid isomorphism. This is a stronger version of `MulAction.toPerm`. -/ @[simps (config := { simpRhs := true })] def MulDistribMulAction.toMulEquiv (x : α) : β ≃* β := { MulDistribMulAction.toMonoidHom β x, MulAction.toPermHom α β x with } variable (α) /-- Each element of the group defines a multiplicative monoid isomorphism. This is a stronger version of `MulAction.toPermHom`. -/ @[simps] def MulDistribMulAction.toMulAut : α →* MulAut β where toFun := MulDistribMulAction.toMulEquiv β map_one' := MulEquiv.ext (one_smul _) map_mul' _ _ := MulEquiv.ext (mul_smul _ _) variable {α β} end MulDistribMulAction section Arrow attribute [local instance] arrowAction /-- When `B` is a monoid, `ArrowAction` is additionally a `MulDistribMulAction`. -/ def arrowMulDistribMulAction {G A B : Type*} [Group G] [MulAction G A] [Monoid B] : MulDistribMulAction G (A → B) where smul_one _ := rfl smul_mul _ _ _ := rfl attribute [local instance] arrowMulDistribMulAction /-- Given groups `G H` with `G` acting on `A`, `G` acts by multiplicative automorphisms on `A → H`. -/ @[simps!] def mulAutArrow {G A H} [Group G] [MulAction G A] [Monoid H] : G →* MulAut (A → H) := MulDistribMulAction.toMulAut _ _ end Arrow namespace IsUnit section DistribMulAction variable [Monoid α] [AddMonoid β] [DistribMulAction α β] @[simp] theorem smul_eq_zero {u : α} (hu : IsUnit u) {x : β} : u • x = 0 ↔ x = 0 := (Exists.elim hu) fun u hu => hu ▸ show u • x = 0 ↔ x = 0 from smul_eq_zero_iff_eq u end DistribMulAction end IsUnit section SMul variable [Group α] [Monoid β] theorem IsUnit.smul_sub_iff_sub_inv_smul [AddGroup β] [DistribMulAction α β] [IsScalarTower α β β] [SMulCommClass α β β] (r : α) (a : β) : IsUnit (r • (1 : β) - a) ↔ IsUnit (1 - r⁻¹ • a) := by rw [← isUnit_smul_iff r (1 - r⁻¹ • a), smul_sub, smul_inv_smul] end SMul
GroupTheory\GroupAction\Hom.lean
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Antoine Chambert-Loir -/ import Mathlib.Algebra.Module.Defs import Mathlib.Algebra.Ring.Action.Basic import Mathlib.Algebra.Group.Hom.CompTypeclasses /-! # Equivariant homomorphisms ## Main definitions * `MulActionHom φ X Y`, the type of equivariant functions from `X` to `Y`, where `φ : M → N` is a map, `M` acting on the type `X` and `N` acting on the type of `Y`. * `DistribMulActionHom φ A B`, the type of equivariant additive monoid homomorphisms from `A` to `B`, where `φ : M → N` is a morphism of monoids, `M` acting on the additive monoid `A` and `N` acting on the additive monoid of `B` * `SMulSemiringHom φ R S`, the type of equivariant ring homomorphisms from `R` to `S`, where `φ : M → N` is a morphism of monoids, `M` acting on the ring `R` and `N` acting on the ring `S`. The above types have corresponding classes: * `MulActionHomClass F φ X Y` states that `F` is a type of bundled `X → Y` homs which are `φ`-equivariant * `DistribMulActionHomClass F φ A B` states that `F` is a type of bundled `A → B` homs preserving the additive monoid structure and `φ`-equivariant * `SMulSemiringHomClass F φ R S` states that `F` is a type of bundled `R → S` homs preserving the ring structure and `φ`-equivariant ## Notation We introduce the following notation to code equivariant maps (the subscript index `ₑ` is for *equivariant*) : * `X →ₑ[φ] Y` is `MulActionHom φ X Y`. * `A →ₑ+[φ] B` is `DistribMulActionHom φ A B`. * `R →ₑ+*[φ] S` is `MulSemiringActionHom φ R S`. When `M = N` and `φ = MonoidHom.id M`, we provide the backward compatible notation : * `X →[M] Y` is `MulActionHom (@id M) X Y` * `A →+[M] B` is `DistribMulActionHom (MonoidHom.id M) A B` * `R →+*[M] S` is `MulSemiringActionHom (MonoidHom.id M) R S` -/ assert_not_exists Submonoid section MulActionHom variable {M' : Type*} variable {M : Type*} {N : Type*} {P : Type*} variable (φ : M → N) (ψ : N → P) (χ : M → P) variable (X : Type*) [SMul M X] [SMul M' X] variable (Y : Type*) [SMul N Y] [SMul M' Y] variable (Z : Type*) [SMul P Z] /-- Equivariant functions : When `φ : M → N` is a function, and types `X` and `Y` are endowed with actions of `M` and `N`, a function `f : X → Y` is `φ`-equivariant if `f (m • x) = (φ m) • (f x)`. -/ -- Porting note(#5171): this linter isn't ported yet. -- @[nolint has_nonempty_instance] structure MulActionHom where /-- The underlying function. -/ protected toFun : X → Y /-- The proposition that the function commutes with the actions. -/ protected map_smul' : ∀ (m : M) (x : X), toFun (m • x) = (φ m) • toFun x /- Porting note: local notation given a name, conflict with Algebra.Hom.GroupAction see https://github.com/leanprover/lean4/issues/2000 -/ /-- `φ`-equivariant functions `X → Y`, where `φ : M → N`, where `M` and `N` act on `X` and `Y` respectively -/ notation:25 (name := «MulActionHomLocal≺») X " →ₑ[" φ:25 "] " Y:0 => MulActionHom φ X Y /-- `M`-equivariant functions `X → Y` with respect to the action of `M` This is the same as `X →ₑ[@id M] Y` -/ notation:25 (name := «MulActionHomIdLocal≺») X " →[" M:25 "] " Y:0 => MulActionHom (@id M) X Y /-- `MulActionSemiHomClass F φ X Y` states that `F` is a type of morphisms which are `φ`-equivariant. You should extend this class when you extend `MulActionHom`. -/ class MulActionSemiHomClass (F : Type*) {M N : outParam Type*} (φ : outParam (M → N)) (X Y : outParam Type*) [SMul M X] [SMul N Y] [FunLike F X Y] : Prop where /-- The proposition that the function preserves the action. -/ map_smulₛₗ : ∀ (f : F) (c : M) (x : X), f (c • x) = (φ c) • (f x) export MulActionSemiHomClass (map_smulₛₗ) /-- `MulActionHomClass F M X Y` states that `F` is a type of morphisms which are equivariant with respect to actions of `M` This is an abbreviation of `MulActionSemiHomClass`. -/ abbrev MulActionHomClass (F : Type*) (M : outParam Type*) (X Y : outParam Type*) [SMul M X] [SMul M Y] [FunLike F X Y] := MulActionSemiHomClass F (@id M) X Y instance : FunLike (MulActionHom φ X Y) X Y where coe := MulActionHom.toFun coe_injective' f g h := by cases f; cases g; congr @[simp] theorem map_smul {F M X Y : Type*} [SMul M X] [SMul M Y] [FunLike F X Y] [MulActionHomClass F M X Y] (f : F) (c : M) (x : X) : f (c • x) = c • f x := map_smulₛₗ f c x -- attribute [simp] map_smulₛₗ -- Porting note: removed has_coe_to_fun instance, coercions handled differently now instance : MulActionSemiHomClass (X →ₑ[φ] Y) φ X Y where map_smulₛₗ := MulActionHom.map_smul' initialize_simps_projections MulActionHom (toFun → apply) namespace MulActionHom variable {φ X Y} variable {F : Type*} [FunLike F X Y] /- porting note: inserted following def & instance for consistent coercion behaviour, see also Algebra.Hom.Group -/ /-- Turn an element of a type `F` satisfying `MulActionSemiHomClass F φ X Y` into an actual `MulActionHom`. This is declared as the default coercion from `F` to `MulActionSemiHom φ X Y`. -/ @[coe] def _root_.MulActionSemiHomClass.toMulActionHom [MulActionSemiHomClass F φ X Y] (f : F) : X →ₑ[φ] Y where toFun := DFunLike.coe f map_smul' := map_smulₛₗ f /-- Any type satisfying `MulActionSemiHomClass` can be cast into `MulActionHom` via `MulActionHomSemiClass.toMulActionHom`. -/ instance [MulActionSemiHomClass F φ X Y] : CoeTC F (X →ₑ[φ] Y) := ⟨MulActionSemiHomClass.toMulActionHom⟩ variable (M' X Y F) in /-- If Y/X/M forms a scalar tower, any map X → Y preserving X-action also preserves M-action. -/ theorem _root_.IsScalarTower.smulHomClass [MulOneClass X] [SMul X Y] [IsScalarTower M' X Y] [MulActionHomClass F X X Y] : MulActionHomClass F M' X Y where map_smulₛₗ f m x := by rw [← mul_one (m • x), ← smul_eq_mul, map_smul, smul_assoc, ← map_smul, smul_eq_mul, mul_one, id_eq] protected theorem map_smul (f : X →[M'] Y) (m : M') (x : X) : f (m • x) = m • f x := map_smul f m x @[ext] theorem ext {f g : X →ₑ[φ] Y} : (∀ x, f x = g x) → f = g := DFunLike.ext f g protected theorem congr_fun {f g : X →ₑ[φ] Y} (h : f = g) (x : X) : f x = g x := DFunLike.congr_fun h _ /-- Two equal maps on scalars give rise to an equivariant map for identity -/ def ofEq {φ' : M → N} (h : φ = φ') (f : X →ₑ[φ] Y) : X →ₑ[φ'] Y where toFun := f.toFun map_smul' m a := h ▸ f.map_smul' m a @[simp] theorem ofEq_coe {φ' : M → N} (h : φ = φ') (f : X →ₑ[φ] Y) : (f.ofEq h).toFun = f.toFun := rfl @[simp] theorem ofEq_apply {φ' : M → N} (h : φ = φ') (f : X →ₑ[φ] Y) (a : X) : (f.ofEq h) a = f a := rfl variable {ψ χ} (M N) /-- The identity map as an equivariant map. -/ protected def id : X →[M] X := ⟨id, fun _ _ => rfl⟩ variable {M N Z} @[simp] theorem id_apply (x : X) : MulActionHom.id M x = x := rfl end MulActionHom namespace MulActionHom open MulActionHom variable {φ ψ χ X Y Z} -- attribute [instance] CompTriple.id_comp CompTriple.comp_id /-- Composition of two equivariant maps. -/ def comp (g : Y →ₑ[ψ] Z) (f : X →ₑ[φ] Y) [κ : CompTriple φ ψ χ] : X →ₑ[χ] Z := ⟨g ∘ f, fun m x => calc g (f (m • x)) = g (φ m • f x) := by rw [map_smulₛₗ] _ = ψ (φ m) • g (f x) := by rw [map_smulₛₗ] _ = (ψ ∘ φ) m • g (f x) := rfl _ = χ m • g (f x) := by rw [κ.comp_eq] ⟩ @[simp] theorem comp_apply (g : Y →ₑ[ψ] Z) (f : X →ₑ[φ] Y) [CompTriple φ ψ χ] (x : X) : g.comp f x = g (f x) := rfl @[simp] theorem id_comp (f : X →ₑ[φ] Y) : (MulActionHom.id N).comp f = f := ext fun x => by rw [comp_apply, id_apply] @[simp] theorem comp_id (f : X →ₑ[φ] Y) : f.comp (MulActionHom.id M) = f := ext fun x => by rw [comp_apply, id_apply] @[simp] theorem comp_assoc {Q T : Type*} [SMul Q T] {η : P → Q} {θ : M → Q} {ζ : N → Q} (h : Z →ₑ[η] T) (g : Y →ₑ[ψ] Z) (f : X →ₑ[φ] Y) [CompTriple φ ψ χ] [CompTriple χ η θ] [CompTriple ψ η ζ] [CompTriple φ ζ θ] : h.comp (g.comp f) = (h.comp g).comp f := ext fun _ => rfl variable {φ' : N → M} variable {Y₁ : Type*} [SMul M Y₁] /-- The inverse of a bijective equivariant map is equivariant. -/ @[simps] def inverse (f : X →[M] Y₁) (g : Y₁ → X) (h₁ : Function.LeftInverse g f) (h₂ : Function.RightInverse g f) : Y₁ →[M] X where toFun := g map_smul' m x := calc g (m • x) = g (m • f (g x)) := by rw [h₂] _ = g (f (m • g x)) := by simp only [map_smul, id_eq] _ = m • g x := by rw [h₁] /-- The inverse of a bijective equivariant map is equivariant. -/ @[simps] def inverse' (f : X →ₑ[φ] Y) (g : Y → X) (k : Function.RightInverse φ' φ) (h₁ : Function.LeftInverse g f) (h₂ : Function.RightInverse g f) : Y →ₑ[φ'] X where toFun := g map_smul' m x := calc g (m • x) = g (m • f (g x)) := by rw [h₂] _ = g ((φ (φ' m)) • f (g x)) := by rw [k] _ = g (f (φ' m • g x)) := by rw [map_smulₛₗ] _ = φ' m • g x := by rw [h₁] lemma inverse_eq_inverse' (f : X →[M] Y₁) (g : Y₁ → X) (h₁ : Function.LeftInverse g f) (h₂ : Function.RightInverse g f) : inverse f g h₁ h₂ = inverse' f g (congrFun rfl) h₁ h₂ := by rfl theorem inverse'_inverse' {f : X →ₑ[φ] Y} {g : Y → X} {k₁ : Function.LeftInverse φ' φ} {k₂ : Function.RightInverse φ' φ} {h₁ : Function.LeftInverse g f} {h₂ : Function.RightInverse g f} : inverse' (inverse' f g k₂ h₁ h₂) f k₁ h₂ h₁ = f := ext fun _ => rfl theorem comp_inverse' {f : X →ₑ[φ] Y} {g : Y → X} {k₁ : Function.LeftInverse φ' φ} {k₂ : Function.RightInverse φ' φ} {h₁ : Function.LeftInverse g f} {h₂ : Function.RightInverse g f} : (inverse' f g k₂ h₁ h₂).comp f (κ := CompTriple.comp_inv k₁) = MulActionHom.id M := by rw [MulActionHom.ext_iff] intro x simp only [comp_apply, inverse_apply, id_apply] exact h₁ x theorem inverse'_comp {f : X →ₑ[φ] Y} {g : Y → X} {k₂ : Function.RightInverse φ' φ} {h₁ : Function.LeftInverse g f} {h₂ : Function.RightInverse g f} : f.comp (inverse' f g k₂ h₁ h₂) (κ := CompTriple.comp_inv k₂) = MulActionHom.id N := by rw [MulActionHom.ext_iff] intro x simp only [comp_apply, inverse_apply, id_apply] exact h₂ x /-- If actions of `M` and `N` on `α` commute, then for `c : M`, `(c • · : α → α)` is an `N`-action homomorphism. -/ @[simps] def _root_.SMulCommClass.toMulActionHom {M} (N α : Type*) [SMul M α] [SMul N α] [SMulCommClass M N α] (c : M) : α →[N] α where toFun := (c • ·) map_smul' := smul_comm _ end MulActionHom end MulActionHom section DistribMulAction variable {M : Type*} [Monoid M] variable {N : Type*} [Monoid N] variable {P : Type*} [Monoid P] variable (φ : M →* N) (φ' : N →* M) (ψ : N →* P) (χ : M →* P) variable (A : Type*) [AddMonoid A] [DistribMulAction M A] variable (B : Type*) [AddMonoid B] [DistribMulAction N B] variable (B₁ : Type*) [AddMonoid B₁] [DistribMulAction M B₁] variable (C : Type*) [AddMonoid C] [DistribMulAction P C] variable (A' : Type*) [AddGroup A'] [DistribMulAction M A'] variable (B' : Type*) [AddGroup B'] [DistribMulAction N B'] /-- Equivariant additive monoid homomorphisms. -/ structure DistribMulActionHom extends A →ₑ[φ] B, A →+ B /-- Reinterpret an equivariant additive monoid homomorphism as an additive monoid homomorphism. -/ add_decl_doc DistribMulActionHom.toAddMonoidHom /-- Reinterpret an equivariant additive monoid homomorphism as an equivariant function. -/ add_decl_doc DistribMulActionHom.toMulActionHom /- Porting note: local notation given a name, conflict with Algebra.Hom.Freiman see https://github.com/leanprover/lean4/issues/2000 -/ @[inherit_doc] notation:25 (name := «DistribMulActionHomLocal≺») A " →ₑ+[" φ:25 "] " B:0 => DistribMulActionHom φ A B @[inherit_doc] notation:25 (name := «DistribMulActionHomIdLocal≺») A " →+[" M:25 "] " B:0 => DistribMulActionHom (MonoidHom.id M) A B -- QUESTION/TODO : Impose that `φ` is a morphism of monoids? /-- `DistribMulActionSemiHomClass F φ A B` states that `F` is a type of morphisms preserving the additive monoid structure and equivariant with respect to `φ`. You should extend this class when you extend `DistribMulActionSemiHom`. -/ class DistribMulActionSemiHomClass (F : Type*) {M N : outParam Type*} (φ : outParam (M → N)) (A B : outParam Type*) [Monoid M] [Monoid N] [AddMonoid A] [AddMonoid B] [DistribMulAction M A] [DistribMulAction N B] [FunLike F A B] extends MulActionSemiHomClass F φ A B, AddMonoidHomClass F A B : Prop /-- `DistribMulActionHomClass F M A B` states that `F` is a type of morphisms preserving the additive monoid structure and equivariant with respect to the action of `M`. It is an abbreviation to `DistribMulActionHomClass F (MonoidHom.id M) A B` You should extend this class when you extend `DistribMulActionHom`. -/ abbrev DistribMulActionHomClass (F : Type*) (M : outParam Type*) (A B : outParam Type*) [Monoid M] [AddMonoid A] [AddMonoid B] [DistribMulAction M A] [DistribMulAction M B] [FunLike F A B] := DistribMulActionSemiHomClass F (MonoidHom.id M) A B /- porting note: Removed a @[nolint dangerousInstance] for DistribMulActionHomClass.toAddMonoidHomClass not dangerous due to `outParam`s -/ namespace DistribMulActionHom /- Porting note (#11215): TODO decide whether the next two instances should be removed Coercion is already handled by all the HomClass constructions I believe -/ -- instance coe : Coe (A →+[M] B) (A →+ B) := -- ⟨toAddMonoidHom⟩ -- instance coe' : Coe (A →+[M] B) (A →[M] B) := -- ⟨toMulActionHom⟩ instance : FunLike (A →ₑ+[φ] B) A B where coe m := m.toFun coe_injective' f g h := by rcases f with ⟨tF, _, _⟩; rcases g with ⟨tG, _, _⟩ cases tF; cases tG; congr instance : DistribMulActionSemiHomClass (A →ₑ+[φ] B) φ A B where map_smulₛₗ m := m.map_smul' map_zero := DistribMulActionHom.map_zero' map_add := DistribMulActionHom.map_add' variable {φ φ' A B B₁} variable {F : Type*} [FunLike F A B] /- porting note: inserted following def & instance for consistent coercion behaviour, see also Algebra.Hom.Group -/ /-- Turn an element of a type `F` satisfying `MulActionHomClass F M X Y` into an actual `MulActionHom`. This is declared as the default coercion from `F` to `MulActionHom M X Y`. -/ @[coe] def _root_.DistribMulActionSemiHomClass.toDistribMulActionHom [DistribMulActionSemiHomClass F φ A B] (f : F) : A →ₑ+[φ] B := { (f : A →+ B), (f : A →ₑ[φ] B) with } /-- Any type satisfying `MulActionHomClass` can be cast into `MulActionHom` via `MulActionHomClass.toMulActionHom`. -/ instance [DistribMulActionSemiHomClass F φ A B] : CoeTC F (A →ₑ+[φ] B) := ⟨DistribMulActionSemiHomClass.toDistribMulActionHom⟩ /-- If `DistribMulAction` of `M` and `N` on `A` commute, then for each `c : M`, `(c • ·)` is an `N`-action additive homomorphism. -/ @[simps] def _root_.SMulCommClass.toDistribMulActionHom {M} (N A : Type*) [Monoid N] [AddMonoid A] [DistribSMul M A] [DistribMulAction N A] [SMulCommClass M N A] (c : M) : A →+[N] A := { SMulCommClass.toMulActionHom N A c, DistribSMul.toAddMonoidHom _ c with toFun := (c • ·) } @[simp] theorem toFun_eq_coe (f : A →ₑ+[φ] B) : f.toFun = f := rfl @[norm_cast] theorem coe_fn_coe (f : A →ₑ+[φ] B) : ⇑(f : A →+ B) = f := rfl @[norm_cast] theorem coe_fn_coe' (f : A →ₑ+[φ] B) : ⇑(f : A →ₑ[φ] B) = f := rfl @[ext] theorem ext {f g : A →ₑ+[φ] B} : (∀ x, f x = g x) → f = g := DFunLike.ext f g protected theorem congr_fun {f g : A →ₑ+[φ] B} (h : f = g) (x : A) : f x = g x := DFunLike.congr_fun h _ theorem toMulActionHom_injective {f g : A →ₑ+[φ] B} (h : (f : A →ₑ[φ] B) = (g : A →ₑ[φ] B)) : f = g := by ext a exact MulActionHom.congr_fun h a theorem toAddMonoidHom_injective {f g : A →ₑ+[φ] B} (h : (f : A →+ B) = (g : A →+ B)) : f = g := by ext a exact DFunLike.congr_fun h a protected theorem map_zero (f : A →ₑ+[φ] B) : f 0 = 0 := map_zero f protected theorem map_add (f : A →ₑ+[φ] B) (x y : A) : f (x + y) = f x + f y := map_add f x y protected theorem map_neg (f : A' →ₑ+[φ] B') (x : A') : f (-x) = -f x := map_neg f x protected theorem map_sub (f : A' →ₑ+[φ] B') (x y : A') : f (x - y) = f x - f y := map_sub f x y protected theorem map_smulₑ (f : A →ₑ+[φ] B) (m : M) (x : A) : f (m • x) = (φ m) • f x := map_smulₛₗ f m x variable (M) /-- The identity map as an equivariant additive monoid homomorphism. -/ protected def id : A →+[M] A := ⟨MulActionHom.id _, rfl, fun _ _ => rfl⟩ @[simp] theorem id_apply (x : A) : DistribMulActionHom.id M x = x := by rfl variable {M C ψ χ} -- porting note: `simp` used to prove this, but now `change` is needed to push past the coercions instance : Zero (A →ₑ+[φ] B) := ⟨{ (0 : A →+ B) with map_smul' := fun m _ => by change (0 : B) = (φ m) • (0 : B); rw [smul_zero]}⟩ instance : One (A →+[M] A) := ⟨DistribMulActionHom.id M⟩ @[simp] theorem coe_zero : ⇑(0 : A →ₑ+[φ] B) = 0 := rfl @[simp] theorem coe_one : ⇑(1 : A →+[M] A) = id := rfl theorem zero_apply (a : A) : (0 : A →ₑ+[φ] B) a = 0 := rfl theorem one_apply (a : A) : (1 : A →+[M] A) a = a := rfl instance : Inhabited (A →ₑ+[φ] B) := ⟨0⟩ set_option linter.unusedVariables false in /-- Composition of two equivariant additive monoid homomorphisms. -/ def comp (g : B →ₑ+[ψ] C) (f : A →ₑ+[φ] B) [κ : MonoidHom.CompTriple φ ψ χ] : A →ₑ+[χ] C := { MulActionHom.comp (g : B →ₑ[ψ] C) (f : A →ₑ[φ] B), AddMonoidHom.comp (g : B →+ C) (f : A →+ B) with } @[simp] theorem comp_apply (g : B →ₑ+[ψ] C) (f : A →ₑ+[φ] B) [MonoidHom.CompTriple φ ψ χ] (x : A) : g.comp f x = g (f x) := rfl @[simp] theorem id_comp (f : A →ₑ+[φ] B) : comp (DistribMulActionHom.id N) f = f := ext fun x => by rw [comp_apply, id_apply] @[simp] theorem comp_id (f : A →ₑ+[φ] B) : f.comp (DistribMulActionHom.id M) = f := ext fun x => by rw [comp_apply, id_apply] @[simp] theorem comp_assoc {Q D : Type*} [Monoid Q] [AddMonoid D] [DistribMulAction Q D] {η : P →* Q} {θ : M →* Q} {ζ : N →* Q} (h : C →ₑ+[η] D) (g : B →ₑ+[ψ] C) (f : A →ₑ+[φ] B) [MonoidHom.CompTriple φ ψ χ] [MonoidHom.CompTriple χ η θ] [MonoidHom.CompTriple ψ η ζ] [MonoidHom.CompTriple φ ζ θ] : h.comp (g.comp f) = (h.comp g).comp f := ext fun _ => rfl /-- The inverse of a bijective `DistribMulActionHom` is a `DistribMulActionHom`. -/ @[simps] def inverse (f : A →+[M] B₁) (g : B₁ → A) (h₁ : Function.LeftInverse g f) (h₂ : Function.RightInverse g f) : B₁ →+[M] A := { (f : A →+ B₁).inverse g h₁ h₂, f.toMulActionHom.inverse g h₁ h₂ with toFun := g } section Semiring variable (R : Type*) [Semiring R] [MulSemiringAction M R] variable (R' : Type*) [Ring R'] [MulSemiringAction M R'] variable (S : Type*) [Semiring S] [MulSemiringAction N S] variable (S' : Type*) [Ring S'] [MulSemiringAction N S'] variable (T : Type*) [Semiring T] [MulSemiringAction P T] variable {R S M' N'} variable [AddMonoid M'] [DistribMulAction R M'] variable [AddMonoid N'] [DistribMulAction S N'] variable {σ : R →* S} @[ext] theorem ext_ring {f g : R →ₑ+[σ] N'} (h : f 1 = g 1) : f = g := by ext x rw [← mul_one x, ← smul_eq_mul R, f.map_smulₑ, g.map_smulₑ, h] end Semiring end DistribMulActionHom variable (R : Type*) [Semiring R] [MulSemiringAction M R] variable (R' : Type*) [Ring R'] [MulSemiringAction M R'] variable (S : Type*) [Semiring S] [MulSemiringAction N S] variable (S' : Type*) [Ring S'] [MulSemiringAction N S'] variable (T : Type*) [Semiring T] [MulSemiringAction P T] -- variable {R S M' N'} -- variable [AddMonoid M'] [DistribMulAction R M'] -- variable [AddMonoid N'] [DistribMulAction S N'] /-- Equivariant ring homomorphisms. -/ -- Porting note(#5171): this linter isn't ported yet. -- @[nolint has_nonempty_instance] structure MulSemiringActionHom extends R →ₑ+[φ] S, R →+* S /- /-- Equivariant ring homomorphism -/ abbrev MulSemiringActionHom (M : Type*) [Monoid M] (R : Type*) [Semiring R] [MulSemiringAction M R] (S : Type*) [Semiring S] [MulSemiringAction M S]:= MulSemiringActionHom (MonoidHom.id M) R S -/ /-- Reinterpret an equivariant ring homomorphism as a ring homomorphism. -/ add_decl_doc MulSemiringActionHom.toRingHom /-- Reinterpret an equivariant ring homomorphism as an equivariant additive monoid homomorphism. -/ add_decl_doc MulSemiringActionHom.toDistribMulActionHom /- Porting note: local notation given a name, conflict with Algebra.Hom.Freiman see https://github.com/leanprover/lean4/issues/2000 -/ @[inherit_doc] notation:25 (name := «MulSemiringActionHomLocal≺») R " →ₑ+*[" φ:25 "] " S:0 => MulSemiringActionHom φ R S @[inherit_doc] notation:25 (name := «MulSemiringActionHomIdLocal≺») R " →+*[" M:25 "] " S:0 => MulSemiringActionHom (MonoidHom.id M) R S /-- `MulSemiringActionHomClass F φ R S` states that `F` is a type of morphisms preserving the ring structure and equivariant with respect to `φ`. You should extend this class when you extend `MulSemiringActionHom`. -/ class MulSemiringActionSemiHomClass (F : Type*) {M N : outParam Type*} [Monoid M] [Monoid N] (φ : outParam (M → N)) (R S : outParam Type*) [Semiring R] [Semiring S] [DistribMulAction M R] [DistribMulAction N S] [FunLike F R S] extends DistribMulActionSemiHomClass F φ R S, RingHomClass F R S : Prop /-- `MulSemiringActionHomClass F M R S` states that `F` is a type of morphisms preserving the ring structure and equivariant with respect to a `DistribMulAction`of `M` on `R` and `S` . -/ abbrev MulSemiringActionHomClass (F : Type*) {M : outParam Type*} [Monoid M] (R S : outParam Type*) [Semiring R] [Semiring S] [DistribMulAction M R] [DistribMulAction M S] [FunLike F R S] := MulSemiringActionSemiHomClass F (MonoidHom.id M) R S /- porting note: Removed a @[nolint dangerousInstance] for MulSemiringActionHomClass.toRingHomClass not dangerous due to outParam -/ namespace MulSemiringActionHom /- Porting note (#11215): TODO decide whether the next two instances should be removed Coercion is already handled by all the HomClass constructions I believe -/ -- @[coe] -- instance coe : Coe (R →+*[M] S) (R →+* S) := -- ⟨toRingHom⟩ -- @[coe] -- instance coe' : Coe (R →+*[M] S) (R →+[M] S) := -- ⟨toDistribMulActionHom⟩ -- Porting note: removed has_coe_to_fun instance, coercions handled differently now instance : FunLike (R →ₑ+*[φ] S) R S where coe m := m.toFun coe_injective' f g h := by rcases f with ⟨⟨tF, _, _⟩, _, _⟩; rcases g with ⟨⟨tG, _, _⟩, _, _⟩ cases tF; cases tG; congr instance : MulSemiringActionSemiHomClass (R →ₑ+*[φ] S) φ R S where map_zero m := m.map_zero' map_add m := m.map_add' map_one := MulSemiringActionHom.map_one' map_mul := MulSemiringActionHom.map_mul' map_smulₛₗ m := m.map_smul' variable {φ R S} variable {F : Type*} [FunLike F R S] /- porting note: inserted following def & instance for consistent coercion behaviour, see also Algebra.Hom.Group -/ /-- Turn an element of a type `F` satisfying `MulSemiringActionHomClass F M R S` into an actual `MulSemiringActionHom`. This is declared as the default coercion from `F` to `MulSemiringActionHom M X Y`. -/ @[coe] def _root_.MulSemiringActionHomClass.toMulSemiringActionHom [MulSemiringActionSemiHomClass F φ R S] (f : F) : R →ₑ+*[φ] S := { (f : R →+* S), (f : R →ₑ+[φ] S) with } /-- Any type satisfying `MulSemiringActionHomClass` can be cast into `MulSemiringActionHom` via `MulSemiringActionHomClass.toMulSemiringActionHom`. -/ instance [MulSemiringActionSemiHomClass F φ R S] : CoeTC F (R →ₑ+*[φ] S) := ⟨MulSemiringActionHomClass.toMulSemiringActionHom⟩ @[norm_cast] theorem coe_fn_coe (f : R →ₑ+*[φ] S) : ⇑(f : R →+* S) = f := rfl @[norm_cast] theorem coe_fn_coe' (f : R →ₑ+*[φ] S) : ⇑(f : R →ₑ+[φ] S) = f := rfl @[ext] theorem ext {f g : R →ₑ+*[φ] S} : (∀ x, f x = g x) → f = g := DFunLike.ext f g protected theorem map_zero (f : R →ₑ+*[φ] S) : f 0 = 0 := map_zero f protected theorem map_add (f : R →ₑ+*[φ] S) (x y : R) : f (x + y) = f x + f y := map_add f x y protected theorem map_neg (f : R' →ₑ+*[φ] S') (x : R') : f (-x) = -f x := map_neg f x protected theorem map_sub (f : R' →ₑ+*[φ] S') (x y : R') : f (x - y) = f x - f y := map_sub f x y protected theorem map_one (f : R →ₑ+*[φ] S) : f 1 = 1 := map_one f protected theorem map_mul (f : R →ₑ+*[φ] S) (x y : R) : f (x * y) = f x * f y := map_mul f x y protected theorem map_smulₛₗ (f : R →ₑ+*[φ] S) (m : M) (x : R) : f (m • x) = φ m • f x := map_smulₛₗ f m x protected theorem map_smul [MulSemiringAction M S] (f : R →+*[M] S) (m : M) (x : R) : f (m • x) = m • f x := map_smulₛₗ f m x end MulSemiringActionHom namespace MulSemiringActionHom variable (M) {R} /-- The identity map as an equivariant ring homomorphism. -/ protected def id : R →+*[M] R := ⟨DistribMulActionHom.id _, rfl, (fun _ _ => rfl)⟩ @[simp] theorem id_apply (x : R) : MulSemiringActionHom.id M x = x := rfl end MulSemiringActionHom namespace MulSemiringActionHom open MulSemiringActionHom variable {R S T} variable {φ φ' ψ χ} set_option linter.unusedVariables false in /-- Composition of two equivariant additive ring homomorphisms. -/ def comp (g : S →ₑ+*[ψ] T) (f : R →ₑ+*[φ] S) [κ : MonoidHom.CompTriple φ ψ χ] : R →ₑ+*[χ] T := { DistribMulActionHom.comp (g : S →ₑ+[ψ] T) (f : R →ₑ+[φ] S), RingHom.comp (g : S →+* T) (f : R →+* S) with } @[simp] theorem comp_apply (g : S →ₑ+*[ψ] T) (f : R →ₑ+*[φ] S) [MonoidHom.CompTriple φ ψ χ] (x : R) : g.comp f x = g (f x) := rfl @[simp] theorem id_comp (f : R →ₑ+*[φ] S) : (MulSemiringActionHom.id N).comp f = f := ext fun x => by rw [comp_apply, id_apply] @[simp] theorem comp_id (f : R →ₑ+*[φ] S) : f.comp (MulSemiringActionHom.id M) = f := ext fun x => by rw [comp_apply, id_apply] /-- The inverse of a bijective `MulSemiringActionHom` is a `MulSemiringActionHom`. -/ @[simps] def inverse' (f : R →ₑ+*[φ] S) (g : S → R) (k : Function.RightInverse φ' φ) (h₁ : Function.LeftInverse g f) (h₂ : Function.RightInverse g f) : S →ₑ+*[φ'] R := { (f : R →+ S).inverse g h₁ h₂, (f : R →* S).inverse g h₁ h₂, (f : R →ₑ[φ] S).inverse' g k h₁ h₂ with toFun := g } /-- The inverse of a bijective `MulSemiringActionHom` is a `MulSemiringActionHom`. -/ @[simps] def inverse {S₁ : Type*} [Semiring S₁] [MulSemiringAction M S₁] (f : R →+*[M] S₁) (g : S₁ → R) (h₁ : Function.LeftInverse g f) (h₂ : Function.RightInverse g f) : S₁ →+*[M] R := { (f : R →+ S₁).inverse g h₁ h₂, (f : R →* S₁).inverse g h₁ h₂, f.toMulActionHom.inverse g h₁ h₂ with toFun := g } end MulSemiringActionHom end DistribMulAction
GroupTheory\GroupAction\IterateAct.lean
/- Copyright (c) 2024 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.Ring.Nat import Mathlib.Algebra.Group.Action.Defs /-! # Monoid action by iterates of a map In this file we define `IterateMulAct f`, `f : α → α`, as a one field structure wrapper over `ℕ` that acts on `α` by iterates of `f`, `⟨n⟩ • x = f^[n] x`. It is useful to convert between definitions and theorems about maps and monoid actions. -/ /-- A structure with a single field `val : ℕ` that additively acts on `α` by `⟨n⟩ +ᵥ x = f^[n] x`. -/ structure IterateAddAct {α : Type*} (f : α → α) where /-- The value of `n : IterateAddAct f`. -/ val : ℕ /-- A structure with a single field `val : ℕ` that acts on `α` by `⟨n⟩ • x = f^[n] x`. -/ @[to_additive (attr := ext)] structure IterateMulAct {α : Type*} (f : α → α) where /-- The value of `n : IterateMulAct f`. -/ val : ℕ namespace IterateMulAct variable {α : Type*} {f : α → α} @[to_additive] instance instCommMonoid : CommMonoid (IterateMulAct f) where one := ⟨0⟩ mul m n := ⟨m.1 + n.1⟩ mul_assoc a b c := by ext; apply add_assoc one_mul _ := by ext; apply zero_add mul_one _ := rfl mul_comm _ _ := by ext; apply add_comm npow n a := ⟨n * a.val⟩ npow_zero _ := by ext; apply zero_mul npow_succ n a := by ext; apply Nat.succ_mul @[to_additive] instance instMulAction : MulAction (IterateMulAct f) α where smul n x := f^[n.val] x one_smul _ := rfl mul_smul _ _ := Function.iterate_add_apply f _ _ @[to_additive (attr := simp)] theorem mk_smul (n : ℕ) (x : α) : mk (f := f) n • x = f^[n] x := rfl end IterateMulAct
GroupTheory\GroupAction\Period.lean
/- Copyright (c) 2024 Emilie Burgun. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Emilie Burgun -/ import Mathlib.Dynamics.PeriodicPts import Mathlib.GroupTheory.Exponent import Mathlib.GroupTheory.GroupAction.Basic /-! # Period of a group action This module defines some helpful lemmas around [`MulAction.period`] and [`AddAction.period`]. The period of a point `a` by a group element `g` is the smallest `m` such that `g ^ m • a = a` (resp. `(m • g) +ᵥ a = a`) for a given `g : G` and `a : α`. If such an `m` does not exist, then by convention `MulAction.period` and `AddAction.period` return 0. -/ namespace MulAction universe u v variable {α : Type v} variable {G : Type u} [Group G] [MulAction G α] variable {M : Type u} [Monoid M] [MulAction M α] /-- If the action is periodic, then a lower bound for its period can be computed. -/ @[to_additive "If the action is periodic, then a lower bound for its period can be computed."] theorem le_period {m : M} {a : α} {n : ℕ} (period_pos : 0 < period m a) (moved : ∀ k, 0 < k → k < n → m ^ k • a ≠ a) : n ≤ period m a := le_of_not_gt fun period_lt_n => moved _ period_pos period_lt_n <| pow_period_smul m a /-- If for some `n`, `m ^ n • a = a`, then `period m a ≤ n`. -/ @[to_additive "If for some `n`, `(n • m) +ᵥ a = a`, then `period m a ≤ n`."] theorem period_le_of_fixed {m : M} {a : α} {n : ℕ} (n_pos : 0 < n) (fixed : m ^ n • a = a) : period m a ≤ n := (isPeriodicPt_smul_iff.mpr fixed).minimalPeriod_le n_pos /-- If for some `n`, `m ^ n • a = a`, then `0 < period m a`. -/ @[to_additive "If for some `n`, `(n • m) +ᵥ a = a`, then `0 < period m a`."] theorem period_pos_of_fixed {m : M} {a : α} {n : ℕ} (n_pos : 0 < n) (fixed : m ^ n • a = a) : 0 < period m a := (isPeriodicPt_smul_iff.mpr fixed).minimalPeriod_pos n_pos @[to_additive] theorem period_eq_one_iff {m : M} {a : α} : period m a = 1 ↔ m • a = a := ⟨fun eq_one => pow_one m ▸ eq_one ▸ pow_period_smul m a, fun fixed => le_antisymm (period_le_of_fixed one_pos (by simpa)) (period_pos_of_fixed one_pos (by simpa))⟩ /-- For any non-zero `n` less than the period of `m` on `a`, `a` is moved by `m ^ n`. -/ @[to_additive "For any non-zero `n` less than the period of `m` on `a`, `a` is moved by `n • m`."] theorem pow_smul_ne_of_lt_period {m : M} {a : α} {n : ℕ} (n_pos : 0 < n) (n_lt_period : n < period m a) : m ^ n • a ≠ a := fun a_fixed => not_le_of_gt n_lt_period <| period_le_of_fixed n_pos a_fixed section Identities /-! ### `MulAction.period` for common group elements -/ variable (M) in @[to_additive (attr := simp)] theorem period_one (a : α) : period (1 : M) a = 1 := period_eq_one_iff.mpr (one_smul M a) @[to_additive (attr := simp)] theorem period_inv (g : G) (a : α) : period g⁻¹ a = period g a := by simp only [period_eq_minimalPeriod, Function.minimalPeriod_eq_minimalPeriod_iff, isPeriodicPt_smul_iff] intro n rw [smul_eq_iff_eq_inv_smul, eq_comm, ← zpow_natCast, inv_zpow, inv_inv, zpow_natCast] end Identities section MonoidExponent /-! ### `MulAction.period` and group exponents The period of a given element `m : M` can be bounded by the `Monoid.exponent M` or `orderOf m`. -/ @[to_additive] theorem period_dvd_orderOf (m : M) (a : α) : period m a ∣ orderOf m := by rw [← pow_smul_eq_iff_period_dvd, pow_orderOf_eq_one, one_smul] @[to_additive] theorem period_pos_of_orderOf_pos {m : M} (order_pos : 0 < orderOf m) (a : α) : 0 < period m a := Nat.pos_of_dvd_of_pos (period_dvd_orderOf m a) order_pos @[to_additive] theorem period_le_orderOf {m : M} (order_pos : 0 < orderOf m) (a : α) : period m a ≤ orderOf m := Nat.le_of_dvd order_pos (period_dvd_orderOf m a) @[to_additive] theorem period_dvd_exponent (m : M) (a : α) : period m a ∣ Monoid.exponent M := by rw [← pow_smul_eq_iff_period_dvd, Monoid.pow_exponent_eq_one, one_smul] @[to_additive] theorem period_pos_of_exponent_pos (exp_pos : 0 < Monoid.exponent M) (m : M) (a : α) : 0 < period m a := Nat.pos_of_dvd_of_pos (period_dvd_exponent m a) exp_pos @[to_additive] theorem period_le_exponent (exp_pos : 0 < Monoid.exponent M) (m : M) (a : α) : period m a ≤ Monoid.exponent M := Nat.le_of_dvd exp_pos (period_dvd_exponent m a) variable (α) @[to_additive] theorem period_bounded_of_exponent_pos (exp_pos : 0 < Monoid.exponent M) (m : M) : BddAbove (Set.range (fun a : α => period m a)) := by use Monoid.exponent M simpa [upperBounds] using period_le_exponent exp_pos _ end MonoidExponent end MulAction
GroupTheory\GroupAction\Pointwise.lean
/- Copyright (c) 2024 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nathaniel Thomas, Jeremy Avigad, Johannes Hölzl, Mario Carneiro, Anne Baanen, Frédéric Dupuis, Heather Macbeth, Antoine Chambert-Loir -/ import Mathlib.Data.Set.Pointwise.SMul import Mathlib.GroupTheory.GroupAction.Hom /-! # Pointwise actions of equivariant maps - `image_smul_setₛₗ` : under a `σ`-equivariant map, one has `h '' (c • s) = (σ c) • h '' s`. - `preimage_smul_setₛₗ'` is a general version of the equality `h ⁻¹' (σ c • s) = c • h⁻¹' s`. It requires that `c` acts surjectively and `σ c` acts injectively and is provided with specific versions: - `preimage_smul_setₛₗ_of_units` when `c` and `σ c` are units - `preimage_smul_setₛₗ` when `σ` belongs to a `MonoidHomClass`and `c` is a unit - `MonoidHom.preimage_smul_setₛₗ` when `σ` is a `MonoidHom` and `c` is a unit - `Group.preimage_smul_setₛₗ` : when the types of `c` and `σ c` are groups. - `image_smul_set`, `preimage_smul_set` and `Group.preimage_smul_set` are the variants when `σ` is the identity. -/ open Set Pointwise theorem MulAction.smul_bijective_of_is_unit {M : Type*} [Monoid M] {α : Type*} [MulAction M α] {m : M} (hm : IsUnit m) : Function.Bijective (fun (a : α) ↦ m • a) := by lift m to Mˣ using hm rw [Function.bijective_iff_has_inverse] use fun a ↦ m⁻¹ • a constructor · intro x; simp [← Units.smul_def] · intro x; simp [← Units.smul_def] variable {R S : Type*} (M M₁ M₂ N : Type*) variable [Monoid R] [Monoid S] (σ : R → S) variable [MulAction R M] [MulAction S N] [MulAction R M₁] [MulAction R M₂] variable {F : Type*} (h : F) section MulActionSemiHomClass variable [FunLike F M N] [MulActionSemiHomClass F σ M N] (c : R) (s : Set M) (t : Set N) -- @[simp] -- In #8386, the `simp_nf` linter complains: -- "Left-hand side does not simplify, when using the simp lemma on itself." -- For now we will have to manually add `image_smul_setₛₗ _` to the `simp` argument list. -- TODO: when lean4#3107 is fixed, mark this as `@[simp]`. theorem image_smul_setₛₗ : h '' (c • s) = σ c • h '' s := by simp only [← image_smul, image_image, map_smulₛₗ h] /-- Translation of preimage is contained in preimage of translation -/ theorem smul_preimage_set_leₛₗ : c • h ⁻¹' t ⊆ h ⁻¹' (σ c • t) := by rintro x ⟨y, hy, rfl⟩ exact ⟨h y, hy, by rw [map_smulₛₗ]⟩ variable {c} /-- General version of `preimage_smul_setₛₗ` -/ theorem preimage_smul_setₛₗ' (hc : Function.Surjective (fun (m : M) ↦ c • m)) (hc' : Function.Injective (fun (n : N) ↦ σ c • n)) : h ⁻¹' (σ c • t) = c • h ⁻¹' t := by apply le_antisymm · intro m obtain ⟨m', rfl⟩ := hc m rintro ⟨n, hn, hn'⟩ refine ⟨m', ?_, rfl⟩ rw [map_smulₛₗ] at hn' rw [mem_preimage, ← hc' hn'] exact hn · exact smul_preimage_set_leₛₗ M N σ h c t /-- `preimage_smul_setₛₗ` when both scalars act by unit -/ theorem preimage_smul_setₛₗ_of_units (hc : IsUnit c) (hc' : IsUnit (σ c)) : h ⁻¹' (σ c • t) = c • h ⁻¹' t := by apply preimage_smul_setₛₗ' · exact (MulAction.smul_bijective_of_is_unit hc).surjective · exact (MulAction.smul_bijective_of_is_unit hc').injective /-- `preimage_smul_setₛₗ` in the context of a `MonoidHom` -/ theorem MonoidHom.preimage_smul_setₛₗ (σ : R →* S) {F : Type*} [FunLike F M N] [MulActionSemiHomClass F ⇑σ M N] (h : F) {c : R} (hc : IsUnit c) (t : Set N) : h ⁻¹' (σ c • t) = c • h ⁻¹' t := preimage_smul_setₛₗ_of_units M N σ h t hc (IsUnit.map σ hc) /-- `preimage_smul_setₛₗ` in the context of a `MonoidHomClass` -/ theorem preimage_smul_setₛₗ {G : Type*} [FunLike G R S] [MonoidHomClass G R S] (σ : G) {F : Type*} [FunLike F M N] [MulActionSemiHomClass F σ M N] (h : F) {c : R} (hc : IsUnit c) (t : Set N) : h ⁻¹' (σ c • t) = c • h ⁻¹' t := MonoidHom.preimage_smul_setₛₗ M N (σ : R →* S) h hc t /-- `preimage_smul_setₛₗ` in the context of a groups -/ theorem Group.preimage_smul_setₛₗ {R S : Type*} [Group R] [Group S] (σ : R → S) [MulAction R M] [MulAction S N] {F : Type*} [FunLike F M N] [MulActionSemiHomClass F σ M N] (h : F) (c : R) (t : Set N) : h ⁻¹' (σ c • t) = c • h ⁻¹' t := preimage_smul_setₛₗ_of_units M N σ h t (Group.isUnit _) (Group.isUnit _) end MulActionSemiHomClass section MulActionHomClass variable (R) variable [FunLike F M₁ M₂] [MulActionHomClass F R M₁ M₂] (c : R) (s : Set M₁) (t : Set M₂) @[simp] -- This can be safely removed as a `@[simp]` lemma if `image_smul_setₛₗ` is readded. theorem image_smul_set : h '' (c • s) = c • h '' s := image_smul_setₛₗ _ _ _ h c s theorem smul_preimage_set_le : c • h ⁻¹' t ⊆ h ⁻¹' (c • t) := smul_preimage_set_leₛₗ _ _ _ h c t variable {c} theorem preimage_smul_set (hc : IsUnit c) : h ⁻¹' (c • t) = c • h ⁻¹' t := preimage_smul_setₛₗ_of_units _ _ _ h t hc hc theorem Group.preimage_smul_set {R : Type*} [Group R] (M₁ M₂ : Type*) [MulAction R M₁] [MulAction R M₂] {F : Type*} [FunLike F M₁ M₂] [MulActionHomClass F R M₁ M₂] (h : F) (c : R) (t : Set M₂) : h ⁻¹' (c • t) = c • h ⁻¹' t := _root_.preimage_smul_set R M₁ M₂ h t (Group.isUnit c) end MulActionHomClass
GroupTheory\GroupAction\Quotient.lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Thomas Browning -/ import Mathlib.Algebra.Group.ConjFinite import Mathlib.Data.Fintype.BigOperators import Mathlib.Dynamics.PeriodicPts import Mathlib.GroupTheory.Commutator import Mathlib.GroupTheory.Coset import Mathlib.GroupTheory.GroupAction.ConjAct import Mathlib.GroupTheory.GroupAction.Hom /-! # Properties of group actions involving quotient groups This file proves properties of group actions which use the quotient group construction, notably * the orbit-stabilizer theorem `card_orbit_mul_card_stabilizer_eq_card_group` * the class formula `card_eq_sum_card_group_div_card_stabilizer'` * Burnside's lemma `sum_card_fixedBy_eq_card_orbits_mul_card_group` -/ universe u v w variable {α : Type u} {β : Type v} {γ : Type w} open Function namespace MulAction variable [Group α] section QuotientAction open Subgroup MulOpposite QuotientGroup variable (β) [Monoid β] [MulAction β α] (H : Subgroup α) /-- A typeclass for when a `MulAction β α` descends to the quotient `α ⧸ H`. -/ class QuotientAction : Prop where /-- The action fulfils a normality condition on products that lie in `H`. This ensures that the action descends to an action on the quotient `α ⧸ H`. -/ inv_mul_mem : ∀ (b : β) {a a' : α}, a⁻¹ * a' ∈ H → (b • a)⁻¹ * b • a' ∈ H /-- A typeclass for when an `AddAction β α` descends to the quotient `α ⧸ H`. -/ class _root_.AddAction.QuotientAction {α : Type u} (β : Type v) [AddGroup α] [AddMonoid β] [AddAction β α] (H : AddSubgroup α) : Prop where /-- The action fulfils a normality condition on summands that lie in `H`. This ensures that the action descends to an action on the quotient `α ⧸ H`. -/ inv_mul_mem : ∀ (b : β) {a a' : α}, -a + a' ∈ H → -(b +ᵥ a) + (b +ᵥ a') ∈ H attribute [to_additive] MulAction.QuotientAction @[to_additive] instance left_quotientAction : QuotientAction α H := ⟨fun _ _ _ _ => by rwa [smul_eq_mul, smul_eq_mul, mul_inv_rev, mul_assoc, inv_mul_cancel_left]⟩ @[to_additive] instance right_quotientAction : QuotientAction (normalizer H).op H := ⟨fun b c _ _ => by rwa [smul_def, smul_def, smul_eq_mul_unop, smul_eq_mul_unop, mul_inv_rev, ← mul_assoc, mem_normalizer_iff'.mp b.prop, mul_assoc, mul_inv_cancel_left]⟩ @[to_additive] instance right_quotientAction' [hH : H.Normal] : QuotientAction αᵐᵒᵖ H := ⟨fun _ _ _ _ => by rwa [smul_eq_mul_unop, smul_eq_mul_unop, mul_inv_rev, mul_assoc, hH.mem_comm_iff, mul_assoc, mul_inv_cancel_right]⟩ @[to_additive] instance quotient [QuotientAction β H] : MulAction β (α ⧸ H) where smul b := Quotient.map' (b • ·) fun _ _ h => leftRel_apply.mpr <| QuotientAction.inv_mul_mem b <| leftRel_apply.mp h one_smul q := Quotient.inductionOn' q fun a => congr_arg Quotient.mk'' (one_smul β a) mul_smul b b' q := Quotient.inductionOn' q fun a => congr_arg Quotient.mk'' (mul_smul b b' a) variable {β} @[to_additive (attr := simp)] theorem Quotient.smul_mk [QuotientAction β H] (b : β) (a : α) : (b • QuotientGroup.mk a : α ⧸ H) = QuotientGroup.mk (b • a) := rfl @[to_additive (attr := simp)] theorem Quotient.smul_coe [QuotientAction β H] (b : β) (a : α) : b • (a : α ⧸ H) = (↑(b • a) : α ⧸ H) := rfl @[to_additive (attr := simp)] theorem Quotient.mk_smul_out' [QuotientAction β H] (b : β) (q : α ⧸ H) : QuotientGroup.mk (b • q.out') = b • q := by rw [← Quotient.smul_mk, QuotientGroup.out_eq'] -- Porting note: removed simp attribute, simp can prove this @[to_additive] theorem Quotient.coe_smul_out' [QuotientAction β H] (b : β) (q : α ⧸ H) : ↑(b • q.out') = b • q := Quotient.mk_smul_out' H b q theorem _root_.QuotientGroup.out'_conj_pow_minimalPeriod_mem (a : α) (q : α ⧸ H) : q.out'⁻¹ * a ^ Function.minimalPeriod (a • ·) q * q.out' ∈ H := by rw [mul_assoc, ← QuotientGroup.eq, QuotientGroup.out_eq', ← smul_eq_mul, Quotient.mk_smul_out', eq_comm, pow_smul_eq_iff_minimalPeriod_dvd] end QuotientAction open QuotientGroup /-- The canonical map to the left cosets. -/ def _root_.MulActionHom.toQuotient (H : Subgroup α) : α →[α] α ⧸ H where toFun := (↑); map_smul' := Quotient.smul_coe H @[simp] theorem _root_.MulActionHom.toQuotient_apply (H : Subgroup α) (g : α) : MulActionHom.toQuotient H g = g := rfl @[to_additive] instance mulLeftCosetsCompSubtypeVal (H I : Subgroup α) : MulAction I (α ⧸ H) := MulAction.compHom (α ⧸ H) (Subgroup.subtype I) variable (α) variable [MulAction α β] (x : β) /-- The canonical map from the quotient of the stabilizer to the set. -/ @[to_additive "The canonical map from the quotient of the stabilizer to the set. "] def ofQuotientStabilizer (g : α ⧸ MulAction.stabilizer α x) : β := Quotient.liftOn' g (· • x) fun g1 g2 H => calc g1 • x = g1 • (g1⁻¹ * g2) • x := congr_arg _ (leftRel_apply.mp H).symm _ = g2 • x := by rw [smul_smul, mul_inv_cancel_left] @[to_additive (attr := simp)] theorem ofQuotientStabilizer_mk (g : α) : ofQuotientStabilizer α x (QuotientGroup.mk g) = g • x := rfl @[to_additive] theorem ofQuotientStabilizer_mem_orbit (g) : ofQuotientStabilizer α x g ∈ orbit α x := Quotient.inductionOn' g fun g => ⟨g, rfl⟩ @[to_additive] theorem ofQuotientStabilizer_smul (g : α) (g' : α ⧸ MulAction.stabilizer α x) : ofQuotientStabilizer α x (g • g') = g • ofQuotientStabilizer α x g' := Quotient.inductionOn' g' fun _ => mul_smul _ _ _ @[to_additive] theorem injective_ofQuotientStabilizer : Function.Injective (ofQuotientStabilizer α x) := fun y₁ y₂ => Quotient.inductionOn₂' y₁ y₂ fun g₁ g₂ (H : g₁ • x = g₂ • x) => Quotient.sound' <| by rw [leftRel_apply] show (g₁⁻¹ * g₂) • x = x rw [mul_smul, ← H, inv_smul_smul] /-- **Orbit-stabilizer theorem**. -/ @[to_additive "Orbit-stabilizer theorem."] noncomputable def orbitEquivQuotientStabilizer (b : β) : orbit α b ≃ α ⧸ stabilizer α b := Equiv.symm <| Equiv.ofBijective (fun g => ⟨ofQuotientStabilizer α b g, ofQuotientStabilizer_mem_orbit α b g⟩) ⟨fun x y hxy => injective_ofQuotientStabilizer α b (by convert congr_arg Subtype.val hxy), fun ⟨b, ⟨g, hgb⟩⟩ => ⟨g, Subtype.eq hgb⟩⟩ /-- Orbit-stabilizer theorem. -/ @[to_additive AddAction.orbitProdStabilizerEquivAddGroup "Orbit-stabilizer theorem."] noncomputable def orbitProdStabilizerEquivGroup (b : β) : orbit α b × stabilizer α b ≃ α := (Equiv.prodCongr (orbitEquivQuotientStabilizer α _) (Equiv.refl _)).trans Subgroup.groupEquivQuotientProdSubgroup.symm /-- Orbit-stabilizer theorem. -/ @[to_additive AddAction.card_orbit_mul_card_stabilizer_eq_card_addGroup "Orbit-stabilizer theorem."] theorem card_orbit_mul_card_stabilizer_eq_card_group (b : β) [Fintype α] [Fintype <| orbit α b] [Fintype <| stabilizer α b] : Fintype.card (orbit α b) * Fintype.card (stabilizer α b) = Fintype.card α := by rw [← Fintype.card_prod, Fintype.card_congr (orbitProdStabilizerEquivGroup α b)] @[to_additive (attr := simp)] theorem orbitEquivQuotientStabilizer_symm_apply (b : β) (a : α) : ((orbitEquivQuotientStabilizer α b).symm a : β) = a • b := rfl @[to_additive (attr := simp)] theorem stabilizer_quotient {G} [Group G] (H : Subgroup G) : MulAction.stabilizer G ((1 : G) : G ⧸ H) = H := by ext simp [QuotientGroup.eq] variable (β) local notation "Ω" => Quotient <| orbitRel α β /-- **Class formula** : given `G` a group acting on `X` and `φ` a function mapping each orbit of `X` under this action (that is, each element of the quotient of `X` by the relation `orbitRel G X`) to an element in this orbit, this gives a (noncomputable) bijection between `X` and the disjoint union of `G/Stab(φ(ω))` over all orbits `ω`. In most cases you'll want `φ` to be `Quotient.out'`, so we provide `MulAction.selfEquivSigmaOrbitsQuotientStabilizer'` as a special case. -/ @[to_additive "**Class formula** : given `G` an additive group acting on `X` and `φ` a function mapping each orbit of `X` under this action (that is, each element of the quotient of `X` by the relation `orbit_rel G X`) to an element in this orbit, this gives a (noncomputable) bijection between `X` and the disjoint union of `G/Stab(φ(ω))` over all orbits `ω`. In most cases you'll want `φ` to be `Quotient.out'`, so we provide `AddAction.selfEquivSigmaOrbitsQuotientStabilizer'` as a special case. "] noncomputable def selfEquivSigmaOrbitsQuotientStabilizer' {φ : Ω → β} (hφ : LeftInverse Quotient.mk'' φ) : β ≃ Σω : Ω, α ⧸ stabilizer α (φ ω) := calc β ≃ Σω : Ω, orbitRel.Quotient.orbit ω := selfEquivSigmaOrbits' α β _ ≃ Σω : Ω, α ⧸ stabilizer α (φ ω) := Equiv.sigmaCongrRight fun ω => (Equiv.Set.ofEq <| orbitRel.Quotient.orbit_eq_orbit_out _ hφ).trans <| orbitEquivQuotientStabilizer α (φ ω) /-- **Class formula** for a finite group acting on a finite type. See `MulAction.card_eq_sum_card_group_div_card_stabilizer` for a specialized version using `Quotient.out'`. -/ @[to_additive "**Class formula** for a finite group acting on a finite type. See `AddAction.card_eq_sum_card_addGroup_div_card_stabilizer` for a specialized version using `Quotient.out'`."] theorem card_eq_sum_card_group_div_card_stabilizer' [Fintype α] [Fintype β] [Fintype Ω] [∀ b : β, Fintype <| stabilizer α b] {φ : Ω → β} (hφ : LeftInverse Quotient.mk'' φ) : Fintype.card β = ∑ ω : Ω, Fintype.card α / Fintype.card (stabilizer α (φ ω)) := by classical have : ∀ ω : Ω, Fintype.card α / Fintype.card (stabilizer α (φ ω)) = Fintype.card (α ⧸ stabilizer α (φ ω)) := by intro ω rw [Fintype.card_congr (@Subgroup.groupEquivQuotientProdSubgroup α _ (stabilizer α <| φ ω)), Fintype.card_prod, Nat.mul_div_cancel] exact Fintype.card_pos_iff.mpr (by infer_instance) simp_rw [this, ← Fintype.card_sigma, Fintype.card_congr (selfEquivSigmaOrbitsQuotientStabilizer' α β hφ)] /-- **Class formula**. This is a special case of `MulAction.self_equiv_sigma_orbits_quotient_stabilizer'` with `φ = Quotient.out'`. -/ @[to_additive "**Class formula**. This is a special case of `AddAction.self_equiv_sigma_orbits_quotient_stabilizer'` with `φ = Quotient.out'`. "] noncomputable def selfEquivSigmaOrbitsQuotientStabilizer : β ≃ Σω : Ω, α ⧸ stabilizer α ω.out' := selfEquivSigmaOrbitsQuotientStabilizer' α β Quotient.out_eq' /-- **Class formula** for a finite group acting on a finite type. -/ @[to_additive "**Class formula** for a finite group acting on a finite type."] theorem card_eq_sum_card_group_div_card_stabilizer [Fintype α] [Fintype β] [Fintype Ω] [∀ b : β, Fintype <| stabilizer α b] : Fintype.card β = ∑ ω : Ω, Fintype.card α / Fintype.card (stabilizer α ω.out') := card_eq_sum_card_group_div_card_stabilizer' α β Quotient.out_eq' /-- **Burnside's lemma** : a (noncomputable) bijection between the disjoint union of all `{x ∈ X | g • x = x}` for `g ∈ G` and the product `G × X/G`, where `G` is a group acting on `X` and `X/G` denotes the quotient of `X` by the relation `orbitRel G X`. -/ @[to_additive AddAction.sigmaFixedByEquivOrbitsProdAddGroup "**Burnside's lemma** : a (noncomputable) bijection between the disjoint union of all `{x ∈ X | g • x = x}` for `g ∈ G` and the product `G × X/G`, where `G` is an additive group acting on `X` and `X/G`denotes the quotient of `X` by the relation `orbitRel G X`. "] noncomputable def sigmaFixedByEquivOrbitsProdGroup : (Σa : α, fixedBy β a) ≃ Ω × α := calc (Σa : α, fixedBy β a) ≃ { ab : α × β // ab.1 • ab.2 = ab.2 } := (Equiv.subtypeProdEquivSigmaSubtype _).symm _ ≃ { ba : β × α // ba.2 • ba.1 = ba.1 } := (Equiv.prodComm α β).subtypeEquiv fun _ => Iff.rfl _ ≃ Σb : β, stabilizer α b := Equiv.subtypeProdEquivSigmaSubtype fun (b : β) a => a ∈ stabilizer α b _ ≃ Σωb : Σω : Ω, orbit α ω.out', stabilizer α (ωb.2 : β) := (selfEquivSigmaOrbits α β).sigmaCongrLeft' _ ≃ Σω : Ω, Σb : orbit α ω.out', stabilizer α (b : β) := Equiv.sigmaAssoc fun (ω : Ω) (b : orbit α ω.out') => stabilizer α (b : β) _ ≃ Σω : Ω, Σ _ : orbit α ω.out', stabilizer α ω.out' := Equiv.sigmaCongrRight fun _ => Equiv.sigmaCongrRight fun ⟨_, hb⟩ => (stabilizerEquivStabilizerOfOrbitRel hb).toEquiv _ ≃ Σω : Ω, orbit α ω.out' × stabilizer α ω.out' := Equiv.sigmaCongrRight fun _ => Equiv.sigmaEquivProd _ _ _ ≃ Σ _ : Ω, α := Equiv.sigmaCongrRight fun ω => orbitProdStabilizerEquivGroup α ω.out' _ ≃ Ω × α := Equiv.sigmaEquivProd Ω α /-- **Burnside's lemma** : given a finite group `G` acting on a set `X`, the average number of elements fixed by each `g ∈ G` is the number of orbits. -/ @[to_additive AddAction.sum_card_fixedBy_eq_card_orbits_mul_card_addGroup "**Burnside's lemma** : given a finite additive group `G` acting on a set `X`, the average number of elements fixed by each `g ∈ G` is the number of orbits. "] theorem sum_card_fixedBy_eq_card_orbits_mul_card_group [Fintype α] [∀ a : α, Fintype <| fixedBy β a] [Fintype Ω] : (∑ a : α, Fintype.card (fixedBy β a)) = Fintype.card Ω * Fintype.card α := by rw [← Fintype.card_prod, ← Fintype.card_sigma, Fintype.card_congr (sigmaFixedByEquivOrbitsProdGroup α β)] @[to_additive] instance isPretransitive_quotient (G) [Group G] (H : Subgroup G) : IsPretransitive G (G ⧸ H) where exists_smul_eq := by { rintro ⟨x⟩ ⟨y⟩ refine ⟨y * x⁻¹, QuotientGroup.eq.mpr ?_⟩ simp only [smul_eq_mul, H.one_mem, mul_left_inv, inv_mul_cancel_right]} variable {α} @[to_additive] instance finite_quotient_of_pretransitive_of_finite_quotient [IsPretransitive α β] {H : Subgroup α} [Finite (α ⧸ H)] : Finite <| orbitRel.Quotient H β := by rcases isEmpty_or_nonempty β with he | ⟨⟨b⟩⟩ · exact Quotient.finite _ · have h' : Finite (Quotient (rightRel H)) := Finite.of_equiv _ (quotientRightRelEquivQuotientLeftRel _).symm let f : Quotient (rightRel H) → orbitRel.Quotient H β := fun a ↦ Quotient.liftOn' a (fun g ↦ ⟦g • b⟧) fun g₁ g₂ r ↦ by replace r := Setoid.symm' _ r change (rightRel H).r _ _ at r rw [rightRel_eq] at r simp only [Quotient.eq] change g₁ • b ∈ orbit H (g₂ • b) rw [mem_orbit_iff] exact ⟨⟨g₁ * g₂⁻¹, r⟩, by simp [mul_smul]⟩ exact Finite.of_surjective f ((Quotient.surjective_liftOn' _).2 (Quotient.surjective_Quotient_mk''.comp (MulAction.surjective_smul _ _))) variable {β} /-- A bijection between the quotient of the action of a subgroup `H` on an orbit, and a corresponding quotient expressed in terms of `Setoid.comap Subtype.val`. -/ @[to_additive "A bijection between the quotient of the action of an additive subgroup `H` on an orbit, and a corresponding quotient expressed in terms of `Setoid.comap Subtype.val`."] noncomputable def equivSubgroupOrbitsSetoidComap (H : Subgroup α) (ω : Ω) : orbitRel.Quotient H (orbitRel.Quotient.orbit ω) ≃ Quotient ((orbitRel H β).comap (Subtype.val : Quotient.mk (orbitRel α β) ⁻¹' {ω} → β)) where toFun := fun q ↦ q.liftOn' (fun x ↦ ⟦⟨↑x, by simp only [Set.mem_preimage, Set.mem_singleton_iff] have hx := x.property rwa [orbitRel.Quotient.mem_orbit, @Quotient.mk''_eq_mk] at hx⟩⟧) fun a b h ↦ by simp only [← Quotient.eq'', Quotient.mk''_eq_mk, orbitRel.Quotient.subgroup_quotient_eq_iff] at h simp only [← Quotient.mk''_eq_mk, Quotient.eq''] at h ⊢ exact h invFun := fun q ↦ q.liftOn' (fun x ↦ ⟦⟨↑x, by have hx := x.property simp only [Set.mem_preimage, Set.mem_singleton_iff] at hx rwa [orbitRel.Quotient.mem_orbit, @Quotient.mk''_eq_mk]⟩⟧) fun a b h ↦ by change Setoid.Rel _ _ _ at h rw [Setoid.comap_rel, Setoid.Rel, ← Quotient.eq'', @Quotient.mk''_eq_mk] at h simp only [orbitRel.Quotient.subgroup_quotient_eq_iff] exact h left_inv := by simp only [LeftInverse] intro q induction q using Quotient.inductionOn' rfl right_inv := by simp only [Function.RightInverse, LeftInverse] intro q induction q using Quotient.inductionOn' rfl variable (β) /-- A bijection between the orbits under the action of a subgroup `H` on `β`, and the orbits under the action of `H` on each orbit under the action of `G`. -/ @[to_additive "A bijection between the orbits under the action of an additive subgroup `H` on `β`, and the orbits under the action of `H` on each orbit under the action of `G`."] noncomputable def equivSubgroupOrbits (H : Subgroup α) : orbitRel.Quotient H β ≃ Σω : Ω, orbitRel.Quotient H (orbitRel.Quotient.orbit ω) := (Setoid.sigmaQuotientEquivOfLe (orbitRel_subgroup_le H)).symm.trans (Equiv.sigmaCongrRight fun ω ↦ (equivSubgroupOrbitsSetoidComap H ω).symm) variable {β} @[to_additive] instance finite_quotient_of_finite_quotient_of_finite_quotient {H : Subgroup α} [Finite (orbitRel.Quotient α β)] [Finite (α ⧸ H)] : Finite <| orbitRel.Quotient H β := by rw [(equivSubgroupOrbits β H).finite_iff] infer_instance end MulAction theorem ConjClasses.card_carrier {G : Type*} [Group G] [Fintype G] (g : G) [Fintype (ConjClasses.mk g).carrier] [Fintype <| MulAction.stabilizer (ConjAct G) g] : Fintype.card (ConjClasses.mk g).carrier = Fintype.card G / Fintype.card (MulAction.stabilizer (ConjAct G) g) := by classical rw [Fintype.card_congr <| ConjAct.toConjAct (G := G) |>.toEquiv] rw [← MulAction.card_orbit_mul_card_stabilizer_eq_card_group (ConjAct G) g, Nat.mul_div_cancel] · simp_rw [ConjAct.orbit_eq_carrier_conjClasses] · exact Fintype.card_pos_iff.mpr inferInstance namespace Subgroup variable {G : Type*} [Group G] (H : Subgroup G) theorem normalCore_eq_ker : H.normalCore = (MulAction.toPermHom G (G ⧸ H)).ker := by apply le_antisymm · intro g hg apply Equiv.Perm.ext refine fun q ↦ QuotientGroup.induction_on q ?_ refine fun g' => (MulAction.Quotient.smul_mk H g g').trans (QuotientGroup.eq.mpr ?_) rw [smul_eq_mul, mul_inv_rev, ← inv_inv g', inv_inv] exact H.normalCore.inv_mem hg g'⁻¹ · refine (Subgroup.normal_le_normalCore.mpr fun g hg => ?_) rw [← H.inv_mem_iff, ← mul_one g⁻¹, ← QuotientGroup.eq, ← mul_one g] exact (MulAction.Quotient.smul_mk H g 1).symm.trans (Equiv.Perm.ext_iff.mp hg (1 : G)) open QuotientGroup /-- Cosets of the centralizer of an element embed into the set of commutators. -/ noncomputable def quotientCentralizerEmbedding (g : G) : G ⧸ centralizer (zpowers (g : G)) ↪ commutatorSet G := ((MulAction.orbitEquivQuotientStabilizer (ConjAct G) g).trans (quotientEquivOfEq (ConjAct.stabilizer_eq_centralizer g))).symm.toEmbedding.trans ⟨fun x => ⟨x * g⁻¹, let ⟨_, x, rfl⟩ := x ⟨x, g, rfl⟩⟩, fun _ _ => Subtype.ext ∘ mul_right_cancel ∘ Subtype.ext_iff.mp⟩ theorem quotientCentralizerEmbedding_apply (g : G) (x : G) : quotientCentralizerEmbedding g x = ⟨⁅x, g⁆, x, g, rfl⟩ := rfl /-- If `G` is generated by `S`, then the quotient by the center embeds into `S`-indexed sequences of commutators. -/ noncomputable def quotientCenterEmbedding {S : Set G} (hS : closure S = ⊤) : G ⧸ center G ↪ S → commutatorSet G := (quotientEquivOfEq (center_eq_infi' S hS)).toEmbedding.trans ((quotientiInfEmbedding _).trans (Function.Embedding.piCongrRight fun g => quotientCentralizerEmbedding (g : G))) theorem quotientCenterEmbedding_apply {S : Set G} (hS : closure S = ⊤) (g : G) (s : S) : quotientCenterEmbedding hS g s = ⟨⁅g, s⁆, g, s, rfl⟩ := rfl end Subgroup section conjClasses open Fintype theorem card_comm_eq_card_conjClasses_mul_card (G : Type*) [Group G] : Nat.card { p : G × G // Commute p.1 p.2 } = Nat.card (ConjClasses G) * Nat.card G := by classical rcases fintypeOrInfinite G; swap · rw [mul_comm, Nat.card_eq_zero_of_infinite, Nat.card_eq_zero_of_infinite, zero_mul] simp only [Nat.card_eq_fintype_card] -- Porting note: Changed `calc` proof into a `rw` proof. rw [card_congr (Equiv.subtypeProdEquivSigmaSubtype Commute), card_sigma, sum_equiv ConjAct.toConjAct.toEquiv (fun a ↦ card { b // Commute a b }) (fun g ↦ card (MulAction.fixedBy G g)) fun g ↦ card_congr' <| congr_arg _ <| funext fun h ↦ mul_inv_eq_iff_eq_mul.symm.eq, MulAction.sum_card_fixedBy_eq_card_orbits_mul_card_group] congr 1; apply card_congr'; congr; ext exact (Setoid.comm' _).trans isConj_iff.symm end conjClasses
GroupTheory\GroupAction\Ring.lean
/- Copyright (c) 2022 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.Group.Action.Defs import Mathlib.Algebra.Ring.Defs /-! # Commutativity and associativity of action of integers on rings This file proves that `ℕ` and `ℤ` act commutatively and associatively on (semi)rings. ## TODO Those instances are in their own file only because they require much less imports than any existing file they could go to. This is unfortunate and should be fixed by reorganising files. -/ open scoped Int variable {α : Type*} /-- Note that `AddMonoid.nat_smulCommClass` requires stronger assumptions on `α`. -/ instance NonUnitalNonAssocSemiring.nat_smulCommClass [NonUnitalNonAssocSemiring α] : SMulCommClass ℕ α α where smul_comm n x y := by induction' n with n ih · simp [zero_nsmul] · simp_rw [succ_nsmul, smul_eq_mul, mul_add, ← smul_eq_mul, ih] /-- Note that `AddCommMonoid.nat_isScalarTower` requires stronger assumptions on `α`. -/ instance NonUnitalNonAssocSemiring.nat_isScalarTower [NonUnitalNonAssocSemiring α] : IsScalarTower ℕ α α where smul_assoc n x y := by induction' n with n ih · simp [zero_nsmul] · simp_rw [succ_nsmul, ← ih, smul_eq_mul, add_mul] /-- Note that `AddMonoid.int_smulCommClass` requires stronger assumptions on `α`. -/ instance NonUnitalNonAssocRing.int_smulCommClass [NonUnitalNonAssocRing α] : SMulCommClass ℤ α α where smul_comm n x y := match n with | (n : ℕ) => by simp_rw [natCast_zsmul, smul_comm] | -[n+1] => by simp_rw [negSucc_zsmul, smul_eq_mul, mul_neg, mul_smul_comm] /-- Note that `AddCommGroup.int_isScalarTower` requires stronger assumptions on `α`. -/ instance NonUnitalNonAssocRing.int_isScalarTower [NonUnitalNonAssocRing α] : IsScalarTower ℤ α α where smul_assoc n x y := match n with | (n : ℕ) => by simp_rw [natCast_zsmul, smul_assoc] | -[n+1] => by simp_rw [negSucc_zsmul, smul_eq_mul, neg_mul, smul_mul_assoc]
GroupTheory\GroupAction\SubMulAction.lean
/- Copyright (c) 2020 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.Module.Defs import Mathlib.Data.SetLike.Basic import Mathlib.GroupTheory.GroupAction.Basic import Mathlib.GroupTheory.GroupAction.Hom /-! # Sets invariant to a `MulAction` In this file we define `SubMulAction R M`; a subset of a `MulAction R M` which is closed with respect to scalar multiplication. For most uses, typically `Submodule R M` is more powerful. ## Main definitions * `SubMulAction.mulAction` - the `MulAction R M` transferred to the subtype. * `SubMulAction.mulAction'` - the `MulAction S M` transferred to the subtype when `IsScalarTower S R M`. * `SubMulAction.isScalarTower` - the `IsScalarTower S R M` transferred to the subtype. * `SubMulAction.inclusion` — the inclusion of a submulaction, as an equivariant map ## Tags submodule, mul_action -/ open Function universe u u' u'' v variable {S : Type u'} {T : Type u''} {R : Type u} {M : Type v} /-- `SMulMemClass S R M` says `S` is a type of subsets `s ≤ M` that are closed under the scalar action of `R` on `M`. Note that only `R` is marked as an `outParam` here, since `M` is supplied by the `SetLike` class instead. -/ class SMulMemClass (S : Type*) (R : outParam Type*) (M : Type*) [SMul R M] [SetLike S M] : Prop where /-- Multiplication by a scalar on an element of the set remains in the set. -/ smul_mem : ∀ {s : S} (r : R) {m : M}, m ∈ s → r • m ∈ s /-- `VAddMemClass S R M` says `S` is a type of subsets `s ≤ M` that are closed under the additive action of `R` on `M`. Note that only `R` is marked as an `outParam` here, since `M` is supplied by the `SetLike` class instead. -/ class VAddMemClass (S : Type*) (R : outParam Type*) (M : Type*) [VAdd R M] [SetLike S M] : Prop where /-- Addition by a scalar with an element of the set remains in the set. -/ vadd_mem : ∀ {s : S} (r : R) {m : M}, m ∈ s → r +ᵥ m ∈ s attribute [to_additive] SMulMemClass attribute [aesop safe 10 apply (rule_sets := [SetLike])] SMulMemClass.smul_mem VAddMemClass.vadd_mem /-- Not registered as an instance because `R` is an `outParam` in `SMulMemClass S R M`. -/ lemma AddSubmonoidClass.nsmulMemClass {S M : Type*} [AddMonoid M] [SetLike S M] [AddSubmonoidClass S M] : SMulMemClass S ℕ M where smul_mem n _x hx := nsmul_mem hx n /-- Not registered as an instance because `R` is an `outParam` in `SMulMemClass S R M`. -/ lemma AddSubgroupClass.zsmulMemClass {S M : Type*} [SubNegMonoid M] [SetLike S M] [AddSubgroupClass S M] : SMulMemClass S ℤ M where smul_mem n _x hx := zsmul_mem hx n namespace SetLike open SMulMemClass section SMul variable [SMul R M] [SetLike S M] [hS : SMulMemClass S R M] (s : S) -- lower priority so other instances are found first /-- A subset closed under the scalar action inherits that action. -/ @[to_additive "A subset closed under the additive action inherits that action."] instance (priority := 50) smul : SMul R s := ⟨fun r x => ⟨r • x.1, smul_mem r x.2⟩⟩ /-- This can't be an instance because Lean wouldn't know how to find `N`, but we can still use this to manually derive `SMulMemClass` on specific types. -/ theorem _root_.SMulMemClass.ofIsScalarTower (S M N α : Type*) [SetLike S α] [SMul M N] [SMul M α] [Monoid N] [MulAction N α] [SMulMemClass S N α] [IsScalarTower M N α] : SMulMemClass S M α := { smul_mem := fun m a ha => smul_one_smul N m a ▸ SMulMemClass.smul_mem _ ha } instance instIsScalarTower [Mul M] [MulMemClass S M] [IsScalarTower R M M] (s : S) : IsScalarTower R s s where smul_assoc r x y := Subtype.ext <| smul_assoc r (x : M) (y : M) instance instSMulCommClass [Mul M] [MulMemClass S M] [SMulCommClass R M M] (s : S) : SMulCommClass R s s where smul_comm r x y := Subtype.ext <| smul_comm r (x : M) (y : M) -- Porting note (#11215): TODO lower priority not actually there -- lower priority so later simp lemmas are used first; to appease simp_nf @[to_additive (attr := simp, norm_cast)] protected theorem val_smul (r : R) (x : s) : (↑(r • x) : M) = r • (x : M) := rfl -- Porting note (#11215): TODO lower priority not actually there -- lower priority so later simp lemmas are used first; to appease simp_nf @[to_additive (attr := simp)] theorem mk_smul_mk (r : R) (x : M) (hx : x ∈ s) : r • (⟨x, hx⟩ : s) = ⟨r • x, smul_mem r hx⟩ := rfl @[to_additive] theorem smul_def (r : R) (x : s) : r • x = ⟨r • x, smul_mem r x.2⟩ := rfl @[simp] theorem forall_smul_mem_iff {R M S : Type*} [Monoid R] [MulAction R M] [SetLike S M] [SMulMemClass S R M] {N : S} {x : M} : (∀ a : R, a • x ∈ N) ↔ x ∈ N := ⟨fun h => by simpa using h 1, fun h a => SMulMemClass.smul_mem a h⟩ end SMul section OfTower variable {N α : Type*} [SetLike S α] [SMul M N] [SMul M α] [Monoid N] [MulAction N α] [SMulMemClass S N α] [IsScalarTower M N α] (s : S) -- lower priority so other instances are found first /-- A subset closed under the scalar action inherits that action. -/ @[to_additive "A subset closed under the additive action inherits that action."] instance (priority := 50) smul' : SMul M s where smul r x := ⟨r • x.1, smul_one_smul N r x.1 ▸ smul_mem _ x.2⟩ @[to_additive (attr := simp, norm_cast)] protected theorem val_smul_of_tower (r : M) (x : s) : (↑(r • x) : α) = r • (x : α) := rfl @[to_additive (attr := simp)] theorem mk_smul_of_tower_mk (r : M) (x : α) (hx : x ∈ s) : r • (⟨x, hx⟩ : s) = ⟨r • x, smul_one_smul N r x ▸ smul_mem _ hx⟩ := rfl @[to_additive] theorem smul_of_tower_def (r : M) (x : s) : r • x = ⟨r • x, smul_one_smul N r x.1 ▸ smul_mem _ x.2⟩ := rfl end OfTower end SetLike /-- A SubMulAction is a set which is closed under scalar multiplication. -/ structure SubMulAction (R : Type u) (M : Type v) [SMul R M] : Type v where /-- The underlying set of a `SubMulAction`. -/ carrier : Set M /-- The carrier set is closed under scalar multiplication. -/ smul_mem' : ∀ (c : R) {x : M}, x ∈ carrier → c • x ∈ carrier namespace SubMulAction variable [SMul R M] instance : SetLike (SubMulAction R M) M := ⟨SubMulAction.carrier, fun p q h => by cases p; cases q; congr⟩ instance : SMulMemClass (SubMulAction R M) R M where smul_mem := smul_mem' _ @[simp] theorem mem_carrier {p : SubMulAction R M} {x : M} : x ∈ p.carrier ↔ x ∈ (p : Set M) := Iff.rfl @[ext] theorem ext {p q : SubMulAction R M} (h : ∀ x, x ∈ p ↔ x ∈ q) : p = q := SetLike.ext h /-- Copy of a sub_mul_action with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (p : SubMulAction R M) (s : Set M) (hs : s = ↑p) : SubMulAction R M where carrier := s smul_mem' := hs.symm ▸ p.smul_mem' @[simp] theorem coe_copy (p : SubMulAction R M) (s : Set M) (hs : s = ↑p) : (p.copy s hs : Set M) = s := rfl theorem copy_eq (p : SubMulAction R M) (s : Set M) (hs : s = ↑p) : p.copy s hs = p := SetLike.coe_injective hs instance : Bot (SubMulAction R M) where bot := { carrier := ∅ smul_mem' := fun _c h => Set.not_mem_empty h } instance : Inhabited (SubMulAction R M) := ⟨⊥⟩ end SubMulAction namespace SubMulAction section SMul variable [SMul R M] variable (p : SubMulAction R M) variable {r : R} {x : M} theorem smul_mem (r : R) (h : x ∈ p) : r • x ∈ p := p.smul_mem' r h instance : SMul R p where smul c x := ⟨c • x.1, smul_mem _ c x.2⟩ variable {p} @[simp, norm_cast] theorem val_smul (r : R) (x : p) : (↑(r • x) : M) = r • (x : M) := rfl -- Porting note: no longer needed because of defeq structure eta variable (p) /-- Embedding of a submodule `p` to the ambient space `M`. -/ protected def subtype : p →[R] M where toFun := Subtype.val map_smul' := by simp [val_smul] @[simp] theorem subtype_apply (x : p) : p.subtype x = x := rfl theorem subtype_eq_val : (SubMulAction.subtype p : p → M) = Subtype.val := rfl end SMul namespace SMulMemClass variable [Monoid R] [MulAction R M] {A : Type*} [SetLike A M] variable [hA : SMulMemClass A R M] (S' : A) -- Prefer subclasses of `MulAction` over `SMulMemClass`. /-- A `SubMulAction` of a `MulAction` is a `MulAction`. -/ instance (priority := 75) toMulAction : MulAction R S' := Subtype.coe_injective.mulAction Subtype.val (SetLike.val_smul S') /-- The natural `MulActionHom` over `R` from a `SubMulAction` of `M` to `M`. -/ protected def subtype : S' →[R] M where toFun := Subtype.val; map_smul' _ _ := rfl @[simp] protected theorem coeSubtype : (SMulMemClass.subtype S' : S' → M) = Subtype.val := rfl end SMulMemClass section MulActionMonoid variable [Monoid R] [MulAction R M] section variable [SMul S R] [SMul S M] [IsScalarTower S R M] variable (p : SubMulAction R M) theorem smul_of_tower_mem (s : S) {x : M} (h : x ∈ p) : s • x ∈ p := by rw [← one_smul R x, ← smul_assoc] exact p.smul_mem _ h instance smul' : SMul S p where smul c x := ⟨c • x.1, smul_of_tower_mem _ c x.2⟩ instance isScalarTower : IsScalarTower S R p where smul_assoc s r x := Subtype.ext <| smul_assoc s r (x : M) instance isScalarTower' {S' : Type*} [SMul S' R] [SMul S' S] [SMul S' M] [IsScalarTower S' R M] [IsScalarTower S' S M] : IsScalarTower S' S p where smul_assoc s r x := Subtype.ext <| smul_assoc s r (x : M) @[simp, norm_cast] theorem val_smul_of_tower (s : S) (x : p) : ((s • x : p) : M) = s • (x : M) := rfl @[simp] theorem smul_mem_iff' {G} [Group G] [SMul G R] [MulAction G M] [IsScalarTower G R M] (g : G) {x : M} : g • x ∈ p ↔ x ∈ p := ⟨fun h => inv_smul_smul g x ▸ p.smul_of_tower_mem g⁻¹ h, p.smul_of_tower_mem g⟩ instance isCentralScalar [SMul Sᵐᵒᵖ R] [SMul Sᵐᵒᵖ M] [IsScalarTower Sᵐᵒᵖ R M] [IsCentralScalar S M] : IsCentralScalar S p where op_smul_eq_smul r x := Subtype.ext <| op_smul_eq_smul r (x : M) end section variable [Monoid S] [SMul S R] [MulAction S M] [IsScalarTower S R M] variable (p : SubMulAction R M) /-- If the scalar product forms a `MulAction`, then the subset inherits this action -/ instance mulAction' : MulAction S p where smul := (· • ·) one_smul x := Subtype.ext <| one_smul _ (x : M) mul_smul c₁ c₂ x := Subtype.ext <| mul_smul c₁ c₂ (x : M) instance mulAction : MulAction R p := p.mulAction' end /-- Orbits in a `SubMulAction` coincide with orbits in the ambient space. -/ theorem val_image_orbit {p : SubMulAction R M} (m : p) : Subtype.val '' MulAction.orbit R m = MulAction.orbit R (m : M) := (Set.range_comp _ _).symm /- -- Previously, the relatively useless : lemma orbit_of_sub_mul {p : SubMulAction R M} (m : p) : (mul_action.orbit R m : set M) = MulAction.orbit R (m : M) := rfl -/ theorem val_preimage_orbit {p : SubMulAction R M} (m : p) : Subtype.val ⁻¹' MulAction.orbit R (m : M) = MulAction.orbit R m := by rw [← val_image_orbit, Subtype.val_injective.preimage_image] lemma mem_orbit_subMul_iff {p : SubMulAction R M} {x m : p} : x ∈ MulAction.orbit R m ↔ (x : M) ∈ MulAction.orbit R (m : M) := by rw [← val_preimage_orbit, Set.mem_preimage] /-- Stabilizers in monoid SubMulAction coincide with stabilizers in the ambient space -/ theorem stabilizer_of_subMul.submonoid {p : SubMulAction R M} (m : p) : MulAction.stabilizerSubmonoid R m = MulAction.stabilizerSubmonoid R (m : M) := by ext simp only [MulAction.mem_stabilizerSubmonoid_iff, ← SubMulAction.val_smul, SetLike.coe_eq_coe] end MulActionMonoid section MulActionGroup variable [Group R] [MulAction R M] lemma orbitRel_of_subMul (p : SubMulAction R M) : MulAction.orbitRel R p = (MulAction.orbitRel R M).comap Subtype.val := by refine Setoid.ext_iff.2 (fun x y ↦ ?_) rw [Setoid.comap_rel] exact mem_orbit_subMul_iff /-- Stabilizers in group SubMulAction coincide with stabilizers in the ambient space -/ theorem stabilizer_of_subMul {p : SubMulAction R M} (m : p) : MulAction.stabilizer R m = MulAction.stabilizer R (m : M) := by rw [← Subgroup.toSubmonoid_eq] exact stabilizer_of_subMul.submonoid m end MulActionGroup section Module variable [Semiring R] [AddCommMonoid M] variable [Module R M] variable (p : SubMulAction R M) theorem zero_mem (h : (p : Set M).Nonempty) : (0 : M) ∈ p := let ⟨x, hx⟩ := h zero_smul R (x : M) ▸ p.smul_mem 0 hx /-- If the scalar product forms a `Module`, and the `SubMulAction` is not `⊥`, then the subset inherits the zero. -/ instance [n_empty : Nonempty p] : Zero p where zero := ⟨0, n_empty.elim fun x => p.zero_mem ⟨x, x.prop⟩⟩ end Module section AddCommGroup variable [Ring R] [AddCommGroup M] variable [Module R M] variable (p p' : SubMulAction R M) variable {r : R} {x y : M} theorem neg_mem (hx : x ∈ p) : -x ∈ p := by rw [← neg_one_smul R] exact p.smul_mem _ hx @[simp] theorem neg_mem_iff : -x ∈ p ↔ x ∈ p := ⟨fun h => by rw [← neg_neg x] exact neg_mem _ h, neg_mem _⟩ instance : Neg p := ⟨fun x => ⟨-x.1, neg_mem _ x.2⟩⟩ @[simp, norm_cast] theorem val_neg (x : p) : ((-x : p) : M) = -x := rfl end AddCommGroup end SubMulAction namespace SubMulAction variable [GroupWithZero S] [Monoid R] [MulAction R M] variable [SMul S R] [MulAction S M] [IsScalarTower S R M] variable (p : SubMulAction R M) {s : S} {x y : M} theorem smul_mem_iff (s0 : s ≠ 0) : s • x ∈ p ↔ x ∈ p := p.smul_mem_iff' (Units.mk0 s s0) end SubMulAction namespace SubMulAction /- The inclusion of a SubMulaction, as an equivariant map -/ variable {M α : Type*} [Monoid M] [MulAction M α] /-- The inclusion of a SubMulAction into the ambient set, as an equivariant map -/ def inclusion (s : SubMulAction M α) : s →[M] α where -- The inclusion map of the inclusion of a SubMulAction toFun := Subtype.val -- The commutation property map_smul' _ _ := rfl theorem inclusion.toFun_eq_coe (s : SubMulAction M α) : s.inclusion.toFun = Subtype.val := rfl theorem inclusion.coe_eq (s : SubMulAction M α) : ⇑s.inclusion = Subtype.val := rfl lemma image_inclusion (s : SubMulAction M α) : Set.range s.inclusion = s.carrier := by rw [inclusion.coe_eq] exact Subtype.range_coe lemma inclusion_injective (s : SubMulAction M α) : Function.Injective s.inclusion := Subtype.val_injective end SubMulAction
GroupTheory\GroupAction\Support.lean
/- Copyright (c) 2022 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Data.Set.Pointwise.SMul /-! # Support of an element under an action action Given an action of a group `G` on a type `α`, we say that a set `s : Set α` supports an element `a : α` if, for all `g` that fix `s` pointwise, `g` fixes `a`. This is crucial in Fourier-Motzkin constructions. -/ open Pointwise variable {G H α β : Type*} namespace MulAction section SMul variable (G) [SMul G α] [SMul G β] /-- A set `s` supports `b` if `g • b = b` whenever `g • a = a` for all `a ∈ s`. -/ @[to_additive "A set `s` supports `b` if `g +ᵥ b = b` whenever `g +ᵥ a = a` for all `a ∈ s`."] def Supports (s : Set α) (b : β) := ∀ g : G, (∀ ⦃a⦄, a ∈ s → g • a = a) → g • b = b variable {s t : Set α} {a : α} {b : β} @[to_additive] theorem supports_of_mem (ha : a ∈ s) : Supports G s a := fun _ h => h ha variable {G} @[to_additive] theorem Supports.mono (h : s ⊆ t) (hs : Supports G s b) : Supports G t b := fun _ hg => (hs _) fun _ ha => hg <| h ha end SMul variable [Group H] [SMul G α] [SMul G β] [MulAction H α] [SMul H β] [SMulCommClass G H β] [SMulCommClass G H α] {s t : Set α} {b : β} -- TODO: This should work without `SMulCommClass` @[to_additive] theorem Supports.smul (g : H) (h : Supports G s b) : Supports G (g • s) (g • b) := by rintro g' hg' rw [smul_comm, h] rintro a ha have := Set.forall_mem_image.1 hg' ha rwa [smul_comm, smul_left_cancel_iff] at this end MulAction
GroupTheory\GroupAction\DomAct\ActionHom.lean
/- Copyright (c) 2023 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.GroupTheory.GroupAction.DomAct.Basic import Mathlib.GroupTheory.GroupAction.Hom /-! # Action of `Mᵈᵐᵃ` on `α →[N] β` and `A →+[N] B` In this file we define action of `DomMulAct M = Mᵈᵐᵃ` on `α →[N] β` and on `A →+[N] B`. At the time of writing, these homomorphisms are not widely used in the library, so we put these instances into a separate file, not with the definition of `DomMulAct`. ## TODO Add left actions of, e.g., `M` on `α →[N] β` to `Mathlib.Algebra.Hom.GroupAction` and `SMulCommClass` instances saying that left and right actions commute. -/ namespace DomMulAct section MulActionSemiHom section SMul variable {M α N β : Type*} variable [SMul M α] [SMul N α] [SMulCommClass M N α] [SMul N β] instance : SMul Mᵈᵐᵃ (α →[N] β) where smul c f := f.comp (SMulCommClass.toMulActionHom _ _ (mk.symm c)) instance {M' : Type*} [SMul M' α] [SMulCommClass M' N α] [SMulCommClass M M' α] : SMulCommClass Mᵈᵐᵃ M'ᵈᵐᵃ (α →[N] β) := DFunLike.coe_injective.smulCommClass (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) theorem smul_mulActionHom_apply (c : Mᵈᵐᵃ) (f : α →[N] β) (a : α) : (c • f) a = f (mk.symm c • a) := rfl @[simp] theorem mk_smul_mulActionHom_apply (c : M) (f : α →[N] β) (a : α) : (mk c • f) a = f (c • a) := rfl end SMul instance {M α N β : Type*} [Monoid M] [MulAction M α] [SMul N α] [SMulCommClass M N α] [SMul N β] : MulAction Mᵈᵐᵃ (α →[N] β) := DFunLike.coe_injective.mulAction _ fun _ _ ↦ rfl end MulActionSemiHom section DistribMulActionHom section SMul variable {M N A B : Type*} [AddMonoid A] [DistribSMul M A] [Monoid N] [AddMonoid B] [DistribMulAction N A] [SMulCommClass M N A] [DistribMulAction N B] instance : SMul Mᵈᵐᵃ (A →+[N] B) where smul c f := f.comp (SMulCommClass.toDistribMulActionHom _ _ (mk.symm c)) instance {M' : Type*} [DistribSMul M' A] [SMulCommClass M' N A] [SMulCommClass M M' A] : SMulCommClass Mᵈᵐᵃ M'ᵈᵐᵃ (A →+[N] B) := DFunLike.coe_injective.smulCommClass (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) theorem smul_mulDistribActionHom_apply (c : Mᵈᵐᵃ) (f : A →+[N] B) (a : A) : (c • f) a = f (mk.symm c • a) := rfl @[simp] theorem mk_smul_mulDistribActionHom_apply (c : M) (f : A →+[N] B) (a : A) : (mk c • f) a = f (c • a) := rfl end SMul instance {M N A B : Type*} [Monoid M] [AddMonoid A] [DistribMulAction M A] [Monoid N] [AddMonoid B] [DistribMulAction N A] [SMulCommClass M N A] [DistribMulAction N B] : MulAction Mᵈᵐᵃ (A →+[N] B) := DFunLike.coe_injective.mulAction _ fun _ _ ↦ rfl end DistribMulActionHom end DomMulAct
GroupTheory\GroupAction\DomAct\Basic.lean
/- Copyright (c) 2023 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.Group.Opposite import Mathlib.Algebra.Group.Pi.Lemmas import Mathlib.Algebra.GroupWithZero.Action.Defs import Mathlib.Algebra.Ring.Defs /-! # Type tags for right action on the domain of a function By default, `M` acts on `α → β` if it acts on `β`, and the action is given by `(c • f) a = c • (f a)`. In some cases, it is useful to consider another action: if `M` acts on `α` on the left, then it acts on `α → β` on the right so that `(c • f) a = f (c • a)`. E.g., this action is used to reformulate the Mean Ergodic Theorem in terms of an operator on \(L^2\). ## Main definitions - `DomMulAct M` (notation: `Mᵈᵐᵃ`): type synonym for `Mᵐᵒᵖ`; if `M` multiplicatively acts on `α`, then `Mᵈᵐᵃ` acts on `α → β` for any type `β`; - `DomAddAct M` (notation: `Mᵈᵃᵃ`): the additive version. We also define actions of `Mᵈᵐᵃ` on: - `α → β` provided that `M` acts on `α`; - `A →* B` provided that `M` acts on `A` by a `MulDistribMulAction`; - `A →+ B` provided that `M` acts on `A` by a `DistribMulAction`. ## Implementation details ### Motivation Right action can be represented in `mathlib` as an action of the opposite group `Mᵐᵒᵖ`. However, this "domain shift" action cannot be an instance because this would create a "diamond" (a.k.a. ambiguous notation): if `M` is a monoid, then how does `Mᵐᵒᵖ` act on `M → M`? On the one hand, `Mᵐᵒᵖ` acts on `M` by `c • a = a * c.unop`, thus we have an action `(c • f) a = f a * c.unop`. On the other hand, `M` acts on itself by multiplication on the left, so with this new instance we would have `(c • f) a = f (c.unop * a)`. Clearly, these are two different actions, so both of them cannot be instances in the library. To overcome this difficulty, we introduce a type synonym `DomMulAct M := Mᵐᵒᵖ` (notation: `Mᵈᵐᵃ`). This new type carries the same algebraic structures as `Mᵐᵒᵖ` but acts on `α → β` by this new action. So, e.g., `Mᵈᵐᵃ` acts on `(M → M) → M` by `DomMulAct.mk c • F f = F (fun a ↦ c • f a)` while `(Mᵈᵐᵃ)ᵈᵐᵃ` (which is isomorphic to `M`) acts on `(M → M) → M` by `DomMulAct.mk (DomMulAct.mk c) • F f = F (fun a ↦ f (c • a))`. ### Action on bundled homomorphisms If the action of `M` on `A` preserves some structure, then `Mᵈᵐᵃ` acts on bundled homomorphisms from `A` to any type `B` that preserve the same structure. Examples (some of them are not yet in the library) include: - a `MulDistribMulAction` generates an action on `A →* B`; - a `DistribMulAction` generates an action on `A →+ B`; - an action on `α` that commutes with action of some other monoid `N` generates an action on `α →[N] β`; - a `DistribMulAction` on an `R`-module that commutes with scalar multiplications by `c : R` generates an action on `R`-linear maps from this module; - a continuous action on `X` generates an action on `C(X, Y)`; - a measurable action on `X` generates an action on `{ f : X → Y // Measurable f }`; - a quasi measure preserving action on `X` generates an action on `X →ₘ[μ] Y`; - a measure preserving action generates an isometric action on `MeasureTheory.Lp _ _ _`. ### Left action vs right action It is common in the literature to consider the left action given by `(c • f) a = f (c⁻¹ • a)` instead of the action defined in this file. However, this left action is defined only if `c` belongs to a group, not to a monoid, so we decided to go with the right action. The left action can be written in terms of `DomMulAct` as `(DomMulAct.mk c)⁻¹ • f`. As for higher level dynamics objects (orbits, invariant functions etc), they coincide for the left and for the right action, so lemmas can be formulated in terms of `DomMulAct`. ## Keywords group action, function, domain -/ open Function /-- If `M` multiplicatively acts on `α`, then `DomMulAct M` acts on `α → β` as well as some bundled maps from `α`. This is a type synonym for `MulOpposite M`, so this corresponds to a right action of `M`. -/ @[to_additive "If `M` additively acts on `α`, then `DomAddAct M` acts on `α → β` as well as some bundled maps from `α`. This is a type synonym for `AddOpposite M`, so this corresponds to a right action of `M`."] def DomMulAct (M : Type*) := MulOpposite M @[inherit_doc] postfix:max "ᵈᵐᵃ" => DomMulAct @[inherit_doc] postfix:max "ᵈᵃᵃ" => DomAddAct namespace DomMulAct variable {M : Type*} /-- Equivalence between `M` and `Mᵈᵐᵃ`. -/ @[to_additive "Equivalence between `M` and `Mᵈᵐᵃ`."] def mk : M ≃ Mᵈᵐᵃ := MulOpposite.opEquiv /-! ### Copy instances from `Mᵐᵒᵖ` -/ set_option hygiene false in run_cmd for n in [`Mul, `One, `Inv, `Semigroup, `CommSemigroup, `LeftCancelSemigroup, `RightCancelSemigroup, `MulOneClass, `Monoid, `CommMonoid, `LeftCancelMonoid, `RightCancelMonoid, `CancelMonoid, `CancelCommMonoid, `InvolutiveInv, `DivInvMonoid, `InvOneClass, `DivInvOneMonoid, `DivisionMonoid, `DivisionCommMonoid, `Group, `CommGroup, `NonAssocSemiring, `NonUnitalSemiring, `NonAssocSemiring, `Semiring, `Ring, `CommRing].map Lean.mkIdent do Lean.Elab.Command.elabCommand (← `( @[to_additive] instance [$n Mᵐᵒᵖ] : $n Mᵈᵐᵃ := ‹_› )) @[to_additive] instance [Mul Mᵐᵒᵖ] [IsLeftCancelMul Mᵐᵒᵖ] : IsLeftCancelMul Mᵈᵐᵃ := ‹_› @[to_additive] instance [Mul Mᵐᵒᵖ] [IsRightCancelMul Mᵐᵒᵖ] : IsRightCancelMul Mᵈᵐᵃ := ‹_› @[to_additive] instance [Mul Mᵐᵒᵖ] [IsCancelMul Mᵐᵒᵖ] : IsCancelMul Mᵈᵐᵃ := ‹_› @[to_additive (attr := simp)] lemma mk_one [One M] : mk (1 : M) = 1 := rfl @[to_additive (attr := simp)] lemma symm_mk_one [One M] : mk.symm (1 : Mᵈᵐᵃ) = 1 := rfl @[to_additive (attr := simp)] lemma mk_mul [Mul M] (a b : M) : mk (a * b) = mk b * mk a := rfl @[to_additive (attr := simp)] lemma symm_mk_mul [Mul M] (a b : Mᵈᵐᵃ) : mk.symm (a * b) = mk.symm b * mk.symm a := rfl @[to_additive (attr := simp)] lemma mk_inv [Inv M] (a : M) : mk (a⁻¹) = (mk a)⁻¹ := rfl @[to_additive (attr := simp)] lemma symm_mk_inv [Inv M] (a : Mᵈᵐᵃ) : mk.symm (a⁻¹) = (mk.symm a)⁻¹ := rfl @[to_additive (attr := simp)] lemma mk_pow [Monoid M] (a : M) (n : ℕ) : mk (a ^ n) = mk a ^ n := rfl @[to_additive (attr := simp)] lemma symm_mk_pow [Monoid M] (a : Mᵈᵐᵃ) (n : ℕ) : mk.symm (a ^ n) = mk.symm a ^ n := rfl @[to_additive (attr := simp)] lemma mk_zpow [DivInvMonoid M] (a : M) (n : ℤ) : mk (a ^ n) = mk a ^ n := rfl @[to_additive (attr := simp)] lemma symm_mk_zpow [DivInvMonoid M] (a : Mᵈᵐᵃ) (n : ℤ) : mk.symm (a ^ n) = mk.symm a ^ n := rfl variable {β α N : Type*} @[to_additive] instance [SMul M α] : SMul Mᵈᵐᵃ (α → β) where smul c f a := f (mk.symm c • a) @[to_additive] theorem smul_apply [SMul M α] (c : Mᵈᵐᵃ) (f : α → β) (a : α) : (c • f) a = f (mk.symm c • a) := rfl @[to_additive] instance [SMul M α] [SMul N β] : SMulCommClass Mᵈᵐᵃ N (α → β) where smul_comm _ _ _ := rfl @[to_additive] instance [SMul M α] [SMul N β] : SMulCommClass N Mᵈᵐᵃ (α → β) where smul_comm _ _ _ := rfl @[to_additive] instance [SMul M α] [SMul N α] [SMulCommClass M N α] : SMulCommClass Mᵈᵐᵃ Nᵈᵐᵃ (α → β) where smul_comm _ _ f := funext fun _ ↦ congr_arg f (smul_comm _ _ _).symm @[to_additive] instance [SMul M α] [FaithfulSMul M α] [Nontrivial β] : FaithfulSMul Mᵈᵐᵃ (α → β) where eq_of_smul_eq_smul {c₁ c₂} h := mk.symm.injective <| eq_of_smul_eq_smul fun a : α ↦ by rcases exists_pair_ne β with ⟨x, y, hne⟩ contrapose! hne haveI := Classical.decEq α replace h := congr_fun (h (update (const α x) (mk.symm c₂ • a) y)) a simpa [smul_apply, hne] using h instance [SMul M α] [Zero β] : SMulZeroClass Mᵈᵐᵃ (α → β) where smul_zero _ := rfl instance {A : Type*} [SMul M α] [AddZeroClass A] : DistribSMul Mᵈᵐᵃ (α → A) where smul_add _ _ _ := rfl @[to_additive] instance [Monoid M] [MulAction M α] : MulAction Mᵈᵐᵃ (α → β) where one_smul f := funext fun _ ↦ congr_arg f (one_smul _ _) mul_smul _ _ f := funext fun _ ↦ congr_arg f (mul_smul _ _ _) instance {A : Type*} [Monoid M] [MulAction M α] [AddMonoid A] : DistribMulAction Mᵈᵐᵃ (α → A) where smul_zero _ := rfl smul_add _ _ _ := rfl instance {A : Type*} [Monoid M] [MulAction M α] [Monoid A] : MulDistribMulAction Mᵈᵐᵃ (α → A) where smul_mul _ _ _ := rfl smul_one _ := rfl section MonoidHom variable {M M' A B : Type*} [Monoid M] [Monoid A] [MulDistribMulAction M A] [MulOneClass B] instance : SMul Mᵈᵐᵃ (A →* B) where smul c f := f.comp (MulDistribMulAction.toMonoidHom _ (mk.symm c)) instance [Monoid M'] [MulDistribMulAction M' A] [SMulCommClass M M' A] : SMulCommClass Mᵈᵐᵃ M'ᵈᵐᵃ (A →* B) := DFunLike.coe_injective.smulCommClass (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) theorem smul_monoidHom_apply (c : Mᵈᵐᵃ) (f : A →* B) (a : A) : (c • f) a = f (mk.symm c • a) := rfl @[simp] theorem mk_smul_monoidHom_apply (c : M) (f : A →* B) (a : A) : (mk c • f) a = f (c • a) := rfl instance : MulAction Mᵈᵐᵃ (A →* B) := DFunLike.coe_injective.mulAction (⇑) fun _ _ ↦ rfl end MonoidHom section AddMonoidHom section DistribSMul variable {A B M M' : Type*} [AddMonoid A] [DistribSMul M A] [AddZeroClass B] instance : SMul Mᵈᵐᵃ (A →+ B) where smul c f := f.comp (DistribSMul.toAddMonoidHom _ (mk.symm c)) instance [DistribSMul M' A] [SMulCommClass M M' A] : SMulCommClass Mᵈᵐᵃ M'ᵈᵐᵃ (A →+ B) := DFunLike.coe_injective.smulCommClass (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) instance [DistribSMul M' B] : SMulCommClass Mᵈᵐᵃ M' (A →+ B) := DFunLike.coe_injective.smulCommClass (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) theorem smul_addMonoidHom_apply (c : Mᵈᵐᵃ) (f : A →+ B) (a : A) : (c • f) a = f (mk.symm c • a) := rfl @[simp] theorem mk_smul_addMonoidHom_apply (c : M) (f : A →+ B) (a : A) : (mk c • f) a = f (c • a) := rfl theorem coe_smul_addMonoidHom (c : Mᵈᵐᵃ) (f : A →+ B) : ⇑(c • f) = c • ⇑f := rfl end DistribSMul variable {A M B : Type*} instance [Monoid M] [AddMonoid A] [DistribMulAction M A] [AddZeroClass B] : MulAction Mᵈᵐᵃ (A →+ B) := DFunLike.coe_injective.mulAction (⇑) fun _ _ ↦ rfl instance [Monoid M] [AddMonoid A] [DistribMulAction M A] [AddCommMonoid B] : DistribMulAction Mᵈᵐᵃ (A →+ B) := DFunLike.coe_injective.distribMulAction (AddMonoidHom.coeFn A B) fun _ _ ↦ rfl instance [Monoid M] [Monoid A] [MulDistribMulAction M A] [CommMonoid B] : MulDistribMulAction Mᵈᵐᵃ (A →* B) := DFunLike.coe_injective.mulDistribMulAction (MonoidHom.coeFn A B) fun _ _ ↦ rfl end AddMonoidHom end DomMulAct
GroupTheory\GroupAction\SubMulAction\Pointwise.lean
/- Copyright (c) 2022 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.GroupTheory.GroupAction.SubMulAction /-! # Pointwise monoid structures on SubMulAction This file provides `SubMulAction.Monoid` and weaker typeclasses, which show that `SubMulAction`s inherit the same pointwise multiplications as sets. To match `Submodule.idemSemiring`, we do not put these in the `Pointwise` locale. -/ open Pointwise variable {R M : Type*} namespace SubMulAction section One variable [Monoid R] [MulAction R M] [One M] instance : One (SubMulAction R M) where one := { carrier := Set.range fun r : R => r • (1 : M) smul_mem' := fun r _ ⟨r', hr'⟩ => hr' ▸ ⟨r * r', mul_smul _ _ _⟩ } theorem coe_one : ↑(1 : SubMulAction R M) = Set.range fun r : R => r • (1 : M) := rfl @[simp] theorem mem_one {x : M} : x ∈ (1 : SubMulAction R M) ↔ ∃ r : R, r • (1 : M) = x := Iff.rfl theorem subset_coe_one : (1 : Set M) ⊆ (1 : SubMulAction R M) := fun _ hx => ⟨1, (one_smul _ _).trans hx.symm⟩ end One section Mul variable [Monoid R] [MulAction R M] [Mul M] [IsScalarTower R M M] instance : Mul (SubMulAction R M) where mul p q := { carrier := Set.image2 (· * ·) p q smul_mem' := fun r _ ⟨m₁, hm₁, m₂, hm₂, h⟩ => h ▸ smul_mul_assoc r m₁ m₂ ▸ Set.mul_mem_mul (p.smul_mem _ hm₁) hm₂ } @[norm_cast] theorem coe_mul (p q : SubMulAction R M) : ↑(p * q) = (p * q : Set M) := rfl theorem mem_mul {p q : SubMulAction R M} {x : M} : x ∈ p * q ↔ ∃ y ∈ p, ∃ z ∈ q, y * z = x := Set.mem_mul end Mul section MulOneClass variable [Monoid R] [MulAction R M] [MulOneClass M] [IsScalarTower R M M] [SMulCommClass R M M] -- Porting note: giving the instance the name `mulOneClass` instance mulOneClass : MulOneClass (SubMulAction R M) where mul := (· * ·) one := 1 mul_one a := by ext x simp only [mem_mul, mem_one, mul_smul_comm, exists_exists_eq_and, mul_one] constructor · rintro ⟨y, hy, r, rfl⟩ exact smul_mem _ _ hy · intro hx exact ⟨x, hx, 1, one_smul _ _⟩ one_mul a := by ext x simp only [mem_mul, mem_one, smul_mul_assoc, exists_exists_eq_and, one_mul] refine ⟨?_, fun hx => ⟨1, x, hx, one_smul _ _⟩⟩ rintro ⟨r, y, hy, rfl⟩ exact smul_mem _ _ hy end MulOneClass section Semigroup variable [Monoid R] [MulAction R M] [Semigroup M] [IsScalarTower R M M] -- Porting note: giving the instance the name `semiGroup` instance semiGroup : Semigroup (SubMulAction R M) where mul := (· * ·) mul_assoc _ _ _ := SetLike.coe_injective (mul_assoc (_ : Set _) _ _) end Semigroup section Monoid variable [Monoid R] [MulAction R M] [Monoid M] [IsScalarTower R M M] [SMulCommClass R M M] instance : Monoid (SubMulAction R M) := { SubMulAction.semiGroup, SubMulAction.mulOneClass with } theorem coe_pow (p : SubMulAction R M) : ∀ {n : ℕ} (_ : n ≠ 0), ↑(p ^ n) = (p : Set M) ^ n | 0, hn => (hn rfl).elim | 1, _ => by rw [pow_one, pow_one] | n + 2, _ => by rw [pow_succ _ (n + 1), pow_succ _ (n + 1), coe_mul, coe_pow _ n.succ_ne_zero] theorem subset_coe_pow (p : SubMulAction R M) : ∀ {n : ℕ}, (p : Set M) ^ n ⊆ ↑(p ^ n) | 0 => by rw [pow_zero, pow_zero] exact subset_coe_one | n + 1 => by rw [← Nat.succ_eq_add_one, coe_pow _ n.succ_ne_zero] end Monoid end SubMulAction
GroupTheory\MonoidLocalization\Basic.lean
/- Copyright (c) 2019 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Amelia Livingston -/ import Mathlib.Algebra.Group.Submonoid.Membership import Mathlib.GroupTheory.Congruence.Basic import Mathlib.RingTheory.OreLocalization.Basic /-! # Localizations of commutative monoids Localizing a commutative ring at one of its submonoids does not rely on the ring's addition, so we can generalize localizations to commutative monoids. We characterize the localization of a commutative monoid `M` at a submonoid `S` up to isomorphism; that is, a commutative monoid `N` is the localization of `M` at `S` iff we can find a monoid homomorphism `f : M →* N` satisfying 3 properties: 1. For all `y ∈ S`, `f y` is a unit; 2. For all `z : N`, there exists `(x, y) : M × S` such that `z * f y = f x`; 3. For all `x, y : M` such that `f x = f y`, there exists `c ∈ S` such that `x * c = y * c`. (The converse is a consequence of 1.) Given such a localization map `f : M →* N`, we can define the surjection `Submonoid.LocalizationMap.mk'` sending `(x, y) : M × S` to `f x * (f y)⁻¹`, and `Submonoid.LocalizationMap.lift`, the homomorphism from `N` induced by a homomorphism from `M` which maps elements of `S` to invertible elements of the codomain. Similarly, given commutative monoids `P, Q`, a submonoid `T` of `P` and a localization map for `T` from `P` to `Q`, then a homomorphism `g : M →* P` such that `g(S) ⊆ T` induces a homomorphism of localizations, `LocalizationMap.map`, from `N` to `Q`. We treat the special case of localizing away from an element in the sections `AwayMap` and `Away`. We also define the quotient of `M × S` by the unique congruence relation (equivalence relation preserving a binary operation) `r` such that for any other congruence relation `s` on `M × S` satisfying '`∀ y ∈ S`, `(1, 1) ∼ (y, y)` under `s`', we have that `(x₁, y₁) ∼ (x₂, y₂)` by `s` whenever `(x₁, y₁) ∼ (x₂, y₂)` by `r`. We show this relation is equivalent to the standard localization relation. This defines the localization as a quotient type, `Localization`, but the majority of subsequent lemmas in the file are given in terms of localizations up to isomorphism, using maps which satisfy the characteristic predicate. The Grothendieck group construction corresponds to localizing at the top submonoid, namely making every element invertible. ## Implementation notes In maths it is natural to reason up to isomorphism, but in Lean we cannot naturally `rewrite` one structure with an isomorphic one; one way around this is to isolate a predicate characterizing a structure up to isomorphism, and reason about things that satisfy the predicate. The infimum form of the localization congruence relation is chosen as 'canonical' here, since it shortens some proofs. To apply a localization map `f` as a function, we use `f.toMap`, as coercions don't work well for this structure. To reason about the localization as a quotient type, use `mk_eq_monoidOf_mk'` and associated lemmas. These show the quotient map `mk : M → S → Localization S` equals the surjection `LocalizationMap.mk'` induced by the map `Localization.monoidOf : Submonoid.LocalizationMap S (Localization S)` (where `of` establishes the localization as a quotient type satisfies the characteristic predicate). The lemma `mk_eq_monoidOf_mk'` hence gives you access to the results in the rest of the file, which are about the `LocalizationMap.mk'` induced by any localization map. ## TODO * Show that the localization at the top monoid is a group. * Generalise to (nonempty) subsemigroups. * If we acquire more bundlings, we can make `Localization.mkOrderEmbedding` be an ordered monoid embedding. ## Tags localization, monoid localization, quotient monoid, congruence relation, characteristic predicate, commutative monoid, grothendieck group -/ open Function namespace AddSubmonoid variable {M : Type*} [AddCommMonoid M] (S : AddSubmonoid M) (N : Type*) [AddCommMonoid N] /-- The type of AddMonoid homomorphisms satisfying the characteristic predicate: if `f : M →+ N` satisfies this predicate, then `N` is isomorphic to the localization of `M` at `S`. -/ -- Porting note(#5171): this linter isn't ported yet. -- @[nolint has_nonempty_instance] structure LocalizationMap extends AddMonoidHom M N where map_add_units' : ∀ y : S, IsAddUnit (toFun y) surj' : ∀ z : N, ∃ x : M × S, z + toFun x.2 = toFun x.1 exists_of_eq : ∀ x y, toFun x = toFun y → ∃ c : S, ↑c + x = ↑c + y -- Porting note: no docstrings for AddSubmonoid.LocalizationMap attribute [nolint docBlame] AddSubmonoid.LocalizationMap.map_add_units' AddSubmonoid.LocalizationMap.surj' AddSubmonoid.LocalizationMap.exists_of_eq /-- The AddMonoidHom underlying a `LocalizationMap` of `AddCommMonoid`s. -/ add_decl_doc LocalizationMap.toAddMonoidHom end AddSubmonoid section CommMonoid variable {M : Type*} [CommMonoid M] (S : Submonoid M) (N : Type*) [CommMonoid N] {P : Type*} [CommMonoid P] namespace Submonoid /-- The type of monoid homomorphisms satisfying the characteristic predicate: if `f : M →* N` satisfies this predicate, then `N` is isomorphic to the localization of `M` at `S`. -/ -- Porting note(#5171): this linter isn't ported yet. -- @[nolint has_nonempty_instance] structure LocalizationMap extends MonoidHom M N where map_units' : ∀ y : S, IsUnit (toFun y) surj' : ∀ z : N, ∃ x : M × S, z * toFun x.2 = toFun x.1 exists_of_eq : ∀ x y, toFun x = toFun y → ∃ c : S, ↑c * x = c * y -- Porting note: no docstrings for Submonoid.LocalizationMap attribute [nolint docBlame] Submonoid.LocalizationMap.map_units' Submonoid.LocalizationMap.surj' Submonoid.LocalizationMap.exists_of_eq attribute [to_additive] Submonoid.LocalizationMap -- Porting note: this translation already exists -- attribute [to_additive] Submonoid.LocalizationMap.toMonoidHom /-- The monoid hom underlying a `LocalizationMap`. -/ add_decl_doc LocalizationMap.toMonoidHom end Submonoid namespace Localization -- Porting note: this does not work so it is done explicitly instead -- run_cmd to_additive.map_namespace `Localization `AddLocalization -- run_cmd Elab.Command.liftCoreM <| ToAdditive.insertTranslation `Localization `AddLocalization /-- The congruence relation on `M × S`, `M` a `CommMonoid` and `S` a submonoid of `M`, whose quotient is the localization of `M` at `S`, defined as the unique congruence relation on `M × S` such that for any other congruence relation `s` on `M × S` where for all `y ∈ S`, `(1, 1) ∼ (y, y)` under `s`, we have that `(x₁, y₁) ∼ (x₂, y₂)` by `r` implies `(x₁, y₁) ∼ (x₂, y₂)` by `s`. -/ @[to_additive AddLocalization.r "The congruence relation on `M × S`, `M` an `AddCommMonoid` and `S` an `AddSubmonoid` of `M`, whose quotient is the localization of `M` at `S`, defined as the unique congruence relation on `M × S` such that for any other congruence relation `s` on `M × S` where for all `y ∈ S`, `(0, 0) ∼ (y, y)` under `s`, we have that `(x₁, y₁) ∼ (x₂, y₂)` by `r` implies `(x₁, y₁) ∼ (x₂, y₂)` by `s`."] def r (S : Submonoid M) : Con (M × S) := sInf { c | ∀ y : S, c 1 (y, y) } /-- An alternate form of the congruence relation on `M × S`, `M` a `CommMonoid` and `S` a submonoid of `M`, whose quotient is the localization of `M` at `S`. -/ @[to_additive AddLocalization.r' "An alternate form of the congruence relation on `M × S`, `M` a `CommMonoid` and `S` a submonoid of `M`, whose quotient is the localization of `M` at `S`."] def r' : Con (M × S) := by -- note we multiply by `c` on the left so that we can later generalize to `•` refine { r := fun a b : M × S ↦ ∃ c : S, ↑c * (↑b.2 * a.1) = c * (a.2 * b.1) iseqv := ⟨fun a ↦ ⟨1, rfl⟩, fun ⟨c, hc⟩ ↦ ⟨c, hc.symm⟩, ?_⟩ mul' := ?_ } · rintro a b c ⟨t₁, ht₁⟩ ⟨t₂, ht₂⟩ use t₂ * t₁ * b.2 simp only [Submonoid.coe_mul] calc (t₂ * t₁ * b.2 : M) * (c.2 * a.1) = t₂ * c.2 * (t₁ * (b.2 * a.1)) := by ac_rfl _ = t₁ * a.2 * (t₂ * (c.2 * b.1)) := by rw [ht₁]; ac_rfl _ = t₂ * t₁ * b.2 * (a.2 * c.1) := by rw [ht₂]; ac_rfl · rintro a b c d ⟨t₁, ht₁⟩ ⟨t₂, ht₂⟩ use t₂ * t₁ calc (t₂ * t₁ : M) * (b.2 * d.2 * (a.1 * c.1)) = t₂ * (d.2 * c.1) * (t₁ * (b.2 * a.1)) := by ac_rfl _ = (t₂ * t₁ : M) * (a.2 * c.2 * (b.1 * d.1)) := by rw [ht₁, ht₂]; ac_rfl /-- The congruence relation used to localize a `CommMonoid` at a submonoid can be expressed equivalently as an infimum (see `Localization.r`) or explicitly (see `Localization.r'`). -/ @[to_additive AddLocalization.r_eq_r' "The additive congruence relation used to localize an `AddCommMonoid` at a submonoid can be expressed equivalently as an infimum (see `AddLocalization.r`) or explicitly (see `AddLocalization.r'`)."] theorem r_eq_r' : r S = r' S := le_antisymm (sInf_le fun _ ↦ ⟨1, by simp⟩) <| le_sInf fun b H ⟨p, q⟩ ⟨x, y⟩ ⟨t, ht⟩ ↦ by rw [← one_mul (p, q), ← one_mul (x, y)] refine b.trans (b.mul (H (t * y)) (b.refl _)) ?_ convert b.symm (b.mul (H (t * q)) (b.refl (x, y))) using 1 dsimp only [Prod.mk_mul_mk, Submonoid.coe_mul] at ht ⊢ simp_rw [mul_assoc, ht, mul_comm y q] variable {S} @[to_additive AddLocalization.r_iff_exists] theorem r_iff_exists {x y : M × S} : r S x y ↔ ∃ c : S, ↑c * (↑y.2 * x.1) = c * (x.2 * y.1) := by rw [r_eq_r' S]; rfl @[to_additive AddLocalization.r_iff_oreEqv_r] theorem r_iff_oreEqv_r {x y : M × S} : r S x y ↔ (OreLocalization.oreEqv S M).r x y := by simp only [r_iff_exists, Subtype.exists, exists_prop, OreLocalization.oreEqv, smul_eq_mul, Submonoid.mk_smul] constructor · rintro ⟨u, hu, e⟩ exact ⟨_, mul_mem hu x.2.2, u * y.2, by rw [mul_assoc, mul_assoc, ← e], mul_right_comm _ _ _⟩ · rintro ⟨u, hu, v, e₁, e₂⟩ exact ⟨u, hu, by rw [← mul_assoc, e₂, mul_right_comm, ← e₁, mul_assoc, mul_comm y.1]⟩ end Localization /-- The localization of a `CommMonoid` at one of its submonoids (as a quotient type). -/ @[to_additive AddLocalization "The localization of an `AddCommMonoid` at one of its submonoids (as a quotient type)."] abbrev Localization := OreLocalization S M namespace Localization variable {S} /-- Given a `CommMonoid` `M` and submonoid `S`, `mk` sends `x : M`, `y ∈ S` to the equivalence class of `(x, y)` in the localization of `M` at `S`. -/ @[to_additive "Given an `AddCommMonoid` `M` and submonoid `S`, `mk` sends `x : M`, `y ∈ S` to the equivalence class of `(x, y)` in the localization of `M` at `S`."] def mk (x : M) (y : S) : Localization S := x /ₒ y @[to_additive] theorem mk_eq_mk_iff {a c : M} {b d : S} : mk a b = mk c d ↔ r S ⟨a, b⟩ ⟨c, d⟩ := by rw [mk, mk, OreLocalization.oreDiv_eq_iff, r_iff_oreEqv_r]; rfl universe u /-- Dependent recursion principle for `Localizations`: given elements `f a b : p (mk a b)` for all `a b`, such that `r S (a, b) (c, d)` implies `f a b = f c d` (with the correct coercions), then `f` is defined on the whole `Localization S`. -/ @[to_additive (attr := elab_as_elim) "Dependent recursion principle for `AddLocalizations`: given elements `f a b : p (mk a b)` for all `a b`, such that `r S (a, b) (c, d)` implies `f a b = f c d` (with the correct coercions), then `f` is defined on the whole `AddLocalization S`."] def rec {p : Localization S → Sort u} (f : ∀ (a : M) (b : S), p (mk a b)) (H : ∀ {a c : M} {b d : S} (h : r S (a, b) (c, d)), (Eq.ndrec (f a b) (mk_eq_mk_iff.mpr h) : p (mk c d)) = f c d) (x) : p x := Quot.rec (fun y ↦ Eq.ndrec (f y.1 y.2) (by rfl)) (fun y z h ↦ by cases y; cases z; exact H (r_iff_oreEqv_r.mpr h)) x /-- Copy of `Quotient.recOnSubsingleton₂` for `Localization` -/ @[to_additive (attr := elab_as_elim) "Copy of `Quotient.recOnSubsingleton₂` for `AddLocalization`"] def recOnSubsingleton₂ {r : Localization S → Localization S → Sort u} [h : ∀ (a c : M) (b d : S), Subsingleton (r (mk a b) (mk c d))] (x y : Localization S) (f : ∀ (a c : M) (b d : S), r (mk a b) (mk c d)) : r x y := @Quotient.recOnSubsingleton₂' _ _ _ _ r (Prod.rec fun _ _ => Prod.rec fun _ _ => h _ _ _ _) x y (Prod.rec fun _ _ => Prod.rec fun _ _ => f _ _ _ _) @[to_additive] theorem mk_mul (a c : M) (b d : S) : mk a b * mk c d = mk (a * c) (b * d) := mul_comm b d ▸ OreLocalization.oreDiv_mul_oreDiv unseal OreLocalization.one in @[to_additive] theorem mk_one : mk 1 (1 : S) = 1 := OreLocalization.one_def @[to_additive] theorem mk_pow (n : ℕ) (a : M) (b : S) : mk a b ^ n = mk (a ^ n) (b ^ n) := by induction n <;> simp [pow_succ, *, ← mk_mul, ← mk_one] -- Porting note: mathport translated `rec` to `ndrec` in the name of this lemma @[to_additive (attr := simp)] theorem ndrec_mk {p : Localization S → Sort u} (f : ∀ (a : M) (b : S), p (mk a b)) (H) (a : M) (b : S) : (rec f H (mk a b) : p (mk a b)) = f a b := rfl /-- Non-dependent recursion principle for localizations: given elements `f a b : p` for all `a b`, such that `r S (a, b) (c, d)` implies `f a b = f c d`, then `f` is defined on the whole `Localization S`. -/ -- Porting note: the attribute `elab_as_elim` fails with `unexpected eliminator resulting type p` -- @[to_additive (attr := elab_as_elim) @[to_additive "Non-dependent recursion principle for `AddLocalization`s: given elements `f a b : p` for all `a b`, such that `r S (a, b) (c, d)` implies `f a b = f c d`, then `f` is defined on the whole `Localization S`."] def liftOn {p : Sort u} (x : Localization S) (f : M → S → p) (H : ∀ {a c : M} {b d : S}, r S (a, b) (c, d) → f a b = f c d) : p := rec f (fun h ↦ (by simpa only [eq_rec_constant] using H h)) x @[to_additive] theorem liftOn_mk {p : Sort u} (f : M → S → p) (H) (a : M) (b : S) : liftOn (mk a b) f H = f a b := rfl @[to_additive (attr := elab_as_elim, induction_eliminator, cases_eliminator)] theorem ind {p : Localization S → Prop} (H : ∀ y : M × S, p (mk y.1 y.2)) (x) : p x := rec (fun a b ↦ H (a, b)) (fun _ ↦ rfl) x @[to_additive (attr := elab_as_elim)] theorem induction_on {p : Localization S → Prop} (x) (H : ∀ y : M × S, p (mk y.1 y.2)) : p x := ind H x /-- Non-dependent recursion principle for localizations: given elements `f x y : p` for all `x` and `y`, such that `r S x x'` and `r S y y'` implies `f x y = f x' y'`, then `f` is defined on the whole `Localization S`. -/ -- Porting note: the attribute `elab_as_elim` fails with `unexpected eliminator resulting type p` -- @[to_additive (attr := elab_as_elim) @[to_additive "Non-dependent recursion principle for localizations: given elements `f x y : p` for all `x` and `y`, such that `r S x x'` and `r S y y'` implies `f x y = f x' y'`, then `f` is defined on the whole `Localization S`."] def liftOn₂ {p : Sort u} (x y : Localization S) (f : M → S → M → S → p) (H : ∀ {a a' b b' c c' d d'}, r S (a, b) (a', b') → r S (c, d) (c', d') → f a b c d = f a' b' c' d') : p := liftOn x (fun a b ↦ liftOn y (f a b) fun hy ↦ H ((r S).refl _) hy) fun hx ↦ induction_on y fun ⟨_, _⟩ ↦ H hx ((r S).refl _) @[to_additive] theorem liftOn₂_mk {p : Sort*} (f : M → S → M → S → p) (H) (a c : M) (b d : S) : liftOn₂ (mk a b) (mk c d) f H = f a b c d := rfl @[to_additive (attr := elab_as_elim)] theorem induction_on₂ {p : Localization S → Localization S → Prop} (x y) (H : ∀ x y : M × S, p (mk x.1 x.2) (mk y.1 y.2)) : p x y := induction_on x fun x ↦ induction_on y <| H x @[to_additive (attr := elab_as_elim)] theorem induction_on₃ {p : Localization S → Localization S → Localization S → Prop} (x y z) (H : ∀ x y z : M × S, p (mk x.1 x.2) (mk y.1 y.2) (mk z.1 z.2)) : p x y z := induction_on₂ x y fun x y ↦ induction_on z <| H x y @[to_additive] theorem one_rel (y : S) : r S 1 (y, y) := fun _ hb ↦ hb y @[to_additive] theorem r_of_eq {x y : M × S} (h : ↑y.2 * x.1 = ↑x.2 * y.1) : r S x y := r_iff_exists.2 ⟨1, by rw [h]⟩ @[to_additive] theorem mk_self (a : S) : mk (a : M) a = 1 := by symm rw [← mk_one, mk_eq_mk_iff] exact one_rel a section Scalar variable {R R₁ R₂ : Type*} theorem smul_mk [SMul R M] [IsScalarTower R M M] (c : R) (a b) : c • (mk a b : Localization S) = mk (c • a) b := by rw [mk, mk, ← OreLocalization.smul_one_oreDiv_one_smul, OreLocalization.oreDiv_smul_oreDiv] show (c • 1) • a /ₒ (b * 1) = _ rw [smul_assoc, one_smul, mul_one] -- move me instance {R M : Type*} [CommMonoid M] [SMul R M] [IsScalarTower R M M] : SMulCommClass R M M where smul_comm r s x := by rw [← one_smul M (s • x), ← smul_assoc, smul_comm, smul_assoc, one_smul] -- Note: Previously there was a `MulDistribMulAction R (Localization S)`. -- It was removed as it is not the correct action. end Scalar end Localization variable {S N} namespace MonoidHom /-- Makes a localization map from a `CommMonoid` hom satisfying the characteristic predicate. -/ @[to_additive "Makes a localization map from an `AddCommMonoid` hom satisfying the characteristic predicate."] def toLocalizationMap (f : M →* N) (H1 : ∀ y : S, IsUnit (f y)) (H2 : ∀ z, ∃ x : M × S, z * f x.2 = f x.1) (H3 : ∀ x y, f x = f y → ∃ c : S, ↑c * x = ↑c * y) : Submonoid.LocalizationMap S N := { f with map_units' := H1 surj' := H2 exists_of_eq := H3 } end MonoidHom namespace Submonoid namespace LocalizationMap /-- Short for `toMonoidHom`; used to apply a localization map as a function. -/ @[to_additive "Short for `toAddMonoidHom`; used to apply a localization map as a function."] abbrev toMap (f : LocalizationMap S N) := f.toMonoidHom @[to_additive (attr := ext)] theorem ext {f g : LocalizationMap S N} (h : ∀ x, f.toMap x = g.toMap x) : f = g := by rcases f with ⟨⟨⟩⟩ rcases g with ⟨⟨⟩⟩ simp only [mk.injEq, MonoidHom.mk.injEq] exact OneHom.ext h @[to_additive] theorem toMap_injective : Function.Injective (@LocalizationMap.toMap _ _ S N _) := fun _ _ h ↦ ext <| DFunLike.ext_iff.1 h @[to_additive] theorem map_units (f : LocalizationMap S N) (y : S) : IsUnit (f.toMap y) := f.2 y @[to_additive] theorem surj (f : LocalizationMap S N) (z : N) : ∃ x : M × S, z * f.toMap x.2 = f.toMap x.1 := f.3 z /-- Given a localization map `f : M →* N`, and `z w : N`, there exist `z' w' : M` and `d : S` such that `f z' / f d = z` and `f w' / f d = w`. -/ @[to_additive "Given a localization map `f : M →+ N`, and `z w : N`, there exist `z' w' : M` and `d : S` such that `f z' - f d = z` and `f w' - f d = w`."] theorem surj₂ (f : LocalizationMap S N) (z w : N) : ∃ z' w' : M, ∃ d : S, (z * f.toMap d = f.toMap z') ∧ (w * f.toMap d = f.toMap w') := by let ⟨a, ha⟩ := surj f z let ⟨b, hb⟩ := surj f w refine ⟨a.1 * b.2, a.2 * b.1, a.2 * b.2, ?_, ?_⟩ · simp_rw [mul_def, map_mul, ← ha] exact (mul_assoc z _ _).symm · simp_rw [mul_def, map_mul, ← hb] exact mul_left_comm w _ _ @[to_additive] theorem eq_iff_exists (f : LocalizationMap S N) {x y} : f.toMap x = f.toMap y ↔ ∃ c : S, ↑c * x = c * y := Iff.intro (f.4 x y) fun ⟨c, h⟩ ↦ by replace h := congr_arg f.toMap h rw [map_mul, map_mul] at h exact (f.map_units c).mul_right_inj.mp h /-- Given a localization map `f : M →* N`, a section function sending `z : N` to some `(x, y) : M × S` such that `f x * (f y)⁻¹ = z`. -/ @[to_additive "Given a localization map `f : M →+ N`, a section function sending `z : N` to some `(x, y) : M × S` such that `f x - f y = z`."] noncomputable def sec (f : LocalizationMap S N) (z : N) : M × S := Classical.choose <| f.surj z @[to_additive] theorem sec_spec {f : LocalizationMap S N} (z : N) : z * f.toMap (f.sec z).2 = f.toMap (f.sec z).1 := Classical.choose_spec <| f.surj z @[to_additive] theorem sec_spec' {f : LocalizationMap S N} (z : N) : f.toMap (f.sec z).1 = f.toMap (f.sec z).2 * z := by rw [mul_comm, sec_spec] /-- Given a MonoidHom `f : M →* N` and Submonoid `S ⊆ M` such that `f(S) ⊆ Nˣ`, for all `w, z : N` and `y ∈ S`, we have `w * (f y)⁻¹ = z ↔ w = f y * z`. -/ @[to_additive "Given an AddMonoidHom `f : M →+ N` and Submonoid `S ⊆ M` such that `f(S) ⊆ AddUnits N`, for all `w, z : N` and `y ∈ S`, we have `w - f y = z ↔ w = f y + z`."] theorem mul_inv_left {f : M →* N} (h : ∀ y : S, IsUnit (f y)) (y : S) (w z : N) : w * (IsUnit.liftRight (f.restrict S) h y)⁻¹ = z ↔ w = f y * z := by rw [mul_comm] exact Units.inv_mul_eq_iff_eq_mul (IsUnit.liftRight (f.restrict S) h y) /-- Given a MonoidHom `f : M →* N` and Submonoid `S ⊆ M` such that `f(S) ⊆ Nˣ`, for all `w, z : N` and `y ∈ S`, we have `z = w * (f y)⁻¹ ↔ z * f y = w`. -/ @[to_additive "Given an AddMonoidHom `f : M →+ N` and Submonoid `S ⊆ M` such that `f(S) ⊆ AddUnits N`, for all `w, z : N` and `y ∈ S`, we have `z = w - f y ↔ z + f y = w`."] theorem mul_inv_right {f : M →* N} (h : ∀ y : S, IsUnit (f y)) (y : S) (w z : N) : z = w * (IsUnit.liftRight (f.restrict S) h y)⁻¹ ↔ z * f y = w := by rw [eq_comm, mul_inv_left h, mul_comm, eq_comm] /-- Given a MonoidHom `f : M →* N` and Submonoid `S ⊆ M` such that `f(S) ⊆ Nˣ`, for all `x₁ x₂ : M` and `y₁, y₂ ∈ S`, we have `f x₁ * (f y₁)⁻¹ = f x₂ * (f y₂)⁻¹ ↔ f (x₁ * y₂) = f (x₂ * y₁)`. -/ @[to_additive (attr := simp) "Given an AddMonoidHom `f : M →+ N` and Submonoid `S ⊆ M` such that `f(S) ⊆ AddUnits N`, for all `x₁ x₂ : M` and `y₁, y₂ ∈ S`, we have `f x₁ - f y₁ = f x₂ - f y₂ ↔ f (x₁ + y₂) = f (x₂ + y₁)`."] theorem mul_inv {f : M →* N} (h : ∀ y : S, IsUnit (f y)) {x₁ x₂} {y₁ y₂ : S} : f x₁ * (IsUnit.liftRight (f.restrict S) h y₁)⁻¹ = f x₂ * (IsUnit.liftRight (f.restrict S) h y₂)⁻¹ ↔ f (x₁ * y₂) = f (x₂ * y₁) := by rw [mul_inv_right h, mul_assoc, mul_comm _ (f y₂), ← mul_assoc, mul_inv_left h, mul_comm x₂, f.map_mul, f.map_mul] /-- Given a MonoidHom `f : M →* N` and Submonoid `S ⊆ M` such that `f(S) ⊆ Nˣ`, for all `y, z ∈ S`, we have `(f y)⁻¹ = (f z)⁻¹ → f y = f z`. -/ @[to_additive "Given an AddMonoidHom `f : M →+ N` and Submonoid `S ⊆ M` such that `f(S) ⊆ AddUnits N`, for all `y, z ∈ S`, we have `- (f y) = - (f z) → f y = f z`."] theorem inv_inj {f : M →* N} (hf : ∀ y : S, IsUnit (f y)) {y z : S} (h : (IsUnit.liftRight (f.restrict S) hf y)⁻¹ = (IsUnit.liftRight (f.restrict S) hf z)⁻¹) : f y = f z := by rw [← mul_one (f y), eq_comm, ← mul_inv_left hf y (f z) 1, h] exact Units.inv_mul (IsUnit.liftRight (f.restrict S) hf z)⁻¹ /-- Given a MonoidHom `f : M →* N` and Submonoid `S ⊆ M` such that `f(S) ⊆ Nˣ`, for all `y ∈ S`, `(f y)⁻¹` is unique. -/ @[to_additive "Given an AddMonoidHom `f : M →+ N` and Submonoid `S ⊆ M` such that `f(S) ⊆ AddUnits N`, for all `y ∈ S`, `- (f y)` is unique."] theorem inv_unique {f : M →* N} (h : ∀ y : S, IsUnit (f y)) {y : S} {z : N} (H : f y * z = 1) : (IsUnit.liftRight (f.restrict S) h y)⁻¹ = z := by rw [← one_mul _⁻¹, Units.val_mul, mul_inv_left] exact H.symm variable (f : LocalizationMap S N) @[to_additive] theorem map_right_cancel {x y} {c : S} (h : f.toMap (c * x) = f.toMap (c * y)) : f.toMap x = f.toMap y := by rw [f.toMap.map_mul, f.toMap.map_mul] at h let ⟨u, hu⟩ := f.map_units c rw [← hu] at h exact (Units.mul_right_inj u).1 h @[to_additive] theorem map_left_cancel {x y} {c : S} (h : f.toMap (x * c) = f.toMap (y * c)) : f.toMap x = f.toMap y := f.map_right_cancel (c := c) <| by rw [mul_comm _ x, mul_comm _ y, h] /-- Given a localization map `f : M →* N`, the surjection sending `(x, y) : M × S` to `f x * (f y)⁻¹`. -/ @[to_additive "Given a localization map `f : M →+ N`, the surjection sending `(x, y) : M × S` to `f x - f y`."] noncomputable def mk' (f : LocalizationMap S N) (x : M) (y : S) : N := f.toMap x * ↑(IsUnit.liftRight (f.toMap.restrict S) f.map_units y)⁻¹ @[to_additive] theorem mk'_mul (x₁ x₂ : M) (y₁ y₂ : S) : f.mk' (x₁ * x₂) (y₁ * y₂) = f.mk' x₁ y₁ * f.mk' x₂ y₂ := (mul_inv_left f.map_units _ _ _).2 <| show _ = _ * (_ * _ * (_ * _)) by rw [← mul_assoc, ← mul_assoc, mul_inv_right f.map_units, mul_assoc, mul_assoc, mul_comm _ (f.toMap x₂), ← mul_assoc, ← mul_assoc, mul_inv_right f.map_units, Submonoid.coe_mul, f.toMap.map_mul, f.toMap.map_mul] ac_rfl @[to_additive] theorem mk'_one (x) : f.mk' x (1 : S) = f.toMap x := by rw [mk', MonoidHom.map_one] exact mul_one _ /-- Given a localization map `f : M →* N` for a submonoid `S ⊆ M`, for all `z : N` we have that if `x : M, y ∈ S` are such that `z * f y = f x`, then `f x * (f y)⁻¹ = z`. -/ @[to_additive (attr := simp) "Given a localization map `f : M →+ N` for a Submonoid `S ⊆ M`, for all `z : N` we have that if `x : M, y ∈ S` are such that `z + f y = f x`, then `f x - f y = z`."] theorem mk'_sec (z : N) : f.mk' (f.sec z).1 (f.sec z).2 = z := show _ * _ = _ by rw [← sec_spec, mul_inv_left, mul_comm] @[to_additive] theorem mk'_surjective (z : N) : ∃ (x : _) (y : S), f.mk' x y = z := ⟨(f.sec z).1, (f.sec z).2, f.mk'_sec z⟩ @[to_additive] theorem mk'_spec (x) (y : S) : f.mk' x y * f.toMap y = f.toMap x := show _ * _ * _ = _ by rw [mul_assoc, mul_comm _ (f.toMap y), ← mul_assoc, mul_inv_left, mul_comm] @[to_additive] theorem mk'_spec' (x) (y : S) : f.toMap y * f.mk' x y = f.toMap x := by rw [mul_comm, mk'_spec] @[to_additive] theorem eq_mk'_iff_mul_eq {x} {y : S} {z} : z = f.mk' x y ↔ z * f.toMap y = f.toMap x := ⟨fun H ↦ by rw [H, mk'_spec], fun H ↦ by erw [mul_inv_right, H]⟩ @[to_additive] theorem mk'_eq_iff_eq_mul {x} {y : S} {z} : f.mk' x y = z ↔ f.toMap x = z * f.toMap y := by rw [eq_comm, eq_mk'_iff_mul_eq, eq_comm] @[to_additive] theorem mk'_eq_iff_eq {x₁ x₂} {y₁ y₂ : S} : f.mk' x₁ y₁ = f.mk' x₂ y₂ ↔ f.toMap (y₂ * x₁) = f.toMap (y₁ * x₂) := ⟨fun H ↦ by rw [f.toMap.map_mul, f.toMap.map_mul, f.mk'_eq_iff_eq_mul.1 H,← mul_assoc, mk'_spec', mul_comm ((toMap f) x₂) _], fun H ↦ by rw [mk'_eq_iff_eq_mul, mk', mul_assoc, mul_comm _ (f.toMap y₁), ← mul_assoc, ← f.toMap.map_mul, mul_comm x₂, ← H, ← mul_comm x₁, f.toMap.map_mul, mul_inv_right f.map_units]⟩ @[to_additive] theorem mk'_eq_iff_eq' {x₁ x₂} {y₁ y₂ : S} : f.mk' x₁ y₁ = f.mk' x₂ y₂ ↔ f.toMap (x₁ * y₂) = f.toMap (x₂ * y₁) := by simp only [f.mk'_eq_iff_eq, mul_comm] @[to_additive] protected theorem eq {a₁ b₁} {a₂ b₂ : S} : f.mk' a₁ a₂ = f.mk' b₁ b₂ ↔ ∃ c : S, ↑c * (↑b₂ * a₁) = c * (a₂ * b₁) := f.mk'_eq_iff_eq.trans <| f.eq_iff_exists @[to_additive] protected theorem eq' {a₁ b₁} {a₂ b₂ : S} : f.mk' a₁ a₂ = f.mk' b₁ b₂ ↔ Localization.r S (a₁, a₂) (b₁, b₂) := by rw [f.eq, Localization.r_iff_exists] @[to_additive] theorem eq_iff_eq (g : LocalizationMap S P) {x y} : f.toMap x = f.toMap y ↔ g.toMap x = g.toMap y := f.eq_iff_exists.trans g.eq_iff_exists.symm @[to_additive] theorem mk'_eq_iff_mk'_eq (g : LocalizationMap S P) {x₁ x₂} {y₁ y₂ : S} : f.mk' x₁ y₁ = f.mk' x₂ y₂ ↔ g.mk' x₁ y₁ = g.mk' x₂ y₂ := f.eq'.trans g.eq'.symm /-- Given a Localization map `f : M →* N` for a Submonoid `S ⊆ M`, for all `x₁ : M` and `y₁ ∈ S`, if `x₂ : M, y₂ ∈ S` are such that `f x₁ * (f y₁)⁻¹ * f y₂ = f x₂`, then there exists `c ∈ S` such that `x₁ * y₂ * c = x₂ * y₁ * c`. -/ @[to_additive "Given a Localization map `f : M →+ N` for a Submonoid `S ⊆ M`, for all `x₁ : M` and `y₁ ∈ S`, if `x₂ : M, y₂ ∈ S` are such that `(f x₁ - f y₁) + f y₂ = f x₂`, then there exists `c ∈ S` such that `x₁ + y₂ + c = x₂ + y₁ + c`."] theorem exists_of_sec_mk' (x) (y : S) : ∃ c : S, ↑c * (↑(f.sec <| f.mk' x y).2 * x) = c * (y * (f.sec <| f.mk' x y).1) := f.eq_iff_exists.1 <| f.mk'_eq_iff_eq.1 <| (mk'_sec _ _).symm @[to_additive] theorem mk'_eq_of_eq {a₁ b₁ : M} {a₂ b₂ : S} (H : ↑a₂ * b₁ = ↑b₂ * a₁) : f.mk' a₁ a₂ = f.mk' b₁ b₂ := f.mk'_eq_iff_eq.2 <| H ▸ rfl @[to_additive] theorem mk'_eq_of_eq' {a₁ b₁ : M} {a₂ b₂ : S} (H : b₁ * ↑a₂ = a₁ * ↑b₂) : f.mk' a₁ a₂ = f.mk' b₁ b₂ := f.mk'_eq_of_eq <| by simpa only [mul_comm] using H @[to_additive] theorem mk'_cancel (a : M) (b c : S) : f.mk' (a * c) (b * c) = f.mk' a b := mk'_eq_of_eq' f (by rw [Submonoid.coe_mul, mul_comm (b : M), mul_assoc]) @[to_additive] theorem mk'_eq_of_same {a b} {d : S} : f.mk' a d = f.mk' b d ↔ ∃ c : S, c * a = c * b := by rw [mk'_eq_iff_eq', map_mul, map_mul, ← eq_iff_exists f] exact (map_units f d).mul_left_inj @[to_additive (attr := simp)] theorem mk'_self' (y : S) : f.mk' (y : M) y = 1 := show _ * _ = _ by rw [mul_inv_left, mul_one] @[to_additive (attr := simp)] theorem mk'_self (x) (H : x ∈ S) : f.mk' x ⟨x, H⟩ = 1 := mk'_self' f ⟨x, H⟩ @[to_additive] theorem mul_mk'_eq_mk'_of_mul (x₁ x₂) (y : S) : f.toMap x₁ * f.mk' x₂ y = f.mk' (x₁ * x₂) y := by rw [← mk'_one, ← mk'_mul, one_mul] @[to_additive] theorem mk'_mul_eq_mk'_of_mul (x₁ x₂) (y : S) : f.mk' x₂ y * f.toMap x₁ = f.mk' (x₁ * x₂) y := by rw [mul_comm, mul_mk'_eq_mk'_of_mul] @[to_additive] theorem mul_mk'_one_eq_mk' (x) (y : S) : f.toMap x * f.mk' 1 y = f.mk' x y := by rw [mul_mk'_eq_mk'_of_mul, mul_one] @[to_additive (attr := simp)] theorem mk'_mul_cancel_right (x : M) (y : S) : f.mk' (x * y) y = f.toMap x := by rw [← mul_mk'_one_eq_mk', f.toMap.map_mul, mul_assoc, mul_mk'_one_eq_mk', mk'_self', mul_one] @[to_additive] theorem mk'_mul_cancel_left (x) (y : S) : f.mk' ((y : M) * x) y = f.toMap x := by rw [mul_comm, mk'_mul_cancel_right] @[to_additive] theorem isUnit_comp (j : N →* P) (y : S) : IsUnit (j.comp f.toMap y) := ⟨Units.map j <| IsUnit.liftRight (f.toMap.restrict S) f.map_units y, show j _ = j _ from congr_arg j <| IsUnit.coe_liftRight (f.toMap.restrict S) f.map_units _⟩ variable {g : M →* P} /-- Given a Localization map `f : M →* N` for a Submonoid `S ⊆ M` and a map of `CommMonoid`s `g : M →* P` such that `g(S) ⊆ Units P`, `f x = f y → g x = g y` for all `x y : M`. -/ @[to_additive "Given a Localization map `f : M →+ N` for a Submonoid `S ⊆ M` and a map of `AddCommMonoid`s `g : M →+ P` such that `g(S) ⊆ AddUnits P`, `f x = f y → g x = g y` for all `x y : M`."] theorem eq_of_eq (hg : ∀ y : S, IsUnit (g y)) {x y} (h : f.toMap x = f.toMap y) : g x = g y := by obtain ⟨c, hc⟩ := f.eq_iff_exists.1 h rw [← one_mul (g x), ← IsUnit.liftRight_inv_mul (g.restrict S) hg c] show _ * g c * _ = _ rw [mul_assoc, ← g.map_mul, hc, mul_comm, mul_inv_left hg, g.map_mul] /-- Given `CommMonoid`s `M, P`, Localization maps `f : M →* N, k : P →* Q` for Submonoids `S, T` respectively, and `g : M →* P` such that `g(S) ⊆ T`, `f x = f y` implies `k (g x) = k (g y)`. -/ @[to_additive "Given `AddCommMonoid`s `M, P`, Localization maps `f : M →+ N, k : P →+ Q` for Submonoids `S, T` respectively, and `g : M →+ P` such that `g(S) ⊆ T`, `f x = f y` implies `k (g x) = k (g y)`."] theorem comp_eq_of_eq {T : Submonoid P} {Q : Type*} [CommMonoid Q] (hg : ∀ y : S, g y ∈ T) (k : LocalizationMap T Q) {x y} (h : f.toMap x = f.toMap y) : k.toMap (g x) = k.toMap (g y) := f.eq_of_eq (fun y : S ↦ show IsUnit (k.toMap.comp g y) from k.map_units ⟨g y, hg y⟩) h variable (hg : ∀ y : S, IsUnit (g y)) /-- Given a Localization map `f : M →* N` for a Submonoid `S ⊆ M` and a map of `CommMonoid`s `g : M →* P` such that `g y` is invertible for all `y : S`, the homomorphism induced from `N` to `P` sending `z : N` to `g x * (g y)⁻¹`, where `(x, y) : M × S` are such that `z = f x * (f y)⁻¹`. -/ @[to_additive "Given a localization map `f : M →+ N` for a submonoid `S ⊆ M` and a map of `AddCommMonoid`s `g : M →+ P` such that `g y` is invertible for all `y : S`, the homomorphism induced from `N` to `P` sending `z : N` to `g x - g y`, where `(x, y) : M × S` are such that `z = f x - f y`."] noncomputable def lift : N →* P where toFun z := g (f.sec z).1 * (IsUnit.liftRight (g.restrict S) hg (f.sec z).2)⁻¹ map_one' := by rw [mul_inv_left, mul_one]; exact f.eq_of_eq hg (by rw [← sec_spec, one_mul]) map_mul' x y := by dsimp only rw [mul_inv_left hg, ← mul_assoc, ← mul_assoc, mul_inv_right hg, mul_comm _ (g (f.sec y).1), ← mul_assoc, ← mul_assoc, mul_inv_right hg] repeat rw [← g.map_mul] exact f.eq_of_eq hg (by simp_rw [f.toMap.map_mul, sec_spec']; ac_rfl) /-- Given a Localization map `f : M →* N` for a Submonoid `S ⊆ M` and a map of `CommMonoid`s `g : M →* P` such that `g y` is invertible for all `y : S`, the homomorphism induced from `N` to `P` maps `f x * (f y)⁻¹` to `g x * (g y)⁻¹` for all `x : M, y ∈ S`. -/ @[to_additive "Given a Localization map `f : M →+ N` for a Submonoid `S ⊆ M` and a map of `AddCommMonoid`s `g : M →+ P` such that `g y` is invertible for all `y : S`, the homomorphism induced from `N` to `P` maps `f x - f y` to `g x - g y` for all `x : M, y ∈ S`."] theorem lift_mk' (x y) : f.lift hg (f.mk' x y) = g x * (IsUnit.liftRight (g.restrict S) hg y)⁻¹ := (mul_inv hg).2 <| f.eq_of_eq hg <| by simp_rw [f.toMap.map_mul, sec_spec', mul_assoc, f.mk'_spec, mul_comm] /-- Given a Localization map `f : M →* N` for a Submonoid `S ⊆ M`, if a `CommMonoid` map `g : M →* P` induces a map `f.lift hg : N →* P` then for all `z : N, v : P`, we have `f.lift hg z = v ↔ g x = g y * v`, where `x : M, y ∈ S` are such that `z * f y = f x`. -/ @[to_additive "Given a Localization map `f : M →+ N` for a Submonoid `S ⊆ M`, if an `AddCommMonoid` map `g : M →+ P` induces a map `f.lift hg : N →+ P` then for all `z : N, v : P`, we have `f.lift hg z = v ↔ g x = g y + v`, where `x : M, y ∈ S` are such that `z + f y = f x`."] theorem lift_spec (z v) : f.lift hg z = v ↔ g (f.sec z).1 = g (f.sec z).2 * v := mul_inv_left hg _ _ v /-- Given a Localization map `f : M →* N` for a Submonoid `S ⊆ M`, if a `CommMonoid` map `g : M →* P` induces a map `f.lift hg : N →* P` then for all `z : N, v w : P`, we have `f.lift hg z * w = v ↔ g x * w = g y * v`, where `x : M, y ∈ S` are such that `z * f y = f x`. -/ @[to_additive "Given a Localization map `f : M →+ N` for a Submonoid `S ⊆ M`, if an `AddCommMonoid` map `g : M →+ P` induces a map `f.lift hg : N →+ P` then for all `z : N, v w : P`, we have `f.lift hg z + w = v ↔ g x + w = g y + v`, where `x : M, y ∈ S` are such that `z + f y = f x`."] theorem lift_spec_mul (z w v) : f.lift hg z * w = v ↔ g (f.sec z).1 * w = g (f.sec z).2 * v := by erw [mul_comm, ← mul_assoc, mul_inv_left hg, mul_comm] @[to_additive] theorem lift_mk'_spec (x v) (y : S) : f.lift hg (f.mk' x y) = v ↔ g x = g y * v := by rw [f.lift_mk' hg]; exact mul_inv_left hg _ _ _ /-- Given a Localization map `f : M →* N` for a Submonoid `S ⊆ M`, if a `CommMonoid` map `g : M →* P` induces a map `f.lift hg : N →* P` then for all `z : N`, we have `f.lift hg z * g y = g x`, where `x : M, y ∈ S` are such that `z * f y = f x`. -/ @[to_additive "Given a Localization map `f : M →+ N` for a Submonoid `S ⊆ M`, if an `AddCommMonoid` map `g : M →+ P` induces a map `f.lift hg : N →+ P` then for all `z : N`, we have `f.lift hg z + g y = g x`, where `x : M, y ∈ S` are such that `z + f y = f x`."] theorem lift_mul_right (z) : f.lift hg z * g (f.sec z).2 = g (f.sec z).1 := by erw [mul_assoc, IsUnit.liftRight_inv_mul, mul_one] /-- Given a Localization map `f : M →* N` for a Submonoid `S ⊆ M`, if a `CommMonoid` map `g : M →* P` induces a map `f.lift hg : N →* P` then for all `z : N`, we have `g y * f.lift hg z = g x`, where `x : M, y ∈ S` are such that `z * f y = f x`. -/ @[to_additive "Given a Localization map `f : M →+ N` for a Submonoid `S ⊆ M`, if an `AddCommMonoid` map `g : M →+ P` induces a map `f.lift hg : N →+ P` then for all `z : N`, we have `g y + f.lift hg z = g x`, where `x : M, y ∈ S` are such that `z + f y = f x`."] theorem lift_mul_left (z) : g (f.sec z).2 * f.lift hg z = g (f.sec z).1 := by rw [mul_comm, lift_mul_right] @[to_additive (attr := simp)] theorem lift_eq (x : M) : f.lift hg (f.toMap x) = g x := by rw [lift_spec, ← g.map_mul]; exact f.eq_of_eq hg (by rw [sec_spec', f.toMap.map_mul]) @[to_additive] theorem lift_eq_iff {x y : M × S} : f.lift hg (f.mk' x.1 x.2) = f.lift hg (f.mk' y.1 y.2) ↔ g (x.1 * y.2) = g (y.1 * x.2) := by rw [lift_mk', lift_mk', mul_inv hg] @[to_additive (attr := simp)] theorem lift_comp : (f.lift hg).comp f.toMap = g := by ext; exact f.lift_eq hg _ @[to_additive (attr := simp)] theorem lift_of_comp (j : N →* P) : f.lift (f.isUnit_comp j) = j := by ext rw [lift_spec] show j _ = j _ * _ erw [← j.map_mul, sec_spec'] @[to_additive] theorem epic_of_localizationMap {j k : N →* P} (h : ∀ a, j.comp f.toMap a = k.comp f.toMap a) : j = k := by rw [← f.lift_of_comp j, ← f.lift_of_comp k] congr 1 with x; exact h x @[to_additive] theorem lift_unique {j : N →* P} (hj : ∀ x, j (f.toMap x) = g x) : f.lift hg = j := by ext rw [lift_spec, ← hj, ← hj, ← j.map_mul] apply congr_arg rw [← sec_spec'] @[to_additive (attr := simp)] theorem lift_id (x) : f.lift f.map_units x = x := DFunLike.ext_iff.1 (f.lift_of_comp <| MonoidHom.id N) x /-- Given Localization maps `f : M →* N` for a Submonoid `S ⊆ M` and `k : M →* Q` for a Submonoid `T ⊆ M`, such that `S ≤ T`, and we have `l : M →* A`, the composition of the induced map `f.lift` for `k` with the induced map `k.lift` for `l` is equal to the induced map `f.lift` for `l`. -/ @[to_additive "Given Localization maps `f : M →+ N` for a Submonoid `S ⊆ M` and `k : M →+ Q` for a Submonoid `T ⊆ M`, such that `S ≤ T`, and we have `l : M →+ A`, the composition of the induced map `f.lift` for `k` with the induced map `k.lift` for `l` is equal to the induced map `f.lift` for `l`"] theorem lift_comp_lift {T : Submonoid M} (hST : S ≤ T) {Q : Type*} [CommMonoid Q] (k : LocalizationMap T Q) {A : Type*} [CommMonoid A] {l : M →* A} (hl : ∀ w : T, IsUnit (l w)) : (k.lift hl).comp (f.lift (map_units k ⟨_, hST ·.2⟩)) = f.lift (hl ⟨_, hST ·.2⟩) := .symm <| lift_unique _ _ fun x ↦ by rw [← MonoidHom.comp_apply, MonoidHom.comp_assoc, lift_comp, lift_comp] @[to_additive] theorem lift_comp_lift_eq {Q : Type*} [CommMonoid Q] (k : LocalizationMap S Q) {A : Type*} [CommMonoid A] {l : M →* A} (hl : ∀ w : S, IsUnit (l w)) : (k.lift hl).comp (f.lift k.map_units) = f.lift hl := lift_comp_lift f le_rfl k hl /-- Given two Localization maps `f : M →* N, k : M →* P` for a Submonoid `S ⊆ M`, the hom from `P` to `N` induced by `f` is left inverse to the hom from `N` to `P` induced by `k`. -/ @[to_additive (attr := simp) "Given two Localization maps `f : M →+ N, k : M →+ P` for a Submonoid `S ⊆ M`, the hom from `P` to `N` induced by `f` is left inverse to the hom from `N` to `P` induced by `k`."] theorem lift_left_inverse {k : LocalizationMap S P} (z : N) : k.lift f.map_units (f.lift k.map_units z) = z := (DFunLike.congr_fun (lift_comp_lift_eq f k f.map_units) z).trans (lift_id f z) @[to_additive] theorem lift_surjective_iff : Function.Surjective (f.lift hg) ↔ ∀ v : P, ∃ x : M × S, v * g x.2 = g x.1 := by constructor · intro H v obtain ⟨z, hz⟩ := H v obtain ⟨x, hx⟩ := f.surj z use x rw [← hz, f.eq_mk'_iff_mul_eq.2 hx, lift_mk', mul_assoc, mul_comm _ (g ↑x.2)] erw [IsUnit.mul_liftRight_inv (g.restrict S) hg, mul_one] · intro H v obtain ⟨x, hx⟩ := H v use f.mk' x.1 x.2 rw [lift_mk', mul_inv_left hg, mul_comm, ← hx] @[to_additive] theorem lift_injective_iff : Function.Injective (f.lift hg) ↔ ∀ x y, f.toMap x = f.toMap y ↔ g x = g y := by constructor · intro H x y constructor · exact f.eq_of_eq hg · intro h rw [← f.lift_eq hg, ← f.lift_eq hg] at h exact H h · intro H z w h obtain ⟨_, _⟩ := f.surj z obtain ⟨_, _⟩ := f.surj w rw [← f.mk'_sec z, ← f.mk'_sec w] exact (mul_inv f.map_units).2 ((H _ _).2 <| (mul_inv hg).1 h) variable {T : Submonoid P} (hy : ∀ y : S, g y ∈ T) {Q : Type*} [CommMonoid Q] (k : LocalizationMap T Q) /-- Given a `CommMonoid` homomorphism `g : M →* P` where for Submonoids `S ⊆ M, T ⊆ P` we have `g(S) ⊆ T`, the induced Monoid homomorphism from the Localization of `M` at `S` to the Localization of `P` at `T`: if `f : M →* N` and `k : P →* Q` are Localization maps for `S` and `T` respectively, we send `z : N` to `k (g x) * (k (g y))⁻¹`, where `(x, y) : M × S` are such that `z = f x * (f y)⁻¹`. -/ @[to_additive "Given an `AddCommMonoid` homomorphism `g : M →+ P` where for Submonoids `S ⊆ M, T ⊆ P` we have `g(S) ⊆ T`, the induced AddMonoid homomorphism from the Localization of `M` at `S` to the Localization of `P` at `T`: if `f : M →+ N` and `k : P →+ Q` are Localization maps for `S` and `T` respectively, we send `z : N` to `k (g x) - k (g y)`, where `(x, y) : M × S` are such that `z = f x - f y`."] noncomputable def map : N →* Q := @lift _ _ _ _ _ _ _ f (k.toMap.comp g) fun y ↦ k.map_units ⟨g y, hy y⟩ variable {k} @[to_additive] theorem map_eq (x) : f.map hy k (f.toMap x) = k.toMap (g x) := f.lift_eq (fun y ↦ k.map_units ⟨g y, hy y⟩) x @[to_additive (attr := simp)] theorem map_comp : (f.map hy k).comp f.toMap = k.toMap.comp g := f.lift_comp fun y ↦ k.map_units ⟨g y, hy y⟩ @[to_additive] theorem map_mk' (x) (y : S) : f.map hy k (f.mk' x y) = k.mk' (g x) ⟨g y, hy y⟩ := by rw [map, lift_mk', mul_inv_left] show k.toMap (g x) = k.toMap (g y) * _ rw [mul_mk'_eq_mk'_of_mul] exact (k.mk'_mul_cancel_left (g x) ⟨g y, hy y⟩).symm /-- Given Localization maps `f : M →* N, k : P →* Q` for Submonoids `S, T` respectively, if a `CommMonoid` homomorphism `g : M →* P` induces a `f.map hy k : N →* Q`, then for all `z : N`, `u : Q`, we have `f.map hy k z = u ↔ k (g x) = k (g y) * u` where `x : M, y ∈ S` are such that `z * f y = f x`. -/ @[to_additive "Given Localization maps `f : M →+ N, k : P →+ Q` for Submonoids `S, T` respectively, if an `AddCommMonoid` homomorphism `g : M →+ P` induces a `f.map hy k : N →+ Q`, then for all `z : N`, `u : Q`, we have `f.map hy k z = u ↔ k (g x) = k (g y) + u` where `x : M, y ∈ S` are such that `z + f y = f x`."] theorem map_spec (z u) : f.map hy k z = u ↔ k.toMap (g (f.sec z).1) = k.toMap (g (f.sec z).2) * u := f.lift_spec (fun y ↦ k.map_units ⟨g y, hy y⟩) _ _ /-- Given Localization maps `f : M →* N, k : P →* Q` for Submonoids `S, T` respectively, if a `CommMonoid` homomorphism `g : M →* P` induces a `f.map hy k : N →* Q`, then for all `z : N`, we have `f.map hy k z * k (g y) = k (g x)` where `x : M, y ∈ S` are such that `z * f y = f x`. -/ @[to_additive "Given Localization maps `f : M →+ N, k : P →+ Q` for Submonoids `S, T` respectively, if an `AddCommMonoid` homomorphism `g : M →+ P` induces a `f.map hy k : N →+ Q`, then for all `z : N`, we have `f.map hy k z + k (g y) = k (g x)` where `x : M, y ∈ S` are such that `z + f y = f x`."] theorem map_mul_right (z) : f.map hy k z * k.toMap (g (f.sec z).2) = k.toMap (g (f.sec z).1) := f.lift_mul_right (fun y ↦ k.map_units ⟨g y, hy y⟩) _ /-- Given Localization maps `f : M →* N, k : P →* Q` for Submonoids `S, T` respectively, if a `CommMonoid` homomorphism `g : M →* P` induces a `f.map hy k : N →* Q`, then for all `z : N`, we have `k (g y) * f.map hy k z = k (g x)` where `x : M, y ∈ S` are such that `z * f y = f x`. -/ @[to_additive "Given Localization maps `f : M →+ N, k : P →+ Q` for Submonoids `S, T` respectively if an `AddCommMonoid` homomorphism `g : M →+ P` induces a `f.map hy k : N →+ Q`, then for all `z : N`, we have `k (g y) + f.map hy k z = k (g x)` where `x : M, y ∈ S` are such that `z + f y = f x`."] theorem map_mul_left (z) : k.toMap (g (f.sec z).2) * f.map hy k z = k.toMap (g (f.sec z).1) := by rw [mul_comm, f.map_mul_right] @[to_additive (attr := simp)] theorem map_id (z : N) : f.map (fun y ↦ show MonoidHom.id M y ∈ S from y.2) f z = z := f.lift_id z /-- If `CommMonoid` homs `g : M →* P, l : P →* A` induce maps of localizations, the composition of the induced maps equals the map of localizations induced by `l ∘ g`. -/ @[to_additive "If `AddCommMonoid` homs `g : M →+ P, l : P →+ A` induce maps of localizations, the composition of the induced maps equals the map of localizations induced by `l ∘ g`."] theorem map_comp_map {A : Type*} [CommMonoid A] {U : Submonoid A} {R} [CommMonoid R] (j : LocalizationMap U R) {l : P →* A} (hl : ∀ w : T, l w ∈ U) : (k.map hl j).comp (f.map hy k) = f.map (fun x ↦ show l.comp g x ∈ U from hl ⟨g x, hy x⟩) j := by ext z show j.toMap _ * _ = j.toMap (l _) * _ rw [mul_inv_left, ← mul_assoc, mul_inv_right] show j.toMap _ * j.toMap (l (g _)) = j.toMap (l _) * _ rw [← j.toMap.map_mul, ← j.toMap.map_mul, ← l.map_mul, ← l.map_mul] exact k.comp_eq_of_eq hl j (by rw [k.toMap.map_mul, k.toMap.map_mul, sec_spec', mul_assoc, map_mul_right]) /-- If `CommMonoid` homs `g : M →* P, l : P →* A` induce maps of localizations, the composition of the induced maps equals the map of localizations induced by `l ∘ g`. -/ @[to_additive "If `AddCommMonoid` homs `g : M →+ P, l : P →+ A` induce maps of localizations, the composition of the induced maps equals the map of localizations induced by `l ∘ g`."] theorem map_map {A : Type*} [CommMonoid A] {U : Submonoid A} {R} [CommMonoid R] (j : LocalizationMap U R) {l : P →* A} (hl : ∀ w : T, l w ∈ U) (x) : k.map hl j (f.map hy k x) = f.map (fun x ↦ show l.comp g x ∈ U from hl ⟨g x, hy x⟩) j x := by -- Porting note: Lean has a hard time figuring out what the implicit arguments should be -- when calling `map_comp_map`. Hence the original line below has to be replaced by a much more -- explicit one -- rw [← f.map_comp_map hy j hl] rw [← @map_comp_map M _ S N _ P _ f g T hy Q _ k A _ U R _ j l hl] simp only [MonoidHom.coe_comp, comp_apply] /-- Given an injective `CommMonoid` homomorphism `g : M →* P`, and a submonoid `S ⊆ M`, the induced monoid homomorphism from the localization of `M` at `S` to the localization of `P` at `g S`, is injective. -/ @[to_additive "Given an injective `AddCommMonoid` homomorphism `g : M →+ P`, and a submonoid `S ⊆ M`, the induced monoid homomorphism from the localization of `M` at `S` to the localization of `P` at `g S`, is injective. "] theorem map_injective_of_injective (hg : Injective g) (k : LocalizationMap (S.map g) Q) : Injective (map f (apply_coe_mem_map g S) k) := fun z w hizw ↦ by set i := map f (apply_coe_mem_map g S) k have ifkg (a : M) : i (f.toMap a) = k.toMap (g a) := map_eq f (apply_coe_mem_map g S) a let ⟨z', w', x, hxz, hxw⟩ := surj₂ f z w have : k.toMap (g z') = k.toMap (g w') := by rw [← ifkg, ← ifkg, ← hxz, ← hxw, map_mul, map_mul, hizw] obtain ⟨⟨_, c, hc, rfl⟩, eq⟩ := k.exists_of_eq _ _ this simp_rw [← map_mul, hg.eq_iff] at eq rw [← (f.map_units x).mul_left_inj, hxz, hxw, f.eq_iff_exists] exact ⟨⟨c, hc⟩, eq⟩ /-- Given a surjective `CommMonoid` homomorphism `g : M →* P`, and a submonoid `S ⊆ M`, the induced monoid homomorphism from the localization of `M` at `S` to the localization of `P` at `g S`, is surjective. -/ @[to_additive "Given a surjective `AddCommMonoid` homomorphism `g : M →+ P`, and a submonoid `S ⊆ M`, the induced monoid homomorphism from the localization of `M` at `S` to the localization of `P` at `g S`, is surjective. "] theorem map_surjective_of_surjective (hg : Surjective g) (k : LocalizationMap (S.map g) Q) : Surjective (map f (apply_coe_mem_map g S) k) := fun z ↦ by obtain ⟨y, ⟨y', s, hs, rfl⟩, rfl⟩ := k.mk'_surjective z obtain ⟨x, rfl⟩ := hg y use f.mk' x ⟨s, hs⟩ rw [map_mk'] section AwayMap variable (x : M) /-- Given `x : M`, the type of `CommMonoid` homomorphisms `f : M →* N` such that `N` is isomorphic to the Localization of `M` at the Submonoid generated by `x`. -/ @[to_additive (attr := reducible) "Given `x : M`, the type of `AddCommMonoid` homomorphisms `f : M →+ N` such that `N` is isomorphic to the localization of `M` at the AddSubmonoid generated by `x`."] def AwayMap (N' : Type*) [CommMonoid N'] := LocalizationMap (powers x) N' variable (F : AwayMap x N) /-- Given `x : M` and a Localization map `F : M →* N` away from `x`, `invSelf` is `(F x)⁻¹`. -/ noncomputable def AwayMap.invSelf : N := F.mk' 1 ⟨x, mem_powers _⟩ /-- Given `x : M`, a Localization map `F : M →* N` away from `x`, and a map of `CommMonoid`s `g : M →* P` such that `g x` is invertible, the homomorphism induced from `N` to `P` sending `z : N` to `g y * (g x)⁻ⁿ`, where `y : M, n : ℕ` are such that `z = F y * (F x)⁻ⁿ`. -/ noncomputable def AwayMap.lift (hg : IsUnit (g x)) : N →* P := Submonoid.LocalizationMap.lift F fun y ↦ show IsUnit (g y.1) by obtain ⟨n, hn⟩ := y.2 rw [← hn, g.map_pow] exact IsUnit.pow n hg @[simp] theorem AwayMap.lift_eq (hg : IsUnit (g x)) (a : M) : F.lift x hg (F.toMap a) = g a := Submonoid.LocalizationMap.lift_eq _ _ _ @[simp] theorem AwayMap.lift_comp (hg : IsUnit (g x)) : (F.lift x hg).comp F.toMap = g := Submonoid.LocalizationMap.lift_comp _ _ /-- Given `x y : M` and Localization maps `F : M →* N, G : M →* P` away from `x` and `x * y` respectively, the homomorphism induced from `N` to `P`. -/ noncomputable def awayToAwayRight (y : M) (G : AwayMap (x * y) P) : N →* P := F.lift x <| show IsUnit (G.toMap x) from isUnit_of_mul_eq_one (G.toMap x) (G.mk' y ⟨x * y, mem_powers _⟩) <| by rw [mul_mk'_eq_mk'_of_mul, mk'_self] end AwayMap end LocalizationMap end Submonoid namespace AddSubmonoid namespace LocalizationMap section AwayMap variable {A : Type*} [AddCommMonoid A] (x : A) {B : Type*} [AddCommMonoid B] (F : AwayMap x B) {C : Type*} [AddCommMonoid C] {g : A →+ C} /-- Given `x : A` and a Localization map `F : A →+ B` away from `x`, `neg_self` is `- (F x)`. -/ noncomputable def AwayMap.negSelf : B := F.mk' 0 ⟨x, mem_multiples _⟩ /-- Given `x : A`, a localization map `F : A →+ B` away from `x`, and a map of `AddCommMonoid`s `g : A →+ C` such that `g x` is invertible, the homomorphism induced from `B` to `C` sending `z : B` to `g y - n • g x`, where `y : A, n : ℕ` are such that `z = F y - n • F x`. -/ noncomputable def AwayMap.lift (hg : IsAddUnit (g x)) : B →+ C := AddSubmonoid.LocalizationMap.lift F fun y ↦ show IsAddUnit (g y.1) by obtain ⟨n, hn⟩ := y.2 rw [← hn] dsimp rw [g.map_nsmul] exact IsAddUnit.map (nsmulAddMonoidHom n : C →+ C) hg @[simp] theorem AwayMap.lift_eq (hg : IsAddUnit (g x)) (a : A) : F.lift x hg (F.toMap a) = g a := AddSubmonoid.LocalizationMap.lift_eq _ _ _ @[simp] theorem AwayMap.lift_comp (hg : IsAddUnit (g x)) : (F.lift x hg).comp F.toMap = g := AddSubmonoid.LocalizationMap.lift_comp _ _ /-- Given `x y : A` and Localization maps `F : A →+ B, G : A →+ C` away from `x` and `x + y` respectively, the homomorphism induced from `B` to `C`. -/ noncomputable def awayToAwayRight (y : A) (G : AwayMap (x + y) C) : B →+ C := F.lift x <| show IsAddUnit (G.toMap x) from isAddUnit_of_add_eq_zero (G.toMap x) (G.mk' y ⟨x + y, mem_multiples _⟩) <| by rw [add_mk'_eq_mk'_of_add, mk'_self] end AwayMap end LocalizationMap end AddSubmonoid namespace Submonoid namespace LocalizationMap variable (f : S.LocalizationMap N) {g : M →* P} (hg : ∀ y : S, IsUnit (g y)) {T : Submonoid P} {Q : Type*} [CommMonoid Q] /-- If `f : M →* N` and `k : M →* P` are Localization maps for a Submonoid `S`, we get an isomorphism of `N` and `P`. -/ @[to_additive "If `f : M →+ N` and `k : M →+ R` are Localization maps for an AddSubmonoid `S`, we get an isomorphism of `N` and `R`."] noncomputable def mulEquivOfLocalizations (k : LocalizationMap S P) : N ≃* P := { toFun := f.lift k.map_units invFun := k.lift f.map_units left_inv := f.lift_left_inverse right_inv := k.lift_left_inverse map_mul' := MonoidHom.map_mul _ } @[to_additive (attr := simp)] theorem mulEquivOfLocalizations_apply {k : LocalizationMap S P} {x} : f.mulEquivOfLocalizations k x = f.lift k.map_units x := rfl @[to_additive (attr := simp)] theorem mulEquivOfLocalizations_symm_apply {k : LocalizationMap S P} {x} : (f.mulEquivOfLocalizations k).symm x = k.lift f.map_units x := rfl @[to_additive] theorem mulEquivOfLocalizations_symm_eq_mulEquivOfLocalizations {k : LocalizationMap S P} : (k.mulEquivOfLocalizations f).symm = f.mulEquivOfLocalizations k := rfl /-- If `f : M →* N` is a Localization map for a Submonoid `S` and `k : N ≃* P` is an isomorphism of `CommMonoid`s, `k ∘ f` is a Localization map for `M` at `S`. -/ @[to_additive "If `f : M →+ N` is a Localization map for a Submonoid `S` and `k : N ≃+ P` is an isomorphism of `AddCommMonoid`s, `k ∘ f` is a Localization map for `M` at `S`."] def ofMulEquivOfLocalizations (k : N ≃* P) : LocalizationMap S P := (k.toMonoidHom.comp f.toMap).toLocalizationMap (fun y ↦ isUnit_comp f k.toMonoidHom y) (fun v ↦ let ⟨z, hz⟩ := k.toEquiv.surjective v let ⟨x, hx⟩ := f.surj z ⟨x, show v * k _ = k _ by rw [← hx, k.map_mul, ← hz]; rfl⟩) fun x y ↦ (k.apply_eq_iff_eq.trans f.eq_iff_exists).1 @[to_additive (attr := simp)] theorem ofMulEquivOfLocalizations_apply {k : N ≃* P} (x) : (f.ofMulEquivOfLocalizations k).toMap x = k (f.toMap x) := rfl @[to_additive] theorem ofMulEquivOfLocalizations_eq {k : N ≃* P} : (f.ofMulEquivOfLocalizations k).toMap = k.toMonoidHom.comp f.toMap := rfl @[to_additive] theorem symm_comp_ofMulEquivOfLocalizations_apply {k : N ≃* P} (x) : k.symm ((f.ofMulEquivOfLocalizations k).toMap x) = f.toMap x := k.symm_apply_apply (f.toMap x) @[to_additive] theorem symm_comp_ofMulEquivOfLocalizations_apply' {k : P ≃* N} (x) : k ((f.ofMulEquivOfLocalizations k.symm).toMap x) = f.toMap x := k.apply_symm_apply (f.toMap x) @[to_additive] theorem ofMulEquivOfLocalizations_eq_iff_eq {k : N ≃* P} {x y} : (f.ofMulEquivOfLocalizations k).toMap x = y ↔ f.toMap x = k.symm y := k.toEquiv.eq_symm_apply.symm @[to_additive addEquivOfLocalizations_right_inv] theorem mulEquivOfLocalizations_right_inv (k : LocalizationMap S P) : f.ofMulEquivOfLocalizations (f.mulEquivOfLocalizations k) = k := toMap_injective <| f.lift_comp k.map_units -- @[simp] -- Porting note (#10618): simp can prove this @[to_additive addEquivOfLocalizations_right_inv_apply] theorem mulEquivOfLocalizations_right_inv_apply {k : LocalizationMap S P} {x} : (f.ofMulEquivOfLocalizations (f.mulEquivOfLocalizations k)).toMap x = k.toMap x := by simp @[to_additive] theorem mulEquivOfLocalizations_left_inv (k : N ≃* P) : f.mulEquivOfLocalizations (f.ofMulEquivOfLocalizations k) = k := DFunLike.ext _ _ fun x ↦ DFunLike.ext_iff.1 (f.lift_of_comp k.toMonoidHom) x -- @[simp] -- Porting note (#10618): simp can prove this @[to_additive] theorem mulEquivOfLocalizations_left_inv_apply {k : N ≃* P} (x) : f.mulEquivOfLocalizations (f.ofMulEquivOfLocalizations k) x = k x := by simp @[to_additive (attr := simp)] theorem ofMulEquivOfLocalizations_id : f.ofMulEquivOfLocalizations (MulEquiv.refl N) = f := by ext; rfl @[to_additive] theorem ofMulEquivOfLocalizations_comp {k : N ≃* P} {j : P ≃* Q} : (f.ofMulEquivOfLocalizations (k.trans j)).toMap = j.toMonoidHom.comp (f.ofMulEquivOfLocalizations k).toMap := by ext; rfl /-- Given `CommMonoid`s `M, P` and Submonoids `S ⊆ M, T ⊆ P`, if `f : M →* N` is a Localization map for `S` and `k : P ≃* M` is an isomorphism of `CommMonoid`s such that `k(T) = S`, `f ∘ k` is a Localization map for `T`. -/ @[to_additive "Given `AddCommMonoid`s `M, P` and `AddSubmonoid`s `S ⊆ M, T ⊆ P`, if `f : M →* N` is a Localization map for `S` and `k : P ≃+ M` is an isomorphism of `AddCommMonoid`s such that `k(T) = S`, `f ∘ k` is a Localization map for `T`."] def ofMulEquivOfDom {k : P ≃* M} (H : T.map k.toMonoidHom = S) : LocalizationMap T N := let H' : S.comap k.toMonoidHom = T := H ▸ (SetLike.coe_injective <| T.1.1.preimage_image_eq k.toEquiv.injective) (f.toMap.comp k.toMonoidHom).toLocalizationMap (fun y ↦ let ⟨z, hz⟩ := f.map_units ⟨k y, H ▸ Set.mem_image_of_mem k y.2⟩ ⟨z, hz⟩) (fun z ↦ let ⟨x, hx⟩ := f.surj z let ⟨v, hv⟩ := k.toEquiv.surjective x.1 let ⟨w, hw⟩ := k.toEquiv.surjective x.2 ⟨(v, ⟨w, H' ▸ show k w ∈ S from hw.symm ▸ x.2.2⟩), show z * f.toMap (k.toEquiv w) = f.toMap (k.toEquiv v) by erw [hv, hw, hx]⟩) fun x y ↦ show f.toMap _ = f.toMap _ → _ by erw [f.eq_iff_exists] exact fun ⟨c, hc⟩ ↦ let ⟨d, hd⟩ := k.toEquiv.surjective c ⟨⟨d, H' ▸ show k d ∈ S from hd.symm ▸ c.2⟩, by erw [← hd, ← k.map_mul, ← k.map_mul] at hc; exact k.toEquiv.injective hc⟩ @[to_additive (attr := simp)] theorem ofMulEquivOfDom_apply {k : P ≃* M} (H : T.map k.toMonoidHom = S) (x) : (f.ofMulEquivOfDom H).toMap x = f.toMap (k x) := rfl @[to_additive] theorem ofMulEquivOfDom_eq {k : P ≃* M} (H : T.map k.toMonoidHom = S) : (f.ofMulEquivOfDom H).toMap = f.toMap.comp k.toMonoidHom := rfl @[to_additive] theorem ofMulEquivOfDom_comp_symm {k : P ≃* M} (H : T.map k.toMonoidHom = S) (x) : (f.ofMulEquivOfDom H).toMap (k.symm x) = f.toMap x := congr_arg f.toMap <| k.apply_symm_apply x @[to_additive] theorem ofMulEquivOfDom_comp {k : M ≃* P} (H : T.map k.symm.toMonoidHom = S) (x) : (f.ofMulEquivOfDom H).toMap (k x) = f.toMap x := congr_arg f.toMap <| k.symm_apply_apply x /-- A special case of `f ∘ id = f`, `f` a Localization map. -/ @[to_additive (attr := simp) "A special case of `f ∘ id = f`, `f` a Localization map."] theorem ofMulEquivOfDom_id : f.ofMulEquivOfDom (show S.map (MulEquiv.refl M).toMonoidHom = S from Submonoid.ext fun x ↦ ⟨fun ⟨_, hy, h⟩ ↦ h ▸ hy, fun h ↦ ⟨x, h, rfl⟩⟩) = f := by ext; rfl /-- Given Localization maps `f : M →* N, k : P →* U` for Submonoids `S, T` respectively, an isomorphism `j : M ≃* P` such that `j(S) = T` induces an isomorphism of localizations `N ≃* U`. -/ @[to_additive "Given Localization maps `f : M →+ N, k : P →+ U` for Submonoids `S, T` respectively, an isomorphism `j : M ≃+ P` such that `j(S) = T` induces an isomorphism of localizations `N ≃+ U`."] noncomputable def mulEquivOfMulEquiv (k : LocalizationMap T Q) {j : M ≃* P} (H : S.map j.toMonoidHom = T) : N ≃* Q := f.mulEquivOfLocalizations <| k.ofMulEquivOfDom H @[to_additive (attr := simp)] theorem mulEquivOfMulEquiv_eq_map_apply {k : LocalizationMap T Q} {j : M ≃* P} (H : S.map j.toMonoidHom = T) (x) : f.mulEquivOfMulEquiv k H x = f.map (fun y : S ↦ show j.toMonoidHom y ∈ T from H ▸ Set.mem_image_of_mem j y.2) k x := rfl @[to_additive] theorem mulEquivOfMulEquiv_eq_map {k : LocalizationMap T Q} {j : M ≃* P} (H : S.map j.toMonoidHom = T) : (f.mulEquivOfMulEquiv k H).toMonoidHom = f.map (fun y : S ↦ show j.toMonoidHom y ∈ T from H ▸ Set.mem_image_of_mem j y.2) k := rfl @[to_additive (attr := simp, nolint simpNF)] theorem mulEquivOfMulEquiv_eq {k : LocalizationMap T Q} {j : M ≃* P} (H : S.map j.toMonoidHom = T) (x) : f.mulEquivOfMulEquiv k H (f.toMap x) = k.toMap (j x) := f.map_eq (fun y : S ↦ H ▸ Set.mem_image_of_mem j y.2) _ @[to_additive (attr := simp, nolint simpNF)] theorem mulEquivOfMulEquiv_mk' {k : LocalizationMap T Q} {j : M ≃* P} (H : S.map j.toMonoidHom = T) (x y) : f.mulEquivOfMulEquiv k H (f.mk' x y) = k.mk' (j x) ⟨j y, H ▸ Set.mem_image_of_mem j y.2⟩ := f.map_mk' (fun y : S ↦ H ▸ Set.mem_image_of_mem j y.2) _ _ @[to_additive (attr := simp, nolint simpNF)] theorem of_mulEquivOfMulEquiv_apply {k : LocalizationMap T Q} {j : M ≃* P} (H : S.map j.toMonoidHom = T) (x) : (f.ofMulEquivOfLocalizations (f.mulEquivOfMulEquiv k H)).toMap x = k.toMap (j x) := Submonoid.LocalizationMap.ext_iff.1 (f.mulEquivOfLocalizations_right_inv (k.ofMulEquivOfDom H)) x @[to_additive] theorem of_mulEquivOfMulEquiv {k : LocalizationMap T Q} {j : M ≃* P} (H : S.map j.toMonoidHom = T) : (f.ofMulEquivOfLocalizations (f.mulEquivOfMulEquiv k H)).toMap = k.toMap.comp j.toMonoidHom := MonoidHom.ext <| f.of_mulEquivOfMulEquiv_apply H end LocalizationMap end Submonoid namespace Localization variable (S) /-- Natural homomorphism sending `x : M`, `M` a `CommMonoid`, to the equivalence class of `(x, 1)` in the Localization of `M` at a Submonoid. -/ @[to_additive "Natural homomorphism sending `x : M`, `M` an `AddCommMonoid`, to the equivalence class of `(x, 0)` in the Localization of `M` at a Submonoid."] def monoidOf : Submonoid.LocalizationMap S (Localization S) := { (r S).mk'.comp <| MonoidHom.inl M S with toFun := fun x ↦ mk x 1 map_one' := mk_one map_mul' := fun x y ↦ by dsimp only; rw [mk_mul, mul_one] map_units' := fun y ↦ isUnit_iff_exists_inv.2 ⟨mk 1 y, by dsimp only; rw [mk_mul, mul_one, one_mul, mk_self]⟩ surj' := fun z ↦ induction_on z fun x ↦ ⟨x, by dsimp only; rw [mk_mul, mul_comm x.fst, ← mk_mul, mk_self, one_mul]⟩ exists_of_eq := fun x y ↦ Iff.mp <| mk_eq_mk_iff.trans <| r_iff_exists.trans <| show (∃ c : S, ↑c * (1 * x) = c * (1 * y)) ↔ _ by rw [one_mul, one_mul] } variable {S} @[to_additive] theorem mk_one_eq_monoidOf_mk (x) : mk x 1 = (monoidOf S).toMap x := rfl @[to_additive] theorem mk_eq_monoidOf_mk'_apply (x y) : mk x y = (monoidOf S).mk' x y := show _ = _ * _ from (Submonoid.LocalizationMap.mul_inv_right (monoidOf S).map_units _ _ _).2 <| by rw [← mk_one_eq_monoidOf_mk, ← mk_one_eq_monoidOf_mk, mk_mul x y y 1, mul_comm y 1] conv => rhs; rw [← mul_one 1]; rw [← mul_one x] exact mk_eq_mk_iff.2 (Con.symm _ <| (Localization.r S).mul (Con.refl _ (x, 1)) <| one_rel _) @[to_additive (attr := simp)] theorem mk_eq_monoidOf_mk' : mk = (monoidOf S).mk' := funext fun _ ↦ funext fun _ ↦ mk_eq_monoidOf_mk'_apply _ _ universe u @[to_additive (attr := simp)] theorem liftOn_mk' {p : Sort u} (f : M → S → p) (H) (a : M) (b : S) : liftOn ((monoidOf S).mk' a b) f H = f a b := by rw [← mk_eq_monoidOf_mk', liftOn_mk] @[to_additive (attr := simp)] theorem liftOn₂_mk' {p : Sort*} (f : M → S → M → S → p) (H) (a c : M) (b d : S) : liftOn₂ ((monoidOf S).mk' a b) ((monoidOf S).mk' c d) f H = f a b c d := by rw [← mk_eq_monoidOf_mk', liftOn₂_mk] variable (f : Submonoid.LocalizationMap S N) /-- Given a Localization map `f : M →* N` for a Submonoid `S`, we get an isomorphism between the Localization of `M` at `S` as a quotient type and `N`. -/ @[to_additive "Given a Localization map `f : M →+ N` for a Submonoid `S`, we get an isomorphism between the Localization of `M` at `S` as a quotient type and `N`."] noncomputable def mulEquivOfQuotient (f : Submonoid.LocalizationMap S N) : Localization S ≃* N := (monoidOf S).mulEquivOfLocalizations f variable {f} @[to_additive (attr := simp)] theorem mulEquivOfQuotient_apply (x) : mulEquivOfQuotient f x = (monoidOf S).lift f.map_units x := rfl @[to_additive (attr := simp, nolint simpNF)] theorem mulEquivOfQuotient_mk' (x y) : mulEquivOfQuotient f ((monoidOf S).mk' x y) = f.mk' x y := (monoidOf S).lift_mk' _ _ _ @[to_additive] theorem mulEquivOfQuotient_mk (x y) : mulEquivOfQuotient f (mk x y) = f.mk' x y := by rw [mk_eq_monoidOf_mk'_apply]; exact mulEquivOfQuotient_mk' _ _ -- @[simp] -- Porting note (#10618): simp can prove this @[to_additive] theorem mulEquivOfQuotient_monoidOf (x) : mulEquivOfQuotient f ((monoidOf S).toMap x) = f.toMap x := by simp @[to_additive (attr := simp)] theorem mulEquivOfQuotient_symm_mk' (x y) : (mulEquivOfQuotient f).symm (f.mk' x y) = (monoidOf S).mk' x y := f.lift_mk' (monoidOf S).map_units _ _ @[to_additive] theorem mulEquivOfQuotient_symm_mk (x y) : (mulEquivOfQuotient f).symm (f.mk' x y) = mk x y := by rw [mk_eq_monoidOf_mk'_apply]; exact mulEquivOfQuotient_symm_mk' _ _ @[to_additive (attr := simp)] theorem mulEquivOfQuotient_symm_monoidOf (x) : (mulEquivOfQuotient f).symm (f.toMap x) = (monoidOf S).toMap x := f.lift_eq (monoidOf S).map_units _ section Away variable (x : M) /-- Given `x : M`, the Localization of `M` at the Submonoid generated by `x`, as a quotient. -/ @[to_additive (attr := reducible) "Given `x : M`, the Localization of `M` at the Submonoid generated by `x`, as a quotient."] def Away := Localization (Submonoid.powers x) /-- Given `x : M`, `invSelf` is `x⁻¹` in the Localization (as a quotient type) of `M` at the Submonoid generated by `x`. -/ @[to_additive "Given `x : M`, `negSelf` is `-x` in the Localization (as a quotient type) of `M` at the Submonoid generated by `x`."] def Away.invSelf : Away x := mk 1 ⟨x, Submonoid.mem_powers _⟩ /-- Given `x : M`, the natural hom sending `y : M`, `M` a `CommMonoid`, to the equivalence class of `(y, 1)` in the Localization of `M` at the Submonoid generated by `x`. -/ @[to_additive (attr := reducible) "Given `x : M`, the natural hom sending `y : M`, `M` an `AddCommMonoid`, to the equivalence class of `(y, 0)` in the Localization of `M` at the Submonoid generated by `x`."] def Away.monoidOf : Submonoid.LocalizationMap.AwayMap x (Away x) := Localization.monoidOf (Submonoid.powers x) -- @[simp] -- Porting note (#10618): simp can prove thisrove this @[to_additive] theorem Away.mk_eq_monoidOf_mk' : mk = (Away.monoidOf x).mk' := by simp /-- Given `x : M` and a Localization map `f : M →* N` away from `x`, we get an isomorphism between the Localization of `M` at the Submonoid generated by `x` as a quotient type and `N`. -/ @[to_additive "Given `x : M` and a Localization map `f : M →+ N` away from `x`, we get an isomorphism between the Localization of `M` at the Submonoid generated by `x` as a quotient type and `N`."] noncomputable def Away.mulEquivOfQuotient (f : Submonoid.LocalizationMap.AwayMap x N) : Away x ≃* N := Localization.mulEquivOfQuotient f end Away end Localization end CommMonoid namespace Localization variable {α : Type*} [CancelCommMonoid α] {s : Submonoid α} {a₁ b₁ : α} {a₂ b₂ : s} @[to_additive] theorem mk_left_injective (b : s) : Injective fun a => mk a b := fun c d h => by simpa [-mk_eq_monoidOf_mk', mk_eq_mk_iff, r_iff_exists] using h @[to_additive] theorem mk_eq_mk_iff' : mk a₁ a₂ = mk b₁ b₂ ↔ ↑b₂ * a₁ = a₂ * b₁ := by simp_rw [mk_eq_mk_iff, r_iff_exists, mul_left_cancel_iff, exists_const] @[to_additive] instance decidableEq [DecidableEq α] : DecidableEq (Localization s) := fun a b => Localization.recOnSubsingleton₂ a b fun _ _ _ _ => decidable_of_iff' _ mk_eq_mk_iff' end Localization namespace OreLocalization variable (R) [CommMonoid R] (S : Submonoid R) /-- The morphism `numeratorHom` is a monoid localization map in the case of commutative `R`. -/ protected def localizationMap : S.LocalizationMap R[S⁻¹] := Localization.monoidOf S /-- If `R` is commutative, Ore localization and monoid localization are isomorphic. -/ protected noncomputable def equivMonoidLocalization : Localization S ≃* R[S⁻¹] := MulEquiv.refl _ end OreLocalization
GroupTheory\MonoidLocalization\MonoidWithZero.lean
/- Copyright (c) 2019 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Amelia Livingston -/ import Mathlib.Algebra.Regular.Basic import Mathlib.GroupTheory.MonoidLocalization.Basic /-! # Localizations of commutative monoids with zeroes -/ open Function namespace Submonoid.LocalizationMap @[to_additive] theorem toMap_injective_iff {M N : Type*} [CommMonoid M] {S : Submonoid M} [CommMonoid N] (f : LocalizationMap S N) : Injective (LocalizationMap.toMap f) ↔ ∀ ⦃x⦄, x ∈ S → IsLeftRegular x := by rw [Injective] constructor <;> intro h · intro x hx y z hyz simp_rw [LocalizationMap.eq_iff_exists] at h apply (fun y z _ => h) y z x lift x to S using hx use x · intro a b hab rw [LocalizationMap.eq_iff_exists] at hab obtain ⟨c,hc⟩ := hab apply (fun x a => h a) c (SetLike.coe_mem c) hc end Submonoid.LocalizationMap section CommMonoidWithZero variable {M : Type*} [CommMonoidWithZero M] (S : Submonoid M) (N : Type*) [CommMonoidWithZero N] {P : Type*} [CommMonoidWithZero P] namespace Submonoid variable {S N} in /-- If `S` contains `0` then the localization at `S` is trivial. -/ theorem LocalizationMap.subsingleton (f : Submonoid.LocalizationMap S N) (h : 0 ∈ S) : Subsingleton N := by refine ⟨fun a b ↦ ?_⟩ rw [← LocalizationMap.mk'_sec f a, ← LocalizationMap.mk'_sec f b, LocalizationMap.eq] exact ⟨⟨0, h⟩, by simp only [zero_mul]⟩ /-- The type of homomorphisms between monoids with zero satisfying the characteristic predicate: if `f : M →*₀ N` satisfies this predicate, then `N` is isomorphic to the localization of `M` at `S`. -/ -- Porting note(#5171): this linter isn't ported yet. -- @[nolint has_nonempty_instance] structure LocalizationWithZeroMap extends LocalizationMap S N where map_zero' : toFun 0 = 0 -- Porting note: no docstrings for LocalizationWithZeroMap.map_zero' attribute [nolint docBlame] LocalizationWithZeroMap.toLocalizationMap LocalizationWithZeroMap.map_zero' variable {S N} /-- The monoid with zero hom underlying a `LocalizationMap`. -/ def LocalizationWithZeroMap.toMonoidWithZeroHom (f : LocalizationWithZeroMap S N) : M →*₀ N := { f with } end Submonoid namespace Localization variable {S} theorem mk_zero (x : S) : mk 0 (x : S) = 0 := OreLocalization.zero_oreDiv' _ instance : CommMonoidWithZero (Localization S) where zero_mul := fun x ↦ Localization.induction_on x fun y => by simp only [← Localization.mk_zero y.2, mk_mul, mk_eq_mk_iff, mul_zero, zero_mul, r_of_eq] mul_zero := fun x ↦ Localization.induction_on x fun y => by simp only [← Localization.mk_zero y.2, mk_mul, mk_eq_mk_iff, mul_zero, zero_mul, r_of_eq] theorem liftOn_zero {p : Type*} (f : M → S → p) (H) : liftOn 0 f H = f 0 1 := by rw [← mk_zero 1, liftOn_mk] end Localization variable {S N} namespace Submonoid @[simp] theorem LocalizationMap.sec_zero_fst {f : LocalizationMap S N} : f.toMap (f.sec 0).fst = 0 := by rw [LocalizationMap.sec_spec', mul_zero] namespace LocalizationWithZeroMap /-- Given a Localization map `f : M →*₀ N` for a Submonoid `S ⊆ M` and a map of `CommMonoidWithZero`s `g : M →*₀ P` such that `g y` is invertible for all `y : S`, the homomorphism induced from `N` to `P` sending `z : N` to `g x * (g y)⁻¹`, where `(x, y) : M × S` are such that `z = f x * (f y)⁻¹`. -/ noncomputable def lift (f : LocalizationWithZeroMap S N) (g : M →*₀ P) (hg : ∀ y : S, IsUnit (g y)) : N →*₀ P := { @LocalizationMap.lift _ _ _ _ _ _ _ f.toLocalizationMap g.toMonoidHom hg with map_zero' := by erw [LocalizationMap.lift_spec f.toLocalizationMap hg 0 0] rw [mul_zero, ← map_zero g, ← g.toMonoidHom_coe] refine f.toLocalizationMap.eq_of_eq hg ?_ rw [LocalizationMap.sec_zero_fst] exact f.toMonoidWithZeroHom.map_zero.symm } /-- Given a Localization map `f : M →*₀ N` for a Submonoid `S ⊆ M`, if `M` is left cancellative monoid with zero, and all elements of `S` are left regular, then N is a left cancellative monoid with zero. -/ theorem leftCancelMulZero_of_le_isLeftRegular (f : LocalizationWithZeroMap S N) [IsLeftCancelMulZero M] (h : ∀ ⦃x⦄, x ∈ S → IsLeftRegular x) : IsLeftCancelMulZero N := by let fl := f.toLocalizationMap let g := f.toMap constructor intro a z w ha hazw obtain ⟨b, hb⟩ := LocalizationMap.surj fl a obtain ⟨x, hx⟩ := LocalizationMap.surj fl z obtain ⟨y, hy⟩ := LocalizationMap.surj fl w rw [(LocalizationMap.eq_mk'_iff_mul_eq fl).mpr hx, (LocalizationMap.eq_mk'_iff_mul_eq fl).mpr hy, LocalizationMap.eq] use 1 rw [OneMemClass.coe_one, one_mul, one_mul] -- The hypothesis `a ≠ 0` in `P` is equivalent to this have b1ne0 : b.1 ≠ 0 := by intro hb1 have m0 : (LocalizationMap.toMap fl) 0 = 0 := f.map_zero' have a0 : a * (LocalizationMap.toMap fl) b.2 = 0 ↔ a = 0 := (f.toLocalizationMap.map_units' b.2).mul_left_eq_zero rw [hb1, m0, a0] at hb exact ha hb have main : g (b.1 * (x.2 * y.1)) = g (b.1 * (y.2 * x.1)) := calc g (b.1 * (x.2 * y.1)) = g b.1 * (g x.2 * g y.1) := by rw [map_mul g,map_mul g] _ = a * g b.2 * (g x.2 * (w * g y.2)) := by rw [hb, hy] _ = a * w * g b.2 * (g x.2 * g y.2) := by rw [← mul_assoc, ← mul_assoc _ w, mul_comm _ w, mul_assoc w, mul_assoc, ← mul_assoc w, ← mul_assoc w, mul_comm w] _ = a * z * g b.2 * (g x.2 * g y.2) := by rw [hazw] _ = a * g b.2 * (z * g x.2 * g y.2) := by rw [mul_assoc a, mul_comm z, ← mul_assoc a, mul_assoc, mul_assoc z] _ = g b.1 * g (y.2 * x.1) := by rw [hx, hb, mul_comm (g x.1), ← map_mul g] _ = g (b.1 * (y.2 * x.1)) := by rw [← map_mul g] -- The hypothesis `h` gives that `f` (so, `g`) is injective, and we can cancel out `b.1`. exact (IsLeftCancelMulZero.mul_left_cancel_of_ne_zero b1ne0 ((LocalizationMap.toMap_injective_iff fl).mpr h main)).symm /-- Given a Localization map `f : M →*₀ N` for a Submonoid `S ⊆ M`, if `M` is a cancellative monoid with zero, and all elements of `S` are regular, then N is a cancellative monoid with zero. -/ theorem isLeftRegular_of_le_isCancelMulZero (f : LocalizationWithZeroMap S N) [IsCancelMulZero M] (h : ∀ ⦃x⦄, x ∈ S → IsRegular x) : IsCancelMulZero N := by have : IsLeftCancelMulZero N := leftCancelMulZero_of_le_isLeftRegular f (fun x h' => (h h').left) exact IsLeftCancelMulZero.to_isCancelMulZero @[deprecated isLeftRegular_of_le_isCancelMulZero (since := "2024-01-16")] alias isLeftRegular_of_le_IsCancelMulZero := isLeftRegular_of_le_isCancelMulZero end LocalizationWithZeroMap end Submonoid end CommMonoidWithZero
GroupTheory\MonoidLocalization\Order.lean
/- Copyright (c) 2019 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Amelia Livingston -/ import Mathlib.GroupTheory.MonoidLocalization.Basic /-! # Ordered structures on localizations of commutative monoids -/ open Function namespace Localization variable {α : Type*} section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid α] {s : Submonoid α} {a₁ b₁ : α} {a₂ b₂ : s} @[to_additive] instance le : LE (Localization s) := ⟨fun a b => Localization.liftOn₂ a b (fun a₁ a₂ b₁ b₂ => ↑b₂ * a₁ ≤ a₂ * b₁) fun {a₁ b₁ a₂ b₂ c₁ d₁ c₂ d₂} hab hcd => propext <| by obtain ⟨e, he⟩ := r_iff_exists.1 hab obtain ⟨f, hf⟩ := r_iff_exists.1 hcd simp only [mul_right_inj] at he hf dsimp rw [← mul_le_mul_iff_right, mul_right_comm, ← hf, mul_right_comm, mul_right_comm (a₂ : α), mul_le_mul_iff_right, ← mul_le_mul_iff_left, mul_left_comm, he, mul_left_comm, mul_left_comm (b₂ : α), mul_le_mul_iff_left]⟩ @[to_additive] instance lt : LT (Localization s) := ⟨fun a b => Localization.liftOn₂ a b (fun a₁ a₂ b₁ b₂ => ↑b₂ * a₁ < a₂ * b₁) fun {a₁ b₁ a₂ b₂ c₁ d₁ c₂ d₂} hab hcd => propext <| by obtain ⟨e, he⟩ := r_iff_exists.1 hab obtain ⟨f, hf⟩ := r_iff_exists.1 hcd simp only [mul_right_inj] at he hf dsimp rw [← mul_lt_mul_iff_right, mul_right_comm, ← hf, mul_right_comm, mul_right_comm (a₂ : α), mul_lt_mul_iff_right, ← mul_lt_mul_iff_left, mul_left_comm, he, mul_left_comm, mul_left_comm (b₂ : α), mul_lt_mul_iff_left]⟩ @[to_additive] theorem mk_le_mk : mk a₁ a₂ ≤ mk b₁ b₂ ↔ ↑b₂ * a₁ ≤ a₂ * b₁ := Iff.rfl @[to_additive] theorem mk_lt_mk : mk a₁ a₂ < mk b₁ b₂ ↔ ↑b₂ * a₁ < a₂ * b₁ := Iff.rfl -- declaring this separately to the instance below makes things faster @[to_additive] instance partialOrder : PartialOrder (Localization s) where le := (· ≤ ·) lt := (· < ·) le_refl a := Localization.induction_on a fun a => le_rfl le_trans a b c := Localization.induction_on₃ a b c fun a b c hab hbc => by simp only [mk_le_mk] at hab hbc ⊢ apply le_of_mul_le_mul_left' _ · exact ↑b.2 rw [mul_left_comm] refine (mul_le_mul_left' hab _).trans ?_ rwa [mul_left_comm, mul_left_comm (b.2 : α), mul_le_mul_iff_left] le_antisymm a b := by induction' a using Localization.rec with a₁ a₂ on_goal 1 => induction' b using Localization.rec with b₁ b₂ · simp_rw [mk_le_mk, mk_eq_mk_iff, r_iff_exists] exact fun hab hba => ⟨1, by rw [hab.antisymm hba]⟩ all_goals rfl lt_iff_le_not_le a b := Localization.induction_on₂ a b fun a b => lt_iff_le_not_le @[to_additive] instance orderedCancelCommMonoid : OrderedCancelCommMonoid (Localization s) where mul_le_mul_left := fun a b => Localization.induction_on₂ a b fun a b hab c => Localization.induction_on c fun c => by simp only [mk_mul, mk_le_mk, Submonoid.coe_mul, mul_mul_mul_comm _ _ c.1] at hab ⊢ exact mul_le_mul_left' hab _ le_of_mul_le_mul_left := fun a b c => Localization.induction_on₃ a b c fun a b c hab => by simp only [mk_mul, mk_le_mk, Submonoid.coe_mul, mul_mul_mul_comm _ _ a.1] at hab ⊢ exact le_of_mul_le_mul_left' hab @[to_additive] instance decidableLE [DecidableRel ((· ≤ ·) : α → α → Prop)] : DecidableRel ((· ≤ ·) : Localization s → Localization s → Prop) := fun a b => Localization.recOnSubsingleton₂ a b fun _ _ _ _ => decidable_of_iff' _ mk_le_mk @[to_additive] instance decidableLT [DecidableRel ((· < ·) : α → α → Prop)] : DecidableRel ((· < ·) : Localization s → Localization s → Prop) := fun a b => Localization.recOnSubsingleton₂ a b fun _ _ _ _ => decidable_of_iff' _ mk_lt_mk /-- An ordered cancellative monoid injects into its localization by sending `a` to `a / b`. -/ @[to_additive (attr := simps!) "An ordered cancellative monoid injects into its localization by sending `a` to `a - b`."] def mkOrderEmbedding (b : s) : α ↪o Localization s where toFun a := mk a b inj' := mk_left_injective _ map_rel_iff' {a b} := by simp [-mk_eq_monoidOf_mk', mk_le_mk] end OrderedCancelCommMonoid @[to_additive] instance [LinearOrderedCancelCommMonoid α] {s : Submonoid α} : LinearOrderedCancelCommMonoid (Localization s) := { Localization.orderedCancelCommMonoid with le_total := fun a b => Localization.induction_on₂ a b fun _ _ => by simp_rw [mk_le_mk] exact le_total _ _ decidableLE := Localization.decidableLE decidableLT := Localization.decidableLT -- Porting note: was wrong in mathlib3 decidableEq := Localization.decidableEq } end Localization
GroupTheory\Order\Min.lean
/- Copyright (c) 2023 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.GroupTheory.Torsion /-! # Minimum order of an element This file defines the minimum order of an element of a monoid. ## Main declarations * `Monoid.minOrder`: The minimum order of an element of a given monoid. * `Monoid.minOrder_eq_top`: The minimum order is infinite iff the monoid is torsion-free. * `ZMod.minOrder`: The minimum order of $$ℤ/nℤ$$ is the smallest factor of `n`, unless `n = 0, 1`. -/ open Subgroup variable {α : Type*} namespace Monoid section Monoid variable (α) [Monoid α] /-- The minimum order of a non-identity element. Also the minimum size of a nontrivial subgroup, see `Monoid.le_minOrder_iff_forall_subgroup`. Returns `∞` if the monoid is torsion-free. -/ @[to_additive "The minimum order of a non-identity element. Also the minimum size of a nontrivial subgroup, see `AddMonoid.le_minOrder_iff_forall_addSubgroup`. Returns `∞` if the monoid is torsion-free."] noncomputable def minOrder : ℕ∞ := ⨅ (a : α) (_ha : a ≠ 1) (_ha' : IsOfFinOrder a), orderOf a variable {α} {a : α} @[to_additive (attr := simp)] lemma minOrder_eq_top : minOrder α = ⊤ ↔ IsTorsionFree α := by simp [minOrder, IsTorsionFree] @[to_additive (attr := simp)] protected alias ⟨_, IsTorsionFree.minOrder⟩ := minOrder_eq_top @[to_additive (attr := simp)] lemma le_minOrder {n : ℕ∞} : n ≤ minOrder α ↔ ∀ ⦃a : α⦄, a ≠ 1 → IsOfFinOrder a → n ≤ orderOf a := by simp [minOrder] @[to_additive] lemma minOrder_le_orderOf (ha : a ≠ 1) (ha' : IsOfFinOrder a) : minOrder α ≤ orderOf a := le_minOrder.1 le_rfl ha ha' end Monoid variable [Group α] {s : Subgroup α} {n : ℕ} @[to_additive] lemma le_minOrder_iff_forall_subgroup {n : ℕ∞} : n ≤ minOrder α ↔ ∀ ⦃s : Subgroup α⦄, s ≠ ⊥ → (s : Set α).Finite → n ≤ Nat.card s := by rw [le_minOrder] refine ⟨fun h s hs hs' ↦ ?_, fun h a ha ha' ↦ ?_⟩ · obtain ⟨a, has, ha⟩ := s.bot_or_exists_ne_one.resolve_left hs exact (h ha <| finite_zpowers.1 <| hs'.subset <| zpowers_le.2 has).trans (WithTop.coe_le_coe.2 <| s.orderOf_le_card hs' has) · simpa using h (zpowers_ne_bot.2 ha) ha'.finite_zpowers @[to_additive] lemma minOrder_le_natCard (hs : s ≠ ⊥) (hs' : (s : Set α).Finite) : minOrder α ≤ Nat.card s := le_minOrder_iff_forall_subgroup.1 le_rfl hs hs' end Monoid open AddMonoid AddSubgroup Nat Set namespace ZMod @[simp] protected lemma minOrder {n : ℕ} (hn : n ≠ 0) (hn₁ : n ≠ 1) : minOrder (ZMod n) = n.minFac := by have : Fact (1 < n) := ⟨one_lt_iff_ne_zero_and_ne_one.mpr ⟨hn, hn₁⟩⟩ classical have : (↑(n / n.minFac) : ZMod n) ≠ 0 := by rw [Ne, ringChar.spec, ringChar.eq (ZMod n) n] exact not_dvd_of_pos_of_lt (Nat.div_pos (minFac_le hn.bot_lt) n.minFac_pos) (div_lt_self hn.bot_lt (minFac_prime hn₁).one_lt) refine ((minOrder_le_natCard (zmultiples_eq_bot.not.2 this) <| toFinite _).trans ?_).antisymm <| le_minOrder_iff_forall_addSubgroup.2 fun s hs _ ↦ ?_ · rw [Nat.card_zmultiples, ZMod.addOrderOf_coe _ hn, gcd_eq_right (div_dvd_of_dvd n.minFac_dvd), Nat.div_div_self n.minFac_dvd hn] · haveI : Nontrivial s := s.bot_or_nontrivial.resolve_left hs exact WithTop.coe_le_coe.2 <| minFac_le_of_dvd Finite.one_lt_card <| (card_addSubgroup_dvd_card _).trans n.card_zmod.dvd @[simp] lemma minOrder_of_prime {p : ℕ} (hp : p.Prime) : minOrder (ZMod p) = p := by rw [ZMod.minOrder hp.ne_zero hp.ne_one, hp.minFac_eq] end ZMod
GroupTheory\Perm\Basic.lean
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Mario Carneiro -/ import Mathlib.Algebra.Group.Prod import Mathlib.Algebra.Group.Units.Equiv import Mathlib.Algebra.GroupPower.IterateHom import Mathlib.Logic.Equiv.Set import Mathlib.Tactic.Common /-! # The group of permutations (self-equivalences) of a type `α` This file defines the `Group` structure on `Equiv.Perm α`. -/ universe u v namespace Equiv variable {α : Type u} {β : Type v} namespace Perm instance instOne : One (Perm α) where one := Equiv.refl _ instance instMul : Mul (Perm α) where mul f g := Equiv.trans g f instance instInv : Inv (Perm α) where inv := Equiv.symm instance instPowNat : Pow (Perm α) ℕ where pow f n := ⟨f^[n], f.symm^[n], f.left_inv.iterate _, f.right_inv.iterate _⟩ instance permGroup : Group (Perm α) where mul_assoc f g h := (trans_assoc _ _ _).symm one_mul := trans_refl mul_one := refl_trans mul_left_inv := self_trans_symm npow n f := f ^ n npow_succ n f := coe_fn_injective $ Function.iterate_succ _ _ zpow := zpowRec fun n f ↦ f ^ n zpow_succ' n f := coe_fn_injective $ Function.iterate_succ _ _ @[simp] theorem default_eq : (default : Perm α) = 1 := rfl /-- The permutation of a type is equivalent to the units group of the endomorphisms monoid of this type. -/ @[simps] def equivUnitsEnd : Perm α ≃* Units (Function.End α) where -- Porting note: needed to add `.toFun`. toFun e := ⟨e.toFun, e.symm.toFun, e.self_comp_symm, e.symm_comp_self⟩ invFun u := ⟨(u : Function.End α), (↑u⁻¹ : Function.End α), congr_fun u.inv_val, congr_fun u.val_inv⟩ left_inv _ := ext fun _ => rfl right_inv _ := Units.ext rfl map_mul' _ _ := rfl /-- Lift a monoid homomorphism `f : G →* Function.End α` to a monoid homomorphism `f : G →* Equiv.Perm α`. -/ @[simps!] def _root_.MonoidHom.toHomPerm {G : Type*} [Group G] (f : G →* Function.End α) : G →* Perm α := equivUnitsEnd.symm.toMonoidHom.comp f.toHomUnits theorem mul_apply (f g : Perm α) (x) : (f * g) x = f (g x) := Equiv.trans_apply _ _ _ theorem one_apply (x) : (1 : Perm α) x = x := rfl @[simp] theorem inv_apply_self (f : Perm α) (x) : f⁻¹ (f x) = x := f.symm_apply_apply x @[simp] theorem apply_inv_self (f : Perm α) (x) : f (f⁻¹ x) = x := f.apply_symm_apply x theorem one_def : (1 : Perm α) = Equiv.refl α := rfl theorem mul_def (f g : Perm α) : f * g = g.trans f := rfl theorem inv_def (f : Perm α) : f⁻¹ = f.symm := rfl @[simp, norm_cast] lemma coe_one : ⇑(1 : Perm α) = id := rfl @[simp, norm_cast] lemma coe_mul (f g : Perm α) : ⇑(f * g) = f ∘ g := rfl @[norm_cast] lemma coe_pow (f : Perm α) (n : ℕ) : ⇑(f ^ n) = f^[n] := rfl @[simp] lemma iterate_eq_pow (f : Perm α) (n : ℕ) : f^[n] = ⇑(f ^ n) := rfl theorem eq_inv_iff_eq {f : Perm α} {x y : α} : x = f⁻¹ y ↔ f x = y := f.eq_symm_apply theorem inv_eq_iff_eq {f : Perm α} {x y : α} : f⁻¹ x = y ↔ x = f y := f.symm_apply_eq theorem zpow_apply_comm {α : Type*} (σ : Perm α) (m n : ℤ) {x : α} : (σ ^ m) ((σ ^ n) x) = (σ ^ n) ((σ ^ m) x) := by rw [← Equiv.Perm.mul_apply, ← Equiv.Perm.mul_apply, zpow_mul_comm] @[simp] lemma image_inv (f : Perm α) (s : Set α) : ↑f⁻¹ '' s = f ⁻¹' s := f⁻¹.image_eq_preimage _ @[simp] lemma preimage_inv (f : Perm α) (s : Set α) : ↑f⁻¹ ⁻¹' s = f '' s := (f.image_eq_preimage _).symm /-! Lemmas about mixing `Perm` with `Equiv`. Because we have multiple ways to express `Equiv.refl`, `Equiv.symm`, and `Equiv.trans`, we want simp lemmas for every combination. The assumption made here is that if you're using the group structure, you want to preserve it after simp. -/ @[simp] theorem trans_one {α : Sort*} {β : Type*} (e : α ≃ β) : e.trans (1 : Perm β) = e := Equiv.trans_refl e @[simp] theorem mul_refl (e : Perm α) : e * Equiv.refl α = e := Equiv.trans_refl e @[simp] theorem one_symm : (1 : Perm α).symm = 1 := Equiv.refl_symm @[simp] theorem refl_inv : (Equiv.refl α : Perm α)⁻¹ = 1 := Equiv.refl_symm @[simp] theorem one_trans {α : Type*} {β : Sort*} (e : α ≃ β) : (1 : Perm α).trans e = e := Equiv.refl_trans e @[simp] theorem refl_mul (e : Perm α) : Equiv.refl α * e = e := Equiv.refl_trans e @[simp] theorem inv_trans_self (e : Perm α) : e⁻¹.trans e = 1 := Equiv.symm_trans_self e @[simp] theorem mul_symm (e : Perm α) : e * e.symm = 1 := Equiv.symm_trans_self e @[simp] theorem self_trans_inv (e : Perm α) : e.trans e⁻¹ = 1 := Equiv.self_trans_symm e @[simp] theorem symm_mul (e : Perm α) : e.symm * e = 1 := Equiv.self_trans_symm e /-! Lemmas about `Equiv.Perm.sumCongr` re-expressed via the group structure. -/ @[simp] theorem sumCongr_mul {α β : Type*} (e : Perm α) (f : Perm β) (g : Perm α) (h : Perm β) : sumCongr e f * sumCongr g h = sumCongr (e * g) (f * h) := sumCongr_trans g h e f @[simp] theorem sumCongr_inv {α β : Type*} (e : Perm α) (f : Perm β) : (sumCongr e f)⁻¹ = sumCongr e⁻¹ f⁻¹ := sumCongr_symm e f @[simp] theorem sumCongr_one {α β : Type*} : sumCongr (1 : Perm α) (1 : Perm β) = 1 := sumCongr_refl /-- `Equiv.Perm.sumCongr` as a `MonoidHom`, with its two arguments bundled into a single `Prod`. This is particularly useful for its `MonoidHom.range` projection, which is the subgroup of permutations which do not exchange elements between `α` and `β`. -/ @[simps] def sumCongrHom (α β : Type*) : Perm α × Perm β →* Perm (α ⊕ β) where toFun a := sumCongr a.1 a.2 map_one' := sumCongr_one map_mul' _ _ := (sumCongr_mul _ _ _ _).symm theorem sumCongrHom_injective {α β : Type*} : Function.Injective (sumCongrHom α β) := by rintro ⟨⟩ ⟨⟩ h rw [Prod.mk.inj_iff] constructor <;> ext i · simpa using Equiv.congr_fun h (Sum.inl i) · simpa using Equiv.congr_fun h (Sum.inr i) @[simp] theorem sumCongr_swap_one {α β : Type*} [DecidableEq α] [DecidableEq β] (i j : α) : sumCongr (Equiv.swap i j) (1 : Perm β) = Equiv.swap (Sum.inl i) (Sum.inl j) := sumCongr_swap_refl i j @[simp] theorem sumCongr_one_swap {α β : Type*} [DecidableEq α] [DecidableEq β] (i j : β) : sumCongr (1 : Perm α) (Equiv.swap i j) = Equiv.swap (Sum.inr i) (Sum.inr j) := sumCongr_refl_swap i j /-! Lemmas about `Equiv.Perm.sigmaCongrRight` re-expressed via the group structure. -/ @[simp] theorem sigmaCongrRight_mul {α : Type*} {β : α → Type*} (F : ∀ a, Perm (β a)) (G : ∀ a, Perm (β a)) : sigmaCongrRight F * sigmaCongrRight G = sigmaCongrRight (F * G) := sigmaCongrRight_trans G F @[simp] theorem sigmaCongrRight_inv {α : Type*} {β : α → Type*} (F : ∀ a, Perm (β a)) : (sigmaCongrRight F)⁻¹ = sigmaCongrRight fun a => (F a)⁻¹ := sigmaCongrRight_symm F @[simp] theorem sigmaCongrRight_one {α : Type*} {β : α → Type*} : sigmaCongrRight (1 : ∀ a, Equiv.Perm <| β a) = 1 := sigmaCongrRight_refl /-- `Equiv.Perm.sigmaCongrRight` as a `MonoidHom`. This is particularly useful for its `MonoidHom.range` projection, which is the subgroup of permutations which do not exchange elements between fibers. -/ @[simps] def sigmaCongrRightHom {α : Type*} (β : α → Type*) : (∀ a, Perm (β a)) →* Perm (Σa, β a) where toFun := sigmaCongrRight map_one' := sigmaCongrRight_one map_mul' _ _ := (sigmaCongrRight_mul _ _).symm theorem sigmaCongrRightHom_injective {α : Type*} {β : α → Type*} : Function.Injective (sigmaCongrRightHom β) := by intro x y h ext a b simpa using Equiv.congr_fun h ⟨a, b⟩ /-- `Equiv.Perm.subtypeCongr` as a `MonoidHom`. -/ @[simps] def subtypeCongrHom (p : α → Prop) [DecidablePred p] : Perm { a // p a } × Perm { a // ¬p a } →* Perm α where toFun pair := Perm.subtypeCongr pair.fst pair.snd map_one' := Perm.subtypeCongr.refl map_mul' _ _ := (Perm.subtypeCongr.trans _ _ _ _).symm theorem subtypeCongrHom_injective (p : α → Prop) [DecidablePred p] : Function.Injective (subtypeCongrHom p) := by rintro ⟨⟩ ⟨⟩ h rw [Prod.mk.inj_iff] constructor <;> ext i <;> simpa using Equiv.congr_fun h i /-- If `e` is also a permutation, we can write `permCongr` completely in terms of the group structure. -/ @[simp] theorem permCongr_eq_mul (e p : Perm α) : e.permCongr p = e * p * e⁻¹ := rfl section ExtendDomain /-! Lemmas about `Equiv.Perm.extendDomain` re-expressed via the group structure. -/ variable (e : Perm α) {p : β → Prop} [DecidablePred p] (f : α ≃ Subtype p) @[simp] theorem extendDomain_one : extendDomain 1 f = 1 := extendDomain_refl f @[simp] theorem extendDomain_inv : (e.extendDomain f)⁻¹ = e⁻¹.extendDomain f := rfl @[simp] theorem extendDomain_mul (e e' : Perm α) : e.extendDomain f * e'.extendDomain f = (e * e').extendDomain f := extendDomain_trans _ _ _ /-- `extendDomain` as a group homomorphism -/ @[simps] def extendDomainHom : Perm α →* Perm β where toFun e := extendDomain e f map_one' := extendDomain_one f map_mul' e e' := (extendDomain_mul f e e').symm theorem extendDomainHom_injective : Function.Injective (extendDomainHom f) := (injective_iff_map_eq_one (extendDomainHom f)).mpr fun e he => ext fun x => f.injective <| Subtype.ext ((extendDomain_apply_image e f x).symm.trans (Perm.ext_iff.mp he (f x))) @[simp] theorem extendDomain_eq_one_iff {e : Perm α} {f : α ≃ Subtype p} : e.extendDomain f = 1 ↔ e = 1 := (injective_iff_map_eq_one' (extendDomainHom f)).mp (extendDomainHom_injective f) e @[simp] lemma extendDomain_pow (n : ℕ) : (e ^ n).extendDomain f = e.extendDomain f ^ n := map_pow (extendDomainHom f) _ _ @[simp] lemma extendDomain_zpow (n : ℤ) : (e ^ n).extendDomain f = e.extendDomain f ^ n := map_zpow (extendDomainHom f) _ _ end ExtendDomain section Subtype variable {p : α → Prop} {f : Perm α} /-- If the permutation `f` fixes the subtype `{x // p x}`, then this returns the permutation on `{x // p x}` induced by `f`. -/ def subtypePerm (f : Perm α) (h : ∀ x, p x ↔ p (f x)) : Perm { x // p x } where toFun := fun x => ⟨f x, (h _).1 x.2⟩ invFun := fun x => ⟨f⁻¹ x, (h (f⁻¹ x)).2 <| by simpa using x.2⟩ left_inv _ := by simp only [Perm.inv_apply_self, Subtype.coe_eta, Subtype.coe_mk] right_inv _ := by simp only [Perm.apply_inv_self, Subtype.coe_eta, Subtype.coe_mk] @[simp] theorem subtypePerm_apply (f : Perm α) (h : ∀ x, p x ↔ p (f x)) (x : { x // p x }) : subtypePerm f h x = ⟨f x, (h _).1 x.2⟩ := rfl @[simp] theorem subtypePerm_one (p : α → Prop) (h := fun _ => Iff.rfl) : @subtypePerm α p 1 h = 1 := rfl @[simp] theorem subtypePerm_mul (f g : Perm α) (hf hg) : (f.subtypePerm hf * g.subtypePerm hg : Perm { x // p x }) = (f * g).subtypePerm fun _ => (hg _).trans <| hf _ := rfl private theorem inv_aux : (∀ x, p x ↔ p (f x)) ↔ ∀ x, p x ↔ p (f⁻¹ x) := f⁻¹.surjective.forall.trans <| by simp_rw [f.apply_inv_self, Iff.comm] /-- See `Equiv.Perm.inv_subtypePerm`-/ theorem subtypePerm_inv (f : Perm α) (hf) : f⁻¹.subtypePerm hf = (f.subtypePerm <| inv_aux.2 hf : Perm { x // p x })⁻¹ := rfl /-- See `Equiv.Perm.subtypePerm_inv`-/ @[simp] theorem inv_subtypePerm (f : Perm α) (hf) : (f.subtypePerm hf : Perm { x // p x })⁻¹ = f⁻¹.subtypePerm (inv_aux.1 hf) := rfl private theorem pow_aux (hf : ∀ x, p x ↔ p (f x)) : ∀ {n : ℕ} (x), p x ↔ p ((f ^ n) x) | 0, _ => Iff.rfl | _ + 1, _ => (hf _).trans (pow_aux hf _) @[simp] theorem subtypePerm_pow (f : Perm α) (n : ℕ) (hf) : (f.subtypePerm hf : Perm { x // p x }) ^ n = (f ^ n).subtypePerm (pow_aux hf) := by induction' n with n ih · simp · simp_rw [pow_succ', ih, subtypePerm_mul] private theorem zpow_aux (hf : ∀ x, p x ↔ p (f x)) : ∀ {n : ℤ} (x), p x ↔ p ((f ^ n) x) | Int.ofNat n => pow_aux hf | Int.negSucc n => by rw [zpow_negSucc] exact inv_aux.1 (pow_aux hf) @[simp] theorem subtypePerm_zpow (f : Perm α) (n : ℤ) (hf) : (f.subtypePerm hf ^ n : Perm { x // p x }) = (f ^ n).subtypePerm (zpow_aux hf) := by induction' n with n ih · exact subtypePerm_pow _ _ _ · simp only [zpow_negSucc, subtypePerm_pow, subtypePerm_inv] variable [DecidablePred p] {a : α} /-- The inclusion map of permutations on a subtype of `α` into permutations of `α`, fixing the other points. -/ def ofSubtype : Perm (Subtype p) →* Perm α where toFun f := extendDomain f (Equiv.refl (Subtype p)) map_one' := Equiv.Perm.extendDomain_one _ map_mul' f g := (Equiv.Perm.extendDomain_mul _ f g).symm theorem ofSubtype_subtypePerm {f : Perm α} (h₁ : ∀ x, p x ↔ p (f x)) (h₂ : ∀ x, f x ≠ x → p x) : ofSubtype (subtypePerm f h₁) = f := Equiv.ext fun x => by by_cases hx : p x · exact (subtypePerm f h₁).extendDomain_apply_subtype _ hx · rw [ofSubtype, MonoidHom.coe_mk] -- Porting note: added `dsimp` dsimp only [OneHom.coe_mk] rw [Equiv.Perm.extendDomain_apply_not_subtype _ _ hx] exact not_not.mp fun h => hx (h₂ x (Ne.symm h)) theorem ofSubtype_apply_of_mem (f : Perm (Subtype p)) (ha : p a) : ofSubtype f a = f ⟨a, ha⟩ := extendDomain_apply_subtype _ _ ha @[simp] theorem ofSubtype_apply_coe (f : Perm (Subtype p)) (x : Subtype p) : ofSubtype f x = f x := Subtype.casesOn x fun _ => ofSubtype_apply_of_mem f theorem ofSubtype_apply_of_not_mem (f : Perm (Subtype p)) (ha : ¬p a) : ofSubtype f a = a := extendDomain_apply_not_subtype _ _ ha theorem mem_iff_ofSubtype_apply_mem (f : Perm (Subtype p)) (x : α) : p x ↔ p ((ofSubtype f : α → α) x) := if h : p x then by simpa only [h, true_iff_iff, MonoidHom.coe_mk, ofSubtype_apply_of_mem f h] using (f ⟨x, h⟩).2 else by simp [h, ofSubtype_apply_of_not_mem f h] @[simp] theorem subtypePerm_ofSubtype (f : Perm (Subtype p)) : subtypePerm (ofSubtype f) (mem_iff_ofSubtype_apply_mem f) = f := Equiv.ext fun x => Subtype.coe_injective (ofSubtype_apply_coe f x) /-- Permutations on a subtype are equivalent to permutations on the original type that fix pointwise the rest. -/ @[simps] protected def subtypeEquivSubtypePerm (p : α → Prop) [DecidablePred p] : Perm (Subtype p) ≃ { f : Perm α // ∀ a, ¬p a → f a = a } where toFun f := ⟨ofSubtype f, fun _ => f.ofSubtype_apply_of_not_mem⟩ invFun f := (f : Perm α).subtypePerm fun a => ⟨Decidable.not_imp_not.1 fun hfa => f.val.injective (f.prop _ hfa) ▸ hfa, Decidable.not_imp_not.1 fun ha hfa => ha <| f.prop a ha ▸ hfa⟩ left_inv := Equiv.Perm.subtypePerm_ofSubtype right_inv f := Subtype.ext ((Equiv.Perm.ofSubtype_subtypePerm _) fun a => Not.decidable_imp_symm <| f.prop a) theorem subtypeEquivSubtypePerm_apply_of_mem (f : Perm (Subtype p)) (h : p a) : -- Porting note: was `Perm.subtypeEquivSubtypePerm p f a` ((Perm.subtypeEquivSubtypePerm p).toFun f).1 a = f ⟨a, h⟩ := f.ofSubtype_apply_of_mem h theorem subtypeEquivSubtypePerm_apply_of_not_mem (f : Perm (Subtype p)) (h : ¬p a) : -- Porting note: was `Perm.subtypeEquivSubtypePerm p f a` ((Perm.subtypeEquivSubtypePerm p).toFun f).1 a = a := f.ofSubtype_apply_of_not_mem h end Subtype end Perm section Swap variable [DecidableEq α] @[simp] theorem swap_inv (x y : α) : (swap x y)⁻¹ = swap x y := rfl @[simp] theorem swap_mul_self (i j : α) : swap i j * swap i j = 1 := swap_swap i j theorem swap_mul_eq_mul_swap (f : Perm α) (x y : α) : swap x y * f = f * swap (f⁻¹ x) (f⁻¹ y) := Equiv.ext fun z => by simp only [Perm.mul_apply, swap_apply_def] split_ifs <;> simp_all only [Perm.apply_inv_self, Perm.eq_inv_iff_eq, eq_self_iff_true, not_true] theorem mul_swap_eq_swap_mul (f : Perm α) (x y : α) : f * swap x y = swap (f x) (f y) * f := by rw [swap_mul_eq_mul_swap, Perm.inv_apply_self, Perm.inv_apply_self] theorem swap_apply_apply (f : Perm α) (x y : α) : swap (f x) (f y) = f * swap x y * f⁻¹ := by rw [mul_swap_eq_swap_mul, mul_inv_cancel_right] @[simp] theorem swap_smul_self_smul [MulAction (Perm α) β] (i j : α) (x : β) : swap i j • swap i j • x = x := by simp [smul_smul] theorem swap_smul_involutive [MulAction (Perm α) β] (i j : α) : Function.Involutive (swap i j • · : β → β) := swap_smul_self_smul i j /-- Left-multiplying a permutation with `swap i j` twice gives the original permutation. This specialization of `swap_mul_self` is useful when using cosets of permutations. -/ @[simp] theorem swap_mul_self_mul (i j : α) (σ : Perm α) : Equiv.swap i j * (Equiv.swap i j * σ) = σ := swap_smul_self_smul i j σ /-- Right-multiplying a permutation with `swap i j` twice gives the original permutation. This specialization of `swap_mul_self` is useful when using cosets of permutations. -/ @[simp] theorem mul_swap_mul_self (i j : α) (σ : Perm α) : σ * Equiv.swap i j * Equiv.swap i j = σ := by rw [mul_assoc, swap_mul_self, mul_one] /-- A stronger version of `mul_right_injective` -/ @[simp] theorem swap_mul_involutive (i j : α) : Function.Involutive (Equiv.swap i j * ·) := swap_mul_self_mul i j /-- A stronger version of `mul_left_injective` -/ @[simp] theorem mul_swap_involutive (i j : α) : Function.Involutive (· * Equiv.swap i j) := mul_swap_mul_self i j @[simp] theorem swap_eq_one_iff {i j : α} : swap i j = (1 : Perm α) ↔ i = j := swap_eq_refl_iff theorem swap_mul_eq_iff {i j : α} {σ : Perm α} : swap i j * σ = σ ↔ i = j := by rw [mul_left_eq_self, swap_eq_one_iff] theorem mul_swap_eq_iff {i j : α} {σ : Perm α} : σ * swap i j = σ ↔ i = j := by rw [mul_right_eq_self, swap_eq_one_iff] theorem swap_mul_swap_mul_swap {x y z : α} (hxy : x ≠ y) (hxz : x ≠ z) : swap y z * swap x y * swap y z = swap z x := by nth_rewrite 3 [← swap_inv] rw [← swap_apply_apply, swap_apply_left, swap_apply_of_ne_of_ne hxy hxz, swap_comm] end Swap section AddGroup variable [AddGroup α] (a b : α) @[simp] lemma addLeft_zero : Equiv.addLeft (0 : α) = 1 := ext zero_add @[simp] lemma addRight_zero : Equiv.addRight (0 : α) = 1 := ext add_zero @[simp] lemma addLeft_add : Equiv.addLeft (a + b) = Equiv.addLeft a * Equiv.addLeft b := ext <| add_assoc _ _ @[simp] lemma addRight_add : Equiv.addRight (a + b) = Equiv.addRight b * Equiv.addRight a := ext fun _ ↦ (add_assoc _ _ _).symm @[simp] lemma inv_addLeft : (Equiv.addLeft a)⁻¹ = Equiv.addLeft (-a) := Equiv.coe_inj.1 rfl @[simp] lemma inv_addRight : (Equiv.addRight a)⁻¹ = Equiv.addRight (-a) := Equiv.coe_inj.1 rfl @[simp] lemma pow_addLeft (n : ℕ) : Equiv.addLeft a ^ n = Equiv.addLeft (n • a) := by ext; simp [Perm.coe_pow] @[simp] lemma pow_addRight (n : ℕ) : Equiv.addRight a ^ n = Equiv.addRight (n • a) := by ext; simp [Perm.coe_pow] @[simp] lemma zpow_addLeft (n : ℤ) : Equiv.addLeft a ^ n = Equiv.addLeft (n • a) := (map_zsmul ({ toFun := Equiv.addLeft, map_zero' := addLeft_zero, map_add' := addLeft_add } : α →+ Additive (Perm α)) _ _).symm @[simp] lemma zpow_addRight : ∀ (n : ℤ), Equiv.addRight a ^ n = Equiv.addRight (n • a) | Int.ofNat n => by simp | Int.negSucc n => by simp end AddGroup section Group variable [Group α] (a b : α) @[to_additive existing (attr := simp)] lemma mulLeft_one : Equiv.mulLeft (1 : α) = 1 := ext one_mul @[to_additive existing (attr := simp)] lemma mulRight_one : Equiv.mulRight (1 : α) = 1 := ext mul_one @[to_additive existing (attr := simp)] lemma mulLeft_mul : Equiv.mulLeft (a * b) = Equiv.mulLeft a * Equiv.mulLeft b := ext <| mul_assoc _ _ @[to_additive existing (attr := simp)] lemma mulRight_mul : Equiv.mulRight (a * b) = Equiv.mulRight b * Equiv.mulRight a := ext fun _ ↦ (mul_assoc _ _ _).symm @[to_additive existing (attr := simp) inv_addLeft] lemma inv_mulLeft : (Equiv.mulLeft a)⁻¹ = Equiv.mulLeft a⁻¹ := Equiv.coe_inj.1 rfl @[to_additive existing (attr := simp) inv_addRight] lemma inv_mulRight : (Equiv.mulRight a)⁻¹ = Equiv.mulRight a⁻¹ := Equiv.coe_inj.1 rfl @[to_additive existing (attr := simp) pow_addLeft] lemma pow_mulLeft (n : ℕ) : Equiv.mulLeft a ^ n = Equiv.mulLeft (a ^ n) := by ext; simp [Perm.coe_pow] @[to_additive existing (attr := simp) pow_addRight] lemma pow_mulRight (n : ℕ) : Equiv.mulRight a ^ n = Equiv.mulRight (a ^ n) := by ext; simp [Perm.coe_pow] @[to_additive existing (attr := simp) zpow_addLeft] lemma zpow_mulLeft (n : ℤ) : Equiv.mulLeft a ^ n = Equiv.mulLeft (a ^ n) := (map_zpow ({ toFun := Equiv.mulLeft, map_one' := mulLeft_one, map_mul' := mulLeft_mul } : α →* Perm α) _ _).symm @[to_additive existing (attr := simp) zpow_addRight] lemma zpow_mulRight : ∀ n : ℤ, Equiv.mulRight a ^ n = Equiv.mulRight (a ^ n) | Int.ofNat n => by simp | Int.negSucc n => by simp end Group end Equiv open Equiv Function namespace Set variable {α : Type*} {f : Perm α} {s : Set α} lemma BijOn.perm_inv (hf : BijOn f s s) : BijOn ↑(f⁻¹) s s := hf.symm f.invOn lemma MapsTo.perm_pow : MapsTo f s s → ∀ n : ℕ, MapsTo (f ^ n) s s := by simp_rw [Equiv.Perm.coe_pow]; exact MapsTo.iterate lemma SurjOn.perm_pow : SurjOn f s s → ∀ n : ℕ, SurjOn (f ^ n) s s := by simp_rw [Equiv.Perm.coe_pow]; exact SurjOn.iterate lemma BijOn.perm_pow : BijOn f s s → ∀ n : ℕ, BijOn (f ^ n) s s := by simp_rw [Equiv.Perm.coe_pow]; exact BijOn.iterate lemma BijOn.perm_zpow (hf : BijOn f s s) : ∀ n : ℤ, BijOn (f ^ n) s s | Int.ofNat n => hf.perm_pow n | Int.negSucc n => (hf.perm_pow (n + 1)).perm_inv end Set
GroupTheory\Perm\Closure.lean
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Yaël Dillies -/ import Mathlib.GroupTheory.Perm.Cycle.Basic /-! # Closure results for permutation groups * This file contains several closure results: * `closure_isCycle` : The symmetric group is generated by cycles * `closure_cycle_adjacent_swap` : The symmetric group is generated by a cycle and an adjacent transposition * `closure_cycle_coprime_swap` : The symmetric group is generated by a cycle and a coprime transposition * `closure_prime_cycle_swap` : The symmetric group is generated by a prime cycle and a transposition -/ open Equiv Function Finset variable {ι α β : Type*} namespace Equiv.Perm section Generation variable [Finite β] open Subgroup theorem closure_isCycle : closure { σ : Perm β | IsCycle σ } = ⊤ := by classical cases nonempty_fintype β exact top_le_iff.mp (le_trans (ge_of_eq closure_isSwap) (closure_mono fun _ => IsSwap.isCycle)) variable [DecidableEq α] [Fintype α] theorem closure_cycle_adjacent_swap {σ : Perm α} (h1 : IsCycle σ) (h2 : σ.support = ⊤) (x : α) : closure ({σ, swap x (σ x)} : Set (Perm α)) = ⊤ := by let H := closure ({σ, swap x (σ x)} : Set (Perm α)) have h3 : σ ∈ H := subset_closure (Set.mem_insert σ _) have h4 : swap x (σ x) ∈ H := subset_closure (Set.mem_insert_of_mem _ (Set.mem_singleton _)) have step1 : ∀ n : ℕ, swap ((σ ^ n) x) ((σ ^ (n + 1) : Perm α) x) ∈ H := by intro n induction' n with n ih · exact subset_closure (Set.mem_insert_of_mem _ (Set.mem_singleton _)) · convert H.mul_mem (H.mul_mem h3 ih) (H.inv_mem h3) simp_rw [mul_swap_eq_swap_mul, mul_inv_cancel_right, pow_succ'] rfl have step2 : ∀ n : ℕ, swap x ((σ ^ n) x) ∈ H := by intro n induction' n with n ih · simp only [Nat.zero_eq, pow_zero, coe_one, id_eq, swap_self, Set.mem_singleton_iff] convert H.one_mem · by_cases h5 : x = (σ ^ n) x · rw [pow_succ', mul_apply, ← h5] exact h4 by_cases h6 : x = (σ ^ (n + 1) : Perm α) x · rw [← h6, swap_self] exact H.one_mem rw [swap_comm, ← swap_mul_swap_mul_swap h5 h6] exact H.mul_mem (H.mul_mem (step1 n) ih) (step1 n) have step3 : ∀ y : α, swap x y ∈ H := by intro y have hx : x ∈ (⊤ : Finset α) := Finset.mem_univ x rw [← h2, mem_support] at hx have hy : y ∈ (⊤ : Finset α) := Finset.mem_univ y rw [← h2, mem_support] at hy cases' IsCycle.exists_pow_eq h1 hx hy with n hn rw [← hn] exact step2 n have step4 : ∀ y z : α, swap y z ∈ H := by intro y z by_cases h5 : z = x · rw [h5, swap_comm] exact step3 y by_cases h6 : z = y · rw [h6, swap_self] exact H.one_mem rw [← swap_mul_swap_mul_swap h5 h6, swap_comm z x] exact H.mul_mem (H.mul_mem (step3 y) (step3 z)) (step3 y) rw [eq_top_iff, ← closure_isSwap, closure_le] rintro τ ⟨y, z, _, h6⟩ rw [h6] exact step4 y z theorem closure_cycle_coprime_swap {n : ℕ} {σ : Perm α} (h0 : Nat.Coprime n (Fintype.card α)) (h1 : IsCycle σ) (h2 : σ.support = Finset.univ) (x : α) : closure ({σ, swap x ((σ ^ n) x)} : Set (Perm α)) = ⊤ := by rw [← Finset.card_univ, ← h2, ← h1.orderOf] at h0 cases' exists_pow_eq_self_of_coprime h0 with m hm have h2' : (σ ^ n).support = ⊤ := Eq.trans (support_pow_coprime h0) h2 have h1' : IsCycle ((σ ^ n) ^ (m : ℤ)) := by rwa [← hm] at h1 replace h1' : IsCycle (σ ^ n) := h1'.of_pow (le_trans (support_pow_le σ n) (ge_of_eq (congr_arg support hm))) rw [eq_top_iff, ← closure_cycle_adjacent_swap h1' h2' x, closure_le, Set.insert_subset_iff] exact ⟨Subgroup.pow_mem (closure _) (subset_closure (Set.mem_insert σ _)) n, Set.singleton_subset_iff.mpr (subset_closure (Set.mem_insert_of_mem _ (Set.mem_singleton _)))⟩ theorem closure_prime_cycle_swap {σ τ : Perm α} (h0 : (Fintype.card α).Prime) (h1 : IsCycle σ) (h2 : σ.support = Finset.univ) (h3 : IsSwap τ) : closure ({σ, τ} : Set (Perm α)) = ⊤ := by obtain ⟨x, y, h4, h5⟩ := h3 obtain ⟨i, hi⟩ := h1.exists_pow_eq (mem_support.mp ((Finset.ext_iff.mp h2 x).mpr (Finset.mem_univ x))) (mem_support.mp ((Finset.ext_iff.mp h2 y).mpr (Finset.mem_univ y))) rw [h5, ← hi] refine closure_cycle_coprime_swap (Nat.Coprime.symm (h0.coprime_iff_not_dvd.mpr fun h => h4 ?_)) h1 h2 x cases' h with m hm rwa [hm, pow_mul, ← Finset.card_univ, ← h2, ← h1.orderOf, pow_orderOf_eq_one, one_pow, one_apply] at hi end Generation end Perm end Equiv
GroupTheory\Perm\ClosureSwap.lean
/- Copyright (c) 2024 Thomas Browning, Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning, Junyan Xu -/ import Mathlib.Data.Set.Finite import Mathlib.GroupTheory.GroupAction.FixedPoints import Mathlib.GroupTheory.Perm.Support /-! # Subgroups generated by transpositions This file studies subgroups generated by transpositions. ## Main results - `swap_mem_closure_isSwap` : If a subgroup is generated by transpositions, then a transposition `swap x y` lies in the subgroup if and only if `x` lies in the same orbit as `y`. - `mem_closure_isSwap` : If a subgroup is generated by transpositions, then a permutation `f` lies in the subgroup if and only if `f` has finite support and `f x` always lies in the same orbit as `x`. -/ open Equiv List MulAction Pointwise Set Subgroup variable {G α : Type*} [Group G] [MulAction G α] /-- If the support of each element in a generating set of a permutation group is finite, then the support of every element in the group is finite. -/ theorem finite_compl_fixedBy_closure_iff {S : Set G} : (∀ g ∈ closure S, (fixedBy α g)ᶜ.Finite) ↔ ∀ g ∈ S, (fixedBy α g)ᶜ.Finite := ⟨fun h g hg ↦ h g (subset_closure hg), fun h g hg ↦ by refine closure_induction hg h (by simp) (fun g g' hg hg' ↦ (hg.union hg').subset ?_) (by simp) simp_rw [← compl_inter, compl_subset_compl, fixedBy_mul]⟩ /-- Given a symmetric generating set of a permutation group, if T is a nonempty proper subset of an orbit, then there exists a generator that sends some element of T into the complement of T. -/ theorem exists_smul_not_mem_of_subset_orbit_closure (S : Set G) (T : Set α) {a : α} (hS : ∀ g ∈ S, g⁻¹ ∈ S) (subset : T ⊆ orbit (closure S) a) (not_mem : a ∉ T) (nonempty : T.Nonempty) : ∃ σ ∈ S, ∃ a ∈ T, σ • a ∉ T := by have key0 : ¬ closure S ≤ stabilizer G T := by have ⟨b, hb⟩ := nonempty obtain ⟨σ, rfl⟩ := subset hb contrapose! not_mem with h exact smul_mem_smul_set_iff.mp ((h σ.2).symm ▸ hb) contrapose! key0 refine (closure_le _).mpr fun σ hσ ↦ ?_ simp_rw [SetLike.mem_coe, mem_stabilizer_iff, Set.ext_iff, mem_smul_set_iff_inv_smul_mem] exact fun a ↦ ⟨fun h ↦ smul_inv_smul σ a ▸ key0 σ hσ (σ⁻¹ • a) h, key0 σ⁻¹ (hS σ hσ) a⟩ variable [DecidableEq α] theorem finite_compl_fixedBy_swap {x y : α} : (fixedBy α (swap x y))ᶜ.Finite := Set.Finite.subset (s := {x, y}) (by simp) (compl_subset_comm.mp fun z h ↦ by apply swap_apply_of_ne_of_ne <;> rintro rfl <;> simp at h) theorem Equiv.Perm.IsSwap.finite_compl_fixedBy {σ : Perm α} (h : σ.IsSwap) : (fixedBy α σ)ᶜ.Finite := by obtain ⟨x, y, -, rfl⟩ := h exact finite_compl_fixedBy_swap -- this result cannot be moved to Perm/Basic since Perm/Basic is not allowed to import Submonoid theorem SubmonoidClass.swap_mem_trans {a b c : α} {C} [SetLike C (Perm α)] [SubmonoidClass C (Perm α)] (M : C) (hab : swap a b ∈ M) (hbc : swap b c ∈ M) : swap a c ∈ M := by obtain rfl | hab' := eq_or_ne a b · exact hbc obtain rfl | hac := eq_or_ne a c · exact swap_self a ▸ one_mem M rw [swap_comm, ← swap_mul_swap_mul_swap hab' hac] exact mul_mem (mul_mem hbc hab) hbc /-- If a subgroup is generated by transpositions, then a transposition `swap x y` lies in the subgroup if and only if `x` lies in the same orbit as `y`. -/ theorem swap_mem_closure_isSwap {S : Set (Perm α)} (hS : ∀ f ∈ S, f.IsSwap) {x y : α} : swap x y ∈ closure S ↔ x ∈ orbit (closure S) y := by refine ⟨fun h ↦ ⟨⟨swap x y, h⟩, swap_apply_right x y⟩, fun hf ↦ ?_⟩ by_contra h have := exists_smul_not_mem_of_subset_orbit_closure S {x | swap x y ∈ closure S} (fun f hf ↦ ?_) (fun z hz ↦ ?_) h ⟨y, ?_⟩ · obtain ⟨σ, hσ, a, ha, hσa⟩ := this obtain ⟨z, w, hzw, rfl⟩ := hS σ hσ have := ne_of_mem_of_not_mem ha hσa rw [Perm.smul_def, ne_comm, swap_apply_ne_self_iff, and_iff_right hzw] at this refine hσa (SubmonoidClass.swap_mem_trans (closure S) ?_ ha) obtain rfl | rfl := this <;> simpa [swap_comm] using subset_closure hσ · obtain ⟨x, y, -, rfl⟩ := hS f hf; rwa [swap_inv] · exact orbit_eq_iff.mpr hf ▸ ⟨⟨swap z y, hz⟩, swap_apply_right z y⟩ · rw [mem_setOf, swap_self]; apply one_mem /-- If a subgroup is generated by transpositions, then a permutation `f` lies in the subgroup if and only if `f` has finite support and `f x` always lies in the same orbit as `x`. -/ theorem mem_closure_isSwap {S : Set (Perm α)} (hS : ∀ f ∈ S, f.IsSwap) {f : Perm α} : f ∈ closure S ↔ (fixedBy α f)ᶜ.Finite ∧ ∀ x, f x ∈ orbit (closure S) x := by refine ⟨fun hf ↦ ⟨?_, fun x ↦ mem_orbit_iff.mpr ⟨⟨f, hf⟩, rfl⟩⟩, ?_⟩ · exact finite_compl_fixedBy_closure_iff.mpr (fun f hf ↦ (hS f hf).finite_compl_fixedBy) _ hf rintro ⟨fin, hf⟩ set supp := (fixedBy α f)ᶜ with supp_eq suffices h : (fixedBy α f)ᶜ ⊆ supp → f ∈ closure S from h supp_eq.symm.subset clear_value supp; clear supp_eq; revert f apply fin.induction_on .. · rintro f - emp; convert (closure S).one_mem; ext; by_contra h; exact emp h rintro a s - - ih f hf supp_subset refine (mul_mem_cancel_left ((swap_mem_closure_isSwap hS).2 (hf a))).1 (ih (fun b ↦ ?_) fun b hb ↦ ?_) · rw [Perm.mul_apply, swap_apply_def]; split_ifs with h1 h2 · rw [← orbit_eq_iff.mpr (hf b), h1, orbit_eq_iff.mpr (hf a)]; apply mem_orbit_self · rw [← orbit_eq_iff.mpr (hf b), h2]; apply hf · exact hf b · contrapose! hb simp_rw [not_mem_compl_iff, mem_fixedBy, Perm.smul_def, Perm.mul_apply, swap_apply_def, apply_eq_iff_eq] by_cases hb' : f b = b · rw [hb']; split_ifs with h <;> simp only [h] simp [show b = a by simpa [hb] using supp_subset hb'] /-- A permutation is a product of transpositions if and only if it has finite support. -/ theorem mem_closure_isSwap' {f : Perm α} : f ∈ closure {σ : Perm α | σ.IsSwap} ↔ (fixedBy α f)ᶜ.Finite := by refine (mem_closure_isSwap fun _ ↦ id).trans (and_iff_left fun x ↦ ⟨⟨swap x (f x), ?_⟩, swap_apply_left x (f x)⟩) by_cases h : x = f x · rw [← h, swap_self] apply Subgroup.one_mem · exact subset_closure ⟨x, f x, h, rfl⟩ /-- A transitive permutation group generated by transpositions must be the whole symmetric group -/ theorem closure_of_isSwap_of_isPretransitive [Finite α] {S : Set (Perm α)} (hS : ∀ σ ∈ S, σ.IsSwap) [MulAction.IsPretransitive (Subgroup.closure S) α] : Subgroup.closure S = ⊤ := by simp [eq_top_iff', mem_closure_isSwap hS, orbit_eq_univ, Set.toFinite] /-- A transitive permutation group generated by transpositions must be the whole symmetric group -/ theorem surjective_of_isSwap_of_isPretransitive [Finite α] (S : Set G) (hS1 : ∀ σ ∈ S, Perm.IsSwap (MulAction.toPermHom G α σ)) (hS2 : Subgroup.closure S = ⊤) [h : MulAction.IsPretransitive G α] : Function.Surjective (MulAction.toPermHom G α) := by rw [← MonoidHom.range_top_iff_surjective] have := MulAction.IsPretransitive.of_compHom (α := α) (MulAction.toPermHom G α).rangeRestrict rw [MonoidHom.range_eq_map, ← hS2, MonoidHom.map_closure] at this ⊢ exact closure_of_isSwap_of_isPretransitive (Set.forall_mem_image.2 hS1)
GroupTheory\Perm\DomMulAct.lean
/- Copyright (c) 2023 Junyan Xu, Antoine Chambert-Loir. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu, Antoine Chambert-Loir -/ import Mathlib.Algebra.Group.Subgroup.Basic import Mathlib.GroupTheory.GroupAction.DomAct.Basic import Mathlib.GroupTheory.GroupAction.Basic import Mathlib.Data.Fintype.Basic import Mathlib.Data.Fintype.Perm import Mathlib.SetTheory.Cardinal.Finite /-! Subgroup of `Equiv.Perm α` preserving a function Let `α` and `ι` by types and let `f : α → ι` * `DomMulAct.mem_stabilizer_iff` proves that the stabilizer of `f : α → ι` in `(Equiv.Perm α)ᵈᵐᵃ` is the set of `g : (Equiv.Perm α)ᵈᵐᵃ` such that `f ∘ (mk.symm g) = f`. The natural equivalence from `stabilizer (Perm α)ᵈᵐᵃ f` to `{ g : Perm α // p ∘ g = f }` can be obtained as `subtypeEquiv mk.symm (fun _ => mem_stabilizer_iff)` * `DomMulAct.stabilizerMulEquiv` is the `MulEquiv` from the MulOpposite of this stabilizer to the product, for `i : ι`, of `Equiv.Perm {a // f a = i}`. * Under `Fintype α` and `Fintype ι`, `DomMulAct.stabilizer_card p` computes the cardinality of the type of permutations preserving `p` : `Fintype.card {g : Perm α // f ∘ g = f} = ∏ i, (Fintype.card {a // f a = i})!`. -/ variable {α ι : Type*} {f : α → ι} open Equiv MulAction namespace DomMulAct lemma mem_stabilizer_iff {g : (Perm α)ᵈᵐᵃ} : g ∈ stabilizer (Perm α)ᵈᵐᵃ f ↔ f ∘ (mk.symm g :) = f := by simp only [MulAction.mem_stabilizer_iff]; rfl /-- The `invFun` component of `MulEquiv` from `MulAction.stabilizer (Perm α) f` to the product of the `Equiv.Perm {a // f a = i} -/ def stabilizerEquiv_invFun (g : ∀ i, Perm {a // f a = i}) (a : α) : α := g (f a) ⟨a, rfl⟩ lemma stabilizerEquiv_invFun_eq (g : ∀ i, Perm {a // f a = i}) {a : α} {i : ι} (h : f a = i) : stabilizerEquiv_invFun g a = g i ⟨a, h⟩ := by subst h; rfl lemma comp_stabilizerEquiv_invFun (g : ∀ i, Perm {a // f a = i}) (a : α) : f (stabilizerEquiv_invFun g a) = f a := (g (f a) ⟨a, rfl⟩).prop /-- The `invFun` component of `MulEquiv` from `MulAction.stabilizer (Perm α) p` to the product of the `Equiv.Perm {a | f a = i} (as an `Equiv.Perm α`) -/ def stabilizerEquiv_invFun_aux (g : ∀ i, Perm {a // f a = i}) : Perm α where toFun := stabilizerEquiv_invFun g invFun := stabilizerEquiv_invFun (fun i ↦ (g i).symm) left_inv a := by rw [stabilizerEquiv_invFun_eq _ (comp_stabilizerEquiv_invFun g a)] exact congr_arg Subtype.val ((g <| f a).left_inv _) right_inv a := by rw [stabilizerEquiv_invFun_eq _ (comp_stabilizerEquiv_invFun _ a)] exact congr_arg Subtype.val ((g <| f a).right_inv _) variable (f) /-- The `MulEquiv` from the `MulOpposite` of `MulAction.stabilizer (Perm α)ᵈᵐᵃ f` to the product of the `Equiv.Perm {a // f a = i}` -/ def stabilizerMulEquiv : (stabilizer (Perm α)ᵈᵐᵃ f)ᵐᵒᵖ ≃* (∀ i, Perm {a // f a = i}) where toFun g i := Perm.subtypePerm (mk.symm g.unop) fun a ↦ by rw [← Function.comp_apply (f := f), mem_stabilizer_iff.mp g.unop.prop] invFun g := ⟨mk (stabilizerEquiv_invFun_aux g), by ext a rw [smul_apply, symm_apply_apply, Perm.smul_def] apply comp_stabilizerEquiv_invFun⟩ left_inv g := rfl right_inv g := by ext i a; apply stabilizerEquiv_invFun_eq map_mul' g h := rfl variable {f} lemma stabilizerMulEquiv_apply (g : (stabilizer (Perm α)ᵈᵐᵃ f)ᵐᵒᵖ) {a : α} {i : ι} (h : f a = i) : ((stabilizerMulEquiv f)) g i ⟨a, h⟩ = (mk.symm g.unop : Equiv.Perm α) a := rfl section Fintype variable [Fintype α] [Fintype ι] [DecidableEq α] [DecidableEq ι] open Nat variable (f) /-- The cardinality of the type of permutations preserving a function -/ theorem stabilizer_card : Fintype.card {g : Perm α // f ∘ g = f} = ∏ i, (Fintype.card {a // f a = i})! := by -- rewriting via Nat.card because Fintype instance is not found rw [← Nat.card_eq_fintype_card, Nat.card_congr (subtypeEquiv mk fun _ ↦ ?_), Nat.card_congr MulOpposite.opEquiv, Nat.card_congr (DomMulAct.stabilizerMulEquiv f).toEquiv, Nat.card_pi] · exact Finset.prod_congr rfl fun i _ ↦ by rw [Nat.card_eq_fintype_card, Fintype.card_perm] · rfl end Fintype end DomMulAct
GroupTheory\Perm\Fin.lean
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.GroupTheory.Perm.Cycle.Type import Mathlib.GroupTheory.Perm.Option import Mathlib.Logic.Equiv.Fin import Mathlib.Logic.Equiv.Fintype /-! # Permutations of `Fin n` -/ open Equiv /-- Permutations of `Fin (n + 1)` are equivalent to fixing a single `Fin (n + 1)` and permuting the remaining with a `Perm (Fin n)`. The fixed `Fin (n + 1)` is swapped with `0`. -/ def Equiv.Perm.decomposeFin {n : ℕ} : Perm (Fin n.succ) ≃ Fin n.succ × Perm (Fin n) := ((Equiv.permCongr <| finSuccEquiv n).trans Equiv.Perm.decomposeOption).trans (Equiv.prodCongr (finSuccEquiv n).symm (Equiv.refl _)) @[simp] theorem Equiv.Perm.decomposeFin_symm_of_refl {n : ℕ} (p : Fin (n + 1)) : Equiv.Perm.decomposeFin.symm (p, Equiv.refl _) = swap 0 p := by simp [Equiv.Perm.decomposeFin, Equiv.permCongr_def] @[simp] theorem Equiv.Perm.decomposeFin_symm_of_one {n : ℕ} (p : Fin (n + 1)) : Equiv.Perm.decomposeFin.symm (p, 1) = swap 0 p := Equiv.Perm.decomposeFin_symm_of_refl p @[simp] theorem Equiv.Perm.decomposeFin_symm_apply_zero {n : ℕ} (p : Fin (n + 1)) (e : Perm (Fin n)) : Equiv.Perm.decomposeFin.symm (p, e) 0 = p := by simp [Equiv.Perm.decomposeFin] @[simp] theorem Equiv.Perm.decomposeFin_symm_apply_succ {n : ℕ} (e : Perm (Fin n)) (p : Fin (n + 1)) (x : Fin n) : Equiv.Perm.decomposeFin.symm (p, e) x.succ = swap 0 p (e x).succ := by refine Fin.cases ?_ ?_ p · simp [Equiv.Perm.decomposeFin, EquivFunctor.map] · intro i by_cases h : i = e x · simp [h, Equiv.Perm.decomposeFin, EquivFunctor.map] · simp [h, Fin.succ_ne_zero, Equiv.Perm.decomposeFin, EquivFunctor.map, swap_apply_def, Ne.symm h] @[simp] theorem Equiv.Perm.decomposeFin_symm_apply_one {n : ℕ} (e : Perm (Fin (n + 1))) (p : Fin (n + 2)) : Equiv.Perm.decomposeFin.symm (p, e) 1 = swap 0 p (e 0).succ := by rw [← Fin.succ_zero_eq_one, Equiv.Perm.decomposeFin_symm_apply_succ e p 0] @[simp] theorem Equiv.Perm.decomposeFin.symm_sign {n : ℕ} (p : Fin (n + 1)) (e : Perm (Fin n)) : Perm.sign (Equiv.Perm.decomposeFin.symm (p, e)) = ite (p = 0) 1 (-1) * Perm.sign e := by refine Fin.cases ?_ ?_ p <;> simp [Equiv.Perm.decomposeFin, Fin.succ_ne_zero] /-- The set of all permutations of `Fin (n + 1)` can be constructed by augmenting the set of permutations of `Fin n` by each element of `Fin (n + 1)` in turn. -/ theorem Finset.univ_perm_fin_succ {n : ℕ} : @Finset.univ (Perm <| Fin n.succ) _ = (Finset.univ : Finset <| Fin n.succ × Perm (Fin n)).map Equiv.Perm.decomposeFin.symm.toEmbedding := (Finset.univ_map_equiv_to_embedding _).symm section CycleRange /-! ### `cycleRange` section Define the permutations `Fin.cycleRange i`, the cycle `(0 1 2 ... i)`. -/ open Equiv.Perm -- Porting note: renamed from finRotate_succ because there is already a theorem with that name theorem finRotate_succ_eq_decomposeFin {n : ℕ} : finRotate n.succ = decomposeFin.symm (1, finRotate n) := by ext i cases n; · simp refine Fin.cases ?_ (fun i => ?_) i · simp rw [coe_finRotate, decomposeFin_symm_apply_succ, if_congr i.succ_eq_last_succ rfl rfl] split_ifs with h · simp [h] · rw [Fin.val_succ, Function.Injective.map_swap Fin.val_injective, Fin.val_succ, coe_finRotate, if_neg h, Fin.val_zero, Fin.val_one, swap_apply_of_ne_of_ne (Nat.succ_ne_zero _) (Nat.succ_succ_ne_one _)] @[simp] theorem sign_finRotate (n : ℕ) : Perm.sign (finRotate (n + 1)) = (-1) ^ n := by induction' n with n ih · simp · rw [finRotate_succ_eq_decomposeFin] simp [ih, pow_succ] @[simp] theorem support_finRotate {n : ℕ} : support (finRotate (n + 2)) = Finset.univ := by ext simp theorem support_finRotate_of_le {n : ℕ} (h : 2 ≤ n) : support (finRotate n) = Finset.univ := by obtain ⟨m, rfl⟩ := exists_add_of_le h rw [add_comm, support_finRotate] theorem isCycle_finRotate {n : ℕ} : IsCycle (finRotate (n + 2)) := by refine ⟨0, by simp, fun x hx' => ⟨x, ?_⟩⟩ clear hx' cases' x with x hx rw [zpow_natCast, Fin.ext_iff, Fin.val_mk] induction' x with x ih; · rfl rw [pow_succ', Perm.mul_apply, coe_finRotate_of_ne_last, ih (lt_trans x.lt_succ_self hx)] rw [Ne, Fin.ext_iff, ih (lt_trans x.lt_succ_self hx), Fin.val_last] exact ne_of_lt (Nat.lt_of_succ_lt_succ hx) theorem isCycle_finRotate_of_le {n : ℕ} (h : 2 ≤ n) : IsCycle (finRotate n) := by obtain ⟨m, rfl⟩ := exists_add_of_le h rw [add_comm] exact isCycle_finRotate @[simp] theorem cycleType_finRotate {n : ℕ} : cycleType (finRotate (n + 2)) = {n + 2} := by rw [isCycle_finRotate.cycleType, support_finRotate, ← Fintype.card, Fintype.card_fin] rfl theorem cycleType_finRotate_of_le {n : ℕ} (h : 2 ≤ n) : cycleType (finRotate n) = {n} := by obtain ⟨m, rfl⟩ := exists_add_of_le h rw [add_comm, cycleType_finRotate] namespace Fin /-- `Fin.cycleRange i` is the cycle `(0 1 2 ... i)` leaving `(i+1 ... (n-1))` unchanged. -/ def cycleRange {n : ℕ} (i : Fin n) : Perm (Fin n) := (finRotate (i + 1)).extendDomain (Equiv.ofLeftInverse' (Fin.castLEEmb (Nat.succ_le_of_lt i.is_lt)) (↑) (by intro x ext simp)) theorem cycleRange_of_gt {n : ℕ} {i j : Fin n.succ} (h : i < j) : cycleRange i j = j := by rw [cycleRange, ofLeftInverse'_eq_ofInjective, ← Function.Embedding.toEquivRange_eq_ofInjective, ← viaFintypeEmbedding, viaFintypeEmbedding_apply_not_mem_range] simpa theorem cycleRange_of_le {n : ℕ} {i j : Fin n.succ} (h : j ≤ i) : cycleRange i j = if j = i then 0 else j + 1 := by cases n · exact Subsingleton.elim (α := Fin 1) _ _ --Porting note; was `simp` have : j = (Fin.castLE (Nat.succ_le_of_lt i.is_lt)) ⟨j, lt_of_le_of_lt h (Nat.lt_succ_self i)⟩ := by simp ext erw [this, cycleRange, ofLeftInverse'_eq_ofInjective, ← Function.Embedding.toEquivRange_eq_ofInjective, ← viaFintypeEmbedding, viaFintypeEmbedding_apply_image, Function.Embedding.coeFn_mk, coe_castLE, coe_finRotate] simp only [Fin.ext_iff, val_last, val_mk, val_zero, Fin.eta, castLE_mk] split_ifs with heq · rfl · rw [Fin.val_add_one_of_lt] exact lt_of_lt_of_le (lt_of_le_of_ne h (mt (congr_arg _) heq)) (le_last i) theorem coe_cycleRange_of_le {n : ℕ} {i j : Fin n.succ} (h : j ≤ i) : (cycleRange i j : ℕ) = if j = i then 0 else (j : ℕ) + 1 := by rw [cycleRange_of_le h] split_ifs with h' · rfl exact val_add_one_of_lt (calc (j : ℕ) < i := Fin.lt_iff_val_lt_val.mp (lt_of_le_of_ne h h') _ ≤ n := Nat.lt_succ_iff.mp i.2) theorem cycleRange_of_lt {n : ℕ} {i j : Fin n.succ} (h : j < i) : cycleRange i j = j + 1 := by rw [cycleRange_of_le h.le, if_neg h.ne] theorem coe_cycleRange_of_lt {n : ℕ} {i j : Fin n.succ} (h : j < i) : (cycleRange i j : ℕ) = j + 1 := by rw [coe_cycleRange_of_le h.le, if_neg h.ne] theorem cycleRange_of_eq {n : ℕ} {i j : Fin n.succ} (h : j = i) : cycleRange i j = 0 := by rw [cycleRange_of_le h.le, if_pos h] @[simp] theorem cycleRange_self {n : ℕ} (i : Fin n.succ) : cycleRange i i = 0 := cycleRange_of_eq rfl theorem cycleRange_apply {n : ℕ} (i j : Fin n.succ) : cycleRange i j = if j < i then j + 1 else if j = i then 0 else j := by split_ifs with h₁ h₂ · exact cycleRange_of_lt h₁ · exact cycleRange_of_eq h₂ · exact cycleRange_of_gt (lt_of_le_of_ne (le_of_not_gt h₁) (Ne.symm h₂)) @[simp] theorem cycleRange_zero (n : ℕ) : cycleRange (0 : Fin n.succ) = 1 := by ext j refine Fin.cases ?_ (fun j => ?_) j · simp · rw [cycleRange_of_gt (Fin.succ_pos j), one_apply] @[simp] theorem cycleRange_last (n : ℕ) : cycleRange (last n) = finRotate (n + 1) := by ext i rw [coe_cycleRange_of_le (le_last _), coe_finRotate] @[simp] theorem cycleRange_zero' {n : ℕ} (h : 0 < n) : cycleRange ⟨0, h⟩ = 1 := by cases' n with n · cases h exact cycleRange_zero n @[simp] theorem sign_cycleRange {n : ℕ} (i : Fin n) : Perm.sign (cycleRange i) = (-1) ^ (i : ℕ) := by simp [cycleRange] @[simp] theorem succAbove_cycleRange {n : ℕ} (i j : Fin n) : i.succ.succAbove (i.cycleRange j) = swap 0 i.succ j.succ := by cases n · rcases j with ⟨_, ⟨⟩⟩ rcases lt_trichotomy j i with (hlt | heq | hgt) · have : castSucc (j + 1) = j.succ := by ext rw [coe_castSucc, val_succ, Fin.val_add_one_of_lt (lt_of_lt_of_le hlt i.le_last)] rw [Fin.cycleRange_of_lt hlt, Fin.succAbove_of_castSucc_lt, this, swap_apply_of_ne_of_ne] · apply Fin.succ_ne_zero · exact (Fin.succ_injective _).ne hlt.ne · rw [Fin.lt_iff_val_lt_val] simpa [this] using hlt · rw [heq, Fin.cycleRange_self, Fin.succAbove_of_castSucc_lt, swap_apply_right, Fin.castSucc_zero] · rw [Fin.castSucc_zero] apply Fin.succ_pos · rw [Fin.cycleRange_of_gt hgt, Fin.succAbove_of_le_castSucc, swap_apply_of_ne_of_ne] · apply Fin.succ_ne_zero · apply (Fin.succ_injective _).ne hgt.ne.symm · simpa [Fin.le_iff_val_le_val] using hgt @[simp] theorem cycleRange_succAbove {n : ℕ} (i : Fin (n + 1)) (j : Fin n) : i.cycleRange (i.succAbove j) = j.succ := by cases' lt_or_ge (castSucc j) i with h h · rw [Fin.succAbove_of_castSucc_lt _ _ h, Fin.cycleRange_of_lt h, Fin.coeSucc_eq_succ] · rw [Fin.succAbove_of_le_castSucc _ _ h, Fin.cycleRange_of_gt (Fin.le_castSucc_iff.mp h)] @[simp] theorem cycleRange_symm_zero {n : ℕ} (i : Fin (n + 1)) : i.cycleRange.symm 0 = i := i.cycleRange.injective (by simp) @[simp] theorem cycleRange_symm_succ {n : ℕ} (i : Fin (n + 1)) (j : Fin n) : i.cycleRange.symm j.succ = i.succAbove j := i.cycleRange.injective (by simp) theorem isCycle_cycleRange {n : ℕ} {i : Fin (n + 1)} (h0 : i ≠ 0) : IsCycle (cycleRange i) := by cases' i with i hi cases i · exact (h0 rfl).elim exact isCycle_finRotate.extendDomain _ @[simp] theorem cycleType_cycleRange {n : ℕ} {i : Fin (n + 1)} (h0 : i ≠ 0) : cycleType (cycleRange i) = {(i + 1 : ℕ)} := by cases' i with i hi cases i · exact (h0 rfl).elim rw [cycleRange, cycleType_extendDomain] exact cycleType_finRotate theorem isThreeCycle_cycleRange_two {n : ℕ} : IsThreeCycle (cycleRange 2 : Perm (Fin (n + 3))) := by rw [IsThreeCycle, cycleType_cycleRange] <;> simp [Fin.ext_iff] end Fin end CycleRange assert_not_exists LinearMap
GroupTheory\Perm\Finite.lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Data.Finset.Fin import Mathlib.Data.Int.Order.Units import Mathlib.GroupTheory.OrderOfElement import Mathlib.GroupTheory.Perm.Support import Mathlib.Logic.Equiv.Fintype /-! # Permutations on `Fintype`s This file contains miscellaneous lemmas about `Equiv.Perm` and `Equiv.swap`, building on top of those in `Data/Equiv/Basic` and other files in `GroupTheory/Perm/*`. -/ universe u v open Equiv Function Fintype Finset variable {α : Type u} {β : Type v} -- An example on how to determine the order of an element of a finite group. example : orderOf (-1 : ℤˣ) = 2 := orderOf_eq_prime (Int.units_sq _) (by decide) namespace Equiv.Perm section Conjugation variable [DecidableEq α] [Fintype α] {σ τ : Perm α} theorem isConj_of_support_equiv (f : { x // x ∈ (σ.support : Set α) } ≃ { x // x ∈ (τ.support : Set α) }) (hf : ∀ (x : α) (hx : x ∈ (σ.support : Set α)), (f ⟨σ x, apply_mem_support.2 hx⟩ : α) = τ ↑(f ⟨x, hx⟩)) : IsConj σ τ := by refine isConj_iff.2 ⟨Equiv.extendSubtype f, ?_⟩ rw [mul_inv_eq_iff_eq_mul] ext x simp only [Perm.mul_apply] by_cases hx : x ∈ σ.support · rw [Equiv.extendSubtype_apply_of_mem, Equiv.extendSubtype_apply_of_mem] · exact hf x (Finset.mem_coe.2 hx) · rwa [Classical.not_not.1 ((not_congr mem_support).1 (Equiv.extendSubtype_not_mem f _ _)), Classical.not_not.1 ((not_congr mem_support).mp hx)] end Conjugation theorem perm_inv_on_of_perm_on_finset {s : Finset α} {f : Perm α} (h : ∀ x ∈ s, f x ∈ s) {y : α} (hy : y ∈ s) : f⁻¹ y ∈ s := by have h0 : ∀ y ∈ s, ∃ (x : _) (hx : x ∈ s), y = (fun i (_ : i ∈ s) => f i) x hx := Finset.surj_on_of_inj_on_of_card_le (fun x hx => (fun i _ => f i) x hx) (fun a ha => h a ha) (fun a₁ a₂ ha₁ ha₂ heq => (Equiv.apply_eq_iff_eq f).mp heq) rfl.ge obtain ⟨y2, hy2, heq⟩ := h0 y hy convert hy2 rw [heq] simp only [inv_apply_self] theorem perm_inv_mapsTo_of_mapsTo (f : Perm α) {s : Set α} [Finite s] (h : Set.MapsTo f s s) : Set.MapsTo (f⁻¹ : _) s s := by cases nonempty_fintype s exact fun x hx => Set.mem_toFinset.mp <| perm_inv_on_of_perm_on_finset (fun a ha => Set.mem_toFinset.mpr (h (Set.mem_toFinset.mp ha))) (Set.mem_toFinset.mpr hx) @[simp] theorem perm_inv_mapsTo_iff_mapsTo {f : Perm α} {s : Set α} [Finite s] : Set.MapsTo (f⁻¹ : _) s s ↔ Set.MapsTo f s s := ⟨perm_inv_mapsTo_of_mapsTo f⁻¹, perm_inv_mapsTo_of_mapsTo f⟩ theorem perm_inv_on_of_perm_on_finite {f : Perm α} {p : α → Prop} [Finite { x // p x }] (h : ∀ x, p x → p (f x)) {x : α} (hx : p x) : p (f⁻¹ x) := -- Porting note: relies heavily on the definitions of `Subtype` and `setOf` unfolding to their -- underlying predicate. have : Finite { x | p x } := ‹_› perm_inv_mapsTo_of_mapsTo (s := {x | p x}) f h hx /-- If the permutation `f` maps `{x // p x}` into itself, then this returns the permutation on `{x // p x}` induced by `f`. Note that the `h` hypothesis is weaker than for `Equiv.Perm.subtypePerm`. -/ abbrev subtypePermOfFintype (f : Perm α) {p : α → Prop} [Finite { x // p x }] (h : ∀ x, p x → p (f x)) : Perm { x // p x } := f.subtypePerm fun x => ⟨h x, fun h₂ => f.inv_apply_self x ▸ perm_inv_on_of_perm_on_finite h h₂⟩ @[simp] theorem subtypePermOfFintype_apply (f : Perm α) {p : α → Prop} [Finite { x // p x }] (h : ∀ x, p x → p (f x)) (x : { x // p x }) : subtypePermOfFintype f h x = ⟨f x, h x x.2⟩ := rfl theorem subtypePermOfFintype_one (p : α → Prop) [Finite { x // p x }] (h : ∀ x, p x → p ((1 : Perm α) x)) : @subtypePermOfFintype α 1 p _ h = 1 := rfl theorem perm_mapsTo_inl_iff_mapsTo_inr {m n : Type*} [Finite m] [Finite n] (σ : Perm (m ⊕ n)) : Set.MapsTo σ (Set.range Sum.inl) (Set.range Sum.inl) ↔ Set.MapsTo σ (Set.range Sum.inr) (Set.range Sum.inr) := by constructor <;> ( intro h classical rw [← perm_inv_mapsTo_iff_mapsTo] at h intro x cases' hx : σ x with l r) · rintro ⟨a, rfl⟩ obtain ⟨y, hy⟩ := h ⟨l, rfl⟩ rw [← hx, σ.inv_apply_self] at hy exact absurd hy Sum.inl_ne_inr · rintro _; exact ⟨r, rfl⟩ · rintro _; exact ⟨l, rfl⟩ · rintro ⟨a, rfl⟩ obtain ⟨y, hy⟩ := h ⟨r, rfl⟩ rw [← hx, σ.inv_apply_self] at hy exact absurd hy Sum.inr_ne_inl theorem mem_sumCongrHom_range_of_perm_mapsTo_inl {m n : Type*} [Finite m] [Finite n] {σ : Perm (m ⊕ n)} (h : Set.MapsTo σ (Set.range Sum.inl) (Set.range Sum.inl)) : σ ∈ (sumCongrHom m n).range := by classical have h1 : ∀ x : m ⊕ n, (∃ a : m, Sum.inl a = x) → ∃ a : m, Sum.inl a = σ x := by rintro x ⟨a, ha⟩ apply h rw [← ha] exact ⟨a, rfl⟩ have h3 : ∀ x : m ⊕ n, (∃ b : n, Sum.inr b = x) → ∃ b : n, Sum.inr b = σ x := by rintro x ⟨b, hb⟩ apply (perm_mapsTo_inl_iff_mapsTo_inr σ).mp h rw [← hb] exact ⟨b, rfl⟩ let σ₁' := subtypePermOfFintype σ h1 let σ₂' := subtypePermOfFintype σ h3 let σ₁ := permCongr (Equiv.ofInjective _ Sum.inl_injective).symm σ₁' let σ₂ := permCongr (Equiv.ofInjective _ Sum.inr_injective).symm σ₂' rw [MonoidHom.mem_range, Prod.exists] use σ₁, σ₂ rw [Perm.sumCongrHom_apply] ext x cases' x with a b · rw [Equiv.sumCongr_apply, Sum.map_inl, permCongr_apply, Equiv.symm_symm, apply_ofInjective_symm Sum.inl_injective] rw [ofInjective_apply, Subtype.coe_mk, Subtype.coe_mk] -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [subtypePerm_apply] · rw [Equiv.sumCongr_apply, Sum.map_inr, permCongr_apply, Equiv.symm_symm, apply_ofInjective_symm Sum.inr_injective] erw [subtypePerm_apply] rw [ofInjective_apply, Subtype.coe_mk, Subtype.coe_mk] nonrec theorem Disjoint.orderOf {σ τ : Perm α} (hστ : Disjoint σ τ) : orderOf (σ * τ) = Nat.lcm (orderOf σ) (orderOf τ) := haveI h : ∀ n : ℕ, (σ * τ) ^ n = 1 ↔ σ ^ n = 1 ∧ τ ^ n = 1 := fun n => by rw [hστ.commute.mul_pow, Disjoint.mul_eq_one_iff (hστ.pow_disjoint_pow n n)] Nat.dvd_antisymm hστ.commute.orderOf_mul_dvd_lcm (Nat.lcm_dvd (orderOf_dvd_of_pow_eq_one ((h (orderOf (σ * τ))).mp (pow_orderOf_eq_one (σ * τ))).1) (orderOf_dvd_of_pow_eq_one ((h (orderOf (σ * τ))).mp (pow_orderOf_eq_one (σ * τ))).2)) theorem Disjoint.extendDomain {p : β → Prop} [DecidablePred p] (f : α ≃ Subtype p) {σ τ : Perm α} (h : Disjoint σ τ) : Disjoint (σ.extendDomain f) (τ.extendDomain f) := by intro b by_cases pb : p b · refine (h (f.symm ⟨b, pb⟩)).imp ?_ ?_ <;> · intro h rw [extendDomain_apply_subtype _ _ pb, h, apply_symm_apply, Subtype.coe_mk] · left rw [extendDomain_apply_not_subtype _ _ pb] theorem Disjoint.isConj_mul [Finite α] {σ τ π ρ : Perm α} (hc1 : IsConj σ π) (hc2 : IsConj τ ρ) (hd1 : Disjoint σ τ) (hd2 : Disjoint π ρ) : IsConj (σ * τ) (π * ρ) := by classical cases nonempty_fintype α obtain ⟨f, rfl⟩ := isConj_iff.1 hc1 obtain ⟨g, rfl⟩ := isConj_iff.1 hc2 have hd1' := coe_inj.2 hd1.support_mul have hd2' := coe_inj.2 hd2.support_mul rw [coe_union] at * have hd1'' := disjoint_coe.2 (disjoint_iff_disjoint_support.1 hd1) have hd2'' := disjoint_coe.2 (disjoint_iff_disjoint_support.1 hd2) refine isConj_of_support_equiv ?_ ?_ · refine ((Equiv.Set.ofEq hd1').trans (Equiv.Set.union hd1''.le_bot)).trans ((Equiv.sumCongr (subtypeEquiv f fun a => ?_) (subtypeEquiv g fun a => ?_)).trans ((Equiv.Set.ofEq hd2').trans (Equiv.Set.union hd2''.le_bot)).symm) <;> · simp only [Set.mem_image, toEmbedding_apply, exists_eq_right, support_conj, coe_map, apply_eq_iff_eq] · intro x hx simp only [trans_apply, symm_trans_apply, Equiv.Set.ofEq_apply, Equiv.Set.ofEq_symm_apply, Equiv.sumCongr_apply] rw [hd1', Set.mem_union] at hx cases' hx with hxσ hxτ · rw [mem_coe, mem_support] at hxσ rw [Set.union_apply_left hd1''.le_bot _, Set.union_apply_left hd1''.le_bot _] · simp only [subtypeEquiv_apply, Perm.coe_mul, Sum.map_inl, comp_apply, Set.union_symm_apply_left, Subtype.coe_mk, apply_eq_iff_eq] have h := (hd2 (f x)).resolve_left ?_ · rw [mul_apply, mul_apply] at h rw [h, inv_apply_self, (hd1 x).resolve_left hxσ] · rwa [mul_apply, mul_apply, inv_apply_self, apply_eq_iff_eq] · rwa [Subtype.coe_mk, mem_coe, mem_support] · rwa [Subtype.coe_mk, Perm.mul_apply, (hd1 x).resolve_left hxσ, mem_coe, apply_mem_support, mem_support] · rw [mem_coe, ← apply_mem_support, mem_support] at hxτ rw [Set.union_apply_right hd1''.le_bot _, Set.union_apply_right hd1''.le_bot _] · simp only [subtypeEquiv_apply, Perm.coe_mul, Sum.map_inr, comp_apply, Set.union_symm_apply_right, Subtype.coe_mk, apply_eq_iff_eq] have h := (hd2 (g (τ x))).resolve_right ?_ · rw [mul_apply, mul_apply] at h rw [inv_apply_self, h, (hd1 (τ x)).resolve_right hxτ] · rwa [mul_apply, mul_apply, inv_apply_self, apply_eq_iff_eq] · rwa [Subtype.coe_mk, mem_coe, ← apply_mem_support, mem_support] · rwa [Subtype.coe_mk, Perm.mul_apply, (hd1 (τ x)).resolve_right hxτ, mem_coe, mem_support] variable [DecidableEq α] section Fintype variable [Fintype α] theorem support_pow_coprime {σ : Perm α} {n : ℕ} (h : Nat.Coprime n (orderOf σ)) : (σ ^ n).support = σ.support := by obtain ⟨m, hm⟩ := exists_pow_eq_self_of_coprime h exact le_antisymm (support_pow_le σ n) (le_trans (ge_of_eq (congr_arg support hm)) (support_pow_le (σ ^ n) m)) end Fintype end Equiv.Perm
GroupTheory\Perm\List.lean
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Algebra.Order.Group.Nat import Mathlib.Data.List.Rotate import Mathlib.GroupTheory.Perm.Support /-! # Permutations from a list A list `l : List α` can be interpreted as an `Equiv.Perm α` where each element in the list is permuted to the next one, defined as `formPerm`. When we have that `Nodup l`, we prove that `Equiv.Perm.support (formPerm l) = l.toFinset`, and that `formPerm l` is rotationally invariant, in `formPerm_rotate`. When there are duplicate elements in `l`, how and in what arrangement with respect to the other elements they appear in the list determines the formed permutation. This is because `List.formPerm` is implemented as a product of `Equiv.swap`s. That means that presence of a sublist of two adjacent duplicates like `[..., x, x, ...]` will produce the same permutation as if the adjacent duplicates were not present. The `List.formPerm` definition is meant to primarily be used with `Nodup l`, so that the resulting permutation is cyclic (if `l` has at least two elements). The presence of duplicates in a particular placement can lead `List.formPerm` to produce a nontrivial permutation that is noncyclic. -/ namespace List variable {α β : Type*} section FormPerm variable [DecidableEq α] (l : List α) open Equiv Equiv.Perm /-- A list `l : List α` can be interpreted as an `Equiv.Perm α` where each element in the list is permuted to the next one, defined as `formPerm`. When we have that `Nodup l`, we prove that `Equiv.Perm.support (formPerm l) = l.toFinset`, and that `formPerm l` is rotationally invariant, in `formPerm_rotate`. -/ def formPerm : Equiv.Perm α := (zipWith Equiv.swap l l.tail).prod @[simp] theorem formPerm_nil : formPerm ([] : List α) = 1 := rfl @[simp] theorem formPerm_singleton (x : α) : formPerm [x] = 1 := rfl @[simp] theorem formPerm_cons_cons (x y : α) (l : List α) : formPerm (x :: y :: l) = swap x y * formPerm (y :: l) := prod_cons theorem formPerm_pair (x y : α) : formPerm [x, y] = swap x y := rfl theorem mem_or_mem_of_zipWith_swap_prod_ne : ∀ {l l' : List α} {x : α}, (zipWith swap l l').prod x ≠ x → x ∈ l ∨ x ∈ l' | [], _, _ => by simp | _, [], _ => by simp | a::l, b::l', x => fun hx ↦ if h : (zipWith swap l l').prod x = x then (eq_or_eq_of_swap_apply_ne_self (a := a) (b := b) (x := x) (by simpa [h] using hx)).imp (by rintro rfl; exact .head _) (by rintro rfl; exact .head _) else (mem_or_mem_of_zipWith_swap_prod_ne h).imp (.tail _) (.tail _) theorem zipWith_swap_prod_support' (l l' : List α) : { x | (zipWith swap l l').prod x ≠ x } ≤ l.toFinset ⊔ l'.toFinset := fun _ h ↦ by simpa using mem_or_mem_of_zipWith_swap_prod_ne h theorem zipWith_swap_prod_support [Fintype α] (l l' : List α) : (zipWith swap l l').prod.support ≤ l.toFinset ⊔ l'.toFinset := by intro x hx have hx' : x ∈ { x | (zipWith swap l l').prod x ≠ x } := by simpa using hx simpa using zipWith_swap_prod_support' _ _ hx' theorem support_formPerm_le' : { x | formPerm l x ≠ x } ≤ l.toFinset := by refine (zipWith_swap_prod_support' l l.tail).trans ?_ simpa [Finset.subset_iff] using tail_subset l theorem support_formPerm_le [Fintype α] : support (formPerm l) ≤ l.toFinset := by intro x hx have hx' : x ∈ { x | formPerm l x ≠ x } := by simpa using hx simpa using support_formPerm_le' _ hx' variable {l} {x : α} theorem mem_of_formPerm_apply_ne (h : l.formPerm x ≠ x) : x ∈ l := by simpa [or_iff_left_of_imp mem_of_mem_tail] using mem_or_mem_of_zipWith_swap_prod_ne h theorem formPerm_apply_of_not_mem (h : x ∉ l) : formPerm l x = x := not_imp_comm.1 mem_of_formPerm_apply_ne h theorem formPerm_apply_mem_of_mem (h : x ∈ l) : formPerm l x ∈ l := by cases' l with y l · simp at h induction' l with z l IH generalizing x y · simpa using h · by_cases hx : x ∈ z :: l · rw [formPerm_cons_cons, mul_apply, swap_apply_def] split_ifs · simp [IH _ hx] · simp · simp [*] · replace h : x = y := Or.resolve_right (mem_cons.1 h) hx simp [formPerm_apply_of_not_mem hx, ← h] theorem mem_of_formPerm_apply_mem (h : l.formPerm x ∈ l) : x ∈ l := by contrapose h rwa [formPerm_apply_of_not_mem h] @[simp] theorem formPerm_mem_iff_mem : l.formPerm x ∈ l ↔ x ∈ l := ⟨l.mem_of_formPerm_apply_mem, l.formPerm_apply_mem_of_mem⟩ @[simp] theorem formPerm_cons_concat_apply_last (x y : α) (xs : List α) : formPerm (x :: (xs ++ [y])) y = x := by induction' xs with z xs IH generalizing x y · simp · simp [IH] @[simp] theorem formPerm_apply_getLast (x : α) (xs : List α) : formPerm (x :: xs) ((x :: xs).getLast (cons_ne_nil x xs)) = x := by induction' xs using List.reverseRecOn with xs y _ generalizing x <;> simp @[simp] theorem formPerm_apply_getElem_length (x : α) (xs : List α) : formPerm (x :: xs) (x :: xs)[xs.length] = x := by rw [getElem_cons_length _ _ _ rfl, formPerm_apply_getLast] @[deprecated formPerm_apply_getElem_length (since := "2024-08-03")] theorem formPerm_apply_get_length (x : α) (xs : List α) : formPerm (x :: xs) ((x :: xs).get (Fin.mk xs.length (by simp))) = x := formPerm_apply_getElem_length .. set_option linter.deprecated false in @[deprecated formPerm_apply_getElem_length (since := "2024-05-30")] theorem formPerm_apply_nthLe_length (x : α) (xs : List α) : formPerm (x :: xs) ((x :: xs).nthLe xs.length (by simp)) = x := formPerm_apply_getElem_length .. theorem formPerm_apply_head (x y : α) (xs : List α) (h : Nodup (x :: y :: xs)) : formPerm (x :: y :: xs) x = y := by simp [formPerm_apply_of_not_mem h.not_mem] theorem formPerm_apply_getElem_zero (l : List α) (h : Nodup l) (hl : 1 < l.length) : formPerm l l[0] = l[1] := by rcases l with (_ | ⟨x, _ | ⟨y, tl⟩⟩) · simp at hl · simp at hl · rw [getElem_cons_zero, formPerm_apply_head _ _ _ h, getElem_cons_succ, getElem_cons_zero] @[deprecated formPerm_apply_getElem_zero (since := "2024-08-03")] theorem formPerm_apply_get_zero (l : List α) (h : Nodup l) (hl : 1 < l.length) : formPerm l (l.get (Fin.mk 0 (by omega))) = l.get (Fin.mk 1 hl) := formPerm_apply_getElem_zero l h hl set_option linter.deprecated false in @[deprecated formPerm_apply_getElem_zero (since := "2024-05-30")] theorem formPerm_apply_nthLe_zero (l : List α) (h : Nodup l) (hl : 1 < l.length) : formPerm l (l.nthLe 0 (by omega)) = l.nthLe 1 hl := by apply formPerm_apply_get_zero _ h variable (l) theorem formPerm_eq_head_iff_eq_getLast (x y : α) : formPerm (y :: l) x = y ↔ x = getLast (y :: l) (cons_ne_nil _ _) := Iff.trans (by rw [formPerm_apply_getLast]) (formPerm (y :: l)).injective.eq_iff theorem formPerm_apply_lt_getElem (xs : List α) (h : Nodup xs) (n : ℕ) (hn : n + 1 < xs.length) : formPerm xs xs[n] = xs[n + 1] := by induction' n with n IH generalizing xs · simpa using formPerm_apply_getElem_zero _ h _ · rcases xs with (_ | ⟨x, _ | ⟨y, l⟩⟩) · simp at hn · rw [formPerm_singleton, getElem_singleton, getElem_singleton, one_apply] · specialize IH (y :: l) h.of_cons _ · simpa [Nat.succ_lt_succ_iff] using hn simp only [swap_apply_eq_iff, coe_mul, formPerm_cons_cons, Function.comp] simp only [getElem_cons_succ] at * rw [← IH, swap_apply_of_ne_of_ne] <;> · intro hx rw [← hx, IH] at h simp [getElem_mem] at h @[deprecated formPerm_apply_lt_getElem (since := "2024-08-03")] theorem formPerm_apply_lt_get (xs : List α) (h : Nodup xs) (n : ℕ) (hn : n + 1 < xs.length) : formPerm xs (xs.get (Fin.mk n ((Nat.lt_succ_self n).trans hn))) = xs.get (Fin.mk (n + 1) hn) := by simp_all [formPerm_apply_lt_getElem] set_option linter.deprecated false in @[deprecated formPerm_apply_lt_get (since := "2024-05-30")] theorem formPerm_apply_lt (xs : List α) (h : Nodup xs) (n : ℕ) (hn : n + 1 < xs.length) : formPerm xs (xs.nthLe n ((Nat.lt_succ_self n).trans hn)) = xs.nthLe (n + 1) hn := by apply formPerm_apply_lt_get _ h theorem formPerm_apply_getElem (xs : List α) (w : Nodup xs) (i : ℕ) (h : i < xs.length) : formPerm xs xs[i] = xs[(i + 1) % xs.length]'(Nat.mod_lt _ (i.zero_le.trans_lt h)) := by cases' xs with x xs · simp at h · have : i ≤ xs.length := by refine Nat.le_of_lt_succ ?_ simpa using h rcases this.eq_or_lt with (rfl | hn') · simp · rw [formPerm_apply_lt_getElem (x :: xs) w _ (Nat.succ_lt_succ hn')] congr rw [Nat.mod_eq_of_lt]; simpa [Nat.succ_eq_add_one] @[deprecated formPerm_apply_getElem (since := "2024-08-03")] theorem formPerm_apply_get (xs : List α) (h : Nodup xs) (i : Fin xs.length) : formPerm xs (xs.get i) = xs.get ⟨((i.val + 1) % xs.length), (Nat.mod_lt _ (i.val.zero_le.trans_lt i.isLt))⟩ := by simp [formPerm_apply_getElem, h] set_option linter.deprecated false in @[deprecated formPerm_apply_get (since := "2024-04-23")] theorem formPerm_apply_nthLe (xs : List α) (h : Nodup xs) (n : ℕ) (hn : n < xs.length) : formPerm xs (xs.nthLe n hn) = xs.nthLe ((n + 1) % xs.length) (Nat.mod_lt _ (n.zero_le.trans_lt hn)) := by apply formPerm_apply_get _ h theorem support_formPerm_of_nodup' (l : List α) (h : Nodup l) (h' : ∀ x : α, l ≠ [x]) : { x | formPerm l x ≠ x } = l.toFinset := by apply _root_.le_antisymm · exact support_formPerm_le' l · intro x hx simp only [Finset.mem_coe, mem_toFinset] at hx obtain ⟨n, hn, rfl⟩ := getElem_of_mem hx rw [Set.mem_setOf_eq, formPerm_apply_getElem _ h] intro H rw [nodup_iff_injective_get, Function.Injective] at h specialize h H rcases (Nat.succ_le_of_lt hn).eq_or_lt with hn' | hn' · simp only [← hn', Nat.mod_self] at h refine not_exists.mpr h' ?_ rw [← length_eq_one, ← hn', (Fin.mk.inj_iff.mp h).symm] · simp [Nat.mod_eq_of_lt hn'] at h theorem support_formPerm_of_nodup [Fintype α] (l : List α) (h : Nodup l) (h' : ∀ x : α, l ≠ [x]) : support (formPerm l) = l.toFinset := by rw [← Finset.coe_inj] convert support_formPerm_of_nodup' _ h h' simp [Set.ext_iff] theorem formPerm_rotate_one (l : List α) (h : Nodup l) : formPerm (l.rotate 1) = formPerm l := by have h' : Nodup (l.rotate 1) := by simpa using h ext x by_cases hx : x ∈ l.rotate 1 · obtain ⟨k, hk, rfl⟩ := getElem_of_mem hx rw [formPerm_apply_getElem _ h', getElem_rotate l, getElem_rotate l, formPerm_apply_getElem _ h] simp · rw [formPerm_apply_of_not_mem hx, formPerm_apply_of_not_mem] simpa using hx theorem formPerm_rotate (l : List α) (h : Nodup l) (n : ℕ) : formPerm (l.rotate n) = formPerm l := by induction' n with n hn · simp · rw [← rotate_rotate, formPerm_rotate_one, hn] rwa [IsRotated.nodup_iff] exact IsRotated.forall l n theorem formPerm_eq_of_isRotated {l l' : List α} (hd : Nodup l) (h : l ~r l') : formPerm l = formPerm l' := by obtain ⟨n, rfl⟩ := h exact (formPerm_rotate l hd n).symm theorem formPerm_append_pair : ∀ (l : List α) (a b : α), formPerm (l ++ [a, b]) = formPerm (l ++ [a]) * swap a b | [], _, _ => rfl | [x], _, _ => rfl | x::y::l, a, b => by simpa [mul_assoc] using formPerm_append_pair (y::l) a b theorem formPerm_reverse : ∀ l : List α, formPerm l.reverse = (formPerm l)⁻¹ | [] => rfl | [_] => rfl | a::b::l => by simp [formPerm_append_pair, swap_comm, ← formPerm_reverse (b::l)] theorem formPerm_pow_apply_getElem (l : List α) (w : Nodup l) (n : ℕ) (i : ℕ) (h : i < l.length) : (formPerm l ^ n) l[i] = l[(i + n) % l.length]'(Nat.mod_lt _ (i.zero_le.trans_lt h)) := by induction' n with n hn · simp [Nat.mod_eq_of_lt h] · simp [pow_succ', mul_apply, hn, formPerm_apply_getElem _ w, Nat.succ_eq_add_one, ← Nat.add_assoc] @[deprecated formPerm_pow_apply_getElem (since := "2024-08-03")] theorem formPerm_pow_apply_get (l : List α) (h : Nodup l) (n : ℕ) (i : Fin l.length) : (formPerm l ^ n) (l.get i) = l.get ⟨((i.val + n) % l.length), (Nat.mod_lt _ (i.val.zero_le.trans_lt i.isLt))⟩ := by simp [formPerm_pow_apply_getElem, h] set_option linter.deprecated false in @[deprecated formPerm_pow_apply_get (since := "2024-04-23")] theorem formPerm_pow_apply_nthLe (l : List α) (h : Nodup l) (n k : ℕ) (hk : k < l.length) : (formPerm l ^ n) (l.nthLe k hk) = l.nthLe ((k + n) % l.length) (Nat.mod_lt _ (k.zero_le.trans_lt hk)) := formPerm_pow_apply_get l h n ⟨k, hk⟩ theorem formPerm_pow_apply_head (x : α) (l : List α) (h : Nodup (x :: l)) (n : ℕ) : (formPerm (x :: l) ^ n) x = (x :: l)[(n % (x :: l).length)]'(Nat.mod_lt _ (Nat.zero_lt_succ _)) := by convert formPerm_pow_apply_getElem _ h n 0 (Nat.succ_pos _) simp theorem formPerm_ext_iff {x y x' y' : α} {l l' : List α} (hd : Nodup (x :: y :: l)) (hd' : Nodup (x' :: y' :: l')) : formPerm (x :: y :: l) = formPerm (x' :: y' :: l') ↔ (x :: y :: l) ~r (x' :: y' :: l') := by refine ⟨fun h => ?_, fun hr => formPerm_eq_of_isRotated hd hr⟩ rw [Equiv.Perm.ext_iff] at h have hx : x' ∈ x :: y :: l := by have : x' ∈ { z | formPerm (x :: y :: l) z ≠ z } := by rw [Set.mem_setOf_eq, h x', formPerm_apply_head _ _ _ hd'] simp only [mem_cons, nodup_cons] at hd' push_neg at hd' exact hd'.left.left.symm simpa using support_formPerm_le' _ this obtain ⟨⟨n, hn⟩, hx'⟩ := get_of_mem hx have hl : (x :: y :: l).length = (x' :: y' :: l').length := by rw [← dedup_eq_self.mpr hd, ← dedup_eq_self.mpr hd', ← card_toFinset, ← card_toFinset] refine congr_arg Finset.card ?_ rw [← Finset.coe_inj, ← support_formPerm_of_nodup' _ hd (by simp), ← support_formPerm_of_nodup' _ hd' (by simp)] simp only [h] use n apply List.ext_getElem · rw [length_rotate, hl] · intro k hk hk' rw [getElem_rotate] induction' k with k IH · refine Eq.trans ?_ hx' congr simpa using hn · conv => congr <;> · arg 2; (rw [← Nat.mod_eq_of_lt hk']) rw [← formPerm_apply_getElem _ hd' k (k.lt_succ_self.trans hk'), ← IH (k.lt_succ_self.trans hk), ← h, formPerm_apply_getElem _ hd] congr 1 rw [hl, Nat.mod_eq_of_lt hk', add_right_comm] apply Nat.add_mod theorem formPerm_apply_mem_eq_self_iff (hl : Nodup l) (x : α) (hx : x ∈ l) : formPerm l x = x ↔ length l ≤ 1 := by obtain ⟨k, hk, rfl⟩ := getElem_of_mem hx rw [formPerm_apply_getElem _ hl k hk, hl.getElem_inj_iff] cases hn : l.length · exact absurd k.zero_le (hk.trans_le hn.le).not_le · rw [hn] at hk rcases (Nat.le_of_lt_succ hk).eq_or_lt with hk' | hk' · simp [← hk', Nat.succ_le_succ_iff, eq_comm] · simpa [Nat.mod_eq_of_lt (Nat.succ_lt_succ hk'), Nat.succ_lt_succ_iff] using (k.zero_le.trans_lt hk').ne.symm theorem formPerm_apply_mem_ne_self_iff (hl : Nodup l) (x : α) (hx : x ∈ l) : formPerm l x ≠ x ↔ 2 ≤ l.length := by rw [Ne, formPerm_apply_mem_eq_self_iff _ hl x hx, not_le] exact ⟨Nat.succ_le_of_lt, Nat.lt_of_succ_le⟩ theorem mem_of_formPerm_ne_self (l : List α) (x : α) (h : formPerm l x ≠ x) : x ∈ l := by suffices x ∈ { y | formPerm l y ≠ y } by rw [← mem_toFinset] exact support_formPerm_le' _ this simpa using h theorem formPerm_eq_self_of_not_mem (l : List α) (x : α) (h : x ∉ l) : formPerm l x = x := by_contra fun H => h <| mem_of_formPerm_ne_self _ _ H theorem formPerm_eq_one_iff (hl : Nodup l) : formPerm l = 1 ↔ l.length ≤ 1 := by cases' l with hd tl · simp · rw [← formPerm_apply_mem_eq_self_iff _ hl hd (mem_cons_self _ _)] constructor · simp (config := { contextual := true }) · intro h simp only [(hd :: tl).formPerm_apply_mem_eq_self_iff hl hd (mem_cons_self hd tl), add_le_iff_nonpos_left, length, nonpos_iff_eq_zero, length_eq_zero] at h simp [h] theorem formPerm_eq_formPerm_iff {l l' : List α} (hl : l.Nodup) (hl' : l'.Nodup) : l.formPerm = l'.formPerm ↔ l ~r l' ∨ l.length ≤ 1 ∧ l'.length ≤ 1 := by rcases l with (_ | ⟨x, _ | ⟨y, l⟩⟩) · suffices l'.length ≤ 1 ↔ l' = nil ∨ l'.length ≤ 1 by simpa [eq_comm, formPerm_eq_one_iff, hl, hl', length_eq_zero] refine ⟨fun h => Or.inr h, ?_⟩ rintro (rfl | h) · simp · exact h · suffices l'.length ≤ 1 ↔ [x] ~r l' ∨ l'.length ≤ 1 by simpa [eq_comm, formPerm_eq_one_iff, hl, hl', length_eq_zero, le_rfl] refine ⟨fun h => Or.inr h, ?_⟩ rintro (h | h) · simp [← h.perm.length_eq] · exact h · rcases l' with (_ | ⟨x', _ | ⟨y', l'⟩⟩) · simp [formPerm_eq_one_iff _ hl, -formPerm_cons_cons] · simp [formPerm_eq_one_iff _ hl, -formPerm_cons_cons] · simp [-formPerm_cons_cons, formPerm_ext_iff hl hl', Nat.succ_le_succ_iff] theorem form_perm_zpow_apply_mem_imp_mem (l : List α) (x : α) (hx : x ∈ l) (n : ℤ) : (formPerm l ^ n) x ∈ l := by by_cases h : (l.formPerm ^ n) x = x · simpa [h] using hx · have h : x ∈ { x | (l.formPerm ^ n) x ≠ x } := h rw [← set_support_apply_mem] at h replace h := set_support_zpow_subset _ _ h simpa using support_formPerm_le' _ h theorem formPerm_pow_length_eq_one_of_nodup (hl : Nodup l) : formPerm l ^ length l = 1 := by ext x by_cases hx : x ∈ l · obtain ⟨k, hk, rfl⟩ := getElem_of_mem hx simp [formPerm_pow_apply_getElem _ hl, Nat.mod_eq_of_lt hk] · have : x ∉ { x | (l.formPerm ^ l.length) x ≠ x } := by intro H refine hx ?_ replace H := set_support_zpow_subset l.formPerm l.length H simpa using support_formPerm_le' _ H simpa using this end FormPerm end List
GroupTheory\Perm\Option.lean
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Data.Fintype.Option import Mathlib.Data.Fintype.Perm import Mathlib.Data.Fintype.Prod import Mathlib.GroupTheory.Perm.Sign import Mathlib.Logic.Equiv.Option /-! # Permutations of `Option α` -/ open Equiv @[simp] theorem Equiv.optionCongr_one {α : Type*} : (1 : Perm α).optionCongr = 1 := Equiv.optionCongr_refl @[simp] theorem Equiv.optionCongr_swap {α : Type*} [DecidableEq α] (x y : α) : optionCongr (swap x y) = swap (some x) (some y) := by ext (_ | i) · simp [swap_apply_of_ne_of_ne] · by_cases hx : i = x · simp only [hx, optionCongr_apply, Option.map_some', swap_apply_left, Option.mem_def, Option.some.injEq] by_cases hy : i = y <;> simp [hx, hy, swap_apply_of_ne_of_ne] @[simp] theorem Equiv.optionCongr_sign {α : Type*} [DecidableEq α] [Fintype α] (e : Perm α) : Perm.sign e.optionCongr = Perm.sign e := by refine Perm.swap_induction_on e ?_ ?_ · simp [Perm.one_def] · intro f x y hne h simp [h, hne, Perm.mul_def, ← Equiv.optionCongr_trans] @[simp] theorem map_equiv_removeNone {α : Type*} [DecidableEq α] (σ : Perm (Option α)) : (removeNone σ).optionCongr = swap none (σ none) * σ := by ext1 x have : Option.map (⇑(removeNone σ)) x = (swap none (σ none)) (σ x) := by cases' x with x · simp · cases h : σ (some _) · simp [removeNone_none _ h] · have hn : σ (some x) ≠ none := by simp [h] have hσn : σ (some x) ≠ σ none := σ.injective.ne (by simp) simp [removeNone_some _ ⟨_, h⟩, ← h, swap_apply_of_ne_of_ne hn hσn] simpa using this /-- Permutations of `Option α` are equivalent to fixing an `Option α` and permuting the remaining with a `Perm α`. The fixed `Option α` is swapped with `none`. -/ @[simps] def Equiv.Perm.decomposeOption {α : Type*} [DecidableEq α] : Perm (Option α) ≃ Option α × Perm α where toFun σ := (σ none, removeNone σ) invFun i := swap none i.1 * i.2.optionCongr left_inv σ := by simp right_inv := fun ⟨x, σ⟩ => by have : removeNone (swap none x * σ.optionCongr) = σ := Equiv.optionCongr_injective (by simp [← mul_assoc]) simp [← Perm.eq_inv_iff_eq, this] theorem Equiv.Perm.decomposeOption_symm_of_none_apply {α : Type*} [DecidableEq α] (e : Perm α) (i : Option α) : Equiv.Perm.decomposeOption.symm (none, e) i = i.map e := by simp theorem Equiv.Perm.decomposeOption_symm_sign {α : Type*} [DecidableEq α] [Fintype α] (e : Perm α) : Perm.sign (Equiv.Perm.decomposeOption.symm (none, e)) = Perm.sign e := by simp /-- The set of all permutations of `Option α` can be constructed by augmenting the set of permutations of `α` by each element of `Option α` in turn. -/ theorem Finset.univ_perm_option {α : Type*} [DecidableEq α] [Fintype α] : @Finset.univ (Perm <| Option α) _ = (Finset.univ : Finset <| Option α × Perm α).map Equiv.Perm.decomposeOption.symm.toEmbedding := (Finset.univ_map_equiv_to_embedding _).symm
GroupTheory\Perm\Sign.lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Algebra.Group.Subgroup.Basic import Mathlib.Algebra.Group.Submonoid.Membership import Mathlib.Data.Finset.Fin import Mathlib.Data.Finset.Sort import Mathlib.Data.Int.Order.Units import Mathlib.GroupTheory.Perm.Support import Mathlib.Logic.Equiv.Fin import Mathlib.Tactic.NormNum.Ineq /-! # Sign of a permutation The main definition of this file is `Equiv.Perm.sign`, associating a `ℤˣ` sign with a permutation. Other lemmas have been moved to `Mathlib.GroupTheory.Perm.Fintype` -/ universe u v open Equiv Function Fintype Finset variable {α : Type u} [DecidableEq α] {β : Type v} namespace Equiv.Perm /-- `modSwap i j` contains permutations up to swapping `i` and `j`. We use this to partition permutations in `Matrix.det_zero_of_row_eq`, such that each partition sums up to `0`. -/ def modSwap (i j : α) : Setoid (Perm α) := ⟨fun σ τ => σ = τ ∨ σ = swap i j * τ, fun σ => Or.inl (refl σ), fun {σ τ} h => Or.casesOn h (fun h => Or.inl h.symm) fun h => Or.inr (by rw [h, swap_mul_self_mul]), fun {σ τ υ} hστ hτυ => by cases' hστ with hστ hστ <;> cases' hτυ with hτυ hτυ <;> try rw [hστ, hτυ, swap_mul_self_mul] <;> simp [hστ, hτυ] -- Porting note: should close goals, but doesn't · simp [hστ, hτυ] · simp [hστ, hτυ] · simp [hστ, hτυ]⟩ noncomputable instance {α : Type*} [Fintype α] [DecidableEq α] (i j : α) : DecidableRel (modSwap i j).r := fun _ _ => Or.decidable /-- Given a list `l : List α` and a permutation `f : Perm α` such that the nonfixed points of `f` are in `l`, recursively factors `f` as a product of transpositions. -/ def swapFactorsAux : ∀ (l : List α) (f : Perm α), (∀ {x}, f x ≠ x → x ∈ l) → { l : List (Perm α) // l.prod = f ∧ ∀ g ∈ l, IsSwap g } | [] => fun f h => ⟨[], Equiv.ext fun x => by rw [List.prod_nil] exact (Classical.not_not.1 (mt h (List.not_mem_nil _))).symm, by simp⟩ | x::l => fun f h => if hfx : x = f x then swapFactorsAux l f fun {y} hy => List.mem_of_ne_of_mem (fun h : y = x => by simp [h, hfx.symm] at hy) (h hy) else let m := swapFactorsAux l (swap x (f x) * f) fun {y} hy => have : f y ≠ y ∧ y ≠ x := ne_and_ne_of_swap_mul_apply_ne_self hy List.mem_of_ne_of_mem this.2 (h this.1) ⟨swap x (f x)::m.1, by rw [List.prod_cons, m.2.1, ← mul_assoc, mul_def (swap x (f x)), swap_swap, ← one_def, one_mul], fun {g} hg => ((List.mem_cons).1 hg).elim (fun h => ⟨x, f x, hfx, h⟩) (m.2.2 _)⟩ /-- `swapFactors` represents a permutation as a product of a list of transpositions. The representation is non unique and depends on the linear order structure. For types without linear order `truncSwapFactors` can be used. -/ def swapFactors [Fintype α] [LinearOrder α] (f : Perm α) : { l : List (Perm α) // l.prod = f ∧ ∀ g ∈ l, IsSwap g } := swapFactorsAux ((@univ α _).sort (· ≤ ·)) f fun {_ _} => (mem_sort _).2 (mem_univ _) /-- This computably represents the fact that any permutation can be represented as the product of a list of transpositions. -/ def truncSwapFactors [Fintype α] (f : Perm α) : Trunc { l : List (Perm α) // l.prod = f ∧ ∀ g ∈ l, IsSwap g } := Quotient.recOnSubsingleton (@univ α _).1 (fun l h => Trunc.mk (swapFactorsAux l f (h _))) (show ∀ x, f x ≠ x → x ∈ (@univ α _).1 from fun _ _ => mem_univ _) /-- An induction principle for permutations. If `P` holds for the identity permutation, and is preserved under composition with a non-trivial swap, then `P` holds for all permutations. -/ @[elab_as_elim] theorem swap_induction_on [Finite α] {P : Perm α → Prop} (f : Perm α) : P 1 → (∀ f x y, x ≠ y → P f → P (swap x y * f)) → P f := by cases nonempty_fintype α cases' (truncSwapFactors f).out with l hl induction' l with g l ih generalizing f · simp (config := { contextual := true }) only [hl.left.symm, List.prod_nil, forall_true_iff] · intro h1 hmul_swap rcases hl.2 g (by simp) with ⟨x, y, hxy⟩ rw [← hl.1, List.prod_cons, hxy.2] exact hmul_swap _ _ _ hxy.1 (ih _ ⟨rfl, fun v hv => hl.2 _ (List.mem_cons_of_mem _ hv)⟩ h1 hmul_swap) theorem mclosure_isSwap [Finite α] : Submonoid.closure { σ : Perm α | IsSwap σ } = ⊤ := by cases nonempty_fintype α refine top_unique fun x _ ↦ ?_ obtain ⟨h1, h2⟩ := Subtype.mem (truncSwapFactors x).out rw [← h1] exact Submonoid.list_prod_mem _ fun y hy ↦ Submonoid.subset_closure (h2 y hy) theorem closure_isSwap [Finite α] : Subgroup.closure { σ : Perm α | IsSwap σ } = ⊤ := Subgroup.closure_eq_top_of_mclosure_eq_top mclosure_isSwap /-- Every finite symmetric group is generated by transpositions of adjacent elements. -/ theorem mclosure_swap_castSucc_succ (n : ℕ) : Submonoid.closure (Set.range fun i : Fin n ↦ swap i.castSucc i.succ) = ⊤ := by apply top_unique rw [← mclosure_isSwap, Submonoid.closure_le] rintro _ ⟨i, j, ne, rfl⟩ wlog lt : i < j generalizing i j · rw [swap_comm]; exact this _ _ ne.symm (ne.lt_or_lt.resolve_left lt) induction' j using Fin.induction with j ih · cases lt have mem : swap j.castSucc j.succ ∈ Submonoid.closure (Set.range fun (i : Fin n) ↦ swap i.castSucc i.succ) := Submonoid.subset_closure ⟨_, rfl⟩ obtain rfl | lts := (Fin.le_castSucc_iff.mpr lt).eq_or_lt · exact mem rw [swap_comm, ← swap_mul_swap_mul_swap (y := Fin.castSucc j) lts.ne lt.ne] exact mul_mem (mul_mem mem <| ih lts.ne lts) mem /-- Like `swap_induction_on`, but with the composition on the right of `f`. An induction principle for permutations. If `P` holds for the identity permutation, and is preserved under composition with a non-trivial swap, then `P` holds for all permutations. -/ @[elab_as_elim] theorem swap_induction_on' [Finite α] {P : Perm α → Prop} (f : Perm α) : P 1 → (∀ f x y, x ≠ y → P f → P (f * swap x y)) → P f := fun h1 IH => inv_inv f ▸ swap_induction_on f⁻¹ h1 fun f => IH f⁻¹ theorem isConj_swap {w x y z : α} (hwx : w ≠ x) (hyz : y ≠ z) : IsConj (swap w x) (swap y z) := isConj_iff.2 (have h : ∀ {y z : α}, y ≠ z → w ≠ z → swap w y * swap x z * swap w x * (swap w y * swap x z)⁻¹ = swap y z := fun {y z} hyz hwz => by rw [mul_inv_rev, swap_inv, swap_inv, mul_assoc (swap w y), mul_assoc (swap w y), ← mul_assoc _ (swap x z), swap_mul_swap_mul_swap hwx hwz, ← mul_assoc, swap_mul_swap_mul_swap hwz.symm hyz.symm] if hwz : w = z then have hwy : w ≠ y := by rw [hwz]; exact hyz.symm ⟨swap w z * swap x y, by rw [swap_comm y z, h hyz.symm hwy]⟩ else ⟨swap w y * swap x z, h hyz hwz⟩) /-- set of all pairs (⟨a, b⟩ : Σ a : fin n, fin n) such that b < a -/ def finPairsLT (n : ℕ) : Finset (Σ_ : Fin n, Fin n) := (univ : Finset (Fin n)).sigma fun a => (range a).attachFin fun _ hm => (mem_range.1 hm).trans a.2 theorem mem_finPairsLT {n : ℕ} {a : Σ_ : Fin n, Fin n} : a ∈ finPairsLT n ↔ a.2 < a.1 := by simp only [finPairsLT, Fin.lt_iff_val_lt_val, true_and_iff, mem_attachFin, mem_range, mem_univ, mem_sigma] /-- `signAux σ` is the sign of a permutation on `Fin n`, defined as the parity of the number of pairs `(x₁, x₂)` such that `x₂ < x₁` but `σ x₁ ≤ σ x₂` -/ def signAux {n : ℕ} (a : Perm (Fin n)) : ℤˣ := ∏ x ∈ finPairsLT n, if a x.1 ≤ a x.2 then -1 else 1 @[simp] theorem signAux_one (n : ℕ) : signAux (1 : Perm (Fin n)) = 1 := by unfold signAux conv => rhs; rw [← @Finset.prod_const_one _ _ (finPairsLT n)] exact Finset.prod_congr rfl fun a ha => if_neg (mem_finPairsLT.1 ha).not_le /-- `signBijAux f ⟨a, b⟩` returns the pair consisting of `f a` and `f b` in decreasing order. -/ def signBijAux {n : ℕ} (f : Perm (Fin n)) (a : Σ_ : Fin n, Fin n) : Σ_ : Fin n, Fin n := if _ : f a.2 < f a.1 then ⟨f a.1, f a.2⟩ else ⟨f a.2, f a.1⟩ theorem signBijAux_injOn {n : ℕ} {f : Perm (Fin n)} : (finPairsLT n : Set (Σ _, Fin n)).InjOn (signBijAux f) := by rintro ⟨a₁, a₂⟩ ha ⟨b₁, b₂⟩ hb h dsimp [signBijAux] at h rw [Finset.mem_coe, mem_finPairsLT] at * have : ¬b₁ < b₂ := hb.le.not_lt split_ifs at h <;> simp_all [(Equiv.injective f).eq_iff, eq_self_iff_true, and_self_iff, heq_iff_eq] · exact absurd this (not_le.mpr ha) · exact absurd this (not_le.mpr ha) theorem signBijAux_surj {n : ℕ} {f : Perm (Fin n)} : ∀ a ∈ finPairsLT n, ∃ b ∈ finPairsLT n, signBijAux f b = a := fun ⟨a₁, a₂⟩ ha => if hxa : f⁻¹ a₂ < f⁻¹ a₁ then ⟨⟨f⁻¹ a₁, f⁻¹ a₂⟩, mem_finPairsLT.2 hxa, by dsimp [signBijAux] rw [apply_inv_self, apply_inv_self, if_pos (mem_finPairsLT.1 ha)]⟩ else ⟨⟨f⁻¹ a₂, f⁻¹ a₁⟩, mem_finPairsLT.2 <| (le_of_not_gt hxa).lt_of_ne fun h => by simp [mem_finPairsLT, f⁻¹.injective h, lt_irrefl] at ha, by dsimp [signBijAux] rw [apply_inv_self, apply_inv_self, if_neg (mem_finPairsLT.1 ha).le.not_lt]⟩ theorem signBijAux_mem {n : ℕ} {f : Perm (Fin n)} : ∀ a : Σ_ : Fin n, Fin n, a ∈ finPairsLT n → signBijAux f a ∈ finPairsLT n := fun ⟨a₁, a₂⟩ ha => by unfold signBijAux split_ifs with h · exact mem_finPairsLT.2 h · exact mem_finPairsLT.2 ((le_of_not_gt h).lt_of_ne fun h => (mem_finPairsLT.1 ha).ne (f.injective h.symm)) @[simp] theorem signAux_inv {n : ℕ} (f : Perm (Fin n)) : signAux f⁻¹ = signAux f := prod_nbij (signBijAux f⁻¹) signBijAux_mem signBijAux_injOn signBijAux_surj fun ⟨a, b⟩ hab ↦ if h : f⁻¹ b < f⁻¹ a then by simp_all [signBijAux, dif_pos h, if_neg h.not_le, apply_inv_self, apply_inv_self, if_neg (mem_finPairsLT.1 hab).not_le] else by simp_all [signBijAux, if_pos (le_of_not_gt h), dif_neg h, apply_inv_self, apply_inv_self, if_pos (mem_finPairsLT.1 hab).le] theorem signAux_mul {n : ℕ} (f g : Perm (Fin n)) : signAux (f * g) = signAux f * signAux g := by rw [← signAux_inv g] unfold signAux rw [← prod_mul_distrib] refine prod_nbij (signBijAux g) signBijAux_mem signBijAux_injOn signBijAux_surj ?_ rintro ⟨a, b⟩ hab dsimp only [signBijAux] rw [mul_apply, mul_apply] rw [mem_finPairsLT] at hab by_cases h : g b < g a · rw [dif_pos h] simp only [not_le_of_gt hab, mul_one, mul_ite, mul_neg, Perm.inv_apply_self, if_false] · rw [dif_neg h, inv_apply_self, inv_apply_self, if_pos hab.le] by_cases h₁ : f (g b) ≤ f (g a) · have : f (g b) ≠ f (g a) := by rw [Ne, f.injective.eq_iff, g.injective.eq_iff] exact ne_of_lt hab rw [if_pos h₁, if_neg (h₁.lt_of_ne this).not_le] rfl · rw [if_neg h₁, if_pos (lt_of_not_ge h₁).le] rfl private theorem signAux_swap_zero_one' (n : ℕ) : signAux (swap (0 : Fin (n + 2)) 1) = -1 := show _ = ∏ x ∈ {(⟨1, 0⟩ : Σ a : Fin (n + 2), Fin (n + 2))}, if (Equiv.swap 0 1) x.1 ≤ swap 0 1 x.2 then (-1 : ℤˣ) else 1 by refine Eq.symm (prod_subset (fun ⟨x₁, x₂⟩ => by simp (config := { contextual := true }) [mem_finPairsLT, Fin.one_pos]) fun a ha₁ ha₂ => ?_) rcases a with ⟨a₁, a₂⟩ replace ha₁ : a₂ < a₁ := mem_finPairsLT.1 ha₁ dsimp only rcases a₁.zero_le.eq_or_lt with (rfl | H) · exact absurd a₂.zero_le ha₁.not_le rcases a₂.zero_le.eq_or_lt with (rfl | H') · simp only [and_true_iff, eq_self_iff_true, heq_iff_eq, mem_singleton, Sigma.mk.inj_iff] at ha₂ have : 1 < a₁ := lt_of_le_of_ne (Nat.succ_le_of_lt ha₁) (Ne.symm (by intro h; apply ha₂; simp [h])) have h01 : Equiv.swap (0 : Fin (n + 2)) 1 0 = 1 := by simp rw [swap_apply_of_ne_of_ne (ne_of_gt H) ha₂, h01, if_neg this.not_le] · have le : 1 ≤ a₂ := Nat.succ_le_of_lt H' have lt : 1 < a₁ := le.trans_lt ha₁ have h01 : Equiv.swap (0 : Fin (n + 2)) 1 1 = 0 := by simp only [swap_apply_right] rcases le.eq_or_lt with (rfl | lt') · rw [swap_apply_of_ne_of_ne H.ne' lt.ne', h01, if_neg H.not_le] · rw [swap_apply_of_ne_of_ne (ne_of_gt H) (ne_of_gt lt), swap_apply_of_ne_of_ne (ne_of_gt H') (ne_of_gt lt'), if_neg ha₁.not_le] private theorem signAux_swap_zero_one {n : ℕ} (hn : 2 ≤ n) : signAux (swap (⟨0, lt_of_lt_of_le (by decide) hn⟩ : Fin n) ⟨1, lt_of_lt_of_le (by decide) hn⟩) = -1 := by rcases n with (_ | _ | n) · norm_num at hn · norm_num at hn · exact signAux_swap_zero_one' n theorem signAux_swap : ∀ {n : ℕ} {x y : Fin n} (_hxy : x ≠ y), signAux (swap x y) = -1 | 0, x, y => by intro; exact Fin.elim0 x | 1, x, y => by dsimp [signAux, swap, swapCore] simp only [eq_iff_true_of_subsingleton, not_true, ite_true, le_refl, prod_const, IsEmpty.forall_iff] | n + 2, x, y => fun hxy => by have h2n : 2 ≤ n + 2 := by exact le_add_self rw [← isConj_iff_eq, ← signAux_swap_zero_one h2n] exact (MonoidHom.mk' signAux signAux_mul).map_isConj (isConj_swap hxy (by exact of_decide_eq_true rfl)) /-- When the list `l : List α` contains all nonfixed points of the permutation `f : Perm α`, `signAux2 l f` recursively calculates the sign of `f`. -/ def signAux2 : List α → Perm α → ℤˣ | [], _ => 1 | x::l, f => if x = f x then signAux2 l f else -signAux2 l (swap x (f x) * f) theorem signAux_eq_signAux2 {n : ℕ} : ∀ (l : List α) (f : Perm α) (e : α ≃ Fin n) (_h : ∀ x, f x ≠ x → x ∈ l), signAux ((e.symm.trans f).trans e) = signAux2 l f | [], f, e, h => by have : f = 1 := Equiv.ext fun y => Classical.not_not.1 (mt (h y) (List.not_mem_nil _)) rw [this, one_def, Equiv.trans_refl, Equiv.symm_trans_self, ← one_def, signAux_one, signAux2] | x::l, f, e, h => by rw [signAux2] by_cases hfx : x = f x · rw [if_pos hfx] exact signAux_eq_signAux2 l f _ fun y (hy : f y ≠ y) => List.mem_of_ne_of_mem (fun h : y = x => by simp [h, hfx.symm] at hy) (h y hy) · have hy : ∀ y : α, (swap x (f x) * f) y ≠ y → y ∈ l := fun y hy => have : f y ≠ y ∧ y ≠ x := ne_and_ne_of_swap_mul_apply_ne_self hy List.mem_of_ne_of_mem this.2 (h _ this.1) have : (e.symm.trans (swap x (f x) * f)).trans e = swap (e x) (e (f x)) * (e.symm.trans f).trans e := by ext rw [← Equiv.symm_trans_swap_trans, mul_def, Equiv.symm_trans_swap_trans, mul_def] repeat (rw [trans_apply]) simp [swap, swapCore] split_ifs <;> rfl have hefx : e x ≠ e (f x) := mt e.injective.eq_iff.1 hfx rw [if_neg hfx, ← signAux_eq_signAux2 _ _ e hy, this, signAux_mul, signAux_swap hefx] simp only [neg_neg, one_mul, neg_mul] /-- When the multiset `s : Multiset α` contains all nonfixed points of the permutation `f : Perm α`, `signAux2 f _` recursively calculates the sign of `f`. -/ def signAux3 [Finite α] (f : Perm α) {s : Multiset α} : (∀ x, x ∈ s) → ℤˣ := Quotient.hrecOn s (fun l _ => signAux2 l f) fun l₁ l₂ h ↦ by rcases Finite.exists_equiv_fin α with ⟨n, ⟨e⟩⟩ refine Function.hfunext (forall_congr fun _ ↦ propext h.mem_iff) fun h₁ h₂ _ ↦ ?_ rw [← signAux_eq_signAux2 _ _ e fun _ _ => h₁ _, ← signAux_eq_signAux2 _ _ e fun _ _ => h₂ _] theorem signAux3_mul_and_swap [Finite α] (f g : Perm α) (s : Multiset α) (hs : ∀ x, x ∈ s) : signAux3 (f * g) hs = signAux3 f hs * signAux3 g hs ∧ Pairwise fun x y => signAux3 (swap x y) hs = -1 := by obtain ⟨n, ⟨e⟩⟩ := Finite.exists_equiv_fin α induction s using Quotient.inductionOn with | _ l => ?_ show signAux2 l (f * g) = signAux2 l f * signAux2 l g ∧ Pairwise fun x y => signAux2 l (swap x y) = -1 have hfg : (e.symm.trans (f * g)).trans e = (e.symm.trans f).trans e * (e.symm.trans g).trans e := Equiv.ext fun h => by simp [mul_apply] constructor · rw [← signAux_eq_signAux2 _ _ e fun _ _ => hs _, ← signAux_eq_signAux2 _ _ e fun _ _ => hs _, ← signAux_eq_signAux2 _ _ e fun _ _ => hs _, hfg, signAux_mul] · intro x y hxy rw [← e.injective.ne_iff] at hxy rw [← signAux_eq_signAux2 _ _ e fun _ _ => hs _, symm_trans_swap_trans, signAux_swap hxy] theorem signAux3_symm_trans_trans [Finite α] [DecidableEq β] [Finite β] (f : Perm α) (e : α ≃ β) {s : Multiset α} {t : Multiset β} (hs : ∀ x, x ∈ s) (ht : ∀ x, x ∈ t) : signAux3 ((e.symm.trans f).trans e) ht = signAux3 f hs := by -- Porting note: switched from term mode to tactic mode induction' t, s using Quotient.inductionOn₂ with t s ht hs show signAux2 _ _ = signAux2 _ _ rcases Finite.exists_equiv_fin β with ⟨n, ⟨e'⟩⟩ rw [← signAux_eq_signAux2 _ _ e' fun _ _ => ht _, ← signAux_eq_signAux2 _ _ (e.trans e') fun _ _ => hs _] exact congr_arg signAux (Equiv.ext fun x => by simp [Equiv.coe_trans, apply_eq_iff_eq, symm_trans_apply]) /-- `SignType.sign` of a permutation returns the signature or parity of a permutation, `1` for even permutations, `-1` for odd permutations. It is the unique surjective group homomorphism from `Perm α` to the group with two elements. -/ def sign [Fintype α] : Perm α →* ℤˣ := MonoidHom.mk' (fun f => signAux3 f mem_univ) fun f g => (signAux3_mul_and_swap f g _ mem_univ).1 section SignType.sign variable [Fintype α] --@[simp] Porting note (#10618): simp can prove theorem sign_mul (f g : Perm α) : sign (f * g) = sign f * sign g := MonoidHom.map_mul sign f g @[simp] theorem sign_trans (f g : Perm α) : sign (f.trans g) = sign g * sign f := by rw [← mul_def, sign_mul] --@[simp] Porting note (#10618): simp can prove theorem sign_one : sign (1 : Perm α) = 1 := MonoidHom.map_one sign @[simp] theorem sign_refl : sign (Equiv.refl α) = 1 := MonoidHom.map_one sign --@[simp] Porting note (#10618): simp can prove theorem sign_inv (f : Perm α) : sign f⁻¹ = sign f := by rw [MonoidHom.map_inv sign f, Int.units_inv_eq_self] @[simp] theorem sign_symm (e : Perm α) : sign e.symm = sign e := sign_inv e theorem sign_swap {x y : α} (h : x ≠ y) : sign (swap x y) = -1 := (signAux3_mul_and_swap 1 1 _ mem_univ).2 h @[simp] theorem sign_swap' {x y : α} : sign (swap x y) = if x = y then 1 else -1 := if H : x = y then by simp [H, swap_self] else by simp [sign_swap H, H] theorem IsSwap.sign_eq {f : Perm α} (h : f.IsSwap) : sign f = -1 := let ⟨_, _, hxy⟩ := h hxy.2.symm ▸ sign_swap hxy.1 @[simp] theorem sign_symm_trans_trans [DecidableEq β] [Fintype β] (f : Perm α) (e : α ≃ β) : sign ((e.symm.trans f).trans e) = sign f := signAux3_symm_trans_trans f e mem_univ mem_univ @[simp] theorem sign_trans_trans_symm [DecidableEq β] [Fintype β] (f : Perm β) (e : α ≃ β) : sign ((e.trans f).trans e.symm) = sign f := sign_symm_trans_trans f e.symm theorem sign_prod_list_swap {l : List (Perm α)} (hl : ∀ g ∈ l, IsSwap g) : sign l.prod = (-1) ^ l.length := by have h₁ : l.map sign = List.replicate l.length (-1) := List.eq_replicate.2 ⟨by simp, fun u hu => let ⟨g, hg⟩ := List.mem_map.1 hu hg.2 ▸ (hl _ hg.1).sign_eq⟩ rw [← List.prod_replicate, ← h₁, List.prod_hom _ (@sign α _ _)] @[simp] theorem sign_abs (f : Perm α) : |(Equiv.Perm.sign f : ℤ)| = 1 := by rw [Int.abs_eq_natAbs, Int.units_natAbs, Nat.cast_one] variable (α) theorem sign_surjective [Nontrivial α] : Function.Surjective (sign : Perm α → ℤˣ) := fun a => (Int.units_eq_one_or a).elim (fun h => ⟨1, by simp [h]⟩) fun h => let ⟨x, y, hxy⟩ := exists_pair_ne α ⟨swap x y, by rw [sign_swap hxy, h]⟩ variable {α} theorem eq_sign_of_surjective_hom {s : Perm α →* ℤˣ} (hs : Surjective s) : s = sign := have : ∀ {f}, IsSwap f → s f = -1 := fun {f} ⟨x, y, hxy, hxy'⟩ => hxy'.symm ▸ by_contradiction fun h => by have : ∀ f, IsSwap f → s f = 1 := fun f ⟨a, b, hab, hab'⟩ => by rw [← isConj_iff_eq, ← Or.resolve_right (Int.units_eq_one_or _) h, hab'] exact s.map_isConj (isConj_swap hab hxy) let ⟨g, hg⟩ := hs (-1) let ⟨l, hl⟩ := (truncSwapFactors g).out have : ∀ a ∈ l.map s, a = (1 : ℤˣ) := fun a ha => let ⟨g, hg⟩ := List.mem_map.1 ha hg.2 ▸ this _ (hl.2 _ hg.1) have : s l.prod = 1 := by rw [← l.prod_hom s, List.eq_replicate_length.2 this, List.prod_replicate, one_pow] rw [hl.1, hg] at this exact absurd this (by simp_all) MonoidHom.ext fun f => by let ⟨l, hl₁, hl₂⟩ := (truncSwapFactors f).out have hsl : ∀ a ∈ l.map s, a = (-1 : ℤˣ) := fun a ha => let ⟨g, hg⟩ := List.mem_map.1 ha hg.2 ▸ this (hl₂ _ hg.1) rw [← hl₁, ← l.prod_hom s, List.eq_replicate_length.2 hsl, List.length_map, List.prod_replicate, sign_prod_list_swap hl₂] theorem sign_subtypePerm (f : Perm α) {p : α → Prop} [DecidablePred p] (h₁ : ∀ x, p x ↔ p (f x)) (h₂ : ∀ x, f x ≠ x → p x) : sign (subtypePerm f h₁) = sign f := by let l := (truncSwapFactors (subtypePerm f h₁)).out have hl' : ∀ g' ∈ l.1.map ofSubtype, IsSwap g' := fun g' hg' => let ⟨g, hg⟩ := List.mem_map.1 hg' hg.2 ▸ (l.2.2 _ hg.1).of_subtype_isSwap have hl'₂ : (l.1.map ofSubtype).prod = f := by rw [l.1.prod_hom ofSubtype, l.2.1, ofSubtype_subtypePerm _ h₂] conv => congr rw [← l.2.1] simp_rw [← hl'₂] rw [sign_prod_list_swap l.2.2, sign_prod_list_swap hl', List.length_map] theorem sign_eq_sign_of_equiv [DecidableEq β] [Fintype β] (f : Perm α) (g : Perm β) (e : α ≃ β) (h : ∀ x, e (f x) = g (e x)) : sign f = sign g := by have hg : g = (e.symm.trans f).trans e := Equiv.ext <| by simp [h] rw [hg, sign_symm_trans_trans] theorem sign_bij [DecidableEq β] [Fintype β] {f : Perm α} {g : Perm β} (i : ∀ x : α, f x ≠ x → β) (h : ∀ x hx hx', i (f x) hx' = g (i x hx)) (hi : ∀ x₁ x₂ hx₁ hx₂, i x₁ hx₁ = i x₂ hx₂ → x₁ = x₂) (hg : ∀ y, g y ≠ y → ∃ x hx, i x hx = y) : sign f = sign g := calc sign f = sign (subtypePerm f <| by simp : Perm { x // f x ≠ x }) := (sign_subtypePerm _ _ fun _ => id).symm _ = sign (subtypePerm g <| by simp : Perm { x // g x ≠ x }) := sign_eq_sign_of_equiv _ _ (Equiv.ofBijective (fun x : { x // f x ≠ x } => (⟨i x.1 x.2, by have : f (f x) ≠ f x := mt (fun h => f.injective h) x.2 rw [← h _ x.2 this] exact mt (hi _ _ this x.2) x.2⟩ : { y // g y ≠ y })) ⟨fun ⟨x, hx⟩ ⟨y, hy⟩ h => Subtype.eq (hi _ _ _ _ (Subtype.mk.inj h)), fun ⟨y, hy⟩ => let ⟨x, hfx, hx⟩ := hg y hy ⟨⟨x, hfx⟩, Subtype.eq hx⟩⟩) fun ⟨x, _⟩ => Subtype.eq (h x _ _) _ = sign g := sign_subtypePerm _ _ fun _ => id /-- If we apply `prod_extendRight a (σ a)` for all `a : α` in turn, we get `prod_congrRight σ`. -/ theorem prod_prodExtendRight {α : Type*} [DecidableEq α] (σ : α → Perm β) {l : List α} (hl : l.Nodup) (mem_l : ∀ a, a ∈ l) : (l.map fun a => prodExtendRight a (σ a)).prod = prodCongrRight σ := by ext ⟨a, b⟩ : 1 -- We'll use induction on the list of elements, -- but we have to keep track of whether we already passed `a` in the list. suffices a ∈ l ∧ (l.map fun a => prodExtendRight a (σ a)).prod (a, b) = (a, σ a b) ∨ a ∉ l ∧ (l.map fun a => prodExtendRight a (σ a)).prod (a, b) = (a, b) by obtain ⟨_, prod_eq⟩ := Or.resolve_right this (not_and.mpr fun h _ => h (mem_l a)) rw [prod_eq, prodCongrRight_apply] clear mem_l induction' l with a' l ih · refine Or.inr ⟨List.not_mem_nil _, ?_⟩ rw [List.map_nil, List.prod_nil, one_apply] rw [List.map_cons, List.prod_cons, mul_apply] rcases ih (List.nodup_cons.mp hl).2 with (⟨mem_l, prod_eq⟩ | ⟨not_mem_l, prod_eq⟩) <;> rw [prod_eq] · refine Or.inl ⟨List.mem_cons_of_mem _ mem_l, ?_⟩ rw [prodExtendRight_apply_ne _ fun h : a = a' => (List.nodup_cons.mp hl).1 (h ▸ mem_l)] by_cases ha' : a = a' · rw [← ha'] at * refine Or.inl ⟨l.mem_cons_self a, ?_⟩ rw [prodExtendRight_apply_eq] · refine Or.inr ⟨fun h => not_or_of_not ha' not_mem_l ((List.mem_cons).mp h), ?_⟩ rw [prodExtendRight_apply_ne _ ha'] section congr variable [DecidableEq β] [Fintype β] @[simp] theorem sign_prodExtendRight (a : α) (σ : Perm β) : sign (prodExtendRight a σ) = sign σ := sign_bij (fun (ab : α × β) _ => ab.snd) (fun ⟨a', b⟩ hab _ => by simp [eq_of_prodExtendRight_ne hab]) (fun ⟨a₁, b₁⟩ ⟨a₂, b₂⟩ hab₁ hab₂ h => by simpa [eq_of_prodExtendRight_ne hab₁, eq_of_prodExtendRight_ne hab₂] using h) fun y hy => ⟨(a, y), by simpa, by simp⟩ theorem sign_prodCongrRight (σ : α → Perm β) : sign (prodCongrRight σ) = ∏ k, sign (σ k) := by obtain ⟨l, hl, mem_l⟩ := Finite.exists_univ_list α have l_to_finset : l.toFinset = Finset.univ := by apply eq_top_iff.mpr intro b _ exact List.mem_toFinset.mpr (mem_l b) rw [← prod_prodExtendRight σ hl mem_l, map_list_prod sign, List.map_map, ← l_to_finset, List.prod_toFinset _ hl] simp_rw [← fun a => sign_prodExtendRight a (σ a), Function.comp] theorem sign_prodCongrLeft (σ : α → Perm β) : sign (prodCongrLeft σ) = ∏ k, sign (σ k) := by refine (sign_eq_sign_of_equiv _ _ (prodComm β α) ?_).trans (sign_prodCongrRight σ) rintro ⟨b, α⟩ rfl @[simp] theorem sign_permCongr (e : α ≃ β) (p : Perm α) : sign (e.permCongr p) = sign p := sign_eq_sign_of_equiv _ _ e.symm (by simp) @[simp] theorem sign_sumCongr (σa : Perm α) (σb : Perm β) : sign (sumCongr σa σb) = sign σa * sign σb := by suffices sign (sumCongr σa (1 : Perm β)) = sign σa ∧ sign (sumCongr (1 : Perm α) σb) = sign σb by rw [← this.1, ← this.2, ← sign_mul, sumCongr_mul, one_mul, mul_one] constructor · refine σa.swap_induction_on ?_ fun σa' a₁ a₂ ha ih => ?_ · simp · rw [← one_mul (1 : Perm β), ← sumCongr_mul, sign_mul, sign_mul, ih, sumCongr_swap_one, sign_swap ha, sign_swap (Sum.inl_injective.ne_iff.mpr ha)] · refine σb.swap_induction_on ?_ fun σb' b₁ b₂ hb ih => ?_ · simp · rw [← one_mul (1 : Perm α), ← sumCongr_mul, sign_mul, sign_mul, ih, sumCongr_one_swap, sign_swap hb, sign_swap (Sum.inr_injective.ne_iff.mpr hb)] @[simp] theorem sign_subtypeCongr {p : α → Prop} [DecidablePred p] (ep : Perm { a // p a }) (en : Perm { a // ¬p a }) : sign (ep.subtypeCongr en) = sign ep * sign en := by simp [subtypeCongr] @[simp] theorem sign_extendDomain (e : Perm α) {p : β → Prop} [DecidablePred p] (f : α ≃ Subtype p) : Equiv.Perm.sign (e.extendDomain f) = Equiv.Perm.sign e := by simp only [Equiv.Perm.extendDomain, sign_subtypeCongr, sign_permCongr, sign_refl, mul_one] @[simp] theorem sign_ofSubtype {p : α → Prop} [DecidablePred p] (f : Equiv.Perm (Subtype p)) : sign (ofSubtype f) = sign f := sign_extendDomain f (Equiv.refl (Subtype p)) end congr end SignType.sign end Equiv.Perm
GroupTheory\Perm\Subgroup.lean
/- Copyright (c) 2020 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.Group.Action.Basic import Mathlib.Algebra.Group.Subgroup.Finite import Mathlib.Data.Fintype.Perm import Mathlib.GroupTheory.Perm.Basic /-! # Lemmas about subgroups within the permutations (self-equivalences) of a type `α` This file provides extra lemmas about some `Subgroup`s that exist within `Equiv.Perm α`. `GroupTheory.Subgroup` depends on `GroupTheory.Perm.Basic`, so these need to be in a separate file. It also provides decidable instances on membership in these subgroups, since `MonoidHom.decidableMemRange` cannot be inferred without the help of a lambda. The presence of these instances induces a `Fintype` instance on the `QuotientGroup.Quotient` of these subgroups. -/ namespace Equiv namespace Perm universe u instance sumCongrHom.decidableMemRange {α β : Type*} [DecidableEq α] [DecidableEq β] [Fintype α] [Fintype β] : DecidablePred (· ∈ (sumCongrHom α β).range) := fun _ => inferInstance @[simp] theorem sumCongrHom.card_range {α β : Type*} [Fintype (sumCongrHom α β).range] [Fintype (Perm α × Perm β)] : Fintype.card (sumCongrHom α β).range = Fintype.card (Perm α × Perm β) := Fintype.card_eq.mpr ⟨(ofInjective (sumCongrHom α β) sumCongrHom_injective).symm⟩ instance sigmaCongrRightHom.decidableMemRange {α : Type*} {β : α → Type*} [DecidableEq α] [∀ a, DecidableEq (β a)] [Fintype α] [∀ a, Fintype (β a)] : DecidablePred (· ∈ (sigmaCongrRightHom β).range) := fun _ => inferInstance @[simp] theorem sigmaCongrRightHom.card_range {α : Type*} {β : α → Type*} [Fintype (sigmaCongrRightHom β).range] [Fintype (∀ a, Perm (β a))] : Fintype.card (sigmaCongrRightHom β).range = Fintype.card (∀ a, Perm (β a)) := Fintype.card_eq.mpr ⟨(ofInjective (sigmaCongrRightHom β) sigmaCongrRightHom_injective).symm⟩ instance subtypeCongrHom.decidableMemRange {α : Type*} (p : α → Prop) [DecidablePred p] [Fintype (Perm { a // p a } × Perm { a // ¬p a })] [DecidableEq (Perm α)] : DecidablePred (· ∈ (subtypeCongrHom p).range) := fun _ => inferInstance @[simp] theorem subtypeCongrHom.card_range {α : Type*} (p : α → Prop) [DecidablePred p] [Fintype (subtypeCongrHom p).range] [Fintype (Perm { a // p a } × Perm { a // ¬p a })] : Fintype.card (subtypeCongrHom p).range = Fintype.card (Perm { a // p a } × Perm { a // ¬p a }) := Fintype.card_eq.mpr ⟨(ofInjective (subtypeCongrHom p) (subtypeCongrHom_injective p)).symm⟩ /-- **Cayley's theorem**: Every group G is isomorphic to a subgroup of the symmetric group acting on `G`. Note that we generalize this to an arbitrary "faithful" group action by `G`. Setting `H = G` recovers the usual statement of Cayley's theorem via `RightCancelMonoid.faithfulSMul` -/ noncomputable def subgroupOfMulAction (G H : Type*) [Group G] [MulAction G H] [FaithfulSMul G H] : G ≃* (MulAction.toPermHom G H).range := MulEquiv.ofLeftInverse' _ (Classical.choose_spec MulAction.toPerm_injective.hasLeftInverse) end Perm end Equiv
GroupTheory\Perm\Support.lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Aaron Anderson, Yakov Pechersky -/ import Mathlib.Algebra.Group.Commute.Basic import Mathlib.Data.Fintype.Card import Mathlib.GroupTheory.Perm.Basic /-! # support of a permutation ## Main definitions In the following, `f g : Equiv.Perm α`. * `Equiv.Perm.Disjoint`: two permutations `f` and `g` are `Disjoint` if every element is fixed either by `f`, or by `g`. Equivalently, `f` and `g` are `Disjoint` iff their `support` are disjoint. * `Equiv.Perm.IsSwap`: `f = swap x y` for `x ≠ y`. * `Equiv.Perm.support`: the elements `x : α` that are not fixed by `f`. Assume `α` is a Fintype: * `Equiv.Perm.fixed_point_card_lt_of_ne_one f` says that `f` has strictly less than `Fintype.card α - 1` fixed points, unless `f = 1`. (Equivalently, `f.support` has at least 2 elements.) -/ open Equiv Finset namespace Equiv.Perm variable {α : Type*} section Disjoint /-- Two permutations `f` and `g` are `Disjoint` if their supports are disjoint, i.e., every element is fixed either by `f`, or by `g`. -/ def Disjoint (f g : Perm α) := ∀ x, f x = x ∨ g x = x variable {f g h : Perm α} @[symm] theorem Disjoint.symm : Disjoint f g → Disjoint g f := by simp only [Disjoint, or_comm, imp_self] theorem Disjoint.symmetric : Symmetric (@Disjoint α) := fun _ _ => Disjoint.symm instance : IsSymm (Perm α) Disjoint := ⟨Disjoint.symmetric⟩ theorem disjoint_comm : Disjoint f g ↔ Disjoint g f := ⟨Disjoint.symm, Disjoint.symm⟩ theorem Disjoint.commute (h : Disjoint f g) : Commute f g := Equiv.ext fun x => (h x).elim (fun hf => (h (g x)).elim (fun hg => by simp [mul_apply, hf, hg]) fun hg => by simp [mul_apply, hf, g.injective hg]) fun hg => (h (f x)).elim (fun hf => by simp [mul_apply, f.injective hf, hg]) fun hf => by simp [mul_apply, hf, hg] @[simp] theorem disjoint_one_left (f : Perm α) : Disjoint 1 f := fun _ => Or.inl rfl @[simp] theorem disjoint_one_right (f : Perm α) : Disjoint f 1 := fun _ => Or.inr rfl theorem disjoint_iff_eq_or_eq : Disjoint f g ↔ ∀ x : α, f x = x ∨ g x = x := Iff.rfl @[simp] theorem disjoint_refl_iff : Disjoint f f ↔ f = 1 := by refine ⟨fun h => ?_, fun h => h.symm ▸ disjoint_one_left 1⟩ ext x cases' h x with hx hx <;> simp [hx] theorem Disjoint.inv_left (h : Disjoint f g) : Disjoint f⁻¹ g := by intro x rw [inv_eq_iff_eq, eq_comm] exact h x theorem Disjoint.inv_right (h : Disjoint f g) : Disjoint f g⁻¹ := h.symm.inv_left.symm @[simp] theorem disjoint_inv_left_iff : Disjoint f⁻¹ g ↔ Disjoint f g := by refine ⟨fun h => ?_, Disjoint.inv_left⟩ convert h.inv_left @[simp] theorem disjoint_inv_right_iff : Disjoint f g⁻¹ ↔ Disjoint f g := by rw [disjoint_comm, disjoint_inv_left_iff, disjoint_comm] theorem Disjoint.mul_left (H1 : Disjoint f h) (H2 : Disjoint g h) : Disjoint (f * g) h := fun x => by cases H1 x <;> cases H2 x <;> simp [*] theorem Disjoint.mul_right (H1 : Disjoint f g) (H2 : Disjoint f h) : Disjoint f (g * h) := by rw [disjoint_comm] exact H1.symm.mul_left H2.symm -- Porting note (#11215): TODO: make it `@[simp]` theorem disjoint_conj (h : Perm α) : Disjoint (h * f * h⁻¹) (h * g * h⁻¹) ↔ Disjoint f g := (h⁻¹).forall_congr fun {_} ↦ by simp only [mul_apply, eq_inv_iff_eq] theorem Disjoint.conj (H : Disjoint f g) (h : Perm α) : Disjoint (h * f * h⁻¹) (h * g * h⁻¹) := (disjoint_conj h).2 H theorem disjoint_prod_right (l : List (Perm α)) (h : ∀ g ∈ l, Disjoint f g) : Disjoint f l.prod := by induction' l with g l ih · exact disjoint_one_right _ · rw [List.prod_cons] exact (h _ (List.mem_cons_self _ _)).mul_right (ih fun g hg => h g (List.mem_cons_of_mem _ hg)) open scoped List in theorem disjoint_prod_perm {l₁ l₂ : List (Perm α)} (hl : l₁.Pairwise Disjoint) (hp : l₁ ~ l₂) : l₁.prod = l₂.prod := hp.prod_eq' <| hl.imp Disjoint.commute theorem nodup_of_pairwise_disjoint {l : List (Perm α)} (h1 : (1 : Perm α) ∉ l) (h2 : l.Pairwise Disjoint) : l.Nodup := by refine List.Pairwise.imp_of_mem ?_ h2 intro τ σ h_mem _ h_disjoint _ subst τ suffices (σ : Perm α) = 1 by rw [this] at h_mem exact h1 h_mem exact ext fun a => or_self_iff.mp (h_disjoint a) theorem pow_apply_eq_self_of_apply_eq_self {x : α} (hfx : f x = x) : ∀ n : ℕ, (f ^ n) x = x | 0 => rfl | n + 1 => by rw [pow_succ, mul_apply, hfx, pow_apply_eq_self_of_apply_eq_self hfx n] theorem zpow_apply_eq_self_of_apply_eq_self {x : α} (hfx : f x = x) : ∀ n : ℤ, (f ^ n) x = x | (n : ℕ) => pow_apply_eq_self_of_apply_eq_self hfx n | Int.negSucc n => by rw [zpow_negSucc, inv_eq_iff_eq, pow_apply_eq_self_of_apply_eq_self hfx] theorem pow_apply_eq_of_apply_apply_eq_self {x : α} (hffx : f (f x) = x) : ∀ n : ℕ, (f ^ n) x = x ∨ (f ^ n) x = f x | 0 => Or.inl rfl | n + 1 => (pow_apply_eq_of_apply_apply_eq_self hffx n).elim (fun h => Or.inr (by rw [pow_succ', mul_apply, h])) fun h => Or.inl (by rw [pow_succ', mul_apply, h, hffx]) theorem zpow_apply_eq_of_apply_apply_eq_self {x : α} (hffx : f (f x) = x) : ∀ i : ℤ, (f ^ i) x = x ∨ (f ^ i) x = f x | (n : ℕ) => pow_apply_eq_of_apply_apply_eq_self hffx n | Int.negSucc n => by rw [zpow_negSucc, inv_eq_iff_eq, ← f.injective.eq_iff, ← mul_apply, ← pow_succ', eq_comm, inv_eq_iff_eq, ← mul_apply, ← pow_succ, @eq_comm _ x, or_comm] exact pow_apply_eq_of_apply_apply_eq_self hffx _ theorem Disjoint.mul_apply_eq_iff {σ τ : Perm α} (hστ : Disjoint σ τ) {a : α} : (σ * τ) a = a ↔ σ a = a ∧ τ a = a := by refine ⟨fun h => ?_, fun h => by rw [mul_apply, h.2, h.1]⟩ cases' hστ a with hσ hτ · exact ⟨hσ, σ.injective (h.trans hσ.symm)⟩ · exact ⟨(congr_arg σ hτ).symm.trans h, hτ⟩ theorem Disjoint.mul_eq_one_iff {σ τ : Perm α} (hστ : Disjoint σ τ) : σ * τ = 1 ↔ σ = 1 ∧ τ = 1 := by simp_rw [Perm.ext_iff, one_apply, hστ.mul_apply_eq_iff, forall_and] theorem Disjoint.zpow_disjoint_zpow {σ τ : Perm α} (hστ : Disjoint σ τ) (m n : ℤ) : Disjoint (σ ^ m) (τ ^ n) := fun x => Or.imp (fun h => zpow_apply_eq_self_of_apply_eq_self h m) (fun h => zpow_apply_eq_self_of_apply_eq_self h n) (hστ x) theorem Disjoint.pow_disjoint_pow {σ τ : Perm α} (hστ : Disjoint σ τ) (m n : ℕ) : Disjoint (σ ^ m) (τ ^ n) := hστ.zpow_disjoint_zpow m n end Disjoint section IsSwap variable [DecidableEq α] /-- `f.IsSwap` indicates that the permutation `f` is a transposition of two elements. -/ def IsSwap (f : Perm α) : Prop := ∃ x y, x ≠ y ∧ f = swap x y @[simp] theorem ofSubtype_swap_eq {p : α → Prop} [DecidablePred p] (x y : Subtype p) : ofSubtype (Equiv.swap x y) = Equiv.swap ↑x ↑y := Equiv.ext fun z => by by_cases hz : p z · rw [swap_apply_def, ofSubtype_apply_of_mem _ hz] split_ifs with hzx hzy · simp_rw [hzx, Subtype.coe_eta, swap_apply_left] · simp_rw [hzy, Subtype.coe_eta, swap_apply_right] · rw [swap_apply_of_ne_of_ne] <;> simp [Subtype.ext_iff, *] · rw [ofSubtype_apply_of_not_mem _ hz, swap_apply_of_ne_of_ne] · intro h apply hz rw [h] exact Subtype.prop x intro h apply hz rw [h] exact Subtype.prop y theorem IsSwap.of_subtype_isSwap {p : α → Prop} [DecidablePred p] {f : Perm (Subtype p)} (h : f.IsSwap) : (ofSubtype f).IsSwap := let ⟨⟨x, hx⟩, ⟨y, hy⟩, hxy⟩ := h ⟨x, y, by simp only [Ne, Subtype.ext_iff] at hxy exact hxy.1, by rw [hxy.2, ofSubtype_swap_eq]⟩ theorem ne_and_ne_of_swap_mul_apply_ne_self {f : Perm α} {x y : α} (hy : (swap x (f x) * f) y ≠ y) : f y ≠ y ∧ y ≠ x := by simp only [swap_apply_def, mul_apply, f.injective.eq_iff] at * by_cases h : f y = x · constructor <;> intro <;> simp_all only [if_true, eq_self_iff_true, not_true, Ne] · split_ifs at hy with h <;> try { simp [*] at * } end IsSwap section support section Set variable (p q : Perm α) theorem set_support_inv_eq : { x | p⁻¹ x ≠ x } = { x | p x ≠ x } := by ext x simp only [Set.mem_setOf_eq, Ne] rw [inv_def, symm_apply_eq, eq_comm] theorem set_support_apply_mem {p : Perm α} {a : α} : p a ∈ { x | p x ≠ x } ↔ a ∈ { x | p x ≠ x } := by simp theorem set_support_zpow_subset (n : ℤ) : { x | (p ^ n) x ≠ x } ⊆ { x | p x ≠ x } := by intro x simp only [Set.mem_setOf_eq, Ne] intro hx H simp [zpow_apply_eq_self_of_apply_eq_self H] at hx theorem set_support_mul_subset : { x | (p * q) x ≠ x } ⊆ { x | p x ≠ x } ∪ { x | q x ≠ x } := by intro x simp only [Perm.coe_mul, Function.comp_apply, Ne, Set.mem_union, Set.mem_setOf_eq] by_cases hq : q x = x <;> simp [hq] end Set @[simp] theorem apply_pow_apply_eq_iff (f : Perm α) (n : ℕ) {x : α} : f ((f ^ n) x) = (f ^ n) x ↔ f x = x := by rw [← mul_apply, Commute.self_pow f, mul_apply, apply_eq_iff_eq] @[simp] theorem apply_zpow_apply_eq_iff (f : Perm α) (n : ℤ) {x : α} : f ((f ^ n) x) = (f ^ n) x ↔ f x = x := by rw [← mul_apply, Commute.self_zpow f, mul_apply, apply_eq_iff_eq] variable [DecidableEq α] [Fintype α] {f g : Perm α} /-- The `Finset` of nonfixed points of a permutation. -/ def support (f : Perm α) : Finset α := univ.filter fun x => f x ≠ x @[simp] theorem mem_support {x : α} : x ∈ f.support ↔ f x ≠ x := by rw [support, mem_filter, and_iff_right (mem_univ x)] theorem not_mem_support {x : α} : x ∉ f.support ↔ f x = x := by simp theorem coe_support_eq_set_support (f : Perm α) : (f.support : Set α) = { x | f x ≠ x } := by ext simp @[simp] theorem support_eq_empty_iff {σ : Perm α} : σ.support = ∅ ↔ σ = 1 := by simp_rw [Finset.ext_iff, mem_support, Finset.not_mem_empty, iff_false_iff, not_not, Equiv.Perm.ext_iff, one_apply] @[simp] theorem support_one : (1 : Perm α).support = ∅ := by rw [support_eq_empty_iff] @[simp] theorem support_refl : support (Equiv.refl α) = ∅ := support_one theorem support_congr (h : f.support ⊆ g.support) (h' : ∀ x ∈ g.support, f x = g x) : f = g := by ext x by_cases hx : x ∈ g.support · exact h' x hx · rw [not_mem_support.mp hx, ← not_mem_support] exact fun H => hx (h H) theorem support_mul_le (f g : Perm α) : (f * g).support ≤ f.support ⊔ g.support := fun x => by simp only [sup_eq_union] rw [mem_union, mem_support, mem_support, mem_support, mul_apply, ← not_and_or, not_imp_not] rintro ⟨hf, hg⟩ rw [hg, hf] theorem exists_mem_support_of_mem_support_prod {l : List (Perm α)} {x : α} (hx : x ∈ l.prod.support) : ∃ f : Perm α, f ∈ l ∧ x ∈ f.support := by contrapose! hx simp_rw [mem_support, not_not] at hx ⊢ induction' l with f l ih · rfl · rw [List.prod_cons, mul_apply, ih, hx] · simp only [List.find?, List.mem_cons, true_or] intros f' hf' refine hx f' ?_ simp only [List.find?, List.mem_cons] exact Or.inr hf' theorem support_pow_le (σ : Perm α) (n : ℕ) : (σ ^ n).support ≤ σ.support := fun _ h1 => mem_support.mpr fun h2 => mem_support.mp h1 (pow_apply_eq_self_of_apply_eq_self h2 n) @[simp] theorem support_inv (σ : Perm α) : support σ⁻¹ = σ.support := by simp_rw [Finset.ext_iff, mem_support, not_iff_not, inv_eq_iff_eq.trans eq_comm, imp_true_iff] -- @[simp] -- Porting note (#10618): simp can prove this theorem apply_mem_support {x : α} : f x ∈ f.support ↔ x ∈ f.support := by rw [mem_support, mem_support, Ne, Ne, apply_eq_iff_eq] -- @[simp] -- Porting note (#10618): simp can prove this theorem pow_apply_mem_support {n : ℕ} {x : α} : (f ^ n) x ∈ f.support ↔ x ∈ f.support := by simp only [mem_support, ne_eq, apply_pow_apply_eq_iff] -- @[simp] -- Porting note (#10618): simp can prove this theorem zpow_apply_mem_support {n : ℤ} {x : α} : (f ^ n) x ∈ f.support ↔ x ∈ f.support := by simp only [mem_support, ne_eq, apply_zpow_apply_eq_iff] theorem pow_eq_on_of_mem_support (h : ∀ x ∈ f.support ∩ g.support, f x = g x) (k : ℕ) : ∀ x ∈ f.support ∩ g.support, (f ^ k) x = (g ^ k) x := by induction' k with k hk · simp · intro x hx rw [pow_succ, mul_apply, pow_succ, mul_apply, h _ hx, hk] rwa [mem_inter, apply_mem_support, ← h _ hx, apply_mem_support, ← mem_inter] theorem disjoint_iff_disjoint_support : Disjoint f g ↔ _root_.Disjoint f.support g.support := by simp [disjoint_iff_eq_or_eq, disjoint_iff, disjoint_iff, Finset.ext_iff, not_and_or, imp_iff_not_or] theorem Disjoint.disjoint_support (h : Disjoint f g) : _root_.Disjoint f.support g.support := disjoint_iff_disjoint_support.1 h theorem Disjoint.support_mul (h : Disjoint f g) : (f * g).support = f.support ∪ g.support := by refine le_antisymm (support_mul_le _ _) fun a => ?_ rw [mem_union, mem_support, mem_support, mem_support, mul_apply, ← not_and_or, not_imp_not] exact (h a).elim (fun hf h => ⟨hf, f.apply_eq_iff_eq.mp (h.trans hf.symm)⟩) fun hg h => ⟨(congr_arg f hg).symm.trans h, hg⟩ theorem support_prod_of_pairwise_disjoint (l : List (Perm α)) (h : l.Pairwise Disjoint) : l.prod.support = (l.map support).foldr (· ⊔ ·) ⊥ := by induction' l with hd tl hl · simp · rw [List.pairwise_cons] at h have : Disjoint hd tl.prod := disjoint_prod_right _ h.left simp [this.support_mul, hl h.right] theorem support_prod_le (l : List (Perm α)) : l.prod.support ≤ (l.map support).foldr (· ⊔ ·) ⊥ := by induction' l with hd tl hl · simp · rw [List.prod_cons, List.map_cons, List.foldr_cons] refine (support_mul_le hd tl.prod).trans ?_ exact sup_le_sup le_rfl hl theorem support_zpow_le (σ : Perm α) (n : ℤ) : (σ ^ n).support ≤ σ.support := fun _ h1 => mem_support.mpr fun h2 => mem_support.mp h1 (zpow_apply_eq_self_of_apply_eq_self h2 n) @[simp] theorem support_swap {x y : α} (h : x ≠ y) : support (swap x y) = {x, y} := by ext z by_cases hx : z = x any_goals simpa [hx] using h.symm by_cases hy : z = y <;> · simp [swap_apply_of_ne_of_ne, hx, hy] <;> exact h theorem support_swap_iff (x y : α) : support (swap x y) = {x, y} ↔ x ≠ y := by refine ⟨fun h => ?_, fun h => support_swap h⟩ rintro rfl simp [Finset.ext_iff] at h theorem support_swap_mul_swap {x y z : α} (h : List.Nodup [x, y, z]) : support (swap x y * swap y z) = {x, y, z} := by simp only [List.not_mem_nil, and_true_iff, List.mem_cons, not_false_iff, List.nodup_cons, List.mem_singleton, and_self_iff, List.nodup_nil] at h push_neg at h apply le_antisymm · convert support_mul_le (swap x y) (swap y z) using 1 rw [support_swap h.left.left, support_swap h.right.left] simp [Finset.ext_iff] · intro simp only [mem_insert, mem_singleton] rintro (rfl | rfl | rfl | _) <;> simp [swap_apply_of_ne_of_ne, h.left.left, h.left.left.symm, h.left.right.symm, h.left.right.left.symm, h.right.left.symm] theorem support_swap_mul_ge_support_diff (f : Perm α) (x y : α) : f.support \ {x, y} ≤ (swap x y * f).support := by intro simp only [and_imp, Perm.coe_mul, Function.comp_apply, Ne, mem_support, mem_insert, mem_sdiff, mem_singleton] push_neg rintro ha ⟨hx, hy⟩ H rw [swap_apply_eq_iff, swap_apply_of_ne_of_ne hx hy] at H exact ha H theorem support_swap_mul_eq (f : Perm α) (x : α) (h : f (f x) ≠ x) : (swap x (f x) * f).support = f.support \ {x} := by by_cases hx : f x = x · simp [hx, sdiff_singleton_eq_erase, not_mem_support.mpr hx, erase_eq_of_not_mem] ext z by_cases hzx : z = x · simp [hzx] by_cases hzf : z = f x · simp [hzf, hx, h, swap_apply_of_ne_of_ne] by_cases hzfx : f z = x · simp [Ne.symm hzx, hzx, Ne.symm hzf, hzfx] · simp [Ne.symm hzx, hzx, Ne.symm hzf, hzfx, f.injective.ne hzx, swap_apply_of_ne_of_ne] theorem mem_support_swap_mul_imp_mem_support_ne {x y : α} (hy : y ∈ support (swap x (f x) * f)) : y ∈ support f ∧ y ≠ x := by simp only [mem_support, swap_apply_def, mul_apply, f.injective.eq_iff] at * by_cases h : f y = x · constructor <;> intro <;> simp_all only [if_true, eq_self_iff_true, not_true, Ne] · split_ifs at hy with heq · subst heq; exact ⟨h, hy⟩ · exact ⟨hy, heq⟩ theorem Disjoint.mem_imp (h : Disjoint f g) {x : α} (hx : x ∈ f.support) : x ∉ g.support := disjoint_left.mp h.disjoint_support hx theorem eq_on_support_mem_disjoint {l : List (Perm α)} (h : f ∈ l) (hl : l.Pairwise Disjoint) : ∀ x ∈ f.support, f x = l.prod x := by induction' l with hd tl IH · simp at h · intro x hx rw [List.pairwise_cons] at hl rw [List.mem_cons] at h rcases h with (rfl | h) · rw [List.prod_cons, mul_apply, not_mem_support.mp ((disjoint_prod_right tl hl.left).mem_imp hx)] · rw [List.prod_cons, mul_apply, ← IH h hl.right _ hx, eq_comm, ← not_mem_support] refine (hl.left _ h).symm.mem_imp ?_ simpa using hx theorem Disjoint.mono {x y : Perm α} (h : Disjoint f g) (hf : x.support ≤ f.support) (hg : y.support ≤ g.support) : Disjoint x y := by rw [disjoint_iff_disjoint_support] at h ⊢ exact h.mono hf hg theorem support_le_prod_of_mem {l : List (Perm α)} (h : f ∈ l) (hl : l.Pairwise Disjoint) : f.support ≤ l.prod.support := by intro x hx rwa [mem_support, ← eq_on_support_mem_disjoint h hl _ hx, ← mem_support] section ExtendDomain variable {β : Type*} [DecidableEq β] [Fintype β] {p : β → Prop} [DecidablePred p] @[simp] theorem support_extend_domain (f : α ≃ Subtype p) {g : Perm α} : support (g.extendDomain f) = g.support.map f.asEmbedding := by ext b simp only [exists_prop, Function.Embedding.coeFn_mk, toEmbedding_apply, mem_map, Ne, Function.Embedding.trans_apply, mem_support] by_cases pb : p b · rw [extendDomain_apply_subtype _ _ pb] constructor · rintro h refine ⟨f.symm ⟨b, pb⟩, ?_, by simp⟩ contrapose! h simp [h] · rintro ⟨a, ha, hb⟩ contrapose! ha obtain rfl : a = f.symm ⟨b, pb⟩ := by rw [eq_symm_apply] exact Subtype.coe_injective hb rw [eq_symm_apply] exact Subtype.coe_injective ha · rw [extendDomain_apply_not_subtype _ _ pb] simp only [not_exists, false_iff_iff, not_and, eq_self_iff_true, not_true] rintro a _ rfl exact pb (Subtype.prop _) theorem card_support_extend_domain (f : α ≃ Subtype p) {g : Perm α} : (g.extendDomain f).support.card = g.support.card := by simp end ExtendDomain section Card -- @[simp] -- Porting note (#10618): simp can prove thisrove this theorem card_support_eq_zero {f : Perm α} : f.support.card = 0 ↔ f = 1 := by rw [Finset.card_eq_zero, support_eq_empty_iff] theorem one_lt_card_support_of_ne_one {f : Perm α} (h : f ≠ 1) : 1 < f.support.card := by simp_rw [one_lt_card_iff, mem_support, ← not_or] contrapose! h ext a specialize h (f a) a rwa [apply_eq_iff_eq, or_self_iff, or_self_iff] at h theorem card_support_ne_one (f : Perm α) : f.support.card ≠ 1 := by by_cases h : f = 1 · exact ne_of_eq_of_ne (card_support_eq_zero.mpr h) zero_ne_one · exact ne_of_gt (one_lt_card_support_of_ne_one h) @[simp] theorem card_support_le_one {f : Perm α} : f.support.card ≤ 1 ↔ f = 1 := by rw [le_iff_lt_or_eq, Nat.lt_succ_iff, Nat.le_zero, card_support_eq_zero, or_iff_not_imp_right, imp_iff_right f.card_support_ne_one] theorem two_le_card_support_of_ne_one {f : Perm α} (h : f ≠ 1) : 2 ≤ f.support.card := one_lt_card_support_of_ne_one h theorem card_support_swap_mul {f : Perm α} {x : α} (hx : f x ≠ x) : (swap x (f x) * f).support.card < f.support.card := Finset.card_lt_card ⟨fun z hz => (mem_support_swap_mul_imp_mem_support_ne hz).left, fun h => absurd (h (mem_support.2 hx)) (mt mem_support.1 (by simp))⟩ theorem card_support_swap {x y : α} (hxy : x ≠ y) : (swap x y).support.card = 2 := show (swap x y).support.card = Finset.card ⟨x ::ₘ y ::ₘ 0, by simp [hxy]⟩ from congr_arg card <| by simp [support_swap hxy, *, Finset.ext_iff] @[simp] theorem card_support_eq_two {f : Perm α} : f.support.card = 2 ↔ IsSwap f := by constructor <;> intro h · obtain ⟨x, t, hmem, hins, ht⟩ := card_eq_succ.1 h obtain ⟨y, rfl⟩ := card_eq_one.1 ht rw [mem_singleton] at hmem refine ⟨x, y, hmem, ?_⟩ ext a have key : ∀ b, f b ≠ b ↔ _ := fun b => by rw [← mem_support, ← hins, mem_insert, mem_singleton] by_cases ha : f a = a · have ha' := not_or.mp (mt (key a).mpr (not_not.mpr ha)) rw [ha, swap_apply_of_ne_of_ne ha'.1 ha'.2] · have ha' := (key (f a)).mp (mt f.apply_eq_iff_eq.mp ha) obtain rfl | rfl := (key a).mp ha · rw [Or.resolve_left ha' ha, swap_apply_left] · rw [Or.resolve_right ha' ha, swap_apply_right] · obtain ⟨x, y, hxy, rfl⟩ := h exact card_support_swap hxy theorem Disjoint.card_support_mul (h : Disjoint f g) : (f * g).support.card = f.support.card + g.support.card := by rw [← Finset.card_union_of_disjoint] · congr ext simp [h.support_mul] · simpa using h.disjoint_support theorem card_support_prod_list_of_pairwise_disjoint {l : List (Perm α)} (h : l.Pairwise Disjoint) : l.prod.support.card = (l.map (Finset.card ∘ support)).sum := by induction' l with a t ih · exact card_support_eq_zero.mpr rfl · obtain ⟨ha, ht⟩ := List.pairwise_cons.1 h rw [List.prod_cons, List.map_cons, List.sum_cons, ← ih ht] exact (disjoint_prod_right _ ha).card_support_mul end Card end support @[simp] theorem support_subtype_perm [DecidableEq α] {s : Finset α} (f : Perm α) (h) : ((f.subtypePerm h : Perm { x // x ∈ s }).support) = (s.attach.filter ((fun x => decide (f x ≠ x))) : Finset { x // x ∈ s }) := by ext simp [Subtype.ext_iff] end Equiv.Perm section FixedPoints namespace Equiv.Perm /-! ### Fixed points -/ variable {α : Type*} theorem fixed_point_card_lt_of_ne_one [DecidableEq α] [Fintype α] {σ : Perm α} (h : σ ≠ 1) : (filter (fun x => σ x = x) univ).card < Fintype.card α - 1 := by rw [Nat.lt_sub_iff_add_lt, ← Nat.lt_sub_iff_add_lt', ← Finset.card_compl, Finset.compl_filter] exact one_lt_card_support_of_ne_one h end Equiv.Perm end FixedPoints section Conjugation namespace Equiv.Perm variable {α : Type*} [Fintype α] [DecidableEq α] {σ τ : Perm α} @[simp] theorem support_conj : (σ * τ * σ⁻¹).support = τ.support.map σ.toEmbedding := by ext simp only [mem_map_equiv, Perm.coe_mul, Function.comp_apply, Ne, Perm.mem_support, Equiv.eq_symm_apply, inv_def] theorem card_support_conj : (σ * τ * σ⁻¹).support.card = τ.support.card := by simp end Equiv.Perm end Conjugation
GroupTheory\Perm\ViaEmbedding.lean
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Mario Carneiro -/ import Mathlib.GroupTheory.Perm.Basic import Mathlib.Logic.Equiv.Set /-! # `Equiv.Perm.viaEmbedding`, a noncomputable analogue of `Equiv.Perm.viaFintypeEmbedding`. -/ variable {α β : Type*} namespace Equiv namespace Perm variable (e : Perm α) (ι : α ↪ β) open scoped Classical /-- Noncomputable version of `Equiv.Perm.viaFintypeEmbedding` that does not assume `Fintype` -/ noncomputable def viaEmbedding : Perm β := extendDomain e (ofInjective ι.1 ι.2) theorem viaEmbedding_apply (x : α) : e.viaEmbedding ι (ι x) = ι (e x) := extendDomain_apply_image e (ofInjective ι.1 ι.2) x theorem viaEmbedding_apply_of_not_mem (x : β) (hx : x ∉ Set.range ι) : e.viaEmbedding ι x = x := extendDomain_apply_not_subtype e (ofInjective ι.1 ι.2) hx /-- `viaEmbedding` as a group homomorphism -/ noncomputable def viaEmbeddingHom : Perm α →* Perm β := extendDomainHom (ofInjective ι.1 ι.2) theorem viaEmbeddingHom_apply : viaEmbeddingHom ι e = viaEmbedding e ι := rfl theorem viaEmbeddingHom_injective : Function.Injective (viaEmbeddingHom ι) := extendDomainHom_injective (ofInjective ι.1 ι.2) end Perm end Equiv
GroupTheory\Perm\Cycle\Basic.lean
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Yaël Dillies -/ import Mathlib.Algebra.Module.BigOperators import Mathlib.Data.Fintype.Perm import Mathlib.GroupTheory.Perm.Finite import Mathlib.GroupTheory.Perm.List /-! # Cycles of a permutation This file starts the theory of cycles in permutations. ## Main definitions In the following, `f : Equiv.Perm β`. * `Equiv.Perm.SameCycle`: `f.SameCycle x y` when `x` and `y` are in the same cycle of `f`. * `Equiv.Perm.IsCycle`: `f` is a cycle if any two nonfixed points of `f` are related by repeated applications of `f`, and `f` is not the identity. * `Equiv.Perm.IsCycleOn`: `f` is a cycle on a set `s` when any two points of `s` are related by repeated applications of `f`. ## Notes `Equiv.Perm.IsCycle` and `Equiv.Perm.IsCycleOn` are different in three ways: * `IsCycle` is about the entire type while `IsCycleOn` is restricted to a set. * `IsCycle` forbids the identity while `IsCycleOn` allows it (if `s` is a subsingleton). * `IsCycleOn` forbids fixed points on `s` (if `s` is nontrivial), while `IsCycle` allows them. -/ open Equiv Function Finset variable {ι α β : Type*} namespace Equiv.Perm /-! ### `SameCycle` -/ section SameCycle variable {f g : Perm α} {p : α → Prop} {x y z : α} /-- The equivalence relation indicating that two points are in the same cycle of a permutation. -/ def SameCycle (f : Perm α) (x y : α) : Prop := ∃ i : ℤ, (f ^ i) x = y @[refl] theorem SameCycle.refl (f : Perm α) (x : α) : SameCycle f x x := ⟨0, rfl⟩ theorem SameCycle.rfl : SameCycle f x x := SameCycle.refl _ _ protected theorem _root_.Eq.sameCycle (h : x = y) (f : Perm α) : f.SameCycle x y := by rw [h] @[symm] theorem SameCycle.symm : SameCycle f x y → SameCycle f y x := fun ⟨i, hi⟩ => ⟨-i, by rw [zpow_neg, ← hi, inv_apply_self]⟩ theorem sameCycle_comm : SameCycle f x y ↔ SameCycle f y x := ⟨SameCycle.symm, SameCycle.symm⟩ @[trans] theorem SameCycle.trans : SameCycle f x y → SameCycle f y z → SameCycle f x z := fun ⟨i, hi⟩ ⟨j, hj⟩ => ⟨j + i, by rw [zpow_add, mul_apply, hi, hj]⟩ variable (f) in theorem SameCycle.equivalence : Equivalence (SameCycle f) := ⟨SameCycle.refl f, SameCycle.symm, SameCycle.trans⟩ /-- The setoid defined by the `SameCycle` relation. -/ def SameCycle.setoid (f : Perm α) : Setoid α where iseqv := SameCycle.equivalence f @[simp] theorem sameCycle_one : SameCycle 1 x y ↔ x = y := by simp [SameCycle] @[simp] theorem sameCycle_inv : SameCycle f⁻¹ x y ↔ SameCycle f x y := (Equiv.neg _).exists_congr_left.trans <| by simp [SameCycle] alias ⟨SameCycle.of_inv, SameCycle.inv⟩ := sameCycle_inv @[simp] theorem sameCycle_conj : SameCycle (g * f * g⁻¹) x y ↔ SameCycle f (g⁻¹ x) (g⁻¹ y) := exists_congr fun i => by simp [conj_zpow, eq_inv_iff_eq] theorem SameCycle.conj : SameCycle f x y → SameCycle (g * f * g⁻¹) (g x) (g y) := by simp [sameCycle_conj] theorem SameCycle.apply_eq_self_iff : SameCycle f x y → (f x = x ↔ f y = y) := fun ⟨i, hi⟩ => by rw [← hi, ← mul_apply, ← zpow_one_add, add_comm, zpow_add_one, mul_apply, (f ^ i).injective.eq_iff] theorem SameCycle.eq_of_left (h : SameCycle f x y) (hx : IsFixedPt f x) : x = y := let ⟨_, hn⟩ := h (hx.perm_zpow _).eq.symm.trans hn theorem SameCycle.eq_of_right (h : SameCycle f x y) (hy : IsFixedPt f y) : x = y := h.eq_of_left <| h.apply_eq_self_iff.2 hy @[simp] theorem sameCycle_apply_left : SameCycle f (f x) y ↔ SameCycle f x y := (Equiv.addRight 1).exists_congr_left.trans <| by simp [zpow_sub, SameCycle, Int.add_neg_one, Function.comp] @[simp] theorem sameCycle_apply_right : SameCycle f x (f y) ↔ SameCycle f x y := by rw [sameCycle_comm, sameCycle_apply_left, sameCycle_comm] @[simp] theorem sameCycle_inv_apply_left : SameCycle f (f⁻¹ x) y ↔ SameCycle f x y := by rw [← sameCycle_apply_left, apply_inv_self] @[simp] theorem sameCycle_inv_apply_right : SameCycle f x (f⁻¹ y) ↔ SameCycle f x y := by rw [← sameCycle_apply_right, apply_inv_self] @[simp] theorem sameCycle_zpow_left {n : ℤ} : SameCycle f ((f ^ n) x) y ↔ SameCycle f x y := (Equiv.addRight (n : ℤ)).exists_congr_left.trans <| by simp [SameCycle, zpow_add] @[simp] theorem sameCycle_zpow_right {n : ℤ} : SameCycle f x ((f ^ n) y) ↔ SameCycle f x y := by rw [sameCycle_comm, sameCycle_zpow_left, sameCycle_comm] @[simp] theorem sameCycle_pow_left {n : ℕ} : SameCycle f ((f ^ n) x) y ↔ SameCycle f x y := by rw [← zpow_natCast, sameCycle_zpow_left] @[simp] theorem sameCycle_pow_right {n : ℕ} : SameCycle f x ((f ^ n) y) ↔ SameCycle f x y := by rw [← zpow_natCast, sameCycle_zpow_right] alias ⟨SameCycle.of_apply_left, SameCycle.apply_left⟩ := sameCycle_apply_left alias ⟨SameCycle.of_apply_right, SameCycle.apply_right⟩ := sameCycle_apply_right alias ⟨SameCycle.of_inv_apply_left, SameCycle.inv_apply_left⟩ := sameCycle_inv_apply_left alias ⟨SameCycle.of_inv_apply_right, SameCycle.inv_apply_right⟩ := sameCycle_inv_apply_right alias ⟨SameCycle.of_pow_left, SameCycle.pow_left⟩ := sameCycle_pow_left alias ⟨SameCycle.of_pow_right, SameCycle.pow_right⟩ := sameCycle_pow_right alias ⟨SameCycle.of_zpow_left, SameCycle.zpow_left⟩ := sameCycle_zpow_left alias ⟨SameCycle.of_zpow_right, SameCycle.zpow_right⟩ := sameCycle_zpow_right theorem SameCycle.of_pow {n : ℕ} : SameCycle (f ^ n) x y → SameCycle f x y := fun ⟨m, h⟩ => ⟨n * m, by simp [zpow_mul, h]⟩ theorem SameCycle.of_zpow {n : ℤ} : SameCycle (f ^ n) x y → SameCycle f x y := fun ⟨m, h⟩ => ⟨n * m, by simp [zpow_mul, h]⟩ @[simp] theorem sameCycle_subtypePerm {h} {x y : { x // p x }} : (f.subtypePerm h).SameCycle x y ↔ f.SameCycle x y := exists_congr fun n => by simp [Subtype.ext_iff] alias ⟨_, SameCycle.subtypePerm⟩ := sameCycle_subtypePerm @[simp] theorem sameCycle_extendDomain {p : β → Prop} [DecidablePred p] {f : α ≃ Subtype p} : SameCycle (g.extendDomain f) (f x) (f y) ↔ g.SameCycle x y := exists_congr fun n => by rw [← extendDomain_zpow, extendDomain_apply_image, Subtype.coe_inj, f.injective.eq_iff] alias ⟨_, SameCycle.extendDomain⟩ := sameCycle_extendDomain theorem SameCycle.exists_pow_eq' [Finite α] : SameCycle f x y → ∃ i < orderOf f, (f ^ i) x = y := by classical rintro ⟨k, rfl⟩ use (k % orderOf f).natAbs have h₀ := Int.natCast_pos.mpr (orderOf_pos f) have h₁ := Int.emod_nonneg k h₀.ne' rw [← zpow_natCast, Int.natAbs_of_nonneg h₁, zpow_mod_orderOf] refine ⟨?_, by rfl⟩ rw [← Int.ofNat_lt, Int.natAbs_of_nonneg h₁] exact Int.emod_lt_of_pos _ h₀ theorem SameCycle.exists_pow_eq'' [Finite α] (h : SameCycle f x y) : ∃ i : ℕ, 0 < i ∧ i ≤ orderOf f ∧ (f ^ i) x = y := by classical obtain ⟨_ | i, hi, rfl⟩ := h.exists_pow_eq' · refine ⟨orderOf f, orderOf_pos f, le_rfl, ?_⟩ rw [pow_orderOf_eq_one, pow_zero] · exact ⟨i.succ, i.zero_lt_succ, hi.le, by rfl⟩ instance (f : Perm α) [DecidableRel (SameCycle f⁻¹)] : DecidableRel (SameCycle f) := fun x y => decidable_of_iff (f⁻¹.SameCycle x y) (sameCycle_inv) instance (f : Perm α) [DecidableRel (SameCycle f)] : DecidableRel (SameCycle f⁻¹) := fun x y => decidable_of_iff (f.SameCycle x y) (sameCycle_inv).symm instance (priority := 100) [DecidableEq α] : DecidableRel (SameCycle (1 : Perm α)) := fun x y => decidable_of_iff (x = y) sameCycle_one.symm instance [Fintype α] [DecidableEq α] (f : Perm α) : DecidableRel (SameCycle f) := fun x y => decidable_of_iff (∃ n ∈ List.range (Fintype.card (Perm α)), (f ^ n) x = y) ⟨fun ⟨n, _, hn⟩ => ⟨n, hn⟩, fun ⟨i, hi⟩ => ⟨(i % orderOf f).natAbs, List.mem_range.2 (Int.ofNat_lt.1 <| by rw [Int.natAbs_of_nonneg (Int.emod_nonneg _ <| Int.natCast_ne_zero.2 (orderOf_pos _).ne')] refine (Int.emod_lt _ <| Int.natCast_ne_zero_iff_pos.2 <| orderOf_pos _).trans_le ?_ simp [orderOf_le_card_univ]), by rw [← zpow_natCast, Int.natAbs_of_nonneg (Int.emod_nonneg _ <| Int.natCast_ne_zero_iff_pos.2 <| orderOf_pos _), zpow_mod_orderOf, hi]⟩⟩ end SameCycle /-! ### `IsCycle` -/ section IsCycle variable {f g : Perm α} {x y : α} /-- A cycle is a non identity permutation where any two nonfixed points of the permutation are related by repeated application of the permutation. -/ def IsCycle (f : Perm α) : Prop := ∃ x, f x ≠ x ∧ ∀ ⦃y⦄, f y ≠ y → SameCycle f x y theorem IsCycle.ne_one (h : IsCycle f) : f ≠ 1 := fun hf => by simp [hf, IsCycle] at h @[simp] theorem not_isCycle_one : ¬(1 : Perm α).IsCycle := fun H => H.ne_one rfl protected theorem IsCycle.sameCycle (hf : IsCycle f) (hx : f x ≠ x) (hy : f y ≠ y) : SameCycle f x y := let ⟨g, hg⟩ := hf let ⟨a, ha⟩ := hg.2 hx let ⟨b, hb⟩ := hg.2 hy ⟨b - a, by rw [← ha, ← mul_apply, ← zpow_add, sub_add_cancel, hb]⟩ theorem IsCycle.exists_zpow_eq : IsCycle f → f x ≠ x → f y ≠ y → ∃ i : ℤ, (f ^ i) x = y := IsCycle.sameCycle theorem IsCycle.inv (hf : IsCycle f) : IsCycle f⁻¹ := hf.imp fun _ ⟨hx, h⟩ => ⟨inv_eq_iff_eq.not.2 hx.symm, fun _ hy => (h <| inv_eq_iff_eq.not.2 hy.symm).inv⟩ @[simp] theorem isCycle_inv : IsCycle f⁻¹ ↔ IsCycle f := ⟨fun h => h.inv, IsCycle.inv⟩ theorem IsCycle.conj : IsCycle f → IsCycle (g * f * g⁻¹) := by rintro ⟨x, hx, h⟩ refine ⟨g x, by simp [coe_mul, inv_apply_self, hx], fun y hy => ?_⟩ rw [← apply_inv_self g y] exact (h <| eq_inv_iff_eq.not.2 hy).conj protected theorem IsCycle.extendDomain {p : β → Prop} [DecidablePred p] (f : α ≃ Subtype p) : IsCycle g → IsCycle (g.extendDomain f) := by rintro ⟨a, ha, ha'⟩ refine ⟨f a, ?_, fun b hb => ?_⟩ · rw [extendDomain_apply_image] exact Subtype.coe_injective.ne (f.injective.ne ha) have h : b = f (f.symm ⟨b, of_not_not <| hb ∘ extendDomain_apply_not_subtype _ _⟩) := by rw [apply_symm_apply, Subtype.coe_mk] rw [h] at hb ⊢ simp only [extendDomain_apply_image, Subtype.coe_injective.ne_iff, f.injective.ne_iff] at hb exact (ha' hb).extendDomain theorem isCycle_iff_sameCycle (hx : f x ≠ x) : IsCycle f ↔ ∀ {y}, SameCycle f x y ↔ f y ≠ y := ⟨fun hf y => ⟨fun ⟨i, hi⟩ hy => hx <| by rw [← zpow_apply_eq_self_of_apply_eq_self hy i, (f ^ i).injective.eq_iff] at hi rw [hi, hy], hf.exists_zpow_eq hx⟩, fun h => ⟨x, hx, fun y hy => h.2 hy⟩⟩ section Finite variable [Finite α] theorem IsCycle.exists_pow_eq (hf : IsCycle f) (hx : f x ≠ x) (hy : f y ≠ y) : ∃ i : ℕ, (f ^ i) x = y := by let ⟨n, hn⟩ := hf.exists_zpow_eq hx hy classical exact ⟨(n % orderOf f).toNat, by {have := n.emod_nonneg (Int.natCast_ne_zero.mpr (ne_of_gt (orderOf_pos f))) rwa [← zpow_natCast, Int.toNat_of_nonneg this, zpow_mod_orderOf]}⟩ end Finite variable [DecidableEq α] theorem isCycle_swap (hxy : x ≠ y) : IsCycle (swap x y) := ⟨y, by rwa [swap_apply_right], fun a (ha : ite (a = x) y (ite (a = y) x a) ≠ a) => if hya : y = a then ⟨0, hya⟩ else ⟨1, by rw [zpow_one, swap_apply_def] split_ifs at * <;> tauto⟩⟩ protected theorem IsSwap.isCycle : IsSwap f → IsCycle f := by rintro ⟨x, y, hxy, rfl⟩ exact isCycle_swap hxy variable [Fintype α] theorem IsCycle.two_le_card_support (h : IsCycle f) : 2 ≤ f.support.card := two_le_card_support_of_ne_one h.ne_one /-- The subgroup generated by a cycle is in bijection with its support -/ noncomputable def IsCycle.zpowersEquivSupport {σ : Perm α} (hσ : IsCycle σ) : (Subgroup.zpowers σ) ≃ σ.support := Equiv.ofBijective (fun (τ : ↥ ((Subgroup.zpowers σ) : Set (Perm α))) => ⟨(τ : Perm α) (Classical.choose hσ), by obtain ⟨τ, n, rfl⟩ := τ erw [Finset.mem_coe, Subtype.coe_mk, zpow_apply_mem_support, mem_support] exact (Classical.choose_spec hσ).1⟩) (by constructor · rintro ⟨a, m, rfl⟩ ⟨b, n, rfl⟩ h ext y by_cases hy : σ y = y · simp_rw [zpow_apply_eq_self_of_apply_eq_self hy] · obtain ⟨i, rfl⟩ := (Classical.choose_spec hσ).2 hy rw [Subtype.coe_mk, Subtype.coe_mk, zpow_apply_comm σ m i, zpow_apply_comm σ n i] exact congr_arg _ (Subtype.ext_iff.mp h) · rintro ⟨y, hy⟩ erw [Finset.mem_coe, mem_support] at hy obtain ⟨n, rfl⟩ := (Classical.choose_spec hσ).2 hy exact ⟨⟨σ ^ n, n, rfl⟩, rfl⟩) @[simp] theorem IsCycle.zpowersEquivSupport_apply {σ : Perm α} (hσ : IsCycle σ) {n : ℕ} : hσ.zpowersEquivSupport ⟨σ ^ n, n, rfl⟩ = ⟨(σ ^ n) (Classical.choose hσ), pow_apply_mem_support.2 (mem_support.2 (Classical.choose_spec hσ).1)⟩ := rfl @[simp] theorem IsCycle.zpowersEquivSupport_symm_apply {σ : Perm α} (hσ : IsCycle σ) (n : ℕ) : hσ.zpowersEquivSupport.symm ⟨(σ ^ n) (Classical.choose hσ), pow_apply_mem_support.2 (mem_support.2 (Classical.choose_spec hσ).1)⟩ = ⟨σ ^ n, n, rfl⟩ := (Equiv.symm_apply_eq _).2 hσ.zpowersEquivSupport_apply protected theorem IsCycle.orderOf (hf : IsCycle f) : orderOf f = f.support.card := by rw [← Fintype.card_zpowers, ← Fintype.card_coe] convert Fintype.card_congr (IsCycle.zpowersEquivSupport hf) theorem isCycle_swap_mul_aux₁ {α : Type*} [DecidableEq α] : ∀ (n : ℕ) {b x : α} {f : Perm α} (_ : (swap x (f x) * f) b ≠ b) (_ : (f ^ n) (f x) = b), ∃ i : ℤ, ((swap x (f x) * f) ^ i) (f x) = b := by intro n induction' n with n hn · exact fun _ h => ⟨0, h⟩ · intro b x f hb h exact if hfbx : f x = b then ⟨0, hfbx⟩ else have : f b ≠ b ∧ b ≠ x := ne_and_ne_of_swap_mul_apply_ne_self hb have hb' : (swap x (f x) * f) (f⁻¹ b) ≠ f⁻¹ b := by rw [mul_apply, apply_inv_self, swap_apply_of_ne_of_ne this.2 (Ne.symm hfbx), Ne, ← f.injective.eq_iff, apply_inv_self] exact this.1 let ⟨i, hi⟩ := hn hb' (f.injective <| by rw [apply_inv_self]; rwa [pow_succ', mul_apply] at h) ⟨i + 1, by rw [add_comm, zpow_add, mul_apply, hi, zpow_one, mul_apply, apply_inv_self, swap_apply_of_ne_of_ne (ne_and_ne_of_swap_mul_apply_ne_self hb).2 (Ne.symm hfbx)]⟩ theorem isCycle_swap_mul_aux₂ {α : Type*} [DecidableEq α] : ∀ (n : ℤ) {b x : α} {f : Perm α} (_ : (swap x (f x) * f) b ≠ b) (_ : (f ^ n) (f x) = b), ∃ i : ℤ, ((swap x (f x) * f) ^ i) (f x) = b := by intro n induction' n with n n · exact isCycle_swap_mul_aux₁ n · intro b x f hb h exact if hfbx' : f x = b then ⟨0, hfbx'⟩ else have : f b ≠ b ∧ b ≠ x := ne_and_ne_of_swap_mul_apply_ne_self hb have hb : (swap x (f⁻¹ x) * f⁻¹) (f⁻¹ b) ≠ f⁻¹ b := by rw [mul_apply, swap_apply_def] split_ifs <;> simp only [inv_eq_iff_eq, Perm.mul_apply, zpow_negSucc, Ne, Perm.apply_inv_self] at * <;> tauto let ⟨i, hi⟩ := isCycle_swap_mul_aux₁ n hb (show (f⁻¹ ^ n) (f⁻¹ x) = f⁻¹ b by rw [← zpow_natCast, ← h, ← mul_apply, ← mul_apply, ← mul_apply, zpow_negSucc, ← inv_pow, pow_succ, mul_assoc, mul_assoc, inv_mul_self, mul_one, zpow_natCast, ← pow_succ', ← pow_succ]) have h : (swap x (f⁻¹ x) * f⁻¹) (f x) = f⁻¹ x := by rw [mul_apply, inv_apply_self, swap_apply_left] ⟨-i, by rw [← add_sub_cancel_right i 1, neg_sub, sub_eq_add_neg, zpow_add, zpow_one, zpow_neg, ← inv_zpow, mul_inv_rev, swap_inv, mul_swap_eq_swap_mul, inv_apply_self, swap_comm _ x, zpow_add, zpow_one, mul_apply, mul_apply (_ ^ i), h, hi, mul_apply, apply_inv_self, swap_apply_of_ne_of_ne this.2 (Ne.symm hfbx')]⟩ theorem IsCycle.eq_swap_of_apply_apply_eq_self {α : Type*} [DecidableEq α] {f : Perm α} (hf : IsCycle f) {x : α} (hfx : f x ≠ x) (hffx : f (f x) = x) : f = swap x (f x) := Equiv.ext fun y => let ⟨z, hz⟩ := hf let ⟨i, hi⟩ := hz.2 hfx if hyx : y = x then by simp [hyx] else if hfyx : y = f x then by simp [hfyx, hffx] else by rw [swap_apply_of_ne_of_ne hyx hfyx] refine by_contradiction fun hy => ?_ cases' hz.2 hy with j hj rw [← sub_add_cancel j i, zpow_add, mul_apply, hi] at hj cases' zpow_apply_eq_of_apply_apply_eq_self hffx (j - i) with hji hji · rw [← hj, hji] at hyx tauto · rw [← hj, hji] at hfyx tauto theorem IsCycle.swap_mul {α : Type*} [DecidableEq α] {f : Perm α} (hf : IsCycle f) {x : α} (hx : f x ≠ x) (hffx : f (f x) ≠ x) : IsCycle (swap x (f x) * f) := ⟨f x, by simp [swap_apply_def, mul_apply, if_neg hffx, f.injective.eq_iff, if_neg hx, hx], fun y hy => let ⟨i, hi⟩ := hf.exists_zpow_eq hx (ne_and_ne_of_swap_mul_apply_ne_self hy).1 -- Porting note: Needed to add Perm α typehint, otherwise does not know how to coerce to fun have hi : (f ^ (i - 1) : Perm α) (f x) = y := calc (f ^ (i - 1) : Perm α) (f x) = (f ^ (i - 1) * f ^ (1 : ℤ) : Perm α) x := by simp _ = y := by rwa [← zpow_add, sub_add_cancel] isCycle_swap_mul_aux₂ (i - 1) hy hi⟩ theorem IsCycle.sign {f : Perm α} (hf : IsCycle f) : sign f = -(-1) ^ f.support.card := let ⟨x, hx⟩ := hf calc Perm.sign f = Perm.sign (swap x (f x) * (swap x (f x) * f)) := by {rw [← mul_assoc, mul_def, mul_def, swap_swap, trans_refl]} _ = -(-1) ^ f.support.card := if h1 : f (f x) = x then by have h : swap x (f x) * f = 1 := by simp only [mul_def, one_def] rw [hf.eq_swap_of_apply_apply_eq_self hx.1 h1, swap_apply_left, swap_swap] rw [sign_mul, sign_swap hx.1.symm, h, sign_one, hf.eq_swap_of_apply_apply_eq_self hx.1 h1, card_support_swap hx.1.symm] rfl else by have h : card (support (swap x (f x) * f)) + 1 = card (support f) := by rw [← insert_erase (mem_support.2 hx.1), support_swap_mul_eq _ _ h1, card_insert_of_not_mem (not_mem_erase _ _), sdiff_singleton_eq_erase] have : card (support (swap x (f x) * f)) < card (support f) := card_support_swap_mul hx.1 rw [sign_mul, sign_swap hx.1.symm, (hf.swap_mul hx.1 h1).sign, ← h] simp only [mul_neg, neg_mul, one_mul, neg_neg, pow_add, pow_one, mul_one] termination_by f.support.card theorem IsCycle.of_pow {n : ℕ} (h1 : IsCycle (f ^ n)) (h2 : f.support ⊆ (f ^ n).support) : IsCycle f := by have key : ∀ x : α, (f ^ n) x ≠ x ↔ f x ≠ x := by simp_rw [← mem_support, ← Finset.ext_iff] exact (support_pow_le _ n).antisymm h2 obtain ⟨x, hx1, hx2⟩ := h1 refine ⟨x, (key x).mp hx1, fun y hy => ?_⟩ cases' hx2 ((key y).mpr hy) with i _ exact ⟨n * i, by rwa [zpow_mul]⟩ -- The lemma `support_zpow_le` is relevant. It means that `h2` is equivalent to -- `σ.support = (σ ^ n).support`, as well as to `σ.support.card ≤ (σ ^ n).support.card`. theorem IsCycle.of_zpow {n : ℤ} (h1 : IsCycle (f ^ n)) (h2 : f.support ⊆ (f ^ n).support) : IsCycle f := by cases n · exact h1.of_pow h2 · simp only [le_eq_subset, zpow_negSucc, Perm.support_inv] at h1 h2 exact (inv_inv (f ^ _) ▸ h1.inv).of_pow h2 theorem nodup_of_pairwise_disjoint_cycles {l : List (Perm β)} (h1 : ∀ f ∈ l, IsCycle f) (h2 : l.Pairwise Disjoint) : l.Nodup := nodup_of_pairwise_disjoint (fun h => (h1 1 h).ne_one rfl) h2 /-- Unlike `support_congr`, which assumes that `∀ (x ∈ g.support), f x = g x)`, here we have the weaker assumption that `∀ (x ∈ f.support), f x = g x`. -/ theorem IsCycle.support_congr (hf : IsCycle f) (hg : IsCycle g) (h : f.support ⊆ g.support) (h' : ∀ x ∈ f.support, f x = g x) : f = g := by have : f.support = g.support := by refine le_antisymm h ?_ intro z hz obtain ⟨x, hx, _⟩ := id hf have hx' : g x ≠ x := by rwa [← h' x (mem_support.mpr hx)] obtain ⟨m, hm⟩ := hg.exists_pow_eq hx' (mem_support.mp hz) have h'' : ∀ x ∈ f.support ∩ g.support, f x = g x := by intro x hx exact h' x (mem_of_mem_inter_left hx) rwa [← hm, ← pow_eq_on_of_mem_support h'' _ x (mem_inter_of_mem (mem_support.mpr hx) (mem_support.mpr hx')), pow_apply_mem_support, mem_support] refine Equiv.Perm.support_congr h ?_ simpa [← this] using h' /-- If two cyclic permutations agree on all terms in their intersection, and that intersection is not empty, then the two cyclic permutations must be equal. -/ theorem IsCycle.eq_on_support_inter_nonempty_congr (hf : IsCycle f) (hg : IsCycle g) (h : ∀ x ∈ f.support ∩ g.support, f x = g x) (hx : f x = g x) (hx' : x ∈ f.support) : f = g := by have hx'' : x ∈ g.support := by rwa [mem_support, ← hx, ← mem_support] have : f.support ⊆ g.support := by intro y hy obtain ⟨k, rfl⟩ := hf.exists_pow_eq (mem_support.mp hx') (mem_support.mp hy) rwa [pow_eq_on_of_mem_support h _ _ (mem_inter_of_mem hx' hx''), pow_apply_mem_support] rw [inter_eq_left.mpr this] at h exact hf.support_congr hg this h theorem IsCycle.support_pow_eq_iff (hf : IsCycle f) {n : ℕ} : support (f ^ n) = support f ↔ ¬orderOf f ∣ n := by rw [orderOf_dvd_iff_pow_eq_one] constructor · intro h H refine hf.ne_one ?_ rw [← support_eq_empty_iff, ← h, H, support_one] · intro H apply le_antisymm (support_pow_le _ n) _ intro x hx contrapose! H ext z by_cases hz : f z = z · rw [pow_apply_eq_self_of_apply_eq_self hz, one_apply] · obtain ⟨k, rfl⟩ := hf.exists_pow_eq hz (mem_support.mp hx) apply (f ^ k).injective rw [← mul_apply, (Commute.pow_pow_self _ _ _).eq, mul_apply] simpa using H theorem IsCycle.support_pow_of_pos_of_lt_orderOf (hf : IsCycle f) {n : ℕ} (npos : 0 < n) (hn : n < orderOf f) : (f ^ n).support = f.support := hf.support_pow_eq_iff.2 <| Nat.not_dvd_of_pos_of_lt npos hn theorem IsCycle.pow_iff [Finite β] {f : Perm β} (hf : IsCycle f) {n : ℕ} : IsCycle (f ^ n) ↔ n.Coprime (orderOf f) := by classical cases nonempty_fintype β constructor · intro h have hr : support (f ^ n) = support f := by rw [hf.support_pow_eq_iff] rintro ⟨k, rfl⟩ refine h.ne_one ?_ simp [pow_mul, pow_orderOf_eq_one] have : orderOf (f ^ n) = orderOf f := by rw [h.orderOf, hr, hf.orderOf] rw [orderOf_pow, Nat.div_eq_self] at this cases' this with h · exact absurd h (orderOf_pos _).ne' · rwa [Nat.coprime_iff_gcd_eq_one, Nat.gcd_comm] · intro h obtain ⟨m, hm⟩ := exists_pow_eq_self_of_coprime h have hf' : IsCycle ((f ^ n) ^ m) := by rwa [hm] refine hf'.of_pow fun x hx => ?_ rw [hm] exact support_pow_le _ n hx -- TODO: Define a `Set`-valued support to get rid of the `Finite β` assumption theorem IsCycle.pow_eq_one_iff [Finite β] {f : Perm β} (hf : IsCycle f) {n : ℕ} : f ^ n = 1 ↔ ∃ x, f x ≠ x ∧ (f ^ n) x = x := by classical cases nonempty_fintype β constructor · intro h obtain ⟨x, hx, -⟩ := id hf exact ⟨x, hx, by simp [h]⟩ · rintro ⟨x, hx, hx'⟩ by_cases h : support (f ^ n) = support f · rw [← mem_support, ← h, mem_support] at hx contradiction · rw [hf.support_pow_eq_iff, Classical.not_not] at h obtain ⟨k, rfl⟩ := h rw [pow_mul, pow_orderOf_eq_one, one_pow] -- TODO: Define a `Set`-valued support to get rid of the `Finite β` assumption theorem IsCycle.pow_eq_one_iff' [Finite β] {f : Perm β} (hf : IsCycle f) {n : ℕ} {x : β} (hx : f x ≠ x) : f ^ n = 1 ↔ (f ^ n) x = x := ⟨fun h => DFunLike.congr_fun h x, fun h => hf.pow_eq_one_iff.2 ⟨x, hx, h⟩⟩ -- TODO: Define a `Set`-valued support to get rid of the `Finite β` assumption theorem IsCycle.pow_eq_one_iff'' [Finite β] {f : Perm β} (hf : IsCycle f) {n : ℕ} : f ^ n = 1 ↔ ∀ x, f x ≠ x → (f ^ n) x = x := ⟨fun h _ hx => (hf.pow_eq_one_iff' hx).1 h, fun h => let ⟨_, hx, _⟩ := id hf (hf.pow_eq_one_iff' hx).2 (h _ hx)⟩ -- TODO: Define a `Set`-valued support to get rid of the `Finite β` assumption theorem IsCycle.pow_eq_pow_iff [Finite β] {f : Perm β} (hf : IsCycle f) {a b : ℕ} : f ^ a = f ^ b ↔ ∃ x, f x ≠ x ∧ (f ^ a) x = (f ^ b) x := by classical cases nonempty_fintype β constructor · intro h obtain ⟨x, hx, -⟩ := id hf exact ⟨x, hx, by simp [h]⟩ · rintro ⟨x, hx, hx'⟩ wlog hab : a ≤ b generalizing a b · exact (this hx'.symm (le_of_not_le hab)).symm suffices f ^ (b - a) = 1 by rw [pow_sub _ hab, mul_inv_eq_one] at this rw [this] rw [hf.pow_eq_one_iff] by_cases hfa : (f ^ a) x ∈ f.support · refine ⟨(f ^ a) x, mem_support.mp hfa, ?_⟩ simp only [pow_sub _ hab, Equiv.Perm.coe_mul, Function.comp_apply, inv_apply_self, ← hx'] · have h := @Equiv.Perm.zpow_apply_comm _ f 1 a x simp only [zpow_one, zpow_natCast] at h rw [not_mem_support, h, Function.Injective.eq_iff (f ^ a).injective] at hfa contradiction theorem IsCycle.isCycle_pow_pos_of_lt_prime_order [Finite β] {f : Perm β} (hf : IsCycle f) (hf' : (orderOf f).Prime) (n : ℕ) (hn : 0 < n) (hn' : n < orderOf f) : IsCycle (f ^ n) := by classical cases nonempty_fintype β have : n.Coprime (orderOf f) := by refine Nat.Coprime.symm ?_ rw [Nat.Prime.coprime_iff_not_dvd hf'] exact Nat.not_dvd_of_pos_of_lt hn hn' obtain ⟨m, hm⟩ := exists_pow_eq_self_of_coprime this have hf'' := hf rw [← hm] at hf'' refine hf''.of_pow ?_ rw [hm] exact support_pow_le f n end IsCycle open Equiv theorem _root_.Int.addLeft_one_isCycle : (Equiv.addLeft 1 : Perm ℤ).IsCycle := ⟨0, one_ne_zero, fun n _ => ⟨n, by simp⟩⟩ theorem _root_.Int.addRight_one_isCycle : (Equiv.addRight 1 : Perm ℤ).IsCycle := ⟨0, one_ne_zero, fun n _ => ⟨n, by simp⟩⟩ section Conjugation variable [Fintype α] [DecidableEq α] {σ τ : Perm α} theorem IsCycle.isConj (hσ : IsCycle σ) (hτ : IsCycle τ) (h : σ.support.card = τ.support.card) : IsConj σ τ := by refine isConj_of_support_equiv (hσ.zpowersEquivSupport.symm.trans <| (zpowersEquivZPowers <| by rw [hσ.orderOf, h, hτ.orderOf]).trans hτ.zpowersEquivSupport) ?_ intro x hx simp only [Perm.mul_apply, Equiv.trans_apply, Equiv.sumCongr_apply] obtain ⟨n, rfl⟩ := hσ.exists_pow_eq (Classical.choose_spec hσ).1 (mem_support.1 hx) erw [hσ.zpowersEquivSupport_symm_apply n] simp only [← Perm.mul_apply, ← pow_succ'] erw [hσ.zpowersEquivSupport_symm_apply (n + 1)] -- This used to be a `simp only` before leanprover/lean4#2644 erw [zpowersEquivZPowers_apply, zpowersEquivZPowers_apply, zpowersEquivSupport_apply] -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 simp_rw [pow_succ', Perm.mul_apply] rfl theorem IsCycle.isConj_iff (hσ : IsCycle σ) (hτ : IsCycle τ) : IsConj σ τ ↔ σ.support.card = τ.support.card where mp h := by obtain ⟨π, rfl⟩ := (_root_.isConj_iff).1 h refine Finset.card_bij (fun a _ => π a) (fun _ ha => ?_) (fun _ _ _ _ ab => π.injective ab) fun b hb ↦ ⟨π⁻¹ b, ?_, π.apply_inv_self b⟩ · simp [mem_support.1 ha] contrapose! hb rw [mem_support, Classical.not_not] at hb rw [mem_support, Classical.not_not, Perm.mul_apply, Perm.mul_apply, hb, Perm.apply_inv_self] mpr := hσ.isConj hτ end Conjugation /-! ### `IsCycleOn` -/ section IsCycleOn variable {f g : Perm α} {s t : Set α} {a b x y : α} /-- A permutation is a cycle on `s` when any two points of `s` are related by repeated application of the permutation. Note that this means the identity is a cycle of subsingleton sets. -/ def IsCycleOn (f : Perm α) (s : Set α) : Prop := Set.BijOn f s s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → f.SameCycle x y @[simp] theorem isCycleOn_empty : f.IsCycleOn ∅ := by simp [IsCycleOn, Set.bijOn_empty] @[simp] theorem isCycleOn_one : (1 : Perm α).IsCycleOn s ↔ s.Subsingleton := by simp [IsCycleOn, Set.bijOn_id, Set.Subsingleton] alias ⟨IsCycleOn.subsingleton, _root_.Set.Subsingleton.isCycleOn_one⟩ := isCycleOn_one @[simp] theorem isCycleOn_singleton : f.IsCycleOn {a} ↔ f a = a := by simp [IsCycleOn, SameCycle.rfl] theorem isCycleOn_of_subsingleton [Subsingleton α] (f : Perm α) (s : Set α) : f.IsCycleOn s := ⟨s.bijOn_of_subsingleton _, fun x _ y _ => (Subsingleton.elim x y).sameCycle _⟩ @[simp] theorem isCycleOn_inv : f⁻¹.IsCycleOn s ↔ f.IsCycleOn s := by simp only [IsCycleOn, sameCycle_inv, and_congr_left_iff] exact fun _ ↦ ⟨fun h ↦ Set.BijOn.perm_inv h, fun h ↦ Set.BijOn.perm_inv h⟩ alias ⟨IsCycleOn.of_inv, IsCycleOn.inv⟩ := isCycleOn_inv theorem IsCycleOn.conj (h : f.IsCycleOn s) : (g * f * g⁻¹).IsCycleOn ((g : Perm α) '' s) := ⟨(g.bijOn_image.comp h.1).comp g.bijOn_symm_image, fun x hx y hy => by rw [← preimage_inv] at hx hy convert Equiv.Perm.SameCycle.conj (h.2 hx hy) (g := g) <;> rw [apply_inv_self]⟩ theorem isCycleOn_swap [DecidableEq α] (hab : a ≠ b) : (swap a b).IsCycleOn {a, b} := ⟨bijOn_swap (by simp) (by simp), fun x hx y hy => by rw [Set.mem_insert_iff, Set.mem_singleton_iff] at hx hy obtain rfl | rfl := hx <;> obtain rfl | rfl := hy · exact ⟨0, by rw [zpow_zero, coe_one, id]⟩ · exact ⟨1, by rw [zpow_one, swap_apply_left]⟩ · exact ⟨1, by rw [zpow_one, swap_apply_right]⟩ · exact ⟨0, by rw [zpow_zero, coe_one, id]⟩⟩ protected theorem IsCycleOn.apply_ne (hf : f.IsCycleOn s) (hs : s.Nontrivial) (ha : a ∈ s) : f a ≠ a := by obtain ⟨b, hb, hba⟩ := hs.exists_ne a obtain ⟨n, rfl⟩ := hf.2 ha hb exact fun h => hba (IsFixedPt.perm_zpow h n) protected theorem IsCycle.isCycleOn (hf : f.IsCycle) : f.IsCycleOn { x | f x ≠ x } := ⟨f.bijOn fun _ => f.apply_eq_iff_eq.not, fun _ ha _ => hf.sameCycle ha⟩ /-- This lemma demonstrates the relation between `Equiv.Perm.IsCycle` and `Equiv.Perm.IsCycleOn` in non-degenerate cases. -/ theorem isCycle_iff_exists_isCycleOn : f.IsCycle ↔ ∃ s : Set α, s.Nontrivial ∧ f.IsCycleOn s ∧ ∀ ⦃x⦄, ¬IsFixedPt f x → x ∈ s := by refine ⟨fun hf => ⟨{ x | f x ≠ x }, ?_, hf.isCycleOn, fun _ => id⟩, ?_⟩ · obtain ⟨a, ha⟩ := hf exact ⟨f a, f.injective.ne ha.1, a, ha.1, ha.1⟩ · rintro ⟨s, hs, hf, hsf⟩ obtain ⟨a, ha⟩ := hs.nonempty exact ⟨a, hf.apply_ne hs ha, fun b hb => hf.2 ha <| hsf hb⟩ theorem IsCycleOn.apply_mem_iff (hf : f.IsCycleOn s) : f x ∈ s ↔ x ∈ s := ⟨fun hx => by convert hf.1.perm_inv.1 hx rw [inv_apply_self], fun hx => hf.1.mapsTo hx⟩ /-- Note that the identity satisfies `IsCycleOn` for any subsingleton set, but not `IsCycle`. -/ theorem IsCycleOn.isCycle_subtypePerm (hf : f.IsCycleOn s) (hs : s.Nontrivial) : (f.subtypePerm fun _ => hf.apply_mem_iff.symm : Perm s).IsCycle := by obtain ⟨a, ha⟩ := hs.nonempty exact ⟨⟨a, ha⟩, ne_of_apply_ne ((↑) : s → α) (hf.apply_ne hs ha), fun b _ => (hf.2 (⟨a, ha⟩ : s).2 b.2).subtypePerm⟩ /-- Note that the identity is a cycle on any subsingleton set, but not a cycle. -/ protected theorem IsCycleOn.subtypePerm (hf : f.IsCycleOn s) : (f.subtypePerm fun _ => hf.apply_mem_iff.symm : Perm s).IsCycleOn _root_.Set.univ := by obtain hs | hs := s.subsingleton_or_nontrivial · haveI := hs.coe_sort exact isCycleOn_of_subsingleton _ _ convert (hf.isCycle_subtypePerm hs).isCycleOn rw [eq_comm, Set.eq_univ_iff_forall] exact fun x => ne_of_apply_ne ((↑) : s → α) (hf.apply_ne hs x.2) -- TODO: Theory of order of an element under an action theorem IsCycleOn.pow_apply_eq {s : Finset α} (hf : f.IsCycleOn s) (ha : a ∈ s) {n : ℕ} : (f ^ n) a = a ↔ s.card ∣ n := by obtain rfl | hs := Finset.eq_singleton_or_nontrivial ha · rw [coe_singleton, isCycleOn_singleton] at hf simpa using IsFixedPt.iterate hf n classical have h : ∀ x ∈ s.attach, ¬f ↑x = ↑x := fun x _ => hf.apply_ne hs x.2 have := (hf.isCycle_subtypePerm hs).orderOf simp only [coe_sort_coe, support_subtype_perm, ne_eq, decide_not, Bool.not_eq_true', decide_eq_false_iff_not, mem_attach, forall_true_left, Subtype.forall, filter_true_of_mem h, card_attach] at this rw [← this, orderOf_dvd_iff_pow_eq_one, (hf.isCycle_subtypePerm hs).pow_eq_one_iff' (ne_of_apply_ne ((↑) : s → α) <| hf.apply_ne hs (⟨a, ha⟩ : s).2)] simp -- This used to be the end of the proof before leanprover/lean4#2644 erw [subtypePerm_apply] simp theorem IsCycleOn.zpow_apply_eq {s : Finset α} (hf : f.IsCycleOn s) (ha : a ∈ s) : ∀ {n : ℤ}, (f ^ n) a = a ↔ (s.card : ℤ) ∣ n | Int.ofNat n => (hf.pow_apply_eq ha).trans Int.natCast_dvd_natCast.symm | Int.negSucc n => by rw [zpow_negSucc, ← inv_pow] exact (hf.inv.pow_apply_eq ha).trans (dvd_neg.trans Int.natCast_dvd_natCast).symm theorem IsCycleOn.pow_apply_eq_pow_apply {s : Finset α} (hf : f.IsCycleOn s) (ha : a ∈ s) {m n : ℕ} : (f ^ m) a = (f ^ n) a ↔ m ≡ n [MOD s.card] := by rw [Nat.modEq_iff_dvd, ← hf.zpow_apply_eq ha] simp [sub_eq_neg_add, zpow_add, eq_inv_iff_eq, eq_comm] theorem IsCycleOn.zpow_apply_eq_zpow_apply {s : Finset α} (hf : f.IsCycleOn s) (ha : a ∈ s) {m n : ℤ} : (f ^ m) a = (f ^ n) a ↔ m ≡ n [ZMOD s.card] := by rw [Int.modEq_iff_dvd, ← hf.zpow_apply_eq ha] simp [sub_eq_neg_add, zpow_add, eq_inv_iff_eq, eq_comm] theorem IsCycleOn.pow_card_apply {s : Finset α} (hf : f.IsCycleOn s) (ha : a ∈ s) : (f ^ s.card) a = a := (hf.pow_apply_eq ha).2 dvd_rfl theorem IsCycleOn.exists_pow_eq {s : Finset α} (hf : f.IsCycleOn s) (ha : a ∈ s) (hb : b ∈ s) : ∃ n < s.card, (f ^ n) a = b := by classical obtain ⟨n, rfl⟩ := hf.2 ha hb obtain ⟨k, hk⟩ := (Int.mod_modEq n s.card).symm.dvd refine ⟨n.natMod s.card, Int.natMod_lt (Nonempty.card_pos ⟨a, ha⟩).ne', ?_⟩ rw [← zpow_natCast, Int.natMod, Int.toNat_of_nonneg (Int.emod_nonneg _ <| Nat.cast_ne_zero.2 (Nonempty.card_pos ⟨a, ha⟩).ne'), sub_eq_iff_eq_add'.1 hk, zpow_add, zpow_mul] simp only [zpow_natCast, coe_mul, comp_apply, EmbeddingLike.apply_eq_iff_eq] exact IsFixedPt.perm_zpow (hf.pow_card_apply ha) _ theorem IsCycleOn.exists_pow_eq' (hs : s.Finite) (hf : f.IsCycleOn s) (ha : a ∈ s) (hb : b ∈ s) : ∃ n : ℕ, (f ^ n) a = b := by lift s to Finset α using id hs obtain ⟨n, -, hn⟩ := hf.exists_pow_eq ha hb exact ⟨n, hn⟩ theorem IsCycleOn.range_pow (hs : s.Finite) (h : f.IsCycleOn s) (ha : a ∈ s) : Set.range (fun n => (f ^ n) a : ℕ → α) = s := Set.Subset.antisymm (Set.range_subset_iff.2 fun _ => h.1.mapsTo.perm_pow _ ha) fun _ => h.exists_pow_eq' hs ha theorem IsCycleOn.range_zpow (h : f.IsCycleOn s) (ha : a ∈ s) : Set.range (fun n => (f ^ n) a : ℤ → α) = s := Set.Subset.antisymm (Set.range_subset_iff.2 fun _ => (h.1.perm_zpow _).mapsTo ha) <| h.2 ha theorem IsCycleOn.of_pow {n : ℕ} (hf : (f ^ n).IsCycleOn s) (h : Set.BijOn f s s) : f.IsCycleOn s := ⟨h, fun _ hx _ hy => (hf.2 hx hy).of_pow⟩ theorem IsCycleOn.of_zpow {n : ℤ} (hf : (f ^ n).IsCycleOn s) (h : Set.BijOn f s s) : f.IsCycleOn s := ⟨h, fun _ hx _ hy => (hf.2 hx hy).of_zpow⟩ theorem IsCycleOn.extendDomain {p : β → Prop} [DecidablePred p] (f : α ≃ Subtype p) (h : g.IsCycleOn s) : (g.extendDomain f).IsCycleOn ((↑) ∘ f '' s) := ⟨h.1.extendDomain, by rintro _ ⟨a, ha, rfl⟩ _ ⟨b, hb, rfl⟩ exact (h.2 ha hb).extendDomain⟩ protected theorem IsCycleOn.countable (hs : f.IsCycleOn s) : s.Countable := by obtain rfl | ⟨a, ha⟩ := s.eq_empty_or_nonempty · exact Set.countable_empty · exact (Set.countable_range fun n : ℤ => (⇑(f ^ n) : α → α) a).mono (hs.2 ha) end IsCycleOn end Equiv.Perm namespace List section variable [DecidableEq α] {l : List α} theorem Nodup.isCycleOn_formPerm (h : l.Nodup) : l.formPerm.IsCycleOn { a | a ∈ l } := by refine ⟨l.formPerm.bijOn fun _ => List.formPerm_mem_iff_mem, fun a ha b hb => ?_⟩ rw [Set.mem_setOf, ← List.indexOf_lt_length] at ha hb rw [← List.getElem_indexOf ha, ← List.getElem_indexOf hb] refine ⟨l.indexOf b - l.indexOf a, ?_⟩ simp only [sub_eq_neg_add, zpow_add, zpow_neg, Equiv.Perm.inv_eq_iff_eq, zpow_natCast, Equiv.Perm.coe_mul, List.formPerm_pow_apply_getElem _ h, Function.comp] rw [add_comm] end end List namespace Finset variable [DecidableEq α] [Fintype α] theorem exists_cycleOn (s : Finset α) : ∃ f : Perm α, f.IsCycleOn s ∧ f.support ⊆ s := by refine ⟨s.toList.formPerm, ?_, fun x hx => by simpa using List.mem_of_formPerm_apply_ne (Perm.mem_support.1 hx)⟩ convert s.nodup_toList.isCycleOn_formPerm simp end Finset namespace Set variable {f : Perm α} {s : Set α} theorem Countable.exists_cycleOn (hs : s.Countable) : ∃ f : Perm α, f.IsCycleOn s ∧ { x | f x ≠ x } ⊆ s := by classical obtain hs' | hs' := s.finite_or_infinite · refine ⟨hs'.toFinset.toList.formPerm, ?_, fun x hx => by simpa using List.mem_of_formPerm_apply_ne hx⟩ convert hs'.toFinset.nodup_toList.isCycleOn_formPerm simp · haveI := hs.to_subtype haveI := hs'.to_subtype obtain ⟨f⟩ : Nonempty (ℤ ≃ s) := inferInstance refine ⟨(Equiv.addRight 1).extendDomain f, ?_, fun x hx => of_not_not fun h => hx <| Perm.extendDomain_apply_not_subtype _ _ h⟩ convert Int.addRight_one_isCycle.isCycleOn.extendDomain f rw [Set.image_comp, Equiv.image_eq_preimage] ext simp theorem prod_self_eq_iUnion_perm (hf : f.IsCycleOn s) : s ×ˢ s = ⋃ n : ℤ, (fun a => (a, (f ^ n) a)) '' s := by ext ⟨a, b⟩ simp only [Set.mem_prod, Set.mem_iUnion, Set.mem_image] refine ⟨fun hx => ?_, ?_⟩ · obtain ⟨n, rfl⟩ := hf.2 hx.1 hx.2 exact ⟨_, _, hx.1, rfl⟩ · rintro ⟨n, a, ha, ⟨⟩⟩ exact ⟨ha, (hf.1.perm_zpow _).mapsTo ha⟩ end Set namespace Finset variable {f : Perm α} {s : Finset α} theorem product_self_eq_disjiUnion_perm_aux (hf : f.IsCycleOn s) : (range s.card : Set ℕ).PairwiseDisjoint fun k => s.map ⟨fun i => (i, (f ^ k) i), fun i j => congr_arg Prod.fst⟩ := by obtain hs | _ := (s : Set α).subsingleton_or_nontrivial · refine Set.Subsingleton.pairwise ?_ _ simp_rw [Set.Subsingleton, mem_coe, ← card_le_one] at hs ⊢ rwa [card_range] classical rintro m hm n hn hmn simp only [disjoint_left, Function.onFun, mem_map, Function.Embedding.coeFn_mk, exists_prop, not_exists, not_and, forall_exists_index, and_imp, Prod.forall, Prod.mk.inj_iff] rintro _ _ _ - rfl rfl a ha rfl h rw [hf.pow_apply_eq_pow_apply ha] at h rw [mem_coe, mem_range] at hm hn exact hmn.symm (h.eq_of_lt_of_lt hn hm) /-- We can partition the square `s ×ˢ s` into shifted diagonals as such: ``` 01234 40123 34012 23401 12340 ``` The diagonals are given by the cycle `f`. -/ theorem product_self_eq_disjiUnion_perm (hf : f.IsCycleOn s) : s ×ˢ s = (range s.card).disjiUnion (fun k => s.map ⟨fun i => (i, (f ^ k) i), fun i j => congr_arg Prod.fst⟩) (product_self_eq_disjiUnion_perm_aux hf) := by ext ⟨a, b⟩ simp only [mem_product, Equiv.Perm.coe_pow, mem_disjiUnion, mem_range, mem_map, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, exists_prop] refine ⟨fun hx => ?_, ?_⟩ · obtain ⟨n, hn, rfl⟩ := hf.exists_pow_eq hx.1 hx.2 exact ⟨n, hn, a, hx.1, rfl, by rw [f.iterate_eq_pow]⟩ · rintro ⟨n, -, a, ha, rfl, rfl⟩ exact ⟨ha, (hf.1.iterate _).mapsTo ha⟩ end Finset namespace Finset variable [Semiring α] [AddCommMonoid β] [Module α β] {s : Finset ι} {σ : Perm ι} theorem sum_smul_sum_eq_sum_perm (hσ : σ.IsCycleOn s) (f : ι → α) (g : ι → β) : (∑ i ∈ s, f i) • ∑ i ∈ s, g i = ∑ k ∈ range s.card, ∑ i ∈ s, f i • g ((σ ^ k) i) := by rw [sum_smul_sum, ← sum_product'] simp_rw [product_self_eq_disjiUnion_perm hσ, sum_disjiUnion, sum_map, Embedding.coeFn_mk] theorem sum_mul_sum_eq_sum_perm (hσ : σ.IsCycleOn s) (f g : ι → α) : ((∑ i ∈ s, f i) * ∑ i ∈ s, g i) = ∑ k ∈ range s.card, ∑ i ∈ s, f i * g ((σ ^ k) i) := sum_smul_sum_eq_sum_perm hσ f g end Finset
GroupTheory\Perm\Cycle\Concrete.lean
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Data.List.Cycle import Mathlib.GroupTheory.Perm.Cycle.Type import Mathlib.GroupTheory.Perm.List /-! # Properties of cyclic permutations constructed from lists/cycles In the following, `{α : Type*} [Fintype α] [DecidableEq α]`. ## Main definitions * `Cycle.formPerm`: the cyclic permutation created by looping over a `Cycle α` * `Equiv.Perm.toList`: the list formed by iterating application of a permutation * `Equiv.Perm.toCycle`: the cycle formed by iterating application of a permutation * `Equiv.Perm.isoCycle`: the equivalence between cyclic permutations `f : Perm α` and the terms of `Cycle α` that correspond to them * `Equiv.Perm.isoCycle'`: the same equivalence as `Equiv.Perm.isoCycle` but with evaluation via choosing over fintypes * The notation `c[1, 2, 3]` to emulate notation of cyclic permutations `(1 2 3)` * A `Repr` instance for any `Perm α`, by representing the `Finset` of `Cycle α` that correspond to the cycle factors. ## Main results * `List.isCycle_formPerm`: a nontrivial list without duplicates, when interpreted as a permutation, is cyclic * `Equiv.Perm.IsCycle.existsUnique_cycle`: there is only one nontrivial `Cycle α` corresponding to each cyclic `f : Perm α` ## Implementation details The forward direction of `Equiv.Perm.isoCycle'` uses `Fintype.choose` of the uniqueness result, relying on the `Fintype` instance of a `Cycle.nodup` subtype. It is unclear if this works faster than the `Equiv.Perm.toCycle`, which relies on recursion over `Finset.univ`. Running `#eval` on even a simple noncyclic permutation `c[(1 : Fin 7), 2, 3] * c[0, 5]` to show it takes a long time. TODO: is this because computing the cycle factors is slow? -/ open Equiv Equiv.Perm List variable {α : Type*} namespace List variable [DecidableEq α] {l l' : List α} theorem formPerm_disjoint_iff (hl : Nodup l) (hl' : Nodup l') (hn : 2 ≤ l.length) (hn' : 2 ≤ l'.length) : Perm.Disjoint (formPerm l) (formPerm l') ↔ l.Disjoint l' := by rw [disjoint_iff_eq_or_eq, List.Disjoint] constructor · rintro h x hx hx' specialize h x rw [formPerm_apply_mem_eq_self_iff _ hl _ hx, formPerm_apply_mem_eq_self_iff _ hl' _ hx'] at h omega · intro h x by_cases hx : x ∈ l on_goal 1 => by_cases hx' : x ∈ l' · exact (h hx hx').elim all_goals have := formPerm_eq_self_of_not_mem _ _ ‹_›; tauto theorem isCycle_formPerm (hl : Nodup l) (hn : 2 ≤ l.length) : IsCycle (formPerm l) := by cases' l with x l · norm_num at hn induction' l with y l generalizing x · norm_num at hn · use x constructor · rwa [formPerm_apply_mem_ne_self_iff _ hl _ (mem_cons_self _ _)] · intro w hw have : w ∈ x::y::l := mem_of_formPerm_ne_self _ _ hw obtain ⟨k, hk, rfl⟩ := getElem_of_mem this use k simp only [zpow_natCast, formPerm_pow_apply_head _ _ hl k, Nat.mod_eq_of_lt hk] theorem pairwise_sameCycle_formPerm (hl : Nodup l) (hn : 2 ≤ l.length) : Pairwise l.formPerm.SameCycle l := Pairwise.imp_mem.mpr (pairwise_of_forall fun _ _ hx hy => (isCycle_formPerm hl hn).sameCycle ((formPerm_apply_mem_ne_self_iff _ hl _ hx).mpr hn) ((formPerm_apply_mem_ne_self_iff _ hl _ hy).mpr hn)) theorem cycleOf_formPerm (hl : Nodup l) (hn : 2 ≤ l.length) (x) : cycleOf l.attach.formPerm x = l.attach.formPerm := have hn : 2 ≤ l.attach.length := by rwa [← length_attach] at hn have hl : l.attach.Nodup := by rwa [← nodup_attach] at hl (isCycle_formPerm hl hn).cycleOf_eq ((formPerm_apply_mem_ne_self_iff _ hl _ (mem_attach _ _)).mpr hn) theorem cycleType_formPerm (hl : Nodup l) (hn : 2 ≤ l.length) : cycleType l.attach.formPerm = {l.length} := by rw [← length_attach] at hn rw [← nodup_attach] at hl rw [cycleType_eq [l.attach.formPerm]] · simp only [map, Function.comp_apply] rw [support_formPerm_of_nodup _ hl, card_toFinset, dedup_eq_self.mpr hl] · simp · intro x h simp [h, Nat.succ_le_succ_iff] at hn · simp · simpa using isCycle_formPerm hl hn · simp set_option linter.deprecated false in theorem formPerm_apply_mem_eq_next (hl : Nodup l) (x : α) (hx : x ∈ l) : formPerm l x = next l x hx := by obtain ⟨k, rfl⟩ := get_of_mem hx rw [next_get _ hl, formPerm_apply_get _ hl] end List namespace Cycle variable [DecidableEq α] (s s' : Cycle α) /-- A cycle `s : Cycle α`, given `Nodup s` can be interpreted as an `Equiv.Perm α` where each element in the list is permuted to the next one, defined as `formPerm`. -/ def formPerm : ∀ s : Cycle α, Nodup s → Equiv.Perm α := fun s => Quotient.hrecOn s (fun l _ => List.formPerm l) fun l₁ l₂ (h : l₁ ~r l₂) => by apply Function.hfunext · ext exact h.nodup_iff · intro h₁ h₂ _ exact heq_of_eq (formPerm_eq_of_isRotated h₁ h) @[simp] theorem formPerm_coe (l : List α) (hl : l.Nodup) : formPerm (l : Cycle α) hl = l.formPerm := rfl theorem formPerm_subsingleton (s : Cycle α) (h : Subsingleton s) : formPerm s h.nodup = 1 := by induction' s using Quot.inductionOn with s simp only [formPerm_coe, mk_eq_coe] simp only [length_subsingleton_iff, length_coe, mk_eq_coe] at h cases' s with hd tl · simp · simp only [length_eq_zero, add_le_iff_nonpos_left, List.length, nonpos_iff_eq_zero] at h simp [h] theorem isCycle_formPerm (s : Cycle α) (h : Nodup s) (hn : Nontrivial s) : IsCycle (formPerm s h) := by induction s using Quot.inductionOn exact List.isCycle_formPerm h (length_nontrivial hn) theorem support_formPerm [Fintype α] (s : Cycle α) (h : Nodup s) (hn : Nontrivial s) : support (formPerm s h) = s.toFinset := by induction' s using Quot.inductionOn with s refine support_formPerm_of_nodup s h ?_ rintro _ rfl simpa [Nat.succ_le_succ_iff] using length_nontrivial hn theorem formPerm_eq_self_of_not_mem (s : Cycle α) (h : Nodup s) (x : α) (hx : x ∉ s) : formPerm s h x = x := by induction s using Quot.inductionOn simpa using List.formPerm_eq_self_of_not_mem _ _ hx theorem formPerm_apply_mem_eq_next (s : Cycle α) (h : Nodup s) (x : α) (hx : x ∈ s) : formPerm s h x = next s h x hx := by induction s using Quot.inductionOn simpa using List.formPerm_apply_mem_eq_next h _ (by simp_all) nonrec theorem formPerm_reverse (s : Cycle α) (h : Nodup s) : formPerm s.reverse (nodup_reverse_iff.mpr h) = (formPerm s h)⁻¹ := by induction s using Quot.inductionOn simpa using formPerm_reverse _ nonrec theorem formPerm_eq_formPerm_iff {α : Type*} [DecidableEq α] {s s' : Cycle α} {hs : s.Nodup} {hs' : s'.Nodup} : s.formPerm hs = s'.formPerm hs' ↔ s = s' ∨ s.Subsingleton ∧ s'.Subsingleton := by rw [Cycle.length_subsingleton_iff, Cycle.length_subsingleton_iff] revert s s' intro s s' apply @Quotient.inductionOn₂' _ _ _ _ _ s s' intro l l' hl hl' simpa using formPerm_eq_formPerm_iff hl hl' end Cycle namespace Equiv.Perm section Fintype variable [Fintype α] [DecidableEq α] (p : Equiv.Perm α) (x : α) /-- `Equiv.Perm.toList (f : Perm α) (x : α)` generates the list `[x, f x, f (f x), ...]` until looping. That means when `f x = x`, `toList f x = []`. -/ def toList : List α := (List.range (cycleOf p x).support.card).map fun k => (p ^ k) x @[simp] theorem toList_one : toList (1 : Perm α) x = [] := by simp [toList, cycleOf_one] @[simp] theorem toList_eq_nil_iff {p : Perm α} {x} : toList p x = [] ↔ x ∉ p.support := by simp [toList] @[simp] theorem length_toList : length (toList p x) = (cycleOf p x).support.card := by simp [toList] theorem toList_ne_singleton (y : α) : toList p x ≠ [y] := by intro H simpa [card_support_ne_one] using congr_arg length H theorem two_le_length_toList_iff_mem_support {p : Perm α} {x : α} : 2 ≤ length (toList p x) ↔ x ∈ p.support := by simp theorem length_toList_pos_of_mem_support (h : x ∈ p.support) : 0 < length (toList p x) := zero_lt_two.trans_le (two_le_length_toList_iff_mem_support.mpr h) theorem get_toList (n : ℕ) (hn : n < length (toList p x)) : (toList p x).get ⟨n, hn⟩ = (p ^ n) x := by simp [toList] theorem toList_get_zero (h : x ∈ p.support) : (toList p x).get ⟨0, (length_toList_pos_of_mem_support _ _ h)⟩ = x := by simp [toList] set_option linter.deprecated false in @[deprecated get_toList (since := "2024-05-08")] theorem nthLe_toList (n : ℕ) (hn : n < length (toList p x)) : (toList p x).nthLe n hn = (p ^ n) x := by simp [toList] set_option linter.deprecated false in @[deprecated toList_get_zero (since := "2024-05-08")] theorem toList_nthLe_zero (h : x ∈ p.support) : (toList p x).nthLe 0 (length_toList_pos_of_mem_support _ _ h) = x := by simp [toList] variable {p} {x} theorem mem_toList_iff {y : α} : y ∈ toList p x ↔ SameCycle p x y ∧ x ∈ p.support := by simp only [toList, mem_range, mem_map] constructor · rintro ⟨n, hx, rfl⟩ refine ⟨⟨n, rfl⟩, ?_⟩ contrapose! hx rw [← support_cycleOf_eq_nil_iff] at hx simp [hx] · rintro ⟨h, hx⟩ simpa using h.exists_pow_eq_of_mem_support hx set_option linter.deprecated false in theorem nodup_toList (p : Perm α) (x : α) : Nodup (toList p x) := by by_cases hx : p x = x · rw [← not_mem_support, ← toList_eq_nil_iff] at hx simp [hx] have hc : IsCycle (cycleOf p x) := isCycle_cycleOf p hx rw [nodup_iff_nthLe_inj] rintro n m hn hm rw [length_toList, ← hc.orderOf] at hm hn rw [← cycleOf_apply_self, ← Ne, ← mem_support] at hx rw [nthLe_toList, nthLe_toList, ← cycleOf_pow_apply_self p x n, ← cycleOf_pow_apply_self p x m] cases' n with n <;> cases' m with m · simp · rw [← hc.support_pow_of_pos_of_lt_orderOf m.zero_lt_succ hm, mem_support, cycleOf_pow_apply_self] at hx simp [hx.symm] · rw [← hc.support_pow_of_pos_of_lt_orderOf n.zero_lt_succ hn, mem_support, cycleOf_pow_apply_self] at hx simp [hx] intro h have hn' : ¬orderOf (p.cycleOf x) ∣ n.succ := Nat.not_dvd_of_pos_of_lt n.zero_lt_succ hn have hm' : ¬orderOf (p.cycleOf x) ∣ m.succ := Nat.not_dvd_of_pos_of_lt m.zero_lt_succ hm rw [← hc.support_pow_eq_iff] at hn' hm' rw [← Nat.mod_eq_of_lt hn, ← Nat.mod_eq_of_lt hm, ← pow_inj_mod] refine support_congr ?_ ?_ · rw [hm', hn'] · rw [hm'] intro y hy obtain ⟨k, rfl⟩ := hc.exists_pow_eq (mem_support.mp hx) (mem_support.mp hy) rw [← mul_apply, (Commute.pow_pow_self _ _ _).eq, mul_apply, h, ← mul_apply, ← mul_apply, (Commute.pow_pow_self _ _ _).eq] set_option linter.deprecated false in theorem next_toList_eq_apply (p : Perm α) (x y : α) (hy : y ∈ toList p x) : next (toList p x) y hy = p y := by rw [mem_toList_iff] at hy obtain ⟨k, hk, hk'⟩ := hy.left.exists_pow_eq_of_mem_support hy.right rw [← nthLe_toList p x k (by simpa using hk)] at hk' simp_rw [← hk'] rw [next_nthLe _ (nodup_toList _ _), nthLe_toList, nthLe_toList, ← mul_apply, ← pow_succ', length_toList, ← pow_mod_orderOf_cycleOf_apply p (k + 1), IsCycle.orderOf] exact isCycle_cycleOf _ (mem_support.mp hy.right) set_option linter.deprecated false in theorem toList_pow_apply_eq_rotate (p : Perm α) (x : α) (k : ℕ) : p.toList ((p ^ k) x) = (p.toList x).rotate k := by apply ext_nthLe · simp only [length_toList, cycleOf_self_apply_pow, length_rotate] · intro n hn hn' rw [nthLe_toList, nthLe_rotate, nthLe_toList, length_toList, pow_mod_card_support_cycleOf_self_apply, pow_add, mul_apply] theorem SameCycle.toList_isRotated {f : Perm α} {x y : α} (h : SameCycle f x y) : toList f x ~r toList f y := by by_cases hx : x ∈ f.support · obtain ⟨_ | k, _, hy⟩ := h.exists_pow_eq_of_mem_support hx · simp only [coe_one, id, pow_zero, Nat.zero_eq] at hy -- Porting note: added `IsRotated.refl` simp [hy, IsRotated.refl] use k.succ rw [← toList_pow_apply_eq_rotate, hy] · rw [toList_eq_nil_iff.mpr hx, isRotated_nil_iff', eq_comm, toList_eq_nil_iff] rwa [← h.mem_support_iff] theorem pow_apply_mem_toList_iff_mem_support {n : ℕ} : (p ^ n) x ∈ p.toList x ↔ x ∈ p.support := by rw [mem_toList_iff, and_iff_right_iff_imp] refine fun _ => SameCycle.symm ?_ rw [sameCycle_pow_left] theorem toList_formPerm_nil (x : α) : toList (formPerm ([] : List α)) x = [] := by simp theorem toList_formPerm_singleton (x y : α) : toList (formPerm [x]) y = [] := by simp theorem toList_formPerm_nontrivial (l : List α) (hl : 2 ≤ l.length) (hn : Nodup l) : toList (formPerm l) (l.get ⟨0, (zero_lt_two.trans_le hl)⟩) = l := by have hc : l.formPerm.IsCycle := List.isCycle_formPerm hn hl have hs : l.formPerm.support = l.toFinset := by refine support_formPerm_of_nodup _ hn ?_ rintro _ rfl simp [Nat.succ_le_succ_iff] at hl rw [toList, hc.cycleOf_eq (mem_support.mp _), hs, card_toFinset, dedup_eq_self.mpr hn] · refine ext_getElem (by simp) fun k hk hk' => ?_ simp only [get_eq_getElem, formPerm_pow_apply_getElem _ hn, zero_add, getElem_map, getElem_range, Nat.mod_eq_of_lt hk'] · simpa [hs] using get_mem _ _ _ theorem toList_formPerm_isRotated_self (l : List α) (hl : 2 ≤ l.length) (hn : Nodup l) (x : α) (hx : x ∈ l) : toList (formPerm l) x ~r l := by obtain ⟨k, hk, rfl⟩ := get_of_mem hx have hr : l ~r l.rotate k := ⟨k, rfl⟩ rw [formPerm_eq_of_isRotated hn hr] rw [get_eq_get_rotate l k k] simp only [Nat.mod_eq_of_lt k.2, tsub_add_cancel_of_le (le_of_lt k.2), Nat.mod_self] erw [toList_formPerm_nontrivial] · simp · simpa using hl · simpa using hn theorem formPerm_toList (f : Perm α) (x : α) : formPerm (toList f x) = f.cycleOf x := by by_cases hx : f x = x · rw [(cycleOf_eq_one_iff f).mpr hx, toList_eq_nil_iff.mpr (not_mem_support.mpr hx), formPerm_nil] ext y by_cases hy : SameCycle f x y · obtain ⟨k, _, rfl⟩ := hy.exists_pow_eq_of_mem_support (mem_support.mpr hx) rw [cycleOf_apply_apply_pow_self, List.formPerm_apply_mem_eq_next (nodup_toList f x), next_toList_eq_apply, pow_succ', mul_apply] rw [mem_toList_iff] exact ⟨⟨k, rfl⟩, mem_support.mpr hx⟩ · rw [cycleOf_apply_of_not_sameCycle hy, formPerm_apply_of_not_mem] simp [mem_toList_iff, hy] /-- Given a cyclic `f : Perm α`, generate the `Cycle α` in the order of application of `f`. Implemented by finding an element `x : α` in the support of `f` in `Finset.univ`, and iterating on using `Equiv.Perm.toList f x`. -/ def toCycle (f : Perm α) (hf : IsCycle f) : Cycle α := Multiset.recOn (Finset.univ : Finset α).val (Quot.mk _ []) (fun x _ l => if f x = x then l else toList f x) (by intro x y _ s refine heq_of_eq ?_ split_ifs with hx hy hy <;> try rfl have hc : SameCycle f x y := IsCycle.sameCycle hf hx hy exact Quotient.sound' hc.toList_isRotated) theorem toCycle_eq_toList (f : Perm α) (hf : IsCycle f) (x : α) (hx : f x ≠ x) : toCycle f hf = toList f x := by have key : (Finset.univ : Finset α).val = x ::ₘ Finset.univ.val.erase x := by simp rw [toCycle, key] simp [hx] theorem nodup_toCycle (f : Perm α) (hf : IsCycle f) : (toCycle f hf).Nodup := by obtain ⟨x, hx, -⟩ := id hf simpa [toCycle_eq_toList f hf x hx] using nodup_toList _ _ theorem nontrivial_toCycle (f : Perm α) (hf : IsCycle f) : (toCycle f hf).Nontrivial := by obtain ⟨x, hx, -⟩ := id hf simp [toCycle_eq_toList f hf x hx, hx, Cycle.nontrivial_coe_nodup_iff (nodup_toList _ _)] /-- Any cyclic `f : Perm α` is isomorphic to the nontrivial `Cycle α` that corresponds to repeated application of `f`. The forward direction is implemented by `Equiv.Perm.toCycle`. -/ def isoCycle : { f : Perm α // IsCycle f } ≃ { s : Cycle α // s.Nodup ∧ s.Nontrivial } where toFun f := ⟨toCycle (f : Perm α) f.prop, nodup_toCycle f f.prop, nontrivial_toCycle _ f.prop⟩ invFun s := ⟨(s : Cycle α).formPerm s.prop.left, (s : Cycle α).isCycle_formPerm _ s.prop.right⟩ left_inv f := by obtain ⟨x, hx, -⟩ := id f.prop simpa [toCycle_eq_toList (f : Perm α) f.prop x hx, formPerm_toList, Subtype.ext_iff] using f.prop.cycleOf_eq hx right_inv s := by rcases s with ⟨⟨s⟩, hn, ht⟩ obtain ⟨x, -, -, hx, -⟩ := id ht have hl : 2 ≤ s.length := by simpa using Cycle.length_nontrivial ht simp only [Cycle.mk_eq_coe, Cycle.nodup_coe_iff, Cycle.mem_coe_iff, Subtype.coe_mk, Cycle.formPerm_coe] at hn hx ⊢ apply Subtype.ext dsimp rw [toCycle_eq_toList _ _ x] · refine Quotient.sound' ?_ exact toList_formPerm_isRotated_self _ hl hn _ hx · rw [← mem_support, support_formPerm_of_nodup _ hn] · simpa using hx · rintro _ rfl simp [Nat.succ_le_succ_iff] at hl end Fintype section Finite variable [Finite α] [DecidableEq α] theorem IsCycle.existsUnique_cycle {f : Perm α} (hf : IsCycle f) : ∃! s : Cycle α, ∃ h : s.Nodup, s.formPerm h = f := by cases nonempty_fintype α obtain ⟨x, hx, hy⟩ := id hf refine ⟨f.toList x, ⟨nodup_toList f x, ?_⟩, ?_⟩ · simp [formPerm_toList, hf.cycleOf_eq hx] · rintro ⟨l⟩ ⟨hn, rfl⟩ simp only [Cycle.mk_eq_coe, Cycle.coe_eq_coe, Subtype.coe_mk, Cycle.formPerm_coe] refine (toList_formPerm_isRotated_self _ ?_ hn _ ?_).symm · contrapose! hx suffices formPerm l = 1 by simp [this] rw [formPerm_eq_one_iff _ hn] exact Nat.le_of_lt_succ hx · rw [← mem_toFinset] refine support_formPerm_le l ?_ simpa using hx theorem IsCycle.existsUnique_cycle_subtype {f : Perm α} (hf : IsCycle f) : ∃! s : { s : Cycle α // s.Nodup }, (s : Cycle α).formPerm s.prop = f := by obtain ⟨s, ⟨hs, rfl⟩, hs'⟩ := hf.existsUnique_cycle refine ⟨⟨s, hs⟩, rfl, ?_⟩ rintro ⟨t, ht⟩ ht' simpa using hs' _ ⟨ht, ht'⟩ theorem IsCycle.existsUnique_cycle_nontrivial_subtype {f : Perm α} (hf : IsCycle f) : ∃! s : { s : Cycle α // s.Nodup ∧ s.Nontrivial }, (s : Cycle α).formPerm s.prop.left = f := by obtain ⟨⟨s, hn⟩, hs, hs'⟩ := hf.existsUnique_cycle_subtype refine ⟨⟨s, hn, ?_⟩, ?_, ?_⟩ · rw [hn.nontrivial_iff] subst f intro H refine hf.ne_one ?_ simpa using Cycle.formPerm_subsingleton _ H · simpa using hs · rintro ⟨t, ht, ht'⟩ ht'' simpa using hs' ⟨t, ht⟩ ht'' end Finite variable [Fintype α] [DecidableEq α] /-- Any cyclic `f : Perm α` is isomorphic to the nontrivial `Cycle α` that corresponds to repeated application of `f`. The forward direction is implemented by finding this `Cycle α` using `Fintype.choose`. -/ def isoCycle' : { f : Perm α // IsCycle f } ≃ { s : Cycle α // s.Nodup ∧ s.Nontrivial } := let f : { s : Cycle α // s.Nodup ∧ s.Nontrivial } → { f : Perm α // IsCycle f } := fun s => ⟨(s : Cycle α).formPerm s.prop.left, (s : Cycle α).isCycle_formPerm _ s.prop.right⟩ { toFun := Fintype.bijInv (show Function.Bijective f by rw [Function.bijective_iff_existsUnique] rintro ⟨f, hf⟩ simp only [Subtype.ext_iff] exact hf.existsUnique_cycle_nontrivial_subtype) invFun := f left_inv := Fintype.rightInverse_bijInv _ right_inv := Fintype.leftInverse_bijInv _ } -- mutes `'decide' tactic does nothing [linter.unusedTactic]` set_option linter.unusedTactic false in notation3 (prettyPrint := false) "c["(l", "* => foldr (h t => List.cons h t) List.nil)"]" => Cycle.formPerm (Cycle.ofList l) (Iff.mpr Cycle.nodup_coe_iff (by decide)) unsafe instance repr_perm [Repr α] : Repr (Perm α) := ⟨fun f _ => repr (Multiset.pmap (fun (g : Perm α) (hg : g.IsCycle) => isoCycle ⟨g, hg⟩) (Perm.cycleFactorsFinset f).val -- toCycle is faster? fun _ hg => (mem_cycleFactorsFinset_iff.mp (Finset.mem_def.mpr hg)).left)⟩ end Equiv.Perm
GroupTheory\Perm\Cycle\Factors.lean
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Yaël Dillies -/ import Mathlib.Algebra.Module.BigOperators import Mathlib.Data.Finset.NoncommProd import Mathlib.Data.Fintype.Perm import Mathlib.Data.Int.ModEq import Mathlib.GroupTheory.Perm.List import Mathlib.GroupTheory.Perm.Sign import Mathlib.Logic.Equiv.Fintype import Mathlib.GroupTheory.Perm.Cycle.Basic /-! # Cycle factors of a permutation Let `β` be a `Fintype` and `f : Equiv.Perm β`. * `Equiv.Perm.cycleOf`: `f.cycleOf x` is the cycle of `f` that `x` belongs to. * `Equiv.Perm.cycleFactors`: `f.cycleFactors` is a list of disjoint cyclic permutations that multiply to `f`. -/ open Equiv Function Finset variable {ι α β : Type*} namespace Equiv.Perm /-! ### `cycleOf` -/ section CycleOf variable {f g : Perm α} {x y : α} /-- `f.cycleOf x` is the cycle of the permutation `f` to which `x` belongs. -/ def cycleOf (f : Perm α) [DecidableRel f.SameCycle] (x : α) : Perm α := ofSubtype (subtypePerm f fun _ => sameCycle_apply_right.symm : Perm { y // SameCycle f x y }) theorem cycleOf_apply (f : Perm α) [DecidableRel f.SameCycle] (x y : α) : cycleOf f x y = if SameCycle f x y then f y else y := by dsimp only [cycleOf] split_ifs with h · apply ofSubtype_apply_of_mem exact h · apply ofSubtype_apply_of_not_mem exact h theorem cycleOf_inv (f : Perm α) [DecidableRel f.SameCycle] (x : α) : (cycleOf f x)⁻¹ = cycleOf f⁻¹ x := Equiv.ext fun y => by rw [inv_eq_iff_eq, cycleOf_apply, cycleOf_apply] split_ifs <;> simp_all [sameCycle_inv, sameCycle_inv_apply_right] @[simp] theorem cycleOf_pow_apply_self (f : Perm α) [DecidableRel f.SameCycle] (x : α) : ∀ n : ℕ, (cycleOf f x ^ n) x = (f ^ n) x := by intro n induction' n with n hn · rfl · rw [pow_succ', mul_apply, cycleOf_apply, hn, if_pos, pow_succ', mul_apply] exact ⟨n, rfl⟩ @[simp] theorem cycleOf_zpow_apply_self (f : Perm α) [DecidableRel f.SameCycle] (x : α) : ∀ n : ℤ, (cycleOf f x ^ n) x = (f ^ n) x := by intro z induction' z with z hz · exact cycleOf_pow_apply_self f x z · rw [zpow_negSucc, ← inv_pow, cycleOf_inv, zpow_negSucc, ← inv_pow, cycleOf_pow_apply_self] theorem SameCycle.cycleOf_apply [DecidableRel f.SameCycle] : SameCycle f x y → cycleOf f x y = f y := ofSubtype_apply_of_mem _ theorem cycleOf_apply_of_not_sameCycle [DecidableRel f.SameCycle] : ¬SameCycle f x y → cycleOf f x y = y := ofSubtype_apply_of_not_mem _ theorem SameCycle.cycleOf_eq [DecidableRel f.SameCycle] (h : SameCycle f x y) : cycleOf f x = cycleOf f y := by ext z rw [Equiv.Perm.cycleOf_apply] split_ifs with hz · exact (h.symm.trans hz).cycleOf_apply.symm · exact (cycleOf_apply_of_not_sameCycle (mt h.trans hz)).symm @[simp] theorem cycleOf_apply_apply_zpow_self (f : Perm α) [DecidableRel f.SameCycle] (x : α) (k : ℤ) : cycleOf f x ((f ^ k) x) = (f ^ (k + 1) : Perm α) x := by rw [SameCycle.cycleOf_apply] · rw [add_comm, zpow_add, zpow_one, mul_apply] · exact ⟨k, rfl⟩ @[simp] theorem cycleOf_apply_apply_pow_self (f : Perm α) [DecidableRel f.SameCycle] (x : α) (k : ℕ) : cycleOf f x ((f ^ k) x) = (f ^ (k + 1) : Perm α) x := by convert cycleOf_apply_apply_zpow_self f x k using 1 @[simp] theorem cycleOf_apply_apply_self (f : Perm α) [DecidableRel f.SameCycle] (x : α) : cycleOf f x (f x) = f (f x) := by convert cycleOf_apply_apply_pow_self f x 1 using 1 @[simp] theorem cycleOf_apply_self (f : Perm α) [DecidableRel f.SameCycle] (x : α) : cycleOf f x x = f x := SameCycle.rfl.cycleOf_apply theorem IsCycle.cycleOf_eq [DecidableRel f.SameCycle] (hf : IsCycle f) (hx : f x ≠ x) : cycleOf f x = f := Equiv.ext fun y => if h : SameCycle f x y then by rw [h.cycleOf_apply] else by rw [cycleOf_apply_of_not_sameCycle h, Classical.not_not.1 (mt ((isCycle_iff_sameCycle hx).1 hf).2 h)] @[simp] theorem cycleOf_eq_one_iff (f : Perm α) [DecidableRel f.SameCycle] : cycleOf f x = 1 ↔ f x = x := by simp_rw [Perm.ext_iff, cycleOf_apply, one_apply] refine ⟨fun h => (if_pos (SameCycle.refl f x)).symm.trans (h x), fun h y => ?_⟩ by_cases hy : f y = y · rw [hy, ite_self] · exact if_neg (mt SameCycle.apply_eq_self_iff (by tauto)) @[simp] theorem cycleOf_self_apply (f : Perm α) [DecidableRel f.SameCycle] (x : α) : cycleOf f (f x) = cycleOf f x := (sameCycle_apply_right.2 SameCycle.rfl).symm.cycleOf_eq @[simp] theorem cycleOf_self_apply_pow (f : Perm α) [DecidableRel f.SameCycle] (n : ℕ) (x : α) : cycleOf f ((f ^ n) x) = cycleOf f x := SameCycle.rfl.pow_left.cycleOf_eq @[simp] theorem cycleOf_self_apply_zpow (f : Perm α) [DecidableRel f.SameCycle] (n : ℤ) (x : α) : cycleOf f ((f ^ n) x) = cycleOf f x := SameCycle.rfl.zpow_left.cycleOf_eq protected theorem IsCycle.cycleOf [DecidableRel f.SameCycle] [DecidableEq α] (hf : IsCycle f) : cycleOf f x = if f x = x then 1 else f := by by_cases hx : f x = x · rwa [if_pos hx, cycleOf_eq_one_iff] · rwa [if_neg hx, hf.cycleOf_eq] theorem cycleOf_one [DecidableRel (1 : Perm α).SameCycle] (x : α) : cycleOf 1 x = 1 := (cycleOf_eq_one_iff 1).mpr rfl theorem isCycle_cycleOf (f : Perm α) [DecidableRel f.SameCycle] (hx : f x ≠ x) : IsCycle (cycleOf f x) := have : cycleOf f x x ≠ x := by rwa [SameCycle.rfl.cycleOf_apply] (isCycle_iff_sameCycle this).2 @fun y => ⟨fun h => mt h.apply_eq_self_iff.2 this, fun h => if hxy : SameCycle f x y then let ⟨i, hi⟩ := hxy ⟨i, by rw [cycleOf_zpow_apply_self, hi]⟩ else by rw [cycleOf_apply_of_not_sameCycle hxy] at h exact (h rfl).elim⟩ @[simp] theorem two_le_card_support_cycleOf_iff [DecidableEq α] [Fintype α] : 2 ≤ card (cycleOf f x).support ↔ f x ≠ x := by refine ⟨fun h => ?_, fun h => by simpa using (isCycle_cycleOf _ h).two_le_card_support⟩ contrapose! h rw [← cycleOf_eq_one_iff] at h simp [h] @[simp] lemma support_cycleOf_nonempty [DecidableEq α] [Fintype α] : (cycleOf f x).support.Nonempty ↔ f x ≠ x := by rw [← two_le_card_support_cycleOf_iff, ← card_pos, ← Nat.succ_le_iff] exact ⟨fun h => Or.resolve_left h.eq_or_lt (card_support_ne_one _).symm, zero_lt_two.trans_le⟩ @[deprecated support_cycleOf_nonempty (since := "2024-06-16")] theorem card_support_cycleOf_pos_iff [DecidableEq α] [Fintype α] : 0 < card (cycleOf f x).support ↔ f x ≠ x := by rw [card_pos, support_cycleOf_nonempty] theorem pow_mod_orderOf_cycleOf_apply (f : Perm α) [DecidableRel f.SameCycle] (n : ℕ) (x : α) : (f ^ (n % orderOf (cycleOf f x))) x = (f ^ n) x := by rw [← cycleOf_pow_apply_self f, ← cycleOf_pow_apply_self f, pow_mod_orderOf] theorem cycleOf_mul_of_apply_right_eq_self [DecidableRel f.SameCycle] [DecidableRel (f * g).SameCycle] (h : Commute f g) (x : α) (hx : g x = x) : (f * g).cycleOf x = f.cycleOf x := by ext y by_cases hxy : (f * g).SameCycle x y · obtain ⟨z, rfl⟩ := hxy rw [cycleOf_apply_apply_zpow_self] simp [h.mul_zpow, zpow_apply_eq_self_of_apply_eq_self hx] · rw [cycleOf_apply_of_not_sameCycle hxy, cycleOf_apply_of_not_sameCycle] contrapose! hxy obtain ⟨z, rfl⟩ := hxy refine ⟨z, ?_⟩ simp [h.mul_zpow, zpow_apply_eq_self_of_apply_eq_self hx] theorem Disjoint.cycleOf_mul_distrib [DecidableRel f.SameCycle] [DecidableRel g.SameCycle] [DecidableRel (f * g).SameCycle] [DecidableRel (g * f).SameCycle] (h : f.Disjoint g) (x : α) : (f * g).cycleOf x = f.cycleOf x * g.cycleOf x := by cases' (disjoint_iff_eq_or_eq.mp h) x with hfx hgx · simp [h.commute.eq, cycleOf_mul_of_apply_right_eq_self h.symm.commute, hfx] · simp [cycleOf_mul_of_apply_right_eq_self h.commute, hgx] theorem support_cycleOf_eq_nil_iff [DecidableEq α] [Fintype α] : (f.cycleOf x).support = ∅ ↔ x ∉ f.support := by simp theorem support_cycleOf_le [DecidableEq α] [Fintype α] (f : Perm α) (x : α) : support (f.cycleOf x) ≤ support f := by intro y hy rw [mem_support, cycleOf_apply] at hy split_ifs at hy · exact mem_support.mpr hy · exact absurd rfl hy theorem mem_support_cycleOf_iff [DecidableEq α] [Fintype α] : y ∈ support (f.cycleOf x) ↔ SameCycle f x y ∧ x ∈ support f := by by_cases hx : f x = x · rw [(cycleOf_eq_one_iff _).mpr hx] simp [hx] · rw [mem_support, cycleOf_apply] split_ifs with hy · simp only [hx, hy, iff_true_iff, Ne, not_false_iff, and_self_iff, mem_support] rcases hy with ⟨k, rfl⟩ rw [← not_mem_support] simpa using hx · simpa [hx] using hy theorem mem_support_cycleOf_iff' (hx : f x ≠ x) [DecidableEq α] [Fintype α] : y ∈ support (f.cycleOf x) ↔ SameCycle f x y := by rw [mem_support_cycleOf_iff, and_iff_left (mem_support.2 hx)] theorem SameCycle.mem_support_iff {f} [DecidableEq α] [Fintype α] (h : SameCycle f x y) : x ∈ support f ↔ y ∈ support f := ⟨fun hx => support_cycleOf_le f x (mem_support_cycleOf_iff.mpr ⟨h, hx⟩), fun hy => support_cycleOf_le f y (mem_support_cycleOf_iff.mpr ⟨h.symm, hy⟩)⟩ theorem pow_mod_card_support_cycleOf_self_apply [DecidableEq α] [Fintype α] (f : Perm α) (n : ℕ) (x : α) : (f ^ (n % (f.cycleOf x).support.card)) x = (f ^ n) x := by by_cases hx : f x = x · rw [pow_apply_eq_self_of_apply_eq_self hx, pow_apply_eq_self_of_apply_eq_self hx] · rw [← cycleOf_pow_apply_self, ← cycleOf_pow_apply_self f, ← (isCycle_cycleOf f hx).orderOf, pow_mod_orderOf] /-- `x` is in the support of `f` iff `Equiv.Perm.cycle_of f x` is a cycle. -/ theorem isCycle_cycleOf_iff (f : Perm α) [DecidableRel f.SameCycle] : IsCycle (cycleOf f x) ↔ f x ≠ x := by refine ⟨fun hx => ?_, f.isCycle_cycleOf⟩ rw [Ne, ← cycleOf_eq_one_iff f] exact hx.ne_one theorem isCycleOn_support_cycleOf [DecidableEq α] [Fintype α] (f : Perm α) (x : α) : f.IsCycleOn (f.cycleOf x).support := ⟨f.bijOn <| by refine fun _ ↦ ⟨fun h ↦ mem_support_cycleOf_iff.2 ?_, fun h ↦ mem_support_cycleOf_iff.2 ?_⟩ · exact ⟨sameCycle_apply_right.1 (mem_support_cycleOf_iff.1 h).1, (mem_support_cycleOf_iff.1 h).2⟩ · exact ⟨sameCycle_apply_right.2 (mem_support_cycleOf_iff.1 h).1, (mem_support_cycleOf_iff.1 h).2⟩ , fun a ha b hb => by rw [mem_coe, mem_support_cycleOf_iff] at ha hb exact ha.1.symm.trans hb.1⟩ theorem SameCycle.exists_pow_eq_of_mem_support {f} [DecidableEq α] [Fintype α] (h : SameCycle f x y) (hx : x ∈ f.support) : ∃ i < (f.cycleOf x).support.card, (f ^ i) x = y := by rw [mem_support] at hx exact Equiv.Perm.IsCycleOn.exists_pow_eq (b := y) (f.isCycleOn_support_cycleOf x) (by rw [mem_support_cycleOf_iff' hx]) (by rwa [mem_support_cycleOf_iff' hx]) theorem SameCycle.exists_pow_eq [DecidableEq α] [Fintype α] (f : Perm α) (h : SameCycle f x y) : ∃ i : ℕ, 0 < i ∧ i ≤ (f.cycleOf x).support.card + 1 ∧ (f ^ i) x = y := by by_cases hx : x ∈ f.support · obtain ⟨k, hk, hk'⟩ := h.exists_pow_eq_of_mem_support hx cases' k with k · refine ⟨(f.cycleOf x).support.card, ?_, self_le_add_right _ _, ?_⟩ · refine zero_lt_one.trans (one_lt_card_support_of_ne_one ?_) simpa using hx · simp only [Nat.zero_eq, pow_zero, coe_one, id_eq] at hk' subst hk' rw [← (isCycle_cycleOf _ <| mem_support.1 hx).orderOf, ← cycleOf_pow_apply_self, pow_orderOf_eq_one, one_apply] · exact ⟨k + 1, by simp, Nat.le_succ_of_le hk.le, hk'⟩ · refine ⟨1, zero_lt_one, by simp, ?_⟩ obtain ⟨k, rfl⟩ := h rw [not_mem_support] at hx rw [pow_apply_eq_self_of_apply_eq_self hx, zpow_apply_eq_self_of_apply_eq_self hx] end CycleOf /-! ### `cycleFactors` -/ section cycleFactors open scoped List in /-- Given a list `l : List α` and a permutation `f : Perm α` whose nonfixed points are all in `l`, recursively factors `f` into cycles. -/ def cycleFactorsAux [DecidableEq α] [Fintype α] : ∀ (l : List α) (f : Perm α), (∀ {x}, f x ≠ x → x ∈ l) → { l : List (Perm α) // l.prod = f ∧ (∀ g ∈ l, IsCycle g) ∧ l.Pairwise Disjoint } := by intro l f h exact match l with | [] => ⟨[], by { simp only [imp_false, List.Pairwise.nil, List.not_mem_nil, forall_const, and_true_iff, forall_prop_of_false, Classical.not_not, not_false_iff, List.prod_nil] at * ext simp [*]}⟩ | x::l => if hx : f x = x then cycleFactorsAux l f (by intro y hy; exact List.mem_of_ne_of_mem (fun h => hy (by rwa [h])) (h hy)) else let ⟨m, hm₁, hm₂, hm₃⟩ := cycleFactorsAux l ((cycleOf f x)⁻¹ * f) (by intro y hy exact List.mem_of_ne_of_mem (fun h : y = x => by rw [h, mul_apply, Ne, inv_eq_iff_eq, cycleOf_apply_self] at hy exact hy rfl) (h fun h : f y = y => by rw [mul_apply, h, Ne, inv_eq_iff_eq, cycleOf_apply] at hy split_ifs at hy <;> tauto)) ⟨cycleOf f x::m, by rw [List.prod_cons, hm₁] simp, fun g hg ↦ ((List.mem_cons).1 hg).elim (fun hg => hg.symm ▸ isCycle_cycleOf _ hx) (hm₂ g), List.pairwise_cons.2 ⟨fun g hg y => or_iff_not_imp_left.2 fun hfy => have hxy : SameCycle f x y := Classical.not_not.1 (mt cycleOf_apply_of_not_sameCycle hfy) have hgm : (g::m.erase g) ~ m := List.cons_perm_iff_perm_erase.2 ⟨hg, List.Perm.refl _⟩ have : ∀ h ∈ m.erase g, Disjoint g h := (List.pairwise_cons.1 ((hgm.pairwise_iff Disjoint.symm).2 hm₃)).1 by_cases id fun hgy : g y ≠ y => (disjoint_prod_right _ this y).resolve_right <| by have hsc : SameCycle f⁻¹ x (f y) := by rwa [sameCycle_inv, sameCycle_apply_right] rw [disjoint_prod_perm hm₃ hgm.symm, List.prod_cons, ← eq_inv_mul_iff_mul_eq] at hm₁ rwa [hm₁, mul_apply, mul_apply, cycleOf_inv, hsc.cycleOf_apply, inv_apply_self, inv_eq_iff_eq, eq_comm], hm₃⟩⟩ theorem mem_list_cycles_iff {α : Type*} [Finite α] {l : List (Perm α)} (h1 : ∀ σ : Perm α, σ ∈ l → σ.IsCycle) (h2 : l.Pairwise Disjoint) {σ : Perm α} : σ ∈ l ↔ σ.IsCycle ∧ ∀ a, σ a ≠ a → σ a = l.prod a := by suffices σ.IsCycle → (σ ∈ l ↔ ∀ a, σ a ≠ a → σ a = l.prod a) by exact ⟨fun hσ => ⟨h1 σ hσ, (this (h1 σ hσ)).mp hσ⟩, fun hσ => (this hσ.1).mpr hσ.2⟩ intro h3 classical cases nonempty_fintype α constructor · intro h a ha exact eq_on_support_mem_disjoint h h2 _ (mem_support.mpr ha) · intro h have hσl : σ.support ⊆ l.prod.support := by intro x hx rw [mem_support] at hx rwa [mem_support, ← h _ hx] obtain ⟨a, ha, -⟩ := id h3 rw [← mem_support] at ha obtain ⟨τ, hτ, hτa⟩ := exists_mem_support_of_mem_support_prod (hσl ha) have hτl : ∀ x ∈ τ.support, τ x = l.prod x := eq_on_support_mem_disjoint hτ h2 have key : ∀ x ∈ σ.support ∩ τ.support, σ x = τ x := by intro x hx rw [h x (mem_support.mp (mem_of_mem_inter_left hx)), hτl x (mem_of_mem_inter_right hx)] convert hτ refine h3.eq_on_support_inter_nonempty_congr (h1 _ hτ) key ?_ ha exact key a (mem_inter_of_mem ha hτa) open scoped List in theorem list_cycles_perm_list_cycles {α : Type*} [Finite α] {l₁ l₂ : List (Perm α)} (h₀ : l₁.prod = l₂.prod) (h₁l₁ : ∀ σ : Perm α, σ ∈ l₁ → σ.IsCycle) (h₁l₂ : ∀ σ : Perm α, σ ∈ l₂ → σ.IsCycle) (h₂l₁ : l₁.Pairwise Disjoint) (h₂l₂ : l₂.Pairwise Disjoint) : l₁ ~ l₂ := by classical refine (List.perm_ext_iff_of_nodup (nodup_of_pairwise_disjoint_cycles h₁l₁ h₂l₁) (nodup_of_pairwise_disjoint_cycles h₁l₂ h₂l₂)).mpr fun σ => ?_ by_cases hσ : σ.IsCycle · obtain _ := not_forall.mp (mt ext hσ.ne_one) rw [mem_list_cycles_iff h₁l₁ h₂l₁, mem_list_cycles_iff h₁l₂ h₂l₂, h₀] · exact iff_of_false (mt (h₁l₁ σ) hσ) (mt (h₁l₂ σ) hσ) /-- Factors a permutation `f` into a list of disjoint cyclic permutations that multiply to `f`. -/ def cycleFactors [Fintype α] [LinearOrder α] (f : Perm α) : { l : List (Perm α) // l.prod = f ∧ (∀ g ∈ l, IsCycle g) ∧ l.Pairwise Disjoint } := cycleFactorsAux (sort (α := α) (· ≤ ·) univ) f (fun {_ _} ↦ (mem_sort _).2 (mem_univ _)) /-- Factors a permutation `f` into a list of disjoint cyclic permutations that multiply to `f`, without a linear order. -/ def truncCycleFactors [DecidableEq α] [Fintype α] (f : Perm α) : Trunc { l : List (Perm α) // l.prod = f ∧ (∀ g ∈ l, IsCycle g) ∧ l.Pairwise Disjoint } := Quotient.recOnSubsingleton (@univ α _).1 (fun l h => Trunc.mk (cycleFactorsAux l f (h _))) (show ∀ x, f x ≠ x → x ∈ (@univ α _).1 from fun _ _ => mem_univ _) section CycleFactorsFinset variable [DecidableEq α] [Fintype α] (f : Perm α) /-- Factors a permutation `f` into a `Finset` of disjoint cyclic permutations that multiply to `f`. -/ def cycleFactorsFinset : Finset (Perm α) := (truncCycleFactors f).lift (fun l : { l : List (Perm α) // l.prod = f ∧ (∀ g ∈ l, IsCycle g) ∧ l.Pairwise Disjoint } => l.val.toFinset) fun ⟨_, hl⟩ ⟨_, hl'⟩ => List.toFinset_eq_of_perm _ _ (list_cycles_perm_list_cycles (hl'.left.symm ▸ hl.left) hl.right.left hl'.right.left hl.right.right hl'.right.right) open scoped List in theorem cycleFactorsFinset_eq_list_toFinset {σ : Perm α} {l : List (Perm α)} (hn : l.Nodup) : σ.cycleFactorsFinset = l.toFinset ↔ (∀ f : Perm α, f ∈ l → f.IsCycle) ∧ l.Pairwise Disjoint ∧ l.prod = σ := by obtain ⟨⟨l', hp', hc', hd'⟩, hl⟩ := Trunc.exists_rep σ.truncCycleFactors have ht : cycleFactorsFinset σ = l'.toFinset := by rw [cycleFactorsFinset, ← hl, Trunc.lift_mk] rw [ht] constructor · intro h have hn' : l'.Nodup := nodup_of_pairwise_disjoint_cycles hc' hd' have hperm : l ~ l' := List.perm_of_nodup_nodup_toFinset_eq hn hn' h.symm refine ⟨?_, ?_, ?_⟩ · exact fun _ h => hc' _ (hperm.subset h) · have := List.Perm.pairwise_iff (@Disjoint.symmetric _) hperm rwa [this] · rw [← hp', hperm.symm.prod_eq'] refine hd'.imp ?_ exact Disjoint.commute · rintro ⟨hc, hd, hp⟩ refine List.toFinset_eq_of_perm _ _ ?_ refine list_cycles_perm_list_cycles ?_ hc' hc hd' hd rw [hp, hp'] theorem cycleFactorsFinset_eq_finset {σ : Perm α} {s : Finset (Perm α)} : σ.cycleFactorsFinset = s ↔ (∀ f : Perm α, f ∈ s → f.IsCycle) ∧ ∃ h : (s : Set (Perm α)).Pairwise Disjoint, s.noncommProd id (h.mono' fun _ _ => Disjoint.commute) = σ := by obtain ⟨l, hl, rfl⟩ := s.exists_list_nodup_eq simp [cycleFactorsFinset_eq_list_toFinset, hl] theorem cycleFactorsFinset_pairwise_disjoint : (cycleFactorsFinset f : Set (Perm α)).Pairwise Disjoint := (cycleFactorsFinset_eq_finset.mp rfl).2.choose theorem cycleFactorsFinset_mem_commute : (cycleFactorsFinset f : Set (Perm α)).Pairwise Commute := (cycleFactorsFinset_pairwise_disjoint _).mono' fun _ _ => Disjoint.commute /-- The product of cycle factors is equal to the original `f : perm α`. -/ theorem cycleFactorsFinset_noncommProd (comm : (cycleFactorsFinset f : Set (Perm α)).Pairwise Commute := cycleFactorsFinset_mem_commute f) : f.cycleFactorsFinset.noncommProd id comm = f := (cycleFactorsFinset_eq_finset.mp rfl).2.choose_spec theorem mem_cycleFactorsFinset_iff {f p : Perm α} : p ∈ cycleFactorsFinset f ↔ p.IsCycle ∧ ∀ a ∈ p.support, p a = f a := by obtain ⟨l, hl, hl'⟩ := f.cycleFactorsFinset.exists_list_nodup_eq rw [← hl'] rw [eq_comm, cycleFactorsFinset_eq_list_toFinset hl] at hl' simpa [List.mem_toFinset, Ne, ← hl'.right.right] using mem_list_cycles_iff hl'.left hl'.right.left theorem cycleOf_mem_cycleFactorsFinset_iff {f : Perm α} {x : α} : cycleOf f x ∈ cycleFactorsFinset f ↔ x ∈ f.support := by rw [mem_cycleFactorsFinset_iff] constructor · rintro ⟨hc, _⟩ contrapose! hc rw [not_mem_support, ← cycleOf_eq_one_iff] at hc simp [hc] · intro hx refine ⟨isCycle_cycleOf _ (mem_support.mp hx), ?_⟩ intro y hy rw [mem_support] at hy rw [cycleOf_apply] split_ifs with H · rfl · rw [cycleOf_apply_of_not_sameCycle H] at hy contradiction theorem mem_cycleFactorsFinset_support_le {p f : Perm α} (h : p ∈ cycleFactorsFinset f) : p.support ≤ f.support := by rw [mem_cycleFactorsFinset_iff] at h intro x hx rwa [mem_support, ← h.right x hx, ← mem_support] theorem cycleFactorsFinset_eq_empty_iff {f : Perm α} : cycleFactorsFinset f = ∅ ↔ f = 1 := by simpa [cycleFactorsFinset_eq_finset] using eq_comm @[simp] theorem cycleFactorsFinset_one : cycleFactorsFinset (1 : Perm α) = ∅ := by simp [cycleFactorsFinset_eq_empty_iff] @[simp] theorem cycleFactorsFinset_eq_singleton_self_iff {f : Perm α} : f.cycleFactorsFinset = {f} ↔ f.IsCycle := by simp [cycleFactorsFinset_eq_finset] theorem IsCycle.cycleFactorsFinset_eq_singleton {f : Perm α} (hf : IsCycle f) : f.cycleFactorsFinset = {f} := cycleFactorsFinset_eq_singleton_self_iff.mpr hf theorem cycleFactorsFinset_eq_singleton_iff {f g : Perm α} : f.cycleFactorsFinset = {g} ↔ f.IsCycle ∧ f = g := by suffices f = g → (g.IsCycle ↔ f.IsCycle) by rw [cycleFactorsFinset_eq_finset] simpa [eq_comm] rintro rfl exact Iff.rfl /-- Two permutations `f g : Perm α` have the same cycle factors iff they are the same. -/ theorem cycleFactorsFinset_injective : Function.Injective (@cycleFactorsFinset α _ _) := by intro f g h rw [← cycleFactorsFinset_noncommProd f] simpa [h] using cycleFactorsFinset_noncommProd g theorem Disjoint.disjoint_cycleFactorsFinset {f g : Perm α} (h : Disjoint f g) : _root_.Disjoint (cycleFactorsFinset f) (cycleFactorsFinset g) := by rw [disjoint_iff_disjoint_support] at h rw [Finset.disjoint_left] intro x hx hy simp only [mem_cycleFactorsFinset_iff, mem_support] at hx hy obtain ⟨⟨⟨a, ha, -⟩, hf⟩, -, hg⟩ := hx, hy have := h.le_bot (by simp [ha, ← hf a ha, ← hg a ha] : a ∈ f.support ∩ g.support) tauto theorem Disjoint.cycleFactorsFinset_mul_eq_union {f g : Perm α} (h : Disjoint f g) : cycleFactorsFinset (f * g) = cycleFactorsFinset f ∪ cycleFactorsFinset g := by rw [cycleFactorsFinset_eq_finset] refine ⟨?_, ?_, ?_⟩ · simp [or_imp, mem_cycleFactorsFinset_iff, forall_swap] · rw [coe_union, Set.pairwise_union_of_symmetric Disjoint.symmetric] exact ⟨cycleFactorsFinset_pairwise_disjoint _, cycleFactorsFinset_pairwise_disjoint _, fun x hx y hy _ => h.mono (mem_cycleFactorsFinset_support_le hx) (mem_cycleFactorsFinset_support_le hy)⟩ · rw [noncommProd_union_of_disjoint h.disjoint_cycleFactorsFinset] rw [cycleFactorsFinset_noncommProd, cycleFactorsFinset_noncommProd] theorem disjoint_mul_inv_of_mem_cycleFactorsFinset {f g : Perm α} (h : f ∈ cycleFactorsFinset g) : Disjoint (g * f⁻¹) f := by rw [mem_cycleFactorsFinset_iff] at h intro x by_cases hx : f x = x · exact Or.inr hx · refine Or.inl ?_ rw [mul_apply, ← h.right, apply_inv_self] rwa [← support_inv, apply_mem_support, support_inv, mem_support] /-- If c is a cycle, a ∈ c.support and c is a cycle of f, then `c = f.cycleOf a` -/ theorem cycle_is_cycleOf {f c : Equiv.Perm α} {a : α} (ha : a ∈ c.support) (hc : c ∈ f.cycleFactorsFinset) : c = f.cycleOf a := by suffices f.cycleOf a = c.cycleOf a by rw [this] apply symm exact Equiv.Perm.IsCycle.cycleOf_eq (Equiv.Perm.mem_cycleFactorsFinset_iff.mp hc).left (Equiv.Perm.mem_support.mp ha) let hfc := (Equiv.Perm.disjoint_mul_inv_of_mem_cycleFactorsFinset hc).symm let hfc2 := Perm.Disjoint.commute hfc rw [← Equiv.Perm.cycleOf_mul_of_apply_right_eq_self hfc2] · simp only [hfc2.eq, inv_mul_cancel_right] -- `a` is in the support of `c`, hence it is not in the support of `g c⁻¹` exact Equiv.Perm.not_mem_support.mp (Finset.disjoint_left.mp (Equiv.Perm.Disjoint.disjoint_support hfc) ha) end CycleFactorsFinset @[elab_as_elim] theorem cycle_induction_on [Finite β] (P : Perm β → Prop) (σ : Perm β) (base_one : P 1) (base_cycles : ∀ σ : Perm β, σ.IsCycle → P σ) (induction_disjoint : ∀ σ τ : Perm β, Disjoint σ τ → IsCycle σ → P σ → P τ → P (σ * τ)) : P σ := by cases nonempty_fintype β suffices ∀ l : List (Perm β), (∀ τ : Perm β, τ ∈ l → τ.IsCycle) → l.Pairwise Disjoint → P l.prod by classical let x := σ.truncCycleFactors.out exact (congr_arg P x.2.1).mp (this x.1 x.2.2.1 x.2.2.2) intro l induction' l with σ l ih · exact fun _ _ => base_one · intro h1 h2 rw [List.prod_cons] exact induction_disjoint σ l.prod (disjoint_prod_right _ (List.pairwise_cons.mp h2).1) (h1 _ (List.mem_cons_self _ _)) (base_cycles σ (h1 σ (l.mem_cons_self σ))) (ih (fun τ hτ => h1 τ (List.mem_cons_of_mem σ hτ)) h2.of_cons) theorem cycleFactorsFinset_mul_inv_mem_eq_sdiff [DecidableEq α] [Fintype α] {f g : Perm α} (h : f ∈ cycleFactorsFinset g) : cycleFactorsFinset (g * f⁻¹) = cycleFactorsFinset g \ {f} := by revert f refine cycle_induction_on (P := fun {g : Perm α} ↦ ∀ {f}, (f ∈ cycleFactorsFinset g) → cycleFactorsFinset (g * f⁻¹) = cycleFactorsFinset g \ {f}) _ ?_ ?_ ?_ · simp · intro σ hσ f hf simp only [cycleFactorsFinset_eq_singleton_self_iff.mpr hσ, mem_singleton] at hf ⊢ simp [hf] · intro σ τ hd _ hσ hτ f simp_rw [hd.cycleFactorsFinset_mul_eq_union, mem_union] -- if only `wlog` could work here... rintro (hf | hf) · rw [hd.commute.eq, union_comm, union_sdiff_distrib, sdiff_singleton_eq_erase, erase_eq_of_not_mem, mul_assoc, Disjoint.cycleFactorsFinset_mul_eq_union, hσ hf] · rw [mem_cycleFactorsFinset_iff] at hf intro x cases' hd.symm x with hx hx · exact Or.inl hx · refine Or.inr ?_ by_cases hfx : f x = x · rw [← hfx] simpa [hx] using hfx.symm · rw [mul_apply] rw [← hf.right _ (mem_support.mpr hfx)] at hx contradiction · exact fun H => not_mem_empty _ (hd.disjoint_cycleFactorsFinset.le_bot (mem_inter_of_mem hf H)) · rw [union_sdiff_distrib, sdiff_singleton_eq_erase, erase_eq_of_not_mem, mul_assoc, Disjoint.cycleFactorsFinset_mul_eq_union, hτ hf] · rw [mem_cycleFactorsFinset_iff] at hf intro x cases' hd x with hx hx · exact Or.inl hx · refine Or.inr ?_ by_cases hfx : f x = x · rw [← hfx] simpa [hx] using hfx.symm · rw [mul_apply] rw [← hf.right _ (mem_support.mpr hfx)] at hx contradiction · exact fun H => not_mem_empty _ (hd.disjoint_cycleFactorsFinset.le_bot (mem_inter_of_mem H hf)) end cycleFactors end Perm end Equiv
GroupTheory\Perm\Cycle\PossibleTypes.lean
/- Copyright (c) 2023 Antoine Chambert-Loir. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Antoine Chambert-Loir -/ import Mathlib.GroupTheory.Perm.Cycle.Concrete /-! # Possible cycle types of permutations * For `m : Multiset ℕ`, `Equiv.Perm.exists_with_cycleType_iff m` proves that there are permutations with cycleType `m` if and only if its sum is at most `Fintype.card α` and its members are at least 2. -/ variable (α : Type*) [DecidableEq α] [Fintype α] /-- There are permutations with cycleType `m` if and only if its sum is at most `Fintype.card α` and its members are at least 2. -/ theorem Equiv.Perm.exists_with_cycleType_iff {m : Multiset ℕ} : (∃ g : Equiv.Perm α, g.cycleType = m) ↔ (m.sum ≤ Fintype.card α ∧ ∀ a ∈ m, 2 ≤ a) := by constructor · -- empty case intro h obtain ⟨g, hg⟩ := h constructor · rw [← hg, Equiv.Perm.sum_cycleType] exact (Equiv.Perm.support g).card_le_univ · intro a rw [← hg] exact Equiv.Perm.two_le_of_mem_cycleType · rintro ⟨hc, h2c⟩ have hc' : m.toList.sum ≤ Fintype.card α := by simp only [Multiset.sum_toList] exact hc obtain ⟨p, hp_length, hp_nodup, hp_disj⟩ := List.exists_pw_disjoint_with_card hc' use List.prod (List.map (fun l => List.formPerm l) p) have hp2 : ∀ x ∈ p, 2 ≤ x.length := by intro x hx apply h2c x.length rw [← Multiset.mem_toList, ← hp_length, List.mem_map] exact ⟨x, hx, rfl⟩ rw [Equiv.Perm.cycleType_eq _ rfl] · -- lengths rw [← Multiset.coe_toList m] apply congr_arg rw [List.map_map]; rw [← hp_length] apply List.map_congr_left intro x hx; simp only [Function.comp_apply] rw [List.support_formPerm_of_nodup x (hp_nodup x hx)] ·-- length rw [List.toFinset_card_of_nodup (hp_nodup x hx)] · -- length >= 1 intro a h apply Nat.not_succ_le_self 1 conv_rhs => rw [← List.length_singleton a]; rw [← h] exact hp2 x hx · -- cycles intro g rw [List.mem_map] rintro ⟨x, hx, rfl⟩ have hx_nodup : x.Nodup := hp_nodup x hx rw [← Cycle.formPerm_coe x hx_nodup] apply Cycle.isCycle_formPerm rw [Cycle.nontrivial_coe_nodup_iff hx_nodup] exact hp2 x hx · -- disjoint rw [List.pairwise_map] apply List.Pairwise.imp_of_mem _ hp_disj intro a b ha hb hab rw [List.formPerm_disjoint_iff (hp_nodup a ha) (hp_nodup b hb) (hp2 a ha) (hp2 b hb)] exact hab
GroupTheory\Perm\Cycle\Type.lean
/- Copyright (c) 2020 Thomas Browning. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning -/ import Mathlib.Algebra.GCDMonoid.Multiset import Mathlib.Combinatorics.Enumerative.Partition import Mathlib.Data.List.Rotate import Mathlib.GroupTheory.Perm.Cycle.Factors import Mathlib.GroupTheory.Perm.Closure import Mathlib.Algebra.GCDMonoid.Nat import Mathlib.Tactic.NormNum.GCD /-! # Cycle Types In this file we define the cycle type of a permutation. ## Main definitions - `Equiv.Perm.cycleType σ` where `σ` is a permutation of a `Fintype` - `Equiv.Perm.partition σ` where `σ` is a permutation of a `Fintype` ## Main results - `sum_cycleType` : The sum of `σ.cycleType` equals `σ.support.card` - `lcm_cycleType` : The lcm of `σ.cycleType` equals `orderOf σ` - `isConj_iff_cycleType_eq` : Two permutations are conjugate if and only if they have the same cycle type. - `exists_prime_orderOf_dvd_card`: For every prime `p` dividing the order of a finite group `G` there exists an element of order `p` in `G`. This is known as Cauchy's theorem. -/ namespace Equiv.Perm open Mathlib (Vector) open Equiv List Multiset variable {α : Type*} [Fintype α] section CycleType variable [DecidableEq α] /-- The cycle type of a permutation -/ def cycleType (σ : Perm α) : Multiset ℕ := σ.cycleFactorsFinset.1.map (Finset.card ∘ support) theorem cycleType_def (σ : Perm α) : σ.cycleType = σ.cycleFactorsFinset.1.map (Finset.card ∘ support) := rfl theorem cycleType_eq' {σ : Perm α} (s : Finset (Perm α)) (h1 : ∀ f : Perm α, f ∈ s → f.IsCycle) (h2 : (s : Set (Perm α)).Pairwise Disjoint) (h0 : s.noncommProd id (h2.imp fun _ _ => Disjoint.commute) = σ) : σ.cycleType = s.1.map (Finset.card ∘ support) := by rw [cycleType_def] congr rw [cycleFactorsFinset_eq_finset] exact ⟨h1, h2, h0⟩ theorem cycleType_eq {σ : Perm α} (l : List (Perm α)) (h0 : l.prod = σ) (h1 : ∀ σ : Perm α, σ ∈ l → σ.IsCycle) (h2 : l.Pairwise Disjoint) : σ.cycleType = l.map (Finset.card ∘ support) := by have hl : l.Nodup := nodup_of_pairwise_disjoint_cycles h1 h2 rw [cycleType_eq' l.toFinset] · simp [List.dedup_eq_self.mpr hl, (· ∘ ·)] · simpa using h1 · simpa [hl] using h2 · simp [hl, h0] @[simp] -- Porting note: new attr theorem cycleType_eq_zero {σ : Perm α} : σ.cycleType = 0 ↔ σ = 1 := by simp [cycleType_def, cycleFactorsFinset_eq_empty_iff] @[simp] -- Porting note: new attr theorem cycleType_one : (1 : Perm α).cycleType = 0 := cycleType_eq_zero.2 rfl theorem card_cycleType_eq_zero {σ : Perm α} : Multiset.card σ.cycleType = 0 ↔ σ = 1 := by rw [card_eq_zero, cycleType_eq_zero] theorem card_cycleType_pos {σ : Perm α} : 0 < Multiset.card σ.cycleType ↔ σ ≠ 1 := pos_iff_ne_zero.trans card_cycleType_eq_zero.not theorem two_le_of_mem_cycleType {σ : Perm α} {n : ℕ} (h : n ∈ σ.cycleType) : 2 ≤ n := by simp only [cycleType_def, ← Finset.mem_def, Function.comp_apply, Multiset.mem_map, mem_cycleFactorsFinset_iff] at h obtain ⟨_, ⟨hc, -⟩, rfl⟩ := h exact hc.two_le_card_support theorem one_lt_of_mem_cycleType {σ : Perm α} {n : ℕ} (h : n ∈ σ.cycleType) : 1 < n := two_le_of_mem_cycleType h theorem IsCycle.cycleType {σ : Perm α} (hσ : IsCycle σ) : σ.cycleType = [σ.support.card] := cycleType_eq [σ] (mul_one σ) (fun _τ hτ => (congr_arg IsCycle (List.mem_singleton.mp hτ)).mpr hσ) (List.pairwise_singleton Disjoint σ) theorem card_cycleType_eq_one {σ : Perm α} : Multiset.card σ.cycleType = 1 ↔ σ.IsCycle := by rw [card_eq_one] simp_rw [cycleType_def, Multiset.map_eq_singleton, ← Finset.singleton_val, Finset.val_inj, cycleFactorsFinset_eq_singleton_iff] constructor · rintro ⟨_, _, ⟨h, -⟩, -⟩ exact h · intro h use σ.support.card, σ simp [h] theorem Disjoint.cycleType {σ τ : Perm α} (h : Disjoint σ τ) : (σ * τ).cycleType = σ.cycleType + τ.cycleType := by rw [cycleType_def, cycleType_def, cycleType_def, h.cycleFactorsFinset_mul_eq_union, ← Multiset.map_add, Finset.union_val, Multiset.add_eq_union_iff_disjoint.mpr _] exact Finset.disjoint_val.2 h.disjoint_cycleFactorsFinset @[simp] -- Porting note: new attr theorem cycleType_inv (σ : Perm α) : σ⁻¹.cycleType = σ.cycleType := cycle_induction_on (P := fun τ : Perm α => τ⁻¹.cycleType = τ.cycleType) σ rfl (fun σ hσ => by simp only [hσ.cycleType, hσ.inv.cycleType, support_inv]) fun σ τ hστ _ hσ hτ => by simp only [mul_inv_rev, hστ.cycleType, hστ.symm.inv_left.inv_right.cycleType, hσ, hτ, add_comm] @[simp] -- Porting note: new attr theorem cycleType_conj {σ τ : Perm α} : (τ * σ * τ⁻¹).cycleType = σ.cycleType := by induction σ using cycle_induction_on with | base_one => simp | base_cycles σ hσ => rw [hσ.cycleType, hσ.conj.cycleType, card_support_conj] | induction_disjoint σ π hd _ hσ hπ => rw [← conj_mul, hd.cycleType, (hd.conj _).cycleType, hσ, hπ] theorem sum_cycleType (σ : Perm α) : σ.cycleType.sum = σ.support.card := by induction σ using cycle_induction_on with | base_one => simp | base_cycles σ hσ => rw [hσ.cycleType, sum_coe, List.sum_singleton] | induction_disjoint σ τ hd _ hσ hτ => rw [hd.cycleType, sum_add, hσ, hτ, hd.card_support_mul] theorem sign_of_cycleType' (σ : Perm α) : sign σ = (σ.cycleType.map fun n => -(-1 : ℤˣ) ^ n).prod := by induction σ using cycle_induction_on with | base_one => simp | base_cycles σ hσ => simp [hσ.cycleType, hσ.sign] | induction_disjoint σ τ hd _ hσ hτ => simp [hσ, hτ, hd.cycleType] theorem sign_of_cycleType (f : Perm α) : sign f = (-1 : ℤˣ) ^ (f.cycleType.sum + Multiset.card f.cycleType) := by rw [sign_of_cycleType'] induction' f.cycleType using Multiset.induction_on with a s ihs · rfl · rw [Multiset.map_cons, Multiset.prod_cons, Multiset.sum_cons, Multiset.card_cons, ihs] simp only [pow_add, pow_one, mul_neg_one, neg_mul, mul_neg, mul_assoc, mul_one] @[simp] -- Porting note: new attr theorem lcm_cycleType (σ : Perm α) : σ.cycleType.lcm = orderOf σ := by induction σ using cycle_induction_on with | base_one => simp | base_cycles σ hσ => simp [hσ.cycleType, hσ.orderOf] | induction_disjoint σ τ hd _ hσ hτ => simp [hd.cycleType, hd.orderOf, lcm_eq_nat_lcm, hσ, hτ] theorem dvd_of_mem_cycleType {σ : Perm α} {n : ℕ} (h : n ∈ σ.cycleType) : n ∣ orderOf σ := by rw [← lcm_cycleType] exact dvd_lcm h theorem orderOf_cycleOf_dvd_orderOf (f : Perm α) (x : α) : orderOf (cycleOf f x) ∣ orderOf f := by by_cases hx : f x = x · rw [← cycleOf_eq_one_iff] at hx simp [hx] · refine dvd_of_mem_cycleType ?_ rw [cycleType, Multiset.mem_map] refine ⟨f.cycleOf x, ?_, ?_⟩ · rwa [← Finset.mem_def, cycleOf_mem_cycleFactorsFinset_iff, mem_support] · simp [(isCycle_cycleOf _ hx).orderOf] theorem two_dvd_card_support {σ : Perm α} (hσ : σ ^ 2 = 1) : 2 ∣ σ.support.card := (congr_arg (Dvd.dvd 2) σ.sum_cycleType).mp (Multiset.dvd_sum fun n hn => by rw [_root_.le_antisymm (Nat.le_of_dvd zero_lt_two <| (dvd_of_mem_cycleType hn).trans <| orderOf_dvd_of_pow_eq_one hσ) (two_le_of_mem_cycleType hn)]) theorem cycleType_prime_order {σ : Perm α} (hσ : (orderOf σ).Prime) : ∃ n : ℕ, σ.cycleType = Multiset.replicate (n + 1) (orderOf σ) := by refine ⟨Multiset.card σ.cycleType - 1, eq_replicate.2 ⟨?_, fun n hn ↦ ?_⟩⟩ · rw [tsub_add_cancel_of_le] rw [Nat.succ_le_iff, card_cycleType_pos, Ne, ← orderOf_eq_one_iff] exact hσ.ne_one · exact (hσ.eq_one_or_self_of_dvd n (dvd_of_mem_cycleType hn)).resolve_left (one_lt_of_mem_cycleType hn).ne' theorem isCycle_of_prime_order {σ : Perm α} (h1 : (orderOf σ).Prime) (h2 : σ.support.card < 2 * orderOf σ) : σ.IsCycle := by obtain ⟨n, hn⟩ := cycleType_prime_order h1 rw [← σ.sum_cycleType, hn, Multiset.sum_replicate, nsmul_eq_mul, Nat.cast_id, mul_lt_mul_right (orderOf_pos σ), Nat.succ_lt_succ_iff, Nat.lt_succ_iff, Nat.le_zero] at h2 rw [← card_cycleType_eq_one, hn, card_replicate, h2] theorem cycleType_le_of_mem_cycleFactorsFinset {f g : Perm α} (hf : f ∈ g.cycleFactorsFinset) : f.cycleType ≤ g.cycleType := by have hf' := mem_cycleFactorsFinset_iff.1 hf rw [cycleType_def, cycleType_def, hf'.left.cycleFactorsFinset_eq_singleton] refine map_le_map ?_ simpa only [Finset.singleton_val, singleton_le, Finset.mem_val] using hf theorem cycleType_mul_inv_mem_cycleFactorsFinset_eq_sub {f g : Perm α} (hf : f ∈ g.cycleFactorsFinset) : (g * f⁻¹).cycleType = g.cycleType - f.cycleType := add_right_cancel (b := f.cycleType) <| by rw [← (disjoint_mul_inv_of_mem_cycleFactorsFinset hf).cycleType, inv_mul_cancel_right, tsub_add_cancel_of_le (cycleType_le_of_mem_cycleFactorsFinset hf)] theorem isConj_of_cycleType_eq {σ τ : Perm α} (h : cycleType σ = cycleType τ) : IsConj σ τ := by induction σ using cycle_induction_on generalizing τ with | base_one => rw [cycleType_one, eq_comm, cycleType_eq_zero] at h rw [h] | base_cycles σ hσ => have hτ := card_cycleType_eq_one.2 hσ rw [h, card_cycleType_eq_one] at hτ apply hσ.isConj hτ rw [hσ.cycleType, hτ.cycleType, coe_eq_coe, List.singleton_perm] at h exact List.singleton_injective h | induction_disjoint σ π hd hc hσ hπ => rw [hd.cycleType] at h have h' : σ.support.card ∈ τ.cycleType := by simp [← h, hc.cycleType] obtain ⟨σ', hσ'l, hσ'⟩ := Multiset.mem_map.mp h' have key : IsConj (σ' * τ * σ'⁻¹) τ := (isConj_iff.2 ⟨σ', rfl⟩).symm refine IsConj.trans ?_ key rw [mul_assoc] have hs : σ.cycleType = σ'.cycleType := by rw [← Finset.mem_def, mem_cycleFactorsFinset_iff] at hσ'l rw [hc.cycleType, ← hσ', hσ'l.left.cycleType]; rfl refine hd.isConj_mul (hσ hs) (hπ ?_) ?_ · rw [cycleType_mul_inv_mem_cycleFactorsFinset_eq_sub, ← h, add_comm, hs, add_tsub_cancel_right] rwa [Finset.mem_def] · exact (disjoint_mul_inv_of_mem_cycleFactorsFinset hσ'l).symm theorem isConj_iff_cycleType_eq {σ τ : Perm α} : IsConj σ τ ↔ σ.cycleType = τ.cycleType := ⟨fun h => by obtain ⟨π, rfl⟩ := isConj_iff.1 h rw [cycleType_conj], isConj_of_cycleType_eq⟩ @[simp] theorem cycleType_extendDomain {β : Type*} [Fintype β] [DecidableEq β] {p : β → Prop} [DecidablePred p] (f : α ≃ Subtype p) {g : Perm α} : cycleType (g.extendDomain f) = cycleType g := by induction g using cycle_induction_on with | base_one => rw [extendDomain_one, cycleType_one, cycleType_one] | base_cycles σ hσ => rw [(hσ.extendDomain f).cycleType, hσ.cycleType, card_support_extend_domain] | induction_disjoint σ τ hd _ hσ hτ => rw [hd.cycleType, ← extendDomain_mul, (hd.extendDomain f).cycleType, hσ, hτ] theorem cycleType_ofSubtype {p : α → Prop} [DecidablePred p] {g : Perm (Subtype p)} : cycleType (ofSubtype g) = cycleType g := cycleType_extendDomain (Equiv.refl (Subtype p)) theorem mem_cycleType_iff {n : ℕ} {σ : Perm α} : n ∈ cycleType σ ↔ ∃ c τ, σ = c * τ ∧ Disjoint c τ ∧ IsCycle c ∧ c.support.card = n := by constructor · intro h obtain ⟨l, rfl, hlc, hld⟩ := truncCycleFactors σ rw [cycleType_eq _ rfl hlc hld, Multiset.mem_coe, List.mem_map] at h obtain ⟨c, cl, rfl⟩ := h rw [(List.perm_cons_erase cl).pairwise_iff @(Disjoint.symmetric)] at hld refine ⟨c, (l.erase c).prod, ?_, ?_, hlc _ cl, rfl⟩ · rw [← List.prod_cons, (List.perm_cons_erase cl).symm.prod_eq' (hld.imp Disjoint.commute)] · exact disjoint_prod_right _ fun g => List.rel_of_pairwise_cons hld · rintro ⟨c, t, rfl, hd, hc, rfl⟩ simp [hd.cycleType, hc.cycleType] theorem le_card_support_of_mem_cycleType {n : ℕ} {σ : Perm α} (h : n ∈ cycleType σ) : n ≤ σ.support.card := (le_sum_of_mem h).trans (le_of_eq σ.sum_cycleType) theorem cycleType_of_card_le_mem_cycleType_add_two {n : ℕ} {g : Perm α} (hn2 : Fintype.card α < n + 2) (hng : n ∈ g.cycleType) : g.cycleType = {n} := by obtain ⟨c, g', rfl, hd, hc, rfl⟩ := mem_cycleType_iff.1 hng suffices g'1 : g' = 1 by rw [hd.cycleType, hc.cycleType, coe_singleton, g'1, cycleType_one, add_zero] contrapose! hn2 with g'1 apply le_trans _ (c * g').support.card_le_univ rw [hd.card_support_mul] exact add_le_add_left (two_le_card_support_of_ne_one g'1) _ end CycleType theorem card_compl_support_modEq [DecidableEq α] {p n : ℕ} [hp : Fact p.Prime] {σ : Perm α} (hσ : σ ^ p ^ n = 1) : σ.supportᶜ.card ≡ Fintype.card α [MOD p] := by rw [Nat.modEq_iff_dvd', ← Finset.card_compl, compl_compl, ← sum_cycleType] · refine Multiset.dvd_sum fun k hk => ?_ obtain ⟨m, -, hm⟩ := (Nat.dvd_prime_pow hp.out).mp (orderOf_dvd_of_pow_eq_one hσ) obtain ⟨l, -, rfl⟩ := (Nat.dvd_prime_pow hp.out).mp ((congr_arg _ hm).mp (dvd_of_mem_cycleType hk)) exact dvd_pow_self _ fun h => (one_lt_of_mem_cycleType hk).ne <| by rw [h, pow_zero] · exact Finset.card_le_univ _ open Function in /-- The number of fixed points of a `p ^ n`-th root of the identity function over a finite set and the set's cardinality have the same residue modulo `p`, where `p` is a prime. -/ theorem card_fixedPoints_modEq [DecidableEq α] {f : Function.End α} {p n : ℕ} [hp : Fact p.Prime] (hf : f ^ p ^ n = 1) : Fintype.card α ≡ Fintype.card f.fixedPoints [MOD p] := by let σ : α ≃ α := ⟨f, f ^ (p ^ n - 1), leftInverse_iff_comp.mpr ((pow_sub_mul_pow f (Nat.one_le_pow n p hp.out.pos)).trans hf), leftInverse_iff_comp.mpr ((pow_mul_pow_sub f (Nat.one_le_pow n p hp.out.pos)).trans hf)⟩ have hσ : σ ^ p ^ n = 1 := by rw [DFunLike.ext'_iff, coe_pow] exact (hom_coe_pow (fun g : Function.End α ↦ g) rfl (fun g h ↦ rfl) f (p ^ n)).symm.trans hf suffices Fintype.card f.fixedPoints = (support σ)ᶜ.card from this ▸ (card_compl_support_modEq hσ).symm suffices f.fixedPoints = (support σ)ᶜ by simp only [this]; apply Fintype.card_coe simp [σ, Set.ext_iff, IsFixedPt] theorem exists_fixed_point_of_prime {p n : ℕ} [hp : Fact p.Prime] (hα : ¬p ∣ Fintype.card α) {σ : Perm α} (hσ : σ ^ p ^ n = 1) : ∃ a : α, σ a = a := by classical contrapose! hα simp_rw [← mem_support, ← Finset.eq_univ_iff_forall] at hα exact Nat.modEq_zero_iff_dvd.1 ((congr_arg _ (Finset.card_eq_zero.2 (compl_eq_bot.2 hα))).mp (card_compl_support_modEq hσ).symm) theorem exists_fixed_point_of_prime' {p n : ℕ} [hp : Fact p.Prime] (hα : p ∣ Fintype.card α) {σ : Perm α} (hσ : σ ^ p ^ n = 1) {a : α} (ha : σ a = a) : ∃ b : α, σ b = b ∧ b ≠ a := by classical have h : ∀ b : α, b ∈ σ.supportᶜ ↔ σ b = b := fun b => by rw [Finset.mem_compl, mem_support, Classical.not_not] obtain ⟨b, hb1, hb2⟩ := Finset.exists_ne_of_one_lt_card (hp.out.one_lt.trans_le (Nat.le_of_dvd (Finset.card_pos.mpr ⟨a, (h a).mpr ha⟩) (Nat.modEq_zero_iff_dvd.mp ((card_compl_support_modEq hσ).trans (Nat.modEq_zero_iff_dvd.mpr hα))))) a exact ⟨b, (h b).mp hb1, hb2⟩ theorem isCycle_of_prime_order' {σ : Perm α} (h1 : (orderOf σ).Prime) (h2 : Fintype.card α < 2 * orderOf σ) : σ.IsCycle := by classical exact isCycle_of_prime_order h1 (lt_of_le_of_lt σ.support.card_le_univ h2) theorem isCycle_of_prime_order'' {σ : Perm α} (h1 : (Fintype.card α).Prime) (h2 : orderOf σ = Fintype.card α) : σ.IsCycle := isCycle_of_prime_order' ((congr_arg Nat.Prime h2).mpr h1) <| by rw [← one_mul (Fintype.card α), ← h2, mul_lt_mul_right (orderOf_pos σ)] exact one_lt_two section Cauchy variable (G : Type*) [Group G] (n : ℕ) /-- The type of vectors with terms from `G`, length `n`, and product equal to `1:G`. -/ def vectorsProdEqOne : Set (Vector G n) := { v | v.toList.prod = 1 } namespace VectorsProdEqOne theorem mem_iff {n : ℕ} (v : Vector G n) : v ∈ vectorsProdEqOne G n ↔ v.toList.prod = 1 := Iff.rfl theorem zero_eq : vectorsProdEqOne G 0 = {Vector.nil} := Set.eq_singleton_iff_unique_mem.mpr ⟨Eq.refl (1 : G), fun v _ => v.eq_nil⟩ theorem one_eq : vectorsProdEqOne G 1 = {Vector.nil.cons 1} := by simp_rw [Set.eq_singleton_iff_unique_mem, mem_iff, Vector.toList_singleton, List.prod_singleton, Vector.head_cons, true_and] exact fun v hv => v.cons_head_tail.symm.trans (congr_arg₂ Vector.cons hv v.tail.eq_nil) instance zeroUnique : Unique (vectorsProdEqOne G 0) := by rw [zero_eq] exact Set.uniqueSingleton Vector.nil instance oneUnique : Unique (vectorsProdEqOne G 1) := by rw [one_eq] exact Set.uniqueSingleton (Vector.nil.cons 1) /-- Given a vector `v` of length `n`, make a vector of length `n + 1` whose product is `1`, by appending the inverse of the product of `v`. -/ @[simps] def vectorEquiv : Vector G n ≃ vectorsProdEqOne G (n + 1) where toFun v := ⟨v.toList.prod⁻¹ ::ᵥ v, by rw [mem_iff, Vector.toList_cons, List.prod_cons, inv_mul_self]⟩ invFun v := v.1.tail left_inv v := v.tail_cons v.toList.prod⁻¹ right_inv v := Subtype.ext <| calc v.1.tail.toList.prod⁻¹ ::ᵥ v.1.tail = v.1.head ::ᵥ v.1.tail := congr_arg (· ::ᵥ v.1.tail) <| Eq.symm <| eq_inv_of_mul_eq_one_left <| by rw [← List.prod_cons, ← Vector.toList_cons, v.1.cons_head_tail] exact v.2 _ = v.1 := v.1.cons_head_tail /-- Given a vector `v` of length `n` whose product is 1, make a vector of length `n - 1`, by deleting the last entry of `v`. -/ def equivVector : ∀ n, vectorsProdEqOne G n ≃ Vector G (n - 1) | 0 => (equivOfUnique (vectorsProdEqOne G 0) (vectorsProdEqOne G 1)).trans (vectorEquiv G 0).symm | (n + 1) => (vectorEquiv G n).symm instance [Fintype G] : Fintype (vectorsProdEqOne G n) := Fintype.ofEquiv (Vector G (n - 1)) (equivVector G n).symm theorem card [Fintype G] : Fintype.card (vectorsProdEqOne G n) = Fintype.card G ^ (n - 1) := (Fintype.card_congr (equivVector G n)).trans (card_vector (n - 1)) variable {G n} {g : G} variable (v : vectorsProdEqOne G n) (j k : ℕ) /-- Rotate a vector whose product is 1. -/ def rotate : vectorsProdEqOne G n := ⟨⟨_, (v.1.1.length_rotate k).trans v.1.2⟩, List.prod_rotate_eq_one_of_prod_eq_one v.2 k⟩ theorem rotate_zero : rotate v 0 = v := Subtype.ext (Subtype.ext v.1.1.rotate_zero) theorem rotate_rotate : rotate (rotate v j) k = rotate v (j + k) := Subtype.ext (Subtype.ext (v.1.1.rotate_rotate j k)) theorem rotate_length : rotate v n = v := Subtype.ext (Subtype.ext ((congr_arg _ v.1.2.symm).trans v.1.1.rotate_length)) end VectorsProdEqOne -- TODO: Make make the `Finite` version of this theorem the default /-- For every prime `p` dividing the order of a finite group `G` there exists an element of order `p` in `G`. This is known as Cauchy's theorem. -/ theorem _root_.exists_prime_orderOf_dvd_card {G : Type*} [Group G] [Fintype G] (p : ℕ) [hp : Fact p.Prime] (hdvd : p ∣ Fintype.card G) : ∃ x : G, orderOf x = p := by have hp' : p - 1 ≠ 0 := mt tsub_eq_zero_iff_le.mp (not_le_of_lt hp.out.one_lt) have Scard := calc p ∣ Fintype.card G ^ (p - 1) := hdvd.trans (dvd_pow (dvd_refl _) hp') _ = Fintype.card (vectorsProdEqOne G p) := (VectorsProdEqOne.card G p).symm let f : ℕ → vectorsProdEqOne G p → vectorsProdEqOne G p := fun k v => VectorsProdEqOne.rotate v k have hf1 : ∀ v, f 0 v = v := VectorsProdEqOne.rotate_zero have hf2 : ∀ j k v, f k (f j v) = f (j + k) v := fun j k v => VectorsProdEqOne.rotate_rotate v j k have hf3 : ∀ v, f p v = v := VectorsProdEqOne.rotate_length let σ := Equiv.mk (f 1) (f (p - 1)) (fun s => by rw [hf2, add_tsub_cancel_of_le hp.out.one_lt.le, hf3]) fun s => by rw [hf2, tsub_add_cancel_of_le hp.out.one_lt.le, hf3] have hσ : ∀ k v, (σ ^ k) v = f k v := fun k => Nat.rec (fun v => (hf1 v).symm) (fun k hk v => by rw [pow_succ, Perm.mul_apply, hk (σ v), Nat.succ_eq_one_add, ← hf2 1 k] simp only [σ, coe_fn_mk]) k replace hσ : σ ^ p ^ 1 = 1 := Perm.ext fun v => by rw [pow_one, hσ, hf3, one_apply] let v₀ : vectorsProdEqOne G p := ⟨Vector.replicate p 1, (List.prod_replicate p 1).trans (one_pow p)⟩ have hv₀ : σ v₀ = v₀ := Subtype.ext (Subtype.ext (List.rotate_replicate (1 : G) p 1)) obtain ⟨v, hv1, hv2⟩ := exists_fixed_point_of_prime' Scard hσ hv₀ refine Exists.imp (fun g hg => orderOf_eq_prime ?_ fun hg' => hv2 ?_) (List.rotate_one_eq_self_iff_eq_replicate.mp (Subtype.ext_iff.mp (Subtype.ext_iff.mp hv1))) · rw [← List.prod_replicate, ← v.1.2, ← hg, show v.val.val.prod = 1 from v.2] · rw [Subtype.ext_iff_val, Subtype.ext_iff_val, hg, hg', v.1.2] simp only [v₀, Vector.replicate] -- TODO: Make make the `Finite` version of this theorem the default /-- For every prime `p` dividing the order of a finite additive group `G` there exists an element of order `p` in `G`. This is the additive version of Cauchy's theorem. -/ theorem _root_.exists_prime_addOrderOf_dvd_card {G : Type*} [AddGroup G] [Fintype G] (p : ℕ) [hp : Fact p.Prime] (hdvd : p ∣ Fintype.card G) : ∃ x : G, addOrderOf x = p := @exists_prime_orderOf_dvd_card (Multiplicative G) _ _ _ _ (by convert hdvd) attribute [to_additive existing] exists_prime_orderOf_dvd_card -- TODO: Make make the `Finite` version of this theorem the default /-- For every prime `p` dividing the order of a finite group `G` there exists an element of order `p` in `G`. This is known as Cauchy's theorem. -/ @[to_additive] theorem _root_.exists_prime_orderOf_dvd_card' {G : Type*} [Group G] [Finite G] (p : ℕ) [hp : Fact p.Prime] (hdvd : p ∣ Nat.card G) : ∃ x : G, orderOf x = p := by have := Fintype.ofFinite G rw [Nat.card_eq_fintype_card] at hdvd exact exists_prime_orderOf_dvd_card p hdvd end Cauchy theorem subgroup_eq_top_of_swap_mem [DecidableEq α] {H : Subgroup (Perm α)} [d : DecidablePred (· ∈ H)] {τ : Perm α} (h0 : (Fintype.card α).Prime) (h1 : Fintype.card α ∣ Fintype.card H) (h2 : τ ∈ H) (h3 : IsSwap τ) : H = ⊤ := by haveI : Fact (Fintype.card α).Prime := ⟨h0⟩ obtain ⟨σ, hσ⟩ := exists_prime_orderOf_dvd_card (Fintype.card α) h1 have hσ1 : orderOf (σ : Perm α) = Fintype.card α := (Subgroup.orderOf_coe σ).trans hσ have hσ2 : IsCycle ↑σ := isCycle_of_prime_order'' h0 hσ1 have hσ3 : (σ : Perm α).support = ⊤ := Finset.eq_univ_of_card (σ : Perm α).support (hσ2.orderOf.symm.trans hσ1) have hσ4 : Subgroup.closure {↑σ, τ} = ⊤ := closure_prime_cycle_swap h0 hσ2 hσ3 h3 rw [eq_top_iff, ← hσ4, Subgroup.closure_le, Set.insert_subset_iff, Set.singleton_subset_iff] exact ⟨Subtype.mem σ, h2⟩ section Partition variable [DecidableEq α] /-- The partition corresponding to a permutation -/ def partition (σ : Perm α) : (Fintype.card α).Partition where parts := σ.cycleType + Multiset.replicate (Fintype.card α - σ.support.card) 1 parts_pos {n hn} := by cases' mem_add.mp hn with hn hn · exact zero_lt_one.trans (one_lt_of_mem_cycleType hn) · exact lt_of_lt_of_le zero_lt_one (ge_of_eq (Multiset.eq_of_mem_replicate hn)) parts_sum := by rw [sum_add, sum_cycleType, Multiset.sum_replicate, nsmul_eq_mul, Nat.cast_id, mul_one, add_tsub_cancel_of_le σ.support.card_le_univ] theorem parts_partition {σ : Perm α} : σ.partition.parts = σ.cycleType + Multiset.replicate (Fintype.card α - σ.support.card) 1 := rfl theorem filter_parts_partition_eq_cycleType {σ : Perm α} : ((partition σ).parts.filter fun n => 2 ≤ n) = σ.cycleType := by rw [parts_partition, filter_add, Multiset.filter_eq_self.2 fun _ => two_le_of_mem_cycleType, Multiset.filter_eq_nil.2 fun a h => ?_, add_zero] rw [Multiset.eq_of_mem_replicate h] decide theorem partition_eq_of_isConj {σ τ : Perm α} : IsConj σ τ ↔ σ.partition = τ.partition := by rw [isConj_iff_cycleType_eq] refine ⟨fun h => ?_, fun h => ?_⟩ · rw [Nat.Partition.ext_iff, parts_partition, parts_partition, ← sum_cycleType, ← sum_cycleType, h] · rw [← filter_parts_partition_eq_cycleType, ← filter_parts_partition_eq_cycleType, h] end Partition /-! ### 3-cycles -/ /-- A three-cycle is a cycle of length 3. -/ def IsThreeCycle [DecidableEq α] (σ : Perm α) : Prop := σ.cycleType = {3} namespace IsThreeCycle variable [DecidableEq α] {σ : Perm α} theorem cycleType (h : IsThreeCycle σ) : σ.cycleType = {3} := h theorem card_support (h : IsThreeCycle σ) : σ.support.card = 3 := by rw [← sum_cycleType, h.cycleType, Multiset.sum_singleton] theorem _root_.card_support_eq_three_iff : σ.support.card = 3 ↔ σ.IsThreeCycle := by refine ⟨fun h => ?_, IsThreeCycle.card_support⟩ by_cases h0 : σ.cycleType = 0 · rw [← sum_cycleType, h0, sum_zero] at h exact (ne_of_lt zero_lt_three h).elim obtain ⟨n, hn⟩ := exists_mem_of_ne_zero h0 by_cases h1 : σ.cycleType.erase n = 0 · rw [← sum_cycleType, ← cons_erase hn, h1, cons_zero, Multiset.sum_singleton] at h rw [IsThreeCycle, ← cons_erase hn, h1, h, ← cons_zero] obtain ⟨m, hm⟩ := exists_mem_of_ne_zero h1 rw [← sum_cycleType, ← cons_erase hn, ← cons_erase hm, Multiset.sum_cons, Multiset.sum_cons] at h have : ∀ {k}, 2 ≤ m → 2 ≤ n → n + (m + k) = 3 → False := by omega cases this (two_le_of_mem_cycleType (mem_of_mem_erase hm)) (two_le_of_mem_cycleType hn) h theorem isCycle (h : IsThreeCycle σ) : IsCycle σ := by rw [← card_cycleType_eq_one, h.cycleType, card_singleton] theorem sign (h : IsThreeCycle σ) : sign σ = 1 := by rw [Equiv.Perm.sign_of_cycleType, h.cycleType] rfl theorem inv {f : Perm α} (h : IsThreeCycle f) : IsThreeCycle f⁻¹ := by rwa [IsThreeCycle, cycleType_inv] @[simp] theorem inv_iff {f : Perm α} : IsThreeCycle f⁻¹ ↔ IsThreeCycle f := ⟨by rw [← inv_inv f] apply inv, inv⟩ theorem orderOf {g : Perm α} (ht : IsThreeCycle g) : orderOf g = 3 := by rw [← lcm_cycleType, ht.cycleType, Multiset.lcm_singleton, normalize_eq] theorem isThreeCycle_sq {g : Perm α} (ht : IsThreeCycle g) : IsThreeCycle (g * g) := by rw [← pow_two, ← card_support_eq_three_iff, support_pow_coprime, ht.card_support] rw [ht.orderOf] norm_num end IsThreeCycle section variable [DecidableEq α] theorem isThreeCycle_swap_mul_swap_same {a b c : α} (ab : a ≠ b) (ac : a ≠ c) (bc : b ≠ c) : IsThreeCycle (swap a b * swap a c) := by suffices h : support (swap a b * swap a c) = {a, b, c} by rw [← card_support_eq_three_iff, h] simp [ab, ac, bc] apply le_antisymm ((support_mul_le _ _).trans fun x => _) fun x hx => ?_ · simp [ab, ac, bc] · simp only [Finset.mem_insert, Finset.mem_singleton] at hx rw [mem_support] simp only [Perm.coe_mul, Function.comp_apply, Ne] obtain rfl | rfl | rfl := hx · rw [swap_apply_left, swap_apply_of_ne_of_ne ac.symm bc.symm] exact ac.symm · rw [swap_apply_of_ne_of_ne ab.symm bc, swap_apply_right] exact ab · rw [swap_apply_right, swap_apply_left] exact bc open Subgroup theorem swap_mul_swap_same_mem_closure_three_cycles {a b c : α} (ab : a ≠ b) (ac : a ≠ c) : swap a b * swap a c ∈ closure { σ : Perm α | IsThreeCycle σ } := by by_cases bc : b = c · subst bc simp [one_mem] exact subset_closure (isThreeCycle_swap_mul_swap_same ab ac bc) theorem IsSwap.mul_mem_closure_three_cycles {σ τ : Perm α} (hσ : IsSwap σ) (hτ : IsSwap τ) : σ * τ ∈ closure { σ : Perm α | IsThreeCycle σ } := by obtain ⟨a, b, ab, rfl⟩ := hσ obtain ⟨c, d, cd, rfl⟩ := hτ by_cases ac : a = c · subst ac exact swap_mul_swap_same_mem_closure_three_cycles ab cd have h' : swap a b * swap c d = swap a b * swap a c * (swap c a * swap c d) := by simp [swap_comm c a, mul_assoc] rw [h'] exact mul_mem (swap_mul_swap_same_mem_closure_three_cycles ab ac) (swap_mul_swap_same_mem_closure_three_cycles (Ne.symm ac) cd) end end Equiv.Perm
GroupTheory\SpecificGroups\Alternating.lean
/- Copyright (c) 2021 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.Algebra.Group.ConjFinite import Mathlib.GroupTheory.Perm.Fin import Mathlib.GroupTheory.Subgroup.Simple import Mathlib.Tactic.IntervalCases /-! # Alternating Groups The alternating group on a finite type `α` is the subgroup of the permutation group `Perm α` consisting of the even permutations. ## Main definitions * `alternatingGroup α` is the alternating group on `α`, defined as a `Subgroup (Perm α)`. ## Main results * `two_mul_card_alternatingGroup` shows that the alternating group is half as large as the permutation group it is a subgroup of. * `closure_three_cycles_eq_alternating` shows that the alternating group is generated by 3-cycles. * `alternatingGroup.isSimpleGroup_five` shows that the alternating group on `Fin 5` is simple. The proof shows that the normal closure of any non-identity element of this group contains a 3-cycle. ## Tags alternating group permutation ## TODO * Show that `alternatingGroup α` is simple if and only if `Fintype.card α ≠ 4`. -/ -- An example on how to determine the order of an element of a finite group. example : orderOf (-1 : ℤˣ) = 2 := orderOf_eq_prime (Int.units_sq _) (by decide) open Equiv Equiv.Perm Subgroup Fintype variable (α : Type*) [Fintype α] [DecidableEq α] /-- The alternating group on a finite type, realized as a subgroup of `Equiv.Perm`. For $A_n$, use `alternatingGroup (Fin n)`. -/ def alternatingGroup : Subgroup (Perm α) := sign.ker -- Porting note (#10754): manually added instance instance alternatingGroup.instFintype : Fintype (alternatingGroup α) := @Subtype.fintype _ _ sign.decidableMemKer _ instance [Subsingleton α] : Unique (alternatingGroup α) := ⟨⟨1⟩, fun ⟨p, _⟩ => Subtype.eq (Subsingleton.elim p _)⟩ variable {α} theorem alternatingGroup_eq_sign_ker : alternatingGroup α = sign.ker := rfl namespace Equiv.Perm @[simp] theorem mem_alternatingGroup {f : Perm α} : f ∈ alternatingGroup α ↔ sign f = 1 := sign.mem_ker theorem prod_list_swap_mem_alternatingGroup_iff_even_length {l : List (Perm α)} (hl : ∀ g ∈ l, IsSwap g) : l.prod ∈ alternatingGroup α ↔ Even l.length := by rw [mem_alternatingGroup, sign_prod_list_swap hl, neg_one_pow_eq_one_iff_even] decide theorem IsThreeCycle.mem_alternatingGroup {f : Perm α} (h : IsThreeCycle f) : f ∈ alternatingGroup α := Perm.mem_alternatingGroup.mpr h.sign set_option linter.deprecated false in theorem finRotate_bit1_mem_alternatingGroup {n : ℕ} : finRotate (2 * n + 1) ∈ alternatingGroup (Fin (2 * n + 1)) := by rw [mem_alternatingGroup, sign_finRotate, pow_mul, pow_two, Int.units_mul_self, one_pow] end Equiv.Perm theorem two_mul_card_alternatingGroup [Nontrivial α] : 2 * card (alternatingGroup α) = card (Perm α) := by let this := (QuotientGroup.quotientKerEquivOfSurjective _ (sign_surjective α)).toEquiv rw [← Fintype.card_units_int, ← Fintype.card_congr this] simp only [← Nat.card_eq_fintype_card] apply (Subgroup.card_eq_card_quotient_mul_card_subgroup _).symm namespace alternatingGroup open Equiv.Perm instance normal : (alternatingGroup α).Normal := sign.normal_ker theorem isConj_of {σ τ : alternatingGroup α} (hc : IsConj (σ : Perm α) (τ : Perm α)) (hσ : (σ : Perm α).support.card + 2 ≤ Fintype.card α) : IsConj σ τ := by obtain ⟨σ, hσ⟩ := σ obtain ⟨τ, hτ⟩ := τ obtain ⟨π, hπ⟩ := isConj_iff.1 hc rw [Subtype.coe_mk, Subtype.coe_mk] at hπ cases' Int.units_eq_one_or (Perm.sign π) with h h · rw [isConj_iff] refine ⟨⟨π, mem_alternatingGroup.mp h⟩, Subtype.val_injective ?_⟩ simpa only [Subtype.val, Subgroup.coe_mul, coe_inv, coe_mk] using hπ · have h2 : 2 ≤ σ.supportᶜ.card := by rw [Finset.card_compl, le_tsub_iff_left σ.support.card_le_univ] exact hσ obtain ⟨a, ha, b, hb, ab⟩ := Finset.one_lt_card.1 h2 refine isConj_iff.2 ⟨⟨π * swap a b, ?_⟩, Subtype.val_injective ?_⟩ · rw [mem_alternatingGroup, MonoidHom.map_mul, h, sign_swap ab, Int.units_mul_self] · simp only [← hπ, coe_mk, Subgroup.coe_mul, Subtype.val] have hd : Disjoint (swap a b) σ := by rw [disjoint_iff_disjoint_support, support_swap ab, Finset.disjoint_insert_left, Finset.disjoint_singleton_left] exact ⟨Finset.mem_compl.1 ha, Finset.mem_compl.1 hb⟩ rw [mul_assoc π _ σ, hd.commute.eq, coe_inv, coe_mk] simp [mul_assoc] theorem isThreeCycle_isConj (h5 : 5 ≤ Fintype.card α) {σ τ : alternatingGroup α} (hσ : IsThreeCycle (σ : Perm α)) (hτ : IsThreeCycle (τ : Perm α)) : IsConj σ τ := alternatingGroup.isConj_of (isConj_iff_cycleType_eq.2 (hσ.trans hτ.symm)) (by rwa [hσ.card_support]) end alternatingGroup namespace Equiv.Perm open alternatingGroup @[simp] theorem closure_three_cycles_eq_alternating : closure { σ : Perm α | IsThreeCycle σ } = alternatingGroup α := closure_eq_of_le _ (fun σ hσ => mem_alternatingGroup.2 hσ.sign) fun σ hσ => by suffices hind : ∀ (n : ℕ) (l : List (Perm α)) (_ : ∀ g, g ∈ l → IsSwap g) (_ : l.length = 2 * n), l.prod ∈ closure { σ : Perm α | IsThreeCycle σ } by obtain ⟨l, rfl, hl⟩ := truncSwapFactors σ obtain ⟨n, hn⟩ := (prod_list_swap_mem_alternatingGroup_iff_even_length hl).1 hσ rw [← two_mul] at hn exact hind n l hl hn intro n induction' n with n ih <;> intro l hl hn · simp [List.length_eq_zero.1 hn, one_mem] rw [Nat.mul_succ] at hn obtain ⟨a, l, rfl⟩ := l.exists_of_length_succ hn rw [List.length_cons, Nat.succ_inj'] at hn obtain ⟨b, l, rfl⟩ := l.exists_of_length_succ hn rw [List.prod_cons, List.prod_cons, ← mul_assoc] rw [List.length_cons, Nat.succ_inj'] at hn exact mul_mem (IsSwap.mul_mem_closure_three_cycles (hl a (List.mem_cons_self a _)) (hl b (List.mem_cons_of_mem a (l.mem_cons_self b)))) (ih _ (fun g hg => hl g (List.mem_cons_of_mem _ (List.mem_cons_of_mem _ hg))) hn) /-- A key lemma to prove $A_5$ is simple. Shows that any normal subgroup of an alternating group on at least 5 elements is the entire alternating group if it contains a 3-cycle. -/ theorem IsThreeCycle.alternating_normalClosure (h5 : 5 ≤ Fintype.card α) {f : Perm α} (hf : IsThreeCycle f) : normalClosure ({⟨f, hf.mem_alternatingGroup⟩} : Set (alternatingGroup α)) = ⊤ := eq_top_iff.2 (by have hi : Function.Injective (alternatingGroup α).subtype := Subtype.coe_injective refine eq_top_iff.1 (map_injective hi (le_antisymm (map_mono le_top) ?_)) rw [← MonoidHom.range_eq_map, subtype_range, normalClosure, MonoidHom.map_closure] refine (le_of_eq closure_three_cycles_eq_alternating.symm).trans (closure_mono ?_) intro g h obtain ⟨c, rfl⟩ := isConj_iff.1 (isConj_iff_cycleType_eq.2 (hf.trans h.symm)) refine ⟨⟨c * f * c⁻¹, h.mem_alternatingGroup⟩, ?_, rfl⟩ rw [Group.mem_conjugatesOfSet_iff] exact ⟨⟨f, hf.mem_alternatingGroup⟩, Set.mem_singleton _, isThreeCycle_isConj h5 hf h⟩) /-- Part of proving $A_5$ is simple. Shows that the square of any element of $A_5$ with a 3-cycle in its cycle decomposition is a 3-cycle, so the normal closure of the original element must be $A_5$. -/ theorem isThreeCycle_sq_of_three_mem_cycleType_five {g : Perm (Fin 5)} (h : 3 ∈ cycleType g) : IsThreeCycle (g * g) := by obtain ⟨c, g', rfl, hd, _, h3⟩ := mem_cycleType_iff.1 h simp only [mul_assoc] rw [hd.commute.eq, ← mul_assoc g'] suffices hg' : orderOf g' ∣ 2 by rw [← pow_two, orderOf_dvd_iff_pow_eq_one.1 hg', one_mul] exact (card_support_eq_three_iff.1 h3).isThreeCycle_sq rw [← lcm_cycleType, Multiset.lcm_dvd] intro n hn rw [le_antisymm (two_le_of_mem_cycleType hn) (le_trans (le_card_support_of_mem_cycleType hn) _)] apply le_of_add_le_add_left rw [← hd.card_support_mul, h3] exact (c * g').support.card_le_univ end Equiv.Perm namespace alternatingGroup open Equiv.Perm theorem nontrivial_of_three_le_card (h3 : 3 ≤ card α) : Nontrivial (alternatingGroup α) := by haveI := Fintype.one_lt_card_iff_nontrivial.1 (lt_trans (by decide) h3) rw [← Fintype.one_lt_card_iff_nontrivial] refine lt_of_mul_lt_mul_left ?_ (le_of_lt Nat.prime_two.pos) rw [two_mul_card_alternatingGroup, card_perm, ← Nat.succ_le_iff] exact le_trans h3 (card α).self_le_factorial instance {n : ℕ} : Nontrivial (alternatingGroup (Fin (n + 3))) := nontrivial_of_three_le_card (by rw [card_fin] exact le_add_left (le_refl 3)) /-- The normal closure of the 5-cycle `finRotate 5` within $A_5$ is the whole group. This will be used to show that the normal closure of any 5-cycle within $A_5$ is the whole group. -/ theorem normalClosure_finRotate_five : normalClosure ({⟨finRotate 5, finRotate_bit1_mem_alternatingGroup (n := 2)⟩} : Set (alternatingGroup (Fin 5))) = ⊤ := eq_top_iff.2 (by have h3 : IsThreeCycle (Fin.cycleRange 2 * finRotate 5 * (Fin.cycleRange 2)⁻¹ * (finRotate 5)⁻¹) := card_support_eq_three_iff.1 (by decide) rw [← h3.alternating_normalClosure (by rw [card_fin])] refine normalClosure_le_normal ?_ rw [Set.singleton_subset_iff, SetLike.mem_coe] have h : (⟨finRotate 5, finRotate_bit1_mem_alternatingGroup (n := 2)⟩ : alternatingGroup (Fin 5)) ∈ normalClosure _ := SetLike.mem_coe.1 (subset_normalClosure (Set.mem_singleton _)) exact (mul_mem (Subgroup.normalClosure_normal.conj_mem _ h -- Porting note: added `: _` ⟨Fin.cycleRange 2, Fin.isThreeCycle_cycleRange_two.mem_alternatingGroup⟩) (inv_mem h) : _)) /-- The normal closure of $(04)(13)$ within $A_5$ is the whole group. This will be used to show that the normal closure of any permutation of cycle type $(2,2)$ is the whole group. -/ theorem normalClosure_swap_mul_swap_five : normalClosure ({⟨swap 0 4 * swap 1 3, mem_alternatingGroup.2 (by decide)⟩} : Set (alternatingGroup (Fin 5))) = ⊤ := by let g1 := (⟨swap 0 2 * swap 0 1, mem_alternatingGroup.2 (by decide)⟩ : alternatingGroup (Fin 5)) let g2 := (⟨swap 0 4 * swap 1 3, mem_alternatingGroup.2 (by decide)⟩ : alternatingGroup (Fin 5)) have h5 : g1 * g2 * g1⁻¹ * g2⁻¹ = ⟨finRotate 5, finRotate_bit1_mem_alternatingGroup (n := 2)⟩ := by rw [Subtype.ext_iff] simp only [Fin.val_mk, Subgroup.coe_mul, Subgroup.coe_inv, Fin.val_mk] decide rw [eq_top_iff, ← normalClosure_finRotate_five] refine normalClosure_le_normal ?_ rw [Set.singleton_subset_iff, SetLike.mem_coe, ← h5] have h : g2 ∈ normalClosure {g2} := SetLike.mem_coe.1 (subset_normalClosure (Set.mem_singleton _)) exact mul_mem (Subgroup.normalClosure_normal.conj_mem _ h g1) (inv_mem h) /-- Shows that any non-identity element of $A_5$ whose cycle decomposition consists only of swaps is conjugate to $(04)(13)$. This is used to show that the normal closure of such a permutation in $A_5$ is $A_5$. -/ theorem isConj_swap_mul_swap_of_cycleType_two {g : Perm (Fin 5)} (ha : g ∈ alternatingGroup (Fin 5)) (h1 : g ≠ 1) (h2 : ∀ n, n ∈ cycleType (g : Perm (Fin 5)) → n = 2) : IsConj (swap 0 4 * swap 1 3) g := by have h := g.support.card_le_univ rw [← Multiset.eq_replicate_card] at h2 rw [← sum_cycleType, h2, Multiset.sum_replicate, smul_eq_mul] at h have h : Multiset.card g.cycleType ≤ 3 := le_of_mul_le_mul_right (le_trans h (by simp only [card_fin]; ring_nf; decide)) (by simp) rw [mem_alternatingGroup, sign_of_cycleType, h2] at ha norm_num at ha rw [pow_add, pow_mul, Int.units_pow_two, one_mul, neg_one_pow_eq_one_iff_even] at ha swap; · decide rw [isConj_iff_cycleType_eq, h2] interval_cases h_1 : Multiset.card g.cycleType · exact (h1 (card_cycleType_eq_zero.1 h_1)).elim · simp at ha · have h04 : (0 : Fin 5) ≠ 4 := by decide have h13 : (1 : Fin 5) ≠ 3 := by decide rw [Disjoint.cycleType, (isCycle_swap h04).cycleType, (isCycle_swap h13).cycleType, card_support_swap h04, card_support_swap h13] · rfl · rw [disjoint_iff_disjoint_support, support_swap h04, support_swap h13] decide · contradiction /-- Shows that $A_5$ is simple by taking an arbitrary non-identity element and showing by casework on its cycle type that its normal closure is all of $A_5$. -/ instance isSimpleGroup_five : IsSimpleGroup (alternatingGroup (Fin 5)) := ⟨fun H => by intro Hn refine or_not.imp id fun Hb => ?_ rw [eq_bot_iff_forall] at Hb push_neg at Hb obtain ⟨⟨g, gA⟩, gH, g1⟩ : ∃ x : ↥(alternatingGroup (Fin 5)), x ∈ H ∧ x ≠ 1 := Hb -- `g` is a non-identity alternating permutation in a normal subgroup `H` of $A_5$. rw [← SetLike.mem_coe, ← Set.singleton_subset_iff] at gH refine eq_top_iff.2 (le_trans (ge_of_eq ?_) (normalClosure_le_normal gH)) -- It suffices to show that the normal closure of `g` in $A_5$ is $A_5$. by_cases h2 : ∀ n ∈ g.cycleType, n = 2 -- If the cycle decomposition of `g` consists entirely of swaps, then the cycle type is $(2,2)$. -- This means that it is conjugate to $(04)(13)$, whose normal closure is $A_5$. · rw [Ne, Subtype.ext_iff] at g1 exact (isConj_swap_mul_swap_of_cycleType_two gA g1 h2).normalClosure_eq_top_of normalClosure_swap_mul_swap_five push_neg at h2 obtain ⟨n, ng, n2⟩ : ∃ n : ℕ, n ∈ g.cycleType ∧ n ≠ 2 := h2 -- `n` is the size of a non-swap cycle in the decomposition of `g`. have n2' : 2 < n := lt_of_le_of_ne (two_le_of_mem_cycleType ng) n2.symm have n5 : n ≤ 5 := le_trans ?_ g.support.card_le_univ -- We check that `2 < n ≤ 5`, so that `interval_cases` has a precise range to check. swap · obtain ⟨m, hm⟩ := Multiset.exists_cons_of_mem ng rw [← sum_cycleType, hm, Multiset.sum_cons] exact le_add_right le_rfl interval_cases n -- This breaks into cases `n = 3`, `n = 4`, `n = 5`. -- If `n = 3`, then `g` has a 3-cycle in its decomposition, so `g^2` is a 3-cycle. -- `g^2` is in the normal closure of `g`, so that normal closure must be $A_5$. · rw [eq_top_iff, ← (isThreeCycle_sq_of_three_mem_cycleType_five ng).alternating_normalClosure (by rw [card_fin])] refine normalClosure_le_normal ?_ rw [Set.singleton_subset_iff, SetLike.mem_coe] have h := SetLike.mem_coe.1 (subset_normalClosure (G := alternatingGroup (Fin 5)) (Set.mem_singleton ⟨g, gA⟩)) exact mul_mem h h · -- The case `n = 4` leads to contradiction, as no element of $A_5$ includes a 4-cycle. have con := mem_alternatingGroup.1 gA rw [sign_of_cycleType, cycleType_of_card_le_mem_cycleType_add_two (by decide) ng] at con have : Odd 5 := by decide simp [this] at con · -- If `n = 5`, then `g` is itself a 5-cycle, conjugate to `finRotate 5`. refine (isConj_iff_cycleType_eq.2 ?_).normalClosure_eq_top_of normalClosure_finRotate_five rw [cycleType_of_card_le_mem_cycleType_add_two (by decide) ng, cycleType_finRotate]⟩ end alternatingGroup
GroupTheory\SpecificGroups\Cyclic.lean
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl -/ import Mathlib.Algebra.Order.BigOperators.Ring.Finset import Mathlib.Data.Nat.Totient import Mathlib.Data.ZMod.Quotient import Mathlib.GroupTheory.OrderOfElement import Mathlib.GroupTheory.Subgroup.Simple import Mathlib.Tactic.Group import Mathlib.GroupTheory.Exponent /-! # Cyclic groups A group `G` is called cyclic if there exists an element `g : G` such that every element of `G` is of the form `g ^ n` for some `n : ℕ`. This file only deals with the predicate on a group to be cyclic. For the concrete cyclic group of order `n`, see `Data.ZMod.Basic`. ## Main definitions * `IsCyclic` is a predicate on a group stating that the group is cyclic. ## Main statements * `isCyclic_of_prime_card` proves that a finite group of prime order is cyclic. * `isSimpleGroup_of_prime_card`, `IsSimpleGroup.isCyclic`, and `IsSimpleGroup.prime_card` classify finite simple abelian groups. * `IsCyclic.exponent_eq_card`: For a finite cyclic group `G`, the exponent is equal to the group's cardinality. * `IsCyclic.exponent_eq_zero_of_infinite`: Infinite cyclic groups have exponent zero. * `IsCyclic.iff_exponent_eq_card`: A finite commutative group is cyclic iff its exponent is equal to its cardinality. ## Tags cyclic group -/ universe u variable {α : Type u} {a : α} section Cyclic attribute [local instance] setFintype open Subgroup /-- A group is called *cyclic* if it is generated by a single element. -/ class IsAddCyclic (α : Type u) [AddGroup α] : Prop where exists_generator : ∃ g : α, ∀ x, x ∈ AddSubgroup.zmultiples g /-- A group is called *cyclic* if it is generated by a single element. -/ @[to_additive] class IsCyclic (α : Type u) [Group α] : Prop where exists_generator : ∃ g : α, ∀ x, x ∈ zpowers g @[to_additive] instance (priority := 100) isCyclic_of_subsingleton [Group α] [Subsingleton α] : IsCyclic α := ⟨⟨1, fun x => by rw [Subsingleton.elim x 1] exact mem_zpowers 1⟩⟩ @[simp] theorem isCyclic_multiplicative_iff [AddGroup α] : IsCyclic (Multiplicative α) ↔ IsAddCyclic α := ⟨fun H ↦ ⟨H.1⟩, fun H ↦ ⟨H.1⟩⟩ instance isCyclic_multiplicative [AddGroup α] [IsAddCyclic α] : IsCyclic (Multiplicative α) := isCyclic_multiplicative_iff.mpr inferInstance @[simp] theorem isAddCyclic_additive_iff [Group α] : IsAddCyclic (Additive α) ↔ IsCyclic α := ⟨fun H ↦ ⟨H.1⟩, fun H ↦ ⟨H.1⟩⟩ instance isAddCyclic_additive [Group α] [IsCyclic α] : IsAddCyclic (Additive α) := isAddCyclic_additive_iff.mpr inferInstance /-- A cyclic group is always commutative. This is not an `instance` because often we have a better proof of `CommGroup`. -/ @[to_additive "A cyclic group is always commutative. This is not an `instance` because often we have a better proof of `AddCommGroup`."] def IsCyclic.commGroup [hg : Group α] [IsCyclic α] : CommGroup α := { hg with mul_comm := fun x y => let ⟨_, hg⟩ := IsCyclic.exists_generator (α := α) let ⟨_, hn⟩ := hg x let ⟨_, hm⟩ := hg y hm ▸ hn ▸ zpow_mul_comm _ _ _ } variable [Group α] /-- A non-cyclic multiplicative group is non-trivial. -/ @[to_additive "A non-cyclic additive group is non-trivial."] theorem Nontrivial.of_not_isCyclic (nc : ¬IsCyclic α) : Nontrivial α := by contrapose! nc exact @isCyclic_of_subsingleton _ _ (not_nontrivial_iff_subsingleton.mp nc) @[to_additive] theorem MonoidHom.map_cyclic {G : Type*} [Group G] [h : IsCyclic G] (σ : G →* G) : ∃ m : ℤ, ∀ g : G, σ g = g ^ m := by obtain ⟨h, hG⟩ := IsCyclic.exists_generator (α := G) obtain ⟨m, hm⟩ := hG (σ h) refine ⟨m, fun g => ?_⟩ obtain ⟨n, rfl⟩ := hG g rw [MonoidHom.map_zpow, ← hm, ← zpow_mul, ← zpow_mul'] @[deprecated (since := "2024-02-21")] alias MonoidAddHom.map_add_cyclic := AddMonoidHom.map_addCyclic @[to_additive] theorem isCyclic_of_orderOf_eq_card [Fintype α] (x : α) (hx : orderOf x = Fintype.card α) : IsCyclic α := by classical use x simp_rw [← SetLike.mem_coe, ← Set.eq_univ_iff_forall] rw [← Fintype.card_congr (Equiv.Set.univ α), ← Fintype.card_zpowers] at hx exact Set.eq_of_subset_of_card_le (Set.subset_univ _) (ge_of_eq hx) @[deprecated (since := "2024-02-21")] alias isAddCyclic_of_orderOf_eq_card := isAddCyclic_of_addOrderOf_eq_card @[to_additive] theorem Subgroup.eq_bot_or_eq_top_of_prime_card {G : Type*} [Group G] {_ : Fintype G} (H : Subgroup G) [hp : Fact (Fintype.card G).Prime] : H = ⊥ ∨ H = ⊤ := by classical have := card_subgroup_dvd_card H rwa [Nat.card_eq_fintype_card (α := G), Nat.dvd_prime hp.1, ← Nat.card_eq_fintype_card, ← eq_bot_iff_card, card_eq_iff_eq_top] at this /-- Any non-identity element of a finite group of prime order generates the group. -/ @[to_additive "Any non-identity element of a finite group of prime order generates the group."] theorem zpowers_eq_top_of_prime_card {G : Type*} [Group G] {_ : Fintype G} {p : ℕ} [hp : Fact p.Prime] (h : Fintype.card G = p) {g : G} (hg : g ≠ 1) : zpowers g = ⊤ := by subst h have := (zpowers g).eq_bot_or_eq_top_of_prime_card rwa [zpowers_eq_bot, or_iff_right hg] at this @[to_additive] theorem mem_zpowers_of_prime_card {G : Type*} [Group G] {_ : Fintype G} {p : ℕ} [hp : Fact p.Prime] (h : Fintype.card G = p) {g g' : G} (hg : g ≠ 1) : g' ∈ zpowers g := by simp_rw [zpowers_eq_top_of_prime_card h hg, Subgroup.mem_top] @[to_additive] theorem mem_powers_of_prime_card {G : Type*} [Group G] {_ : Fintype G} {p : ℕ} [hp : Fact p.Prime] (h : Fintype.card G = p) {g g' : G} (hg : g ≠ 1) : g' ∈ Submonoid.powers g := by rw [mem_powers_iff_mem_zpowers] exact mem_zpowers_of_prime_card h hg @[to_additive] theorem powers_eq_top_of_prime_card {G : Type*} [Group G] {_ : Fintype G} {p : ℕ} [hp : Fact p.Prime] (h : Fintype.card G = p) {g : G} (hg : g ≠ 1) : Submonoid.powers g = ⊤ := by ext x simp [mem_powers_of_prime_card h hg] /-- A finite group of prime order is cyclic. -/ @[to_additive "A finite group of prime order is cyclic."] theorem isCyclic_of_prime_card {α : Type u} [Group α] [Fintype α] {p : ℕ} [hp : Fact p.Prime] (h : Fintype.card α = p) : IsCyclic α := by obtain ⟨g, hg⟩ : ∃ g, g ≠ 1 := Fintype.exists_ne_of_one_lt_card (h.symm ▸ hp.1.one_lt) 1 exact ⟨g, fun g' ↦ mem_zpowers_of_prime_card h hg⟩ /-- A finite group of order dividing a prime is cyclic. -/ @[to_additive "A finite group of order dividing a prime is cyclic."] theorem isCyclic_of_card_dvd_prime {α : Type u} [Group α] {p : ℕ} [hp : Fact p.Prime] (h : Nat.card α ∣ p) : IsCyclic α := by have : Finite α := Nat.finite_of_card_ne_zero (ne_zero_of_dvd_ne_zero hp.1.ne_zero h) rcases (Nat.dvd_prime hp.out).mp h with h | h · exact @isCyclic_of_subsingleton α _ (Nat.card_eq_one_iff_unique.mp h).1 · have : Fintype α := Fintype.ofFinite α rw [Nat.card_eq_fintype_card] at h exact isCyclic_of_prime_card h @[to_additive] theorem isCyclic_of_surjective {H G F : Type*} [Group H] [Group G] [hH : IsCyclic H] [FunLike F H G] [MonoidHomClass F H G] (f : F) (hf : Function.Surjective f) : IsCyclic G := by obtain ⟨x, hx⟩ := hH refine ⟨f x, fun a ↦ ?_⟩ obtain ⟨a, rfl⟩ := hf a obtain ⟨n, rfl⟩ := hx a exact ⟨n, (map_zpow _ _ _).symm⟩ @[to_additive] theorem orderOf_eq_card_of_forall_mem_zpowers [Fintype α] {g : α} (hx : ∀ x, x ∈ zpowers g) : orderOf g = Fintype.card α := by classical rw [← Fintype.card_zpowers] apply Fintype.card_of_finset' simpa using hx @[to_additive] lemma orderOf_generator_eq_natCard (h : ∀ x, x ∈ Subgroup.zpowers a) : orderOf a = Nat.card α := Nat.card_zpowers a ▸ (Nat.card_congr <| Equiv.subtypeUnivEquiv h) @[to_additive] theorem exists_pow_ne_one_of_isCyclic {G : Type*} [Group G] [Fintype G] [G_cyclic : IsCyclic G] {k : ℕ} (k_pos : k ≠ 0) (k_lt_card_G : k < Fintype.card G) : ∃ a : G, a ^ k ≠ 1 := by rcases G_cyclic with ⟨a, ha⟩ use a contrapose! k_lt_card_G convert orderOf_le_of_pow_eq_one k_pos.bot_lt k_lt_card_G rw [← Nat.card_eq_fintype_card, ← Nat.card_zpowers, eq_comm, card_eq_iff_eq_top, eq_top_iff] exact fun x _ ↦ ha x @[to_additive] theorem Infinite.orderOf_eq_zero_of_forall_mem_zpowers [Infinite α] {g : α} (h : ∀ x, x ∈ zpowers g) : orderOf g = 0 := by classical rw [orderOf_eq_zero_iff'] refine fun n hn hgn => ?_ have ho := isOfFinOrder_iff_pow_eq_one.mpr ⟨n, hn, hgn⟩ obtain ⟨x, hx⟩ := Infinite.exists_not_mem_finset (Finset.image (fun x => g ^ x) <| Finset.range <| orderOf g) apply hx rw [← ho.mem_powers_iff_mem_range_orderOf, Submonoid.mem_powers_iff] obtain ⟨k, hk⟩ := h x dsimp at hk obtain ⟨k, rfl | rfl⟩ := k.eq_nat_or_neg · exact ⟨k, mod_cast hk⟩ rw [← zpow_mod_orderOf] at hk have : 0 ≤ (-k % orderOf g : ℤ) := Int.emod_nonneg (-k) (mod_cast ho.orderOf_pos.ne') refine ⟨(-k % orderOf g : ℤ).toNat, ?_⟩ rwa [← zpow_natCast, Int.toNat_of_nonneg this] @[to_additive] instance Bot.isCyclic {α : Type u} [Group α] : IsCyclic (⊥ : Subgroup α) := ⟨⟨1, fun x => ⟨0, Subtype.eq <| (zpow_zero (1 : α)).trans <| Eq.symm (Subgroup.mem_bot.1 x.2)⟩⟩⟩ @[to_additive] instance Subgroup.isCyclic {α : Type u} [Group α] [IsCyclic α] (H : Subgroup α) : IsCyclic H := haveI := Classical.propDecidable let ⟨g, hg⟩ := IsCyclic.exists_generator (α := α) if hx : ∃ x : α, x ∈ H ∧ x ≠ (1 : α) then let ⟨x, hx₁, hx₂⟩ := hx let ⟨k, hk⟩ := hg x have hk : g ^ k = x := hk have hex : ∃ n : ℕ, 0 < n ∧ g ^ n ∈ H := ⟨k.natAbs, Nat.pos_of_ne_zero fun h => hx₂ <| by rw [← hk, Int.natAbs_eq_zero.mp h, zpow_zero], by cases' k with k k · rw [Int.ofNat_eq_coe, Int.natAbs_cast k, ← zpow_natCast, ← Int.ofNat_eq_coe, hk] exact hx₁ · rw [Int.natAbs_negSucc, ← Subgroup.inv_mem_iff H]; simp_all⟩ ⟨⟨⟨g ^ Nat.find hex, (Nat.find_spec hex).2⟩, fun ⟨x, hx⟩ => let ⟨k, hk⟩ := hg x have hk : g ^ k = x := hk have hk₂ : g ^ ((Nat.find hex : ℤ) * (k / Nat.find hex : ℤ)) ∈ H := by rw [zpow_mul] apply H.zpow_mem exact mod_cast (Nat.find_spec hex).2 have hk₃ : g ^ (k % Nat.find hex : ℤ) ∈ H := (Subgroup.mul_mem_cancel_right H hk₂).1 <| by rw [← zpow_add, Int.emod_add_ediv, hk]; exact hx have hk₄ : k % Nat.find hex = (k % Nat.find hex).natAbs := by rw [Int.natAbs_of_nonneg (Int.emod_nonneg _ (Int.natCast_ne_zero_iff_pos.2 (Nat.find_spec hex).1))] have hk₅ : g ^ (k % Nat.find hex).natAbs ∈ H := by rwa [← zpow_natCast, ← hk₄] have hk₆ : (k % (Nat.find hex : ℤ)).natAbs = 0 := by_contradiction fun h => Nat.find_min hex (Int.ofNat_lt.1 <| by rw [← hk₄]; exact Int.emod_lt_of_pos _ (Int.natCast_pos.2 (Nat.find_spec hex).1)) ⟨Nat.pos_of_ne_zero h, hk₅⟩ ⟨k / (Nat.find hex : ℤ), Subtype.ext_iff_val.2 (by suffices g ^ ((Nat.find hex : ℤ) * (k / Nat.find hex : ℤ)) = x by simpa [zpow_mul] rw [Int.mul_ediv_cancel' (Int.dvd_of_emod_eq_zero (Int.natAbs_eq_zero.mp hk₆)), hk])⟩⟩⟩ else by have : H = (⊥ : Subgroup α) := Subgroup.ext fun x => ⟨fun h => by simp at *; tauto, fun h => by rw [Subgroup.mem_bot.1 h]; exact H.one_mem⟩ subst this; infer_instance open Finset Nat section Classical open scoped Classical @[to_additive IsAddCyclic.card_nsmul_eq_zero_le] theorem IsCyclic.card_pow_eq_one_le [DecidableEq α] [Fintype α] [IsCyclic α] {n : ℕ} (hn0 : 0 < n) : (univ.filter fun a : α => a ^ n = 1).card ≤ n := let ⟨g, hg⟩ := IsCyclic.exists_generator (α := α) calc (univ.filter fun a : α => a ^ n = 1).card ≤ (zpowers (g ^ (Fintype.card α / Nat.gcd n (Fintype.card α))) : Set α).toFinset.card := card_le_card fun x hx => let ⟨m, hm⟩ := show x ∈ Submonoid.powers g from mem_powers_iff_mem_zpowers.2 <| hg x Set.mem_toFinset.2 ⟨(m / (Fintype.card α / Nat.gcd n (Fintype.card α)) : ℕ), by dsimp at hm have hgmn : g ^ (m * Nat.gcd n (Fintype.card α)) = 1 := by rw [pow_mul, hm, ← pow_gcd_card_eq_one_iff]; exact (mem_filter.1 hx).2 dsimp only rw [zpow_natCast, ← pow_mul, Nat.mul_div_cancel_left', hm] refine Nat.dvd_of_mul_dvd_mul_right (gcd_pos_of_pos_left (Fintype.card α) hn0) ?_ conv_lhs => rw [Nat.div_mul_cancel (Nat.gcd_dvd_right _ _), ← orderOf_eq_card_of_forall_mem_zpowers hg] exact orderOf_dvd_of_pow_eq_one hgmn⟩ _ ≤ n := by let ⟨m, hm⟩ := Nat.gcd_dvd_right n (Fintype.card α) have hm0 : 0 < m := Nat.pos_of_ne_zero fun hm0 => by rw [hm0, mul_zero, Fintype.card_eq_zero_iff] at hm exact hm.elim' 1 simp only [Set.toFinset_card, SetLike.coe_sort_coe] rw [Fintype.card_zpowers, orderOf_pow g, orderOf_eq_card_of_forall_mem_zpowers hg] nth_rw 2 [hm]; nth_rw 3 [hm] rw [Nat.mul_div_cancel_left _ (gcd_pos_of_pos_left _ hn0), gcd_mul_left_left, hm, Nat.mul_div_cancel _ hm0] exact le_of_dvd hn0 (Nat.gcd_dvd_left _ _) @[deprecated (since := "2024-02-21")] alias IsAddCyclic.card_pow_eq_one_le := IsAddCyclic.card_nsmul_eq_zero_le end Classical @[to_additive] theorem IsCyclic.exists_monoid_generator [Finite α] [IsCyclic α] : ∃ x : α, ∀ y : α, y ∈ Submonoid.powers x := by simp_rw [mem_powers_iff_mem_zpowers] exact IsCyclic.exists_generator @[to_additive] lemma IsCyclic.exists_ofOrder_eq_natCard [h : IsCyclic α] : ∃ g : α, orderOf g = Nat.card α := by obtain ⟨g, hg⟩ := h.exists_generator use g rw [← card_zpowers g, (eq_top_iff' (zpowers g)).mpr hg] exact Nat.card_congr (Equiv.Set.univ α) @[to_additive] lemma isCyclic_iff_exists_ofOrder_eq_natCard [Finite α] : IsCyclic α ↔ ∃ g : α, orderOf g = Nat.card α := by refine ⟨fun h ↦ h.exists_ofOrder_eq_natCard, fun h ↦ ?_⟩ obtain ⟨g, hg⟩ := h cases nonempty_fintype α refine isCyclic_of_orderOf_eq_card g ?_ simp [hg] @[to_additive (attr := deprecated (since := "2024-04-20"))] protected alias IsCyclic.iff_exists_ofOrder_eq_natCard_of_Fintype := isCyclic_iff_exists_ofOrder_eq_natCard section variable [DecidableEq α] [Fintype α] @[to_additive] theorem IsCyclic.image_range_orderOf (ha : ∀ x : α, x ∈ zpowers a) : Finset.image (fun i => a ^ i) (range (orderOf a)) = univ := by simp_rw [← SetLike.mem_coe] at ha simp only [_root_.image_range_orderOf, Set.eq_univ_iff_forall.mpr ha, Set.toFinset_univ] @[to_additive] theorem IsCyclic.image_range_card (ha : ∀ x : α, x ∈ zpowers a) : Finset.image (fun i => a ^ i) (range (Fintype.card α)) = univ := by rw [← orderOf_eq_card_of_forall_mem_zpowers ha, IsCyclic.image_range_orderOf ha] @[to_additive] theorem IsCyclic.unique_zpow_zmod (ha : ∀ x : α, x ∈ zpowers a) (x : α) : ∃! n : ZMod (Fintype.card α), x = a ^ n.val := by obtain ⟨n, rfl⟩ := ha x refine ⟨n, (?_ : a ^ n = _), fun y (hy : a ^ n = _) ↦ ?_⟩ · rw [← zpow_natCast, zpow_eq_zpow_iff_modEq, orderOf_eq_card_of_forall_mem_zpowers ha, Int.modEq_comm, Int.modEq_iff_add_fac, ← ZMod.intCast_eq_iff] · rw [← zpow_natCast, zpow_eq_zpow_iff_modEq, orderOf_eq_card_of_forall_mem_zpowers ha, ← ZMod.intCast_eq_intCast_iff] at hy simp [hy] @[to_additive] lemma IsCyclic.ext {G : Type*} [Group G] [Fintype G] [IsCyclic G] {d : ℕ} {a b : ZMod d} (hGcard : Fintype.card G = d) (h : ∀ t : G, t ^ a.val = t ^ b.val) : a = b := by obtain ⟨g, hg⟩ := IsCyclic.exists_generator (α := G) specialize h g subst hGcard rw [pow_eq_pow_iff_modEq, orderOf_eq_card_of_forall_mem_zpowers hg, ← ZMod.natCast_eq_natCast_iff] at h simpa [ZMod.natCast_val, ZMod.cast_id'] using h end section Totient variable [DecidableEq α] [Fintype α] (hn : ∀ n : ℕ, 0 < n → (univ.filter fun a : α => a ^ n = 1).card ≤ n) @[to_additive] private theorem card_pow_eq_one_eq_orderOf_aux (a : α) : (Finset.univ.filter fun b : α => b ^ orderOf a = 1).card = orderOf a := le_antisymm (hn _ (orderOf_pos a)) (calc orderOf a = @Fintype.card (zpowers a) (id _) := Fintype.card_zpowers.symm _ ≤ @Fintype.card (↑(univ.filter fun b : α => b ^ orderOf a = 1) : Set α) (Fintype.ofFinset _ fun _ => Iff.rfl) := (@Fintype.card_le_of_injective (zpowers a) (↑(univ.filter fun b : α => b ^ orderOf a = 1) : Set α) (id _) (id _) (fun b => ⟨b.1, mem_filter.2 ⟨mem_univ _, by let ⟨i, hi⟩ := b.2 rw [← hi, ← zpow_natCast, ← zpow_mul, mul_comm, zpow_mul, zpow_natCast, pow_orderOf_eq_one, one_zpow]⟩⟩) fun _ _ h => Subtype.eq (Subtype.mk.inj h)) _ = (univ.filter fun b : α => b ^ orderOf a = 1).card := Fintype.card_ofFinset _ _ ) -- Use φ for `Nat.totient` open Nat @[to_additive] private theorem card_orderOf_eq_totient_aux₁ : ∀ {d : ℕ}, d ∣ Fintype.card α → 0 < (univ.filter fun a : α => orderOf a = d).card → (univ.filter fun a : α => orderOf a = d).card = φ d := by intro d hd hpos induction' d using Nat.strongRec' with d IH rcases Decidable.eq_or_ne d 0 with (rfl | hd0) · cases Fintype.card_ne_zero (eq_zero_of_zero_dvd hd) rcases card_pos.1 hpos with ⟨a, ha'⟩ have ha : orderOf a = d := (mem_filter.1 ha').2 have h1 : (∑ m ∈ d.properDivisors, (univ.filter fun a : α => orderOf a = m).card) = ∑ m ∈ d.properDivisors, φ m := by refine Finset.sum_congr rfl fun m hm => ?_ simp only [mem_filter, mem_range, mem_properDivisors] at hm refine IH m hm.2 (hm.1.trans hd) (Finset.card_pos.2 ⟨a ^ (d / m), ?_⟩) simp only [mem_filter, mem_univ, orderOf_pow a, ha, true_and_iff, Nat.gcd_eq_right (div_dvd_of_dvd hm.1), Nat.div_div_self hm.1 hd0] have h2 : (∑ m ∈ d.divisors, (univ.filter fun a : α => orderOf a = m).card) = ∑ m ∈ d.divisors, φ m := by rw [← filter_dvd_eq_divisors hd0, sum_card_orderOf_eq_card_pow_eq_one hd0, filter_dvd_eq_divisors hd0, sum_totient, ← ha, card_pow_eq_one_eq_orderOf_aux hn a] simpa [← cons_self_properDivisors hd0, ← h1] using h2 @[to_additive] theorem card_orderOf_eq_totient_aux₂ {d : ℕ} (hd : d ∣ Fintype.card α) : (univ.filter fun a : α => orderOf a = d).card = φ d := by let c := Fintype.card α have hc0 : 0 < c := Fintype.card_pos_iff.2 ⟨1⟩ apply card_orderOf_eq_totient_aux₁ hn hd by_contra h0 -- Must qualify `Finset.card_eq_zero` because of leanprover/lean4#2849 simp_rw [not_lt, Nat.le_zero, Finset.card_eq_zero] at h0 apply lt_irrefl c calc c = ∑ m ∈ c.divisors, (univ.filter fun a : α => orderOf a = m).card := by simp only [← filter_dvd_eq_divisors hc0.ne', sum_card_orderOf_eq_card_pow_eq_one hc0.ne'] apply congr_arg card simp [c] _ = ∑ m ∈ c.divisors.erase d, (univ.filter fun a : α => orderOf a = m).card := by rw [eq_comm] refine sum_subset (erase_subset _ _) fun m hm₁ hm₂ => ?_ have : m = d := by contrapose! hm₂ exact mem_erase_of_ne_of_mem hm₂ hm₁ simp [this, h0] _ ≤ ∑ m ∈ c.divisors.erase d, φ m := by refine sum_le_sum fun m hm => ?_ have hmc : m ∣ c := by simp only [mem_erase, mem_divisors] at hm tauto rcases (filter (fun a : α => orderOf a = m) univ).card.eq_zero_or_pos with (h1 | h1) · simp [h1] · simp [card_orderOf_eq_totient_aux₁ hn hmc h1] _ < ∑ m ∈ c.divisors, φ m := sum_erase_lt_of_pos (mem_divisors.2 ⟨hd, hc0.ne'⟩) (totient_pos.2 (pos_of_dvd_of_pos hd hc0)) _ = c := sum_totient _ @[to_additive isAddCyclic_of_card_nsmul_eq_zero_le] theorem isCyclic_of_card_pow_eq_one_le : IsCyclic α := have : (univ.filter fun a : α => orderOf a = Fintype.card α).Nonempty := card_pos.1 <| by rw [card_orderOf_eq_totient_aux₂ hn dvd_rfl, totient_pos] apply Fintype.card_pos let ⟨x, hx⟩ := this isCyclic_of_orderOf_eq_card x (Finset.mem_filter.1 hx).2 @[deprecated (since := "2024-02-21")] alias isAddCyclic_of_card_pow_eq_one_le := isAddCyclic_of_card_nsmul_eq_zero_le end Totient @[to_additive] theorem IsCyclic.card_orderOf_eq_totient [IsCyclic α] [Fintype α] {d : ℕ} (hd : d ∣ Fintype.card α) : (univ.filter fun a : α => orderOf a = d).card = totient d := by classical apply card_orderOf_eq_totient_aux₂ (fun n => IsCyclic.card_pow_eq_one_le) hd @[deprecated (since := "2024-02-21")] alias IsAddCyclic.card_orderOf_eq_totient := IsAddCyclic.card_addOrderOf_eq_totient /-- A finite group of prime order is simple. -/ @[to_additive "A finite group of prime order is simple."] theorem isSimpleGroup_of_prime_card {α : Type u} [Group α] [Fintype α] {p : ℕ} [hp : Fact p.Prime] (h : Fintype.card α = p) : IsSimpleGroup α := by subst h have : Nontrivial α := by have h' := Nat.Prime.one_lt hp.out exact Fintype.one_lt_card_iff_nontrivial.1 h' exact ⟨fun H _ => H.eq_bot_or_eq_top_of_prime_card⟩ end Cyclic section QuotientCenter open Subgroup variable {G : Type*} {H : Type*} [Group G] [Group H] /-- A group is commutative if the quotient by the center is cyclic. Also see `commGroup_of_cycle_center_quotient` for the `CommGroup` instance. -/ @[to_additive "A group is commutative if the quotient by the center is cyclic. Also see `addCommGroup_of_cycle_center_quotient` for the `AddCommGroup` instance."] theorem commutative_of_cyclic_center_quotient [IsCyclic H] (f : G →* H) (hf : f.ker ≤ center G) (a b : G) : a * b = b * a := let ⟨⟨x, y, (hxy : f y = x)⟩, (hx : ∀ a : f.range, a ∈ zpowers _)⟩ := IsCyclic.exists_generator (α := f.range) let ⟨m, hm⟩ := hx ⟨f a, a, rfl⟩ let ⟨n, hn⟩ := hx ⟨f b, b, rfl⟩ have hm : x ^ m = f a := by simpa [Subtype.ext_iff] using hm have hn : x ^ n = f b := by simpa [Subtype.ext_iff] using hn have ha : y ^ (-m) * a ∈ center G := hf (by rw [f.mem_ker, f.map_mul, f.map_zpow, hxy, zpow_neg x m, hm, inv_mul_self]) have hb : y ^ (-n) * b ∈ center G := hf (by rw [f.mem_ker, f.map_mul, f.map_zpow, hxy, zpow_neg x n, hn, inv_mul_self]) calc a * b = y ^ m * (y ^ (-m) * a * y ^ n) * (y ^ (-n) * b) := by simp [mul_assoc] _ = y ^ m * (y ^ n * (y ^ (-m) * a)) * (y ^ (-n) * b) := by rw [mem_center_iff.1 ha] _ = y ^ m * y ^ n * y ^ (-m) * (a * (y ^ (-n) * b)) := by simp [mul_assoc] _ = y ^ m * y ^ n * y ^ (-m) * (y ^ (-n) * b * a) := by rw [mem_center_iff.1 hb] _ = b * a := by group @[deprecated (since := "2024-02-21")] alias commutative_of_add_cyclic_center_quotient := commutative_of_addCyclic_center_quotient /-- A group is commutative if the quotient by the center is cyclic. -/ @[to_additive commutativeOfAddCycleCenterQuotient "A group is commutative if the quotient by the center is cyclic."] def commGroupOfCycleCenterQuotient [IsCyclic H] (f : G →* H) (hf : f.ker ≤ center G) : CommGroup G := { show Group G by infer_instance with mul_comm := commutative_of_cyclic_center_quotient f hf } end QuotientCenter namespace IsSimpleGroup section CommGroup variable [CommGroup α] [IsSimpleGroup α] @[to_additive] instance (priority := 100) isCyclic : IsCyclic α := by cases' subsingleton_or_nontrivial α with hi hi <;> haveI := hi · apply isCyclic_of_subsingleton · obtain ⟨g, hg⟩ := exists_ne (1 : α) refine ⟨⟨g, fun x => ?_⟩⟩ cases' IsSimpleOrder.eq_bot_or_eq_top (Subgroup.zpowers g) with hb ht · exfalso apply hg rw [← Subgroup.mem_bot, ← hb] apply Subgroup.mem_zpowers · rw [ht] apply Subgroup.mem_top @[to_additive] theorem prime_card [Fintype α] : (Fintype.card α).Prime := by have h0 : 0 < Fintype.card α := Fintype.card_pos_iff.2 (by infer_instance) obtain ⟨g, hg⟩ := IsCyclic.exists_generator (α := α) rw [Nat.prime_def_lt''] refine ⟨Fintype.one_lt_card_iff_nontrivial.2 inferInstance, fun n hn => ?_⟩ refine (IsSimpleOrder.eq_bot_or_eq_top (Subgroup.zpowers (g ^ n))).symm.imp ?_ ?_ · intro h have hgo := orderOf_pow (n := n) g rw [orderOf_eq_card_of_forall_mem_zpowers hg, Nat.gcd_eq_right_iff_dvd.1 hn, orderOf_eq_card_of_forall_mem_zpowers, eq_comm, Nat.div_eq_iff_eq_mul_left (Nat.pos_of_dvd_of_pos hn h0) hn] at hgo · exact (mul_left_cancel₀ (ne_of_gt h0) ((mul_one (Fintype.card α)).trans hgo)).symm · intro x rw [h] exact Subgroup.mem_top _ · intro h apply le_antisymm (Nat.le_of_dvd h0 hn) rw [← orderOf_eq_card_of_forall_mem_zpowers hg] apply orderOf_le_of_pow_eq_one (Nat.pos_of_dvd_of_pos hn h0) rw [← Subgroup.mem_bot, ← h] exact Subgroup.mem_zpowers _ end CommGroup end IsSimpleGroup @[to_additive] theorem CommGroup.is_simple_iff_isCyclic_and_prime_card [Fintype α] [CommGroup α] : IsSimpleGroup α ↔ IsCyclic α ∧ (Fintype.card α).Prime := by constructor · intro h exact ⟨IsSimpleGroup.isCyclic, IsSimpleGroup.prime_card⟩ · rintro ⟨_, hp⟩ haveI : Fact (Fintype.card α).Prime := ⟨hp⟩ exact isSimpleGroup_of_prime_card rfl section SpecificInstances instance : IsAddCyclic ℤ := ⟨1, fun n ↦ ⟨n, by simp only [smul_eq_mul, mul_one]⟩⟩ instance ZMod.instIsAddCyclic (n : ℕ) : IsAddCyclic (ZMod n) := isAddCyclic_of_surjective (Int.castRingHom _) ZMod.intCast_surjective instance ZMod.instIsSimpleAddGroup {p : ℕ} [Fact p.Prime] : IsSimpleAddGroup (ZMod p) := AddCommGroup.is_simple_iff_isAddCyclic_and_prime_card.2 ⟨inferInstance, by simpa using (Fact.out : p.Prime)⟩ end SpecificInstances section Exponent open Monoid @[to_additive] theorem IsCyclic.exponent_eq_card [Group α] [IsCyclic α] [Fintype α] : exponent α = Fintype.card α := by obtain ⟨g, hg⟩ := IsCyclic.exists_generator (α := α) apply Nat.dvd_antisymm · rw [← lcm_orderOf_eq_exponent, Finset.lcm_dvd_iff] exact fun b _ => orderOf_dvd_card rw [← orderOf_eq_card_of_forall_mem_zpowers hg] exact order_dvd_exponent _ @[to_additive] theorem IsCyclic.of_exponent_eq_card [CommGroup α] [Fintype α] (h : exponent α = Fintype.card α) : IsCyclic α := let ⟨g, _, hg⟩ := Finset.mem_image.mp (Finset.max'_mem _ _) isCyclic_of_orderOf_eq_card g <| hg.trans <| exponent_eq_max'_orderOf.symm.trans h @[to_additive] theorem IsCyclic.iff_exponent_eq_card [CommGroup α] [Fintype α] : IsCyclic α ↔ exponent α = Fintype.card α := ⟨fun _ => IsCyclic.exponent_eq_card, IsCyclic.of_exponent_eq_card⟩ @[to_additive] theorem IsCyclic.exponent_eq_zero_of_infinite [Group α] [IsCyclic α] [Infinite α] : exponent α = 0 := let ⟨_, hg⟩ := IsCyclic.exists_generator (α := α) exponent_eq_zero_of_order_zero <| Infinite.orderOf_eq_zero_of_forall_mem_zpowers hg @[simp] protected theorem ZMod.exponent (n : ℕ) : AddMonoid.exponent (ZMod n) = n := by cases n · rw [IsAddCyclic.exponent_eq_zero_of_infinite] · rw [IsAddCyclic.exponent_eq_card, card] /-- A group of order `p ^ 2` is not cyclic if and only if its exponent is `p`. -/ @[to_additive] lemma not_isCyclic_iff_exponent_eq_prime [Group α] {p : ℕ} (hp : p.Prime) (hα : Nat.card α = p ^ 2) : ¬ IsCyclic α ↔ Monoid.exponent α = p := by -- G is a nontrivial fintype of cardinality `p ^ 2` let _inst : Fintype α := @Fintype.ofFinite α <| Nat.finite_of_card_ne_zero <| by aesop have hα' : Fintype.card α = p ^ 2 := by simpa using hα have := (Fintype.one_lt_card_iff_nontrivial (α := α)).mp <| hα' ▸ one_lt_pow hp.one_lt two_ne_zero /- in the forward direction, we apply `exponent_eq_prime_iff`, and the reverse direction follows immediately because if `α` has exponent `p`, it has no element of order `p ^ 2`. -/ refine ⟨fun h_cyc ↦ (Monoid.exponent_eq_prime_iff hp).mpr fun g hg ↦ ?_, fun h_exp h_cyc ↦ by obtain (rfl|rfl) := eq_zero_or_one_of_sq_eq_self <| hα' ▸ h_exp ▸ (h_cyc.exponent_eq_card).symm · exact Nat.not_prime_zero hp · exact Nat.not_prime_one hp⟩ /- we must show every non-identity element has order `p`. By Lagrange's theorem, the only possible orders of `g` are `1`, `p`, or `p ^ 2`. It can't be the former because `g ≠ 1`, and it can't the latter because the group isn't cyclic. -/ have := (Nat.mem_divisors (m := p ^ 2)).mpr ⟨hα' ▸ orderOf_dvd_card (x := g), by aesop⟩ simp? [Nat.divisors_prime_pow hp 2] at this says simp only [Nat.divisors_prime_pow hp 2, Nat.reduceAdd, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk] at this obtain ⟨a, ha, ha'⟩ := this interval_cases a · exact False.elim <| hg <| orderOf_eq_one_iff.mp <| by aesop · aesop · exact False.elim <| h_cyc <| isCyclic_of_orderOf_eq_card g <| by aesop end Exponent section ZMod open Subgroup AddSubgroup variable {G H : Type*} /-- The kernel of `zmultiplesHom G g` is equal to the additive subgroup generated by `addOrderOf g`. -/ theorem zmultiplesHom_ker_eq [AddGroup G] (g : G) : (zmultiplesHom G g).ker = zmultiples ↑(addOrderOf g) := by ext simp_rw [AddMonoidHom.mem_ker, mem_zmultiples_iff, zmultiplesHom_apply, ← addOrderOf_dvd_iff_zsmul_eq_zero, zsmul_eq_mul', Int.cast_id, dvd_def, eq_comm] /-- The kernel of `zpowersHom G g` is equal to the subgroup generated by `orderOf g`. -/ theorem zpowersHom_ker_eq [Group G] (g : G) : (zpowersHom G g).ker = zpowers (Multiplicative.ofAdd ↑(orderOf g)) := congr_arg AddSubgroup.toSubgroup <| zmultiplesHom_ker_eq (Additive.ofMul g) /-- The isomorphism from `ZMod n` to any cyclic additive group of `Nat.card` equal to `n`. -/ noncomputable def zmodAddCyclicAddEquiv [AddGroup G] (h : IsAddCyclic G) : ZMod (Nat.card G) ≃+ G := by let n := Nat.card G let ⟨g, surj⟩ := Classical.indefiniteDescription _ h.exists_generator have kereq : ((zmultiplesHom G) g).ker = zmultiples ↑(Nat.card G) := by rw [zmultiplesHom_ker_eq] congr rw [← Nat.card_zmultiples] exact Nat.card_congr (Equiv.subtypeUnivEquiv surj) exact Int.quotientZMultiplesNatEquivZMod n |>.symm.trans <| QuotientAddGroup.quotientAddEquivOfEq kereq |>.symm.trans <| QuotientAddGroup.quotientKerEquivOfSurjective (zmultiplesHom G g) surj /-- The isomorphism from `Multiplicative (ZMod n)` to any cyclic group of `Nat.card` equal to `n`. -/ noncomputable def zmodCyclicMulEquiv [Group G] (h : IsCyclic G) : Multiplicative (ZMod (Nat.card G)) ≃* G := AddEquiv.toMultiplicative <| zmodAddCyclicAddEquiv <| isAddCyclic_additive_iff.2 h /-- Two cyclic additive groups of the same cardinality are isomorphic. -/ noncomputable def addEquivOfAddCyclicCardEq [AddGroup G] [AddGroup H] [hG : IsAddCyclic G] [hH : IsAddCyclic H] (hcard : Nat.card G = Nat.card H) : G ≃+ H := hcard ▸ zmodAddCyclicAddEquiv hG |>.symm.trans (zmodAddCyclicAddEquiv hH) /-- Two cyclic groups of the same cardinality are isomorphic. -/ @[to_additive existing] noncomputable def mulEquivOfCyclicCardEq [Group G] [Group H] [hG : IsCyclic G] [hH : IsCyclic H] (hcard : Nat.card G = Nat.card H) : G ≃* H := hcard ▸ zmodCyclicMulEquiv hG |>.symm.trans (zmodCyclicMulEquiv hH) /-- Two groups of the same prime cardinality are isomorphic. -/ @[to_additive "Two additive groups of the same prime cardinality are isomorphic."] noncomputable def mulEquivOfPrimeCardEq {p : ℕ} [Fintype G] [Fintype H] [Group G] [Group H] [Fact p.Prime] (hG : Fintype.card G = p) (hH : Fintype.card H = p) : G ≃* H := by have hGcyc := isCyclic_of_prime_card hG have hHcyc := isCyclic_of_prime_card hH apply mulEquivOfCyclicCardEq rw [← Nat.card_eq_fintype_card] at hG hH exact hG.trans hH.symm end ZMod section generator /-! ### Groups with a given generator We state some results in terms of an explicitly given generator. The generating property is given as in `IsCyclic.exists_generator`. The main statements are about the existence and uniqueness of homomorphisms and isomorphisms specified by the image of the given generator. -/ open Subgroup variable {G G' : Type*} [Group G] [Group G'] {g : G} (hg : ∀ x, x ∈ zpowers g) {g' : G'} section monoidHom variable (hg' : orderOf g' ∣ orderOf (g : G)) /-- If `g` generates the group `G` and `g'` is an element of another group `G'` whose order divides that of `g`, then there is a homomorphism `G →* G'` mapping `g` to `g'`. -/ @[to_additive "If `g` generates the additive group `G` and `g'` is an element of another additive group `G'` whose order divides that of `g`, then there is a homomorphism `G →+ G'` mapping `g` to `g'`."] noncomputable def monoidHomOfForallMemZpowers : G →* G' where toFun x := g' ^ (Classical.choose <| mem_zpowers_iff.mp <| hg x) map_one' := orderOf_dvd_iff_zpow_eq_one.mp <| (Int.natCast_dvd_natCast.mpr hg').trans <| orderOf_dvd_iff_zpow_eq_one.mpr <| Classical.choose_spec <| mem_zpowers_iff.mp <| hg 1 map_mul' x y := by simp only [← zpow_add, zpow_eq_zpow_iff_modEq] apply Int.ModEq.of_dvd (Int.natCast_dvd_natCast.mpr hg') rw [← zpow_eq_zpow_iff_modEq, zpow_add] simp only [fun x ↦ Classical.choose_spec <| mem_zpowers_iff.mp <| hg x] @[to_additive (attr := simp)] lemma monoidHomOfForallMemZpowers_apply_gen : monoidHomOfForallMemZpowers hg hg' g = g' := by simp only [monoidHomOfForallMemZpowers, MonoidHom.coe_mk, OneHom.coe_mk] nth_rw 2 [← zpow_one g'] rw [zpow_eq_zpow_iff_modEq] apply Int.ModEq.of_dvd (Int.natCast_dvd_natCast.mpr hg') rw [← zpow_eq_zpow_iff_modEq, zpow_one] exact Classical.choose_spec <| mem_zpowers_iff.mp <| hg g end monoidHom /-- Two group homomorphisms `G →* G'` are equal if and only if they agree on a generator of `G`. -/ @[to_additive "Two homomorphisms `G →+ G'` of additive groups are equal if and only if they agree on a generator of `G`."] lemma MonoidHom.eq_iff_eq_on_generator (f₁ f₂ : G →* G') : f₁ = f₂ ↔ f₁ g = f₂ g := by rw [DFunLike.ext_iff] refine ⟨fun H ↦ H g, fun H x ↦ ?_⟩ obtain ⟨n, hn⟩ := mem_zpowers_iff.mp <| hg x rw [← hn, map_zpow, map_zpow, H] /-- Two group isomorphisms `G ≃* G'` are equal if and only if they agree on a generator of `G`. -/ @[to_additive "Two isomorphisms `G ≃+ G'` of additive groups are equal if and only if they agree on a generator of `G`."] lemma MulEquiv.eq_iff_eq_on_generator (f₁ f₂ : G ≃* G') : f₁ = f₂ ↔ f₁ g = f₂ g := (Function.Injective.eq_iff toMonoidHom_injective).symm.trans <| MonoidHom.eq_iff_eq_on_generator hg .. section mulEquiv variable (hg' : ∀ x, x ∈ zpowers g') (h : orderOf g = orderOf g') /-- Given two groups that are generated by elements `g` and `g'` of the same order, we obtain an isomorphism sending `g` to `g'`. -/ @[to_additive "Given two additive groups that are generated by elements `g` and `g'` of the same order, we obtain an isomorphism sending `g` to `g'`."] noncomputable def mulEquivOfOrderOfEq : G ≃* G' := by refine MonoidHom.toMulEquiv (monoidHomOfForallMemZpowers hg h.symm.dvd) (monoidHomOfForallMemZpowers hg' h.dvd) ?_ ?_ <;> refine (MonoidHom.eq_iff_eq_on_generator (by assumption) _ _).mpr ?_ <;> simp only [MonoidHom.coe_comp, Function.comp_apply, monoidHomOfForallMemZpowers_apply_gen, MonoidHom.id_apply] @[to_additive (attr := simp)] lemma mulEquivOfOrderOfEq_apply_gen : mulEquivOfOrderOfEq hg hg' h g = g' := monoidHomOfForallMemZpowers_apply_gen hg h.symm.dvd @[to_additive (attr := simp)] lemma mulEquivOfOrderOfEq_symm : (mulEquivOfOrderOfEq hg hg' h).symm = mulEquivOfOrderOfEq hg' hg h.symm := rfl @[to_additive] -- `simp` can prove this by a combination of the two preceding lemmas lemma mulEquivOfOrderOfEq_symm_apply_gen : (mulEquivOfOrderOfEq hg hg' h).symm g' = g := monoidHomOfForallMemZpowers_apply_gen hg' h.dvd end mulEquiv end generator
GroupTheory\SpecificGroups\Dihedral.lean
/- Copyright (c) 2020 Shing Tak Lam. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Shing Tak Lam -/ import Mathlib.Data.ZMod.Basic import Mathlib.GroupTheory.Exponent /-! # Dihedral Groups We define the dihedral groups `DihedralGroup n`, with elements `r i` and `sr i` for `i : ZMod n`. For `n ≠ 0`, `DihedralGroup n` represents the symmetry group of the regular `n`-gon. `r i` represents the rotations of the `n`-gon by `2πi/n`, and `sr i` represents the reflections of the `n`-gon. `DihedralGroup 0` corresponds to the infinite dihedral group. -/ /-- For `n ≠ 0`, `DihedralGroup n` represents the symmetry group of the regular `n`-gon. `r i` represents the rotations of the `n`-gon by `2πi/n`, and `sr i` represents the reflections of the `n`-gon. `DihedralGroup 0` corresponds to the infinite dihedral group. -/ inductive DihedralGroup (n : ℕ) : Type | r : ZMod n → DihedralGroup n | sr : ZMod n → DihedralGroup n deriving DecidableEq namespace DihedralGroup variable {n : ℕ} /-- Multiplication of the dihedral group. -/ private def mul : DihedralGroup n → DihedralGroup n → DihedralGroup n | r i, r j => r (i + j) | r i, sr j => sr (j - i) | sr i, r j => sr (i + j) | sr i, sr j => r (j - i) /-- The identity `1` is the rotation by `0`. -/ private def one : DihedralGroup n := r 0 instance : Inhabited (DihedralGroup n) := ⟨one⟩ /-- The inverse of an element of the dihedral group. -/ private def inv : DihedralGroup n → DihedralGroup n | r i => r (-i) | sr i => sr i /-- The group structure on `DihedralGroup n`. -/ instance : Group (DihedralGroup n) where mul := mul mul_assoc := by rintro (a | a) (b | b) (c | c) <;> simp only [(· * ·), mul] <;> ring_nf one := one one_mul := by rintro (a | a) · exact congr_arg r (zero_add a) · exact congr_arg sr (sub_zero a) mul_one := by rintro (a | a) · exact congr_arg r (add_zero a) · exact congr_arg sr (add_zero a) inv := inv mul_left_inv := by rintro (a | a) · exact congr_arg r (neg_add_self a) · exact congr_arg r (sub_self a) @[simp] theorem r_mul_r (i j : ZMod n) : r i * r j = r (i + j) := rfl @[simp] theorem r_mul_sr (i j : ZMod n) : r i * sr j = sr (j - i) := rfl @[simp] theorem sr_mul_r (i j : ZMod n) : sr i * r j = sr (i + j) := rfl @[simp] theorem sr_mul_sr (i j : ZMod n) : sr i * sr j = r (j - i) := rfl theorem one_def : (1 : DihedralGroup n) = r 0 := rfl private def fintypeHelper : (ZMod n) ⊕ (ZMod n) ≃ DihedralGroup n where invFun i := match i with | r j => Sum.inl j | sr j => Sum.inr j toFun i := match i with | Sum.inl j => r j | Sum.inr j => sr j left_inv := by rintro (x | x) <;> rfl right_inv := by rintro (x | x) <;> rfl /-- If `0 < n`, then `DihedralGroup n` is a finite group. -/ instance [NeZero n] : Fintype (DihedralGroup n) := Fintype.ofEquiv _ fintypeHelper instance : Infinite (DihedralGroup 0) := DihedralGroup.fintypeHelper.infinite_iff.mp inferInstance instance : Nontrivial (DihedralGroup n) := ⟨⟨r 0, sr 0, by simp_rw [ne_eq, not_false_eq_true]⟩⟩ /-- If `0 < n`, then `DihedralGroup n` has `2n` elements. -/ theorem card [NeZero n] : Fintype.card (DihedralGroup n) = 2 * n := by rw [← Fintype.card_eq.mpr ⟨fintypeHelper⟩, Fintype.card_sum, ZMod.card, two_mul] theorem nat_card : Nat.card (DihedralGroup n) = 2 * n := by cases n · rw [Nat.card_eq_zero_of_infinite] · rw [Nat.card_eq_fintype_card, card] @[simp] theorem r_one_pow (k : ℕ) : (r 1 : DihedralGroup n) ^ k = r k := by induction' k with k IH · rw [Nat.cast_zero] rfl · rw [pow_succ', IH, r_mul_r] congr 1 norm_cast rw [Nat.one_add] -- @[simp] -- Porting note: simp changes the goal to `r 0 = 1`. `r_one_pow_n` is no longer useful. theorem r_one_pow_n : r (1 : ZMod n) ^ n = 1 := by rw [r_one_pow, one_def] congr 1 exact ZMod.natCast_self _ -- @[simp] -- Porting note: simp changes the goal to `r 0 = 1`. `sr_mul_self` is no longer useful. theorem sr_mul_self (i : ZMod n) : sr i * sr i = 1 := by rw [sr_mul_sr, sub_self, one_def] /-- If `0 < n`, then `sr i` has order 2. -/ @[simp] theorem orderOf_sr (i : ZMod n) : orderOf (sr i) = 2 := by apply orderOf_eq_prime · rw [sq, sr_mul_self] · -- Porting note: Previous proof was `decide` revert n simp_rw [one_def, ne_eq, forall_const, not_false_eq_true] /-- If `0 < n`, then `r 1` has order `n`. -/ @[simp] theorem orderOf_r_one : orderOf (r 1 : DihedralGroup n) = n := by rcases eq_zero_or_neZero n with (rfl | hn) · rw [orderOf_eq_zero_iff'] intro n hn rw [r_one_pow, one_def] apply mt r.inj simpa using hn.ne' · apply (Nat.le_of_dvd (NeZero.pos n) <| orderOf_dvd_of_pow_eq_one <| @r_one_pow_n n).lt_or_eq.resolve_left intro h have h1 : (r 1 : DihedralGroup n) ^ orderOf (r 1) = 1 := pow_orderOf_eq_one _ rw [r_one_pow] at h1 injection h1 with h2 rw [← ZMod.val_eq_zero, ZMod.val_natCast, Nat.mod_eq_of_lt h] at h2 exact absurd h2.symm (orderOf_pos _).ne /-- If `0 < n`, then `i : ZMod n` has order `n / gcd n i`. -/ theorem orderOf_r [NeZero n] (i : ZMod n) : orderOf (r i) = n / Nat.gcd n i.val := by conv_lhs => rw [← ZMod.natCast_zmod_val i] rw [← r_one_pow, orderOf_pow, orderOf_r_one] theorem exponent : Monoid.exponent (DihedralGroup n) = lcm n 2 := by rcases eq_zero_or_neZero n with (rfl | hn) · exact Monoid.exponent_eq_zero_of_order_zero orderOf_r_one apply Nat.dvd_antisymm · apply Monoid.exponent_dvd_of_forall_pow_eq_one rintro (m | m) · rw [← orderOf_dvd_iff_pow_eq_one, orderOf_r] refine Nat.dvd_trans ⟨gcd n m.val, ?_⟩ (dvd_lcm_left n 2) exact (Nat.div_mul_cancel (Nat.gcd_dvd_left n m.val)).symm · rw [← orderOf_dvd_iff_pow_eq_one, orderOf_sr] exact dvd_lcm_right n 2 · apply lcm_dvd · convert Monoid.order_dvd_exponent (r (1 : ZMod n)) exact orderOf_r_one.symm · convert Monoid.order_dvd_exponent (sr (0 : ZMod n)) exact (orderOf_sr 0).symm /-- If n is odd, then the Dihedral group of order $2n$ has $n(n+3)$ pairs (represented as $n + n + n + n*n$) of commuting elements. -/ @[simps] def OddCommuteEquiv (hn : Odd n) : { p : DihedralGroup n × DihedralGroup n // Commute p.1 p.2 } ≃ ZMod n ⊕ ZMod n ⊕ ZMod n ⊕ ZMod n × ZMod n := let u := ZMod.unitOfCoprime 2 (Nat.prime_two.coprime_iff_not_dvd.mpr hn.not_two_dvd_nat) have hu : ∀ a : ZMod n, a + a = 0 ↔ a = 0 := fun a => ZMod.add_self_eq_zero_iff_eq_zero hn { toFun := fun | ⟨⟨sr i, r _⟩, _⟩ => Sum.inl i | ⟨⟨r _, sr j⟩, _⟩ => Sum.inr (Sum.inl j) | ⟨⟨sr i, sr j⟩, _⟩ => Sum.inr (Sum.inr (Sum.inl (i + j))) | ⟨⟨r i, r j⟩, _⟩ => Sum.inr (Sum.inr (Sum.inr ⟨i, j⟩)) invFun := fun | .inl i => ⟨⟨sr i, r 0⟩, congrArg sr ((add_zero i).trans (sub_zero i).symm)⟩ | .inr (.inl j) => ⟨⟨r 0, sr j⟩, congrArg sr ((sub_zero j).trans (add_zero j).symm)⟩ | .inr (.inr (.inl k)) => ⟨⟨sr (u⁻¹ * k), sr (u⁻¹ * k)⟩, rfl⟩ | .inr (.inr (.inr ⟨i, j⟩)) => ⟨⟨r i, r j⟩, congrArg r (add_comm i j)⟩ left_inv := fun | ⟨⟨r i, r j⟩, h⟩ => rfl | ⟨⟨r i, sr j⟩, h⟩ => by simpa [sub_eq_add_neg, neg_eq_iff_add_eq_zero, hu, eq_comm (a := i) (b := 0)] using h.eq | ⟨⟨sr i, r j⟩, h⟩ => by simpa [sub_eq_add_neg, eq_neg_iff_add_eq_zero, hu, eq_comm (a := j) (b := 0)] using h.eq | ⟨⟨sr i, sr j⟩, h⟩ => by replace h := r.inj h rw [← neg_sub, neg_eq_iff_add_eq_zero, hu, sub_eq_zero] at h rw [Subtype.ext_iff, Prod.ext_iff, sr.injEq, sr.injEq, h, and_self, ← two_mul] exact u.inv_mul_cancel_left j right_inv := fun | .inl i => rfl | .inr (.inl j) => rfl | .inr (.inr (.inl k)) => congrArg (Sum.inr ∘ Sum.inr ∘ Sum.inl) <| two_mul (u⁻¹ * k) ▸ u.mul_inv_cancel_left k | .inr (.inr (.inr ⟨i, j⟩)) => rfl } /-- If n is odd, then the Dihedral group of order $2n$ has $n(n+3)$ pairs of commuting elements. -/ lemma card_commute_odd (hn : Odd n) : Nat.card { p : DihedralGroup n × DihedralGroup n // Commute p.1 p.2 } = n * (n + 3) := by have hn' : NeZero n := ⟨hn.pos.ne'⟩ simp_rw [Nat.card_congr (OddCommuteEquiv hn), Nat.card_sum, Nat.card_prod, Nat.card_zmod] ring lemma card_conjClasses_odd (hn : Odd n) : Nat.card (ConjClasses (DihedralGroup n)) = (n + 3) / 2 := by rw [← Nat.mul_div_mul_left _ 2 hn.pos, ← card_commute_odd hn, mul_comm, card_comm_eq_card_conjClasses_mul_card, nat_card, Nat.mul_div_left _ (mul_pos two_pos hn.pos)] end DihedralGroup
GroupTheory\SpecificGroups\KleinFour.lean
/- Copyright (c) 2023 Newell Jensen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Newell Jensen -/ import Mathlib.GroupTheory.SpecificGroups.Cyclic import Mathlib.GroupTheory.SpecificGroups.Dihedral /-! # Klein Four Group The Klein (Vierergruppe) four-group is a non-cyclic abelian group with four elements, in which each element is self-inverse and in which composing any two of the three non-identity elements produces the third one. ## Main definitions * `IsKleinFour` : A mixin class which states that the group has order four and exponent two. * `mulEquiv'` : An equivalence between a Klein four-group and a group of exponent two which preserves the identity is in fact an isomorphism. * `mulEquiv`: Any two Klein four-groups are isomorphic via any identity preserving equivalence. ## References * https://en.wikipedia.org/wiki/Klein_four-group * https://en.wikipedia.org/wiki/Alternating_group ## TODO * Prove an `IsKleinFour` group is isomorphic to the normal subgroup of `alternatingGroup (Fin 4)` with the permutation cycles `V = {(), (1 2)(3 4), (1 3)(2 4), (1 4)(2 3)}`. This is the kernel of the surjection of `alternatingGroup (Fin 4)` onto `alternatingGroup (Fin 3) ≃ (ZMod 3)`. In other words, we have the exact sequence `V → A₄ → A₃`. * The outer automorphism group of `A₆` is the Klein four-group `V = (ZMod 2) × (ZMod 2)`, and is related to the outer automorphism of `S₆`. The extra outer automorphism in `A₆` swaps the 3-cycles (like `(1 2 3)`) with elements of shape `3²` (like `(1 2 3)(4 5 6)`). ## Tags non-cyclic abelian group -/ /-! # Klein four-groups as a mixin class -/ /-- An (additive) Klein four-group is an (additive) group of cardinality four and exponent two. -/ class IsAddKleinFour (G : Type*) [AddGroup G] : Prop where card_four : Nat.card G = 4 exponent_two : AddMonoid.exponent G = 2 /-- A Klein four-group is a group of cardinality four and exponent two. -/ @[to_additive existing IsAddKleinFour] class IsKleinFour (G : Type*) [Group G] : Prop where card_four : Nat.card G = 4 exponent_two : Monoid.exponent G = 2 attribute [simp] IsKleinFour.card_four IsKleinFour.exponent_two IsAddKleinFour.card_four IsAddKleinFour.exponent_two instance : IsAddKleinFour (ZMod 2 × ZMod 2) where card_four := by simp exponent_two := by simp [AddMonoid.exponent_prod] instance : IsKleinFour (DihedralGroup 2) where card_four := by simp only [Nat.card_eq_fintype_card]; rfl exponent_two := by simp [DihedralGroup.exponent] instance {G : Type*} [Group G] [IsKleinFour G] : IsAddKleinFour (Additive G) where card_four := by rw [← IsKleinFour.card_four (G := G)]; congr! exponent_two := by simp instance {G : Type*} [AddGroup G] [IsAddKleinFour G] : IsKleinFour (Multiplicative G) where card_four := by rw [← IsAddKleinFour.card_four (G := G)]; congr! exponent_two := by simp namespace IsKleinFour @[to_additive] instance instFinite {G : Type*} [Group G] [IsKleinFour G] : Finite G := Nat.finite_of_card_ne_zero <| by norm_num [IsKleinFour.card_four] @[to_additive (attr := simp)] lemma card_four' {G : Type*} [Group G] [Fintype G] [IsKleinFour G] : Fintype.card G = 4 := Nat.card_eq_fintype_card (α := G).symm ▸ IsKleinFour.card_four open Finset variable {G : Type*} [Group G] [IsKleinFour G] @[to_additive] lemma not_isCyclic : ¬ IsCyclic G := fun h ↦ by let _inst := Fintype.ofFinite G; simpa using h.exponent_eq_card @[to_additive] lemma inv_eq_self (x : G) : x⁻¹ = x := inv_eq_self_of_exponent_two (by simp) x /- this is not an appropriate global `simp` lemma for a `Prop`-mixin class. Indeed, if it were then every time Lean sees `·⁻¹` it would try to apply `inv_eq_self` which would trigger type class inference to try and synthesize an `IsKleinFour` instance. -/ scoped[IsKleinFour] attribute [simp] inv_eq_self scoped[IsAddKleinFour] attribute [simp] neg_eq_self @[to_additive] lemma mul_self (x : G) : x * x = 1 := by rw [mul_eq_one_iff_eq_inv, inv_eq_self] @[to_additive] lemma eq_finset_univ [Fintype G] [DecidableEq G] {x y : G} (hx : x ≠ 1) (hy : y ≠ 1) (hxy : x ≠ y) : {x * y, x, y, (1 : G)} = Finset.univ := by apply Finset.eq_univ_of_card rw [card_four'] repeat rw [card_insert_of_not_mem] on_goal 4 => simpa using mul_not_mem_of_exponent_two (by simp) hx hy hxy all_goals aesop @[to_additive] lemma eq_mul_of_ne_all {x y z : G} (hx : x ≠ 1) (hy : y ≠ 1) (hxy : x ≠ y) (hz : z ≠ 1) (hzx : z ≠ x) (hzy : z ≠ y) : z = x * y := by classical let _ := Fintype.ofFinite G apply eq_of_not_mem_of_mem_insert <| (eq_finset_univ hx hy hxy).symm ▸ mem_univ _ simpa only [mem_singleton, mem_insert, not_or] using ⟨hzx, hzy, hz⟩ variable {G₁ G₂ : Type*} [Group G₁] [Group G₂] [IsKleinFour G₁] /-- An equivalence between an `IsKleinFour` group `G₁` and a group `G₂` of exponent two which sends `1 : G₁` to `1 : G₂` is in fact an isomorphism. -/ @[to_additive "An equivalence between an `IsAddKleinFour` group `G₁` and a group `G₂` of exponent two which sends `0 : G₁` to `0 : G₂` is in fact an isomorphism."] def mulEquiv' (e : G₁ ≃ G₂) (he : e 1 = 1) (h : Monoid.exponent G₂ = 2) : G₁ ≃* G₂ where toEquiv := e map_mul' := by let _inst₁ := Fintype.ofFinite G₁ let _inst₂ := Fintype.ofEquiv G₁ e intro x y by_cases hx : x = 1 <;> by_cases hy : y = 1 all_goals try simp only [hx, hy, mul_one, one_mul, Equiv.toFun_as_coe, he] by_cases hxy : x = y · simp [hxy, mul_self, ← pow_two (e y), h ▸ Monoid.pow_exponent_eq_one (e y), he] · classical have univ₂ : {e (x * y), e x, e y, (1 : G₂)} = Finset.univ := by simpa [map_univ_equiv e, map_insert, he] using congr(Finset.map e.toEmbedding $(eq_finset_univ hx hy hxy)) rw [← Ne, ← e.injective.ne_iff] at hx hy hxy rw [he] at hx hy symm apply eq_of_not_mem_of_mem_insert <| univ₂.symm ▸ mem_univ _ simpa using mul_not_mem_of_exponent_two h hx hy hxy /-- Any two `IsKleinFour` groups are isomorphic via any equivalence which sends the identity of one group to the identity of the other. -/ @[to_additive (attr := reducible) "Any two `IsAddKleinFour` groups are isomorphic via any equivalence which sends the identity of one group to the identity of the other."] def mulEquiv [IsKleinFour G₂] (e : G₁ ≃ G₂) (he : e 1 = 1) : G₁ ≃* G₂ := mulEquiv' e he exponent_two /-- Any two `IsKleinFour` groups are isomorphic. -/ @[to_additive "Any two `IsAddKleinFour` groups are isomorphic."] lemma nonempty_mulEquiv [IsKleinFour G₂] : Nonempty (G₁ ≃* G₂) := by classical let _inst₁ := Fintype.ofFinite G₁ let _inst₁ := Fintype.ofFinite G₂ exact ⟨mulEquiv ((Fintype.equivOfCardEq <| by simp).setValue 1 1) <| by simp⟩ end IsKleinFour
GroupTheory\SpecificGroups\Quaternion.lean
/- Copyright (c) 2021 Julian Kuelshammer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Julian Kuelshammer -/ import Mathlib.Data.ZMod.Basic import Mathlib.Algebra.Group.Nat import Mathlib.Tactic.IntervalCases import Mathlib.GroupTheory.SpecificGroups.Dihedral import Mathlib.GroupTheory.SpecificGroups.Cyclic /-! # Quaternion Groups We define the (generalised) quaternion groups `QuaternionGroup n` of order `4n`, also known as dicyclic groups, with elements `a i` and `xa i` for `i : ZMod n`. The (generalised) quaternion groups can be defined by the presentation $\langle a, x | a^{2n} = 1, x^2 = a^n, x^{-1}ax=a^{-1}\rangle$. We write `a i` for $a^i$ and `xa i` for $x * a^i$. For `n=2` the quaternion group `QuaternionGroup 2` is isomorphic to the unit integral quaternions `(Quaternion ℤ)ˣ`. ## Main definition `QuaternionGroup n`: The (generalised) quaternion group of order `4n`. ## Implementation notes This file is heavily based on `DihedralGroup` by Shing Tak Lam. In mathematics, the name "quaternion group" is reserved for the cases `n ≥ 2`. Since it would be inconvenient to carry around this condition we define `QuaternionGroup` also for `n = 0` and `n = 1`. `QuaternionGroup 0` is isomorphic to the infinite dihedral group, while `QuaternionGroup 1` is isomorphic to a cyclic group of order `4`. ## References * https://en.wikipedia.org/wiki/Dicyclic_group * https://en.wikipedia.org/wiki/Quaternion_group ## TODO Show that `QuaternionGroup 2 ≃* (Quaternion ℤ)ˣ`. -/ /-- The (generalised) quaternion group `QuaternionGroup n` of order `4n`. It can be defined by the presentation $\langle a, x | a^{2n} = 1, x^2 = a^n, x^{-1}ax=a^{-1}\rangle$. We write `a i` for $a^i$ and `xa i` for $x * a^i$. -/ inductive QuaternionGroup (n : ℕ) : Type | a : ZMod (2 * n) → QuaternionGroup n | xa : ZMod (2 * n) → QuaternionGroup n deriving DecidableEq namespace QuaternionGroup variable {n : ℕ} /-- Multiplication of the dihedral group. -/ private def mul : QuaternionGroup n → QuaternionGroup n → QuaternionGroup n | a i, a j => a (i + j) | a i, xa j => xa (j - i) | xa i, a j => xa (i + j) | xa i, xa j => a (n + j - i) /-- The identity `1` is given by `aⁱ`. -/ private def one : QuaternionGroup n := a 0 instance : Inhabited (QuaternionGroup n) := ⟨one⟩ /-- The inverse of an element of the quaternion group. -/ private def inv : QuaternionGroup n → QuaternionGroup n | a i => a (-i) | xa i => xa (n + i) /-- The group structure on `QuaternionGroup n`. -/ instance : Group (QuaternionGroup n) where mul := mul mul_assoc := by rintro (i | i) (j | j) (k | k) <;> simp only [(· * ·), mul] <;> ring_nf congr calc -(n : ZMod (2 * n)) = 0 - n := by rw [zero_sub] _ = 2 * n - n := by norm_cast; simp _ = n := by ring one := one one_mul := by rintro (i | i) · exact congr_arg a (zero_add i) · exact congr_arg xa (sub_zero i) mul_one := by rintro (i | i) · exact congr_arg a (add_zero i) · exact congr_arg xa (add_zero i) inv := inv mul_left_inv := by rintro (i | i) · exact congr_arg a (neg_add_self i) · exact congr_arg a (sub_self (n + i)) @[simp] theorem a_mul_a (i j : ZMod (2 * n)) : a i * a j = a (i + j) := rfl @[simp] theorem a_mul_xa (i j : ZMod (2 * n)) : a i * xa j = xa (j - i) := rfl @[simp] theorem xa_mul_a (i j : ZMod (2 * n)) : xa i * a j = xa (i + j) := rfl @[simp] theorem xa_mul_xa (i j : ZMod (2 * n)) : xa i * xa j = a ((n : ZMod (2 * n)) + j - i) := rfl theorem one_def : (1 : QuaternionGroup n) = a 0 := rfl private def fintypeHelper : ZMod (2 * n) ⊕ ZMod (2 * n) ≃ QuaternionGroup n where invFun i := match i with | a j => Sum.inl j | xa j => Sum.inr j toFun i := match i with | Sum.inl j => a j | Sum.inr j => xa j left_inv := by rintro (x | x) <;> rfl right_inv := by rintro (x | x) <;> rfl /-- The special case that more or less by definition `QuaternionGroup 0` is isomorphic to the infinite dihedral group. -/ def quaternionGroupZeroEquivDihedralGroupZero : QuaternionGroup 0 ≃* DihedralGroup 0 where toFun i := -- Porting note: Originally `QuaternionGroup.recOn i DihedralGroup.r DihedralGroup.sr` match i with | a j => DihedralGroup.r j | xa j => DihedralGroup.sr j invFun i := match i with | DihedralGroup.r j => a j | DihedralGroup.sr j => xa j left_inv := by rintro (k | k) <;> rfl right_inv := by rintro (k | k) <;> rfl map_mul' := by rintro (k | k) (l | l) <;> simp /-- If `0 < n`, then `QuaternionGroup n` is a finite group. -/ instance [NeZero n] : Fintype (QuaternionGroup n) := Fintype.ofEquiv _ fintypeHelper instance : Nontrivial (QuaternionGroup n) := ⟨⟨a 0, xa 0, by revert n; simp⟩⟩ -- Porting note: `revert n; simp` was `decide` /-- If `0 < n`, then `QuaternionGroup n` has `4n` elements. -/ theorem card [NeZero n] : Fintype.card (QuaternionGroup n) = 4 * n := by rw [← Fintype.card_eq.mpr ⟨fintypeHelper⟩, Fintype.card_sum, ZMod.card, two_mul] ring @[simp] theorem a_one_pow (k : ℕ) : (a 1 : QuaternionGroup n) ^ k = a k := by induction' k with k IH · rw [Nat.cast_zero]; rfl · rw [pow_succ, IH, a_mul_a] congr 1 norm_cast -- @[simp] -- Porting note: simp changes this to `a 0 = 1`, so this is no longer a good simp lemma. theorem a_one_pow_n : (a 1 : QuaternionGroup n) ^ (2 * n) = 1 := by rw [a_one_pow, one_def] congr 1 exact ZMod.natCast_self _ @[simp] theorem xa_sq (i : ZMod (2 * n)) : xa i ^ 2 = a n := by simp [sq] @[simp] theorem xa_pow_four (i : ZMod (2 * n)) : xa i ^ 4 = 1 := by rw [pow_succ, pow_succ, sq, xa_mul_xa, a_mul_xa, xa_mul_xa, add_sub_cancel_right, add_sub_assoc, sub_sub_cancel] norm_cast rw [← two_mul] simp [one_def] /-- If `0 < n`, then `xa i` has order 4. -/ @[simp] theorem orderOf_xa [NeZero n] (i : ZMod (2 * n)) : orderOf (xa i) = 4 := by change _ = 2 ^ 2 haveI : Fact (Nat.Prime 2) := Fact.mk Nat.prime_two apply orderOf_eq_prime_pow · intro h simp only [pow_one, xa_sq] at h injection h with h' apply_fun ZMod.val at h' apply_fun (· / n) at h' simp only [ZMod.val_natCast, ZMod.val_zero, Nat.zero_div, Nat.mod_mul_left_div_self, Nat.div_self (NeZero.pos n)] at h' · norm_num /-- In the special case `n = 1`, `Quaternion 1` is a cyclic group (of order `4`). -/ theorem quaternionGroup_one_isCyclic : IsCyclic (QuaternionGroup 1) := by apply isCyclic_of_orderOf_eq_card · rw [card, mul_one] exact orderOf_xa 0 /-- If `0 < n`, then `a 1` has order `2 * n`. -/ @[simp] theorem orderOf_a_one : orderOf (a 1 : QuaternionGroup n) = 2 * n := by cases' eq_zero_or_neZero n with hn hn · subst hn simp_rw [mul_zero, orderOf_eq_zero_iff'] intro n h rw [one_def, a_one_pow] apply mt a.inj haveI : CharZero (ZMod (2 * 0)) := ZMod.charZero simpa using h.ne' apply (Nat.le_of_dvd (NeZero.pos _) (orderOf_dvd_of_pow_eq_one (@a_one_pow_n n))).lt_or_eq.resolve_left intro h have h1 : (a 1 : QuaternionGroup n) ^ orderOf (a 1) = 1 := pow_orderOf_eq_one _ rw [a_one_pow] at h1 injection h1 with h2 rw [← ZMod.val_eq_zero, ZMod.val_natCast, Nat.mod_eq_of_lt h] at h2 exact absurd h2.symm (orderOf_pos _).ne /-- If `0 < n`, then `a i` has order `(2 * n) / gcd (2 * n) i`. -/ theorem orderOf_a [NeZero n] (i : ZMod (2 * n)) : orderOf (a i) = 2 * n / Nat.gcd (2 * n) i.val := by conv_lhs => rw [← ZMod.natCast_zmod_val i] rw [← a_one_pow, orderOf_pow, orderOf_a_one] theorem exponent : Monoid.exponent (QuaternionGroup n) = 2 * lcm n 2 := by rw [← normalize_eq 2, ← lcm_mul_left, normalize_eq] norm_num cases' eq_zero_or_neZero n with hn hn · subst hn simp only [lcm_zero_left, mul_zero] exact Monoid.exponent_eq_zero_of_order_zero orderOf_a_one apply Nat.dvd_antisymm · apply Monoid.exponent_dvd_of_forall_pow_eq_one rintro (m | m) · rw [← orderOf_dvd_iff_pow_eq_one, orderOf_a] refine Nat.dvd_trans ⟨gcd (2 * n) m.val, ?_⟩ (dvd_lcm_left (2 * n) 4) exact (Nat.div_mul_cancel (Nat.gcd_dvd_left (2 * n) m.val)).symm · rw [← orderOf_dvd_iff_pow_eq_one, orderOf_xa] exact dvd_lcm_right (2 * n) 4 · apply lcm_dvd · convert Monoid.order_dvd_exponent (a 1) exact orderOf_a_one.symm · convert Monoid.order_dvd_exponent (xa (0 : ZMod (2 * n))) exact (orderOf_xa 0).symm end QuaternionGroup
GroupTheory\Subgroup\Center.lean
/- Copyright (c) 2020 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import Mathlib.Algebra.Group.Subgroup.Basic import Mathlib.Algebra.GroupWithZero.Units.Basic import Mathlib.GroupTheory.Submonoid.Center /-! # Centers of subgroups -/ open Function open Int variable {G : Type*} [Group G] namespace Subgroup variable (G) /-- The center of a group `G` is the set of elements that commute with everything in `G` -/ @[to_additive "The center of an additive group `G` is the set of elements that commute with everything in `G`"] def center : Subgroup G := { Submonoid.center G with carrier := Set.center G inv_mem' := Set.inv_mem_center } @[to_additive] theorem coe_center : ↑(center G) = Set.center G := rfl @[to_additive (attr := simp)] theorem center_toSubmonoid : (center G).toSubmonoid = Submonoid.center G := rfl instance center.isCommutative : (center G).IsCommutative := ⟨⟨fun a b => Subtype.ext (b.2.comm a).symm⟩⟩ /-- For a group with zero, the center of the units is the same as the units of the center. -/ @[simps! apply_val_coe symm_apply_coe_val] def centerUnitsEquivUnitsCenter (G₀ : Type*) [GroupWithZero G₀] : Subgroup.center (G₀ˣ) ≃* (Submonoid.center G₀)ˣ where toFun := MonoidHom.toHomUnits <| { toFun := fun u ↦ ⟨(u : G₀ˣ), (Submonoid.mem_center_iff.mpr (fun r ↦ by rcases eq_or_ne r 0 with (rfl | hr) · rw [mul_zero, zero_mul] exact congrArg Units.val <| (u.2.comm <| Units.mk0 r hr).symm))⟩ map_one' := rfl map_mul' := fun _ _ ↦ rfl } invFun u := unitsCenterToCenterUnits G₀ u left_inv _ := by ext; rfl right_inv _ := by ext; rfl map_mul' := map_mul _ variable {G} @[to_additive] theorem mem_center_iff {z : G} : z ∈ center G ↔ ∀ g, g * z = z * g := by rw [← Semigroup.mem_center_iff] exact Iff.rfl instance decidableMemCenter (z : G) [Decidable (∀ g, g * z = z * g)] : Decidable (z ∈ center G) := decidable_of_iff' _ mem_center_iff @[to_additive] instance centerCharacteristic : (center G).Characteristic := by refine characteristic_iff_comap_le.mpr fun ϕ g hg => ?_ rw [mem_center_iff] intro h rw [← ϕ.injective.eq_iff, ϕ.map_mul, ϕ.map_mul] exact (hg.comm (ϕ h)).symm theorem _root_.CommGroup.center_eq_top {G : Type*} [CommGroup G] : center G = ⊤ := by rw [eq_top_iff'] intro x rw [Subgroup.mem_center_iff] intro y exact mul_comm y x /-- A group is commutative if the center is the whole group -/ def _root_.Group.commGroupOfCenterEqTop (h : center G = ⊤) : CommGroup G := { ‹Group G› with mul_comm := by rw [eq_top_iff'] at h intro x y apply Subgroup.mem_center_iff.mp _ x exact h y } variable {H : Subgroup G} section Normalizer @[to_additive] theorem center_le_normalizer : center G ≤ H.normalizer := fun x hx y => by simp [← mem_center_iff.mp hx y, mul_assoc] end Normalizer end Subgroup namespace IsConj variable {M : Type*} [Monoid M] theorem eq_of_left_mem_center {g h : M} (H : IsConj g h) (Hg : g ∈ Set.center M) : g = h := by rcases H with ⟨u, hu⟩; rwa [← u.mul_left_inj, Hg.comm u] theorem eq_of_right_mem_center {g h : M} (H : IsConj g h) (Hh : h ∈ Set.center M) : g = h := (H.symm.eq_of_left_mem_center Hh).symm end IsConj namespace ConjClasses theorem mk_bijOn (G : Type*) [Group G] : Set.BijOn ConjClasses.mk (↑(Subgroup.center G)) (noncenter G)ᶜ := by refine ⟨fun g hg ↦ ?_, fun x hx y _ H ↦ ?_, ?_⟩ · simp only [mem_noncenter, Set.compl_def, Set.mem_setOf, Set.not_nontrivial_iff] intro x hx y hy simp only [mem_carrier_iff_mk_eq, mk_eq_mk_iff_isConj] at hx hy rw [hx.eq_of_right_mem_center hg, hy.eq_of_right_mem_center hg] · rw [mk_eq_mk_iff_isConj] at H exact H.eq_of_left_mem_center hx · rintro ⟨g⟩ hg refine ⟨g, ?_, rfl⟩ simp only [mem_noncenter, Set.compl_def, Set.mem_setOf, Set.not_nontrivial_iff] at hg rw [SetLike.mem_coe, Subgroup.mem_center_iff] intro h rw [← mul_inv_eq_iff_eq_mul] refine hg ?_ mem_carrier_mk rw [mem_carrier_iff_mk_eq] apply mk_eq_mk_iff_isConj.mpr rw [isConj_comm, isConj_iff] exact ⟨h, rfl⟩ end ConjClasses assert_not_exists Multiset assert_not_exists Ring
GroupTheory\Subgroup\Centralizer.lean
/- Copyright (c) 2020 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import Mathlib.GroupTheory.Subgroup.Center import Mathlib.GroupTheory.Submonoid.Centralizer /-! # Centralizers of subgroups -/ open Function open Int variable {G : Type*} [Group G] namespace Subgroup variable {H K : Subgroup G} /-- The `centralizer` of `H` is the subgroup of `g : G` commuting with every `h : H`. -/ @[to_additive "The `centralizer` of `H` is the additive subgroup of `g : G` commuting with every `h : H`."] def centralizer (s : Set G) : Subgroup G := { Submonoid.centralizer s with carrier := Set.centralizer s inv_mem' := Set.inv_mem_centralizer } @[to_additive] theorem mem_centralizer_iff {g : G} {s : Set G} : g ∈ centralizer s ↔ ∀ h ∈ s, h * g = g * h := Iff.rfl @[to_additive] theorem mem_centralizer_iff_commutator_eq_one {g : G} {s : Set G} : g ∈ centralizer s ↔ ∀ h ∈ s, h * g * h⁻¹ * g⁻¹ = 1 := by simp only [mem_centralizer_iff, mul_inv_eq_iff_eq_mul, one_mul] @[to_additive] theorem centralizer_univ : centralizer Set.univ = center G := SetLike.ext' (Set.centralizer_univ G) @[to_additive] theorem le_centralizer_iff : H ≤ centralizer K ↔ K ≤ centralizer H := ⟨fun h x hx _y hy => (h hy x hx).symm, fun h x hx _y hy => (h hy x hx).symm⟩ @[to_additive] theorem center_le_centralizer (s) : center G ≤ centralizer s := Set.center_subset_centralizer s @[to_additive] theorem centralizer_le {s t : Set G} (h : s ⊆ t) : centralizer t ≤ centralizer s := Submonoid.centralizer_le h @[to_additive (attr := simp)] theorem centralizer_eq_top_iff_subset {s : Set G} : centralizer s = ⊤ ↔ s ⊆ center G := SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset @[to_additive] instance Centralizer.characteristic [hH : H.Characteristic] : (centralizer (H : Set G)).Characteristic := by refine Subgroup.characteristic_iff_comap_le.mpr fun ϕ g hg h hh => ϕ.injective ?_ rw [map_mul, map_mul] exact hg (ϕ h) (Subgroup.characteristic_iff_le_comap.mp hH ϕ hh) @[to_additive] theorem le_centralizer_iff_isCommutative : K ≤ centralizer K ↔ K.IsCommutative := ⟨fun h => ⟨⟨fun x y => Subtype.ext (h y.2 x x.2)⟩⟩, fun h x hx y hy => congr_arg Subtype.val (h.1.1 ⟨y, hy⟩ ⟨x, hx⟩)⟩ variable (H) @[to_additive] theorem le_centralizer [h : H.IsCommutative] : H ≤ centralizer H := le_centralizer_iff_isCommutative.mpr h end Subgroup
GroupTheory\Subgroup\Saturated.lean
/- Copyright (c) 2021 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Algebra.Group.Subgroup.Basic import Mathlib.Algebra.Module.Defs /-! # Saturated subgroups ## Tags subgroup, subgroups -/ namespace Subgroup variable {G : Type*} [Group G] /-- A subgroup `H` of `G` is *saturated* if for all `n : ℕ` and `g : G` with `g^n ∈ H` we have `n = 0` or `g ∈ H`. -/ @[to_additive "An additive subgroup `H` of `G` is *saturated* if for all `n : ℕ` and `g : G` with `n•g ∈ H` we have `n = 0` or `g ∈ H`."] def Saturated (H : Subgroup G) : Prop := ∀ ⦃n g⦄, g ^ n ∈ H → n = 0 ∨ g ∈ H @[to_additive] theorem saturated_iff_npow {H : Subgroup G} : Saturated H ↔ ∀ (n : ℕ) (g : G), g ^ n ∈ H → n = 0 ∨ g ∈ H := Iff.rfl @[to_additive] theorem saturated_iff_zpow {H : Subgroup G} : Saturated H ↔ ∀ (n : ℤ) (g : G), g ^ n ∈ H → n = 0 ∨ g ∈ H := by constructor · intros hH n g hgn induction' n with n n · simp only [Int.natCast_eq_zero, Int.ofNat_eq_coe, zpow_natCast] at hgn ⊢ exact hH hgn · suffices g ^ (n + 1) ∈ H by refine (hH this).imp ?_ id simp only [IsEmpty.forall_iff, Nat.succ_ne_zero] simpa only [inv_mem_iff, zpow_negSucc] using hgn · intro h n g hgn specialize h n g simp only [Int.natCast_eq_zero, zpow_natCast] at h apply h hgn end Subgroup namespace AddSubgroup theorem ker_saturated {A₁ A₂ : Type*} [AddCommGroup A₁] [AddCommGroup A₂] [NoZeroSMulDivisors ℕ A₂] (f : A₁ →+ A₂) : f.ker.Saturated := by intro n g hg simpa only [f.mem_ker, nsmul_eq_smul, f.map_nsmul, smul_eq_zero] using hg end AddSubgroup
GroupTheory\Subgroup\Simple.lean
/- Copyright (c) 2021 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.Order.Atoms import Mathlib.Algebra.Group.Subgroup.Basic /-! # Simple groups This file defines `IsSimpleGroup G`, a class indicating that a group has exactly two normal subgroups. ## Main definitions - `IsSimpleGroup G`, a class indicating that a group has exactly two normal subgroups. ## Tags subgroup, subgroups -/ variable {G : Type*} [Group G] variable {A : Type*} [AddGroup A] section variable (G) (A) /-- A `Group` is simple when it has exactly two normal `Subgroup`s. -/ class IsSimpleGroup extends Nontrivial G : Prop where /-- Any normal subgroup is either `⊥` or `⊤` -/ eq_bot_or_eq_top_of_normal : ∀ H : Subgroup G, H.Normal → H = ⊥ ∨ H = ⊤ /-- An `AddGroup` is simple when it has exactly two normal `AddSubgroup`s. -/ class IsSimpleAddGroup extends Nontrivial A : Prop where /-- Any normal additive subgroup is either `⊥` or `⊤` -/ eq_bot_or_eq_top_of_normal : ∀ H : AddSubgroup A, H.Normal → H = ⊥ ∨ H = ⊤ attribute [to_additive] IsSimpleGroup variable {G} {A} @[to_additive] theorem Subgroup.Normal.eq_bot_or_eq_top [IsSimpleGroup G] {H : Subgroup G} (Hn : H.Normal) : H = ⊥ ∨ H = ⊤ := IsSimpleGroup.eq_bot_or_eq_top_of_normal H Hn namespace IsSimpleGroup @[to_additive] instance {C : Type*} [CommGroup C] [IsSimpleGroup C] : IsSimpleOrder (Subgroup C) := ⟨fun H => H.normal_of_comm.eq_bot_or_eq_top⟩ open Subgroup @[to_additive] theorem isSimpleGroup_of_surjective {H : Type*} [Group H] [IsSimpleGroup G] [Nontrivial H] (f : G →* H) (hf : Function.Surjective f) : IsSimpleGroup H := ⟨fun H iH => by refine (iH.comap f).eq_bot_or_eq_top.imp (fun h => ?_) fun h => ?_ · rw [← map_bot f, ← h, map_comap_eq_self_of_surjective hf] · rw [← comap_top f] at h exact comap_injective hf h⟩ end IsSimpleGroup end
GroupTheory\Submonoid\Center.lean
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.Group.Submonoid.Operations import Mathlib.GroupTheory.Subsemigroup.Center /-! # Centers of monoids ## Main definitions * `Submonoid.center`: the center of a monoid * `AddSubmonoid.center`: the center of an additive monoid We provide `Subgroup.center`, `AddSubgroup.center`, `Subsemiring.center`, and `Subring.center` in other files. -/ namespace Submonoid section MulOneClass variable (M : Type*) [MulOneClass M] /-- The center of a multiplication with unit `M` is the set of elements that commute with everything in `M` -/ @[to_additive "The center of an addition with zero `M` is the set of elements that commute with everything in `M`"] def center : Submonoid M where carrier := Set.center M one_mem' := Set.one_mem_center mul_mem' := Set.mul_mem_center @[to_additive] theorem coe_center : ↑(center M) = Set.center M := rfl @[to_additive (attr := simp) AddSubmonoid.center_toAddSubsemigroup] theorem center_toSubsemigroup : (center M).toSubsemigroup = Subsemigroup.center M := rfl variable {M} /-- The center of a multiplication with unit is commutative and associative. This is not an instance as it forms an non-defeq diamond with `Submonoid.toMonoid` in the `npow` field. -/ @[to_additive "The center of an addition with zero is commutative and associative."] abbrev center.commMonoid' : CommMonoid (center M) := { (center M).toMulOneClass, Subsemigroup.center.commSemigroup with } end MulOneClass section Monoid variable {M} [Monoid M] /-- The center of a monoid is commutative. -/ @[to_additive] instance center.commMonoid : CommMonoid (center M) := { (center M).toMonoid, Subsemigroup.center.commSemigroup with } -- no instance diamond, unlike the primed version example : center.commMonoid.toMonoid = Submonoid.toMonoid (center M) := by with_reducible_and_instances rfl @[to_additive] theorem mem_center_iff {z : M} : z ∈ center M ↔ ∀ g, g * z = z * g := by rw [← Semigroup.mem_center_iff] exact Iff.rfl @[to_additive] instance decidableMemCenter (a) [Decidable <| ∀ b : M, b * a = a * b] : Decidable (a ∈ center M) := decidable_of_iff' _ mem_center_iff /-- The center of a monoid acts commutatively on that monoid. -/ instance center.smulCommClass_left : SMulCommClass (center M) M M where smul_comm m x y := Commute.left_comm (m.prop.comm x) y /-- The center of a monoid acts commutatively on that monoid. -/ instance center.smulCommClass_right : SMulCommClass M (center M) M := SMulCommClass.symm _ _ _ /-! Note that `smulCommClass (center M) (center M) M` is already implied by `Submonoid.smulCommClass_right` -/ example : SMulCommClass (center M) (center M) M := by infer_instance end Monoid section variable (M : Type*) [CommMonoid M] @[simp] theorem center_eq_top : center M = ⊤ := SetLike.coe_injective (Set.center_eq_univ M) end end Submonoid variable (M) /-- For a monoid, the units of the center inject into the center of the units. This is not an equivalence in general; one case when it is is for groups with zero, which is covered in `centerUnitsEquivUnitsCenter`. -/ @[to_additive (attr := simps! apply_coe_val) "For an additive monoid, the units of the center inject into the center of the units."] def unitsCenterToCenterUnits [Monoid M] : (Submonoid.center M)ˣ →* Submonoid.center (Mˣ) := (Units.map (Submonoid.center M).subtype).codRestrict _ <| fun u ↦ Submonoid.mem_center_iff.mpr <| fun r ↦ Units.ext <| by rw [Units.val_mul, Units.coe_map, Submonoid.coe_subtype, Units.val_mul, Units.coe_map, Submonoid.coe_subtype, u.1.prop.comm r] @[to_additive] theorem unitsCenterToCenterUnits_injective [Monoid M] : Function.Injective (unitsCenterToCenterUnits M) := fun _a _b h => Units.ext <| Subtype.ext <| congr_arg (Units.val ∘ Subtype.val) h -- Guard against import creep assert_not_exists Finset
GroupTheory\Submonoid\Centralizer.lean
/- Copyright (c) 2021 Thomas Browning. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning -/ import Mathlib.GroupTheory.Subsemigroup.Centralizer import Mathlib.GroupTheory.Submonoid.Center /-! # Centralizers of magmas and monoids ## Main definitions * `Submonoid.centralizer`: the centralizer of a subset of a monoid * `AddSubmonoid.centralizer`: the centralizer of a subset of an additive monoid We provide `Subgroup.centralizer`, `AddSubgroup.centralizer` in other files. -/ variable {M : Type*} {S T : Set M} namespace Submonoid section variable [Monoid M] (S) /-- The centralizer of a subset of a monoid `M`. -/ @[to_additive "The centralizer of a subset of an additive monoid."] def centralizer : Submonoid M where carrier := S.centralizer one_mem' := S.one_mem_centralizer mul_mem' := Set.mul_mem_centralizer @[to_additive (attr := simp, norm_cast)] theorem coe_centralizer : ↑(centralizer S) = S.centralizer := rfl theorem centralizer_toSubsemigroup : (centralizer S).toSubsemigroup = Subsemigroup.centralizer S := rfl theorem _root_.AddSubmonoid.centralizer_toAddSubsemigroup {M} [AddMonoid M] (S : Set M) : (AddSubmonoid.centralizer S).toAddSubsemigroup = AddSubsemigroup.centralizer S := rfl attribute [to_additive existing AddSubmonoid.centralizer_toAddSubsemigroup] Submonoid.centralizer_toSubsemigroup variable {S} @[to_additive] theorem mem_centralizer_iff {z : M} : z ∈ centralizer S ↔ ∀ g ∈ S, g * z = z * g := Iff.rfl @[to_additive] theorem center_le_centralizer (s) : center M ≤ centralizer s := s.center_subset_centralizer @[to_additive] instance decidableMemCentralizer (a) [Decidable <| ∀ b ∈ S, b * a = a * b] : Decidable (a ∈ centralizer S) := decidable_of_iff' _ mem_centralizer_iff @[to_additive] theorem centralizer_le (h : S ⊆ T) : centralizer T ≤ centralizer S := Set.centralizer_subset h @[to_additive (attr := simp)] theorem centralizer_eq_top_iff_subset {s : Set M} : centralizer s = ⊤ ↔ s ⊆ center M := SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset variable (M) @[to_additive (attr := simp)] theorem centralizer_univ : centralizer Set.univ = center M := SetLike.ext' (Set.centralizer_univ M) @[to_additive] lemma le_centralizer_centralizer {s : Submonoid M} : s ≤ centralizer (centralizer (s : Set M)) := Set.subset_centralizer_centralizer @[to_additive (attr := simp)] lemma centralizer_centralizer_centralizer {s : Set M} : centralizer s.centralizer.centralizer = centralizer s := by apply SetLike.coe_injective simp only [coe_centralizer, Set.centralizer_centralizer_centralizer] end end Submonoid -- Guard against import creep assert_not_exists Finset
GroupTheory\Submonoid\Inverses.lean
/- Copyright (c) 2021 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.Algebra.Group.Submonoid.Pointwise /-! # Submonoid of inverses Given a submonoid `N` of a monoid `M`, we define the submonoid `N.leftInv` as the submonoid of left inverses of `N`. When `M` is commutative, we may define `fromCommLeftInv : N.leftInv →* N` since the inverses are unique. When `N ≤ IsUnit.Submonoid M`, this is precisely the pointwise inverse of `N`, and we may define `leftInvEquiv : S.leftInv ≃* S`. For the pointwise inverse of submonoids of groups, please refer to the file `Mathlib.Algebra.Group.Submonoid.Pointwise`. `N.leftInv` is distinct from `N.units`, which is the subgroup of `Mˣ` containing all units that are in `N`. See the implementation notes of `Mathlib.GroupTheory.Submonoid.Units` for more details on related constructions. ## TODO Define the submonoid of right inverses and two-sided inverses. See the comments of #10679 for a possible implementation. -/ variable {M : Type*} namespace Submonoid @[to_additive] noncomputable instance [Monoid M] : Group (IsUnit.submonoid M) := { inferInstanceAs (Monoid (IsUnit.submonoid M)) with inv := fun x ↦ ⟨x.prop.unit⁻¹.val, x.prop.unit⁻¹.isUnit⟩ mul_left_inv := fun x ↦ Subtype.ext ((Units.val_mul x.prop.unit⁻¹ _).trans x.prop.unit.inv_val) } @[to_additive] noncomputable instance [CommMonoid M] : CommGroup (IsUnit.submonoid M) := { inferInstanceAs (Group (IsUnit.submonoid M)) with mul_comm := fun a b ↦ by convert mul_comm a b } @[to_additive] theorem IsUnit.Submonoid.coe_inv [Monoid M] (x : IsUnit.submonoid M) : ↑x⁻¹ = (↑x.prop.unit⁻¹ : M) := rfl section Monoid variable [Monoid M] (S : Submonoid M) /-- `S.leftInv` is the submonoid containing all the left inverses of `S`. -/ @[to_additive "`S.leftNeg` is the additive submonoid containing all the left additive inverses of `S`."] def leftInv : Submonoid M where carrier := { x : M | ∃ y : S, x * y = 1 } one_mem' := ⟨1, mul_one 1⟩ mul_mem' := fun {a} _b ⟨a', ha⟩ ⟨b', hb⟩ ↦ ⟨b' * a', by simp only [coe_mul, ← mul_assoc, mul_assoc a, hb, mul_one, ha]⟩ @[to_additive] theorem leftInv_leftInv_le : S.leftInv.leftInv ≤ S := by rintro x ⟨⟨y, z, h₁⟩, h₂ : x * y = 1⟩ convert z.prop rw [← mul_one x, ← h₁, ← mul_assoc, h₂, one_mul] @[to_additive] theorem unit_mem_leftInv (x : Mˣ) (hx : (x : M) ∈ S) : ((x⁻¹ : _) : M) ∈ S.leftInv := ⟨⟨x, hx⟩, x.inv_val⟩ @[to_additive] theorem leftInv_leftInv_eq (hS : S ≤ IsUnit.submonoid M) : S.leftInv.leftInv = S := by refine le_antisymm S.leftInv_leftInv_le ?_ intro x hx have : x = ((hS hx).unit⁻¹⁻¹ : Mˣ) := by rw [inv_inv (hS hx).unit] rfl rw [this] exact S.leftInv.unit_mem_leftInv _ (S.unit_mem_leftInv _ hx) /-- The function from `S.leftInv` to `S` sending an element to its right inverse in `S`. This is a `MonoidHom` when `M` is commutative. -/ @[to_additive "The function from `S.leftAdd` to `S` sending an element to its right additive inverse in `S`. This is an `AddMonoidHom` when `M` is commutative."] noncomputable def fromLeftInv : S.leftInv → S := fun x ↦ x.prop.choose @[to_additive (attr := simp)] theorem mul_fromLeftInv (x : S.leftInv) : (x : M) * S.fromLeftInv x = 1 := x.prop.choose_spec @[to_additive (attr := simp)] theorem fromLeftInv_one : S.fromLeftInv 1 = 1 := (one_mul _).symm.trans (Subtype.eq <| S.mul_fromLeftInv 1) end Monoid section CommMonoid variable [CommMonoid M] (S : Submonoid M) @[to_additive (attr := simp)] theorem fromLeftInv_mul (x : S.leftInv) : (S.fromLeftInv x : M) * x = 1 := by rw [mul_comm, mul_fromLeftInv] @[to_additive] theorem leftInv_le_isUnit : S.leftInv ≤ IsUnit.submonoid M := fun x ⟨y, hx⟩ ↦ ⟨⟨x, y, hx, mul_comm x y ▸ hx⟩, rfl⟩ @[to_additive] theorem fromLeftInv_eq_iff (a : S.leftInv) (b : M) : (S.fromLeftInv a : M) = b ↔ (a : M) * b = 1 := by rw [← IsUnit.mul_right_inj (leftInv_le_isUnit _ a.prop), S.mul_fromLeftInv, eq_comm] /-- The `MonoidHom` from `S.leftInv` to `S` sending an element to its right inverse in `S`. -/ @[to_additive (attr := simps) "The `AddMonoidHom` from `S.leftNeg` to `S` sending an element to its right additive inverse in `S`."] noncomputable def fromCommLeftInv : S.leftInv →* S where toFun := S.fromLeftInv map_one' := S.fromLeftInv_one map_mul' x y := Subtype.ext <| by rw [fromLeftInv_eq_iff, mul_comm x, Submonoid.coe_mul, Submonoid.coe_mul, mul_assoc, ← mul_assoc (x : M), mul_fromLeftInv, one_mul, mul_fromLeftInv] variable (hS : S ≤ IsUnit.submonoid M) /-- The submonoid of pointwise inverse of `S` is `MulEquiv` to `S`. -/ @[to_additive (attr := simps apply) "The additive submonoid of pointwise additive inverse of `S` is `AddEquiv` to `S`."] noncomputable def leftInvEquiv : S.leftInv ≃* S := { S.fromCommLeftInv with invFun := fun x ↦ by choose x' hx using hS x.prop exact ⟨x'.inv, x, hx ▸ x'.inv_val⟩ left_inv := fun x ↦ Subtype.eq <| by dsimp only; generalize_proofs h; rw [← h.choose.mul_left_inj] conv => rhs; rw [h.choose_spec] exact h.choose.inv_val.trans (S.mul_fromLeftInv x).symm right_inv := fun x ↦ by dsimp only [fromCommLeftInv] ext rw [fromLeftInv_eq_iff] convert (hS x.prop).choose.inv_val exact (hS x.prop).choose_spec.symm } @[to_additive (attr := simp)] theorem fromLeftInv_leftInvEquiv_symm (x : S) : S.fromLeftInv ((S.leftInvEquiv hS).symm x) = x := (S.leftInvEquiv hS).right_inv x @[to_additive (attr := simp)] theorem leftInvEquiv_symm_fromLeftInv (x : S.leftInv) : (S.leftInvEquiv hS).symm (S.fromLeftInv x) = x := (S.leftInvEquiv hS).left_inv x @[to_additive] theorem leftInvEquiv_mul (x : S.leftInv) : (S.leftInvEquiv hS x : M) * x = 1 := by simpa only [leftInvEquiv_apply, fromCommLeftInv] using fromLeftInv_mul S x @[to_additive] theorem mul_leftInvEquiv (x : S.leftInv) : (x : M) * S.leftInvEquiv hS x = 1 := by simp only [leftInvEquiv_apply, fromCommLeftInv, mul_fromLeftInv] @[to_additive (attr := simp)] theorem leftInvEquiv_symm_mul (x : S) : ((S.leftInvEquiv hS).symm x : M) * x = 1 := by convert S.mul_leftInvEquiv hS ((S.leftInvEquiv hS).symm x) simp @[to_additive (attr := simp)] theorem mul_leftInvEquiv_symm (x : S) : (x : M) * (S.leftInvEquiv hS).symm x = 1 := by convert S.leftInvEquiv_mul hS ((S.leftInvEquiv hS).symm x) simp end CommMonoid section Group variable [Group M] (S : Submonoid M) open Pointwise @[to_additive] theorem leftInv_eq_inv : S.leftInv = S⁻¹ := Submonoid.ext fun _ ↦ ⟨fun h ↦ Submonoid.mem_inv.mpr ((inv_eq_of_mul_eq_one_right h.choose_spec).symm ▸ h.choose.prop), fun h ↦ ⟨⟨_, h⟩, mul_right_inv _⟩⟩ @[to_additive (attr := simp)] theorem fromLeftInv_eq_inv (x : S.leftInv) : (S.fromLeftInv x : M) = (x : M)⁻¹ := by rw [← mul_right_inj (x : M), mul_right_inv, mul_fromLeftInv] end Group section CommGroup variable [CommGroup M] (S : Submonoid M) (hS : S ≤ IsUnit.submonoid M) @[to_additive (attr := simp)] theorem leftInvEquiv_symm_eq_inv (x : S) : ((S.leftInvEquiv hS).symm x : M) = (x : M)⁻¹ := by rw [← mul_right_inj (x : M), mul_right_inv, mul_leftInvEquiv_symm] end CommGroup end Submonoid
GroupTheory\Subsemigroup\Center.lean
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser, Jireh Loreaux -/ import Mathlib.Algebra.Group.Center import Mathlib.Algebra.Group.Subsemigroup.Operations /-! # Centers of semigroups, as subsemigroups. ## Main definitions * `Subsemigroup.center`: the center of a semigroup * `AddSubsemigroup.center`: the center of an additive semigroup We provide `Submonoid.center`, `AddSubmonoid.center`, `Subgroup.center`, `AddSubgroup.center`, `Subsemiring.center`, and `Subring.center` in other files. ## References * [Cabrera García and Rodríguez Palacios, Non-associative normed algebras. Volume 1] [cabreragarciarodriguezpalacios2014] -/ /-! ### `Set.center` as a `Subsemigroup`. -/ variable (M) namespace Subsemigroup section Mul variable [Mul M] /-- The center of a semigroup `M` is the set of elements that commute with everything in `M` -/ @[to_additive "The center of a semigroup `M` is the set of elements that commute with everything in `M`"] def center : Subsemigroup M where carrier := Set.center M mul_mem' := Set.mul_mem_center -- Porting note: `coe_center` is now redundant variable {M} /-- The center of a magma is commutative and associative. -/ @[to_additive "The center of an additive magma is commutative and associative."] instance center.commSemigroup : CommSemigroup (center M) where mul_assoc _ b _ := Subtype.ext <| b.2.mid_assoc _ _ mul_comm a _ := Subtype.ext <| a.2.comm _ end Mul section Semigroup variable {M} [Semigroup M] @[to_additive] theorem mem_center_iff {z : M} : z ∈ center M ↔ ∀ g, g * z = z * g := by rw [← Semigroup.mem_center_iff] exact Iff.rfl @[to_additive] instance decidableMemCenter (a) [Decidable <| ∀ b : M, b * a = a * b] : Decidable (a ∈ center M) := decidable_of_iff' _ Semigroup.mem_center_iff end Semigroup section CommSemigroup variable [CommSemigroup M] @[to_additive (attr := simp)] theorem center_eq_top : center M = ⊤ := SetLike.coe_injective (Set.center_eq_univ M) end CommSemigroup end Subsemigroup -- Guard against import creep assert_not_exists Finset
GroupTheory\Subsemigroup\Centralizer.lean
/- Copyright (c) 2021 Thomas Browning. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning, Jireh Loreaux -/ import Mathlib.GroupTheory.Subsemigroup.Center import Mathlib.Algebra.Group.Center /-! # Centralizers in semigroups, as subsemigroups. ## Main definitions * `Subsemigroup.centralizer`: the centralizer of a subset of a semigroup * `AddSubsemigroup.centralizer`: the centralizer of a subset of an additive semigroup We provide `Monoid.centralizer`, `AddMonoid.centralizer`, `Subgroup.centralizer`, and `AddSubgroup.centralizer` in other files. -/ variable {M : Type*} {S T : Set M} namespace Subsemigroup section variable [Semigroup M] (S) /-- The centralizer of a subset of a semigroup `M`. -/ @[to_additive "The centralizer of a subset of an additive semigroup."] def centralizer : Subsemigroup M where carrier := S.centralizer mul_mem' := Set.mul_mem_centralizer @[to_additive (attr := simp, norm_cast)] theorem coe_centralizer : ↑(centralizer S) = S.centralizer := rfl variable {S} @[to_additive] theorem mem_centralizer_iff {z : M} : z ∈ centralizer S ↔ ∀ g ∈ S, g * z = z * g := Iff.rfl @[to_additive] instance decidableMemCentralizer (a) [Decidable <| ∀ b ∈ S, b * a = a * b] : Decidable (a ∈ centralizer S) := decidable_of_iff' _ mem_centralizer_iff @[to_additive] theorem center_le_centralizer (S) : center M ≤ centralizer S := S.center_subset_centralizer @[to_additive] theorem centralizer_le (h : S ⊆ T) : centralizer T ≤ centralizer S := Set.centralizer_subset h @[to_additive (attr := simp)] theorem centralizer_eq_top_iff_subset {s : Set M} : centralizer s = ⊤ ↔ s ⊆ center M := SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset variable (M) @[to_additive (attr := simp)] theorem centralizer_univ : centralizer Set.univ = center M := SetLike.ext' (Set.centralizer_univ M) end end Subsemigroup -- Guard against import creep assert_not_exists Finset
InformationTheory\Hamming.lean
/- Copyright (c) 2022 Wrenna Robson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Wrenna Robson -/ import Mathlib.Analysis.Normed.Group.Basic import Mathlib.Topology.Instances.Discrete /-! # Hamming spaces The Hamming metric counts the number of places two members of a (finite) Pi type differ. The Hamming norm is the same as the Hamming metric over additive groups, and counts the number of places a member of a (finite) Pi type differs from zero. This is a useful notion in various applications, but in particular it is relevant in coding theory, in which it is fundamental for defining the minimum distance of a code. ## Main definitions * `hammingDist x y`: the Hamming distance between `x` and `y`, the number of entries which differ. * `hammingNorm x`: the Hamming norm of `x`, the number of non-zero entries. * `Hamming β`: a type synonym for `Π i, β i` with `dist` and `norm` provided by the above. * `Hamming.toHamming`, `Hamming.ofHamming`: functions for casting between `Hamming β` and `Π i, β i`. * the Hamming norm forms a normed group on `Hamming β`. -/ section HammingDistNorm open Finset Function variable {α ι : Type*} {β : ι → Type*} [Fintype ι] [∀ i, DecidableEq (β i)] variable {γ : ι → Type*} [∀ i, DecidableEq (γ i)] /-- The Hamming distance function to the naturals. -/ def hammingDist (x y : ∀ i, β i) : ℕ := (univ.filter fun i => x i ≠ y i).card /-- Corresponds to `dist_self`. -/ @[simp] theorem hammingDist_self (x : ∀ i, β i) : hammingDist x x = 0 := by rw [hammingDist, card_eq_zero, filter_eq_empty_iff] exact fun _ _ H => H rfl /-- Corresponds to `dist_nonneg`. -/ theorem hammingDist_nonneg {x y : ∀ i, β i} : 0 ≤ hammingDist x y := zero_le _ /-- Corresponds to `dist_comm`. -/ theorem hammingDist_comm (x y : ∀ i, β i) : hammingDist x y = hammingDist y x := by simp_rw [hammingDist, ne_comm] /-- Corresponds to `dist_triangle`. -/ theorem hammingDist_triangle (x y z : ∀ i, β i) : hammingDist x z ≤ hammingDist x y + hammingDist y z := by classical unfold hammingDist refine le_trans (card_mono ?_) (card_union_le _ _) rw [← filter_or] exact monotone_filter_right _ fun i h ↦ (h.ne_or_ne _).imp_right Ne.symm /-- Corresponds to `dist_triangle_left`. -/ theorem hammingDist_triangle_left (x y z : ∀ i, β i) : hammingDist x y ≤ hammingDist z x + hammingDist z y := by rw [hammingDist_comm z] exact hammingDist_triangle _ _ _ /-- Corresponds to `dist_triangle_right`. -/ theorem hammingDist_triangle_right (x y z : ∀ i, β i) : hammingDist x y ≤ hammingDist x z + hammingDist y z := by rw [hammingDist_comm y] exact hammingDist_triangle _ _ _ /-- Corresponds to `swap_dist`. -/ theorem swap_hammingDist : swap (@hammingDist _ β _ _) = hammingDist := by funext x y exact hammingDist_comm _ _ /-- Corresponds to `eq_of_dist_eq_zero`. -/ theorem eq_of_hammingDist_eq_zero {x y : ∀ i, β i} : hammingDist x y = 0 → x = y := by simp_rw [hammingDist, card_eq_zero, filter_eq_empty_iff, Classical.not_not, funext_iff, mem_univ, forall_true_left, imp_self] /-- Corresponds to `dist_eq_zero`. -/ @[simp] theorem hammingDist_eq_zero {x y : ∀ i, β i} : hammingDist x y = 0 ↔ x = y := ⟨eq_of_hammingDist_eq_zero, fun H => by rw [H] exact hammingDist_self _⟩ /-- Corresponds to `zero_eq_dist`. -/ @[simp] theorem hamming_zero_eq_dist {x y : ∀ i, β i} : 0 = hammingDist x y ↔ x = y := by rw [eq_comm, hammingDist_eq_zero] /-- Corresponds to `dist_ne_zero`. -/ theorem hammingDist_ne_zero {x y : ∀ i, β i} : hammingDist x y ≠ 0 ↔ x ≠ y := hammingDist_eq_zero.not /-- Corresponds to `dist_pos`. -/ @[simp] theorem hammingDist_pos {x y : ∀ i, β i} : 0 < hammingDist x y ↔ x ≠ y := by rw [← hammingDist_ne_zero, iff_not_comm, not_lt, Nat.le_zero] -- @[simp] -- Porting note (#10618): simp can prove this theorem hammingDist_lt_one {x y : ∀ i, β i} : hammingDist x y < 1 ↔ x = y := by rw [Nat.lt_one_iff, hammingDist_eq_zero] theorem hammingDist_le_card_fintype {x y : ∀ i, β i} : hammingDist x y ≤ Fintype.card ι := card_le_univ _ theorem hammingDist_comp_le_hammingDist (f : ∀ i, γ i → β i) {x y : ∀ i, γ i} : (hammingDist (fun i => f i (x i)) fun i => f i (y i)) ≤ hammingDist x y := card_mono (monotone_filter_right _ fun i H1 H2 => H1 <| congr_arg (f i) H2) theorem hammingDist_comp (f : ∀ i, γ i → β i) {x y : ∀ i, γ i} (hf : ∀ i, Injective (f i)) : (hammingDist (fun i => f i (x i)) fun i => f i (y i)) = hammingDist x y := le_antisymm (hammingDist_comp_le_hammingDist _) <| card_mono (monotone_filter_right _ fun i H1 H2 => H1 <| hf i H2) theorem hammingDist_smul_le_hammingDist [∀ i, SMul α (β i)] {k : α} {x y : ∀ i, β i} : hammingDist (k • x) (k • y) ≤ hammingDist x y := hammingDist_comp_le_hammingDist fun i => (k • · : β i → β i) /-- Corresponds to `dist_smul` with the discrete norm on `α`. -/ theorem hammingDist_smul [∀ i, SMul α (β i)] {k : α} {x y : ∀ i, β i} (hk : ∀ i, IsSMulRegular (β i) k) : hammingDist (k • x) (k • y) = hammingDist x y := hammingDist_comp (fun i => (k • · : β i → β i)) hk section Zero variable [∀ i, Zero (β i)] [∀ i, Zero (γ i)] /-- The Hamming weight function to the naturals. -/ def hammingNorm (x : ∀ i, β i) : ℕ := (univ.filter (x · ≠ 0)).card /-- Corresponds to `dist_zero_right`. -/ @[simp] theorem hammingDist_zero_right (x : ∀ i, β i) : hammingDist x 0 = hammingNorm x := rfl /-- Corresponds to `dist_zero_left`. -/ @[simp] theorem hammingDist_zero_left : hammingDist (0 : ∀ i, β i) = hammingNorm := funext fun x => by rw [hammingDist_comm, hammingDist_zero_right] /-- Corresponds to `norm_nonneg`. -/ -- @[simp] -- Porting note (#10618): simp can prove this theorem hammingNorm_nonneg {x : ∀ i, β i} : 0 ≤ hammingNorm x := zero_le _ /-- Corresponds to `norm_zero`. -/ @[simp] theorem hammingNorm_zero : hammingNorm (0 : ∀ i, β i) = 0 := hammingDist_self _ /-- Corresponds to `norm_eq_zero`. -/ @[simp] theorem hammingNorm_eq_zero {x : ∀ i, β i} : hammingNorm x = 0 ↔ x = 0 := hammingDist_eq_zero /-- Corresponds to `norm_ne_zero_iff`. -/ theorem hammingNorm_ne_zero_iff {x : ∀ i, β i} : hammingNorm x ≠ 0 ↔ x ≠ 0 := hammingNorm_eq_zero.not /-- Corresponds to `norm_pos_iff`. -/ @[simp] theorem hammingNorm_pos_iff {x : ∀ i, β i} : 0 < hammingNorm x ↔ x ≠ 0 := hammingDist_pos -- @[simp] -- Porting note (#10618): simp can prove this theorem hammingNorm_lt_one {x : ∀ i, β i} : hammingNorm x < 1 ↔ x = 0 := hammingDist_lt_one theorem hammingNorm_le_card_fintype {x : ∀ i, β i} : hammingNorm x ≤ Fintype.card ι := hammingDist_le_card_fintype theorem hammingNorm_comp_le_hammingNorm (f : ∀ i, γ i → β i) {x : ∀ i, γ i} (hf : ∀ i, f i 0 = 0) : (hammingNorm fun i => f i (x i)) ≤ hammingNorm x := by simpa only [← hammingDist_zero_right, hf] using hammingDist_comp_le_hammingDist f (y := fun _ ↦ 0) theorem hammingNorm_comp (f : ∀ i, γ i → β i) {x : ∀ i, γ i} (hf₁ : ∀ i, Injective (f i)) (hf₂ : ∀ i, f i 0 = 0) : (hammingNorm fun i => f i (x i)) = hammingNorm x := by simpa only [← hammingDist_zero_right, hf₂] using hammingDist_comp f hf₁ (y := fun _ ↦ 0) theorem hammingNorm_smul_le_hammingNorm [Zero α] [∀ i, SMulWithZero α (β i)] {k : α} {x : ∀ i, β i} : hammingNorm (k • x) ≤ hammingNorm x := hammingNorm_comp_le_hammingNorm (fun i (c : β i) => k • c) fun i => by simp_rw [smul_zero] theorem hammingNorm_smul [Zero α] [∀ i, SMulWithZero α (β i)] {k : α} (hk : ∀ i, IsSMulRegular (β i) k) (x : ∀ i, β i) : hammingNorm (k • x) = hammingNorm x := hammingNorm_comp (fun i (c : β i) => k • c) hk fun i => by simp_rw [smul_zero] end Zero /-- Corresponds to `dist_eq_norm`. -/ theorem hammingDist_eq_hammingNorm [∀ i, AddGroup (β i)] (x y : ∀ i, β i) : hammingDist x y = hammingNorm (x - y) := by simp_rw [hammingNorm, hammingDist, Pi.sub_apply, sub_ne_zero] end HammingDistNorm /-! ### The `Hamming` type synonym -/ /-- Type synonym for a Pi type which inherits the usual algebraic instances, but is equipped with the Hamming metric and norm, instead of `Pi.normedAddCommGroup` which uses the sup norm. -/ def Hamming {ι : Type*} (β : ι → Type*) : Type _ := ∀ i, β i namespace Hamming variable {α ι : Type*} {β : ι → Type*} /-! Instances inherited from normal Pi types. -/ instance [∀ i, Inhabited (β i)] : Inhabited (Hamming β) := ⟨fun _ => default⟩ instance [DecidableEq ι] [Fintype ι] [∀ i, Fintype (β i)] : Fintype (Hamming β) := Pi.fintype instance [Inhabited ι] [∀ i, Nonempty (β i)] [Nontrivial (β default)] : Nontrivial (Hamming β) := Pi.nontrivial instance [Fintype ι] [∀ i, DecidableEq (β i)] : DecidableEq (Hamming β) := Fintype.decidablePiFintype instance [∀ i, Zero (β i)] : Zero (Hamming β) := Pi.instZero instance [∀ i, Neg (β i)] : Neg (Hamming β) := Pi.instNeg instance [∀ i, Add (β i)] : Add (Hamming β) := Pi.instAdd instance [∀ i, Sub (β i)] : Sub (Hamming β) := Pi.instSub instance [∀ i, SMul α (β i)] : SMul α (Hamming β) := Pi.instSMul instance [Zero α] [∀ i, Zero (β i)] [∀ i, SMulWithZero α (β i)] : SMulWithZero α (Hamming β) := Pi.smulWithZero _ instance [∀ i, AddMonoid (β i)] : AddMonoid (Hamming β) := Pi.addMonoid instance [∀ i, AddCommMonoid (β i)] : AddCommMonoid (Hamming β) := Pi.addCommMonoid instance [∀ i, AddCommGroup (β i)] : AddCommGroup (Hamming β) := Pi.addCommGroup instance (α) [Semiring α] (β : ι → Type*) [∀ i, AddCommMonoid (β i)] [∀ i, Module α (β i)] : Module α (Hamming β) := Pi.module _ _ _ /-! API to/from the type synonym. -/ /-- `Hamming.toHamming` is the identity function to the `Hamming` of a type. -/ @[match_pattern] def toHamming : (∀ i, β i) ≃ Hamming β := Equiv.refl _ /-- `Hamming.ofHamming` is the identity function from the `Hamming` of a type. -/ @[match_pattern] def ofHamming : Hamming β ≃ ∀ i, β i := Equiv.refl _ @[simp] theorem toHamming_symm_eq : (@toHamming _ β).symm = ofHamming := rfl @[simp] theorem ofHamming_symm_eq : (@ofHamming _ β).symm = toHamming := rfl @[simp] theorem toHamming_ofHamming (x : Hamming β) : toHamming (ofHamming x) = x := rfl @[simp] theorem ofHamming_toHamming (x : ∀ i, β i) : ofHamming (toHamming x) = x := rfl --@[simp] -- Porting note (#10618): removing `simp`, `simp` can prove it -- and `dsimp` cannot use `Iff.rfl` theorem toHamming_inj {x y : ∀ i, β i} : toHamming x = toHamming y ↔ x = y := Iff.rfl --@[simp] -- Porting note (#10618): removing `simp`, `simp` can prove it -- and `dsimp` cannot use `Iff.rfl` theorem ofHamming_inj {x y : Hamming β} : ofHamming x = ofHamming y ↔ x = y := Iff.rfl @[simp] theorem toHamming_zero [∀ i, Zero (β i)] : toHamming (0 : ∀ i, β i) = 0 := rfl @[simp] theorem ofHamming_zero [∀ i, Zero (β i)] : ofHamming (0 : Hamming β) = 0 := rfl @[simp] theorem toHamming_neg [∀ i, Neg (β i)] {x : ∀ i, β i} : toHamming (-x) = -toHamming x := rfl @[simp] theorem ofHamming_neg [∀ i, Neg (β i)] {x : Hamming β} : ofHamming (-x) = -ofHamming x := rfl @[simp] theorem toHamming_add [∀ i, Add (β i)] {x y : ∀ i, β i} : toHamming (x + y) = toHamming x + toHamming y := rfl @[simp] theorem ofHamming_add [∀ i, Add (β i)] {x y : Hamming β} : ofHamming (x + y) = ofHamming x + ofHamming y := rfl @[simp] theorem toHamming_sub [∀ i, Sub (β i)] {x y : ∀ i, β i} : toHamming (x - y) = toHamming x - toHamming y := rfl @[simp] theorem ofHamming_sub [∀ i, Sub (β i)] {x y : Hamming β} : ofHamming (x - y) = ofHamming x - ofHamming y := rfl @[simp] theorem toHamming_smul [∀ i, SMul α (β i)] {r : α} {x : ∀ i, β i} : toHamming (r • x) = r • toHamming x := rfl @[simp] theorem ofHamming_smul [∀ i, SMul α (β i)] {r : α} {x : Hamming β} : ofHamming (r • x) = r • ofHamming x := rfl section /-! Instances equipping `Hamming` with `hammingNorm` and `hammingDist`. -/ variable [Fintype ι] [∀ i, DecidableEq (β i)] instance : Dist (Hamming β) := ⟨fun x y => hammingDist (ofHamming x) (ofHamming y)⟩ @[simp, push_cast] theorem dist_eq_hammingDist (x y : Hamming β) : dist x y = hammingDist (ofHamming x) (ofHamming y) := rfl instance : PseudoMetricSpace (Hamming β) where dist_self := by push_cast exact mod_cast hammingDist_self dist_comm := by push_cast exact mod_cast hammingDist_comm dist_triangle := by push_cast exact mod_cast hammingDist_triangle toUniformSpace := ⊥ uniformity_dist := uniformity_dist_of_mem_uniformity _ _ fun s => by push_cast constructor · refine fun hs => ⟨1, zero_lt_one, fun hab => ?_⟩ rw_mod_cast [hammingDist_lt_one] at hab rw [ofHamming_inj, ← mem_idRel] at hab exact hs hab · rintro ⟨_, hε, hs⟩ ⟨_, _⟩ hab rw [mem_idRel] at hab rw [hab] refine hs (lt_of_eq_of_lt ?_ hε) exact mod_cast hammingDist_self _ toBornology := ⟨⊥, bot_le⟩ cobounded_sets := by ext push_cast refine iff_of_true (Filter.mem_sets.mpr Filter.mem_bot) ⟨Fintype.card ι, fun _ _ _ _ => ?_⟩ exact mod_cast hammingDist_le_card_fintype @[simp, push_cast] theorem nndist_eq_hammingDist (x y : Hamming β) : nndist x y = hammingDist (ofHamming x) (ofHamming y) := rfl -- Porting note (#10754): new instance instance : DiscreteTopology (Hamming β) := ⟨rfl⟩ instance : MetricSpace (Hamming β) := .ofT0PseudoMetricSpace _ instance [∀ i, Zero (β i)] : Norm (Hamming β) := ⟨fun x => hammingNorm (ofHamming x)⟩ @[simp, push_cast] theorem norm_eq_hammingNorm [∀ i, Zero (β i)] (x : Hamming β) : ‖x‖ = hammingNorm (ofHamming x) := rfl -- Porting note: merged `SeminormedAddCommGroup` and `NormedAddCommGroup` instances instance [∀ i, AddCommGroup (β i)] : NormedAddCommGroup (Hamming β) where dist_eq := by push_cast; exact mod_cast hammingDist_eq_hammingNorm @[simp, push_cast] theorem nnnorm_eq_hammingNorm [∀ i, AddCommGroup (β i)] (x : Hamming β) : ‖x‖₊ = hammingNorm (ofHamming x) := rfl end end Hamming
Init\Classical.lean
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad, Mario Carneiro -/ import Mathlib.Tactic.IrreducibleDef /-! # Note about `Mathlib/Init/` The files in `Mathlib/Init` are leftovers from the port from Mathlib3. (They contain content moved from lean3 itself that Mathlib needed but was not moved to lean4.) We intend to move all the content of these files out into the main `Mathlib` directory structure. Contributions assisting with this are appreciated. ### alignments from lean 3 `init.classical` -/ namespace Classical attribute [local instance] propDecidable attribute [local instance] decidableInhabited alias axiom_of_choice := axiomOfChoice -- TODO: fix in core alias prop_complete := propComplete -- TODO: fix in core @[elab_as_elim] theorem cases_true_false (p : Prop → Prop) (h1 : p True) (h2 : p False) (a : Prop) : p a := Or.elim (prop_complete a) (fun ht : a = True ↦ ht.symm ▸ h1) fun hf : a = False ↦ hf.symm ▸ h2 theorem cases_on (a : Prop) {p : Prop → Prop} (h1 : p True) (h2 : p False) : p a := @cases_true_false p h1 h2 a theorem cases {p : Prop → Prop} (h1 : p True) (h2 : p False) (a) : p a := cases_on a h1 h2 alias by_cases := byCases alias by_contradiction := byContradiction theorem eq_false_or_eq_true (a : Prop) : a = False ∨ a = True := (prop_complete a).symm end Classical
Init\Core.lean
/- Copyright (c) 2014 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Mario Carneiro -/ import Mathlib.Tactic.Relation.Trans /-! # Note about `Mathlib/Init/` The files in `Mathlib/Init` are leftovers from the port from Mathlib3. (They contain content moved from lean3 itself that Mathlib needed but was not moved to lean4.) We intend to move all the content of these files out into the main `Mathlib` directory structure. Contributions assisting with this are appreciated. # Notation, basic datatypes and type classes This file contains alignments from lean 3 `init.core`. -/ -- Note: we do not currently auto-align constants. -- TODO -- attribute [elab_as_elim, subst] Eq.subst attribute [trans] Eq.trans attribute [symm] Eq.symm universe u v w def Prod.mk.injArrow {α : Type u} {β : Type v} {x₁ : α} {y₁ : β} {x₂ : α} {y₂ : β} : (x₁, y₁) = (x₂, y₂) → ∀ ⦃P : Sort w⦄, (x₁ = x₂ → y₁ = y₂ → P) → P := fun h₁ _ h₂ ↦ Prod.noConfusion h₁ h₂ def PProd.mk.injArrow {α : Type u} {β : Type v} {x₁ : α} {y₁ : β} {x₂ : α} {y₂ : β} : (x₁, y₁) = (x₂, y₂) → ∀ ⦃P : Sort w⦄, (x₁ = x₂ → y₁ = y₂ → P) → P := fun h₁ _ h₂ ↦ Prod.noConfusion h₁ h₂ -- attribute [pp_using_anonymous_constructor] Sigma PSigma Subtype PProd And -- Generic 'has'-stripping -- Note: we don't currently strip automatically for various reasons. attribute [simp] insert_emptyc_eq -- Combinator calculus namespace Combinator variable {α : Sort u} {β : Sort v} {γ : Sort w} def I (a : α) := a def K (a : α) (_b : β) := a def S (x : α → β → γ) (y : α → β) (z : α) := x z (y z) end Combinator
Init\Logic.lean
/- Copyright (c) 2014 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad, Floris van Doorn -/ import Mathlib.Tactic.Lemma import Mathlib.Tactic.Relation.Trans import Mathlib.Tactic.ProjectionNotation import Batteries.Tactic.Alias import Batteries.Tactic.Lint.Misc /-! # Note about `Mathlib/Init/` The files in `Mathlib/Init` are leftovers from the port from Mathlib3. (They contain content moved from lean3 itself that Mathlib needed but was not moved to lean4.) We intend to move all the content of these files out into the main `Mathlib` directory structure. Contributions assisting with this are appreciated. -/ universe u v variable {α : Sort u} /- Eq -/ theorem not_of_eq_false {p : Prop} (h : p = False) : ¬p := fun hp ↦ h ▸ hp theorem cast_proof_irrel {β : Sort u} (h₁ h₂ : α = β) (a : α) : cast h₁ a = cast h₂ a := rfl attribute [symm] Eq.symm /- Ne -/ attribute [symm] Ne.symm /- HEq -/ alias eq_rec_heq := eqRec_heq -- FIXME This is still rejected after #857 -- attribute [refl] HEq.refl attribute [symm] HEq.symm attribute [trans] HEq.trans attribute [trans] heq_of_eq_of_heq theorem heq_of_eq_rec_left {φ : α → Sort v} {a a' : α} {p₁ : φ a} {p₂ : φ a'} : (e : a = a') → (h₂ : Eq.rec (motive := fun a _ ↦ φ a) p₁ e = p₂) → HEq p₁ p₂ | rfl, rfl => HEq.rfl theorem heq_of_eq_rec_right {φ : α → Sort v} {a a' : α} {p₁ : φ a} {p₂ : φ a'} : (e : a' = a) → (h₂ : p₁ = Eq.rec (motive := fun a _ ↦ φ a) p₂ e) → HEq p₁ p₂ | rfl, rfl => HEq.rfl theorem of_heq_true {a : Prop} (h : HEq a True) : a := of_eq_true (eq_of_heq h) theorem eq_rec_compose {α β φ : Sort u} : ∀ (p₁ : β = φ) (p₂ : α = β) (a : α), (Eq.recOn p₁ (Eq.recOn p₂ a : β) : φ) = Eq.recOn (Eq.trans p₂ p₁) a | rfl, rfl, _ => rfl theorem heq_prop {P Q : Prop} (p : P) (q : Q) : HEq p q := Subsingleton.helim (propext <| iff_of_true p q) _ _ /- and -/ variable {a b c d : Prop} /- or -/ /- xor -/ def Xor' (a b : Prop) := (a ∧ ¬ b) ∨ (b ∧ ¬ a) /- iff -/ attribute [refl] Iff.refl attribute [trans] Iff.trans attribute [symm] Iff.symm -- This is needed for `calc` to work with `iff`. instance : Trans Iff Iff Iff where trans := fun p q ↦ p.trans q alias ⟨not_of_not_not_not, _⟩ := not_not_not -- FIXME -- attribute [congr] not_congr variable (p) -- FIXME: remove _iff and add _eq for the lean 4 core versions theorem and_true_iff : p ∧ True ↔ p := iff_of_eq (and_true _) theorem true_and_iff : True ∧ p ↔ p := iff_of_eq (true_and _) theorem and_false_iff : p ∧ False ↔ False := iff_of_eq (and_false _) theorem false_and_iff : False ∧ p ↔ False := iff_of_eq (false_and _) theorem true_or_iff : True ∨ p ↔ True := iff_of_eq (true_or _) theorem or_true_iff : p ∨ True ↔ True := iff_of_eq (or_true _) theorem false_or_iff : False ∨ p ↔ p := iff_of_eq (false_or _) theorem or_false_iff : p ∨ False ↔ p := iff_of_eq (or_false _) theorem not_or_of_not : ¬a → ¬b → ¬(a ∨ b) := fun h1 h2 ↦ not_or.2 ⟨h1, h2⟩ theorem iff_true_iff : (a ↔ True) ↔ a := iff_of_eq (iff_true _) theorem true_iff_iff : (True ↔ a) ↔ a := iff_of_eq (true_iff _) theorem iff_false_iff : (a ↔ False) ↔ ¬a := iff_of_eq (iff_false _) theorem false_iff_iff : (False ↔ a) ↔ ¬a := iff_of_eq (false_iff _) theorem iff_self_iff (a : Prop) : (a ↔ a) ↔ True := iff_of_eq (iff_self _) -- TODO -- attribute [intro] Exists.intro /- exists unique -/ def ExistsUnique (p : α → Prop) := ∃ x, p x ∧ ∀ y, p y → y = x namespace Mathlib.Notation open Lean /-- Checks to see that `xs` has only one binder. -/ def isExplicitBinderSingular (xs : TSyntax ``explicitBinders) : Bool := match xs with | `(explicitBinders| $_:binderIdent $[: $_]?) => true | `(explicitBinders| ($_:binderIdent : $_)) => true | _ => false open TSyntax.Compat in /-- `∃! x : α, p x` means that there exists a unique `x` in `α` such that `p x`. This is notation for `ExistsUnique (fun (x : α) ↦ p x)`. This notation does not allow multiple binders like `∃! (x : α) (y : β), p x y` as a shorthand for `∃! (x : α), ∃! (y : β), p x y` since it is liable to be misunderstood. Often, the intended meaning is instead `∃! q : α × β, p q.1 q.2`. -/ macro "∃!" xs:explicitBinders ", " b:term : term => do if !isExplicitBinderSingular xs then Macro.throwErrorAt xs "\ The `ExistsUnique` notation should not be used with more than one binder.\n\ \n\ The reason for this is that `∃! (x : α), ∃! (y : β), p x y` has a completely different \ meaning from `∃! q : α × β, p q.1 q.2`. \ To prevent confusion, this notation requires that you be explicit \ and use one with the correct interpretation." expandExplicitBinders ``ExistsUnique xs b /-- Pretty-printing for `ExistsUnique`, following the same pattern as pretty printing for `Exists`. However, it does *not* merge binders. -/ @[app_unexpander ExistsUnique] def unexpandExistsUnique : Lean.PrettyPrinter.Unexpander | `($(_) fun $x:ident ↦ $b) => `(∃! $x:ident, $b) | `($(_) fun ($x:ident : $t) ↦ $b) => `(∃! $x:ident : $t, $b) | _ => throw () /-- `∃! x ∈ s, p x` means `∃! x, x ∈ s ∧ p x`, which is to say that there exists a unique `x ∈ s` such that `p x`. Similarly, notations such as `∃! x ≤ n, p n` are supported, using any relation defined using the `binder_predicate` command. -/ syntax "∃! " binderIdent binderPred ", " term : term macro_rules | `(∃! $x:ident $p:binderPred, $b) => `(∃! $x:ident, satisfies_binder_pred% $x $p ∧ $b) | `(∃! _ $p:binderPred, $b) => `(∃! x, satisfies_binder_pred% x $p ∧ $b) end Mathlib.Notation -- @[intro] -- TODO theorem ExistsUnique.intro {p : α → Prop} (w : α) (h₁ : p w) (h₂ : ∀ y, p y → y = w) : ∃! x, p x := ⟨w, h₁, h₂⟩ theorem ExistsUnique.elim {α : Sort u} {p : α → Prop} {b : Prop} (h₂ : ∃! x, p x) (h₁ : ∀ x, p x → (∀ y, p y → y = x) → b) : b := Exists.elim h₂ (fun w hw ↦ h₁ w (And.left hw) (And.right hw)) theorem exists_unique_of_exists_of_unique {α : Sort u} {p : α → Prop} (hex : ∃ x, p x) (hunique : ∀ y₁ y₂, p y₁ → p y₂ → y₁ = y₂) : ∃! x, p x := Exists.elim hex (fun x px ↦ ExistsUnique.intro x px (fun y (h : p y) ↦ hunique y x h px)) theorem ExistsUnique.exists {p : α → Prop} : (∃! x, p x) → ∃ x, p x | ⟨x, h, _⟩ => ⟨x, h⟩ theorem ExistsUnique.unique {α : Sort u} {p : α → Prop} (h : ∃! x, p x) {y₁ y₂ : α} (py₁ : p y₁) (py₂ : p y₂) : y₁ = y₂ := let ⟨_, _, hy⟩ := h; (hy _ py₁).trans (hy _ py₂).symm /- exists, forall, exists unique congruences -/ -- TODO -- attribute [congr] forall_congr' -- attribute [congr] exists_congr' -- @[congr] theorem existsUnique_congr {p q : α → Prop} (h : ∀ a, p a ↔ q a) : (∃! a, p a) ↔ ∃! a, q a := exists_congr fun _ ↦ and_congr (h _) <| forall_congr' fun _ ↦ imp_congr_left (h _) /- decidable -/ theorem decide_True' (h : Decidable True) : decide True = true := by simp theorem decide_False' (h : Decidable False) : decide False = false := by simp namespace Decidable def recOn_true [h : Decidable p] {h₁ : p → Sort u} {h₂ : ¬p → Sort u} (h₃ : p) (h₄ : h₁ h₃) : Decidable.recOn h h₂ h₁ := cast (by match h with | .isTrue _ => rfl) h₄ def recOn_false [h : Decidable p] {h₁ : p → Sort u} {h₂ : ¬p → Sort u} (h₃ : ¬p) (h₄ : h₂ h₃) : Decidable.recOn h h₂ h₁ := cast (by match h with | .isFalse _ => rfl) h₄ alias by_cases := byCases alias by_contradiction := byContradiction alias not_not_iff := not_not end Decidable alias Or.decidable := instDecidableOr alias And.decidable := instDecidableAnd alias Not.decidable := instDecidableNot alias Iff.decidable := instDecidableIff alias decidableTrue := instDecidableTrue alias decidableFalse := instDecidableFalse instance {q : Prop} [Decidable p] [Decidable q] : Decidable (Xor' p q) := inferInstanceAs (Decidable (Or ..)) def IsDecEq {α : Sort u} (p : α → α → Bool) : Prop := ∀ ⦃x y : α⦄, p x y = true → x = y def IsDecRefl {α : Sort u} (p : α → α → Bool) : Prop := ∀ x, p x x = true def decidableEq_of_bool_pred {α : Sort u} {p : α → α → Bool} (h₁ : IsDecEq p) (h₂ : IsDecRefl p) : DecidableEq α | x, y => if hp : p x y = true then isTrue (h₁ hp) else isFalse (fun hxy : x = y ↦ absurd (h₂ y) (by rwa [hxy] at hp)) theorem decidableEq_inl_refl {α : Sort u} [h : DecidableEq α] (a : α) : h a a = isTrue (Eq.refl a) := match h a a with | isTrue _ => rfl theorem decidableEq_inr_neg {α : Sort u} [h : DecidableEq α] {a b : α} (n : a ≠ b) : h a b = isFalse n := match h a b with | isFalse _ => rfl /- subsingleton -/ theorem rec_subsingleton {p : Prop} [h : Decidable p] {h₁ : p → Sort u} {h₂ : ¬p → Sort u} [h₃ : ∀ h : p, Subsingleton (h₁ h)] [h₄ : ∀ h : ¬p, Subsingleton (h₂ h)] : Subsingleton (Decidable.recOn h h₂ h₁) := match h with | isTrue h => h₃ h | isFalse h => h₄ h theorem imp_of_if_pos {c t e : Prop} [Decidable c] (h : ite c t e) (hc : c) : t := (if_pos hc ▸ h :) theorem imp_of_if_neg {c t e : Prop} [Decidable c] (h : ite c t e) (hnc : ¬c) : e := (if_neg hnc ▸ h :) theorem if_ctx_congr {α : Sort u} {b c : Prop} [dec_b : Decidable b] [dec_c : Decidable c] {x y u v : α} (h_c : b ↔ c) (h_t : c → x = u) (h_e : ¬c → y = v) : ite b x y = ite c u v := match dec_b, dec_c with | isFalse _, isFalse h₂ => h_e h₂ | isTrue _, isTrue h₂ => h_t h₂ | isFalse h₁, isTrue h₂ => absurd h₂ (Iff.mp (not_congr h_c) h₁) | isTrue h₁, isFalse h₂ => absurd h₁ (Iff.mpr (not_congr h_c) h₂) theorem if_congr {α : Sort u} {b c : Prop} [Decidable b] [Decidable c] {x y u v : α} (h_c : b ↔ c) (h_t : x = u) (h_e : y = v) : ite b x y = ite c u v := if_ctx_congr h_c (fun _ ↦ h_t) (fun _ ↦ h_e) theorem if_ctx_congr_prop {b c x y u v : Prop} [dec_b : Decidable b] [dec_c : Decidable c] (h_c : b ↔ c) (h_t : c → (x ↔ u)) (h_e : ¬c → (y ↔ v)) : ite b x y ↔ ite c u v := match dec_b, dec_c with | isFalse _, isFalse h₂ => h_e h₂ | isTrue _, isTrue h₂ => h_t h₂ | isFalse h₁, isTrue h₂ => absurd h₂ (Iff.mp (not_congr h_c) h₁) | isTrue h₁, isFalse h₂ => absurd h₁ (Iff.mpr (not_congr h_c) h₂) -- @[congr] theorem if_congr_prop {b c x y u v : Prop} [Decidable b] [Decidable c] (h_c : b ↔ c) (h_t : x ↔ u) (h_e : y ↔ v) : ite b x y ↔ ite c u v := if_ctx_congr_prop h_c (fun _ ↦ h_t) (fun _ ↦ h_e) theorem if_ctx_simp_congr_prop {b c x y u v : Prop} [Decidable b] (h_c : b ↔ c) (h_t : c → (x ↔ u)) -- FIXME: after https://github.com/leanprover/lean4/issues/1867 is fixed, -- this should be changed back to: -- (h_e : ¬c → (y ↔ v)) : ite b x y ↔ ite c (h := decidable_of_decidable_of_iff h_c) u v := (h_e : ¬c → (y ↔ v)) : ite b x y ↔ @ite _ c (decidable_of_decidable_of_iff h_c) u v := if_ctx_congr_prop (dec_c := decidable_of_decidable_of_iff h_c) h_c h_t h_e theorem if_simp_congr_prop {b c x y u v : Prop} [Decidable b] (h_c : b ↔ c) (h_t : x ↔ u) -- FIXME: after https://github.com/leanprover/lean4/issues/1867 is fixed, -- this should be changed back to: -- (h_e : y ↔ v) : ite b x y ↔ (ite c (h := decidable_of_decidable_of_iff h_c) u v) := (h_e : y ↔ v) : ite b x y ↔ (@ite _ c (decidable_of_decidable_of_iff h_c) u v) := if_ctx_simp_congr_prop h_c (fun _ ↦ h_t) (fun _ ↦ h_e) -- @[congr] theorem dif_ctx_congr {α : Sort u} {b c : Prop} [dec_b : Decidable b] [dec_c : Decidable c] {x : b → α} {u : c → α} {y : ¬b → α} {v : ¬c → α} (h_c : b ↔ c) (h_t : ∀ h : c, x (Iff.mpr h_c h) = u h) (h_e : ∀ h : ¬c, y (Iff.mpr (not_congr h_c) h) = v h) : @dite α b dec_b x y = @dite α c dec_c u v := match dec_b, dec_c with | isFalse _, isFalse h₂ => h_e h₂ | isTrue _, isTrue h₂ => h_t h₂ | isFalse h₁, isTrue h₂ => absurd h₂ (Iff.mp (not_congr h_c) h₁) | isTrue h₁, isFalse h₂ => absurd h₁ (Iff.mpr (not_congr h_c) h₂) theorem dif_ctx_simp_congr {α : Sort u} {b c : Prop} [Decidable b] {x : b → α} {u : c → α} {y : ¬b → α} {v : ¬c → α} (h_c : b ↔ c) (h_t : ∀ h : c, x (Iff.mpr h_c h) = u h) (h_e : ∀ h : ¬c, y (Iff.mpr (not_congr h_c) h) = v h) : -- FIXME: after https://github.com/leanprover/lean4/issues/1867 is fixed, -- this should be changed back to: -- dite b x y = dite c (h := decidable_of_decidable_of_iff h_c) u v := dite b x y = @dite _ c (decidable_of_decidable_of_iff h_c) u v := dif_ctx_congr (dec_c := decidable_of_decidable_of_iff h_c) h_c h_t h_e def AsTrue (c : Prop) [Decidable c] : Prop := if c then True else False def AsFalse (c : Prop) [Decidable c] : Prop := if c then False else True theorem AsTrue.get {c : Prop} [h₁ : Decidable c] (_ : AsTrue c) : c := match h₁ with | isTrue h_c => h_c /- Equalities for rewriting let-expressions -/ theorem let_value_eq {α : Sort u} {β : Sort v} {a₁ a₂ : α} (b : α → β) (h : a₁ = a₂) : (let x : α := a₁; b x) = (let x : α := a₂; b x) := congrArg b h theorem let_value_heq {α : Sort v} {β : α → Sort u} {a₁ a₂ : α} (b : ∀ x : α, β x) (h : a₁ = a₂) : HEq (let x : α := a₁; b x) (let x : α := a₂; b x) := by cases h; rfl theorem let_body_eq {α : Sort v} {β : α → Sort u} (a : α) {b₁ b₂ : ∀ x : α, β x} (h : ∀ x, b₁ x = b₂ x) : (let x : α := a; b₁ x) = (let x : α := a; b₂ x) := by exact h _ ▸ rfl theorem let_eq {α : Sort v} {β : Sort u} {a₁ a₂ : α} {b₁ b₂ : α → β} (h₁ : a₁ = a₂) (h₂ : ∀ x, b₁ x = b₂ x) : (let x : α := a₁; b₁ x) = (let x : α := a₂; b₂ x) := by simp [h₁, h₂] section Relation variable {α : Sort u} {β : Sort v} (r : β → β → Prop) /-- Local notation for an arbitrary binary relation `r`. -/ local infix:50 " ≺ " => r /-- A reflexive relation relates every element to itself. -/ def Reflexive := ∀ x, x ≺ x /-- A relation is symmetric if `x ≺ y` implies `y ≺ x`. -/ def Symmetric := ∀ ⦃x y⦄, x ≺ y → y ≺ x /-- A relation is transitive if `x ≺ y` and `y ≺ z` together imply `x ≺ z`. -/ def Transitive := ∀ ⦃x y z⦄, x ≺ y → y ≺ z → x ≺ z lemma Equivalence.reflexive {r : β → β → Prop} (h : Equivalence r) : Reflexive r := h.refl lemma Equivalence.symmetric {r : β → β → Prop} (h : Equivalence r) : Symmetric r := fun _ _ ↦ h.symm lemma Equivalence.transitive {r : β → β → Prop} (h : Equivalence r) : Transitive r := fun _ _ _ ↦ h.trans /-- A relation is total if for all `x` and `y`, either `x ≺ y` or `y ≺ x`. -/ def Total := ∀ x y, x ≺ y ∨ y ≺ x /-- Irreflexive means "not reflexive". -/ def Irreflexive := ∀ x, ¬ x ≺ x /-- A relation is antisymmetric if `x ≺ y` and `y ≺ x` together imply that `x = y`. -/ def AntiSymmetric := ∀ ⦃x y⦄, x ≺ y → y ≺ x → x = y /-- An empty relation does not relate any elements. -/ @[nolint unusedArguments] def EmptyRelation := fun _ _ : α ↦ False theorem InvImage.trans (f : α → β) (h : Transitive r) : Transitive (InvImage r f) := fun (a₁ a₂ a₃ : α) (h₁ : InvImage r f a₁ a₂) (h₂ : InvImage r f a₂ a₃) ↦ h h₁ h₂ theorem InvImage.irreflexive (f : α → β) (h : Irreflexive r) : Irreflexive (InvImage r f) := fun (a : α) (h₁ : InvImage r f a a) ↦ h (f a) h₁ end Relation section Binary variable {α : Type u} {β : Type v} (f : α → α → α) (inv : α → α) (one : α) /-- Local notation for `f`, high priority to avoid ambiguity with `HMul.hMul`. -/ local infix:70 (priority := high) " * " => f /-- Local notation for `inv`, high priority to avoid ambiguity with `Inv.inv`. -/ local postfix:100 (priority := high) "⁻¹" => inv variable (g : α → α → α) /-- Local notation for `g`, high priority to avoid ambiguity with `HAdd.hAdd`. -/ local infix:65 (priority := high) " + " => g def Commutative := ∀ a b, a * b = b * a def Associative := ∀ a b c, (a * b) * c = a * (b * c) def LeftIdentity := ∀ a, one * a = a def RightIdentity := ∀ a, a * one = a def RightInverse := ∀ a, a * a⁻¹ = one def LeftCancelative := ∀ a b c, a * b = a * c → b = c def RightCancelative := ∀ a b c, a * b = c * b → a = c def LeftDistributive := ∀ a b c, a * (b + c) = a * b + a * c def RightDistributive := ∀ a b c, (a + b) * c = a * c + b * c def RightCommutative (h : β → α → β) := ∀ b a₁ a₂, h (h b a₁) a₂ = h (h b a₂) a₁ def LeftCommutative (h : α → β → β) := ∀ a₁ a₂ b, h a₁ (h a₂ b) = h a₂ (h a₁ b) theorem left_comm : Commutative f → Associative f → LeftCommutative f := fun hcomm hassoc a b c ↦ calc a*(b*c) _ = (a*b)*c := Eq.symm (hassoc a b c) _ = (b*a)*c := hcomm a b ▸ rfl _ = b*(a*c) := hassoc b a c theorem right_comm : Commutative f → Associative f → RightCommutative f := fun hcomm hassoc a b c ↦ calc (a*b)*c _ = a*(b*c) := hassoc a b c _ = a*(c*b) := hcomm b c ▸ rfl _ = (a*c)*b := Eq.symm (hassoc a c b) end Binary
Init\Quot.lean
/- Copyright (c) 2023 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ /-! # Note about `Mathlib/Init/` The files in `Mathlib/Init` are leftovers from the port from Mathlib3. (They contain content moved from lean3 itself that Mathlib needed but was not moved to lean4.) We intend to move all the content of these files out into the main `Mathlib` directory structure. Contributions assisting with this are appreciated. # Quot Some induction principles tagged with `elab_as_elim`, since the attribute is missing in core. -/ universe u v variable {α : Sort u} {r : α → α → Prop} {motive : Quot r → Sort v} @[inherit_doc Quot.rec, elab_as_elim] -- Porting note: adding `elab_as_elim` protected abbrev Quot.recOn' (q : Quot r) (f : (a : α) → motive (Quot.mk r a)) (h : (a b : α) → (p : r a b) → Eq.ndrec (f a) (Quot.sound p) = f b) : motive q := q.rec f h -- expected token /-- Version of `Quot.recOnSubsingleton` tagged with `elab_as_elim` -/ @[elab_as_elim] -- Porting note: this attribute is missing in core protected abbrev Quot.recOnSubsingleton' [h : (a : α) → Subsingleton (motive (Quot.mk r a))] (q : Quot r) (f : (a : α) → motive (Quot.mk r a)) : motive q := by induction q using Quot.rec apply f apply Subsingleton.elim theorem Quotient.mk'_eq_mk [s : Setoid α] : Quotient.mk' = Quotient.mk s := rfl
Init\Set.lean
/- Copyright (c) 2016 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Lean.Parser.Term import Batteries.Util.ExtendedBinder /-! # Note about `Mathlib/Init/` The files in `Mathlib/Init` are leftovers from the port from Mathlib3. (They contain content moved from lean3 itself that Mathlib needed but was not moved to lean4.) We intend to move all the content of these files out into the main `Mathlib` directory structure. Contributions assisting with this are appreciated. # Sets This file sets up the theory of sets whose elements have a given type. ## Main definitions Given a type `X` and a predicate `p : X → Prop`: * `Set X` : the type of sets whose elements have type `X` * `{a : X | p a} : Set X` : the set of all elements of `X` satisfying `p` * `{a | p a} : Set X` : a more concise notation for `{a : X | p a}` * `{f x y | (x : X) (y : Y)} : Set Z` : a more concise notation for `{z : Z | ∃ x y, f x y = z}` * `{a ∈ S | p a} : Set X` : given `S : Set X`, the subset of `S` consisting of its elements satisfying `p`. ## Implementation issues As in Lean 3, `Set X := X → Prop` I didn't call this file Data.Set.Basic because it contains core Lean 3 stuff which happens before mathlib3's data.set.basic . This file is a port of the core Lean 3 file `lib/lean/library/init/data/set.lean`. -/ open Batteries.ExtendedBinder universe u variable {α : Type u} /-- A set is a collection of elements of some type `α`. Although `Set` is defined as `α → Prop`, this is an implementation detail which should not be relied on. Instead, `setOf` and membership of a set (`∈`) should be used to convert between sets and predicates. -/ def Set (α : Type u) := α → Prop /-- Turn a predicate `p : α → Prop` into a set, also written as `{x | p x}` -/ def setOf {α : Type u} (p : α → Prop) : Set α := p namespace Set /-- Membership in a set -/ protected def Mem (a : α) (s : Set α) : Prop := s a instance : Membership α (Set α) := ⟨Set.Mem⟩ theorem ext {a b : Set α} (h : ∀ (x : α), x ∈ a ↔ x ∈ b) : a = b := funext (fun x ↦ propext (h x)) /-- The subset relation on sets. `s ⊆ t` means that all elements of `s` are elements of `t`. Note that you should **not** use this definition directly, but instead write `s ⊆ t`. -/ protected def Subset (s₁ s₂ : Set α) := ∀ ⦃a⦄, a ∈ s₁ → a ∈ s₂ /-- Porting note: we introduce `≤` before `⊆` to help the unifier when applying lattice theorems to subset hypotheses. -/ instance : LE (Set α) := ⟨Set.Subset⟩ instance : HasSubset (Set α) := ⟨(· ≤ ·)⟩ instance : EmptyCollection (Set α) := ⟨fun _ ↦ False⟩ syntax "{" extBinder " | " term "}" : term macro_rules | `({ $x:ident | $p }) => `(setOf fun $x:ident ↦ $p) | `({ $x:ident : $t | $p }) => `(setOf fun $x:ident : $t ↦ $p) | `({ $x:ident $b:binderPred | $p }) => `(setOf fun $x:ident ↦ satisfies_binder_pred% $x $b ∧ $p) @[app_unexpander setOf] def setOf.unexpander : Lean.PrettyPrinter.Unexpander | `($_ fun $x:ident ↦ $p) => `({ $x:ident | $p }) | `($_ fun ($x:ident : $ty:term) ↦ $p) => `({ $x:ident : $ty:term | $p }) | _ => throw () open Batteries.ExtendedBinder in /-- `{ f x y | (x : X) (y : Y) }` is notation for the set of elements `f x y` constructed from the binders `x` and `y`, equivalent to `{z : Z | ∃ x y, f x y = z}`. If `f x y` is a single identifier, it must be parenthesized to avoid ambiguity with `{x | p x}`; for instance, `{(x) | (x : Nat) (y : Nat) (_hxy : x = y^2)}`. -/ macro (priority := low) "{" t:term " | " bs:extBinders "}" : term => `({x | ∃ᵉ $bs:extBinders, $t = x}) /-- * `{ pat : X | p }` is notation for pattern matching in set-builder notation, where `pat` is a pattern that is matched by all objects of type `X` and `p` is a proposition that can refer to variables in the pattern. It is the set of all objects of type `X` which, when matched with the pattern `pat`, make `p` come out true. * `{ pat | p }` is the same, but in the case when the type `X` can be inferred. For example, `{ (m, n) : ℕ × ℕ | m * n = 12 }` denotes the set of all ordered pairs of natural numbers whose product is 12. Note that if the type ascription is left out and `p` can be interpreted as an extended binder, then the extended binder interpretation will be used. For example, `{ n + 1 | n < 3 }` will be interpreted as `{ x : Nat | ∃ n < 3, n + 1 = x }` rather than using pattern matching. -/ macro (name := macroPattSetBuilder) (priority := low-1) "{" pat:term " : " t:term " | " p:term "}" : term => `({ x : $t | match x with | $pat => $p }) @[inherit_doc macroPattSetBuilder] macro (priority := low-1) "{" pat:term " | " p:term "}" : term => `({ x | match x with | $pat => $p }) /-- Pretty printing for set-builder notation with pattern matching. -/ @[app_unexpander setOf] def setOfPatternMatchUnexpander : Lean.PrettyPrinter.Unexpander | `($_ fun $x:ident ↦ match $y:ident with | $pat => $p) => if x == y then `({ $pat:term | $p:term }) else throw () | `($_ fun ($x:ident : $ty:term) ↦ match $y:ident with | $pat => $p) => if x == y then `({ $pat:term : $ty:term | $p:term }) else throw () | _ => throw () /-- The universal set on a type `α` is the set containing all elements of `α`. This is conceptually the "same as" `α` (in set theory, it is actually the same), but type theory makes the distinction that `α` is a type while `Set.univ` is a term of type `Set α`. `Set.univ` can itself be coerced to a type `↥Set.univ` which is in bijection with (but distinct from) `α`. -/ def univ : Set α := {_a | True} /-- `Set.insert a s` is the set `{a} ∪ s`. Note that you should **not** use this definition directly, but instead write `insert a s` (which is mediated by the `Insert` typeclass). -/ protected def insert (a : α) (s : Set α) : Set α := {b | b = a ∨ b ∈ s} instance : Insert α (Set α) := ⟨Set.insert⟩ /-- The singleton of an element `a` is the set with `a` as a single element. Note that you should **not** use this definition directly, but instead write `{a}`. -/ protected def singleton (a : α) : Set α := {b | b = a} instance instSingletonSet : Singleton α (Set α) := ⟨Set.singleton⟩ /-- The union of two sets `s` and `t` is the set of elements contained in either `s` or `t`. Note that you should **not** use this definition directly, but instead write `s ∪ t`. -/ protected def union (s₁ s₂ : Set α) : Set α := {a | a ∈ s₁ ∨ a ∈ s₂} instance : Union (Set α) := ⟨Set.union⟩ /-- The intersection of two sets `s` and `t` is the set of elements contained in both `s` and `t`. Note that you should **not** use this definition directly, but instead write `s ∩ t`. -/ protected def inter (s₁ s₂ : Set α) : Set α := {a | a ∈ s₁ ∧ a ∈ s₂} instance : Inter (Set α) := ⟨Set.inter⟩ /-- The complement of a set `s` is the set of elements not contained in `s`. Note that you should **not** use this definition directly, but instead write `sᶜ`. -/ protected def compl (s : Set α) : Set α := {a | a ∉ s} /-- The difference of two sets `s` and `t` is the set of elements contained in `s` but not in `t`. Note that you should **not** use this definition directly, but instead write `s \ t`. -/ protected def diff (s t : Set α) : Set α := {a ∈ s | a ∉ t} instance : SDiff (Set α) := ⟨Set.diff⟩ /-- `𝒫 s` is the set of all subsets of `s`. -/ def powerset (s : Set α) : Set (Set α) := {t | t ⊆ s} @[inherit_doc] prefix:100 "𝒫" => powerset universe v in /-- The image of `s : Set α` by `f : α → β`, written `f '' s`, is the set of `b : β` such that `f a = b` for some `a ∈ s`. -/ def image {β : Type v} (f : α → β) (s : Set α) : Set β := {f a | a ∈ s} instance : Functor Set where map := @Set.image instance : LawfulFunctor Set where id_map _ := funext fun _ ↦ propext ⟨fun ⟨_, sb, rfl⟩ ↦ sb, fun sb ↦ ⟨_, sb, rfl⟩⟩ comp_map g h _ := funext <| fun c ↦ propext ⟨fun ⟨a, ⟨h₁, h₂⟩⟩ ↦ ⟨g a, ⟨⟨a, ⟨h₁, rfl⟩⟩, h₂⟩⟩, fun ⟨_, ⟨⟨a, ⟨h₁, h₂⟩⟩, h₃⟩⟩ ↦ ⟨a, ⟨h₁, show h (g a) = c from h₂ ▸ h₃⟩⟩⟩ map_const := rfl /-- The property `s.Nonempty` expresses the fact that the set `s` is not empty. It should be used in theorem assumptions instead of `∃ x, x ∈ s` or `s ≠ ∅` as it gives access to a nice API thanks to the dot notation. -/ protected def Nonempty (s : Set α) : Prop := ∃ x, x ∈ s end Set
Init\Algebra\Classes.lean
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Mathlib.Init.Logic /-! # Note about `Mathlib/Init/` The files in `Mathlib/Init` are leftovers from the port from Mathlib3. (They contain content moved from lean3 itself that Mathlib needed but was not moved to lean4.) We intend to move all the content of these files out into the main `Mathlib` directory structure. Contributions assisting with this are appreciated. # Unbundled algebra classes These classes are part of an incomplete refactor described [here on the github Wiki](https://github.com/leanprover/lean/wiki/Refactoring-structures#encoding-the-algebraic-hierarchy-1). However a subset of them are widely used in mathlib3, and it has been tricky to clean this up as this file was in core Lean 3. By themselves, these classes are not good replacements for the `Monoid` / `Group` etc structures provided by mathlib, as they are not discoverable by `simp` unlike the current lemmas due to there being little to index on. The Wiki page linked above describes an algebraic normalizer, but it was never implemented in Lean 3. ## Porting note: This file is ancient, and it would be good to replace it with a clean version that provides what mathlib4 actually needs. I've omitted all the `@[algebra]` attributes, as they are not used elsewhere. The section `StrictWeakOrder` has been omitted, but I've left the mathport output in place. Please delete if cleaning up. I've commented out some classes which we think are completely unused in mathlib. I've added many of the declarations to `nolints.json`. If you clean up this file, please add documentation to classes that we are keeping. Mario made the following analysis of uses in mathlib3: * `is_symm_op`: unused except for some instances * `is_commutative`: used a fair amount via some theorems about folds (also assuming `is_associative`) * `is_associative`: ditto, also used in `noncomm_fold` * `is_left_id`, `is_right_id`: unused except in the mathlib class `is_unital` and in `mono` (which looks like it could use `is_unital`) * `is_left_null`, `is_right_null`: unused * `is_left_cancel`, `is_right_cancel`: unused except for instances * `is_idempotent`: this one is actually used to prove things not directly about `is_idempotent` * `is_left_distrib`, `is_right_distrib`, `is_left_inv`, `is_right_inv`, `is_cond_left_inv`, `is_cond_right_inv`: unused * `is_distinct`: unused (although we reinvented this one as `nontrivial`) * `is_irrefl`, `is_refl`, `is_symm`, `is_trans`: significant usage * `is_asymm`, `is_antisymm`, `is_total`, `is_strict_order`: a lot of uses but all in order theory and it's unclear how much could not be transferred to another typeclass * `is_preorder`: unused except for instances (except `antisymmetrization`, maybe it could be transferred) * `is_total_preorder`, `is_partial_order`: unused except for instances * `is_linear_order`: unused except for instances * `is_equiv`: unused except for instances (most uses can use `equivalence` instead) * `is_per`: unused * `is_incomp_trans`: unused * `is_strict_weak_order`: significant usage (most of it on `rbmap`, could be transferred) * `is_trichotomous`: some usage * `is_strict_total_order`: looks like the only usage is in `rbmap` again -/ universe u v -- Porting note: removed `outParam` class IsSymmOp (α : Sort u) (β : Sort v) (op : α → α → β) : Prop where symm_op : ∀ a b, op a b = op b a /-- A commutative binary operation. -/ @[deprecated Std.Commutative (since := "2024-02-02")] abbrev IsCommutative (α : Sort u) (op : α → α → α) := Std.Commutative op instance (priority := 100) isSymmOp_of_isCommutative (α : Sort u) (op : α → α → α) [Std.Commutative op] : IsSymmOp α α op where symm_op := Std.Commutative.comm /-- An associative binary operation. -/ @[deprecated Std.Associative (since := "2024-02-02")] abbrev IsAssociative (α : Sort u) (op : α → α → α) := Std.Associative op /-- A binary operation with a left identity. -/ @[deprecated Std.LawfulLeftIdentity (since := "2024-02-02")] abbrev IsLeftId (α : Sort u) (op : α → α → α) (o : outParam α) := Std.LawfulLeftIdentity op o /-- A binary operation with a right identity. -/ @[deprecated Std.LawfulRightIdentity (since := "2024-02-02")] abbrev IsRightId (α : Sort u) (op : α → α → α) (o : outParam α) := Std.LawfulRightIdentity op o -- class IsLeftNull (α : Sort u) (op : α → α → α) (o : outParam α) : Prop where -- left_null : ∀ a, op o a = o -- class IsRightNull (α : Sort u) (op : α → α → α) (o : outParam α) : Prop where -- right_null : ∀ a, op a o = o class IsLeftCancel (α : Sort u) (op : α → α → α) : Prop where left_cancel : ∀ a b c, op a b = op a c → b = c class IsRightCancel (α : Sort u) (op : α → α → α) : Prop where right_cancel : ∀ a b c, op a b = op c b → a = c @[deprecated Std.IdempotentOp (since := "2024-02-02")] abbrev IsIdempotent (α : Sort u) (op : α → α → α) := Std.IdempotentOp op -- class IsLeftDistrib (α : Sort u) (op₁ : α → α → α) (op₂ : outParam <| α → α → α) : Prop where -- left_distrib : ∀ a b c, op₁ a (op₂ b c) = op₂ (op₁ a b) (op₁ a c) -- class IsRightDistrib (α : Sort u) (op₁ : α → α → α) (op₂ : outParam <| α → α → α) : Prop where -- right_distrib : ∀ a b c, op₁ (op₂ a b) c = op₂ (op₁ a c) (op₁ b c) -- class IsLeftInv (α : Sort u) (op : α → α → α) (inv : outParam <| α → α) (o : outParam α) : -- Prop where -- left_inv : ∀ a, op (inv a) a = o -- class IsRightInv (α : Sort u) (op : α → α → α) (inv : outParam <| α → α) (o : outParam α) : -- Prop where -- right_inv : ∀ a, op a (inv a) = o -- class IsCondLeftInv (α : Sort u) (op : α → α → α) (inv : outParam <| α → α) (o : outParam α) -- (p : outParam <| α → Prop) : Prop where -- left_inv : ∀ a, p a → op (inv a) a = o -- class IsCondRightInv (α : Sort u) (op : α → α → α) (inv : outParam <| α → α) (o : outParam α) -- (p : outParam <| α → Prop) : Prop where -- right_inv : ∀ a, p a → op a (inv a) = o -- class IsDistinct (α : Sort u) (a : α) (b : α) : Prop where -- distinct : a ≠ b /- -- The following type class doesn't seem very useful, a regular simp lemma should work for this. class is_inv (α : Sort u) (β : Sort v) (f : α → β) (g : out β → α) : Prop := (inv : ∀ a, g (f a) = a) -- The following one can also be handled using a regular simp lemma class is_idempotent (α : Sort u) (f : α → α) : Prop := (idempotent : ∀ a, f (f a) = f a) -/ /-- `IsIrrefl X r` means the binary relation `r` on `X` is irreflexive (that is, `r x x` never holds). -/ class IsIrrefl (α : Sort u) (r : α → α → Prop) : Prop where irrefl : ∀ a, ¬r a a /-- `IsRefl X r` means the binary relation `r` on `X` is reflexive. -/ class IsRefl (α : Sort u) (r : α → α → Prop) : Prop where refl : ∀ a, r a a /-- `IsSymm X r` means the binary relation `r` on `X` is symmetric. -/ class IsSymm (α : Sort u) (r : α → α → Prop) : Prop where symm : ∀ a b, r a b → r b a /-- The opposite of a symmetric relation is symmetric. -/ instance (priority := 100) isSymmOp_of_isSymm (α : Sort u) (r : α → α → Prop) [IsSymm α r] : IsSymmOp α Prop r where symm_op a b := propext <| Iff.intro (IsSymm.symm a b) (IsSymm.symm b a) /-- `IsAsymm X r` means that the binary relation `r` on `X` is asymmetric, that is, `r a b → ¬ r b a`. -/ class IsAsymm (α : Sort u) (r : α → α → Prop) : Prop where asymm : ∀ a b, r a b → ¬r b a /-- `IsAntisymm X r` means the binary relation `r` on `X` is antisymmetric. -/ class IsAntisymm (α : Sort u) (r : α → α → Prop) : Prop where antisymm : ∀ a b, r a b → r b a → a = b instance (priority := 100) IsAsymm.toIsAntisymm {α : Sort u} (r : α → α → Prop) [IsAsymm α r] : IsAntisymm α r where antisymm _ _ hx hy := (IsAsymm.asymm _ _ hx hy).elim /-- `IsTrans X r` means the binary relation `r` on `X` is transitive. -/ class IsTrans (α : Sort u) (r : α → α → Prop) : Prop where trans : ∀ a b c, r a b → r b c → r a c instance {α : Sort u} {r : α → α → Prop} [IsTrans α r] : Trans r r r := ⟨IsTrans.trans _ _ _⟩ instance (priority := 100) {α : Sort u} {r : α → α → Prop} [Trans r r r] : IsTrans α r := ⟨fun _ _ _ => Trans.trans⟩ /-- `IsTotal X r` means that the binary relation `r` on `X` is total, that is, that for any `x y : X` we have `r x y` or `r y x`. -/ class IsTotal (α : Sort u) (r : α → α → Prop) : Prop where total : ∀ a b, r a b ∨ r b a /-- `IsPreorder X r` means that the binary relation `r` on `X` is a pre-order, that is, reflexive and transitive. -/ class IsPreorder (α : Sort u) (r : α → α → Prop) extends IsRefl α r, IsTrans α r : Prop /-- `IsTotalPreorder X r` means that the binary relation `r` on `X` is total and a preorder. -/ class IsTotalPreorder (α : Sort u) (r : α → α → Prop) extends IsTrans α r, IsTotal α r : Prop /-- Every total pre-order is a pre-order. -/ instance (priority := 100) isTotalPreorder_isPreorder (α : Sort u) (r : α → α → Prop) [s : IsTotalPreorder α r] : IsPreorder α r where trans := s.trans refl a := Or.elim (@IsTotal.total _ r _ a a) id id /-- `IsPartialOrder X r` means that the binary relation `r` on `X` is a partial order, that is, `IsPreorder X r` and `IsAntisymm X r`. -/ class IsPartialOrder (α : Sort u) (r : α → α → Prop) extends IsPreorder α r, IsAntisymm α r : Prop /-- `IsLinearOrder X r` means that the binary relation `r` on `X` is a linear order, that is, `IsPartialOrder X r` and `IsTotal X r`. -/ class IsLinearOrder (α : Sort u) (r : α → α → Prop) extends IsPartialOrder α r, IsTotal α r : Prop /-- `IsEquiv X r` means that the binary relation `r` on `X` is an equivalence relation, that is, `IsPreorder X r` and `IsSymm X r`. -/ class IsEquiv (α : Sort u) (r : α → α → Prop) extends IsPreorder α r, IsSymm α r : Prop -- /-- `IsPer X r` means that the binary relation `r` on `X` is a partial equivalence relation, that -- is, `IsSymm X r` and `IsTrans X r`. -/ -- class IsPer (α : Sort u) (r : α → α → Prop) extends IsSymm α r, IsTrans α r : Prop /-- `IsStrictOrder X r` means that the binary relation `r` on `X` is a strict order, that is, `IsIrrefl X r` and `IsTrans X r`. -/ class IsStrictOrder (α : Sort u) (r : α → α → Prop) extends IsIrrefl α r, IsTrans α r : Prop /-- `IsIncompTrans X lt` means that for `lt` a binary relation on `X`, the incomparable relation `fun a b => ¬ lt a b ∧ ¬ lt b a` is transitive. -/ class IsIncompTrans (α : Sort u) (lt : α → α → Prop) : Prop where incomp_trans : ∀ a b c, ¬lt a b ∧ ¬lt b a → ¬lt b c ∧ ¬lt c b → ¬lt a c ∧ ¬lt c a /-- `IsStrictWeakOrder X lt` means that the binary relation `lt` on `X` is a strict weak order, that is, `IsStrictOrder X lt` and `IsIncompTrans X lt`. -/ class IsStrictWeakOrder (α : Sort u) (lt : α → α → Prop) extends IsStrictOrder α lt, IsIncompTrans α lt : Prop /-- `IsTrichotomous X lt` means that the binary relation `lt` on `X` is trichotomous, that is, either `lt a b` or `a = b` or `lt b a` for any `a` and `b`. -/ class IsTrichotomous (α : Sort u) (lt : α → α → Prop) : Prop where trichotomous : ∀ a b, lt a b ∨ a = b ∨ lt b a /-- `IsStrictTotalOrder X lt` means that the binary relation `lt` on `X` is a strict total order, that is, `IsTrichotomous X lt` and `IsStrictOrder X lt`. -/ class IsStrictTotalOrder (α : Sort u) (lt : α → α → Prop) extends IsTrichotomous α lt, IsStrictOrder α lt : Prop /-- Equality is an equivalence relation. -/ instance eq_isEquiv (α : Sort u) : IsEquiv α (· = ·) where symm := @Eq.symm _ trans := @Eq.trans _ refl := Eq.refl section variable {α : Sort u} {r : α → α → Prop} local infixl:50 " ≺ " => r theorem irrefl [IsIrrefl α r] (a : α) : ¬a ≺ a := IsIrrefl.irrefl a theorem refl [IsRefl α r] (a : α) : a ≺ a := IsRefl.refl a theorem trans [IsTrans α r] {a b c : α} : a ≺ b → b ≺ c → a ≺ c := IsTrans.trans _ _ _ theorem symm [IsSymm α r] {a b : α} : a ≺ b → b ≺ a := IsSymm.symm _ _ theorem antisymm [IsAntisymm α r] {a b : α} : a ≺ b → b ≺ a → a = b := IsAntisymm.antisymm _ _ theorem asymm [IsAsymm α r] {a b : α} : a ≺ b → ¬b ≺ a := IsAsymm.asymm _ _ theorem trichotomous [IsTrichotomous α r] : ∀ a b : α, a ≺ b ∨ a = b ∨ b ≺ a := IsTrichotomous.trichotomous theorem incomp_trans [IsIncompTrans α r] {a b c : α} : ¬a ≺ b ∧ ¬b ≺ a → ¬b ≺ c ∧ ¬c ≺ b → ¬a ≺ c ∧ ¬c ≺ a := IsIncompTrans.incomp_trans _ _ _ instance (priority := 90) isAsymm_of_isTrans_of_isIrrefl [IsTrans α r] [IsIrrefl α r] : IsAsymm α r := ⟨fun a _b h₁ h₂ => absurd (_root_.trans h₁ h₂) (irrefl a)⟩ section ExplicitRelationVariants variable (r) @[elab_without_expected_type] theorem irrefl_of [IsIrrefl α r] (a : α) : ¬a ≺ a := irrefl a @[elab_without_expected_type] theorem refl_of [IsRefl α r] (a : α) : a ≺ a := refl a @[elab_without_expected_type] theorem trans_of [IsTrans α r] {a b c : α} : a ≺ b → b ≺ c → a ≺ c := _root_.trans @[elab_without_expected_type] theorem symm_of [IsSymm α r] {a b : α} : a ≺ b → b ≺ a := symm @[elab_without_expected_type] theorem asymm_of [IsAsymm α r] {a b : α} : a ≺ b → ¬b ≺ a := asymm @[elab_without_expected_type] theorem total_of [IsTotal α r] (a b : α) : a ≺ b ∨ b ≺ a := IsTotal.total _ _ @[elab_without_expected_type] theorem trichotomous_of [IsTrichotomous α r] : ∀ a b : α, a ≺ b ∨ a = b ∨ b ≺ a := trichotomous @[elab_without_expected_type] theorem incomp_trans_of [IsIncompTrans α r] {a b c : α} : ¬a ≺ b ∧ ¬b ≺ a → ¬b ≺ c ∧ ¬c ≺ b → ¬a ≺ c ∧ ¬c ≺ a := incomp_trans end ExplicitRelationVariants end namespace StrictWeakOrder section variable {α : Sort u} {r : α → α → Prop} local infixl:50 " ≺ " => r def Equiv (a b : α) : Prop := ¬a ≺ b ∧ ¬b ≺ a local infixl:50 " ≈ " => @Equiv _ r theorem esymm {a b : α} : a ≈ b → b ≈ a := fun ⟨h₁, h₂⟩ => ⟨h₂, h₁⟩ theorem not_lt_of_equiv {a b : α} : a ≈ b → ¬a ≺ b := fun h => h.1 theorem not_lt_of_equiv' {a b : α} : a ≈ b → ¬b ≺ a := fun h => h.2 variable [IsStrictWeakOrder α r] theorem erefl (a : α) : a ≈ a := ⟨irrefl a, irrefl a⟩ theorem etrans {a b c : α} : a ≈ b → b ≈ c → a ≈ c := incomp_trans instance isEquiv : IsEquiv α (@Equiv _ r) where refl := erefl trans _ _ _ := etrans symm _ _ := esymm end /-- The equivalence relation induced by `lt` -/ notation:50 a " ≈[" lt "]" b:50 => @Equiv _ lt a b--Equiv (r := lt) a b end StrictWeakOrder theorem isStrictWeakOrder_of_isTotalPreorder {α : Sort u} {le : α → α → Prop} {lt : α → α → Prop} [DecidableRel le] [IsTotalPreorder α le] (h : ∀ a b, lt a b ↔ ¬le b a) : IsStrictWeakOrder α lt := { trans := fun a b c hab hbc => have nba : ¬le b a := Iff.mp (h _ _) hab have ncb : ¬le c b := Iff.mp (h _ _) hbc have hab : le a b := Or.resolve_left (total_of le b a) nba have nca : ¬le c a := fun hca : le c a => have hcb : le c b := trans_of le hca hab absurd hcb ncb Iff.mpr (h _ _) nca irrefl := fun a hlt => absurd (refl_of le a) (Iff.mp (h _ _) hlt) incomp_trans := fun a b c ⟨nab, nba⟩ ⟨nbc, ncb⟩ => have hba : le b a := Decidable.of_not_not (Iff.mp (not_congr (h _ _)) nab) have hab : le a b := Decidable.of_not_not (Iff.mp (not_congr (h _ _)) nba) have hcb : le c b := Decidable.of_not_not (Iff.mp (not_congr (h _ _)) nbc) have hbc : le b c := Decidable.of_not_not (Iff.mp (not_congr (h _ _)) ncb) have hac : le a c := trans_of le hab hbc have hca : le c a := trans_of le hcb hba And.intro (fun n => absurd hca (Iff.mp (h _ _) n)) fun n => absurd hac (Iff.mp (h _ _) n) } theorem lt_of_lt_of_incomp {α : Sort u} {lt : α → α → Prop} [IsStrictWeakOrder α lt] [DecidableRel lt] : ∀ {a b c}, lt a b → ¬lt b c ∧ ¬lt c b → lt a c := @fun a b c hab ⟨nbc, ncb⟩ => have nca : ¬lt c a := fun hca => absurd (trans_of lt hca hab) ncb Decidable.by_contradiction fun nac : ¬lt a c => have : ¬lt a b ∧ ¬lt b a := incomp_trans_of lt ⟨nac, nca⟩ ⟨ncb, nbc⟩ absurd hab this.1 theorem lt_of_incomp_of_lt {α : Sort u} {lt : α → α → Prop} [IsStrictWeakOrder α lt] [DecidableRel lt] : ∀ {a b c}, ¬lt a b ∧ ¬lt b a → lt b c → lt a c := @fun a b c ⟨nab, nba⟩ hbc => have nca : ¬lt c a := fun hca => absurd (trans_of lt hbc hca) nba Decidable.by_contradiction fun nac : ¬lt a c => have : ¬lt b c ∧ ¬lt c b := incomp_trans_of lt ⟨nba, nab⟩ ⟨nac, nca⟩ absurd hbc this.1 theorem eq_of_incomp {α : Sort u} {lt : α → α → Prop} [IsTrichotomous α lt] {a b} : ¬lt a b ∧ ¬lt b a → a = b := fun ⟨nab, nba⟩ => match trichotomous_of lt a b with | Or.inl hab => absurd hab nab | Or.inr (Or.inl hab) => hab | Or.inr (Or.inr hba) => absurd hba nba theorem eq_of_eqv_lt {α : Sort u} {lt : α → α → Prop} [IsTrichotomous α lt] {a b} : a ≈[lt]b → a = b := eq_of_incomp theorem incomp_iff_eq {α : Sort u} {lt : α → α → Prop} [IsTrichotomous α lt] [IsIrrefl α lt] (a b) : ¬lt a b ∧ ¬lt b a ↔ a = b := Iff.intro eq_of_incomp fun hab => hab ▸ And.intro (irrefl_of lt a) (irrefl_of lt a) theorem eqv_lt_iff_eq {α : Sort u} {lt : α → α → Prop} [IsTrichotomous α lt] [IsIrrefl α lt] (a b) : a ≈[lt]b ↔ a = b := incomp_iff_eq a b theorem not_lt_of_lt {α : Sort u} {lt : α → α → Prop} [IsStrictOrder α lt] {a b} : lt a b → ¬lt b a := fun h₁ h₂ => absurd (trans_of lt h₁ h₂) (irrefl_of lt _)
Init\Data\Quot.lean
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ /-! # Note about `Mathlib/Init/` The files in `Mathlib/Init` are leftovers from the port from Mathlib3. (They contain content moved from lean3 itself that Mathlib needed but was not moved to lean4.) We intend to move all the content of these files out into the main `Mathlib` directory structure. Contributions assisting with this are appreciated. # Quotient types These are ported from the Lean 3 standard library file `init/data/quot.lean`. -/ universe u section variable {α : Type u} variable (r : α → α → Prop) /-- `EqvGen r` is the equivalence relation generated by `r`. -/ inductive EqvGen : α → α → Prop | rel : ∀ x y, r x y → EqvGen x y | refl : ∀ x, EqvGen x x | symm : ∀ x y, EqvGen x y → EqvGen y x | trans : ∀ x y z, EqvGen x y → EqvGen y z → EqvGen x z theorem EqvGen.is_equivalence : Equivalence (@EqvGen α r) := Equivalence.mk EqvGen.refl (EqvGen.symm _ _) (EqvGen.trans _ _ _) /-- `EqvGen.Setoid r` is the setoid generated by a relation `r`. The motivation for this definition is that `Quot r` behaves like `Quotient (EqvGen.Setoid r)`, see for example `Quot.exact` and `Quot.EqvGen_sound`. -/ def EqvGen.Setoid : Setoid α := Setoid.mk _ (EqvGen.is_equivalence r) theorem Quot.exact {a b : α} (H : Quot.mk r a = Quot.mk r b) : EqvGen r a b := @Quotient.exact _ (EqvGen.Setoid r) a b (congrArg (Quot.lift (Quotient.mk (EqvGen.Setoid r)) (fun x y h ↦ Quot.sound (EqvGen.rel x y h))) H) theorem Quot.EqvGen_sound {r : α → α → Prop} {a b : α} (H : EqvGen r a b) : Quot.mk r a = Quot.mk r b := EqvGen.rec (fun _ _ h ↦ Quot.sound h) (fun _ ↦ rfl) (fun _ _ _ IH ↦ Eq.symm IH) (fun _ _ _ _ _ IH₁ IH₂ ↦ Eq.trans IH₁ IH₂) H end open Decidable instance Quotient.decidableEq {α : Sort u} {s : Setoid α} [d : ∀ a b : α, Decidable (a ≈ b)] : DecidableEq (Quotient s) := fun q₁ q₂ : Quotient s ↦ Quotient.recOnSubsingleton₂ q₁ q₂ (fun a₁ a₂ ↦ match (d a₁ a₂) with | (isTrue h₁) => isTrue (Quotient.sound h₁) | (isFalse h₂) => isFalse (fun h ↦ absurd (Quotient.exact h) h₂))
Init\Data\Fin\Basic.lean
/- Copyright (c) 2016 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Mathlib.Data.Nat.Notation /-! # Note about `Mathlib/Init/` The files in `Mathlib/Init` are leftovers from the port from Mathlib3. (They contain content moved from lean3 itself that Mathlib needed but was not moved to lean4.) We intend to move all the content of these files out into the main `Mathlib` directory structure. Contributions assisting with this are appreciated. # Theorems about equality in `Fin`. -/ namespace Fin variable {n : ℕ} {i j : Fin n} @[deprecated eq_of_val_eq (since := "2024-02-15")] theorem eq_of_veq : i.val = j.val → i = j := eq_of_val_eq @[deprecated val_eq_of_eq (since := "2024-02-15")] theorem veq_of_eq : i = j → i.val = j.val := val_eq_of_eq -- These two aren't deprecated because `ne_of_val_ne` and `val_ne_of_ne` -- use `¬a = b` instead of `a ≠ b`. TODO: fix or rename in Lean core. theorem ne_of_vne (h : i.val ≠ j.val) : i ≠ j := ne_of_val_ne h theorem vne_of_ne (h : i ≠ j) : i.val ≠ j.val := val_ne_of_ne h end Fin
Init\Data\Int\Order.lean
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad -/ import Mathlib.Data.Int.Notation import Mathlib.Data.Nat.Notation import Mathlib.Order.Defs /-! # Note about `Mathlib/Init/` The files in `Mathlib/Init` are leftovers from the port from Mathlib3. (They contain content moved from lean3 itself that Mathlib needed but was not moved to lean4.) We intend to move all the content of these files out into the main `Mathlib` directory structure. Contributions assisting with this are appreciated. # The order relation on the integers -/ open Nat namespace Int export private decNonneg from Init.Data.Int.Basic theorem le.elim {a b : ℤ} (h : a ≤ b) {P : Prop} (h' : ∀ n : ℕ, a + ↑n = b → P) : P := Exists.elim (le.dest h) h' alias ⟨le_of_ofNat_le_ofNat, ofNat_le_ofNat_of_le⟩ := ofNat_le theorem lt.elim {a b : ℤ} (h : a < b) {P : Prop} (h' : ∀ n : ℕ, a + ↑(Nat.succ n) = b → P) : P := Exists.elim (lt.dest h) h' alias ⟨lt_of_ofNat_lt_ofNat, ofNat_lt_ofNat_of_lt⟩ := ofNat_lt instance instLinearOrder : LinearOrder ℤ where le := (·≤·) le_refl := Int.le_refl le_trans := @Int.le_trans le_antisymm := @Int.le_antisymm lt := (·<·) lt_iff_le_not_le := @Int.lt_iff_le_not_le le_total := Int.le_total decidableEq := by infer_instance decidableLE := by infer_instance decidableLT := by infer_instance theorem neg_mul_eq_neg_mul_symm (a b : ℤ) : -a * b = -(a * b) := (Int.neg_mul_eq_neg_mul a b).symm theorem mul_neg_eq_neg_mul_symm (a b : ℤ) : a * -b = -(a * b) := (Int.neg_mul_eq_mul_neg a b).symm protected theorem eq_zero_or_eq_zero_of_mul_eq_zero {a b : ℤ} (h : a * b = 0) : a = 0 ∨ b = 0 := match lt_trichotomy 0 a with | Or.inl hlt₁ => match lt_trichotomy 0 b with | Or.inl hlt₂ => by have : 0 < a * b := Int.mul_pos hlt₁ hlt₂ rw [h] at this exact absurd this (lt_irrefl _) | Or.inr (Or.inl heq₂) => Or.inr heq₂.symm | Or.inr (Or.inr hgt₂) => by have : 0 > a * b := Int.mul_neg_of_pos_of_neg hlt₁ hgt₂ rw [h] at this exact absurd this (lt_irrefl _) | Or.inr (Or.inl heq₁) => Or.inl heq₁.symm | Or.inr (Or.inr hgt₁) => match lt_trichotomy 0 b with | Or.inl hlt₂ => by have : 0 > a * b := Int.mul_neg_of_neg_of_pos hgt₁ hlt₂ rw [h] at this exact absurd this (lt_irrefl _) | Or.inr (Or.inl heq₂) => Or.inr heq₂.symm | Or.inr (Or.inr hgt₂) => by have : 0 < a * b := Int.mul_pos_of_neg_of_neg hgt₁ hgt₂ rw [h] at this exact absurd this (lt_irrefl _)
Init\Data\List\Basic.lean
/- Copyright (c) 2016 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Mathlib.Data.Nat.Notation import Batteries.Data.List.Basic /-! # Note about `Mathlib/Init/` The files in `Mathlib/Init` are leftovers from the port from Mathlib3. (They contain content moved from lean3 itself that Mathlib needed but was not moved to lean4.) We intend to move all the content of these files out into the main `Mathlib` directory structure. Contributions assisting with this are appreciated. ## Definitions for `List` not (yet) in `Batteries` -/ open Decidable List universe u v w variable {α : Type u} namespace List /-- The head of a list, or the default element of the type is the list is `nil`. -/ def headI [Inhabited α] : List α → α | [] => default | (a :: _) => a @[simp] theorem headI_nil [Inhabited α] : ([] : List α).headI = default := rfl @[simp] theorem headI_cons [Inhabited α] {h : α} {t : List α} : (h :: t).headI = h := rfl /-- The last element of a list, with the default if list empty -/ def getLastI [Inhabited α] : List α → α | [] => default | [a] => a | [_, b] => b | _ :: _ :: l => getLastI l /-- List with a single given element. -/ @[inline, deprecated List.pure (since := "2024-03-24")] protected def ret {α : Type u} (a : α) : List α := [a] /-- `≤` implies not `>` for lists. -/ theorem le_eq_not_gt [LT α] : ∀ l₁ l₂ : List α, (l₁ ≤ l₂) = ¬l₂ < l₁ := fun _ _ => rfl @[deprecated (since := "2024-06-07")] alias toArray_data := Array.data_toArray end List
Init\Data\List\Instances.lean
/- Copyright (c) 2016 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ /-! # Note about `Mathlib/Init/` The files in `Mathlib/Init` are leftovers from the port from Mathlib3. (They contain content moved from lean3 itself that Mathlib needed but was not moved to lean4.) We intend to move all the content of these files out into the main `Mathlib` directory structure. Contributions assisting with this are appreciated. # Decidable and Monad instances for `List` not (yet) in `Batteries` -/ universe u v w namespace List variable {α : Type u} {β : Type v} {γ : Type w} instance instMonad : Monad List.{u} where pure := @List.pure bind := @List.bind map := @List.map @[simp] theorem pure_def (a : α) : pure a = [a] := rfl instance instLawfulMonad : LawfulMonad List.{u} := LawfulMonad.mk' (id_map := map_id) (pure_bind := fun _ _ => List.append_nil _) (bind_assoc := List.bind_assoc) (bind_pure_comp := fun _ _ => (map_eq_bind _ _).symm) instance instAlternative : Alternative List.{u} where failure := @List.nil orElse l l' := List.append l (l' ()) end List
Init\Data\List\Lemmas.lean
/- Copyright (c) 2014 Parikshit Khanna. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn -/ import Batteries.Data.List.Lemmas import Mathlib.Tactic.Cases /-! # Note about `Mathlib/Init/` The files in `Mathlib/Init` are leftovers from the port from Mathlib3. (They contain content moved from lean3 itself that Mathlib needed but was not moved to lean4.) We intend to move all the content of these files out into the main `Mathlib` directory structure. Contributions assisting with this are appreciated. # Lemmas for `List` not (yet) in `Batteries` -/ universe u v w w₁ w₂ variable {α : Type u} {β : Type v} {γ : Type w} namespace List open Nat /-! append -/ /-! length -/ /-! map -/ /-! bind -/ /-! mem -/ theorem mem_cons_eq (a y : α) (l : List α) : (a ∈ y :: l) = (a = y ∨ a ∈ l) := propext List.mem_cons alias ⟨eq_or_mem_of_mem_cons, _⟩ := mem_cons theorem not_exists_mem_nil (p : α → Prop) : ¬∃ x ∈ @nil α, p x := fun ⟨_, hx, _⟩ => List.not_mem_nil _ hx @[deprecated (since := "2024-03-23")] alias not_bex_nil := not_exists_mem_nil @[deprecated (since := "2024-03-23")] alias bex_cons := exists_mem_cons /-! list subset -/ -- This is relying on an automatically generated instance name from Batteries. /-! sublists -/ alias length_le_of_sublist := Sublist.length_le /-! filter -/ /-! map_accumr -/ section MapAccumr variable {φ : Type w₁} {σ : Type w₂} /-- Runs a function over a list returning the intermediate results and a final result. -/ def mapAccumr (f : α → σ → σ × β) : List α → σ → σ × List β | [], c => (c, []) | y :: yr, c => let r := mapAccumr f yr c let z := f y r.1 (z.1, z.2 :: r.2) /-- Length of the list obtained by `mapAccumr`. -/ @[simp] theorem length_mapAccumr : ∀ (f : α → σ → σ × β) (x : List α) (s : σ), length (mapAccumr f x s).2 = length x | f, _ :: x, s => congr_arg succ (length_mapAccumr f x s) | _, [], _ => rfl end MapAccumr section MapAccumr₂ variable {φ : Type w₁} {σ : Type w₂} /-- Runs a function over two lists returning the intermediate results and a final result. -/ def mapAccumr₂ (f : α → β → σ → σ × φ) : List α → List β → σ → σ × List φ | [], _, c => (c, []) | _, [], c => (c, []) | x :: xr, y :: yr, c => let r := mapAccumr₂ f xr yr c let q := f x y r.1 (q.1, q.2 :: r.2) /-- Length of a list obtained using `mapAccumr₂`. -/ @[simp] theorem length_mapAccumr₂ : ∀ (f : α → β → σ → σ × φ) (x y c), length (mapAccumr₂ f x y c).2 = min (length x) (length y) | f, _ :: x, _ :: y, c => calc succ (length (mapAccumr₂ f x y c).2) = succ (min (length x) (length y)) := congr_arg succ (length_mapAccumr₂ f x y c) _ = min (succ (length x)) (succ (length y)) := Eq.symm (succ_min_succ (length x) (length y)) | _, _ :: _, [], _ => rfl | _, [], _ :: _, _ => rfl | _, [], [], _ => rfl end MapAccumr₂ end List
Init\Data\Nat\Lemmas.lean
/- Copyright (c) 2016 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad -/ import Batteries.Data.Nat.Lemmas import Batteries.WF import Mathlib.Util.AssertExists import Mathlib.Data.Nat.Notation /-! # Note about `Mathlib/Init/` The files in `Mathlib/Init` are leftovers from the port from Mathlib3. (They contain content moved from lean3 itself that Mathlib needed but was not moved to lean4.) We intend to move all the content of these files out into the main `Mathlib` directory structure. Contributions assisting with this are appreciated. -/ assert_not_exists Preorder universe u namespace Nat /-! multiplication -/ theorem eq_zero_of_mul_eq_zero : ∀ {n m : ℕ}, n * m = 0 → n = 0 ∨ m = 0 | 0, m => fun _ => Or.inl rfl | succ n, m => by rw [succ_mul]; intro h exact Or.inr (Nat.eq_zero_of_add_eq_zero_left h) /-! properties of inequality -/ protected def ltGeByCases {a b : ℕ} {C : Sort u} (h₁ : a < b → C) (h₂ : b ≤ a → C) : C := Decidable.byCases h₁ fun h => h₂ (Or.elim (Nat.lt_or_ge a b) (fun a => absurd a h) fun a => a) protected def ltByCases {a b : ℕ} {C : Sort u} (h₁ : a < b → C) (h₂ : a = b → C) (h₃ : b < a → C) : C := Nat.ltGeByCases h₁ fun h₁ => Nat.ltGeByCases h₃ fun h => h₂ (Nat.le_antisymm h h₁) -- TODO: there are four variations, depending on which variables we assume to be nonneg /-! bit0/bit1 properties -/ section bit end bit /-! successor and predecessor -/ def discriminate {B : Sort u} {n : ℕ} (H1 : n = 0 → B) (H2 : ∀ m, n = succ m → B) : B := by induction n with | zero => exact H1 rfl | succ n _ => apply H2 _ rfl theorem one_eq_succ_zero : 1 = succ 0 := rfl /-! subtraction Many lemmas are proven more generally in mathlib `Algebra/Order/Sub` -/ /-! min -/ /-! induction principles -/ def twoStepInduction {P : ℕ → Sort u} (H1 : P 0) (H2 : P 1) (H3 : ∀ (n : ℕ) (_IH1 : P n) (_IH2 : P (succ n)), P (succ (succ n))) : ∀ a : ℕ, P a | 0 => H1 | 1 => H2 | succ (succ _n) => H3 _ (twoStepInduction H1 H2 H3 _) (twoStepInduction H1 H2 H3 _) def subInduction {P : ℕ → ℕ → Sort u} (H1 : ∀ m, P 0 m) (H2 : ∀ n, P (succ n) 0) (H3 : ∀ n m, P n m → P (succ n) (succ m)) : ∀ n m : ℕ, P n m | 0, _m => H1 _ | succ _n, 0 => H2 _ | succ n, succ m => H3 _ _ (subInduction H1 H2 H3 n m) -- Porting note: added `elab_as_elim` @[elab_as_elim] protected theorem strong_induction_on {p : Nat → Prop} (n : Nat) (h : ∀ n, (∀ m, m < n → p m) → p n) : p n := Nat.strongRecOn n h protected theorem case_strong_induction_on {p : Nat → Prop} (a : Nat) (hz : p 0) (hi : ∀ n, (∀ m, m ≤ n → p m) → p (succ n)) : p a := Nat.strong_induction_on a fun n => match n with | 0 => fun _ => hz | n + 1 => fun h₁ => hi n fun _m h₂ => h₁ _ (lt_succ_of_le h₂) /-! mod -/ theorem cond_decide_mod_two (x : ℕ) [d : Decidable (x % 2 = 1)] : cond (@decide (x % 2 = 1) d) 1 0 = x % 2 := by by_cases h : x % 2 = 1 · simp! [*] · cases mod_two_eq_zero_or_one x <;> simp! [*, Nat.zero_ne_one] /-! div -/ /-! dvd -/ end Nat
Init\Data\Sigma\Basic.lean
/- Copyright (c) 2014 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad, Floris van Doorn -/ /-! # Note about `Mathlib/Init/` The files in `Mathlib/Init` are leftovers from the port from Mathlib3. (They contain content moved from lean3 itself that Mathlib needed but was not moved to lean4.) We intend to move all the content of these files out into the main `Mathlib` directory structure. Contributions assisting with this are appreciated. # Lemmas about `Sigma` from Lean 3 core. -/ universe u v theorem ex_of_psig {α : Sort u} {p : α → Prop} : (Σ' x, p x) → ∃ x, p x | ⟨x, hx⟩ => ⟨x, hx⟩ protected theorem Sigma.eq {α : Type u} {β : α → Type v} : ∀ {p₁ p₂ : Σ a, β a} (h₁ : p₁.1 = p₂.1), (Eq.recOn h₁ p₁.2 : β p₂.1) = p₂.2 → p₁ = p₂ | ⟨_, _⟩, _, rfl, rfl => rfl protected theorem PSigma.eq {α : Sort u} {β : α → Sort v} : ∀ {p₁ p₂ : Σ' a, β a} (h₁ : p₁.1 = p₂.1), (Eq.recOn h₁ p₁.2 : β p₂.1) = p₂.2 → p₁ = p₂ | ⟨_, _⟩, _, rfl, rfl => rfl
Init\Data\Sigma\Lex.lean
/- Copyright (c) 2016 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ /-! # Note about `Mathlib/Init/` The files in `Mathlib/Init` are leftovers from the port from Mathlib3. (They contain content moved from lean3 itself that Mathlib needed but was not moved to lean4.) We intend to move all the content of these files out into the main `Mathlib` directory structure. Contributions assisting with this are appreciated. # Well-foundedness of orders of well-founded relations Porting note: many declarations that were here in mathlib3 have been moved to `Init.WF` in Lean 4 core. The ones below are all the exceptions. -/ universe u v namespace PSigma section open WellFounded variable {α : Sort u} {β : α → Sort v} {r : α → α → Prop} {s : ∀ a : α, β a → β a → Prop} /-- The lexicographical order of well-founded relations is well-founded. -/ theorem lex_wf (ha : WellFounded r) (hb : ∀ x, WellFounded (s x)) : WellFounded (Lex r s) := WellFounded.intro fun ⟨a, b⟩ => lexAccessible (WellFounded.apply ha a) hb b end section open WellFounded variable {α : Sort u} {β : Sort v} {r : α → α → Prop} {s : β → β → Prop} theorem revLex_wf (ha : WellFounded r) (hb : WellFounded s) : WellFounded (RevLex r s) := WellFounded.intro fun ⟨a, b⟩ => revLexAccessible (apply hb b) (WellFounded.apply ha) a end section theorem skipLeft_wf (α : Type u) {β : Type v} {s : β → β → Prop} (hb : WellFounded s) : WellFounded (SkipLeft α s) := revLex_wf emptyWf.wf hb end instance hasWellFounded {α : Type u} {β : α → Type v} [s₁ : WellFoundedRelation α] [s₂ : ∀ a, WellFoundedRelation (β a)] : WellFoundedRelation (PSigma β) where rel := Lex s₁.rel fun a => (s₂ a).rel wf := lex_wf s₁.wf fun a => (s₂ a).wf end PSigma
Init\Order\LinearOrder.lean
/- Copyright (c) 2016 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura -/ import Mathlib.Order.Defs /-! # Note about `Mathlib/Init/` The files in `Mathlib/Init` are leftovers from the port from Mathlib3. (They contain content moved from lean3 itself that Mathlib needed but was not moved to lean4.) We intend to move all the content of these files out into the main `Mathlib` directory structure. Contributions assisting with this are appreciated. # Basic lemmas about linear orders. The contents of this file came from `init.algebra.functions` in Lean 3, and it would be good to find everything a better home. -/ universe u section open Decidable variable {α : Type u} [LinearOrder α] theorem min_def (a b : α) : min a b = if a ≤ b then a else b := by rw [LinearOrder.min_def a] theorem max_def (a b : α) : max a b = if a ≤ b then b else a := by rw [LinearOrder.max_def a] theorem min_le_left (a b : α) : min a b ≤ a := by -- Porting note: no `min_tac` tactic if h : a ≤ b then simp [min_def, if_pos h, le_refl] else simp [min_def, if_neg h]; exact le_of_not_le h theorem min_le_right (a b : α) : min a b ≤ b := by -- Porting note: no `min_tac` tactic if h : a ≤ b then simp [min_def, if_pos h]; exact h else simp [min_def, if_neg h, le_refl] theorem le_min {a b c : α} (h₁ : c ≤ a) (h₂ : c ≤ b) : c ≤ min a b := by -- Porting note: no `min_tac` tactic if h : a ≤ b then simp [min_def, if_pos h]; exact h₁ else simp [min_def, if_neg h]; exact h₂ theorem le_max_left (a b : α) : a ≤ max a b := by -- Porting note: no `min_tac` tactic if h : a ≤ b then simp [max_def, if_pos h]; exact h else simp [max_def, if_neg h, le_refl] theorem le_max_right (a b : α) : b ≤ max a b := by -- Porting note: no `min_tac` tactic if h : a ≤ b then simp [max_def, if_pos h, le_refl] else simp [max_def, if_neg h]; exact le_of_not_le h theorem max_le {a b c : α} (h₁ : a ≤ c) (h₂ : b ≤ c) : max a b ≤ c := by -- Porting note: no `min_tac` tactic if h : a ≤ b then simp [max_def, if_pos h]; exact h₂ else simp [max_def, if_neg h]; exact h₁ theorem eq_min {a b c : α} (h₁ : c ≤ a) (h₂ : c ≤ b) (h₃ : ∀ {d}, d ≤ a → d ≤ b → d ≤ c) : c = min a b := le_antisymm (le_min h₁ h₂) (h₃ (min_le_left a b) (min_le_right a b)) theorem min_comm (a b : α) : min a b = min b a := eq_min (min_le_right a b) (min_le_left a b) fun h₁ h₂ => le_min h₂ h₁ theorem min_assoc (a b c : α) : min (min a b) c = min a (min b c) := by apply eq_min · apply le_trans; apply min_le_left; apply min_le_left · apply le_min; apply le_trans; apply min_le_left; apply min_le_right; apply min_le_right · intro d h₁ h₂; apply le_min; apply le_min h₁; apply le_trans h₂; apply min_le_left apply le_trans h₂; apply min_le_right theorem min_left_comm : ∀ a b c : α, min a (min b c) = min b (min a c) := left_comm (@min α _) (@min_comm α _) (@min_assoc α _) @[simp] theorem min_self (a : α) : min a a = a := by simp [min_def] theorem min_eq_left {a b : α} (h : a ≤ b) : min a b = a := by apply Eq.symm; apply eq_min (le_refl _) h; intros; assumption theorem min_eq_right {a b : α} (h : b ≤ a) : min a b = b := min_comm b a ▸ min_eq_left h theorem eq_max {a b c : α} (h₁ : a ≤ c) (h₂ : b ≤ c) (h₃ : ∀ {d}, a ≤ d → b ≤ d → c ≤ d) : c = max a b := le_antisymm (h₃ (le_max_left a b) (le_max_right a b)) (max_le h₁ h₂) theorem max_comm (a b : α) : max a b = max b a := eq_max (le_max_right a b) (le_max_left a b) fun h₁ h₂ => max_le h₂ h₁ theorem max_assoc (a b c : α) : max (max a b) c = max a (max b c) := by apply eq_max · apply le_trans; apply le_max_left a b; apply le_max_left · apply max_le; apply le_trans; apply le_max_right a b; apply le_max_left; apply le_max_right · intro d h₁ h₂; apply max_le; apply max_le h₁; apply le_trans (le_max_left _ _) h₂ apply le_trans (le_max_right _ _) h₂ theorem max_left_comm : ∀ a b c : α, max a (max b c) = max b (max a c) := left_comm (@max α _) (@max_comm α _) (@max_assoc α _) @[simp] theorem max_self (a : α) : max a a = a := by simp [max_def] theorem max_eq_left {a b : α} (h : b ≤ a) : max a b = a := by apply Eq.symm; apply eq_max (le_refl _) h; intros; assumption theorem max_eq_right {a b : α} (h : a ≤ b) : max a b = b := max_comm b a ▸ max_eq_left h -- these rely on lt_of_lt theorem min_eq_left_of_lt {a b : α} (h : a < b) : min a b = a := min_eq_left (le_of_lt h) theorem min_eq_right_of_lt {a b : α} (h : b < a) : min a b = b := min_eq_right (le_of_lt h) theorem max_eq_left_of_lt {a b : α} (h : b < a) : max a b = a := max_eq_left (le_of_lt h) theorem max_eq_right_of_lt {a b : α} (h : a < b) : max a b = b := max_eq_right (le_of_lt h) -- these use the fact that it is a linear ordering theorem lt_min {a b c : α} (h₁ : a < b) (h₂ : a < c) : a < min b c := -- Porting note: no `min_tac` tactic Or.elim (le_or_gt b c) (fun h : b ≤ c ↦ by rwa [min_eq_left h]) (fun h : b > c ↦ by rwa [min_eq_right_of_lt h]) theorem max_lt {a b c : α} (h₁ : a < c) (h₂ : b < c) : max a b < c := -- Porting note: no `min_tac` tactic Or.elim (le_or_gt a b) (fun h : a ≤ b ↦ by rwa [max_eq_right h]) (fun h : a > b ↦ by rwa [max_eq_left_of_lt h]) end
Lean\CoreM.lean
/- Copyright (c) 2023 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Tactic.ToExpr /-! # Additional functions using `CoreM` state. -/ open Lean Core /-- Run a `CoreM α` in a fresh `Environment` with specified `modules : List Name` imported. -/ def CoreM.withImportModules {α : Type} (modules : Array Name) (run : CoreM α) (searchPath : Option SearchPath := none) (options : Options := {}) (trustLevel : UInt32 := 0) (fileName := "") : IO α := unsafe do if let some sp := searchPath then searchPathRef.set sp Lean.withImportModules (modules.map (Import.mk · false)) options trustLevel fun env => let ctx := {fileName, options, fileMap := default} let state := {env} Prod.fst <$> (CoreM.toIO · ctx state) do run
Lean\EnvExtension.lean
/- Copyright (c) 2023 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import Lean.ScopedEnvExtension /-! # Helper function for environment extensions and attributes. -/ open Lean instance {σ : Type} [Inhabited σ] : Inhabited (ScopedEnvExtension.State σ) := ⟨{state := default}⟩