l3lab/ntp-mathlib huggingface dataset:
/-- 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 _ _
  

Proof state:
case inr
ι : Type u_1
α : Type u_2
β : Type u_3
f g : Perm α
s t : Set α
a b x y : α
hf : IsCycleOn f s
hs : Set.Nontrivial s
⊢ IsCycleOn (subtypePerm f (_ : ∀ (x : α), x ∈ s ↔ f x ∈ s)) _root_.Set.univ

Next tactic:
convert (hf.isCycle_subtypePerm hs).isCycleOn
/-- 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
  

Proof state:
case h.e'_3
ι : Type u_1
α : Type u_2
β : Type u_3
f g : Perm α
s t : Set α
a b x y : α
hf : IsCycleOn f s
hs : Set.Nontrivial s
⊢ _root_.Set.univ = {x | (subtypePerm f (_ : ∀ (x : α), x ∈ s ↔ f x ∈ s)) x ≠ x}

Next tactic:
rw [eq_comm, Set.eq_univ_iff_forall]
/-- 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]
  

Proof state:
case h.e'_3
ι : Type u_1
α : Type u_2
β : Type u_3
f g : Perm α
s t : Set α
a b x y : α
hf : IsCycleOn f s
hs : Set.Nontrivial s
⊢ ∀ (x : { x // x ∈ s }), x ∈ {x | (subtypePerm f (_ : ∀ (x : α), x ∈ s ↔ f x ∈ s)) x ≠ x}

Next tactic:
exact fun x => ne_of_apply_ne ((↑) : s → α) (hf.apply_ne hs x.2)
theorem IsCycleOn.pow_apply_eq {s : Finset α} (hf : f.IsCycleOn s) (ha : a ∈ s) {n : ℕ} :
    (f ^ n) a = a ↔ s.card ∣ n := by
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
f g : Perm α
s✝ t : Set α
a b x y : α
s : Finset α
hf : IsCycleOn f ↑s
ha : a ∈ s
n : ℕ
⊢ (f ^ n) a = a ↔ card s ∣ n

Next tactic:
obtain rfl | hs := Finset.eq_singleton_or_nontrivial ha
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
  · 

Proof state:
case inl
ι : Type u_1
α : Type u_2
β : Type u_3
f g : Perm α
s t : Set α
a b x y : α
n : ℕ
hf : IsCycleOn f ↑{a}
ha : a ∈ {a}
⊢ (f ^ n) a = a ↔ card {a} ∣ n

Next tactic:
rw [coe_singleton, isCycleOn_singleton] at hf
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
    

Proof state:
case inl
ι : Type u_1
α : Type u_2
β : Type u_3
f g : Perm α
s t : Set α
a b x y : α
n : ℕ
hf : f a = a
ha : a ∈ {a}
⊢ (f ^ n) a = a ↔ card {a} ∣ n

Next tactic:
simpa using IsFixedPt.iterate hf n
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
  

Proof state:
case inr
ι : Type u_1
α : Type u_2
β : Type u_3
f g : Perm α
s✝ t : Set α
a b x y : α
s : Finset α
hf : IsCycleOn f ↑s
ha : a ∈ s
n : ℕ
hs : Finset.Nontrivial s
⊢ (f ^ n) a = a ↔ card s ∣ n

Next tactic:
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.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
    

Proof state:
case inr
ι : Type u_1
α : Type u_2
β : Type u_3
f g : Perm α
s✝ t : Set α
a b x y : α
s : Finset α
hf : IsCycleOn f ↑s
ha : a ∈ s
n : ℕ
hs : Finset.Nontrivial s
⊢ (f ^ n) a = a ↔ card s ∣ n

Next tactic:
have h : ∀ x ∈ s.attach, ¬f ↑x = ↑x := fun x _ => hf.apply_ne hs x.2
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
    

Proof state:
case inr
ι : Type u_1
α : Type u_2
β : Type u_3
f g : Perm α
s✝ t : Set α
a b x y : α
s : Finset α
hf : IsCycleOn f ↑s
ha : a ∈ s
n : ℕ
hs : Finset.Nontrivial s
h : ∀ x ∈ attach s, ¬f ↑x = ↑x
⊢ (f ^ n) a = a ↔ card s ∣ n

Next tactic:
have := (hf.isCycle_subtypePerm hs).orderOf
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
    

Proof state:
case inr
ι : Type u_1
α : Type u_2
β : Type u_3
f g : Perm α
s✝ t : Set α
a b x y : α
s : Finset α
hf : IsCycleOn f ↑s
ha : a ∈ s
n : ℕ
hs : Finset.Nontrivial s
h : ∀ x ∈ attach s, ¬f ↑x = ↑x
this :
  orderOf (subtypePerm f (_ : ∀ (x : α), x ∈ ↑s ↔ f x ∈ ↑s)) =
    card (support (subtypePerm f (_ : ∀ (x : α), x ∈ ↑s ↔ f x ∈ ↑s)))
⊢ (f ^ n) a = a ↔ card s ∣ n

Next tactic:
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
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
    

Proof state:
case inr
ι : Type u_1
α : Type u_2
β : Type u_3
f g : Perm α
s✝ t : Set α
a b x y : α
s : Finset α
hf : IsCycleOn f ↑s
ha : a ∈ s
n : ℕ
hs : Finset.Nontrivial s
h : ∀ x ∈ attach s, ¬f ↑x = ↑x
this : orderOf (subtypePerm f (_ : ∀ (x : α), x ∈ ↑s ↔ f x ∈ ↑s)) = card s
⊢ (f ^ n) a = a ↔ card s ∣ n

Next tactic:
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)]
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)]
    

