MathGroup Archive 2011

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

Search the Archive

Re: evaluation-- one or many levels, your thoughts?

  • To: mathgroup at
  • Subject: [mg117088] Re: evaluation-- one or many levels, your thoughts?
  • From: Richard Fateman <fateman at>
  • Date: Wed, 9 Mar 2011 07:01:07 -0500 (EST)
  • References: <ikq8gs$7vl$> <ikt5i5$5$> <il2d46$61n$> <il50qo$n92$>

On 3/8/2011 2:36 AM, David Bailey wrote:
> On 07/03/2011 10:47, Richard Fateman wrote:
>> On 3/5/2011 3:07 AM, David Bailey wrote:
>> ..
>> e.g.
>> x1=x2
>> x2= Sum[a[i]*v^i,{i,1,1000}]
>> x3=x1  is, or should be, fast  whether it really assigns literally x2
>> or the Sum.
> It is too fast to measure - I have just tested it! Mathematica seems to
> be VERY good at tracking which parts of expressions need evaluating.

It is fast because it doesn't need to do much of anything.  If x1 is 
fully evaluated and does not have within it an occurrence of x3, then 
x3=x1 just copies a pointer.   How does it know that x1 does not have
within it an occurrence of x3?  That information (what variables affect
the value of an expression), is pre-computed.

> have often wondered about this, and I wish Wolfram would devote a blog
> article to lifting the hood a little about this!

You can read my review of Mathematica for an explanation.
>> 2. You are mimicking the execution of a program in a language like
>> FORTRAN, but are doing everything symbolically so as to find bugs,
>> and relate the computed values to expected mathematical formulas.
>> The fact that x=x+1   produces, for x, a value of "x+1" means that
>> x was not properly initialized and you have found a bug in the FORTRAN
>> program.
> If I wanted to do this, I'd probably replace X by a sequence of
> variables representing the successive values, so we would end up with
> something like
> X3=X2+1
> I'd certainly not represent the operation x=x+1 by that Mathematica
> expression!
Well, if you were not using Mathematica, you COULD.
> Before you object that this would generate an impossible number of
> variables, it is worth pointing out that such a simulation would
> probably also generate some horrendously large expressions, if performed
> for many cycles.

not if you did x=x+1.  After 100 times, you would have x+100.
> It is interesting that you need to resort to such an obscure example!

this is not obscure, but one of most successful early applications of
symbolic computation, to do program testing; I believe it was widely
used for testing of things like "reactor safety code", programs written
in Fortran.

> I think complete evaluation is desirable because there is no clear
> distinction between programming variables and algebraic variables.

This, of course, might be an error in design...

> If you write
> x=f[i,j,l,m] (where f stands for a complicated function)
> you clearly want f to evaluate if i is a loop variable, but not if none
> of the variables have changed since the expression has been created - in
> other words, Mathematica would need to track variable changes, whether
> it performed exhaustive evaluation or not!

Indeed, it tracks variable changes, and also keeps track of a virtual 
"time" so it knows if the change to i happened after the last evaluation 
of x.

> More generally, I think any CAS system has to contain compromises,
> particularly when it is also meant to a wider role as a numerical
> calculator. When I first encountered Mathematica, the exhaustive
> evaluation paradigm surprised me, but it is clearly implemented in an
> efficient way, so I am happy with it.

It is probably implemented efficiently for what it does, but that
does not eliminate the possibility of a (much) more efficient
evaluation setup.

  Furthermore, there is absolutely
> no way in which you could change this now, so any discussion seems a
> little pointless.

Well, in computer algebra research/business one is generally looking at
what the "next" system should do better than the current one.


  • Prev by Date: Re: Apply a rule to an expression only once
  • Next by Date: Re: PDE backward solution problem
  • Previous by thread: Re: evaluation-- one or many levels, your thoughts?
  • Next by thread: AstronomicalData errors and internet connectivity