简体   繁体   中英

How do I get a solver (problem) in an SMTLIB format using the Z3 Python API?

I would like to print the SMTLIB string of a problem. For example to save a constructed problem to a file, run other solvers on it, etc.

I know of the functions sexpr() and to_smt2() but the latter behaves in unexpected ways. In particular it does not add function definitions. After the following script:

solv = z3.Solver()
n = z3.Int("n")
f = z3.RecFunction("f", [z3.IntSort(), z3.IntSort()])
z3.RecAddDefinition(f, n, n * 5 )
solv.add(f(2) == 10)

Now sexpr() returns

(define-funs-rec ( ( f ((x!1 Int)) Int)) ( (* x!1 5)))
(assert (= ((_ f 0) 2) 10))

lacking for example set-info and check-sat commands. to_smt2() on the other hand returns

(set-info :status unknown)
(assert (= ((_ f 0) 2) 10)) 
(check-sat)

print the set-info/check-sat which is what I would expect but does not include the function definitions for f for example. How can I obtain an SMTLIB2 string that includes the definitions etc. as well as check-sat/set-info etc. commands?

There isn't any. Just use sexpr and add the additional bits yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM