Skip to content

fix: grind congruence-table invariant for lazy ite branches#13624

Merged
leodemoura merged 3 commits into
masterfrom
grind_eqc_inv_issue
May 3, 2026
Merged

fix: grind congruence-table invariant for lazy ite branches#13624
leodemoura merged 3 commits into
masterfrom
grind_eqc_inv_issue

Conversation

@leodemoura
Copy link
Copy Markdown
Member

@leodemoura leodemoura commented May 3, 2026

This PR fixes a grind congruence-table invariant violation that could panic
when an ite branch was internalized lazily (after the condition became True
or False) and that branch's equivalence class was later merged with another.

Internalize.lean has a special case for ite that internalizes only the
condition; the then/else branches are skipped and only internalized later
on demand by propagateIte. The on-demand path (applyCongrFun) called
internalize for the branch but never called registerParent to add the
parent ite to the branch's parent set in the e-graph. Subsequent merges of
the branch's equivalence class then skipped re-hashing the ite in the
congruence table, leaving an orphan entry whose congr chain no longer matched
the table's representative.

The fix adds the explicit registerParent e rhs that the standard
for arg in args loop in Internalize.lean would have made for an ordinary
application argument; we are simply mirroring that pattern lazily. The same
helper is reused by propagateDIte, but with parent registration disabled
(controlled by a new ite : Bool parameter): for dite the rhs propagated
upwards is a constructed reduction (built via mkApp from e's children,
possibly post-preprocess), not a structural argument of e, so registering
e as its parent would be incorrect. The lambda branches of a dite are
already eagerly internalized as parents of e by Internalize.lean, so this
case does not need the fix.

@leodemoura leodemoura added the changelog-tactics User facing tactics label May 3, 2026
@leodemoura leodemoura enabled auto-merge May 3, 2026 14:35
@leodemoura leodemoura added this pull request to the merge queue May 3, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 3, 2026
@github-actions github-actions Bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label May 3, 2026
@leanprover-bot
Copy link
Copy Markdown
Collaborator

leanprover-bot commented May 3, 2026

Reference manual CI status:

  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-05-03 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-manual, reference manual CI should run now. You can force reference manual CI using the force-manual-ci label. (2026-05-03 15:31:31)
  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase 1b23b051f369dfedddd5b255c7e9bedbf5953eff --onto 3fc99eef102549c743c6c63547983319bfae6f01. You can force reference manual CI using the force-manual-ci label. (2026-05-03 18:08:07)

@github-actions github-actions Bot added the mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN label May 3, 2026
@leodemoura leodemoura added this pull request to the merge queue May 3, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 3, 2026
@leodemoura leodemoura added this pull request to the merge queue May 3, 2026
This PR fixes a `grind` equivalence-class invariant violation that could
panic when an `ite`/`dite` branch was internalized lazily (after the
condition became `True` or `False`) and that branch's equivalence class
was later merged with another. `applyCongrFun` already passed the parent
to `internalize` (so satellite solvers see it) but never called
`registerParent`, so the lazily internalized branch had no record of the
`ite` as one of its parents. Subsequent merges then skipped re-hashing
the `ite` in the congruence table, leaving an orphaned entry whose
`congr` chain no longer matched the table's representative.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@mathlib-lean-pr-testing mathlib-lean-pr-testing Bot added the builds-mathlib CI has verified that Mathlib builds against this PR label May 3, 2026
@mathlib-lean-pr-testing
Copy link
Copy Markdown

mathlib-lean-pr-testing Bot commented May 3, 2026

Mathlib CI status (docs):

  • ✅ Mathlib branch lean-pr-testing-13624 has successfully built against this PR. (2026-05-03 16:27:19) View Log
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 1b23b051f369dfedddd5b255c7e9bedbf5953eff --onto fe3c7394fd3acb1faecf6fc26f267eb22058fe66. You can force Mathlib CI using the force-mathlib-ci label. (2026-05-03 18:08:06)

@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 3, 2026
@leodemoura leodemoura force-pushed the grind_eqc_inv_issue branch from 6d06f1d to 2370329 Compare May 3, 2026 16:43
@leodemoura leodemoura enabled auto-merge May 3, 2026 16:44
@leodemoura leodemoura added this pull request to the merge queue May 3, 2026
@leodemoura leodemoura removed this pull request from the merge queue due to a manual request May 3, 2026
@leodemoura leodemoura enabled auto-merge May 3, 2026 17:17
@leodemoura leodemoura added this pull request to the merge queue May 3, 2026
Merged via the queue into master with commit 316c39f May 3, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

builds-mathlib CI has verified that Mathlib builds against this PR changelog-tactics User facing tactics mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants