Re: Recalculating values in tables?
- To: mathgroup at smc.vnet.net
- Subject: [mg63908] Re: [mg63881] Recalculating values in tables?
- From: ggroup at sarj.ca
- Date: Sat, 21 Jan 2006 01:51:08 -0500 (EST)
- References: <200601200932.EAA22054@smc.vnet.net>
- Reply-to: ggroup at sarj.ca
- Sender: owner-wri-mathgroup at wolfram.com
It was Friday, January 20, 2006 at 4:32 AM, when 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?
No. Try it with a simple example:
f1 := n++;
f2 := i++;
n = i = 1;
Table[{f1, f1, f1, f2, f2, f2}, {10}] // InputForm
This gives the output:
{{30, 29, 28, 1, 2, 3}, {27, 26, 25, 4, 5, 6},
{24, 23, 22, 7, 8, 9}, {21, 20, 19, 10, 11, 12},
{18, 17, 16, 13, 14, 15}, {15, 14, 13, 16, 17, 18},
{12, 11, 10, 19, 20, 21}, {9, 8, 7, 22, 23, 24},
{6, 5, 4, 25, 26, 27}, {3, 2, 1, 28, 29, 30}}
> Or should I always take the messier of route of coding these functions
> explicitly in my initialExpressions using something like
Sure looks like it.
<snip>
- References:
- Recalculating values in tables?
- From: AES <siegman@stanford.edu>
- Recalculating values in tables?