Before I begin, I want to point out the most important difference between Maple and traditional programming languages. If an identifier has not been assigned a value, then it stands for itself. It is a symbol. Symbols are used to represent unknowns in equations, variables in polynomials, summation indices, etc. Consider the Maple assignment statement
> p := x^2+4*x+4; 2 p := x + 4 x + 4
Here the identifier has been assigned the formula
.
The identifier
has not been assigned a value, it is just a symbol,
an unknown. The identifier
has been assigned a value. It is now
like a programming variable, and its value can be used in subsequent
calculations just like a normal programming variable.
What is the value of
?
> p; 2 x + 4 x + 4
It is the formula . What is the value of
?
> x; x
It is the symbol .
Because a variable can be assigned a value which contains symbols,
the issue of evaluation arises. Consider
> x := 3; x := 3 > p; 25
Here we assigned the value 3 and asked Maple to print
out the value of
. What should Maple print out? Should it print out
the polynomial
or should it evaluate the polynomial,
i.e. compute
and return the result 25?
We see that Maple does the latter.
This issue of evaluation will come up from time to time as it may
affect the efficiency and semantics of a program.
This difference between Maple and traditional programming languages,
where identifiers can be used for both programming variables and mathematical
unknowns is nice. But be careful not to mix the two.
Many problems that users encounter have to do with using identifiers
for both symbols and programming variables.
For example, what happens if we now try to compute
?
> int(p,x); Error, (in int) invalid arguments
An error has occurred in the integration function int.
Here we are thinking of as a symbol, the integration variable.
But
was previously assigned the integer
.
Maple evaluates the arguments to the int function
and tries to integrate 25 with respect to 3.
It doesn't make sense to integrate with respect to 3!
How does one convert
back into a symbol?
In Maple one unassigns the variable
by doing
> x := 'x'; x := x > int(p,x); 3 2 1/3 x + 2 x + 4 x