If you just use the rules for simplicity (and I assume you mean that you are using Replace[] ), then there may be problems if the template you want to replace is present, but not in the correct form. For example, your example is Replace[q2*q1^2*p2,q2*p2->(p2*q2+q2*p2)/2] , which will do nothing in this case (note that the entry q2*p2*q1^2 will not help either because Mathematica sorts all the input data before starting the evaluation.
In the past, I came across similar simplification problems with Mathematica, and there are two strategies that have given reasonable success. Sorry, I canβt give you a specific solution, I hope this helps you figure it out.
Solution 1: you should write your own function ReplaceUnordered[form,rule] , which parses all the various form orders for possible rule applications. This can be done using Permutations[] and using HoldForm[] .
Solution 2. Use Simplify[] . In particular, use ComplexityFunction to make asymmetric expressions more "expensive", and the TransformationFunctions option to specify your own simplification rules.
Here (pdf) is a short (ish) introduction to Mathematica, and it builds and evaluates the process.
Extra Bonus Solution: Use FORM , which is a language written specifically to solve the problem you have.
EDIT: An additional bonus (possibly very simple) Solution: Because rcollier indicated that SymmetricReduction[] can do what you want very easily.
And one more thing for the road: when I had to do calculations with non-commutative variables, I used this package, which contains algebra and calculus for Grassmann variables.
source share