MathGroup Archive 2005

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

Search the Archive

Re: Computation speeds: numerical vs symbolic

  • To: mathgroup at
  • Subject: [mg55914] Re: Computation speeds: numerical vs symbolic
  • From: carlos at
  • Date: Sat, 9 Apr 2005 03:57:04 -0400 (EDT)
  • References: <d2tfah$ql7$>
  • Sender: owner-wri-mathgroup at

AES wrote:
> No actual question, or at least no immediately useful question in
> post.  I'm just expressing surprise and/or asking for enlightenment
> what seems like a vast disparity in speeds of symbolic vs numerical
> calculations in the latest version of Mathematica.
> To be specific, take an expression like
>   v = Exp[ -a (s+y)] ( Exp[2 a y] Cos[s0 + q (s-y)] - Cos[s0 + q
(s+y)] )
> which happens to have come up in a problem I'm just working on (y and
> are the independent variables of interest, dimensionless surrogates
> space and time; a, q and s0 are parameters; q happens to be an
> in the end).  I then want to evaluate the integral
>    w = Integrate[v^2, {y, 0 , Pi}]
> (symbolically) and make some plots of w versus s, with values of a,
> and q being set by rules for each plot.
> The integration involved here (nothing but products of exponentials
> cosines)  I would describe as trivial but tedious,  that is, I could
> it by hand, but it would be a (very) dull job.  Yet on my Mac iBook
> under Mathematica 5.1, it takes 15 seconds to do this particular
> integration.  If I follow the above cell with a second cell putting
> the "simplifying" assumption
>    w = Integrate[v^2, {y, 0 , Pi}, Assumptions->Element[q,Integers]]
> this calculation takes 27 seconds.
> Oddly, if I immediate re-evaluate either of the cells it only takes
> seconds or 5 seconds, respectively, for the results to come up the
> second time,  but having evaluated the first cell (without the
> Assumption) doesn't seem to speed up the second cell (with the
> Assumption), so it's not like some integration rules have gotten
> and cached in evaluating the first cell and used in evaluating the
> second cell. So, I don't see how I can use this speedup in any
> way (???).
> The speed contrast comes when I then make a single DisplayPlot
> containing Plots of the w function from above and two very similar
> functions wp and wpp versus s for 10 instances of rules specifying
> values of a, s0 and q,  in other words, thirty decaying-sinusoid-like

> curves in all, each containing 5 or 6 complete cycles.  This plot
> appears on the screen faster than I can release the Enter key to
> it.
> So, I'm just curious, how can a calculate and plot command like this
> be so stunningly fast?  and the trivially simple symbolic integration

> above be so slow?

I got these time ratios in my version (4.2.1 on a Mac G4 laptop).

Integrate [ ... ]   1.19 sec   (repeatable)
Simplify[Integrate[  ... ]]   7.05 sec  first time
Simplify[Integrate[  ... ]]   1.03 sec  next time(s)

The ratio between symbolic and numeric can be arbitrarily high.
E.g. a FEM computation I gave in Nov to my class (Intro to FEM
graduate course) as HW. 34 equations. All numbers, no symbols.
On my laptop

Symbolic:           45 minutes
Numeric (float):    0.18 sec

The students were surprised.

  • Prev by Date: Re: Replacement gyrations
  • Next by Date: Re: Re: Re: spiral cipher
  • Previous by thread: Re: Computation speeds: numerical vs symbolic
  • Next by thread: Re: Computation speeds: numerical vs symbolic