Theorem: GeneralizedContinuedFraction.sub_convergents_eq
File: Mathlib/Algebra/ContinuedFractions/Computation/Approximations.lean

tactic: let g := of v
state_before: 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 := (g.continuantsAux (n + 1)).b;
  let pB := (g.continuantsAux n).b;
  v - g.convergents n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
state_after: 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 := (g.continuantsAux (n + 1)).b;
  let pB := (g.continuantsAux n).b;
  v - g.convergents n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))

tactic: let conts := g.continuantsAux (n + 1)
state_before: 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 := (g.continuantsAux (n + 1)).b;
  let pB := (g.continuantsAux n).b;
  v - g.convergents n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
state_after: 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 := g.continuantsAux (n + 1)
⊢ let g := of v;
  let B := (g.continuantsAux (n + 1)).b;
  let pB := (g.continuantsAux n).b;
  v - g.convergents n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))

tactic: let pred_conts := g.continuantsAux n
state_before: 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 := g.continuantsAux (n + 1)
⊢ let g := of v;
  let B := (g.continuantsAux (n + 1)).b;
  let pB := (g.continuantsAux n).b;
  v - g.convergents n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
state_after: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux n
⊢ let g := of v;
  let B := (g.continuantsAux (n + 1)).b;
  let pB := (g.continuantsAux n).b;
  v - g.convergents n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))

tactic: have g_finite_correctness :
  v = GeneralizedContinuedFraction.compExactValue pred_conts conts ifp.fr :=
  compExactValue_correctness_of_stream_eq_some stream_nth_eq
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux n
⊢ let g := of v;
  let B := (g.continuantsAux (n + 1)).b;
  let pB := (g.continuantsAux n).b;
  v - g.convergents n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
state_after: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux n
g_finite_correctness : v = GeneralizedContinuedFraction.compExactValue pred_conts conts ifp.fr
⊢ let g := of v;
  let B := (g.continuantsAux (n + 1)).b;
  let pB := (g.continuantsAux n).b;
  v - g.convergents n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))

tactic: obtain (ifp_fr_eq_zero | ifp_fr_ne_zero) := eq_or_ne ifp.fr 0
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux n
g_finite_correctness : v = GeneralizedContinuedFraction.compExactValue pred_conts conts ifp.fr
⊢ let g := of v;
  let B := (g.continuantsAux (n + 1)).b;
  let pB := (g.continuantsAux n).b;
  v - g.convergents n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
state_after: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 := (g.continuantsAux (n + 1)).b;
  let pB := (g.continuantsAux n).b;
  v - g.convergents n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))

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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 := (g.continuantsAux (n + 1)).b;
  let pB := (g.continuantsAux n).b;
  v - g.convergents n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))

tactic: suffices v - g.convergents n = 0 by simpa [ifp_fr_eq_zero]
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 := (g.continuantsAux (n + 1)).b;
  let pB := (g.continuantsAux n).b;
  v - g.convergents n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
state_after: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux n
g_finite_correctness : v = GeneralizedContinuedFraction.compExactValue pred_conts conts ifp.fr
ifp_fr_eq_zero : ifp.fr = 0
⊢ v - g.convergents n = 0

tactic: replace g_finite_correctness : v = g.convergents n := by
  simpa [GeneralizedContinuedFraction.compExactValue, ifp_fr_eq_zero] using g_finite_correctness
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux n
g_finite_correctness : v = GeneralizedContinuedFraction.compExactValue pred_conts conts ifp.fr
ifp_fr_eq_zero : ifp.fr = 0
⊢ v - g.convergents n = 0
state_after: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux n
ifp_fr_eq_zero : ifp.fr = 0
g_finite_correctness : v = g.convergents n
⊢ v - g.convergents n = 0

tactic: exact sub_eq_zero.2 g_finite_correctness
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux n
ifp_fr_eq_zero : ifp.fr = 0
g_finite_correctness : v = g.convergents n
⊢ v - g.convergents n = 0
state_after: no goals

