MathGroup Archive 2007

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

Search the Archive

Re: NestListEffects function not working in 6.0

  • To: mathgroup at
  • Subject: [mg77059] Re: NestListEffects function not working in 6.0
  • From: Jon Davis <jon_davis at>
  • Date: Sat, 2 Jun 2007 04:16:22 -0400 (EDT)
  • References: <f3ofsh$p6j$>

Sorry about the lack of specificity regarding problems in my last post. 
More details on my problem with NestListEffects follow.

The NestListEffects function is basically an enhanced version of 
NestList. It does the same thing as NestList (applies a function f to 
an expression n times). It also does some other nifty stuff. For 
example, if I pass SideEffects -> {{printCounter, 10}} to 
NestListEffects as the opts___ argument, then the function prints out 
the number of iterations completed as NestList runs. For example, if n 
is 200 and SideEffects ->{{printCounter, 10}}, then I'll get a count 
output every 10 iterations of NestList. That is,  in the notebook as 
NestList is processing, the numbers 0 10 20 ... 200 will print, 
sequentially, as the 200 steps are completed. This is very handy for 
complex functions and large data sets because it can take several hours 
for a simulation to complete and I can see how far things have 

NestListEffects worked in Mathematica 4.0 for sure. It doesn't seem to 
work in Mathematica 6.0. The simulations run correctly, so NestList is 
still properly applied. However, the numbers don't print out every 10 
iterations of the simulation...

Hope this helps!

On 2007-06-01 01:55:13 -0500, Jon Davis <jdavis at> said:

> I'm coming back to Mathematica after a couple of years and I just
> upgraded to 6.0. I have relied on a function for quite awhile that I
> got from a book by Richard Gaylord and Louis D'Andria titled
> "Simulating Society".  The function is very useful for agent-based
> simulations and for some reason, it doesn't seem to work in version
> 6.0... No incompatibilities are identified by the version advisory
> scanner, so I'm not sure what to do. Can anyone help? Functions follow.
> Any help is deeply appreciated!!! I can provide a notebook with example
> usage on request.
> NestListEffects::usage = "NestListEffects[f, expr, n, ReturnValues =E2=86=
> =92
> {g, k}] returns a list of every kth element of NestList[f, expr, n]
> after the application of g. NestListEffects[f, expr, n, SideEffects =E2=86=
> =92
> {{g1, k1}, {g2, k2},...}] applies gi after every ki steps, but does not
> effect return values.";
> ReturnValues::usage = "ReturnValues is an option to NestListEffects
> that determines what is returned and how often.";
> SideEffects::usage = "SideEffects is an option to NestListEffects that
> applies functions without effecting return values. The option
> SideEffects does not affect return values";
> Options[NestListEffects]={ReturnValues-> {#&, 1}, SideEffects-> {}};
> NestListEffects[f_, expr_, n_, opts___]:= If[({ReturnValues,
> SideEffects} /. {opts} /. Options[NestListEffects]) === {{#&, 1}, {=
> }},
> NestList[f, expr, n],
>    (* else *)
>    Module[{c = 0, lis = {}, side, ret}, {ret, side} = {ReturnValues=
> ,
> SideEffects} /. {opts} /. Options[NestListEffects];
>     If[side === {}, side = {{Null, Infinity}}];
>     Nest[( If[Mod[c, ret[[-1]]] === 0, lis = Join[lis, {First[ret=
> ][#, c]}]];
>          Table[If[Mod[c, side[[i, -1]]] === 0, side[[i, 1]][#, c]],=
>  {i,
> Length[side]}];
>          c++;
>          #)&[f[#]]&, expr, n];
>     lis]
>    ];

  • Prev by Date: Re: curved arrows
  • Next by Date: Re: How-to's in v6 ???
  • Previous by thread: Re: NestListEffects function not working in 6.0
  • Next by thread: Re: NestListEffects function not working in 6.0