TAOCP Vol 2: Seminumerical Algorithms · Week 76
TAOCP 4.2.2 Accuracy of Floating Point Arithmetic
Updated
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.
This week's steps
3 stepsRead §4.2.2 Accuracy of Floating Point Arithmetic
Write programs that demonstrate non-associativity and catastrophic cancellation.
Start with Ex 4, Ex 3, Ex 8; log what you solve below.
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 820▶ Recommended
Apply the approximate-equality relations to concrete pairs. Builds intuition for tolerance comparisons.
Exercise 13M25▶ Recommended
Doing exact integer arithmetic on top of floating point and when it stays exact.
Exercise 15M24▶ Recommended
Does the computed midpoint of an interval always lie inside it? Classic binary-search trap.
Exercise 19M30▶ Recommended
Error analysis of Kahan's compensated summation. The stretch, and worth implementing.
Your log
Sign in to log the exercises you work: number, rating, how far you got.
Your notes
Only youSign 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 postsQuestions 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```spoilerblock.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```spoilerblock.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```spoilerblock.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```spoilerblock.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```spoilerblock.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```spoilerblock.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```spoilerblock.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```spoilerblock.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.