The iterative FFT computes the DFT, and FFT-MULTIPLY returns the product full
This proof shows: correctness.
Let R be a commutative ring with 1, N=2k with k≥0, and ω∈R with ωN=1 and, if N≥2, ωN/2=−1. For a list c=[c0,…,cN−1] define DFTω(c)i=∑j<Ncjωij for 0≤i<N. For 0≤l≤k and 0≤t<2l, write revl(t) for the number whose l binary digits are those of t in reverse order.
Lemma 1 (powers of a principal root). For 1≤L≤N a power of two, ωL=ωN/L satisfies ωLL=1 and, if L≥2, ωLL/2=−1. Also ω−1=ωN−1 is again a principal N-th root of unity.
Proof. ωLL=ωN=1 and ωLL/2=ωN/2=−1. For ω−1: ω⋅ωN−1=1, (ω−1)N=1, and (ω−1)N/2=(ωN/2)−1=(−1)−1=−1. □
Lemma 2 (iterative FFT). DFT(a,ω), lines F1 to F11, replaces a by DFTω(a).
Proof. Let a be the input. Line F1 puts arevk(i) at position i; the swap of i and revk(i) is done once for each pair with i<revk(i), and revk is an involution, so this is a permutation. We prove by induction on l the claim
(Sl) after the stages with block lengths 2,4,…,2l (for l=0, after line F1), for each block index 0≤t<N/L with L=2l and each 0≤j<L, the position tL+j holds Yl,t(j)=∑p<Lar+pN/LωLjp, where r=revk−l(t).
Base. For l=0, L=1, the sum has one term, arevk(t), which line F1 put at position t.
Step. Assume (Sl) and let L=2l<N. The stage with len =2L (line F4 sets wlen=ωN/2L=ω2L) works on the blocks [s,s+2L) with s=2Lt′. Such a block is the union of the old blocks 2t′ and 2t′+1. Reversing k−l digits, revk−l(2t′)=revk−l−1(t′), since the low digit 0 of 2t′ becomes the top digit, and revk−l(2t′+1)=2k−l−1+revk−l−1(t′). Write r′=revk−l−1(t′), and note 2k−l−1=N/2L. So by (Sl) the first half of the block holds E(j)=∑p<Lar′+2pN/2LωLjp and the second half holds O(j)=∑p<Lar′+N/2L+2pN/2LωLjp, for 0≤j<L.
Lines F6 and F10 give w=ω2Lj in step j of line F7. Lines F8 and F9 set position s+j to E(j)+ω2LjO(j) and position s+j+L to E(j)−ω2LjO(j). Each step reads only the two positions it writes, so the steps do not interfere. Now split the target sum by the parity of q:
Yl+1,t′(j)=q<2L∑ar′+qN/2Lω2Ljq=p<L∑ar′+2pN/2Lω2L2jp+p<L∑ar′+(2p+1)N/2Lω2Lj(2p+1)=E(j)+ω2LjO(j), because ω2L2=ωL. For j+L, the same computation has ωL(j+L)p=ωLjp (as ωLL=1) and ω2Lj+L=−ω2Lj (as ω2LL=−1, Lemma 1), so Yl+1,t′(j+L)=E(j)−ω2LjO(j). This is (Sl+1).
End. The loop of line F3 runs for len =2,…,N, so (Sk) holds at the end. With L=N there is one block, t=0, r=0, and position j holds ∑p<Napωjp=DFTω(a)j. □
Lemma 3 (orthogonality). For each integer j with N∤j, ∑i<Nωij=0.
Proof. Then N≥2. Write jmodN=2eo with o odd and 0≤e<k, and let h=N/2e+1, an integer at least 1. Let η=ωj. Then ηh=ω2eoN/2e+1=(ωN/2)o=(−1)o=−1 (using ωN=1 to reduce j modulo N). Group the indices 0≤i<N in pairs {i,i+h} with ⌊i/h⌋ even; these pairs cover [0,N) because 2h divides N. In each pair ηi+h=−ηi, so each pair sums to 0. □
Lemma 4 (inversion). For each list c of length N, if N is a unit then N−1DFTω−1(DFTω(c))=c.
Proof. The j-th entry of DFTω−1(DFTω(c)) is
i<N∑ω−ijl<N∑clωil=l<N∑cli<N∑ωi(l−j). For l=j the inner sum is N. For l=j, 0<∣l−j∣<N, so N∤l−j, and the inner sum is 0 by Lemma 3 (the exponent l−j may be negative; ωl−j means ω(l−j)modN). So the entry is Ncj. □
Lemma 5 (the pointwise product). Let f=∑i<maixi, g=∑j<nbjxj, h=fg, and let aˉ,bˉ,hˉ be the coefficient lists padded with zeros to length N≥m+n−1. Then DFTω(aˉ)i⋅DFTω(bˉ)i=DFTω(hˉ)i for each i.
Proof. DFTω(aˉ)i=f(ωi), because the padded zeros add nothing. Evaluation at ωi is a ring homomorphism R[x]→R, so f(ωi)g(ωi)=h(ωi). Since degh≤m+n−2<N, hˉ holds all coefficients of h, and h(ωi)=DFTω(hˉ)i. □
Theorem. If ω is a principal N-th root of unity in R and N is a unit, FFT-MULTIPLY(a,b) returns the normalized coefficient list of fg.
Proof. If a or b is empty, a factor is zero and line L1 returns the empty list. Otherwise lines L2 and L3 give N≥m+n−1 and the padded lists. By Lemma 2, line L4 computes A=DFTω(aˉ) and B=DFTω(bˉ), and by Lemma 5, line L5 gives C=DFTω(hˉ). By Lemma 1, ω−1 is a principal N-th root, so Lemma 2 applies to the call in line L6, and by Lemma 4 line L6 gives c=hˉ. Line L7 drops the padding above position m+n−2, which is zero, and removes zero top entries, which do not change the polynomial. ■
Remark (the reductions over Z, Z/mZ and Q). Over Z, each coefficient satisfies ∣hk∣=∣∑i+j=kaibj∣≤min(m,n)max∣ai∣max∣bj∣=B, since the sum has at most min(m,n) terms. The theorem gives hkmodp for each prime p used. If the product P of the primes exceeds 2B, then hk is the only integer in (−P/2,P/2] with these residues, by the Chinese remainder theorem, and Garner's method returns it. For Z/mZ, the map Z[x]→(Z/mZ)[x] is a ring homomorphism, so reducing the integer product of the representatives gives the product modulo m. For Q, (daf)(dbg)=dadbfg with integer polynomials on the left. □