Discussion:
compiling files written in maxima
Miguel Marco
2005-12-13 12:27:00 UTC
Permalink
If i understand well the structure of Maxima, it is essentially a lisp
interpreter with a layer that translates the syntax to the user interface,
and a big set of predefined functions.
In that situation, it seems that it wouldn't be difficult to compile a .mac
file into an executable one (since it is internally a lisp program). It would
improve dramatically it's speed, which could be usefull for very long
calculations.

Is there any implemented feature like this? If not, i suggest it to be
considered for future versions (actually, it could make a huge difference
between MAxima and other CAS; many users would switch to Maxima just because
of this).




Miguel Angel Marco Buzunariz
Departamento de matemáticas
Universidad de Zaragoza
Barton Willis
2005-12-13 13:08:56 UTC
Permalink
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(<file name>).

(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
Stavros Macrakis
2005-12-13 18:57:17 UTC
Permalink
Post by Miguel Marco
If i understand well the structure of Maxima, it is essentially a lisp
interpreter with a layer that translates the syntax to the user interface,
and a big set of predefined functions.
That is almost correct. The Maxima language is similar to Lisp in
many ways, but it is not Lisp. The external form of Maxima is
translated into an internal form, and that is interpreted by Maxima's
own language interpreter, which has somewhat different semantics, most
notably that a symbol or a function without a value evaluates to
itself rather than giving an error, and that simplification is called
after evaluation. (But there are many other, more subtle,
differences.)

And as you say, there is a large library of predefined functions.

There is a translator that can translate Maxima language programs into
Lisp (translate) and a compiler that will first translate into Lisp
and then compile the resulting Lisp. See Barton's email for more
information about that.

In numerical calculations, this can make for a huge increase in speed
(especially with correct declarations). For symbolic calculations,
most time is spent inside the simplifier and other libraries, and the
speedup will be less, often even negligeable.

-s

Continue reading on narkive:
Search results for 'compiling files written in maxima' (Questions and Answers)
4
replies
Combining two C++ programs?
started 2013-04-16 18:11:03 UTC
programming & design
Loading...