       Re: Beware of Simplify[] bottlenecks in v 3.0

• To: mathgroup at smc.vnet.net
• 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 wolfram.com

```> 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
>
> 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:= Timing[simp = Simplify[fp]]

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

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

Pi
Sin[phiQ] Sin[--])) /
8

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

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

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

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

In:= LeafCount[fp]

Out= 116

In:= LeafCount[simp]

Out= 90

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

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

Simplify::time:
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= {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:= Timing[simp = Simplify[fp]][]

Out= 80.728 Second

In:= LeafCount[simp]

Out= 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:= LeafCount[Simplify[fp, Trig -> False]] //Timing

Out= {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