3

I am trying to do some quantum algebra computations in Mathematica. Up to now I was able to make the noncommutative multiplication linear and to factorize powers. However, I still have some issues with associativity. In particular, I would like to be able to remove brackets expressions like a ** ( b ** c ) and get a ** b ** c. The reason for that is that I already have a procedure that substitutes a^2 ** b to a ** a ** b, but this doesn't work when I have brackets (a ** ( a ** b )).
Does anyone know how to overcome this problem?

far
  • 31
  • 2

1 Answers1

1

The problem (if I understand correctly) is that you want to make the following replacements:

a * (a * c)  ==> a * a * c   ==> a^2 * c
a * (a ** c) ==> a * a ** c  ==> a^2 ** c

The trick is that in the second line, a * a ** c is parenthesised as a * (a ** c), where a * a is not recognized as a^2. Use the following rule:

rep = (x_*(x_ ** y__) :> x^2 ** y);
a*(a ** c)                 (* ==>   a a ** c)        *)
a*(a ** c ** d) /. rep     (* ==>   a^2 ** c ** d    *)
a*(b ** a) /. rep          (* ==>   a b ** a     NC-ity is maintained    *)
István Zachar
  • 47,032
  • 20
  • 143
  • 291