CONTINUED_FRACTION Operator
Date: 2020-10-07 18:10:00

Up | Next | Prev | PrevTail | Tail

### 7.7 CONTINUED_FRACTION Operator

The operator CONTINUED_FRACTION generates the continued fraction expansion of a rational number argument. For irrational or rounded arguments, it approximates the real number as a rational number to the current system precision and generates the continued fraction expansion. Currently the operator CF is a complete synonym for CONTINUED_FRACTION although this may change in future updates of the package RATAPRX.

The operator CONTINUED_FRACTION accepts one, two or three arguments: the number to be expanded; an optional maximum size permitted for the denominator of the convergent and an optional number of continuents to be generated:

continued_fraction(⟨num⟩)
continued_fraction(⟨num⟩,⟨size⟩)
continued_fraction(⟨num⟩,⟨size⟩,⟨numterms⟩)

The result is the special operator contfrac with three arguments: the original number to be expanded ⟨num⟩, secondly the rational number approximation (the ﬁnal convergent) and thirdly a list of continuents of the continued fraction (iė. a list of pairs of partial numerators and denominators)

Note that, although with the current algorithm all the partial numerators have the value 1, they are stored in the list of continuents. This is for compatibility with the output of other continued fractions functions cfrac and cf_euler. This facilitates pretty-printing and the implementation of various equivalence transformations all of which are documented in the continued fraction subsection of the RATAPRX manual (Section 16.51).

Precision: the second optional parameter ⟨size⟩ is an upper bound for the absolute value of the denominator of the convergent.
Number of terms: the third optional parameter ⟨numterms⟩ is the maximum number of terms (continuents) to be generated.
If both optional parameters omitted, the expansion performed is exact for rational number arguments and for irrational or rounded arguments it is up to the current system precision. If both optional parameters are given the expansion is halted when the desired precision is reached or when the speciﬁed maximum number of terms have been generated whichever is the sooner. If the size parameter is zero, its value is ignored. Thus to obtain a continued fraction expansion to, for example, 10 terms one would specify the ⟨size⟩ parameter to be 0 and the ⟨numterms⟩ parameter to be 10.

Note that the operator contfrac is not normally seen as the output is pretty-printed, unless the number of continuents generated is larger than 12.

Examples:

continued_fraction(6/11);
6 1
{----,exact,---------------}
11 1
1 + ---------
1
1 + ---
5
continued_fraction(pi,1000);
355 1
{pi,-----,3 + ----------------}
113 1
7 + ----------
1
15 + ---
1
continued_fraction(pi,0,6);
104348 1
{pi,--------,3 + ------------------------------}
33215 1
7 + ------------------------
1
15 + -----------------
1
1 + -----------
1
292 + ---
1
continued_fraction(pi,1000,3);
333 1
{pi,-----,3 + ----------}
106 1
7 + ----
15
continued_fraction(pi,1000,6);
355 1
{pi,-----,3 + ----------------}
113 1
7 + ----------
1
15 + ---
1
continued_fraction e;
{e,
13580623
----------,
4996032
{2, {1,1}, {1,2}, {1,1}, {1,1}, {1,4}, {1,1}, {1,1}, {1,6},
{1,1}, {1,1}, {1,8}, {1,1}, {1,1}, {1,10}, {1,1}, {1,1}, {1,12}}}

Up | Next | Prev | PrevTail | Front