Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If I load and then unload NCAlgebra package, my code snippet will not work properly. #27

Closed
hongyi-zhao opened this issue Dec 4, 2023 · 1 comment

Comments

@hongyi-zhao
Copy link

hongyi-zhao commented Dec 4, 2023

My testing is as follows:

  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
  1. 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

@mcdeoliveira
Copy link
Collaborator

You assume that ClearAll "unloads" NCAlgebra but this is far from it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants