Message Boards Message Boards

0
|
1150 Views
|
6 Replies
|
5 Total Likes
View groups...
Share
Share this post:

Unable to Simplify non-commutative Expression Further

Posted 5 months ago

Dear Wolfram Community,

I hope this message finds you well. I require some assistance with a problem I encountered while using Wolfram Mathematica.

I have been trying to resolve problem 1.1 from the second edition of Sakurai's Modern Quantum Mechanics, using Mathematica. The problem's solution is shown below:

enter image description here

Here is the code I have been using:

In[3]:= commutator[x_, y_] := x ** y - y ** x

In[9]:= A ** commutator[C, B] ** D - A ** C ** commutator[D, B] + 
commutator[C, A] ** D ** B - 
C ** commutator[D, A] ** B // FullSimplify

Out[9]= -A ** C ** (-B ** D + D ** B) + A ** (-B ** C + C ** B) ** D -
C ** (-A ** D + D ** A) ** B + (-A ** C + C ** A) ** D ** B

However, I'm unsure as to why the result isn't further expandable and simplifiable. Am I missing something here? Any insights into this issue would greatly be appreciated.

Thank you for taking the time to read my query. I look forward to hearing from you soon.

Best regards, Zhao

POSTED BY: Hongyi Zhao
6 Replies

I tend to use a head other than NonCommutativeMultiply, and to attach down values of interest. This code is adapted from a Mathematica StackOverflow thread (I've used it elsewhere as well).

First define rules to enforce associativity and to distribute our product over Plus. Als we have some, not needed here, to pull out "scalars".

ncTimes[] := 1
ncTimes[a_] := a
ncTimes[a___, ncTimes[b_, c__], d___] := ncTimes[a, b, c, d]
ncTimes[a___, x_ + y_, b___] := ncTimes[a, x, b] + ncTimes[a, y, b]
ncTimes[a___, i_?NumericQ*c_, b___] := i*ncTimes[a, c, b]
ncTimes[a___, i_?NumericQ, b___] := i*ncTimes[a, b]
commutator[x_, y_] := ncTimes[x, y] - ncTimes[y, x]
anticommutator[x_, y_] := ncTimes[x, y] + ncTimes[y, x]

Here is the example.

lhs = commutator[ncTimes[a, b], ncTimes[c, d]]

(* Out[153]= ncTimes[a, b, c, d] - ncTimes[c, d, a, b] *)

rhs = 
 ncTimes[a, anticommutator[c, b], d] - 
  ncTimes[a, c, anticommutator[d, b]] + 
  ncTimes[anticommutator[c, a], d, b] - 
  ncTimes[c, anticommutator[d, a], b]

(* Out[154]= ncTimes[a, b, c, d] - ncTimes[c, d, a, b] *)

So the two canonicalize to the same expression (hence are equivalent).

POSTED BY: Daniel Lichtblau
Posted 5 months ago

Thank you very much for your tip. But I still wonder whether I can verify all the following identities with the help of Wolfram language:

enter image description here

Regards, Zhao

POSTED BY: Hongyi Zhao
Posted 5 months ago

But, now I found another strange thing: If I load and then unload NCAlgebra package, then my code snippet will not work correctly:

  1. First, test without loading NCAlgebra package, my code snippet works smoothly:

    In[1]:= (*
    The following method doesn't rely on NCAlgebra package.
    
    Unable to Simplify non-commutative Expression Further in Mathematica.
    https://community.wolfram.com/groups/-/m/t/3076922*)
    ClearAll["Global`*"]
    Unprotect[NonCommutativeMultiply];
    a_ ** (b_?NumberQ c_) := b*(a ** c)
    (b_?NumberQ c_) ** a_ := b*(c ** a)
    a_ ** (b_ + c_) := a ** b + a ** c
    (b_ + c_) ** a_ := b ** a + c ** a
    comm[x_, y_] := x ** y - y ** x
    anticomm[x_, y_] := x ** y + y ** x
    A ** anticomm[C, B] ** D - A ** C ** anticomm[D, B] + 
      anticomm[C, A] ** D ** B - C ** anticomm[D, A] ** B // Simplify
    % == comm[A ** B, C ** D] // FullSimplify
    
    Out[9]= A ** B ** C ** D - C ** D ** A ** B
    
    Out[10]= True
    
  2. Then, I try to load NCAlgebra package, and then unload it by ClearAll as follows:

    << NC`
    << NCAlgebra`
    
    NC::Directory: You are using a paclet version of NCAlgebra.
    
    NCAlgebra::SmallCapSymbolsNonCommutative: All lower cap single letter symbols (e.g. a,b,c,...) were set as noncommutative.
    
    In[15]:= (*
    The following method doesn't rely on NCAlgebra package.
    
    Unable to Simplify non-commutative Expression Further in Mathematica.
    https://community.wolfram.com/groups/-/m/t/3076922*)
    ClearAll["Global`*"]
    Unprotect[NonCommutativeMultiply];
    a_ ** (b_?NumberQ c_) := b*(a ** c)
    (b_?NumberQ c_) ** a_ := b*(c ** a)
    a_ ** (b_ + c_) := a ** b + a ** c
    (b_ + c_) ** a_ := b ** a + c ** a
    comm[x_, y_] := x ** y - y ** x
    anticomm[x_, y_] := x ** y + y ** x
    A ** anticomm[C, B] ** D - A ** C ** anticomm[D, B] + 
      anticomm[C, A] ** D ** B - C ** anticomm[D, A] ** B // Simplify
    % == comm[A ** B, C ** D] // FullSimplify
    
    During evaluation of In[15]:= ClearAll::wrsym: Symbol T is Protected.
    
    Out[23]= 0
    
    Out[24]= True
    

As you can see, now the result is 0. Any tips for fixing this problem will be appreciated.

See here for the related discussion.

Regards, Zhao

POSTED BY: Hongyi Zhao

You assume that ClearAll "unloads" NCAlgebra, but it certainly does not. It only attempts to clear the few global symbols, mainly the small cap letters and the convenience operator letter T. In fact, it even fails to do so (see ClearAll::wrsym message). But even if it had succeeded, it would not have cleared the hundreds of rules that NCAlgebra loads. Important in this case, that A, B, C, and D were not declared noncomutative and hence NonCommutativeMultiply will make them commute and simplify to zero, as you are a seeing. If you do not want to use NCAlgebra, simply do not load it. You can't load it and unload it in the middle of a session.

Try giving these rules:

Unprotect[NonCommutativeMultiply];
a_ ** (b_?NumberQ c_ ) := b*(a ** c)
(b_?NumberQ c_ ) ** a_ := b*(c ** a)
a_ ** (b_ + c_) := a ** b + a ** c
(b_ + c_) ** a_ := b ** a + c ** a
POSTED BY: Gianluca Gorni
Posted 5 months ago

Well, thank you very much. It worked, as shown below:

In[1]:= (*
The following method doesn't rely on NCAlgebra package.

Unable to Simplify non-commutative Expression Further in Mathematica.
https://community.wolfram.com/groups/-/m/t/3076922*)
Unprotect[NonCommutativeMultiply];
a_ ** (b_?NumberQ c_) := b*(a ** c)
(b_?NumberQ c_) ** a_ := b*(c ** a)
a_ ** (b_ + c_) := a ** b + a ** c
(b_ + c_) ** a_ := b ** a + c ** a
comm[x_, y_] := x ** y - y ** x
anticomm[x_, y_] := x ** y + y ** x
A ** anticomm[C, B] ** D - A ** C ** anticomm[D, B] + 
  anticomm[C, A] ** D ** B - C ** anticomm[D, A] ** B // Simplify
% == comm[A ** B, C ** D]

Out[8]= A ** B ** C ** D - C ** D ** A ** B

Out[9]= True

Regards, Zhao

POSTED BY: Hongyi Zhao
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract