Tutorial: cvc5's examples in Mojo¶
Each program on this page is one of cvc5's own Python examples, from
examples/api/python in the cvc5 1.4.1 sources, translated to Mojo by
bindgen.translate. The programs are generated, not edited by hand.
pixi run --locked cvc5-tests builds each one and compares its output with
the official Python bindings. Most examples match exactly. The floating-point
example checks its models and compares the remaining output exactly, since
valid witnesses can differ between builds. Recorded Python output is shown
under each program.
The translation keeps Python's names and structure, so you can read each program alongside its Python original in cvc5's sources. The differences come from Mojo:
- a variable is declared with
var, and a function's parameters have types; - a list is typed by its first element, or by what is appended to it;
- an f-string or
"...".format(...)becomesString(...), which writes each value as Python'sstrdoes; - comments are not carried over, so the explanations are here instead.
Hello world¶
A term manager creates sorts and terms, and a solver checks them. A Boolean
constant named Hello World! is satisfiable on its own. cvc5 prints the
symbol between bars, because it contains a space.
"""cvc5's Python example `helloworld.py`, translated to Mojo."""
from cvc5_mojo import Solver, TermManager
def main() raises:
var tm = TermManager()
var slv = Solver(tm)
var helloworld = tm.mkConst(tm.getBooleanSort(), "Hello World!")
print(helloworld, "is", slv.checkSatAssuming(helloworld))
Run from the repository root pixi run --locked mojo run -I src tests/cvc5/examples/helloworld.mojo
Output, as in Python
|Hello World!| is sat
Quickstart¶
The quickstart sets options and a logic, builds real and integer constants
and constraints with mkTerm, and checks satisfiability. getValue returns
a model value as a term. getRealValue turns that term into an exact
fraction, apn_mojo's Rational, which subtracts and prints as Python's
Fraction does. After resetAssertions, a set of integer constraints that
cannot hold together gives an unsat core: a List[Term] that prints as
Python's list does.
"""cvc5's Python example `quickstart.py`, translated to Mojo."""
from cvc5_mojo import Kind, Solver, TermManager
def main() raises:
var tm = TermManager()
var solver = Solver(tm)
solver.setOption("produce-models", "true")
solver.setOption("produce-unsat-cores", "true")
solver.setLogic("ALL")
var realSort = tm.getRealSort()
var intSort = tm.getIntegerSort()
var x = tm.mkConst(realSort, "x")
var y = tm.mkConst(realSort, "y")
var a = tm.mkConst(intSort, "a")
var b = tm.mkConst(intSort, "b")
var zero = tm.mkReal(0)
var one = tm.mkReal(1)
var xPlusY = tm.mkTerm(Kind.ADD, x, y)
var constraint1 = tm.mkTerm(Kind.LT, zero, x)
var constraint2 = tm.mkTerm(Kind.LT, zero, y)
var constraint3 = tm.mkTerm(Kind.LT, xPlusY, one)
var constraint4 = tm.mkTerm(Kind.LEQ, x, y)
solver.assertFormula(constraint1)
solver.assertFormula(constraint2)
solver.assertFormula(constraint3)
solver.assertFormula(constraint4)
var r1 = solver.checkSat()
print("expected: sat")
print("result: ", r1)
var xVal = solver.getValue(x)
var yVal = solver.getValue(y)
var xMinusY = tm.mkTerm(Kind.SUB, x, y)
var xMinusYVal = solver.getValue(xMinusY)
var xPy = xVal.getRealValue()
var yPy = yVal.getRealValue()
var xMinusYPy = xMinusYVal.getRealValue()
print("value for x: ", xPy)
print("value for y: ", yPy)
print("value for x - y: ", xMinusYPy)
var xMinusYComputed = (xPy - yPy)
if (xMinusYComputed == xMinusYPy):
print("computed correctly")
else:
print("computed incorrectly")
var xStr = String(xPy)
var yStr = String(yPy)
var xMinusYStr = String(xMinusYPy)
solver.resetAssertions()
solver.assertFormula(tm.mkTerm(Kind.LT, tm.mkInteger(0), a))
solver.assertFormula(tm.mkTerm(Kind.LT, tm.mkInteger(0), b))
solver.assertFormula(tm.mkTerm(Kind.LT, tm.mkTerm(Kind.ADD, a, b), tm.mkInteger(1)))
solver.assertFormula(tm.mkTerm(Kind.LEQ, a, b))
var r2 = solver.checkSat()
print("expected: unsat")
print("result:", r2)
var unsatCore = solver.getUnsatCore()
print("unsat core size:", len(unsatCore))
print("unsat core:", unsatCore)
Run from the repository root pixi run --locked mojo run -I src tests/cvc5/examples/quickstart.mojo
Output, as in Python
expected: sat
result: sat
value for x: 1/6
value for y: 1/6
value for x - y: 0
computed correctly
expected: unsat
result: unsat
unsat core size: 3
unsat core: [(< 0 a), (< 0 b), (< (+ a b) 1)]
Datatypes¶
This example declares a list of integers as a datatype: a DatatypeDecl
with declarations of its constructors and their selectors. The datatype's
sort gives the Datatype, which you can index by constructor name, as in
consList["cons"], and iterate over its constructors and their selectors.
Terms of the datatype apply constructors, selectors, testers, and updaters.
The second half declares a parametric list and instantiates it with
integers.
The Python example's helper function test becomes a Mojo function, with
its parameters typed by the arguments it is called with. main calls it
twice, the second time on a datatype made with declareDatatype.
"""cvc5's Python example `datatypes.py`, translated to Mojo."""
from cvc5_mojo import Kind, Solver, Sort, TermManager
def test(slv: Solver, consListSort: Sort) raises:
var tm = slv.getTermManager()
var consList = consListSort.getDatatype()
var t = tm.mkTerm(Kind.APPLY_CONSTRUCTOR, consList.getConstructor("cons").getTerm(), tm.mkInteger(0), tm.mkTerm(Kind.APPLY_CONSTRUCTOR, consList.getConstructor("nil").getTerm()))
print(String("t is ", t, "\nsort of cons is ", consList.getConstructor("cons").getTerm().getSort(), "\n sort of nil is ", consList.getConstructor("nil").getTerm().getSort()))
var t2 = tm.mkTerm(Kind.APPLY_SELECTOR, consList["cons"].getSelector("head").getTerm(), t)
print(String("t2 is ", t2, "\nsimplify(t2) is ", slv.simplify(t2), "\n\n"))
for i in consList:
print("ctor:", i)
for j in i:
print(" + args:", j)
print()
var t_is_cons = tm.mkTerm(Kind.APPLY_TESTER, consList["cons"].getTesterTerm(), t)
print(String("t_is_cons is ", t_is_cons, "\n\n"))
slv.assertFormula(t_is_cons)
var t_updated = tm.mkTerm(Kind.APPLY_UPDATER, consList["cons"]["head"].getUpdaterTerm(), t, tm.mkInteger(1))
print(String("t_updated is ", t_updated, "\n\n"))
slv.assertFormula(tm.mkTerm(Kind.DISTINCT, t, t_updated))
var sort = tm.mkParamSort("T")
var paramConsListSpec = tm.mkDatatypeDecl("paramlist", [sort])
var paramCons = tm.mkDatatypeConstructorDecl("cons")
var paramNil = tm.mkDatatypeConstructorDecl("nil")
paramCons.addSelector("head", sort)
paramCons.addSelectorSelf("tail")
paramConsListSpec.addConstructor(paramCons)
paramConsListSpec.addConstructor(paramNil)
var paramConsListSort = tm.mkDatatypeSort(paramConsListSpec)
var paramConsIntListSort = paramConsListSort.instantiate([tm.getIntegerSort()])
var paramConsList = paramConsListSort.getDatatype()
var a = tm.mkConst(paramConsIntListSort, "a")
print(String("term ", a, " is of sort ", a.getSort()))
var head_a = tm.mkTerm(Kind.APPLY_SELECTOR, paramConsList["cons"].getSelector("head").getTerm(), a)
print(String("head_a is ", head_a, " of sort ", head_a.getSort()))
print("sort of cons is", paramConsList.getConstructor("cons").getTerm().getSort())
var assertion = tm.mkTerm(Kind.GT, head_a, tm.mkInteger(50))
print("Assert", assertion)
slv.assertFormula(assertion)
print("Expect sat.")
print("cvc5:", slv.checkSat())
def main() raises:
var tm = TermManager()
var slv = Solver(tm)
var consListSpec = tm.mkDatatypeDecl("list")
var cons = tm.mkDatatypeConstructorDecl("cons")
cons.addSelector("head", tm.getIntegerSort())
cons.addSelectorSelf("tail")
consListSpec.addConstructor(cons)
var nil = tm.mkDatatypeConstructorDecl("nil")
consListSpec.addConstructor(nil)
print(String("spec is ", consListSpec))
var consListSort = tm.mkDatatypeSort(consListSpec)
test(slv, consListSort)
print("### Alternatively, use declareDatatype")
var cons2 = tm.mkDatatypeConstructorDecl("cons")
cons2.addSelector("head", tm.getIntegerSort())
cons2.addSelectorSelf("tail")
var nil2 = tm.mkDatatypeConstructorDecl("nil")
var consListSort2 = slv.declareDatatype("list2", cons2, nil2)
test(slv, consListSort2)
Run from the repository root pixi run --locked mojo run -I src tests/cvc5/examples/datatypes.mojo
Output, as in Python
spec is DATATYPE list =
cons(head: unresolved, tail: [self]) | nil END;
t is (cons 0 nil)
sort of cons is list
sort of nil is list
t2 is (head (cons 0 nil))
simplify(t2) is 0
ctor: cons(head: Int, tail: list)
+ args: head: Int
+ args: tail: list
ctor: nil
t_is_cons is ((_ is cons) (cons 0 nil))
t_updated is ((_ update head) (cons 0 nil) 1)
term a is of sort (paramlist Int)
head_a is (head a) of sort Int
sort of cons is (paramlist T)
Assert (> (head a) 50)
Expect sat.
cvc5: sat
### Alternatively, use declareDatatype
t is (cons 0 nil)
sort of cons is list2
sort of nil is list2
t2 is (head (cons 0 nil))
simplify(t2) is 0
ctor: cons(head: Int, tail: list2)
+ args: head: Int
+ args: tail: list2
ctor: nil
t_is_cons is ((_ is cons) (cons 0 nil))
t_updated is ((_ update head) (cons 0 nil) 1)
term a is of sort (paramlist Int)
head_a is (head a) of sort Int
sort of cons is (paramlist T)
Assert (> (head a) 50)
Expect sat.
cvc5: sat
Parsing SMT-LIB¶
An InputParser reads SMT-LIB text into commands. The loop invokes each
command on the solver until nextCommand returns a null command. Each
command prints its response, which is success with the print-success
option. The solver then holds the parsed assertions.
"""cvc5's Python example `parser.py`, translated to Mojo."""
from cvc5_mojo import InputLanguage, InputParser, Solver, TermManager
def main() raises:
var tm = TermManager()
var slv = Solver(tm)
slv.setOption("print-success", "true")
var parser = InputParser(slv)
var input = "\n (set-logic QF_LIA)\n (declare-fun a () Int)\n (declare-fun b () Int)\n (declare-fun c () Int)\n (assert (> a (+ b c)))\n (assert (< a b))\n (assert (> c 0))\n "
parser.setStringInput(InputLanguage.SMT_LIB_2_6, input, "MyInput")
var sm = parser.getSymbolManager()
while True:
var cmd = parser.nextCommand()
if cmd.isNull():
break
print(String("Executing command ", cmd, ":"))
print(cmd.invoke(slv, sm), end="")
print("Finished parsing commands")
var r = slv.checkSat()
print("expected: unsat")
print(String("result: ", r))
Run from the repository root pixi run --locked mojo run -I src tests/cvc5/examples/parser.mojo
Output, as in Python
Executing command (set-logic QF_LIA):
success
Executing command (declare-fun a () Int):
success
Executing command (declare-fun b () Int):
success
Executing command (declare-fun c () Int):
success
Executing command (assert (> a (+ b c))):
success
Executing command (assert (< a b)):
success
Executing command (assert (> c 0)):
success
Finished parsing commands
expected: unsat
result: unsat
Synthesis¶
This example uses syntax-guided synthesis. It defines a grammar for the
function max, leaves min unrestricted, and states constraints over
universally quantified variables. checkSynth finds both functions. The two
helper functions come from the Python example's utils module, and the
translator types their parameters from the call, as List[Term].
"""cvc5's Python example `sygus-fun.py`, translated to Mojo."""
from cvc5_mojo import Kind, Solver, Term, TermManager
def define_fun_to_string(f: Term, params: List[Term], body: Term) raises -> String:
var sort = f.getSort()
if sort.isFunction():
sort = f.getSort().getFunctionCodomainSort()
var result = (("(define-fun " + String(f)) + " (")
for i in range(0, len(params)):
if (i > 0):
result += " "
result += (((("(" + String(params[i])) + " ") + String(params[i].getSort())) + ")")
result += ((((") " + String(sort)) + " ") + String(body)) + ")")
return result
def print_synth_solutions(terms: List[Term], sols: List[Term]) raises:
var result = "(\n"
for i in range(0, len(terms)):
var params = List[Term]()
var body = sols[i]
if (sols[i].getKind() == Kind.LAMBDA):
for _item1 in sols[i][0]:
params.append(_item1)
body = sols[i][1]
result += ((" " + define_fun_to_string(terms[i], params, body)) + "\n")
result += ")"
print(result)
def main() raises:
var tm = TermManager()
var slv = Solver(tm)
slv.setOption("sygus", "true")
slv.setOption("incremental", "false")
slv.setLogic("LIA")
var integer = tm.getIntegerSort()
var boolean = tm.getBooleanSort()
var x = tm.mkVar(integer, "x")
var y = tm.mkVar(integer, "y")
var start = tm.mkVar(integer, "Start")
var start_bool = tm.mkVar(boolean, "StartBool")
var zero = tm.mkInteger(0)
var one = tm.mkInteger(1)
var plus = tm.mkTerm(Kind.ADD, start, start)
var minus = tm.mkTerm(Kind.SUB, start, start)
var ite = tm.mkTerm(Kind.ITE, start_bool, start, start)
var And = tm.mkTerm(Kind.AND, start_bool, start_bool)
var Not = tm.mkTerm(Kind.NOT, start_bool)
var leq = tm.mkTerm(Kind.LEQ, start, start)
var g = slv.mkGrammar([x, y], [start, start_bool])
g.addRules(start, [zero, one, x, y, plus, minus, ite])
g.addRules(start_bool, [And, Not, leq])
var max = slv.synthFun("max", [x, y], integer, g)
var min = slv.synthFun("min", [x, y], integer)
var varX = slv.declareSygusVar("x", integer)
var varY = slv.declareSygusVar("y", integer)
var max_x_y = tm.mkTerm(Kind.APPLY_UF, max, varX, varY)
var min_x_y = tm.mkTerm(Kind.APPLY_UF, min, varX, varY)
slv.addSygusConstraint(tm.mkTerm(Kind.GEQ, max_x_y, varX))
slv.addSygusConstraint(tm.mkTerm(Kind.GEQ, max_x_y, varY))
slv.addSygusConstraint(tm.mkTerm(Kind.OR, tm.mkTerm(Kind.EQUAL, max_x_y, varX), tm.mkTerm(Kind.EQUAL, max_x_y, varY)))
slv.addSygusConstraint(tm.mkTerm(Kind.EQUAL, tm.mkTerm(Kind.ADD, max_x_y, min_x_y), tm.mkTerm(Kind.ADD, varX, varY)))
if slv.checkSynth().hasSolution():
var terms: List[type_of(max)] = [max, min]
print_synth_solutions(terms, slv.getSynthSolutions(terms))
Run from the repository root pixi run --locked mojo run -I src tests/cvc5/examples/sygus_fun.mojo
Output, as in Python
(
(define-fun max ((x Int) (y Int)) Int (ite (<= x y) y x))
(define-fun min ((x Int) (y Int)) Int (ite (<= x y) x y))
)
Floating-point models¶
The floating-point example demonstrates fused arithmetic, non-associative addition, NaN and infinity, rounding modes, and the gap between zero and the smallest positive value. Two correct solver builds can choose different values for a satisfiable formula. Requiring identical witnesses would reject valid results.
The translation evaluates every active assertion after each SAT result. It also checks that each printed value has the term's sort and equals that term in the model. The comparison keeps the SAT/UNSAT answers, explanatory text, and output order exact. The Python witness below is one valid output, not a required choice of floating-point bits.
"""cvc5's Python example `floating_point.py`, translated to Mojo."""
from std.testing import assert_true
from cvc5_mojo import Kind, Result, RoundingMode, Solver, Term, TermManager
def _checked_sat(solver: Solver) raises -> Result:
var result = solver.checkSat()
if result.isSat():
for assertion in solver.getAssertions():
assert_true(solver.getValue(assertion).getBooleanValue(), "model violates an assertion")
return result
def _checked_value(solver: Solver, term: Term) raises -> Term:
var value = solver.getValue(term)
assert_true(value.getSort() == term.getSort(), "model value has the wrong sort")
var equal = solver.getTermManager().mkTerm(Kind.EQUAL, term, value)
assert_true(solver.getValue(equal).getBooleanValue(), "model value disagrees with the evaluated term")
return value
def main() raises:
var tm = TermManager()
var slv = Solver(tm)
slv.setOption("produce-models", "true")
slv.setLogic("QF_FP")
var fp32 = tm.mkFloatingPointSort(8, 24)
var rm = tm.mkRoundingMode(RoundingMode.ROUND_NEAREST_TIES_TO_EVEN)
var a = tm.mkConst(fp32, "a")
var b = tm.mkConst(fp32, "b")
var c = tm.mkConst(fp32, "c")
var d = tm.mkConst(fp32, "d")
var e = tm.mkConst(fp32, "e")
print("Show that fused multiplication and addition `(fp.fma RM a b c)`")
print("is different from `(fp.add RM (fp.mul a b) c)`:")
slv.push()
var fma = tm.mkTerm(Kind.FLOATINGPOINT_FMA, rm, a, b, c)
var mul = tm.mkTerm(Kind.FLOATINGPOINT_MULT, rm, a, b)
var add = tm.mkTerm(Kind.FLOATINGPOINT_ADD, rm, mul, c)
slv.assertFormula(tm.mkTerm(Kind.DISTINCT, fma, add))
print("Expect SAT.")
print("cvc5:", _checked_sat(slv))
print(String("Value of `a`: ", _checked_value(slv, a)))
print(String("Value of `b`: ", _checked_value(slv, b)))
print(String("Value of `c`: ", _checked_value(slv, c)))
print(String("Value of `(fp.fma RNE a b c)`: ", _checked_value(slv, fma)))
print(String("Value of `(fp.add RNE (fp.mul a b) c)`: ", _checked_value(slv, add)))
print()
slv.pop()
print("Show that floating-point addition is not associative:")
print("(a + (b + c)) != ((a + b) + c)")
slv.push()
slv.assertFormula(tm.mkTerm(Kind.DISTINCT, tm.mkTerm(Kind.FLOATINGPOINT_ADD, rm, a, tm.mkTerm(Kind.FLOATINGPOINT_ADD, rm, b, c)), tm.mkTerm(Kind.FLOATINGPOINT_ADD, rm, tm.mkTerm(Kind.FLOATINGPOINT_ADD, rm, a, b), c)))
print("Expect SAT.")
print("cvc5:", _checked_sat(slv))
print(String("Value of `a`: ", _checked_value(slv, a)))
print(String("Value of `b`: ", _checked_value(slv, b)))
print(String("Value of `c`: ", _checked_value(slv, c)))
print()
print("Now, restrict `a` to be either NaN or positive infinity:")
var nan = tm.mkFloatingPointNaN(8, 24)
var inf = tm.mkFloatingPointPosInf(8, 24)
slv.assertFormula(tm.mkTerm(Kind.OR, tm.mkTerm(Kind.EQUAL, a, inf), tm.mkTerm(Kind.EQUAL, a, nan)))
print("Expect SAT.")
print("cvc5:", _checked_sat(slv))
print(String("Value of `a`: ", _checked_value(slv, a)))
print(String("Value of `b`: ", _checked_value(slv, b)))
print(String("Value of `c`: ", _checked_value(slv, c)))
print()
slv.pop(1)
print("Now, try to find a (normal) floating-point number that rounds")
print("to different integer values for different rounding modes:")
slv.push()
var rtp = tm.mkRoundingMode(RoundingMode.ROUND_TOWARD_POSITIVE)
var rtn = tm.mkRoundingMode(RoundingMode.ROUND_TOWARD_NEGATIVE)
var op = tm.mkOp(Kind.FLOATINGPOINT_TO_UBV, 16)
var lhs = tm.mkTerm(op, rtp, d)
var rhs = tm.mkTerm(op, rtn, d)
slv.assertFormula(tm.mkTerm(Kind.FLOATINGPOINT_IS_NORMAL, d))
slv.assertFormula(tm.mkTerm(Kind.NOT, tm.mkTerm(Kind.EQUAL, lhs, rhs)))
print("Expect SAT.")
print("cvc5:", _checked_sat(slv))
print("Get value of `d` as floating-point, bit-vector and real:")
var val = _checked_value(slv, d)
print(String("Value of `d`: ", val))
print(String("Value of `((_ fp.to_ubv 16) RTP d)`: ", _checked_value(slv, lhs)))
print(String("Value of `((_ fp.to_ubv 16) RTN d)`: ", _checked_value(slv, rhs)))
print(String("Value of `(fp.to_real d)`: ", _checked_value(slv, tm.mkTerm(Kind.FLOATINGPOINT_TO_REAL, val))))
print()
slv.pop()
print("Finally, try to find a floating-point number between positive")
print("zero and the smallest positive floating-point number:")
var zero = tm.mkFloatingPointPosZero(8, 24)
var smallest = tm.mkFloatingPoint(8, 24, tm.mkBitVector(32, 1))
slv.assertFormula(tm.mkTerm(Kind.AND, tm.mkTerm(Kind.FLOATINGPOINT_LT, zero, e), tm.mkTerm(Kind.FLOATINGPOINT_LT, e, smallest)))
print("Expect UNSAT.")
print("cvc5:", _checked_sat(slv))
Run from the repository root pixi run --locked mojo run -I src tests/cvc5/examples/floating_point.mojo
Python output; model values may differ
Show that fused multiplication and addition `(fp.fma RM a b c)`
is different from `(fp.add RM (fp.mul a b) c)`:
Expect SAT.
cvc5: sat
Value of `a`: (fp #b1 #b11011110 #b00110011001000001001011)
Value of `b`: (fp #b0 #b10100001 #b00111111110000011111101)
Value of `c`: (fp #b0 #b11111111 #b00000000000000000000000)
Value of `(fp.fma RNE a b c)`: (fp #b0 #b11111111 #b00000000000000000000000)
Value of `(fp.add RNE (fp.mul a b) c)`: (fp #b0 #b11111111 #b10000000000000000000000)
Show that floating-point addition is not associative:
(a + (b + c)) != ((a + b) + c)
Expect SAT.
cvc5: sat
Value of `a`: (fp #b1 #b11111110 #b11111111111111011111111)
Value of `b`: (fp #b1 #b11101111 #b00000001000000000000000)
Value of `c`: (fp #b0 #b11111111 #b00000000000000000000000)
Now, restrict `a` to be either NaN or positive infinity:
Expect SAT.
cvc5: sat
Value of `a`: (fp #b0 #b11111111 #b00000000000000000000000)
Value of `b`: (fp #b1 #b11101000 #b00000000000000000000000)
Value of `c`: (fp #b1 #b11111110 #b11111111111111111111111)
Now, try to find a (normal) floating-point number that rounds
to different integer values for different rounding modes:
Expect SAT.
cvc5: sat
Get value of `d` as floating-point, bit-vector and real:
Value of `d`: (fp #b1 #b10010011 #b11111111111111100000000)
Value of `((_ fp.to_ubv 16) RTP d)`: #b1111111111111110
Value of `((_ fp.to_ubv 16) RTN d)`: #b1111111111111111
Value of `(fp.to_real d)`: (- 2097120.0)
Finally, try to find a floating-point number between positive
zero and the smallest positive floating-point number:
Expect UNSAT.
cvc5: unsat
Catching errors¶
The legacy exceptions example returns a nonzero status if an expected error is missing. Its invalid option remains a runtime check. Two other calls have invalid argument types or arity in Mojo; generated compile-failure fixtures check those calls separately. Translation stops at the first rejected call, as Python does when it raises, rather than trying to execute unreachable legacy names later in the block.
"""cvc5's Python example `exceptions.py`, translated to Mojo."""
from std.testing import assert_true
from cvc5_mojo import Solver, TermManager
def _example_main() raises -> Int:
var tm = TermManager()
var slv = Solver(tm)
slv.setOption("produce-models", "true")
try:
slv.setOption("non-existing", "true")
return 1
except:
pass
# Argument rejection checked by a separate compile-fail fixture:
# x = tm.mkConst('x', integer)
# Argument rejection checked by a separate compile-fail fixture:
# slv.checkSat(tm.mkBoolean(False))
return 0
def main() raises:
assert_true(_example_main() == 0, "example returned a nonzero exit status")
Run from the repository root pixi run --locked mojo run -I src tests/cvc5/examples/exceptions.mojo
Output, as in Python
All the examples¶
22 of cvc5's 23 Python examples run: 21 match Python's output exactly and one
uses the model checks described above. The
coverage report lists them, and says why
the finite-field example does not run. They are in tests/cvc5/examples/, and you can run
any of them from the repository root:
pixi run --locked mojo run -I src tests/cvc5/examples/<name>.mojo