0

I have a test.smt2 file:

(set-logic QF_IDL)
(declare-const a Int)
(declare-const b Int)
(declare-const c Int)
(assert (or (< a 2) (< b 2 )) )
(check-sat)
(get-model)
(exit)

Is there anyway to tell Z3 to only output a=1 (or b=1)? Because when a is 1, b's value does not matter any more.

I executed z3 smt.relevancy=2 -smt2 test.smt2

(following How do I get Z3 to return minimal model?, although smt.relevancy seems has default value 2), but it still outputs:

sat
(model
  (define-fun b () Int
    2)
  (define-fun a () Int
    1)
)

Thank you!

Community
  • 1
  • 1

1 Answers1

0

The example given in the answer to the question referred to is slightly out of date. A Solver() will pick a suitable tactic to solve the problem, and it appears that it picks a different one now. We can still get that behavior by using a SimpleSolver() (at a possibly significant performance loss). Here's an updated example:

from z3 import *

x, y = Bools('x y')
s = SimpleSolver()
s.set(auto_config=False,relevancy=2)
s.add(Or(x, y))
print s.check()
print s.model()

Note that the (check-sat) command will not execute the same tactic as the SimpleSolver(); to get the same behavior when solving SMT2 files, we need to use the smt tactic, i.e., use (check-sat-using smt). In many cases it will be beneficial to additionally run the simplifier on the problem first which we can achieve by constructing a custom tactic, e.g., (check-sat-using (then simplify smt))

Christoph Wintersteiger
  • 8,234
  • 1
  • 16
  • 30
  • Thanks Christoph! I'm relatively new in Z3, and I wonder: 1) In my example, how to modify the .smt2 file and the command I executed, in order to get the result (only have a=1, rather than (a=1, b=2))? 2) Is smt.relevancy's default value 2? And also would the command I executed: z3 smt.relevancy=2 have the same effect? Thanks again! – Qingzhou Luo Feb 04 '15 at 05:51
  • I'll let you run those combinations by yourself, but yes, smt.relevancy=2 is the default, it seems that was not always the case though (see old example), so it might change again. In SMT2 options can be set via the (set-option :name value) command or on the command line. Don't forget to set auto_config=false, and if you're not using tactics/solvers, then the parameter for relevancy is smt.relevancy instead of just relevancy. – Christoph Wintersteiger Feb 04 '15 at 16:43
  • Yes, I added "(set-option :smt.auto-config false) (set-option :smt.relevancy 2)" to the top of the file as listed in the original post, use "z3 test.smt2" to execute the program, but it still gives out the same result (b=2, a=1). Anyway thanks very much for your reply, probably I misunderstood something about relevancy. – Qingzhou Luo Feb 04 '15 at 19:49
  • I am using Z3 4.3.2, and I 'm adding (set-option :auto-config false) (set-option :smt.auto-config false) (set-option :smt.relevancy 2) to test.smt2. Basically I tried any combination I can think of, but Z3 still gives me result (a=2,b=1) instead of just (a=2). – Qingzhou Luo Feb 04 '15 at 20:02
  • Indeed, I had forgotten that I have to get back to SMT2 after the excursion to Python. I've added a paragraph about that to the answer, I hope that helps! – Christoph Wintersteiger Feb 05 '15 at 13:52
  • Thank you very much Christoph! It indeed solved my problem. I will learn more about relevancy to see if relevancy=2 will give me the property that the model is minimal (meaning you cannot remove any assignment from that model but still get true for the formula), it looks like so as I tried a few examples. – Qingzhou Luo Feb 05 '15 at 19:21