Part 1 — Core proofs

1.3 Talk about arbitrary values

Tutorial sequence · Previous: 1.2 Prove by cases

Goal: prove \(\forall x:A.\;\exists y:A.\;y = x\) using theorem headers, universal parameters, bound variables, and existential witnesses.

Statement and example

\[ \forall x:A.\;\exists y:A.\;y = x. \]

Taking an arbitrary \(x:A\) and supplying \(x\) as the witness reduces the goal to \(x = x\), closed by reflexivity.

Mojo

compact_quantified_proof.mojo Download
"""Use a theorem parameter for a leading universal quantifier."""

from judgment import Session, exists


def main() raises:
    var s = Session()
    var proof = s.theorem("self_witness")
    var A = proof.type_var("A")
    var x = proof.var("x", A)
    var y = proof.bound_var("y", A)
    proof.goal(exists(y, y == x))

    proof.witness(x)
    proof.rfl()
    var theorem = proof.finish()
    print(theorem)
    print("Axiom dependencies:", len(theorem.axioms()))

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

Output

[A] ⊢ ∀x:A. ∃y:A. y = x
Axiom dependencies: 0

Python

compact_quantified_proof.py Download
"""Use a theorem parameter for a leading universal quantifier."""

from judgment import Session, exists


def main():
    s = Session()
    proof = s.theorem("self_witness")
    A = proof.type_var("A")
    x = proof.var("x", A)
    y = proof.bound_var("y", A)
    proof.goal(exists(y, y == x))

    proof.witness(x)
    proof.rfl()
    theorem = proof.finish()
    print(theorem)
    print("Axiom dependencies:", len(theorem.axioms()))


if __name__ == "__main__":
    main()

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

Output

[A] ⊢ ∀x:A. ∃y:A. y = x
Axiom dependencies: 0

Theorem headers and bound variables

Calling s.theorem("self_witness") without a target opens a header where you declare the theorem's parameters before fixing its conclusion:

  • proof.type_var("A") introduces a schematic type parameter A.
  • proof.var("x", A) introduces an arbitrary term parameter of type A (universally quantified on finish()).
  • proof.bound_var("y", A) creates a binder variable for forming exists(y, ...).

proof.goal(exists(y, y == x)) fixes the conclusion. When finish() runs, term parameters become leading universal quantifiers, while schematic type parameters are displayed in brackets ([A]).

Witnesses and equality

proof.witness(x) instantiates the existential goal with x, leaving x == x, which proof.rfl() closes.

Note that == constructs a symbolic HOL equation Expr. To test handle identity in host code, use same_as (for instance, Python assert x == x constructs an Expr rather than checking reflexivity).

Compare the three declaration scopes:

Call Scope
s.declare_type("Point") Declares a concrete type constant in the session theory.
s.symbol("origin", point) Declares a concrete term constant in the session theory.
proof.var("x", A) Introduces a local parameter universally quantified on finish().

Similarly, s.prop("P") declares a session constant, whereas proof.prop("P") introduces a universally quantified proposition parameter.

Exercise

Add proof.var("z", A) to the header and supply z as the witness for exists(y, y == x). Does rfl() succeed?

Answer

No. The remaining goal is z = x, which is not reflexive for distinct arbitrary parameters z and x.

See Lesson 3.1 for explicit polymorphic instantiation.

Next: 1.4 Rewrite with a reason.

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