| 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 |
(* Informal arithmetic procedures: polynomials *) |
| 11 |
(* -------------------------------------------------------------------------- *) |
| 12 |
|
| 13 |
(* Dependencies *) |
| 14 |
needs "Formal_ineqs/informal/informal_interval.hl";; |
| 15 |
|
| 16 |
(* poly *) |
| 17 |
module type Informal_poly_sig = |
| 18 |
sig |
| 19 |
val eval_interval_poly_f : int -> Informal_interval.interval list -> Informal_interval.interval -> Informal_interval.interval |
| 20 |
val eval_high_poly_f_pos_pos : int -> Informal_interval.interval list -> Informal_float.ifloat -> Informal_float.ifloat |
| 21 |
val eval_low_poly_f_pos_pos : int -> Informal_interval.interval list -> Informal_float.ifloat -> Informal_float.ifloat |
| 22 |
val eval_pow2_high : int -> Informal_float.ifloat -> Informal_float.ifloat |
| 23 |
val eval_pow2_low : int -> Informal_float.ifloat -> Informal_float.ifloat |
| 24 |
val eval_pow4_high : int -> Informal_float.ifloat -> Informal_float.ifloat |
| 25 |
val eval_pow4_low : int -> Informal_float.ifloat -> Informal_float.ifloat |
| 26 |
val eval_pow2_pow4_high : int -> Informal_float.ifloat -> Informal_float.ifloat * Informal_float.ifloat |
| 27 |
val eval_pow2_pow4_low : int -> Informal_float.ifloat -> Informal_float.ifloat * Informal_float.ifloat |
| 28 |
end;; |
| 29 |
|
| 30 |
|
| 31 |
module Informal_poly : Informal_poly_sig = struct |
| 32 |
|
| 33 |
open Informal_float;; |
| 34 |
open Informal_interval;; |
| 35 |
|
| 36 |
let rec eval_interval_poly_f pp cs x_int = |
| 37 |
match cs with |
| 38 |
| [] -> zero_interval |
| 39 |
| [first] -> first |
| 40 |
| first :: rest -> |
| 41 |
let r = eval_interval_poly_f pp rest x_int in |
| 42 |
add_interval pp first (mul_interval pp x_int r);; |
| 43 |
|
| 44 |
let rec eval_high_poly_f_pos_pos = |
| 45 |
let zero = mk_small_num_float 0 in |
| 46 |
let check_pos c = |
| 47 |
if le_interval zero c then () |
| 48 |
else failwith "Informal_poly.eval_high_poly_f_pos_pos: negative coefficient" in |
| 49 |
fun pp cs x -> |
| 50 |
let _ = check_pos (mk_interval (x, x)) in |
| 51 |
let rec eval cs = |
| 52 |
match cs with |
| 53 |
| [] -> zero |
| 54 |
| [first] -> |
| 55 |
let _ = check_pos first in |
| 56 |
snd (dest_interval first) |
| 57 |
| first :: rest -> |
| 58 |
let _ = check_pos first in |
| 59 |
let _, b = dest_interval first in |
| 60 |
let r = eval rest in |
| 61 |
let m = mul_float_hi pp x r in |
| 62 |
add_float_hi pp b m in |
| 63 |
eval cs;; |
| 64 |
|
| 65 |
let rec eval_low_poly_f_pos_pos = |
| 66 |
let zero = mk_small_num_float 0 in |
| 67 |
let check_pos c = |
| 68 |
if le_interval zero c then () |
| 69 |
else failwith "Informal_poly.eval_high_poly_f_pos_pos: negative coefficient" in |
| 70 |
fun pp cs x -> |
| 71 |
let _ = check_pos (mk_interval (x, x)) in |
| 72 |
let rec eval cs = |
| 73 |
match cs with |
| 74 |
| [] -> zero |
| 75 |
| [first] -> |
| 76 |
let _ = check_pos first in |
| 77 |
fst (dest_interval first) |
| 78 |
| first :: rest -> |
| 79 |
let _ = check_pos first in |
| 80 |
let b, _ = dest_interval first in |
| 81 |
let r = eval rest in |
| 82 |
let m = mul_float_lo pp x r in |
| 83 |
add_float_lo pp b m in |
| 84 |
eval cs;; |
| 85 |
|
| 86 |
|
| 87 |
let eval_pow2_high pp x = mul_float_hi pp x x;; |
| 88 |
|
| 89 |
let eval_pow2_low pp x = mul_float_lo pp x x;; |
| 90 |
|
| 91 |
let eval_pow4_high pp x = |
| 92 |
let a = mul_float_hi pp x x in |
| 93 |
mul_float_hi pp a a;; |
| 94 |
|
| 95 |
let eval_pow4_low pp x = |
| 96 |
let a = mul_float_lo pp x x in |
| 97 |
mul_float_lo pp a a;; |
| 98 |
|
| 99 |
let eval_pow2_pow4_high pp x = |
| 100 |
let a = mul_float_hi pp x x in |
| 101 |
a, mul_float_hi pp a a;; |
| 102 |
|
| 103 |
let eval_pow2_pow4_low pp x = |
| 104 |
let a = mul_float_lo pp x x in |
| 105 |
a, mul_float_lo pp a a;; |
| 106 |
|
| 107 |
|
| 108 |
end;; |