Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

[Merged by Bors] - feat(data/sym2) Defining the symmetric square (unordered pairs)#3264

Closed
kmill wants to merge 10 commits intomasterfrom
sym2
Closed

[Merged by Bors] - feat(data/sym2) Defining the symmetric square (unordered pairs)#3264
kmill wants to merge 10 commits intomasterfrom
sym2

Conversation

@kmill
Copy link
Collaborator

@kmill kmill commented Jul 1, 2020

This adds a type for the symmetric square of a type, which is the quotient of the cartesian square by permutations. These are also known as unordered pairs.

Additionally, this provides some definitions and lemmas for equalities, functoriality, membership, and a relationship between symmetric relations and terms of the symmetric square.

I preferred sym2 over unordered_pairs out of a combination of familiarity and brevity, but I could go either way for naming.


This adds a type for the symmetric square of a type, which is the
quotient of the cartesian square by permutations.  These are also
known as unordered pairs.

We provide some definitions and lemmas for equalities, functoriality,
and a relationship between symmetric relations and terms of the
symmetric square.
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.

Thank you for your pull request!

Do you have a particular use case for this file already? Generally you get a much better library if you work towards a particular goal, and add things that you need (and lemmas similar to those) than if you just start writing a library without a goal in mind.

For example, are mem and vmem both useful?

Incorporated suggestions from code review.
@kmill
Copy link
Collaborator Author

kmill commented Jul 2, 2020

Thank you for reviewing my PR @fpvandoorn!

Do you have a particular use case for this file already? Generally you get a much better library if you work towards a particular goal, and add things that you need (and lemmas similar to those) than if you just start writing a library without a goal in mind.

For example, are mem and vmem both useful?

I hope this PR didn't look quite so aimless! This library came from some work dealing with graphs over the last few weeks, and I figured I would try a PR with this before attempting the rest. Some of the lemmas in this file, though, are purely for well-definedness/uniqueness purposes to prove the definition is good, in that I think they let you work with each definition without expanding them.

The mem versus vmem thing is for computability reasons, and there's a part of the graph library that might or might not use vmem in the end. (Given a vertex and an incident edge, how do you get the vertex opposite the edge? If edges are terms of sym2 over the vertex type, and incidence is recorded with vmem, then you can compute that opposite vertex. Otherwise one needs additional assumptions.)

kmill added 2 commits July 1, 2020 18:55
Added a mention that one of the key definitions is `sym2.from_rel`,
which transforms a symmetric relation into set membership.

Also added a lemma that is useful for simple graphs.
Also reformatted the lemma statement.
@kmill
Copy link
Collaborator Author

kmill commented Jul 2, 2020

I just added documentation pointing to from_rel, which is sort of the reason behind this PR.

I also added a lemma I forgot to include, from_rel_irreflexive, which is that from_rel of a symmetric relation has no diagonal elements iff the relation is irreflexive. This has applications for simple graphs, and it makes use of is_diag. Hopefully it is OK adding it to this PR this time.

@fpvandoorn
Copy link
Member

I hope this PR didn't look quite so aimless! This library came from some work dealing with graphs over the last few weeks, and I figured I would try a PR with this before attempting the rest.

That's good! I also thought that this could be useful for graph theory.

Some of the lemmas in this file, though, are purely for well-definedness/uniqueness purposes to prove the definition is good, in that I think they let you work with each definition without expanding them.

That's indeed a good think to aim for!

The mem versus vmem thing is for computability reasons, and there's a part of the graph library that might or might not use vmem in the end. (Given a vertex and an incident edge, how do you get the vertex opposite the edge? If edges are terms of sym2 over the vertex type, and incidence is recorded with vmem, then you can compute that opposite vertex. Otherwise one needs additional assumptions.)

Yeah, vmem might be useful for computable functions.

Btw, the linter complains that it wants you to add an instance [inhabited \a] : inhabited (sym2 \a).

