z3 0.0.20160427 → 0.0.20161008
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/Rakefile +56 -0
- data/examples/bit_tricks +21 -38
- data/examples/circuit_problems +170 -0
- data/lib/z3/ast.rb +21 -3
- data/lib/z3/context.rb +9 -7
- data/lib/z3/exception.rb +1 -2
- data/lib/z3/expr/arith_expr.rb +29 -11
- data/lib/z3/expr/array_expr.rb +5 -0
- data/lib/z3/expr/bitvec_expr.rb +293 -13
- data/lib/z3/expr/bool_expr.rb +30 -6
- data/lib/z3/expr/expr.rb +155 -2
- data/lib/z3/expr/float_expr.rb +185 -0
- data/lib/z3/expr/int_expr.rb +20 -5
- data/lib/z3/expr/real_expr.rb +1 -3
- data/lib/z3/expr/rounding_mode_expr.rb +5 -0
- data/lib/z3/expr/set_expr.rb +66 -0
- data/lib/z3/func_decl.rb +5 -5
- data/lib/z3/goal.rb +64 -0
- data/lib/z3/interface.rb +21 -222
- data/lib/z3/low_level.rb +84 -58
- data/lib/z3/low_level_auto.rb +1509 -1563
- data/lib/z3/model.rb +39 -37
- data/lib/z3/printer.rb +54 -12
- data/lib/z3/probe.rb +69 -0
- data/lib/z3/solver.rb +20 -20
- data/lib/z3/sort/array_sort.rb +24 -0
- data/lib/z3/sort/bitvec_sort.rb +1 -1
- data/lib/z3/sort/float_sort.rb +92 -0
- data/lib/z3/sort/rounding_mode_sort.rb +41 -0
- data/lib/z3/sort/set_sort.rb +31 -0
- data/lib/z3/sort/sort.rb +39 -5
- data/lib/z3/tactic.rb +69 -0
- data/lib/z3/very_low_level.rb +33 -29
- data/lib/z3/very_low_level_auto.rb +505 -517
- data/lib/z3.rb +13 -0
- data/spec/array_expr_spec.rb +18 -0
- data/spec/array_sort_spec.rb +11 -0
- data/spec/bitvec_expr_spec.rb +196 -44
- data/spec/bitvec_sort_spec.rb +29 -27
- data/spec/bool_expr_spec.rb +57 -55
- data/spec/bool_sort_spec.rb +17 -15
- data/spec/coverage_helper.rb +11 -0
- data/spec/expr_spec.rb +151 -147
- data/spec/float_expr_spec.rb +167 -0
- data/spec/float_sort_spec.rb +44 -0
- data/spec/goal_spec.rb +17 -0
- data/spec/int_expr_spec.rb +76 -63
- data/spec/int_sort_spec.rb +16 -14
- data/spec/integration/algebra_problems_spec.rb +4 -4
- data/spec/integration/cicruit_problem_spec.rb +23 -0
- data/spec/integration/geometry_problem_spec.rb +4 -4
- data/spec/integration/kinematics_problems_spec.rb +3 -3
- data/spec/model_spec.rb +39 -37
- data/spec/printer_spec.rb +49 -18
- data/spec/probe_spec.rb +17 -0
- data/spec/real_expr_spec.rb +59 -51
- data/spec/real_sort_spec.rb +22 -20
- data/spec/rounding_mode_expr_spec.rb +16 -0
- data/spec/rounding_mode_sort_spec.rb +13 -0
- data/spec/set_expr_spec.rb +61 -0
- data/spec/set_sort_spec.rb +27 -0
- data/spec/solver_spec.rb +37 -27
- data/spec/sort_spec.rb +38 -36
- data/spec/spec_helper.rb +59 -2
- data/spec/tactic_spec.rb +9 -0
- metadata +44 -4
data/lib/z3.rb
CHANGED
@@ -21,6 +21,10 @@ require_relative "z3/sort/int_sort"
|
|
21
21
|
require_relative "z3/sort/real_sort"
|
22
22
|
require_relative "z3/sort/bool_sort"
|
23
23
|
require_relative "z3/sort/bitvec_sort"
|
24
|
+
require_relative "z3/sort/float_sort"
|
25
|
+
require_relative "z3/sort/rounding_mode_sort"
|
26
|
+
require_relative "z3/sort/set_sort"
|
27
|
+
require_relative "z3/sort/array_sort"
|
24
28
|
|
25
29
|
# ASTs
|
26
30
|
require_relative "z3/expr/expr"
|
@@ -29,6 +33,15 @@ require_relative "z3/expr/int_expr"
|
|
29
33
|
require_relative "z3/expr/real_expr"
|
30
34
|
require_relative "z3/expr/bool_expr"
|
31
35
|
require_relative "z3/expr/bitvec_expr"
|
36
|
+
require_relative "z3/expr/float_expr"
|
37
|
+
require_relative "z3/expr/rounding_mode_expr"
|
38
|
+
require_relative "z3/expr/set_expr"
|
39
|
+
require_relative "z3/expr/array_expr"
|
40
|
+
|
41
|
+
# Tactics, Probes, and Goals
|
42
|
+
require_relative "z3/tactic"
|
43
|
+
require_relative "z3/probe"
|
44
|
+
require_relative "z3/goal"
|
32
45
|
|
33
46
|
# Python-style interface
|
34
47
|
require_relative "z3/interface"
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Z3
|
2
|
+
describe ArrayExpr do
|
3
|
+
let(:sort) { ArraySort.new(IntSort.new, IntSort.new) }
|
4
|
+
let(:a) { sort.var("a") }
|
5
|
+
let(:b) { sort.var("b") }
|
6
|
+
let(:c) { sort.var("c") }
|
7
|
+
let(:x) { Z3::Bool("x") }
|
8
|
+
|
9
|
+
# TODO: Formatting is dreadful
|
10
|
+
it "== and !=" do
|
11
|
+
expect([a == b, b != c]).to have_solution(
|
12
|
+
a => "store(const(0), 0, 1)",
|
13
|
+
b => "store(const(0), 0, 1)",
|
14
|
+
c => "const(0)",
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Z3
|
2
|
+
describe ArraySort do
|
3
|
+
let(:int_int_array) { ArraySort.new(IntSort.new, IntSort.new) }
|
4
|
+
let(:int_real_array) { ArraySort.new(IntSort.new, RealSort.new) }
|
5
|
+
|
6
|
+
it "can instantiate variables" do
|
7
|
+
expect(int_int_array.var("a").inspect).to eq("Array(Int, Int)<a>")
|
8
|
+
expect(int_real_array.var("a").inspect).to eq("Array(Int, Real)<a>")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/spec/bitvec_expr_spec.rb
CHANGED
@@ -1,55 +1,207 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
expect([a == 2, b == -254, x == (a == b)]).to have_solution(x => true)
|
9
|
-
expect([a == 2, b == 2, x == (a == b)]).to have_solution(x => true)
|
10
|
-
expect([a == 2, b == 3, x == (a == b)]).to have_solution(x => false)
|
11
|
-
end
|
1
|
+
module Z3
|
2
|
+
describe BitvecExpr do
|
3
|
+
let(:a) { Z3.Bitvec("a", 8) }
|
4
|
+
let(:b) { Z3.Bitvec("b", 8) }
|
5
|
+
let(:c) { Z3.Bitvec("c", 8) }
|
6
|
+
let(:d) { Z3.Bitvec("d", 12) }
|
7
|
+
let(:x) { Z3.Bool("x") }
|
12
8
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
9
|
+
it "==" do
|
10
|
+
expect([a == 2, b == -254, x == (a == b)]).to have_solution(x => true)
|
11
|
+
expect([a == 2, b == 2, x == (a == b)]).to have_solution(x => true)
|
12
|
+
expect([a == 2, b == 3, x == (a == b)]).to have_solution(x => false)
|
13
|
+
end
|
18
14
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
15
|
+
it "!=" do
|
16
|
+
expect([a == 2, b == -254, x == (a != b)]).to have_solution(x => false)
|
17
|
+
expect([a == 2, b == 2, x == (a != b)]).to have_solution(x => false)
|
18
|
+
expect([a == 2, b == 3, x == (a != b)]).to have_solution(x => true)
|
19
|
+
end
|
24
20
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
21
|
+
it "+" do
|
22
|
+
expect([a == 2, b == 40, c == (a + b)]).to have_solution(c => 42)
|
23
|
+
expect([a == 200, b == 40, c == (a + b)]).to have_solution(c => 240)
|
24
|
+
expect([a == -1, b == -1, c == (a + b)]).to have_solution(c => 254)
|
25
|
+
end
|
30
26
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
27
|
+
it "-" do
|
28
|
+
expect([a == 50, b == 8, c == (a - b)]).to have_solution(c => 42)
|
29
|
+
expect([a == 200, b == 40, c == (a - b)]).to have_solution(c => 160)
|
30
|
+
expect([a == 40, b == 200, c == (a - b)]).to have_solution(c => 96)
|
31
|
+
end
|
35
32
|
|
36
|
-
|
37
|
-
|
38
|
-
|
33
|
+
it "*" do
|
34
|
+
expect([a == 3, b == 40, c == (a * b)]).to have_solution(c => 120)
|
35
|
+
expect([a == 30, b == 42, c == (a * b)]).to have_solution(c => 236)
|
36
|
+
end
|
39
37
|
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
it "&" do
|
39
|
+
expect([a == 50, b == 27, c == (a & b)]).to have_solution(c => 18)
|
40
|
+
end
|
43
41
|
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
it "|" do
|
43
|
+
expect([a == 50, b == 27, c == (a | b)]).to have_solution(c => 59)
|
44
|
+
end
|
47
45
|
|
48
|
-
|
49
|
-
|
50
|
-
|
46
|
+
it "^" do
|
47
|
+
expect([a == 50, b == 27, c == (a ^ b)]).to have_solution(c => 41)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "xnor" do
|
51
|
+
expect([a == 50, b == 27, c == a.xnor(b)]).to have_solution(c => 214)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "nand" do
|
55
|
+
expect([a == 50, b == 27, c == a.nand(b)]).to have_solution(c => 237)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "nor" do
|
59
|
+
expect([a == 50, b == 27, c == a.nor(b)]).to have_solution(c => 196)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "unary -" do
|
63
|
+
expect([a == 50, b == -a]).to have_solution(b => 206)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "~" do
|
67
|
+
expect([a == 50, b == ~a]).to have_solution(b => 205)
|
68
|
+
end
|
69
|
+
|
70
|
+
it ">> (sign-dependent)" do
|
71
|
+
expect([a == 234, b == 2, c == a.unsigned_rshift(b)]).to have_solution(c => 58)
|
72
|
+
expect([a == 234, b == 2, c == a.signed_rshift(b)]).to have_solution(c => 250)
|
73
|
+
expect{ a.rshift(b) }.to raise_error(Z3::Exception)
|
74
|
+
expect{ a >> b }.to raise_error(Z3::Exception)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "<< (sign-independent)" do
|
78
|
+
expect([a == 234, b == 2, c == a.signed_lshift(b)]).to have_solution(c => 168)
|
79
|
+
expect([a == 234, b == 2, c == a.unsigned_lshift(b)]).to have_solution(c => 168)
|
80
|
+
expect([a == 234, b == 2, c == a.lshift(b)]).to have_solution(c => 168)
|
81
|
+
expect([a == 234, b == 2, c == (a << b)]).to have_solution(c => 168)
|
82
|
+
end
|
83
|
+
|
84
|
+
it ">" do
|
85
|
+
expect{ a > b }.to raise_error(Z3::Exception)
|
86
|
+
expect([a == 100, b == 20, x == a.unsigned_gt(b)]).to have_solution(x => true)
|
87
|
+
expect([a == 100, b == 100, x == a.unsigned_gt(b)]).to have_solution(x => false)
|
88
|
+
expect([a == 100, b == 120, x == a.unsigned_gt(b)]).to have_solution(x => false)
|
89
|
+
expect([a == 100, b == 200, x == a.unsigned_gt(b)]).to have_solution(x => false)
|
90
|
+
expect([a == 100, b == 20, x == a.signed_gt(b)]).to have_solution(x => true)
|
91
|
+
expect([a == 100, b == 100, x == a.signed_gt(b)]).to have_solution(x => false)
|
92
|
+
expect([a == 100, b == 120, x == a.signed_gt(b)]).to have_solution(x => false)
|
93
|
+
expect([a == 100, b == 200, x == a.signed_gt(b)]).to have_solution(x => true)
|
94
|
+
end
|
95
|
+
|
96
|
+
it ">=" do
|
97
|
+
expect{ a >= b }.to raise_error(Z3::Exception)
|
98
|
+
expect([a == 100, b == 20, x == a.unsigned_ge(b)]).to have_solution(x => true)
|
99
|
+
expect([a == 100, b == 100, x == a.unsigned_ge(b)]).to have_solution(x => true)
|
100
|
+
expect([a == 100, b == 120, x == a.unsigned_ge(b)]).to have_solution(x => false)
|
101
|
+
expect([a == 100, b == 200, x == a.unsigned_ge(b)]).to have_solution(x => false)
|
102
|
+
expect([a == 100, b == 20, x == a.signed_ge(b)]).to have_solution(x => true)
|
103
|
+
expect([a == 100, b == 100, x == a.signed_ge(b)]).to have_solution(x => true)
|
104
|
+
expect([a == 100, b == 120, x == a.signed_ge(b)]).to have_solution(x => false)
|
105
|
+
expect([a == 100, b == 200, x == a.signed_ge(b)]).to have_solution(x => true)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "<" do
|
109
|
+
expect{ a < b }.to raise_error(Z3::Exception)
|
110
|
+
expect([a == 100, b == 20, x == a.unsigned_lt(b)]).to have_solution(x => false)
|
111
|
+
expect([a == 100, b == 100, x == a.unsigned_lt(b)]).to have_solution(x => false)
|
112
|
+
expect([a == 100, b == 120, x == a.unsigned_lt(b)]).to have_solution(x => true)
|
113
|
+
expect([a == 100, b == 200, x == a.unsigned_lt(b)]).to have_solution(x => true)
|
114
|
+
expect([a == 100, b == 20, x == a.signed_lt(b)]).to have_solution(x => false)
|
115
|
+
expect([a == 100, b == 100, x == a.signed_lt(b)]).to have_solution(x => false)
|
116
|
+
expect([a == 100, b == 120, x == a.signed_lt(b)]).to have_solution(x => true)
|
117
|
+
expect([a == 100, b == 200, x == a.signed_lt(b)]).to have_solution(x => false)
|
118
|
+
end
|
119
|
+
|
120
|
+
it "<=" do
|
121
|
+
expect{ a <= b }.to raise_error(Z3::Exception)
|
122
|
+
expect([a == 100, b == 20, x == a.unsigned_le(b)]).to have_solution(x => false)
|
123
|
+
expect([a == 100, b == 100, x == a.unsigned_le(b)]).to have_solution(x => true)
|
124
|
+
expect([a == 100, b == 120, x == a.unsigned_le(b)]).to have_solution(x => true)
|
125
|
+
expect([a == 100, b == 200, x == a.unsigned_le(b)]).to have_solution(x => true)
|
126
|
+
expect([a == 100, b == 20, x == a.signed_le(b)]).to have_solution(x => false)
|
127
|
+
expect([a == 100, b == 100, x == a.signed_le(b)]).to have_solution(x => true)
|
128
|
+
expect([a == 100, b == 120, x == a.signed_le(b)]).to have_solution(x => true)
|
129
|
+
expect([a == 100, b == 200, x == a.signed_le(b)]).to have_solution(x => false)
|
130
|
+
end
|
131
|
+
|
132
|
+
it "signed_add_no_overflow?" do
|
133
|
+
expect([a == 100, b == 100, x == a.signed_add_no_overflow?(b)]).to have_solution(x => false)
|
134
|
+
expect([a == 50, b == 50, x == a.signed_add_no_overflow?(b)]).to have_solution(x => true)
|
135
|
+
expect([a == -50, b == -50, x == a.signed_add_no_overflow?(b)]).to have_solution(x => true)
|
136
|
+
expect([a == -100, b == -100, x == a.signed_add_no_overflow?(b)]).to have_solution(x => true)
|
137
|
+
end
|
138
|
+
|
139
|
+
it "unsigned_add_no_overflow?" do
|
140
|
+
expect([a == 100, b == 100, x == a.unsigned_add_no_overflow?(b)]).to have_solution(x => true)
|
141
|
+
expect([a == 50, b == 50, x == a.unsigned_add_no_overflow?(b)]).to have_solution(x => true)
|
142
|
+
expect([a == -50, b == -50, x == a.unsigned_add_no_overflow?(b)]).to have_solution(x => false)
|
143
|
+
expect([a == -100, b == -100, x == a.unsigned_add_no_overflow?(b)]).to have_solution(x => false)
|
144
|
+
end
|
145
|
+
|
146
|
+
# Inherently signed, unsigned add can't underflow
|
147
|
+
it "signed_add_no_underflow?" do
|
148
|
+
expect([a == 100, b == 100, x == a.signed_add_no_underflow?(b)]).to have_solution(x => true)
|
149
|
+
expect([a == 50, b == 50, x == a.signed_add_no_underflow?(b)]).to have_solution(x => true)
|
150
|
+
expect([a == -50, b == -50, x == a.signed_add_no_underflow?(b)]).to have_solution(x => true)
|
151
|
+
expect([a == -100, b == -100, x == a.signed_add_no_underflow?(b)]).to have_solution(x => false)
|
152
|
+
end
|
153
|
+
|
154
|
+
# Inherently signed, there is no signed neg
|
155
|
+
it "signed_neg_no_overflow?" do
|
156
|
+
expect([a == 100, x == a.signed_neg_no_overflow?]).to have_solution(x => true)
|
157
|
+
expect([a == -100, x == a.signed_neg_no_overflow?]).to have_solution(x => true)
|
158
|
+
expect([a == 0, x == a.signed_neg_no_overflow?]).to have_solution(x => true)
|
159
|
+
expect([a == 127, x == a.signed_neg_no_overflow?]).to have_solution(x => true)
|
160
|
+
expect([a == -128, x == a.signed_neg_no_overflow?]).to have_solution(x => false)
|
161
|
+
end
|
162
|
+
|
163
|
+
# Unsigned div can't overflow, and signed div can only overflow for one value
|
164
|
+
it "signed_div_no_overflow?" do
|
165
|
+
expect([a == -128, b == -1, x == a.signed_div_no_overflow?(b)]).to have_solution(x => false)
|
166
|
+
expect([a == -128, b == -2, x == a.signed_div_no_overflow?(b)]).to have_solution(x => true)
|
167
|
+
expect([a == 127, b == 1, x == a.signed_div_no_overflow?(b)]).to have_solution(x => true)
|
168
|
+
end
|
169
|
+
|
170
|
+
## This API is broken, z3 returns unevaluated bvsmul_noovfl(10, 10) instead of actual answer
|
171
|
+
|
172
|
+
# it "signed_mul_no_overflow?" do
|
173
|
+
# expect([a == 10, b == 10, x == a.signed_mul_no_overflow?(b)]).to have_solution(x => true)
|
174
|
+
# expect([a == 20, b == 10, x == a.signed_mul_no_overflow?(b)]).to have_solution(x => false)
|
175
|
+
# expect([a == 20, b == 20, x == a.signed_mul_no_overflow?(b)]).to have_solution(x => false)
|
176
|
+
# expect([a == -10, b == -10, x == a.signed_mul_no_overflow?(b)]).to have_solution(x => true)
|
177
|
+
# end
|
178
|
+
#
|
179
|
+
# it "unsigned_mul_no_overflow?" do
|
180
|
+
# expect([a == 10, b == 10, x == a.unsigned_mul_no_overflow?(b)]).to have_solution(x => true)
|
181
|
+
# expect([a == 20, b == 10, x == a.unsigned_mul_no_overflow?(b)]).to have_solution(x => true)
|
182
|
+
# expect([a == 20, b == 20, x == a.unsigned_mul_no_overflow?(b)]).to have_solution(x => false)
|
183
|
+
# expect([a == -10, b == -10, x == a.unsigned_mul_no_overflow?(b)]).to have_solution(x => false)
|
184
|
+
# end
|
185
|
+
#
|
186
|
+
# # Inherently signed, unsigned can't underflow
|
187
|
+
# it "signed_mul_no_underflow?" do
|
188
|
+
# expect([a == -10, b == -10, x == a.signed_mul_no_underflow?(b)]).to have_solution(x => true)
|
189
|
+
# expect([a == -20, b == -20, x == a.signed_mul_no_underflow?(b)]).to have_solution(x => true)
|
190
|
+
# expect([a == -20, b == 20, x == a.signed_mul_no_underflow?(b)]).to have_solution(x => false)
|
191
|
+
# end
|
192
|
+
|
193
|
+
it "zero_ext / sign_ext" do
|
194
|
+
expect([a == 100, d == a.zero_ext(4)]).to have_solution(d => 100)
|
195
|
+
expect([a == -100, d == a.zero_ext(4)]).to have_solution(d => 2**8-100)
|
196
|
+
expect([a == 100, d == a.sign_ext(4)]).to have_solution(d => 100)
|
197
|
+
expect([a == -100, d == a.sign_ext(4)]).to have_solution(d => 2**12-100)
|
198
|
+
end
|
51
199
|
|
52
|
-
|
53
|
-
|
200
|
+
it "rotate_left / rotate_right" do
|
201
|
+
expect([a == 0b0101_0110, b == a.rotate_left(1)]).to have_solution(b => 0b101_0110_0)
|
202
|
+
expect([a == 0b0101_0110, b == a.rotate_left(4)]).to have_solution(b => 0b0110_0101)
|
203
|
+
expect([a == 0b0101_0110, b == a.rotate_right(1)]).to have_solution(b => 0b0_0101_011)
|
204
|
+
expect([a == 0b0101_0110, b == a.rotate_right(4)]).to have_solution(b => 0b0110_0101)
|
205
|
+
end
|
54
206
|
end
|
55
207
|
end
|
data/spec/bitvec_sort_spec.rb
CHANGED
@@ -1,34 +1,36 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module Z3
|
2
|
+
describe BitvecSort do
|
3
|
+
let(:bv3) { BitvecSort.new(3) }
|
4
|
+
let(:bv8) { BitvecSort.new(8) }
|
5
|
+
let(:bv32) { BitvecSort.new(32) }
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
it "can instantiate constants - 32 bit" do
|
8
|
+
expect(bv32.from_const(0).inspect).to eq("Bitvec(32)<0>")
|
9
|
+
expect(bv32.from_const(42).inspect).to eq("Bitvec(32)<42>")
|
10
|
+
expect(bv32.from_const(0x1234_5678_9abc).inspect).to eq("Bitvec(32)<1450744508>")
|
11
|
+
expect(bv32.from_const(-0x1234_5678_9abc).inspect).to eq("Bitvec(32)<2844222788>")
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
it "can instantiate constants - 8 bit" do
|
15
|
+
expect(bv8.from_const(0).inspect).to eq("Bitvec(8)<0>")
|
16
|
+
expect(bv8.from_const(42).inspect).to eq("Bitvec(8)<42>")
|
17
|
+
expect(bv8.from_const(0x1234_5678_9abc).inspect).to eq("Bitvec(8)<188>")
|
18
|
+
expect(bv8.from_const(-0x1234_5678_9abc).inspect).to eq("Bitvec(8)<68>")
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
it "can instantiate constants - 3 bit" do
|
22
|
+
expect(bv3.from_const(-1).inspect).to eq("Bitvec(3)<7>")
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
it "raisesbv32 exception when trying to convert constants of wrong type" do
|
26
|
+
expect{ bv32.from_const(true) }.to raise_error(Z3::Exception)
|
27
|
+
expect{ bv32.from_const(false) }.to raise_error(Z3::Exception)
|
28
|
+
expect{ bv32.from_const(0.0) }.to raise_error(Z3::Exception)
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
it "can instantiate variables" do
|
32
|
+
expect(Z3.Bitvec("a", 8).inspect).to eq("Bitvec(8)<a>")
|
33
|
+
expect(Z3.Bitvec("a", 32).inspect).to eq("Bitvec(32)<a>")
|
34
|
+
end
|
33
35
|
end
|
34
36
|
end
|
data/spec/bool_expr_spec.rb
CHANGED
@@ -1,65 +1,67 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module Z3
|
2
|
+
describe BoolExpr do
|
3
|
+
let(:a) { Z3.Bool("a") }
|
4
|
+
let(:b) { Z3.Bool("b") }
|
5
|
+
let(:c) { Z3.Bool("c") }
|
6
|
+
let(:x) { Z3.Int("x") }
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
it "&" do
|
9
|
+
expect([a == true, b == true, c == (a & b)]).to have_solution(c => true)
|
10
|
+
expect([a == true, b == false, c == (a & b)]).to have_solution(c => false)
|
11
|
+
expect([a == false, b == true, c == (a & b)]).to have_solution(c => false)
|
12
|
+
expect([a == false, b == false, c == (a & b)]).to have_solution(c => false)
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
it "|" do
|
16
|
+
expect([a == true, b == true, c == (a | b)]).to have_solution(c => true)
|
17
|
+
expect([a == true, b == false, c == (a | b)]).to have_solution(c => true)
|
18
|
+
expect([a == false, b == true, c == (a | b)]).to have_solution(c => true)
|
19
|
+
expect([a == false, b == false, c == (a | b)]).to have_solution(c => false)
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
it "^" do
|
23
|
+
expect([a == true, b == true, c == (a ^ b)]).to have_solution(c => false)
|
24
|
+
expect([a == true, b == false, c == (a ^ b)]).to have_solution(c => true)
|
25
|
+
expect([a == false, b == true, c == (a ^ b)]).to have_solution(c => true)
|
26
|
+
expect([a == false, b == false, c == (a ^ b)]).to have_solution(c => false)
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
it "!=" do
|
30
|
+
expect([a == true, b == true, c == (a != b)]).to have_solution(c => false)
|
31
|
+
expect([a == true, b == false, c == (a != b)]).to have_solution(c => true)
|
32
|
+
expect([a == false, b == true, c == (a != b)]).to have_solution(c => true)
|
33
|
+
expect([a == false, b == false, c == (a != b)]).to have_solution(c => false)
|
34
|
+
end
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
it "implies" do
|
37
|
+
expect([a == true, b == true, c == a.implies(b)]).to have_solution(c => true)
|
38
|
+
expect([a == true, b == false, c == a.implies(b)]).to have_solution(c => false)
|
39
|
+
expect([a == false, b == true, c == a.implies(b)]).to have_solution(c => true)
|
40
|
+
expect([a == false, b == false, c == a.implies(b)]).to have_solution(c => true)
|
41
|
+
end
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
it "iff" do
|
44
|
+
expect([a == true, b == true, c == a.iff(b)]).to have_solution(c => true)
|
45
|
+
expect([a == true, b == false, c == a.iff(b)]).to have_solution(c => false)
|
46
|
+
expect([a == false, b == true, c == a.iff(b)]).to have_solution(c => false)
|
47
|
+
expect([a == false, b == false, c == a.iff(b)]).to have_solution(c => true)
|
48
|
+
end
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
50
|
+
it "==" do
|
51
|
+
expect([a == true, b == true, c == (a == b)]).to have_solution(c => true)
|
52
|
+
expect([a == true, b == false, c == (a == b)]).to have_solution(c => false)
|
53
|
+
expect([a == false, b == true, c == (a == b)]).to have_solution(c => false)
|
54
|
+
expect([a == false, b == false, c == (a == b)]).to have_solution(c => true)
|
55
|
+
end
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
it "~" do
|
58
|
+
expect([a == true, b == ~a]).to have_solution(b => false)
|
59
|
+
expect([a == false, b == ~a]).to have_solution(b => true)
|
60
|
+
end
|
60
61
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
62
|
+
it "if then else" do
|
63
|
+
expect([a == true, x == a.ite(2, 3)]).to have_solution(x => 2)
|
64
|
+
expect([a == false, x == a.ite(2, 3)]).to have_solution(x => 3)
|
65
|
+
end
|
66
|
+
end
|
65
67
|
end
|
data/spec/bool_sort_spec.rb
CHANGED
@@ -1,20 +1,22 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module Z3
|
2
|
+
describe BoolSort do
|
3
|
+
it "can instantiate constants" do
|
4
|
+
expect(subject.from_const(true).inspect).to eq("Bool<true>")
|
5
|
+
expect(subject.from_const(false).inspect).to eq("Bool<false>")
|
6
|
+
end
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
it "raises exception when trying to convert constants of wrong type" do
|
9
|
+
expect{ subject.from_const(0) }.to raise_error(Z3::Exception)
|
10
|
+
expect{ subject.from_const(0.0) }.to raise_error(Z3::Exception)
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
it "interface constructors" do
|
14
|
+
expect(Z3.True.inspect).to eq("Bool<true>")
|
15
|
+
expect(Z3.False.inspect).to eq("Bool<false>")
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
18
|
+
it "can instantiate variables" do
|
19
|
+
expect(Z3.Bool("a").inspect).to eq("Bool<a>")
|
20
|
+
end
|
19
21
|
end
|
20
22
|
end
|