fix(ClearExcept): modify so that each isAuxDecl is retained#36723
fix(ClearExcept): modify so that each isAuxDecl is retained#36723oliver-butterley wants to merge 18 commits intoleanprover-community:masterfrom
ClearExcept): modify so that each isAuxDecl is retained#36723Conversation
|
bench! |
PR summary fb131a4c00Import changes for modified filesNo significant changes to the import graph Import changes for all files
|
…utterley/issue36722
ClearExcept): update to skip isAuxDeclClearExcept): modify so to retail all isAuxDecl
ClearExcept): modify so to retail all isAuxDeclClearExcept): modify so that each isAuxDecl is retained
…utterley/issue36722
|
Thanks, this looks like the right direction for the recursive-hypothesis case. One bounded edge-case question before merge: this change now preserves every I’m asking because the current test clearly covers the motivating recursive example, but the implementation change is slightly broader than that example. If the broader semantics are intended, a short note in the docstring/test rationale may be enough. |
Good point! The description of the PR is very focussed on the recursion case in order to be specific however the primary motive is to improve the user friendliness of I'll improve the docstring. Any suggestions? |
…rley/mathlib4 into oliver-butterley/issue36722
|
One small wording suggestion, if it matches your intent: maybe make the rationale slightly more explicit than the recursive example. For example, something like: "Returns the free variable IDs that can be cleared, excluding those in the preserve list, class instances, and hidden auxiliary declarations (for example recursive hypotheses). The intent is that That seemed to match your explanation that the recursion case is the motivating example, but the intended behavior is broader. |
oliver-butterley
left a comment
There was a problem hiding this comment.
Thanks for all the feedback! Yes, that phrases very well the intent. I wasn't sure where you suggested it would be best to add the clarification. I updated the docstring of the tactic so it is very user-visible since that made most sense to me. Does that seem reasonable?
ClearExcept): modify so that each isAuxDecl is retainedClearExcept): modify so that each isAuxDecl is retained
|
If I remember correctly, this PR had some zulip discussion about it. Can you also link that in the PR description, so future readers can find it more easily? Thanks! |
It is not necessary, and caused confusion in #36723.
Good thinking. Done! |
|
This PR/issue depends on: |
) It is not necessary, and caused confusion in leanprover-community#36723.
|
Yes, this seems reasonable to me. Thanks for making the intended broader semantics explicit in the docstrings and for linking the Zulip discussion as well. |
) It is not necessary, and caused confusion in leanprover-community#36723.
This PR updates the defintion of
ClearExceptto skip anyisAuxDecland adds a test to confirm this behaviour.The intent is that clear * - only clears user-visible local declarations; hidden auxiliary declarations should be handled by more specific mechanisms when needed.
Motivation
When writing a recursive proof in tactic mode, Lean places the recursive hypothesis in the local context as an auxiliary declaration (
LocalDecl.isAuxDecl). This declaration is:Previously the
clear * -tactic (Mathlib.Tactic.ClearExcept) iterates over all declarations in the local context and clears everything not in the explicit keep set or a type-class instance. As such it silently clears the recursive hypothesis. While the hypothesis can technically be added to the keep set by name, it is not shown in the Infoview, making it easy to overlook.In simple examples this is never an issue, the inconvenience was found when working with software verification where the context gets huge and needs clearing for performance and where the recursive goals are closed by automation and so it is easy to overlook the need to explicitly add the name of the theorem to the exclude list.
Zulip discussion: (#general > ClearExcept clears even if isAuxDecl, is this intended?).
clear*-fromisClosedMap_iff_specializingMap#36961 (refactor proof which uses clear*- to clear auxDecl created by wlog)clearExceptcall #36966 (warning that clearExcept does nothing in this use)