I am working with the Python API of Z3 in an attempt to include support for it in a research tool that I am writing. I have a question regarding extracting the unsatisfiable core using the Python interface.
I have the following simple query:
(set-option :produce-unsat-cores true)
(assert (! (not (= (_ bv0 32) (_ bv0 32))) :named __constraint0))
(check-sat)
(get-unsat-core)
(exit)
Running this query through the z3 executable (for Z3 4.1), I receive the expected result:
unsat
(__constraint0)
For Z3 4.3, I obtain a segmentation fault:
unsat
Segmentation fault
That isn't the main question, although that was an intriguing observation. I then modified the query (inside a file) as
(assert (! (not (= (_ bv0 32) (_ bv0 32))) :named __constraint0))
(exit)
Using a file handler, I passed the contents of this file (in a variable `queryStr') to the following Python code:
import z3
...
solver = z3.Solver()
solver.reset()
solver.add(z3.parse_smt2_string(queryStr))
querySatResult = solver.check()
if querySatResult == z3.sat:
...
elif querySatResult == z3.unsat:
print solver.unsat_core()
I receive the empty list from the `unsat_core' function: []. Am I using this function incorrectly? The docstring for the function suggests that I should instead be doing something similar to
solver.add(z3.Implies(p1, z3.Not(0 == 0)))
However, I was wondering if it were still possible to use the query as is, since it conforms to SMT-LIB v2.0 standards (I believe), and whether I was missing something obvious.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…