CSE 548: Analysis of Algorithms Lecture 4 ( Divide-and-Conquer Algorithms: Polynomial Multiplication ) Rezaul A. Chowdhury Department of Computer Science SUNY Stony Brook Spring 2015
Coefficient Representation of Polynomials is a polynomial of degree bound represented as a vector,,, of coefficients. The degreeof is provided it is the largest integer such that is nonzero. Clearly, 01. Evaluating at a given point: Takes Θ time using Horner s rule:
Coefficient Representation of Polynomials Adding Two Polynomials: Adding two polynomials of degree bound takes Θ time. Then, where, for 01. where, and.
Coefficient Representation of Polynomials Multiplying Two Polynomials: The product of two polynomials of degree bound is another polynomial of degree bound 21. where, and. Then, where, for 022. The coefficient vector,,,, denoted by, is also called the convolutionof vectors,,, and,,,. Clearly, straightforward evaluation of takes Θ time.
Convolution
Convolution
Convolution
Convolution
Convolution
Convolution
Convolution
Coefficient Representation of Polynomials Multiplying Two Polynomials: We can use Karatsuba salgorithm (assume to be a power of 2): Then But 3 recursive multiplications of polynomials of degree bound. Similar recurrence as in Karatsuba sinteger multiplication algorithm leading to a complexity of Ο Ο..
Point-Value Representation of Polynomials A point-value representation of a polynomial is a set of pointvalue pairs,,,,,, such that all are distinct and for 01. A polynomial has many point-value representations. Adding Two Polynomials: Suppose we have point-value representations of two polynomials of degree bound using the same set of points. If then :,,,,,, :,,,,,, :,,,,,, Thus polynomial addition takes Θ time.
Point-Value Representation of Polynomials Multiplying Two Polynomials: Suppose we have extended(why?) point-value representations of two polynomials of degree bound using the same set of 2points. If then :,,,,,, :,,,,,, :,,,,,, Thus polynomial multiplication also takes only Θ time! ( compare this with the Θ time needed in the coefficient form )
Faster Polynomial Multiplication? ( in Coefficient Form ) ordinary multiplication Time Θ evaluation Time? interpolation Time?,,, pointwise multiplication Time Θ
Faster Polynomial Multiplication? ( in Coefficient Form ) Coefficient Representation Point-Value Representation: We select any set of distinct points,,,, and evaluate for 01. Using Horner s rule this approach takes Θ time. Point-Value Representation Coefficient Representation: We can interpolate using Lagrange s formula: This again takes Θ time. In both cases we need to do much better!
Coefficient Form Point-Value Form A polynomial of degree bound : A set of distinct points:,,, Compute point-value form:,,,,,, Using matrix notation: 1 1 1 We want to choose the set of points in a way that simplifies the multiplication. In the rest of the lecture on this topic we will assume: is a power of 2.
Coefficient Form Point-Value Form Let s choose for 0 21. Then 1 1 1 1 1 1 Observe that for 0 21:,,,. Thus we have just split the original matrix into two almost similar matrices!
Coefficient Form Point-Value Form How and how much do we save? where, and., Observe that for 0 21: So in order to evaluate for all 01, we need: 2evaluations of and 2evaluations of multiplications 2additions and 2subtractions Thus we save about half the computation!
Coefficient Form Point-Value Form If we can recursively evaluate and using the same approach, we get the following recurrence relation for the running time of the algorithm: Θ 1, 1, 2 2 Θ,. Θ log Our trick was to evaluate at ( positive ) and ( negative ). But inputs to and are always of the form ( positive )! How can we apply the same trick?
Coefficient Form Point-Value Form Let us consider the evaluation of for 0 21: 1 1 1 In order to apply the same trick on we must set: for 0 4 1
Coefficient Form Point-Value Form In we set: for 0 41. Then 1 1 1 1 1 1 This means setting, where 1( imaginary )! This also allows us to apply the same trick on.
Coefficient Form Point-Value Form We can apply the trick once if we set: for 0 21 We can apply the trick ( recursively ) 2 times if we also set: for 0 2 1 We can apply the trick ( recursively ) 3 times if we also set: for 0 2 1 We can apply the trick ( recursively ) times if we also set: for 0 2 1
Coefficient Form Point-Value Form Consider the primitive root of unity: Then cos sin 1
Coefficient Form Point-Value Form If 2 we would like to apply the trick times recursively. What values should we choose for,,,? Example: For 2 we need to choose,,,. Choose: 1 3: 2: 1: 1 1 complex roots of unity
Coefficient Form Point-Value Form For a polynomial of degree bound 2, we need to apply the trick recursively at most logtimes. We choose 1 and set for 11. Then we compute the following product: 1 1 1 1 1 1 1 1 The vector,,, is called the discretefourier transform( DFT ) of,,,. This method of computing DFT is called the fast Fourier transform ( FFT ) method.
Coefficient Form Point-Value Form Rec-FFT ( ( a 0, a 1,, a n - 1 ) ) { n = 2 k for integer k 0 } 1. if n = 1 then 2. return ( a 0 ) 3. ω n e 2πi/n 4. ω 1 5. y even Rec-FFT ( ( a 0, a 2,, a n - 2 ) ) 6. y odd Rec-FFT ( ( a 1, a 3,, a n - 1 ) ) 7. for j 0 to n/2 1 do 8. y j y even j + ω y odd j 9. y n/2+j y even j ω y odd j 10. ω ω ω n 11. return y Running time: Θ 1, 1, 2 2 Θ,. Θ log
Faster Polynomial Multiplication? ( in Coefficient Form ) ordinary multiplication Time Θ forward FFT Time Θ log interpolation Time?,,, pointwise multiplication Time Θ Next Lecture will Cover Interpolation