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

[Merged by Bors] - feat({tactic + test}/congrm, logic/basic): congrm = congr + pattern-match #14153

Closed
wants to merge 23 commits into from

Conversation

adomani
Copy link
Collaborator

@adomani adomani commented May 15, 2022

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

Co-authored-by: Gabriel Ebner gebner@gebner.org


Open in Gitpod

@adomani adomani added the RFC Request for comment label May 15, 2022
@eric-wieser
Copy link
Member

That zulip link just goes to the channel; can you correct it?

@adomani
Copy link
Collaborator Author

adomani commented May 15, 2022

Eric, thanks for noticing: I updated the link and the description of the PR.

n ← get_unused_name "h",
assert n el,
rotate,
get_local n >>= rewrite_target,
Copy link
Member

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.

Copy link
Member

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.

@arthurpaulino arthurpaulino added the modifies-tactic-syntax This PR adds a new interactive tactic or modifies the syntax of an existing tactic. label May 17, 2022
@gebner gebner added the WIP Work in progress label May 17, 2022
@adomani adomani added awaiting-review The author would like community review of the PR t-meta Tactics, attributes or user commands and removed WIP Work in progress RFC Request for comment labels Jun 3, 2022
@adomani adomani changed the title feat(tactic/congrm): congrm = congr + pattern-match feat({tactic + test}/congrm, logic/basic): congrm = congr + pattern-match Jun 3, 2022
bors bot pushed a commit that referenced this pull request Jun 8, 2022
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.
setup_tactic_parser

/--
`congrm e` assumes that the goal is of the form `lhs = rhs` or `lhs ↔ rhs`.
Copy link
Member

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.

Copy link
Collaborator Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@robertylewis robertylewis added awaiting-author A reviewer has asked the author a question or requested changes and removed awaiting-review The author would like community review of the PR labels Jun 13, 2022
@adomani adomani added awaiting-review The author would like community review of the PR and removed awaiting-author A reviewer has asked the author a question or requested changes labels Jun 14, 2022
@robertylewis
Copy link
Member

bors merge

@github-actions github-actions bot added ready-to-merge All that is left is for bors to build and merge this PR. (Remember you need to say `bors r+`.) and removed awaiting-review The author would like community review of the PR labels Jun 14, 2022
bors bot pushed a commit that referenced this pull request Jun 14, 2022
…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>
@bors
Copy link

bors bot commented Jun 14, 2022

Pull request successfully merged into master.

Build succeeded:

@bors bors bot changed the title feat({tactic + test}/congrm, logic/basic): congrm = congr + pattern-match [Merged by Bors] - feat({tactic + test}/congrm, logic/basic): congrm = congr + pattern-match Jun 14, 2022
@bors bors bot closed this Jun 14, 2022
@bors bors bot deleted the adomani_congrm branch June 14, 2022 16:34
bors bot pushed a commit that referenced this pull request Jun 15, 2022
)

This PR is simply intended to showcase some possible applications of the new tactic `congrm`, introduced in #14153.




Co-authored-by: Gabriel Ebner <gebner@gebner.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
modifies-tactic-syntax This PR adds a new interactive tactic or modifies the syntax of an existing tactic. ready-to-merge All that is left is for bors to build and merge this PR. (Remember you need to say `bors r+`.) t-meta Tactics, attributes or user commands
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants