File: Mathlib/Algebra/ContinuedFractions/Basic.lean

full_name: GenContFract.Pair.a
code: /-- We collect a partial numerator `aᵢ` and partial denominator `bᵢ` in a pair `⟨aᵢ, bᵢ⟩`. -/
structure GenContFract.Pair where
  /-- Partial numerator -/
  a : α
  /-- Partial denominator -/
  b : α
  deriving Inhabited
goal: α

full_name: GenContFract.Pair
code: /-- We collect a partial numerator `aᵢ` and partial denominator `bᵢ` in a pair `⟨aᵢ, bᵢ⟩`. -/
structure GenContFract.Pair where
  /-- Partial numerator -/
  a : α
  /-- Partial denominator -/
  b : α
  deriving Inhabited
goal: Type u_1

full_name: GenContFract.instInhabitedPair
code: /-- We collect a partial numerator `aᵢ` and partial denominator `bᵢ` in a pair `⟨aᵢ, bᵢ⟩`. -/
structure GenContFract.Pair where
  /-- Partial numerator -/
  a : α
  /-- Partial denominator -/
  b : α
  deriving Inhabited
goal: {a : Type u_2} → [inst : Inhabited a] → Inhabited (GenContFract.Pair a)

full_name: GenContFract.Pair.b
code: /-- We collect a partial numerator `aᵢ` and partial denominator `bᵢ` in a pair `⟨aᵢ, bᵢ⟩`. -/
structure GenContFract.Pair where
  /-- Partial numerator -/
  a : α
  /-- Partial denominator -/
  b : α
  deriving Inhabited
goal: α

full_name: GenContFract.Pair.instRepr
code: /-- Make a `GenContFract.Pair` printable. -/
instance [Repr α] : Repr (Pair α) 
goal: Repr (GenContFract.Pair α)

full_name: GenContFract.Pair.map
code: /-- Maps a function `f` on both components of a given pair. -/
def map {β : Type*} (f : α → β) (gp : Pair α) : Pair β 
goal: GenContFract.Pair β

full_name: GenContFract.Pair.coeFn
code: /-- The coercion between numerator-denominator pairs happens componentwise. -/
@[coe]
def coeFn : Pair α → Pair β 
goal: GenContFract.Pair α → GenContFract.Pair β

full_name: GenContFract.Pair.instCoe
code: /-- Coerce a pair by elementwise coercion. -/
instance : Coe (Pair α) (Pair β) 
goal: Coe (GenContFract.Pair α) (GenContFract.Pair β)

full_name: GenContFract.Pair.coe_toPair
code: @[simp, norm_cast]
theorem coe_toPair {a b : α} : (↑(Pair.mk a b) : Pair β) = Pair.mk (a : β) (b : β) 
goal: ↑{ a := a, b := b } = { a := Coe.coe a, b := Coe.coe b }

full_name: GenContFract.s
code: /-- A *generalised continued fraction* (gcf) is a potentially infinite expression of the form
$$
  h + \dfrac{a_0}
            {b_0 + \dfrac{a_1}
                         {b_1 + \dfrac{a_2}
                                      {b_2 + \dfrac{a_3}
                                                   {b_3 + \dots}}}}
$$
where `h` is called the *head term* or *integer part*, the `aᵢ` are called the
*partial numerators* and the `bᵢ` the *partial denominators* of the gcf.
We store the sequence of partial numerators and denominators in a sequence of `GenContFract.Pair`s
`s`.
For convenience, one often writes `[h; (a₀, b₀), (a₁, b₁), (a₂, b₂),...]`.
-/
@[ext]
structure GenContFract where
  /-- Head term -/
  h : α
  /-- Sequence of partial numerator and denominator pairs. -/
  s : Stream'.Seq <| Pair α
goal: Stream'.Seq (GenContFract.Pair α)

full_name: GenContFract.h
code: /-- A *generalised continued fraction* (gcf) is a potentially infinite expression of the form
$$
  h + \dfrac{a_0}
            {b_0 + \dfrac{a_1}
                         {b_1 + \dfrac{a_2}
                                      {b_2 + \dfrac{a_3}
                                                   {b_3 + \dots}}}}
$$
where `h` is called the *head term* or *integer part*, the `aᵢ` are called the
*partial numerators* and the `bᵢ` the *partial denominators* of the gcf.
We store the sequence of partial numerators and denominators in a sequence of `GenContFract.Pair`s
`s`.
For convenience, one often writes `[h; (a₀, b₀), (a₁, b₁), (a₂, b₂),...]`.
-/
@[ext]
structure GenContFract where
  /-- Head term -/
  h : α
  /-- Sequence of partial numerator and denominator pairs. -/
  s : Stream'.Seq <| Pair α
goal: α

