Message Boards Message Boards

0
|
2079 Views
|
2 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Symbol a is Protected even after ClearAll["Global`*"]

Posted 1 year ago

See my following code snippet:

In[197]:= ClearAll["Global`*"]
a = {{4, 16, 4}, {7, 25, 8}, {17, 63, 18}};
b = {{2, -2, -2}, {7, -71, 2}, {14, -114, 0}};
Last[HermiteDecomposition[a]] == Last[HermiteDecomposition[b]]
MatrixForm /@ {LatticeReduce[a], LatticeReduce[b]}

During evaluation of In[197]:= Set::wrsym: Symbol a is Protected.

During evaluation of In[197]:= Set::wrsym: Symbol b is Protected.

During evaluation of In[197]:= HermiteDecomposition::latm: Matrix contains an entry that is not rational.

During evaluation of In[197]:= HermiteDecomposition::latm: Matrix contains an entry that is not rational.

Out[200]= a == b

Out[201]= {\!\(\*
TagBox[
RowBox[{"LatticeReduce", "[", "a", "]"}],
Function[BoxForm`e$, 
MatrixForm[BoxForm`e$]]]\), \!\(\*
TagBox[
RowBox[{"LatticeReduce", "[", "b", "]"}],
Function[BoxForm`e$, 
MatrixForm[BoxForm`e$]]]\)}

As you can see, I've used the command ClearAll["Global`"]* at the beginninf of my code, but still the Symbol a is Protected** problem is triggered. Any hints for fixing this problem?

Regards,
Zhao

POSTED BY: Hongyi Zhao
2 Replies
Posted 1 year ago

From the documentation of ClearAll:

enter image description here

POSTED BY: Hans Milton

From the documentation for ClearAll:

ClearAll does not affect symbols with the attributes Locked or Protected.  »

You could Unprotect your variables or localize them. Or do not Protect symbols in the global context. Protecting them should indicate that you do not want to use them except in the protected way. That seems to be false in your situation.

If you've also locked the variables, then use different variables.

In my own workflows, I do not ClearAll["Global`*"] nor do I Protect symbols in the Global` context. I also do not set single-letter variables to a value, except localized in Module, Block, With, or Pattern — or in scratch work in a Documentation notebook, since cell groups get a unique context in them. That's all a matter of personal style, though, and probably idiosyncratic. Mostly they avoid mistakes I commonly make. One danger I live with is that when a new documentation page loads, it wipes out your scratch work, even if you go back (I suspect many people wouldn't like that danger).

POSTED BY: Michael Rogers
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