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?
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.