Theorem: toZ_iterate_pred_of_not_isMin
File: Mathlib/Order/SuccPred/LinearLocallyFinite.lean

tactic: cases' n with n n
state_before: ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
n : ℕ
hn : ¬IsMin ((pred^[n]) i0)
⊢ toZ i0 ((pred^[n]) i0) = -↑n

tactic: have : (pred^[n.succ]) i0 < i0 := by
  refine' lt_of_le_of_ne (pred_iterate_le _ _) fun h_pred_iterate_eq ↦ hn _
  have h_pred_eq_pred : (pred^[n.succ]) i0 = (pred^[0]) i0 := by
    rwa [Function.iterate_zero, id.def]
  exact isMin_iterate_pred_of_eq_of_ne h_pred_eq_pred (Nat.succ_ne_zero n)
state_before: case succ
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
n : ℕ
hn : ¬IsMin ((pred^[Nat.succ n]) i0)
⊢ toZ i0 ((pred^[Nat.succ n]) i0) = -↑(Nat.succ n)

tactic: let m := (-toZ i0 ((pred^[n.succ]) i0)).toNat
state_before: case succ
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
n : ℕ
hn : ¬IsMin ((pred^[Nat.succ n]) i0)
this : (pred^[Nat.succ n]) i0 < i0
⊢ toZ i0 ((pred^[Nat.succ n]) i0) = -↑(Nat.succ n)

tactic: have h_eq : (pred^[m]) i0 = (pred^[n.succ]) i0 := iterate_pred_toZ _ this
state_before: case succ
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
n : ℕ
hn : ¬IsMin ((pred^[Nat.succ n]) i0)
this : (pred^[Nat.succ n]) i0 < i0
m : ℕ := Int.toNat (-toZ i0 ((pred^[Nat.succ n]) i0))
⊢ toZ i0 ((pred^[Nat.succ n]) i0) = -↑(Nat.succ n)

tactic: by_cases hmn : m = n.succ
state_before: case succ
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
n : ℕ
hn : ¬IsMin ((pred^[Nat.succ n]) i0)
this : (pred^[Nat.succ n]) i0 < i0
m : ℕ := Int.toNat (-toZ i0 ((pred^[Nat.succ n]) i0))
h_eq : (pred^[m]) i0 = (pred^[Nat.succ n]) i0
⊢ toZ i0 ((pred^[Nat.succ n]) i0) = -↑(Nat.succ n)

tactic: simp only [Nat.zero_eq, Function.iterate_zero, id.def, toZ_of_eq, Nat.cast_zero, neg_zero]
state_before: case zero
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
hn : ¬IsMin ((pred^[Nat.zero]) i0)
⊢ toZ i0 ((pred^[Nat.zero]) i0) = -↑Nat.zero

tactic: refine' lt_of_le_of_ne (pred_iterate_le _ _) fun h_pred_iterate_eq ↦ hn _
state_before: ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
n : ℕ
hn : ¬IsMin ((pred^[Nat.succ n]) i0)
⊢ (pred^[Nat.succ n]) i0 < i0

tactic: have h_pred_eq_pred : (pred^[n.succ]) i0 = (pred^[0]) i0 := by
  rwa [Function.iterate_zero, id.def]
state_before: ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
n : ℕ
hn : ¬IsMin ((pred^[Nat.succ n]) i0)
h_pred_iterate_eq : (pred^[Nat.succ n]) i0 = i0
⊢ IsMin ((pred^[Nat.succ n]) i0)

tactic: exact isMin_iterate_pred_of_eq_of_ne h_pred_eq_pred (Nat.succ_ne_zero n)
state_before: ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
n : ℕ
hn : ¬IsMin ((pred^[Nat.succ n]) i0)
h_pred_iterate_eq : (pred^[Nat.succ n]) i0 = i0
h_pred_eq_pred : (pred^[Nat.succ n]) i0 = (pred^[0]) i0
⊢ IsMin ((pred^[Nat.succ n]) i0)

tactic: rwa [Function.iterate_zero, id.def]
state_before: ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
n : ℕ
hn : ¬IsMin ((pred^[Nat.succ n]) i0)
h_pred_iterate_eq : (pred^[Nat.succ n]) i0 = i0
⊢ (pred^[Nat.succ n]) i0 = (pred^[0]) i0

