Algorithm Search⌘K

Proofs: Convolution via FFT

These are the human proofs of Convolution via FFT, at full length.

FFT-CONVOLVE returns the linear convolution, with a first-order error bound in floating point full

This proof shows: correctness, error-bound.

Let RR be a commutative ring, a∈Rma \in R^m, b∈Rℓb \in R^\ell with m,ℓ≥1m, \ell \ge 1, L=m+ℓ−1L = m + \ell - 1, and NN the least power of two with N≥LN \ge L. Assume that ω∈R\omega \in R is a principal NN-th root of unity and that NN is a unit of RR. Let a′,b′∈RNa', b' \in R^N be aa and bb padded with zeros (lines L4 and L5).

Lemma 1 (padding). For 0≤k≤N−10 \le k \le N - 1, (a′⊛b′)k=(a∗b)k(a' \circledast b')_k = (a * b)_k if k≤L−1k \le L - 1, and 00 otherwise.

Proof. By definition (a′⊛b′)k=∑j=0N−1aj′b(k−j) mod N′(a' \circledast b')_k = \sum_{j=0}^{N-1} a'_j b'_{(k - j) \bmod N}. A term is nonzero only if j≤m−1j \le m - 1 and r=(k−j) mod N≤ℓ−1r = (k - j) \bmod N \le \ell - 1. Then j+r≤m+ℓ−2<Nj + r \le m + \ell - 2 < N, and j+r≡k(modN)j + r \equiv k \pmod N with 0≤j+r<N0 \le j + r < N, so j+r=kj + r = k. Hence the sum is ∑j+r=k, j<m, r<ℓajbr\sum_{j + r = k,\ j < m,\ r < \ell} a_j b_r, which is (a∗b)k(a * b)_k for k≤L−1k \le L - 1 and an empty sum for k≥Lk \ge L. □\square

Theorem 1. FFT-CONVOLVE(a,b)(a, b) returns a∗ba * b.

Proof. By the correctness theorem of the FFT, line L6 sets A=FNa′A = F_N a' and B=FNb′B = F_N b', with (FNx)k=∑jxjωjk(F_N x)_k = \sum_j x_j \omega^{jk}. Line L7 sets C=A⋅BC = A \cdot B entrywise. By the convolution theorem (forward form, which only needs ωN=1\omega^N = 1), C=FN(a′⊛b′)C = F_N(a' \circledast b'). Since ω\omega is principal and NN is a unit, INVERSE-FFT computes FN−1F_N^{-1}, so line L8 leaves a′⊛b′a' \circledast b' in CC. By Lemma 1, its first LL entries, returned by line L9, are a∗ba * b. ■\blacksquare

Operation count. Lines L6 and L8 run three FFTs of length NN, each with N2lg⁡N\frac{N}{2} \lg N multiplications and Nlg⁡NN \lg N additions. Line L7 does NN multiplications, and the scaling in line L8 does NN more. In total 32Nlg⁡N+2N\frac{3}{2} N \lg N + 2N multiplications and 3Nlg⁡N3 N \lg N additions, with N<2LN < 2L by the choice of NN.

Theorem 2 (floating point, first order). Over C\mathbb{C} with ω=e−2πi/N\omega = e^{-2\pi i/N}, let each FFT be computed in floating point with unit roundoff uu, and assume the bound of Higham, Theorem 24.2: the computed transform y^\hat y of any vector xx satisfies ∥y^−Fx∥2≤δ∥Fx∥2\lVert \hat y - F x \rVert_2 \le \delta \lVert F x \rVert_2, where δ=lg⁡N⋅η/(1−lg⁡N⋅η)\delta = \lg N \cdot \eta / (1 - \lg N \cdot \eta) and η=μ+γ4(2+μ)\eta = \mu + \gamma_4 (\sqrt 2 + \mu). The same bound holds for the transform with ω−1\omega^{-1}. Assume each computed complex product is xy(1+θ)xy(1 + \theta) with ∣θ∣≤γ=2γ2|\theta| \le \gamma = \sqrt 2 \gamma_2, and that the division by the power of two NN is exact. Then the computed c^\hat c satisfies

∥c^−a∗b∥∞≤(3δ+γ)K+O(u2),K=max⁡(∥a∥1∥b∥2, ∥a∥2∥b∥1).\lVert \hat c - a * b \rVert_\infty \le (3\delta + \gamma) K + O(u^2), \qquad K = \max(\lVert a \rVert_1 \lVert b \rVert_2, \ \lVert a \rVert_2 \lVert b \rVert_1).

