MathGroup Archive 2011

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

Search the Archive

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

  • To: mathgroup at
  • Subject: [mg116995] Re: evaluation-- one or many levels, your thoughts?
  • From: Richard Fateman <fateman at>
  • Date: Mon, 7 Mar 2011 05:46:52 -0500 (EST)
  • References: <ikq8gs$7vl$> <ikt5i5$5$>

On 3/5/2011 3:07 AM, David Bailey wrote:

  Some time ago, I did some timing tests to explore this very
> issue - for example,
> x1=large expression;
> x2=x1;
> The cost of the assignment to x2  did not seem to increase with the
> complexity of the large expression, and clearly the kernel uses some
> pretty clever techniques to prevent redundant reevaluations.

It doesn't always avoid redundant calculations, but that depends on
secret heuristics.

The cost of the initial assignment should not be a problem. It is 
keeping track of changes, perhaps unnecessarily.
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.

Next define a[n_]:=b[n!].
x3=x1  is fast if it really assigns literally x2.  If however it goes
further and evaluates the Sum, and must compute factorials of all the 
integers from 1 to 1000,
then it goes on for a long time. Indeed, if one does a[4]=b[4], then
all 1000 instances of a[i] in Sum have to be checked, I think.

> In practice, I suspect that users would usually require exhaustive
> evaluation of expressions, and would have to code this explicitly, which
> would certainly be slower than letting Mathematica do this job in the
> first place.

My speculation is that users almost never require exhaustive
evaluation of expressions, which is why I asked, and I thank you
for voicing your suspicion -- so lets look at this a little more.

Coding eval-until-no-change in an eval-once system explicitly
is easy, e.g. by
FixedPoint[Eval, expression].  I agree that if the user wanted/needed to
do this all the time and had to write such things all over the
place, that this would probably not be as efficient as if it were 
programmed as part of the system. It would certainly look clumsy.

Can we experiment, though?

I do not know of a way of turning Mathematica into an "eval once"
system -- perhaps there is a way??

If so, I would be very interested in learning what experiences
people might have in this altered system, running their own
large programs.   Realize that if you have at hand a large system
that runs in some other computer algebra system and you convert
it to Mathematica syntax, if it didn't use infinite eval before,
it probably doesn't need it in Mathematica either.

I have had the opposite experience, which is to convert a largish,
but perhaps not totally typical, Mathematica program to an eval-once 
system, and it runs the same. Which is why I raised this issue.

> I do wish that mistakes like x=x+1 gave an explicit error message,
> specifying the variable in question! However, I can't see much value in
> being able to actually store x+1 as the value of x!

Here are 2.
1.  You don't get surprised by an error message when you meant to do 
x=3 .... x=x+1.  but you forgot to initialize x.  You just get the
odd value x+100  instead of 103.

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

note also that x=x+1 is not always so obvious.  e.g.

x=x-f[x]/f'[x]   which someone might think of as a Newton iteration,
has the same kind of problem.  With Mathematica, not other languages.


  • Prev by Date: Notebook interface and Wolfram-Alpha
  • Next by Date: Re: Select from Tuplet using logical expression
  • Previous by thread: Re: evaluation-- one or many levels, your thoughts?
  • Next by thread: Re: evaluation-- one or many levels, your thoughts?