tactic: nth_rw 2 [← hmn]
state_before: case pos
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
n : ℕ
hn : ¬IsMin ((pred^[Nat.succ n]) i0)
this : (pred^[Nat.succ n]) i0 < i0
m : ℕ := Int.toNat (-toZ i0 ((pred^[Nat.succ n]) i0))
h_eq : (pred^[m]) i0 = (pred^[Nat.succ n]) i0
hmn : m = Nat.succ n
⊢ toZ i0 ((pred^[Nat.succ n]) i0) = -↑(Nat.succ n)

tactic: rw [Int.toNat_eq_max, toZ_of_lt this, max_eq_left, neg_neg]
state_before: case pos
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
n : ℕ
hn : ¬IsMin ((pred^[Nat.succ n]) i0)
this : (pred^[Nat.succ n]) i0 < i0
m : ℕ := Int.toNat (-toZ i0 ((pred^[Nat.succ n]) i0))
h_eq : (pred^[m]) i0 = (pred^[Nat.succ n]) i0
hmn : m = Nat.succ n
⊢ toZ i0 ((pred^[Nat.succ n]) i0) = -↑m

tactic: rw [neg_neg]
state_before: case pos
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
n : ℕ
hn : ¬IsMin ((pred^[Nat.succ n]) i0)
this : (pred^[Nat.succ n]) i0 < i0
m : ℕ := Int.toNat (-toZ i0 ((pred^[Nat.succ n]) i0))
h_eq : (pred^[m]) i0 = (pred^[Nat.succ n]) i0
hmn : m = Nat.succ n
⊢ 0 ≤ - -↑(Nat.find (_ : ∃ n_1, (pred^[n_1]) i0 = (pred^[Nat.succ n]) i0))

tactic: exact Nat.cast_nonneg _
state_before: case pos
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
n : ℕ
hn : ¬IsMin ((pred^[Nat.succ n]) i0)
this : (pred^[Nat.succ n]) i0 < i0
m : ℕ := Int.toNat (-toZ i0 ((pred^[Nat.succ n]) i0))
h_eq : (pred^[m]) i0 = (pred^[Nat.succ n]) i0
hmn : m = Nat.succ n
⊢ 0 ≤ ↑(Nat.find (_ : ∃ n_1, (pred^[n_1]) i0 = (pred^[Nat.succ n]) i0))

tactic: suffices : IsMin ((pred^[n.succ]) i0)
state_before: case neg
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
n : ℕ
hn : ¬IsMin ((pred^[Nat.succ n]) i0)
this : (pred^[Nat.succ n]) i0 < i0
m : ℕ := Int.toNat (-toZ i0 ((pred^[Nat.succ n]) i0))
h_eq : (pred^[m]) i0 = (pred^[Nat.succ n]) i0
hmn : ¬m = Nat.succ n
⊢ toZ i0 ((pred^[Nat.succ n]) i0) = -↑(Nat.succ n)

tactic: exact absurd this hn
state_before: case neg
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
n : ℕ
hn : ¬IsMin ((pred^[Nat.succ n]) i0)
this✝ : (pred^[Nat.succ n]) i0 < i0
m : ℕ := Int.toNat (-toZ i0 ((pred^[Nat.succ n]) i0))
h_eq : (pred^[m]) i0 = (pred^[Nat.succ n]) i0
hmn : ¬m = Nat.succ n
this : IsMin ((pred^[Nat.succ n]) i0)
⊢ toZ i0 ((pred^[Nat.succ n]) i0) = -↑(Nat.succ n)

case this
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
n : ℕ
hn : ¬IsMin ((pred^[Nat.succ n]) i0)
this : (pred^[Nat.succ n]) i0 < i0
m : ℕ := Int.toNat (-toZ i0 ((pred^[Nat.succ n]) i0))
h_eq : (pred^[m]) i0 = (pred^[Nat.succ n]) i0
hmn : ¬m = Nat.succ n
⊢ IsMin ((pred^[Nat.succ n]) i0)

tactic: exact isMin_iterate_pred_of_eq_of_ne h_eq.symm (Ne.symm hmn)
state_before: case this
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
n : ℕ
hn : ¬IsMin ((pred^[Nat.succ n]) i0)
this : (pred^[Nat.succ n]) i0 < i0
m : ℕ := Int.toNat (-toZ i0 ((pred^[Nat.succ n]) i0))
h_eq : (pred^[m]) i0 = (pred^[Nat.succ n]) i0
hmn : ¬m = Nat.succ n
⊢ IsMin ((pred^[Nat.succ n]) i0)