Quant Memo
Coding/●●●●

Pairwise summation, the trick NumPy uses for nearly free accuracy

Asked at Jump Trading, Citadel

A plain accumulation loop has worst-case rounding error that grows like O(nε)O(n\varepsilon): the more numbers you add, the worse it gets. Kahan summation fixes this but costs about four extra operations per element. There is a middle path that costs almost nothing.

Implement pairwise (divide-and-conquer) summation, state its error bound, and explain why it is nearly as fast as the naive loop.

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions