Group Abstract Group Abstract

Message Boards Message Boards

Why is Notebook-level evaluation sometimes done in the wrong order?

Posted 8 years ago
POSTED BY: Tigran Aivazian
2 Replies

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.

POSTED BY: Tigran Aivazian

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 BY: Kuba Podkalicki
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard