I have some rules for differentiation:

myD[-a_, o_] := -myD[a, o];
myD[a_, -o_] := -myD[a, o];
myD[a_ + n_, o_] := myD[a, o] + myD[n, o];
myD[a_ b_, o_] := b myD[a, o] + a myD[b, o];
myD[myD[a_, b__], c__] := myD[a, b, c]
Format[HoldPattern@myD[a_, b__]] := TraditionalForm@HoldForm@D[a, b]
$Assumptions = 
 x \[Element] Matrices[{2*M, 2*M}, Reals, Antisymmetric[{1, 2}]]
x[arg__] /; ! OrderedQ@{arg} := Signature@{arg} x @@ Sort@{arg} 
Format[x[arg__]] := Subscript[x, arg]

What to do to create a new rule that defines, $$\frac{\partial ^2Q}{\partial x_{1,2}\, \partial x_{3,4}}=\frac{\partial ^2Q}{\partial x_{3,4}\, \partial x_{1,2}}$$

myD[myD[Q, x[1, 2]], x[3, 4]] 

is how to write code to get $\frac{\partial ^2Q}{\partial x_{1,2}\, \partial x_{3,4}}$


1 Answer 1


You can do something like this:

myD[a_, o__] /; ! OrderedQ@{o} := myD[a, Sequence @@ Sort@{o}]

myD[myD[Q, x[1, 2]], x[3, 4]] 

enter image description here

This will ensure that the coordinates after which the expression is differentiated are always sorted. You can define another order instead of Sort{o}, but the key is that all equivalent forms are converted into a single canonical version:

myD[myD[Q, x[1, 2]], x[3, 4]] == myD[myD[Q, x[3, 4]], x[1, 2]] 
(* True *)

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.