The Fast Fourier Transform
The Fast Fourier Transform
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
FFT
FFT
Polynomials
Polynomial:
p( x ) 5 2 x 8 x 2 3x 3 4 x 4
In general,
p ( x ) ai x
i 0
n 1
or p ( x ) a0 a1 x a2 x an 1 x
2
FFT
n 1
Polynomial Evaluation
Horners Rule:
Given coefficients (a0,a1,a2,,an-1), defining polynomial n 1 i i i 0 Given x, we can evaluate p(x) in O(n) time using the equation
p( x ) a x
[Where A=(a0,a1,a2,,an-1)]
p ( x ) q( x ) ci x
where
n 1 i 0
ci a j bi j
j 0
A straightforward evaluation would take O(n2) time. The magical FFT will do it in O(n log n) time.
FFT 5
Calculate p() on 2n x-values, x0,x1,,x2n-1. Calculate q() on the same 2n x values. Find the (2n-1)-degree polynomial that goes through the points {(x0,p(x0)q(x0)), (x1,p(x1)q(x1)), , (x2n-1,p(x2n-1)q(x2n-1))}.
Unfortunately, a straightforward evaluation would still take O(n2) time, as we would need to apply an O(n)-time Horners Rule evaluation to 2n different points. The magical FFT will do it in O(n log n) time, by picking 2n points that are easy to evaluate
FFT 6
Example 1:
2, 6, 7, 8 are 10-th roots of unity in Z*11 22=4, 62=3, 72=5, 82=9 are 5-th roots of unity in Z*11 2-1=6, 3-1=4, 4-1=3, 5-1=9, 6-1=2, 7-1=8, 8-1=7, 9-1=5
Example 2: The complex number e2pi/n is a primitive n-th root of unity, where i 1 FFT 7
w
j 0
n 1
kj
(w k )n 1 (w n )k 1 (1)k 1 11 w k k 0 k k w 1 w 1 w 1 w 1 j 0
n 1 kj
Reduction Property: If w is a primitve (2n)-th root of unity, then w2 is a primitive n-th root of unity.
0 w ( n / 2 ) j w 0 w n / 2 w 0 w n / 2 w 0 w n / 2 ( n / 2)(1 w n / 2 )
j 0
n 1
FFT
y j aiw
i 0
The Inverse Discrete Fourier Transform recovers the coefficients of an (n-1)-degree polynomial given its values at 1,w,w2,,wn-1
FFT
1 n 1 ki kj A[i, j ] w w n k 0
If i=j, then
1 n 1 ki ki 1 n 1 0 1 A[i, i ] w w w n 1 n k 0 n k 0 n
If i and j are different, then
1 n 1 ( j i ) k A[i, j ] w 0 n k 0
FFT
10
Convolution
The DFT and the inverse DFT can be used to multiply two polynomials
So we can get the coefficients of the product polynomial quickly if we can compute the DFT (and its inverse) quickly
[y0z0,y1z1,...,y2n-1z2n-1]
inverse DFT
[c0,c1,c2,...,c2n-1]
FFT
(Convolution)
11
FFT
12
Find a generator x of Z*p. Then w=xc is a primitive n-th root of unity in Z*p (arithmetic is mod p)
Apply convolution and FFT algorithm to compute the convolution C of the vector representations of I and J. n 1 Then compute K ci 2 mi
i 0
10;
FFT
15
FFT
16
FFT
17
FFT
18
Non-recursive FFT
There is also a non-recursive version of the FFT
Performs the FFT in place Precomputes all roots of unity Performs a cumulative collection of shuffles on A and on B prior to the FFT, which amounts to assigning the value at index i to the index bit-reverse(i).
The code is a bit more complex, but the running time is faster by a constant, due to improved overhead
FFT
19
Experimental Results
Log-log scale shows traditional multiply runs in O(n2) time, while FFT versions are almost linear
FFT
20