Repository navigation
fix: looseBVarRange_eq proves False on its own - #5
Merged
Merged
Conversation
Expr.looseBVarRange is a 20-bit field read, so `< 2^20` is provable with no axiom at all, while looseBVarRange' is unbounded. At `Expr.bvar 1048575` the model gives 2^20 and the field gives 0, so the axiom proves False on its own -- it needs neither mkData_eq nor the repo's bv_decide-backed looseBVarRange_le. Adds Expr.BVarBounded, a hereditary per-subterm bound, as the side condition. Hereditary because a binder's model range is a max involving its children, so a top-level bound does not constrain them. Also proves BVarBounded.looseBVarRange'_le, which is the machine-checked evidence that the condition actually blocks the refutation rather than merely looking plausible: under it the model range obeys the same bound the packed field does, so the two sides are no longer forced apart. The build is red, deliberately: four declarations acquire the new obligation and discharging them is not plumbing. The full list was established by stubbing each site and rebuilding until all 1197 jobs completed, so nothing else in the tree depended on the unconditional form. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This was referenced Aug 22, 2026
vasnesterov
pushed a commit
that referenced
this pull request
Aug 23, 2026
…er, not the worker **The criterion answered a different question than expected.** Asked which side condition the consumers satisfy for free, an axiom-cone scan (`Lean.collectAxioms`) over every non-internal `Lean4Lean.*` declaration returned: | axiom | dependents | |---|---| | **`Lean.Expr.liftLooseBVars_eq`** | **0** | | the other 13 in scope | 35 - 162 each | Zero for a structural reason, not by luck: **the checker never calls `Expr.liftLooseBVars`.** No occurrence outside `Verify/` and `Experimental/`, and the only textual matches inside `Verify/` are theorems about the *model* `liftLooseBVars'`, none about the opaque constant. The axiom is `@[simp]`, so it has no explicit call sites either way -- and the cone scan is exactly what settles that, since a `@[simp]` lemma that fires does appear in the proof term. **So the fix is subtraction, not domestication:** deleting it cannot break a proof, and it removes a live false axiom. Fallback if a reviewer prefers to keep the statement: the C guard is `!lean_is_scalar(s) || !lean_is_scalar(d)`, so **both** arguments need bounding -- `s < 2^63 ∧ d < 2^63`, not `d < 2^63` alone. A `USize` restatement does not fit without changing the signature. **The guard class, stated as method in §11.1.** §7.1's entries describe the *worker* functions faithfully; what they skip is the `extern "C"` wrapper, which is where argument validation lives. > For any `@[extern]` axiom, read the wrapper first and enumerate every > early return before reading the algorithm. A `Nat` crossing into C is boxed, hence always bignum-guarded, and the guard either panics or silently substitutes a fallback the axiom must then match. **Seven of fourteen axioms in scope sit on one.** **Four more failed attacks (#4-#7), recorded with their failure step.** - **#6 `findAux_isSome` survives** -- both sides use the *same* `==` and the functions are parallel clause-for-clause; the shared panic-index agrees whatever `default : Entry` is. - **#4/#5 survive a non-reflexive `BEq`.** `PartialEquivBEq` requires symmetry and transitivity but **not** reflexivity, so `⟨fun _ _ => false⟩` is legal and `LawfulHashable` is vacuous -- a key can be inserted twice and the filter deletes nothing. Both axioms still hold. Hand-executed, not machine-checked, and marked so. - **#7 `structEq_eq` survives, but §7.3's reason was wrong**, in a way worth keeping. It claims `Substring.Raw.Internal.beq` *is* the `BEq` instance. Not definitionally: `example : @Substring.Raw.Internal.beq = (· == ·) := rfl` **fails**. The identity holds *through the linker*, via an `@[extern]`/`@[export]` pairing -- weaker assurance, and the reason this axiom can never be discharged by unfolding. The attack it prompted (position-sensitivity like `Substring.Raw.sameAs`) fails under differential test, with both negative controls checked. Still declined: **digama0#31's dependency on #15**, since from one side it is the weaker test. Ready to pair with the `Level` stream. §11.9 keeps the three evidence strengths separate and now names the cone scan as the strongest instrument in the pass -- a complete search over the environment rather than a sample -- which is why #21's recommendation is *delete* rather than *weaken*. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
vasnesterov
pushed a commit
that referenced
this pull request
Aug 23, 2026
… a documentation artifact **`ORCHESTRATOR.md`** -- orchestrator-only instructions, separate from `CLAUDE.md` which is for every agent. Centrepiece: **prefer handoffs to resumes.** A resumed agent carries a long, mostly irrelevant transcript and drifts toward what it already believes; instead ask a stream at a boundary to write `docs/handoff-<topic>.md` and point a **fresh** agent at it. The handoff must carry what a newcomer cannot cheaply reconstruct -- in particular **what was tried and failed, and the step it failed at**, which is the half that gets lost and the most common waste to re-derive. Also records the git gate, explicit-path staging, one-file-one-stream with boundaries rather than arbitration, and ruling on measurements rather than reasons. **Audit §13.** No inconsistency found; one recorded justification corrected, one risk bounded. **digama0#31's "depends on 15" is a documentation artifact.** A constant-dependency scan over statement, value and the `brecOn` helper shows `Expr.eqv_eq`, `Expr.eqv'` and `eqv'._f` mention `instLawfulBEqLevel` **nowhere**. What digama0#31 actually rests on is different in kind and strictly weaker: that `BEq Level` is **the same function** C uses, not that it is **lawful** -- the instance *is* `Level.beq` definitionally, `Level.beq` is `@[extern "lean_level_eq"]`, and `expr_eq_fn.cpp` compares levels with that same symbol. **Why it is worth fixing:** if #15 were refuted -- if `lean_level_eq` normalised and so were not structural -- **digama0#31 would be unaffected**, because both sides of `eqv_eq` would use the same non-structural comparison and still agree. The annotation invites the inference *"refuting 15 propagates to 31"*, which is false. Same shape as §7.3: right verdict, wrong recorded reason. Bonus sweep: the `LawfulBEq Expr` route was re-run as an environment-wide instance scan over the **whole import closure** rather than core alone. The only such instance in scope is `instLawfulBEqLevel`, and it is for `Level`. Route closed over the closure. **Container axioms: `WF` is the reachable set for #4/#5 too**, by a longer chain. Only 7 distinct `PersistentHashMap`/`PersistentArray` constants are referenced by any `Lean4Lean.*` declaration, and `insert`/`find?` are not among them -- they arrive through `ConstMap = SMap Name ConstantInfo`. `SMap.map₂` **defaults to empty**; `fromHashMap` sets only `map₁` and the stage; `SMap.insert` is **the only writer of `map₂`**; the single construction site is at stage 2, so every later insert lands in `map₂` starting from `∅`. Hence every reachable `PersistentHashMap` is `empty` followed by `insert`s -- exactly `WF`'s two generators. `erase`, `modify`, `insertIfNew`, `ofList` are unreachable. **What that buys, stated narrowly:** it rules out the failure mode that actually produced a `False` here -- an axiom stated for arbitrary, including malformed, structures -- since a hypothesis that is exactly the reachable set cannot be applied outside its domain. It does **not** make the axioms true *on* that domain: no model of the HAMT or the trie exists, so an error in the algorithms themselves survives untouched. **Class (B) risk is bounded, not removed**, and §13.5's evidence table ends with the row `#4/#5 are true -- none, still no model`, which is the point of the table. Three more failed attacks recorded in §13.4. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
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.
Draft: the build is red on purpose. The correction is right; discharging it
is not plumbing, and the reason why is the most interesting thing here.
The bug
Expr.looseBVarRangeis a 20-bit field read ((data >>> 44).toUInt32), so< 2^20is provable with no axiom at all.looseBVarRange'is unbounded:(Expr.bvar 1048575).looseBVarRange' = 2^20. So the axiom provesFalseonits own — it needs neither
mkData_eqnor the repo'sbv_decide-backedlooseBVarRange_le:C agrees the value is unrepresentable:
lean_expr_mk_datacallslean_internal_panic.Guard 2 whitelists this axiom by name, so it sits in
kernel_sound's trustedcone — an inconsistent base makes the theorem provable vacuously while the guard
reports success. Latent today only because
Verify/Soundness.leanimportsnothing from the refinement layer.
The fix
Expr.BVarBounded, a hereditary per-subterm bound. Hereditary is necessary,not cautious:
looseBVarRange' (.lam _ t b) = max t.lBR (b.lBR - 1), so a boundon the parent does not bound
b.Plus
BVarBounded.looseBVarRange'_le, proved and axiom-free — themachine-checked evidence that the condition actually blocks the refutation
rather than merely looking plausible: under it the model range obeys the same
bound the packed field does, so the two sides are no longer forced apart.
Not the tempting repair of replacing the RHS with
if e.looseBVarRange' ≤ 2^20-1 then … else 0. That reifies Lean'spanic! = defaultconvention, but the C function aborts — the correctedaxiom would then be a different false statement, claiming the checker keeps
running with range 0.
What breaks — exactly four declarations
BetaReduce.cheapBetaReduceVerify/Typing/Lemmas.lean:1973TypeChecker.Inner.isDefEqLambda.WFVerify/TypeChecker/IsDefEq.lean:9TypeChecker.Inner.isDefEqForall.WFVerify/TypeChecker/IsDefEq.lean:79TypeChecker.Inner.inferType'.WFVerify/TypeChecker/InferType.lean:413The list is exhaustive: established by stubbing each site and rebuilding until
all 1197 jobs completed, so nothing else in the tree depended on the
unconditional form. All stubs reverted;
git difftouches onlyAxioms.lean.Why this is not a small repair — and a finding about the checker
The cheap route (add the bound to
TrExprS/VLCtxwell-formedness) isprovably insufficient, because of
inferType'.WF.In its
.bvarbranch the only context ish : (Expr.bvar i).looseBVarRange = 0,from the checker's own
if e.hasLooseBVars then throwguard, and the goal isthat the following
panic! "unreachable code has been reached"is WF. The oldproof rewrote
htoi + 1 = 0. The corrected axiom gives onlyi + 1 ≤ 2^20 - 1, andinferType'.WF's hypotheses are—
hinfis conditional, so on theinferOnly = falsepath there is noTrExprS eat all. An invariant onTrExprScannot reach this goal.Read honestly, that is a statement about the checker, not a proof artifact:
inferType'applied toExpr.bvar 1048575passes thehasLooseBVarsguard —the packed field reads 0 — and falls into unreachable code. The real
executable can never build that term, because
lean_expr_mk_dataaborts first.Which is exactly why this has to be an assumption that is checked, not one
that is proved away. It is the same 20-bit field and the same
silent-degradation mechanism as the
hasLooseBVarsnon-conservativity bugalready in
bugs-found.md.cheapBetaReducecascades similarly: the obligation propagates to sites whereeis the inferred type returned by a recursive call, so discharging it meansproving the checker's own outputs are
BVarBounded.The honest fix touches
Lean4Lean/TypeChecker.leanplus the mutual WF recursionacross
Verify/TypeChecker/{Basic,InferType,IsDefEq,WHNF,Reduce}.lean—several hundred lines — and should probably thread an explicit check from
addDeclrather than an invariant.Caveats on the correction itself
@[simp]is now nearly inert. The side goale.BVarBoundedhas no simpequations, so simp will essentially never discharge it — which is partly why
only four sites broke. Whoever finishes this should add unfolding lemmas or
make
BVarBoundedan inductive.Prop-valued recursive def, so notdecide-able. A checkedprecondition needs a
Bool-valued version plus a soundness lemma; probablyworth defining that way from the start.
BVarBoundedis not too weak. The new lemmashows it bounds the model range; that a binder's own
mkDataargument isautomatically in range once its children are was verified only as arithmetic,
not against the real
mkDatachain..litis unconstrained. Fine today becauseTrExprSexpands it viatoConstructor, which is closed and bvar-free — a silent dependency.2^20 - 1, not2^20. Deliberate: it matches the C check andthe repo's existing
mkData_looseBVarRange.Note on the freeze
Verify/Axioms.leanis frozen perCLAUDE.md; this is a proposal for sign-off.Axiom names are unchanged, so guard 1's list still matches.
🤖 Generated with Claude Code