Divide-and-Conquer: Polynomial Multiplication: FFT
Divide-and-Conquer: Polynomial Multiplication: FFT
R. Inkulu
http://www.iitg.ac.in/rinkulu/
1 / 10
Description
Given two polynomials A(x) = a0 + a1 x + a2 x2 + . . . + an1 xn1 , and
2
B(x) = bP
bn1 xn1 , computing
0 + b1 x + b2 x + . . . +P
2n2
j
C(x) = j=0 cj x , where cj = jk=0 ak bjk .
2 / 10
Description
Given two polynomials A(x) = a0 + a1 x + a2 x2 + . . . + an1 xn1 , and
2
B(x) = bP
bn1 xn1 , computing
0 + b1 x + b2 x + . . . +P
2n2
j
C(x) = j=0 cj x , where cj = jk=0 ak bjk .
a0 b 0
a0b n1
a0b 1
a1b 1
a1b 0
a0b n2 a b
1 n2
a1b n1
an1b n1
an1b 0
summing along the diagonals yield the required cj s takes O(n2 ) time.
(Polynomial Multiplication: FFT)
2 / 10
Polynomial representations
Pn1
j=0
aj xj is a
3 / 10
Polynomial representations
Pn1
j=0
aj xj is a
3 / 10
4 / 10
4 / 10
Naive algorithm
5 / 10
6 / 10
n 1 at 2n points.
6 / 10
n 1 at 2n points.
Then T(n/2) denotes the number of operations required to evaluate a
polynomial Aeven (resp. Aodd ) of degree 2n 1 at n points.
6 / 10
n 1 at 2n points.
Then T(n/2) denotes the number of operations required to evaluate a
polynomial Aeven (resp. Aodd ) of degree 2n 1 at n points.
However, if Aeven (resp. Aodd ) is evaluated at only n points, how to
represent A(x) with 2n points?
(Polynomial Multiplication: FFT)
6 / 10
Choose 2n distinct x values such that if we evaluate Aeven and Aodd at the
first n of these, in O(n) time we can compute A(x) at all of these x values;
in particular, choose the distinct complex numbers (twiddle factors):
2j
2j
0,2n , 1,2n , . . . , 2n1,2n , where j,r = e r i = cos( 2j
r ) + i sin( r ).
7 / 10
Choose 2n distinct x values such that if we evaluate Aeven and Aodd at the
first n of these, in O(n) time we can compute A(x) at all of these x values;
in particular, choose the distinct complex numbers (twiddle factors):
2j
2j
0,2n , 1,2n , . . . , 2n1,2n , where j,r = e r i = cos( 2j
r ) + i sin( r ).
* representing a polynomial P with the set of points corresponding to
twiddle factors as x-coordinates is known as the discrete Fourier transform
(DFT) of P
7 / 10
8 / 10
8 / 10
Obtaining A(j,2n ) from Aeven (j,n ) and Aodd (j,n ) for all j = 0, 1, . . . , 2n
together takes O(n) time: use (a) for j = 0, . . . , n 1 and (b) for
j = 0, . . . , n 1
8 / 10
Obtaining A(j,2n ) from Aeven (j,n ) and Aodd (j,n ) for all j = 0, 1, . . . , 2n
together takes O(n) time: use (a) for j = 0, . . . , n 1 and (b) for
j = 0, . . . , n 1
Hence, T(n) = 2T(n/2) + O(n) i.e., T(n) is O(n lg n)
8 / 10
another reason to evaluate A(x) and B(x) at twiddle factors: V 1 is efficiently computable
9 / 10
another reason to evaluate A(x) and B(x) at twiddle factors: V 1 is efficiently computable
9 / 10
and, cj =
1
1
2n
P2n2
k=0
jk,2n 1
2n
yk jk,2n , for j = 0, 1, . . . , 2n 2
another reason to evaluate A(x) and B(x) at twiddle factors: V 1 is efficiently computable
9 / 10
cj =
1
2n
P2n2
k=0
yk kj,2n , for j = 0, 1, . . . , 2n 2.
contrast this with the DFT of (a0 , a1 , . . . , an1 ) that we have computed as
Pn1
Pn1
k
part of (1): A(j,2n ) = k=0 ak j,2n
= k=0 ak kj,2n
Therefore, compute the inverse DFT of (y0 , y1 , . . . , y2n2 ) and divide
10 / 10