On 10/11/2011 7:44 AM, Akshay Srinivasan wrote:
> Hello,
> I've been going the round-about way for my mechanics problems,
> doing symbolics in Maxima, generating code for solving the thus
> obtained ODE by C through Lisp/Python, then doing visualisation in
> LISP with cl-opengl.
> I'm not all that experienced with Lisp (or Maxima for that
> matter!) yet, but I sense that I can generate code on the fly using
> macros. I know maxima has a lisp mode; but from what I've seen, it
> does not strike me as a particularly clean interface; by "clean", I
> mean something like Sussman and Wisdom's scmutils.
It is more accurate to say that Maxima is written in Lisp, not that it
has a lisp mode. If you want to invoke a fast numeric program from
Maxima, you can write a program in lisp.
e.g.
to compute f(x):=x^2-0.5 fast, write the lisp program
:lisp (defun $f(x)(- (* x x) 0.5))
and call it from Maxima, e.g. f(3.0) is 8.5.
You can make f run faster this way..
:lisp (defun $f(x) (declare (double x)(optimize (speed 3)(safety
0))) (- (* x x) 0.5d0))
and :lisp (compile '$f).
Now if you want to generate a piece of code using an expression computed
in Maxima, you have some options.
One of them is to use the compile command in Maxima. In which case it
also helps to have mode_declares in place. This command converts the
Maxima stuff into Lisp stuff and then into machine language. It is not
usually so efficient because the possibility that something "symbolic"
may be left in there has to be entirely eliminated before one can
generate really good numeric code.
And yes, there is a macro construction mechanism in Maxima tha is
sometimes useful.
> I can probably do something like replace maxima's function tags in
> the expression list with the usual operators and put it inside a
> function definition; but is there a better interface for Lisp ?
unclear what you are trying here. Can you give an example?
> Is there a better way of going about this ? Has someone done something
> like this before with Maxima - so that I can steal their code :) ?
>
There's stuff like gentran (unsupported?) and f2cl. Maybe other stuff.
> Cheers,
> Akshay
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima