Re: need performance tips

"Andrew K. Wolven" <[email protected]> Sun, 24 Sep 2006 17:39:48 -0500
Newsgroups gmane.lisp.allegro
Message-ID <00b901c6e02a$5825ac30$0d00a8c0@Schmazelshmox>
I need to get a copy of the Jaluria book that the fortran came from, 
honestly, I am not sure anymore what the function "derivative" is actually 
doing.  (something lost in the translation) I am working this all out on 
paper so I know what is going on.

I will however, use lists and recursion where logical and iteration where 
logical.  Forgetting fortran and working the entire solution as a lisp 
problem is the best way to go.

Thank you for the code, it's not producing the same results as "derivative", 
that could either be a bug in the code or a bad explanation of what is going 
on by my part.

I'll go through this code and figure out what is different.

thanks,
AKW


----- Original Message ----- 
From: "Richard Fateman" <[email protected]>
To: "'Andrew K. Wolven'" <[email protected]>
Cc: <[email protected]>
Sent: Sunday, September 24, 2006 11:43 AM
Subject: RE: need performance tips


>I became curious as to how your task could be done without arrays at all.
> Here's a more lisp-ish solution.
>
> One could add declarations to make everything double-float and compile to
> better code. If you debug it, I'd like to see how it looks. RJF
>
> (defparameter y2 (list 0))
> (defun spline(x y)
>  ;; natural spline on n points.
>
>  ;; take two lists of length n, of (x, y) values for points.
>  ;; x1<x2<x3 ...,  y1=f(x1), etc.
>  ;; return a list of length n which contains the second derivative
>  ;; of the interpolating function. The first and last elements will be 0
>  ;; for a "natural" spline.
>  (let* ((y2 (list 0))
> (u (sp1 (car x)(cadr x)(caddr x)(rest x)
> (car y)(cadr y)(caddr y)(rest y)
> (list 0))))
>    (do ((yy (nreverse y2) (cdr yy))
> (uu (nreverse u) (cdr uu))
> (ans (list 0)  (cons (+ (car uu)(* (car yy)(car ans))) ans)
> ((null yy) ans) )))))
>
> (defun sp1
>  (xim1 xi xip1 morex  yim1 yi yip1 morey  u) ;;x[i-1], x[i], x[i+1] etc
>  (if (null (cdr morex)) (cons 0 u)
>    (let* ((k0 (- xi xim1))(k1 (- xip1 xim1))  (sig (/ k0 k1))
>    (p (+ (* sig (car y2)) 2.0d0)))
>      (push (/ (1- sig) p) y2)
>      (sp1 xi xip1 (caddr morex) (cdr morex)
>    yi yip1 (caddr morey)(cdr morey)
>    (cons (/
>   (* 6.0d0
>      (- (/ (- (/ (- yip1 yi)    (- xip1 xi))
>       (/ (- yi yim1)    k0))
>    k1)
> (* sig (car u))))
>   p)
> u)))))
>
> ;; advantages over fortran..
> ;; answer is allocated storage as needed.
> ;; I don't know if the formulas are quite right.
>
> ;; spline-interpolate could also use lists. e.g. if you took a
> ;; list of new x-values, sorted them, and returned a list of new y-values.
>
>
>