functions - Maple Help

Functions

 Calling Sequence expr(expseq)

Description

 • This help page describes the Maple function expression. A "function" expression represents a function call, or application of a function or procedure to arguments. For a list of mathematical functions defined in Maple, see initial functions.  A mathematical function can be defined in Maple using a functional operator.  Use these to define a function of a single variable, a multivariate function, or a vector function.
 • In Maple, a "function" expression represents a function call, or application of a function or procedure to arguments. Such an expression is said to be of type function. A "typical" example of an expression of type function is the expression $f\left(x\right)$, which represents the application of the expression $f$ to the argument sequence $x$. Note that, in this expression, we refer to the entire expression $f\left(x\right)$ as being of type function (that is, a "function call" or "function application"), while the expression $f$ is typically not itself of type function (but often is of type procedure).
 • The operands of a function expression are the "arguments". For example, the operands of the expression $f\left(a,b,c\right)$ are $a$, $b$ and $c$. The expression $f$ may be extracted from this expression as the zero-th operand. See the examples section below for more about this.
 • In an expression $f\left(a,b,c,...\right)$ of type function, the applied expression $f$ is often a Maple procedure, or a name that evaluates to a procedure. In this case, evaluating the expression causes the procedure $f$ (or to which $f$ evaluates) to be applied to the arguments $a,b,c,\dots$ (see Argument Processing), and the result of evaluating the expression is the value returned by the procedure. However, the expression $f$ need not be a procedure, or even evaluate to one.
 • In fact, expr can be a complicated expression, such as a list, set, polynomial, or even an expression sequence.
 • Apart from procedure applications, one of the most useful applications of function expressions is the ability to use them to define abstract data types. This application makes use of Maple's ability to manipulate unevaluated function calls easily and naturally.
 • Function expressions may be created using the constructor apply.
 • Assignments to unevaluated function calls can create procedures. When you assign a value to the function expression $f\left(x\right)$, in which $f$ is an unassigned name, a procedure is created and assigned to $f$ which returns unevaluated for all argument sequences other than $x$ and returns the value assigned when passed the argument $x$. The value of the expression $f\left(x\right)$ is stored in the remember table of the newly created procedure. Subsequent assignments to unevaluated calls to $f$ further populate this remember table.
 • In the case when $f$ is a numeric constant, there are some differences in how $f\left(x\right)$ is parsed in 1-D and 2-D input modes.  For example, in 1-D input 2(x) is a function application, but in 2-D by default this means multiplication.  For more information, including how to change this default behavior, see 2DMathDetails.
 If, in this case, an expression such as 2(x) is a function application, it represents the constant function 2 (the function that is 2 everywhere). The result of evaluating it is the number 2.

Examples

Two ways to apply sin to $\mathrm{\pi }$:

 > $\mathrm{sin}\left(\mathrm{Pi}\right)$
 ${0}$ (1)
 > $\mathrm{apply}\left(\mathrm{sin},\mathrm{Pi}\right)$
 ${0}$ (2)

The next command, entered two ways, returns unevaluated.

 > $\mathrm{sin}\left(x\right)$
 ${\mathrm{sin}}{}\left({x}\right)$ (3)
 > $\mathrm{apply}\left(\mathrm{sin},x\right)$
 ${\mathrm{sin}}{}\left({x}\right)$ (4)
 > $\mathrm{type}\left(\mathrm{sin}\left(x\right),'\mathrm{function}'\right)$
 ${\mathrm{true}}$ (5)
 > $\mathrm{type}\left(\mathrm{sin}\left(x\right),'\mathrm{procedure}'\right)$
 ${\mathrm{false}}$ (6)
 > $\mathrm{type}\left(\mathrm{sin},'\mathrm{function}'\right)$
 ${\mathrm{false}}$ (7)
 > $\mathrm{type}\left(\mathrm{sin},'\mathrm{procedure}'\right)$
 ${\mathrm{true}}$ (8)
 > type( 'proc(x) 1+x; end( 2 )', 'function' );
 ${\mathrm{true}}$ (9)
 > $\mathrm{type}\left('\left(x→{x}^{2}\right)\left(a\right)','\mathrm{function}'\right)$
 ${\mathrm{true}}$ (10)
 > $\left(\mathrm{sin},\mathrm{cos}\right)\left(x\right)$
 ${\mathrm{sin}}{}\left({x}\right){,}{\mathrm{cos}}{}\left({x}\right)$ (11)
 > $\mathrm{type}\left(\left[\mathrm{sin},\mathrm{cos}\right]\left(x\right),'\mathrm{function}'\right)$
 ${\mathrm{false}}$ (12)
 > $\mathrm{type}\left(\left[\mathrm{sin},\mathrm{cos}\right]\left(x\right),'\mathrm{list}'\left('\mathrm{function}'\right)\right)$
 ${\mathrm{true}}$ (13)
 > $\mathrm{type}\left('\left[\mathrm{sin},\mathrm{cos}\right]\left(x\right)','\mathrm{function}'\right)$
 ${\mathrm{true}}$ (14)
 > $\mathrm{pointto}\left(\mathrm{assemble}\left(\mathrm{kernelopts}\left(\mathrm{dagtag}=\mathrm{STOP}\right)\right)\right)\left(s\right)$
 ${\mathbf{stop}}{}\left({s}\right)$ (15)
 > $\mathrm{type}\left(\mathrm{pointto}\left(\mathrm{assemble}\left(\mathrm{kernelopts}\left(\mathrm{dagtag}=\mathrm{STOP}\right)\right)\right)\left(s\right),'\mathrm{function}'\right)$
 ${\mathrm{true}}$ (16)
 > $\mathrm{interface}\left('\mathrm{verboseproc}'=3\right):$
 > $\mathrm{unassign}\left('f'\right):$
 > $\mathrm{eval}\left(f\right)$
 ${f}$ (17)

Assign to this function expression.

 > $f\left(2\right)≔3$
 ${f}{}\left({2}\right){≔}{3}$ (18)

Now $f$ is assigned a procedure with a remember table.

 > $\mathrm{eval}\left(f\right)$
 ${\mathbf{proc}}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{option}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{remember}}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{'}{\mathrm{procname}}{}\left({\mathrm{args}}\right){'}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}{\text{#(2) = 3}}$ (19)

Add more entries to the remember table.

 > $f\left(3\right)≔1:$$f\left(1\right)≔2:$
 > $\mathrm{eval}\left(f\right)$
 ${\mathbf{proc}}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{option}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{remember}}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{'}{\mathrm{procname}}{}\left({\mathrm{args}}\right){'}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}{\text{#(1) = 2}}{\text{#(2) = 3}}{\text{#(3) = 1}}$ (20)