The toy Harvey-van der Hoeven scheme returns the product full
This proof shows: correctness, termination.
This proof is for the exact toy of the page: distinct primes s1,…,sd, S=s1⋯sd, a prime q≡1(modS), limbs of b bits and β=2b. It does not cover Gaussian resampling or the complex arithmetic of the paper, whose analysis is in Harvey and van der Hoeven's Sections 4 and 5.
Termination. Every loop of the toy runs over a finite range: d dimensions, S cells, s−1 convolution indices. PRIME-DFT is not recursive, and DFTd calls it ∑iS/si times.
Lemma 1 (the cell map). The map κ(j)=(jmods1,…,jmodsd) is a bijection from {0,…,S−1} to ∏i{0,…,si−1}, and κ(j+j′)=κ(j)+κ(j′) with addition in each coordinate modulo si, for every j,j′, where j+j′ is read modulo S.
Proof. The si are distinct primes, hence pairwise coprime, so by the Chinese remainder theorem Z/S→∏iZ/si, j↦(jmodsi)i, is a group isomorphism. Both sets have S elements. □
Lemma 2 (Rader). Let s be prime, g a generator of (Z/s)× and ω an element of Zq with ωs=1. Lines L10 to L12 return Xk=∑n<sxnωnk for every 0≤k<s.
Proof. For k=0, X0=∑nxn, line L10. For s=2 the code passes ω=−1, the primitive square root of unity, which is its own inverse, and returns (x0+x1,x0−x1), which is the DFT. For s>2, each k=0 is g−pmods for exactly one p∈{0,…,s−2}, and each n=0 is gmmods for exactly one m, since g generates a cyclic group of order s−1. Then
Xg−p=x0+m=0∑s−2xgmωgm−p=x0+m=0∑s−2amc(p−m)mod(s−1), with am=xgm and ck=ωg−k, because ωe depends only on emods and gm−p=g−(p−m), where the exponent of g can be read modulo s−1. The last sum is entry p of the cyclic convolution of a and c, line L11, and line L12 stores x0+cp at g−p. □
Lemma 3 (DFTd). For an array A indexed by (j1,…,jd) with 0≤ji<si, DFTd(A,σ) returns
A^(k1,…,kd)=j1,…,jd∑A(j1,…,jd)i∏ωiσjiki. Proof. After the pass i of line L7, the array holds the transform in the first i coordinates: this holds for i=0, and the pass i applies, by Lemma 2, the one-dimensional DFT with root ωiσ to every line along coordinate i, which multiplies by ωiσjiki and sums over ji with the other coordinates fixed. The kernel is a product of one-dimensional kernels, so the d passes give A^. □
Lemma 4 (inversion and convolution). If ωi is a primitive si-th root of unity for each i, then DFTd(DFTd(A,+1),−1)=S⋅A, and DFTd(F^⋅G^,−1)/S is the cyclic convolution H(ℓ)=∑j+j′=ℓF(j)G(j′), with j+j′ taken coordinatewise modulo the si.
Proof. For a primitive s-th root ω and an integer e, ∑k<sωek is s if s∣e and 0 otherwise, since ωe=1 is a root of ∑k<szk in the field Zq. Expanding both claims with Lemma 3 gives products of these sums over the d coordinates, which are S when j=ℓ (resp. j+j′=ℓ) in each coordinate and 0 otherwise. □
Theorem. If 0≤u,v<β(S+1)/2 and 2S+1(β−1)2<q, then HVDH-TOY-MULTIPLY returns uv.
Proof. Line L1 writes u=∑j<Cfjβj and v=∑j<Cgjβj with C=(S+1)/2 and 0≤fj,gj<β, and sets fj=gj=0 for C≤j<S. Line L2 puts fj in the cell κ(j); by Lemma 1 each cell receives exactly one index. By Lemmas 3 and 4, after line L5 the cell κ(ℓ) holds ∑fjgj′ over the pairs with κ(j)+κ(j′)=κ(ℓ), which by Lemma 1 are the pairs with j+j′≡ℓ(modS). Since fjgj′=0 only for j,j′<C, we have j+j′≤2C−2=S−1, so the congruence is an equality, and the cell holds hℓ=∑j+j′=ℓfjgj′ reduced modulo q. This integer is a sum of at most C terms, each at most (β−1)2, so it is less than q and equals its residue. Line L6 computes ∑ℓhℓβℓ=∑j,j′fjgj′βj+j′=uv. ■