CVC5 Mojo documentation

Mojo bindings for the cvc5 SMT solver

CVC5 Mojo lets Mojo programs use the cvc5 SMT solver. Its API follows cvc5's Python bindings, with the same classes, methods, and enum names, so cvc5's Python documentation and examples carry over. You build terms with a TermManager, assert them on a Solver, and ask for a satisfiability result, a model, an unsat core, a proof, or a synthesized function.

The bindings are generated from the cvc5 release they bind, currently cvc5 1.4.1. Version 1.4.1.0 is published in the modular-community conda channel for Mojo 1.1 on Linux x86-64, Linux ARM64, and macOS Apple Silicon: pixi add cvc5_mojo installs it.

Python's API in Mojo

tm.mkConst, solver.checkSat, and Kind.ADD work as in Python. The reference shows each Mojo signature.

cvc5's examples

cvc5's own Python examples, translated to Mojo. Output comparisons and model checks verify their results against the Python originals.

Ownership and errors

Values release their cvc5 objects when Mojo destroys them. A call that cvc5 rejects raises an error that you can catch.

Numbers of any size

Integers and fractions come back exactly, as apn_mojo's Integer and Rational.

Tested against cvc5

366 of cvc5's Python unit tests run in Mojo and pass, alongside the project's own tests.

How the bindings are made

Names, signatures, and enum values are extracted from the pinned cvc5 release, and the Mojo code is generated from them.

First program

After setting up a checkout, run this program from the repository root. It asks cvc5 whether the square of a real number can be negative.

quickstart.mojo Download
"""The smallest complete program: prove that no real number has a negative square."""

from std.testing import assert_true

from cvc5_mojo import TermManager, Solver, Kind


def main() raises:
    var tm = TermManager()
    var solver = Solver(tm)
    solver.setLogic("QF_NRA")

    var x = tm.mkConst(tm.getRealSort(), "x")
    var negative_square = tm.mkTerm(Kind.LT, tm.mkTerm(Kind.MULT, x, x), tm.mkInteger(0))
    solver.assertFormula(negative_square)

    var result = solver.checkSat()
    assert_true(result.isUnsat())
    print(negative_square, "is", result)

Run from the repository root pixi run --locked mojo run -I src docs/examples/quickstart.mojo

Output

(< (* x x) 0) is unsat

A TermManager creates sorts and terms, and a Solver holds assertions and checks them. Each value holds a reference to its cvc5 object and releases it when Mojo destroys the value; see ownership and errors.

What the bindings cover

Area Coverage
Python's base API 392 of its 458 methods, in all 19 of its classes. The coverage report lists the others.
Plugin callbacks Supply lemmas and observe learned clauses through the Plugin trait and Solver.addPlugin.
Left out The 65 deprecated methods, each replaced by a TermManager method, and Term.toPythonObj, which returns Python objects.
Enums All 14, with Python's member names and values. They print as Python's enums do.
Numbers Integers of any size are apn_mojo's Integer, and fractions are its Rational.
Errors A call that cvc5 rejects raises an Error whose message starts with cvc5:.
Platforms Linux x86-64, Linux ARM64, and macOS Apple Silicon with Mojo 1.2.0 and cvc5 1.4.1; validation status. Native ARM and macOS execution checks are pending.

See support and limitations for the details.

Learn through worked problems

Start with the twelve-lesson course, then build a scheduling application that diagnoses conflicts and certifies an optimum. The transcendental course develops exact queries involving exponentials, logarithms, trigonometry, and rigorous bounds. Each course includes complete programs, explanations, and exercises.

Use the task cookbook to choose a solving pattern, compare Python and Mojo, or build an external consumer.

Find your starting point

I want to... Read
Set up a checkout and run a program Installation
Learn constraint solving step by step Tutorial course
Model transcendental functions Transcendental course
Learn from cvc5's own examples Tutorial
Understand lifetimes and errors Ownership and errors
Look up a class or method API reference
Check what is supported Support and limitations
Fix a failing build or run Troubleshooting
Browse every runnable example Examples
Understand how the bindings are generated Architecture
Contribute Development
cvc5_mojo v1.4.1.1 for Mojo 1.2 and cvc5 1.4.1 · Apache License 2.0 with LLVM Exceptions · Source on GitHub