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] - refactor(algebra/group/basic): add extra typeclasses for negation #11960

Closed
wants to merge 37 commits into from

Conversation

eric-wieser
Copy link
Member

@eric-wieser eric-wieser commented Feb 10, 2022

The new typeclasses are:

  • has_involutive_inv R, stating that (r⁻¹)⁻¹ = r
    (instances: group, group_with_zero, ennreal, set, submonoid)
  • has_involutive_neg R, stating that - -r = r
    (instances: add_group, ereal, module.ray, ray_vector, set, add_submonoid, jordan_decomposition)
  • has_distrib_neg R, stating that -a * b = a * -b = -(a * b)
    (instances: ring, units, unitary, special_linear_group, GL_pos)

While the original motivation only concerned the two neg typeclasses, the to_additive machinery forced the introduction of has_involutive_inv, which turned out to be used in more places than expected.

Adding these typeclases removes a large number of specialized units R lemmas as the lemmas about R now match themselves. A surprising number of lemmas elsewhere in the library can also be removed. The removed lemmas are:

  • Lemmas about units (replaced by units.has_distrib_neg):
    • units.neg_one_pow_eq_or
    • units.neg_pow
    • units.neg_pow_bit0
    • units.neg_pow_bit1
    • units.neg_sq
    • units.neg_inv (now inv_neg' for arbitrary groups with distributive negation)
    • units.neg_neg
    • units.neg_mul
    • units.mul_neg
    • units.neg_mul_eq_neg_mul
    • units.neg_mul_eq_mul_neg
    • units.neg_mul_neg
    • units.neg_eq_neg_one_mul
    • units.mul_neg_one
    • units.neg_one_mul
    • semiconj_by.units_neg_right
    • semiconj_by.units_neg_right_iff
    • semiconj_by.units_neg_left
    • semiconj_by.units_neg_left_iff
    • semiconj_by.units_neg_one_right
    • semiconj_by.units_neg_one_left
    • commute.units_neg_right
    • commute.units_neg_right_iff
    • commute.units_neg_left
    • commute.units_neg_left_iff
    • commute.units_neg_one_right
    • commute.units_neg_one_left
  • Lemmas about groups with zero (replaced by group_with_zero.to_has_involutive_neg):
    • inv_inv₀
    • inv_involutive₀
    • inv_injective₀
    • inv_eq_iff (now shared with the inv_eq_iff_inv_eq group lemma)
    • eq_inv_iff (now shared with the eq_inv_iff_eq_inv group lemma)
    • equiv.inv₀
    • measurable_equiv.inv₀
  • Lemmas about ereal (replaced by ereal.has_involutive_neg):
    • ereal.neg_neg
    • ereal.neg_inj
    • ereal.neg_eq_neg_iff
    • ereal.neg_eq_iff_neg_eq
  • Lemmas about ennreal (replaced by ennreal.has_involutive_inv):
    • ereal.inv_inv
    • ereal.inv_involutive
    • ereal.inv_bijective
    • ereal.inv_eq_inv
  • Other lemmas:
    • ray_vector.neg_neg
    • module.ray.neg_neg
    • module.ray.neg_involutive
    • module.ray.eq_neg_iff_eq_neg
    • set.inv_inv
    • set.neg_neg
    • submonoid.inv_inv
    • add_submonoid.neg_neg

As a bonus, this provides the group unitary R with a negation operator and all the lemmas listed for units above.

For now this doesn't attempt to unify units.neg_smul and neg_smul.


Open in Gitpod

@urkud
Copy link
Member

urkud commented Feb 10, 2022

Please list all new classes in the commit message.

@eric-wieser eric-wieser added awaiting-CI The author would like to see what CI has to say before doing more work. awaiting-review The author would like community review of the PR labels Feb 10, 2022
@eric-wieser eric-wieser marked this pull request as ready for review February 10, 2022 21:34
@eric-wieser
Copy link
Member Author

Please list all new classes in the commit message.

That was always my plan once I hit most of the lemmas I planned to move.

@github-actions github-actions bot removed the awaiting-CI The author would like to see what CI has to say before doing more work. label Feb 12, 2022
test/matrix.lean Outdated
-/
-- Previously we could do `simp [matrix.det_succ_row_zero, fin.sum_univ_succ]`, but that now times
-- out.
rw det_fin_three,
Copy link
Member

Choose a reason for hiding this comment

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

I think that this example was here to show how to compute the determinant of any matrix, not only 3*3. Can we fix the timeout in some other way?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't really understand why the timeout is happening I'm afraid. Do you think we need to get to the bottom of it before merging, or are you ok with just going ahead with the change anyway.

@urkud
Copy link
Member

urkud commented Feb 15, 2022

Otherwise LGTM
bors d+

@bors
Copy link

bors bot commented Feb 15, 2022

✌️ eric-wieser 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 Feb 15, 2022
test/matrix.lean Outdated Show resolved Hide resolved
@eric-wieser
Copy link
Member Author

bors merge

@github-actions github-actions bot added the ready-to-merge All that is left is for bors to build and merge this PR. (Remember you need to say `bors r+`.) label Feb 16, 2022
bors bot pushed a commit that referenced this pull request Feb 16, 2022
…1960)

