z3 0.0.20160330 → 0.0.20160427

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -0
  3. data/examples/{bridges_solver → bridges} +5 -12
  4. data/examples/bridges-1.txt +7 -0
  5. data/examples/{clogic_puzzle_solver → clogic_puzzle} +0 -0
  6. data/examples/four_hackers_puzzle +2 -1
  7. data/examples/{kakuro_solver → kakuro} +5 -15
  8. data/examples/kakuro-1.txt +10 -0
  9. data/examples/{knights_puzzle_solver → knights_puzzle} +4 -4
  10. data/examples/{letter_connections_solver → letter_connections} +6 -15
  11. data/examples/letter_connections-1.txt +10 -0
  12. data/examples/{light_up_solver → light_up} +5 -12
  13. data/examples/light_up-1.txt +7 -0
  14. data/examples/{minisudoku_solver → minisudoku} +8 -11
  15. data/examples/minisudoku-1.txt +6 -0
  16. data/examples/nonogram +152 -0
  17. data/examples/{selfref_solver → selfref} +0 -0
  18. data/examples/{sudoku_solver → sudoku} +9 -14
  19. data/examples/sudoku-1.txt +9 -0
  20. data/lib/z3.rb +10 -6
  21. data/lib/z3/ast.rb +33 -0
  22. data/lib/z3/{value/arith_value.rb → expr/arith_expr.rb} +3 -3
  23. data/lib/z3/{value/bitvec_value.rb → expr/bitvec_expr.rb} +1 -1
  24. data/lib/z3/{value/bool_value.rb → expr/bool_expr.rb} +5 -1
  25. data/lib/z3/{value/value.rb → expr/expr.rb} +7 -13
  26. data/lib/z3/expr/int_expr.rb +15 -0
  27. data/lib/z3/{value/int_value.rb → expr/real_expr.rb} +2 -2
  28. data/lib/z3/func_decl.rb +33 -23
  29. data/lib/z3/interface.rb +52 -30
  30. data/lib/z3/low_level.rb +10 -1
  31. data/lib/z3/low_level_auto.rb +83 -83
  32. data/lib/z3/model.rb +6 -5
  33. data/lib/z3/printer.rb +26 -0
  34. data/lib/z3/solver.rb +1 -5
  35. data/lib/z3/sort/bitvec_sort.rb +3 -3
  36. data/lib/z3/sort/bool_sort.rb +4 -4
  37. data/lib/z3/sort/int_sort.rb +2 -2
  38. data/lib/z3/sort/real_sort.rb +5 -5
  39. data/lib/z3/sort/sort.rb +22 -7
  40. data/lib/z3/very_low_level.rb +1 -1
  41. data/spec/bitvec_expr_spec.rb +55 -0
  42. data/spec/bitvec_sort_spec.rb +34 -0
  43. data/spec/bool_expr_spec.rb +65 -0
  44. data/spec/bool_sort_spec.rb +20 -0
  45. data/spec/{value_spec.rb → expr_spec.rb} +3 -3
  46. data/spec/int_expr_spec.rb +78 -0
  47. data/spec/int_sort_spec.rb +18 -0
  48. data/spec/integration/algebra_problems_spec.rb +19 -20
  49. data/spec/integration/basic_int_math_spec.rb +4 -5
  50. data/spec/integration/basic_logic_spec.rb +3 -4
  51. data/spec/integration/bit_tricks_spec.rb +2 -3
  52. data/spec/integration/bridges_spec.rb +2 -3
  53. data/spec/integration/four_hackers_puzzle_spec.rb +26 -0
  54. data/spec/integration/geometry_problem_spec.rb +10 -11
  55. data/spec/integration/kakuro_spec.rb +2 -3
  56. data/spec/integration/kinematics_problems_spec.rb +36 -37
  57. data/spec/integration/knights_puzzle_spec.rb +96 -0
  58. data/spec/integration/letter_connections_spec.rb +2 -3
  59. data/spec/integration/light_up_spec.rb +3 -4
  60. data/spec/integration/minisudoku_spec.rb +2 -3
  61. data/spec/integration/nonogram_spec.rb +26 -0
  62. data/spec/integration/selfref_spec.rb +2 -3
  63. data/spec/integration/sudoku_spec.rb +2 -3
  64. data/spec/integration/verbal_arithmetic_spec.rb +2 -3
  65. data/spec/model_spec.rb +13 -6
  66. data/spec/printer_spec.rb +22 -0
  67. data/spec/real_expr_spec.rb +64 -0
  68. data/spec/real_sort_spec.rb +24 -0
  69. data/spec/solver_spec.rb +11 -0
  70. data/spec/spec_helper.rb +39 -64
  71. metadata +81 -18
  72. data/lib/z3/value/real_value.rb +0 -7
