# Derivative of the composition of two functions

Background, this seems to work (This is manually transcribed from the program, beware of errors):

J1[f_, i_] := DifferenceDelta[f[i], i]^2
D[J1[f + t v, i], t]

2 (-v[i] + v[i+1]) (-(f + t v)[i] + (f + t v)[i+1])


What I would like to do is replace the ()^2 with a generic function JJ, and later specify

JJ[x_] := ...


Here's what happens with the generic JJ:

J2[f_, i_] := JJ[DifferenceDelta[f[i], i]]
D[J2[f + t v, i],t]

0


Why can't it return a derivative expression in terms of a generic derivative JJ', and how could I modify my code to make it work?

• I get (-v[i] + v[1 + i]) Derivative[JJ][-(f + t v)[i] + (f + t v)[1 + i]], not 0. It may still not be what you want. If you're getting 0, then you might want to quit the kernel and try again. Perhaps v has the value 0. – Michael E2 Jun 7 '14 at 11:58
• I think the issue was caused by a typo in the original post (tv was used instead of t v in D[J2[...]]); and now, with Michael's edit, it is fixed :) – kglr Jun 7 '14 at 13:22

JJ[x_] := x^2

2 (-v[i] + v[1 + i]) (-(f + t v)[i] + (f + t v)[1 + i])