WS 03/04 Algorithmentheorie 02 – Polynomprodukt und Fast Fourier Transformation Prof. Dr. S....

20
WS 03/04 Algorithmentheorie 02 – Polynomprodukt und Fast Fourier Transformation Prof. Dr. S. Albers Prof. Dr. Th. Ottmann

Transcript of WS 03/04 Algorithmentheorie 02 – Polynomprodukt und Fast Fourier Transformation Prof. Dr. S....

Page 1: WS 03/04 Algorithmentheorie 02 – Polynomprodukt und Fast Fourier Transformation Prof. Dr. S. Albers Prof. Dr. Th. Ottmann.

WS 03/04

Algorithmentheorie

02 – Polynomprodukt undFast Fourier Transformation

Prof. Dr. S. Albers

Prof. Dr. Th. Ottmann

Page 2: WS 03/04 Algorithmentheorie 02 – Polynomprodukt und Fast Fourier Transformation Prof. Dr. S. Albers Prof. Dr. Th. Ottmann.

2 WS 03/04

Polynomprodukt

Berechnung des Produkts zweier Polynome p, q vom Grade < n

p,q Grad n-1, n KoeffizientenAuswertung:

2n Punkt/Wertpaare und

Punktweise Multiplikation

2n Punkt/Wertpaare

Interpolation

pq Grad 2n-2, 2n-1 Koeffizienten

12

2

1

2

0

2 ,,, nnnn

i

n

i

n p 22 , i

n

i

n q 22 ,

i

n

i

n pq 22 ,

Page 3: WS 03/04 Algorithmentheorie 02 – Polynomprodukt und Fast Fourier Transformation Prof. Dr. S. Albers Prof. Dr. Th. Ottmann.

3 WS 03/04

Diskrete Fourier Transformation

