Part 5 — Concurrency, libraries & integration

5.11 Check a proof against a promised conclusion

Tutorial sequence · Previous: 5.10 Check a symbolic transformation

Every derivation in a Session is checked by judgment_core's stateless checker over proof-DAG rows stored in termbank.dag. A theorem declaration checks not only that each inference step is valid, but also that the finished derivation proves the exact conclusion requested.

This example derives True ∧ True by sharing one proof of True for both conjuncts, registers it as a theorem, and then submits the same derivation for the wrong goal False to verify that the mismatch is rejected.

Mojo

checking_proofs.mojo Download
"""Check a proof against its promised conclusion and reject a mismatch."""

from std.testing import assert_true
from judgment import Fact, Proof, Session, Step
from judgment_shell import LibErrorKind


def main() raises:
    var s = Session()
    var root = s.base()
    var truth = s.true_()
    var falsehood = s.false_()
    var expected = truth & truth

    var leaf: Step = s.truth(root)
    var both: Step = s.and_intro(leaf, leaf)
    assert_true(both.statement().same_as(expected))
    assert_true(len(both.hypotheses()) == 0)

    var proof: Proof = s.theorem("both_true", expected)
    proof.exact(both)
    var checked: Fact = proof.finish()
    assert_true(checked.statement().same_as(expected))
    assert_true(len(checked.axioms()) == 0)

    var rejected = False
    try:
        var wrong = s.theorem("wrong_goal", falsehood)
        wrong.exact(both)
    except e:
        rejected = e.kind == LibErrorKind.KERNEL or e.kind == LibErrorKind.SHAPE
    assert_true(rejected)
    print("Accepted theorem: True and True")
    print("Rejected promised conclusion: False")

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

Output

Accepted theorem: True and True
Rejected promised conclusion: False

Python

checking_proofs.py Download
"""Check a proof against its promised conclusion and reject a mismatch."""

from judgment import Fact, Proof, Session, Step, JudgmentError
from judgment import LibErrorKind


def main():
    s = Session()
    root = s.base()
    truth = s.true_()
    falsehood = s.false_()
    expected = truth & truth

    leaf = s.truth(root)
    both = s.and_intro(leaf, leaf)
    assert both.statement().same_as(expected)
    assert len(both.hypotheses()) == 0

    proof = s.theorem("both_true", expected)
    proof.exact(both)
    checked = proof.finish()
    assert checked.statement().same_as(expected)
    assert len(checked.axioms()) == 0

    rejected = False
    try:
        wrong = s.theorem("wrong_goal", falsehood)
        wrong.exact(both)
    except JudgmentError as e:
        rejected = e.kind == LibErrorKind.KERNEL or e.kind == LibErrorKind.SHAPE
    assert rejected
    print("Accepted theorem: True and True")
    print("Rejected promised conclusion: False")


if __name__ == "__main__":
    main()

Run from the repository root PYTHONPATH=bindings/python:docs/examples/python pixi run python docs/examples/python/checking_proofs.py

Output

Accepted theorem: True and True
Rejected promised conclusion: False

Build and share derivation steps

s.truth(root) builds a checked Step for True in the base frame root. Passing leaf twice to s.and_intro(leaf, leaf) shares the same underlying proof-DAG row in termbank.dag rather than duplicating the subproof.

Inspecting both.statement() and both.hypotheses() shows that both proves True ∧ True with no remaining local hypotheses.

Check the result you meant to request

s.theorem("both_true", expected) opens a Proof goal for expected, and proof.exact(both) discharges that goal only if both matches the promised conclusion. proof.finish() registers the closed theorem as a Fact whose axiom dependencies can be inspected via checked.axioms().

A valid proof of some other proposition never satisfies a request for a different target. When wrong.exact(both) submits the proof of True ∧ True for the goal False, the session rejects the mismatch with LibErrorKind.KERNEL or LibErrorKind.SHAPE.

For speculative proof search or branching over large search spaces, combine step construction with scoped work (Session.transaction(), Session.snapshot(), and Session.fork()). Persistent interchange belongs to the optional judgment_store.

Next: 5.12 Manage memory limits, spill storage, and judgment_mathlib.

judgment v1.0.0 for Mojo 1.2 · Apache License 2.0 with LLVM Exceptions · Source on GitHub