Polynomials and the Fast Fourier Transform (FFT)

advertisement
Polynomials and the
Fast Fourier Transform (FFT)
Algorithm Design and Analysis
(Week 7)
1
Battle Plan
• Polynomials
– Algorithms to add, multiply and evaluate polynomials
– Coefficient and point-value representation
• Fourier Transform
– Discrete Fourier Transform (DFT) and inverse DFT to
translate between polynomial representations
– “A Short Digression on Complex Roots of Unity”
– Fast Fourier Transform (FFT) is a divide-and-conquer
algorithm based on properties of complex roots of unity
2
Polynomials
• A polynomial in the variable ๐‘ฅ is a representation of
a function
๐ด ๐‘ฅ = ๐‘Ž๐‘›−1 ๐‘ฅ ๐‘›−1 + โ‹ฏ + ๐‘Ž2 ๐‘ฅ 2 + ๐‘Ž1 ๐‘ฅ + ๐‘Ž0
as a formal sum ๐ด ๐‘ฅ =
๐‘›−1
๐‘—
๐‘—=0 ๐‘Ž๐‘— ๐‘ฅ .
• We call the values ๐‘Ž0 , ๐‘Ž1, … , ๐‘Ž๐‘›−1 the coefficients of
the polynomial
• ๐ด ๐‘ฅ is said to have degree ๐‘˜ if its highest nonzero
coefficient is ๐‘Ž๐‘˜ .
• Any integer strictly greater than the degree of a
polynomial is a degree-bound of that polynomial
3
Examples
• ๐ด ๐‘ฅ = ๐‘ฅ 3 − 2๐‘ฅ − 1
– ๐ด(๐‘ฅ) has degree 3
– ๐ด(๐‘ฅ) has degree-bounds 4, 5, 6, … or all values > degree
– ๐ด(๐‘ฅ) has coefficients (−1, −2, 0, 1)
• ๐ต ๐‘ฅ = ๐‘ฅ3 + ๐‘ฅ2 + 1
– ๐ต(๐‘ฅ) has degree 3
– ๐ต(๐‘ฅ) has degree bounds 4, 5, 6, … or all values > degree
– ๐ต(๐‘ฅ) has coefficients (1, 0, 1, 1)
4
Coefficient Representation
• A coefficient representation of a polynomial
๐‘—
๐ด ๐‘ฅ = ๐‘›−1
๐‘—=0 ๐‘Ž๐‘— ๐‘ฅ of degree-bound ๐‘› is a vector of
coefficients ๐‘Ž = ๐‘Ž0 , ๐‘Ž1 , … , ๐‘Ž๐‘›−1 .
• More examples
– ๐ด ๐‘ฅ = 6๐‘ฅ 3 + 7๐‘ฅ 2 − 10๐‘ฅ + 9
– ๐ต ๐‘ฅ = −2๐‘ฅ 3 + 4๐‘ฅ − 5
(9, −10, 7, 6)
(−5, 4, 0, −2)
• The operation of evaluating the polynomial ๐ด(๐‘ฅ) at
point ๐‘ฅ0 consists of computing the value of ๐ด ๐‘ฅ0 .
• Evaluation takes time Θ(๐‘›) using Horner’s rule
๐ด(๐‘ฅ0 ) = ๐‘Ž0 + ๐‘ฅ0 (๐‘Ž1 + ๐‘ฅ0 (๐‘Ž2 + โ‹ฏ + ๐‘ฅ0 ๐‘Ž๐‘›−2 + ๐‘ฅ0 ๐‘Ž๐‘›−1
โ‹ฏ ))
5
Adding Polynomials
• Adding two polynomials represented by the
coefficient vectors ๐‘Ž = (๐‘Ž0 , ๐‘Ž1 , … , ๐‘Ž๐‘›−1 ) and
๐‘ = (๐‘0 , ๐‘1 , … , ๐‘๐‘›−1 ) takes time Θ(๐‘›).
• Sum is the coefficient vector ๐‘ = (๐‘0 , ๐‘1 , … , ๐‘๐‘›−1 ),
where ๐‘๐‘— = ๐‘Ž๐‘— + ๐‘๐‘— for ๐‘— = 0,1, … , ๐‘› − 1.
• Example
๐ด ๐‘ฅ = 6๐‘ฅ 3 + 7๐‘ฅ 2 − 10๐‘ฅ + 9
๐ต ๐‘ฅ = − 2๐‘ฅ 3
+ 4๐‘ฅ − 5
3
2
๐ถ(๐‘ฅ) = 4๐‘ฅ + 7๐‘ฅ − 6๐‘ฅ + 4
(9, −10, 7, 6)
(−5, 4, 0, −2)
(4, −6,7,4)
6
Multiplying Polynomials
• For polynomial multiplication, if ๐ด(๐‘ฅ) and ๐ต(๐‘ฅ) are
polynomials of degree-bound n, we say their product
๐ถ(๐‘ฅ) is a polynomial of degree-bound 2๐‘› − 1.
• Example
6๐‘ฅ 3
− 2๐‘ฅ 3
− 30๐‘ฅ 3
24๐‘ฅ 4 + 28๐‘ฅ 3
− 12๐‘ฅ 6 − 14๐‘ฅ 5 + 20๐‘ฅ 4 − 18๐‘ฅ 3
− 12๐‘ฅ 6 − 14๐‘ฅ 5 + 44๐‘ฅ 4 − 20๐‘ฅ 3
+ 7๐‘ฅ 2 − 10๐‘ฅ + 9
+ 4๐‘ฅ − 5
2
− 35๐‘ฅ + 50๐‘ฅ − 45
− 40๐‘ฅ 2 + 36๐‘ฅ
− 75๐‘ฅ 2 + 86๐‘ฅ − 45
7
Multiplying Polynomials
• Multiplication of two degree-bound n polynomials
๐ด(๐‘ฅ) and ๐ต(๐‘ฅ) takes time Θ ๐‘›2 , since each
coefficient in vector ๐‘Ž must be multiplied by each
coefficient in vector ๐‘.
• Another way to express the product C(x) is
๐‘—
2๐‘›−1
๐‘—
๐‘—=0 ๐‘๐‘— ๐‘ฅ , where ๐‘๐‘— = ๐‘˜=0 ๐‘Ž๐‘˜ ๐‘๐‘—−๐‘˜ .
• The resulting coefficient vector ๐‘ = (๐‘0 , ๐‘1 , … ๐‘2๐‘›−1 )
is also called the convolution of the input vectors ๐‘Ž
and ๐‘, denoted as ๐‘ = ๐‘Žโจ‚๐‘.
8
Point-Value Representation
• A point-value representation of a polynomial ๐ด(๐‘ฅ)
of degree-bound ๐‘› is a set of ๐‘› point-value pairs
๐‘ฅ0 , ๐‘ฆ0 , ๐‘ฅ1 , ๐‘ฆ1 , … , ๐‘ฅ๐‘›−1 , ๐‘ฆ๐‘›−1
such that all of the ๐‘ฅ๐‘˜ are distinct and ๐‘ฆ๐‘˜ = ๐ด(๐‘ฅ๐‘˜ )
for ๐‘˜ = 0, 1, … , ๐‘› − 1.
• Example ๐ด ๐‘ฅ = ๐‘ฅ 3 − 2๐‘ฅ + 1
– ๐‘ฅ๐‘˜
– ๐ด(๐‘ฅ๐‘˜ )
0, 1, 2, 3
1, 0, 5, 22
* 0, 1 , 1, 0 , 2, 5 , 3, 22 +
• Using Horner’s method, ๐’-point evaluation takes
time Θ(๐‘›2 ).
9
Point-Value Representation
• The inverse of evaluation is called interpolation
– determines coefficient form of polynomial from pointvalue representation
– For any set * ๐‘ฅ0 , ๐‘ฆ0 , ๐‘ฅ1 , ๐‘ฆ1 , … , ๐‘ฅ๐‘›−1 , ๐‘ฆ๐‘›−1 + of ๐‘› pointvalue pairs such that all the ๐‘ฅ๐‘˜ values are distinct, there is
a unique polynomial ๐ด(๐‘ฅ) of degree-bound ๐‘› such that
๐‘ฆ๐‘˜ = ๐ด(๐‘ฅ๐‘˜ ) for ๐‘˜ = 0, 1, … , ๐‘› − 1.
• Lagrange’s formula
๐‘›−1
๐ด ๐‘ฅ =
๐‘ฆ๐‘˜
๐‘˜=0
๐‘—≠๐‘˜(๐‘ฅ
− ๐‘ฅ๐‘— )
๐‘—≠k(๐‘ฅ๐‘˜
− ๐‘ฅ๐‘— )
• Using Lagrange’s formula, interpolation takes time
Θ(๐‘›2 ).
10
Example
• Using Lagrange’s formula, we interpolate the pointvalue representation 0, 1 , 1, 0 , 2, 5 , 3, 22 .
๐‘ฅ−1 (๐‘ฅ−2)(๐‘ฅ−3)
– 1 (0−1)(0−2)(0−3) =
๐‘ฅ 3 −6๐‘ฅ 2 +11๐‘ฅ−6
−6
=
−๐‘ฅ 3 +6๐‘ฅ 2 −11๐‘ฅ+6
6
(๐‘ฅ−0)(๐‘ฅ−2)(๐‘ฅ−3)
– 0 (1−0)(1−2)(1−3) = 0
(๐‘ฅ−0)(๐‘ฅ−1)(๐‘ฅ−3)
– 5 (2−0)(2−1)(2−3) = 5
(๐‘ฅ−0)(๐‘ฅ−1)(๐‘ฅ−2)
๐‘ฅ 3 −4๐‘ฅ 2 +3๐‘ฅ
−2
– 22 (3−0)(3−1)(3−2) = 22
–
1
6
=
๐‘ฅ 3 −3๐‘ฅ 2 +2๐‘ฅ
6
−15๐‘ฅ 3 +60๐‘ฅ 2 −45๐‘ฅ
6
=
22๐‘ฅ 3 −66๐‘ฅ 2 +44๐‘ฅ
6
6๐‘ฅ 3 + 0๐‘ฅ 2 − 12๐‘ฅ + 6
– ๐‘ฅ 3 − 2๐‘ฅ + 1
11
Adding Polynomials
• In point-value form, addition ๐ถ ๐‘ฅ = ๐ด ๐‘ฅ + ๐ต(๐‘ฅ) is
given by ๐ถ ๐‘ฅ๐‘˜ = ๐ด ๐‘ฅ๐‘˜ + ๐ต(๐‘ฅ๐‘˜ ) for any point ๐‘ฅ๐‘˜ .
– ๐ด: ๐‘ฅ0 , ๐‘ฆ0 , ๐‘ฅ1 , ๐‘ฆ1 , … , ๐‘ฅ๐‘›−1 , ๐‘ฆ๐‘›−1
′
– ๐ต: ๐‘ฅ0 , ๐‘ฆ0′ , ๐‘ฅ1 , ๐‘ฆ1′ , … , ๐‘ฅ๐‘›−1 , ๐‘ฆ๐‘›−1
′
– ๐ถ: * ๐‘ฅ0 , ๐‘ฆ0 + ๐‘ฆ0′ , ๐‘ฅ1 , ๐‘ฆ1 + ๐‘ฆ1′ , … , ๐‘ฅ๐‘›−1 , ๐‘ฆ๐‘›−1 + ๐‘ฆ๐‘›−1
+
• ๐ด and ๐ต are evaluated for the same ๐‘› points.
• The time to add two polynomials of degree-bound ๐‘›
in point-value form is Θ(๐‘›).
12
Example
• We add ๐ถ ๐‘ฅ = ๐ด ๐‘ฅ + ๐ต(๐‘ฅ) in point-value form
–
–
–
–
–
–
๐ด ๐‘ฅ = ๐‘ฅ 3 − 2๐‘ฅ + 1
๐ต ๐‘ฅ = ๐‘ฅ3 + ๐‘ฅ2 + 1
๐‘ฅ๐‘˜ = (0, 1, 2, 3)
๐ด:
0, 1 , 1, 0 , 2, 5 , 3, 22
๐ต: * 0, 1 , 1, 3 , 2, 13 , 3, 37 +
๐ถ: * 0, 2 , 1, 3 , 2, 18 , 3, 59 +
13
Multiplying Polynomials
• In point-value form, multiplication ๐ถ ๐‘ฅ = ๐ด ๐‘ฅ ๐ต(๐‘ฅ)
is given by ๐ถ ๐‘ฅ๐‘˜ = ๐ด ๐‘ฅ๐‘˜ ๐ต(๐‘ฅ๐‘˜ ) for any point ๐‘ฅ๐‘˜ .
• Problem: if ๐ด and ๐ต are of degree-bound ๐‘›, then ๐ถ is
of degree-bound 2๐‘›.
• Need to start with “extended” point-value forms for
๐ด and ๐ต consisting of 2๐‘› point-value pairs each.
– ๐ด: ๐‘ฅ0 , ๐‘ฆ0 , ๐‘ฅ1 , ๐‘ฆ1 , … , ๐‘ฅ2๐‘›−1 , ๐‘ฆ2๐‘›−1
′
– ๐ต: ๐‘ฅ0 , ๐‘ฆ0′ , ๐‘ฅ1 , ๐‘ฆ1′ , … , ๐‘ฅ2๐‘›−1 , ๐‘ฆ2๐‘›−1
′
– ๐ถ: * ๐‘ฅ0 , ๐‘ฆ0 ๐‘ฆ0′ , ๐‘ฅ1 , ๐‘ฆ1 ๐‘ฆ1′ , … , ๐‘ฅ2๐‘›−1 , ๐‘ฆ2๐‘›−1 ๐‘ฆ2๐‘›−1
+
• The time to multiply two polynomials of degreebound ๐‘› in point-value form is Θ(๐‘›).
14
Example
• We multiply ๐ถ ๐‘ฅ = ๐ด ๐‘ฅ ๐ต(๐‘ฅ) in point-value form
–
–
–
–
–
–
๐ด ๐‘ฅ = ๐‘ฅ 3 − 2๐‘ฅ + 1
๐ต ๐‘ฅ = ๐‘ฅ3 + ๐‘ฅ2 + 1
๐‘ฅ๐‘˜ = (−3, −2, −1, 0, 1, 2, 3)
We need 7 coefficients!
๐ด:
−3, −17 , −2, −3 , −1,1 , 0, 1 , 1, 0 , 2, 5 , 3, 22
๐ต: * −3, −20 , −2, −3 , −1, 2 , 0, 1 , 1, 3 , 2, 13 , 3, 37 +
๐ถ: * −3,340 , −2,9 , −1,2 , 0, 1 , 1, 0 , 2, 65 , 3, 814 +
15
The Road So Far
๐‘Ž0 , ๐‘Ž1 , … , ๐‘Ž๐‘›−1
๐‘0 , ๐‘1 , … , ๐‘Ž๐‘›−1
Ordinary multiplication
Time Θ(๐‘›2 )
Evaluation
Time Θ(๐‘›2 )
๐ด ๐‘ฅ0 , ๐ต ๐‘ฅ0
๐ด ๐‘ฅ1 , ๐ต ๐‘ฅ1
โ‹ฎ
๐ด ๐‘ฅ2๐‘›−1 , ๐ต(๐‘ฅ2๐‘›−1 )
๐‘0 , ๐‘1 , … , ๐‘๐‘›−1
Coefficient
representations
Interpolation
Time Θ(๐‘›2 )
Pointwise multiplication
Time Θ(๐‘›)
๐ถ ๐‘ฅ0
๐ถ ๐‘ฅ1
โ‹ฎ
๐ถ(๐‘ฅ2๐‘›−1 )
Point-value
representations
• Can we do better?
– Using Fast Fourier Transform (FFT) and its inverse, we can do
evaluation and interpolation in time Θ(๐‘› log ๐‘›).
• The product of two polynomials of degree-bound ๐‘› can
be computed in time Θ(๐‘› log ๐‘›), with both the input and
output in coefficient form.
16
Fourier Transform
• Fourier Transforms originate from signal processing
Weight
Amplitude
– Transform signal from time domain to frequency domain
Time
Frequency
– Input signal is a function mapping time to amplitude
– Output is a weighted sum of phase-shifted sinusoids of
varying frequencies
17
Fast Multiplication of Polynomials
• Using complex roots of unity
– Evaluation by taking the Discrete Fourier Transform (DFT)
of a coefficient vector
– Interpolation by taking the “inverse DFT” of point-value
pairs, yielding a coefficient vector
– Fast Fourier Transform (FFT) can perform DFT and inverse
DFT in time Θ(๐‘› log ๐‘›)
• Algorithm
1.
2.
3.
4.
Add ๐‘› higher-order zero coefficients to ๐ด(๐‘ฅ) and ๐ต(๐‘ฅ)
Evaluate ๐ด(๐‘ฅ) and ๐ต(๐‘ฅ) using FFT for 2๐‘› points
Pointwise multiplication of point-value forms
Interpolate ๐ถ(๐‘ฅ) using FFT to compute inverse DFT
18
Complex Roots of Unity
• A complex ๐’th root of unity (1) is a complex number
๐œ” such that ๐œ”๐‘› = 1.
• There are exactly ๐‘› complex ๐‘›th root of unity
2๐œ‹๐‘–๐‘˜
๐‘› for ๐‘˜ = 0, 1, … , ๐‘› − 1
๐‘’
where ๐‘’ ๐‘–๐‘ข = cos ๐‘ข + ๐‘– sin(๐‘ข). Here ๐‘ข represents
an angle in radians.
2๐œ‹๐‘–๐‘˜
๐‘› = cos 2๐œ‹๐‘˜
• Using ๐‘’
check that it is a root
๐‘’
2๐œ‹๐‘–๐‘˜
๐‘›
๐‘›
๐‘›
+ ๐‘– sin(2๐œ‹๐‘˜ ๐‘›), we can
= ๐‘’ 2๐œ‹๐‘–๐‘˜ = cos(2๐œ‹๐‘˜) +๐‘– sin(2๐œ‹๐‘˜) = 1
1
0
19
Examples
• The complex 4th roots of unity are
1, −1, ๐‘–, −๐‘–
where −1 = ๐‘–.
• The complex 8th roots of unity are all of the above,
plus four more
1
2
+
๐‘–
2
1
,
2
• For example
1
2
๐‘–
−
+
,−
2
๐‘–
2
2
1
2
+
๐‘–
2
, and −
1
2
−
๐‘–
2
1 2๐‘– ๐‘– 2
= + + =๐‘–
2 2 2
20
Principal ๐‘›th Root of Unity
• The value
2๐œ‹๐‘–
๐‘›
๐œ”๐‘› = ๐‘’
is called the principal ๐’th root of unity.
• All of the other complex ๐‘›th roots of unity are powers
of ๐œ”๐‘› .
• The ๐‘› complex ๐‘›th roots of unity, ๐œ”๐‘›0 , ๐œ”๐‘›1 , … , ๐œ”๐‘›๐‘›−1 ,
form a group under multiplication that has the same
structure as (โ„ค๐‘› , +) modulo ๐‘›.
• ๐œ”๐‘›๐‘› = ๐œ”๐‘›0 = 1 implies
๐‘—
๐‘—+๐‘˜
๐‘—+๐‘˜ mod ๐‘›
– ๐œ”๐‘› ๐œ”๐‘›๐‘˜ = ๐œ”๐‘› = ๐œ”๐‘›
– ๐œ”๐‘›−1 = ๐œ”๐‘›๐‘›−1
21
Visualizing 8 Complex 8th Roots of Unity
imaginary
๐œ”83
=−
1
2
+
๐œ”82 = ๐‘–
๐‘–
๐‘–
๐œ”18 =
2
๐œ”84 = −1
1
2
2
+
๐‘–
2
๐œ”80 = ๐œ”88 = 1
−1
๐œ”85 = −
1
−
1
๐‘–
2
๐œ”87 =
−๐‘–
real
1
2
−
๐‘–
2
๐œ”86 = −๐‘–
22
Cancellation Lemma
• For any integers ๐‘› ≥ 0, ๐‘˜ ≥ 0, and ๐‘ > 0,
๐‘‘๐‘˜
๐œ”๐‘‘๐‘›
= ๐œ”๐‘›๐‘˜ .
• Proof
๐‘‘๐‘˜
๐œ”๐‘‘๐‘›
= ๐‘’
2๐œ‹๐‘–
๐‘‘๐‘›
๐‘‘๐‘˜
= ๐‘’
2๐œ‹๐‘–
๐‘›
๐‘˜
= ๐œ”๐‘›๐‘˜
๐‘›
• For any even integer ๐‘› > 0, ๐œ”๐‘› 2 = ๐œ”2 = −1.
6
• Example ๐œ”24
= ๐œ”4
6
– ๐œ”24
= ๐‘’
2๐œ‹๐‘–
24
6
6
= ๐‘’ 2๐œ‹๐‘– 24 = ๐‘’
2๐œ‹๐‘–
4
= ๐œ”4
23
Halving Lemma
• If ๐‘› > 0 is even, then the squares of the ๐‘› complex
๐‘›th roots of unity are the ๐‘› 2 complex ๐‘› 2th roots of
unity.
• Proof
– By the cancellation lemma, we have ๐œ”๐‘›๐‘˜
nonnegative integer ๐‘˜.
2
= ๐œ”๐‘›๐‘˜ 2 for any
• If we square all of the complex ๐‘›th roots of unity,
then each ๐‘› 2th root of unity is obtained exactly twice
๐‘˜+๐‘›
– ๐œ”๐‘›
2
2
= ๐œ”๐‘›2๐‘˜+๐‘› = ๐œ”๐‘›2๐‘˜ ๐œ”๐‘›๐‘› = ๐œ”๐‘›2๐‘˜ = ๐œ”๐‘›๐‘˜
๐‘˜+๐‘›
– Thus, ๐œ”๐‘›๐‘˜ and ๐œ”๐‘›
2
2
have the same square
24
Summation Lemma
• For any integer ๐‘› ≥ 1 and nonzero integer ๐‘˜ not
divisible by ๐‘›,
๐‘›−1
๐‘—=0
๐œ”๐‘›๐‘˜
๐‘—
= 0.
• Proof
– Geometric series
–
๐‘›−1
๐‘—=0
๐œ”๐‘›๐‘˜
๐‘—
=
๐‘˜
๐œ”๐‘›
๐‘ฅ ๐‘› −1
๐‘ฅ−1
๐‘›−1 ๐‘—
๐‘—=0 ๐‘ฅ
=
๐‘›
๐‘› ๐‘˜ −1
๐œ”๐‘›
−1
๐‘˜ −1
๐œ”๐‘›
=
๐‘˜ −1
๐œ”๐‘›
=
1 ๐‘˜ −1
๐‘˜ −1
๐œ”๐‘›
=0
– Requiring that ๐‘˜ not be divisible by ๐‘› ensures that the
denominator is not 0, since ๐œ”๐‘›๐‘˜ = 1 only when k is divisible
by ๐‘›
25
Discrete Fourier Transform (DFT)
• Evaluate a polynomial ๐ด(๐‘ฅ) of degree-bound ๐‘› at the
๐‘› complex ๐‘›th roots of unity, ๐œ”๐‘›0 , ๐œ”๐‘›1 , ๐œ”๐‘›2 , … , ๐œ”๐‘›๐‘›−1 .
– assume that ๐‘› is a power of 2
– assume ๐ด is given in coefficient form ๐‘Ž = (๐‘Ž0 , ๐‘Ž1 , … , ๐‘Ž๐‘›−1 )
• We define the results ๐‘ฆ๐‘˜ , for ๐‘˜ = 0, 1, … , ๐‘› − 1, by
๐‘ฆ๐‘˜ = ๐ด ๐œ”๐‘›๐‘˜ =
๐‘˜๐‘—
๐‘›−1
๐‘—=0 ๐‘Ž๐‘— ๐œ”๐‘› .
• The vector ๐‘ฆ = (๐‘ฆ0 , ๐‘ฆ1 , … , ๐‘ฆ๐‘›−1 ) is the Discrete
Fourier Transform (DFT) of the coefficient vector
๐‘Ž = ๐‘Ž0 , ๐‘Ž1 , … , ๐‘Ž๐‘›−1 , denoted as ๐‘ฆ = DFT๐‘› (๐‘Ž).
26
Fast Fourier Transform (FFT)
• Fast Fourier Transform (FFT) takes advantage of the
special properties of the complex roots of unity to
compute DFT๐‘› (a) in time Θ(๐‘› log ๐‘›).
• Divide-and-conquer strategy
– define two new polynomials of degree-bound ๐‘› 2, using
even-index and odd-index coefficients of ๐ด(๐‘ฅ) separately
– ๐ด 0 ๐‘ฅ = ๐‘Ž0 + ๐‘Ž2 ๐‘ฅ + ๐‘Ž4 ๐‘ฅ 2 + โ‹ฏ + ๐‘Ž๐‘›−2 ๐‘ฅ
– ๐ด 1 ๐‘ฅ = ๐‘Ž1 + ๐‘Ž3 ๐‘ฅ + ๐‘Ž5 ๐‘ฅ 2 + โ‹ฏ + ๐‘Ž๐‘›−1 ๐‘ฅ
๐‘›
2−1
๐‘›
2−1
– ๐ด ๐‘ฅ = ๐ด 0 ๐‘ฅ 2 + ๐‘ฅ๐ด 1 (๐‘ฅ 2 )
27
Fast Fourier Transform (FFT)
• The problem of evaluating ๐ด(๐‘ฅ) at ๐œ”๐‘›0 , ๐œ”๐‘›1 , … , ๐œ”๐‘›๐‘›−1
reduces to
1. evaluating the degree-bound ๐‘› 2 polynomials ๐ด 0 (๐‘ฅ)
and ๐ด 1 (๐‘ฅ) at the points ๐œ”๐‘›0 2 , ๐œ”๐‘›1 2 , … , ๐œ”๐‘›๐‘›−1 2
2. combining the results by ๐ด ๐‘ฅ = ๐ด 0 ๐‘ฅ 2 + ๐‘ฅ๐ด 1 (๐‘ฅ 2 )
• Why bother?
– The list ๐œ”๐‘›0 2 , ๐œ”๐‘›1 2 , … , ๐œ”๐‘›๐‘›−1 2 does not contain ๐‘›
distinct values, but ๐‘› 2 complex ๐‘› 2th roots of unity
– Polynomials ๐ด 0 and ๐ด 1 are recursively evaluated at the
๐‘› complex ๐‘› th roots of unity
2
2
– Subproblems have exactly the same form as the original
problem, but are half the size
28
Example
• ๐ด ๐‘ฅ = ๐‘Ž0 + ๐‘Ž1 ๐‘ฅ + ๐‘Ž2 ๐‘ฅ 2 + ๐‘Ž3 ๐‘ฅ 3 of degree-bound 4
–
–
–
–
๐ด
๐ด
๐ด
๐ด
๐œ”40
๐œ”41
๐œ”42
๐œ”43
=๐ด
=๐ด
=๐ด
=๐ด
1 = ๐‘Ž0 + ๐‘Ž1 + ๐‘Ž2 + ๐‘Ž3
๐‘– = ๐‘Ž๐‘œ + ๐‘Ž1 ๐‘– − ๐‘Ž2 − ๐‘Ž3 ๐‘–
−1 = ๐‘Ž0 − ๐‘Ž1 + ๐‘Ž2 − ๐‘Ž3
−๐‘– = ๐‘Ž0 − ๐‘Ž1 ๐‘– + ๐‘Ž2 + ๐‘Ž3 ๐‘–
• Using ๐ด ๐‘ฅ = ๐ด 0 ๐‘ฅ 2 + ๐‘ฅ๐ด 1 ๐‘ฅ 2
–
–
–
–
–
๐ด
๐ด
๐ด
๐ด
๐ด
๐‘ฅ = ๐‘Ž0 + ๐‘Ž2 ๐‘ฅ 2 + ๐‘ฅ ๐‘Ž1 + ๐‘Ž3 ๐‘ฅ 2
๐œ”40 = ๐ด 1 = ๐‘Ž0 + ๐‘Ž2 + 1(๐‘Ž1 + ๐‘Ž3 )
๐œ”41 = ๐ด ๐‘– = ๐‘Ž0 − ๐‘Ž2 + ๐‘–(๐‘Ž1 − ๐‘Ž3 )
๐œ”42 = ๐ด −1 = ๐‘Ž0 + ๐‘Ž2 − 1 ๐‘Ž1 + ๐‘Ž3
๐œ”43 = ๐ด −๐‘– = ๐‘Ž0 − ๐‘Ž2 − ๐‘–(๐‘Ž1 − ๐‘Ž3 )
29
Recursive FFT Algorithm
RECURSIVE-FFT ๐‘Ž
1
2
3
4
5
6
7
8
9
10
11
12
13
14
๐‘› ← ๐‘™๐‘’๐‘›๐‘”๐‘กโ„Ž,๐‘Žif ๐‘› = 1
then return ๐‘Ž
2๐œ‹๐‘–
๐œ”๐‘› ← ๐‘’ ๐‘›
๐œ”←1
๐‘Ž 0 ← (๐‘Ž0 , ๐‘Ž2 , … , ๐‘Ž๐‘›−2 )
๐‘Ž 1 ← (๐‘Ž1 , ๐‘Ž3 , … , ๐‘Ž๐‘›−1 )
๐‘ฆ 0 ← RECURSIVE-FFT ๐‘Ž 0
๐‘ฆ 1 ← RECURSIVE-FFT ๐‘Ž 1
for ๐‘˜ ← 0 to ๐‘› 2 − 1
0
1
do ๐‘ฆ๐‘˜ ← ๐‘ฆ๐‘˜ + ๐œ”๐‘ฆ๐‘˜
0
1
๐‘ฆ๐‘˜+(๐‘› 2) ← ๐‘ฆ๐‘˜ − ๐œ”๐‘ฆ๐‘˜
๐œ” ← ๐œ”๐œ”๐‘›
return ๐‘ฆ
๐‘› is a power of 2
basis of recursion
๐œ”๐‘› is principal ๐‘›th root of unity
0
๐‘ฆ๐‘˜ = ๐ด 0 ๐œ”๐‘›๐‘˜ 2 = ๐ด 0 (๐œ”๐‘›2๐‘˜ )
1
๐‘ฆ๐‘˜ = ๐ด 1 ๐œ”๐‘›๐‘˜ 2 = ๐ด 1 (๐œ”๐‘›2๐‘˜ )
๐‘˜+ ๐‘› 2
since −๐œ”๐‘›๐‘˜ = ๐œ”๐‘›
compute ๐œ”๐‘›๐‘˜ iteratively
30
Why Does It Work?
• For ๐‘ฆ0 , ๐‘ฆ1 , … ๐‘ฆ๐‘› 2−1
0
๐‘ฆ๐‘˜
0
๐‘ฆ๐‘˜
1
+ ๐œ”๐‘›๐‘˜ ๐‘ฆ๐‘˜
๐œ”๐‘›2๐‘˜ +
๐œ”๐‘›๐‘˜
=
=๐ด
=๐ด
(line 11)
๐œ”๐‘›๐‘˜ ๐ด 1 ๐œ”๐‘›2๐‘˜
• For ๐‘ฆ๐‘› 2 , ๐‘ฆ๐‘› 2+1 , … , ๐‘ฆ๐‘›−1
๐‘ฆ๐‘˜+๐‘› 2 =
=
(line 12)
๐‘ฆ๐‘˜0
๐‘ฆ๐‘˜0
0
=๐ด
=๐ด
− ๐œ”๐‘›๐‘˜ ๐‘ฆ๐‘˜1
๐‘˜+ ๐‘› 2
+ ๐œ”๐‘›
๐‘ฆ๐‘˜1
since
๐‘›
๐‘˜+
2
๐œ”๐‘›2๐‘˜ + ๐œ”๐‘›
๐ด 1 ๐œ”๐‘›2๐‘˜
๐‘›
๐‘˜+
0
2
๐œ”๐‘›2๐‘˜+๐‘› + ๐œ”๐‘›
๐ด 1 ๐œ”๐‘›2๐‘˜+๐‘›
๐‘˜+ ๐‘› 2
−๐œ”๐‘›๐‘˜ = ๐œ”๐‘›
since ๐œ”๐‘›2๐‘˜+๐‘› = ๐œ”๐‘›2๐‘˜
๐‘˜+ ๐‘› 2
= ๐ด ๐œ”๐‘›
31
Input Vector Tree of RECURSIVEFFT(๐‘Ž)
(๐‘Ž0 , ๐‘Ž1 , ๐‘Ž2 , ๐‘Ž3 , ๐‘Ž4 , ๐‘Ž5 , ๐‘Ž6 , ๐‘Ž7 )
(๐‘Ž0 , ๐‘Ž2 , ๐‘Ž4 , ๐‘Ž6 )
(๐‘Ž0 , ๐‘Ž4 )
(๐‘Ž0 )
(๐‘Ž4 )
(๐‘Ž1 , ๐‘Ž3 , ๐‘Ž5 , ๐‘Ž7 )
(๐‘Ž2 , ๐‘Ž6 )
(๐‘Ž2 )
(๐‘Ž6 )
(๐‘Ž1 , ๐‘Ž5 )
(๐‘Ž1 )
(๐‘Ž5 )
(๐‘Ž3 , ๐‘Ž7 )
(๐‘Ž3 )
(๐‘Ž7 )
32
Interpolation
• Interpolation by computing the inverse DFT, denoted
by a = DFT๐‘›−1 (๐‘ฆ).
• By modifying the FFT algorithm, we can compute
DFT๐‘›−1 in time Θ(๐‘› log ๐‘›).
– switch the roles of ๐‘Ž and ๐‘ฆ
– replace ๐œ”๐‘› by ๐œ”๐‘›−1
– divide each element of the result by ๐‘›
33
Download