Anticommutative rules in Mathematica

50 Views Asked by At

I am trying to create a product with the anticommutative rule in Mathematica using the operation $**$. I set in my rules the following line:

before___ ** a_ ** b_ ** after___ :> If[OrderedQ[{a, b}] == True, before ** a ** b ** after, before ** ((-1)*b) ** a ** after], NonCommutativeMultiply[x_] :> x

This does half the job that I want, since it takes this output:

$$o_{1,2}\text{**}o_{1,3}\text{**}o_{2,3}-o_{1,2}\text{**}o_{2,3}\text{**}o_{1,3}-o_{1,3}\text{**}o_{1,2}\text{**}o_{2,3}+o_{1,3}\text{**}o_{2,3}\text{**}o_{1,2}+o_{2,3}\text{**}o_{1,2}\text{**}o_{1,3}-o_{2,3}\text{**}o_{1,3}\text{**}o_{1,2}$$

To the following: $$2 o_{1,2}\text{**}o_{1,3}\text{**}o_{2,3}-2 o_{1,2}\text{**}o_{2,3}\text{**}o_{1,3}+2 o_{1,3}\text{**}o_{2,3}\text{**}o_{1,2}$$

I ultimately want it to reduce to: $$ 6 o_{1,2}\text{**}o_{1,3}\text{**}o_{2,3}$$