Re: evaluation-- one or many levels, your thoughts?
- To: mathgroup at smc.vnet.net
- Subject: [mg116944] Re: evaluation-- one or many levels, your thoughts?
- From: David Bailey <dave at removedbailey.co.uk>
- Date: Sat, 5 Mar 2011 06:06:29 -0500 (EST)
- References: <ikq8gs$7vl$1@smc.vnet.net>
On 04/03/2011 08:39, Richard Fateman wrote: > How often do you require the behavior that an expression > is evaluated until it stops changing, rather than evaluated > "once"? > > Difference in behavior.. > > once > x1=x2 > x2=x3 > > x1 evaluates to x2 > > "infinite" evaluation until stops changing.. > > x1 evaluates to x3. > > Note that with "once" evaluation, > x=x+1 sets x to "x+1" > > not "recursion depth exceeded". > Note first, that if you examine the value of X1 using OwnValues, you do find that it contains x2. The only reason you suggest (there may be others in your paper) for wanting "once evaluation", would be to potentially speed up calculations by avoiding redundant passes over expressions that are already fully evaluated. Some time ago, I did some timing tests to explore this very issue - for example, x1=large expression; x2=x1; The cost of the assignment to x2 did not seem to increase with the complexity of the large expression, and clearly the kernel uses some pretty clever techniques to prevent redundant reevaluations. In practice, I suspect that users would usually require exhaustive evaluation of expressions, and would have to code this explicitly, which would certainly be slower than letting Mathematica do this job in the first place. I do wish that mistakes like x=x+1 gave an explicit error message, specifying the variable in question! However, I can't see much value in being able to actually store x+1 as the value of x! David Bailey http://www.dbaileyconsultancy.co.uk