4.4 Maple: Assignment and Evaluation

So far, when we use the name 'y', we always mean "the unknown quantity named y". It is also possible to use a name like 'y' to label other expressions. This is called assignment:
> y := x^3 - 21 * x;

			    y := x  - 21 x

> y;

			       x  - 21 x

> y^2;

			      3        2
			    (x  - 21 x)

> expand( y^2 );

			   6       4        2
			  x  - 42 x  + 441 x
Here, the operator := makes 'y' a name for the expression x^3 - 21 * x. Everywhere you write y, Maple substitutes the expression x^3 - 21 * x. This is known as an evaluation of the symbolic name 'y'.

You can prevent Maple from evaluating a name by putting the name in single-quotemarks. Notice the difference:

> x := 4;

				x := 4

> y := 5 * x + 3;

				y := 23

> y := 5 * 'x' + 3;

			    y := 5 x + 3
In the second statement, y is assigned the constant value 23. In the third, y is assigned the value "5 times the value of x plus 3". If the value of x changes, then so will the value of y.

In fact, you should think of the single-quotemarks as an expression whose value is exactly the expression they contain--in unevaluated form. You can nest them one inside the other:

> ''x'';


> ";


> ";

So the result of quoting an expression is to "delay" its evaluation. Another special occasion where Maple doesn't evaluate a symbol is when it appears as the left-hand side of an assignment statement (think of why this is so!).

One important thing to remember is: every symbol in Maple has a value. Initially, the value of a symbol is its own name. The initial value of the symbol x is the name x. This implies that you can "unassign" a variable by assigning its own (quoted) name to itself:

> x;


> x := 'x';

				x := x

> x;

The corollary of this is that there is no such thing in Maple as an "undefined symbol" error. There can only be syntax errors or mathematical errors such as dividing by 0. Therefore, when we speak of a symbol whose value is "unknown", it just means that the symbol is unassigned, i.e. its value is its own name.

Keith Orpen, who is still writing this, would like to hear your comments and suggestions.