MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Subscript[x,1] value do not get cleared using Clear["Global`*"]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg104064] Re: Subscript[x,1] value do not get cleared using Clear["Global`*"]
  • From: Albert Retey <awnl at gmx-topmail.de>
  • Date: Sat, 17 Oct 2009 07:04:37 -0400 (EDT)
  • References: <hb9jt6$ke$1@smc.vnet.net>

Nasser M. Abbasi wrote:
> Hello,
> Version 7 on XP Sp2
> 
> Before, I used to use Clear["Global`*] to clear all variable, until I just 
> found subscripted variable do not get cleared
> 
> In[31]:= Remove["Global`*"]
> 
> In[33]:= Subscript[a, 1] = 5
> 
> In[34]:= Subscript[a, 1]
> Out[34]= 5
> 
> In[35]:= Clear["Global`*"]    --> now clear it
> 
> In[36]:= Subscript[a, 1]
> Out[36]= 5      ----> did not clear
> 
> In[37]:= Remove["Global`*"]
> In[38]:= Subscript[a, 1]
> 
> Out[38]= Subscript[a, 1]   ---> ok, removed
> 
> I find the above a bit strange. I first thought may be becuase I did not 
> "symbolize" a_1 using the notation package, but even after doing that, a_1 
> would still not be cleared of its value:
> 
> In[59]:= Remove["Global`*"]
> In[60]:= << "Notation`"
> 
> In[61]:= Symbolize[ParsedBoxWrapper[\(a\_1\)]]
> 
> In[62]:= Subscript[a, 1] = 5
> Out[62]= 5
> 
> In[63]:= Clear["Global`*"]   --> now clear it
> 
> In[64]:= Subscript[a, 1]
> Out[64]= 5   ----> did not clear
> 
> In[65]:= Remove["Global`*"]
> 
> In[66]:= Subscript[a, 1]
> Out[66]= Removed[a\[UnderBracket]Subscript\[UnderBracket]1]
> 
> I thought the above should make it so that a_1 is now "one" symbol, and it 
> should have been cleared?
> 
> So now, to make sure I am starting with clean computation, I either will do 
> Remove[...] or restart the kernel.
> 
> Do you find this strange or is it just me?

It is strange, but the following should help you understand what is
going on:

Subscript[a,1]=5

DownValues[Subscript]

Context[Subscript]

Clear["Global`*"]

DownValues[Subscript]

Remove[a]

DownValues[Subscript]

there are two possibilities to achieve what you want: Either
Clear[Subscript] in addition to Clear["Global`*"] or associate the
definition for Subscript[a,1] with a instead of Subscript via e.g. TagSet:

a /: Subscript[a, 1] = 5

then the definition is in:

UpValues[a]

and will be Cleared with Clear[a] (or Clear["Global`*"])

hth,

albert


  • Prev by Date: Re: Generic Mapping Tools and Mathematica
  • Next by Date: Re: Subscript[x,1] value do not get cleared using Clear["Global`*"]
  • Previous by thread: Re: Point on sphere greatest distance from given points
  • Next by thread: Re: Subscript[x,1] value do not get cleared using Clear["Global`*"]