5.9 Transport theorems between theories with interpretations¶
Tutorial sequence · Previous: 5.8 Verify an exported proof in Isabelle/HOL
Goal: translate types and terms across two sessions sharing a base snapshot
(TypeImage, transport_type, transport_term, prepare_interpretation),
replay a checked derivation from an abstract theory into a concrete theory with
reuse to discharge source axioms, and verify atomic refusal when a proof
obligation is omitted.
Complete the Store setup from Lesson 5.4
(libjudgment_store.so on Linux, libjudgment_store.dylib on macOS).
Checked theory interpretations¶
Suppose an abstract theory declares an unspecified carrier Carrier and an
involution op : Carrier → Carrier with axiom ∀ x, op(op(x)) = x, and proves
a collection of theorems over it. Given a concrete carrier Concrete whose
operation (λ y, y) satisfies that law as a proved theorem (with zero axioms),
a checked theory interpretation (theory interpretations):
- maps every non-base source type constructor via
TypeImage(constructor, parameters, body)and every non-base source constant via(source_const, target_expr); - verifies that every source axiom and defining equation is matched by a
checked target
Factproving its translated statement; and - replays the source theorem's derivation through
judgment_corein the target session and publishes the resulting targetFact.
Because every replayed inference is checked in target, any source axiom
discharged by a proved target theorem disappears from the transported theorem's
axioms().
Syntax transport vs. checked proof replay¶
| Operation | Role | Establishes proof authority? |
|---|---|---|
transport_type |
Translates a TypeExpr across sessions using TypeImage templates |
No |
transport_term / transport_scoped_term |
Translates closed or frame-scoped syntax across sessions | No |
prepare_interpretation |
Validates the type, constant, and literal mapping once inside paired transactions (PreparedInterpretation.type_, .term, .scoped_term) |
No |
reuse |
Validates the full source signature, replays a theorem's proof DAG in target, and registers the checked target Fact |
Yes (checked by judgment_core) |
Mojo
"""Transport types, terms, and checked proofs between theories over a common base snapshot."""
from judgment import Session, arrow, forall, lambda_
from judgment_shell import LibErrorKind
from judgment_store import TypeImage, prepare_interpretation, reuse, transport_term, transport_type
from std.testing import assert_equal, assert_true
from termbank import Budget
def main() raises:
var budget = Budget(20_000_000)
# Seal an explicit common base snapshot shared by the abstract and concrete theories.
var base_session = Session()
var base = base_session.seal()
# 1. Abstract source theory: a carrier C, an operator op : C -> C, an involution axiom,
# and a derived theorem proving op(op(op(op(x)))) = x.
var source = Session.open(base)
var Carrier = source.type_constructor("Carrier", 0)
var C = Carrier()
var op = source.symbol("op", arrow(C, C))
var sx = source.bound_var("x", C)
var invol = source.axiom("invol", forall(sx, op(op(sx)) == sx))
var quad_proof = source.theorem("quad", forall(sx, op(op(op(op(sx)))) == sx))
var x_var = quad_proof.intro_var("x")
var chain = quad_proof.calc(op(op(op(op(x_var)))))
chain.eq(op(op(x_var)), invol, "outer_invol")
chain.eq(x_var, invol, "inner_invol")
quad_proof.exact(chain.finish())
var quad = quad_proof.finish()
assert_equal(len(quad.axioms()), 1)
# 2. Concrete target theory: a type Concrete where op is interpreted as the identity function.
var target = Session.open(base)
var Concrete = target.declare_type("Concrete")
var ty = target.bound_var("y", Concrete)
var id_fn = lambda_(ty, ty)
var target_invol_proof = target.theorem("id_invol", forall(ty, id_fn(id_fn(ty)) == ty))
_ = target_invol_proof.intro_var("y")
target_invol_proof.rfl()
var target_invol = target_invol_proof.finish()
assert_equal(len(target_invol.axioms()), 0)
# 3. Transport syntax (types and terms) and reuse a prepared interpretation across operands.
var type_map: List[TypeImage] = [TypeImage(Carrier, [], Concrete)]
var translated_ty = transport_type(source, target, base, C, type_map, budget)
assert_true(translated_ty.same_as(Concrete))
var translated_stmt = transport_term(source, target, base, quad.statement(), [(op, id_fn)], budget, type_images=type_map)
var stx = source.transaction()
var ttx = target.transaction()
var prepared = prepare_interpretation(source, target, base, [(op, id_fn)], budget, type_images=type_map)
var prepared_ty = prepared.type_(source, target, base, C, budget)
var prepared_stmt = prepared.term(source, target, base, quad.statement(), budget)
stx.discard()
var retained = ttx.commit(types=[prepared_ty], exprs=[prepared_stmt])
assert_true(retained.types()[0].same_as(Concrete))
assert_true(retained.expressions()[0].same_as(translated_stmt))
print("Transported type:", translated_ty.format(), "| prepared syntax matches:", retained.expressions()[0].same_as(translated_stmt))
# 4. Replay the source derivation in the target session, discharging the source axiom completely.
var transported = reuse(
source, target, base, quad, "concrete.quad_id",
[(op, id_fn)], [(invol, target_invol)], budget, type_images=type_map,
)
assert_true(transported.statement().same_as(translated_stmt))
assert_equal(len(transported.axioms()), 0)
assert_equal(len(transported.admissions()), 0)
print("Source axioms:", len(quad.axioms()), "| transported target axioms:", len(transported.axioms()))
# 5. Omitting a required source axiom obligation is refused atomically.
var refused = False
try:
_ = reuse(source, target, base, quad, "concrete.missing_obligation", [(op, id_fn)], [], budget, type_images=type_map)
except e:
assert_equal(e.kind, LibErrorKind.NO_MATCH)
refused = True
assert_true(refused)
print("Incomplete obligation refused:", refused)
Run from the repository root pixi run mojo run -I src docs/examples/store/theory_interpretation.mojo
Output
Transported type: Concrete | prepared syntax matches: True
Source axioms: 1 | transported target axioms: 0
Incomplete obligation refused: True
Python
"""Transport types, terms, and checked proofs between theories over a common base snapshot."""
from judgment import (
Budget, JudgmentError, LibErrorKind, Session, TypeImage, arrow, forall, lambda_,
prepare_interpretation, reuse, transport_term, transport_type,
)
def main():
budget = Budget(20_000_000)
# Seal an explicit common base snapshot shared by the abstract and concrete theories.
base_session = Session()
base = base_session.seal()
# 1. Abstract source theory: a carrier C, an operator op : C -> C, an involution axiom,
# and a derived theorem proving op(op(op(op(x)))) = x.
source = Session.open(base)
Carrier = source.type_constructor("Carrier", 0)
C = Carrier()
op = source.symbol("op", arrow(C, C))
sx = source.bound_var("x", C)
invol = source.axiom("invol", forall(sx, op(op(sx)) == sx))
quad_proof = source.theorem("quad", forall(sx, op(op(op(op(sx)))) == sx))
x_var = quad_proof.intro_var("x")
chain = quad_proof.calc(op(op(op(op(x_var)))))
chain.eq(op(op(x_var)), invol, "outer_invol")
chain.eq(x_var, invol, "inner_invol")
quad_proof.exact(chain.finish())
quad = quad_proof.finish()
assert len(quad.axioms()) == 1
# 2. Concrete target theory: a type Concrete where op is interpreted as the identity function.
target = Session.open(base)
Concrete = target.declare_type("Concrete")
ty = target.bound_var("y", Concrete)
id_fn = lambda_(ty, ty)
target_invol_proof = target.theorem("id_invol", forall(ty, id_fn(id_fn(ty)) == ty))
target_invol_proof.intro_var("y")
target_invol_proof.rfl()
target_invol = target_invol_proof.finish()
assert len(target_invol.axioms()) == 0
# 3. Transport syntax (types and terms) and reuse a prepared interpretation across operands.
type_map = [TypeImage(Carrier, [], Concrete)]
translated_ty = transport_type(source, target, base, C, type_map, budget)
assert translated_ty.same_as(Concrete)
translated_stmt = transport_term(source, target, base, quad.statement(), [(op, id_fn)], budget, type_images=type_map)
stx = source.transaction()
ttx = target.transaction()
prepared = prepare_interpretation(source, target, base, [(op, id_fn)], budget, type_images=type_map)
prepared_ty = prepared.type_(source, target, base, C, budget)
prepared_stmt = prepared.term(source, target, base, quad.statement(), budget)
stx.discard()
retained = ttx.commit(types=[prepared_ty], exprs=[prepared_stmt])
assert retained.types()[0].same_as(Concrete)
assert retained.expressions()[0].same_as(translated_stmt)
print("Transported type:", translated_ty.format(), "| prepared syntax matches:", retained.expressions()[0].same_as(translated_stmt))
# 4. Replay the source derivation in the target session, discharging the source axiom completely.
transported = reuse(
source, target, base, quad, "concrete.quad_id",
[(op, id_fn)], [(invol, target_invol)], budget, type_images=type_map,
)
assert transported.statement().same_as(translated_stmt)
assert len(transported.axioms()) == 0
assert len(transported.admissions()) == 0
print("Source axioms:", len(quad.axioms()), "| transported target axioms:", len(transported.axioms()))
# 5. Omitting a required source axiom obligation is refused atomically.
refused = False
try:
reuse(source, target, base, quad, "concrete.missing_obligation", [(op, id_fn)], [], budget, type_images=type_map)
except JudgmentError as e:
assert e.kind == LibErrorKind.NO_MATCH
refused = True
assert refused
print("Incomplete obligation refused:", refused)
if __name__ == "__main__":
main()
Run from the repository root PYTHONPATH=bindings/python:docs/examples/python/store pixi run python docs/examples/python/store/theory_interpretation.py
Output
Transported type: Concrete | prepared syntax matches: True
Source axioms: 1 | transported target axioms: 0
Incomplete obligation refused: True
Soundness invariants¶
- Shared base snapshot: both
sourceandtargetmust descend from the same authenticatedbasesnapshot. Base declarations (Prop,=, logical connectives) map identically; every declaration introduced afterbaseinsourcemust be mapped explicitly. - Whole-signature completeness:
reusechecks every non-base declaration and obligation in the source signature, even if the transported theorem does not cite every axiom. Omitting the proof image forinvolfails immediately withNO_MATCH. - Paired transactions (
prepare_interpretation): aPreparedInterpretationreuses its validated declaration table and type memo while both endpoint transactions remain open. Discard the source readback transaction (stx.discard()) before committing the target transaction (ttx.commit(...)), retaining required handles. - Same-session interpretations:
sourceandtargetmay be the sameSession(instantiating an abstract sub-theory inside one workspace); one transaction then covers both sides.
Exercise¶
In theory_interpretation, replace [(invol, target_invol)] with a target
fact proving True = True instead of ∀ y, id(id(y)) = y. What happens?
Answer
reuse translates invol's statement under the type and constant maps, rejects
the mismatch, and rolls back the target transaction without publishing
concrete.quad_id.
Next: 5.10 Check a symbolic transformation, or see the Interpretations API reference.