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.3 LTS), Mac OS (12.7.3) and Windows (Windows Server 2022), 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 two core libraries.
Each is summarised below. Or you can go straight to the API reference.
continuedfractions.lib
#
This is a library of standalone functions, the most important of which are summarised below.
continued_fraction_rational()
- generates the (ordered) sequence of elements (coefficients) of the unique simple continued fraction of a given rational number, given as afractions.Fraction
instancecontinued_fraction_real()
- generates the sequence of elements of a simple continued fraction of a real number, given as a singleint
,float
,str
, ordecimal.Decimal
value; the results forfloat
inputs may be approximate and not necessarily uniquefraction_from_elements()
- returns afractions.Fraction
instance of the rational number represented by a simple continued fraction with the given sequence of elementsconvergent()
- returns the \(k\)-th convergent (for a positive integer \(k\)) from a sequence of elements of a (finite) simple continued fraction; the convergent is returned as afractions.Fraction
instancemediant()
- returns the \(k\)-th left or right mediant of two rational numbers, given asfractions.Fraction
values; the mediant is returned as afractions.Fraction
instance
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 offractions.Fraction
, designed to represent (finite) simple continued fractions as Python objects, which are fully operable as rational numbers.