full_name: GenContFract
code: /-- A *generalised continued fraction* (gcf) is a potentially infinite expression of the form
$$
  h + \dfrac{a_0}
            {b_0 + \dfrac{a_1}
                         {b_1 + \dfrac{a_2}
                                      {b_2 + \dfrac{a_3}
                                                   {b_3 + \dots}}}}
$$
where `h` is called the *head term* or *integer part*, the `aᵢ` are called the
*partial numerators* and the `bᵢ` the *partial denominators* of the gcf.
We store the sequence of partial numerators and denominators in a sequence of `GenContFract.Pair`s
`s`.
For convenience, one often writes `[h; (a₀, b₀), (a₁, b₁), (a₂, b₂),...]`.
-/
@[ext]
structure GenContFract where
  /-- Head term -/
  h : α
  /-- Sequence of partial numerator and denominator pairs. -/
  s : Stream'.Seq <| Pair α
goal: Type u_1

full_name: GenContFract.ofInteger
code: /-- Constructs a generalized continued fraction without fractional part. -/
def ofInteger (a : α) : GenContFract α 
goal: GenContFract α

full_name: GenContFract.instInhabited
code: instance [Inhabited α] : Inhabited (GenContFract α) 
goal: Inhabited (GenContFract α)

full_name: GenContFract.partNums
code: /-- Returns the sequence of partial numerators `aᵢ` of `g`. -/
def partNums (g : GenContFract α) : Stream'.Seq α 
goal: Stream'.Seq α

full_name: GenContFract.partDens
code: /-- Returns the sequence of partial denominators `bᵢ` of `g`. -/
def partDens (g : GenContFract α) : Stream'.Seq α 
goal: Stream'.Seq α

full_name: GenContFract.TerminatedAt
code: /-- A gcf terminated at position `n` if its sequence terminates at position `n`. -/
def TerminatedAt (g : GenContFract α) (n : ℕ) : Prop 
goal: Prop

full_name: GenContFract.terminatedAtDecidable
code: /-- It is decidable whether a gcf terminated at a given position. -/
instance terminatedAtDecidable (g : GenContFract α) (n : ℕ) :
    Decidable (g.TerminatedAt n) 
goal: Decidable (g.TerminatedAt n)

full_name: GenContFract.Terminates
code: /-- A gcf terminates if its sequence terminates. -/
def Terminates (g : GenContFract α) : Prop 
goal: Prop

full_name: GenContFract.coeFn
code: /-- The coercion between `GenContFract` happens on the head term
and all numerator-denominator pairs componentwise. -/
@[coe]
def coeFn : GenContFract α → GenContFract β 
goal: GenContFract α → GenContFract β

full_name: GenContFract.instCoe
code: /-- Coerce a gcf by elementwise coercion. -/
instance : Coe (GenContFract α) (GenContFract β) 
goal: Coe (GenContFract α) (GenContFract β)

