Re: Confusing behaviour with caching of evaluated expressions ?
- To: mathgroup at smc.vnet.net
- Subject: [mg63745] Re: [mg63727] Confusing behaviour with caching of evaluated expressions ?
- From: "Carl K. Woll" <carlw at wolfram.com>
- Date: Fri, 13 Jan 2006 04:48:23 -0500 (EST)
- References: <200601120822.DAA10481@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Chris Rodgers wrote: > Hi, > > Can anyone shed any light upon the following unexpected output from > Mathematica? > > I have come across some rather strange behaviour in the way Mathematica > handles expressions which depend on a "flag" variable e.g.: > > F[x_] := G /; flag==1 > > It appears that Mathematica forgets that flag is a variable that might > change in the future. Thus, if one defines another expression e.g.: > > flag=0 > expr1= F[z1] > expr2:=F[z2] > > expr1 and expr2 will both currently evaluate to F[z1] and F[z2] as > expected. BUT, if we now change the flag and try to prod them into > evaluating to give G, things become tricky: > > flag=1 > expr1 > expr2 > Evaluate[expr1] > Evaluate[expr2] > FullSimplify[expr1] > FullSimplify[expr2] > > Even doing something like > > F[z1] > expr1 > > doesn't work. (The F[z1] returns G correctly, but expr1 doesn't realise > that it should change to give G.) > > The only way to make it work again seems to be to "change" z1 or z2. For > example, > > z1=z1+0 > expr1 > > RandomFunctionIMadeUp[z2]^:=33 > expr2 > > These two assignments are enough to make Mathematica update its cache(?). > > Can anyone explain to me why this might be "by design"? > > Can anyone tell me a way to make Mathematica fully evaluate an > expression e.g. expr1 without getting stuck in this way? Is there a > SuperFullActuallyEvaluate[expr1] commmand?? :-) > > Many thanks in advance, > > Chris. The command you are looking for is Update. After changing flag, do Update[F]. Then, F will use the new value of flag. Carl Woll Wolfram Research
- References:
- Confusing behaviour with caching of evaluated expressions ?
- From: Chris Rodgers <rodgers@physchem.NOSPAMox.aREMOVEc.uk>
- Confusing behaviour with caching of evaluated expressions ?