Skip to content

fix: recognizer branches depend on constants they never require (3/4) - #9

Merged
vasnesterov merged 1 commit into
masterfrom
fix/primitive-containment-guards
Aug 22, 2026
Merged

vasnesterov merged 1 commit into
masterfrom
fix/primitive-containment-guards

Conversation

@vasnesterov

Copy link
Copy Markdown
Owner

Split out of #2, as requested. 3 of 4. Independent of the siblings; applies
to pristine master.

The bug

Every arithmetic branch builds Nat and Bool literals, and depends on other
primitives' semantics, without requiring any of them to be in the
environment
:

  • Nat.sub, mul, pow, mod, div, gcd, shiftLeft, shiftRight,
    land, lor, xor build Nat.zero/Nat.succ without requiring Nat;
  • land/lor/xor build Bool literals without requiring Bool;
  • mod/div need Nat.ble's semantics (via Condition.natLE) but never
    require Nat.ble;
  • bitwise needs Nat.add/Nat.div/Nat.mod/Nat.beq but requires none of
    them;
  • the Nat.gcd path needs Bool inside unfoldNatWellFounded.

Each was implied by a later checkType in the same branch — but only
recoverable by inverting "type checking succeeded, therefore this constant is
present". And that inversion comes too late: the TrExprS witnesses the
isDefEq specification demands cannot be built without those containments,
so the obligations are needed before the inversion is available.

This is a different failure from the sibling PRs. Nothing unsound was accepted;
the postcondition was simply unprovable in the order the proof has to go.

The fix

Explicit env.contains guards, in the house style of the branches that already
had them.

They reject nothing new. Every guard is forced by a checkType or isDefEq
later in the same branch, so any declaration that previously passed still
passes — confirmed by the arena and by Verify/Soundness.lean's build-time
stdPrelude accepted by addDecl ✓ check. They exist so the postcondition can be
proved, not to change the decision.

Testing

lake build lean4lean green, including the run_meta self-test over all 24
entries of Environment.primitives.

On the arena: the combined change of all four splits was arena-verified at
185 correct / 6 either / 0 incorrect, the baseline. Each split is a subset of
that strictness, so none can reject anything the combined version accepted.

divergences.md is updated in #7, which carries the note for the whole series.

🤖 Generated with Claude Code

Every arithmetic branch built Nat and Bool literals, and depended on
other primitives' semantics, without requiring any of them present in the
environment. Each was implied by a later checkType, but only recoverable
by inverting "type checking succeeded" -- and the translation witnesses
the isDefEq specification demands cannot be built before that inversion
is available.

They are now explicit env.contains guards. The guards are provably
redundant as *checks*, so no previously accepted declaration is now
rejected; they exist so the postcondition can be proved.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
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