Fast Fourier Transform¶
From Computability, Complexity & Algorithms — Charles Brubaker and Lance Fortnow
Introduction: Convolution and Polynomial Multiplication¶
The Fast Fourier Transform (FFT) enables efficient convolution of sequences, reducing the naive \(O(nm)\) cost to \(O(N \log N)\) where \(N = n + m - 1\) is the output length.
Convolution arises in signal processing, image filtering, and polynomial multiplication. The \(k\)-th coefficient of the convolution of sequences \(a\) and \(b\) is:
Initial alignment of the two sequences for convolution at \(k = 0\).¶
Final state after sliding the reversed sequence through the convolution.¶
Alignment demonstrating calculation of the \(x^2\) term in polynomial multiplication.¶
Convolution of \(a\) and \(b\) is equivalent to multiplying the corresponding polynomials \(A(x)\) and \(B(x)\).
Polynomial Representations¶
A degree-\(n\) polynomial \(A(x) = a_0 + a_1 x + a_2 x^2 + \cdots + a_{n-1} x^{n-1}\) can be represented in two ways:
Coefficient form: the vector \((a_0, a_1, \ldots, a_{n-1})\).
Value form: the values \(A(x_0), A(x_1), \ldots, A(x_{N-1})\) at \(N\) distinct points (requires \(N \geq n\)).
Conversion from coefficients to values at \(N\) points uses the Vandermonde matrix:
Vandermonde matrix converting polynomial coefficients to point values.¶
Key observation: In value form, pointwise multiplication of two degree-\(N\) polynomials costs only \(O(N)\):
Multiplication is \(O(N^2)\) in coefficient form but \(O(N)\) in value form.¶
The Three-Step FFT Process¶
Evaluate → Multiply → Interpolate: convert to values, multiply pointwise, convert back to coefficients.¶
Evaluate \(A\) and \(B\) at \(N\) chosen points → value representations.
Multiply pointwise: \(C(x_i) = A(x_i) \cdot B(x_i)\) for each \(i\) — cost \(O(N)\).
Interpolate the product values back to coefficients of \(C\).
Quiz: Multiply two polynomials using value representation.¶
Time complexity of each stage — the bottleneck is evaluation and interpolation.¶
The naive evaluation at \(N\) arbitrary points costs \(O(N^2)\) (one Horner evaluation per point). The FFT achieves \(O(N \log N)\) by choosing the evaluation points cleverly.
Even-Odd Decomposition¶
Split \(A(x)\) into even- and odd-indexed coefficients:
Then:
Evaluating at \(+x\) and \(-x\) shares the computation of \(A_e(x^2)\) and \(A_o(x^2)\).¶
Saving: One recursive call at \(x^2\) gives both \(A(x)\) and \(A(-x)\) — halving the work at each level.
Roots of Unity¶
To apply the even-odd trick recursively, choose evaluation points as the \(N\)-th roots of unity:
These satisfy the key cancellation property:
so the positive-negative pairing needed by the even-odd split is automatically present.
The 8th roots of unity arranged on the unit circle in the complex plane.¶
Squaring the 8th roots of unity yields the 4th roots of unity.¶
Recursive FFT Structure¶
First decomposition level: evaluate at 8th roots → two sub-problems at 4th roots.¶
Second decomposition level: 4th roots → two sub-problems at 2nd roots (base case).¶
Quiz: Apply FFT to evaluate a polynomial at the four 4th roots of unity.¶
FFT Algorithm¶
Formal recursive FFT pseudocode.¶
FFT(a, ω): # a = coefficient vector, ω = primitive N-th root
if N == 1: return a[0]
a_e = [a[0], a[2], ..., a[N-2]]
a_o = [a[1], a[3], ..., a[N-1]]
y_e = FFT(a_e, ω²)
y_o = FFT(a_o, ω²)
for j = 0 to N/2 - 1:
y[j] = y_e[j] + ω^j · y_o[j]
y[j + N/2] = y_e[j] - ω^j · y_o[j]
return y
Recurrence:
by the Master Theorem.
Butterfly Network¶
The FFT computation can be visualised as a butterfly network — a circuit of \(\log N\) layers each performing \(N/2\) butterfly operations.
Butterfly network showing the data flow and computation dependencies.¶
Right-to-left paths encode the bit-reversal permutation of input indices.¶
Left-to-right paths encode the twiddle-factor \(\omega^j\) multiplications.¶
Updated running time: evaluation and interpolation both cost \(O(N \log N)\), giving overall \(O(N \log N)\) polynomial multiplication.¶
Inverse FFT (Interpolation)¶
Given the values \(A(\omega^0), \ldots, A(\omega^{N-1})\), recover the coefficients using the inverse DFT. The Vandermonde matrix at roots of unity has a convenient inverse:
This is simply FFT evaluated at the conjugate roots \(\bar{\omega} = \omega^{-1}\), followed by scaling by \(1/N\).
Vandermonde matrix structure at the \(N\)-th roots of unity and its inverse.¶
Inverse FFT algorithm: run FFT with \(\omega^{-1}\) then divide by \(N\).¶
Quiz: Recover polynomial coefficients from their values at roots of unity.¶
Complete Process¶
Full polynomial multiplication pipeline achieving \(O(N \log N)\) overall.¶
Summary of costs:
Stage |
Naive cost |
FFT cost |
|---|---|---|
Evaluate \(A\), \(B\) at \(N\) points |
\(O(N^2)\) |
\(O(N \log N)\) |
Pointwise multiply |
\(O(N)\) |
\(O(N)\) |
Interpolate \(C\) from values |
\(O(N^2)\) |
\(O(N \log N)\) |
Total |
\(O(N^2)\) |
\(O(N \log N)\) |
Key Formulas¶
Even-odd split:
Primitive \(N\)-th root of unity:
Cancellation property:
FFT recurrence:
Inverse DFT:
Further Reading¶
Cooley-Tukey iterative (in-place) FFT implementation
Number-theoretic transforms (FFT over finite fields)
Applications: signal processing, image convolution, fast integer multiplication