z3 0.0.20160221 → 0.0.20160323
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/ast.rb
DELETED
@@ -1,302 +0,0 @@
|
|
1
|
-
class Z3::Ast
|
2
|
-
attr_reader :_ast
|
3
|
-
# Do not use .new directly
|
4
|
-
def initialize(_ast)
|
5
|
-
@_ast = _ast
|
6
|
-
end
|
7
|
-
|
8
|
-
def sort
|
9
|
-
Z3::Sort.new(Z3::LowLevel.get_sort(self))
|
10
|
-
end
|
11
|
-
|
12
|
-
def to_s
|
13
|
-
Z3::LowLevel.ast_to_string(self)
|
14
|
-
end
|
15
|
-
|
16
|
-
def inspect
|
17
|
-
"Z3::Ast<#{to_s} :: #{sort.to_s}>"
|
18
|
-
end
|
19
|
-
|
20
|
-
def ~
|
21
|
-
raise Z3::Exception, "Can only be used on booleans" unless bool?
|
22
|
-
Z3::Ast.not(self)
|
23
|
-
end
|
24
|
-
|
25
|
-
def int?
|
26
|
-
sort == Z3::Sort.int
|
27
|
-
end
|
28
|
-
|
29
|
-
def bool?
|
30
|
-
sort == Z3::Sort.bool
|
31
|
-
end
|
32
|
-
|
33
|
-
def real?
|
34
|
-
sort == Z3::Sort.real
|
35
|
-
end
|
36
|
-
|
37
|
-
private def binary_arithmetic_operator(op, b)
|
38
|
-
b = Z3::Ast.from_const(b, sort) unless b.is_a?(Z3::Ast)
|
39
|
-
raise Z3::Exception, "Can't be used on booleans" if bool? or b.bool?
|
40
|
-
if sort == b.sort
|
41
|
-
a = self
|
42
|
-
else
|
43
|
-
a, b = Z3::Ast.coerce_to_same_sort(self, b)
|
44
|
-
end
|
45
|
-
Z3::Ast.send(op, a, b)
|
46
|
-
end
|
47
|
-
|
48
|
-
private def binary_int_operator(op, b)
|
49
|
-
b = Z3::Ast.from_const(b, sort) unless b.is_a?(Z3::Ast)
|
50
|
-
raise Z3::Exception, "Can only be used on integers" unless int? and b.int?
|
51
|
-
Z3::Ast.send(op, self, b)
|
52
|
-
end
|
53
|
-
|
54
|
-
def |(b)
|
55
|
-
b = Z3::Ast.from_const(b, sort) unless b.is_a?(Z3::Ast)
|
56
|
-
raise Z3::Exception, "Can only be used on booleans" unless bool? and b.bool?
|
57
|
-
Z3::Ast.or(self, b)
|
58
|
-
end
|
59
|
-
|
60
|
-
def &(b)
|
61
|
-
b = Z3::Ast.from_const(b, sort) unless b.is_a?(Z3::Ast)
|
62
|
-
raise Z3::Exception, "Can only be used on booleans" unless bool? and b.bool?
|
63
|
-
Z3::Ast.and(self, b)
|
64
|
-
end
|
65
|
-
|
66
|
-
def +(b)
|
67
|
-
binary_arithmetic_operator(:add, b)
|
68
|
-
end
|
69
|
-
|
70
|
-
def *(b)
|
71
|
-
binary_arithmetic_operator(:mul, b)
|
72
|
-
end
|
73
|
-
|
74
|
-
def -(b)
|
75
|
-
binary_arithmetic_operator(:sub, b)
|
76
|
-
end
|
77
|
-
|
78
|
-
def >=(b)
|
79
|
-
binary_arithmetic_operator(:ge, b)
|
80
|
-
end
|
81
|
-
|
82
|
-
def >(b)
|
83
|
-
binary_arithmetic_operator(:gt, b)
|
84
|
-
end
|
85
|
-
|
86
|
-
def <=(b)
|
87
|
-
binary_arithmetic_operator(:le, b)
|
88
|
-
end
|
89
|
-
|
90
|
-
def <(b)
|
91
|
-
binary_arithmetic_operator(:lt, b)
|
92
|
-
end
|
93
|
-
|
94
|
-
def **(b)
|
95
|
-
binary_arithmetic_operator(:power, b)
|
96
|
-
end
|
97
|
-
|
98
|
-
def /(b)
|
99
|
-
binary_arithmetic_operator(:div, b)
|
100
|
-
end
|
101
|
-
|
102
|
-
def %(b)
|
103
|
-
binary_int_operator(:mod, b)
|
104
|
-
end
|
105
|
-
|
106
|
-
def rem(b)
|
107
|
-
binary_int_operator(:rem, b)
|
108
|
-
end
|
109
|
-
|
110
|
-
def -@
|
111
|
-
raise "Can only apply unary negation to Int or Real" unless int? or real?
|
112
|
-
Z3::Ast.new(Z3::LowLevel.mk_unary_minus(self))
|
113
|
-
end
|
114
|
-
|
115
|
-
def ==(b)
|
116
|
-
b = Z3::Ast.from_const(b, sort) unless b.is_a?(Z3::Ast)
|
117
|
-
if sort != b.sort
|
118
|
-
a, b = Z3::Ast.coerce_to_same_sort(self, b)
|
119
|
-
else
|
120
|
-
a = self
|
121
|
-
end
|
122
|
-
Z3::Ast.eq(self, b)
|
123
|
-
end
|
124
|
-
|
125
|
-
def !=(b)
|
126
|
-
b = Z3::Ast.from_const(b, sort) unless b.is_a?(Z3::Ast)
|
127
|
-
if sort != b.sort
|
128
|
-
a, b = Z3::Ast.coerce_to_same_sort(self, b)
|
129
|
-
else
|
130
|
-
a = self
|
131
|
-
end
|
132
|
-
Z3::Ast.distinct(a, b)
|
133
|
-
end
|
134
|
-
|
135
|
-
def coerce(other)
|
136
|
-
[Z3::Ast.from_const(other, sort), self]
|
137
|
-
end
|
138
|
-
|
139
|
-
def int_to_real
|
140
|
-
raise Z3::Exception, "Type mismatch" unless int?
|
141
|
-
Z3::Ast.new(Z3::LowLevel.mk_int2real(self))
|
142
|
-
end
|
143
|
-
|
144
|
-
class <<self
|
145
|
-
def from_const(value, sort)
|
146
|
-
case sort
|
147
|
-
when Z3::Sort.bool
|
148
|
-
raise Z3::Exception, "Can't convert #{value.class} to Bool" unless value == true or value == false
|
149
|
-
if value
|
150
|
-
Z3::Ast.true
|
151
|
-
else
|
152
|
-
Z3::Ast.false
|
153
|
-
end
|
154
|
-
when Z3::Sort.int
|
155
|
-
# (int_var == 2.4) gets changed to
|
156
|
-
# ((int_to_real int_var) == (mknumeral 2.4))
|
157
|
-
raise Z3::Exception, "Can't convert #{value.class} to Real" unless value.is_a?(Numeric)
|
158
|
-
if value.is_a?(Float)
|
159
|
-
Z3::Ast.new(Z3::LowLevel.mk_numeral(value.to_s, Z3::Sort.real))
|
160
|
-
else
|
161
|
-
Z3::Ast.new(Z3::LowLevel.mk_numeral(value.to_s, sort))
|
162
|
-
end
|
163
|
-
when Z3::Sort.real
|
164
|
-
raise Z3::Exception, "Can't convert #{value.class} to Real" unless value.is_a?(Numeric)
|
165
|
-
Z3::Ast.new(Z3::LowLevel.mk_numeral(value.to_s, sort))
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
def coerce_bool(value)
|
170
|
-
if value.is_a?(Z3::Ast)
|
171
|
-
return value if value.bool?
|
172
|
-
raise Z3::Exception, "Can't convert #{value.sort} to Bool"
|
173
|
-
end
|
174
|
-
raise Z3::Exception, "Can't convert #{value.class} to Bool" unless value == true or value == false
|
175
|
-
if value
|
176
|
-
Z3::Ast.true
|
177
|
-
else
|
178
|
-
Z3::Ast.false
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
def coerce_to_same_sort(a, b)
|
183
|
-
if a.sort == Z3::Sort.int and b.sort == Z3::Sort.real
|
184
|
-
[a.int_to_real, b]
|
185
|
-
elsif b.sort == Z3::Sort.int and a.sort == Z3::Sort.real
|
186
|
-
[a, b.int_to_real]
|
187
|
-
else
|
188
|
-
raise Z3::Exception, "No rules how to coerce #{a.sort} and #{b.sort}"
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
def true
|
193
|
-
Z3::Ast.new(Z3::LowLevel.mk_true)
|
194
|
-
end
|
195
|
-
|
196
|
-
def false
|
197
|
-
Z3::Ast.new(Z3::LowLevel.mk_false)
|
198
|
-
end
|
199
|
-
|
200
|
-
def eq(a, b)
|
201
|
-
Z3::Ast.new(Z3::LowLevel.mk_eq(a, b))
|
202
|
-
end
|
203
|
-
|
204
|
-
def ge(a, b)
|
205
|
-
Z3::Ast.new(Z3::LowLevel.mk_ge(a, b))
|
206
|
-
end
|
207
|
-
|
208
|
-
def gt(a, b)
|
209
|
-
Z3::Ast.new(Z3::LowLevel.mk_gt(a, b))
|
210
|
-
end
|
211
|
-
|
212
|
-
def le(a, b)
|
213
|
-
Z3::Ast.new(Z3::LowLevel.mk_le(a, b))
|
214
|
-
end
|
215
|
-
|
216
|
-
def lt(a, b)
|
217
|
-
Z3::Ast.new(Z3::LowLevel.mk_lt(a, b))
|
218
|
-
end
|
219
|
-
|
220
|
-
def power(a, b)
|
221
|
-
Z3::Ast.new(Z3::LowLevel.mk_power(a, b))
|
222
|
-
end
|
223
|
-
|
224
|
-
def div(a, b)
|
225
|
-
Z3::Ast.new(Z3::LowLevel.mk_div(a, b))
|
226
|
-
end
|
227
|
-
|
228
|
-
def mod(a, b)
|
229
|
-
Z3::Ast.new(Z3::LowLevel.mk_mod(a, b))
|
230
|
-
end
|
231
|
-
|
232
|
-
def rem(a, b)
|
233
|
-
Z3::Ast.new(Z3::LowLevel.mk_rem(a, b))
|
234
|
-
end
|
235
|
-
|
236
|
-
def not(a)
|
237
|
-
a = coerce_bool(a)
|
238
|
-
Z3::Ast.new(Z3::LowLevel.mk_not(a))
|
239
|
-
end
|
240
|
-
|
241
|
-
def distinct(*args)
|
242
|
-
Z3::Ast.new(Z3::LowLevel.mk_distinct(args))
|
243
|
-
end
|
244
|
-
|
245
|
-
def and(*args)
|
246
|
-
args = args.map{|a| coerce_bool(a)}
|
247
|
-
Z3::Ast.new(Z3::LowLevel.mk_and(args))
|
248
|
-
end
|
249
|
-
|
250
|
-
def or(*args)
|
251
|
-
args = args.map{|a| coerce_bool(a)}
|
252
|
-
Z3::Ast.new(Z3::LowLevel.mk_or(args))
|
253
|
-
end
|
254
|
-
|
255
|
-
def add(*args)
|
256
|
-
Z3::Ast.new(Z3::LowLevel.mk_add(args))
|
257
|
-
end
|
258
|
-
|
259
|
-
def iff(a, b)
|
260
|
-
a = coerce_bool(a)
|
261
|
-
b = coerce_bool(b)
|
262
|
-
Z3::Ast.new(Z3::LowLevel.mk_iff(a, b))
|
263
|
-
end
|
264
|
-
|
265
|
-
def implies(a, b)
|
266
|
-
a = coerce_bool(a)
|
267
|
-
b = coerce_bool(b)
|
268
|
-
Z3::Ast.new(Z3::LowLevel.mk_implies(a, b))
|
269
|
-
end
|
270
|
-
|
271
|
-
def sub(*args)
|
272
|
-
Z3::Ast.new(Z3::LowLevel.mk_sub(args))
|
273
|
-
end
|
274
|
-
|
275
|
-
def mul(*args)
|
276
|
-
Z3::Ast.new(Z3::LowLevel.mk_mul(args))
|
277
|
-
end
|
278
|
-
|
279
|
-
def bool(name)
|
280
|
-
var(name, Z3::Sort.bool)
|
281
|
-
end
|
282
|
-
|
283
|
-
def int(name)
|
284
|
-
var(name, Z3::Sort.int)
|
285
|
-
end
|
286
|
-
|
287
|
-
def real(name)
|
288
|
-
var(name, Z3::Sort.real)
|
289
|
-
end
|
290
|
-
|
291
|
-
private
|
292
|
-
|
293
|
-
def var(name, sort)
|
294
|
-
Z3::Ast.new(
|
295
|
-
Z3::LowLevel.mk_const(
|
296
|
-
Z3::LowLevel.mk_string_symbol(name),
|
297
|
-
sort,
|
298
|
-
)
|
299
|
-
)
|
300
|
-
end
|
301
|
-
end
|
302
|
-
end
|
data/lib/z3/sort.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
class Z3::Sort
|
2
|
-
attr_reader :_sort
|
3
|
-
# Do not use .new directly
|
4
|
-
def initialize(_sort)
|
5
|
-
@_sort = _sort
|
6
|
-
end
|
7
|
-
|
8
|
-
def ==(other)
|
9
|
-
other.is_a?(Z3::Sort) and @_sort == other._sort
|
10
|
-
end
|
11
|
-
|
12
|
-
def to_s
|
13
|
-
Z3::LowLevel.sort_to_string(self)
|
14
|
-
end
|
15
|
-
|
16
|
-
def inspect
|
17
|
-
"Z3::Sort<#{to_s}>"
|
18
|
-
end
|
19
|
-
|
20
|
-
class << self
|
21
|
-
def bool
|
22
|
-
Z3::Sort.new(Z3::LowLevel.mk_bool_sort)
|
23
|
-
end
|
24
|
-
|
25
|
-
def int
|
26
|
-
Z3::Sort.new(Z3::LowLevel.mk_int_sort)
|
27
|
-
end
|
28
|
-
|
29
|
-
def real
|
30
|
-
Z3::Sort.new(Z3::LowLevel.mk_real_sort)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
File without changes
|