Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wildcard generalize only generalizes visible theorems #4846

Merged
merged 1 commit into from
Oct 25, 2024

Conversation

ymherklotz
Copy link
Contributor

@ymherklotz ymherklotz commented Jul 26, 2024

generalize ... at * sometimes will try to modify the recursive hypothesis corresponding to the current theorem being defined, which may not be the expected behaviour. It should only try to generalize hypotheses that it can actually modify and are visible, not implementation details. Otherwise this means that there are discrepancies between generalize ... at * and generalize ... at H, even though H is the only hypothesis in the context.

This commit uses getLocalHyps instead of getFVarIds to get the current valid FVarIds in the context. This uses isImplementationDetail to filter out FVarIds that are implementation details in the context and are not visible to the user and should not be manipulated by generalize.

Closes #4845

@ymherklotz
Copy link
Contributor Author

If there is a preferred way to fix this, or if this is actually the expected behaviour then let me know, happy to close the PR then.

awaiting-review

@github-actions github-actions bot added awaiting-review Waiting for someone to review the PR toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN labels Jul 26, 2024
@leanprover-community-mathlib4-bot
Copy link
Collaborator

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 9b342efb84f63a334ba740e01dbd09e7f38685da --onto 39e0b41fe1ab4d16f15efb0dc9bd7607a8941713. (2024-07-26 21:26:33)

@leanprover-bot leanprover-bot added the P-medium We may work on this issue if we find the time label Aug 2, 2024
@ymherklotz ymherklotz marked this pull request as ready for review August 2, 2024 16:24
@ymherklotz ymherklotz requested a review from kim-em as a code owner August 2, 2024 16:24
`generalize ... at *` sometimes will try to modify the recursive hypothesis
corresponding to the current theorem being defined, which may not be the
expected behaviour.  It should only try to `generalize` hypotheses that it can
actually modify and are visible, not implementation details. Otherwise this
means that there are discrepancies between `generalize ... at *` and `generalize
... at H`, even though `H` is the only hypothesis in the context.

This commit uses `getLocalHyps` instead of `getFVarIds` to get the current valid
`FVarIds` in the context.  This uses `isImplementationDetail` to filter out
`FVarIds` that are implementation details in the context and are not visible to
the user and should not be manipulated by `generalize`.

Closes 4845
@kim-em kim-em force-pushed the wildcard-generalize branch from e21c10f to 34819d8 Compare October 25, 2024 01:32
@kim-em
Copy link
Collaborator

kim-em commented Oct 25, 2024

@ymherklotz, apologies for my unreasonable delay here. This looks good. I've just rebase on nightly-with-mathlib so we can get some downstream testing before merging. If that goes well, I will merge.

leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Oct 25, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Oct 25, 2024
@leanprover-community-bot leanprover-community-bot added the builds-mathlib CI has verified that Mathlib builds against this PR label Oct 25, 2024
@leanprover-community-bot
Copy link
Collaborator

Mathlib CI status (docs):

@kim-em kim-em added this pull request to the merge queue Oct 25, 2024
Merged via the queue into leanprover:master with commit 19ce204 Oct 25, 2024
16 checks passed
tobiasgrosser pushed a commit to opencompl/lean4 that referenced this pull request Oct 27, 2024
…ver#4846)

`generalize ... at *` sometimes will try to modify the recursive
hypothesis corresponding to the current theorem being defined, which may
not be the expected behaviour. It should only try to `generalize`
hypotheses that it can actually modify and are visible, not
implementation details. Otherwise this means that there are
discrepancies between `generalize ... at *` and `generalize ... at H`,
even though `H` is the only hypothesis in the context.

This commit uses `getLocalHyps` instead of `getFVarIds` to get the
current valid `FVarIds` in the context. This uses
`isImplementationDetail` to filter out `FVarIds` that are implementation
details in the context and are not visible to the user and should not be
manipulated by `generalize`.

Closes leanprover#4845
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-review Waiting for someone to review the PR builds-mathlib CI has verified that Mathlib builds against this PR P-medium We may work on this issue if we find the time 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.

Generalize seems to try to generalize inside the hypothesis being defined
5 participants