[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp_n : IntFractPair K
nth_stream_eq : IntFractPair.stream v n = some ifp_n
⊢ 0 ≤ ifp_n.fr ∧ ifp_n.fr < 1
[PROOFSTEP]
cases n
[GOAL]
case zero
K : Type u_1
v : K
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp_n : IntFractPair K
nth_stream_eq : IntFractPair.stream v Nat.zero = some ifp_n
⊢ 0 ≤ ifp_n.fr ∧ ifp_n.fr < 1
case succ
K : Type u_1
v : K
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp_n : IntFractPair K
n✝ : ℕ
nth_stream_eq : IntFractPair.stream v (Nat.succ n✝) = some ifp_n
⊢ 0 ≤ ifp_n.fr ∧ ifp_n.fr < 1
[PROOFSTEP]
case zero =>
  have : IntFractPair.of v = ifp_n := by injection nth_stream_eq
  rw [← this, IntFractPair.of]
  exact ⟨fract_nonneg _, fract_lt_one _⟩
[GOAL]
K : Type u_1
v : K
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp_n : IntFractPair K
nth_stream_eq : IntFractPair.stream v Nat.zero = some ifp_n
⊢ 0 ≤ ifp_n.fr ∧ ifp_n.fr < 1
[PROOFSTEP]
case zero =>
  have : IntFractPair.of v = ifp_n := by injection nth_stream_eq
  rw [← this, IntFractPair.of]
  exact ⟨fract_nonneg _, fract_lt_one _⟩
[GOAL]
K : Type u_1
v : K
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp_n : IntFractPair K
nth_stream_eq : IntFractPair.stream v Nat.zero = some ifp_n
⊢ 0 ≤ ifp_n.fr ∧ ifp_n.fr < 1
[PROOFSTEP]
have : IntFractPair.of v = ifp_n := by injection nth_stream_eq
[GOAL]
K : Type u_1
v : K
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp_n : IntFractPair K
nth_stream_eq : IntFractPair.stream v Nat.zero = some ifp_n
⊢ IntFractPair.of v = ifp_n
[PROOFSTEP]
injection nth_stream_eq
[GOAL]
K : Type u_1
v : K
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp_n : IntFractPair K
nth_stream_eq : IntFractPair.stream v Nat.zero = some ifp_n
this : IntFractPair.of v = ifp_n
⊢ 0 ≤ ifp_n.fr ∧ ifp_n.fr < 1
[PROOFSTEP]
rw [← this, IntFractPair.of]
[GOAL]
K : Type u_1
v : K
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp_n : IntFractPair K
nth_stream_eq : IntFractPair.stream v Nat.zero = some ifp_n
this : IntFractPair.of v = ifp_n
⊢ 0 ≤ { b := ⌊v⌋, fr := fract v }.fr ∧ { b := ⌊v⌋, fr := fract v }.fr < 1
[PROOFSTEP]
exact ⟨fract_nonneg _, fract_lt_one _⟩
[GOAL]
case succ
K : Type u_1
v : K
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp_n : IntFractPair K
n✝ : ℕ
nth_stream_eq : IntFractPair.stream v (Nat.succ n✝) = some ifp_n
⊢ 0 ≤ ifp_n.fr ∧ ifp_n.fr < 1
[PROOFSTEP]
case succ =>
  rcases succ_nth_stream_eq_some_iff.1 nth_stream_eq with ⟨_, _, _, ifp_of_eq_ifp_n⟩
  rw [← ifp_of_eq_ifp_n, IntFractPair.of]
  exact ⟨fract_nonneg _, fract_lt_one _⟩
[GOAL]
K : Type u_1
v : K
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp_n : IntFractPair K
n✝ : ℕ
nth_stream_eq : IntFractPair.stream v (Nat.succ n✝) = some ifp_n
⊢ 0 ≤ ifp_n.fr ∧ ifp_n.fr < 1
[PROOFSTEP]
case succ =>
  rcases succ_nth_stream_eq_some_iff.1 nth_stream_eq with ⟨_, _, _, ifp_of_eq_ifp_n⟩
  rw [← ifp_of_eq_ifp_n, IntFractPair.of]
  exact ⟨fract_nonneg _, fract_lt_one _⟩
[GOAL]
K : Type u_1
v : K
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp_n : IntFractPair K
n✝ : ℕ
nth_stream_eq : IntFractPair.stream v (Nat.succ n✝) = some ifp_n
⊢ 0 ≤ ifp_n.fr ∧ ifp_n.fr < 1
[PROOFSTEP]
rcases succ_nth_stream_eq_some_iff.1 nth_stream_eq with ⟨_, _, _, ifp_of_eq_ifp_n⟩
[GOAL]
case intro.intro.intro
K : Type u_1
v : K
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp_n : IntFractPair K
n✝ : ℕ
nth_stream_eq : IntFractPair.stream v (Nat.succ n✝) = some ifp_n
w✝ : IntFractPair K
left✝¹ : IntFractPair.stream v n✝ = some w✝
left✝ : w✝.fr ≠ 0
ifp_of_eq_ifp_n : IntFractPair.of w✝.fr⁻¹ = ifp_n
⊢ 0 ≤ ifp_n.fr ∧ ifp_n.fr < 1
[PROOFSTEP]
rw [← ifp_of_eq_ifp_n, IntFractPair.of]
[GOAL]
case intro.intro.intro
K : Type u_1
v : K
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp_n : IntFractPair K
n✝ : ℕ
nth_stream_eq : IntFractPair.stream v (Nat.succ n✝) = some ifp_n
w✝ : IntFractPair K
left✝¹ : IntFractPair.stream v n✝ = some w✝
left✝ : w✝.fr ≠ 0
ifp_of_eq_ifp_n : IntFractPair.of w✝.fr⁻¹ = ifp_n
⊢ 0 ≤ { b := ⌊w✝.fr⁻¹⌋, fr := fract w✝.fr⁻¹ }.fr ∧ { b := ⌊w✝.fr⁻¹⌋, fr := fract w✝.fr⁻¹ }.fr < 1
[PROOFSTEP]
exact ⟨fract_nonneg _, fract_lt_one _⟩
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
⊢ 1 ≤ ifp_succ_n.b
[PROOFSTEP]
obtain ⟨ifp_n, nth_stream_eq, stream_nth_fr_ne_zero, ⟨-⟩⟩ :
  ∃ ifp_n, IntFractPair.stream v n = some ifp_n ∧ ifp_n.fr ≠ 0 ∧ IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
⊢ ∃ ifp_n, IntFractPair.stream v n = some ifp_n ∧ ifp_n.fr ≠ 0 ∧ IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
case intro.intro.intro.refl
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp_n : IntFractPair K
nth_stream_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some (IntFractPair.of ifp_n.fr⁻¹)
⊢ 1 ≤ (IntFractPair.of ifp_n.fr⁻¹).b
[PROOFSTEP]
exact succ_nth_stream_eq_some_iff.1 succ_nth_stream_eq
[GOAL]
case intro.intro.intro.refl
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp_n : IntFractPair K
nth_stream_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some (IntFractPair.of ifp_n.fr⁻¹)
⊢ 1 ≤ (IntFractPair.of ifp_n.fr⁻¹).b
[PROOFSTEP]
suffices 1 ≤ ifp_n.fr⁻¹ by rwa [IntFractPair.of, le_floor, cast_one]
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp_n : IntFractPair K
nth_stream_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some (IntFractPair.of ifp_n.fr⁻¹)
this : 1 ≤ ifp_n.fr⁻¹
⊢ 1 ≤ (IntFractPair.of ifp_n.fr⁻¹).b
[PROOFSTEP]
rwa [IntFractPair.of, le_floor, cast_one]
[GOAL]
case intro.intro.intro.refl
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp_n : IntFractPair K
nth_stream_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some (IntFractPair.of ifp_n.fr⁻¹)
⊢ 1 ≤ ifp_n.fr⁻¹
[PROOFSTEP]
suffices ifp_n.fr ≤ 1
  by
  have h : 0 < ifp_n.fr := lt_of_le_of_ne (nth_stream_fr_nonneg nth_stream_eq) stream_nth_fr_ne_zero.symm
  apply one_le_inv h this
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp_n : IntFractPair K
nth_stream_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some (IntFractPair.of ifp_n.fr⁻¹)
this : ifp_n.fr ≤ 1
⊢ 1 ≤ ifp_n.fr⁻¹
[PROOFSTEP]
have h : 0 < ifp_n.fr := lt_of_le_of_ne (nth_stream_fr_nonneg nth_stream_eq) stream_nth_fr_ne_zero.symm
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp_n : IntFractPair K
nth_stream_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some (IntFractPair.of ifp_n.fr⁻¹)
this : ifp_n.fr ≤ 1
h : 0 < ifp_n.fr
⊢ 1 ≤ ifp_n.fr⁻¹
[PROOFSTEP]
apply one_le_inv h this
[GOAL]
case intro.intro.intro.refl
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp_n : IntFractPair K
nth_stream_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some (IntFractPair.of ifp_n.fr⁻¹)
⊢ ifp_n.fr ≤ 1
[PROOFSTEP]
simp only [le_of_lt (nth_stream_fr_lt_one nth_stream_eq)]
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp_n ifp_succ_n : IntFractPair K
nth_stream_eq : IntFractPair.stream v n = some ifp_n
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
⊢ ↑ifp_succ_n.b ≤ ifp_n.fr⁻¹
[PROOFSTEP]
suffices (⌊ifp_n.fr⁻¹⌋ : K) ≤ ifp_n.fr⁻¹ by
  cases' ifp_n with _ ifp_n_fr
  have : ifp_n_fr ≠ 0 := by
    intro h
    simp [h, IntFractPair.stream, nth_stream_eq] at succ_nth_stream_eq 
  have : IntFractPair.of ifp_n_fr⁻¹ = ifp_succ_n := by
    simpa [this, IntFractPair.stream, nth_stream_eq, Option.coe_def] using succ_nth_stream_eq
  rwa [← this]
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp_n ifp_succ_n : IntFractPair K
nth_stream_eq : IntFractPair.stream v n = some ifp_n
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
this : ↑⌊ifp_n.fr⁻¹⌋ ≤ ifp_n.fr⁻¹
⊢ ↑ifp_succ_n.b ≤ ifp_n.fr⁻¹
[PROOFSTEP]
cases' ifp_n with _ ifp_n_fr
[GOAL]
case mk
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
b✝ : ℤ
ifp_n_fr : K
nth_stream_eq : IntFractPair.stream v n = some { b := b✝, fr := ifp_n_fr }
this : ↑⌊{ b := b✝, fr := ifp_n_fr }.fr⁻¹⌋ ≤ { b := b✝, fr := ifp_n_fr }.fr⁻¹
⊢ ↑ifp_succ_n.b ≤ { b := b✝, fr := ifp_n_fr }.fr⁻¹
[PROOFSTEP]
have : ifp_n_fr ≠ 0 := by
  intro h
  simp [h, IntFractPair.stream, nth_stream_eq] at succ_nth_stream_eq 
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
b✝ : ℤ
ifp_n_fr : K
nth_stream_eq : IntFractPair.stream v n = some { b := b✝, fr := ifp_n_fr }
this : ↑⌊{ b := b✝, fr := ifp_n_fr }.fr⁻¹⌋ ≤ { b := b✝, fr := ifp_n_fr }.fr⁻¹
⊢ ifp_n_fr ≠ 0
[PROOFSTEP]
intro h
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
b✝ : ℤ
ifp_n_fr : K
nth_stream_eq : IntFractPair.stream v n = some { b := b✝, fr := ifp_n_fr }
this : ↑⌊{ b := b✝, fr := ifp_n_fr }.fr⁻¹⌋ ≤ { b := b✝, fr := ifp_n_fr }.fr⁻¹
h : ifp_n_fr = 0
⊢ False
[PROOFSTEP]
simp [h, IntFractPair.stream, nth_stream_eq] at succ_nth_stream_eq 
[GOAL]
case mk
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
b✝ : ℤ
ifp_n_fr : K
nth_stream_eq : IntFractPair.stream v n = some { b := b✝, fr := ifp_n_fr }
this✝ : ↑⌊{ b := b✝, fr := ifp_n_fr }.fr⁻¹⌋ ≤ { b := b✝, fr := ifp_n_fr }.fr⁻¹
this : ifp_n_fr ≠ 0
⊢ ↑ifp_succ_n.b ≤ { b := b✝, fr := ifp_n_fr }.fr⁻¹
[PROOFSTEP]
have : IntFractPair.of ifp_n_fr⁻¹ = ifp_succ_n := by
  simpa [this, IntFractPair.stream, nth_stream_eq, Option.coe_def] using succ_nth_stream_eq
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
b✝ : ℤ
ifp_n_fr : K
nth_stream_eq : IntFractPair.stream v n = some { b := b✝, fr := ifp_n_fr }
this✝ : ↑⌊{ b := b✝, fr := ifp_n_fr }.fr⁻¹⌋ ≤ { b := b✝, fr := ifp_n_fr }.fr⁻¹
this : ifp_n_fr ≠ 0
⊢ IntFractPair.of ifp_n_fr⁻¹ = ifp_succ_n
[PROOFSTEP]
simpa [this, IntFractPair.stream, nth_stream_eq, Option.coe_def] using succ_nth_stream_eq
[GOAL]
case mk
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
b✝ : ℤ
ifp_n_fr : K
nth_stream_eq : IntFractPair.stream v n = some { b := b✝, fr := ifp_n_fr }
this✝¹ : ↑⌊{ b := b✝, fr := ifp_n_fr }.fr⁻¹⌋ ≤ { b := b✝, fr := ifp_n_fr }.fr⁻¹
this✝ : ifp_n_fr ≠ 0
this : IntFractPair.of ifp_n_fr⁻¹ = ifp_succ_n
⊢ ↑ifp_succ_n.b ≤ { b := b✝, fr := ifp_n_fr }.fr⁻¹
[PROOFSTEP]
rwa [← this]
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp_n ifp_succ_n : IntFractPair K
nth_stream_eq : IntFractPair.stream v n = some ifp_n
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
⊢ ↑⌊ifp_n.fr⁻¹⌋ ≤ ifp_n.fr⁻¹
[PROOFSTEP]
exact floor_le ifp_n.fr⁻¹
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
b : K
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators (of v)) n = some b
⊢ 1 ≤ b
[PROOFSTEP]
obtain ⟨gp_n, nth_s_eq, ⟨-⟩⟩ : ∃ gp_n, (of v).s.get? n = some gp_n ∧ gp_n.b = b
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
b : K
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators (of v)) n = some b
⊢ ∃ gp_n, Stream'.Seq.get? (of v).s n = some gp_n ∧ gp_n.b = b
case intro.intro.refl
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
gp_n : Pair K
nth_s_eq : Stream'.Seq.get? (of v).s n = some gp_n
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators (of v)) n = some gp_n.b
⊢ 1 ≤ gp_n.b
[PROOFSTEP]
exact exists_s_b_of_part_denom nth_part_denom_eq
[GOAL]
case intro.intro.refl
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
gp_n : Pair K
nth_s_eq : Stream'.Seq.get? (of v).s n = some gp_n
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators (of v)) n = some gp_n.b
⊢ 1 ≤ gp_n.b
[PROOFSTEP]
obtain ⟨ifp_n, succ_nth_stream_eq, ifp_n_b_eq_gp_n_b⟩ :
  ∃ ifp, IntFractPair.stream v (n + 1) = some ifp ∧ (ifp.b : K) = gp_n.b
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
gp_n : Pair K
nth_s_eq : Stream'.Seq.get? (of v).s n = some gp_n
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators (of v)) n = some gp_n.b
⊢ ∃ ifp, IntFractPair.stream v (n + 1) = some ifp ∧ ↑ifp.b = gp_n.b
case intro.intro.refl.intro.intro
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
gp_n : Pair K
nth_s_eq : Stream'.Seq.get? (of v).s n = some gp_n
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators (of v)) n = some gp_n.b
ifp_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_n
ifp_n_b_eq_gp_n_b : ↑ifp_n.b = gp_n.b
⊢ 1 ≤ gp_n.b
[PROOFSTEP]
exact IntFractPair.exists_succ_get?_stream_of_gcf_of_get?_eq_some nth_s_eq
[GOAL]
case intro.intro.refl.intro.intro
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
gp_n : Pair K
nth_s_eq : Stream'.Seq.get? (of v).s n = some gp_n
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators (of v)) n = some gp_n.b
ifp_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_n
ifp_n_b_eq_gp_n_b : ↑ifp_n.b = gp_n.b
⊢ 1 ≤ gp_n.b
[PROOFSTEP]
rw [← ifp_n_b_eq_gp_n_b]
[GOAL]
case intro.intro.refl.intro.intro
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
gp_n : Pair K
nth_s_eq : Stream'.Seq.get? (of v).s n = some gp_n
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators (of v)) n = some gp_n.b
ifp_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_n
ifp_n_b_eq_gp_n_b : ↑ifp_n.b = gp_n.b
⊢ 1 ≤ ↑ifp_n.b
[PROOFSTEP]
exact_mod_cast IntFractPair.one_le_succ_nth_stream_b succ_nth_stream_eq
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
gp : Pair K
nth_s_eq : Stream'.Seq.get? (of v).s n = some gp
⊢ gp.a = 1 ∧ ∃ z, gp.b = ↑z
[PROOFSTEP]
obtain ⟨ifp, stream_succ_nth_eq, -⟩ : ∃ ifp, IntFractPair.stream v (n + 1) = some ifp ∧ _
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
gp : Pair K
nth_s_eq : Stream'.Seq.get? (of v).s n = some gp
⊢ ∃ ifp, IntFractPair.stream v (n + 1) = some ifp ∧ ?m.6997 ifp
case intro.intro
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
gp : Pair K
nth_s_eq : Stream'.Seq.get? (of v).s n = some gp
ifp : IntFractPair K
stream_succ_nth_eq : IntFractPair.stream v (n + 1) = some ifp
⊢ gp.a = 1 ∧ ∃ z, gp.b = ↑z
[PROOFSTEP]
exact IntFractPair.exists_succ_get?_stream_of_gcf_of_get?_eq_some nth_s_eq
[GOAL]
case intro.intro
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
gp : Pair K
nth_s_eq : Stream'.Seq.get? (of v).s n = some gp
ifp : IntFractPair K
stream_succ_nth_eq : IntFractPair.stream v (n + 1) = some ifp
⊢ gp.a = 1 ∧ ∃ z, gp.b = ↑z
[PROOFSTEP]
have : gp = ⟨1, ifp.b⟩ :=
  by
  have : (of v).s.get? n = some ⟨1, ifp.b⟩ := get?_of_eq_some_of_succ_get?_intFractPair_stream stream_succ_nth_eq
  have : some gp = some ⟨1, ifp.b⟩ := by rwa [nth_s_eq] at this 
  injection this
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
gp : Pair K
nth_s_eq : Stream'.Seq.get? (of v).s n = some gp
ifp : IntFractPair K
stream_succ_nth_eq : IntFractPair.stream v (n + 1) = some ifp
⊢ gp = { a := 1, b := ↑ifp.b }
[PROOFSTEP]
have : (of v).s.get? n = some ⟨1, ifp.b⟩ := get?_of_eq_some_of_succ_get?_intFractPair_stream stream_succ_nth_eq
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
gp : Pair K
nth_s_eq : Stream'.Seq.get? (of v).s n = some gp
ifp : IntFractPair K
stream_succ_nth_eq : IntFractPair.stream v (n + 1) = some ifp
this : Stream'.Seq.get? (of v).s n = some { a := 1, b := ↑ifp.b }
⊢ gp = { a := 1, b := ↑ifp.b }
[PROOFSTEP]
have : some gp = some ⟨1, ifp.b⟩ := by rwa [nth_s_eq] at this 
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
gp : Pair K
nth_s_eq : Stream'.Seq.get? (of v).s n = some gp
ifp : IntFractPair K
stream_succ_nth_eq : IntFractPair.stream v (n + 1) = some ifp
this : Stream'.Seq.get? (of v).s n = some { a := 1, b := ↑ifp.b }
⊢ some gp = some { a := 1, b := ↑ifp.b }
[PROOFSTEP]
rwa [nth_s_eq] at this 
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
gp : Pair K
nth_s_eq : Stream'.Seq.get? (of v).s n = some gp
ifp : IntFractPair K
stream_succ_nth_eq : IntFractPair.stream v (n + 1) = some ifp
this✝ : Stream'.Seq.get? (of v).s n = some { a := 1, b := ↑ifp.b }
this : some gp = some { a := 1, b := ↑ifp.b }
⊢ gp = { a := 1, b := ↑ifp.b }
[PROOFSTEP]
injection this
[GOAL]
case intro.intro
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
gp : Pair K
nth_s_eq : Stream'.Seq.get? (of v).s n = some gp
ifp : IntFractPair K
stream_succ_nth_eq : IntFractPair.stream v (n + 1) = some ifp
this : gp = { a := 1, b := ↑ifp.b }
⊢ gp.a = 1 ∧ ∃ z, gp.b = ↑z
[PROOFSTEP]
simp [this]
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
a : K
nth_part_num_eq : Stream'.Seq.get? (partialNumerators (of v)) n = some a
⊢ a = 1
[PROOFSTEP]
obtain ⟨gp, nth_s_eq, gp_a_eq_a_n⟩ : ∃ gp, (of v).s.get? n = some gp ∧ gp.a = a
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
a : K
nth_part_num_eq : Stream'.Seq.get? (partialNumerators (of v)) n = some a
⊢ ∃ gp, Stream'.Seq.get? (of v).s n = some gp ∧ gp.a = a
case intro.intro
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
a : K
nth_part_num_eq : Stream'.Seq.get? (partialNumerators (of v)) n = some a
gp : Pair K
nth_s_eq : Stream'.Seq.get? (of v).s n = some gp
gp_a_eq_a_n : gp.a = a
⊢ a = 1
[PROOFSTEP]
exact exists_s_a_of_part_num nth_part_num_eq
[GOAL]
case intro.intro
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
a : K
nth_part_num_eq : Stream'.Seq.get? (partialNumerators (of v)) n = some a
gp : Pair K
nth_s_eq : Stream'.Seq.get? (of v).s n = some gp
gp_a_eq_a_n : gp.a = a
⊢ a = 1
[PROOFSTEP]
have : gp.a = 1 := (of_part_num_eq_one_and_exists_int_part_denom_eq nth_s_eq).left
[GOAL]
case intro.intro
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
a : K
nth_part_num_eq : Stream'.Seq.get? (partialNumerators (of v)) n = some a
gp : Pair K
nth_s_eq : Stream'.Seq.get? (of v).s n = some gp
gp_a_eq_a_n : gp.a = a
this : gp.a = 1
⊢ a = 1
[PROOFSTEP]
rwa [gp_a_eq_a_n] at this 
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
b : K
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators (of v)) n = some b
⊢ ∃ z, b = ↑z
[PROOFSTEP]
obtain ⟨gp, nth_s_eq, gp_b_eq_b_n⟩ : ∃ gp, (of v).s.get? n = some gp ∧ gp.b = b
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
b : K
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators (of v)) n = some b
⊢ ∃ gp, Stream'.Seq.get? (of v).s n = some gp ∧ gp.b = b
case intro.intro
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
b : K
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators (of v)) n = some b
gp : Pair K
nth_s_eq : Stream'.Seq.get? (of v).s n = some gp
gp_b_eq_b_n : gp.b = b
⊢ ∃ z, b = ↑z
[PROOFSTEP]
exact exists_s_b_of_part_denom nth_part_denom_eq
[GOAL]
case intro.intro
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
b : K
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators (of v)) n = some b
gp : Pair K
nth_s_eq : Stream'.Seq.get? (of v).s n = some gp
gp_b_eq_b_n : gp.b = b
⊢ ∃ z, b = ↑z
[PROOFSTEP]
have : ∃ z : ℤ, gp.b = (z : K) := (of_part_num_eq_one_and_exists_int_part_denom_eq nth_s_eq).right
[GOAL]
case intro.intro
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
b : K
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators (of v)) n = some b
gp : Pair K
nth_s_eq : Stream'.Seq.get? (of v).s n = some gp
gp_b_eq_b_n : gp.b = b
this : ∃ z, gp.b = ↑z
⊢ ∃ z, b = ↑z
[PROOFSTEP]
rwa [gp_b_eq_b_n] at this 
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
⊢ ∀ (n : ℕ),
    (∀ (m : ℕ), m < n → m ≤ 1 ∨ ¬TerminatedAt (of v) (m - 2) → ↑(fib m) ≤ (continuantsAux (of v) m).b) →
      n ≤ 1 ∨ ¬TerminatedAt (of v) (n - 2) → ↑(fib n) ≤ (continuantsAux (of v) n).b
[PROOFSTEP]
intro n IH hyp
[GOAL]
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
n : ℕ
IH : ∀ (m : ℕ), m < n → m ≤ 1 ∨ ¬TerminatedAt (of v) (m - 2) → ↑(fib m) ≤ (continuantsAux (of v) m).b
hyp : n ≤ 1 ∨ ¬TerminatedAt (of v) (n - 2)
⊢ ↑(fib n) ≤ (continuantsAux (of v) n).b
[PROOFSTEP]
rcases n with (_ | _ | n)
[GOAL]
case zero
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
IH : ∀ (m : ℕ), m < zero → m ≤ 1 ∨ ¬TerminatedAt (of v) (m - 2) → ↑(fib m) ≤ (continuantsAux (of v) m).b
hyp : zero ≤ 1 ∨ ¬TerminatedAt (of v) (zero - 2)
⊢ ↑(fib zero) ≤ (continuantsAux (of v) zero).b
[PROOFSTEP]
simp [fib_add_two, continuantsAux]
  -- case n = 0
[GOAL]
case succ.zero
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
IH : ∀ (m : ℕ), m < Nat.succ zero → m ≤ 1 ∨ ¬TerminatedAt (of v) (m - 2) → ↑(fib m) ≤ (continuantsAux (of v) m).b
hyp : Nat.succ zero ≤ 1 ∨ ¬TerminatedAt (of v) (Nat.succ zero - 2)
⊢ ↑(fib (Nat.succ zero)) ≤ (continuantsAux (of v) (Nat.succ zero)).b
[PROOFSTEP]
simp [fib_add_two, continuantsAux]
  -- case n = 1
[GOAL]
case succ.succ
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
n : ℕ
IH :
  ∀ (m : ℕ), m < Nat.succ (Nat.succ n) → m ≤ 1 ∨ ¬TerminatedAt (of v) (m - 2) → ↑(fib m) ≤ (continuantsAux (of v) m).b
hyp : Nat.succ (Nat.succ n) ≤ 1 ∨ ¬TerminatedAt (of v) (Nat.succ (Nat.succ n) - 2)
⊢ ↑(fib (Nat.succ (Nat.succ n))) ≤ (continuantsAux (of v) (Nat.succ (Nat.succ n))).b
[PROOFSTEP]
let g := of v
[GOAL]
case succ.succ
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
n : ℕ
IH :
  ∀ (m : ℕ), m < Nat.succ (Nat.succ n) → m ≤ 1 ∨ ¬TerminatedAt (of v) (m - 2) → ↑(fib m) ≤ (continuantsAux (of v) m).b
hyp : Nat.succ (Nat.succ n) ≤ 1 ∨ ¬TerminatedAt (of v) (Nat.succ (Nat.succ n) - 2)
g : GeneralizedContinuedFraction K := of v
⊢ ↑(fib (Nat.succ (Nat.succ n))) ≤ (continuantsAux (of v) (Nat.succ (Nat.succ n))).b
[PROOFSTEP]
have : ¬n + 2 ≤ 1 := by linarith
[GOAL]
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
n : ℕ
IH :
  ∀ (m : ℕ), m < Nat.succ (Nat.succ n) → m ≤ 1 ∨ ¬TerminatedAt (of v) (m - 2) → ↑(fib m) ≤ (continuantsAux (of v) m).b
hyp : Nat.succ (Nat.succ n) ≤ 1 ∨ ¬TerminatedAt (of v) (Nat.succ (Nat.succ n) - 2)
g : GeneralizedContinuedFraction K := of v
⊢ ¬n + 2 ≤ 1
[PROOFSTEP]
linarith
[GOAL]
case succ.succ
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
n : ℕ
IH :
  ∀ (m : ℕ), m < Nat.succ (Nat.succ n) → m ≤ 1 ∨ ¬TerminatedAt (of v) (m - 2) → ↑(fib m) ≤ (continuantsAux (of v) m).b
hyp : Nat.succ (Nat.succ n) ≤ 1 ∨ ¬TerminatedAt (of v) (Nat.succ (Nat.succ n) - 2)
g : GeneralizedContinuedFraction K := of v
this : ¬n + 2 ≤ 1
⊢ ↑(fib (Nat.succ (Nat.succ n))) ≤ (continuantsAux (of v) (Nat.succ (Nat.succ n))).b
[PROOFSTEP]
have not_terminated_at_n : ¬g.TerminatedAt n := Or.resolve_left hyp this
[GOAL]
case succ.succ
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
n : ℕ
IH :
  ∀ (m : ℕ), m < Nat.succ (Nat.succ n) → m ≤ 1 ∨ ¬TerminatedAt (of v) (m - 2) → ↑(fib m) ≤ (continuantsAux (of v) m).b
hyp : Nat.succ (Nat.succ n) ≤ 1 ∨ ¬TerminatedAt (of v) (Nat.succ (Nat.succ n) - 2)
g : GeneralizedContinuedFraction K := of v
this : ¬n + 2 ≤ 1
not_terminated_at_n : ¬TerminatedAt g n
⊢ ↑(fib (Nat.succ (Nat.succ n))) ≤ (continuantsAux (of v) (Nat.succ (Nat.succ n))).b
[PROOFSTEP]
obtain ⟨gp, s_ppred_nth_eq⟩ : ∃ gp, g.s.get? n = some gp
[GOAL]
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
n : ℕ
IH :
  ∀ (m : ℕ), m < Nat.succ (Nat.succ n) → m ≤ 1 ∨ ¬TerminatedAt (of v) (m - 2) → ↑(fib m) ≤ (continuantsAux (of v) m).b
hyp : Nat.succ (Nat.succ n) ≤ 1 ∨ ¬TerminatedAt (of v) (Nat.succ (Nat.succ n) - 2)
g : GeneralizedContinuedFraction K := of v
this : ¬n + 2 ≤ 1
not_terminated_at_n : ¬TerminatedAt g n
⊢ ∃ gp, Stream'.Seq.get? g.s n = some gp
case succ.succ.intro
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
n : ℕ
IH :
  ∀ (m : ℕ), m < Nat.succ (Nat.succ n) → m ≤ 1 ∨ ¬TerminatedAt (of v) (m - 2) → ↑(fib m) ≤ (continuantsAux (of v) m).b
hyp : Nat.succ (Nat.succ n) ≤ 1 ∨ ¬TerminatedAt (of v) (Nat.succ (Nat.succ n) - 2)
g : GeneralizedContinuedFraction K := of v
this : ¬n + 2 ≤ 1
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_ppred_nth_eq : Stream'.Seq.get? g.s n = some gp
⊢ ↑(fib (Nat.succ (Nat.succ n))) ≤ (continuantsAux (of v) (Nat.succ (Nat.succ n))).b
[PROOFSTEP]
exact Option.ne_none_iff_exists'.mp not_terminated_at_n
[GOAL]
case succ.succ.intro
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
n : ℕ
IH :
  ∀ (m : ℕ), m < Nat.succ (Nat.succ n) → m ≤ 1 ∨ ¬TerminatedAt (of v) (m - 2) → ↑(fib m) ≤ (continuantsAux (of v) m).b
hyp : Nat.succ (Nat.succ n) ≤ 1 ∨ ¬TerminatedAt (of v) (Nat.succ (Nat.succ n) - 2)
g : GeneralizedContinuedFraction K := of v
this : ¬n + 2 ≤ 1
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_ppred_nth_eq : Stream'.Seq.get? g.s n = some gp
⊢ ↑(fib (Nat.succ (Nat.succ n))) ≤ (continuantsAux (of v) (Nat.succ (Nat.succ n))).b
[PROOFSTEP]
set pconts := g.continuantsAux (n + 1) with pconts_eq
[GOAL]
case succ.succ.intro
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
n : ℕ
IH :
  ∀ (m : ℕ), m < Nat.succ (Nat.succ n) → m ≤ 1 ∨ ¬TerminatedAt (of v) (m - 2) → ↑(fib m) ≤ (continuantsAux (of v) m).b
hyp : Nat.succ (Nat.succ n) ≤ 1 ∨ ¬TerminatedAt (of v) (Nat.succ (Nat.succ n) - 2)
g : GeneralizedContinuedFraction K := of v
this : ¬n + 2 ≤ 1
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_ppred_nth_eq : Stream'.Seq.get? g.s n = some gp
pconts : Pair K := continuantsAux g (n + 1)
pconts_eq : pconts = continuantsAux g (n + 1)
⊢ ↑(fib (Nat.succ (Nat.succ n))) ≤ (continuantsAux (of v) (Nat.succ (Nat.succ n))).b
[PROOFSTEP]
set ppconts := g.continuantsAux n with ppconts_eq
[GOAL]
case succ.succ.intro
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
n : ℕ
IH :
  ∀ (m : ℕ), m < Nat.succ (Nat.succ n) → m ≤ 1 ∨ ¬TerminatedAt (of v) (m - 2) → ↑(fib m) ≤ (continuantsAux (of v) m).b
hyp : Nat.succ (Nat.succ n) ≤ 1 ∨ ¬TerminatedAt (of v) (Nat.succ (Nat.succ n) - 2)
g : GeneralizedContinuedFraction K := of v
this : ¬n + 2 ≤ 1
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_ppred_nth_eq : Stream'.Seq.get? g.s n = some gp
pconts : Pair K := continuantsAux g (n + 1)
pconts_eq : pconts = continuantsAux g (n + 1)
ppconts : Pair K := continuantsAux g n
ppconts_eq : ppconts = continuantsAux g n
⊢ ↑(fib (Nat.succ (Nat.succ n))) ≤ (continuantsAux (of v) (Nat.succ (Nat.succ n))).b
[PROOFSTEP]
suffices (fib n : K) + fib (n + 1) ≤ gp.a * ppconts.b + gp.b * pconts.b by
  simpa [fib_add_two, add_comm, continuantsAux_recurrence s_ppred_nth_eq ppconts_eq pconts_eq]
    -- make use of the fact that `gp.a = 1`
[GOAL]
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
n : ℕ
IH :
  ∀ (m : ℕ), m < Nat.succ (Nat.succ n) → m ≤ 1 ∨ ¬TerminatedAt (of v) (m - 2) → ↑(fib m) ≤ (continuantsAux (of v) m).b
hyp : Nat.succ (Nat.succ n) ≤ 1 ∨ ¬TerminatedAt (of v) (Nat.succ (Nat.succ n) - 2)
g : GeneralizedContinuedFraction K := of v
this✝ : ¬n + 2 ≤ 1
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_ppred_nth_eq : Stream'.Seq.get? g.s n = some gp
pconts : Pair K := continuantsAux g (n + 1)
pconts_eq : pconts = continuantsAux g (n + 1)
ppconts : Pair K := continuantsAux g n
ppconts_eq : ppconts = continuantsAux g n
this : ↑(fib n) + ↑(fib (n + 1)) ≤ gp.a * ppconts.b + gp.b * pconts.b
⊢ ↑(fib (Nat.succ (Nat.succ n))) ≤ (continuantsAux (of v) (Nat.succ (Nat.succ n))).b
[PROOFSTEP]
simpa [fib_add_two, add_comm, continuantsAux_recurrence s_ppred_nth_eq ppconts_eq pconts_eq]
  -- make use of the fact that `gp.a = 1`
[GOAL]
case succ.succ.intro
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
n : ℕ
IH :
  ∀ (m : ℕ), m < Nat.succ (Nat.succ n) → m ≤ 1 ∨ ¬TerminatedAt (of v) (m - 2) → ↑(fib m) ≤ (continuantsAux (of v) m).b
hyp : Nat.succ (Nat.succ n) ≤ 1 ∨ ¬TerminatedAt (of v) (Nat.succ (Nat.succ n) - 2)
g : GeneralizedContinuedFraction K := of v
this : ¬n + 2 ≤ 1
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_ppred_nth_eq : Stream'.Seq.get? g.s n = some gp
pconts : Pair K := continuantsAux g (n + 1)
pconts_eq : pconts = continuantsAux g (n + 1)
ppconts : Pair K := continuantsAux g n
ppconts_eq : ppconts = continuantsAux g n
⊢ ↑(fib n) + ↑(fib (n + 1)) ≤ gp.a * ppconts.b + gp.b * pconts.b
[PROOFSTEP]
suffices (fib n : K) + fib (n + 1) ≤ ppconts.b + gp.b * pconts.b by
  simpa [of_part_num_eq_one <| part_num_eq_s_a s_ppred_nth_eq]
[GOAL]
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
n : ℕ
IH :
  ∀ (m : ℕ), m < Nat.succ (Nat.succ n) → m ≤ 1 ∨ ¬TerminatedAt (of v) (m - 2) → ↑(fib m) ≤ (continuantsAux (of v) m).b
hyp : Nat.succ (Nat.succ n) ≤ 1 ∨ ¬TerminatedAt (of v) (Nat.succ (Nat.succ n) - 2)
g : GeneralizedContinuedFraction K := of v
this✝ : ¬n + 2 ≤ 1
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_ppred_nth_eq : Stream'.Seq.get? g.s n = some gp
pconts : Pair K := continuantsAux g (n + 1)
pconts_eq : pconts = continuantsAux g (n + 1)
ppconts : Pair K := continuantsAux g n
ppconts_eq : ppconts = continuantsAux g n
this : ↑(fib n) + ↑(fib (n + 1)) ≤ ppconts.b + gp.b * pconts.b
⊢ ↑(fib n) + ↑(fib (n + 1)) ≤ gp.a * ppconts.b + gp.b * pconts.b
[PROOFSTEP]
simpa [of_part_num_eq_one <| part_num_eq_s_a s_ppred_nth_eq]
[GOAL]
case succ.succ.intro
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
n : ℕ
IH :
  ∀ (m : ℕ), m < Nat.succ (Nat.succ n) → m ≤ 1 ∨ ¬TerminatedAt (of v) (m - 2) → ↑(fib m) ≤ (continuantsAux (of v) m).b
hyp : Nat.succ (Nat.succ n) ≤ 1 ∨ ¬TerminatedAt (of v) (Nat.succ (Nat.succ n) - 2)
g : GeneralizedContinuedFraction K := of v
this : ¬n + 2 ≤ 1
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_ppred_nth_eq : Stream'.Seq.get? g.s n = some gp
pconts : Pair K := continuantsAux g (n + 1)
pconts_eq : pconts = continuantsAux g (n + 1)
ppconts : Pair K := continuantsAux g n
ppconts_eq : ppconts = continuantsAux g n
⊢ ↑(fib n) + ↑(fib (n + 1)) ≤ ppconts.b + gp.b * pconts.b
[PROOFSTEP]
have not_terminated_at_pred_n : ¬g.TerminatedAt (n - 1) := mt (terminated_stable <| Nat.sub_le n 1) not_terminated_at_n
[GOAL]
case succ.succ.intro
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
n : ℕ
IH :
  ∀ (m : ℕ), m < Nat.succ (Nat.succ n) → m ≤ 1 ∨ ¬TerminatedAt (of v) (m - 2) → ↑(fib m) ≤ (continuantsAux (of v) m).b
hyp : Nat.succ (Nat.succ n) ≤ 1 ∨ ¬TerminatedAt (of v) (Nat.succ (Nat.succ n) - 2)
g : GeneralizedContinuedFraction K := of v
this : ¬n + 2 ≤ 1
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_ppred_nth_eq : Stream'.Seq.get? g.s n = some gp
pconts : Pair K := continuantsAux g (n + 1)
pconts_eq : pconts = continuantsAux g (n + 1)
ppconts : Pair K := continuantsAux g n
ppconts_eq : ppconts = continuantsAux g n
not_terminated_at_pred_n : ¬TerminatedAt g (n - 1)
⊢ ↑(fib n) + ↑(fib (n + 1)) ≤ ppconts.b + gp.b * pconts.b
[PROOFSTEP]
have not_terminated_at_ppred_n : ¬TerminatedAt g (n - 2) :=
  mt (terminated_stable (n - 1).pred_le) not_terminated_at_pred_n
[GOAL]
case succ.succ.intro
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
n : ℕ
IH :
  ∀ (m : ℕ), m < Nat.succ (Nat.succ n) → m ≤ 1 ∨ ¬TerminatedAt (of v) (m - 2) → ↑(fib m) ≤ (continuantsAux (of v) m).b
hyp : Nat.succ (Nat.succ n) ≤ 1 ∨ ¬TerminatedAt (of v) (Nat.succ (Nat.succ n) - 2)
g : GeneralizedContinuedFraction K := of v
this : ¬n + 2 ≤ 1
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_ppred_nth_eq : Stream'.Seq.get? g.s n = some gp
pconts : Pair K := continuantsAux g (n + 1)
pconts_eq : pconts = continuantsAux g (n + 1)
ppconts : Pair K := continuantsAux g n
ppconts_eq : ppconts = continuantsAux g n
not_terminated_at_pred_n : ¬TerminatedAt g (n - 1)
not_terminated_at_ppred_n : ¬TerminatedAt g (n - 2)
⊢ ↑(fib n) + ↑(fib (n + 1)) ≤ ppconts.b + gp.b * pconts.b
[PROOFSTEP]
have ppred_nth_fib_le_ppconts_B : (fib n : K) ≤ ppconts.b :=
  IH n (lt_trans (Nat.lt.base n) <| Nat.lt.base <| n + 1) (Or.inr not_terminated_at_ppred_n)
[GOAL]
case succ.succ.intro
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
n : ℕ
IH :
  ∀ (m : ℕ), m < Nat.succ (Nat.succ n) → m ≤ 1 ∨ ¬TerminatedAt (of v) (m - 2) → ↑(fib m) ≤ (continuantsAux (of v) m).b
