| 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 *) |
| 11 |
(* -------------------------------------------------------------------------- *) |
| 12 |
|
| 13 |
needs "Formal_ineqs/taylor/m_taylor.hl";; |
| 14 |
needs "Formal_ineqs/misc/misc_vars.hl";; |
| 15 |
|
| 16 |
module M_taylor_arith = struct |
| 17 |
|
| 18 |
open Ssreflect;; |
| 19 |
open Ssrfun;; |
| 20 |
open Ssrbool;; |
| 21 |
open Ssrnat;; |
| 22 |
open Taylor_interval;; |
| 23 |
open Multivariate_taylor;; |
| 24 |
open Misc_functions;; |
| 25 |
open Arith_nat;; |
| 26 |
open Arith_float;; |
| 27 |
open More_float;; |
| 28 |
open Float_pow;; |
| 29 |
open Exp_eval;; |
| 30 |
open Log_eval;; |
| 31 |
open Atn_eval;; |
| 32 |
open Asn_acs_eval;; |
| 33 |
open Cos_eval;; |
| 34 |
open Sin_eval;; |
| 35 |
open Matan_eval;; |
| 36 |
open Float_theory;; |
| 37 |
open M_taylor;; |
| 38 |
open Misc_vars;; |
| 39 |
|
| 40 |
let abs_tm = `abs` and |
| 41 |
pow_tm = `pow` and |
| 42 |
sqrt_tm = `sqrt` and |
| 43 |
exp_tm = `exp` and |
| 44 |
log_tm = `log` and |
| 45 |
atn_tm = `atn` and |
| 46 |
acs_tm = `acs` and |
| 47 |
asn_tm = `asn` and |
| 48 |
sin_tm = `sin` and |
| 49 |
cos_tm = `cos` and |
| 50 |
matan_tm = `matan`;; |
| 51 |
|
| 52 |
|
| 53 |
(*************************************) |
| 54 |
|
| 55 |
let binary_beta_gen_eq f1_tm f2_tm x_var op_tm = |
| 56 |
let beta_tm1, beta_tm2 = mk_comb (f1_tm, x_var), mk_comb (f2_tm, x_var) in |
| 57 |
let beta_th1 = if is_abs f1_tm then BETA beta_tm1 else REFL beta_tm1 and |
| 58 |
beta_th2 = if is_abs f2_tm then BETA beta_tm2 else REFL beta_tm2 in |
| 59 |
ABS x_var (MK_COMB (AP_TERM op_tm beta_th1, beta_th2));; |
| 60 |
|
| 61 |
|
| 62 |
let unary_beta_gen_eq f_tm x_var op_tm = |
| 63 |
let beta_tm = mk_comb (f_tm, x_var) in |
| 64 |
let beta_th = if is_abs f_tm then BETA beta_tm else REFL beta_tm in |
| 65 |
ABS x_var (AP_TERM op_tm beta_th);; |
| 66 |
|
| 67 |
let pow_beta_gen_eq f_tm x_var n_tm = |
| 68 |
let beta_tm = mk_comb (f_tm, x_var) in |
| 69 |
let beta_th = if is_abs f_tm then BETA beta_tm else REFL beta_tm in |
| 70 |
ABS x_var (AP_THM (AP_TERM pow_tm beta_th) n_tm);; |
| 71 |
|
| 72 |
let m_taylor_interval_norm th eq_th = |
| 73 |
let lhs1, d2f = dest_comb (concl th) in |
| 74 |
let lhs2, d1f = dest_comb lhs1 in |
| 75 |
let lhs3, d0f = dest_comb lhs2 in |
| 76 |
let lhs4, w = dest_comb lhs3 in |
| 77 |
let lhs5, y = dest_comb lhs4 in |
| 78 |
let lhs6, domain = dest_comb lhs5 in |
| 79 |
let m_taylor = rator lhs6 in |
| 80 |
let th0 = AP_TERM m_taylor eq_th in |
| 81 |
let th1 = AP_THM (AP_THM (AP_THM (AP_THM (AP_THM (AP_THM th0 domain) y) w) d0f) d1f) d2f in |
| 82 |
EQ_MP th1 th;; |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
(*****************************************) |
| 88 |
(* dest_m_lin_approx *) |
| 89 |
|
| 90 |
|
| 91 |
let MK_M_LIN_APPROX' = (RULE o MATCH_MP EQ_IMP o SYM o SPEC_ALL) m_lin_approx;; |
| 92 |
let DEST_M_LIN_APPROX' = MY_RULE_NUM m_lin_approx;; |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
let m_lin_approx_components n m_lin_th = |
| 97 |
let f_tm, x_tm, f_bounds, d_bounds_list = dest_lin_approx (concl m_lin_th) in |
| 98 |
let ty = n_type_array.(n) in |
| 99 |
let f_var = mk_var ("f", type_of f_tm) in |
| 100 |
let x_var = mk_var ("x", type_of x_tm) in |
| 101 |
let th0 = (INST[f_tm, f_var; x_tm, x_var; f_bounds, f_bounds_var; |
| 102 |
d_bounds_list, df_bounds_list_var] o inst_first_type_var ty) DEST_M_LIN_APPROX' in |
| 103 |
let th1 = EQ_MP th0 m_lin_th in |
| 104 |
match (CONJUNCTS th1) with |
| 105 |
| [r1; r2; r3] -> r1, r2, r3 |
| 106 |
| _ -> failwith "no match";; |
| 107 |
|
| 108 |
|
| 109 |
(********************************) |
| 110 |
(* all_n manipulations *) |
| 111 |
|
| 112 |
let ALL_N_EMPTY' = prove(`all_n n [] (s:num->A->bool)`, REWRITE_TAC[all_n]);; |
| 113 |
let ALL_N_CONS_IMP' = (MY_RULE o prove)(`SUC n = m /\ s n (x:A) ==> |
| 114 |
(all_n m t s <=> all_n n (CONS x t) s)`, SIMP_TAC[all_n]);; |
| 115 |
let ALL_N_CONS_EQ' = (MY_RULE o prove)(`SUC n = m ==> |
| 116 |
(all_n n (CONS x t) s <=> (s n (x:A) /\ all_n m t s))`, SIMP_TAC[all_n]);; |
| 117 |
|
| 118 |
let dest_all_n all_n_tm = |
| 119 |
let ltm, s_tm = dest_comb all_n_tm in |
| 120 |
let ltm2, list_tm = dest_comb ltm in |
| 121 |
rand ltm2, list_tm, s_tm;; |
| 122 |
|
| 123 |
|
| 124 |
(* Splits `|- all_n n list s` into separate components. |
| 125 |
Also returns the list of SUC n = m theorems *) |
| 126 |
let all_n_components all_n_th = |
| 127 |
let n_tm, list_tm, s_tm = dest_all_n (concl all_n_th) in |
| 128 |
let list_ty = type_of list_tm in |
| 129 |
let ty = (hd o snd o dest_type) list_ty in |
| 130 |
let s_var = mk_var ("s", type_of s_tm) and |
| 131 |
x_var = mk_var ("x", ty) and |
| 132 |
t_var = mk_var ("t", list_ty) in |
| 133 |
let all_n_cons_th = (INST[s_tm, s_var] o INST_TYPE[ty, aty]) ALL_N_CONS_EQ' in |
| 134 |
|
| 135 |
let rec get_components n_tm list_tm all_n_th = |
| 136 |
if is_const list_tm then [], [] |
| 137 |
else |
| 138 |
let x_tm, t_tm = dest_cons list_tm in |
| 139 |
let suc_th = raw_suc_conv_hash (mk_comb (suc_op_num, n_tm)) in |
| 140 |
let m_tm = rand (concl suc_th) in |
| 141 |
let th0 = INST[n_tm, n_var_num; m_tm, m_var_num; x_tm, x_var; t_tm, t_var] all_n_cons_th in |
| 142 |
let th1 = MY_PROVE_HYP suc_th th0 in |
| 143 |
let th2 = EQ_MP th1 all_n_th in |
| 144 |
let snx_th, all_m_th = CONJUNCT1 th2, CONJUNCT2 th2 in |
| 145 |
let comps, suc_list = get_components m_tm t_tm all_m_th in |
| 146 |
snx_th :: comps, suc_th :: suc_list in |
| 147 |
get_components n_tm list_tm all_n_th;; |
| 148 |
|
| 149 |
|
| 150 |
(* Builds all_n from the given theorems and SUC n = m results *) |
| 151 |
let build_all_n ths suc_ths = |
| 152 |
(* The list ths should be not empty *) |
| 153 |
let tm0 = (concl o hd) ths in |
| 154 |
let lhs, rhs = dest_comb tm0 in |
| 155 |
let s_tm = rator lhs in |
| 156 |
let ty = type_of rhs in |
| 157 |
let list_ty = mk_type ("list", [ty]) in |
| 158 |
let s_var = mk_var ("s", type_of s_tm) and |
| 159 |
x_var = mk_var ("x", ty) and |
| 160 |
t_var = mk_var ("t", list_ty) in |
| 161 |
let m_tm = (rand o concl o hd) suc_ths in |
| 162 |
|
| 163 |
let empty_th = (INST[s_tm, s_var; m_tm, n_var_num] o INST_TYPE[ty, aty]) ALL_N_EMPTY' in |
| 164 |
let cons_th = (INST[s_tm, s_var] o INST_TYPE[ty, aty]) ALL_N_CONS_IMP' in |
| 165 |
|
| 166 |
let build suc_th s_th th = |
| 167 |
let t_tm = (rand o rator o concl) th in |
| 168 |
let x_tm = rand (concl s_th) in |
| 169 |
let lhs, m_tm = dest_eq (concl suc_th) in |
| 170 |
let n_tm = rand lhs in |
| 171 |
let th' = INST[n_tm, n_var_num; m_tm, m_var_num; x_tm, x_var; t_tm, t_var] cons_th in |
| 172 |
EQ_MP (MY_PROVE_HYP s_th (MY_PROVE_HYP suc_th th')) th in |
| 173 |
|
| 174 |
rev_itlist2 build suc_ths ths empty_th;; |
| 175 |
|
| 176 |
|
| 177 |
(*************************) |
| 178 |
|
| 179 |
(* Generates |- s D1 a1 /\ ... /\ s D_m a_m <=> all_n D1 [a1; ... ; a_m] s *) |
| 180 |
let gen_all_n_th m = |
| 181 |
let a_vars = map (fun i -> mk_var ("a"^string_of_int i, aty)) (1--m) in |
| 182 |
let list_tm = mk_list (a_vars, aty) in |
| 183 |
let all_tm = mk_comb (mk_binop `all_n : num -> (A)list -> (num -> A -> bool) -> bool` `1` list_tm, |
| 184 |
`s : num -> A -> bool`) in |
| 185 |
(SYM o MY_RULE_NUM o CONV_RULE NUM_REDUCE_CONV) (REWRITE_CONV[all_n] all_tm);; |
| 186 |
|
| 187 |
let all_n_array = Array.init (max_dim + 1) (fun i -> if i = 0 then TRUTH else gen_all_n_th i);; |
| 188 |
|
| 189 |
(***) |
| 190 |
|
| 191 |
let build2 ths = |
| 192 |
let n = length ths in |
| 193 |
let th0 = rev_itlist CONJ (tl ths) (hd ths) in |
| 194 |
let tm0 = (concl o hd) ths in |
| 195 |
let lhs, rhs = dest_comb tm0 in |
| 196 |
let a_tms = rev (map (rand o concl) ths) in |
| 197 |
let s_tm = rator lhs in |
| 198 |
let ty = type_of rhs in |
| 199 |
let s_var = mk_var ("s", type_of s_tm) and |
| 200 |
a_vars0 = map (fun i -> mk_var ("a"^string_of_int i, ty)) (1--n) in |
| 201 |
|
| 202 |
let th1 = (INST[s_tm, s_var] o INST (zip a_tms a_vars0) o INST_TYPE[ty, aty]) all_n_array.(n) in |
| 203 |
EQ_MP th1 th0;; |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
(************************) |
| 209 |
|
| 210 |
|
| 211 |
(* Constructs all_n n (map s list1) *) |
| 212 |
let eval_all_n all_n1_th beta_flag s = |
| 213 |
let ths1', suc_ths = all_n_components all_n1_th in |
| 214 |
let ths1 = if beta_flag then map MY_BETA_RULE ths1' else ths1' in |
| 215 |
let ths1, suc_ths = List.rev ths1, List.rev suc_ths in |
| 216 |
let ths = map s ths1 in |
| 217 |
(* build_all_n ths suc_ths;; *) |
| 218 |
build2 ths;; |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
(* Constructs all_n n (map2 s list1 list2) *) |
| 223 |
let eval_all_n2 all_n1_th all_n2_th beta_flag s = |
| 224 |
let ths1', suc_ths = all_n_components all_n1_th in |
| 225 |
let ths2', _ = all_n_components all_n2_th in |
| 226 |
let ths1, ths2 = |
| 227 |
if beta_flag then map MY_BETA_RULE ths1', map MY_BETA_RULE ths2' else ths1', ths2' in |
| 228 |
|
| 229 |
let ths1, ths2, suc_ths = List.rev ths1, List.rev ths2, List.rev suc_ths in |
| 230 |
let ths = map2 s ths1 ths2 in |
| 231 |
(* build_all_n ths suc_ths;; *) |
| 232 |
build2 ths;; |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
(***************************************) |
| 237 |
(* eval_m_taylor_add *) |
| 238 |
|
| 239 |
|
| 240 |
let SECOND_BOUNDED' = MY_RULE_NUM second_bounded;; |
| 241 |
|
| 242 |
let dest_second_bounded tm = |
| 243 |
let ltm, dd = dest_comb tm in |
| 244 |
let ltm2, domain = dest_comb ltm in |
| 245 |
rand ltm2, domain, dd;; |
| 246 |
|
| 247 |
let second_bounded_components n th = |
| 248 |
let f_tm, domain_tm, dd_tm = dest_second_bounded (concl th) in |
| 249 |
let x_var = mk_var ("x", n_vector_type_array.(n)) in |
| 250 |
let th0 = (INST[f_tm, mk_var ("f", type_of f_tm); |
| 251 |
domain_tm, mk_var ("domain", type_of domain_tm); |
| 252 |
dd_tm, dd_bounds_list_var] o inst_first_type_var n_type_array.(n)) SECOND_BOUNDED' in |
| 253 |
UNDISCH (SPEC x_var (EQ_MP th0 th));; |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
let MK_M_TAYLOR_ADD' = (MY_RULE_NUM o prove) |
| 259 |
(`m_cell_domain domain (y:real^N) w ==> |
| 260 |
diff2c_domain domain f ==> |
| 261 |
diff2c_domain domain g ==> |
| 262 |
interval_arith (f y + g y) bounds ==> |
| 263 |
all_n 1 d_bounds_list (\i int. interval_arith (partial i f y + partial i g y) int) ==> |
| 264 |
(!x. x IN interval [domain] ==> all_n 1 dd_bounds_list (\i list_i. all_n 1 list_i |
| 265 |
(\j int. interval_arith (partial2 j i f x + partial2 j i g x) int))) ==> |
| 266 |
m_taylor_interval (\x. f x + g x) domain y w bounds d_bounds_list dd_bounds_list`, |
| 267 |
REWRITE_TAC[m_taylor_interval; m_lin_approx; second_bounded] THEN |
| 268 |
REPEAT DISCH_TAC THEN |
| 269 |
SUBGOAL_THEN `lift o f differentiable at (y:real^N) /\ lift o g differentiable at y` ASSUME_TAC THENL |
| 270 |
[ |
| 271 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 272 |
UNDISCH_TAC `diff2c_domain domain (g:real^N->real)` THEN |
| 273 |
REWRITE_TAC[diff2c_domain_alt; diff2_domain] THEN STRIP_TAC THEN STRIP_TAC THEN |
| 274 |
REPEAT (new_rewrite [] [] diff2_imp_diff) THEN REWRITE_TAC[] THEN |
| 275 |
FIRST_X_ASSUM MATCH_MP_TAC THEN |
| 276 |
MATCH_MP_TAC y_in_domain THEN EXISTS_TAC `w:real^N` THEN ASM_REWRITE_TAC[]; |
| 277 |
ALL_TAC |
| 278 |
] THEN |
| 279 |
|
| 280 |
REPEAT STRIP_TAC THEN ASM_REWRITE_TAC[] THENL |
| 281 |
[ |
| 282 |
new_rewrite [] [] diff2c_domain_add THEN ASM_REWRITE_TAC[]; |
| 283 |
REWRITE_TAC[f_lift_add] THEN |
| 284 |
new_rewrite [] [] DIFFERENTIABLE_ADD THEN |
| 285 |
ASM_REWRITE_TAC[ETA_AX]; |
| 286 |
ASM_SIMP_TAC[partial_add]; |
| 287 |
ALL_TAC |
| 288 |
] THEN |
| 289 |
|
| 290 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 291 |
UNDISCH_TAC `diff2c_domain domain (g:real^N->real)` THEN |
| 292 |
REWRITE_TAC[diff2c_domain_alt; diff2_domain] THEN |
| 293 |
REPEAT (DISCH_THEN (MP_TAC o SPEC `x:real^N` o CONJUNCT1) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC) THEN |
| 294 |
ASM_SIMP_TAC[second_partial_add]);; |
| 295 |
|
| 296 |
|
| 297 |
(*************************) |
| 298 |
|
| 299 |
|
| 300 |
let add_partial_lemma' = prove(`interval_arith (partial i f (x:real^N) + partial i g x) int <=> |
| 301 |
(\i int. interval_arith (partial i f x + partial i g x) int) i int`, |
| 302 |
REWRITE_TAC[]);; |
| 303 |
|
| 304 |
let add_second_lemma' = prove(`interval_arith (partial2 j i f (x:real^N) + partial2 j i g x) int <=> |
| 305 |
(\j int. interval_arith (partial2 j i f x + partial2 j i g x) int) j int`, |
| 306 |
REWRITE_TAC[]);; |
| 307 |
|
| 308 |
let add_second_lemma'' = (NUMERALS_TO_NUM o prove)(`all_n 1 list |
| 309 |
(\j int. interval_arith (partial2 j i f (x:real^N) + partial2 j i g x) int) <=> |
| 310 |
(\i list. all_n 1 list |
| 311 |
(\j int. interval_arith (partial2 j i f x + partial2 j i g x) int)) i list`, |
| 312 |
REWRITE_TAC[]);; |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
let eval_m_taylor_add n p_lin p_second taylor1_th taylor2_th = |
| 318 |
let domain_th, diff2_f1_th, lin1_th, second1_th = dest_m_taylor_thms n taylor1_th in |
| 319 |
let _, diff2_f2_th, lin2_th, second2_th = dest_m_taylor_thms n taylor2_th in |
| 320 |
let f1_tm = (rand o concl) diff2_f1_th and |
| 321 |
f2_tm = (rand o concl) diff2_f2_th in |
| 322 |
let domain_tm, y_tm, w_tm = dest_m_cell_domain (concl domain_th) in |
| 323 |
let ty = type_of y_tm in |
| 324 |
|
| 325 |
let x_var = mk_var ("x", ty) and |
| 326 |
y_var = mk_var ("y", ty) and |
| 327 |
w_var = mk_var ("w", ty) and |
| 328 |
f_var = mk_var ("f", type_of f1_tm) and |
| 329 |
g_var = mk_var ("g", type_of f2_tm) and |
| 330 |
domain_var = mk_var ("domain", type_of domain_tm) in |
| 331 |
|
| 332 |
let _, bounds1_th, df1_th = m_lin_approx_components n lin1_th and |
| 333 |
_, bounds2_th, df2_th = m_lin_approx_components n lin2_th in |
| 334 |
|
| 335 |
let bounds_th = float_interval_add p_lin bounds1_th bounds2_th in |
| 336 |
let bounds_tm = (rand o concl) bounds_th in |
| 337 |
|
| 338 |
let add_lemma0 = (INST[f1_tm, f_var; f2_tm, g_var; y_tm, x_var] o |
| 339 |
INST_TYPE[n_type_array.(n), nty]) add_partial_lemma' in |
| 340 |
|
| 341 |
let add th1 th2 = |
| 342 |
let add_th = float_interval_add p_lin th1 th2 in |
| 343 |
let int_tm = rand (concl add_th) and |
| 344 |
i_tm = (rand o rator o rator o lhand) (concl th1) in |
| 345 |
let th0 = INST[i_tm, i_var_num; int_tm, int_var] add_lemma0 in |
| 346 |
EQ_MP th0 add_th in |
| 347 |
|
| 348 |
let df_th = eval_all_n2 df1_th df2_th true add in |
| 349 |
let d_bounds_list = (rand o rator o concl) df_th in |
| 350 |
|
| 351 |
|
| 352 |
let dd1 = second_bounded_components n second1_th in |
| 353 |
let dd2 = second_bounded_components n second2_th in |
| 354 |
|
| 355 |
let add_second_lemma0 = (INST[f1_tm, f_var; f2_tm, g_var] o |
| 356 |
INST_TYPE[n_type_array.(n), nty]) add_second_lemma' in |
| 357 |
|
| 358 |
let add_second_lemma1 = (INST[f1_tm, f_var; f2_tm, g_var] o |
| 359 |
INST_TYPE[n_type_array.(n), nty]) add_second_lemma'' in |
| 360 |
|
| 361 |
|
| 362 |
let add_second2 th1 th2 = |
| 363 |
let i_tm = (rand o rator o concl) th1 in |
| 364 |
let th1, th2 = MY_BETA_RULE th1, MY_BETA_RULE th2 in |
| 365 |
let lemma = INST[i_tm, i_var_num] add_second_lemma0 in |
| 366 |
let add_second th1 th2 = |
| 367 |
let add_th = float_interval_add p_second th1 th2 in |
| 368 |
let int_tm = rand (concl add_th) and |
| 369 |
j_tm = (rand o rator o rator o rator o lhand) (concl th1) in |
| 370 |
let th0 = INST[j_tm, j_var_num; int_tm, int_var] lemma in |
| 371 |
EQ_MP th0 add_th in |
| 372 |
let add_th = eval_all_n2 th1 th2 true add_second in |
| 373 |
let list_tm = (rand o rator o concl) add_th in |
| 374 |
let lemma1 = INST[i_tm, i_var_num; list_tm, list_var_real_pair] add_second_lemma1 in |
| 375 |
EQ_MP lemma1 add_th in |
| 376 |
|
| 377 |
|
| 378 |
let dd_th0 = eval_all_n2 dd1 dd2 false add_second2 in |
| 379 |
let dd_list = (rand o rator o concl) dd_th0 in |
| 380 |
let dd_th = GEN x_var (DISCH_ALL dd_th0) in |
| 381 |
|
| 382 |
let th = (MY_PROVE_HYP dd_th o MY_PROVE_HYP diff2_f1_th o MY_PROVE_HYP diff2_f2_th o |
| 383 |
MY_PROVE_HYP bounds_th o MY_PROVE_HYP df_th o MY_PROVE_HYP domain_th o |
| 384 |
INST[f1_tm, f_var; f2_tm, g_var; |
| 385 |
domain_tm, domain_var; y_tm, y_var; w_tm, w_var; |
| 386 |
bounds_tm, bounds_var; d_bounds_list, d_bounds_list_var; |
| 387 |
dd_list, dd_bounds_list_var] o |
| 388 |
INST_TYPE[n_type_array.(n), nty]) MK_M_TAYLOR_ADD' in |
| 389 |
let eq_th = binary_beta_gen_eq f1_tm f2_tm x_var add_op_real in |
| 390 |
m_taylor_interval_norm th eq_th;; |
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
(***************************************) |
| 395 |
(* eval_m_taylor_sub *) |
| 396 |
|
| 397 |
|
| 398 |
let MK_M_TAYLOR_SUB' = (MY_RULE_NUM o prove) |
| 399 |
(`m_cell_domain domain (y:real^N) w ==> |
| 400 |
diff2c_domain domain f ==> |
| 401 |
diff2c_domain domain g ==> |
| 402 |
interval_arith (f y - g y) bounds ==> |
| 403 |
all_n 1 d_bounds_list (\i int. interval_arith (partial i f y - partial i g y) int) ==> |
| 404 |
(!x. x IN interval [domain] ==> all_n 1 dd_bounds_list (\i list_i. all_n 1 list_i |
| 405 |
(\j int. interval_arith (partial2 j i f x - partial2 j i g x) int))) ==> |
| 406 |
m_taylor_interval (\x. f x - g x) domain y w bounds d_bounds_list dd_bounds_list`, |
| 407 |
REWRITE_TAC[m_taylor_interval; m_lin_approx; second_bounded] THEN |
| 408 |
REPEAT DISCH_TAC THEN |
| 409 |
SUBGOAL_THEN `lift o f differentiable at (y:real^N) /\ lift o g differentiable at y` ASSUME_TAC THENL |
| 410 |
[ |
| 411 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 412 |
UNDISCH_TAC `diff2c_domain domain (g:real^N->real)` THEN |
| 413 |
REWRITE_TAC[diff2c_domain_alt; diff2_domain] THEN STRIP_TAC THEN STRIP_TAC THEN |
| 414 |
REPEAT (new_rewrite [] [] diff2_imp_diff) THEN REWRITE_TAC[] THEN |
| 415 |
FIRST_X_ASSUM MATCH_MP_TAC THEN |
| 416 |
MATCH_MP_TAC y_in_domain THEN EXISTS_TAC `w:real^N` THEN ASM_REWRITE_TAC[]; |
| 417 |
ALL_TAC |
| 418 |
] THEN |
| 419 |
|
| 420 |
REPEAT STRIP_TAC THEN ASM_REWRITE_TAC[] THENL |
| 421 |
[ |
| 422 |
new_rewrite [] [] diff2c_domain_sub THEN ASM_REWRITE_TAC[]; |
| 423 |
REWRITE_TAC[f_lift_sub] THEN |
| 424 |
new_rewrite [] [] DIFFERENTIABLE_SUB THEN |
| 425 |
ASM_REWRITE_TAC[ETA_AX]; |
| 426 |
ASM_SIMP_TAC[partial_sub]; |
| 427 |
ALL_TAC |
| 428 |
] THEN |
| 429 |
|
| 430 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 431 |
UNDISCH_TAC `diff2c_domain domain (g:real^N->real)` THEN |
| 432 |
REWRITE_TAC[diff2c_domain_alt; diff2_domain] THEN |
| 433 |
REPEAT (DISCH_THEN (MP_TAC o SPEC `x:real^N` o CONJUNCT1) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC) THEN |
| 434 |
ASM_SIMP_TAC[second_partial_sub]);; |
| 435 |
|
| 436 |
|
| 437 |
(*************************) |
| 438 |
|
| 439 |
|
| 440 |
let sub_partial_lemma' = prove(`interval_arith (partial i f (x:real^N) - partial i g x) int <=> |
| 441 |
(\i int. interval_arith (partial i f x - partial i g x) int) i int`, |
| 442 |
REWRITE_TAC[]);; |
| 443 |
|
| 444 |
let sub_second_lemma' = prove(`interval_arith (partial2 j i f (x:real^N) - partial2 j i g x) int <=> |
| 445 |
(\j int. interval_arith (partial2 j i f x - partial2 j i g x) int) j int`, |
| 446 |
REWRITE_TAC[]);; |
| 447 |
|
| 448 |
let sub_second_lemma'' = (NUMERALS_TO_NUM o prove)(`all_n 1 list |
| 449 |
(\j int. interval_arith (partial2 j i f (x:real^N) - partial2 j i g x) int) <=> |
| 450 |
(\i list. all_n 1 list |
| 451 |
(\j int. interval_arith (partial2 j i f x - partial2 j i g x) int)) i list`, |
| 452 |
REWRITE_TAC[]);; |
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
let eval_m_taylor_sub n p_lin p_second taylor1_th taylor2_th = |
| 458 |
let domain_th, diff2_f1_th, lin1_th, second1_th = dest_m_taylor_thms n taylor1_th in |
| 459 |
let _, diff2_f2_th, lin2_th, second2_th = dest_m_taylor_thms n taylor2_th in |
| 460 |
let f1_tm = (rand o concl) diff2_f1_th and |
| 461 |
f2_tm = (rand o concl) diff2_f2_th in |
| 462 |
let domain_tm, y_tm, w_tm = dest_m_cell_domain (concl domain_th) in |
| 463 |
let ty = type_of y_tm in |
| 464 |
|
| 465 |
let x_var = mk_var ("x", ty) and |
| 466 |
y_var = mk_var ("y", ty) and |
| 467 |
w_var = mk_var ("w", ty) and |
| 468 |
f_var = mk_var ("f", type_of f1_tm) and |
| 469 |
g_var = mk_var ("g", type_of f2_tm) and |
| 470 |
domain_var = mk_var ("domain", type_of domain_tm) in |
| 471 |
|
| 472 |
let _, bounds1_th, df1_th = m_lin_approx_components n lin1_th and |
| 473 |
_, bounds2_th, df2_th = m_lin_approx_components n lin2_th in |
| 474 |
|
| 475 |
let bounds_th = float_interval_sub p_lin bounds1_th bounds2_th in |
| 476 |
let bounds_tm = (rand o concl) bounds_th in |
| 477 |
|
| 478 |
let sub_lemma0 = (INST[f1_tm, f_var; f2_tm, g_var; y_tm, x_var] o |
| 479 |
INST_TYPE[n_type_array.(n), nty]) sub_partial_lemma' in |
| 480 |
|
| 481 |
let sub th1 th2 = |
| 482 |
let sub_th = float_interval_sub p_lin th1 th2 in |
| 483 |
let int_tm = rand (concl sub_th) and |
| 484 |
i_tm = (rand o rator o rator o lhand) (concl th1) in |
| 485 |
let th0 = INST[i_tm, i_var_num; int_tm, int_var] sub_lemma0 in |
| 486 |
EQ_MP th0 sub_th in |
| 487 |
|
| 488 |
let df_th = eval_all_n2 df1_th df2_th true sub in |
| 489 |
let d_bounds_list = (rand o rator o concl) df_th in |
| 490 |
|
| 491 |
|
| 492 |
let dd1 = second_bounded_components n second1_th in |
| 493 |
let dd2 = second_bounded_components n second2_th in |
| 494 |
|
| 495 |
let sub_second_lemma0 = (INST[f1_tm, f_var; f2_tm, g_var] o |
| 496 |
INST_TYPE[n_type_array.(n), nty]) sub_second_lemma' in |
| 497 |
|
| 498 |
let sub_second_lemma1 = (INST[f1_tm, f_var; f2_tm, g_var] o |
| 499 |
INST_TYPE[n_type_array.(n), nty]) sub_second_lemma'' in |
| 500 |
|
| 501 |
|
| 502 |
let sub_second2 th1 th2 = |
| 503 |
let i_tm = (rand o rator o concl) th1 in |
| 504 |
let th1, th2 = MY_BETA_RULE th1, MY_BETA_RULE th2 in |
| 505 |
let lemma = INST[i_tm, i_var_num] sub_second_lemma0 in |
| 506 |
let sub_second th1 th2 = |
| 507 |
let sub_th = float_interval_sub p_second th1 th2 in |
| 508 |
let int_tm = rand (concl sub_th) and |
| 509 |
j_tm = (rand o rator o rator o rator o lhand) (concl th1) in |
| 510 |
let th0 = INST[j_tm, j_var_num; int_tm, int_var] lemma in |
| 511 |
EQ_MP th0 sub_th in |
| 512 |
let sub_th = eval_all_n2 th1 th2 true sub_second in |
| 513 |
let list_tm = (rand o rator o concl) sub_th in |
| 514 |
let lemma1 = INST[i_tm, i_var_num; list_tm, list_var_real_pair] sub_second_lemma1 in |
| 515 |
EQ_MP lemma1 sub_th in |
| 516 |
|
| 517 |
|
| 518 |
let dd_th0 = eval_all_n2 dd1 dd2 false sub_second2 in |
| 519 |
let dd_list = (rand o rator o concl) dd_th0 in |
| 520 |
let dd_th = GEN x_var (DISCH_ALL dd_th0) in |
| 521 |
|
| 522 |
let th = (MY_PROVE_HYP dd_th o MY_PROVE_HYP diff2_f1_th o MY_PROVE_HYP diff2_f2_th o |
| 523 |
MY_PROVE_HYP bounds_th o MY_PROVE_HYP df_th o MY_PROVE_HYP domain_th o |
| 524 |
INST[f1_tm, f_var; f2_tm, g_var; |
| 525 |
domain_tm, domain_var; y_tm, y_var; w_tm, w_var; |
| 526 |
bounds_tm, bounds_var; d_bounds_list, d_bounds_list_var; |
| 527 |
dd_list, dd_bounds_list_var] o |
| 528 |
INST_TYPE[n_type_array.(n), nty]) MK_M_TAYLOR_SUB' in |
| 529 |
let eq_th = binary_beta_gen_eq f1_tm f2_tm x_var sub_op_real in |
| 530 |
m_taylor_interval_norm th eq_th;; |
| 531 |
|
| 532 |
|
| 533 |
(*******************************************************) |
| 534 |
|
| 535 |
|
| 536 |
(***************************************) |
| 537 |
(* eval_m_taylor_mul *) |
| 538 |
|
| 539 |
|
| 540 |
let MK_M_TAYLOR_MUL' = (MY_RULE_NUM o prove) |
| 541 |
(`m_cell_domain domain (y:real^N) w ==> |
| 542 |
diff2c_domain domain f ==> |
| 543 |
diff2c_domain domain g ==> |
| 544 |
interval_arith (f y * g y) bounds ==> |
| 545 |
all_n 1 d_bounds_list (\i int. interval_arith (partial i f y * g y + f y * partial i g y) int) ==> |
| 546 |
(!x. x IN interval [domain] ==> all_n 1 dd_bounds_list (\i list_i. all_n 1 list_i |
| 547 |
(\j int. interval_arith ((partial2 j i f x * g x + partial i f x * partial j g x) + |
| 548 |
partial j f x * partial i g x + f x * partial2 j i g x) int))) ==> |
| 549 |
m_taylor_interval (\x. f x * g x) domain y w bounds d_bounds_list dd_bounds_list`, |
| 550 |
REWRITE_TAC[m_taylor_interval; m_lin_approx; second_bounded] THEN |
| 551 |
REPEAT DISCH_TAC THEN |
| 552 |
SUBGOAL_THEN `lift o f differentiable at (y:real^N) /\ lift o g differentiable at y` ASSUME_TAC THENL |
| 553 |
[ |
| 554 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 555 |
UNDISCH_TAC `diff2c_domain domain (g:real^N->real)` THEN |
| 556 |
REWRITE_TAC[diff2c_domain_alt; diff2_domain] THEN STRIP_TAC THEN STRIP_TAC THEN |
| 557 |
REPEAT (new_rewrite [] [] diff2_imp_diff) THEN REWRITE_TAC[] THEN |
| 558 |
FIRST_X_ASSUM MATCH_MP_TAC THEN |
| 559 |
MATCH_MP_TAC y_in_domain THEN EXISTS_TAC `w:real^N` THEN ASM_REWRITE_TAC[]; |
| 560 |
ALL_TAC |
| 561 |
] THEN |
| 562 |
|
| 563 |
REPEAT STRIP_TAC THEN ASM_REWRITE_TAC[] THENL |
| 564 |
[ |
| 565 |
new_rewrite [] [] diff2c_domain_mul THEN ASM_REWRITE_TAC[]; |
| 566 |
new_rewrite [] [] differentiable_mul THEN ASM_REWRITE_TAC[]; |
| 567 |
ASM_SIMP_TAC[partial_mul]; |
| 568 |
ALL_TAC |
| 569 |
] THEN |
| 570 |
|
| 571 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 572 |
UNDISCH_TAC `diff2c_domain domain (g:real^N->real)` THEN |
| 573 |
REWRITE_TAC[diff2c_domain_alt; diff2_domain] THEN |
| 574 |
REPEAT (DISCH_THEN (MP_TAC o SPEC `x:real^N` o CONJUNCT1) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC) THEN |
| 575 |
ASM_SIMP_TAC[second_partial_mul]);; |
| 576 |
|
| 577 |
|
| 578 |
(*************************) |
| 579 |
|
| 580 |
|
| 581 |
let mul_partial_lemma' = |
| 582 |
prove(`interval_arith (partial i f (y:real^N) * g y + f y * partial i g y) int <=> |
| 583 |
(\i int. interval_arith (partial i f y * g y + f y * partial i g y) int) i int`, |
| 584 |
REWRITE_TAC[]);; |
| 585 |
|
| 586 |
let mul_second_lemma' = |
| 587 |
prove(`interval_arith ((partial2 j i f x * g (x:real^N) + partial i f x * partial j g x) + |
| 588 |
partial j f x * partial i g x + f x * partial2 j i g x) int <=> |
| 589 |
(\j int. interval_arith ((partial2 j i f x * g x + partial i f x * partial j g x) + |
| 590 |
partial j f x * partial i g x + f x * partial2 j i g x) int) j int`, |
| 591 |
REWRITE_TAC[]);; |
| 592 |
|
| 593 |
|
| 594 |
let mul_second_lemma'' = (NUMERALS_TO_NUM o prove) |
| 595 |
(`all_n 1 list (\j int. interval_arith ((partial2 j i f x * g x + partial i f x * partial j g x) + |
| 596 |
partial j f x * partial i g x + f (x:real^N) * partial2 j i g x) int) <=> |
| 597 |
(\i list. all_n 1 list |
| 598 |
(\j int. interval_arith ((partial2 j i f x * g x + partial i f x * partial j g x) + |
| 599 |
partial j f x * partial i g x + f x * partial2 j i g x) int)) i list`, |
| 600 |
REWRITE_TAC[]);; |
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
let eval_m_taylor_mul n p_lin p_second taylor1_th taylor2_th = |
| 606 |
let domain_th, diff2_f1_th, lin1_th, second1_th = dest_m_taylor_thms n taylor1_th and |
| 607 |
_, diff2_f2_th, lin2_th, second2_th = dest_m_taylor_thms n taylor2_th in |
| 608 |
let f1_tm = (rand o concl) diff2_f1_th and |
| 609 |
f2_tm = (rand o concl) diff2_f2_th in |
| 610 |
let domain_tm, y_tm, w_tm = dest_m_cell_domain (concl domain_th) in |
| 611 |
let ty = type_of y_tm in |
| 612 |
|
| 613 |
let x_var = mk_var ("x", ty) and |
| 614 |
y_var = mk_var ("y", ty) and |
| 615 |
w_var = mk_var ("w", ty) and |
| 616 |
f_var = mk_var ("f", type_of f1_tm) and |
| 617 |
g_var = mk_var ("g", type_of f2_tm) and |
| 618 |
domain_var = mk_var ("domain", type_of domain_tm) in |
| 619 |
|
| 620 |
let _, bounds1_th, df1_th = m_lin_approx_components n lin1_th and |
| 621 |
_, bounds2_th, df2_th = m_lin_approx_components n lin2_th in |
| 622 |
|
| 623 |
let bounds_th = float_interval_mul p_lin bounds1_th bounds2_th in |
| 624 |
let bounds_tm = (rand o concl) bounds_th in |
| 625 |
|
| 626 |
let mul_lemma0 = (INST[f1_tm, f_var; f2_tm, g_var; y_tm, y_var] o |
| 627 |
INST_TYPE[n_type_array.(n), nty]) mul_partial_lemma' in |
| 628 |
|
| 629 |
let mul th1 th2 = |
| 630 |
let mul_th = |
| 631 |
let ( * ), ( + ) = float_interval_mul p_lin, float_interval_add p_lin in |
| 632 |
th1 * bounds2_th + bounds1_th * th2 in |
| 633 |
let int_tm = rand (concl mul_th) in |
| 634 |
let i_tm = (rand o rator o rator o lhand) (concl th1) in |
| 635 |
let th0 = INST[i_tm, i_var_num; int_tm, int_var] mul_lemma0 in |
| 636 |
EQ_MP th0 mul_th in |
| 637 |
|
| 638 |
let df_th = eval_all_n2 df1_th df2_th true mul in |
| 639 |
let d_bounds_list = (rand o rator o concl) df_th in |
| 640 |
|
| 641 |
|
| 642 |
let dd1 = second_bounded_components n second1_th in |
| 643 |
let dd2 = second_bounded_components n second2_th in |
| 644 |
|
| 645 |
let mul_second_lemma0 = (INST[f1_tm, f_var; f2_tm, g_var] o |
| 646 |
INST_TYPE[n_type_array.(n), nty]) mul_second_lemma' in |
| 647 |
|
| 648 |
let mul_second_lemma1 = (INST[f1_tm, f_var; f2_tm, g_var] o |
| 649 |
INST_TYPE[n_type_array.(n), nty]) mul_second_lemma'' in |
| 650 |
|
| 651 |
let undisch = UNDISCH o SPEC x_var in |
| 652 |
|
| 653 |
let d1_bounds = map (fun i -> |
| 654 |
let th0 = eval_m_taylor_partial_bound n p_second i taylor1_th in |
| 655 |
undisch th0) (1--n) in |
| 656 |
|
| 657 |
let d2_bounds = map (fun i -> |
| 658 |
let th0 = eval_m_taylor_partial_bound n p_second i taylor2_th in |
| 659 |
undisch th0) (1--n) in |
| 660 |
|
| 661 |
let f1_bound = undisch (eval_m_taylor_bound n p_second taylor1_th) and |
| 662 |
f2_bound = undisch (eval_m_taylor_bound n p_second taylor2_th) in |
| 663 |
|
| 664 |
let mul_second2 th1 th2 = |
| 665 |
let i_tm = (rand o rator o concl) th1 in |
| 666 |
let i_int = (Num.int_of_num o raw_dest_hash) i_tm in |
| 667 |
let di1 = List.nth d1_bounds (i_int - 1) and |
| 668 |
di2 = List.nth d2_bounds (i_int - 1) in |
| 669 |
let th1, th2 = MY_BETA_RULE th1, MY_BETA_RULE th2 in |
| 670 |
let lemma = INST[i_tm, i_var_num] mul_second_lemma0 in |
| 671 |
let mul_second th1 th2 = |
| 672 |
let j_tm = (rand o rator o rator o rator o lhand) (concl th1) in |
| 673 |
let j_int = (Num.int_of_num o raw_dest_hash) j_tm in |
| 674 |
let dj1 = List.nth d1_bounds (j_int - 1) and |
| 675 |
dj2 = List.nth d2_bounds (j_int - 1) in |
| 676 |
|
| 677 |
let mul_th = |
| 678 |
let ( * ), ( + ) = float_interval_mul p_second, float_interval_add p_second in |
| 679 |
(th1 * f2_bound + di1 * dj2) + (dj1 * di2 + f1_bound * th2) in |
| 680 |
|
| 681 |
let int_tm = rand (concl mul_th) in |
| 682 |
let th0 = INST[j_tm, j_var_num; int_tm, int_var] lemma in |
| 683 |
EQ_MP th0 mul_th in |
| 684 |
|
| 685 |
let mul_th = eval_all_n2 th1 th2 true mul_second in |
| 686 |
let list_tm = (rand o rator o concl) mul_th in |
| 687 |
let lemma1 = INST[i_tm, i_var_num; list_tm, list_var_real_pair] mul_second_lemma1 in |
| 688 |
EQ_MP lemma1 mul_th in |
| 689 |
|
| 690 |
|
| 691 |
let dd_th0 = eval_all_n2 dd1 dd2 false mul_second2 in |
| 692 |
let dd_list = (rand o rator o concl) dd_th0 in |
| 693 |
let dd_th = GEN x_var (DISCH_ALL dd_th0) in |
| 694 |
|
| 695 |
let th = (MY_PROVE_HYP dd_th o MY_PROVE_HYP diff2_f1_th o MY_PROVE_HYP diff2_f2_th o |
| 696 |
MY_PROVE_HYP bounds_th o MY_PROVE_HYP df_th o MY_PROVE_HYP domain_th o |
| 697 |
INST[f1_tm, f_var; f2_tm, g_var; |
| 698 |
domain_tm, domain_var; y_tm, y_var; w_tm, w_var; |
| 699 |
bounds_tm, bounds_var; d_bounds_list, d_bounds_list_var; |
| 700 |
dd_list, dd_bounds_list_var] o |
| 701 |
INST_TYPE[n_type_array.(n), nty]) MK_M_TAYLOR_MUL' in |
| 702 |
let eq_th = binary_beta_gen_eq f1_tm f2_tm x_var mul_op_real in |
| 703 |
m_taylor_interval_norm th eq_th;; |
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
(*******************************************************) |
| 711 |
|
| 712 |
(* neg, pow, inv, sqrt, atn, acs *) |
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
let partial_uni_compose' = |
| 717 |
REWRITE_RULE[SWAP_FORALL_THM; GSYM RIGHT_IMP_FORALL_THM] partial_uni_compose;; |
| 718 |
|
| 719 |
let second_partial_uni_compose' = |
| 720 |
REWRITE_RULE[SWAP_FORALL_THM; GSYM RIGHT_IMP_FORALL_THM] second_partial_uni_compose;; |
| 721 |
|
| 722 |
let all_n1_raw = (GEN_REWRITE_RULE (RAND_CONV o DEPTH_CONV) [SYM num1_eq] o REFL) |
| 723 |
`all_n 1`;; |
| 724 |
|
| 725 |
|
| 726 |
(* neg *) |
| 727 |
let MK_M_TAYLOR_NEG' = (MY_RULE_FLOAT o prove) |
| 728 |
(`m_cell_domain domain (y:real^N) w ==> |
| 729 |
diff2c_domain domain f ==> |
| 730 |
interval_arith (-- (f y)) bounds ==> |
| 731 |
all_n 1 d_bounds_list (\i int. interval_arith (-- partial i f y) int) ==> |
| 732 |
(!x. x IN interval [domain] ==> all_n 1 dd_bounds_list (\i list_i. all_n 1 list_i |
| 733 |
(\j int. interval_arith (-- partial2 j i f x) int))) ==> |
| 734 |
m_taylor_interval (\x. -- (f x)) domain y w bounds d_bounds_list dd_bounds_list`, |
| 735 |
REWRITE_TAC[m_taylor_interval; m_lin_approx; second_bounded] THEN |
| 736 |
REPEAT DISCH_TAC THEN |
| 737 |
SUBGOAL_THEN `lift o f differentiable at (y:real^N)` ASSUME_TAC THENL |
| 738 |
[ |
| 739 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 740 |
REWRITE_TAC[diff2c_domain_alt; diff2_domain] THEN STRIP_TAC THEN |
| 741 |
REPEAT (new_rewrite [] [] diff2_imp_diff) THEN REWRITE_TAC[] THEN |
| 742 |
FIRST_X_ASSUM MATCH_MP_TAC THEN |
| 743 |
MATCH_MP_TAC y_in_domain THEN EXISTS_TAC `w:real^N` THEN ASM_REWRITE_TAC[]; |
| 744 |
ALL_TAC |
| 745 |
] THEN |
| 746 |
|
| 747 |
REPEAT STRIP_TAC THEN ASM_REWRITE_TAC[] THENL |
| 748 |
[ |
| 749 |
new_rewrite [] [] diff2c_domain_neg THEN ASM_REWRITE_TAC[]; |
| 750 |
REWRITE_TAC[f_lift_neg] THEN |
| 751 |
new_rewrite [] [] DIFFERENTIABLE_NEG THEN |
| 752 |
ASM_REWRITE_TAC[ETA_AX]; |
| 753 |
ASM_SIMP_TAC[partial_neg]; |
| 754 |
ALL_TAC |
| 755 |
] THEN |
| 756 |
|
| 757 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 758 |
REWRITE_TAC[diff2c_domain_alt; diff2_domain] THEN |
| 759 |
DISCH_THEN (MP_TAC o SPEC `x:real^N` o CONJUNCT1) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN |
| 760 |
ASM_SIMP_TAC[second_partial_neg]);; |
| 761 |
|
| 762 |
(* abs *) |
| 763 |
|
| 764 |
let MK_M_TAYLOR_ABS_POS' = (MY_RULE_FLOAT o prove) |
| 765 |
(`m_taylor_interval f domain (y:real^N) w bounds d_bounds_list dd_bounds_list ==> |
| 766 |
(!x. x IN interval [domain] ==> interval_arith (f x) f_bounds) ==> |
| 767 |
interval_pos f_bounds ==> |
| 768 |
m_taylor_interval (\x. abs (f x)) domain y w bounds d_bounds_list dd_bounds_list`, |
| 769 |
REWRITE_TAC[m_taylor_interval; m_lin_approx; second_bounded; ETA_AX] THEN |
| 770 |
DISCH_THEN STRIP_ASSUME_TAC THEN REPEAT DISCH_TAC THEN ASM_REWRITE_TAC[] THEN |
| 771 |
SUBGOAL_THEN `!x:real^N. x IN interval [domain] ==> &0 < f x` ASSUME_TAC THENL |
| 772 |
[ |
| 773 |
GEN_TAC THEN DISCH_TAC THEN |
| 774 |
apply_tac interval_arith_pos THEN |
| 775 |
EXISTS_TAC `f_bounds:real#real` THEN |
| 776 |
ASM_REWRITE_TAC[] THEN |
| 777 |
FIRST_X_ASSUM MATCH_MP_TAC THEN ASM_REWRITE_TAC[]; |
| 778 |
ALL_TAC |
| 779 |
] THEN |
| 780 |
|
| 781 |
SUBGOAL_THEN `&0 < f (y:real^N)` ASSUME_TAC THENL |
| 782 |
[ |
| 783 |
FIRST_X_ASSUM MATCH_MP_TAC THEN |
| 784 |
MATCH_MP_TAC y_in_domain THEN EXISTS_TAC `w:real^N` THEN |
| 785 |
ASM_REWRITE_TAC[]; |
| 786 |
ALL_TAC |
| 787 |
] THEN |
| 788 |
|
| 789 |
REPEAT STRIP_TAC THEN ASM_REWRITE_TAC[] THENL |
| 790 |
[ |
| 791 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 792 |
REWRITE_TAC[diff2c_domain] THEN REPEAT STRIP_TAC THEN |
| 793 |
ONCE_REWRITE_TAC[GSYM o_THM] THEN REWRITE_TAC[ETA_AX] THEN |
| 794 |
apply_tac diff2c_abs_pos_compose THEN CONJ_TAC THEN FIRST_X_ASSUM MATCH_MP_TAC THEN ASM_REWRITE_TAC[]; |
| 795 |
new_rewrite [] [`abs _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 796 |
apply_tac diff_uni_compose THEN ASM_REWRITE_TAC[] THEN |
| 797 |
MATCH_MP_TAC REAL_DIFFERENTIABLE_AT_ABS_POS THEN ASM_REWRITE_TAC[]; |
| 798 |
ASM_SIMP_TAC[REAL_ARITH `&0 < a ==> abs a = a`]; |
| 799 |
new_rewrite [] [`abs _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 800 |
MP_TAC (ISPECL [`y:real^N`; `f:real^N->real`] partial_uni_compose') THEN |
| 801 |
ASM_REWRITE_TAC[] THEN |
| 802 |
DISCH_THEN (MP_TAC o SPEC `abs`) THEN |
| 803 |
ANTS_TAC THENL |
| 804 |
[ |
| 805 |
MATCH_MP_TAC REAL_DIFFERENTIABLE_AT_ABS_POS THEN ASM_REWRITE_TAC[]; |
| 806 |
ALL_TAC |
| 807 |
] THEN |
| 808 |
ASM_SIMP_TAC[derivative_abs_pos; REAL_MUL_LID]; |
| 809 |
ALL_TAC |
| 810 |
] THEN |
| 811 |
|
| 812 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 813 |
REWRITE_TAC[diff2c_domain_alt; diff2_domain] THEN |
| 814 |
DISCH_THEN (MP_TAC o SPEC `x:real^N` o CONJUNCT1) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN |
| 815 |
MP_TAC (ISPECL [`x:real^N`; `f:real^N->real`] second_partial_uni_compose') THEN |
| 816 |
ASM_REWRITE_TAC[] THEN |
| 817 |
DISCH_THEN (MP_TAC o SPEC `abs`) THEN |
| 818 |
ANTS_TAC THENL |
| 819 |
[ |
| 820 |
MATCH_MP_TAC diff2_abs_pos THEN |
| 821 |
FIRST_X_ASSUM MATCH_MP_TAC THEN ASM_REWRITE_TAC[]; |
| 822 |
ALL_TAC |
| 823 |
] THEN |
| 824 |
|
| 825 |
new_rewrite [] [`abs _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 826 |
ASM_SIMP_TAC[second_derivative_abs_pos; derivative_abs_pos] THEN DISCH_THEN (fun th -> ALL_TAC) THEN |
| 827 |
REWRITE_TAC[REAL_ARITH `(&0 * a) * b + &1 * c = c`] THEN |
| 828 |
ASM_SIMP_TAC[]);; |
| 829 |
|
| 830 |
let MK_M_TAYLOR_ABS_NEG' = (MY_RULE_FLOAT o prove) |
| 831 |
(`m_taylor_interval (\x. --f x) domain (y:real^N) w bounds d_bounds_list dd_bounds_list ==> |
| 832 |
(!x. x IN interval [domain] ==> interval_arith (f x) f_bounds) ==> |
| 833 |
interval_neg f_bounds ==> |
| 834 |
m_taylor_interval (\x. abs (f x)) domain y w bounds d_bounds_list dd_bounds_list`, |
| 835 |
REWRITE_TAC[m_taylor_interval; m_lin_approx; second_bounded; ETA_AX] THEN |
| 836 |
DISCH_THEN STRIP_ASSUME_TAC THEN REPEAT DISCH_TAC THEN ASM_REWRITE_TAC[] THEN |
| 837 |
SUBGOAL_THEN `!x:real^N. x IN interval [domain] ==> f x < &0` ASSUME_TAC THENL |
| 838 |
[ |
| 839 |
GEN_TAC THEN DISCH_TAC THEN |
| 840 |
apply_tac interval_arith_neg THEN |
| 841 |
EXISTS_TAC `f_bounds:real#real` THEN |
| 842 |
ASM_REWRITE_TAC[] THEN |
| 843 |
FIRST_X_ASSUM MATCH_MP_TAC THEN ASM_REWRITE_TAC[]; |
| 844 |
ALL_TAC |
| 845 |
] THEN |
| 846 |
|
| 847 |
SUBGOAL_THEN `f (y:real^N) < &0` ASSUME_TAC THENL |
| 848 |
[ |
| 849 |
FIRST_X_ASSUM MATCH_MP_TAC THEN |
| 850 |
MATCH_MP_TAC y_in_domain THEN EXISTS_TAC `w:real^N` THEN |
| 851 |
ASM_REWRITE_TAC[]; |
| 852 |
ALL_TAC |
| 853 |
] THEN |
| 854 |
|
| 855 |
SUBGOAL_THEN `diff2c_domain domain (f:real^N->real)` ASSUME_TAC THENL [ |
| 856 |
SUBGOAL_THEN `f:real^N->real = (\x. -- (--f x))` (fun th -> ONCE_REWRITE_TAC[th]) THENL [ |
| 857 |
REWRITE_TAC[REAL_NEG_NEG; ETA_AX]; |
| 858 |
ALL_TAC |
| 859 |
] THEN |
| 860 |
apply_tac diff2c_domain_neg THEN ASM_REWRITE_TAC[]; |
| 861 |
ALL_TAC |
| 862 |
] THEN |
| 863 |
|
| 864 |
SUBGOAL_THEN `lift o (f:real^N->real) differentiable at y` ASSUME_TAC THENL [ |
| 865 |
SUBGOAL_THEN `lift o (f:real^N->real) = (\x. --((lift o (\t. --f t)) x))` ASSUME_TAC THENL [ |
| 866 |
REWRITE_TAC[FUN_EQ_THM; o_THM; LIFT_NEG; VECTOR_NEG_NEG]; |
| 867 |
ALL_TAC |
| 868 |
] THEN |
| 869 |
POP_ASSUM (fun th -> ONCE_REWRITE_TAC[th]) THEN |
| 870 |
MATCH_MP_TAC DIFFERENTIABLE_NEG THEN |
| 871 |
ASM_REWRITE_TAC[ETA_AX]; |
| 872 |
ALL_TAC |
| 873 |
] THEN |
| 874 |
|
| 875 |
REPEAT STRIP_TAC THEN ASM_REWRITE_TAC[] THENL |
| 876 |
[ |
| 877 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 878 |
REWRITE_TAC[diff2c_domain] THEN REPEAT STRIP_TAC THEN |
| 879 |
ONCE_REWRITE_TAC[GSYM o_THM] THEN REWRITE_TAC[ETA_AX] THEN |
| 880 |
apply_tac diff2c_abs_neg_compose THEN ASM_SIMP_TAC[]; |
| 881 |
|
| 882 |
new_rewrite [] [`abs _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 883 |
apply_tac diff_uni_compose THEN ASM_REWRITE_TAC[] THEN |
| 884 |
MATCH_MP_TAC REAL_DIFFERENTIABLE_AT_ABS_NEG THEN ASM_REWRITE_TAC[]; |
| 885 |
|
| 886 |
ASM_SIMP_TAC[REAL_ARITH `a < &0 ==> abs a = --a`]; |
| 887 |
|
| 888 |
new_rewrite [] [`abs _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 889 |
MP_TAC (ISPECL [`y:real^N`; `f:real^N->real`] partial_uni_compose') THEN |
| 890 |
ASM_REWRITE_TAC[] THEN |
| 891 |
DISCH_THEN (MP_TAC o SPEC `abs`) THEN |
| 892 |
ANTS_TAC THENL |
| 893 |
[ |
| 894 |
MATCH_MP_TAC REAL_DIFFERENTIABLE_AT_ABS_NEG THEN ASM_REWRITE_TAC[]; |
| 895 |
ALL_TAC |
| 896 |
] THEN |
| 897 |
ASM_SIMP_TAC[derivative_abs_neg; GSYM REAL_NEG_MINUS1; GSYM partial_neg]; |
| 898 |
ALL_TAC |
| 899 |
] THEN |
| 900 |
|
| 901 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 902 |
REWRITE_TAC[diff2c_domain_alt; diff2_domain] THEN |
| 903 |
DISCH_THEN (MP_TAC o SPEC `x:real^N` o CONJUNCT1) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN |
| 904 |
MP_TAC (ISPECL [`x:real^N`; `f:real^N->real`] second_partial_uni_compose') THEN |
| 905 |
ASM_REWRITE_TAC[] THEN |
| 906 |
DISCH_THEN (MP_TAC o SPEC `abs`) THEN |
| 907 |
ANTS_TAC THENL |
| 908 |
[ |
| 909 |
MATCH_MP_TAC diff2_abs_neg THEN |
| 910 |
FIRST_X_ASSUM MATCH_MP_TAC THEN ASM_REWRITE_TAC[]; |
| 911 |
ALL_TAC |
| 912 |
] THEN |
| 913 |
|
| 914 |
new_rewrite [] [`abs _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 915 |
ASM_SIMP_TAC[second_derivative_abs_neg; derivative_abs_neg] THEN DISCH_THEN (K ALL_TAC) THEN |
| 916 |
REWRITE_TAC[REAL_ARITH `(&0 * a) * b + -- &1 * c = --c`] THEN |
| 917 |
ASM_SIMP_TAC[GSYM second_partial_neg]);; |
| 918 |
|
| 919 |
|
| 920 |
(* pow *) |
| 921 |
|
| 922 |
let REAL_DIFFERENTIABLE_AT_POW = prove |
| 923 |
(`!k x. (\x. x pow k) real_differentiable atreal x`, |
| 924 |
SIMP_TAC[REAL_DIFFERENTIABLE_POW_ATREAL; REAL_DIFFERENTIABLE_ID]);; |
| 925 |
|
| 926 |
let MK_M_TAYLOR_POW = prove |
| 927 |
(`m_cell_domain domain (y:real^N) w ==> |
| 928 |
diff2c_domain domain f ==> |
| 929 |
interval_arith ((f y) pow k) bounds ==> |
| 930 |
all_n 1 d_bounds_list (\i int. interval_arith ((&k * (f y) pow (k - 1)) * partial i f y) int) ==> |
| 931 |
(!x. x IN interval [domain] ==> all_n 1 dd_bounds_list (\i list_i. all_n 1 list_i |
| 932 |
(\j int. interval_arith (((&(k * (k - 1)) * f x pow (k - 2)) * partial j f x) |
| 933 |
* partial i f x + (&k * f x pow (k - 1)) * partial2 j i f x) int))) ==> |
| 934 |
m_taylor_interval (\x. (f x) pow k) domain y w bounds d_bounds_list dd_bounds_list`, |
| 935 |
REWRITE_TAC[m_taylor_interval; m_lin_approx; second_bounded; ETA_AX] THEN |
| 936 |
REPEAT DISCH_TAC THEN |
| 937 |
SUBGOAL_THEN `lift o f differentiable at (y:real^N)` ASSUME_TAC THENL |
| 938 |
[ |
| 939 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 940 |
REWRITE_TAC[diff2c_domain_alt; diff2_domain] THEN STRIP_TAC THEN |
| 941 |
new_rewrite [] [] diff2_imp_diff THEN REWRITE_TAC[] THEN |
| 942 |
FIRST_X_ASSUM MATCH_MP_TAC THEN |
| 943 |
MATCH_MP_TAC y_in_domain THEN EXISTS_TAC `w:real^N` THEN ASM_REWRITE_TAC[]; |
| 944 |
ALL_TAC |
| 945 |
] THEN |
| 946 |
|
| 947 |
SUBGOAL_THEN `(\x:real^N. f x pow k) = (\x. x pow k) o f` ASSUME_TAC THENL [ |
| 948 |
REWRITE_TAC[FUN_EQ_THM; o_THM]; |
| 949 |
ALL_TAC |
| 950 |
] THEN |
| 951 |
|
| 952 |
REPEAT STRIP_TAC THEN ASM_REWRITE_TAC[] THENL |
| 953 |
[ |
| 954 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 955 |
REWRITE_TAC[diff2c_domain] THEN REPEAT STRIP_TAC THEN |
| 956 |
apply_tac diff2c_pow_compose THEN FIRST_X_ASSUM MATCH_MP_TAC THEN ASM_REWRITE_TAC[]; |
| 957 |
apply_tac diff_uni_compose THEN ASM_REWRITE_TAC[REAL_DIFFERENTIABLE_AT_POW]; |
| 958 |
MP_TAC (ISPECL [`y:real^N`; `f:real^N->real`] partial_uni_compose') THEN |
| 959 |
ASM_REWRITE_TAC[] THEN |
| 960 |
DISCH_THEN (MP_TAC o SPEC `(\x:real. x pow k)`) THEN |
| 961 |
REWRITE_TAC[REAL_DIFFERENTIABLE_AT_POW] THEN |
| 962 |
ASM_SIMP_TAC[derivative_pow_x]; |
| 963 |
ALL_TAC |
| 964 |
] THEN |
| 965 |
|
| 966 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 967 |
REWRITE_TAC[diff2c_domain_alt; diff2_domain] THEN |
| 968 |
DISCH_THEN (MP_TAC o SPEC `x:real^N` o CONJUNCT1) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN |
| 969 |
MP_TAC (ISPECL [`x:real^N`; `f:real^N->real`] second_partial_uni_compose') THEN |
| 970 |
ASM_REWRITE_TAC[] THEN |
| 971 |
DISCH_THEN (MP_TAC o SPEC `\x. x pow k`) THEN |
| 972 |
REWRITE_TAC[diff2_pow_x] THEN |
| 973 |
ASM_SIMP_TAC[nth_derivative2; second_derivative_pow_x; derivative_pow_x]);; |
| 974 |
|
| 975 |
let MK_M_TAYLOR_POW2' = (UNDISCH_ALL o PURE_REWRITE_RULE[all_n1_raw] o prove) |
| 976 |
(`m_cell_domain domain (y:real^N) w ==> |
| 977 |
diff2c_domain domain f ==> |
| 978 |
interval_arith ((f y) pow 2) bounds ==> |
| 979 |
all_n 1 d_bounds_list (\i int. interval_arith ((&2 * f y) * partial i f y) int) ==> |
| 980 |
(!x. x IN interval [domain] ==> all_n 1 dd_bounds_list (\i list_i. all_n 1 list_i |
| 981 |
(\j int. interval_arith (&2 * (partial j f x * partial i f x |
| 982 |
+ f x * partial2 j i f x)) int))) ==> |
| 983 |
m_taylor_interval (\x. (f x) pow 2) domain y w bounds d_bounds_list dd_bounds_list`, |
| 984 |
REPEAT STRIP_TAC THEN MP_TAC (INST[`2`, `k:num`] MK_M_TAYLOR_POW) THEN |
| 985 |
ASM_REWRITE_TAC[ARITH_RULE `2 - 1 = 1 /\ 2 - 2 = 0`; REAL_POW_1; real_pow] THEN |
| 986 |
REWRITE_TAC[MULT_CLAUSES; REAL_MUL_RID] THEN |
| 987 |
ASM_REWRITE_TAC[REAL_ARITH `(a * b) * c + (a * x) * y = a * (b * c + x * y)`]);; |
| 988 |
|
| 989 |
let MK_M_TAYLOR_POW' = (UNDISCH_ALL o PURE_REWRITE_RULE[all_n1_raw] o prove) |
| 990 |
(`m_cell_domain domain (y:real^N) w ==> |
| 991 |
diff2c_domain domain f ==> |
| 992 |
interval_arith (f y * f y pow (k - 1)) bounds ==> |
| 993 |
k >= 2 ==> |
| 994 |
all_n 1 d_bounds_list (\i int. interval_arith ((&k * f y pow (k - 1)) * partial i f y) int) ==> |
| 995 |
(!x. x IN interval [domain] ==> all_n 1 dd_bounds_list (\i list_i. all_n 1 list_i |
| 996 |
(\j int. interval_arith ((&k * f x pow (k - 2)) * ((&(k - 1) * partial j f x) * partial i f x |
| 997 |
+ f x * partial2 j i f x)) int))) ==> |
| 998 |
m_taylor_interval (\x. (f x) pow k) domain y w bounds d_bounds_list dd_bounds_list`, |
| 999 |
REPEAT STRIP_TAC THEN MP_TAC MK_M_TAYLOR_POW THEN |
| 1000 |
ASM_REWRITE_TAC[GSYM REAL_OF_NUM_MUL; IMP_IMP] THEN |
| 1001 |
DISCH_THEN MATCH_MP_TAC THEN CONJ_TAC THENL [ |
| 1002 |
SUBGOAL_THEN `!x. x pow k = x * x pow (k - 1)` ASSUME_TAC THENL [ |
| 1003 |
GEN_TAC THEN MP_TAC (ARITH_RULE `k >= 2 ==> k = 1 + (k - 1)`) THEN ASM_REWRITE_TAC[] THEN |
| 1004 |
DISCH_THEN (fun th -> GEN_REWRITE_TAC (LAND_CONV o DEPTH_CONV) [th]) THEN |
| 1005 |
REWRITE_TAC[REAL_POW_ADD; REAL_POW_1]; |
| 1006 |
ALL_TAC |
| 1007 |
] THEN |
| 1008 |
ASM_REWRITE_TAC[]; |
| 1009 |
ALL_TAC |
| 1010 |
] THEN |
| 1011 |
SUBGOAL_THEN `!x. x pow (k - 1) = x pow (k - 2) * x` ASSUME_TAC THENL [ |
| 1012 |
ASM_SIMP_TAC[ARITH_RULE `k >= 2 ==> k - 1 = (k - 2) + 1`] THEN |
| 1013 |
REWRITE_TAC[REAL_POW_ADD; REAL_POW_1]; |
| 1014 |
ALL_TAC |
| 1015 |
] THEN |
| 1016 |
ASM_REWRITE_TAC[REAL_ARITH `(((k * k1) * f2) * j) * i + (k * f2 * f) * x = |
| 1017 |
(k * f2) * ((k1 * j) * i + f * x)`]);; |
| 1018 |
|
| 1019 |
(* inv *) |
| 1020 |
let MK_M_TAYLOR_INV' = (UNDISCH_ALL o PURE_REWRITE_RULE[float2_eq] o DISCH_ALL o |
| 1021 |
MY_RULE_FLOAT o prove) |
| 1022 |
(`m_cell_domain domain (y:real^N) w ==> |
| 1023 |
(!x. x IN interval [domain] ==> interval_arith (f x) f_bounds) ==> |
| 1024 |
interval_not_zero f_bounds ==> |
| 1025 |
diff2c_domain domain f ==> |
| 1026 |
interval_arith (inv (f y)) bounds ==> |
| 1027 |
all_n 1 d_bounds_list (\i int. interval_arith (--inv (f y * f y) * partial i f y) int) ==> |
| 1028 |
(!x. x IN interval [domain] ==> all_n 1 dd_bounds_list (\i list_i. all_n 1 list_i |
| 1029 |
(\j int. interval_arith (((&2 * inv (f x * f x * f x)) * partial j f x) * partial i f x - |
| 1030 |
inv (f x * f x) * partial2 j i f x) int))) ==> |
| 1031 |
m_taylor_interval (\x. inv (f x)) domain y w bounds d_bounds_list dd_bounds_list`, |
| 1032 |
REWRITE_TAC[m_taylor_interval; m_lin_approx; second_bounded; ETA_AX] THEN |
| 1033 |
REPEAT DISCH_TAC THEN |
| 1034 |
SUBGOAL_THEN `lift o f differentiable at (y:real^N)` ASSUME_TAC THENL |
| 1035 |
[ |
| 1036 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 1037 |
REWRITE_TAC[diff2c_domain_alt; diff2_domain] THEN STRIP_TAC THEN |
| 1038 |
new_rewrite [] [] diff2_imp_diff THEN REWRITE_TAC[] THEN |
| 1039 |
FIRST_X_ASSUM MATCH_MP_TAC THEN |
| 1040 |
MATCH_MP_TAC y_in_domain THEN EXISTS_TAC `w:real^N` THEN ASM_REWRITE_TAC[]; |
| 1041 |
ALL_TAC |
| 1042 |
] THEN |
| 1043 |
|
| 1044 |
SUBGOAL_THEN `!x:real^N. x IN interval [domain] ==> ~(f x = &0)` ASSUME_TAC THENL |
| 1045 |
[ |
| 1046 |
GEN_TAC THEN DISCH_TAC THEN |
| 1047 |
apply_tac interval_arith_not_zero THEN |
| 1048 |
EXISTS_TAC `f_bounds:real#real` THEN |
| 1049 |
ASM_REWRITE_TAC[] THEN |
| 1050 |
FIRST_X_ASSUM MATCH_MP_TAC THEN ASM_REWRITE_TAC[]; |
| 1051 |
ALL_TAC |
| 1052 |
] THEN |
| 1053 |
|
| 1054 |
SUBGOAL_THEN `~(f (y:real^N) = &0)` ASSUME_TAC THENL |
| 1055 |
[ |
| 1056 |
FIRST_X_ASSUM MATCH_MP_TAC THEN |
| 1057 |
MATCH_MP_TAC y_in_domain THEN EXISTS_TAC `w:real^N` THEN |
| 1058 |
ASM_REWRITE_TAC[]; |
| 1059 |
ALL_TAC |
| 1060 |
] THEN |
| 1061 |
|
| 1062 |
REPEAT STRIP_TAC THEN ASM_REWRITE_TAC[] THENL |
| 1063 |
[ |
| 1064 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 1065 |
REWRITE_TAC[diff2c_domain] THEN REPEAT STRIP_TAC THEN |
| 1066 |
ONCE_REWRITE_TAC[GSYM o_THM] THEN REWRITE_TAC[ETA_AX] THEN |
| 1067 |
apply_tac diff2c_inv_compose THEN CONJ_TAC THEN FIRST_X_ASSUM MATCH_MP_TAC THEN ASM_REWRITE_TAC[]; |
| 1068 |
new_rewrite [] [`inv _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 1069 |
apply_tac diff_uni_compose THEN ASM_REWRITE_TAC[] THEN |
| 1070 |
MATCH_MP_TAC REAL_DIFFERENTIABLE_AT_INV THEN ASM_REWRITE_TAC[]; |
| 1071 |
new_rewrite [] [`inv _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 1072 |
MP_TAC (ISPECL [`y:real^N`; `f:real^N->real`] partial_uni_compose') THEN |
| 1073 |
ASM_REWRITE_TAC[] THEN |
| 1074 |
DISCH_THEN (MP_TAC o SPEC `inv`) THEN |
| 1075 |
ANTS_TAC THENL |
| 1076 |
[ |
| 1077 |
MATCH_MP_TAC REAL_DIFFERENTIABLE_AT_INV THEN ASM_REWRITE_TAC[]; |
| 1078 |
ALL_TAC |
| 1079 |
] THEN |
| 1080 |
ASM_SIMP_TAC[derivative_inv]; |
| 1081 |
ALL_TAC |
| 1082 |
] THEN |
| 1083 |
|
| 1084 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 1085 |
REWRITE_TAC[diff2c_domain_alt; diff2_domain] THEN |
| 1086 |
DISCH_THEN (MP_TAC o SPEC `x:real^N` o CONJUNCT1) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN |
| 1087 |
MP_TAC (ISPECL [`x:real^N`; `f:real^N->real`] second_partial_uni_compose') THEN |
| 1088 |
ASM_REWRITE_TAC[] THEN |
| 1089 |
DISCH_THEN (MP_TAC o SPEC `inv`) THEN |
| 1090 |
ANTS_TAC THENL |
| 1091 |
[ |
| 1092 |
MATCH_MP_TAC diff2_inv THEN |
| 1093 |
FIRST_X_ASSUM MATCH_MP_TAC THEN ASM_REWRITE_TAC[]; |
| 1094 |
ALL_TAC |
| 1095 |
] THEN |
| 1096 |
|
| 1097 |
new_rewrite [] [`inv _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 1098 |
ASM_SIMP_TAC[second_derivative_inv; derivative_inv; REAL_MUL_LNEG; GSYM real_sub] THEN |
| 1099 |
ASM_SIMP_TAC[REAL_ARITH `a pow 3 = a * a * a`]);; |
| 1100 |
|
| 1101 |
|
| 1102 |
(* sqrt *) |
| 1103 |
let MK_M_TAYLOR_SQRT' = (UNDISCH_ALL o PURE_REWRITE_RULE[float2_eq; float4_eq] o |
| 1104 |
DISCH_ALL o MY_RULE_FLOAT o prove) |
| 1105 |
(`m_cell_domain domain (y:real^N) w ==> |
| 1106 |
(!x. x IN interval [domain] ==> interval_arith (f x) f_bounds) ==> |
| 1107 |
interval_pos f_bounds ==> |
| 1108 |
diff2c_domain domain f ==> |
| 1109 |
interval_arith (sqrt (f y)) bounds ==> |
| 1110 |
all_n 1 d_bounds_list (\i int. interval_arith (inv (&2 * sqrt (f y)) * partial i f y) int) ==> |
| 1111 |
(!x. x IN interval [domain] ==> all_n 1 dd_bounds_list (\i list_i. all_n 1 list_i |
| 1112 |
(\j int. interval_arith ((--inv ((&2 * sqrt (f x)) * (&2 * f x)) * partial j f x) * partial i f x + |
| 1113 |
inv (&2 * sqrt (f x)) * partial2 j i f x) int))) ==> |
| 1114 |
m_taylor_interval (\x. sqrt (f x)) domain y w bounds d_bounds_list dd_bounds_list`, |
| 1115 |
REWRITE_TAC[m_taylor_interval; m_lin_approx; second_bounded; ETA_AX] THEN |
| 1116 |
REPEAT DISCH_TAC THEN |
| 1117 |
SUBGOAL_THEN `lift o f differentiable at (y:real^N)` ASSUME_TAC THENL |
| 1118 |
[ |
| 1119 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 1120 |
REWRITE_TAC[diff2c_domain_alt; diff2_domain] THEN STRIP_TAC THEN |
| 1121 |
new_rewrite [] [] diff2_imp_diff THEN REWRITE_TAC[] THEN |
| 1122 |
FIRST_X_ASSUM MATCH_MP_TAC THEN |
| 1123 |
MATCH_MP_TAC y_in_domain THEN EXISTS_TAC `w:real^N` THEN ASM_REWRITE_TAC[]; |
| 1124 |
ALL_TAC |
| 1125 |
] THEN |
| 1126 |
|
| 1127 |
SUBGOAL_THEN `!x:real^N. x IN interval [domain] ==> &0 < f x` ASSUME_TAC THENL |
| 1128 |
[ |
| 1129 |
GEN_TAC THEN DISCH_TAC THEN |
| 1130 |
apply_tac interval_arith_pos THEN |
| 1131 |
EXISTS_TAC `f_bounds:real#real` THEN |
| 1132 |
ASM_REWRITE_TAC[] THEN |
| 1133 |
FIRST_X_ASSUM MATCH_MP_TAC THEN ASM_REWRITE_TAC[]; |
| 1134 |
ALL_TAC |
| 1135 |
] THEN |
| 1136 |
|
| 1137 |
SUBGOAL_THEN `&0 < f (y:real^N)` ASSUME_TAC THENL |
| 1138 |
[ |
| 1139 |
FIRST_X_ASSUM MATCH_MP_TAC THEN |
| 1140 |
MATCH_MP_TAC y_in_domain THEN EXISTS_TAC `w:real^N` THEN |
| 1141 |
ASM_REWRITE_TAC[]; |
| 1142 |
ALL_TAC |
| 1143 |
] THEN |
| 1144 |
|
| 1145 |
REPEAT STRIP_TAC THEN ASM_REWRITE_TAC[] THENL |
| 1146 |
[ |
| 1147 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 1148 |
REWRITE_TAC[diff2c_domain] THEN REPEAT STRIP_TAC THEN |
| 1149 |
ONCE_REWRITE_TAC[GSYM o_THM] THEN REWRITE_TAC[ETA_AX] THEN |
| 1150 |
apply_tac diff2c_sqrt_compose THEN CONJ_TAC THEN FIRST_X_ASSUM MATCH_MP_TAC THEN ASM_REWRITE_TAC[]; |
| 1151 |
new_rewrite [] [`sqrt _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 1152 |
apply_tac diff_uni_compose THEN ASM_REWRITE_TAC[] THEN |
| 1153 |
MATCH_MP_TAC REAL_DIFFERENTIABLE_AT_SQRT THEN ASM_REWRITE_TAC[]; |
| 1154 |
new_rewrite [] [`sqrt _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 1155 |
MP_TAC (ISPECL [`y:real^N`; `f:real^N->real`] partial_uni_compose') THEN |
| 1156 |
ASM_REWRITE_TAC[] THEN |
| 1157 |
DISCH_THEN (MP_TAC o SPEC `sqrt`) THEN |
| 1158 |
ANTS_TAC THENL |
| 1159 |
[ |
| 1160 |
MATCH_MP_TAC REAL_DIFFERENTIABLE_AT_SQRT THEN ASM_REWRITE_TAC[]; |
| 1161 |
ALL_TAC |
| 1162 |
] THEN |
| 1163 |
ASM_SIMP_TAC[derivative_sqrt]; |
| 1164 |
ALL_TAC |
| 1165 |
] THEN |
| 1166 |
|
| 1167 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 1168 |
REWRITE_TAC[diff2c_domain_alt; diff2_domain] THEN |
| 1169 |
DISCH_THEN (MP_TAC o SPEC `x:real^N` o CONJUNCT1) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN |
| 1170 |
MP_TAC (ISPECL [`x:real^N`; `f:real^N->real`] second_partial_uni_compose') THEN |
| 1171 |
ASM_REWRITE_TAC[] THEN |
| 1172 |
DISCH_THEN (MP_TAC o SPEC `sqrt`) THEN |
| 1173 |
ANTS_TAC THENL |
| 1174 |
[ |
| 1175 |
MATCH_MP_TAC diff2_sqrt THEN |
| 1176 |
FIRST_X_ASSUM MATCH_MP_TAC THEN ASM_REWRITE_TAC[]; |
| 1177 |
ALL_TAC |
| 1178 |
] THEN |
| 1179 |
|
| 1180 |
new_rewrite [] [`sqrt _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 1181 |
ASM_SIMP_TAC[second_derivative_sqrt; derivative_sqrt] THEN DISCH_THEN (fun th -> ALL_TAC) THEN |
| 1182 |
REWRITE_TAC[REAL_ARITH `a pow 3 = a * a pow 2`] THEN |
| 1183 |
new_rewrite [] [] SQRT_MUL THEN |
| 1184 |
new_rewrite [] [] POW_2_SQRT THENL |
| 1185 |
[ |
| 1186 |
MATCH_MP_TAC REAL_LT_IMP_LE THEN FIRST_X_ASSUM MATCH_MP_TAC THEN ASM_REWRITE_TAC[]; |
| 1187 |
ALL_TAC |
| 1188 |
] THEN |
| 1189 |
ASM_SIMP_TAC[REAL_ARITH `&4 * a * b = (&2 * a) * (&2 * b)`]);; |
| 1190 |
|
| 1191 |
(* exp *) |
| 1192 |
let MK_M_TAYLOR_EXP' = (UNDISCH_ALL o PURE_REWRITE_RULE[float1_eq] o DISCH_ALL o |
| 1193 |
MY_RULE_FLOAT o prove) |
| 1194 |
(`m_cell_domain domain (y:real^N) w ==> |
| 1195 |
diff2c_domain domain f ==> |
| 1196 |
interval_arith (exp (f y)) bounds ==> |
| 1197 |
all_n 1 d_bounds_list (\i int. interval_arith (exp (f y) * partial i f y) int) ==> |
| 1198 |
(!x. x IN interval [domain] ==> all_n 1 dd_bounds_list (\i list_i. all_n 1 list_i |
| 1199 |
(\j int. interval_arith ((exp (f x) * partial j f x) |
| 1200 |
* partial i f x + exp (f x) * partial2 j i f x) int))) ==> |
| 1201 |
m_taylor_interval (\x. exp (f x)) domain y w bounds d_bounds_list dd_bounds_list`, |
| 1202 |
REWRITE_TAC[m_taylor_interval; m_lin_approx; second_bounded; ETA_AX] THEN |
| 1203 |
REPEAT DISCH_TAC THEN |
| 1204 |
SUBGOAL_THEN `lift o f differentiable at (y:real^N)` ASSUME_TAC THENL |
| 1205 |
[ |
| 1206 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 1207 |
REWRITE_TAC[diff2c_domain_alt; diff2_domain] THEN STRIP_TAC THEN |
| 1208 |
new_rewrite [] [] diff2_imp_diff THEN REWRITE_TAC[] THEN |
| 1209 |
FIRST_X_ASSUM MATCH_MP_TAC THEN |
| 1210 |
MATCH_MP_TAC y_in_domain THEN EXISTS_TAC `w:real^N` THEN ASM_REWRITE_TAC[]; |
| 1211 |
ALL_TAC |
| 1212 |
] THEN |
| 1213 |
|
| 1214 |
REPEAT STRIP_TAC THEN ASM_REWRITE_TAC[] THENL |
| 1215 |
[ |
| 1216 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 1217 |
REWRITE_TAC[diff2c_domain] THEN REPEAT STRIP_TAC THEN |
| 1218 |
ONCE_REWRITE_TAC[GSYM o_THM] THEN REWRITE_TAC[ETA_AX] THEN |
| 1219 |
apply_tac diff2c_exp_compose THEN FIRST_X_ASSUM MATCH_MP_TAC THEN ASM_REWRITE_TAC[]; |
| 1220 |
new_rewrite [] [`exp _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 1221 |
apply_tac diff_uni_compose THEN ASM_REWRITE_TAC[] THEN |
| 1222 |
REWRITE_TAC[REAL_DIFFERENTIABLE_AT_EXP]; |
| 1223 |
new_rewrite [] [`exp _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 1224 |
MP_TAC (ISPECL [`y:real^N`; `f:real^N->real`] partial_uni_compose') THEN |
| 1225 |
ASM_REWRITE_TAC[] THEN |
| 1226 |
DISCH_THEN (MP_TAC o SPEC `exp`) THEN REWRITE_TAC[REAL_DIFFERENTIABLE_AT_EXP] THEN |
| 1227 |
ASM_SIMP_TAC[derivative_exp]; |
| 1228 |
ALL_TAC |
| 1229 |
] THEN |
| 1230 |
|
| 1231 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 1232 |
REWRITE_TAC[diff2c_domain_alt; diff2_domain] THEN |
| 1233 |
DISCH_THEN (MP_TAC o SPEC `x:real^N` o CONJUNCT1) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN |
| 1234 |
MP_TAC (ISPECL [`x:real^N`; `f:real^N->real`] second_partial_uni_compose') THEN |
| 1235 |
ASM_REWRITE_TAC[] THEN |
| 1236 |
DISCH_THEN (MP_TAC o SPEC `exp`) THEN |
| 1237 |
REWRITE_TAC[diff2_exp] THEN |
| 1238 |
new_rewrite [] [`exp _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 1239 |
ASM_SIMP_TAC[nth_derivative2; second_derivative_exp; derivative_exp]);; |
| 1240 |
|
| 1241 |
(* log *) |
| 1242 |
let MK_M_TAYLOR_LOG' = (UNDISCH_ALL o PURE_REWRITE_RULE[num2_eq] o |
| 1243 |
DISCH_ALL o MY_RULE_FLOAT o prove) |
| 1244 |
(`m_cell_domain domain (y:real^N) w ==> |
| 1245 |
(!x. x IN interval [domain] ==> interval_arith (f x) f_bounds) ==> |
| 1246 |
interval_pos f_bounds ==> |
| 1247 |
diff2c_domain domain f ==> |
| 1248 |
interval_arith (log (f y)) bounds ==> |
| 1249 |
all_n 1 d_bounds_list (\i int. interval_arith (inv (f y) * partial i f y) int) ==> |
| 1250 |
(!x. x IN interval [domain] ==> all_n 1 dd_bounds_list (\i list_i. all_n 1 list_i |
| 1251 |
(\j int. interval_arith ((--(inv (f x) pow 2) * partial j f x) * partial i f x + |
| 1252 |
inv (f x) * partial2 j i f x) int))) ==> |
| 1253 |
m_taylor_interval (\x. log (f x)) domain y w bounds d_bounds_list dd_bounds_list`, |
| 1254 |
REWRITE_TAC[m_taylor_interval; m_lin_approx; second_bounded; ETA_AX] THEN |
| 1255 |
REPEAT DISCH_TAC THEN |
| 1256 |
SUBGOAL_THEN `lift o f differentiable at (y:real^N)` ASSUME_TAC THENL |
| 1257 |
[ |
| 1258 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 1259 |
REWRITE_TAC[diff2c_domain_alt; diff2_domain] THEN STRIP_TAC THEN |
| 1260 |
new_rewrite [] [] diff2_imp_diff THEN REWRITE_TAC[] THEN |
| 1261 |
FIRST_X_ASSUM MATCH_MP_TAC THEN |
| 1262 |
MATCH_MP_TAC y_in_domain THEN EXISTS_TAC `w:real^N` THEN ASM_REWRITE_TAC[]; |
| 1263 |
ALL_TAC |
| 1264 |
] THEN |
| 1265 |
|
| 1266 |
SUBGOAL_THEN `!x:real^N. x IN interval [domain] ==> &0 < f x` ASSUME_TAC THENL |
| 1267 |
[ |
| 1268 |
GEN_TAC THEN DISCH_TAC THEN |
| 1269 |
apply_tac interval_arith_pos THEN |
| 1270 |
EXISTS_TAC `f_bounds:real#real` THEN |
| 1271 |
ASM_REWRITE_TAC[] THEN |
| 1272 |
FIRST_X_ASSUM MATCH_MP_TAC THEN ASM_REWRITE_TAC[]; |
| 1273 |
ALL_TAC |
| 1274 |
] THEN |
| 1275 |
|
| 1276 |
SUBGOAL_THEN `&0 < f (y:real^N)` ASSUME_TAC THENL |
| 1277 |
[ |
| 1278 |
FIRST_X_ASSUM MATCH_MP_TAC THEN |
| 1279 |
MATCH_MP_TAC y_in_domain THEN EXISTS_TAC `w:real^N` THEN |
| 1280 |
ASM_REWRITE_TAC[]; |
| 1281 |
ALL_TAC |
| 1282 |
] THEN |
| 1283 |
|
| 1284 |
REPEAT STRIP_TAC THEN ASM_REWRITE_TAC[] THENL |
| 1285 |
[ |
| 1286 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 1287 |
REWRITE_TAC[diff2c_domain] THEN REPEAT STRIP_TAC THEN |
| 1288 |
ONCE_REWRITE_TAC[GSYM o_THM] THEN REWRITE_TAC[ETA_AX] THEN |
| 1289 |
apply_tac diff2c_log_compose THEN CONJ_TAC THEN FIRST_X_ASSUM MATCH_MP_TAC THEN ASM_REWRITE_TAC[]; |
| 1290 |
new_rewrite [] [`log _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 1291 |
apply_tac diff_uni_compose THEN ASM_REWRITE_TAC[] THEN |
| 1292 |
MATCH_MP_TAC REAL_DIFFERENTIABLE_AT_LOG THEN ASM_REWRITE_TAC[]; |
| 1293 |
new_rewrite [] [`log _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 1294 |
MP_TAC (ISPECL [`y:real^N`; `f:real^N->real`] partial_uni_compose') THEN |
| 1295 |
ASM_REWRITE_TAC[] THEN |
| 1296 |
DISCH_THEN (MP_TAC o SPEC `log`) THEN |
| 1297 |
ANTS_TAC THENL |
| 1298 |
[ |
| 1299 |
MATCH_MP_TAC REAL_DIFFERENTIABLE_AT_LOG THEN ASM_REWRITE_TAC[]; |
| 1300 |
ALL_TAC |
| 1301 |
] THEN |
| 1302 |
ASM_SIMP_TAC[derivative_log]; |
| 1303 |
ALL_TAC |
| 1304 |
] THEN |
| 1305 |
|
| 1306 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 1307 |
REWRITE_TAC[diff2c_domain_alt; diff2_domain] THEN |
| 1308 |
DISCH_THEN (MP_TAC o SPEC `x:real^N` o CONJUNCT1) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN |
| 1309 |
MP_TAC (ISPECL [`x:real^N`; `f:real^N->real`] second_partial_uni_compose') THEN |
| 1310 |
ASM_REWRITE_TAC[] THEN |
| 1311 |
DISCH_THEN (MP_TAC o SPEC `log`) THEN |
| 1312 |
ANTS_TAC THENL |
| 1313 |
[ |
| 1314 |
MATCH_MP_TAC diff2_log THEN |
| 1315 |
FIRST_X_ASSUM MATCH_MP_TAC THEN ASM_REWRITE_TAC[]; |
| 1316 |
ALL_TAC |
| 1317 |
] THEN |
| 1318 |
|
| 1319 |
new_rewrite [] [`log _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 1320 |
ASM_SIMP_TAC[second_derivative_log; derivative_log; REAL_INV_POW]);; |
| 1321 |
|
| 1322 |
(* atn *) |
| 1323 |
let MK_M_TAYLOR_ATN' = (UNDISCH_ALL o PURE_REWRITE_RULE[float1_eq; float2_eq; num2_eq] o DISCH_ALL o |
| 1324 |
MY_RULE_FLOAT o prove) |
| 1325 |
(`m_cell_domain domain (y:real^N) w ==> |
| 1326 |
diff2c_domain domain f ==> |
| 1327 |
interval_arith (atn (f y)) bounds ==> |
| 1328 |
all_n 1 d_bounds_list (\i int. interval_arith (inv (&1 + f y * f y) * partial i f y) int) ==> |
| 1329 |
(!x. x IN interval [domain] ==> all_n 1 dd_bounds_list (\i list_i. all_n 1 list_i |
| 1330 |
(\j int. interval_arith ((((-- &2 * f x) * inv (&1 + f x * f x) pow 2) * partial j f x) |
| 1331 |
* partial i f x + inv (&1 + f x * f x) * partial2 j i f x) int))) ==> |
| 1332 |
m_taylor_interval (\x. atn (f x)) domain y w bounds d_bounds_list dd_bounds_list`, |
| 1333 |
REWRITE_TAC[m_taylor_interval; m_lin_approx; second_bounded; ETA_AX] THEN |
| 1334 |
REPEAT DISCH_TAC THEN |
| 1335 |
SUBGOAL_THEN `lift o f differentiable at (y:real^N)` ASSUME_TAC THENL |
| 1336 |
[ |
| 1337 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 1338 |
REWRITE_TAC[diff2c_domain_alt; diff2_domain] THEN STRIP_TAC THEN |
| 1339 |
new_rewrite [] [] diff2_imp_diff THEN REWRITE_TAC[] THEN |
| 1340 |
FIRST_X_ASSUM MATCH_MP_TAC THEN |
| 1341 |
MATCH_MP_TAC y_in_domain THEN EXISTS_TAC `w:real^N` THEN ASM_REWRITE_TAC[]; |
| 1342 |
ALL_TAC |
| 1343 |
] THEN |
| 1344 |
|
| 1345 |
REPEAT STRIP_TAC THEN ASM_REWRITE_TAC[] THENL |
| 1346 |
[ |
| 1347 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 1348 |
REWRITE_TAC[diff2c_domain] THEN REPEAT STRIP_TAC THEN |
| 1349 |
ONCE_REWRITE_TAC[GSYM o_THM] THEN REWRITE_TAC[ETA_AX] THEN |
| 1350 |
apply_tac diff2c_atn_compose THEN FIRST_X_ASSUM MATCH_MP_TAC THEN ASM_REWRITE_TAC[]; |
| 1351 |
new_rewrite [] [`atn _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 1352 |
apply_tac diff_uni_compose THEN ASM_REWRITE_TAC[] THEN |
| 1353 |
REWRITE_TAC[REAL_DIFFERENTIABLE_AT_ATN]; |
| 1354 |
new_rewrite [] [`atn _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 1355 |
MP_TAC (ISPECL [`y:real^N`; `f:real^N->real`] partial_uni_compose') THEN |
| 1356 |
ASM_REWRITE_TAC[] THEN |
| 1357 |
DISCH_THEN (MP_TAC o SPEC `atn`) THEN REWRITE_TAC[REAL_DIFFERENTIABLE_AT_ATN] THEN |
| 1358 |
ASM_SIMP_TAC[derivative_atn]; |
| 1359 |
ALL_TAC |
| 1360 |
] THEN |
| 1361 |
|
| 1362 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 1363 |
REWRITE_TAC[diff2c_domain_alt; diff2_domain] THEN |
| 1364 |
DISCH_THEN (MP_TAC o SPEC `x:real^N` o CONJUNCT1) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN |
| 1365 |
MP_TAC (ISPECL [`x:real^N`; `f:real^N->real`] second_partial_uni_compose') THEN |
| 1366 |
ASM_REWRITE_TAC[] THEN |
| 1367 |
DISCH_THEN (MP_TAC o SPEC `atn`) THEN |
| 1368 |
REWRITE_TAC[diff2_atn] THEN |
| 1369 |
new_rewrite [] [`atn _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 1370 |
ASM_SIMP_TAC[nth_derivative2; second_derivative_atn; derivative_atn] THEN |
| 1371 |
new_rewrite [] [`f x pow 2`] REAL_POW_2 THEN |
| 1372 |
ASM_SIMP_TAC[]);; |
| 1373 |
|
| 1374 |
(* cos *) |
| 1375 |
let MK_M_TAYLOR_COS' = (UNDISCH_ALL o PURE_REWRITE_RULE[float1_eq; float2_eq; num2_eq] o DISCH_ALL o |
| 1376 |
MY_RULE_FLOAT o prove) |
| 1377 |
(`m_cell_domain domain (y:real^N) w ==> |
| 1378 |
diff2c_domain domain f ==> |
| 1379 |
interval_arith (cos (f y)) bounds ==> |
| 1380 |
all_n 1 d_bounds_list (\i int. interval_arith (--sin (f y) * partial i f y) int) ==> |
| 1381 |
(!x. x IN interval [domain] ==> all_n 1 dd_bounds_list (\i list_i. all_n 1 list_i |
| 1382 |
(\j int. interval_arith (--((cos (f x) * partial j f x) * partial i f x |
| 1383 |
+ sin (f x) * partial2 j i f x)) int))) ==> |
| 1384 |
m_taylor_interval (\x. cos (f x)) domain y w bounds d_bounds_list dd_bounds_list`, |
| 1385 |
REWRITE_TAC[m_taylor_interval; m_lin_approx; second_bounded; ETA_AX] THEN |
| 1386 |
REPEAT DISCH_TAC THEN |
| 1387 |
SUBGOAL_THEN `lift o f differentiable at (y:real^N)` ASSUME_TAC THENL [ |
| 1388 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 1389 |
REWRITE_TAC[diff2c_domain_alt; diff2_domain] THEN STRIP_TAC THEN |
| 1390 |
new_rewrite [] [] diff2_imp_diff THEN REWRITE_TAC[] THEN |
| 1391 |
FIRST_X_ASSUM MATCH_MP_TAC THEN |
| 1392 |
MATCH_MP_TAC y_in_domain THEN EXISTS_TAC `w:real^N` THEN ASM_REWRITE_TAC[]; |
| 1393 |
ALL_TAC |
| 1394 |
] THEN |
| 1395 |
|
| 1396 |
REPEAT STRIP_TAC THEN ASM_REWRITE_TAC[] THENL [ |
| 1397 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 1398 |
REWRITE_TAC[diff2c_domain] THEN REPEAT STRIP_TAC THEN |
| 1399 |
ONCE_REWRITE_TAC[GSYM o_THM] THEN REWRITE_TAC[ETA_AX] THEN |
| 1400 |
apply_tac diff2c_cos_compose THEN FIRST_X_ASSUM MATCH_MP_TAC THEN ASM_REWRITE_TAC[]; |
| 1401 |
new_rewrite [] [`cos _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 1402 |
apply_tac diff_uni_compose THEN ASM_REWRITE_TAC[] THEN |
| 1403 |
REWRITE_TAC[REAL_DIFFERENTIABLE_AT_COS]; |
| 1404 |
new_rewrite [] [`cos _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 1405 |
MP_TAC (ISPECL [`y:real^N`; `f:real^N->real`] partial_uni_compose') THEN |
| 1406 |
ASM_REWRITE_TAC[] THEN |
| 1407 |
DISCH_THEN (MP_TAC o SPEC `cos`) THEN REWRITE_TAC[REAL_DIFFERENTIABLE_AT_COS] THEN |
| 1408 |
ASM_SIMP_TAC[derivative_cos]; |
| 1409 |
ALL_TAC |
| 1410 |
] THEN |
| 1411 |
|
| 1412 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 1413 |
REWRITE_TAC[diff2c_domain_alt; diff2_domain] THEN |
| 1414 |
DISCH_THEN (MP_TAC o SPEC `x:real^N` o CONJUNCT1) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN |
| 1415 |
MP_TAC (ISPECL [`x:real^N`; `f:real^N->real`] second_partial_uni_compose') THEN |
| 1416 |
ASM_REWRITE_TAC[] THEN |
| 1417 |
DISCH_THEN (MP_TAC o SPEC `cos`) THEN |
| 1418 |
REWRITE_TAC[diff2_cos] THEN |
| 1419 |
new_rewrite [] [`cos _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 1420 |
ASM_SIMP_TAC[second_derivative_cos; derivative_cos] THEN |
| 1421 |
ASM_SIMP_TAC[REAL_ARITH `(--c * p1) * p2 + --s * p3 = --((c * p1) * p2 + s * p3)`]);; |
| 1422 |
|
| 1423 |
(* sin *) |
| 1424 |
let MK_M_TAYLOR_SIN' = (UNDISCH_ALL o PURE_REWRITE_RULE[float1_eq; float2_eq; num2_eq] o DISCH_ALL o |
| 1425 |
MY_RULE_FLOAT o prove) |
| 1426 |
(`m_cell_domain domain (y:real^N) w ==> |
| 1427 |
diff2c_domain domain f ==> |
| 1428 |
interval_arith (sin (f y)) bounds ==> |
| 1429 |
all_n 1 d_bounds_list (\i int. interval_arith (cos (f y) * partial i f y) int) ==> |
| 1430 |
(!x. x IN interval [domain] ==> all_n 1 dd_bounds_list (\i list_i. all_n 1 list_i |
| 1431 |
(\j int. interval_arith (((--sin (f x)) * partial j f x) * partial i f x |
| 1432 |
+ cos (f x) * partial2 j i f x) int))) ==> |
| 1433 |
m_taylor_interval (\x. sin (f x)) domain y w bounds d_bounds_list dd_bounds_list`, |
| 1434 |
REWRITE_TAC[m_taylor_interval; m_lin_approx; second_bounded; ETA_AX] THEN |
| 1435 |
REPEAT DISCH_TAC THEN |
| 1436 |
SUBGOAL_THEN `lift o f differentiable at (y:real^N)` ASSUME_TAC THENL [ |
| 1437 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 1438 |
REWRITE_TAC[diff2c_domain_alt; diff2_domain] THEN STRIP_TAC THEN |
| 1439 |
new_rewrite [] [] diff2_imp_diff THEN REWRITE_TAC[] THEN |
| 1440 |
FIRST_X_ASSUM MATCH_MP_TAC THEN |
| 1441 |
MATCH_MP_TAC y_in_domain THEN EXISTS_TAC `w:real^N` THEN ASM_REWRITE_TAC[]; |
| 1442 |
ALL_TAC |
| 1443 |
] THEN |
| 1444 |
|
| 1445 |
REPEAT STRIP_TAC THEN ASM_REWRITE_TAC[] THENL [ |
| 1446 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 1447 |
REWRITE_TAC[diff2c_domain] THEN REPEAT STRIP_TAC THEN |
| 1448 |
ONCE_REWRITE_TAC[GSYM o_THM] THEN REWRITE_TAC[ETA_AX] THEN |
| 1449 |
apply_tac diff2c_sin_compose THEN FIRST_X_ASSUM MATCH_MP_TAC THEN ASM_REWRITE_TAC[]; |
| 1450 |
new_rewrite [] [`sin _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 1451 |
apply_tac diff_uni_compose THEN ASM_REWRITE_TAC[] THEN |
| 1452 |
REWRITE_TAC[REAL_DIFFERENTIABLE_AT_SIN]; |
| 1453 |
new_rewrite [] [`sin _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 1454 |
MP_TAC (ISPECL [`y:real^N`; `f:real^N->real`] partial_uni_compose') THEN |
| 1455 |
ASM_REWRITE_TAC[] THEN |
| 1456 |
DISCH_THEN (MP_TAC o SPEC `sin`) THEN REWRITE_TAC[REAL_DIFFERENTIABLE_AT_SIN] THEN |
| 1457 |
ASM_SIMP_TAC[derivative_sin]; |
| 1458 |
ALL_TAC |
| 1459 |
] THEN |
| 1460 |
|
| 1461 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 1462 |
REWRITE_TAC[diff2c_domain_alt; diff2_domain] THEN |
| 1463 |
DISCH_THEN (MP_TAC o SPEC `x:real^N` o CONJUNCT1) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN |
| 1464 |
MP_TAC (ISPECL [`x:real^N`; `f:real^N->real`] second_partial_uni_compose') THEN |
| 1465 |
ASM_REWRITE_TAC[] THEN |
| 1466 |
DISCH_THEN (MP_TAC o SPEC `sin`) THEN |
| 1467 |
REWRITE_TAC[diff2_sin] THEN |
| 1468 |
new_rewrite [] [`sin _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 1469 |
ASM_SIMP_TAC[second_derivative_sin; derivative_sin]);; |
| 1470 |
|
| 1471 |
(* acs *) |
| 1472 |
let iabs_lemma = GEN_REWRITE_RULE (RAND_CONV o RAND_CONV) [GSYM float1_eq] (REFL `iabs f_bounds < &1`);; |
| 1473 |
|
| 1474 |
let MK_M_TAYLOR_ACS' = (UNDISCH_ALL o PURE_ONCE_REWRITE_RULE[iabs_lemma] o |
| 1475 |
PURE_REWRITE_RULE[float1_eq; num3_eq] o DISCH_ALL o |
| 1476 |
MY_RULE_FLOAT o prove) |
| 1477 |
(`m_cell_domain domain (y:real^N) w ==> |
| 1478 |
(!x. x IN interval [domain] ==> interval_arith (f x) f_bounds) ==> |
| 1479 |
iabs f_bounds < &1 ==> |
| 1480 |
diff2c_domain domain f ==> |
| 1481 |
interval_arith (acs (f y)) bounds ==> |
| 1482 |
all_n 1 d_bounds_list |
| 1483 |
(\i int. interval_arith (--inv (sqrt (&1 - f y * f y)) * partial i f y) int) ==> |
| 1484 |
(!x. x IN interval [domain] ==> all_n 1 dd_bounds_list (\i list_i. all_n 1 list_i |
| 1485 |
(\j int. interval_arith ((--(f x / sqrt ((&1 - f x * f x) pow 3)) * partial j f x) * partial i f x - |
| 1486 |
inv (sqrt (&1 - f x * f x)) * partial2 j i f x) int))) ==> |
| 1487 |
m_taylor_interval (\x. acs (f x)) domain y w bounds d_bounds_list dd_bounds_list`, |
| 1488 |
REWRITE_TAC[m_taylor_interval; m_lin_approx; second_bounded; ETA_AX] THEN |
| 1489 |
REPEAT DISCH_TAC THEN |
| 1490 |
SUBGOAL_THEN `lift o f differentiable at (y:real^N)` ASSUME_TAC THENL |
| 1491 |
[ |
| 1492 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 1493 |
REWRITE_TAC[diff2c_domain_alt; diff2_domain] THEN STRIP_TAC THEN |
| 1494 |
new_rewrite [] [] diff2_imp_diff THEN REWRITE_TAC[] THEN |
| 1495 |
FIRST_X_ASSUM MATCH_MP_TAC THEN |
| 1496 |
MATCH_MP_TAC y_in_domain THEN EXISTS_TAC `w:real^N` THEN ASM_REWRITE_TAC[]; |
| 1497 |
ALL_TAC |
| 1498 |
] THEN |
| 1499 |
|
| 1500 |
SUBGOAL_THEN `!x:real^N. x IN interval [domain] ==> abs (f x) < &1` ASSUME_TAC THENL |
| 1501 |
[ |
| 1502 |
GEN_TAC THEN DISCH_TAC THEN |
| 1503 |
apply_tac interval_arith_abs THEN |
| 1504 |
EXISTS_TAC `f_bounds:real#real` THEN |
| 1505 |
ASM_REWRITE_TAC[] THEN |
| 1506 |
FIRST_X_ASSUM MATCH_MP_TAC THEN ASM_REWRITE_TAC[]; |
| 1507 |
ALL_TAC |
| 1508 |
] THEN |
| 1509 |
|
| 1510 |
SUBGOAL_THEN `abs (f (y:real^N)) < &1` ASSUME_TAC THENL |
| 1511 |
[ |
| 1512 |
FIRST_X_ASSUM MATCH_MP_TAC THEN |
| 1513 |
MATCH_MP_TAC y_in_domain THEN EXISTS_TAC `w:real^N` THEN |
| 1514 |
ASM_REWRITE_TAC[]; |
| 1515 |
ALL_TAC |
| 1516 |
] THEN |
| 1517 |
|
| 1518 |
REPEAT STRIP_TAC THEN ASM_REWRITE_TAC[] THENL |
| 1519 |
[ |
| 1520 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 1521 |
REWRITE_TAC[diff2c_domain] THEN REPEAT STRIP_TAC THEN |
| 1522 |
ONCE_REWRITE_TAC[GSYM o_THM] THEN REWRITE_TAC[ETA_AX] THEN |
| 1523 |
apply_tac diff2c_acs_compose THEN CONJ_TAC THEN FIRST_X_ASSUM MATCH_MP_TAC THEN ASM_REWRITE_TAC[]; |
| 1524 |
new_rewrite [] [`acs _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 1525 |
apply_tac diff_uni_compose THEN ASM_REWRITE_TAC[] THEN |
| 1526 |
MATCH_MP_TAC REAL_DIFFERENTIABLE_AT_ACS THEN ASM_REWRITE_TAC[]; |
| 1527 |
new_rewrite [] [`acs _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 1528 |
MP_TAC (ISPECL [`y:real^N`; `f:real^N->real`] partial_uni_compose') THEN |
| 1529 |
ASM_REWRITE_TAC[] THEN |
| 1530 |
DISCH_THEN (MP_TAC o SPEC `acs`) THEN |
| 1531 |
ANTS_TAC THENL |
| 1532 |
[ |
| 1533 |
MATCH_MP_TAC REAL_DIFFERENTIABLE_AT_ACS THEN ASM_REWRITE_TAC[]; |
| 1534 |
ALL_TAC |
| 1535 |
] THEN |
| 1536 |
ASM_SIMP_TAC[derivative_acs]; |
| 1537 |
ALL_TAC |
| 1538 |
] THEN |
| 1539 |
|
| 1540 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 1541 |
REWRITE_TAC[diff2c_domain_alt; diff2_domain] THEN |
| 1542 |
DISCH_THEN (MP_TAC o SPEC `x:real^N` o CONJUNCT1) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN |
| 1543 |
MP_TAC (ISPECL [`x:real^N`; `f:real^N->real`] second_partial_uni_compose') THEN |
| 1544 |
ASM_REWRITE_TAC[] THEN |
| 1545 |
DISCH_THEN (MP_TAC o SPEC `acs`) THEN |
| 1546 |
ANTS_TAC THENL |
| 1547 |
[ |
| 1548 |
MATCH_MP_TAC diff2_acs THEN |
| 1549 |
FIRST_X_ASSUM MATCH_MP_TAC THEN ASM_REWRITE_TAC[]; |
| 1550 |
ALL_TAC |
| 1551 |
] THEN |
| 1552 |
|
| 1553 |
new_rewrite [] [`acs _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 1554 |
ASM_SIMP_TAC[second_derivative_acs; derivative_acs; REAL_MUL_LNEG; GSYM real_sub] THEN |
| 1555 |
ASM_SIMP_TAC[GSYM REAL_MUL_LNEG]);; |
| 1556 |
|
| 1557 |
(* asn *) |
| 1558 |
let MK_M_TAYLOR_ASN' = (UNDISCH_ALL o PURE_ONCE_REWRITE_RULE[iabs_lemma] o |
| 1559 |
PURE_REWRITE_RULE[float1_eq; num3_eq] o DISCH_ALL o |
| 1560 |
MY_RULE_FLOAT o prove) |
| 1561 |
(`m_cell_domain domain (y:real^N) w ==> |
| 1562 |
(!x. x IN interval [domain] ==> interval_arith (f x) f_bounds) ==> |
| 1563 |
iabs f_bounds < &1 ==> |
| 1564 |
diff2c_domain domain f ==> |
| 1565 |
interval_arith (asn (f y)) bounds ==> |
| 1566 |
all_n 1 d_bounds_list |
| 1567 |
(\i int. interval_arith (inv (sqrt (&1 - f y * f y)) * partial i f y) int) ==> |
| 1568 |
(!x. x IN interval [domain] ==> all_n 1 dd_bounds_list (\i list_i. all_n 1 list_i |
| 1569 |
(\j int. interval_arith (((f x / sqrt ((&1 - f x * f x) pow 3)) * partial j f x) * partial i f x + |
| 1570 |
inv (sqrt (&1 - f x * f x)) * partial2 j i f x) int))) ==> |
| 1571 |
m_taylor_interval (\x. asn (f x)) domain y w bounds d_bounds_list dd_bounds_list`, |
| 1572 |
REWRITE_TAC[m_taylor_interval; m_lin_approx; second_bounded; ETA_AX] THEN |
| 1573 |
REPEAT DISCH_TAC THEN |
| 1574 |
SUBGOAL_THEN `lift o f differentiable at (y:real^N)` ASSUME_TAC THENL |
| 1575 |
[ |
| 1576 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 1577 |
REWRITE_TAC[diff2c_domain_alt; diff2_domain] THEN STRIP_TAC THEN |
| 1578 |
new_rewrite [] [] diff2_imp_diff THEN REWRITE_TAC[] THEN |
| 1579 |
FIRST_X_ASSUM MATCH_MP_TAC THEN |
| 1580 |
MATCH_MP_TAC y_in_domain THEN EXISTS_TAC `w:real^N` THEN ASM_REWRITE_TAC[]; |
| 1581 |
ALL_TAC |
| 1582 |
] THEN |
| 1583 |
|
| 1584 |
SUBGOAL_THEN `!x:real^N. x IN interval [domain] ==> abs (f x) < &1` ASSUME_TAC THENL |
| 1585 |
[ |
| 1586 |
GEN_TAC THEN DISCH_TAC THEN |
| 1587 |
apply_tac interval_arith_abs THEN |
| 1588 |
EXISTS_TAC `f_bounds:real#real` THEN |
| 1589 |
ASM_REWRITE_TAC[] THEN |
| 1590 |
FIRST_X_ASSUM MATCH_MP_TAC THEN ASM_REWRITE_TAC[]; |
| 1591 |
ALL_TAC |
| 1592 |
] THEN |
| 1593 |
|
| 1594 |
SUBGOAL_THEN `abs (f (y:real^N)) < &1` ASSUME_TAC THENL |
| 1595 |
[ |
| 1596 |
FIRST_X_ASSUM MATCH_MP_TAC THEN |
| 1597 |
MATCH_MP_TAC y_in_domain THEN EXISTS_TAC `w:real^N` THEN |
| 1598 |
ASM_REWRITE_TAC[]; |
| 1599 |
ALL_TAC |
| 1600 |
] THEN |
| 1601 |
|
| 1602 |
REPEAT STRIP_TAC THEN ASM_REWRITE_TAC[] THENL |
| 1603 |
[ |
| 1604 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 1605 |
REWRITE_TAC[diff2c_domain] THEN REPEAT STRIP_TAC THEN |
| 1606 |
ONCE_REWRITE_TAC[GSYM o_THM] THEN REWRITE_TAC[ETA_AX] THEN |
| 1607 |
apply_tac diff2c_asn_compose THEN CONJ_TAC THEN FIRST_X_ASSUM MATCH_MP_TAC THEN ASM_REWRITE_TAC[]; |
| 1608 |
new_rewrite [] [`asn _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 1609 |
apply_tac diff_uni_compose THEN ASM_REWRITE_TAC[] THEN |
| 1610 |
MATCH_MP_TAC REAL_DIFFERENTIABLE_AT_ASN THEN ASM_REWRITE_TAC[]; |
| 1611 |
new_rewrite [] [`asn _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 1612 |
MP_TAC (ISPECL [`y:real^N`; `f:real^N->real`] partial_uni_compose') THEN |
| 1613 |
ASM_REWRITE_TAC[] THEN |
| 1614 |
DISCH_THEN (MP_TAC o SPEC `asn`) THEN |
| 1615 |
ANTS_TAC THENL |
| 1616 |
[ |
| 1617 |
MATCH_MP_TAC REAL_DIFFERENTIABLE_AT_ASN THEN ASM_REWRITE_TAC[]; |
| 1618 |
ALL_TAC |
| 1619 |
] THEN |
| 1620 |
ASM_SIMP_TAC[derivative_asn]; |
| 1621 |
ALL_TAC |
| 1622 |
] THEN |
| 1623 |
|
| 1624 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 1625 |
REWRITE_TAC[diff2c_domain_alt; diff2_domain] THEN |
| 1626 |
DISCH_THEN (MP_TAC o SPEC `x:real^N` o CONJUNCT1) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN |
| 1627 |
MP_TAC (ISPECL [`x:real^N`; `f:real^N->real`] second_partial_uni_compose') THEN |
| 1628 |
ASM_REWRITE_TAC[] THEN |
| 1629 |
DISCH_THEN (MP_TAC o SPEC `asn`) THEN |
| 1630 |
ANTS_TAC THENL |
| 1631 |
[ |
| 1632 |
MATCH_MP_TAC diff2_asn THEN |
| 1633 |
FIRST_X_ASSUM MATCH_MP_TAC THEN ASM_REWRITE_TAC[]; |
| 1634 |
ALL_TAC |
| 1635 |
] THEN |
| 1636 |
|
| 1637 |
new_rewrite [] [`asn _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 1638 |
ASM_SIMP_TAC[second_derivative_asn; derivative_asn]);; |
| 1639 |
|
| 1640 |
|
| 1641 |
(* matan *) |
| 1642 |
|
| 1643 |
let float_neg1_eq = FLOAT_TO_NUM_CONV (mk_float (-1) 0);; |
| 1644 |
|
| 1645 |
let MK_M_TAYLOR_MATAN' = (UNDISCH_ALL o |
| 1646 |
PURE_REWRITE_RULE[float1_eq; SYM float_neg1_eq] o DISCH_ALL o |
| 1647 |
MY_RULE_FLOAT o prove) |
| 1648 |
(`m_cell_domain domain (y:real^N) w ==> |
| 1649 |
(!x. x IN interval [domain] ==> interval_arith (f x) f_bounds) ==> |
| 1650 |
interval_gt (-- &1) f_bounds ==> |
| 1651 |
diff2c_domain domain f ==> |
| 1652 |
interval_arith (matan (f y)) bounds ==> |
| 1653 |
all_n 1 d_bounds_list |
| 1654 |
(\i int. interval_arith (dmatan (f y) * partial i f y) int) ==> |
| 1655 |
(!x. x IN interval [domain] ==> all_n 1 dd_bounds_list (\i list_i. all_n 1 list_i |
| 1656 |
(\j int. interval_arith ((ddmatan (f x) * partial j f x) * partial i f x + |
| 1657 |
dmatan (f x) * partial2 j i f x) int))) ==> |
| 1658 |
m_taylor_interval (\x. matan (f x)) domain y w bounds d_bounds_list dd_bounds_list`, |
| 1659 |
REWRITE_TAC[m_taylor_interval; m_lin_approx; second_bounded; ETA_AX] THEN |
| 1660 |
REPEAT DISCH_TAC THEN |
| 1661 |
SUBGOAL_THEN `lift o f differentiable at (y:real^N)` ASSUME_TAC THENL [ |
| 1662 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 1663 |
REWRITE_TAC[diff2c_domain_alt; diff2_domain] THEN STRIP_TAC THEN |
| 1664 |
new_rewrite [] [] diff2_imp_diff THEN REWRITE_TAC[] THEN |
| 1665 |
FIRST_X_ASSUM MATCH_MP_TAC THEN |
| 1666 |
MATCH_MP_TAC y_in_domain THEN EXISTS_TAC `w:real^N` THEN ASM_REWRITE_TAC[]; |
| 1667 |
ALL_TAC |
| 1668 |
] THEN |
| 1669 |
|
| 1670 |
SUBGOAL_THEN `!x:real^N. x IN interval [domain] ==> -- &1 < f x` ASSUME_TAC THENL [ |
| 1671 |
GEN_TAC THEN DISCH_TAC THEN |
| 1672 |
apply_tac interval_arith_gt THEN |
| 1673 |
EXISTS_TAC `f_bounds:real#real` THEN |
| 1674 |
ASM_REWRITE_TAC[] THEN |
| 1675 |
FIRST_X_ASSUM MATCH_MP_TAC THEN ASM_REWRITE_TAC[]; |
| 1676 |
ALL_TAC |
| 1677 |
] THEN |
| 1678 |
|
| 1679 |
SUBGOAL_THEN `-- &1 < f (y:real^N)` ASSUME_TAC THENL [ |
| 1680 |
FIRST_X_ASSUM MATCH_MP_TAC THEN |
| 1681 |
MATCH_MP_TAC y_in_domain THEN EXISTS_TAC `w:real^N` THEN |
| 1682 |
ASM_REWRITE_TAC[]; |
| 1683 |
ALL_TAC |
| 1684 |
] THEN |
| 1685 |
|
| 1686 |
REPEAT STRIP_TAC THEN ASM_REWRITE_TAC[] THENL [ |
| 1687 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 1688 |
REWRITE_TAC[diff2c_domain] THEN REPEAT STRIP_TAC THEN |
| 1689 |
ONCE_REWRITE_TAC[GSYM o_THM] THEN REWRITE_TAC[ETA_AX] THEN |
| 1690 |
apply_tac diff2c_matan_compose THEN CONJ_TAC THEN FIRST_X_ASSUM MATCH_MP_TAC THEN ASM_REWRITE_TAC[]; |
| 1691 |
new_rewrite [] [`matan _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 1692 |
apply_tac diff_uni_compose THEN ASM_REWRITE_TAC[] THEN |
| 1693 |
MATCH_MP_TAC matan_differentiable THEN ASM_REWRITE_TAC[]; |
| 1694 |
new_rewrite [] [`matan _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 1695 |
MP_TAC (ISPECL [`y:real^N`; `f:real^N->real`] partial_uni_compose') THEN |
| 1696 |
ASM_REWRITE_TAC[] THEN |
| 1697 |
DISCH_THEN (MP_TAC o SPEC `matan`) THEN |
| 1698 |
ANTS_TAC THENL [ |
| 1699 |
MATCH_MP_TAC matan_differentiable THEN ASM_REWRITE_TAC[]; |
| 1700 |
ALL_TAC |
| 1701 |
] THEN |
| 1702 |
ASM_SIMP_TAC[derivative_matan]; |
| 1703 |
ALL_TAC |
| 1704 |
] THEN |
| 1705 |
|
| 1706 |
UNDISCH_TAC `diff2c_domain domain (f:real^N->real)` THEN |
| 1707 |
REWRITE_TAC[diff2c_domain_alt; diff2_domain] THEN |
| 1708 |
DISCH_THEN (MP_TAC o SPEC `x:real^N` o CONJUNCT1) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN |
| 1709 |
MP_TAC (ISPECL [`x:real^N`; `f:real^N->real`] second_partial_uni_compose') THEN |
| 1710 |
ASM_REWRITE_TAC[] THEN |
| 1711 |
DISCH_THEN (MP_TAC o SPEC `matan`) THEN |
| 1712 |
ANTS_TAC THENL [ |
| 1713 |
MATCH_MP_TAC diff2_matan THEN |
| 1714 |
FIRST_X_ASSUM MATCH_MP_TAC THEN ASM_REWRITE_TAC[]; |
| 1715 |
ALL_TAC |
| 1716 |
] THEN |
| 1717 |
|
| 1718 |
new_rewrite [] [`matan _`] (GSYM o_THM) THEN REWRITE_TAC[ETA_AX] THEN |
| 1719 |
ASM_SIMP_TAC[second_derivative_matan; derivative_matan]);; |
| 1720 |
|
| 1721 |
|
| 1722 |
(* ----------------------- *) |
| 1723 |
(* eval_m_taylor_pow2 *) |
| 1724 |
(* ----------------------- *) |
| 1725 |
|
| 1726 |
let pow2_partial_lemma' = |
| 1727 |
prove(`interval_arith ((&2 * f y) * partial i f (y:real^N)) int <=> |
| 1728 |
(\i int. interval_arith ((&2 * f y) * partial i f y) int) i int`, |
| 1729 |
REWRITE_TAC[]);; |
| 1730 |
|
| 1731 |
|
| 1732 |
let pow2_second_lemma' = |
| 1733 |
prove(`interval_arith (&2 * (partial j f (x:real^N) * partial i f x + |
| 1734 |
f x * partial2 j i f x)) int <=> |
| 1735 |
(\j int. interval_arith (&2 * (partial j f x * partial i f x + |
| 1736 |
f x * partial2 j i f x)) int) j int`, |
| 1737 |
REWRITE_TAC[]);; |
| 1738 |
|
| 1739 |
|
| 1740 |
let pow2_second_lemma'' = (PURE_REWRITE_RULE[all_n1_raw] o prove) |
| 1741 |
(`all_n 1 list |
| 1742 |
(\j int. interval_arith (&2 * (partial j f (x:real^N) * partial i f x + |
| 1743 |
f x * partial2 j i f x)) int) <=> |
| 1744 |
(\i list. all_n 1 list |
| 1745 |
(\j int. interval_arith (&2 * (partial j f x * partial i f x + |
| 1746 |
f x * partial2 j i f x)) int)) i list`, |
| 1747 |
REWRITE_TAC[]);; |
| 1748 |
|
| 1749 |
let eval_m_taylor_pow2 n p_lin p_second taylor1_th = |
| 1750 |
let domain_th, diff2_f1_th, lin1_th, second1_th = dest_m_taylor_thms n taylor1_th in |
| 1751 |
let f1_tm = (rand o concl) diff2_f1_th in |
| 1752 |
let domain_tm, y_tm, w_tm = dest_m_cell_domain (concl domain_th) in |
| 1753 |
let ty = type_of y_tm in |
| 1754 |
|
| 1755 |
let x_var = mk_var ("x", ty) and |
| 1756 |
y_var = mk_var ("y", ty) and |
| 1757 |
w_var = mk_var ("w", ty) and |
| 1758 |
f_var = mk_var ("f", type_of f1_tm) and |
| 1759 |
domain_var = mk_var ("domain", type_of domain_tm) in |
| 1760 |
|
| 1761 |
let undisch = UNDISCH o SPEC x_var in |
| 1762 |
|
| 1763 |
let f1_bound0 = eval_m_taylor_bound n p_second taylor1_th in |
| 1764 |
let f1_bound = undisch f1_bound0 in |
| 1765 |
|
| 1766 |
let _, bounds1_th, df1_th = m_lin_approx_components n lin1_th in |
| 1767 |
|
| 1768 |
let bounds_th = float_interval_pow p_lin 2 bounds1_th in |
| 1769 |
let bounds_tm = (rand o concl) bounds_th in |
| 1770 |
|
| 1771 |
(* partial_lemma' *) |
| 1772 |
let u_lemma0 = (INST[f1_tm, f_var; y_tm, y_var] o |
| 1773 |
INST_TYPE[n_type_array.(n), nty]) pow2_partial_lemma' in |
| 1774 |
|
| 1775 |
let u_bounds = |
| 1776 |
let ( * ) = float_interval_mul p_lin in |
| 1777 |
two_interval * bounds1_th in |
| 1778 |
|
| 1779 |
let u_lin th1 = |
| 1780 |
(* partial *) |
| 1781 |
let u_th = |
| 1782 |
let ( * ) = float_interval_mul p_lin in |
| 1783 |
u_bounds * th1 in |
| 1784 |
let int_tm = rand (concl u_th) in |
| 1785 |
let i_tm = (rand o rator o rator o lhand) (concl th1) in |
| 1786 |
let th0 = INST[i_tm, i_var_num; int_tm, int_var] u_lemma0 in |
| 1787 |
EQ_MP th0 u_th in |
| 1788 |
|
| 1789 |
let df_th = eval_all_n df1_th true u_lin in |
| 1790 |
let d_bounds_list = (rand o rator o concl) df_th in |
| 1791 |
|
| 1792 |
let dd1 = second_bounded_components n second1_th in |
| 1793 |
|
| 1794 |
(* second_lemma', second_lemma'' *) |
| 1795 |
let u_second_lemma0 = (INST[f1_tm, f_var] o |
| 1796 |
INST_TYPE[n_type_array.(n), nty]) pow2_second_lemma' in |
| 1797 |
|
| 1798 |
let u_second_lemma1 = (INST[f1_tm, f_var] o |
| 1799 |
INST_TYPE[n_type_array.(n), nty]) pow2_second_lemma'' in |
| 1800 |
|
| 1801 |
let d1_bounds = map (fun i -> |
| 1802 |
let th0 = eval_m_taylor_partial_bound n p_second i taylor1_th in |
| 1803 |
undisch th0) (1--n) in |
| 1804 |
|
| 1805 |
let u_second2 th1 = |
| 1806 |
let i_tm = (rand o rator o concl) th1 in |
| 1807 |
let i_int = (Num.int_of_num o raw_dest_hash) i_tm in |
| 1808 |
let di1 = List.nth d1_bounds (i_int - 1) in |
| 1809 |
let th1 = MY_BETA_RULE th1 in |
| 1810 |
let lemma = INST[i_tm, i_var_num] u_second_lemma0 in |
| 1811 |
let u_second th1 = |
| 1812 |
let j_tm = (rand o rator o rator o rator o lhand) (concl th1) in |
| 1813 |
let j_int = (Num.int_of_num o raw_dest_hash) j_tm in |
| 1814 |
let dj1 = List.nth d1_bounds (j_int - 1) in |
| 1815 |
|
| 1816 |
(* partial2 *) |
| 1817 |
let u_th = |
| 1818 |
let ( * ), ( + ) = float_interval_mul p_second, float_interval_add p_second in |
| 1819 |
two_interval * (dj1 * di1 + f1_bound * th1) in |
| 1820 |
|
| 1821 |
let int_tm = rand (concl u_th) in |
| 1822 |
let th0 = INST[j_tm, j_var_num; int_tm, int_var] lemma in |
| 1823 |
EQ_MP th0 u_th in |
| 1824 |
|
| 1825 |
let u_th = eval_all_n th1 true u_second in |
| 1826 |
let list_tm = (rand o rator o concl) u_th in |
| 1827 |
let lemma1 = INST[i_tm, i_var_num; list_tm, list_var_real_pair] u_second_lemma1 in |
| 1828 |
EQ_MP lemma1 u_th in |
| 1829 |
|
| 1830 |
let dd_th0 = eval_all_n dd1 false u_second2 in |
| 1831 |
let dd_list = (rand o rator o concl) dd_th0 in |
| 1832 |
let dd_th = GEN x_var (DISCH_ALL dd_th0) in |
| 1833 |
|
| 1834 |
let th = (MY_PROVE_HYP dd_th o MY_PROVE_HYP diff2_f1_th o |
| 1835 |
MY_PROVE_HYP bounds_th o MY_PROVE_HYP df_th o MY_PROVE_HYP domain_th o |
| 1836 |
INST[f1_tm, f_var; |
| 1837 |
domain_tm, domain_var; y_tm, y_var; w_tm, w_var; |
| 1838 |
bounds_tm, bounds_var; d_bounds_list, d_bounds_list_var; |
| 1839 |
dd_list, dd_bounds_list_var] o |
| 1840 |
INST_TYPE[n_type_array.(n), nty]) MK_M_TAYLOR_POW2' in |
| 1841 |
let k_tm = rand (rand (rator (concl bounds_th))) in |
| 1842 |
let eq_th = pow_beta_gen_eq f1_tm x_var k_tm in |
| 1843 |
m_taylor_interval_norm th eq_th;; |
| 1844 |
|
| 1845 |
(* ----------------------- *) |
| 1846 |
(* eval_m_taylor_pow *) |
| 1847 |
(* ----------------------- *) |
| 1848 |
|
| 1849 |
let pow_partial_lemma' = |
| 1850 |
prove(`interval_arith ((&k * f y pow (k - 1)) * partial i f (y:real^N)) int <=> |
| 1851 |
(\i int. interval_arith ((&k * f y pow (k - 1)) * partial i f y) int) i int`, |
| 1852 |
REWRITE_TAC[]);; |
| 1853 |
|
| 1854 |
|
| 1855 |
let pow_second_lemma' = |
| 1856 |
prove(`interval_arith ((&k * f x pow (k - 2)) * ((&(k - 1) * partial j f (x:real^N)) |
| 1857 |
* partial i f x + f x * partial2 j i f x)) int <=> |
| 1858 |
(\j int. interval_arith ((&k * f x pow (k - 2)) * ((&(k - 1) * partial j f (x:real^N)) |
| 1859 |
* partial i f x + f x * partial2 j i f x)) int) j int`, |
| 1860 |
REWRITE_TAC[]);; |
| 1861 |
|
| 1862 |
|
| 1863 |
let pow_second_lemma'' = (PURE_REWRITE_RULE[all_n1_raw] o prove) |
| 1864 |
(`all_n 1 list |
| 1865 |
(\j int. interval_arith ((&k * f x pow (k - 2)) * ((&(k - 1) * partial j f (x:real^N)) |
| 1866 |
* partial i f x + f x * partial2 j i f x)) int) <=> |
| 1867 |
(\i list. all_n 1 list |
| 1868 |
(\j int. interval_arith ((&k * f x pow (k - 2)) * ((&(k - 1) * partial j f (x:real^N)) |
| 1869 |
* partial i f x + f x * partial2 j i f x)) int)) i list`, |
| 1870 |
REWRITE_TAC[]);; |
| 1871 |
|
| 1872 |
let eval_m_taylor_pow k = |
| 1873 |
if k <= 1 then failwith "eval_m_taylor_pow: k <= 1 (simplify low powers!)" |
| 1874 |
else if k = 2 then eval_m_taylor_pow2 |
| 1875 |
else |
| 1876 |
let k_tm = mk_small_numeral k in |
| 1877 |
let k_interval = mk_float_interval_small_num k in |
| 1878 |
let k1_interval = mk_float_interval_small_num (k - 1) in |
| 1879 |
let k1_eq = NUM_SUB_CONV (mk_binary "-" (k_tm, mk_small_numeral 1)) in |
| 1880 |
let k2_eq = NUM_SUB_CONV (mk_binary "-" (k_tm, mk_small_numeral 2)) in |
| 1881 |
let k_ge2 = NUM_GE_CONV (mk_binary ">=" (k_tm, mk_small_numeral 2)) in |
| 1882 |
let RULE = PURE_REWRITE_RULE[k1_eq; k2_eq; k_ge2] o INST[k_tm, k_var_num] in |
| 1883 |
let MK_POW = (PROVE_HYP TRUTH o UNDISCH_ALL o RULE o DISCH_ALL) MK_M_TAYLOR_POW' in |
| 1884 |
let pow_partial_lemma' = RULE pow_partial_lemma' and |
| 1885 |
pow_second_lemma' = RULE pow_second_lemma' and |
| 1886 |
pow_second_lemma'' = RULE pow_second_lemma'' in |
| 1887 |
fun n p_lin p_second taylor1_th -> |
| 1888 |
let domain_th, diff2_f1_th, lin1_th, second1_th = dest_m_taylor_thms n taylor1_th in |
| 1889 |
let f1_tm = (rand o concl) diff2_f1_th in |
| 1890 |
let domain_tm, y_tm, w_tm = dest_m_cell_domain (concl domain_th) in |
| 1891 |
let ty = type_of y_tm in |
| 1892 |
|
| 1893 |
let x_var = mk_var ("x", ty) and |
| 1894 |
y_var = mk_var ("y", ty) and |
| 1895 |
w_var = mk_var ("w", ty) and |
| 1896 |
f_var = mk_var ("f", type_of f1_tm) and |
| 1897 |
domain_var = mk_var ("domain", type_of domain_tm) in |
| 1898 |
|
| 1899 |
let undisch = UNDISCH o SPEC x_var in |
| 1900 |
|
| 1901 |
let f1_bound0 = eval_m_taylor_bound n p_second taylor1_th in |
| 1902 |
let f1_bound = undisch f1_bound0 in |
| 1903 |
|
| 1904 |
let _, bounds1_th, df1_th = m_lin_approx_components n lin1_th in |
| 1905 |
|
| 1906 |
let bounds_pow_k1 = float_interval_pow p_lin (k - 1) bounds1_th in |
| 1907 |
let bounds_th = |
| 1908 |
let ( * ) = float_interval_mul p_lin in |
| 1909 |
bounds1_th * bounds_pow_k1 in |
| 1910 |
let bounds_tm = (rand o concl) bounds_th in |
| 1911 |
|
| 1912 |
(* partial_lemma' *) |
| 1913 |
let u_lemma0 = (INST[f1_tm, f_var; y_tm, y_var] o |
| 1914 |
INST_TYPE[n_type_array.(n), nty]) pow_partial_lemma' in |
| 1915 |
|
| 1916 |
let u_bounds = |
| 1917 |
let ( * ) = float_interval_mul p_lin in |
| 1918 |
k_interval * bounds_pow_k1 in |
| 1919 |
|
| 1920 |
let u_lin th1 = |
| 1921 |
(* partial *) |
| 1922 |
let u_th = |
| 1923 |
let ( * ) = float_interval_mul p_lin in |
| 1924 |
u_bounds * th1 in |
| 1925 |
let int_tm = rand (concl u_th) in |
| 1926 |
let i_tm = (rand o rator o rator o lhand) (concl th1) in |
| 1927 |
let th0 = INST[i_tm, i_var_num; int_tm, int_var] u_lemma0 in |
| 1928 |
EQ_MP th0 u_th in |
| 1929 |
|
| 1930 |
let df_th = eval_all_n df1_th true u_lin in |
| 1931 |
let d_bounds_list = (rand o rator o concl) df_th in |
| 1932 |
|
| 1933 |
let dd1 = second_bounded_components n second1_th in |
| 1934 |
|
| 1935 |
(* second_lemma', second_lemma'' *) |
| 1936 |
let u_second_lemma0 = (INST[f1_tm, f_var] o |
| 1937 |
INST_TYPE[n_type_array.(n), nty]) pow_second_lemma' in |
| 1938 |
|
| 1939 |
let u_second_lemma1 = (INST[f1_tm, f_var] o |
| 1940 |
INST_TYPE[n_type_array.(n), nty]) pow_second_lemma'' in |
| 1941 |
|
| 1942 |
let d1_bounds = map (fun i -> |
| 1943 |
let th0 = eval_m_taylor_partial_bound n p_second i taylor1_th in |
| 1944 |
undisch th0) (1--n) in |
| 1945 |
|
| 1946 |
(* u'(f x), u''(f x) *) |
| 1947 |
let d2_th0 = |
| 1948 |
let ( * ) = float_interval_mul p_second in |
| 1949 |
let pow_k2 = float_interval_pow p_second (k - 2) in |
| 1950 |
k_interval * pow_k2 f1_bound in |
| 1951 |
|
| 1952 |
let u_second2 th1 = |
| 1953 |
let i_tm = (rand o rator o concl) th1 in |
| 1954 |
let i_int = (Num.int_of_num o raw_dest_hash) i_tm in |
| 1955 |
let di1 = List.nth d1_bounds (i_int - 1) in |
| 1956 |
let th1 = MY_BETA_RULE th1 in |
| 1957 |
let lemma = INST[i_tm, i_var_num] u_second_lemma0 in |
| 1958 |
let u_second th1 = |
| 1959 |
let j_tm = (rand o rator o rator o rator o lhand) (concl th1) in |
| 1960 |
let j_int = (Num.int_of_num o raw_dest_hash) j_tm in |
| 1961 |
let dj1 = List.nth d1_bounds (j_int - 1) in |
| 1962 |
|
| 1963 |
(* partial2 *) |
| 1964 |
let u_th = |
| 1965 |
let ( * ), ( + ) = float_interval_mul p_second, float_interval_add p_second in |
| 1966 |
d2_th0 * ((k1_interval * dj1) * di1 + f1_bound * th1) in |
| 1967 |
|
| 1968 |
let int_tm = rand (concl u_th) in |
| 1969 |
let th0 = INST[j_tm, j_var_num; int_tm, int_var] lemma in |
| 1970 |
EQ_MP th0 u_th in |
| 1971 |
|
| 1972 |
let u_th = eval_all_n th1 true u_second in |
| 1973 |
let list_tm = (rand o rator o concl) u_th in |
| 1974 |
let lemma1 = INST[i_tm, i_var_num; list_tm, list_var_real_pair] u_second_lemma1 in |
| 1975 |
EQ_MP lemma1 u_th in |
| 1976 |
|
| 1977 |
let dd_th0 = eval_all_n dd1 false u_second2 in |
| 1978 |
let dd_list = (rand o rator o concl) dd_th0 in |
| 1979 |
let dd_th = GEN x_var (DISCH_ALL dd_th0) in |
| 1980 |
|
| 1981 |
let th = (MY_PROVE_HYP dd_th o MY_PROVE_HYP diff2_f1_th o |
| 1982 |
MY_PROVE_HYP bounds_th o MY_PROVE_HYP df_th o MY_PROVE_HYP domain_th o |
| 1983 |
INST[f1_tm, f_var; |
| 1984 |
domain_tm, domain_var; y_tm, y_var; w_tm, w_var; |
| 1985 |
bounds_tm, bounds_var; d_bounds_list, d_bounds_list_var; |
| 1986 |
dd_list, dd_bounds_list_var] o |
| 1987 |
INST_TYPE[n_type_array.(n), nty]) MK_POW in |
| 1988 |
let eq_th = pow_beta_gen_eq f1_tm x_var k_tm in |
| 1989 |
m_taylor_interval_norm th eq_th;; |
| 1990 |
|
| 1991 |
|
| 1992 |
(* ----------------------- *) |
| 1993 |
(* eval_m_taylor_inv *) |
| 1994 |
(* ----------------------- *) |
| 1995 |
|
| 1996 |
let inv_partial_lemma' = |
| 1997 |
prove(`interval_arith (--inv (f y * f y) * partial i f (y:real^N)) int <=> |
| 1998 |
(\i int. interval_arith (--inv (f y * f y) * partial i f y) int) i int`, |
| 1999 |
REWRITE_TAC[]);; |
| 2000 |
|
| 2001 |
let inv_second_lemma' = |
| 2002 |
prove(`interval_arith (((&2 * inv (f x * f x * f x)) * partial j f x) * partial i f (x:real^N) - |
| 2003 |
inv (f x * f x) * partial2 j i f x) int <=> |
| 2004 |
(\j int. interval_arith (((&2 * inv (f x * f x * f x)) * partial j f x) * partial i f x - |
| 2005 |
inv (f x * f x) * partial2 j i f x) int) j int`, |
| 2006 |
REWRITE_TAC[]);; |
| 2007 |
|
| 2008 |
|
| 2009 |
let inv_second_lemma'' = (PURE_REWRITE_RULE[GSYM num1_eq] o prove) |
| 2010 |
(`all_n 1 list |
| 2011 |
(\j int. interval_arith (((&2 * inv (f x * f x * f x)) * partial j f x) * partial i f (x:real^N) - |
| 2012 |
inv (f x * f x) * partial2 j i f x) int) <=> |
| 2013 |
(\i list. all_n 1 list |
| 2014 |
(\j int. interval_arith (((&2 * inv (f x * f x * f x)) * partial j f x) * partial i f x - |
| 2015 |
inv (f x * f x) * partial2 j i f x) int)) i list`, |
| 2016 |
REWRITE_TAC[]);; |
| 2017 |
|
| 2018 |
|
| 2019 |
|
| 2020 |
|
| 2021 |
let eval_m_taylor_inv n p_lin p_second taylor1_th = |
| 2022 |
let domain_th, diff2_f1_th, lin1_th, second1_th = dest_m_taylor_thms n taylor1_th in |
| 2023 |
let f1_tm = (rand o concl) diff2_f1_th in |
| 2024 |
let domain_tm, y_tm, w_tm = dest_m_cell_domain (concl domain_th) in |
| 2025 |
let ty = type_of y_tm in |
| 2026 |
|
| 2027 |
let x_var = mk_var ("x", ty) and |
| 2028 |
y_var = mk_var ("y", ty) and |
| 2029 |
w_var = mk_var ("w", ty) and |
| 2030 |
f_var = mk_var ("f", type_of f1_tm) and |
| 2031 |
domain_var = mk_var ("domain", type_of domain_tm) in |
| 2032 |
|
| 2033 |
let undisch = UNDISCH o SPEC x_var in |
| 2034 |
|
| 2035 |
let f1_bound0 = eval_m_taylor_bound n p_second taylor1_th in |
| 2036 |
let f1_bound = undisch f1_bound0 in |
| 2037 |
let f_bounds_tm = (rand o concl) f1_bound in |
| 2038 |
|
| 2039 |
(* cond *) |
| 2040 |
let cond_th = check_interval_not_zero f_bounds_tm in |
| 2041 |
|
| 2042 |
let _, bounds1_th, df1_th = m_lin_approx_components n lin1_th in |
| 2043 |
|
| 2044 |
let bounds_th = float_interval_inv p_lin bounds1_th in |
| 2045 |
let bounds_tm = (rand o concl) bounds_th in |
| 2046 |
|
| 2047 |
(* partial_lemma' *) |
| 2048 |
let u_lemma0 = (INST[f1_tm, f_var; y_tm, y_var] o |
| 2049 |
INST_TYPE[n_type_array.(n), nty]) inv_partial_lemma' in |
| 2050 |
|
| 2051 |
let u_bounds = |
| 2052 |
let neg, inv, ( * ) = float_interval_neg, float_interval_inv p_lin, float_interval_mul p_lin in |
| 2053 |
neg (inv (bounds1_th * bounds1_th)) in |
| 2054 |
|
| 2055 |
|
| 2056 |
let u_lin th1 = |
| 2057 |
(* partial *) |
| 2058 |
let u_th = |
| 2059 |
let ( * ) = float_interval_mul p_lin in |
| 2060 |
u_bounds * th1 in |
| 2061 |
let int_tm = rand (concl u_th) in |
| 2062 |
let i_tm = (rand o rator o rator o lhand) (concl th1) in |
| 2063 |
let th0 = INST[i_tm, i_var_num; int_tm, int_var] u_lemma0 in |
| 2064 |
EQ_MP th0 u_th in |
| 2065 |
|
| 2066 |
let df_th = eval_all_n df1_th true u_lin in |
| 2067 |
let d_bounds_list = (rand o rator o concl) df_th in |
| 2068 |
|
| 2069 |
|
| 2070 |
let dd1 = second_bounded_components n second1_th in |
| 2071 |
|
| 2072 |
(* second_lemma', second_lemma'' *) |
| 2073 |
let u_second_lemma0 = (INST[f1_tm, f_var] o |
| 2074 |
INST_TYPE[n_type_array.(n), nty]) inv_second_lemma' in |
| 2075 |
|
| 2076 |
let u_second_lemma1 = (INST[f1_tm, f_var] o |
| 2077 |
INST_TYPE[n_type_array.(n), nty]) inv_second_lemma'' in |
| 2078 |
|
| 2079 |
|
| 2080 |
let d1_bounds = map (fun i -> |
| 2081 |
let th0 = eval_m_taylor_partial_bound n p_second i taylor1_th in |
| 2082 |
undisch th0) (1--n) in |
| 2083 |
|
| 2084 |
(* u'(f x), u''(f x) *) |
| 2085 |
let d1_th0, d2_th0 = |
| 2086 |
let inv, ( * ) = float_interval_inv p_second, float_interval_mul p_second in |
| 2087 |
let ff = f1_bound * f1_bound in |
| 2088 |
inv ff, |
| 2089 |
two_interval * inv (f1_bound * ff) in |
| 2090 |
|
| 2091 |
|
| 2092 |
let u_second2 th1 = |
| 2093 |
let i_tm = (rand o rator o concl) th1 in |
| 2094 |
let i_int = (Num.int_of_num o raw_dest_hash) i_tm in |
| 2095 |
let di1 = List.nth d1_bounds (i_int - 1) in |
| 2096 |
let th1 = MY_BETA_RULE th1 in |
| 2097 |
let lemma = INST[i_tm, i_var_num] u_second_lemma0 in |
| 2098 |
let u_second th1 = |
| 2099 |
let j_tm = (rand o rator o rator o rator o lhand) (concl th1) in |
| 2100 |
let j_int = (Num.int_of_num o raw_dest_hash) j_tm in |
| 2101 |
let dj1 = List.nth d1_bounds (j_int - 1) in |
| 2102 |
|
| 2103 |
(* partial2 *) |
| 2104 |
let u_th = |
| 2105 |
let ( * ), ( - ) = float_interval_mul p_second, float_interval_sub p_second in |
| 2106 |
(d2_th0 * dj1) * di1 - d1_th0 * th1 in |
| 2107 |
|
| 2108 |
let int_tm = rand (concl u_th) in |
| 2109 |
let th0 = INST[j_tm, j_var_num; int_tm, int_var] lemma in |
| 2110 |
EQ_MP th0 u_th in |
| 2111 |
|
| 2112 |
let u_th = eval_all_n th1 true u_second in |
| 2113 |
let list_tm = (rand o rator o concl) u_th in |
| 2114 |
let lemma1 = INST[i_tm, i_var_num; list_tm, list_var_real_pair] u_second_lemma1 in |
| 2115 |
EQ_MP lemma1 u_th in |
| 2116 |
|
| 2117 |
let dd_th0 = eval_all_n dd1 false u_second2 in |
| 2118 |
let dd_list = (rand o rator o concl) dd_th0 in |
| 2119 |
let dd_th = GEN x_var (DISCH_ALL dd_th0) in |
| 2120 |
|
| 2121 |
let th = (MY_PROVE_HYP dd_th o MY_PROVE_HYP diff2_f1_th o |
| 2122 |
MY_PROVE_HYP cond_th o MY_PROVE_HYP f1_bound0 o |
| 2123 |
MY_PROVE_HYP bounds_th o MY_PROVE_HYP df_th o MY_PROVE_HYP domain_th o |
| 2124 |
INST[f1_tm, f_var; f_bounds_tm, f_bounds_var; |
| 2125 |
domain_tm, domain_var; y_tm, y_var; w_tm, w_var; |
| 2126 |
bounds_tm, bounds_var; d_bounds_list, d_bounds_list_var; |
| 2127 |
dd_list, dd_bounds_list_var] o |
| 2128 |
INST_TYPE[n_type_array.(n), nty]) MK_M_TAYLOR_INV' in |
| 2129 |
let eq_th = unary_beta_gen_eq f1_tm x_var inv_op_real in |
| 2130 |
m_taylor_interval_norm th eq_th;; |
| 2131 |
|
| 2132 |
(* ----------------------- *) |
| 2133 |
(* eval_m_taylor_sqrt *) |
| 2134 |
(* ----------------------- *) |
| 2135 |
|
| 2136 |
let sqrt_partial_lemma' = |
| 2137 |
prove(`interval_arith (inv (&2 * sqrt (f y)) * partial i f (y:real^N)) int <=> |
| 2138 |
(\i int. interval_arith (inv (&2 * sqrt (f y)) * partial i f y) int) i int`, |
| 2139 |
REWRITE_TAC[]);; |
| 2140 |
|
| 2141 |
|
| 2142 |
let sqrt_second_lemma' = |
| 2143 |
prove(`interval_arith ((--inv ((&2 * sqrt (f x)) * (&2 * f x)) * partial j f x) * partial i f (x:real^N) + |
| 2144 |
inv (&2 * sqrt (f x)) * partial2 j i f x) int <=> |
| 2145 |
(\j int. interval_arith ((--inv ((&2 * sqrt (f x))*(&2 * f x)) * partial j f x) * partial i f x + |
| 2146 |
inv (&2 * sqrt (f x)) * partial2 j i f x) int) j int`, |
| 2147 |
REWRITE_TAC[]);; |
| 2148 |
|
| 2149 |
|
| 2150 |
let sqrt_second_lemma'' = (PURE_REWRITE_RULE[GSYM num1_eq] o prove) |
| 2151 |
(`all_n 1 list |
| 2152 |
(\j int. interval_arith ((--inv ((&2 * sqrt (f x)) * (&2 * f x)) * partial j f x) * partial i f x + |
| 2153 |
inv (&2 * sqrt (f x)) * partial2 j i f (x:real^N)) int) <=> |
| 2154 |
(\i list. all_n 1 list |
| 2155 |
(\j int. interval_arith ((--inv ((&2 * sqrt (f x)) * (&2 * f x)) * partial j f x) * partial i f x + |
| 2156 |
inv (&2 * sqrt (f x)) * partial2 j i f (x:real^N)) int)) i list`, |
| 2157 |
REWRITE_TAC[]);; |
| 2158 |
|
| 2159 |
|
| 2160 |
let eval_m_taylor_sqrt n p_lin p_second taylor1_th = |
| 2161 |
let domain_th, diff2_f1_th, lin1_th, second1_th = dest_m_taylor_thms n taylor1_th in |
| 2162 |
let f1_tm = (rand o concl) diff2_f1_th in |
| 2163 |
let domain_tm, y_tm, w_tm = dest_m_cell_domain (concl domain_th) in |
| 2164 |
let ty = type_of y_tm in |
| 2165 |
|
| 2166 |
let x_var = mk_var ("x", ty) and |
| 2167 |
y_var = mk_var ("y", ty) and |
| 2168 |
w_var = mk_var ("w", ty) and |
| 2169 |
f_var = mk_var ("f", type_of f1_tm) and |
| 2170 |
domain_var = mk_var ("domain", type_of domain_tm) in |
| 2171 |
|
| 2172 |
let undisch = UNDISCH o SPEC x_var in |
| 2173 |
|
| 2174 |
let f1_bound0 = eval_m_taylor_bound n p_second taylor1_th in |
| 2175 |
let f1_bound = undisch f1_bound0 in |
| 2176 |
let f_bounds_tm = (rand o concl) f1_bound in |
| 2177 |
|
| 2178 |
(* cond *) |
| 2179 |
let cond_th = check_interval_pos f_bounds_tm in |
| 2180 |
|
| 2181 |
let _, bounds1_th, df1_th = m_lin_approx_components n lin1_th in |
| 2182 |
|
| 2183 |
let bounds_th = float_interval_sqrt p_lin bounds1_th in |
| 2184 |
let bounds_tm = (rand o concl) bounds_th in |
| 2185 |
|
| 2186 |
(* partial_lemma' *) |
| 2187 |
let u_lemma0 = (INST[f1_tm, f_var; y_tm, y_var] o |
| 2188 |
INST_TYPE[n_type_array.(n), nty]) sqrt_partial_lemma' in |
| 2189 |
|
| 2190 |
let u_bounds = |
| 2191 |
let inv, ( * ) = float_interval_inv p_lin, float_interval_mul p_lin in |
| 2192 |
inv (two_interval * bounds_th) in |
| 2193 |
|
| 2194 |
let u_lin th1 = |
| 2195 |
(* partial *) |
| 2196 |
let u_th = |
| 2197 |
let ( * ) = float_interval_mul p_lin in |
| 2198 |
u_bounds * th1 in |
| 2199 |
let int_tm = rand (concl u_th) in |
| 2200 |
let i_tm = (rand o rator o rator o lhand) (concl th1) in |
| 2201 |
let th0 = INST[i_tm, i_var_num; int_tm, int_var] u_lemma0 in |
| 2202 |
EQ_MP th0 u_th in |
| 2203 |
|
| 2204 |
let df_th = eval_all_n df1_th true u_lin in |
| 2205 |
let d_bounds_list = (rand o rator o concl) df_th in |
| 2206 |
|
| 2207 |
|
| 2208 |
let dd1 = second_bounded_components n second1_th in |
| 2209 |
|
| 2210 |
(* second_lemma', second_lemma'' *) |
| 2211 |
let u_second_lemma0 = (INST[f1_tm, f_var] o |
| 2212 |
INST_TYPE[n_type_array.(n), nty]) sqrt_second_lemma' in |
| 2213 |
|
| 2214 |
let u_second_lemma1 = (INST[f1_tm, f_var] o |
| 2215 |
INST_TYPE[n_type_array.(n), nty]) sqrt_second_lemma'' in |
| 2216 |
|
| 2217 |
let d1_bounds = map (fun i -> |
| 2218 |
let th0 = eval_m_taylor_partial_bound n p_second i taylor1_th in |
| 2219 |
undisch th0) (1--n) in |
| 2220 |
|
| 2221 |
(* u'(f x), u''(f x) *) |
| 2222 |
let d1_th0, d2_th0 = |
| 2223 |
let neg, sqrt, inv, ( * ) = float_interval_neg, float_interval_sqrt p_second, |
| 2224 |
float_interval_inv p_second, float_interval_mul p_second in |
| 2225 |
let two_sqrt_f = two_interval * sqrt f1_bound in |
| 2226 |
inv two_sqrt_f, |
| 2227 |
neg (inv (two_sqrt_f * (two_interval * f1_bound))) in |
| 2228 |
|
| 2229 |
let u_second2 th1 = |
| 2230 |
let i_tm = (rand o rator o concl) th1 in |
| 2231 |
let i_int = (Num.int_of_num o raw_dest_hash) i_tm in |
| 2232 |
let di1 = List.nth d1_bounds (i_int - 1) in |
| 2233 |
let th1 = MY_BETA_RULE th1 in |
| 2234 |
let lemma = INST[i_tm, i_var_num] u_second_lemma0 in |
| 2235 |
let u_second th1 = |
| 2236 |
let j_tm = (rand o rator o rator o rator o lhand) (concl th1) in |
| 2237 |
let j_int = (Num.int_of_num o raw_dest_hash) j_tm in |
| 2238 |
let dj1 = List.nth d1_bounds (j_int - 1) in |
| 2239 |
|
| 2240 |
(* partial2 *) |
| 2241 |
let u_th = |
| 2242 |
let ( * ), ( + ) = float_interval_mul p_second, float_interval_add p_second in |
| 2243 |
(d2_th0 * dj1) * di1 + d1_th0 * th1 in |
| 2244 |
|
| 2245 |
let int_tm = rand (concl u_th) in |
| 2246 |
let th0 = INST[j_tm, j_var_num; int_tm, int_var] lemma in |
| 2247 |
EQ_MP th0 u_th in |
| 2248 |
|
| 2249 |
let u_th = eval_all_n th1 true u_second in |
| 2250 |
let list_tm = (rand o rator o concl) u_th in |
| 2251 |
let lemma1 = INST[i_tm, i_var_num; list_tm, list_var_real_pair] u_second_lemma1 in |
| 2252 |
EQ_MP lemma1 u_th in |
| 2253 |
|
| 2254 |
let dd_th0 = eval_all_n dd1 false u_second2 in |
| 2255 |
let dd_list = (rand o rator o concl) dd_th0 in |
| 2256 |
let dd_th = GEN x_var (DISCH_ALL dd_th0) in |
| 2257 |
|
| 2258 |
let th = (MY_PROVE_HYP dd_th o MY_PROVE_HYP diff2_f1_th o |
| 2259 |
MY_PROVE_HYP cond_th o MY_PROVE_HYP f1_bound0 o |
| 2260 |
MY_PROVE_HYP bounds_th o MY_PROVE_HYP df_th o MY_PROVE_HYP domain_th o |
| 2261 |
INST[f1_tm, f_var; f_bounds_tm, f_bounds_var; |
| 2262 |
domain_tm, domain_var; y_tm, y_var; w_tm, w_var; |
| 2263 |
bounds_tm, bounds_var; d_bounds_list, d_bounds_list_var; |
| 2264 |
dd_list, dd_bounds_list_var] o |
| 2265 |
INST_TYPE[n_type_array.(n), nty]) MK_M_TAYLOR_SQRT' in |
| 2266 |
let eq_th = unary_beta_gen_eq f1_tm x_var sqrt_tm in |
| 2267 |
m_taylor_interval_norm th eq_th;; |
| 2268 |
|
| 2269 |
|
| 2270 |
(* ----------------------- *) |
| 2271 |
(* eval_m_taylor_exp *) |
| 2272 |
(* ----------------------- *) |
| 2273 |
|
| 2274 |
let exp_partial_lemma' = |
| 2275 |
prove(`interval_arith (exp (f y) * partial i f (y:real^N)) int <=> |
| 2276 |
(\i int. interval_arith (exp (f y) * partial i f y) int) i int`, |
| 2277 |
REWRITE_TAC[]);; |
| 2278 |
|
| 2279 |
|
| 2280 |
let exp_second_lemma' = |
| 2281 |
prove(`interval_arith ((exp (f x) * partial j f (x:real^N)) |
| 2282 |
* partial i f x + exp (f x) * partial2 j i f x) int <=> |
| 2283 |
(\j int. interval_arith ((exp (f x) * partial j f x) |
| 2284 |
* partial i f x + exp (f x) * partial2 j i f x) int) j int`, |
| 2285 |
REWRITE_TAC[]);; |
| 2286 |
|
| 2287 |
|
| 2288 |
let exp_second_lemma'' = (PURE_REWRITE_RULE[float1_eq; float2_eq; num2_eq] o NUMERALS_TO_NUM o |
| 2289 |
PURE_REWRITE_RULE[FLOAT_OF_NUM; min_exp_def] o prove) |
| 2290 |
(`all_n 1 list |
| 2291 |
(\j int. interval_arith ((exp (f x) * partial j f (x:real^N)) |
| 2292 |
* partial i f x + exp (f x) * partial2 j i f x) int) <=> |
| 2293 |
(\i list. all_n 1 list |
| 2294 |
(\j int. interval_arith ((exp (f x) * partial j f x) |
| 2295 |
* partial i f x + exp (f x) * partial2 j i f x) int)) i list`, |
| 2296 |
REWRITE_TAC[]);; |
| 2297 |
|
| 2298 |
|
| 2299 |
let eval_m_taylor_exp n p_lin p_second taylor1_th = |
| 2300 |
let domain_th, diff2_f1_th, lin1_th, second1_th = dest_m_taylor_thms n taylor1_th in |
| 2301 |
let f1_tm = (rand o concl) diff2_f1_th in |
| 2302 |
let domain_tm, y_tm, w_tm = dest_m_cell_domain (concl domain_th) in |
| 2303 |
let ty = type_of y_tm in |
| 2304 |
|
| 2305 |
let x_var = mk_var ("x", ty) and |
| 2306 |
y_var = mk_var ("y", ty) and |
| 2307 |
w_var = mk_var ("w", ty) and |
| 2308 |
f_var = mk_var ("f", type_of f1_tm) and |
| 2309 |
domain_var = mk_var ("domain", type_of domain_tm) in |
| 2310 |
|
| 2311 |
let undisch = UNDISCH o SPEC x_var in |
| 2312 |
|
| 2313 |
let f1_bound0 = eval_m_taylor_bound n p_second taylor1_th in |
| 2314 |
let f1_bound = undisch f1_bound0 in |
| 2315 |
|
| 2316 |
let _, bounds1_th, df1_th = m_lin_approx_components n lin1_th in |
| 2317 |
|
| 2318 |
let bounds_th = float_interval_exp p_lin bounds1_th in |
| 2319 |
let bounds_tm = (rand o concl) bounds_th in |
| 2320 |
|
| 2321 |
(* partial_lemma' *) |
| 2322 |
let u_lemma0 = (INST[f1_tm, f_var; y_tm, y_var] o |
| 2323 |
INST_TYPE[n_type_array.(n), nty]) exp_partial_lemma' in |
| 2324 |
|
| 2325 |
let u_bounds = |
| 2326 |
let exp = float_interval_exp p_lin in |
| 2327 |
exp (bounds1_th) in |
| 2328 |
|
| 2329 |
let u_lin th1 = |
| 2330 |
(* partial *) |
| 2331 |
let u_th = |
| 2332 |
let ( * ) = float_interval_mul p_lin in |
| 2333 |
u_bounds * th1 in |
| 2334 |
let int_tm = rand (concl u_th) in |
| 2335 |
let i_tm = (rand o rator o rator o lhand) (concl th1) in |
| 2336 |
let th0 = INST[i_tm, i_var_num; int_tm, int_var] u_lemma0 in |
| 2337 |
EQ_MP th0 u_th in |
| 2338 |
|
| 2339 |
let df_th = eval_all_n df1_th true u_lin in |
| 2340 |
let d_bounds_list = (rand o rator o concl) df_th in |
| 2341 |
|
| 2342 |
let dd1 = second_bounded_components n second1_th in |
| 2343 |
|
| 2344 |
(* second_lemma', second_lemma'' *) |
| 2345 |
let u_second_lemma0 = (INST[f1_tm, f_var] o |
| 2346 |
INST_TYPE[n_type_array.(n), nty]) exp_second_lemma' in |
| 2347 |
|
| 2348 |
let u_second_lemma1 = (INST[f1_tm, f_var] o |
| 2349 |
INST_TYPE[n_type_array.(n), nty]) exp_second_lemma'' in |
| 2350 |
|
| 2351 |
let d1_bounds = map (fun i -> |
| 2352 |
let th0 = eval_m_taylor_partial_bound n p_second i taylor1_th in |
| 2353 |
undisch th0) (1--n) in |
| 2354 |
|
| 2355 |
(* u'(f x), u''(f x) *) |
| 2356 |
let d1_th0, d2_th0 = |
| 2357 |
let exp = float_interval_exp p_second in |
| 2358 |
let exp_f = exp f1_bound in |
| 2359 |
exp_f, exp_f in |
| 2360 |
|
| 2361 |
let u_second2 th1 = |
| 2362 |
let i_tm = (rand o rator o concl) th1 in |
| 2363 |
let i_int = (Num.int_of_num o raw_dest_hash) i_tm in |
| 2364 |
let di1 = List.nth d1_bounds (i_int - 1) in |
| 2365 |
let th1 = MY_BETA_RULE th1 in |
| 2366 |
let lemma = INST[i_tm, i_var_num] u_second_lemma0 in |
| 2367 |
let u_second th1 = |
| 2368 |
let j_tm = (rand o rator o rator o rator o lhand) (concl th1) in |
| 2369 |
let j_int = (Num.int_of_num o raw_dest_hash) j_tm in |
| 2370 |
let dj1 = List.nth d1_bounds (j_int - 1) in |
| 2371 |
|
| 2372 |
(* partial2 *) |
| 2373 |
let u_th = |
| 2374 |
let ( * ), ( + ) = float_interval_mul p_second, float_interval_add p_second in |
| 2375 |
(d2_th0 * dj1) * di1 + d1_th0 * th1 in |
| 2376 |
|
| 2377 |
let int_tm = rand (concl u_th) in |
| 2378 |
let th0 = INST[j_tm, j_var_num; int_tm, int_var] lemma in |
| 2379 |
EQ_MP th0 u_th in |
| 2380 |
|
| 2381 |
let u_th = eval_all_n th1 true u_second in |
| 2382 |
let list_tm = (rand o rator o concl) u_th in |
| 2383 |
let lemma1 = INST[i_tm, i_var_num; list_tm, list_var_real_pair] u_second_lemma1 in |
| 2384 |
EQ_MP lemma1 u_th in |
| 2385 |
|
| 2386 |
let dd_th0 = eval_all_n dd1 false u_second2 in |
| 2387 |
let dd_list = (rand o rator o concl) dd_th0 in |
| 2388 |
let dd_th = GEN x_var (DISCH_ALL dd_th0) in |
| 2389 |
|
| 2390 |
let th = (MY_PROVE_HYP dd_th o MY_PROVE_HYP diff2_f1_th o |
| 2391 |
MY_PROVE_HYP bounds_th o MY_PROVE_HYP df_th o MY_PROVE_HYP domain_th o |
| 2392 |
INST[f1_tm, f_var; |
| 2393 |
domain_tm, domain_var; y_tm, y_var; w_tm, w_var; |
| 2394 |
bounds_tm, bounds_var; d_bounds_list, d_bounds_list_var; |
| 2395 |
dd_list, dd_bounds_list_var] o |
| 2396 |
INST_TYPE[n_type_array.(n), nty]) MK_M_TAYLOR_EXP' in |
| 2397 |
let eq_th = unary_beta_gen_eq f1_tm x_var exp_tm in |
| 2398 |
m_taylor_interval_norm th eq_th;; |
| 2399 |
|
| 2400 |
|
| 2401 |
(* ----------------------- *) |
| 2402 |
(* eval_m_taylor_log *) |
| 2403 |
(* ----------------------- *) |
| 2404 |
|
| 2405 |
let log_partial_lemma' = |
| 2406 |
prove(`interval_arith (inv (f y) * partial i f (y:real^N)) int <=> |
| 2407 |
(\i int. interval_arith (inv (f y) * partial i f y) int) i int`, |
| 2408 |
REWRITE_TAC[]);; |
| 2409 |
|
| 2410 |
|
| 2411 |
let log_second_lemma' = |
| 2412 |
prove(`interval_arith ((--(inv (f x) pow 2) * partial j f x) * partial i f (x:real^N) + |
| 2413 |
inv (f x) * partial2 j i f x) int <=> |
| 2414 |
(\j int. interval_arith ((--(inv (f x) pow 2) * partial j f x) * partial i f x + |
| 2415 |
inv (f x) * partial2 j i f x) int) j int`, |
| 2416 |
REWRITE_TAC[]);; |
| 2417 |
|
| 2418 |
|
| 2419 |
let log_second_lemma'' = (PURE_REWRITE_RULE[GSYM num1_eq] o prove) |
| 2420 |
(`all_n 1 list |
| 2421 |
(\j int. interval_arith ((--(inv (f x) pow 2) * partial j f x) * partial i f x + |
| 2422 |
inv (f x) * partial2 j i f (x:real^N)) int) <=> |
| 2423 |
(\i list. all_n 1 list |
| 2424 |
(\j int. interval_arith ((--(inv (f x) pow 2) * partial j f x) * partial i f x + |
| 2425 |
inv (f x) * partial2 j i f (x:real^N)) int)) i list`, |
| 2426 |
REWRITE_TAC[]);; |
| 2427 |
|
| 2428 |
|
| 2429 |
let eval_m_taylor_log n p_lin p_second taylor1_th = |
| 2430 |
let domain_th, diff2_f1_th, lin1_th, second1_th = dest_m_taylor_thms n taylor1_th in |
| 2431 |
let f1_tm = (rand o concl) diff2_f1_th in |
| 2432 |
let domain_tm, y_tm, w_tm = dest_m_cell_domain (concl domain_th) in |
| 2433 |
let ty = type_of y_tm in |
| 2434 |
|
| 2435 |
let x_var = mk_var ("x", ty) and |
| 2436 |
y_var = mk_var ("y", ty) and |
| 2437 |
w_var = mk_var ("w", ty) and |
| 2438 |
f_var = mk_var ("f", type_of f1_tm) and |
| 2439 |
domain_var = mk_var ("domain", type_of domain_tm) in |
| 2440 |
|
| 2441 |
let undisch = UNDISCH o SPEC x_var in |
| 2442 |
|
| 2443 |
let f1_bound0 = eval_m_taylor_bound n p_second taylor1_th in |
| 2444 |
let f1_bound = undisch f1_bound0 in |
| 2445 |
let f_bounds_tm = (rand o concl) f1_bound in |
| 2446 |
|
| 2447 |
(* cond *) |
| 2448 |
let cond_th = check_interval_pos f_bounds_tm in |
| 2449 |
|
| 2450 |
let _, bounds1_th, df1_th = m_lin_approx_components n lin1_th in |
| 2451 |
|
| 2452 |
let bounds_th = float_interval_log p_lin bounds1_th in |
| 2453 |
let bounds_tm = (rand o concl) bounds_th in |
| 2454 |
|
| 2455 |
(* partial_lemma' *) |
| 2456 |
let u_lemma0 = (INST[f1_tm, f_var; y_tm, y_var] o |
| 2457 |
INST_TYPE[n_type_array.(n), nty]) log_partial_lemma' in |
| 2458 |
|
| 2459 |
let u_bounds = |
| 2460 |
let inv = float_interval_inv p_lin in |
| 2461 |
inv (bounds1_th) in |
| 2462 |
|
| 2463 |
let u_lin th1 = |
| 2464 |
(* partial *) |
| 2465 |
let u_th = |
| 2466 |
let ( * ) = float_interval_mul p_lin in |
| 2467 |
u_bounds * th1 in |
| 2468 |
let int_tm = rand (concl u_th) in |
| 2469 |
let i_tm = (rand o rator o rator o lhand) (concl th1) in |
| 2470 |
let th0 = INST[i_tm, i_var_num; int_tm, int_var] u_lemma0 in |
| 2471 |
EQ_MP th0 u_th in |
| 2472 |
|
| 2473 |
let df_th = eval_all_n df1_th true u_lin in |
| 2474 |
let d_bounds_list = (rand o rator o concl) df_th in |
| 2475 |
|
| 2476 |
let dd1 = second_bounded_components n second1_th in |
| 2477 |
|
| 2478 |
(* second_lemma', second_lemma'' *) |
| 2479 |
let u_second_lemma0 = (INST[f1_tm, f_var] o |
| 2480 |
INST_TYPE[n_type_array.(n), nty]) log_second_lemma' in |
| 2481 |
|
| 2482 |
let u_second_lemma1 = (INST[f1_tm, f_var] o |
| 2483 |
INST_TYPE[n_type_array.(n), nty]) log_second_lemma'' in |
| 2484 |
|
| 2485 |
let d1_bounds = map (fun i -> |
| 2486 |
let th0 = eval_m_taylor_partial_bound n p_second i taylor1_th in |
| 2487 |
undisch th0) (1--n) in |
| 2488 |
|
| 2489 |
(* u'(f x), u''(f x) *) |
| 2490 |
let d1_th0, d2_th0 = |
| 2491 |
let neg, pow2, inv = |
| 2492 |
float_interval_neg, float_interval_pow p_second 2, float_interval_inv p_second in |
| 2493 |
let inv_f = inv f1_bound in |
| 2494 |
inv_f, neg (pow2 inv_f) in |
| 2495 |
|
| 2496 |
let u_second2 th1 = |
| 2497 |
let i_tm = (rand o rator o concl) th1 in |
| 2498 |
let i_int = (Num.int_of_num o raw_dest_hash) i_tm in |
| 2499 |
let di1 = List.nth d1_bounds (i_int - 1) in |
| 2500 |
let th1 = MY_BETA_RULE th1 in |
| 2501 |
let lemma = INST[i_tm, i_var_num] u_second_lemma0 in |
| 2502 |
let u_second th1 = |
| 2503 |
let j_tm = (rand o rator o rator o rator o lhand) (concl th1) in |
| 2504 |
let j_int = (Num.int_of_num o raw_dest_hash) j_tm in |
| 2505 |
let dj1 = List.nth d1_bounds (j_int - 1) in |
| 2506 |
|
| 2507 |
(* partial2 *) |
| 2508 |
let u_th = |
| 2509 |
let ( * ), ( + ) = float_interval_mul p_second, float_interval_add p_second in |
| 2510 |
(d2_th0 * dj1) * di1 + d1_th0 * th1 in |
| 2511 |
|
| 2512 |
let int_tm = rand (concl u_th) in |
| 2513 |
let th0 = INST[j_tm, j_var_num; int_tm, int_var] lemma in |
| 2514 |
EQ_MP th0 u_th in |
| 2515 |
|
| 2516 |
let u_th = eval_all_n th1 true u_second in |
| 2517 |
let list_tm = (rand o rator o concl) u_th in |
| 2518 |
let lemma1 = INST[i_tm, i_var_num; list_tm, list_var_real_pair] u_second_lemma1 in |
| 2519 |
EQ_MP lemma1 u_th in |
| 2520 |
|
| 2521 |
let dd_th0 = eval_all_n dd1 false u_second2 in |
| 2522 |
let dd_list = (rand o rator o concl) dd_th0 in |
| 2523 |
let dd_th = GEN x_var (DISCH_ALL dd_th0) in |
| 2524 |
|
| 2525 |
let th = (MY_PROVE_HYP dd_th o MY_PROVE_HYP diff2_f1_th o |
| 2526 |
MY_PROVE_HYP cond_th o MY_PROVE_HYP f1_bound0 o |
| 2527 |
MY_PROVE_HYP bounds_th o MY_PROVE_HYP df_th o MY_PROVE_HYP domain_th o |
| 2528 |
INST[f1_tm, f_var; f_bounds_tm, f_bounds_var; |
| 2529 |
domain_tm, domain_var; y_tm, y_var; w_tm, w_var; |
| 2530 |
bounds_tm, bounds_var; d_bounds_list, d_bounds_list_var; |
| 2531 |
dd_list, dd_bounds_list_var] o |
| 2532 |
INST_TYPE[n_type_array.(n), nty]) MK_M_TAYLOR_LOG' in |
| 2533 |
let eq_th = unary_beta_gen_eq f1_tm x_var log_tm in |
| 2534 |
m_taylor_interval_norm th eq_th;; |
| 2535 |
|
| 2536 |
|
| 2537 |
|
| 2538 |
(* ----------------------- *) |
| 2539 |
(* eval_m_taylor_atn *) |
| 2540 |
(* ----------------------- *) |
| 2541 |
|
| 2542 |
let atn_partial_lemma' = |
| 2543 |
prove(`interval_arith (inv (&1 + f y * f y) * partial i f (y:real^N)) int <=> |
| 2544 |
(\i int. interval_arith (inv (&1 + f y * f y) * partial i f y) int) i int`, |
| 2545 |
REWRITE_TAC[]);; |
| 2546 |
|
| 2547 |
|
| 2548 |
let atn_second_lemma' = |
| 2549 |
prove(`interval_arith ((((-- &2 * f x) * inv (&1 + f x * f x) pow 2) * partial j f (x:real^N)) |
| 2550 |
* partial i f x + inv (&1 + f x * f x) * partial2 j i f x) int <=> |
| 2551 |
(\j int. interval_arith ((((-- &2 * f x) * inv (&1 + f x * f x) pow 2) * partial j f x) |
| 2552 |
* partial i f x + inv (&1 + f x * f x) * partial2 j i f x) int) j int`, |
| 2553 |
REWRITE_TAC[]);; |
| 2554 |
|
| 2555 |
|
| 2556 |
let atn_second_lemma'' = (PURE_REWRITE_RULE[float1_eq; float2_eq; num2_eq] o NUMERALS_TO_NUM o |
| 2557 |
PURE_REWRITE_RULE[FLOAT_OF_NUM; min_exp_def] o prove) |
| 2558 |
(`all_n 1 list |
| 2559 |
(\j int. interval_arith ((((-- &2 * f x) * inv (&1 + f x * f x) pow 2) * partial j f (x:real^N)) |
| 2560 |
* partial i f x + inv (&1 + f x * f x) * partial2 j i f x) int) <=> |
| 2561 |
(\i list. all_n 1 list |
| 2562 |
(\j int. interval_arith ((((-- &2 * f x) * inv (&1 + f x * f x) pow 2) * partial j f x) |
| 2563 |
* partial i f x + inv (&1 + f x * f x) * partial2 j i f x) int)) i list`, |
| 2564 |
REWRITE_TAC[]);; |
| 2565 |
|
| 2566 |
|
| 2567 |
|
| 2568 |
let eval_m_taylor_atn n p_lin p_second taylor1_th = |
| 2569 |
let domain_th, diff2_f1_th, lin1_th, second1_th = dest_m_taylor_thms n taylor1_th in |
| 2570 |
let f1_tm = (rand o concl) diff2_f1_th in |
| 2571 |
let domain_tm, y_tm, w_tm = dest_m_cell_domain (concl domain_th) in |
| 2572 |
let ty = type_of y_tm in |
| 2573 |
|
| 2574 |
let x_var = mk_var ("x", ty) and |
| 2575 |
y_var = mk_var ("y", ty) and |
| 2576 |
w_var = mk_var ("w", ty) and |
| 2577 |
f_var = mk_var ("f", type_of f1_tm) and |
| 2578 |
domain_var = mk_var ("domain", type_of domain_tm) in |
| 2579 |
|
| 2580 |
let undisch = UNDISCH o SPEC x_var in |
| 2581 |
|
| 2582 |
let f1_bound0 = eval_m_taylor_bound n p_second taylor1_th in |
| 2583 |
let f1_bound = undisch f1_bound0 in |
| 2584 |
|
| 2585 |
let _, bounds1_th, df1_th = m_lin_approx_components n lin1_th in |
| 2586 |
|
| 2587 |
let bounds_th = float_interval_atn p_lin bounds1_th in |
| 2588 |
let bounds_tm = (rand o concl) bounds_th in |
| 2589 |
|
| 2590 |
(* partial_lemma' *) |
| 2591 |
let u_lemma0 = (INST[f1_tm, f_var; y_tm, y_var] o |
| 2592 |
INST_TYPE[n_type_array.(n), nty]) atn_partial_lemma' in |
| 2593 |
|
| 2594 |
let u_bounds = |
| 2595 |
let inv, ( + ), ( * ) = float_interval_inv p_lin, float_interval_add p_lin, float_interval_mul p_lin in |
| 2596 |
inv (one_interval + bounds1_th * bounds1_th) in |
| 2597 |
|
| 2598 |
let u_lin th1 = |
| 2599 |
(* partial *) |
| 2600 |
let u_th = |
| 2601 |
let ( * ) = float_interval_mul p_lin in |
| 2602 |
u_bounds * th1 in |
| 2603 |
let int_tm = rand (concl u_th) in |
| 2604 |
let i_tm = (rand o rator o rator o lhand) (concl th1) in |
| 2605 |
let th0 = INST[i_tm, i_var_num; int_tm, int_var] u_lemma0 in |
| 2606 |
EQ_MP th0 u_th in |
| 2607 |
|
| 2608 |
let df_th = eval_all_n df1_th true u_lin in |
| 2609 |
let d_bounds_list = (rand o rator o concl) df_th in |
| 2610 |
|
| 2611 |
|
| 2612 |
let dd1 = second_bounded_components n second1_th in |
| 2613 |
|
| 2614 |
(* second_lemma', second_lemma'' *) |
| 2615 |
let u_second_lemma0 = (INST[f1_tm, f_var] o |
| 2616 |
INST_TYPE[n_type_array.(n), nty]) atn_second_lemma' in |
| 2617 |
|
| 2618 |
let u_second_lemma1 = (INST[f1_tm, f_var] o |
| 2619 |
INST_TYPE[n_type_array.(n), nty]) atn_second_lemma'' in |
| 2620 |
|
| 2621 |
let d1_bounds = map (fun i -> |
| 2622 |
let th0 = eval_m_taylor_partial_bound n p_second i taylor1_th in |
| 2623 |
undisch th0) (1--n) in |
| 2624 |
|
| 2625 |
|
| 2626 |
(* u'(f x), u''(f x) *) |
| 2627 |
let d1_th0, d2_th0 = |
| 2628 |
let neg, inv, ( + ), ( * ), pow2 = float_interval_neg, float_interval_inv p_second, |
| 2629 |
float_interval_add p_second, float_interval_mul p_second, float_interval_pow p_second 2 in |
| 2630 |
let inv_one_ff = inv (one_interval + f1_bound * f1_bound) in |
| 2631 |
inv_one_ff, |
| 2632 |
(neg_two_interval * f1_bound) * pow2 inv_one_ff in |
| 2633 |
|
| 2634 |
let u_second2 th1 = |
| 2635 |
let i_tm = (rand o rator o concl) th1 in |
| 2636 |
let i_int = (Num.int_of_num o raw_dest_hash) i_tm in |
| 2637 |
let di1 = List.nth d1_bounds (i_int - 1) in |
| 2638 |
let th1 = MY_BETA_RULE th1 in |
| 2639 |
let lemma = INST[i_tm, i_var_num] u_second_lemma0 in |
| 2640 |
let u_second th1 = |
| 2641 |
let j_tm = (rand o rator o rator o rator o lhand) (concl th1) in |
| 2642 |
let j_int = (Num.int_of_num o raw_dest_hash) j_tm in |
| 2643 |
let dj1 = List.nth d1_bounds (j_int - 1) in |
| 2644 |
|
| 2645 |
(* partial2 *) |
| 2646 |
let u_th = |
| 2647 |
let ( * ), ( + ) = float_interval_mul p_second, float_interval_add p_second in |
| 2648 |
(d2_th0 * dj1) * di1 + d1_th0 * th1 in |
| 2649 |
|
| 2650 |
let int_tm = rand (concl u_th) in |
| 2651 |
let th0 = INST[j_tm, j_var_num; int_tm, int_var] lemma in |
| 2652 |
EQ_MP th0 u_th in |
| 2653 |
|
| 2654 |
let u_th = eval_all_n th1 true u_second in |
| 2655 |
let list_tm = (rand o rator o concl) u_th in |
| 2656 |
let lemma1 = INST[i_tm, i_var_num; list_tm, list_var_real_pair] u_second_lemma1 in |
| 2657 |
EQ_MP lemma1 u_th in |
| 2658 |
|
| 2659 |
let dd_th0 = eval_all_n dd1 false u_second2 in |
| 2660 |
let dd_list = (rand o rator o concl) dd_th0 in |
| 2661 |
let dd_th = GEN x_var (DISCH_ALL dd_th0) in |
| 2662 |
|
| 2663 |
let th = (MY_PROVE_HYP dd_th o MY_PROVE_HYP diff2_f1_th o |
| 2664 |
MY_PROVE_HYP bounds_th o MY_PROVE_HYP df_th o MY_PROVE_HYP domain_th o |
| 2665 |
INST[f1_tm, f_var; |
| 2666 |
domain_tm, domain_var; y_tm, y_var; w_tm, w_var; |
| 2667 |
bounds_tm, bounds_var; d_bounds_list, d_bounds_list_var; |
| 2668 |
dd_list, dd_bounds_list_var] o |
| 2669 |
INST_TYPE[n_type_array.(n), nty]) MK_M_TAYLOR_ATN' in |
| 2670 |
let eq_th = unary_beta_gen_eq f1_tm x_var atn_tm in |
| 2671 |
m_taylor_interval_norm th eq_th;; |
| 2672 |
|
| 2673 |
|
| 2674 |
(* ----------------------- *) |
| 2675 |
(* eval_m_taylor_cos *) |
| 2676 |
(* ----------------------- *) |
| 2677 |
|
| 2678 |
let cos_partial_lemma' = |
| 2679 |
prove(`interval_arith (--sin (f y) * partial i f (y:real^N)) int <=> |
| 2680 |
(\i int. interval_arith (--sin (f y) * partial i f y) int) i int`, |
| 2681 |
REWRITE_TAC[]);; |
| 2682 |
|
| 2683 |
|
| 2684 |
let cos_second_lemma' = |
| 2685 |
prove(`interval_arith (--((cos (f x) * partial j f (x:real^N)) * partial i f x |
| 2686 |
+ sin (f x) * partial2 j i f x)) int <=> |
| 2687 |
(\j int. interval_arith (--((cos (f x) * partial j f x) * partial i f x |
| 2688 |
+ sin (f x) * partial2 j i f x)) int) j int`, |
| 2689 |
REWRITE_TAC[]);; |
| 2690 |
|
| 2691 |
|
| 2692 |
let cos_second_lemma'' = (PURE_REWRITE_RULE[float1_eq; float2_eq; num2_eq] o NUMERALS_TO_NUM o |
| 2693 |
PURE_REWRITE_RULE[FLOAT_OF_NUM; min_exp_def] o prove) |
| 2694 |
(`all_n 1 list |
| 2695 |
(\j int. interval_arith (--((cos (f x) * partial j f (x:real^N)) * partial i f x |
| 2696 |
+ sin (f x) * partial2 j i f x)) int) <=> |
| 2697 |
(\i list. all_n 1 list |
| 2698 |
(\j int. interval_arith (--((cos (f x) * partial j f (x:real^N)) * partial i f x |
| 2699 |
+ sin (f x) * partial2 j i f x)) int)) i list`, |
| 2700 |
REWRITE_TAC[]);; |
| 2701 |
|
| 2702 |
|
| 2703 |
let eval_m_taylor_cos n p_lin p_second taylor1_th = |
| 2704 |
let domain_th, diff2_f1_th, lin1_th, second1_th = dest_m_taylor_thms n taylor1_th in |
| 2705 |
let f1_tm = (rand o concl) diff2_f1_th in |
| 2706 |
let domain_tm, y_tm, w_tm = dest_m_cell_domain (concl domain_th) in |
| 2707 |
let ty = type_of y_tm in |
| 2708 |
|
| 2709 |
let x_var = mk_var ("x", ty) and |
| 2710 |
y_var = mk_var ("y", ty) and |
| 2711 |
w_var = mk_var ("w", ty) and |
| 2712 |
f_var = mk_var ("f", type_of f1_tm) and |
| 2713 |
domain_var = mk_var ("domain", type_of domain_tm) in |
| 2714 |
|
| 2715 |
let undisch = UNDISCH o SPEC x_var in |
| 2716 |
|
| 2717 |
let f1_bound0 = eval_m_taylor_bound n p_second taylor1_th in |
| 2718 |
let f1_bound = undisch f1_bound0 in |
| 2719 |
|
| 2720 |
let _, bounds1_th, df1_th = m_lin_approx_components n lin1_th in |
| 2721 |
|
| 2722 |
let bounds_th = float_interval_cos p_lin bounds1_th in |
| 2723 |
let bounds_tm = (rand o concl) bounds_th in |
| 2724 |
|
| 2725 |
(* partial_lemma' *) |
| 2726 |
let u_lemma0 = (INST[f1_tm, f_var; y_tm, y_var] o |
| 2727 |
INST_TYPE[n_type_array.(n), nty]) cos_partial_lemma' in |
| 2728 |
|
| 2729 |
let u_bounds = |
| 2730 |
let sin, neg = float_interval_sin p_lin, float_interval_neg in |
| 2731 |
neg (sin bounds1_th) in |
| 2732 |
|
| 2733 |
let u_lin th1 = |
| 2734 |
(* partial *) |
| 2735 |
let u_th = |
| 2736 |
let ( * ) = float_interval_mul p_lin in |
| 2737 |
u_bounds * th1 in |
| 2738 |
let int_tm = rand (concl u_th) in |
| 2739 |
let i_tm = (rand o rator o rator o lhand) (concl th1) in |
| 2740 |
let th0 = INST[i_tm, i_var_num; int_tm, int_var] u_lemma0 in |
| 2741 |
EQ_MP th0 u_th in |
| 2742 |
|
| 2743 |
let df_th = eval_all_n df1_th true u_lin in |
| 2744 |
let d_bounds_list = (rand o rator o concl) df_th in |
| 2745 |
|
| 2746 |
let dd1 = second_bounded_components n second1_th in |
| 2747 |
|
| 2748 |
(* second_lemma', second_lemma'' *) |
| 2749 |
let u_second_lemma0 = (INST[f1_tm, f_var] o |
| 2750 |
INST_TYPE[n_type_array.(n), nty]) cos_second_lemma' in |
| 2751 |
|
| 2752 |
let u_second_lemma1 = (INST[f1_tm, f_var] o |
| 2753 |
INST_TYPE[n_type_array.(n), nty]) cos_second_lemma'' in |
| 2754 |
|
| 2755 |
let d1_bounds = map (fun i -> |
| 2756 |
let th0 = eval_m_taylor_partial_bound n p_second i taylor1_th in |
| 2757 |
undisch th0) (1--n) in |
| 2758 |
|
| 2759 |
(* u'(f x), u''(f x) *) |
| 2760 |
let d1_th0, d2_th0 = |
| 2761 |
let cos, sin = float_interval_cos p_second, float_interval_sin p_second in |
| 2762 |
sin f1_bound, cos f1_bound in |
| 2763 |
|
| 2764 |
let u_second2 th1 = |
| 2765 |
let i_tm = (rand o rator o concl) th1 in |
| 2766 |
let i_int = (Num.int_of_num o raw_dest_hash) i_tm in |
| 2767 |
let di1 = List.nth d1_bounds (i_int - 1) in |
| 2768 |
let th1 = MY_BETA_RULE th1 in |
| 2769 |
let lemma = INST[i_tm, i_var_num] u_second_lemma0 in |
| 2770 |
let u_second th1 = |
| 2771 |
let j_tm = (rand o rator o rator o rator o lhand) (concl th1) in |
| 2772 |
let j_int = (Num.int_of_num o raw_dest_hash) j_tm in |
| 2773 |
let dj1 = List.nth d1_bounds (j_int - 1) in |
| 2774 |
|
| 2775 |
(* partial2 *) |
| 2776 |
let u_th = |
| 2777 |
let ( * ), ( + ) = float_interval_mul p_second, float_interval_add p_second in |
| 2778 |
let neg = float_interval_neg in |
| 2779 |
neg ((d2_th0 * dj1) * di1 + d1_th0 * th1) in |
| 2780 |
|
| 2781 |
let int_tm = rand (concl u_th) in |
| 2782 |
let th0 = INST[j_tm, j_var_num; int_tm, int_var] lemma in |
| 2783 |
EQ_MP th0 u_th in |
| 2784 |
|
| 2785 |
let u_th = eval_all_n th1 true u_second in |
| 2786 |
let list_tm = (rand o rator o concl) u_th in |
| 2787 |
let lemma1 = INST[i_tm, i_var_num; list_tm, list_var_real_pair] u_second_lemma1 in |
| 2788 |
EQ_MP lemma1 u_th in |
| 2789 |
|
| 2790 |
let dd_th0 = eval_all_n dd1 false u_second2 in |
| 2791 |
let dd_list = (rand o rator o concl) dd_th0 in |
| 2792 |
let dd_th = GEN x_var (DISCH_ALL dd_th0) in |
| 2793 |
|
| 2794 |
let th = (MY_PROVE_HYP dd_th o MY_PROVE_HYP diff2_f1_th o |
| 2795 |
MY_PROVE_HYP bounds_th o MY_PROVE_HYP df_th o MY_PROVE_HYP domain_th o |
| 2796 |
INST[f1_tm, f_var; |
| 2797 |
domain_tm, domain_var; y_tm, y_var; w_tm, w_var; |
| 2798 |
bounds_tm, bounds_var; d_bounds_list, d_bounds_list_var; |
| 2799 |
dd_list, dd_bounds_list_var] o |
| 2800 |
INST_TYPE[n_type_array.(n), nty]) MK_M_TAYLOR_COS' in |
| 2801 |
let eq_th = unary_beta_gen_eq f1_tm x_var cos_tm in |
| 2802 |
m_taylor_interval_norm th eq_th;; |
| 2803 |
|
| 2804 |
|
| 2805 |
(* ----------------------- *) |
| 2806 |
(* eval_m_taylor_sin *) |
| 2807 |
(* ----------------------- *) |
| 2808 |
|
| 2809 |
let sin_partial_lemma' = |
| 2810 |
prove(`interval_arith (cos (f y) * partial i f (y:real^N)) int <=> |
| 2811 |
(\i int. interval_arith (cos (f y) * partial i f y) int) i int`, |
| 2812 |
REWRITE_TAC[]);; |
| 2813 |
|
| 2814 |
|
| 2815 |
let sin_second_lemma' = |
| 2816 |
prove(`interval_arith ((--sin (f x) * partial j f (x:real^N)) * partial i f x |
| 2817 |
+ cos (f x) * partial2 j i f x) int <=> |
| 2818 |
(\j int. interval_arith ((--sin (f x) * partial j f x) * partial i f x |
| 2819 |
+ cos (f x) * partial2 j i f x) int) j int`, |
| 2820 |
REWRITE_TAC[]);; |
| 2821 |
|
| 2822 |
|
| 2823 |
let sin_second_lemma'' = (PURE_REWRITE_RULE[float1_eq; float2_eq; num2_eq] o NUMERALS_TO_NUM o |
| 2824 |
PURE_REWRITE_RULE[FLOAT_OF_NUM; min_exp_def] o prove) |
| 2825 |
(`all_n 1 list |
| 2826 |
(\j int. interval_arith ((--sin (f x) * partial j f (x:real^N)) * partial i f x |
| 2827 |
+ cos (f x) * partial2 j i f x) int) <=> |
| 2828 |
(\i list. all_n 1 list |
| 2829 |
(\j int. interval_arith ((--sin (f x) * partial j f (x:real^N)) * partial i f x |
| 2830 |
+ cos (f x) * partial2 j i f x) int)) i list`, |
| 2831 |
REWRITE_TAC[]);; |
| 2832 |
|
| 2833 |
|
| 2834 |
let eval_m_taylor_sin n p_lin p_second taylor1_th = |
| 2835 |
let domain_th, diff2_f1_th, lin1_th, second1_th = dest_m_taylor_thms n taylor1_th in |
| 2836 |
let f1_tm = (rand o concl) diff2_f1_th in |
| 2837 |
let domain_tm, y_tm, w_tm = dest_m_cell_domain (concl domain_th) in |
| 2838 |
let ty = type_of y_tm in |
| 2839 |
|
| 2840 |
let x_var = mk_var ("x", ty) and |
| 2841 |
y_var = mk_var ("y", ty) and |
| 2842 |
w_var = mk_var ("w", ty) and |
| 2843 |
f_var = mk_var ("f", type_of f1_tm) and |
| 2844 |
domain_var = mk_var ("domain", type_of domain_tm) in |
| 2845 |
|
| 2846 |
let undisch = UNDISCH o SPEC x_var in |
| 2847 |
|
| 2848 |
let f1_bound0 = eval_m_taylor_bound n p_second taylor1_th in |
| 2849 |
let f1_bound = undisch f1_bound0 in |
| 2850 |
|
| 2851 |
let _, bounds1_th, df1_th = m_lin_approx_components n lin1_th in |
| 2852 |
|
| 2853 |
let bounds_th = float_interval_sin p_lin bounds1_th in |
| 2854 |
let bounds_tm = (rand o concl) bounds_th in |
| 2855 |
|
| 2856 |
(* partial_lemma' *) |
| 2857 |
let u_lemma0 = (INST[f1_tm, f_var; y_tm, y_var] o |
| 2858 |
INST_TYPE[n_type_array.(n), nty]) sin_partial_lemma' in |
| 2859 |
|
| 2860 |
let u_bounds = |
| 2861 |
let cos = float_interval_cos p_lin in |
| 2862 |
cos bounds1_th in |
| 2863 |
|
| 2864 |
let u_lin th1 = |
| 2865 |
(* partial *) |
| 2866 |
let u_th = |
| 2867 |
let ( * ) = float_interval_mul p_lin in |
| 2868 |
u_bounds * th1 in |
| 2869 |
let int_tm = rand (concl u_th) in |
| 2870 |
let i_tm = (rand o rator o rator o lhand) (concl th1) in |
| 2871 |
let th0 = INST[i_tm, i_var_num; int_tm, int_var] u_lemma0 in |
| 2872 |
EQ_MP th0 u_th in |
| 2873 |
|
| 2874 |
let df_th = eval_all_n df1_th true u_lin in |
| 2875 |
let d_bounds_list = (rand o rator o concl) df_th in |
| 2876 |
|
| 2877 |
let dd1 = second_bounded_components n second1_th in |
| 2878 |
|
| 2879 |
(* second_lemma', second_lemma'' *) |
| 2880 |
let u_second_lemma0 = (INST[f1_tm, f_var] o |
| 2881 |
INST_TYPE[n_type_array.(n), nty]) sin_second_lemma' in |
| 2882 |
|
| 2883 |
let u_second_lemma1 = (INST[f1_tm, f_var] o |
| 2884 |
INST_TYPE[n_type_array.(n), nty]) sin_second_lemma'' in |
| 2885 |
|
| 2886 |
let d1_bounds = map (fun i -> |
| 2887 |
let th0 = eval_m_taylor_partial_bound n p_second i taylor1_th in |
| 2888 |
undisch th0) (1--n) in |
| 2889 |
|
| 2890 |
(* u'(f x), u''(f x) *) |
| 2891 |
let d1_th0, d2_th0 = |
| 2892 |
let cos, sin = float_interval_cos p_second, float_interval_sin p_second in |
| 2893 |
let neg = float_interval_neg in |
| 2894 |
cos f1_bound, neg (sin f1_bound) in |
| 2895 |
|
| 2896 |
let u_second2 th1 = |
| 2897 |
let i_tm = (rand o rator o concl) th1 in |
| 2898 |
let i_int = (Num.int_of_num o raw_dest_hash) i_tm in |
| 2899 |
let di1 = List.nth d1_bounds (i_int - 1) in |
| 2900 |
let th1 = MY_BETA_RULE th1 in |
| 2901 |
let lemma = INST[i_tm, i_var_num] u_second_lemma0 in |
| 2902 |
let u_second th1 = |
| 2903 |
let j_tm = (rand o rator o rator o rator o lhand) (concl th1) in |
| 2904 |
let j_int = (Num.int_of_num o raw_dest_hash) j_tm in |
| 2905 |
let dj1 = List.nth d1_bounds (j_int - 1) in |
| 2906 |
|
| 2907 |
(* partial2 *) |
| 2908 |
let u_th = |
| 2909 |
let ( * ), ( + ) = float_interval_mul p_second, float_interval_add p_second in |
| 2910 |
(d2_th0 * dj1) * di1 + d1_th0 * th1 in |
| 2911 |
|
| 2912 |
let int_tm = rand (concl u_th) in |
| 2913 |
let th0 = INST[j_tm, j_var_num; int_tm, int_var] lemma in |
| 2914 |
EQ_MP th0 u_th in |
| 2915 |
|
| 2916 |
let u_th = eval_all_n th1 true u_second in |
| 2917 |
let list_tm = (rand o rator o concl) u_th in |
| 2918 |
let lemma1 = INST[i_tm, i_var_num; list_tm, list_var_real_pair] u_second_lemma1 in |
| 2919 |
EQ_MP lemma1 u_th in |
| 2920 |
|
| 2921 |
let dd_th0 = eval_all_n dd1 false u_second2 in |
| 2922 |
let dd_list = (rand o rator o concl) dd_th0 in |
| 2923 |
let dd_th = GEN x_var (DISCH_ALL dd_th0) in |
| 2924 |
|
| 2925 |
let th = (MY_PROVE_HYP dd_th o MY_PROVE_HYP diff2_f1_th o |
| 2926 |
MY_PROVE_HYP bounds_th o MY_PROVE_HYP df_th o MY_PROVE_HYP domain_th o |
| 2927 |
INST[f1_tm, f_var; |
| 2928 |
domain_tm, domain_var; y_tm, y_var; w_tm, w_var; |
| 2929 |
bounds_tm, bounds_var; d_bounds_list, d_bounds_list_var; |
| 2930 |
dd_list, dd_bounds_list_var] o |
| 2931 |
INST_TYPE[n_type_array.(n), nty]) MK_M_TAYLOR_SIN' in |
| 2932 |
let eq_th = unary_beta_gen_eq f1_tm x_var sin_tm in |
| 2933 |
m_taylor_interval_norm th eq_th;; |
| 2934 |
|
| 2935 |
|
| 2936 |
(* ----------------------- *) |
| 2937 |
(* eval_m_taylor_asn *) |
| 2938 |
(* ----------------------- *) |
| 2939 |
|
| 2940 |
let asn_partial_lemma' = |
| 2941 |
prove(`interval_arith (inv (sqrt (&1 - f y * f y)) * partial i f (y:real^N)) int <=> |
| 2942 |
(\i int. interval_arith (inv (sqrt (&1 - f y * f y)) * partial i f y) int) i int`, |
| 2943 |
REWRITE_TAC[]);; |
| 2944 |
|
| 2945 |
|
| 2946 |
let asn_second_lemma' = |
| 2947 |
prove(`interval_arith (((f x / sqrt ((&1 - f x * f x) pow 3)) * partial j f x) * partial i f (x:real^N) + inv (sqrt (&1 - f x * f x)) * partial2 j i f x) int <=> |
| 2948 |
|
| 2949 |
(\j int. interval_arith (((f x / sqrt ((&1 - f x * f x) pow 3)) * partial j f x) * partial i f (x:real^N) + inv (sqrt (&1 - f x * f x)) * partial2 j i f x) int) j int`, |
| 2950 |
REWRITE_TAC[]);; |
| 2951 |
|
| 2952 |
|
| 2953 |
let asn_second_lemma'' = (PURE_REWRITE_RULE[float1_eq; float2_eq; num3_eq; num2_eq] o NUMERALS_TO_NUM o |
| 2954 |
PURE_REWRITE_RULE[FLOAT_OF_NUM; min_exp_def] o prove) |
| 2955 |
(`all_n 1 list |
| 2956 |
(\j int. interval_arith (((f x / sqrt ((&1 - f x * f x) pow 3)) * partial j f x) * partial i f (x:real^N) + inv (sqrt (&1 - f x * f x)) * partial2 j i f x) int) <=> |
| 2957 |
(\i list. all_n 1 list |
| 2958 |
(\j int. interval_arith (((f x / sqrt ((&1 - f x * f x) pow 3)) * partial j f x) * partial i f (x:real^N) + inv (sqrt (&1 - f x * f x)) * partial2 j i f x) int)) i list`, |
| 2959 |
REWRITE_TAC[]);; |
| 2960 |
|
| 2961 |
|
| 2962 |
let eval_m_taylor_asn n p_lin p_second taylor1_th = |
| 2963 |
let domain_th, diff2_f1_th, lin1_th, second1_th = dest_m_taylor_thms n taylor1_th in |
| 2964 |
let f1_tm = (rand o concl) diff2_f1_th in |
| 2965 |
let domain_tm, y_tm, w_tm = dest_m_cell_domain (concl domain_th) in |
| 2966 |
let ty = type_of y_tm in |
| 2967 |
|
| 2968 |
let x_var = mk_var ("x", ty) and |
| 2969 |
y_var = mk_var ("y", ty) and |
| 2970 |
w_var = mk_var ("w", ty) and |
| 2971 |
f_var = mk_var ("f", type_of f1_tm) and |
| 2972 |
domain_var = mk_var ("domain", type_of domain_tm) in |
| 2973 |
|
| 2974 |
let undisch = UNDISCH o SPEC x_var in |
| 2975 |
|
| 2976 |
let f1_bound0 = eval_m_taylor_bound n p_second taylor1_th in |
| 2977 |
let f1_bound = undisch f1_bound0 in |
| 2978 |
let f_bounds_tm = (rand o concl) f1_bound in |
| 2979 |
|
| 2980 |
(* cond *) |
| 2981 |
let cond_th = EQT_ELIM (check_interval_iabs f_bounds_tm one_float) in |
| 2982 |
|
| 2983 |
let _, bounds1_th, df1_th = m_lin_approx_components n lin1_th in |
| 2984 |
|
| 2985 |
let bounds_th = float_interval_asn p_lin bounds1_th in |
| 2986 |
let bounds_tm = (rand o concl) bounds_th in |
| 2987 |
|
| 2988 |
(* partial_lemma' *) |
| 2989 |
let u_lemma0 = (INST[f1_tm, f_var; y_tm, y_var] o |
| 2990 |
INST_TYPE[n_type_array.(n), nty]) asn_partial_lemma' in |
| 2991 |
|
| 2992 |
let u_bounds = |
| 2993 |
let inv, sqrt = float_interval_inv p_lin, float_interval_sqrt p_lin in |
| 2994 |
let ( * ), (-) = float_interval_mul p_lin, float_interval_sub p_lin in |
| 2995 |
inv (sqrt (one_interval - bounds1_th * bounds1_th)) in |
| 2996 |
|
| 2997 |
let u_lin th1 = |
| 2998 |
(* partial *) |
| 2999 |
let u_th = |
| 3000 |
let ( * ) = float_interval_mul p_lin in |
| 3001 |
u_bounds * th1 in |
| 3002 |
let int_tm = rand (concl u_th) in |
| 3003 |
let i_tm = (rand o rator o rator o lhand) (concl th1) in |
| 3004 |
let th0 = INST[i_tm, i_var_num; int_tm, int_var] u_lemma0 in |
| 3005 |
EQ_MP th0 u_th in |
| 3006 |
|
| 3007 |
let df_th = eval_all_n df1_th true u_lin in |
| 3008 |
let d_bounds_list = (rand o rator o concl) df_th in |
| 3009 |
|
| 3010 |
|
| 3011 |
let dd1 = second_bounded_components n second1_th in |
| 3012 |
|
| 3013 |
(* second_lemma', second_lemma'' *) |
| 3014 |
let u_second_lemma0 = (INST[f1_tm, f_var] o |
| 3015 |
INST_TYPE[n_type_array.(n), nty]) asn_second_lemma' in |
| 3016 |
|
| 3017 |
let u_second_lemma1 = (INST[f1_tm, f_var] o |
| 3018 |
INST_TYPE[n_type_array.(n), nty]) asn_second_lemma'' in |
| 3019 |
|
| 3020 |
let d1_bounds = map (fun i -> |
| 3021 |
let th0 = eval_m_taylor_partial_bound n p_second i taylor1_th in |
| 3022 |
undisch th0) (1--n) in |
| 3023 |
|
| 3024 |
(* u'(f x), u''(f x) *) |
| 3025 |
let d1_th0, d2_th0 = |
| 3026 |
let sqrt, inv = float_interval_sqrt p_second, float_interval_inv p_second in |
| 3027 |
let (-), ( * ), (/) = float_interval_sub p_second, float_interval_mul p_second, float_interval_div p_second in |
| 3028 |
let pow3 = float_interval_pow p_second 3 in |
| 3029 |
let ff_1 = one_interval - f1_bound * f1_bound in |
| 3030 |
inv (sqrt ff_1), |
| 3031 |
f1_bound / sqrt (pow3 ff_1) in |
| 3032 |
|
| 3033 |
let u_second2 th1 = |
| 3034 |
let i_tm = (rand o rator o concl) th1 in |
| 3035 |
let i_int = (Num.int_of_num o raw_dest_hash) i_tm in |
| 3036 |
let di1 = List.nth d1_bounds (i_int - 1) in |
| 3037 |
let th1 = MY_BETA_RULE th1 in |
| 3038 |
let lemma = INST[i_tm, i_var_num] u_second_lemma0 in |
| 3039 |
let u_second th1 = |
| 3040 |
let j_tm = (rand o rator o rator o rator o lhand) (concl th1) in |
| 3041 |
let j_int = (Num.int_of_num o raw_dest_hash) j_tm in |
| 3042 |
let dj1 = List.nth d1_bounds (j_int - 1) in |
| 3043 |
|
| 3044 |
(* partial2 *) |
| 3045 |
let u_th = |
| 3046 |
let ( * ), ( + ) = float_interval_mul p_second, float_interval_add p_second in |
| 3047 |
(d2_th0 * dj1) * di1 + d1_th0 * th1 in |
| 3048 |
|
| 3049 |
let int_tm = rand (concl u_th) in |
| 3050 |
let th0 = INST[j_tm, j_var_num; int_tm, int_var] lemma in |
| 3051 |
EQ_MP th0 u_th in |
| 3052 |
|
| 3053 |
let u_th = eval_all_n th1 true u_second in |
| 3054 |
let list_tm = (rand o rator o concl) u_th in |
| 3055 |
let lemma1 = INST[i_tm, i_var_num; list_tm, list_var_real_pair] u_second_lemma1 in |
| 3056 |
EQ_MP lemma1 u_th in |
| 3057 |
|
| 3058 |
let dd_th0 = eval_all_n dd1 false u_second2 in |
| 3059 |
let dd_list = (rand o rator o concl) dd_th0 in |
| 3060 |
let dd_th = GEN x_var (DISCH_ALL dd_th0) in |
| 3061 |
|
| 3062 |
let th = (MY_PROVE_HYP dd_th o MY_PROVE_HYP diff2_f1_th o |
| 3063 |
MY_PROVE_HYP cond_th o MY_PROVE_HYP f1_bound0 o |
| 3064 |
MY_PROVE_HYP bounds_th o MY_PROVE_HYP df_th o MY_PROVE_HYP domain_th o |
| 3065 |
INST[f1_tm, f_var; f_bounds_tm, f_bounds_var; |
| 3066 |
domain_tm, domain_var; y_tm, y_var; w_tm, w_var; |
| 3067 |
bounds_tm, bounds_var; d_bounds_list, d_bounds_list_var; |
| 3068 |
dd_list, dd_bounds_list_var] o |
| 3069 |
INST_TYPE[n_type_array.(n), nty]) MK_M_TAYLOR_ASN' in |
| 3070 |
let eq_th = unary_beta_gen_eq f1_tm x_var asn_tm in |
| 3071 |
m_taylor_interval_norm th eq_th;; |
| 3072 |
|
| 3073 |
|
| 3074 |
(* ----------------------- *) |
| 3075 |
(* eval_m_taylor_acs *) |
| 3076 |
(* ----------------------- *) |
| 3077 |
|
| 3078 |
let acs_partial_lemma' = |
| 3079 |
prove(`interval_arith (--inv (sqrt (&1 - f y * f y)) * partial i f (y:real^N)) int <=> |
| 3080 |
(\i int. interval_arith (--inv (sqrt (&1 - f y * f y)) * partial i f y) int) i int`, |
| 3081 |
REWRITE_TAC[]);; |
| 3082 |
|
| 3083 |
|
| 3084 |
let acs_second_lemma' = |
| 3085 |
prove(`interval_arith ((--(f x / sqrt ((&1 - f x * f x) pow 3)) * partial j f x) * partial i f (x:real^N) - inv (sqrt (&1 - f x * f x)) * partial2 j i f x) int <=> |
| 3086 |
|
| 3087 |
(\j int. interval_arith ((--(f x / sqrt ((&1 - f x * f x) pow 3)) * partial j f x) * partial i f (x:real^N) - inv (sqrt (&1 - f x * f x)) * partial2 j i f x) int) j int`, |
| 3088 |
REWRITE_TAC[]);; |
| 3089 |
|
| 3090 |
|
| 3091 |
let acs_second_lemma'' = (PURE_REWRITE_RULE[float1_eq; float2_eq; num3_eq; num2_eq] o NUMERALS_TO_NUM o |
| 3092 |
PURE_REWRITE_RULE[FLOAT_OF_NUM; min_exp_def] o prove) |
| 3093 |
(`all_n 1 list |
| 3094 |
(\j int. interval_arith ((--(f x / sqrt ((&1 - f x * f x) pow 3)) * partial j f x) * partial i f (x:real^N) - inv (sqrt (&1 - f x * f x)) * partial2 j i f x) int) <=> |
| 3095 |
(\i list. all_n 1 list |
| 3096 |
(\j int. interval_arith ((--(f x / sqrt ((&1 - f x * f x) pow 3)) * partial j f x) * partial i f (x:real^N) - inv (sqrt (&1 - f x * f x)) * partial2 j i f x) int)) i list`, |
| 3097 |
REWRITE_TAC[]);; |
| 3098 |
|
| 3099 |
|
| 3100 |
let eval_m_taylor_acs n p_lin p_second taylor1_th = |
| 3101 |
let domain_th, diff2_f1_th, lin1_th, second1_th = dest_m_taylor_thms n taylor1_th in |
| 3102 |
let f1_tm = (rand o concl) diff2_f1_th in |
| 3103 |
let domain_tm, y_tm, w_tm = dest_m_cell_domain (concl domain_th) in |
| 3104 |
let ty = type_of y_tm in |
| 3105 |
|
| 3106 |
let x_var = mk_var ("x", ty) and |
| 3107 |
y_var = mk_var ("y", ty) and |
| 3108 |
w_var = mk_var ("w", ty) and |
| 3109 |
f_var = mk_var ("f", type_of f1_tm) and |
| 3110 |
domain_var = mk_var ("domain", type_of domain_tm) in |
| 3111 |
|
| 3112 |
let undisch = UNDISCH o SPEC x_var in |
| 3113 |
|
| 3114 |
let f1_bound0 = eval_m_taylor_bound n p_second taylor1_th in |
| 3115 |
let f1_bound = undisch f1_bound0 in |
| 3116 |
let f_bounds_tm = (rand o concl) f1_bound in |
| 3117 |
|
| 3118 |
(* cond *) |
| 3119 |
let cond_th = EQT_ELIM (check_interval_iabs f_bounds_tm one_float) in |
| 3120 |
|
| 3121 |
let _, bounds1_th, df1_th = m_lin_approx_components n lin1_th in |
| 3122 |
|
| 3123 |
let bounds_th = float_interval_acs p_lin bounds1_th in |
| 3124 |
let bounds_tm = (rand o concl) bounds_th in |
| 3125 |
|
| 3126 |
(* partial_lemma' *) |
| 3127 |
let u_lemma0 = (INST[f1_tm, f_var; y_tm, y_var] o |
| 3128 |
INST_TYPE[n_type_array.(n), nty]) acs_partial_lemma' in |
| 3129 |
|
| 3130 |
let u_bounds = |
| 3131 |
let inv, sqrt, neg = float_interval_inv p_lin, float_interval_sqrt p_lin, float_interval_neg in |
| 3132 |
let ( * ), (-) = float_interval_mul p_lin, float_interval_sub p_lin in |
| 3133 |
neg (inv (sqrt (one_interval - bounds1_th * bounds1_th))) in |
| 3134 |
|
| 3135 |
let u_lin th1 = |
| 3136 |
(* partial *) |
| 3137 |
let u_th = |
| 3138 |
let ( * ) = float_interval_mul p_lin in |
| 3139 |
u_bounds * th1 in |
| 3140 |
let int_tm = rand (concl u_th) in |
| 3141 |
let i_tm = (rand o rator o rator o lhand) (concl th1) in |
| 3142 |
let th0 = INST[i_tm, i_var_num; int_tm, int_var] u_lemma0 in |
| 3143 |
EQ_MP th0 u_th in |
| 3144 |
|
| 3145 |
let df_th = eval_all_n df1_th true u_lin in |
| 3146 |
let d_bounds_list = (rand o rator o concl) df_th in |
| 3147 |
|
| 3148 |
|
| 3149 |
let dd1 = second_bounded_components n second1_th in |
| 3150 |
|
| 3151 |
(* second_lemma', second_lemma'' *) |
| 3152 |
let u_second_lemma0 = (INST[f1_tm, f_var] o |
| 3153 |
INST_TYPE[n_type_array.(n), nty]) acs_second_lemma' in |
| 3154 |
|
| 3155 |
let u_second_lemma1 = (INST[f1_tm, f_var] o |
| 3156 |
INST_TYPE[n_type_array.(n), nty]) acs_second_lemma'' in |
| 3157 |
|
| 3158 |
let d1_bounds = map (fun i -> |
| 3159 |
let th0 = eval_m_taylor_partial_bound n p_second i taylor1_th in |
| 3160 |
undisch th0) (1--n) in |
| 3161 |
|
| 3162 |
(* u'(f x), u''(f x) *) |
| 3163 |
let d1_th0, d2_th0 = |
| 3164 |
let neg, sqrt, inv = float_interval_neg, float_interval_sqrt p_second, float_interval_inv p_second in |
| 3165 |
let (-), ( * ), (/) = float_interval_sub p_second, float_interval_mul p_second, float_interval_div p_second in |
| 3166 |
let pow3 = float_interval_pow p_second 3 in |
| 3167 |
let ff_1 = one_interval - f1_bound * f1_bound in |
| 3168 |
inv (sqrt ff_1), |
| 3169 |
neg (f1_bound / sqrt (pow3 ff_1)) in |
| 3170 |
|
| 3171 |
let u_second2 th1 = |
| 3172 |
let i_tm = (rand o rator o concl) th1 in |
| 3173 |
let i_int = (Num.int_of_num o raw_dest_hash) i_tm in |
| 3174 |
let di1 = List.nth d1_bounds (i_int - 1) in |
| 3175 |
let th1 = MY_BETA_RULE th1 in |
| 3176 |
let lemma = INST[i_tm, i_var_num] u_second_lemma0 in |
| 3177 |
let u_second th1 = |
| 3178 |
let j_tm = (rand o rator o rator o rator o lhand) (concl th1) in |
| 3179 |
let j_int = (Num.int_of_num o raw_dest_hash) j_tm in |
| 3180 |
let dj1 = List.nth d1_bounds (j_int - 1) in |
| 3181 |
|
| 3182 |
(* partial2 *) |
| 3183 |
let u_th = |
| 3184 |
let ( * ), ( - ) = float_interval_mul p_second, float_interval_sub p_second in |
| 3185 |
(d2_th0 * dj1) * di1 - d1_th0 * th1 in |
| 3186 |
|
| 3187 |
let int_tm = rand (concl u_th) in |
| 3188 |
let th0 = INST[j_tm, j_var_num; int_tm, int_var] lemma in |
| 3189 |
EQ_MP th0 u_th in |
| 3190 |
|
| 3191 |
let u_th = eval_all_n th1 true u_second in |
| 3192 |
let list_tm = (rand o rator o concl) u_th in |
| 3193 |
let lemma1 = INST[i_tm, i_var_num; list_tm, list_var_real_pair] u_second_lemma1 in |
| 3194 |
EQ_MP lemma1 u_th in |
| 3195 |
|
| 3196 |
let dd_th0 = eval_all_n dd1 false u_second2 in |
| 3197 |
let dd_list = (rand o rator o concl) dd_th0 in |
| 3198 |
let dd_th = GEN x_var (DISCH_ALL dd_th0) in |
| 3199 |
|
| 3200 |
let th = (MY_PROVE_HYP dd_th o MY_PROVE_HYP diff2_f1_th o |
| 3201 |
MY_PROVE_HYP cond_th o MY_PROVE_HYP f1_bound0 o |
| 3202 |
MY_PROVE_HYP bounds_th o MY_PROVE_HYP df_th o MY_PROVE_HYP domain_th o |
| 3203 |
INST[f1_tm, f_var; f_bounds_tm, f_bounds_var; |
| 3204 |
domain_tm, domain_var; y_tm, y_var; w_tm, w_var; |
| 3205 |
bounds_tm, bounds_var; d_bounds_list, d_bounds_list_var; |
| 3206 |
dd_list, dd_bounds_list_var] o |
| 3207 |
INST_TYPE[n_type_array.(n), nty]) MK_M_TAYLOR_ACS' in |
| 3208 |
let eq_th = unary_beta_gen_eq f1_tm x_var acs_tm in |
| 3209 |
m_taylor_interval_norm th eq_th;; |
| 3210 |
|
| 3211 |
|
| 3212 |
(* ----------------------- *) |
| 3213 |
(* eval_m_taylor_matan *) |
| 3214 |
(* ----------------------- *) |
| 3215 |
|
| 3216 |
let matan_partial_lemma' = |
| 3217 |
prove(`interval_arith (dmatan (f y) * partial i f (y:real^N)) int <=> |
| 3218 |
(\i int. interval_arith (dmatan (f y) * partial i f y) int) i int`, |
| 3219 |
REWRITE_TAC[]);; |
| 3220 |
|
| 3221 |
|
| 3222 |
let matan_second_lemma' = |
| 3223 |
prove(`interval_arith ((ddmatan (f x) * partial j f x) * partial i f (x:real^N) + |
| 3224 |
dmatan (f x) * partial2 j i f x) int <=> |
| 3225 |
(\j int. interval_arith ((ddmatan (f x) * partial j f x) * partial i f (x:real^N) + |
| 3226 |
dmatan (f x) * partial2 j i f x) int) j int`, |
| 3227 |
REWRITE_TAC[]);; |
| 3228 |
|
| 3229 |
|
| 3230 |
let matan_second_lemma'' = (NUMERALS_TO_NUM o |
| 3231 |
PURE_REWRITE_RULE[FLOAT_OF_NUM; min_exp_def] o prove) |
| 3232 |
(`all_n 1 list |
| 3233 |
(\j int. interval_arith ((ddmatan (f x) * partial j f x) * partial i f (x:real^N) |
| 3234 |
+ dmatan (f x) * partial2 j i f x) int) <=> |
| 3235 |
(\i list. all_n 1 list |
| 3236 |
(\j int. interval_arith ((ddmatan (f x) * partial j f x) * partial i f (x:real^N) |
| 3237 |
+ dmatan (f x) * partial2 j i f x) int)) i list`, |
| 3238 |
REWRITE_TAC[]);; |
| 3239 |
|
| 3240 |
let neg_one_float = (lhand o concl) float_neg1_eq;; |
| 3241 |
|
| 3242 |
|
| 3243 |
let eval_m_taylor_matan n p_lin p_second taylor1_th = |
| 3244 |
let domain_th, diff2_f1_th, lin1_th, second1_th = dest_m_taylor_thms n taylor1_th in |
| 3245 |
let f1_tm = (rand o concl) diff2_f1_th in |
| 3246 |
let domain_tm, y_tm, w_tm = dest_m_cell_domain (concl domain_th) in |
| 3247 |
let ty = type_of y_tm in |
| 3248 |
|
| 3249 |
let x_var = mk_var ("x", ty) and |
| 3250 |
y_var = mk_var ("y", ty) and |
| 3251 |
w_var = mk_var ("w", ty) and |
| 3252 |
f_var = mk_var ("f", type_of f1_tm) and |
| 3253 |
domain_var = mk_var ("domain", type_of domain_tm) in |
| 3254 |
|
| 3255 |
let undisch = UNDISCH o SPEC x_var in |
| 3256 |
|
| 3257 |
let f1_bound0 = eval_m_taylor_bound n p_second taylor1_th in |
| 3258 |
let f1_bound = undisch f1_bound0 in |
| 3259 |
let f_bounds_tm = (rand o concl) f1_bound in |
| 3260 |
|
| 3261 |
(* cond *) |
| 3262 |
let cond_th = check_interval_gt neg_one_float f_bounds_tm in |
| 3263 |
|
| 3264 |
let _, bounds1_th, df1_th = m_lin_approx_components n lin1_th in |
| 3265 |
|
| 3266 |
let bounds_th = float_interval_matan p_lin bounds1_th in |
| 3267 |
let bounds_tm = (rand o concl) bounds_th in |
| 3268 |
|
| 3269 |
(* partial_lemma' *) |
| 3270 |
let u_lemma0 = (INST[f1_tm, f_var; y_tm, y_var] o |
| 3271 |
INST_TYPE[n_type_array.(n), nty]) matan_partial_lemma' in |
| 3272 |
|
| 3273 |
let u_bounds = |
| 3274 |
float_interval_dmatan p_lin bounds1_th in |
| 3275 |
|
| 3276 |
let u_lin th1 = |
| 3277 |
(* partial *) |
| 3278 |
let u_th = |
| 3279 |
let ( * ) = float_interval_mul p_lin in |
| 3280 |
u_bounds * th1 in |
| 3281 |
let int_tm = rand (concl u_th) in |
| 3282 |
let i_tm = (rand o rator o rator o lhand) (concl th1) in |
| 3283 |
let th0 = INST[i_tm, i_var_num; int_tm, int_var] u_lemma0 in |
| 3284 |
EQ_MP th0 u_th in |
| 3285 |
|
| 3286 |
let df_th = eval_all_n df1_th true u_lin in |
| 3287 |
let d_bounds_list = (rand o rator o concl) df_th in |
| 3288 |
|
| 3289 |
|
| 3290 |
let dd1 = second_bounded_components n second1_th in |
| 3291 |
|
| 3292 |
(* second_lemma', second_lemma'' *) |
| 3293 |
let u_second_lemma0 = (INST[f1_tm, f_var] o |
| 3294 |
INST_TYPE[n_type_array.(n), nty]) matan_second_lemma' in |
| 3295 |
|
| 3296 |
let u_second_lemma1 = (INST[f1_tm, f_var] o |
| 3297 |
INST_TYPE[n_type_array.(n), nty]) matan_second_lemma'' in |
| 3298 |
|
| 3299 |
let d1_bounds = map (fun i -> |
| 3300 |
let th0 = eval_m_taylor_partial_bound n p_second i taylor1_th in |
| 3301 |
undisch th0) (1--n) in |
| 3302 |
|
| 3303 |
(* u'(f x), u''(f x) *) |
| 3304 |
let d1_th0, d2_th0 = |
| 3305 |
float_interval_dmatan p_second f1_bound, |
| 3306 |
float_interval_ddmatan p_second f1_bound in |
| 3307 |
|
| 3308 |
let u_second2 th1 = |
| 3309 |
let i_tm = (rand o rator o concl) th1 in |
| 3310 |
let i_int = (Num.int_of_num o raw_dest_hash) i_tm in |
| 3311 |
let di1 = List.nth d1_bounds (i_int - 1) in |
| 3312 |
let th1 = MY_BETA_RULE th1 in |
| 3313 |
let lemma = INST[i_tm, i_var_num] u_second_lemma0 in |
| 3314 |
let u_second th1 = |
| 3315 |
let j_tm = (rand o rator o rator o rator o lhand) (concl th1) in |
| 3316 |
let j_int = (Num.int_of_num o raw_dest_hash) j_tm in |
| 3317 |
let dj1 = List.nth d1_bounds (j_int - 1) in |
| 3318 |
|
| 3319 |
(* partial2 *) |
| 3320 |
let u_th = |
| 3321 |
let ( * ), ( + ) = float_interval_mul p_second, float_interval_add p_second in |
| 3322 |
(d2_th0 * dj1) * di1 + d1_th0 * th1 in |
| 3323 |
|
| 3324 |
let int_tm = rand (concl u_th) in |
| 3325 |
let th0 = INST[j_tm, j_var_num; int_tm, int_var] lemma in |
| 3326 |
EQ_MP th0 u_th in |
| 3327 |
|
| 3328 |
let u_th = eval_all_n th1 true u_second in |
| 3329 |
let list_tm = (rand o rator o concl) u_th in |
| 3330 |
let lemma1 = INST[i_tm, i_var_num; list_tm, list_var_real_pair] u_second_lemma1 in |
| 3331 |
EQ_MP lemma1 u_th in |
| 3332 |
|
| 3333 |
let dd_th0 = eval_all_n dd1 false u_second2 in |
| 3334 |
let dd_list = (rand o rator o concl) dd_th0 in |
| 3335 |
let dd_th = GEN x_var (DISCH_ALL dd_th0) in |
| 3336 |
|
| 3337 |
let th = (MY_PROVE_HYP dd_th o MY_PROVE_HYP diff2_f1_th o |
| 3338 |
MY_PROVE_HYP cond_th o MY_PROVE_HYP f1_bound0 o |
| 3339 |
MY_PROVE_HYP bounds_th o MY_PROVE_HYP df_th o MY_PROVE_HYP domain_th o |
| 3340 |
INST[f1_tm, f_var; f_bounds_tm, f_bounds_var; |
| 3341 |
domain_tm, domain_var; y_tm, y_var; w_tm, w_var; |
| 3342 |
bounds_tm, bounds_var; d_bounds_list, d_bounds_list_var; |
| 3343 |
dd_list, dd_bounds_list_var] o |
| 3344 |
INST_TYPE[n_type_array.(n), nty]) MK_M_TAYLOR_MATAN' in |
| 3345 |
let eq_th = unary_beta_gen_eq f1_tm x_var matan_tm in |
| 3346 |
m_taylor_interval_norm th eq_th;; |
| 3347 |
|
| 3348 |
|
| 3349 |
end;; |
| 3350 |
|
| 3351 |
(* |
| 3352 |
|
| 3353 |
needs "Formal_ineqs/informal/informal_taylor.hl";; |
| 3354 |
needs "Formal_ineqs/verifier/m_verifier_build.hl";; |
| 3355 |
open M_verifier_build;; |
| 3356 |
|
| 3357 |
#install_printer Informal_float.print_ifloat;; |
| 3358 |
#install_printer Informal_interval.print_interval;; |
| 3359 |
|
| 3360 |
open Arith_float;; |
| 3361 |
open M_taylor_arith;; |
| 3362 |
open M_taylor;; |
| 3363 |
open More_float;; |
| 3364 |
|
| 3365 |
let x_list = mk_list ([mk_float (-1) 0; mk_float (-1) 0], `:real`);; |
| 3366 |
let z_list = mk_list ([mk_float 350 (-1); mk_float 350 (-1)], `:real`);; |
| 3367 |
|
| 3368 |
let x_inf = [Informal_float.mk_float (-1) (0); Informal_float.mk_float (-1) (0)];; |
| 3369 |
let y_inf = [Informal_float.mk_float (350) (-1); Informal_float.mk_float (350) (-1)];; |
| 3370 |
|
| 3371 |
let dom_th = mk_m_center_domain 2 5 x_list z_list;; |
| 3372 |
let dom_inf = Informal_taylor.mk_m_center_domain 5 x_inf y_inf;; |
| 3373 |
|
| 3374 |
let f1, f2 = mk_verification_functions_poly 5 `\x:real^2. x$1 + x$2 * x$1 pow 2`;; |
| 3375 |
let t_th = f1.taylor 5 5 dom_th;; |
| 3376 |
let t_inf = f2.Informal_verifier.taylor 5 5 dom_inf;; |
| 3377 |
|
| 3378 |
eval_m_taylor_pow 41 2 5 5 t_th;; |
| 3379 |
Informal_taylor.eval_m_taylor_pow 41 5 5 t_inf;; |
| 3380 |
|
| 3381 |
|
| 3382 |
eval_m_taylor_sqrt 2 5 5 t_th;; |
| 3383 |
eval_m_taylor_log 2 5 5 t_th;; |
| 3384 |
eval_m_taylor_exp 2 5 5 t_th;; |
| 3385 |
|
| 3386 |
(**************) |
| 3387 |
|
| 3388 |
let n = 2 and |
| 3389 |
p_lin = 5 and |
| 3390 |
p_second = 5 and |
| 3391 |
taylor1_th = t_th;; |
| 3392 |
|
| 3393 |
|
| 3394 |
let th2 = eval_m_taylor_matan 2 5 5 t_th;; |
| 3395 |
let t2_inf = Informal_taylor.eval_m_taylor_matan 5 5 t_inf;; |
| 3396 |
|
| 3397 |
let th3 = eval_m_taylor_sin2 2 5 5 th2;; |
| 3398 |
let t3_inf = Informal_taylor.eval_m_taylor_sin 5 5 t2_inf;; |
| 3399 |
|
| 3400 |
|
| 3401 |
(*****) |
| 3402 |
|
| 3403 |
open Informal_taylor;; |
| 3404 |
|
| 3405 |
let p_lin = 5 and |
| 3406 |
p_second = 5 and |
| 3407 |
ti = t_inf;; |
| 3408 |
|
| 3409 |
let n = ti.n;; |
| 3410 |
let ns = 1--n;; |
| 3411 |
let f1_bound = eval_m_taylor_bound p_second ti;; |
| 3412 |
let bounds = matan_interval p_lin ti.f;; |
| 3413 |
let u_bounds = |
| 3414 |
let dmatan = dmatan_interval p_lin in |
| 3415 |
dmatan (bounds);; |
| 3416 |
let df = |
| 3417 |
let ( * ) = mul_interval p_lin in |
| 3418 |
map (fun d -> u_bounds * d) ti.df;; |
| 3419 |
|
| 3420 |
|
| 3421 |
(************) |
| 3422 |
|
| 3423 |
open M_taylor;; |
| 3424 |
|
| 3425 |
let n = 2 and |
| 3426 |
p_lin = 5 and |
| 3427 |
p_second = 5 and |
| 3428 |
taylor1_th = t_th;; |
| 3429 |
|
| 3430 |
let domain_th, diff2_f1_th, lin1_th, second1_th = dest_m_taylor_thms n taylor1_th;; |
| 3431 |
let f1_tm = (rand o concl) diff2_f1_th;; |
| 3432 |
let domain_tm, y_tm, w_tm = dest_m_cell_domain (concl domain_th);; |
| 3433 |
let ty = type_of y_tm;; |
| 3434 |
|
| 3435 |
let x_var = mk_var ("x", ty) and |
| 3436 |
y_var = mk_var ("y", ty) and |
| 3437 |
w_var = mk_var ("w", ty) and |
| 3438 |
f_var = mk_var ("f", type_of f1_tm) and |
| 3439 |
domain_var = mk_var ("domain", type_of domain_tm);; |
| 3440 |
|
| 3441 |
let undisch = UNDISCH o SPEC x_var;; |
| 3442 |
|
| 3443 |
let f1_bound0 = eval_m_taylor_bound n p_second taylor1_th;; |
| 3444 |
let f1_bound = undisch f1_bound0;; |
| 3445 |
let f_bounds_tm = (rand o concl) f1_bound;; |
| 3446 |
|
| 3447 |
(* cond *) |
| 3448 |
let cond_th = check_interval_gt neg_one_float f_bounds_tm;; |
| 3449 |
|
| 3450 |
let _, bounds1_th, df1_th = m_lin_approx_components n lin1_th;; |
| 3451 |
|
| 3452 |
let bounds_th = float_interval_matan p_lin bounds1_th;; |
| 3453 |
let bounds_tm = (rand o concl) bounds_th;; |
| 3454 |
|
| 3455 |
(* partial_lemma' *) |
| 3456 |
let u_lemma0 = (INST[f1_tm, f_var; y_tm, y_var] o |
| 3457 |
INST_TYPE[n_type_array.(n), nty]) matan_partial_lemma';; |
| 3458 |
|
| 3459 |
let u_bounds = |
| 3460 |
float_interval_dmatan p_lin bounds1_th;; |
| 3461 |
|
| 3462 |
let u_lin th1 = |
| 3463 |
(* partial *) |
| 3464 |
let u_th = |
| 3465 |
let ( * ) = float_interval_mul p_lin in |
| 3466 |
u_bounds * th1 in |
| 3467 |
let int_tm = rand (concl u_th) in |
| 3468 |
let i_tm = (rand o rator o rator o lhand) (concl th1) in |
| 3469 |
let th0 = INST[i_tm, i_var_num; int_tm, int_var] u_lemma0 in |
| 3470 |
EQ_MP th0 u_th;; |
| 3471 |
|
| 3472 |
let df_th = eval_all_n df1_th true u_lin;; |
| 3473 |
let d_bounds_list = (rand o rator o concl) df_th;; |
| 3474 |
*) |
| 3475 |
|
| 3476 |
|
| 3477 |
|