Exercises — Module 12 (The Spectral Test)
Self-contained problems on this module's material — the monotonicity of , the increment translation, plane counting, Gauss–Lagrange optimality, Algorithm C's certified search, and spectral figures of merit. You can work every one without the books: each states the problem in full, gives a hint to peek at when stuck, and a worked answer sketch to check against after you try. Computational answers here are reproduced by the code you write in the lab (or a few lines at a REPL).
Ratings follow Knuth's scale (00–50; M = needs mathematics, ▶ = especially
instructive). The W-numbers are this course's curated set for the
build; if you own Volume 2, the exercises of §3.3.4 continue the story (several
assume the full Algorithm S).
Tracking
| # | Topic | Rating | Status |
|---|---|---|---|
| 1 | ▶ Monotonicity : pad with a zero | M10 | ⬜ |
| 2 | The increment-translation proof, in full | M18 | ⬜ |
| 3 | Plane count ; the hidden assumption | M22 | ⬜ |
| 4 | ▶ Gauss–Lagrange optimality, every inequality | M24 | ⬜ |
| 5 | Instrument Algorithm C; the doubling bound | 22 | ⬜ |
| 6 | ▶ Certified search at ; RANDU's | 30 | ⬜ |
| 7 | A mini Fishman–Moore search for | M28 | ⬜ |
Problems
1. ▶ Monotonicity : pad with a zero (rating M10 · cf. W1)
Problem. Recall $\nu_t^2 = \min{,u_1^2 + \cdots + u_t^2 : u_1 + a u_2 + \cdots
- a^{t-1}u_t \equiv 0 \pmod{m},\ u \ne 0,}\nu_{t+1} \le \nu_tam$ — so a generator's spectral quality can only degrade as the dimension grows.
Hint. Take a shortest dual vector in dimension and append a zero coordinate. Is the result a legal dual vector in dimension , and what is its length?
Answer sketch. Let achieve the minimum, so , , and . Pad it: . Its dual condition in dimension is — the same congruence, already satisfied. And with . Since is the minimum over all dimension- dual vectors, it is at most this one: . Sanity check against the lesson's Table 1: the toy generator has , (); RANDU has , (). The moral: passing the test in low dimensions guarantees nothing higher up — you must test every your application consumes.
2. The increment-translation proof, in full (rating M18 · cf. W2)
Problem. The lesson works with throughout, claiming the increment merely translates the point set and so changes no . Prove it rigorously. Compare the sequence with the sequence from the same , and show every -tuple equals a lattice point plus one fixed vector independent of . Exhibit explicitly.
Hint. Write (so ). Prove the splitting identity , then express coordinate of in terms of the tuple's own leading value .
Answer sketch. By induction, . Coordinate () of the tuple starting at position is . Using (proved by splitting the sum at the term ),
Therefore, with ,
The first term is a lattice point (as varies, runs through the same residues the sequence does), and is a single fixed vector — verified numerically: for , one finds and for every . So the whole -point-set is the set rigidly translated by . Translations move no inter-point spacings and shift plane families bodily without changing their count or separation, so every quantity the spectral test measures — , plane counts, gaps — is independent of .
3. Plane count ; the hidden assumption (rating M22 · cf. W3)
Problem. A dual vector with entries of both signs cuts the point set with the family of parallel planes . Split into positive and negative parts, and . Prove that exactly of these planes meet the cube . Then identify the assumption the counting argument quietly relies on, and confirm the count for RANDU's .
Hint. Bound the linear form over ; its extreme values are attained by pushing each coordinate to or according to the sign of . The planes are indexed by the integers inside that range.
Answer sketch. For , each coordinate , so is maximized by setting where and where , giving ; it is minimized symmetrically at . Thus
A covering plane has index , so ranges over the integers in . Since and , the integer runs from to inclusive — that is values. Hidden assumption: each of those candidate planes actually contains an integer point of the cube (otherwise it would not "meet" the point set and the count would be an over-estimate). This holds because of the can be taken for a shortest dual vector, making solvable in the cube for each admissible . For RANDU, gives , , so planes carry all triples — at most , and one fewer because both signs are present. Fifteen gaping slabs in a cube cells on a side: Marsaglia's title was not hyperbole.
4. ▶ Gauss–Lagrange optimality, every inequality (rating M24 · cf. W4)
Problem. Algorithm G reduces the rank- dual basis , until and , then declares shortest. Fill in every inequality of the optimality proof: show that any nonzero lattice vector () has . Then confirm the hand trace on , , and explain where integrality is load-bearing.
Hint. The cross case ( both nonzero) reduces to showing for nonzero integers. Complete the square.
Answer sketch. At termination two facts hold: (from the ordering step), and (from rounding the shear coefficient to the nearest integer). Take , . If : . If : . Otherwise,
using and . Finally $\alpha^2 - |\alpha||\beta| + \beta^2 = \tfrac12\big((|\alpha|-|\beta|)^2 + \alpha^2
- \beta^2\big) \ge 1\alpha, \beta2|w| \ge |v_2|v_2\blacksquare\nu_2^2(137, 256) = 274(7, -15)\alpha = \beta = \tfrac12\alpha^2 - |\alpha||\beta| + \beta^2 = \tfrac14 < 1$, so the argument collapses — which is exactly why shortest-vector is a hard discrete optimization while its continuous relaxation (linear algebra) is trivial.
5. Instrument Algorithm C; the doubling bound (rating 22 · cf. W5)
Problem. Algorithm C finds by scanning , doubling until . Instrument it: report the final and the total number of scanned cells for RANDU (, ), , and (both mod ). Then check the claim that the doubling schedule costs at most of the final scan alone.
Hint. The scan at bound visits cells (excluding ). Summed over , consecutive terms grow by roughly , so the geometric series is of the last term — asymptotically.
Answer sketch. Measured (reproduced by the lab's instrumentation):
| generator | final | total cells | final scan | ratio | |
|---|---|---|---|---|---|
| RANDU | |||||
The bound comes from the geometric series: cells at bound number , and , so total work of the final scan in the leading term. The two large searches sit right at . RANDU comes in slightly over () because its search certifies at a tiny , where the lower-order in has not yet washed out — an honest reminder that is the asymptotic constant, not a hard cap at small . Either way the cost is dominated by the last scan, exactly the table-doubling accounting from earlier modules.
6. ▶ Certified search at ; RANDU's (rating 30 · cf. W6)
Problem. Extend Algorithm C to : scan , pin to the centered residue of , and certify with the same test (Hermite's guarantees termination). Estimate the cost from the Hermite bound, then compute for RANDU. Is it just the padded value from ?
Hint. The dimension- shortest dual vector pads to , a legal dimension- dual vector of squared length (Problem 1). So — but the true minimum could be smaller.
Answer sketch. Hermite gives for RANDU, so once (here ) the scan is certified; in fact RANDU certifies at . The computed value is
strictly below the padded : the witness satisfies and has squared length . So padding the optimum gives only an upper bound (consistent with , i.e. ); the extra dimension opens a genuinely shorter direction that the search could not see. This is why each dimension must be searched afresh — and why Knuth's Algorithm S transforms the basis as grows rather than reusing lower- answers.
7. A mini Fishman–Moore search for (rating M28 · cf. W7)
Problem. The multiplier was found by an exhaustive spectral search (Fishman–Moore style) over multipliers for the Mersenne modulus . Reproduce the method in miniature: for a range of candidate multipliers (coprime to ), compute and and rank by the figure of merit . How close to -quality can you get?
Hint. comes from Algorithm G (fast); from Algorithm C (slower). Knuth's rule of thumb: passes, is excellent. Because dominates the cost, screen candidates on first and only compute for survivors.
Answer sketch. Evaluating a handful of named multipliers reproduces the verdicts of the lesson's Table 1 and shows the search works:
| (passes, unspectacular) | |||
| (excellent) | |||
| (excellent) |
A full exhaustive sweep of all in a wide band, ranked by , is the term-project version (hence M28): it must skip with , prune early on , and — because is costly per candidate — parallelize or restrict to a smart sub-band, which is precisely what Fishman and Moore did in 1986 to certify as a best-in-class multiplier for this modulus. The takeaway that the search makes concrete: and cost the same to evaluate at runtime, yet is an order of magnitude better in three dimensions — spectral vetting, not folklore, is why the standard was revised.
Your solutions
Use this space to log your own work — a restated problem, your approach, and how it compared with the sketch above.
Exercise N (rating RR)
Approach. Answer / proof. Compared with the sketch: what you did differently, what you missed.