\chapter[RATAPRX: Rational Approximations]%
{RATAPRX : Rational Approximations Package}
\label{RATAPRX}
\typeout{{RATAPRX : Rational Approximations Package}}
{\footnotesize
\begin{center}
Lisa Temme\\
Wolfram Koepf\\
Konrad-Zuse-Zentrum f\"ur Informationstechnik Berlin\\
Takustra\"se 7 \\
D-14195 Berlin-Dahlem, Germany \\
e-mail: koepf@zib.de
\end{center}
}
\ttindex{RATAPRX}
This package provides functions to
\begin{itemize}
\item convert rational numbers in their periodic representation and vice versa,
\item to compute continued fractions and
\item to compute the Pad\'{e} approximant of a function.
\end{itemize}
The package can be loaded using {\tt load\_package rataprx;} it supersedes
the {\tt contfr} package.
\section{}
\subsection{Periodic Representation}
The function \f{rational2periodic(n)\ttindex{RATIONAL2PERIODIC}}
converts a rational number {\tt n} in its periodic representation.
For example $59/70$ is converted to $0.8\overline{428571}$. \\
Depending on the print function of your \REDUCE\ system, calling the
function \f{rational2periodic} might result in an expression of
the form {\tt periodic(\{a,b\},\{c$_1$,...,c$_n$\})\ttindex{PERIODIC}}.
{\tt a} and {\tt b} is the non-periodic part of the rational number
{\tt n} and {\tt c$_1$,...,c$_n$} are the digits of the periodic part.
In this case $59/70$ would result in {\tt periodic(\{8,10\},\{4,2,8,5,7,1\})}. \\
The function \f{periodic2rational(periodic(\{a,b\},\{c$_1$,...,c$_n$\}))
\ttindex{PERIODIC2RATIONAL}} is the
inverse function and computes the rational expression for a periodic one.
Note that {\tt b} is 1,-1 or a integer multiple of 10. If {\tt a} is zero,
then the input number {\tt b} indicates how many places after the decimal
point the period occurs.
\begin{verbatim}
rational2periodic(6/17);
periodic({0,1},{3,5,2,9,4,1,1,7,6,4,7,0,5,8,8,2})
periodic2rational(ws);
6
----
17
\end{verbatim}
\subsection{Continued Fractions}
A continued fraction (see \cite{Baker:81a} \S 4.2) has the general form
\[b_0 + \frac{a_1}{b_1 +
\frac{a_2}{b_2+
\frac{a_3}{b_3 + \ldots
}}}
\;.\]
A more compact way of writing this is as
\[b_0 + \frac{a_1|}{|b_1} + \frac{a_2|}{|b_2} + \frac{a_3|}{|b_3} + \ldots\,.\]
\\
This is represented in \REDUCE\ as
\[{\tt
contfrac({\mbox{\sl Rational\hspace{2mm} approximant}},
\{b_0, \{a_1,b_1\}, \{a_2,b_2\},.....\}).\ttindex{CONTFRAC}
}\]
There are four different functions to determine the continued fractions
for real numbers and functions {\tt f} in the variable {\tt var}:
\begin{center}
{\tt
\begin{tabular}{l l}
cfrac(number); & cfrac(number,length); \\
cfrac(f, var); & cfrac(f, var, length);
\end{tabular}} \\[1mm]
\end{center}
\ttindex{CFRAC}
The {\tt length} argument is optional and specifies the number of
ordered pairs $\{a_i,b_i\}$ to be returned. It's default value is five.
\begin{verbatim}
cfrac pi;
1146408
contfrac(---------),
364913
{3,{1,7},{1,15},{1,1},{1,292},{1,1},{1,1},{1,1},
{1,2},{1,1}})
\end{verbatim}
\newpage
\begin{verbatim}
cfrac((x+2/3)^2/(6*x-5),x);
2
9*x + 12*x + 4 6*x + 13 24*x - 20
contfrac(-----------------,{----------,{1,-----------}})
54*x - 45 36 9
cfrac(e^x,x);
3 2
x + 9*x + 36*x + 60
contfrac(-----------------------,
2
3*x - 24*x + 60
{1,{x,1},{ - x,2},{x,3},{ - x,2},{x,5}})
\end{verbatim}
\subsection{Pad\'{e} Approximation}
The Pad\'{e} 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 \cite{Baker:81a}). Given a power series
\[ f(x) = c_0 + c_1 (x-h) + c_2 (x-h)^2 \ldots \]
and the degree of numerator, $n$, and of the denominator, $d$,
the {\tt pade} function finds the unique coefficients
$a_i,\, b_i$ in the Pad\'{e} approximant
\[ \frac{a_0+a_1 x+ \cdots + a_n x^n}{b_0+b_1 x+ \cdots + b_d x^d} \; .\]
The function \f{pade(f, x, h ,n ,d)\ttindex{PAD\'{E}}} takes as input the
function {\tt f} in the variable {\tt x} to be approximated , where
{\tt h} is the point at which the approximation is evaluated. {\tt n}
and {\tt d} are the (specified) degrees of the numerator and the denominator.
It returns the Pad\'{e} Approximant, ie. a rational function. \par
Error Messages may occur in the following different cases:
\begin{itemize}
\item The Taylor series expansion for the function {\tt f} has not yet been
implemented in the \REDUCE\ Taylor Package.
\item A Pad\'{e} Approximant of this function does not exist.
\item A Pad\'{e} Approximant of this order (ie. the specified numerator and
denominator orders) does not exist. Please note, there might exist an
approximant of a different order.
\end{itemize}
\newpage
\begin{verbatim}
pade(sin(x),x,0,3,3);
2
x*( - 7*x + 60)
------------------
2
3*(x + 20)
pade(tanh(x),x,0,5,5);
4 2
x*(x + 105*x + 945)
-----------------------
4 2
15*(x + 28*x + 63)
pade(exp(1/x),x,0,5,5);
***** no Pade Approximation exists
pade(factorial(x),x,1,3,3);
***** not yet implemented
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
\end{verbatim}