Skip to content

Conversation

@nomeata
Copy link
Collaborator

@nomeata nomeata commented Dec 2, 2025

This PR generalizes the noConfusion constructions to heterogeneous equalities (assuming propositional equalities between the indices). This lays ground work for better support for applying injection to heterogeneous equalities in grind.

The Meta.mkNoConfusion app builder shields most of the code from these changes.

Since the per-constructor noConfusion principles are now more expressive, Meta.mkNoConfusion no longer uses the general one.

In Init.Prelude some proofs are more pedestrian because injection now needs a bit more machinery.

This is a breaking change for whoever uses the noConfusion principle manually and explicitly for a type with indices.

Fixes #11450.

@nomeata
Copy link
Collaborator Author

nomeata commented Dec 2, 2025

!radar

@leanprover-radar
Copy link

leanprover-radar commented Dec 2, 2025

Benchmark results for 19a08bb against 5bd331e are in! @nomeata

Minor changes (1)
  • size/all/.olean//bytes: -713kiB (-0.2%)

@nomeata nomeata marked this pull request as ready for review December 2, 2025 13:07
@nomeata nomeata added the changelog-language Language features and metaprograms label Dec 2, 2025
where `x1 x2 x3` and `x1' x2' x3'` are the fields of a constructor application of `ctorName`,
omitting equalities between propositions and using `HEq` where needed.
-/
def mkNoConfusionCtorArg (ctorName : Name) (P : Expr) : MetaM Expr := do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessarily related to this change, but this function is always used with beta directly after it, so why produce a lambda at all?

Copy link
Collaborator Author

@nomeata nomeata Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So just passing in concrete xs, fs1, fs2 and skipping the forallBoundedTelescope isn't a good idea, probably because of this commit:

  -- We bring the constructor's parameters into scope abstractly, this way
  -- we can check if we need to use HEq. (The concrete fields could allow Eq)

Of course I could move the .beta into mkNoConfusionCtorArg, but it’s a private function, so not worth the bother.

Maybe this was only strictly needed before the present change? Anyways, feels safer this way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean we could at least do t.replaceFVars instead of mkLambdaFVars + beta. Anyways, I feel like this is in general a bit hacky, couldn't you just check hasLooseBVars on the forall domain? So to be precise we could start with let ctorType := instantiateForall ctorInfo.type params and then peel away the forall layers while deciding on Eq vs HEq using hasLooseBVars.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to try and see if the resulting code is more elegant.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And while you are at it, maybe you can come up with prettier tactic-free code for mkEqNDRecTelescope

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

Reference manual CI status:

  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2025-12-01 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-02 13:51:55)

leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Dec 2, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Dec 2, 2025
@leanprover-community-bot leanprover-community-bot added the breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan label Dec 2, 2025
@leanprover-community-bot
Copy link
Collaborator

leanprover-community-bot commented Dec 2, 2025

Mathlib CI status (docs):

nomeata added a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Dec 2, 2025
nomeata added a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Dec 2, 2025
@leanprover-community-bot leanprover-community-bot added builds-mathlib CI has verified that Mathlib builds against this PR and removed breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan labels Dec 2, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Dec 2, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Dec 2, 2025
@nomeata nomeata added this pull request to the merge queue Dec 2, 2025
Merged via the queue into master with commit edf804c Dec 2, 2025
27 checks passed
algebraic-dev pushed a commit that referenced this pull request Dec 8, 2025
This PR generalizes the `noConfusion` constructions to heterogeneous
equalities (assuming propositional equalities between the indices). This
lays ground work for better support for applying injection to
heterogeneous equalities in grind.

The `Meta.mkNoConfusion` app builder shields most of the code from these
changes.

Since the per-constructor noConfusion principles are now more
expressive, `Meta.mkNoConfusion` no longer uses the general one.

In `Init.Prelude` some proofs are more pedestrian because `injection`
now needs a bit more machinery.

This is a breaking change for whoever uses the `noConfusion` principle
manually and explicitly for a type with indices.

Fixes #11450.
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-language Language features and metaprograms 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.

RFC: heterogeneous noConfusion

6 participants