10

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.

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
Mark Neuhaus
  • 337
  • 2
  • 7
  • 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 Answers1

11

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 *)
Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
  • 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
  • 1
    @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
  • 2
    @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
  • NCExpand[x01 ** x10 - x10 ** x01] still gives zero. What kind of indexing can I use? (I have more than 1000 variables so different letters is not an option) – Mark Neuhaus May 16 '12 at 12:27
  • @Mark again, unfortunately I haven't used the package. A glance at the docs confirms that only single-letter lowercase variables are non-commutative by default. You can set x01, x10 to be non-commutative using SetNonCommutative[x01, x10]. I'm not sure how the default for all symbols can be changed. Regarding easy indexing, x[0, 1] ** x[1, 0] - x[1, 0] ** x[0, 1] might be an easier solution. – Szabolcs May 16 '12 at 12:31
  • Ok. I wrote an email to the developers. I will post the results here. – Mark Neuhaus May 16 '12 at 12:37
  • 1
    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
  • 1
    The newest version of NCAlgebra supports Subscript. If the base symbol is noncommutative so will be its subscripted version. Things like: Subscript[x, 0, 1] ** Subscript[x, 1, 0] - Subscript[x, 1, 0] ** Subscript[x, 0, 1] will work out of the box. – Mauricio de Oliveira Apr 19 '17 at 16:13