2.2 Structure larger proofs: claims, abbreviations, and binders¶
Tutorial sequence · Previous: 2.1 Negation, equivalence, and witnesses
Goal: factor local lemmas with have, introduce local abbreviations with
define/fold/unfold, and rewrite under quantifiers with under.
These three operations scope proof structure to a branch without extending the session's global theory.
Intermediate claims (have)¶
proof.have("name", proposition) splits the branch into:
- a new subgoal (
step) with targetproposition, evaluated in the context preceding the claim; and - the continuation, where
step.fact()is available as a local hypothesis.
A claim may be deferred with sorry() while finishing the continuation. It
cannot cite itself, and proof.finish() refuses completion until every claim
(used or unused) is solved.
Mojo
"""Develop a named intermediate claim independently of its continuation."""
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_with_claim", implies(P & Q, Q & P))
var h = proof.intro()
var step = proof.have("first_component", Q)
step.sorry()
proof.exact(proof.conjoin(step.fact(), proof.left(h)))
# The continuation is solved, but the intermediate claim still needs proof.
step.resume()
step.exact(step.right(h))
var theorem = proof.finish()
print(theorem)
print("Axiom dependencies:", len(theorem.axioms()))
Run from the repository root pixi run core-run docs/examples/library/intermediate_claims.mojo
Output
⊢ P ∧ Q → Q ∧ P
Axiom dependencies: 0
Python
"""Develop a named intermediate claim independently of its continuation."""
from judgment import Session, implies
def main():
s = Session()
P = s.prop("P")
Q = s.prop("Q")
proof = s.theorem("swap_with_claim", implies(P & Q, Q & P))
h = proof.intro()
step = proof.have("first_component", Q)
step.sorry()
proof.exact(proof.conjoin(step.fact(), proof.left(h)))
# The continuation is solved, but the intermediate claim still needs proof.
step.resume()
step.exact(step.right(h))
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/intermediate_claims.py
Output
⊢ P ∧ Q → Q ∧ P
Axiom dependencies: 0
Once step is closed, proof.finish() discharges the local hypothesis and
records zero axiom dependencies.
Local definitions (define, fold, unfold)¶
proof.define("t", expr) introduces a local abbreviation scoped to the current
branch and its descendants (unlike s.define(...), it does not modify the
session theory). Use fold(t) to replace an occurrence of expr with t and
unfold(t) to expand t:
Mojo
"""Name an expression inside a proof, then fold and unfold it explicitly."""
from judgment import Session, arrow
def main() raises:
var s = Session()
var A = s.declare_type("A")
var f = s.symbol("f", arrow(A, A))
var proof = s.theorem("named_expression")
var x = proof.var("x", A)
proof.goal(f(f(x)) == f(f(x)))
var t = proof.define("t", f(x))
_ = proof.lhs().at(f(x)).fold(t)
print(proof.target().format())
_ = proof.lhs().at(t).unfold(t)
proof.rfl()
print(proof.finish())
Run from the repository root pixi run core-run docs/examples/library/local_definitions.mojo
Output
f(t) = f(f(x))
⊢ ∀x:A. f(f(x)) = f(f(x))
Python
"""Name an expression inside a proof, then fold and unfold it explicitly."""
from judgment import Session, arrow
def main():
s = Session()
A = s.declare_type("A")
f = s.symbol("f", arrow(A, A))
proof = s.theorem("named_expression")
x = proof.var("x", A)
proof.goal(f(f(x)) == f(f(x)))
t = proof.define("t", f(x))
_ = proof.lhs().at(f(x)).fold(t)
print(proof.target().format())
_ = proof.lhs().at(t).unfold(t)
proof.rfl()
print(proof.finish())
if __name__ == "__main__":
main()
Run from the repository root PYTHONPATH=bindings/python:docs/examples/python/library pixi run python docs/examples/python/library/local_definitions.py
Output
f(t) = f(f(x))
⊢ ∀x:A. f(f(x)) = f(f(x))
Folding and unfolding are explicit; conversion does not expand local
abbreviations implicitly. At proof.finish(), the local definition is
discharged and the registered theorem states the original unabbreviated formula
∀x:A. f(f(x)) = f(f(x)).
Rewriting under binders (under)¶
Ordinary at(...) searches treat quantifier and lambda bodies as opaque to
prevent free-variable capture. To rewrite inside ∀x:A. x = a, call
under("z") to open the binder with a fresh local variable z, rewrite inside
opened.body(), and close the scope with opened.finish():
Mojo
"""Rewrite beneath a quantifier through an explicit fresh-variable scope."""
from judgment import Session, forall
def main() raises:
var s = Session()
var A = s.declare_type("A")
var proof = s.theorem("replace_under_forall")
var values = proof.vars("a b", A)
var a, b = values[0], values[1]
var equality = proof.given("equality", a == b)
var x = proof.bound_var("x", A)
proof.goal(forall(x, x == a) == forall(x, x == b))
var opened = proof.lhs().under("z")
_ = opened.body().at(a).rw(equality)
_ = opened.finish()
proof.rfl()
print(proof.finish())
Run from the repository root pixi run core-run docs/examples/library/binder_rewrites.mojo
Output
⊢ ∀a:A. ∀b:A. a = b → (∀x:A. x = a) = (∀x:A. x = b)
Python
"""Rewrite beneath a quantifier through an explicit fresh-variable scope."""
from judgment import Session, forall
def main():
s = Session()
A = s.declare_type("A")
proof = s.theorem("replace_under_forall")
values = proof.vars("a b", A)
a, b = values[0], values[1]
equality = proof.given("equality", a == b)
x = proof.bound_var("x", A)
proof.goal(forall(x, x == a) == forall(x, x == b))
opened = proof.lhs().under("z")
_ = opened.body().at(a).rw(equality)
_ = opened.finish()
proof.rfl()
print(proof.finish())
if __name__ == "__main__":
main()
Run from the repository root PYTHONPATH=bindings/python:docs/examples/python/library pixi run python docs/examples/python/library/binder_rewrites.py
Output
⊢ ∀a:A. ∀b:A. a = b → (∀x:A. x = a) = (∀x:A. x = b)
under("z") fixes a fresh variable over the current frame, performs the
rewrite, and lifts the equality across the binder by congruence when
opened.finish() runs.
Summary¶
| Operation | Scope | Role |
|---|---|---|
proof.have(name, prop) |
Current branch and continuation | Local lemma without a global declaration. |
proof.define(name, expr) |
Current branch and descendants | Local abbreviation; switch explicitly with fold / unfold. |
focus.under(name) |
Until opened.finish() |
Capture-avoiding rewrite inside forall, exists, or lambda_. |
Exercises¶
In intermediate_claims, remove step.resume() and step.exact(step.right(h)).
Does proof.finish() succeed once the continuation is solved?
Answer
No. step.fact() depends on proving first_component; leaving step deferred
leaves an open obligation in proof.obligations(), so finish() refuses.
In binder_rewrites, what happens if you call proof.lhs().at(a).rw(equality)
directly without under("z")?
Answer
The call fails (UNSUPPORTED or NO_MATCH). Binder bodies are opaque to at
to prevent variable capture; open them explicitly with under.