z3 0.0.0 → 0.0.20160221
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/bridges_solver +132 -0
- data/examples/kakuro_solver +124 -0
- data/examples/letter_connections_solver +199 -0
- data/lib/z3/ast.rb +1 -1
- data/lib/z3/low_level.rb +2 -183
- data/lib/z3/low_level_auto.rb +2063 -0
- data/lib/z3/very_low_level.rb +32 -64
- data/lib/z3/very_low_level_auto.rb +516 -0
- data/spec/integration/bridges_spec.rb +28 -0
- data/spec/integration/geometry_problem_spec.rb +1 -1
- data/spec/integration/kakuro_spec.rb +17 -0
- data/spec/integration/letter_connections_spec.rb +17 -0
- data/spec/integration/selfref_spec.rb +1 -1
- metadata +25 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73f23f4e1511fe002de7b2e1d3d91945bc6f8be6
|
4
|
+
data.tar.gz: e6662d712ccaedd2b76a9c560dac242228d51311
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 206d8cb1e08173e3013da2426359a922c72631c28e84957ac8b94ce1219e5295960436fbd78513eb128cd0eb1b396bdf4f534247b183848ecb92df4d16d9e452
|
7
|
+
data.tar.gz: 04f74e3844e9e017bb6636cd26b96fd0cc79e05e59a86650c66fe18b271a3bc9798ee8481fb9979ec134cb298354f03c2b097b14f9c531166bf0f0ac87ea0ce6
|
@@ -0,0 +1,132 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative "../lib/z3"
|
4
|
+
|
5
|
+
class Bridges
|
6
|
+
def initialize(data)
|
7
|
+
data = data.strip.split("\n").map do |line|
|
8
|
+
line.split.map{|c| c == "_" ? nil : c.to_i}
|
9
|
+
end
|
10
|
+
@xsize = data[0].size
|
11
|
+
@ysize = data.size
|
12
|
+
@data = map_coordinates{|x,y| data[y][x]}
|
13
|
+
@solver = Z3::Solver.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def solve!
|
17
|
+
@vars = {}
|
18
|
+
(0...@xsize).each do |x|
|
19
|
+
(0...@ysize).each do |y|
|
20
|
+
u = int012(x,y,"u")
|
21
|
+
d = int012(x,y,"d")
|
22
|
+
r = int012(x,y,"r")
|
23
|
+
l = int012(x,y,"l")
|
24
|
+
@vars[[x,y,"u"]] = u
|
25
|
+
@vars[[x,y,"d"]] = d
|
26
|
+
@vars[[x,y,"r"]] = r
|
27
|
+
@vars[[x,y,"l"]] = l
|
28
|
+
if @data[[x,y]] == nil
|
29
|
+
@solver.assert u == d
|
30
|
+
@solver.assert l == r
|
31
|
+
@solver.assert (u==0) | (l==0)
|
32
|
+
else
|
33
|
+
@solver.assert u+d+r+l == @data[[x,y]]
|
34
|
+
end
|
35
|
+
# Nothing goes out of the map
|
36
|
+
if x == 0
|
37
|
+
@solver.assert l == 0
|
38
|
+
end
|
39
|
+
if x == @xsize - 1
|
40
|
+
@solver.assert r == 0
|
41
|
+
end
|
42
|
+
if y == 0
|
43
|
+
@solver.assert u == 0
|
44
|
+
end
|
45
|
+
if y == @ysize - 1
|
46
|
+
@solver.assert d == 0
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
(0...@xsize).each do |x|
|
52
|
+
(0...@ysize).each do |y|
|
53
|
+
if x != @xsize-1
|
54
|
+
@solver.assert @vars[[x,y,"r"]] == @vars[[x+1,y,"l"]]
|
55
|
+
end
|
56
|
+
if y != @ysize-1
|
57
|
+
@solver.assert @vars[[x,y,"d"]] == @vars[[x,y+1,"u"]]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
if @solver.check == :sat
|
63
|
+
@model = @solver.model
|
64
|
+
print_answer!
|
65
|
+
else
|
66
|
+
puts "failed to solve"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def map_coordinates
|
73
|
+
Hash[(0...@xsize).to_a.product((0...@ysize).to_a).map{|x,y| [[x,y],yield(x,y)]}]
|
74
|
+
end
|
75
|
+
|
76
|
+
def print_answer!
|
77
|
+
picture = (0...@ysize*3).map do
|
78
|
+
[" "] * (3*@xsize)
|
79
|
+
end
|
80
|
+
|
81
|
+
@data.each do |(x,y),v|
|
82
|
+
if v == nil
|
83
|
+
u = @model[@vars[[x,y,"u"]]].to_s.to_i
|
84
|
+
l = @model[@vars[[x,y,"l"]]].to_s.to_i
|
85
|
+
if u > 0
|
86
|
+
picture[y*3+1][x*3+1] = " |\u2016"[u]
|
87
|
+
elsif l > 0
|
88
|
+
picture[y*3+1][x*3+1] = " -="[l]
|
89
|
+
else
|
90
|
+
picture[y*3+1][x*3+1] = " "
|
91
|
+
end
|
92
|
+
else
|
93
|
+
picture[y*3+1][x*3+1] = v.to_s
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
@data.each do |(x,y),_|
|
98
|
+
u = @model[@vars[[x,y,"u"]]].to_s.to_i
|
99
|
+
d = @model[@vars[[x,y,"d"]]].to_s.to_i
|
100
|
+
l = @model[@vars[[x,y,"l"]]].to_s.to_i
|
101
|
+
r = @model[@vars[[x,y,"r"]]].to_s.to_i
|
102
|
+
|
103
|
+
picture[y*3+1][x*3 ] = " -="[l]
|
104
|
+
picture[y*3+1][x*3+2] = " -="[r]
|
105
|
+
picture[y*3 ][x*3+1] = " |\u2016"[u]
|
106
|
+
picture[y*3+2][x*3+1] = " |\u2016"[d]
|
107
|
+
end
|
108
|
+
|
109
|
+
picture.each do |row|
|
110
|
+
puts row.join
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def int012(x, y, d)
|
115
|
+
v = Z3::Ast.int("#{x},#{y},#{d}")
|
116
|
+
@solver.assert v >= 0
|
117
|
+
@solver.assert v <= 2
|
118
|
+
v
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
Bridges.new(
|
123
|
+
"""
|
124
|
+
3 _ _ 6 _ _ 4
|
125
|
+
_ 1 _ _ _ _ _
|
126
|
+
_ _ _ 4 _ 4 _
|
127
|
+
_ _ _ _ _ _ _
|
128
|
+
_ _ 1 _ 3 _ _
|
129
|
+
1 _ _ _ _ 2 _
|
130
|
+
_ 3 _ _ 5 _ 3
|
131
|
+
"""
|
132
|
+
).solve!
|
@@ -0,0 +1,124 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
class Hash
|
4
|
+
def compact
|
5
|
+
ht = {}
|
6
|
+
each do |k,v|
|
7
|
+
ht[k] = v unless v.nil?
|
8
|
+
end
|
9
|
+
ht
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
require_relative "../lib/z3"
|
14
|
+
|
15
|
+
class Kakuro
|
16
|
+
def initialize(data)
|
17
|
+
data = data.strip.split("\n").map do |line|
|
18
|
+
line.split.map{|cell| parse_cell(cell)}
|
19
|
+
end
|
20
|
+
@xsize = data[0].size
|
21
|
+
@ysize = data.size
|
22
|
+
@data = map_coordinates{|x,y| data[y][x]}
|
23
|
+
@solver = Z3::Solver.new
|
24
|
+
end
|
25
|
+
|
26
|
+
def solve!
|
27
|
+
@cells = map_coordinates{|x,y| cell_var(x,y) if @data[[x,y]] == nil}.compact
|
28
|
+
|
29
|
+
(0...@ysize).each do |y|
|
30
|
+
(0...@xsize).each do |x|
|
31
|
+
cell = @data[[x,y]]
|
32
|
+
next if cell == nil
|
33
|
+
(a,b) = cell
|
34
|
+
setup_line!(x,y,0,1,a)
|
35
|
+
setup_line!(x,y,1,0,b)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
if @solver.check() == :sat
|
40
|
+
@model = @solver.model
|
41
|
+
print_board!
|
42
|
+
else
|
43
|
+
puts "failed to solve"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def map_coordinates
|
50
|
+
Hash[(0...@xsize).to_a.product((0...@ysize).to_a).map{|x,y| [[x,y],yield(x,y)]}]
|
51
|
+
end
|
52
|
+
|
53
|
+
def print_board!
|
54
|
+
(0...@ysize).each do |y|
|
55
|
+
(0...@xsize).each do |x|
|
56
|
+
cell = @data[[x,y]]
|
57
|
+
if cell == nil
|
58
|
+
if @model and @cells.has_key?([x,y])
|
59
|
+
a = @model[@cells[[x,y]]].to_s
|
60
|
+
print(" [#{a}] ")
|
61
|
+
else
|
62
|
+
print(" _ ")
|
63
|
+
end
|
64
|
+
elsif cell == [0,0]
|
65
|
+
print(" x ")
|
66
|
+
else
|
67
|
+
(a,b) = cell
|
68
|
+
a = if a == 0 then " " else ("%2d" % a) end
|
69
|
+
b = if b == 0 then " " else ("%-2d" % b) end
|
70
|
+
print("#{a}/#{b}")
|
71
|
+
end
|
72
|
+
print " "
|
73
|
+
end
|
74
|
+
print "\n"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def parse_cell(cell)
|
79
|
+
if cell == "_"
|
80
|
+
nil
|
81
|
+
elsif cell == "x"
|
82
|
+
[0,0]
|
83
|
+
else
|
84
|
+
a,b = cell.split("/")
|
85
|
+
[a.to_i, b.to_i]
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def cell_var(x,y)
|
90
|
+
v = Z3::Ast.int("c#{x},#{y}")
|
91
|
+
@solver.assert v >= 1
|
92
|
+
@solver.assert v <= 9
|
93
|
+
v
|
94
|
+
end
|
95
|
+
|
96
|
+
def setup_line!(x0, y0, dx, dy, sum)
|
97
|
+
return if sum == 0
|
98
|
+
vs = []
|
99
|
+
x, y = x0+dx, y0+dy
|
100
|
+
while @cells.has_key?([x,y])
|
101
|
+
vs << @cells[[x,y]]
|
102
|
+
x += dx
|
103
|
+
y += dy
|
104
|
+
end
|
105
|
+
return if vs.empty?
|
106
|
+
@solver.assert Z3::Ast.distinct(*vs)
|
107
|
+
@solver.assert Z3::Ast.add(*vs) == sum
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
Kakuro.new(
|
112
|
+
"""
|
113
|
+
x x x 10/ 24/ 29/ x 11/ 21/ 10/
|
114
|
+
x 11/ 19/24 _ _ _ /6 _ _ _
|
115
|
+
/31 _ _ _ _ _ 10/20 _ _ _
|
116
|
+
/4 _ _ 22/18 _ _ _ 23/13 _ _
|
117
|
+
/18 _ _ _ 24/26 _ _ _ _ _
|
118
|
+
x 19/ 30/16 _ _ 10/11 _ _ 11/ 20/
|
119
|
+
/34 _ _ _ _ _ 23/23 _ _ _
|
120
|
+
/7 _ _ 9/16 _ _ _ 3/4 _ _
|
121
|
+
/24 _ _ _ /23 _ _ _ _ _
|
122
|
+
/10 _ _ _ /11 _ _ _ x x
|
123
|
+
"""
|
124
|
+
).solve!
|
@@ -0,0 +1,199 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# NOTE: This solver can fill empty spaces with phantom loops,
|
4
|
+
# so it's not technically totally legit true
|
5
|
+
# As in:
|
6
|
+
# A..
|
7
|
+
# A..
|
8
|
+
#
|
9
|
+
# Into:
|
10
|
+
# A* A→ A↓
|
11
|
+
# A↑ A↑ A←
|
12
|
+
#
|
13
|
+
# Instead of more correct:
|
14
|
+
#
|
15
|
+
# A* A← A←
|
16
|
+
# A→ A→ A↑
|
17
|
+
#
|
18
|
+
# This affects few enough real world puzzles and would complicate solution enough
|
19
|
+
# that I let it be.
|
20
|
+
require_relative "../lib/z3"
|
21
|
+
|
22
|
+
class LetterConnections
|
23
|
+
def initialize(data)
|
24
|
+
data = data.strip.split("\n")
|
25
|
+
@xsize = data[0].size
|
26
|
+
@ysize = data.size
|
27
|
+
@letters = {}
|
28
|
+
@rletters = {}
|
29
|
+
@starts = {}
|
30
|
+
@ends = {}
|
31
|
+
@special_ends = {}
|
32
|
+
@special_starts = {}
|
33
|
+
|
34
|
+
data = map_coordinates{|x,y| data[y][x]}
|
35
|
+
|
36
|
+
data.sort.each do |(x,y), letter|
|
37
|
+
next if letter == "."
|
38
|
+
if @letters.has_key?(letter)
|
39
|
+
if @ends.has_key?(letter)
|
40
|
+
raise "Letter #{letter} occurs more than twice"
|
41
|
+
end
|
42
|
+
@ends[letter] = [x,y]
|
43
|
+
@special_ends[[x,y]] = letter
|
44
|
+
else
|
45
|
+
i = @letters.size
|
46
|
+
@letters[letter] = i
|
47
|
+
@rletters[i] = letter
|
48
|
+
@starts[letter] = [x,y]
|
49
|
+
@special_starts[[x,y]] = letter
|
50
|
+
end
|
51
|
+
end
|
52
|
+
@letters.each_key do |letter|
|
53
|
+
unless @ends.has_key?(letter)
|
54
|
+
raise "Letter #{letter} occurs only once"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
@solver = Z3::Solver.new
|
59
|
+
end
|
60
|
+
|
61
|
+
def solve!
|
62
|
+
@line = map_coordinates{|x,y| line_var(x,y) }
|
63
|
+
@dir = map_coordinates{|x,y| dir_var(x,y) }
|
64
|
+
|
65
|
+
@letters.each do |letter, i|
|
66
|
+
@solver.assert @line[@starts[letter]] == i
|
67
|
+
@solver.assert @line[@ends[letter]] == i
|
68
|
+
end
|
69
|
+
|
70
|
+
(0...@ysize).each do |y|
|
71
|
+
(0...@xsize).each do |x|
|
72
|
+
next if @special_ends.has_key?([x,y])
|
73
|
+
# Direction Left
|
74
|
+
if x == 0
|
75
|
+
@solver.assert @dir[[x,y]] != 0
|
76
|
+
else
|
77
|
+
@solver.assert Z3::Ast.implies(@dir[[x,y]] == 0, @line[[x,y]] == @line[[x-1,y]])
|
78
|
+
@solver.assert Z3::Ast.implies(@dir[[x,y]] == 0, @dir[[x-1,y]] != 2)
|
79
|
+
end
|
80
|
+
# Direction Up
|
81
|
+
if y == 0
|
82
|
+
@solver.assert @dir[[x,y]] != 1
|
83
|
+
else
|
84
|
+
@solver.assert Z3::Ast.implies(@dir[[x,y]] == 1, @line[[x,y]] == @line[[x,y-1]])
|
85
|
+
@solver.assert Z3::Ast.implies(@dir[[x,y]] == 1, @dir[[x,y-1]] != 3)
|
86
|
+
end
|
87
|
+
# Direction Right
|
88
|
+
if x == @xsize - 1
|
89
|
+
@solver.assert @dir[[x,y]] != 2
|
90
|
+
else
|
91
|
+
@solver.assert Z3::Ast.implies(@dir[[x,y]] == 2, @line[[x,y]] == @line[[x+1,y]])
|
92
|
+
@solver.assert Z3::Ast.implies(@dir[[x,y]] == 2, @dir[[x+1,y]] != 0)
|
93
|
+
end
|
94
|
+
# Direction Down
|
95
|
+
if y == @ysize - 1
|
96
|
+
@solver.assert @dir[[x,y]] != 3
|
97
|
+
else
|
98
|
+
@solver.assert Z3::Ast.implies(@dir[[x,y]] == 3, @line[[x,y]] == @line[[x,y+1]])
|
99
|
+
@solver.assert Z3::Ast.implies(@dir[[x,y]] == 3, @dir[[x,y+1]] != 1)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
# Everything except start node has one incoming arrow
|
105
|
+
# End nodes not counted for this
|
106
|
+
|
107
|
+
(0...@ysize).each do |y|
|
108
|
+
(0...@xsize).each do |x|
|
109
|
+
next if @special_starts.has_key?([x,y])
|
110
|
+
potential_incoming = potential_incoming(x,y)
|
111
|
+
condition_exactly_one(
|
112
|
+
potential_incoming.map{|i,j,d| @dir[[i,j]] == d}
|
113
|
+
)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
if @solver.check == :sat
|
117
|
+
@model = @solver.model
|
118
|
+
print_answer!
|
119
|
+
else
|
120
|
+
puts "failed to solve"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
private
|
125
|
+
|
126
|
+
def map_coordinates
|
127
|
+
Hash[(0...@xsize).to_a.product((0...@ysize).to_a).map{|x,y| [[x,y],yield(x,y)]}]
|
128
|
+
end
|
129
|
+
|
130
|
+
def line_var(x, y)
|
131
|
+
v = Z3::Ast.int("l#{x},#{y}")
|
132
|
+
@solver.assert v >= 0
|
133
|
+
@solver.assert v < @letters.size
|
134
|
+
v
|
135
|
+
end
|
136
|
+
|
137
|
+
def dir_var(x, y)
|
138
|
+
v = Z3::Ast.int("d#{x},#{y}")
|
139
|
+
@solver.assert v >= 0
|
140
|
+
@solver.assert v <= 3
|
141
|
+
v
|
142
|
+
end
|
143
|
+
|
144
|
+
def potential_incoming(x0, y0)
|
145
|
+
[
|
146
|
+
[x0+1,y0,0],
|
147
|
+
[x0-1,y0,2],
|
148
|
+
[x0,y0+1,1],
|
149
|
+
[x0,y0-1,3],
|
150
|
+
].select do |x,y,d|
|
151
|
+
@dir.has_key?([x,y]) and not @special_ends.has_key?([x,y])
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
# Surely Z3 must have a thing for it
|
156
|
+
def condition_exactly_one(conds)
|
157
|
+
@solver.assert Z3::Ast.or(*conds)
|
158
|
+
(0...conds.size).each do |ci|
|
159
|
+
(0...conds.size).each do |cj|
|
160
|
+
if ci < cj
|
161
|
+
@solver.assert ~conds[ci] | ~conds[cj]
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def print_answer!
|
168
|
+
(0...@ysize).each do |y|
|
169
|
+
(0...@xsize).each do |x|
|
170
|
+
li = @model[@line[[x,y]]].to_s.to_i
|
171
|
+
l = @rletters[li]
|
172
|
+
d = @model[@dir[[x,y]]].to_s.to_i
|
173
|
+
if [x,y] == @starts[l]
|
174
|
+
print("\u2190\u2191\u2192\u2193"[d]+l+" ")
|
175
|
+
elsif [x,y] == @ends[l]
|
176
|
+
print("*"+l+" ")
|
177
|
+
else
|
178
|
+
print("\u2190\u2191\u2192\u2193"[d]+l.downcase+" ")
|
179
|
+
end
|
180
|
+
end
|
181
|
+
puts ""
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
LetterConnections.new(
|
187
|
+
"""
|
188
|
+
..KJ....FE
|
189
|
+
.FJ.......
|
190
|
+
......G...
|
191
|
+
.K.I......
|
192
|
+
.......D..
|
193
|
+
IE......B.
|
194
|
+
...H...CD.
|
195
|
+
...A..C...
|
196
|
+
.A.H......
|
197
|
+
...B.G....
|
198
|
+
"""
|
199
|
+
).solve!
|
data/lib/z3/ast.rb
CHANGED
@@ -48,7 +48,7 @@ class Z3::Ast
|
|
48
48
|
private def binary_int_operator(op, b)
|
49
49
|
b = Z3::Ast.from_const(b, sort) unless b.is_a?(Z3::Ast)
|
50
50
|
raise Z3::Exception, "Can only be used on integers" unless int? and b.int?
|
51
|
-
Z3::Ast.send(op,
|
51
|
+
Z3::Ast.send(op, self, b)
|
52
52
|
end
|
53
53
|
|
54
54
|
def |(b)
|
data/lib/z3/low_level.rb
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
|
4
4
|
module Z3::LowLevel
|
5
5
|
class << self
|
6
|
-
# Common API
|
7
6
|
def get_version
|
8
7
|
a = FFI::MemoryPointer.new(:int)
|
9
8
|
b = FFI::MemoryPointer.new(:int)
|
@@ -17,87 +16,10 @@ module Z3::LowLevel
|
|
17
16
|
Z3::VeryLowLevel.Z3_set_error_handler(_ctx_pointer, block)
|
18
17
|
end
|
19
18
|
|
20
|
-
def global_param_set(k,v)
|
21
|
-
Z3::VeryLowLevel.Z3_global_param_set(k.to_s, v.to_s)
|
22
|
-
end
|
23
|
-
|
24
|
-
# Context API
|
25
19
|
def mk_context
|
26
20
|
Z3::VeryLowLevel.Z3_mk_context
|
27
21
|
end
|
28
22
|
|
29
|
-
# Symbol API
|
30
|
-
def mk_string_symbol(name)
|
31
|
-
Z3::VeryLowLevel.Z3_mk_string_symbol(_ctx_pointer, name)
|
32
|
-
end
|
33
|
-
|
34
|
-
def get_symbol_string(symbol)
|
35
|
-
Z3::VeryLowLevel.Z3_get_symbol_string(_ctx_pointer, symbol)
|
36
|
-
end
|
37
|
-
|
38
|
-
# Sort API
|
39
|
-
def mk_bool_sort
|
40
|
-
Z3::VeryLowLevel.Z3_mk_bool_sort(_ctx_pointer)
|
41
|
-
end
|
42
|
-
|
43
|
-
def mk_int_sort
|
44
|
-
Z3::VeryLowLevel.Z3_mk_int_sort(_ctx_pointer)
|
45
|
-
end
|
46
|
-
|
47
|
-
def mk_real_sort
|
48
|
-
Z3::VeryLowLevel.Z3_mk_real_sort(_ctx_pointer)
|
49
|
-
end
|
50
|
-
|
51
|
-
def sort_to_string(sort)
|
52
|
-
Z3::VeryLowLevel.Z3_sort_to_string(_ctx_pointer, sort._sort)
|
53
|
-
end
|
54
|
-
|
55
|
-
# Solver API
|
56
|
-
def mk_solver
|
57
|
-
Z3::VeryLowLevel.Z3_mk_solver(_ctx_pointer)
|
58
|
-
end
|
59
|
-
|
60
|
-
def solver_push(solver)
|
61
|
-
Z3::VeryLowLevel.Z3_solver_push(_ctx_pointer, solver._solver)
|
62
|
-
end
|
63
|
-
|
64
|
-
def solver_pop(solver, n)
|
65
|
-
Z3::VeryLowLevel.Z3_solver_pop(_ctx_pointer, solver._solver, n)
|
66
|
-
end
|
67
|
-
|
68
|
-
def solver_reset(solver)
|
69
|
-
Z3::VeryLowLevel.Z3_solver_reset(_ctx_pointer, solver._solver)
|
70
|
-
end
|
71
|
-
|
72
|
-
def solver_assert(solver, ast)
|
73
|
-
Z3::VeryLowLevel.Z3_solver_assert(_ctx_pointer, solver._solver, ast._ast)
|
74
|
-
end
|
75
|
-
|
76
|
-
def solver_check(solver)
|
77
|
-
Z3::VeryLowLevel.Z3_solver_check(_ctx_pointer, solver._solver)
|
78
|
-
end
|
79
|
-
|
80
|
-
def solver_inc_ref(solver)
|
81
|
-
Z3::VeryLowLevel.Z3_solver_inc_ref(_ctx_pointer, solver._solver)
|
82
|
-
end
|
83
|
-
|
84
|
-
# Model API
|
85
|
-
def solver_get_model(solver)
|
86
|
-
Z3::VeryLowLevel.Z3_solver_get_model(_ctx_pointer, solver._solver)
|
87
|
-
end
|
88
|
-
|
89
|
-
def model_get_num_consts(model)
|
90
|
-
Z3::VeryLowLevel.Z3_model_get_num_consts(_ctx_pointer, model._model)
|
91
|
-
end
|
92
|
-
|
93
|
-
def model_get_num_funcs(model)
|
94
|
-
Z3::VeryLowLevel.Z3_model_get_num_funcs(_ctx_pointer, model._model)
|
95
|
-
end
|
96
|
-
|
97
|
-
def model_get_num_sorts(model)
|
98
|
-
Z3::VeryLowLevel.Z3_model_get_num_sorts(_ctx_pointer, model._model)
|
99
|
-
end
|
100
|
-
|
101
23
|
def model_eval(model, ast, model_completion)
|
102
24
|
rv_ptr = FFI::MemoryPointer.new(:pointer)
|
103
25
|
result = Z3::VeryLowLevel.Z3_model_eval(_ctx_pointer, model._model, ast._ast, !!model_completion, rv_ptr)
|
@@ -108,84 +30,6 @@ module Z3::LowLevel
|
|
108
30
|
end
|
109
31
|
end
|
110
32
|
|
111
|
-
def model_get_const_decl(model, i)
|
112
|
-
Z3::VeryLowLevel.Z3_model_get_const_decl(_ctx_pointer, model._model, i)
|
113
|
-
end
|
114
|
-
|
115
|
-
# FuncDecl API
|
116
|
-
def func_decl_to_ast(func_decl)
|
117
|
-
Z3::VeryLowLevel.Z3_func_decl_to_ast(_ctx_pointer, func_decl._func_decl)
|
118
|
-
end
|
119
|
-
|
120
|
-
def get_decl_name(func_decl)
|
121
|
-
Z3::VeryLowLevel.Z3_get_decl_name(_ctx_pointer, func_decl._func_decl)
|
122
|
-
end
|
123
|
-
|
124
|
-
def get_arity(func_decl)
|
125
|
-
Z3::VeryLowLevel.Z3_get_arity(_ctx_pointer, func_decl._func_decl)
|
126
|
-
end
|
127
|
-
|
128
|
-
def get_decl_ast_parameter(func_decl, i)
|
129
|
-
Z3::VeryLowLevel.Z3_get_decl_ast_parameter(_ctx_pointer, func_decl._func_decl, i)
|
130
|
-
end
|
131
|
-
|
132
|
-
def model_get_const_interp(model, func_decl)
|
133
|
-
Z3::VeryLowLevel.Z3_model_get_const_interp(_ctx_pointer, model._model, func_decl._func_decl)
|
134
|
-
end
|
135
|
-
|
136
|
-
# AST API
|
137
|
-
def mk_true
|
138
|
-
Z3::VeryLowLevel.Z3_mk_true(_ctx_pointer)
|
139
|
-
end
|
140
|
-
|
141
|
-
def mk_false
|
142
|
-
Z3::VeryLowLevel.Z3_mk_false(_ctx_pointer)
|
143
|
-
end
|
144
|
-
|
145
|
-
def mk_eq(a,b)
|
146
|
-
Z3::VeryLowLevel.Z3_mk_eq(_ctx_pointer, a._ast, b._ast)
|
147
|
-
end
|
148
|
-
|
149
|
-
def mk_ge(a,b)
|
150
|
-
Z3::VeryLowLevel.Z3_mk_ge(_ctx_pointer, a._ast, b._ast)
|
151
|
-
end
|
152
|
-
|
153
|
-
def mk_gt(a,b)
|
154
|
-
Z3::VeryLowLevel.Z3_mk_gt(_ctx_pointer, a._ast, b._ast)
|
155
|
-
end
|
156
|
-
|
157
|
-
def mk_le(a,b)
|
158
|
-
Z3::VeryLowLevel.Z3_mk_le(_ctx_pointer, a._ast, b._ast)
|
159
|
-
end
|
160
|
-
|
161
|
-
def mk_lt(a,b)
|
162
|
-
Z3::VeryLowLevel.Z3_mk_lt(_ctx_pointer, a._ast, b._ast)
|
163
|
-
end
|
164
|
-
|
165
|
-
def mk_power(a,b)
|
166
|
-
Z3::VeryLowLevel.Z3_mk_power(_ctx_pointer, a._ast, b._ast)
|
167
|
-
end
|
168
|
-
|
169
|
-
def mk_rem(a,b)
|
170
|
-
Z3::VeryLowLevel.Z3_mk_rem(_ctx_pointer, a._ast, b._ast)
|
171
|
-
end
|
172
|
-
|
173
|
-
def mk_mod(a,b)
|
174
|
-
Z3::VeryLowLevel.Z3_mk_mod(_ctx_pointer, a._ast, b._ast)
|
175
|
-
end
|
176
|
-
|
177
|
-
def mk_div(a,b)
|
178
|
-
Z3::VeryLowLevel.Z3_mk_div(_ctx_pointer, a._ast, b._ast)
|
179
|
-
end
|
180
|
-
|
181
|
-
def mk_not(a)
|
182
|
-
Z3::VeryLowLevel.Z3_mk_not(_ctx_pointer, a._ast)
|
183
|
-
end
|
184
|
-
|
185
|
-
def mk_const(_symbol, sort)
|
186
|
-
Z3::VeryLowLevel.Z3_mk_const(_ctx_pointer, _symbol, sort._sort)
|
187
|
-
end
|
188
|
-
|
189
33
|
def mk_and(asts)
|
190
34
|
Z3::VeryLowLevel.Z3_mk_and(_ctx_pointer, asts.size, asts_vector(asts))
|
191
35
|
end
|
@@ -194,14 +38,6 @@ module Z3::LowLevel
|
|
194
38
|
Z3::VeryLowLevel.Z3_mk_or(_ctx_pointer, asts.size, asts_vector(asts))
|
195
39
|
end
|
196
40
|
|
197
|
-
def mk_iff(asts)
|
198
|
-
Z3::VeryLowLevel.Z3_mk_iff(_ctx_pointer, a._ast, b._ast)
|
199
|
-
end
|
200
|
-
|
201
|
-
def mk_implies(a, b)
|
202
|
-
Z3::VeryLowLevel.Z3_mk_implies(_ctx_pointer, a._ast, b._ast)
|
203
|
-
end
|
204
|
-
|
205
41
|
def mk_mul(asts)
|
206
42
|
Z3::VeryLowLevel.Z3_mk_mul(_ctx_pointer, asts.size, asts_vector(asts))
|
207
43
|
end
|
@@ -218,25 +54,8 @@ module Z3::LowLevel
|
|
218
54
|
Z3::VeryLowLevel.Z3_mk_distinct(_ctx_pointer, asts.size, asts_vector(asts))
|
219
55
|
end
|
220
56
|
|
221
|
-
|
222
|
-
|
223
|
-
end
|
224
|
-
|
225
|
-
def get_sort(ast)
|
226
|
-
Z3::VeryLowLevel.Z3_get_sort(_ctx_pointer, ast._ast)
|
227
|
-
end
|
228
|
-
|
229
|
-
def mk_int2real(ast)
|
230
|
-
Z3::VeryLowLevel.Z3_mk_int2real(_ctx_pointer, ast._ast)
|
231
|
-
end
|
232
|
-
|
233
|
-
def mk_numeral(str, sort)
|
234
|
-
Z3::VeryLowLevel.Z3_mk_numeral(_ctx_pointer, str, sort._sort)
|
235
|
-
end
|
236
|
-
|
237
|
-
def mk_unary_minus(ast)
|
238
|
-
Z3::VeryLowLevel.Z3_mk_unary_minus(_ctx_pointer, ast._ast)
|
239
|
-
end
|
57
|
+
### Automatically generated, do not edit that file
|
58
|
+
eval open("#{__dir__}/low_level_auto.rb").read
|
240
59
|
|
241
60
|
private
|
242
61
|
|