LINKS:
Launching python-bound python theorem Z3
I used Z3 as a SAT solver. For larger formulas, there seems to be performance issues, so I wanted to check picosate to see if this is a faster alternative. My existing python code generates a propositional formula in z3 syntax:
from z3 import *
import pycosat
from pycosat import solve, itersolve
C, G, M, P, R, S, SN, B = Bools('C G M P R S SN B')
C = (And(*(S,Or(Not(S),P),Or(Not(P),S),Or(Not(P),B),Or(Not(C),P),Or(Not(G),P),Or(Not(M),P),Or(Not(R),P),Or(Not(SN),P),Or(Not(B),P),True,Not(False),Or(R,SN,B,G,M,C,True))))
f = simplify(C)
print f
OUTPUT / RESULT
And(S,
Or(Not(S), P),
Or(Not(P), S),
Or(Not(P), B),
Or(Not(C), P),
Or(Not(G), P),
Or(Not(M), P),
Or(Not(R), P),
Or(Not(SN), P),
Or(Not(B), P))
However, Picosat uses lists / arrays of numbers, as shown in the following example ("clauses1": 6 refers to the variable P, -6 means "not P", etc.):
import pycosat
from pycosat import solve, itersolve
#
# use pico sat
#
nvars = 8
clauses =[
[6],
[-6, 4], ## "Or(Not(S), P)" from OUPUT above
[-4, 6],
[-4, 8],
[-1, 4],
[-2, 4],
[-3, 4],
[-5, 4],
[-7, 4],
[-8, 4]]
#
# efficiently find all models of the formula
#
sols = list(itersolve(clauses, vars=nvars))
print "result:"
print sols
print "\n\n====\n"
Z3- (, varaible "f" ), CNF, , picosat CNF? API- python Z3, .
( , . , C, , z3 )