z3 0.0.20160330 → 0.0.20160427
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/examples/{bridges_solver → bridges} +5 -12
- data/examples/bridges-1.txt +7 -0
- data/examples/{clogic_puzzle_solver → clogic_puzzle} +0 -0
- data/examples/four_hackers_puzzle +2 -1
- data/examples/{kakuro_solver → kakuro} +5 -15
- data/examples/kakuro-1.txt +10 -0
- data/examples/{knights_puzzle_solver → knights_puzzle} +4 -4
- data/examples/{letter_connections_solver → letter_connections} +6 -15
- data/examples/letter_connections-1.txt +10 -0
- data/examples/{light_up_solver → light_up} +5 -12
- data/examples/light_up-1.txt +7 -0
- data/examples/{minisudoku_solver → minisudoku} +8 -11
- data/examples/minisudoku-1.txt +6 -0
- data/examples/nonogram +152 -0
- data/examples/{selfref_solver → selfref} +0 -0
- data/examples/{sudoku_solver → sudoku} +9 -14
- data/examples/sudoku-1.txt +9 -0
- data/lib/z3.rb +10 -6
- data/lib/z3/ast.rb +33 -0
- data/lib/z3/{value/arith_value.rb → expr/arith_expr.rb} +3 -3
- data/lib/z3/{value/bitvec_value.rb → expr/bitvec_expr.rb} +1 -1
- data/lib/z3/{value/bool_value.rb → expr/bool_expr.rb} +5 -1
- data/lib/z3/{value/value.rb → expr/expr.rb} +7 -13
- data/lib/z3/expr/int_expr.rb +15 -0
- data/lib/z3/{value/int_value.rb → expr/real_expr.rb} +2 -2
- data/lib/z3/func_decl.rb +33 -23
- data/lib/z3/interface.rb +52 -30
- data/lib/z3/low_level.rb +10 -1
- data/lib/z3/low_level_auto.rb +83 -83
- data/lib/z3/model.rb +6 -5
- data/lib/z3/printer.rb +26 -0
- data/lib/z3/solver.rb +1 -5
- data/lib/z3/sort/bitvec_sort.rb +3 -3
- data/lib/z3/sort/bool_sort.rb +4 -4
- data/lib/z3/sort/int_sort.rb +2 -2
- data/lib/z3/sort/real_sort.rb +5 -5
- data/lib/z3/sort/sort.rb +22 -7
- data/lib/z3/very_low_level.rb +1 -1
- data/spec/bitvec_expr_spec.rb +55 -0
- data/spec/bitvec_sort_spec.rb +34 -0
- data/spec/bool_expr_spec.rb +65 -0
- data/spec/bool_sort_spec.rb +20 -0
- data/spec/{value_spec.rb → expr_spec.rb} +3 -3
- data/spec/int_expr_spec.rb +78 -0
- data/spec/int_sort_spec.rb +18 -0
- data/spec/integration/algebra_problems_spec.rb +19 -20
- data/spec/integration/basic_int_math_spec.rb +4 -5
- data/spec/integration/basic_logic_spec.rb +3 -4
- data/spec/integration/bit_tricks_spec.rb +2 -3
- data/spec/integration/bridges_spec.rb +2 -3
- data/spec/integration/four_hackers_puzzle_spec.rb +26 -0
- data/spec/integration/geometry_problem_spec.rb +10 -11
- data/spec/integration/kakuro_spec.rb +2 -3
- data/spec/integration/kinematics_problems_spec.rb +36 -37
- data/spec/integration/knights_puzzle_spec.rb +96 -0
- data/spec/integration/letter_connections_spec.rb +2 -3
- data/spec/integration/light_up_spec.rb +3 -4
- data/spec/integration/minisudoku_spec.rb +2 -3
- data/spec/integration/nonogram_spec.rb +26 -0
- data/spec/integration/selfref_spec.rb +2 -3
- data/spec/integration/sudoku_spec.rb +2 -3
- data/spec/integration/verbal_arithmetic_spec.rb +2 -3
- data/spec/model_spec.rb +13 -6
- data/spec/printer_spec.rb +22 -0
- data/spec/real_expr_spec.rb +64 -0
- data/spec/real_sort_spec.rb +24 -0
- data/spec/solver_spec.rb +11 -0
- data/spec/spec_helper.rb +39 -64
- metadata +81 -18
- 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
|
-
|
3
|
-
|
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 =
|
8
|
-
*
|
9
|
-
*
|
6
|
+
* x = -22
|
7
|
+
* |\\|-6\\|| = 6
|
8
|
+
* |\\|x-2\\|| = 24
|
10
9
|
Solution to problem 04:
|
11
|
-
* ax =
|
12
|
-
* ay =
|
13
|
-
* bx =
|
14
|
-
* by =
|
15
|
-
*
|
10
|
+
* ax = -4
|
11
|
+
* ay = -5
|
12
|
+
* bx = -1
|
13
|
+
* by = -1
|
14
|
+
* |\\|a-b\\|| = 5
|
16
15
|
Solution to problem 05:
|
17
|
-
* x =
|
18
|
-
* y = 0
|
16
|
+
* x = 9/2
|
17
|
+
* y = 0
|
19
18
|
Solution to problem 06:
|
20
|
-
* answer = 6
|
21
|
-
* x1 = 1
|
22
|
-
* x2 = 2
|
23
|
-
* y1 = 7
|
24
|
-
* y2 = 13
|
19
|
+
* answer = 6
|
20
|
+
* x1 = 1
|
21
|
+
* x2 = 2
|
22
|
+
* y1 = 7
|
23
|
+
* y2 = 13
|
25
24
|
Solution to problem 10:
|
26
|
-
* x = 1
|
27
|
-
*
|
25
|
+
* x = 1
|
26
|
+
* |\\|-2x + 2\\|| = 0
|
28
27
|
EOF
|
29
28
|
end
|
30
29
|
end
|
@@ -1,12 +1,11 @@
|
|
1
|
-
describe "Basic
|
2
|
-
|
3
|
-
|
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 =
|
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
|
-
|
3
|
-
|
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
|
-
|
3
|
-
|
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
|
-
|
3
|
-
|
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
|
-
|
3
|
-
|
4
|
-
|
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
|
8
|
-
* b.y = 0
|
9
|
-
* c.x = 10
|
10
|
-
* c.y = 0
|
11
|
-
* d.x = 10
|
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
|
-
*
|
14
|
-
*
|
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
|
-
|
3
|
-
|
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
|
-
|
3
|
-
|
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 =
|
7
|
-
* d =
|
8
|
-
* t =
|
5
|
+
* a = 16/5
|
6
|
+
* d = 215168/125
|
7
|
+
* t = 164/5
|
9
8
|
Solution to problem 02:
|
10
|
-
* a =
|
11
|
-
* d = 110
|
12
|
-
* t =
|
9
|
+
* a = 2200000/271441
|
10
|
+
* d = 110
|
11
|
+
* t = 521/100
|
13
12
|
Solution to problem 03:
|
14
|
-
* a =
|
15
|
-
* d =
|
16
|
-
* t =
|
17
|
-
* v =
|
13
|
+
* a = 981/100
|
14
|
+
* d = 165789/5000
|
15
|
+
* t = 13/5
|
16
|
+
* v = 12753/500
|
18
17
|
Solution to problem 04:
|
19
|
-
* a =
|
20
|
-
* d =
|
21
|
-
* t =
|
22
|
-
* ve =
|
23
|
-
* vs =
|
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 =
|
26
|
-
* d =
|
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 =
|
30
|
-
* d =
|
31
|
-
* t =
|
32
|
-
* v = 444
|
28
|
+
* a = 14800/61
|
29
|
+
* d = 20313/50
|
30
|
+
* t = 183/100
|
31
|
+
* v = 444
|
33
32
|
Solution to problem 07:
|
34
|
-
* a =
|
35
|
-
* d =
|
36
|
-
* t =
|
37
|
-
* v =
|
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
|
40
|
-
* d =
|
41
|
-
* t =
|
42
|
-
* v = 65
|
38
|
+
* a = 3
|
39
|
+
* d = 4225/6
|
40
|
+
* t = 65/3
|
41
|
+
* v = 65
|
43
42
|
Solution to problem 09:
|
44
|
-
* d =
|
45
|
-
* t =
|
46
|
-
* v =
|
43
|
+
* d = 714/25
|
44
|
+
* t = 51/20
|
45
|
+
* v = 112/5
|
47
46
|
Solution to problem 10:
|
48
|
-
* a =
|
49
|
-
* d =
|
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
|
-
|
3
|
-
|
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 "
|
2
|
-
|
3
|
-
|
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
|
-
|
3
|
-
|
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
|
-
|
3
|
-
|
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
|
-
|
3
|
-
|
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
|