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

Proof state:
case neg
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
⊢ ↑j + 1 = ↑(j + 1)

Next tactic:
rw [Fin.val_add_one_of_lt]
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
  · rfl
  · rw [Fin.val_add_one_of_lt]
    

Proof state:
case neg
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
⊢ j < last (n✝ + 1)

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

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:
rw [cycleRange_of_le h]
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]
  

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

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

Proof state:
case pos
n : ℕ
i j : Fin (Nat.succ n)
h : j ≤ i
h' : j = i
⊢ ↑0 = 0

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

Proof state:
case neg
n : ℕ
i j : Fin (Nat.succ n)
h : j ≤ i
h' : ¬j = i
⊢ ↑(j + 1) = ↑j + 1

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

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

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

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

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

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

Next tactic:
rw [cycleRange_of_le h.le, if_pos h]
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
  

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

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

Proof state:
case pos
n : ℕ
i j : Fin (Nat.succ n)
h₁ : j < i
⊢ (cycleRange i) j = j + 1

Next tactic:
exact cycleRange_of_lt h₁
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₁
  · 

Proof state:
case pos
n : ℕ
i j : Fin (Nat.succ n)
h₁ : ¬j < i
h₂ : j = i
⊢ (cycleRange i) j = 0

Next tactic:
exact cycleRange_of_eq h₂
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₂
  · 

Proof state:
case neg
n : ℕ
i j : Fin (Nat.succ n)
h₁ : ¬j < i
h₂ : ¬j = i
⊢ (cycleRange i) j = j

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

Proof state:
n : ℕ
⊢ cycleRange 0 = 1

Next tactic:
ext j
@[simp]
theorem cycleRange_zero (n : ℕ) : cycleRange (0 : Fin n.succ) = 1 := by
  ext j
  

Proof state:
case H.h
n : ℕ
j : Fin (Nat.succ n)
⊢ ↑((cycleRange 0) j) = ↑(1 j)

Next tactic:
refine' Fin.cases _ (fun j => _) j
@[simp]
theorem cycleRange_zero (n : ℕ) : cycleRange (0 : Fin n.succ) = 1 := by
  ext j
  refine' Fin.cases _ (fun j => _) j
  · 

Proof state:
case H.h.refine'_1
n : ℕ
j : Fin (Nat.succ n)
⊢ ↑((cycleRange 0) 0) = ↑(1 0)

Next tactic:
simp
@[simp]
theorem cycleRange_zero (n : ℕ) : cycleRange (0 : Fin n.succ) = 1 := by
  ext j
  refine' Fin.cases _ (fun j => _) j
  · simp
  · 

Proof state:
case H.h.refine'_2
n : ℕ
j✝ : Fin (Nat.succ n)
j : Fin n
⊢ ↑((cycleRange 0) (succ j)) = ↑(1 (succ j))

Next tactic:
rw [cycleRange_of_gt (Fin.succ_pos j), one_apply]
@[simp]
theorem cycleRange_last (n : ℕ) : cycleRange (last n) = finRotate (n + 1) := by
  

Proof state:
n : ℕ
⊢ cycleRange (last n) = finRotate (n + 1)

Next tactic:
ext i
@[simp]
theorem cycleRange_last (n : ℕ) : cycleRange (last n) = finRotate (n + 1) := by
  ext i
  

Proof state:
case H.h
n : ℕ
i : Fin (n + 1)
⊢ ↑((cycleRange (last n)) i) = ↑((finRotate (n + 1)) i)

Next tactic:
rw [coe_cycleRange_of_le (le_last _), coe_finRotate]
@[simp]
theorem cycleRange_zero' {n : ℕ} (h : 0 < n) : cycleRange ⟨0, h⟩ = 1 := by
  

Proof state:
n : ℕ
h : 0 < n
⊢ cycleRange { val := 0, isLt := h } = 1

Next tactic:
cases' n with n
@[simp]
theorem cycleRange_zero' {n : ℕ} (h : 0 < n) : cycleRange ⟨0, h⟩ = 1 := by
  cases' n with n
  · 

Proof state:
case zero
h : 0 < Nat.zero
⊢ cycleRange { val := 0, isLt := h } = 1

Next tactic:
cases h
@[simp]
theorem cycleRange_zero' {n : ℕ} (h : 0 < n) : cycleRange ⟨0, h⟩ = 1 := by
  cases' n with n
  · cases h
  

