5

I have been trying to figure tis ou for 3 days and have not gotten anywhere. I have to implement polynomial multiplication (multiply 2 quadratic equations). They look like:

( a1 x^2 + b1 x + c1 ) * ( a2 x^2 + b2 x + c2 );

But the trickier part is to implement it in 5 coefficient multplications. I have reduced it to 6. For eg, a1 * b1, ( a1 + a2 ) * ( b1 + b2 ) count as one multiplication. But (a1 x + a2 ) * ( b1 x + b2 ) count as 4 (a1 b1, a1 b2, a2 b1, a2 b2).

tshepang
  • 12,111
  • 21
  • 91
  • 136
Brahadeesh
  • 2,245
  • 8
  • 40
  • 58

3 Answers3

3

Hmm I think I found the answer.

you replace it to ( x * ( A1*x + b1 ) + c1 ) * ( x *( a2 * x + b2 ) + c2 );

and there you have it 5 multiplications .

Sorry this was edited , my first answer was wrong and had 9 multiplications indeed.

Valentin Kuzub
  • 11,703
  • 7
  • 56
  • 93
  • I think he's counting that as 9 multiplications. – ThomasMcLeod Feb 16 '11 at 06:35
  • Yes That is 9 multiplications. If yo want me to specify, I'll do it. But its pretty obvious. – Brahadeesh Feb 16 '11 at 06:36
  • @Brahadeesh It's not at all obvious. There are five multiplications in that formula. You've tagged the question as optimal but then you seem to insist on expanding your equations. That's what you do when you want something that is sub-optimal. – David Heffernan Feb 16 '11 at 07:02
  • @David I am sorry. I thought 5 multiplication implementation would be optimal. – Brahadeesh Feb 17 '11 at 14:19
  • @valentin. I dont think that is 5 multiplications too. Let (a1 x + b1)=m1, (a2 x + b2)=m2. The product (m1 * x + c1)(m2 * x + c2) requires c1*c2, m1*m2 and (m1+c1)(m2+c2) {for now 3 multiplications} since m1c2+m2c1 can be written as (m1+c1)(m2+c2) - m1m2 - c1c2. But m1m2 requires another 3 multiplications. So a total of 6 multiplications. – Brahadeesh Feb 17 '11 at 14:23
  • So you cannot count? too bad how can it be 6 multiplications when it has 5 * signs =) ok ill do it for you (a1*x+b1) M1, X*M1+C1 =M2, (A2*x+b2)=M3 (x*M3+c2)=M4 , M3*M4= M5 – Valentin Kuzub Feb 17 '11 at 14:25
  • @David I guess I have to be clearer. I meant coefficient multiplication. c1*c2 is a coefficient multiplication. But c1*x is not. I dont want to multiply with x. x is an unknown. I just want the coefficients of the resultant polynomial. – Brahadeesh Feb 17 '11 at 14:29
  • @valentin Please refer my last comment to David. a1*x+c1 is not a coefficient multiplication. – Brahadeesh Feb 17 '11 at 14:32
  • Ahh sorry okay I understand what you mean now. Nice question though, Toom-Cook looks serious! – Valentin Kuzub Feb 17 '11 at 14:41
3

You may want to have a look at the Toom-3 algorithm used in multiprecision multiplication. Ref: Toom-Cook multiplication.

Basically, you eval each polynomial at x=-2,-1,0,+1,infinity using only additions and shifts, then multiply these 5 values to get the values of the product at x=-2,-1,0,+1,infinity. The final step is to get back to the coefficients of the result.

For P(X) = A*X^2 + B*X + C the values at x=-2,-1,0,+1,infinity are:

P(-2) = 4*A - 2*B + C  (the products here are bit shifts)
P(-1) = A - B + C
P( 0) = C
P(+1) = A + B + C
P(oo) = A

The product R(X) = T*X^4 + U*X^3 + V*X^2 + W*X + K, and the values are:

R(-2) = 16*T - 8*U + 4*V - 2*W + K
R(-1) = T - U + V - W + K
R( 0) = K
R(+1) = T + U + V + W + K
R(oo) = T

You know the values R(x) = P(x)*Q(x) for x=-2,-1,0,+1,infinity, and you have to solve this linear system to get coefficients T,U,V,W,K.

Jonas
  • 1,019
  • 4
  • 20
  • 33
Eric Bainville
  • 9,738
  • 1
  • 25
  • 27
0

I have also found a 6 multiplication solution, which could help yourself or others solve.

M1 := (a1 + b1)*(a2 + b2)  
M2 := (a1 + c1)*(a2 + c2)  
M3 := (b1 + c1)*(b2 + c2)  
M4 := a1 * a2  
M5 := b1 * b2  
M6 := c1 * c2

This then gives :

M4 * x^4 + 
(M1 - M4 - M5) * x^3 + 
(M2 - M4 - M6 + M5) * x^2 +
(M3 - M5 - M6) * x +
M6
threenplusone
  • 2,112
  • 19
  • 28