Proof state:
case inr
ι : Type u_1
α : Type u_2
β : Type u_3
f g : Perm α
s✝ t : Set α
a b x y : α
s : Finset α
hf : IsCycleOn f ↑s
ha : a ∈ s
n : ℕ
hs : Finset.Nontrivial s
h : ∀ x ∈ attach s, ¬f ↑x = ↑x
this : orderOf (subtypePerm f (_ : ∀ (x : α), x ∈ ↑s ↔ f x ∈ ↑s)) = card s
⊢ (f ^ n) a = a ↔
    (subtypePerm f (_ : ∀ (x : α), x ∈ ↑s ↔ f x ∈ ↑s) ^ n) { val := a, property := ha } = { val := a, property := ha }

Next tactic:
simp
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
    

Proof state:
case inr
ι : Type u_1
α : Type u_2
β : Type u_3
f g : Perm α
s✝ t : Set α
a b x y : α
s : Finset α
hf : IsCycleOn f ↑s
ha : a ∈ s
n : ℕ
hs : Finset.Nontrivial s
h : ∀ x ∈ attach s, ¬f ↑x = ↑x
this : orderOf (subtypePerm f (_ : ∀ (x : α), x ∈ ↑s ↔ f x ∈ ↑s)) = card s
⊢ (f ^ n) a = a ↔
    (subtypePerm (f ^ n) (_ : ∀ (x : α), x ∈ ↑s ↔ (f ^ n) x ∈ ↑s)) { val := a, property := ha } =
      { val := a, property := ha }

Next tactic:
erw [subtypePerm_apply]
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]
    

Proof state:
case inr
ι : Type u_1
α : Type u_2
β : Type u_3
f g : Perm α
s✝ t : Set α
a b x y : α
s : Finset α
hf : IsCycleOn f ↑s
ha : a ∈ s
n : ℕ
hs : Finset.Nontrivial s
h : ∀ x ∈ attach s, ¬f ↑x = ↑x
this : orderOf (subtypePerm f (_ : ∀ (x : α), x ∈ ↑s ↔ f x ∈ ↑s)) = card s
⊢ (f ^ n) a = a ↔
    { val := (f ^ n) ↑{ val := a, property := ha }, property := (_ : (f ^ n) ↑{ val := a, property := ha } ∈ ↑s) } =
      { val := a, property := ha }

