Re: Computation speeds: numerical vs symbolic
- To: mathgroup at smc.vnet.net
- Subject: [mg55879] Re: Computation speeds: numerical vs symbolic
- From: Paul Abbott <paul at physics.uwa.edu.au>
- Date: Fri, 8 Apr 2005 01:37:15 -0400 (EDT)
- Organization: The University of Western Australia
- References: <d2tfah$ql7$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
In article <d2tfah$ql7$1 at smc.vnet.net>, AES <siegman at stanford.edu>
wrote:
> No actual question, or at least no immediately useful question in this
> post. I'm just expressing surprise and/or asking for enlightenment on
> 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 s
> are the independent variables of interest, dimensionless surrogates for
> space and time; a, q and s0 are parameters; q happens to be an integer
> 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, s0
> and q being set by rules for each plot.
>
> The integration involved here (nothing but products of exponentials and
> cosines) I would describe as trivial but tedious, that is, I could do
> it by hand, but it would be a (very) dull job. Yet on my Mac iBook G4
> under Mathematica 5.1, it takes 15 seconds to do this particular
> integration.
It is trivial -- and you can speed things up considerably using
indefinite integration and substituting in the limits (as you would do
by hand).
int = Integrate[v^2, y];
Timing[Simplify[(int /. y -> Pi) - int /. y -> 0), Element[q,Integers]]
You can justify this approach for this example.
> If I follow the above cell with a second cell putting in
> 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 2.7
> 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 loaded
> 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 practical
> way (???).
Indeed, you cannot.
> 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 create
> 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'm suprised that you think this. In general, direct numerical
computation is _much_ easier and faster than symbolic computation,
especially definite symbolic integration.
Cheers,
Paul
--
Paul Abbott Phone: +61 8 6488 2734
School of Physics, M013 Fax: +61 8 6488 1014
The University of Western Australia (CRICOS Provider No 00126G)
35 Stirling Highway
Crawley WA 6009 mailto:paul at physics.uwa.edu.au
AUSTRALIA http://physics.uwa.edu.au/~paul