z3 0.0.20160221 → 0.0.20160323
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/examples/algebra_problems +24 -24
- data/examples/basic_int_math +8 -8
- data/examples/basic_logic +8 -8
- data/examples/bit_tricks +161 -0
- data/examples/bridges_solver +1 -1
- data/examples/clogic_puzzle_solver +135 -0
- data/examples/four_hackers_puzzle +194 -0
- data/examples/geometry_problem +11 -11
- data/examples/kakuro_solver +3 -3
- data/examples/kinematics_problems +37 -37
- data/examples/letter_connections_solver +11 -11
- data/examples/light_up_solver +5 -5
- data/examples/minisudoku_solver +4 -4
- data/examples/selfref_solver +35 -35
- data/examples/sudoku_solver +4 -4
- data/examples/verbal_arithmetic +2 -2
- data/lib/z3/exception.rb +25 -0
- data/lib/z3/func_decl.rb +7 -7
- data/lib/z3/interface.rb +255 -0
- data/lib/z3/low_level.rb +4 -6
- data/lib/z3/low_level_auto.rb +1551 -1547
- data/lib/z3/model.rb +3 -2
- data/lib/z3/solver.rb +65 -54
- data/lib/z3/sort/bitvec_sort.rb +40 -0
- data/lib/z3/sort/bool_sort.rb +31 -0
- data/lib/z3/sort/int_sort.rb +21 -0
- data/lib/z3/sort/real_sort.rb +36 -0
- data/lib/z3/sort/sort.rb +76 -0
- data/lib/z3/value/arith_value.rb +53 -0
- data/lib/z3/value/bitvec_value.rb +67 -0
- data/lib/z3/value/bool_value.rb +29 -0
- data/lib/z3/value/int_value.rb +7 -0
- data/lib/z3/value/real_value.rb +7 -0
- data/lib/z3/value/value.rb +48 -0
- data/lib/z3/very_low_level.rb +28 -45
- data/lib/z3/very_low_level_auto.rb +518 -516
- data/lib/z3.rb +23 -33
- data/spec/integration/bit_tricks_spec.rb +21 -0
- data/spec/model_spec.rb +9 -9
- data/spec/solver_spec.rb +2 -2
- data/spec/sort_spec.rb +38 -13
- data/spec/{ast_spec.rb → value_spec.rb} +60 -57
- metadata +21 -6
- data/lib/z3/ast.rb +0 -302
- data/lib/z3/sort.rb +0 -33
- /data/spec/integration/{bagic_int_math_spec.rb → basic_int_math_spec.rb} +0 -0
data/lib/z3.rb
CHANGED
@@ -1,43 +1,33 @@
|
|
1
1
|
module Z3
|
2
|
-
class <<self
|
3
|
-
def version
|
4
|
-
Z3::LowLevel.get_version.join(".")
|
5
|
-
end
|
6
|
-
|
7
|
-
def set_param(k,v)
|
8
|
-
Z3::LowLevel.global_param_set(k,v)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
class Z3::Exception < StandardError
|
14
2
|
end
|
15
3
|
|
4
|
+
# Low level base classes, do not use directly
|
16
5
|
require_relative "z3/very_low_level"
|
6
|
+
require_relative "z3/very_low_level_auto"
|
17
7
|
require_relative "z3/low_level"
|
8
|
+
require_relative "z3/low_level_auto"
|
9
|
+
|
10
|
+
# Classes
|
18
11
|
require_relative "z3/context"
|
19
12
|
require_relative "z3/solver"
|
20
|
-
require_relative "z3/sort"
|
21
|
-
require_relative "z3/ast"
|
22
13
|
require_relative "z3/model"
|
14
|
+
require_relative "z3/exception"
|
23
15
|
require_relative "z3/func_decl"
|
24
16
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
raise Z3::Exception, "Z3 library failed with error #{error}"
|
43
|
-
end
|
17
|
+
# Sorts
|
18
|
+
require_relative "z3/sort/sort"
|
19
|
+
require_relative "z3/sort/int_sort"
|
20
|
+
require_relative "z3/sort/real_sort"
|
21
|
+
require_relative "z3/sort/bool_sort"
|
22
|
+
require_relative "z3/sort/bitvec_sort"
|
23
|
+
|
24
|
+
# ASTs
|
25
|
+
require_relative "z3/value/value"
|
26
|
+
require_relative "z3/value/arith_value"
|
27
|
+
require_relative "z3/value/int_value"
|
28
|
+
require_relative "z3/value/real_value"
|
29
|
+
require_relative "z3/value/bool_value"
|
30
|
+
require_relative "z3/value/bitvec_value"
|
31
|
+
|
32
|
+
# Python-style interface
|
33
|
+
require_relative "z3/interface"
|
@@ -0,0 +1,21 @@
|
|
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
|
5
|
+
Validating sign trick:
|
6
|
+
Proven
|
7
|
+
Validating sign trick:
|
8
|
+
Proven
|
9
|
+
Validating abs without branching, version 1
|
10
|
+
Proven
|
11
|
+
Validating abs without branching, version 2
|
12
|
+
Proven
|
13
|
+
Validating min without branching
|
14
|
+
Proven
|
15
|
+
Validating max without branching
|
16
|
+
Proven
|
17
|
+
Validating is power of two
|
18
|
+
Proven
|
19
|
+
EOF
|
20
|
+
end
|
21
|
+
end
|
data/spec/model_spec.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# Solver and Model specs are codependent, so half of functionality of each is tested in other class's tests
|
2
2
|
describe Z3::Model do
|
3
3
|
let(:solver) { Z3::Solver.new }
|
4
|
-
let(:a) { Z3
|
5
|
-
let(:b) { Z3
|
6
|
-
let(:c) { Z3
|
4
|
+
let(:a) { Z3.Int("a") }
|
5
|
+
let(:b) { Z3.Int("b") }
|
6
|
+
let(:c) { Z3.Int("c") }
|
7
7
|
let(:model) { solver.model }
|
8
8
|
|
9
9
|
it "knows how many variables are in the model" do
|
@@ -19,12 +19,12 @@ describe Z3::Model do
|
|
19
19
|
solver.assert(a == 2)
|
20
20
|
solver.assert(b == a+2)
|
21
21
|
expect(solver.check).to eq(:sat)
|
22
|
-
expect(model.model_eval(a).
|
23
|
-
expect(model.model_eval(b).
|
24
|
-
expect(model.model_eval(c).
|
25
|
-
expect(model.model_eval(a, true).
|
26
|
-
expect(model.model_eval(b, true).
|
27
|
-
expect(model.model_eval(c, true).
|
22
|
+
expect(model.model_eval(a).to_s).to eq("2")
|
23
|
+
expect(model.model_eval(b).to_s).to eq("4")
|
24
|
+
expect(model.model_eval(c).to_s).to eq("c")
|
25
|
+
expect(model.model_eval(a, true).to_s).to eq("2")
|
26
|
+
expect(model.model_eval(b, true).to_s).to eq("4")
|
27
|
+
expect(model.model_eval(c, true).to_s).to eq("0")
|
28
28
|
end
|
29
29
|
|
30
30
|
it "#to_s" do
|
data/spec/solver_spec.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Solver and Model specs are codependent, so half of functionality of each is tested in other class's tests
|
2
2
|
describe Z3::Solver do
|
3
3
|
let(:solver) { Z3::Solver.new }
|
4
|
-
let(:a) { Z3
|
5
|
-
let(:b) { Z3
|
4
|
+
let(:a) { Z3.Int("a") }
|
5
|
+
let(:b) { Z3.Int("b") }
|
6
6
|
|
7
7
|
it "basic functionality" do
|
8
8
|
solver.assert(a == b)
|
data/spec/sort_spec.rb
CHANGED
@@ -1,22 +1,47 @@
|
|
1
1
|
describe Z3::Sort do
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
let(:bool_sort) { Z3::BoolSort.new }
|
3
|
+
let(:int_sort) { Z3::IntSort.new }
|
4
|
+
let(:real_sort) { Z3::RealSort.new }
|
5
|
+
let(:bv8_sort) { Z3::BitvecSort.new(8) }
|
6
|
+
let(:bv32_sort) { Z3::BitvecSort.new(32) }
|
7
|
+
|
8
|
+
let(:sorts) { [bool_sort, int_sort, real_sort, bv8_sort, bv32_sort] }
|
9
|
+
|
10
|
+
it "can't instantiate Sort abstract superclass" do
|
11
|
+
expect{ Z3::Sort.new }.to raise_error(NoMethodError)
|
5
12
|
end
|
6
13
|
|
7
|
-
it "#
|
8
|
-
expect(
|
9
|
-
expect(
|
14
|
+
it "#to_s" do
|
15
|
+
expect(bool_sort.to_s).to eq("Bool")
|
16
|
+
expect( int_sort.to_s).to eq("Int")
|
17
|
+
expect(real_sort.to_s).to eq("Real")
|
18
|
+
expect( bv8_sort.to_s).to eq("Bitvec(8)")
|
19
|
+
expect(bv32_sort.to_s).to eq("Bitvec(32)")
|
10
20
|
end
|
11
21
|
|
12
|
-
it "#
|
13
|
-
expect(
|
14
|
-
expect(
|
22
|
+
it "#inspect" do
|
23
|
+
expect(bool_sort.inspect).to eq("BoolSort")
|
24
|
+
expect( int_sort.inspect).to eq("IntSort")
|
25
|
+
expect(real_sort.inspect).to eq("RealSort")
|
26
|
+
expect( bv8_sort.inspect).to eq("BitvecSort(8)")
|
27
|
+
expect(bv32_sort.inspect).to eq("BitvecSort(32)")
|
15
28
|
end
|
16
29
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
30
|
+
describe "==" do
|
31
|
+
it "all Sorts are value-objects" do
|
32
|
+
expect(bool_sort).to eq( Z3::BoolSort.new )
|
33
|
+
expect( int_sort).to eq( Z3::IntSort.new )
|
34
|
+
expect(real_sort).to eq( Z3::RealSort.new )
|
35
|
+
expect( bv8_sort).to eq( Z3::BitvecSort.new(8) )
|
36
|
+
expect(bv32_sort).to eq( Z3::BitvecSort.new(32) )
|
37
|
+
end
|
38
|
+
|
39
|
+
it "is == to itself and no other sort" do
|
40
|
+
sorts.each do |sort1|
|
41
|
+
sorts.each do |sort2|
|
42
|
+
expect(sort1 == sort2).to eq(sort1.to_s == sort2.to_s)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
21
46
|
end
|
22
47
|
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
describe Z3::
|
2
|
-
let(:a) { Z3
|
3
|
-
let(:b) { Z3
|
4
|
-
let(:c) { Z3
|
5
|
-
let(:d) { Z3
|
6
|
-
let(:e) { Z3
|
7
|
-
let(:f) { Z3
|
1
|
+
describe Z3::Value do
|
2
|
+
let(:a) { Z3.Int("a") }
|
3
|
+
let(:b) { Z3.Int("b") }
|
4
|
+
let(:c) { Z3.Bool("c") }
|
5
|
+
let(:d) { Z3.Bool("d") }
|
6
|
+
let(:e) { Z3.Real("e") }
|
7
|
+
let(:f) { Z3.Real("f") }
|
8
8
|
|
9
9
|
it "#sort returns Sort object" do
|
10
|
-
expect(a.sort).to eq(Z3::
|
11
|
-
expect(c.sort).to eq(Z3::
|
12
|
-
expect(e.sort).to eq(Z3::
|
10
|
+
expect(a.sort).to eq(Z3::IntSort.new)
|
11
|
+
expect(c.sort).to eq(Z3::BoolSort.new)
|
12
|
+
expect(e.sort).to eq(Z3::RealSort.new)
|
13
13
|
end
|
14
14
|
|
15
15
|
it "#to_s" do
|
@@ -17,8 +17,8 @@ describe Z3::Ast do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it "#inspect" do
|
20
|
-
expect(a.inspect).to eq("
|
21
|
-
expect((e+f).inspect).to eq("
|
20
|
+
expect(a.inspect).to eq("Value<a :: Int>")
|
21
|
+
expect((e+f).inspect).to eq("Value<(+ e f) :: Real>")
|
22
22
|
end
|
23
23
|
|
24
24
|
describe "#~" do
|
@@ -27,8 +27,8 @@ describe Z3::Ast do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
it "raises exception if type cast is not possible" do
|
30
|
-
expect{~a}.to raise_error(
|
31
|
-
expect{~e}.to raise_error(
|
30
|
+
expect{~a}.to raise_error(NoMethodError)
|
31
|
+
expect{~e}.to raise_error(NoMethodError)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -38,12 +38,12 @@ describe Z3::Ast do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
it "raises exception if type cast is not possible" do
|
41
|
-
expect{a&b}.to raise_error(
|
42
|
-
expect{e&f}.to raise_error(
|
43
|
-
expect{a&c}.to raise_error(
|
44
|
-
expect{e&c}.to raise_error(
|
45
|
-
expect{c&a}.to raise_error(
|
46
|
-
expect{c&e}.to raise_error(
|
41
|
+
expect{a&b}.to raise_error(NoMethodError)
|
42
|
+
expect{e&f}.to raise_error(NoMethodError)
|
43
|
+
expect{a&c}.to raise_error(NoMethodError)
|
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
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -53,12 +53,12 @@ describe Z3::Ast do
|
|
53
53
|
end
|
54
54
|
|
55
55
|
it "raises exception if type cast is not possible" do
|
56
|
-
expect{a|b}.to raise_error(
|
57
|
-
expect{e|f}.to raise_error(
|
58
|
-
expect{a|c}.to raise_error(
|
59
|
-
expect{e|c}.to raise_error(
|
60
|
-
expect{c|a}.to raise_error(
|
61
|
-
expect{c|e}.to raise_error(
|
56
|
+
expect{a|b}.to raise_error(NoMethodError)
|
57
|
+
expect{e|f}.to raise_error(NoMethodError)
|
58
|
+
expect{a|c}.to raise_error(NoMethodError)
|
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
62
|
end
|
63
63
|
end
|
64
64
|
|
@@ -83,17 +83,20 @@ describe Z3::Ast do
|
|
83
83
|
end
|
84
84
|
|
85
85
|
it "raises exception if type cast is not possible" do
|
86
|
-
|
87
|
-
expect{
|
88
|
-
expect{e.send op, c}.to raise_error(
|
89
|
-
expect{
|
90
|
-
expect{
|
91
|
-
expect{
|
92
|
-
expect{
|
93
|
-
|
94
|
-
|
95
|
-
expect{c.send op,
|
96
|
-
expect{
|
86
|
+
# Int/Real has #>= #+ etc. but they don't like these arguments
|
87
|
+
expect{a.send op, c}.to raise_error(ArgumentError)
|
88
|
+
expect{e.send op, c}.to raise_error(ArgumentError)
|
89
|
+
expect{a.send op, true}.to raise_error(ArgumentError)
|
90
|
+
expect{a.send op, false}.to raise_error(ArgumentError)
|
91
|
+
expect{e.send op, true}.to raise_error(ArgumentError)
|
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)
|
97
100
|
end
|
98
101
|
end
|
99
102
|
end
|
@@ -121,16 +124,16 @@ describe Z3::Ast do
|
|
121
124
|
end
|
122
125
|
|
123
126
|
it "raises exception if type cast is not possible" do
|
124
|
-
expect{a == c}.to raise_error(
|
125
|
-
expect{e == c}.to raise_error(
|
126
|
-
expect{a == true}.to raise_error(
|
127
|
-
expect{e == true}.to raise_error(
|
128
|
-
# expect{true == a}.to raise_error(
|
129
|
-
# expect{true == e}.to raise_error(
|
130
|
-
expect{c == 42}.to raise_error(
|
131
|
-
expect{c == 42.5}.to raise_error(
|
132
|
-
expect{42 == c}.to raise_error(
|
133
|
-
expect{42.5 == c}.to raise_error(
|
127
|
+
expect{a == c}.to raise_error(ArgumentError)
|
128
|
+
expect{e == c}.to raise_error(ArgumentError)
|
129
|
+
expect{a == true}.to raise_error(ArgumentError)
|
130
|
+
expect{e == true}.to raise_error(ArgumentError)
|
131
|
+
# expect{true == a}.to raise_error(ArgumentError)
|
132
|
+
# expect{true == e}.to raise_error(ArgumentError)
|
133
|
+
expect{c == 42}.to raise_error(ArgumentError)
|
134
|
+
expect{c == 42.5}.to raise_error(ArgumentError)
|
135
|
+
expect{42 == c}.to raise_error(ArgumentError)
|
136
|
+
expect{42.5 == c}.to raise_error(ArgumentError)
|
134
137
|
end
|
135
138
|
end
|
136
139
|
|
@@ -157,16 +160,16 @@ describe Z3::Ast do
|
|
157
160
|
end
|
158
161
|
|
159
162
|
it "raises exception if type cast is not possible" do
|
160
|
-
expect{a != c}.to raise_error(
|
161
|
-
expect{e != c}.to raise_error(
|
162
|
-
expect{a != true}.to raise_error(
|
163
|
-
expect{e != true}.to raise_error(
|
164
|
-
# expect{true != a}.to raise_error(
|
165
|
-
# expect{true != e}.to raise_error(
|
166
|
-
expect{c != 42}.to raise_error(
|
167
|
-
expect{c != 42.5}.to raise_error(
|
168
|
-
# expect{42 != c}.to raise_error(
|
169
|
-
# expect{42.5 != c}.to raise_error(
|
163
|
+
expect{a != c}.to raise_error(ArgumentError)
|
164
|
+
expect{e != c}.to raise_error(ArgumentError)
|
165
|
+
expect{a != true}.to raise_error(ArgumentError)
|
166
|
+
expect{e != true}.to raise_error(ArgumentError)
|
167
|
+
# expect{true != a}.to raise_error(ArgumentError)
|
168
|
+
# expect{true != e}.to raise_error(ArgumentError)
|
169
|
+
expect{c != 42}.to raise_error(ArgumentError)
|
170
|
+
expect{c != 42.5}.to raise_error(ArgumentError)
|
171
|
+
# expect{42 != c}.to raise_error(ArgumentError)
|
172
|
+
# expect{42.5 != c}.to raise_error(ArgumentError)
|
170
173
|
end
|
171
174
|
end
|
172
175
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: z3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.20160323
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomasz Wegrzanowski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -34,7 +34,10 @@ files:
|
|
34
34
|
- examples/algebra_problems
|
35
35
|
- examples/basic_int_math
|
36
36
|
- examples/basic_logic
|
37
|
+
- examples/bit_tricks
|
37
38
|
- examples/bridges_solver
|
39
|
+
- examples/clogic_puzzle_solver
|
40
|
+
- examples/four_hackers_puzzle
|
38
41
|
- examples/geometry_problem
|
39
42
|
- examples/kakuro_solver
|
40
43
|
- examples/kinematics_problems
|
@@ -45,20 +48,31 @@ files:
|
|
45
48
|
- examples/sudoku_solver
|
46
49
|
- examples/verbal_arithmetic
|
47
50
|
- lib/z3.rb
|
48
|
-
- lib/z3/ast.rb
|
49
51
|
- lib/z3/context.rb
|
52
|
+
- lib/z3/exception.rb
|
50
53
|
- lib/z3/func_decl.rb
|
54
|
+
- lib/z3/interface.rb
|
51
55
|
- lib/z3/low_level.rb
|
52
56
|
- lib/z3/low_level_auto.rb
|
53
57
|
- lib/z3/model.rb
|
54
58
|
- lib/z3/solver.rb
|
55
|
-
- lib/z3/sort.rb
|
59
|
+
- lib/z3/sort/bitvec_sort.rb
|
60
|
+
- lib/z3/sort/bool_sort.rb
|
61
|
+
- lib/z3/sort/int_sort.rb
|
62
|
+
- lib/z3/sort/real_sort.rb
|
63
|
+
- lib/z3/sort/sort.rb
|
64
|
+
- lib/z3/value/arith_value.rb
|
65
|
+
- lib/z3/value/bitvec_value.rb
|
66
|
+
- lib/z3/value/bool_value.rb
|
67
|
+
- lib/z3/value/int_value.rb
|
68
|
+
- lib/z3/value/real_value.rb
|
69
|
+
- lib/z3/value/value.rb
|
56
70
|
- lib/z3/very_low_level.rb
|
57
71
|
- lib/z3/very_low_level_auto.rb
|
58
|
-
- spec/ast_spec.rb
|
59
72
|
- spec/integration/algebra_problems_spec.rb
|
60
|
-
- spec/integration/
|
73
|
+
- spec/integration/basic_int_math_spec.rb
|
61
74
|
- spec/integration/basic_logic_spec.rb
|
75
|
+
- spec/integration/bit_tricks_spec.rb
|
62
76
|
- spec/integration/bridges_spec.rb
|
63
77
|
- spec/integration/geometry_problem_spec.rb
|
64
78
|
- spec/integration/kakuro_spec.rb
|
@@ -73,6 +87,7 @@ files:
|
|
73
87
|
- spec/solver_spec.rb
|
74
88
|
- spec/sort_spec.rb
|
75
89
|
- spec/spec_helper.rb
|
90
|
+
- spec/value_spec.rb
|
76
91
|
- spec/z3_spec.rb
|
77
92
|
homepage: https://github.com/taw/z3
|
78
93
|
licenses:
|