Re: speed of multiplying polynomials

*To*: mathgroup at smc.vnet.net*Subject*: [mg72556] Re: speed of multiplying polynomials*From*: Giovanni Resta <g.restaxxx at cutTheXXXiit.cnr.it>*Date*: Tue, 9 Jan 2007 07:01:16 -0500 (EST)*References*: <enpste$e5t$1@smc.vnet.net>

dmharvey at math.harvard.edu wrote: > This is ludicrously slow compared to some other computer algebra > systems, which can do this multiplication in about 0.0003 > seconds. I can't believe mathematica is in the order of 10000 times > slower for this simple task. I think perhaps we are doing something > wrong. Can anyone suggest a way of coaxing mathematica into doing this > kind of arithmetic at a comparable pace? I think that the point is that Mathematica multiplies the two expression without regarding them as polynomials, but as general expressions. Indeed, if I have two polynomials: a = Sum[Random[Integer,{1,1000}] x^k,{k,0,1000}]; b = Sum[Random[Integer,{1,1000}] x^k,{k,0,1000}]; And I compute the explicit product: Timing[c = Expand[a b];] {1.28408 Second, Null} If I have something that is not a polynomial: Timing[c = Expand[(a+7/x)(b+Sin[x])];] {1.36808 Second, Null} I got a time which is very near. Hence, probably Mathematica is not taking advantage of the fact that a and b are polynomials, in the first case. In other symbolic programs you have to declare explicitly that something is a polynomial (sometimes you can manipulate only polynomials...) so easily the computation is faster. I do not know if there is a way to tell mathematica that that expressions are polynomials. Usually to perform such a simple tasks, if I need speed, I write a specific C program (unless coefficients are symbolic...). g.