An Efficient SMT Solver
OCaml API examples (Index)
Exit gracefully in case of error.
Create a logical context. Enable model construction.
Also enable tracing to stderr.
Create a variable using the given name and type.
Create a boolean variable using the given name.
Create an integer variable using the given name.
Create a Z3 integer node using a C int.
Create a real variable using the given name.
Create the unary function application: (f x) .
Create the binary function application: (f x y) .
Auxiliary function to check whether two Z3 types are equal or not.
Check whether the logical context is satisfiable, and compare the result with the expected result.
If the context is satisfiable, then display the model.
Prove that the constraints already asserted into the logical
context implies the given formula. The result of the proof is
displayed.
Z3 is a satisfiability checker. So, one can prove f by showing
that (not f) is unsatisfiable.
The context ctx is not modified by this function.
Assert the axiom: function f is injective in the i-th argument.
The following axiom is asserted into the logical context:
forall (x_1, ..., x_n) finv(f(x_1, ..., x_i, ..., x_n)) = x_i
Where, finv is a fresh function declaration.
Assert the axiom: function f is commutative.
This example uses the SMT-LIB parser to simplify the axiom construction.
Z3 does not support explicitly tuple updates. They can be easily implemented
as macros. The argument
t must have tuple type.
A tuple update is a new tuple where field
i has value
new_val , and all
other fields have the value of the respective field of
t .
update(t, i, new_val) is equivalent to
mk_tuple(proj_0(t), ..., new_val, ..., proj_n(t))
Display a symbol in the given output stream.
Display the given type.
Custom ast pretty printer.
This function demonstrates how to use the API to navigate terms.
Custom function for traversing a term and replacing the constant
'x' by the bound variable having index 'idx'.
This function illustrates how to walk Z3 terms and
reconstruct them.
*
Example abstraction function.
*
Custom function interpretations pretty printer.
Custom model pretty printer.
Similar to #check, but uses #display_model instead of #Z3_model_to_string.
Display Z3 version in the standard output.
"Hello world" example: create a Z3 logical context, and delete it.
Demonstration of how Z3 can be used to prove validity of
De Morgan's Duality Law: not(x and y) <-> (not x) or ( not y)
Find a model for x xor y .
Find a model for x < y + 1, x > 2 .
Then, assert not(x = y) , and find another model.
Prove
x = y implies g(x) = g(y) , and
disprove
x = y implies g(g(x)) = g(y) .
This function demonstrates how to create uninterpreted types and
functions.
Prove
not(g(g(x) - g(y)) = g(z)), x + z <= y <= x implies z < 0 .
Then, show that
z < -1 is not implied.
This example demonstrates how to combine uninterpreted functions and arithmetic.
Show how push & pop can be used to create "backtracking"
points.
This example also demonstrates how big numbers can be created in Z3.
Prove that f(x, y) = f(w, v) implies y = v when
f is injective in the second argument.
Prove
store(a1, i1, v1) = store(a2, i2, v2) implies (i1 = i3 or i2 = i3 or select(a1, i3) = select(a2, i3)) .
This example demonstrates how to use the array theory.
Show that
distinct(a_0, ... , a_n) is
unsatisfiable when
a_i's are arrays from boolean to
boolean and n > 4.
This example also shows how to use the distinct construct.
Simple array type construction/deconstruction example.
Simple tuple type example. It creates a tuple that is a pair of real numbers.
Simple bit-vector example. This example disproves that x - 10 <= 0 IFF x <= 10 for (32-bit) machine integers
Find x and y such that: x ^ y - 103 == x * y
Demonstrate how to use #Z3_eval.
Several logical context can be used simultaneously.
Demonstrates how error codes can be read insted of registering an error handler.
Demonstrates how Z3 exceptions can be used.
Demonstrates how to use the SMTLIB parser.
Demonstrates how to initialize the parser symbol table.
Demonstrates how to initialize the parser symbol table.
Display the declarations, assumptions and formulas in a SMT-LIB string.
Demonstrates how to handle parser errors using Z3 exceptions.
Example for creating an if-then-else expression.
Create an enumeration data type.
Several more examples of creating and using data-types (lists, trees, records)
are provided for the C-based API.
The translation from the examples in C to use the OCaml API follow the same pattern
that is used here.
Example for extracting unsatisfiable core and proof.
The example uses the function check_assumptions which allows passing in additional
hypotheses. The unsatisfiable core is a subset of these additional hypotheses.