Previous Up Next

8.2.2  Transforming an expression into a function

The unapply command transforms an expression into a function.

Examples

unapply(exp(x+2),x)
     
x↦ ex+2           
unapply(x*y-x-y,(x,y))
     

x,y
↦ x yxy
          
Remark.

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:

g:=sin(x+1); f:=unapply(g,x)
     
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

f:=unapply(lagrange([1,2,3],[4,8,12]),x)

(See Section 17.1.1.)

     
x↦ 4 
x−1
+4
          
f:=unapply(integrate(log(t),t,1,x),x)
     
x↦ x lnxx+1           
f:=unapply(integrate(log(t),t,1,x),x):; f(x)
     
x lnxx+1           
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

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

Previous Up Next