Taylor or Padé? Two ways to spend the same seven numbers
Every engineering student learns the Taylor series. Very few meet its cousin, the Padé approximant, even though it hides inside tools they use every day. The stiff ODE solver, the matrix exponential in SciPy and the time-delay block in a control toolbox all use it.
So here is the question I want to answer in this post. Suppose I know the first seven Taylor coefficients of a function at \(x = 0\), and nothing else. What is the best way to use them?
The obvious answer is to add them up into a polynomial of degree six. The other answer is to rearrange the same seven numbers into a ratio of two polynomials of degree three. Both use exactly the same information. We will see that they behave very differently once we move away from \(x = 0\).
All the numbers and figures in this post come from one script, taylor-vs-pade.py. It also checks every number quoted here.
1 The Taylor polynomial
Let \(f(x) = c_0 + c_1 x + c_2 x^2 + \cdots\) near \(x = 0\). The Taylor polynomial of degree \(n\) keeps the first \(n + 1\) terms, \[ T_n(x) = \sum_{k=0}^{n} c_k x^k, \qquad c_k = \frac{f^{(k)}(0)}{k!}. \] It agrees with \(f\) to order \(x^n\), so the error starts at \(x^{n+1}\).
Its strength is that it is simple. Its weakness is that it is a polynomial. A polynomial is finite everywhere and runs off to \(\pm\infty\) as \(|x| \to \infty\). So it cannot have a vertical asymptote, it cannot level off to a constant, and it cannot imitate a singularity.
This weakness has a precise form. The Taylor series converges only inside a disc in the complex plane whose radius is the distance from \(x = 0\) to the nearest singularity of \(f\). Outside that disc, adding more terms makes things worse, not better.
2 The Padé approximant
A Padé approximant replaces the polynomial by a ratio of polynomials, \[ R_{[L/M]}(x) = \frac{P_L(x)}{Q_M(x)} = \frac{a_0 + a_1 x + \cdots + a_L x^L}{1 + b_1 x + \cdots + b_M x^M}. \] We fix \(b_0 = 1\), because multiplying the top and the bottom by the same constant does not change the ratio. That leaves \(L + 1\) unknowns on top and \(M\) unknowns below, \(L + M + 1\) in all.
We choose them so that \(R\) matches the Taylor series of \(f\) for as many terms as possible. With \(L + M + 1\) unknowns we can match \(L + M + 1\) coefficients, \(c_0\) to \(c_{L+M}\). That is the same number of coefficients a Taylor polynomial of degree \(L + M\) uses. So [3/3] Padé and degree-6 Taylor are a fair comparison. Each is built from \(c_0, \dots, c_6\).
How do we find the coefficients? Matching \(f \approx P/Q\) directly is non-linear in the \(b_j\). The trick is to multiply through by \(Q\) first and ask for \[ f(x)\,Q_M(x) - P_L(x) = O\!\left(x^{L+M+1}\right). \] Now everything is linear. Expand the product \(f Q\) and collect powers of \(x\). The coefficient of \(x^k\) in \(f Q\) is \(\sum_{j=0}^{\min(k,M)} b_j c_{k-j}\).
- For \(k = L+1, \dots, L+M\) there is no matching term in \(P\), so these coefficients must vanish. That gives \(M\) linear equations for \(b_1, \dots, b_M\).
- For \(k = 0, \dots, L\) the coefficient must equal \(a_k\). Once the \(b_j\) are known, this simply reads off the numerator.
So a Padé approximant costs one small linear solve, after which the numerator comes for free.
Henri Padé studied these approximants systematically in his 1892 thesis in Paris, written under Charles Hermite. They were not new even then. Jacobi and Frobenius had studied them, and Hermite had used a close relative in his 1873 proof that \(e\) is transcendental. Padé’s contribution was the table that arranges all \([L/M]\) for one function in a grid, now called the Padé table.
2.1 A first example by hand
Example. Find the [1/1] Padé approximant of \(\ln(1+x)\) about \(x = 0\). Compare it with the degree-2 Taylor polynomial at \(x = 1\), where the exact value is \(\ln 2\).
Solution. Both approximations use three coefficients. From \(\ln(1+x) = x - x^2/2 + x^3/3 - \cdots\) these are \[ c_0 = 0, \qquad c_1 = 1, \qquad c_2 = -\tfrac{1}{2}. \] We want \(P = a_0 + a_1 x\) and \(Q = 1 + b_1 x\) with \(f Q - P = O(x^3)\). The product is \[ (c_0 + c_1 x + c_2 x^2)(1 + b_1 x) = c_0 + (c_1 + c_0 b_1)\,x + (c_2 + c_1 b_1)\,x^2 + O(x^3). \] The \(x^2\) coefficient has no partner in \(P\), so it must vanish, \[ c_2 + c_1 b_1 = 0 \quad\Longrightarrow\quad -\tfrac{1}{2} + b_1 = 0 \quad\Longrightarrow\quad b_1 = \tfrac{1}{2}. \] The lower coefficients give the numerator, \[ a_0 = c_0 = 0, \qquad a_1 = c_1 + c_0 b_1 = 1. \] So \[ R_{[1/1]}(x) = \frac{x}{1 + x/2} = \frac{2x}{2 + x}. \] At \(x = 1\) the three numbers are \[ T_2(1) = 1 - \tfrac{1}{2} = 0.5, \qquad R_{[1/1]}(1) = \tfrac{2}{3} \approx 0.667, \qquad \ln 2 \approx 0.693. \] The Taylor polynomial is off by 28%. The Padé approximant is off by 4%, with the same three coefficients and no extra work beyond solving one equation.
Notice also what the Padé approximant has that the polynomial does not. It has a pole at \(x = -2\). The true function has a singularity at \(x = -1\). The rational function has “noticed” that something goes wrong on the negative axis and placed a pole there. A polynomial has no way to do that. This is the whole story in miniature, and the next section shows it with seven coefficients.
3 When Taylor gives up: \(\ln(1+x)\)
The function \(\ln(1+x)\) has a singularity at \(x = -1\). So its Taylor series about \(x = 0\) has radius of convergence 1. For \(x > 1\) it diverges, however many terms we add.
Using the seven coefficients \(c_0 = 0\) and \(c_k = (-1)^{k+1}/k\) for \(k = 1, \dots, 6\), the linear solve gives the [3/3] approximant with exact rational coefficients, \[ R_{[3/3]}(x) = \frac{x + x^2 + \tfrac{11}{60}x^3} {1 + \tfrac{3}{2}x + \tfrac{3}{5}x^2 + \tfrac{1}{20}x^3}. \]
In Figure 1 the black curve is the true function, the dashed orange curve is the Taylor polynomial and the blue curve is the Padé approximant. On the left, the blue curve lies on top of the black one over the whole range. The orange curve follows them up to about \(x = 0.8\), then turns over and dives. On the right, the vertical gap between the two error curves is the factor by which Padé beats Taylor at that \(x\).
Some numbers make the picture concrete.
| \(x\) | \(\ln(1+x)\) | Taylor, degree 6 | Padé [3/3] |
|---|---|---|---|
| 2 | 1.099 | \(-5.6\) | 1.098 |
| 3 | 1.386 | \(-85.65\) | 1.384 |
| 10 | 2.40 | \(-148\,873\) | 2.33 |
At \(x = 3\) the Taylor polynomial has the wrong sign and is more than sixty times too large in magnitude. The Padé approximant, built from the same coefficients, is right to three figures.
3.1 Why does it work?
Where are the poles and zeros of this rational function? The denominator factors exactly as \[ 1 + \tfrac{3}{2}x + \tfrac{3}{5}x^2 + \tfrac{1}{20}x^3 = \tfrac{1}{20}(x + 2)(x^2 + 10x + 10), \] so the poles are at \[ x = -2, \qquad x = -5 \pm \sqrt{15} \approx -1.127, \; -8.873. \] The numerator vanishes at \(x = 0\) and at \(x = (-30 \pm 4\sqrt{15})/11\), which is about \(-1.319\) and \(-4.136\).
The zero at \(x = 0\) is the genuine zero of \(\ln(1+x)\). Every other zero and every pole lies on \(x < -1\), and they alternate along it, pole, zero, pole, zero, pole as we move left from \(-1\). This is no accident. In the complex plane, \(\ln(1+x)\) has a branch cut along the real axis from \(-1\) to \(-\infty\). A rational function cannot have a branch cut. The best it can do is to line up poles and zeros along the cut, and that is exactly what it does. Away from the cut, this string of poles and zeros imitates the logarithm well. A polynomial has no poles at all, so it can only feel the singularity at \(x = -1\) as a limit on how far it reaches.
There is a theorem behind this observation. The function \(\ln(1+x)/x\) belongs to a class called Stieltjes functions, and for these a classical theorem of Markov says that the Padé approximants converge in every bounded region of the complex plane that keeps away from the cut. Their poles lie on the cut, exactly as we found. Herbert Stahl later extended the convergence to a much wider class of functions with branch points. The Taylor polynomials, in contrast, converge only inside the unit disc.
The table also shows that the error grows as \(x\) moves away from the origin. At \(x = 10\) the Padé value is off by 3%. Seven coefficients cannot describe the whole positive axis.
3.2 A caution
The Padé approximant does not grow like a logarithm for very large \(x\). As \(x \to \infty\) it tends to the ratio of the leading coefficients, \((11/60)/(1/20) = 11/3 \approx 3.667\). At \(x = 100\) it gives 3.44 against the true 4.62. Every \([n/n]\) approximant levels off to some constant, because a rational function with numerator and denominator of the same degree must. It is far better than a polynomial, but it is still not the logarithm.
4 When Taylor is already good: \(e^x\)
The exponential has no singularity anywhere. Its Taylor series converges for every \(x\). So the advantage Padé had for the logarithm is gone, and we should expect a closer contest.
The [3/3] approximant is \[ R_{[3/3]}(x) = \frac{1 + \tfrac{1}{2}x + \tfrac{1}{10}x^2 + \tfrac{1}{120}x^3} {1 - \tfrac{1}{2}x + \tfrac{1}{10}x^2 - \tfrac{1}{120}x^3}. \] The denominator is the numerator with \(x\) replaced by \(-x\). This is not a coincidence either. Since \(e^{-x} = 1/e^x\), the function \(Q(-x)/P(-x)\) also matches the Taylor series of \(e^x\) to the same order. The Padé approximant is unique, so it must be the same function, and that forces \(Q(x) = P(-x)\). As a consequence, \[ R(-x) = \frac{P(-x)}{Q(-x)} = \frac{Q(x)}{P(x)} = \frac{1}{R(x)}. \] The approximant inherits the property \(e^{-x} = 1/e^{x}\) exactly. The Taylor polynomial does not.
Figure 2 uses the same colours. On the left, all three curves agree on the middle of the range. Near \(x = 4\) the blue Padé curve shoots above the black curve, and near \(x = -4\) the orange Taylor curve lifts away from zero. The error plot on the right tells us which approximation wins where.
On the negative side, Padé wins over the whole plotted range. The true value at \(x = -4\) is \(e^{-4} \approx 0.0183\). The Taylor polynomial gives 2.156, more than a hundred times too large. A polynomial of even degree with positive leading coefficient must climb back up as \(x \to -\infty\), so it cannot follow a decaying exponential. The Padé approximant gives \(1/77 \approx 0.01299\). It inherits this behaviour from the positive side through \(R(-x) = 1/R(x)\), since \(R(4) = 77\).
The same symmetry carries a warning. The numerator is \(P(x) = Q(-x)\), so every pole of \(R\) on the positive side becomes a zero on the negative side. Just beyond the plotted range, at \(x \approx -4.644\), the approximant passes through zero and turns negative, which \(e^x\) never does. At \(x = -5\) it gives \(-0.0059\) against the true \(0.0067\), and as \(x \to -\infty\) it tends to \(-1\). Its error is still small in absolute terms (Taylor gives 9.4 there), but a negative value can break a calculation that takes a logarithm or a square root of the result.
Near the origin, Padé is more accurate. At \(x = 1\) the relative errors are 0.0083% for Taylor and 0.0010% for Padé, about eight times smaller.
On the positive side, Padé eventually loses. The two error curves cross at \(x \approx 3.06\). Beyond that, Taylor is better, and at \(x = 4\) Taylor gives 48.56 while Padé gives 77, against the true 54.60. The reason is a pole. The denominator has a real root at \(x \approx 4.644\) (and a complex pair at \(3.678 \pm 3.509\,i\)). The true exponential has no pole there. The rational function has to put its poles somewhere, and for an entire function there is nowhere good to put them.
The lesson from the two examples is this. Padé’s real advantage appears when a singularity limits the Taylor series. When the function is entire, as \(e^x\) is, the Taylor series is already a fine tool, and the Padé approximant brings its own hazard, a pole that the true function does not have.
5 Where engineers meet Padé
The property \(R(-x) = 1/R(x)\) that we found for \(e^x\) turns out to be the reason Padé approximants appear in engineering software. Let us see two places where it matters.
5.1 Time delays in control
A pure time delay \(\tau\) has transfer function \(e^{-s\tau}\). It is not a rational function of \(s\), so the root locus, the pole placement and all the state-space tools of classical control cannot handle it directly. We must replace it by a rational function. Delays are everywhere in aerospace. The pilot’s reaction time, the computation cycle of a fly-by-wire computer and the transport lag of fuel in a pipe are all delays.
On the frequency axis \(s = i\omega\), the exact delay has magnitude 1 at every frequency and phase \(-\omega\tau\). It changes the timing of a signal but never its size.
The [1/1] Padé approximant of \(e^{x}\), worked out exactly like the logarithm example, is \((1 + x/2)/(1 - x/2)\). With \(x = -s\tau\) it gives \[ e^{-s\tau} \approx \frac{1 - s\tau/2}{1 + s\tau/2}. \] On \(s = i\omega\) the numerator and denominator are complex conjugates, so the magnitude is exactly 1 at every frequency, just like the true delay. This is the property \(R(-x) = 1/R(x)\) again. At \(\omega\tau = 1\) its phase is \(-0.927\) rad against the true \(-1\) rad.
The first-order Taylor replacement \(1 - s\tau\) has magnitude \(\sqrt{1 + \omega^2\tau^2}\), which is 1.414 at \(\omega\tau = 1\) and grows without limit at high frequency. Its phase there is only \(-0.785\) rad. The deeper problem is that \(1 - s\tau\) is a polynomial in \(s\) with no denominator. Its numerator has a higher degree than its denominator, so it is not a proper transfer function. It has no state-space realisation, and it amplifies high-frequency noise without bound, which a real delay never does. The Padé model has numerator and denominator of the same degree, so it is proper and becomes one extra state in the model.
Both models have a zero in the right half plane, the Taylor one at \(s = 1/\tau\) and the Padé one at \(s = 2/\tau\). Such a zero limits how fast any controller can make the loop respond, and that is indeed the effect a real delay has. So the useful difference between the two is not the zero. It is that the Padé model gets the magnitude exactly right and stays proper.
The trade-off is that [1/1] is accurate only up to about \(\omega\tau \approx 1\). A designer who cares about higher frequencies uses [2/2] or [3/3] and pays with more states in the model.
5.2 Stiff differential equations
The second place is numerical integration. Apply a one-step method with step \(h\) to the test equation \(\dot{y} = \lambda y\), and write \(z = h\lambda\). The exact solution multiplies \(y\) by \(e^{z}\) in every step. A numerical method multiplies it by some approximation \(R(z)\) of \(e^{z}\), called its stability function.
- Explicit Euler has \(R(z) = 1 + z\), the degree-1 Taylor polynomial. Every explicit Runge–Kutta method has a Taylor-like polynomial here.
- The trapezoidal rule (Crank–Nicolson) has \(R(z) = (1 + z/2)/(1 - z/2)\), the [1/1] Padé approximant.
For a decaying mode \(\lambda < 0\) the exact factor \(e^{z}\) is less than 1. Take a stiff mode with \(z = -10\). The exact factor is \(e^{-10} \approx 4.5\times 10^{-5}\). Explicit Euler multiplies the error by \(|1 + z| = 9\) in every step, so the computation blows up. The trapezoidal rule multiplies it by \(|{-4}/6| \approx 0.667\), so the mode decays, if slowly.
This is not luck. For the trapezoidal rule \(|R(z)| < 1\) whenever \(\operatorname{Re} z < 0\), because \(z\) is then closer to \(-2\) than to \(+2\). A polynomial can never do this, because it grows without bound as \(|z| \to \infty\). So no explicit method is stable for every decaying mode at every step size. Implicit methods with Padé stability functions are. The Gauss–Legendre implicit Runge–Kutta methods with \(s\) stages have the \([s/s]\) Padé approximant of \(e^{z}\) as their stability function. The price is an equation to solve at every step, which is why we use them only when the problem is stiff.
The same idea is inside scipy.linalg.expm, the routine that computes the exponential of a matrix. It scales the matrix down until a Padé approximant is accurate, applies it, and squares the result back up.
6 So which one should I use?
Both approximations start from the same Taylor coefficients, so the choice is about what we need away from \(x = 0\).
- Use Taylor when \(x\) stays well inside the radius of convergence, when the function is entire, or when you need a guaranteed error bound. The Taylor remainder theorem gives one. Taylor polynomials are also cheaper to evaluate and never divide by zero.
- Use Padé when a singularity near the origin limits the Taylor series, when you need sensible behaviour for large \(x\), or when a structural property such as \(|e^{i\omega}| = 1\) or \(e^{-x} = 1/e^x\) must survive the approximation.
Padé comes with its own hazards. Its poles may land inside the interval you care about, as the pole at \(x \approx 4.644\) did for \(e^x\). The linear system can be singular or badly conditioned for high orders. And if the Taylor coefficients themselves carry noise, from measurement or round-off, the approximant can grow a spurious pole sitting next to a zero. Such a pair is called a Froissart doublet, and it cancels almost everywhere except right next to itself. So always plot a Padé approximant over the range you intend to use, and check where its poles are.