What a Computer Does to a Number
Error in a Long Sum Grows Like Root n, Not Like n
Last timeThe Error of One Operation
The bound on a sum of a million values allows 999,999 unit roundoffs of error, the measured error is 169, and they differ because the roundings have mixed signs unless something makes them agree.
What a long sum is allowed to do
One addition rounds once and is wrong by at most half the gap at its result. A
sum of values is additions, so there are roundings, and the
question is what they do together. Write for the running total after
terms, with and at every later
step. The model for one operation applies to each step on its own, giving
with , where
is the relative error of that one addition and is the unit
roundoff, .
Now the step that usually gets skipped. The factor does not
multiply . It multiplies the entire quantity , which is to
say it multiplies everything added so far. So the error committed at the second
addition is carried into the third, and into the fourth, and into every
addition after that. Unrolling the recursion and discarding the products of two
or more s, which are smaller than and cannot matter at this
size, leaves the error of the finished sum as a weighted total of the
individual roundings, each weighted by the running total at the moment it
happened.
- the total the machine returns after n minus 1 rounded additions
- the exact mathematical total of the stored values, with no rounding anywhere
- the relative error of the kth addition alone, a definite number of either sign with magnitude at most u
- the running total after k terms, which is what the kth rounding acts on
- the worst case, reached only if every one of the n minus 1 roundings is as large as it may be and all of them have the same sign
The worst case, as a number
Take a million values drawn uniformly between 0 and 1. Their total, computed
exactly and rounded once at the end, is 499,984.11193900305. The terms are all
positive, so the sum of the magnitudes is the total itself, and the bound reads
. In relative terms that is
$999{,}999 \times 0.00000000000000011102230246251565 =
0.00000000011102219144021319$, and in absolute terms it is 0.0000555, so the
bound guarantees only the first ten digits of a sixteen digit format.
Adding the same million values left to right gives 499,984.11193899205. The
error is , which in units of is . The bound
allowed 999,999 of those units. The measurement used 198, so the bound is too
large by a factor of . A reader told only the
bound would conclude that a million additions destroy six digits, try it, see
that it destroys two, and stop believing the page.
What the error actually does as the sum gets longer
The way to settle this is to lengthen the sum and watch. Each row below is the
mean of twenty independent data sets, so that one lucky arrangement cannot
decide the shape, and the error is reported in units of so that the rows
are comparable.
The lesson stops here
7 more paragraphs to go
You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.
The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.
See the planThe contentsThis is the reading half
Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.
The contents