pyoculus.utils.continued_fraction
This module provides functions related to the continued fraction expansion. Reference in Ivan Niven, Irrational Numbers (Cambridge University Press, 2005).
- authors:
Zhisong Qu (zhisong.qu@anu.edu.au)
Ludovic Rais (ludovic.rais@epfl.ch)
Functions
|
Expands a positive real number in its continued fraction. |
|
Obtains the fraction \(n/m\) from the coefficients \([a_0, a_1, ..., a_m]\) of the continued fraction. |
- pyoculus.utils.continued_fraction.expandcf(realnumber, n=100, thres=1e-12)
Expands a positive real number in its continued fraction.
- Parameters:
realnumber (float) – The positive real number to expand. An absolute value will be taken if negative.
n (int, optional) – The maximum number of terms in the expansion. Default to 100.
thres (float, optional) – The threshold to stop the expansion. Default to 1e-6.
- Returns:
A NumPy array containing the continued fraction expansion of the real number up to the nth term or until the threshold is met.
- Return type:
np.ndarray
- pyoculus.utils.continued_fraction.fromcf(ai)
Obtains the fraction \(n/m\) from the coefficients \([a_0, a_1, ..., a_m]\) of the continued fraction.
- Parameters:
ai (list of int) – An integer list containing ai for the continued fraction expansion.
- Returns:
A tuple \((n, m)\), representing the fraction.
- Return type:
tuple