Proof state:
case succ
n : ℕ
h : 0 < Nat.succ n
⊢ cycleRange { val := 0, isLt := h } = 1

Next tactic:
exact cycleRange_zero n
@[simp]
theorem sign_cycleRange {n : ℕ} (i : Fin n) : Perm.sign (cycleRange i) = (-1) ^ (i : ℕ) := by
  

Proof state:
n : ℕ
i : Fin n
⊢ sign (cycleRange i) = (-1) ^ ↑i

Next tactic:
simp [cycleRange]
@[simp]
theorem succAbove_cycleRange {n : ℕ} (i j : Fin n) :
    i.succ.succAbove (i.cycleRange j) = swap 0 i.succ j.succ := by
  

Proof state:
n : ℕ
i j : Fin n
⊢ succAbove (succ i) ((cycleRange i) j) = (swap 0 (succ i)) (succ j)

Next tactic:
cases n
@[simp]
theorem succAbove_cycleRange {n : ℕ} (i j : Fin n) :
    i.succ.succAbove (i.cycleRange j) = swap 0 i.succ j.succ := by
  cases n
  · 

Proof state:
case zero
i j : Fin Nat.zero
⊢ succAbove (succ i) ((cycleRange i) j) = (swap 0 (succ i)) (succ j)

Next tactic:
rcases j with ⟨_, ⟨⟩⟩
@[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 ⟨_, ⟨⟩⟩
  

Proof state:
case succ
n✝ : ℕ
i j : Fin (Nat.succ n✝)
⊢ succAbove (succ i) ((cycleRange i) j) = (swap 0 (succ i)) (succ j)

Next tactic:
rcases lt_trichotomy j i with (hlt | heq | hgt)
@[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)
  · 

Proof state:
case succ.inl
n✝ : ℕ
i j : Fin (Nat.succ n✝)
hlt : j < i
⊢ succAbove (succ i) ((cycleRange i) j) = (swap 0 (succ i)) (succ j)

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

Proof state:
n✝ : ℕ
i j : Fin (Nat.succ n✝)
hlt : j < i
⊢ castSucc (j + 1) = succ j

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

Proof state:
case h
n✝ : ℕ
i j : Fin (Nat.succ n✝)
hlt : j < i
⊢ ↑(castSucc (j + 1)) = ↑(succ j)

Next tactic:
rw [coe_castSucc, val_succ, Fin.val_add_one_of_lt (lt_of_lt_of_le hlt i.le_last)]
@[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)]
    

Proof state:
case succ.inl
n✝ : ℕ
i j : Fin (Nat.succ n✝)
hlt : j < i
this : castSucc (j + 1) = succ j
⊢ succAbove (succ i) ((cycleRange i) j) = (swap 0 (succ i)) (succ j)

Next tactic:
rw [Fin.cycleRange_of_lt hlt, Fin.succAbove_below, this, swap_apply_of_ne_of_ne]
@[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_below, this, swap_apply_of_ne_of_ne]
    · 

Proof state:
case succ.inl.a
n✝ : ℕ
i j : Fin (Nat.succ n✝)
hlt : j < i
this : castSucc (j + 1) = succ j
⊢ succ j ≠ 0

Next tactic:
apply Fin.succ_ne_zero
@[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_below, this, swap_apply_of_ne_of_ne]
    · apply Fin.succ_ne_zero
    · 

Proof state:
case succ.inl.a
n✝ : ℕ
i j : Fin (Nat.succ n✝)
hlt : j < i
this : castSucc (j + 1) = succ j
⊢ succ j ≠ succ i

Next tactic:
exact (Fin.succ_injective _).ne hlt.ne
@[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_below, this, swap_apply_of_ne_of_ne]
    · apply Fin.succ_ne_zero
    · exact (Fin.succ_injective _).ne hlt.ne
    · 

Proof state:
case succ.inl.h
n✝ : ℕ
i j : Fin (Nat.succ n✝)
hlt : j < i
this : castSucc (j + 1) = succ j
⊢ castSucc (j + 1) < succ i

Next tactic:
rw [Fin.lt_iff_val_lt_val]
@[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_below, 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]
      

Proof state:
case succ.inl.h
n✝ : ℕ
i j : Fin (Nat.succ n✝)
hlt : j < i
this : castSucc (j + 1) = succ j
⊢ ↑(castSucc (j + 1)) < ↑(succ i)

Next tactic:
simpa [this] using hlt
@[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_below, 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
  · 

Proof state:
case succ.inr.inl
n✝ : ℕ
i j : Fin (Nat.succ n✝)
heq : j = i
⊢ succAbove (succ i) ((cycleRange i) j) = (swap 0 (succ i)) (succ j)

Next tactic:
rw [heq, Fin.cycleRange_self, Fin.succAbove_below, swap_apply_right, Fin.castSucc_zero]
@[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_below, 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_below, swap_apply_right, Fin.castSucc_zero]
    · 

Proof state:
case succ.inr.inl.h
n✝ : ℕ
i j : Fin (Nat.succ n✝)
heq : j = i
⊢ castSucc 0 < succ i

Next tactic:
rw [Fin.castSucc_zero]
@[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_below, 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_below, swap_apply_right, Fin.castSucc_zero]
    · rw [Fin.castSucc_zero]
      

Proof state:
case succ.inr.inl.h
n✝ : ℕ
i j : Fin (Nat.succ n✝)
heq : j = i
⊢ 0 < succ i

Next tactic:
apply Fin.succ_pos
@[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_below, 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_below, swap_apply_right, Fin.castSucc_zero]
    · rw [Fin.castSucc_zero]
      apply Fin.succ_pos
  · 

Proof state:
case succ.inr.inr
n✝ : ℕ
i j : Fin (Nat.succ n✝)
hgt : i < j
⊢ succAbove (succ i) ((cycleRange i) j) = (swap 0 (succ i)) (succ j)

Next tactic:
rw [Fin.cycleRange_of_gt hgt, Fin.succAbove_above, swap_apply_of_ne_of_ne]
@[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_below, 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_below, swap_apply_right, Fin.castSucc_zero]
    · rw [Fin.castSucc_zero]
      apply Fin.succ_pos
  · rw [Fin.cycleRange_of_gt hgt, Fin.succAbove_above, swap_apply_of_ne_of_ne]
    · 

Proof state:
case succ.inr.inr.a
n✝ : ℕ
i j : Fin (Nat.succ n✝)
hgt : i < j
⊢ succ j ≠ 0

Next tactic:
apply Fin.succ_ne_zero
@[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_below, 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_below, swap_apply_right, Fin.castSucc_zero]
    · rw [Fin.castSucc_zero]
      apply Fin.succ_pos
  · rw [Fin.cycleRange_of_gt hgt, Fin.succAbove_above, swap_apply_of_ne_of_ne]
    · apply Fin.succ_ne_zero
    · 

Proof state:
case succ.inr.inr.a
n✝ : ℕ
i j : Fin (Nat.succ n✝)
hgt : i < j
⊢ succ j ≠ succ i

Next tactic:
apply (Fin.succ_injective _).ne hgt.ne.symm
@[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_below, 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_below, swap_apply_right, Fin.castSucc_zero]
    · rw [Fin.castSucc_zero]
      apply Fin.succ_pos
  · rw [Fin.cycleRange_of_gt hgt, Fin.succAbove_above, swap_apply_of_ne_of_ne]
    · apply Fin.succ_ne_zero
    · apply (Fin.succ_injective _).ne hgt.ne.symm
    · 

Proof state:
case succ.inr.inr.h
n✝ : ℕ
i j : Fin (Nat.succ n✝)
hgt : i < j
⊢ succ i ≤ castSucc j

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

Proof state:
n : ℕ
i : Fin (n + 1)
j : Fin n
⊢ (cycleRange i) (succAbove i j) = succ j

Next tactic:
cases' lt_or_ge (castSucc j) i with h h
@[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
  · 

Proof state:
case inl
n : ℕ
i : Fin (n + 1)
j : Fin n
h : castSucc j < i
⊢ (cycleRange i) (succAbove i j) = succ j

Next tactic:
rw [Fin.succAbove_below _ _ h, Fin.cycleRange_of_lt h, Fin.coeSucc_eq_succ]
@[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_below _ _ h, Fin.cycleRange_of_lt h, Fin.coeSucc_eq_succ]
  · 

Proof state:
case inr
n : ℕ
i : Fin (n + 1)
j : Fin n
h : castSucc j ≥ i
⊢ (cycleRange i) (succAbove i j) = succ j

Next tactic:
rw [Fin.succAbove_above _ _ 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 

Proof state:
n : ℕ
i : Fin (n + 1)
⊢ (cycleRange i) ((cycleRange i).symm 0) = (cycleRange i) i

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

Proof state:
n : ℕ
i : Fin (n + 1)
j : Fin n
⊢ (cycleRange i) ((cycleRange i).symm (succ j)) = (cycleRange i) (succAbove i j)

Next tactic:
simp
theorem isCycle_cycleRange {n : ℕ} {i : Fin (n + 1)} (h0 : i ≠ 0) : IsCycle (cycleRange i) := by
  

Proof state:
n : ℕ
i : Fin (n + 1)
h0 : i ≠ 0
⊢ IsCycle (cycleRange i)

Next tactic:
cases' i with i hi
theorem isCycle_cycleRange {n : ℕ} {i : Fin (n + 1)} (h0 : i ≠ 0) : IsCycle (cycleRange i) := by
  cases' i with i hi
  

Proof state:
case mk
n i : ℕ
hi : i < n + 1
h0 : { val := i, isLt := hi } ≠ 0
⊢ IsCycle (cycleRange { val := i, isLt := hi })

Next tactic:
cases i
theorem isCycle_cycleRange {n : ℕ} {i : Fin (n + 1)} (h0 : i ≠ 0) : IsCycle (cycleRange i) := by
  cases' i with i hi
  cases i
  · 

Proof state:
case mk.zero
n : ℕ
hi : Nat.zero < n + 1
h0 : { val := Nat.zero, isLt := hi } ≠ 0
⊢ IsCycle (cycleRange { val := Nat.zero, isLt := hi })

Next tactic:
exact (h0 rfl).elim
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
  

Proof state:
case mk.succ
n n✝ : ℕ
hi : Nat.succ n✝ < n + 1
h0 : { val := Nat.succ n✝, isLt := hi } ≠ 0
⊢ IsCycle (cycleRange { val := Nat.succ n✝, isLt := hi })

Next tactic:
exact isCycle_finRotate.extendDomain _
@[simp]
theorem cycleType_cycleRange {n : ℕ} {i : Fin (n + 1)} (h0 : i ≠ 0) :
    cycleType (cycleRange i) = {(i + 1 : ℕ)} := by
  

Proof state:
n : ℕ
i : Fin (n + 1)
h0 : i ≠ 0
⊢ cycleType (cycleRange i) = {↑i + 1}

Next tactic:
cases' i with i hi
@[simp]
theorem cycleType_cycleRange {n : ℕ} {i : Fin (n + 1)} (h0 : i ≠ 0) :
    cycleType (cycleRange i) = {(i + 1 : ℕ)} := by
  cases' i with i hi
  

Proof state:
case mk
n i : ℕ
hi : i < n + 1
h0 : { val := i, isLt := hi } ≠ 0
⊢ cycleType (cycleRange { val := i, isLt := hi }) = {↑{ val := i, isLt := hi } + 1}

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

Proof state:
case mk.zero
n : ℕ
hi : Nat.zero < n + 1
h0 : { val := Nat.zero, isLt := hi } ≠ 0
⊢ cycleType (cycleRange { val := Nat.zero, isLt := hi }) = {↑{ val := Nat.zero, isLt := hi } + 1}

Next tactic:
exact (h0 rfl).elim
@[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
  

Proof state:
case mk.succ
n n✝ : ℕ
hi : Nat.succ n✝ < n + 1
h0 : { val := Nat.succ n✝, isLt := hi } ≠ 0
⊢ cycleType (cycleRange { val := Nat.succ n✝, isLt := hi }) = {↑{ val := Nat.succ n✝, isLt := hi } + 1}

Next tactic:
rw [cycleRange, cycleType_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]
  

Proof state:
case mk.succ
n n✝ : ℕ
hi : Nat.succ n✝ < n + 1
h0 : { val := Nat.succ n✝, isLt := hi } ≠ 0
⊢ cycleType (finRotate (↑{ val := Nat.succ n✝, isLt := hi } + 1)) = {↑{ val := Nat.succ n✝, isLt := hi } + 1}

Next tactic:
exact cycleType_finRotate
theorem isThreeCycle_cycleRange_two {n : ℕ} : IsThreeCycle (cycleRange 2 : Perm (Fin (n + 3))) := by
  

Proof state:
n : ℕ
⊢ IsThreeCycle (cycleRange 2)

Next tactic:
rw [IsThreeCycle, cycleType_cycleRange]