# Using rule with derivative

Assuming I have an expression like:

D[a[t, r], r] + D[D[a[t, r], r],r] + D[D[a[t, r], t],r]

I would like to change variables, by expression everything in terms of b = D[a[t,r],r] If I naively set a rule such as,

myrule = D[a[t, r], r] -> b[t,r]

then, this will only correctly substitute it in for the first expression. Obviously, i could create a specific rule for each occurrence, but I was wondering if there was no nice way to make it work in general in a single go.

• If you base the replacement on the FullForm of these terms, it'll be easier. May 10, 2019 at 15:45
• Your expression gets evaluated to Derivative[0, 1][a][t, r] + Derivative[0, 2][a][t, r] + Derivative[1, 1][a][t, r], and the second term doesn't match your pattern. May 10, 2019 at 15:45

You can give Derivative an UpValues for a:

a /: Derivative[n_, 1][a] := Derivative[n, 0][b]


Then:

D[a[t, r], r] + D[D[a[t, r], r],r] + D[D[a[t, r], t],r] //TeXForm


$$b^{(0,1)}(t,r)+b^{(1,0)}(t,r)+b(t,r)$$

Another possibility is:

Clear[a]
D[a[t, r], r] + D[D[a[t, r], r],r] + D[D[a[t, r], t],r] /. a->Derivative[0,-1][b] //TeXForm


$$b^{(0,1)}(t,r)+b^{(1,0)}(t,r)+b(t,r)$$

• Nice. Thank you. May 10, 2019 at 16:06