Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can get final CNF formula from Z3?

Tags:

z3

z3py

Here is my simple encoding. I would like to get the final Boolean CNF that presents all these constrains. Is there any option in Z3 solver to get the final Boolean CNF ?

x = Int('x')
y = Int('y')

c1 = And(x >= 1, x <= 10)
c2 = And(y >= 1, y <= 10)
c3 = Distinct(x,y)

s = Solver()
s.add(c1 , c2 , c3)
# I need the final Boolean CNF formula from Z3 solver...

Thanks & Regards

like image 945
user1770051 Avatar asked Oct 20 '25 02:10

user1770051


1 Answers

As Ayrat says, use goals and tactics. Here is an example: http://rise4fun.com/Z3Py/4I3

x = Int('x')
y = Int('y')

c1 = And(x >= 1, x <= 10)
c2 = And(y >= 1, y <= 10)
c3 = Distinct(x,y)

g = Goal()
g.add(c1 , c2 , c3)

describe_tactics()

t = Tactic('tseitin-cnf')
r = t(g)

print(r[0].dimacs())

(DIMACS CNF output command 🎩-tip: CoolA1d)

like image 126
Nikolaj Bjorner Avatar answered Oct 22 '25 05:10

Nikolaj Bjorner



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!