sqrt2periodicCfrac {contFracR}R Documentation

Function To Generate Periodic Continued Fraction For Square Roots

Description

This function produces the denominators of the continued fraction form of any square root.

Usage

sqrt2periodicCfrac(num, denom = 1,  nterms = 50, ...)

Arguments

num

An integer, bigz integer, or a character string form of an integer, representing the number or the numerator of the number for which the continued fraction form of the square root is to be generated.

denom

An integer ,bigz integer, or a character string form of an integer,representing the denominator of the number for which the continued fraction form of the square root is to be generated. The default value is 1. If denom is not 1, the values returned must be divided by the denominator. See the Details section.

nterms

The maximum number of terms (denominators) to calculate. This is a "safety" limit in case the denominator repeat pattern turns out to be extremely long. See the Details section.

...

Reserved for future use.

Details

As discussed in the references, this algorithm will produce a periodic sequence of denominator values for any rational input value. Important note: the algorithm actually calculates the square root of num * denom because it only works properly with integers. Thus, if num/denom is not an integer, you must divide the results by the value of the denominator to get the correct square root. If the returned value of repeated is "FALSE" then increase the input argument nterms. The default value (50) exists so that the function can terminate rather than spend (possibly undesired) time calculating extremely long denominator repeat sequences.

Value

A list, with: The continued fraction numerators and denominators in bigz form num , denom . The continued fraction numerators and denominators in numeric form numericnum, numericdenom . In the extreme case that a value exceeds the machine size of a numeric, NA is returned. repeated returns TRUE if the denominator repeat argument is found, and FALSE if not. input echoes back the input num and denom arguments. The numerators (A) and denominators (B) of the convergents are provided in convA and convB

Author(s)

Carl Witthoft, carl@witthoft.com

References

https://r-knott.surrey.ac.uk/Fibonacci/cfINTRO.html section6.2 https://math.stackexchange.com/questions/2215918

Proof of periodicity: https://web.math.princeton.edu/mathlab/jr02fall/Periodicity/mariusjp.pdf

Examples

sqrt2periodicCfrac(12)
sqrt2periodicCfrac('12')
sqrt2periodicCfrac(12,7)


[Package contFracR version 1.2.1 Index]