TAOCP Vol 2: Seminumerical Algorithms · Week 70
TAOCP 3.3.4 The Spectral Test
Updated
Summary
TAOCP 3.3.4 The Spectral Test: The most important test for LCGs: in t dimensions, successive tuples from an LCG lie on a set of parallel hyperplanes, and the spectral test measures how far apart those planes are. Budget about 9 hours; do exercises 1, 8 and 4.
Knuth gives an algorithm to compute it and tables of good and bad multipliers.
See it
All visualsStep through at your own pace; the arrow keys work too.
Each dot is a pair (Xn, Xn+1)
Xn+1 = (a·Xn + c) mod m
(137·221 + 187) mod 256 = 0
Sequence
1361312146513295146221
Period 256 of a possible 256
Theorem A: a full period needs all three
- c and m share no factor (gcd 1): yes
- a − 1 is divisible by every prime of m (2): yes
- a − 1 is a multiple of 4, since 4 divides m: yes
X256 = 0 was seen before, so the period is 256, the full modulus, and every pair lies on a few parallel lines whose spacing the spectral test measures.
This week's steps
3 stepsRead §3.3.4 The Spectral Test
Before reading, plot (X_n, X_{n+1}) for a small LCG and see the lines.
Start with Ex 1, Ex 8, Ex 4; 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 32 exercises, rated M10 to HM47, and Knuth marks 7 of them with the triangle for recommended. Implementing Algorithm S and running it on a few famous multipliers is the best use of this week; exercise 14 is the warm-up for that.
Worth your time
Exercise 4M23▶ Recommended
The two-dimensional lattice basis behind the test. The geometry in miniature.
Exercise 8M16
How bad two-dimensional accuracy can be while three-dimensional accuracy stays fine.
Exercise 15M20▶ Recommended
Count how many parallel hyperplanes cut the unit cube. Connects the abstract number to the picture.
Exercise 24M28▶ Recommended
Extend the spectral test to second-order recurrences. The stretch.
Exercise 32M21▶ Recommended
Show that a well-known combined generator is close to one big linear congruential generator, so the spectral test applies to it.
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 1M10No 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 4M23No 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 8M16No 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 1424No 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 15M20No 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 21M20No 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 24M28No 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 32M21No 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 explains disasters like IBM's RANDU, whose triples fall on just 15 planes. It is the reason you should not trust a generator just because its 1D histogram looks flat.
Before you start
- 3.2.1 The Linear Congruential Method
- Basic linear algebra (vectors, dot products)
How to approach it
Before reading, plot (X_n, X_{n+1}) for a small LCG and see the lines. Plot RANDU triples in 3D. Then read the spectral test algorithm for the ideas. Following every step of the algorithm is optional.
Common traps
- Getting lost in lattice-reduction details. The picture is what matters.