z3 0.0.20160427 → 0.0.20161008

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +2 -0
  3. data/Rakefile +56 -0
  4. data/examples/bit_tricks +21 -38
  5. data/examples/circuit_problems +170 -0
  6. data/lib/z3/ast.rb +21 -3
  7. data/lib/z3/context.rb +9 -7
  8. data/lib/z3/exception.rb +1 -2
  9. data/lib/z3/expr/arith_expr.rb +29 -11
  10. data/lib/z3/expr/array_expr.rb +5 -0
  11. data/lib/z3/expr/bitvec_expr.rb +293 -13
  12. data/lib/z3/expr/bool_expr.rb +30 -6
  13. data/lib/z3/expr/expr.rb +155 -2
  14. data/lib/z3/expr/float_expr.rb +185 -0
  15. data/lib/z3/expr/int_expr.rb +20 -5
  16. data/lib/z3/expr/real_expr.rb +1 -3
  17. data/lib/z3/expr/rounding_mode_expr.rb +5 -0
  18. data/lib/z3/expr/set_expr.rb +66 -0
  19. data/lib/z3/func_decl.rb +5 -5
  20. data/lib/z3/goal.rb +64 -0
  21. data/lib/z3/interface.rb +21 -222
  22. data/lib/z3/low_level.rb +84 -58
  23. data/lib/z3/low_level_auto.rb +1509 -1563
  24. data/lib/z3/model.rb +39 -37
  25. data/lib/z3/printer.rb +54 -12
  26. data/lib/z3/probe.rb +69 -0
  27. data/lib/z3/solver.rb +20 -20
  28. data/lib/z3/sort/array_sort.rb +24 -0
  29. data/lib/z3/sort/bitvec_sort.rb +1 -1
  30. data/lib/z3/sort/float_sort.rb +92 -0
  31. data/lib/z3/sort/rounding_mode_sort.rb +41 -0
  32. data/lib/z3/sort/set_sort.rb +31 -0
  33. data/lib/z3/sort/sort.rb +39 -5
  34. data/lib/z3/tactic.rb +69 -0
  35. data/lib/z3/very_low_level.rb +33 -29
  36. data/lib/z3/very_low_level_auto.rb +505 -517
  37. data/lib/z3.rb +13 -0
  38. data/spec/array_expr_spec.rb +18 -0
  39. data/spec/array_sort_spec.rb +11 -0
  40. data/spec/bitvec_expr_spec.rb +196 -44
  41. data/spec/bitvec_sort_spec.rb +29 -27
  42. data/spec/bool_expr_spec.rb +57 -55
  43. data/spec/bool_sort_spec.rb +17 -15
  44. data/spec/coverage_helper.rb +11 -0
  45. data/spec/expr_spec.rb +151 -147
  46. data/spec/float_expr_spec.rb +167 -0
  47. data/spec/float_sort_spec.rb +44 -0
  48. data/spec/goal_spec.rb +17 -0
  49. data/spec/int_expr_spec.rb +76 -63
  50. data/spec/int_sort_spec.rb +16 -14
  51. data/spec/integration/algebra_problems_spec.rb +4 -4
  52. data/spec/integration/cicruit_problem_spec.rb +23 -0
  53. data/spec/integration/geometry_problem_spec.rb +4 -4
  54. data/spec/integration/kinematics_problems_spec.rb +3 -3
  55. data/spec/model_spec.rb +39 -37
  56. data/spec/printer_spec.rb +49 -18
  57. data/spec/probe_spec.rb +17 -0
  58. data/spec/real_expr_spec.rb +59 -51
  59. data/spec/real_sort_spec.rb +22 -20
  60. data/spec/rounding_mode_expr_spec.rb +16 -0
  61. data/spec/rounding_mode_sort_spec.rb +13 -0
  62. data/spec/set_expr_spec.rb +61 -0
  63. data/spec/set_sort_spec.rb +27 -0
  64. data/spec/solver_spec.rb +37 -27
  65. data/spec/sort_spec.rb +38 -36
  66. data/spec/spec_helper.rb +59 -2
  67. data/spec/tactic_spec.rb +9 -0
  68. metadata +44 -4
