formalization(tc): verify WHNF, inference, DefEq, and the recursive method knot - #528
Open
johnchandlerburnham wants to merge 4 commits into
Open
formalization(tc): verify WHNF, inference, DefEq, and the recursive method knot#528johnchandlerburnham wants to merge 4 commits into
johnchandlerburnham wants to merge 4 commits into
Conversation
arthurpaulino
approved these changes
Aug 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR substantially expands the formal verification of the production
Ix.Tckernel. It completes the K1 WHNF layer and the K2 inference/definitional-equality layer, then assembles all six recursive methods into a single fixed-universe closure theorem.
The principal result is
RecursiveMethodClosureContext.closedAt, which combines:K1ClosureContext.closedAt; andinferandisDefEqcontracts fromInferDefEqClosureContext.closedAt.This proves every finite
methodsNapproximation selected by the production recursive runner satisfies the six-methodMethods.WFAtcontract. The proof is non-circular: each unfolded method-table layer may assume correctness only of the strictly smaller predecessor table.
The formalization remains over
Ix.Tc. Transporting these results to the Rust kernel through Aeneas, or directly to the Aiur IxVMimplementation, remains later work.
WHNF verification
The K1 portion verifies the structural, no-delta, full-WHNF, and trusted-delta reducer layers, including:
The WHNF proof is organized by semantic responsibility under directories such as
Beta/,Iota/,Structural/,NoDelta/,Driver/,Delta/,Projection/,StructEta/, andRuntime/.Inference verification
The K2 inference layer provides an exhaustive proof of the production uncached dispatcher and its public cache shell. It covers:
inferOnlybehavior.Successful inference returns a supported kernel expression whose translation is a valid Theory type for the translated source. Partial errors
preserve the checker invariant.
Definitional-equality verification
The K2 DefEq layer follows the production reducer in its exact phase order and verifies:
isDefEqcache shell.A successful
isDefEqresult is connected toVEnv.IsDefEqUfor the translated operands.Cache and context-key soundness
The PR adds a joint K1/K2 cache model for WHNF, inference, DefEq, and proposition-classifier entries.
Notable changes include:
The Lean and Rust equivalence managers now retain both radii in
EqKey. Root-cache reuse is accepted only when the representativesreconstruct the requested comparison scope.
The distinction between expression-address collision freedom and collision freedom of the composite context digest is documented in
docs/tc- context-digest-collision-boundary.md.Recursive closure
The final assembly adds:
Methods.WhnfLayerWFAtfor the four K1 fields;Methods.InferDefEqLayerWFAtfor the two K2 fields;Methods.ClosedAt.of_partsfor their exact composition;InferDefEqClosureContext.closedAt;RecursiveMethodClosureContext.closedAt;methodsNapproximation; andTcM.runRec_wfAtfor transporting a reader-level proof to the concrete finite method table selected by the production state.No field assumes the correctness of the method-table layer it is currently proving.
Production hardening surfaced by the proof
The proof effort also produced several aligned Lean/Rust kernel changes:
abstractFVarsno longer takes the no-free-variable fast path when loose bound variables still require shifting.Explicit remaining boundaries
This PR closes the fixed-universe K1/K2 recursive core under explicitly named semantic resources. It does not yet claim the final end-to-end
checker theorem.
The remaining boundaries are intentionally visible:
TcM.whnf.wf,TcM.infer.wf,TcM.isDefEq.wf, andTcM.checkConst.wfremain the four separately audited public statement-frontier roots.tryNatOffsetStuckstage remains an explicitOptionalReduction.WFAtpremise until its callbacks and intern operations areinstantiated from finite run-scoped contracts.
address collision freedom alone is not sufficient.
TcM.WFresults establish invariant preservation and semantic correctness of successful results; they do not assert that every checkerinvocation succeeds.
Verification
lake build IxTcVerifylake build Ix.Tc.Verify.Audit.Completed Ix.Tc.Verify.Audit.Statementsperl .github/scripts/check_tc_verify_sorries.pllake lint -- --wfail -vThe completed trust manifest currently enumerates 1,510 theorem roots. The four public statement-frontier roots are audited separately, and
legacy whole-environment and broad delta-authority dependencies are forbidden from the completed closure surface.
The branch is two commits ahead of
mainand is published asjcb/formalization.