Proof authoring theory

Recipes

A recipe describes how to build a judgment. It is data: untrusted, serializable, and meaningful only when run in a session.

Definition R-1 (recipe). A recipe is a finite list of steps \(s_1, \dots, s_n\), each referring only to earlier steps, with a designated root. A step is one of:

Step Meaning
Rule(tag, operands) one kernel inference rule (K1.8), with operands that are earlier steps (for premises), terms, types, declarations, locals, hypotheses, or contexts
Theorem(decl, type_args, terms) the kernel's use of an axiom, theorem, or definition equation
Cite(fact) a provisional fact of the current request, which carries its own recipe
Stored(handle) a step already checked in this session, such as a theorem from a store
Derived(name, operands) a derived rule (Definition R-2)
Certificate(kind, data, claim) a certificate, expanded by its registered expander into steps that prove claim
Search(engine, query) a call to an engine, which returns a recipe for the query

Terms and types in a recipe are either session handles (in memory) or raw syntax with the information needed to certify it (when serialized by judgment_store).

Definition R-2 (expanders). A derived rule or certificate expander is a function from operands to a recipe whose root proves the step's conclusion. It is deterministic when its output is a function of its operands and the session's answers to the queries it makes.

Definition R-3 (closed recipe). A recipe is closed when it contains no Search step, every Cite names a fact whose recipe is closed, and every expander it uses is deterministic. A closed recipe can therefore be replayed without any engine.

Definition R-4 (running a recipe). Running a recipe in a session expands every Derived and Certificate step, runs every cited fact's recipe, executes every Search step's returned recipe (in an open recipe), and then calls, in step order, the session's operation for each Rule and Theorem step, passing the steps of earlier steps as premises. The result is the root's step, or an error naming the first step that failed. The run is one transaction: a failure discards it, leaving the session's rows as they were.

Soundness

Theorem R-1 (running is sound). If running a recipe returns a step \(j\), then \(j\) is a step the session's checked operations created, and it is valid in every model of its theory restricted to its dependencies.

Proof. Every step the procedure returns or passes on was returned by a session operation, which writes proof rows that the stateless checker checks; the recipe never constructs a step itself (it cannot: only the session creates handles). The validity statement is the soundness theorem of the local checking page. \(\square\)

No property of the recipe, its expanders, or the engines it called enters this argument. A wrong recipe fails to run; it cannot produce a wrong judgment.

Determinism and replay

Theorem R-2 (closed recipes replay). Let \(r\) be closed. Running \(r\) twice, in sessions at the same version whose theories contain the same declarations, gives steps with the same proposition, the same context entries, and the same dependencies.

Proof. A closed recipe calls no engine. Its expansions are deterministic (Definition R-2), so both runs execute the same sequence of session operations on structurally equal operands. The session and the checker are deterministic (ground rule G1), and canonical forms of terms without locals depend only on their content. A local is its binding site: the frame it extends, its type, and its name (CG9). The derived rules fix their own locals under reserved names, chosen by variant over the locals of their own run (L1.6), so both runs fix locals at the same binding sites. So every call returns structurally equal results, by induction on the steps. \(\square\)

No recipe is stored: a proof library keeps proof rows, which a load checks again without any recipe or engine (Proposition B-6 of checking at the boundary). Theorem R-2 lets a proof that was not kept be rebuilt by running its closed recipe again in a session of the same version.

Running and direct calls

Theorem R-3 (running agrees with direct calls). For each Rule step, running it in a session and calling the session's operation for its rule directly, on the same operands, produce steps with the same statement and frame.

Proof. run dispatches a rule step to the session's operation for its rule, with the operands the step names; the operation is deterministic (ground rule G1), and both steps are proof rows that the stateless checker checks with the same rule implementation (ground rule G10). \(\square\)

Failure

Proposition R-4 (the first failing step). If running a recipe fails, the error names the first step, in step order, whose session operation raised.

Proof. Steps run in order, and the procedure stops at the first error. \(\square\)

This is what recovery after a failed check needs (architecture note, section 30.8): the failing step identifies the rule or engine to quarantine.

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