For this example: http://pastebin.com/QyebfD1p z3 and cvc4 return "unknown" as result of check-sat. Both are not very verbose about the cause, is there a way to make z3 more verbose about its execution ?
相关问题
- How to compute with Quaternion numbers in Z3?
- Z3 real arithmetics and data types theories integr
- Timeout for Z3 Optimize
- Adjusting `simplify` tactic in Z3
- How to setup a Java development environment for Z3
相关文章
- retrieve the matched model in Z3py?
- Simplex in z3 via for-all
- How do I get Z3 to return minimal model?
- How to get z3 to return multiple unsat cores, mult
- ld linking error while compiling z3
- Horn clauses in Z3
- Getting a “good” unsat-core with z3 (logic QF_BV)
- how to get multiple solutions for z3 solver in smt
Your script uses the tactic
This tactic applies the Z3 simplifier, and then executes a "general purpose" SMT solver available in Z3. This solver is not complete for nonlinear arithmetic. It is based on a combination of: Simplex, Interval Arithmetic and Grobner Basis. One of the big limitations of this module is that it can't find models/solutions containing irrational numbers. In the future, we will replace this module with new nonlinear solvers available in Z3.
For nonlinear arithmetic, we usually suggest the nlsat solver available in Z3. This is a complete procedure and is usually very effective for unsatisfiable and satisfiable instances. You can find more about nlsat in this article. To use nlsat, we have to use
Unfortunately, nlsat will get stuck in your example. It will get stuck computing Subresultants of very big polynomials produced during solving..
Z3 has yet another engine for handling nonlinear arithmetic. This engine reduces the problem to SAT. It is only effective on satisfiable problems that have solutions of the form
a + b sqrt(2)
wherea
andb
are rational numbers. Using this engine, we can solve your problem in a very short amount of time. I attached the result in the end of the post. To use this engine, we have to useEDIT Moreover, the tactic
nla2bv
encodes the rational numbersa
andb
as a pair of bit-vectors. By default, it uses bit-vectors of size 4. However, this value can be specified using the optionnlsat_bv_size
. This is not a global option, but an option provided to the tacticnla2bv
. Thus,nla2bv
can only find solutions of the forma + b sqrt(2)
wherea
andb
can be encoded using a small number of bits. If a satisfiable problem does not have a solution of this form, this tactic will fail and returnunknown
. END EDITYour example also suggests that we have to improve nlsat, and make it more effective as a model/solution finding procedure. The current version gets stuck when trying to show that the problem has no solution. We are aware of these limitations and are working on new procedures to workaround them.
BTW, in the Python front-end, Z3 displays the models/solutions in decimal notation. However, everything is computed precisely. To get the precise representation of the solution. We can use the method
sexpr()
. For example, I changed your loop toIn the new loop, I'm displaying the result in decimal notation and the internal precise one. The meaning of
(root-obj (+ (* 2 (^ x 2)) (* 12 x) (- 7)) 2)
is the 2nd root of the polynomial2*x^2 + 12x - 7
.EDIT Z3 provides combinators for creating non-trivial solvers. In the examples above, we used
Then
to perform the sequential composition of different tactics. We may also useOrElse
to try different tactics. andTryFor(t, ms)
that tries tactict
forms
milliseconds, and fails if the problem can't be solved in the given time. These combinators can be used to create tactics that use different strategies for solving a problem. END EDITEDIT You can solve the problem in your comment by using the tactic
This tactic will solve the problem in a couple of seconds, and produce the solution in the end of the post. As I said above,
nlsat
is complete, but it may take very long time. Your problem is on the fringe of what the current version of Z3 can decide/solve automatically. We can combine different tactics withOrElse
andTryFor
to make it more stable. Example:The tactic above tries the
nla2bv
approach for 1 sec, thennlsat
for 1 sec, thennla2bv
for 10 secs, and finallynlsat
without a timeout.I know this is not an ideal solution, but variations like that may be useful workarounds until the next solver for nonlinear arithmetic is ready. Moreover, Z3 has many other tactics that may be used to simplify/preprocess the problem before we invoke
nlsat
. END EDITEDIT 2 Your problems are on the fringe of what Z3 can do in a reasonable amount of time. Nonlinear real arithmetic is decidable, but is very expensive. Regarding debugging/tracing what is going on in Z3. Here are some possibilities:
We can enable verbose messages using the command:
set_option("verbose", 10)
. The number is the verbosity level: 0 == "no message", and higher numbers == "more messages".Compile Z3 with support for tracing. See this post for more information.
Create a log of the Z3 APIs invoked by the Python program using the command
open_log("z3.log")
. This command should be invoked before any other Z3 API call. Then execute the log using thez3
executable inside ofgdb
. So, you will be able to stop the execution and find where Z3 is stuck. Thenlsat
solver usually gets stuck in two different places:Computing subresultants (the procedure
psc_chain
will be on the stack), andisolating the roots of polynomials with algebraic coefficients (the procedure
isolate_roots
will be on the stack).Problem 2 will be soon fixed, after we replace the old algebraic number package with the new one that is much more efficient. Unfortunately, it seems your problems get stuck in the subresultant step.
Another remarks: although
nla2bv
was effective for your original benchmark, it is unlikely your new benchmarks will have a solution of the forma + b sqrt(2)
wherea
andb
are rational numbers. So, usingnla2bv
is just overhead. The tacticnlsat
assumes the problem to be in CNF. So, forpastebin.com/QRCUQE10
, we have to invoketseitin-cnf
before invokingnlsat
. Another option is to use "big" tacticqfnra-nlsat
. It invokes many pre-processing steps before invokingnlsat
. However, some of these steps may make some problems harder to solve.END EDIT 2