How do I calculate the margin of rounding error?

I have been trying to write a program, that will allow me to calculate the constant e to an extremely precice value.

This is the equation I used:

1 + 1/1! + 1/2! and so on

My goal, was to calculate e to 9001 digits in precision (aka, OVER 9000!)

However, with the equation I used, I had to do some rounding.For example, 1/(1*2*3) would end up getting me 0.16666666666 (the 6 repeats until the 9001st digit, where it is rounded to a 7).

the rounding rules I used were, if the number cannot be divided evenly within 9001 digits, I would look at the 9002nd digit, if it is 5 or above, round up. else, round down.

Now my question is, in my circumstance, is it possible to figure out at most how many digits at the end would be made inaccurate because of the rounding?

thanks.

-
You should not use an exclamation mark in "OVER 9000!" if you do not want to cause confusion. – Henry Oct 16 '12 at 23:32

If you keep $n$ digits beyond what you want, each term can contribute a rounding error of at most $\pm 5 \cdot 10^{-n}$. Then if you add up $k$ terms, the maximum error is $\pm 5k \cdot 10^{-n}$. Of course, it is unlikely to be that bad. Alternately, if you keep no guard digits, the error could be $\frac k2$ in the last place.

-

Every tail of this series is bounded above by a geometric series, thus: \begin{align} e & = 1+1+\frac12+\frac16+\frac{1}{24}+\underbrace{\frac{1}{120}+\frac{1}{720}+\frac{1}{5040}+\cdots\cdots} \\[8pt] & < 1+1+\frac12+\frac16 + \frac{1}{24}+\underbrace{\frac{1}{120}+\frac{1}{6\cdot120}+\frac{1}{6^2\cdot120}+\frac{1}{6^3\cdot120}+\cdots\cdots} \\[8pt] & = 1+1+\frac12+\frac16 + \frac{1}{24}+\underbrace{\frac{1/120}{1-\frac16}} \\[8pt] & = 1+1+\frac12+\frac16 + \frac{1}{24}+\frac{1}{100} \\[8pt] & = \frac{600+600+300+100+25+6}{600} = \frac{1631}{600} = 2.718333333\ldots \end{align} and via long division, you can see that the $3$ must keep repeating. Now let's find a lower bound: \begin{align} e & > 1 + 1 + \frac12+\frac16+\frac{1}{24} +\frac{1}{120} + \frac{1}{720} \\[8pt] & = \frac{720+720+360+120+30+6+1}{720} = \frac{1957}{720} = 2.718055555\ldots \end{align} and again, by long division you can see that the $5$ must keep repeating. So you know exact values of the upper and lower bounds, and that guarantees that certain digits are correct. And you can narrow it down by using more terms of the series for the lower bound, and more terms before bounding above by a geometric series. This tells us that in "$2.718$" there's no rounding until after the $8$, and you can get more digits after that.

-

You will want to try to calculate $$\sum_{n=0}^{2962} \frac{1}{n!}$$ since $2963! \gt 10^{9002}$. All these terms will require rounding except when $n=0,1,2$ so you have to round $2960$ terms.

So the maximum absolute error will be $2560 \times \frac{1}{2} \times 10^{-9001}$ and you cannot absolutely trust the $8998$th decimal place and the $8997$th may be out by $1$, though probably is not.

More realistically the errors may largely cancel each other out, so assuming the errors are independently uniformly distributed, the standard deviation of each error is $\sqrt{\frac{1}{12}} \times 10^{-9001}$ so the standard deviation of the sum of the rounding errors is $\sqrt{\frac{2560}{12}} \times 10^{-9001}$ and taking three times this suggests that you should not trust the $9000$th decimal place and the $8999$th may be out by $1$ but is unlikely to be wrong by more than this.

-