I'm trying to write a Mathematica program to find derivatives such as the following simple example:enter image description here

Could you please help?


For instance:

varD[f1_ f2_, x_] := varD[f1, x] f2 + f1 varD[f2, x];
varD[f1_ + f2_, x_] := varD[f1, x] + varD[f2, x];
varD[c_?NumericQ, x_] := 0;
varD[delta[a_, b_], x_] := 0;
varD[S[a_, b_], S[c_, d_]] := delta[a, c] delta[b, d]

Now you can do

In[]:= varD[7 S[a, b] S[c, d], S[e, f]]
Out[]= 7 (delta[c, e] delta[d, f] S[a, b] + delta[a, e] delta[b, f] S[c, d])


In[]:= varD[%, S[g, h]] // Expand
Out[]= 7 delta[a, g] delta[b, h] delta[c, e] delta[d, f] + 7 delta[a, e] delta[b, f] delta[c, g] delta[d, h]

Not the answer you're looking for? Browse other questions tagged or ask your own question.