Timeline for How does Mathematica determine that an evaluation should be terminated?
Current License: CC BY-SA 2.5
13 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Apr 7, 2014 at 16:47 | comment | added | Leonid Shifrin | @luyuwuli No problem. I should've been more clear. But this was in the comment, not in the answer, and the other folks involved in the conversation knew what I meant. | |
| Apr 7, 2014 at 15:14 | comment | added | luyuwuli | @LeonidShifrin Thanks for the detailed explanation:) Maybe I'm too entangled in the terminology. Sorry to bother you. | |
| Apr 7, 2014 at 14:15 | comment | added | Leonid Shifrin | @luyuwuli You had to follow the discussion more closely. My real statement does not contradict Wagner. The evaluation process first goes down the expression - and during this part, the head is evaluated first indeed (and you can find me stating this in numerous places in my answers here on SE). Then, there is a "going up" stage, in which the arguments has been already evaluated, and then the rules associated with heads are applied. I meant this one. I do agree though, that I used a slightly confusing terminology: I had to say instead that "the rules associated with head ... are applied". | |
| Apr 7, 2014 at 14:03 | comment | added | luyuwuli | @LeonidShifrin "...standard evaluation, first arguments are evaluated...and then the head", while Wagner's book Power Programming with Mathematica page 192 step 5 and 7, indicates that the head should be evaluated first. And it can be verified by f[x_] := x; g = f; g[x + 1 + 1] // Trace. | |
| Jul 28, 2013 at 6:31 | history | migrated | from stackoverflow.com (revisions) | ||
| Mar 17, 2011 at 22:40 | comment | added | Leonid Shifrin | @Alexey Yes this is $IterationLimit - related. If such a variable as you mention is exposed to the top level, I am not aware of it, so you should ask some more knowledgeable people here or on Mathgroup. | |
| Mar 17, 2011 at 22:15 | comment | added | Alexey Popkov | @Leonid As I understand the "evaluation rounds" or "evaluation steps" we discuss are related to $IterationLimit. So there should be some variable that increments on each step and then is compared with $IterationLimit. Is this variable accessible in any way? | |
| Mar 17, 2011 at 13:42 | comment | added | Leonid Shifrin | @Alexey Continuing with the analysis: now when you enter Clear[x]; (1 + x) + 1 // Trace // FullForm, you see that after the Flat attribute applies, and we get HoldForm[Plus[1, 1, x]], this expression is found amenable to further evaluation, Then, the new evaluation round starts, and since it is a new evaluation, x is re-evaluated again, which ultimately leads to an infinite loop. Regarding the evaluation steps, I think Trace can give a pretty clear picture of what is happening. When unsure, you can construct minimal examples, taking out all but what you want to inspect. | |
| Mar 17, 2011 at 13:35 | comment | added | Leonid Shifrin | @Alexey I mean that in the standard evaluation, first arguments are evaluated (in this case, x is evaluated non-trivially), and then the head (Plus in this case) is evaluated, with the corresponding Attributes actions (Flat here) and associated with the head global rules. You can use Clear[x];(1 + x) + y // Trace // FullForm to see that what happens is due to Flat. The same last two steps happen when x is defined non-trivially as above. In either case, the value of x has been computed already,and Mathematica considers it unnecessary to re-evaluate it - perhaps due to optimization | |
| Mar 17, 2011 at 11:26 | comment | added | Alexey Popkov | @Leonid Do you mean that two last transformations both correspond to the one (last) step of evaluation? If so is there a way to check at which transformation a particular step of evaluation starts and at which it ends? | |
| Mar 17, 2011 at 10:34 | comment | added | Leonid Shifrin | @Alexey What you see when you turn on Plus tracking, is the final stage of evaluation ("on the way up"). The line (1+x)+y --> 1+x+y is just the evaluation of Plus (it is Flat), after which the resulting 1+x+y can not be further simplified, so the process stops. With (1+x)+1 it is apparenty different, because a new expression 2+x is produced. This may have to do with optimizations that Mathematica employs to not re-evaluate expressions that it thinks have not changed since the last evaluation. But, admittedly, I don't have a definitive answer here. | |
| Mar 17, 2011 at 10:20 | comment | added | Alexey Popkov | I don not understand why with symbolic y "no further evaluation happens after the first step". On[Plus]; x + y shows that there is (1+x)+y --> 1+x+y transformation. Isn't it an evaluation step? | |
| Mar 17, 2011 at 10:01 | history | answered | Leonid Shifrin | CC BY-SA 2.5 |