Skip to main content
Z3’s JavaScript bindings provide two APIs:
  1. High-Level API: Z3Py-like object-oriented interface (recommended)
  2. Low-Level API: Direct C API bindings
This reference covers the high-level API. For the low-level API, see the C API documentation.

Initialization

init()

Initializes the Z3 WebAssembly module.
Returns: Promise resolving to:
  • Context: High-level API context constructor
  • em: Emscripten module for advanced control
  • Z3: Low-level C-like API
Example:

Context

Creates an isolated Z3 context. All operations must use objects from the same context.

Context(name)

Parameters:
  • name: String identifier for type safety (TypeScript only)
Returns: Object containing all Z3 operations and types Example:

Sorts (Types)

Z3 sorts represent the types of expressions.

Integer and Real

Sort
Integer arithmetic sort
Sort
Real arithmetic sort
Methods:
  • Int.const(name: string): Create integer variable
  • Int.val(value: number | bigint): Create integer constant
  • Real.const(name: string): Create real variable
  • Real.val(numerator: number, denominator?: number): Create rational constant

Boolean

Sort
Boolean sort for true/false values
Methods:
  • Bool.const(name: string): Create boolean variable
  • Bool.val(value: boolean): Create boolean constant

Bit-Vectors

Sort
Fixed-width bit-vector sort
Methods:
  • BitVec.const(name: string, bits: number): Create bit-vector variable
  • BitVec.val(value: number | bigint, bits: number): Create bit-vector constant
Example:

Arrays

Sort
Array sort with index and value types
Methods:
  • Array.sort(indexSort: Sort, valueSort: Sort): Create array sort
  • Array.const(name: string, indexSort: Sort, valueSort: Sort): Create array variable
  • Array.K(domain: Sort, value: Expr): Create constant array
Example:

Expressions

All Z3 values and formulas are expressions.

Arithmetic Operations

method
Addition: a.add(b, c, ...)Supports multiple arguments for efficiency.
method
Subtraction: a.sub(b)
method
Multiplication: a.mul(b, c, ...)
method
Division: a.div(b)Integer division for Int, real division for Real.
method
Modulo: a.mod(b)Integer expressions only.
method
Power: a.pow(b)
Example:

Comparison Operations

method
Equality: a.eq(b)Returns boolean expression.
method
Inequality: a.neq(b)Equivalent to Not(a.eq(b)).
method
Less than: a.lt(b)
method
Less than or equal: a.le(b)
method
Greater than: a.gt(b)
method
Greater than or equal: a.ge(b)

Boolean Operations

These are provided as both methods and standalone functions:
function
Conjunction: And(a, b, c, ...)Returns true if all arguments are true.
function
Disjunction: Or(a, b, c, ...)Returns true if any argument is true.
function
Negation: Not(a)
function
Implication: Implies(a, b)Equivalent to Or(Not(a), b).
function
If-and-only-if: Iff(a, b)True when both have same truth value.
function
Exclusive or: Xor(a, b)
Example:

Bit-Vector Operations

method
Bit-vector addition: a.add(b)
method
Bit-vector subtraction: a.sub(b)
method
Bit-vector multiplication: a.mul(b)
method
Unsigned division: a.udiv(b)
method
Signed division: a.sdiv(b)
method
Unsigned remainder: a.urem(b)
method
Bitwise AND: a.and(b)
method
Bitwise OR: a.or(b)
method
Bitwise XOR: a.xor(b)
method
Bitwise NOT: a.not()
method
Shift left: a.shl(b)
method
Logical shift right: a.lshr(b)
method
Arithmetic shift right: a.ashr(b)

Array Operations

method
Array read: arr.select(index)Returns value at index.
method
Array write: arr.store(index, value)Returns new array with updated value.
Example:

Solver

The solver checks satisfiability of constraints.

new Solver()

Creates a new solver instance.

Methods

method
Add constraints to the solver.Example:
method
Check satisfiability with optional assumptions.Returns:
  • 'sat': Satisfiable (solution exists)
  • 'unsat': Unsatisfiable (no solution)
  • 'unknown': Solver could not determine
Example:
method
Get the model (variable assignments) after a sat result.Throws: Error if called before check() or if result is not sat.
method
Remove all constraints from the solver.
method
Create a backtracking point.
method
Backtrack to previous state.Parameters:
  • num: Number of scopes to pop (default: 1)
Example:

Model

Represents a solution (variable assignments).

Methods

method
Evaluate expression in the model.Parameters:
  • expr: Expression to evaluate
  • modelCompletion: If true, assign default values to unbound variables (default: false)
Example:
method
Get S-expression representation of the model.Returns: SMT-LIB2 format string
method
Get human-readable model representation.

Simplifier

Simplifiers preprocess expressions before solving.

new Simplifier(name)

Example:

Params

Parameter sets for configuring solvers and tactics.

new Params()

Example:

Tactic

Tactics are solvers with specific strategies.

new Tactic(name)

Common tactics:
  • '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

C functions with out parameters return objects:
Array lengths are inferred:
  • JavaScript number for int, unsigned, float, double
  • JavaScript BigInt for int64_t, uint64_t
Types ending in _opt accept/return null:
Long-running operations are async:
  • Z3_simplify
  • Z3_solver_check
  • Z3_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