-
Notifications
You must be signed in to change notification settings - Fork 451
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: apply_rfl tactic: handle Eq, HEq, better error messages #3714
Conversation
this implements the first half of #3302: It improves the extensible `rfl` tactic (the one that looks at `refl` attributes) to * Check itself that the lhs and rhs are defEq, and give a nice consistent error message when they don't (instead of just passing on the less helpful error message from `apply Foo.refl`) * Also handle `Eq` and `HEq` (built in) and `Iff` (using the attribute) Care ist taken that, as before, the transparency setting affects comparing the lhs and rhs, but not the reduction of the relation A test file checks the various failure modes and error messages. I believe this `apply_rfl` can serve as the only implementation of `rfl`, which would then complete #3302, but that seems to require a non-trivial bootstrapping dance, so maybe better done separately.
leanprover-community-mathlib4-bot
commented
Mar 19, 2024
•
edited by leanprover-community-bot
Loading
edited by leanprover-community-bot
Mathlib CI status (docs):
|
throwError MessageData.tagged `Tactic.unsolvedGoals <| m!"unsolved goals\n{ | ||
goalsToMessageData gs}" |
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.
this seems like it should be a function somewhere
Ah, interesting: The So I should adjust this code to do these things as well (reduce with |
This is a bit unfortunate: since a given goal can look quite different under Given prominence of (The alternative of using either |
the `rfl` was a bit of a defeq abuse: The goal was `StateEqRs a b` for definitely different terms `a` and `b`, but it was still using `StateEqRs.refl a`, because then after unfolding `StateEqRs` and doing a bit of computation the proof held. This would break once leanprover/lean4#3714 lands, and is a bit fishy in any case so let's just let `simp` handle it.
This reverts commit c972bcb.
building upon #3714, this (almost) implements the second half of #3302. The main effect is that we now get a better error message when `rfl` fails. For ```lean example : n+1+m = n + (1+m) := by rfl ``` instead of the wall of text ``` The rfl tactic failed. Possible reasons: - The goal is not a reflexive relation (neither `=` nor a relation with a @[refl] lemma). - The arguments of the relation are not equal. Try using the reflexivity lemma for your relation explicitly, e.g. `exact Eq.refl _` or `exact HEq.rfl` etc. n m : Nat ⊢ n + 1 + m = n + (1 + m) ``` we now get ``` error: tactic 'rfl' failed, the left-hand side n + 1 + m is not definitionally equal to the right-hand side n + (1 + m) n m : Nat ⊢ n + 1 + m = n + (1 + m) ``` Unfortunately, because of very subtle differences in semantics (which transparency setting is used when reducing the goal and whether the “implicit lambda” feature applies) I could not make this simply the only `rfl` implementation. So `rfl` remains a macro and is still expanded to `eq_refl` (difference transparency setting) and `exact Iff.rfl` and `exact HEq.rfl` (implicit lambda) to not break existing code. This can be revised later, so this still closes: #3302. A user might still be puzzled *why* to terms are not defeq. Explaining that better (“reduced to… and reduces to… etc.”) would also be great, but that’s not specific to `rfl`, so better left for some other time.
This implements the first half of #3302: It improves the extensible
apply_rfl
tactic (the one that looks atrefl
attributes, part ofthe
rfl
macro) toCheck itself and ahead of time that the lhs and rhs are defEq, and give
a nice consistent error message when they don't (instead of just passing on
the less helpful error message from
apply Foo.refl
), and using themachinery that
apply
uses to elaborate expressions to highlight diffsin implicit arguments.
Also handle
Eq
andHEq
(built in) andIff
(using the attribute)Care is taken that, as before, the current transparency setting affects
comparing the lhs and rhs, but not the reduction of the relation
So before we had
and with this PR the messages we get are
resp.
A test file checks the various failure modes and error messages.
I believe this
apply_rfl
can serve as the only implementation ofrfl
, which would then complete #3302, and actually expose these improvederror messages to the user. But as that seems to require a
non-trivial bootstrapping dance, it’ll be separate.