REDUCE

7.7 CONTINUED_FRACTION Operator

The operator CONTINUED_FRACTION approximates the real number (rational number, rounded number) into a continued fraction. CONTINUED_FRACTION has one or two arguments, the number to be converted and an optional precision:

continued_fraction(num)

or

continued_fraction(num,size)

The result is a list of two elements: the first one is the rational value of the approximation, the second one is the list of terms of the continued fraction which represents the same value according to the definition t0 +1/(t1 + 1/(t2 + ...)). Precision: the second optional parameter size is an upper bound for the absolute value of the result denominator. If omitted, the approximation is performed up to the current system precision.

Examples:

continued_fraction pi;  
 
                  ->  
 
  1146408  
{---------,{3,7,15,1,292,1,1,1,2,1}}  
  364913  
 
continued_fraction(pi,100);  
 
                  ->  
 
  22  
{----,{3,7}}  
  7