MathGroup Archive 2006

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

Search the Archive

Re: Recalculating values in tables?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63898] Re: [mg63881] Recalculating values in tables?
  • From: Sseziwa Mukasa <mukasa at jeol.com>
  • Date: Sat, 21 Jan 2006 01:50:44 -0500 (EST)
  • References: <200601200932.EAA22054@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On Jan 20, 2006, at 4:32 AM, 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?

If by low risk you mean a safe assumption, then the answer is no.   
Mathematica can't know that f1 and f2 do not depend on a global state  
that has changed in value between calls so it does the safest thing  
and executes them again.

> 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} ]
>
> Just wondering how far to trust Mathematica in situations like this?

This is not specific to Mathematica, any programming language that  
allows global state cannot automatically perform the optimization you  
desire.

Regards,

Ssezi


  • Prev by Date: Question about Reduce
  • Next by Date: Re: Weiner process
  • Previous by thread: Recalculating values in tables?
  • Next by thread: Re: Recalculating values in tables?