@@ -1,78 +1,91 @@
1
- describe Z3::IntExpr do
2
- let(:a) { Z3::Int("a") }
3
- let(:b) { Z3::Int("b") }
4
- let(:c) { Z3::Int("c") }
5
- let(:x) { Z3::Bool("x") }
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
- it "+" do
8
- expect([a == 2, b == 4, c == a + b]).to have_solution(c => 6)
9
- end
8
+ it "+" do
9
+ expect([a == 2, b == 4, c == a + b]).to have_solution(c => 6)
10
+ end
10
11
 
11
- it "-" do
12
- expect([a == 2, b == 4, c == a - b]).to have_solution(c => -2)
13
- end
12
+ it "-" do
13
+ expect([a == 2, b == 4, c == a - b]).to have_solution(c => -2)
14
+ end
14
15
 
15
- it "*" do
16
- expect([a == 2, b == 4, c == a * b]).to have_solution(c => 8)
17
- end
16
+ it "*" do
17
+ expect([a == 2, b == 4, c == a * b]).to have_solution(c => 8)
18
+ end
18
19
 
19
- it "/" do
20
- expect([a == 10, b == 3, c == a / b]).to have_solution(c => 3)
21
- expect([a == -10, b == 3, c == a / b]).to have_solution(c => -4)
22
- expect([a == 10, b == -3, c == a / b]).to have_solution(c => -3)
23
- expect([a == -10, b == -3, c == a / b]).to have_solution(c => 4)
24
- end
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
- # Can't say these make much sense, but let's document what Z3 actually does
27
- it "rem" do
28
- expect([a == 10, b == 3, c == a.rem(b)]).to have_solution(c => 10 - 3 * 3)
29
- expect([a == -10, b == 3, c == a.rem(b)]).to have_solution(c =>-10 - 3 * -4)
30
- expect([a == 10, b == -3, c == a.rem(b)]).to have_solution(c =>-( 10 - -3 * -3))
31
- expect([a == -10, b == -3, c == a.rem(b)]).to have_solution(c =>-(-10 - -3 * 4))
32
- end
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
- it "mod" do
35
- expect([a == 10, b == 3, c == a.mod(b)]).to have_solution(c => 1)
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 => 2)
38
- expect([a == -10, b == -3, c == a.mod(b)]).to have_solution(c => 2)
39
- end
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
- it "==" do
42
- expect([a == 2, b == 2, x == (a == b)]).to have_solution(x => true)
43
- expect([a == 2, b == 3, x == (a == b)]).to have_solution(x => false)
44
- end
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
- it "!=" do
47
- expect([a == 2, b == 2, x == (a != b)]).to have_solution(x => false)
48
- expect([a == 2, b == 3, x == (a != b)]).to have_solution(x => true)
49
- end
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
- it ">" do
52
- expect([a == 3, b == 2, x == (a > b)]).to have_solution(x => true)
53
- expect([a == 2, b == 2, x == (a > b)]).to have_solution(x => false)
54
- expect([a == 1, b == 2, x == (a > b)]).to have_solution(x => false)
55
- end
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
- it ">=" do
58
- expect([a == 3, b == 2, x == (a >= b)]).to have_solution(x => true)
59
- expect([a == 2, b == 2, x == (a >= b)]).to have_solution(x => true)
60
- expect([a == 1, b == 2, x == (a >= b)]).to have_solution(x => false)
61
- end
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
- it "<" do
64
- expect([a == 3, b == 2, x == (a < b)]).to have_solution(x => false)
65
- expect([a == 2, b == 2, x == (a < b)]).to have_solution(x => false)
66
- expect([a == 1, b == 2, x == (a < b)]).to have_solution(x => true)
67
- end
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
- it "<=" do
70
- expect([a == 3, b == 2, x == (a <= b)]).to have_solution(x => false)
71
- expect([a == 2, b == 2, x == (a <= b)]).to have_solution(x => true)
72
- expect([a == 1, b == 2, x == (a <= b)]).to have_solution(x => true)
73
- end
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
- it "**" do
76
- expect([a == 3, b == 4, c == (a ** b)]).to have_solution(c => 81)
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
@@ -1,18 +1,20 @@
1
- describe Z3::IntSort do
2
- it "can instantiate constants" do
3
- expect(subject.from_const(0).inspect).to eq("Int<0>")
4
- expect(subject.from_const(42).inspect).to eq("Int<42>")
5
- expect(subject.from_const(1_000_000_000_000).inspect).to eq("Int<1000000000000>")
6
- expect(subject.from_const(-1_000_000_000_000).inspect).to eq("Int<-1000000000000>")
7
- end
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
- it "raises exception when trying to convert constants of wrong type" do
10
- expect{ subject.from_const(true) }.to raise_error(Z3::Exception)
11
- expect{ subject.from_const(false) }.to raise_error(Z3::Exception)
12
- expect{ subject.from_const(0.0) }.to raise_error(Z3::Exception)
13
- end
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
- it "can instantiate variables" do
16
- expect(Z3.Int("a").inspect).to eq("Int<a>")
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
- * |\\|-6\\|| = 6
8
- * |\\|x-2\\|| = 24
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
- * |\\|a-b\\|| = 5
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
- * |\\|-2x + 2\\|| = 0
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 = (root-obj (+ (^ x 2) (- 300)) 1)
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 = (root-obj (+ (^ x 2) (- 300)) 1)
12
- * |\\|a-c\\|| = -20
13
- * |\\|b-d\\|| = 20
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 = (root-obj (+ (* 167 (^ x 2)) (- 280)) 2)
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 = (root-obj (+ (* 981 (^ x 2)) (- 524)) 2)
50
- * v = (root-obj (+ (* 2500 (^ x 2)) (- 128511)) 2)
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
- describe Z3::Model do
3
- let(:solver) { Z3::Solver.new }
4
- let(:a) { Z3.Int("a") }
5
- let(:b) { Z3.Int("b") }
6
- let(:c) { Z3.Int("c") }
7
- let(:model) { solver.model }
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
- it "knows how many variables are in the model" do
10
- solver.assert(a == 2)
11
- solver.assert(b == a+2)
12
- expect(solver.check).to eq(:sat)
13
- expect(model.num_consts).to eq(2)
14
- expect(model.num_funcs).to eq(0)
15
- expect(model.num_sorts).to eq(0)
16
- end
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
- it "can evaluate variables" do
19
- solver.assert(a == 2)
20
- solver.assert(b == a+2)
21
- expect(solver.check).to eq(:sat)
22
- expect(model.model_eval(a)).to be_same_as(Z3.Const(2))
23
- expect(model.model_eval(b)).to be_same_as(Z3.Const(4))
24
- expect(model.model_eval(c)).to be_same_as(c)
25
- expect(model.model_eval(a, true)).to be_same_as(Z3.Const(2))
26
- expect(model.model_eval(b, true)).to be_same_as(Z3.Const(4))
27
- expect(model.model_eval(c, true)).to be_same_as(Z3.Const(0))
28
- end
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
- it "#to_a" do
31
- solver.assert(a == 2)
32
- solver.assert(b == a+2)
33
- expect(solver.check).to eq(:sat)
34
- expect(model.to_a).to be_same_as([[Z3.Int("a"), Z3.Const(2)], [Z3.Int("b"), Z3.Const(4)]])
35
- end
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
- it "#to_s" do
38
- solver.assert(a == 2)
39
- solver.assert(b == a+2)
40
- expect(solver.check).to eq(:sat)
41
- expect(model.to_s).to eq("Z3::Model<a=2, b=4>")
42
- expect(model.inspect).to eq("Z3::Model<a=2, b=4>")
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
- describe Z3::Printer do
2
- it "numbers" do
3
- expect(Z3::IntSort.new.from_const(42)).to stringify("42")
4
- expect(Z3::IntSort.new.from_const(-42)).to stringify("-42")
5
- expect(Z3::RealSort.new.from_const(42)).to stringify("42")
6
- expect(Z3::RealSort.new.from_const(-42)).to stringify("-42")
7
- expect(Z3::RealSort.new.from_const(3.14)).to stringify("157/50")
8
- expect(Z3::RealSort.new.from_const(-3.14)).to stringify("-157/50")
9
- end
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
- it "booleans" do
12
- expect(Z3.True).to stringify("true")
13
- expect(Z3.False).to stringify("false")
14
- end
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
- it "variables" do
17
- expect(Z3::Int("a")).to stringify("a")
18
- expect(Z3::Real("a")).to stringify("a")
19
- expect(Z3::Bool("a")).to stringify("a")
20
- expect(Z3::Bitvec("a", 32)).to stringify("a")
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
@@ -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
@@ -1,64 +1,72 @@
1
- describe Z3::RealExpr do
2
- let(:a) { Z3::Real("a") }
3
- let(:b) { Z3::Real("b") }
4
- let(:c) { Z3::Real("c") }
5
- let(:x) { Z3::Bool("x") }
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
- it "+" do
8
- expect([a == 2, b == 4, c == a + b]).to have_solution(c => 6)
9
- end
8
+ it "+" do
9
+ expect([a == 2, b == 4, c == a + b]).to have_solution(c => 6)
10
+ end
10
11
 
