l3lab/ntp-mathlib huggingface dataset:
instance (priority := 100) LinearOrder.isPredArchimedean_of_isSuccArchimedean [SuccOrder ι]
    [PredOrder ι] [IsSuccArchimedean ι] : IsPredArchimedean ι where
  exists_pred_iterate_of_le := by
    intro i j hij
    

Proof state:
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : PredOrder ι
inst✝ : IsSuccArchimedean ι
i j : ι
hij : i ≤ j
⊢ ∃ n, pred^[n] j = i

Next tactic:
have h_exists := exists_succ_iterate_of_le hij
instance (priority := 100) LinearOrder.isPredArchimedean_of_isSuccArchimedean [SuccOrder ι]
    [PredOrder ι] [IsSuccArchimedean ι] : IsPredArchimedean ι where
  exists_pred_iterate_of_le := by
    intro i j hij
    have h_exists := exists_succ_iterate_of_le hij
    

Proof state:
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : PredOrder ι
inst✝ : IsSuccArchimedean ι
i j : ι
hij : i ≤ j
h_exists : ∃ n, succ^[n] i = j
⊢ ∃ n, pred^[n] j = i

Next tactic:
obtain ⟨n, hn_eq, hn_lt_ne⟩ : ∃ n, succ^[n] i = j ∧ ∀ m < n, succ^[m] i ≠ j
instance (priority := 100) LinearOrder.isPredArchimedean_of_isSuccArchimedean [SuccOrder ι]
    [PredOrder ι] [IsSuccArchimedean ι] : IsPredArchimedean ι where
  exists_pred_iterate_of_le := by
    intro i j hij
    have h_exists := exists_succ_iterate_of_le hij
    obtain ⟨n, hn_eq, hn_lt_ne⟩ : ∃ n, succ^[n] i = j ∧ ∀ m < n, succ^[m] i ≠ j
    

Proof state:
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : PredOrder ι
inst✝ : IsSuccArchimedean ι
i j : ι
hij : i ≤ j
h_exists : ∃ n, succ^[n] i = j
⊢ ∃ n, succ^[n] i = j ∧ ∀ m < n, succ^[m] i ≠ j
case intro.intro
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : PredOrder ι
inst✝ : IsSuccArchimedean ι
i j : ι
hij : i ≤ j
h_exists : ∃ n, succ^[n] i = j
n : ℕ
hn_eq : succ^[n] i = j
hn_lt_ne : ∀ m < n, succ^[m] i ≠ j
⊢ ∃ n, pred^[n] j = i

Next tactic:
exact ⟨Nat.find h_exists, Nat.find_spec h_exists, fun m hmn ↦ Nat.find_min h_exists hmn⟩
instance (priority := 100) LinearOrder.isPredArchimedean_of_isSuccArchimedean [SuccOrder ι]
    [PredOrder ι] [IsSuccArchimedean ι] : IsPredArchimedean ι where
  exists_pred_iterate_of_le := by
    intro i j hij
    have h_exists := exists_succ_iterate_of_le hij
    obtain ⟨n, hn_eq, hn_lt_ne⟩ : ∃ n, succ^[n] i = j ∧ ∀ m < n, succ^[m] i ≠ j
    exact ⟨Nat.find h_exists, Nat.find_spec h_exists, fun m hmn ↦ Nat.find_min h_exists hmn⟩
    

Proof state:
case intro.intro
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : PredOrder ι
inst✝ : IsSuccArchimedean ι
i j : ι
hij : i ≤ j
h_exists : ∃ n, succ^[n] i = j
n : ℕ
hn_eq : succ^[n] i = j
hn_lt_ne : ∀ m < n, succ^[m] i ≠ j
⊢ ∃ n, pred^[n] j = i

