Lab for Automated Reasoning and Analysis LARA

Examples of Using Z3 with Scala

Compiling and running the following examples requires that you obtain z3.jar, libz3.so (from Microsoft Research), and use Scala 2.8. The best way to figure out which functions to use is probably to read through the C API once, then through the Scala API, then looking at examples, and finally, contacting us.

Testing your setup

*nix Systems

Once you have the required files, try our your setup with the Scala interpreter. Note that you have to make sure that libz3.so is in the dynamically-loaded library path (LD_LIBRARY_PATH in Unix-like systems). You can run scala as follows:

LD_LIBRARY_PATH=${Z3_LIB_PATH} scala -classpath scalaz3.jar

where ${Z3_LIB_PATH} is the directory where you keep libz3.so. (Alternatively, export LD_LIBRARY_PATH once and for all.) Then, try the following:

Note that Z3 does not say sat, because of the universally-quantified axiom (it would have to build an infinite model, to be “really sure”). It gives a candidate model, though. The candidate model does not satisfy the universal axiom (because in its interpretation, fib(6) = 1, for instance), but note that it's enough to get you the result that you wanted (fib is correct up to the required value).

Using Algebraic Data Types

More to come later. Contact us if you're can't wait and/or figure it out by looking at the API.

Writing Theory Plugins

More to come later. Contact us if you're can't wait and/or figure it out by looking at the API.