## Z3 support for nonlinear arithmetic

Z3 supports nonlinear polynomial Real arithmetic. So, there is no support for transcendental functions (e.g., sine and cosine), and exponential (e.g., 2^x). Actually, for the exponential, Z3 can handle exponents that can be simplified to numerals. Here is an example, x = Real(‘x’) y = Real(‘y’) solve(y == 3, x**y == 2) In this example, … Read more

Categories z3 Tags

## K-out-of-N constraint in Z3Py

Yes, Z3Py has built-in support for this. There is an undocumented API for this, that isn’t mentioned in the Z3Py docs: use PbEq. In particular, the expression PbEq(((x1,1),(x2,1),..,(xN,1)),K) will be true if exactly K out of the N boolean variables are set to true. There are some reports that this encoding will be faster than … Read more

## Soft/Hard constraints in Z3

Assumptions are available in the SMT 2.0 frontend. They are used to extract unsatisfiable cores. They may be also used to “retract” assumptions. Note that, assumptions are not really “soft constraints”, but they can be used to implement them. See the maxsat example (subdir maxsat) in the Z3 distribution. That being said, here is an … Read more

Categories z3 Tags

## Z3: finding all satisfying models

One way to accomplish this is using one of the APIs, along with the model generation capability. You can then use the generated model from one satisfiability check to add constraints to prevent previous model values from being used in subsequent satisfiability checks, until there are no more satisfying assignments. Of course, you have to … Read more

## How does Z3 handle non-linear integer arithmetic?

Yes, the decision problem for nonlinear integer arithmetic is undecidable. We can encode the Halting problem for Turing machines in nonlinear integer arithmetic. I strongly recommend the beautiful book Hilbert’s tenth problem for anybody interested in this problem. Note that, if a formula has a solution, we can always find it by brute force. That … Read more

Categories z3 Tags