[Date Index]
[Thread Index]
[Author Index]
Remove [was Re: RE: Re: Finding variables in a very long expression]
*To*: mathgroup at smc.vnet.net
*Subject*: [mg31566] Remove [was Re: [mg31456] RE: [mg31410] Re: Finding variables in a very long expression]
*From*: "Allan Hayes" <hay at haystack.demon.co.uk>
*Date*: Sun, 11 Nov 2001 16:26:10 -0500 (EST)
*Sender*: owner-wri-mathgroup at wolfram.com
Dear Fred and Hartmut,
I have collected the observations that have come up. I am puzzled by the
behaviour of Print in FURTHER NOTES 2), at the end.
REMOVE
Remove[a] causes a in the rules stored up to and including from the current
input line, and in the output of the current line to be replaced by a
special symbol that always prints as Removed[a], but Remove[a]'s in
different input lines
produce different Removed[a]'s (Fred Simons). These replacements preserve
the structure of
expressions , which would not happen if the occurences of a were simply
remove, while telling us about the removal.
Examples (Quit[]must always be evaluated in its own input line)
Quit[]
{b=a, Remove[a],c=a}
{b,c}
{Removed[a],Null,Removed[a]}
{Removed[a],Removed[a]}
Remove[a] is a print form for a symbol.
Check that Removed[a] is a symbol:
Head[b]
Symbol
The two occurences of Removed[a] above, values of b and c, are the same (
Evaluate[b] below gives Removed[a] - Fred Simons noted that Remove[a] can be
assigned a value)
Evaluate[b]=2;
{b,c}
{2,2}
Here, following our description at the beginning, only the a in b=a is
changed:
Quit[]
b=a;
Remove[a];
c=a;
{b,c}
{Removed[a],a}
And in the following, the two symbols that print as Removed[a] are
different
Quit[]
{b=a,Remove[a]}
{c=a,Remove[a]}
{b,c}
{Removed[a],Null}
{Removed[a],Null}
{Removed[a],Removed[a]}
That the two Removed[a]'s are different is show by the following, had they
been the same then both b and c would have evaluated to 3.
Evaluate[b]=2;
Evaluate[c] =3;
{b,c}
{2,3}
Here is we find that the values of the two versiona of Removed[a] are
stored in
OwnValues[Removed[a]]
ReleaseHold[Hold[OwnValues[b]]/.OwnValues[b]]
{HoldPattern[Removed[]] :> 2}
ReleaseHold[Hold[OwnValues[c]]/.OwnValues[c]]
{HoldPattern[Removed[]] :> 3}
FURTHER NOTES
1) Notice the TagBox in the cell expression of the output from
Remove[a];a
Cell[BoxData[
TagBox[
RowBox[{"Removed", "[", "\<\"a\"\>", "]"}],
False,
Editable->False]], "Output",
CellLabel->"Out[13]="]
2) A problem - why does the first Print[b=a] print a when the value of b
is Removed[a]?
Quit[]
{Print[b=a], Remove[a], Print[c=a];a};
{b,c}
a
Removed[a]
{Removed[a],Removed[a]}
{Removed[a],Removed[a]}
3) What we see as Removed[a] in the output above is not the same as the
output from typing in Removed[a]:
b
Removed[a]
b== Removed[a]
Removed[a]==Removed[a]
4) but
ToExpression[ToString[b]] \[Equal] Removed[a]
True
Hartmut Wolf noticed this.
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565
----- Original Message -----
From: "Fred Simons" <f.h.simons at tue.nl>
To: mathgroup at smc.vnet.net
<Hartmut.Wolf at t-systems.de>
Subject: [mg31566] Re: [mg31456] RE: [mg31410] Re: Finding variables in a very long
expression
> Dear Allan and Hartmut,
>
> With much interest I read your remarks on removed symbols.
>
> It seems to me that the only reason for the presence of the name Removed
in
> the system is that it gives the information about Removed["a"]. The name
> itself has no function properties, anyway it does not transform
Removed["a"]
> into a removed symbol a.
>
> Here are some more observations.
>
> In[6]:= c= f[a]; d = g[a];
> Remove[a]
> {c, d}
>
> Out[8]=
> {f[Removed[a]], g[Removed[a]]}
>
> In this expression, Removed[a] is a symbol:
>
> In[9]:=
> {c[[1]], c[[1]] // FullForm, c[[1]] // AtomQ,c[[1]] // Head}
>
> Out[9]=
> {Removed[a],Removed["a"],True,Symbol}
>
> When we type Removed["a"] ourselves, we have something completely
different,
> as in your remarks:
>
> In[11]:=
> {Removed["a"] , c[[1]]}
> Head /@ {Removed["a"] , c[[1]]}
> Removed["a"] \[Equal] c[[1]]
>
> Out[11]=
> {Removed[a],Removed[a]}
>
> Out[12]=
> {Removed,Symbol}
>
> Out[13]=
> Removed[a]==Removed[a]
>
> Now it is rather surprising that we can assign values to removed symbols.
>
> In[14]:=
> Hold @@ OwnValues[c] /. RuleDelayed[_, f[x_]] \[RuleDelayed] Set[x, \[Pi]]
> //
> ReleaseHold;
> OwnValues[c]
> {c, d}
>
> Out[15]=
> {HoldPattern[c]\[RuleDelayed]f[Removed[a]]}
>
> Out[16]=
> {f[\[Pi]],g[\[Pi]]}
>
> Now we recreate the name a and remove it.
>
> In[17]:=
> e=h[a]; Remove[a]; {c,d,e}
>
> Out[17]=
> {f[\[Pi]],g[\[Pi]],h[Removed[a]]}
>
> A new Removed[a] has been made that is different from the previous one,
that
> still exists.
>
> In[18]:=
> Hold @@ OwnValues[c] /.
> RuleDelayed[_, f[x_]] \[RuleDelayed]Clear[x] // ReleaseHold
> {c,d,e}
>
> Out[19]=
> {f[Removed[a]],g[Removed[a]],h[Removed[a]]}
>
> In[20]:=
> Hold @@ OwnValues[d] /. RuleDelayed[_, g[x_]] \[RuleDelayed] Set[x, 2] //
> ReleaseHold;
> Hold @@ OwnValues[e] /. RuleDelayed[_, h[x_]] \[RuleDelayed] Set[x, 3] //
> ReleaseHold;
> {c,d,e}
>
> Out[22]=
> {f[2],g[2],h[3]}
>
> So each time when a symbol is removed, a new removed symbol is created,
not
> overwriting previously made removed symbols. It is more or less like local
> variables in Module.
>
> Regards,
>
> Fred Simons
>
--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565
Prev by Date:
**Re: style sheeting**
Next by Date:
**Fast read ascii file**
Previous by thread:
**Re: style sheeting**
Next by thread:
**Fast read ascii file**
| |