[Maxima] compilation speeds
Thu Nov 16 09:38:35 CST 2006
On Thu, 2006-11-16 at 06:58 -0600, Barton Willis wrote:
. . .
> Compiling a Maxima function does remove tail-recursion. (Maybe CL
> isn't required to do this, but GCL does.) Removing tail-recursion
> allows a recursively defined function to handle larger data:
By "removing tail-recursion" you mean transforming tail-recursion into
> (%i1) sumlist(l) := if l =  then 0 else first(l) + sumlist(rest(l))$
> (%i2) p : makelist((-1)^k,k,1,1000)$
> (%i3) sumlist(p);
> Error in PROGN [or a callee]: Bind stack overflow.
But, this function isn't tail-recursive, that is, the recursive call to
sumlist is not what is known as a tail call, since further work (the
addition) is done on the result returned by the recursive call.
A tail-recursive version of sumlist would look more like
sumlist( l, a ) := if l =  then a else sumlist( rest(l), a + first(l)
with line (%i3) changed to "sumlist( p, 0 )"
(please forgive any syntactic errors; I haven't studied the maxima
programming language syntax yet, so I'm winging it).
> Let's compile and re-try:
> (%i4) compile(sumlist)$
> (%i5) sumlist(p);
> (%o5) 0
> So even when the Maxima translator isn't able to speed things up, sometimes
> there is an advantage to compiling Maxima code.
This apparently depends critically on which Common Lisp your maxima was
built with, since I can't duplicate your error with your data; I'm using
-- Bill Wood
More information about the Maxima