z3satisfiability

Bounding number of allowable True/False in Z3


Suppose I have a collection of logical assertions in Z3 and I want to check the satisfiability. Is there a way to bound the total number of Trues/Falses in the satisfying model(s)?

For example, I might have a collection of assertions involving 100 Boolean variables, but I am only interested in solutions with at least 90 Trues.


Solution

  • Yes. There are two relatively easy ways to achieve this:

    Note that you can even get z3 to "maximize" the number of true booleans. This will use the optimization engine, and works by maximizing the sum expression in the first option above. You can find many references in SO on how to use the optimizer.