Skip to content

Commit

Permalink
docs: further refinements in the docs for convergents
Browse files Browse the repository at this point in the history
  • Loading branch information
sr-murthy committed Jul 12, 2024
1 parent 7548f57 commit 37b3914
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions docs/sources/exploring-continued-fractions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ If we use the 100th convergent (with :math:`101` elements consisting of the inte
>>> sqrt2_100.as_decimal()
Decimal('1.414213562373095048801688724')
The decimal value of ``ContinuedFraction.from_elements(1, *[2] * 100)`` in this construction is now accurate up to 27 digits in the fractional part, but the decimal representation stops there. Why 27? Because the :py:mod:`decimal` library uses a default `contextual precision <https://docs.python.org/3/library/decimal.html#decimal.DefaultContext>`_ of 28 digits, including the integer part. The :py:mod:`decimal` precision can be increased, and the accuracy of the "longer" approximation above can be compared, as follows:
The decimal value of ``ContinuedFraction.from_elements(1, *[2] * 100)`` in this construction is now accurate up to 27 digits in the fractional part, but the decimal representation stops there. This is because the :py:mod:`decimal` library uses a default `contextual precision <https://docs.python.org/3/library/decimal.html#decimal.DefaultContext>`_ of 28 digits, including the integer part. The :py:mod:`decimal` precision can be increased, and the accuracy of the "longer" approximation above can be compared, as follows:

.. code:: python
Expand Down Expand Up @@ -265,7 +265,7 @@ The :py:class:`~continuedfractions.continuedfraction.ContinuedFraction` class pr
>>> dict(ContinuedFraction(649, 200).odd_convergents)
{1: ContinuedFraction(13, 4), 3: ContinuedFraction(649, 200)}
As with :py:attr:`~continuedfractions.continuedfraction.ContinuedFraction.convergents` the results are generators of enumerated sequences of :py:class:`~continuedfractions.continuedfraction.ContinuedFraction` instances, where the enumeration is by convergent index.
As with the :py:attr:`~continuedfractions.continuedfraction.ContinuedFraction.convergents` property the result is a generator of enumerated sequence of :py:class:`~continuedfractions.continuedfraction.ContinuedFraction` instances, where the enumeration is by convergent index.

The different behaviour of even- and odd-indexed convergents can be illustrated by a :py:class:`~continuedfractions.continuedfraction.ContinuedFraction` approximation of :math:`\sqrt{2}` with one hundred 2s in the tail, using dictionaries to store the even- and odd-indexed convergents:

Expand Down Expand Up @@ -425,8 +425,6 @@ It is also possible to get all of the remainders at once using the :py:attr:`~co
>>> dict(ContinuedFraction('3.245').remainders)
{3: ContinuedFraction(4, 1), 2: ContinuedFraction(49, 4), 1: ContinuedFraction(200, 49), 0: ContinuedFraction(649, 200)}
As with convergents the result is a generator of an enumerated sequence of :py:class:`~continuedfractions.continuedfraction.ContinuedFraction` instances.

Using the simple continued fraction of :math:`\frac{649}{200}` we can verify that these remainders are mathematically correct.

.. math::
Expand Down

0 comments on commit 37b3914

Please sign in to comment.