VIEWS: 4 PAGES: 37 POSTED ON: 8/17/2012
Polynomials and FFT Lecture 11 Prof. Dr. Aydın Öztürk Polynomials A polynomial in the variable x is defined as n 1 A( x) a j x j j 0 where a0 , a1 , an 1 are the coefficiens of the polynomial. Polynomials(cont.) A polynomial A(x) is said have degree k if its highest non-zero coefficient is ak. Any integer strictly greather than the degree of a polynomial is a degree bound of that polynomial. Therefore, the degree of a polynomial of degree bound n may be any integer between 0 and n-1. Polynomial addition If A(x) and B(x) are polynomials of degree bound n, their sum is a polynomial C(x) s.t. C(x)= A(x)+ B(x) For all x underlying their field F that is if n 1 n 1 A( x) a j x j and B ( x) b j x j j 0 j 0 then n 1 C ( x) c j x j j 0 where c j a j b j Polynomial addition(cont.) Example: If A( x) 6 x 3 7 x 2 10 x 9 B ( x ) 2 x 3 4 x 5 then C ( x) 4 x 3 7 x 2 6 x 4 Polynomial multiplication If A(x) and B(x) are polynomials of degree bound n, their product C(x) is a ppolynomial of degree-bound 2n-1 s.t. C(x)= A(x) B(x) for all x underlying their field F. n 1 n 1 A( x) a j x j and B ( x) b j x j j 0 j 0 then 2n 2 C ( x) c j x j j 0 j where c j ak b j k k 0 Polynomial multiplication(cont.) Example: If A( x) 6 x 3 7 x 2 10 x 9 B( x) 2 x 4 x 5 3 then C ( x) A( x) B( x) 12 x 14 x 44 x 20 x 75 x 86 x 45 6 5 4 3 2 Representation of polynomials Coefficient representation A coefficient representation of a polynomial n 1 A( x) a j x j j 0 of degree bound n is a vector of coefficients a (a0 , a1 , an 1 ) Coefficient representation(cont.) A coefficient representation is convenient for certain operations on polynomials. Example: Evaluating A(x) at x0. Evaluation takes time Θ(n) when Horner’s rule is used: A( x0 ) a0 x0 (a1 x0 (a2 x0 (an 2 x0 an 1 )))) Point-value representation A point-value representation of a polynomial A(x) of degree-bound n is a set of poin-value pairs. {( x0 , y0 ), ( x1 , y1 ), , ( xn 1 , y n 1 )} s.t. all of the xk are distinct and y k A( xk ) for k 0,1,, n 1 With Horners’ method, an n-point evaluation takes Θ(n2). Point-value representation(cont.) Addition based on point-value representation: If we have a point value representation for A(x) {( x0 , y0 ), ( x1 , y1 ), , ( xn 1 , y n 1 )} and for B(x) ' ' ' {( x0 , y0 ), ( x1, y1 ),, ( xn 1, yn 1 )} Then a point-value representation for C(x)= A(x)+ B(x) is {(x0 , y0 y0 ), ( x1, y1 y1 ),, ( xn 1, yn 1 yn 1 )} ' ' ' Point-value representation(cont.) The time to add two polynomials of degree bound point- value representation is Θ(n). Point-value representation(cont.) Multiplication based on point-value representation: If we have a point value representation for A(x) {( x0 , y0 ), ( x1 , y1 ), , ( x2n 1 , y 2n 1 )} and for B(x) ' ' ' {( x0 , y0 ), ( x1, y1 ),, ( x2n 1, y2n 1 )} then a point-value representation for C(x)= A(x)B(x) is ' ' ' {(x0 , y0 y0 ), ( x1, y1 y1 ),, ( xn 1, yn 1 yn 1 )} Point-value representation(cont.) The time to multiply two polynomials of degree bound point-value representation is Θ(n). Fast multiplication of polinomials Can we use the linear-time multiplication method for polynomials in point-value form to expedite polynomial multiplication in coefficient form? The answer hinges on our ability to convert a polynomial quickly from coefficient form to point-value form and vice-versa. Fast multiplication of polinomials We can choose the evaluation points carefully, we can convert between representations in Θ(nlg n) time. If we choose complex roots of unity as the evaluation points, we can produce a point-value representation by taking the Discrete Fourier Transform(DFT) of a coefficient vector The inverse operation can be performed by taking the inverse DFT of point-value pairs in Θ(nlg n) time. Fast multiplication of polinomials a0 , a1 , an 1 Ordinary multiplication Coefficient c0 , c1 , c2 n 1 b0 , b1 , bn 1 representation Θ(n2 ) Interpolation time Θ(nlg n) Θ(nlg n) A( 2 n ), 0 B ( 2 n ) 0 C ( 2 n ) 0 A( 1 n ), B ( 1 n ) Pointwise multiplication C ( 1 n ) 2 Point-value 2 2 representation A( 2 n 1 ), 2n n B ( 2 n 1 ) Θ(n) C ( 2 n 1 ) 2n The DFT and FFT In this section we define • Complex roots of unity, • Define the DFT • Show how the FFT computes the DFT Complex roots of unity A complex nth root of unity is a complex number ω s.t. n 1 The n roots are: e 2ik / n , for k 0,1,..., n 1 To interpret this formula we use the defination of exponential of complex number: eiu cos(u) i sin( u) Complex roots of unity The value n e 2i / n is called the principal root of unity. All of the other complex nth roots of unity are powers of n . The n complex nth roots of unity are: n ,1 ,,n 1 , 0 n n Complex roots of unity Lemma-1: For any integers n ≥ 0 and d > 0, dk n dn k Proof: dn (e 2i / dn ) dk dk (e 2i / n ) k wn k Complex roots of unity Corollary: For any even integer n > 0, n / 2 2 1 n Lemma-2: If n > 0 is even then the squares of the nth roots of unity are the (n/2)th roots of unity. Proof: We have ( k ) 2 n / 2 (by lemma-1) k n ( n n / 2 ) 2 n k n k 2 n k n 2 n n k 2 ( n ) 2 k Complex roots of unity Lemma-3: For any integer n ≥ 1 and nonnegative integer k not divisible by n, n 1 ( k ) 0 n j j 0 Proof: n 1 ( n ) n 1 k ( k ) n j j 0 n 1 k ( n ) k 1 n n 1 k (1) k 1 n 1 k 0 The DFT We wish to evaluate a polynomial n 1 A( x) a j x j j 0 of degree bound n at n 1 n ,n ,,n , 0 1 Without loss of generality, we assume that n is a power of 2. (We canalways add new high order zero coefficient as necessary) The DFT Assume that A(x) is given in coefficient form a (a0 , a1 , an 1 ) For k=0,1, ..., n-1 we define y k A( n ) k n 1 a j n kj j 0 The vector y ( y0 , y1 , y n 1 )is called the Discrete Fourier Transform(DFT) of the coefficient vector a (a0 , a1 , an 1 ) We also write y=DFTn(a). The FFT(cont.) Let A[0] ( x) a0 a2 x a4 x 2 an 2 x n / 2 1 A[1] ( x) a1 a3 x a5 x 2 an 1 x n / 2 1 It follows that A( x) A[0] ( x 2 ) xA[1] ( x 2 ) The FFT(cont.) The problem of evaluating A(x) at n ,1 ,,n 1 0 n n reduces to [ 0] 1. Evaluating the degree-bound n/2 polynomials A ( x) and A[1] ( x) at the points (n ) 2 , (1 ) 2 ,, (n 1 ) 2 0 n n as yk A(n ) k 2. Combining the results. Recursive FFT RECURSIVE - FFT( a ) 1 n length[a ] 2 if n 1 3 then return a 4 n e 2i / n 5 1 6 a [ 0 ] ( a 0 , a 2 , , a n 2 ) 7 a[1] (a1 , a3 , , an 1 ) 8 y [ 0] RECURSIVE - FFT( a[0] ) 9 y [1] RECURSIVE - FFT( a[1] ) 10 for k 0 to n / 2 1 11 do y k y [0] y [1] k k 12 y k n / 2 y [0] y [1] k k 13 n 14 return y y is assumed to be a vector. Running time of RECURSIVE-FFT We note that exclusive of the recursive calls, each invocation takes time Θ(n). The recurrence for the running time is therefore T (n) 2T (n / 2) (n) (n lg n) Interpolation We can write the DFT as the matrix product y = Va that is y0 1 1 1 1 1 a0 n 1 y1 1 n n 2 n 3 n a1 1 n 2 n 4 n 6 n ( n 1) 2 y2 a2 1 n 3 n 6 n 9 n ( n 1) 3 y3 a3 ( n 1)( n 1) y n 1 1 n 1 n n 2 ( n 1) 3( n 1) n n an 1 Interpolation(cont.) Theorem: For j,k=0,1, ..., n-1, the ( j,k) entry of the inverse of matrix is kj ( j, k ) n /n Given the inverse matrix V -1, we have that DFTn 1 (y) is given by 1 n 1 kj a j y k n n k 0 Interpolation(cont.) By using the FFT and the inverse FFT, we can transform a polynomial of degree-bound n back and forth between its coefficient representation and a point-value representation in time Θ(n lg n). Interpolation(cont.) Theorem: For any two vectors a and b of length n is a power of 2, a b DFT21 ( DFT2n (a) DFT2n (b)) n Where the vectors a and b are padded with zero’s to length 2n and . denotes the componentwise product of two 2n element vectors. Example Multiply the following polynomials. A( x) 1 x 2 x 2 B( x) 1 2 x 3x 2 Q( x) A( x) B( x) 1 3x 7 x 2 7 x 3 6 x 4 Run time: (n 2 ) Example Multiply the polynomials in (n log n)) a (1, 1, 2, 0, 0) b (1, 2, 3, 0, 0) The Discrete Fourier Transform(DFT) of the coefficient vectors: DFT(a)= [4.000, (-0.309 - 2.126i), (0.809 + 1.314i), (0.809 - 1.314i), ( -0.309+ 2.126i)] DFT(b)= [6.000, (-0.809 - 3.665i), (0.309 + 1.677i), (0.309 -1.677i), (-0.809 + 3.665i)] Example DFT(a)∙DFT(b)= [24.00, (-7.545 + 2.853i), (-1.954 + 1.763i), ( -1.954 - 1.763i), (-7.545 - 2.853i)] a b DFT 1 ( DFT (a) DFT (b)) (1 3 7 7 6)