Part 1 — Core proofs

1.9 See what remains to prove

Tutorial sequence · Previous: 1.8 Inspect and repair a proof

Goal: inspect open obligations programmatically, defer and resume a goal with sorry() / resume(), and audit dependencies of a finished theorem.

Tracking obligations

The example proves \(P \to (P \land P)\), splits the conjunction, closes the left subgoal, defers the right subgoal with sorry(), resumes it, and finishes the proof.

Mojo

inspect_progress.mojo Download
"""Inspect open and deferred goals, then the finished theorem."""

from std.testing import assert_equal
from judgment import Session, implies


def main() raises:
    var s = Session()
    var P = s.prop("P")
    var proof = s.theorem("duplicate", implies(P, P & P))
    var premise = proof.intro("premise")
    _ = proof.split()
    print("After splitting:")
    print(proof.format())
    var captured = proof.obligations()[0]
    assert_equal(len(captured.assumptions()), 1)

    var left = proof.select("left")
    left.exact(premise)
    var right = proof.select("right")
    right.sorry()
    print("After solving left and deferring right:")
    print(proof.format())
    assert_equal(len(proof.obligations()), 1)

    # A Goal is a snapshot. Select the outstanding goal again before resuming it.
    right = proof.select(proof.obligations()[0])
    right.resume()
    right.exact(premise)
    print("Before finish:")
    print(proof.format())
    assert_equal(len(proof.obligations()), 0)
    var theorem = proof.finish()
    print("Theorem:", theorem)
    print("Axioms:", len(theorem.axioms()), "Admissions:", len(theorem.admissions()))

Run from the repository root pixi run core-run docs/examples/library/inspect_progress.mojo

Output

After splitting:
duplicate: 2 obligations

goal 2 [open] duplicate [left]
  premise: [local] ⊢ P
  ⊢ P

goal 3 [open] duplicate [right]
  premise: [local] ⊢ P
  ⊢ P
After solving left and deferring right:
duplicate: 1 obligation

goal 3 [deferred] duplicate [right]
  premise: [local] ⊢ P
  ⊢ P
Before finish:
duplicate: ready to finish
Theorem: ⊢ P → P ∧ P
Axioms: 0 Admissions: 0

Python

inspect_progress.py Download
"""Inspect open and deferred goals, then the finished theorem."""

from judgment import Session, implies


def main():
    s = Session()
    P = s.prop("P")
    proof = s.theorem("duplicate", implies(P, P & P))
    premise = proof.intro("premise")
    proof.split()
    print("After splitting:")
    print(proof.format())
    captured = proof.obligations()[0]
    assert len(captured.assumptions()) == 1

    left = proof.select("left")
    left.exact(premise)
    right = proof.select("right")
    right.sorry()
    print("After solving left and deferring right:")
    print(proof.format())
    assert len(proof.obligations()) == 1

    # A Goal is a snapshot. Select the outstanding goal again before resuming it.
    right = proof.select(proof.obligations()[0])
    right.resume()
    right.exact(premise)
    print("Before finish:")
    print(proof.format())
    assert len(proof.obligations()) == 0
    theorem = proof.finish()
    print("Theorem:", theorem)
    print("Axioms:", len(theorem.axioms()), "Admissions:", len(theorem.admissions()))


if __name__ == "__main__":
    main()

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

Output

After splitting:
duplicate: 2 obligations

goal 2 [open] duplicate [left]
  premise: [local] ⊢ P
  ⊢ P

goal 3 [open] duplicate [right]
  premise: [local] ⊢ P
  ⊢ P
After solving left and deferring right:
duplicate: 1 obligation

goal 3 [deferred] duplicate [right]
  premise: [local] ⊢ P
  ⊢ P
Before finish:
duplicate: ready to finish
Theorem: ⊢ P → P ∧ P
Axioms: 0 Admissions: 0

proof.format() prints all outstanding goals with their status, branch path, local context, and target. After left.exact(premise), only the right branch remains; right.sorry() marks it deferred (still blocking finish()), and resume() returns it to open.

Programmatic inspection

For tooling, proof scripts, or automated search, query structured objects rather than parsing formatted output:

Call Returns
proof.obligations() Remaining open and deferred Goal snapshots (solved goals omitted).
proof.current_goal() Snapshot of the currently selected goal.
goal.status() / goal.path() Status and branch path.
goal.target() / goal.assumptions() / goal.variables() Target expression, local hypotheses, and local parameters.
goal.data() Structured descriptor including a revision token.
proof.select(goal) Focus handle for that obligation.

A Goal is an immutable snapshot taken at query time. Re-query obligations() after modifying the proof or restoring a checkpoint; selecting a solved or replaced goal raises an error.

Auditing finished theorems

  • print(theorem) prints the statement with type parameters and hypotheses.
  • theorem.statement().format() prints the proposition alone.
  • theorem.format(details=True) prints detailed provenance.
  • theorem.axioms(), theorem.admissions(), and theorem.imported() return structured dependency lists.

Exercise

Call finish() immediately after right.sorry(). What happens?

Answer

finish() rejects the proof because the deferred branch remains in obligations(). sorry() is a placeholder only; it does not discharge a goal.

Next: 2.1 Negation, equivalence, and using witnesses.

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