MathGroup Archive 1997

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Beware of Simplify[] bottlenecks in v 3.0

  • To: mathgroup at
  • Subject: [mg8987] Re: [mg8925] Beware of Simplify[] bottlenecks in v 3.0
  • From: David Withoff <withoff>
  • Date: Tue, 7 Oct 1997 03:35:33 -0400
  • Sender: owner-wri-mathgroup at

> After installing v 3.0 on my Max 8500/120 I have done some side 
> by side timing tests with old Notebooks comparing the speed of
> Mma 2.2 vs 3.0.  Generally v. 3.0 is 10% to 60% slower in most cases,
> but ocassionally I found it to be an order of magnitude slower.  
> I traced the difference to the frequent use of the Simplify function.  
> This used to be a bottleneck in 2.2, and can be even more so in 3.0.  
> The following code fragment, extracted from an old Notebook, 
> illustrates the dramatic speed difference:
> fp=(a*(2*a + a*Cos[phiQ])*(2*a*Cos[phiQ]*(1 - Cos[theta]) +
>  a*(1 - Cos[phiQ]*Cos[Pi/8]*Cos[theta] - Sin[phiQ]*Sin[Pi/8])))/
>  (2*2^(1/2)*(5*a^2 - (2*a + a*Cos[phiQ])*(2*a + a*Cos[Pi/8])*Cos[theta] + 
>  a*(2*a*(Cos[phiQ] + Cos[Pi/8]) - a*Sin[phiQ]*Sin[Pi/8]))^(3/2));
> Print[Timing[fp=Simplify[fp]]];
> Mma 2.2:  15.75 Seconds
> Mma 3.0: 140.517 Seconds - same result
>I tried to limit the operation to 15 seconds to see if 3.0 can return the 
> same answer quicker:
> Print[Timing[fp=Simplify[fp,TimeConstraint->15]]];
> but the option is ignored:
> Mma 3.0: 142.417 Seconds 
> The purpose of this post is to warn users converting to 3.0 about
> such bottlenecks, and that they are uncontrollable until the
> TimeConstraint option works.

The TimeConstraint option limits the amount of time for individual
transformations within Simplify, not the total time.   On my computer
I was able to use the TimeConstraint option to cut the simplification
time in half.  Here is the timing that I found using Mathematica
Version 3.0.1 for Windows on my 100 MHz Pentium computer (which
is apparently quite a bit slower than your computer):

In[2]:= Timing[simp = Simplify[fp]]

Out[2]= {319.28 Second, -(a  (2 + Cos[phiQ])

      (-1 + Cos[phiQ] (-2 + (2 + Cos[--]) Cos[theta]) +

        Sin[phiQ] Sin[--])) /

                     2                         Pi
   (2 Sqrt[2] Power[a  (5 + 2 (Cos[phiQ] + Cos[--]) -

         (2 + Cos[phiQ]) (2 + Cos[--]) Cos[theta] -

         Sin[phiQ] Sin[--]), 3/2])}

This result is significantly simpler (as measured by LeafCount)
that the original expression:

In[3]:= LeafCount[fp]

Out[3]= 116

In[4]:= LeafCount[simp]

Out[4]= 90

I got a similar result in about half the time by including
the TimeConstraint option:

In[9]:=Timing[LeafCount[Simplify[fp, TimeConstraint -> 1]]]

   Time spent on a transformation exceeded 1
     seconds, and the transformation was aborted. Increasing
     the value of TimeConstraint option may improve the
     result of simplification.

Out[9]= {151.7 Second, 92}

This can be compared with the result using Mathematica Version 2.2.3
on the same computer.  A result is returned about four times faster
in that version, but there is almost no simplification.  (I did not
observe the factor of nine speed difference that you reported.  Perhaps
you were using a different version of Mathematica.)

In[2]:= Timing[simp = Simplify[fp]][[1]]

Out[2]= 80.728 Second

In[3]:= LeafCount[simp]

Out[3]= 113

The Simplify function in Version 3.0 will be slower for some examples
because it tries more transformations.  In this example, Version 3.0
finds some simplifications that Version 2.2 didn't find.  You can use
the TimeConstraint option in Version 3.0 to exclude the transformations
that use the most time.

If you are concerned about speed, you can get considerable speed
improvement (and the same result) by turning off the trigonometric
transformations.  Here is a timing in Version 3.0.1:

In[10]:= LeafCount[Simplify[fp, Trig -> False]] //Timing

Out[10]= {11.15 Second, 90}

The Simplify function applies various transformations to the expression
and to every subexpression, and returns the simplest result that it
finds.  If you are even more concerned about speed, you may want to
be more selective in choosing transformations.  You can get the
simplifications in this example in a fraction of a second with careful
application of Collect and FactorSquareFree.

Dave Withoff
Wolfram Research

  • Prev by Date: Re: Re: How to select a cell in Mathematica?
  • Next by Date: Re: soliton interactions
  • Previous by thread: Beware of Simplify[] bottlenecks in v 3.0
  • Next by thread: List of lists in MultipleListPlot