Skip to main content

Overview

The Solver API provides an incremental interface for solving satisfiability problems. Solvers support assertions, backtracking (push/pop), and extracting models and unsat cores.

Types

Z3_solver

Incremental solver object that can be specialized by tactics or logics.

Solver Creation

Z3_mk_solver

Create a general-purpose solver.
Z3_solver
New solver instance
Description: Creates a solver using the default SMT solver with strategic preprocessing. Example:

Z3_mk_simple_solver

Create a simple solver without strategic preprocessing.
Z3_solver
New simple solver instance
Description: Faster startup but may be less efficient on complex problems.

Z3_mk_solver_for_logic

Create a solver optimized for a specific logic.
Z3_solver
New solver instance
Example:

Z3_mk_solver_from_tactic

Create a solver from a tactic.
Z3_solver
Solver based on tactic

Reference Counting

Z3_solver_inc_ref

Increment the reference counter of the solver.

Z3_solver_dec_ref

Decrement the reference counter of the solver.

Assertions

Z3_solver_assert

Assert a constraint into the solver. Example:

Z3_solver_assert_and_track

Assert a constraint with a tracking literal. Description: The tracking literal allows identification of assertions in unsat cores. Example:

Satisfiability Checking

Z3_solver_check

Check if the current set of assertions is satisfiable.
Z3_lbool
Z3_L_TRUE if satisfiable, Z3_L_FALSE if unsatisfiable, Z3_L_UNDEF if unknown
Example:

Z3_solver_check_assumptions

Check satisfiability under given assumptions.
Z3_lbool
Satisfiability result
Description: Assumptions are temporary constraints only active for this check call. Example:

Models

Z3_solver_get_model

Retrieve the model for the last check (if satisfiable).
Z3_model
Model object (must increment reference)
Note: Model must be kept alive with Z3_model_inc_ref.

Unsat Cores

Z3_solver_get_unsat_core

Retrieve the unsat core from the last check (if unsatisfiable).
Z3_ast_vector
Subset of asserted constraints that are unsatisfiable
Requirements:
  • Context must be created with unsat_core enabled
  • Assertions must be tracked using Z3_solver_assert_and_track
Example:

Backtracking

Z3_solver_push

Create a backtracking point. Description: Saves the current state. Assertions added after push can be removed with pop.

Z3_solver_pop

Backtrack n backtracking points. Example:

Z3_solver_reset

Remove all assertions from the solver.

Solver Information

Z3_solver_get_num_scopes

Return the number of backtracking points.
unsigned
Number of scopes

Z3_solver_get_assertions

Return the set of asserted formulas.
Z3_ast_vector
Vector of assertions

Z3_solver_get_reason_unknown

Return a string describing why the last check returned unknown.
Z3_string
Reason string

Z3_solver_to_string

Convert solver state to a string (SMT-LIB format).
Z3_string
String representation

Complete Example