Examples
Example gallery¶
Every example below lives in docs/examples/ and runs in CI via
pixi run docs-test.
| Example | File | API layer | What it shows |
|---|---|---|---|
| Quickstart | docs/examples/quickstart.mojo |
Pythonic | Building a Context, using qfnra-nlsat, proving x^2 < 0 is unsat |
| Nonlinear and quantified reals | docs/examples/nonlinear_reals.mojo |
Pythonic + Safe | Exact apn_mojo.Rational model extraction (355/113) and quantified NRA |
| Unsat cores and incremental solving | docs/examples/unsat_cores_and_incremental.mojo |
Safe | Solver.for_logic("QF_NRA"), assert_and_track, get_unsat_core, and push/pop |
| Tactics and optimization | docs/examples/tactics_and_optimize.mojo |
Safe | Chaining Tactic with Params, and linear maximization with Optimize |
| RCF, floating point, and strings | docs/examples/rcf_and_theories.mojo |
Safe | RcfNum.mk_roots (sqrt(2)), pi/e, IEEE-754 double FPA, and strings |
| Callbacks and user propagator | docs/examples/callbacks_and_propagator.mojo |
Pythonic + Callbacks | UserPropagator conflict propagation, OnClause, and Optimize.set_on_model |
| Low-level C API | docs/examples/c_api_low_level.mojo |
Low-level C (z3_mojo.c) |
Direct c_api() calls with Z3_mk_context_rc and manual Z3_inc_ref / Z3_dec_ref |
| Tutorial Part 1: First steps | docs/examples/tutorial_01_first_steps.mojo |
Pythonic | Scheduling puzzle, solutions, exact Rational vs algebraic roots |
| Tutorial Part 2: Solver control | docs/examples/tutorial_02_solver_control.mojo |
Pythonic + Safe | Unsat cores, push/pop, Optimize soft constraints, Tactic & Probe |
| Tutorial Part 3: Theories | docs/examples/tutorial_03_theories.mojo |
Pythonic | BitVectors, Float32 non-associativity, Strings/Regex, Arrays, Polymorphic Datatypes, FiniteSets & GF(17) |
| Tutorial Part 4: Quantifiers & RCF | docs/examples/tutorial_04_quantifiers_rcf.mojo |
Pythonic + Safe | ForAll/MultiPattern, RecFunction, Model.project, Fixedpoint, RcfNum |
| Tutorial Part 5: Extending Z3 | docs/examples/tutorial_05_extending_z3.mojo |
Callbacks + Low-level C | Custom UserPropagator, OnClause, Optimize.set_on_model, and z3_mojo.c |
Running the examples¶
From the repository root:
pixi run docs-test
Or run a single file:
pixi run mojo run -I src docs/examples/c_api_low_level.mojo