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(data/finset/noncomm_prod): Use set.pairwise #16859

Closed
wants to merge 7 commits into from

Conversation

YaelDillies
Copy link
Collaborator

Redefine the various noncomm_prods using set.pairwise. This has the advantage of having a solid API around monotonicity in the set or in the relation and avoiding checking the trivial i = j case.


Open in Gitpod

@YaelDillies YaelDillies added WIP Work in progress t-algebra Algebra (groups, rings, fields etc) labels Oct 7, 2022
Copy link
Collaborator

@alreadydone alreadydone left a comment

Choose a reason for hiding this comment

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

LGTM!

rintro rfl,
exact hn.left hx
end
by { rw coe_to_finset at hl, exact hn.pairwise_of_set_pairwise hl }

lemma pairwise_iff_coe_to_finset_pairwise (hn : l.nodup) (hs : symmetric r) :
(l.to_finset : set α).pairwise r ↔ l.pairwise r :=
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems we're missing the backward direction without the l.nodup condition, but maybe another PR ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No lemma should be stated in terms of (l.to_finset : set α) anymore anyway. I will remove these lemmas in a later PR.

src/data/list/nodup.lean Show resolved Hide resolved
src/group_theory/perm/cycle/basic.lean Outdated Show resolved Hide resolved
src/group_theory/perm/cycle/basic.lean Outdated Show resolved Hide resolved
src/group_theory/perm/cycle/basic.lean Outdated Show resolved Hide resolved
src/data/finset/noncomm_prod.lean Outdated Show resolved Hide resolved
src/data/finset/noncomm_prod.lean Outdated Show resolved Hide resolved
src/data/finset/noncomm_prod.lean Outdated Show resolved Hide resolved
Comment on lines +355 to +356
@[simp] lemma nodup.pairwise_coe [is_symm α r] (hl : l.nodup) :
{a | a ∈ l}.pairwise r ↔ l.pairwise r :=
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the name better as nodup.pairwise_coe_iff? Also we don't actually have a coercion from list to set now.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, I now wonder why finset.set.has_coe_t is not via a set_like instance. (Of course list and multiset can't have set_like instances since taking membership predicate isn't injective.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I prefer the name as is to match the general convention from list/multiset/finset of omitting the _iff quite eagerly. However I agree that the coe bit is a bit bad because there won't ever be a coercion, as all coercions are meant to be injective.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe we can just fix that in a later PR? This is very tangential to the current.

Copy link
Collaborator

Choose a reason for hiding this comment

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

all coercions are meant to be injective.

I don't think that's a universal rule? int.cast_coe certainly aren't always injective, and #16567 adds has_lift_t for algebras which also uses coe but isn't always surjective.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm... true, but I don't know of a non-injective coercion that's explicitly between concrete types, as is the case here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we can just fix that in a later PR? This is very tangential to the current.

I think so! (but it's indeed a new lemma introduced in this PR.)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually we have multiset.has_coe from list to multiset which is a quotient map, so it's surjective and seldom injective. There are many other examples of quotient maps as coercions in mathlib as well:
quotient_group.has_quotient.quotient.has_coe_t
quiver.weakly_connected_component.has_coe_t
add_circle.has_coe_t

So I don't see why we shouldn't make multiset.to_finset (also surjective) a coercion and then by transitivity we get coercion from list all the way down to set.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, I think the problem is that a ∈ m.to_finset isn't be defeq to a ∈ m for m : multiset α. Maybe that's why multiset.to_finset isn't a coercion. But we may still have coercions from multiset and list to set, even though they're neither injective nor surjective ...

@alreadydone
Copy link
Collaborator

maintainer merge

(By accident, this PR has never been marked awaiting-review, so probably not many people have looked at it, but I think it's good to go!)

@github-actions
Copy link

🚀 Pull request has been placed on the maintainer queue by alreadydone.

@kmill
Copy link
Collaborator

kmill commented Oct 14, 2022

It's a bit odd having this be tagged WIP, so let me delegate this to @YaelDillies to be sure they think it's ready to be merged!

bors d+

@bors
Copy link

bors bot commented Oct 14, 2022

✌️ YaelDillies 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 the delegated The PR author may merge after reviewing final suggestions. label Oct 14, 2022
@YaelDillies YaelDillies removed the WIP Work in progress label Oct 14, 2022
@YaelDillies
Copy link
Collaborator Author

Sorry! What happened is that it went from "PR I'm working on at night" to "quickly needed" without me noticing, and then I forgot to update the label. It's actually ready.

bors merge

bors bot pushed a commit that referenced this pull request Oct 14, 2022
Redefine the various `noncomm_prod`s using `set.pairwise`. This has the advantage of having a solid API around monotonicity in the set or in the relation and avoiding checking the trivial `i = j` case.
@bors
Copy link

bors bot commented Oct 15, 2022

Pull request successfully merged into master.

Build succeeded:

@bors bors bot changed the title refactor(data/finset/noncomm_prod): Use set.pairwise [Merged by Bors] - refactor(data/finset/noncomm_prod): Use set.pairwise Oct 15, 2022
@bors bors bot closed this Oct 15, 2022
@bors bors bot deleted the noncomm_prod_pairwise branch October 15, 2022 03:24
@eric-wieser eric-wieser added the hacktoberfest-accepted Without this label hacktoberfest is scared off by bors label Oct 29, 2022
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. hacktoberfest-accepted Without this label hacktoberfest is scared off by bors t-algebra Algebra (groups, rings, fields etc)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants