Skip to main content

Overview

The Tactics API provides a framework for building custom solvers through composable transformations. Tactics transform goals (sets of formulas) into simpler subgoals.

Types

Z3_tactic

Basic building block for creating custom solvers for specific problem domains.

Z3_probe

Function/predicate used to inspect a goal and collect information for deciding which tactic to use.

Z3_goal

Set of formulas that can be solved or transformed using tactics.

Z3_apply_result

Collection of subgoals resulting from applying a tactic to a goal.

Tactic Creation

Z3_mk_tactic

Create a tactic by name.
Z3_tactic
Tactic object
Common Tactics:
  • "simplify" - Apply simplification rules
  • "solve-eqs" - Solve for variables
  • "smt" - Apply SMT solver
  • "qe" - Quantifier elimination
  • "sat" - SAT solver
  • "ctx-solver-simplify" - Contextual simplification
  • "purify-arith" - Purify arithmetic expressions
  • "split-clause" - Split clauses
Example:

Z3_tactic_inc_ref

Increment the reference counter of a tactic.

Z3_tactic_dec_ref

Decrement the reference counter of a tactic.

Tactic Combinators

Z3_tactic_and_then

Create a tactic that applies t1 followed by t2.
Z3_tactic
Sequential composition tactic
Example:

Z3_tactic_or_else

Create a tactic that tries t1, and if it fails, tries t2.
Z3_tactic
Or-else combinator

Z3_tactic_par_or

Create a tactic that applies tactics in parallel, returning the first result.
Z3_tactic
Parallel-or combinator

Z3_tactic_par_and_then

Create a tactic that applies t1 to the goal and t2 to subgoals in parallel.
Z3_tactic
Parallel composition

Z3_tactic_try_for

Create a tactic that applies t with a time limit.
Z3_tactic
Tactic with timeout
Example:

Z3_tactic_repeat

Create a tactic that repeatedly applies t until fixpoint or max iterations.
Z3_tactic
Repeat combinator

Z3_tactic_when

Create a tactic that applies t only when probe p evaluates to true.
Z3_tactic
Conditional tactic

Z3_tactic_cond

Create a tactic that applies t1 if probe p is true, otherwise t2.
Z3_tactic
If-then-else tactic
Example:

Probes

Z3_mk_probe

Create a probe by name.
Z3_probe
Probe object
Common Probes:
  • "is-qflia" - Linear integer arithmetic
  • "is-qfbv" - Bit-vectors
  • "is-propositional" - Pure Boolean
  • "num-consts" - Number of constants
  • "size" - Goal size
  • "depth" - Expression depth
Example:

Z3_probe_inc_ref

Increment reference counter of a probe.

Z3_probe_dec_ref

Decrement reference counter of a probe.

Goals

Z3_mk_goal

Create a goal (collection of formulas).
Z3_goal
Goal object
Example:

Z3_goal_assert

Add a formula to the goal.

Z3_tactic_apply

Apply a tactic to a goal.
Z3_apply_result
Result containing subgoals

Z3_apply_result_get_num_subgoals

Return the number of subgoals in the result.
unsigned
Number of subgoals

Z3_apply_result_get_subgoal

Return the i-th subgoal.
Z3_goal
Subgoal

Complete Example