Next tactic:
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.coe_nat_dvd.symm
  | Int.negSucc n => by
    

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
f g : Perm α
s✝ t : Set α
a b x y : α
s : Finset α
hf : IsCycleOn f ↑s
ha : a ∈ s
n : ℕ
⊢ (f ^ Int.negSucc n) a = a ↔ ↑(card s) ∣ Int.negSucc n

Next tactic:
rw [zpow_negSucc, ← inv_pow]
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.coe_nat_dvd.symm
  | Int.negSucc n => by
    rw [zpow_negSucc, ← inv_pow]
    

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
f g : Perm α
s✝ t : Set α
a b x y : α
s : Finset α
hf : IsCycleOn f ↑s
ha : a ∈ s
n : ℕ
⊢ (f⁻¹ ^ (n + 1)) a = a ↔ ↑(card s) ∣ Int.negSucc n

Next tactic:
exact (hf.inv.pow_apply_eq ha).trans (dvd_neg.trans Int.coe_nat_dvd).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
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
f g : Perm α
s✝ t : Set α
a b x y : α
s : Finset α
hf : IsCycleOn f ↑s
ha : a ∈ s
m n : ℕ
⊢ (f ^ m) a = (f ^ n) a ↔ m ≡ n [MOD card s]

Next tactic:
rw [Nat.modEq_iff_dvd, ← hf.zpow_apply_eq ha]
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]
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
f g : Perm α
s✝ t : Set α
a b x y : α
s : Finset α
hf : IsCycleOn f ↑s
ha : a ∈ s
m n : ℕ
⊢ (f ^ m) a = (f ^ n) a ↔ (f ^ (↑n - ↑m)) a = a

Next tactic:
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
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
f g : Perm α
s✝ t : Set α
a b x y : α
s : Finset α
hf : IsCycleOn f ↑s
ha : a ∈ s
m n : ℤ
⊢ (f ^ m) a = (f ^ n) a ↔ m ≡ n [ZMOD ↑(card s)]

Next tactic:
rw [Int.modEq_iff_dvd, ← hf.zpow_apply_eq ha]
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]
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
f g : Perm α
s✝ t : Set α
a b x y : α
s : Finset α
hf : IsCycleOn f ↑s
ha : a ∈ s
m n : ℤ
⊢ (f ^ m) a = (f ^ n) a ↔ (f ^ (n - m)) a = a

Next tactic:
simp [sub_eq_neg_add, zpow_add, eq_inv_iff_eq, eq_comm]
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
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
f g : Perm α
s✝ t : Set α
a b x y : α
s : Finset α
hf : IsCycleOn f ↑s
ha : a ∈ s
hb : b ∈ s
⊢ ∃ n < card s, (f ^ n) a = b

Next tactic:
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_ofNat, 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_coe_nat, coe_mul, comp_apply, EmbeddingLike.apply_eq_iff_eq]
    exact IsFixedPt.perm_zpow (hf.pow_card_apply ha) _
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
    

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
f g : Perm α
s✝ t : Set α
a b x y : α
s : Finset α
hf : IsCycleOn f ↑s
ha : a ∈ s
hb : b ∈ s
⊢ ∃ n < card s, (f ^ n) a = b

Next tactic:
obtain ⟨n, rfl⟩ := hf.2 ha hb
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
    

Proof state:
case intro
ι : Type u_1
α : Type u_2
β : Type u_3
f g : Perm α
s✝ t : Set α
a x y : α
s : Finset α
hf : IsCycleOn f ↑s
ha : a ∈ s
n : ℤ
hb : (f ^ n) a ∈ s
⊢ ∃ n_1 < card s, (f ^ n_1) a = (f ^ n) a

Next tactic:
obtain ⟨k, hk⟩ := (Int.mod_modEq n s.card).symm.dvd
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
    

Proof state:
case intro.intro
ι : Type u_1
α : Type u_2
β : Type u_3
f g : Perm α
s✝ t : Set α
a x y : α
s : Finset α
hf : IsCycleOn f ↑s
ha : a ∈ s
n : ℤ
hb : (f ^ n) a ∈ s
k : ℤ
hk : n % ↑(card s) - n = ↑(card s) * k
⊢ ∃ n_1 < card s, (f ^ n_1) a = (f ^ n) a

