Programming Functions
The following are the built-in functions and operators especially useful for writing and debugging Derive programs:
Use the MAP and MAP_LIST functions to map functions over the elements of vectors and sets. If u is an expression involving the variable x and c is a set or a vector, MAP_LIST(u, x, c) evaluates u(x) for x equal to each element of c and returns the results as a set or vector (depending on the type of c). MAP_LIST(u,k,m,n,s) evaluates u(k) for k=m to n in steps of size s. s defaults to 1. The function MAP evaluates u identical to MAP_LIST, but it just returns the truth-value "true".
Use the ASSIGN function to assign values to variables generated by programs. The := assignment operator (see the Author > Variable Value command2SGW02B) and the ASSIGN function are both used to assign values to variables. The left operand of the := assignment operator must be a variable, since it is not simplified. Whereas, the first argument of the ASSIGN function can be any expression, so long as it simplifies to a variable. Therefore, use ASSIGN when it is necessary to generate a variable and then assign it a value. For example, simplifying the expression
ASSIGN(APPEND("a", 1), 25)
generates the string variable "a1" and assigns it the value 25.
Use the following variable update operators to make user-defined functions more efficient and easier to read:
• x :+ u increments the variable x by the value of the expression u.
• x :- u decrements the variable x by the value of the expression u.
• x :* u multiplies the variable x by the value of the expression u.
• x :/ u divides the variable x by the value of the expression u.
For example, the statement x :+ 1 is faster than the equivalent statement x := x+1. Similarly, the statement x :* 2 is faster than the equivalent statement x := 2·x.
Use the WRITE function in user-defined functions to show intermediate results of a transient nature. WRITE(u) format the expression u as a single line of text, and displays the result on the Algebra window status line. Any expression previously displayed on the status line is over-written. WRITE is useful for displaying counters in program loops to help determine where programming errors have occurred.
Use the DISPLAY function in user-defined functions to display intermediate results in a text box. DISPLAY(u,n) creates a new text box containing the expression u formatted in 2 dimensions using up to n lines of text. n defaults to 1. DISPLAY makes it possible for user-defined functions to show the steps involved in a calculation.
Other Programming in DERIVEProgramming
Created with the Personal Edition of HelpNDoc: Full-featured EPub generator