Repository navigation
Two axioms that proved False - #16
vasnesterov wants to merge 3 commits into
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]>
The model `mkIMaxCore` carried an extra `|| u matches .succ .zero`
disjunct in its third branch. Upstream `Lean.Level.mkLevelIMaxCore` has
no such disjunct, in either the pinned v4.33.0-rc2 or master -- its third
branch is just `else if u.isZero then v`.
Because `mkLevelIMaxCore` is a plain `private def` rather than an
`opaque`, the equation is decidable, so the axiom did not merely
misdescribe the implementation: it proved `False`.
theorem contradiction : False
-- 'contradiction' depends on axioms: [propext, Quot.sound, mkLevelIMaxCore_eq]
Removing the disjunct makes the model a verbatim copy, so the equation
holds by `rfl` and the axiom is not needed at all. The two binders
`(e : Expr) (n : Nat)` were spurious -- the statement never mentioned
them -- and are dropped.
The axiom had no users anywhere in the Lean4Lean cone, so nothing else
changes. `lake build Lean4Lean.Verify` is green.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Discharges the three proofs that consumed the now-conditional `looseBVarRange_eq`. Threading its `BVarBounded` side condition through was not an option: `BVarBounded` is not preserved by the checker. Substitution preserves it (substituends are closed, so `liftLooseBVars` is the identity and `instantiate1'` only lowers indices), but `Expr.abstract` does not -- `mkLambda`/`mkForall` in `inferLambda.loop` replace an fvar by `.bvar k` at the current local-context depth, which is bounded only by the binder nesting of the term being inferred, and beta reduction grows that without bound. So the three sites simply stop trusting the cached bit: * `cheapBetaReduce.cont` returns `mkAppRange (fn.instantiateRevRange 0 i args) i args.size args` rather than dropping the consumed arguments -- a beta reduction whichever way the cached bit falls, so `BetaReduce.cheapBetaReduce` needs no side condition. When the bit is honest `instantiateRevRange` is the identity and the C wrapper returns immediately on cached range 0, so the fast path survives. * `isDefEqLambda`/`isDefEqForall` always introduce the free variable rather than pushing `default`. When the bit is honest neither body looks at the pushed value, so the decision is identical. The WF proofs get shorter -- the whole `else` branch goes away. * `inferType'`'s `.bvar` case throws instead of `unreachable!`. In this monad `unreachable!` is `fun _ _ s => .ok (default, s)`, so if reached it would have *succeeded*, handing back a default expression as the term's inferred type. It now throws the same exception the function's own entry guard throws, which the C++ kernel also throws; the C++ kernel's `lean_unreachable()` here is UB in a release build. The obligation was provable before only via `looseBVarRange_eq`. Net: `Lean.Expr.looseBVarRange_eq` has zero users in the repo. Three new `divergences.md` entries. Kernel behavior is unchanged whenever the cached field is honest, which at run time is always: `lean_expr_mk_data` panics and aborts rather than build a term that overflows it. `lake exe lean4lean Init.Core` and `lake exe lean4lean --fresh Init.System.IO` (43609 declarations) both still pass. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
So this is already fixed in this repo? Close then |
|
Yes — confirmed: all seven fix commits are ancestors of These three (#16, #17, #18) were rebuilt on The branches stay on the fork, so if you ever want to send this upstream the verified work is there: #14 and #15 stay open — those carry content that is genuinely not on |
|
Already on |
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.Lean4Lean/Verify/Axioms.leanstates that Lean's@[extern]primitives agree with pure-Lean reference implementations. Two of those axioms are inconsistent — each provesFalseon its own.and hence, from either one:
Anything proved with these in scope is proved vacuously.
The defects
Expr.looseBVarRange_eqequatese.looseBVarRange(which reads the cached 20-bitDatafield) with the recursivelooseBVarRange'. The cached field saturates: an expression nested past2^20binders reports a smaller range than it has. The fix adds thee.BVarBoundedside condition the equation actually needs.mkLevelIMaxCore_eqwas an axiom asserting an equality that is provable — and provable false as stated. It becomes arfltheorem.Consequences for the checker
looseBVarRangewas load-bearing in two places that now stop trusting the cached bit:cheapBetaReduceusedinstantiateRevRangeguarded by the cached range; it now instantiates unconditionally over the correct range.isDefEqLambda/isDefEqForallskipped introducing a free variable when the cached range claimed the body was closed. They now always introduce. This is a behavioral divergence from the C++ kernel (recorded indivergences.md): the C++ kernel makes the same optimisation and is exposed to the same saturation.The
.bvarcase ofinferTypenow throws instead ofunreachable!, which the first two fixes make reachable.Verification
lake buildexit 0;lake build Lean4Lean.Experimental Lean4Lean.Testsexit 0.lake exe lean4lean Init.Coreexit 0 (1035 declarations).lake exe lean4lean --fresh Init.System.IOexit 0 (43609 declarations).Verify/Axioms.lean: 32 → 31.sorry-warning count unchanged at 108; no proof was silently sorried.Notes for review
docs/axiom-audit.md, which arrives in the companion audit PR in this repo. If that PR is not taken, these two links dangle and should be dropped.false-axiomsPR in exactly one file,Verify/TypeChecker/IsDefEq.lean, whichever lands second. Resolution is mechanical: take this PR's deletion of theelsebranch inisDefEqLambda.WF/isDefEqForall.WF, keep the other PR's additions in the surviving code.🤖 Generated with Claude Code