t> ASSIGNMENTS AND EQUATIONS
b>
t> This section explains the difference between the assignment operator,
t> := (the colon character followed by the equals sign), and the equation
t> operator, =. It is very important to understand the distinction between
t> the two.
b>
c1>
t> Assignments
b>
t> We have previously learned how to create expressions, special data
t> types, and Maple command calls; but these objects are very transitory
t> until we actually assign their values to some holder or variable. For
t> example, if we create a list containing the first 10 prime numbers in
t> order and *do not* assign this to a variable name, then each time we
t> wish to use that structure within a Maple command or a large data
t> structure, we have to recreate it from scratch. If instead, we assign
t> the list (with the := operator) to a variable name, say first10primes,
t> then we can easily use it in other calculations or as input to other
t> Maple commands.
b>
x> first10primes := [ithprime(i)$i=1..10];
h> i := 'i';
x> product(first10primes[i], i=1..10);
h> i := 'i';
b>
c1>
t> Bear in mind that when you make an assignment, the expression to the
t> right of the := is first evaluated, and then the name on the left of
t> the := is assigned to that value until you tell Maple differently.
t> Maple only remembers the most recently assigned value for any variable.
t> If you assign the variable x to 5 and then later assign it to 7.5,
t> only the latter assignment is remembered.
b>
t> As well, you must use caution when choosing names for assigned
t> variables. If you redefine a Maple command name through an assignment, 
t> the standard meaning of that command is temporarily lost and that 
t> can cause many unpredictable errors within a session. To keep you from 
t> making such a mistake, certain names, including all standard library 
t> command names, are automatically protected. If you try to assign to 
t> one of these names, you are warned and the assignment is not made. 
b>
c1> 
t> The protect command is also supplied in case you want to protect names 
t> that you have created. As well, the unprotect command will remove the 
t> protection from any name defined by either you or the system. Use 
t> extreme caution when using unprotect!
b>
t> Question
b>
c2> 
q> Using the previously defined variable, first10primes, and the sum command,
q> find the sum of the first ten prime numbers and assign it to the name
q> sum10primes.
a> sum10primes := sum(first10primes[i], i=1..10);
eoq>
b>
c1>
b>
t> Equations
b>
t> The most important thing to realize about equations is that they are
t> not the same as assignments. Equations are simply mathematical
t> expressions that show relationships between certain variables and
t> values; they do not infer any explicit values on the variables they
t> contain. For example:
b>
x> x = y + 3;
x> x;
x> y;
t> As you can see, the variables x and y are still unassigned.
b>
c1>
t> The = operator is most frequently seen either in input to a Maple
t> command or in output from a Maple command. One common family of
t> commands that uses the = operator is the *solve* family. These
t> commands take equations of various forms and try to find a solution 
t> or solutions for a given set of variables.
b>
t> solve takes a normal set of linear or nonlinear equations and tries
t> to find a closed-form solution. fsolve takes a similar set of
t> equations and finds a numerical approximation for the answer. dsolve
t> solves a set of ordinary differential equations. rsolve solves a set
t> of recurrence equations. Following is a simple example of the solve
t> command.
b>
x> sols := solve({x+y=3,x-y=1}, {x,y});
c1>
t> As you can see, the solution that you get is a set of equations for the
t> specified variables. If there are multiple solutions, they are all
t> presented. Be aware that x and y in the above example have *not* been
t> assigned to the values 2 and 1, respectively. If you wish to make
t> such an assignment, use the assign command, which takes an equation (or
t> set of equations) and changes each = operator to a := operator.
b>
x> assign(sols);
x> x;
x> y;
h> x:='x';
h> y:='y';
c1>
t> Another common use of the equation operator is in boolean (true or
t> false) situations. When you want to make a decision how to proceed
t> dependant on the relationship between the values of two variables, the
t> = operator can be used to test for equality. Other such operators
t> include: <, <=, <>, and, or, not. The Maple command evalb evaluates a
t> boolean statement. Some examples follow.
b>
x> evalb(3! = 4!/2^2);
x> evalb(157/50 > 22/7);
x> evalb(isprime(5) and isprime(541));
t> Questions
b>
c2>
q> Using the = operator and the fsolve command, find numerical solutions for
q> x and y given that x+y=Pi and x-y=exp(1).
a> fsolve({x+y=Pi,x-y=exp(1)}, {x,y});
b>
c2>
q> Using the evalb command, the numtheory[issqrfree] command, and the *or*
q> operator, test whether either 2345 or 3456 is free of perfect squares.
a> evalb(numtheory[issqrfree](2345) or numtheory[issqrfree](3456));
eoq>
eof>
