Repository navigation
Five axioms that described functions that don't run - #17
Closed
vasnesterov wants to merge 6 commits into
Closed
vasnesterov wants to merge 6 commits into
vasnesterov wants to merge 6 commits into
Conversation
Both Level.mkData_eq and Expr.mkData_eq equate a model with a function that, out of range, calls lean_internal_panic and aborts rather than returning anything. Level.mkData_eq is additionally *jointly inconsistent* with hasParam_eq and hasMVar_eq: a level of depth at least 2^24 gets data = 0, so hasParam reads false while hasParam' is true. Both now carry the range hypothesis, with the value arguments made implicit so call sites read `rw [mkData_eq H]` rather than threading four placeholders. Five of the six users already carried exactly that hypothesis and needed a one-token change. The sixth, mkData_flags_of_false, is the single place that used the panic branch as a *fact*; with the hypothesis present it and its four corollaries become literally their unconditional counterparts, so they are deleted rather than duplicated, with a comment recording what they were and why. The build is red at exactly four goals, all the same goal, and all of them the hereditary bvar bound from the looseBVarRange_eq fix. The blast radius was measured by stubbing those four and rebuilding: all 1197 jobs complete, so nothing else is disturbed. This change cannot land on its own. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> (cherry picked from commit cfdadf1)
…tion Both equate a Lean model with `Lean.Expr.instantiateRange` / `instantiateRevRange`, which are `@[extern]` wrappers over `kernel/instantiate.cpp`. Out of range the C function does not return a different value -- it prints INTERNAL PANIC and aborts the process. The axioms assert an equation there anyway. Both now carry `start ≤ stop` and `stop ≤ subst.size`. No proof changes were needed. Both are `@[simp]`, and simp's own discharger closes the two bounds at every call site, so Verify/TypeChecker/WHNF.lean and Verify/TypeChecker/InferType.lean are untouched. That the rewrites still fire, rather than silently failing while the proofs succeed by another route, was confirmed with `#print axioms`: both names remain in the axiom cone of whnfCore'.WF and inferApp.loop.WF. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> (cherry picked from commit 94e9197)
…l sequential Lean.Expr.instantiate is a simultaneous substitution; the model instantiateList applies its entries one after another. They differ whenever a substituend contains a loose bvar: instantiate (.bvar 0) #[.bvar 0, .sort .zero] is .bvar 0, the model gives .sort .zero. The axiom now requires every substituend to be closed, which is the condition under which the two agree. Expr.instantiateRev_push was relying on the false form -- as stated, with no hypotheses, it is itself false. Two type-checker lemmas needed genuinely new hypotheses rather than local derivations: inferApp.loop.WF and both isDefEqLambda.WF/isDefEqForall.WF. Note isDefEqLambda pushes `default` into the substitution, which is a closed constant, so the obligation is dischargeable there only by that accident. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> (cherry picked from commit 394af31)
The C abstract does not shift loose bvars, so abstracting under a binder captures; and it resolves duplicate free variables last-wins where the model takes the first. The axiom now requires a closed body and a duplicate-free variable list. Its one direct caller was relying on the false form, and heavily. LocalContext.mkBinding_eq was stated with no hypotheses at all, for an arbitrary local context, body and variable list -- so it asserted exactly what the counterexamples refute. It now carries the closed body, the nodup list, and a new third condition: every declaration type and let-value reachable from the context is loose-bvar-free. mkBinding abstracts those too, which the old statement silently assumed. TrLCtx.closed_of_find? supplies that condition from local-context well-formedness alone, with no environment well-formedness needed, so the new hypothesis is discharged where it arises rather than propagating. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> (cherry picked from commit aa7cd05)
…hypothesis A malformed persistent array silently drops 32 elements, so the axiom is false as stated. It now takes WF arr, and is renamed to PersistentArray.WF.toList'_push to match the rest of that namespace. Two callers were relying on the false form: mkLocalDecl_toList and mkLetDecl_toList were @[simp] lemmas over an arbitrary LocalContext, hence false for the same reason. They now take the well-formedness of the declaration array and are no longer simp lemmas; both use sites supply it. Note this changes an axiom's fully qualified name, so Guard.lean's whitelist needs the new one. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> (cherry picked from commit e092850)
…still supports The corrected `mkData_eq` carries the `d < 2^24` / `br ≤ 2^20 - 1` bounds under which the C `lean_expr_mk_data` actually returns rather than aborts. That leaves the `bvar` case of the four `Expr.hasX_eq` lemmas unprovable: `Expr.bvar i` calls `mkData` with `looseBVarRange := i + 1`, which is unbounded, so nothing is known about the resulting word. The fix is not to add a bound but to weaken the statements, because only one direction was ever used. `hasFVar_eq_false : e.hasFVar = false → e.hasFVar' = false` and its three siblings are provable with no bound at all: the one node whose `mkData` call can leave the range is `bvar`, and `hasFVar' (.bvar _) = false` whatever an out-of-range `mkData` returns, while every other node combines its children's cached bits with `||` under a bound that `Expr.Data.looseBVarRange_le` supplies unconditionally. The four biconditional `hasX_eq` lemmas are dropped; they had no users. Consumers follow the same pattern: * `instantiateLevelParamsCore_eq` now splits on the cached `hasLevelParam` bit -- which is what `replaceFn` actually tests -- and converts with `hasLevelParam_eq_false`, so the proof needs no bound. * `fvarsIn_iff_hasMVar` and `fvarsList_eq_nil` split into structural iffs (`fvarsIn_iff_hasMVar'`, `fvarsList_eq_nil'`) plus one-directional wrappers taking the cached bit, which is the form both call sites want. Proofs only: no file outside `Lean4Lean/Verify/` changes, so the checker's behavior is untouched. `lake build` is green, with the same 23 `sorry` warnings as the base commit. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Owner
Author
|
Already on |
vasnesterov
pushed a commit
that referenced
this pull request
Aug 23, 2026
…d a guard class the audit missed **The systemic finding: a guard class §6/§7.1 did not account for.** Every `@[extern]` C entry point in scope that takes a `Nat` begins with a **`lean_is_scalar` bignum test -- before** the range test the audit records. `LEAN_MAX_SMALL_NAT = SIZE_MAX >> 1`, so it fires at `2^63`. §6 describes `lean_expr_instantiate_range` as "starts with `if (b > e || e > sz) lean_internal_panic`" -- that is the function's **second** statement, not its first. **Seven axioms in scope sit on that guard**, and it resolves four different ways. ## #21 `Lean.Expr.liftLooseBVars_eq` is FALSE if (!lean_is_scalar(s) || !lean_is_scalar(d)) { lean_inc(e); return e; } Witness `e := .bvar 0`, `s := 0`, `d := 2^63`. Both halves machine-checked, deliberately **by different instruments**: - C side, differential test on compiled code: `#eval idx ((Expr.bvar 0).liftLooseBVars 0 (2^63))` prints `"bvar 0"`. - Model side, kernel reduction: `liftLooseBVars' (.bvar 0) 0 (2^63) = .bvar (2^63)`, and `≠ .bvar 0`. So the axiom asserts `.bvar 0 = .bvar (2^63)`. Worse than #26/digama0#27 in one specific way: **the call completes.** No panic, no exotic input -- `2^63` is an ordinary literal and `.bvar 0` an ordinary `Expr`. Only the *model's* output is not runtime-constructible, which is why the two sides cannot be evaluated in one expression (`#eval` of the model's answer trips `lean_expr_mk_data`'s own panic -- observed). **Not an inconsistency**: `liftLooseBVars` is `opaque @[extern]` and the toolchain has no core theorem about it, so there is no second fact to contradict. Same category as #12/#17. Fix is `d < 2^63` or a `USize` restatement -- frozen file, needs sign-off. ## Three failed attacks, recorded as failed attacks - **#22, digama0#30** carry the same guard and **survive**: the C fallback coincides with the model on every input a real `Expr` can supply, with machine-checked agreement lemmas for both. One of the stream's own witnesses was wrong -- `(.bvar 7).lowerLooseBVars (2^63) 1` returns `bvar 7` from *both* sides -- and the correction is recorded rather than quietly dropped. - **digama0#29 `abstractRange_eq`**, the only unconditional range axiom, also survives: its fallback uses `lean_array_size` and `Array.extract 0 n` clamps to the same thing, agreeing at **every** input, logical or not. Verdict unchanged, for a reason §7.1 did not state. ## #26/digama0#27: the side condition is necessary but NOT sufficient `start ≤ stop ≤ subst.size` excludes the second guard, not the first -- `stop` may be non-scalar provided `subst.size` is too, which needs `subst.size ≥ 2^63`: expressible, not constructible. Strictly weaker than #21, no differential test possible. **Source reading only, and marked as such.** ## The two other priority targets, answered - **#17 `Expr.mkData_eq` -- no analogous consequence.** `lean_expr_mk_data` panics twice, and its hypothesis implies **both** are passed; the `approxDepth` clamp matches too. Unlike #12, correctly guarded. - **#3 `PersistentArray.toList'_push` -- hypothesis adequate**, in the strongest available sense: `WF` is generated by `empty`/`push` only, and a reverse scan shows lean4lean uses **no other `PersistentArray` operation**. So `WF` is exactly the reachable set, not an approximation. Not reached: #4-#7. **digama0#31's dependency on #15 deliberately not pursued** -- #15 belongs to another stream's section, and a cross-section attack run from one side only is the weaker version of the test. **No `False` was derived.** §11.9 keeps the evidence strengths separate: differential-test-plus-source, source-only, and proof are three different things, and none of this is a proof. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
vasnesterov
pushed a commit
that referenced
this pull request
Aug 23, 2026
…ide condition Neither possibility in the brief was right; the answer is a third. **They are consistent** (the argued contradiction is dead), **they are not provable** (their docstrings' claim is false), **and they become provable under a side condition.** New `Lean4Lean/Tests/AxiomConsistency.lean` (nothing imports it). It works by **model exhibition** against `dataOf f` -- `Lean/Level.lean`'s computed field with the opaque `mkData` replaced by `f` -- and checks clause-by-clause by `rfl` that `dataOf mkData` is the real `Level.data`. - **§1** a clamping model (`min d (2^24-1)` instead of panic) validates **all three** of #12/#13/#14 by induction on `Level`. So they are **jointly consistent**, and §4's argument needed the *unconditional* `mkData_eq`: it dies with the `H : d < 2^24` repair. - **§2** a zeroing model validates #12 but **refutes** #13/#14 on `succ^[2^24] (.param x)`. So **#13/#14 are independent of #12** -- nothing constrains `mkData` at `d ≥ 2^24`, and they cannot be proved "using `mkData_eq` and friends" as their docstrings claim. - **§3** `hasParam_eq_of_dep`, `hasMVar_eq_of_dep`, `depth_eq_of_dep`, each under `(h : dep l < 2^24)` -- proved **without** #13/#14. The hypothesis is verified load-bearing (§2 *is* the proof it must be) and satisfiable, and the qualified name was checked to be `Lean.Level.mkData_eq` rather than the `Expr` one. **Joint-consistency survey (§12).** Mechanical: which free symbol each axiom pins. The relation is a **DAG** -- verified no `X_eq : X = Total.X` has `Total.X` reaching `X`. That splits the set: - **Class (A), 23 axioms** -- each pins a free symbol to a total definable function. **Jointly consistent by topological interpretation.** - **Class (B), 6 axioms** -- constrain a free symbol *through* a definable observation with provable properties. **Both historical `False`-proofs were in class (B)**, which is where attack effort belongs. **Seven failed attacks recorded in §12.3, each with the step it fails at**: #15+digama0#31 and digama0#30+digama0#31 (no shared constant -- independent opaques); mutual definability of the ten substitution/abstraction primitives (all independent opaques, the equivalences are **docstrings only**); #18 at the `BVarBounded` boundary; off-by-one at both panic boundaries; #17's unconditional form. **The strongest single result:** an environment sweep over every constant whose type mentions any of the 27 pinned opaques (private manglings resolved, not grepped) returns 21 whitelisted axioms plus exactly four auto-generated inert lemmas. **No theorem anywhere asserts a behavioural property of any pinned opaque** -- so contradictions can only arise *between* whitelisted axioms. Unverified, stated as such: the `PersistentArray`/`PersistentHashMap` three are the **highest residual risk** -- class (B), same shape as the two that proved `False`; `WF` blocks the known counterexamples and no new attack succeeded, but no model exists and building one means proving the real HAMT algorithms correct. And the `Expr` analogue of §1 is hand-analysed, not mechanised. Also noted: removing the two `TreeMap` axioms eliminated the only two with **zero model freedom**. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
vasnesterov
pushed a commit
that referenced
this pull request
Aug 23, 2026
…t endpoints Both gates failed. `Theory/Typing/PropShadow.lean`, new, sorry-free, `[propext, Classical.choice, Quot.sound]`. **Item 1 -- the Prop-shadow closes arithmetically and the case does not.** `app_shadow_arith`: from the IH at `f` in shadow form, the two codomain universes agree on propositionhood -- consuming **no `DefInv` clause, no `SubstC`, and nothing about the argument**. So the literal question answers **no**. But `app_shadow_of` prices the rest: the case is about universes *after* instantiation, and closing that gap needs two further statements, neither of them `SubstC`: - **`InstLvl`** -- `SubstT` at **depth 0** with a closed target type. **Not refuted, not proved**: `SubstTRefute`'s witness is at depth 1, and `SubstCRefute`'s witness **satisfies** it (checked). - **`PropUniq` at a subject that is not a subterm** of the application, so the running induction cannot supply it. **And a cost §8 did not price: the other cases stop being free.** In the full statement every non-`app` case closes by `trans` on the shape-determined type; in the shadow, inversion delivers a *conversion* and a universe must be carried across it (`LvlConvInv`, at an arbitrary type). **Trap #10 in a third direction: weakening a conclusion also weakens what every `trans`/`conv` step can transport, so a weakening is not a weakening uniformly across an induction.** **Item 2 -- the route's row zero is FALSE, machine-checked.** The "regularity" statement `thesis-architecture.md` §8 proposed **as the repair** -- that a `⊢ₙ₊₁` conversion's endpoints are each `⊢ₙ`-typeable -- is refuted at `n+1 = 1` over `VEnv.empty` by `sortDF` on the domains and `symm (beta …)` on the bodies, closed by `lamDF`. The right endpoint has **no `⊢₀` type at all**. Four checks make it decisive rather than an artifact: it uses **none of this tree's `rfl` deviation** (rules verified line by line against `axioms.tex:30-41`); the **left** endpoint *is* `⊢₀`-typeable, so it is not a well-formedness accident; **both** endpoints are `⊢₁`-typeable, so what fails is exactly the index **drop**; and it **survives at the level of types** -- swap `lamDF` for `forallEDF` and the right Π-type has a `⊢₁` universe and no `⊢₀` one, which is what `lvl` is defined on. The context is `[]`, so it also survives the `⟦Γ⟧ ≠ ∅` side condition. **The defect named:** §5 conflates a **rule's premises** with a **conversion's endpoints**. The premise-free rules (`sortDF`, `lamDF`, `forallEDF`) build conversions mentioning terms **no premise ever typed**. Trap #17. **Consequence: the stage-`n+1` obligations have no admissible order.** (4)-before-(2) needs the stage-`n` model on a `⊢ₙ₊₁` conversion's endpoints -- refuted. (2)-before-(4) is the branch blocked by `SubstC`. And the obvious rescue -- restricting (4) to conversions with `⊢ₙ`-typed endpoints -- **loses exactly the case the route existed for**: a genuine `⊢₁` derivation whose endpoints have `⊢₀` universes and whose `trans` node's middle term has none, so the restricted statement does not compose at `trans` -- and `trans` is the route's stated "real leverage". **Not established, not claimed:** that part (4) is *false*; that item 1 fails for `n ≥ 1`; that `InstLvl` is false. **`PropTypeAgree` and `SortForallEDisjoint` are untouched** -- handoff §5 and §9 stand unchanged. §4's observation survives and is worth keeping: **a model does give sort injectivity without confluence, at any index where it can be built** -- but nothing builds it above `n = 0`. 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.
Staged against
upstream-base(a copy ofdigama0/master), not against ourmaster— these fixes are already onmaster. This is the same work rebuilt on the upstream base so it is reviewable here and ready if you ever choose to send it on. Nothing has been submitted anywhere.Companion to the inconsistent-axioms PR. Those two axioms proved
Falseoutright; these five are false but not inconsistent — the upstream side isopaqueorpartial, so no Lean-internal contradiction follows, but each axiom describes a function that is not the one that runs.The defects
Expr.mkData_eq,Level.mkData_eq0) at inputs where the C function callslean_internal_panicand aborts the processExpr.instantiateRange_eq,instantiateRevRange_eqExpr.instantiate_eqinstantiateis simultaneous; the model substitutes sequentially. They differ whenever a substituted term contains a loose bvarExpr.abstract_eqPersistentArray.toList'_pushWF arrhypothesis; on a malformed array the realpushsilently drops 32 elementsEach fix adds the side condition the equation actually needs, or corrects the model to the function that runs. All five remain axioms — the upstream implementations are
@[extern], so they stay unprovable.The cached-bit lemmas
Bounding
mkData_eqmakes thebvarcase ofExpr.hasFVar_eq,hasExprMVar_eq,hasLevelMVar_eqandhasLevelParam_equnprovable: the cached bit may be set spuriously on a.bvarbuilt through the panicking path.Only the
= falsedirection of those four is ever used, so this PR drops the four biconditionals and keeps unconditionalhasX_eq_falsecompanions, adapting the three consumers (instantiateLevelParamsCore_eq,fvarsIn_iff_hasMVar/fvarsList_eq_nil, and theVerify/Environment/Checker.leancall sites). Keeping the biconditionals would require aBVarBoundedhypothesis, which lives in the inconsistent-axioms PR — this way the two PRs stay independent.Verification
lake buildexit 0;lake build Lean4Lean.Experimental Lean4Lean.Testsexit 0.lake exe lean4lean Init.Coreexit 0.Lean4Lean/Verify/, so checker behavior is unchanged by construction.sorry-warning count unchanged at 108.Note for review
Conflicts with the inconsistent-axioms PR in exactly one file,
Verify/TypeChecker/IsDefEq.lean, whichever lands second — mechanical, see that PR's description. Independent of it otherwise; either can land first.🤖 Generated with Claude Code