Download presentation
Presentation is loading. Please wait.
1
Fast Fourier Transform
Algorithms in Action Fast Fourier Transform Haim Kaplan, Uri Zwick Tel Aviv University March 2016 Last updated: March 6, 2018
2
Discrete Fourier Transform (DFT)
A very special linear transformation ๐ฆ 0 ๐ฆ 1 โฎ ๐ฆ ๐โ1 = โฎ โฏ ๐ ๐ ๐๐ โฏ โฎ โฎ ๐ฅ 0 ๐ฅ 1 โฎ ๐ฅ ๐โ1 ๐ โ row index , ๐ โ column index ๐ฆ ๐ = ๐=0 ๐โ1 ๐ ๐ ๐๐ ๐ฅ ๐ ๐ = ๐ ๐ = ๐ 2๐๐/๐ = cos 2๐ ๐ +๐ sin 2๐ ๐ ๐= โ1
3
Complex roots of unity (๐=8)
๐ 2 =๐ ๐ 3 = ๐ ๐๐/4 =โ ๐ ๐ = ๐ 8 = ๐ ๐๐/ = ๐ ๐ 4 =โ1 ๐ 0 = ๐ 8 =1 ๐ 5 ๐ 7 ๐ 6 =โ๐
4
Discrete Fourier Transform (DFT)
The case ๐=4 ๐ฆ 0 ๐ฆ 1 ๐ฆ 2 ๐ฆ 3 = ๐ ๐ 2 ๐ ๐ 2 ๐ ๐ ๐ 2 ๐ ๐ฅ 0 ๐ฅ 1 ๐ฅ 2 ๐ฅ 3 ๐ = ๐ 4 = ๐ 2๐๐/4 =๐ In general: ๐ ๐ ๐ = ๐ ๐ ๐ mod ๐ .
5
DFT as polynomial evaluation
Evaluating a polynomial at 1,๐, ๐ 2 ,โฆ, ๐ ๐โ1 ๐ฆ 0 ๐ฆ 1 โฎ ๐ฆ ๐โ1 = โฎ โฏ ๐ ๐ ๐๐ โฏ โฎ โฎ ๐ฅ 0 ๐ฅ 1 โฎ ๐ฅ ๐โ1 โ๐ง-transformโ ๐ ๐ง = ๐=0 ๐โ1 ๐ฅ ๐ ๐ง ๐ = ๐ฅ 0 + ๐ฅ 1 ๐ง+โฆ+ ๐ฅ ๐โ1 ๐ง ๐โ1 ๐ฆ ๐ = ๐=0 ๐โ1 ๐ ๐ ๐๐ ๐ฅ ๐ =๐ ๐ ๐ ๐ , ๐=0,1,โฆ,๐โ1
6
Fast Fourier Transform (FFT)
FFT is an algorithm for computing DFT. Naรฏve computation of DFT requires ฮ ๐ 2 time. FFT computes DFT in ฮ(๐ log ๐) time. Developed by Cooley and Tuckey in 1965, but similar ideas were used much earlier, e.g., by Runge and Kรถnig in 1924 and others. We assume that ๐= 2 ๐ .
7
Digital signal processing: Computing convolutions:
Applications of the FFT Digital signal processing: Transforming signals from time to frequency domain Computing convolutions: Multiplication of polynomials Multiplication of large integers String matching problems Quantum computing: Used in Shorโs integer factorization algorithm โฎ
8
Sampling sin (9 2๐๐ฅ ) Sampling rate = 32 Hz
9
Sampling sin (9 2๐๐ฅ ) Sampling rate = 32 Hz
10
sin (9 2๐๐ฅ ) and its spectrum
Spectrum = absolute value of the Fourier coefficients. In addition to the spectrum, we also have the phase. 9 (=9Hz) is right. What is 23? 23=32โ9 !
11
Aliasing example: sin 5 2๐๐ฅ vs. โ sin 11 2๐๐ฅ
Same samples at 16Hz. sin 2๐๐โ๐ฅ =โ sin ๐ฅ sin ๐โ๐ 2๐๐/๐ =โ sin ๐2๐๐/๐
12
The Sampling Theorem (Nyquist, Shannon, โฆ)
โIf a real continuous signal ๐ฅ(๐ก) contains no frequencies higher than ๐ต Hz, then ๐ฅ(๐ก) is uniquely determined by its sampled version ๐ฅ ๐ =๐ฅ(๐/๐น), where ๐=โฆ,โ1,0,1,โฆ, at frequency ๐น Hz, provided that ๐นโฅ2๐ต.โ For information only. Not part of this course. We only consider finite discrete โsignalsโ.
13
โSymmetryโ of DFT for real signals
Lemma: If ๐ฑ= ๐ฅ 0 , ๐ฅ 1 ,โฆ, ๐ฅ ๐โ1 โ โ ๐ , y = ๐ฆ 0 , ๐ฆ 1 ,โฆ, ๐ฆ ๐โ1 โ โ ๐ and ๐ฒ=๐ท๐น๐(๐ฑ), then ๐ฆ ๐โ๐ = ๐ฆ ๐ โ , for ๐=1,2,โฆ,๐โ1. Complex conjugates: If ๐ง=๐ฅ+๐๐ฆ then ๐ง โ =๐ฅโ๐๐ฆ. Absolute values: If ๐ง=๐ฅ+๐๐ฆ then ๐ง 2 =๐ง ๐ง โ = ๐ฅ 2 + ๐ฆ 2 . Exercise: Prove the lemma. For real inputs, the first half of the DFT contains all the information.
14
Frequencies and their relative contribution correctly identified!
sin 9 2๐๐ฅ sin 2 2๐๐ฅ +2 cos 2๐๐ฅ Frequencies and their relative contribution correctly identified! As we shall soon see, from the Fourier coefficients, not just their absolute values, we can reconstruct the original signal.
15
sin 9.5 2๐๐ฅ Basis vectors correspond to integer frequencies.
9.5 Hz is a non-trivial combination of basis vectors. See below.
16
For more information, take a course on digital signal processing.
๐ฅ For more information, take a course on digital signal processing.
17
Decomposing the DFT (I)
Goal: Compute a DFT of even size ๐ by computing two DFTs of size ๐/2. Split ๐ฑ into even and odd parts. ๐ฑ= ๐ฅ 0 , ๐ฅ 1 ,โฆ, ๐ฅ ๐โ1 ๐ ๐ง = ๐=0 ๐โ1 ๐ฅ ๐ ๐ง ๐ ๐ฑ (0) = ๐ฅ 0 , ๐ฅ 2 ,โฆ, ๐ฅ ๐โ2 ๐ 0 ๐ง = ๐=0 ๐/2โ1 ๐ฅ 2๐ ๐ง ๐ ๐ฑ (1) = ๐ฅ 1 , ๐ฅ 3 ,โฆ, ๐ฅ ๐โ1 ๐ 1 ๐ง = ๐=0 ๐/2โ1 ๐ฅ 2๐+1 ๐ง ๐ ๐ ๐ง = ๐ ๐ง 2 + ๐ง ๐ ๐ง 2
18
Decomposing the DFT (II)
๐ ๐ง = ๐ ๐ง 2 + ๐ง ๐ ๐ง 2 We need to evaluate ๐(๐ง) at ๐ ๐ 0 , ๐ ๐ 1 ,โฆ, ๐ ๐ ๐โ1 To do that we need to evaluate ๐ 0 (๐ง) and ๐ 1 (๐ง) at ๐ ๐ 0 , ๐ ๐ 2 ,โฆ, ๐ ๐ 2(๐โ1) But these ๐ points are exactly ๐ ๐/2 0 , ๐ ๐/2 1 ,โฆ, ๐ ๐/2 ๐/2โ1 , ๐ ๐/2 0 , ๐ ๐/2 1 ,โฆ, ๐ ๐/2 ๐/2โ1 Thus, we only need to compute ๐ท๐น๐( ๐ฑ 0 ) and ๐ท๐น๐( ๐ฑ 1 ) , use each computed number twice, and multiply the values of ๐ท๐น๐ ๐ฑ by appropriate powers of ๐ ๐ !!!
19
FFT โ recursive version
๐น๐น๐ ๐ฅ 0 , ๐ฅ 1 ,โฆ, ๐ฅ ๐โ1 : if ๐=2: return ( ๐ฅ 0 + ๐ฅ 1 , ๐ฅ 0 โ ๐ฅ 1 ) ( ๐ 0 , ๐ 1 ,โฆ, ๐ ๐/2โ1 ) โ๐น๐น๐ ๐ฅ 0 , ๐ฅ 2 ,โฆ, ๐ฅ ๐โ2 ( ๐ 0 , ๐ 1 ,โฆ, ๐ ๐/2โ1 ) โ๐น๐น๐ ๐ฅ 1 , ๐ฅ 3 ,โฆ, ๐ฅ ๐โ1 for ๐โ0 to ๐/2โ1: ๐ฆ ๐ โ ๐ ๐ + ๐ ๐ ๐ ๐ ๐ ๐ฆ ๐/2+๐ โ ๐ ๐ โ ๐ ๐ ๐ ๐ ๐ // ๐ ๐ ๐/2+๐ =โ ๐ ๐ ๐ return ๐ฆ 0 , ๐ฆ 1 ,โฆ, ๐ฆ ๐โ1
20
๐น๐น๐ ๐ฅ 0 , ๐ฅ 1 ,โฆ, ๐ฅ ๐โ1 : // Slightly optimized
if ๐=2: return ( ๐ฅ 0 + ๐ฅ 1 , ๐ฅ 0 โ ๐ฅ 1 ) ( ๐ 0 , ๐ 1 ,โฆ, ๐ ๐/2โ1 ) โ๐น๐น๐ ๐ฅ 0 , ๐ฅ 2 ,โฆ, ๐ฅ ๐โ2 ( ๐ 0 , ๐ 1 ,โฆ, ๐ ๐/2โ1 ) โ๐น๐น๐ ๐ฅ 1 , ๐ฅ 3 ,โฆ, ๐ฅ ๐โ1 ๐โ1 for ๐โ0 to ๐/2โ1: ๐กโ๐ ๐ ๐ ๐ฆ ๐ โ ๐ ๐ +๐ก ๐ฆ ๐/2+๐ โ ๐ ๐ โ๐ก ๐โ๐ ๐ ๐ // Can be precomputed return ๐ฆ 0 , ๐ฆ 1 ,โฆ, ๐ฆ ๐โ1
21
Complexity of the FFT ๐(๐) โ Cost of an FFT of size ๐.
๐ ๐ =2๐ ๐/2 +๐(๐) ๐ ๐ =๐(๐ log ๐ ) ๐ด(๐) โ Number of additions/subtractions in ๐น๐น ๐ ๐ ๐(๐) โ Number of (complex) multiplications in ๐น๐น ๐ ๐ ๐ด 2 =2 ๐ 2 =0 ๐ด ๐ =2๐ด ๐/2 +๐ ๐ ๐ =2๐ ๐/2 +๐/2 ๐ ๐ = ๐ 2 log 2 ๐ 2 ๐ด ๐ =๐ log 2 ๐
22
A butterfly ๐ ๐+๐๐ + โTwiddle factorโ ๐ ๐ ๐โ๐๐ ๏ด ๏ญ ๐ ๐ ๐ ๐+๐๐ ๐โ๐๐
23
An FFT circuit ๐น 4 ๐น 4 Input permuted! ๐ฅ 0 ๐ฅ 4 ๐ฅ 6 ๐ฅ 1 ๐ฅ 3 ๐ฅ 5 ๐ฅ 2 ๐ฅ 7
๐ฆ 0 ๐ฆ 2 ๐ฆ 3 ๐ฆ 4 ๐ฆ 5 ๐ฆ 6 ๐ฆ 1 ๐ฆ 7 ๐น 4 ๐ 8 0 ๐ 8 1 ๐ 8 2 ๐ 8 3 ๐น 4
24
Input further permuted!
An FFT circuit Input further permuted! ๐ฅ 0 ๐ฅ 2 ๐ฅ 6 ๐ฅ 1 ๐ฅ 5 ๐ฅ 3 ๐ฅ 4 ๐ฅ 7 ๐น 2 ๐ 4 0 ๐ 4 1 ๐ฆ 0 ๐ฆ 2 ๐ฆ 3 ๐ฆ 4 ๐ฆ 5 ๐ฆ 6 ๐ฆ 1 ๐ฆ 7 ๐ 8 0 ๐ 8 1 ๐ 8 2 ๐ 8 3 ๐น 2 ๐ 4 0 ๐ 4 1
25
An FFT circuit Input permuted! ๐ฅ 0 ๐ฆ 0 ๐ 2 0 ๐ฅ 4 ๐ 4 0 ๐ฆ 1 ๐ฅ 2 ๐ฆ 2
๐ฅ 6 ๐ฅ 1 ๐ฅ 5 ๐ฅ 3 ๐ฅ 4 ๐ฅ 7 ๐ฆ 0 ๐ฆ 2 ๐ฆ 3 ๐ฆ 4 ๐ฆ 5 ๐ฆ 6 ๐ฆ 1 ๐ฆ 7 ๐ 2 0 ๐ 4 0 ๐ 8 0 ๐ 4 1 ๐ 8 1 ๐ 2 0 ๐ 8 2 ๐ 8 3 ๐ 2 0 ๐ 4 0 ๐ 4 1 ๐ 2 0
26
Bit-reversal permutation
An FFT circuit Bit-reversal permutation ๐ฅ 0 ๐ฅ 2 ๐ฅ 6 ๐ฅ 1 ๐ฅ 5 ๐ฅ 3 ๐ฅ 4 ๐ฅ 7 ๐ฅ 0 ๐ฆ 0 ๐ฆ 2 ๐ฆ 3 ๐ฆ 4 ๐ฆ 5 ๐ฆ 6 ๐ฆ 1 ๐ฆ 7 ๐ 2 0 ๐ 4 0 ๐ 8 0 ๐ฅ 1 ๐ 4 1 ๐ 8 1 ๐ฅ 2 ๐ 2 0 ๐ 8 2 ๐ฅ 3 ๐ 8 3 ๐ฅ 4 ๐ 2 0 ๐ 4 0 ๐ฅ 5 ๐ 4 1 ๐ฅ 6 ๐ 2 0 ๐ฅ 7
27
Bit-reversal permutation
An FFT circuit Bit-reversal permutation ๐ฅ 0 ๐ฅ 2 ๐ฅ 6 ๐ฅ 1 ๐ฅ 5 ๐ฅ 3 ๐ฅ 4 ๐ฅ 7 ๐ฅ 0 ๐ฆ 0 ๐ฆ 2 ๐ฆ 3 ๐ฆ 4 ๐ฆ 5 ๐ฆ 6 ๐ฆ 1 ๐ฆ 7 ๐ 2 0 ๐ 4 0 ๐ฅ 1 ๐ 4 1 ๐ฅ 2 ๐ 2 0 ๐ฅ 3 ๐ฅ 4 ๐ 2 0 ๐ 4 0 ๐ฅ 5 ๐ 4 1 ๐ฅ 6 ๐ 2 0 ๐ฅ 7
28
FFT and Algorithm Engineering
In real life, constant factors matter. A tremendous amount of work was invested is optimizing the performance of FFT algorithms on specific architectures. The algorithm we saw is a radix-2 FFT. Radix-4 and varying radices work better in practice. A good FFT implementation should use cache and memory cleverly, and use parallelism if possible.
29
Decomposing the DFT (I)
๐ ๐ ๐โ
2๐ = ๐ ๐/2 ๐๐ ๐ ๐ ๐โ
(2๐+1) = ๐ ๐ ๐ โ
๐ ๐/2 ๐๐ ๐ ๐ ( ๐ 2 +๐)โ
2๐ = ๐ ๐/2 ๐๐ ๐ ๐ ( ๐ 2 +๐)โ
(2๐+1) = โ ๐ ๐ ๐ โ
๐ ๐/2 ๐๐ This gives the algorithm we have seen.
30
Decomposing the DFT (II)
๐ ๐ 2๐โ
๐ = ๐ ๐/2 ๐๐ ๐ ๐ (2๐+1)โ
๐ = ๐ ๐/2 ๐๐ โ
๐ ๐ ๐ ๐ ๐ 2๐โ
( ๐ 2 +๐) = ๐ ๐/2 ๐๐ ๐ ๐ (2๐+1)โ
( ๐ 2 +๐) = ๐ ๐ 2 ๐๐ โ
(โ ๐ ๐ ๐ ) This gives an alternative algorithm.
31
The Inverse DFT The inverse DFT is very similar to the DFT:
๐ฅ 0 ๐ฅ 1 โฎ ๐ฅ ๐โ1 = 1 ๐ โฎ โฏ ๐ ๐ โ๐๐ โฏ โฎ ๐ฆ 0 ๐ฆ 1 โฎ ๐ฆ ๐โ1 To prove it, we need show that โ=0 ๐โ1 ๐ ๐ ๐โ ๐ ๐ โโ๐ = ๐ if ๐=๐ 0 otherwise (Recall that if ๐ถ=๐ด๐ต, then ๐ ๐,๐ = โ=0 ๐โ1 ๐ ๐,โ ๐ โ,๐ .)
32
The Inverse DFT โ=0 ๐โ1 ๐ ๐ ๐โ ๐ ๐ โโ๐ = ๐ if ๐=๐ 0 otherwise
If ๐=๐, then ๐ ๐ ๐โ ๐ ๐ โโ๐ =1, so the claim is obvious. If ๐โ ๐, and 0โค๐,๐<๐, then: โ=0 ๐โ1 ๐ ๐ ๐โ ๐ ๐ โโ๐ = โ=0 ๐โ1 ๐ ๐ (๐โ๐)โ = ๐ ๐ ๐โ๐ ๐ โ1 ๐ ๐ ๐โ๐ โ1 =0 as ๐ ๐ ๐โ๐ ๐ = ๐ ๐ ๐ ๐โ๐ =1, while ๐ ๐ ๐โ๐ โ 1. (Recall that if ๐โ 1, then โ=0 ๐โ1 ๐ โ = ๐ ๐ โ1 ๐โ1 .)
33
๐ท๐น ๐ โ1 as polynomial interpolation
๐ท๐น๐(๐ฑ) evaluates the polynomial ๐ ๐ง = ๐=0 ๐โ1 ๐ฅ ๐ ๐ง ๐ corresponding to ๐ฑ at the points 1, ๐ ๐ , ๐ ๐ 2 ,โฆ, ๐ ๐ ๐โ1 . ๐ท๐น ๐ โ1 (๐ฒ) interpolates the coefficients of a polynomial ๐ ๐ง = ๐=0 ๐โ1 ๐ฅ ๐ ๐ง ๐ such that ๐( ๐ ๐ ๐ ) = ๐ฆ ๐ , ๐=0,โฆ,๐โ1. As ๐ท๐น๐ and ๐ท๐น ๐ โ1 are inverses of each other, the interpolation polynomial is unique. Interpolation Theorem: For any sequence ๐ผ 0 , ๐ผ 1 ,โฆ, ๐ผ ๐ of distinct numbers, and any sequence ๐ฆ 0 , ๐ฆ 1 ,โฆ, ๐ฆ ๐ , there is a unique polynomial ๐ ๐ง = ๐=0 ๐โ1 ๐ฅ ๐ ๐ง ๐ of degree less than ๐ such that ๐ ๐ผ ๐ = ๐ฆ ๐ , for ๐=0,1,โฆ,๐โ1.
34
Change of basis The standard basis of โ ๐ is ๐ 0 , ๐ 1 ,โฆ, ๐ ๐โ1 . ๐ฑ= ๐ฅ 0 , ๐ฅ 1 ,โฆ, ๐ฅ ๐โ1 ๐ = ๐=0 ๐โ1 ๐ฅ ๐ ๐ ๐ Let ๐ 0 , ๐ 1 ,โฆ, ๐ ๐โ1 โ โ ๐ be a basis of โ ๐ , i.e., a sequence of ๐ linearly independent vectors. Then, ๐ฑ= ๐=0 ๐โ1 ๐ฅ ๐ ๐ ๐ , for some ๐ฅ 0 , ๐ฅ 1 ,โฆ, ๐ฅ ๐โ1 that can be obtained by solving a system of linear equations: ๐ฅ 0 ๐ฅ 1 โฎ ๐ฅ ๐โ1 = | | | ๐ 0 ๐ 1 โฏ ๐ ๐โ1 | | | ๐ฅ ๐ฅ 1 โฎ ๐ฅ ๐โ1
35
Orthonormal basis ๐ ๐ ,๐ ๐ = ๐ ๐ โ ๐ ๐ = 1 if ๐=๐ 0 otherwise
A basis ๐ 0 , ๐ 1 ,โฆ, ๐ ๐โ1 โ โ ๐ is orthonormal if ๐ ๐ ,๐ ๐ = ๐ ๐ โ ๐ ๐ = 1 if ๐=๐ 0 otherwise ๐ฑ= ๐ฅ 0 ๐ฅ 1 โฎ ๐ฅ ๐โ ๐ฑ โ =[ ๐ฅ 0 โ ๐ฅ 1 โ โฆ ๐ฅ ๐โ1 โ ] Conjugate transpose ๐ฅ=๐+๐๐ ๐ฅ โ =๐โ๐๐
36
Orthonormal basis If ๐ 0 , ๐ 1 ,โฆ, ๐ ๐โ1 โ โ ๐ is orthonormal then | | | ๐ 0 ๐ 1 โฏ ๐ ๐โ1 | | | โ1 = ๏พ ๐ 0 โ ๏พ ๏พ ๐ 1 โ ๏พ โฎ ๏พ ๐ ๐โ1 โ ๏พ ๐ฅ ๐ฅ 1 โฎ ๐ฅ ๐โ1 = ๏พ ๐ 0 โ ๏พ ๏พ ๐ 1 โ ๏พ โฎ ๏พ ๐ ๐โ1 โ ๏พ ๐ฅ 0 ๐ฅ 1 โฎ ๐ฅ ๐โ1 ๐ฅ ๐ = ๐ ๐ ,๐ฑ =๐ ๐ โ ๐ฑ
37
The Fourier basis ๐ ๐ = 1 ๐ 1, ๐ ๐ โ๐ , ๐ ๐ โ2๐ ,โฆ, ๐ ๐ โ ๐โ1 ๐ ๐
๐ ๐ = 1 ๐ 1, ๐ ๐ โ๐ , ๐ ๐ โ2๐ ,โฆ, ๐ ๐ โ ๐โ1 ๐ ๐ ๐ ๐ โ ๐ ๐ = 1 if ๐=๐ 0 otherwise The Fourier basis is orthonormal. The DFT performs a change of basis, from the standard basis to the Fourier basis. (If we multiply the result by 1 ๐ .) The minus signs can be removed from the definition of the basis vectors ๐ ๐ and moved into the DFT matrix.
38
Why did the โsignal processingโ examples work?
Exercise: Let ๐ฑ= ๐ 0 ,๐ ,โฆ,๐ , where ๐ ๐ฅ = sin 9 2๐๐ฅ sin 2 2๐๐ฅ +2 cos 2๐๐ฅ . What is ๐ท๐น๐(๐ฑ) ? Hint: No complicated calculations are required. Use the facts that sin ๐ฅ = 1 2๐ ๐ ๐๐ฅ โ ๐ โ๐๐ฅ , and similar relations. Note: The values shown on slide 14 are normalized absolute values.
39
A butterfly and its inverse
+ ๏ญ ๏ด ๐ ๐ ๐ ๐=๐+๐๐ ๐=๐โ๐๐ ๏ด + ๏ญ ๐ โ1 ๐+๐=2๐ ๐ โ1 ๐โ๐ =2๐ ๐=๐+๐๐ ๐=๐โ๐๐ To compute ๐น๐น ๐ โ1 we can also run the ๐น๐น๐ network backwards. This also gives the alternative ๐น๐น๐ network.
40
Convolution ๐ฑ= ๐ฅ 0 , ๐ฅ 1 ,โฆ, ๐ฅ ๐โ1 ๐ณ=๐ฑโ๐ ๐ฒ= ๐ฆ 0 , ๐ฆ 1 ,โฆ, ๐ฆ ๐โ1
๐ฑ= ๐ฅ 0 , ๐ฅ 1 ,โฆ, ๐ฅ ๐โ1 ๐ณ=๐ฑโ๐ ๐ฒ= ๐ฆ 0 , ๐ฆ 1 ,โฆ, ๐ฆ ๐โ1 ๐ณ= ๐ง 0 , ๐ง 1 ,โฆ, ๐ง 2๐โ1 ๐ง ๐ = ๐+๐=๐ ๐ฅ ๐ ๐ฆ ๐ = ๐ ๐ฅ ๐ ๐ฆ ๐โ๐ max 0,๐โ๐ โค๐โคminโก{๐,๐} Naturally extends to ๐ฑ and ๐ฒ having different length.
41
Convolution ๐ฑ= ๐ฅ 0 , ๐ฅ 1 ,โฆ, ๐ฅ ๐โ1 ๐ณ=๐ฑโ๐ ๐ฒ= ๐ฆ 0 , ๐ฆ 1 ,โฆ, ๐ฆ ๐โ1
๐ฑ= ๐ฅ 0 , ๐ฅ 1 ,โฆ, ๐ฅ ๐โ1 ๐ณ=๐ฑโ๐ ๐ฒ= ๐ฆ 0 , ๐ฆ 1 ,โฆ, ๐ฆ ๐โ1 ๐ณ= ๐ง 0 , ๐ง 1 ,โฆ, ๐ง 2๐โ1 ๐ง ๐ = ๐+๐=๐ ๐ฅ ๐ ๐ฆ ๐ ๐ง 0 = ๐ฅ 0 ๐ฆ 0 ๐ง 1 = ๐ฅ 0 ๐ฆ 1 + ๐ฅ 1 ๐ฆ 0 ๐ง 2 = ๐ฅ 0 ๐ฆ 2 + ๐ฅ 1 ๐ฆ 1 + ๐ฅ 2 ๐ฆ 0 ๐ง 3 = ๐ฅ 0 ๐ฆ 3 + ๐ฅ 1 ๐ฆ 2 + ๐ฅ 2 ๐ฆ 1 + ๐ฅ 3 ๐ฆ 0 ๐ง 4 = ๐ฅ 1 ๐ฆ 3 + ๐ฅ 2 ๐ฆ 2 + ๐ฅ 3 ๐ฆ 1 ๐ง 5 = ๐ฅ 2 ๐ฆ 3 + ๐ฅ 3 ๐ฆ 2 Example: ๐=4 ๐ง 6 = ๐ฅ 3 ๐ฆ 3 For convenience ๐ง 7 =0
42
Convolution ๐ฅ 0 ๐ฅ 1 ๐ฅ 2 ๐ฅ 3 ๐ฆ 3 ๐ฆ 2 ๐ฆ 1 ๐ฆ 0 ๐ฆ 0 ๐ฆ 1 ๐ฆ 2 ๐ฆ 3 Reverse ๐ฒ.
Shift ๐ฒ to starting position. Compute products for each aligment.
43
Convolution ๐ฅ 0 ๐ฅ 1 ๐ฅ 2 ๐ฅ 3 ๐ฆ 3 ๐ฆ 2 ๐ฆ 1 ๐ฆ 0 ๐ง 0 = ๐ฅ 0 ๐ฆ 0
๐ง 0 = ๐ฅ 0 ๐ฆ 0 ๐ง 1 = ๐ฅ 0 ๐ฆ 1 + ๐ฅ 1 ๐ฆ 0 ๐ง 2 = ๐ฅ 0 ๐ฆ 2 + ๐ฅ 1 ๐ฆ 1 + ๐ฅ 2 ๐ฆ 0 ๐ง 3 = ๐ฅ 0 ๐ฆ 3 + ๐ฅ 1 ๐ฆ 2 + ๐ฅ 2 ๐ฆ 1 + ๐ฅ 3 ๐ฆ 0 ๐ง 4 = ๐ฅ 1 ๐ฆ 3 + ๐ฅ 2 ๐ฆ 2 + ๐ฅ 3 ๐ฆ 1 ๐ง 5 = ๐ฅ 2 ๐ฆ 3 + ๐ฅ 3 ๐ฆ 2 ๐ง 6 = ๐ฅ 3 ๐ฆ 3
44
Convolution and polynomial multiplication
๐ด ๐ฅ = ๐=0 ๐โ1 ๐ ๐ ๐ฅ ๐ ๐ต ๐ฅ = ๐=0 ๐โ1 ๐ ๐ ๐ฅ ๐ ๐ถ ๐ฅ =๐ด ๐ฅ ๐ต ๐ฅ = ๐=0 ๐โ1 ๐ ๐ ๐ฅ ๐ ๐=0 ๐โ1 ๐ ๐ ๐ฅ ๐ = ๐=0 2๐โ2 ๐+๐=๐ ๐ ๐ ๐ ๐ ๐ฅ ๐ = ๐=0 2๐โ1 ๐ ๐ ๐ฅ ๐ ๐=๐โ๐
45
๐ง ๐ = ๐+๐โก๐ mod ๐ ๐ฅ ๐ ๐ฆ ๐ = ๐+๐=๐ ๐ฅ ๐ ๐ฆ ๐ + ๐+๐=๐+๐ ๐ฅ ๐ ๐ฆ ๐
Cyclic Convolution ๐ฑ= ๐ฅ 0 , ๐ฅ 1 ,โฆ, ๐ฅ ๐โ1 ๐ณ=๐ฑโ๐ ๐ฒ= ๐ฆ 0 , ๐ฆ 1 ,โฆ, ๐ฆ ๐โ1 ๐ณ= ๐ง 0 , ๐ง 1 ,โฆ, ๐ง ๐โ1 ๐ง ๐ = ๐+๐โก๐ mod ๐ ๐ฅ ๐ ๐ฆ ๐ = ๐+๐=๐ ๐ฅ ๐ ๐ฆ ๐ + ๐+๐=๐+๐ ๐ฅ ๐ ๐ฆ ๐ ๐ง 0 = ๐ฅ 0 ๐ฆ 0 + ๐ฅ 1 ๐ฆ 3 + ๐ฅ 2 ๐ฆ 2 + ๐ฅ 3 ๐ฆ 1 Example: ๐=4 ๐ง 1 = ๐ฅ 0 ๐ฆ 1 + ๐ฅ 1 ๐ฆ 0 + ๐ฅ 2 ๐ฆ 3 + ๐ฅ 3 ๐ฆ 2 ๐ง 2 = ๐ฅ 0 ๐ฆ 2 + ๐ฅ 1 ๐ฆ 1 + ๐ฅ 2 ๐ฆ 0 + ๐ฅ 3 ๐ฆ 3 ๐ง 3 = ๐ฅ 0 ๐ฆ 3 + ๐ฅ 1 ๐ฆ 2 + ๐ฅ 2 ๐ฆ 1 + ๐ฅ 3 ๐ฆ 0
46
Convolution ๏ Cyclic Convolution
Cyclic convolutions can be computed using ๐น๐น๐ and ๐น๐น ๐ โ1 . Convolutions can be reduced to cyclic convolutions by padding. ๐ ๐ฑโฒ= ๐ฅ 0 , ๐ฅ 1 ,โฆ, ๐ฅ ๐โ1 ,0,0,โฆ,0 ๐ฒโฒ= ๐ฆ 0 , ๐ฆ 1 ,โฆ, ๐ฆ ๐โ1 ,0,0,โฆ,0 ๐ฑโ๐ฒ=๐ฑโฒโ๐ฒโฒ
47
The Convolution Theorem
๐ฑโ๐ฒ= ๐ท๐น๐ โ1 ๐ท๐น๐ ๐ฑ โ๐ท๐น๐ ๐ฒ Point-wise multiplication Cyclic convolution Proof idea: Let ๐๐ ๐ง = ๐=0 ๐โ1 ๐+๐โก๐ ๐ฅ ๐ ๐ฆ ๐ ๐ง ๐ be the polynomial corresponding to ๐ฑโ๐ฒ. We show that ๐๐ ๐ ๐ โ =๐ ๐ ๐ โ ๐ ๐ ๐ โ , for every โ=0,1,โฆ,๐โ1.
48
Proof of Convolution Theorem
Let ๐= ๐ ๐ . ๐ ๐ โ ๐ ๐ โ = ๐=0 ๐โ1 ๐ฅ ๐ ๐ โ๐ ๐=0 ๐โ1 ๐ฆ ๐ ๐ โ๐ = ๐=0 2๐โ2 ๐+๐=๐ ๐ฅ ๐ ๐ฆ ๐ ๐ โ๐ = ๐=0 ๐โ1 ๐+๐โก๐ ๐ฅ ๐ ๐ฆ ๐ ๐ โ๐ =๐๐ ๐ โ As ๐ โ ๐+๐ = ๐ โ๐ . The claim follows as the interpolation polynomial is unique. Uniqueness follows from the fact that DFT is invertible. (BTW, ๐๐ ๐ง = ๐=0 ๐โ1 ๐+๐โก๐ ๐ฅ ๐ ๐ฆ ๐ ๐ง ๐ =๐ ๐ง ๐ ๐ง (mod ๐ฅ ๐ โ1).)
49
The Chirp Transform Let ๐ง be an arbitrary (but fixed) complex number.
The Chirp transform of ๐ฑโ โ ๐ , w.r.t. ๐ง, is: ๐ฆ ๐ = ๐=0 ๐โ1 ๐ฅ ๐ ๐ง ๐๐ =๐ ๐ง ๐ ๏ฌ ๐=0,1,โฆ,๐โ1 Exercise: Show that the Chirp transform, for any ๐งโโ, can be computed in ๐ ๐ log ๐ time. Hint: use the relation: ๐ฆ ๐ = ๐ง ๐ 2 /2 ๐=0 ๐โ1 ๐ฅ ๐ ๐ง ๐ 2 /2 ๐ง โ ๐โ๐ 2 /2 ๏ฌ ๐=0,1,โฆ,๐โ1 Exercise: Show that ๐ท๐น๐ of size ๐ can be computed in ๐ ๐ log ๐ time for every ๐, not necessarily a power of 2.
50
Polynomial arithmetic
Let ๐ด ๐ฅ = ๐=0 ๐โ1 ๐ ๐ ๐ฅ ๐ and ๐ต ๐ฅ = ๐=0 ๐โ1 ๐ ๐ ๐ฅ ๐ be two polynomials of degree less than ๐, with real or complex coefficients. The coefficients of ๐ด ๐ฅ +๐ต(๐ฅ) can be easily computed using ๐ additions. A naรฏve computations of the coefficients of ๐ด ๐ฅ ๐ต(๐ฅ) requires ฮ ๐ 2 operations. Using FFT we can compute the coefficients of ๐ด ๐ฅ ๐ต(๐ฅ) using only ฮ ๐ log ๐ operations!
51
Karatsubaโs algorithm
When ๐ is only moderately large, the following polynomial multiplication algorithm works better in practice. ๐ด ๐ฅ = ๐ด 0 ๐ฅ + ๐ฅ ๐/2 ๐ด 1 ๐ฅ ๐ต ๐ฅ = ๐ต 0 ๐ฅ + ๐ฅ ๐/2 ๐ต 1 ๐ฅ ๐ถ 0 ๐ฅ = ๐ด 0 (๐ฅ)๐ต 0 ๐ฅ ๐ถ 1 ๐ฅ = ( ๐ด 0 ๐ฅ +๐ด 1 ๐ฅ ) ( ๐ต 0 ๐ฅ +๐ต 1 ๐ฅ ) ๐ถ 2 ๐ฅ = ๐ด 1 (๐ฅ)๐ต 1 ๐ฅ ๐ด ๐ฅ ๐ต ๐ฅ = ๐ถ 0 ๐ฅ + ๐ฅ ๐/2 ๐ถ 1 ๐ฅ โ ๐ถ 0 ๐ฅ โ ๐ถ 2 ๐ฅ + ๐ฅ ๐ ๐ถ 2 (๐ฅ) ๐ ๐ =3 ๐ ๐ 2 +๐(๐) ๐ ๐ =๐ ๐ log =๐( ๐ 1.59 )
52
Numerical issues So far, we assumed that all arithmetical operations are exact. This is not a realistic assumption, as ๐ ๐ is usually irrational. The FFT algorithm is well-behaved numerically. The errors introduced if all operations are done using floating-point arithmetic are relatively small. In signal processing applications small errors are acceptable.
53
Integer Polynomial Multiplication
We now want to add and multiply polynomials with integer coefficients. We want an exact result. If we use high enough precision, we can use ๐น๐น๐ and ๐น๐น ๐ โ1 and round the results obtained to the nearest integers. To multiply two polynomials of degree at most ๐ with integer coefficients of absolute value at most ๐, ๐( log ๐ ) bits of precision are enough. (Proof omitted.)
54
Integer Multiplication
There are practical applications, e.g., cryptography, that require multiplying very large integers. The naรฏve method for multiplying two ๐-bit numbers requires ฮ ๐ 2 bit operations. Can we use FFTs to obtain a aster integer multiplication algorithm/circuit? Yes, as integer multiplication can be reduced to polynomial multiplication.
55
Schรถnhage-Strassenโs algorithm
Basic idea ๐ฑ= ๐ฅ ๐โ1 โฆ ๐ฅ 1 ๐ฅ = ๐=0 ๐โ1 ๐ฅ ๐ 2 ๐ =๐ 2 ๐ฒ= ๐ฆ ๐โ1 โฆ ๐ฆ 1 ๐ฆ = ๐=0 ๐โ1 ๐ฆ ๐ 2 ๐ =๐ 2 Compute ๐ ๐ก =๐ ๐ก ๐(๐ก) (polynomial multiplication) ๐ฑโ๐ฒ=๐ณ= ๐ง 2๐โ1 โฆ ๐ง 1 ๐ง = ๐=0 2๐โ1 ๐ง ๐ 2 ๐ =๐ 2 We are not done yet, as the ๐ง ๐ are not binary. But, as 0โค ๐ง ๐ <๐ this is not a serious problem. Some clever tricks are used to speed-up the algorithm. The first trick is to use base ๐= 2 ๐ rather than 2.
56
Schรถnhage-Strassenโs algorithm
๐= log ๐ ๐ ๐= 2 ๐ ๐ฅ ๐/๐โ1 ๐ฅ ๐/๐โ2 โฆ ๐ฅ 1 ๐ฅ 0 ๐ฑ= ๐ฆ ๐/๐โ1 ๐ฆ ๐/๐โ2 ๐ฆ 1 ๐ฆ 0 ๐ฒ= ๐ฑ= ๐ฅ ๐/๐โ1 โฆ ๐ฅ 1 ๐ฅ 0 ๐ = ๐=0 ๐/๐โ1 ๐ฅ ๐ 2 ๐๐ =๐ 2 ๐ ๐ฒ= ๐ฆ ๐/๐โ1 โฆ ๐ฆ 1 ๐ฆ 0 ๐ = ๐=0 ๐/๐โ1 ๐ฆ ๐ 2 ๐๐ =๐ 2 ๐ Compute ๐ ๐ก =๐ ๐ก ๐(๐ก) (polynomial multiplication) ๐ฑโ๐ฒ=๐ณ= ๐ง 2๐/๐โ1 โฆ ๐ง 1 ๐ง 0 ๐ = ๐=0 2๐/๐โ1 ๐ง ๐ 2 ๐๐ =๐ 2 ๐
57
Schรถnhage-Strassenโs algorithm
๐ฑ = ๐=0 ๐/๐โ1 ๐ฅ ๐ 2 ๐๐ ๐ฒ = ๐=0 ๐/๐โ1 ๐ฆ ๐ 2 ๐๐ ๐ณ = ๐=0 2๐/๐โ1 ๐ง ๐ 2 ๐๐ ๐ง ๐ = ๐+โ=๐ ๐ฅ ๐ ๐ฆ โ 0โค ๐ฅ ๐ , ๐ฆ ๐ < 2 ๐ =๐ โค๐ง ๐ < ๐/logโก๐ ๐ 2 < ๐ 3 Each ๐ง ๐ is a 3-digit number in base ๐. We can thus pack all the ๐ง ๐ into 3 long integers. Adding these 3 integers gives us the final answer.
58
Schรถnhage-Strassenโs algorithm
The final step 3๐= 3 log ๐ ๐= log ๐ โฆ ๐ง 3 ๐ง 0 โฆ ๐ง 4 ๐ง 1 โฆ ๐ง 5 ๐ง 2 Adding 3 2๐-bit numbers can be easily done using ๐(๐) bit operations.
59
Schรถnhage-Strassenโs algorithm
To multiply two ๐-bit numbers, we compute two ๐น๐น๐s and one ๐น๐น ๐ โ1 of size ๐/๐=๐/logโก๐. Each input number is an integer between 0 and ๐โ1. Each output number is an integer between 0 and ๐ 3 โ1. It is enough to perform all arithmetical operations using a precision of ๐( log ๐) bits. (Stated without proof.) Let ๐ ๐ be the total number of bit operations performed. ๐ ๐ =๐ ๐ log ๐ log ๐ log ๐ ร๐ ๐ log ๐ =O(๐ ๐(๐( log ๐))) Number of arithmetical operations in an ๐น๐น๐ of size ๐/ log ๐ . Number of bit operations per each arithmetical operation.
60
Schรถnhage-Strassenโs algorithm
๐ ๐ =๐ ๐ 2 ๐ ๐ =O(๐ ๐(๐( log ๐))) ๐ ๐ =๐ ๐ log ๐ 2 ๐ ๐ =๐ ๐ log ๐ log log ๐ 2 ๐ ๐ =๐ ๐ log ๐ (log log ๐ ) log log log ๐ 2 โฎ
61
Integer Multiplication
[Schรถnhage-Strassen (1971)] obtained an improved version of their algorithm with a running time of ??? ๐ ๐ =๐ ๐ log ๐ ( log log ๐ ) Improvement obtained by performing the ๐น๐น๐s in a suitable integer ring in which ๐=2 is a primitive root of unity. Multiplications by powers of ๐ are very cheap! No numerical issues! [Fรผrer (2007)] and [De-Kurur-Saha-Saptharishi (2008)] improved the running time to ๐ ๐ =๐ ๐ log ๐ 2 ๐ log โ ๐
62
String Matching abraabracadabracadabraabara abracadabra abracadabra
Given a text of length ๐ and a pattern of length ๐, find all occurrences of the pattern in the text. The naรฏve algorithm runs in ๐ ๐๐ time. Several classical algorithms run in ๐ ๐+๐ time. [Knuth-Morris-Pratt (1977)] [Boyer-Moore (1977)]
63
More String Matching Problems
abraabracadabracadabraabara abracadabra abracadabra Count the number of matches/mismatches in each alignment of the pattern with the text. Find all aligments with at most ๐ mismatches. Allow a wildcard (โdonโt careโ) (โ) that match any (single) symbol in the pattern and/or text. โTraditionalโ string matching techniques are not so efficient for these extensions.
64
(Cross-)Correlation ๐ฅ 0 ๐ฅ 1 ๐ฅ 2 ๐ฅ 3 ๐ฆ 0 ๐ฆ 1 ๐ฆ 2 ๐ฆ 3 ๐ง โ3 = ๐ฅ 0 ๐ฆ 3
๐ง โ3 = ๐ฅ 0 ๐ฆ 3 ๐ง โ2 = ๐ฅ 0 ๐ฆ 2 + ๐ฅ 1 ๐ฆ 3 ๐ง โ1 = ๐ฅ 0 ๐ฆ 1 + ๐ฅ 1 ๐ฆ 2 + ๐ฅ 2 ๐ฆ 3 ๐ง 0 = ๐ฅ 0 ๐ฆ 0 + ๐ฅ 1 ๐ฆ 1 + ๐ฅ 2 ๐ฆ 2 + ๐ฅ 3 ๐ฆ 3 ๐ง 1 = ๐ฅ 1 ๐ฆ 0 + ๐ฅ 2 ๐ฆ 1 + ๐ฅ 3 ๐ฆ 2 ๐ง 2 = ๐ฅ 2 ๐ฆ 0 + ๐ฅ 3 ๐ฆ 1 ๐ง 3 = ๐ฅ 3 ๐ฆ 0
65
(Cross-)Correlation ๐ง ๐ = ๐ ๐ฅ ๐ ๐ฆ ๐โ๐ = ๐ ๐ฅ ๐+๐ ๐ฆ ๐ = ๐ฑโ ๐ฒ ๐
๐+๐โ1
A convolution without the initial reversal, with a shift of indices. ๐ง ๐ = ๐ ๐ฅ ๐ ๐ฆ ๐โ๐ = ๐ ๐ฅ ๐+๐ ๐ฆ ๐ = ๐ฑโ ๐ฒ ๐
๐+๐โ1 If ๐ฑ is of length ๐ and ๐ฒ of length ๐, where ๐โค๐, then ๐=1โ๐,โฆ,๐โ1. Sometimes, only the values ๐=0,โฆ,๐โ๐, corresponding to a full overlap of ๐ฑ with a shift of ๐ฒ, are of interest. The correlation of two vectors of length ๐ can be computed in ๐ ๐ log ๐ time. Exercise: The correlation of two vectors of length ๐ and ๐, where ๐โค๐, can be computed in ๐ ๐ log ๐ time.
66
Counting mismatches [Fischer-Paterson (1974)]
Let ฮฃ be the alphabet of the pattern and text. We may assume that ฮฃ โค๐+1. (Why?) For every ๐โฮฃ create two Boolean strings: ๐ ๐ ๐ =1 iff ๐ ๐ =๐ ๐ ๐ ๐ =1 iff ๐ ๐ โ ๐ Correlation of ๐ ๐ and ๐ ๐ counts mismatches involving ๐. Summing over all ๐โฮฃ we get the total no. of mismatches. Complexity: ๐( ฮฃ ๐ log ๐ ) word operations. (Each word assumed to hold ฮ log ๐ bits.) Fast only if ฮฃ is small.
67
Counting mismatches with wildcards [Fischer-Paterson (1974)]
For every ๐โฮฃ create two Boolean strings: ๐ ๐ ๐ =1 iff ๐ ๐ =๐ ๐ ๐ ๐ =1 iff ๐ ๐ โ ๐ and ๐ ๐ โ โ Complexity: ๐( ฮฃ ๐ log ๐ ) word operations. If we only want to find exact matches, replace each character ๐โฮฃ by a log 2 |ฮฃ| bit string. Complexity drops to ๐( log ฮฃ ๐ log ๐ ). Can we get rid of the dependence on |ฮฃ| ?
68
๐ฟ 2 -matching [Lipsky-Porat (2011)]
Standard string matching uses the Hamming distance. Two characters either match or they do not. ๐ is not closer to ๐ than to ๐ง. Suppose that each โcharacterโ is a real number. We want to find approximate matches. For each ๐=0,1,โฆ,๐โ๐ we want to compute ๐ ๐ = ๐=0 ๐โ1 ๐ ๐ โ ๐ก ๐+๐ 2 ๐ฟ 2 -distance: ๐ฑโ๐ฒ 2 = ๐=0 ๐โ1 ๐ฅ ๐ โ ๐ฆ ๐ 2
69
๐ฟ 2 -matching can be computed in ๐(๐ log ๐ ) time.
[Lipsky-Porat (2011)] ๐=0 ๐โ1 ๐ ๐ โ ๐ก ๐+๐ 2 = ๐=0 ๐โ1 ๐ ๐ 2 โ2 ๐=0 ๐โ1 ๐ ๐ ๐ก ๐+๐ + ๐=0 ๐โ1 ๐ก ๐+๐ 2 Constant. ๐(๐) time. Correlation. ๐ ๐ log ๐ time. Easy in ๐ ๐ time. ๐ฟ 2 -matching can be computed in ๐(๐ log ๐ ) time.
70
Exact matches with wildcards
[Clifford-Clifford (2007)] Replace each character by a positive integer. Replace the wildcard by 0. For each ๐=0,1,โฆ,๐โ๐ compute ๐ ๐ = ๐=0 ๐โ1 ๐ ๐ ๐ก ๐+๐ ๐ ๐ โ ๐ก ๐+๐ 2 There is an exact match at position ๐ iff ๐ ๐ =0.
71
Exact matches with wildcards
[Clifford-Clifford (2007)] ๐ ๐ = ๐=0 ๐โ1 ๐ ๐ ๐ก ๐+๐ ๐ ๐ โ ๐ก ๐+๐ 2 = ๐=0 ๐โ1 ๐ ๐ 3 ๐ก ๐+๐ โ2 ๐=0 ๐โ1 ๐ ๐ 2 ๐ก ๐+๐ 2 + ๐=0 ๐โ1 ๐ ๐ ๐ก ๐+๐ 3 Compute three correlations of appropriate sequences in ๐ ๐ log ๐ time. Running time is independent of |ฮฃ| ! Assuming that each character fits in an ฮ log ๐ -bit word and that operations on such words takes constant time.
72
Not covered in class this term
Bonus material Not covered in class this term โCareful. We donโt want to learn from this.โ (Calvin in Bill Wattersonโs โCalvin and Hobbesโ)
73
Continuous Fourier Transform
If ๐:โโโ, then its Fourier transform ๐ :โโโ is: ๐ (๐ฆ)= โโ โ ๐(๐ฅ) ๐ โ2๐๐๐ฅ๐ฆ ๐๐ฅ ๐(๐ฅ)= โโ โ ๐ (๐ฆ) ๐ 2๐๐๐ฅ๐ฆ ๐๐ฆ (Some conditions apply.)
74
Fourier series ๐ ๐ฅ = ๐=โโ โ ๐ ๐ ๐ ๐๐๐ฅ ๐ ๐ = 1 2๐ โ๐ ๐ ๐ ๐ฅ ๐ โ๐๐๐ฅ ๐๐ฅ
If ๐:[โ๐,๐]โโ, then its Fourier series is: ๐ ๐ฅ = ๐=โโ โ ๐ ๐ ๐ ๐๐๐ฅ where: ๐ ๐ = 1 2๐ โ๐ ๐ ๐ ๐ฅ ๐ โ๐๐๐ฅ ๐๐ฅ (Some conditions apply.)
75
Polynomial interpolation
๐ฅ 1 , ๐ฅ 2 ,โฆ, ๐ฅ ๐ โ๐ฝ distinct ๐ฆ 1 , ๐ฆ 2 ,โฆ, ๐ฆ ๐ โ๐ฝ (not necessarily distinct) There is a unique polynomial ๐ ๐ฅ = ๐=0 ๐โ1 ๐ ๐ ๐ฅ ๐ such that ๐ ๐ฅ 1 = ๐ฆ 1 , ๐ ๐ฅ 2 = ๐ฆ 2 , โฆ, ๐ ๐ฅ ๐ = ๐ฆ ๐ which can be found by solving by solving the linear equations: 1 ๐ฅ 1 โฆ ๐ฅ 1 ๐โ1 1 ๐ฅ 2 โฆ ๐ฅ 2 ๐โ1 โฎ โฎ โฑ โฎ 1 ๐ฅ ๐ โฆ ๐ฅ ๐ ๐โ ๐ 0 ๐ 1 โฎ ๐ ๐โ1 = ๐ฆ 1 ๐ฆ 2 โฎ ๐ฆ ๐ A solution exists and is unique because the matrix, known as a Vandermonde matrix, is non-singular.
76
Vandermonde Determinant
77
Lagrange formula ๐ ๐ฅ = ๐=0 ๐โ1 ๐ฆ ๐ ๐โ ๐ ๐ฅโ ๐ฅ ๐ ๐โ ๐ ๐ฅ ๐ โ ๐ฅ ๐
๐ฅ 1 , ๐ฅ 2 ,โฆ, ๐ฅ ๐ โ๐ฝ distinct ๐ฆ 1 , ๐ฆ 2 ,โฆ, ๐ฆ ๐ โ๐ฝ (not necessarily distinct) The unique polynomial ๐ ๐ฅ = ๐=0 ๐โ1 ๐ ๐ ๐ฅ ๐ such that ๐ ๐ฅ 1 = ๐ฆ 1 , ๐ ๐ฅ 2 = ๐ฆ 2 , โฆ, ๐ ๐ฅ ๐ = ๐ฆ ๐ can be obtained as follows: ๐ ๐ฅ = ๐=0 ๐โ1 ๐ฆ ๐ ๐โ ๐ ๐ฅโ ๐ฅ ๐ ๐โ ๐ ๐ฅ ๐ โ ๐ฅ ๐
78
๐น๐น๐ decomposition Suppose that ๐= ๐ 1 ๐ 2 .
To compute an ๐น๐น๐ of ๐ numbers: Input the numbers row by row into an ๐ 1 ร ๐ 2 matrix. Do an ๐น๐น๐ of dimension ๐ 1 on each column. Multiply the ๐-th column by ๐ ๐ ๐ . Do an ๐น๐น๐ of dimension ๐ 2 on each row. Output the numbers in the matrix column by column. In the standard algorithm, ๐ 1 =๐/2 and ๐ 2 =2.
79
Raderโs ๐น๐น๐ algorithm When ๐ is prime, ๐ท๐น๐ reduces to cyclic convolution. Let ๐ be a generator of โค ๐ โ . 1,๐, ๐ 2 ,.., ๐ ๐โ2 and 1, ๐ โ1 , ๐ โ2 ,.., ๐ โ(๐โ2) , computed mod ๐, are permutations of 1,2,โฆ,๐โ1. ๐ฆ ๐ = ๐=0 ๐โ1 ๐ ๐ ๐๐ ๐ฅ ๐ = ๐ฅ 0 + ๐=0 ๐โ2 ๐ ๐ ๐ โ๐ ๐ฅ ๐ โ๐ , ๐=0,1,โฆ,๐โ1 ๐ฆ ๐ ๐ = ๐ฅ 0 + ๐=0 ๐โ2 ๐ ๐ ๐ ๐ โ๐ ๐ฅ ๐ โ๐ = ๐ฅ 0 + ๐=0 ๐โ2 ๐ ๐ ๐โ๐ ๐ฅ ๐ โ๐ , ๐=0,1,โฆ,๐โ2 ๐ฅ ๐ โฒ = ๐ฆ ๐ โ๐ , ๐ฆ ๐ โฒ = ๐ฆ ๐ ๐ โ ๐ฅ 0 , ๐ค ๐ = ๐ ๐ ๐ , ๐=0,1,โฆ,๐โ2, ๐ฒ โฒ =๐ฐโ๐ฑโฒ
80
Example: ๐=7, ๐=3 (without first row and column)
Raderโs ๐น๐น๐ algorithm Example: ๐=7, ๐=3 (without first row and column) ๐ฆ 1 ๐ฆ 2 ๐ฆ 3 ๐ฆ 4 ๐ฆ 5 ๐ฆ = ๐ 1 ๐ 2 ๐ 3 ๐ 4 ๐ 5 ๐ 6 ๐ 2 ๐ 4 ๐ 6 ๐ 1 ๐ 3 ๐ 5 ๐ 3 ๐ 6 ๐ 2 ๐ 5 ๐ 1 ๐ 4 ๐ 4 ๐ 1 ๐ 5 ๐ 2 ๐ 6 ๐ 3 ๐ 5 ๐ 3 ๐ 1 ๐ 6 ๐ 4 ๐ 2 ๐ 6 ๐ 5 ๐ 4 ๐ 3 ๐ 2 ๐ ๐ฅ 1 ๐ฅ 2 ๐ฅ 3 ๐ฅ 4 ๐ฅ 5 ๐ฅ 6 ๐ฆ 1 ๐ฆ 3 ๐ฆ 2 ๐ฆ 6 ๐ฆ 4 ๐ฆ = ๐ 1 ๐ 5 ๐ 4 ๐ 6 ๐ 2 ๐ 3 ๐ 3 ๐ 1 ๐ 5 ๐ 4 ๐ 6 ๐ 2 ๐ 2 ๐ 3 ๐ 1 ๐ 5 ๐ 4 ๐ 6 ๐ 6 ๐ 2 ๐ 3 ๐ 1 ๐ 5 ๐ 4 ๐ 4 ๐ 6 ๐ 2 ๐ 3 ๐ 1 ๐ 5 ๐ 5 ๐ 4 ๐ 6 ๐ 2 ๐ 3 ๐ ๐ฅ 1 ๐ฅ 5 ๐ฅ 4 ๐ฅ 6 ๐ฅ 2 ๐ฅ 3
81
Raderโs ๐น๐น๐ algorithm When ๐ is prime, ๐ท๐น๐ reduces to cyclic convolution. Cyclic convolution can be computed using ๐น๐น๐s of a larger size, e.g., a power of 2, by padding. We thus get an ๐ ๐ log ๐ algorithm for computing a ๐ท๐น๐ of size ๐ when ๐ is prime. When ๐ is composite, we can decompose the problem. The end result is an ๐ ๐ log ๐ algorithm for computing a ๐ท๐น๐ for any ๐. When ๐= 2 ๐ , the algorithm is most efficient.
82
Negative Cyclic Convolution
๐ง ๐ = ๐+๐=๐ ๐ฅ ๐ ๐ฆ ๐ Cyclic Convolution: ๐ง ๐ = ๐+๐โก๐ mod ๐ ๐ฅ ๐ ๐ฆ ๐ = ๐+๐=๐ ๐ฅ ๐ ๐ฆ ๐ + ๐+๐=๐+๐ ๐ฅ ๐ ๐ฆ ๐ Negative Cyclic Convolution: ๐ง ๐ = ๐+๐=๐ ๐ฅ ๐ ๐ฆ ๐ โ ๐+๐=๐+๐ ๐ฅ ๐ ๐ฆ ๐
83
Negative Cyclic Convolution
Polynomial multiplication modulo ๐ฅ ๐ +1. A naรฏve way of computing the negative cyclic convolution is to first compute the non-cyclic convolution. Let ๐ be an ๐-th primitive root of unity. Let ๐ be such that ๐ 2 =๐. ๐=(1,๐,โฆ, ๐ ๐โ1 ) , ๐ โ1 =(1, ๐ โ1 ,โฆ, ๐ โ ๐โ1 ) The negative cyclic convolution of ๐ฑ and ๐ฒ is: ๐ โ1 โ๐ท๐น ๐ โ1 ๐ท๐น๐ ๐โ๐ฑ โ๐ท๐น๐ ๐โ๐ฒ This saves a factor of 2 and plays an important role in the modular Schรถnhage-Strassen algorithm.
84
DFT and FFT in rings To define ๐ท๐น๐ and ๐ท๐น ๐ โ1 over a ring we need an primitive ๐-th root of unity ๐. If ๐ท๐น๐ and ๐ท๐น ๐ โ1 are well defined, then the ๐น๐น๐ algorithm can be used to compute them. An element ๐ is a primitive ๐-th root of unity in ๐
iff: (i) ๐ ๐ =1, (ii) ๐=0 ๐โ1 ๐ ๐๐ =0, for ๐=0,1,โฆ,๐โ1, (iii) ๐ has an inverse in ๐
. In โ, ๐ ๐ = ๐ 2๐๐/๐ is a primitive ๐-th root of unity. So is ๐ ๐ ๐ = ๐ 2๐๐๐/๐ , if ๐ is relatively prime to ๐. In โ, there is such a root only for ๐=2โฆ Are there other useful rings in which ๐ท๐น๐ can be performed?
85
๐
,โ is a commutative monoid:
Rings A (commutative) ring ๐
, โ ,+ is a set ๐
with two binary operations โ,+:๐
ร๐
โ๐
such that: ๐
,+ is an abelian group: โ๐,๐โ๐
. ๐+๐=๐+๐ โ๐,๐,๐โ๐
. ๐+ ๐+๐ = ๐+๐ +๐ โ 0โ๐
. โ ๐โ๐
. ๐+0=๐ โ ๐โ๐
. โ โ๐โ๐
. ๐+(โ๐)=0 ๐
,โ is a commutative monoid: โ๐,๐โ๐
. ๐โ๐=๐โ๐ โ๐,๐,๐โ๐
. ๐โ ๐โ๐ = ๐โ๐ โ๐ โ 1โ๐
. โ ๐โ๐
. ๐โ1=๐ Distributive law: โ๐,๐,๐โ๐
. ๐โ ๐+๐ =๐โ๐+๐โ๐
86
Rings and Fields A (commutative) ring ๐
, โ ,+ is a field if there are also multiplicative inverses: ๐
โ 0 , โ is an abelian group, not just a monoid: โ ๐โ๐
โ{0} . โ ๐ โ1 โ๐
. ๐โ ๐ โ1 =1 Examples: โ, โ ,+ - The natural numbers do not form a ring. โค, โ ,+ - The integers form a ring, but not a field. โ, โ ,+ - The real numbers form a field. โ, โ ,+ - The complex numbers form a field. More Examples: โค ๐ , โ ,+ - The integers modulo ๐ (see next slide). ๐
[๐ฅ], โ ,+ - The ring of polynomials (in ๐ฅ) over a ring. โฆ
87
Modular arithmetic ( โค ๐ = 0,1,โฆ,๐โ1 , โ ,+ )
( โค ๐ = 0,1,โฆ,๐โ1 , โ ,+ ) Addition and multiplication performed modulo ๐. For example, if ๐=12, then 7+6=1 and 4โ3=0. Lemma: โค ๐ is a ring, for every integer ๐. Theorem: โค ๐ is a field, if and only if ๐ is prime. For example, if ๐=17, then 5 โ1 =7. (Why?) Addition, multiplication modulo ๐ can be performed using addition, multiplication and division of numbers up to ๐ 2 .
88
Generators of prime fields
Theorem: If ๐ is prime, then in โค ๐ has a generator, i.e., an element ๐ such that ๐ ๐โ1 =1 but ๐ ๐ โ 1, for ๐=2,3,โฆ,๐โ2. (Fermatโs Little Theorem: If ๐ is prime, then for every ๐โ 0 in โค ๐ we have ๐ ๐โ1 =1.) 2 is not a generator of โค 17 , as 2 8 โก1 (mod 17) . But ๐=3 is a generator of โค 17 : ๐ ๐ , for ๐=1,โฆ,16 evaluates to 3, 9, 10, 13, 5, 15, 11, 16, 14, 8, 7, 4, 12, 2, 6, 1 Lemma: If ๐ is prime and ๐ | ๐โ1 and ๐=(๐โ1)/๐, then ๐= ๐ ๐ is a primitive ๐-th root of unity in โค ๐ .
89
FFT in prime fields Example: Multiply two integer polynomials of degree < 512. We need to compute ๐น๐น๐ and ๐น๐น ๐ โ1 with ๐=1024. Find a prime ๐ such that 1024 | ๐โ1. For example, ๐=12โ1024+1=12,289. But, we will get the coefficients modulo 12,289 โฆ Suppose the input coefficients are in the range 0,1,โฆ,1023. The output coefficients are in the range 0,1,โฆ, โ1. Find a prime ๐> such that 1024 | ๐โ1. For example, ๐=( )โ1024+1=1,073,750,017. (Still fits in one 32-bit word.) We can take ๐=5, and ๐= ๐ (๐โ1)/1024 =381,780,781.
90
FFT in prime fields Example: Multiply two integer polynomials of degree < 512. What do we gain by working modulo 1,073,750,017 instead of working over the complex numbers? Modular arithmetic may be more โelegantโ. We donโt have to worry about numerical errors. But, modular arithmetic is not necessarily faster than working with floating point complex numbers. We need to find appropriate prime numbers and generators. The prime number theorem: The number of prime numbers less than ๐ is about ๐/ ln ๐ .
91
FFT using modular arithmetic
To support DFT and FFT a ring does not have to be a field. The main advantage of using modular arithmetic comes from choosing rings with very special primitive roots of unity. Lemma: Let ๐ and ๐ be positive powers of 2. Then, ๐ is a primitive ๐-th root of unity in โค ๐ , where ๐= ๐ ๐/2 +1. ๐ is a power of 2. ๐ is one more than a power of 2. Multiplications by ๐ ๐ or ๐ โ๐ = ๐ ๐โ๐ are just shifts! Mod ๐ is a very simple operation. ๐โ1= ๐ ๐/2 = 2 ๐ , ๐= ๐/2 log ๐ ๐ฅ= ๐ฅ 1 2 ๐ + ๐ฅ 0 ๏ ๐ฅ mod ๐= ๐ฅ 0 โ ๐ฅ 1
92
Schรถnhage-Strassenโs algorithm
FFT performs ๐ ๐ log ๐ arithmetical operations. However, they are all either additions or multiplications by ๐ ๐ . To compute a convolution, we only need ๐ multiplications, other than multiplications by ๐ ๐ . Break two ๐-bit integers to ๐ 1 blocks of ๐ 2 -bits each. ๐ ๐ =๐ ๐ 1 log ๐ 1 ร๐ ๐( ๐ 2 ) If multiplications by ๐ ๐ are essentially additions, then ๐ ๐ =๐ ๐ 1 log ๐ 1 ๐( ๐ 2 )+ ๐ 1 ๐ ๐( ๐ 2 ) There are some technical problems to overcome. We have to choose ๐ 1 = ๐ rather than ๐ 1 =๐/ log ๐ . The end result is an integer multiplication algorithm that performs only ๐(๐ log ๐ log log ๐ ) bit operations.
93
Modular Schรถnhage-Strassen
Let ๐ข,๐ฃ be two ๐-bit integers. The algorithm computes ๐ข๐ฃ mod ( 2 ๐ +1). ๐= 2 ๐ , ๐= 2 ๐/2 , ๐=๐/๐ Break ๐ข,๐ฃ into ๐ ๐-bit blocks. Note that ๐|๐. ๐ข= ๐ข ๐โ1 2 ๐โ1 ๐ +โฆ+ ๐ข 1 2 ๐ + ๐ข 0 ๐ฃ= ๐ฃ ๐โ1 2 ๐โ1 ๐ +โฆ+ ๐ฃ 1 2 ๐ + ๐ฃ 0 ๐ข๐ฃ = ๐ฆ 2๐โ ๐โ2 ๐ +โฆ+ ๐ฆ 1 2 ๐ + ๐ฆ 0 ๐ข๐ฃ mod 2 ๐ +1 = ๐ค ๐โ1 2 ๐โ1 ๐ +โฆ+ ๐ค 1 2 ๐ + ๐ค 0 ๐ค ๐ = ๐ฆ ๐ โ ๐ฆ ๐+๐ is the negative cyclic convolution of ๐ข and ๐ฃ. โ ๐โ ๐ ๐ <๐ค ๐ < ๐ ๐ Enough to compute each ๐ค ๐ modulo 2 2๐ +1 and modulo ๐.
94
Modular Schรถnhage-Strassen
๐ค ๐ = ๐ฆ ๐ โ ๐ฆ ๐+๐ is the negative cyclic convolution of ๐ข and ๐ฃ. Enough to compute each ๐ค ๐ modulo 2 2๐ +1 and modulo ๐. To compute ๐ค ๐ mod ๐, pack the ๐ข ๐ , ๐ฃ ๐ into two large integers, with some padding between consecutive digits, and preform one integer product using Karatsubaโs algorithm. As ๐=๐ ๐ , the cost of this step is ๐ ๐ . To compute ๐ค ๐ mod ( 2 2๐ +1), compute a negative circular convolution modulo ๐=2 2๐ +1 using ๐น๐น๐ and ๐น๐น ๐ โ1 . ๐= 2 4๐/๐ , ๐ ๐/2 = 2 2๐ โกโ1 , ๐ ๐ โก1 (mod ๐) ๐ is a ๐-th primitive root of unity in โค ๐ .
95
Modular Schรถnhage-Strassen
๐ ๐ โค๐ ๐ log ๐ +๐ ๐(2๐) ๐ โฒ (๐)=๐(๐)/๐ ๐ โฒ ๐ โค๐ log ๐ +2๐โฒ 4 ๐ ๐ 0 =๐ , ๐ ๐ =4 ๐ ๐โ1 โน ๐ ๐ โค16 ๐ 2 โ๐ ๐ โฒ ๐ โค๐( log ๐ log ๐ log ๐ 2 +โฆ) ๐ โฒ ๐ โค๐ ๐=0 log log ๐ โ1 2 ๐ log ๐ ๐ โ๐ ๐=0 log log ๐ โ1 log ๐ =๐ log ๐ log log ๐ ๐ ๐ โ๐๐ log ๐ log log ๐
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.