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/to_additive): Improvements to to_additive #5487

Closed
wants to merge 44 commits into from

Conversation

alexjbest
Copy link
Member

@alexjbest alexjbest commented Dec 23, 2020

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.

See also #5468

@alexjbest alexjbest added awaiting-review The author would like community review of the PR t-meta Tactics, attributes or user commands labels Dec 24, 2020
@alexjbest alexjbest changed the title feat(tactic/to_additive) Allow to_additive after norm_cast feat(tactic/to_additive) Allow to_additive after norm_cast or continuity Dec 24, 2020
src/tactic/transform_decl.lean Show resolved Hide resolved
src/tactic/transform_decl.lean Outdated Show resolved Hide resolved
src/tactic/transform_decl.lean Outdated Show resolved Hide resolved
src/tactic/transform_decl.lean Outdated Show resolved Hide resolved
@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 Dec 24, 2020
@bryangingechen bryangingechen changed the title feat(tactic/to_additive) Allow to_additive after norm_cast or continuity feat(tactic/to_additive): Allow to_additive after norm_cast or continuity Jan 2, 2021
@alexjbest
Copy link
Member Author

alexjbest commented Jan 4, 2021

Thanks for reviewing this @robertylewis, I hope to come back to it soon,

@fpvandoorn
Copy link
Member

fpvandoorn commented Jan 8, 2021

What you're doing is almost the same as https://leanprover-community.github.io/mathlib_docs/tactic/core.html#tactic.set_attribute
The only difference seem to be the parameter we give to the new attribute. Maybe we can find a common generalization that takes as argument some kind of tactic that generates the parameter for us?

@fpvandoorn
Copy link
Member

fpvandoorn commented Jan 8, 2021

This issue closes #1639, right?

EDIT: At least, if you add `ext to the list (unless there is a reason that @[ext] behaves differently)

@github-actions github-actions bot added the merge-conflict Please `git merge origin/master` then a bot will remove this label. label Jan 27, 2021
@alexjbest alexjbest added the please-adopt This PR/issue may have been abandoned by the original contributor. You are welcome to take it over. label Mar 15, 2021
@github-actions github-actions bot removed the merge-conflict Please `git merge origin/master` then a bot will remove this label. label Jun 1, 2021
@alexjbest alexjbest removed the please-adopt This PR/issue may have been abandoned by the original contributor. You are welcome to take it over. label Jun 1, 2021
@github-actions github-actions bot added the merge-conflict Please `git merge origin/master` then a bot will remove this label. label Jun 4, 2021
@alexjbest alexjbest 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 Oct 17, 2021
alexjbest added a commit that referenced this pull request Oct 18, 2021
Since #9138 and #5487 to_additive got a lot better, so a lot of
duplication in the library becomes unnecessary and makes maintenence a
burden. So we remove a large number of copy-pasted declarations that
can now be generated automatically.
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.

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)) $
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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.

Copy link
Member Author

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

Comment on lines +517 to +519
mwhen (has_attribute' `mono src)
(trace $ "to_additive does not work with mono, apply the mono attribute to both" ++
"versions after"),
Copy link
Member

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 of mono_selection to evaluate to mono_selection.both
  • We should probably check that the original parameter was also equal to both (and otherwise fail).

Copy link
Member Author

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 :)

@bors
Copy link

bors bot commented Oct 18, 2021

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

@github-actions github-actions bot added delegated The PR author may merge after reviewing final suggestions. and removed awaiting-review The author would like community review of the PR labels Oct 18, 2021
@alexjbest
Copy link
Member Author

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+

bors bot pushed a commit that referenced this pull request Oct 18, 2021
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.
@bors
Copy link

bors bot commented Oct 18, 2021

Build failed (retrying...):

bors bot pushed a commit that referenced this pull request Oct 18, 2021
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.
@bors
Copy link

bors bot commented Oct 19, 2021

Pull request successfully merged into master.

Build succeeded:

@bors bors bot changed the title feat(tactic/to_additive): Improvements to to_additive [Merged by Bors] - feat(tactic/to_additive): Improvements to to_additive Oct 19, 2021
@bors bors bot closed this Oct 19, 2021
@bors bors bot deleted the norm_cast_to_additive branch October 19, 2021 02:23
bors bot pushed a commit that referenced this pull request Oct 30, 2021
Since #9138 and #5487 to_additive got a lot better, so a lot of duplication in the library becomes unnecessary and makes maintenence a burden. So we remove a large number of copy-pasted declarations that can now be generated automatically.
bors bot pushed a commit that referenced this pull request Oct 30, 2021
Since #9138 and #5487 to_additive got a lot better, so a lot of duplication in the library becomes unnecessary and makes maintenence a burden. So we remove a large number of copy-pasted declarations that can now be generated automatically.
bors bot pushed a commit that referenced this pull request Oct 31, 2021
Since #9138 and #5487 to_additive got a lot better, so a lot of duplication in the library becomes unnecessary and makes maintenence a burden. So we remove a large number of copy-pasted declarations that can now be generated automatically.
ericrbg pushed a commit that referenced this pull request Nov 9, 2021
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.
ericrbg pushed a commit that referenced this pull request Nov 9, 2021
Since #9138 and #5487 to_additive got a lot better, so a lot of duplication in the library becomes unnecessary and makes maintenence a burden. So we remove a large number of copy-pasted declarations that can now be generated automatically.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
delegated The PR author may merge after reviewing final suggestions. t-meta Tactics, attributes or user commands
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants