(* kernel.sml
*
* COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
* All rights reserved.
*)
structure Kernel : sig
type coefficient = FloatLit.float
(* polynomial represented as list of coefficients, where ith element is
* coefficient for x^i.
*)
type polynomial = coefficient list
type kernel = {
support : int, (* number of samples to left/right *)
segs : polynomial list, (* piece-wise polynomial that defines the *)
(* kernel; there are 2*support segments *)
}
val differentiate : polynomial -> polynomial
val evaluate : polynomial * int -> FloatLit.float
end = struct
structure F = FloatLit
type coefficient = F.float
(* polynomial represented as list of coefficients, where ith element is
* coefficient for x^i.
*)
type polynomial = coefficient list
type kernel = {
support : int, (* number of samples to left/right *)
segs : polynomial list, (* piece-wise polynomial that defines the *)
(* kernel; there are 2*support segments *)
}
fun differentiate [] = raise Fail "invalid polynomial"
| differentiate [_] = [F.zero]
| differentiate (_::coeffs) = let
fun lp (_, []) = []
| lp (i, c::r) = F.mul(F.fromInt i, c) :: lp(i+1, r)
in
lp (1, coeffs)
end
(* evaluate a polynomial at an integer coordinate (used to test continuity) *)
fun evaluate (poly, x) = let
val x = F.fromInt x
fun eval (sum, [], xn) = sum
| eval (sum, c::r, xn) = eval(F.add(sum, F.mul(c, xn)), r, F.mul(x, xn))
in
eval (F.zero, poly, F.one)
end
end