| 1 |
(* ========================================================================== *) |
| 2 |
(* Formal verification of nonlinear inequalities in HOL Light *) |
| 3 |
(* *) |
| 4 |
(* Copyright (c) 2014 Alexey Solovyev *) |
| 5 |
(* *) |
| 6 |
(* This file is distributed under the terms of the MIT licence *) |
| 7 |
(* ========================================================================== *) |
| 8 |
|
| 9 |
(* -------------------------------------------------------------------------- *) |
| 10 |
(* Formal interval evaluation of functions: sin *) |
| 11 |
(* -------------------------------------------------------------------------- *) |
| 12 |
|
| 13 |
needs "Formal_ineqs/misc/misc_functions.hl";; |
| 14 |
needs "Formal_ineqs/misc/misc_vars.hl";; |
| 15 |
needs "Formal_ineqs/arith/interval_arith.hl";; |
| 16 |
needs "Formal_ineqs/trig/atn_eval.hl";; |
| 17 |
needs "Formal_ineqs/trig/cos_eval.hl";; |
| 18 |
|
| 19 |
module type Sin_eval_sig = |
| 20 |
sig |
| 21 |
val float_interval_sin : int -> thm -> thm |
| 22 |
end;; |
| 23 |
|
| 24 |
module Sin_eval : Sin_eval_sig = struct |
| 25 |
|
| 26 |
open Misc_functions;; |
| 27 |
open Float_theory;; |
| 28 |
open Interval_arith;; |
| 29 |
open More_float;; |
| 30 |
open Arith_float;; |
| 31 |
open Atn_eval;; |
| 32 |
open Cos_eval;; |
| 33 |
open Misc_vars;; |
| 34 |
|
| 35 |
prioritize_real();; |
| 36 |
|
| 37 |
(* TODO: compute sin directly? *) |
| 38 |
|
| 39 |
(* Reduce sin to cos *) |
| 40 |
|
| 41 |
let th_rule = UNDISCH_ALL o PURE_REWRITE_RULE[GSYM IMP_IMP];; |
| 42 |
|
| 43 |
let cos_pi2_eq_sin = prove(`cos (x - pi / &2) = sin x`, |
| 44 |
REWRITE_TAC[SIN_COS; REAL_ARITH `pi / &2 - x = --(x - pi / &2)`; COS_NEG]);; |
| 45 |
|
| 46 |
let sin_reduce_th = (th_rule o prove)(`interval_arith (cos (x - pi / &2)) (low, high) |
| 47 |
==> interval_arith (sin x) (low, high)`, |
| 48 |
REWRITE_TAC[cos_pi2_eq_sin]);; |
| 49 |
|
| 50 |
let translate_interval_const = (th_rule o prove)(`interval_arith x (a, b) /\ |
| 51 |
interval_arith c (lo, hi) /\ |
| 52 |
a1 <= a - hi /\ b - lo <= b1 |
| 53 |
==> interval_arith (x - c) (a1, b1)`, |
| 54 |
REWRITE_TAC[interval_arith] THEN REAL_ARITH_TAC);; |
| 55 |
|
| 56 |
|
| 57 |
(* Transforms |- interval_arith x (a,b) into |- interval_arith (x - pi / &2) (a1, b1) *) |
| 58 |
let translate_pi2 = |
| 59 |
let c_tm = `pi / &2` in |
| 60 |
fun pp x_th -> |
| 61 |
let x_tm, bounds = dest_interval_arith (concl x_th) in |
| 62 |
let ltm, b_tm = dest_comb bounds in |
| 63 |
let a_tm = rand ltm in |
| 64 |
let pi2_th = pi2_approx_array.(pp) in |
| 65 |
let bounds = rand (concl pi2_th) in |
| 66 |
let ltm, hi_tm = dest_comb bounds in |
| 67 |
let lo_tm = rand ltm in |
| 68 |
let a_sub_hi = float_sub_lo pp a_tm hi_tm and |
| 69 |
b_sub_lo = float_sub_hi pp b_tm lo_tm in |
| 70 |
let a1_tm = rand (rator (concl a_sub_hi)) and |
| 71 |
b1_tm = rand (concl b_sub_lo) in |
| 72 |
let th0 = INST[x_tm, x_var_real; c_tm, c_var_real; |
| 73 |
lo_tm, lo_var_real; hi_tm, hi_var_real; |
| 74 |
a_tm, a_var_real; b_tm, b_var_real; |
| 75 |
a1_tm, a1_var_real; b1_tm, b1_var_real] translate_interval_const in |
| 76 |
itlist MY_PROVE_HYP [pi2_th; x_th; a_sub_hi; b_sub_lo] th0;; |
| 77 |
|
| 78 |
let float_interval_sin pp x_th = |
| 79 |
let x_tm, _ = dest_interval_arith (concl x_th) in |
| 80 |
let x_pi2_th = translate_pi2 pp x_th in |
| 81 |
let cos_x_pi2 = float_interval_cos pp x_pi2_th in |
| 82 |
let bounds = rand (concl cos_x_pi2) in |
| 83 |
let ltm, high_tm = dest_comb bounds in |
| 84 |
let low_tm = rand ltm in |
| 85 |
let th0 = INST[x_tm, x_var_real; low_tm, low_var_real; |
| 86 |
high_tm, high_var_real] sin_reduce_th in |
| 87 |
MY_PROVE_HYP cos_x_pi2 th0;; |
| 88 |
|
| 89 |
|
| 90 |
end;; |
| 91 |
|
| 92 |
|
| 93 |
(* |
| 94 |
let x_int = pi2_approx_array.(10);; |
| 95 |
float_interval_sin 8 x_int;; |
| 96 |
|
| 97 |
test 100 (float_interval_cos 6) x_int;; |
| 98 |
test 100 (float_interval_sin 6) x_int;; |
| 99 |
*) |