Skip to content

Two axioms that proved False - #16

Closed
vasnesterov wants to merge 3 commits into
upstream-basefrom
upstream-fix/inconsistent-axioms
Closed

vasnesterov wants to merge 3 commits into
upstream-basefrom
upstream-fix/inconsistent-axioms

Conversation

@vasnesterov

Copy link
Copy Markdown
Owner

Staged against upstream-base (a copy of digama0/master), not against our master — these fixes are already on master. 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.lean states that Lean's @[extern] primitives agree with pure-Lean reference implementations. Two of those axioms are inconsistent — each proves False on its own.

'contradiction_alone' depends on axioms: [propext, Quot.sound, Expr.looseBVarRange_eq]
'contradiction'       depends on axioms: [propext, Quot.sound, mkLevelIMaxCore_eq]

and hence, from either one:

theorem anything (P : Prop) : P := contradiction.elim

Anything proved with these in scope is proved vacuously.

The defects

Expr.looseBVarRange_eq equates e.looseBVarRange (which reads the cached 20-bit Data field) with the recursive looseBVarRange'. The cached field saturates: an expression nested past 2^20 binders reports a smaller range than it has. The fix adds the e.BVarBounded side condition the equation actually needs.

mkLevelIMaxCore_eq was an axiom asserting an equality that is provable — and provable false as stated. It becomes a rfl theorem.

Consequences for the checker

looseBVarRange was load-bearing in two places that now stop trusting the cached bit:

  • cheapBetaReduce used instantiateRevRange guarded by the cached range; it now instantiates unconditionally over the correct range.
  • isDefEqLambda / isDefEqForall skipped 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 in divergences.md): the C++ kernel makes the same optimisation and is exposed to the same saturation.

The .bvar case of inferType now throws instead of unreachable!, which the first two fixes make reachable.

Verification

  • lake build exit 0; lake build Lean4Lean.Experimental Lean4Lean.Tests exit 0.
  • lake exe lean4lean Init.Core exit 0 (1035 declarations).
  • lake exe lean4lean --fresh Init.System.IO exit 0 (43609 declarations).
  • Axiom count in Verify/Axioms.lean: 32 → 31. sorry-warning count unchanged at 108; no proof was silently sorried.

Notes for review

  • The third commit is a strict subset of a larger downstream change — only the two implementation sites and their proofs, ~75 lines. The rest of that change repairs fallout from a different axiom fix and belongs with #(false-axioms).
  • The two docstrings added here reference 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.
  • Conflicts with the companion false-axioms PR in exactly one file, Verify/TypeChecker/IsDefEq.lean, whichever lands second. Resolution is mechanical: take this PR's deletion of the else branch in isDefEqLambda.WF/isDefEqForall.WF, keep the other PR's additions in the surviving code.

🤖 Generated with Claude Code

vasnesterov and others added 3 commits August 23, 2026 04:47
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]>
@vasnesterov

Copy link
Copy Markdown
Owner Author

So this is already fixed in this repo? Close then

@vasnesterov

Copy link
Copy Markdown
Owner Author

Yes — confirmed: all seven fix commits are ancestors of master, and Verify/Axioms.lean on master is at 31 axioms rather than the original 32. Nothing here is new to this repo.

These three (#16, #17, #18) were rebuilt on upstream-base (a copy of digama0/master) only so the diffs would be reviewable against the upstream base. That was the wrong thing to open as PRs — closing all three.

The branches stay on the fork, so if you ever want to send this upstream the verified work is there: upstream-fix/inconsistent-axioms, upstream-fix/false-axioms, upstream-docs/axiom-audit, all based on upstream-base.

#14 and #15 stay open — those carry content that is genuinely not on master yet (the audit document, and the primitive-recognizer fix).

@vasnesterov

Copy link
Copy Markdown
Owner Author

Already on master — see #16. Branch kept.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant