       • To: mathgroup at smc.vnet.net
• Subject: [mg51397] Re: [mg51384] Question about derivatives
• From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
• Date: Sat, 16 Oct 2004 04:20:29 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```On 15 Oct 2004, at 15:48, Ben Whale wrote:

> Hi,
>    I want to treat a function abstractly, I know that it is a function
> of n
> variables. I wish to take its derivative after addition or
> multiplication
> with another function. However Derivative does not return what I
> expect.
> Derivative[0,1][f+g] gives (f+g)^(0,1)  instead of f^(0,1)+g^(0,1) and
> Derivative[0,1][fg] gives (fg)^(0,1) instead of f^(0,1)g+g^(0,1)f.
> Now
> perhaps I'm going about my problem in the wrong way, if I am please
> tell me.
>
> I also have some other questions about Derivative,
> Derivative[0,1][Composition[f,g]] gives f^(0,1)(g)g^(0,1), the correct
> result, why does Derivative know the chain rule and not the product
> rule?
>
> Also, in order to get the correct behaviour for Derivative[0,1][f+g],
> I can
> use the Map function, that is Map[Derivative[0,1],f+g] returns f^(0,1)
> +g^(0,1).  Which is fine except that if I have  the function 1+f and
> apply
> the same command to it I get 0& + f^(0,1),   instead of f^(0,1).
> Clearly
> this is because of the presence of the command Function, however I
> have
> been unable to find a function that fixes this problem.
>
> In essence I want to do vector operations of the ring of functions,
> but find
> that doing this in Mathematica is hard.  How can I do this easily?
> Surely
> someone else has figured out a convenient way of do this.
>
> Thanks,
> Ben
>
>
>
recently). The answer I am posting I have also already posted several
times.
For reasons which I do not want to argue about again Mathematica does
not implement the algebra of functions. that is, if f and g are
functions, whether  defined using patterns as in f[x_]:=  or as pure
functions using Function,  f+g, f*g etc. are not is not treated by
Mathematica as functions. If you wan to change this  you can always do
so:

Unprotect[Times, Plus, Power];
(a_?NumericQ*f_.)[x__] := a f[x];
(f_ + g_)[x__] := f[x] + g[x];
(f_*g_)[x__] := f[x]*g[x];
(f_^n_?NumericQ)[x__] := f[x]^n
Protect[Times, Plus, Power];

Now you will get:

Derivative[0, 1][f + g]

Derivative[0, 1][f][#1, #2] +
Derivative[0, 1][g][#1, #2] &

Derivative[0, 1][f*g]

g[#1, #2]*Derivative[0, 1][f][#1,
#2] + f[#1, #2]*
Derivative[0, 1][g][#1, #2] &

You have to be aware however that in general it is not a good idea to
modify basic functions such as Times, Plus, Power. They are used by
practically every other Mathematica function and you can never tell if
having  additional rules or modifications like those above will not
produce unexpected and unintended behaviour.

Andrzej Kozlowski

Chiba, Japan
http://www.akikoz.net/~andrzej/
http://www.mimuw.edu.pl/~akoz/

```

• Prev by Date: Re: PDE Notation options (one works the other does not)
• Next by Date: Re: Re: Sorting a list of pairs on the second elements