Re: evaluation-- one or many levels, your thoughts?
- To: mathgroup at smc.vnet.net
- Subject: [mg117064] Re: evaluation-- one or many levels, your thoughts?
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Wed, 9 Mar 2011 06:56:47 -0500 (EST)
Working with x=x+1, Newton iterations, etc. is a job for Nest or FixedPoint. Bobby On Tue, 08 Mar 2011 04:34:57 -0600, David Bailey <dave at removedbailey.co.uk> 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. I > have often wondered about this, and I wish Wolfram would devote a blog > article to lifting the hood a little about this! > >> >> 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! > > 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. > > It is interesting that you need to resort to such an obscure example! > > I think complete evaluation is desirable because there is no clear > distinction between programming variables and algebraic variables. > 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! > > 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. Furthermore, there is absolutely > no way in which you could change this now, so any discussion seems a > little pointless. > > David Bailey > http://www.dbaileyconsultancy.co.uk > > -- DrMajorBob at yahoo.com