11
- it "-" do
12
- expect([a == 2, b == 4, c == a - b]).to have_solution(c => -2)
13
- end
12
+ it "-" do
13
+ expect([a == 2, b == 4, c == a - b]).to have_solution(c => -2)
14
+ end
14
15
 
15
- it "*" do
16
- expect([a == 2, b == 4, c == a * b]).to have_solution(c => 8)
17
- end
16
+ it "*" do
17
+ expect([a == 2, b == 4, c == a * b]).to have_solution(c => 8)
18
+ end
18
19
 
19
- it "/" do
20
- expect([a == 10, b == 3, c == a / b]).to have_solution(c => "10/3")
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
- end
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
- it "==" do
27
- expect([a == 2, b == 2, x == (a == b)]).to have_solution(x => true)
28
- expect([a == 2, b == 3, x == (a == b)]).to have_solution(x => false)
29
- end
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
- it "!=" do
32
- expect([a == 2, b == 2, x == (a != b)]).to have_solution(x => false)
33
- expect([a == 2, b == 3, x == (a != b)]).to have_solution(x => true)
34
- end
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
- it ">" do
37
- expect([a == 3, b == 2, x == (a > b)]).to have_solution(x => true)
38
- expect([a == 2, b == 2, x == (a > b)]).to have_solution(x => false)
39
- expect([a == 1, b == 2, x == (a > b)]).to have_solution(x => false)
40
- end
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
- it ">=" do
43
- expect([a == 3, b == 2, x == (a >= b)]).to have_solution(x => true)
44
- expect([a == 2, b == 2, x == (a >= b)]).to have_solution(x => true)
45
- expect([a == 1, b == 2, x == (a >= b)]).to have_solution(x => false)
46
- end
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
- it "<" do
49
- expect([a == 3, b == 2, x == (a < b)]).to have_solution(x => false)
50
- expect([a == 2, b == 2, x == (a < b)]).to have_solution(x => false)
51
- expect([a == 1, b == 2, x == (a < b)]).to have_solution(x => true)
52
- end
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
- it "<=" do
55
- expect([a == 3, b == 2, x == (a <= b)]).to have_solution(x => false)
56
- expect([a == 2, b == 2, x == (a <= b)]).to have_solution(x => true)
57
- expect([a == 1, b == 2, x == (a <= b)]).to have_solution(x => true)
58
- end
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
- it "**" do
61
- expect([a == 3, b == 4, c == (a ** b)]).to have_solution(c => 81)
62
- expect([a == 81, b == 0.25, c == (a ** b)]).to have_solution(c => 3)
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
@@ -1,24 +1,26 @@
1
- describe Z3::RealSort do
2
- it "can instantiate constants" do
3
- expect(subject.from_const(0).inspect).to eq("Real<0>")
4
- expect(subject.from_const(42).inspect).to eq("Real<42>")
5
- expect(subject.from_const(1_000_000_000_000).inspect).to eq("Real<1000000000000>")
6
- expect(subject.from_const(-1_000_000_000_000).inspect).to eq("Real<-1000000000000>")
7
- expect(subject.from_const(0.0).inspect).to eq("Real<0>")
8
- expect(subject.from_const(-0.0).inspect).to eq("Real<0>")
9
- expect(subject.from_const(3.14).inspect).to eq("Real<157/50>")
10
- expect(subject.from_const(-3.14).inspect).to eq("Real<-157/50>")
11
- end
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
- it "raises exception when trying to convert constants of wrong type" do
14
- expect{ subject.from_const(true) }.to raise_error(Z3::Exception)
15
- expect{ subject.from_const(false) }.to raise_error(Z3::Exception)
16
- expect{ subject.from_const(1.0 / 0.0) }.to raise_error(Z3::Exception)
17
- expect{ subject.from_const(-1.0 / 0.0) }.to raise_error(Z3::Exception)
18
- expect{ subject.from_const(0.0 / 0.0) }.to raise_error(Z3::Exception)
19
- end
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
- it "can instantiate variables" do
22
- expect(Z3.Real("a").inspect).to eq("Real<a>")
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