Installation¶
z3_mojo targets Mojo 1.2.0, Z3 5.3.3, and APN Mojo 1.0.2 on:
- Linux x86-64 (
linux-64) - Linux ARM64 (
linux-aarch64) - macOS Apple Silicon (
osx-arm64, macOS 15+)
Install with Pixi¶
Once published to the modular-community channel:
pixi init my-solver-project \
--platform linux-64 --platform linux-aarch64 --platform osx-arm64 \
-c https://conda.modular.com/max \
-c https://repo.prefix.dev/modular-community \
-c conda-forge
cd my-solver-project
pixi add "mojo==1.2.0" "z3_mojo==5.3.3.0"
The package places the precompiled module at
${CONDA_PREFIX}/lib/mojo/z3_mojo.mojoc (so from z3_mojo import ... works
without -I), bundles the matching libz3 under
${CONDA_PREFIX}/lib/z3_mojo/lib/, and pulls in apn_mojo==1.0.2.
Work from a checkout¶
git clone https://github.com/Spellbound-Mojo/z3_mojo.git
cd z3_mojo
pixi install --all
pixi run fetch
pixi run test
pixi run docs-test
pixi run fetch downloads the pinned Z3 release archives listed in
z3-version.toml, checks their SHA-256 hashes, and unpacks them into
third_party/.
Where libz3 is found¶
On the first call into Z3 (usually Context()), z3_mojo looks for
libz3.so (or libz3.dylib on macOS) in this order:
$Z3_MOJO_LIBRARY, if set. If it points to a missing file, loading fails immediately rather than falling back silently.$CONDA_PREFIX/lib/z3_mojo/lib/libz3.{so,dylib}(the installed package layout, kept separate from anyconda-forgelibz3).third_party/z3/bin/libz3.{so,dylib}(a local checkout afterpixi run fetch).$CONDA_PREFIX/lib/libz3.{so,dylib}(a fallback for environments that installlibz3fromconda-forge).
The library is opened once per process, and all C symbols are resolved into a
single cached CApi table. Creating additional Context or Solver objects
does not call dlopen or dlsym again.
Arbitrary-precision numbers (apn_mojo)¶
Z3 handles integers and rationals of arbitrary size. z3_mojo converts them
directly to and from apn_mojo:
ctx.mk_integer(val: Integer)andctx.mk_real(val: Rational)build exact numerals of any width. When a numerator and denominator fit inInt64,mk_realuses Z3's fast 64-bit constructor; larger values go throughZ3_mk_numeral.ast.as_integer(),ast.as_rational(),model.get_integer(ast), andmodel.get_rational(ast)returnOptional[Integer]andOptional[Rational]without rounding to floating point.