Next tactic:
refine' ⟨n, _⟩
instance (priority := 100) LinearOrder.isPredArchimedean_of_isSuccArchimedean [SuccOrder ι]
    [PredOrder ι] [IsSuccArchimedean ι] : IsPredArchimedean ι where
  exists_pred_iterate_of_le := by
    intro i j hij
    have h_exists := exists_succ_iterate_of_le hij
    obtain ⟨n, hn_eq, hn_lt_ne⟩ : ∃ n, succ^[n] i = j ∧ ∀ m < n, succ^[m] i ≠ j
    exact ⟨Nat.find h_exists, Nat.find_spec h_exists, fun m hmn ↦ Nat.find_min h_exists hmn⟩
    refine' ⟨n, _⟩
    

Proof state:
case intro.intro
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : PredOrder ι
inst✝ : IsSuccArchimedean ι
i j : ι
hij : i ≤ j
h_exists : ∃ n, succ^[n] i = j
n : ℕ
hn_eq : succ^[n] i = j
hn_lt_ne : ∀ m < n, succ^[m] i ≠ j
⊢ pred^[n] j = i

Next tactic:
rw [← hn_eq]
instance (priority := 100) LinearOrder.isPredArchimedean_of_isSuccArchimedean [SuccOrder ι]
    [PredOrder ι] [IsSuccArchimedean ι] : IsPredArchimedean ι where
  exists_pred_iterate_of_le := by
    intro i j hij
    have h_exists := exists_succ_iterate_of_le hij
    obtain ⟨n, hn_eq, hn_lt_ne⟩ : ∃ n, succ^[n] i = j ∧ ∀ m < n, succ^[m] i ≠ j
    exact ⟨Nat.find h_exists, Nat.find_spec h_exists, fun m hmn ↦ Nat.find_min h_exists hmn⟩
    refine' ⟨n, _⟩
    rw [← hn_eq]
    

Proof state:
case intro.intro
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : PredOrder ι
inst✝ : IsSuccArchimedean ι
i j : ι
hij : i ≤ j
h_exists : ∃ n, succ^[n] i = j
n : ℕ
hn_eq : succ^[n] i = j
hn_lt_ne : ∀ m < n, succ^[m] i ≠ j
⊢ pred^[n] (succ^[n] i) = i

Next tactic:
induction' n with n
instance (priority := 100) LinearOrder.isPredArchimedean_of_isSuccArchimedean [SuccOrder ι]
    [PredOrder ι] [IsSuccArchimedean ι] : IsPredArchimedean ι where
  exists_pred_iterate_of_le := by
    intro i j hij
    have h_exists := exists_succ_iterate_of_le hij
    obtain ⟨n, hn_eq, hn_lt_ne⟩ : ∃ n, succ^[n] i = j ∧ ∀ m < n, succ^[m] i ≠ j
    exact ⟨Nat.find h_exists, Nat.find_spec h_exists, fun m hmn ↦ Nat.find_min h_exists hmn⟩
    refine' ⟨n, _⟩
    rw [← hn_eq]
    induction' n with n
    · 

Proof state:
case intro.intro.zero
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : PredOrder ι
inst✝ : IsSuccArchimedean ι
i j : ι
hij : i ≤ j
h_exists : ∃ n, succ^[n] i = j
hn_eq : succ^[Nat.zero] i = j
hn_lt_ne : ∀ m < Nat.zero, succ^[m] i ≠ j
⊢ pred^[Nat.zero] (succ^[Nat.zero] i) = i

Next tactic:
simp only [Nat.zero_eq, Function.iterate_zero, id.def]
instance (priority := 100) LinearOrder.isPredArchimedean_of_isSuccArchimedean [SuccOrder ι]
    [PredOrder ι] [IsSuccArchimedean ι] : IsPredArchimedean ι where
  exists_pred_iterate_of_le := by
    intro i j hij
    have h_exists := exists_succ_iterate_of_le hij
    obtain ⟨n, hn_eq, hn_lt_ne⟩ : ∃ n, succ^[n] i = j ∧ ∀ m < n, succ^[m] i ≠ j
    exact ⟨Nat.find h_exists, Nat.find_spec h_exists, fun m hmn ↦ Nat.find_min h_exists hmn⟩
    refine' ⟨n, _⟩
    rw [← hn_eq]
    induction' n with n
    · simp only [Nat.zero_eq, Function.iterate_zero, id.def]
    · 

