Bug fix: Problems with unapply

The function unapply , which constructs a procedure from an expression, has two major shortcomings, listed below. To correct them, I have written the alternative procedure vnapply .

• unapply does not work with arrays (including matrices and vectors), Arrays (including Matrices or Vectors) or tables.

> f:=unapply(vector([1,x,x^2]), x);

> f(t);

> F:= unapply(Vector([1,x,x^2]), x);

> F(t);

Here it is with vnapply :

> f:= vnapply(vector([1,x,x^2]), x);

> f(t);

> F:= vnapply(Vector([1,x,x^2]),x);

> F(t);

• When the expression contains derivatives with respect to the variables, we don't want unapply to return a result such as , because that wouldn't work unless x is a name of a variable. What we do want is to take the derivative of g , and then return the function that evaluates this at its argument. This can be expressed using the D operator.

> unapply(diff(g(x),x), x);
unapply(diff(g(x,y),y),y);

Unfortunately, unapply fails to do this in slightly more complicated circumstances.

> unapply(2*diff(g(x),x), x);
unapply(diff(g(x,y),x)+diff(g(x,y),y),(x,y));

Here they are with vnapply :

> vnapply(2*diff(g(x),x), x);
vnapply(diff(g(x,y),x)+diff(g(x,y),y),(x,y));

Maple Advisor Database, R. Israel 2000