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: port GroupTheory.Subgroup.Basic #1797

Closed
wants to merge 37 commits into from

Conversation

Ruben-VandeVelde
Copy link
Collaborator


Open in Gitpod

Mathbin -> Mathlib

fix certain import statements

move "by" to end of line

add import to Mathlib.lean
@Ruben-VandeVelde Ruben-VandeVelde added help-wanted The author needs attention to resolve issues awaiting-author A reviewer has asked the author a question or requested changes labels Jan 23, 2023
@LukasMias LukasMias added mathlib-port This is a port of a theory file from mathlib. WIP Work in progress and removed awaiting-author A reviewer has asked the author a question or requested changes labels Jan 24, 2023
@Vierkantor
Copy link
Contributor

It's somewhat surprising that this seems to have more problems than LinearMap given that I expected unbundled inheritance as in MulMemClass etc. to be easier on Lean 4's outParam support than bundled as in LinearMapClass. I'll take a look, see if I can fix some of the issues.

@Vierkantor
Copy link
Contributor

I think I see the issue: MulMemClass etc. should not have an outParam and instead leave figuring out the type of elements to SetLike. Let's see if that helps...

Vierkantor added a commit that referenced this pull request Jan 25, 2023
… parents' `outParam`

This PR fixes a large amount of issues encountered in the port of `GroupTheory.Subgroup.Basic`, #1797. Subobject classes such as `MulMemClass` and `SubmonoidClass` take a `SetLike` parameter, and we were used to just copy over the `M : outParam Type` declaration from `SetLike`. Since Lean 3 synthesized from left to right, we'd fill in the `outParam` from `SetLike`, then the `Mul M` instance would be available for synthesis and we'd be in business. In Lean 4 however, we often go from right to left, so that `MulMemClass ?M S [?inst : Mul ?M]` is handled first, which can't be solved before finding a `Mul ?M` instance on the metavariable `?M`, causing search through all `Mul` instances.

The solution is: whenever a class is declared that takes another class as parameter (i.e. unbundled inheritance), the `outParam`s of the parent class should be unmarked and become in-params in the child class. Then Lean will try to find the parent class instance first, fill in the `outParam`s and we'll be able to synthesize the child class instance without problems.
@Vierkantor
Copy link
Contributor

I spun out the outParam fix to a new PR: #1832. Next, I'll try and see if we can backport this fix to Lean 3, for easier porting in the future.

bors bot pushed a commit that referenced this pull request Jan 25, 2023
… parents' `outParam` (#1832)

This PR fixes a large amount of issues encountered in the port of `GroupTheory.Subgroup.Basic`, #1797. Subobject classes such as `MulMemClass` and `SubmonoidClass` take a `SetLike` parameter, and we were used to just copy over the `M : outParam Type` declaration from `SetLike`. Since Lean 3 synthesized from left to right, we'd fill in the `outParam` from `SetLike`, then the `Mul M` instance would be available for synthesis and we'd be in business. In Lean 4 however, we often go from right to left, so that `MulMemClass ?M S [?inst : Mul ?M]` is handled first, which can't be solved before finding a `Mul ?M` instance on the metavariable `?M`, causing search through all `Mul` instances.

The solution is: whenever a class is declared that takes another class as parameter (i.e. unbundled inheritance), the `outParam`s of the parent class should be unmarked and become in-params in the child class. Then Lean will try to find the parent class instance first, fill in the `outParam`s and we'll be able to synthesize the child class instance without problems.

Pair: leanprover-community/mathlib#18291
@Ruben-VandeVelde Ruben-VandeVelde added awaiting-review The author would like community review of the PR and removed help-wanted The author needs attention to resolve issues WIP Work in progress labels Jan 25, 2023
Mathlib/GroupTheory/Subgroup/Basic.lean Outdated Show resolved Hide resolved
Mathlib/GroupTheory/Subgroup/Basic.lean Outdated Show resolved Hide resolved
Mathlib/GroupTheory/Subgroup/Basic.lean Outdated Show resolved Hide resolved
Mathlib/GroupTheory/Subgroup/Basic.lean Outdated Show resolved Hide resolved
Mathlib/GroupTheory/Subgroup/Basic.lean Outdated Show resolved Hide resolved
Mathlib/GroupTheory/Subgroup/Basic.lean Outdated Show resolved Hide resolved
#align add_subgroup.add_subgroup_of AddSubgroup.addSubgroupOf

/-- If `H ≤ K`, then `H` as a subgroup of `K` is isomorphic to `H`. -/
@[to_additive "If `H ≤ K`, then `H` as a subgroup of `K` is isomorphic to `H`.", simps]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Does this transfer the simps as well, or does it not need to?

Copy link
Member

Choose a reason for hiding this comment

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

no, this needs fixing with to_additive (attr := simps)

Mathlib/GroupTheory/Subgroup/Basic.lean Outdated Show resolved Hide resolved
Mathlib/GroupTheory/Subgroup/Basic.lean Outdated Show resolved Hide resolved

