evaluation-- one or many levels, your thoughts?
- To: mathgroup at smc.vnet.net
- Subject: [mg116909] evaluation-- one or many levels, your thoughts?
- From: Richard Fateman <fateman at cs.berkeley.edu>
- Date: Fri, 4 Mar 2011 03:39:00 -0500 (EST)
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". You may not have a clear idea of the answer to this question, since conventionally Mathematica evaluates "as far as possible", and you may not, therefore, have an idea of whether your programs would still work under the "once" model. I invite you to think about this, and whether another model might work for you. I think that the evaluate once model is less onerous for the implementor, and might speed up your computing. Given the "once" model, one can easily write "evaluate until no change". The reverse emulation is much harder, as far as I can tell. The complexity of non-evaluation in Mathematica includes, among other operators, Hold, Holdform, Defer, HoldAll, HoldFirst, HoldRest, Evaluate, Unevaluated, ReleaseHold, HoldComplete, HoldPattern, HoldAllComplete, SequenceHold, Update, NHoldAll, NHoldFirst, NHoldRest, With, Extract.. Some languages make do with about 2 constructs, a mechanism to protect from evaluation (quoting) and some way of re-evaluating. Some time ago I wrote a paper on this topic, http://www.cs.berkeley.edu/~fateman/papers/eval.pdf but some recent programming that I was doing suggested to me that Mathematica was probably doing considerable unnecessary work checking for something that never happened. (That is, after the 1st evaluation, nothing ever changed again.) This is kind of conventional in ordering programming languages, and that's all I seemed to expect as I was writing. The choice between 0 ("Hold") and "perhaps many" defaults to "perhaps many", which in practice was "just once". RJF