I have a boolean function that is presented by truth table.
In total it is 10 variables and I'd like to get CNF with a reasonable length (not necessary the shortest, but short enough).
How can I do it?
Python script or any public available software such as Mathematica/Mapple/etc will work fine for me as well.
The
sympypackage allows you to do this out-of-the box. (https://www.sympy.org/en/index.html)Here's a simple example. Assuming you've three variables and the truth table encodes the following set:
(i.e., only the rows corresponding to
x=true, y=true, z=falseandx=true, y=false, z=truearetrue, while all others arefalse). You can easily code this and convert to CNF as follows:simplify_logiccan convert to CNF or DNF, based on theformargument. See here: https://github.com/sympy/sympy/blob/c3087c883be02ad228820ff714ad6eb9af1ad868/sympy/logic/boolalg.py#L2746-L2827Note that CNF expansion can be costly in general, and Tseitin encoding is the preferred method to avoid this complexity (https://en.wikipedia.org/wiki/Tseytin_transformation). But it has the disadvantage of introducing new variables.