1
1
enable_experimental;
2
2
3
+ load_sawcore_from_file "mr_solver_test_funs.sawcore";
4
+
3
5
let eq_bool b1 b2 =
4
6
if b1 then
5
7
if b2 then true else false
@@ -15,56 +17,102 @@ let run_test name test expected =
15
17
do { print "Test failed\n"; exit 1; }; };
16
18
17
19
// The constant 0 function const0 x = 0
18
- const0 <- parse_core
19
- "\\ (_:Vec 64 Bool) -> retS VoidEv emptyFunStack (Vec 64 Bool) (bvNat 64 0)";
20
+ let ret0_core = "retS VoidEv emptyFunStack (Vec 64 Bool) (bvNat 64 0)";
21
+ let const0_core = str_concat "\\ (_:Vec 64 Bool) -> " ret0_core;
22
+ const0 <- parse_core const0_core;
20
23
21
24
// The constant 1 function const1 x = 1
22
- const1 <- parse_core
23
- "\\ (_:Vec 64 Bool) -> retS VoidEv emptyFunStack (Vec 64 Bool) (bvNat 64 1)" ;
25
+ let const1_core = "\\ (_:Vec 64 Bool) -> retS VoidEv emptyFunStack (Vec 64 Bool) (bvNat 64 1)";
26
+ const1 <- parse_core const1_core ;
24
27
25
28
// const0 <= const0
26
29
run_test "const0 |= const0" (mr_solver_query const0 const0) true;
27
-
28
- /*
29
- // The function test_fun0 from the prelude = const0
30
- test_fun0 <- parse_core "test_fun0";
30
+ // (using mrsolver tactic)
31
+ let const0_refines =
32
+ str_concats ["(x:Vec 64 Bool) -> refinesS_eq VoidEv emptyFunStack (Vec 64 Bool) ",
33
+ "((", const0_core, ") x) ", "((", const0_core, ") x)"];
34
+ prove_extcore mrsolver (parse_core const0_refines);
35
+
36
+ // The function test_fun0 = const0
37
+ test_fun0 <- parse_core_mod "test_funs" "test_fun0";
31
38
run_test "const0 |= test_fun0" (mr_solver_query const0 test_fun0) true;
39
+ // (using mrsolver tactic)
40
+ let const0_test_fun0_refines =
41
+ str_concats ["(x:Vec 64 Bool) -> refinesS_eq VoidEv emptyFunStack (Vec 64 Bool) ",
42
+ "((", const0_core, ") x) ", "(test_fun0 x)"];
43
+ prove_extcore mrsolver (parse_core_mod "test_funs" const0_test_fun0_refines);
32
44
33
45
// not const0 <= const1
34
46
run_test "const0 |= const1" (mr_solver_query const0 const1) false;
35
-
36
- // The function test_fun1 from the prelude = const1
37
- test_fun1 <- parse_core "test_fun1";
47
+ // (using mrsolver tactic - fails as expected)
48
+ // let const0_const1_refines =
49
+ // str_concats ["(x:Vec 64 Bool) -> refinesS_eq VoidEv emptyFunStack (Vec 64 Bool) ",
50
+ // "((", const0_core, ") x) ", "((", const1_core, ") x)"];
51
+ // prove_extcore mrsolver (parse_core const0_const1_refines);
52
+
53
+ // The function test_fun1 = const1
54
+ test_fun1 <- parse_core_mod "test_funs" "test_fun1";
38
55
run_test "const1 |= test_fun1" (mr_solver_query const1 test_fun1) true;
39
56
run_test "const0 |= test_fun1" (mr_solver_query const0 test_fun1) false;
40
- */
57
+ // (using mrsolver tactic)
58
+ let const1_test_fun1_refines =
59
+ str_concats ["(x:Vec 64 Bool) -> refinesS_eq VoidEv emptyFunStack (Vec 64 Bool) ",
60
+ "((", const1_core, ") x) ", "(test_fun1 x)"];
61
+ prove_extcore mrsolver (parse_core_mod "test_funs" const1_test_fun1_refines);
62
+ // (using mrsolver tactic - fails as expected)
63
+ // let const0_test_fun1_refines =
64
+ // str_concats ["(x:Vec 64 Bool) -> refinesS_eq VoidEv emptyFunStack (Vec 64 Bool) ",
65
+ // "((", const0_core, ") x) ", "(test_fun1 x)"];
66
+ // prove_extcore mrsolver (parse_core_mod "test_funs" const0_test_fun1_refines);
41
67
42
68
// ifxEq0 x = If x == 0 then x else 0; should be equal to 0
43
- ifxEq0 <- parse_core "\\ (x:Vec 64 Bool) -> \
69
+ let ifxEq0_core = "\\ (x:Vec 64 Bool) -> \
44
70
\ ite (SpecM VoidEv emptyFunStack (Vec 64 Bool)) \
45
71
\ (bvEq 64 x (bvNat 64 0)) \
46
72
\ (retS VoidEv emptyFunStack (Vec 64 Bool) x) \
47
73
\ (retS VoidEv emptyFunStack (Vec 64 Bool) (bvNat 64 0))";
74
+ ifxEq0 <- parse_core ifxEq0_core;
48
75
49
76
// ifxEq0 <= const0
50
77
run_test "ifxEq0 |= const0" (mr_solver_query ifxEq0 const0) true;
78
+ // (using mrsolver tactic)
79
+ let ifxEq0_const0_refines =
80
+ str_concats ["(x:Vec 64 Bool) -> refinesS_eq VoidEv emptyFunStack (Vec 64 Bool) ",
81
+ "((", ifxEq0_core, ") x) ", "((", const0_core, ") x)"];
82
+ prove_extcore mrsolver (parse_core ifxEq0_const0_refines);
51
83
52
84
// not ifxEq0 <= const1
53
85
run_test "ifxEq0 |= const1" (mr_solver_query ifxEq0 const1) false;
86
+ // (using mrsolver tactic - fails as expected)
87
+ // let ifxEq0_const1_refines =
88
+ // str_concats ["(x:Vec 64 Bool) -> refinesS_eq VoidEv emptyFunStack (Vec 64 Bool) ",
89
+ // "((", ifxEq0_core, ") x) ", "((", const1_core, ") x)"];
90
+ // prove_extcore mrsolver (parse_core ifxEq0_const1_refines);
54
91
55
92
// noErrors1 x = existsS x. retS x
56
- noErrors1 <- parse_core
93
+ let noErrors1_core =
57
94
"\\ (_:Vec 64 Bool) -> existsS VoidEv emptyFunStack (Vec 64 Bool)";
95
+ noErrors1 <- parse_core noErrors1_core;
58
96
59
97
// const0 <= noErrors
60
98
run_test "noErrors1 |= noErrors1" (mr_solver_query noErrors1 noErrors1) true;
99
+ // (using mrsolver tactic)
100
+ let noErrors1_refines =
101
+ str_concats ["(x:Vec 64 Bool) -> refinesS_eq VoidEv emptyFunStack (Vec 64 Bool) ",
102
+ "((", noErrors1_core, ") x) ", "((", noErrors1_core, ") x)"];
103
+ prove_extcore mrsolver (parse_core noErrors1_refines);
61
104
62
105
// const1 <= noErrors
63
106
run_test "const1 |= noErrors1" (mr_solver_query const1 noErrors1) true;
107
+ // (using mrsolver tactic)
108
+ let const1_noErrors1_refines =
109
+ str_concats ["(x:Vec 64 Bool) -> refinesS_eq VoidEv emptyFunStack (Vec 64 Bool) ",
110
+ "((", const1_core, ") x) ", "((", noErrors1_core, ") x)"];
111
+ prove_extcore mrsolver (parse_core const1_noErrors1_refines);
64
112
65
113
// noErrorsRec1 _ = orS (existsM x. returnM x) (noErrorsRec1 x)
66
114
// Intuitively, this specifies functions that either return a value or loop
67
- noErrorsRec1 <- parse_core
115
+ let noErrorsRec1_core =
68
116
"fixS VoidEv emptyFunStack (Vec 64 Bool) (\\ (_:Vec 64 Bool) -> Vec 64 Bool) \
69
117
\ (\\ (f: fixSFun VoidEv emptyFunStack \
70
118
\ (Vec 64 Bool) (\\ (_:Vec 64 Bool) -> Vec 64 Bool)) \
@@ -76,13 +124,20 @@ noErrorsRec1 <- parse_core
76
124
\ (\\ (_:Vec 64 Bool) -> Vec 64 Bool)) \
77
125
\ (Vec 64 Bool)) \
78
126
\ (f x))";
127
+ noErrorsRec1 <- parse_core noErrorsRec1_core;
79
128
80
129
// loop x = loop x
81
- loop1 <- parse_core
130
+ let loop1_core =
82
131
"fixS VoidEv emptyFunStack (Vec 64 Bool) (\\ (_:Vec 64 Bool) -> Vec 64 Bool) \
83
132
\ (\\ (f: fixSFun VoidEv emptyFunStack \
84
133
\ (Vec 64 Bool) (\\ (_:Vec 64 Bool) -> Vec 64 Bool)) \
85
134
\ (x:Vec 64 Bool) -> f x)";
135
+ loop1 <- parse_core loop1_core;
86
136
87
137
// loop1 <= noErrorsRec1
88
138
run_test "loop1 |= noErrorsRec1" (mr_solver_query loop1 noErrorsRec1) true;
139
+ // (using mrsolver tactic)
140
+ let loop1_noErrorsRec1_refines =
141
+ str_concats ["(x:Vec 64 Bool) -> refinesS_eq VoidEv emptyFunStack (Vec 64 Bool) ",
142
+ "((", loop1_core, ") x) ", "((", noErrorsRec1_core, ") x)"];
143
+ prove_extcore mrsolver (parse_core loop1_noErrorsRec1_refines);
0 commit comments