counting primes



On Sat, Apr 03, 2010 at 05:47:16PM +0100, Leo Butler wrote:
[skipped]
> < Maxima encountered a Lisp error:
> < 
> <  Error in PROGN [or a callee]: Bind stack overflow.
> < 
> < Automatically continuing.
> < To enable the Lisp debugger set *debugger-hook* to nil.
[skipped]
> < What is the reason?
>  
> The Lisp error message tells you the reason: the recursive calls
> overflow the stack.

Okay, I will reformulate the question: is it a bug in GCL?

> Note that this is dependent on your Lisp. With CMUCL, we can
> compute pi[5000] comfortably.

Well, I can do that too in this Maxima, but for some reason only
gradually. That is, if try it in one step, it fails:

(%i1) pi[n]:=if n = 2 then 1 elseif primep(n) then pi[n-1]+1 else
pi[n-1]$

(%i2) pi[5000];

Maxima encountered a Lisp error:

 Error in PROGN [or a callee]: Bind stack overflow.

Automatically continuing.
To enable the Lisp debugger set *debugger-hook* to nil.

Now, if I restart Maxima and do this, it works:

(%i1) pi[n]:=if n = 2 then 1 elseif primep(n) then pi[n-1]+1 else pi[n-1]$

(%i2) for n: 100 thru 5000 step 100 do print(pi[n]);
25 
46 
62 
...
646 
654 
669

-- 
Stanislav