ArticleslgStudy

computer science

2Sum

2Sum 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 2Sum rather than just read about it. In short: 2Sum is a floating-point algorithm for computing the exact round-off error in a floating-point addition operation. 2Sum and its variant Fast2Sum were first published by Ole Møller in 1965. Fast2Sum is often used implicitly in other algorithms such as compensated summation algorithms; Kahan's summation algorithm was published first in 1965, and Fast2Sum was later factored out of it by Dekker in 1971 for double-double…

Key takeaways

  • 2Sum 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 2Sum to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of 2Sum from memory before moving on to harder problems.

Reference excerpt

2Sum is a floating-point algorithm for computing the exact round-off error in a floating-point addition operation. 2Sum and its variant Fast2Sum were first published by Ole Møller in 1965. Fast2Sum is often used implicitly in other algorithms such as compensated summation algorithms; Kahan's summation algorithm was published first in 1965, and Fast2Sum was later factored out of it by Dekker in 1971 for double-double arithmetic algorithms. The names 2Sum and Fast2Sum appear to have been applied retroactively by Shewchuk in 1997.

Algorithm Given two floating-point numbers a and b, 2Sum computes the floating-point sum s:=a⊕b rounded to nearest and the floating-point error t:=a+b−(a⊕b) so that s+t=a+b, where ⊕ and ⊖ respectively denote the addition and subtraction rounded to nearest. The error t is itself a floating-point number.

Inputs floating-point numbers a,b Outputs rounded sum s=a⊕b and exact error t=a+b−(a⊕b) s:=a⊕b a′:=s⊖b b′:=s⊖a′ δa:=a⊖a′ δb:=b⊖b′ t:=δa⊕δb return (s,t) Provided the floating-point arithmetic is correctly rounded to nearest (with ties resolved any way), as is the default in IEEE 754, and provided the sum does not overflow and, if it underflows, underflows gradually, it can be proven that s+t=a+b. A variant of 2Sum called Fast2Sum uses only three floating-point operations, for floating-point arithmetic in radix 2 or radix 3, under the assumption that the exponent of a is at least as large as the exponent of b, such as when |a|≥|b|:

Inputs radix-2 or radix-3 floating-point numbers a and b, where either at least one is zero, or which have normalized exponents ea≥eb Outputs rounded sum s=a⊕b and exact error t=a+b−(a⊕b) s:=a⊕b z=s⊖a t=b⊖z return (s,t) Even if the conditions are not satisfied, 2Sum and Fast2Sum often provide reasonable approximations to the error, i.e. s+t≈a+b, which enables algorithms for compensated summation, dot-product, etc., to have low error even if the inputs are not sorted or the rounding mode is unusual. More complicated variants of 2Sum and Fast2Sum are used for rounding modes other than round-to-nearest.

See also Kahan summation algorithm Round-off error Double-double arithmetic

References

Worked examples

Example 1 — a first encounter with 2Sum

Start with the simplest possible case. Write down what 2Sum 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 2Sum 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 2Sum 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 2Sum

In research
2Sum 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 2Sum 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
2Sum is common in secondary-school and first-year university syllabi. It links to neighbouring topics Computer arithmetic, Floating point, Numerical analysis, so understanding it makes those chapters shorter.
In everyday life
Look for 2Sum 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 “2Sum” →

How to study 2Sum in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what 2Sum 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 2Sum out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is 2Sum in simple terms?

2Sum is a floating-point algorithm for computing the exact round-off error in a floating-point addition operation. 2Sum and its variant Fast2Sum were first published by Ole Møller in 1965. Fast2Sum is often used implicitly in other algorithms such as compensated summation algorithms; Kahan's summat…

Why does 2Sum 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 2Sum?

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 2Sum.

Tags

  • Computer arithmetic
  • Floating point
  • Numerical analysis

Keep exploring