full_name: GenContFract.coe_toGenContFract
code: @[simp, norm_cast]
theorem coe_toGenContFract {g : GenContFract α} :
    (g : GenContFract β) =
      ⟨(g.h : β), (g.s.map (↑) : Stream'.Seq <| Pair β)⟩ 
goal: ↑g = { h := Coe.coe g.h, s := Stream'.Seq.map GenContFract.Pair.coeFn g.s }

full_name: GenContFract.IsSimpContFract
code: /-- A generalized continued fraction is a *simple continued fraction* if all partial numerators are
equal to one.
$$
  h + \dfrac{1}
            {b_0 + \dfrac{1}
                         {b_1 + \dfrac{1}
                                      {b_2 + \dfrac{1}
                                                   {b_3 + \dots}}}}
$$
-/
def GenContFract.IsSimpContFract (g : GenContFract α)
    [One α] : Prop 
goal: Prop

full_name: SimpContFract
code: /-- A *simple continued fraction* (scf) is a generalized continued fraction (gcf) whose partial
numerators are equal to one.
$$
  h + \dfrac{1}
            {b_0 + \dfrac{1}
                         {b_1 + \dfrac{1}
                                      {b_2 + \dfrac{1}
                                                   {b_3 + \dots}}}}
$$
For convenience, one often writes `[h; b₀, b₁, b₂,...]`.
It is encoded as the subtype of gcfs that satisfy `GenContFract.IsSimpContFract`.
 -/
def SimpContFract [One α] 
goal: Type u_1

full_name: SimpContFract.ofInteger
code: /-- Constructs a simple continued fraction without fractional part. -/
def ofInteger (a : α) : SimpContFract α 
goal: SimpContFract α

full_name: SimpContFract.instInhabited
code: instance : Inhabited (SimpContFract α) 
goal: Inhabited (SimpContFract α)

full_name: SimpContFract.instCoeGenContFract
code: /-- Lift a scf to a gcf using the inclusion map. -/
instance : Coe (SimpContFract α) (GenContFract α) 
goal: Coe (SimpContFract α) (GenContFract α)

full_name: SimpContFract.IsContFract
code: /--
A simple continued fraction is a *(regular) continued fraction* ((r)cf) if all partial denominators
`bᵢ` are positive, i.e. `0 < bᵢ`.
-/
def SimpContFract.IsContFract [One α] [Zero α] [LT α]
    (s : SimpContFract α) : Prop 
goal: Prop

full_name: ContFract
code: /-- A *(regular) continued fraction* ((r)cf) is a simple continued fraction (scf) whose partial
denominators are all positive. It is the subtype of scfs that satisfy `SimpContFract.IsContFract`.
 -/
def ContFract [One α] [Zero α] [LT α] 
goal: Type u_1

full_name: ContFract.ofInteger
code: /-- Constructs a continued fraction without fractional part. -/
def ofInteger (a : α) : ContFract α 
goal: ContFract α

full_name: ContFract.instInhabited
code: instance : Inhabited (ContFract α) 
goal: Inhabited (ContFract α)

full_name: ContFract.instCoeSimpContFract
code: /-- Lift a cf to a scf using the inclusion map. -/
instance : Coe (ContFract α) (SimpContFract α) 
goal: Coe (ContFract α) (SimpContFract α)

full_name: ContFract.instCoeGenContFract
code: /-- Lift a cf to a scf using the inclusion map. -/
instance : Coe (ContFract α) (GenContFract α) 
goal: Coe (ContFract α) (GenContFract α)

full_name: GenContFract.nextNum
code: /-- Returns the next numerator `Aₙ = bₙ₋₁ * Aₙ₋₁ + aₙ₋₁ * Aₙ₋₂`, where `predA` is `Aₙ₋₁`,
`ppredA` is `Aₙ₋₂`, `a` is `aₙ₋₁`, and `b` is `bₙ₋₁`.
-/
def nextNum (a b ppredA predA : K) : K 
goal: K

full_name: GenContFract.nextDen
code: /-- Returns the next denominator `Bₙ = bₙ₋₁ * Bₙ₋₁ + aₙ₋₁ * Bₙ₋₂`, where `predB` is `Bₙ₋₁` and
`ppredB` is `Bₙ₋₂`, `a` is `aₙ₋₁`, and `b` is `bₙ₋₁`.
-/
def nextDen (aₙ bₙ ppredB predB : K) : K 
goal: K

full_name: GenContFract.nextConts
code: /--
Returns the next continuants `⟨Aₙ, Bₙ⟩` using `nextNum` and `nextDen`, where `pred`
is `⟨Aₙ₋₁, Bₙ₋₁⟩`, `ppred` is `⟨Aₙ₋₂, Bₙ₋₂⟩`, `a` is `aₙ₋₁`, and `b` is `bₙ₋₁`.
-/
def nextConts (a b : K) (ppred pred : Pair K) : Pair K 
goal: GenContFract.Pair K

full_name: GenContFract.contsAux
code: /-- Returns the continuants `⟨Aₙ₋₁, Bₙ₋₁⟩` of `g`. -/
def contsAux (g : GenContFract K) : Stream' (Pair K)
  
goal: Stream' (GenContFract.Pair K)

full_name: GenContFract.conts
code: /-- Returns the continuants `⟨Aₙ, Bₙ⟩` of `g`. -/
def conts (g : GenContFract K) : Stream' (Pair K) 
goal: Stream' (GenContFract.Pair K)

full_name: GenContFract.nums
code: /-- Returns the numerators `Aₙ` of `g`. -/
def nums (g : GenContFract K) : Stream' K 
goal: Stream' K

full_name: GenContFract.dens
code: /-- Returns the denominators `Bₙ` of `g`. -/
def dens (g : GenContFract K) : Stream' K 
goal: Stream' K

full_name: GenContFract.convs
code: /-- Returns the convergents `Aₙ / Bₙ` of `g`, where `Aₙ, Bₙ` are the nth continuants of `g`. -/
def convs (g : GenContFract K) : Stream' K 
goal: Stream' K

full_name: GenContFract.convs'Aux
code: /--
Returns the approximation of the fraction described by the given sequence up to a given position n.
For example, `convs'Aux [(1, 2), (3, 4), (5, 6)] 2 = 1 / (2 + 3 / 4)` and
`convs'Aux [(1, 2), (3, 4), (5, 6)] 0 = 0`.
-/
def convs'Aux : Stream'.Seq (Pair K) → ℕ → K
  
goal: Stream'.Seq (GenContFract.Pair K) → ℕ → K

full_name: GenContFract.convs'
code: /-- Returns the convergents of `g` by evaluating the fraction described by `g` up to a given
position `n`. For example, `convs' [9; (1, 2), (3, 4), (5, 6)] 2 = 9 + 1 / (2 + 3 / 4)` and
`convs' [9; (1, 2), (3, 4), (5, 6)] 0 = 9`
-/
def convs' (g : GenContFract K) (n : ℕ) : K 
goal: K