periodicCF | R Documentation |
Generates a periodic continued fraction.
periodicCF(d)
d |
positive integer that is not a square number |
The function computes the periodic continued fraction of the square root of an integer that itself shall not be a square (because otherwise the integer square root will be returned). Note that the continued fraction of an irrational quadratic number is always a periodic continued fraction.
The first term is the biggest integer below sqrt(d)
and the rest is
the period of the continued fraction. The period is always exact, there is
no floating point inaccuracy involved (though integer overflow may happen
for very long fractions).
The underlying algorithm is sometimes called "The Fundamental Algorithm for Quadratic Numbers". The function will be utilized especially when solving Pell's equation.
Returns a list with components
cf |
the continued fraction with integer part and first period. |
plen |
the length of the period. |
Integer overflow may happen for very long continued fractions.
Hans Werner Borchers
Mak Trifkovic. Algebraic Theory of Quadratic Numbers. Springer Verlag, Universitext, New York 2013.
solvePellsEq
periodicCF(2) # sqrt(2) = [1; 2,2,2,...] = [1; (2)] periodicCF(1003) ## $cf ## [1] 31 1 2 31 2 1 62 ## $plen ## [1] 6
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.