Proof state:
case intro.intro.succ
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : PredOrder ι
inst✝ : IsSuccArchimedean ι
i j : ι
hij : i ≤ j
h_exists : ∃ n, succ^[n] i = j
n : ℕ
n_ih✝ : succ^[n] i = j → (∀ m < n, succ^[m] i ≠ j) → pred^[n] (succ^[n] i) = i
hn_eq : succ^[Nat.succ n] i = j
hn_lt_ne : ∀ m < Nat.succ n, succ^[m] i ≠ j
⊢ pred^[Nat.succ n] (succ^[Nat.succ n] i) = i

Next tactic:
rw [pred_succ_iterate_of_not_isMax]
instance (priority := 100) LinearOrder.isPredArchimedean_of_isSuccArchimedean [SuccOrder ι]
    [PredOrder ι] [IsSuccArchimedean ι] : IsPredArchimedean ι where
  exists_pred_iterate_of_le := by
    intro i j hij
    have h_exists := exists_succ_iterate_of_le hij
    obtain ⟨n, hn_eq, hn_lt_ne⟩ : ∃ n, succ^[n] i = j ∧ ∀ m < n, succ^[m] i ≠ j
    exact ⟨Nat.find h_exists, Nat.find_spec h_exists, fun m hmn ↦ Nat.find_min h_exists hmn⟩
    refine' ⟨n, _⟩
    rw [← hn_eq]
    induction' n with n
    · simp only [Nat.zero_eq, Function.iterate_zero, id.def]
    · rw [pred_succ_iterate_of_not_isMax]
      

Proof state:
case intro.intro.succ.hin
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : PredOrder ι
inst✝ : IsSuccArchimedean ι
i j : ι
hij : i ≤ j
h_exists : ∃ n, succ^[n] i = j
n : ℕ
n_ih✝ : succ^[n] i = j → (∀ m < n, succ^[m] i ≠ j) → pred^[n] (succ^[n] i) = i
hn_eq : succ^[Nat.succ n] i = j
hn_lt_ne : ∀ m < Nat.succ n, succ^[m] i ≠ j
⊢ ¬IsMax (succ^[Nat.succ n - 1] i)

Next tactic:
rw [Nat.succ_sub_succ_eq_sub, tsub_zero]
instance (priority := 100) LinearOrder.isPredArchimedean_of_isSuccArchimedean [SuccOrder ι]
    [PredOrder ι] [IsSuccArchimedean ι] : IsPredArchimedean ι where
  exists_pred_iterate_of_le := by
    intro i j hij
    have h_exists := exists_succ_iterate_of_le hij
    obtain ⟨n, hn_eq, hn_lt_ne⟩ : ∃ n, succ^[n] i = j ∧ ∀ m < n, succ^[m] i ≠ j
    exact ⟨Nat.find h_exists, Nat.find_spec h_exists, fun m hmn ↦ Nat.find_min h_exists hmn⟩
    refine' ⟨n, _⟩
    rw [← hn_eq]
    induction' n with n
    · simp only [Nat.zero_eq, Function.iterate_zero, id.def]
    · rw [pred_succ_iterate_of_not_isMax]
      rw [Nat.succ_sub_succ_eq_sub, tsub_zero]
      

Proof state:
case intro.intro.succ.hin
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : PredOrder ι
inst✝ : IsSuccArchimedean ι
i j : ι
hij : i ≤ j
h_exists : ∃ n, succ^[n] i = j
n : ℕ
n_ih✝ : succ^[n] i = j → (∀ m < n, succ^[m] i ≠ j) → pred^[n] (succ^[n] i) = i
hn_eq : succ^[Nat.succ n] i = j
hn_lt_ne : ∀ m < Nat.succ n, succ^[m] i ≠ j
⊢ ¬IsMax (succ^[n] i)

