Pairwise Summation¶
This page describes the Pairwise summation strategy, which reduces rounding error by recursively combining sub-sums of similar size.
Implementation¶
Pairwise summation works by dividing the input array into two halves, summing each half separately, and then adding the two partial sums. By pairing numbers of comparable magnitude, the method limits the error growth that occurs when small values are added to a large accumulator.
Numerical Behavior¶
When applied to the test vector
the algorithm
- splits the vector into two halves:
{1.0, 1.0e16}
and{-1.0e16, -0.5}
- sums left half to get
1.0 + 1.0e16 = 1.0e16
- sums right half to get
-1.0e16 - 0.5 = -1.0e16
- finally adds the two partial sums:
1.0e16 + (-1.0e16) = 0.0
In this extreme case, the pairwise summation still results in catastrophic cancellation. However, for larger and more varied datasets, this method significantly reduces overall rounding error compared to the naive loop.