tactic: simpa [ifp_fr_eq_zero]
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux n
g_finite_correctness : v = GeneralizedContinuedFraction.compExactValue pred_conts conts ifp.fr
ifp_fr_eq_zero : ifp.fr = 0
this : v - g.convergents n = 0
⊢ let g := of v;
  let B := (g.continuantsAux (n + 1)).b;
  let pB := (g.continuantsAux n).b;
  v - g.convergents n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
state_after: no goals

tactic: simpa [GeneralizedContinuedFraction.compExactValue, ifp_fr_eq_zero] using g_finite_correctness
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux n
g_finite_correctness : v = GeneralizedContinuedFraction.compExactValue pred_conts conts ifp.fr
ifp_fr_eq_zero : ifp.fr = 0
⊢ v = g.convergents n
state_after: no goals

tactic: let A := conts.a
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 := (g.continuantsAux (n + 1)).b;
  let pB := (g.continuantsAux n).b;
  v - g.convergents n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
state_after: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 := (g.continuantsAux (n + 1)).b;
  let pB := (g.continuantsAux n).b;
  v - g.convergents n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))

tactic: let B := conts.b
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 := (g.continuantsAux (n + 1)).b;
  let pB := (g.continuantsAux n).b;
  v - g.convergents n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
state_after: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 := (g.continuantsAux (n + 1)).b;
  let pB := (g.continuantsAux n).b;
  v - g.convergents n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))

tactic: let pA := pred_conts.a
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 := (g.continuantsAux (n + 1)).b;
  let pB := (g.continuantsAux n).b;
  v - g.convergents n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
state_after: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 := (g.continuantsAux (n + 1)).b;
  let pB := (g.continuantsAux n).b;
  v - g.convergents n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))

tactic: let pB := pred_conts.b
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 := (g.continuantsAux (n + 1)).b;
  let pB := (g.continuantsAux n).b;
  v - g.convergents n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
state_after: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 := (g.continuantsAux (n + 1)).b;
  let pB := (g.continuantsAux n).b;
  v - g.convergents n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))

tactic: suffices v - A / B = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB)) by simpa [ifp_fr_ne_zero]
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 := (g.continuantsAux (n + 1)).b;
  let pB := (g.continuantsAux n).b;
  v - g.convergents n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
state_after: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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))

tactic: replace g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B) := by
  simpa [GeneralizedContinuedFraction.compExactValue, ifp_fr_ne_zero, nextContinuants,
    nextNumerator, nextDenominator, add_comm] using g_finite_correctness
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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))
state_after: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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))

tactic: suffices
  (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B) - A / B = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB)) by
  rwa [g_finite_correctness]
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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))
state_after: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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))

tactic: have determinant_eq : pA * B - pB * A = (-1) ^ n :=
  determinant_aux n_eq_zero_or_not_terminated_at_pred_n
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 ∨ ¬g.TerminatedAt (n - 1)
⊢ (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B) - A / B = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
state_after: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 ∨ ¬g.TerminatedAt (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))

tactic: have zero_lt_B : 0 < B := B_ineq.trans_lt' <| cast_pos.2 <| fib_pos.2 n.succ_pos
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 ∨ ¬g.TerminatedAt (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))
state_after: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 ∨ ¬g.TerminatedAt (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))

tactic: have : 0 ≤ pB := (cast_nonneg _).trans pB_ineq
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 ∨ ¬g.TerminatedAt (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))
state_after: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 ∨ ¬g.TerminatedAt (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
this : 0 ≤ pB
⊢ (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B) - A / B = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))

tactic: have : 0 < ifp.fr :=
  ifp_fr_ne_zero.lt_of_le' <| IntFractPair.nth_stream_fr_nonneg stream_nth_eq
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 ∨ ¬g.TerminatedAt (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
this : 0 ≤ pB
⊢ (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B) - A / B = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
state_after: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 ∨ ¬g.TerminatedAt (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
this✝ : 0 ≤ pB
this : 0 < ifp.fr
⊢ (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B) - A / B = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))

tactic: have : pB + ifp.fr⁻¹ * B ≠ 0 := by positivity
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 ∨ ¬g.TerminatedAt (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
this✝ : 0 ≤ pB
this : 0 < ifp.fr
⊢ (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B) - A / B = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
state_after: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 ∨ ¬g.TerminatedAt (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
this✝¹ : 0 ≤ pB
this✝ : 0 < ifp.fr
this : pB + ifp.fr⁻¹ * B ≠ 0
⊢ (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B) - A / B = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))

