0
$\begingroup$

Given the following 2 series approximations for $e^{-x}$, which is more prone to finite precision f-p rounding errors? \begin{equation} e^{-x}=1-x+\frac{1}{2}x^2-\frac{1}{6}x^3+...\\ e^{-x}=\frac{1}{1+x+x^2/2+x^3/6+...} \end{equation}

I said that the first one is more prone to the rounding errors because it involves subtraction and the cancellation involved in subtraction can result in a great loss of information in floating point arithmetic. Is this the right $e^{-x}$, and if so how can I better my explanation as to why?

$\endgroup$
4
  • $\begingroup$ Questions you may want to consider: Are you looking at a particular interval containing $x$? On that interval, is subtractive cancellation actually an issue? Does the division add error, and if so, how large is its contribution to overall error relative to the error in the series evaluation alone? $\endgroup$
    – njuffa
    Sep 12, 2021 at 20:52
  • 1
    $\begingroup$ Example: Let's assume we wish to compute, using IEEE-754 binary32 (single precision), $e^{-x}$ for $x$ in $[0, \frac{1}{32}]$, accurate to single precision. We truncate the series after the $\frac{1}{6}$ term. First approach: x in [0.000000, 0.031250] maxrelerr=7.30939332e-8 Second approach: x in [0.000000, 0.031250] maxrelerr=1.29086775e-7. However, for other choices of input interval, the second approach can deliver superior accuracy compared to the first. $\endgroup$
    – njuffa
    Sep 12, 2021 at 21:23
  • 1
    $\begingroup$ The advantage of the first is that we know in advance the number of terms to be added for a given $x$ and a given tolerance. So, no more IF test in the summation loop. $\endgroup$ Sep 13, 2021 at 9:14
  • $\begingroup$ Were you ultimately able to resolve this question? $\endgroup$ Oct 13, 2021 at 15:50

1 Answer 1

1
$\begingroup$

As the question is currently stated, the two expansions are equally bad. It is left to the reader to determine the domain of each expansion and in each case it is natural to first consider the set of real numbers.

However, the natural choice is not necessarily right choice. Let $f : \mathbb{R} \rightarrow \mathbb{R}$ denote the natural exponential function $$f(x) = \exp(x)$$ and let $p_n(x)$ denote the Taylor polynomial of $f$ at the point $x_0 = 0$ of degree at most $n$, i.e., $$p_n(x) = \sum_{j=0}^{n} \frac{1}{j!} x^j.$$ A general polynomial $$q(x) = \sum_{j=0}^m a_j x^j$$ can be evaluated using Horner's method. In general, the computed value $\hat{y}$ of $y = q(x)$ satisfies $$|y - \hat{y}| \leq \gamma_{2m} \sum_{j=0}^m |a_j| |x^j|, \quad \gamma_{k} = \frac{ku}{1-ku}$$ where $u$ is the unit roundoff. In particular, if $a_j x^j$ has the same sign for all $j$, then the forward relative error satisfies $$\frac{|y- \hat{y}|}{|y|} \leq \gamma_{2m}.$$ It follows readily that we can evaluate $p_n(x)$ accurately for all $x \ge 0$. We have no such guarantee for $x<0$ and the expression for $p_n(x)$ suffers from subtractive cancellation for $x<0$ is large and $n$ is large. A good first approach to computing $f$ is to use $$f(x) \approx p_n(x), \quad x \ge 0$$ and $$f(x) \approx \frac{1}{p_n(-x)}, \quad x < 0$$ for a suitably large value of $n$ that can be determine in advance using, say, Taylor's theorem.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .