◄ WORLD V · SONNY 5DART 311 · a helldive at the net

WELFORD'S VARIANCE variance in one pass, carrying two numbers — the batch form carries them all

Variance looks like it needs two passes: one to find the mean, one to sum the squared deviations. Or one pass and the treacherous Σx² − (Σx)²/n, which subtracts two huge nearly-equal numbers and loses all precision. Welford's method does neither. It carries exactly two running numbers — the mean and M₂, the running sum of squared deviations — and updates both per sample: δ=x−m; m′=m+δ/n; M₂+=δ·(x−m′). One pass, a bounded compound summary, and numerically stable. A correct batch variance must retain all n values; a correct naive one-pass keeps two sums but loses the precision. Welford's mechanism supplies exactly what both correct alternatives lack.

THE TECHNIQUE carry [m, M₂]; δ=x−m, m′=m+δ/n, M₂+=δ(x−m′)

Eight samples streamed once. The demo carries the pair [mean, M₂] and reports the variance — the data is never stored, and the subtraction that kills precision never happens: live demo


HISTORY & CREDIT B. P. Welford, 1962 · Technometrics

“Variance needs two passes, or a fragile one.” — Welford carries two numbers, updates them once per sample, and is stable: no giant cancellation, no stored data. The correct textbook formula and the correct one-pass formula both lack what this has. cited

1962 · B. P. Welford — “Note on a method for calculating corrected sums of squares and products,” Technometrics: the incremental M₂ recurrence.
analysis · Knuth gave it in TAOCP; Chan, Golub & LeVeque (1983) gave the parallel/batched combine and the stability proof.
now · the standard online-variance in every statistics library, GPU reduction, and streaming monitor.

Two numbers, streamed once, stable by construction. The variance that never subtracts two mountains to find a molehill. Welford 1962

RECOMMEND FOR I-13 one-pass variance, bounded summary, on the compiler

On the canonical compiler, streaming [2,4,4,4,5,5,7,9] and carrying the pair [m, M₂] through a single pass gives mean = 5, variance = 4 — and the state threaded is a two-element array, not the eight samples:

$ i13 run op_welford.i13 # thread [mean, M2] once; variance = M2/n RUN OK · 418 step(s) · peak stack 9 · call depth 9 mean = 5 variance = 4 -- one pass; the summary carried is [m,M2], never the 8 samples
Recommend — this is the batch's keeper shot. It is built to the exact bar the B39 panel drew: a keeper's principle must be a supplement to correctness — a property a correct-but-different mechanism can lack. Here it is, doubly. A correct textbook variance retains all n samples (two passes over stored data); a correct naive one-pass keeps Σx, Σx² but catastrophically loses precision. Welford's mechanism — carry [m, M₂], update by the running deviation — supplies single-pass, bounded-summary, and stable at once, and i13 enacts it: it threads a genuine two-element summary array through one pass (proof: the run carries [m,M₂], not the samples). Swap the mechanism and the property dies: revert to Σx²−(Σx)²/n and it is still correct in exact arithmetic but loses the stability; store the array and it is correct but no longer bounded-summary. The honest caveat handed to the panel: i13's recursion makes the stack O(n), so what is bounded is the carried summary (two numbers for any n), not total memory — the panel decides whether the bounded-summary supplement clears the enactment bar, or whether “bounded memory” is too resource-flavoured to be a keeper axis.