Algorithm Search⌘K

Proofs: Fast Fourier transform

These are the human proofs of Fast Fourier transform, at full length.

The iterative radix-2 FFT computes the DFT, and INVERSE-FFT inverts it full

This proof shows: correctness, complexity.

Let RR be a commutative ring, n=2tn = 2^t with t≥0t \ge 0, and ω∈R\omega \in R with ωn/2=−1\omega^{n/2} = -1 if n≥2n \ge 2. Then ωn=1\omega^n = 1. Write xx for the input array and x′x' for the array as the algorithm changes it. For h=2qh = 2^q with 0≤q≤t0 \le q \le t and a block start ss with h∣sh \mid s, let c(s,h)=revt−q(s/h)c(s, h) = \mathrm{rev}_{t-q}(s/h), so 0≤c(s,h)<n/h0 \le c(s,h) < n/h, and define the subsequence x(s,h)∈Rhx^{(s,h)} \in R^h by xm(s,h)=xc(s,h)+mn/hx^{(s,h)}_m = x_{c(s,h) + m n/h} for 0≤m<h0 \le m < h.

Lemma 1 (split). Let N=2M≥2N = 2M \ge 2 and ζ∈R\zeta \in R with ζM=−1\zeta^M = -1. For y∈RNy \in R^N, let EE and OO be the DFTs of length MM with the root ζ2\zeta^2 of (y0,y2,…,yN−2)(y_0, y_2, \ldots, y_{N-2}) and (y1,y3,…,yN−1)(y_1, y_3, \ldots, y_{N-1}). Then for 0≤k<M0 \le k < M,

∑m=0N−1ymζmk=Ek+ζkOk,∑m=0N−1ymζm(k+M)=Ek−ζkOk.\sum_{m=0}^{N-1} y_m \zeta^{mk} = E_k + \zeta^k O_k, \qquad \sum_{m=0}^{N-1} y_m \zeta^{m(k+M)} = E_k - \zeta^k O_k.

