Ryan Adams wrote:

> I am writing an extremely floating-point-intensive application, that
> requires the evaluation of a polynomial (not finding the roots, just
> substituting) that is not known at compile time (in the C++ sense of
> "compile time").  Any particular polynomial evaluation is performed
> around 25,000 times with different substituted values, before moving to
> another polynomial.  As you might expect, these evaluations seem to be
> the limiting factors in the code execution.
> 
> As the evaluation is not known until runtime, there is a good deal of
> control code surrounding the actual floating-point computations.  It
> would seem that with Lisp, and CMUCL in particular, that I could compile
> a function on the fly for the particular polynomial evaluation, thereby
> eliminating all of the inner-loop control code, and also allow for
> possible optimizations.

Bad idea.


(defun make-polynomial (v-coeffs)
  (declare (optimize (safety 0) (speed 3)))
  (let* ((v-coeffs (coerce v-coeffs '(simple-array double-float (*))))
         (nr-coeffs (length v-coeffs)))
    #'(lambda (x)
        (declare (double-float x))
        (labels
            ((walk (val n)
               (declare (double-float val) (fixnum n))
               (if (= n nr-coeffs)
                   val
                 (walk (+ (aref v-coeffs n) (* val x)) (1+ n)))))
          (walk 0.0d0 0)))))


P.S.: greet Jerry Sussman from me when you meet him...


-- 
regards,               [EMAIL PROTECTED]              (o_
 Thomas Fischbacher -  http://www.cip.physik.uni-muenchen.de/~tf  //\
(lambda (n) ((lambda (p q r) (p p q r)) (lambda (g x y)           V_/_
(if (= x 0) y (g g (- x 1) (* x y)))) n 1))                  (Debian GNU)

Reply via email to