numlib::contfrac -- the domain
of continued fractions
Introductionnumlib::contfrac(a, n) creates a continued
fraction approximation for a, using the first
n digits of its floating-point evaluation.
Creating
Elementsnumlib::contfrac(a <,n>)
Parametersn |
- | positive integer |
a |
- | numerical expression |
Detailsn is not given, the value of the variable DIGITS is used.approx(dom cf, positive
integer n)n coefficients coincide with those of cf
equals [a,b).unapprox(numerical expression a, numerical expression b)_plus(dom a, dom
b)a and b into
rationals, adds them, and returns the sum converted back into a
continued fraction._plus of the system kernel._mult(dom a, dom
b)a and b into
rationals, multiplies them, and returns the product converted back into
a continued fraction._mult of the system kernel._invert(dom a)_invert of the system kernel._power(dom a, integer
n)a by itself n
times, or, if n is negative, the inverse of a
by itself -n times.
Example
1numlib::contfrac can also compute continued
fraction expansions of irrational numbers:
>> a:= numlib::contfrac(PI, 5): b:= numlib::contfrac(sqrt(7), 2): a, b
1 1
---------------------- + 3, ------------------- + 2
1 1
------------------ + 7 --------------- + 1
1 1
------------- + 15 ----------- + 1
1 1
--------- + 1 ------- + 1
1 1
--- + 292 --- + 4
... ...
All basic arithmetical operations are available:
>> a + b, a*b, a^3
1 1 1
--------------- + 5, ------- + 8, ------------- + 31
1 1 1
----------- + 1 --- + 3 ------- + 159
1 ... 1
------- + 3 --- + 3
1 ...
--- + 1
...
contfrac