@@ -0,0 +1,18 @@
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
8
+
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
14
+
15
+ it "can instantiate variables" do
16
+ expect(Z3.Int("a").inspect).to eq("Int<a>")
17
+ end
18
+ end
@@ -1,30 +1,29 @@
1
1
  describe "Algebra Problems" do
2
- let(:executable) { "#{__dir__}/../../examples/algebra_problems" }
3
- it "can solve algebra puzzles" do
4
- expect(IO.popen(executable).read).to eq <<EOF
2
+ it do
3
+ expect("algebra_problems").to have_output <<EOF
5
4
  Solution to problem 01:
6
5
  Solution to problem 03:
7
- * x = (- 22.0)
8
- * |-6| = 6.0
9
- * |x-2| = 24.0
6
+ * x = -22
7
+ * |\\|-6\\|| = 6
8
+ * |\\|x-2\\|| = 24
10
9
  Solution to problem 04:
11
- * ax = (- 4.0)
12
- * ay = (- 5.0)
13
- * bx = (- 1.0)
14
- * by = (- 1.0)
15
- * |a-b| = 5.0
10
+ * ax = -4
11
+ * ay = -5
12
+ * bx = -1
13
+ * by = -1
14
+ * |\\|a-b\\|| = 5
16
15
  Solution to problem 05:
17
- * x = (/ 9.0 2.0)
18
- * y = 0.0
16
+ * x = 9/2
17
+ * y = 0
19
18
  Solution to problem 06:
20
- * answer = 6.0
21
- * x1 = 1.0
22
- * x2 = 2.0
23
- * y1 = 7.0
24
- * y2 = 13.0
19
+ * answer = 6
20
+ * x1 = 1
21
+ * x2 = 2
22
+ * y1 = 7
23
+ * y2 = 13
25
24
  Solution to problem 10:
26
- * x = 1.0
27
- * |-2x + 2| = 0.0
25
+ * x = 1
26
+ * |\\|-2x + 2\\|| = 0
28
27
  EOF
29
28
  end
30
29
  end
@@ -1,12 +1,11 @@
1
- describe "Basic Int Math" do
2
- let(:executable) { "#{__dir__}/../../examples/basic_int_math" }
3
- it "can solve basic integer math problems" do
4
- expect(IO.popen(executable).read).to eq <<EOF
1
+ describe "Basic Integer Math" do
2
+ it do
3
+ expect("basic_int_math").to have_output <<EOF
5
4
  Checking if (a+b)(a-b)==a*a-b*b
6
5
  Proven
7
6
  Checking if a+b >= a
8
7
  Counterexample exists
9
- * b = (- 1)
8
+ * b = -1
10
9
  Checking if a+b >= a if a,b >= 0
11
10
  Proven
12
11
  EOF
@@ -1,7 +1,6 @@
1
- describe "Basic Logic" do
2
- let(:executable) { "#{__dir__}/../../examples/basic_logic" }
3
- it "can solve basic logic problems" do
4
- expect(IO.popen(executable).read).to eq <<EOF
1
+ describe "Basic Logic Problems" do
2
+ it do
3
+ expect("basic_logic").to have_output <<EOF
5
4
  Checking if true == true
6
5
  Proven
7
6
  Checking if true == false
@@ -1,7 +1,6 @@
1
1
  describe "Bit Tricks" do
2
- let(:executable) { "#{__dir__}/../../examples/bit_tricks" }
3
- it "can validate bit tricks" do
4
- expect(IO.popen(executable).read.gsub(/ *$/, "")).to eq <<EOF
2
+ it do
3
+ expect("bit_tricks").to have_output <<EOF
5
4
  Validating sign trick:
6
5
  Proven
