Non-commutative algebra (NCAlgebra): How to properly SetCommutingOperators
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).
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