Enhancements to Continued Fractions in Maple 16
A continued fraction is a mathematical expression of the form b0+a1b1+a2b2+a3b3+a4b4+⋯ approximating either a constant or a function. Continued fractions are well known to provide very good rational approximations, as demonstrated in the following examples.
Example 1: Approximating π by rational numbers
Example 2: Approximating tanx by a rational function
Periodic continued fractions
The following command computes the continued fraction approximation to π of order 10.
withnumtheory:
cfracπ
3+17+115+11+1292+11+11+11+12+11+13+...
In this case, all "numerators" ai are 1, and all "denominators" bi are positive. The successive convergents c1=3, c2=3+17, c3=3+17+115, c4=3+17+115+11, c5=3+17+115+11+1292, … of this continued fraction are finite continued fractions, namely rational numbers, giving better and better numerical approximations of π. They can be computed by specifying optional arguments:
cfracπ,10,'c':
c
3,227,333106,355113,10399333102,10434833215,20834166317,31268999532,833719265381,1146408364913,42729431360120,...
evalf20c
3.,3.1428571428571428571,3.1415094339622641509,3.1415929203539823009,3.1415926530119026041,3.1415926539214210447,3.1415926534674367055,3.1415926536189366234,3.1415926535810777712,3.1415926535914039785,3.1415926535893891715,...
abserror ≔ mapz→evalf20π−z, c1..10
abserror:=0.1415926535897932385,−0.0012644892673496186,0.0000832196275290876,−2.667641890624⁢10-7,5.778906344⁢10-10,−3.316278062⁢10-10,1.223565330⁢10-10,−2.91433849⁢10-11,8.7154673⁢10-12,−1.6107400⁢10-12
You can see that the well-known rational approximation π≈227 occurs as the second convergent c2, and it is accurate to 2 decimal digits after the decimal point.
The best approximations, however, are obtained from the centered continued fraction, which allows "denominators" to be negative as well:
cfracπ,10,'c',centered
3+17+116−1294−13−14−15−115+13−12+12+...
The ability to obtain the convergents for a centered continued fraction with an optional argument was added in Maple 16.
3,227,355113,10434833215,31268999532,1146408364913,54193511725033,8014385725510582,24585092278256779,411557987131002976,1068966896340262731,...
3.,3.1428571428571428571,3.1415929203539823009,3.1415926539214210447,3.1415926536189366234,3.1415926535914039785,3.1415926535898153832,3.1415926535897926594,3.1415926535897931603,3.1415926535897932578,3.1415926535897932354,...
abserror ≔ mapz→evalf20π−z, c1..10
abserror:=0.1415926535897932385,−0.0012644892673496186,−2.667641890624⁢10-7,−3.316278062⁢10-10,−2.91433849⁢10-11,−1.6107400⁢10-12,−2.21447⁢10-14,5.791⁢10-16,7.82⁢10-17,−1.93⁢10-17
In this example, a continued fraction approximation of order 10 to the tangent function around x=0 is computed:
cfractanx
x1−x23−x25−x27−x29−x211−x213−x215−x217−x219+...
In this example, all the "numerators" are powers of x (up to sign), and the "denominators" exhibit an obvious pattern. Again, the convergents c1=x1, c2=x1−x23, c3=x1−x23−x25, c4=x1−x23−x25−x27, … form approximations of tanx of higher and higher orders. In this case, we obtain the convergents by calling cfrac twice, since applying cfrac to a continued fraction returns the rational function (or rational number) it represents:
cfractanx,1
x1+...
c1≔cfrac
c1:=x
cfractanx,2
x1−x23+...
c2≔cfrac
c2:=−3⁢x−3+x2
c3≔cfraccfractanx,3
c3:=13⁢x⁢−15+x2−5+2⁢x2
c4≔cfraccfractanx,4
c4:=−5⁢x⁢−21+2⁢x2105−45⁢x2+x4
c5≔cfraccfractanx,5
c5:=115⁢x⁢945−105⁢x2+x463−28⁢x2+x4
for i from 1 to 5 do seriesOtanx−ci,x,20 end;
Ox3
Ox5
Ox7
Ox9
Ox11
In fact, the convergents provide better approximations to then tangent function around x=0 than the Taylor expansion of the same order. Below, this is illustrated for c5 and the Taylor expansion s to tanx with the same error term, Ox11, by plotting the two differences tanx−s and tanx−c5:
seriestanx,x,11
x+13⁢x3+215⁢x5+17315⁢x7+622835⁢x9+Ox11
s≔convert,polynom
s:=x+13⁢x3+215⁢x5+17315⁢x7+622835⁢x9
plottanx−s,tanx−c5,x=−1..1, legend=Taylor,continued fraction,thickness=2,color=red,blue
For example, the absolute errors for the two approximations at x=1 are:
evalftanx−sx=a|f(x)x=1
0.014903316
evalftanx−c5x=a|f(x)x=1
3.18⁢10-7
The ability to compute a continued fraction at an expansion point other than 0 was added in Maple 16:
cfractanx,x=π
x−π1−x−π23−x−π25−x−π27−x−π29+...
Any rational number has a finite, and therefore periodic, continued fraction. It is a classical fact that more generally a real number has a periodic continued fraction expansion if and only if it is either rational or a real algebraic number of degree 2, i.e., a number of the form a+bd, where a and b are rational numbers and d is a positive integer. For example, the periodic continued fraction expansion for 7 is:
cfrac7,periodic
2+11+11+11+14+11+11+11+14+...
Maple's data structure for periodic continued fractions has two components: a list of integers representing the preperiod, and another list of positive integers denoting the repeating period. This representation can be requested using an optional argument:
cfrac7,periodic,quotients
2,1,1,1,4
As of Maple 16, applying the cfrac command to such a list will return the real number represented by that continued fraction. For example, the following command finds the quadratic irrational number whose continued fraction expansion is an infinite repetition of the period 1+12+13+14+15:
cfrac,1,2,3,4,5
1314⁢65029+195314
cfrac,periodic
1+12+13+14+15+11+12+13+14+15+...
cfrac,20
1+12+13+14+15+11+12+13+14+15+11+12+13+14+15+11+12+13+14+15+11+...
Download Help Document