Skip to content

Commit 393c1ed

Browse files
committed
Modernize FloVer for regression tests
1 parent b5f5853 commit 393c1ed

35 files changed

+812
-1218
lines changed

icing/flover/CertificateCheckerScript.sml

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ open AbbrevsTheory ExpressionsTheory FloverTactics ExpressionAbbrevsTheory
1313
open preambleFloVer;
1414

1515
val _ = new_theory "CertificateChecker";
16-
val _ = temp_overload_on("abs",``real$abs``);
16+
17+
Overload abs[local] = “real$abs”;
1718

1819
(** Certificate checking function **)
1920
Definition CertificateChecker_def:
+23-12
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
(**
2+
A simple, unverified generator for certificates.
3+
To be used in conjunction with the certificate checker to first analyze
4+
a kernel and then validate the analysis result
5+
**)
16
open RealIntervalInferenceTheory ErrorIntervalInferenceTheory ExpressionsTheory
27
FloverMapTheory TypeValidatorTheory CommandsTheory AbbrevsTheory
38
ExpressionAbbrevsTheory;
49
open preambleFloVer;
510

611
val _ = new_theory "CertificateGenerator";
712

8-
val CertificateGeneratorExp_def = Define `
13+
Definition CertificateGeneratorExp_def:
914
CertificateGeneratorExp (f:real expr) (P:precond) (Gamma:typeMap)
1015
:(real expr # precond # typeMap # analysisResult) option =
1116
let
@@ -17,15 +22,18 @@ val CertificateGeneratorExp_def = Define `
1722
(case inferErrorbound f tMap ivMap FloverMapTree_empty of
1823
| SOME errMap => SOME (f,P,Gamma,errMap)
1924
| NONE => NONE)
20-
| _, _ => NONE`;
25+
| _, _ => NONE
26+
End
2127

22-
val getExp_def = Define `
23-
getExp (f, P, Gamma, errMap) = f`;
28+
Definition getExp_def:
29+
getExp (f, P, Gamma, errMap) = f
30+
End
2431

25-
val getError_def = Define `
26-
getError (f, P, Gamma, errMap) = FloverMapTree_find f errMap`;
32+
Definition getError_def:
33+
getError (f, P, Gamma, errMap) = FloverMapTree_find f errMap
34+
End
2735

28-
val CertificateGeneratorCmd_def = Define `
36+
Definition CertificateGeneratorCmd_def:
2937
CertificateGeneratorCmd (f:real cmd) (P:precond) (Gamma:typeMap)
3038
:(real cmd # precond # typeMap # analysisResult) option =
3139
let
@@ -37,12 +45,15 @@ val CertificateGeneratorCmd_def = Define `
3745
(case inferErrorboundCmd f tMap ivMap FloverMapTree_empty of
3846
| SOME errMap => SOME (f,P,Gamma,errMap)
3947
| NONE => NONE)
40-
| _, _ => NONE`;
48+
| _, _ => NONE
49+
End
4150

42-
val getCmd_def = Define `
43-
getCmd (f, P, Gamma, errMap) = f`;
51+
Definition getCmd_def:
52+
getCmd (f, P, Gamma, errMap) = f
53+
End
4454

45-
val getError_def = Define `
46-
getError (f, P, Gamma, errMap) = FloverMapTree_find (getRetExp f) errMap`;
55+
Definition getError_def:
56+
getError (f, P, Gamma, errMap) = FloverMapTree_find (getRetExp f) errMap
57+
End
4758

4859
val _ = export_theory ();

icing/flover/EnvironmentsScript.sml

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
(**
2+
An inductive relation relating real-numbered environments with
3+
an environment with "errors", i.e. where variables are bound to
4+
finite-precision values
5+
**)
16
open simpLib realTheory realLib RealArith sptreeTheory;
27
open AbbrevsTheory ExpressionAbbrevsTheory RealSimpsTheory CommandsTheory
38
FloverTactics FloverMapTheory MachineTypeTheory;
49
open preambleFloVer;
510

611
val _ = new_theory "Environments";
712

8-
val _ = temp_overload_on("abs",``real$abs``);
13+
Overload abs[local] = real$abs
914

1015
Definition approxEnv_def:
1116
approxEnv E1 Gamma absEnv (fVars:num_set) (dVars:num_set) E2 =
@@ -98,8 +103,7 @@ Proof
98103
\\ fs[]
99104
QED
100105

101-
val approxEnv_rules = LIST_CONJ [approxEnvRefl, approxEnvUpdFree, approxEnvUpdBound]
102-
val _ = save_thm ("approxEnv_rules", approxEnv_rules);
106+
Theorem approxEnv_rules = LIST_CONJ [approxEnvRefl, approxEnvUpdFree, approxEnvUpdBound]
103107

104108
Theorem approxEnv_gives_value:
105109
!E1 E2 x v (fVars:num_set) (dVars:num_set) absenv Gamma.

icing/flover/ErrorBoundsScript.sml

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ open preambleFloVer;
1111
val _ = new_theory "ErrorBounds";
1212

1313
val _ = Parse.hide "delta"; (* so that it can be used as a variable *)
14-
val _ = temp_overload_on("abs",``real$abs``);
14+
15+
Overload abs[local] = “real$abs”
1516

1617
val triangle_tac =
1718
irule triangle_trans \\ rpt conj_tac \\ TRY (fs[REAL_ABS_TRIANGLE] \\ NO_TAC);

icing/flover/ErrorIntervalInferenceScript.sml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(**
1+
(**
22
This file contains the HOL4 implementation of the error bound validator as well
33
as its soundness proof. The function validErrorbound is the Error bound
44
validator from the certificate checking process. Under the assumption that a

icing/flover/ErrorValidationScript.sml

+4-5
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ open preambleFloVer;
1717
val _ = new_theory "ErrorValidation";
1818

1919
val _ = Parse.hide "delta"; (* so that it can be used as a variable *)
20-
val _ = temp_overload_on("abs",``real$abs``);
21-
val _ = temp_overload_on("+",``realax$real_add``);
22-
val _ = temp_overload_on("-",``real$real_sub``);
23-
val _ = temp_overload_on("*",``realax$real_mul``);
24-
val _ = temp_overload_on("/",``real$/``);
20+
21+
Overload abs[local] = “real$abs”
22+
23+
val _ = realLib.prefer_real();
2524

2625
val triangle_tac =
2726
irule triangle_trans \\ fs[REAL_ABS_TRIANGLE];

icing/flover/FPRangeValidatorScript.sml

+22-17
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ open preambleFloVer;
1818

1919
val _ = new_theory "FPRangeValidator";
2020

21-
val _ = temp_overload_on("abs",``real$abs``);
21+
Overload abs[local] = real$abs
2222

23-
val FPRangeValidator_def = Define `
23+
Definition FPRangeValidator_def:
2424
FPRangeValidator (e:real expr) A typeMap dVars =
2525
case FloverMapTree_find e A, FloverMapTree_find e typeMap of
2626
| SOME (iv_e, err_e), SOME m =>
@@ -58,28 +58,31 @@ val FPRangeValidator_def = Define `
5858
then normal_or_zero /\ recRes
5959
else
6060
F)
61-
| _, _ => F`;
61+
| _, _ => F
62+
End
6263

63-
val normalOrZero_def = Define `
64+
Definition normalOrZero_def:
6465
normalOrZero iv_e_float m =
6566
((normal (IVlo iv_e_float) m \/ (IVlo iv_e_float) = 0) /\
66-
(normal (IVhi iv_e_float) m \/ (IVhi iv_e_float) = 0))`;
67+
(normal (IVhi iv_e_float) m \/ (IVhi iv_e_float) = 0))
68+
End
6769

68-
val FPRangeValidatorCmd_def = Define `
70+
Definition FPRangeValidatorCmd_def:
6971
(FPRangeValidatorCmd ((Let m x e g):real cmd) A typeMap dVars =
7072
if FPRangeValidator e A typeMap dVars
7173
then FPRangeValidatorCmd g A typeMap (insert x () dVars)
7274
else F) /\
7375
(FPRangeValidatorCmd (Ret e) A typeMap dVars =
74-
FPRangeValidator e A typeMap dVars)`;
76+
FPRangeValidator e A typeMap dVars)
77+
End
7578

76-
val enclosure_to_abs = store_thm (
77-
"enclosure_to_abs",
78-
``!a b c.
79+
Theorem enclosure_to_abs:
80+
!a b c.
7981
a <= b /\ b <= c /\
8082
(0 < a \/ c < 0 ) ==>
8183
(abs a <= abs b /\ abs b <= abs c) \/
82-
(abs c <= abs b /\ abs b <= abs a)``,
84+
(abs c <= abs b /\ abs b <= abs a)
85+
Proof
8386
rpt strip_tac \\ fs[]
8487
>- (`0 < b` by REAL_ASM_ARITH_TAC
8588
\\ `0 <= a /\ 0 <= b` by REAL_ASM_ARITH_TAC
@@ -91,21 +94,22 @@ val enclosure_to_abs = store_thm (
9194
>- (`~ (0 <= b)` by REAL_ASM_ARITH_TAC
9295
\\ `~ (0 <= a)` by REAL_ASM_ARITH_TAC
9396
\\ `~ (0 <= c)` by REAL_ASM_ARITH_TAC
94-
\\ fs[realTheory.abs]));
97+
\\ fs[realTheory.abs])
98+
QED
9599

96100
fun assume_all l =
97101
case l of
98102
t :: ls => assume_tac t \\ assume_all ls
99103
| NIL => ALL_TAC;
100104

101-
val normal_enclosing = store_thm (
102-
"normal_enclosing",
103-
``!v m vHi vLo.
105+
Theorem normal_enclosing:
106+
!v m vHi vLo.
104107
(0 < vLo \/ vHi < 0) /\
105108
normal vLo m /\
106109
normal vHi m /\
107110
vLo <= v /\ v <= vHi ==>
108-
normal v m``,
111+
normal v m
112+
Proof
109113
rpt gen_tac
110114
\\ disch_then (fn thm => assume_all (CONJ_LIST 4 thm))
111115
\\ `(abs vLo <= abs v /\ abs v <= abs vHi) \/ (abs vHi <= abs v /\ abs v <= abs vLo)`
@@ -114,7 +118,8 @@ val normal_enclosing = store_thm (
114118
\\ fs[normal_def]
115119
\\ rveq
116120
\\ fs[]
117-
\\ RealArith.REAL_ASM_ARITH_TAC);
121+
\\ RealArith.REAL_ASM_ARITH_TAC
122+
QED
118123

119124
val solve_tac =
120125
rpt (qpat_x_assum `!x. _` kall_tac)

icing/flover/IEEE_connectionScript.sml

+39-23
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
(**
2+
Connect FloVer's idealized machine semantics to 64-bit
3+
IEEE-754 floating-point semantics
4+
**)
15
open machine_ieeeTheory binary_ieeeTheory lift_ieeeTheory realTheory RealArith;
26
open MachineTypeTheory ExpressionsTheory RealSimpsTheory FloverTactics
37
CertificateCheckerTheory FPRangeValidatorTheory IntervalValidationTheory
@@ -9,7 +13,8 @@ open preambleFloVer;
913

1014
val _ = new_theory "IEEE_connection";
1115

12-
val _ = temp_overload_on("abs",``real$abs``);
16+
Overload abs[local] = “real$abs”
17+
1318
val _ = diminish_srw_ss ["RMULCANON_ss","RMULRELNORM_ss"]
1419

1520
(** FloVer assumes rounding with ties to even, thus we exprlicitly define
@@ -295,30 +300,41 @@ Proof
295300
\\ `w2n c0 = 2047` by fs[] \\ fs[]
296301
\\ TOP_CASE_TAC \\ fs[minValue_pos_def, minExponentPos_def]
297302
\\ fs[REAL_ABS_MUL, POW_M1]
298-
>- (`44942328371557897693232629769725618340449424473557664318357520289433168951375240783177119330601884005280028469967848339414697442203604155623211857659868531094441973356216371319075554900311523529863270738021251442209537670585615720368478277635206809290837627671146574559986811484619929076208839082406056034304⁻¹ <= inv 1`
299-
by (irule REAL_INV_LE_ANTIMONO_IMPR \\ fs[])
300-
\\ fs[pow_simp1, REAL_DIV_LZERO, ABS_1, REAL_OF_NUM_POW, abs]
301-
\\ `179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639474124377767893424865485276302219601246094119453082952085005768838150682342462881473913110540827237163350510684586298239947245938479716304835356329624224137216 < inv 1`
302-
by (irule REAL_LTE_TRANS \\ asm_exists_tac \\ fs[])
303-
\\ fs[REAL_INV1])
303+
>- (
304+
qpat_x_assum ‘_ < inv _’ mp_tac
305+
\\ qmatch_goalsub_abbrev_tac ‘_ < inv cst1 ⇒ _’
306+
\\ strip_tac
307+
\\ `inv cst1 <= inv 1`
308+
by (unabbrev_all_tac \\ irule REAL_INV_LE_ANTIMONO_IMPR \\ fs[])
309+
\\ fs[pow_simp1, REAL_DIV_LZERO, ABS_1, REAL_OF_NUM_POW, abs]
310+
\\ qpat_x_assum ‘_ < inv cst1’ mp_tac
311+
\\ qmatch_goalsub_abbrev_tac ‘cst2 < inv cst1’ \\ strip_tac
312+
\\ `cst2 < inv 1`
313+
by (unabbrev_all_tac \\ irule REAL_LTE_TRANS \\ asm_exists_tac \\ fs[])
314+
\\ unabbrev_all_tac \\ fs[REAL_INV1])
304315
\\ Cases_on `c1` \\ fs[]
305316
\\ `1 < abs (1 + &n / 4503599627370496)`
306-
by (
307-
fs[abs]
308-
\\ `0:real <= 1 + &n / 4503599627370496`
309-
by (irule REAL_LE_TRANS
310-
\\ qexists_tac `1` \\ fs[]
311-
\\ irule REAL_LE_DIV \\ fs[])
312-
\\ fs[]
313-
\\ once_rewrite_tac [GSYM REAL_ADD_RID]
314-
\\ once_rewrite_tac [GSYM REAL_ADD_ASSOC]
315-
\\ fs[]
316-
\\ irule REAL_LT_DIV \\ fs[])
317-
\\ `44942328371557897693232629769725618340449424473557664318357520289433168951375240783177119330601884005280028469967848339414697442203604155623211857659868531094441973356216371319075554900311523529863270738021251442209537670585615720368478277635206809290837627671146574559986811484619929076208839082406056034304⁻¹ <= inv 1`
318-
by (irule REAL_INV_LE_ANTIMONO_IMPR \\ fs[])
317+
by (fs[abs]
318+
\\ `0:real <= 1 + &n / 4503599627370496`
319+
by (irule REAL_LE_TRANS
320+
\\ qexists_tac `1` \\ fs[]
321+
\\ irule REAL_LE_DIV \\ fs[])
322+
\\ fs[]
323+
\\ once_rewrite_tac [GSYM REAL_ADD_RID]
324+
\\ once_rewrite_tac [GSYM REAL_ADD_ASSOC]
325+
\\ fs[]
326+
\\ irule REAL_LT_DIV \\ fs[])
327+
\\ qpat_x_assum ‘_ < inv _’ mp_tac
328+
\\ qmatch_goalsub_abbrev_tac ‘_ < inv cst1 ⇒ _’
329+
\\ `inv cst1 <= inv 1`
330+
by (unabbrev_all_tac \\ irule REAL_INV_LE_ANTIMONO_IMPR \\ fs[])
331+
\\ strip_tac
319332
\\ fs[pow_simp1, REAL_DIV_LZERO, ABS_1, REAL_OF_NUM_POW, abs]
320-
\\ `179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639474124377767893424865485276302219601246094119453082952085005768838150682342462881473913110540827237163350510684586298239947245938479716304835356329624224137216 < inv 1`
321-
by (irule REAL_LTE_TRANS \\ once_rewrite_tac[CONJ_COMM]
333+
\\ qpat_x_assum ‘_ < inv cst1’ mp_tac
334+
\\ qmatch_goalsub_abbrev_tac ‘(cst2 * _) < inv cst1’
335+
\\ strip_tac
336+
\\ `cst2 < inv 1`
337+
by (unabbrev_all_tac \\ irule REAL_LTE_TRANS \\ once_rewrite_tac[CONJ_COMM]
322338
\\ rewrite_tac[REAL_INV1] \\ asm_exists_tac \\ fs[]
323339
\\ qmatch_goalsub_abbrev_tac `cst1 < cst2`
324340
\\ `0 <= (1:real) + &n / 4503599627370496`
@@ -332,7 +348,7 @@ Proof
332348
\\ once_rewrite_tac [GSYM REAL_MUL_ASSOC] \\ irule REAL_LT_LMUL_IMP
333349
\\ fs[]
334350
\\ unabbrev_all_tac \\ fs[])
335-
\\ fs[REAL_INV1]
351+
\\ unabbrev_all_tac \\ fs[REAL_INV1]
336352
QED
337353

338354
Theorem validValue_gives_float_value:

icing/flover/Infra/FloverCompLib.sml

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
(**
2+
Small changes to computeLib for FloVer
3+
**)
14
structure FloverCompLib =
25
struct
36
open computeLib;

icing/flover/Infra/Holmakefile

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1-
INCLUDES = $(HOLDIR)/examples/machine-code/hoare-triple $(HOLDIR)/examples/fun-op-sem/lprefix_lub
2-
31
OPTIONS = QUIT_ON_FAILURE
2+
3+
all: $(DEFAULT_TARGETS) README.md
4+
5+
README_SOURCES = $(wildcard *Script.sml) $(wildcard *Lib.sml) $(wildcard *Syntax.sml)
6+
DIRS = $(wildcard */)
7+
README.md: $(CAKEMLDIR)/developers/readme_gen readmePrefix $(patsubst %,%readmePrefix,$(DIRS)) $(README_SOURCES)
8+
$(CAKEMLDIR)/developers/readme_gen $(README_SOURCES)

icing/flover/Infra/MachineTypeScript.sml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ open preambleFloVer;
1010

1111
val _ = new_theory "MachineType";
1212

13-
val _ = temp_overload_on("abs",``real$abs``);
13+
Overload abs[local] = “real$abs”
14+
1415
val _ = monadsyntax.enable_monadsyntax();
1516
val _ = List.app monadsyntax.enable_monad ["option"];
1617

17-
1818
Datatype:
1919
mType = REAL | M16 | M32 | M64 | F num num bool (* first num is word length, second is fractional bits, bool is for sign of fractional bits *)
2020
End

0 commit comments

Comments
 (0)