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: improvements to congr! and convert #2606

Closed
wants to merge 51 commits into from

Conversation

kmill
Copy link
Contributor

@kmill kmill commented Mar 3, 2023

  • There is now configuration for congr!, convert, and convert_to to control parts of the congruence algorithm, in particular transparency settings when applying congruence lemmas.
  • congr! now applies congruence lemmas with reducible transparency by default. This prevents it from unfolding definitions when applying congruence lemmas. It also now tries both the LHS-biased and RHS-biased simp congruence lemmas, with a configuration option to set which it should try first.
  • There is now a new HEq congruence lemma generator that gives each hypothesis access to the proofs of previous hypotheses. This means that if you have an equality ⊢ ⟨a, x⟩ = ⟨b, y⟩ of sigma types, congr! turns this into goals ⊢ a = b and ⊢ a = b → HEq x y (note that congr! will also auto-introduce a = b for you in the second goal). This congruence lemma generator applies to more cases than the simp congruence lemma generator does.
  • congr! (and hence convert) are more careful about applying lemmas that don't force definitions to unfold. There were a number of cases in mathlib where the implementation of congr was being abused to unfold definitions.
  • With set_option trace.congr! true you can see what congr! sees when it is deciding on congruence lemmas.
  • There is also a bug fix in convert_to to do using 1 when there is no using clause, to match its documentation.

Note that congr! is more capable than congr at finding a way to equate left-hand sides and right-hand sides, so you will frequently need to limit its depth with a using clause. However, there is also a new heuristic to prevent considering unlikely-to-be-provable type equalities (controlled by the typeEqs option), which can help limit the depth automatically.

There is also a predefined configuration that you can invoke with, for example, convert (config := .unfoldSameFun) h, that causes it to behave more like congr, including using default transparency when unfolding.


Open in Gitpod

@kmill kmill added t-meta Tactics, attributes or user commands WIP Work in progress labels Mar 3, 2023
@kmill kmill changed the title feat: use simp-style fallback congruence lemmas feat: improvements to congr! and convert Mar 7, 2023
@kmill kmill added awaiting-review and removed WIP Work in progress labels Mar 7, 2023
@kmill kmill requested a review from fpvandoorn March 7, 2023 20:13
@kmill kmill added WIP Work in progress and removed awaiting-review labels Mar 8, 2023
@semorrison semorrison added the merge-conflict The PR has a merge conflict with master, and needs manual merging. label Mar 10, 2023
@semorrison semorrison added the merge-conflict The PR has a merge conflict with master, and needs manual merging. label Mar 12, 2023
@semorrison semorrison removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. label Mar 13, 2023
Copy link
Member

@fpvandoorn fpvandoorn left a comment

Choose a reason for hiding this comment

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

LGTM

bors d+

test/convert.lean Outdated Show resolved Hide resolved
Mathlib/Tactic/Congr!.lean Outdated Show resolved Hide resolved
Mathlib/Tactic/Congr!.lean Outdated Show resolved Hide resolved
Mathlib/Tactic/Congr!.lean Outdated Show resolved Hide resolved
Mathlib/Tactic/Congr!.lean Outdated Show resolved Hide resolved
Mathlib/Tactic/Congr!.lean Outdated Show resolved Hide resolved
@bors
Copy link

bors bot commented Mar 16, 2023

✌️ kmill can now approve this pull request. To approve and merge a pull request, simply reply with bors r+. More detailed instructions are available here.

@kmill
Copy link
Contributor Author

kmill commented Mar 16, 2023

bors r+

@github-actions github-actions bot added the ready-to-merge This PR has been sent to bors. label Mar 16, 2023
bors bot pushed a commit that referenced this pull request Mar 16, 2023
* There is now configuration for `congr!`, `convert`, and `convert_to` to control parts of the congruence algorithm, in particular transparency settings when applying congruence lemmas.
* `congr!` now applies congruence lemmas with reducible transparency by default. This prevents it from unfolding definitions when applying congruence lemmas. It also now tries both the LHS-biased and RHS-biased simp congruence lemmas, with a configuration option to set which it should try first.
* There is now a new `HEq` congruence lemma generator that gives each hypothesis access to the proofs of previous hypotheses. This means that if you have an equality `⊢ ⟨a, x⟩ = ⟨b, y⟩` of sigma types, `congr!` turns this into goals `⊢ a = b` and `⊢ a = b → HEq x y` (note that `congr!` will also auto-introduce `a = b` for you in the second goal). This congruence lemma generator applies to more cases than the simp congruence lemma generator does.
* `congr!` (and hence `convert`) are more careful about applying lemmas that don't force definitions to unfold. There were a number of cases in mathlib where the implementation of `congr` was being abused to unfold definitions.
* With `set_option trace.congr! true` you can see what `congr!` sees when it is deciding on congruence lemmas.
* There is also a bug fix in `convert_to` to do `using 1` when there is no `using` clause, to match its documentation.

Note that `congr!` is more capable than `congr` at finding a way to equate left-hand sides and right-hand sides, so you will frequently need to limit its depth with a `using` clause. However, there is also a new heuristic to prevent considering unlikely-to-be-provable type equalities (controlled by the `typeEqs` option), which can help limit the depth automatically.

There is also a predefined configuration that you can invoke with, for example, `convert (config := .unfoldSameFun) h`, that causes it to behave more like `congr`, including using default transparency when unfolding.
@bors
Copy link

bors bot commented Mar 16, 2023

Pull request successfully merged into master.

Build succeeded:

@bors bors bot changed the title feat: improvements to congr! and convert [Merged by Bors] - feat: improvements to congr! and convert Mar 16, 2023
@bors bors bot closed this Mar 16, 2023
@bors bors bot deleted the kmill_congr_fallback branch March 16, 2023 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
delegated ready-to-merge This PR has been sent to bors. t-meta Tactics, attributes or user commands
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants