WOLFRAM LANGUAGE TUTORIAL
Principles of Evaluation
The fundamental operation that the Wolfram Language performs is evaluation. Whenever you enter an expression, the Wolfram Language evaluates the expression, then returns the result.
Evaluation in the Wolfram Language works by applying a sequence of definitions. The definitions can either be ones you explicitly entered, or ones that are built into the Wolfram Language.
Thus, for example, the Wolfram Language evaluates the expression using a built‐in procedure for adding integers. Similarly, the Wolfram Language evaluates the algebraic expression using a built‐in simplification procedure. If you had made the definition , then the Wolfram Language would use this definition to reduce to .
The two most central concepts in the Wolfram Language are probably expressions and evaluation. "Expressions" discusses how all the different kinds of objects that the Wolfram Language handles are represented in a uniform way using expressions. This tutorial describes how all the operations that the Wolfram Language can perform can also be viewed in a uniform way as examples of evaluation.
Some interpretations of evaluation.
The Wolfram Language is an infinite evaluation system. When you enter an expression, the Wolfram Language will keep on using definitions it knows until it gets a result to which no definitions apply.
in terms of
, and then defines
If you ask for
, the Wolfram Language uses all the definitions it knows to give you a result.
Here is a recursive definition in which the factorial function is defined in terms of itself.
If you ask for
, the Wolfram Language will keep on applying the definitions you have given until the result it gets no longer changes.
When the Wolfram Language has used all the definitions it knows, it gives whatever expression it has obtained as the result. Sometimes the result may be an object such as a number. But usually the result is an expression in which some objects are represented in a symbolic form.
The Wolfram Language uses its built‐
in definitions for simplifying sums, but knows no definitions for
, so leaves this in symbolic form.
The Wolfram Language follows the principle of applying definitions until the result it gets no longer changes. This means that if you take the final result that the Wolfram Language gives, and enter it as Wolfram Language input, you will get back the same result again. (There are some subtle cases discussed in "Controlling Infinite Evaluation" in which this does not occur.)
If you type in a result from the Wolfram Language, you get back the same expression again.
At any given time, the Wolfram Language can only use those definitions that it knows at that time. If you add more definitions later, however, the Wolfram Language will be able to use these. The results you get from the Wolfram Language may change in this case.
Here is a new definition for the function
With the new definition, the results you get can change.
The simplest examples of evaluation involve using definitions such as which transform one expression directly into another. But evaluation is also the process used to execute programs written in the Wolfram Language. Thus, for example, if you have a procedure consisting of a sequence of Wolfram Language expressions, some perhaps representing conditionals and loops, the execution of this procedure corresponds to the evaluation of these expressions. Sometimes the evaluation process may involve evaluating a particular expression several times, as in a loop.
The expression Print[zzzz]
is evaluated three times during the evaluation of the Do