Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #13008 > unrolled thread
| Started by | Roman Pearce <rpearcea@gmail.com> |
|---|---|
| First post | 2013-01-01 00:45 +0000 |
| Last post | 2013-01-07 05:35 +0000 |
| Articles | 4 — 2 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
PolynomialQuotient slow Roman Pearce <rpearcea@gmail.com> - 2013-01-01 00:45 +0000
Re: PolynomialQuotient slow danl@wolfram.com - 2013-01-03 02:14 +0000
Re: PolynomialQuotient slow Roman Pearce <rpearcea@gmail.com> - 2013-01-05 07:17 +0000
Re: PolynomialQuotient slow danl@wolfram.com - 2013-01-07 05:35 +0000
| From | Roman Pearce <rpearcea@gmail.com> |
|---|---|
| Date | 2013-01-01 00:45 +0000 |
| Subject | PolynomialQuotient slow |
| Message-ID | <kbtbip$cph$1@smc.vnet.net> |
Something seems wrong here with the performance of PolynomialQuotient. Is there blowup because the leading coefficient in x is a polynomial? Also it seems slower in Mathematica 9 versus v8. d = 5 f = Expand[ ((1+x)*(1+y)*(1+z))^d + 1 ]; g = Expand[ ((1-x)*(1-y)*(1-z))^d + 1 ]; AbsoluteTiming[ p = Expand[ f g ]; ] AbsoluteTiming[ q = PolynomialQuotient[p, f, x]; ] AbsoluteTiming[ P = Factor[ p ]; ] What is the preferred method for (exact) division of polynomials? On this example I tried Cancel[ p/f ] and it works fine, but on other problems it is faster to use PolynomialQuotient. Suggestions?
[toc] | [next] | [standalone]
| From | danl@wolfram.com |
|---|---|
| Date | 2013-01-03 02:14 +0000 |
| Message-ID | <kc2pi2$md9$1@smc.vnet.net> |
| In reply to | #13008 |
On Monday, December 31, 2012 6:45:13 PM UTC-6, Roman Pearce wrote:
> Something seems wrong here with the performance of PolynomialQuotient. Is there blowup because the leading coefficient in x is a polynomial? Also it seems slower in Mathematica 9 versus v8.
>
>
>
> d = 5
>
> f = Expand[ ((1+x)*(1+y)*(1+z))^d + 1 ];
>
> g = Expand[ ((1-x)*(1-y)*(1-z))^d + 1 ];
>
> AbsoluteTiming[ p = Expand[ f g ]; ]
>
> AbsoluteTiming[ q = PolynomialQuotient[p, f, x]; ]
>
> AbsoluteTiming[ P = Factor[ p ]; ]
>
>
>
> What is the preferred method for (exact) division of polynomials? On this example I tried Cancel[ p/f ] and it works fine, but on other problems it is faster to use PolynomialQuotient. Suggestions?
Hi Roman,
Yes, PolynomialQuotient is slow. It is, as you suspected, intrinsically "univariate" and thus does not work in a fraction-free manner when coefficients are themselves polynomials.
Here are some possibilities for improved speed.
(1) Use PolynomialReduce (in the sense of computing Groebner bases).
(2) Use PolynomialMod, as that seems better able to find a remainder quickly. Then subtract that from the dividend and Together the result over the divisor. If you know the division is exact to begin (as in this example) with you can skip the PolynomialMod step.
(3) Use a certain (undocumented) internal function.
Here are the three approaches.
In[51]:= AbsoluteTiming[{q2, r} =
PolynomialReduce[p, f, Variables[{p, f}]]; q2 = First[q2];]
Out[51]= {0.052611, Null}
In[54]:= AbsoluteTiming[r = PolynomialMod[p, f];
q3 = Together[(p - r)/f];]
Out[54]= {0.086507, Null}
In[59]:= AbsoluteTiming[q4 = Algebra`IPExactQuotient[p, f];]
Out[59]= {0.013560, Null}
In[69]:= Together[q] === q2 === q3 === q4
Out[69]= True
Regards,
Daniel
[toc] | [prev] | [next] | [standalone]
| From | Roman Pearce <rpearcea@gmail.com> |
|---|---|
| Date | 2013-01-05 07:17 +0000 |
| Message-ID | <kc8k29$b15$1@smc.vnet.net> |
| In reply to | #13015 |
Thanks Daniel, the internal routine seems to be what I want, as its time is comparable to Expand. And it is parallelized? This is very nice work. Can I ask if it is recursive or distributed? I'd appreciate any references where I can read about it. Two things we noticed were that ExactQuotient sometimes uses more threads and gets better speedup than Expand, so it may be possible to improve Expand, and Factor doesn't seem to use the parallel algorithms which is something to consider if you haven't already. f = Expand[ (1+x+y+z+t)^30+1 ]; g = f+1; AbsoluteTiming[ p = Algebra`IPExpand[ f g ]; ] AbsoluteTiming[ q = Algebra`IPExactQuotient[ p, f ]; ] We were also excited to see some of the other core algorithm improvements in Mathematica 9. I think you have a very strong release here. All the best in the new year :)
[toc] | [prev] | [next] | [standalone]
| From | danl@wolfram.com |
|---|---|
| Date | 2013-01-07 05:35 +0000 |
| Message-ID | <kcdmqp$lvg$1@smc.vnet.net> |
| In reply to | #13037 |
On Saturday, January 5, 2013 1:17:29 AM UTC-6, Roman Pearce wrote: > Thanks Daniel, the internal routine seems to be what I want, as its time is comparable to Expand. And it is parallelized? This is very nice work. Can I ask if it is recursive or distributed? I'd appreciate any references where I can read about it. It is using the sparse recursive form. The speed derives use of GMP integers rather than explicit Mathematica integers. Not much difference between these; the main thing is the memory management. At least that's what I've been told. From your experiments I guess it may also be using multiple processors. Offhand I do not see how, but it's Sunday... The person to ask if you want more detail would be Adam Strzebonski. I don't think there is anything going on other than what I noted above, but if there is something smart in parallelization then yes, that would warrant more detail (at least, more than I can provide). > Two things we noticed were that ExactQuotient sometimes uses more threads and gets better speedup than Expand, so it may be possible to improve Expand, and Factor doesn't seem to use the parallel algorithms which is something to consider if you haven't already. I am not sure what the plan is there. It's a large job to tackle. But I agree the potential for improvement is substantial. I should add that to some extent it is already in Factor, and has been for a very long time. That is to say, the underlying sparse recursive division has been there. (I believe) the bulk of the further improvement comes from having GMP handle the allocation/deallocation stuff. It is this aspect that, I think, is not at this time inside Factor. > f = Expand[ (1+x+y+z+t)^30+1 ]; g = f+1; > > AbsoluteTiming[ p = Algebra`IPExpand[ f g ]; ] > > AbsoluteTiming[ q = Algebra`IPExactQuotient[ p, f ]; ] > > > > We were also excited to see some of the other core algorithm improvements in Mathematica 9. I think you have a very strong release here. All the best in the new year :) Same to you, Roman. Feel free to sent a note off-line if this does not cover all your questions. Regards, Daniel
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web