Docsity

Lecture Notes 6: Algorithm Design & Analysis - Fourier Transform - Prof. David E. Maier, Study notes of Computer Science

Toggle sidebar
bg1
CS 410/584, Algorithm Design & Analysis, Lecture Notes 6
1© 1994, 2003, 2003, 2006, 2008,
2009 David Maier
Algorithm Design & Analysis
Fourier Transform
Time domain Æfrequency domain
Ex
p
ress a
p
eriodic function as a sum of
pp
sine and cosine functions
We will use a discrete version of it for
fast multiplication of polynomials
First, some examination of polynomials
David Maier 1
Lecture Notes 6
Algorithm Design & Analysis
Polynomial as List of Coefficients
Polynomial with n+1 terms
anxn+ an-1xn-1 + … + a
2
x2+ a
1
x + a0
Write as a summation
A(x) = Σ
Can
j
ust kee
p
track of coefficients
David Maier 2
Lecture Notes 6
jp
Degree = k means
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Lecture Notes 6: Algorithm Design & Analysis - Fourier Transform - Prof. David E. Maier and more Study notes Computer Science in PDF only on Docsity!

2009 David Maier

Algorithm Design & Analysis

Fourier Transform

Time domain Æ frequency domain

Express a periodic function as a sum ofp p

sine and cosine functions

We will use a discrete version of it for

fast multiplication of polynomials

First, some examination of polynomials

Lecture Notes 6 David Maier (^1)

Algorithm Design & Analysis

Polynomial as List of Coefficients

Polynomial with n+1 terms

a n x n^ + a n-1 x n-1^ + … + a 2 x 2 + a 1 x + a 0

Write as a summation

A(x) = Σ

Can just keep track of coefficients

Lecture Notes 6 David Maier (^2)

j p

Degree = k means

2009 David Maier

Algorithm Design & Analysis

Examples

x 3 - 2x - 1

Has degree 3

Has degree bound

Has coefficients

x 3 + x 2 + 1

Lecture Notes 6 David Maier (^3)

Has coefficients

Algorithm Design & Analysis

Easy to Add Polynomials

A(x)

(a 0 , a 1 , …, a n )

B(x)

(b 0 , b 1 , …, b n )

A(x) + B(x)

Lecture Notes 6 David Maier (^4)

(-1, -2, 0, 1)

( 1, 0, 1, 1)

2009 David Maier

Algorithm Design & Analysis Example

(-1, -2, 0, 1)

( 1, 0, 1, 1)

cc 0 0 = (-1)(1) =( 1)(1)

c 1 = (-1)(0) + (-2)(1) =

c 2 = (-1)(1) + (-2)(0) + (0)(1) =

c 3 = (-1)(1) + (-2)(1) + (0)(0) +

c 4 = (-2)(1) +(0)(1) + (1)(0) =

Lecture Notes 6 David Maier (^7)

c 5 = (0)(1) + (1)(1) =

c 6 = (1)(1) =

Algorithm Design & Analysis

Point-Value Representation

A polynomial of degree n is uniquely

determined by its value at n+1 distinct

p intspoints

A(x)

{(x 0 ,A(x 0 )), (x 1 ,A(x 1 )), …,(x n ,A(x n ))}

Example A(x) = x 3 - 2x + 1

x i ( 0, 1, 2, 3 )

A( ) ( )

Lecture Notes 6 David Maier (^8)

A(x i ) ( , , , )

2009 David Maier

Algorithm Design & Analysis

Interpolating Back to Coefficients

Can go from point-value set {(x i,y i)}

back to coefficients

LLagrange s formula n ’s f mul

A(x) = Σy (^) k Π (x – x (^) j )

Lecture Notes 6 David Maier (^9)

Π (x k – x j )

Algorithm Design & Analysis

Example

1 ⋅ (x-1)(x-2)(x-3) (0-1)(0-2)(0-3)

0 ⋅ (x-0)(x-2)(x-3) (1-0)(1-2)(1-3)

Lecture Notes 6 David Maier (^10)

5 ⋅ (x-0)(x-1)(x-3) (2-0)(2-1)(2-3)

22 ⋅ (x-0)(x-1)(x-2) (3-0)(3-1)(3-2)

2009 David Maier

Algorithm Design & Analysis

Need 7 Coefficients Here

Result

Lecture Notes 6 David Maier (^13)

Algorithm Design & Analysis

One Way to Multiply A(n), B(n) of Degree n

Given as coefficient lists

(a 0 , …, a (^) n )

(b 0 , …, b (^) n )

