# [✓] Why is Notebook-level evaluation sometimes done in the wrong order?

Posted 9 months ago
925 Views
|
2 Replies
|
3 Total Likes
|
 Here is a very simple notebook containing three cells. When it is evaluated (via menu Evaluation/Evaluate Notebook) the first time the result of the third cell is incorrect. But if it is evaluated again, then the result is correct. See the two screenshots attached (done on Raspberry Pi 3 running Wolfram Mathematica 11.2.0):
2 Replies
Sort By:
Posted 9 months ago
 Subscript is not special except of the way it is formatted. Let's replace it with e.g. h to clearly show what is the problem: h[m, e] = 10; m = 20; m/h[m, e]  20 / h[20,e] This was the first evaluation. You expected 10 instead of h[20, e] but since nothing prevents m or e from evaluation you end up with h[20,e]. And there is not any rule associated with h[20, e], only with h[m,e] (since it was created before m had value). You can confirm it with: h[Unevaluated[m], e]  10 Now comes the second evaluation, which happens in different circumstances because m already has a value 20, which means that m will freely evaluate and: h[m, e] = 10; Will add h[20, e] = 10 to downvalues of h. Which will make m/h[m, e] evaluate in following steps: m / h[m, e] ---> 20 / h[20, e] ---> 20 / 10 ---> 2 You can always use Trace to inspect evaluation steps or use ? to display rules associated with symbols. Where the latter was tricky in your case as it was about rules for Subscript you've created.
Posted 9 months ago
 Ah.... I understand now! Thank you very much for the explanation. Yes, now everything makes sense! :)If I didn't jump to the conclusion that this is specific to evaluation in the notebook, i.e. if I tried to reproduce it in the terminal-based wolfram session, then everything would have become clear.
Community posts can be styled and formatted using the Markdown syntax.