API reference

Pythonic API Reference (Z3 5.3.3)

Everything in this page is re-exported at the package root (from z3_mojo import ...). It mirrors official z3-solver 5.3.3 (z3.z3) with 378 free functions, builders, and callback helpers, operator overloading on Ast, Probe, and RcfNum, and Pythonic methods on every core class. For direct 1-to-1 Context.mk_* and handle methods, see Safe Handle & Context API; for the raw C bindings, see Low-Level C API.

Quick Start: Most-Used Symbols

Task Everyday symbols
Variables & functions IntVar, Real, BoolVar, BitVec, StringVar, Function
Formulas & logic Eq, Ne, And, Or, Not, Implies, If, ForAll, Exists
Solving & proving Solver, Model, prove, solve · sat / unsat / unknown
Optimization Optimize
Arrays & sets Select, Store, K, Lambda, EmptySet, SetUnion
Strings & regex Length, Concat, Re, Range, InRe
BitVectors & FPA BitVecVal, ULE, BVAddNoOverflow, Float32Sort, FP, fpAdd
Datatypes & callbacks Datatype, EnumSort, UserPropagator, OnClause

Result Constants & Operators

  • Check results: sat, unsat, unknown (CheckResult values, matching z3.sat / z3.unsat / z3.unknown, plus .is_sat(), .is_unsat(), .is_unknown()).
  • Ast operators: +, -, *, /, //, %, **, unary -, &, |, ^, ~, <<, >>, <, <=, >, >=, and array indexing arr[i] (with automatic coercion of Int, apn_mojo.Integer, apn_mojo.Rational, Bool, and String literals). Structural equality stays == (Equatable); build Z3 formulas with Eq(a, b) / a.eq(b) and Ne(a, b) / a.ne(b).
  • Probe operators: <, <=, >, >=, &, |, ~ (with Float64 / Int thresholds).
  • RcfNum operators: +, -, *, /, **, unary -, <, <=, >, >=.
  • Callable & indexable handles: f(x, y) (FuncDecl.__call__), m[x] (Model.__getitem__), len(g) / g[i] (Goal.__len__ / __getitem__).
from z3_mojo import Context, IntVar, Eq, Solver, sat
var ctx = Context()
var x = IntVar("x", ctx)
var s = Solver(ctx)
s.add(x > 0, Eq(x * x, 49))
if s.check() == sat:
    print("x =", s.model()[x].value())

Safe Callback Traits (UserPropagator, ClauseHandler, ModelHandler)

Attach callbacks with Solver.set_propagator, Solver.register_on_clause / OnClause, and Optimize.set_on_model. Callback state is heap-pinned for the lifetime of the Solver or Optimize handle, and any Mojo Error raised inside a callback is captured safely and re-raised when check() returns. See the Callbacks guide.

var s = SimpleSolver(ctx)
var prop = ArcPointer(MyPropagator())
s.set_propagator(prop, fixed=True)
s.propagate_register(p)

UserPropagator

Trait for Z3 custom theory propagators (Solver.set_propagator).

Override only the callbacks you enable when attaching the propagator. Errors raised inside any callback are captured safely and re-raised when Solver.check() returns.

UserPropagator.push

def push(mut self) raises

Called when Z3 pushes a new search scope.

UserPropagator.pop

def pop(mut self, num_scopes: Int) raises

Called when Z3 pops num_scopes search scopes.

UserPropagator.on_fresh

def on_fresh(mut self, new_ctx: Context) raises

Called if Z3 spawns an internal sub-solver with a fresh Context.

UserPropagator.fixed

def fixed(mut self, cb: SolverCallback, term: Ast, value: Ast) raises

Called when a registered Boolean or BitVector term is fixed to value.

UserPropagator.final

def final(mut self, cb: SolverCallback) raises

Called on final check when all decision variables are assigned.

UserPropagator.eq

def eq(mut self, cb: SolverCallback, lhs: Ast, rhs: Ast) raises

Called when two registered terms become equal in the current state.

UserPropagator.diseq

def diseq(mut self, cb: SolverCallback, lhs: Ast, rhs: Ast) raises

Called when two registered terms become disequal in the current state.

UserPropagator.created

def created(mut self, cb: SolverCallback, term: Ast) raises

Called when Z3 creates a term headed by a PropagateFunction.

UserPropagator.decide

def decide(mut self, cb: SolverCallback, term: Ast, bit_index: Int, phase: Bool) raises

Called before Z3 splits on term (override via cb.next_split(...)).

UserPropagator.on_binding

def on_binding(mut self, cb: SolverCallback, quantifier: Ast, instance: Ast) raises -> Bool

Called when Z3 instantiates quantifier with instance; return False to block.

ClauseHandler

Trait for Z3 CDCL(T) clause callbacks (Solver.register_on_clause / OnClause).

ClauseHandler.on_clause

def on_clause(mut self, proof_hint: Optional[Ast], deps: List[Int], literals: List[Ast]) raises

Called when Z3 asserts, derives, or deletes a clause.

ModelHandler

Trait for Z3 Optimize improving-model callbacks (Optimize.set_on_model).

ModelHandler.on_model

def on_model(mut self, model: Model) raises

Called whenever Optimize discovers an improved model (borrowed for callback duration).

SolverCallback

Borrowed handle passed by Z3 inside user-propagator callbacks.

SolverCallback.ctx

def ctx(self) -> Context

Return the Context associated with this callback.

SolverCallback.add

def add(self, expr: Ast) raises

Dynamically register expr for propagation during a callback (Z3_solver_propagate_register_cb).

SolverCallback.propagate

def propagate(self, conseq: Ast, deps: List[Ast]) raises -> Bool
def propagate(self, conseq: Ast, deps: List[Ast], eq_lhs: List[Ast], eq_rhs: List[Ast]) raises -> Bool

Propagate conseq justified by fixed terms deps and equalities eq_lhs[i] == eq_rhs[i].

SolverCallback.conflict

def conflict(self, deps: List[Ast]) raises -> Bool
def conflict(self, deps: List[Ast], eq_lhs: List[Ast], eq_rhs: List[Ast]) raises -> Bool

Report a theory conflict justified by fixed terms deps and equalities eq_lhs[i] == eq_rhs[i].

SolverCallback.next_split

def next_split(self, term: Ast, idx: Int = 0, phase: Lbool = Lbool.UNDEF) raises -> Bool

Guide the solver's next decision on term (bit idx, preferred phase).

SolverCallback.consequence

def consequence(self, fixed: List[Ast], eq_lhs: List[Ast], eq_rhs: List[Ast], conseq: Ast) raises -> Bool

Propagate a consequence based on fixed values and equalities. A client may invoke it during the propagate_fixed, propagate_eq, propagate_diseq, and propagate_final callbacks. The callback adds a propagation consequence based on the fixed values passed in fixed and equalities between eq_lhs and eq_rhs. Wraps Z3_solver_propagate_consequence.

SolverCallback.register_cb

def register_cb(self, e: Ast) raises

Register an expression to propagate on with the solver. Only expressions of type Bool and type Bit-Vector can be registered for propagation. Unlike Z3_solver_propagate_register, this function takes a solver callback context as argument. It can be invoked during a callback to register new expressions. Wraps Z3_solver_propagate_register_cb.

Pythonic Methods on Core Classes

In addition to the 1-to-1 Z3 C-API methods listed in Safe Handle & Context API, each core handle struct provides Python Z3 constructors, aliases, operators, and inspection methods.

Solver

See also the full 1-to-1 handle reference in Solver (Safe Handle API).

var ctx = Context()
var s = Solver(ctx)
var x = IntVar("x", ctx)
s.add(x > 0, x < 10)
if s.check() == sat:
    print(s.model()[x].value())

Solver.from_tactic

def from_tactic(ctx: Context, tactic_name: String) raises -> Solver

Create a solver directly from a named Z3 tactic (e.g. 'qfnra-nlsat').

Solver.set_param_uint

def set_param_uint(self, key: String, val: Int) raises

Set an unsigned-integer solver parameter key to val.

Solver.set_param_bool

def set_param_bool(self, key: String, val: Bool) raises

Set a Boolean solver parameter key to val.

Solver.set_timeout_ms

def set_timeout_ms(self, ms: Int) raises

Set the solver timeout in milliseconds.

Solver.set_rlimit

def set_rlimit(self, limit: Int) raises

Set the deterministic solver resource limit (rlimit).

Solver.set_seed

def set_seed(self, seed: Int) raises

Set the solver random seed (seed for tactic solvers, random_seed otherwise).

Solver.set_unsat_core

def set_unsat_core(self, enable: Bool = True) raises

Enable or disable unsatisfiable-core generation on this solver.

Solver.add

def add(self, *formulas: Ast) raises
def add(self, formulas: List[Ast]) raises

Assert one or more formulas into this solver.

Solver.check

def check(self) raises -> CheckResult

Check satisfiability of the asserted formulas and return sat, unsat, or unknown (Z3_solver_check).

Solver.check_assumptions

def check_assumptions(self, assumptions: List[Ast]) raises -> CheckResult

Check satisfiability under temporary Boolean assumptions (Z3_solver_check_assumptions).

Solver.set_propagator

def set_propagator[P: UserPropagator](self, propagator: ArcPointer[P], *, fixed: Bool = False, final: Bool = False, eq: Bool = False, diseq: Bool = False, created: Bool = False, decide: Bool = False, on_binding: Bool = False,) raises

Attach a UserPropagator to this solver and register the selected Z3 callbacks.

Solver.register_on_clause

def register_on_clause[H: ClauseHandler](self, handler: ArcPointer[H]) raises

Register a ClauseHandler called on asserted, inferred, and deleted CDCL(T) clauses (Z3_solver_register_on_clause).

Solver.on_clause

def on_clause[H: ClauseHandler](self, handler: ArcPointer[H]) raises

Alias for register_on_clause(handler).

Solver.model

def model(self) raises -> Model

Return the current satisfying Model, raising if none is available.

Solver.unsat_core

def unsat_core(self) raises -> List[Ast]

Python Z3 alias for get_unsat_core().

Solver.to_smt2

def to_smt2(self) raises -> String

Python Z3 alias for to_string() (SMT-LIB2 format).

Solver.sexpr

def sexpr(self) raises -> String

Python Z3 alias for to_string().

Solver.dimacs

def dimacs(self, include_names: Bool = True) raises -> String

Return DIMACS CNF representation of the solver's assertions.

Solver.help

def help(self) raises -> String

Return Z3 parameter help text for Solver.

Solver.param_descrs

def param_descrs(self) raises -> ParamDescrs

Return parameter descriptions (ParamDescrs) for Solver.

Solver.num_scopes

def num_scopes(self) raises -> Int

Return the number of active push() scopes.

Solver.units

def units(self) raises -> List[Ast]

Return unit literals derived by the solver.

Solver.non_units

def non_units(self) raises -> List[Ast]

Return non-unit clauses in the solver.

Solver.trail

def trail(self) raises -> List[Ast]

Return the current decision/propagation trail.

Solver.trail_levels

def trail_levels(self) raises -> List[UInt32]

Return decision levels corresponding to trail().

Solver.assert_exprs

def assert_exprs(self, *formulas: Ast) raises
def assert_exprs(self, formulas: List[Ast]) raises

Python Z3 alias for add(*formulas).

Solver.append

def append(self, *formulas: Ast) raises

Alias for add(*formulas) asserting formulas into this solver.

Solver.insert

def insert(self, *formulas: Ast) raises

Alias for add(*formulas) asserting formulas into this solver.

Solver.solutions

def solutions(self, term: Ast, max_solutions: Int = 1000) raises -> List[Ast]
def solutions(self, terms: List[Ast], max_solutions: Int = 1000) raises -> List[List[Ast]]

Enumerate up to max_solutions distinct satisfying tuples for terms.

Solver.set

def set(self, key: String, val: Bool) raises
def set(self, key: String, val: Int) raises
All 4 overloads
def set(self, key: String, val: Bool) raises
def set(self, key: String, val: Int) raises
def set(self, key: String, val: Float64) raises
def set(self, key: String, val: String) raises

Set an unsigned-integer solver parameter (Python Z3 s.set(key, val)).

Solver.proof

def proof(self) raises -> Optional[Ast]

Return the unsatisfiability proof AST if proof generation was enabled via Config.

Solver.statistics

def statistics(self) raises -> Stats

Return solver statistics for this solver.

Solver.consequences

def consequences(self, assumptions: List[Ast], variables: List[Ast]) raises -> Tuple[CheckResult, List[Ast]]

Compute implied equations/values for variables under assumptions.

Solver.cube_vars

def cube_vars(self, vars: List[Ast], backtrack_level: Int = 0) raises -> List[Ast]

Generate a cube for cube-and-conquer partitioning over vars.

Optimize

See also the full 1-to-1 handle reference in Optimize (Safe Handle API).

var opt = Optimize(ctx)
var x = IntVar("x", ctx)
opt.add(x >= 0, x <= 10)
var obj = opt.maximize(x)
if opt.check() == sat:
    print("max =", opt.upper(obj))

Optimize.__init__

def __init__(out self, ctx: Context) raises

Create a new Z3 Optimize solver.

Optimize.set_on_model

def set_on_model[H: ModelHandler](self, handler: ArcPointer[H]) raises

Register a ModelHandler called whenever optimization finds an improving model (Z3_optimize_register_model_eh).

Optimize.set_timeout_ms

def set_timeout_ms(self, ms: Int) raises