Next tactic:
suffices succ^[n] i < succ^[n.succ] i from not_isMax_of_lt this
instance (priority := 100) LinearOrder.isPredArchimedean_of_isSuccArchimedean [SuccOrder ι]
    [PredOrder ι] [IsSuccArchimedean ι] : IsPredArchimedean ι where
  exists_pred_iterate_of_le := by
    intro i j hij
    have h_exists := exists_succ_iterate_of_le hij
    obtain ⟨n, hn_eq, hn_lt_ne⟩ : ∃ n, succ^[n] i = j ∧ ∀ m < n, succ^[m] i ≠ j
    exact ⟨Nat.find h_exists, Nat.find_spec h_exists, fun m hmn ↦ Nat.find_min h_exists hmn⟩
    refine' ⟨n, _⟩
    rw [← hn_eq]
    induction' n with n
    · simp only [Nat.zero_eq, Function.iterate_zero, id.def]
    · rw [pred_succ_iterate_of_not_isMax]
      rw [Nat.succ_sub_succ_eq_sub, tsub_zero]
      suffices succ^[n] i < succ^[n.succ] i from not_isMax_of_lt this
      

Proof state:
case intro.intro.succ.hin
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : PredOrder ι
inst✝ : IsSuccArchimedean ι
i j : ι
hij : i ≤ j
h_exists : ∃ n, succ^[n] i = j
n : ℕ
n_ih✝ : succ^[n] i = j → (∀ m < n, succ^[m] i ≠ j) → pred^[n] (succ^[n] i) = i
hn_eq : succ^[Nat.succ n] i = j
hn_lt_ne : ∀ m < Nat.succ n, succ^[m] i ≠ j
⊢ succ^[n] i < succ^[Nat.succ n] i

Next tactic:
refine' lt_of_le_of_ne _ _
instance (priority := 100) LinearOrder.isPredArchimedean_of_isSuccArchimedean [SuccOrder ι]
    [PredOrder ι] [IsSuccArchimedean ι] : IsPredArchimedean ι where
  exists_pred_iterate_of_le := by
    intro i j hij
    have h_exists := exists_succ_iterate_of_le hij
    obtain ⟨n, hn_eq, hn_lt_ne⟩ : ∃ n, succ^[n] i = j ∧ ∀ m < n, succ^[m] i ≠ j
    exact ⟨Nat.find h_exists, Nat.find_spec h_exists, fun m hmn ↦ Nat.find_min h_exists hmn⟩
    refine' ⟨n, _⟩
    rw [← hn_eq]
    induction' n with n
    · simp only [Nat.zero_eq, Function.iterate_zero, id.def]
    · rw [pred_succ_iterate_of_not_isMax]
      rw [Nat.succ_sub_succ_eq_sub, tsub_zero]
      suffices succ^[n] i < succ^[n.succ] i from not_isMax_of_lt this
      refine' lt_of_le_of_ne _ _
      · 

Proof state:
case intro.intro.succ.hin.refine'_1
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : PredOrder ι
inst✝ : IsSuccArchimedean ι
i j : ι
hij : i ≤ j
h_exists : ∃ n, succ^[n] i = j
n : ℕ
n_ih✝ : succ^[n] i = j → (∀ m < n, succ^[m] i ≠ j) → pred^[n] (succ^[n] i) = i
hn_eq : succ^[Nat.succ n] i = j
hn_lt_ne : ∀ m < Nat.succ n, succ^[m] i ≠ j
⊢ succ^[n] i ≤ succ^[Nat.succ n] i

