On 12/11/20 7:39 PM, Benedict wrote:
> divergence-free, i.e. replacing
>
> c1DFRule = MakeRule[{-Derivative[0, 1, 0, 0][C11][t[], x[], y[], z[]],
> Derivative[0, 0, 1, 0][C12][t[], x[], y[], z[]] + Derivative[0, 0, 0,
> 1][C13][t[], x[], y[], z[]]}];
>
> by one rule? Or is there another way of accomplishing this, such that it also
> works when other derivatives are taken on top of such a combination of terms?
c1DFRule = Derivative[n0_, n1_?Positive, n2_, n3_][C11][vars___] :> (
- Derivative[n0, n1-1, n2+1, n3][C12][vars]
- Derivative[n0, n1-1, n2, n3+1][C13][vars])
should do the trick, I think (of course you need the same for C21,C22,C23 and
for C31,C32,C33; it can also be generalized to any dimension, but that gets
super ugly).
Probably for your use case the above is enough and is the right approach. More
generally it might be nice to have a general tool for this. Something like the
following (not tested much)
(**************)
HoldPattern[MyMakeRules[Derivative[k___][f_][vars___], replacement_]] :=
{
Derivative[k][f][vars] :> replacement,
Derivative[n___][f][vars] :>
With[{l = {n} - {k}},
D @@ Join[{replacement}, Transpose[{{vars}, l}]] /;
AllTrue[l, # >= 0 &]]
};
MyMakeRules[f_[vars___], replacement_] :=
{
f[vars] :> replacement,
Derivative[n___][f][vars] :>
D @@ Join[{replacement}, Transpose[{{vars}, {n}}]]
};
(**************)
(* Then get the various rules for traceless divergence-free:*)
(**************)
txyz=Sequence[t[],x[],y[],z[]];
cTFRules = MyMakeRules[C11[txyz], -C22[txyz] - C33[txyz]]
c1DFRules = MyMakeRules[D[C11[txyz],x[]], -D[C12[txyz],y[]]-D[C13[txyz],z[]]]
c2DFRules = MyMakeRules[D[C21[txyz],x[]], -D[C22[txyz],y[]]-D[C23[txyz],z[]]]
c3DFRules = MyMakeRules[D[C31[txyz],x[]], -D[C32[txyz],y[]]-D[C33[txyz],z[]]]
(**************)
Bruno