hyp : Nat.succ (Nat.succ n) ≤ 1 ∨ ¬TerminatedAt (of v) (Nat.succ (Nat.succ n) - 2)
g : GeneralizedContinuedFraction K := of v
this : ¬n + 2 ≤ 1
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_ppred_nth_eq : Stream'.Seq.get? g.s n = some gp
pconts : Pair K := continuantsAux g (n + 1)
pconts_eq : pconts = continuantsAux g (n + 1)
ppconts : Pair K := continuantsAux g n
ppconts_eq : ppconts = continuantsAux g n
not_terminated_at_pred_n : ¬TerminatedAt g (n - 1)
not_terminated_at_ppred_n : ¬TerminatedAt g (n - 2)
ppred_nth_fib_le_ppconts_B : ↑(fib n) ≤ ppconts.b
⊢ ↑(fib n) + ↑(fib (n + 1)) ≤ ppconts.b + gp.b * pconts.b
[PROOFSTEP]
suffices : (fib (n + 1) : K) ≤ gp.b * pconts.b
[GOAL]
case succ.succ.intro
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
n : ℕ
IH :
  ∀ (m : ℕ), m < Nat.succ (Nat.succ n) → m ≤ 1 ∨ ¬TerminatedAt (of v) (m - 2) → ↑(fib m) ≤ (continuantsAux (of v) m).b
hyp : Nat.succ (Nat.succ n) ≤ 1 ∨ ¬TerminatedAt (of v) (Nat.succ (Nat.succ n) - 2)
g : GeneralizedContinuedFraction K := of v
this✝ : ¬n + 2 ≤ 1
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_ppred_nth_eq : Stream'.Seq.get? g.s n = some gp
pconts : Pair K := continuantsAux g (n + 1)
pconts_eq : pconts = continuantsAux g (n + 1)
ppconts : Pair K := continuantsAux g n
ppconts_eq : ppconts = continuantsAux g n
not_terminated_at_pred_n : ¬TerminatedAt g (n - 1)
not_terminated_at_ppred_n : ¬TerminatedAt g (n - 2)
ppred_nth_fib_le_ppconts_B : ↑(fib n) ≤ ppconts.b
this : ↑(fib (n + 1)) ≤ gp.b * pconts.b
⊢ ↑(fib n) + ↑(fib (n + 1)) ≤ ppconts.b + gp.b * pconts.b
case this
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
n : ℕ
IH :
  ∀ (m : ℕ), m < Nat.succ (Nat.succ n) → m ≤ 1 ∨ ¬TerminatedAt (of v) (m - 2) → ↑(fib m) ≤ (continuantsAux (of v) m).b
hyp : Nat.succ (Nat.succ n) ≤ 1 ∨ ¬TerminatedAt (of v) (Nat.succ (Nat.succ n) - 2)
g : GeneralizedContinuedFraction K := of v
this : ¬n + 2 ≤ 1
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_ppred_nth_eq : Stream'.Seq.get? g.s n = some gp
pconts : Pair K := continuantsAux g (n + 1)
pconts_eq : pconts = continuantsAux g (n + 1)
ppconts : Pair K := continuantsAux g n
ppconts_eq : ppconts = continuantsAux g n
not_terminated_at_pred_n : ¬TerminatedAt g (n - 1)
not_terminated_at_ppred_n : ¬TerminatedAt g (n - 2)
ppred_nth_fib_le_ppconts_B : ↑(fib n) ≤ ppconts.b
⊢ ↑(fib (n + 1)) ≤ gp.b * pconts.b
[PROOFSTEP]
solve_by_elim [_root_.add_le_add ppred_nth_fib_le_ppconts_B]
  -- finally use the fact that `1 ≤ gp.b` to solve the goal
[GOAL]
case this
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
n : ℕ
IH :
  ∀ (m : ℕ), m < Nat.succ (Nat.succ n) → m ≤ 1 ∨ ¬TerminatedAt (of v) (m - 2) → ↑(fib m) ≤ (continuantsAux (of v) m).b
hyp : Nat.succ (Nat.succ n) ≤ 1 ∨ ¬TerminatedAt (of v) (Nat.succ (Nat.succ n) - 2)
g : GeneralizedContinuedFraction K := of v
this : ¬n + 2 ≤ 1
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_ppred_nth_eq : Stream'.Seq.get? g.s n = some gp
pconts : Pair K := continuantsAux g (n + 1)
pconts_eq : pconts = continuantsAux g (n + 1)
ppconts : Pair K := continuantsAux g n
ppconts_eq : ppconts = continuantsAux g n
not_terminated_at_pred_n : ¬TerminatedAt g (n - 1)
not_terminated_at_ppred_n : ¬TerminatedAt g (n - 2)
ppred_nth_fib_le_ppconts_B : ↑(fib n) ≤ ppconts.b
⊢ ↑(fib (n + 1)) ≤ gp.b * pconts.b
[PROOFSTEP]
suffices 1 * (fib (n + 1) : K) ≤ gp.b * pconts.b by rwa [one_mul] at this 
[GOAL]
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
n : ℕ
IH :
  ∀ (m : ℕ), m < Nat.succ (Nat.succ n) → m ≤ 1 ∨ ¬TerminatedAt (of v) (m - 2) → ↑(fib m) ≤ (continuantsAux (of v) m).b
hyp : Nat.succ (Nat.succ n) ≤ 1 ∨ ¬TerminatedAt (of v) (Nat.succ (Nat.succ n) - 2)
g : GeneralizedContinuedFraction K := of v
this✝ : ¬n + 2 ≤ 1
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_ppred_nth_eq : Stream'.Seq.get? g.s n = some gp
pconts : Pair K := continuantsAux g (n + 1)
pconts_eq : pconts = continuantsAux g (n + 1)
ppconts : Pair K := continuantsAux g n
ppconts_eq : ppconts = continuantsAux g n
not_terminated_at_pred_n : ¬TerminatedAt g (n - 1)
not_terminated_at_ppred_n : ¬TerminatedAt g (n - 2)
ppred_nth_fib_le_ppconts_B : ↑(fib n) ≤ ppconts.b
this : 1 * ↑(fib (n + 1)) ≤ gp.b * pconts.b
⊢ ↑(fib (n + 1)) ≤ gp.b * pconts.b
[PROOFSTEP]
rwa [one_mul] at this 
[GOAL]
case this
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
n : ℕ
IH :
  ∀ (m : ℕ), m < Nat.succ (Nat.succ n) → m ≤ 1 ∨ ¬TerminatedAt (of v) (m - 2) → ↑(fib m) ≤ (continuantsAux (of v) m).b
hyp : Nat.succ (Nat.succ n) ≤ 1 ∨ ¬TerminatedAt (of v) (Nat.succ (Nat.succ n) - 2)
g : GeneralizedContinuedFraction K := of v
this : ¬n + 2 ≤ 1
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_ppred_nth_eq : Stream'.Seq.get? g.s n = some gp
pconts : Pair K := continuantsAux g (n + 1)
pconts_eq : pconts = continuantsAux g (n + 1)
ppconts : Pair K := continuantsAux g n
ppconts_eq : ppconts = continuantsAux g n
not_terminated_at_pred_n : ¬TerminatedAt g (n - 1)
not_terminated_at_ppred_n : ¬TerminatedAt g (n - 2)
ppred_nth_fib_le_ppconts_B : ↑(fib n) ≤ ppconts.b
⊢ 1 * ↑(fib (n + 1)) ≤ gp.b * pconts.b
[PROOFSTEP]
have one_le_gp_b : (1 : K) ≤ gp.b := of_one_le_get?_part_denom (part_denom_eq_s_b s_ppred_nth_eq)
[GOAL]
case this
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
n : ℕ
IH :
  ∀ (m : ℕ), m < Nat.succ (Nat.succ n) → m ≤ 1 ∨ ¬TerminatedAt (of v) (m - 2) → ↑(fib m) ≤ (continuantsAux (of v) m).b
hyp : Nat.succ (Nat.succ n) ≤ 1 ∨ ¬TerminatedAt (of v) (Nat.succ (Nat.succ n) - 2)
g : GeneralizedContinuedFraction K := of v
this : ¬n + 2 ≤ 1
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_ppred_nth_eq : Stream'.Seq.get? g.s n = some gp
pconts : Pair K := continuantsAux g (n + 1)
pconts_eq : pconts = continuantsAux g (n + 1)
ppconts : Pair K := continuantsAux g n
ppconts_eq : ppconts = continuantsAux g n
not_terminated_at_pred_n : ¬TerminatedAt g (n - 1)
not_terminated_at_ppred_n : ¬TerminatedAt g (n - 2)
ppred_nth_fib_le_ppconts_B : ↑(fib n) ≤ ppconts.b
one_le_gp_b : 1 ≤ gp.b
⊢ 1 * ↑(fib (n + 1)) ≤ gp.b * pconts.b
[PROOFSTEP]
have : (0 : K) ≤ fib (n + 1) := by exact_mod_cast (fib (n + 1)).zero_le
[GOAL]
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
n : ℕ
IH :
  ∀ (m : ℕ), m < Nat.succ (Nat.succ n) → m ≤ 1 ∨ ¬TerminatedAt (of v) (m - 2) → ↑(fib m) ≤ (continuantsAux (of v) m).b
hyp : Nat.succ (Nat.succ n) ≤ 1 ∨ ¬TerminatedAt (of v) (Nat.succ (Nat.succ n) - 2)
g : GeneralizedContinuedFraction K := of v
this : ¬n + 2 ≤ 1
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_ppred_nth_eq : Stream'.Seq.get? g.s n = some gp
pconts : Pair K := continuantsAux g (n + 1)
pconts_eq : pconts = continuantsAux g (n + 1)
ppconts : Pair K := continuantsAux g n
ppconts_eq : ppconts = continuantsAux g n
not_terminated_at_pred_n : ¬TerminatedAt g (n - 1)
not_terminated_at_ppred_n : ¬TerminatedAt g (n - 2)
ppred_nth_fib_le_ppconts_B : ↑(fib n) ≤ ppconts.b
one_le_gp_b : 1 ≤ gp.b
⊢ 0 ≤ ↑(fib (n + 1))
[PROOFSTEP]
exact_mod_cast (fib (n + 1)).zero_le
[GOAL]
case this
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
n : ℕ
IH :
  ∀ (m : ℕ), m < Nat.succ (Nat.succ n) → m ≤ 1 ∨ ¬TerminatedAt (of v) (m - 2) → ↑(fib m) ≤ (continuantsAux (of v) m).b
hyp : Nat.succ (Nat.succ n) ≤ 1 ∨ ¬TerminatedAt (of v) (Nat.succ (Nat.succ n) - 2)
g : GeneralizedContinuedFraction K := of v
this✝ : ¬n + 2 ≤ 1
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_ppred_nth_eq : Stream'.Seq.get? g.s n = some gp
pconts : Pair K := continuantsAux g (n + 1)
pconts_eq : pconts = continuantsAux g (n + 1)
ppconts : Pair K := continuantsAux g n
ppconts_eq : ppconts = continuantsAux g n
not_terminated_at_pred_n : ¬TerminatedAt g (n - 1)
not_terminated_at_ppred_n : ¬TerminatedAt g (n - 2)
ppred_nth_fib_le_ppconts_B : ↑(fib n) ≤ ppconts.b
one_le_gp_b : 1 ≤ gp.b
this : 0 ≤ ↑(fib (n + 1))
⊢ 1 * ↑(fib (n + 1)) ≤ gp.b * pconts.b
[PROOFSTEP]
have : (0 : K) ≤ gp.b := le_trans zero_le_one one_le_gp_b
[GOAL]
case this
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
n : ℕ
IH :
  ∀ (m : ℕ), m < Nat.succ (Nat.succ n) → m ≤ 1 ∨ ¬TerminatedAt (of v) (m - 2) → ↑(fib m) ≤ (continuantsAux (of v) m).b
hyp : Nat.succ (Nat.succ n) ≤ 1 ∨ ¬TerminatedAt (of v) (Nat.succ (Nat.succ n) - 2)
g : GeneralizedContinuedFraction K := of v
this✝¹ : ¬n + 2 ≤ 1
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_ppred_nth_eq : Stream'.Seq.get? g.s n = some gp
pconts : Pair K := continuantsAux g (n + 1)
pconts_eq : pconts = continuantsAux g (n + 1)
ppconts : Pair K := continuantsAux g n
ppconts_eq : ppconts = continuantsAux g n
not_terminated_at_pred_n : ¬TerminatedAt g (n - 1)
not_terminated_at_ppred_n : ¬TerminatedAt g (n - 2)
ppred_nth_fib_le_ppconts_B : ↑(fib n) ≤ ppconts.b
one_le_gp_b : 1 ≤ gp.b
this✝ : 0 ≤ ↑(fib (n + 1))
this : 0 ≤ gp.b
⊢ 1 * ↑(fib (n + 1)) ≤ gp.b * pconts.b
[PROOFSTEP]
mono
[GOAL]
case this.h₂.a
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
n : ℕ
IH :
  ∀ (m : ℕ), m < Nat.succ (Nat.succ n) → m ≤ 1 ∨ ¬TerminatedAt (of v) (m - 2) → ↑(fib m) ≤ (continuantsAux (of v) m).b
hyp : Nat.succ (Nat.succ n) ≤ 1 ∨ ¬TerminatedAt (of v) (Nat.succ (Nat.succ n) - 2)
g : GeneralizedContinuedFraction K := of v
this✝¹ : ¬n + 2 ≤ 1
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_ppred_nth_eq : Stream'.Seq.get? g.s n = some gp
pconts : Pair K := continuantsAux g (n + 1)
pconts_eq : pconts = continuantsAux g (n + 1)
ppconts : Pair K := continuantsAux g n
ppconts_eq : ppconts = continuantsAux g n
not_terminated_at_pred_n : ¬TerminatedAt g (n - 1)
not_terminated_at_ppred_n : ¬TerminatedAt g (n - 2)
ppred_nth_fib_le_ppconts_B : ↑(fib n) ≤ ppconts.b
one_le_gp_b : 1 ≤ gp.b
this✝ : 0 ≤ ↑(fib (n + 1))
this : 0 ≤ gp.b
s_ppred_nth_eq_symm : some gp = Stream'.Seq.get? g.s n
⊢ n + 1 < Nat.succ (Nat.succ n)
[PROOFSTEP]
norm_num
[GOAL]
case this.h₂.a
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
n : ℕ
IH :
  ∀ (m : ℕ), m < Nat.succ (Nat.succ n) → m ≤ 1 ∨ ¬TerminatedAt (of v) (m - 2) → ↑(fib m) ≤ (continuantsAux (of v) m).b
hyp : Nat.succ (Nat.succ n) ≤ 1 ∨ ¬TerminatedAt (of v) (Nat.succ (Nat.succ n) - 2)
g : GeneralizedContinuedFraction K := of v
this✝¹ : ¬n + 2 ≤ 1
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_ppred_nth_eq : Stream'.Seq.get? g.s n = some gp
pconts : Pair K := continuantsAux g (n + 1)
pconts_eq : pconts = continuantsAux g (n + 1)
ppconts : Pair K := continuantsAux g n
ppconts_eq : ppconts = continuantsAux g n
not_terminated_at_pred_n : ¬TerminatedAt g (n - 1)
not_terminated_at_ppred_n : ¬TerminatedAt g (n - 2)
ppred_nth_fib_le_ppconts_B : ↑(fib n) ≤ ppconts.b
one_le_gp_b : 1 ≤ gp.b
this✝ : 0 ≤ ↑(fib (n + 1))
this : 0 ≤ gp.b
s_ppred_nth_eq_symm : some gp = Stream'.Seq.get? g.s n
⊢ n + 1 ≤ 1 ∨ ¬TerminatedAt (of v) (n + 1 - 2)
[PROOFSTEP]
tauto
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp : n = 0 ∨ ¬TerminatedAt (of v) (n - 1)
⊢ ↑(fib (n + 1)) ≤ denominators (of v) n
[PROOFSTEP]
rw [denom_eq_conts_b, nth_cont_eq_succ_nth_cont_aux]
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp : n = 0 ∨ ¬TerminatedAt (of v) (n - 1)
⊢ ↑(fib (n + 1)) ≤ (continuantsAux (of v) (n + 1)).b
[PROOFSTEP]
have : n + 1 ≤ 1 ∨ ¬(of v).TerminatedAt (n - 1) := by
  cases' n with n
  case zero => exact Or.inl <| le_refl 1
  case succ => exact Or.inr (Or.resolve_left hyp n.succ_ne_zero)
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp : n = 0 ∨ ¬TerminatedAt (of v) (n - 1)
⊢ n + 1 ≤ 1 ∨ ¬TerminatedAt (of v) (n - 1)
[PROOFSTEP]
cases' n with n
[GOAL]
case zero
K : Type u_1
v : K
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp : zero = 0 ∨ ¬TerminatedAt (of v) (zero - 1)
⊢ zero + 1 ≤ 1 ∨ ¬TerminatedAt (of v) (zero - 1)
case succ
K : Type u_1
v : K
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
n : ℕ
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
⊢ Nat.succ n + 1 ≤ 1 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
[PROOFSTEP]
case zero => exact Or.inl <| le_refl 1
[GOAL]
K : Type u_1
v : K
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp : zero = 0 ∨ ¬TerminatedAt (of v) (zero - 1)
⊢ zero + 1 ≤ 1 ∨ ¬TerminatedAt (of v) (zero - 1)
[PROOFSTEP]
case zero => exact Or.inl <| le_refl 1
[GOAL]
K : Type u_1
v : K
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp : zero = 0 ∨ ¬TerminatedAt (of v) (zero - 1)
⊢ zero + 1 ≤ 1 ∨ ¬TerminatedAt (of v) (zero - 1)
[PROOFSTEP]
exact Or.inl <| le_refl 1
[GOAL]
case succ
K : Type u_1
v : K
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
n : ℕ
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
⊢ Nat.succ n + 1 ≤ 1 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
[PROOFSTEP]
case succ => exact Or.inr (Or.resolve_left hyp n.succ_ne_zero)
[GOAL]
K : Type u_1
v : K
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
n : ℕ
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
⊢ Nat.succ n + 1 ≤ 1 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
[PROOFSTEP]
case succ => exact Or.inr (Or.resolve_left hyp n.succ_ne_zero)
[GOAL]
K : Type u_1
v : K
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
n : ℕ
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
⊢ Nat.succ n + 1 ≤ 1 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
[PROOFSTEP]
exact Or.inr (Or.resolve_left hyp n.succ_ne_zero)
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp : n = 0 ∨ ¬TerminatedAt (of v) (n - 1)
this : n + 1 ≤ 1 ∨ ¬TerminatedAt (of v) (n - 1)
⊢ ↑(fib (n + 1)) ≤ (continuantsAux (of v) (n + 1)).b
[PROOFSTEP]
exact fib_le_of_continuantsAux_b this
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
⊢ 0 ≤ (continuantsAux (of v) n).b
[PROOFSTEP]
let g := of v
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
⊢ 0 ≤ (continuantsAux (of v) n).b
[PROOFSTEP]
induction' n with n IH
[GOAL]
case zero
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
⊢ 0 ≤ (continuantsAux (of v) zero).b
case succ
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
n : ℕ
IH : 0 ≤ (continuantsAux (of v) n).b
⊢ 0 ≤ (continuantsAux (of v) (Nat.succ n)).b
[PROOFSTEP]
case zero => rfl
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
⊢ 0 ≤ (continuantsAux (of v) zero).b
[PROOFSTEP]
case zero => rfl
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
⊢ 0 ≤ (continuantsAux (of v) zero).b
[PROOFSTEP]
rfl
[GOAL]
case succ
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
n : ℕ
IH : 0 ≤ (continuantsAux (of v) n).b
⊢ 0 ≤ (continuantsAux (of v) (Nat.succ n)).b
[PROOFSTEP]
case succ =>
  cases' Decidable.em <| g.TerminatedAt (n - 1) with terminated not_terminated
  ·
    -- terminating case
    cases' n with n
    · simp [succ_eq_add_one, zero_le_one]
    · have : g.continuantsAux (n + 2) = g.continuantsAux (n + 1) := continuantsAux_stable_step_of_terminated terminated
      simp only [this, IH]
  ·
    -- non-terminating casecalc
      (0 : K) ≤ fib (n + 1) := by exact_mod_cast (n + 1).fib.zero_le
      _ ≤ ((of v).continuantsAux (n + 1)).b := fib_le_of_continuantsAux_b (Or.inr not_terminated)
[GOAL]
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
n : ℕ
IH : 0 ≤ (continuantsAux (of v) n).b
⊢ 0 ≤ (continuantsAux (of v) (Nat.succ n)).b
[PROOFSTEP]
case succ =>
  cases' Decidable.em <| g.TerminatedAt (n - 1) with terminated not_terminated
  ·
    -- terminating case
    cases' n with n
    · simp [succ_eq_add_one, zero_le_one]
    · have : g.continuantsAux (n + 2) = g.continuantsAux (n + 1) := continuantsAux_stable_step_of_terminated terminated
      simp only [this, IH]
  ·
    -- non-terminating casecalc
      (0 : K) ≤ fib (n + 1) := by exact_mod_cast (n + 1).fib.zero_le
      _ ≤ ((of v).continuantsAux (n + 1)).b := fib_le_of_continuantsAux_b (Or.inr not_terminated)
