How many decimal places are needed for computing e^n accurately?

339 Views Asked by At

How many decimal places are needed in $n$ for computing $e^n$ with a precision of $k$ decimal places, given that $0\lt n\lt 1$?

Edit: The context

Let's suppose that I have a function f(x, y, k) = mul(y, log(x, k), k) so that the result is accurate up to the kth decimal place:

f(2, 0.1, 3) = mul(0.1, log(2, w), z) = mul(0.1, 0.693 + w decimal places, z) = 0.069 + z decimal places

So, to get an accurate result from exp(f(2, 0.1, w), z) up to the 3rd decimal place, what should be the value of w and z? By accurate I mean truncating everything after k. For example, log(2) = 0.69314718055994... and log(2, 3) = 0.693.

2

There are 2 best solutions below

3
On

This problem is much more specific than your previous question. It is consequently much easier.

Over the given range $e^n<3$, so if you want an absolute error of at most $\epsilon=10^{-k}/2$ then it is enough to have a relative error of at most $\epsilon/3$. This can be done uniformly over the given interval by taking Taylor terms for powers of $0,1,\dots,N$ where $N$ is large enough that $\frac{1}{(N+1)!}<\epsilon/3$. A quick-and-dirty way to do this is to note that for $n>9$, $n!>9! 10^{n-9}>3 \cdot 10^{n-4}$. Consequently if $k \geq 6$ then you can take $N=k+4$ (which can of course be extended to $k<6$ by taking $N=\max \{ k+4,10 \}$). For example $1/11! \approx 2.5 \cdot 10^{-8}<10^{-6}/6$.

Overall I am saying that if $x \leq 1$ then

$$\sum_{i=0}^{\max \{ k+4,10 \}} \frac{x^i}{i!}$$

is within $10^{-k}/2$ of $e^x$. Technically this does not necessarily imply that $k$ decimal places are correct, it only implies that $k$ decimal places are either correct or off by 1 (where 0 as a decimal place should really be understood as "10"). There is nothing that can really be done about that because fully correct decimal places are an unstable matter (due to carries).

This is not optimal however, because it performs far better on the left end of the interval than the right. Better methods that distribute the error more uniformly over the interval exist. One is Pade approximation, another is Chebyshev interpolation.

1
On

As the derivative of $e^n$ is between $1$ and $e$ for $n$ between $0$ and $1$, you need about the same number of decimal places for $n$ as for $e^n$ (half a place more to cover $n=1$).

Of course, the approximation formula that you'll use to compute $e^n$ must be true enough to the mathematical result to preserve the decimal places you need, but that wasn't your question.