Define a Function - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Functional Operators

Description

 • A functional operator in Maple is a special form of a procedure. Functional operators are written using arrow notation.

$\mathrm{vars}\to \mathrm{result}$

 Here, vars is a sequence of variable names (or a single variable) and result is the result of the procedure acting on vars.
 • For example, the following

$x\to {x}^{2}$

 represents the function that squares its argument.
 • Multivariate and vector functions are also allowed. You must put parentheses around vars or result whenever they are expression sequences. For example, the following functions have the correct syntax.

$\left(x,y\right)\to {x}^{2}+{y}^{2}$

$x\to \left(2x,3{x}^{4}\right)$

$\left(x,y,z\right)\to \left(xy,yz\right)$

 • You can also create a functional operator by using the unapply command.  (See unapply.)
 • A functional operator of the form:

$\mathrm{vars}\to \mathrm{result}$

 is semantically equivalent to:

 proc(vars) option operator, arrow; result end

 • The identity operator is expressed as $x\to x$ for any variable name x.
 • Constant operators do not simplify to numbers. For example, $x\to 1$ does not simplify to $1$.
 • Expressions such as $x\to f\left(x\right)$ do not simplify to $f$. This is invalid if $f$ can also take fewer or greater than one argument.
 • Note that optional and keyword parameters (see the paramprocessing help page for more information on these) cannot be used in functional operators. However, type specifiers for parameters are supported.  If a type specifier is used, then the parameters must be enclosed in parentheses, even in the case of a single parameter.

Examples

 > $f≔x→3x+5$
 ${f}{≔}{x}{↦}{3}{\cdot }{x}{+}{5}$ (1)
 > $f\left(2\right)$
 ${11}$ (2)
 > $g≔\left(x,y\right)→\mathrm{sin}\left(x\right)\mathrm{cos}\left(y\right)+xy$
 ${g}{≔}\left({x}{,}{y}\right){↦}{\mathrm{sin}}{}\left({x}\right){\cdot }{\mathrm{cos}}{}\left({y}\right){+}{y}{\cdot }{x}$ (3)
 > $g\left(\frac{\mathrm{Pi}}{2},\mathrm{Pi}\right)$
 ${-}{1}{+}\frac{{{\mathrm{\pi }}}^{{2}}}{{2}}$ (4)
 > $h≔x→\left(2x,{x}^{3}\right)$
 ${h}{≔}{x}{↦}\left({2}{\cdot }{x}{,}{{x}}^{{3}}\right)$ (5)
 > $h\left(3\right)$
 ${6}{,}{27}$ (6)
 > $u≔\left(x::\mathrm{integer},y::\mathrm{integer}\right)→x+y-\mathrm{igcd}\left(x,y\right)$
 ${u}{≔}\left({x}{::}{\mathrm{Typesetting}}{:-}{\mathrm{_Hold}}{}\left(\left[{\mathrm{integer}}\right]\right){,}{y}{::}{\mathrm{Typesetting}}{:-}{\mathrm{_Hold}}{}\left(\left[{\mathrm{integer}}\right]\right)\right){↦}{x}{+}{y}{-}{\mathrm{igcd}}{}\left({x}{,}{y}\right)$ (7)
 > $u\left(\frac{2}{3},4\right)$