MathGroup Archive 2006

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

Search the Archive

Re: Recalculating values in tables?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63919] Re: Recalculating values in tables?
  • From: Bill Rowe <readnewsciv at earthlink.net>
  • Date: Sun, 22 Jan 2006 00:52:33 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

On 1/20/06 at 4:32 AM, siegman at stanford.edu (AES) wrote:

>If I'm evaluating a table with something like

>Table[ {initialExpressions; f1, f2, Sqrt[(f1-f2)/(f1*f2)},
>{iterator} ]

>where  f1, f2, f3  are slow-to-evaluate functions (possibly with
>explicit variables, which will be the same for all three calls to
>the f's), I'm tempted to assume that Mathematica will be smart
>enough to evaluate  f1, f2 and f3 just once, not three times, for
>each line in the Table.  Is this low risk?

I would make exactly the opposite assumption, i.e., Mathematica will evaluate each function again when it is called again. It is difficult to know just how much impact this will have on performance since Mathematica does cache calculations. So, when a function is called for a second evaluation, quite often the second evaluation occurs much more quickly but probably still with some performance hit.

>Or should I always take the messier of route of coding these
>functions explicitly in my initialExpressions using something like

> Table[ { initialExpressions;
>            g1=f1;
>            g2=f2;
>            g3=f3;
>            g1, g2, Sqrt[(g1-g2)/(g1*g2)}, {iterator} ]

Another alternative would be to use dynamic programming, i.e., writing your slow-to-evaluate functions along the lines of

f[x_]:=f[x]=expr

Then whenever f is evaluated a new rule is created and attached to it so the computation is not repeated and f evaluates essentially immediately. Of course there is a cost for doing things this way. The memory needed for f will be larger than it would be if dynamic programming were not used.
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: Question about Reduce
  • Next by Date: Re: Problem plotting high-order Laguerre polynomials
  • Previous by thread: Re: Re: Recalculating values in tables?
  • Next by thread: NDSolve and vector variables