Skip to content

Commit

Permalink
docs: minor docstring fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sr-murthy committed Jun 18, 2024
1 parent c036e25 commit 5806bac
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
4 changes: 2 additions & 2 deletions docs/sources/exploring-continued-fractions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ It is also possible to get all of the convergents at once using the :py:attr:`~c
>>> tuple(ContinuedFraction(649 200).convergents)
((0, ContinuedFraction(3, 1)), (1, ContinuedFraction(13, 4)), (2, ContinuedFraction(159, 49)), (3, ContinuedFraction(649, 200)))
The return of a generator of an enumerated sequence is helpful as it allows the caller to define an appropriate static data structure to store all the convergents, if required, e.g. via a dict keyed by convergent index :math:`0, 1,\ldots, n`.
The return of a generator of an enumerated sequence is helpful as it allows the caller to define an appropriate static data structure to store all the convergents by index, if required, e.g. via a dict:

.. code:: python
Expand All @@ -127,7 +127,7 @@ It is known that even- and odd-indexed convergents behave differently: the even-
\frac{p_k}{q_k} - \frac{p_{k - 1}}{q_{k - 1}} = \frac{(-1)^k}{q_kq_{k - 1}}, \hskip{3em} k \geq 1
The :py:class:`~continuedfractions.continuedfraction.ContinuedFraction` class provides (cached) properties for even-indexed convergents (:py:attr:`~continuedfractions.continuedfraction.ContinuedFraction.even_convergents`) and odd-indexed convergents (:py:attr:`~continuedfractions.continuedfraction.ContinuedFraction.odd_convergents`), as illustrated below.
The :py:class:`~continuedfractions.continuedfraction.ContinuedFraction` class provides properties for generating even-indexed convergents (:py:attr:`~continuedfractions.continuedfraction.ContinuedFraction.even_convergents`) and odd-indexed convergents (:py:attr:`~continuedfractions.continuedfraction.ContinuedFraction.odd_convergents`), as illustrated below.

.. code:: python
Expand Down
23 changes: 16 additions & 7 deletions src/continuedfractions/continuedfraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,10 @@ def convergents(self) -> Generator[tuple[int, ContinuedFraction], None, None]:
The convergents are generated as tuples of :py:class:`int` and
:py:class:`~continuedfraction.continuedfraction.ContinuedFraction`
instances, where the integers represent the orders of the convergents.
instances, where the integers represent the indices of the convergents.
If :math:`n` is the order of the continued fraction then :math:`n + 1`
convergents :math:`C_0, C_1, \\ldots, C_n` are generated in that order.
Yields
------
Expand All @@ -765,9 +768,12 @@ def convergents(self) -> Generator[tuple[int, ContinuedFraction], None, None]:
def even_convergents(self) -> Generator[tuple[int, ContinuedFraction], None, None]:
"""Generates an enumerated sequence of all even-order convergents of the continued fraction.
The even-order convergents are generated as tuples of :py:class:`int`
and :py:class:`~continuedfraction.continuedfraction.ContinuedFraction`
instances, where the integers represent the orders of the convergents.
The convergents are generated as tuples of :py:class:`int` and
:py:class:`~continuedfraction.continuedfraction.ContinuedFraction`
instances, where the integers represent the indices of the convergents.
If :math:`n` is the order of the continued fraction then only the even-
indexed convergents :math:`C_0, C_2, C_4, \\ldots` are generated.
Yields
------
Expand All @@ -787,9 +793,12 @@ def even_convergents(self) -> Generator[tuple[int, ContinuedFraction], None, Non
def odd_convergents(self) -> Generator[tuple[int, ContinuedFraction], None, None]:
"""Generates an enumerated sequence of all odd-order convergents of the continued fraction.
The odd-order convergents are generated as tuples of :py:class:`int`
and :py:class:`~continuedfraction.continuedfraction.ContinuedFraction`
instances, where the integers represent the orders of the convergents.
The convergents are generated as tuples of :py:class:`int` and
:py:class:`~continuedfraction.continuedfraction.ContinuedFraction`
instances, where the integers represent the indices of the convergents.
If :math:`n` is the order of the continued fraction then only the odd-
indexed convergents :math:`C_1, C_3, C_5, \\ldots` are generated.
Yields
------
Expand Down
6 changes: 3 additions & 3 deletions src/continuedfractions/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ def convergents(*elements: int) -> Generator[Fraction, None, None]:
"""Generates an (ordered) sequence of convergents of a (finite, simple) continued fraction given as a sequence of its elements.
If :math:`n` is the order of the continued fraction represented by the
given sequence of its elements then convergents of orders
:math:`0, 1, \\ldots, n` are generated in that order.
given sequence of its elements then :math:`n + 1` convergents
:math:`C_0, C_1, \\ldots, C_n` are generated in that order.
Parameters
----------
Expand All @@ -322,7 +322,7 @@ def convergents(*elements: int) -> Generator[Fraction, None, None]:
------
fractions.Fraction
Each element generated is a :py:class:`fractions.Fraction` instance and
a :math:`k`-order convergent of the given continued fraction.
a :math:`k`-th convergent of the given continued fraction.
Raises
------
Expand Down

0 comments on commit 5806bac

Please sign in to comment.