Theorem: GeneralizedContinuedFraction.of_correctness_of_nth_stream_eq_none
File: Mathlib/Algebra/ContinuedFractions/Computation/CorrectnessTerminating.lean

tactic: contradiction
state_before: case zero
K : Type u_1
inst✝¹ : LinearOrderedField K
v : K
n : ℕ
inst✝ : FloorRing K
nth_stream_eq_none : IntFractPair.stream v 0 = none
⊢ v = (of v).convergents (0 - 1)
state_after: no goals

tactic: let g := of v
state_before: case succ
K : Type u_1
inst✝¹ : LinearOrderedField K
v : K
n✝ : ℕ
inst✝ : FloorRing K
n : ℕ
IH : IntFractPair.stream v n = none → v = (of v).convergents (n - 1)
nth_stream_eq_none : IntFractPair.stream v (n + 1) = none
⊢ v = (of v).convergents (n + 1 - 1)
state_after: case succ
K : Type u_1
inst✝¹ : LinearOrderedField K
v : K
n✝ : ℕ
inst✝ : FloorRing K
n : ℕ
IH : IntFractPair.stream v n = none → v = (of v).convergents (n - 1)
nth_stream_eq_none : IntFractPair.stream v (n + 1) = none
g : GeneralizedContinuedFraction K := of v
⊢ v = (of v).convergents (n + 1 - 1)

tactic: change v = g.convergents n
state_before: case succ
K : Type u_1
inst✝¹ : LinearOrderedField K
v : K
n✝ : ℕ
inst✝ : FloorRing K
n : ℕ
IH : IntFractPair.stream v n = none → v = (of v).convergents (n - 1)
nth_stream_eq_none : IntFractPair.stream v (n + 1) = none
g : GeneralizedContinuedFraction K := of v
⊢ v = (of v).convergents (n + 1 - 1)
state_after: case succ
K : Type u_1
inst✝¹ : LinearOrderedField K
v : K
n✝ : ℕ
inst✝ : FloorRing K
n : ℕ
IH : IntFractPair.stream v n = none → v = (of v).convergents (n - 1)
nth_stream_eq_none : IntFractPair.stream v (n + 1) = none
g : GeneralizedContinuedFraction K := of v
⊢ v = g.convergents n

tactic: have :
  IntFractPair.stream v n = none ∨ ∃ ifp, IntFractPair.stream v n = some ifp ∧ ifp.fr = 0 :=
  IntFractPair.succ_nth_stream_eq_none_iff.1 nth_stream_eq_none
state_before: case succ
K : Type u_1
inst✝¹ : LinearOrderedField K
v : K
n✝ : ℕ
inst✝ : FloorRing K
n : ℕ
IH : IntFractPair.stream v n = none → v = (of v).convergents (n - 1)
nth_stream_eq_none : IntFractPair.stream v (n + 1) = none
g : GeneralizedContinuedFraction K := of v
⊢ v = g.convergents n
state_after: case succ
K : Type u_1
inst✝¹ : LinearOrderedField K
v : K
n✝ : ℕ
inst✝ : FloorRing K
n : ℕ
IH : IntFractPair.stream v n = none → v = (of v).convergents (n - 1)
nth_stream_eq_none : IntFractPair.stream v (n + 1) = none
g : GeneralizedContinuedFraction K := of v
this : IntFractPair.stream v n = none ∨ ∃ ifp, IntFractPair.stream v n = some ifp ∧ ifp.fr = 0
⊢ v = g.convergents n

