33 |
|
|
34 |
val evaluate : polynomial * int -> Rational.rat |
val evaluate : polynomial * int -> Rational.rat |
35 |
|
|
36 |
|
(* some standard kernels *) |
37 |
|
val tent : kernel (* linear interpolation *) |
38 |
|
val ctmr : kernel (* Catmull-Rom interpolation *) |
39 |
|
val bspl3 : kernel (* cubic bspline reconstruction, doesn't interpolate *) |
40 |
|
val bspl5 : kernel (* quintic bspline reconstruction, doesn't interpolate *) |
41 |
|
|
42 |
end = struct |
end = struct |
43 |
|
|
44 |
structure R = Rational |
structure R = Rational |
48 |
|
|
49 |
type coefficient = R.rat |
type coefficient = R.rat |
50 |
|
|
51 |
val zero = R.fromInt 0 |
val zero = R.zero |
52 |
val one = R.fromInt 1 |
val one = R.fromInt 1 |
53 |
|
|
54 |
(* polynomial represented as list of coefficients, where ith element is |
(* polynomial represented as list of coefficients, where ith element is |
88 |
} |
} |
89 |
|
|
90 |
(* determine if a list of polynomials represents a continuous piece-wise polynomial *) |
(* determine if a list of polynomials represents a continuous piece-wise polynomial *) |
91 |
fun isContinuous polys = let |
fun isContinuous [_] = true |
92 |
|
| isContinuous (f0::r) = let |
93 |
fun chk (i, f_i, []) = (R.zero = evaluate(f_i, i)) |
fun chk (i, f_i, []) = (R.zero = evaluate(f_i, i)) |
94 |
| chk (i, f_i, f_i1::r) = let |
| chk (i, f_i, f_i1::r) = let |
95 |
val y_i = evaluate(f_i, i) |
val y_i = evaluate(f_i, i) |
97 |
in |
in |
98 |
if (y_i = y_i1) |
if (y_i = y_i1) |
99 |
then chk(i+1, f_i1, r) |
then chk(i+1, f_i1, r) |
100 |
else false |
else |
101 |
end |
end |
102 |
in |
in |
103 |
case polys of (f0::r) => chk (0, f0, r) | _ => true |
chk (1, f0, r) |
104 |
end |
end |
105 |
|
|
106 |
(* kernel name *) |
(* kernel name *) |
116 |
(* compute the (k+1)'th derivative, given the k'th *) |
(* compute the (k+1)'th derivative, given the k'th *) |
117 |
fun diff (k, {isOdd, isCont, segs}) = let |
fun diff (k, {isOdd, isCont, segs}) = let |
118 |
val segs' = List.map differentiate segs |
val segs' = List.map differentiate segs |
119 |
val isOdd = not isOdd |
val isOdd' = not isOdd |
120 |
|
val isCont' = if isCont andalso isContinuous segs' |
121 |
|
then (not isOdd') orelse (evaluate(List.hd segs', 0) = R.zero) |
122 |
|
else false |
123 |
in { |
in { |
124 |
isOdd = not isOdd, |
isOdd = isOdd', |
125 |
isCont = isContinuous segs', |
isCont = isCont', |
126 |
segs = segs' |
segs = segs' |
127 |
} end |
} end |
128 |
fun lp (j, curve) = if (j < k) |
fun lp (j, curve) = if (j < k) |