Skip to content

Conversation

@nomeata
Copy link
Collaborator

@nomeata nomeata commented Dec 4, 2025

This PR, still an experiment, changes how match equations are generated, to fix issues like #11342 (which would arise more frequently once we have #11105).

When proving a matcher equation, we may encounter casesOn that do not reduce right away (it is not applied to a constructor), and that we thus want to split. But splitting can be blocked when the scrutine is not a free variable, which can be the case when this target is also the index of a later target, see #11342.

A more robust approach at equation generation to to prove it in the form of the “congruence equation” from #8284, where the arguments to the matcher are free variables, and the information that these arguments are actually equal to the current pattern is put into hypotheses. In this form, we should reliably be able to split the match into all its branches, avoiding the issue above. At each branch there are three possibilities:

  • We are in the right branch. We may need to substitute some variable and apply injection to the assumed assumption to unify the goal, and then are done. This can be handled by a (restrictively configured) call to grind, now that grind handles heterogeneous equality between constructors better (feat: heterogeneous contructor injectivity in grind #11491).

  • We are in a wrong branch and the patterns do not unify. Then we should have a (possibly heterogeneous) equality between different constructors somewhere in the context, and grind can handle it.

  • We are in a wrong branch and it’s overlapping the one we care about. Then there should be a no-overlap assumption in the context, and we need to use that. The code for that exists in contradiction (but maybe we can make that even more targetted?)

This is a more expensive approach than the current one, which can avoid many case splits. We'll see how bad it is, and whether we can tweak this to be faster, or whether we need both algorithms and this one is the fallback, or whether the common case is rfl anyways, so either refl or this one suffices.

@nomeata nomeata added the changelog-language Language features and metaprograms label Dec 4, 2025
@nomeata
Copy link
Collaborator Author

nomeata commented Dec 5, 2025

Just a note to future myself:

The next issue is that during proveCondEqThm we want the overlap assumptions to be applied to the abstract discrs, but the final theorem needs them applied to the concrete pattern and simpHlified, to match the splitter and be convenient.

This requires a bit of refactoring, and in particular simpH needs to return an actual proof of equivalence between the two (possibly only since this week since #11474).

@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 Dec 8, 2025
@leanprover-bot
Copy link
Collaborator

leanprover-bot commented Dec 8, 2025

Reference manual CI status:

  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2025-12-05 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. (2025-12-08 22:07:13)
  • 💥 Reference manual branch lean-pr-testing-11512 build failed against this PR. (2025-12-09 10:59:35) View Log
  • 🟡 Reference manual branch lean-pr-testing-11512 build against this PR didn't complete normally. (2025-12-09 11:00:04) View Log

leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Dec 8, 2025
@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 Dec 8, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Dec 8, 2025
@leanprover-community-bot leanprover-community-bot added the builds-mathlib CI has verified that Mathlib builds against this PR label Dec 8, 2025
@leanprover-community-bot
Copy link
Collaborator

leanprover-community-bot commented Dec 8, 2025

Mathlib CI status (docs):

leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Dec 9, 2025
leanprover-bot added a commit to leanprover/reference-manual that referenced this pull request Dec 9, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Dec 9, 2025
@leanprover-bot leanprover-bot added the breaks-manual This is not necessarily a blocker for merging, but there needs to be a plan. label Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaks-manual This is not necessarily a blocker for merging, but there needs to be a plan. builds-mathlib CI has verified that Mathlib builds against this PR changelog-language Language features and metaprograms 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.

4 participants