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

# Online Help

###### All Products    Maple    MapleSim

unapply

returns an operator from an expression and arguments

MakeFunction

returns an operator from an expression and arguments

 Calling Sequence MakeFunction(expr, x, y, ..) MakeFunction(expr, x, y, .., options) MakeFunction(expr, l) MakeFunction(expr, l, options) unapply(expr, x, y, ..) unapply(expr, x, y, .., options) unapply(expr, l) unapply(expr, l, options)

Parameters

 expr - expression x, y, .. - variable names, or names with type specifiers l - list of variable names options - list of optional arguments

Options

 The following optional arguments are available.
 • numeric=variables
 For this option variables must be a set or list of variable names, or a single variable name, all of which must correspond to a variable in the input for MakeFunction (that is, in either the list or the specified variable names). With this option, MakeFunction constructs an operator that returns unevaluated whenever the specified variables do not evaluate to numeric values.
 Note: This option cannot be used for inputs containing derivatives, such as $\frac{ⅆ}{ⅆx}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}f\left(x\right)$ or $\mathrm{DEsol}$ structures.
 Providing the optional argument numeric is simply a shortcut for numeric=variables.
 • proc_options=keywords
 This option must be a keyword, or list or set of keywords. The MakeFunction command constructs the operator with the specified keywords as options. By default, the options {operator,arrow} are used, but any of arrow, inline, operator, remember, or system are valid keywords.
 • The MakeFunction command implements the lambda-expressions of lambda calculus.
 • The unapply command is an alias for MakeFunction; the two commands are the same in all respects.

Description

 • The result of MakeFunction(expr, x) is a functional operator. Applying this operator to x gives the original expression.

$\mathrm{MakeFunction}\left(\mathrm{expr},x\right)\left(x\right)\to \mathrm{expr}$

 • In particular, for a function $f\left(x\right)$,

$\mathrm{MakeFunction}\left(f\left(x\right),x\right)\to f$

 • To construct a multi-argument operator from a multi-variate expression, list all the variables as arguments to MakeFunction or explicitly put all variables in a list and pass it as the second argument to MakeFunction.
 • Use the MakeFunction command when constructing an operator using contents of variables or evaluated expressions.
 • The variable names may be simple names of type symbol (e.g., x, y, z), or names with type specifiers using :: (e.g, x::numeric, y::integer, z::float).

Examples

 > $p≔{x}^{2}+\mathrm{sin}\left(x\right)+1$
 ${p}{≔}{{x}}^{{2}}{+}{\mathrm{sin}}{}\left({x}\right){+}{1}$ (1)
 > $f≔\mathrm{MakeFunction}\left(p,x\right)$
 ${f}{≔}{x}{↦}{{x}}^{{2}}{+}{\mathrm{sin}}{}\left({x}\right){+}{1}$ (2)
 > $f\left(\frac{\mathrm{Pi}}{6}\right)$
 $\frac{{{\mathrm{\pi }}}^{{2}}}{{36}}{+}\frac{{3}}{{2}}$ (3)
 > $q≔{x}^{2}+{y}^{3}+1$
 ${q}{≔}{{y}}^{{3}}{+}{{x}}^{{2}}{+}{1}$ (4)
 > $f≔\mathrm{unapply}\left(q,x\right)$
 ${f}{≔}{x}{↦}{{y}}^{{3}}{+}{{x}}^{{2}}{+}{1}$ (5)
 > $f\left(2\right)$
 ${{y}}^{{3}}{+}{5}$ (6)
 > $g≔\mathrm{MakeFunction}\left(q,x,y\right)$
 ${g}{≔}\left({x}{,}{y}\right){↦}{{y}}^{{3}}{+}{{x}}^{{2}}{+}{1}$ (7)
 > $g\left(2,3\right)$
 ${32}$ (8)
 > $h≔\mathrm{MakeFunction}\left(q,\left[x,y\right]\right)$
 ${h}{≔}\left({x}{,}{y}\right){↦}{{y}}^{{3}}{+}{{x}}^{{2}}{+}{1}$ (9)
 > $h\left(2,3\right)$
 ${32}$ (10)

Example of MakeFunction with the numeric option:

 > $\mathrm{f1}≔\mathrm{MakeFunction}\left({x}^{2}+1,x,\mathrm{numeric}\right)$
 ${\mathrm{f1}}{≔}{\mathbf{proc}}\left({x}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{local}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{unnamed}}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{if}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{type}}{}\left({\mathrm{evalf}}{}\left({x}\right){,}{'}{\mathrm{numeric}}{'}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{then}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{x}{^}{2}{+}{1}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{elif}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{procname}}{<>}{'}{\mathrm{unknown}}{'}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{and}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{not}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{member}}{}\left({\mathrm{sprintf}}{}\left({"%a"}{,}{\mathrm{procname}}\right){,}\left\{{"%"}{,}{"%%"}{,}{"%%%"}\right\}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{then}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{'}{\mathrm{procname}}{'}{}\left({x}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{else}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{unnamed}}{≔}{\mathrm{pointto}}{}\left(\left(\left[\begin{array}{r}36893627818826449596\end{array}\right]\right){[}{1}{]}\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{'}{\mathrm{unnamed}}{'}{}\left({x}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end if}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (11)
 > $\mathrm{f1}\left(1\right)$
 ${2}$ (12)
 > $\mathrm{f1}\left(x\right)$
 ${\mathrm{f1}}{}\left({x}\right)$ (13)

This behavior is different from specification of the type with the variable

 > $\mathrm{f2}≔\mathrm{MakeFunction}\left({x}^{2}+1,x::\mathrm{numeric}\right)$
 ${\mathrm{f2}}{≔}{x}{::}{\mathrm{numeric}}{↦}{{x}}^{{2}}{+}{1}$ (14)
 > $\mathrm{f2}\left(1\right)$
 ${2}$ (15)
 > $\mathrm{f2}\left(x\right)$

Example of MakeFunction with specified options:

 > f := proc() lprint(called); 0; end proc;
 ${f}{≔}{\mathbf{proc}}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{lprint}}{}\left({\mathrm{called}}\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{0}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (16)
 > $\mathrm{pol}≔\mathrm{MakeFunction}\left({x}^{2}+3x+1+'f'\left(\right),x,\mathrm{proc_options}=\left\{\mathrm{remember},\mathrm{operator},\mathrm{arrow}\right\}\right)$
 ${\mathrm{pol}}{≔}{x}{↦}{{x}}^{{2}}{+}{3}{\cdot }{x}{+}{1}{+}{f}{}\left(\right)$ (17)
 > $\mathrm{pol}\left(1\right)$
 called
 ${5}$ (18)
 > $\mathrm{pol}\left(2\right)$
 called
 ${11}$ (19)
 > $\mathrm{pol}\left(1\right)$
 ${5}$ (20)

References

 Gonnet, G.H. "An Implementation of Operators for Symbolic Algebra Systems" SYMSAC. July 1986.

Compatibility

 • The MakeFunction command was introduced in Maple 2023.
 • For more information on Maple 2023 changes, see Updates in Maple 2023.

 See Also