Part 1 — Core proofs

1.1 Prove your first theorem

Tutorial sequence · Next: 1.2 Prove by cases

Goal: prove \((P \land Q) \to (Q \land P)\) using a goal-first Proof. Complete setup first.

Statement and example

We construct the implication

\[ (P \land Q) \to (Q \land P) \]

for two declared proposition symbols P and Q, assume the conjunction, project its components in reverse order, re-conjoin them, and discharge the assumption.

Mojo

quick_start_goal.mojo Download
"""Complete a goal-first proof by composing checked facts directly."""

from judgment import Session, implies


def main() raises:
    var s = Session()
    var P = s.prop("P")
    var Q = s.prop("Q")

    var proof = s.theorem("swap", implies(P & Q, Q & P))
    var h = proof.intro("h")
    proof.exact(proof.conjoin(proof.right(h), proof.left(h)))
    var theorem = proof.finish()
    print(theorem)

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

Output

⊢ P ∧ Q → Q ∧ P

Python

quick_start_goal.py Download
"""Complete a goal-first proof by composing checked facts directly."""

from judgment import Session, implies


def main():
    s = Session()
    P = s.prop("P")
    Q = s.prop("Q")

    proof = s.theorem("swap", implies(P & Q, Q & P))
    h = proof.intro("h")
    proof.exact(proof.conjoin(proof.right(h), proof.left(h)))
    theorem = proof.finish()
    print(theorem)


if __name__ == "__main__":
    main()

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

Output

⊢ P ∧ Q → Q ∧ P

Declarations and expressions

Session() holds declarations, expressions, proof drafts, and proved facts. Handles belong to the session that created them and cannot be mixed across sessions.

  • s.prop("P") declares a proposition symbol and returns its Expr; it does not assert P.
  • P & Q and implies(P & Q, Q & P) build symbolic HOL expressions (not host-language Booleans; in Python, use &, not and).
  • s.theorem("swap", target) opens a proof draft for target. The name is registered in the session only when finish() succeeds.

Proof steps

proof.intro("h") introduces the implication's antecedent as a local assumption h and updates the goal to its consequent:

Call Effect
intro("h") Assumes P & Q; goal becomes Q & P.
right(h) Derives Q under h.
left(h) Derives P under h.
conjoin(right(h), left(h)) Derives Q & P under h.
exact(...) Closes the current goal with the supplied derivation.

exact checks that the supplied derivation matches the selected goal; it does not search.

Finishing and inspecting the result

proof.finish() verifies that all obligations are closed, discharges h into the implication, and registers the theorem as a Fact (retrievable later via s.fact("swap")).

The printed ⊢ denotes a checked theorem with no added axioms. P and Q are session constants rather than universally quantified parameters; Lesson 1.3 covers quantified theorem headers.

Exercises

Change the target to implies(P, P) under a fresh name. After intro("h"), what closes the goal?

Answer

proof.exact(h) followed by proof.finish(). h proves P in the local context, and finish() discharges it to yield P → P.

Change the target to implies(P, Q) while keeping exact(h).

Expected behavior

The kernel rejects exact(h) because h proves P, whereas the goal is Q.

Next: 1.2 Prove by cases.

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