ArticleslgStudy

computer science

Pairwise summation

Pairwise summation is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Pairwise summation rather than just read about it. In short: In numerical analysis, pairwise summation, also called cascade summation, is a summation algorithm, i.e. a technique to sum a sequence of finite-precision floating-point numbers that substantially reduces the accumulated round-off error compared to naively accumulating the sum in sequence. Although there are other techniques such as Kahan summation that typically have even smaller round-off errors, pairwise summatio…

Key takeaways

  • Pairwise summation belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Pairwise summation to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Pairwise summation from memory before moving on to harder problems.

Reference excerpt

In numerical analysis, pairwise summation, also called cascade summation, is a summation algorithm, i.e. a technique to sum a sequence of finite-precision floating-point numbers that substantially reduces the accumulated round-off error compared to naively accumulating the sum in sequence. Although there are other techniques such as Kahan summation that typically have even smaller round-off errors, pairwise summation is nearly as good (differing only by a logarithmic factor) while having much lower computational cost—it can be implemented so as to have nearly the same cost (and exactly the same number of arithmetic operations) as naive summation. In particular, pairwise summation of a sequence of n numbers xn works by recursively breaking the sequence into two halves, summing each half, and adding the two sums: a divide and conquer algorithm. Its worst-case roundoff errors grow asymptotically as at most O(ε log n), where ε is the machine precision (assuming a fixed condition number, as discussed below). In comparison, the naive technique of accumulating the sum in sequence (adding each xi one at a time for i = 1, ..., n) has roundoff errors that grow at worst as O(εn). Kahan summation has a worst-case error of roughly O(ε), independent of n, but requires several times more arithmetic operations. If the roundoff errors are random, and in particular have random signs, then they form a random walk and the error growth is reduced to an average of O ( ε log ⁡ n ) {\displaystyle O(\varepsilon {\sqrt {\log n}})} for pairwise summation. A very similar recursive structure of DFT decomposition is found in many fast Fourier transform (FFT) algorithms, and is responsible for the same slow roundoff accumulation of those FFTs when implemented with a breadth-first technique due to poor memory locality.

The algorithm In pseudocode, the pairwise summation algorithm for an array x of length n ≥ 0 can be written:

s = pairwise(x[1...n]) if n ≤ N base case: naive summation for a sufficiently small array s = 0 for i = 1 to n s = s + x[i] else divide and conquer: recursively sum two halves of the array m = floor(n / 2) s = pairwise(x[1...m]) + pairwise(x[m+1...n]) end if

For some sufficiently small N, this algorithm switches to a naive loop-based summation as a base case, whose error bound is O(Nε). The entire sum has a worst-case error that grows asymptotically as O(ε log n) for large n, for a given condition number (see below). In an algorithm of this sort (as for divide and conquer algorithms in general), it is desirable to use a larger base case in order to amortize the overhead of the recursion. If N = 1, then there is roughly one recursive subroutine call for every input, but more generally there is one recursive call for (roughly) every N/2 inputs if the recursion stops at exactly n = N. By making N sufficiently large, the overhead of recursion can be made negligible (precisely this technique of a large base case for recursive summation is employed by high-performance FFT implementations). Regardless of N, exactly n−1 additions are performed in total, the same as for naive summation, so if the recursion overhead is made negligible then pairwise summation has essentially the same computational cost as for naive summation. A variation on this idea is to break the sum into b blocks at each recursive stage, summing each block recursively, and then summing the results, which was dubbed a "superblock" algorithm by its proposers. The above pairwise algorithm corresponds to b = 2 for every stage except for the last stage which is b = N. Dalton, Wang & Blainey (2014) describe a iterative, "shift-reduce" formulation for pairwise summation. It can be unrolled and sped up using SIMD instructions. The non-unrolled version is:

Accuracy Suppose that one is summing n values xi, for i = 1, ..., n. The exact sum is:

S n = ∑ i = 1 n x i {\displaystyle S_{n}=\sum _{i=1}^{n}x_{i}}

(computed with infinite precision). With pairwise summation for a base case N = 1, one instead obtains S n + E n {\displaystyle S_{n}+E_{n}} , where the error E n {\displaystyle E_{n}} is bounded above by:

| E n | ≤ ε log 2 ⁡ n 1 − ε log 2 ⁡ n ∑ i = 1 n | x i | {\displaystyle |E_{n}|\leq {\frac {\varepsilon \log _{2}n}{1-\varepsilon \log _{2}n}}\sum _{i=1}^{n}|x_{i}|}

where ε is the machine precision of the arithmetic being employed (e.g. ε ≈ 10−16 for standard double precision floating point). Usually, the quantity of interest is the relative error | E n | / | S n | {\displaystyle |E_{n}|/|S_{n}|} , which is therefore bounded above by:

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Pairwise summation

Start with the simplest possible case. Write down what Pairwise summation claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Pairwise summation before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Pairwise summation ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Pairwise summation

In research
Pairwise summation appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Pairwise summation in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Pairwise summation is common in secondary-school and first-year university syllabi. It links to neighbouring topics Computer arithmetic, Numerical analysis, so understanding it makes those chapters shorter.
In everyday life
Look for Pairwise summation outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Pairwise summation” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Pairwise summation in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Pairwise summation means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Pairwise summation out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Pairwise summation in simple terms?

In numerical analysis, pairwise summation, also called cascade summation, is a summation algorithm, i.e. a technique to sum a sequence of finite-precision floating-point numbers that substantially reduces the accumulated round-off error compared to naively accumulating the sum in sequence. Although…

Why does Pairwise summation matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Pairwise summation?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Pairwise summation.

Tags

  • Computer arithmetic
  • Numerical analysis

Keep exploring