Hi I am new to Z3 SMT solver. I know you can invoke Z3 programmatically by using relevant APIs. But I want to do the following things with Z3 SMT solver:
how can I feed Z3 with one input file programmatically?
how can I incrementally get the solution(s)?
For example:
while ((check-sat) returns sat)
get the assignments for all boolean vairables
Finally, how can I ask Z3 to save the results into one output file after solving the formula?
Any ideas or documents I can look at?
Thanks million!!!
The Z3 distribution contains several (programmatic API) examples.
examples/c/test_capi.c: many small examples using the C interface.
examples/dotnet/test_managed.cs: similar examples in C#
examples/maxsat/maxsat.c: MaxSAT procedures (in C) on top of the Z3 API.
examples/ocaml/test_mlapi.ml: examples in ML
examples/theory/test_user_theory.c: example showing how to implement an external theory (plugin).
Related
I am currently going through following documents:
https://rise4fun.com/z3/tutorial/strategies
http://z3prover.github.io/api/html/namespace_microsoft_1_1_z3.html
In one of our academic research project, we are using Z3 for problem-solving. It is written using Z3 C# API. We want to use the concept of tactics, goals, and sub-goals. We want to give tactics using tactic combinators (aka tacticals). However, in the C# API, I could not find any way to use combinators like (then ..) (or-else ...).
Is there any API function I can use to create such combinators?
The way a single tactic can be used is as follows:
Tactic t = Context.MkTactic("simplify");
Context.MkSolver(Tactic)
The tactic combinator constructors are on the Context, e.g. AndThen.
I'm trying to find the c++ file for Z3 where the algorithm backtraces if it can't find a solution on the current branch. I've been looking through all the files and tried debug mode on the python files, but no luck so far. I just want to add a print statement to the method, so I can tell when it is returning to a previous node and trying a new path.
Thanks!
It depends on which solver Z3 uses for your problem. It typically uses smt_context.cpp in src/smt. The relevant backjump can be traced in the context::pop_scope method. Other solvers exist too: the src/sat/sat_solver is used for bit-vector and Boolean problems. It has a similar pop method. Finally, nlsat is used for non-linear polynomial arithmetic over the reals.
I build the formula in z3 using the java API.
However, I have some formula that are difficult to solve, and I want to investigate why. Therefore, I want to print the formula in SMTLIB2 format.
Is it possible to get that from a Solver object. Currently, what I can get is only an array of assertions. Thank you.
Yes, Solver.toString() does that. This should also include the variable/constant declarations if you are using the latest master; I think that part was added after the last release.
I thought I read somewhere that Z3 has some option for returning the model with the "least" value eg given something like
x >= 2
Z3 would return 2. I could swear that I saw some reference to this recently, but I am unable to find it now. Can anyone confirm this?
No, Z3 does not produce 'least' models. However, a separate branch of Z3 that adds optimization features is being developed at the moment (the branch is called `opt'), and perhaps will later be integrated into Z3 proper. A tutorial for the current optimization features is available here: Z3Opt Guide
I am trying to encode some imperative program using HORN logic of Z3 (set-logic HORN) but getting some difficulties of defining clause (using SMT2). Could anyone tell me where can I find a good source of documentations for this feature of Z3?
Well, there's more to it when it comes to "encoding" a program in horn clauses.
First you need to check an appropriate proof rule: does the program has recursive functions, should you do function summarization? and so on.
There are a few papers on the subject, but I don't think there's any tutorial on VC gen.
You may also want to take a look to some benchmarks in Horn SMT format to draw inspiration: https://svn.sosy-lab.org/software/sv-benchmarks/trunk/clauses/
Feel free to ask if you have a specific question.