0% found this document useful (0 votes)
92 views22 pages

Divide-and-Conquer: Polynomial Multiplication: FFT

This document discusses the divide-and-conquer algorithm for polynomial multiplication using the Fast Fourier Transform (FFT). It describes how to represent polynomials in coefficient and point value pair forms, and how these representations are equivalent. It then outlines the naive O(n^3) algorithm before explaining how to improve it to O(nlogn) time using the FFT. The key steps are: (1) evaluating polynomials at twiddle factors in O(nlogn) time, (2) multiplying the point values in O(n) time, and (3) recovering coefficients from point values also in O(n) time using the inverse FFT.

Uploaded by

RakshitTiwari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views22 pages

Divide-and-Conquer: Polynomial Multiplication: FFT

This document discusses the divide-and-conquer algorithm for polynomial multiplication using the Fast Fourier Transform (FFT). It describes how to represent polynomials in coefficient and point value pair forms, and how these representations are equivalent. It then outlines the naive O(n^3) algorithm before explaining how to improve it to O(nlogn) time using the FFT. The key steps are: (1) evaluating polynomials at twiddle factors in O(nlogn) time, (2) multiplying the point values in O(n) time, and (3) recovering coefficients from point values also in O(n) time using the inverse FFT.

Uploaded by

RakshitTiwari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Divide-and-Conquer

Polynomial Multiplication: FFT

R. Inkulu
http://www.iitg.ac.in/rinkulu/

(Polynomial Multiplication: FFT)

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 .

(Polynomial Multiplication: FFT)

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

The coefficient representation of a polynomial A(x) =

Pn1
j=0

aj xj is a

vector of coefficents (a0 , a1 , . . . , an1 ).

(Polynomial Multiplication: FFT)

3 / 10

Polynomial representations

The coefficient representation of a polynomial A(x) =

Pn1
j=0

aj xj is a

vector of coefficents (a0 , a1 , . . . , an1 ).


A set of points representation of a polynomial A(x) of degree n 1 is a

set of n point-value pairs {(x0 , y0 ), (x1 , y1 ), . . . , (xn1 , yn1 )} such that


all the xk are distinct and yk = A(xk ) for k = 0, 1, . . . , n 1.

(Polynomial Multiplication: FFT)

3 / 10

Equivalence between polynomial representations

coefficient set of points


