Next: Expressions: SumsProducts, Up: Introduction Previous: Introduction

Evaluation

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

=-1.00.5plus##1`##1=12=^^M=12 > p := x^2+4*x+4;

2 p := x + 4 x + 4

plusplus -100 plus 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 ?

=-1.00.5plus##1`##1=12=^^M=12 > p; 2 x + 4 x + 4

plusplus -100 plus It is the formula . What is the value of ?

=-1.00.5plus##1`##1=12=^^M=12 > x; x

plusplus -100 plus It is the symbol . Because a variable can be assigned a value which contains symbols, the issue of evaluation arises. Consider

=-1.00.5plus##1`##1=12=^^M=12 > x := 3; x := 3

> p; 25

plusplus -100 plus 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 ?

=-1.00.5plus##1`##1=12=^^M=12 > int(p,x); Error, (in int) wrong number (or type) of arguments

plusplus -100 plus 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

=-1.00.5plus##1`##1=12=^^M=12 > x := 'x'; x := x

> int(p,x); 3 2 1/3 x + 2 x + 4 x

plusplus -100 plus



Next: Expressions: SumsProducts, Up: Introduction Previous: Introduction


Klaus Steinberger
Mi Apr 13 12:51:51 MDT 1994