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