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: support and improve notation_class in simps #2883

Closed
wants to merge 8 commits into from

Conversation

fpvandoorn
Copy link
Member

@fpvandoorn fpvandoorn commented Mar 14, 2023

  • If you write @[simps] for the definition of an AddGroup, it will now generate the correct lemmas for 0, +, nsmul and zsmul using OfNat and heterogenous operations. This is needed for [Merged by Bors] - feat: port CategoryTheory.Groupoid.VertexGroup #2609.
    • This is a lot more flexible than the Lean 3 implementation, in order to handle nsmul, zsmul and numerals.
    • It doesn't handle the zpow and npow projections, since their argument order is different than that of HPow.pow (that was likely done for the sake of to_additive, but we can consider to revisit that choice).
  • Also fixes the nvMonoid bug encountered in [Merged by Bors] - feat: port CategoryTheory.Groupoid.VertexGroup #2609
    • There was an issue where the wrong projection was chosen, since toDiv is a prefix of toDivInvMonoid
    • Before we were checking if _toDiv is a prefix of your projection with _ prepended (e.g. _toDivInvMonoid), now we are checking whether toDiv_ is a prefix of your projection with _ appended (which doesn't match toDivInvMonoid_).

A potential better implementation to this is to have a custom simp-set that simplifies standard projections to the desired custom projections (suggested by Kyle).

Open in Gitpod

@fpvandoorn fpvandoorn added awaiting-review The author would like community review of the PR t-meta Tactics, attributes or user commands awaiting-CI labels Mar 14, 2023
@fpvandoorn fpvandoorn 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 Mar 15, 2023
@fpvandoorn fpvandoorn 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 Mar 15, 2023
Copy link
Contributor

@kmill kmill left a comment

Choose a reason for hiding this comment

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

I have a few comments, but I'll leave it to you to decide how to address them and merge.

bors d+

Mathlib/Lean/Expr/Basic.lean Outdated Show resolved Hide resolved
an applicable name. (e.g. `Iso.inv`)

Implementation note: getting rid of TermElabM is tricky, since `Expr.mkAppOptM` doesn't allow to
keep metavariables around, which are necessary for `OutParam`. -/
Copy link
Contributor

Choose a reason for hiding this comment

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

I won't suggest that you change this, but since we last talked about it I realized that it's possible to do a pattern where you create new FVars rather than metavariables, use mkAppOptM and friends, and then at the end substitute those FVars for metavariables. You could probably set up a nice combinator for this, a variant of withLocalDecl.

By the way, I'm using elabAppArgs in apply_fun (see this block). It's much more powerful than using mkAppOptM since it is the function application elaborator.

catch ex =>
trace[simps.debug] "Projection doesn't have the right type for the automatic projection:\n{
ex.toMessageData}"
return none
Copy link
Contributor

Choose a reason for hiding this comment

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

Might there be any instances that need solving in eInstType before synthInstance? You might insert Lean.Elab.Term.synthesizeSyntheticMVars here.

Copy link
Member Author

Choose a reason for hiding this comment

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

It seems incredibly unlikely, since the classes that will be used here are notation classes like Mul and HasSubset, and those shouldn't have other type-class arguments. And if there are, I probably need to change more, because I made all meta variables using mkFreshExprMVar, and I probably need to make some of them synthetic, if I wanted to support this case (which I probably don't want to).

Mathlib/Tactic/Simps/Basic.lean Outdated Show resolved Hide resolved
Mathlib/Tactic/Simps/Basic.lean Outdated Show resolved Hide resolved
Mathlib/Tactic/Simps/Basic.lean Show resolved Hide resolved
Mathlib/Tactic/Simps/NotationClass.lean Outdated Show resolved Hide resolved
@bors
Copy link

bors bot commented Mar 21, 2023

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

@semorrison semorrison added delegated and removed awaiting-review The author would like community review of the PR labels Mar 21, 2023
@fpvandoorn
Copy link
Member Author

bors merge

@github-actions github-actions bot added the ready-to-merge This PR has been sent to bors. label Mar 22, 2023
bors bot pushed a commit that referenced this pull request Mar 22, 2023
* If you write `@[simps]` for the definition of an `AddGroup`, it will now generate the correct lemmas for `0`, `+`, `nsmul` and `zsmul` using `OfNat` and heterogenous operations. This is needed for #2609.
  * This is a lot more flexible than the Lean 3 implementation, in order to handle `nsmul`, `zsmul` and numerals.
  * It doesn't handle the `zpow` and `npow` projections, since their argument order is different than that of `HPow.pow` (that was likely done for the sake of `to_additive`, but we can consider to revisit that choice).
* Also fixes the `nvMonoid` bug encountered in #2609 
  * There was an issue where the wrong projection was chosen, since `toDiv` is a prefix of `toDivInvMonoid`
  * Before we were checking if `_toDiv` is a prefix of your projection with `_` prepended (e.g. `_toDivInvMonoid`), now we are checking whether `toDiv_` is a prefix of your projection with `_` appended (which doesn't match `toDivInvMonoid_`).
@bors
Copy link

bors bot commented Mar 22, 2023

Pull request successfully merged into master.

Build succeeded:

@bors bors bot changed the title feat: support and improve notation_class in simps [Merged by Bors] - feat: support and improve notation_class in simps Mar 22, 2023
@bors bors bot closed this Mar 22, 2023
@bors bors bot deleted the simpsgroup branch March 22, 2023 22:11
bors bot pushed a commit that referenced this pull request Mar 23, 2023
 - [x] depends on: #2883


Co-authored-by: Moritz Firsching <firsching@google.com>
Co-authored-by: Parcly Taxel <reddeloostw@gmail.com>
Co-authored-by: ChrisHughes24 <chrishughes24@gmail.com>
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

3 participants