Skip to main content

Exercises — Module 12 (The Spectral Test)

Self-contained problems on this module's material — the monotonicity of νt\nu_t, 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 t≤3t \le 3 build; if you own Volume 2, the exercises of §3.3.4 continue the story (several assume the full Algorithm S).

Tracking​

#TopicRatingStatus
1▶ Monotonicity νt+1≤νt\nu_{t+1} \le \nu_t: pad with a zeroM10⬜
2The increment-translation proof, in fullM18⬜
3Plane count N+P−1N + P - 1; the hidden assumptionM22⬜
4▶ Gauss–Lagrange optimality, every inequalityM24⬜
5Instrument Algorithm C; the 4/34/3 doubling bound22⬜
6▶ Certified search at t=4t = 4; RANDU's ν4\nu_430⬜
7A mini Fishman–Moore search for m=231−1m = 2^{31} - 1M28⬜

Problems​

1. ▶ Monotonicity νt+1≤νt\nu_{t+1} \le \nu_t: 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,}.Provethat. Prove that \nu_{t+1} \le \nu_tforeverymultiplierfor every multiplieraandmodulusand modulusm$ — so a generator's spectral quality can only degrade as the dimension grows.

Hint. Take a shortest dual vector in dimension tt and append a zero coordinate. Is the result a legal dual vector in dimension t+1t + 1, and what is its length?

Answer sketch. Let u=(u1,…,ut)u = (u_1, \ldots, u_t) achieve the minimum, so u1+au2+⋯+at−1ut≡0(modm)u_1 + a u_2 + \cdots + a^{t-1}u_t \equiv 0 \pmod m, u≠0u \ne 0, and ∥u∥2=νt2\|u\|^2 = \nu_t^2. Pad it: u′=(u1,…,ut,0)u' = (u_1, \ldots, u_t, 0). Its dual condition in dimension t+1t + 1 is u1+au2+⋯+at−1ut+at⋅0≡0(modm)u_1 + a u_2 + \cdots + a^{t-1}u_t + a^t\cdot 0 \equiv 0 \pmod m — the same congruence, already satisfied. And u′≠0u' \ne 0 with ∥u′∥2=∥u∥2=νt2\|u'\|^2 = \|u\|^2 = \nu_t^2. Since νt+12\nu_{t+1}^2 is the minimum over all dimension-(t+1)(t+1) dual vectors, it is at most this one: νt+12≤νt2\nu_{t+1}^2 \le \nu_t^2. ■\blacksquare Sanity check against the lesson's Table 1: the toy generator has ν22=274\nu_2^2 = 274, ν32=30\nu_3^2 = 30 (30≤27430 \le 274); RANDU has ν22=2 147 221 514\nu_2^2 = 2\,147\,221\,514, ν32=118\nu_3^2 = 118 (118≤ν22118 \le \nu_2^2). The moral: passing the test in low dimensions guarantees nothing higher up — you must test every tt your application consumes.

2. The increment-translation proof, in full (rating M18 · cf. W2)​

Problem. The lesson works with c=0c = 0 throughout, claiming the increment merely translates the point set and so changes no νt\nu_t. Prove it rigorously. Compare the sequence xn+1=(axn+c) mod mx_{n+1} = (a x_n + c) \bmod m with the c=0c = 0 sequence from the same x0x_0, and show every tt-tuple Pn(c)P_n(c) equals a lattice point plus one fixed vector wtw_t independent of nn. Exhibit wtw_t explicitly.

Hint. Write Sj=aj−1+⋯+a+1S_j = a^{j-1} + \cdots + a + 1 (so S0=0S_0 = 0). Prove the splitting identity Sn+j=ajSn+SjS_{n+j} = a^j S_n + S_j, then express coordinate jj of Pn(c)P_n(c) in terms of the tuple's own leading value xn(c)x_n(c).

Answer sketch. By induction, xn(c)=anx0+Snc(modm)x_n(c) = a^n x_0 + S_n c \pmod m. Coordinate jj (0≤j≤t−10 \le j \le t-1) of the tuple starting at position nn is xn+j(c)=an+jx0+Sn+jcx_{n+j}(c) = a^{n+j}x_0 + S_{n+j}c. Using Sn+j=ajSn+SjS_{n+j} = a^j S_n + S_j (proved by splitting the sum an+j−1+⋯+1a^{n+j-1} + \cdots + 1 at the term aja^j),

xn+j(c)=aj(anx0+Snc)+Sjc=aj xn(c)+Sjc(modm).x_{n+j}(c) = a^j\big(a^n x_0 + S_n c\big) + S_j c = a^j\, x_n(c) + S_j c \pmod m.

Therefore, with v=(1,a,a2,…,at−1)v = (1, a, a^2, \ldots, a^{t-1}),

Pn(c)=xn(c)⋅v+wt(modm),wt=(S0c, S1c, …, St−1c)=(0, c, (a+1)c, (a2+a+1)c, …).P_n(c) = x_n(c)\cdot v + w_t \pmod m, \qquad w_t = (S_0 c,\, S_1 c,\, \ldots,\, S_{t-1}c) = (0,\, c,\, (a+1)c,\, (a^2+a+1)c,\, \ldots).

The first term xn(c)⋅vx_n(c)\cdot v is a lattice point (as nn varies, xn(c)x_n(c) runs through the same residues the c=0c = 0 sequence does), and wtw_t is a single fixed vector — verified numerically: for a=3,m=100,c=7a = 3, m = 100, c = 7, one finds w3=(0,7,28)w_3 = (0, 7, 28) and Pn(c)=xn(c)v+w3(modm)P_n(c) = x_n(c)v + w_3 \pmod m for every nn. So the whole cc-point-set is the c=0c = 0 set rigidly translated by wtw_t. Translations move no inter-point spacings and shift plane families bodily without changing their count or separation, so every quantity the spectral test measures — νt\nu_t, plane counts, gaps — is independent of cc. ■\blacksquare

3. Plane count N+P−1N + P - 1; the hidden assumption (rating M22 · cf. W3)​

Problem. A dual vector uu with entries of both signs cuts the point set with the family of parallel planes u⋅x=kmu \cdot x = km. Split uu into positive and negative parts, P=∑ui>0uiP = \sum_{u_i > 0} u_i and N=∑ui<0∣ui∣N = \sum_{u_i < 0} |u_i|. Prove that exactly N+P−1N + P - 1 of these planes meet the cube [0,m)t[0, m)^t. Then identify the assumption the counting argument quietly relies on, and confirm the count for RANDU's u=(9,−6,1)u = (9, -6, 1).

Hint. Bound the linear form u⋅xu \cdot x over x∈[0,m)tx \in [0, m)^t; its extreme values are attained by pushing each coordinate to 00 or m−1m - 1 according to the sign of uiu_i. The planes are indexed by the integers k=(u⋅x)/mk = (u\cdot x)/m inside that range.

Answer sketch. For x∈[0,m)tx \in [0, m)^t, each coordinate xi∈{0,…,m−1}x_i \in \{0, \ldots, m-1\}, so u⋅xu \cdot x is maximized by setting xi=m−1x_i = m - 1 where ui>0u_i > 0 and xi=0x_i = 0 where ui<0u_i < 0, giving (m−1)P(m-1)P; it is minimized symmetrically at −(m−1)N-(m-1)N. Thus

−(m−1)N ≤ u⋅x ≤ (m−1)P.-(m-1)N \ \le\ u\cdot x \ \le\ (m-1)P.

A covering plane has index k=(u⋅x)/mk = (u\cdot x)/m, so kk ranges over the integers in [−(m−1)N/m, (m−1)P/m][-(m-1)N/m,\ (m-1)P/m]. Since (m−1)N/m<N(m-1)N/m < N and (m−1)P/m<P(m-1)P/m < P, the integer kk runs from −(N−1)-(N-1) to P−1P - 1 inclusive — that is (N−1)+(P−1)+1=N+P−1(N - 1) + (P - 1) + 1 = N + P - 1 values. Hidden assumption: each of those N+P−1N + P - 1 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 gcd⁡\gcd of the uiu_i can be taken 11 for a shortest dual vector, making u⋅x=kmu\cdot x = km solvable in the cube for each admissible kk. For RANDU, u=(9,−6,1)u = (9, -6, 1) gives P=10P = 10, N=6N = 6, so N+P−1=15N + P - 1 = 15 planes carry all 2292^{29} triples — at most ∣9∣+∣6∣+∣1∣=16|9| + |6| + |1| = 16, and one fewer because both signs are present. Fifteen gaping slabs in a cube 2312^{31} 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-22 dual basis v1=(m,0)v_1 = (m, 0), v2=(−a,1)v_2 = (-a, 1) until ∥v1∥≥∥v2∥\|v_1\| \ge \|v_2\| and ∣v1⋅v2∣≤∥v2∥2/2|v_1 \cdot v_2| \le \|v_2\|^2/2, then declares v2v_2 shortest. Fill in every inequality of the optimality proof: show that any nonzero lattice vector w=αv1+βv2w = \alpha v_1 + \beta v_2 (α,β∈Z\alpha, \beta \in \mathbb{Z}) has ∥w∥≥∥v2∥\|w\| \ge \|v_2\|. Then confirm the hand trace on a=137a = 137, m=256m = 256, and explain where integrality is load-bearing.

Hint. The cross case (α,β\alpha, \beta both nonzero) reduces to showing α2−∣αβ∣+β2≥1\alpha^2 - |\alpha\beta| + \beta^2 \ge 1 for nonzero integers. Complete the square.

Answer sketch. At termination two facts hold: ∥v1∥≥∥v2∥\|v_1\| \ge \|v_2\| (from the ordering step), and ∣v1⋅v2∣≤∥v2∥2/2|v_1\cdot v_2| \le \|v_2\|^2/2 (from rounding the shear coefficient to the nearest integer). Take w=αv1+βv2w = \alpha v_1 + \beta v_2, w≠0w \ne 0. If β=0\beta = 0: ∥w∥=∣α∣ ∥v1∥≥∥v2∥\|w\| = |\alpha|\,\|v_1\| \ge \|v_2\|. If α=0\alpha = 0: ∥w∥=∣β∣ ∥v2∥≥∥v2∥\|w\| = |\beta|\,\|v_2\| \ge \|v_2\|. Otherwise,

∥w∥2=α2∥v1∥2+2αβ(v1⋅v2)+β2∥v2∥2≥α2∥v2∥2−2∣α∣∣β∣⋅12∥v2∥2+β2∥v2∥2=(α2−∣α∣∣β∣+β2)∥v2∥2,\begin{aligned} \|w\|^2 &= \alpha^2\|v_1\|^2 + 2\alpha\beta(v_1\cdot v_2) + \beta^2\|v_2\|^2 \\ &\ge \alpha^2\|v_2\|^2 - 2|\alpha||\beta|\cdot\tfrac12\|v_2\|^2 + \beta^2\|v_2\|^2 = \big(\alpha^2 - |\alpha||\beta| + \beta^2\big)\|v_2\|^2, \end{aligned}

using ∥v1∥2≥∥v2∥2\|v_1\|^2 \ge \|v_2\|^2 and ∣v1⋅v2∣≤∥v2∥2/2|v_1\cdot v_2| \le \|v_2\|^2/2. Finally $\alpha^2 - |\alpha||\beta| + \beta^2 = \tfrac12\big((|\alpha|-|\beta|)^2 + \alpha^2

  • \beta^2\big) \ge 1fornonzerointegersfor nonzero integers\alpha, \beta(thebracketisasumofsquares,atleast(the bracket is a sum of squares, at least2).Hence). Hence |w| \ge |v_2|:: v_2isgenuinelyshortest.is genuinely shortest.\blacksquareThehandtraceconfirmsThe hand trace confirms\nu_2^2(137, 256) = 274withshortestvectorwith shortest vector(7, -15)(threereductionpasses,reproducedbythelab).∗∗Integralityisload−bearing∗∗inthefinalstep:overthereals(three reduction passes, reproduced by the lab). **Integrality is load-bearing** in the final step: over the reals\alpha = \beta = \tfrac12makesmakes\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 4/34/3 doubling bound (rating 22 · cf. W5)​

Problem. Algorithm C finds ν32\nu_3^2 by scanning (u2,u3)∈[−B,B]2(u_2, u_3) \in [-B, B]^2, doubling BB until B2≥bestB^2 \ge \text{best}. Instrument it: report the final BB and the total number of scanned cells for RANDU (a=65539a = 65539, m=231m = 2^{31}), 1680716807, and 4827148271 (both mod 231−12^{31} - 1). Then check the claim that the doubling schedule costs at most 43\tfrac43 of the final scan alone.

Hint. The scan at bound BB visits (2B+1)2−1(2B+1)^2 - 1 cells (excluding (0,0)(0,0)). Summed over B=1,2,4,…,BfinalB = 1, 2, 4, \ldots, B_{\text{final}}, consecutive terms grow by roughly 4×4\times, so the geometric series is ≤43\le \tfrac{4}{3} of the last term — asymptotically.

