Previous Up Next

6.15.2  Transforming an expression into a function: unapply

The unapply command transforms an expression into a function.


Examples.


Warning.
When a function being is defined, the right side of the assignment is not evaluated, hence g:=sin(x+1); f(x):=g does not define the function f: x → sin(x+1) but defines the function f: xg. To define the former function, unapply should be used, as in the following example:
Example.
Input:

g:= sin(x+1); f:=unapply(g,x)

Output:

sin
x+1
,x↦ sin
x+1

hence, the variable g is assigned to a symbolic expression and the variable f is assigned to a function.


Examples.


Remark.
Suppose that f is a function of 2 variables f:(x,w)→ f(x,w), and that g is the function defined by g: whw, where hw is the function defined by hw(x)=f(x,w).
unapply can also be used to define g.


Example.
Input:

f(x,w):=2*x+w:;
g(w):=unapply(f(x,w),x):;
g(3)

Output:

x↦ 2 x+3

Previous Up Next