Skip to main content

C++ API Reference

Complete reference documentation for the Z3 C++ API. All classes are in the z3 namespace.

Core Classes

z3::context

Manages all Z3 objects and global configuration. Every Z3 object is associated with a context.

Constructor

Create a new Z3 context, optionally with custom configuration. Example:

Sort Creation Methods

Create various sorts (types) for expressions. Example:

Constant Creation Methods

Create named constants of various types. Example:

Value Creation Methods

Create concrete values. Example:

Function Declaration

Declare uninterpreted functions. Example:

Configuration

Update context parameters. Example:

Parsing

Parse SMT-LIB2 format strings or files.

z3::solver

The main interface for solving constraints.

Constructor

Create a solver, optionally for a specific logic (e.g., “QF_LIA” for quantifier-free linear integer arithmetic). Example:

Adding Constraints

Add constraints to the solver. Example:

Checking Satisfiability

Check if the current set of constraints is satisfiable. Returns: z3::sat, z3::unsat, or z3::unknown Example:

Extracting Models

Retrieve a model when the constraints are satisfiable. Example:

Backtracking

Manage the assertion stack for incremental solving. Example:

Getting Information

Retrieve information about the solver state. Example:

z3::expr

Represents formulas and terms. This is the main class for building expressions.

Type Checking

Check the type and kind of expression. Example:

Getting Information

Retrieve properties of the expression. Example:

Extracting Numeral Values

Extract numeric values from numeral expressions. Example:

Application Information

Access parts of an application expression. Example:

Simplification

Simplify the expression. Example:

Substitution

Perform substitution on the expression.

z3::model

Represents a satisfying assignment (model) for a set of constraints.

Evaluating Expressions

Evaluate an expression in the model. Example:

Inspecting the Model

Iterate over the model’s assignments. Example:

Operator Overloading

The C++ API provides natural operator syntax for building expressions.

Boolean Operators

Example:

Arithmetic Operators

Example:

Comparison Operators

Example:

Bitvector Operators

Example:

Helper Functions

Quantifiers

Create quantified formulas. Example:

Array Operations

Manipulate array expressions. Example:

Other Helpers


Additional Classes

z3::config

Configuration object for context creation.

z3::params

Parameters for solvers and tactics.

z3::expr_vector

Vector of expressions.

z3::sort_vector

Vector of sorts.

Next Steps