Algorithm Search⌘K

Proofs: Good-Thomas prime-factor FFT

These are the human proofs of Good-Thomas prime-factor FFT, at full length.

The Good-Thomas re-indexing turns a DFT with coprime factors into a multidimensional DFT without twiddle factors full

This proof shows: correctness, complexity, error-bound.

Let RR be a commutative ring, n=n1⋯nrn = n_1 \cdots n_r with the nin_i pairwise coprime, and ω∈R\omega \in R a principal nn-th root of unity: ωn=1\omega^n = 1 and ∑j=0n−1ωjl=0\sum_{j=0}^{n-1} \omega^{jl} = 0 for 1≤l≤n−11 \le l \le n - 1. Put Ni=n/niN_i = n/n_i and ei=Ni−1 mod nie_i = N_i^{-1} \bmod n_i. Define ι(j1,…,jr)=∑iNiji mod n\iota(j_1, \ldots, j_r) = \sum_i N_i j_i \bmod n (line L2) and κ(k1,…,kr)=∑iNieiki mod n\kappa(k_1, \ldots, k_r) = \sum_i N_i e_i k_i \bmod n (line L5), on tuples with 0≤ji,ki<ni0 \le j_i, k_i < n_i.

Lemma 1 (bijections). ι\iota and κ\kappa are bijections onto {0,…,n−1}\{0, \ldots, n - 1\}, and κ(k1,…,kr)≡ki(modni)\kappa(k_1, \ldots, k_r) \equiv k_i \pmod{n_i} for every ii.

Proof. For a≠ia \ne i, na∣Nin_a \mid N_i, so ι(j)≡Naja(modna)\iota(j) \equiv N_a j_a \pmod{n_a} and κ(k)≡Naeaka≡ka(modna)\kappa(k) \equiv N_a e_a k_a \equiv k_a \pmod{n_a}. Since gcd⁡(Na,na)=1\gcd(N_a, n_a) = 1, NaN_a is invertible modulo nan_a, so the residues of ι(j)\iota(j) modulo all nan_a determine jj, and those of κ(k)\kappa(k) are kk itself. By the Chinese remainder theorem a number in {0,…,n−1}\{0, \ldots, n - 1\} is determined by its residues modulo the nan_a, so both maps are injective, and both sets have nn elements. □\square

Lemma 2 (splitting the kernel). ωι(j)κ(k)=∏i=1r(ωNi)jiki\omega^{\iota(j) \kappa(k)} = \prod_{i=1}^{r} (\omega^{N_i})^{j_i k_i}.

Proof. Since ωn=1\omega^n = 1, exponents may be taken modulo nn. ι(j)κ(k)≡∑a,iNaNieijaki(modn)\iota(j) \kappa(k) \equiv \sum_{a, i} N_a N_i e_i j_a k_i \pmod n. For a≠ia \ne i, NaNiN_a N_i is a multiple of nn, since every nbn_b divides NaN_a or NiN_i and the nbn_b are pairwise coprime; so only the terms a=ia = i remain, and ωι(j)κ(k)=∏i(ωNi)Nieijiki\omega^{\iota(j)\kappa(k)} = \prod_i (\omega^{N_i})^{N_i e_i j_i k_i}. Now (ωNi)ni=1(\omega^{N_i})^{n_i} = 1 and Niei≡1(modni)N_i e_i \equiv 1 \pmod{n_i}, so (ωNi)Nieijiki=(ωNi)jiki(\omega^{N_i})^{N_i e_i j_i k_i} = (\omega^{N_i})^{j_i k_i}. □\square

Lemma 3 (axis roots). If nn is a unit of RR, then ωNi\omega^{N_i} is a principal nin_i-th root of unity. (Theorem 1 below does not need this; it matters when line L4 uses a fast short DFT, such as a radix-2 FFT, that requires a principal root.)

Proof. Let ζ=ωNi\zeta = \omega^{N_i}. Then ζni=ωn=1\zeta^{n_i} = \omega^n = 1. Fix 1≤l≤ni−11 \le l \le n_i - 1 and put T=∑m=0ni−1ζmlT = \sum_{m=0}^{n_i - 1} \zeta^{ml}. Writing j=qni+mj = q n_i + m with 0≤q<Ni0 \le q < N_i and 0≤m<ni0 \le m < n_i, and using ωqniNil=1\omega^{q n_i N_i l} = 1, we get ∑j=0n−1ωjNil=NiT\sum_{j=0}^{n-1} \omega^{j N_i l} = N_i T. The left side is 00 because 1≤Nil≤n−Ni<n1 \le N_i l \le n - N_i < n and ω\omega is principal. Since Nini=nN_i n_i = n is a unit, so is NiN_i, hence T=0T = 0. □\square

Theorem 1 (correctness). GOOD-THOMAS returns X=FnxX = F_n x, Xk=∑jxjωjkX_k = \sum_j x_j \omega^{jk}.

Proof. Line L2 sets A[j1,…,jr]=xι(j)A[j_1, \ldots, j_r] = x_{\iota(j)}. The loop of lines L3 and L4 applies, for i=1,…,ri = 1, \ldots, r, the DFT of length nin_i with the root ωNi\omega^{N_i} along the axis ii. These maps act on different indices and are linear, so after the loop

A[k1,…,kr]=∑j1,…,jrxι(j)∏i(ωNi)jiki=∑j1,…,jrxι(j) ωι(j)κ(k)A[k_1, \ldots, k_r] = \sum_{j_1, \ldots, j_r} x_{\iota(j)} \prod_i (\omega^{N_i})^{j_i k_i} = \sum_{j_1, \ldots, j_r} x_{\iota(j)} \, \omega^{\iota(j) \kappa(k)}

