Continued fractions vs Power series

The Taylor series of the exponential function,
{\displaystyle e^x = \sum_{n=0}^\infty \frac{x^n}{n!} = 1 + x + \frac{x^2}{2} + \frac{x^3}{6} + \frac{x^4}{24} + \frac{x^5}{120} + \cdots }
provides reasonable approximations to the function near zero: for example, with {\displaystyle T_3(x) = 1 + x + \frac{x^2}{2} + \frac{x^3}{6} } we get

T3
Taylor polynomial T_3 in red

The quality of approximation not being spectacular, one can try to improve it by using rational functions instead of polynomials. In view of the identity
{\displaystyle e^x = \frac{e^{x/2}}{e^{-x/2}} \approx \frac{T_3(x/2)}{T_3(-x/2)}}
one can get {e^x\approx p(x)/p(-x)} with {\displaystyle p(x) = 1 + \frac{x}{2} + \frac{x^2}{8} + \frac{x^3}{48} }. The improvement is substantial for negative {x}:

exp-half
Rational approximation based on exp(x/2)

Having rational approximation of the form {e^x\approx p(x)/p(-x)} makes perfect sense, because such approximants obey the same functional equation {f(x)f(-x)=1} as the exponential function itself. We cannot hope to satisfy other functional equations like {f(x+1)=e f(x)} by functions simpler than {\exp}.

However, the polynomial {T_n(x/2)} is not optimal for approximation {e^x \approx p(x)/p(-x)} except for {n=0, 1}. For degree {3}, the optimal choice is {\displaystyle p(x) = 1 + \frac{x}{2} + \frac{x^2}{10} + \frac{x^3}{120} }. In the same plot window as above, the graph of {p(x)/p(-x)} is indistinguishable from {e^x}.

pade
Red=rational, Blue=exponential

This is a Padé approximant to the exponential function. One way to obtain such approximants is to replace the Taylor series with continued fraction, using long division:

{\displaystyle e^x = 1 + \dfrac{x}{1 + \dfrac{-x/2}{1 + \dfrac{x/6}{1 + \dfrac{-x/6}{1 + \dfrac{x/10}{1 + \dfrac{-x/10}{1 + \cdots }}}}}} }

Terminating the expansion after an even number of {x} apprearances gives a Padé approximant of the above form.

This can be compared to replacing the decimal expansion of number {e}:

{\displaystyle e = 2 + \frac{7}{10} + \frac{1}{10^2} + \frac{8}{10^3} + \frac{2}{10^4}+\cdots }

with the continued fraction expansion

{\displaystyle e = 2 + \dfrac{1}{1 + \dfrac{1}{2 + \dfrac{1}{1 + \dfrac{1}{1 + \dfrac{1}{4 + \dfrac{1}{1 + \cdots }}}}}} }

which, besides greater accuracy, has a regular pattern: 121 141 161 181 …

The numerators {p} of the (diagonal) Padé approximants to the exponential function happen to have a closed form:

{\displaystyle p(x) = \sum_{k=0}^n \frac{\binom{n}{k}}{\binom{2n}{k}} \frac{x^k}{k!} }

which shows that for every fixed {k}, the coefficient of {x^k} converges to {2^{-k}/k!} as {n\to\infty }. The latter is precisely the Taylor coefficient of {e^{x/2}}.

In practice, a recurrence relation is probably the easiest way to get these numerators: begin with {p_0(x)=1} and {p_1(x) = 1+x/2}, and after that use {\displaystyle p_{n+1}(x) = p_n(x) + \frac{x^2}{16n^2 - 4} p_{n-1}(x)}. This relation can be derived from the recurrence relations for the convergents {A_n/B_n} of a generalized continued fraction {\displaystyle \mathop{\raisebox{-5pt}{\huge K}}_{n=1}^\infty \frac{a_n}{b_n}}. Namely, {A_n = b_nA_{n-1}+a_nA_{n-2}} and {B_n = b_nB_{n-1}+a_nB_{n-2}}. Only the first relation is actually needed here.

Using the recurrence relation, we get

{\displaystyle p_2(x) = p_1(x) + \frac{x^2}{12}p_0(x) = 1 + \frac{x}{2} + \frac{x^{2}}{12} }

{\displaystyle p_3(x) = p_2(x) + \frac{x^2}{60}p_1(x) = 1 + \frac{x}{2} + \frac{x^{2}}{10} + \frac{x^{3}}{120} }

{\displaystyle p_4(x) = p_3(x) + \frac{x^2}{140}p_2(x) = 1 + \frac{x}{2} + \frac{3 x^{2}}{28} + \frac{x^{3}}{84} + \frac{x^{4}}{1680} }

(so, not all coefficients have numerator 1…)

{\displaystyle p_5(x) = p_4(x) + \frac{x^2}{252}p_3(x) = 1 + \frac{x}{2} + \frac{x^{2}}{9} + \frac{x^{3}}{72} + \frac{x^{4}}{1008} + \frac{x^{5}}{30240} }

The quality of approximation to {e^x} is best seen on logarithmic scale: i.e., how close is {\log(p(x)/p(-x))} to {x}? Here is this comparison using {p_5}.

pade5
Rational approximation based on 5th degree polynomial

For comparison, the Taylor polynomial of fifth degree, also on logarithmic scale: {\log(T_5(x))} where {\displaystyle T_5(x) = 1 + x + \frac{x^2}{2} + \frac{x^3}{6} + \frac{x^4}{24} + \frac{x^5}{120}}.

T5
log(T_5) in red