Re: ?
- To: mathgroup at smc.vnet.net
- Subject: [mg42908] Re: ?
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Sat, 2 Aug 2003 04:12:33 -0400 (EDT)
- References: <bg9mqh$pi8$1@smc.vnet.net>
- Reply-to: "Allan Hayes" <hay at haystack.demon.co.uk>
- Sender: owner-wri-mathgroup at wolfram.com
Some notes on Remove and how they relate to Hartmut's posting (parsing seems to be important in sorting out the original query from Vadym). If during the evaluation of an input line, Remove[symbol1..."form1"...] is evaluated (it gives Null) then for any unprotected symbol s that is a symboli or whose name matches a "formi": - Mathematica deletes "s" from the list Names and deletes all stored rules that are tagged by s. - each s in the remaining stored rules (including parsing rules) and in the currrent state of the input line is replaced by a new symbol rs, say, that is different for each s and each input line. - rs prints as Removed["short name of s"] (the short names of a and c`a are both a); - rs cannot be found by Names, but can be assigned values; - evaluating Remove[rs] gives Null and generates a message that s has already been removed, othewise it does nothing; This preserve the structure of expressions, which would not happen if removed symbols were simply deleted. Some of these features show in In[1]:= Quit In[1]:= {s=2,s,Remove[s],s,s=3,s,OwnValues[s],Symbol["s"]} Out[2]= {2, 2, Null, Removed[s], 3, 3, {HoldPattern[Removed[s]] :> 3}, s} In[3]:= s Out[3]= s Turning to the original example involving Derivative we have In[4]:= Quit Note first the parsing (not evaluation since f' is held). In[1]:= Hold[f']//InputForm Out[1]//InputForm= Hold[Derivative[1][f]] In[2]:= f'[2]=3; Here is the rule just created, it is tagged by Derivative. In[3]:= SubValues[Derivative]//First//InputForm Out[3]//InputForm= HoldPattern[Derivative[1][f][2]] :> 3 Remove Derivative In[4]:= Remove[Derivative] Suppose that Derivative is replaced by rd (which prints as Removed[Derivative]) In the parsing rules, Derivative has been changed to rd: In[5]:= Hold[f']//FullForm Out[5]//FullForm= Hold[Removed["Derivative"][1][f]] So the following creates the rule HoldPattern[rd[1][f][2]]\[RuleDelayed]3 In[6]:= f'[2]=4; and we get In[7]:= f'[2] Out[7]= 4 via the parsed form HoldPattern[rd[1][f][2]] The second use of Remove: In[8]:= Remove[Derivative] does nothing as Hatrmut points out,save create Derivative and then deleted it, so we again get In[9]:= f'[2] Out[9]= 4 Allan --------------- Allan Hayes hay at haystack.demon.co.uk Voice: +44 (0)116 241 8747 Fax: +44 (0)870 164 0565 "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com> wrote in message news:bg9mqh$pi8$1 at smc.vnet.net... > > >-----Original Message----- > >From: lepetyuk at hotmail.com [mailto:lepetyuk at hotmail.com] To: mathgroup at smc.vnet.net > >Sent: Wednesday, July 30, 2003 10:08 AM > >To: mathgroup at smc.vnet.net > >Subject: [mg42908] ? > > > > > >Hello MathGroup: > > > >When I execute the following list of expressions (in Mathematica > >v.4.2) I expect to get "f'[5]" from the last expression instead > >of "3". Is it a bug or something else? > > > >---------------------------- > >f'[5] > >f'[_] = 2; > >f'[5] > >Remove[Derivative] > >f'[5] > >f'[_] = 3; > >f'[5] > >Remove[Derivative] > >f'[5] > >---------------------------- > > > >If Remove[] is replaced by Clear[] the output from the last > >expression is "f'[5]" as expected. Would it be the reason to > >always use Clear[] rather than Remove[]? > > > >Thank you, > >Vadym > > > > I cannot Remove Removed[Derivative], as this is no symbol: > > In[15]:= ?Removed > "Removed[string] is printed to indicate a symbol that has been removed." > > > However, if a symbol is Removed, other symbols still might refer to that, > this is indicated by Removed["string-for-name-of-symbol"], see e.g. > > In[1]:= s = d > Out[1]= d > > In[2]:= d[f][_] = 2 > Out[2]= 2 > > In[3]:= d[f][5] > Out[3]= 2 > > In[4]:= ?? d > > Global`d > > d[f][_] = 2 > > In[5]:= Remove[d] > > In[6]:= s > Out[6]= Removed["d"] > > In particular the system doesn't crash. > > > Now, Removed["d"] isn't accessible, you can't see downvalues or anything of > it. > > However, by miracle, you still may assign a value to it: > > In[7]:= s[f][_] = 3 > Out[7]= 3 > > In[8]:= ?s > > Global`s > > s = Removed["d"] > > The definition made is not associated with s, but it is there, somewhere > > In[9]:= s[f][5] > Out[9]= 3 > > In[10]:= s[f][5] // Trace > Out[10]= {{{s, Removed["d"]}, Removed["d"][f]}, Removed["d"][f][5], 3} > > so it is associated with Removed["d"]. > > > Similar things happen with Derivative. Your second assignment goes to > Removed["Derivative"] and the expression > > f'[5] recalls from there > > The second attempt to Remove[Derivative] after that does not work, this > removes "Derivative" (which does not exits, or is created anew and then > removed, I don't know), but it does not remove Removed["Derivative"] (and > shall not, if you want to keep alive). > > > Just the same as happens here: > > In[11]:= Remove[d] > > In[12]:= s[f][5] > Out[12]= 3 > > > > BTW: you shouldn't remove Derivative, nor Clear it. Perhaps you may reach > your ends whith shadowing? Or what was it, you wanted to attain in first > place? > > -- > Hartmut Wolf >