Answer sketch. Measured (reproduced by the lab's instrumentation):

generatorν32\nu_3^2final BBtotal cellsfinal scanratio
RANDU118118161614881488108810881.3681.368
1680716807408 197408\,197102410245 600 5925\,600\,5924 198 4004\,198\,4001.3341.334
48271482711 433 8811\,433\,8812048204822 386 00022\,386\,00016 785 40816\,785\,4081.3341.334

The bound comes from the geometric series: cells at bound BB number ≈4B2\approx 4B^2, and ∑k=0K4k=4K+1−13≈43⋅4K\sum_{k=0}^{K} 4^k = \tfrac{4^{K+1}-1}{3} \approx \tfrac43\cdot 4^K, so total work ≤43\le \tfrac43 of the final scan in the leading term. The two large searches sit right at 1.334≈431.334 \approx \tfrac43. RANDU comes in slightly over (1.3681.368) because its search certifies at a tiny B=16B = 16, where the lower-order +1+1 in (2B+1)2(2B+1)^2 has not yet washed out — an honest reminder that 43\tfrac43 is the asymptotic constant, not a hard cap at small BB. Either way the cost is dominated by the last scan, exactly the table-doubling accounting from earlier modules.

6. ▶ Certified search at t=4t = 4; RANDU's ν4\nu_4 (rating 30 · cf. W6)​

Problem. Extend Algorithm C to t=4t = 4: scan (u2,u3,u4)∈[−B,B]3(u_2, u_3, u_4) \in [-B, B]^3, pin u1u_1 to the centered residue of −(au2+a2u3+a3u4) mod m-(a u_2 + a^2 u_3 + a^3 u_4) \bmod m, and certify with the same B2≥bestB^2 \ge \text{best} test (Hermite's γ4=2\gamma_4 = \sqrt2 guarantees termination). Estimate the cost from the Hermite bound, then compute ν42\nu_4^2 for RANDU. Is it just the padded value from t=3t = 3?

Hint. The dimension-33 shortest dual vector (9,−6,1)(9, -6, 1) pads to (9,−6,1,0)(9, -6, 1, 0), a legal dimension-44 dual vector of squared length 118118 (Problem 1). So ν42≤118\nu_4^2 \le 118 — but the true minimum could be smaller.

Answer sketch. Hermite gives ν42≤γ4 m1/2=2⋅(231)1/2=65536\nu_4^2 \le \gamma_4\, m^{1/2} = \sqrt2\cdot (2^{31})^{1/2} = 65536 for RANDU, so once B≥256B \ge 256 (here B2≥65536B^2 \ge 65536) the scan is certified; in fact RANDU certifies at B=16B = 16. The computed value is

ν42(RANDU)=116,\nu_4^2(\text{RANDU}) = 116,

strictly below the padded 118118: the witness u=(−9,−3,5,−1)u = (-9, -3, 5, -1) satisfies −9−3a+5a2−a3≡0(mod231)-9 - 3a + 5a^2 - a^3 \equiv 0 \pmod{2^{31}} and has squared length 81+9+25+1=11681 + 9 + 25 + 1 = 116. So padding the t=3t = 3 optimum gives only an upper bound (consistent with ν4≤ν3\nu_4 \le \nu_3, i.e. 116≤118116 \le 118); the extra dimension opens a genuinely shorter direction that the t=3t = 3 search could not see. This is why each dimension must be searched afresh — and why Knuth's Algorithm S transforms the basis as tt grows rather than reusing lower-tt answers.

7. A mini Fishman–Moore search for m=231−1m = 2^{31} - 1 (rating M28 · cf. W7)​

Problem. The multiplier 4827148271 was found by an exhaustive spectral search (Fishman–Moore style) over multipliers for the Mersenne modulus m=231−1m = 2^{31} - 1. Reproduce the method in miniature: for a range of candidate multipliers aa (coprime to mm), compute μ2=π ν22/m\mu_2 = \pi\,\nu_2^2/m and μ3=43π ν33/m\mu_3 = \tfrac43\pi\, \nu_3^3/m and rank by the figure of merit min⁡(μ2,μ3)\min(\mu_2, \mu_3). How close to 4827148271-quality can you get?

Hint. ν22\nu_2^2 comes from Algorithm G (fast); ν32\nu_3^2 from Algorithm C (slower). Knuth's rule of thumb: μt≥0.1\mu_t \ge 0.1 passes, μt≥1\mu_t \ge 1 is excellent. Because ν3\nu_3 dominates the cost, screen candidates on μ2\mu_2 first and only compute μ3\mu_3 for survivors.

Answer sketch. Evaluating a handful of named multipliers reproduces the verdicts of the lesson's Table 1 and shows the search works:

aaμ2\mu_2μ3\mu_3min⁡(μ2,μ3)\min(\mu_2, \mu_3)
16807168070.410.410.510.510.410.41 (passes, unspectacular)
48271482712.912.913.353.352.912.91 (excellent)
7429382857429382852.732.733.783.782.732.73 (excellent)

A full exhaustive sweep of all aa in a wide band, ranked by min⁡(μ2,μ3)\min(\mu_2, \mu_3), is the term-project version (hence M28): it must skip aa with gcd⁡(a,m)≠1\gcd(a, m) \ne 1, prune early on μ2\mu_2, and — because ν3\nu_3 is costly per candidate — parallelize or restrict to a smart sub-band, which is precisely what Fishman and Moore did in 1986 to certify 4827148271 as a best-in-class multiplier for this modulus. The takeaway that the search makes concrete: 1680716807 and 4827148271 cost the same to evaluate at runtime, yet 4827148271 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.