| 1 |
(* ========================================================================== *) |
| 2 |
(* Formal verification of nonlinear inequalities in HOL Light *) |
| 3 |
(* *) |
| 4 |
(* Copyright (c) 2012 Alexey Solovyev *) |
| 5 |
(* *) |
| 6 |
(* This file is distributed under the terms of the MIT licence *) |
| 7 |
(* ========================================================================== *) |
| 8 |
|
| 9 |
(* -------------------------------------------------------------------------- *) |
| 10 |
(* Informal taylor intervals *) |
| 11 |
(* -------------------------------------------------------------------------- *) |
| 12 |
|
| 13 |
(* Dependencies *) |
| 14 |
needs "Formal_ineqs/misc/misc_functions.hl";; |
| 15 |
needs "Formal_ineqs/informal/informal_eval_interval.hl";; |
| 16 |
|
| 17 |
|
| 18 |
module Informal_taylor = struct |
| 19 |
|
| 20 |
open Misc_functions;; |
| 21 |
open Informal_interval;; |
| 22 |
open Informal_float;; |
| 23 |
open Informal_exp;; |
| 24 |
open Informal_log;; |
| 25 |
open Informal_atn;; |
| 26 |
open Informal_asn_acs;; |
| 27 |
open Informal_sin_cos;; |
| 28 |
open Informal_matan;; |
| 29 |
open Informal_eval_interval;; |
| 30 |
|
| 31 |
|
| 32 |
type m_cell_domain = |
| 33 |
{ |
| 34 |
lo : ifloat list; |
| 35 |
hi : ifloat list; |
| 36 |
y : ifloat list; |
| 37 |
w : ifloat list; |
| 38 |
};; |
| 39 |
|
| 40 |
|
| 41 |
type m_taylor_interval = |
| 42 |
{ |
| 43 |
n : int; |
| 44 |
domain : m_cell_domain; |
| 45 |
f : interval; |
| 46 |
df : interval list; |
| 47 |
ddf : interval list list; |
| 48 |
};; |
| 49 |
|
| 50 |
|
| 51 |
let float_0 = mk_small_num_float 0 and |
| 52 |
float_1 = mk_small_num_float 1 and |
| 53 |
float_2 = mk_small_num_float 2;; |
| 54 |
|
| 55 |
let float_inv2 = div_float_lo 1 float_1 float_2;; |
| 56 |
|
| 57 |
(* convert_to_float_list *) |
| 58 |
let convert_to_float_list pp lo_flag list_tm = |
| 59 |
let tms = dest_list list_tm in |
| 60 |
let i_funs = map build_interval_fun tms in |
| 61 |
let ints = map (fun f -> eval_interval_fun pp f [] []) i_funs in |
| 62 |
let extract = (if lo_flag then fst else snd) o dest_interval in |
| 63 |
map extract ints;; |
| 64 |
|
| 65 |
|
| 66 |
(* mk_m_center_domain *) |
| 67 |
let mk_m_center_domain pp x_list z_list = |
| 68 |
let y_list = |
| 69 |
let ( * ), (+) = mul_float_eq, add_float_hi pp in |
| 70 |
map2 (fun x z -> if eq_float x z then x else float_inv2 * (x + z)) x_list z_list in |
| 71 |
|
| 72 |
(* test: x <= y <= z *) |
| 73 |
let flag1 = itlist2 (fun x y a -> le_float x y && a) x_list y_list true and |
| 74 |
flag2 = itlist2 (fun y z a -> le_float y z && a) y_list z_list true in |
| 75 |
if not flag1 || not flag2 then |
| 76 |
failwith "mk_m_center_domain: ~(x <= y <= z)" |
| 77 |
else |
| 78 |
let w_list = |
| 79 |
let (-) = sub_float_hi pp in |
| 80 |
let w1 = map2 (-) y_list x_list in |
| 81 |
let w2 = map2 (-) z_list y_list in |
| 82 |
map2 max_float w1 w2 in |
| 83 |
{lo = x_list; hi = z_list; y = y_list; w = w_list};; |
| 84 |
|
| 85 |
|
| 86 |
(* eval_m_taylor (pp0 for initial evaluation of constants) *) |
| 87 |
let eval_m_taylor pp0 f_tm partials partials2 = |
| 88 |
let build = eval_constants pp0 o build_interval_fun o snd o dest_abs in |
| 89 |
let f = build f_tm in |
| 90 |
let n = length partials in |
| 91 |
(* Verify that the list of second partial derivatives is correct *) |
| 92 |
let _ = map2 (fun i list -> if length list <> i then |
| 93 |
failwith "eval_m_taylor: incorrect partials2" else ()) (1--n) partials2 in |
| 94 |
let dfs = map (build o rand o concl) partials in |
| 95 |
let d2fs = map (build o rand o concl) (List.flatten partials2) in |
| 96 |
let f_dfs_list = find_and_replace_all (f :: dfs) [] in |
| 97 |
let rec shape_list dd i = |
| 98 |
if i >= n then [dd] else |
| 99 |
let l1, l2 = chop_list i dd in |
| 100 |
l1 :: shape_list l2 (i + 1) in |
| 101 |
let d2fs_list = find_and_replace_all d2fs [] in |
| 102 |
fun p_lin p_second domain -> |
| 103 |
let y_ints = map (fun y -> mk_interval (y, y)) domain.y in |
| 104 |
let xz_ints = map mk_interval (zip domain.lo domain.hi) in |
| 105 |
let f_dfs_vals = eval_interval_fun_list p_lin f_dfs_list y_ints in |
| 106 |
let d2fs_vals = eval_interval_fun_list p_second d2fs_list xz_ints in |
| 107 |
{n = n; domain = domain; |
| 108 |
f = hd f_dfs_vals; df = tl f_dfs_vals; |
| 109 |
ddf = shape_list d2fs_vals 1};; |
| 110 |
|
| 111 |
|
| 112 |
(* mk_eval_function *) |
| 113 |
let mk_eval_function pp0 f_tm = |
| 114 |
let build = eval_constants pp0 o build_interval_fun o snd o dest_abs in |
| 115 |
let f = build f_tm in |
| 116 |
let f_list = find_and_replace_all [f] [] in |
| 117 |
fun pp x_list z_list -> |
| 118 |
let xz_ints = map mk_interval (zip x_list z_list) in |
| 119 |
let f_val = eval_interval_fun_list pp f_list xz_ints in |
| 120 |
hd f_val;; |
| 121 |
|
| 122 |
|
| 123 |
(* error_mul_f2_hi *) |
| 124 |
let error_mul_f2_hi pp a int = mul_float_hi pp a (iabs_interval int);; |
| 125 |
|
| 126 |
|
| 127 |
(* eval_m_taylor_error *) |
| 128 |
(* sum_{i = 1}^n (w_i * (f_ii * w_i + 2 * sum_{j = 1}^{i - 1} w_j * f_ij)) *) |
| 129 |
let eval_m_taylor_error pp ti = |
| 130 |
let w = ti.domain.w in |
| 131 |
let ns = 1--ti.n in |
| 132 |
let ( * ), ( + ) = mul_float_hi pp, add_float_hi pp in |
| 133 |
let mul_wdd = map2 (fun list i -> my_map2 (error_mul_f2_hi pp) w list) ti.ddf ns in |
| 134 |
let sums1 = map (end_itlist ( + ) o butlast) (tl mul_wdd) in |
| 135 |
let sums2 = (hd o hd) mul_wdd :: map2 (fun list t1 -> last list + float_2 * t1) (tl mul_wdd) sums1 in |
| 136 |
let sums = map2 ( * ) w sums2 in |
| 137 |
end_itlist ( + ) sums;; |
| 138 |
|
| 139 |
|
| 140 |
(* eval_m_taylor_upper_bound *) |
| 141 |
let eval_m_taylor_upper_bound pp ti = |
| 142 |
let f_hi = (snd o dest_interval) ti.f in |
| 143 |
let error = eval_m_taylor_error pp ti in |
| 144 |
let ( * ), ( + ) = mul_float_hi pp, add_float_hi pp in |
| 145 |
let sum2 = |
| 146 |
let mul_wd = map2 (error_mul_f2_hi pp) ti.domain.w ti.df in |
| 147 |
end_itlist ( + ) mul_wd in |
| 148 |
let a = sum2 + float_inv2 * error in |
| 149 |
f_hi + a;; |
| 150 |
|
| 151 |
(* eval_m_taylor_lower_bound *) |
| 152 |
let eval_m_taylor_lower_bound pp ti = |
| 153 |
let f_lo = (fst o dest_interval) ti.f in |
| 154 |
let error = eval_m_taylor_error pp ti in |
| 155 |
let ( * ), ( + ), ( - ) = mul_float_hi pp, add_float_hi pp, sub_float_lo pp in |
| 156 |
let sum2 = |
| 157 |
let mul_wd = map2 (error_mul_f2_hi pp) ti.domain.w ti.df in |
| 158 |
end_itlist ( + ) mul_wd in |
| 159 |
let a = sum2 + float_inv2 * error in |
| 160 |
f_lo - a;; |
| 161 |
|
| 162 |
|
| 163 |
(* eval_m_taylor_bound *) |
| 164 |
let eval_m_taylor_bound pp ti = |
| 165 |
let f_lo, f_hi = dest_interval ti.f in |
| 166 |
let error = eval_m_taylor_error pp ti in |
| 167 |
let ( * ), ( + ), ( - ) = mul_float_hi pp, add_float_hi pp, sub_float_lo pp in |
| 168 |
let sum2 = |
| 169 |
let mul_wd = map2 (error_mul_f2_hi pp) ti.domain.w ti.df in |
| 170 |
end_itlist ( + ) mul_wd in |
| 171 |
let a = sum2 + float_inv2 * error in |
| 172 |
let hi = f_hi + a in |
| 173 |
let lo = f_lo - a in |
| 174 |
mk_interval (lo, hi);; |
| 175 |
|
| 176 |
|
| 177 |
(* eval_m_taylor_partial_upper *) |
| 178 |
let eval_m_taylor_partial_upper pp i ti = |
| 179 |
let df_hi = (snd o dest_interval o List.nth ti.df) (i - 1) in |
| 180 |
let dd_list = map (fun j -> if j <= i then |
| 181 |
List.nth (List.nth ti.ddf (i - 1)) (j - 1) |
| 182 |
else |
| 183 |
List.nth (List.nth ti.ddf (j - 1)) (i - 1)) (1--ti.n) in |
| 184 |
let sum2 = |
| 185 |
let mul_dd = map2 (error_mul_f2_hi pp) ti.domain.w dd_list in |
| 186 |
end_itlist (add_float_hi pp) mul_dd in |
| 187 |
add_float_hi pp df_hi sum2;; |
| 188 |
|
| 189 |
|
| 190 |
(* eval_m_taylor_partial_lower *) |
| 191 |
let eval_m_taylor_partial_lower pp i ti = |
| 192 |
let df_lo = (fst o dest_interval o List.nth ti.df) (i - 1) in |
| 193 |
let dd_list = map (fun j -> if j <= i then |
| 194 |
List.nth (List.nth ti.ddf (i - 1)) (j - 1) |
| 195 |
else |
| 196 |
List.nth (List.nth ti.ddf (j - 1)) (i - 1)) (1--ti.n) in |
| 197 |
let sum2 = |
| 198 |
let mul_dd = map2 (error_mul_f2_hi pp) ti.domain.w dd_list in |
| 199 |
end_itlist (add_float_hi pp) mul_dd in |
| 200 |
sub_float_lo pp df_lo sum2;; |
| 201 |
|
| 202 |
|
| 203 |
(* eval_m_taylor_partial_bound *) |
| 204 |
let eval_m_taylor_partial_bound pp i ti = |
| 205 |
let df_lo, df_hi = (dest_interval o List.nth ti.df) (i - 1) in |
| 206 |
let dd_list = map (fun j -> if j <= i then |
| 207 |
List.nth (List.nth ti.ddf (i - 1)) (j - 1) |
| 208 |
else |
| 209 |
List.nth (List.nth ti.ddf (j - 1)) (i - 1)) (1--ti.n) in |
| 210 |
let sum2 = |
| 211 |
let mul_dd = map2 (error_mul_f2_hi pp) ti.domain.w dd_list in |
| 212 |
end_itlist (add_float_hi pp) mul_dd in |
| 213 |
let lo = sub_float_lo pp df_lo sum2 in |
| 214 |
let hi = add_float_hi pp df_hi sum2 in |
| 215 |
mk_interval (lo, hi);; |
| 216 |
|
| 217 |
|
| 218 |
(* add *) |
| 219 |
let eval_m_taylor_add p_lin p_second taylor1 taylor2 = |
| 220 |
let ( + ), ( ++ ) = add_interval p_lin, add_interval p_second in |
| 221 |
{ |
| 222 |
n = taylor1.n; |
| 223 |
domain = taylor1.domain; |
| 224 |
f = taylor1.f + taylor2.f; |
| 225 |
df = map2 (+) taylor1.df taylor2.df; |
| 226 |
ddf = map2 (map2 (++)) taylor1.ddf taylor2.ddf |
| 227 |
};; |
| 228 |
|
| 229 |
|
| 230 |
(* sub *) |
| 231 |
let eval_m_taylor_sub p_lin p_second taylor1 taylor2 = |
| 232 |
let ( - ), ( -- ) = sub_interval p_lin, sub_interval p_second in |
| 233 |
{ |
| 234 |
n = taylor1.n; |
| 235 |
domain = taylor1.domain; |
| 236 |
f = taylor1.f - taylor2.f; |
| 237 |
df = map2 (-) taylor1.df taylor2.df; |
| 238 |
ddf = map2 (map2 (--)) taylor1.ddf taylor2.ddf |
| 239 |
};; |
| 240 |
|
| 241 |
|
| 242 |
(* mul *) |
| 243 |
let eval_m_taylor_mul p_lin p_second ti1 ti2 = |
| 244 |
let n = ti1.n in |
| 245 |
let ns = 1--n in |
| 246 |
let bounds = mul_interval p_lin ti1.f ti2.f in |
| 247 |
let df = map2 (fun d1 d2 -> |
| 248 |
let ( * ), ( + ) = mul_interval p_lin, add_interval p_lin in |
| 249 |
d1 * ti2.f + ti1.f * d2) ti1.df ti2.df in |
| 250 |
let d1_bounds = map (fun i -> eval_m_taylor_partial_bound p_second i ti1) ns in |
| 251 |
let d2_bounds = map (fun i -> eval_m_taylor_partial_bound p_second i ti2) ns in |
| 252 |
let f1_bound = eval_m_taylor_bound p_second ti1 in |
| 253 |
let f2_bound = eval_m_taylor_bound p_second ti2 in |
| 254 |
let ddf = |
| 255 |
let ( * ), ( + ) = mul_interval p_second, add_interval p_second in |
| 256 |
map2 (fun (list1, list2) i -> |
| 257 |
let di1 = List.nth d1_bounds (i - 1) in |
| 258 |
let di2 = List.nth d2_bounds (i - 1) in |
| 259 |
map2 (fun (dd1, dd2) j -> |
| 260 |
let dj1 = List.nth d1_bounds (j - 1) in |
| 261 |
let dj2 = List.nth d2_bounds (j - 1) in |
| 262 |
(dd1 * f2_bound + di1 * dj2) + (dj1 * di2 + f1_bound * dd2)) |
| 263 |
(zip list1 list2) (1--i)) (zip ti1.ddf ti2.ddf) ns in |
| 264 |
{ |
| 265 |
n = n; |
| 266 |
domain = ti1.domain; |
| 267 |
f = bounds; |
| 268 |
df = df; |
| 269 |
ddf = ddf; |
| 270 |
};; |
| 271 |
|
| 272 |
(* neg *) |
| 273 |
let eval_m_taylor_neg taylor1 = |
| 274 |
let neg = neg_interval in |
| 275 |
{ |
| 276 |
n = taylor1.n; |
| 277 |
domain = taylor1.domain; |
| 278 |
f = neg taylor1.f; |
| 279 |
df = map neg taylor1.df; |
| 280 |
ddf = map (map neg) taylor1.ddf; |
| 281 |
};; |
| 282 |
|
| 283 |
(* abs *) |
| 284 |
let eval_m_taylor_abs p_second ti = |
| 285 |
let f1_bound = eval_m_taylor_bound p_second ti in |
| 286 |
match (compare0_interval f1_bound) with |
| 287 |
| -1 -> eval_m_taylor_neg ti |
| 288 |
| 1 -> ti |
| 289 |
| _ -> failwith "eval_m_taylor_abs: interval contains 0";; |
| 290 |
|
| 291 |
(* pow2 *) |
| 292 |
let eval_m_taylor_pow2 p_lin p_second ti = |
| 293 |
let n = ti.n in |
| 294 |
let ns = 1--n in |
| 295 |
let f1_bound = eval_m_taylor_bound p_second ti in |
| 296 |
let bounds = pow_interval p_lin 2 ti.f in |
| 297 |
let u_bounds = |
| 298 |
let ( * ) = mul_interval p_lin in |
| 299 |
two_interval * ti.f in |
| 300 |
let df = |
| 301 |
let ( * ) = mul_interval p_lin in |
| 302 |
map (fun d -> u_bounds * d) ti.df in |
| 303 |
let d1_bounds = map (fun i -> eval_m_taylor_partial_bound p_second i ti) ns in |
| 304 |
let ddf = |
| 305 |
let ( * ), ( + ) = mul_interval p_second, add_interval p_second in |
| 306 |
map2 (fun dd_list di1 -> |
| 307 |
my_map2 (fun dd dj1 -> two_interval * (dj1 * di1 + f1_bound * dd)) |
| 308 |
dd_list d1_bounds) ti.ddf d1_bounds in |
| 309 |
{ |
| 310 |
n = n; |
| 311 |
domain = ti.domain; |
| 312 |
f = bounds; |
| 313 |
df = df; |
| 314 |
ddf = ddf; |
| 315 |
};; |
| 316 |
|
| 317 |
(* pow *) |
| 318 |
let eval_m_taylor_pow k = |
| 319 |
if k <= 1 then failwith "Informal.eval_m_taylor_pow: k <= 1" |
| 320 |
else if k = 2 then eval_m_taylor_pow2 |
| 321 |
else |
| 322 |
let k_interval = mk_small_num_interval k in |
| 323 |
let k1_interval = mk_small_num_interval (k - 1) in |
| 324 |
fun p_lin p_second ti -> |
| 325 |
let n = ti.n in |
| 326 |
let ns = 1--n in |
| 327 |
let f1_bound = eval_m_taylor_bound p_second ti in |
| 328 |
let bounds_pow_k1 = pow_interval p_lin (k - 1) ti.f in |
| 329 |
let bounds = |
| 330 |
let ( * ) = mul_interval p_lin in |
| 331 |
ti.f * bounds_pow_k1 in |
| 332 |
let u_bounds = |
| 333 |
let ( * ) = mul_interval p_lin in |
| 334 |
k_interval * bounds_pow_k1 in |
| 335 |
let df = |
| 336 |
let ( * ) = mul_interval p_lin in |
| 337 |
map (fun d -> u_bounds * d) ti.df in |
| 338 |
let d1_bounds = map (fun i -> eval_m_taylor_partial_bound p_second i ti) ns in |
| 339 |
let d2 = |
| 340 |
let ( * ) = mul_interval p_second in |
| 341 |
let pow_k2 = pow_interval p_second (k - 2) in |
| 342 |
k_interval * pow_k2 f1_bound in |
| 343 |
let ddf = |
| 344 |
let ( * ), ( + ) = mul_interval p_second, add_interval p_second in |
| 345 |
map2 (fun dd_list di1 -> |
| 346 |
my_map2 (fun dd dj1 -> d2 * ((k1_interval * dj1) * di1 + f1_bound * dd)) |
| 347 |
dd_list d1_bounds) ti.ddf d1_bounds in |
| 348 |
{ |
| 349 |
n = n; |
| 350 |
domain = ti.domain; |
| 351 |
f = bounds; |
| 352 |
df = df; |
| 353 |
ddf = ddf; |
| 354 |
};; |
| 355 |
|
| 356 |
(* inv *) |
| 357 |
let eval_m_taylor_inv p_lin p_second ti = |
| 358 |
let n = ti.n in |
| 359 |
let ns = 1--n in |
| 360 |
let f1_bound = eval_m_taylor_bound p_second ti in |
| 361 |
let bounds = inv_interval p_lin ti.f in |
| 362 |
let u_bounds = |
| 363 |
let neg, inv, ( * ) = neg_interval, inv_interval p_lin, mul_interval p_lin in |
| 364 |
neg (inv (ti.f * ti.f)) in |
| 365 |
let df = |
| 366 |
let ( * ) = mul_interval p_lin in |
| 367 |
map (fun d -> u_bounds * d) ti.df in |
| 368 |
let d1_bounds = map (fun i -> eval_m_taylor_partial_bound p_second i ti) ns in |
| 369 |
let d1, d2 = |
| 370 |
let inv, ( * ) = inv_interval p_second, mul_interval p_second in |
| 371 |
let ff = f1_bound * f1_bound in |
| 372 |
inv ff, two_interval * inv (f1_bound * ff) in |
| 373 |
let ddf = |
| 374 |
let ( * ), ( - ) = mul_interval p_second, sub_interval p_second in |
| 375 |
map2 (fun dd_list di1 -> |
| 376 |
my_map2 (fun dd dj1 -> |
| 377 |
(d2 * dj1) * di1 - d1 * dd) dd_list d1_bounds) ti.ddf d1_bounds in |
| 378 |
{ |
| 379 |
n = n; |
| 380 |
domain = ti.domain; |
| 381 |
f = bounds; |
| 382 |
df = df; |
| 383 |
ddf = ddf; |
| 384 |
};; |
| 385 |
|
| 386 |
|
| 387 |
(* sqrt *) |
| 388 |
let eval_m_taylor_sqrt p_lin p_second ti = |
| 389 |
let n = ti.n in |
| 390 |
let ns = 1--n in |
| 391 |
let f1_bound = eval_m_taylor_bound p_second ti in |
| 392 |
let bounds = sqrt_interval p_lin ti.f in |
| 393 |
let u_bounds = |
| 394 |
let inv, ( * ) = inv_interval p_lin, mul_interval p_lin in |
| 395 |
inv (two_interval * bounds) in |
| 396 |
let df = |
| 397 |
let ( * ) = mul_interval p_lin in |
| 398 |
map (fun d -> u_bounds * d) ti.df in |
| 399 |
let d1_bounds = map (fun i -> eval_m_taylor_partial_bound p_second i ti) ns in |
| 400 |
let d1, d2 = |
| 401 |
let neg, sqrt, inv, ( * ) = neg_interval, sqrt_interval p_second, |
| 402 |
inv_interval p_second, mul_interval p_second in |
| 403 |
let two_sqrt_f = two_interval * sqrt f1_bound in |
| 404 |
inv two_sqrt_f, neg (inv (two_sqrt_f * (two_interval * f1_bound))) in |
| 405 |
let ddf = |
| 406 |
let ( * ), ( + ) = mul_interval p_second, add_interval p_second in |
| 407 |
map2 (fun dd_list di1 -> |
| 408 |
my_map2 (fun dd dj1 -> |
| 409 |
(d2 * dj1) * di1 + d1 * dd) dd_list d1_bounds) ti.ddf d1_bounds in |
| 410 |
{ |
| 411 |
n = n; |
| 412 |
domain = ti.domain; |
| 413 |
f = bounds; |
| 414 |
df = df; |
| 415 |
ddf = ddf; |
| 416 |
};; |
| 417 |
|
| 418 |
(* exp *) |
| 419 |
let eval_m_taylor_exp p_lin p_second ti = |
| 420 |
let n = ti.n in |
| 421 |
let ns = 1--n in |
| 422 |
let f1_bound = eval_m_taylor_bound p_second ti in |
| 423 |
let bounds = exp_interval p_lin ti.f in |
| 424 |
let u_bounds = |
| 425 |
let exp = exp_interval p_lin in |
| 426 |
exp ti.f in |
| 427 |
let df = |
| 428 |
let ( * ) = mul_interval p_lin in |
| 429 |
map (fun d -> u_bounds * d) ti.df in |
| 430 |
let d1_bounds = map (fun i -> eval_m_taylor_partial_bound p_second i ti) ns in |
| 431 |
let d1, d2 = |
| 432 |
let exp = exp_interval p_second in |
| 433 |
let exp_f = exp f1_bound in |
| 434 |
exp_f, exp_f in |
| 435 |
let ddf = |
| 436 |
let ( * ), ( + ) = mul_interval p_second, add_interval p_second in |
| 437 |
map2 (fun dd_list di1 -> |
| 438 |
my_map2 (fun dd dj1 -> |
| 439 |
(d2 * dj1) * di1 + d1 * dd) dd_list d1_bounds) ti.ddf d1_bounds in |
| 440 |
{ |
| 441 |
n = n; |
| 442 |
domain = ti.domain; |
| 443 |
f = bounds; |
| 444 |
df = df; |
| 445 |
ddf = ddf; |
| 446 |
};; |
| 447 |
|
| 448 |
(* log *) |
| 449 |
let eval_m_taylor_log p_lin p_second ti = |
| 450 |
let n = ti.n in |
| 451 |
let ns = 1--n in |
| 452 |
let f1_bound = eval_m_taylor_bound p_second ti in |
| 453 |
let bounds = log_interval p_lin ti.f in |
| 454 |
let u_bounds = |
| 455 |
let inv = inv_interval p_lin in |
| 456 |
inv (ti.f) in |
| 457 |
let df = |
| 458 |
let ( * ) = mul_interval p_lin in |
| 459 |
map (fun d -> u_bounds * d) ti.df in |
| 460 |
let d1_bounds = map (fun i -> eval_m_taylor_partial_bound p_second i ti) ns in |
| 461 |
let d1, d2 = |
| 462 |
let neg, pow2, inv = |
| 463 |
neg_interval, pow_interval p_second 2, inv_interval p_second in |
| 464 |
let inv_f = inv f1_bound in |
| 465 |
inv_f, neg (pow2 inv_f) in |
| 466 |
let ddf = |
| 467 |
let ( * ), ( + ) = mul_interval p_second, add_interval p_second in |
| 468 |
map2 (fun dd_list di1 -> |
| 469 |
my_map2 (fun dd dj1 -> |
| 470 |
(d2 * dj1) * di1 + d1 * dd) dd_list d1_bounds) ti.ddf d1_bounds in |
| 471 |
{ |
| 472 |
n = n; |
| 473 |
domain = ti.domain; |
| 474 |
f = bounds; |
| 475 |
df = df; |
| 476 |
ddf = ddf; |
| 477 |
};; |
| 478 |
|
| 479 |
|
| 480 |
(* matan *) |
| 481 |
let eval_m_taylor_matan p_lin p_second ti = |
| 482 |
let n = ti.n in |
| 483 |
let ns = 1--n in |
| 484 |
let f1_bound = eval_m_taylor_bound p_second ti in |
| 485 |
let bounds = matan_interval p_lin ti.f in |
| 486 |
let u_bounds = |
| 487 |
let dmatan = dmatan_interval p_lin in |
| 488 |
dmatan ti.f in |
| 489 |
let df = |
| 490 |
let ( * ) = mul_interval p_lin in |
| 491 |
map (fun d -> u_bounds * d) ti.df in |
| 492 |
let d1_bounds = map (fun i -> eval_m_taylor_partial_bound p_second i ti) ns in |
| 493 |
let d1, d2 = |
| 494 |
let dmatan, ddmatan = dmatan_interval p_second, ddmatan_interval p_second in |
| 495 |
dmatan f1_bound, ddmatan f1_bound in |
| 496 |
let ddf = |
| 497 |
let ( * ), ( + ) = mul_interval p_second, add_interval p_second in |
| 498 |
map2 (fun dd_list di1 -> |
| 499 |
my_map2 (fun dd dj1 -> |
| 500 |
(d2 * dj1) * di1 + d1 * dd) dd_list d1_bounds) ti.ddf d1_bounds in |
| 501 |
{ |
| 502 |
n = n; |
| 503 |
domain = ti.domain; |
| 504 |
f = bounds; |
| 505 |
df = df; |
| 506 |
ddf = ddf; |
| 507 |
};; |
| 508 |
|
| 509 |
|
| 510 |
(* atn *) |
| 511 |
let eval_m_taylor_atn = |
| 512 |
let neg_two_interval = neg_interval two_interval in |
| 513 |
fun p_lin p_second ti -> |
| 514 |
let n = ti.n in |
| 515 |
let ns = 1--n in |
| 516 |
let f1_bound = eval_m_taylor_bound p_second ti in |
| 517 |
let bounds = atn_interval p_lin ti.f in |
| 518 |
let u_bounds = |
| 519 |
let inv, ( + ), ( * ) = inv_interval p_lin, add_interval p_lin, mul_interval p_lin in |
| 520 |
inv (one_interval + ti.f * ti.f) in |
| 521 |
let df = |
| 522 |
let ( * ) = mul_interval p_lin in |
| 523 |
map (fun d -> u_bounds * d) ti.df in |
| 524 |
let d1_bounds = map (fun i -> eval_m_taylor_partial_bound p_second i ti) ns in |
| 525 |
let d1, d2 = |
| 526 |
let neg, inv, ( + ), ( * ) = neg_interval, inv_interval p_second, |
| 527 |
add_interval p_second, mul_interval p_second in |
| 528 |
let pow2 = pow_interval p_second 2 in |
| 529 |
let inv_one_ff = inv (one_interval + f1_bound * f1_bound) in |
| 530 |
inv_one_ff, (neg_two_interval * f1_bound) * pow2 inv_one_ff in |
| 531 |
let ddf = |
| 532 |
let ( * ), ( + ) = mul_interval p_second, add_interval p_second in |
| 533 |
map2 (fun dd_list di1 -> |
| 534 |
my_map2 (fun dd dj1 -> |
| 535 |
(d2 * dj1) * di1 + d1 * dd) dd_list d1_bounds) ti.ddf d1_bounds in |
| 536 |
{ |
| 537 |
n = n; |
| 538 |
domain = ti.domain; |
| 539 |
f = bounds; |
| 540 |
df = df; |
| 541 |
ddf = ddf; |
| 542 |
};; |
| 543 |
|
| 544 |
(* cos *) |
| 545 |
let eval_m_taylor_cos p_lin p_second ti = |
| 546 |
let n = ti.n in |
| 547 |
let ns = 1--n in |
| 548 |
let f1_bound = eval_m_taylor_bound p_second ti in |
| 549 |
let bounds = cos_interval p_lin ti.f in |
| 550 |
let u_bounds = |
| 551 |
let sin, neg = sin_interval p_lin, neg_interval in |
| 552 |
neg (sin ti.f) in |
| 553 |
let df = |
| 554 |
let ( * ) = mul_interval p_lin in |
| 555 |
map (fun d -> u_bounds * d) ti.df in |
| 556 |
let d1_bounds = map (fun i -> eval_m_taylor_partial_bound p_second i ti) ns in |
| 557 |
let d1, d2 = |
| 558 |
let cos, sin = cos_interval p_second, sin_interval p_second in |
| 559 |
sin f1_bound, cos f1_bound in |
| 560 |
let ddf = |
| 561 |
let ( * ), ( + ) = mul_interval p_second, add_interval p_second in |
| 562 |
let neg = neg_interval in |
| 563 |
map2 (fun dd_list di1 -> |
| 564 |
my_map2 (fun dd dj1 -> |
| 565 |
neg ((d2 * dj1) * di1 + d1 * dd)) dd_list d1_bounds) ti.ddf d1_bounds in |
| 566 |
{ |
| 567 |
n = n; |
| 568 |
domain = ti.domain; |
| 569 |
f = bounds; |
| 570 |
df = df; |
| 571 |
ddf = ddf; |
| 572 |
};; |
| 573 |
|
| 574 |
(* sin *) |
| 575 |
let eval_m_taylor_sin p_lin p_second ti = |
| 576 |
let n = ti.n in |
| 577 |
let ns = 1--n in |
| 578 |
let f1_bound = eval_m_taylor_bound p_second ti in |
| 579 |
let bounds = sin_interval p_lin ti.f in |
| 580 |
let u_bounds = |
| 581 |
let cos = cos_interval p_lin in |
| 582 |
cos ti.f in |
| 583 |
let df = |
| 584 |
let ( * ) = mul_interval p_lin in |
| 585 |
map (fun d -> u_bounds * d) ti.df in |
| 586 |
let d1_bounds = map (fun i -> eval_m_taylor_partial_bound p_second i ti) ns in |
| 587 |
let d1, d2 = |
| 588 |
let cos, sin = cos_interval p_second, sin_interval p_second in |
| 589 |
let neg = neg_interval in |
| 590 |
cos f1_bound, neg (sin f1_bound) in |
| 591 |
let ddf = |
| 592 |
let ( * ), ( + ) = mul_interval p_second, add_interval p_second in |
| 593 |
map2 (fun dd_list di1 -> |
| 594 |
my_map2 (fun dd dj1 -> |
| 595 |
(d2 * dj1) * di1 + d1 * dd) dd_list d1_bounds) ti.ddf d1_bounds in |
| 596 |
{ |
| 597 |
n = n; |
| 598 |
domain = ti.domain; |
| 599 |
f = bounds; |
| 600 |
df = df; |
| 601 |
ddf = ddf; |
| 602 |
};; |
| 603 |
|
| 604 |
|
| 605 |
(* asn *) |
| 606 |
let eval_m_taylor_asn p_lin p_second ti = |
| 607 |
let n = ti.n in |
| 608 |
let ns = 1--n in |
| 609 |
let f1_bound = eval_m_taylor_bound p_second ti in |
| 610 |
let bounds = asn_interval p_lin ti.f in |
| 611 |
let u_bounds = |
| 612 |
let inv, sqrt = inv_interval p_lin, sqrt_interval p_lin in |
| 613 |
let ( * ), ( - ) = mul_interval p_lin, sub_interval p_lin in |
| 614 |
inv (sqrt (one_interval - ti.f * ti.f)) in |
| 615 |
let df = |
| 616 |
let ( * ) = mul_interval p_lin in |
| 617 |
map (fun d -> u_bounds * d) ti.df in |
| 618 |
let d1_bounds = map (fun i -> eval_m_taylor_partial_bound p_second i ti) ns in |
| 619 |
let d1, d2 = |
| 620 |
let sqrt, inv = sqrt_interval p_second, inv_interval p_second in |
| 621 |
let ( - ), ( * ), ( / ) = sub_interval p_second, mul_interval p_second, div_interval p_second in |
| 622 |
let pow3 = pow_interval p_second 3 in |
| 623 |
let ff_1 = one_interval - f1_bound * f1_bound in |
| 624 |
inv (sqrt ff_1), f1_bound / sqrt (pow3 ff_1) in |
| 625 |
let ddf = |
| 626 |
let ( * ), ( + ) = mul_interval p_second, add_interval p_second in |
| 627 |
map2 (fun dd_list di1 -> |
| 628 |
my_map2 (fun dd dj1 -> |
| 629 |
(d2 * dj1) * di1 + d1 * dd) dd_list d1_bounds) ti.ddf d1_bounds in |
| 630 |
{ |
| 631 |
n = n; |
| 632 |
domain = ti.domain; |
| 633 |
f = bounds; |
| 634 |
df = df; |
| 635 |
ddf = ddf; |
| 636 |
};; |
| 637 |
|
| 638 |
|
| 639 |
(* acs *) |
| 640 |
let eval_m_taylor_acs p_lin p_second ti = |
| 641 |
let n = ti.n in |
| 642 |
let ns = 1--n in |
| 643 |
let f1_bound = eval_m_taylor_bound p_second ti in |
| 644 |
let bounds = acs_interval p_lin ti.f in |
| 645 |
let u_bounds = |
| 646 |
let inv, sqrt, neg = inv_interval p_lin, sqrt_interval p_lin, neg_interval in |
| 647 |
let ( * ), ( - ) = mul_interval p_lin, sub_interval p_lin in |
| 648 |
neg (inv (sqrt (one_interval - ti.f * ti.f))) in |
| 649 |
let df = |
| 650 |
let ( * ) = mul_interval p_lin in |
| 651 |
map (fun d -> u_bounds * d) ti.df in |
| 652 |
let d1_bounds = map (fun i -> eval_m_taylor_partial_bound p_second i ti) ns in |
| 653 |
let d1, d2 = |
| 654 |
let neg, sqrt, inv = neg_interval, sqrt_interval p_second, inv_interval p_second in |
| 655 |
let ( - ), ( * ), ( / ) = sub_interval p_second, mul_interval p_second, div_interval p_second in |
| 656 |
let pow3 = pow_interval p_second 3 in |
| 657 |
let ff_1 = one_interval - f1_bound * f1_bound in |
| 658 |
inv (sqrt ff_1), neg (f1_bound / sqrt (pow3 ff_1)) in |
| 659 |
let ddf = |
| 660 |
let ( * ), ( - ) = mul_interval p_second, sub_interval p_second in |
| 661 |
map2 (fun dd_list di1 -> |
| 662 |
my_map2 (fun dd dj1 -> |
| 663 |
(d2 * dj1) * di1 - d1 * dd) dd_list d1_bounds) ti.ddf d1_bounds in |
| 664 |
{ |
| 665 |
n = n; |
| 666 |
domain = ti.domain; |
| 667 |
f = bounds; |
| 668 |
df = df; |
| 669 |
ddf = ddf; |
| 670 |
};; |
| 671 |
|
| 672 |
|
| 673 |
end;; |