# [Maxima] How to speed up programs by compiling

Richard Hennessy rich.hennessy at verizon.net
Sat Sep 5 16:25:30 CDT 2009

```> 1. Extra calls to simplify are probably not as expensive as they might appear.
> The reason is, the first thing that simplify does is it asks "is this already simplified?"
> and if so, it returns.
>

That is good to know thanks.

> 2. Compiling of programs that do mostly double-precision floating point arithmetic may be
> substantially sped up, with extra declarations, some luck, and a good underlying Lisp compiler.
> Declaring items as "number" is probably not saving time, since the Lisp system must call a subroutine
> to do arithmetic on "numbers" anyway.  There are too many different kinds of numbers.
>

I want my case to work fast with symbolic not numeric inputs.

> 3. Compiling of programs that spend most of their time in routines that are already compiled (like integration)
> will not result in much of a speedup.
>

The problem I am working on has about 55 seconds that are spent inside integrate.

> 4. Rewriting code for speed is more productive if it is based on profiling data which shows where
> the time is being spent.
>
Yes, I have not determined yet the most offending parts of my code, besides integrate there must be something else.  The total time is about 5 minutes, integrate take up just one minute approximately.  I need to do this, sorry.

> 5. I don't understand how a lot of time is spent in integrating a polynomial.  I find that
> integration of a dense polynomial of degree 50 takes between 0 and 0.05 sec.   What kind of
> example are you trying to speed up?
>

55.40 seconds inside integrate, 294 seconds total.

Here is the example.

assume(a>0,b<0,c>0);
define(p(x), ((3*b*x^2+3*c)*signum(x+a)+(-3*b*x^2-3*c)*signum(x-a))/(12*a*c+4*a^3*b));
define(dc(x), pwdefint(p(p)*p(x-p),p,minf,inf))\$
for i : 1 thru 15 do define(dc(x), pwdefint(dc(p)*p(x-p),p,minf,inf));

> RJF

Richard Hennessy wrote:
I got poly_int to be about the same speed (compiled) as integrate now without having to resort to Lisp coding.  There seems to be no
point to including it in pw.mac since the idea was to get a screaming fast pwdefint() function.  I will add it anyway so if anyone
has the time to look at it and suggest changes I will be happy with that.

Rich

----- Original Message -----
From: "Richard Hennessy" <rich.hennessy at verizon.net>
Cc: "Maxima List" <maxima at math.utexas.edu>
Sent: Friday, September 04, 2009 6:27 PM
Subject: Re: [Maxima] How to speed up programs by compiling

Well, I guess I am on my own with this.  I will try to write my own version of this function directly in Lisp bypassing the
compiler.

Rich

----- Original Message -----
From: "Richard Hennessy" <rich.hennessy at verizon.net>
To: "Barton Willis" <willisb at unk.edu>
Cc: "Maxima List" <maxima at math.utexas.edu>; <maxima-bounces at math.utexas.edu>
Sent: Friday, September 04, 2009 2:24 PM
Subject: Re: [Maxima] How to speed up programs by compiling

I have noticed that in the lisp code there are a lot of calls to simplify, maybe some of them are unnecessary?  Also mode_declare
does help by improving speed to about 2/3 of the original execution time, but integrate was about 6 times faster.  The exponents are
numbers usually so I declared them as number.  Other variables are possibly symbols so I said mode_declare([x1,x2,...], any).

----- Original Message -----
From: "Barton Willis" <willisb at unk.edu>
To: "Richard Hennessy" <rich.hennessy at verizon.net>
Cc: "Maxima List" <maxima at math.utexas.edu>; <maxima-bounces at math.utexas.edu>
Sent: Friday, September 04, 2009 1:01 PM
Subject: Re: [Maxima] How to speed up programs by compiling

Try searching the mailing list archives using something like "compile
speed up"; for example

http://www.math.utexas.edu/pipermail/maxima/2006/003524.html

An easy way to search the Maxima mailing list is from

http://maxima.sourceforge.net/maximalist.html

Barton

maxima-bounces at math.utexas.edu wrote on 09/04/2009 11:14:25 AM:

[image removed]

[Maxima] How to speed up programs by compiling

Richard Hennessy

to:

Maxima List

09/04/2009 11:14 AM

Sent by:

maxima-bounces at math.utexas.edu

How can you make a program run faster by compiling?  I have tried to
compile functions in pw.mac and it does not improve speed even
though I thought it should.  For example I wrote a simple polynomial
integrator program which I was going to put into pw.mac because
I thought an integrate program that can only do polynomials would be
faster than one that has to consider all possibilities but when
I test it it is still slower the Maximas' integrate.  I tried
compiling it and got no improvement.  What am I doing wrong?

Rich

_______________________________________________
Maxima mailing list
Maxima at math.utexas.edu
http://www.math.utexas.edu/mailman/listinfo/maxima

_______________________________________________
Maxima mailing list
Maxima at math.utexas.edu
http://www.math.utexas.edu/mailman/listinfo/maxima

_______________________________________________
Maxima mailing list
Maxima at math.utexas.edu
http://www.math.utexas.edu/mailman/listinfo/maxima

--------------------------------------------------------------------------------

_______________________________________________
Maxima mailing list
Maxima at math.utexas.edu
http://www.math.utexas.edu/mailman/listinfo/maxima
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.math.utexas.edu/pipermail/maxima/attachments/20090905/2f9c2fbf/attachment-0001.htm
```