feat: verify primitive-model conservation through declaration checking - #32
Draft
kim-em wants to merge 8 commits into
Draft
feat: verify primitive-model conservation through declaration checking#32kim-em wants to merge 8 commits into
kim-em wants to merge 8 commits into
Conversation
kim-em
force-pushed
the
agent/hasprimitives-conservation
branch
from
August 4, 2026 01:34
9b323af to
8bee9c5
Compare
kim-em
force-pushed
the
agent/hasprimitives-conservation
branch
from
August 4, 2026 02:10
041c498 to
2283ffe
Compare
kim-em
marked this pull request as ready for review
August 6, 2026 03:00
kim-em
force-pushed
the
agent/hasprimitives-conservation
branch
from
August 12, 2026 01:35
eee5b1a to
40635ec
Compare
johnchandlerburnham
added a commit
to argumentcomputer/lean4lean
that referenced
this pull request
Aug 20, 2026
The reconcile merge 29d67a7 absorbed all five digama commits; the ladder entry is deleted per convention. Section 2 records: remote drift reconciled (watch items PR digama0#43/digama0#32/digama0#27 stand, re-checked at every checkpoint boundary), ladder position = lane phase (Lane R L4L-16N, Lane V checker pre-closure, Lane D D-ladder volume, 16E in slack). The V6 route-map row carries the banked repair recipe and its dependent-match residual (one focused Lane-V session); the collision risk row notes the absorption. reduceProjCore.WF discharge is ledger D022 (upstream-contribution candidate); D012 narrowed; D021 added.
kim-em
marked this pull request as draft
August 22, 2026 02:38
kim-em
force-pushed
the
agent/hasprimitives-conservation
branch
from
August 22, 2026 03:36
f01ded2 to
56af22f
Compare
List.Forall2 helpers, and the VDecl/VEnv/Typing lemmas the conservation argument needs about environment extension.
Nat.mod, Nat.div, Nat.gcd and Nat.bitwise are defined by non-structural recursion, so recognizing them requires unfolding a WellFounded.fix or a fuel-carrying go function and checking the result against the expected equations. Replace the ad-hoc unfolding with an explicit certificate: a NatWellFoundedCoreResult recording the unfolded shape, specialized to NatGcdFixCertificate or NatBitwiseFixCertificate and checked against the expected top/zero/succ equations. This is the only part of the branch that changes what the kernel accepts.
addDefinition now establishes the header and body typing facts before calling checkPrimitiveDef, because verifying checkPrimitiveDef needs those facts to justify its own isDefEq calls; the reserved-name check moves after the primitive result is available. addMutual checks each member with fresh caches and makes the block available through opaque headers rather than axioms, so no member's body can unfold another's unchecked value. Does not build on its own: Verify/Environment.lean is repaired in a later commit.
M.WF.sandbox, for computations that cannot invalidate verifier state, and the ReflectsNat* predicates that say what it means for an abstract environment to reflect a Nat operation. VEnv.HasPrimitives gains natPred and natBitwise fields.
Reflection predicates, the HasPrimitives extension lemmas, the certificate validity arguments, and a checkPrimitiveDef.<op>.WF_typed theorem for each of the 17 primitives, plus checkPrimitiveInductive.WF. Closedness side conditions are discharged by the fvars_closed tactic, which reduces FVarsIn structurally. Deciding hasFVar/hasMVar instead would not work: those read the cached Expr.data word built by the extern mkData, which the kernel cannot reduce.
The fuel and fixpoint reasoning for Nat.bitwise, Nat.mod and Nat.div, separated from the per-primitive conservation theorems that consume it.
Rebuild the environment verification layer on the restructured checkers: per-declaration WF theorems for the new addDefinition and addMutual, the mutual header/body relations, and the environment model for opaque mutual headers. addDecl.WF now discharges the primitive cases from the previous commits instead of admitting checkPrimitiveDef.WF. Verify/Environment/Extension.lean is superseded and retains only what is still referenced.
kim-em
force-pushed
the
agent/hasprimitives-conservation
branch
from
August 22, 2026 03:54
56af22f to
5aaa700
Compare
Record what the certificates are, why Nat.mod, Nat.div, Nat.gcd and Nat.bitwise need them, and what the checker verifies. Document the one acceptance difference from the previous checker: the gcd and bitwise certificates require the well-founded state to be built with PSigma.mk, where the previous checker was generic in the state type. Lean's shipped Nat.gcd uses exactly that representation and dispatch is by reserved name, so ordinary code is unaffected; the restriction is on which alternative preludes lean4lean accepts.
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.
This PR adds an end-to-end
addDecl.WFtheorem showing that successful declaration checking preserves a verified environment for the currently modeled fragment. It replaces ad hoc recognition of non-structural Nat primitives with checked reduction certificates, proves conservation ofVEnv.HasPrimitives, and rebuilds the declaration-level verification around those results. The diff contains 24,247 insertions and 1,264 deletions across 33 files.The final theorem is deliberately restricted by
Declaration.SupportedByModel:Inductive declarations are therefore out of scope entirely. For mutual definitions,
addMutual.WFtakes name uniqueness as a hypothesis. Master derived that fact from the executable name checker; this branch still rejects duplicate names, but its proof interface no longer derives the fact from that check.This does not mean that the kernel is verified. The branch removes one admitted proof and adds none, but
addDecl.WFstill depends onsorryAxthrough admitted lemmas elsewhere inLean4Lean/Verify/that are already present on master.#print axioms Lean4Lean.addDecl.WFreports 34 dependencies, includingsorryAxand twobv_decideaxioms originating inLean4Lean/Verify/Expr.lean, with nonative_decideaxiom.The executable certificate checker narrows the alternative preludes that lean4lean accepts. The
Nat.gcdandNat.bitwisecertificates require their two-Nat well-founded state to usePSigma.mk. Execution with Lean 4.33.0-rc2 confirms that the shippedNat.gcduses that representation, so the shipped prelude is unaffected. Ordinary user declarations cannot reach this difference becausecheckPrimitiveDefCoredispatches on the reserved declaration namesNat.gcdandNat.bitwise. An alternative prelude can reach it by defining one of those constants through a one-argument well-founded helper over another state type such asNat × Nat.doc/wf-certificate-design.mddescribes the comparison and proposes the correspondingdivergences.mdentry.Review the change top-down in this order:
Lean4Lean/Primitive.leanfirst. Commit2fc4f84changes that file by 1,223 insertions and 127 deletions and contains the executable acceptance delta: the generic well-founded reduction record, the GCD and bitwise specializations, and the closed equations for the fuel-based mod and div helpers.Lean4Lean/Verify/Environment.leannext, especiallyDeclaration.SupportedByModel,addMutual.WF, andaddDecl.WF, to see the final claim and every additional hypothesis.Nat.gcdend to end throughNatGcdFixCertificate,checkNatGcdFixCertificate.WF,NatGcdFixCertificate.NormalizedValid.reflects, and the GCD branch of primitive conservation. This is the representative well-founded case.27304beadds 9,808 lines across the nine reflection-toolbox files.Lean4Lean/Verify/Primitive.lean. Commitb2d9169adds 8,957 lines covering the per-primitive conservation development; the bitwise proof is the largest specialization, while the direct-equation primitives follow the same checker-to-model pattern.Validation on the exact pushed tree succeeds with:
lake build: 161 jobslake build Lean4Lean.Experimental: 68 jobslake build Lean4Lean.Tests: 63 jobslake exe lean4lean Init.Core: 1,035 declarations checkedlake exe lean4lean --fresh Init.Core: 3,953 declarations checkedAll commands exit successfully.
🤖 Prepared with Claude Code