7
6
  Validating sign trick:
@@ -1,7 +1,6 @@
1
1
  describe "Bridges" do
2
- let(:executable) { "#{__dir__}/../../examples/bridges_solver" }
3
- it "can solve bridges puzzle" do
4
- expect(IO.popen(executable).read.gsub(/ *$/, "")).to eq <<EOF
2
+ it do
3
+ expect("bridges").to have_output <<EOF
5
4
 
6
5
  3========6========4
7
6
  | ‖ ‖
@@ -0,0 +1,26 @@
1
+ describe "Four Hackers Puzzle" do
2
+ it do
3
+ expect("four_hackers_puzzle").to have_output <<EOF
4
+ 0-alias = Lennard
5
+ 0-amount = 160000
6
+ 0-country = Norway
7
+ 0-language = Perl
8
+ 0-name = Frogger
9
+ 1-alias = Badger
10
+ 1-amount = 80000
11
+ 1-country = Belgium
12
+ 1-language = Lisp
13
+ 1-name = Dragonene
14
+ 2-alias = Griffin
15
+ 2-amount = 10000
16
+ 2-country = Yemen
17
+ 2-language = Java
18
+ 2-name = Phineus
19
+ 3-alias = Monks
20
+ 3-amount = 640000
21
+ 3-country = England
22
+ 3-language = C
23
+ 3-name = Armand
24
+ EOF
25
+ end
26
+ end
@@ -1,17 +1,16 @@
1
1
  describe "Geometry Problem" do
2
- let(:executable) { "#{__dir__}/../../examples/geometry_problem" }
3
- it "can solve geometry problem" do
4
- expect(IO.popen(executable).read).to eq <<EOF
5
- * a.x = 0.0
2
+ it do
3
+ expect("geometry_problem").to have_output <<EOF
4
+ * a.x = 0
6
5
  * a.y = (root-obj (+ (^ x 2) (- 300)) 1)
7
- * b.x = 0.0
8
- * b.y = 0.0
9
- * c.x = 10.0
10
- * c.y = 0.0
11
- * d.x = 10.0
6
+ * b.x = 0
7
+ * b.y = 0
8
+ * c.x = 10
9
+ * c.y = 0
10
+ * d.x = 10
12
11
  * d.y = (root-obj (+ (^ x 2) (- 300)) 1)
13
- * |a-c| = (- 20.0)
14
- * |b-d| = 20.0
12
+ * |\\|a-c\\|| = -20
13
+ * |\\|b-d\\|| = 20
15
14
  EOF
16
15
  end
17
16
  end
@@ -1,7 +1,6 @@
1
1
  describe "Kakuro" do
2
- let(:executable) { "#{__dir__}/../../examples/kakuro_solver" }
3
- it "can solve kakuro puzzle" do
4
- expect(IO.popen(executable).read.gsub(/ *$/, "")).to eq <<EOF
2
+ it do
3
+ expect("kakuro").to have_output <<EOF
5
4
  x x x 10/ 24/ 29/ x 11/ 21/ 10/
6
5
  x 11/ 19/24 [8] [9] [7] /6 [2] [3] [1]
7
6
  /31 [8] [9] [2] [7] [5] 10/20 [9] [8] [3]
@@ -1,52 +1,51 @@
1
1
  describe "Kinematics Problems" do
2
- let(:executable) { "#{__dir__}/../../examples/kinematics_problems" }
3
- it "can solve kinematics problems" do
4
- expect(IO.popen(executable).read).to eq <<EOF
2
+ it do
3
+ expect("kinematics_problems").to have_output <<EOF
5
4
  Solution to problem 01:
6
- * a = (/ 16.0 5.0)
7
- * d = (/ 215168.0 125.0)
8
- * t = (/ 164.0 5.0)
5
+ * a = 16/5
6
+ * d = 215168/125
7
+ * t = 164/5
9
8
  Solution to problem 02:
10
- * a = (/ 2200000.0 271441.0)
11
- * d = 110.0
12
- * t = (/ 521.0 100.0)
9
+ * a = 2200000/271441
10
+ * d = 110
11
+ * t = 521/100
13
12
  Solution to problem 03:
