I am trying to learn numerical methods and understand why some algorithms are more efficient than others. My question os about the approximation of $\exp{-x}$. There are (at least) two possibilities. The first would be thinking of $e^{-x}$ as $$ \sum_{k=0}^\infty \frac{(-1)^k x^k}{k!} $$ and truncate this series to obtain the approximation.
The second option is think of $e^{-x}$ as
$$ \frac{1}{\sum_{k=0}^\infty \frac{x^k}{k!}} $$
and truncate the series.
I programmed both algorithms to compare them. I try with different values of $x$, seems that for small values ($x=0.5$) the first algorithm is better, while for bigger values ($x = 5$), the second is better than the first.
Could you help me to understand why is this?
There are probably multiple good answers for this question, but one reason is the relative computational error. If $x$ is large, then $\sum\limits_{k=0}^\infty \frac{(-1)^k x^k}{k!}$ adds and substracts large positive numbers at least in the beginning. This is bad as can be seen from the following toy example: If $a = 100$ and $b = 101$, then $b-a = 1$. A relative error of $1\%$ in $a$ or $b$ could give you up to $100\%$ error in the difference $b-a$. Addition (of positive numbers) does not have this problem; an error of $1\%$ in $b$ or $a$ will not give you more than $1\%$ error in the sum. Thus the alternating series should be avoided for large $x$. For small $x$ the terms get small very quickly so that you do not get this problem (as much).