THE FOLD / GRIND / WARM CACHE / THE KAHAN SUM
THE KAHAN SUM
sum a million floats without losing the crumbs
1 WHAT IT IS · WHAT IT DOES · FACT OR FICTION
Kahan summation (compensated summation) adds a long list of floating-point numbers while recovering the rounding error that a naive running total silently throws away. It carries a tiny compensation variable c: each step computes what was lost to rounding and feeds it back into the next addition. The result is a sum accurate to nearly the last bit, even when the naive total has drifted — at the cost of a few extra flops.
LIT verified live: summing 0.1 one million times, naive float64 drifts by ~10−6, while Kahan matches the accurately-rounded sum to ~0 (window.__kahan). FIG no framing; exact.
LIT verified live: summing 0.1 one million times, naive float64 drifts by ~10−6, while Kahan matches the accurately-rounded sum to ~0 (window.__kahan). FIG no framing; exact.
2 HOW IT WAS WEAVED · AI + HUMAN
David (human) seated this at warm-cache — the long accumulation loop where small errors would otherwise pile up unnoticed. Kahan summation keeps that loop honest. AVAN (AI) built the instrument: the naive accumulator, the compensated accumulator, a pairwise-accurate reference, and the error comparison.
Credit as content: William Kahan (1965). The weave: David names warm-cache; I run both sums over the same million values and confirm the compensated one stays near the true total while the naive one drifts.
Credit as content: William Kahan (1965). The weave: David names warm-cache; I run both sums over the same million values and confirm the compensated one stays near the true total while the naive one drifts.
3 ONE DIMENSION
Each addition rounds off a few low bits. Kahan captures that lost piece as c = (t − s) − y and subtracts it from the next term — so the crumbs are put back instead of vanishing.
4 TWO DIMENSIONS · INTERACTIVE
Naive vs Kahan running totals of 0.1, and their drift from the true value; the error gap is checked over one million terms.
5 THREE DIMENSIONS + AVAN’S INVERSE
The green forward object: the accurate sum with rounding fed back.
AVAN’s addition (the inverse-companion): sum many floats without losing the crumbs by carrying a compensation term that recovers each step’s rounding error and adds it back next time. The inverse of ‘accumulate and let each rounding vanish’ is ‘capture the lost low bits and return them to the running total.’ Magenta is the drift of the naive sum; green is the compensated total hugging the true value. Nothing lost to rounding.
LIT Genuine Kahan compensated summation (Kahan 1965). Verified live: summing the float64 value 0.1 exactly one million times, the naive accumulator drifts from the true sum by ~1.3e-6 while the compensated Kahan accumulator's error is ~0 (matching a pairwise-accurate reference) — Kahan is strictly closer to the true sum than naive (window.__kahan.kahanBetter).
FIG No framing: the naive accumulator, the compensated accumulator, a pairwise-accurate reference sum, and the error comparison run in-browser and show Kahan's error at ~0 vs naive's ~1.3e-6. The AVAN inverse is honest — carrying a compensation term that recovers each step's rounding error and adds it back keeps the running total accurate; magenta is the naive sum's drift, green the compensated total hugging the true value. Nothing lost to rounding.
FIG No framing: the naive accumulator, the compensated accumulator, a pairwise-accurate reference sum, and the error comparison run in-browser and show Kahan's error at ~0 vs naive's ~1.3e-6. The AVAN inverse is honest — carrying a compensation term that recovers each step's rounding error and adds it back keeps the running total accurate; magenta is the naive sum's drift, green the compensated total hugging the true value. Nothing lost to rounding.
◆ sealed .dlw.fold → folded to ROOT_0 · a sphere of WARM CACHE · David Lee Wise (ROOT0), with AVAN