Repository navigation
fix: primitive-definition recognizer does not establish what the model assumes - #2
vasnesterov wants to merge 1 commit into
Conversation
…aims Three defects in Environment.checkPrimitiveDef, each of which let a declaration pass the check without the property the abstract model then assumes of it. This check is lean4lean-only (see divergences.md): Lean itself does not verify that primitives are declared with the right types and definitional behaviour, because it ships its prelude. Char.ofNat and String.ofList were recognized up to definitional equality while the model pins their VConstant to a literal syntactic type, and the translation reads the declared type off structurally. Declaring Char.ofNat at `(fun _ : Nat => Nat → Char) Nat.zero` passed the check and produced a different constant. They now compare with Expr.eqv, which is exactly what the translation sees through -- the toolchain declares both at the expected shape up to binder name. The Nat equations were compared as `∀ _ : Nat, e₁` against `∀ _ : Nat, e₂`, a deliberately ill-typed pseudo-type used to get under a binder. Since `Nat.add x 0` is not a type, those comparisons had no translation witness at all and so carried no semantic content. They are now checked under withLocalDecl-bound free variables, as the Nat.div and Nat.mod branches already did. Nat.land and Nat.lor were additionally binding their Bool variable at type Nat. And every arithmetic branch built Nat and Bool literals, and depended on other primitives' semantics, without requiring any of them present. Each was implied by a later checkType, but only by inverting "type checking succeeded" -- and the witnesses the specification demands cannot be built before that inversion is available. They are now explicit guards. The recognizer is strictly stricter than before. Kernel Arena is unchanged at 185 correct / 6 either / 0 incorrect, and the run_meta self-test over all 24 entries of Environment.primitives still passes. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Can it be splitted into 3 (or 4) PRs, one for each problem? |
|
Split as requested. Four PRs, one per defect, each independent and applying to pristine
The fourth was not in this PR at all — it was found afterwards, while assembling the proof, and it turned out to have a second instance I had not seen: the equations' right-hand sides also mention primitives whose types On testing: each of the four makes the recognizer strictly stricter, and the combined change was arena-verified at 185 correct / 6 either / 0 incorrect — the baseline. Since each split is a subset of that strictness, none can reject anything the combined version accepted, so a per-branch arena run is not needed to establish no regression. |
…lent to the hole, not stronger Neither proved nor refuted, and reduced in two independent directions that make its truth unnecessary. The uninhabitedness premise is provably free at one binder — the statement with it deleted is equivalent at every ordered environment — so any proof must come from the contexts and the derivation alone. And the context guard can be kept at no cost, giving a route at cone 3415 with zero holes and zero watched names whose residual is *equivalent* to the hole, where yesterday's route was strictly stronger than what it proves. The move earlier rounds missed: do not reduce to one binder, hand the residual the whole remaining lift at the first uninhabited peel, and the guard never crosses an uninhabited binder. It also ordered holes #1 and #2, with the borrow smaller than #2 itself, and a like-for-like comparison that favours the new route on both axes: 3674 against 3698 constants and four by-policy names against six, from a strictly weaker starting residual. The finding that corrects my brief: there are six statements in this family, the four on the abstract side keep both context guards and are equivalences with their targets, and only the two on the verification side gave a guard away — so the statement I handed over as "the reduced target" was the lossiest member of its own family. Three of its priors were wrong in direction, the most in this series, and it says the result came from the two that surprised it rather than from its bet. The price is stated rather than buried: nothing is discharged, and the repair costs known non-vacuity, since the tree's only uninhabited-binder witness has an ill-formed context — so the new residuals are vacuous exactly if the hole is already closed. Its checklist correction is adopted: in a corner with sibling statements, build the family table by hypothesis shape *first*. Extremes are for a single statement; a family table prices every route before you pick one, and all three of this round's results came from one such grep after a third of the round went to extremes. Two of its three instrument claims I adjudicated rather than adopting. That a bare build does not re-run the guards is refuted — it emitted all three lines; the true and sharper point is that guard 2 audits one cone, so a leaf's hole is invisible to it by design, which is why the census exists beside it. That the fixed-root census script cannot see orphan modules is confirmed, and I have been using the whole-population variant throughout, so the figures I have reported stand. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Three defects in
Environment.checkPrimitiveDef(Lean4Lean/Primitive.lean).Each lets a declaration pass the check without the property the abstract model
then assumes of it, so
checkPrimitiveDef.WF— the statement that the recognizerestablishes
VEnv.HasPrimitives— was false as written in three independentways.
This check is lean4lean-only (see
divergences.md): Lean itself does not verifythat primitives are declared with the right types and definitional behaviour,
because it ships its prelude and an alternative prelude is unsupported. lean4lean
does verify it, and needs to for soundness.
1.
Char.ofNat/String.ofListrecognized up to defeqVEnv.HasPrimitivespins these constants'VConstantto a literal syntactictype, and
TrConstantreadsv.typeoff structurally viaTrExprS. But therecognizer only checked
isDefEq v.type q(Nat → Char).Declaring
Char.ofNatat(fun _ : Nat => Nat → Char) Nat.zeropasses thatcheck and translates to a structurally different
VConstant, refutingPrimitiveResult.preserves— which quantifies over everyci'withTrDefVal, so no proof can dodge it.Fixed by comparing with
Expr.eqv. That is the right notion here: the toolchaindeclares both at exactly the expected shape up to binder name, and
TrExprSignores precisely binder names and binder info.
2. The
Natequations were checked on ill-typed termsdefeq1/defeq2compared∀ _ : Nat, e₁against∀ _ : Nat, e₂— adeliberately ill-typed pseudo-type, used to get under a binder.
Nat.add x 0isnot a type, so
TrExprS.forallE's hypothesis is unsatisfiable, no witnessexists, and every one of those checks carried no semantic content: the
isDefEqspecification's hypothesis could never be discharged.Nat.landandNat.loradditionally bound theirBoolvariable at typeNat,which is not merely untranslatable but plainly ill-typed.
Fixed by checking under
withLocalDecl-bound free variables, as theNat.divand
Nat.modbranches already did. Same decision procedure —isDefEqon anarrow reduces via
isDefEqForall, which introduces exactly such a variable.3. Branches depended on constants they never required
Every arithmetic branch built
Nat/Boolliterals, and depended on otherprimitives' semantics, without requiring any of them in the environment. Each was
implied by a later
checkType— but only recoverable by inverting "typechecking succeeded", and the
TrExprSwitnesses theisDefEqspecificationdemands cannot be built before that inversion is available.
Now explicit
env.containsguards.Testing
The recognizer is strictly stricter than before, so this needed regression
testing rather than just a build:
lean4lean-local: 185 correct / 6 either / 0 incorrect —identical to the baseline.
lake build lean4leanandlake build Lean4Lean.Testsgreen, including therun_metaself-test that runscheckPrimitiveDefover all 24 entries ofEnvironment.primitivesin the live environment.Guard.leanchecks still pass; no newaxiom/sorry/partial/extern/implemented_by.divergences.mdis updated to describe the added strictness.Not fixed here
A fourth defect remains, filed separately:
checkPrimitiveDefruns beforecheckConstantVal, so it callsisDefEqon untyped input and records the resultin the
EquivManager, whose well-formedness invariant demands translationwitnesses that untyped input does not have. That one is a broken postcondition
rather than a soundness hole — both lean4lean and Lean's own kernel reject the
witness declaration with
unknown constant.🤖 Generated with Claude Code