/-- A non-computable version of `MonoidHom.liftOfRightInverse` for when no computable right
inverse is available, that uses `Function.surjInv`. -/
@[simp,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Does this need to_additive-izing?

Copy link
Member

Choose a reason for hiding this comment

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

this should raise a linter error... Yes, it does.

@ChrisHughes24
Copy link
Member

bors merge

@github-actions github-actions bot added ready-to-merge This PR has been sent to bors. and removed awaiting-review The author would like community review of the PR labels Jan 26, 2023
bors bot pushed a commit that referenced this pull request Jan 26, 2023
Co-authored-by: Johan Commelin <johan@commelin.net>
Co-authored-by: Lukas Miaskiwskyi <lukas.mias@gmail.com>
Co-authored-by: qawbecrdtey <qawbecrdtey@naver.com>
Co-authored-by: Vierkantor <vierkantor@vierkantor.com>
Co-authored-by: Floris van Doorn <fpvdoorn@gmail.com>
@bors
Copy link

bors bot commented Jan 26, 2023

Pull request successfully merged into master.

Build succeeded:

@bors bors bot changed the title feat: port GroupTheory.Subgroup.Basic [Merged by Bors] - feat: port GroupTheory.Subgroup.Basic Jan 26, 2023
@bors bors bot closed this Jan 26, 2023
@bors bors bot deleted the port/GroupTheory.Subgroup.Basic branch January 26, 2023 10:33
bors bot pushed a commit to leanprover-community/mathlib that referenced this pull request Jan 27, 2023
…d not repeat the parents' `out_param` (#18291)

This PR is a backport for a mathlib4 fix for a large amount of issues encountered in the port of `group_theory.subgroup.basic`, leanprover-community/mathlib4#1797. Subobject classes such as `mul_mem_class` and `submonoid_class` take a `set_like` parameter, and we were used to just copy over the `M : out_param Type` declaration from `set_like`. Since Lean 3 synthesizes from left to right, we'd fill in the `out_param` from `set_like`, then the `has_mul M` instance would be available for synthesis and we'd be in business. In Lean 4 however, we will often go from right to left, so that `MulMemClass ?M S [?inst : Mul ?M]` is handled first, which can't be solved before finding a `Mul ?M` instance on the metavariable `?M`, causing search through all `Mul` instances.

The solution is: whenever a class is declared that takes another class as parameter (i.e. unbundled inheritance), the `out_param`s of the parent class should be unmarked and become in-params in the child class. Then Lean will try to find the parent class instance first, fill in the `out_param`s and we'll be able to synthesize the child class instance without problems.

One consequence is that sometimes we have to give slightly more type ascription when talking about membership and the types don't quite align: if `M` and `M'` are semireducibly defeq, then before `zero_mem_class S M` would work to prove `(0 : M') ∈ (s : S)`, since the `out_param` became a metavariable, was filled in, and then checked (up to semireducibility apparently) for equality. Now `M` is checked to equal `M'` before applying the instance, with instance-reducible transparency. I don't think this is a huge issue since it feels Lean 4 is stricter about these kinds of equalities anyway.

Mathlib4 pair: leanprover-community/mathlib4#1832
bors bot pushed a commit to leanprover-community/mathlib that referenced this pull request Jan 27, 2023
…d not repeat the parents' `out_param` (#18291)

This PR is a backport for a mathlib4 fix for a large amount of issues encountered in the port of `group_theory.subgroup.basic`, leanprover-community/mathlib4#1797. Subobject classes such as `mul_mem_class` and `submonoid_class` take a `set_like` parameter, and we were used to just copy over the `M : out_param Type` declaration from `set_like`. Since Lean 3 synthesizes from left to right, we'd fill in the `out_param` from `set_like`, then the `has_mul M` instance would be available for synthesis and we'd be in business. In Lean 4 however, we will often go from right to left, so that `MulMemClass ?M S [?inst : Mul ?M]` is handled first, which can't be solved before finding a `Mul ?M` instance on the metavariable `?M`, causing search through all `Mul` instances.

The solution is: whenever a class is declared that takes another class as parameter (i.e. unbundled inheritance), the `out_param`s of the parent class should be unmarked and become in-params in the child class. Then Lean will try to find the parent class instance first, fill in the `out_param`s and we'll be able to synthesize the child class instance without problems.

One consequence is that sometimes we have to give slightly more type ascription when talking about membership and the types don't quite align: if `M` and `M'` are semireducibly defeq, then before `zero_mem_class S M` would work to prove `(0 : M') ∈ (s : S)`, since the `out_param` became a metavariable, was filled in, and then checked (up to semireducibility apparently) for equality. Now `M` is checked to equal `M'` before applying the instance, with instance-reducible transparency. I don't think this is a huge issue since it feels Lean 4 is stricter about these kinds of equalities anyway.

Mathlib4 pair: leanprover-community/mathlib4#1832
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mathlib-port This is a port of a theory file from mathlib. ready-to-merge This PR has been sent to bors.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants