2

Suppose I want to approximate $e^x$ for very large $x$. Suppose my tolerance were constant, for example, within a factor of $e$ (between $e^{x-1}$ and $e^{x+1}$). Are theres constants $k$ and $n$ such that for all $x > n$, I could approximate $e^x$ by just evaluating $k$ of its Taylor series terms? I don't mean starting from the beginning. I can evaluate any $k$ consecutive terms. How would I find this out?

What if, instead of a constant error tolerance, I can tolerate $O(\log(x))$ error? What is the error size like if I use $\log(x)$ terms?

To further expand, given any function $f(x)$ and its Taylor series, how many terms of its Taylor series, $T(x)$, would I need to approximate $f(x)$ with an error $E(x)$?

  • I'm not sure I get that "any $k$ consecutive terms" bit. You mean that you want to be able to approximate $e^x$ for all "sufficiently large" $x$, but you want to be able to do that even if you're somehow free to (or forced to) use the $500$th through $509$th terms of the Taylor series (for $k = 10$, for example)? That seems like it would be impossible to pick constants $n$ and $k$ for that. – Brian Tung Jun 29 '22 at 00:56
  • You're allowed to pick terms m(x) through m(x)+k – allidoiswin Jun 30 '22 at 20:44

2 Answers2

3

For a given non-negative real value of $\lambda$, we can ask about the distribution of sizes of the terms in the Taylor series

$$\exp(\lambda) = \sum_{n \ge 0} \frac{\lambda^n}{n!}$$

and in particular what the largest term is and what the terms close to this term look like. This question has a very good answer: after dividing by $\exp(\lambda)$, the terms of this series give a Poisson distribution

$$\mathbb{P}(X = n) = \exp(-\lambda) \frac{\lambda^n}{n!}$$

with parameter $\lambda$. For large $\lambda$ the Poisson distribution is asymptotically normal with mean and variance $\lambda$, and in particular the largest term occurs when $n \approx \lambda$ and the resulting probability is about $\frac{1}{\sqrt{2 \pi \lambda}}$; this follows from either the central limit theorem or Stirling's approximation depending on taste.

This means we only need $O(\sqrt{\lambda})$ terms (the terms closest to the largest term) to get within a multiplicative constant factor of the full sum; you can figure out what the multiplicative constants are here by integrating a normal distribution appropriately.

In general it depends on how the coefficients of the Taylor series grow.

Edit: I will say, though, that this is a fairly perverse thing to do because the exponential you're trying to approximate is easier to calculate than the factorials you need to evaluate these terms! We're essentially running Stirling's approximation in reverse here, and usually we think of Stirling's approximation as helpful precisely because it reduces estimating a factorial (hard) to estimating some exponentials (easy).

In slightly more detail, suppose you wanted to know the first $k$ digits of $\exp(N)$ where $N$ is large, as well as how many digits it has. Well, the number of digits is

$$\lfloor \log_{10} \exp(N) \rfloor = \lfloor N \log_{10} e \rfloor = \left\lfloor \frac{N}{\ln 10} \right\rfloor = d$$

while the first $k$ digits can be computed by writing

$$\exp(N) = \exp(N - d \ln 10) 10^d.$$

So first we need to compute $d$, which just means computing $\ln 10$ to suitably high precision, and we know how to do this. Next we need to compute $\exp(N - d \ln 10)$ to $k$ digits where $0 < N - d \ln 10 < \ln 10$ is bounded independent of $N$ and so the Taylor series now converges rapidly independent of $N$ (and there are probably lots of tricks available here to speed up convergence further), provided that we've computed $\ln 10$ to suitable precision.

Qiaochu Yuan
  • 419,620
  • I think this is in fact what I was looking for. Thanks! You said that "In general it depends on how the coefficients of the Taylor series grow." -- could you elaborate?

    As for perverseness -- it's more about something intriguing than immediately practical :)

    – allidoiswin Jul 05 '22 at 22:56
  • 1
    @allidoiswin: for another Taylor series the analysis would just be different, I'm not sure what there is to say in full generality. Any Taylor series $\sum \frac{a_n}{n!} x^n$ where $a_n$ grows, say, at most exponentially has infinite radius of convergence and there's a lot of wiggle room in how the $a_n$ could grow which alters the analysis. If you wanted to name a specific such series you're interested in I could see if I can say anything more specific about that one. – Qiaochu Yuan Jul 05 '22 at 23:42
2

I do not know if this will answer the question.

Consider first the problem of $$e^{-x}=\sum_{n=0}^\infty (-1)^n \frac {x^n}{n!}=\sum_{n=0}^p (-1)^n \frac {x^n}{n!}+\sum_{n=p+1}^\infty (-1)^n \frac {x^n}{n!}$$ and you want to know $p$ such that $$\sum_{n=p+1}^\infty (-1)^n \frac {x^n}{n!} \leq 10^{-k}$$ Since this is an alternating series it suffices to find $p$ such that $$\frac {x^{p+1}}{(p+1)!}\leq 10^{-k}\quad \implies \quad (p+1)! \geq x^{p+1} \,10^k$$

If you look at this question, you will find that $$p \sim x \, e^{1+W(t)}-\frac 32 \quad \text{where} \qquad t=\frac{1}{2 e x}\log \left(\frac{10^{2 k}}{2 \pi x}\right)$$ $W(t)$ being Lambert function.

For example, using $x=5$ and $k=20$, this would give, as a real $p=39.0514$ (the exact solution being $p=39.0519$); so, using the ceiling function $p=40$.

Now, compute $$\sum_{n=0}^{40} \frac {5^n}{n!}=\color{red}{148.41315910257660342111}40$$ while $$e^5=\color{red}{148.4131591025766034211156}$$