Getting Started#

This is a PyPI package which uses only Python standard libraries, and is supported on any Linux, Mac OS or Windows system supporting Python 3.10, 3.11, or 3.12. It is CI-tested on Ubuntu Linux (22.04.4 LTS), Mac OS (13.6.6) and Windows (Windows Server 2022 21H2), but should also install on any other platform supporting these Python versions.

Installation#

A standard pip install is sufficient:

pip install continuedfractions

Potential contributors may want look at the project TOML, and then the contributions overview.

Package Structure#

The continuedfractions package consists of three core libraries.

Note

The continuedfractions.utils library contains internal utilities.

Each is summarised below. Or you can go straight to the API reference.

continuedfractions.lib#

This is a library of standalone functions:

Note

There are also two “wrapper” functions for computing left- and right-mediants - left_mediant() and right_mediant() - but these just call mediant().

continuedfractions.continuedfraction#

This is a library containing a single main class:

  • ContinuedFraction - a subclass of fractions.Fraction, designed to represent (finite) simple continued fractions as Python objects, which are fully operable as rational numbers.

continuedfractions.sequences#

This is a library of functions and classes relating to ordered sequences and structures of integers and rational numbers, such as (currently) coprime integers, Farey sequences and (in the future) the Stern-Brocot tree:

  • coprime_integers() - returns a sequence of integers coprime (or relatively prime) to a given positive integer.

  • KSRMTree - implements an implicit/generative class for the Kanga-Saunders-Randall-Mitchell (KSRM) ternary trees for representing and generating pairs of (positive) coprime integers.

  • coprime_pairs() - returns a sequence of all pairs of (positive) coprime integers less than or equal to a given positive integer. Uses the KSRM tree search() method to perform the search.

  • farey_sequence() - returns a sequence of rational numbers called a Farey sequence for a given positive integer. Uses the coprime_integers() and coprime_pairs() functions.