0

How i can list only specific constraint result from my unsat core? I have a lot of conditions and printing whole core doesn't print all. I read that it can be done with assert_and_track and unsat_core commands. I found some examples but they don't works. Any experience with this?

s.assert_and_track(A > B, 'p1')
s.assert_and_track(B > C, 'p2')
if s.check() == sat:
  print('ok')
else:
  c = s.unsat_core
  print(c) <- this print all core

So how to print only p1 or p2 (just true/false result) ? e.g. p2 = false, or it can be displayed in way as is displayed in print(c) mode - but just for p1.

z3_test
  • 19
  • 6

1 Answers1

0

The easiest way to achieve that is to simply save a map of labels to constraints, for this examples we can do

M = {}
M['p1'] = (A > B)
M['p2'] = (B > C)
M['p3'] = (C > A)

so that later we can print the core in terms of those constraints, for instance as follows

core = s.unsat_core()
for e in core:
    print(M[str(e)])

Of course this will also work if you want to print only some entries instead of all of them.

Christoph Wintersteiger
  • 8,234
  • 1
  • 16
  • 30
  • It doesn't work. First i must due syntax error correct `print M[str(e)]` to `print (M[str(e)])` and then i get `TypeError: 'method' object is not iterable` on line `for e in core:`. Also try display it directly with `print (M['p1'])` but this display `A > B`. So i try convert it to boolean `print (bool(M['p1']))` but this print always True no matter what conditions (< > ==) i set. – z3_test Oct 25 '15 at 09:49
  • Looks like you're using Python 3.x while I've been using 2.x; I'll have to update the example for it to work with 3.x. – Christoph Wintersteiger Oct 25 '15 at 19:47
  • I've updated the example and I've fixed another Python 3.x problem Z3's API. The example runs fine using my Python 3.4.3 on Windows. Are you using an old version of Z3 or of Python? – Christoph Wintersteiger Oct 26 '15 at 16:11
  • Python v3.5, Z3 v4.4.1 - both x64. I have in my test small typo `unsat_core` shoul be `unsat_core()` now it's without error, but still no output. If i use direct print object `print (M['p1'])` i get in output `A > B` – z3_test Oct 26 '15 at 18:51