Search code examples
mapleunapply

why do I have to use the unapply operator in maple, when defining a function by diff?


I am an absolute beginner in maple and have problems to understand the following:

The following does not work:

f:=(x)->x^2;
df_wrong:=(x)->diff(f(x),x);

Since df_wrong(1); always yields the following "Error, (in df_wrong) invalid input: diff received 1, which is not valid for its 2nd argument ". After some time I found that the following solves this:

df_correct := unapply(diff(f(x), x), x);

Since df_correct(1);. Could anyone explain me what is the problem the problem in using df_wrong and maybe why unapply() solves these?

I have checked the Maple explanation of unapply(), but it is somehow still not very clear to me.

Thanks in advance!


Solution

  • In your wrong version, your function uses x as a functional operator. When you input 1, df_wrong(1) is parsed as diff(f(1),1), which is nonsense: you cannot differentiate wrt. a constant.

    The nice thing about the unapply functional is that it returns a functional operator. This means you can manipulate things and then use it as an operator. This is in contrast to the operator assign command x -> ... that makes x an operator of the entire right hand side.