# Simplify an expression containing NonCommutativeMultiply

How does mathematica evaluate the following expression to zero:

-a ** (b ** c - c ** b) + b ** (a ** c - c ** a) -
c ** (a ** b - b ** a) + (a ** b - b ** a) **
c - (a ** c - c ** a) ** b + (b ** c - c ** b) ** a

In the reference of the non commutative multiplication ** is stated that it is assumed to be associative and consequently the expression should be equal to zero. However just applying Simplify[] doesn't work for me.

-
The problem seems to be that Mathematica doesn't consider ** to be distributive: a**(b+c)-a**b-a**c doesn't evaluate to 0, not even with FullSimplify. – celtschk May 12 '12 at 12:14
Ok. But if this is true, it should be considered as a bug, because in the context of rings the term 'multiplication' referees to something that is distributive and since '-' and '+' are there, too, we should think at least in terms of rings here. – Mark Neuhaus May 12 '12 at 12:17
@Mark This is not a bug. The system simply doesn't have many operations built-in for non-commutative operators. Simplify/Expand/etc. assume complex numbers, not general operators. – Szabolcs May 12 '12 at 13:07
Have you looked at the NCAlgebra package that has been suggested in your last question? It looks like something exactly for this. – Szabolcs May 12 '12 at 13:08
Ok I wasn't aware of the restrictions of Simplify ect. but on a first look I think the recommended package is what I need. – Mark Neuhaus May 12 '12 at 13:27

## 1 Answer

What you need here is actually expanding the expression (i.e. transforming all (a+b) ** c type expressions to a**c + b**c). There's no built-in support for this kind of manipulation of non-commutative expressions. You'd need to implement them yourself, which can be quite a bit of work.

However, instead of bothering with implementing all these simple operations yourself, I recommend using a dedicated package. @gpap suggested the NCAlgebra package in an answer to your previous question.

After installing NCAlgebra by placing the NC directory in my \$UserBaseDirectory/Applications directory, I could do this:

<< NC
<< NCAlgebra

expr = -a ** (b ** c - c ** b) + b ** (a ** c - c ** a) -
c ** (a ** b - b ** a) + (a ** b - b ** a) **
c - (a ** c - c ** a) ** b + (b ** c - c ** b) ** a

NCExpand[expr]

(* ==> 0 *)
-
Hmm wen I use the NC package I get NCExpand[Y01 ** Y10 - Y10 ** Y01] =0. Seems ** is interpreted differently here. – Mark Neuhaus May 16 '12 at 11:19
@Mark That is very strange. It seems Y01 ** Y10 - Y10 ** Y01 evaluates to 0 when using that package. a**b - b**a doesn't however. I am not familiar with the package, but I'll try to see what's going on. – Szabolcs May 16 '12 at 11:23
@Mark if you look at the docs of the package, it says: "At present, single-letter lower case variables are non-commutative by default and all others are commutative by default." – Szabolcs May 16 '12 at 11:29
@Mark Originally I suggested using expr //. e_NonCommutativeMultiply :> Distribute[e]. However, this won't work for an expression like a ** f[b ** (c + d)], so I'm removing it. – Szabolcs May 16 '12 at 11:31
Using SetNonCommutative[] worked. I wrote a little program that put all the thousands of indexed variables into SetNonCommutative[] and then used NCExpand[] to do the job, which it did pretty well. Good package. Robust even on input data >1MB ... – Mark Neuhaus May 18 '12 at 16:05