Horners rule: A(xr ) = a0 + xr (a1 + xr (a2 + . . . + (xr (an2 + xr (an1 )))).

(Polynomial Multiplication: FFT)

4 / 10

Equivalence between polynomial representations

coefficient set of points


Horners rule: A(xr ) = a0 + xr (a1 + xr (a2 + . . . + (xr (an2 + xr (an1 )))).
set of points coefficient
interpolating the polynomial with the help of matrix algebra

(Polynomial Multiplication: FFT)

4 / 10

Naive algorithm

(1) Since C(x) is of degree 2n 2, we require at least 2n 1 points to


recover C(x). Choose distinct x1 , x2 , . . . , x2n1 and evaluate A(x) and
B(x) at these points.
O(n2 ) time using Horners rule

(2) Compute C(xj ) = A(xj )B(xj ) for j = 1, 2, . . . , 2n 1.


O(n) time

(3) Reconstructing C(x) of degree 2n 2 from C(xj ) for j = 1, 2, . . . , 2n 1.


O(n3 ) time using techniques from Linear Algebra

(Polynomial Multiplication: FFT)

5 / 10

Handling (1): divide-conquer-combine


A(x) = a0 + a1 x + a2 x2 + . . . + an1 xn1

= (a0 + a2 x2 + . . . + an2 xn2 ) + x(a1 + a3 x2 + . . . + an1 xn2 )


= (a0 + a2 (x2 ) + . . . + an2 (x2 )(n2)/2 )
+ x(a1 + a3 (x2 ) + . . . + an1 (x2 )(n2)/2 )
= Aeven (x2 ) + xAodd (x2 )

(Polynomial Multiplication: FFT)

6 / 10

Handling (1): divide-conquer-combine


A(x) = a0 + a1 x + a2 x2 + . . . + an1 xn1

= (a0 + a2 x2 + . . . + an2 xn2 ) + x(a1 + a3 x2 + . . . + an1 xn2 )


= (a0 + a2 (x2 ) + . . . + an2 (x2 )(n2)/2 )
+ x(a1 + a3 (x2 ) + . . . + an1 (x2 )(n2)/2 )
= Aeven (x2 ) + xAodd (x2 )
Let T(n) be the number of operations required to evaluate A(x) of degree

n 1 at 2n points.

(Polynomial Multiplication: FFT)

6 / 10

Handling (1): divide-conquer-combine


A(x) = a0 + a1 x + a2 x2 + . . . + an1 xn1

= (a0 + a2 x2 + . . . + an2 xn2 ) + x(a1 + a3 x2 + . . . + an1 xn2 )


= (a0 + a2 (x2 ) + . . . + an2 (x2 )(n2)/2 )
+ x(a1 + a3 (x2 ) + . . . + an1 (x2 )(n2)/2 )
= Aeven (x2 ) + xAodd (x2 )
Let T(n) be the number of operations required to evaluate A(x) of degree

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.

(Polynomial Multiplication: FFT)

6 / 10

Handling (1): divide-conquer-combine


A(x) = a0 + a1 x + a2 x2 + . . . + an1 xn1

= (a0 + a2 x2 + . . . + an2 xn2 ) + x(a1 + a3 x2 + . . . + an1 xn2 )


= (a0 + a2 (x2 ) + . . . + an2 (x2 )(n2)/2 )
+ x(a1 + a3 (x2 ) + . . . + an1 (x2 )(n2)/2 )
= Aeven (x2 ) + xAodd (x2 )
Let T(n) be the number of operations required to evaluate A(x) of degree

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

Handling (1): intro to twiddle factors (j,2n )

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 ).

(Polynomial Multiplication: FFT)

7 / 10

Handling (1): intro to twiddle factors (j,2n )

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

(Polynomial Multiplication: FFT)

7 / 10

Handling (1): using twiddle factors


2 =
Given that j,2n
j,n
2 )+
2
A(j,2n ) = Aeven (j,2n
j,2n Aodd (j,2n ) = Aeven (j,n ) + j,2n Aodd (j,n )
(a)

(Polynomial Multiplication: FFT)

8 / 10

Handling (1): using twiddle factors


2 =
Given that j,2n
j,n
2 )+
2
A(j,2n ) = Aeven (j,2n
j,2n Aodd (j,2n ) = Aeven (j,n ) + j,2n Aodd (j,n )
(a)
2
2
Given that j+n,2n
= j,2n
A(j+n,2n )
2
2
)
) + j+n,2n Aodd (j+n,2n
= Aeven (j+n,2n
2
2
= Aeven (j,2n ) + j+n,2n Aodd (j,2n ) (b)

(Polynomial Multiplication: FFT)

8 / 10

Handling (1): using twiddle factors


2 =
Given that j,2n
j,n
2 )+
2
A(j,2n ) = Aeven (j,2n
j,2n Aodd (j,2n ) = Aeven (j,n ) + j,2n Aodd (j,n )
(a)
2
2
Given that j+n,2n
= j,2n
A(j+n,2n )
2
2
)
) + j+n,2n Aodd (j+n,2n
= Aeven (j+n,2n
2
2
= Aeven (j,2n ) + j+n,2n Aodd (j,2n ) (b)

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

(Polynomial Multiplication: FFT)

8 / 10

Handling (1): using twiddle factors


2 =
Given that j,2n
j,n
2 )+
2
A(j,2n ) = Aeven (j,2n
j,2n Aodd (j,2n ) = Aeven (j,n ) + j,2n Aodd (j,n )
(a)
2
2
Given that j+n,2n
= j,2n
A(j+n,2n )
2
2
)
) + j+n,2n Aodd (j+n,2n
= Aeven (j+n,2n
2
2
= Aeven (j,2n ) + j+n,2n Aodd (j,2n ) (b)

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)

(Polynomial Multiplication: FFT)

8 / 10

Handling (3): algebra to express cj s in terms of yk s


From (2), we have set of points representation for C(x) as:

(0,2n , y0 ), (1,2n , y1 ), . . . , (2n2,2n , y2n2 )


and, intend to find coefficients c0 , c1 , . . . , c2n2 in
C(x) = c0 + c1 x + c2 x2 + . . . + c2n2 x2n2 .

another reason to evaluate A(x) and B(x) at twiddle factors: V 1 is efficiently computable

(Polynomial Multiplication: FFT)

9 / 10

Handling (3): algebra to express cj s in terms of yk s


From (2), we have set of points representation for C(x) as:

(0,2n , y0 ), (1,2n , y1 ), . . . , (2n2,2n , y2n2 )


and, intend to find coefficients c0 , c1 , . . . , c2n2 in
C(x) = c0 + c1 x + c2 x2 + . . . + c2n2 x2n2 .
Substituting these points in C(x) yields: VC = Y, where
* C is a column vector of order (2n 1) 1 comprising the coefficients of
C(x) vector C of this form is termed as the inverse discrete Fourier
transform of Y
* Y is a column vector of order (2n 1) 1 comprising second coordi of
points.
* V is a Vandermonde matrix of order (2n 1) (2n 1) whose (j, k)th
k
entry is j,2n
, which is equal to jk,2n .

another reason to evaluate A(x) and B(x) at twiddle factors: V 1 is efficiently computable

(Polynomial Multiplication: FFT)

9 / 10

Handling (3): algebra to express cj s in terms of yk s


From (2), we have set of points representation for C(x) as:

(0,2n , y0 ), (1,2n , y1 ), . . . , (2n2,2n , y2n2 )


and, intend to find coefficients c0 , c1 , . . . , c2n2 in
C(x) = c0 + c1 x + c2 x2 + . . . + c2n2 x2n2 .
Substituting these points in C(x) yields: VC = Y, where
* C is a column vector of order (2n 1) 1 comprising the coefficients of
C(x) vector C of this form is termed as the inverse discrete Fourier
transform of Y
* Y is a column vector of order (2n 1) 1 comprising second coordi of
points.
* V is a Vandermonde matrix of order (2n 1) (2n 1) whose (j, k)th
k
entry is j,2n
, which is equal to jk,2n .
Note that (j, k)th entry of V 1 is

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

(Polynomial Multiplication: FFT)

9 / 10

Handling (3): inverse DFT computation using


divide-conquer-combine

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

each element of the result by 2n to obtain coefficient vector corresp. to


C(x).
former is same as computing DFT of a polynomial except for using
slightly different twiddle factor set

(Polynomial Multiplication: FFT)

10 / 10

You might also like