Proof. We use two facts on F=FNF = F_N and G=FN(ω−1)G = F_N(\omega^{-1}): ∥Fx∥2=N∥x∥2\lVert F x \rVert_2 = \sqrt N \lVert x \rVert_2, by the summation lemma, and ∥Fx∥∞≤∥x∥1\lVert F x \rVert_\infty \le \lVert x \rVert_1, since every entry of FF has modulus 11; the same holds for GG. Also ∥a′∥=∥a∥\lVert a' \rVert = \lVert a \rVert in each norm.

Let A=Fa′A = F a' and A^=A+EA\hat A = A + E_A with ∥EA∥2≤δN∥a∥2\lVert E_A \rVert_2 \le \delta \sqrt N \lVert a \rVert_2, and in the same way B^=B+EB\hat B = B + E_B with ∥EB∥2≤δN∥b∥2\lVert E_B \rVert_2 \le \delta \sqrt N \lVert b \rVert_2. The computed product is C^k=A^kB^k(1+θk)\hat C_k = \hat A_k \hat B_k (1 + \theta_k). With C=A⋅BC = A \cdot B, and dropping products of two error terms,

C^−C=EA⋅B+A⋅EB+θ⋅A⋅B+O(u2).\hat C - C = E_A \cdot B + A \cdot E_B + \theta \cdot A \cdot B + O(u^2).

Now ∥EA⋅B∥2≤∥EA∥2∥B∥∞≤δN∥a∥2∥b∥1\lVert E_A \cdot B \rVert_2 \le \lVert E_A \rVert_2 \lVert B \rVert_\infty \le \delta \sqrt N \lVert a \rVert_2 \lVert b \rVert_1, ∥A⋅EB∥2≤∥A∥∞∥EB∥2≤δN∥a∥1∥b∥2\lVert A \cdot E_B \rVert_2 \le \lVert A \rVert_\infty \lVert E_B \rVert_2 \le \delta \sqrt N \lVert a \rVert_1 \lVert b \rVert_2, and ∥θ⋅A⋅B∥2≤γ∥A∥2∥B∥∞≤γN∥a∥2∥b∥1\lVert \theta \cdot A \cdot B \rVert_2 \le \gamma \lVert A \rVert_2 \lVert B \rVert_\infty \le \gamma \sqrt N \lVert a \rVert_2 \lVert b \rVert_1. So ∥C^−C∥2≤(2δ+γ)NK+O(u2)\lVert \hat C - C \rVert_2 \le (2\delta + \gamma) \sqrt N K + O(u^2).

The inverse step computes c^′=1N(GC^+EG)\hat c' = \frac{1}{N}(G \hat C + E_G) with ∥EG∥2≤δ∥GC^∥2=δN∥C^∥2\lVert E_G \rVert_2 \le \delta \lVert G \hat C \rVert_2 = \delta \sqrt N \lVert \hat C \rVert_2. The exact value is c′=1NGC=a′⊛b′c' = \frac{1}{N} G C = a' \circledast b', by Theorem 1. So

c^′−c′=1NG(C^−C)+1NEG.\hat c' - c' = \tfrac{1}{N} G (\hat C - C) + \tfrac{1}{N} E_G.

For the first term, ∥1NGv∥∞≤1N∥v∥1≤1N∥v∥2\lVert \frac{1}{N} G v \rVert_\infty \le \frac{1}{N} \lVert v \rVert_1 \le \frac{1}{\sqrt N} \lVert v \rVert_2, which gives at most (2δ+γ)K+O(u2)(2\delta + \gamma) K + O(u^2). For the second term, ∥1NEG∥∞≤1N∥EG∥2≤δN∥C^∥2\lVert \frac{1}{N} E_G \rVert_\infty \le \frac{1}{N} \lVert E_G \rVert_2 \le \frac{\delta}{\sqrt N} \lVert \hat C \rVert_2, and ∥C^∥2=∥C∥2+O(u)≤∥A∥2∥B∥∞+O(u)≤NK+O(u)\lVert \hat C \rVert_2 = \lVert C \rVert_2 + O(u) \le \lVert A \rVert_2 \lVert B \rVert_\infty + O(u) \le \sqrt N K + O(u), which gives at most δK+O(u2)\delta K + O(u^2). Adding the two terms, and noting that c^\hat c is the first LL entries of c^′\hat c' and a∗ba * b the first LL entries of c′c', proves the bound. ■\blacksquare

Exact rounding. If aa and bb are integer vectors, then a∗ba * b is an integer vector, and if the right side of Theorem 2, including the second-order terms, is below 12\frac{1}{2}, rounding each real part of c^\hat c to the nearest integer returns a∗ba * b exactly.

Back to Convolution via FFT