Next tactic:
refine' ⟨n.natMod s.card, Int.natMod_lt (Nonempty.card_pos ⟨a, ha⟩).ne', _⟩
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', _⟩
    

Proof state:
case intro.intro
ι : Type u_1
α : Type u_2
β : Type u_3
f g : Perm α
s✝ t : Set α
a x y : α
s : Finset α
hf : IsCycleOn f ↑s
ha : a ∈ s
n : ℤ
hb : (f ^ n) a ∈ s
k : ℤ
hk : n % ↑(card s) - n = ↑(card s) * k
⊢ (f ^ Int.natMod n ↑(card s)) a = (f ^ n) a

Next tactic:
rw [← zpow_ofNat, 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]
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_ofNat, 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]
    

Proof state:
case intro.intro
ι : Type u_1
α : Type u_2
β : Type u_3
f g : Perm α
s✝ t : Set α
a x y : α
s : Finset α
hf : IsCycleOn f ↑s
ha : a ∈ s
n : ℤ
hb : (f ^ n) a ∈ s
k : ℤ
hk : n % ↑(card s) - n = ↑(card s) * k
⊢ (f ^ n * (f ^ ↑(card s)) ^ k) a = (f ^ n) a

Next tactic:
simp only [zpow_coe_nat, coe_mul, comp_apply, EmbeddingLike.apply_eq_iff_eq]
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_ofNat, 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_coe_nat, coe_mul, comp_apply, EmbeddingLike.apply_eq_iff_eq]
    

Proof state:
case intro.intro
ι : Type u_1
α : Type u_2
β : Type u_3
f g : Perm α
s✝ t : Set α
a x y : α
s : Finset α
hf : IsCycleOn f ↑s
ha : a ∈ s
n : ℤ
hb : (f ^ n) a ∈ s
k : ℤ
hk : n % ↑(card s) - n = ↑(card s) * k
⊢ ((f ^ card s) ^ k) a = a

Next tactic:
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
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
f g : Perm α
s t : Set α
a b x y : α
hs : Set.Finite s
hf : IsCycleOn f s
ha : a ∈ s
hb : b ∈ s
⊢ ∃ n, (f ^ n) a = b

Next tactic:
lift s to Finset α using id hs
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
  

Proof state:
case intro
ι : Type u_1
α : Type u_2
β : Type u_3
f g : Perm α
t : Set α
a b x y : α
s : Finset α
hs : Set.Finite ↑s
hf : IsCycleOn f ↑s
ha : a ∈ ↑s
hb : b ∈ ↑s
⊢ ∃ n, (f ^ n) a = b

Next tactic:
obtain ⟨n, -, hn⟩ := hf.exists_pow_eq ha hb
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
  

Proof state:
case intro.intro.intro
ι : Type u_1
α : Type u_2
β : Type u_3
f g : Perm α
t : Set α
a b x y : α
s : Finset α
hs : Set.Finite ↑s
hf : IsCycleOn f ↑s
ha : a ∈ ↑s
hb : b ∈ ↑s
n : ℕ
hn : (f ^ n) a = b
⊢ ∃ n, (f ^ n) a = b

Next tactic:
exact ⟨n, hn⟩
theorem IsCycleOn.extendDomain {p : β → Prop} [DecidablePred p] (f : α ≃ Subtype p)
    (h : g.IsCycleOn s) : (g.extendDomain f).IsCycleOn ((↑) ∘ f '' s) :=
  ⟨h.1.extendDomain, by
    

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
f✝ g : Perm α
s t : Set α
a b x y : α
p : β → Prop
inst✝ : DecidablePred p
f : α ≃ Subtype p
h : IsCycleOn g s
⊢ ∀ ⦃x : β⦄, x ∈ Subtype.val ∘ ⇑f '' s → ∀ ⦃y : β⦄, y ∈ Subtype.val ∘ ⇑f '' s → SameCycle (Perm.extendDomain g f) x y

Next tactic:
rintro _ ⟨a, ha, rfl⟩ _ ⟨b, hb, rfl⟩
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⟩
    

