1 needs "../formal_lp/formal_interval/lin_approx.hl";;
\r
3 (* Explicit formula (float) for inv(&2) *)
\r
6 let one_float_eq_one = FLOAT_TO_NUM_CONV one_float in
\r
7 let inv2_eq_lemma = prove(`interval_arith (&2 * x) (&1, &1) ==> inv (&2) = x`,
\r
8 REWRITE_TAC[interval_arith] THEN CONV_TAC REAL_FIELD) in
\r
9 let half_tm = (fst o dest_pair o rand o concl) (float_interval_inv 1 two_interval) in
\r
10 let half_interval = mk_const_interval half_tm in
\r
11 let mul_th = REWRITE_RULE[one_float_eq_one] (float_interval_mul 2 two_interval half_interval) in
\r
12 MATCH_MP inv2_eq_lemma mul_th;;
\r
14 let float_inv2 = rand (concl float_inv2_th);;
\r
15 let inv2_interval = mk_const_interval float_inv2;;
\r
17 let INTERVAL_IMP_HI = (RULE o prove)(`interval_arith x (lo, hi) ==> x <= hi`,
\r
18 REWRITE_TAC[interval_arith] THEN REAL_ARITH_TAC);;
\r
20 let interval_imp_hi int_th =
\r
21 let lhs, bounds = dest_comb (concl int_th) in
\r
22 let x_tm, (lo_tm, hi_tm) = rand lhs, dest_pair bounds in
\r
23 let th0 = INST[x_tm, x_var_real; lo_tm, lo_var_real; hi_tm, hi_var_real] INTERVAL_IMP_HI in
\r
24 MY_PROVE_HYP int_th th0;;
\r
27 (*****************************)
\r
30 let dest_cell_domain tm =
\r
31 let lhs, w_tm = dest_comb tm in
\r
32 let lhs2, z_tm = dest_comb lhs in
\r
33 let lhs3, y_tm = dest_comb lhs2 in
\r
34 rand lhs3, y_tm, z_tm, w_tm;;
\r
37 (******************************************)
\r
39 let CELL_DOMAIN_IMP_INTERVAL_ARITH = prove(`cell_domain x y z w ==> interval_arith y (x, z)`,
\r
40 REWRITE_TAC[cell_domain; interval_arith] THEN REAL_ARITH_TAC);;
\r
43 let MK_CELL_DOMAIN_0' = (UNDISCH_ALL o PURE_REWRITE_RULE[GSYM IMP_IMP] o prove)
\r
44 (`(x <= y <=> T) /\ (y <= z <=> T) /\ y - x <= w1 /\ z - y <= w2 /\ (w1 <= w <=> T) /\ (w2 <= w <=> T) ==>
\r
45 cell_domain x y z w`,
\r
46 SIMP_TAC[cell_domain] THEN REAL_ARITH_TAC);;
\r
49 let MK_CELL_DOMAIN' = (UNDISCH_ALL o PURE_REWRITE_RULE[GSYM IMP_IMP] o prove)
\r
50 (`(x <= y <=> T) /\ (y <= z <=> T) /\ y - x <= w1 /\ z - y <= w2 /\ max w1 w2 = w ==>
\r
51 cell_domain x y z w`, REWRITE_TAC[cell_domain] THEN REAL_ARITH_TAC);;
\r
54 let mk_cell_domain0 pp x_tm y_tm z_tm w_tm =
\r
55 let xy_th = float_le x_tm y_tm and
\r
56 yz_th = float_le y_tm z_tm in
\r
57 let yx_w1 = float_sub_hi pp y_tm x_tm and
\r
58 zy_w2 = float_sub_hi pp z_tm y_tm in
\r
59 let w1_tm = (rand o concl) yx_w1 and
\r
60 w2_tm = (rand o concl) zy_w2 in
\r
61 let w1w = float_le w1_tm w_tm and
\r
62 w2w = float_le w2_tm w_tm in
\r
63 let th0 = INST[x_tm, x_var_real; y_tm, y_var_real; z_tm, z_var_real;
\r
64 w_tm, w_var_real; w1_tm, w1_var_real; w2_tm, w2_var_real] MK_CELL_DOMAIN_0' in
\r
65 (MY_PROVE_HYP xy_th o MY_PROVE_HYP yz_th o MY_PROVE_HYP yx_w1 o MY_PROVE_HYP zy_w2 o
\r
66 MY_PROVE_HYP w1w o MY_PROVE_HYP w2w) th0;;
\r
69 let mk_cell_domain pp x_tm y_tm z_tm =
\r
70 let w1_th = float_sub_hi pp y_tm x_tm and
\r
71 w2_th = float_sub_hi pp z_tm y_tm in
\r
72 let w1_tm = (rand o concl) w1_th and
\r
73 w2_tm = (rand o concl) w2_th in
\r
74 let max_th = float_max w1_tm w2_tm in
\r
75 let w_tm = (rand o concl) max_th in
\r
76 let x_le_y = float_le x_tm y_tm and
\r
77 y_le_z = float_le y_tm z_tm in
\r
78 let th0 = INST[x_tm, x_var_real; y_tm, y_var_real; z_tm, z_var_real;
\r
79 w_tm, w_var_real; w1_tm, w1_var_real; w2_tm, w2_var_real] MK_CELL_DOMAIN' in
\r
80 (MY_PROVE_HYP x_le_y o MY_PROVE_HYP y_le_z o
\r
81 MY_PROVE_HYP w1_th o MY_PROVE_HYP w2_th o MY_PROVE_HYP max_th) th0;;
\r
86 (* TODO: remove formal computation of y *)
\r
87 let mk_center_domain pp x_tm z_tm =
\r
88 let y0_tm = (rand o concl) (float_add_hi pp x_tm z_tm) in
\r
89 let y_tm = (rand o concl) (float_mul_eq float_inv2 y0_tm) in
\r
90 mk_cell_domain pp x_tm y_tm z_tm;;
\r
94 let x_tm = mk_float 1 50;;
\r
95 let z_tm = mk_float 4 50;;
\r
97 let domain_th = mk_center_domain 2 x_tm z_tm;;
\r
99 let x_tm, y_tm, z_tm, w_tm = dest_cell_domain (concl domain_th);;
\r
100 mk_cell_domain 2 x_tm y_tm z_tm;;
\r
101 mk_cell_domain0 2 x_tm y_tm z_tm w_tm;;
\r
105 (***************************************************)
\r
106 (* Elementary functions and their taylor intervals *)
\r
107 (***************************************************)
\r
110 (*****************************)
\r
113 let TAYLOR_X' = RULE taylor_x;;
\r
116 let eval_taylor_x domain_th =
\r
117 let x_tm, y_tm, z_tm, w_tm = dest_cell_domain (concl domain_th) in
\r
118 let th0 = INST[x_tm, x_var_real; y_tm, y_var_real; z_tm, z_var_real; w_tm, w_var_real] TAYLOR_X' in
\r
119 MY_PROVE_HYP domain_th th0;;
\r
123 eval_taylor_x domain_th;;
\r
126 (********************************)
\r
129 let TAYLOR_CONST' = RULE taylor_const;;
\r
130 let eval_taylor_const domain_th c_tm =
\r
131 let x_tm, y_tm, z_tm, w_tm = dest_cell_domain (concl domain_th) in
\r
132 (MY_PROVE_HYP domain_th o
\r
133 INST[c_tm, c_var_real; x_tm, x_var_real; y_tm, y_var_real;
\r
134 z_tm, z_var_real; w_tm, w_var_real]) TAYLOR_CONST';;
\r
137 let TAYLOR_CONST_INTERVAL' = (RULE o prove)
\r
138 (`cell_domain x y z w ==> interval_arith c bounds ==>
\r
139 taylor_interval (\x. c) x y z w bounds (&0, &0) (&0, &0)`,
\r
140 REPEAT DISCH_TAC THEN
\r
141 MP_TAC (SPEC_ALL taylor_const) THEN ASM_SIMP_TAC[taylor_interval; lin_approx_eq]);;
\r
143 let eval_taylor_const_interval int_th domain_th =
\r
144 let x_tm, y_tm, z_tm, w_tm = dest_cell_domain (concl domain_th) in
\r
145 let lhs, bounds = dest_comb (concl int_th) in
\r
146 let c_tm = rand lhs in
\r
147 (MY_PROVE_HYP int_th o MY_PROVE_HYP domain_th o
\r
148 INST[c_tm, c_var_real; bounds, bounds_var; x_tm, x_var_real; y_tm, y_var_real;
\r
149 z_tm, z_var_real; w_tm, w_var_real]) TAYLOR_CONST_INTERVAL';;
\r
153 eval_taylor_const domain_th `&3`;;
\r
156 (***********************************)
\r
159 let taylor_atn = prove(`cell_domain x y z w ==>
\r
160 bounded_on_int (\x. (-- &2 * x) / (&1 + x pow 2) pow 2) (x,z) dd_bounds ==>
\r
161 lin_approx atn y f_bounds df_bounds ==>
\r
162 taylor_interval atn x y z w f_bounds df_bounds dd_bounds`,
\r
163 REWRITE_TAC[cell_domain; taylor_interval; real_div; REAL_INV_POW] THEN REPEAT DISCH_TAC THEN
\r
164 ASM_REWRITE_TAC[] THEN
\r
165 MATCH_MP_TAC second_derivative_atn_bounds THEN ASM_REWRITE_TAC[]);;
\r
167 let TAYLOR_ATN' = (UNDISCH_ALL o REWRITE_RULE[REAL_POW_2]) taylor_atn;;
\r
170 let eval_taylor_atn pp domain_th =
\r
171 let x_tm, y_tm, z_tm, w_tm = dest_cell_domain (concl domain_th) in
\r
172 let atn_lin = eval_lin_approx_atn pp y_tm in
\r
173 let _, _, f_bounds, df_bounds = dest_lin_approx (concl atn_lin) in
\r
176 let x_th = ASSUME (mk_interval x_var_real (mk_pair (x_tm, z_tm))) and
\r
177 ( * ) = float_interval_mul pp and
\r
178 (+) = float_interval_add pp and
\r
179 (/) = float_interval_div pp in
\r
180 let x2_1 = one_interval + x_th * x_th in
\r
181 mk_bounded_on_int ((neg_two_interval * x_th) / (x2_1 * x2_1)) in
\r
183 let dd_bounds = rand (concl ddf_th) in
\r
184 (MY_PROVE_HYP domain_th o MY_PROVE_HYP atn_lin o MY_PROVE_HYP ddf_th o
\r
185 INST[x_tm, x_var_real; y_tm, y_var_real; z_tm, z_var_real; w_tm, w_var_real;
\r
186 dd_bounds, dd_bounds_var; f_bounds, f_bounds_var; df_bounds, df_bounds_var]) TAYLOR_ATN';;
\r
191 let domain_th = mk_center_domain 5 (mk_float 1 50) (mk_float 4 50);;
\r
193 eval_taylor_atn pp domain_th;;
\r
198 (***********************************)
\r
201 let taylor_inv = prove(`cell_domain x y z w ==>
\r
202 interval_not_zero (x,z) ==>
\r
203 bounded_on_int (\x. &2 * inv (x pow 3)) (x,z) dd_bounds ==>
\r
204 lin_approx inv y f_bounds df_bounds ==>
\r
205 taylor_interval inv x y z w f_bounds df_bounds dd_bounds`,
\r
206 REWRITE_TAC[cell_domain; taylor_interval] THEN REPEAT DISCH_TAC THEN
\r
207 ASM_REWRITE_TAC[] THEN
\r
208 MATCH_MP_TAC (REWRITE_RULE[IMP_IMP] second_derivative_inv_bounds) THEN ASM_REWRITE_TAC[]);;
\r
210 let TAYLOR_INV' = (UNDISCH_ALL o REWRITE_RULE[GSYM real_div; REAL_ARITH `x pow 3 = x * x * x`]) taylor_inv;;
\r
213 let eval_taylor_inv pp domain_th =
\r
214 let x_tm, y_tm, z_tm, w_tm = dest_cell_domain (concl domain_th) in
\r
215 let int_tm = mk_pair (x_tm, z_tm) in
\r
216 let lin_th = eval_lin_approx_inv pp y_tm in
\r
217 let _, _, f_bounds, df_bounds = dest_lin_approx (concl lin_th) in
\r
218 let cond_th = check_interval_not_zero int_tm in
\r
221 let x_th = ASSUME (mk_interval x_var_real (mk_pair (x_tm, z_tm))) and
\r
222 ( * ) = float_interval_mul pp and
\r
223 (/) = float_interval_div pp in
\r
224 mk_bounded_on_int (two_interval / (x_th * (x_th * x_th))) in
\r
226 let dd_bounds = rand (concl ddf_th) in
\r
227 (MY_PROVE_HYP domain_th o MY_PROVE_HYP lin_th o MY_PROVE_HYP ddf_th o MY_PROVE_HYP cond_th o
\r
228 INST[x_tm, x_var_real; y_tm, y_var_real; z_tm, z_var_real; w_tm, w_var_real;
\r
229 dd_bounds, dd_bounds_var; f_bounds, f_bounds_var; df_bounds, df_bounds_var]) TAYLOR_INV';;
\r
234 let domain_th = mk_center_domain 5 (mk_float 1 50) (mk_float 4 50);;
\r
236 eval_taylor_inv pp domain_th;;
\r
240 (***********************************)
\r
241 (* f(x) = sqrt x *)
\r
243 let taylor_sqrt = prove(`cell_domain x y z w ==>
\r
244 interval_pos (x,z) ==>
\r
245 bounded_on_int (\x. --inv (&4 * sqrt (x pow 3))) (x,z) dd_bounds ==>
\r
246 lin_approx sqrt y f_bounds df_bounds ==>
\r
247 taylor_interval sqrt x y z w f_bounds df_bounds dd_bounds`,
\r
248 REWRITE_TAC[cell_domain; taylor_interval] THEN REPEAT DISCH_TAC THEN
\r
249 ASM_REWRITE_TAC[] THEN
\r
250 MATCH_MP_TAC (REWRITE_RULE[IMP_IMP] second_derivative_sqrt_bounds) THEN ASM_REWRITE_TAC[]);;
\r
252 let TAYLOR_SQRT' = (UNDISCH_ALL o REWRITE_RULE[REAL_ARITH `x pow 3 = x * x * x`]) taylor_sqrt;;
\r
253 let four_interval = mk_float_interval_small_num 4;;
\r
256 let eval_taylor_sqrt pp domain_th =
\r
257 let x_tm, y_tm, z_tm, w_tm = dest_cell_domain (concl domain_th) in
\r
258 let int_tm = mk_pair (x_tm, z_tm) in
\r
259 let lin_th = eval_lin_approx_sqrt pp y_tm in
\r
260 let _, _, f_bounds, df_bounds = dest_lin_approx (concl lin_th) in
\r
261 let cond_th = check_interval_pos int_tm in
\r
264 let x_th = ASSUME (mk_interval x_var_real (mk_pair (x_tm, z_tm))) and
\r
265 ( * ) = float_interval_mul pp and
\r
266 sqrt = float_interval_sqrt pp and
\r
267 inv = float_interval_inv pp and
\r
268 neg = float_interval_neg in
\r
269 mk_bounded_on_int (neg (inv (four_interval * sqrt (x_th * (x_th * x_th))))) in
\r
271 let dd_bounds = rand (concl ddf_th) in
\r
272 (MY_PROVE_HYP domain_th o MY_PROVE_HYP lin_th o MY_PROVE_HYP ddf_th o MY_PROVE_HYP cond_th o
\r
273 INST[x_tm, x_var_real; y_tm, y_var_real; z_tm, z_var_real; w_tm, w_var_real;
\r
274 dd_bounds, dd_bounds_var; f_bounds, f_bounds_var; df_bounds, df_bounds_var]) TAYLOR_SQRT';;
\r
279 let domain_th = mk_center_domain 5 (mk_float 1 50) (mk_float 4 50);;
\r
281 eval_taylor_sqrt pp domain_th;;
\r
285 (***********************************)
\r
288 let iabs_lt1_lemma =
\r
289 (GEN_REWRITE_RULE (RAND_CONV o LAND_CONV o RAND_CONV) [GSYM (FLOAT_TO_NUM_CONV one_float)] o prove)
\r
290 (`iabs int < &1 <=> (iabs int < &1 <=> T)`, REWRITE_TAC[]);;
\r
292 let taylor_acs = prove(`cell_domain x y z w ==>
\r
293 iabs (x,z) < &1 ==>
\r
294 bounded_on_int (\x. --(x / sqrt ((&1 - x * x) pow 3))) (x,z) dd_bounds ==>
\r
295 lin_approx acs y f_bounds df_bounds ==>
\r
296 taylor_interval acs x y z w f_bounds df_bounds dd_bounds`,
\r
297 REWRITE_TAC[cell_domain; taylor_interval] THEN REPEAT DISCH_TAC THEN
\r
298 ASM_REWRITE_TAC[] THEN
\r
299 MATCH_MP_TAC (REWRITE_RULE[IMP_IMP] second_derivative_acs_bounds) THEN ASM_REWRITE_TAC[]);;
\r
303 PURE_ONCE_REWRITE_RULE[iabs_lt1_lemma] o
\r
304 REWRITE_RULE[REAL_ARITH `x pow 3 = x * x * x`]) taylor_acs;;
\r
307 let eval_taylor_acs pp domain_th =
\r
308 let x_tm, y_tm, z_tm, w_tm = dest_cell_domain (concl domain_th) in
\r
309 let int_tm = mk_pair (x_tm, z_tm) in
\r
310 let lin_th = eval_lin_approx_acs pp y_tm in
\r
311 let _, _, f_bounds, df_bounds = dest_lin_approx (concl lin_th) in
\r
312 let cond_th = check_interval_iabs int_tm one_float in
\r
315 let x_th = ASSUME (mk_interval x_var_real (mk_pair (x_tm, z_tm))) and
\r
316 ( * ) = float_interval_mul pp and
\r
317 (-) = float_interval_sub pp and
\r
318 (/) = float_interval_div pp and
\r
319 sqrt = float_interval_sqrt pp and
\r
320 neg = float_interval_neg in
\r
321 let x2_1 = one_interval - x_th * x_th in
\r
322 mk_bounded_on_int (neg (x_th / sqrt (x2_1 * (x2_1 * x2_1)))) in
\r
324 let dd_bounds = rand (concl ddf_th) in
\r
325 (MY_PROVE_HYP domain_th o MY_PROVE_HYP lin_th o MY_PROVE_HYP ddf_th o MY_PROVE_HYP cond_th o
\r
326 INST[x_tm, x_var_real; y_tm, y_var_real; z_tm, z_var_real; w_tm, w_var_real;
\r
327 dd_bounds, dd_bounds_var; f_bounds, f_bounds_var; df_bounds, df_bounds_var]) TAYLOR_ACS';;
\r
332 let domain_th1 = mk_center_domain 5 (mk_float 1 49) (mk_float 8 49);;
\r
333 let domain_th2 = mk_center_domain 5 (mk_float (-5) 49) (mk_float 1 49);;
\r
335 eval_taylor_acs pp domain_th1;;
\r
336 eval_taylor_atn pp domain_th1;;
\r
337 eval_taylor_inv pp domain_th1;;
\r
338 eval_taylor_sqrt pp domain_th1;;
\r
340 eval_taylor_acs pp domain_th2;;
\r
341 eval_taylor_atn pp domain_th2;;
\r
342 eval_taylor_inv pp domain_th2;;
\r
343 eval_taylor_sqrt pp domain_th2;;
\r
347 (***********************************************************)
\r
350 (***********************************)
\r
351 (* Taylor bounds *)
\r
354 let dest_taylor_interval tm =
\r
355 let lhs, dd_bounds = dest_comb tm in
\r
356 let lhs, df_bounds = dest_comb lhs in
\r
357 let lhs, f_bounds = dest_comb lhs in
\r
358 let lhs, w_tm = dest_comb lhs in
\r
359 let lhs, z_tm = dest_comb lhs in
\r
360 let lhs, y_tm = dest_comb lhs in
\r
361 let lhs, x_tm = dest_comb lhs in
\r
362 rand lhs, x_tm, y_tm, z_tm, w_tm, f_bounds, df_bounds, dd_bounds;;
\r
365 (****************************)
\r
368 let TAYLOR_F_BOUNDS' = (RULE o REWRITE_RULE[float_inv2_th]) taylor_f_bounds;;
\r
371 let eval_taylor_f_bounds pp th =
\r
372 let f_tm, x_tm, y_tm, z_tm, w_tm, f_bounds, df_bounds, dd_bounds = dest_taylor_interval (concl th) in
\r
373 let f_lo, f_hi = dest_pair f_bounds in
\r
374 let iabs_df_th = float_iabs df_bounds and
\r
375 iabs_dd_th = float_iabs dd_bounds in
\r
376 let df_tm = (rand o concl) iabs_df_th and
\r
377 dd_tm = (rand o concl) iabs_dd_th in
\r
380 let df = mk_refl_ineq df_tm and
\r
381 inv2 = mk_refl_ineq float_inv2 and
\r
382 ( * ) = mul_ineq_pos_const_hi pp and
\r
383 ( + ) = add_ineq_hi pp in
\r
384 w_tm * (df + w_tm * (dd_tm * inv2)) in
\r
386 let t_tm = (rand o concl) error_th in
\r
387 let lo_th = float_sub_lo pp f_lo t_tm and
\r
388 hi_th = float_add_hi pp f_hi t_tm in
\r
389 let lo_tm = (lhand o concl) lo_th and
\r
390 hi_tm = (rand o concl) hi_th in
\r
392 (MY_PROVE_HYP lo_th o MY_PROVE_HYP hi_th o MY_PROVE_HYP error_th o
\r
393 MY_PROVE_HYP iabs_df_th o MY_PROVE_HYP iabs_dd_th o MY_PROVE_HYP th o
\r
394 INST[dd_bounds, dd_bounds_var; dd_tm, dd_var_real; df_bounds, df_bounds_var;
\r
395 df_tm, df_var_real; t_tm, t_var_real;
\r
396 lo_tm, lo_var_real; f_lo, f_lo_var;
\r
397 w_tm, w_var_real; f_hi, f_hi_var; hi_tm, hi_var_real;
\r
398 f_tm, f_var_fun; x_tm, x_var_real;
\r
399 y_tm, y_var_real; z_tm, z_var_real]) TAYLOR_F_BOUNDS';;
\r
404 let domain_th = mk_center_domain pp one_float two_float;;
\r
405 let th = eval_taylor_atn pp domain_th;;
\r
406 eval_taylor_f_bounds pp th;;
\r
408 test 1000 (eval_taylor_f_bounds pp) th;;
\r
412 (****************************)
\r
416 let TAYLOR_DF_BOUNDS' = RULE taylor_df_bounds;;
\r
418 let eval_taylor_df_bounds pp th =
\r
419 let f_tm, x_tm, y_tm, z_tm, w_tm, f_bounds, df_bounds, dd_bounds = dest_taylor_interval (concl th) in
\r
420 let df_lo, df_hi = dest_pair df_bounds in
\r
421 let iabs_dd_th = float_iabs dd_bounds in
\r
422 let dd_tm = (rand o concl) iabs_dd_th in
\r
423 let w_dd_hi = float_mul_hi pp w_tm dd_tm in
\r
425 let lo_th = sub_ineq_lo pp (mk_refl_ineq df_lo) w_dd_hi and
\r
426 hi_th = add_ineq_hi pp (mk_refl_ineq df_hi) w_dd_hi in
\r
427 let lo_tm = (lhand o concl) lo_th and
\r
428 hi_tm = (rand o concl) hi_th in
\r
430 (MY_PROVE_HYP lo_th o MY_PROVE_HYP hi_th o MY_PROVE_HYP th o MY_PROVE_HYP iabs_dd_th o
\r
431 INST[dd_bounds, dd_bounds_var; dd_tm, dd_var_real; f_bounds, f_bounds_var;
\r
432 lo_tm, lo_var_real; df_lo, df_lo_var;
\r
433 w_tm, w_var_real; df_hi, df_hi_var; hi_tm, hi_var_real;
\r
434 f_tm, f_var_fun; x_tm, x_var_real;
\r
435 y_tm, y_var_real; z_tm, z_var_real]) TAYLOR_DF_BOUNDS';;
\r
440 let th = eval_taylor_atn pp domain_th;;
\r
441 eval_taylor_df_bounds pp th;;
\r
444 (**************************************************)
\r
445 (* mk_taylor_interval_th, dest_taylor_interval_th *)
\r
447 let TAYLOR_INTERVAL_EQ' = (RULE o prove)(`taylor_interval f x y z w f_bounds df_bounds dd_bounds <=>
\r
448 cell_domain x y z w /\ lin_approx f y f_bounds df_bounds /\
\r
449 has_bounded_second_derivative f (x,z) dd_bounds`,
\r
450 SIMP_TAC[cell_domain; taylor_interval; CONJ_ACI]);;
\r
452 let MK_TAYLOR_INTERVAL' = (RULE o prove)(`cell_domain x y z w /\
\r
453 lin_approx f y f_bounds df_bounds /\
\r
454 has_bounded_second_derivative f (x,z) dd_bounds ==>
\r
455 taylor_interval f x y z w f_bounds df_bounds dd_bounds`,
\r
456 SIMP_TAC[cell_domain; taylor_interval]);;
\r
459 let dest_taylor_interval_th th =
\r
460 let f_tm, x_tm, y_tm, z_tm, w_tm, f_bounds, df_bounds, dd_bounds = dest_taylor_interval (concl th) in
\r
461 let th0 = INST[f_tm, f_var_fun; x_tm, x_var_real; y_tm, y_var_real; z_tm, z_var_real;
\r
462 w_tm, w_var_real; f_bounds, f_bounds_var;
\r
463 df_bounds, df_bounds_var; dd_bounds, dd_bounds_var] TAYLOR_INTERVAL_EQ' in
\r
464 let [domain; approx; second] = CONJUNCTS (EQ_MP th0 th) in
\r
465 domain, approx, second;;
\r
469 let mk_taylor_interval_th domain_th approx_th second_th =
\r
470 let x_tm, y_tm, z_tm, w_tm = dest_cell_domain (concl domain_th) in
\r
471 let f_tm, _, f_bounds, df_bounds = dest_lin_approx (concl approx_th) in
\r
472 let dd_bounds = rand (concl second_th) in
\r
473 let th0 = INST[f_tm, f_var_fun; x_tm, x_var_real; y_tm, y_var_real; z_tm, z_var_real;
\r
474 w_tm, w_var_real; f_bounds, f_bounds_var;
\r
475 df_bounds, df_bounds_var; dd_bounds, dd_bounds_var] MK_TAYLOR_INTERVAL' in
\r
476 (MY_PROVE_HYP approx_th o MY_PROVE_HYP domain_th o MY_PROVE_HYP second_th) th0;;
\r
481 let th = eval_taylor_atn 5 domain_th;;
\r
482 let domain_th, approx_th, second_th = dest_taylor_interval_th th;;
\r
483 mk_taylor_interval_th domain_th approx_th second_th;;
\r
487 (**************************************)
\r
488 (* has_bounded_second_derivative_dest *)
\r
490 let HAS_BOUNDED_SECOND_DERIVATIVE_EQ' = SPEC_ALL has_bounded_second_derivative;;
\r
493 let dest_has_bounded_second_derivative tm =
\r
494 let lhs, dd_bounds = dest_comb tm in
\r
495 let lhs2, int_tm = dest_comb lhs in
\r
496 rand lhs2, int_tm, dd_bounds;;
\r
499 let dest_has_bounded_second_derivative_th th =
\r
500 let f_tm, int_tm, dd_bounds = dest_has_bounded_second_derivative (concl th) in
\r
501 let th0 = INST[f_tm, f_var_fun; int_tm, int_var;
\r
502 dd_bounds, dd_bounds_var] HAS_BOUNDED_SECOND_DERIVATIVE_EQ' in
\r
503 let [diff_th; bounded_th] = CONJUNCTS (EQ_MP th0 th) in
\r
504 diff_th, bounded_th;;
\r
508 let diff_th, bounded_th = dest_has_bounded_second_derivative_th second_th;;
\r
511 (********************************************)
\r
514 (******************************)
\r
515 (* Taylor interval arithmetic *)
\r
516 (******************************)
\r
519 (**************************************)
\r
520 let taylor_interval_tm = `taylor_interval`;;
\r
522 let taylor_interval_norm th eq_th =
\r
523 let lhs1, d2f = dest_comb (concl th) in
\r
524 let lhs2, d1f = dest_comb lhs1 in
\r
525 let lhs3, d0f = dest_comb lhs2 in
\r
526 let lhs4, w = dest_comb lhs3 in
\r
527 let lhs5, z = dest_comb lhs4 in
\r
528 let lhs6, y = dest_comb lhs5 in
\r
529 let x = rand lhs6 in
\r
530 let th0 = AP_TERM taylor_interval_tm eq_th in
\r
531 let th1 = (AP_THM (AP_THM (AP_THM (AP_THM (AP_THM (AP_THM (AP_THM th0 x) y) z) w) d0f) d1f) d2f) in
\r
535 (*************************************)
\r
536 (* taylor_interval_neg *)
\r
537 let TAYLOR_INTERVAL_NEG' = (UNDISCH_ALL o prove)
\r
538 (`cell_domain x y z w ==>
\r
539 lin_approx (\x. -- (f x)) y bounds d_bounds ==>
\r
540 nth_diff_strong_int 2 (x,z) f ==>
\r
541 bounded_on_int (\x. -- nth_derivative 2 f x) (x,z) dd_bounds ==>
\r
542 taylor_interval (\x. -- (f x)) x y z w bounds d_bounds dd_bounds`,
\r
543 SIMP_TAC[taylor_interval; cell_domain] THEN ONCE_REWRITE_TAC[REAL_ARITH `--a = (-- (&1)) * a`] THEN
\r
544 REPEAT STRIP_TAC THEN
\r
545 ASM_SIMP_TAC[second_derivative_scale_bounds]);;
\r
548 let taylor_interval_neg th1 =
\r
549 let domain_th, approx1_th, second1_th = dest_taylor_interval_th th1 in
\r
550 let diff1_th, dd1_th = dest_has_bounded_second_derivative_th second1_th in
\r
552 let approx_th = lin_approx_neg approx1_th in
\r
553 let dd_th = bounded_on_int_neg dd1_th in
\r
555 let x_tm, y_tm, z_tm, w_tm = dest_cell_domain (concl domain_th) and
\r
556 f_tm = (rand o concl) diff1_th and
\r
557 _, _, bounds, d_bounds = dest_lin_approx (concl approx_th) and
\r
558 dd_bounds = (rand o concl) dd_th in
\r
560 let th0 = (MY_PROVE_HYP domain_th o MY_PROVE_HYP approx_th o
\r
561 MY_PROVE_HYP diff1_th o MY_PROVE_HYP dd_th o
\r
562 INST[x_tm, x_var_real; y_tm, y_var_real; z_tm, z_var_real; w_tm, w_var_real;
\r
564 bounds, bounds_var; d_bounds, d_bounds_var; dd_bounds, dd_bounds_var])
\r
565 TAYLOR_INTERVAL_NEG' in
\r
566 let eq_th = unary_beta_eq f_tm neg_op_real in
\r
567 taylor_interval_norm th0 eq_th;;
\r
571 let th1 = eval_taylor_x domain_th and
\r
572 th2 = eval_taylor_sqrt pp domain_th;;
\r
573 taylor_interval_neg th1;;
\r
574 taylor_interval_neg th2;;
\r
579 (*************************************)
\r
580 (* taylor_interval_add *)
\r
582 let TAYLOR_INTERVAL_ADD' = (UNDISCH_ALL o prove)
\r
583 (`cell_domain x y z w ==>
\r
584 lin_approx (\x. f x + g x) y bounds d_bounds ==>
\r
585 nth_diff_strong_int 2 (x,z) f ==>
\r
586 nth_diff_strong_int 2 (x,z) g ==>
\r
587 bounded_on_int (\x. nth_derivative 2 f x + nth_derivative 2 g x) (x,z) dd_bounds ==>
\r
588 taylor_interval (\x. f x + g x) x y z w bounds d_bounds dd_bounds`,
\r
589 SIMP_TAC[taylor_interval; cell_domain] THEN REPEAT STRIP_TAC THEN
\r
590 ASM_SIMP_TAC[second_derivative_add_bounds]);;
\r
593 let taylor_interval_add pp th1 th2 =
\r
594 let domain_th, approx1_th, second1_th = dest_taylor_interval_th th1 and
\r
595 _, approx2_th, second2_th = dest_taylor_interval_th th2 in
\r
596 let diff1_th, dd1_th = dest_has_bounded_second_derivative_th second1_th and
\r
597 diff2_th, dd2_th = dest_has_bounded_second_derivative_th second2_th in
\r
599 let approx_th = lin_approx_add pp approx1_th approx2_th in
\r
601 let (+) = bounded_on_int_add pp in
\r
604 let x_tm, y_tm, z_tm, w_tm = dest_cell_domain (concl domain_th) and
\r
605 f_tm = (rand o concl) diff1_th and
\r
606 g_tm = (rand o concl) diff2_th and
\r
607 _, _, bounds, d_bounds = dest_lin_approx (concl approx_th) and
\r
608 dd_bounds = (rand o concl) dd_th in
\r
610 let th0 = (MY_PROVE_HYP domain_th o MY_PROVE_HYP approx_th o
\r
611 MY_PROVE_HYP diff1_th o MY_PROVE_HYP diff2_th o MY_PROVE_HYP dd_th o
\r
612 INST[x_tm, x_var_real; y_tm, y_var_real; z_tm, z_var_real; w_tm, w_var_real;
\r
613 f_tm, f_var_fun; g_tm, g_var_fun;
\r
614 bounds, bounds_var; d_bounds, d_bounds_var; dd_bounds, dd_bounds_var])
\r
615 TAYLOR_INTERVAL_ADD' in
\r
616 let eq_th = binary_beta_eq f_tm g_tm add_op_real in
\r
617 taylor_interval_norm th0 eq_th;;
\r
622 let th1 = eval_taylor_x domain_th and
\r
623 th2 = eval_taylor_sqrt pp domain_th;;
\r
624 taylor_interval_add pp th1 th2;;
\r
628 (*************************************)
\r
629 (* taylor_interval_sub *)
\r
631 let TAYLOR_INTERVAL_SUB' = (UNDISCH_ALL o prove)
\r
632 (`cell_domain x y z w ==>
\r
633 lin_approx (\x. f x - g x) y bounds d_bounds ==>
\r
634 nth_diff_strong_int 2 (x,z) f ==>
\r
635 nth_diff_strong_int 2 (x,z) g ==>
\r
636 bounded_on_int (\x. nth_derivative 2 f x - nth_derivative 2 g x) (x,z) dd_bounds ==>
\r
637 taylor_interval (\x. f x - g x) x y z w bounds d_bounds dd_bounds`,
\r
638 SIMP_TAC[taylor_interval; cell_domain] THEN REPEAT STRIP_TAC THEN
\r
639 ASM_SIMP_TAC[second_derivative_sub_bounds]);;
\r
642 let taylor_interval_sub pp th1 th2 =
\r
643 let domain_th, approx1_th, second1_th = dest_taylor_interval_th th1 and
\r
644 _, approx2_th, second2_th = dest_taylor_interval_th th2 in
\r
645 let diff1_th, dd1_th = dest_has_bounded_second_derivative_th second1_th and
\r
646 diff2_th, dd2_th = dest_has_bounded_second_derivative_th second2_th in
\r
648 let approx_th = lin_approx_sub pp approx1_th approx2_th in
\r
650 let (-) = bounded_on_int_sub pp in
\r
653 let x_tm, y_tm, z_tm, w_tm = dest_cell_domain (concl domain_th) and
\r
654 f_tm = (rand o concl) diff1_th and
\r
655 g_tm = (rand o concl) diff2_th and
\r
656 _, _, bounds, d_bounds = dest_lin_approx (concl approx_th) and
\r
657 dd_bounds = (rand o concl) dd_th in
\r
659 let th0 = (MY_PROVE_HYP domain_th o MY_PROVE_HYP approx_th o
\r
660 MY_PROVE_HYP diff1_th o MY_PROVE_HYP diff2_th o MY_PROVE_HYP dd_th o
\r
661 INST[x_tm, x_var_real; y_tm, y_var_real; z_tm, z_var_real; w_tm, w_var_real;
\r
662 f_tm, f_var_fun; g_tm, g_var_fun;
\r
663 bounds, bounds_var; d_bounds, d_bounds_var; dd_bounds, dd_bounds_var])
\r
664 TAYLOR_INTERVAL_SUB' in
\r
665 let eq_th = binary_beta_eq f_tm g_tm sub_op_real in
\r
666 taylor_interval_norm th0 eq_th;;
\r
671 let th1 = eval_taylor_x domain_th and
\r
672 th2 = eval_taylor_sqrt pp domain_th;;
\r
673 taylor_interval_sub pp th1 th2;;
\r
677 (*************************************)
\r
678 (* taylor_interval_mul *)
\r
680 let TAYLOR_INTERVAL_MUL' = (UNDISCH_ALL o prove)
\r
681 (`cell_domain x y z w ==>
\r
682 lin_approx (\x. f x * g x) y bounds d_bounds ==>
\r
683 nth_diff_strong_int 2 (x,z) f ==>
\r
684 nth_diff_strong_int 2 (x,z) g ==>
\r
685 bounded_on_int (\x. f x * nth_derivative 2 g x + &2 * derivative f x * derivative g x +
\r
686 nth_derivative 2 f x * g x) (x,z) dd_bounds ==>
\r
687 taylor_interval (\x. f x * g x) x y z w bounds d_bounds dd_bounds`,
\r
688 SIMP_TAC[taylor_interval; cell_domain] THEN REPEAT STRIP_TAC THEN
\r
689 ASM_SIMP_TAC[second_derivative_mul_bounds]);;
\r
692 let taylor_interval_mul pp th1 th2 =
\r
693 let domain_th, approx1_th, second1_th = dest_taylor_interval_th th1 and
\r
694 _, approx2_th, second2_th = dest_taylor_interval_th th2 in
\r
695 let diff1_th, dd1_th = dest_has_bounded_second_derivative_th second1_th and
\r
696 diff2_th, dd2_th = dest_has_bounded_second_derivative_th second2_th in
\r
698 let approx_th = lin_approx_mul pp approx1_th approx2_th in
\r
700 let dest = dest_bounded_on_int_raw in
\r
701 let f = (dest o eval_taylor_f_bounds pp) th1 and
\r
702 g = (dest o eval_taylor_f_bounds pp) th2 and
\r
703 df = (dest o eval_taylor_df_bounds pp) th1 and
\r
704 dg = (dest o eval_taylor_df_bounds pp) th2 and
\r
705 ddf = dest dd1_th and
\r
706 ddg = dest dd2_th and
\r
707 (+) = float_interval_add pp and
\r
708 ( * ) = float_interval_mul pp in
\r
709 mk_bounded_on_int (f * ddg + (two_interval * (df * dg) + ddf * g)) in
\r
711 let x_tm, y_tm, z_tm, w_tm = dest_cell_domain (concl domain_th) and
\r
712 f_tm = (rand o concl) diff1_th and
\r
713 g_tm = (rand o concl) diff2_th and
\r
714 _, _, bounds, d_bounds = dest_lin_approx (concl approx_th) and
\r
715 dd_bounds = (rand o concl) dd_th in
\r
717 let th0 = (MY_PROVE_HYP domain_th o MY_PROVE_HYP approx_th o
\r
718 MY_PROVE_HYP diff1_th o MY_PROVE_HYP diff2_th o MY_PROVE_HYP dd_th o
\r
719 INST[x_tm, x_var_real; y_tm, y_var_real; z_tm, z_var_real; w_tm, w_var_real;
\r
720 f_tm, f_var_fun; g_tm, g_var_fun;
\r
721 bounds, bounds_var; d_bounds, d_bounds_var; dd_bounds, dd_bounds_var])
\r
722 TAYLOR_INTERVAL_MUL' in
\r
723 let eq_th = binary_beta_eq f_tm g_tm mul_op_real in
\r
724 taylor_interval_norm th0 eq_th;;
\r
729 let th1 = eval_taylor_x domain_th and
\r
730 th2 = eval_taylor_sqrt pp domain_th;;
\r
731 let th3 = taylor_interval_sub pp th1 th2;;
\r
732 taylor_interval_mul pp th1 th3;;
\r
737 (*************************************)
\r
738 (* taylor_interval_div *)
\r
740 let TAYLOR_INTERVAL_DIV' = (UNDISCH_ALL o prove)
\r
741 (`cell_domain x y z w ==>
\r
742 bounded_on_int g (x,z) g_bounds ==>
\r
743 interval_not_zero g_bounds ==>
\r
744 lin_approx (\x. f x / g x) y bounds d_bounds ==>
\r
745 nth_diff_strong_int 2 (x,z) f ==>
\r
746 nth_diff_strong_int 2 (x,z) g ==>
\r
747 bounded_on_int (\x. ((nth_derivative 2 f x * g x - f x * nth_derivative 2 g x) * g x -
\r
748 &2 * derivative g x * (derivative f x * g x - f x * derivative g x)) /
\r
749 (g x * g x * g x)) (x,z) dd_bounds ==>
\r
750 taylor_interval (\x. f x / g x) x y z w bounds d_bounds dd_bounds`,
\r
751 SIMP_TAC[taylor_interval; cell_domain] THEN REPEAT STRIP_TAC THEN
\r
752 MATCH_MP_TAC ((SPEC_ALL o REWRITE_RULE[IMP_IMP]) second_derivative_div_bounds) THEN
\r
753 ASM_REWRITE_TAC[REAL_ARITH `g x pow 3 = g x * g x * (g:real->real) x`]);;
\r
756 let taylor_interval_div pp th1 th2 =
\r
757 let domain_th, approx1_th, second1_th = dest_taylor_interval_th th1 and
\r
758 _, approx2_th, second2_th = dest_taylor_interval_th th2 in
\r
759 let diff1_th, dd1_th = dest_has_bounded_second_derivative_th second1_th and
\r
760 diff2_th, dd2_th = dest_has_bounded_second_derivative_th second2_th in
\r
762 let g_bounds_th = eval_taylor_f_bounds pp th2 and
\r
763 approx_th = lin_approx_div pp approx1_th approx2_th in
\r
764 let g_bounds = (rand o concl) g_bounds_th in
\r
765 let cond_th = check_interval_not_zero g_bounds in
\r
768 let dest = dest_bounded_on_int_raw in
\r
769 let f = (dest o eval_taylor_f_bounds pp) th1 and
\r
770 g = dest g_bounds_th and
\r
771 df = (dest o eval_taylor_df_bounds pp) th1 and
\r
772 dg = (dest o eval_taylor_df_bounds pp) th2 and
\r
773 ddf = dest dd1_th and
\r
774 ddg = dest dd2_th and
\r
775 (-) = float_interval_sub pp and
\r
776 ( * ) = float_interval_mul pp and
\r
777 (/) = float_interval_div pp in
\r
778 mk_bounded_on_int (((ddf * g - f * ddg) * g - two_interval * (dg * (df * g - f * dg))) / (g * (g * g))) in
\r
780 let x_tm, y_tm, z_tm, w_tm = dest_cell_domain (concl domain_th) and
\r
781 f_tm = (rand o concl) diff1_th and
\r
782 g_tm = (rand o concl) diff2_th and
\r
783 _, _, bounds, d_bounds = dest_lin_approx (concl approx_th) and
\r
784 dd_bounds = (rand o concl) dd_th in
\r
786 let th0 = (MY_PROVE_HYP domain_th o MY_PROVE_HYP approx_th o
\r
787 MY_PROVE_HYP g_bounds_th o MY_PROVE_HYP cond_th o
\r
788 MY_PROVE_HYP diff1_th o MY_PROVE_HYP diff2_th o MY_PROVE_HYP dd_th o
\r
789 INST[x_tm, x_var_real; y_tm, y_var_real; z_tm, z_var_real; w_tm, w_var_real;
\r
790 f_tm, f_var_fun; g_tm, g_var_fun; g_bounds, g_bounds_var;
\r
791 bounds, bounds_var; d_bounds, d_bounds_var; dd_bounds, dd_bounds_var])
\r
792 TAYLOR_INTERVAL_DIV' in
\r
793 let eq_th = binary_beta_eq f_tm g_tm div_op_real in
\r
794 taylor_interval_norm th0 eq_th;;
\r
799 let domain_th = mk_center_domain pp one_float two_float;;
\r
800 let th1 = eval_taylor_x domain_th and
\r
801 th2 = eval_taylor_sqrt pp domain_th;;
\r
802 let th3 = taylor_interval_sub pp th1 th2;;
\r
803 taylor_interval_div pp th1 th2;;
\r
804 taylor_interval_div pp th3 th2;;
\r
806 test 100 (taylor_interval_div pp th1) th2;;
\r
810 (*************************************)
\r
811 (* taylor_interval_atn *)
\r
813 let TAYLOR_INTERVAL_ATN' = (UNDISCH_ALL o REWRITE_RULE[REAL_POW_2] o prove)
\r
814 (`cell_domain x y z w ==>
\r
815 lin_approx (\x. atn (f x)) y bounds d_bounds ==>
\r
816 nth_diff_strong_int 2 (x,z) f ==>
\r
817 bounded_on_int (\x. (nth_derivative 2 f x * (&1 + f x * f x) - &2 * f x * derivative f x pow 2) /
\r
818 (&1 + f x * f x) pow 2) (x,z) dd_bounds ==>
\r
819 taylor_interval (\x. atn (f x)) x y z w bounds d_bounds dd_bounds`,
\r
820 SIMP_TAC[taylor_interval; cell_domain] THEN REPEAT STRIP_TAC THEN
\r
821 MATCH_MP_TAC ((SPEC_ALL o REWRITE_RULE[IMP_IMP]) second_derivative_compose_atn_bounds) THEN
\r
822 ASM_REWRITE_TAC[]);;
\r
825 let taylor_interval_atn pp th1 =
\r
826 let domain_th, approx1_th, second1_th = dest_taylor_interval_th th1 in
\r
827 let diff1_th, dd1_th = dest_has_bounded_second_derivative_th second1_th in
\r
829 let approx_th = lin_approx_atn pp approx1_th in
\r
831 let dest = dest_bounded_on_int_raw in
\r
832 let f = (dest o eval_taylor_f_bounds pp) th1 and
\r
833 df = (dest o eval_taylor_df_bounds pp) th1 and
\r
834 ddf = dest dd1_th and
\r
835 (+) = float_interval_add pp and
\r
836 (-) = float_interval_sub pp and
\r
837 ( * ) = float_interval_mul pp and
\r
838 (/) = float_interval_div pp in
\r
839 let ff1 = one_interval + f * f in
\r
840 mk_bounded_on_int ((ddf * ff1 - two_interval * (f * (df * df))) / (ff1 * ff1)) in
\r
842 let x_tm, y_tm, z_tm, w_tm = dest_cell_domain (concl domain_th) and
\r
843 f_tm = (rand o concl) diff1_th and
\r
844 _, _, bounds, d_bounds = dest_lin_approx (concl approx_th) and
\r
845 dd_bounds = (rand o concl) dd_th in
\r
847 let th0 = (MY_PROVE_HYP domain_th o MY_PROVE_HYP approx_th o
\r
848 MY_PROVE_HYP diff1_th o MY_PROVE_HYP dd_th o
\r
849 INST[x_tm, x_var_real; y_tm, y_var_real; z_tm, z_var_real; w_tm, w_var_real;
\r
851 bounds, bounds_var; d_bounds, d_bounds_var; dd_bounds, dd_bounds_var])
\r
852 TAYLOR_INTERVAL_ATN' in
\r
853 let eq_th = unary_beta_eq f_tm atn_tm in
\r
854 taylor_interval_norm th0 eq_th;;
\r
859 let domain_th = mk_center_domain pp one_float two_float;;
\r
860 let th1 = eval_taylor_x domain_th and
\r
861 th2 = eval_taylor_sqrt pp domain_th;;
\r
862 let th3 = taylor_interval_add pp th1 th2;;
\r
863 taylor_interval_atn pp th1;;
\r
864 taylor_interval_atn pp th2;;
\r
865 taylor_interval_atn pp th3;;
\r
871 (*************************************)
\r
872 (* taylor_interval_inv *)
\r
874 let TAYLOR_INTERVAL_INV' = (UNDISCH_ALL o REWRITE_RULE[REAL_POW_2; REAL_ARITH `a pow 3 = a * a * a`] o prove)
\r
875 (`cell_domain x y z w ==>
\r
876 bounded_on_int f (x,z) f_bounds ==>
\r
877 interval_not_zero f_bounds ==>
\r
878 lin_approx (\x. inv (f x)) y bounds d_bounds ==>
\r
879 nth_diff_strong_int 2 (x,z) f ==>
\r
880 bounded_on_int (\x. (&2 * derivative f x pow 2 - nth_derivative 2 f x * f x) / (f x pow 3)) (x,z) dd_bounds
\r
881 ==> taylor_interval (\x. inv (f x)) x y z w bounds d_bounds dd_bounds`,
\r
882 SIMP_TAC[taylor_interval; cell_domain] THEN REPEAT STRIP_TAC THEN
\r
883 MATCH_MP_TAC ((SPEC_ALL o REWRITE_RULE[IMP_IMP]) second_derivative_compose_inv_bounds) THEN
\r
884 ASM_REWRITE_TAC[]);;
\r
887 let taylor_interval_inv pp th1 =
\r
888 let domain_th, approx1_th, second1_th = dest_taylor_interval_th th1 in
\r
889 let diff1_th, dd1_th = dest_has_bounded_second_derivative_th second1_th in
\r
891 let f_bounds_th = eval_taylor_f_bounds pp th1 and
\r
892 approx_th = lin_approx_inv pp approx1_th in
\r
893 let f_bounds = (rand o concl) f_bounds_th in
\r
894 let cond_th = check_interval_not_zero f_bounds in
\r
897 let dest = dest_bounded_on_int_raw in
\r
898 let f = dest f_bounds_th and
\r
899 df = (dest o eval_taylor_df_bounds pp) th1 and
\r
900 ddf = dest dd1_th and
\r
901 (-) = float_interval_sub pp and
\r
902 ( * ) = float_interval_mul pp and
\r
903 (/) = float_interval_div pp in
\r
904 mk_bounded_on_int ((two_interval * (df * df) - ddf * f) / (f * (f * f))) in
\r
906 let x_tm, y_tm, z_tm, w_tm = dest_cell_domain (concl domain_th) and
\r
907 f_tm = (rand o concl) diff1_th and
\r
908 _, _, bounds, d_bounds = dest_lin_approx (concl approx_th) and
\r
909 dd_bounds = (rand o concl) dd_th in
\r
911 let th0 = (MY_PROVE_HYP domain_th o MY_PROVE_HYP approx_th o
\r
912 MY_PROVE_HYP f_bounds_th o MY_PROVE_HYP cond_th o
\r
913 MY_PROVE_HYP diff1_th o MY_PROVE_HYP dd_th o
\r
914 INST[x_tm, x_var_real; y_tm, y_var_real; z_tm, z_var_real; w_tm, w_var_real;
\r
915 f_tm, f_var_fun; f_bounds, f_bounds_var;
\r
916 bounds, bounds_var; d_bounds, d_bounds_var; dd_bounds, dd_bounds_var])
\r
917 TAYLOR_INTERVAL_INV' in
\r
918 let eq_th = unary_beta_eq f_tm inv_tm in
\r
919 taylor_interval_norm th0 eq_th;;
\r
924 let domain_th = mk_center_domain pp one_float two_float;;
\r
925 let th1 = eval_taylor_x domain_th and
\r
926 th2 = eval_taylor_sqrt pp domain_th;;
\r
927 let th3 = taylor_interval_add pp th1 th2;;
\r
928 taylor_interval_inv pp th1;;
\r
929 taylor_interval_inv pp th2;;
\r
930 taylor_interval_inv pp th3;;
\r
935 (*************************************)
\r
936 (* taylor_interval_sqrt *)
\r
938 let TAYLOR_INTERVAL_SQRT' = (UNDISCH_ALL o REWRITE_RULE[REAL_POW_2; REAL_ARITH `a pow 3 = a * a * a`] o prove)
\r
939 (`cell_domain x y z w ==>
\r
940 bounded_on_int f (x,z) f_bounds ==>
\r
941 interval_pos f_bounds ==>
\r
942 lin_approx (\x. sqrt (f x)) y bounds d_bounds ==>
\r
943 nth_diff_strong_int 2 (x,z) f ==>
\r
944 bounded_on_int (\x. (&2 * nth_derivative 2 f x * f x - derivative f x pow 2) /
\r
945 (&4 * sqrt (f x pow 3))) (x,z) dd_bounds ==>
\r
946 taylor_interval (\x. sqrt (f x)) x y z w bounds d_bounds dd_bounds`,
\r
947 SIMP_TAC[taylor_interval; cell_domain] THEN REPEAT STRIP_TAC THEN
\r
948 MATCH_MP_TAC ((SPEC_ALL o REWRITE_RULE[IMP_IMP]) second_derivative_compose_sqrt_bounds) THEN
\r
949 ASM_REWRITE_TAC[]);;
\r
952 let taylor_interval_sqrt pp th1 =
\r
953 let domain_th, approx1_th, second1_th = dest_taylor_interval_th th1 in
\r
954 let diff1_th, dd1_th = dest_has_bounded_second_derivative_th second1_th in
\r
956 let f_bounds_th = eval_taylor_f_bounds pp th1 and
\r
957 approx_th = lin_approx_sqrt pp approx1_th in
\r
958 let f_bounds = (rand o concl) f_bounds_th in
\r
959 let cond_th = check_interval_pos f_bounds in
\r
962 let dest = dest_bounded_on_int_raw in
\r
963 let f = dest f_bounds_th and
\r
964 df = (dest o eval_taylor_df_bounds pp) th1 and
\r
965 ddf = dest dd1_th and
\r
966 (-) = float_interval_sub pp and
\r
967 ( * ) = float_interval_mul pp and
\r
968 (/) = float_interval_div pp and
\r
969 sqrt = float_interval_sqrt pp in
\r
970 mk_bounded_on_int ((two_interval * (ddf * f) - df * df) / (four_interval * sqrt (f * (f * f)))) in
\r
972 let x_tm, y_tm, z_tm, w_tm = dest_cell_domain (concl domain_th) and
\r
973 f_tm = (rand o concl) diff1_th and
\r
974 _, _, bounds, d_bounds = dest_lin_approx (concl approx_th) and
\r
975 dd_bounds = (rand o concl) dd_th in
\r
977 let th0 = (MY_PROVE_HYP domain_th o MY_PROVE_HYP approx_th o
\r
978 MY_PROVE_HYP f_bounds_th o MY_PROVE_HYP cond_th o
\r
979 MY_PROVE_HYP diff1_th o MY_PROVE_HYP dd_th o
\r
980 INST[x_tm, x_var_real; y_tm, y_var_real; z_tm, z_var_real; w_tm, w_var_real;
\r
981 f_tm, f_var_fun; f_bounds, f_bounds_var;
\r
982 bounds, bounds_var; d_bounds, d_bounds_var; dd_bounds, dd_bounds_var])
\r
983 TAYLOR_INTERVAL_SQRT' in
\r
984 let eq_th = unary_beta_eq f_tm sqrt_tm in
\r
985 taylor_interval_norm th0 eq_th;;
\r
990 let domain_th = mk_center_domain pp one_float two_float;;
\r
991 let th1 = eval_taylor_x domain_th and
\r
992 th2 = eval_taylor_sqrt pp domain_th;;
\r
993 let th3 = taylor_interval_add pp th1 th2;;
\r
994 taylor_interval_sqrt pp th1;;
\r
995 taylor_interval_sqrt pp th2;;
\r
996 taylor_interval_sqrt pp th3;;
\r
1000 (*************************************)
\r
1001 (* taylor_interval_acs *)
\r
1003 let TAYLOR_INTERVAL_ACS' =
\r
1004 (UNDISCH_ALL o PURE_ONCE_REWRITE_RULE[iabs_lt1_lemma] o
\r
1005 REWRITE_RULE[REAL_POW_2; REAL_ARITH `a pow 3 = a * a * a`] o prove)
\r
1006 (`cell_domain x y z w ==>
\r
1007 bounded_on_int f (x,z) f_bounds ==>
\r
1008 (iabs f_bounds < &1 <=> T)==>
\r
1009 lin_approx (\x. acs (f x)) y bounds d_bounds ==>
\r
1010 nth_diff_strong_int 2 (x,z) f ==>
\r
1011 bounded_on_int (\x. --((nth_derivative 2 f x * (&1 - f x * f x) + f x * derivative f x pow 2) /
\r
1012 sqrt ((&1 - f x * f x) pow 3))) (x,z) dd_bounds ==>
\r
1013 taylor_interval (\x. acs (f x)) x y z w bounds d_bounds dd_bounds`,
\r
1014 SIMP_TAC[taylor_interval; cell_domain] THEN REPEAT STRIP_TAC THEN
\r
1015 MATCH_MP_TAC ((SPEC_ALL o REWRITE_RULE[IMP_IMP]) second_derivative_compose_acs_bounds) THEN
\r
1016 ASM_REWRITE_TAC[]);;
\r
1019 let taylor_interval_acs pp th1 =
\r
1020 let domain_th, approx1_th, second1_th = dest_taylor_interval_th th1 in
\r
1021 let diff1_th, dd1_th = dest_has_bounded_second_derivative_th second1_th in
\r
1023 let f_bounds_th = eval_taylor_f_bounds pp th1 and
\r
1024 approx_th = lin_approx_acs pp approx1_th in
\r
1025 let f_bounds = (rand o concl) f_bounds_th in
\r
1026 let cond_th = check_interval_iabs f_bounds one_float in
\r
1029 let dest = dest_bounded_on_int_raw in
\r
1030 let f = dest f_bounds_th and
\r
1031 df = (dest o eval_taylor_df_bounds pp) th1 and
\r
1032 ddf = dest dd1_th and
\r
1033 (+) = float_interval_add pp and
\r
1034 (-) = float_interval_sub pp and
\r
1035 ( * ) = float_interval_mul pp and
\r
1036 (/) = float_interval_div pp and
\r
1037 sqrt = float_interval_sqrt pp and
\r
1038 neg = float_interval_neg in
\r
1039 let ff1 = one_interval - f * f in
\r
1040 mk_bounded_on_int (neg ((ddf * ff1 + f * (df * df)) / sqrt (ff1 * (ff1 * ff1)))) in
\r
1042 let x_tm, y_tm, z_tm, w_tm = dest_cell_domain (concl domain_th) and
\r
1043 f_tm = (rand o concl) diff1_th and
\r
1044 _, _, bounds, d_bounds = dest_lin_approx (concl approx_th) and
\r
1045 dd_bounds = (rand o concl) dd_th in
\r
1047 let th0 = (MY_PROVE_HYP domain_th o MY_PROVE_HYP approx_th o
\r
1048 MY_PROVE_HYP f_bounds_th o MY_PROVE_HYP cond_th o
\r
1049 MY_PROVE_HYP diff1_th o MY_PROVE_HYP dd_th o
\r
1050 INST[x_tm, x_var_real; y_tm, y_var_real; z_tm, z_var_real; w_tm, w_var_real;
\r
1051 f_tm, f_var_fun; f_bounds, f_bounds_var;
\r
1052 bounds, bounds_var; d_bounds, d_bounds_var; dd_bounds, dd_bounds_var])
\r
1053 TAYLOR_INTERVAL_ACS' in
\r
1054 let eq_th = unary_beta_eq f_tm acs_tm in
\r
1055 taylor_interval_norm th0 eq_th;;
\r
1060 let domain_th = mk_center_domain pp (mk_float (-5) 49) (mk_float 3 49);;
\r
1061 let th1 = eval_taylor_x domain_th and
\r
1062 th2 = eval_taylor_atn pp domain_th;;
\r
1063 let th3 = taylor_interval_mul pp th1 th2;;
\r
1065 taylor_interval_acs pp th1;;
\r
1066 taylor_interval_acs pp th2;;
\r
1067 taylor_interval_acs pp th3;;
\r
1076 (****************************************)
\r
1079 let dest_bounded_on_int_tm tm =
\r
1080 let lhs, f_bounds = dest_comb tm in
\r
1081 let lhs2, int_tm = dest_comb lhs in
\r
1082 rand lhs2, int_tm, f_bounds;;
\r
1084 let dest_interval_arith tm =
\r
1085 let lhs, int_tm = dest_comb tm in
\r
1086 rand lhs, int_tm;;
\r
1089 let BOUNDED_SECOND_DERIVATIVE_COMPOSE' = (UNDISCH_ALL o REWRITE_RULE[REAL_POW_2] o SPEC_ALL)
\r
1090 second_derivative_compose_bounds;;
\r
1092 let BOUNDED_ON_INT_COMPOSE' = (UNDISCH_ALL o SPEC_ALL) bounded_on_int_compose;;
\r
1094 let TAYLOR_INTERVAL_NARROW' = (UNDISCH_ALL o PURE_ONCE_REWRITE_RULE[REAL_ARITH `a <= b <=> (a <= b <=> T)`] o
\r
1095 SPEC_ALL) taylor_interval_narrow;;
\r
1097 let BOUNDED_ON_INT_IMP_INTERVAL' = (UNDISCH_ALL o SPEC_ALL) bounded_on_int_imp_interval_arith;;
\r
1099 let LIN_APPROX_COMPOSE' = (UNDISCH_ALL o SPEC_ALL) lin_approx_compose;;
\r
1103 let taylor_interval_compose pp eval_f eval_g domain_th =
\r
1104 let g_taylor = eval_g pp domain_th in
\r
1105 let _, lin_g, second_g = dest_taylor_interval_th g_taylor in
\r
1106 let dg_th, g2_th = dest_has_bounded_second_derivative_th second_g in
\r
1107 let g0_th = eval_taylor_f_bounds pp g_taylor in
\r
1108 let g1_th = eval_taylor_df_bounds pp g_taylor in
\r
1109 let g_tm, y_tm, g_bounds0, _ = dest_lin_approx (concl lin_g) in
\r
1111 (* narrow domain *)
\r
1112 let g0_lo, g0_hi = dest_pair g_bounds0 in
\r
1113 let fu_domain = mk_center_domain (pp + 1) g0_lo g0_hi in
\r
1114 let w0_tm = (rand o concl) fu_domain in
\r
1117 let _, u_tm, _, _ = dest_cell_domain (concl fu_domain) in
\r
1118 let g_lo, g_hi = (dest_pair o rand o concl) g0_th in
\r
1119 let fw_domain = mk_cell_domain pp g_lo u_tm g_hi in
\r
1120 let w_tm = (rand o concl) fw_domain in
\r
1122 (* taylor_interval f *)
\r
1123 let f_taylor = eval_f pp fw_domain in
\r
1124 let f1_th = eval_taylor_df_bounds pp f_taylor in
\r
1125 let _, lin_f, second_f = dest_taylor_interval_th f_taylor in
\r
1126 let f_tm, _, f_bounds0, df_bounds0 = dest_lin_approx (concl lin_f) in
\r
1127 let df_th, f2_th = dest_has_bounded_second_derivative_th second_f in
\r
1129 (* has_bounded_second_derivative (\x. f (g x)) *)
\r
1130 let _, int_tm, g_bounds = dest_bounded_on_int_tm (concl g0_th) in
\r
1131 let df_tm, _, df_bounds = dest_bounded_on_int_tm (concl f1_th) in
\r
1132 let ddf_tm, _, ddf_bounds = dest_bounded_on_int_tm (concl f2_th) in
\r
1134 let f2_g_bounded_th = (MY_PROVE_HYP g0_th o MY_PROVE_HYP f2_th o
\r
1135 INST[ddf_tm, f_var_fun; g_tm, g_var_fun; g_bounds, g_bounds_var;
\r
1136 ddf_bounds, f_bounds_var; int_tm, int_var]) BOUNDED_ON_INT_COMPOSE' in
\r
1137 let f1_g_bounded_th = (MY_PROVE_HYP g0_th o MY_PROVE_HYP f1_th o
\r
1138 INST[df_tm, f_var_fun; g_tm, g_var_fun; g_bounds, g_bounds_var;
\r
1139 df_bounds, f_bounds_var; int_tm, int_var]) BOUNDED_ON_INT_COMPOSE' in
\r
1141 let fg2_bounded_th0 =
\r
1142 let ( * ) = bounded_on_int_mul pp and
\r
1143 (+) = bounded_on_int_add pp in
\r
1144 (f2_g_bounded_th * (g1_th * g1_th) + f1_g_bounded_th * g2_th) in
\r
1146 let dd_bounds = (rand o concl) fg2_bounded_th0 in
\r
1147 let fg2_bounded_th = (MY_PROVE_HYP fg2_bounded_th0 o MY_PROVE_HYP g0_th o
\r
1148 MY_PROVE_HYP dg_th o MY_PROVE_HYP df_th o
\r
1149 INST[f_tm, f_var_fun; g_tm, g_var_fun; int_tm, int_var;
\r
1150 dd_bounds, dd_bounds_var; g_bounds, g_bounds_var])
\r
1151 BOUNDED_SECOND_DERIVATIVE_COMPOSE' in
\r
1153 (* lin_approx (\x. f (g x)) *)
\r
1154 let fu_taylor = (MY_PROVE_HYP (float_le g_lo g0_lo) o MY_PROVE_HYP (float_le g0_hi g_hi) o
\r
1155 MY_PROVE_HYP fu_domain o MY_PROVE_HYP f_taylor o
\r
1156 INST[g0_lo, x0_var_real; u_tm, y_var_real; g0_hi, z0_var_real; w0_tm, w0_var_real;
\r
1157 f_tm, f_var_fun; g_lo, x_var_real; g_hi, z_var_real; w_tm, w_var_real;
\r
1158 f_bounds0, f_bounds_var; df_bounds0, df_bounds_var; ddf_bounds, dd_bounds_var])
\r
1159 TAYLOR_INTERVAL_NARROW' in
\r
1162 let _, _, f_second = dest_taylor_interval_th fu_taylor in
\r
1163 (fst o dest_has_bounded_second_derivative_th) f_second in
\r
1164 let f00_th = eval_taylor_f_bounds pp fu_taylor in
\r
1165 let f01_th = eval_taylor_df_bounds pp fu_taylor in
\r
1166 let fg_bounds0 = (rand o concl) f00_th in
\r
1167 let dfg_bounds0 = (rand o concl) f01_th in
\r
1169 let dg0_th, int_g_th, int_dg_th = lin_approx_components lin_g in
\r
1170 let gy_tm, _ = dest_interval_arith (concl int_g_th) in
\r
1172 let int_df_g_th = (MY_PROVE_HYP int_g_th o MY_PROVE_HYP f01_th o
\r
1173 INST[df_tm, f_var_fun; gy_tm, y_var_real; g_bounds0, int_var; dfg_bounds0, f_bounds_var])
\r
1174 BOUNDED_ON_INT_IMP_INTERVAL' in
\r
1176 let int_dfg_th = float_interval_mul pp int_dg_th int_df_g_th in
\r
1177 let dfg_bounds00 = rand (concl int_dfg_th) in
\r
1179 let fg_lin_th = (MY_PROVE_HYP int_dfg_th o MY_PROVE_HYP int_g_th o MY_PROVE_HYP f00_th o
\r
1180 MY_PROVE_HYP dg0_th o MY_PROVE_HYP df0_th o
\r
1181 INST[f_tm, f_var_fun; g_tm, g_var_fun; y_tm, y_var_real; dfg_bounds00, d_bounds_var;
\r
1182 g_bounds0, g_bounds_var; fg_bounds0, f_bounds_var]) LIN_APPROX_COMPOSE' in
\r
1184 (* beta reduction *)
\r
1185 let gx_tm = mk_comb (g_tm, x_var_real) in
\r
1186 let gx_th = if is_abs g_tm then BETA gx_tm else REFL gx_tm in
\r
1188 let fgx_th0 = MK_COMB (REFL f_tm, gx_th) in
\r
1189 let fgx_eq_th = ABS x_var_real
\r
1190 (if is_abs f_tm then TRANS fgx_th0 (BETA_CONV (rand (concl fgx_th0))) else fgx_th0) in
\r
1192 let fg_lin_th1 = norm_lin_approx fg_lin_th fgx_eq_th and
\r
1193 fg2_bounded_th1 = norm_second_derivative fg2_bounded_th fgx_eq_th in
\r
1195 mk_taylor_interval_th domain_th fg_lin_th1 fg2_bounded_th1;;
\r