Introduction to Programming with Mathematica, Third Edition

Appendix A: How Expressions are Evaluated

Evaluation of expressions

Evaluation takes place whenever an expression is entered. Here is the general procedure followed by Mathematica when evaluating an expression (with a few exceptions):

  1. If the expression is a number or a string, it is left unchanged.

    <i class="emphasis">In[1]:</i>= <b class="bold">4.58425</b><i class="emphasis">Out[1]</i>= 4.58425
  2. If the expression is a symbol, it is rewritten if there is an applicable rewrite rule in the global rule base; otherwise, it is unchanged.

    <i class="emphasis">In[2]:</i>= <b class="bold">expr</b><i class="emphasis">Out[2]</i>= expr<i class="emphasis">In[3]:</i>= <b class="bold">my symbol</b><i class="emphasis">Out[3]</i>= my symbol
  3. If the expression is not a number, string or symbol, its parts are evaluated in a specific order:

    • The head of the expression is evaluated.

    • The arguments of the expression are evaluated in order, except when the head is a symbol with a Hold attribute. In this case, some of its arguments are left in their unevaluated forms.

  4. After the head and arguments of an expression are each completely evaluated, the expression consisting of the evaluated head and arguments is rewritten (after making any necessary changes to the arguments based on the Attributes of the head) if there is an applicable rewrite rule in the global rule base.

  5. After carrying out the previous steps, the resulting expression is evaluated in the same way and then the result of that evaluation is evaluated, and so on until there are no more applicable rewrite rules.

The term rewriting process done in steps 2 and 4 above can be described as follows:

  • pattern match parts of...

UNLIMITED FREE ACCESS TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: DC-DC Converter Chips
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.