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

THE ONLINE MEAN the average, updated one sample at a time — never store the data

The schoolbook mean sums every value then divides: it must hold the whole dataset. The online mean never does. It carries one number and updates it: m ← m + (x−m)/n as each sample arrives. After the last one it holds the exact same average — but it never retained the data, and it looked at each value once. That is the streaming discipline in its simplest form: a correct batch mean stores n values and can revisit them; this carries a bounded summary (one running number) and forgets each sample the instant it is folded in. Same answer, a property the batch form lacks.

THE TECHNIQUE m ← m + (x−m)/n; one number, one pass

A stream of four values. The demo folds each into a single running mean — the data is never stored: live demo


HISTORY & CREDIT the provisional-mean update · Welford 1962

“To average a stream you must first collect it.” — the online update carries one number and folds each arrival in; the data is gone the moment it is used. The mean without the memory. cited

1962 · B. P. Welford — the numerically-stable incremental update mn = mn−1 + (x−mn−1)/n, the “provisional mean” recurrence.
popularized · Knuth, TAOCP vol. 2, as the recommended way to compute a running average.
now · the first thing every streaming, embedded, or online-learning system reaches for.

One number, folded forward, the data discarded behind it. The average that never needed the archive. Welford 1962

RECOMMEND FOR I-13 the running mean, one pass on the compiler

On the canonical compiler, streaming [4,8,6,2] through the update lands on mean = 5 — carrying a single running number, touching each value once:

$ i13 run op_onlinemean.i13 # m <- m + (a[i]-m)/(i+1) RUN OK · 122 step(s) · peak stack 5 · call depth 5 mean = 5 -- exact average of [4,8,6,2], data never retained
Recommend: the online mean is the streaming discipline at its purest, and i13 enacts it exactly — one running scalar threaded through a single pass, each sample folded in and forgotten. The supplement to correctness is precise: a correct batch mean must retain all n values; this carries a bounded summary and touches each once. (Honest bound: i13's only loop is recursion, so the call stack is O(n) — what i13 genuinely enacts is the bounded summary and the single touch, not O(1) total memory. The state that matters — what you carry forward — is one number.) The warm-up for Welford's variance (dart 311), where the bounded summary grows to two.