Skip to main content
The Z3 C API is the foundational interface to Z3. All other language bindings are built on top of it.

Core Types

The Z3 C API uses opaque pointer types for all objects:

Fundamental Types

opaque pointer
Configuration object used to initialize contexts. Set parameters before creating a context.
opaque pointer
Manager of all Z3 objects. Required for all API calls. Stores global configuration and manages memory.
opaque pointer
Lisp-like symbol used to name types, constants, and functions. Can be created from strings or integers.
opaque pointer
Abstract syntax tree node representing terms, formulas, and types. Base type for all expressions.
opaque pointer
Kind of AST representing types (Int, Real, Bool, etc.).
opaque pointer
Function declaration (symbol with signature).
opaque pointer
Function application (function symbol applied to arguments).

Solver Types

opaque pointer
Incremental solver for checking satisfiability of formulas.
opaque pointer
Model (satisfying assignment) for satisfiable formulas.
opaque pointer
Parameter set for configuring solvers, tactics, and other components.

Advanced Types

opaque pointer
Building block for custom solvers.
opaque pointer
Set of formulas that can be solved or transformed.
opaque pointer
Context for the recursive predicate solver (Datalog engine).
opaque pointer
Context for solving optimization queries (maximize/minimize).

Enumerations

Z3_lbool

Lifted Boolean type for satisfiability results:

Z3_sort_kind

The different kinds of sorts (types):

Context Management

Creating Contexts

function
Create a configuration object. Use Z3_set_param_value to set parameters.
function
Delete configuration object. Call after creating context.
function
Set a configuration parameter. Common parameters:
  • "model": "true" to enable model generation
  • "proof": "true" to enable proof generation
  • "timeout": milliseconds (e.g., "1000")
function
Create a context using the given configuration.
function
Delete context and all associated objects.

Version Information

function
Get Z3 version numbers.

Symbols

function
Create a symbol from a string.
function
Create a symbol from an integer.

Sorts (Types)

Basic Sorts

function
Create Boolean sort.
function
Create integer sort.
function
Create real sort.
function
Create bit-vector sort of size sz.

Array Sorts

function
Create array sort (maps from domain to range).

Constants and Variables

function
Create a constant (0-arity function) with given symbol and type.
function
Create an integer numeral.
function
Create a real numeral num/den.

Boolean Operations

function
Create the true constant.
function
Create the false constant.
function
Create NOT expression.
function
Create n-ary AND expression.
function
Create n-ary OR expression.
function
Create implication t1 => t2.
function
Create bi-implication (equivalence) t1 <=> t2.

Arithmetic Operations

function
Create n-ary addition.
function
Create n-ary subtraction.
function
Create n-ary multiplication.
function
Create division (real division or integer division).
function
Create modulo operation.

Comparison Operations

function
Create equality l = r.
function
Create distinct constraint (all arguments pairwise different).
function
Create less-than t1 < t2.
function
Create less-than-or-equal t1 <= t2.
function
Create greater-than t1 > t2.
function
Create greater-than-or-equal t1 >= t2.

Solver API

Creating Solvers

function
Create a new solver instance.
function
Increment solver reference count.
function
Decrement solver reference count.

Adding Constraints

function
Assert constraint to the solver.
function
Create a backtracking point (save state).
function
Backtrack n scopes.

Checking Satisfiability

function
Check satisfiability of assertions. Returns Z3_L_TRUE, Z3_L_FALSE, or Z3_L_UNDEF.
function
Check satisfiability under given assumptions.

Getting Results

function
Get model for last satisfiable check. Requires "model" parameter to be "true".
function
Get proof for last unsatisfiable check. Requires "proof" parameter to be "true".
function
Get unsat core (subset of assertions that are unsatisfiable).

Model API

function
Increment model reference count.
function
Decrement model reference count.
function
Evaluate expression t in model m. Result stored in v.

String Conversion

function
Convert AST to string (S-expression format).
function
Convert solver state to string.
function
Convert model to string.

SMT-LIB Parsing

function
Parse SMT-LIB2 string with custom sorts and declarations.

Resources

Full C API Documentation

Official Z3 C API reference

C Examples

Complete examples in the Z3 repository

Header File

Browse the z3.h header file

Getting Started

Learn the basics of the C API