I just added documentation pointing to from_rel, which is sort of the reason behind this PR.

I also added a lemma I forgot to include, from_rel_irreflexive, which is that from_rel of a symmetric relation has no diagonal elements iff the relation is irreflexive. This has applications for simple graphs, and it makes use of is_diag. Hopefully it is OK adding it to this PR this time.

So for simple graphs isn't it easier to work with the type of unordered pairs where the two components are unequal (so the irreflexivity is built in)?
Though maybe this is better: make "simple graphs with loops" the basic object, and have a special class of simple graphs in those.

To do this in a clean way, defined symmetric powers in general and an
equivalence between two potential definitions (subtype of multisets,
or quotient of vectors).  The difference is whether the
cardinality/length condition is outside or inside the quotient.
@kmill
Copy link
Collaborator Author

kmill commented Jul 2, 2020

Btw, the linter complains that it wants you to add an instance [inhabited \a] : inhabited (sym2 \a).

Ok, I'll look into that. I was going to ask how to deal with this linter warning.

So for simple graphs isn't it easier to work with the type of unordered pairs where the two components are unequal (so the irreflexivity is built in)?
Though maybe this is better: make "simple graphs with loops" the basic object, and have a special class of simple graphs in those.

I've found it to be really hard to say what's better than what when defining graphs, since people use them for all sorts of things (and as for me, I tend to use multigraphs exclusively, or sometimes simple graphs allowing loops). Perhaps it's worth defining a symmetric square with deleted diagonal, but at least {x : sym2 α // ¬is_diag x} is equivalent.

Copy link
Member

@jcommelin jcommelin left a comment

Choose a reason for hiding this comment

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

Looks good to me! Some minor stylistic issues, but I think after that this is ready for merging.
@fpvandoorn Do you have further comments?

@bryangingechen bryangingechen added the awaiting-review The author would like community review of the PR label Jul 5, 2020
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.

Looking good, including all additions.

Feel free to merge it after incorporating my comments (or let someone else do it if you're unsure).

bors d+

@bors
Copy link

bors bot commented Jul 6, 2020

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

@fpvandoorn
Copy link
Member

bors merge

@github-actions github-actions bot added ready-to-merge All that is left is for bors to build and merge this PR. (Remember you need to say `bors r+`.) and removed awaiting-review The author would like community review of the PR labels Jul 6, 2020
bors bot pushed a commit that referenced this pull request Jul 6, 2020
This adds a type for the symmetric square of a type, which is the quotient of the cartesian square by permutations.  These are also known as unordered pairs.

Additionally, this provides some definitions and lemmas for equalities, functoriality, membership, and a relationship between symmetric relations and terms of the symmetric square.

I preferred `sym2` over `unordered_pairs` out of a combination of familiarity and brevity, but I could go either way for naming.
@bors
Copy link

bors bot commented Jul 6, 2020

Pull request successfully merged into master.

Build succeeded:

@bors bors bot changed the title feat(data/sym2) Defining the symmetric square (unordered pairs) [Merged by Bors] - feat(data/sym2) Defining the symmetric square (unordered pairs) Jul 6, 2020
@bors bors bot closed this Jul 6, 2020
@bors bors bot deleted the sym2 branch July 6, 2020 17:28
@kim-em
Copy link
Collaborator

kim-em commented Jul 9, 2020

Oops, we probably shouldn't leave import tactic in files going into mathlib. I'll clean this up elsewhere.

cipher1024 pushed a commit to cipher1024/mathlib that referenced this pull request Mar 15, 2022
…prover-community#3264)

This adds a type for the symmetric square of a type, which is the quotient of the cartesian square by permutations.  These are also known as unordered pairs.

Additionally, this provides some definitions and lemmas for equalities, functoriality, membership, and a relationship between symmetric relations and terms of the symmetric square.

I preferred `sym2` over `unordered_pairs` out of a combination of familiarity and brevity, but I could go either way for naming.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

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.

5 participants