On 7/7/06, Raindrop <cmoucha at raindrop.ws> wrote:
> nest(f,a,b):=block([erg],erg:a, for tmp:0 while tmp<b do (erg:f(erg)),
> return(erg);
>
> With a function f(x):=x^2 or something like that it works quite good,
> but if I give a function like cos, e.g. nest(cos,%pi/4,20), it never comes
> to an end.
I find that the time to evaluate nest(cos, x, n) is proportional to 3^n,
while for something like nest(foo, x, n) (where foo is not a known
function) the time is proportional to n.
I'm pretty sure all the time is spent attempting to simplify the
nested cos expression. I don't know why simplification of nested
cos expressions is so time consuming.
I can't think of any easy way to make it go faster. simp : false;
disables simplfiication, but even if you disabled simplification while
constructing the expression, it would be simplified when it is
returned to the caller. Perhaps the algorithm for simplification of
nested trig expressions can be improved.
HTH
Robert Dodier