How to construct a Z3 solver from a Query in txt - z3

I am in a situation where I have a bunch of Z3(bitvector) queries already in txt format. Is there a way to create a solver and a context through some API by reading in those queries? I am more of a java programmer, so I'd be in favor of some Java API, but c and python should be fine as well.
Much appreciated! Thanks!

Assuming those queries are in SMTLib format, you're looking for:
C: Z3_solver_from_string
Python: parse_smt2_string
Java: fromString
In the reverse direction:
C: Z3_solver_to_string
Python: sexpr
Java: toString

Related

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.

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,

Z3 Java API: FuncDecl and Expr

I have an existing smt2 file, and used z3 java api parsed this and solved the problem. But I have a question about how to cast a FuncDecl to an Expr because I want to build some simple formula by using z3 java apis. Since my original formulas is purely written in smt2 text file and everything gets parsed into a single BoolExpr. Now, I successfully extracted the consts, and need to manipulate them with new formula. How can i do it? Basically, what I am looking for is how to build an Expr from FuncDecl Or is there a way I can cast it to Expr? Is there any official java api document available? I know there is an example of using z3 java api, but it's pretty painful to look for a specific api description in such a large example.
FuncDecl's are function declarations, they can not be cast directly to expressions, but the function they represent can be applied (to some arguments) to yield an expression. This is what FuncDecl.apply(...) does. Constants are of course a special case, where the function doesn't take any arguments.

Convert an Elixir AST to an Erlang AST? Is it possible?

Is it possible to take a quoted Elixir expression (AST tree) like this:
quote do: 1 + 1
=> {:+, [context: Elixir, import: Kernel], [1, 1]}
And convert it to an Erlang AST?
I looked through the Code module as well as some of the Kernel modules looking for a function that did this but I didn't find anything. I am not even sure if this would be possible... I don't know how things like Elixir macros would be represented in Erlang AST.
Thanks in advance!
There isn't currently a public API to do so. You could look into the elixir module to know how it is done but it is private API and it can be changed any time with no guarantee of compatibility, or even removed.
For example I wrote 'gist' how it can be done - https://gist.github.com/habibutsu/bc6791d3d81b6ea54e1a
There are used two functions:
fun elixir:'string_to_quoted!'/4
fun elixir:quoted_to_erl/3

Translating from Z3Py to SMT-LIB

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

Resources