-
Notifications
You must be signed in to change notification settings - Fork 297
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
[Merged by Bors] - feat({tactic + test}/congrm, logic/basic): congrm = congr + pattern-match
#14153
Conversation
That zulip link just goes to the channel; can you correct it? |
Eric, thanks for noticing: I updated the link and the description of the PR. |
src/tactic/congrm.lean
Outdated
n ← get_unused_name "h", | ||
assert n el, | ||
rotate, | ||
get_local n >>= rewrite_target, |
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.
A key feature of the congr
tactic is that it uses the automatically generated congruence lemmas (mk_specialized_congr_lemma
). This is what allows it to ignore subsingleton arguments and rewrite in dependent positions. For example on ite p a b = ite q a b
we want the subgoal p = q
but we cannot rw
with p = q
. Similarly on ite p a b = by classical; exact p a c
we want the subgoal b = c
but this requires knowing that decidable p
is a subsingleton.
In other words, equate_with_pattern
should do something like apply_eq_congr_core
, except compute the congruence lemma from the pattern instead of the lhs.
It would also be cool if congr(m) could descend into lambdas and foralls. I wonder why we never implemented that.
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.
It would also be cool if congr(m) could descend into lambdas and foralls. I wonder why we never implemented that.
This is my biggest gripe with congr
.
congrm = congr + pattern-match
congrm = congr + pattern-match
This lemma is used in #14153, where `congrm` is defined. A big reason for splitting these 3 lines off the main PR is that they are the only ones that are not in a leaf of the import hierarchy: this hopefully saves lots of CI time, when doing trivial changes to the main PR.
src/tactic/congrm.lean
Outdated
setup_tactic_parser | ||
|
||
/-- | ||
`congrm e` assumes that the goal is of the form `lhs = rhs` or `lhs ↔ rhs`. |
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.
My only complaint is that the docs are a little on the technical side, with discussion of metavariables and so on! I think it might be clearer to write something like, "congrm e
takes an expression e
containing placeholders _
. It matches both lhs
and rhs
to this pattern, and produces one goal for each placeholder, stating that the corresponding subexpressions in lhs
and rhs
are equal."
I think it would also be good to include one or two of the earlier tests in the docs as examples, rather than only giving the one that has binders in 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.
Thanks, Rob! I updated the doc-string, making it hopefully more user-friendly!
I also added an example that should clarify better the intended use of the tactic.
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.
Looks great!
bors merge |
…match` (#14153) This PR defines a tactic `congrm`. If the goal is an equality, where the sides are "almost" equal, then calling `congrm <expr_with_mvars_for_differences>` will produce goals for each place where the given expression has metavariables and will try to close the goal assuming all equalities have been proven. For instance, ``` example {a b : ℕ} (h : a = b) : (λ y : ℕ, ∀ z, a + a = z) = (λ x, ∀ z, b + a = z) := begin congrm λ x, ∀ w, _ + a = w, exact h, end ``` works. [Zulip](https://leanprover.zulipchat.com/#narrow/stream/239415-metaprogramming-.2F-tactics/topic/variant.20syntax.20for.20.60congr'.60) Co-authored-by: Gabriel Ebner <gebner@gebner.org> Co-authored-by: Gabriel Ebner <gebner@gebner.org>
Pull request successfully merged into master. Build succeeded: |
congrm = congr + pattern-match
congrm = congr + pattern-match
This PR defines a tactic
congrm
. If the goal is an equality, where the sides are "almost" equal, then callingcongrm <expr_with_mvars_for_differences>
will produce goals for each place where the given expression has metavariables and will try to close the goal assuming all equalities have been proven.For instance,
works.
Zulip
Co-authored-by: Gabriel Ebner gebner@gebner.org