- High-Level API: Z3Py-like object-oriented interface (recommended)
- Low-Level API: Direct C API bindings
Initialization
init()
Initializes the Z3 WebAssembly module.Context: High-level API context constructorem: Emscripten module for advanced controlZ3: Low-level C-like API
Context
Creates an isolated Z3 context. All operations must use objects from the same context.Context(name)
name: String identifier for type safety (TypeScript only)
Sorts (Types)
Z3 sorts represent the types of expressions.Integer and Real
Integer arithmetic sort
Real arithmetic sort
Int.const(name: string): Create integer variableInt.val(value: number | bigint): Create integer constantReal.const(name: string): Create real variableReal.val(numerator: number, denominator?: number): Create rational constant
Boolean
Boolean sort for true/false values
Bool.const(name: string): Create boolean variableBool.val(value: boolean): Create boolean constant
Bit-Vectors
Fixed-width bit-vector sort
BitVec.const(name: string, bits: number): Create bit-vector variableBitVec.val(value: number | bigint, bits: number): Create bit-vector constant
Arrays
Array sort with index and value types
Array.sort(indexSort: Sort, valueSort: Sort): Create array sortArray.const(name: string, indexSort: Sort, valueSort: Sort): Create array variableArray.K(domain: Sort, value: Expr): Create constant array
Expressions
All Z3 values and formulas are expressions.Arithmetic Operations
Addition:
a.add(b, c, ...)Supports multiple arguments for efficiency.Subtraction:
a.sub(b)Multiplication:
a.mul(b, c, ...)Division:
a.div(b)Integer division for Int, real division for Real.Modulo:
a.mod(b)Integer expressions only.Power:
a.pow(b)Comparison Operations
Equality:
a.eq(b)Returns boolean expression.Inequality:
a.neq(b)Equivalent to Not(a.eq(b)).Less than:
a.lt(b)Less than or equal:
a.le(b)Greater than:
a.gt(b)Greater than or equal:
a.ge(b)Boolean Operations
These are provided as both methods and standalone functions:Conjunction:
And(a, b, c, ...)Returns true if all arguments are true.Disjunction:
Or(a, b, c, ...)Returns true if any argument is true.Negation:
Not(a)Implication:
Implies(a, b)Equivalent to Or(Not(a), b).If-and-only-if:
Iff(a, b)True when both have same truth value.Exclusive or:
Xor(a, b)Bit-Vector Operations
Bit-vector addition:
a.add(b)Bit-vector subtraction:
a.sub(b)Bit-vector multiplication:
a.mul(b)Unsigned division:
a.udiv(b)Signed division:
a.sdiv(b)Unsigned remainder:
a.urem(b)Bitwise AND:
a.and(b)Bitwise OR:
a.or(b)Bitwise XOR:
a.xor(b)Bitwise NOT:
a.not()Shift left:
a.shl(b)Logical shift right:
a.lshr(b)Arithmetic shift right:
a.ashr(b)Array Operations
Array read:
arr.select(index)Returns value at index.Array write:
arr.store(index, value)Returns new array with updated value.Solver
The solver checks satisfiability of constraints.new Solver()
Creates a new solver instance.Methods
'sat': Satisfiable (solution exists)'unsat': Unsatisfiable (no solution)'unknown': Solver could not determine
sat result.Throws: Error if called before check() or if result is not sat.num: Number of scopes to pop (default: 1)
Model
Represents a solution (variable assignments).Methods
expr: Expression to evaluatemodelCompletion: If true, assign default values to unbound variables (default: false)
Simplifier
Simplifiers preprocess expressions before solving.new Simplifier(name)
Params
Parameter sets for configuring solvers and tactics.new Params()
Tactic
Tactics are solvers with specific strategies.new Tactic(name)
'simplify': Simplify expressions'solve-eqs': Solve equations'qe': Quantifier elimination'sat': SAT solver'smt': SMT solver
Low-Level API
The low-level API provides direct access to Z3’s C API.Differences from C API
Out Parameters
Out Parameters
C functions with out parameters return objects:
Arrays
Arrays
Array lengths are inferred:
Integers
Integers
- JavaScript
numberforint,unsigned,float,double - JavaScript
BigIntforint64_t,uint64_t
Null Pointers
Null Pointers
Types ending in
_opt accept/return null:Async Functions
Async Functions
Long-running operations are async:
Z3_simplifyZ3_solver_checkZ3_tactic_apply- And others (see installation page)
Example
Type Definitions
Full TypeScript definitions are included:Further Reading
Getting Started
Practical examples and tutorials
C API Docs
Low-level C API reference
TypeDoc
Auto-generated API documentation
GitHub Examples
More code examples