Proof. Split the sum by the parity of m=2m′m = 2m' or m=2m′+1m = 2m' + 1: ∑mymζmk′=∑m′y2m′(ζ2)m′k′+ζk′∑m′y2m′+1(ζ2)m′k′\sum_m y_m \zeta^{mk'} = \sum_{m'} y_{2m'} (\zeta^2)^{m'k'} + \zeta^{k'} \sum_{m'} y_{2m'+1} (\zeta^2)^{m'k'} for each k′k'. For k′=kk' = k this is Ek+ζkOkE_k + \zeta^k O_k. For k′=k+Mk' = k + M, (ζ2)m′(k+M)=(ζ2)m′k(ζ2M)m′=(ζ2)m′k(\zeta^2)^{m'(k+M)} = (\zeta^2)^{m'k} (\zeta^{2M})^{m'} = (\zeta^2)^{m'k} because ζ2M=1\zeta^{2M} = 1, and ζk+M=−ζk\zeta^{k+M} = -\zeta^k. □\square

Lemma 2 (indices). Let h=2qh = 2^q with q<tq < t and 2h∣s2h \mid s. Then c(s,h)=c(s,2h)c(s, h) = c(s, 2h) and c(s+h,h)=c(s,2h)+n/(2h)c(s + h, h) = c(s, 2h) + n/(2h). Hence x(s,h)x^{(s,h)} and x(s+h,h)x^{(s+h,h)} are the even-indexed and the odd-indexed entries of x(s,2h)x^{(s,2h)}.

Proof. Let s/(2h)=as/(2h) = a. Then s/h=2as/h = 2a and (s+h)/h=2a+1(s + h)/h = 2a + 1, written with t−qt - q binary digits. Reversing t−qt - q digits moves the lowest digit to the top place 2t−q−1=n/(2h)2^{t-q-1} = n/(2h) and reverses the other t−q−1t - q - 1 digits, so revt−q(2a+b)=b⋅n/(2h)+revt−q−1(a)\mathrm{rev}_{t-q}(2a + b) = b \cdot n/(2h) + \mathrm{rev}_{t-q-1}(a) for b∈{0,1}b \in \{0, 1\}, and revt−q−1(a)=c(s,2h)\mathrm{rev}_{t-q-1}(a) = c(s, 2h). So xm(s,h)=xc(s,2h)+2m⋅n/(2h)=x2m(s,2h)x^{(s,h)}_{m} = x_{c(s,2h) + 2m \cdot n/(2h)} = x^{(s,2h)}_{2m} and xm(s+h,h)=xc(s,2h)+(2m+1)n/(2h)=x2m+1(s,2h)x^{(s+h,h)}_{m} = x_{c(s,2h) + (2m+1) n/(2h)} = x^{(s,2h)}_{2m+1}. □\square

Invariant (I). When line L6 tests h=2qh = 2^q, for each ss with h∣sh \mid s and 0≤k<h0 \le k < h,

x′[s+k]=∑m=0h−1xm(s,h) (ωn/h)mk.x'[s + k] = \sum_{m=0}^{h-1} x^{(s,h)}_m \, \left(\omega^{n/h}\right)^{mk}.

Initialization. Lines L3 and L4 swap each pair {j,revt(j)}\{j, \mathrm{rev}_t(j)\} with j<revt(j)j < \mathrm{rev}_t(j) exactly once and leave the fixed points alone. Since revt\mathrm{rev}_t is an involution, the pairs are disjoint, and afterwards x′[j]=xrevt(j)x'[j] = x_{\mathrm{rev}_t(j)} for each jj. Line L5 sets h=1h = 1, and (I) for h=1h = 1 says x′[s]=x0(s,1)=xrevt(s)x'[s] = x^{(s,1)}_0 = x_{\mathrm{rev}_t(s)}, which holds.

Maintenance. Let (I) hold for h<nh < n, and fix a block start ss with 2h∣s2h \mid s. Put ζ=ωn/(2h)\zeta = \omega^{n/(2h)} and M=hM = h. Then ζM=ωn/2=−1\zeta^{M} = \omega^{n/2} = -1 and ζ2=ωn/h\zeta^2 = \omega^{n/h}. By (I) and Lemma 2, before the loop of line L8 the cells x′[s…s+h−1]x'[s \ldots s + h - 1] hold EE and the cells x′[s+h…s+2h−1]x'[s + h \ldots s + 2h - 1] hold OO, the DFTs with the root ζ2\zeta^2 of the even and odd entries of y=x(s,2h)y = x^{(s,2h)}. For each k<hk < h, lines L9 to L12 read only the cells s+ks + k and s+k+hs + k + h, and write only those two cells, so the iterations for different kk do not interfere, and blocks for different ss are disjoint. The table entry is W[k⋅n/(2h)]=ωkn/(2h)=ζkW[k \cdot n/(2h)] = \omega^{k n/(2h)} = \zeta^k by line L2, and k⋅n/(2h)<n/2k \cdot n/(2h) < n/2, so it is in the table. Line L9 saves u=Eku = E_k before line L11 overwrites it, line L10 computes v=ζkOkv = \zeta^k O_k, and lines L11 and L12 store Ek+ζkOkE_k + \zeta^k O_k and Ek−ζkOkE_k - \zeta^k O_k. By Lemma 1 with N=2hN = 2h, these are the entries kk and k+hk + h of the DFT of x(s,2h)x^{(s,2h)} with the root ζ=ωn/(2h)\zeta = \omega^{n/(2h)}. After line L13 doubles hh, (I) holds for the new hh.

Termination. The loop ends when h=nh = n. Then the only block start is s=0s = 0, c(0,n)=rev0(0)=0c(0, n) = \mathrm{rev}_0(0) = 0, and x(0,n)=xx^{(0,n)} = x. So by (I), x′[k]=∑mxmωmk=Xkx'[k] = \sum_m x_m \omega^{mk} = X_k for each kk.

Theorem 1. If n=2tn = 2^t and ωn/2=−1\omega^{n/2} = -1 (no condition when n=1n = 1), FFT(x,ω)(x, \omega) replaces xx by FnxF_n x, with (Fnx)k=∑jxjωjk(F_n x)_k = \sum_{j} x_j \omega^{jk}. This holds in particular when ω\omega is a principal nn-th root of unity and nn is a unit, because then ωn/2=−1\omega^{n/2} = -1 by the cancellation lemma, and for ω=e∓2πi/n\omega = e^{\mp 2\pi i/n} over C\mathbb{C}.

Proof. The invariant and the termination step above. □\square

Theorem 2. If ω\omega is a principal nn-th root of unity and nn is a unit of RR, then INVERSE-FFT(Fnx,ω)(F_n x, \omega) returns xx.

Proof. The element ω−1=ωn−1\omega^{-1} = \omega^{n-1} is a principal nn-th root: (ω−1)n=1(\omega^{-1})^n = 1, and for 1≤k≤n−11 \le k \le n - 1, ∑jω−jk=∑jωj(n−k)=0\sum_j \omega^{-jk} = \sum_j \omega^{j(n-k)} = 0 since 1≤n−k≤n−11 \le n - k \le n - 1. So by Theorem 1, line L14 computes Yj=∑kXkω−jk=∑lxl∑kω(l−j)kY_j = \sum_k X_k \omega^{-jk} = \sum_{l} x_l \sum_k \omega^{(l - j)k}. By the summation lemma in the form of the definition of a principal root, the inner sum is nn if l=jl = j and 00 otherwise, for 0≤l,j≤n−10 \le l, j \le n - 1. So Yj=nxjY_j = n x_j, and line L15 returns xjx_j. ■\blacksquare

Operation count. Each pass of the loop of line L6 runs n/(2h)n/(2h) blocks of hh butterflies, and each butterfly does one multiplication (line L10) and two additions (lines L11 and L12). There are tt passes, with h=1,2,…,n/2h = 1, 2, \ldots, n/2. So the butterflies use exactly n2t=n2lg⁡n\frac{n}{2} t = \frac{n}{2} \lg n multiplications and nlg⁡nn \lg n additions in RR. Line L2 needs at most max⁡(n/2−2,0)\max(n/2 - 2, 0) multiplications if each power is the previous one times ω\omega, and line L15 needs nn more for the inverse.

Back to Fast Fourier transform