compiling files written in maxima



Maxima can compile Maxima code.  Try this experiment:

---file g.mac---------------

g(x,n):= block([s],modedeclare(x,float,s,float,i,fixnum,n,fixnum),s:0.0,for
i thru n do  s:s+sin(i*x),s);

---------------------------
(%i1) load("c:/maxima/g.mac")$
(%i2) showtime : all$
(%i3) g(0.1,100000);
Evaluation took 2.12 seconds (2.12 elapsed)
(%o3) 19.352475814766755

(%i4) compile_file("c:/maxima/g.mac")$

(%i5) load("c:/maxima/g.o")$

(%i6) g(0.1,100000);
Evaluation took 0.10 seconds (0.10 elapsed)
(%o6) 19.352475814766755

Notes:

(0) If you read Common Lisp, you can look at the translated
Lisp code --- try translate_file().

(1) The modedeclare statement is important for compiled code.

(2) Compiling can greatly speed numerical code; for mostly
symbolic code, the speed up is not great.

(3) There are some differences between compiled and uncompiled
code -- be careful. In the past few days, several fixes
have been made to the translator.

Barton