-
Notifications
You must be signed in to change notification settings - Fork 460
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
feat: binderNameHint #6947
feat: binderNameHint #6947
Conversation
Mathlib CI status (docs):
|
…achim/binderNameHint
Should this be legal on the LHS too, to allow reverse rewriting? |
Hmm, for that we’d have to make sure it does not get in the way of matching, so probably has to be marked as reducible? One would have to investigate if that works well first. |
in hypotheses or by other tactics. | ||
-/ | ||
@[simp ↓] | ||
def binderNameHint {α : Sort u} {β : Sort v} {γ : Sort w} (v : α) (binder : β) (e : γ) : γ := e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this ought to be reducible, so that defeq matching on the types of theorems (for instance, perhaps loogle and exact?) does not get tripped up by it?
More extremely, perhaps it should be a macro
that produces an Expr.mdata
, so that unaware tactics can easily strip it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, making this reducible is worth a try.
I don’t think a mdata
can store other expressions, so not sure if this would work better.
This PR adds the
binderNameHint
gadget. It can be used in rewrite and simp rules to preserve a user-provided name where possible.The expression
binderNameHint v binder e
defined to bee
.If it is used on the right-hand side of an equation that is applied by a tactic like
rw
orsimp
,and
v
is a local variable, andbinder
is an expression that (after beta-reduction) is a binder(so
fun w => …
or∀ w, …
), then it will renamev
to the name used in the binder, and removethe
binderNameHint
.A typical use of this gadget would be as follows; the gadget ensures that after rewriting, the local
variable is still
name
, and notx
:This gadget is supported by
simp
,dsimp
andrw
in the right-hand-side of an equation, but notin hypotheses or by other tactics.