tactic: 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 zero_lt_B.ne']
  _ = (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
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 ∨ ¬g.TerminatedAt (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
this✝¹ : 0 ≤ pB
this✝ : 0 < ifp.fr
this : pB + ifp.fr⁻¹ * B ≠ 0
⊢ (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B) - A / B = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
state_after: no goals

tactic: simpa [ifp_fr_ne_zero]
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 := (g.continuantsAux (n + 1)).b;
  let pB := (g.continuantsAux n).b;
  v - g.convergents n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
state_after: no goals

tactic: simpa [GeneralizedContinuedFraction.compExactValue, ifp_fr_ne_zero, nextContinuants,
  nextNumerator, nextDenominator, add_comm] using g_finite_correctness
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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)
state_after: no goals

tactic: rwa [g_finite_correctness]
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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))
state_after: no goals

tactic: cases' n with n'
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 ∨ ¬g.TerminatedAt (n - 1)
state_after: 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 0 = some ifp
conts : Pair K := g.continuantsAux (0 + 1)
pred_conts : Pair K := g.continuantsAux 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)
⊢ 0 = 0 ∨ ¬g.TerminatedAt (0 - 1)

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 (n' + 1) = some ifp
conts : Pair K := g.continuantsAux (n' + 1 + 1)
pred_conts : Pair K := g.continuantsAux (n' + 1)
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' + 1 = 0 ∨ ¬g.TerminatedAt (n' + 1 - 1)

tactic: simp
state_before: 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 0 = some ifp
conts : Pair K := g.continuantsAux (0 + 1)
pred_conts : Pair K := g.continuantsAux 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)
⊢ 0 = 0 ∨ ¬g.TerminatedAt (0 - 1)
state_after: no goals

tactic: have : IntFractPair.stream v (n' + 1) ≠ none := by simp [stream_nth_eq]
state_before: 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 (n' + 1) = some ifp
conts : Pair K := g.continuantsAux (n' + 1 + 1)
pred_conts : Pair K := g.continuantsAux (n' + 1)
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' + 1 = 0 ∨ ¬g.TerminatedAt (n' + 1 - 1)
state_after: 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 (n' + 1) = some ifp
conts : Pair K := g.continuantsAux (n' + 1 + 1)
pred_conts : Pair K := g.continuantsAux (n' + 1)
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
⊢ n' + 1 = 0 ∨ ¬g.TerminatedAt (n' + 1 - 1)

tactic: have : ¬g.TerminatedAt n' :=
  (not_congr of_terminatedAt_n_iff_succ_nth_intFractPair_stream_eq_none).2 this
state_before: 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 (n' + 1) = some ifp
conts : Pair K := g.continuantsAux (n' + 1 + 1)
pred_conts : Pair K := g.continuantsAux (n' + 1)
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
⊢ n' + 1 = 0 ∨ ¬g.TerminatedAt (n' + 1 - 1)
state_after: 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 (n' + 1) = some ifp
conts : Pair K := g.continuantsAux (n' + 1 + 1)
pred_conts : Pair K := g.continuantsAux (n' + 1)
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 : ¬g.TerminatedAt n'
⊢ n' + 1 = 0 ∨ ¬g.TerminatedAt (n' + 1 - 1)

tactic: exact Or.inr this
state_before: 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 (n' + 1) = some ifp
conts : Pair K := g.continuantsAux (n' + 1 + 1)
pred_conts : Pair K := g.continuantsAux (n' + 1)
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 : ¬g.TerminatedAt n'
⊢ n' + 1 = 0 ∨ ¬g.TerminatedAt (n' + 1 - 1)
state_after: no goals

tactic: simp [stream_nth_eq]
state_before: 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 (n' + 1) = some ifp
conts : Pair K := g.continuantsAux (n' + 1 + 1)
pred_conts : Pair K := g.continuantsAux (n' + 1)
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
state_after: no goals

tactic: cases' n_eq_zero_or_not_terminated_at_pred_n with n_eq_zero not_terminated_at_pred_n
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 ∨ ¬g.TerminatedAt (n - 1)
determinant_eq : pA * B - pB * A = (-1) ^ n
⊢ n ≤ 1 ∨ ¬g.TerminatedAt (n - 2)
state_after: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 ∨ ¬g.TerminatedAt (n - 2)

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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 : ¬g.TerminatedAt (n - 1)
⊢ n ≤ 1 ∨ ¬g.TerminatedAt (n - 2)

tactic: simp [n_eq_zero]
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 ∨ ¬g.TerminatedAt (n - 2)
state_after: no goals

tactic: exact Or.inr <| mt (terminated_stable (n - 1).pred_le) not_terminated_at_pred_n
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 : ¬g.TerminatedAt (n - 1)
⊢ n ≤ 1 ∨ ¬g.TerminatedAt (n - 2)
state_after: no goals

tactic: cases' n_eq_zero_or_not_terminated_at_pred_n with n_eq_zero not_terminated_at_pred_n
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 ∨ ¬g.TerminatedAt (n - 1)
determinant_eq : pA * B - pB * A = (-1) ^ n
pB_ineq : ↑(fib n) ≤ pB
⊢ n + 1 ≤ 1 ∨ ¬g.TerminatedAt (n + 1 - 2)
state_after: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 ∨ ¬g.TerminatedAt (n + 1 - 2)

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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 : ¬g.TerminatedAt (n - 1)
⊢ n + 1 ≤ 1 ∨ ¬g.TerminatedAt (n + 1 - 2)

tactic: simp [n_eq_zero, le_refl]
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 ∨ ¬g.TerminatedAt (n + 1 - 2)
state_after: no goals

tactic: exact Or.inr not_terminated_at_pred_n
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 : ¬g.TerminatedAt (n - 1)
⊢ n + 1 ≤ 1 ∨ ¬g.TerminatedAt (n + 1 - 2)
state_after: no goals

tactic: positivity
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 ∨ ¬g.TerminatedAt (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
this✝ : 0 ≤ pB
this : 0 < ifp.fr
⊢ pB + ifp.fr⁻¹ * B ≠ 0
state_after: no goals

tactic: rw [div_sub_div _ _ this zero_lt_B.ne']
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 ∨ ¬g.TerminatedAt (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
this✝¹ : 0 ≤ pB
this✝ : 0 < ifp.fr
this : pB + ifp.fr⁻¹ * B ≠ 0
⊢ (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)
state_after: no goals

tactic: repeat' rw [add_mul]
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 ∨ ¬g.TerminatedAt (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
this✝¹ : 0 ≤ pB
this✝ : 0 < ifp.fr
this : pB + ifp.fr⁻¹ * B ≠ 0
⊢ ((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.75424
state_after: no goals

tactic: rw [add_mul]
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 ∨ ¬g.TerminatedAt (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
this✝¹ : 0 ≤ pB
this✝ : 0 < ifp.fr
this : pB + ifp.fr⁻¹ * B ≠ 0
⊢ (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.75424
state_after: no goals

tactic: ring
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 ∨ ¬g.TerminatedAt (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
this✝¹ : 0 ≤ pB
this✝ : 0 < ifp.fr
this : pB + ifp.fr⁻¹ * B ≠ 0
⊢ (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)
state_after: no goals

tactic: rw [determinant_eq]
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 ∨ ¬g.TerminatedAt (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
this✝¹ : 0 ≤ pB
this✝ : 0 < ifp.fr
this : pB + ifp.fr⁻¹ * B ≠ 0
⊢ (pA * B - pB * A) / ((pB + ifp.fr⁻¹ * B) * B) = (-1) ^ n / ((pB + ifp.fr⁻¹ * B) * B)
state_after: no goals

tactic: ac_rfl
state_before: 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 := g.continuantsAux (n + 1)
pred_conts : Pair K := g.continuantsAux 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 ∨ ¬g.TerminatedAt (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
this✝¹ : 0 ≤ pB
this✝ : 0 < ifp.fr
this : pB + ifp.fr⁻¹ * B ≠ 0
⊢ (-1) ^ n / ((pB + ifp.fr⁻¹ * B) * B) = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))
state_after: no goals