How-to Guides

Quick reference

Compact summary of common operations across Mojo (thin client or direct package) and Python. Method names match in both languages; Python omits Mojo's var / ^ ownership syntax and uses int / fractions.Fraction for exact numbers.

Setup and execution

pixi run build-core                                 # build libjudgment.so / .dylib once
pixi run build-core-store                           # add libjudgment_store.so / .dylib once

pixi run core-run my_proof.mojo                     # run Mojo against libjudgment
pixi run core-run --variant store my_lib.mojo       # run Mojo against libjudgment_store
PYTHONPATH=bindings/python pixi run python app.py   # run Python against the same shared library

Sessions, types, and expressions

Task Call (Mojo and Python)
Open fresh or snapshot session Session() / Session.open(snapshot, work=...)
Declare type / type constructor s.declare_type("A") / s.type_constructor("list", 1)
Declare proposition / constant s.prop("P") / s.symbol("f", arrow(A, B))
Bound variable and quantifiers x = s.bound_var("x", A); forall(x, body), exists(x, body), lambda_(x, body)
Connectives and equality P & Q, P \| Q, ~P, implies(P, Q), iff(P, Q), a == b
Check structural identity e1.same_as(e2) (== builds a symbolic HOL equation)
Definitions and axioms s.define("d", body, transparent=True) / transparent=False / s.axiom("ax", prop)
Nonempty subset type sb = s.subset("Pos", A, pred); sub = sb.finish(witness_fact)
Type classes and custom ACU s.class_("monoid"), s.instance(...), s.class_relation(...), s.acu_operator(...)

Goal-first proofs and tactics

Task Call (Mojo and Python)
Start and finish a theorem p = s.theorem("name", goal) ... fact = p.finish()
Introduce implication / ∀ h = p.intro("h") / x = p.intro_var("x")
Close with evidence / reflexivity / assumption p.exact(step) / p.rfl() / p.assumption()
Conjunction / disjunction / ∃ p.split(), p.left(h), p.right(h), p.conjoin(a, b), p.choose_left(), p.choose_right(), p.cases(h), p.witness(t), p.obtain(h, "x")
Apply theorem backward subgoals = p.apply(fact) or p.apply(fact, premises=[...])
Targeted rewrite / calculation p.lhs().at(sub).rw(eq_step) / c = p.calc(start); c.eq(next, using=fact, label="step"); p.exact(c.finish())
Checked term transformation tr = s.transform(expr); tr.at(sub).rw(fact); step = tr.evidence()
Tactic combinators t = p.tactics(); t1.then(t2), t1.or_else(t2), t1.repeat(), t1.all_goals(), p.by(tac)
Checkpoints, deferrals, and audits cp = p.checkpoint() / p.restore(cp); p.sorry(); p.admit("n", "why"); fact.axioms(), fact.admissions(), fact.dependencies()

Scoped work, budgets, and cancellation

Task Call (Mojo and Python)
Atomic transaction tx = s.transaction() ... tx.commit(expressions=[...], facts=[...]) or tx.discard()
Theory rollback / seal snap = s.snapshot(); s.checkout(snap) / sealed = s.seal()
Budgets and forks s.work_remaining(), s.spend(n), s.add_work(n); child = p.fork(work, stop=sig); sig = StopSignal(); sig.request()
Memory cap and spill s.set_memory_limit(bytes), s.memory_used(), s.set_spill_directory(dir), s.spill()

Scalar symbolic and numeric tools

Task Call (Mojo and Python)
Build profile and open session prof = build_scalar(budget, ProfileLevel.POWERS_AND_ROOTS); s = session(prof, ["x"])
Rational-function transfer res = transfer(s, prof, s.base(), lhs, rhs, budget) (res.kind() == TransferResult.PROVED, .guard(), .step())
Polynomial reification and identity poly = build_scalar_poly(prof, budget); ps = Session.open(poly.sealed_snapshot()); reify(...), identity(...)
Guards, cases, and literal facts ScalarAtom(...), is_generic(atom), to_guard(...), class_split(...), literal_facts(...)
Cut-aware numeric testing evaluate(s, prof, expr, point), decide(s, prof, atom, point), refute(s, prof, lhs, rhs, guard, vars)

Binary libraries, OpenTheory, and theory interpretations

Task Call (Mojo and Python)
Create / open / query library lib = Library.create(path, "none"), Library.open(path), lib.find(name), lib.categories(), lib.dependents(name)
Publish / replace / withdraw / rebase ch = lib.change(); ch.add(export) / ch.add_snapshot(snap, "", budget) / ch.replace(name, exp) / ch.withdraw(name) / ch.rebase() / ch.publish()
Load (rechecked vs. statement-only) Session.open(lib.snapshot(budget)) vs. s = Session.open(lib.profile_snapshot(budget)); s.import_theorem(lib, name)
OpenTheory articles Article.write(path, [export], budget), art = Article.open(path), ch.add_article(path)
Theory interpretations TypeImage(Ctor, params, body), transport_type(...), transport_term(...), prepare_interpretation(...), reuse(src, dst, base, thm, name, consts, proofs, budget, type_images=...)

Common error kinds

Error kind Typical cause
SHAPE Malformed argument, wrong goal form (e.g. intro on a ∀ instead of intro_var), unfinished obligations at finish(), or duplicate declaration
NO_MATCH Pattern, rewrite occurrence, tactic, or theory-interpretation obligation did not match
KERNEL Kernel rejected a type, scope, or rule check (inspect e.kernel_kind)
LIMIT Session work allowance, Budget, or memory cap exhausted (atomic; state unchanged)
WRONG_KERNEL Handle passed to a different Session than its owner
BAD_HANDLE Freed, consumed, or stale handle (prebuilt core)
BUSY Concurrent call on a busy Session, object, or Budget (prebuilt core)
CONFLICT (StoreErrorKind) Another writer published a newer library version; call change.rebase() and retry
judgment v1.0.0 for Mojo 1.2 · Apache License 2.0 with LLVM Exceptions · Source on GitHub