[GOAL]
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
n : ℕ
IH : 0 ≤ (continuantsAux (of v) n).b
⊢ 0 ≤ (continuantsAux (of v) (Nat.succ n)).b
[PROOFSTEP]
cases' Decidable.em <| g.TerminatedAt (n - 1) with terminated not_terminated
[GOAL]
case inl
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
n : ℕ
IH : 0 ≤ (continuantsAux (of v) n).b
terminated : TerminatedAt g (n - 1)
⊢ 0 ≤ (continuantsAux (of v) (Nat.succ n)).b
[PROOFSTEP]
cases' n with n
[GOAL]
case inl.zero
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
IH : 0 ≤ (continuantsAux (of v) zero).b
terminated : TerminatedAt g (zero - 1)
⊢ 0 ≤ (continuantsAux (of v) (Nat.succ zero)).b
[PROOFSTEP]
simp [succ_eq_add_one, zero_le_one]
[GOAL]
case inl.succ
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
n : ℕ
IH : 0 ≤ (continuantsAux (of v) (Nat.succ n)).b
terminated : TerminatedAt g (Nat.succ n - 1)
⊢ 0 ≤ (continuantsAux (of v) (Nat.succ (Nat.succ n))).b
[PROOFSTEP]
have : g.continuantsAux (n + 2) = g.continuantsAux (n + 1) := continuantsAux_stable_step_of_terminated terminated
[GOAL]
case inl.succ
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
n : ℕ
IH : 0 ≤ (continuantsAux (of v) (Nat.succ n)).b
terminated : TerminatedAt g (Nat.succ n - 1)
this : continuantsAux g (n + 2) = continuantsAux g (n + 1)
⊢ 0 ≤ (continuantsAux (of v) (Nat.succ (Nat.succ n))).b
[PROOFSTEP]
simp only [this, IH]
[GOAL]
case inr
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
n : ℕ
IH : 0 ≤ (continuantsAux (of v) n).b
not_terminated : ¬TerminatedAt g (n - 1)
⊢ 0 ≤ (continuantsAux (of v) (Nat.succ n)).b
[PROOFSTEP]
calc
  (0 : K) ≤ fib (n + 1) := by exact_mod_cast (n + 1).fib.zero_le
  _ ≤ ((of v).continuantsAux (n + 1)).b := fib_le_of_continuantsAux_b (Or.inr not_terminated)
[GOAL]
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
n : ℕ
IH : 0 ≤ (continuantsAux (of v) n).b
not_terminated : ¬TerminatedAt g (n - 1)
⊢ 0 ≤ ↑(fib (n + 1))
[PROOFSTEP]
exact_mod_cast (n + 1).fib.zero_le
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
⊢ 0 ≤ denominators (of v) n
[PROOFSTEP]
rw [denom_eq_conts_b, nth_cont_eq_succ_nth_cont_aux]
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
⊢ 0 ≤ (continuantsAux (of v) (n + 1)).b
[PROOFSTEP]
exact zero_le_of_continuantsAux_b
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
b : K
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators (of v)) n = some b
⊢ b * (continuantsAux (of v) (n + 1)).b ≤ (continuantsAux (of v) (n + 2)).b
[PROOFSTEP]
obtain ⟨gp_n, nth_s_eq, rfl⟩ : ∃ gp_n, (of v).s.get? n = some gp_n ∧ gp_n.b = b
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
b : K
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators (of v)) n = some b
⊢ ∃ gp_n, Stream'.Seq.get? (of v).s n = some gp_n ∧ gp_n.b = b
case intro.intro
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
gp_n : Pair K
nth_s_eq : Stream'.Seq.get? (of v).s n = some gp_n
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators (of v)) n = some gp_n.b
⊢ gp_n.b * (continuantsAux (of v) (n + 1)).b ≤ (continuantsAux (of v) (n + 2)).b
[PROOFSTEP]
exact exists_s_b_of_part_denom nth_part_denom_eq
[GOAL]
case intro.intro
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
gp_n : Pair K
nth_s_eq : Stream'.Seq.get? (of v).s n = some gp_n
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators (of v)) n = some gp_n.b
⊢ gp_n.b * (continuantsAux (of v) (n + 1)).b ≤ (continuantsAux (of v) (n + 2)).b
[PROOFSTEP]
simp [of_part_num_eq_one (part_num_eq_s_a nth_s_eq), zero_le_of_continuantsAux_b,
  GeneralizedContinuedFraction.continuantsAux_recurrence nth_s_eq rfl rfl]
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
b : K
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators (of v)) n = some b
⊢ b * denominators (of v) n ≤ denominators (of v) (n + 1)
[PROOFSTEP]
rw [denom_eq_conts_b, nth_cont_eq_succ_nth_cont_aux]
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
b : K
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators (of v)) n = some b
⊢ b * (continuantsAux (of v) (n + 1)).b ≤ denominators (of v) (n + 1)
[PROOFSTEP]
exact le_of_succ_succ_get?_continuantsAux_b nth_part_denom_eq
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
⊢ denominators (of v) n ≤ denominators (of v) (n + 1)
[PROOFSTEP]
let g := of v
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
⊢ denominators (of v) n ≤ denominators (of v) (n + 1)
[PROOFSTEP]
cases' Decidable.em <| g.partialDenominators.TerminatedAt n with terminated not_terminated
[GOAL]
case inl
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
terminated : Stream'.Seq.TerminatedAt (partialDenominators g) n
⊢ denominators (of v) n ≤ denominators (of v) (n + 1)
[PROOFSTEP]
have : g.partialDenominators.get? n = none := by rwa [Stream'.Seq.TerminatedAt] at terminated 
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
terminated : Stream'.Seq.TerminatedAt (partialDenominators g) n
⊢ Stream'.Seq.get? (partialDenominators g) n = none
[PROOFSTEP]
rwa [Stream'.Seq.TerminatedAt] at terminated 
[GOAL]
case inl
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
terminated : Stream'.Seq.TerminatedAt (partialDenominators g) n
this : Stream'.Seq.get? (partialDenominators g) n = none
⊢ denominators (of v) n ≤ denominators (of v) (n + 1)
[PROOFSTEP]
have : g.TerminatedAt n := terminatedAt_iff_part_denom_none.2 (by rwa [Stream'.Seq.TerminatedAt] at terminated )
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
terminated : Stream'.Seq.TerminatedAt (partialDenominators g) n
this : Stream'.Seq.get? (partialDenominators g) n = none
⊢ Stream'.Seq.get? (partialDenominators g) n = none
[PROOFSTEP]
rwa [Stream'.Seq.TerminatedAt] at terminated 
[GOAL]
case inl
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
terminated : Stream'.Seq.TerminatedAt (partialDenominators g) n
this✝ : Stream'.Seq.get? (partialDenominators g) n = none
this : TerminatedAt g n
⊢ denominators (of v) n ≤ denominators (of v) (n + 1)
[PROOFSTEP]
have : g.denominators (n + 1) = g.denominators n := denominators_stable_of_terminated n.le_succ this
[GOAL]
case inl
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
terminated : Stream'.Seq.TerminatedAt (partialDenominators g) n
this✝¹ : Stream'.Seq.get? (partialDenominators g) n = none
this✝ : TerminatedAt g n
this : denominators g (n + 1) = denominators g n
⊢ denominators (of v) n ≤ denominators (of v) (n + 1)
[PROOFSTEP]
rw [this]
[GOAL]
case inr
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
not_terminated : ¬Stream'.Seq.TerminatedAt (partialDenominators g) n
⊢ denominators (of v) n ≤ denominators (of v) (n + 1)
[PROOFSTEP]
obtain ⟨b, nth_part_denom_eq⟩ : ∃ b, g.partialDenominators.get? n = some b
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
not_terminated : ¬Stream'.Seq.TerminatedAt (partialDenominators g) n
⊢ ∃ b, Stream'.Seq.get? (partialDenominators g) n = some b
case inr.intro
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
not_terminated : ¬Stream'.Seq.TerminatedAt (partialDenominators g) n
b : K
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators g) n = some b
⊢ denominators (of v) n ≤ denominators (of v) (n + 1)
[PROOFSTEP]
exact Option.ne_none_iff_exists'.mp not_terminated
[GOAL]
case inr.intro
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
not_terminated : ¬Stream'.Seq.TerminatedAt (partialDenominators g) n
b : K
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators g) n = some b
⊢ denominators (of v) n ≤ denominators (of v) (n + 1)
[PROOFSTEP]
have : 1 ≤ b := of_one_le_get?_part_denom nth_part_denom_eq
[GOAL]
case inr.intro
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
not_terminated : ¬Stream'.Seq.TerminatedAt (partialDenominators g) n
b : K
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators g) n = some b
this : 1 ≤ b
⊢ denominators (of v) n ≤ denominators (of v) (n + 1)
[PROOFSTEP]
calc
  g.denominators n ≤ b * g.denominators n := by simpa using mul_le_mul_of_nonneg_right this zero_le_of_denom
  _ ≤ g.denominators (n + 1) := le_of_succ_get?_denom nth_part_denom_eq
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
g : GeneralizedContinuedFraction K := of v
not_terminated : ¬Stream'.Seq.TerminatedAt (partialDenominators g) n
b : K
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators g) n = some b
this : 1 ≤ b
⊢ denominators g n ≤ b * denominators g n
[PROOFSTEP]
simpa using mul_le_mul_of_nonneg_right this zero_le_of_denom
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp : n = 0 ∨ ¬TerminatedAt (of v) (n - 1)
⊢ (continuantsAux (of v) n).a * (continuantsAux (of v) (n + 1)).b -
      (continuantsAux (of v) n).b * (continuantsAux (of v) (n + 1)).a =
    (-1) ^ n
[PROOFSTEP]
induction' n with n IH
[GOAL]
case zero
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n = 0 ∨ ¬TerminatedAt (of v) (n - 1)
hyp : zero = 0 ∨ ¬TerminatedAt (of v) (zero - 1)
⊢ (continuantsAux (of v) zero).a * (continuantsAux (of v) (zero + 1)).b -
      (continuantsAux (of v) zero).b * (continuantsAux (of v) (zero + 1)).a =
    (-1) ^ zero
case succ
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n✝ = 0 ∨ ¬TerminatedAt (of v) (n✝ - 1)
n : ℕ
IH :
  n = 0 ∨ ¬TerminatedAt (of v) (n - 1) →
    (continuantsAux (of v) n).a * (continuantsAux (of v) (n + 1)).b -
        (continuantsAux (of v) n).b * (continuantsAux (of v) (n + 1)).a =
      (-1) ^ n
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
⊢ (continuantsAux (of v) (Nat.succ n)).a * (continuantsAux (of v) (Nat.succ n + 1)).b -
      (continuantsAux (of v) (Nat.succ n)).b * (continuantsAux (of v) (Nat.succ n + 1)).a =
    (-1) ^ Nat.succ n
[PROOFSTEP]
case zero => simp [continuantsAux]
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n = 0 ∨ ¬TerminatedAt (of v) (n - 1)
hyp : zero = 0 ∨ ¬TerminatedAt (of v) (zero - 1)
⊢ (continuantsAux (of v) zero).a * (continuantsAux (of v) (zero + 1)).b -
      (continuantsAux (of v) zero).b * (continuantsAux (of v) (zero + 1)).a =
    (-1) ^ zero
[PROOFSTEP]
case zero => simp [continuantsAux]
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n = 0 ∨ ¬TerminatedAt (of v) (n - 1)
hyp : zero = 0 ∨ ¬TerminatedAt (of v) (zero - 1)
⊢ (continuantsAux (of v) zero).a * (continuantsAux (of v) (zero + 1)).b -
      (continuantsAux (of v) zero).b * (continuantsAux (of v) (zero + 1)).a =
    (-1) ^ zero
[PROOFSTEP]
simp [continuantsAux]
[GOAL]
case succ
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n✝ = 0 ∨ ¬TerminatedAt (of v) (n✝ - 1)
n : ℕ
IH :
  n = 0 ∨ ¬TerminatedAt (of v) (n - 1) →
    (continuantsAux (of v) n).a * (continuantsAux (of v) (n + 1)).b -
        (continuantsAux (of v) n).b * (continuantsAux (of v) (n + 1)).a =
      (-1) ^ n
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
⊢ (continuantsAux (of v) (Nat.succ n)).a * (continuantsAux (of v) (Nat.succ n + 1)).b -
      (continuantsAux (of v) (Nat.succ n)).b * (continuantsAux (of v) (Nat.succ n + 1)).a =
    (-1) ^ Nat.succ n
[PROOFSTEP]
case succ =>
  -- set up some shorthand notation
  let g := of v
  let conts := continuantsAux g (n + 2)
  set pred_conts := continuantsAux g (n + 1) with pred_conts_eq
  set ppred_conts := continuantsAux g n with ppred_conts_eq
  let pA := pred_conts.a
  let pB := pred_conts.b
  let ppA := ppred_conts.a
  let ppB := ppred_conts.b
  change pA * conts.b - pB * conts.a = (-1) ^ (n + 1)
  have not_terminated_at_n : ¬TerminatedAt g n := Or.resolve_left hyp n.succ_ne_zero
  obtain ⟨gp, s_nth_eq⟩ : ∃ gp, g.s.get? n = some gp
  exact Option.ne_none_iff_exists'.1 not_terminated_at_n
  suffices pA * (ppB + gp.b * pB) - pB * (ppA + gp.b * pA) = (-1) ^ (n + 1)
    by
    simp only [continuantsAux_recurrence s_nth_eq ppred_conts_eq pred_conts_eq]
    have gp_a_eq_one : gp.a = 1 := of_part_num_eq_one (part_num_eq_s_a s_nth_eq)
    rw [gp_a_eq_one, this.symm]
    ring
  suffices : pA * ppB - pB * ppA = (-1) ^ (n + 1);
  calc
    pA * (ppB + gp.b * pB) - pB * (ppA + gp.b * pA) = pA * ppB + pA * gp.b * pB - pB * ppA - pB * gp.b * pA := by ring
    _ = pA * ppB - pB * ppA := by ring
    _ = (-1) ^ (n + 1) := by assumption
  suffices ppA * pB - ppB * pA = (-1) ^ n
    by
    have pow_succ_n : (-1 : K) ^ (n + 1) = -1 * (-1) ^ n := pow_succ (-1) n
    rw [pow_succ_n, ← this]
    ring
  exact IH <| Or.inr <| mt (terminated_stable <| n.sub_le 1) not_terminated_at_n
[GOAL]
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n✝ = 0 ∨ ¬TerminatedAt (of v) (n✝ - 1)
n : ℕ
IH :
  n = 0 ∨ ¬TerminatedAt (of v) (n - 1) →
    (continuantsAux (of v) n).a * (continuantsAux (of v) (n + 1)).b -
        (continuantsAux (of v) n).b * (continuantsAux (of v) (n + 1)).a =
      (-1) ^ n
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
⊢ (continuantsAux (of v) (Nat.succ n)).a * (continuantsAux (of v) (Nat.succ n + 1)).b -
      (continuantsAux (of v) (Nat.succ n)).b * (continuantsAux (of v) (Nat.succ n + 1)).a =
    (-1) ^ Nat.succ n
[PROOFSTEP]
case succ =>
  -- set up some shorthand notation
  let g := of v
  let conts := continuantsAux g (n + 2)
  set pred_conts := continuantsAux g (n + 1) with pred_conts_eq
  set ppred_conts := continuantsAux g n with ppred_conts_eq
  let pA := pred_conts.a
  let pB := pred_conts.b
  let ppA := ppred_conts.a
  let ppB := ppred_conts.b
  change pA * conts.b - pB * conts.a = (-1) ^ (n + 1)
  have not_terminated_at_n : ¬TerminatedAt g n := Or.resolve_left hyp n.succ_ne_zero
  obtain ⟨gp, s_nth_eq⟩ : ∃ gp, g.s.get? n = some gp
  exact Option.ne_none_iff_exists'.1 not_terminated_at_n
  suffices pA * (ppB + gp.b * pB) - pB * (ppA + gp.b * pA) = (-1) ^ (n + 1)
    by
    simp only [continuantsAux_recurrence s_nth_eq ppred_conts_eq pred_conts_eq]
    have gp_a_eq_one : gp.a = 1 := of_part_num_eq_one (part_num_eq_s_a s_nth_eq)
    rw [gp_a_eq_one, this.symm]
    ring
  suffices : pA * ppB - pB * ppA = (-1) ^ (n + 1);
  calc
    pA * (ppB + gp.b * pB) - pB * (ppA + gp.b * pA) = pA * ppB + pA * gp.b * pB - pB * ppA - pB * gp.b * pA := by ring
    _ = pA * ppB - pB * ppA := by ring
    _ = (-1) ^ (n + 1) := by assumption
  suffices ppA * pB - ppB * pA = (-1) ^ n
    by
    have pow_succ_n : (-1 : K) ^ (n + 1) = -1 * (-1) ^ n := pow_succ (-1) n
    rw [pow_succ_n, ← this]
    ring
  exact IH <| Or.inr <| mt (terminated_stable <| n.sub_le 1) not_terminated_at_n
[GOAL]
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n✝ = 0 ∨ ¬TerminatedAt (of v) (n✝ - 1)
n : ℕ
IH :
  n = 0 ∨ ¬TerminatedAt (of v) (n - 1) →
    (continuantsAux (of v) n).a * (continuantsAux (of v) (n + 1)).b -
        (continuantsAux (of v) n).b * (continuantsAux (of v) (n + 1)).a =
      (-1) ^ n
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
⊢ (continuantsAux (of v) (Nat.succ n)).a * (continuantsAux (of v) (Nat.succ n + 1)).b -
      (continuantsAux (of v) (Nat.succ n)).b * (continuantsAux (of v) (Nat.succ n + 1)).a =
    (-1) ^ Nat.succ n
[PROOFSTEP]
let g := of v
[GOAL]
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n✝ = 0 ∨ ¬TerminatedAt (of v) (n✝ - 1)
n : ℕ
IH :
  n = 0 ∨ ¬TerminatedAt (of v) (n - 1) →
    (continuantsAux (of v) n).a * (continuantsAux (of v) (n + 1)).b -
        (continuantsAux (of v) n).b * (continuantsAux (of v) (n + 1)).a =
      (-1) ^ n
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
g : GeneralizedContinuedFraction K := of v
⊢ (continuantsAux (of v) (Nat.succ n)).a * (continuantsAux (of v) (Nat.succ n + 1)).b -
      (continuantsAux (of v) (Nat.succ n)).b * (continuantsAux (of v) (Nat.succ n + 1)).a =
    (-1) ^ Nat.succ n
[PROOFSTEP]
let conts := continuantsAux g (n + 2)
[GOAL]
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n✝ = 0 ∨ ¬TerminatedAt (of v) (n✝ - 1)
n : ℕ
IH :
  n = 0 ∨ ¬TerminatedAt (of v) (n - 1) →
    (continuantsAux (of v) n).a * (continuantsAux (of v) (n + 1)).b -
        (continuantsAux (of v) n).b * (continuantsAux (of v) (n + 1)).a =
      (-1) ^ n
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 2)
⊢ (continuantsAux (of v) (Nat.succ n)).a * (continuantsAux (of v) (Nat.succ n + 1)).b -
      (continuantsAux (of v) (Nat.succ n)).b * (continuantsAux (of v) (Nat.succ n + 1)).a =
    (-1) ^ Nat.succ n
[PROOFSTEP]
set pred_conts := continuantsAux g (n + 1) with pred_conts_eq
[GOAL]
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n✝ = 0 ∨ ¬TerminatedAt (of v) (n✝ - 1)
n : ℕ
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 2)
pred_conts : Pair K := continuantsAux g (n + 1)
IH :
  n = 0 ∨ ¬TerminatedAt (of v) (n - 1) →
    (continuantsAux (of v) n).a * pred_conts.b - (continuantsAux (of v) n).b * pred_conts.a = (-1) ^ n
pred_conts_eq : pred_conts = continuantsAux g (n + 1)
⊢ pred_conts.a * (continuantsAux (of v) (Nat.succ n + 1)).b -
      pred_conts.b * (continuantsAux (of v) (Nat.succ n + 1)).a =
    (-1) ^ Nat.succ n
[PROOFSTEP]
set ppred_conts := continuantsAux g n with ppred_conts_eq
[GOAL]
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n✝ = 0 ∨ ¬TerminatedAt (of v) (n✝ - 1)
n : ℕ
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 2)
pred_conts : Pair K := continuantsAux g (n + 1)
pred_conts_eq : pred_conts = continuantsAux g (n + 1)
ppred_conts : Pair K := continuantsAux g n
IH : n = 0 ∨ ¬TerminatedAt (of v) (n - 1) → ppred_conts.a * pred_conts.b - ppred_conts.b * pred_conts.a = (-1) ^ n
ppred_conts_eq : ppred_conts = continuantsAux g n
⊢ pred_conts.a * (continuantsAux (of v) (Nat.succ n + 1)).b -
      pred_conts.b * (continuantsAux (of v) (Nat.succ n + 1)).a =
    (-1) ^ Nat.succ n
[PROOFSTEP]
let pA := pred_conts.a
[GOAL]
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n✝ = 0 ∨ ¬TerminatedAt (of v) (n✝ - 1)
n : ℕ
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 2)
pred_conts : Pair K := continuantsAux g (n + 1)
pred_conts_eq : pred_conts = continuantsAux g (n + 1)
ppred_conts : Pair K := continuantsAux g n
IH : n = 0 ∨ ¬TerminatedAt (of v) (n - 1) → ppred_conts.a * pred_conts.b - ppred_conts.b * pred_conts.a = (-1) ^ n
ppred_conts_eq : ppred_conts = continuantsAux g n
pA : K := pred_conts.a
⊢ pred_conts.a * (continuantsAux (of v) (Nat.succ n + 1)).b -
      pred_conts.b * (continuantsAux (of v) (Nat.succ n + 1)).a =
    (-1) ^ Nat.succ n
