Awefully confused about how to write interpolation routines



On Sun, Dec 18, 2005 at 03:34:24PM -0800, Richard Fateman wrote:

> oh, if you returned the lambda([x], stuff(x))  result, you
> could get stuff(x)  or stuff(z)  just by applying it to a
> symbolic argument. So they are kind closely related, and which
> one you actually return is sort of arbitrary -- what do you
> want?
> 
> RJF

Here's the code I have. It does return the lambda([x],...) result but
if I try to apply it to a symbolic argument, then it complains about
not being able to evaluate the predicate x < first(xx).

however, I can do this:

foo: linterp([1,2,3],[2,4,8]); 

second(foo); /* returns the body of the lambda*/

foo(1.5); /* returns the interpolated value 3.0 */

------------------------------ code below ---------------------

linterp(xs,ys) := sublis(['xs=xs,'ys=ys],lambda([x],
    (block([xx:xs,yy:ys],
        if (x < first(xx)) then error(x, " is below valid range in linterp")
        else
        do
        (/*print(xx," ",yy),*/
          if(x > first(xx) and rest(xx) # [] and x > second(xx) ) then
          
          (xx:rest(xx), yy:rest(yy) )
          else
          if(rest(xx) # [] ) then
          return(first(yy) + (second(yy) - first(yy))/ (second(xx) - first(xx)) * (x - first(xx)))
          else if (x = first(xx)) then return(first(yy)) else
          error(x, " is above valid range in linterp"))))));
        
/*
foo : linterp(makelist(i,i,1,10),map(lambda([x],x^2),makelist(i,i,1,10)));
*/




-- 
Daniel Lakeland
dlakelan@street-artists.org
http://www.street-artists.org/~dlakelan