unapply - Maple Programming Help

Home : Support : Online Help : Programming : Operations : Operators : unapply

unapply

returns an operator from an expression and arguments

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

Parameters

 expr - expression x, y, .. - variable names l - list of variable names options - list of optional arguments

Description

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

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

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

$\mathrm{unapply}\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 unapply or explicitly put all variables in a list and pass it as the second argument to unapply.
 • Use the unapply command when constructing an operator using contents of variables or evaluated expressions.
 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 unapply (that is, in either the list or the specified variable names). With this option, unapply 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}f\left(x\right)$ or $\mathrm{DEsol}$ structures.
 • numeric
 This is simply a shortcut for numeric=variables, which places all the variables in the numeric list.
 • proc_options=keywords
 This option must be a keyword, or list or set of keywords. The unapply 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 unapply command implements the lambda-expressions of lambda calculus.

Examples

 > $p≔{x}^{2}+\mathrm{sin}\left(x\right)+1$
 ${p}{≔}{{x}}^{{2}}{+}{\mathrm{sin}}{}\left({x}\right){+}{1}$ (1)
 > $f≔\mathrm{unapply}\left(p,x\right)$
 ${f}{≔}{x}{→}{{x}}^{{2}}{+}{\mathrm{sin}}{}\left({x}\right){+}{1}$ (2)
 > $f\left(\frac{\mathrm{π}}{6}\right)$
 $\frac{{1}}{{36}}{}{{\mathrm{π}}}^{{2}}{+}\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{unapply}\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{unapply}\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 unapply with the numeric option:

 > $\mathrm{f1}≔\mathrm{unapply}\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({\mathrm{Array\left(1..1, \left\{\left(1\right) = 18446883770874228598\right\}\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{unapply}\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 unapply 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{unapply}\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}{}{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.