Set the optimizer timeout in milliseconds.

Optimize.add

def add(self, *formulas: Ast) raises
def add(self, formulas: List[Ast]) raises

Assert one or more hard constraints into this optimizer.

Optimize.check

def check(self) raises -> CheckResult

Solve the constraints and objectives and return sat, unsat, or unknown (Z3_optimize_check).

Optimize.model

def model(self) raises -> Model

Return the current satisfying Model, raising if none is available.

Optimize.sexpr

def sexpr(self) raises -> String

Return the SMT-LIB2 string representation of this optimizer.

Optimize.assert_exprs

def assert_exprs(self, *formulas: Ast) raises
def assert_exprs(self, formulas: List[Ast]) raises

Python Z3 alias for add(*formulas).

Optimize.append

def append(self, *formulas: Ast) raises

Alias for add(*formulas) asserting hard constraints into this optimizer.

Optimize.insert

def insert(self, *formulas: Ast) raises

Alias for add(*formulas) asserting hard constraints into this optimizer.

Optimize.add_soft

def add_soft(self, formula: Ast, weight: String = "1", id: String = "") raises -> Int
def add_soft(self, formula: Ast, weight: Int, id: String = "") raises -> Int

Python Z3 alias for assert_soft(formula, weight, id).

Optimize.lower

def lower(self, handle: Int) raises -> Ast

Python Z3 alias for get_lower(handle).

Optimize.upper

def upper(self, handle: Int) raises -> Ast

Python Z3 alias for get_upper(handle).

Optimize.lower_values

def lower_values(self, handle: Int) raises -> List[Ast]

Return (inf, val, eps) lower-bound vector for objective handle.

Optimize.upper_values

def upper_values(self, handle: Int) raises -> List[Ast]

Return (inf, val, eps) upper-bound vector for objective handle.

Optimize.assertions

def assertions(self) raises -> List[Ast]

Return all asserted hard constraints.

Optimize.objectives

def objectives(self) raises -> List[Ast]

Return all registered optimization objectives.

Optimize.unsat_core

def unsat_core(self) raises -> List[Ast]

Return the unsatisfiable core of tracked assertions.

Optimize.reason_unknown

def reason_unknown(self) raises -> String

Return the reason the last check() returned unknown.

Optimize.help

def help(self) raises -> String

Return Z3 parameter help text for Optimize.

Optimize.param_descrs

def param_descrs(self) raises -> ParamDescrs

Return parameter descriptions (ParamDescrs) for Optimize.

Optimize.set

def set(self, key: String, val: Bool) raises
def set(self, key: String, val: Int) raises
All 4 overloads
def set(self, key: String, val: Bool) raises
def set(self, key: String, val: Int) raises
def set(self, key: String, val: Float64) raises
def set(self, key: String, val: String) raises

Set an unsigned-integer parameter on this optimizer.

Optimize.statistics

def statistics(self) raises -> Stats

Return solver statistics for this optimizer.

Model

See also the full 1-to-1 handle reference in Model (Safe Handle API).

Model.evaluate

def evaluate(self, ast: Ast, model_completion: Bool = False) raises -> Optional[Ast]

Python Z3 alias for eval(ast, model_completion) (defaults model_completion=False).

Model.__getitem__

def __getitem__(self, ast: Ast) raises -> Optional[Ast]

Evaluate ast in this model with model completion enabled.

Model.get_bool

def get_bool(self, ast: Ast) raises -> Optional[Bool]

Evaluate ast in this model and extract its Bool value if concrete.

Model.get_integer

def get_integer(self, ast: Ast) raises -> Optional[Integer]

Evaluate ast in this model and extract its exact apn_mojo.Integer value if an integer numeral.

Model.get_rational

def get_rational(self, ast: Ast) raises -> Optional[Rational]

Evaluate ast in this model and extract its exact apn_mojo.Rational value if a rational numeral.

Model.consts

def consts(self) raises -> List[FuncDecl]

Return all constant declarations interpreted in this model.

Model.funcs

def funcs(self) raises -> List[FuncDecl]

Return all non-constant function declarations interpreted in this model.

Model.decls

def decls(self) raises -> List[FuncDecl]

Return all constant and function declarations interpreted in this model.

Model.func_interp

def func_interp(self, f: FuncDecl) raises -> Optional[FuncInterp]

Return the FuncInterp for f if present in this model.

Model.sexpr

def sexpr(self) raises -> String

Return the SMT-LIB2 string representation of this model.

Model.num_sorts

def num_sorts(self) raises -> Int

Return the number of uninterpreted sorts with finite universes in this model.

Model.sorts

def sorts(self) raises -> List[Sort]

Return all uninterpreted sorts with finite universes in this model.

Model.get_universe

def get_universe(self, s: Sort) raises -> List[Ast]

Return the finite universe of uninterpreted sort s in this model.

Model.project

def project(self, vars: List[Ast], formula: Ast) raises -> Ast

Model-based projection of formula eliminating vars using this model.

FuncInterp

See also the full 1-to-1 handle reference in FuncInterp (Safe Handle API).

FuncInterp.else_value

def else_value(self) raises -> Ast

Return the default (else) value of this function interpretation.

FuncInterp.entries

def entries(self) raises -> List[Tuple[List[Ast], Ast]]

Return all finite table rows as (args, value) pairs.

Stats

See also the full 1-to-1 handle reference in Stats (Safe Handle API).

Stats.entries

def entries(self) raises -> List[Tuple[String, String]]

Return all (key, value_string) pairs in this statistics snapshot.

Stats.get_uint

def get_uint(self, key: String) raises -> Optional[UInt32]

Look up an unsigned integer statistic by key.

Stats.get_double

def get_double(self, key: String) raises -> Optional[Float64]

Look up a floating-point statistic by key.

Goal

See also the full 1-to-1 handle reference in Goal (Safe Handle API).

Goal.__init__

def __init__(out self, ctx: Context, models: Bool = True, unsat_cores: Bool = False, proofs: Bool = False) raises

Create a new Z3 Goal.

Goal.add

def add(self, *formulas: Ast) raises
def add(self, formulas: List[Ast]) raises

Assert one or more formulas into this goal.

Goal.get

def get(self, index: Int) raises -> Ast

Return the formula at index in this goal (alias for formula(index)).

Goal.append

def append(self, *formulas: Ast) raises

Alias for add(*formulas) asserting formulas into this goal.

Goal.insert

def insert(self, *formulas: Ast) raises

Alias for add(*formulas) asserting formulas into this goal.

Goal.assert_exprs

def assert_exprs(self, *formulas: Ast) raises
def assert_exprs(self, formulas: List[Ast]) raises

Python Z3 alias for add(*formulas).

Goal.as_expr

def as_expr(self) raises -> Ast

Return the conjunction of all formulas in this goal.

Goal.sexpr

def sexpr(self) raises -> String

Return the SMT-LIB2 string representation of this goal.

Goal.dimacs

def dimacs(self, include_names: Bool = True) raises -> String

Return the DIMACS CNF representation of this goal.

Goal.prec

def prec(self) raises -> GoalPrec

Return the approximation precision (GoalPrec) of this goal.

Goal.simplify

def simplify(self) raises -> Goal

Apply Z3's default simplify tactic to this goal and return the simplified subgoal.

Operator overloads (2 methods)
def __len__(self) -> Int
def __getitem__(self, index: Int) raises -> Ast

Tactic

See also the full 1-to-1 handle reference in Tactic (Safe Handle API).

Tactic.__init__

def __init__(out self, name: String, ctx: Context) raises

Create a named Z3 tactic (e.g. Tactic("simplify", ctx)).

Tactic.ctx

def ctx(self) -> Context

Return a Context handle referencing this tactic's owning Z3 context.

Tactic.solver

def solver(self) raises -> Solver

Python Z3 alias for to_solver().

Tactic.help

def help(self) raises -> String

Return Z3 parameter help text for this tactic.

Tactic.param_descrs

def param_descrs(self) raises -> ParamDescrs

Return parameter descriptions (ParamDescrs) for this tactic.

Probe

See also the full 1-to-1 handle reference in Probe (Safe Handle API).

Probe.__init__

def __init__(out self, name: String, ctx: Context) raises

Create a named Z3 goal probe (e.g. Probe("num-consts", ctx)).

Probe.create

def create(ctx: Context, name: String) raises -> Probe

Create a named Z3 goal probe (e.g. 'num-consts', 'is-qfnra').

Probe.const

def const(ctx: Context, val: Float64) raises -> Probe

Create a constant numeric probe.

Probe.ctx

def ctx(self) -> Context

Return a Context handle referencing this probe's owning Z3 context.

Operator overloads (15 methods)
def __lt__(self, other: Probe) raises -> Probe
def __lt__(self, val: Float64) raises -> Probe
def __lt__(self, val: Int) raises -> Probe
def __le__(self, other: Probe) raises -> Probe
def __le__(self, val: Float64) raises -> Probe
def __le__(self, val: Int) raises -> Probe
def __gt__(self, other: Probe) raises -> Probe
def __gt__(self, val: Float64) raises -> Probe
def __gt__(self, val: Int) raises -> Probe
def __ge__(self, other: Probe) raises -> Probe
def __ge__(self, val: Float64) raises -> Probe
def __ge__(self, val: Int) raises -> Probe
def __and__(self, other: Probe) raises -> Probe
def __or__(self, other: Probe) raises -> Probe
def __invert__(self) raises -> Probe

Fixedpoint

See also the full 1-to-1 handle reference in Fixedpoint (Safe Handle API).

Fixedpoint.__init__

def __init__(out self, ctx: Context) raises

Create a new Z3 Fixedpoint / Horn / Spacer solver.

Fixedpoint.create

def create(ctx: Context) raises -> Fixedpoint

Create a new Z3 Fixedpoint / Horn / Spacer solver.

Fixedpoint.rule

def rule(self, rule: Ast, name: String = "") raises

Python Z3 alias for add_rule(rule, name).

Fixedpoint.fact

def fact(self, fact: Ast) raises

Add a ground or universally quantified fact rule.

Fixedpoint.add

def add(self, *axioms: Ast) raises
def add(self, axioms: List[Ast]) raises

Assert one or more background axioms into this fixedpoint engine.

Fixedpoint.append

def append(self, *axioms: Ast) raises

Alias for add(*axioms) asserting background axioms into this fixedpoint engine.

Fixedpoint.insert

def insert(self, *axioms: Ast) raises

Alias for add(*axioms) asserting background axioms into this fixedpoint engine.

Fixedpoint.assert_exprs

def assert_exprs(self, *axioms: Ast) raises

Python Z3 alias for add(*axioms) asserting background axioms into this fixedpoint engine.

Fixedpoint.parse_string

def parse_string(self, smt2: String) raises -> List[Ast]

Parse Datalog / Horn SMT-LIB2 rules from a string and return queries.

Fixedpoint.parse_file

def parse_file(self, path: String) raises -> List[Ast]

Parse Datalog / Horn SMT-LIB2 rules from a file and return queries.

Fixedpoint.assertions

def assertions(self) raises -> List[Ast]

Return all asserted formulas in this fixedpoint engine.

Fixedpoint.reason_unknown

def reason_unknown(self) raises -> String

Return the reason the last query returned unknown.

Fixedpoint.help

def help(self) raises -> String

Return Z3 parameter help text for Fixedpoint.

Fixedpoint.param_descrs

def param_descrs(self) raises -> ParamDescrs

Return parameter descriptions for Fixedpoint.

Fixedpoint.sexpr

def sexpr(self) raises -> String

Return the SMT-LIB2 string representation of this fixedpoint engine.

Fixedpoint.set

def set(self, key: String, val: Bool) raises
def set(self, key: String, val: Int) raises
All 4 overloads
def set(self, key: String, val: Bool) raises
def set(self, key: String, val: Int) raises
def set(self, key: String, val: Float64) raises
def set(self, key: String, val: String) raises

Set an unsigned-integer parameter on this fixedpoint engine.

Fixedpoint.query_check

def query_check(self, query: Ast) raises -> CheckResult

Run Z3_fixedpoint_query and return a CheckResult (sat/unsat/unknown).

Fixedpoint.statistics

def statistics(self) raises -> Stats

Return solver statistics for this fixedpoint engine.

Ast

See also the full 1-to-1 handle reference in Ast (Safe Handle API).

Ast.write_to

def write_to(self, mut writer: Some[Writer])

Write this AST's SMT-LIB2 string representation to writer.

Ast.hash_code

def hash_code(self) raises -> UInt32

Return the Z3 structural hash code of this AST (Z3_get_ast_hash).

Ast.hash

def hash(self) raises -> UInt32

Python Z3 alias for hash_code().

Ast.get_id

def get_id(self) raises -> UInt32

Return the unique Z3 AST identifier.

Ast.kind

def kind(self) raises -> AstKind

Return the AstKind of this AST (Z3_get_ast_kind).

Ast.sort

def sort(self) raises -> Sort

Return the Sort of this AST (Z3_get_sort).

Ast.sort_kind

def sort_kind(self) raises -> SortKind

Return the SortKind of this AST's sort.

Ast.simplify

def simplify(self) raises -> Ast

Simplify this AST using Z3's default simplifier (Z3_simplify).

Ast.to_string

def to_string(self) raises -> String

Format this AST as an SMT-LIB2 string (Z3_ast_to_string).

Ast.sexpr

def sexpr(self) raises -> String

Python Z3 alias for to_string().

Ast.translate

def translate(self, target: Context) raises -> Ast

Translate this AST into target Context.

Ast.is_numeral

def is_numeral(self) raises -> Bool

Return True if this AST is a numeral value (Z3_is_numeral_ast).

Ast.is_algebraic_number

def is_algebraic_number(self) raises -> Bool

Return True if this AST is an irrational real algebraic numeral (Z3_is_algebraic_number).

Ast.as_bool

def as_bool(self) raises -> Optional[Bool]

Extract True or False if this AST is a Boolean constant, or None (Z3_get_bool_value).

Ast.as_integer

def as_integer(self) raises -> Optional[Integer]

Extract exact arbitrary-precision apn_mojo.Integer if this AST is an integer numeral.

Ast.as_rational

def as_rational(self) raises -> Optional[Rational]

Extract exact arbitrary-precision apn_mojo.Rational if this AST is a rational numeral.

Ast.is_app

def is_app(self) raises -> Bool

Return True if this AST is an application (constants and compound terms).

Ast.is_const

def is_const(self) raises -> Bool

Return True if this AST is a 0-arity application (constant or numeral).

Ast.is_quantifier

def is_quantifier(self) raises -> Bool

Return True if this AST is a quantifier (ForAll, Exists, or Lambda).

Ast.is_true

def is_true(self) raises -> Bool

Return True if this AST is the Boolean constant true.

Ast.is_false

def is_false(self) raises -> Bool

Return True if this AST is the Boolean constant false.

Ast.is_bool

def is_bool(self) raises -> Bool

Return True if this AST has Bool sort.

Ast.is_int

def is_int(self) raises -> Bool

Return True if this AST has Int sort.

Ast.is_real

def is_real(self) raises -> Bool

Return True if this AST has Real sort.

Ast.is_bv

def is_bv(self) raises -> Bool

Return True if this AST has BitVec sort.

Ast.is_string

def is_string(self) raises -> Bool

Return True if this AST has String sort.

Ast.is_array

def is_array(self) raises -> Bool

Return True if this AST has Array sort.

Ast.is_fp

def is_fp(self) raises -> Bool

Return True if this AST has IEEE-754 FloatingPoint sort.

Ast.is_finite_field

def is_finite_field(self) raises -> Bool

Return True if this AST has FiniteField sort.

Ast.is_finite_set

def is_finite_set(self) raises -> Bool

Return True if this AST has FiniteSet sort.

Ast.is_complex

def is_complex(self) raises -> Bool

Return True if this AST has Complex sort.

Ast.decl

def decl(self) raises -> FuncDecl

Return the top-level FuncDecl of an application AST (raises if not an app).

Ast.decl_kind

def decl_kind(self) raises -> DeclKind

Return the DeclKind of this application AST's top-level declaration.

Ast.num_args

def num_args(self) raises -> Int

Return the number of child arguments (0 for non-application ASTs).

Ast.arg

def arg(self, index: Int) raises -> Ast

Return child argument index of an application AST.

Ast.children

def children(self) raises -> List[Ast]

Return all child arguments of an application AST as a List[Ast].

Ast.ctx

def ctx(self) -> Context

Return a Context handle referencing this AST's owning Z3 context.

Ast.eq

def eq(self, other: Ast) raises -> Ast
def eq(self, other: Int) raises -> Ast
All 6 overloads
def eq(self, other: Ast) raises -> Ast
def eq(self, other: Int) raises -> Ast
def eq(self, other: Integer) raises -> Ast
def eq(self, other: Rational) raises -> Ast
def eq(self, other: Bool) raises -> Ast
def eq(self, other: String) raises -> Ast

Build a Z3 equality formula (= self other) (keeping == as Mojo structural equality).

Ast.ne

def ne(self, other: Ast) raises -> Ast
def ne(self, other: Int) raises -> Ast
All 6 overloads
def ne(self, other: Ast) raises -> Ast
def ne(self, other: Int) raises -> Ast
def ne(self, other: Integer) raises -> Ast
def ne(self, other: Rational) raises -> Ast
def ne(self, other: Bool) raises -> Ast
def ne(self, other: String) raises -> Ast

Build a Z3 disequality formula (distinct self other) coercing Rational literal other.

Ast.implies

def implies(self, other: Ast) raises -> Ast

Build a Z3 implication formula (=> self other).

Ast.substitute

def substitute(self, from_ast: Ast, to_ast: Ast) raises -> Ast
def substitute(self, from_asts: List[Ast], to_asts: List[Ast]) raises -> Ast

Simultaneously substitute each from_asts[i] with to_asts[i].

Operator overloads (100 methods)
def __eq__(self, other: Self) -> Bool
def __neg__(self) raises -> Ast
def __pos__(self) raises -> Ast
def __invert__(self) raises -> Ast
def __add__(self, other: Ast) raises -> Ast
def __add__(self, other: Int) raises -> Ast
def __radd__(self, other: Int) raises -> Ast
def __add__(self, other: Integer) raises -> Ast
def __radd__(self, other: Integer) raises -> Ast
def __add__(self, other: Rational) raises -> Ast
def __radd__(self, other: Rational) raises -> Ast
def __add__(self, other: String) raises -> Ast
def __radd__(self, other: String) raises -> Ast
def __sub__(self, other: Ast) raises -> Ast
def __sub__(self, other: Int) raises -> Ast
def __rsub__(self, other: Int) raises -> Ast
def __sub__(self, other: Integer) raises -> Ast
def __rsub__(self, other: Integer) raises -> Ast
def __sub__(self, other: Rational) raises -> Ast
def __rsub__(self, other: Rational) raises -> Ast
def __mul__(self, other: Ast) raises -> Ast
def __mul__(self, other: Int) raises -> Ast
def __rmul__(self, other: Int) raises -> Ast
def __mul__(self, other: Integer) raises -> Ast
def __rmul__(self, other: Integer) raises -> Ast
def __mul__(self, other: Rational) raises -> Ast
def __rmul__(self, other: Rational) raises -> Ast
def __truediv__(self, other: Ast) raises -> Ast
def __truediv__(self, other: Int) raises -> Ast
def __rtruediv__(self, other: Int) raises -> Ast
def __truediv__(self, other: Integer) raises -> Ast
def __rtruediv__(self, other: Integer) raises -> Ast
def __truediv__(self, other: Rational) raises -> Ast
def __rtruediv__(self, other: Rational) raises -> Ast
def __floordiv__(self, other: Ast) raises -> Ast
def __floordiv__(self, other: Int) raises -> Ast
def __rfloordiv__(self, other: Int) raises -> Ast
def __floordiv__(self, other: Integer) raises -> Ast
def __rfloordiv__(self, other: Integer) raises -> Ast
def __mod__(self, other: Ast) raises -> Ast
def __mod__(self, other: Int) raises -> Ast
def __rmod__(self, other: Int) raises -> Ast
def __mod__(self, other: Integer) raises -> Ast
def __rmod__(self, other: Integer) raises -> Ast
def __pow__(self, other: Ast) raises -> Ast
def __pow__(self, other: Int) raises -> Ast
def __rpow__(self, other: Int) raises -> Ast
def __pow__(self, other: Integer) raises -> Ast
def __rpow__(self, other: Integer) raises -> Ast
def __pow__(self, other: Rational) raises -> Ast
def __rpow__(self, other: Rational) raises -> Ast
def __and__(self, other: Ast) raises -> Ast
def __and__(self, other: Bool) raises -> Ast
def __rand__(self, other: Bool) raises -> Ast
def __and__(self, other: Int) raises -> Ast
def __rand__(self, other: Int) raises -> Ast
def __and__(self, other: Integer) raises -> Ast
def __rand__(self, other: Integer) raises -> Ast
def __or__(self, other: Ast) raises -> Ast
def __or__(self, other: Bool) raises -> Ast
def __ror__(self, other: Bool) raises -> Ast
def __or__(self, other: Int) raises -> Ast
def __ror__(self, other: Int) raises -> Ast
def __or__(self, other: Integer) raises -> Ast
def __ror__(self, other: Integer) raises -> Ast
def __xor__(self, other: Ast) raises -> Ast
def __xor__(self, other: Bool) raises -> Ast
def __rxor__(self, other: Bool) raises -> Ast
def __xor__(self, other: Int) raises -> Ast
def __rxor__(self, other: Int) raises -> Ast
def __xor__(self, other: Integer) raises -> Ast
def __rxor__(self, other: Integer) raises -> Ast
def __lshift__(self, other: Ast) raises -> Ast
def __lshift__(self, other: Int) raises -> Ast
def __rlshift__(self, other: Int) raises -> Ast
def __lshift__(self, other: Integer) raises -> Ast
def __rlshift__(self, other: Integer) raises -> Ast
def __rshift__(self, other: Ast) raises -> Ast
def __rshift__(self, other: Int) raises -> Ast
def __rrshift__(self, other: Int) raises -> Ast
def __rshift__(self, other: Integer) raises -> Ast
def __rrshift__(self, other: Integer) raises -> Ast
def __lt__(self, other: Ast) raises -> Ast
def __lt__(self, other: Int) raises -> Ast
def __lt__(self, other: Integer) raises -> Ast
def __lt__(self, other: Rational) raises -> Ast
def __le__(self, other: Ast) raises -> Ast
def __le__(self, other: Int) raises -> Ast
def __le__(self, other: Integer) raises -> Ast
def __le__(self, other: Rational) raises -> Ast
def __gt__(self, other: Ast) raises -> Ast
def __gt__(self, other: Int) raises -> Ast
def __gt__(self, other: Integer) raises -> Ast
def __gt__(self, other: Rational) raises -> Ast
def __ge__(self, other: Ast) raises -> Ast
def __ge__(self, other: Int) raises -> Ast
def __ge__(self, other: Integer) raises -> Ast
def __ge__(self, other: Rational) raises -> Ast
def __getitem__(self, index: Ast) raises -> Ast
def __getitem__(self, index: Int) raises -> Ast

FuncDecl

See also the full 1-to-1 handle reference in FuncDecl (Safe Handle API).

FuncDecl.__eq__

def __eq__(self, other: Self) -> Bool

Return True if two FuncDecl handles refer to the same declaration.

FuncDecl.name

def name(self) raises -> String

Return the name of this function declaration (Z3_get_decl_name).

FuncDecl.arity

def arity(self) raises -> Int

Return the number of parameters of this function declaration (Z3_get_arity).

FuncDecl.range

def range(self) raises -> Sort

Return the return Sort of this function declaration (Z3_get_range).

FuncDecl.domain

def domain(self, index: Int) raises -> Sort

Return the Sort of parameter index of this function declaration.

FuncDecl.kind

def kind(self) raises -> DeclKind

Return the DeclKind of this function declaration.

FuncDecl.sexpr

def sexpr(self) raises -> String

Return the SMT-LIB2 string representation of this function declaration.

FuncDecl.get_id

def get_id(self) raises -> UInt32

Return the unique Z3 identifier of this function declaration.

FuncDecl.hash

def hash(self) raises -> UInt32

Return the Z3 AST hash of this function declaration.

FuncDecl.ctx

def ctx(self) -> Context

Return a Context handle referencing this declaration's owning Z3 context.

FuncDecl.__call__

def __call__(self, *args: Ast) raises -> Ast
def __call__(self, args: List[Ast]) raises -> Ast

Apply this function declaration to positional Ast arguments.

Sort

See also the full 1-to-1 handle reference in Sort (Safe Handle API).

Sort.__eq__

def __eq__(self, other: Self) -> Bool

Return True if two Sort handles refer to the same Z3 sort.

Sort.kind

def kind(self) raises -> SortKind

Return the SortKind of this sort (Z3_get_sort_kind).

Sort.to_string

def to_string(self) raises -> String

Format this sort as a string (Z3_sort_to_string).

Sort.sexpr

def sexpr(self) raises -> String

Return the SMT-LIB2 string representation of this sort.

Sort.name

def name(self) raises -> String

Return the name of this sort.

Sort.get_id

def get_id(self) raises -> UInt32

Return the unique Z3 sort identifier.

Sort.ctx

def ctx(self) -> Context

Return a Context handle referencing this sort's owning Z3 context.

Sort.write_to

def write_to(self, mut writer: Some[Writer])

Write this sort's string representation to writer.

AstVector

See also the full 1-to-1 handle reference in AstVector (Safe Handle API).

AstVector.to_list

def to_list(self) raises -> List[Ast]

Copy every AST in this vector into a Mojo List[Ast], pinning each AST to the context.

RcfNum

See also the full 1-to-1 handle reference in RcfNum (Safe Handle API).

Operator overloads (11 methods)
def __neg__(self) raises -> RcfNum
def __pos__(self) raises -> RcfNum
def __add__(self, other: RcfNum) raises -> RcfNum
def __sub__(self, other: RcfNum) raises -> RcfNum
def __mul__(self, other: RcfNum) raises -> RcfNum
def __truediv__(self, other: RcfNum) raises -> RcfNum
def __pow__(self, exp: Int) raises -> RcfNum
def __lt__(self, other: RcfNum) raises -> Bool
def __le__(self, other: RcfNum) raises -> Bool
def __gt__(self, other: RcfNum) raises -> Bool
def __ge__(self, other: RcfNum) raises -> Bool

Core Constructors, Operators & Combinators (z3_mojo.pythonic)

Variables, constants, and function declarations

var ctx = Context()
var x = IntVar("x", ctx)
var y = Real("y", ctx)
var f = Function("f", IntSort(ctx), IntSort(ctx))

