MathGroup Archive 1997

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

Search the Archive

Re: Strange timing behavior of Integrate[]

  • To: mathgroup at
  • Subject: [mg8380] Re: Strange timing behavior of Integrate[]
  • From: carlos at mars.Colorado.EDU (Carlos A. Felippa)
  • Date: Tue, 26 Aug 1997 20:41:15 -0400
  • Organization: University of Colorado, Boulder
  • Sender: owner-wri-mathgroup at

In article <bruck-ya02408000R2208971202520001 at> bruck at (Ronald Bruck) writes:
>In article <5thq18$43q at>, carlos at mars.Colorado.EDU (Carlos
>A. Felippa) wrote:
>:I am doing an acoustic radiation study with Mma 3.0 in which I have to 
>:evaluate thousands of trigonometric integrals of the form sin[phi]^m*cos[phi]^n
>:over 0->2 Pi for a wide range of integers m and n.  I noticed that some 
>:combinations took enormous times to evaluate forcing aborts.
>:I traced it to the phenomenon exemplified by the equivalent commands
>:Print [Integrate[(a+b)^12*Cos[phi]^8*Sin[phi]^8,{phi,0,2*Pi}]//Timing];
>:Print [(a+b)^12*Integrate[Cos[phi]^8*Sin[phi]^8,{phi,0,2*Pi}]//Timing];
>:The result is obviously the same.  However, On a Mac 8500/120, 
>:the first form takes 4.85 seconds while the second completes in 0.53 Seconds.  
>:For more complex factors the time ratio may reach into the thousands.
>:What is going on?  It seems as if Integrate[] cannot identify invariant
>I get similar timings.  Perhaps Mathematica is expanding the (a+b)^12 when
>it's inside the integral and computing the 13 resulting integrals
>separately?  You could try tracing the calculation.
>Sometimes Mathematica's integration routines are just plain dumb.  For example,
>  Integrate[x^2 (1+x^3)^4000,x]
>expands the power and integrates the resulting 4001-term polynomial! 
>(Taking 42.85 seconds on my PowerTower Pro 225, using //Short.)  Yet it
>  Integrate[x^2 (1+x^3)^n,x]
>correctly (albeit in a strange form, as
>  1/3 (1+t^3)^n (1/(1+n) + t^3/(1+n)).
>Now 100% ISDN from this address

Internal expansion is most likely responsible.  I have not traced the
interior flow, but the following results are suggestive:

  Print [(a+b)^100*Integrate[Cos[phi]^8*Sin[phi]^8,{phi,0,2*Pi}]//Timing];
  Print [Integrate[(a+b)^n*  Cos[phi]^8*Sin[phi]^8,{phi,0,2*Pi}]//Timing];
  Print [Integrate[(a+b)^100*Cos[phi]^8*Sin[phi]^8,{phi,0,2*Pi}]//Timing];

Timings: 0.533, 0.850 and 72 seconds, respectively, with Mma 3.0.  Even
more unbalance noted with version 2.2.1: 0.266, 0.466 and 171 seconds, 
respectively, a ratio of near 1000:1.

In my radiation problem, after careful reprogramming using Coefficient[] to extract 
invariant factors outside Integrate[], I was able to cut the time of a typical
run from about 4hrs (overnight) to 40-50 seconds.  Equally important, the max kernel
memory use dropped from 62MB to 7MB. (On the Mac OS, memory overflow is deadly).

  • Prev by Date: Mma 2.2: Display and PostScript Question
  • Next by Date: Live subscripts
  • Previous by thread: Strange timing behavior of Integrate[]
  • Next by thread: Re: Strange timing behavior of Integrate[]