1.7 Define names and track assumptions¶
Tutorial sequence · Previous: 1.6 Reuse a theorem
Goal: declare transparent and opaque definitions, unfold definitions explicitly during conversion, register named theorems, and audit axiom dependencies.
A Session maintains a current theory of declarations (types, constants,
definitions, axioms, and proved theorems). Each declaration extends the theory
under a fresh name.
Transparent vs. opaque definitions¶
The example below defines two proposition constants equal to True (s.true_()):
one transparent to conversion and one opaque. It proves the transparent equation
by controlled unfolding and reflexivity, saves the opaque defining equation as
a theorem, and demonstrates expected kernel refusals when unfolding is omitted
or disallowed.
Mojo
"""Compare transparent and opaque definitions and save a proven equation."""
from std.testing import assert_true
from judgment import Session
from judgment_shell import LibErrorKind
def main() raises:
var s = Session()
var truth = s.true_()
var absent = False
try:
_ = s.fact("Hidden")
except e:
absent = e.kind == LibErrorKind.NO_MATCH
assert_true(absent)
var visible = s.define("Visible", truth, transparent=True)
var hidden = s.define("Hidden", truth, transparent=False)
var visible_term = visible.symbol()
var hidden_term = hidden.symbol()
assert_true(not visible_term.same_as(truth))
# A transparent definition unfolds during explicit conversion.
var by_conv = s.theorem("visible_is_true", visible_term == truth)
by_conv.change(truth == truth, unfold=[visible])
by_conv.rfl()
var visible_fact = by_conv.finish()
assert_true(visible_fact.statement().same_as(visible_term == truth))
# Without explicit unfolding, and for opaque definitions, conversion refuses.
var no_unfold = False
try:
var blocked = s.theorem("visible_no_unfold", visible_term == truth)
blocked.change(truth == truth)
except e:
no_unfold = e.kind == LibErrorKind.KERNEL or e.kind == LibErrorKind.SHAPE
assert_true(no_unfold)
var opaque_blocked = False
try:
var blocked = s.theorem("hidden_by_conv", hidden_term == truth)
blocked.change(truth == truth, unfold=[hidden])
except e:
opaque_blocked = e.kind == LibErrorKind.KERNEL or e.kind == LibErrorKind.SHAPE
assert_true(opaque_blocked)
# Even an opaque definition supplies a checked defining equation.
var equation = hidden.equation()
var expected = hidden_term == truth
assert_true(equation.statement().same_as(expected))
var saved_proof = s.theorem("hidden_is_true", expected)
saved_proof.exact(equation)
var saved = saved_proof.finish()
var reused = s.fact("hidden_is_true")
assert_true(saved.statement().same_as(expected))
assert_true(reused.statement().same_as(expected))
assert_true(len(reused.axioms()) == 0)
print("Transparent definition: equal by conversion")
print("Opaque definition: equation proved, saved, and reused")
Run from the repository root pixi run mojo run -I src docs/examples/definitions.mojo
Output
Transparent definition: equal by conversion
Opaque definition: equation proved, saved, and reused
Python
"""Compare transparent and opaque definitions and save a proven equation."""
from judgment import Session, JudgmentError
from judgment import LibErrorKind
def main():
s = Session()
truth = s.true_()
absent = False
try:
_ = s.fact("Hidden")
except JudgmentError as e:
absent = e.kind == LibErrorKind.NO_MATCH
assert absent
visible = s.define("Visible", truth, transparent=True)
hidden = s.define("Hidden", truth, transparent=False)
visible_term = visible.symbol()
hidden_term = hidden.symbol()
assert not visible_term.same_as(truth)
# A transparent definition unfolds during explicit conversion.
by_conv = s.theorem("visible_is_true", visible_term == truth)
by_conv.change(truth == truth, unfold=[visible])
by_conv.rfl()
visible_fact = by_conv.finish()
assert visible_fact.statement().same_as(visible_term == truth)
# Without explicit unfolding, and for opaque definitions, conversion refuses.
no_unfold = False
try:
blocked = s.theorem("visible_no_unfold", visible_term == truth)
blocked.change(truth == truth)
except JudgmentError as e:
no_unfold = e.kind == LibErrorKind.KERNEL or e.kind == LibErrorKind.SHAPE
assert no_unfold
opaque_blocked = False
try:
blocked = s.theorem("hidden_by_conv", hidden_term == truth)
blocked.change(truth == truth, unfold=[hidden])
except JudgmentError as e:
opaque_blocked = e.kind == LibErrorKind.KERNEL or e.kind == LibErrorKind.SHAPE
assert opaque_blocked
# Even an opaque definition supplies a checked defining equation.
equation = hidden.equation()
expected = hidden_term == truth
assert equation.statement().same_as(expected)
saved_proof = s.theorem("hidden_is_true", expected)
saved_proof.exact(equation)
saved = saved_proof.finish()
reused = s.fact("hidden_is_true")
assert saved.statement().same_as(expected)
assert reused.statement().same_as(expected)
assert len(reused.axioms()) == 0
print("Transparent definition: equal by conversion")
print("Opaque definition: equation proved, saved, and reused")
if __name__ == "__main__":
main()
Run from the repository root PYTHONPATH=bindings/python:docs/examples/python pixi run python docs/examples/python/definitions.py
Output
Transparent definition: equal by conversion
Opaque definition: equation proved, saved, and reused
s.define(name, body, transparent=...) declares a closed constant and returns
a Definition with .symbol() and its checked defining .equation().
transparent controls only whether conversion may unfold the symbol when
explicitly requested:
VisibleandTrueremain distinct expressions until unfolded.change(truth == truth, unfold=[visible])checks convertibility while unfolding only the definitions listed, leaving a reflexive goal forrfl().- Without
unfold=[visible],changefails because conversion unfolds no definitions by default. Hiddencannot be unfolded by conversion even if listed, thoughhidden.equation()still provides the checked equalityHidden = True.
See three ways to compare expressions for the distinction between syntactic identity, conversion, and proved equality.
Named theorems and lookup¶
finish() registers a theorem under its name, retrievable via s.fact(name)
(an undeclared name raises NO_MATCH; s.find(prefix) lists matching names).
Premises, definitions, and axioms¶
| Construct | Contribution | Effect on finished theorems |
|---|---|---|
given / intro |
Local hypothesis | Discharged as an implication premise. |
s.define(...) |
Conservative constant with defining equation | No axiom added; defining equation is checked. |
s.axiom(...) |
Unproved closed proposition | Recorded in axioms() of every dependent theorem. |
s.axiom(name, prop) checks well-formedness and tracks provenance in the
dependency closure; the kernel does not check consistency of user axioms.
Inspect any Fact with:
fact.statement()— the proved proposition;fact.axioms()— transitive axiom dependencies;fact.admissions()— explicitly admitted obligations (admit);fact.format(details=True)— statement together with dependencies.
For exploratory declarations that should not pollute the main theory, use
transactions, snapshots, or forks. See also the
API guide and
Session reference.
Exercise¶
Set transparent=False on Visible. How must the proof of visible_is_true
change?
Answer
Conversion can no longer unfold Visible. Replace change(..., unfold=[visible])
and rfl() with by_conv.exact(visible.equation()).