Efficient Lisp functions -- using results of symbolic calculations numerically
Subject: Efficient Lisp functions -- using results of symbolic calculations numerically
From: Raymond Toy (RT/EUS)
Date: Fri, 07 Sep 2007 13:07:59 -0400
Robert Dodier wrote:
>
> h(x):=(mode_declare(x,float),2*cos(x^2)-sin(x^2)/x^2)$
> translate (h);
> :lisp #'$h
> =>
> #<FUNCTION $H ($X) (DECLARE (IN-DEFUN $H) (SPECIAL $X) (FLONUM $X))
> (BLOCK $H
> (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.
>
It would probably help a bit more if Lisp actually knew what a flonum
type was. :-) When I compile this with cmucl, it complains that flonum
is an unknown type. We probably need to add (deftype flonum ()
'double-float) somewhere.
Ray