Tutorials

Tutorials

This five-part series walks you through z3_mojo by solving real problems, starting with basic constraints and exact models and working up to custom theories and the low-level C API.

Every snippet in these tutorials comes from a complete, runnable file under docs/examples/ that runs in CI via pixi run docs-test.

Part Topic Runnable file
Part 1: First steps Context, variables, operators, Solver, exact apn_mojo models, solutions docs/examples/tutorial_01_first_steps.mojo
Part 2: Solver control push/pop, unsat_core, timeouts, Optimize soft constraints, Tactic & Probe docs/examples/tutorial_02_solver_control.mojo
Part 3: Theories in practice BitVectors, IEEE-754 FPA, Strings/Regex, Arrays, Polymorphic Datatypes, FiniteSets & GF(p) docs/examples/tutorial_03_theories.mojo
Part 4: Quantifiers, reachability & RCF ForAll/MultiPattern, RecFunction, Model.project, Fixedpoint, RcfNum docs/examples/tutorial_04_quantifiers_rcf.mojo
Part 5: Extending Z3 UserPropagator, OnClause, Optimize.set_on_model, and the low-level C API (z3_mojo.c) docs/examples/tutorial_05_extending_z3.mojo

Prerequisites

Make sure you have completed Installation and fetched the pinned Z3 5.3.3 libraries (pixi run fetch). You can run any tutorial program from the repository root with:

pixi run mojo run -I src docs/examples/tutorial_01_first_steps.mojo
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