I want to transform total derivatives into normal derivatives:

Dt[r, t] == -r*Dt[v, x] - v*Dt[r, x] /. Dt[f_, s_] :> D[f[x, t], s]

To get:

D[r[x, t], t] == -r*D[v[x, t], x] - v*D[r[x, t], x]

But the replacement rule above doesn't seem to match Dt.

Only the explicit rule, Dt[v, x] /. Dt[v, x] :> D[v[x], x] works, but Dt[v, x] /. Dt[f_, t_] :> D[f[t], t] yields Dt[v, x], not D[v[x],x].

Of course, the work-around is just to start with normal derivatives, but I was trying to get a nicely formatted version of the Euler equations which I could then use for further operations like NDSolve, and Dt made it much more readable than having explicit functions of x and t for rho, v, and e:

 {u = \[Rho] {1, v, e}, 
  p = (\[Gamma] - 1) \[Rho] (e - 1/2 v^2) /. \[Gamma] -> 3/2,
  F, eqn, deqn,
  dwdt = Dt[{\[Rho], v, e}, t]},
 F = {\[Rho] v, \[Rho] v^2 + p, v (\[Rho] e + p)};
\*SubscriptBox[\(\[PartialD]\), \(t\)]u\)+\!\(
\*SubscriptBox[\(\[PartialD]\), \(x\)]F\)==0*)
 eqn = Thread[Dt[u, t] + Dt[F, x] == 0];
 deqn = Thread[dwdt == (dwdt /. First@Solve[eqn, dwdt])];
 TableForm[deqn /. {Dt[f_, s_] :> \!\(
\*SubscriptBox[\(\[PartialD]\), \(s\)]\(f[x, t]\)\)}]

I've encountered this issue many times when doing mechanics problems. Even something as simple as the equation of motion for a double pendulum is difficult to parse because of all the explicit functions.

I've considered doing the reverse:

expressionWithD /. Derivative[ijk__][f_][x_, t_] :> Dt[f,???]

1 Answer 1


RuleDelayed (:>) doesn't hold its first argument (it only has the attribute HoldRest), so your rule will evaluate to:

Dt[f_, s_] :> D[f[x, t], s]
(* Dt[f, s_] Derivative[1, 0][Pattern][f, _] :> D[f[x, t], s] *)

This is clearly undesired.

To resolve the problem, use HoldPattern to stop the automatic evaluation of Dt[f_, s_]:

Dt[r, t] == -r Dt[v, x] - v Dt[r, x] /. HoldPattern@Dt[f_, s_] :> D[f[x, t], s]
(* Derivative[0, 1][r][x, t] == 
   -v Derivative[1, 0][r][x, t] - r Derivative[1, 0][v][x, t] *)

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.