Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #3094

Metastable expressions in Mathematica

From David Bailey <dave@removedbailey.co.uk>
Newsgroups comp.soft-sys.math.mathematica
Subject Metastable expressions in Mathematica
Date 2011-06-14 10:14 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <it7cae$636$1@smc.vnet.net> (permalink)

Show all headers | View raw


Everyone knows that expressions in Mathematica get automatically 
evaluated as far as is possible. Furthermore, most people realise that 
Mathematica must have a way to track changes to the definitions of 
symbols, so as to avoid excessive evaluation.

Here is the typical case:

In[672]:= Clear[f]

In[673]:= test = g[f[a]]

Out[673]= g[f[a]]

'test' contains an expression containing an unevaluated function call to f

In[674]:= test

Out[674]= g[f[a]]

Now we give f a definition, and confirm that Mathematica 'knows' the 
expression held by 'test' needs to be reevaluated:

In[675]:= f[x_] := x^2;

In[676]:= test

Out[676]= g[a^2]

So far as expected, but now we define f in a way that allows it to be 
switched on and off without actually changing its definition:

In[677]:= Clear[f]

In[679]:= switch = False;

In[680]:= f[x_] := x^2 /; switch

In[681]:= test = g[f[a]]

Out[681]= g[f[a]]

In[682]:= switch = True;

Here we see that Mathematica fails to notice that the expression can be 
further evaluated - the expression in 'test' is metastable.

In[683]:= test

Out[683]= g[f[a]]

Some processes obviously cause complete evaluation:

In[684]:= Uncompress[Compress[test]]

Out[684]= g[a^2]

Others, rather surprisingly, do not!

(Dialog) In[687]:= test /. f -> f

(Dialog) Out[687]= g[f[a]]

I don't really consider metastable expression to be a bug - more a 
curiosity - and it would be undesirable to slow Mathematica processing 
to try to fix this.

However, metastable expressions, do give a window into the methods 
Mathematica uses to minimise the reevaluation of expressions. For 
example, it might be interesting to repeat the above 10000 times with 
different symbols, to determine if Mathematica is always consistent in 
this regard.

I have never seen this effect discussed, so I would be interested in 
links to previous discussions, if any.

David Bailey
http://www.dbaileyconsultancy.co.uk

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Metastable expressions in Mathematica David Bailey <dave@removedbailey.co.uk> - 2011-06-14 10:14 +0000

csiph-web