Algorithm Search⌘K

Proofs: Harvey-van der Hoeven multiplication

These are the human proofs of Harvey-van der Hoeven multiplication, at full length.

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,…,sds_1, \dots, s_d, S=s1⋯sdS = s_1 \cdots s_d, a prime q≡1(modS)q \equiv 1 \pmod S, limbs of bb bits and β=2b\beta = 2^b. 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: dd dimensions, SS cells, s−1s - 1 convolution indices. PRIME-DFT is not recursive, and DFTd_d calls it ∑iS/si\sum_i S/s_i times.

Lemma 1 (the cell map). The map κ(j)=(j mod s1,…,j mod sd)\kappa(j) = (j \bmod s_1, \dots, j \bmod s_d) is a bijection from {0,…,S−1}\{0, \dots, S - 1\} to ∏i{0,…,si−1}\prod_i \{0, \dots, s_i - 1\}, and κ(j+j′)=κ(j)+κ(j′)\kappa(j + j') = \kappa(j) + \kappa(j') with addition in each coordinate modulo sis_i, for every j,j′j, j', where j+j′j + j' is read modulo SS.

Proof. The sis_i are distinct primes, hence pairwise coprime, so by the Chinese remainder theorem Z/S→∏iZ/si\mathbb{Z}/S \to \prod_i \mathbb{Z}/s_i, j↦(j mod si)ij \mapsto (j \bmod s_i)_i, is a group isomorphism. Both sets have SS elements. □\square

Lemma 2 (Rader). Let ss be prime, gg a generator of (Z/s)×(\mathbb{Z}/s)^\times and ω\omega an element of Zq\mathbb{Z}_q with ωs=1\omega^s = 1. Lines L10 to L12 return Xk=∑n<sxnωnkX_k = \sum_{n < s} x_n \omega^{nk} for every 0≤k<s0 \le k < s.

Proof. For k=0k = 0, X0=∑nxnX_0 = \sum_n x_n, line L10. For s=2s = 2 the code passes ω=−1\omega = -1, the primitive square root of unity, which is its own inverse, and returns (x0+x1,x0−x1)(x_0 + x_1, x_0 - x_1), which is the DFT. For s>2s > 2, each k≠0k \ne 0 is g−p mod sg^{-p} \bmod s for exactly one p∈{0,…,s−2}p \in \{0, \dots, s - 2\}, and each n≠0n \ne 0 is gm mod sg^{m} \bmod s for exactly one mm, since gg generates a cyclic group of order s−1s - 1. Then

Xg−p=x0+∑m=0s−2xgm ωgm−p=x0+∑m=0s−2amc(p−m) mod (s−1),X_{g^{-p}} = x_0 + \sum_{m=0}^{s-2} x_{g^m}\, \omega^{g^{m - p}} = x_0 + \sum_{m=0}^{s-2} a_m c_{(p - m) \bmod (s - 1)},

with am=xgma_m = x_{g^m} and ck=ωg−kc_k = \omega^{g^{-k}}, because ωe\omega^e depends only on e mod se \bmod s and gm−p=g−(p−m)g^{m-p} = g^{-(p - m)}, where the exponent of gg can be read modulo s−1s - 1. The last sum is entry pp of the cyclic convolution of aa and cc, line L11, and line L12 stores x0+cpx_0 + c_p at g−pg^{-p}. □\square

Lemma 3 (DFTd_d). For an array AA indexed by (j1,…,jd)(j_1, \dots, j_d) with 0≤ji<si0 \le j_i < s_i, DFTd(A,σ)_d(A, \sigma) returns

A^(k1,…,kd)=∑j1,…,jdA(j1,…,jd)∏iωiσjiki.\hat A(k_1, \dots, k_d) = \sum_{j_1, \dots, j_d} A(j_1, \dots, j_d) \prod_i \omega_i^{\sigma j_i k_i}.

Proof. After the pass ii of line L7, the array holds the transform in the first ii coordinates: this holds for i=0i = 0, and the pass ii applies, by Lemma 2, the one-dimensional DFT with root ωiσ\omega_i^\sigma to every line along coordinate ii, which multiplies by ωiσjiki\omega_i^{\sigma j_i k_i} and sums over jij_i with the other coordinates fixed. The kernel is a product of one-dimensional kernels, so the dd passes give A^\hat A. □\square

Lemma 4 (inversion and convolution). If ωi\omega_i is a primitive sis_i-th root of unity for each ii, then DFTd(DFTd(A,+1),−1)=S⋅A_d(\mathrm{DFT}_d(A, +1), -1) = S \cdot A, and DFTd(F^⋅G^,−1)/S_d(\hat F \cdot \hat G, -1)/S is the cyclic convolution H(ℓ)=∑j+j′=ℓF(j)G(j′)H(\ell) = \sum_{j + j' = \ell} F(j) G(j'), with j+j′j + j' taken coordinatewise modulo the sis_i.

Proof. For a primitive ss-th root ω\omega and an integer ee, ∑k<sωek\sum_{k < s} \omega^{ek} is ss if s∣es \mid e and 0 otherwise, since ωe≠1\omega^e \ne 1 is a root of ∑k<szk\sum_{k < s} z^k in the field Zq\mathbb{Z}_q. Expanding both claims with Lemma 3 gives products of these sums over the dd coordinates, which are SS when j=ℓj = \ell (resp. j+j′=ℓj + j' = \ell) in each coordinate and 0 otherwise. □\square

Theorem. If 0≤u,v<β(S+1)/20 \le u, v < \beta^{(S+1)/2} and S+12(β−1)2<q\frac{S+1}{2}(\beta - 1)^2 < q, then HVDH-TOY-MULTIPLY returns uvuv.

Proof. Line L1 writes u=∑j<Cfjβju = \sum_{j < C} f_j \beta^j and v=∑j<Cgjβjv = \sum_{j < C} g_j \beta^j with C=(S+1)/2C = (S + 1)/2 and 0≤fj,gj<β0 \le f_j, g_j < \beta, and sets fj=gj=0f_j = g_j = 0 for C≤j<SC \le j < S. Line L2 puts fjf_j in the cell κ(j)\kappa(j); by Lemma 1 each cell receives exactly one index. By Lemmas 3 and 4, after line L5 the cell κ(ℓ)\kappa(\ell) holds ∑fjgj′\sum f_j g_{j'} over the pairs with κ(j)+κ(j′)=κ(ℓ)\kappa(j) + \kappa(j') = \kappa(\ell), which by Lemma 1 are the pairs with j+j′≡ℓ(modS)j + j' \equiv \ell \pmod S. Since fjgj′≠0f_j g_{j'} \ne 0 only for j,j′<Cj, j' < C, we have j+j′≤2C−2=S−1j + j' \le 2C - 2 = S - 1, so the congruence is an equality, and the cell holds hℓ=∑j+j′=ℓfjgj′h_\ell = \sum_{j + j' = \ell} f_j g_{j'} reduced modulo qq. This integer is a sum of at most CC terms, each at most (β−1)2(\beta - 1)^2, so it is less than qq and equals its residue. Line L6 computes ∑ℓhℓβℓ=∑j,j′fjgj′βj+j′=uv\sum_\ell h_\ell \beta^\ell = \sum_{j, j'} f_j g_{j'} \beta^{j + j'} = uv. ■\blacksquare

Back to Harvey-van der Hoeven multiplication