Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get only "true" variables from SAT model?

Tags:

z3

Consider that I have a simple SMT-lib formula:

(declare-const a Bool)
(declare-const b Bool)
(declare-const c Bool)
(declare-const d Bool)
(assert (or a b))
(assert (or d c))
(check-sat)
(get-model)

When SAT solver gives a model. It provides all variables with there true/false values. But I want only "True" value assigned variables. It is possible with Z3??

like image 521
user1770051 Avatar asked Nov 02 '25 08:11

user1770051


1 Answers

Here's a z3py script that accomplishes this. http://rise4fun.com/Z3Py/fp5k

I think to interact with / traverse the model, you need to work with an API.

a,b,c,d = Bools('a b c d')

s = Solver()

s.add( Or(a, b) )
s.add( Or(c, d) )

s.check()
m = s.model()
print m

for t in m.decls():
  if is_true(m[t]):
    print t
    print m[t]
like image 95
Taylor T. Johnson Avatar answered Nov 04 '25 14:11

Taylor T. Johnson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!