query in .datalog input format of Z3 - z3

Bddbddb supports queries of the form "Gt("a", "d")?". I added this query to the end of the example datalog program given in fixedpoints Z3 doc under the section "Basic datalog", and ran both bddbddb and Z3. Z3 does not seem to support such syntax. Is there another syntax to query in the ".datalog" input format of Z3?

Related

QnA task for Z3. Is it possible?

I'm trying to solve a question answering task. There are several approaches to this like Deep Learning methods, querying Knowledge Graphs, Semantic Search etc. But I thought if it would be possible to use Z3 theorem prover for that task as well? For example, if we can present knowledge as a set of axioms, each axiom consists of the predicates (relations), subjects and objects and is expressed in FOL clauses, then we can traverse through them and find an answer to the query (which can be expressed as axiom as well). For example, I can encode a simple knowledge "English is language" in FOL clause:
exists l.(language(l) & exists n.(name(n) & :op1(n,"English") & :name(l,n)))
How can I translate it into Z3? And how can I extract an answer to the query "{unknown} is language" to find an {unknown} variable or clause? Note that the {unknown} can be anything. It can be an atom or logical clause depending on the match with the query.
I don't think an SMT solver is very suitable for this task. Not because you can't do it using z3, but a system like Prolog or a custom-program you build will work just as fine as well. SMT solvers shine when you have combination of theories (numbers, arithmetic, arrays, data-structures, etc.); for your problem domain, all you need is a Prolog like simple-database and a query engine.
Encoding your suggested statement really depends on what sort of predicates you have in mind. Note that SMTLib is a "typed" language; so a predicate like language(l) is redundant: You'd have a value of the type language only when that call type-checks; i.e., you can't pass the predicate language anything that's not a language anyways. (This is similar to programming in a typed-language like Haskell/O'Caml etc., vs. in a dynamically typed language like Lisp/Scheme/Python etc.)
See Solving predicate calculus problems with Z3 SMT for an example of how to use an SMT solver to deal with first-order-logic modeling problems.

acyclic relation in bddbddb

I'm using Z3 to evaluate datalog programmes write using the bddbddb format (http://bddbddb.sourceforge.net/).
How to express the fact that a relation is acyclic in bddbddb format ?
I mean a rule such this one in datalog
:- rel(X,Y), rel(Y,X).

Convert SMT-LIBv2 QF_AUFBV to CNF DIMACS format using Z3

Can I convert an input file having SMT-LIBv2 format and containing set-logic QF_AUFBV, to CNF? If so, how can I use the Z3 command line unility to do it?
UPDATE: I also need the mapping of the variables from th SMT-LIBv2 instance to the CNF DIMACS file as comments. Is that possible using Z3?
QF_AUFBV contains both arrays and uninterpreted functions. I don't think CNF DIMACS understands any of that.
From the programmatic API, you can apply the tactics that convert formulas to CNF. Then you can walk those formulas and pretty print them in any form you like. The Z3 source code also contains a few places where we dump intermediary results into DIMACS, but we don't expose ready to use features for this (but you can always compile your own version of Z3 for this need, e.g., use the "goal::display_dimacs" utility.

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

how to convert z3 expression to infix expression?

I want to translate boolExpression in Z3 into infix representation. For example, there is a z3 expression (>= t 3), I want to get the infix string "t>=3", is any existing Z3 api to implement it in C# ?
No, the official API does not have support for displaying expressions in infix notation. This functionality can be implemented on top of the API for traversing expressions. The Z3 Python API implements an infix printer. Actually, it implements two: one for Python-like syntax, and one for HTML math-like syntax. The source code of these printers is included in the Z3 distribution. The code is written in python, but can be easily converted into any programming language. The code is located at python\z3printer.py.

Resources