MathGroup Archive 2002

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

Search the Archive

RE: Is it possible to access internal variables? [CompoundExpression]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg34797] RE: Is it possible to access internal variables? [CompoundExpression]
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
  • Date: Fri, 7 Jun 2002 01:09:01 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Dear Allan,

you might be interested in this device to check for the evaluation sequence:
 
In[1]:= v[n_] := Nest["*" <> # &, "", n]

In[2]:= e1 /; (Print["e1", v[++c1]]; False) = Null
In[3]:= e2 /; (Print["e2", v[++c2]]; False) = Null
In[4]:= e3 /; (Print["e3", v[++c3]]; False) = Null

 normal execution of CompoundExpression:

In[5]:= c1 = c2 = c3 = 0;
In[6]:= e1; e2; e3
>From In[6]:= e1*
>From In[6]:= e2*
>From In[6]:= e3*
>From In[6]:= e3**
Out[6]= e3

 pushing e3:

In[7]:= c1 = c2 = c3 = 0;
In[8]:= e1; e2; Evaluate[e3]
>From In[8]:= e3*
>From In[8]:= e1*
>From In[8]:= e2*
>From In[8]:= e3**
>From In[8]:= e3***
Out[8]= e3

 conversely:

In[9]:= c1 = c2 = c3 = 0;
In[10]:= e1; e2; {e3}
>From In[10]:= e1*
>From In[10]:= e2*
>From In[10]:= e3*
Out[10]= {e3}

... "lists are inert"

 equally:

In[11]:= c1 = c2 = c3 = 0;
In[12]:= e1; {e2, e3}
>From In[12]:= e1*
>From In[12]:= e2*
>From In[12]:= e3*
Out[12]= {e2, e3}

 also

In[13]:= c1 = c2 = c3 = 0;
In[14]:= (e1; Evaluate[{e2, e3}])
>From In[14]:= e2*
>From In[14]:= e3*
>From In[14]:= e1*
Out[14]= {e2, e3}

 sandwiching
 
In[15]:= c1 = c2 = c3 = 0;
In[16]:= (e1; Evaluate[{Hold[e2], e3}]) // ReleaseHold
>From In[16]:= e3*
>From In[16]:= e1*
>From In[16]:= e2*
>From In[16]:= e3**
Out[16]= {e2, e3}
 
In[17]:= c1 = c2 = c3 = 0;
In[18]:= (e1; Evaluate[e2; e3])
>From In[18]:= e2*
>From In[18]:= e3*
>From In[18]:= e3**
>From In[18]:= e1*
>From In[18]:= e3***
>From In[18]:= e3****
Out[18]= e3
 
In[19]:= c1 = c2 = c3 = 0;
In[20]:= (e1; Evaluate[Hold[e2]; e3]) // ReleaseHold
>From In[20]:= e3*
>From In[20]:= e3**
>From In[20]:= e1*
>From In[20]:= e3***
>From In[20]:= e3****
>From In[20]:= e3*****
Out[20]= e3

I'd call this a 5 star evaluation

--
Hartmut


> -----Original Message-----
> From: Allan Hayes [mailto:hay at haystack.demon.co.uk]
To: mathgroup at smc.vnet.net
> Sent: Thursday, June 06, 2002 1:34 PM
> Subject: [mg34797] Re: Is it possible to access internal variables?
> [CompoundExpression]
> 
> 
> Dear Hartmut,
> 
> The description of the evaluation of CompoundExpression in
> http://library.wolfram.com/mathgroup/archive/1999/Feb/msg00460.html
> was corrected in
>  http://library.wolfram.com/mathgroup/archive/1999/Feb/msg00440.html
> 
> (although the latter was sent a day later, for some reason it appears
> earlier in the MathGroup numbering).
> 
> Here is a sketch of the evaluation ( e* denotes the value of e)
> 
>  CompoundExpression[e1, Evaluate[e2], e3]
>  CompoundExpression[e1, e2*, e3] (*evaluate Evaluate[.].. in order*)
>  CompoundExpression[e1*, e2*,  e3](*restart; evaluate entries 
> in order*)
>  CompoundExpression[e1*, e2**,  e3]
>  CompoundExpression[e1*, e2**,  e3*]
>  e3*
>  e3**   (*evaluate e3* since it is not the same as
>             CompoundExpression[e1*, e2**,  e3*]
>           *)
> 
> 
> SUPPORTING EVIDENCE ( I have added comments to the output)
> 
> Clear[pr,a];
> 
> CompoundExpression[
> Print[pr = Print], Evaluate[pr[Print[2]]], {a, a = 4}
> ]
> 
>     2            (* from evaluating Evaluate[...] to pr[Null] *)
> 
>     Print       (* from evaluating Print[pr = Print] *)
> 
>     Null        (* from evaluating pr[Null] *)
> 
>     {4,4}        (* from the evaluation of {a, 4} , after 
> evaluating a=4*)
> 
> 
> SIMULATION with CE
> 
>     SetAttributes[CE, HoldAll]
>     CE[x__]:= Last[{x}]
>     CE[]:=Null
> 
>     Clear[pr,a];
> 
>     CE[
>         Print[pr = Print], Evaluate[pr[Print[2]]], {a,a=4}
>     ]
> 
>         2
> 
>         Print
> 
>         Null
> 
>         {4,4}
> 
> --
> 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
> 
> 
> "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com> wrote in message
> news:admtj1$ekh$1 at smc.vnet.net...
> >
> > Hello Bobby,
> >
> > Two things: (1) as Hob Hanlon has pointed out, I missed to 
> assign to v at
> > definiton of h[x_], which of course explains everything. 
> Aside from being
> > this my standard blunder mixing up Append with AppendTo in 
> my mind from my
> > first day on with Mathematica, I did not look close enough, 
> and finally:
> > there are no mysteries. Sorry for disturbing you.
> >
> > (2) What considers CompoundExpression: this is no bug for 
> shure; instead
> we
> > simply have to recognize the precise semantics of (e1; e2; ...; en)
> >
> > The expressions e1, e2, up to en are executed in order, 
> then the result of
> > en is assigned to CompoundExpression[e1, e2, ..., en] and 
> then this is
> > evaluated again. Normaly, this has no visible effect since 
> the execution
> > environment of en when evaluated within the 
> CompoundExpression is the same
> > as that of the CompoundExpression when it returns; yet this 
> is not enough.
> > Here, since FindMinimum fails it returns itself unevaluated 
> (a standard
> > behaviour), this now becomes the value of 
> CompoundExpression and such
> > FindMinimum will start anew.
> >
> > This all conforms to the execution sequence as specified 
> for Mathematica.
> We
> > certainly should have internalized this precisely and 
> permanently (as a
> > morning prayer). However, we are human beings, and build up 
> our own rules
> in
> > our heads and take many shortcuts. It's there where we often become
> > irritated. We just have concede that
> >
> >  In[1]:= expr1
> >
> >  In[2]:= expr2
> >
> > is *not* the same as
> >
> >  In[1]:= expr1;
> >          expr2
> >
> > As I mentioned I've seen a prior thread to this theme with 
> a prominent
> > contribution of Allan Hayes, e.g.
> > 
> http://library.wolfram.com/mathgroup/archive/1999/Feb/msg00460
> .html or see
> > also my reply to Allan at another thread
> > 
> http://library.wolfram.com/mathgroup/archive/2000/Jul/msg00115.html .
> >
> > BTW esp. with Block, things are quite the same, and quite 
> common here,
> since
> > the execution
> > environment within Block almost always differs form that 
> one outside: we
> > have to anticipate the transformations to the _result_ of 
> Block, as here
> to
> > the _result_ of CompoundExpression.
> >
> > --
> > Hartmut
> >
> >
> > > -----Original Message-----
> > > From: DrBob [mailto:majort at cox-internet.com]
To: mathgroup at smc.vnet.net
> > > Sent: Tuesday, June 04, 2002 5:59 PM
> > > Cc: 'David Park'; BobHanlon at aol.com
> > > Subject: [mg34797] RE:  Is it possible to
> > > access internal variables?
> > >
> > >
> > > If compound expressions are not evaluated in order, how 
> can Modules or
> > > Blocks work?  Aren't they compound expressions?  What 
> makes g and h
> > > different?
> > >
> > > These are serious bugs.
> > >
> > > I feel like we're walking on quicksand, now.
> > >
> > > Bobby
> > >
> > > -----Original Message-----
> > > From: Wolf, Hartmut [mailto:Hartmut.Wolf at t-systems.com]
To: mathgroup at smc.vnet.net
> > > Sent: Tuesday, June 04, 2002 3:45 AM
> > > Subject: [mg34797]  Is it possible
> > > to access
> > > internal variables?
> > >
> > >
> > > Hello Bob,
> > >
> > > there is something mysterious with your proposal that disturbs me
> > > somewhat.
> > > See my records:
> > >
> > > In[1]:= f[x_] := (x - 3)(x - 4)
> > >
> > > In[2]:= g[x_] := Module[{t = f[x]}, v = Append[v, {x, t}]; t];
> > > In[3]:= v = {}; FindMinimum[g[x], {x, 2, 1, 3}]
> > > >From In[3]:=
> > > FindMinimum::"regex": "Reached the point 
> \!\({3.5000000000000018`}\)
> > > which
> > > is \
> > > outside the region \!\({\({1.`, 3.`}\)}\)."
> > > >From In[3]:=
> > > FindMinimum::"regex": "Reached the point 
> \!\({3.5000000000000018`}\)
> > > which
> > > is \
> > > outside the region \!\({\({1.`, 3.`}\)}\)."
> > > Out[3]=
> > > FindMinimum[g[x], {x, 2, 1, 3}]
> > >
> > > In[4]:= v
> > > Out[4]=
> > > {{2., 2.}, {2., 2.}, {2.03136, 1.9069}, {2.05074, 
> 1.85035}, {2.18642,
> > >     1.4755}, {3., 0.}, {2., 2.}, {2., 2.}, {2.03136, 1.9069},
> > > {2.05074,
> > >     1.85035}, {2.18642, 1.4755}, {3., 0.}}
> > >
> > > In[5]:= g[x]
> > > Out[5]= (-4 + x) (-3 + x)
> > >
> > > In[6]:= ?g
> > > Global`g
> > > g[x_] := Module[{t = f[x]}, v = Append[v, {x, t}]; t]
> > >
> > > Apart from the fact that FindMinimum is restarted and 
> that the first
> > > value
> > > appears twice, this seems to be what you intended. It doesn't
> > > help Arny
> > > though, as the minimum value -- what he supposed to be 
> that x occuring
> > > in
> > >
> > > But there seems to be something special with g, if I try with h it
> > > doesn't
> > > work:
> > >
> > > In[7]:= h[x_] := Module[{t = f[x]}, Append[v, {x, t}]; t];
> > > In[8]:= v = {}; FindMinimum[h[x], {x, 2, 1, 3}]
> > > >From In[8]:=
> > > FindMinimum::"regex": "Reached the point 
> \!\({3.5000000000000018`}\)
> > > which
> > > is \
> > > outside the region \!\({\({1.`, 3.`}\)}\)."
> > > >From In[8]:=
> > > FindMinimum::"regex": "Reached the point 
> \!\({3.5000000000000018`}\)
> > > which
> > > is \
> > > outside the region \!\({\({1.`, 3.`}\)}\)."
> > > Out[8]=
> > > FindMinimum[h[x], {x, 2, 1, 3}]
> > >
> > > In[9]:= v     (* v is empty *)
> > > Out[9]= {}
> > >
> > > In[10]:= h[x]
> > > Out[10]= (-4 + x) (-3 + x)
> > >
> > > In[11]:= ?h
> > > Global`h
> > > h[x_] := Module[{t = f[x]}, Append[v, {x, t}]; t]
> > >
> > >
> > > Now observe:
> > >
> > > In[12]:= FindMinimum[Print[x]; f[x], {x, 2, 1, 3}]
> > > >From In[12]:= x
> > > >From In[12]:= 2.
> > > >From In[12]:= 2.03136
> > > >From In[12]:= 2.05074
> > > >From In[12]:= 2.18642
> > > >From In[12]:= 3.
> > > >From In[12]:= FindMinimum::"regex": "Reached the point
> > > \!\({3.5000000000000018`}\) which is \
> > > outside the region \!\({\({1.`, 3.`}\)}\)."
> > > Out[12]= FindMinimum[Print[x]; f[x], {x, 2, 1, 3}]
> > >
> > > The Argument of FindMinimum is evaluated first with 
> symbolic x (to get
> > > at
> > > the derivative I suppose), later, at the second call, it and
> > > such also t
> > > =
> > > (-4 + x) (-3 + x) get a numeric value, and therefore the 
> values are
> > > introduced into v when appending {x,t}, so the start value
> > > gets doubled.
> > >
> > >
> > > The restart of the minimization seems to be triggered by 
> the compound
> > > expression v = {}; FindMinimum[...] in the main loop (not 
> within Find
> > > Minimum)
> > >
> > > In[19]:= h5[x_] := Module[{t = f[x]}, Print[x]; t];
> > >
> > > In[20]:= v = {}; FindMinimum[h5[x], {x, 2, 1, 3}]
> > > >From In[20]:= x
> > > >From In[20]:= 2.
> > > >From In[20]:= 2.03136
> > > >From In[20]:= 2.05074
> > > >From In[20]:= 2.18642
> > > >From In[20]:= 3.
> > > >From In[20]:=
> > > FindMinimum::"regex": "Reached the point 
> \!\({3.5000000000000018`}\)
> > > which
> > > is \
> > > outside the region \!\({\({1.`, 3.`}\)}\)."
> > > >From In[20]:= x
> > > >From In[20]:= 2.
> > > >From In[20]:= 2.03136
> > > >From In[20]:= 2.05074
> > > >From In[20]:= 2.18642
> > > >From In[20]:= 3.
> > > >From In[20]:=
> > > FindMinimum::"regex": "Reached the point 
> \!\({3.5000000000000018`}\)
> > > which
> > > is \
> > > outside the region \!\({\({1.`, 3.`}\)}\)."
> > > Out[20]= FindMinimum[h5[x], {x, 2, 1, 3}]
> > >
> > > Any expression e.g. (3; FindMinimum[...]) does that too; 
> conversely if
> > > you
> > > initialize v in an extra line, there will be no restart. 
> This may have
> > > something to do with peculiarities of compound 
> expression, sometimes
> > > starting a re-evaluation. (This had been reported by 
> Allan Hayes some
> > > years
> > > ago.) See:
> > >
> > > In[65]:= x = 5;
> > >
> > > In[66]:= x =.; Print[x]; {x, x = 3, x}
> > > >From In[66]:= x
> > > Out[66]= {3, 3, 3}
> > >
> > > In[67]:= x =.
> > > In[68]:= {x, x = 3, x}
> > > Out[68]= {x, 3, 3}
> > >
> > > Anyways, as shown above, Arny's desire to get at 
> 'internal values' of
> > > FindMinimum seems to be hopeless. My advice would be to 
> check for the
> > > error
> > > message and then possibly increase the search range (by a certain
> > > tolerance)
> > > and restart (only a finite number of times).
> > >
> > > --
> > > Hartmut
> > >
> > >
> > > > -----Original Message-----
> > > > From: BobHanlon at aol.com [mailto:BobHanlon at aol.com]
To: mathgroup at smc.vnet.net
> > > > Sent: Sunday, June 02, 2002 7:15 AM
> > > > Subject: [mg34797]  Is it possible to access
> > > internal
> > > > variables?
> > > >
> > > >
> > > >
> > > > In a message dated 6/1/02 6:18:58 AM,
> > > > someone at somewhere.sometime writes:
> > > >
> > > > >I am minimizing a function which only has real values
> > > > >between 1 and -1,
> > > > most
> > > > >of the time... occasionally its range is different and
> > > > unknown, (but anyway
> > > > >not far from 1 and -1).  I could write a routine using Check
> > > > to catch errors
> > > > >and then expand the range over which FindMinimum is allowed
> > > > to search,
> > > > >but
> > > > >since FindMinimum seems to be getting the appropriate values
> > > > anyway - it
> > > > >tells me the values in its error message -  I was wondering
> > > > if there weren't
> > > > >some way to get at those values and use them without
> > > > bothering to write
> > > > >said routine.  I was thinking of analysing 'MessageList' or
> > > > '$MessageList',
> > > > >but was thinking there might be some easier way.
> > > > >
> > > > >Aren't variables within packages accessible via their long
> > > > names, e.g.
> > > > >`package`private`variablename or something like that?  Does
> > > > anyone have
> > > > >any suggestions?
> > > > >
> > > >
> > > > f[x_] := (x-3)(x-4);
> > > >
> > > > g[x_] := Module[{t = f[x]}, v=Append[v, {x,t}]; t];
> > > >
> > > > g is the same function as f except that calls to g are 
> recorded in v
> > > >
> > > > v={}; FindMinimum[g[x], {x, 2}]
> > > >
> > > > {-0.25, {x -> 3.5}}
> > > >
> > > > FindMinimum called g at the following values of x:
> > > >
> > > > v[[All,1]]
> > > >
> > > > {2., 2., 2.0313609375, 2.0507430627940644,
> > > >
> > > >   2.1864179398525154, 3.136142079261673, 3.500000000000001,
> > > >
> > > >   3.838316500294484, 3.5, 3.3180710396308366,
> > > >
> > > >   3.4999904004703097, 3.5, 3.499999994722301}
> > > >
> > > >
> > > > Bob Hanlon
> > > > Chantilly, VA  USA
> > > >
> > >
> > >
> > >
> >
> 
> 
> 

------_=_NextPart_001_01C20D8F.F90A4740

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2651.75">
<TITLE>RE: Is it possible to access internal variables? [CompoundExpression]</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=2>Dear Allan,</FONT>
</P>

<P><FONT SIZE=2>you might be interested in this device to check for the evaluation sequence:</FONT>
<BR><FONT SIZE=2>&nbsp;</FONT>
<BR><FONT SIZE=2>In[1]:= v[n_] := Nest[&quot;*&quot; &lt;&gt; # &amp;, &quot;&quot;, n]</FONT>
</P>

<P><FONT SIZE=2>In[2]:= e1 /; (Print[&quot;e1&quot;, v[++c1]]; False) = Null</FONT>
<BR><FONT SIZE=2>In[3]:= e2 /; (Print[&quot;e2&quot;, v[++c2]]; False) = Null</FONT>
<BR><FONT SIZE=2>In[4]:= e3 /; (Print[&quot;e3&quot;, v[++c3]]; False) = Null</FONT>
</P>

<P><FONT SIZE=2>&nbsp;normal execution of CompoundExpression:</FONT>
</P>

<P><FONT SIZE=2>In[5]:= c1 = c2 = c3 = 0;</FONT>
<BR><FONT SIZE=2>In[6]:= e1; e2; e3</FONT>
<BR><FONT SIZE=2>From In[6]:= e1*</FONT>
<BR><FONT SIZE=2>From In[6]:= e2*</FONT>
<BR><FONT SIZE=2>From In[6]:= e3*</FONT>
<BR><FONT SIZE=2>From In[6]:= e3**</FONT>
<BR><FONT SIZE=2>Out[6]= e3</FONT>
</P>

<P><FONT SIZE=2>&nbsp;pushing e3:</FONT>
</P>

<P><FONT SIZE=2>In[7]:= c1 = c2 = c3 = 0;</FONT>
<BR><FONT SIZE=2>In[8]:= e1; e2; Evaluate[e3]</FONT>
<BR><FONT SIZE=2>From In[8]:= e3*</FONT>
<BR><FONT SIZE=2>From In[8]:= e1*</FONT>
<BR><FONT SIZE=2>From In[8]:= e2*</FONT>
<BR><FONT SIZE=2>From In[8]:= e3**</FONT>
<BR><FONT SIZE=2>From In[8]:= e3***</FONT>
<BR><FONT SIZE=2>Out[8]= e3</FONT>
</P>

<P><FONT SIZE=2>&nbsp;conversely:</FONT>
</P>

<P><FONT SIZE=2>In[9]:= c1 = c2 = c3 = 0;</FONT>
<BR><FONT SIZE=2>In[10]:= e1; e2; {e3}</FONT>
<BR><FONT SIZE=2>From In[10]:= e1*</FONT>
<BR><FONT SIZE=2>From In[10]:= e2*</FONT>
<BR><FONT SIZE=2>From In[10]:= e3*</FONT>
<BR><FONT SIZE=2>Out[10]= {e3}</FONT>
</P>

<P><FONT SIZE=2>... &quot;lists are inert&quot;</FONT>
</P>

<P><FONT SIZE=2>&nbsp;equally:</FONT>
</P>

<P><FONT SIZE=2>In[11]:= c1 = c2 = c3 = 0;</FONT>
<BR><FONT SIZE=2>In[12]:= e1; {e2, e3}</FONT>
<BR><FONT SIZE=2>From In[12]:= e1*</FONT>
<BR><FONT SIZE=2>From In[12]:= e2*</FONT>
<BR><FONT SIZE=2>From In[12]:= e3*</FONT>
<BR><FONT SIZE=2>Out[12]= {e2, e3}</FONT>
</P>

<P><FONT SIZE=2>&nbsp;also</FONT>
</P>

<P><FONT SIZE=2>In[13]:= c1 = c2 = c3 = 0;</FONT>
<BR><FONT SIZE=2>In[14]:= (e1; Evaluate[{e2, e3}])</FONT>
<BR><FONT SIZE=2>From In[14]:= e2*</FONT>
<BR><FONT SIZE=2>From In[14]:= e3*</FONT>
<BR><FONT SIZE=2>From In[14]:= e1*</FONT>
<BR><FONT SIZE=2>Out[14]= {e2, e3}</FONT>
</P>

<P><FONT SIZE=2>&nbsp;sandwiching</FONT>
<BR><FONT SIZE=2>&nbsp;</FONT>
<BR><FONT SIZE=2>In[15]:= c1 = c2 = c3 = 0;</FONT>
<BR><FONT SIZE=2>In[16]:= (e1; Evaluate[{Hold[e2], e3}]) // ReleaseHold</FONT>
<BR><FONT SIZE=2>From In[16]:= e3*</FONT>
<BR><FONT SIZE=2>From In[16]:= e1*</FONT>
<BR><FONT SIZE=2>From In[16]:= e2*</FONT>
<BR><FONT SIZE=2>From In[16]:= e3**</FONT>
<BR><FONT SIZE=2>Out[16]= {e2, e3}</FONT>
<BR><FONT SIZE=2>&nbsp;</FONT>
<BR><FONT SIZE=2>In[17]:= c1 = c2 = c3 = 0;</FONT>
<BR><FONT SIZE=2>In[18]:= (e1; Evaluate[e2; e3])</FONT>
<BR><FONT SIZE=2>From In[18]:= e2*</FONT>
<BR><FONT SIZE=2>From In[18]:= e3*</FONT>
<BR><FONT SIZE=2>From In[18]:= e3**</FONT>
<BR><FONT SIZE=2>From In[18]:= e1*</FONT>
<BR><FONT SIZE=2>From In[18]:= e3***</FONT>
<BR><FONT SIZE=2>From In[18]:= e3****</FONT>
<BR><FONT SIZE=2>Out[18]= e3</FONT>
<BR><FONT SIZE=2>&nbsp;</FONT>
<BR><FONT SIZE=2>In[19]:= c1 = c2 = c3 = 0;</FONT>
<BR><FONT SIZE=2>In[20]:= (e1; Evaluate[Hold[e2]; e3]) // ReleaseHold</FONT>
<BR><FONT SIZE=2>From In[20]:= e3*</FONT>
<BR><FONT SIZE=2>From In[20]:= e3**</FONT>
<BR><FONT SIZE=2>From In[20]:= e1*</FONT>
<BR><FONT SIZE=2>From In[20]:= e3***</FONT>
<BR><FONT SIZE=2>From In[20]:= e3****</FONT>
<BR><FONT SIZE=2>From In[20]:= e3*****</FONT>
<BR><FONT SIZE=2>Out[20]= e3</FONT>
</P>

<P><FONT SIZE=2>I'd call this a 5 star evaluation</FONT>
</P>

<P><FONT SIZE=2>--</FONT>
<BR><FONT SIZE=2>Hartmut</FONT>
</P>
<BR>

<P><FONT SIZE=2>&gt; -----Original Message-----</FONT>
<BR><FONT SIZE=2>&gt; From: Allan Hayes [<A HREF="mailto:hay at haystack.demon.co.uk">mailto:hay at haystack.demon.co.uk</A>]</FONT>
To: mathgroup at smc.vnet.net
<BR><FONT SIZE=2>&gt; Sent: Thursday, June 06, 2002 1:34 PM</FONT>
<BR><FONT SIZE=2>&gt; To: Wolf, Hartmut; majort at cox-internet.com; Bob Hanlon; David Park</FONT>
<BR><FONT SIZE=2>&gt; Subject: [mg34797] Re: Is it possible to access internal variables?</FONT>
<BR><FONT SIZE=2>&gt; [CompoundExpression]</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt; Dear Hartmut,</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt; The description of the evaluation of CompoundExpression in</FONT>
<BR><FONT SIZE=2>&gt; <A HREF="http://library.wolfram.com/mathgroup/archive/1999/Feb/msg00460.html"; TARGET="_blank">http://library.wolfram.com/mathgroup/archive/1999/Feb/msg00460.html</A></FONT>
<BR><FONT SIZE=2>&gt; was corrected in</FONT>
<BR><FONT SIZE=2>&gt;&nbsp; <A HREF="http://library.wolfram.com/mathgroup/archive/1999/Feb/msg00440.html"; TARGET="_blank">http://library.wolfram.com/mathgroup/archive/1999/Feb/msg00440.html</A></FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt; (although the latter was sent a day later, for some reason it appears</FONT>
<BR><FONT SIZE=2>&gt; earlier in the MathGroup numbering).</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt; Here is a sketch of the evaluation ( e* denotes the value of e)</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt;&nbsp; CompoundExpression[e1, Evaluate[e2], e3]</FONT>
<BR><FONT SIZE=2>&gt;&nbsp; CompoundExpression[e1, e2*, e3] (*evaluate Evaluate[.].. in order*)</FONT>
<BR><FONT SIZE=2>&gt;&nbsp; CompoundExpression[e1*, e2*,&nbsp; e3](*restart; evaluate entries </FONT>
<BR><FONT SIZE=2>&gt; in order*)</FONT>
<BR><FONT SIZE=2>&gt;&nbsp; CompoundExpression[e1*, e2**,&nbsp; e3]</FONT>
<BR><FONT SIZE=2>&gt;&nbsp; CompoundExpression[e1*, e2**,&nbsp; e3*]</FONT>
<BR><FONT SIZE=2>&gt;&nbsp; e3*</FONT>
<BR><FONT SIZE=2>&gt;&nbsp; e3**&nbsp;&nbsp; (*evaluate e3* since it is not the same as</FONT>
<BR><FONT SIZE=2>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CompoundExpression[e1*, e2**,&nbsp; e3*]</FONT>
<BR><FONT SIZE=2>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *)</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt; SUPPORTING EVIDENCE ( I have added comments to the output)</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt; Clear[pr,a];</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt; CompoundExpression[</FONT>
<BR><FONT SIZE=2>&gt; Print[pr = Print], Evaluate[pr[Print[2]]], {a, a = 4}</FONT>
<BR><FONT SIZE=2>&gt; ]</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt;&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (* from evaluating Evaluate[...] to pr[Null] *)</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Print&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (* from evaluating Print[pr = Print] *)</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Null&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (* from evaluating pr[Null] *)</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt;&nbsp;&nbsp;&nbsp;&nbsp; {4,4}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (* from the evaluation of {a, 4} , after </FONT>
<BR><FONT SIZE=2>&gt; evaluating a=4*)</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt; SIMULATION with CE</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt;&nbsp;&nbsp;&nbsp;&nbsp; SetAttributes[CE, HoldAll]</FONT>
<BR><FONT SIZE=2>&gt;&nbsp;&nbsp;&nbsp;&nbsp; CE[x__]:= Last[{x}]</FONT>
<BR><FONT SIZE=2>&gt;&nbsp;&nbsp;&nbsp;&nbsp; CE[]:=Null</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Clear[pr,a];</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt;&nbsp;&nbsp;&nbsp;&nbsp; CE[</FONT>
<BR><FONT SIZE=2>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Print[pr = Print], Evaluate[pr[Print[2]]], {a,a=4}</FONT>
<BR><FONT SIZE=2>&gt;&nbsp;&nbsp;&nbsp;&nbsp; ]</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Print</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Null</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {4,4}</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt; --</FONT>
<BR><FONT SIZE=2>&gt; Allan</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt; ---------------------</FONT>
<BR><FONT SIZE=2>&gt; Allan Hayes</FONT>
<BR><FONT SIZE=2>&gt; Mathematica Training and Consulting</FONT>
<BR><FONT SIZE=2>&gt; Leicester UK</FONT>
<BR><FONT SIZE=2>&gt; www.haystack.demon.co.uk</FONT>
<BR><FONT SIZE=2>&gt; hay at haystack.demon.co.uk</FONT>
<BR><FONT SIZE=2>&gt; Voice: +44 (0)116 271 4198</FONT>
<BR><FONT SIZE=2>&gt; Fax: +44 (0)870 164 0565</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt; &quot;Wolf, Hartmut&quot; &lt;Hartmut.Wolf at t-systems.com&gt; wrote in message</FONT>
<BR><FONT SIZE=2>&gt; <A HREF="news:admtj1$ekh$1 at smc.vnet.net" TARGET="_blank">news:admtj1$ekh$1 at smc.vnet.net</A>...</FONT>
<BR><FONT SIZE=2>&gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; Hello Bobby,</FONT>
<BR><FONT SIZE=2>&gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; Two things: (1) as Hob Hanlon has pointed out, I missed to </FONT>
<BR><FONT SIZE=2>&gt; assign to v at</FONT>
<BR><FONT SIZE=2>&gt; &gt; definiton of h[x_], which of course explains everything. </FONT>
<BR><FONT SIZE=2>&gt; Aside from being</FONT>
<BR><FONT SIZE=2>&gt; &gt; this my standard blunder mixing up Append with AppendTo in </FONT>
<BR><FONT SIZE=2>&gt; my mind from my</FONT>
<BR><FONT SIZE=2>&gt; &gt; first day on with Mathematica, I did not look close enough, </FONT>
<BR><FONT SIZE=2>&gt; and finally:</FONT>
<BR><FONT SIZE=2>&gt; &gt; there are no mysteries. Sorry for disturbing you.</FONT>
<BR><FONT SIZE=2>&gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; (2) What considers CompoundExpression: this is no bug for </FONT>
<BR><FONT SIZE=2>&gt; shure; instead</FONT>
<BR><FONT SIZE=2>&gt; we</FONT>
<BR><FONT SIZE=2>&gt; &gt; simply have to recognize the precise semantics of (e1; e2; ...; en)</FONT>
<BR><FONT SIZE=2>&gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; The expressions e1, e2, up to en are executed in order, </FONT>
<BR><FONT SIZE=2>&gt; then the result of</FONT>
<BR><FONT SIZE=2>&gt; &gt; en is assigned to CompoundExpression[e1, e2, ..., en] and </FONT>
<BR><FONT SIZE=2>&gt; then this is</FONT>
<BR><FONT SIZE=2>&gt; &gt; evaluated again. Normaly, this has no visible effect since </FONT>
<BR><FONT SIZE=2>&gt; the execution</FONT>
<BR><FONT SIZE=2>&gt; &gt; environment of en when evaluated within the </FONT>
<BR><FONT SIZE=2>&gt; CompoundExpression is the same</FONT>
<BR><FONT SIZE=2>&gt; &gt; as that of the CompoundExpression when it returns; yet this </FONT>
<BR><FONT SIZE=2>&gt; is not enough.</FONT>
<BR><FONT SIZE=2>&gt; &gt; Here, since FindMinimum fails it returns itself unevaluated </FONT>
<BR><FONT SIZE=2>&gt; (a standard</FONT>
<BR><FONT SIZE=2>&gt; &gt; behaviour), this now becomes the value of </FONT>
<BR><FONT SIZE=2>&gt; CompoundExpression and such</FONT>
<BR><FONT SIZE=2>&gt; &gt; FindMinimum will start anew.</FONT>
<BR><FONT SIZE=2>&gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; This all conforms to the execution sequence as specified </FONT>
<BR><FONT SIZE=2>&gt; for Mathematica.</FONT>
<BR><FONT SIZE=2>&gt; We</FONT>
<BR><FONT SIZE=2>&gt; &gt; certainly should have internalized this precisely and </FONT>
<BR><FONT SIZE=2>&gt; permanently (as a</FONT>
<BR><FONT SIZE=2>&gt; &gt; morning prayer). However, we are human beings, and build up </FONT>
<BR><FONT SIZE=2>&gt; our own rules</FONT>
<BR><FONT SIZE=2>&gt; in</FONT>
<BR><FONT SIZE=2>&gt; &gt; our heads and take many shortcuts. It's there where we often become</FONT>
<BR><FONT SIZE=2>&gt; &gt; irritated. We just have concede that</FONT>
<BR><FONT SIZE=2>&gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt;&nbsp; In[1]:= expr1</FONT>
<BR><FONT SIZE=2>&gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt;&nbsp; In[2]:= expr2</FONT>
<BR><FONT SIZE=2>&gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; is *not* the same as</FONT>
<BR><FONT SIZE=2>&gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt;&nbsp; In[1]:= expr1;</FONT>
<BR><FONT SIZE=2>&gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; expr2</FONT>
<BR><FONT SIZE=2>&gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; As I mentioned I've seen a prior thread to this theme with </FONT>
<BR><FONT SIZE=2>&gt; a prominent</FONT>
<BR><FONT SIZE=2>&gt; &gt; contribution of Allan Hayes, e.g.</FONT>
<BR><FONT SIZE=2>&gt; &gt; </FONT>
<BR><FONT SIZE=2>&gt; <A HREF="http://library.wolfram.com/mathgroup/archive/1999/Feb/msg00460"; TARGET="_blank">http://library.wolfram.com/mathgroup/archive/1999/Feb/msg00460</A></FONT>
<BR><FONT SIZE=2>&gt; .html or see</FONT>
<BR><FONT SIZE=2>&gt; &gt; also my reply to Allan at another thread</FONT>
<BR><FONT SIZE=2>&gt; &gt; </FONT>
<BR><FONT SIZE=2>&gt; <A HREF="http://library.wolfram.com/mathgroup/archive/2000/Jul/msg00115.html"; TARGET="_blank">http://library.wolfram.com/mathgroup/archive/2000/Jul/msg00115.html</A> .</FONT>
<BR><FONT SIZE=2>&gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; BTW esp. with Block, things are quite the same, and quite </FONT>
<BR><FONT SIZE=2>&gt; common here,</FONT>
<BR><FONT SIZE=2>&gt; since</FONT>
<BR><FONT SIZE=2>&gt; &gt; the execution</FONT>
<BR><FONT SIZE=2>&gt; &gt; environment within Block almost always differs form that </FONT>
<BR><FONT SIZE=2>&gt; one outside: we</FONT>
<BR><FONT SIZE=2>&gt; &gt; have to anticipate the transformations to the _result_ of </FONT>
<BR><FONT SIZE=2>&gt; Block, as here</FONT>
<BR><FONT SIZE=2>&gt; to</FONT>
<BR><FONT SIZE=2>&gt; &gt; the _result_ of CompoundExpression.</FONT>
<BR><FONT SIZE=2>&gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; --</FONT>
<BR><FONT SIZE=2>&gt; &gt; Hartmut</FONT>
<BR><FONT SIZE=2>&gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; -----Original Message-----</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; From: DrBob [<A HREF="mailto:majort at cox-internet.com">mailto:majort at cox-internet.com</A>]</FONT>
To: mathgroup at smc.vnet.net
<BR><FONT SIZE=2>&gt; &gt; &gt; Sent: Tuesday, June 04, 2002 5:59 PM</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; Cc: 'David Park'; BobHanlon at aol.com</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; Subject: [mg34797] RE:&nbsp; Is it possible to</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; access internal variables?</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; If compound expressions are not evaluated in order, how </FONT>
<BR><FONT SIZE=2>&gt; can Modules or</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; Blocks work?&nbsp; Aren't they compound expressions?&nbsp; What </FONT>
<BR><FONT SIZE=2>&gt; makes g and h</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; different?</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; These are serious bugs.</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; I feel like we're walking on quicksand, now.</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; Bobby</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; -----Original Message-----</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; From: Wolf, Hartmut [<A HREF="mailto:Hartmut.Wolf at t-systems.com">mailto:Hartmut.Wolf at t-systems.com</A>]</FONT>
To: mathgroup at smc.vnet.net
<BR><FONT SIZE=2>&gt; &gt; &gt; Sent: Tuesday, June 04, 2002 3:45 AM</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; Subject:&nbsp; Is it possible</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; to access</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; internal variables?</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; Hello Bob,</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; there is something mysterious with your proposal that disturbs me</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; somewhat.</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; See my records:</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; In[1]:= f[x_] := (x - 3)(x - 4)</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; In[2]:= g[x_] := Module[{t = f[x]}, v = Append[v, {x, t}]; t];</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; In[3]:= v = {}; FindMinimum[g[x], {x, 2, 1, 3}]</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;From In[3]:=</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; FindMinimum::&quot;regex&quot;: &quot;Reached the point </FONT>
<BR><FONT SIZE=2>&gt; \!\({3.5000000000000018`}\)</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; which</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; is \</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; outside the region \!\({\({1.`, 3.`}\)}\).&quot;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;From In[3]:=</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; FindMinimum::&quot;regex&quot;: &quot;Reached the point </FONT>
<BR><FONT SIZE=2>&gt; \!\({3.5000000000000018`}\)</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; which</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; is \</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; outside the region \!\({\({1.`, 3.`}\)}\).&quot;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; Out[3]=</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; FindMinimum[g[x], {x, 2, 1, 3}]</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; In[4]:= v</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; Out[4]=</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; {{2., 2.}, {2., 2.}, {2.03136, 1.9069}, {2.05074, </FONT>
<BR><FONT SIZE=2>&gt; 1.85035}, {2.18642,</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; 1.4755}, {3., 0.}, {2., 2.}, {2., 2.}, {2.03136, 1.9069},</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; {2.05074,</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; 1.85035}, {2.18642, 1.4755}, {3., 0.}}</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; In[5]:= g[x]</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; Out[5]= (-4 + x) (-3 + x)</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; In[6]:= ?g</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; Global`g</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; g[x_] := Module[{t = f[x]}, v = Append[v, {x, t}]; t]</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; Apart from the fact that FindMinimum is restarted and </FONT>
<BR><FONT SIZE=2>&gt; that the first</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; value</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; appears twice, this seems to be what you intended. It doesn't</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; help Arny</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; though, as the minimum value -- what he supposed to be </FONT>
<BR><FONT SIZE=2>&gt; that x occuring</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; in</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; But there seems to be something special with g, if I try with h it</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; doesn't</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; work:</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; In[7]:= h[x_] := Module[{t = f[x]}, Append[v, {x, t}]; t];</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; In[8]:= v = {}; FindMinimum[h[x], {x, 2, 1, 3}]</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;From In[8]:=</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; FindMinimum::&quot;regex&quot;: &quot;Reached the point </FONT>
<BR><FONT SIZE=2>&gt; \!\({3.5000000000000018`}\)</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; which</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; is \</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; outside the region \!\({\({1.`, 3.`}\)}\).&quot;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;From In[8]:=</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; FindMinimum::&quot;regex&quot;: &quot;Reached the point </FONT>
<BR><FONT SIZE=2>&gt; \!\({3.5000000000000018`}\)</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; which</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; is \</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; outside the region \!\({\({1.`, 3.`}\)}\).&quot;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; Out[8]=</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; FindMinimum[h[x], {x, 2, 1, 3}]</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; In[9]:= v&nbsp;&nbsp;&nbsp;&nbsp; (* v is empty *)</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; Out[9]= {}</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; In[10]:= h[x]</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; Out[10]= (-4 + x) (-3 + x)</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; In[11]:= ?h</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; Global`h</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; h[x_] := Module[{t = f[x]}, Append[v, {x, t}]; t]</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; Now observe:</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; In[12]:= FindMinimum[Print[x]; f[x], {x, 2, 1, 3}]</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;From In[12]:= x</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;From In[12]:= 2.</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;From In[12]:= 2.03136</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;From In[12]:= 2.05074</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;From In[12]:= 2.18642</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;From In[12]:= 3.</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;From In[12]:= FindMinimum::&quot;regex&quot;: &quot;Reached the point</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; \!\({3.5000000000000018`}\) which is \</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; outside the region \!\({\({1.`, 3.`}\)}\).&quot;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; Out[12]= FindMinimum[Print[x]; f[x], {x, 2, 1, 3}]</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; The Argument of FindMinimum is evaluated first with </FONT>
<BR><FONT SIZE=2>&gt; symbolic x (to get</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; at</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; the derivative I suppose), later, at the second call, it and</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; such also t</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; =</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; (-4 + x) (-3 + x) get a numeric value, and therefore the </FONT>
<BR><FONT SIZE=2>&gt; values are</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; introduced into v when appending {x,t}, so the start value</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; gets doubled.</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; The restart of the minimization seems to be triggered by </FONT>
<BR><FONT SIZE=2>&gt; the compound</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; expression v = {}; FindMinimum[...] in the main loop (not </FONT>
<BR><FONT SIZE=2>&gt; within Find</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; Minimum)</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; In[19]:= h5[x_] := Module[{t = f[x]}, Print[x]; t];</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; In[20]:= v = {}; FindMinimum[h5[x], {x, 2, 1, 3}]</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;From In[20]:= x</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;From In[20]:= 2.</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;From In[20]:= 2.03136</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;From In[20]:= 2.05074</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;From In[20]:= 2.18642</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;From In[20]:= 3.</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;From In[20]:=</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; FindMinimum::&quot;regex&quot;: &quot;Reached the point </FONT>
<BR><FONT SIZE=2>&gt; \!\({3.5000000000000018`}\)</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; which</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; is \</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; outside the region \!\({\({1.`, 3.`}\)}\).&quot;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;From In[20]:= x</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;From In[20]:= 2.</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;From In[20]:= 2.03136</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;From In[20]:= 2.05074</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;From In[20]:= 2.18642</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;From In[20]:= 3.</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;From In[20]:=</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; FindMinimum::&quot;regex&quot;: &quot;Reached the point </FONT>
<BR><FONT SIZE=2>&gt; \!\({3.5000000000000018`}\)</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; which</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; is \</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; outside the region \!\({\({1.`, 3.`}\)}\).&quot;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; Out[20]= FindMinimum[h5[x], {x, 2, 1, 3}]</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; Any expression e.g. (3; FindMinimum[...]) does that too; </FONT>
<BR><FONT SIZE=2>&gt; conversely if</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; you</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; initialize v in an extra line, there will be no restart. </FONT>
<BR><FONT SIZE=2>&gt; This may have</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; something to do with peculiarities of compound </FONT>
<BR><FONT SIZE=2>&gt; expression, sometimes</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; starting a re-evaluation. (This had been reported by </FONT>
<BR><FONT SIZE=2>&gt; Allan Hayes some</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; years</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; ago.) See:</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; In[65]:= x = 5;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; In[66]:= x =.; Print[x]; {x, x = 3, x}</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;From In[66]:= x</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; Out[66]= {3, 3, 3}</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; In[67]:= x =.</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; In[68]:= {x, x = 3, x}</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; Out[68]= {x, 3, 3}</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; Anyways, as shown above, Arny's desire to get at </FONT>
<BR><FONT SIZE=2>&gt; 'internal values' of</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; FindMinimum seems to be hopeless. My advice would be to </FONT>
<BR><FONT SIZE=2>&gt; check for the</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; error</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; message and then possibly increase the search range (by a certain</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; tolerance)</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; and restart (only a finite number of times).</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; --</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; Hartmut</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; -----Original Message-----</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; From: BobHanlon at aol.com [<A HREF="mailto:BobHanlon at aol.com">mailto:BobHanlon at aol.com</A>]</FONT>
To: mathgroup at smc.vnet.net
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; Sent: Sunday, June 02, 2002 7:15 AM</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; Subject:&nbsp; Is it possible to access</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; internal</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; variables?</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; In a message dated 6/1/02 6:18:58 AM,</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; someone at somewhere.sometime writes:</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; &gt;I am minimizing a function which only has real values</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; &gt;between 1 and -1,</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; most</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; &gt;of the time... occasionally its range is different and</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; unknown, (but anyway</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; &gt;not far from 1 and -1).&nbsp; I could write a routine using Check</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; to catch errors</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; &gt;and then expand the range over which FindMinimum is allowed</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; to search,</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; &gt;but</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; &gt;since FindMinimum seems to be getting the appropriate values</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; anyway - it</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; &gt;tells me the values in its error message -&nbsp; I was wondering</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; if there weren't</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; &gt;some way to get at those values and use them without</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; bothering to write</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; &gt;said routine.&nbsp; I was thinking of analysing 'MessageList' or</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; '$MessageList',</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; &gt;but was thinking there might be some easier way.</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; &gt;Aren't variables within packages accessible via their long</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; names, e.g.</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; &gt;`package`private`variablename or something like that?&nbsp; Does</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; anyone have</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; &gt;any suggestions?</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; f[x_] := (x-3)(x-4);</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; g[x_] := Module[{t = f[x]}, v=Append[v, {x,t}]; t];</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; g is the same function as f except that calls to g are </FONT>
<BR><FONT SIZE=2>&gt; recorded in v</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; v={}; FindMinimum[g[x], {x, 2}]</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; {-0.25, {x -&gt; 3.5}}</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; FindMinimum called g at the following values of x:</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; v[[All,1]]</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; {2., 2., 2.0313609375, 2.0507430627940644,</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;&nbsp;&nbsp; 2.1864179398525154, 3.136142079261673, 3.500000000000001,</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;&nbsp;&nbsp; 3.838316500294484, 3.5, 3.3180710396308366,</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;&nbsp;&nbsp; 3.4999904004703097, 3.5, 3.499999994722301}</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; Bob Hanlon</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; Chantilly, VA&nbsp; USA</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt; </FONT>
</P>

</BODY>
</HTML>
------_=_NextPart_001_01C20D8F.F90A4740--


  • Prev by Date: Re: Use of NonlinearRegress[..., ShowProgress -> True,...] Option Output.
  • Next by Date: Re: PlotVectorField
  • Previous by thread: RE: Graphics
  • Next by thread: Re: Is it possible to access internal variables? [CompoundExpression]