feat(Tactic): convert now discharges side goals at reducible transparency#39039
feat(Tactic): convert now discharges side goals at reducible transparency#39039Vierkantor wants to merge 12 commits into
Conversation
✅ PR Title Formatted CorrectlyThe title of this PR has been updated to match our commit style conventions. |
|
How difficult is it to replace |
|
I'm working on it right now! (My idea was it pops up a |
|
I need to have dinner now, and it's going to be a busy weekend. If you'd like to push fixes, please go ahead! Otherwise I'll go and add a few more fixes in my unoccupied hours. |
|
Just to note, I had started another PR changing a setting in I think that could fit together with the change in this PR by keeping |
|
I like the setting change in #38071! Since this PR causes quite a bit of downstream breakage in |
PR summary 5a6a0455e2Import changes for modified filesNo significant changes to the import graph Import changes for all files
|
|
Assuming build passes and we don't pick up more merge conflicts, I'm more or less happy with this PR. (There is the issue of some "Try this:" suggestions being slightly misformatted, which I would prefer to wait for the autoformatter.) Let's think about how to get this merged without causing approximately a thousand merge conflicts. In the Zulip thread I have an idea for how to do so incrementally, what do you think? |
|
This pull request has conflicts, please merge |
|
This pull request has conflicts, please merge |
There was a problem hiding this comment.
@maintainer: this is the relevant part of the change
There was a problem hiding this comment.
@maintainer: this is the relevant part of the change
| convert | ||
| ((H.comp hF).comp (mvPolynomialHomeomorph _ R A).isEmbedding).comp | ||
| (isEmbedding_precomp_of_surjective (R := R) fBC hfBC) |
There was a problem hiding this comment.
| convert | |
| ((H.comp hF).comp (mvPolynomialHomeomorph _ R A).isEmbedding).comp | |
| (isEmbedding_precomp_of_surjective (R := R) fBC hfBC) | |
| convert ((H.comp hF).comp (mvPolynomialHomeomorph _ R A).isEmbedding).comp | |
| (isEmbedding_precomp_of_surjective (R := R) fBC hfBC) |
There is quite a few of these formatting changes without content. I assume they came from a script adding convert! first and then removing ! again? Maybe it be better to undo these formatting changes?
(on the other hand, since we don't yet have an auto-formatter in use, I won't insist on reverting these formatting changes)
| p.degrees = p.support.sup fun s : σ →₀ ℕ => Finsupp.toMultiset s := by rw [degrees]; convert | ||
| rfl |
There was a problem hiding this comment.
| p.degrees = p.support.sup fun s : σ →₀ ℕ => Finsupp.toMultiset s := by rw [degrees]; convert | |
| rfl | |
| p.degrees = p.support.sup fun s : σ →₀ ℕ => Finsupp.toMultiset s := by | |
| rw [degrees] | |
| convert rfl |
if reformatted, then better without ; which the style guide (weakly) prefers.
| @@ -274,8 +336,13 @@ example (a b c d e f g N : ℕ) : (a + b) + (c + d) + (e + f) + g ≤ N := by | |||
| ``` | |||
| -/ | |||
| syntax (name := acChange) "ac_change " term (" using " num)? : tactic | |||
| @[tactic_alt acChange] | |||
There was a problem hiding this comment.
| @[tactic_alt acChange] | |
| @[tactic_alt acChange] |
| -- TODO: also enable this in the future? (Not right now, for backwards compatibility). | ||
| -- transparency := default, | ||
| -- preTransparency := default, | ||
| postTransparency := default } |
There was a problem hiding this comment.
does that mean there is no way to override this using the config and when postTransparency explicitly it will just be ignored?
It's a bit odd to me that you can write convert! (postTransparency := .reducible) ... or convert! (postTransparency := .default) ... and they do the same thing as the argument is overwritten.
But I guess I don't have a better solution either.
There was a problem hiding this comment.
In #39928, I've come up with a solution involving two structure declarations with different default field values and their own declare_config_elab that we choose between.
| if semireducible.isSome then | ||
| liftMetaTactic fun g ↦ do | ||
| -- Suggest `convert` instead of `convert!` if that gives us the same goals. | ||
| let redGoals ← g.convert e sym.isSome (n.map (·.getNat)) baseConfig patterns | ||
| let defaultGoals ← g.convert e sym.isSome (n.map (·.getNat)) config patterns | ||
| if redGoals.length == defaultGoals.length then | ||
| let sameGoals ← try | ||
| (redGoals.zip defaultGoals).allM fun (g₁, g₂) => do | ||
| -- Check that they agree on the set of free variables, otherwise we get errors. | ||
| -- We assume the context in the `convert` case is a subset of the `convert!` case | ||
| -- since `convert!` can more agressively unfold and introduce more variables. | ||
| if !(← g₁.getDecl).lctx.isSubPrefixOf (← g₂.getDecl).lctx then return false | ||
| g₂.withContext <| withReducible <| isDefEq (← g₁.getType) (← g₂.getType) | ||
| catch _ => pure false | ||
| if sameGoals then | ||
| let tac ← `(tactic| convert%$tk $cfg $[←%$sym]? $term $[using $n]? $[with $ps?*]?) | ||
| TryThis.addSuggestion tk { suggestion := tac } (origSpan? := ← getRef) | ||
| return defaultGoals ++ gs | ||
| else | ||
| liftMetaTactic fun g ↦ | ||
| return (← g.convert e sym.isSome (n.map (·.getNat)) config patterns) ++ gs |
There was a problem hiding this comment.
I assume this was here for you to figure out which ! to remove for this PR. Is your intent to keep this in for the final PR? Isn't that quite inefficient?
There was a problem hiding this comment.
This is indeed inefficient, but I don't know a good way to add the "Try this:" otherwise. I figure it might make a nice lint, perhaps hidden behind an off-by-default option? We could benchmark it in the final version.
| -- TODO: also enable this in the future? (Not right now, for backwards compatibility). | ||
| -- transparency := default, | ||
| -- preTransparency := default, | ||
| postTransparency := default } |
There was a problem hiding this comment.
(same question as above)
| $[with $ps?*]? $[$loc?:location]?) => do | ||
| let n : ℕ := n |>.map (·.getNat) |>.getD 1 | ||
| let config ← Congr!.elabConfig (mkOptionalNode cfg) | ||
| let mut config := { ← Convert.elabConfig cfg with } |
This PR prepares for #39039 by adding the required syntax. Once this PR is in, we'll do a global find and replace for changing `convert` to `convert!` (without changing the behaviour), and finally we will enable the new behaviour for `convert`.
…39715) This PR prepares for #39039 by adding the required syntax. Once this PR is in, we'll do a global find and replace for changing `convert` to `convert!` (without changing the behaviour), and finally we will enable the new behaviour for `convert`. Co-authored-by: Anne C.A. Baanen <vierkantor@vierkantor.com>
…39715) This PR prepares for #39039 by adding the required syntax. Once this PR is in, we'll do a global find and replace for changing `convert` to `convert!` (without changing the behaviour), and finally we will enable the new behaviour for `convert`. Co-authored-by: Anne C.A. Baanen <vierkantor@vierkantor.com>
Otherwise it turns out some proofs break.
afb33db to
2763d79
Compare
|
This PR/issue depends on: |
…eanprover-community#39715) This PR prepares for leanprover-community#39039 by adding the required syntax. Once this PR is in, we'll do a global find and replace for changing `convert` to `convert!` (without changing the behaviour), and finally we will enable the new behaviour for `convert`. Co-authored-by: Anne C.A. Baanen <vierkantor@vierkantor.com>
…-community#39721) This PR makes any use of `convert` pop up a "Try this:" message replacing it with `convert!`. This prepares for leanprover-community#39039 which will make `convert` change behaviour and `convert!` retain the old behaviour. Note that `convert` and `convert!` still do the same thing and result in the same goals after this PR is applied, except `convert!` does not pop up a "Try this:" afterwards. Co-authored-by: Anne C.A. Baanen <vierkantor@vierkantor.com> Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Co-authored-by: Michael Rothgang <rothgang@math.uni-bonn.de>
|
This pull request has conflicts, please merge |
|
Now that all uses of Also, what do you think about By the way, my other PR changing the behaviour of It should only do congruence steps when the head function on both sides is the same. I'll wait with working on that PR until this one is merged to avoid merge conflicts. |
|
(Quick answer for this sentence, I'll write a full response when I am ready tomorrow.)
My plan is to get a PR ready which updates |
…eanprover-community#39715) This PR prepares for leanprover-community#39039 by adding the required syntax. Once this PR is in, we'll do a global find and replace for changing `convert` to `convert!` (without changing the behaviour), and finally we will enable the new behaviour for `convert`. Co-authored-by: Anne C.A. Baanen <vierkantor@vierkantor.com>
…-community#39721) This PR makes any use of `convert` pop up a "Try this:" message replacing it with `convert!`. This prepares for leanprover-community#39039 which will make `convert` change behaviour and `convert!` retain the old behaviour. Note that `convert` and `convert!` still do the same thing and result in the same goals after this PR is applied, except `convert!` does not pop up a "Try this:" afterwards. Co-authored-by: Anne C.A. Baanen <vierkantor@vierkantor.com> Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Co-authored-by: Michael Rothgang <rothgang@math.uni-bonn.de>
…eanprover-community#39715) This PR prepares for leanprover-community#39039 by adding the required syntax. Once this PR is in, we'll do a global find and replace for changing `convert` to `convert!` (without changing the behaviour), and finally we will enable the new behaviour for `convert`. Co-authored-by: Anne C.A. Baanen <vierkantor@vierkantor.com>
…-community#39721) This PR makes any use of `convert` pop up a "Try this:" message replacing it with `convert!`. This prepares for leanprover-community#39039 which will make `convert` change behaviour and `convert!` retain the old behaviour. Note that `convert` and `convert!` still do the same thing and result in the same goals after this PR is applied, except `convert!` does not pop up a "Try this:" afterwards. Co-authored-by: Anne C.A. Baanen <vierkantor@vierkantor.com> Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Co-authored-by: Michael Rothgang <rothgang@math.uni-bonn.de>
This PR implements the main behaviour change from #39039: `convert` now discharges side goals at reducible transparency. `convert!`, which we previously switched all calls inside Mathlib to, keeps the old behaviour of working at default transparency. (Everything discussed in this PR holds analogously for the other tactics in the family: `convert_to` and `ac_change`). The main trick in this PR is in allowing `convert!` to have different configuration options than `convert`, but still allow the user to override those options too. So `convert! (postTransparency := .instances)` will have transparency set to `.instances`, not `.default`. We achieve this by having two new structures that copy `Congr!.Config` but set different default values, and choosing between the corresponding elaborators for those configs based on the presence of an `!`. I got this trick from Jovan's #38071 which also changes settings in `Convert.Config`. This PR should be mostly compatible with #38071 and I'd like to get both this one and #38071 in before wrapping up #39039 by replacing unnecessary calls to `convert!` with `convert`.
This PR implements the main behaviour change from #39039: `convert` now discharges side goals at reducible transparency. `convert!`, which we previously switched all calls inside Mathlib to, keeps the old behaviour of working at default transparency. (Everything discussed in this PR holds analogously for the other tactics in the family: `convert_to` and `ac_change`). The main trick in this PR is in allowing `convert!` to have different configuration options than `convert`, but still allow the user to override those options too. So `convert! (postTransparency := .instances)` will have transparency set to `.instances`, not `.default`. We achieve this by having two new structures that copy `Congr!.Config` but set different default values, and choosing between the corresponding elaborators for those configs based on the presence of an `!`. I got this trick from Jovan's #38071 which also changes settings in `Convert.Config`. This PR should be mostly compatible with #38071 and I'd like to get both this one and #38071 in before wrapping up #39039 by replacing unnecessary calls to `convert!` with `convert`. Co-authored-by: Anne C.A. Baanen <vierkantor@vierkantor.com>
…ommunity#39928) This PR implements the main behaviour change from leanprover-community#39039: `convert` now discharges side goals at reducible transparency. `convert!`, which we previously switched all calls inside Mathlib to, keeps the old behaviour of working at default transparency. (Everything discussed in this PR holds analogously for the other tactics in the family: `convert_to` and `ac_change`). The main trick in this PR is in allowing `convert!` to have different configuration options than `convert`, but still allow the user to override those options too. So `convert! (postTransparency := .instances)` will have transparency set to `.instances`, not `.default`. We achieve this by having two new structures that copy `Congr!.Config` but set different default values, and choosing between the corresponding elaborators for those configs based on the presence of an `!`. I got this trick from Jovan's leanprover-community#38071 which also changes settings in `Convert.Config`. This PR should be mostly compatible with leanprover-community#38071 and I'd like to get both this one and leanprover-community#38071 in before wrapping up leanprover-community#39039 by replacing unnecessary calls to `convert!` with `convert`. Co-authored-by: Anne C.A. Baanen <vierkantor@vierkantor.com>
This PR changes the
postCongr!discharge step of theconverttactic to operate at reducible transparency by default, just like thepreCongr!step. This should make the behaviour more predictable since it does not unfold quite as much.convert_toandac_changeget a similar modification, since they are macros on top ofconvert.To get back the old behaviour and work at default transparency, write
convert!. To make Mathlib not break due to this change, we replace all occurrences ofconvertwithconvert!in the next commit.Zulip discussion: https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/Mathlib.20code.20quality.3A.20simpa/with/594729278
convert!,convert_to!,ac_change!#39715