BoolVar

def BoolVar(name: String, ctx: Context) raises -> Ast

Create a Boolean constant (variable) named name.

Bools

def Bools(names: String, ctx: Context) raises -> List[Ast]

Create whitespace-separated Boolean variables (e.g. Bools("p q r", ctx)).

IntVar

def IntVar(name: String, ctx: Context) raises -> Ast

Create an Int constant (variable) named name.

Ints

def Ints(names: String, ctx: Context) raises -> List[Ast]

Create whitespace-separated Int variables (e.g. Ints("x y z", ctx)).

Real

def Real(name: String, ctx: Context) raises -> Ast

Create a Real constant (variable) named name.

RealVar

def RealVar(name: String, ctx: Context) raises -> Ast

Alias for Real(name, ctx).

Reals

def Reals(names: String, ctx: Context) raises -> List[Ast]

Create whitespace-separated Real variables (e.g. Reals("x y z", ctx)).

BitVec

def BitVec(name: String, bits: Int, ctx: Context) raises -> Ast

Create a BitVector constant of width bits named name.

BitVecs

def BitVecs(names: String, bits: Int, ctx: Context) raises -> List[Ast]

Create whitespace-separated BitVector variables of width bits.

StringVar

def StringVar(name: String, ctx: Context) raises -> Ast

Create a String constant (variable) named name.

ArrayVar

def ArrayVar(name: String, domain: Sort, range_: Sort) raises -> Ast

Create an Array constant mapping domain to range_.

Const

def Const(name: String, sort: Sort) raises -> Ast

Create a constant of arbitrary sort.

Function

def Function(name: String, domain: Sort, range_: Sort) raises -> FuncDecl
def Function(name: String, d1: Sort, d2: Sort, range_: Sort) raises -> FuncDecl
All 4 overloads
def Function(name: String, domain: Sort, range_: Sort) raises -> FuncDecl
def Function(name: String, d1: Sort, d2: Sort, range_: Sort) raises -> FuncDecl
def Function(name: String, d1: Sort, d2: Sort, d3: Sort, range_: Sort) raises -> FuncDecl
def Function(name: String, domain: List[Sort], range_: Sort) raises -> FuncDecl

Declare a ternary uninterpreted function name: (d1, d2, d3) -> range_.

Exact numerals and literals

BoolVal

def BoolVal(v: Bool, ctx: Context) raises -> Ast

Create a Boolean literal (true or false).

IntVal

def IntVal(v: Int, ctx: Context) raises -> Ast
def IntVal(v: Integer, ctx: Context) raises -> Ast

Create an arbitrary-precision Int numeral from apn_mojo.Integer.

RealVal

def RealVal(v: Int, ctx: Context) raises -> Ast
def RealVal(num: Int, den: Int, ctx: Context) raises -> Ast
All 5 overloads
def RealVal(v: Int, ctx: Context) raises -> Ast
def RealVal(num: Int, den: Int, ctx: Context) raises -> Ast
def RealVal(v: Integer, ctx: Context) raises -> Ast
def RealVal(v: Rational, ctx: Context) raises -> Ast
def RealVal(s: String, ctx: Context) raises -> Ast

Create an exact Real numeral from a decimal or fraction string (e.g. '1/3' or '0.25').

BitVecVal

def BitVecVal(v: Int, bits: Int, ctx: Context) raises -> Ast
def BitVecVal(v: Integer, bits: Int, ctx: Context) raises -> Ast

Create a BitVector numeral of width bits from apn_mojo.Integer.

StringVal

def StringVal(s: String, ctx: Context) raises -> Ast

Create a Z3 String literal.

Logical combinators, equality, and arithmetic aggregates

var s = Solver(ctx)
s.add(And(x > 0, y > 0), Or(Eq(x + y, 10), Ne(x, y)))
var cond = If(x > 5, x - 5, IntVal(0, ctx))

And

def And(*args: Ast) raises -> Ast
def And(args: List[Ast]) raises -> Ast

Build a conjunction (and ...) from a non-empty list of Boolean ASTs.

Or

def Or(*args: Ast) raises -> Ast
def Or(args: List[Ast]) raises -> Ast

Build a disjunction (or ...) from a non-empty list of Boolean ASTs.

Not

def Not(a: Ast) raises -> Ast

Build logical negation (not a).

Implies

def Implies(a: Ast, b: Ast) raises -> Ast

Build logical implication (=> a b).

Xor

def Xor(a: Ast, b: Ast) raises -> Ast

Build logical exclusive-OR (xor a b).

If

def If(cond: Ast, then_ast: Ast, else_ast: Ast) raises -> Ast
def If(cond: Ast, then_ast: Ast, else_val: Int) raises -> Ast
All 13 overloads
def If(cond: Ast, then_ast: Ast, else_ast: Ast) raises -> Ast
def If(cond: Ast, then_ast: Ast, else_val: Int) raises -> Ast
def If(cond: Ast, then_val: Int, else_ast: Ast) raises -> Ast
def If(cond: Ast, then_ast: Ast, else_val: Integer) raises -> Ast
def If(cond: Ast, then_val: Integer, else_ast: Ast) raises -> Ast
def If(cond: Ast, then_ast: Ast, else_val: Rational) raises -> Ast
def If(cond: Ast, then_val: Rational, else_ast: Ast) raises -> Ast
def If(cond: Ast, then_ast: Ast, else_val: Bool) raises -> Ast
def If(cond: Ast, then_val: Bool, else_ast: Ast) raises -> Ast
def If(cond: Ast, then_val: Int, else_val: Int) raises -> Ast
def If(cond: Ast, then_val: Integer, else_val: Integer) raises -> Ast
def If(cond: Ast, then_val: Rational, else_val: Rational) raises -> Ast
def If(cond: Ast, then_val: Bool, else_val: Bool) raises -> Ast

Build an if-then-else expression (ite cond then_ast else_ast) (branches may be Ast, Int, Integer, Rational, or Bool).

Eq

def Eq(a: Ast, b: Ast) raises -> Ast
def Eq(a: Ast, b: Int) raises -> Ast
All 6 overloads
def Eq(a: Ast, b: Ast) raises -> Ast
def Eq(a: Ast, b: Int) raises -> Ast
def Eq(a: Ast, b: Integer) raises -> Ast
def Eq(a: Ast, b: Rational) raises -> Ast
def Eq(a: Ast, b: Bool) raises -> Ast
def Eq(a: Ast, b: String) raises -> Ast

Build a Z3 equality formula (= a b) (accepts Ast, Int, Integer, Rational, Bool, or String RHS).

Ne

def Ne(a: Ast, b: Ast) raises -> Ast
def Ne(a: Ast, b: Int) raises -> Ast
All 6 overloads
def Ne(a: Ast, b: Ast) raises -> Ast
def Ne(a: Ast, b: Int) raises -> Ast
def Ne(a: Ast, b: Integer) raises -> Ast
def Ne(a: Ast, b: Rational) raises -> Ast
def Ne(a: Ast, b: Bool) raises -> Ast
def Ne(a: Ast, b: String) raises -> Ast

Build a Z3 disequality formula (distinct a b) (accepts Ast, Int, Integer, Rational, Bool, or String RHS).

Distinct

def Distinct(*args: Ast) raises -> Ast
def Distinct(args: List[Ast]) raises -> Ast

Build a pairwise-distinctness constraint from a non-empty list of ASTs.

Sum

def Sum(*args: Ast) raises -> Ast
def Sum(args: List[Ast]) raises -> Ast

Sum a non-empty list of Int/Real (or BitVec) ASTs.

Product

def Product(*args: Ast) raises -> Ast
def Product(args: List[Ast]) raises -> Ast

Multiply a non-empty list of Int/Real (or BitVec) ASTs.

Quantifiers, patterns, weights, and one-shot prove / solve

var f = Function("f", IntSort(ctx), IntSort(ctx))
var x = IntVar("x", ctx)
var ax = ForAll([x], f(x) >= x, patterns=[MultiPattern([f(x)])], weight=1)
var res = prove(Implies(ax, f(IntVal(10, ctx)) >= 10))

MultiPattern

def MultiPattern(*terms: Ast) raises -> Pattern
def MultiPattern(terms: List[Ast]) raises -> Pattern

Create a quantifier E-matching trigger pattern from a non-empty list of ASTs.

ForAll

def ForAll(bound: Ast, body: Ast) raises -> Ast
def ForAll(bounds: List[Ast], body: Ast) raises -> Ast
All 5 overloads
def ForAll(bound: Ast, body: Ast) raises -> Ast
def ForAll(bounds: List[Ast], body: Ast) raises -> Ast
def ForAll(bound: Ast, body: Ast, patterns: List[Pattern], weight: Int = 0, qid: String = "", skolem_id: String = "",) raises -> Ast
def ForAll(bounds: List[Ast], body: Ast, patterns: List[Pattern], weight: Int = 0, qid: String = "", skolem_id: String = "",) raises -> Ast
def ForAll(bounds: List[Ast], body: Ast, patterns: List[Pattern], no_patterns: List[Ast], weight: Int = 0, qid: String = "", skolem_id: String = "",) raises -> Ast

Build a universally quantified formula with explicit E-matching patterns, weight, and qid.

Exists

def Exists(bound: Ast, body: Ast) raises -> Ast
def Exists(bounds: List[Ast], body: Ast) raises -> Ast
All 5 overloads
def Exists(bound: Ast, body: Ast) raises -> Ast
def Exists(bounds: List[Ast], body: Ast) raises -> Ast
def Exists(bound: Ast, body: Ast, patterns: List[Pattern], weight: Int = 0, qid: String = "", skolem_id: String = "",) raises -> Ast
def Exists(bounds: List[Ast], body: Ast, patterns: List[Pattern], weight: Int = 0, qid: String = "", skolem_id: String = "",) raises -> Ast
def Exists(bounds: List[Ast], body: Ast, patterns: List[Pattern], no_patterns: List[Ast], weight: Int = 0, qid: String = "", skolem_id: String = "",) raises -> Ast

Build an existentially quantified formula with explicit E-matching patterns, weight, and qid.

prove

def prove(claim: Ast) raises -> CheckResult

Check validity of claim by testing Not(claim).

Returns CHECK_UNSAT when claim is proved valid, CHECK_SAT when a counterexample exists, or CHECK_UNKNOWN if the solver could not decide.

solve

def solve(*constraints: Ast) raises -> Optional[Model]
def solve(constraints: List[Ast]) raises -> Optional[Model]

Check a non-empty list of constraints in a fresh Solver and return a Model if satisfiable.

Arrays, numeric conversions, and unsigned / structural BitVector operations

var a = BitVec("a", 8, ctx)
var arr = Store(K(IntSort(ctx), IntVal(0, ctx)), 3, 42)
var ok = And(ULE(a, BitVecVal(100, 8, ctx)), Eq(Select(arr, 3), 42))

Select

def Select(arr: Ast, idx: Ast) raises -> Ast
def Select(arr: Ast, idx: Int) raises -> Ast

Array select arr[idx] with Int index coerced to the array domain.

Store

def Store(arr: Ast, idx: Ast, val: Ast) raises -> Ast
def Store(arr: Ast, idx: Int, val: Ast) raises -> Ast
All 7 overloads
def Store(arr: Ast, idx: Ast, val: Ast) raises -> Ast
def Store(arr: Ast, idx: Int, val: Ast) raises -> Ast
def Store(arr: Ast, idx: Ast, val: Int) raises -> Ast
def Store(arr: Ast, idx: Int, val: Int) raises -> Ast
def Store(arr: Ast, idx: Ast, val: Integer) raises -> Ast
def Store(arr: Ast, idx: Ast, val: Rational) raises -> Ast
def Store(arr: Ast, idx: Ast, val: Bool) raises -> Ast

Array store returning an updated array with arr[idx] = val (accepts Ast, Int, Integer, Rational, or Bool literals).

ToReal

def ToReal(a: Ast) raises -> Ast

Convert an Int AST to Real (Z3_mk_int2real).

ToInt

def ToInt(a: Ast) raises -> Ast

Convert a Real AST to Int via floor (Z3_mk_real2int).

ULT

def ULT(a: Ast, b: Ast) raises -> Ast
def ULT(a: Ast, b: Int) raises -> Ast
def ULT(a: Ast, b: Integer) raises -> Ast

Unsigned BitVector less-than (Z3_mk_bvult; RHS may be Ast, Int, or Integer).

ULE

def ULE(a: Ast, b: Ast) raises -> Ast
def ULE(a: Ast, b: Int) raises -> Ast
def ULE(a: Ast, b: Integer) raises -> Ast

Unsigned BitVector less-than-or-equal (Z3_mk_bvule; RHS may be Ast, Int, or Integer).

UGT

def UGT(a: Ast, b: Ast) raises -> Ast
def UGT(a: Ast, b: Int) raises -> Ast
def UGT(a: Ast, b: Integer) raises -> Ast

Unsigned BitVector greater-than (Z3_mk_bvugt; RHS may be Ast, Int, or Integer).

UGE

def UGE(a: Ast, b: Ast) raises -> Ast
def UGE(a: Ast, b: Int) raises -> Ast
def UGE(a: Ast, b: Integer) raises -> Ast

Unsigned BitVector greater-than-or-equal (Z3_mk_bvuge; RHS may be Ast, Int, or Integer).

UDiv

