1
$\begingroup$

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.

$\endgroup$
2
  • 1
    $\begingroup$ If you base the replacement on the FullForm of these terms, it'll be easier. $\endgroup$
    – Roman
    May 10, 2019 at 15:45
  • $\begingroup$ 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. $\endgroup$
    – rhermans
    May 10, 2019 at 15:45

1 Answer 1

3
$\begingroup$

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)$

$\endgroup$
1
  • $\begingroup$ Nice. Thank you. $\endgroup$
    – Patrick.B
    May 10, 2019 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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