Basic Definitions/Theorems for Continued Fractions

Summary

We define generalised, simple, and regular continued fractions and functions to evaluate their convergents. We follow the naming conventions from Wikipedia and [wall2018analytic], Chapter 1.

Main definitions

  1. Generalised continued fractions (gcfs)
  2. Simple continued fractions (scfs)
  3. (Regular) continued fractions ((r)cfs)
  4. Computation of convergents using the recurrence relation in convergents.
  5. Computation of convergents by directly evaluating the fraction described by the gcf in convergents'.

Implementation notes

  1. The most commonly used kind of continued fractions in the literature are regular continued fractions. We hence just call them continued_fractions in the library.
  2. We use sequences from data.seq to encode potentially infinite sequences.

References

Tags

numerics, number theory, approximations, fractions


generalized_continued_fraction.pair

We collect a partial numerator aᵢ and partial denominator bᵢ in a pair ⟨aᵢ,bᵢ⟩.

generalized_continued_fraction.pair.has_repr

Make a gcf.pair printable.

generalized_continued_fraction.pair.has_coe_to_generalized_continued_fraction_pair

Coerce a pair by elementwise coercion.

generalized_continued_fraction

A generalised continued fraction (gcf) is a potentially infinite expression of the form

                            a₀
            h + --------------------------
                              a₁
                  b₀ + --------------------
                                a₂
                        b₁ + --------------
                                    a₃
                              b₂ + --------
                                  b₃ + ...

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 generalized_continued_fraction.pairs s. For convenience, one often writes [h; (a₀, b₀), (a₁, b₁), (a₂, b₂),...].

generalized_continued_fraction.partial_numerators

Returns the sequence of partial numerators aᵢ of g.

generalized_continued_fraction.partial_denominators

Returns the sequence of partial denominators bᵢ of g.

generalized_continued_fraction.terminated_at

A gcf terminated at position n if its sequence terminates at position n.

generalized_continued_fraction.terminated_at_decidable

It is decidable whether a gcf terminated at a given position.

generalized_continued_fraction.terminates

A gcf terminates if its sequence terminates.

generalized_continued_fraction.seq.coe_to_seq

Coerce a sequence by elementwise coercion.

generalized_continued_fraction.has_coe_to_generalized_continued_fraction

Coerce a gcf by elementwise coercion.

generalized_continued_fraction.is_simple_continued_fraction

A generalized continued fraction is a simple continued fraction if all partial numerators are equal to one.

                            1
            h + --------------------------
                              1
                  b₀ + --------------------
                                1
                        b₁ + --------------
                                    1
                              b₂ + --------
                                  b₃ + ...

simple_continued_fraction

A simple continued fraction (scf) is a generalized continued fraction (gcf) whose partial numerators are equal to one.

                            1
            h + --------------------------
                              1
                  b₀ + --------------------
                                1
                        b₁ + --------------
                                    1
                              b₂ + --------
                                  b₃ + ...

For convenience, one often writes [h; b₀, b₁, b₂,...]. It is encoded as the subtype of gcfs that satisfy generalized_continued_fraction.is_simple_continued_fraction.

simple_continued_fraction.has_coe_to_generalized_continued_fraction

Lift a scf to a gcf using the inclusion map.

simple_continued_fraction.is_regular_continued_fraction

A simple continued fraction is a (regular) continued fraction ((r)cf) if all partial denominators bᵢ are positive, i.e. 0 < bᵢ.

continued_fraction

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 simple_continued_fraction.is_regular_continued_fraction.

continued_fraction.has_coe_to_simple_continued_fraction

Lift a cf to a scf using the inclusion map.

continued_fraction.has_coe_to_generalized_continued_fraction

Lift a cf to a scf using the inclusion map.

generalized_continued_fraction.next_numerator

Returns the next numerator Aₙ = bₙ-* Aₙ₋₁ + aₙ-* Aₙ₋₂, where predA is Aₙ₋₁, ppredA is Aₙ₋₂, a is aₙ₋₁, and b is bₙ₋₁.

generalized_continued_fraction.next_denominator

Returns the next denominator Bₙ = bₙ-* Bₙ₋₁ + aₙ-* Bₙ₋₂``, where predBisBₙ₋₁andppredBisBₙ₋₂, aisaₙ₋₁, and bisbₙ₋₁`.

generalized_continued_fraction.next_continuants

Returns the next continuants ⟨Aₙ, Bₙ⟩ using next_numerator and next_denominator, where pred is ⟨Aₙ₋₁, Bₙ₋₁⟩, ppred is ⟨Aₙ₋₂, Bₙ₋₂⟩, a is aₙ₋₁, and b is bₙ₋₁.

generalized_continued_fraction.continuants_aux

Returns the continuants ⟨Aₙ₋₁, Bₙ₋₁⟩ of g.

generalized_continued_fraction.continuants

Returns the continuants ⟨Aₙ, Bₙ⟩ of g.

generalized_continued_fraction.numerators

Returns the numerators Aₙ of g.

generalized_continued_fraction.denominators

Returns the denominators Bₙ of g.

generalized_continued_fraction.convergents

Returns the convergents Aₙ / Bₙ of g, where Aₙ, Bₙ are the nth continuants of g.

generalized_continued_fraction.convergents'_aux

Returns the approximation of the fraction described by the given sequence up to a given position n. For example, convergents'_aux [(1, 2), (3, 4), (5, 6)] 2 = 1 / (2 + 3 / 4) and convergents'_aux [(1, 2), (3, 4), (5, 6)] 0 = 0.

generalized_continued_fraction.convergents'

Returns the convergents of g by evaluating the fraction described by g up to a given position n. For example, convergents' [9; (1, 2), (3, 4), (5, 6)] 2 = 9 + 1 / (2 + 3 / 4) and convergents' [9; (1, 2), (3, 4), (5, 6)] 0 = 9

generalized_continued_fraction.ext_iff

Two gcfs g and g' are equal if and only if their components are equal.