Commit 3d6185b5 authored by Heiko Becker's avatar Heiko Becker

Add fixed-point precision to HOL4, fix minor bug in configure script

parent 2dd19d8d
......@@ -44,7 +44,7 @@ val Certificate_checking_is_sound = store_thm ("Certificate_checking_is_sound",
CertificateChecker e A P defVars ==>
?iv err vR vF m.
FloverMapTree_find e A = SOME (iv,err) /\
eval_exp E1 (toRMap defVars) (toREval e) vR M0 /\
eval_exp E1 (toRMap defVars) (toREval e) vR REAL /\
eval_exp E2 defVars e vF m /\
(!vF m.
eval_exp E2 defVars e vF m ==>
......@@ -99,7 +99,7 @@ val CertificateCmd_checking_is_sound = store_thm ("CertificateCmd_checking_is_so
CertificateCheckerCmd f A P defVars ==>
?iv err vR vF m.
FloverMapTree_find (getRetExp f) A = SOME (iv, err) /\
bstep (toREvalCmd f) E1 (toRMap defVars) vR M0 /\
bstep (toREvalCmd f) E1 (toRMap defVars) vR REAL /\
bstep f E2 defVars vF m /\
(!vF m. bstep f E2 defVars vF m ==> abs (vR - vF) <= err)``,
simp [CertificateCheckerCmd_def]
......
......@@ -20,7 +20,7 @@ val _ = Datatype `
val toREvalCmd_def = Define `
toREvalCmd (f:real cmd) : real cmd =
case f of
| Let m x e g => Let M0 x (toREval e) (toREvalCmd g)
| Let m x e g => Let REAL x (toREval e) (toREvalCmd g)
| Ret e => Ret (toREval e)`;
(**
......
......@@ -12,7 +12,7 @@ val (approxEnv_rules, approxEnv_ind, approxEnv_cases) = Hol_reln `
(!(E1:env) (E2:env) (defVars: num -> mType option) (A:analysisResult) (fVars:num_set) (dVars:num_set) v1 v2 x.
approxEnv E1 defVars A fVars dVars E2 /\
(defVars x = SOME m) /\
(abs (v1 - v2) <= abs v1 * (mTypeToR m)) /\
(abs (v1 - v2) <= computeError v1 m) /\
(lookup x (union fVars dVars) = NONE) ==>
approxEnv (updEnv x v1 E1) (updDefVars x m defVars) A (insert x () fVars) dVars (updEnv x v2 E2)) /\
(!(E1:env) (E2:env) (defVars: num -> mType option) (A:analysisResult)
......@@ -58,7 +58,7 @@ val approxEnv_fVar_bounded = store_thm (
E2 x = SOME v2 /\
x IN (domain fVars) /\
Gamma x = SOME m ==>
abs (v - v2) <= (abs v) * (mTypeToR m)``,
abs (v - v2) <= computeError v m``,
rpt strip_tac
\\ qspec_then
`\E1 Gamma absenv fVars dVars E2.
......@@ -67,7 +67,7 @@ val approxEnv_fVar_bounded = store_thm (
E2 x = SOME v2 /\
x IN (domain fVars) /\
Gamma x = SOME m ==>
abs (v - v2) <= (abs v) * (mTypeToR m)`
abs (v - v2) <= computeError v m`
(fn thm => irule (SIMP_RULE std_ss [] thm))
approxEnv_ind
\\ rpt strip_tac
......
This diff is collapsed.
This diff is collapsed.
......@@ -61,7 +61,7 @@ val evalFma_def = Define `
val toREval_def = Define `
(toREval (Var n) = Var n) /\
(toREval (Const m n) = Const M0 n) /\
(toREval (Const m n) = Const REAL n) /\
(toREval (Unop u e1) = Unop u (toREval e1)) /\
(toREval (Binop b e1 e2) = Binop b (toREval e1) (toREval e2)) /\
(toREval (Fma e1 e2 e3) = Fma (toREval e1) (toREval e2) (toREval e3)) /\
......@@ -71,7 +71,9 @@ val toREval_def = Define `
Define a perturbation function to ease writing of basic definitions
**)
val perturb_def = Define `
perturb (r:real) (e:real) = r * (1 + e)`
perturb (rVal:real) (REAL) (delta:real) = rVal /\
perturb rVal (F w f) delta = rVal + delta /\
perturb rVal _ delta = rVal * (1 + delta)`;
(**
Define expression evaluation relation parametric by an "error" epsilon.
......@@ -80,38 +82,38 @@ using a perturbation of the real valued computation by (1 + delta), where
|delta| <= machine epsilon.
**)
val (eval_exp_rules, eval_exp_ind, eval_exp_cases) = Hol_reln `
(!E defVars m x v.
defVars x = SOME m /\
(!E Gamma m x v.
Gamma x = SOME m /\
E x = SOME v ==>
eval_exp E defVars (Var x) v m) /\
(!E defVars m n delta.
eval_exp E Gamma (Var x) v m) /\
(!E Gamma m n delta.
abs delta <= (mTypeToR m) ==>
eval_exp E defVars (Const m n) (perturb n delta) m) /\
(!E defVars m f1 v1.
eval_exp E defVars f1 v1 m ==>
eval_exp E defVars (Unop Neg f1) (evalUnop Neg v1) m) /\
(!E defVars m f1 v1 delta.
eval_exp E Gamma (Const m n) (perturb n m delta) m) /\
(!E Gamma m f1 v1.
eval_exp E Gamma f1 v1 m ==>
eval_exp E Gamma (Unop Neg f1) (evalUnop Neg v1) m) /\
(!E Gamma m f1 v1 delta.
abs delta <= (mTypeToR m) /\
(v1 <> 0) /\
eval_exp E defVars f1 v1 m ==>
eval_exp E defVars (Unop Inv f1) (perturb (evalUnop Inv v1) delta) m) /\
(!E defVars m m1 f1 v1 delta.
eval_exp E Gamma f1 v1 m /\
(v1 <> 0) ==>
eval_exp E Gamma (Unop Inv f1) (perturb (evalUnop Inv v1) m delta) m) /\
(!E Gamma m m1 f1 v1 delta.
isMorePrecise m1 m /\
abs delta <= (mTypeToR m) /\
eval_exp E defVars f1 v1 m1 ==>
eval_exp E defVars (Downcast m f1) (perturb v1 delta) m) /\
(!E defVars m1 m2 b f1 f2 v1 v2 delta.
eval_exp E Gamma f1 v1 m1 ==>
eval_exp E Gamma (Downcast m f1) (perturb v1 m delta) m) /\
(!E Gamma m1 m2 b f1 f2 v1 v2 delta.
abs delta <= (mTypeToR (join m1 m2)) /\
eval_exp E defVars f1 v1 m1 /\
eval_exp E defVars f2 v2 m2 /\
eval_exp E Gamma f1 v1 m1 /\
eval_exp E Gamma f2 v2 m2 /\
((b = Div) ==> (v2 <> 0)) ==>
eval_exp E defVars (Binop b f1 f2) (perturb (evalBinop b v1 v2) delta) (join m1 m2)) /\
(!E defVars m1 m2 m3 f1 f2 f3 v1 v2 v3 delta.
eval_exp E Gamma (Binop b f1 f2) (perturb (evalBinop b v1 v2) (join m1 m2) delta) (join m1 m2)) /\
(!E Gamma m1 m2 m3 f1 f2 f3 v1 v2 v3 delta.
abs delta <= (mTypeToR (join3 m1 m2 m3)) /\
eval_exp E defVars f1 v1 m1 /\
eval_exp E defVars f2 v2 m2 /\
eval_exp E defVars f3 v3 m3 ==>
eval_exp E defVars (Fma f1 f2 f3) (perturb (evalFma v1 v2 v3) delta) (join3 m1 m2 m3))`;
eval_exp E Gamma f1 v1 m1 /\
eval_exp E Gamma f2 v2 m2 /\
eval_exp E Gamma f3 v3 m3 ==>
eval_exp E Gamma (Fma f1 f2 f3) (perturb (evalFma v1 v2 v3) (join3 m1 m2 m3) delta) (join3 m1 m2 m3))`;
val eval_exp_cases_old = save_thm ("eval_exp_cases_old", eval_exp_cases);
......@@ -145,7 +147,7 @@ val Const_dist' = store_thm (
"Const_dist'",
``!m n delta v m' E Gamma.
(abs delta) <= (mTypeToR m) /\
v = perturb n delta /\
v = perturb n m delta /\
m' = m ==>
eval_exp E Gamma (Const m n) v m'``,
fs [Const_dist]);
......@@ -165,7 +167,7 @@ val Unop_inv' = store_thm (
(abs delta) <= (mTypeToR m) /\
eval_exp E Gamma f1 v1 m /\
(v1 <> 0) /\
v = perturb (evalUnop Inv v1) delta /\
v = perturb (evalUnop Inv v1) m delta /\
m' = m ==>
eval_exp E Gamma (Unop Inv f1) v m'``,
fs [Unop_inv]);
......@@ -175,7 +177,7 @@ val Downcast_dist' = store_thm ("Downcast_dist'",
isMorePrecise m1 m /\
(abs delta) <= (mTypeToR m) /\
eval_exp E Gamma f1 v1 m1 /\
v = perturb v1 delta /\
v = perturb v1 m delta /\
m' = m ==>
eval_exp E Gamma (Downcast m f1) v m'``,
rpt strip_tac
......@@ -189,7 +191,7 @@ val Binop_dist' = store_thm ("Binop_dist'",
eval_exp E Gamma f1 v1 m1 /\
eval_exp E Gamma f2 v2 m2 /\
((op = Div) ==> (v2 <> 0)) /\
v = perturb (evalBinop op v1 v2) delta /\
v = perturb (evalBinop op v1 v2) m' delta /\
m' = join m1 m2 ==>
eval_exp E Gamma (Binop op f1 f2) v m'``,
fs [Binop_dist]);
......@@ -200,7 +202,7 @@ val Fma_dist' = store_thm ("Fma_dist'",
eval_exp E Gamma f1 v1 m1 /\
eval_exp E Gamma f2 v2 m2 /\
eval_exp E Gamma f3 v3 m3 /\
v = perturb (evalFma v1 v2 v3) delta /\
v = perturb (evalFma v1 v2 v3) m' delta /\
m' = join3 m1 m2 m3 ==>
eval_exp E Gamma (Fma f1 f2 f3) v m'``,
fs [Fma_dist]);
......@@ -222,35 +224,40 @@ val usedVars_def = Define `
(**
If |delta| <= 0 then perturb v delta is exactly v.
**)
val delta_0_deterministic = store_thm("delta_0_deterministic",
``!(v:real) (delta:real). abs delta <= 0 ==> perturb v delta = v``,
val delta_0_deterministic = store_thm(
"delta_0_deterministic",
``!(v:real) (m:mType) (delta:real).
abs delta <= 0 ==> perturb v m delta = v``,
Cases_on `m` \\
fs [perturb_def,ABS_BOUNDS,REAL_LE_ANTISYM]);
val delta_M0_deterministic = store_thm("delta_M0_deterministic",
``!(v:real) (delta:real). abs delta <= mTypeToR M0 ==> perturb v delta = v``,
fs [mTypeToR_def,perturb_def,ABS_BOUNDS,REAL_LE_ANTISYM]);
val delta_REAL_deterministic = store_thm(
"delta_REAL_deterministic",
``!(v:real) (m:mType) (delta:real).
abs delta <= mTypeToR REAL ==> perturb v m delta = v``,
Cases_on `m` \\ fs[mTypeToR_def, delta_0_deterministic]);
val toRMap_def = Define `
toRMap (d:num -> mType option) (n:num) : mType option =
case d n of
| SOME m => SOME M0
| SOME m => SOME REAL
| NONE => NONE`;
val toRMap_eval_M0 = store_thm (
"toRMap_eval_M0",
val toRMap_eval_REAL = store_thm (
"toRMap_eval_REAL",
``!f v E Gamma m.
eval_exp E (toRMap Gamma) (toREval f) v m ==> m = M0``,
eval_exp E (toRMap Gamma) (toREval f) v m ==> m = REAL``,
Induct \\ fs[toREval_def] \\ fs[eval_exp_cases, toRMap_def]
\\ rpt strip_tac \\ fs[]
>- (every_case_tac \\ fs[])
>- (rveq \\ first_x_assum drule \\ strip_tac \\ fs[])
>- (rveq \\ first_x_assum drule \\ strip_tac \\ fs[])
>- (`m1 = M0` by (rpt (first_x_assum drule \\ strip_tac) \\ fs[])
\\ `m2 = M0` by (rpt (first_x_assum drule \\ strip_tac) \\ fs[])
>- (`m1 = REAL` by (rpt (first_x_assum drule \\ strip_tac) \\ fs[])
\\ `m2 = REAL` by (rpt (first_x_assum drule \\ strip_tac) \\ fs[])
\\ rveq \\ fs[join_def])
>- (`m1 = M0` by (rpt (first_x_assum drule \\ strip_tac) \\ fs[])
\\ `m2 = M0` by (rpt (first_x_assum drule \\ strip_tac) \\ fs[])
\\ `m3 = M0` by (rpt (first_x_assum drule \\ strip_tac) \\ fs[])
>- (`m1 = REAL` by (rpt (first_x_assum drule \\ strip_tac) \\ fs[])
\\ `m2 = REAL` by (rpt (first_x_assum drule \\ strip_tac) \\ fs[])
\\ `m3 = REAL` by (rpt (first_x_assum drule \\ strip_tac) \\ fs[])
\\ rveq \\ fs[join3_def] \\ fs[join_def]));
(**
......@@ -258,8 +265,8 @@ Evaluation with 0 as machine epsilon is deterministic
**)
val meps_0_deterministic = store_thm("meps_0_deterministic",
``!(f: real exp) v1:real v2:real E defVars.
eval_exp E (toRMap defVars) (toREval f) v1 M0 /\
eval_exp E (toRMap defVars) (toREval f) v2 M0 ==>
eval_exp E (toRMap defVars) (toREval f) v1 REAL /\
eval_exp E (toRMap defVars) (toREval f) v2 REAL ==>
v1 = v2``,
Induct_on `f`
>- (rw [toREval_def] \\ fs [eval_exp_cases])
......@@ -279,13 +286,13 @@ val meps_0_deterministic = store_thm("meps_0_deterministic",
qpat_x_assum `eval_exp _ _ (toREval _) _ _`
(fn thm => assume_tac (ONCE_REWRITE_RULE [toREval_def] thm)))
\\ Cases_on `b` \\ fs [eval_exp_cases]
\\ `m1 = M0 /\ m2 = M0` by (conj_tac \\ irule toRMap_eval_M0 \\ asm_exists_tac \\ fs [])
\\ `m1 = REAL /\ m2 = REAL` by (conj_tac \\ irule toRMap_eval_REAL \\ asm_exists_tac \\ fs [])
\\ rw[]
\\ rename1 `eval_exp E _ (toREval f1) vf11 M0`
\\ rename1 `eval_exp E _ (toREval f1) vf11 REAL`
\\ rename1 `eval_exp E _ (toREval f1) vf12 m1`
\\ rename1 `eval_exp E _ (toREval f2) vf21 M0`
\\ rename1 `eval_exp E _ (toREval f2) vf21 REAL`
\\ rename1 `eval_exp _ _ (toREval f2) vf22 m2`
\\ `m1 = M0 /\ m2 = M0` by (conj_tac \\ irule toRMap_eval_M0 \\ asm_exists_tac \\ fs [])
\\ `m1 = REAL /\ m2 = REAL` by (conj_tac \\ irule toRMap_eval_REAL \\ asm_exists_tac \\ fs [])
\\ rw []
\\ fs [join_def, mTypeToR_def, delta_0_deterministic]
\\ qpat_x_assum `!v1 v2 E defVars. _ /\ _ ==> v1 = v2` (fn thm =>qspecl_then [`vf21`,`vf22`] ASSUME_TAC thm)
......@@ -297,10 +304,10 @@ val meps_0_deterministic = store_thm("meps_0_deterministic",
qpat_x_assum `eval_exp _ _ (toREval _) _ _`
(fn thm => assume_tac (ONCE_REWRITE_RULE [toREval_def] thm)))
\\ fs [eval_exp_cases]
\\ `m1 = M0 /\ m2 = M0` by (conj_tac \\ irule toRMap_eval_M0 \\ asm_exists_tac \\ fs [])
\\ `m3 = M0` by (irule toRMap_eval_M0 \\ asm_exists_tac \\ fs [])
\\ `m1' = M0 /\ m2' = M0` by (conj_tac \\ irule toRMap_eval_M0 \\ asm_exists_tac \\ fs [])
\\ `m3' = M0` by (irule toRMap_eval_M0 \\ asm_exists_tac \\ fs [])
\\ `m1 = REAL /\ m2 = REAL` by (conj_tac \\ irule toRMap_eval_REAL \\ asm_exists_tac \\ fs [])
\\ `m3 = REAL` by (irule toRMap_eval_REAL \\ asm_exists_tac \\ fs [])
\\ `m1' = REAL /\ m2' = REAL` by (conj_tac \\ irule toRMap_eval_REAL \\ asm_exists_tac \\ fs [])
\\ `m3' = REAL` by (irule toRMap_eval_REAL \\ asm_exists_tac \\ fs [])
\\ rw[]
\\ qpat_x_assum `!v1 v2 E defVars. _ /\ _ ==> v1 = v2` (fn thm =>qspecl_then [`v3`,`v3'`, `E`, `defVars`] ASSUME_TAC thm)
\\ qpat_x_assum `!v1 v2 E defVars. _ /\ _ ==> v1 = v2` (fn thm =>qspecl_then [`v2'`,`v2''`, `E`, `defVars`] ASSUME_TAC thm)
......@@ -325,10 +332,10 @@ val binary_unfolding = store_thm("binary_unfolding",
(abs delta) <= (mTypeToR (join m1 m2)) /\
eval_exp E Gamma f1 v1 m1 /\
eval_exp E Gamma f2 v2 m2 /\
eval_exp E Gamma (Binop b f1 f2) (perturb (evalBinop b v1 v2) delta) (join m1 m2) ==>
eval_exp E Gamma (Binop b f1 f2) (perturb (evalBinop b v1 v2) (join m1 m2) delta) (join m1 m2) ==>
eval_exp (updEnv 2 v2 (updEnv 1 v1 emptyEnv))
(updDefVars 2 m2 (updDefVars 1 m1 Gamma))
(Binop b (Var 1) (Var 2)) (perturb (evalBinop b v1 v2) delta) (join m1 m2)``,
(Binop b (Var 1) (Var 2)) (perturb (evalBinop b v1 v2) (join m1 m2) delta) (join m1 m2)``,
fs [updEnv_def,updDefVars_def,join_def,eval_exp_cases,APPLY_UPDATE_THM,PULL_EXISTS]
\\ metis_tac []);
......@@ -338,10 +345,10 @@ val fma_unfolding = store_thm("fma_unfolding",
eval_exp E Gamma f1 v1 m1 /\
eval_exp E Gamma f2 v2 m2 /\
eval_exp E Gamma f3 v3 m3 /\
eval_exp E Gamma (Fma f1 f2 f3) (perturb (evalFma v1 v2 v3) delta) (join3 m1 m2 m3) ==>
eval_exp E Gamma (Fma f1 f2 f3) (perturb (evalFma v1 v2 v3) (join3 m1 m2 m3) delta) (join3 m1 m2 m3) ==>
eval_exp (updEnv 3 v3 (updEnv 2 v2 (updEnv 1 v1 emptyEnv)))
(updDefVars 3 m3 (updDefVars 2 m2 (updDefVars 1 m1 Gamma)))
(Fma (Var 1) (Var 2) (Var 3)) (perturb (evalFma v1 v2 v3) delta) (join3 m1 m2 m3)``,
(Fma (Var 1) (Var 2) (Var 3)) (perturb (evalFma v1 v2 v3) (join3 m1 m2 m3) delta) (join3 m1 m2 m3)``,
fs [updEnv_def,updDefVars_def,join3_def,join_def,eval_exp_cases,APPLY_UPDATE_THM,PULL_EXISTS]
\\ rpt strip_tac
\\ qexists_tac `delta'`
......
......@@ -150,7 +150,7 @@ val FPRangeValidator_sound = store_thm (
\\ disch_then drule \\ fs[])
\\ once_rewrite_tac [validFloatValue_def]
\\ `?iv err vR. FloverMapTree_find e A = SOME (iv, err) /\
eval_exp E1 (toRMap Gamma) (toREval e) vR M0 /\
eval_exp E1 (toRMap Gamma) (toREval e) vR REAL /\
FST iv <= vR /\ vR <= SND iv`
by (drule validIntervalbounds_sound
\\ disch_then (qspecl_then [`fVars`, `E1`, `Gamma`] impl_subgoal_tac)
......@@ -256,7 +256,7 @@ val FPRangeValidatorCmd_sound = store_thm (
\\ rpt strip_tac
\\ metis_tac[])
>- (irule swap_Gamma_bstep
\\ qexists_tac `updDefVars n M0 (toRMap Gamma)` \\ fs[]
\\ qexists_tac `updDefVars n REAL (toRMap Gamma)` \\ fs[]
\\ fs [updDefVars_def, REWRITE_RULE [updDefVars_def] Rmap_updVars_comm])
>- (fs[DIFF_DEF, domain_insert, SUBSET_DEF]
\\ rpt strip_tac \\ first_x_assum irule
......
......@@ -51,7 +51,7 @@ val bstep_float_def = Define `
val normal_or_zero_def = Define `
normal_or_zero (v:real) =
(minValue M64 <= abs v \/ v = 0)`;
(minValue_pos M64 <= abs v \/ v = 0)`;
val isValid_def = Define `
isValid e =
......@@ -155,7 +155,7 @@ val normalValue_implies_normalization = store_thm ("validFloatValue_implies_norm
normal v M64 ==>
normalizes (:52 #11) v``,
rpt strip_tac
\\ fs[normal_def, normalizes_def, wordsTheory.INT_MAX_def, minValue_def,
\\ fs[normal_def, normalizes_def, wordsTheory.INT_MAX_def, minValue_pos_def,
minExponentPos_def, wordsTheory.INT_MIN_def, wordsTheory.dimindex_11,
wordsTheory.UINT_MAX_def, wordsTheory.dimword_11]
\\ irule REAL_LET_TRANS
......@@ -179,11 +179,11 @@ val denormalValue_implies_finiteness = store_thm ("normalValue_implies_finitenes
\\ fs [real_to_float_def, denormal_def, dmode_def]
\\ irule float_round_finite
\\ irule REAL_LT_TRANS
\\ qexists_tac `minValue M64` \\ fs[]
\\ qexists_tac `minValue_pos M64` \\ fs[]
\\ irule REAL_LET_TRANS \\ qexists_tac `maxValue M64`
\\ `minValue M64 <= 1`
\\ `minValue_pos M64 <= 1`
by (once_rewrite_tac [GSYM REAL_INV1]
\\ fs[minValue_def, minExponentPos_def]
\\ fs[minValue_pos_def, minExponentPos_def]
\\ irule REAL_INV_LE_ANTIMONO_IMPR \\ fs[])
\\ fs[threshold_64_bit_lt_maxValue]
\\ irule REAL_LE_TRANS \\ qexists_tac `1`
......@@ -198,7 +198,7 @@ val normal_value_is_float_value = store_thm (
\\rewrite_tac[float_value_def]
\\rw_thm_asm `normal _ _` normal_def
\\fs[float_to_real_def]
\\ every_case_tac \\ fs[maxValue_def, maxExponent_def, minValue_def, minExponentPos_def]
\\ every_case_tac \\ fs[maxValue_def, maxExponent_def, minValue_pos_def, minExponentPos_def]
>-( Cases_on `ff.Sign` \\ fs[]
\\ Cases_on `n` \\ fs[]
\\ Cases_on `n'` \\ fs[])
......@@ -275,7 +275,7 @@ val denormal_value_is_float_value = store_thm ("denormal_value_is_float_value",
\\ `w2n (-1w:word11) = 2047` by EVAL_TAC
\\ `w2n c0 = 2047` by fs[]
\\ fs[]
\\ TOP_CASE_TAC \\ fs[minValue_def, minExponentPos_def]
\\ TOP_CASE_TAC \\ fs[minValue_pos_def, minExponentPos_def]
\\ fs[REAL_ABS_MUL, POW_M1]
>- (`44942328371557897693232629769725618340449424473557664318357520289433168951375240783177119330601884005280028469967848339414697442203604155623211857659868531094441973356216371319075554900311523529863270738021251442209537670585615720368478277635206809290837627671146574559986811484619929076208839082406056034304⁻¹ <= inv 1`
by (irule REAL_INV_LE_ANTIMONO_IMPR \\ fs[])
......@@ -638,7 +638,7 @@ val eval_exp_gives_IEEE = store_thm ("eval_exp_gives_IEEE",
\\ fs[eval_exp_float_def, optionLift_def]
\\ Cases_on `E2 n` \\ fs[optionLift_def, normal_or_zero_def])
>- (rveq \\ fs[eval_exp_cases]
\\ fs[optionLift_def, normal_or_zero_def, minValue_def,
\\ fs[optionLift_def, normal_or_zero_def, minValue_pos_def,
minExponentPos_def, REAL_LT_INV_EQ]
\\ qexists_tac `0:real`
\\ fs[mTypeToR_pos, perturb_def, fp64_to_float_float_to_fp64,
......@@ -721,7 +721,7 @@ val eval_exp_gives_IEEE = store_thm ("eval_exp_gives_IEEE",
\\ rename1 `eval_exp_float e1 _ = SOME vF1`
\\ rename1 `eval_exp_float e2 _ = SOME vF2`
\\ `?iv err nR2. FloverMapTree_find (toRExp e2) A = SOME (iv, err) /\
eval_exp E1 (toRMap Gamma) (toREval (toRExp e2)) nR2 M0 /\
eval_exp E1 (toRMap Gamma) (toREval (toRExp e2)) nR2 REAL /\
FST iv <= nR2 /\ nR2 <= SND iv`
by (irule validIntervalbounds_sound
\\ qexistsl_tac [`P`, `dVars`, `fVars`]
......@@ -782,8 +782,7 @@ val eval_exp_gives_IEEE = store_thm ("eval_exp_gives_IEEE",
\\ irule eval_eq_env
\\ asm_exists_tac \\ fs[eval_exp_cases]
\\ rewrite_tac [CONJ_ASSOC]
\\ rpt (once_rewrite_tac [CONJ_COMM]
\\ asm_exists_tac \\ fs[])
\\ rpt (once_rewrite_tac [CONJ_COMM] \\ asm_exists_tac \\ fs[])
\\ qexists_tac ` 0:real`
\\ Cases_on `b`
\\ fs[perturb_def, evalBinop_def, mTypeToR_pos, join_def])
......@@ -862,18 +861,19 @@ val eval_exp_gives_IEEE = store_thm ("eval_exp_gives_IEEE",
\\ qexistsl_tac [`M64`, `M64`, `float_to_real (fp64_to_float vF1)`,
`float_to_real (fp64_to_float vF2)`, `err`]
\\ fs[perturb_def, evalBinop_def]
\\ fs[mTypeToR_def, join_def])
\\ fs[mTypeToR_def, join_def, perturb_def])
(* result = 0 *)
>- (fs[REAL_LNEG_UNIQ, evalBinop_def]
>- (IMP_RES_TAC validValue_gives_float_value
\\ fs[REAL_LNEG_UNIQ, evalBinop_def]
\\ fs[fp64_add_def, dmode_def, fp64_to_float_float_to_fp64]
\\ fs[float_add_def]
\\ fs[float_add_def, float_round_with_flags_def]
\\ fs[join_def]
\\ qexistsl_tac [`M64`, `M64`, `float_to_real (fp64_to_float vF1)`, `float_to_real (fp64_to_float vF2)`, `0:real`]
\\ qexistsl_tac [`M64`, `M64`, `float_to_real (fp64_to_float vF1)`,
`float_to_real (fp64_to_float vF2)`, `0:real`]
\\ fs[perturb_def, mTypeToR_pos, evalBinop_def]
\\ fs[validValue_gives_float_value, float_round_with_flags_def]
\\ `2 * abs (0:real) <= ulp (:52 #11)`
by (fs[ulp_def, ULP_def])
\\ fs[ float_to_real_round_zero_is_zero])
\\ fs[float_to_real_round_zero_is_zero])
(* Subtraction, normal value *)
>- (fs[fp64_sub_def, fp64_to_float_float_to_fp64, evalBinop_def]
\\ `normal (evalBinop Sub (float_to_real (fp64_to_float vF1))
......@@ -905,7 +905,7 @@ val eval_exp_gives_IEEE = store_thm ("eval_exp_gives_IEEE",
\\ qexistsl_tac [`M64`, `M64`, `float_to_real (fp64_to_float vF1)`,
`float_to_real (fp64_to_float vF2)`, `err`]
\\ fs[perturb_def, evalBinop_def]
\\ fs[mTypeToR_def, join_def])
\\ fs[mTypeToR_def, join_def, perturb_def])
>- (fs[evalBinop_def]
\\ qpat_x_assum `float_to_real (fp64_to_float _) = _` MP_TAC
\\ simp[real_sub, REAL_LNEG_UNIQ, evalBinop_def]
......@@ -955,7 +955,7 @@ val eval_exp_gives_IEEE = store_thm ("eval_exp_gives_IEEE",
\\ qexistsl_tac [`M64`, `M64`, `float_to_real (fp64_to_float vF1)`,
`float_to_real (fp64_to_float vF2)`, `err`]
\\ fs[perturb_def, evalBinop_def]
\\ fs[mTypeToR_def, join_def])
\\ fs[mTypeToR_def, join_def, perturb_def])
>- (fs[evalBinop_def, REAL_ENTIRE, fp64_mul_def, float_mul_def,
GSYM float_is_zero_to_real, float_is_zero_def]
THENL [ Cases_on `float_value (fp64_to_float vF1)`,
......@@ -971,7 +971,7 @@ val eval_exp_gives_IEEE = store_thm ("eval_exp_gives_IEEE",
\\ qexistsl_tac [`M64`, `M64`, `float_to_real (fp64_to_float vF1)`,
`float_to_real (fp64_to_float vF2)`, `0:real`]
\\ rveq
\\ fs[GSYM float_is_zero_to_real, float_is_zero_def, join_def, mTypeToR_pos])
\\ fs[GSYM float_is_zero_to_real, float_is_zero_def, join_def, mTypeToR_pos, perturb_def])
(* Division *)
>- (fs[fp64_div_def, fp64_to_float_float_to_fp64, evalBinop_def]
\\ `normal (evalBinop Div (float_to_real (fp64_to_float vF1))
......@@ -1002,7 +1002,7 @@ val eval_exp_gives_IEEE = store_thm ("eval_exp_gives_IEEE",
\\ qexistsl_tac [`M64`, `M64`, `float_to_real (fp64_to_float vF1)`,
`float_to_real (fp64_to_float vF2)`, `err`]
\\ fs[perturb_def, evalBinop_def]
\\ fs[mTypeToR_def, join_def])
\\ fs[mTypeToR_def, join_def, perturb_def])
>- (fs[fp64_div_def, dmode_def, fp64_to_float_float_to_fp64,
float_div_def, evalBinop_def]
\\ `float_to_real (fp64_to_float vF1) = 0`
......@@ -1104,7 +1104,7 @@ val bstep_gives_IEEE = store_thm (
validIntervalboundsCmd (toRCmd f) A P dVars /\
validErrorboundCmd (toRCmd f) tMap A dVars /\
FPRangeValidatorCmd (toRCmd f) A tMap dVars /\
bstep (toREvalCmd (toRCmd f)) E1 (toRMap Gamma) vR M0 /\
bstep (toREvalCmd (toRCmd f)) E1 (toRMap Gamma) vR REAL /\
bstep (toRCmd f) (toREnv E2) Gamma vF M64 /\
domain (freeVars (toRCmd f)) DIFF domain dVars domain fVars
is64BitBstep (toRCmd f) /\
......@@ -1232,7 +1232,7 @@ val bstep_gives_IEEE = store_thm (
\\ fs[Once freeVars_def]
\\ simp[Once freeVars_def, domain_union])
>- (irule swap_Gamma_bstep
\\ qexists_tac `updDefVars n M0 (toRMap Gamma)` \\ fs[]
\\ qexists_tac `updDefVars n REAL (toRMap Gamma)` \\ fs[]
\\ strip_tac
\\ qspecl_then [`Gamma`, `n`, `M64`, `n'`] assume_tac Rmap_updVars_comm
\\ fs[updDefVars_def])
......@@ -1303,7 +1303,7 @@ val bstep_gives_IEEE = store_thm (
\\ rpt strip_tac
\\ metis_tac[])
>- (irule swap_Gamma_bstep
\\ qexists_tac `updDefVars n M0 (toRMap Gamma)` \\ fs[]
\\ qexists_tac `updDefVars n REAL (toRMap Gamma)` \\ fs[]
\\ rpt strip_tac
\\ qspecl_then [`Gamma`, `n`, `M64`, `n'`] assume_tac Rmap_updVars_comm
\\ fs[updDefVars_def])
......@@ -1393,7 +1393,7 @@ val IEEE_connection_exp = store_thm (
CertificateChecker (toRExp e) A P defVars ==>
?iv err vR vF. (* m, currently = M64 *)
FloverMapTree_find (toRExp e) A = SOME (iv, err) /\
eval_exp E1 (toRMap defVars) (toREval (toRExp e)) vR M0 /\
eval_exp E1 (toRMap defVars) (toREval (toRExp e)) vR REAL /\
eval_exp_float e E2 = SOME vF /\
eval_exp (toREnv E2) defVars (toRExp e) (float_to_real (fp64_to_float vF)) M64 /\
abs (vR - (float_to_real (fp64_to_float vF))) <= err``,
......@@ -1435,7 +1435,7 @@ val IEEE_connection_cmds = store_thm (
CertificateCheckerCmd (toRCmd f) A P defVars ==>
?iv err vR vF. (* m, currently = M64 *)
FloverMapTree_find (getRetExp (toRCmd f)) A = SOME (iv, err) /\
bstep (toREvalCmd (toRCmd f)) E1 (toRMap defVars) vR M0 /\
bstep (toREvalCmd (toRCmd f)) E1 (toRMap defVars) vR REAL /\
bstep_float f E2 = SOME vF /\
bstep (toRCmd f) (toREnv E2) defVars (float_to_real (fp64_to_float vF)) M64 /\
abs (vR - (float_to_real (fp64_to_float vF))) <= err``,
......
......@@ -196,6 +196,27 @@ fun Flover_compute t =
(split_pair_case_tac)) \\ fs[])))
end;
fun iter_exists_tac ind n =
fn tm =>
if ind < n
then
(part_match_exists_tac
(fn concl => List.nth (strip_conj concl, ind)) tm)
ORELSE (iter_exists_tac (ind+1) n tm)
else
FAIL_TAC (concat ["No matching clause found for ", term_to_string tm]) ;
val try_all:term -> tactic =
fn tm =>
fn (asl, g) =>
let
val len = length (strip_conj (snd (dest_exists g))) in
iter_exists_tac 0 len tm (asl, g)
end;
val find_exists_tac =
first_assum (try_all o concl);
(* val Flover_compute:tactic = *)
(* fn (g:goal) => *)
(* let *)
......
......@@ -4,7 +4,7 @@
@author: Raphael Monat
@maintainer: Heiko Becker
**)
open miscTheory realTheory realLib sptreeTheory;
open realTheory realLib sptreeTheory;
open RealSimpsTheory;
open preamble;
......@@ -13,13 +13,13 @@ val _ = new_theory "MachineType";
val _ = temp_overload_on("abs",``real$abs``);
val _ = Datatype `
mType = M0 | M16 | M32 | M64(* | M128 | M256 *)
mType = REAL | M16 | M32 | M64(* | M128 | M256 *)
|F num num (*first num is word length, second is fractional bits *)`;
val mTypeToR_def = Define `
mTypeToR (m:mType) : real =
case m of
| M0 => 0
| REAL => 0
| M16 => 1 / (2 pow 11)
| M32 => 1 / (2 pow 24)
| M64 => 1 / (2 pow 53)
......@@ -29,14 +29,10 @@ val mTypeToR_def = Define `
(* | M128 => 1 / (2 pow 105) *)
(* | M256 => 1 / (2 pow 211) *)`;
val _ = export_rewrites ["mTypeToR_def"];
(* val meps_def = Define `meps = mTypeToR`; *)
val computeError_def = Define `
computeError v m =
case m of
| M0 => 0
| REAL => 0
| F w f => mTypeToR m
| _ => abs v * mTypeToR m`;
......@@ -50,7 +46,7 @@ val computeError_up = store_thm (
``!v a b m.
abs v <= maxAbs (a,b) ==>
computeError v m <= computeError (maxAbs (a,b)) m``,
rpt strip_tac \\ Cases_on `m` \\ fs[computeError_def] \\ TRY RealArith.REAL_ASM_ARITH_TAC
rpt strip_tac \\ Cases_on `m` \\ fs[mTypeToR_def, computeError_def] \\ TRY RealArith.REAL_ASM_ARITH_TAC
\\ irule REAL_LE_RMUL_IMP \\ fs[]
\\ fs[maxAbs_def]
\\ `abs (real$max (abs a) (abs b)) = real$max (abs a) (abs b)`
......@@ -62,28 +58,28 @@ val computeError_up = store_thm (
(**
Check if machine precision m1 is more precise than machine precision m2.
M0 is real-valued evaluation, hence the most precise.
REAL is real-valued evaluation, hence the most precise.
All others are compared by
mTypeToR m1 <= mTypeToR m2
**)
val isMorePrecise_def = Define `
isMorePrecise (m1:mType) (m2:mType) =
case m1, m2 of
| M0, _ => T
| REAL, _ => T
| F w1 f1, F w2 f2 => w1 <= w2