Next tactic:
rw [Function.iterate_succ']
instance (priority := 100) LinearOrder.isPredArchimedean_of_isSuccArchimedean [SuccOrder ι]
    [PredOrder ι] [IsSuccArchimedean ι] : IsPredArchimedean ι where
  exists_pred_iterate_of_le := by
    intro i j hij
    have h_exists := exists_succ_iterate_of_le hij
    obtain ⟨n, hn_eq, hn_lt_ne⟩ : ∃ n, succ^[n] i = j ∧ ∀ m < n, succ^[m] i ≠ j
    exact ⟨Nat.find h_exists, Nat.find_spec h_exists, fun m hmn ↦ Nat.find_min h_exists hmn⟩
    refine' ⟨n, _⟩
    rw [← hn_eq]
    induction' n with n
    · simp only [Nat.zero_eq, Function.iterate_zero, id.def]
    · rw [pred_succ_iterate_of_not_isMax]
      rw [Nat.succ_sub_succ_eq_sub, tsub_zero]
      suffices succ^[n] i < succ^[n.succ] i from not_isMax_of_lt this
      refine' lt_of_le_of_ne _ _
      · rw [Function.iterate_succ']
        

Proof state:
case intro.intro.succ.hin.refine'_1
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : PredOrder ι
inst✝ : IsSuccArchimedean ι
i j : ι
hij : i ≤ j
h_exists : ∃ n, succ^[n] i = j
n : ℕ
n_ih✝ : succ^[n] i = j → (∀ m < n, succ^[m] i ≠ j) → pred^[n] (succ^[n] i) = i
hn_eq : succ^[Nat.succ n] i = j
hn_lt_ne : ∀ m < Nat.succ n, succ^[m] i ≠ j
⊢ succ^[n] i ≤ (succ ∘ succ^[n]) i

Next tactic:
exact le_succ _
instance (priority := 100) LinearOrder.isPredArchimedean_of_isSuccArchimedean [SuccOrder ι]
    [PredOrder ι] [IsSuccArchimedean ι] : IsPredArchimedean ι where
  exists_pred_iterate_of_le := by
    intro i j hij
    have h_exists := exists_succ_iterate_of_le hij
    obtain ⟨n, hn_eq, hn_lt_ne⟩ : ∃ n, succ^[n] i = j ∧ ∀ m < n, succ^[m] i ≠ j
    exact ⟨Nat.find h_exists, Nat.find_spec h_exists, fun m hmn ↦ Nat.find_min h_exists hmn⟩
    refine' ⟨n, _⟩
    rw [← hn_eq]
    induction' n with n
    · simp only [Nat.zero_eq, Function.iterate_zero, id.def]
    · rw [pred_succ_iterate_of_not_isMax]
      rw [Nat.succ_sub_succ_eq_sub, tsub_zero]
      suffices succ^[n] i < succ^[n.succ] i from not_isMax_of_lt this
      refine' lt_of_le_of_ne _ _
      · rw [Function.iterate_succ']
        exact le_succ _
      · 

Proof state:
case intro.intro.succ.hin.refine'_2
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : PredOrder ι
inst✝ : IsSuccArchimedean ι
i j : ι
hij : i ≤ j
h_exists : ∃ n, succ^[n] i = j
n : ℕ
n_ih✝ : succ^[n] i = j → (∀ m < n, succ^[m] i ≠ j) → pred^[n] (succ^[n] i) = i
hn_eq : succ^[Nat.succ n] i = j
hn_lt_ne : ∀ m < Nat.succ n, succ^[m] i ≠ j
⊢ succ^[n] i ≠ succ^[Nat.succ n] i

Next tactic:
rw [hn_eq]
instance (priority := 100) LinearOrder.isPredArchimedean_of_isSuccArchimedean [SuccOrder ι]
    [PredOrder ι] [IsSuccArchimedean ι] : IsPredArchimedean ι where
  exists_pred_iterate_of_le := by
    intro i j hij
    have h_exists := exists_succ_iterate_of_le hij
    obtain ⟨n, hn_eq, hn_lt_ne⟩ : ∃ n, succ^[n] i = j ∧ ∀ m < n, succ^[m] i ≠ j
    exact ⟨Nat.find h_exists, Nat.find_spec h_exists, fun m hmn ↦ Nat.find_min h_exists hmn⟩
    refine' ⟨n, _⟩
    rw [← hn_eq]
    induction' n with n
    · simp only [Nat.zero_eq, Function.iterate_zero, id.def]
    · rw [pred_succ_iterate_of_not_isMax]
      rw [Nat.succ_sub_succ_eq_sub, tsub_zero]
      suffices succ^[n] i < succ^[n.succ] i from not_isMax_of_lt this
      refine' lt_of_le_of_ne _ _
      · rw [Function.iterate_succ']
        exact le_succ _
      · rw [hn_eq]
        

Proof state:
case intro.intro.succ.hin.refine'_2
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : PredOrder ι
inst✝ : IsSuccArchimedean ι
i j : ι
hij : i ≤ j
h_exists : ∃ n, succ^[n] i = j
n : ℕ
n_ih✝ : succ^[n] i = j → (∀ m < n, succ^[m] i ≠ j) → pred^[n] (succ^[n] i) = i
hn_eq : succ^[Nat.succ n] i = j
hn_lt_ne : ∀ m < Nat.succ n, succ^[m] i ≠ j
⊢ succ^[n] i ≠ j

Next tactic:
exact hn_lt_ne _ (Nat.lt_succ_self n)
@[simp]
theorem toZ_of_eq : toZ i0 i0 = 0 := by
  

Proof state:
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
⊢ toZ i0 i0 = 0

Next tactic:
rw [toZ_of_ge le_rfl]
@[simp]
theorem toZ_of_eq : toZ i0 i0 = 0 := by
  rw [toZ_of_ge le_rfl]
  

Proof state:
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
⊢ ↑(Nat.find (_ : ∃ n, succ^[n] i0 = i0)) = 0

Next tactic:
norm_cast
@[simp]
theorem toZ_of_eq : toZ i0 i0 = 0 := by
  rw [toZ_of_ge le_rfl]
  norm_cast
  

Proof state:
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
⊢ Nat.find (_ : ∃ n, succ^[n] i0 = i0) = 0

Next tactic:
refine' le_antisymm (Nat.find_le _) (zero_le _)
@[simp]
theorem toZ_of_eq : toZ i0 i0 = 0 := by
  rw [toZ_of_ge le_rfl]
  norm_cast
  refine' le_antisymm (Nat.find_le _) (zero_le _)
  

Proof state:
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
⊢ succ^[0] i0 = i0

Next tactic:
rw [Function.iterate_zero, id.def]
theorem iterate_succ_toZ (i : ι) (hi : i0 ≤ i) : succ^[(toZ i0 i).toNat] i0 = i := by
  

Proof state:
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i✝ i : ι
hi : i0 ≤ i
⊢ succ^[Int.toNat (toZ i0 i)] i0 = i

Next tactic:
rw [toZ_of_ge hi, Int.toNat_coe_nat]
theorem iterate_succ_toZ (i : ι) (hi : i0 ≤ i) : succ^[(toZ i0 i).toNat] i0 = i := by
  rw [toZ_of_ge hi, Int.toNat_coe_nat]
  

Proof state:
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i✝ i : ι
hi : i0 ≤ i
⊢ succ^[Nat.find (_ : ∃ n, succ^[n] i0 = i)] i0 = i

Next tactic:
exact Nat.find_spec (exists_succ_iterate_of_le hi)
theorem iterate_pred_toZ (i : ι) (hi : i < i0) : pred^[(-toZ i0 i).toNat] i0 = i := by
  

Proof state:
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i✝ i : ι
hi : i < i0
⊢ pred^[Int.toNat (-toZ i0 i)] i0 = i

Next tactic:
rw [toZ_of_lt hi, neg_neg, Int.toNat_coe_nat]
theorem iterate_pred_toZ (i : ι) (hi : i < i0) : pred^[(-toZ i0 i).toNat] i0 = i := by
  rw [toZ_of_lt hi, neg_neg, Int.toNat_coe_nat]
  

Proof state:
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i✝ i : ι
hi : i < i0
⊢ pred^[Nat.find (_ : ∃ n, pred^[n] i0 = i)] i0 = i

Next tactic:
exact Nat.find_spec (exists_pred_iterate_of_le hi.le)
theorem toZ_nonneg (hi : i0 ≤ i) : 0 ≤ toZ i0 i := by
  

Proof state:
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
hi : i0 ≤ i
⊢ 0 ≤ toZ i0 i

Next tactic:
rw [toZ_of_ge hi]
theorem toZ_nonneg (hi : i0 ≤ i) : 0 ≤ toZ i0 i := by
  rw [toZ_of_ge hi]
  

Proof state:
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
hi : i0 ≤ i
⊢ 0 ≤ ↑(Nat.find (_ : ∃ n, succ^[n] i0 = i))

Next tactic:
exact Nat.cast_nonneg _
theorem toZ_neg (hi : i < i0) : toZ i0 i < 0 := by
  

Proof state:
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
hi : i < i0
⊢ toZ i0 i < 0

Next tactic:
refine' lt_of_le_of_ne _ _
theorem toZ_neg (hi : i < i0) : toZ i0 i < 0 := by
  refine' lt_of_le_of_ne _ _
  · 

Proof state:
case refine'_1
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
hi : i < i0
⊢ toZ i0 i ≤ 0

Next tactic:
rw [toZ_of_lt hi, neg_nonpos]
theorem toZ_neg (hi : i < i0) : toZ i0 i < 0 := by
  refine' lt_of_le_of_ne _ _
  · rw [toZ_of_lt hi, neg_nonpos]
    

Proof state:
case refine'_1
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
hi : i < i0
⊢ 0 ≤ ↑(Nat.find (_ : ∃ n, pred^[n] i0 = i))

Next tactic:
exact Nat.cast_nonneg _
theorem toZ_neg (hi : i < i0) : toZ i0 i < 0 := by
  refine' lt_of_le_of_ne _ _
  · rw [toZ_of_lt hi, neg_nonpos]
    exact Nat.cast_nonneg _
  · 

Proof state:
case refine'_2
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
hi : i < i0
⊢ toZ i0 i ≠ 0

Next tactic:
by_contra h
theorem toZ_neg (hi : i < i0) : toZ i0 i < 0 := by
  refine' lt_of_le_of_ne _ _
  · rw [toZ_of_lt hi, neg_nonpos]
    exact Nat.cast_nonneg _
  · by_contra h
    

Proof state:
case refine'_2
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
hi : i < i0
h : toZ i0 i = 0
⊢ False

Next tactic:
have h_eq := iterate_pred_toZ i hi
theorem toZ_neg (hi : i < i0) : toZ i0 i < 0 := by
  refine' lt_of_le_of_ne _ _
  · rw [toZ_of_lt hi, neg_nonpos]
    exact Nat.cast_nonneg _
  · by_contra h
    have h_eq := iterate_pred_toZ i hi
    

Proof state:
case refine'_2
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
hi : i < i0
h : toZ i0 i = 0
h_eq : pred^[Int.toNat (-toZ i0 i)] i0 = i
⊢ False

Next tactic:
rw [← h_eq, h] at hi
theorem toZ_neg (hi : i < i0) : toZ i0 i < 0 := by
  refine' lt_of_le_of_ne _ _
  · rw [toZ_of_lt hi, neg_nonpos]
    exact Nat.cast_nonneg _
  · by_contra h
    have h_eq := iterate_pred_toZ i hi
    rw [← h_eq, h] at hi
    

Proof state:
case refine'_2
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
hi : pred^[Int.toNat (-0)] i0 < i0
h : toZ i0 i = 0
h_eq : pred^[Int.toNat (-toZ i0 i)] i0 = i
⊢ False

Next tactic:
simp only [neg_zero, Int.toNat_zero, Function.iterate_zero, id.def, lt_self_iff_false] at hi
theorem toZ_iterate_succ_le (n : ℕ) : toZ i0 (succ^[n] i0) ≤ n := by
  

Proof state:
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
n : ℕ
⊢ toZ i0 (succ^[n] i0) ≤ ↑n

Next tactic:
rw [toZ_of_ge (le_succ_iterate _ _)]
theorem toZ_iterate_succ_le (n : ℕ) : toZ i0 (succ^[n] i0) ≤ n := by
  rw [toZ_of_ge (le_succ_iterate _ _)]
  

Proof state:
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
n : ℕ
⊢ ↑(Nat.find (_ : ∃ n_1, succ^[n_1] i0 = succ^[n] i0)) ≤ ↑n

Next tactic:
norm_cast
theorem toZ_iterate_succ_le (n : ℕ) : toZ i0 (succ^[n] i0) ≤ n := by
  rw [toZ_of_ge (le_succ_iterate _ _)]
  norm_cast
  

Proof state:
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
n : ℕ
⊢ Nat.find (_ : ∃ n_1, succ^[n_1] i0 = succ^[n] i0) ≤ n

Next tactic:
exact Nat.find_min' _ rfl
theorem toZ_iterate_pred_ge (n : ℕ) : -(n : ℤ) ≤ toZ i0 (pred^[n] i0) := by
  

Proof state:
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
n : ℕ
⊢ -↑n ≤ toZ i0 (pred^[n] i0)

Next tactic:
rcases le_or_lt i0 (pred^[n] i0) with h | h
theorem toZ_iterate_pred_ge (n : ℕ) : -(n : ℤ) ≤ toZ i0 (pred^[n] i0) := by
  rcases le_or_lt i0 (pred^[n] i0) with h | h
  · 

Proof state:
case inl
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
n : ℕ
h : i0 ≤ pred^[n] i0
⊢ -↑n ≤ toZ i0 (pred^[n] i0)

Next tactic:
have h_eq : pred^[n] i0 = i0 := le_antisymm (pred_iterate_le _ _) h
theorem toZ_iterate_pred_ge (n : ℕ) : -(n : ℤ) ≤ toZ i0 (pred^[n] i0) := by
  rcases le_or_lt i0 (pred^[n] i0) with h | h
  · have h_eq : pred^[n] i0 = i0 := le_antisymm (pred_iterate_le _ _) h
    

Proof state:
case inl
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
n : ℕ
h : i0 ≤ pred^[n] i0
h_eq : pred^[n] i0 = i0
⊢ -↑n ≤ toZ i0 (pred^[n] i0)

Next tactic:
rw [h_eq, toZ_of_eq]
theorem toZ_iterate_pred_ge (n : ℕ) : -(n : ℤ) ≤ toZ i0 (pred^[n] i0) := by
  rcases le_or_lt i0 (pred^[n] i0) with h | h
  · have h_eq : pred^[n] i0 = i0 := le_antisymm (pred_iterate_le _ _) h
    rw [h_eq, toZ_of_eq]
    

Proof state:
case inl
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
n : ℕ
h : i0 ≤ pred^[n] i0
h_eq : pred^[n] i0 = i0
⊢ -↑n ≤ 0

Next tactic:
simp only [Right.neg_nonpos_iff, Nat.cast_nonneg]
theorem toZ_iterate_pred_ge (n : ℕ) : -(n : ℤ) ≤ toZ i0 (pred^[n] i0) := by
  rcases le_or_lt i0 (pred^[n] i0) with h | h
  · have h_eq : pred^[n] i0 = i0 := le_antisymm (pred_iterate_le _ _) h
    rw [h_eq, toZ_of_eq]
    simp only [Right.neg_nonpos_iff, Nat.cast_nonneg]
  · 

Proof state:
case inr
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
n : ℕ
h : pred^[n] i0 < i0
⊢ -↑n ≤ toZ i0 (pred^[n] i0)

Next tactic:
rw [toZ_of_lt h, neg_le_neg_iff]
theorem toZ_iterate_pred_ge (n : ℕ) : -(n : ℤ) ≤ toZ i0 (pred^[n] i0) := by
  rcases le_or_lt i0 (pred^[n] i0) with h | h
  · have h_eq : pred^[n] i0 = i0 := le_antisymm (pred_iterate_le _ _) h
    rw [h_eq, toZ_of_eq]
    simp only [Right.neg_nonpos_iff, Nat.cast_nonneg]
  · rw [toZ_of_lt h, neg_le_neg_iff]
    

Proof state:
case inr
ι : Type u_1
inst✝³ : LinearOrder ι
inst✝² : SuccOrder ι
inst✝¹ : IsSuccArchimedean ι
inst✝ : PredOrder ι
i0 i : ι
n : ℕ
h : pred^[n] i0 < i0
⊢ ↑(Nat.find (_ : ∃ n_1, pred^[n_1] i0 = pred^[n] i0)) ≤ ↑n

Next tactic:
norm_cast