n-te komplexe Haupteinheitswurzel: nin e /2

))(,),(),(()( 110 nnnnn ppppDFT

Fast Fourier Transformation:Berechung von DFTn(p) mittels eines Divide-and ConquerAnsatzes

Page 4: WS 03/04 Algorithmentheorie 02 – Polynomprodukt und Fast Fourier Transformation Prof. Dr. S. Albers Prof. Dr. Th. Ottmann.

4 WS 03/04

Diskrete Fourier Transformation

Ansatz: (n sei gerade)

2/2

1311

2/2

2200

n

n

n

n

xaxaaxp

xaxaaxp

2

12

0

2/221

231

2/222

220

11

331

22

220

1110

xxpxp

xaxaax

xaxaa

xaxaxa

xaxaa

xaxaaxp

n

n

n

n

nn

nn

nn

Page 5: WS 03/04 Algorithmentheorie 02 – Polynomprodukt und Fast Fourier Transformation Prof. Dr. S. Albers Prof. Dr. Th. Ottmann.

5 WS 03/04

Diskrete Fourier Transformation

Auswertung für k = 0, ... , n – 1

2/ falls

2/ falls

,

2/2/1

2/2/2/0

2/12/0

nk

pp

nk

pp

pnk

nnk

nnk

n

kn

kn

kn

kn

Page 6: WS 03/04 Algorithmentheorie 02 – Polynomprodukt und Fast Fourier Transformation Prof. Dr. S. Albers Prof. Dr. Th. Ottmann.

6 WS 03/04

6. Fast Fourier Transformation

Algorithmus FFTInput: Ein Array a mit den n Koeffizienten eines Polynoms p

und n = 2k

Output: DFTn(p) 1. if n = 1 then /* p ist konstant */2. return a

3. d[0] = FFT([a0, a2, ... , an-2 ], n/2)

4. d[1] = FFT([a1, a3, ... , an-1], n/2)

5. n = e2i/n

6. = 1

7. for k = 0 to n/2 – 1 do /* = nk*/

8.9.10.11.return d

n

102/

10

kknk

kkk

ddd

ddd

Page 7: WS 03/04 Algorithmentheorie 02 – Polynomprodukt und Fast Fourier Transformation Prof. Dr. S. Albers Prof. Dr. Th. Ottmann.

7 WS 03/04

FFT : Beispiel

a = [0, 18,-15, 3 ]

a[0] = [0, -15] a[1] = [18, 3]

FFT([0, -15], 2) = (FFT([0],1) + FFT([-15],1), FFT([0],1) - FFT([-15],1))

= (-15,15)

FFT([18, 3],2) = (FFT([18],1) + FFT([3],1), FFT([18],1) - FFT([3],1))

= (21,15)

k = 0 ; = 1

d0 = -15 + 1 * 21 = 6 d2 = -15 – 1 * 21 = -36

k = 1 ; = i

d1 = 15 + i*15 d3 = 15 – i*15

FFT(a, 4) = (6, 15+15i, -36, 15 –15i)

018153 23 xxxxp

Page 8: WS 03/04 Algorithmentheorie 02 – Polynomprodukt und Fast Fourier Transformation Prof. Dr. S. Albers Prof. Dr. Th. Ottmann.

8 WS 03/04

7. Analyse

T(n) = Zeit um ein Polynom vom Grad < n an den Stellen

auszuwerten.

T(1) = O(1)

T(n) = 2 T(n/2) + O(n)

= O(n log n)

12

2

1

2

0

2 ,,, nnnn

Page 9: WS 03/04 Algorithmentheorie 02 – Polynomprodukt und Fast Fourier Transformation Prof. Dr. S. Albers Prof. Dr. Th. Ottmann.

9 WS 03/04

Polynomprodukt

Berechnung des Produkts zweier Polynome p, q vom Grade < n

p,q Grad n-1, n KoeffizientenAuswertung durch FFT:

2n Punkt/Wertpaare und

Punktweise Multiplikation

2n Punkt/Wertpaare

Interpolation

pq Grad 2n-2, 2n-1 Koeffizienten

122

12

02 ,,, n

nnn

i

n

i

n p 22 , i

n

i

n q 22 ,

i

n

i

n pq 22 ,

Page 10: WS 03/04 Algorithmentheorie 02 – Polynomprodukt und Fast Fourier Transformation Prof. Dr. S. Albers Prof. Dr. Th. Ottmann.

10 WS 03/04

Interpolation

Umrechnung der Punkt/Wert-Darstellung in dieKoeffizientendarstellung

Gegeben: (x0, y0),..., (xn-1, yn-1) mit xi xj, für alle i j

Gesucht: Polynom p mit Koeffizienten a0,..., an-1, so dass

1

1

111101

2

1

212102

1

1

111101

0

1

010100

n

n

nnnn

n

n

n

n

n

n

yxaxaaxp

yxaxaaxpyxaxaaxpyxaxaaxp

Page 11: WS 03/04 Algorithmentheorie 02 – Polynomprodukt und Fast Fourier Transformation Prof. Dr. S. Albers Prof. Dr. Th. Ottmann.

11 WS 03/04

Interpolation

Matrixschreibweise

1

1

0

1

1

0

1

11

1

21

1

00

1

1

1

nn

n

nn

n

n

y

y

y

a

a

a

xx

xx

xx

Page 12: WS 03/04 Algorithmentheorie 02 – Polynomprodukt und Fast Fourier Transformation Prof. Dr. S. Albers Prof. Dr. Th. Ottmann.

12 WS 03/04

Interpolation

Spezialfall (hier) : Definition:

jixx

y

y

y

a

a

a

xx

xx

xx

ji

nn

n

nn

n

n

allefür ,für lösbar ist

1

1

1

systemGleichungs

1

1

0

1

1

0

1

11

1

11

1

00

V

, ,

1

n

,

yVaya

yyaaV

n

iiji

ij

nn

i

nix

Page 13: WS 03/04 Algorithmentheorie 02 – Polynomprodukt und Fast Fourier Transformation Prof. Dr. S. Albers Prof. Dr. Th. Ottmann.

13 WS 03/04

Interpolation

SatzFür alle 0 i, j n – 1 gilt:

n

Vij

n

ijn

1

Beweis

ji

ijn

n nV

,

1

zu zeigen:

nnnIVV 1

Page 14: WS 03/04 Algorithmentheorie 02 – Polynomprodukt und Fast Fourier Transformation Prof. Dr. S. Albers Prof. Dr. Th. Ottmann.

14 WS 03/04

Interpolation

ij

jn

n

j

n

j

nni

n

i

n

ijnn

nn

nnn

VV

jiVV

)1(

2

)1(

1

1

1

1

: Spalte , in Zeile von Eintrag Betrachte

Page 15: WS 03/04 Algorithmentheorie 02 – Polynomprodukt und Fast Fourier Transformation Prof. Dr. S. Albers Prof. Dr. Th. Ottmann.

15 WS 03/04

Interpolation

1

0

)(1

0

1 1 n

k

kji

n

n

k

jk

n

ik

n

ijnn nnVV

Fall 1: i = j

1

0

01

01

11 n

k

k

n

n

k

kji

n nn

Fall 2: i j, : | damit

und 11 d.h. jin

njin

1

00

1 n

k

kji

nn

Page 16: WS 03/04 Algorithmentheorie 02 – Polynomprodukt und Fast Fourier Transformation Prof. Dr. S. Albers Prof. Dr. Th. Ottmann.

16 WS 03/04

Interpolation

Summationslemma

:gilt |mit 0,0 alleFür jnjn

1

00

n

k

jkn

Page 17: WS 03/04 Algorithmentheorie 02 – Polynomprodukt und Fast Fourier Transformation Prof. Dr. S. Albers Prof. Dr. Th. Ottmann.

17 WS 03/04

Interpolation

1

0

1

0

1

1

0

1

1

1

,,,1

n

k

kink

n

k

ikn

k

n

nin

in

ini

yn

ny

y

y

y

nnn

yVa

Page 18: WS 03/04 Algorithmentheorie 02 – Polynomprodukt und Fast Fourier Transformation Prof. Dr. S. Albers Prof. Dr. Th. Ottmann.

18 WS 03/04

Interpolation

)1(10

1

1

2

210

1

0

1

0

11

0

10

,,,1

,,,1

n

nnn

n

n

n

k

n

k

kn

nk

kn

k nk

k

nk

rrrn

a

xyxyxyyxr

yyyn

a

Page 19: WS 03/04 Algorithmentheorie 02 – Polynomprodukt und Fast Fourier Transformation Prof. Dr. S. Albers Prof. Dr. Th. Ottmann.

19 WS 03/04

Interpolation und DFT

0 )(1

irDFTn

a inni

)1(10 ,,,1 n

nnnrrr

na

11 ,,,1

nnn

nn rrr

na 1nndenndenn

)(1

00 rDFTn

a n

Page 20: WS 03/04 Algorithmentheorie 02 – Polynomprodukt und Fast Fourier Transformation Prof. Dr. S. Albers Prof. Dr. Th. Ottmann.

20 WS 03/04

Polynomprodukt durch FFT

Berechnung des Produkts zweier Polynome p, q vom Grade < n

p,q Grad n-1, n KoeffizientenAuswertung durch FFT:

2n Punkt/Wertpaare und

Punktweise Multiplikation

2n Punkt/Wertpaare

Interpolation durch FFT

pq Grad 2n-2, 2n-1 Koeffizienten

122

12

02 ,,, n

nnn

i

n

i

n p 22 , i

n

i

n q 22 ,

i

n

i

n pq 22 ,