The new typeclasses are:
* `has_involutive_inv R`, stating that `(r⁻¹)⁻¹ = r`  
  (instances: `group`, `group_with_zero`, `ennreal`, `set`, `submonoid`)
* `has_involutive_neg R`, stating that `- -r = r`
  (instances: `add_group`, `ereal`, `module.ray`, `ray_vector`, `set`, `add_submonoid`, `jordan_decomposition`)
* `has_distrib_neg R`, stating that `-a * b = a * -b = -(a * b)`
  (instances: `ring`, `units`, `unitary`, `special_linear_group`, `GL_pos`)

While the original motivation only concerned the two `neg` typeclasses, the `to_additive` machinery forced the introduction of `has_involutive_inv`, which turned out to be used in more places than expected.

Adding these typeclases removes a large number of specialized `units R` lemmas as the lemmas about `R` now match themselves. A surprising number of lemmas elsewhere in the library can also be removed. The removed lemmas are:
* Lemmas about `units` (replaced by `units.has_distrib_neg`):
  * `units.neg_one_pow_eq_or`
  * `units.neg_pow`
  * `units.neg_pow_bit0`
  * `units.neg_pow_bit1`
  * `units.neg_sq`
  * `units.neg_inv` (now `inv_neg'` for arbitrary groups with distributive negation)
  * `units.neg_neg`
  * `units.neg_mul`
  * `units.mul_neg`
  * `units.neg_mul_eq_neg_mul`
  * `units.neg_mul_eq_mul_neg`
  * `units.neg_mul_neg`
  * `units.neg_eq_neg_one_mul`
  * `units.mul_neg_one`
  * `units.neg_one_mul`
  * `semiconj_by.units_neg_right`
  * `semiconj_by.units_neg_right_iff`
  * `semiconj_by.units_neg_left`
  * `semiconj_by.units_neg_left_iff`
  * `semiconj_by.units_neg_one_right`
  * `semiconj_by.units_neg_one_left`
  * `commute.units_neg_right`
  * `commute.units_neg_right_iff`
  * `commute.units_neg_left`
  * `commute.units_neg_left_iff`
  * `commute.units_neg_one_right`
  * `commute.units_neg_one_left`
* Lemmas about groups with zero (replaced by `group_with_zero.to_has_involutive_neg`):
  * `inv_inv₀`
  * `inv_involutive₀`
  * `inv_injective₀`
  * `inv_eq_iff` (now shared with the `inv_eq_iff_inv_eq` group lemma)
  * `eq_inv_iff` (now shared with the `eq_inv_iff_eq_inv` group lemma)
  * `equiv.inv₀`
  * `measurable_equiv.inv₀`
* Lemmas about `ereal` (replaced by `ereal.has_involutive_neg`):
  * `ereal.neg_neg`
  * `ereal.neg_inj`
  * `ereal.neg_eq_neg_iff`
  * `ereal.neg_eq_iff_neg_eq`
* Lemmas about `ennreal` (replaced by `ennreal.has_involutive_inv`):
  * `ereal.inv_inv`
  * `ereal.inv_involutive`
  * `ereal.inv_bijective`
  * `ereal.inv_eq_inv`
* Other lemmas:
  * `ray_vector.neg_neg`
  * `module.ray.neg_neg`
  * `module.ray.neg_involutive`
  * `module.ray.eq_neg_iff_eq_neg`
  * `set.inv_inv`
  * `set.neg_neg`
  * `submonoid.inv_inv`
  * `add_submonoid.neg_neg`

As a bonus, this provides the group `unitary R`  with a negation operator and all the lemmas listed for `units` above.

For now this doesn't attempt to unify `units.neg_smul` and `neg_smul`.
@bors
Copy link

bors bot commented Feb 16, 2022

Pull request successfully merged into master.

Build succeeded:

@bors bors bot changed the title refactor(algebra/group/basic): add extra typeclasses for negation [Merged by Bors] - refactor(algebra/group/basic): add extra typeclasses for negation Feb 16, 2022
@bors bors bot closed this Feb 16, 2022
@bors bors bot deleted the eric-wieser/monoid_with_neg branch February 16, 2022 13:36
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. ready-to-merge All that is left is for bors to build and merge this PR. (Remember you need to say `bors r+`.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants