Skip to content

Commit e93ba4e

Browse files
committed
refactor: Redefine pow in terms of iterate
In the `Monoid` instances for `Function.End α`, `Equiv.Perm α`, `AddMonoid.End α`, `α →+* α`, replace the default `npowRec` by a custom one in terms of `Nat.iterate`. Write the expected coercion lemmas. As a consequence, I can delete the recently introduced file `Algebra.Ring.Hom.IterateHom`.
1 parent 4421fe0 commit e93ba4e

File tree

7 files changed

+50
-62
lines changed

7 files changed

+50
-62
lines changed

Mathlib.lean

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,6 @@ import Mathlib.Algebra.Ring.Equiv
576576
import Mathlib.Algebra.Ring.Fin
577577
import Mathlib.Algebra.Ring.Hom.Basic
578578
import Mathlib.Algebra.Ring.Hom.Defs
579-
import Mathlib.Algebra.Ring.Hom.IterateHom
580579
import Mathlib.Algebra.Ring.Idempotents
581580
import Mathlib.Algebra.Ring.InjSurj
582581
import Mathlib.Algebra.Ring.Int

Mathlib/Algebra/Group/Hom/Defs.lean

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Authors: Patrick Massot, Kevin Buzzard, Scott Morrison, Johan Commelin, Chris Hu
66
-/
77
import Mathlib.Algebra.Group.Pi.Basic
88
import Mathlib.Data.FunLike.Basic
9+
import Mathlib.Logic.Function.Iterate
910

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

@@ -1132,29 +1133,31 @@ protected def End := A →+ A
11321133

11331134
namespace End
11341135

1136+
instance instFunLike : FunLike (AddMonoid.End A) A A := AddMonoidHom.instFunLike
1137+
instance instAddMonoidHomClass : AddMonoidHomClass (AddMonoid.End A) A A :=
1138+
AddMonoidHom.instAddMonoidHomClass
1139+
1140+
instance instOne : One (AddMonoid.End A) where one := .id _
1141+
instance instMul : Mul (AddMonoid.End A) where mul := .comp
1142+
1143+
@[simp, norm_cast] lemma coe_one : ((1 : AddMonoid.End A) : A → A) = id := rfl
1144+
#align add_monoid.coe_one AddMonoid.End.coe_one
1145+
1146+
@[simp, norm_cast] lemma coe_mul (f g : AddMonoid.End A) : (f * g : A → A) = f ∘ g := rfl
1147+
#align add_monoid.coe_mul AddMonoid.End.coe_mul
1148+
11351149
instance monoid : Monoid (AddMonoid.End A) where
1136-
mul := AddMonoidHom.comp
1137-
one := AddMonoidHom.id A
11381150
mul_assoc _ _ _ := AddMonoidHom.comp_assoc _ _ _
11391151
mul_one := AddMonoidHom.comp_id
11401152
one_mul := AddMonoidHom.id_comp
1153+
npow n f := (npowRec n f).copy (Nat.iterate f n) $ by induction n <;> simp [npowRec, *] <;> rfl
1154+
npow_succ n f := DFunLike.coe_injective $ Function.iterate_succ _ _
11411155

1142-
instance : Inhabited (AddMonoid.End A) := ⟨1
1143-
1144-
instance : FunLike (AddMonoid.End A) A A := AddMonoidHom.instFunLike
1156+
@[simp, norm_cast] lemma coe_pow (f : AddMonoid.End A) (n : ℕ) : (↑(f ^ n) : A → A) = f^[n] := rfl
11451157

1146-
instance : AddMonoidHomClass (AddMonoid.End A) A A := AddMonoidHom.instAddMonoidHomClass
1158+
instance : Inhabited (AddMonoid.End A) := 1
11471159

11481160
end End
1149-
1150-
@[simp]
1151-
theorem coe_one : ((1 : AddMonoid.End A) : A → A) = id := rfl
1152-
#align add_monoid.coe_one AddMonoid.coe_one
1153-
1154-
@[simp]
1155-
theorem coe_mul (f g) : ((f * g : AddMonoid.End A) : A → A) = f ∘ g := rfl
1156-
#align add_monoid.coe_mul AddMonoid.coe_mul
1157-
11581161
end AddMonoid
11591162

11601163
end End

Mathlib/Algebra/Ring/Hom/Defs.lean

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -681,31 +681,31 @@ theorem id_comp (f : α →+* β) : (id β).comp f = f :=
681681
ext fun _ => rfl
682682
#align ring_hom.id_comp RingHom.id_comp
683683

684-
instance : Monoid (α →+* α) where
685-
one := id α
686-
mul := comp
687-
mul_one := comp_id
688-
one_mul := id_comp
689-
mul_assoc f g h := comp_assoc _ _ _
684+
instance instOne : One (α →+* α) where one := id _
685+
instance instMul : Mul (α →+* α) where mul := comp
690686

691-
theorem one_def : (1 : α →+* α) = id α :=
692-
rfl
687+
lemma one_def : (1 : α →+* α) = id α := rfl
693688
#align ring_hom.one_def RingHom.one_def
694689

695-
theorem mul_def (f g : α →+* α) : f * g = f.comp g :=
696-
rfl
690+
lemma mul_def (f g : α →+* α) : f * g = f.comp g := rfl
697691
#align ring_hom.mul_def RingHom.mul_def
698692

699-
@[simp]
700-
theorem coe_one : ⇑(1 : α →+* α) = _root_.id :=
701-
rfl
693+
@[simp, norm_cast] lemma coe_one : ⇑(1 : α →+* α) = _root_.id := rfl
702694
#align ring_hom.coe_one RingHom.coe_one
703695

704-
@[simp]
705-
theorem coe_mul (f g : α →+* α) : ⇑(f * g) = f ∘ g :=
706-
rfl
696+
@[simp, norm_cast] lemma coe_mul (f g : α →+* α) : ⇑(f * g) = f ∘ g := rfl
707697
#align ring_hom.coe_mul RingHom.coe_mul
708698

699+
instance instMonoid : Monoid (α →+* α) where
700+
mul_one := comp_id
701+
one_mul := id_comp
702+
mul_assoc f g h := comp_assoc _ _ _
703+
npow n f := (npowRec n f).copy (f^[n]) $ by induction' n <;> simp [npowRec, *]
704+
npow_succ n f := DFunLike.coe_injective $ Function.iterate_succ _ _
705+
706+
@[simp, norm_cast] lemma coe_pow (f : α →+* α) (n : ℕ) : ⇑(f ^ n) = f^[n] := rfl
707+
#align ring_hom.coe_pow RingHom.coe_pow
708+
709709
@[simp]
710710
theorem cancel_right {g₁ g₂ : β →+* γ} {f : α →+* β} (hf : Surjective f) :
711711
g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=

Mathlib/Algebra/Ring/Hom/IterateHom.lean

Lines changed: 0 additions & 21 deletions
This file was deleted.

Mathlib/Dynamics/FixedPoints/Basic.lean

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@ protected theorem perm_inv (h : IsFixedPt e x) : IsFixedPt (⇑e⁻¹) x :=
112112
h.equiv_symm
113113
#align function.is_fixed_pt.perm_inv Function.IsFixedPt.perm_inv
114114

115-
protected theorem perm_pow (h : IsFixedPt e x) (n : ℕ) : IsFixedPt (⇑(e ^ n)) x := by
116-
rw [Equiv.Perm.coe_pow]
117-
exact h.iterate _
115+
protected theorem perm_pow (h : IsFixedPt e x) (n : ℕ) : IsFixedPt (⇑(e ^ n)) x := h.iterate _
118116
#align function.is_fixed_pt.perm_pow Function.IsFixedPt.perm_pow
119117

120118
protected theorem perm_zpow (h : IsFixedPt e x) : ∀ n : ℤ, IsFixedPt (⇑(e ^ n)) x

Mathlib/GroupTheory/GroupAction/Defs.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Mathlib.Algebra.Group.Hom.Defs
88
import Mathlib.Algebra.Group.TypeTags
99
import Mathlib.Algebra.Opposites
1010
import Mathlib.Logic.Embedding.Basic
11+
import Mathlib.Logic.Function.Iterate
1112

1213
#align_import group_theory.group_action.defs from "leanprover-community/mathlib"@"dad7ecf9a1feae63e6e49f07619b7087403fb8d4"
1314

@@ -1152,6 +1153,8 @@ instance : Monoid (Function.End α) where
11521153
mul_assoc f g h := rfl
11531154
mul_one f := rfl
11541155
one_mul f := rfl
1156+
npow n f := f^[n]
1157+
npow_succ n f := Function.iterate_succ _ _
11551158

11561159
instance : Inhabited (Function.End α) :=
11571160
1

Mathlib/GroupTheory/Perm/Basic.lean

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,21 @@ variable {α : Type u} {β : Type v}
2525

2626
namespace Perm
2727

28+
instance instOne : One (Perm α) where one := Equiv.refl _
29+
instance instMul : Mul (Perm α) where mul f g := Equiv.trans g f
30+
instance instInv : Inv (Perm α) where inv := Equiv.symm
31+
instance instPowNat : Pow (Perm α) ℕ where
32+
pow f n := ⟨f^[n], f.symm^[n], f.left_inv.iterate _, f.right_inv.iterate _⟩
33+
2834
instance permGroup : Group (Perm α) where
29-
mul f g := Equiv.trans g f
30-
one := Equiv.refl α
31-
inv := Equiv.symm
3235
mul_assoc f g h := (trans_assoc _ _ _).symm
3336
one_mul := trans_refl
3437
mul_one := refl_trans
3538
mul_left_inv := self_trans_symm
39+
npow n f := f ^ n
40+
npow_succ n f := coe_fn_injective $ Function.iterate_succ _ _
41+
zpow := zpowRec fun n f ↦ f ^ n
42+
zpow_succ' n f := coe_fn_injective $ Function.iterate_succ _ _
3643
#align equiv.perm.perm_group Equiv.Perm.permGroup
3744

3845
@[simp]
@@ -100,11 +107,10 @@ theorem inv_def (f : Perm α) : f⁻¹ = f.symm :=
100107
@[simp, norm_cast] lemma coe_mul (f g : Perm α) : ⇑(f * g) = f ∘ g := rfl
101108
#align equiv.perm.coe_mul Equiv.Perm.coe_mul
102109

103-
@[norm_cast] lemma coe_pow (f : Perm α) (n : ℕ) : ⇑(f ^ n) = f^[n] :=
104-
hom_coe_pow _ rfl (fun _ _ ↦ rfl) _ _
110+
@[norm_cast] lemma coe_pow (f : Perm α) (n : ℕ) : ⇑(f ^ n) = (f^[n]) := rfl
105111
#align equiv.perm.coe_pow Equiv.Perm.coe_pow
106112

107-
@[simp] lemma iterate_eq_pow (f : Perm α) (n : ℕ) : f^[n] = ⇑(f ^ n) := (coe_pow _ _).symm
113+
@[simp] lemma iterate_eq_pow (f : Perm α) (n : ℕ) : (f^[n]) = ⇑(f ^ n) := rfl
108114
#align equiv.perm.iterate_eq_pow Equiv.Perm.iterate_eq_pow
109115

110116
theorem eq_inv_iff_eq {f : Perm α} {x y : α} : x = f⁻¹ y ↔ f x = y :=

0 commit comments

Comments
 (0)