-
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/to_additive): Improvements to to_additive #5487
Conversation
Thanks for reviewing this @robertylewis, I hope to come back to it soon, |
What you're doing is almost the same as https://leanprover-community.github.io/mathlib_docs/tactic/core.html#tactic.set_attribute |
This issue closes #1639, right? EDIT: At least, if you add |
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.
These are great improvements.
I have some suggestions, but since this PR is so big and desired, I'm also happy if they are done in follow-up PRs.
bors d+
tactic unit := do | ||
get_decl tgt <|> fail!"unknown declaration {tgt}", | ||
-- if the source doesn't have the attribute we do not error and simply return | ||
mwhen (succeeds (has_attribute attr_name src)) $ |
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.
mwhen (succeeds (has_attribute attr_name src)) $ | |
tt ← has_attribute' attr_name src | skip, |
if you do this you don't have to indent / add a nested do
on the next line.
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.
Oh this is smart! Thanks
mwhen (has_attribute' `mono src) | ||
(trace $ "to_additive does not work with mono, apply the mono attribute to both" ++ | ||
"versions after"), |
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.
There are a couple ways to fix mono
.
Maybe we have a way to modify mono
so that it accepts the attribute when it's provided with a (wrong) first argument. This might be tricky.
We could also modify to_additive
so that it works with mono
.
We can add a clause to copy_attribute'
special-casing mono
. Something like if attr_name = "mono" then [add the attribute, but with `none` as first component]
Another way I thought of, but which is worse:
We can copy the attribute by using tactic.set_attribute
. In this case
- We should fix the
inhabited
instance ofmono_selection
to evaluate tomono_selection.both
- We should probably check that the original parameter was also equal to
both
(and otherwise fail).
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.
To be honest I didn't think too much about fixing mono recently, once I realised what the issue with it seemed too annoying to tackle for the relative gain. But I'll have a think about your suggestions :)
✌️ alexjbest can now approve this pull request. To approve and merge a pull request, simply reply with |
Thanks Floris, I will take you at your word and make any changes in a follow up so we can hopefully avoid merge conflicts. bors r+ |
Change a couple of things in to_additive: - First add a `tactic.copy_attribute'` intended for user attributes with parameters very similar to `tactic.copy_attribute` that just copies the parameter over when setting the attribute. This allows to_additive after many other attributes to transfer those attributes properly (e.g. norm_cast) - Have to additive register generated equation lemmas as such, this necessitates a bit of restructuring, first all declarations must be generated (including equational lemmas), then the equational lemmas need their attributes, then they are registered as equation lemmas, finally the attributes are added to the main declaration. - I also fixup the library in many places to account for these changes simplifying the source files, only one new lemma was added, in src/analysis/normed/group/quotient.lean `quotient_norm_mk_le'` to replace the unprimed version in the proof of `norm_normed_mk_le` as simp got better thanks to the new simp lemmas introduced by this PR. Probably many more handwritten additive versions can now be deleted in a future PR, especially defs and instances. - All other library changes are just simplifications by using to additive for some hand generated declarations, and many more attributes on the generated lemmas. - The attribute mono is trickier as it contains for its parameter not actual exprs containing names but exprs making names from strings, so I don't see how to handle it right now. We now warn the user about this, and fix the library in a couple of places.
Build failed (retrying...): |
Change a couple of things in to_additive: - First add a `tactic.copy_attribute'` intended for user attributes with parameters very similar to `tactic.copy_attribute` that just copies the parameter over when setting the attribute. This allows to_additive after many other attributes to transfer those attributes properly (e.g. norm_cast) - Have to additive register generated equation lemmas as such, this necessitates a bit of restructuring, first all declarations must be generated (including equational lemmas), then the equational lemmas need their attributes, then they are registered as equation lemmas, finally the attributes are added to the main declaration. - I also fixup the library in many places to account for these changes simplifying the source files, only one new lemma was added, in src/analysis/normed/group/quotient.lean `quotient_norm_mk_le'` to replace the unprimed version in the proof of `norm_normed_mk_le` as simp got better thanks to the new simp lemmas introduced by this PR. Probably many more handwritten additive versions can now be deleted in a future PR, especially defs and instances. - All other library changes are just simplifications by using to additive for some hand generated declarations, and many more attributes on the generated lemmas. - The attribute mono is trickier as it contains for its parameter not actual exprs containing names but exprs making names from strings, so I don't see how to handle it right now. We now warn the user about this, and fix the library in a couple of places.
Pull request successfully merged into master. Build succeeded: |
Change a couple of things in to_additive: - First add a `tactic.copy_attribute'` intended for user attributes with parameters very similar to `tactic.copy_attribute` that just copies the parameter over when setting the attribute. This allows to_additive after many other attributes to transfer those attributes properly (e.g. norm_cast) - Have to additive register generated equation lemmas as such, this necessitates a bit of restructuring, first all declarations must be generated (including equational lemmas), then the equational lemmas need their attributes, then they are registered as equation lemmas, finally the attributes are added to the main declaration. - I also fixup the library in many places to account for these changes simplifying the source files, only one new lemma was added, in src/analysis/normed/group/quotient.lean `quotient_norm_mk_le'` to replace the unprimed version in the proof of `norm_normed_mk_le` as simp got better thanks to the new simp lemmas introduced by this PR. Probably many more handwritten additive versions can now be deleted in a future PR, especially defs and instances. - All other library changes are just simplifications by using to additive for some hand generated declarations, and many more attributes on the generated lemmas. - The attribute mono is trickier as it contains for its parameter not actual exprs containing names but exprs making names from strings, so I don't see how to handle it right now. We now warn the user about this, and fix the library in a couple of places.
Change a couple of things in to_additive:
tactic.copy_attribute'
intended for user attributes with parameters very similar totactic.copy_attribute
that just copies the parameter over when setting the attribute. This allows to_additive after many other attributes to transfer those attributes properly (e.g. norm_cast)quotient_norm_mk_le'
to replace the unprimed version in the proof ofnorm_normed_mk_le
as simp got better thanks to the new simp lemmas introduced by this PR. Probably many more handwritten additive versions can now be deleted in a future PR, especially defs and instances.See also #5468