[Maxima] Efficient Lisp functions -- using results of symbolic calculations numerically
robert.dodier at gmail.com
Fri Aug 31 19:55:02 CDT 2007
On 8/31/07, Bruno Daniel <bruno.daniel at gmx.net> wrote:
> #'(LAMBDA (X)
> (DECLARE (TYPE DOUBLE-FLOAT X) (VALUES DOUBLE-FLOAT)
> (OPTIMIZE (SPEED 3) (SPACE 0) (SAFETY 0) (DEBUG 0)))
> (+ (* 2 (COS (EXPT X 2))) (- (* (/ (EXPT X 2)) (SIN (EXPT X 2))))))
Bruno, as mentioned by Stavros, the Maxima-to-Lisp translator
can exploit some declarations to generate faster Lisp code.
Here is an example.
Without declaration for x:
#<FUNCTION $G ($X) (DECLARE (IN-DEFUN $G) (SPECIAL $X))
(ADD* (MUL* 2 (SIMPLIFY (LIST '(%COS) (POWER $X 2))))
(*MMINUS (MUL* (POWER $X -2) (SIMPLIFY (LIST '(%SIN) (POWER $X 2)))))))>
With declaration for x:
#<FUNCTION $H ($X) (DECLARE (IN-DEFUN $H) (SPECIAL $X) (FLONUM $X))
(PROGN NIL (+ (* 2.0 (COS (EXPT$ $X 2))) (- (* (EXPT$ $X -2) (SIN
(EXPT$ $X 2)))))))>
The code generated for h is not so different from the code you
showed, and it runs just a little bit slower.
The Maxima translator has some known bugs, and hasn't received
much attention lately. Perhaps you would be interested in fixing
up the translator. That would be useful to many people.
More information about the Maxima