Logic & kernel theory

Checking at the boundary

This page states the guarantees of checking at the request boundary: proofs are checked where results leave a request, provisional facts circulate inside it, and yet every result labeled checked is a valid judgment. The argument reduces everything to two facts: the kernel's soundness (Theorem M-1, together with the trusted-base assumption that the kernel implements the rules) and three invariants enforced by the API.

The system as a state machine

Definition B-1 (state). At any moment the system has:

  • \(K\), the set of judgments of the proof rows that a check of the kernel has ever passed, in the bank or in a workspace (local checking, Definition LC-14); a truncation removes rows, never judgments, from \(K\);
  • \(S\), the contents of the durable and shared stores;
  • for each open request \(r\), a session holding a set \(F_r\) of provisional facts, each a proposition with a recipe;
  • the results returned so far, each with a label (Definition B-2).

Definition B-2 (labels). A result is a claim \(\Gamma \vdash A\) (an answer, a conditional answer \(G \Rightarrow e = e'\), or a fact) with a label: Checked with a handle \(j\), or Unchecked with a recipe.

Requirement B-R1 (kernel correctness, trusted). Every \(j \in K\) is the conclusion of a derivation in the theory of its context, by the rules of the deduction page, from exactly the recorded dependencies, and the home theory recorded for it includes the home theory of that derivation (Definition D-5).

The three invariants

Invariant Statement Enforced by
B-I1 (return) A result labeled Checked carries a handle \(j \in K\) whose judgment is the claim. Labels are computed from the handle; a session hands out a handle only for a row the kernel's check passed.
B-I2 (store) \(S \subseteq K\). A library is written only from rows below the verified watermark (ST9.9); a seal commits a session's rows into the shared bank, whose checks pass them before its watermark does.
B-I3 (confinement) A provisional fact of \(F_r\) is never read by a request other than \(r\), never written to \(S\), and is discarded when \(r\) closes. The session owns \(F_r\); no API passes provisional facts across sessions.

Theorem B-1 (the invariants are preserved). Every operation of the system preserves B-I1, B-I2, and B-I3.

Proof. By cases on the operations. Checks only add to \(K\); B-I1 and B-I2 are statements about membership in \(K\), which only grows. Store writes publish only rows that checks have passed, so B-I2 is kept. Returning a result computes the label from the presence of a handle, which names a checked row (a handle of another session, or of a row that a truncation removed, is rejected, G6), so B-I1 is kept. Engine steps add to the \(F_r\) of their own session, and the session API exposes \(F_r\) only to engines running in \(r\) (B-I3). Closing a request discards \(F_r\). \(\square\)

Workspaces. A session builds the rows of a request in a workspace over a verified prefix of the bank (DAG storage, TD1.12). A failed operation or a return to a snapshot truncates the workspace, and a fork that is not merged is discarded. Every handle to a removed row is then stale: the session rejects it (G6), so its judgment can enter no later derivation, store, or result. The judgment stays in \(K\), the set of judgments whose rows a check has ever passed (Definition B-1), so \(K\) only grows; the judgment stays derivable and is merely no longer reachable. A fork merged into its parent (Session.merge) is committed into the parent's workspace, where its rows are checked again (Definition LC-20), and the fork's handles become stale. A session's rows reach the shared bank only by a seal, whose checks run again there, so B-I2 is kept.

Soundness

Theorem B-2 (boundary soundness). Assume B-R1 and the invariants. Then:

  1. every result labeled Checked is valid (Definition M-4) in every model of its recorded home theory, which contains the logic core, its recorded dependencies, and the canonical signature (Definition D-5), and hence in every model of every theory that includes it;
  2. every element of every durable or shared store is valid in the same sense;
  3. no provisional fact, true or false, affects the validity of any Checked result or stored judgment.

Proof. (1) By B-I1 the result has a handle \(j \in K\) for its claim; by B-R1 the claim is derivable from \(j\)'s dependencies; by Theorem D-2 it is derivable in the subcontext of the hypotheses and locals it uses, and by Theorem D-8 in its recorded home theory, which contains the declarations it uses; by Theorem M-1 it is valid in every model of that theory. (2) By B-I2 and the same argument. (3) A provisional fact can influence a Checked result only by becoming part of the kernel derivation behind the result's handle. A recipe that cites the fact is expanded into proof steps that derive it; if the fact is false, no derivation exists (by (1) applied to the model in which it fails), the kernel's check fails, and no handle is created. The fact cannot reach a store or another request (B-I3). \(\square\)

Corollary B-3 (cost of wrong search). An engine that derives false provisional facts can cause a failed check, and hence a missing or worse answer, but never an accepted false judgment. The recovery procedure of the architecture note (section 30.8) changes which answer is returned, never whether a Checked label is sound.

What Unchecked means

An Unchecked result is a claim with a recipe and no handle. Theorem B-2 says nothing about it: it may be false. Its label makes this visible, and B-I2 keeps it out of every store. If the recipe is later checked and succeeds, the result becomes Checked with that handle; nothing else can change its label.

Determinism and replay

Requirement B-R2 (deterministic runs). A run with deterministic budgets (counts of steps, not wall-clock time) is a function of its inputs: the request, the configuration, the contents of the stores it reads, and the versions of the engines and the kernel.

Proposition B-4 (proofs on demand). Under B-R2, rerunning a request reproduces the same provisional facts, the same recipes, and the same selected result, so a proof that was not materialized can be rebuilt and checked later; the check succeeds exactly when it would have succeeded during the first run.

Proof. The rerun computes the same function on the same inputs; the kernel's check is a function of the recipe and the theory. \(\square\)

Proposition B-4 lets a request keep a recipe instead of a proof and check the proof only when someone asks. It needs every engine the run used, at its version. A library stores proofs instead, and checking them again needs no engine (Proposition B-6).

Generic answers

Proposition B-5. If the CAS returns \(e'\) for \(e\) in generic mode, the returned result is a Checked judgment \(\Gamma \vdash G \Rightarrow e = e'\) with \(G\) generic (Definition X-6). By Theorem B-2 it is valid: under every valuation that satisfies the context and \(G\), \(e\) and \(e'\) have the same value. Where \(G\) fails (at the excluded points), nothing is claimed.

Stored proofs

Definition B-3 (stored proof). The stored proof of a theorem that a library proves is the PROOF row that its partition's export table names, with the rows that row reaches: term nodes, frames, declarations, theories, and proof rows, each proof row with its conclusion (ST9.6, proof libraries). Its rows name declarations, terms, frames, and premises. None names a recipe, a search engine, or a certificate: termbank.dag refuses CERTIFICATE and SEALED proof rows at commit (local checking, LC-R8), and the trusted base admits no certificate checker.

Proposition B-6 (rechecking without search). A load of a library version, and Library.recheck (proof libraries, Definition L-7), commit the version's stored proofs into a bank over the current checker and profile and check every row. Each refuses the whole version unless every row passes, and neither runs a search engine. Checking the same rows with the same checker and profile gives the same result at every worker count. Checking them with another checker, such as one with a bug fixed, decides the theorems anew: by Theorem B-2, a theorem whose recheck succeeds is valid in every model of its home theory, whatever checker first checked it.

Proof. The rows are data. A row's check reads only the rows of its cone (Lemma LC-15), and the verdicts do not depend on scheduling (Theorem LC-18), so the checks are deterministic functions of the rows, the checker, and the profile (Requirement B-R2); none of them calls an engine. A load refuses the whole version on any refusal (Definition L-7), which gives the first two statements. The last is Theorem B-2, with Corollary LC-13, applied to the rechecking checker. \(\square\)

A theorem stored in a library therefore rests on its stored proof, not on the checker that first checked it: every load checks the proof again with the current checker, and Library.recheck checks a whole version in a fresh bank without changing anything. The one exception is a statement-only import (ST9.8), which declares a theorem without its proof and checks no proof row for it; the version's producer is trusted for that statement (SG1). No recipe is stored. Proposition B-4 rebuilds a proof by rerunning the request, and a closed recipe (recipes, Definition R-3) replays without search inside a session (Theorem R-2), but neither is a durable record.

External decisions

An external decision procedure, such as an RCF decider or an SMT solver, is an untrusted engine. Its answer can enter a derivation only with a certificate that an expander turns into rows the kernel checks, or as a hypothesis.

Proposition B-7 (external decisions as hypotheses). Let a derivation of \(\Gamma, h: C \vdash R\) use the claim \(C\) of an external decider as the hypothesis \(h\), and let export discharge it, giving \(\Gamma \vdash C \to R\). Then:

  1. \(\Gamma \vdash C \to R\) is valid in every model of its home theory (Theorem B-2), whether or not the decider was right;
  2. if \(\Gamma \vdash C\) is later derived, from a certificate checked by the kernel's rules, \((\to\mathrm E)\) gives \(\Gamma \vdash R\);
  3. no result labeled Checked claims \(R\) itself unless \(C\) has been derived.

Proof. (1) The export is a derivation by the rules (Theorem D-4), so Theorem B-2 applies. (2) is one rule. (3) A label is computed from a handle (invariant B-I1), and the only handle the decision contributes is that of \(C \to R\). \(\square\)

A wrong external answer therefore costs at most a guarded result whose guard is false. It never becomes a false checked claim, and it never enters a theory as an axiom, where it could make the theory inconsistent.

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