z3 0.0.20180203 → 0.0.20180616
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -5
- data/lib/z3.rb +1 -0
- data/lib/z3/expr/expr.rb +1 -1
- data/lib/z3/expr/float_expr.rb +8 -8
- data/lib/z3/low_level_auto.rb +170 -2
- data/lib/z3/optimize.rb +126 -0
- data/lib/z3/printer.rb +2 -2
- data/lib/z3/sort/real_sort.rb +1 -1
- data/lib/z3/very_low_level_auto.rb +43 -1
- data/spec/float_expr_spec.rb +16 -6
- data/spec/optimize_spec.rb +76 -0
- data/spec/real_expr_spec.rb +2 -0
- data/spec/real_sort_spec.rb +2 -0
- data/spec/spec_helper.rb +4 -15
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1a008f1afd884efa0e1dc6e9964e9f0be381bd77884a2526a07bff5efe64212
|
4
|
+
data.tar.gz: d9379bd2084cb2e5222856da043d58e8ddd399cd86abdce01f0243464e2c6097
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27b7f713bedcbe819207d9d120d081366a274d9f61c952625e7256d3c5f7d177ba6de6d55f31971c06e084fcefa80c52004cd271d7dc7163753daf61e156edcc
|
7
|
+
data.tar.gz: a6f97e4b4916e5189a94bc439bc174342dae679fec6a246ac1a4c6c4245d7355b619cf922515913e41f5d9070b719c0a562ca9682d4d37fcbe6b1d6959c0033b
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
This is Ruby interface for Z3 [ https://github.com/Z3Prover/z3 ].
|
2
2
|
|
3
|
+
Minimum required version is Z3 4.6.
|
4
|
+
|
3
5
|
It's in very early stages of development. Pull requests always welcome.
|
4
6
|
|
5
7
|
### Interface
|
@@ -12,13 +14,16 @@ The interface is potentially unstable, and can change in the future.
|
|
12
14
|
|
13
15
|
`Z3::VeryLowLever` and `Z3::LowLevel` are FFI interface for internal use, and they shouldn't be used directly. Also don't use any method starting with `_`. Doing this is likely to lead to segmentation faults unless extreme care is taken.
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
To use it, you'll need to install `z3`. On OSX that would be:
|
17
|
+
A utility at `api/gen_api` will loop through a .h file and generate Ruby definitions. This will update the API when upstream changes `z3_api.h`
|
18
18
|
|
19
|
-
|
19
|
+
## Building
|
20
20
|
|
21
|
-
|
21
|
+
```
|
22
|
+
brew install z3
|
23
|
+
rake gem:build
|
24
|
+
bundle install
|
25
|
+
rake spec
|
26
|
+
```
|
22
27
|
|
23
28
|
*NB: On Linux, since FFI will look for `libz3.so`, you might need to install `libz3-dev`using your usual package manager.*
|
24
29
|
|
data/lib/z3.rb
CHANGED
@@ -11,6 +11,7 @@ require_relative "z3/low_level_auto"
|
|
11
11
|
require_relative "z3/ast"
|
12
12
|
require_relative "z3/context"
|
13
13
|
require_relative "z3/solver"
|
14
|
+
require_relative "z3/optimize"
|
14
15
|
require_relative "z3/model"
|
15
16
|
require_relative "z3/exception"
|
16
17
|
require_relative "z3/func_decl"
|
data/lib/z3/expr/expr.rb
CHANGED
data/lib/z3/expr/float_expr.rb
CHANGED
@@ -89,8 +89,8 @@ module Z3
|
|
89
89
|
FloatExpr.Min(self, other)
|
90
90
|
end
|
91
91
|
|
92
|
-
def exponent_string
|
93
|
-
LowLevel.fpa_get_numeral_exponent_string(self)
|
92
|
+
def exponent_string(biased)
|
93
|
+
LowLevel.fpa_get_numeral_exponent_string(self, biased)
|
94
94
|
end
|
95
95
|
|
96
96
|
def significand_string
|
@@ -169,12 +169,12 @@ module Z3
|
|
169
169
|
a.sort.new(LowLevel.mk_fpa_rem(a, b))
|
170
170
|
end
|
171
171
|
|
172
|
-
#
|
173
|
-
#
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
172
|
+
# In older versons, this dies when trying to calll Z3_get_ast_kind, min works on same call
|
173
|
+
# Works in 4.6
|
174
|
+
def Max(a, b)
|
175
|
+
a, b = coerce_to_same_float_sort(a, b)
|
176
|
+
a.sort.new(LowLevel.mk_fpa_max(a, b))
|
177
|
+
end
|
178
178
|
|
179
179
|
def Min(a, b)
|
180
180
|
a, b = coerce_to_same_float_sort(a, b)
|
data/lib/z3/low_level_auto.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
module Z3
|
2
2
|
module LowLevel
|
3
3
|
class << self
|
4
|
+
def add_const_interp(model, func_decl, ast) #=> :void
|
5
|
+
VeryLowLevel.Z3_add_const_interp(_ctx_pointer, model._model, func_decl._ast, ast._ast)
|
6
|
+
end
|
7
|
+
|
8
|
+
def add_func_interp(model, func_decl, ast) #=> :func_interp_pointer
|
9
|
+
VeryLowLevel.Z3_add_func_interp(_ctx_pointer, model._model, func_decl._ast, ast._ast)
|
10
|
+
end
|
11
|
+
|
4
12
|
def algebraic_add(ast1, ast2) #=> :ast_pointer
|
5
13
|
VeryLowLevel.Z3_algebraic_add(_ctx_pointer, ast1._ast, ast2._ast)
|
6
14
|
end
|
@@ -213,6 +221,10 @@ module Z3
|
|
213
221
|
VeryLowLevel.Z3_fixedpoint_add_cover(_ctx_pointer, fixedpoint._fixedpoint, num, func_decl._ast, ast._ast)
|
214
222
|
end
|
215
223
|
|
224
|
+
def fixedpoint_add_invariant(fixedpoint, func_decl, ast) #=> :void
|
225
|
+
VeryLowLevel.Z3_fixedpoint_add_invariant(_ctx_pointer, fixedpoint._fixedpoint, func_decl._ast, ast._ast)
|
226
|
+
end
|
227
|
+
|
216
228
|
def fixedpoint_add_rule(fixedpoint, ast, sym) #=> :void
|
217
229
|
VeryLowLevel.Z3_fixedpoint_add_rule(_ctx_pointer, fixedpoint._fixedpoint, ast._ast, sym)
|
218
230
|
end
|
@@ -245,6 +257,10 @@ module Z3
|
|
245
257
|
VeryLowLevel.Z3_fixedpoint_get_cover_delta(_ctx_pointer, fixedpoint._fixedpoint, num, func_decl._ast)
|
246
258
|
end
|
247
259
|
|
260
|
+
def fixedpoint_get_ground_sat_answer(fixedpoint) #=> :ast_pointer
|
261
|
+
VeryLowLevel.Z3_fixedpoint_get_ground_sat_answer(_ctx_pointer, fixedpoint._fixedpoint)
|
262
|
+
end
|
263
|
+
|
248
264
|
def fixedpoint_get_help(fixedpoint) #=> :string
|
249
265
|
VeryLowLevel.Z3_fixedpoint_get_help(_ctx_pointer, fixedpoint._fixedpoint)
|
250
266
|
end
|
@@ -257,14 +273,26 @@ module Z3
|
|
257
273
|
VeryLowLevel.Z3_fixedpoint_get_param_descrs(_ctx_pointer, fixedpoint._fixedpoint)
|
258
274
|
end
|
259
275
|
|
276
|
+
def fixedpoint_get_reachable(fixedpoint, func_decl) #=> :ast_pointer
|
277
|
+
VeryLowLevel.Z3_fixedpoint_get_reachable(_ctx_pointer, fixedpoint._fixedpoint, func_decl._ast)
|
278
|
+
end
|
279
|
+
|
260
280
|
def fixedpoint_get_reason_unknown(fixedpoint) #=> :string
|
261
281
|
VeryLowLevel.Z3_fixedpoint_get_reason_unknown(_ctx_pointer, fixedpoint._fixedpoint)
|
262
282
|
end
|
263
283
|
|
284
|
+
def fixedpoint_get_rule_names_along_trace(fixedpoint) #=> :symbol_pointer
|
285
|
+
VeryLowLevel.Z3_fixedpoint_get_rule_names_along_trace(_ctx_pointer, fixedpoint._fixedpoint)
|
286
|
+
end
|
287
|
+
|
264
288
|
def fixedpoint_get_rules(fixedpoint) #=> :ast_vector_pointer
|
265
289
|
VeryLowLevel.Z3_fixedpoint_get_rules(_ctx_pointer, fixedpoint._fixedpoint)
|
266
290
|
end
|
267
291
|
|
292
|
+
def fixedpoint_get_rules_along_trace(fixedpoint) #=> :ast_vector_pointer
|
293
|
+
VeryLowLevel.Z3_fixedpoint_get_rules_along_trace(_ctx_pointer, fixedpoint._fixedpoint)
|
294
|
+
end
|
295
|
+
|
268
296
|
def fixedpoint_get_statistics(fixedpoint) #=> :stats_pointer
|
269
297
|
VeryLowLevel.Z3_fixedpoint_get_statistics(_ctx_pointer, fixedpoint._fixedpoint)
|
270
298
|
end
|
@@ -285,6 +313,10 @@ module Z3
|
|
285
313
|
VeryLowLevel.Z3_fixedpoint_query(_ctx_pointer, fixedpoint._fixedpoint, ast._ast)
|
286
314
|
end
|
287
315
|
|
316
|
+
def fixedpoint_query_from_lvl(fixedpoint, ast, num) #=> :int
|
317
|
+
VeryLowLevel.Z3_fixedpoint_query_from_lvl(_ctx_pointer, fixedpoint._fixedpoint, ast._ast, num)
|
318
|
+
end
|
319
|
+
|
288
320
|
def fixedpoint_register_relation(fixedpoint, func_decl) #=> :void
|
289
321
|
VeryLowLevel.Z3_fixedpoint_register_relation(_ctx_pointer, fixedpoint._fixedpoint, func_decl._ast)
|
290
322
|
end
|
@@ -301,8 +333,20 @@ module Z3
|
|
301
333
|
VeryLowLevel.Z3_fpa_get_ebits(_ctx_pointer, sort._ast)
|
302
334
|
end
|
303
335
|
|
304
|
-
def
|
305
|
-
VeryLowLevel.
|
336
|
+
def fpa_get_numeral_exponent_bv(ast, bool) #=> :ast_pointer
|
337
|
+
VeryLowLevel.Z3_fpa_get_numeral_exponent_bv(_ctx_pointer, ast._ast, bool)
|
338
|
+
end
|
339
|
+
|
340
|
+
def fpa_get_numeral_exponent_string(ast, bool) #=> :string
|
341
|
+
VeryLowLevel.Z3_fpa_get_numeral_exponent_string(_ctx_pointer, ast._ast, bool)
|
342
|
+
end
|
343
|
+
|
344
|
+
def fpa_get_numeral_sign_bv(ast) #=> :ast_pointer
|
345
|
+
VeryLowLevel.Z3_fpa_get_numeral_sign_bv(_ctx_pointer, ast._ast)
|
346
|
+
end
|
347
|
+
|
348
|
+
def fpa_get_numeral_significand_bv(ast) #=> :ast_pointer
|
349
|
+
VeryLowLevel.Z3_fpa_get_numeral_significand_bv(_ctx_pointer, ast._ast)
|
306
350
|
end
|
307
351
|
|
308
352
|
def fpa_get_numeral_significand_string(ast) #=> :string
|
@@ -313,6 +357,34 @@ module Z3
|
|
313
357
|
VeryLowLevel.Z3_fpa_get_sbits(_ctx_pointer, sort._ast)
|
314
358
|
end
|
315
359
|
|
360
|
+
def fpa_is_numeral_inf(ast) #=> :bool
|
361
|
+
VeryLowLevel.Z3_fpa_is_numeral_inf(_ctx_pointer, ast._ast)
|
362
|
+
end
|
363
|
+
|
364
|
+
def fpa_is_numeral_nan(ast) #=> :bool
|
365
|
+
VeryLowLevel.Z3_fpa_is_numeral_nan(_ctx_pointer, ast._ast)
|
366
|
+
end
|
367
|
+
|
368
|
+
def fpa_is_numeral_negative(ast) #=> :bool
|
369
|
+
VeryLowLevel.Z3_fpa_is_numeral_negative(_ctx_pointer, ast._ast)
|
370
|
+
end
|
371
|
+
|
372
|
+
def fpa_is_numeral_normal(ast) #=> :bool
|
373
|
+
VeryLowLevel.Z3_fpa_is_numeral_normal(_ctx_pointer, ast._ast)
|
374
|
+
end
|
375
|
+
|
376
|
+
def fpa_is_numeral_positive(ast) #=> :bool
|
377
|
+
VeryLowLevel.Z3_fpa_is_numeral_positive(_ctx_pointer, ast._ast)
|
378
|
+
end
|
379
|
+
|
380
|
+
def fpa_is_numeral_subnormal(ast) #=> :bool
|
381
|
+
VeryLowLevel.Z3_fpa_is_numeral_subnormal(_ctx_pointer, ast._ast)
|
382
|
+
end
|
383
|
+
|
384
|
+
def fpa_is_numeral_zero(ast) #=> :bool
|
385
|
+
VeryLowLevel.Z3_fpa_is_numeral_zero(_ctx_pointer, ast._ast)
|
386
|
+
end
|
387
|
+
|
316
388
|
def func_entry_dec_ref(func_entry) #=> :void
|
317
389
|
VeryLowLevel.Z3_func_entry_dec_ref(_ctx_pointer, func_entry._func_entry)
|
318
390
|
end
|
@@ -333,6 +405,10 @@ module Z3
|
|
333
405
|
VeryLowLevel.Z3_func_entry_inc_ref(_ctx_pointer, func_entry._func_entry)
|
334
406
|
end
|
335
407
|
|
408
|
+
def func_interp_add_entry(func_interp, ast_vector, ast) #=> :void
|
409
|
+
VeryLowLevel.Z3_func_interp_add_entry(_ctx_pointer, func_interp._func_interp, ast_vector, ast._ast)
|
410
|
+
end
|
411
|
+
|
336
412
|
def func_interp_dec_ref(func_interp) #=> :void
|
337
413
|
VeryLowLevel.Z3_func_interp_dec_ref(_ctx_pointer, func_interp._func_interp)
|
338
414
|
end
|
@@ -357,6 +433,10 @@ module Z3
|
|
357
433
|
VeryLowLevel.Z3_func_interp_inc_ref(_ctx_pointer, func_interp._func_interp)
|
358
434
|
end
|
359
435
|
|
436
|
+
def func_interp_set_else(func_interp, ast) #=> :void
|
437
|
+
VeryLowLevel.Z3_func_interp_set_else(_ctx_pointer, func_interp._func_interp, ast._ast)
|
438
|
+
end
|
439
|
+
|
360
440
|
def get_algebraic_number_lower(ast, num) #=> :ast_pointer
|
361
441
|
VeryLowLevel.Z3_get_algebraic_number_lower(_ctx_pointer, ast._ast, num)
|
362
442
|
end
|
@@ -489,6 +569,10 @@ module Z3
|
|
489
569
|
VeryLowLevel.Z3_get_error_code(_ctx_pointer)
|
490
570
|
end
|
491
571
|
|
572
|
+
def get_full_version #=> :string
|
573
|
+
VeryLowLevel.Z3_get_full_version()
|
574
|
+
end
|
575
|
+
|
492
576
|
def get_func_decl_id(func_decl) #=> :uint
|
493
577
|
VeryLowLevel.Z3_get_func_decl_id(_ctx_pointer, func_decl._ast)
|
494
578
|
end
|
@@ -521,6 +605,10 @@ module Z3
|
|
521
605
|
VeryLowLevel.Z3_get_numerator(_ctx_pointer, ast._ast)
|
522
606
|
end
|
523
607
|
|
608
|
+
def get_parser_error #=> :string
|
609
|
+
VeryLowLevel.Z3_get_parser_error(_ctx_pointer)
|
610
|
+
end
|
611
|
+
|
524
612
|
def get_pattern(pattern, num) #=> :ast_pointer
|
525
613
|
VeryLowLevel.Z3_get_pattern(_ctx_pointer, pattern._ast, num)
|
526
614
|
end
|
@@ -745,6 +833,10 @@ module Z3
|
|
745
833
|
VeryLowLevel.Z3_mk_array_sort(_ctx_pointer, sort1._ast, sort2._ast)
|
746
834
|
end
|
747
835
|
|
836
|
+
def mk_as_array(func_decl) #=> :ast_pointer
|
837
|
+
VeryLowLevel.Z3_mk_as_array(_ctx_pointer, func_decl._ast)
|
838
|
+
end
|
839
|
+
|
748
840
|
def mk_ast_map #=> :ast_map_pointer
|
749
841
|
VeryLowLevel.Z3_mk_ast_map(_ctx_pointer)
|
750
842
|
end
|
@@ -1253,6 +1345,10 @@ module Z3
|
|
1253
1345
|
VeryLowLevel.Z3_mk_int_symbol(_ctx_pointer, num)
|
1254
1346
|
end
|
1255
1347
|
|
1348
|
+
def mk_int_to_str(ast) #=> :ast_pointer
|
1349
|
+
VeryLowLevel.Z3_mk_int_to_str(_ctx_pointer, ast._ast)
|
1350
|
+
end
|
1351
|
+
|
1256
1352
|
def mk_interpolant(ast) #=> :ast_pointer
|
1257
1353
|
VeryLowLevel.Z3_mk_interpolant(_ctx_pointer, ast._ast)
|
1258
1354
|
end
|
@@ -1281,6 +1377,10 @@ module Z3
|
|
1281
1377
|
VeryLowLevel.Z3_mk_mod(_ctx_pointer, ast1._ast, ast2._ast)
|
1282
1378
|
end
|
1283
1379
|
|
1380
|
+
def mk_model #=> :model_pointer
|
1381
|
+
VeryLowLevel.Z3_mk_model(_ctx_pointer)
|
1382
|
+
end
|
1383
|
+
|
1284
1384
|
def mk_not(ast) #=> :ast_pointer
|
1285
1385
|
VeryLowLevel.Z3_mk_not(_ctx_pointer, ast._ast)
|
1286
1386
|
end
|
@@ -1305,6 +1405,26 @@ module Z3
|
|
1305
1405
|
VeryLowLevel.Z3_mk_probe(_ctx_pointer, str)
|
1306
1406
|
end
|
1307
1407
|
|
1408
|
+
def mk_re_complement(ast) #=> :ast_pointer
|
1409
|
+
VeryLowLevel.Z3_mk_re_complement(_ctx_pointer, ast._ast)
|
1410
|
+
end
|
1411
|
+
|
1412
|
+
def mk_re_empty(sort) #=> :ast_pointer
|
1413
|
+
VeryLowLevel.Z3_mk_re_empty(_ctx_pointer, sort._ast)
|
1414
|
+
end
|
1415
|
+
|
1416
|
+
def mk_re_full(sort) #=> :ast_pointer
|
1417
|
+
VeryLowLevel.Z3_mk_re_full(_ctx_pointer, sort._ast)
|
1418
|
+
end
|
1419
|
+
|
1420
|
+
def mk_re_loop(ast, num1, num2) #=> :ast_pointer
|
1421
|
+
VeryLowLevel.Z3_mk_re_loop(_ctx_pointer, ast._ast, num1, num2)
|
1422
|
+
end
|
1423
|
+
|
1424
|
+
def mk_re_range(ast1, ast2) #=> :ast_pointer
|
1425
|
+
VeryLowLevel.Z3_mk_re_range(_ctx_pointer, ast1._ast, ast2._ast)
|
1426
|
+
end
|
1427
|
+
|
1308
1428
|
def mk_real(num1, num2) #=> :ast_pointer
|
1309
1429
|
VeryLowLevel.Z3_mk_real(_ctx_pointer, num1, num2)
|
1310
1430
|
end
|
@@ -1389,6 +1509,10 @@ module Z3
|
|
1389
1509
|
VeryLowLevel.Z3_mk_store(_ctx_pointer, ast1._ast, ast2._ast, ast3._ast)
|
1390
1510
|
end
|
1391
1511
|
|
1512
|
+
def mk_str_to_int(ast) #=> :ast_pointer
|
1513
|
+
VeryLowLevel.Z3_mk_str_to_int(_ctx_pointer, ast._ast)
|
1514
|
+
end
|
1515
|
+
|
1392
1516
|
def mk_string_symbol(str) #=> :symbol_pointer
|
1393
1517
|
VeryLowLevel.Z3_mk_string_symbol(_ctx_pointer, str)
|
1394
1518
|
end
|
@@ -1429,6 +1553,10 @@ module Z3
|
|
1429
1553
|
VeryLowLevel.Z3_model_dec_ref(_ctx_pointer, model._model)
|
1430
1554
|
end
|
1431
1555
|
|
1556
|
+
def model_extrapolate(model, ast) #=> :ast_pointer
|
1557
|
+
VeryLowLevel.Z3_model_extrapolate(_ctx_pointer, model._model, ast._ast)
|
1558
|
+
end
|
1559
|
+
|
1432
1560
|
def model_get_const_decl(model, num) #=> :func_decl_pointer
|
1433
1561
|
VeryLowLevel.Z3_model_get_const_decl(_ctx_pointer, model._model, num)
|
1434
1562
|
end
|
@@ -1493,6 +1621,18 @@ module Z3
|
|
1493
1621
|
VeryLowLevel.Z3_optimize_dec_ref(_ctx_pointer, optimize._optimize)
|
1494
1622
|
end
|
1495
1623
|
|
1624
|
+
def optimize_from_file(optimize, str) #=> :void
|
1625
|
+
VeryLowLevel.Z3_optimize_from_file(_ctx_pointer, optimize._optimize, str)
|
1626
|
+
end
|
1627
|
+
|
1628
|
+
def optimize_from_string(optimize, str) #=> :void
|
1629
|
+
VeryLowLevel.Z3_optimize_from_string(_ctx_pointer, optimize._optimize, str)
|
1630
|
+
end
|
1631
|
+
|
1632
|
+
def optimize_get_assertions(optimize) #=> :ast_vector_pointer
|
1633
|
+
VeryLowLevel.Z3_optimize_get_assertions(_ctx_pointer, optimize._optimize)
|
1634
|
+
end
|
1635
|
+
|
1496
1636
|
def optimize_get_help(optimize) #=> :string
|
1497
1637
|
VeryLowLevel.Z3_optimize_get_help(_ctx_pointer, optimize._optimize)
|
1498
1638
|
end
|
@@ -1501,10 +1641,18 @@ module Z3
|
|
1501
1641
|
VeryLowLevel.Z3_optimize_get_lower(_ctx_pointer, optimize._optimize, num)
|
1502
1642
|
end
|
1503
1643
|
|
1644
|
+
def optimize_get_lower_as_vector(optimize, num) #=> :ast_vector_pointer
|
1645
|
+
VeryLowLevel.Z3_optimize_get_lower_as_vector(_ctx_pointer, optimize._optimize, num)
|
1646
|
+
end
|
1647
|
+
|
1504
1648
|
def optimize_get_model(optimize) #=> :model_pointer
|
1505
1649
|
VeryLowLevel.Z3_optimize_get_model(_ctx_pointer, optimize._optimize)
|
1506
1650
|
end
|
1507
1651
|
|
1652
|
+
def optimize_get_objectives(optimize) #=> :ast_vector_pointer
|
1653
|
+
VeryLowLevel.Z3_optimize_get_objectives(_ctx_pointer, optimize._optimize)
|
1654
|
+
end
|
1655
|
+
|
1508
1656
|
def optimize_get_param_descrs(optimize) #=> :param_descrs_pointer
|
1509
1657
|
VeryLowLevel.Z3_optimize_get_param_descrs(_ctx_pointer, optimize._optimize)
|
1510
1658
|
end
|
@@ -1521,6 +1669,10 @@ module Z3
|
|
1521
1669
|
VeryLowLevel.Z3_optimize_get_upper(_ctx_pointer, optimize._optimize, num)
|
1522
1670
|
end
|
1523
1671
|
|
1672
|
+
def optimize_get_upper_as_vector(optimize, num) #=> :ast_vector_pointer
|
1673
|
+
VeryLowLevel.Z3_optimize_get_upper_as_vector(_ctx_pointer, optimize._optimize, num)
|
1674
|
+
end
|
1675
|
+
|
1524
1676
|
def optimize_inc_ref(optimize) #=> :void
|
1525
1677
|
VeryLowLevel.Z3_optimize_inc_ref(_ctx_pointer, optimize._optimize)
|
1526
1678
|
end
|
@@ -1665,6 +1817,10 @@ module Z3
|
|
1665
1817
|
VeryLowLevel.Z3_probe_or(_ctx_pointer, probe1._probe, probe2._probe)
|
1666
1818
|
end
|
1667
1819
|
|
1820
|
+
def qe_lite(ast_vector, ast) #=> :ast_pointer
|
1821
|
+
VeryLowLevel.Z3_qe_lite(_ctx_pointer, ast_vector, ast._ast)
|
1822
|
+
end
|
1823
|
+
|
1668
1824
|
def rcf_add(num1, num2) #=> :rcf_num_pointer
|
1669
1825
|
VeryLowLevel.Z3_rcf_add(_ctx_pointer, num1._rcf_num, num2._rcf_num)
|
1670
1826
|
end
|
@@ -1789,10 +1945,22 @@ module Z3
|
|
1789
1945
|
VeryLowLevel.Z3_solver_dec_ref(_ctx_pointer, solver._solver)
|
1790
1946
|
end
|
1791
1947
|
|
1948
|
+
def solver_from_file(solver, str) #=> :void
|
1949
|
+
VeryLowLevel.Z3_solver_from_file(_ctx_pointer, solver._solver, str)
|
1950
|
+
end
|
1951
|
+
|
1952
|
+
def solver_from_string(solver, str) #=> :void
|
1953
|
+
VeryLowLevel.Z3_solver_from_string(_ctx_pointer, solver._solver, str)
|
1954
|
+
end
|
1955
|
+
|
1792
1956
|
def solver_get_assertions(solver) #=> :ast_vector_pointer
|
1793
1957
|
VeryLowLevel.Z3_solver_get_assertions(_ctx_pointer, solver._solver)
|
1794
1958
|
end
|
1795
1959
|
|
1960
|
+
def solver_get_consequences(solver, ast_vector1, ast_vector2, ast_vector3) #=> :int
|
1961
|
+
VeryLowLevel.Z3_solver_get_consequences(_ctx_pointer, solver._solver, ast_vector1, ast_vector2, ast_vector3)
|
1962
|
+
end
|
1963
|
+
|
1796
1964
|
def solver_get_help(solver) #=> :string
|
1797
1965
|
VeryLowLevel.Z3_solver_get_help(_ctx_pointer, solver._solver)
|
1798
1966
|
end
|
data/lib/z3/optimize.rb
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
module Z3
|
2
|
+
class Optimize
|
3
|
+
attr_reader :_optimize
|
4
|
+
def initialize
|
5
|
+
@_optimize = LowLevel.mk_optimize
|
6
|
+
LowLevel.optimize_inc_ref(self)
|
7
|
+
reset_model!
|
8
|
+
end
|
9
|
+
|
10
|
+
def push
|
11
|
+
reset_model!
|
12
|
+
LowLevel.optimize_push(self)
|
13
|
+
end
|
14
|
+
|
15
|
+
def pop
|
16
|
+
reset_model!
|
17
|
+
LowLevel.optimize_pop(self)
|
18
|
+
end
|
19
|
+
|
20
|
+
def assert(ast)
|
21
|
+
reset_model!
|
22
|
+
LowLevel.optimize_assert(self, ast)
|
23
|
+
end
|
24
|
+
|
25
|
+
def assert_soft(ast)
|
26
|
+
reset_model!
|
27
|
+
LowLevel.optimize_assert_soft(self, ast)
|
28
|
+
end
|
29
|
+
|
30
|
+
def check
|
31
|
+
reset_model!
|
32
|
+
result = check_sat_results(LowLevel.optimize_check(self))
|
33
|
+
@has_model = true if result == :sat
|
34
|
+
result
|
35
|
+
end
|
36
|
+
|
37
|
+
def satisfiable?
|
38
|
+
case check
|
39
|
+
when :sat
|
40
|
+
true
|
41
|
+
when :unsat
|
42
|
+
false
|
43
|
+
else
|
44
|
+
raise Z3::Exception, "Satisfiability unknown"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def unsatisfiable?
|
49
|
+
case check
|
50
|
+
when :unsat
|
51
|
+
true
|
52
|
+
when :sat
|
53
|
+
false
|
54
|
+
else
|
55
|
+
raise Z3::Exception, "Satisfiability unknown"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def model
|
60
|
+
if @has_model
|
61
|
+
@model ||= Z3::Model.new(LowLevel.optimize_get_model(self))
|
62
|
+
else
|
63
|
+
raise Z3::Exception, "You need to check that it's satisfiable before asking for the model"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def assertions
|
68
|
+
_ast_vector = LowLevel.optimize_get_assertions(self)
|
69
|
+
LowLevel.unpack_ast_vector(_ast_vector)
|
70
|
+
end
|
71
|
+
|
72
|
+
def statistics
|
73
|
+
_stats = LowLevel::optimize_get_statistics(self)
|
74
|
+
LowLevel.unpack_statistics(_stats)
|
75
|
+
end
|
76
|
+
|
77
|
+
def prove!(ast)
|
78
|
+
@has_model = false
|
79
|
+
push
|
80
|
+
assert(~ast)
|
81
|
+
case check
|
82
|
+
when :sat
|
83
|
+
puts "Counterexample exists"
|
84
|
+
model.each do |n,v|
|
85
|
+
puts "* #{n} = #{v}"
|
86
|
+
end
|
87
|
+
when :unknown
|
88
|
+
puts "Unknown"
|
89
|
+
when :unsat
|
90
|
+
puts "Proven"
|
91
|
+
else
|
92
|
+
raise "Wrong SAT result #{r}"
|
93
|
+
end
|
94
|
+
ensure
|
95
|
+
pop
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
def reason_unknown
|
100
|
+
LowLevel.optimize_get_reason_unknown(self)
|
101
|
+
end
|
102
|
+
|
103
|
+
def maximize(ast)
|
104
|
+
LowLevel.optimize_maximize(self, ast)
|
105
|
+
end
|
106
|
+
|
107
|
+
def minimize(ast)
|
108
|
+
LowLevel.optimize_minimize(self, ast)
|
109
|
+
end
|
110
|
+
|
111
|
+
private
|
112
|
+
|
113
|
+
def reset_model!
|
114
|
+
@has_model = false
|
115
|
+
@model = nil
|
116
|
+
end
|
117
|
+
|
118
|
+
def check_sat_results(r)
|
119
|
+
{
|
120
|
+
-1 => :unsat,
|
121
|
+
0 => :unknown,
|
122
|
+
1 => :sat,
|
123
|
+
}[r] or raise Z3::Exception, "Wrong SAT result #{r}"
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
data/lib/z3/printer.rb
CHANGED
@@ -44,9 +44,9 @@ module Z3
|
|
44
44
|
decl = FuncDecl.new( LowLevel::get_as_array_func_decl(a) )
|
45
45
|
PrintedExpr.new(decl.sexpr.gsub(/k!\d+/, "k!"))
|
46
46
|
elsif a.func_decl.name == "fp.numeral" and a.sort.is_a?(FloatSort)
|
47
|
+
# This API chaged in Z3 4.6
|
47
48
|
s = a.significand_string
|
48
|
-
e = a.exponent_string
|
49
|
-
e = "+#{e}" if e[0] != "-"
|
49
|
+
e = "%+d" % a.exponent_string(false).to_i
|
50
50
|
PrintedExpr.new("#{s}B#{e}")
|
51
51
|
else
|
52
52
|
decl = a.func_decl
|
data/lib/z3/sort/real_sort.rb
CHANGED
@@ -9,7 +9,7 @@ module Z3
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def from_const(val)
|
12
|
-
if val.is_a?(Integer) or (val.is_a?(Float) and val.finite?)
|
12
|
+
if val.is_a?(Integer) or (val.is_a?(Float) and val.finite?) or val.is_a?(Rational)
|
13
13
|
new LowLevel.mk_numeral(val.to_s, self)
|
14
14
|
else
|
15
15
|
raise Z3::Exception, "Cannot convert #{val.class} to #{self.class}"
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module Z3
|
2
2
|
module VeryLowLevel
|
3
|
+
attach_function :Z3_add_const_interp, [:ctx_pointer, :model_pointer, :func_decl_pointer, :ast_pointer], :void
|
4
|
+
attach_function :Z3_add_func_interp, [:ctx_pointer, :model_pointer, :func_decl_pointer, :ast_pointer], :func_interp_pointer
|
3
5
|
attach_function :Z3_algebraic_add, [:ctx_pointer, :ast_pointer, :ast_pointer], :ast_pointer
|
4
6
|
attach_function :Z3_algebraic_div, [:ctx_pointer, :ast_pointer, :ast_pointer], :ast_pointer
|
5
7
|
attach_function :Z3_algebraic_eq, [:ctx_pointer, :ast_pointer, :ast_pointer], :bool
|
@@ -53,6 +55,7 @@ module Z3
|
|
53
55
|
attach_function :Z3_enable_trace, [:string], :void
|
54
56
|
attach_function :Z3_finalize_memory, [], :void
|
55
57
|
attach_function :Z3_fixedpoint_add_cover, [:ctx_pointer, :fixedpoint_pointer, :int, :func_decl_pointer, :ast_pointer], :void
|
58
|
+
attach_function :Z3_fixedpoint_add_invariant, [:ctx_pointer, :fixedpoint_pointer, :func_decl_pointer, :ast_pointer], :void
|
56
59
|
attach_function :Z3_fixedpoint_add_rule, [:ctx_pointer, :fixedpoint_pointer, :ast_pointer, :symbol_pointer], :void
|
57
60
|
attach_function :Z3_fixedpoint_assert, [:ctx_pointer, :fixedpoint_pointer, :ast_pointer], :void
|
58
61
|
attach_function :Z3_fixedpoint_dec_ref, [:ctx_pointer, :fixedpoint_pointer], :void
|
@@ -61,34 +64,51 @@ module Z3
|
|
61
64
|
attach_function :Z3_fixedpoint_get_answer, [:ctx_pointer, :fixedpoint_pointer], :ast_pointer
|
62
65
|
attach_function :Z3_fixedpoint_get_assertions, [:ctx_pointer, :fixedpoint_pointer], :ast_vector_pointer
|
63
66
|
attach_function :Z3_fixedpoint_get_cover_delta, [:ctx_pointer, :fixedpoint_pointer, :int, :func_decl_pointer], :ast_pointer
|
67
|
+
attach_function :Z3_fixedpoint_get_ground_sat_answer, [:ctx_pointer, :fixedpoint_pointer], :ast_pointer
|
64
68
|
attach_function :Z3_fixedpoint_get_help, [:ctx_pointer, :fixedpoint_pointer], :string
|
65
69
|
attach_function :Z3_fixedpoint_get_num_levels, [:ctx_pointer, :fixedpoint_pointer, :func_decl_pointer], :uint
|
66
70
|
attach_function :Z3_fixedpoint_get_param_descrs, [:ctx_pointer, :fixedpoint_pointer], :param_descrs_pointer
|
71
|
+
attach_function :Z3_fixedpoint_get_reachable, [:ctx_pointer, :fixedpoint_pointer, :func_decl_pointer], :ast_pointer
|
67
72
|
attach_function :Z3_fixedpoint_get_reason_unknown, [:ctx_pointer, :fixedpoint_pointer], :string
|
73
|
+
attach_function :Z3_fixedpoint_get_rule_names_along_trace, [:ctx_pointer, :fixedpoint_pointer], :symbol_pointer
|
68
74
|
attach_function :Z3_fixedpoint_get_rules, [:ctx_pointer, :fixedpoint_pointer], :ast_vector_pointer
|
75
|
+
attach_function :Z3_fixedpoint_get_rules_along_trace, [:ctx_pointer, :fixedpoint_pointer], :ast_vector_pointer
|
69
76
|
attach_function :Z3_fixedpoint_get_statistics, [:ctx_pointer, :fixedpoint_pointer], :stats_pointer
|
70
77
|
attach_function :Z3_fixedpoint_inc_ref, [:ctx_pointer, :fixedpoint_pointer], :void
|
71
78
|
attach_function :Z3_fixedpoint_pop, [:ctx_pointer, :fixedpoint_pointer], :void
|
72
79
|
attach_function :Z3_fixedpoint_push, [:ctx_pointer, :fixedpoint_pointer], :void
|
73
80
|
attach_function :Z3_fixedpoint_query, [:ctx_pointer, :fixedpoint_pointer, :ast_pointer], :int
|
81
|
+
attach_function :Z3_fixedpoint_query_from_lvl, [:ctx_pointer, :fixedpoint_pointer, :ast_pointer, :uint], :int
|
74
82
|
attach_function :Z3_fixedpoint_register_relation, [:ctx_pointer, :fixedpoint_pointer, :func_decl_pointer], :void
|
75
83
|
attach_function :Z3_fixedpoint_set_params, [:ctx_pointer, :fixedpoint_pointer, :params_pointer], :void
|
76
84
|
attach_function :Z3_fixedpoint_update_rule, [:ctx_pointer, :fixedpoint_pointer, :ast_pointer, :symbol_pointer], :void
|
77
85
|
attach_function :Z3_fpa_get_ebits, [:ctx_pointer, :sort_pointer], :uint
|
78
|
-
attach_function :
|
86
|
+
attach_function :Z3_fpa_get_numeral_exponent_bv, [:ctx_pointer, :ast_pointer, :bool], :ast_pointer
|
87
|
+
attach_function :Z3_fpa_get_numeral_exponent_string, [:ctx_pointer, :ast_pointer, :bool], :string
|
88
|
+
attach_function :Z3_fpa_get_numeral_sign_bv, [:ctx_pointer, :ast_pointer], :ast_pointer
|
89
|
+
attach_function :Z3_fpa_get_numeral_significand_bv, [:ctx_pointer, :ast_pointer], :ast_pointer
|
79
90
|
attach_function :Z3_fpa_get_numeral_significand_string, [:ctx_pointer, :ast_pointer], :string
|
80
91
|
attach_function :Z3_fpa_get_sbits, [:ctx_pointer, :sort_pointer], :uint
|
92
|
+
attach_function :Z3_fpa_is_numeral_inf, [:ctx_pointer, :ast_pointer], :bool
|
93
|
+
attach_function :Z3_fpa_is_numeral_nan, [:ctx_pointer, :ast_pointer], :bool
|
94
|
+
attach_function :Z3_fpa_is_numeral_negative, [:ctx_pointer, :ast_pointer], :bool
|
95
|
+
attach_function :Z3_fpa_is_numeral_normal, [:ctx_pointer, :ast_pointer], :bool
|
96
|
+
attach_function :Z3_fpa_is_numeral_positive, [:ctx_pointer, :ast_pointer], :bool
|
97
|
+
attach_function :Z3_fpa_is_numeral_subnormal, [:ctx_pointer, :ast_pointer], :bool
|
98
|
+
attach_function :Z3_fpa_is_numeral_zero, [:ctx_pointer, :ast_pointer], :bool
|
81
99
|
attach_function :Z3_func_entry_dec_ref, [:ctx_pointer, :func_entry_pointer], :void
|
82
100
|
attach_function :Z3_func_entry_get_arg, [:ctx_pointer, :func_entry_pointer, :uint], :ast_pointer
|
83
101
|
attach_function :Z3_func_entry_get_num_args, [:ctx_pointer, :func_entry_pointer], :uint
|
84
102
|
attach_function :Z3_func_entry_get_value, [:ctx_pointer, :func_entry_pointer], :ast_pointer
|
85
103
|
attach_function :Z3_func_entry_inc_ref, [:ctx_pointer, :func_entry_pointer], :void
|
104
|
+
attach_function :Z3_func_interp_add_entry, [:ctx_pointer, :func_interp_pointer, :ast_vector_pointer, :ast_pointer], :void
|
86
105
|
attach_function :Z3_func_interp_dec_ref, [:ctx_pointer, :func_interp_pointer], :void
|
87
106
|
attach_function :Z3_func_interp_get_arity, [:ctx_pointer, :func_interp_pointer], :uint
|
88
107
|
attach_function :Z3_func_interp_get_else, [:ctx_pointer, :func_interp_pointer], :ast_pointer
|
89
108
|
attach_function :Z3_func_interp_get_entry, [:ctx_pointer, :func_interp_pointer, :uint], :func_entry_pointer
|
90
109
|
attach_function :Z3_func_interp_get_num_entries, [:ctx_pointer, :func_interp_pointer], :uint
|
91
110
|
attach_function :Z3_func_interp_inc_ref, [:ctx_pointer, :func_interp_pointer], :void
|
111
|
+
attach_function :Z3_func_interp_set_else, [:ctx_pointer, :func_interp_pointer, :ast_pointer], :void
|
92
112
|
attach_function :Z3_get_algebraic_number_lower, [:ctx_pointer, :ast_pointer, :uint], :ast_pointer
|
93
113
|
attach_function :Z3_get_algebraic_number_upper, [:ctx_pointer, :ast_pointer, :uint], :ast_pointer
|
94
114
|
attach_function :Z3_get_app_arg, [:ctx_pointer, :app_pointer, :uint], :ast_pointer
|
@@ -122,6 +142,7 @@ module Z3
|
|
122
142
|
attach_function :Z3_get_domain, [:ctx_pointer, :func_decl_pointer, :uint], :sort_pointer
|
123
143
|
attach_function :Z3_get_domain_size, [:ctx_pointer, :func_decl_pointer], :uint
|
124
144
|
attach_function :Z3_get_error_code, [:ctx_pointer], :uint
|
145
|
+
attach_function :Z3_get_full_version, [], :string
|
125
146
|
attach_function :Z3_get_func_decl_id, [:ctx_pointer, :func_decl_pointer], :uint
|
126
147
|
attach_function :Z3_get_index_value, [:ctx_pointer, :ast_pointer], :uint
|
127
148
|
attach_function :Z3_get_interpolant, [:ctx_pointer, :ast_pointer, :ast_pointer, :params_pointer], :ast_vector_pointer
|
@@ -130,6 +151,7 @@ module Z3
|
|
130
151
|
attach_function :Z3_get_numeral_decimal_string, [:ctx_pointer, :ast_pointer, :uint], :string
|
131
152
|
attach_function :Z3_get_numeral_string, [:ctx_pointer, :ast_pointer], :string
|
132
153
|
attach_function :Z3_get_numerator, [:ctx_pointer, :ast_pointer], :ast_pointer
|
154
|
+
attach_function :Z3_get_parser_error, [:ctx_pointer], :string
|
133
155
|
attach_function :Z3_get_pattern, [:ctx_pointer, :pattern_pointer, :uint], :ast_pointer
|
134
156
|
attach_function :Z3_get_pattern_num_terms, [:ctx_pointer, :pattern_pointer], :uint
|
135
157
|
attach_function :Z3_get_probe_name, [:ctx_pointer, :uint], :string
|
@@ -186,6 +208,7 @@ module Z3
|
|
186
208
|
attach_function :Z3_is_well_sorted, [:ctx_pointer, :ast_pointer], :bool
|
187
209
|
attach_function :Z3_mk_array_default, [:ctx_pointer, :ast_pointer], :ast_pointer
|
188
210
|
attach_function :Z3_mk_array_sort, [:ctx_pointer, :sort_pointer, :sort_pointer], :sort_pointer
|
211
|
+
attach_function :Z3_mk_as_array, [:ctx_pointer, :func_decl_pointer], :ast_pointer
|
189
212
|
attach_function :Z3_mk_ast_map, [:ctx_pointer], :ast_map_pointer
|
190
213
|
attach_function :Z3_mk_ast_vector, [:ctx_pointer], :ast_vector_pointer
|
191
214
|
attach_function :Z3_mk_bool_sort, [:ctx_pointer], :sort_pointer
|
@@ -313,6 +336,7 @@ module Z3
|
|
313
336
|
attach_function :Z3_mk_int64, [:ctx_pointer, :int64, :sort_pointer], :ast_pointer
|
314
337
|
attach_function :Z3_mk_int_sort, [:ctx_pointer], :sort_pointer
|
315
338
|
attach_function :Z3_mk_int_symbol, [:ctx_pointer, :int], :symbol_pointer
|
339
|
+
attach_function :Z3_mk_int_to_str, [:ctx_pointer, :ast_pointer], :ast_pointer
|
316
340
|
attach_function :Z3_mk_interpolant, [:ctx_pointer, :ast_pointer], :ast_pointer
|
317
341
|
attach_function :Z3_mk_interpolation_context, [:config_pointer], :ctx_pointer
|
318
342
|
attach_function :Z3_mk_is_int, [:ctx_pointer, :ast_pointer], :ast_pointer
|
@@ -320,12 +344,18 @@ module Z3
|
|
320
344
|
attach_function :Z3_mk_le, [:ctx_pointer, :ast_pointer, :ast_pointer], :ast_pointer
|
321
345
|
attach_function :Z3_mk_lt, [:ctx_pointer, :ast_pointer, :ast_pointer], :ast_pointer
|
322
346
|
attach_function :Z3_mk_mod, [:ctx_pointer, :ast_pointer, :ast_pointer], :ast_pointer
|
347
|
+
attach_function :Z3_mk_model, [:ctx_pointer], :model_pointer
|
323
348
|
attach_function :Z3_mk_not, [:ctx_pointer, :ast_pointer], :ast_pointer
|
324
349
|
attach_function :Z3_mk_numeral, [:ctx_pointer, :string, :sort_pointer], :ast_pointer
|
325
350
|
attach_function :Z3_mk_optimize, [:ctx_pointer], :optimize_pointer
|
326
351
|
attach_function :Z3_mk_params, [:ctx_pointer], :params_pointer
|
327
352
|
attach_function :Z3_mk_power, [:ctx_pointer, :ast_pointer, :ast_pointer], :ast_pointer
|
328
353
|
attach_function :Z3_mk_probe, [:ctx_pointer, :string], :probe_pointer
|
354
|
+
attach_function :Z3_mk_re_complement, [:ctx_pointer, :ast_pointer], :ast_pointer
|
355
|
+
attach_function :Z3_mk_re_empty, [:ctx_pointer, :sort_pointer], :ast_pointer
|
356
|
+
attach_function :Z3_mk_re_full, [:ctx_pointer, :sort_pointer], :ast_pointer
|
357
|
+
attach_function :Z3_mk_re_loop, [:ctx_pointer, :ast_pointer, :uint, :uint], :ast_pointer
|
358
|
+
attach_function :Z3_mk_re_range, [:ctx_pointer, :ast_pointer, :ast_pointer], :ast_pointer
|
329
359
|
attach_function :Z3_mk_real, [:ctx_pointer, :int, :int], :ast_pointer
|
330
360
|
attach_function :Z3_mk_real2int, [:ctx_pointer, :ast_pointer], :ast_pointer
|
331
361
|
attach_function :Z3_mk_real_sort, [:ctx_pointer], :sort_pointer
|
@@ -347,6 +377,7 @@ module Z3
|
|
347
377
|
attach_function :Z3_mk_solver_for_logic, [:ctx_pointer, :symbol_pointer], :solver_pointer
|
348
378
|
attach_function :Z3_mk_solver_from_tactic, [:ctx_pointer, :tactic_pointer], :solver_pointer
|
349
379
|
attach_function :Z3_mk_store, [:ctx_pointer, :ast_pointer, :ast_pointer, :ast_pointer], :ast_pointer
|
380
|
+
attach_function :Z3_mk_str_to_int, [:ctx_pointer, :ast_pointer], :ast_pointer
|
350
381
|
attach_function :Z3_mk_string_symbol, [:ctx_pointer, :string], :symbol_pointer
|
351
382
|
attach_function :Z3_mk_tactic, [:ctx_pointer, :string], :tactic_pointer
|
352
383
|
attach_function :Z3_mk_true, [:ctx_pointer], :ast_pointer
|
@@ -357,6 +388,7 @@ module Z3
|
|
357
388
|
attach_function :Z3_mk_xor, [:ctx_pointer, :ast_pointer, :ast_pointer], :ast_pointer
|
358
389
|
attach_function :Z3_mk_zero_ext, [:ctx_pointer, :uint, :ast_pointer], :ast_pointer
|
359
390
|
attach_function :Z3_model_dec_ref, [:ctx_pointer, :model_pointer], :void
|
391
|
+
attach_function :Z3_model_extrapolate, [:ctx_pointer, :model_pointer, :ast_pointer], :ast_pointer
|
360
392
|
attach_function :Z3_model_get_const_decl, [:ctx_pointer, :model_pointer, :uint], :func_decl_pointer
|
361
393
|
attach_function :Z3_model_get_const_interp, [:ctx_pointer, :model_pointer, :func_decl_pointer], :ast_pointer
|
362
394
|
attach_function :Z3_model_get_func_decl, [:ctx_pointer, :model_pointer, :uint], :func_decl_pointer
|
@@ -373,13 +405,19 @@ module Z3
|
|
373
405
|
attach_function :Z3_optimize_assert_soft, [:ctx_pointer, :optimize_pointer, :ast_pointer, :string, :symbol_pointer], :uint
|
374
406
|
attach_function :Z3_optimize_check, [:ctx_pointer, :optimize_pointer], :int
|
375
407
|
attach_function :Z3_optimize_dec_ref, [:ctx_pointer, :optimize_pointer], :void
|
408
|
+
attach_function :Z3_optimize_from_file, [:ctx_pointer, :optimize_pointer, :string], :void
|
409
|
+
attach_function :Z3_optimize_from_string, [:ctx_pointer, :optimize_pointer, :string], :void
|
410
|
+
attach_function :Z3_optimize_get_assertions, [:ctx_pointer, :optimize_pointer], :ast_vector_pointer
|
376
411
|
attach_function :Z3_optimize_get_help, [:ctx_pointer, :optimize_pointer], :string
|
377
412
|
attach_function :Z3_optimize_get_lower, [:ctx_pointer, :optimize_pointer, :uint], :ast_pointer
|
413
|
+
attach_function :Z3_optimize_get_lower_as_vector, [:ctx_pointer, :optimize_pointer, :uint], :ast_vector_pointer
|
378
414
|
attach_function :Z3_optimize_get_model, [:ctx_pointer, :optimize_pointer], :model_pointer
|
415
|
+
attach_function :Z3_optimize_get_objectives, [:ctx_pointer, :optimize_pointer], :ast_vector_pointer
|
379
416
|
attach_function :Z3_optimize_get_param_descrs, [:ctx_pointer, :optimize_pointer], :param_descrs_pointer
|
380
417
|
attach_function :Z3_optimize_get_reason_unknown, [:ctx_pointer, :optimize_pointer], :string
|
381
418
|
attach_function :Z3_optimize_get_statistics, [:ctx_pointer, :optimize_pointer], :stats_pointer
|
382
419
|
attach_function :Z3_optimize_get_upper, [:ctx_pointer, :optimize_pointer, :uint], :ast_pointer
|
420
|
+
attach_function :Z3_optimize_get_upper_as_vector, [:ctx_pointer, :optimize_pointer, :uint], :ast_vector_pointer
|
383
421
|
attach_function :Z3_optimize_inc_ref, [:ctx_pointer, :optimize_pointer], :void
|
384
422
|
attach_function :Z3_optimize_maximize, [:ctx_pointer, :optimize_pointer, :ast_pointer], :uint
|
385
423
|
attach_function :Z3_optimize_minimize, [:ctx_pointer, :optimize_pointer, :ast_pointer], :uint
|
@@ -416,6 +454,7 @@ module Z3
|
|
416
454
|
attach_function :Z3_probe_lt, [:ctx_pointer, :probe_pointer, :probe_pointer], :probe_pointer
|
417
455
|
attach_function :Z3_probe_not, [:ctx_pointer, :probe_pointer], :probe_pointer
|
418
456
|
attach_function :Z3_probe_or, [:ctx_pointer, :probe_pointer, :probe_pointer], :probe_pointer
|
457
|
+
attach_function :Z3_qe_lite, [:ctx_pointer, :ast_vector_pointer, :ast_pointer], :ast_pointer
|
419
458
|
attach_function :Z3_rcf_add, [:ctx_pointer, :rcf_num_pointer, :rcf_num_pointer], :rcf_num_pointer
|
420
459
|
attach_function :Z3_rcf_del, [:ctx_pointer, :rcf_num_pointer], :void
|
421
460
|
attach_function :Z3_rcf_div, [:ctx_pointer, :rcf_num_pointer, :rcf_num_pointer], :rcf_num_pointer
|
@@ -447,7 +486,10 @@ module Z3
|
|
447
486
|
attach_function :Z3_solver_assert_and_track, [:ctx_pointer, :solver_pointer, :ast_pointer, :ast_pointer], :void
|
448
487
|
attach_function :Z3_solver_check, [:ctx_pointer, :solver_pointer], :int
|
449
488
|
attach_function :Z3_solver_dec_ref, [:ctx_pointer, :solver_pointer], :void
|
489
|
+
attach_function :Z3_solver_from_file, [:ctx_pointer, :solver_pointer, :string], :void
|
490
|
+
attach_function :Z3_solver_from_string, [:ctx_pointer, :solver_pointer, :string], :void
|
450
491
|
attach_function :Z3_solver_get_assertions, [:ctx_pointer, :solver_pointer], :ast_vector_pointer
|
492
|
+
attach_function :Z3_solver_get_consequences, [:ctx_pointer, :solver_pointer, :ast_vector_pointer, :ast_vector_pointer, :ast_vector_pointer], :int
|
451
493
|
attach_function :Z3_solver_get_help, [:ctx_pointer, :solver_pointer], :string
|
452
494
|
attach_function :Z3_solver_get_model, [:ctx_pointer, :solver_pointer], :model_pointer
|
453
495
|
attach_function :Z3_solver_get_num_scopes, [:ctx_pointer, :solver_pointer], :uint
|
data/spec/float_expr_spec.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Z3
|
2
2
|
describe FloatExpr do
|
3
3
|
let(:mode) { RoundingModeSort.new }
|
4
|
+
let(:float_single) { FloatSort.new(:single) }
|
4
5
|
let(:float_double) { FloatSort.new(:double) }
|
5
6
|
let(:a) { float_double.var("a") }
|
6
7
|
let(:b) { float_double.var("b") }
|
@@ -62,12 +63,12 @@ module Z3
|
|
62
63
|
)
|
63
64
|
end
|
64
65
|
|
65
|
-
# Broken in z3
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
66
|
+
# Broken in z3 before 4.6
|
67
|
+
it "max" do
|
68
|
+
expect([a == 2.0, b == 3.0, c == a.max(b)]).to have_solution(
|
69
|
+
c => float_double.from_const(3.0),
|
70
|
+
)
|
71
|
+
end
|
71
72
|
|
72
73
|
it "min" do
|
73
74
|
expect([a == 2.0, b == 3.0, c == a.min(b)]).to have_solution(
|
@@ -104,6 +105,15 @@ module Z3
|
|
104
105
|
# Denormals changed
|
105
106
|
if Z3.version >= '4.5'
|
106
107
|
expect(float_double.from_const(1234 * 0.5**1040).to_s).to eq("0.00470733642578125B-1022")
|
108
|
+
expect(float_single.from_const(1234 * 0.5**136).to_s).to eq("1.205078125B-126")
|
109
|
+
# This is what we get, all of these are wrong, by a lot:
|
110
|
+
# expect(float_single.from_const(1234 * 0.5**137).to_s).to eq("0.205078125B-126")
|
111
|
+
# expect(float_single.from_const(1234 * 0.5**138).to_s).to eq("0.205078125B-126")
|
112
|
+
# expect(float_single.from_const(1234 * 0.5**139).to_s).to eq("0.205078125B-126")
|
113
|
+
#
|
114
|
+
# It's not even a bug in printer Z3_mk_fpa_numeral_double is broken for denormals
|
115
|
+
#
|
116
|
+
# Probably best revisit it in 4.7+
|
107
117
|
else
|
108
118
|
expect(float_double.from_const(1234 * 0.5**1040).to_s).to eq("1.205078125B-1030")
|
109
119
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# Optimize and Model specs are codependent, so half of functionality of each is tested in other class's tests
|
2
|
+
module Z3
|
3
|
+
describe Optimize do
|
4
|
+
let(:optimize) { Optimize.new }
|
5
|
+
let(:a) { Z3.Int("a") }
|
6
|
+
let(:b) { Z3.Int("b") }
|
7
|
+
|
8
|
+
it "basic functionality" do
|
9
|
+
optimize.assert(a == b)
|
10
|
+
expect(optimize).to be_satisfiable
|
11
|
+
optimize.assert(a != b)
|
12
|
+
expect(optimize).to be_unsatisfiable
|
13
|
+
end
|
14
|
+
|
15
|
+
it "push/pop" do
|
16
|
+
optimize.assert(a == b)
|
17
|
+
optimize.push
|
18
|
+
optimize.assert(a != b)
|
19
|
+
expect(optimize).to be_unsatisfiable
|
20
|
+
optimize.pop
|
21
|
+
expect(optimize).to be_satisfiable
|
22
|
+
end
|
23
|
+
|
24
|
+
it "#assertions" do
|
25
|
+
optimize.assert a + b == 4
|
26
|
+
optimize.assert b >= 2
|
27
|
+
optimize.assert Z3.Or(a == 2, a == -2)
|
28
|
+
expect(optimize.assertions).to be_same_as([
|
29
|
+
a + b == 4,
|
30
|
+
b >= 2,
|
31
|
+
(a == 2) | (a == -2),
|
32
|
+
])
|
33
|
+
end
|
34
|
+
|
35
|
+
it "#statistics" do
|
36
|
+
optimize.assert a + b == 4
|
37
|
+
optimize.assert b >= 2
|
38
|
+
optimize.assert Z3.Or(a == 2, a == -2)
|
39
|
+
stats = optimize.statistics
|
40
|
+
expect(stats.keys).to match_array(["rlimit count", "max memory", "memory", "num allocs"])
|
41
|
+
end
|
42
|
+
|
43
|
+
# This is a very simple example of unknown satisfiablity
|
44
|
+
# so we might need more complex one in the future
|
45
|
+
# Unlike Z3::Solver, this is unknown even 4.6.0
|
46
|
+
it "third way" do
|
47
|
+
optimize.assert a**3 == a
|
48
|
+
expect(optimize.check).to eq(:unknown)
|
49
|
+
expect{optimize.satisfiable?}.to raise_error("Satisfiability unknown")
|
50
|
+
expect{optimize.unsatisfiable?}.to raise_error("Satisfiability unknown")
|
51
|
+
end
|
52
|
+
|
53
|
+
it "third way" do
|
54
|
+
optimize.assert a**a == a
|
55
|
+
expect(optimize.check).to eq(:unknown)
|
56
|
+
expect{optimize.satisfiable?}.to raise_error("Satisfiability unknown")
|
57
|
+
expect{optimize.unsatisfiable?}.to raise_error("Satisfiability unknown")
|
58
|
+
end
|
59
|
+
|
60
|
+
it "maximize" do
|
61
|
+
optimize.assert a > 0
|
62
|
+
optimize.assert a < 10
|
63
|
+
optimize.maximize a
|
64
|
+
expect(optimize).to be_satisfiable
|
65
|
+
expect(optimize.model[a].to_i).to eq 9
|
66
|
+
end
|
67
|
+
|
68
|
+
it "maximize" do
|
69
|
+
optimize.assert a > 0
|
70
|
+
optimize.assert a < 10
|
71
|
+
optimize.minimize a
|
72
|
+
expect(optimize).to be_satisfiable
|
73
|
+
expect(optimize.model[a].to_i).to eq 1
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/spec/real_expr_spec.rb
CHANGED
@@ -7,6 +7,7 @@ module Z3
|
|
7
7
|
|
8
8
|
it "+" do
|
9
9
|
expect([a == 2, b == 4, c == a + b]).to have_solution(c => 6)
|
10
|
+
expect([a == Rational(1,3), b == Rational(3,2), c == a + b]).to have_solution(c => "11/6")
|
10
11
|
end
|
11
12
|
|
12
13
|
it "-" do
|
@@ -67,6 +68,7 @@ module Z3
|
|
67
68
|
expect([a == 3, b == -a]).to have_solution(b => -3)
|
68
69
|
expect([a == 0, b == -a]).to have_solution(b => 0)
|
69
70
|
expect([a == 3.5, b == -a]).to have_solution(b => "-7/2")
|
71
|
+
expect([a == Rational(4,3), b == -a]).to have_solution(b => "-4/3")
|
70
72
|
end
|
71
73
|
end
|
72
74
|
end
|
data/spec/real_sort_spec.rb
CHANGED
@@ -9,6 +9,8 @@ module Z3
|
|
9
9
|
expect(subject.from_const(-0.0).inspect).to eq("Real<0>")
|
10
10
|
expect(subject.from_const(3.14).inspect).to eq("Real<157/50>")
|
11
11
|
expect(subject.from_const(-3.14).inspect).to eq("Real<-157/50>")
|
12
|
+
expect(subject.from_const(Rational(22,7)).inspect).to eq("Real<22/7>")
|
13
|
+
expect(subject.from_const(Rational(-22,7)).inspect).to eq("Real<-22/7>")
|
12
14
|
end
|
13
15
|
|
14
16
|
it "raises exception when trying to convert constants of wrong type" do
|
data/spec/spec_helper.rb
CHANGED
@@ -11,28 +11,17 @@ require_relative "../lib/z3"
|
|
11
11
|
|
12
12
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
13
13
|
RSpec.configure do |config|
|
14
|
-
# rspec-expectations config goes here. You can use an alternate
|
15
|
-
# assertion/expectation library such as wrong or the stdlib/minitest
|
16
|
-
# assertions if you prefer.
|
17
14
|
config.expect_with :rspec do |expectations|
|
18
|
-
# This option will default to `true` in RSpec 4. It makes the `description`
|
19
|
-
# and `failure_message` of custom matchers include text for helper methods
|
20
|
-
# defined using `chain`, e.g.:
|
21
|
-
# be_bigger_than(2).and_smaller_than(4).description
|
22
|
-
# # => "be bigger than 2 and smaller than 4"
|
23
|
-
# ...rather than:
|
24
|
-
# # => "be bigger than 2"
|
25
15
|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
26
16
|
end
|
27
17
|
|
28
|
-
# rspec-mocks config goes here. You can use an alternate test double
|
29
|
-
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
30
18
|
config.mock_with :rspec do |mocks|
|
31
|
-
# Prevents you from mocking or stubbing a method that does not exist on
|
32
|
-
# a real object. This is generally recommended, and will default to
|
33
|
-
# `true` in RSpec 4.
|
34
19
|
mocks.verify_partial_doubles = true
|
35
20
|
end
|
21
|
+
|
22
|
+
config.define_derived_metadata do |meta|
|
23
|
+
meta[:aggregate_failures] = true
|
24
|
+
end
|
36
25
|
end
|
37
26
|
|
38
27
|
RSpec::Matchers.define :have_output do |expected|
|
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.20180616
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomasz Wegrzanowski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -177,6 +177,7 @@ files:
|
|
177
177
|
- lib/z3/low_level.rb
|
178
178
|
- lib/z3/low_level_auto.rb
|
179
179
|
- lib/z3/model.rb
|
180
|
+
- lib/z3/optimize.rb
|
180
181
|
- lib/z3/printer.rb
|
181
182
|
- lib/z3/probe.rb
|
182
183
|
- lib/z3/solver.rb
|
@@ -231,6 +232,7 @@ files:
|
|
231
232
|
- spec/integration/verbal_arithmetic_spec.rb
|
232
233
|
- spec/integration/zebra_puzzle_spec.rb
|
233
234
|
- spec/model_spec.rb
|
235
|
+
- spec/optimize_spec.rb
|
234
236
|
- spec/printer_spec.rb
|
235
237
|
- spec/probe_spec.rb
|
236
238
|
- spec/real_expr_spec.rb
|