MathGroup Archive 2006

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

Search the Archive

Confusing behaviour with caching of evaluated expressions ?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63727] Confusing behaviour with caching of evaluated expressions ?
  • From: Chris Rodgers <rodgers at physchem.NOSPAMox.aREMOVEc.uk>
  • Date: Thu, 12 Jan 2006 03:22:35 -0500 (EST)
  • Organization: Oxford University, England
  • Sender: owner-wri-mathgroup at wolfram.com

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.


  • Prev by Date: Java -> Mathematica -> Java
  • Next by Date: Re: PrincipalComponents
  • Previous by thread: Re: Re: Java -> Mathematica -> Java
  • Next by thread: Re: Confusing behaviour with caching of evaluated expressions ?