Is it possible to use pi, e and other non-algebraic real numbers in Z3Py?
I wouldn't want to run any C program, but directly from the Z3 Python API
Non-algebraic numbers are usually not supported by SMT solvers. Having said that, you can get pi in z3 indirectly via trigonometric functions, (sin, cos etc.); but the support is incomplete. (Meaning that the solver is most likely to return unknown for most inputs.)
See this answer for a related question: Support of trigonometric functions ( e.g.: cos, tan) in Z3
Related
The Z3 SMT solver from Microsoft Research is widely viewed as a leader in its field.
Is there any meaning behind the name "Z3" or is it purely a random project name? I have looked through several papers and slides that introduce the project, but none of them seem to explain the name.
"Z3" in the name Z3 SMT solver (SMT = Satisfiability modulo theories) is based on a previous Microsoft solver called Zapatho. Basically, higher versions had more functions but a shorter name. It went from
Zapatho
Zap2
Z3
Explained by Nikolaj Bjørner in Z3 and SMT in Industrial R&D:
Microsoft Research was also an incubator to the SLAM symbolic model checker, which had instigated the previous generations of SMT solvers at Microsoft: Zapatho solved integer difference logic and uninterpreted functions, Zap2 (dropping “atho”) extended the scope to full linear arithmetic, uninterpreted functions, arrays and quantifiers,and Leonardo de Moura and I created a v. 3 from scratch, Z3, dropping “ap”.
(Originally: N Bjørner, "Z3 and SMT in Industrial R&D" in: K Havelund, J Peleska, B Roscoe, E de Vink: "Formal Methods: 22nd International Symposium, FM 2018, Held as Part of the Federated Logic Conference, FloC 2018, Oxford, UK, July 15-17, 2018, Proceedings", Springer, p. 676.)
I am using the Z3 solver with Python API to tackle a Circuit SAT problem.
It consists of many Xor expressions with up to 21 inputs and three-input And expressions. Z3 is able to solve my smaller examples but does not cope with the bigger ones.
Rather than creating the Solver object with
s = Solver()
I tried to optimize the solver tactics like in
t = Then('simplify', 'symmetry-reduce', 'aig', 'tseitin-cnf', 'sat' )
s = t.solver()
I got the tactics list via describe_tactics()
Unfortunately, my attempts have not been fruitful. The default sequence of tactics seems to do a pretty good job. The tactics tutorial previously available in rise4fun is no longer accessible.
Another attempt - without visible effect - was to set the phase parameter, as I am expecting the majority of my variables to have false values. (cf related post)
set_option("sat.phase", "always-false")
What sequence of tactics is recommended for Circuit SAT problems?
I am trying to optimize z3 python input that is generated from my models. I am able to run it on models up 15k constraints (200 states) and then z3 stops finishing in reasonable time (<10 minutes). Is there a way to optimize the constraints that are generated from my models ?
Model for 3 states:
http://pastebin.com/EHZ1P20C
The performance of the script http://pastebin.com/F5iuhN42 can be improved by using a custom strategy. Z3 allows users to define custom strategies/solvers. This tutorial shows how to define strategies/tactics using the Z3 Python API. In the script http://pastebin.com/F5iuhN42, if we replace the line
s = Solver()
with
s = Then('simplify', 'elim-term-ite', 'solve-eqs', 'smt').solver()
the runtime will decrease from 30 secs to 1 sec (on my machine).
The procedure Then is creating a strategy/tactic composed of 4 steps:
Simplifier (i.e., a rewriter that applies rules such as x + 1 - x + y ==> 1 + y
Elimination of expressions of the form If(a, b, c) where b and c are not Boolean. The script makes extensive use this kind of expression. The tactic elim-term-ite will apply transformations that eliminate this kind of expression.
Equational solver. It applies transformations such as x = a And F[x] ==> F[a]. In the script above, this tactic can eliminate more than 1000 variables.
The tactic smt invokes a general purpose SMT solver in Z3.
The method .solver() converts a Z3 tactic/strategy into a solver object that provides the add and check methods. The tutorial that I included in the beginning of the message has more details.
Z3 has a prove() method, that can prove the equivalence of two formulas.
However, I cannot find technical documentation of this prove() method. What is the definition of "equivalence" that prove() is using behind the scene ? Is that the "partial equivalence" (proposed in the "Regression Verification" paper), or something more powerful ?
A reminder, the "partial equivalence" guarantees that two formulas are equivalent if given the same input, they produce the same output.
In "Regression Verification", we are checking whether a newer version of a program produces the same output as the earlier one. That is, it is an approach for checking program equivalence.
In this approach, theorem provers (SMT solvers) such as Z3 are used. That being said, we should not confuse program equivalence with formula equivalence in first-order logic. Z3 processes first-order logic formulas. First-order logic has well defined semantics. A key concept is satisfiability. For example, the formula p or q is satisfiable, because we can make it true by assigning p or q to true. On the other hand, p and (not p) is unsatisfiable. We can find additional information in this section of the Z3 tutorial.
The Z3 API provides procedures for checking the satisfiability of first-order formulas. The Z3 Python interface has a prove procedure. It shows that a formula is valid by showing that its negation is unsatisfiable. This is a simple function built on top of the Z3 API. Here is a link to its documentation.The documentation was automatically generated from the PyDoc annotations in the code.
Note that, prove(F) is checking whether a formula F is valid or not. Thus, we can use prove(F == G) to try to prove that two first-order formulas F and G are equivalent. That is, we are essentially showing that F iff G is a valid formula.
Is there a way to make z3 solver emit "symbolic" solutions? For example, for equation:
1+x=c
the solution is x=c-1, but z3 always emits a specific model, like [c = 0, x = -1]. How to "define" c as a symbolic variable?
Unfortunately, Z3 does not expose this kind of functionality. Although we use solvers internally, they are not exposed in the API. In future versions, we want to expose internal components such as: solver, Grobner bases procedures, etc. In the current version, we have a tactic called solve-eqs (see http://rise4fun.com/Z3Py/tutorial/strategies). It eliminates variables using a generalization of Gaussian elimination. However, this is a preprocessing step, and you do not have any control over which variables are eliminated.