Translating from Z3Py to SMT-LIB - z3

Please let me know how to translate the following line from Z3Py to SMT-LIB:
def _to_octonion(a):
if isinstance(a, OctonionExpr):
return a
else:
return OctonionExpr(a, RealVal(0), RealVal(0), RealVal(0), RealVal(0), RealVal(0),
RealVal(0), RealVal(0))
Many thanks

The short answer is: it can't be done.
Z3Py is the Z3 API on top of Python (a programming language that contains a bunch of conveniences for users). On the other hand, SMT-LIB 2.0 is a formula exchange format, and is very limited. SMT-LIB 2.0 files are usually generated by other programs that need to interact with SMT solvers.
Note that the function above does not even "type-check" in the SMT-LIB 2.0 format.
The input can be an OctonionExpr or "anything else" and the output is an OctonionExpr (or an exception).

Related

dafny corresponding SMT queries

I'm trying to inspect a simple looping program that finds the maximal element in an integer array. Here is the permalink here. Everything works fine, but I'm really interested in
the resulting SMT file, so I extracted it using:
$ dafny /compile:3 /proverLog:./mySMT.smt myCode.dfy
Then ran with z3 as follows:
$ z3 ./mySMT.smt
I got 3 unsat responses and I was wondering what are the corresponding 3 queries?
I looked at the *.smt file and found 11K of machine-generated SMT.
Any tips on deciphering the smt file? thanks!
If you want the resulting SMT file, then that 11K file is your answer. I imagine that looking at it will lead you to the conclusion that you don't actually want to look at the resulting SMT file.
So, I don't know what it is that you want to accomplish. If you want to learn more about your program, then the best way is to work (only) from the Dafny program text. For example, you can add more assert statements to, essentially, ask the verifier if the given condition is provable at the location of the statement.
If you're interested in how Dafny encodes its verification conditions (that is, if you yourself are a tool developer and want to learn how to generate good verification conditions), then I suggest you use the /print switch to generate the Boogie program that Dafny generates. With some understanding of the Boogie intermediate verification language, the Boogie code is readable. For a more tutorial account of how to encode a Dafny-like language into Boogie, I recommend:
"Specification and verification of object-oriented software",
K. Rustan M. Leino.
Lecture note, Marktoberdorf 2008.
Rustan
PS. Unless you insist on particular formatting, you can print your array elements without using a loop if you first convert the array's element to a sequence:
print "a = ", a[..], "\n";

Microsoft Z3 - How to use tactic combinators in the C# API

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.

Which logics are supported by z3?

Is there a complete listing of all theories/logics that z3 supports? I have consulted this SMTLIB Tutorial which provides a number of logics, but I do not believe that the list is exhaustive. The z3 documentation itself doesn't seem to specify which logics are supported.
I ask because I have an smt file which cannot be solved under any of the logics in the SMTLIB Tutorial (when specified with 'set-logic'), but can be solved when no logic is specified.
For Z3, I have not seen such a list in the documentation, but you can find it in the source code if you really want to know. The list starts around line 65 of check_logic.cpp. I parsed out the list for you using a scary awk one-liner, and found this as of May 20, 2016 (between Z3 4.4.1 and 4.4.2):
"AUFLIA", "AUFLIRA", "AUFNIRA", "LRA", "QF_ABV", "QF_AUFBV", "QF_UFBV", "QF_AUFLIA", "QF_AX", "QF_BV", "QF_IDL", "QF_RDL", "QF_LIA", "QF_LRA", "QF_NIA", "QF_NRA", "QF_UF", "QF_UFIDL", "QF_UFLIA", "QF_UFLRA", "QF_UFNRA", "UFLRA", "UFNIA", "UFBV", "QF_S"
You can compare this to the official list of SMT-LIB 2 logics.
Probably more importantly for you is what the "best logic" is for your application. It sounds like you have a large and varying set of problems that you want Z3 to apply whatever tactics it can to. In that case, for now, it's best to leave the logic unspecified. The problem is that in SMT-LIB v2.0 there was no all-encompassing logic -- the largest logic by some standards was AUFNIRA, but this does not include, for example, bit vectors. As a result, CVC4 introduced a non-standard ALL_SUPPORTED logic, and Z3 performs best for some classes of problems when no logic is specified. This shortcoming of the SMT-LIB 2.0 standard is addressed in SMT-LIB 2.5, with a new logic called "ALL". However, this is not yet supported by either Z3 or CVC4.
You specify a logic in Z3 to ensure that Z3 uses a particular strategy and engine that is typically useful for the class of formulas expressed in this logic.
If no logic is specified, then Z3 falls back to a default mode. There is no logic corresponding to
this default mode: it integrates multiple engines.

C API Parametric datatypes, how?

i'm using Z3 for my phd thesis. In a first attempt i just used the smtlibparse function for convenience since i had my formulas converted to smtlib format.
Now I wanted to use the api, since converting formulas to smtlib formated strings, and then parse them with z3 is a bit cumbersome and has slow performance.
I started to look at the api and I couldn't found how I can define parametric datatypes like this one
(declare-datatypes (T) ((Ref (mk-ref (inner T)))))
I would appreciate your help,

how do i invoke Z3 Programmatically

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).

Resources