def UDiv(a: Ast, b: Ast) raises -> Ast
def UDiv(a: Ast, b: Int) raises -> Ast

Unsigned BitVector division with Int literal RHS coerced to the sort of a.

URem

def URem(a: Ast, b: Ast) raises -> Ast
def URem(a: Ast, b: Int) raises -> Ast

Unsigned BitVector remainder with Int literal RHS coerced to the sort of a.

LShR

def LShR(a: Ast, b: Ast) raises -> Ast
def LShR(a: Ast, b: Int) raises -> Ast

Unsigned (logical) BitVector shift right (Z3_mk_bvlshr; shift amount may be Ast or Int).

Concat

def Concat(*args: Ast) raises -> Ast
def Concat(args: List[Ast]) raises -> Ast

Concatenate a non-empty list of BitVectors, Sequences/Strings, or Regular Expressions.

Extract

def Extract(high: Int, low: Int, a: Ast) raises -> Ast

Extract bits [high:low] (inclusive) from BitVector a.

ZeroExt

def ZeroExt(n: Int, a: Ast) raises -> Ast

Zero-extend BitVector a by n bits.

SignExt

def SignExt(n: Int, a: Ast) raises -> Ast

Sign-extend BitVector a by n bits.

Simplification and substitution

Simplify

def Simplify(a: Ast) raises -> Ast

Simplify a using Z3's default simplifier.

Substitute

def Substitute(a: Ast, from_ast: Ast, to_ast: Ast) raises -> Ast
def Substitute(a: Ast, from_asts: List[Ast], to_asts: List[Ast]) raises -> Ast

Simultaneously substitute from_asts[i] with to_asts[i] in a.

Vectors, fresh variables, plural constructors, and sort helpers

BoolVector

def BoolVector(prefix: String, n: Int, ctx: Context) raises -> List[Ast]

Create n Boolean variables named <prefix>__0, ..., <prefix>__<n-1>.

IntVector

def IntVector(prefix: String, n: Int, ctx: Context) raises -> List[Ast]

Create n Int variables named <prefix>__0, ..., <prefix>__<n-1>.

RealVector

def RealVector(prefix: String, n: Int, ctx: Context) raises -> List[Ast]

Create n Real variables named <prefix>__0, ..., <prefix>__<n-1>.

BitVecVector

def BitVecVector(prefix: String, n: Int, bits: Int, ctx: Context) raises -> List[Ast]

Create n BitVector variables of width bits named <prefix>__0, ...

FreshBool

def FreshBool(ctx: Context, prefix: String = "b") raises -> Ast

Create a fresh Boolean constant guaranteed unique in ctx.

FreshInt

def FreshInt(ctx: Context, prefix: String = "x") raises -> Ast

Create a fresh Int constant guaranteed unique in ctx.

FreshReal

def FreshReal(ctx: Context, prefix: String = "r") raises -> Ast

Create a fresh Real constant guaranteed unique in ctx.

FreshConst

def FreshConst(sort: Sort, prefix: String = "c") raises -> Ast

Create a fresh constant of arbitrary sort guaranteed unique in its context.

Consts

def Consts(names: String, sort: Sort) raises -> List[Ast]

Create whitespace-separated constants of sort.

Strings

def Strings(names: String, ctx: Context) raises -> List[Ast]

Create whitespace-separated String variables.

Q

def Q(num: Int, den: Int, ctx: Context) raises -> Ast
def Q(num: Integer, den: Integer, ctx: Context) raises -> Ast

Shorthand for exact rational num / den (RealVal(num, den, ctx)).

Abs

def Abs(a: Ast) raises -> Ast

Absolute value If(a >= 0, a, -a) for Int, Real, or signed BitVec.

IsInt

def IsInt(a: Ast) raises -> Ast

Predicate asserting that Real expression a has an integer value.

BoolSort

def BoolSort(ctx: Context) raises -> Sort

Return the Bool sort.

IntSort

def IntSort(ctx: Context) raises -> Sort

Return the Int sort.

RealSort

def RealSort(ctx: Context) raises -> Sort

Return the Real sort.

BitVecSort

def BitVecSort(bits: Int, ctx: Context) raises -> Sort

Return the BitVec sort of width bits.

StringSort

def StringSort(ctx: Context) raises -> Sort

Return the String sort.

ArraySort

def ArraySort(domain: Sort, range_: Sort) raises -> Sort

Return the Array[domain, range_] sort.

SeqSort

def SeqSort(elem: Sort) raises -> Sort

Return the Seq[elem] sort.

SetSort

def SetSort(elem: Sort) raises -> Sort

Return the Set[elem] sort (Array[elem, Bool]).

DeclareSort

def DeclareSort(name: String, ctx: Context) raises -> Sort

Declare an uninterpreted sort named name.

Cardinality and Pseudo-Boolean constraints

AtMost

def AtMost(args: List[Ast], k: Int) raises -> Ast

Cardinality constraint: at most k Boolean ASTs in args are true.

AtLeast

def AtLeast(args: List[Ast], k: Int) raises -> Ast

Cardinality constraint: at least k Boolean ASTs in args are true.

PbEq

def PbEq(terms: List[Ast], weights: List[Int], k: Int) raises -> Ast

Pseudo-Boolean equality: sum(weights[i] * terms[i]) == k.

PbLe

def PbLe(terms: List[Ast], weights: List[Int], k: Int) raises -> Ast

Pseudo-Boolean upper bound: sum(weights[i] * terms[i]) <= k.

PbGe

def PbGe(terms: List[Ast], weights: List[Int], k: Int) raises -> Ast

Pseudo-Boolean lower bound: sum(weights[i] * terms[i]) >= k.

Tactic & Probe combinators and solver / SMT-LIB2 shortcuts

var is_qfnra = Probe("is-qfnra", ctx)
var pipe = Then(Tactic("simplify", ctx), When(is_qfnra > 0, Tactic("qfnra-nlsat", ctx)))
var s = pipe.solver()

Then

def Then(*tactics: Tactic) raises -> Tactic
def Then(tactics: List[Tactic]) raises -> Tactic

Compose one or more tactics sequentially (t1, then t2, ...).

OrElse

def OrElse(*tactics: Tactic) raises -> Tactic
def OrElse(tactics: List[Tactic]) raises -> Tactic

Try a non-empty list of tactics in order until one succeeds.

TryFor

def TryFor(t: Tactic, ms: Int) raises -> Tactic

Run tactic t with a timeout of ms milliseconds.

With

def With(t: Tactic, params: Params) raises -> Tactic

Configure tactic t with params.

FailIf

def FailIf(p: Probe) raises -> Tactic

Tactic that fails if probe p evaluates to true (non-zero).

When

def When(p: Probe, t: Tactic) raises -> Tactic

Apply tactic t only when probe p evaluates to true.

Cond

def Cond(p: Probe, t1: Tactic, t2: Tactic) raises -> Tactic

Apply t1 if probe p is true, otherwise t2.

Repeat

def Repeat(t: Tactic, max: Int = 0) raises -> Tactic

Repeat tactic t up to max times (0 means until fixed point).

ParOr

def ParOr(*tactics: Tactic) raises -> Tactic
def ParOr(tactics: List[Tactic]) raises -> Tactic

Run tactics in parallel and return the first result.

ParThen

def ParThen(t1: Tactic, t2: Tactic) raises -> Tactic

Apply t1 and then apply t2 in parallel to each generated subgoal.

SolverFor

def SolverFor(logic: String, ctx: Context) raises -> Solver

Create a solver specialized for SMT-LIB2 logic (e.g. 'QF_NRA', 'QF_BV').

SimpleSolver

def SimpleSolver(ctx: Context) raises -> Solver

Create an incremental solver without tactic preprocessing.

parse_smt2_string

def parse_smt2_string(smt2: String, ctx: Context) raises -> List[Ast]

Parse an SMT-LIB2 script string and return its asserted formulas.

parse_smt2_file

def parse_smt2_file(path: String, ctx: Context) raises -> List[Ast]

Parse an SMT-LIB2 file and return its asserted formulas.

Python Z3 aliases, lowercase core functions, and AST is_* predicates

Array

def Array(name: String, domain: Sort, range_: Sort) raises -> Ast

Python Z3 alias for ArrayVar(name, domain, range_).

AsArray

def AsArray(f: FuncDecl) raises -> Ast

Lift function declaration f into an array AST (Z3_mk_as_array).

Map

def Map(f: FuncDecl, *arrays: Ast) raises -> Ast
def Map(f: FuncDecl, arrays: List[Ast]) raises -> Ast

Apply f elementwise across a non-empty list of arrays (Z3_mk_map).

Ext

def Ext(a: Ast, b: Ast) raises -> Ast

Array extensionality witness index where a[idx] != b[idx] if a != b (Z3_mk_array_ext).

FreshFunction

def FreshFunction(domain: Sort, range_: Sort, prefix: String = "f") raises -> FuncDecl
def FreshFunction(domain: List[Sort], range_: Sort, prefix: String = "f") raises -> FuncDecl

Declare a fresh unary uninterpreted function.

Var

def Var(index: Int, sort: Sort) raises -> Ast

Create a de Bruijn bound variable of sort at index (Z3_mk_bound).

get_var_index

def get_var_index(a: Ast) raises -> Int

Return the de Bruijn index of a bound variable AST (Z3_get_index_value).

RatVal

def RatVal(num: Int, den: Int, ctx: Context) raises -> Ast
def RatVal(num: Integer, den: Integer, ctx: Context) raises -> Ast

Python Z3 alias for arbitrary-precision exact rational Q(num, den, ctx).

Sqrt

def Sqrt(a: Ast) raises -> Ast

Symbolic square root a ** (1/2) for Real ASTs.

Cbrt

def Cbrt(a: Ast) raises -> Ast

Symbolic cube root a ** (1/3) for Real ASTs.

AndThen

def AndThen(*tactics: Tactic) raises -> Tactic

Python Z3 alias for Then(*tactics).

ParAndThen

def ParAndThen(t1: Tactic, t2: Tactic) raises -> Tactic

Python Z3 alias for ParThen(t1, t2).

WithParams

def WithParams(t: Tactic, params: Params) raises -> Tactic

Python Z3 alias for With(t, params).

simplify

def simplify(a: Ast) raises -> Ast

Python Z3 lowercase alias for Simplify(a).

substitute

def substitute(a: Ast, from_ast: Ast, to_ast: Ast) raises -> Ast
def substitute(a: Ast, from_asts: List[Ast], to_asts: List[Ast]) raises -> Ast

Python Z3 lowercase alias for Substitute(a, from_asts, to_asts).

substitute_vars

def substitute_vars(a: Ast, to_asts: List[Ast]) raises -> Ast

Substitute de Bruijn bound variables Var(0), Var(1), ... in a with to_asts.

eq

def eq(a: Ast, b: Ast) -> Bool

Python Z3 structural AST identity check (a == b).

set_param

def set_param(key: String, value: String) raises
def set_param(key: String, value: Bool) raises
def set_param(key: String, value: Int) raises

Set a Z3 global parameter (Z3_global_param_set; accepts String, Bool, or Int values).

set_option

def set_option(key: String, value: String) raises
def set_option(key: String, value: Bool) raises
def set_option(key: String, value: Int) raises

Python Z3 alias for set_param(key, value) (accepts String, Bool, or Int values).

get_param

def get_param(key: String) raises -> Optional[String]

Read a Z3 global parameter (Z3_global_param_get).

reset_params

def reset_params() raises

Reset all Z3 global parameters to defaults (Z3_global_param_reset_all).

get_version_string

def get_version_string() raises -> String

Return Z3's full version string.

tactics

def tactics(ctx: Context) raises -> List[String]

Return the names of all built-in Z3 tactics.

probes

def probes(ctx: Context) raises -> List[String]

Return the names of all built-in Z3 probes.

tactic_description

def tactic_description(name: String, ctx: Context) raises -> String

Return the Z3 description string for tactic name.

probe_description

def probe_description(name: String, ctx: Context) raises -> String

Return the Z3 description string for probe name.

solve_using

def solve_using(tactic: Tactic, *constraints: Ast) raises -> Optional[Model]
def solve_using(tactic: Tactic, constraints: List[Ast]) raises -> Optional[Model]

Check a list of constraints using tactic.solver() and return a Model if satisfiable.

is_app

def is_app(a: Ast) raises -> Bool

Return True if a is an application AST (constants and compound terms).

is_app_of

def is_app_of(a: Ast, k: DeclKind) raises -> Bool

Return True if a is an application AST with declaration kind k.

is_const

def is_const(a: Ast) raises -> Bool

Return True if a is a 0-arity application (constant or numeral).

is_var

def is_var(a: Ast) raises -> Bool

Return True if a is a de Bruijn bound variable AST.

is_quantifier

def is_quantifier(a: Ast) raises -> Bool

Return True if a is a quantifier (ForAll, Exists, or Lambda).

is_bool

def is_bool(a: Ast) raises -> Bool

Return True if a has Bool sort.

is_true

def is_true(a: Ast) raises -> Bool

Return True if a is the Boolean constant true.

is_false

def is_false(a: Ast) raises -> Bool

Return True if a is the Boolean constant false.

is_int

def is_int(a: Ast) raises -> Bool

Return True if a has Int sort.

is_real

def is_real(a: Ast) raises -> Bool

Return True if a has Real sort.

is_arith

def is_arith(a: Ast) raises -> Bool

Return True if a has Int or Real sort.

is_bv

