TAOCP Vol 2: Seminumerical Algorithms · Week 76

TAOCP 4.2.2 Accuracy of Floating Point Arithmetic

Updated

About 8 hours31 exercises, rated 10 to M40

Summary

TAOCP 4.2.2 Accuracy of Floating Point Arithmetic: Error analysis for floating point: which algebraic laws survive (commutativity does), which break (associativity, distributivity), and how to reason about the error of a sequence of operations. Budget about 8 hours; do exercises 4, 3 and 8.

Flashcards 14 cards for Anki and AnkiMobile · all decks

Anki deck.tsv

This week's steps

3 steps
  1. Read §4.2.2 Accuracy of Floating Point Arithmetic

    Write programs that demonstrate non-associativity and catastrophic cancellation.

  2. Work the exercises (8 picked)

    Start with Ex 4, Ex 3, Ex 8; log what you solve below.

  3. Write down one thing you'd explain to someone

    A few sentences in your own words in Your notes: the idea, why it works, an example. 30 words ticks this.

Sign in to track this: tick each step off and it counts toward your week.

Exercises

This section has 31 exercises, rated 10 to M40, and Knuth marks 9 of them with the triangle for recommended. Pair each exercise with an experiment in your language's doubles; the point of this section is to stop trusting algebra that floating point does not obey.

Worth your time

  • Exercise 3M20

    Find concrete numbers where floating multiplication is not associative.

    Discuss

  • Exercise 410

    Can regrouping a product change whether it overflows?

    Discuss

  • Exercise 820▶ Recommended

    Apply the approximate-equality relations to concrete pairs. Builds intuition for tolerance comparisons.

    Discuss

  • Exercise 13M25▶ Recommended

    Doing exact integer arithmetic on top of floating point and when it stays exact.

    Discuss

  • Exercise 15M24▶ Recommended

    Does the computed midpoint of an interval always lie inside it? Classic binary-search trap.

    Discuss

  • Exercise 19M30▶ Recommended

    Error analysis of Kahan's compensated summation. The stretch, and worth implementing.

    Discuss

  • Exercise 23M26▶ Recommended

    Check an identity about rounding down that looks obviously true.

    Discuss

  • Exercise 2515▶ Recommended

    Why blaming cancellation is usually blaming the wrong step.

    Discuss

Your log

Sign in to log the exercises you work: number, rating, how far you got.

Your notes

Only you

Sign in to keep private notes on this guide, in Markdown. They stay yours: never on your profile, and you can export them all.

Discussion

0 posts

Questions about the reading go here; each exercise has its own thread below. Hints over answers.

No posts yet. Ask a question or share a tip.

Sign in to postAnyone can read. Posting needs an account with a confirmed email.

Exercise threads

One thread per exercise. Open one to ask for a nudge or check your thinking.

  • Exercise 3M20No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 410No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 820No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 13M25No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 15M24No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 19M30No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 23M26No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 2515No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

Reference

Why it matters

This is the section that teaches you why summing an array in a different order changes the answer, and how to write numeric code that does not drift.

Before you start
  • 4.2.1 Single-Precision Calculations
How to approach it

Write programs that demonstrate non-associativity and catastrophic cancellation. Implement Kahan compensated summation (widely documented) and compare to naive summation.

Common traps
  • Comparing floats with == in tests.

Spot a mistake? Report it

Back to week 76