Problem with defining such derivatives is that Dt
doesn't hold its arguments, so if f
and g
have some definitions
ClearAll[f, g]
f[a_, b_] := a^2 + b
g[a_, b_] := a + b
then they are evaluated when passed to Dt
, so "standard trick" with defining UpValues
like:
f /: Dt[HoldPattern@f[a_, b_], HoldPattern@g[a_, b_]] := r1[a, b]
will not work.
What you can do is to use an "environment", in which this derivative will have desired value.
ClearAll[f, g]
f[a_, b_] := a^2 + b
g[a_, b_] := a + b
ClearAll[withMyDerivative]
SetAttributes[withMyDerivative, HoldFirst]
withMyDerivative[expr_] :=
Block[{g},
g /: Dt[f[a_, b_], g[a_, b_]] := r1[a, b];
expr
]
Now, inside withMyDerivative
environment, Dt[f[a_, b_], g[a_, b_]]
will evaluate to r1[a, b]
.
g[a, b] (f[a, b] + Dt[f[a, b], g[a, b]]) // withMyDerivative
(* (a + b) (a^2 + b + r1[a, b]) *)