def is_bv(a: Ast) raises -> Bool

Return True if a has BitVec sort.

is_string

def is_string(a: Ast) raises -> Bool

Return True if a has String sort.

is_seq

def is_seq(a: Ast) raises -> Bool

Return True if a has Seq (including String) sort.

is_re

def is_re(a: Ast) raises -> Bool

Return True if a has regular-expression (Re) sort.

is_array

def is_array(a: Ast) raises -> Bool

Return True if a has Array sort.

is_fp

def is_fp(a: Ast) raises -> Bool

Return True if a has IEEE-754 FloatingPoint sort.

is_finite_field

def is_finite_field(a: Ast) raises -> Bool

Return True if a has FiniteField sort.

is_finite_set

def is_finite_set(a: Ast) raises -> Bool

Return True if a has FiniteSet sort.

is_complex

def is_complex(a: Ast) raises -> Bool

Return True if a has Complex sort.

is_int_value

def is_int_value(a: Ast) raises -> Bool

Return True if a is an Int numeral.

is_rational_value

def is_rational_value(a: Ast) raises -> Bool

Return True if a is a Real rational numeral (not an algebraic irrational).

is_algebraic_value

def is_algebraic_value(a: Ast) raises -> Bool

Return True if a is an irrational real algebraic numeral.

is_bv_value

def is_bv_value(a: Ast) raises -> Bool

Return True if a is a BitVec numeral.

is_string_value

def is_string_value(a: Ast) raises -> Bool

Return True if a is a String literal value.

is_and

def is_and(a: Ast) raises -> Bool

Return True if a is a conjunction (and ...) application.

is_or

def is_or(a: Ast) raises -> Bool

Return True if a is a disjunction (or ...) application.

is_not

def is_not(a: Ast) raises -> Bool

Return True if a is a logical negation (not ...) application.

is_eq

def is_eq(a: Ast) raises -> Bool

Return True if a is an equality (= ...) application.

is_distinct

def is_distinct(a: Ast) raises -> Bool

Return True if a is a distinctness (distinct ...) application.

is_implies

def is_implies(a: Ast) raises -> Bool

Return True if a is an implication (=> ...) application.

is_add

def is_add(a: Ast) raises -> Bool

Return True if a is an arithmetic addition (+ ...) application.

is_sub

def is_sub(a: Ast) raises -> Bool

Return True if a is an arithmetic subtraction (- ...) application.

is_mul

def is_mul(a: Ast) raises -> Bool

Return True if a is an arithmetic multiplication (* ...) application.

is_div

def is_div(a: Ast) raises -> Bool

Return True if a is a real division (/ ...) application.

is_idiv

def is_idiv(a: Ast) raises -> Bool

Return True if a is an integer division (div ...) application.

is_mod

def is_mod(a: Ast) raises -> Bool

Return True if a is an integer modulo (mod ...) application.

is_lt

def is_lt(a: Ast) raises -> Bool

Return True if a is a less-than (< ...) application.

is_le

def is_le(a: Ast) raises -> Bool

Return True if a is a less-than-or-equal (<= ...) application.

is_gt

def is_gt(a: Ast) raises -> Bool

Return True if a is a greater-than (> ...) application.

is_ge

def is_ge(a: Ast) raises -> Bool

Return True if a is a greater-than-or-equal (>= ...) application.

is_select

def is_select(a: Ast) raises -> Bool

Return True if a is an array (select ...) application.

is_store

def is_store(a: Ast) raises -> Bool

Return True if a is an array (store ...) application.

is_to_real

def is_to_real(a: Ast) raises -> Bool

Return True if a is an Int-to-Real conversion (to_real ...) application.

is_to_int

def is_to_int(a: Ast) raises -> Bool

Return True if a is a Real-to-Int conversion (to_int ...) application.

is_is_int

def is_is_int(a: Ast) raises -> Bool

Return True if a is an integrality predicate (is_int ...) application.

Remaining Python Z3 helpers, sort/value predicates & introspection

RealVarVector

def RealVarVector(prefix: String, sz: Int, ctx: Context) raises -> List[Ast]

Alias for RealVector(prefix, sz, ctx).

mk_not

def mk_not(a: Ast) raises -> Ast

Python Z3 alias for Not(a) (Z3_mk_not).

Update

def Update(arr: Ast, idx: Ast, val: Ast) raises -> Ast
def Update(arr: Ast, idx: Int, val: Ast) raises -> Ast
All 7 overloads
def Update(arr: Ast, idx: Ast, val: Ast) raises -> Ast
def Update(arr: Ast, idx: Int, val: Ast) raises -> Ast
def Update(arr: Ast, idx: Ast, val: Int) raises -> Ast
def Update(arr: Ast, idx: Int, val: Int) raises -> Ast
def Update(arr: Ast, idx: Ast, val: Integer) raises -> Ast
def Update(arr: Ast, idx: Ast, val: Rational) raises -> Ast
def Update(arr: Ast, idx: Ast, val: Bool) raises -> Ast

Python Z3 alias for Store(arr, idx, val) (accepts Ast, Int, Integer, Rational, or Bool literals).

substitute_funs

def substitute_funs(a: Ast, from_decls: List[FuncDecl], to_asts: List[Ast]) raises -> Ast
def substitute_funs(a: Ast, from_decl: FuncDecl, to_ast: Ast) raises -> Ast

Replace applications of from_decls[i] in a with to_asts[i] (using Var(0), Var(1), ... for arguments).

num_simplifiers

def num_simplifiers(ctx: Context) raises -> Int

Return the number of built-in Z3 simplifiers.

simplifier_name

def simplifier_name(index: Int, ctx: Context) raises -> String

Return the name of the index-th built-in Z3 simplifier.

simplifier_description

def simplifier_description(name: String, ctx: Context) raises -> String

Return the Z3 description string for simplifier name.

help_simplify

def help_simplify(ctx: Context) raises -> String

Return Z3's help text describing simplify options.

simplify_param_descrs

def simplify_param_descrs(ctx: Context) raises -> ParamDescrs

Return the ParamDescrs accepted by simplify.

describe_tactics

def describe_tactics(ctx: Context) raises -> String

Return a formatted summary of all built-in Z3 tactics and their descriptions.

describe_probes

def describe_probes(ctx: Context) raises -> String

Return a formatted summary of all built-in Z3 probes and their descriptions.

is_arith_sort

def is_arith_sort(s: Sort) raises -> Bool

Return True if s is IntSort or RealSort.

is_array_sort

def is_array_sort(s: Sort) raises -> Bool

Return True if s is an Array sort.

is_bv_sort

def is_bv_sort(s: Sort) raises -> Bool

Return True if s is a BitVector sort.

is_complex_sort

def is_complex_sort(s: Sort) raises -> Bool

Return True if s is a Complex sort.

is_finite_domain_sort

def is_finite_domain_sort(s: Sort) raises -> Bool

Return True if s is a FiniteDomain sort.

is_finite_set_sort

def is_finite_set_sort(s: Sort) raises -> Bool

Return True if s is a FiniteSet sort.

is_fp_sort

def is_fp_sort(s: Sort) raises -> Bool

Return True if s is a FloatingPoint sort.

is_fprm_sort

def is_fprm_sort(s: Sort) raises -> Bool

Return True if s is a FloatingPoint rounding-mode sort.

is_finite_domain

def is_finite_domain(a: Ast) raises -> Bool

Return True if a has FiniteDomain sort.

is_finite_domain_value

def is_finite_domain_value(a: Ast) raises -> Bool

Return True if a is a FiniteDomain numeral.

is_fp_value

def is_fp_value(a: Ast) raises -> Bool

Return True if a is a FloatingPoint numeral.

is_fprm

def is_fprm(a: Ast) raises -> Bool

Return True if a has FloatingPoint rounding-mode sort.

is_fprm_value

def is_fprm_value(a: Ast) raises -> Bool

Return True if a is a FloatingPoint rounding-mode numeral.

is_K

def is_K(a: Ast) raises -> Bool

Return True if a is a Z3 constant array (K(sort, val)).

is_const_array

def is_const_array(a: Ast) raises -> Bool

Alias for is_K(a).

is_as_array

def is_as_array(a: Ast) raises -> Bool

Return True if a is an AsArray(f) expression.

get_as_array_func

def get_as_array_func(a: Ast) raises -> FuncDecl

Return the FuncDecl underlying an AsArray(f) expression.

is_default

def is_default(a: Ast) raises -> Bool

Return True if a is a Default(arr) expression.

is_map

def is_map(a: Ast) raises -> Bool

Return True if a is a Map(f, ...) array expression.

get_map_func

def get_map_func(a: Ast) raises -> FuncDecl

Return the FuncDecl mapped by a Map(f, ...) array expression.

Theories: Strings, Regex, Sets, BitVectors, FPA, Datatypes, Z3 5.x (z3_mojo.theories)

Strings and regular expressions

var code = StringVar("code", ctx)
var pat = Concat(Re("INV-", ctx), Loop(Range("0", "9", ctx), 4, 4))
var s = Solver(ctx)
s.add(InRe(code, pat), Eq(Length(code), 8))

Length

def Length(s: Ast) raises -> Ast

Return the length of String or Seq s as an Int AST.

Contains

def Contains(s: Ast, sub: Ast) raises -> Ast
def Contains(s: Ast, sub: String) raises -> Ast

Return a Bool formula asserting s contains substring/subsequence sub (Ast or String).

PrefixOf

def PrefixOf(prefix: Ast, s: Ast) raises -> Ast
def PrefixOf(prefix: String, s: Ast) raises -> Ast

Return a Bool formula asserting prefix (Ast or String) is a prefix of s.

SuffixOf

def SuffixOf(suffix: Ast, s: Ast) raises -> Ast
def SuffixOf(suffix: String, s: Ast) raises -> Ast

Return a Bool formula asserting suffix (Ast or String) is a suffix of s.

IndexOf

def IndexOf(s: Ast, sub: Ast, offset: Ast) raises -> Ast
def IndexOf(s: Ast, sub: Ast, offset: Int = 0) raises -> Ast
def IndexOf(s: Ast, sub: String, offset: Int = 0) raises -> Ast

Return the first index of sub (Ast or String) in s starting at offset (Ast or Int), or -1.

SubString

def SubString(s: Ast, offset: Ast, length: Ast) raises -> Ast
def SubString(s: Ast, offset: Int, length: Int) raises -> Ast
All 4 overloads
def SubString(s: Ast, offset: Ast, length: Ast) raises -> Ast
def SubString(s: Ast, offset: Int, length: Int) raises -> Ast
def SubString(s: Ast, offset: Ast, length: Int) raises -> Ast
def SubString(s: Ast, offset: Int, length: Ast) raises -> Ast

Extract a substring/subsequence of s starting at offset with length (Ast or Int).

Replace

def Replace(s: Ast, src: Ast, dst: Ast) raises -> Ast
def Replace(s: Ast, src: String, dst: String) raises -> Ast

Replace the first occurrence of src in s with dst (accepts Ast or String arguments).

StrToInt

def StrToInt(s: Ast) raises -> Ast

Convert non-negative decimal String s to Int (-1 if invalid).

IntToStr

def IntToStr(n: Ast) raises -> Ast

Convert non-negative Int n to its decimal String representation.

Re

def Re(s: Ast) raises -> Ast
def Re(s: String, ctx: Context) raises -> Ast

Lift String/Seq AST s into a regular expression matching s.

InRe

def InRe(s: Ast, re: Ast) raises -> Ast

Return a Bool formula asserting String/Seq s matches regex re.

Union

def Union(*res: Ast) raises -> Ast
def Union(res: List[Ast]) raises -> Ast

Regular-expression union from a non-empty list of regex ASTs.

Intersect

def Intersect(*res: Ast) raises -> Ast
def Intersect(res: List[Ast]) raises -> Ast

Regular-expression intersection from a non-empty list of regex ASTs.

Star

def Star(r: Ast) raises -> Ast

Kleene star r*.

Plus

def Plus(r: Ast) raises -> Ast

Kleene plus r+.

Option

def Option(r: Ast) raises -> Ast

Optional regex r?.

Complement

def Complement(r: Ast) raises -> Ast

Regular-expression complement ~r.

Range

def Range(lo: Ast, hi: Ast) raises -> Ast
def Range(lo: String, hi: String, ctx: Context) raises -> Ast

Character-range regex matching characters between lo and hi (e.g. Range("a", "z", ctx)).

Loop

def Loop(r: Ast, lo: Int, hi: Int = 0) raises -> Ast

Bounded regex repetition r{lo, hi} (hi = 0 means unbounded upper limit).

Arrays and Sets

var idx = IntVar("idx", ctx)
var base = Store(K(IntSort(ctx), IntVal(0, ctx)), 7, 99)
var shifted = Lambda(idx, base[idx] + 1)
var u = SetUnion(SetAdd(EmptySet(IntSort(ctx)), IntVal(1, ctx)), EmptySet(IntSort(ctx)))

K

def K(domain: Sort, val: Ast) raises -> Ast

Build a constant array mapping every key of domain to val.

Default

def Default(arr: Ast) raises -> Ast

Return the default value of an array (when defined).

Lambda

def Lambda(bound: Ast, body: Ast) raises -> Ast
def Lambda(bounds: List[Ast], body: Ast) raises -> Ast

Build a multi-variable array lambda over bounds.

EmptySet

def EmptySet(elem_sort: Sort) raises -> Ast

Create the empty set over elem_sort.

FullSet

def FullSet(elem_sort: Sort) raises -> Ast

Create the universal (full) set over elem_sort.

SetAdd

def SetAdd(s: Ast, elem: Ast) raises -> Ast

Return s U {elem}.

SetDel

def SetDel(s: Ast, elem: Ast) raises -> Ast

Return s \\ {elem}.

SetUnion

def SetUnion(*sets: Ast) raises -> Ast
def SetUnion(sets: List[Ast]) raises -> Ast

Return the union of a non-empty list of sets.

SetIntersect

def SetIntersect(*sets: Ast) raises -> Ast
def SetIntersect(sets: List[Ast]) raises -> Ast

Return the intersection of a non-empty list of sets.

SetDifference

def SetDifference(s1: Ast, s2: Ast) raises -> Ast

Return the set difference s1 \\ s2.

SetComplement

def SetComplement(s: Ast) raises -> Ast

Return the set complement of s.

IsMember

def IsMember(elem: Ast, s: Ast) raises -> Ast

Return a Bool formula asserting elem in s.

IsSubset

def IsSubset(s1: Ast, s2: Ast) raises -> Ast

Return a Bool formula asserting s1 subseteq s2.

BitVector extras and overflow / underflow predicates

var a = BitVec("a", 8, ctx)
var b = BitVec("b", 8, ctx)
var s = Solver(ctx)
s.add(ULE(a, BitVecVal(100, 8, ctx)), ULE(b, BitVecVal(100, 8, ctx)), Not(BVAddNoOverflow(a, b, False)))

BV2Int

def BV2Int(a: Ast, is_signed: Bool = False) raises -> Ast

Convert BitVector a to Int (unsigned by default, or two's-complement if is_signed).

Int2BV

def Int2BV(a: Ast, bits: Int) raises -> Ast

Convert Int a to a BitVector of width bits.

RotateLeft

def RotateLeft(a: Ast, n: Int) raises -> Ast

Rotate BitVector a left by n bits.

RotateRight

def RotateRight(a: Ast, n: Int) raises -> Ast

Rotate BitVector a right by n bits.

RepeatBitVec

def RepeatBitVec(n: Int, a: Ast) raises -> Ast

Repeat BitVector a n times by concatenation.

SRem

def SRem(a: Ast, b: Ast) raises -> Ast
def SRem(a: Ast, b: Int) raises -> Ast

Signed BitVector remainder with Int literal RHS coerced to the sort of a.

BVRedAnd

def BVRedAnd(a: Ast) raises -> Ast

Bitwise AND reduction of all bits of a to a 1-bit BitVector.

BVRedOr

def BVRedOr(a: Ast) raises -> Ast

Bitwise OR reduction of all bits of a to a 1-bit BitVector.

BVAddNoOverflow

def BVAddNoOverflow(a: Ast, b: Ast, is_signed: Bool) raises -> Ast

Predicate asserting a + b does not overflow.

BVAddNoUnderflow

def BVAddNoUnderflow(a: Ast, b: Ast) raises -> Ast

Predicate asserting signed a + b does not underflow.

BVSubNoOverflow

def BVSubNoOverflow(a: Ast, b: Ast) raises -> Ast

Predicate asserting signed a - b does not overflow.

BVSubNoUnderflow

def BVSubNoUnderflow(a: Ast, b: Ast, is_signed: Bool) raises -> Ast

Predicate asserting a - b does not underflow.

BVMulNoOverflow

def BVMulNoOverflow(a: Ast, b: Ast, is_signed: Bool) raises -> Ast

Predicate asserting a * b does not overflow.

BVMulNoUnderflow

def BVMulNoUnderflow(a: Ast, b: Ast) raises -> Ast

Predicate asserting signed a * b does not underflow.

BVSDivNoOverflow

def BVSDivNoOverflow(a: Ast, b: Ast) raises -> Ast

Predicate asserting signed a / b does not overflow (MIN_INT / -1).

BVSNegNoOverflow

def BVSNegNoOverflow(a: Ast) raises -> Ast

Predicate asserting signed -a does not overflow (-MIN_INT).

IEEE-754 Floating-Point Arithmetic (FPA)

var f32 = Float32Sort(ctx)
var rm = RNE(ctx)
var a = FP("a", f32)
var b = FP("b", f32)
var sum_ab = fpAdd(rm, a, b)

Float16Sort

def Float16Sort(ctx: Context) raises -> Sort

IEEE-754 binary16 (half-precision) floating-point sort.

Float32Sort

def Float32Sort(ctx: Context) raises -> Sort

IEEE-754 binary32 (single-precision) floating-point sort.

Float64Sort

def Float64Sort(ctx: Context) raises -> Sort

IEEE-754 binary64 (double-precision) floating-point sort.

Float128Sort

def Float128Sort(ctx: Context) raises -> Sort

IEEE-754 binary128 (quadruple-precision) floating-point sort.

FloatHalf

def FloatHalf(ctx: Context) raises -> Sort

Alias for Float16Sort(ctx) (IEEE-754 binary16).

FloatSingle

def FloatSingle(ctx: Context) raises -> Sort

Alias for Float32Sort(ctx) (IEEE-754 binary32).

FloatDouble

def FloatDouble(ctx: Context) raises -> Sort

Alias for Float64Sort(ctx) (IEEE-754 binary64).

FloatQuadruple

def FloatQuadruple(ctx: Context) raises -> Sort

Alias for Float128Sort(ctx) (IEEE-754 binary128).

FPSort

def FPSort(ebits: Int, sbits: Int, ctx: Context) raises -> Sort

IEEE-754 floating-point sort with ebits exponent bits and sbits significand bits.

RNE

def RNE(ctx: Context) raises -> Ast

Rounding mode: Round Nearest Ties to Even.

RNA

def RNA(ctx: Context) raises -> Ast

Rounding mode: Round Nearest Ties to Away.

RTP

def RTP(ctx: Context) raises -> Ast

Rounding mode: Round Toward Positive.

RTN

def RTN(ctx: Context) raises -> Ast

Rounding mode: Round Toward Negative.

RTZ

def RTZ(ctx: Context) raises -> Ast

Rounding mode: Round Toward Zero.

FP

def FP(name: String, sort: Sort) raises -> Ast

Create a floating-point constant of sort named name.

FPs

def FPs(names: String, sort: Sort) raises -> List[Ast]

Create whitespace-separated floating-point variables of sort.

FPVal

def FPVal(v: Float64, sort: Sort) raises -> Ast
def FPVal(v: Float32, sort: Sort) raises -> Ast
def FPVal(v: Int, sort: Sort) raises -> Ast

Create an IEEE-754 floating-point numeral from Float64.

fpNaN

def fpNaN(sort: Sort) raises -> Ast

Create an IEEE-754 NaN numeral of sort.

fpPlusInfinity

def fpPlusInfinity(sort: Sort) raises -> Ast

Create +oo of sort.

fpMinusInfinity

def fpMinusInfinity(sort: Sort) raises -> Ast

Create -oo of sort.

fpPlusZero

def fpPlusZero(sort: Sort) raises -> Ast

Create +0.0 of sort.

fpMinusZero

def fpMinusZero(sort: Sort) raises -> Ast

Create -0.0 of sort.

fpAdd

def fpAdd(rm: Ast, a: Ast, b: Ast) raises -> Ast

IEEE-754 addition with rounding mode rm.

fpSub

def fpSub(rm: Ast, a: Ast, b: Ast) raises -> Ast

IEEE-754 subtraction with rounding mode rm.

fpMul

def fpMul(rm: Ast, a: Ast, b: Ast) raises -> Ast

IEEE-754 multiplication with rounding mode rm.

fpDiv

def fpDiv(rm: Ast, a: Ast, b: Ast) raises -> Ast

IEEE-754 division with rounding mode rm.

fpSqrt

def fpSqrt(rm: Ast, a: Ast) raises -> Ast

IEEE-754 square root with rounding mode rm.

fpFMA

def fpFMA(rm: Ast, a: Ast, b: Ast, c: Ast) raises -> Ast

IEEE-754 fused multiply-add a * b + c with rounding mode rm.

fpRem

def fpRem(a: Ast, b: Ast) raises -> Ast

IEEE-754 remainder.

fpAbs

def fpAbs(a: Ast) raises -> Ast

IEEE-754 absolute value.

fpNeg

def fpNeg(a: Ast) raises -> Ast

IEEE-754 negation.

fpMin

def fpMin(a: Ast, b: Ast) raises -> Ast

IEEE-754 minimum.

fpMax

def fpMax(a: Ast, b: Ast) raises -> Ast

IEEE-754 maximum.

fpRoundToIntegral

def fpRoundToIntegral(rm: Ast, a: Ast) raises -> Ast

Round IEEE-754 float a to an integral float under rounding mode rm.

fpEQ

def fpEQ(a: Ast, b: Ast) raises -> Ast

IEEE-754 numerical equality (NaN != NaN, +0.0 == -0.0).

fpNEQ

def fpNEQ(a: Ast, b: Ast) raises -> Ast

Negation of IEEE-754 numerical equality.

fpLT

def fpLT(a: Ast, b: Ast) raises -> Ast

IEEE-754 less-than.

fpLEQ

def fpLEQ(a: Ast, b: Ast) raises -> Ast

IEEE-754 less-than-or-equal.

fpGT

def fpGT(a: Ast, b: Ast) raises -> Ast

IEEE-754 greater-than.

fpGEQ

def fpGEQ(a: Ast, b: Ast) raises -> Ast

IEEE-754 greater-than-or-equal.

fpIsNaN

def fpIsNaN(a: Ast) raises -> Ast

Predicate asserting IEEE-754 float a is NaN (Z3_mk_fpa_is_nan).

fpIsInf

def fpIsInf(a: Ast) raises -> Ast

Predicate asserting IEEE-754 float a is infinite (Z3_mk_fpa_is_infinite).

fpIsZero

def fpIsZero(a: Ast) raises -> Ast

Predicate asserting IEEE-754 float a is +0.0 or -0.0 (Z3_mk_fpa_is_zero).

fpIsNormal

def fpIsNormal(a: Ast) raises -> Ast

Predicate asserting IEEE-754 float a is a normal floating-point number (Z3_mk_fpa_is_normal).

fpIsSubnormal

def fpIsSubnormal(a: Ast) raises -> Ast

Predicate asserting IEEE-754 float a is a subnormal floating-point number (Z3_mk_fpa_is_subnormal).

fpIsPositive

def fpIsPositive(a: Ast) raises -> Ast

Predicate asserting IEEE-754 float a is positive (Z3_mk_fpa_is_positive).

fpIsNegative

def fpIsNegative(a: Ast) raises -> Ast

Predicate asserting IEEE-754 float a is negative (Z3_mk_fpa_is_negative).

fpToReal

def fpToReal(a: Ast) raises -> Ast

Convert IEEE-754 float a to Real.

fpToFP

def fpToFP(rm: Ast, a: Ast, sort: Sort) raises -> Ast

Convert an IEEE-754 float to target sort under rounding mode rm.

fpRealToFP

def fpRealToFP(rm: Ast, a: Ast, sort: Sort) raises -> Ast

Convert a Real AST to IEEE-754 sort under rounding mode rm.

fpSignedToFP

def fpSignedToFP(rm: Ast, bv: Ast, sort: Sort) raises -> Ast

Convert a signed BitVector to IEEE-754 sort under rounding mode rm.

fpUnsignedToFP

def fpUnsignedToFP(rm: Ast, bv: Ast, sort: Sort) raises -> Ast

Convert an unsigned BitVector to IEEE-754 sort under rounding mode rm.

fpToFPUnsigned

def fpToFPUnsigned(rm: Ast, bv: Ast, sort: Sort) raises -> Ast

Python Z3 alias for fpUnsignedToFP(rm, bv, sort).

fpFPToFP

def fpFPToFP(rm: Ast, a: Ast, sort: Sort) raises -> Ast

Python Z3 alias for fpToFP(rm, a, sort) (FP-to-FP conversion).

fpBVToFP

def fpBVToFP(bv: Ast, sort: Sort) raises -> Ast

Reinterpret IEEE-754 bit pattern bv as floating-point sort.

fpToIEEEBV

def fpToIEEEBV(a: Ast) raises -> Ast

Reinterpret IEEE-754 float a as its bit-vector representation.

fpToSBV

def fpToSBV(rm: Ast, a: Ast, bits: Int) raises -> Ast

Convert IEEE-754 float a to signed BitVector of width bits.

fpToUBV

def fpToUBV(rm: Ast, a: Ast, bits: Int) raises -> Ast

Convert IEEE-754 float a to unsigned BitVector of width bits.

Algebraic Datatypes, EnumSort, TupleSort, and Recursive Functions

var pair_dt = Datatype("IntPair", ctx)
pair_dt.declare("mk_pair", [DatatypeField.of("fst", IntSort(ctx)), DatatypeField.of("snd", IntSort(ctx))])
var res = CreateDatatypes([pair_dt])[0]
var mk_pair = res.constructor("mk_pair")

DatatypeResult

struct DatatypeResult(Movable)

Result of Datatype.create(), holding the sort, constructors, recognizers, and accessors.

DatatypeField

struct DatatypeField(Copyable, Movable)

Field descriptor for Datatype and mutually recursive CreateDatatypes.

Datatype

struct Datatype(Copyable, Movable)

Builder for single (optionally self-recursive) or mutually recursive algebraic datatypes.

Pass None as a field sort in declare, or use DatatypeField.self_ref / DatatypeField.mutual_ref, to express self- or mutual recursion.

CreateDatatypes

def CreateDatatypes(datatypes: List[Datatype]) raises -> List[DatatypeResult]

Finalize a mutually recursive group of Datatype builders in one Z3_mk_datatypes call.

DeclareTypeVar

def DeclareTypeVar(name: String, ctx: Context) raises -> Sort

Create a sort type variable for polymorphic datatypes (Z3_mk_type_variable).

DatatypeSort

def DatatypeSort(name: String, ctx: Context) raises -> Sort
def DatatypeSort(name: String, params: List[Sort], ctx: Context) raises -> Sort

Instantiate or reference a parametric datatype sort name(params...) (Z3_mk_datatype_sort).

CreatePolymorphicDatatype

def CreatePolymorphicDatatype(dt: Datatype, type_params: List[Sort]) raises -> DatatypeResult

Finalize a polymorphic Datatype parameterized by type_params (Z3_mk_polymorphic_datatype).

EnumSort

def EnumSort(name: String, values: List[String], ctx: Context) raises -> Tuple[Sort, List[Ast]]

Create a finite enumeration sort returning (sort, value_asts).

TupleSort

def TupleSort(name: String, field_names: List[String], field_sorts: List[Sort], ctx: Context) raises -> Tuple[Sort, FuncDecl, List[FuncDecl]]

Create a tuple sort returning (sort, constructor_decl, projection_decls).

RecFunction

def RecFunction(name: String, domain: Sort, range_: Sort) raises -> FuncDecl
def RecFunction(name: String, d1: Sort, d2: Sort, range_: Sort) raises -> FuncDecl
def RecFunction(name: String, domain: List[Sort], range_: Sort) raises -> FuncDecl

Declare a binary recursive function name: (d1, d2) -> range_.

RecAddDefinition

def RecAddDefinition(f: FuncDecl, arg: Ast, body: Ast) raises
def RecAddDefinition(f: FuncDecl, args: List[Ast], body: Ast) raises

Add the defining equation f(args...) = body for recursive function f.

Finite Fields (GF(p))

var gf17 = FiniteFieldSort(17, ctx)
var fx = FiniteFieldElem("fx", gf17)
var s = SolverFor("QF_FF", ctx)
s.add(Eq(fx * fx, FiniteFieldVal(2, gf17)))

FiniteFieldSort

def FiniteFieldSort(prime: Int, ctx: Context) raises -> Sort
def FiniteFieldSort(prime: Integer, ctx: Context) raises -> Sort
def FiniteFieldSort(prime: String, ctx: Context) raises -> Sort

Create the prime finite field sort GF(prime) for an arbitrary-precision prime.

FiniteFieldElem

def FiniteFieldElem(name: String, sort: Sort) raises -> Ast

Create a finite-field variable of sort named name.

FiniteFieldElems

def FiniteFieldElems(names: String, sort: Sort) raises -> List[Ast]

Create whitespace-separated finite-field variables of sort.

FiniteFieldVal

def FiniteFieldVal(val: Int, sort: Sort) raises -> Ast
def FiniteFieldVal(val: Integer, sort: Sort) raises -> Ast
def FiniteFieldVal(val: String, sort: Sort) raises -> Ast

Create a finite-field numeral of sort from apn_mojo.Integer.

FiniteFieldBitsum

def FiniteFieldBitsum(bits: List[Ast]) raises -> Ast

Compute sum(2^i * bits[i]) in a finite field (Z3_mk_ff_bitsum).

Finite Sets (with exact cardinality)

var u = FiniteSetUnion(Singleton(IntVal(1, ctx)), Singleton(IntVal(2, ctx)))
var s = Solver(ctx)
s.add(FiniteSetMember(IntVal(2, ctx), u), Eq(FiniteSetSize(u), 2))

FiniteSetSort

def FiniteSetSort(elem_sort: Sort) raises -> Sort

Create a Z3 finite-set sort over elem_sort (supports FiniteSetSize).

FiniteSetEmpty

def FiniteSetEmpty(set_sort: Sort) raises -> Ast

Create the empty finite set of set_sort.

FiniteSetSingleton

def FiniteSetSingleton(elem: Ast) raises -> Ast

Create the singleton finite set {elem}.

Singleton

def Singleton(elem: Ast) raises -> Ast

Python Z3 alias for FiniteSetSingleton(elem).

FiniteSetUnion

def FiniteSetUnion(s1: Ast, s2: Ast) raises -> Ast

Return the union of two finite sets.

FiniteSetIntersect

def FiniteSetIntersect(s1: Ast, s2: Ast) raises -> Ast

Return the intersection of two finite sets.

FiniteSetDifference

def FiniteSetDifference(s1: Ast, s2: Ast) raises -> Ast

Return the difference s1 \\ s2 of two finite sets.

FiniteSetMember

def FiniteSetMember(elem: Ast, s: Ast) raises -> Ast

Predicate asserting elem in s for a finite set s.

FiniteSetSubset

def FiniteSetSubset(s1: Ast, s2: Ast) raises -> Ast

Predicate asserting s1 subseteq s2 for finite sets.

FiniteSetSize

def FiniteSetSize(s: Ast) raises -> Ast

Return the exact cardinality |s| as an Int AST.

FiniteSetRange

def FiniteSetRange(low: Ast, high: Ast) raises -> Ast

Create the finite integer interval set {low, ..., high}.

FiniteSetMap

def FiniteSetMap(f: Ast, s: Ast) raises -> Ast

Map array/lambda function f over finite set s.

FiniteSetFilter

def FiniteSetFilter(f: Ast, s: Ast) raises -> Ast

Filter finite set s by predicate array/lambda f.

Complex Numbers

ComplexSort

def ComplexSort(ctx: Context) raises -> Sort

Return Z3's built-in Complex number sort.

Complex

def Complex(name: String, ctx: Context) raises -> Ast

Create a Complex variable named name.

Complexes

def Complexes(names: String, ctx: Context) raises -> List[Ast]

Create whitespace-separated Complex variables.

ComplexVal

def ComplexVal(re: Ast, im: Ast) raises -> Ast
def ComplexVal(re: Int, im: Int, ctx: Context) raises -> Ast
def ComplexVal(re: Rational, im: Rational, ctx: Context) raises -> Ast

Build exact complex numeral re + im * i from apn_mojo.Rationals.

RealPart

def RealPart(z: Ast) raises -> Ast

Extract the real part Re(z) of a Complex AST.

ImagPart

def ImagPart(z: Ast) raises -> Ast

Extract the imaginary part Im(z) of a Complex AST.

Special Order and Graph Relations

LinearOrder

def LinearOrder(sort: Sort, id: Int = 0) raises -> FuncDecl

Create a built-in linear-order relation over sort.

PartialOrder

def PartialOrder(sort: Sort, id: Int = 0) raises -> FuncDecl

Create a built-in partial-order relation over sort.

TreeOrder

def TreeOrder(sort: Sort, id: Int = 0) raises -> FuncDecl

Create a built-in tree-order relation over sort.

PiecewiseLinearOrder

def PiecewiseLinearOrder(sort: Sort, id: Int = 0) raises -> FuncDecl

Create a built-in piecewise-linear-order relation over sort.

TransitiveClosure

def TransitiveClosure(rel: FuncDecl) raises -> FuncDecl

Create the transitive closure of binary predicate rel.

Additional Python Z3 theory helpers (BV, Seq/Char/Re, FPA, FiniteDomain)

BvNand

def BvNand(a: Ast, b: Ast) raises -> Ast

BitVector bitwise NAND (Z3_mk_bvnand).

BvNor

def BvNor(a: Ast, b: Ast) raises -> Ast

BitVector bitwise NOR (Z3_mk_bvnor).

BvXnor

def BvXnor(a: Ast, b: Ast) raises -> Ast

BitVector bitwise XNOR (Z3_mk_bvxnor).

LastIndexOf

def LastIndexOf(s: Ast, sub: Ast) raises -> Ast
def LastIndexOf(s: Ast, sub: String) raises -> Ast

Return the last index of literal substring sub in String s (or -1).

SubSeq

def SubSeq(s: Ast, offset: Ast, length: Ast) raises -> Ast
def SubSeq(s: Ast, offset: Int, length: Int) raises -> Ast

Extract a subsequence of s starting at offset with length (Ast or Int).

Unit

def Unit(elem: Ast) raises -> Ast

Create a singleton sequence [elem] (Z3_mk_seq_unit).

Empty

def Empty(sort: Sort) raises -> Ast

Create an empty sequence or empty regex of sort.

Full

def Full(re_sort: Sort) raises -> Ast

Create the universal regex matching all strings/sequences of re_sort.

AllChar

def AllChar(re_sort: Sort) raises -> Ast

Create the wildcard regex matching any single character of re_sort.

Diff

def Diff(r1: Ast, r2: Ast) raises -> Ast

Regular-expression difference r1 \\ r2 (Z3_mk_re_diff).

ReSort

def ReSort(seq_sort: Sort) raises -> Sort

Create the regular-expression sort over seq_sort.

StrToCode

def StrToCode(s: Ast) raises -> Ast

Return the Unicode code point of a 1-character string s (-1 otherwise).

StrFromCode

def StrFromCode(n: Ast) raises -> Ast

Convert Unicode code point Int n to a 1-character string.

SeqMap

def SeqMap(f: Ast, s: Ast) raises -> Ast

Map array/lambda function f over sequence s (Z3_mk_seq_map).

SeqMapI

def SeqMapI(f: Ast, i: Ast, s: Ast) raises -> Ast

Map indexed function f over sequence s starting at index i (Z3_mk_seq_mapi).

SeqFoldLeft

def SeqFoldLeft(f: Ast, init: Ast, s: Ast) raises -> Ast

Left-fold sequence s with binary function f and initial accumulator init.

SeqFoldLeftI

def SeqFoldLeftI(f: Ast, i: Ast, init: Ast, s: Ast) raises -> Ast

Indexed left-fold over sequence s.

SeqPower

def SeqPower(s: Ast, n: Ast) raises -> Ast

Repeat sequence s n times (Z3_mk_seq_power).

CharSort

def CharSort(ctx: Context) raises -> Sort

Return Z3's Unicode Character sort.

CharVal

def CharVal(code_point: Int, ctx: Context) raises -> Ast

Create a Character literal from Unicode code_point.

CharToInt

def CharToInt(ch: Ast) raises -> Ast

Convert Character AST ch to its Int Unicode code point.

CharToBv

def CharToBv(ch: Ast) raises -> Ast

Convert Character AST ch to a BitVector.

CharFromBv

def CharFromBv(bv: Ast) raises -> Ast

Convert BitVector AST bv to a Character.

CharIsDigit

def CharIsDigit(ch: Ast) raises -> Ast

Predicate asserting Character AST ch is an ASCII decimal digit.

RoundNearestTiesToEven

def RoundNearestTiesToEven(ctx: Context) raises -> Ast

Rounding mode: Round Nearest Ties to Even (alias for RNE(ctx)).

RoundNearestTiesToAway

def RoundNearestTiesToAway(ctx: Context) raises -> Ast

Rounding mode: Round Nearest Ties to Away (alias for RNA(ctx)).

RoundTowardPositive

def RoundTowardPositive(ctx: Context) raises -> Ast

Rounding mode: Round Toward Positive (alias for RTP(ctx)).

RoundTowardNegative

def RoundTowardNegative(ctx: Context) raises -> Ast

Rounding mode: Round Toward Negative (alias for RTN(ctx)).

RoundTowardZero

def RoundTowardZero(ctx: Context) raises -> Ast

Rounding mode: Round Toward Zero (alias for RTZ(ctx)).

fpFP

def fpFP(sgn: Ast, exp: Ast, sig: Ast) raises -> Ast

Assemble an IEEE-754 float from sign (1-bit BV), exponent BV, and significand BV.

fpInfinity

def fpInfinity(sort: Sort, negative: Bool) raises -> Ast

Create +oo (negative=False) or -oo (negative=True) of sort.

fpZero

def fpZero(sort: Sort, negative: Bool) raises -> Ast

Create +0.0 (negative=False) or -0.0 (negative=True) of sort.

FiniteDomainSort

def FiniteDomainSort(name: String, size: Int, ctx: Context) raises -> Sort

Create a finite-domain sort of cardinality size.

FiniteDomainVal

def FiniteDomainVal(val: Int, sort: Sort) raises -> Ast

Create a finite-domain numeral of sort.

Callback Helpers (z3_mojo.callbacks)

General

var s = SimpleSolver(ctx)
var counter = ArcPointer(MyClauseHandler())
OnClause(s, counter)

PropagateFunction

def PropagateFunction(name: String, domain: List[Sort], range_: Sort) raises -> FuncDecl
def PropagateFunction(name: String, d1: Sort, range_: Sort) raises -> FuncDecl
def PropagateFunction(name: String, d1: Sort, d2: Sort, range_: Sort) raises -> FuncDecl

Declare a function tracked by a UserPropagator's created callback (Z3_solver_propagate_declare).

OnClause

def OnClause[H: ClauseHandler](solver: Solver, handler: ArcPointer[H]) raises

Register a ClauseHandler on solver (Python Z3 OnClause(s, cb)).

z3_mojo v5.3.3.0 for Mojo 1.2 and Z3 5.3.3 · Apache License 2.0 with LLVM Exceptions · Source on GitHub