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

full_name: GenContFract.IntFractPair.fr
code: /-- We collect an integer part `b = ⌊v⌋` and fractional part `fr = v - ⌊v⌋` of a value `v` in a pair
`⟨b, fr⟩`.
-/
structure IntFractPair where
  b : ℤ
  fr : K
goal: K

full_name: GenContFract.IntFractPair
code: /-- We collect an integer part `b = ⌊v⌋` and fractional part `fr = v - ⌊v⌋` of a value `v` in a pair
`⟨b, fr⟩`.
-/
structure IntFractPair where
  b : ℤ
  fr : K
goal: Type u_1

full_name: GenContFract.IntFractPair.b
code: /-- We collect an integer part `b = ⌊v⌋` and fractional part `fr = v - ⌊v⌋` of a value `v` in a pair
`⟨b, fr⟩`.
-/
structure IntFractPair where
  b : ℤ
  fr : K
goal: ℤ

full_name: GenContFract.IntFractPair.instRepr
code: /-- Make an `IntFractPair` printable. -/
instance [Repr K] : Repr (IntFractPair K) 
goal: Repr (GenContFract.IntFractPair K)

full_name: GenContFract.IntFractPair.inhabited
code: instance inhabited [Inhabited K] : Inhabited (IntFractPair K) 
goal: Inhabited (GenContFract.IntFractPair K)

full_name: GenContFract.IntFractPair.mapFr
code: /-- Maps a function `f` on the fractional components of a given pair.
-/
def mapFr {β : Type*} (f : K → β) (gp : IntFractPair K) : IntFractPair β 
goal: GenContFract.IntFractPair β

full_name: GenContFract.IntFractPair.coeFn
code: /-- The coercion between integer-fraction pairs happens componentwise. -/
@[coe]
def coeFn : IntFractPair K → IntFractPair β 
goal: GenContFract.IntFractPair K → GenContFract.IntFractPair β

full_name: GenContFract.IntFractPair.coe
code: /-- Coerce a pair by coercing the fractional component. -/
instance coe : Coe (IntFractPair K) (IntFractPair β) 
goal: Coe (GenContFract.IntFractPair K) (GenContFract.IntFractPair β)

full_name: GenContFract.IntFractPair.coe_to_intFractPair
code: @[simp, norm_cast]
theorem coe_to_intFractPair {b : ℤ} {fr : K} :
    (↑(IntFractPair.mk b fr) : IntFractPair β) = IntFractPair.mk b (↑fr : β) 
goal: ↑{ b := b, fr := fr } = { b := b, fr := Coe.coe fr }

full_name: GenContFract.IntFractPair.of
code: /-- Creates the integer and fractional part of a value `v`, i.e. `⟨⌊v⌋, v - ⌊v⌋⟩`. -/
protected def of (v : K) : IntFractPair K 
goal: GenContFract.IntFractPair K

full_name: GenContFract.IntFractPair.stream
code: /-- Creates the stream of integer and fractional parts of a value `v` needed to obtain the continued
fraction representation of `v` in `GenContFract.of`. More precisely, given a value `v : K`, it
recursively computes a stream of option `ℤ × K` pairs as follows:
- `stream v 0 = some ⟨⌊v⌋, v - ⌊v⌋⟩`
- `stream v (n + 1) = some ⟨⌊frₙ⁻¹⌋, frₙ⁻¹ - ⌊frₙ⁻¹⌋⟩`,
    if `stream v n = some ⟨_, frₙ⟩` and `frₙ ≠ 0`
- `stream v (n + 1) = none`, otherwise

For example, let `(v : ℚ) := 3.4`. The process goes as follows:
- `stream v 0 = some ⟨⌊v⌋, v - ⌊v⌋⟩ = some ⟨3, 0.4⟩`
- `stream v 1 = some ⟨⌊0.4⁻¹⌋, 0.4⁻¹ - ⌊0.4⁻¹⌋⟩ = some ⟨⌊2.5⌋, 2.5 - ⌊2.5⌋⟩ = some ⟨2, 0.5⟩`
- `stream v 2 = some ⟨⌊0.5⁻¹⌋, 0.5⁻¹ - ⌊0.5⁻¹⌋⟩ = some ⟨⌊2⌋, 2 - ⌊2⌋⟩ = some ⟨2, 0⟩`
- `stream v n = none`, for `n ≥ 3`
-/
protected def stream (v : K) : Stream' <| Option (IntFractPair K)
  
goal: Stream' (Option (GenContFract.IntFractPair K))

full_name: GenContFract.IntFractPair.stream_isSeq
code: /-- Shows that `IntFractPair.stream` has the sequence property, that is once we return `none` at
position `n`, we also return `none` at `n + 1`.
-/
theorem stream_isSeq (v : K) : (IntFractPair.stream v).IsSeq 
goal: (GenContFract.IntFractPair.stream v).IsSeq

full_name: GenContFract.IntFractPair.seq1
code: /--
Uses `IntFractPair.stream` to create a sequence with head (i.e. `seq1`) of integer and fractional
parts of a value `v`. The first value of `IntFractPair.stream` is never `none`, so we can safely
extract it and put the tail of the stream in the sequence part.

This is just an intermediate representation and users should not (need to) directly interact with
it. The setup of rewriting/simplification lemmas that make the definitions easy to use is done in
`Algebra.ContinuedFractions.Computation.Translations`.
-/
protected def seq1 (v : K) : Stream'.Seq1 <| IntFractPair K 
goal: Stream'.Seq1 (GenContFract.IntFractPair K)

full_name: GenContFract.of
code: /-- Returns the `GenContFract` of a value. In fact, the returned gcf is also a `ContFract` that
terminates if and only if `v` is rational
(see `Algebra.ContinuedFractions.Computation.TerminatesIffRat`).

The continued fraction representation of `v` is given by `[⌊v⌋; b₀, b₁, b₂,...]`, where
`[b₀; b₁, b₂,...]` recursively is the continued fraction representation of `1 / (v - ⌊v⌋)`. This
process stops when the fractional part `v - ⌊v⌋` hits 0 at some step.

The implementation uses `IntFractPair.stream` to obtain the partial denominators of the continued
fraction. Refer to said function for more details about the computation process.
-/
protected def of [LinearOrderedField K] [FloorRing K] (v : K) : GenContFract K 
goal: GenContFract K