| 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 |
(* Formal arithmetic of taylor intervals 2 *) |
| 11 |
(* -------------------------------------------------------------------------- *) |
| 12 |
|
| 13 |
needs "Formal_ineqs/taylor/m_taylor_arith.hl";; |
| 14 |
|
| 15 |
|
| 16 |
module M_taylor_arith2 = struct |
| 17 |
|
| 18 |
open Ssrfun;; |
| 19 |
open Ssrbool;; |
| 20 |
open Ssrnat;; |
| 21 |
open Taylor_interval;; |
| 22 |
open Multivariate_taylor;; |
| 23 |
open Misc_functions;; |
| 24 |
open Arith_nat;; |
| 25 |
open Arith_float;; |
| 26 |
open More_float;; |
| 27 |
open Float_pow;; |
| 28 |
open Exp_eval;; |
| 29 |
open Log_eval;; |
| 30 |
open Atn_eval;; |
| 31 |
open Asn_acs_eval;; |
| 32 |
open Cos_eval;; |
| 33 |
open Sin_eval;; |
| 34 |
open Matan_eval;; |
| 35 |
open Float_theory;; |
| 36 |
open M_taylor;; |
| 37 |
open M_taylor_arith;; |
| 38 |
open Misc_vars;; |
| 39 |
|
| 40 |
|
| 41 |
(**************************************) |
| 42 |
let mk_vars n name ty = map (fun i -> mk_var (name^string_of_int i, ty)) (1--n);; |
| 43 |
|
| 44 |
|
| 45 |
let all_n_components2 n all_n_th = |
| 46 |
let th0 = SYM (all_n_array.(n)) in |
| 47 |
let _, list_tm, s_tm = dest_all_n (concl all_n_th) in |
| 48 |
let list_ty = type_of list_tm in |
| 49 |
let ty = (hd o snd o dest_type) list_ty in |
| 50 |
let s_var = mk_var ("s", type_of s_tm) and |
| 51 |
a_vars = mk_vars n "a" ty in |
| 52 |
|
| 53 |
let list_tms = dest_list list_tm in |
| 54 |
let th1 = (INST ([s_tm, s_var] @ zip list_tms a_vars) o INST_TYPE[ty, aty]) th0 in |
| 55 |
CONJUNCTS (EQ_MP th1 all_n_th);; |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
(***************************************) |
| 60 |
|
| 61 |
let gen_taylor_arith_thm arith_th final_rule n = |
| 62 |
let num1_th = (SYM o REWRITE_RULE[Arith_num.NUM_THM] o NUMERAL_TO_NUM_CONV) `1` in |
| 63 |
let th0 = (REWRITE_RULE[num1_th] o DISCH_ALL o INST_TYPE[n_type_array.(n), nty]) arith_th in |
| 64 |
let pty = `:real#real` in |
| 65 |
let dfs = mk_vars n "df" pty in |
| 66 |
let ddfs' = map (fun i -> map (fun j -> dd_vars_array.(i).(j)) (1--i)) (1--n) in |
| 67 |
let ddfs = map (fun list -> mk_list (list, pty)) ddfs' in |
| 68 |
let d_bounds_list = mk_list (dfs, pty) in |
| 69 |
let dd_bounds_list = mk_list (ddfs, type_of (hd ddfs)) in |
| 70 |
let th1 = INST[d_bounds_list, d_bounds_list_var; dd_bounds_list, dd_bounds_list_var] th0 in |
| 71 |
let th2 = (CONV_RULE NUM_REDUCE_CONV o REWRITE_RULE[all_n]) th1 in |
| 72 |
(UNDISCH_ALL o final_rule o REWRITE_RULE[GSYM CONJ_ASSOC] o |
| 73 |
NUMERALS_TO_NUM o PURE_REWRITE_RULE[FLOAT_OF_NUM; min_exp_def]) th2;; |
| 74 |
|
| 75 |
let gen_add_thm = gen_taylor_arith_thm MK_M_TAYLOR_ADD' (CONV_RULE ALL_CONV);; |
| 76 |
let gen_sub_thm = gen_taylor_arith_thm MK_M_TAYLOR_SUB' (CONV_RULE ALL_CONV);; |
| 77 |
let gen_mul_thm = gen_taylor_arith_thm MK_M_TAYLOR_MUL' (CONV_RULE ALL_CONV);; |
| 78 |
let gen_neg_thm = gen_taylor_arith_thm MK_M_TAYLOR_NEG' (CONV_RULE ALL_CONV);; |
| 79 |
let gen_inv_thm = gen_taylor_arith_thm MK_M_TAYLOR_INV' (REWRITE_RULE[float2_eq]);; |
| 80 |
let gen_sqrt_thm = gen_taylor_arith_thm MK_M_TAYLOR_SQRT' (REWRITE_RULE[float2_eq]);; |
| 81 |
let gen_exp_thm = gen_taylor_arith_thm MK_M_TAYLOR_EXP' (CONV_RULE ALL_CONV);; |
| 82 |
|
| 83 |
let gen_log_thm = |
| 84 |
let pow2_th = (SYM o REWRITE_CONV[SYM num2_eq]) `x pow 2` in |
| 85 |
gen_taylor_arith_thm MK_M_TAYLOR_LOG' (REWRITE_RULE[pow2_th]);; |
| 86 |
|
| 87 |
let gen_atn_thm = |
| 88 |
let pow2_th = (SYM o REWRITE_CONV[SYM num2_eq]) `x pow 2` in |
| 89 |
gen_taylor_arith_thm MK_M_TAYLOR_ATN' (REWRITE_RULE[float2_eq; float1_eq; pow2_th]);; |
| 90 |
|
| 91 |
let gen_cos_thm = |
| 92 |
gen_taylor_arith_thm MK_M_TAYLOR_COS' (CONV_RULE ALL_CONV);; |
| 93 |
|
| 94 |
let gen_sin_thm = |
| 95 |
gen_taylor_arith_thm MK_M_TAYLOR_SIN' (CONV_RULE ALL_CONV);; |
| 96 |
|
| 97 |
let gen_acs_thm = |
| 98 |
let iabs_lemma = REWRITE_CONV[SYM float1_eq] `iabs f_bounds < &1` in |
| 99 |
let pow3_lemma = (SYM o REWRITE_CONV[SYM num3_eq]) `x pow 3` in |
| 100 |
gen_taylor_arith_thm MK_M_TAYLOR_ACS' (REWRITE_RULE[iabs_lemma] o REWRITE_RULE[float1_eq; pow3_lemma]);; |
| 101 |
|
| 102 |
let gen_asn_thm = |
| 103 |
let iabs_lemma = REWRITE_CONV[SYM float1_eq] `iabs f_bounds < &1` in |
| 104 |
let pow3_lemma = (SYM o REWRITE_CONV[SYM num3_eq]) `x pow 3` in |
| 105 |
gen_taylor_arith_thm MK_M_TAYLOR_ASN' (REWRITE_RULE[iabs_lemma] o REWRITE_RULE[float1_eq; pow3_lemma]);; |
| 106 |
|
| 107 |
let gen_matan_thm = gen_taylor_arith_thm MK_M_TAYLOR_MATAN' (CONV_RULE ALL_CONV);; |
| 108 |
|
| 109 |
let add_ths_array, |
| 110 |
sub_ths_array, |
| 111 |
mul_ths_array, |
| 112 |
neg_ths_array, |
| 113 |
inv_ths_array, |
| 114 |
sqrt_ths_array, |
| 115 |
exp_ths_array, |
| 116 |
log_ths_array, |
| 117 |
atn_ths_array, |
| 118 |
cos_ths_array, |
| 119 |
sin_ths_array, |
| 120 |
acs_ths_array, |
| 121 |
asn_ths_array, |
| 122 |
matan_ths_array = |
| 123 |
let gen = fun f -> Array.init (max_dim + 1) (fun i -> if i = 0 then TRUTH else f i) in |
| 124 |
gen gen_add_thm, |
| 125 |
gen gen_sub_thm, |
| 126 |
gen gen_mul_thm, |
| 127 |
gen gen_neg_thm, |
| 128 |
gen gen_inv_thm, |
| 129 |
gen gen_sqrt_thm, |
| 130 |
gen gen_exp_thm, |
| 131 |
gen gen_log_thm, |
| 132 |
gen gen_atn_thm, |
| 133 |
gen gen_cos_thm, |
| 134 |
gen gen_sin_thm, |
| 135 |
gen gen_acs_thm, |
| 136 |
gen gen_asn_thm, |
| 137 |
gen gen_matan_thm;; |
| 138 |
|
| 139 |
|
| 140 |
(* ----------------------- *) |
| 141 |
(* add *) |
| 142 |
(* ----------------------- *) |
| 143 |
|
| 144 |
let eval_m_taylor_add2 n p_lin p_second taylor1_th taylor2_th = |
| 145 |
let domain_th, diff2_f1_th, lin1_th, second1_th = dest_m_taylor_thms n taylor1_th in |
| 146 |
let _, diff2_f2_th, lin2_th, second2_th = dest_m_taylor_thms n taylor2_th in |
| 147 |
let f1_tm = (rand o concl) diff2_f1_th and |
| 148 |
f2_tm = (rand o concl) diff2_f2_th in |
| 149 |
let domain_tm, y_tm, w_tm = dest_m_cell_domain (concl domain_th) in |
| 150 |
let ty = type_of y_tm in |
| 151 |
|
| 152 |
let x_var = mk_var ("x", ty) and |
| 153 |
y_var = mk_var ("y", ty) and |
| 154 |
w_var = mk_var ("w", ty) and |
| 155 |
f_var = mk_var ("f", type_of f1_tm) and |
| 156 |
g_var = mk_var ("g", type_of f2_tm) and |
| 157 |
domain_var = mk_var ("domain", type_of domain_tm) in |
| 158 |
|
| 159 |
let _, bounds1_th, df1_th = m_lin_approx_components n lin1_th and |
| 160 |
_, bounds2_th, df2_th = m_lin_approx_components n lin2_th in |
| 161 |
|
| 162 |
let bounds_th = float_interval_add p_lin bounds1_th bounds2_th in |
| 163 |
let bounds_tm = (rand o concl) bounds_th in |
| 164 |
|
| 165 |
let df_ths = |
| 166 |
let df1_ths = map MY_BETA_RULE (all_n_components2 n df1_th) in |
| 167 |
let df2_ths = map MY_BETA_RULE (all_n_components2 n df2_th) in |
| 168 |
map2 (float_interval_add p_lin) df1_ths df2_ths in |
| 169 |
|
| 170 |
let df_th = end_itlist CONJ df_ths in |
| 171 |
|
| 172 |
let dd_ths = |
| 173 |
let dd1' = all_n_components2 n (second_bounded_components n second1_th) in |
| 174 |
let dd2' = all_n_components2 n (second_bounded_components n second2_th) in |
| 175 |
let dd1 = map2 (fun i -> map MY_BETA_RULE o all_n_components2 i o MY_BETA_RULE) (1--n) dd1' in |
| 176 |
let dd2 = map2 (fun i -> map MY_BETA_RULE o all_n_components2 i o MY_BETA_RULE) (1--n) dd2' in |
| 177 |
map2 (map2 (float_interval_add p_second)) dd1 dd2 in |
| 178 |
|
| 179 |
let dd_th = (GEN x_var o DISCH_ALL o end_itlist CONJ) (List.flatten dd_ths) in |
| 180 |
|
| 181 |
let df_vars = map (fun i -> df_vars_array.(i)) (1--n) in |
| 182 |
let dd_vars = map (fun i -> map (fun j -> dd_vars_array.(i).(j)) (1--i)) (1--n) in |
| 183 |
|
| 184 |
let dfs = map (rand o concl) df_ths in |
| 185 |
let dds = map (map (rand o concl)) dd_ths in |
| 186 |
let inst_list = union (zip dfs df_vars) (zip (List.flatten dds) (List.flatten dd_vars)) in |
| 187 |
|
| 188 |
let th = (MY_PROVE_HYP diff2_f1_th o MY_PROVE_HYP diff2_f2_th o |
| 189 |
MY_PROVE_HYP bounds_th o MY_PROVE_HYP domain_th o |
| 190 |
MY_PROVE_HYP df_th o MY_PROVE_HYP dd_th o |
| 191 |
INST([f1_tm, f_var; f2_tm, g_var; |
| 192 |
domain_tm, domain_var; y_tm, y_var; w_tm, w_var; |
| 193 |
bounds_tm, bounds_var] @ inst_list)) add_ths_array.(n) in |
| 194 |
let eq_th = binary_beta_gen_eq f1_tm f2_tm x_var add_op_real in |
| 195 |
m_taylor_interval_norm th eq_th;; |
| 196 |
|
| 197 |
|
| 198 |
(* ----------------------- *) |
| 199 |
(* sub *) |
| 200 |
(* ----------------------- *) |
| 201 |
|
| 202 |
let eval_m_taylor_sub2 n p_lin p_second taylor1_th taylor2_th = |
| 203 |
let domain_th, diff2_f1_th, lin1_th, second1_th = dest_m_taylor_thms n taylor1_th in |
| 204 |
let _, diff2_f2_th, lin2_th, second2_th = dest_m_taylor_thms n taylor2_th in |
| 205 |
let f1_tm = (rand o concl) diff2_f1_th and |
| 206 |
f2_tm = (rand o concl) diff2_f2_th in |
| 207 |
let domain_tm, y_tm, w_tm = dest_m_cell_domain (concl domain_th) in |
| 208 |
let ty = type_of y_tm in |
| 209 |
|
| 210 |
let x_var = mk_var ("x", ty) and |
| 211 |
y_var = mk_var ("y", ty) and |
| 212 |
w_var = mk_var ("w", ty) and |
| 213 |
f_var = mk_var ("f", type_of f1_tm) and |
| 214 |
g_var = mk_var ("g", type_of f2_tm) and |
| 215 |
domain_var = mk_var ("domain", type_of domain_tm) in |
| 216 |
|
| 217 |
let _, bounds1_th, df1_th = m_lin_approx_components n lin1_th and |
| 218 |
_, bounds2_th, df2_th = m_lin_approx_components n lin2_th in |
| 219 |
|
| 220 |
let bounds_th = float_interval_sub p_lin bounds1_th bounds2_th in |
| 221 |
let bounds_tm = (rand o concl) bounds_th in |
| 222 |
|
| 223 |
let df_ths = |
| 224 |
let df1_ths = map MY_BETA_RULE (all_n_components2 n df1_th) in |
| 225 |
let df2_ths = map MY_BETA_RULE (all_n_components2 n df2_th) in |
| 226 |
map2 (float_interval_sub p_lin) df1_ths df2_ths in |
| 227 |
|
| 228 |
let df_th = end_itlist CONJ df_ths in |
| 229 |
|
| 230 |
let dd_ths = |
| 231 |
let dd1' = all_n_components2 n (second_bounded_components n second1_th) in |
| 232 |
let dd2' = all_n_components2 n (second_bounded_components n second2_th) in |
| 233 |
let dd1 = map2 (fun i -> map MY_BETA_RULE o all_n_components2 i o MY_BETA_RULE) (1--n) dd1' in |
| 234 |
let dd2 = map2 (fun i -> map MY_BETA_RULE o all_n_components2 i o MY_BETA_RULE) (1--n) dd2' in |
| 235 |
map2 (map2 (float_interval_sub p_second)) dd1 dd2 in |
| 236 |
|
| 237 |
let dd_th = (GEN x_var o DISCH_ALL o end_itlist CONJ) (List.flatten dd_ths) in |
| 238 |
|
| 239 |
let df_vars = map (fun i -> df_vars_array.(i)) (1--n) in |
| 240 |
let dd_vars = map (fun i -> map (fun j -> dd_vars_array.(i).(j)) (1--i)) (1--n) in |
| 241 |
|
| 242 |
let dfs = map (rand o concl) df_ths in |
| 243 |
let dds = map (map (rand o concl)) dd_ths in |
| 244 |
let inst_list = union (zip dfs df_vars) (zip (List.flatten dds) (List.flatten dd_vars)) in |
| 245 |
|
| 246 |
let th = (MY_PROVE_HYP diff2_f1_th o MY_PROVE_HYP diff2_f2_th o |
| 247 |
MY_PROVE_HYP bounds_th o MY_PROVE_HYP domain_th o |
| 248 |
MY_PROVE_HYP df_th o MY_PROVE_HYP dd_th o |
| 249 |
INST([f1_tm, f_var; f2_tm, g_var; |
| 250 |
domain_tm, domain_var; y_tm, y_var; w_tm, w_var; |
| 251 |
bounds_tm, bounds_var] @ inst_list)) sub_ths_array.(n) in |
| 252 |
let eq_th = binary_beta_gen_eq f1_tm f2_tm x_var sub_op_real in |
| 253 |
m_taylor_interval_norm th eq_th;; |
| 254 |
|
| 255 |
|
| 256 |
(* ----------------------- *) |
| 257 |
(* mul *) |
| 258 |
(* ----------------------- *) |
| 259 |
|
| 260 |
let eval_m_taylor_mul2 n p_lin p_second taylor1_th taylor2_th = |
| 261 |
let domain_th, diff2_f1_th, lin1_th, second1_th = dest_m_taylor_thms n taylor1_th in |
| 262 |
let _, diff2_f2_th, lin2_th, second2_th = dest_m_taylor_thms n taylor2_th in |
| 263 |
let f1_tm = (rand o concl) diff2_f1_th and |
| 264 |
f2_tm = (rand o concl) diff2_f2_th in |
| 265 |
let domain_tm, y_tm, w_tm = dest_m_cell_domain (concl domain_th) in |
| 266 |
let ty = type_of y_tm in |
| 267 |
|
| 268 |
let x_var = mk_var ("x", ty) and |
| 269 |
y_var = mk_var ("y", ty) and |
| 270 |
w_var = mk_var ("w", ty) and |
| 271 |
f_var = mk_var ("f", type_of f1_tm) and |
| 272 |
g_var = mk_var ("g", type_of f2_tm) and |
| 273 |
domain_var = mk_var ("domain", type_of domain_tm) in |
| 274 |
|
| 275 |
let undisch = UNDISCH o SPEC x_var in |
| 276 |
|
| 277 |
let _, bounds1_th, df1_th = m_lin_approx_components n lin1_th and |
| 278 |
_, bounds2_th, df2_th = m_lin_approx_components n lin2_th in |
| 279 |
|
| 280 |
let bounds_th = float_interval_mul p_lin bounds1_th bounds2_th in |
| 281 |
let bounds_tm = (rand o concl) bounds_th in |
| 282 |
|
| 283 |
(* first partials *) |
| 284 |
let df_ths = |
| 285 |
let df1_ths = map MY_BETA_RULE (all_n_components2 n df1_th) in |
| 286 |
let df2_ths = map MY_BETA_RULE (all_n_components2 n df2_th) in |
| 287 |
let ( * ), ( + ) = float_interval_mul p_lin, float_interval_add p_lin in |
| 288 |
map2 (fun d1 d2 -> d1 * bounds2_th + bounds1_th * d2) df1_ths df2_ths in |
| 289 |
|
| 290 |
let df_th = end_itlist CONJ df_ths in |
| 291 |
|
| 292 |
(* second partials *) |
| 293 |
let d1_bounds = map (fun i -> |
| 294 |
undisch (eval_m_taylor_partial_bound n p_second i taylor1_th)) (1--n) in |
| 295 |
let d2_bounds = map (fun i -> |
| 296 |
undisch (eval_m_taylor_partial_bound n p_second i taylor2_th)) (1--n) in |
| 297 |
let f1_bound = undisch (eval_m_taylor_bound n p_second taylor1_th) in |
| 298 |
let f2_bound = undisch (eval_m_taylor_bound n p_second taylor2_th) in |
| 299 |
|
| 300 |
let dd_ths = |
| 301 |
let ns = 1--n in |
| 302 |
let dd1' = all_n_components2 n (second_bounded_components n second1_th) in |
| 303 |
let dd2' = all_n_components2 n (second_bounded_components n second2_th) in |
| 304 |
let dd1 = map2 (fun i -> map MY_BETA_RULE o all_n_components2 i o MY_BETA_RULE) ns dd1' in |
| 305 |
let dd2 = map2 (fun i -> map MY_BETA_RULE o all_n_components2 i o MY_BETA_RULE) ns dd2' in |
| 306 |
let ( * ), ( + ) = float_interval_mul p_second, float_interval_add p_second in |
| 307 |
map2 (fun (dd1_list, dd2_list) i -> |
| 308 |
let di1 = List.nth d1_bounds (i - 1) in |
| 309 |
let di2 = List.nth d2_bounds (i - 1) in |
| 310 |
map2 (fun (dd1, dd2) j -> |
| 311 |
let dj1 = List.nth d1_bounds (j - 1) in |
| 312 |
let dj2 = List.nth d2_bounds (j - 1) in |
| 313 |
(dd1 * f2_bound + di1 * dj2) + (dj1 * di2 + f1_bound * dd2)) |
| 314 |
(zip dd1_list dd2_list) (1--i)) (zip dd1 dd2) ns in |
| 315 |
|
| 316 |
let dd_th = (GEN x_var o DISCH_ALL o end_itlist CONJ) (List.flatten dd_ths) in |
| 317 |
|
| 318 |
let df_vars = map (fun i -> df_vars_array.(i)) (1--n) in |
| 319 |
let dd_vars = map (fun i -> map (fun j -> dd_vars_array.(i).(j)) (1--i)) (1--n) in |
| 320 |
|
| 321 |
let dfs = map (rand o concl) df_ths in |
| 322 |
let dds = map (map (rand o concl)) dd_ths in |
| 323 |
let inst_list = union (zip dfs df_vars) (zip (List.flatten dds) (List.flatten dd_vars)) in |
| 324 |
|
| 325 |
let th = (MY_PROVE_HYP diff2_f1_th o MY_PROVE_HYP diff2_f2_th o |
| 326 |
MY_PROVE_HYP bounds_th o MY_PROVE_HYP domain_th o |
| 327 |
MY_PROVE_HYP df_th o MY_PROVE_HYP dd_th o |
| 328 |
INST([f1_tm, f_var; f2_tm, g_var; |
| 329 |
domain_tm, domain_var; y_tm, y_var; w_tm, w_var; |
| 330 |
bounds_tm, bounds_var] @ inst_list)) mul_ths_array.(n) in |
| 331 |
let eq_th = binary_beta_gen_eq f1_tm f2_tm x_var mul_op_real in |
| 332 |
m_taylor_interval_norm th eq_th;; |
| 333 |
|
| 334 |
|
| 335 |
(* ----------------------- *) |
| 336 |
(* neg *) |
| 337 |
(* ----------------------- *) |
| 338 |
|
| 339 |
let eval_m_taylor_neg2_raw norm_flag n taylor1_th = |
| 340 |
let domain_th, diff2_f1_th, lin1_th, second1_th = dest_m_taylor_thms n taylor1_th in |
| 341 |
let f1_tm = (rand o concl) diff2_f1_th in |
| 342 |
let domain_tm, y_tm, w_tm = dest_m_cell_domain (concl domain_th) in |
| 343 |
let ty = type_of y_tm in |
| 344 |
|
| 345 |
let x_var = mk_var ("x", ty) and |
| 346 |
y_var = mk_var ("y", ty) and |
| 347 |
w_var = mk_var ("w", ty) and |
| 348 |
f_var = mk_var ("f", type_of f1_tm) and |
| 349 |
domain_var = mk_var ("domain", type_of domain_tm) in |
| 350 |
|
| 351 |
let _, bounds1_th, df1_th = m_lin_approx_components n lin1_th in |
| 352 |
|
| 353 |
let bounds_th = float_interval_neg bounds1_th in |
| 354 |
let bounds_tm = (rand o concl) bounds_th in |
| 355 |
|
| 356 |
let df_ths = |
| 357 |
let df1_ths = map MY_BETA_RULE (all_n_components2 n df1_th) in |
| 358 |
map (float_interval_neg) df1_ths in |
| 359 |
|
| 360 |
let df_th = end_itlist CONJ df_ths in |
| 361 |
|
| 362 |
let dd_ths = |
| 363 |
let dd1' = all_n_components2 n (second_bounded_components n second1_th) in |
| 364 |
let dd1 = map2 (fun i -> map MY_BETA_RULE o all_n_components2 i o MY_BETA_RULE) (1--n) dd1' in |
| 365 |
map (map float_interval_neg) dd1 in |
| 366 |
|
| 367 |
let dd_th = (GEN x_var o DISCH_ALL o end_itlist CONJ) (List.flatten dd_ths) in |
| 368 |
|
| 369 |
let df_vars = map (fun i -> df_vars_array.(i)) (1--n) in |
| 370 |
let dd_vars = map (fun i -> map (fun j -> dd_vars_array.(i).(j)) (1--i)) (1--n) in |
| 371 |
|
| 372 |
let dfs = map (rand o concl) df_ths in |
| 373 |
let dds = map (map (rand o concl)) dd_ths in |
| 374 |
let inst_list = union (zip dfs df_vars) (zip (List.flatten dds) (List.flatten dd_vars)) in |
| 375 |
|
| 376 |
let th = (MY_PROVE_HYP diff2_f1_th o MY_PROVE_HYP bounds_th o |
| 377 |
MY_PROVE_HYP domain_th o MY_PROVE_HYP df_th o MY_PROVE_HYP dd_th o |
| 378 |
INST([f1_tm, f_var; |
| 379 |
domain_tm, domain_var; y_tm, y_var; w_tm, w_var; |
| 380 |
bounds_tm, bounds_var] @ inst_list)) neg_ths_array.(n) in |
| 381 |
if norm_flag then |
| 382 |
let eq_th = unary_beta_gen_eq f1_tm x_var neg_op_real in |
| 383 |
m_taylor_interval_norm th eq_th |
| 384 |
else |
| 385 |
th;; |
| 386 |
|
| 387 |
let eval_m_taylor_neg2 = eval_m_taylor_neg2_raw true;; |
| 388 |
|
| 389 |
|
| 390 |
(* ----------------------- *) |
| 391 |
(* abs *) |
| 392 |
(* ----------------------- *) |
| 393 |
|
| 394 |
let eval_m_taylor_abs2 n p_second taylor1_th = |
| 395 |
let f1_bound0 = eval_m_taylor_bound n p_second taylor1_th in |
| 396 |
let f_bounds_tm = (rand o rand o snd o dest_forall o concl) f1_bound0 in |
| 397 |
let cond_th, taylor_th, th0, |
| 398 |
(f1_tm, domain_tm, y_tm, w_tm, bounds_tm, d_tm, dd_tm) = |
| 399 |
try |
| 400 |
let cond_th = check_interval_pos f_bounds_tm in |
| 401 |
cond_th, taylor1_th, MK_M_TAYLOR_ABS_POS', dest_m_taylor (concl taylor1_th) |
| 402 |
with Failure _ -> |
| 403 |
let cond_th = check_interval_neg f_bounds_tm in |
| 404 |
let neg_taylor = eval_m_taylor_neg2_raw false n taylor1_th in |
| 405 |
let neg_f1_tm, domain_tm, y_tm, w_tm, bounds_tm, d_tm, dd_tm = |
| 406 |
dest_m_taylor (concl neg_taylor) in |
| 407 |
let f1_tm = (rator o rand o snd o dest_abs) neg_f1_tm in |
| 408 |
cond_th, neg_taylor, MK_M_TAYLOR_ABS_NEG', |
| 409 |
(f1_tm, domain_tm, y_tm, w_tm, bounds_tm, d_tm, dd_tm) in |
| 410 |
let ty = type_of y_tm in |
| 411 |
let x_var = mk_var ("x", ty) and |
| 412 |
y_var = mk_var ("y", ty) and |
| 413 |
w_var = mk_var ("w", ty) and |
| 414 |
f_var = mk_var ("f", type_of f1_tm) and |
| 415 |
domain_var = mk_var ("domain", type_of domain_tm) in |
| 416 |
let th1 = (MY_PROVE_HYP f1_bound0 o |
| 417 |
MY_PROVE_HYP cond_th o |
| 418 |
MY_PROVE_HYP taylor_th o |
| 419 |
INST[f1_tm, f_var; f_bounds_tm, f_bounds_var; |
| 420 |
domain_tm, domain_var; y_tm, y_var; w_tm, w_var; |
| 421 |
bounds_tm, bounds_var; d_tm, d_bounds_list_var; |
| 422 |
dd_tm, dd_bounds_list_var] o |
| 423 |
INST_TYPE[n_type_array.(n), nty]) th0 in |
| 424 |
let eq_th = unary_beta_gen_eq f1_tm x_var abs_tm in |
| 425 |
m_taylor_interval_norm th1 eq_th;; |
| 426 |
|
| 427 |
|
| 428 |
(* ----------------------- *) |
| 429 |
(* inv *) |
| 430 |
(* ----------------------- *) |
| 431 |
|
| 432 |
let eval_m_taylor_inv2 n p_lin p_second taylor1_th = |
| 433 |
let domain_th, diff2_f1_th, lin1_th, second1_th = dest_m_taylor_thms n taylor1_th in |
| 434 |
let f1_tm = (rand o concl) diff2_f1_th in |
| 435 |
let domain_tm, y_tm, w_tm = dest_m_cell_domain (concl domain_th) in |
| 436 |
|
| 437 |
let ty = type_of y_tm in |
| 438 |
let x_var = mk_var ("x", ty) and |
| 439 |
y_var = mk_var ("y", ty) and |
| 440 |
w_var = mk_var ("w", ty) and |
| 441 |
f_var = mk_var ("f", type_of f1_tm) and |
| 442 |
domain_var = mk_var ("domain", type_of domain_tm) in |
| 443 |
|
| 444 |
let undisch = UNDISCH o SPEC x_var in |
| 445 |
|
| 446 |
let f1_bound0 = eval_m_taylor_bound n p_second taylor1_th in |
| 447 |
let f1_bound = undisch f1_bound0 in |
| 448 |
let f_bounds_tm = (rand o concl) f1_bound in |
| 449 |
|
| 450 |
(* cond *) |
| 451 |
let cond_th = check_interval_not_zero f_bounds_tm in |
| 452 |
|
| 453 |
let _, bounds1_th, df1_th = m_lin_approx_components n lin1_th in |
| 454 |
|
| 455 |
let bounds_th = float_interval_inv p_lin bounds1_th in |
| 456 |
let bounds_tm = (rand o concl) bounds_th in |
| 457 |
|
| 458 |
(* first partials *) |
| 459 |
let u_bounds = |
| 460 |
let neg, inv, ( * ) = float_interval_neg, float_interval_inv p_lin, float_interval_mul p_lin in |
| 461 |
neg (inv (bounds1_th * bounds1_th)) in |
| 462 |
|
| 463 |
let df1_ths' = all_n_components2 n df1_th in |
| 464 |
let df1_ths = map MY_BETA_RULE df1_ths' in |
| 465 |
|
| 466 |
let df_ths = |
| 467 |
let ( * ) = float_interval_mul p_lin in |
| 468 |
map (fun th1 -> u_bounds * th1) df1_ths in |
| 469 |
|
| 470 |
let df_th = end_itlist CONJ df_ths in |
| 471 |
|
| 472 |
(* second partials *) |
| 473 |
let dd_ths = |
| 474 |
let dd1 = all_n_components2 n (second_bounded_components n second1_th) in |
| 475 |
map2 (fun i -> map MY_BETA_RULE o all_n_components2 i o MY_BETA_RULE) (1--n) dd1 in |
| 476 |
|
| 477 |
let d1_bounds = map (fun i -> |
| 478 |
let th0 = eval_m_taylor_partial_bound n p_second i taylor1_th in |
| 479 |
undisch th0) (1--n) in |
| 480 |
|
| 481 |
(* u'(f x), u''(f x) *) |
| 482 |
let d1_th0, d2_th0 = |
| 483 |
let inv, ( * ) = float_interval_inv p_second, float_interval_mul p_second in |
| 484 |
let ff = f1_bound * f1_bound in |
| 485 |
inv ff, |
| 486 |
two_interval * inv (f1_bound * ff) in |
| 487 |
|
| 488 |
let dd_ths = |
| 489 |
let ( * ), ( - ) = float_interval_mul p_second, float_interval_sub p_second in |
| 490 |
map2 (fun dd_list di1 -> |
| 491 |
my_map2 (fun dd dj1 -> |
| 492 |
(d2_th0 * dj1) * di1 - d1_th0 * dd) dd_list d1_bounds) dd_ths d1_bounds in |
| 493 |
|
| 494 |
let dd_th = (GEN x_var o DISCH_ALL o end_itlist CONJ) (List.flatten dd_ths) in |
| 495 |
|
| 496 |
(***) |
| 497 |
let df_vars = map (fun i -> df_vars_array.(i)) (1--n) in |
| 498 |
let dd_vars = map (fun i -> map (fun j -> dd_vars_array.(i).(j)) (1--i)) (1--n) in |
| 499 |
|
| 500 |
let dfs = map (rand o concl) df_ths in |
| 501 |
let dds = map (map (rand o concl)) dd_ths in |
| 502 |
|
| 503 |
let inst_list = union (zip dfs df_vars) (zip (List.flatten dds) (List.flatten dd_vars)) in |
| 504 |
|
| 505 |
let th1 = (MY_PROVE_HYP diff2_f1_th o MY_PROVE_HYP cond_th o MY_PROVE_HYP f1_bound0 o |
| 506 |
MY_PROVE_HYP bounds_th o MY_PROVE_HYP domain_th o |
| 507 |
MY_PROVE_HYP dd_th o MY_PROVE_HYP df_th o |
| 508 |
INST([f1_tm, f_var; f_bounds_tm, f_bounds_var; |
| 509 |
domain_tm, domain_var; y_tm, y_var; w_tm, w_var; |
| 510 |
bounds_tm, bounds_var] @ inst_list)) inv_ths_array.(n) in |
| 511 |
let eq_th = unary_beta_gen_eq f1_tm x_var inv_op_real in |
| 512 |
m_taylor_interval_norm th1 eq_th;; |
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
(* ----------------------- *) |
| 517 |
(* sqrt *) |
| 518 |
(* ----------------------- *) |
| 519 |
|
| 520 |
let eval_m_taylor_sqrt2 n p_lin p_second taylor1_th = |
| 521 |
let domain_th, diff2_f1_th, lin1_th, second1_th = dest_m_taylor_thms n taylor1_th in |
| 522 |
let f1_tm = (rand o concl) diff2_f1_th in |
| 523 |
let domain_tm, y_tm, w_tm = dest_m_cell_domain (concl domain_th) in |
| 524 |
|
| 525 |
let ty = type_of y_tm in |
| 526 |
let x_var = mk_var ("x", ty) and |
| 527 |
y_var = mk_var ("y", ty) and |
| 528 |
w_var = mk_var ("w", ty) and |
| 529 |
f_var = mk_var ("f", type_of f1_tm) and |
| 530 |
domain_var = mk_var ("domain", type_of domain_tm) in |
| 531 |
|
| 532 |
let undisch = UNDISCH o SPEC x_var in |
| 533 |
|
| 534 |
let f1_bound0 = eval_m_taylor_bound n p_second taylor1_th in |
| 535 |
let f1_bound = undisch f1_bound0 in |
| 536 |
let f_bounds_tm = (rand o concl) f1_bound in |
| 537 |
|
| 538 |
(* cond *) |
| 539 |
let cond_th = check_interval_pos f_bounds_tm in |
| 540 |
|
| 541 |
let _, bounds1_th, df1_th = m_lin_approx_components n lin1_th in |
| 542 |
|
| 543 |
let bounds_th = float_interval_sqrt p_lin bounds1_th in |
| 544 |
let bounds_tm = (rand o concl) bounds_th in |
| 545 |
|
| 546 |
(* first partials *) |
| 547 |
let u_bounds = |
| 548 |
let inv, ( * ) = float_interval_inv p_lin, float_interval_mul p_lin in |
| 549 |
inv (two_interval * bounds_th) in |
| 550 |
|
| 551 |
let df1_ths' = all_n_components2 n df1_th in |
| 552 |
let df1_ths = map MY_BETA_RULE df1_ths' in |
| 553 |
|
| 554 |
let df_ths = |
| 555 |
let ( * ) = float_interval_mul p_lin in |
| 556 |
map (fun th1 -> u_bounds * th1) df1_ths in |
| 557 |
|
| 558 |
let df_th = end_itlist CONJ df_ths in |
| 559 |
|
| 560 |
(* second partials *) |
| 561 |
let dd_ths = |
| 562 |
let dd1 = all_n_components2 n (second_bounded_components n second1_th) in |
| 563 |
map2 (fun i -> map MY_BETA_RULE o all_n_components2 i o MY_BETA_RULE) (1--n) dd1 in |
| 564 |
|
| 565 |
let d1_bounds = map (fun i -> |
| 566 |
let th0 = eval_m_taylor_partial_bound n p_second i taylor1_th in |
| 567 |
undisch th0) (1--n) in |
| 568 |
|
| 569 |
(* u'(f x), u''(f x) *) |
| 570 |
let d1_th0, d2_th0 = |
| 571 |
let neg, sqrt, inv, ( * ) = float_interval_neg, float_interval_sqrt p_second, |
| 572 |
float_interval_inv p_second, float_interval_mul p_second in |
| 573 |
let two_sqrt_f = two_interval * sqrt f1_bound in |
| 574 |
inv two_sqrt_f, neg (inv (two_sqrt_f * (two_interval * f1_bound))) in |
| 575 |
|
| 576 |
let dd_ths = |
| 577 |
let ( * ), ( + ) = float_interval_mul p_second, float_interval_add p_second in |
| 578 |
map2 (fun dd_list di1 -> |
| 579 |
my_map2 (fun dd dj1 -> |
| 580 |
(d2_th0 * dj1) * di1 + d1_th0 * dd) dd_list d1_bounds) dd_ths d1_bounds in |
| 581 |
|
| 582 |
let dd_th = (GEN x_var o DISCH_ALL o end_itlist CONJ) (List.flatten dd_ths) in |
| 583 |
|
| 584 |
(***) |
| 585 |
let df_vars = map (fun i -> df_vars_array.(i)) (1--n) in |
| 586 |
let dd_vars = map (fun i -> map (fun j -> dd_vars_array.(i).(j)) (1--i)) (1--n) in |
| 587 |
|
| 588 |
let dfs = map (rand o concl) df_ths in |
| 589 |
let dds = map (map (rand o concl)) dd_ths in |
| 590 |
|
| 591 |
let inst_list = union (zip dfs df_vars) (zip (List.flatten dds) (List.flatten dd_vars)) in |
| 592 |
|
| 593 |
let th1 = (MY_PROVE_HYP diff2_f1_th o MY_PROVE_HYP cond_th o MY_PROVE_HYP f1_bound0 o |
| 594 |
MY_PROVE_HYP bounds_th o MY_PROVE_HYP domain_th o |
| 595 |
MY_PROVE_HYP dd_th o MY_PROVE_HYP df_th o |
| 596 |
INST([f1_tm, f_var; f_bounds_tm, f_bounds_var; |
| 597 |
domain_tm, domain_var; y_tm, y_var; w_tm, w_var; |
| 598 |
bounds_tm, bounds_var] @ inst_list)) sqrt_ths_array.(n) in |
| 599 |
let eq_th = unary_beta_gen_eq f1_tm x_var sqrt_tm in |
| 600 |
m_taylor_interval_norm th1 eq_th;; |
| 601 |
|
| 602 |
(* ----------------------- *) |
| 603 |
(* exp *) |
| 604 |
(* ----------------------- *) |
| 605 |
|
| 606 |
let eval_m_taylor_exp2 n p_lin p_second taylor1_th = |
| 607 |
let domain_th, diff2_f1_th, lin1_th, second1_th = dest_m_taylor_thms n taylor1_th in |
| 608 |
let f1_tm = (rand o concl) diff2_f1_th in |
| 609 |
let domain_tm, y_tm, w_tm = dest_m_cell_domain (concl domain_th) in |
| 610 |
|
| 611 |
let ty = type_of y_tm in |
| 612 |
let x_var = mk_var ("x", ty) and |
| 613 |
y_var = mk_var ("y", ty) and |
| 614 |
w_var = mk_var ("w", ty) and |
| 615 |
f_var = mk_var ("f", type_of f1_tm) and |
| 616 |
domain_var = mk_var ("domain", type_of domain_tm) in |
| 617 |
|
| 618 |
let undisch = UNDISCH o SPEC x_var in |
| 619 |
|
| 620 |
let f1_bound0 = eval_m_taylor_bound n p_second taylor1_th in |
| 621 |
let f1_bound = undisch f1_bound0 in |
| 622 |
let f_bounds_tm = (rand o concl) f1_bound in |
| 623 |
|
| 624 |
let _, bounds1_th, df1_th = m_lin_approx_components n lin1_th in |
| 625 |
|
| 626 |
let bounds_th = float_interval_exp p_lin bounds1_th in |
| 627 |
let bounds_tm = (rand o concl) bounds_th in |
| 628 |
|
| 629 |
(* first partials *) |
| 630 |
let u_bounds = |
| 631 |
let exp = float_interval_exp p_lin in |
| 632 |
exp bounds1_th in |
| 633 |
|
| 634 |
let df1_ths' = all_n_components2 n df1_th in |
| 635 |
let df1_ths = map MY_BETA_RULE df1_ths' in |
| 636 |
|
| 637 |
let df_ths = |
| 638 |
let ( * ) = float_interval_mul p_lin in |
| 639 |
map (fun th1 -> u_bounds * th1) df1_ths in |
| 640 |
|
| 641 |
let df_th = end_itlist CONJ df_ths in |
| 642 |
|
| 643 |
(* second partials *) |
| 644 |
let dd_ths = |
| 645 |
let dd1 = all_n_components2 n (second_bounded_components n second1_th) in |
| 646 |
map2 (fun i -> map MY_BETA_RULE o all_n_components2 i o MY_BETA_RULE) (1--n) dd1 in |
| 647 |
|
| 648 |
let d1_bounds = map (fun i -> |
| 649 |
let th0 = eval_m_taylor_partial_bound n p_second i taylor1_th in |
| 650 |
undisch th0) (1--n) in |
| 651 |
|
| 652 |
(* u'(f x), u''(f x) *) |
| 653 |
let d1_th0, d2_th0 = |
| 654 |
let exp = float_interval_exp p_second in |
| 655 |
let exp_f = exp f1_bound in |
| 656 |
exp_f, exp_f in |
| 657 |
|
| 658 |
let dd_ths = |
| 659 |
let ( * ), ( + ) = float_interval_mul p_second, float_interval_add p_second in |
| 660 |
map2 (fun dd_list di1 -> |
| 661 |
my_map2 (fun dd dj1 -> |
| 662 |
(d2_th0 * dj1) * di1 + d1_th0 * dd) dd_list d1_bounds) dd_ths d1_bounds in |
| 663 |
|
| 664 |
let dd_th = (GEN x_var o DISCH_ALL o end_itlist CONJ) (List.flatten dd_ths) in |
| 665 |
|
| 666 |
(***) |
| 667 |
let df_vars = map (fun i -> df_vars_array.(i)) (1--n) in |
| 668 |
let dd_vars = map (fun i -> map (fun j -> dd_vars_array.(i).(j)) (1--i)) (1--n) in |
| 669 |
|
| 670 |
let dfs = map (rand o concl) df_ths in |
| 671 |
let dds = map (map (rand o concl)) dd_ths in |
| 672 |
|
| 673 |
let inst_list = union (zip dfs df_vars) (zip (List.flatten dds) (List.flatten dd_vars)) in |
| 674 |
|
| 675 |
let th1 = (MY_PROVE_HYP diff2_f1_th o MY_PROVE_HYP f1_bound0 o |
| 676 |
MY_PROVE_HYP bounds_th o MY_PROVE_HYP domain_th o |
| 677 |
MY_PROVE_HYP dd_th o MY_PROVE_HYP df_th o |
| 678 |
INST([f1_tm, f_var; f_bounds_tm, f_bounds_var; |
| 679 |
domain_tm, domain_var; y_tm, y_var; w_tm, w_var; |
| 680 |
bounds_tm, bounds_var] @ inst_list)) exp_ths_array.(n) in |
| 681 |
let eq_th = unary_beta_gen_eq f1_tm x_var exp_tm in |
| 682 |
m_taylor_interval_norm th1 eq_th;; |
| 683 |
|
| 684 |
(* ----------------------- *) |
| 685 |
(* log *) |
| 686 |
(* ----------------------- *) |
| 687 |
|
| 688 |
let eval_m_taylor_log2 n p_lin p_second taylor1_th = |
| 689 |
let domain_th, diff2_f1_th, lin1_th, second1_th = dest_m_taylor_thms n taylor1_th in |
| 690 |
let f1_tm = (rand o concl) diff2_f1_th in |
| 691 |
let domain_tm, y_tm, w_tm = dest_m_cell_domain (concl domain_th) in |
| 692 |
|
| 693 |
let ty = type_of y_tm in |
| 694 |
let x_var = mk_var ("x", ty) and |
| 695 |
y_var = mk_var ("y", ty) and |
| 696 |
w_var = mk_var ("w", ty) and |
| 697 |
f_var = mk_var ("f", type_of f1_tm) and |
| 698 |
domain_var = mk_var ("domain", type_of domain_tm) in |
| 699 |
|
| 700 |
let undisch = UNDISCH o SPEC x_var in |
| 701 |
|
| 702 |
let f1_bound0 = eval_m_taylor_bound n p_second taylor1_th in |
| 703 |
let f1_bound = undisch f1_bound0 in |
| 704 |
let f_bounds_tm = (rand o concl) f1_bound in |
| 705 |
|
| 706 |
(* cond *) |
| 707 |
let cond_th = check_interval_pos f_bounds_tm in |
| 708 |
|
| 709 |
let _, bounds1_th, df1_th = m_lin_approx_components n lin1_th in |
| 710 |
|
| 711 |
let bounds_th = float_interval_log p_lin bounds1_th in |
| 712 |
let bounds_tm = (rand o concl) bounds_th in |
| 713 |
|
| 714 |
(* first partials *) |
| 715 |
let u_bounds = |
| 716 |
let inv = float_interval_inv p_lin in |
| 717 |
inv (bounds1_th) in |
| 718 |
|
| 719 |
let df1_ths' = all_n_components2 n df1_th in |
| 720 |
let df1_ths = map MY_BETA_RULE df1_ths' in |
| 721 |
|
| 722 |
let df_ths = |
| 723 |
let ( * ) = float_interval_mul p_lin in |
| 724 |
map (fun th1 -> u_bounds * th1) df1_ths in |
| 725 |
|
| 726 |
let df_th = end_itlist CONJ df_ths in |
| 727 |
|
| 728 |
(* second partials *) |
| 729 |
let dd_ths = |
| 730 |
let dd1 = all_n_components2 n (second_bounded_components n second1_th) in |
| 731 |
map2 (fun i -> map MY_BETA_RULE o all_n_components2 i o MY_BETA_RULE) (1--n) dd1 in |
| 732 |
|
| 733 |
let d1_bounds = map (fun i -> |
| 734 |
let th0 = eval_m_taylor_partial_bound n p_second i taylor1_th in |
| 735 |
undisch th0) (1--n) in |
| 736 |
|
| 737 |
(* u'(f x), u''(f x) *) |
| 738 |
let d1_th0, d2_th0 = |
| 739 |
let neg, pow2, inv = |
| 740 |
float_interval_neg, float_interval_pow p_second 2, float_interval_inv p_second in |
| 741 |
let inv_f = inv f1_bound in |
| 742 |
inv_f, neg (pow2 inv_f) in |
| 743 |
|
| 744 |
let dd_ths = |
| 745 |
let ( * ), ( + ) = float_interval_mul p_second, float_interval_add p_second in |
| 746 |
map2 (fun dd_list di1 -> |
| 747 |
my_map2 (fun dd dj1 -> |
| 748 |
(d2_th0 * dj1) * di1 + d1_th0 * dd) dd_list d1_bounds) dd_ths d1_bounds in |
| 749 |
|
| 750 |
let dd_th = (GEN x_var o DISCH_ALL o end_itlist CONJ) (List.flatten dd_ths) in |
| 751 |
|
| 752 |
(***) |
| 753 |
let df_vars = map (fun i -> df_vars_array.(i)) (1--n) in |
| 754 |
let dd_vars = map (fun i -> map (fun j -> dd_vars_array.(i).(j)) (1--i)) (1--n) in |
| 755 |
|
| 756 |
let dfs = map (rand o concl) df_ths in |
| 757 |
let dds = map (map (rand o concl)) dd_ths in |
| 758 |
|
| 759 |
let inst_list = union (zip dfs df_vars) (zip (List.flatten dds) (List.flatten dd_vars)) in |
| 760 |
|
| 761 |
let th1 = (MY_PROVE_HYP diff2_f1_th o MY_PROVE_HYP cond_th o MY_PROVE_HYP f1_bound0 o |
| 762 |
MY_PROVE_HYP bounds_th o MY_PROVE_HYP domain_th o |
| 763 |
MY_PROVE_HYP dd_th o MY_PROVE_HYP df_th o |
| 764 |
INST([f1_tm, f_var; f_bounds_tm, f_bounds_var; |
| 765 |
domain_tm, domain_var; y_tm, y_var; w_tm, w_var; |
| 766 |
bounds_tm, bounds_var] @ inst_list)) log_ths_array.(n) in |
| 767 |
let eq_th = unary_beta_gen_eq f1_tm x_var log_tm in |
| 768 |
m_taylor_interval_norm th1 eq_th;; |
| 769 |
|
| 770 |
(* ----------------------- *) |
| 771 |
(* atn *) |
| 772 |
(* ----------------------- *) |
| 773 |
|
| 774 |
let eval_m_taylor_atn2 n p_lin p_second taylor1_th = |
| 775 |
let domain_th, diff2_f1_th, lin1_th, second1_th = dest_m_taylor_thms n taylor1_th in |
| 776 |
let f1_tm = (rand o concl) diff2_f1_th in |
| 777 |
let domain_tm, y_tm, w_tm = dest_m_cell_domain (concl domain_th) in |
| 778 |
|
| 779 |
let ty = type_of y_tm in |
| 780 |
let x_var = mk_var ("x", ty) and |
| 781 |
y_var = mk_var ("y", ty) and |
| 782 |
w_var = mk_var ("w", ty) and |
| 783 |
f_var = mk_var ("f", type_of f1_tm) and |
| 784 |
domain_var = mk_var ("domain", type_of domain_tm) in |
| 785 |
|
| 786 |
let undisch = UNDISCH o SPEC x_var in |
| 787 |
|
| 788 |
let f1_bound0 = eval_m_taylor_bound n p_second taylor1_th in |
| 789 |
let f1_bound = undisch f1_bound0 in |
| 790 |
let f_bounds_tm = (rand o concl) f1_bound in |
| 791 |
|
| 792 |
let _, bounds1_th, df1_th = m_lin_approx_components n lin1_th in |
| 793 |
|
| 794 |
let bounds_th = float_interval_atn p_lin bounds1_th in |
| 795 |
let bounds_tm = (rand o concl) bounds_th in |
| 796 |
|
| 797 |
(* first partials *) |
| 798 |
let u_bounds = |
| 799 |
let inv, ( + ), ( * ) = float_interval_inv p_lin, |
| 800 |
float_interval_add p_lin, float_interval_mul p_lin in |
| 801 |
inv (one_interval + bounds1_th * bounds1_th) in |
| 802 |
|
| 803 |
let df1_ths' = all_n_components2 n df1_th in |
| 804 |
let df1_ths = map MY_BETA_RULE df1_ths' in |
| 805 |
|
| 806 |
let df_ths = |
| 807 |
let ( * ) = float_interval_mul p_lin in |
| 808 |
map (fun th1 -> u_bounds * th1) df1_ths in |
| 809 |
|
| 810 |
let df_th = end_itlist CONJ df_ths in |
| 811 |
|
| 812 |
(* second partials *) |
| 813 |
let dd_ths = |
| 814 |
let dd1 = all_n_components2 n (second_bounded_components n second1_th) in |
| 815 |
map2 (fun i -> map MY_BETA_RULE o all_n_components2 i o MY_BETA_RULE) (1--n) dd1 in |
| 816 |
|
| 817 |
let d1_bounds = map (fun i -> |
| 818 |
let th0 = eval_m_taylor_partial_bound n p_second i taylor1_th in |
| 819 |
undisch th0) (1--n) in |
| 820 |
|
| 821 |
(* u'(f x), u''(f x) *) |
| 822 |
let d1_th0, d2_th0 = |
| 823 |
let neg, inv, ( + ), ( * ), pow2 = float_interval_neg, float_interval_inv p_second, |
| 824 |
float_interval_add p_second, float_interval_mul p_second, float_interval_pow p_second 2 in |
| 825 |
let inv_one_ff = inv (one_interval + f1_bound * f1_bound) in |
| 826 |
inv_one_ff, (neg_two_interval * f1_bound) * pow2 inv_one_ff in |
| 827 |
|
| 828 |
let dd_ths = |
| 829 |
let ( * ), ( + ) = float_interval_mul p_second, float_interval_add p_second in |
| 830 |
map2 (fun dd_list di1 -> |
| 831 |
my_map2 (fun dd dj1 -> |
| 832 |
(d2_th0 * dj1) * di1 + d1_th0 * dd) dd_list d1_bounds) dd_ths d1_bounds in |
| 833 |
|
| 834 |
let dd_th = (GEN x_var o DISCH_ALL o end_itlist CONJ) (List.flatten dd_ths) in |
| 835 |
|
| 836 |
(***) |
| 837 |
let df_vars = map (fun i -> df_vars_array.(i)) (1--n) in |
| 838 |
let dd_vars = map (fun i -> map (fun j -> dd_vars_array.(i).(j)) (1--i)) (1--n) in |
| 839 |
|
| 840 |
let dfs = map (rand o concl) df_ths in |
| 841 |
let dds = map (map (rand o concl)) dd_ths in |
| 842 |
|
| 843 |
let inst_list = union (zip dfs df_vars) (zip (List.flatten dds) (List.flatten dd_vars)) in |
| 844 |
|
| 845 |
let th1 = (MY_PROVE_HYP diff2_f1_th o MY_PROVE_HYP f1_bound0 o |
| 846 |
MY_PROVE_HYP bounds_th o MY_PROVE_HYP domain_th o |
| 847 |
MY_PROVE_HYP dd_th o MY_PROVE_HYP df_th o |
| 848 |
INST([f1_tm, f_var; f_bounds_tm, f_bounds_var; |
| 849 |
domain_tm, domain_var; y_tm, y_var; w_tm, w_var; |
| 850 |
bounds_tm, bounds_var] @ inst_list)) atn_ths_array.(n) in |
| 851 |
let eq_th = unary_beta_gen_eq f1_tm x_var atn_tm in |
| 852 |
m_taylor_interval_norm th1 eq_th;; |
| 853 |
|
| 854 |
|
| 855 |
(* ----------------------- *) |
| 856 |
(* cos *) |
| 857 |
(* ----------------------- *) |
| 858 |
|
| 859 |
let eval_m_taylor_cos2 n p_lin p_second taylor1_th = |
| 860 |
let domain_th, diff2_f1_th, lin1_th, second1_th = dest_m_taylor_thms n taylor1_th in |
| 861 |
let f1_tm = (rand o concl) diff2_f1_th in |
| 862 |
let domain_tm, y_tm, w_tm = dest_m_cell_domain (concl domain_th) in |
| 863 |
|
| 864 |
let ty = type_of y_tm in |
| 865 |
let x_var = mk_var ("x", ty) and |
| 866 |
y_var = mk_var ("y", ty) and |
| 867 |
w_var = mk_var ("w", ty) and |
| 868 |
f_var = mk_var ("f", type_of f1_tm) and |
| 869 |
domain_var = mk_var ("domain", type_of domain_tm) in |
| 870 |
|
| 871 |
let undisch = UNDISCH o SPEC x_var in |
| 872 |
|
| 873 |
let f1_bound0 = eval_m_taylor_bound n p_second taylor1_th in |
| 874 |
let f1_bound = undisch f1_bound0 in |
| 875 |
let f_bounds_tm = (rand o concl) f1_bound in |
| 876 |
|
| 877 |
let _, bounds1_th, df1_th = m_lin_approx_components n lin1_th in |
| 878 |
|
| 879 |
let bounds_th = float_interval_cos p_lin bounds1_th in |
| 880 |
let bounds_tm = (rand o concl) bounds_th in |
| 881 |
|
| 882 |
(* first partials *) |
| 883 |
let u_bounds = |
| 884 |
let sin, neg = float_interval_sin p_lin, float_interval_neg in |
| 885 |
neg (sin bounds1_th) in |
| 886 |
|
| 887 |
let df1_ths' = all_n_components2 n df1_th in |
| 888 |
let df1_ths = map MY_BETA_RULE df1_ths' in |
| 889 |
|
| 890 |
let df_ths = |
| 891 |
let ( * ) = float_interval_mul p_lin in |
| 892 |
map (fun th1 -> u_bounds * th1) df1_ths in |
| 893 |
|
| 894 |
let df_th = end_itlist CONJ df_ths in |
| 895 |
|
| 896 |
(* second partials *) |
| 897 |
let dd_ths = |
| 898 |
let dd1 = all_n_components2 n (second_bounded_components n second1_th) in |
| 899 |
map2 (fun i -> map MY_BETA_RULE o all_n_components2 i o MY_BETA_RULE) (1--n) dd1 in |
| 900 |
|
| 901 |
let d1_bounds = map (fun i -> |
| 902 |
let th0 = eval_m_taylor_partial_bound n p_second i taylor1_th in |
| 903 |
undisch th0) (1--n) in |
| 904 |
|
| 905 |
(* u'(f x), u''(f x) *) |
| 906 |
let d1_th0, d2_th0 = |
| 907 |
let cos, sin = float_interval_cos p_second, float_interval_sin p_second in |
| 908 |
sin f1_bound, cos f1_bound in |
| 909 |
|
| 910 |
let dd_ths = |
| 911 |
let ( * ), ( + ) = float_interval_mul p_second, float_interval_add p_second in |
| 912 |
let neg = float_interval_neg in |
| 913 |
map2 (fun dd_list di1 -> |
| 914 |
my_map2 (fun dd dj1 -> |
| 915 |
neg ((d2_th0 * dj1) * di1 + d1_th0 * dd)) dd_list d1_bounds) dd_ths d1_bounds in |
| 916 |
|
| 917 |
let dd_th = (GEN x_var o DISCH_ALL o end_itlist CONJ) (List.flatten dd_ths) in |
| 918 |
|
| 919 |
(***) |
| 920 |
let df_vars = map (fun i -> df_vars_array.(i)) (1--n) in |
| 921 |
let dd_vars = map (fun i -> map (fun j -> dd_vars_array.(i).(j)) (1--i)) (1--n) in |
| 922 |
|
| 923 |
let dfs = map (rand o concl) df_ths in |
| 924 |
let dds = map (map (rand o concl)) dd_ths in |
| 925 |
|
| 926 |
let inst_list = union (zip dfs df_vars) (zip (List.flatten dds) (List.flatten dd_vars)) in |
| 927 |
|
| 928 |
let th1 = (MY_PROVE_HYP diff2_f1_th o MY_PROVE_HYP f1_bound0 o |
| 929 |
MY_PROVE_HYP bounds_th o MY_PROVE_HYP domain_th o |
| 930 |
MY_PROVE_HYP dd_th o MY_PROVE_HYP df_th o |
| 931 |
INST([f1_tm, f_var; f_bounds_tm, f_bounds_var; |
| 932 |
domain_tm, domain_var; y_tm, y_var; w_tm, w_var; |
| 933 |
bounds_tm, bounds_var] @ inst_list)) cos_ths_array.(n) in |
| 934 |
let eq_th = unary_beta_gen_eq f1_tm x_var cos_tm in |
| 935 |
m_taylor_interval_norm th1 eq_th;; |
| 936 |
|
| 937 |
|
| 938 |
(* ----------------------- *) |
| 939 |
(* sin *) |
| 940 |
(* ----------------------- *) |
| 941 |
|
| 942 |
let eval_m_taylor_sin2 n p_lin p_second taylor1_th = |
| 943 |
let domain_th, diff2_f1_th, lin1_th, second1_th = dest_m_taylor_thms n taylor1_th in |
| 944 |
let f1_tm = (rand o concl) diff2_f1_th in |
| 945 |
let domain_tm, y_tm, w_tm = dest_m_cell_domain (concl domain_th) in |
| 946 |
|
| 947 |
let ty = type_of y_tm in |
| 948 |
let x_var = mk_var ("x", ty) and |
| 949 |
y_var = mk_var ("y", ty) and |
| 950 |
w_var = mk_var ("w", ty) and |
| 951 |
f_var = mk_var ("f", type_of f1_tm) and |
| 952 |
domain_var = mk_var ("domain", type_of domain_tm) in |
| 953 |
|
| 954 |
let undisch = UNDISCH o SPEC x_var in |
| 955 |
|
| 956 |
let f1_bound0 = eval_m_taylor_bound n p_second taylor1_th in |
| 957 |
let f1_bound = undisch f1_bound0 in |
| 958 |
let f_bounds_tm = (rand o concl) f1_bound in |
| 959 |
|
| 960 |
let _, bounds1_th, df1_th = m_lin_approx_components n lin1_th in |
| 961 |
|
| 962 |
let bounds_th = float_interval_sin p_lin bounds1_th in |
| 963 |
let bounds_tm = (rand o concl) bounds_th in |
| 964 |
|
| 965 |
(* first partials *) |
| 966 |
let u_bounds = |
| 967 |
let cos = float_interval_cos p_lin in |
| 968 |
cos bounds1_th in |
| 969 |
|
| 970 |
let df1_ths' = all_n_components2 n df1_th in |
| 971 |
let df1_ths = map MY_BETA_RULE df1_ths' in |
| 972 |
|
| 973 |
let df_ths = |
| 974 |
let ( * ) = float_interval_mul p_lin in |
| 975 |
map (fun th1 -> u_bounds * th1) df1_ths in |
| 976 |
|
| 977 |
let df_th = end_itlist CONJ df_ths in |
| 978 |
|
| 979 |
(* second partials *) |
| 980 |
let dd_ths = |
| 981 |
let dd1 = all_n_components2 n (second_bounded_components n second1_th) in |
| 982 |
map2 (fun i -> map MY_BETA_RULE o all_n_components2 i o MY_BETA_RULE) (1--n) dd1 in |
| 983 |
|
| 984 |
let d1_bounds = map (fun i -> |
| 985 |
let th0 = eval_m_taylor_partial_bound n p_second i taylor1_th in |
| 986 |
undisch th0) (1--n) in |
| 987 |
|
| 988 |
(* u'(f x), u''(f x) *) |
| 989 |
let d1_th0, d2_th0 = |
| 990 |
let cos, sin = float_interval_cos p_second, float_interval_sin p_second in |
| 991 |
let neg = float_interval_neg in |
| 992 |
cos f1_bound, neg (sin f1_bound) in |
| 993 |
|
| 994 |
let dd_ths = |
| 995 |
let ( * ), ( + ) = float_interval_mul p_second, float_interval_add p_second in |
| 996 |
map2 (fun dd_list di1 -> |
| 997 |
my_map2 (fun dd dj1 -> |
| 998 |
(d2_th0 * dj1) * di1 + d1_th0 * dd) dd_list d1_bounds) dd_ths d1_bounds in |
| 999 |
|
| 1000 |
let dd_th = (GEN x_var o DISCH_ALL o end_itlist CONJ) (List.flatten dd_ths) in |
| 1001 |
|
| 1002 |
(***) |
| 1003 |
let df_vars = map (fun i -> df_vars_array.(i)) (1--n) in |
| 1004 |
let dd_vars = map (fun i -> map (fun j -> dd_vars_array.(i).(j)) (1--i)) (1--n) in |
| 1005 |
|
| 1006 |
let dfs = map (rand o concl) df_ths in |
| 1007 |
let dds = map (map (rand o concl)) dd_ths in |
| 1008 |
|
| 1009 |
let inst_list = union (zip dfs df_vars) (zip (List.flatten dds) (List.flatten dd_vars)) in |
| 1010 |
|
| 1011 |
let th1 = (MY_PROVE_HYP diff2_f1_th o MY_PROVE_HYP f1_bound0 o |
| 1012 |
MY_PROVE_HYP bounds_th o MY_PROVE_HYP domain_th o |
| 1013 |
MY_PROVE_HYP dd_th o MY_PROVE_HYP df_th o |
| 1014 |
INST([f1_tm, f_var; f_bounds_tm, f_bounds_var; |
| 1015 |
domain_tm, domain_var; y_tm, y_var; w_tm, w_var; |
| 1016 |
bounds_tm, bounds_var] @ inst_list)) sin_ths_array.(n) in |
| 1017 |
let eq_th = unary_beta_gen_eq f1_tm x_var sin_tm in |
| 1018 |
m_taylor_interval_norm th1 eq_th;; |
| 1019 |
|
| 1020 |
|
| 1021 |
(* ----------------------- *) |
| 1022 |
(* asn *) |
| 1023 |
(* ----------------------- *) |
| 1024 |
|
| 1025 |
let eval_m_taylor_asn2 n p_lin p_second taylor1_th = |
| 1026 |
let domain_th, diff2_f1_th, lin1_th, second1_th = dest_m_taylor_thms n taylor1_th in |
| 1027 |
let f1_tm = (rand o concl) diff2_f1_th in |
| 1028 |
let domain_tm, y_tm, w_tm = dest_m_cell_domain (concl domain_th) in |
| 1029 |
|
| 1030 |
let ty = type_of y_tm in |
| 1031 |
let x_var = mk_var ("x", ty) and |
| 1032 |
y_var = mk_var ("y", ty) and |
| 1033 |
w_var = mk_var ("w", ty) and |
| 1034 |
f_var = mk_var ("f", type_of f1_tm) and |
| 1035 |
domain_var = mk_var ("domain", type_of domain_tm) in |
| 1036 |
|
| 1037 |
let undisch = UNDISCH o SPEC x_var in |
| 1038 |
|
| 1039 |
let f1_bound0 = eval_m_taylor_bound n p_second taylor1_th in |
| 1040 |
let f1_bound = undisch f1_bound0 in |
| 1041 |
let f_bounds_tm = (rand o concl) f1_bound in |
| 1042 |
|
| 1043 |
(* cond *) |
| 1044 |
let cond_th = EQT_ELIM (check_interval_iabs f_bounds_tm one_float) in |
| 1045 |
|
| 1046 |
let _, bounds1_th, df1_th = m_lin_approx_components n lin1_th in |
| 1047 |
|
| 1048 |
let bounds_th = float_interval_asn p_lin bounds1_th in |
| 1049 |
let bounds_tm = (rand o concl) bounds_th in |
| 1050 |
|
| 1051 |
(* first partials *) |
| 1052 |
let u_bounds = |
| 1053 |
let inv, sqrt = float_interval_inv p_lin, float_interval_sqrt p_lin in |
| 1054 |
let ( * ), ( - ) = float_interval_mul p_lin, float_interval_sub p_lin in |
| 1055 |
inv (sqrt (one_interval - bounds1_th * bounds1_th)) in |
| 1056 |
|
| 1057 |
let df1_ths' = all_n_components2 n df1_th in |
| 1058 |
let df1_ths = map MY_BETA_RULE df1_ths' in |
| 1059 |
|
| 1060 |
let df_ths = |
| 1061 |
let ( * ) = float_interval_mul p_lin in |
| 1062 |
map (fun th1 -> u_bounds * th1) df1_ths in |
| 1063 |
|
| 1064 |
let df_th = end_itlist CONJ df_ths in |
| 1065 |
|
| 1066 |
(* second partials *) |
| 1067 |
let dd_ths = |
| 1068 |
let dd1 = all_n_components2 n (second_bounded_components n second1_th) in |
| 1069 |
map2 (fun i -> map MY_BETA_RULE o all_n_components2 i o MY_BETA_RULE) (1--n) dd1 in |
| 1070 |
|
| 1071 |
let d1_bounds = map (fun i -> |
| 1072 |
let th0 = eval_m_taylor_partial_bound n p_second i taylor1_th in |
| 1073 |
undisch th0) (1--n) in |
| 1074 |
|
| 1075 |
(* u'(f x), u''(f x) *) |
| 1076 |
let d1_th0, d2_th0 = |
| 1077 |
let sqrt, inv = float_interval_sqrt p_second, float_interval_inv p_second in |
| 1078 |
let ( - ), ( * ), ( / ), pow3 = float_interval_sub p_second, float_interval_mul p_second, |
| 1079 |
float_interval_div p_second, float_interval_pow p_second 3 in |
| 1080 |
let ff_1 = one_interval - f1_bound * f1_bound in |
| 1081 |
inv (sqrt ff_1), f1_bound / sqrt (pow3 ff_1) in |
| 1082 |
|
| 1083 |
let dd_ths = |
| 1084 |
let ( * ), ( + ) = float_interval_mul p_second, float_interval_add p_second in |
| 1085 |
map2 (fun dd_list di1 -> |
| 1086 |
my_map2 (fun dd dj1 -> |
| 1087 |
(d2_th0 * dj1) * di1 + d1_th0 * dd) dd_list d1_bounds) dd_ths d1_bounds in |
| 1088 |
|
| 1089 |
let dd_th = (GEN x_var o DISCH_ALL o end_itlist CONJ) (List.flatten dd_ths) in |
| 1090 |
|
| 1091 |
(***) |
| 1092 |
let df_vars = map (fun i -> df_vars_array.(i)) (1--n) in |
| 1093 |
let dd_vars = map (fun i -> map (fun j -> dd_vars_array.(i).(j)) (1--i)) (1--n) in |
| 1094 |
|
| 1095 |
let dfs = map (rand o concl) df_ths in |
| 1096 |
let dds = map (map (rand o concl)) dd_ths in |
| 1097 |
|
| 1098 |
let inst_list = union (zip dfs df_vars) (zip (List.flatten dds) (List.flatten dd_vars)) in |
| 1099 |
|
| 1100 |
let th1 = (MY_PROVE_HYP diff2_f1_th o MY_PROVE_HYP cond_th o MY_PROVE_HYP f1_bound0 o |
| 1101 |
MY_PROVE_HYP bounds_th o MY_PROVE_HYP domain_th o |
| 1102 |
MY_PROVE_HYP dd_th o MY_PROVE_HYP df_th o |
| 1103 |
INST([f1_tm, f_var; f_bounds_tm, f_bounds_var; |
| 1104 |
domain_tm, domain_var; y_tm, y_var; w_tm, w_var; |
| 1105 |
bounds_tm, bounds_var] @ inst_list)) asn_ths_array.(n) in |
| 1106 |
let eq_th = unary_beta_gen_eq f1_tm x_var asn_tm in |
| 1107 |
m_taylor_interval_norm th1 eq_th;; |
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
(* ----------------------- *) |
| 1112 |
(* acs *) |
| 1113 |
(* ----------------------- *) |
| 1114 |
|
| 1115 |
let eval_m_taylor_acs2 n p_lin p_second taylor1_th = |
| 1116 |
let domain_th, diff2_f1_th, lin1_th, second1_th = dest_m_taylor_thms n taylor1_th in |
| 1117 |
let f1_tm = (rand o concl) diff2_f1_th in |
| 1118 |
let domain_tm, y_tm, w_tm = dest_m_cell_domain (concl domain_th) in |
| 1119 |
|
| 1120 |
let ty = type_of y_tm in |
| 1121 |
let x_var = mk_var ("x", ty) and |
| 1122 |
y_var = mk_var ("y", ty) and |
| 1123 |
w_var = mk_var ("w", ty) and |
| 1124 |
f_var = mk_var ("f", type_of f1_tm) and |
| 1125 |
domain_var = mk_var ("domain", type_of domain_tm) in |
| 1126 |
|
| 1127 |
let undisch = UNDISCH o SPEC x_var in |
| 1128 |
|
| 1129 |
let f1_bound0 = eval_m_taylor_bound n p_second taylor1_th in |
| 1130 |
let f1_bound = undisch f1_bound0 in |
| 1131 |
let f_bounds_tm = (rand o concl) f1_bound in |
| 1132 |
|
| 1133 |
(* cond *) |
| 1134 |
let cond_th = EQT_ELIM (check_interval_iabs f_bounds_tm one_float) in |
| 1135 |
|
| 1136 |
let _, bounds1_th, df1_th = m_lin_approx_components n lin1_th in |
| 1137 |
|
| 1138 |
let bounds_th = float_interval_acs p_lin bounds1_th in |
| 1139 |
let bounds_tm = (rand o concl) bounds_th in |
| 1140 |
|
| 1141 |
(* first partials *) |
| 1142 |
let u_bounds = |
| 1143 |
let inv, sqrt, neg = float_interval_inv p_lin, float_interval_sqrt p_lin, float_interval_neg in |
| 1144 |
let ( * ), ( - ) = float_interval_mul p_lin, float_interval_sub p_lin in |
| 1145 |
neg (inv (sqrt (one_interval - bounds1_th * bounds1_th))) in |
| 1146 |
|
| 1147 |
let df1_ths' = all_n_components2 n df1_th in |
| 1148 |
let df1_ths = map MY_BETA_RULE df1_ths' in |
| 1149 |
|
| 1150 |
let df_ths = |
| 1151 |
let ( * ) = float_interval_mul p_lin in |
| 1152 |
map (fun th1 -> u_bounds * th1) df1_ths in |
| 1153 |
|
| 1154 |
let df_th = end_itlist CONJ df_ths in |
| 1155 |
|
| 1156 |
(* second partials *) |
| 1157 |
let dd_ths = |
| 1158 |
let dd1 = all_n_components2 n (second_bounded_components n second1_th) in |
| 1159 |
map2 (fun i -> map MY_BETA_RULE o all_n_components2 i o MY_BETA_RULE) (1--n) dd1 in |
| 1160 |
|
| 1161 |
let d1_bounds = map (fun i -> |
| 1162 |
let th0 = eval_m_taylor_partial_bound n p_second i taylor1_th in |
| 1163 |
undisch th0) (1--n) in |
| 1164 |
|
| 1165 |
(* u'(f x), u''(f x) *) |
| 1166 |
let d1_th0, d2_th0 = |
| 1167 |
let neg, sqrt, inv = float_interval_neg, float_interval_sqrt p_second, float_interval_inv p_second in |
| 1168 |
let ( - ), ( * ), ( / ), pow3 = float_interval_sub p_second, float_interval_mul p_second, |
| 1169 |
float_interval_div p_second, float_interval_pow p_second 3 in |
| 1170 |
let ff_1 = one_interval - f1_bound * f1_bound in |
| 1171 |
inv (sqrt ff_1), neg (f1_bound / sqrt (pow3 ff_1)) in |
| 1172 |
|
| 1173 |
let dd_ths = |
| 1174 |
let ( * ), ( - ) = float_interval_mul p_second, float_interval_sub p_second in |
| 1175 |
map2 (fun dd_list di1 -> |
| 1176 |
my_map2 (fun dd dj1 -> |
| 1177 |
(d2_th0 * dj1) * di1 - d1_th0 * dd) dd_list d1_bounds) dd_ths d1_bounds in |
| 1178 |
|
| 1179 |
let dd_th = (GEN x_var o DISCH_ALL o end_itlist CONJ) (List.flatten dd_ths) in |
| 1180 |
|
| 1181 |
(***) |
| 1182 |
let df_vars = map (fun i -> df_vars_array.(i)) (1--n) in |
| 1183 |
let dd_vars = map (fun i -> map (fun j -> dd_vars_array.(i).(j)) (1--i)) (1--n) in |
| 1184 |
|
| 1185 |
let dfs = map (rand o concl) df_ths in |
| 1186 |
let dds = map (map (rand o concl)) dd_ths in |
| 1187 |
|
| 1188 |
let inst_list = union (zip dfs df_vars) (zip (List.flatten dds) (List.flatten dd_vars)) in |
| 1189 |
|
| 1190 |
let th1 = (MY_PROVE_HYP diff2_f1_th o MY_PROVE_HYP cond_th o MY_PROVE_HYP f1_bound0 o |
| 1191 |
MY_PROVE_HYP bounds_th o MY_PROVE_HYP domain_th o |
| 1192 |
MY_PROVE_HYP dd_th o MY_PROVE_HYP df_th o |
| 1193 |
INST([f1_tm, f_var; f_bounds_tm, f_bounds_var; |
| 1194 |
domain_tm, domain_var; y_tm, y_var; w_tm, w_var; |
| 1195 |
bounds_tm, bounds_var] @ inst_list)) acs_ths_array.(n) in |
| 1196 |
let eq_th = unary_beta_gen_eq f1_tm x_var acs_tm in |
| 1197 |
m_taylor_interval_norm th1 eq_th;; |
| 1198 |
|
| 1199 |
|
| 1200 |
(* ----------------------- *) |
| 1201 |
(* matan *) |
| 1202 |
(* ----------------------- *) |
| 1203 |
|
| 1204 |
let eval_m_taylor_matan2 n p_lin p_second taylor1_th = |
| 1205 |
let domain_th, diff2_f1_th, lin1_th, second1_th = dest_m_taylor_thms n taylor1_th in |
| 1206 |
let f1_tm = (rand o concl) diff2_f1_th in |
| 1207 |
let domain_tm, y_tm, w_tm = dest_m_cell_domain (concl domain_th) in |
| 1208 |
|
| 1209 |
let ty = type_of y_tm in |
| 1210 |
let x_var = mk_var ("x", ty) and |
| 1211 |
y_var = mk_var ("y", ty) and |
| 1212 |
w_var = mk_var ("w", ty) and |
| 1213 |
f_var = mk_var ("f", type_of f1_tm) and |
| 1214 |
domain_var = mk_var ("domain", type_of domain_tm) in |
| 1215 |
|
| 1216 |
let undisch = UNDISCH o SPEC x_var in |
| 1217 |
|
| 1218 |
let f1_bound0 = eval_m_taylor_bound n p_second taylor1_th in |
| 1219 |
let f1_bound = undisch f1_bound0 in |
| 1220 |
let f_bounds_tm = (rand o concl) f1_bound in |
| 1221 |
|
| 1222 |
(* cond *) |
| 1223 |
let cond_th = check_interval_gt neg_one_float f_bounds_tm in |
| 1224 |
|
| 1225 |
let _, bounds1_th, df1_th = m_lin_approx_components n lin1_th in |
| 1226 |
|
| 1227 |
let bounds_th = float_interval_matan p_lin bounds1_th in |
| 1228 |
let bounds_tm = (rand o concl) bounds_th in |
| 1229 |
|
| 1230 |
(* first partials *) |
| 1231 |
let u_bounds = |
| 1232 |
float_interval_dmatan p_lin bounds1_th in |
| 1233 |
|
| 1234 |
let df1_ths' = all_n_components2 n df1_th in |
| 1235 |
let df1_ths = map MY_BETA_RULE df1_ths' in |
| 1236 |
|
| 1237 |
let df_ths = |
| 1238 |
let ( * ) = float_interval_mul p_lin in |
| 1239 |
map (fun th1 -> u_bounds * th1) df1_ths in |
| 1240 |
|
| 1241 |
let df_th = end_itlist CONJ df_ths in |
| 1242 |
|
| 1243 |
(* second partials *) |
| 1244 |
let dd_ths = |
| 1245 |
let dd1 = all_n_components2 n (second_bounded_components n second1_th) in |
| 1246 |
map2 (fun i -> map MY_BETA_RULE o all_n_components2 i o MY_BETA_RULE) (1--n) dd1 in |
| 1247 |
|
| 1248 |
let d1_bounds = map (fun i -> |
| 1249 |
let th0 = eval_m_taylor_partial_bound n p_second i taylor1_th in |
| 1250 |
undisch th0) (1--n) in |
| 1251 |
|
| 1252 |
(* u'(f x), u''(f x) *) |
| 1253 |
let d1_th0, d2_th0 = |
| 1254 |
float_interval_dmatan p_second f1_bound, |
| 1255 |
float_interval_ddmatan p_second f1_bound in |
| 1256 |
|
| 1257 |
let dd_ths = |
| 1258 |
let ( * ), ( + ) = float_interval_mul p_second, float_interval_add p_second in |
| 1259 |
map2 (fun dd_list di1 -> |
| 1260 |
my_map2 (fun dd dj1 -> |
| 1261 |
(d2_th0 * dj1) * di1 + d1_th0 * dd) dd_list d1_bounds) dd_ths d1_bounds in |
| 1262 |
|
| 1263 |
let dd_th = (GEN x_var o DISCH_ALL o end_itlist CONJ) (List.flatten dd_ths) in |
| 1264 |
|
| 1265 |
(***) |
| 1266 |
let df_vars = map (fun i -> df_vars_array.(i)) (1--n) in |
| 1267 |
let dd_vars = map (fun i -> map (fun j -> dd_vars_array.(i).(j)) (1--i)) (1--n) in |
| 1268 |
|
| 1269 |
let dfs = map (rand o concl) df_ths in |
| 1270 |
let dds = map (map (rand o concl)) dd_ths in |
| 1271 |
|
| 1272 |
let inst_list = union (zip dfs df_vars) (zip (List.flatten dds) (List.flatten dd_vars)) in |
| 1273 |
|
| 1274 |
let th1 = (MY_PROVE_HYP diff2_f1_th o MY_PROVE_HYP cond_th o MY_PROVE_HYP f1_bound0 o |
| 1275 |
MY_PROVE_HYP bounds_th o MY_PROVE_HYP domain_th o |
| 1276 |
MY_PROVE_HYP dd_th o MY_PROVE_HYP df_th o |
| 1277 |
INST([f1_tm, f_var; f_bounds_tm, f_bounds_var; |
| 1278 |
domain_tm, domain_var; y_tm, y_var; w_tm, w_var; |
| 1279 |
bounds_tm, bounds_var] @ inst_list)) matan_ths_array.(n) in |
| 1280 |
let eq_th = unary_beta_gen_eq f1_tm x_var matan_tm in |
| 1281 |
m_taylor_interval_norm th1 eq_th;; |
| 1282 |
|
| 1283 |
end;; |
| 1284 |
|
| 1285 |
(* |
| 1286 |
needs "Formal_ineqs/informal/informal_taylor.hl";; |
| 1287 |
needs "Formal_ineqs/verifier/m_verifier_build.hl";; |
| 1288 |
open M_verifier_build;; |
| 1289 |
|
| 1290 |
#install_printer Informal_float.print_ifloat;; |
| 1291 |
#install_printer Informal_interval.print_interval;; |
| 1292 |
|
| 1293 |
open M_taylor_arith2;; |
| 1294 |
open M_taylor;; |
| 1295 |
open Arith_float;; |
| 1296 |
open More_float;; |
| 1297 |
|
| 1298 |
Informal_taylor.mk_m_center_domain;; |
| 1299 |
|
| 1300 |
let x_list = mk_list ([mk_float 1 0; mk_float 1 (-1)], `:real`);; |
| 1301 |
let z_list = mk_list ([mk_float 350 (-1); mk_float 350 (-1)], `:real`);; |
| 1302 |
|
| 1303 |
let x_inf = [Informal_float.mk_float (1) 0; Informal_float.mk_float (1) (-1)];; |
| 1304 |
let y_inf = [Informal_float.mk_float (350) (-1); Informal_float.mk_float (350) (-1)];; |
| 1305 |
|
| 1306 |
let dom_th = mk_m_center_domain 2 5 x_list z_list;; |
| 1307 |
let dom_inf = Informal_taylor.mk_m_center_domain 5 x_inf y_inf;; |
| 1308 |
|
| 1309 |
|
| 1310 |
let f1, f2 = mk_verification_functions_poly 5 `\x:real^2. x$1 - #1.1`;; |
| 1311 |
|
| 1312 |
let f1, f2 = mk_verification_functions_poly 5 `\x:real^2. x$1 pow 2 + x$2 - &10`;; |
| 1313 |
|
| 1314 |
let t_th = f1.taylor 5 5 dom_th;; |
| 1315 |
let t_inf = f2.Informal_verifier.taylor 5 5 dom_inf;; |
| 1316 |
|
| 1317 |
eval_m_taylor_bound 2 5 t_th;; |
| 1318 |
|
| 1319 |
eval_m_taylor_abs2 2 5 t_th;; |
| 1320 |
Informal_taylor.eval_m_taylor_abs 5 t_inf;; |
| 1321 |
|
| 1322 |
let t2_th = eval_m_taylor_neg2 2 t_th;; |
| 1323 |
eval_m_taylor_abs2 2 5 (eval_m_taylor_abs2 2 5 t2_th);; |
| 1324 |
|
| 1325 |
let t2_inf = Informal_taylor.eval_m_taylor_neg t_inf;; |
| 1326 |
Informal_taylor.eval_m_taylor_abs 5 (Informal_taylor.eval_m_taylor_abs 5 t2_inf);; |
| 1327 |
|
| 1328 |
eval_m_taylor_neg2_raw false 2 t_th;; |
| 1329 |
|
| 1330 |
eval_m_taylor_sqrt2 2 5 5 t_th;; |
| 1331 |
|
| 1332 |
eval_m_taylor_exp2 2 5 5 t_th;; |
| 1333 |
Informal_taylor.eval_m_taylor_exp 5 5 t_inf;; |
| 1334 |
|
| 1335 |
eval_m_taylor_log2 2 5 5 t_th;; |
| 1336 |
Informal_taylor.eval_m_taylor_log 5 5 t_inf;; |
| 1337 |
|
| 1338 |
let th2 = eval_m_taylor_matan2 2 5 5 t_th;; |
| 1339 |
let t2_inf = Informal_taylor.eval_m_taylor_matan 5 5 t_inf;; |
| 1340 |
|
| 1341 |
let th3 = eval_m_taylor_sin2 2 5 5 th2;; |
| 1342 |
let t3_inf = Informal_taylor.eval_m_taylor_sin 5 5 t2_inf;; |
| 1343 |
*) |