Application Center - Maplesoft

App Preview:

Maple Programming: 4.6: Maple functions are procedures

You can switch back to the summary page by clicking here.

Learn about Maple
Download Application


 

4.06.mws

Programming in Maple

Roger Kraft
Department of Mathematics, Computer Science, and Statistics
Purdue University Calumet

roger@calumet.purdue.edu

4.6. Maple functions are procedures

A function in Maple is really like a procedure. Below we define a procedure,  a Maple function, and an expression, each of them equivalent to the mathematical function f(x) = x^2+2*x-1 .

>    f1 := x^2+2*x-1;    # The mathematical function as an expression,

f1 := x^2+2*x-1

>    f2 := x->x^2+2*x-1; # as a Maple function,

f2 := proc (x) options operator, arrow; x^2+2*x-1 end proc

>    f3 := proc(x)       # as a procedure.

>       x^2+2*x-1

>    end;

f3 := proc (x) x^2+2*x-1 end proc

Let us see how Maple remembers the definitions of   f1 ,   f2 , and   f3 .   

>    eval( f1 );   # f1 was defined as an expression.

x^2+2*x-1

>    eval( f2 );   # f2 was defined as a function.

proc (x) options operator, arrow; x^2+2*x-1 end proc

>    eval( f3 );   # f3 was defined as a procedure.

proc (x) x^2+2*x-1 end proc

Check the data types of f1 , f2 , and f3 .

>    whattype( eval(f1) );   # f1 was defined as an expression.

`+`

>    whattype( eval(f2) );   # f2 was defined as a function.

procedure

>    whattype( eval(f3) );   # f3 was defined as a procedure.

procedure

Notice that Maple considers both f2  and f3  to be of type procedure , so Maple treats functions as procedures.

>   

>