tactic: rcases this with (⟨nth_stream_eq_none⟩ | ⟨ifp_n, nth_stream_eq, nth_stream_fr_eq_zero⟩)
state_before: case succ
K : Type u_1
inst✝¹ : LinearOrderedField K
v : K
n✝ : ℕ
inst✝ : FloorRing K
n : ℕ
IH : IntFractPair.stream v n = none → v = (of v).convergents (n - 1)
nth_stream_eq_none : IntFractPair.stream v (n + 1) = none
g : GeneralizedContinuedFraction K := of v
this : IntFractPair.stream v n = none ∨ ∃ ifp, IntFractPair.stream v n = some ifp ∧ ifp.fr = 0
⊢ v = g.convergents n
state_after: case succ.inl
K : Type u_1
inst✝¹ : LinearOrderedField K
v : K
n✝ : ℕ
inst✝ : FloorRing K
n : ℕ
IH : IntFractPair.stream v n = none → v = (of v).convergents (n - 1)
nth_stream_eq_none✝ : IntFractPair.stream v (n + 1) = none
g : GeneralizedContinuedFraction K := of v
nth_stream_eq_none : IntFractPair.stream v n = none
⊢ v = g.convergents n

case succ.inr.intro.intro
K : Type u_1
inst✝¹ : LinearOrderedField K
v : K
n✝ : ℕ
inst✝ : FloorRing K
n : ℕ
IH : IntFractPair.stream v n = none → v = (of v).convergents (n - 1)
nth_stream_eq_none : IntFractPair.stream v (n + 1) = none
g : GeneralizedContinuedFraction K := of v
ifp_n : IntFractPair K
nth_stream_eq : IntFractPair.stream v n = some ifp_n
nth_stream_fr_eq_zero : ifp_n.fr = 0
⊢ v = g.convergents n

tactic: cases' n with n'
state_before: case succ.inl
K : Type u_1
inst✝¹ : LinearOrderedField K
v : K
n✝ : ℕ
inst✝ : FloorRing K
n : ℕ
IH : IntFractPair.stream v n = none → v = (of v).convergents (n - 1)
nth_stream_eq_none✝ : IntFractPair.stream v (n + 1) = none
g : GeneralizedContinuedFraction K := of v
nth_stream_eq_none : IntFractPair.stream v n = none
⊢ v = g.convergents n
state_after: case succ.inl.zero
K : Type u_1
inst✝¹ : LinearOrderedField K
v : K
n : ℕ
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
IH : IntFractPair.stream v 0 = none → v = (of v).convergents (0 - 1)
nth_stream_eq_none✝ : IntFractPair.stream v (0 + 1) = none
nth_stream_eq_none : IntFractPair.stream v 0 = none
⊢ v = g.convergents 0

