You can avoid the need for quotes if you ensure that

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ; convert( S, list ); [1, 2, 5] The convert command can perform many other structural and mathematical conversions. For more information, refer to the ?convert help page. 202 • Chapter 6: Evaluation and Simplification 6.4 Evaluation Rules In a symbolic mathematics program such as Maple you encounter the issue of evaluation . If you assign the value y to x, the value z to y, and the value 5 to z, then to what should x evaluate? Levels of Evaluation Maple, in most cases, does full evaluation of names. That is, when you use a name or symbol, Maple checks if the name or symbol has an assigned value. If it has a value, Maple substitutes the value for the name. If this value itself has an assigned value, Maple performs a substitution again, and so on, recursively, until no more substitutions are possible. > x := y; x := y > y := z; y := z > z := 5; z := 5 Maple evaluates x fully. That is, Maple substitutes y for x, z for y, and then 5 for z. > x; 5 You can use the eval command to control the level of evaluation of an expression. If you call eval with one argument, then eval evaluates that argument fully. > eval(x); 5 A second argument to eval specifies how far you want to evaluate the first argument. 6.4 Evaluation Rules > eval(x, 1); • 203 y > eval(x, 2); z > eval(x, 3); 5 The main exceptions to the rule of full evaluation are special data structures like tables, matrices, and procedures, and the behavior of local variables inside a procedure. Last-Name Evaluation The data structures array, table, matrix, and proc have a special evaluation behavior called last-name evaluation . > x := y; x := y > y := z; y := z > z := array( [ [1,2], [3,4] ] ); z := 12 34 Maple substitutes y for x and z for y. Because evaluation of the last name, z, produces an array, one of the four special structures, z is unevaluated. > x; z 204 • Chapter 6: Evaluation and Simplification Maple uses last-name evaluation for arrays, tables, matrices, and procedures to retain compact representations of unassigned table entries (for example, T[3]) and unevaluated commands (for example, sin(x)). For more information on last-name evaluation, refer to the ?last_name_eval help page. You can force full evaluation by calling eval explicitly. > eval(x); 12 34 > add2 := proc(x,y) x+y; end proc; add2 := proc(x, y ) x + y end proc > add2; add2 You can force full evaluation by using eval or print. > eval(add2); proc(x, y ) x + y end proc Note that full evaluation of Maple library procedures, by default, suppresses the code in the procedure. To illustrate this, examine the erfi command. > erfi; erfi > eval(erfi); proc(x::algebraic ) . . . end proc Set the interface variable verboseproc to 2, and then try again. > interface( verboseproc=2 ); > eval(erfi); 6.4 Evaluation Rules • 205 proc(x::algebraic ) optionsystem , ‘Copyright (c ) 1996 Waterloo Maple \ Inc . All rights reserved .‘; try return _Remember(’procname’(args)) catch : end try; if nargs = 1 then error ...
View Full Document

This note was uploaded on 08/27/2012 for the course MATH 1100 taught by Professor Nil during the Spring '12 term at National University of Singapore.

Ask a homework question - tutors are online