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/int_expr_spec.rb
CHANGED
@@ -1,78 +1,91 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module Z3
|
2
|
+
describe IntExpr do
|
3
|
+
let(:a) { Z3.Int("a") }
|
4
|
+
let(:b) { Z3.Int("b") }
|
5
|
+
let(:c) { Z3.Int("c") }
|
6
|
+
let(:x) { Z3.Bool("x") }
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
it "+" do
|
9
|
+
expect([a == 2, b == 4, c == a + b]).to have_solution(c => 6)
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
it "-" do
|
13
|
+
expect([a == 2, b == 4, c == a - b]).to have_solution(c => -2)
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
it "*" do
|
17
|
+
expect([a == 2, b == 4, c == a * b]).to have_solution(c => 8)
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
it "/" do
|
21
|
+
expect([a == 10, b == 3, c == a / b]).to have_solution(c => 3)
|
22
|
+
expect([a == -10, b == 3, c == a / b]).to have_solution(c => -4)
|
23
|
+
expect([a == 10, b == -3, c == a / b]).to have_solution(c => -3)
|
24
|
+
expect([a == -10, b == -3, c == a / b]).to have_solution(c => 4)
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
# Can't say these make much sense, but let's document what Z3 actually does
|
28
|
+
it "rem" do
|
29
|
+
expect([a == 10, b == 3, c == a.rem(b)]).to have_solution(c => 10 - 3 * 3)
|
30
|
+
expect([a == -10, b == 3, c == a.rem(b)]).to have_solution(c =>-10 - 3 * -4)
|
31
|
+
expect([a == 10, b == -3, c == a.rem(b)]).to have_solution(c =>-( 10 - -3 * -3))
|
32
|
+
expect([a == -10, b == -3, c == a.rem(b)]).to have_solution(c =>-(-10 - -3 * 4))
|
33
|
+
end
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
it "mod" do
|
36
|
+
expect([a == 10, b == 3, c == a.mod(b)]).to have_solution(c => 1)
|
37
|
+
expect([a == 10, b == -3, c == a.mod(b)]).to have_solution(c => 1)
|
38
|
+
expect([a == -10, b == 3, c == a.mod(b)]).to have_solution(c => 2)
|
39
|
+
expect([a == -10, b == -3, c == a.mod(b)]).to have_solution(c => 2)
|
40
|
+
end
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
it "==" do
|
43
|
+
expect([a == 2, b == 2, x == (a == b)]).to have_solution(x => true)
|
44
|
+
expect([a == 2, b == 3, x == (a == b)]).to have_solution(x => false)
|
45
|
+
end
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
it "!=" do
|
48
|
+
expect([a == 2, b == 2, x == (a != b)]).to have_solution(x => false)
|
49
|
+
expect([a == 2, b == 3, x == (a != b)]).to have_solution(x => true)
|
50
|
+
end
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
it ">" do
|
53
|
+
expect([a == 3, b == 2, x == (a > b)]).to have_solution(x => true)
|
54
|
+
expect([a == 2, b == 2, x == (a > b)]).to have_solution(x => false)
|
55
|
+
expect([a == 1, b == 2, x == (a > b)]).to have_solution(x => false)
|
56
|
+
end
|
56
57
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
58
|
+
it ">=" do
|
59
|
+
expect([a == 3, b == 2, x == (a >= b)]).to have_solution(x => true)
|
60
|
+
expect([a == 2, b == 2, x == (a >= b)]).to have_solution(x => true)
|
61
|
+
expect([a == 1, b == 2, x == (a >= b)]).to have_solution(x => false)
|
62
|
+
end
|
62
63
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
64
|
+
it "<" do
|
65
|
+
expect([a == 3, b == 2, x == (a < b)]).to have_solution(x => false)
|
66
|
+
expect([a == 2, b == 2, x == (a < b)]).to have_solution(x => false)
|
67
|
+
expect([a == 1, b == 2, x == (a < b)]).to have_solution(x => true)
|
68
|
+
end
|
68
69
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
70
|
+
it "<=" do
|
71
|
+
expect([a == 3, b == 2, x == (a <= b)]).to have_solution(x => false)
|
72
|
+
expect([a == 2, b == 2, x == (a <= b)]).to have_solution(x => true)
|
73
|
+
expect([a == 1, b == 2, x == (a <= b)]).to have_solution(x => true)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "**" do
|
77
|
+
expect([a == 3, b == 4, c == (a ** b)]).to have_solution(c => 81)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "unary -" do
|
81
|
+
expect([a == 3, b == -a]).to have_solution(b => -3)
|
82
|
+
end
|
74
83
|
|
75
|
-
|
76
|
-
|
84
|
+
it "simplify" do
|
85
|
+
a = Z3.Const(5)
|
86
|
+
b = Z3.Const(3)
|
87
|
+
expect((a+b).inspect).to eq("Int<5 + 3>")
|
88
|
+
expect((a+b).simplify.inspect).to eq("Int<8>")
|
89
|
+
end
|
77
90
|
end
|
78
91
|
end
|
data/spec/int_sort_spec.rb
CHANGED
@@ -1,18 +1,20 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
module Z3
|
2
|
+
describe IntSort do
|
3
|
+
it "can instantiate constants" do
|
4
|
+
expect(subject.from_const(0).inspect).to eq("Int<0>")
|
5
|
+
expect(subject.from_const(42).inspect).to eq("Int<42>")
|
6
|
+
expect(subject.from_const(1_000_000_000_000).inspect).to eq("Int<1000000000000>")
|
7
|
+
expect(subject.from_const(-1_000_000_000_000).inspect).to eq("Int<-1000000000000>")
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
it "raises exception when trying to convert constants of wrong type" do
|
11
|
+
expect{ subject.from_const(true) }.to raise_error(Z3::Exception)
|
12
|
+
expect{ subject.from_const(false) }.to raise_error(Z3::Exception)
|
13
|
+
expect{ subject.from_const(0.0) }.to raise_error(Z3::Exception)
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
it "can instantiate variables" do
|
17
|
+
expect(Z3.Int("a").inspect).to eq("Int<a>")
|
18
|
+
end
|
17
19
|
end
|
18
20
|
end
|
@@ -4,14 +4,14 @@ describe "Algebra Problems" do
|
|
4
4
|
Solution to problem 01:
|
5
5
|
Solution to problem 03:
|
6
6
|
* x = -22
|
7
|
-
*
|
8
|
-
*
|
7
|
+
* |-6| = 6
|
8
|
+
* |x-2| = 24
|
9
9
|
Solution to problem 04:
|
10
10
|
* ax = -4
|
11
11
|
* ay = -5
|
12
12
|
* bx = -1
|
13
13
|
* by = -1
|
14
|
-
*
|
14
|
+
* |a-b| = 5
|
15
15
|
Solution to problem 05:
|
16
16
|
* x = 9/2
|
17
17
|
* y = 0
|
@@ -23,7 +23,7 @@ Solution to problem 06:
|
|
23
23
|
* y2 = 13
|
24
24
|
Solution to problem 10:
|
25
25
|
* x = 1
|
26
|
-
*
|
26
|
+
* |-2x + 2| = 0
|
27
27
|
EOF
|
28
28
|
end
|
29
29
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
describe "Circuit Problems" do
|
2
|
+
it do
|
3
|
+
expect("circuit_problems").to have_output <<EOF
|
4
|
+
Problem 1
|
5
|
+
* I V = -5/4
|
6
|
+
|
7
|
+
Problem 2
|
8
|
+
* I V = -10
|
9
|
+
|
10
|
+
Problem 3
|
11
|
+
* I L = -1
|
12
|
+
* I V = -1
|
13
|
+
* I L = -1/2
|
14
|
+
* I V = -1/2
|
15
|
+
* I L = 0
|
16
|
+
* I V = 0
|
17
|
+
* I L = -1/2
|
18
|
+
* I V = 1/2
|
19
|
+
* I L = -1
|
20
|
+
* I V = 1
|
21
|
+
EOF
|
22
|
+
end
|
23
|
+
end
|
@@ -2,15 +2,15 @@ describe "Geometry Problem" do
|
|
2
2
|
it do
|
3
3
|
expect("geometry_problem").to have_output <<EOF
|
4
4
|
* a.x = 0
|
5
|
-
* a.y =
|
5
|
+
* a.y = -17.3205080756?
|
6
6
|
* b.x = 0
|
7
7
|
* b.y = 0
|
8
8
|
* c.x = 10
|
9
9
|
* c.y = 0
|
10
10
|
* d.x = 10
|
11
|
-
* d.y =
|
12
|
-
*
|
13
|
-
*
|
11
|
+
* d.y = -17.3205080756?
|
12
|
+
* |a-c| = -20
|
13
|
+
* |b-d| = 20
|
14
14
|
EOF
|
15
15
|
end
|
16
16
|
end
|
@@ -23,7 +23,7 @@ Solution to problem 04:
|
|
23
23
|
Solution to problem 05:
|
24
24
|
* a = 167/100
|
25
25
|
* d = 7/5
|
26
|
-
* t =
|
26
|
+
* t = 1.2948539325?
|
27
27
|
Solution to problem 06:
|
28
28
|
* a = 14800/61
|
29
29
|
* d = 20313/50
|
@@ -46,8 +46,8 @@ Solution to problem 09:
|
|
46
46
|
Solution to problem 10:
|
47
47
|
* a = -981/100
|
48
48
|
* d = 131/50
|
49
|
-
* t =
|
50
|
-
* v =
|
49
|
+
* t = 0.7308548609?
|
50
|
+
* v = 7.1696861856?
|
51
51
|
EOF
|
52
52
|
end
|
53
53
|
end
|
data/spec/model_spec.rb
CHANGED
@@ -1,44 +1,46 @@
|
|
1
1
|
# Solver and Model specs are codependent, so half of functionality of each is tested in other class's tests
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
module Z3
|
3
|
+
describe Model do
|
4
|
+
let(:solver) { Solver.new }
|
5
|
+
let(:a) { Z3.Int("a") }
|
6
|
+
let(:b) { Z3.Int("b") }
|
7
|
+
let(:c) { Z3.Int("c") }
|
8
|
+
let(:model) { solver.model }
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
it "knows how many variables are in the model" do
|
11
|
+
solver.assert(a == 2)
|
12
|
+
solver.assert(b == a+2)
|
13
|
+
expect(solver.check).to eq(:sat)
|
14
|
+
expect(model.num_consts).to eq(2)
|
15
|
+
expect(model.num_funcs).to eq(0)
|
16
|
+
expect(model.num_sorts).to eq(0)
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
19
|
+
it "can evaluate variables" do
|
20
|
+
solver.assert(a == 2)
|
21
|
+
solver.assert(b == a+2)
|
22
|
+
expect(solver.check).to eq(:sat)
|
23
|
+
expect(model.model_eval(a)).to be_same_as(Z3.Const(2))
|
24
|
+
expect(model.model_eval(b)).to be_same_as(Z3.Const(4))
|
25
|
+
expect(model.model_eval(c)).to be_same_as(c)
|
26
|
+
expect(model.model_eval(a, true)).to be_same_as(Z3.Const(2))
|
27
|
+
expect(model.model_eval(b, true)).to be_same_as(Z3.Const(4))
|
28
|
+
expect(model.model_eval(c, true)).to be_same_as(Z3.Const(0))
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
it "#to_a" do
|
32
|
+
solver.assert(a == 2)
|
33
|
+
solver.assert(b == a+2)
|
34
|
+
expect(solver.check).to eq(:sat)
|
35
|
+
expect(model.to_a).to be_same_as([[Z3.Int("a"), Z3.Const(2)], [Z3.Int("b"), Z3.Const(4)]])
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
it "#to_s" do
|
39
|
+
solver.assert(a == 2)
|
40
|
+
solver.assert(b == a+2)
|
41
|
+
expect(solver.check).to eq(:sat)
|
42
|
+
expect(model.to_s).to eq("Z3::Model<a=2, b=4>")
|
43
|
+
expect(model.inspect).to eq("Z3::Model<a=2, b=4>")
|
44
|
+
end
|
43
45
|
end
|
44
46
|
end
|
data/spec/printer_spec.rb
CHANGED
@@ -1,22 +1,53 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
module Z3
|
2
|
+
describe Printer do
|
3
|
+
it "numbers" do
|
4
|
+
expect(IntSort.new.from_const(42)).to stringify("42")
|
5
|
+
expect(IntSort.new.from_const(-42)).to stringify("-42")
|
6
|
+
expect(RealSort.new.from_const(42)).to stringify("42")
|
7
|
+
expect(RealSort.new.from_const(-42)).to stringify("-42")
|
8
|
+
expect(RealSort.new.from_const(3.14)).to stringify("157/50")
|
9
|
+
expect(RealSort.new.from_const(-3.14)).to stringify("-157/50")
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
it "booleans" do
|
13
|
+
expect(Z3.True).to stringify("true")
|
14
|
+
expect(Z3.False).to stringify("false")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "variables" do
|
18
|
+
expect(Z3.Int("a")).to stringify("a")
|
19
|
+
expect(Z3.Real("a")).to stringify("a")
|
20
|
+
expect(Z3.Bool("a")).to stringify("a")
|
21
|
+
expect(Z3.Bitvec("a", 32)).to stringify("a")
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "expressions" do
|
25
|
+
let(:a) { Z3.Int("a") }
|
26
|
+
let(:b) { Z3.Int("b") }
|
27
|
+
let(:c) { Z3.Int("c") }
|
28
|
+
|
29
|
+
it "binary operators" do
|
30
|
+
expect(a + b).to stringify("a + b")
|
31
|
+
expect(a - b).to stringify("a - b")
|
32
|
+
expect(a * b).to stringify("a * b")
|
33
|
+
expect(a / b).to stringify("div(a, b)")
|
34
|
+
expect(a.mod b).to stringify("mod(a, b)")
|
35
|
+
expect(a.rem b).to stringify("rem(a, b)")
|
36
|
+
end
|
37
|
+
|
38
|
+
it "parentheses" do
|
39
|
+
expect(a + b + c).to stringify("(a + b) + c")
|
40
|
+
expect(a + b * c).to stringify("a + (b * c)")
|
41
|
+
expect((a + b) * c).to stringify("(a + b) * c")
|
42
|
+
expect(a.mod(b + c)).to stringify("mod(a, b + c)")
|
43
|
+
expect(a.mod(b) + c).to stringify("mod(a, b) + c")
|
44
|
+
end
|
15
45
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
46
|
+
it "unary operators" do
|
47
|
+
expect(-a).to stringify("-a")
|
48
|
+
expect(-(a + b)).to stringify("-(a + b)")
|
49
|
+
expect((-a) + (-b)).to stringify("(-a) + (-b)")
|
50
|
+
end
|
51
|
+
end
|
21
52
|
end
|
22
53
|
end
|
data/spec/probe_spec.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Z3
|
2
|
+
describe Probe do
|
3
|
+
it "names" do
|
4
|
+
expect(Probe.names).to include("num-consts")
|
5
|
+
end
|
6
|
+
|
7
|
+
# Just simple way to brute force coverage
|
8
|
+
it "probe building" do
|
9
|
+
a = Probe.named("num-consts") < Probe.const(10.0)
|
10
|
+
b = Probe.named("size") <= Probe.named("depth")
|
11
|
+
c = Probe.named("num-bool-consts") > Probe.const(1.5)
|
12
|
+
d = Probe.named("memory") >= Probe.const(4000)
|
13
|
+
e = (a == b) & (~c | d)
|
14
|
+
expect(e.is_a?(Probe)).to be true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/spec/real_expr_spec.rb
CHANGED
@@ -1,64 +1,72 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module Z3
|
2
|
+
describe RealExpr do
|
3
|
+
let(:a) { Z3.Real("a") }
|
4
|
+
let(:b) { Z3.Real("b") }
|
5
|
+
let(:c) { Z3.Real("c") }
|
6
|
+
let(:x) { Z3.Bool("x") }
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
it "+" do
|
9
|
+
expect([a == 2, b == 4, c == a + b]).to have_solution(c => 6)
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
it "-" do
|
13
|
+
expect([a == 2, b == 4, c == a - b]).to have_solution(c => -2)
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
it "*" do
|
17
|
+
expect([a == 2, b == 4, c == a * b]).to have_solution(c => 8)
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
it "/" do
|
21
|
+
expect([a == 10, b == 3, c == a / b]).to have_solution(c => "10/3")
|
22
|
+
expect([a == -10, b == 3, c == a / b]).to have_solution(c => "-10/3")
|
23
|
+
expect([a == 10, b == -3, c == a / b]).to have_solution(c => "-10/3")
|
24
|
+
expect([a == -10, b == -3, c == a / b]).to have_solution(c => "10/3")
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
it "==" do
|
28
|
+
expect([a == 2, b == 2, x == (a == b)]).to have_solution(x => true)
|
29
|
+
expect([a == 2, b == 3, x == (a == b)]).to have_solution(x => false)
|
30
|
+
end
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
it "!=" do
|
33
|
+
expect([a == 2, b == 2, x == (a != b)]).to have_solution(x => false)
|
34
|
+
expect([a == 2, b == 3, x == (a != b)]).to have_solution(x => true)
|
35
|
+
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
it ">" do
|
38
|
+
expect([a == 3, b == 2, x == (a > b)]).to have_solution(x => true)
|
39
|
+
expect([a == 2, b == 2, x == (a > b)]).to have_solution(x => false)
|
40
|
+
expect([a == 1, b == 2, x == (a > b)]).to have_solution(x => false)
|
41
|
+
end
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
it ">=" do
|
44
|
+
expect([a == 3, b == 2, x == (a >= b)]).to have_solution(x => true)
|
45
|
+
expect([a == 2, b == 2, x == (a >= b)]).to have_solution(x => true)
|
46
|
+
expect([a == 1, b == 2, x == (a >= b)]).to have_solution(x => false)
|
47
|
+
end
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
49
|
+
it "<" do
|
50
|
+
expect([a == 3, b == 2, x == (a < b)]).to have_solution(x => false)
|
51
|
+
expect([a == 2, b == 2, x == (a < b)]).to have_solution(x => false)
|
52
|
+
expect([a == 1, b == 2, x == (a < b)]).to have_solution(x => true)
|
53
|
+
end
|
53
54
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
55
|
+
it "<=" do
|
56
|
+
expect([a == 3, b == 2, x == (a <= b)]).to have_solution(x => false)
|
57
|
+
expect([a == 2, b == 2, x == (a <= b)]).to have_solution(x => true)
|
58
|
+
expect([a == 1, b == 2, x == (a <= b)]).to have_solution(x => true)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "**" do
|
62
|
+
expect([a == 3, b == 4, c == (a ** b)]).to have_solution(c => 81)
|
63
|
+
expect([a == 81, b == 0.25, c == (a ** b)]).to have_solution(c => 3)
|
64
|
+
end
|
59
65
|
|
60
|
-
|
61
|
-
|
62
|
-
|
66
|
+
it "unary -" do
|
67
|
+
expect([a == 3, b == -a]).to have_solution(b => -3)
|
68
|
+
expect([a == 0, b == -a]).to have_solution(b => 0)
|
69
|
+
expect([a == 3.5, b == -a]).to have_solution(b => "-7/2")
|
70
|
+
end
|
63
71
|
end
|
64
72
|
end
|
data/spec/real_sort_spec.rb
CHANGED
@@ -1,24 +1,26 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
module Z3
|
2
|
+
describe RealSort do
|
3
|
+
it "can instantiate constants" do
|
4
|
+
expect(subject.from_const(0).inspect).to eq("Real<0>")
|
5
|
+
expect(subject.from_const(42).inspect).to eq("Real<42>")
|
6
|
+
expect(subject.from_const(1_000_000_000_000).inspect).to eq("Real<1000000000000>")
|
7
|
+
expect(subject.from_const(-1_000_000_000_000).inspect).to eq("Real<-1000000000000>")
|
8
|
+
expect(subject.from_const(0.0).inspect).to eq("Real<0>")
|
9
|
+
expect(subject.from_const(-0.0).inspect).to eq("Real<0>")
|
10
|
+
expect(subject.from_const(3.14).inspect).to eq("Real<157/50>")
|
11
|
+
expect(subject.from_const(-3.14).inspect).to eq("Real<-157/50>")
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
it "raises exception when trying to convert constants of wrong type" do
|
15
|
+
expect{ subject.from_const(true) }.to raise_error(Z3::Exception)
|
16
|
+
expect{ subject.from_const(false) }.to raise_error(Z3::Exception)
|
17
|
+
expect{ subject.from_const(1.0 / 0.0) }.to raise_error(Z3::Exception)
|
18
|
+
expect{ subject.from_const(-1.0 / 0.0) }.to raise_error(Z3::Exception)
|
19
|
+
expect{ subject.from_const(0.0 / 0.0) }.to raise_error(Z3::Exception)
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
22
|
+
it "can instantiate variables" do
|
23
|
+
expect(Z3.Real("a").inspect).to eq("Real<a>")
|
24
|
+
end
|
23
25
|
end
|
24
26
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Z3
|
2
|
+
describe RoundingModeExpr do
|
3
|
+
let(:sort) { RoundingModeSort.new }
|
4
|
+
let(:a) { sort.var("a") }
|
5
|
+
|
6
|
+
it "list all possible options" do
|
7
|
+
expect([a == a]).to have_solutions([
|
8
|
+
{ a => sort.nearest_ties_away },
|
9
|
+
{ a => sort.nearest_ties_even },
|
10
|
+
{ a => sort.towards_zero },
|
11
|
+
{ a => sort.towards_negative },
|
12
|
+
{ a => sort.towards_positive },
|
13
|
+
])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|