Skip to content

Commit

Permalink
docs: various typesetting and content fixes in the Sphinx docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sr-murthy committed Jun 15, 2024
1 parent 4e0d5ad commit 26ba883
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
20 changes: 12 additions & 8 deletions docs/sources/exploring-continued-fractions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ The elements and orders of :py:class:`~continuedfractions.continuedfraction.Cont
Convergents and Rational Approximations
=======================================

For an integer :math:`k >= 0` the (simple) :math:`k`-th **convergent** :math:`C_k` of a simple continued fraction :math:`[a_0; a_1,\ldots]` of a real number :math:`x` is the rational number :math:`\frac{p_k}{q_k}` with the simple continued fraction :math:`[a_0; a_1,\ldots,a_k]` formed from the first :math:`k + 1` elements of the original.
For an integer :math:`k \geq 0` the (simple) :math:`k`-th **convergent** :math:`C_k` of a simple continued fraction :math:`[a_0; a_1,\ldots]` of a real number :math:`x` is the rational number :math:`\frac{p_k}{q_k}` with the simple continued fraction :math:`[a_0; a_1,\ldots,a_k]` formed from the first :math:`k + 1` elements of the original.

.. math::
Expand Down Expand Up @@ -197,7 +197,9 @@ is called a **semiconvergent** of :math:`\frac{p_{k - 1}}{q_{k - 1}}` and :math:

Some definitions of semiconvergents are more restricted: one such definition is the same as above, except that :math:`m` is required to be an integer in the range :math:`0..a_{k + 1}`, i.e. :math:`0 \leq m \leq a_{k + 1}`, where the corner cases are :math:`m = 0` in which case the semiconvergent is equal to :math:`\frac{p_{k - 1}}{q_{k - 1}}`, and :math:`m = a_{n + 1}` (if this is defined) in which the case the semiconvergent is equal to :math:`\frac{p_{k + 1}}{q_{k + 1}}`. Another restrictive definition is also the same as the first definition above except that :math:`m` is required to be an integer in the range :math:`1..a_{k + 1} - 1`, i.e. :math:`0 < m < a_{k + 1}`. In this latter definition, the two corner cases listed above are excluded.

The first, more general definition is used here, and has been implemented in the :py:class:`~continuedfractions.continuedfraction.ContinuedFraction` class as the :py:meth:`~continuedfractions.continuedfraction.ContinuedFraction.semiconvergent` method. A few examples are given below for the continued fraction :math:`[-5; 1, 1, 6, 7]` for :math:`-\frac{415}{93}`.
The first, more general definition is used here, and has been implemented in the :py:class:`~continuedfractions.continuedfraction.ContinuedFraction` class as the (cached) :py:meth:`~continuedfractions.continuedfraction.ContinuedFraction.semiconvergent` method. This takes two arguments: a positive integer :math:`k` determining two consecutive convergents :math:`\frac{p_{k - 1}}{q_{k - 1}}, \frac{p_k}{q_k}` for which to take a semiconvergent, and a positive integer :math:`m` for the index of the semiconvergent (see the definition of "right-mediant" :ref:`here <sequences.mediants.generalised>`).

A few examples are given below for the continued fraction :math:`[-5; 1, 1, 6, 7]` for :math:`-\frac{415}{93}`.

.. code:: python
Expand All @@ -221,7 +223,7 @@ The first, more general definition is used here, and has been implemented in the
>>> cf.semiconvergent(3, 7)
ContinuedFraction(-415, 93)
The :math:`m`-th semiconvergent :math:`\frac{p_{k - 1} + mp_k}{q_{k - 1} + mq_k}` of the convergents :math:`\frac{p_{k - 1}}{q_{k - 1}}` and :math:`\frac{p_k}{q_k}` is the semiconvergent of the :math:`(m - 1)`-st semiconvergent :math:`\frac{p_{k - 1} + (m - 1)p_k}{q_{k - 1} + (m - 1)q_k}` and the convergent :math:`\frac{p_k}{q_k}`. The semiconvergent sequence :math:`\left( \frac{p_{k - 1} + mp_k}{q_{k - 1} + mq_k} \right)` is monotonic in :math:`m`, upper-bounded by :math:`\frac{p_k}{q_k}`, and thus has the limit :math:`\frac{p_k}{q_k}` as :math:`m \to \infty`. This can be seen in the example above.
The :math:`m`-th semiconvergent :math:`\frac{p_{k - 1} + mp_k}{q_{k - 1} + mq_k}` of the convergents :math:`\frac{p_{k - 1}}{q_{k - 1}}` and :math:`\frac{p_k}{q_k}` is the semiconvergent of the :math:`(m - 1)`-st semiconvergent :math:`\frac{p_{k - 1} + (m - 1)p_k}{q_{k - 1} + (m - 1)q_k}` and the convergent :math:`\frac{p_k}{q_k}`. The semiconvergent sequence :math:`\left( \frac{p_{k - 1} + mp_k}{q_{k - 1} + mq_k} \right)` is monotonic in :math:`m`, bounded on one side by :math:`\frac{p_k}{q_k}` (the side depends on whether :math:`k` is odd or even), and has the limit :math:`\frac{p_k}{q_k}` as :math:`m \to \infty`. This can be seen in the example above.

The semiconvergents have the same alternating behaviour in :math:`k` as the convergents: the difference between the :math:`m`-th semiconvergent :math:`\frac{p_{k - 1} + mp_k}{q_{k - 1} + mq_k}` and the :math:`(m - 1)`-st semiconvergent :math:`\frac{p_{k - 1} + (m - 1)p_k}{q_{k - 1} + (m - 1)q_k}` is given by:

Expand All @@ -242,12 +244,14 @@ This can be illustrated again using the continued fraction for :math:`-\frac{415
(-5, 1, 1, 6, 7)
>>> cf.convergents
mappingproxy({0: ContinuedFraction(-5, 1), 1: ContinuedFraction(-4, 1), 2: ContinuedFraction(-9, 2), 3: ContinuedFraction(-58, 13), 4: ContinuedFraction(-415, 93)})
>>> cf.semiconvergent(2, 1) - cf.semiconvergent(1, 1)
>>> cf.semiconvergent(1, 2) - cf.semiconvergent(1, 1)
ContinuedFraction(1, 6)
>>> cf.semiconvergent(3, 1) - cf.semiconvergent(2, 1)
ContinuedFraction(-2, 15)
>>> cf.semiconvergent(4, 1) - cf.semiconvergent(3, 1)
ContinuedFraction(7, 1590)
>>> cf.semiconvergent(2, 2) - cf.semiconvergent(2, 1)
ContinuedFraction(-1, 15)
>>> cf.semiconvergent(3, 2) - cf.semiconvergent(3, 1)
ContinuedFraction(1, 420)
>>> cf.semiconvergent(4, 2) - cf.semiconvergent(4, 1)
ContinuedFraction(-1, 21094)
.. note::

Expand Down
8 changes: 6 additions & 2 deletions docs/sources/sequences.rst
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ The Farey sequence :math:`F_n` of order :math:`n` is an (ordered) sequence of (i
.. math::
\begin{align}
F_n = \left(\frac{b}{a}\right) \text{ s.t. } & (a, b) = 1 \text{ and } 1 \leq b < a \leq n,\\
F_n = \left(\frac{b}{a}\right) \text{ s.t. } & 1 \leq b < a \leq n,\\
& \text{ or } b = 0, a = 1, \\
& \text{ or } b = a = 1
\end{align}
Expand All @@ -562,6 +562,8 @@ The special case is when :math:`n = 1` and :math:`F_1` is given by:
F_1 = \left(\frac{0}{1}, \frac{1}{1}\right)
For :math:`n \geq 2` the requirement that :math:`1 \leq b < a \leq n` means the fractions :math:`\frac{b}{a} \neq \frac{0}{1}, \frac{1}{1}` must be irreducible, which implies coprimality :math:`(a, b) = 1`.

The elements of :math:`F_n` are written in ascending order of magnitude. The first five Farey sequences are listed below:

.. math::
Expand Down Expand Up @@ -589,7 +591,7 @@ and this can be checked with the :py:func:`~continuedfractions.sequences.farey_s
>>> farey_sequence(5)
(ContinuedFraction(0, 1), ContinuedFraction(1, 5), ContinuedFraction(1, 4), ContinuedFraction(1, 3), ContinuedFraction(2, 5), ContinuedFraction(1, 2), ContinuedFraction(3, 5), ContinuedFraction(2, 3), ContinuedFraction(3, 4), ContinuedFraction(4, 5), ContinuedFraction(1, 1))
For :math:`n > 1` we can write the fractions in :math:`F_n` as :math:`\frac{b}{a}` where :math:`a > b`: then the restriction :math:`(a, b) = 1` (meaning :math:`a` and :math:`b` must be coprime), combined with :math:`a \leq n`, means that :math:`F_n` contains, for each :math:`a \leq n`, exactly :math:`\phi(a)` fractions of the form :math:`\frac{b}{a}` where :math:`a > b` and :math:`(a, b) = 1`, and :math:`\phi(k)` is the totient function.
For :math:`n > 1` we can write the fractions in :math:`F_n` as :math:`\frac{b}{a}` where :math:`a > b`: the coprimality condition :math:`(a, b) = 1`, combined with :math:`a \leq n`, means that :math:`F_n` contains, for each :math:`a \leq n`, exactly :math:`\phi(a)` fractions of the form :math:`\frac{b}{a}` where :math:`a > b` and :math:`(a, b) = 1`, and :math:`\phi(k)` is the totient function.

As :math:`F_n` also contains the special fraction :math:`\frac{0}{1}` as its initial element, it means that the length :math:`|F_n|` of :math:`F_n` is given by:

Expand Down Expand Up @@ -632,6 +634,8 @@ This can be checked using :py:func:`~continuedfractions.sequences.farey_sequence
>>> print(', '.join([str(frac) for frac in farey_sequence(4)]))
0, 1/4, 1/3, 1/2, 2/3, 3/4, 1
>>> print(', '.join([str(frac) for frac in farey_sequence(7)]))
0, 1/7, 1/6, 1/5, 1/4, 2/7, 1/3, 2/5, 3/7, 1/2, 4/7, 3/5, 2/3, 5/7, 3/4, 4/5, 5/6, 6/7, 1
>>> assert ContinuedFraction(2, 3).mediant(ContinuedFraction(3, 4)) in farey_sequence(7)
>>> assert ContinuedFraction(3, 4) - ContinuedFraction(2, 3) in farey_sequence(12)
Expand Down

0 comments on commit 26ba883

Please sign in to comment.