File: Mathlib/Algebra/ContinuedFractions/Computation/Approximations.lean

full_name: GenContFract.IntFractPair.nth_stream_fr_nonneg_lt_one
code: /-- Shows that the fractional parts of the stream are in `[0,1)`. -/
theorem nth_stream_fr_nonneg_lt_one {ifp_n : IntFractPair K}
    (nth_stream_eq : IntFractPair.stream v n = some ifp_n) : 0 ≤ ifp_n.fr ∧ ifp_n.fr < 1 
goal: 0 ≤ ifp_n.fr ∧ ifp_n.fr < 1

full_name: GenContFract.IntFractPair.nth_stream_fr_nonneg
code: /-- Shows that the fractional parts of the stream are nonnegative. -/
theorem nth_stream_fr_nonneg {ifp_n : IntFractPair K}
    (nth_stream_eq : IntFractPair.stream v n = some ifp_n) : 0 ≤ ifp_n.fr 
goal: 0 ≤ ifp_n.fr

full_name: GenContFract.IntFractPair.nth_stream_fr_lt_one
code: /-- Shows that the fractional parts of the stream are smaller than one. -/
theorem nth_stream_fr_lt_one {ifp_n : IntFractPair K}
    (nth_stream_eq : IntFractPair.stream v n = some ifp_n) : ifp_n.fr < 1 
goal: ifp_n.fr < 1

full_name: GenContFract.IntFractPair.one_le_succ_nth_stream_b
code: /-- Shows that the integer parts of the stream are at least one. -/
theorem one_le_succ_nth_stream_b {ifp_succ_n : IntFractPair K}
    (succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n) : 1 ≤ ifp_succ_n.b 
goal: 1 ≤ ifp_succ_n.b

full_name: GenContFract.IntFractPair.succ_nth_stream_b_le_nth_stream_fr_inv
code: /--
Shows that the `n + 1`th integer part `bₙ₊₁` of the stream is smaller or equal than the inverse of
the `n`th fractional part `frₙ` of the stream.
This result is straight-forward as `bₙ₊₁` is defined as the floor of `1 / frₙ`.
-/
theorem succ_nth_stream_b_le_nth_stream_fr_inv {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 : K) ≤ ifp_n.fr⁻¹ 
goal: ↑ifp_succ_n.b ≤ ifp_n.fr⁻¹

full_name: GenContFract.of_one_le_get?_partDen
code: /-- Shows that the integer parts of the continued fraction are at least one. -/
theorem of_one_le_get?_partDen {b : K}
    (nth_partDen_eq : (of v).partDens.get? n = some b) : 1 ≤ b 
goal: 1 ≤ b

full_name: GenContFract.of_partNum_eq_one_and_exists_int_partDen_eq
code: /--
Shows that the partial numerators `aᵢ` of the continued fraction are equal to one and the partial
denominators `bᵢ` correspond to integers.
-/
theorem of_partNum_eq_one_and_exists_int_partDen_eq {gp : GenContFract.Pair K}
    (nth_s_eq : (of v).s.get? n = some gp) : gp.a = 1 ∧ ∃ z : ℤ, gp.b = (z : K) 
goal: gp.a = 1 ∧ ∃ z, gp.b = ↑z

full_name: GenContFract.of_partNum_eq_one
code: /-- Shows that the partial numerators `aᵢ` are equal to one. -/
theorem of_partNum_eq_one {a : K} (nth_partNum_eq : (of v).partNums.get? n = some a) :
    a = 1 
goal: a = 1

full_name: GenContFract.exists_int_eq_of_partDen
code: /-- Shows that the partial denominators `bᵢ` correspond to an integer. -/
theorem exists_int_eq_of_partDen {b : K}
    (nth_partDen_eq : (of v).partDens.get? n = some b) : ∃ z : ℤ, b = (z : K) 
goal: ∃ z, b = ↑z

full_name: GenContFract.of_isSimpContFract
code: theorem GenContFract.of_isSimpContFract :
    (of v).IsSimpContFract 
goal: (GenContFract.of v).IsSimpContFract

full_name: SimpContFract.of
code: /-- Creates the simple continued fraction of a value. -/
nonrec def SimpContFract.of : SimpContFract K 
goal: SimpContFract K

full_name: SimpContFract.of_isContFract
code: theorem SimpContFract.of_isContFract :
    (SimpContFract.of v).IsContFract 
goal: (SimpContFract.of v).IsContFract

full_name: ContFract.of
code: /-- Creates the continued fraction of a value. -/
def ContFract.of : ContFract K 
goal: ContFract K

full_name: GenContFract.fib_le_of_contsAux_b
code: theorem fib_le_of_contsAux_b :
    n ≤ 1 ∨ ¬(of v).TerminatedAt (n - 2) → (fib n : K) ≤ ((of v).contsAux n).b 
goal: n ≤ 1 ∨ ¬(GenContFract.of v).TerminatedAt (n - 2) → ↑(Nat.fib n) ≤ ((GenContFract.of v).contsAux n).b

full_name: GenContFract.succ_nth_fib_le_of_nth_den
code: /-- Shows that the `n`th denominator is greater than or equal to the `n + 1`th fibonacci number,
that is `Nat.fib (n + 1) ≤ Bₙ`. -/
theorem succ_nth_fib_le_of_nth_den (hyp : n = 0 ∨ ¬(of v).TerminatedAt (n - 1)) :
    (fib (n + 1) : K) ≤ (of v).dens n 
goal: ↑(Nat.fib (n + 1)) ≤ (GenContFract.of v).dens n

full_name: GenContFract.zero_le_of_contsAux_b
code: theorem zero_le_of_contsAux_b : 0 ≤ ((of v).contsAux n).b 
goal: 0 ≤ ((GenContFract.of v).contsAux n).b

full_name: GenContFract.zero_le_of_den
code: /-- Shows that all denominators are nonnegative. -/
theorem zero_le_of_den : 0 ≤ (of v).dens n 
goal: 0 ≤ (GenContFract.of v).dens n

full_name: GenContFract.le_of_succ_succ_get?_contsAux_b
code: theorem le_of_succ_succ_get?_contsAux_b {b : K}
    (nth_partDen_eq : (of v).partDens.get? n = some b) :
    b * ((of v).contsAux <| n + 1).b ≤ ((of v).contsAux <| n + 2).b 
goal: b * ((GenContFract.of v).contsAux (n + 1)).b ≤ ((GenContFract.of v).contsAux (n + 2)).b

full_name: GenContFract.le_of_succ_get?_den
code: /-- Shows that `bₙ * Bₙ ≤ Bₙ₊₁`, where `bₙ` is the `n`th partial denominator and `Bₙ₊₁` and `Bₙ` are
the `n + 1`th and `n`th denominator of the continued fraction. -/
theorem le_of_succ_get?_den {b : K}
    (nth_partDenom_eq : (of v).partDens.get? n = some b) :
    b * (of v).dens n ≤ (of v).dens (n + 1) 
goal: b * (GenContFract.of v).dens n ≤ (GenContFract.of v).dens (n + 1)

full_name: GenContFract.of_den_mono
code: /-- Shows that the sequence of denominators is monotone, that is `Bₙ ≤ Bₙ₊₁`. -/
theorem of_den_mono : (of v).dens n ≤ (of v).dens (n + 1) 
goal: (GenContFract.of v).dens n ≤ (GenContFract.of v).dens (n + 1)

full_name: GenContFract.sub_convs_eq
code: /-- This lemma follows from the finite correctness proof, the determinant equality, and
by simplifying the difference. -/
theorem sub_convs_eq {ifp : IntFractPair K}
    (stream_nth_eq : IntFractPair.stream v n = some ifp) :
    let g := of v
    let B := (g.contsAux (n + 1)).b
    let pB := (g.contsAux n).b
    v - g.convs n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB)) 
goal: let g := GenContFract.of v;
let B := (g.contsAux (n + 1)).b;
let pB := (g.contsAux n).b;
v - g.convs n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB))

full_name: GenContFract.abs_sub_convs_le
code: /-- Shows that `|v - Aₙ / Bₙ| ≤ 1 / (Bₙ * Bₙ₊₁)`. -/
theorem abs_sub_convs_le (not_terminatedAt_n : ¬(of v).TerminatedAt n) :
    |v - (of v).convs n| ≤ 1 / ((of v).dens n * ((of v).dens <| n + 1)) 
goal: |v - (GenContFract.of v).convs n| ≤ 1 / ((GenContFract.of v).dens n * (GenContFract.of v).dens (n + 1))

full_name: GenContFract.abs_sub_convergents_le'
code: /-- Shows that `|v - Aₙ / Bₙ| ≤ 1 / (bₙ * Bₙ * Bₙ)`. This bound is worse than the one shown in
`GenContFract.abs_sub_convs_le`, but sometimes it is easier to apply and
sufficient for one's use case.
 -/
theorem abs_sub_convergents_le' {b : K}
    (nth_partDen_eq : (of v).partDens.get? n = some b) :
    |v - (of v).convs n| ≤ 1 / (b * (of v).dens n * (of v).dens n) 
goal: |v - (GenContFract.of v).convs n| ≤ 1 / (b * (GenContFract.of v).dens n * (GenContFract.of v).dens n)