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/spec/expr_spec.rb
CHANGED
@@ -1,175 +1,179 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
expect(a.to_s).to eq("a")
|
17
|
-
end
|
18
|
-
|
19
|
-
it "#inspect" do
|
20
|
-
expect(a.inspect).to eq("Int<a>")
|
21
|
-
expect((e+f).inspect).to eq("Real<(+ e f)>")
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "#~" do
|
25
|
-
it "allows negating boolean variables" do
|
26
|
-
expect((~c).to_s).to eq("(not c)")
|
1
|
+
# TODO: This spec doesn't reflect current functionality all that well
|
2
|
+
|
3
|
+
module Z3
|
4
|
+
describe Expr do
|
5
|
+
let(:a) { Z3.Int("a") }
|
6
|
+
let(:b) { Z3.Int("b") }
|
7
|
+
let(:c) { Z3.Bool("c") }
|
8
|
+
let(:d) { Z3.Bool("d") }
|
9
|
+
let(:e) { Z3.Real("e") }
|
10
|
+
let(:f) { Z3.Real("f") }
|
11
|
+
|
12
|
+
it "#sort returns Sort object" do
|
13
|
+
expect(a.sort).to eq(IntSort.new)
|
14
|
+
expect(c.sort).to eq(BoolSort.new)
|
15
|
+
expect(e.sort).to eq(RealSort.new)
|
27
16
|
end
|
28
17
|
|
29
|
-
it "
|
30
|
-
expect
|
31
|
-
expect{~e}.to raise_error(NoMethodError)
|
18
|
+
it "#to_s" do
|
19
|
+
expect(a.sexpr).to eq("a")
|
32
20
|
end
|
33
|
-
end
|
34
21
|
|
35
|
-
|
36
|
-
|
37
|
-
expect((
|
22
|
+
it "#inspect" do
|
23
|
+
expect(a.inspect).to eq("Int<a>")
|
24
|
+
expect((e+f).inspect).to eq("Real<e + f>")
|
38
25
|
end
|
39
26
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
expect{e&c}.to raise_error(NoMethodError)
|
45
|
-
expect{c&a}.to raise_error(ArgumentError)
|
46
|
-
expect{c&e}.to raise_error(ArgumentError)
|
47
|
-
end
|
48
|
-
end
|
27
|
+
describe "#~" do
|
28
|
+
it "allows negating boolean variables" do
|
29
|
+
expect((~c).sexpr).to eq("(not c)")
|
30
|
+
end
|
49
31
|
|
50
|
-
|
51
|
-
|
52
|
-
|
32
|
+
it "raises exception if type cast is not possible" do
|
33
|
+
expect{~a}.to raise_error(NoMethodError)
|
34
|
+
expect{~e}.to raise_error(NoMethodError)
|
35
|
+
end
|
53
36
|
end
|
54
37
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
expect{e|c}.to raise_error(NoMethodError)
|
60
|
-
expect{c|a}.to raise_error(ArgumentError)
|
61
|
-
expect{c|e}.to raise_error(ArgumentError)
|
62
|
-
end
|
63
|
-
end
|
38
|
+
describe "#&" do
|
39
|
+
it "allows and of boolean variables" do
|
40
|
+
expect((c & d).sexpr).to eq("(and c d)")
|
41
|
+
end
|
64
42
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
expect
|
69
|
-
expect
|
43
|
+
it "raises exception if type cast is not possible" do
|
44
|
+
expect{a&b}.to raise_error(NoMethodError)
|
45
|
+
expect{e&f}.to raise_error(NoMethodError)
|
46
|
+
expect{a&c}.to raise_error(NoMethodError)
|
47
|
+
expect{e&c}.to raise_error(NoMethodError)
|
48
|
+
expect{c&a}.to raise_error(ArgumentError)
|
49
|
+
expect{c&e}.to raise_error(ArgumentError)
|
70
50
|
end
|
51
|
+
end
|
71
52
|
|
72
|
-
|
73
|
-
|
74
|
-
expect((
|
75
|
-
expect((a.send op, 42).to_s).to eq "(#{op} a 42)"
|
76
|
-
expect((42.send op, a).to_s).to eq "(#{op} 42 a)"
|
77
|
-
expect((a.send op, 42.5).to_s).to eq "(#{op} (to_real a) (/ 85.0 2.0))"
|
78
|
-
expect((42.5.send op, a).to_s).to eq "(#{op} (/ 85.0 2.0) (to_real a))"
|
79
|
-
expect((e.send op, 42).to_s).to eq "(#{op} e 42.0)"
|
80
|
-
expect((42.send op, e).to_s).to eq "(#{op} 42.0 e)"
|
81
|
-
expect((e.send op, 42.5).to_s).to eq "(#{op} e (/ 85.0 2.0))"
|
82
|
-
expect((42.5.send op, e).to_s).to eq "(#{op} (/ 85.0 2.0) e)"
|
53
|
+
describe "#|" do
|
54
|
+
it "allows or of boolean variables" do
|
55
|
+
expect((c | d).sexpr).to eq("(or c d)")
|
83
56
|
end
|
84
57
|
|
85
58
|
it "raises exception if type cast is not possible" do
|
86
|
-
|
87
|
-
expect{
|
88
|
-
expect{
|
89
|
-
expect{
|
90
|
-
expect{a
|
91
|
-
expect{e
|
92
|
-
expect{e.send op, false}.to raise_error(ArgumentError)
|
93
|
-
|
94
|
-
# Bool doesn't have #>= #+ etc.
|
95
|
-
expect{c.send op, a}.to raise_error(NoMethodError)
|
96
|
-
expect{c.send op, d}.to raise_error(NoMethodError)
|
97
|
-
expect{c.send op, e}.to raise_error(NoMethodError)
|
98
|
-
expect{c.send op, true}.to raise_error(NoMethodError)
|
99
|
-
expect{c.send op, false}.to raise_error(NoMethodError)
|
59
|
+
expect{a|b}.to raise_error(NoMethodError)
|
60
|
+
expect{e|f}.to raise_error(NoMethodError)
|
61
|
+
expect{a|c}.to raise_error(NoMethodError)
|
62
|
+
expect{e|c}.to raise_error(NoMethodError)
|
63
|
+
expect{c|a}.to raise_error(ArgumentError)
|
64
|
+
expect{c|e}.to raise_error(ArgumentError)
|
100
65
|
end
|
101
66
|
end
|
102
|
-
end
|
103
67
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
68
|
+
%W[+ - * <= < >= >].each do |op|
|
69
|
+
describe "#{op} arithmetic operator" do
|
70
|
+
it "allows + of int or real variables" do
|
71
|
+
expect((a.send op, b).sexpr).to eq "(#{op} a b)"
|
72
|
+
expect((e.send op, f).sexpr).to eq "(#{op} e f)"
|
73
|
+
end
|
74
|
+
|
75
|
+
it "casts to correct type if possible" do
|
76
|
+
expect((a.send op, e).sexpr).to eq "(#{op} (to_real a) e)"
|
77
|
+
expect((e.send op, a).sexpr).to eq "(#{op} e (to_real a))"
|
78
|
+
expect((a.send op, 42).sexpr).to eq "(#{op} a 42)"
|
79
|
+
expect((42.send op, a).sexpr).to eq "(#{op} 42 a)"
|
80
|
+
expect((a.send op, 42.5).sexpr).to eq "(#{op} (to_real a) (/ 85.0 2.0))"
|
81
|
+
expect((42.5.send op, a).sexpr).to eq "(#{op} (/ 85.0 2.0) (to_real a))"
|
82
|
+
expect((e.send op, 42).sexpr).to eq "(#{op} e 42.0)"
|
83
|
+
expect((42.send op, e).sexpr).to eq "(#{op} 42.0 e)"
|
84
|
+
expect((e.send op, 42.5).sexpr).to eq "(#{op} e (/ 85.0 2.0))"
|
85
|
+
expect((42.5.send op, e).sexpr).to eq "(#{op} (/ 85.0 2.0) e)"
|
86
|
+
end
|
87
|
+
|
88
|
+
it "raises exception if type cast is not possible" do
|
89
|
+
# Int/Real has #>= #+ etc. but they don't like these arguments
|
90
|
+
expect{a.send op, c}.to raise_error(ArgumentError)
|
91
|
+
expect{e.send op, c}.to raise_error(ArgumentError)
|
92
|
+
expect{a.send op, true}.to raise_error(ArgumentError)
|
93
|
+
expect{a.send op, false}.to raise_error(ArgumentError)
|
94
|
+
expect{e.send op, true}.to raise_error(ArgumentError)
|
95
|
+
expect{e.send op, false}.to raise_error(ArgumentError)
|
96
|
+
|
97
|
+
# Bool doesn't have #>= #+ etc.
|
98
|
+
expect{c.send op, a}.to raise_error(NoMethodError)
|
99
|
+
expect{c.send op, d}.to raise_error(NoMethodError)
|
100
|
+
expect{c.send op, e}.to raise_error(NoMethodError)
|
101
|
+
expect{c.send op, true}.to raise_error(NoMethodError)
|
102
|
+
expect{c.send op, false}.to raise_error(NoMethodError)
|
103
|
+
end
|
104
|
+
end
|
109
105
|
end
|
110
106
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
expect((c == false).to_s).to eq "(= c false)"
|
118
|
-
expect((a == 42.5).to_s).to eq "(= (to_real a) (/ 85.0 2.0))"
|
119
|
-
expect((42.5 == a).to_s).to eq "(= (to_real a) (/ 85.0 2.0))"
|
120
|
-
expect((e == 42.5).to_s).to eq "(= e (/ 85.0 2.0))"
|
121
|
-
expect((42.5 == e).to_s).to eq "(= e (/ 85.0 2.0))"
|
122
|
-
# expect((true == c).to_s).to eq "(= true c)"
|
123
|
-
# expect((false == c).to_s).to eq "(= false c)"
|
124
|
-
end
|
107
|
+
describe "#==" do
|
108
|
+
it "allows == of variables of same sort" do
|
109
|
+
expect((a == b).sexpr).to eq "(= a b)"
|
110
|
+
expect((c == d).sexpr).to eq "(= c d)"
|
111
|
+
expect((e == f).sexpr).to eq "(= e f)"
|
112
|
+
end
|
125
113
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
114
|
+
it "casts to correct type if possible" do
|
115
|
+
expect((a == 42).sexpr).to eq "(= a 42)"
|
116
|
+
expect((42 == a).sexpr).to eq "(= a 42)"
|
117
|
+
expect((a == e).sexpr).to eq "(= (to_real a) e)"
|
118
|
+
expect((e == a).sexpr).to eq "(= e (to_real a))"
|
119
|
+
expect((c == true).sexpr).to eq "(= c true)"
|
120
|
+
expect((c == false).sexpr).to eq "(= c false)"
|
121
|
+
expect((a == 42.5).sexpr).to eq "(= (to_real a) (/ 85.0 2.0))"
|
122
|
+
expect((42.5 == a).sexpr).to eq "(= (to_real a) (/ 85.0 2.0))"
|
123
|
+
expect((e == 42.5).sexpr).to eq "(= e (/ 85.0 2.0))"
|
124
|
+
expect((42.5 == e).sexpr).to eq "(= e (/ 85.0 2.0))"
|
125
|
+
# expect((true == c).sexpr).to eq "(= true c)"
|
126
|
+
# expect((false == c).sexpr).to eq "(= false c)"
|
127
|
+
end
|
139
128
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
129
|
+
it "raises exception if type cast is not possible" do
|
130
|
+
expect{a == c}.to raise_error(ArgumentError)
|
131
|
+
expect{e == c}.to raise_error(ArgumentError)
|
132
|
+
expect{a == true}.to raise_error(ArgumentError)
|
133
|
+
expect{e == true}.to raise_error(ArgumentError)
|
134
|
+
# expect{true == a}.to raise_error(ArgumentError)
|
135
|
+
# expect{true == e}.to raise_error(ArgumentError)
|
136
|
+
expect{c == 42}.to raise_error(ArgumentError)
|
137
|
+
expect{c == 42.5}.to raise_error(ArgumentError)
|
138
|
+
expect{42 == c}.to raise_error(ArgumentError)
|
139
|
+
expect{42.5 == c}.to raise_error(ArgumentError)
|
140
|
+
end
|
145
141
|
end
|
146
142
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
143
|
+
describe "#!=" do
|
144
|
+
it "allows != of variables of same sort" do
|
145
|
+
expect((a != b).sexpr).to eq "(distinct a b)"
|
146
|
+
expect((c != d).sexpr).to eq "(distinct c d)"
|
147
|
+
expect((e != f).sexpr).to eq "(distinct e f)"
|
148
|
+
end
|
149
|
+
|
150
|
+
it "casts to correct type if possible" do
|
151
|
+
expect((a != 42).sexpr).to eq "(distinct a 42)"
|
152
|
+
# expect((42 != a).sexpr).to eq "(distinct a 42)"
|
153
|
+
expect((a != e).sexpr).to eq "(distinct (to_real a) e)"
|
154
|
+
expect((e != a).sexpr).to eq "(distinct e (to_real a))"
|
155
|
+
expect((c != true).sexpr).to eq "(distinct c true)"
|
156
|
+
expect((c != false).sexpr).to eq "(distinct c false)"
|
157
|
+
expect((a != 42.5).sexpr).to eq "(distinct (to_real a) (/ 85.0 2.0))"
|
158
|
+
# expect((42.5 != a).sexpr).to eq "(distinct (to_real a) (/ 85.0 2.0))"
|
159
|
+
expect((e != 42.5).sexpr).to eq "(distinct e (/ 85.0 2.0))"
|
160
|
+
# expect((42.5 != e).sexpr).to eq "(distinct e (/ 85.0 2.0))"
|
161
|
+
# expect((true != c).sexpr).to eq "(distinct true c)"
|
162
|
+
# expect((false != c).sexpr).to eq "(distinct false c)"
|
163
|
+
end
|
161
164
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
165
|
+
it "raises exception if type cast is not possible" do
|
166
|
+
expect{a != c}.to raise_error(ArgumentError)
|
167
|
+
expect{e != c}.to raise_error(ArgumentError)
|
168
|
+
expect{a != true}.to raise_error(ArgumentError)
|
169
|
+
expect{e != true}.to raise_error(ArgumentError)
|
170
|
+
# expect{true != a}.to raise_error(ArgumentError)
|
171
|
+
# expect{true != e}.to raise_error(ArgumentError)
|
172
|
+
expect{c != 42}.to raise_error(ArgumentError)
|
173
|
+
expect{c != 42.5}.to raise_error(ArgumentError)
|
174
|
+
# expect{42 != c}.to raise_error(ArgumentError)
|
175
|
+
# expect{42.5 != c}.to raise_error(ArgumentError)
|
176
|
+
end
|
173
177
|
end
|
174
178
|
end
|
175
179
|
end
|
@@ -0,0 +1,167 @@
|
|
1
|
+
module Z3
|
2
|
+
describe FloatExpr do
|
3
|
+
let(:mode) { RoundingModeSort.new }
|
4
|
+
let(:float_double) { FloatSort.new(:double) }
|
5
|
+
let(:a) { float_double.var("a") }
|
6
|
+
let(:b) { float_double.var("b") }
|
7
|
+
let(:c) { float_double.var("c") }
|
8
|
+
let(:m) { mode.var("m") }
|
9
|
+
let(:x) { BoolSort.new.var("x") }
|
10
|
+
|
11
|
+
let(:positive_zero) { float_double.positive_zero }
|
12
|
+
let(:negative_zero) { float_double.negative_zero }
|
13
|
+
let(:positive_infinity) { float_double.positive_infinity }
|
14
|
+
let(:negative_infinity) { float_double.negative_infinity }
|
15
|
+
let(:nan) { float_double.nan }
|
16
|
+
|
17
|
+
it "+" do
|
18
|
+
expect([a == 2.0, b == 4.0, c == a.add(b,m)]).to have_solution(
|
19
|
+
c => float_double.from_const(6.0),
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "*" do
|
24
|
+
expect([a == -2.0, b == 0.5, c == a.mul(b,m)]).to have_solution(
|
25
|
+
c => float_double.from_const(-1.0),
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "-" do
|
30
|
+
expect([a == 2.0, b == 0.5, c == a.sub(b,m)]).to have_solution(
|
31
|
+
c => float_double.from_const(1.5),
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "/" do
|
36
|
+
expect([a == 12.0, b == 3.0, c == a.div(b,m)]).to have_solution(
|
37
|
+
c => float_double.from_const(4.0),
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "%" do
|
42
|
+
expect([a == 13.5, b == 3.0, c == a.rem(b)]).to have_solution(
|
43
|
+
c => float_double.from_const(1.5),
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "abs" do
|
48
|
+
expect([a == 7.5, c == a.abs]).to have_solution(
|
49
|
+
c => float_double.from_const(7.5),
|
50
|
+
)
|
51
|
+
expect([a == -7.5, c == a.abs]).to have_solution(
|
52
|
+
c => float_double.from_const(7.5),
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "neg" do
|
57
|
+
expect([a == 7.5, c == -a]).to have_solution(
|
58
|
+
c => float_double.from_const(7.5),
|
59
|
+
)
|
60
|
+
expect([a == -7.5, c == -a]).to have_solution(
|
61
|
+
c => float_double.from_const(7.5),
|
62
|
+
)
|
63
|
+
end
|
64
|
+
|
65
|
+
# Broken in z3
|
66
|
+
# it "max" do
|
67
|
+
# expect([a == 2.0, b == 3.0, c == a.max(b)]).to have_solution(
|
68
|
+
# c => float_double.from_const(3.0),
|
69
|
+
# )
|
70
|
+
# end
|
71
|
+
|
72
|
+
it "min" do
|
73
|
+
expect([a == 2.0, b == 3.0, c == a.min(b)]).to have_solution(
|
74
|
+
c => float_double.from_const(2.0),
|
75
|
+
)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "comparisons" do
|
79
|
+
expect([a == 3.0, b == 3.0, x == (a >= b)]).to have_solution(x => true)
|
80
|
+
expect([a == 3.0, b == 3.0, x == (a > b)]).to have_solution(x => false)
|
81
|
+
expect([a == 3.0, b == 3.0, x == (a <= b)]).to have_solution(x => true)
|
82
|
+
expect([a == 3.0, b == 3.0, x == (a < b)]).to have_solution(x => false)
|
83
|
+
expect([a == 3.0, b == 3.0, x == (a == b)]).to have_solution(x => true)
|
84
|
+
expect([a == 3.0, b == 3.0, x == (a != b)]).to have_solution(x => false)
|
85
|
+
|
86
|
+
expect([a == 3.0, b == 2.0, x == (a >= b)]).to have_solution(x => true)
|
87
|
+
expect([a == 3.0, b == 2.0, x == (a > b)]).to have_solution(x => true)
|
88
|
+
expect([a == 3.0, b == 2.0, x == (a <= b)]).to have_solution(x => false)
|
89
|
+
expect([a == 3.0, b == 2.0, x == (a < b)]).to have_solution(x => false)
|
90
|
+
expect([a == 3.0, b == 2.0, x == (a == b)]).to have_solution(x => false)
|
91
|
+
expect([a == 3.0, b == 2.0, x == (a != b)]).to have_solution(x => true)
|
92
|
+
end
|
93
|
+
|
94
|
+
# This isn't the most amazing format ever, probably reevaluate it completely at some point
|
95
|
+
it "to_s" do
|
96
|
+
expect(float_double.from_const(1.0).to_s).to eq("1B+0")
|
97
|
+
expect(float_double.from_const(2.0).to_s).to eq("1B+1")
|
98
|
+
expect(float_double.from_const(0.5).to_s).to eq("1B-1")
|
99
|
+
expect(positive_zero.to_s).to eq("+zero")
|
100
|
+
expect(negative_zero.to_s).to eq("-zero")
|
101
|
+
expect(positive_infinity.to_s).to eq("+oo")
|
102
|
+
expect(negative_infinity.to_s).to eq("-oo")
|
103
|
+
expect(nan.to_s).to eq("NaN")
|
104
|
+
expect(float_double.from_const(1234 * 0.5**1040).to_s).to eq("1.205078125B-1030")
|
105
|
+
end
|
106
|
+
|
107
|
+
it "zero?" do
|
108
|
+
expect([x == positive_zero.zero?]).to have_solution(x => true)
|
109
|
+
expect([x == negative_zero.zero?]).to have_solution(x => true)
|
110
|
+
expect([x == positive_infinity.zero?]).to have_solution(x => false)
|
111
|
+
expect([x == negative_infinity.zero?]).to have_solution(x => false)
|
112
|
+
expect([x == float_double.from_const(1.5).zero?]).to have_solution(x => false)
|
113
|
+
expect([x == nan.zero?]).to have_solution(x => false)
|
114
|
+
end
|
115
|
+
|
116
|
+
it "infinite?" do
|
117
|
+
expect([x == positive_zero.infinite?]).to have_solution(x => false)
|
118
|
+
expect([x == positive_infinity.infinite?]).to have_solution(x => true)
|
119
|
+
expect([x == negative_infinity.infinite?]).to have_solution(x => true)
|
120
|
+
expect([x == float_double.from_const(1.5).infinite?]).to have_solution(x => false)
|
121
|
+
expect([x == nan.infinite?]).to have_solution(x => false)
|
122
|
+
end
|
123
|
+
|
124
|
+
it "nan?" do
|
125
|
+
expect([x == positive_zero.nan?]).to have_solution(x => false)
|
126
|
+
expect([x == positive_infinity.nan?]).to have_solution(x => false)
|
127
|
+
expect([x == float_double.from_const(1.5).nan?]).to have_solution(x => false)
|
128
|
+
expect([x == nan.nan?]).to have_solution(x => true)
|
129
|
+
end
|
130
|
+
|
131
|
+
it "normal?" do
|
132
|
+
expect([x == positive_zero.normal?]).to have_solution(x => false)
|
133
|
+
expect([x == positive_infinity.normal?]).to have_solution(x => false)
|
134
|
+
expect([x == nan.normal?]).to have_solution(x => false)
|
135
|
+
expect([x == float_double.from_const(1.5).normal?]).to have_solution(x => true)
|
136
|
+
expect([x == float_double.from_const(1234 * 0.5**1040).normal?]).to have_solution(x => false)
|
137
|
+
end
|
138
|
+
|
139
|
+
it "subnormal?" do
|
140
|
+
expect([x == positive_zero.subnormal?]).to have_solution(x => false)
|
141
|
+
expect([x == positive_infinity.subnormal?]).to have_solution(x => false)
|
142
|
+
expect([x == nan.subnormal?]).to have_solution(x => false)
|
143
|
+
expect([x == float_double.from_const(1.5).subnormal?]).to have_solution(x => false)
|
144
|
+
expect([x == float_double.from_const(1234 * 0.5**1040).subnormal?]).to have_solution(x => true)
|
145
|
+
end
|
146
|
+
|
147
|
+
it "positive?" do
|
148
|
+
expect([x == positive_zero.positive?]).to have_solution(x => true)
|
149
|
+
expect([x == negative_zero.positive?]).to have_solution(x => false)
|
150
|
+
expect([x == positive_infinity.positive?]).to have_solution(x => true)
|
151
|
+
expect([x == negative_infinity.positive?]).to have_solution(x => false)
|
152
|
+
expect([x == float_double.from_const(1.5).positive?]).to have_solution(x => true)
|
153
|
+
expect([x == float_double.from_const(-1.5).positive?]).to have_solution(x => false)
|
154
|
+
expect([x == nan.positive?]).to have_solution(x => false)
|
155
|
+
end
|
156
|
+
|
157
|
+
it "negative?" do
|
158
|
+
expect([x == positive_zero.negative?]).to have_solution(x => false)
|
159
|
+
expect([x == negative_zero.negative?]).to have_solution(x => true)
|
160
|
+
expect([x == positive_infinity.negative?]).to have_solution(x => false)
|
161
|
+
expect([x == negative_infinity.negative?]).to have_solution(x => true)
|
162
|
+
expect([x == float_double.from_const(1.5).negative?]).to have_solution(x => false)
|
163
|
+
expect([x == float_double.from_const(-1.5).negative?]).to have_solution(x => true)
|
164
|
+
expect([x == nan.negative?]).to have_solution(x => false)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Z3
|
2
|
+
describe FloatSort do
|
3
|
+
let(:float_16) { FloatSort.new(16) }
|
4
|
+
let(:float_32) { FloatSort.new(32) }
|
5
|
+
let(:float_64) { FloatSort.new(64) }
|
6
|
+
let(:float_128) { FloatSort.new(128) }
|
7
|
+
let(:float_half) { FloatSort.new(:half) }
|
8
|
+
let(:float_single) { FloatSort.new(:single) }
|
9
|
+
let(:float_double) { FloatSort.new(:double) }
|
10
|
+
let(:float_quadruple) { FloatSort.new(:quadruple) }
|
11
|
+
let(:float_5_11) { FloatSort.new(5, 11) }
|
12
|
+
let(:float_8_24) { FloatSort.new(8, 24) }
|
13
|
+
let(:float_11_53) { FloatSort.new(11, 53) }
|
14
|
+
let(:float_15_113) { FloatSort.new(15, 113) }
|
15
|
+
|
16
|
+
it "to_s" do
|
17
|
+
expect(float_5_11.to_s).to eq("Float(5, 11)")
|
18
|
+
expect(float_15_113.to_s).to eq("Float(15, 113)")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "inspect" do
|
22
|
+
expect(float_5_11.inspect).to eq("FloatSort(5, 11)")
|
23
|
+
expect(float_15_113.inspect).to eq("FloatSort(15, 113)")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "sbits" do
|
27
|
+
expect(float_8_24.sbits).to eq(24)
|
28
|
+
expect(float_11_53.sbits).to eq(53)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "ebits" do
|
32
|
+
expect(float_8_24.ebits).to eq(8)
|
33
|
+
expect(float_11_53.ebits).to eq(11)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "shortcut syntax" do
|
37
|
+
expect([float_16, float_32, float_64, float_128]).to be_all_different
|
38
|
+
expect([float_16, float_half, float_5_11]).to be_all_same
|
39
|
+
expect([float_32, float_single, float_8_24]).to be_all_same
|
40
|
+
expect([float_64, float_double, float_11_53]).to be_all_same
|
41
|
+
expect([float_128, float_quadruple, float_15_113]).to be_all_same
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/spec/goal_spec.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Z3
|
2
|
+
describe Goal do
|
3
|
+
it "basic functionality" do
|
4
|
+
g = Goal.new
|
5
|
+
g.assert Z3.Int("x") == 3
|
6
|
+
expect(g.num_exprs).to eq(3)
|
7
|
+
expect(g.size).to eq(1)
|
8
|
+
expect(g.depth).to eq(0)
|
9
|
+
expect(g.precision).to eq(0)
|
10
|
+
expect(g.to_s).to eq("(goal\n (= x 3))")
|
11
|
+
expect(g.decided_sat?).to eq(false)
|
12
|
+
expect(g.decided_unsat?).to eq(false)
|
13
|
+
expect(g.inconsistent?).to eq(false)
|
14
|
+
expect(g.formula(0).to_s).to eq("x = 3")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|