11
$\begingroup$

I am starting to work with non-commutative algebra in Mathematica and had a look at the NCAlgebra package. I installed it and can use its functions. However, what I am struggling with is the SetCommutingOperators command, described in I.4.6.4 of the documentation. Honestly, LeftQ, SetCommutingFunctions and SetCommutingOperators just reference themselves in a cycle if I am not mistaken - which disallows me to fully understand the important note about using LeftQ.

How do I properly define that two symbols a and b commute, such that a**b-b**a==0. Some code with (as it appears) no effect of SetCommutingOperators:

ClearAll["Global`*"];
<< NC`
<< NCAlgebra`
SetCommutingOperators[a, b]
a ** b == b ** a`
(* a ** b == b ** a *)
NCE[b ** a - a ** b]
(* -a ** b + b ** a *)

It is important, that a and b are not commutative in general.

Clarification It was suggested in a comment to use SetCommutative[a,b] which achieves the desired result in this case. However, this is the wrong approach as you can see if there is a second operator c with that a and b should not commute:

SetCommutative[a, b]
a**c-c**a
(* 0 *)

This is not desired; it should be -c**a+a**c. SetCommutative sets a and b commutative in general, but they should only commute with each other.

$\endgroup$
3
  • $\begingroup$ Why can't you just use SetCommutative[a, b]. It works. $\endgroup$
    – Hubble07
    Commented Dec 18, 2015 at 13:27
  • $\begingroup$ @Hubble07 In some sense it does, but actually it lets a and b commute with everything. See update $\endgroup$
    – Lukas
    Commented Dec 18, 2015 at 13:35
  • $\begingroup$ Check my answer $\endgroup$
    – Hubble07
    Commented Dec 18, 2015 at 13:54

2 Answers 2

8
$\begingroup$

Setting LeftQ[a, b] = True together with SetCommutingOperators seems to work.

ClearAll["Global`*"];
<< NC`
<< NCAlgebra`

NCE[b ** a - a ** b]

(*-a ** b + b ** a`*)

SetCommutingOperators[a, b];
LeftQ[a, b] = True;

NCE[b ** a - a ** b]

(*0*)

NCE[a ** c - c ** a]

(*a ** c - c ** a*)

Update providing explanation for the usage of SetCommutingOperators

Firstly the docs (see pg 74) says

SetCommutingOperators takes exactly two parameters. SetCommutingOperators[b, c] will implement the definitions which follow ...

This means that SetCommutingOperators is not supposed to be used as a standalone command instead it should always be followed by setting LeftQ

Secondly LeftQ determines which of the two operators should be equated to the other.

For e.g.

 SetCommutingOperators[a, b];
 LeftQ[a, b] = True;

 a ** b
(*a ** b*)

 b ** a
(*a ** b*)

 SetCommutingOperators[a, b];
 LeftQ[a, b] = False;

 a ** b
(*b ** a*)

 b ** a
(*b ** a*)

So LeftQ is required to be set in order to avoid any ambiguity about which operator is actually equated to the other. This is mentioned clearly in the NOTE section in that same page.

Also the order of operators in LeftQ should match the order in SetCommutingOperators. Read the WARNING section in that page.

Lastly for SetCommutingOperators it doesn't matter if you set LeftQ to either True or False with the correct ordering. I think the True/False matters for SetCommutingFunctions as seen here (scroll to the bottom).

$\endgroup$
3
  • $\begingroup$ Thanks alot! Can you explain what the LeftQ actually does? I'd like to understand what it is needed for $\endgroup$
    – Lukas
    Commented Dec 18, 2015 at 17:11
  • $\begingroup$ @Lukas see my updated answer $\endgroup$
    – Hubble07
    Commented Dec 18, 2015 at 18:30
  • $\begingroup$ many thanks! Of course I read the description of LeftQ and also the referenced note. But I wasn't able to make the right out of it. Now it's clear :) $\endgroup$
    – Lukas
    Commented Dec 18, 2015 at 19:14
7
$\begingroup$

In the newest version of NCAlgebra the command SetCommutingOperators has been much improved. It is implemented using UpValues for efficiency and it no longer uses LeftQ. Instead, it will honor whatever order you give to SetCommutingOperators. For example, after:

<< NC`
<< NCAlgebra`
SetCommutingOperators[a,b]

the following will have the results:

a ** b == b ** a

True

b ** a - a ** b

0

a ** b

a ** b

b ** a

a ** b

If instead you use

SetCommutingOperators[b,a]

then

a ** b

b ** a

b ** a

b ** a

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.