[PROOFSTEP]
let pB := pred_conts.b
[GOAL]
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n✝ = 0 ∨ ¬TerminatedAt (of v) (n✝ - 1)
n : ℕ
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 2)
pred_conts : Pair K := continuantsAux g (n + 1)
pred_conts_eq : pred_conts = continuantsAux g (n + 1)
ppred_conts : Pair K := continuantsAux g n
IH : n = 0 ∨ ¬TerminatedAt (of v) (n - 1) → ppred_conts.a * pred_conts.b - ppred_conts.b * pred_conts.a = (-1) ^ n
ppred_conts_eq : ppred_conts = continuantsAux g n
pA : K := pred_conts.a
pB : K := pred_conts.b
⊢ pred_conts.a * (continuantsAux (of v) (Nat.succ n + 1)).b -
      pred_conts.b * (continuantsAux (of v) (Nat.succ n + 1)).a =
    (-1) ^ Nat.succ n
[PROOFSTEP]
let ppA := ppred_conts.a
[GOAL]
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n✝ = 0 ∨ ¬TerminatedAt (of v) (n✝ - 1)
n : ℕ
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 2)
pred_conts : Pair K := continuantsAux g (n + 1)
pred_conts_eq : pred_conts = continuantsAux g (n + 1)
ppred_conts : Pair K := continuantsAux g n
IH : n = 0 ∨ ¬TerminatedAt (of v) (n - 1) → ppred_conts.a * pred_conts.b - ppred_conts.b * pred_conts.a = (-1) ^ n
ppred_conts_eq : ppred_conts = continuantsAux g n
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
⊢ pred_conts.a * (continuantsAux (of v) (Nat.succ n + 1)).b -
      pred_conts.b * (continuantsAux (of v) (Nat.succ n + 1)).a =
    (-1) ^ Nat.succ n
[PROOFSTEP]
let ppB := ppred_conts.b
[GOAL]
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n✝ = 0 ∨ ¬TerminatedAt (of v) (n✝ - 1)
n : ℕ
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 2)
pred_conts : Pair K := continuantsAux g (n + 1)
pred_conts_eq : pred_conts = continuantsAux g (n + 1)
ppred_conts : Pair K := continuantsAux g n
IH : n = 0 ∨ ¬TerminatedAt (of v) (n - 1) → ppred_conts.a * pred_conts.b - ppred_conts.b * pred_conts.a = (-1) ^ n
ppred_conts_eq : ppred_conts = continuantsAux g n
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
⊢ pred_conts.a * (continuantsAux (of v) (Nat.succ n + 1)).b -
      pred_conts.b * (continuantsAux (of v) (Nat.succ n + 1)).a =
    (-1) ^ Nat.succ n
[PROOFSTEP]
change pA * conts.b - pB * conts.a = (-1) ^ (n + 1)
[GOAL]
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n✝ = 0 ∨ ¬TerminatedAt (of v) (n✝ - 1)
n : ℕ
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 2)
pred_conts : Pair K := continuantsAux g (n + 1)
pred_conts_eq : pred_conts = continuantsAux g (n + 1)
ppred_conts : Pair K := continuantsAux g n
IH : n = 0 ∨ ¬TerminatedAt (of v) (n - 1) → ppred_conts.a * pred_conts.b - ppred_conts.b * pred_conts.a = (-1) ^ n
ppred_conts_eq : ppred_conts = continuantsAux g n
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
⊢ pA * conts.b - pB * conts.a = (-1) ^ (n + 1)
[PROOFSTEP]
have not_terminated_at_n : ¬TerminatedAt g n := Or.resolve_left hyp n.succ_ne_zero
[GOAL]
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n✝ = 0 ∨ ¬TerminatedAt (of v) (n✝ - 1)
n : ℕ
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 2)
pred_conts : Pair K := continuantsAux g (n + 1)
pred_conts_eq : pred_conts = continuantsAux g (n + 1)
ppred_conts : Pair K := continuantsAux g n
IH : n = 0 ∨ ¬TerminatedAt (of v) (n - 1) → ppred_conts.a * pred_conts.b - ppred_conts.b * pred_conts.a = (-1) ^ n
ppred_conts_eq : ppred_conts = continuantsAux g n
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
not_terminated_at_n : ¬TerminatedAt g n
⊢ pA * conts.b - pB * conts.a = (-1) ^ (n + 1)
[PROOFSTEP]
obtain ⟨gp, s_nth_eq⟩ : ∃ gp, g.s.get? n = some gp
[GOAL]
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n✝ = 0 ∨ ¬TerminatedAt (of v) (n✝ - 1)
n : ℕ
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 2)
pred_conts : Pair K := continuantsAux g (n + 1)
pred_conts_eq : pred_conts = continuantsAux g (n + 1)
ppred_conts : Pair K := continuantsAux g n
IH : n = 0 ∨ ¬TerminatedAt (of v) (n - 1) → ppred_conts.a * pred_conts.b - ppred_conts.b * pred_conts.a = (-1) ^ n
ppred_conts_eq : ppred_conts = continuantsAux g n
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
not_terminated_at_n : ¬TerminatedAt g n
⊢ ∃ gp, Stream'.Seq.get? g.s n = some gp
case intro
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n✝ = 0 ∨ ¬TerminatedAt (of v) (n✝ - 1)
n : ℕ
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 2)
pred_conts : Pair K := continuantsAux g (n + 1)
pred_conts_eq : pred_conts = continuantsAux g (n + 1)
ppred_conts : Pair K := continuantsAux g n
IH : n = 0 ∨ ¬TerminatedAt (of v) (n - 1) → ppred_conts.a * pred_conts.b - ppred_conts.b * pred_conts.a = (-1) ^ n
ppred_conts_eq : ppred_conts = continuantsAux g n
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
⊢ pA * conts.b - pB * conts.a = (-1) ^ (n + 1)
[PROOFSTEP]
exact Option.ne_none_iff_exists'.1 not_terminated_at_n
[GOAL]
case intro
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n✝ = 0 ∨ ¬TerminatedAt (of v) (n✝ - 1)
n : ℕ
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 2)
pred_conts : Pair K := continuantsAux g (n + 1)
pred_conts_eq : pred_conts = continuantsAux g (n + 1)
ppred_conts : Pair K := continuantsAux g n
IH : n = 0 ∨ ¬TerminatedAt (of v) (n - 1) → ppred_conts.a * pred_conts.b - ppred_conts.b * pred_conts.a = (-1) ^ n
ppred_conts_eq : ppred_conts = continuantsAux g n
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
⊢ pA * conts.b - pB * conts.a = (-1) ^ (n + 1)
[PROOFSTEP]
suffices pA * (ppB + gp.b * pB) - pB * (ppA + gp.b * pA) = (-1) ^ (n + 1)
  by
  simp only [continuantsAux_recurrence s_nth_eq ppred_conts_eq pred_conts_eq]
  have gp_a_eq_one : gp.a = 1 := of_part_num_eq_one (part_num_eq_s_a s_nth_eq)
  rw [gp_a_eq_one, this.symm]
  ring
[GOAL]
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n✝ = 0 ∨ ¬TerminatedAt (of v) (n✝ - 1)
n : ℕ
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 2)
pred_conts : Pair K := continuantsAux g (n + 1)
pred_conts_eq : pred_conts = continuantsAux g (n + 1)
ppred_conts : Pair K := continuantsAux g n
IH : n = 0 ∨ ¬TerminatedAt (of v) (n - 1) → ppred_conts.a * pred_conts.b - ppred_conts.b * pred_conts.a = (-1) ^ n
ppred_conts_eq : ppred_conts = continuantsAux g n
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
this : pA * (ppB + gp.b * pB) - pB * (ppA + gp.b * pA) = (-1) ^ (n + 1)
⊢ pA * conts.b - pB * conts.a = (-1) ^ (n + 1)
[PROOFSTEP]
simp only [continuantsAux_recurrence s_nth_eq ppred_conts_eq pred_conts_eq]
[GOAL]
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n✝ = 0 ∨ ¬TerminatedAt (of v) (n✝ - 1)
n : ℕ
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 2)
pred_conts : Pair K := continuantsAux g (n + 1)
pred_conts_eq : pred_conts = continuantsAux g (n + 1)
ppred_conts : Pair K := continuantsAux g n
IH : n = 0 ∨ ¬TerminatedAt (of v) (n - 1) → ppred_conts.a * pred_conts.b - ppred_conts.b * pred_conts.a = (-1) ^ n
ppred_conts_eq : ppred_conts = continuantsAux g n
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
this : pA * (ppB + gp.b * pB) - pB * (ppA + gp.b * pA) = (-1) ^ (n + 1)
⊢ (continuantsAux (of v) (n + 1)).a * (gp.b * (continuantsAux (of v) (n + 1)).b + gp.a * (continuantsAux (of v) n).b) -
      (continuantsAux (of v) (n + 1)).b *
        (gp.b * (continuantsAux (of v) (n + 1)).a + gp.a * (continuantsAux (of v) n).a) =
    (-1) ^ (n + 1)
[PROOFSTEP]
have gp_a_eq_one : gp.a = 1 := of_part_num_eq_one (part_num_eq_s_a s_nth_eq)
[GOAL]
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n✝ = 0 ∨ ¬TerminatedAt (of v) (n✝ - 1)
n : ℕ
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 2)
pred_conts : Pair K := continuantsAux g (n + 1)
pred_conts_eq : pred_conts = continuantsAux g (n + 1)
ppred_conts : Pair K := continuantsAux g n
IH : n = 0 ∨ ¬TerminatedAt (of v) (n - 1) → ppred_conts.a * pred_conts.b - ppred_conts.b * pred_conts.a = (-1) ^ n
ppred_conts_eq : ppred_conts = continuantsAux g n
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
this : pA * (ppB + gp.b * pB) - pB * (ppA + gp.b * pA) = (-1) ^ (n + 1)
gp_a_eq_one : gp.a = 1
⊢ (continuantsAux (of v) (n + 1)).a * (gp.b * (continuantsAux (of v) (n + 1)).b + gp.a * (continuantsAux (of v) n).b) -
      (continuantsAux (of v) (n + 1)).b *
        (gp.b * (continuantsAux (of v) (n + 1)).a + gp.a * (continuantsAux (of v) n).a) =
    (-1) ^ (n + 1)
[PROOFSTEP]
rw [gp_a_eq_one, this.symm]
[GOAL]
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n✝ = 0 ∨ ¬TerminatedAt (of v) (n✝ - 1)
n : ℕ
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 2)
pred_conts : Pair K := continuantsAux g (n + 1)
pred_conts_eq : pred_conts = continuantsAux g (n + 1)
ppred_conts : Pair K := continuantsAux g n
IH : n = 0 ∨ ¬TerminatedAt (of v) (n - 1) → ppred_conts.a * pred_conts.b - ppred_conts.b * pred_conts.a = (-1) ^ n
ppred_conts_eq : ppred_conts = continuantsAux g n
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
this : pA * (ppB + gp.b * pB) - pB * (ppA + gp.b * pA) = (-1) ^ (n + 1)
gp_a_eq_one : gp.a = 1
⊢ (continuantsAux (of v) (n + 1)).a * (gp.b * (continuantsAux (of v) (n + 1)).b + 1 * (continuantsAux (of v) n).b) -
      (continuantsAux (of v) (n + 1)).b * (gp.b * (continuantsAux (of v) (n + 1)).a + 1 * (continuantsAux (of v) n).a) =
    pA * (ppB + gp.b * pB) - pB * (ppA + gp.b * pA)
[PROOFSTEP]
ring
[GOAL]
case intro
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n✝ = 0 ∨ ¬TerminatedAt (of v) (n✝ - 1)
n : ℕ
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 2)
pred_conts : Pair K := continuantsAux g (n + 1)
pred_conts_eq : pred_conts = continuantsAux g (n + 1)
ppred_conts : Pair K := continuantsAux g n
IH : n = 0 ∨ ¬TerminatedAt (of v) (n - 1) → ppred_conts.a * pred_conts.b - ppred_conts.b * pred_conts.a = (-1) ^ n
ppred_conts_eq : ppred_conts = continuantsAux g n
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
⊢ pA * (ppB + gp.b * pB) - pB * (ppA + gp.b * pA) = (-1) ^ (n + 1)
[PROOFSTEP]
suffices : pA * ppB - pB * ppA = (-1) ^ (n + 1)
[GOAL]
case intro
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n✝ = 0 ∨ ¬TerminatedAt (of v) (n✝ - 1)
n : ℕ
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 2)
pred_conts : Pair K := continuantsAux g (n + 1)
pred_conts_eq : pred_conts = continuantsAux g (n + 1)
ppred_conts : Pair K := continuantsAux g n
IH : n = 0 ∨ ¬TerminatedAt (of v) (n - 1) → ppred_conts.a * pred_conts.b - ppred_conts.b * pred_conts.a = (-1) ^ n
ppred_conts_eq : ppred_conts = continuantsAux g n
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
this : pA * ppB - pB * ppA = (-1) ^ (n + 1)
⊢ pA * (ppB + gp.b * pB) - pB * (ppA + gp.b * pA) = (-1) ^ (n + 1)
case this
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n✝ = 0 ∨ ¬TerminatedAt (of v) (n✝ - 1)
n : ℕ
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 2)
pred_conts : Pair K := continuantsAux g (n + 1)
pred_conts_eq : pred_conts = continuantsAux g (n + 1)
ppred_conts : Pair K := continuantsAux g n
IH : n = 0 ∨ ¬TerminatedAt (of v) (n - 1) → ppred_conts.a * pred_conts.b - ppred_conts.b * pred_conts.a = (-1) ^ n
ppred_conts_eq : ppred_conts = continuantsAux g n
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
⊢ pA * ppB - pB * ppA = (-1) ^ (n + 1)
[PROOFSTEP]
calc
  pA * (ppB + gp.b * pB) - pB * (ppA + gp.b * pA) = pA * ppB + pA * gp.b * pB - pB * ppA - pB * gp.b * pA := by ring
  _ = pA * ppB - pB * ppA := by ring
  _ = (-1) ^ (n + 1) := by assumption
[GOAL]
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n✝ = 0 ∨ ¬TerminatedAt (of v) (n✝ - 1)
n : ℕ
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 2)
pred_conts : Pair K := continuantsAux g (n + 1)
pred_conts_eq : pred_conts = continuantsAux g (n + 1)
ppred_conts : Pair K := continuantsAux g n
IH : n = 0 ∨ ¬TerminatedAt (of v) (n - 1) → ppred_conts.a * pred_conts.b - ppred_conts.b * pred_conts.a = (-1) ^ n
ppred_conts_eq : ppred_conts = continuantsAux g n
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
this : pA * ppB - pB * ppA = (-1) ^ (n + 1)
⊢ pA * (ppB + gp.b * pB) - pB * (ppA + gp.b * pA) = pA * ppB + pA * gp.b * pB - pB * ppA - pB * gp.b * pA
[PROOFSTEP]
ring
[GOAL]
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n✝ = 0 ∨ ¬TerminatedAt (of v) (n✝ - 1)
n : ℕ
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 2)
pred_conts : Pair K := continuantsAux g (n + 1)
pred_conts_eq : pred_conts = continuantsAux g (n + 1)
ppred_conts : Pair K := continuantsAux g n
IH : n = 0 ∨ ¬TerminatedAt (of v) (n - 1) → ppred_conts.a * pred_conts.b - ppred_conts.b * pred_conts.a = (-1) ^ n
ppred_conts_eq : ppred_conts = continuantsAux g n
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
this : pA * ppB - pB * ppA = (-1) ^ (n + 1)
⊢ pA * ppB + pA * gp.b * pB - pB * ppA - pB * gp.b * pA = pA * ppB - pB * ppA
[PROOFSTEP]
ring
[GOAL]
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n✝ = 0 ∨ ¬TerminatedAt (of v) (n✝ - 1)
n : ℕ
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 2)
pred_conts : Pair K := continuantsAux g (n + 1)
pred_conts_eq : pred_conts = continuantsAux g (n + 1)
ppred_conts : Pair K := continuantsAux g n
IH : n = 0 ∨ ¬TerminatedAt (of v) (n - 1) → ppred_conts.a * pred_conts.b - ppred_conts.b * pred_conts.a = (-1) ^ n
ppred_conts_eq : ppred_conts = continuantsAux g n
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
this : pA * ppB - pB * ppA = (-1) ^ (n + 1)
⊢ pA * ppB - pB * ppA = (-1) ^ (n + 1)
[PROOFSTEP]
assumption
[GOAL]
case this
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n✝ = 0 ∨ ¬TerminatedAt (of v) (n✝ - 1)
n : ℕ
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 2)
pred_conts : Pair K := continuantsAux g (n + 1)
pred_conts_eq : pred_conts = continuantsAux g (n + 1)
ppred_conts : Pair K := continuantsAux g n
IH : n = 0 ∨ ¬TerminatedAt (of v) (n - 1) → ppred_conts.a * pred_conts.b - ppred_conts.b * pred_conts.a = (-1) ^ n
ppred_conts_eq : ppred_conts = continuantsAux g n
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
⊢ pA * ppB - pB * ppA = (-1) ^ (n + 1)
[PROOFSTEP]
suffices ppA * pB - ppB * pA = (-1) ^ n
  by
  have pow_succ_n : (-1 : K) ^ (n + 1) = -1 * (-1) ^ n := pow_succ (-1) n
  rw [pow_succ_n, ← this]
  ring
[GOAL]
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n✝ = 0 ∨ ¬TerminatedAt (of v) (n✝ - 1)
n : ℕ
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 2)
pred_conts : Pair K := continuantsAux g (n + 1)
pred_conts_eq : pred_conts = continuantsAux g (n + 1)
ppred_conts : Pair K := continuantsAux g n
IH : n = 0 ∨ ¬TerminatedAt (of v) (n - 1) → ppred_conts.a * pred_conts.b - ppred_conts.b * pred_conts.a = (-1) ^ n
ppred_conts_eq : ppred_conts = continuantsAux g n
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
this : ppA * pB - ppB * pA = (-1) ^ n
⊢ pA * ppB - pB * ppA = (-1) ^ (n + 1)
[PROOFSTEP]
have pow_succ_n : (-1 : K) ^ (n + 1) = -1 * (-1) ^ n := pow_succ (-1) n
[GOAL]
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n✝ = 0 ∨ ¬TerminatedAt (of v) (n✝ - 1)
n : ℕ
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 2)
pred_conts : Pair K := continuantsAux g (n + 1)
pred_conts_eq : pred_conts = continuantsAux g (n + 1)
ppred_conts : Pair K := continuantsAux g n
IH : n = 0 ∨ ¬TerminatedAt (of v) (n - 1) → ppred_conts.a * pred_conts.b - ppred_conts.b * pred_conts.a = (-1) ^ n
ppred_conts_eq : ppred_conts = continuantsAux g n
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
this : ppA * pB - ppB * pA = (-1) ^ n
pow_succ_n : (-1) ^ (n + 1) = -1 * (-1) ^ n
⊢ pA * ppB - pB * ppA = (-1) ^ (n + 1)
[PROOFSTEP]
rw [pow_succ_n, ← this]
[GOAL]
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n✝ = 0 ∨ ¬TerminatedAt (of v) (n✝ - 1)
n : ℕ
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 2)
pred_conts : Pair K := continuantsAux g (n + 1)
pred_conts_eq : pred_conts = continuantsAux g (n + 1)
ppred_conts : Pair K := continuantsAux g n
IH : n = 0 ∨ ¬TerminatedAt (of v) (n - 1) → ppred_conts.a * pred_conts.b - ppred_conts.b * pred_conts.a = (-1) ^ n
ppred_conts_eq : ppred_conts = continuantsAux g n
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
this : ppA * pB - ppB * pA = (-1) ^ n
pow_succ_n : (-1) ^ (n + 1) = -1 * (-1) ^ n
⊢ pA * ppB - pB * ppA = -1 * (ppA * pB - ppB * pA)
[PROOFSTEP]
ring
[GOAL]
case this
K : Type u_1
v : K
n✝ : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
hyp✝ : n✝ = 0 ∨ ¬TerminatedAt (of v) (n✝ - 1)
n : ℕ
hyp : Nat.succ n = 0 ∨ ¬TerminatedAt (of v) (Nat.succ n - 1)
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 2)
pred_conts : Pair K := continuantsAux g (n + 1)
pred_conts_eq : pred_conts = continuantsAux g (n + 1)
ppred_conts : Pair K := continuantsAux g n
IH : n = 0 ∨ ¬TerminatedAt (of v) (n - 1) → ppred_conts.a * pred_conts.b - ppred_conts.b * pred_conts.a = (-1) ^ n
ppred_conts_eq : ppred_conts = continuantsAux g n
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
⊢ ppA * pB - ppB * pA = (-1) ^ n
[PROOFSTEP]
exact IH <| Or.inr <| mt (terminated_stable <| n.sub_le 1) not_terminated_at_n
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
⊢ let g := of v;
  let B := (continuantsAux g (n + 1)).b;
  let pB := (continuantsAux g n).b;
  v - convergents g n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
[PROOFSTEP]
let g := of v
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
⊢ let g := of v;
  let B := (continuantsAux g (n + 1)).b;
  let pB := (continuantsAux g n).b;
  v - convergents g n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
[PROOFSTEP]
let conts := g.continuantsAux (n + 1)
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
⊢ let g := of v;
  let B := (continuantsAux g (n + 1)).b;
  let pB := (continuantsAux g n).b;
  v - convergents g n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
[PROOFSTEP]
let pred_conts := g.continuantsAux n
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
⊢ let g := of v;
  let B := (continuantsAux g (n + 1)).b;
  let pB := (continuantsAux g n).b;
  v - convergents g n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
[PROOFSTEP]
have g_finite_correctness : v = GeneralizedContinuedFraction.compExactValue pred_conts conts ifp.fr :=
  compExactValue_correctness_of_stream_eq_some stream_nth_eq
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
g_finite_correctness : v = GeneralizedContinuedFraction.compExactValue pred_conts conts ifp.fr
⊢ let g := of v;
  let B := (continuantsAux g (n + 1)).b;
  let pB := (continuantsAux g n).b;
  v - convergents g n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
[PROOFSTEP]
cases' Decidable.em (ifp.fr = 0) with ifp_fr_eq_zero ifp_fr_ne_zero
[GOAL]
case inl
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
g_finite_correctness : v = GeneralizedContinuedFraction.compExactValue pred_conts conts ifp.fr
ifp_fr_eq_zero : ifp.fr = 0
⊢ let g := of v;
  let B := (continuantsAux g (n + 1)).b;
  let pB := (continuantsAux g n).b;
  v - convergents g n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
[PROOFSTEP]
suffices v - g.convergents n = 0 by simpa [ifp_fr_eq_zero]
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
g_finite_correctness : v = GeneralizedContinuedFraction.compExactValue pred_conts conts ifp.fr
ifp_fr_eq_zero : ifp.fr = 0
this : v - convergents g n = 0
⊢ let g := of v;
  let B := (continuantsAux g (n + 1)).b;
  let pB := (continuantsAux g n).b;
  v - convergents g n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
[PROOFSTEP]
simpa [ifp_fr_eq_zero]
[GOAL]
case inl
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
g_finite_correctness : v = GeneralizedContinuedFraction.compExactValue pred_conts conts ifp.fr
ifp_fr_eq_zero : ifp.fr = 0
⊢ v - convergents g n = 0
[PROOFSTEP]
replace g_finite_correctness : v = g.convergents n
[GOAL]
case g_finite_correctness
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
g_finite_correctness : v = GeneralizedContinuedFraction.compExactValue pred_conts conts ifp.fr
ifp_fr_eq_zero : ifp.fr = 0
⊢ v = convergents g n
[PROOFSTEP]
simpa [GeneralizedContinuedFraction.compExactValue, ifp_fr_eq_zero] using g_finite_correctness
[GOAL]
case inl
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_eq_zero : ifp.fr = 0
g_finite_correctness : v = convergents g n
⊢ v - convergents g n = 0
[PROOFSTEP]
exact sub_eq_zero.2 g_finite_correctness
[GOAL]
case inr
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
g_finite_correctness : v = GeneralizedContinuedFraction.compExactValue pred_conts conts ifp.fr
ifp_fr_ne_zero : ¬ifp.fr = 0
⊢ let g := of v;
  let B := (continuantsAux g (n + 1)).b;
  let pB := (continuantsAux g n).b;
  v - convergents g n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
[PROOFSTEP]
let A := conts.a
[GOAL]
case inr
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
g_finite_correctness : v = GeneralizedContinuedFraction.compExactValue pred_conts conts ifp.fr
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
⊢ let g := of v;
  let B := (continuantsAux g (n + 1)).b;
  let pB := (continuantsAux g n).b;
  v - convergents g n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
[PROOFSTEP]
let B := conts.b
[GOAL]
case inr
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
g_finite_correctness : v = GeneralizedContinuedFraction.compExactValue pred_conts conts ifp.fr
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
⊢ let g := of v;
  let B := (continuantsAux g (n + 1)).b;
  let pB := (continuantsAux g n).b;
  v - convergents g n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
[PROOFSTEP]
let pA := pred_conts.a
[GOAL]
case inr
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
g_finite_correctness : v = GeneralizedContinuedFraction.compExactValue pred_conts conts ifp.fr
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
⊢ let g := of v;
  let B := (continuantsAux g (n + 1)).b;
  let pB := (continuantsAux g n).b;
  v - convergents g n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
[PROOFSTEP]
let pB := pred_conts.b
[GOAL]
case inr
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
g_finite_correctness : v = GeneralizedContinuedFraction.compExactValue pred_conts conts ifp.fr
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
⊢ let g := of v;
  let B := (continuantsAux g (n + 1)).b;
  let pB := (continuantsAux g n).b;
  v - convergents g n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
[PROOFSTEP]
suffices v - A / B = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB)) by
  simpa [ifp_fr_ne_zero]
    -- now we can unfold `g.compExactValue` to derive the following equality for `v`
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
g_finite_correctness : v = GeneralizedContinuedFraction.compExactValue pred_conts conts ifp.fr
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
this : v - A / B = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
⊢ let g := of v;
  let B := (continuantsAux g (n + 1)).b;
  let pB := (continuantsAux g n).b;
  v - convergents g n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
[PROOFSTEP]
simpa [ifp_fr_ne_zero]
  -- now we can unfold `g.compExactValue` to derive the following equality for `v`
[GOAL]
case inr
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
g_finite_correctness : v = GeneralizedContinuedFraction.compExactValue pred_conts conts ifp.fr
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
⊢ v - A / B = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
[PROOFSTEP]
replace g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
[GOAL]
case g_finite_correctness
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
g_finite_correctness : v = GeneralizedContinuedFraction.compExactValue pred_conts conts ifp.fr
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
⊢ v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
[PROOFSTEP]
simpa [GeneralizedContinuedFraction.compExactValue, ifp_fr_ne_zero, nextContinuants, nextNumerator, nextDenominator,
  add_comm] using g_finite_correctness
[GOAL]
case inr
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
⊢ v - A / B = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
[PROOFSTEP]
suffices (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B) - A / B = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB)) by
  rwa [g_finite_correctness]
    -- To continue, we need use the determinant equality. So let's derive the needed hypothesis.
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
this : (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B) - A / B = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
⊢ v - A / B = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
[PROOFSTEP]
rwa [g_finite_correctness]
  -- To continue, we need use the determinant equality. So let's derive the needed hypothesis.
[GOAL]
case inr
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
⊢ (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B) - A / B = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
[PROOFSTEP]
have n_eq_zero_or_not_terminated_at_pred_n : n = 0 ∨ ¬g.TerminatedAt (n - 1) :=
  by
  cases' n with n'
  · simp
  · have : IntFractPair.stream v (n' + 1) ≠ none := by simp [stream_nth_eq]
    have : ¬g.TerminatedAt n' := (not_congr of_terminatedAt_n_iff_succ_nth_intFractPair_stream_eq_none).2 this
    exact Or.inr this
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
⊢ n = 0 ∨ ¬TerminatedAt g (n - 1)
[PROOFSTEP]
cases' n with n'
[GOAL]
case zero
K : Type u_1
v : K
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
g : GeneralizedContinuedFraction K := of v
ifp_fr_ne_zero : ¬ifp.fr = 0
stream_nth_eq : IntFractPair.stream v zero = some ifp
conts : Pair K := continuantsAux g (zero + 1)
pred_conts : Pair K := continuantsAux g zero
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
⊢ zero = 0 ∨ ¬TerminatedAt g (zero - 1)
[PROOFSTEP]
simp
[GOAL]
case succ
K : Type u_1
v : K
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
g : GeneralizedContinuedFraction K := of v
ifp_fr_ne_zero : ¬ifp.fr = 0
n' : ℕ
stream_nth_eq : IntFractPair.stream v (Nat.succ n') = some ifp
conts : Pair K := continuantsAux g (Nat.succ n' + 1)
pred_conts : Pair K := continuantsAux g (Nat.succ n')
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
⊢ Nat.succ n' = 0 ∨ ¬TerminatedAt g (Nat.succ n' - 1)
[PROOFSTEP]
have : IntFractPair.stream v (n' + 1) ≠ none := by simp [stream_nth_eq]
[GOAL]
K : Type u_1
v : K
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
g : GeneralizedContinuedFraction K := of v
ifp_fr_ne_zero : ¬ifp.fr = 0
n' : ℕ
stream_nth_eq : IntFractPair.stream v (Nat.succ n') = some ifp
conts : Pair K := continuantsAux g (Nat.succ n' + 1)
pred_conts : Pair K := continuantsAux g (Nat.succ n')
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
⊢ IntFractPair.stream v (n' + 1) ≠ none
[PROOFSTEP]
simp [stream_nth_eq]
[GOAL]
case succ
K : Type u_1
v : K
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
g : GeneralizedContinuedFraction K := of v
ifp_fr_ne_zero : ¬ifp.fr = 0
n' : ℕ
stream_nth_eq : IntFractPair.stream v (Nat.succ n') = some ifp
conts : Pair K := continuantsAux g (Nat.succ n' + 1)
pred_conts : Pair K := continuantsAux g (Nat.succ n')
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
this : IntFractPair.stream v (n' + 1) ≠ none
⊢ Nat.succ n' = 0 ∨ ¬TerminatedAt g (Nat.succ n' - 1)
[PROOFSTEP]
have : ¬g.TerminatedAt n' := (not_congr of_terminatedAt_n_iff_succ_nth_intFractPair_stream_eq_none).2 this
[GOAL]
case succ
K : Type u_1
v : K
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
g : GeneralizedContinuedFraction K := of v
ifp_fr_ne_zero : ¬ifp.fr = 0
n' : ℕ
stream_nth_eq : IntFractPair.stream v (Nat.succ n') = some ifp
conts : Pair K := continuantsAux g (Nat.succ n' + 1)
pred_conts : Pair K := continuantsAux g (Nat.succ n')
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
this✝ : IntFractPair.stream v (n' + 1) ≠ none
this : ¬TerminatedAt g n'
⊢ Nat.succ n' = 0 ∨ ¬TerminatedAt g (Nat.succ n' - 1)
[PROOFSTEP]
exact Or.inr this
[GOAL]
case inr
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
n_eq_zero_or_not_terminated_at_pred_n : n = 0 ∨ ¬TerminatedAt g (n - 1)
⊢ (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B) - A / B = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
[PROOFSTEP]
have determinant_eq : pA * B - pB * A = (-1) ^ n := determinant_aux n_eq_zero_or_not_terminated_at_pred_n
[GOAL]
case inr
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
n_eq_zero_or_not_terminated_at_pred_n : n = 0 ∨ ¬TerminatedAt g (n - 1)
determinant_eq : pA * B - pB * A = (-1) ^ n
⊢ (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B) - A / B = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
[PROOFSTEP]
have pB_ineq : (fib n : K) ≤ pB :=
  haveI : n ≤ 1 ∨ ¬g.TerminatedAt (n - 2) :=
    by
    cases' n_eq_zero_or_not_terminated_at_pred_n with n_eq_zero not_terminated_at_pred_n
    · simp [n_eq_zero]
    · exact Or.inr <| mt (terminated_stable (n - 1).pred_le) not_terminated_at_pred_n
  fib_le_of_continuantsAux_b this
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
n_eq_zero_or_not_terminated_at_pred_n : n = 0 ∨ ¬TerminatedAt g (n - 1)
determinant_eq : pA * B - pB * A = (-1) ^ n
⊢ n ≤ 1 ∨ ¬TerminatedAt g (n - 2)
[PROOFSTEP]
cases' n_eq_zero_or_not_terminated_at_pred_n with n_eq_zero not_terminated_at_pred_n
[GOAL]
case inl
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
determinant_eq : pA * B - pB * A = (-1) ^ n
n_eq_zero : n = 0
⊢ n ≤ 1 ∨ ¬TerminatedAt g (n - 2)
[PROOFSTEP]
simp [n_eq_zero]
[GOAL]
case inr
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
determinant_eq : pA * B - pB * A = (-1) ^ n
not_terminated_at_pred_n : ¬TerminatedAt g (n - 1)
⊢ n ≤ 1 ∨ ¬TerminatedAt g (n - 2)
[PROOFSTEP]
exact Or.inr <| mt (terminated_stable (n - 1).pred_le) not_terminated_at_pred_n
[GOAL]
case inr
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
n_eq_zero_or_not_terminated_at_pred_n : n = 0 ∨ ¬TerminatedAt g (n - 1)
determinant_eq : pA * B - pB * A = (-1) ^ n
pB_ineq : ↑(fib n) ≤ pB
⊢ (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B) - A / B = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
[PROOFSTEP]
have B_ineq : (fib (n + 1) : K) ≤ B :=
  haveI : n + 1 ≤ 1 ∨ ¬g.TerminatedAt (n + 1 - 2) :=
    by
    cases' n_eq_zero_or_not_terminated_at_pred_n with n_eq_zero not_terminated_at_pred_n
    · simp [n_eq_zero, le_refl]
    · exact Or.inr not_terminated_at_pred_n
  fib_le_of_continuantsAux_b this
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
n_eq_zero_or_not_terminated_at_pred_n : n = 0 ∨ ¬TerminatedAt g (n - 1)
determinant_eq : pA * B - pB * A = (-1) ^ n
pB_ineq : ↑(fib n) ≤ pB
⊢ n + 1 ≤ 1 ∨ ¬TerminatedAt g (n + 1 - 2)
[PROOFSTEP]
cases' n_eq_zero_or_not_terminated_at_pred_n with n_eq_zero not_terminated_at_pred_n
[GOAL]
case inl
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
determinant_eq : pA * B - pB * A = (-1) ^ n
pB_ineq : ↑(fib n) ≤ pB
n_eq_zero : n = 0
⊢ n + 1 ≤ 1 ∨ ¬TerminatedAt g (n + 1 - 2)
[PROOFSTEP]
simp [n_eq_zero, le_refl]
[GOAL]
case inr
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
determinant_eq : pA * B - pB * A = (-1) ^ n
pB_ineq : ↑(fib n) ≤ pB
not_terminated_at_pred_n : ¬TerminatedAt g (n - 1)
⊢ n + 1 ≤ 1 ∨ ¬TerminatedAt g (n + 1 - 2)
[PROOFSTEP]
exact Or.inr not_terminated_at_pred_n
[GOAL]
case inr
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
n_eq_zero_or_not_terminated_at_pred_n : n = 0 ∨ ¬TerminatedAt g (n - 1)
determinant_eq : pA * B - pB * A = (-1) ^ n
pB_ineq : ↑(fib n) ≤ pB
B_ineq : ↑(fib (n + 1)) ≤ B
⊢ (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B) - A / B = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
[PROOFSTEP]
have zero_lt_B : 0 < B :=
  haveI : 1 ≤ B := le_trans (by exact_mod_cast fib_pos (lt_of_le_of_ne n.succ.zero_le n.succ_ne_zero.symm)) B_ineq
  lt_of_lt_of_le zero_lt_one this
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
n_eq_zero_or_not_terminated_at_pred_n : n = 0 ∨ ¬TerminatedAt g (n - 1)
determinant_eq : pA * B - pB * A = (-1) ^ n
pB_ineq : ↑(fib n) ≤ pB
B_ineq : ↑(fib (n + 1)) ≤ B
⊢ 1 ≤ ↑(fib (n + 1))
[PROOFSTEP]
exact_mod_cast fib_pos (lt_of_le_of_ne n.succ.zero_le n.succ_ne_zero.symm)
[GOAL]
case inr
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
n_eq_zero_or_not_terminated_at_pred_n : n = 0 ∨ ¬TerminatedAt g (n - 1)
determinant_eq : pA * B - pB * A = (-1) ^ n
pB_ineq : ↑(fib n) ≤ pB
B_ineq : ↑(fib (n + 1)) ≤ B
zero_lt_B : 0 < B
⊢ (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B) - A / B = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
[PROOFSTEP]
have zero_ne_B : 0 ≠ B := ne_of_lt zero_lt_B
[GOAL]
case inr
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
n_eq_zero_or_not_terminated_at_pred_n : n = 0 ∨ ¬TerminatedAt g (n - 1)
determinant_eq : pA * B - pB * A = (-1) ^ n
pB_ineq : ↑(fib n) ≤ pB
B_ineq : ↑(fib (n + 1)) ≤ B
zero_lt_B : 0 < B
zero_ne_B : 0 ≠ B
⊢ (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B) - A / B = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
[PROOFSTEP]
have : 0 ≠ pB + ifp.fr⁻¹ * B :=
  by
  have : (0 : K) ≤ fib n := by exact_mod_cast (fib n).zero_le
  have zero_le_pB : 0 ≤ pB := le_trans this pB_ineq
  have : 0 < ifp.fr⁻¹ := by
    suffices 0 < ifp.fr by rwa [inv_pos]
    have : 0 ≤ ifp.fr := IntFractPair.nth_stream_fr_nonneg stream_nth_eq
    change ifp.fr ≠ 0 at ifp_fr_ne_zero 
    exact lt_of_le_of_ne this ifp_fr_ne_zero.symm
  have : 0 < ifp.fr⁻¹ * B := mul_pos this zero_lt_B
  have : 0 < pB + ifp.fr⁻¹ * B := add_pos_of_nonneg_of_pos zero_le_pB this
  exact ne_of_lt this
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
n_eq_zero_or_not_terminated_at_pred_n : n = 0 ∨ ¬TerminatedAt g (n - 1)
determinant_eq : pA * B - pB * A = (-1) ^ n
pB_ineq : ↑(fib n) ≤ pB
B_ineq : ↑(fib (n + 1)) ≤ B
zero_lt_B : 0 < B
zero_ne_B : 0 ≠ B
⊢ 0 ≠ pB + ifp.fr⁻¹ * B
[PROOFSTEP]
have : (0 : K) ≤ fib n := by exact_mod_cast (fib n).zero_le
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
n_eq_zero_or_not_terminated_at_pred_n : n = 0 ∨ ¬TerminatedAt g (n - 1)
determinant_eq : pA * B - pB * A = (-1) ^ n
pB_ineq : ↑(fib n) ≤ pB
B_ineq : ↑(fib (n + 1)) ≤ B
zero_lt_B : 0 < B
zero_ne_B : 0 ≠ B
⊢ 0 ≤ ↑(fib n)
[PROOFSTEP]
exact_mod_cast (fib n).zero_le
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
n_eq_zero_or_not_terminated_at_pred_n : n = 0 ∨ ¬TerminatedAt g (n - 1)
determinant_eq : pA * B - pB * A = (-1) ^ n
pB_ineq : ↑(fib n) ≤ pB
B_ineq : ↑(fib (n + 1)) ≤ B
zero_lt_B : 0 < B
zero_ne_B : 0 ≠ B
this : 0 ≤ ↑(fib n)
⊢ 0 ≠ pB + ifp.fr⁻¹ * B
[PROOFSTEP]
have zero_le_pB : 0 ≤ pB := le_trans this pB_ineq
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
n_eq_zero_or_not_terminated_at_pred_n : n = 0 ∨ ¬TerminatedAt g (n - 1)
determinant_eq : pA * B - pB * A = (-1) ^ n
pB_ineq : ↑(fib n) ≤ pB
B_ineq : ↑(fib (n + 1)) ≤ B
zero_lt_B : 0 < B
zero_ne_B : 0 ≠ B
this : 0 ≤ ↑(fib n)
zero_le_pB : 0 ≤ pB
⊢ 0 ≠ pB + ifp.fr⁻¹ * B
[PROOFSTEP]
have : 0 < ifp.fr⁻¹ := by
  suffices 0 < ifp.fr by rwa [inv_pos]
  have : 0 ≤ ifp.fr := IntFractPair.nth_stream_fr_nonneg stream_nth_eq
  change ifp.fr ≠ 0 at ifp_fr_ne_zero 
  exact lt_of_le_of_ne this ifp_fr_ne_zero.symm
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
n_eq_zero_or_not_terminated_at_pred_n : n = 0 ∨ ¬TerminatedAt g (n - 1)
determinant_eq : pA * B - pB * A = (-1) ^ n
pB_ineq : ↑(fib n) ≤ pB
B_ineq : ↑(fib (n + 1)) ≤ B
zero_lt_B : 0 < B
zero_ne_B : 0 ≠ B
this : 0 ≤ ↑(fib n)
zero_le_pB : 0 ≤ pB
⊢ 0 < ifp.fr⁻¹
[PROOFSTEP]
suffices 0 < ifp.fr by rwa [inv_pos]
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
n_eq_zero_or_not_terminated_at_pred_n : n = 0 ∨ ¬TerminatedAt g (n - 1)
determinant_eq : pA * B - pB * A = (-1) ^ n
pB_ineq : ↑(fib n) ≤ pB
B_ineq : ↑(fib (n + 1)) ≤ B
zero_lt_B : 0 < B
zero_ne_B : 0 ≠ B
this✝ : 0 ≤ ↑(fib n)
zero_le_pB : 0 ≤ pB
this : 0 < ifp.fr
⊢ 0 < ifp.fr⁻¹
[PROOFSTEP]
rwa [inv_pos]
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
n_eq_zero_or_not_terminated_at_pred_n : n = 0 ∨ ¬TerminatedAt g (n - 1)
determinant_eq : pA * B - pB * A = (-1) ^ n
pB_ineq : ↑(fib n) ≤ pB
B_ineq : ↑(fib (n + 1)) ≤ B
zero_lt_B : 0 < B
zero_ne_B : 0 ≠ B
this : 0 ≤ ↑(fib n)
zero_le_pB : 0 ≤ pB
⊢ 0 < ifp.fr
[PROOFSTEP]
have : 0 ≤ ifp.fr := IntFractPair.nth_stream_fr_nonneg stream_nth_eq
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
n_eq_zero_or_not_terminated_at_pred_n : n = 0 ∨ ¬TerminatedAt g (n - 1)
determinant_eq : pA * B - pB * A = (-1) ^ n
pB_ineq : ↑(fib n) ≤ pB
B_ineq : ↑(fib (n + 1)) ≤ B
zero_lt_B : 0 < B
zero_ne_B : 0 ≠ B
this✝ : 0 ≤ ↑(fib n)
zero_le_pB : 0 ≤ pB
this : 0 ≤ ifp.fr
⊢ 0 < ifp.fr
[PROOFSTEP]
change ifp.fr ≠ 0 at ifp_fr_ne_zero 
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
n_eq_zero_or_not_terminated_at_pred_n : n = 0 ∨ ¬TerminatedAt g (n - 1)
determinant_eq : pA * B - pB * A = (-1) ^ n
pB_ineq : ↑(fib n) ≤ pB
B_ineq : ↑(fib (n + 1)) ≤ B
zero_lt_B : 0 < B
zero_ne_B : 0 ≠ B
this✝ : 0 ≤ ↑(fib n)
zero_le_pB : 0 ≤ pB
this : 0 ≤ ifp.fr
ifp_fr_ne_zero : ifp.fr ≠ 0
⊢ 0 < ifp.fr
[PROOFSTEP]
exact lt_of_le_of_ne this ifp_fr_ne_zero.symm
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
n_eq_zero_or_not_terminated_at_pred_n : n = 0 ∨ ¬TerminatedAt g (n - 1)
determinant_eq : pA * B - pB * A = (-1) ^ n
pB_ineq : ↑(fib n) ≤ pB
B_ineq : ↑(fib (n + 1)) ≤ B
zero_lt_B : 0 < B
zero_ne_B : 0 ≠ B
this✝ : 0 ≤ ↑(fib n)
zero_le_pB : 0 ≤ pB
this : 0 < ifp.fr⁻¹
⊢ 0 ≠ pB + ifp.fr⁻¹ * B
[PROOFSTEP]
have : 0 < ifp.fr⁻¹ * B := mul_pos this zero_lt_B
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
n_eq_zero_or_not_terminated_at_pred_n : n = 0 ∨ ¬TerminatedAt g (n - 1)
determinant_eq : pA * B - pB * A = (-1) ^ n
pB_ineq : ↑(fib n) ≤ pB
B_ineq : ↑(fib (n + 1)) ≤ B
zero_lt_B : 0 < B
zero_ne_B : 0 ≠ B
this✝¹ : 0 ≤ ↑(fib n)
zero_le_pB : 0 ≤ pB
this✝ : 0 < ifp.fr⁻¹
this : 0 < ifp.fr⁻¹ * B
⊢ 0 ≠ pB + ifp.fr⁻¹ * B
[PROOFSTEP]
have : 0 < pB + ifp.fr⁻¹ * B := add_pos_of_nonneg_of_pos zero_le_pB this
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
n_eq_zero_or_not_terminated_at_pred_n : n = 0 ∨ ¬TerminatedAt g (n - 1)
determinant_eq : pA * B - pB * A = (-1) ^ n
pB_ineq : ↑(fib n) ≤ pB
B_ineq : ↑(fib (n + 1)) ≤ B
zero_lt_B : 0 < B
zero_ne_B : 0 ≠ B
this✝² : 0 ≤ ↑(fib n)
zero_le_pB : 0 ≤ pB
this✝¹ : 0 < ifp.fr⁻¹
this✝ : 0 < ifp.fr⁻¹ * B
this : 0 < pB + ifp.fr⁻¹ * B
⊢ 0 ≠ pB + ifp.fr⁻¹ * B
[PROOFSTEP]
exact ne_of_lt this
[GOAL]
case inr
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
n_eq_zero_or_not_terminated_at_pred_n : n = 0 ∨ ¬TerminatedAt g (n - 1)
determinant_eq : pA * B - pB * A = (-1) ^ n
pB_ineq : ↑(fib n) ≤ pB
B_ineq : ↑(fib (n + 1)) ≤ B
zero_lt_B : 0 < B
zero_ne_B : 0 ≠ B
this : 0 ≠ pB + ifp.fr⁻¹ * B
⊢ (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B) - A / B = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
[PROOFSTEP]
calc
  (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B) - A / B =
      ((pA + ifp.fr⁻¹ * A) * B - (pB + ifp.fr⁻¹ * B) * A) / ((pB + ifp.fr⁻¹ * B) * B) :=
    by rw [div_sub_div _ _ this.symm zero_ne_B.symm]
  _ = (pA * B + ifp.fr⁻¹ * A * B - (pB * A + ifp.fr⁻¹ * B * A)) / _ := by repeat' rw [add_mul]
  _ = (pA * B - pB * A) / ((pB + ifp.fr⁻¹ * B) * B) := by ring
  _ = (-1) ^ n / ((pB + ifp.fr⁻¹ * B) * B) := by rw [determinant_eq]
  _ = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB)) := by ac_rfl
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
n_eq_zero_or_not_terminated_at_pred_n : n = 0 ∨ ¬TerminatedAt g (n - 1)
determinant_eq : pA * B - pB * A = (-1) ^ n
pB_ineq : ↑(fib n) ≤ pB
B_ineq : ↑(fib (n + 1)) ≤ B
zero_lt_B : 0 < B
zero_ne_B : 0 ≠ B
this : 0 ≠ pB + ifp.fr⁻¹ * B
⊢ (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B) - A / B =
    ((pA + ifp.fr⁻¹ * A) * B - (pB + ifp.fr⁻¹ * B) * A) / ((pB + ifp.fr⁻¹ * B) * B)
[PROOFSTEP]
rw [div_sub_div _ _ this.symm zero_ne_B.symm]
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
n_eq_zero_or_not_terminated_at_pred_n : n = 0 ∨ ¬TerminatedAt g (n - 1)
determinant_eq : pA * B - pB * A = (-1) ^ n
pB_ineq : ↑(fib n) ≤ pB
B_ineq : ↑(fib (n + 1)) ≤ B
zero_lt_B : 0 < B
zero_ne_B : 0 ≠ B
this : 0 ≠ pB + ifp.fr⁻¹ * B
⊢ ((pA + ifp.fr⁻¹ * A) * B - (pB + ifp.fr⁻¹ * B) * A) / ((pB + ifp.fr⁻¹ * B) * B) =
    (pA * B + ifp.fr⁻¹ * A * B - (pB * A + ifp.fr⁻¹ * B * A)) / ?m.95134
[PROOFSTEP]
repeat' rw [add_mul]
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
n_eq_zero_or_not_terminated_at_pred_n : n = 0 ∨ ¬TerminatedAt g (n - 1)
determinant_eq : pA * B - pB * A = (-1) ^ n
pB_ineq : ↑(fib n) ≤ pB
B_ineq : ↑(fib (n + 1)) ≤ B
zero_lt_B : 0 < B
zero_ne_B : 0 ≠ B
this : 0 ≠ pB + ifp.fr⁻¹ * B
⊢ ((pA + ifp.fr⁻¹ * A) * B - (pB + ifp.fr⁻¹ * B) * A) / ((pB + ifp.fr⁻¹ * B) * B) =
    (pA * B + ifp.fr⁻¹ * A * B - (pB * A + ifp.fr⁻¹ * B * A)) / ?m.95134
[PROOFSTEP]
rw [add_mul]
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
n_eq_zero_or_not_terminated_at_pred_n : n = 0 ∨ ¬TerminatedAt g (n - 1)
determinant_eq : pA * B - pB * A = (-1) ^ n
pB_ineq : ↑(fib n) ≤ pB
B_ineq : ↑(fib (n + 1)) ≤ B
zero_lt_B : 0 < B
zero_ne_B : 0 ≠ B
this : 0 ≠ pB + ifp.fr⁻¹ * B
⊢ (pA * B + ifp.fr⁻¹ * A * B - (pB + ifp.fr⁻¹ * B) * A) / ((pB + ifp.fr⁻¹ * B) * B) =
    (pA * B + ifp.fr⁻¹ * A * B - (pB * A + ifp.fr⁻¹ * B * A)) / ?m.95134
[PROOFSTEP]
rw [add_mul]
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
n_eq_zero_or_not_terminated_at_pred_n : n = 0 ∨ ¬TerminatedAt g (n - 1)
determinant_eq : pA * B - pB * A = (-1) ^ n
pB_ineq : ↑(fib n) ≤ pB
B_ineq : ↑(fib (n + 1)) ≤ B
zero_lt_B : 0 < B
zero_ne_B : 0 ≠ B
this : 0 ≠ pB + ifp.fr⁻¹ * B
⊢ (pA * B + ifp.fr⁻¹ * A * B - (pB * A + ifp.fr⁻¹ * B * A)) / ((pB + ifp.fr⁻¹ * B) * B) =
    (pA * B - pB * A) / ((pB + ifp.fr⁻¹ * B) * B)
[PROOFSTEP]
ring
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
n_eq_zero_or_not_terminated_at_pred_n : n = 0 ∨ ¬TerminatedAt g (n - 1)
determinant_eq : pA * B - pB * A = (-1) ^ n
pB_ineq : ↑(fib n) ≤ pB
B_ineq : ↑(fib (n + 1)) ≤ B
zero_lt_B : 0 < B
zero_ne_B : 0 ≠ B
this : 0 ≠ pB + ifp.fr⁻¹ * B
⊢ (pA * B - pB * A) / ((pB + ifp.fr⁻¹ * B) * B) = (-1) ^ n / ((pB + ifp.fr⁻¹ * B) * B)
[PROOFSTEP]
rw [determinant_eq]
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
ifp : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp
g : GeneralizedContinuedFraction K := of v
conts : Pair K := continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
ifp_fr_ne_zero : ¬ifp.fr = 0
A : K := conts.a
B : K := conts.b
pA : K := pred_conts.a
pB : K := pred_conts.b
g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B)
n_eq_zero_or_not_terminated_at_pred_n : n = 0 ∨ ¬TerminatedAt g (n - 1)
determinant_eq : pA * B - pB * A = (-1) ^ n
pB_ineq : ↑(fib n) ≤ pB
B_ineq : ↑(fib (n + 1)) ≤ B
zero_lt_B : 0 < B
zero_ne_B : 0 ≠ B
this : 0 ≠ pB + ifp.fr⁻¹ * B
⊢ (-1) ^ n / ((pB + ifp.fr⁻¹ * B) * B) = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
[PROOFSTEP]
ac_rfl
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
⊢ |v - convergents (of v) n| ≤ 1 / (denominators (of v) n * denominators (of v) (n + 1))
[PROOFSTEP]
let g := of v
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
⊢ |v - convergents (of v) n| ≤ 1 / (denominators (of v) n * denominators (of v) (n + 1))
[PROOFSTEP]
let nextConts := g.continuantsAux (n + 2)
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
⊢ |v - convergents (of v) n| ≤ 1 / (denominators (of v) n * denominators (of v) (n + 1))
[PROOFSTEP]
set conts := continuantsAux g (n + 1) with conts_eq
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
⊢ |v - convergents (of v) n| ≤ 1 / (denominators (of v) n * denominators (of v) (n + 1))
[PROOFSTEP]
set pred_conts := continuantsAux g n with pred_conts_eq
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
⊢ |v - convergents (of v) n| ≤ 1 / (denominators (of v) n * denominators (of v) (n + 1))
[PROOFSTEP]
change |v - convergents g n| ≤ 1 / (conts.b * nextConts.b)
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
⊢ |v - convergents g n| ≤ 1 / (conts.b * nextConts.b)
[PROOFSTEP]
obtain ⟨gp, s_nth_eq⟩ : ∃ gp, g.s.get? n = some gp
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
⊢ ∃ gp, Stream'.Seq.get? g.s n = some gp
case intro
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
⊢ |v - convergents g n| ≤ 1 / (conts.b * nextConts.b)
[PROOFSTEP]
exact Option.ne_none_iff_exists'.1 not_terminated_at_n
[GOAL]
case intro
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
⊢ |v - convergents g n| ≤ 1 / (conts.b * nextConts.b)
[PROOFSTEP]
have gp_a_eq_one : gp.a = 1 :=
  of_part_num_eq_one
    (part_num_eq_s_a s_nth_eq)
      -- unfold the recurrence relation for `nextConts.b`
[GOAL]
case intro
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
⊢ |v - convergents g n| ≤ 1 / (conts.b * nextConts.b)
[PROOFSTEP]
have nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b := by
  simp [continuantsAux_recurrence s_nth_eq pred_conts_eq conts_eq, gp_a_eq_one, pred_conts_eq.symm, conts_eq.symm,
    add_comm]
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
⊢ nextConts.b = pred_conts.b + gp.b * conts.b
[PROOFSTEP]
simp [continuantsAux_recurrence s_nth_eq pred_conts_eq conts_eq, gp_a_eq_one, pred_conts_eq.symm, conts_eq.symm,
  add_comm]
[GOAL]
case intro
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
⊢ |v - convergents g n| ≤ 1 / (conts.b * nextConts.b)
[PROOFSTEP]
let denom := conts.b * (pred_conts.b + gp.b * conts.b)
[GOAL]
case intro
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
⊢ |v - convergents g n| ≤ 1 / (conts.b * nextConts.b)
[PROOFSTEP]
suffices |v - g.convergents n| ≤ 1 / denom by rw [nextConts_b_eq]; congr 1
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
this : |v - convergents g n| ≤ 1 / denom
⊢ |v - convergents g n| ≤ 1 / (conts.b * nextConts.b)
[PROOFSTEP]
rw [nextConts_b_eq]
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
this : |v - convergents g n| ≤ 1 / denom
⊢ |v - convergents g n| ≤ 1 / (conts.b * (pred_conts.b + gp.b * conts.b))
[PROOFSTEP]
congr 1
[GOAL]
case intro
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
⊢ |v - convergents g n| ≤ 1 / denom
[PROOFSTEP]
obtain ⟨ifp_succ_n, succ_nth_stream_eq, ifp_succ_n_b_eq_gp_b⟩ :
  ∃ ifp_succ_n, IntFractPair.stream v (n + 1) = some ifp_succ_n ∧ (ifp_succ_n.b : K) = gp.b
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
⊢ ∃ ifp_succ_n, IntFractPair.stream v (n + 1) = some ifp_succ_n ∧ ↑ifp_succ_n.b = gp.b
case intro.intro.intro
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
⊢ |v - convergents g n| ≤ 1 / denom
[PROOFSTEP]
exact IntFractPair.exists_succ_get?_stream_of_gcf_of_get?_eq_some s_nth_eq
[GOAL]
case intro.intro.intro
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
⊢ |v - convergents g n| ≤ 1 / denom
[PROOFSTEP]
obtain ⟨ifp_n, stream_nth_eq, stream_nth_fr_ne_zero, if_of_eq_ifp_succ_n⟩ :
  ∃ ifp_n, IntFractPair.stream v n = some ifp_n ∧ ifp_n.fr ≠ 0 ∧ IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
⊢ ∃ ifp_n, IntFractPair.stream v n = some ifp_n ∧ ifp_n.fr ≠ 0 ∧ IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
case intro.intro.intro.intro.intro.intro
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
⊢ |v - convergents g n| ≤ 1 / denom
[PROOFSTEP]
exact IntFractPair.succ_nth_stream_eq_some_iff.1 succ_nth_stream_eq
[GOAL]
case intro.intro.intro.intro.intro.intro
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
⊢ |v - convergents g n| ≤ 1 / denom
[PROOFSTEP]
let denom' :=
  conts.b *
    (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
      -- now we can use `sub_convergents_eq` to simplify our goal
[GOAL]
case intro.intro.intro.intro.intro.intro
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
⊢ |v - convergents g n| ≤ 1 / denom
[PROOFSTEP]
suffices |(-1) ^ n / denom'| ≤ 1 / denom
  by
  have : v - g.convergents n = (-1) ^ n / denom' := by
    -- apply `sub_convergents_eq` and simplify the result
    have tmp := sub_convergents_eq stream_nth_eq
    simp only [stream_nth_fr_ne_zero, conts_eq.symm, pred_conts_eq.symm, if_false] at tmp 
    rw [tmp]
    ring
  rwa [this]
    -- derive some tedious inequalities that we need to rewrite our goal
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
this : |(-1) ^ n / denom'| ≤ 1 / denom
⊢ |v - convergents g n| ≤ 1 / denom
[PROOFSTEP]
have : v - g.convergents n = (-1) ^ n / denom' := by
  -- apply `sub_convergents_eq` and simplify the result
  have tmp := sub_convergents_eq stream_nth_eq
  simp only [stream_nth_fr_ne_zero, conts_eq.symm, pred_conts_eq.symm, if_false] at tmp 
  rw [tmp]
  ring
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
this : |(-1) ^ n / denom'| ≤ 1 / denom
⊢ v - convergents g n = (-1) ^ n / denom'
[PROOFSTEP]
have tmp := sub_convergents_eq stream_nth_eq
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
this : |(-1) ^ n / denom'| ≤ 1 / denom
tmp :
  let g := of v;
  let B := (continuantsAux g (n + 1)).b;
  let pB := (continuantsAux g n).b;
  v - convergents g n = if ifp_n.fr = 0 then 0 else (-1) ^ n / (B * (ifp_n.fr⁻¹ * B + pB))
⊢ v - convergents g n = (-1) ^ n / denom'
[PROOFSTEP]
simp only [stream_nth_fr_ne_zero, conts_eq.symm, pred_conts_eq.symm, if_false] at tmp 
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
this : |(-1) ^ n / denom'| ≤ 1 / denom
tmp : v - convergents (of v) n = (-1) ^ n / (conts.b * (ifp_n.fr⁻¹ * conts.b + pred_conts.b))
⊢ v - convergents g n = (-1) ^ n / denom'
[PROOFSTEP]
rw [tmp]
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
this : |(-1) ^ n / denom'| ≤ 1 / denom
tmp : v - convergents (of v) n = (-1) ^ n / (conts.b * (ifp_n.fr⁻¹ * conts.b + pred_conts.b))
⊢ (-1) ^ n / (conts.b * (ifp_n.fr⁻¹ * conts.b + pred_conts.b)) = (-1) ^ n / denom'
[PROOFSTEP]
ring
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
this✝ : |(-1) ^ n / denom'| ≤ 1 / denom
this : v - convergents g n = (-1) ^ n / denom'
⊢ |v - convergents g n| ≤ 1 / denom
[PROOFSTEP]
rwa [this]
  -- derive some tedious inequalities that we need to rewrite our goal
[GOAL]
case intro.intro.intro.intro.intro.intro
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
⊢ |(-1) ^ n / denom'| ≤ 1 / denom
[PROOFSTEP]
have nextConts_b_ineq : (fib (n + 2) : K) ≤ pred_conts.b + gp.b * conts.b :=
  by
  have : (fib (n + 2) : K) ≤ nextConts.b := fib_le_of_continuantsAux_b (Or.inr not_terminated_at_n)
  rwa [nextConts_b_eq] at this 
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
⊢ ↑(fib (n + 2)) ≤ pred_conts.b + gp.b * conts.b
[PROOFSTEP]
have : (fib (n + 2) : K) ≤ nextConts.b := fib_le_of_continuantsAux_b (Or.inr not_terminated_at_n)
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
this : ↑(fib (n + 2)) ≤ nextConts.b
⊢ ↑(fib (n + 2)) ≤ pred_conts.b + gp.b * conts.b
[PROOFSTEP]
rwa [nextConts_b_eq] at this 
[GOAL]
case intro.intro.intro.intro.intro.intro
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
nextConts_b_ineq : ↑(fib (n + 2)) ≤ pred_conts.b + gp.b * conts.b
⊢ |(-1) ^ n / denom'| ≤ 1 / denom
[PROOFSTEP]
have conts_b_ineq : (fib (n + 1) : K) ≤ conts.b :=
  haveI : ¬g.TerminatedAt (n - 1) := mt (terminated_stable n.pred_le) not_terminated_at_n
  fib_le_of_continuantsAux_b <| Or.inr this
[GOAL]
case intro.intro.intro.intro.intro.intro
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
nextConts_b_ineq : ↑(fib (n + 2)) ≤ pred_conts.b + gp.b * conts.b
conts_b_ineq : ↑(fib (n + 1)) ≤ conts.b
⊢ |(-1) ^ n / denom'| ≤ 1 / denom
[PROOFSTEP]
have zero_lt_conts_b : 0 < conts.b :=
  haveI : (0 : K) < fib (n + 1) := by exact_mod_cast fib_pos (lt_of_le_of_ne n.succ.zero_le n.succ_ne_zero.symm)
  lt_of_lt_of_le this conts_b_ineq
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
nextConts_b_ineq : ↑(fib (n + 2)) ≤ pred_conts.b + gp.b * conts.b
conts_b_ineq : ↑(fib (n + 1)) ≤ conts.b
⊢ 0 < ↑(fib (n + 1))
[PROOFSTEP]
exact_mod_cast fib_pos (lt_of_le_of_ne n.succ.zero_le n.succ_ne_zero.symm)
[GOAL]
case intro.intro.intro.intro.intro.intro
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
nextConts_b_ineq : ↑(fib (n + 2)) ≤ pred_conts.b + gp.b * conts.b
conts_b_ineq : ↑(fib (n + 1)) ≤ conts.b
zero_lt_conts_b : 0 < conts.b
⊢ |(-1) ^ n / denom'| ≤ 1 / denom
[PROOFSTEP]
suffices 1 / denom' ≤ 1 / denom
  by
  have : |(-1) ^ n / denom'| = 1 / denom' :=
    by
    suffices 1 / |denom'| = 1 / denom' by rwa [abs_div, abs_neg_one_pow n]
    have : 0 < denom' :=
      by
      have : 0 ≤ pred_conts.b :=
        haveI : (fib n : K) ≤ pred_conts.b :=
          haveI : ¬g.TerminatedAt (n - 2) := mt (terminated_stable (n.sub_le 2)) not_terminated_at_n
          fib_le_of_continuantsAux_b <| Or.inr this
        le_trans (by exact_mod_cast (fib n).zero_le) this
      have : 0 < ifp_n.fr⁻¹ :=
        haveI zero_le_ifp_n_fract : 0 ≤ ifp_n.fr := IntFractPair.nth_stream_fr_nonneg stream_nth_eq
        inv_pos.2
          (lt_of_le_of_ne zero_le_ifp_n_fract stream_nth_fr_ne_zero.symm)
            -- Porting note: replaced complicated positivity proof with tactic.
      positivity
    rw [abs_of_pos this]
  rwa [this]
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
nextConts_b_ineq : ↑(fib (n + 2)) ≤ pred_conts.b + gp.b * conts.b
conts_b_ineq : ↑(fib (n + 1)) ≤ conts.b
zero_lt_conts_b : 0 < conts.b
this : 1 / denom' ≤ 1 / denom
⊢ |(-1) ^ n / denom'| ≤ 1 / denom
[PROOFSTEP]
have : |(-1) ^ n / denom'| = 1 / denom' :=
  by
  suffices 1 / |denom'| = 1 / denom' by rwa [abs_div, abs_neg_one_pow n]
  have : 0 < denom' :=
    by
    have : 0 ≤ pred_conts.b :=
      haveI : (fib n : K) ≤ pred_conts.b :=
        haveI : ¬g.TerminatedAt (n - 2) := mt (terminated_stable (n.sub_le 2)) not_terminated_at_n
        fib_le_of_continuantsAux_b <| Or.inr this
      le_trans (by exact_mod_cast (fib n).zero_le) this
    have : 0 < ifp_n.fr⁻¹ :=
      haveI zero_le_ifp_n_fract : 0 ≤ ifp_n.fr := IntFractPair.nth_stream_fr_nonneg stream_nth_eq
      inv_pos.2
        (lt_of_le_of_ne zero_le_ifp_n_fract stream_nth_fr_ne_zero.symm)
          -- Porting note: replaced complicated positivity proof with tactic.
    positivity
  rw [abs_of_pos this]
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
nextConts_b_ineq : ↑(fib (n + 2)) ≤ pred_conts.b + gp.b * conts.b
conts_b_ineq : ↑(fib (n + 1)) ≤ conts.b
zero_lt_conts_b : 0 < conts.b
this : 1 / denom' ≤ 1 / denom
⊢ |(-1) ^ n / denom'| = 1 / denom'
[PROOFSTEP]
suffices 1 / |denom'| = 1 / denom' by rwa [abs_div, abs_neg_one_pow n]
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
nextConts_b_ineq : ↑(fib (n + 2)) ≤ pred_conts.b + gp.b * conts.b
conts_b_ineq : ↑(fib (n + 1)) ≤ conts.b
zero_lt_conts_b : 0 < conts.b
this✝ : 1 / denom' ≤ 1 / denom
this : 1 / |denom'| = 1 / denom'
⊢ |(-1) ^ n / denom'| = 1 / denom'
[PROOFSTEP]
rwa [abs_div, abs_neg_one_pow n]
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
nextConts_b_ineq : ↑(fib (n + 2)) ≤ pred_conts.b + gp.b * conts.b
conts_b_ineq : ↑(fib (n + 1)) ≤ conts.b
zero_lt_conts_b : 0 < conts.b
this : 1 / denom' ≤ 1 / denom
⊢ 1 / |denom'| = 1 / denom'
[PROOFSTEP]
have : 0 < denom' :=
  by
  have : 0 ≤ pred_conts.b :=
    haveI : (fib n : K) ≤ pred_conts.b :=
      haveI : ¬g.TerminatedAt (n - 2) := mt (terminated_stable (n.sub_le 2)) not_terminated_at_n
      fib_le_of_continuantsAux_b <| Or.inr this
    le_trans (by exact_mod_cast (fib n).zero_le) this
  have : 0 < ifp_n.fr⁻¹ :=
    haveI zero_le_ifp_n_fract : 0 ≤ ifp_n.fr := IntFractPair.nth_stream_fr_nonneg stream_nth_eq
    inv_pos.2
      (lt_of_le_of_ne zero_le_ifp_n_fract stream_nth_fr_ne_zero.symm)
        -- Porting note: replaced complicated positivity proof with tactic.
  positivity
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
nextConts_b_ineq : ↑(fib (n + 2)) ≤ pred_conts.b + gp.b * conts.b
conts_b_ineq : ↑(fib (n + 1)) ≤ conts.b
zero_lt_conts_b : 0 < conts.b
this : 1 / denom' ≤ 1 / denom
⊢ 0 < denom'
[PROOFSTEP]
have : 0 ≤ pred_conts.b :=
  haveI : (fib n : K) ≤ pred_conts.b :=
    haveI : ¬g.TerminatedAt (n - 2) := mt (terminated_stable (n.sub_le 2)) not_terminated_at_n
    fib_le_of_continuantsAux_b <| Or.inr this
  le_trans (by exact_mod_cast (fib n).zero_le) this
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
nextConts_b_ineq : ↑(fib (n + 2)) ≤ pred_conts.b + gp.b * conts.b
conts_b_ineq : ↑(fib (n + 1)) ≤ conts.b
zero_lt_conts_b : 0 < conts.b
this✝ : 1 / denom' ≤ 1 / denom
this : ↑(fib n) ≤ pred_conts.b
⊢ 0 ≤ ↑(fib n)
[PROOFSTEP]
exact_mod_cast (fib n).zero_le
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
nextConts_b_ineq : ↑(fib (n + 2)) ≤ pred_conts.b + gp.b * conts.b
conts_b_ineq : ↑(fib (n + 1)) ≤ conts.b
zero_lt_conts_b : 0 < conts.b
this✝ : 1 / denom' ≤ 1 / denom
this : 0 ≤ pred_conts.b
⊢ 0 < denom'
[PROOFSTEP]
have : 0 < ifp_n.fr⁻¹ :=
  haveI zero_le_ifp_n_fract : 0 ≤ ifp_n.fr := IntFractPair.nth_stream_fr_nonneg stream_nth_eq
  inv_pos.2
    (lt_of_le_of_ne zero_le_ifp_n_fract stream_nth_fr_ne_zero.symm)
      -- Porting note: replaced complicated positivity proof with tactic.
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
nextConts_b_ineq : ↑(fib (n + 2)) ≤ pred_conts.b + gp.b * conts.b
conts_b_ineq : ↑(fib (n + 1)) ≤ conts.b
zero_lt_conts_b : 0 < conts.b
this✝¹ : 1 / denom' ≤ 1 / denom
this✝ : 0 ≤ pred_conts.b
this : 0 < ifp_n.fr⁻¹
⊢ 0 < denom'
[PROOFSTEP]
positivity
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
nextConts_b_ineq : ↑(fib (n + 2)) ≤ pred_conts.b + gp.b * conts.b
conts_b_ineq : ↑(fib (n + 1)) ≤ conts.b
zero_lt_conts_b : 0 < conts.b
this✝ : 1 / denom' ≤ 1 / denom
this : 0 < denom'
⊢ 1 / |denom'| = 1 / denom'
[PROOFSTEP]
rw [abs_of_pos this]
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
nextConts_b_ineq : ↑(fib (n + 2)) ≤ pred_conts.b + gp.b * conts.b
conts_b_ineq : ↑(fib (n + 1)) ≤ conts.b
zero_lt_conts_b : 0 < conts.b
this✝ : 1 / denom' ≤ 1 / denom
this : |(-1) ^ n / denom'| = 1 / denom'
⊢ |(-1) ^ n / denom'| ≤ 1 / denom
[PROOFSTEP]
rwa [this]
[GOAL]
case intro.intro.intro.intro.intro.intro
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
nextConts_b_ineq : ↑(fib (n + 2)) ≤ pred_conts.b + gp.b * conts.b
conts_b_ineq : ↑(fib (n + 1)) ≤ conts.b
zero_lt_conts_b : 0 < conts.b
⊢ 1 / denom' ≤ 1 / denom
[PROOFSTEP]
suffices 0 < denom ∧ denom ≤ denom' from div_le_div_of_le_left zero_le_one this.left this.right
[GOAL]
case intro.intro.intro.intro.intro.intro
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
nextConts_b_ineq : ↑(fib (n + 2)) ≤ pred_conts.b + gp.b * conts.b
conts_b_ineq : ↑(fib (n + 1)) ≤ conts.b
zero_lt_conts_b : 0 < conts.b
⊢ 0 < denom ∧ denom ≤ denom'
[PROOFSTEP]
constructor
[GOAL]
case intro.intro.intro.intro.intro.intro.left
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
nextConts_b_ineq : ↑(fib (n + 2)) ≤ pred_conts.b + gp.b * conts.b
conts_b_ineq : ↑(fib (n + 1)) ≤ conts.b
zero_lt_conts_b : 0 < conts.b
⊢ 0 < denom
[PROOFSTEP]
have : 0 < pred_conts.b + gp.b * conts.b :=
  lt_of_lt_of_le (by exact_mod_cast fib_pos (lt_of_le_of_ne n.succ.succ.zero_le n.succ.succ_ne_zero.symm))
    nextConts_b_ineq
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
nextConts_b_ineq : ↑(fib (n + 2)) ≤ pred_conts.b + gp.b * conts.b
conts_b_ineq : ↑(fib (n + 1)) ≤ conts.b
zero_lt_conts_b : 0 < conts.b
⊢ 0 < ↑(fib (n + 2))
[PROOFSTEP]
exact_mod_cast fib_pos (lt_of_le_of_ne n.succ.succ.zero_le n.succ.succ_ne_zero.symm)
[GOAL]
case intro.intro.intro.intro.intro.intro.left
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
nextConts_b_ineq : ↑(fib (n + 2)) ≤ pred_conts.b + gp.b * conts.b
conts_b_ineq : ↑(fib (n + 1)) ≤ conts.b
zero_lt_conts_b : 0 < conts.b
this : 0 < pred_conts.b + gp.b * conts.b
⊢ 0 < denom
[PROOFSTEP]
solve_by_elim [mul_pos]
[GOAL]
case intro.intro.intro.intro.intro.intro.right
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
nextConts_b_ineq : ↑(fib (n + 2)) ≤ pred_conts.b + gp.b * conts.b
conts_b_ineq : ↑(fib (n + 1)) ≤ conts.b
zero_lt_conts_b : 0 < conts.b
⊢ denom ≤ denom'
[PROOFSTEP]
suffices : gp.b * conts.b ≤ ifp_n.fr⁻¹ * conts.b
[GOAL]
case intro.intro.intro.intro.intro.intro.right
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
nextConts_b_ineq : ↑(fib (n + 2)) ≤ pred_conts.b + gp.b * conts.b
conts_b_ineq : ↑(fib (n + 1)) ≤ conts.b
zero_lt_conts_b : 0 < conts.b
this : gp.b * conts.b ≤ ifp_n.fr⁻¹ * conts.b
⊢ denom ≤ denom'
case this
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
nextConts_b_ineq : ↑(fib (n + 2)) ≤ pred_conts.b + gp.b * conts.b
conts_b_ineq : ↑(fib (n + 1)) ≤ conts.b
zero_lt_conts_b : 0 < conts.b
⊢ gp.b * conts.b ≤ ifp_n.fr⁻¹ * conts.b
[PROOFSTEP]
exact (mul_le_mul_left zero_lt_conts_b).2 <| (add_le_add_iff_left pred_conts.b).2 this
[GOAL]
case this
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
nextConts_b_ineq : ↑(fib (n + 2)) ≤ pred_conts.b + gp.b * conts.b
conts_b_ineq : ↑(fib (n + 1)) ≤ conts.b
zero_lt_conts_b : 0 < conts.b
⊢ gp.b * conts.b ≤ ifp_n.fr⁻¹ * conts.b
[PROOFSTEP]
suffices (ifp_succ_n.b : K) * conts.b ≤ ifp_n.fr⁻¹ * conts.b by rwa [← ifp_succ_n_b_eq_gp_b]
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
nextConts_b_ineq : ↑(fib (n + 2)) ≤ pred_conts.b + gp.b * conts.b
conts_b_ineq : ↑(fib (n + 1)) ≤ conts.b
zero_lt_conts_b : 0 < conts.b
this : ↑ifp_succ_n.b * conts.b ≤ ifp_n.fr⁻¹ * conts.b
⊢ gp.b * conts.b ≤ ifp_n.fr⁻¹ * conts.b
[PROOFSTEP]
rwa [← ifp_succ_n_b_eq_gp_b]
[GOAL]
case this
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
nextConts_b_ineq : ↑(fib (n + 2)) ≤ pred_conts.b + gp.b * conts.b
conts_b_ineq : ↑(fib (n + 1)) ≤ conts.b
zero_lt_conts_b : 0 < conts.b
⊢ ↑ifp_succ_n.b * conts.b ≤ ifp_n.fr⁻¹ * conts.b
[PROOFSTEP]
have : (ifp_succ_n.b : K) ≤ ifp_n.fr⁻¹ :=
  IntFractPair.succ_nth_stream_b_le_nth_stream_fr_inv stream_nth_eq succ_nth_stream_eq
[GOAL]
case this
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
nextConts_b_ineq : ↑(fib (n + 2)) ≤ pred_conts.b + gp.b * conts.b
conts_b_ineq : ↑(fib (n + 1)) ≤ conts.b
zero_lt_conts_b : 0 < conts.b
this : ↑ifp_succ_n.b ≤ ifp_n.fr⁻¹
⊢ ↑ifp_succ_n.b * conts.b ≤ ifp_n.fr⁻¹ * conts.b
[PROOFSTEP]
have : 0 ≤ conts.b := le_of_lt zero_lt_conts_b
[GOAL]
case this
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
nextConts_b_ineq : ↑(fib (n + 2)) ≤ pred_conts.b + gp.b * conts.b
conts_b_ineq : ↑(fib (n + 1)) ≤ conts.b
zero_lt_conts_b : 0 < conts.b
this✝ : ↑ifp_succ_n.b ≤ ifp_n.fr⁻¹
this : 0 ≤ conts.b
⊢ ↑ifp_succ_n.b * conts.b ≤ ifp_n.fr⁻¹ * conts.b
[PROOFSTEP]
refine' mul_le_mul_of_nonneg_right _ _
[GOAL]
case this.refine'_1
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
nextConts_b_ineq : ↑(fib (n + 2)) ≤ pred_conts.b + gp.b * conts.b
conts_b_ineq : ↑(fib (n + 1)) ≤ conts.b
zero_lt_conts_b : 0 < conts.b
this✝ : ↑ifp_succ_n.b ≤ ifp_n.fr⁻¹
this : 0 ≤ conts.b
⊢ ↑ifp_succ_n.b ≤ ifp_n.fr⁻¹
[PROOFSTEP]
assumption
[GOAL]
case this.refine'_2
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
not_terminated_at_n : ¬TerminatedAt (of v) n
g : GeneralizedContinuedFraction K := of v
nextConts : Pair K := continuantsAux g (n + 2)
conts : Pair K := continuantsAux g (n + 1)
conts_eq : conts = continuantsAux g (n + 1)
pred_conts : Pair K := continuantsAux g n
pred_conts_eq : pred_conts = continuantsAux g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
gp_a_eq_one : gp.a = 1
nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b
denom : K := conts.b * (pred_conts.b + gp.b * conts.b)
ifp_succ_n : IntFractPair K
succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n
ifp_succ_n_b_eq_gp_b : ↑ifp_succ_n.b = gp.b
ifp_n : IntFractPair K
stream_nth_eq : IntFractPair.stream v n = some ifp_n
stream_nth_fr_ne_zero : ifp_n.fr ≠ 0
if_of_eq_ifp_succ_n : IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n
denom' : K := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
nextConts_b_ineq : ↑(fib (n + 2)) ≤ pred_conts.b + gp.b * conts.b
conts_b_ineq : ↑(fib (n + 1)) ≤ conts.b
zero_lt_conts_b : 0 < conts.b
this✝ : ↑ifp_succ_n.b ≤ ifp_n.fr⁻¹
this : 0 ≤ conts.b
⊢ 0 ≤ conts.b
[PROOFSTEP]
assumption
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
b : K
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators (of v)) n = some b
⊢ |v - convergents (of v) n| ≤ 1 / (b * denominators (of v) n * denominators (of v) n)
[PROOFSTEP]
have not_terminated_at_n : ¬(of v).TerminatedAt n := by simp [terminatedAt_iff_part_denom_none, nth_part_denom_eq]
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
b : K
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators (of v)) n = some b
⊢ ¬TerminatedAt (of v) n
[PROOFSTEP]
simp [terminatedAt_iff_part_denom_none, nth_part_denom_eq]
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
b : K
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators (of v)) n = some b
not_terminated_at_n : ¬TerminatedAt (of v) n
⊢ |v - convergents (of v) n| ≤ 1 / (b * denominators (of v) n * denominators (of v) n)
[PROOFSTEP]
refine'
  (abs_sub_convergents_le not_terminated_at_n).trans
    _
      -- One can show that `0 < (GeneralizedContinuedFraction.of v).denominators n` but it's easier
        -- to consider the case `(GeneralizedContinuedFraction.of v).denominators n = 0`.
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
b : K
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators (of v)) n = some b
not_terminated_at_n : ¬TerminatedAt (of v) n
⊢ 1 / (denominators (of v) n * denominators (of v) (n + 1)) ≤ 1 / (b * denominators (of v) n * denominators (of v) n)
[PROOFSTEP]
rcases(zero_le_of_denom (K := K)).eq_or_gt with ((hB : (GeneralizedContinuedFraction.of v).denominators n = 0) | hB)
[GOAL]
case inl
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
b : K
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators (of v)) n = some b
not_terminated_at_n : ¬TerminatedAt (of v) n
hB : denominators (of v) n = 0
⊢ 1 / (denominators (of v) n * denominators (of v) (n + 1)) ≤ 1 / (b * denominators (of v) n * denominators (of v) n)
[PROOFSTEP]
simp only [hB, mul_zero, zero_mul, div_zero, le_refl]
[GOAL]
case inr
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
b : K
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators (of v)) n = some b
not_terminated_at_n : ¬TerminatedAt (of v) n
hB : 0 < denominators (of v) n
⊢ 1 / (denominators (of v) n * denominators (of v) (n + 1)) ≤ 1 / (b * denominators (of v) n * denominators (of v) n)
[PROOFSTEP]
apply one_div_le_one_div_of_le
[GOAL]
case inr.ha
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
b : K
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators (of v)) n = some b
not_terminated_at_n : ¬TerminatedAt (of v) n
hB : 0 < denominators (of v) n
⊢ 0 < b * denominators (of v) n * denominators (of v) n
[PROOFSTEP]
have : 0 < b := zero_lt_one.trans_le (of_one_le_get?_part_denom nth_part_denom_eq)
[GOAL]
case inr.ha
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
b : K
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators (of v)) n = some b
not_terminated_at_n : ¬TerminatedAt (of v) n
hB : 0 < denominators (of v) n
this : 0 < b
⊢ 0 < b * denominators (of v) n * denominators (of v) n
[PROOFSTEP]
apply_rules [mul_pos]
[GOAL]
case inr.h
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
b : K
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators (of v)) n = some b
not_terminated_at_n : ¬TerminatedAt (of v) n
hB : 0 < denominators (of v) n
⊢ b * denominators (of v) n * denominators (of v) n ≤ denominators (of v) n * denominators (of v) (n + 1)
[PROOFSTEP]
conv_rhs => rw [mul_comm]
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
b : K
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators (of v)) n = some b
not_terminated_at_n : ¬TerminatedAt (of v) n
hB : 0 < denominators (of v) n
| denominators (of v) n * denominators (of v) (n + 1)
[PROOFSTEP]
rw [mul_comm]
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
b : K
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators (of v)) n = some b
not_terminated_at_n : ¬TerminatedAt (of v) n
hB : 0 < denominators (of v) n
| denominators (of v) n * denominators (of v) (n + 1)
[PROOFSTEP]
rw [mul_comm]
[GOAL]
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
b : K
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators (of v)) n = some b
not_terminated_at_n : ¬TerminatedAt (of v) n
hB : 0 < denominators (of v) n
| denominators (of v) n * denominators (of v) (n + 1)
[PROOFSTEP]
rw [mul_comm]
[GOAL]
case inr.h
K : Type u_1
v : K
n : ℕ
inst✝¹ : LinearOrderedField K
inst✝ : FloorRing K
b : K
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators (of v)) n = some b
not_terminated_at_n : ¬TerminatedAt (of v) n
hB : 0 < denominators (of v) n
⊢ b * denominators (of v) n * denominators (of v) n ≤ denominators (of v) (n + 1) * denominators (of v) n
[PROOFSTEP]
exact mul_le_mul_of_nonneg_right (le_of_succ_get?_denom nth_part_denom_eq) hB.le