14
- * a = (/ 981.0 100.0)
15
- * d = (/ 165789.0 5000.0)
16
- * t = (/ 13.0 5.0)
17
- * v = (/ 12753.0 500.0)
13
+ * a = 981/100
14
+ * d = 165789/5000
15
+ * t = 13/5
16
+ * v = 12753/500
18
17
  Solution to problem 04:
19
- * a = (/ 2760.0 247.0)
20
- * d = (/ 79781.0 1000.0)
21
- * t = (/ 247.0 100.0)
22
- * ve = (/ 461.0 10.0)
23
- * vs = (/ 37.0 2.0)
18
+ * a = 2760/247
19
+ * d = 79781/1000
20
+ * t = 247/100
21
+ * ve = 461/10
22
+ * vs = 37/2
24
23
  Solution to problem 05:
25
- * a = (/ 167.0 100.0)
26
- * d = (/ 7.0 5.0)
24
+ * a = 167/100
25
+ * d = 7/5
27
26
  * t = (root-obj (+ (* 167 (^ x 2)) (- 280)) 2)
28
27
  Solution to problem 06:
29
- * a = (/ 14800.0 61.0)
30
- * d = (/ 20313.0 50.0)
31
- * t = (/ 183.0 100.0)
32
- * v = 444.0
28
+ * a = 14800/61
29
+ * d = 20313/50
30
+ * t = 183/100
31
+ * v = 444
33
32
  Solution to problem 07:
34
- * a = (/ 5041.0 7080.0)
35
- * d = (/ 177.0 5.0)
36
- * t = (/ 708.0 71.0)
37
- * v = (/ 71.0 10.0)
33
+ * a = 5041/7080
34
+ * d = 177/5
35
+ * t = 708/71
36
+ * v = 71/10
38
37
  Solution to problem 08:
39
- * a = 3.0
40
- * d = (/ 4225.0 6.0)
41
- * t = (/ 65.0 3.0)
42
- * v = 65.0
38
+ * a = 3
39
+ * d = 4225/6
40
+ * t = 65/3
41
+ * v = 65
43
42
  Solution to problem 09:
44
- * d = (/ 714.0 25.0)
45
- * t = (/ 51.0 20.0)
46
- * v = (/ 112.0 5.0)
43
+ * d = 714/25
44
+ * t = 51/20
45
+ * v = 112/5
47
46
  Solution to problem 10:
48
- * a = (- (/ 981.0 100.0))
49
- * d = (/ 131.0 50.0)
47
+ * a = -981/100
48
+ * d = 131/50
50
49
  * t = (root-obj (+ (* 981 (^ x 2)) (- 524)) 2)
51
50
  * v = (root-obj (+ (* 2500 (^ x 2)) (- 128511)) 2)
52
51
  EOF
@@ -0,0 +1,96 @@
1
+ describe "Knights Swap Puzzle" do
2
+ it do
3
+ expect("knights_puzzle").to have_output <<EOF
4
+ Solved
5
+ State 0:
6
+ bbb.
7
+ xbxw
8
+ ..ww
9
+ x.xw
10
+ b: 1,1 -> 3,0
11
+
12
+ State 1:
13
+ bbbb
14
+ x.xw
15
+ ..ww
16
+ x.xw
17
+ w: 3,2 -> 1,1
18
+
19
+ State 2:
20
+ bbbb
21
+ xwxw
22
+ ..w.
23
+ x.xw
24
+ b: 2,0 -> 3,2
25
+
26
+ State 3:
27
+ bb.b
28
+ xwxw
29
+ ..wb
30
+ x.xw
31
+ w: 3,3 -> 1,2
32
+
33
+ State 4:
34
+ bb.b
35
+ xwxw
36
+ .wwb
37
+ x.x.
38
+ w: 1,2 -> 2,0
39
+
40
+ State 5:
41
+ bbwb
42
+ xwxw
43
+ ..wb
44
+ x.x.
45
+ b: 0,0 -> 1,2
46
+
47
+ State 6:
48
+ .bwb
49
+ xwxw
50
+ .bwb
51
+ x.x.
52
+ b: 1,2 -> 3,3
53
+
54
+ State 7:
55
+ .bwb
56
+ xwxw
57
+ ..wb
58
+ x.xb
59
+ w: 3,1 -> 1,2
60
+
61
+ State 8:
62
+ .bwb
63
+ xwx.
64
+ .wwb
65
+ x.xb
66
+ b: 1,0 -> 3,1
67
+
68
+ State 9:
69
+ ..wb
70
+ xwxb
71
+ .wwb
72
+ x.xb
73
+ w: 2,2 -> 1,0
74
+
75
+ State 10:
76
+ .wwb
77
+ xwxb
78
+ .w.b
79
+ x.xb
80
+ b: 3,0 -> 2,2
81
+
82
+ State 11:
83
+ .ww.
84
+ xwxb
85
+ .wbb
86
+ x.xb
87
+ w: 1,2 -> 0,0
88
+
89
+ State 12:
90
+ www.
91
+ xwxb
92
+ ..bb
93
+ x.xb
94
+ EOF
95
+ end
96
+ end
@@ -1,7 +1,6 @@
1
1
  describe "Letter Connections" do
