180 likes | 309 Views
w : the primitive n th root of unity. A Straightforward way of O( n 2 ) time !!! n 2 multiplications. …………………………………. …………………………………. P ( x ) = P n -1 x n -1 + P n -2 x n -2 + … + P 1 x 1 + P 0 n = 2 k. k 4. P ( x ) = P 0 + P 1 x + … + P 15 x 15. n = 2 4. 3.
E N D
w : theprimitive nth root of unity A Straightforward way of O(n2) time !!! n2 multiplications …………………………………. ………………………………….
k 4 P(x) = P0 + P1x + … + P15x15 n = 24 3 P1 + P3x + … + P15x7 P0 + P2x + … + P14x7 2 P0 + P4x + P8x2 + P12x3 P1 + P5x + P9x2 + P13x3 P2 + P6x + P10x2 + P14x3 P3 + P7x + P11x2 + P15x3 1 P0 + P8x P4 + P12x P2 + P10x P6 + P14x P1 + P9x P5 + P13x P3 + P11x P7 + P15x 0 P0 P8 P4 P12 P2 P10 P6 P14 P1 P9 P5 P13 P3 P11 P7 P15 For a polynomial p at any internal node, the left child is peven and the right child is podd
n = 2k p(xi) p(-xi) Level l Level l+1 Peven((wi)2) Podd((wi)2) xi = wi i i i i
procedureRecursiveFFT(P:RealArray; k,m:integer; vartransform:ComplexArray); var evens, odds : ComplexArray; xPOdd : Complex; j : integer; begin ifk=0 then transform[0] = p0; else {Evaluate peven at the 2k-1th roots of 1} RecursiveFFT((p0,p2,, ); k–1; 2m; evens); : M(k–1) {Evaluate poddat the 2k-1th roots of 1} RecursiveFFT((p1,p3,, ); k–1; 2m; odds); : M(k–1) for j := 0 to 2k-1–1 do {evaluate p(wj) and } xPOdd := omega[mj] ×odds[j]; transform[j] := evens[j] + xPOdd; 2k–1 {Compute } transform[2k-1 + j] := evens[j] – xPOdd end{for} end{if} end{RecursiveFFT} M(k) = 2M(k–1) + 2k–1
n = 2k,n/2 = 2k–1, k = log n M(0) = 0 M(k) = 2k–1 + 2M(k–1) = 2k–1 + 2·2k–2 + 22M(k–2) M(k) = k·2k–1 = (n/2)log2n O(nlog n) 2(2k–2 + 2M(k–2)) = 2k–1 + 4M(k–2)
Pm 0’s Qm 0’s
Given p(x) and q(x), find r(x). (symbolic Multiplication) (1) Evaluate p(x) and q(x) at 2m points. x0, x1, x2, ···, x2m-1 (2) r(xi)=p(xi) q(xi) , i = 0, 1, ···,2m-1 (xi,r(xi)), i = 0, 1, ···, 2m-1 (3) Compute (r0, r1, ···, r2m-1) r(x) = p(x) · q(x) r(x) = r2m-1x2m-1 + ··· + r0
Step (1) xi= wi i = 0,1,···, 2m-1 p(wi) q(wi) O(mlog m) Why? Step (2) r(xi) = p(xi) q(xi) i = 0,1,···, 2m-1 O(m) Step (3) wi r(wi) (xi,r(xi)) r(wi) = r0 + r1(wi)1 + r2(wi)2 + ··· + r2m-1(wi)2m-1 r(wi) = zi F2mR = Z R = F2m–1Z i = 0,1,···, 2m-1 r(wi) = p(wi) q(wi)
Lemma : Forn>0, Fnis invertible and the (i, j)th entry of its inverse is (1/n)w-ij for 0 i, j n-1 [ Proof ] c = Why? n does not divide i–j if i j
Theorem 7.7 Let U and V be n-vectors. Then UV = Fn-1(FnU*FnV), where * denotes multiplication. Fn(UV) = FnU*FnV [ Proof ] We show that Fn(UV) = FnU*FnV. For 0 i n–1, the i th component of FnU*FnV is The t th component of UV is where subscripts are taken modulo n. Thus the i th component of Fn(UV) is Let k = t – j (mod n) in the inner summation. For each j, since t ranges from 0 to n–1, k will also range from 0 to n–1, although in a different order. Also, for any p, wp = wp(mod n), so the i th component of Fn(UV) is which is exactly the i th component of FnU*FnV
nFn-1 = [w-ij] why ? w-i = wn–iw-i = wn·w-i wn = 1 Row Permutation !!! w(n–i)jw–ij FnnFn–1 n–ith row ith row w(–i)j = w(n-i)j
Algorithm : Inverse Discrete Fourier Transform Input : A, n, where A is an n-vector ; n is a power of 2. Output : The vector B = (b0,b1,···,bn-1), where B = Fn–1A Procedure InverseFT ( A: ComplexArray; n : integer; varB : ComplexArray); var i : integer; transform : ComplexArray ; begin FFT(A, n, transform) ; b0 := transform[0] / n ; for i := 1 ton–1 do bi = transform[n-i] / n ; w-i = wn-i end { for } ; row permutation end { inverseFT } ;