((x0 ,A(x0 )⋅B(x0 )),

(c 0 , …, c (^) 2n )

Lecture Notes 6 David Maier (^14)

((x 0 ,A(x 0 )), …,(x (^) 2n ,A(x (^) 2n ))

((x 0 ,B(x 0 )), …,(x (^) 2n ,B(x (^) 2n ))

…,(x (^) 2n ,A(x (^) 2n )⋅B(x (^) 2n ))

2009 David Maier

Algorithm Design & Analysis

Why Bother

Have we gained anything?

Evaluation and interpolation are O(np 2 )

in general

However, if we correctly pick the x i ,

we can do both in O(n log(n)), giving

O(n log(n)) over all.

Lecture Notes 6 David Maier (^15)

( g( ))

Algorithm Design & Analysis

Roots of Unity

Use n th^ roots of 1 (unity)

Anyy ω such that

What are the 4 th^ roots of unity?

What are the 8 th^ roots of unity?

All f h b k b h 4!

Lecture Notes 6 David Maier (^16)

All of the above work, but there are 4 more!

2009 David Maier

Algorithm Design & Analysis

Picture of 8 th^ Roots in Complex Plane

6

Lecture Notes 6 David Maier (^19)

8

These roots act like the integers mod 8 under +

(ω 8 ) j^ (ω 8 ) k^ = (ω 8 ) j+k^ =

Algorithm Design & Analysis

Cancellation Lemma

An example

(e 1/24(2πi))^6 = e 6/24(2πi)^ = e (2πi)^ =

In general

ωn = (ωdn)d

More generally

Lecture Notes 6 David Maier (^20)

ωnk^ = (ω n) k

Special case

ω2rr^ = ω 2 =

2009 David Maier

Algorithm Design & Analysis

Squares of 2r th^ roots

ω2rk^ and (ω2r)k+r

have the same squareq

(ω2rk)^2 =

(ω2rk+r)^2 = ω2r2k⋅ω2r2r^ = ω2r2k^ =

which is an rth^ root of unity

{(ω2r^0 )^2 , (ω2r^1 )^2 , (ω2r^2 )^2 , …, (ω2r2r-1^ )^2 }

Lecture Notes 6 David Maier (^21)

= {ωr^0 , ωr^1 , ωr^2 , …, ωrr-1^ }

Exercise:

ω2rk^ = -(ω2r)k+r

Algorithm Design & Analysis

Summing Up nth^ Roots

Exercise:

ω2r2rk = -(ω2r2r)k+r

So:

ω2r^0 + ω2r^1 + ω2r^2 + … + ω2r2r-1^ =

Actually

ωn^0 + ωn^1 + ωn^2 + … + ωnn-1^ =

Lecture Notes 6 David Maier (^22)

2009 David Maier

Algorithm Design & Analysis

How to Evaluate A(x)

Can evaluate A(x) at n points

x 0 , x 1 , x 2 , …, x (^) n-

BB y evaluating A.0(y) and A.1(y)l 0( ) d 1( )

x 0 , x 1 , x 2 , …, x (^) n-

What is the degree of A.0(y) and

A.1(y)?

Lecture Notes 6 David Maier (^25)

Algorithm Design & Analysis

Evaluating at n th^ Roots

If the x i ’s are the nth^ roots of unity,

where n = 2r

SSo

x (^) j = ωnj^ = ω2rj (x (^) j )^2 = (ωnj^ )^2 = ω2r2j^ =

Instead of 2r points, we only have r

points to evaluate

Evaluating one polynomial of degree 2r-1 at 2r points =

Lecture Notes 6 David Maier (^26)

2r points = Evaluating two polynomials of degree r-1 at r points plus

Time Complexity

2009 David Maier

Algorithm Design & Analysis

Recursive FFT

FFT(a 0 ) =

FFT(aFFT(a 0 0 , a1 , a1 , …, , …, anan-1 1 ) ) Let wn be principal n th^ root of unity w Å 1 a.0 = (a 0 , a 2 , a 4 , …, a (^) n-2 ) a.1 = (a 1 , a 3 , a 5 , …, a (^) n-1 ) y.0 = y.1 =

Lecture Notes 6 David Maier (^27)

for k Å 1 to (n/2)- yk Å y.0 (^) k + yk+(n/2) Å y.0 (^) k - w Å w⋅wn return( )

Algorithm Design & Analysis

Are the Values Right?

Note

y.0 (^) k = A.0(ωn/2k^ ) = A.0( ) y 1y.1k = A.1(A 1(ωωn/2 kk^ )^ ) = A 1(A.1( ))

So

y (^) k = y.0 (^) k + ωnk⋅y.1 (^) k = A.0(ωn2k^ ) + ωnk⋅A.1(ωn2k^ ) =

y (^) k+(n/2) = y.0 (^) k - ωnk⋅y.1 (^) k

Lecture Notes 6 David Maier (^28)

yk+(n/2) y (^) k n y (^) k = y.0 (^) k + ωnk+(n/2)⋅y.1 (^) k = A.0(ωn2k^ ) + ωnk+(n/2)⋅A.1(ωn2k^ ) =