7

Whenever I see proofs that use Taylor series for the natural exponential function, they use the following:

$$ e^x = 1 + x + \frac{x^2}{2!} + \frac{x^3}{3!} + \ldots $$

It is my understanding that such series is an approximation for when x is around 0, but does it work accurately for x far away from 0 as well? How can we use this series to prove things like Euler's formula and generalize across any x?

If we want Taylor series for the natural exponential function around $a$ that is far away from 0, shouldn't we use the following instead?

$$ e^x = e^a + e^a (x - a) + \frac{e^a (x-a)^2}{2!} + \ldots $$

Would the proof for, for example, Euler's formula end up being the same whether I use the first Taylor expansion at the top or the one just above? It feels like the one above would become much more complex due to the expansion of $(x-a)$ but maybe it ends up being the same after some cancellations happen?

Thanks!

Sebastiano
  • 7,649
  • 3
    Both series are correct: the second is in effect the first but using $e^ae^{x-a}$ rather than $e^x$. Both are correct for all real $x$ and $a$ if you do the full sum. In the second expression, you get closer with a few terms but have the problem of calculating $e^a$. – Henry Nov 08 '23 at 16:42
  • 4
    The difficulty here only shifts: What is $e^a$? You'll have to compute that somehow! – Wolfgang Bangerth Nov 09 '23 at 03:31
  • 1
    @WolfgangBangerth knowing that e=2.7... you could split e^a into e^{n+b} where n is the greatest integer smaller than a and b=a-n. Then using e^{n+b} = e^n e^b compute e^n = e * e * ... * e and evaluate e^b via the Taylor approx. around x=0. – infinitezero Nov 09 '23 at 08:04
  • @infinitezero Sure, that works if $a$ is an integer. But what do you do for complex numbers $a$? – Wolfgang Bangerth Nov 09 '23 at 20:15

4 Answers4

10

The Taylor series for $e^x$ has radius of convergence $\infty$, and it converges to $e^x$ for every $x$. It can certainly be used for proving things such as Euler's formula $e^{ix} = \cos(x) + i \sin(x)$. What it is not so good for is actual numerical approximations of $e^x$ when $|x|$ is large: there are other methods that are good for that.

Robert Israel
  • 448,999
  • 2
    "Not so good" is putting it too mildly. The Taylor series is horribly inefficient for numerical approximations when $|x|$ is large. – leftaroundabout Nov 09 '23 at 10:14
8

The Taylor series for $e^x$ has an infinite radius of convergence, meaning that for all $x \in \mathbb{R}$ (and indeed all $x \in \mathbb{C}$), $\sum_{n = 0}^\infty \frac{x^n}{n!}$ converges exactly to $e^x$.

However, the series is only pointwise convergent, not uniformly convergent. What that means is that the speed at which it converges depends on $x$, and in particular large values of $x$ will converge more slowly, i.e. the error in estimating $e^x$ with $n$ terms of its Taylor series increases as $x$ increases.

We can look at Taylor's theorem to understand this. In one form, it says that:

$$e^x = 1 + x + \frac{x^2}{2} + \ldots + \frac{x^n}{n!} + \frac{e^c}{(n+1)!} x^{n+1}$$

where $c$ is a number between $0$ and $x$. In other words, the error in using $n$ terms of the series to estimate $e^x$ will be on the scale of $M x^{n+1}$ for some value $M$.

On that basis, if you want to accurately calculate $e^x$ for a large value of $x$, then you either need to include a lot of terms in the Taylor series (and you can use Taylor's theorem to work out how many such terms you'd need to achieve a particular level of accuracy), or you would need to look for an alternative method. Certainly, you could do something like shift the Taylor series as you suggest, but that requires you to calculate $e^a$ as well as $e^x$ and multiply those together which will probably not be any more efficient to achieve the same level of accuracy. There are some algorithms discussed in other SE posts (e.g. this one or this one) that use methods like continued fractions and they may be more computationally efficient under the right circumstances.

ConMan
  • 24,300
  • 1
    Don't miss the improved methods that @Johan found on Wikipedia! Some are straightforward and fundamental, like argument reduction using $\exp(x) = \exp(x/2)^2$. Others are subtle and even more fundamental, like—@Johan's summary—"[using] Newton iteration to reduce the problem to computing the logarithm function and then using an algorithm based on the arithmetic-geometric mean to compute the logarithm." – Vectornaut Nov 09 '23 at 07:35
  • I'd say the error in using $n$ terms is on the scale of $Mx^{n+1}/(n+1)!$ where $M$ can be $e^x$. With Stirling's formula I get from this that, just to make sure the error is less than $e^x$ itself (which of course is by far not enough), we need something like $n > e\cdot x$. – Torsten Schoeneberg Nov 09 '23 at 21:07
3

If you want to calculate a decimal number that gives you the $e$ raised to some large $x$, you can do the following. The Taylor series will appear, I promise. First, change to a base-ten exponential, viz $$ e^x = 10^{x \log_{10}e}, $$ and write $x \log_{10} e = N + y$ with $N$ integral and $0\le y<1$. Then $$ e^x = 10^N \times 10^y. $$ Observe that ten to an integral power is trivial, multiplication is easy and $\log_{10}e$ can be looked up in tables if you have no PC but a library at your disposal. So you only need to calculate the exponential of the fractional part, $10^y$, and shift the decimal point by $N$ places.

How does one evaluate $10^y$, you might ask. Let's write $ 10^y = e^{y \ln{10}}$. This seems to have taken us back to the starting point -- but $\ln{10} \approx 2.302$ so the exponent is now always smaller than $\pi$, i.e. it is now a bounded small number and we can thus confidently use the Taylor series. Note though that you need some ten terms to reach the third digit of $e^{2.302}$. In that sense you are still far from the expansion point. Thankfully, you can improve this easily. If you look up e.g. $e^2$ in your library's tables, you can factor this out and evaluate the Taylor series even closer to zero and quickly gain more than one decimal digit per series term.

For a binary number you would replace all tens by twos in the above, but the procedure remains the same. There's one added benefit worth pointing out, namely that $\ln 2<1$ which makes $e^{y\ln 2}$ efficient to evaluate with the Taylor series without further preparation.

Returning to your original question, yes, you could use the Taylor series, but as you have noticed and other users explained, that is quite unwieldy far from the origin. Yet, as demonstrated above, it is easy to improve the calculation while still relying on the Taylor series by putting to use some knowledge of our number system and of logarithms.

tobi_s
  • 343
3

Exponential function $e^x$ is entire function, meaning it's Taylor series around any point $a$ will converge with infinite radius of convergence. However, rate of convergence will depend on how far $x$ is from $a$. Further it is, slower the convergence is.

The problem is actually evident, no matter how large degree of Taylor polynomial you are using for approximations, no polynomial can approximate exponential function well when $|x|\to\infty$ because of elementary limits $\lim_{x\to\infty}\frac{e^x}{x^n} = \infty$ and $\lim_{x\to -\infty}\frac{x^n}{e^x} = \pm\infty$. Intuitively, and as you probably know, exponential growth is staggeringly faster than polynomial growth.

So, even though it's clear that for higher accuracy of approximation you need Taylor polynomial of higher degree, here we want to closer inspect it's dependance on $x$. For that we can look at Lagrange form of the remainder: $$e^x = \sum_{k=0}^n\frac{x^k}{k!}+\frac{e^c}{(n+1)!}x^{n+1}$$ for $c$ between $0$ and $x$. Combined with the fact that $e^x$ is strictly increasing, for positive $x$ we get an upper bound on absolute error: $$\left|e^x - \sum_{k=0}^n\frac{x^k}{k!}\right|\leq\left|\frac{e^x}{(n+1)!}x^{n+1}\right|.$$ Therefore, to guarantee that the absolute error is less than $\varepsilon$, for positive $x$ you need to find $n$ such that $$x^{n+1}e^x < \varepsilon (n+1)!\tag{1}.$$ To get a feel for that, here's a table where $n$ will be the smallest positive integer that satisfies inequality $(1)$ for $\varepsilon = 0.1$ (meaning the absolute error is less than $0.1$) and $m$ will be the smallest positive integer that satisfies $\left|e^x - \sum_{k=0}^n\frac{x^k}{k!}\right| < 0.1,$ i.e. true minimal value for the degree of Taylor polynomial good enough to approximate $e^x$ to the desired accuracy.

\begin{array}{c|c|c} x & n & m \\ \hline 1 & 4 & 3\\ 2 & 7 & 6\\ 5 & 17 & 14\\ 10 & 35 & 27\\ 100 & ? & 273 \end{array}

I couldn't find the value with $?$ due to machine precision issues.

The table tells you, for example, that to estimate $e^5$ with absolute error less than $0.1$, we need Taylor polynomial of degree at least $14$, while Lagrange form of the remainder would tell us that we need at least $17$ to be certain without actually computing.

Of course, if you have keen eye, you will notice the bigger problem with this. To get an upper bound on error for approximating $e^x$ in Lagrange form of the remainder, we need to know $e^x$, or to avoid circularity, upper bound for $e^x$, i.e. $M$ such that $|e^x| \leq M$, so we get the following estimate on absolute error: $$\left|e^x - \sum_{k=0}^n\frac{x^k}{k!}\right|\leq\left|\frac{e^x}{(n+1)!}x^{n+1}\right|\leq\left|\frac{M}{(n+1)!}x^{n+1}\right|,$$ so instead of $(1)$ we need to first find suitable $M$ and then solve inequality $Mx^{n+1} < \varepsilon (n+1)!$ for $n$. For example, if you are estimating $e^x$ for $x\in [0,1]$, we can pick $M = 3$, since $e < 3$.

All of this tells you that approximating $e^x$ with Taylor series around $0$, although possible, is not practical for $x$ far away from $0$.

Ennar
  • 23,082