2.03.mws
Programming in Maple
Roger Kraft
Department of Mathematics, Computer Science, and Statistics
Purdue University Calumet
roger@calumet.purdue.edu
2.3 Levels of evaluation
Let us go back to the first example of full evaluation defined earlier.
> |
x:='x': y:='y': z:='z':
|
Now if we ask Maple to evaluate
x
, Maple uses full evaluation and returns 3.
But for Maple to get from
x
to 3 it had to go through the intermediate values of
y
and
z
. There is a name for these intermediate values and there is a way to access them also. The name for these intermediate values is
levels of evaluation
and we can control the level of evaluation using a special form of the
eval
command. For example, here is how we get one level of evaluation of
x
, which returns the name
y
.
Here is how we get two levels of evaluation of
x
, which returns the name
z
.
Here is how we get three levels of evaluation of
x
, which returns the value 3.
We can ask for four or higher levels of evaluation, but 3 always evaluates to 3.
Let us unassign the variables that we have used so far.
Here is another example using levels of evaluation.
Now evaluate
f
to several different levels. Mentally check each level of evaluation yourself to make sure that you understand what the
eval
command is doing.
Exercise
: Redo the last example. Can you explain why the results of the example are different the second time that you go through it? How can you get the example to work again like it did the first time?
Levels of evaluation do not work when functions are involved. Consider this example.
Now try using levels of evaluation.
Notice that nothing is being evaluated inside the
sin
function. However, if we use the
eval
command without any level parameter, then everything is fully evaluated.