# Defining arbitary Derivatives of functions

If I have two functions like these f[a_,b_] and g[a_,b_]. Lets say

f[a_,b_]:= a^2 + b
g[a_,b_]:= a + b


some times I encounter Dt[f[a,b] , g[a,b]] and I want to have a defined value for this derivative, like Dt[f[a,b] , g[a,b]]-> R1 How can I define new derivative for this problem in Mathematica?

I mean whenever I differentiate f with respect g I get R1.

• I think in order to know the correct way to do this, we need more context about your problem (and the previous question you asked doesn't contain enough context). Nov 24, 2015 at 23:45
• I tried to make it more clear Nov 24, 2015 at 23:52

protected = Unprotect[Dt]


{"Dt"}

Dt[f[___], g[___]] := R1

Dt[f[a, b], g[]]


R1

Clear@Dt

Dt[f[], g[]]


0

Remember

If your definition is no longer needed Clear it - otherwise you might get unwanted results in other areas. And restore protection:

Protect[Evaluate[protected]]


{"Dt"}

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]) *)