Lisp-Z3 Documentation

Sorts

Enums

An enum sort consists of a finite set of elements, specified when the enum is registered.

The following line defines an enum sort with the name :bar and the elements a, b, and c. (register-enum-sort :bar (a b c))

A constant enum element can be expressed using (enumval <ty> <el>). For example, the following statement asserts that q is equal to the :bar element a.

(z3-assert (q :bar)
           (= q (enumval :bar a)))

Named tuples

A named tuple sort consists of a set of fields, each of which has a name and a sort.

The following line defines a tuple sort with two fields, name (which is a string) and age (which is an integer).

(register-tuple-sort :dog
  ((name . :string)
   (age  . :int)))

Values of this sort can be constructed using (tuple-val <tuple-name> <field1> ... <fieldn>), where tuple-name is the registered name of the tuple sort and the fields must be provided in the same order as they appeared in the register-tuple-sort form.

For example, the following statement asserts that the :dog value x is equal to the given constant :dog value:

(z3-assert (x :dog)
           (= x (tuple-val :dog "Toto" 5)))

The value of a field can be accessed using (tuple-get <tuple-name> <field-name> <val>), where tuple-name is the registered name of the tuple sort, field-name is the name of one of the fields of the tuple sort, and val is a value of the tuple sort.

For example, the following statement asserts that the name of the :dog value x is equal to name, and the age of x is greater than 3.

(z3-assert (x :dog name :string)
           (and (= (tuple-get :dog name x) name)
                (> (tuple-get :dog age x) 3)))

Functions

Names in parentheses after a function call denote alternative names for the same function.

Propositional Logic

Arithmetic

Typically, functions with arity greater than unary require both arguments to be of the same sort. This is not an issue at the moment, as the interface currently does not support any numeric sorts aside from integers.

Note that operations that may cause exceptions in other languages (like division by zero) are underspecified in Z3. This means that Z3 treats (/ x 0) as an uninterpreted function that it may assign any interpretation to. This can lead to unexpected behavior if you're not careful.

For example, Z3 reports that the following is satisfiable, since it can assign x and y different values, and has the flexibility to have division by 0 for the value of x return 3, and division by 0 for the value of y return 4.

(z3-assert (x :int y :int)
           (and (= (/ x 0) 3)
                (= (/ y 0) 4)))
(check-sat)

Function Application

Quantifiers

Bitvectors

TODO

Sequences

Most of these functions operate on both strings and sequences (since strings are essentially just a special case of sequences).

Conversions

Regular expressions

TODO

Sets

Note that the translation of set values reported by Z3 is not currently supported.

Arrays

TODO