Search
Evaluations
Untitled (the Wolfram Language for Students - Personal Use Only : www.wolfram.com)

How are symbols evaluated

Suppose we start with an undefined symbol

Evaluations_1.png

Evaluations_2.png

We can assign a value to this symbol using = (Set)

Evaluations_3.png

Evaluations_4.png

How does Mathematica know to replace every instance of x with its value?

It uses a global look-up table. We can find the rules for evaluating symbols by calling OwnValues

Evaluations_5.png

Evaluations_6.png

The symbol :→ (typed :>) means replace the lhs with the rhs, and only then evaluate the rhs

HoldPattern is a way of expressing a rule for a symbol without having the symbol transformed by other existing rules

Evaluations_7.png

Evaluations_8.png

Evaluations_9.png

Since we used SetDelayed, we see that in this case y is replaced by a new random number each time

How functions are evaluated

Recall our Fibonacci sequence

Evaluations_10.gif

Evaluations_11.png

Evaluations_12.png

fib has no OwnValues. That’s because if we evaluate

Evaluations_13.png

Evaluations_14.png

no rule is applied. Rules are only applied if we give an argument to fib

Evaluations_15.png

Evaluations_16.png

These kinds of rules (that require arguments) are known as DownValues

Evaluations_17.png

Evaluations_18.png

The order of these rules shows the order in which Mathematica will attempt to apply them

There are also UpValues and SubValues, but they are a bit obscure...

Understanding function evaluation

Trace helps us understand the order in which Mathematica evaluates expressions

Evaluations_19.png

Evaluations_20.png

Evaluations_21.png

Evaluations_22.png

Trace will not show the inner workings of all functions

Evaluations_23.png

Evaluations_24.gif

Evaluations_25.png

Evaluations_26.png

Evaluations_27.png

Evaluations_28.png

However, FindRoot supports EvaluationMonitor

Evaluations_29.png

Evaluations_30.png

Evaluations_31.png

Evaluations_32.png

Evaluations_33.png

Evaluations_34.png