Proof state:
case intro.intro.intro.intro
ι : Type u_1
α : Type u_2
β : Type u_3
f✝ g : Perm α
s t : Set α
a✝ b✝ x y : α
p : β → Prop
inst✝ : DecidablePred p
f : α ≃ Subtype p
h : IsCycleOn g s
a : α
ha : a ∈ s
b : α
hb : b ∈ s
⊢ SameCycle (Perm.extendDomain g f) ((Subtype.val ∘ ⇑f) a) ((Subtype.val ∘ ⇑f) b)

Next tactic:
exact (h.2 ha hb).extendDomain
protected theorem IsCycleOn.countable (hs : f.IsCycleOn s) : s.Countable := by
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
f g : Perm α
s t : Set α
a b x y : α
hs : IsCycleOn f s
⊢ Set.Countable s

Next tactic:
obtain rfl | ⟨a, ha⟩ := s.eq_empty_or_nonempty
protected theorem IsCycleOn.countable (hs : f.IsCycleOn s) : s.Countable := by
  obtain rfl | ⟨a, ha⟩ := s.eq_empty_or_nonempty
  · 

Proof state:
case inl
ι : Type u_1
α : Type u_2
β : Type u_3
f g : Perm α
t : Set α
a b x y : α
hs : IsCycleOn f ∅
⊢ Set.Countable ∅

Next tactic:
exact Set.countable_empty
protected theorem IsCycleOn.countable (hs : f.IsCycleOn s) : s.Countable := by
  obtain rfl | ⟨a, ha⟩ := s.eq_empty_or_nonempty
  · exact Set.countable_empty
  · 

Proof state:
case inr.intro
ι : Type u_1
α : Type u_2
β : Type u_3
f g : Perm α
s t : Set α
a✝ b x y : α
hs : IsCycleOn f s
a : α
ha : a ∈ s
⊢ Set.Countable s

Next tactic:
exact (Set.countable_range fun n : ℤ => (⇑(f ^ n) : α → α) a).mono (hs.2 ha)
theorem cycleOf_apply (f : Perm α) (x y : α) :
    cycleOf f x y = if SameCycle f x y then f y else y := by
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
inst✝¹ : DecidableEq α
inst✝ : Fintype α
f✝ g : Perm α
x✝ y✝ : α
f : Perm α
x y : α
⊢ (cycleOf f x) y = if SameCycle f x y then f y else y

Next tactic:
dsimp only [cycleOf]
theorem cycleOf_apply (f : Perm α) (x y : α) :
    cycleOf f x y = if SameCycle f x y then f y else y := by
  dsimp only [cycleOf]
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
inst✝¹ : DecidableEq α
inst✝ : Fintype α
f✝ g : Perm α
x✝ y✝ : α
f : Perm α
x y : α
⊢ (ofSubtype (subtypePerm f (_ : ∀ (x_1 : α), SameCycle f x x_1 ↔ SameCycle f x (f x_1)))) y =
    if SameCycle f x y then f y else y

Next tactic:
split_ifs with h
theorem cycleOf_apply (f : Perm α) (x y : α) :
    cycleOf f x y = if SameCycle f x y then f y else y := by
  dsimp only [cycleOf]
  split_ifs with h
  · 

Proof state:
case pos
ι : Type u_1
α : Type u_2
β : Type u_3
inst✝¹ : DecidableEq α
inst✝ : Fintype α
f✝ g : Perm α
x✝ y✝ : α
f : Perm α
x y : α
h : SameCycle f x y
⊢ (ofSubtype (subtypePerm f (_ : ∀ (x_1 : α), SameCycle f x x_1 ↔ SameCycle f x (f x_1)))) y = f y

Next tactic:
apply ofSubtype_apply_of_mem
theorem cycleOf_apply (f : Perm α) (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
    

Proof state:
case pos.ha
ι : Type u_1
α : Type u_2
β : Type u_3
inst✝¹ : DecidableEq α
inst✝ : Fintype α
f✝ g : Perm α
x✝ y✝ : α
f : Perm α
x y : α
h : SameCycle f x y
⊢ SameCycle f x y

Next tactic:
exact h