REDUCE

16.51 RATAPRX: Rational Approximations Package for REDUCE

Authors: Lisa Temme and Wolfram Koepf

16.51.1 Periodic Decimal Representation

The division of one integer by another often results in a period in the decimal part. The rational2periodic function in this package can recognise and represent such an answer in a periodic representation. The inverse function, periodic2rational, can also convert a periodic representation back to a rational number.

Periodic Representation of a Rational Number

SYNTAX: rational2periodic(n);

INPUT: n is a rational number

RESULT: periodic({a,b} , {c1,...,cn})

where a/b is the non-periodic part

and c1,...,cn are the digits of the periodic part.

EXAMPLE: 5970 written as 0.8428571

1: rational2periodic(59/70);

periodic({8,10},{4,2,8,5,7,1})

Rational Number of a Periodic Representation

SYNTAX: periodic2rational(periodic({a,b},{c1,...,cn}))

periodic2rational({a,b},{c1,...,cn})

INPUT:     a is an integer

    b is 1, -1 or an integer multiple of 10

c1,...,cn is a list of positive digits

RESULT: A rational number.

EXAMPLE: 0.8428571 written as 5970

2: periodic2rational(periodic({8,10},{4,2,8,5,7,1}));

59

—-

70

3: periodic2rational({8,10},{4,2,8,5,7,1});

59

—-

70

Note that if a is zero, b will indicate how many places after the decimal point that the period occurs. Note also that if the answer is negative then this will be indicated by the sign of a (unless a is zero in which case it is indicated by the sign of b).

ERROR MESSAGE

***** operator to be used in off rounded mode

The periodicity of a function can only be recognised in the off rounded mode. This is also true for the inverse procedure.

EXAMPLES

4: rational2periodic(1/3);  
 
periodic({0,1},{3})  
 
5: periodic2rational(ws);  
 
 1  
---  
 3  
 
6: periodic2rational({0,1},{3});  
 
 1  
---  
 3  
 
7: rational2periodic(-1/6);  
 
periodic({-1,10},{6})  
 
8: periodic2rational(ws);  
 
  - 1  
------  
  6  
 
9: rational2periodic(6/17);  
 
periodic({0,1},{3,5,2,9,4,1,1,7,6,4,7,0,5,8,8,2})  
 
10: periodic2rational(ws);  
 
 6  
----  
 17  
 
11: rational2periodic(352673/3124);  
 
periodic({11289,100},{1,4,8,5,2,7,5,2,8,8,0,9,2,1,8,9,5,0,0,6,  
                      4,0,2,0,4,8,6,5,5,5,6,9,7,8,2,3,3,0,3,4,  
                      5,7,1,0,6,2,7,4,0,0,7,6,8,2,4,5,8,3,8,6,  
                      6,8,3,7,3,8,7,9,6,4})  
 
12: periodic2rational(ws);  
 
 352673  
--------  
  3124  

16.51.2 Continued Fractions

A continued fraction (see  [?] 4.2) has the general form

           a1
b0 +  --------a-----.
      b1 +  b2+-2a3--
               b3+...

A more compact way of writing this is as

    a |   a |   a |
b0 +-1- + -2-+  -3-+ ....
    |b1   |b2   |b3


This is represented in REDUCE as

contfrac(Rational approximant, {b0,{a1,b1},{a2,b2},.....})

SYNTAX:   cfrac(number);

cfrac(number,length);

cfrac(f, var);

cfrac(f, var, length);

INPUT: number is any real number

f is a function

var is the function variable

Optional Argument: length

The length argument is optional. For an NON-RATIONAL function input the length argument specifies the number of ordered pairs, {ai,bi}, to be returned. It’s default value is five. For a RATIONAL function input the length argument can only truncate the answer, it cannot return additional pairs even if the precision is increased. The default value is the complete continued fraction of the rational input. For a NUMBER input the default value is dependent on the precision of the session, and the length argument will only take effect if it has a smaller value than that of the number of ordered pairs which the default value would return.

EXAMPLES

13: cfrac(23.696);  
 
          2962  
contfrac(------,{23,{1,1},{1,2},{1,3},{1,2},{1,5}})  
          125  
 
 
14: cfrac(23.696,3);  
 
          237  
contfrac(-----,{23,{1,1},{1,2},{1,3}})  
          10  
 
15: cfrac pi;  
 
 
          1146408  
contfrac(---------,  
          364913  
 
         {3,{1,7},{1,15},{1,1},{1,292},{1,1},{1,1},{1,1},{1,2},{1,1}})  
 
16: cfrac(pi,3);  
 
          355  
contfrac(-----,{3,{1,7},{1,15},{1,1}})  
          113  
 
17: cfrac(pi*e*sqrt(2),4);  
 
          10978  
contfrac(-------,{12,{1,12},{1,1},{1,68},{1,1}})  
           909  
 
18: cfrac((x+2/3)^2/(6*x-5),x,1);  
 
             2  
          9*x  + 12*x + 4    6*x + 13      24*x - 20  
contfrac(-----------------,{----------,{1,-----------}})  
             54*x - 45          36             9  
 
19: cfrac((x+2/3)^2/(6*x-5),x,10);  
 
             2  
          9*x  + 12*x + 4    6*x + 13      24*x - 20  
contfrac(-----------------,{----------,{1,-----------}})  
             54*x - 45          36             9  
 
 
20: cfrac(e^x,x);  
 
 
 
           3      2  
          x  + 9*x  + 36*x + 60  
contfrac(-----------------------,{1,{x,1},{ - x,2},{x,3},{ - x,2},{x,5}})  
               2  
            3*x  - 24*x + 60  
 
21: cfrac(x^2/(x-1)*e^x,x);  
 
           6      4    2  
          x  + 3*x  + x  
contfrac(----------------,{0,  
             4    2  
          3*x  - x  - 1  
 
                 2            2       2       2       2  
            { - x ,1}, { - 2*x ,1}, {x ,1}, {x ,1}, {x ,1}})  
 
22: cfrac(x^2/(x-1)*e^x,x,2);  
 
             2  
             x              2           2  
contfrac(----------,{0,{ - x ,1},{ - 2*x ,1}})  
             2  
          2*x  - 1  

16.51.3 Pad Approximation

The Pad approximant represents a function by the ratio of two polynomials. The coefficients of the powers occuring in the polynomials are determined by the coefficients in the Taylor series expansion of the function (see  [?]). Given a power series

                                2
f(x) = c0 + c1(x - h) + c2(x - h ) ...

and the degree of numerator, n, and of the denominator, d, the pade function finds the unique coefficients ai,bi in the Pad approximant

a0 + a1x + ⋅⋅⋅ + anxn
--------------------d .
 b0 + b1x + ⋅⋅⋅ + bdx


SYNTAX:   pade(f, x, h, n, d);

INPUT: f is the funtion to be approximated

x is the function variable

h is the point at which the approximation is

evaluated

n is the (specified) degree of the numerator

d is the (specified) degree of the denominator

RESULT: Pad Approximant, ie. a rational function.

ERROR MESSAGES

***** not yet implemented

The Taylor series expansion for the function, f, has not yet been implemented in the REDUCE Taylor Package.

***** no Pade Approximation exists

A Pad Approximant of this function does not exist.

***** Pade Approximation of this order does not exist

A Pad Approximant of this order (ie. the specified numerator and denominator orders) does not exist but one of a different order may exist.

EXAMPLES

 
23: pade(sin(x),x,0,3,3);  
 
          2  
 x*( - 7*x  + 60)  
------------------  
       2  
   3*(x  + 20)  
 
24: pade(tanh(x),x,0,5,5);  
 
     4        2  
 x*(x  + 105*x  + 945)  
-----------------------  
      4       2  
 15*(x  + 28*x  + 63)  
 
25: pade(atan(x),x,0,5,5);  
 
        4        2  
 x*(64*x  + 735*x  + 945)  
--------------------------  
         4       2  
 15*(15*x  + 70*x  + 63)  
 
26: pade(exp(1/x),x,0,5,5);  
 
***** no Pade Approximation exists  
 
27: pade(factorial(x),x,1,3,3);  
 
***** not yet implemented  
 
28: pade(asech(x),x,0,3,3);  
 
            2                        2                 2  
- 3*log(x)*x  + 8*log(x) + 3*log(2)*x  - 8*log(2) + 2*x  
--------------------------------------------------------  
                          2  
                       3*x  - 8  
 
29: taylor(ws-asech(x),x,0,10);  
 
               11  
log(x)*(0 + O(x  ))  
 
     13    6     43    8    1611    10      11  
 + (-----*x  + ------*x  + -------*x   + O(x  ))  
     768        2048        81920  
 
30: pade(sin(x)/x^2,x,0,10,0);  
 
***** Pade Approximation of this order does not exist  
 
31:  pade(sin(x)/x^2,x,0,10,2);  
 
     10        8         6           4            2  
( - x   + 110*x  - 7920*x  + 332640*x  - 6652800*x  
 
  + 39916800)/(39916800*x)  
 
32: pade(exp(x),x,0,10,10);  
 
 
 
  10        9         8           7            6  
(x   + 110*x  + 5940*x  + 205920*x  + 5045040*x  
 
              5               4                3  
  + 90810720*x  + 1210809600*x  + 11762150400*x  
 
                 2  
  + 79394515200*x  + 335221286400*x + 670442572800)/  
 
      10        9         8           7            6  
    (x   - 110*x  + 5940*x  - 205920*x  + 5045040*x  
 
                     5               4  
         - 90810720*x  + 1210809600*x  
 
                        3               2  
         - 11762150400*x + 79394515200*x  
 
         - 335221286400*x + 670442572800)  
 
33: pade(sin(sqrt(x)),x,0,3,3);  
 
(sqrt(x)*  
            3            2  
  (56447*x  - 4851504*x  + 132113520*x - 885487680))\  
 
              3         2  
    (7*(179*x  - 7200*x  - 2209680*x - 126498240))

Bibliography

[1]   Baker(Jr.), George A. and Graves-Morris, Peter:
Pad Approximants, Part I: Basic Theory, (Encyclopedia of mathematics and its applications, Vol 13, Section: Mathematics of physics), Addison-Wesley Publishing Company, Reading, Massachusetts, 1981.