case succ.inl.succ
K : Type u_1
inst✝¹ : LinearOrderedField K
v : K
n : ℕ
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
n' : ℕ
IH : IntFractPair.stream v (n' + 1) = none → v = (of v).convergents (n' + 1 - 1)
nth_stream_eq_none✝ : IntFractPair.stream v (n' + 1 + 1) = none
nth_stream_eq_none : IntFractPair.stream v (n' + 1) = none
⊢ v = g.convergents (n' + 1)

tactic: contradiction
state_before: case succ.inl.zero
K : Type u_1
inst✝¹ : LinearOrderedField K
v : K
n : ℕ
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
IH : IntFractPair.stream v 0 = none → v = (of v).convergents (0 - 1)
nth_stream_eq_none✝ : IntFractPair.stream v (0 + 1) = none
nth_stream_eq_none : IntFractPair.stream v 0 = none
⊢ v = g.convergents 0
state_after: no goals

tactic: have : g.TerminatedAt n' :=
  of_terminatedAt_n_iff_succ_nth_intFractPair_stream_eq_none.2
    nth_stream_eq_none
state_before: case succ.inl.succ
K : Type u_1
inst✝¹ : LinearOrderedField K
v : K
n : ℕ
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
n' : ℕ
IH : IntFractPair.stream v (n' + 1) = none → v = (of v).convergents (n' + 1 - 1)
nth_stream_eq_none✝ : IntFractPair.stream v (n' + 1 + 1) = none
nth_stream_eq_none : IntFractPair.stream v (n' + 1) = none
⊢ v = g.convergents (n' + 1)
state_after: case succ.inl.succ
K : Type u_1
inst✝¹ : LinearOrderedField K
v : K
n : ℕ
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
n' : ℕ
IH : IntFractPair.stream v (n' + 1) = none → v = (of v).convergents (n' + 1 - 1)
nth_stream_eq_none✝ : IntFractPair.stream v (n' + 1 + 1) = none
nth_stream_eq_none : IntFractPair.stream v (n' + 1) = none
this : g.TerminatedAt n'
⊢ v = g.convergents (n' + 1)

tactic: have : g.convergents (n' + 1) = g.convergents n' :=
  convergents_stable_of_terminated n'.le_succ this
state_before: case succ.inl.succ
K : Type u_1
inst✝¹ : LinearOrderedField K
v : K
n : ℕ
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
n' : ℕ
IH : IntFractPair.stream v (n' + 1) = none → v = (of v).convergents (n' + 1 - 1)
nth_stream_eq_none✝ : IntFractPair.stream v (n' + 1 + 1) = none
nth_stream_eq_none : IntFractPair.stream v (n' + 1) = none
this : g.TerminatedAt n'
⊢ v = g.convergents (n' + 1)
state_after: case succ.inl.succ
K : Type u_1
inst✝¹ : LinearOrderedField K
v : K
n : ℕ
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
n' : ℕ
IH : IntFractPair.stream v (n' + 1) = none → v = (of v).convergents (n' + 1 - 1)
nth_stream_eq_none✝ : IntFractPair.stream v (n' + 1 + 1) = none
nth_stream_eq_none : IntFractPair.stream v (n' + 1) = none
this✝ : g.TerminatedAt n'
this : g.convergents (n' + 1) = g.convergents n'
⊢ v = g.convergents (n' + 1)

tactic: rw [this]
state_before: case succ.inl.succ
K : Type u_1
inst✝¹ : LinearOrderedField K
v : K
n : ℕ
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
n' : ℕ
IH : IntFractPair.stream v (n' + 1) = none → v = (of v).convergents (n' + 1 - 1)
nth_stream_eq_none✝ : IntFractPair.stream v (n' + 1 + 1) = none
nth_stream_eq_none : IntFractPair.stream v (n' + 1) = none
this✝ : g.TerminatedAt n'
this : g.convergents (n' + 1) = g.convergents n'
⊢ v = g.convergents (n' + 1)
state_after: case succ.inl.succ
K : Type u_1
inst✝¹ : LinearOrderedField K
v : K
n : ℕ
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
n' : ℕ
IH : IntFractPair.stream v (n' + 1) = none → v = (of v).convergents (n' + 1 - 1)
nth_stream_eq_none✝ : IntFractPair.stream v (n' + 1 + 1) = none
nth_stream_eq_none : IntFractPair.stream v (n' + 1) = none
this✝ : g.TerminatedAt n'
this : g.convergents (n' + 1) = g.convergents n'
⊢ v = g.convergents n'

tactic: exact IH nth_stream_eq_none
state_before: case succ.inl.succ
K : Type u_1
inst✝¹ : LinearOrderedField K
v : K
n : ℕ
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
n' : ℕ
IH : IntFractPair.stream v (n' + 1) = none → v = (of v).convergents (n' + 1 - 1)
nth_stream_eq_none✝ : IntFractPair.stream v (n' + 1 + 1) = none
nth_stream_eq_none : IntFractPair.stream v (n' + 1) = none
this✝ : g.TerminatedAt n'
this : g.convergents (n' + 1) = g.convergents n'
⊢ v = g.convergents n'
state_after: no goals

tactic: simpa [nth_stream_fr_eq_zero, compExactValue] using
  compExactValue_correctness_of_stream_eq_some nth_stream_eq
state_before: case succ.inr.intro.intro
K : Type u_1
inst✝¹ : LinearOrderedField K
v : K
n✝ : ℕ
inst✝ : FloorRing K
n : ℕ
IH : IntFractPair.stream v n = none → v = (of v).convergents (n - 1)
nth_stream_eq_none : IntFractPair.stream v (n + 1) = none
g : GeneralizedContinuedFraction K := of v
ifp_n : IntFractPair K
nth_stream_eq : IntFractPair.stream v n = some ifp_n
nth_stream_fr_eq_zero : ifp_n.fr = 0
⊢ v = g.convergents n
state_after: no goals