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

Proof state:
n : ℕ
e : Perm (Fin n)
p : Fin (n + 1)
x : Fin n
⊢ (decomposeFin.symm (p, e)) (Fin.succ x) = (swap 0 p) (Fin.succ (e x))

Next tactic:
refine' Fin.cases _ _ p
@[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
  · 

Proof state:
case refine'_1
n : ℕ
e : Perm (Fin n)
p : Fin (n + 1)
x : Fin n
⊢ (decomposeFin.symm (0, e)) (Fin.succ x) = (swap 0 0) (Fin.succ (e x))

Next tactic:
simp [Equiv.Perm.decomposeFin, EquivFunctor.map]
@[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]
  · 

Proof state:
case refine'_2
n : ℕ
e : Perm (Fin n)
p : Fin (n + 1)
x : Fin n
⊢ ∀ (i : Fin n), (decomposeFin.symm (Fin.succ i, e)) (Fin.succ x) = (swap 0 (Fin.succ i)) (Fin.succ (e x))

Next tactic:
intro i
@[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
    

Proof state:
case refine'_2
n : ℕ
e : Perm (Fin n)
p : Fin (n + 1)
x i : Fin n
⊢ (decomposeFin.symm (Fin.succ i, e)) (Fin.succ x) = (swap 0 (Fin.succ i)) (Fin.succ (e x))

Next tactic:
by_cases h : i = e x
@[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
    · 

Proof state:
case pos
n : ℕ
e : Perm (Fin n)
p : Fin (n + 1)
x i : Fin n
h : i = e x
⊢ (decomposeFin.symm (Fin.succ i, e)) (Fin.succ x) = (swap 0 (Fin.succ i)) (Fin.succ (e x))

Next tactic:
simp [h, Equiv.Perm.decomposeFin, EquivFunctor.map]
@[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]
    · 

Proof state:
case neg
n : ℕ
e : Perm (Fin n)
p : Fin (n + 1)
x i : Fin n
h : ¬i = e x
⊢ (decomposeFin.symm (Fin.succ i, e)) (Fin.succ x) = (swap 0 (Fin.succ i)) (Fin.succ (e x))

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

Proof state:
n : ℕ
e : Perm (Fin (n + 1))
p : Fin (n + 2)
⊢ (decomposeFin.symm (p, e)) 1 = (swap 0 p) (Fin.succ (e 0))

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

Proof state:
n : ℕ
p : Fin (n + 1)
e : Perm (Fin n)
⊢ sign (decomposeFin.symm (p, e)) = (if p = 0 then 1 else -1) * sign e

Next tactic:
refine' Fin.cases _ _ p
@[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 <;> 

Proof state:
case refine'_1
n : ℕ
p : Fin (n + 1)
e : Perm (Fin n)
⊢ sign (decomposeFin.symm (0, e)) = (if 0 = 0 then 1 else -1) * sign e

Next tactic:
simp [Equiv.Perm.decomposeFin, Fin.succ_ne_zero]
@[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 <;> 

Proof state:
case refine'_2
n : ℕ
p : Fin (n + 1)
e : Perm (Fin n)
⊢ ∀ (i : Fin n), sign (decomposeFin.symm (Fin.succ i, e)) = (if Fin.succ i = 0 then 1 else -1) * sign e

Next tactic:
simp [Equiv.Perm.decomposeFin, Fin.succ_ne_zero]
theorem finRotate_succ_eq_decomposeFin {n : ℕ} :
    finRotate n.succ = decomposeFin.symm (1, finRotate n) := by
  

Proof state:
n : ℕ
⊢ finRotate (Nat.succ n) = decomposeFin.symm (1, finRotate n)

Next tactic:
ext i
theorem finRotate_succ_eq_decomposeFin {n : ℕ} :
    finRotate n.succ = decomposeFin.symm (1, finRotate n) := by
  ext i
  

Proof state:
case H.h
n : ℕ
i : Fin (Nat.succ n)
⊢ ↑((finRotate (Nat.succ n)) i) = ↑((decomposeFin.symm (1, finRotate n)) i)

Next tactic:
cases n
theorem finRotate_succ_eq_decomposeFin {n : ℕ} :
    finRotate n.succ = decomposeFin.symm (1, finRotate n) := by
  ext i
  cases n; · 

Proof state:
case H.h.zero
i : Fin (Nat.succ Nat.zero)
⊢ ↑((finRotate (Nat.succ Nat.zero)) i) = ↑((decomposeFin.symm (1, finRotate Nat.zero)) i)

Next tactic:
simp
theorem finRotate_succ_eq_decomposeFin {n : ℕ} :
    finRotate n.succ = decomposeFin.symm (1, finRotate n) := by
  ext i
  cases n; · simp
  

Proof state:
case H.h.succ
n✝ : ℕ
i : Fin (Nat.succ (Nat.succ n✝))
⊢ ↑((finRotate (Nat.succ (Nat.succ n✝))) i) = ↑((decomposeFin.symm (1, finRotate (Nat.succ n✝))) i)

Next tactic:
refine' Fin.cases _ (fun i => _) i
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
  · 

Proof state:
case H.h.succ.refine'_1
n✝ : ℕ
i : Fin (Nat.succ (Nat.succ n✝))
⊢ ↑((finRotate (Nat.succ (Nat.succ n✝))) 0) = ↑((decomposeFin.symm (1, finRotate (Nat.succ n✝))) 0)

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

Proof state:
case H.h.succ.refine'_2
n✝ : ℕ
i✝ : Fin (Nat.succ (Nat.succ n✝))
i : Fin (n✝ + 1)
⊢ ↑((finRotate (Nat.succ (Nat.succ n✝))) (Fin.succ i)) =
    ↑((decomposeFin.symm (1, finRotate (Nat.succ n✝))) (Fin.succ i))

Next tactic:
rw [coe_finRotate, decomposeFin_symm_apply_succ, if_congr i.succ_eq_last_succ rfl rfl]
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]
  

Proof state:
case H.h.succ.refine'_2
n✝ : ℕ
i✝ : Fin (Nat.succ (Nat.succ n✝))
i : Fin (n✝ + 1)
⊢ (if i = Fin.last n✝ then 0 else ↑(Fin.succ i) + 1) = ↑((swap 0 1) (Fin.succ ((finRotate (Nat.succ n✝)) i)))

Next tactic:
split_ifs with h
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
  · 

Proof state:
case pos
n✝ : ℕ
i✝ : Fin (Nat.succ (Nat.succ n✝))
i : Fin (n✝ + 1)
h : i = Fin.last n✝
⊢ 0 = ↑((swap 0 1) (Fin.succ ((finRotate (Nat.succ n✝)) i)))

Next tactic:
simp [h]
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]
  · 

Proof state:
case neg
n✝ : ℕ
i✝ : Fin (Nat.succ (Nat.succ n✝))
i : Fin (n✝ + 1)
h : ¬i = Fin.last n✝
⊢ ↑(Fin.succ i) + 1 = ↑((swap 0 1) (Fin.succ ((finRotate (Nat.succ n✝)) i)))

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

Proof state:
n : ℕ
⊢ sign (finRotate (n + 1)) = (-1) ^ n

Next tactic:
induction' n with n ih
@[simp]
theorem sign_finRotate (n : ℕ) : Perm.sign (finRotate (n + 1)) = (-1) ^ n := by
  induction' n with n ih
  · 

Proof state:
case zero
⊢ sign (finRotate (Nat.zero + 1)) = (-1) ^ Nat.zero

Next tactic:
simp
@[simp]
theorem sign_finRotate (n : ℕ) : Perm.sign (finRotate (n + 1)) = (-1) ^ n := by
  induction' n with n ih
  · simp; 

Proof state:
case zero
⊢ sign (finRotate (0 + 1)) = 1

Next tactic:
rfl
@[simp]
theorem sign_finRotate (n : ℕ) : Perm.sign (finRotate (n + 1)) = (-1) ^ n := by
  induction' n with n ih
  · simp; rfl
  · 

Proof state:
case succ
n : ℕ
ih : sign (finRotate (n + 1)) = (-1) ^ n
⊢ sign (finRotate (Nat.succ n + 1)) = (-1) ^ Nat.succ n

Next tactic:
rw [finRotate_succ_eq_decomposeFin]
@[simp]
theorem sign_finRotate (n : ℕ) : Perm.sign (finRotate (n + 1)) = (-1) ^ n := by
  induction' n with n ih
  · simp; rfl
  · rw [finRotate_succ_eq_decomposeFin]
    

Proof state:
case succ
n : ℕ
ih : sign (finRotate (n + 1)) = (-1) ^ n
⊢ sign (decomposeFin.symm (1, finRotate (n + 1))) = (-1) ^ Nat.succ n

Next tactic:
simp [ih, pow_succ]
@[simp]
theorem support_finRotate {n : ℕ} : support (finRotate (n + 2)) = Finset.univ := by
  

Proof state:
n : ℕ
⊢ support (finRotate (n + 2)) = Finset.univ

Next tactic:
ext
@[simp]
theorem support_finRotate {n : ℕ} : support (finRotate (n + 2)) = Finset.univ := by
  ext
  

Proof state:
case a
n : ℕ
a✝ : Fin (n + 2)
⊢ a✝ ∈ support (finRotate (n + 2)) ↔ a✝ ∈ Finset.univ

Next tactic:
simp
theorem support_finRotate_of_le {n : ℕ} (h : 2 ≤ n) : support (finRotate n) = Finset.univ := by
  

Proof state:
n : ℕ
h : 2 ≤ n
⊢ support (finRotate n) = Finset.univ

Next tactic:
obtain ⟨m, rfl⟩ := exists_add_of_le h
theorem support_finRotate_of_le {n : ℕ} (h : 2 ≤ n) : support (finRotate n) = Finset.univ := by
  obtain ⟨m, rfl⟩ := exists_add_of_le h
  

Proof state:
case intro
m : ℕ
h : 2 ≤ 2 + m
⊢ support (finRotate (2 + m)) = Finset.univ

Next tactic:
rw [add_comm, support_finRotate]
theorem isCycle_finRotate {n : ℕ} : IsCycle (finRotate (n + 2)) := by
  

Proof state:
n : ℕ
⊢ IsCycle (finRotate (n + 2))

Next tactic:
refine' ⟨0, by simp, fun x hx' => ⟨x, _⟩⟩
theorem isCycle_finRotate {n : ℕ} : IsCycle (finRotate (n + 2)) := by
  refine' ⟨0, by 

Proof state:
n : ℕ
⊢ (finRotate (n + 2)) 0 ≠ 0

Next tactic:
simp
theorem isCycle_finRotate {n : ℕ} : IsCycle (finRotate (n + 2)) := by
  refine' ⟨0, by simp, fun x hx' => ⟨x, _⟩⟩
  

Proof state:
n : ℕ
x : Fin (n + 2)
hx' : (finRotate (n + 2)) x ≠ x
⊢ (finRotate (n + 2) ^ ↑↑x) 0 = x

Next tactic:
clear hx'
theorem isCycle_finRotate {n : ℕ} : IsCycle (finRotate (n + 2)) := by
  refine' ⟨0, by simp, fun x hx' => ⟨x, _⟩⟩
  clear hx'
  

Proof state:
n : ℕ
x : Fin (n + 2)
⊢ (finRotate (n + 2) ^ ↑↑x) 0 = x

Next tactic:
cases' x with x hx
theorem isCycle_finRotate {n : ℕ} : IsCycle (finRotate (n + 2)) := by
  refine' ⟨0, by simp, fun x hx' => ⟨x, _⟩⟩
  clear hx'
  cases' x with x hx
  

Proof state:
case mk
n x : ℕ
hx : x < n + 2
⊢ (finRotate (n + 2) ^ ↑↑{ val := x, isLt := hx }) 0 = { val := x, isLt := hx }

Next tactic:
rw [zpow_ofNat, Fin.ext_iff, Fin.val_mk]
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_ofNat, Fin.ext_iff, Fin.val_mk]
  

Proof state:
case mk
n x : ℕ
hx : x < n + 2
⊢ ↑((finRotate (n + 2) ^ ↑{ val := x, isLt := hx }) 0) = ↑{ val := x, isLt := hx }

Next tactic:
induction' x with x ih
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_ofNat, Fin.ext_iff, Fin.val_mk]
  induction' x with x ih; · 

Proof state:
case mk.zero
n : ℕ
hx : Nat.zero < n + 2
⊢ ↑((finRotate (n + 2) ^ ↑{ val := Nat.zero, isLt := hx }) 0) = ↑{ val := Nat.zero, isLt := hx }

Next tactic:
rfl
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_ofNat, Fin.ext_iff, Fin.val_mk]
  induction' x with x ih; · rfl
  

Proof state:
case mk.succ
n x : ℕ
ih : ∀ (hx : x < n + 2), ↑((finRotate (n + 2) ^ ↑{ val := x, isLt := hx }) 0) = ↑{ val := x, isLt := hx }
hx : Nat.succ x < n + 2
⊢ ↑((finRotate (n + 2) ^ ↑{ val := Nat.succ x, isLt := hx }) 0) = ↑{ val := Nat.succ x, isLt := hx }

Next tactic:
rw [pow_succ, Perm.mul_apply, coe_finRotate_of_ne_last, ih (lt_trans x.lt_succ_self hx)]
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_ofNat, 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)]
  

Proof state:
case mk.succ
n x : ℕ
ih : ∀ (hx : x < n + 2), ↑((finRotate (n + 2) ^ ↑{ val := x, isLt := hx }) 0) = ↑{ val := x, isLt := hx }
hx : Nat.succ x < n + 2
⊢ (finRotate (n + 2) ^ x) 0 ≠ Fin.last (n + 1)

Next tactic:
rw [Ne.def, Fin.ext_iff, ih (lt_trans x.lt_succ_self hx), Fin.val_last]
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_ofNat, 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.def, Fin.ext_iff, ih (lt_trans x.lt_succ_self hx), Fin.val_last]
  

Proof state:
case mk.succ
n x : ℕ
ih : ∀ (hx : x < n + 2), ↑((finRotate (n + 2) ^ ↑{ val := x, isLt := hx }) 0) = ↑{ val := x, isLt := hx }
hx : Nat.succ x < n + 2
⊢ ¬↑{ val := x, isLt := (_ : x < n + 2) } = n + 1

Next tactic:
exact ne_of_lt (Nat.lt_of_succ_lt_succ hx)
theorem isCycle_finRotate_of_le {n : ℕ} (h : 2 ≤ n) : IsCycle (finRotate n) := by
  

Proof state:
n : ℕ
h : 2 ≤ n
⊢ IsCycle (finRotate n)

Next tactic:
obtain ⟨m, rfl⟩ := exists_add_of_le h
theorem isCycle_finRotate_of_le {n : ℕ} (h : 2 ≤ n) : IsCycle (finRotate n) := by
  obtain ⟨m, rfl⟩ := exists_add_of_le h
  

Proof state:
case intro
m : ℕ
h : 2 ≤ 2 + m
⊢ IsCycle (finRotate (2 + m))

Next tactic:
rw [add_comm]
theorem isCycle_finRotate_of_le {n : ℕ} (h : 2 ≤ n) : IsCycle (finRotate n) := by
  obtain ⟨m, rfl⟩ := exists_add_of_le h
  rw [add_comm]
  

Proof state:
case intro
m : ℕ
h : 2 ≤ 2 + m
⊢ IsCycle (finRotate (m + 2))

Next tactic:
exact isCycle_finRotate
@[simp]
theorem cycleType_finRotate {n : ℕ} : cycleType (finRotate (n + 2)) = {n + 2} := by
  

Proof state:
n : ℕ
⊢ cycleType (finRotate (n + 2)) = {n + 2}

Next tactic:
rw [isCycle_finRotate.cycleType, support_finRotate, ← Fintype.card, Fintype.card_fin]
@[simp]
theorem cycleType_finRotate {n : ℕ} : cycleType (finRotate (n + 2)) = {n + 2} := by
  rw [isCycle_finRotate.cycleType, support_finRotate, ← Fintype.card, Fintype.card_fin]
  

Proof state:
n : ℕ
⊢ ↑[n + 2] = {n + 2}

Next tactic:
rfl
theorem cycleType_finRotate_of_le {n : ℕ} (h : 2 ≤ n) : cycleType (finRotate n) = {n} := by
  

Proof state:
n : ℕ
h : 2 ≤ n
⊢ cycleType (finRotate n) = {n}

Next tactic:
obtain ⟨m, rfl⟩ := exists_add_of_le h
theorem cycleType_finRotate_of_le {n : ℕ} (h : 2 ≤ n) : cycleType (finRotate n) = {n} := by
  obtain ⟨m, rfl⟩ := exists_add_of_le h
  

Proof state:
case intro
m : ℕ
h : 2 ≤ 2 + m
⊢ cycleType (finRotate (2 + m)) = {2 + m}

Next tactic:
rw [add_comm, cycleType_finRotate]
/-- `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)).toEmbedding (↑)
      (by
        

Proof state:
n : ℕ
i : Fin n
⊢ Function.LeftInverse (fun x => ↑↑x) ⇑(castLEEmb (_ : Nat.succ ↑i ≤ n)).toEmbedding

Next tactic:
intro x
/-- `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)).toEmbedding (↑)
      (by
        intro x
        

Proof state:
n : ℕ
i : Fin n
x : Fin (Nat.succ ↑i)
⊢ (fun x => ↑↑x) ((castLEEmb (_ : Nat.succ ↑i ≤ n)).toEmbedding x) = x

Next tactic:
ext
/-- `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)).toEmbedding (↑)
      (by
        intro x
        ext
        

Proof state:
case h
n : ℕ
i : Fin n
x : Fin (Nat.succ ↑i)
⊢ ↑((fun x => ↑↑x) ((castLEEmb (_ : Nat.succ ↑i ≤ n)).toEmbedding x)) = ↑x

Next tactic:
simp
theorem cycleRange_of_gt {n : ℕ} {i j : Fin n.succ} (h : i < j) : cycleRange i j = j := by
  

Proof state:
n : ℕ
i j : Fin (Nat.succ n)
h : i < j
⊢ (cycleRange i) j = j

Next tactic:
rw [cycleRange, ofLeftInverse'_eq_ofInjective,
    ← Function.Embedding.toEquivRange_eq_ofInjective, ← viaFintypeEmbedding,
    viaFintypeEmbedding_apply_not_mem_range]
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]
  

Proof state:
case h
n : ℕ
i j : Fin (Nat.succ n)
h : i < j
⊢ j ∉ Set.range ⇑(castLEEmb (_ : Nat.succ ↑i ≤ Nat.succ n)).toEmbedding

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

Proof state:
n : ℕ
i j : Fin (Nat.succ n)
h : j ≤ i
⊢ (cycleRange i) j = if j = i then 0 else j + 1

Next tactic:
cases n
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
  · 

Proof state:
case zero
i j : Fin (Nat.succ Nat.zero)
h : j ≤ i
⊢ (cycleRange i) j = if j = i then 0 else j + 1

Next tactic:
exact Subsingleton.elim (α := Fin 1) _ _
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`
  

Proof state:
case succ
n✝ : ℕ
i j : Fin (Nat.succ (Nat.succ n✝))
h : j ≤ i
⊢ (cycleRange i) j = if j = i then 0 else j + 1

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

Proof state:
n✝ : ℕ
i j : Fin (Nat.succ (Nat.succ n✝))
h : j ≤ i
⊢ j = castLE (_ : Nat.succ ↑i ≤ Nat.succ (Nat.succ n✝)) { val := ↑j, isLt := (_ : ↑j < Nat.succ ↑i) }

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

Proof state:
case succ
n✝ : ℕ
i j : Fin (Nat.succ (Nat.succ n✝))
h : j ≤ i
this : j = castLE (_ : Nat.succ ↑i ≤ Nat.succ (Nat.succ n✝)) { val := ↑j, isLt := (_ : ↑j < Nat.succ ↑i) }
⊢ (cycleRange i) j = if j = i then 0 else j + 1

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

Proof state:
case succ.h
n✝ : ℕ
i j : Fin (Nat.succ (Nat.succ n✝))
h : j ≤ i
this : j = castLE (_ : Nat.succ ↑i ≤ Nat.succ (Nat.succ n✝)) { val := ↑j, isLt := (_ : ↑j < Nat.succ ↑i) }
⊢ ↑((cycleRange i) j) = ↑(if j = i then 0 else j + 1)

Next tactic:
erw [this, cycleRange, ofLeftInverse'_eq_ofInjective, ←
    Function.Embedding.toEquivRange_eq_ofInjective, ← viaFintypeEmbedding,
    viaFintypeEmbedding_apply_image, castLEEmb_toEmbedding, Function.Embedding.coeFn_mk,
    coe_castLE, coe_finRotate]
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, castLEEmb_toEmbedding, Function.Embedding.coeFn_mk,
    coe_castLE, coe_finRotate]
  

Proof state:
case succ.h
n✝ : ℕ
i j : Fin (Nat.succ (Nat.succ n✝))
h : j ≤ i
this : j = castLE (_ : Nat.succ ↑i ≤ Nat.succ (Nat.succ n✝)) { val := ↑j, isLt := (_ : ↑j < Nat.succ ↑i) }
⊢ (if { val := ↑j, isLt := (_ : ↑j < Nat.succ ↑i) } = last ↑i then 0
    else ↑{ val := ↑j, isLt := (_ : ↑j < Nat.succ ↑i) } + 1) =
    ↑(if castLE (_ : Nat.succ ↑i ≤ Nat.succ (Nat.succ n✝)) { val := ↑j, isLt := (_ : ↑j < Nat.succ ↑i) } = i then 0
      else castLE (_ : Nat.succ ↑i ≤ Nat.succ (Nat.succ n✝)) { val := ↑j, isLt := (_ : ↑j < Nat.succ ↑i) } + 1)

Next tactic:
simp only [Fin.ext_iff, val_last, val_mk, val_zero, Fin.eta, castLE_mk]
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, castLEEmb_toEmbedding, Function.Embedding.coeFn_mk,
    coe_castLE, coe_finRotate]
  simp only [Fin.ext_iff, val_last, val_mk, val_zero, Fin.eta, castLE_mk]
  

Proof state:
case succ.h
n✝ : ℕ
i j : Fin (Nat.succ (Nat.succ n✝))
h : j ≤ i
this : j = castLE (_ : Nat.succ ↑i ≤ Nat.succ (Nat.succ n✝)) { val := ↑j, isLt := (_ : ↑j < Nat.succ ↑i) }
⊢ (if ↑j = ↑i then 0 else ↑j + 1) = ↑(if ↑j = ↑i then 0 else j + 1)

Next tactic:
split_ifs with heq
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, castLEEmb_toEmbedding, 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
  · 

Proof state:
case pos
n✝ : ℕ
i j : Fin (Nat.succ (Nat.succ n✝))
h : j ≤ i
this : j = castLE (_ : Nat.succ ↑i ≤ Nat.succ (Nat.succ n✝)) { val := ↑j, isLt := (_ : ↑j < Nat.succ ↑i) }
heq : ↑j = ↑i
⊢ 0 = ↑0

Next tactic:
rfl