[Maxima] Conditional inside a block not working
william.wood3 at comcast.net
Sun Apr 13 12:58:49 CDT 2008
On Sun, 2008-04-13 at 13:02 -0400, Stavros Macrakis wrote:
> On Sun, Apr 13, 2008 at 12:43 PM, Bill Wood <william.wood3 at comcast.net> wrote:
> > There must be a lot of overhead in the maxima-to-lisp translations of
> > functions. I compiled foo and then ran "foo(5000000)" -- it took 2
> > minutes wall time. My lisp version (CMUCL) using my own implementation
> > of power_mod took 15 sec. after compilation.
> Partly there is indeed some extra overhead.. But partly it's simply
> because the translator tries to respect Maxima semantics, which means
> that the general case of symbolic values must be handled, f(x) where f
> is undefined returns f(x) not an error, etc. In your example, the
> translator has no way of knowing that "bound" is an integer value, for
> example. And power_mod is not declared internally as an
> integer-valued function (this is a bug).
> Try declaring your variables and functions as integer-valued and see
> how much that helps:
> foo(bound) := block([m],
> modedeclare([m,bound,function(power_mod)],integer), ...
> Let us know,
Hoo boy! After adding the mode declaration and compiling it now runs in
(wall time) essentially the same time as my compiled lisp version -- ca.
16 sec. (BTW that's about three times faster than my Python version.
Speed's not everything, but whacking the competition is good
Thanks for the suggestion,
-- Bill Wood
More information about the Maxima