by Lemma 2. Since ι\iota is a bijection (Lemma 1), this is ∑j=0n−1xjωjκ(k)=Xκ(k)\sum_{j=0}^{n-1} x_j \omega^{j \kappa(k)} = X_{\kappa(k)}. Line L5 stores it at the index κ(k)\kappa(k), and since κ\kappa is a bijection, every entry of XX is written exactly once. □\square

Theorem 2 (inverse). If nn is a unit of RR, running GOOD-THOMAS with ω−1\omega^{-1} and multiplying by n−1n^{-1} returns xx from XX.

Proof. ω−1\omega^{-1} is a principal nn-th root (as in Theorem 2 of the FFT proof), so by Theorem 1 the procedure computes Yl=∑kXkω−lk=∑jxj∑kω(j−l)k=nxlY_l = \sum_k X_k \omega^{-lk} = \sum_j x_j \sum_k \omega^{(j - l)k} = n x_l, by the definition of a principal root. □\square

Operation count. Line L4 for the axis ii runs Ni=n/niN_i = n/n_i short DFTs. If each costs M(ni)M(n_i) multiplications and S(ni)S(n_i) additions, the total is n∑iM(ni)/nin \sum_i M(n_i)/n_i multiplications and n∑iS(ni)/nin \sum_i S(n_i)/n_i additions. Lines L2 and L5 are permutations, with no ring operations. The direct short DFT used by the implementation does (ni−1)2(n_i - 1)^2 multiplications by roots other than 11 and ni(ni−1)n_i(n_i - 1) additions, so the total is at most n∑i(ni−1)n \sum_i (n_i - 1) of each.

Theorem 3 (rounding error over C\mathbb{C}). Suppose ω=e−2πi/n\omega = e^{-2\pi i/n}, each computed root power r^\hat r has ∣r^−r∣≤μ|\hat r - r| \le \mu, complex products have relative error at most 2γ2\sqrt 2 \gamma_2 (Higham, Lemma 3.5), and the short DFTs are direct sums evaluated left to right. Then

∥X^−X∥2≤∑i=1rni (γni−1+2γ2+μ) ∥X∥2+O(u2).\lVert \hat X - X \rVert_2 \le \sum_{i=1}^{r} \sqrt{n_i} \, (\gamma_{n_i - 1} + \sqrt 2 \gamma_2 + \mu) \, \lVert X \rVert_2 + O(u^2).

Proof. Let ci=γni−1+2γ2+μc_i = \gamma_{n_i - 1} + \sqrt 2 \gamma_2 + \mu. Consider one short DFT of a line z∈Cmz \in \mathbb{C}^{m}, m=nim = n_i, with outputs Yk=∑lzlrlkY_k = \sum_l z_l r^{lk}, ∣r∣=1|r| = 1. Each product zlr^lkz_l \hat r^{lk} is computed with error at most (μ+2γ2)∣zl∣+O(u2)(\mu + \sqrt 2 \gamma_2)|z_l| + O(u^2), and the recursive sum of mm complex terms tlt_l has error at most γm−1∑l∣tl∣\gamma_{m-1} \sum_l |t_l|, since each of the real and imaginary parts does and (∑lal)2+(∑lbl)2≤∑lal2+bl2\sqrt{(\sum_l a_l)^2 + (\sum_l b_l)^2} \le \sum_l \sqrt{a_l^2 + b_l^2} for al,bl≥0a_l, b_l \ge 0. So ∣Y^k−Yk∣≤ci∑l∣zl∣+O(u2)≤cim∥z∥2+O(u2)|\hat Y_k - Y_k| \le c_i \sum_l |z_l| + O(u^2) \le c_i \sqrt m \lVert z \rVert_2 + O(u^2), and over the mm outputs, ∥Y^−Y∥2≤ci m ∥z∥2+O(u2)=cim ∥Y∥2+O(u2)\lVert \hat Y - Y \rVert_2 \le c_i \, m \, \lVert z \rVert_2 + O(u^2) = c_i \sqrt m \, \lVert Y \rVert_2 + O(u^2), since ∥Y∥2=m∥z∥2\lVert Y \rVert_2 = \sqrt m \lVert z \rVert_2. Summing over the lines of an axis, the pass ii maps the array z(i−1)z^{(i-1)} to Siz(i−1)S_i z^{(i-1)} with Si=ni QiS_i = \sqrt{n_i} \, Q_i, QiQ_i unitary, and adds an error eie_i with ∥ei∥2≤cini∥Siz(i−1)∥2+O(u2)\lVert e_i \rVert_2 \le c_i \sqrt{n_i} \lVert S_i z^{(i-1)} \rVert_2 + O(u^2). The permutations of lines L2 and L5 are exact and preserve norms. By linearity, the final error is ∑iSr⋯Si+1ei\sum_i S_r \cdots S_{i+1} e_i, and ∥Sr⋯Si+1Siz(i−1)∥2=n∥x∥2(1+O(u))=∥X∥2(1+O(u))\lVert S_r \cdots S_{i+1} S_i z^{(i-1)} \rVert_2 = \sqrt n \lVert x \rVert_2 (1 + O(u)) = \lVert X \rVert_2 (1 + O(u)), so each term has norm at most cini∥X∥2+O(u2)c_i \sqrt{n_i} \lVert X \rVert_2 + O(u^2). Summing over ii gives the bound. ■\blacksquare

Back to Good-Thomas prime-factor FFT