Up | Next | Prev | PrevTail | Tail |
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( \(\langle \)num\(\rangle \)) |
continued_fraction( \(\langle \)num\(\rangle \), \(\langle \)size\(\rangle \)) |
continued_fraction( \(\langle \)num\(\rangle \), \(\langle \)size\(\rangle \), \(\langle \)numterms\(\rangle \)) |
The result is the special operator contfrac
with three arguments: the original number
to be expanded \(\langle \)num\(\rangle \), secondly the rational number approximation (the final convergent)
and thirdly a list of continuents of the continued fraction (i.e. a list of pairs of partial
numerators and denominators)
{t0, {1, t1}, {1, t2}, .... }
which represents the same value according to the definition
t0 + 1/(t1 + 1/(t2 + ...))
.
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
20.48.2).
Precision: the second optional parameter \(\langle \)size\(\rangle \) is an upper bound for the absolute value of
the denominator of the convergent.
Number of terms: the third optional parameter \(\langle \)numterms\(\rangle \) 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 specified 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 \(\langle \)size\(\rangle \) parameter to be 0 and the \(\langle \)numterms\(\rangle \) 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 |