2
- let(:executable) { "#{__dir__}/../../examples/letter_connections_solver" }
3
- it "can solve letter connections puzzle" do
4
- expect(IO.popen(executable).read.gsub(/ *$/, "")).to eq <<EOF
2
+ it do
3
+ expect("letter_connections").to have_output <<EOF
5
4
  →k →k *K *J →f →f →f →f *F *E
6
5
  ↑k ↓F →J ↑j ↑f →e →e →e →e ↑e
7
6
  ↑k →f →f →f ↑f ↑e *G ←g ←g ←g
@@ -1,7 +1,6 @@
1
- describe "LightUp" do
2
- let(:executable) { "#{__dir__}/../../examples/light_up_solver" }
3
- it "can solve light up puzzle" do
4
- expect(IO.popen(executable).read.gsub(/ *$/, "")).to eq <<EOF
1
+ describe "Light Up" do
2
+ it do
3
+ expect("light_up").to have_output <<EOF
5
4
  * 0
6
5
  *
7
6
  x 2*x
@@ -1,7 +1,6 @@
1
1
  describe "MiniSudoku" do
2
- let(:executable) { "#{__dir__}/../../examples/minisudoku_solver" }
3
- it "can solve minisudoku" do
4
- expect(IO.popen(executable).read).to eq <<EOF
2
+ it do
3
+ expect("minisudoku").to have_output <<EOF
5
4
  2 1 5 4 3 6
6
5
  3 6 4 1 2 5
7
6
  1 3 6 5 4 2
@@ -0,0 +1,26 @@
1
+ describe "Nonogram" do
2
+ it do
3
+ expect("nonogram").to have_output <<EOF
4
+ ··········███·······
5
+ ·········█████······
6
+ ·········███·█······
7
+ ·········██··█······
8
+ ······███·███·████··
9
+ ····██··██···███████
10
+ ··██████·█···█······
11
+ ·████···██··██······
12
+ ········█···█·······
13
+ ·······███··█·······
14
+ ·······██████·······
15
+ ·██···███████·······
16
+ ██████··███·█·······
17
+ █·██··██·█··█·······
18
+ ···████··█·█··███···
19
+ ········████·██·██··
20
+ ········███··███·█··
21
+ ·······███····███···
22
+ ······███···········
23
+ ······██·█··········
24
+ EOF
25
+ end
26
+ end
@@ -1,7 +1,6 @@
1
1
  describe "Self-Referential Aptitude Test" do
2
- let(:executable) { "#{__dir__}/../../examples/selfref_solver" }
3
- it "can solve Self-Referential Aptitude Test" do
4
- expect(IO.popen(executable).read).to eq <<EOF
2
+ it do
3
+ expect("selfref").to have_output <<EOF
5
4
  Q 1: D
6
5
  Q 2: A
7
6
  Q 3: D
@@ -1,7 +1,6 @@
1
1
  describe "Sudoku" do
2
- let(:executable) { "#{__dir__}/../../examples/sudoku_solver" }
3
- it "can solve sudoku" do
4
- expect(IO.popen(executable).read).to eq <<EOF
2
+ it do
3
+ expect("sudoku").to have_output <<EOF
5
4
  8 6 3 5 7 9 2 4 1
6
5
  9 2 5 3 1 4 8 7 6
7
6
  4 7 1 8 2 6 9 5 3