Skip to content

feat(Combinatorics): define undirected hypergraphs#28613

Open
espottesmith wants to merge 61 commits intoleanprover-community:masterfrom
espottesmith:undirhyper
Open

feat(Combinatorics): define undirected hypergraphs#28613
espottesmith wants to merge 61 commits intoleanprover-community:masterfrom
espottesmith:undirhyper

Conversation

@espottesmith
Copy link
Copy Markdown

This PR defines undirected hypergraphs:

@[ext]
structure Hypergraph (α : Type*) where
  /-- The vertex set -/
  vertexSet : Set α
  /-- The hyperedge set -/
  hyperedgeSet : Set (Set α)
  /-- All hyperedges must be subsets of the vertex set -/
  hyperedge_isSubset_vertexSet : ∀ ⦃e⦄, e ∈ hyperedgeSet → e ⊆ vertexSet

In addition to the main definition, some additional definitions and related lemmas are provided:

  • vertex adjacency
  • hyperedge adjacency
  • vertex "stars"
  • special cases (loops, empty hypergraphs, trivial hypergraphs, complete hypergraphs, simple hypergraphs, k-uniform hypergraphs, and d-regular hypergraphs)
  • (some) hypergraph cardinality
  • subhypergraphs, induced subhypergraphs, and partial hypergraphs

This implementation is certainly bare-bones. I'm submitting this PR at this point, rather than when my developments are more fleshed out, because there has been some interest in others contributing to hypergraph formalization in mathlib.

In the near future, goals include:

  • defining incidence matrices (i.e., conversion from Hypergraph α to Matrix α (Set α) β
  • coersion/generalization of graph as 2-uniform hypergraph
  • conversion of a hypergraph into its associated clique graph/two-section graph
  • constructing the dual of a hypergraph (note: on first blush, this appears somewhat challenging, given that we define hyperedges as Set α rather than some other type β)
  • rank and co-rank
  • walks, paths, cycles, etc. on hypergraphs

Open in Gitpod

@github-actions github-actions bot added new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! t-combinatorics Combinatorics labels Aug 18, 2025
@github-actions
Copy link
Copy Markdown

github-actions bot commented Aug 18, 2025

PR summary 2e36a1dbb4

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference
Mathlib.Combinatorics.Hypergraph.Basic (new file) 742

Declarations diff

+ Adj
+ Adj.symm
+ EAdj
+ EAdj.exists_vertex
+ EAdj.inter_nonempty
+ EAdj.symm
+ Hypergraph
+ IsComplete
+ IsEmpty
+ IsEmpty.eq
+ IsEmpty.not_isNonempty
+ IsEmpty.not_mem
+ IsIsolated
+ IsLoop
+ IsNonempty
+ IsNonempty.not_isEmpty
+ IsTrivial
+ _root_.Membership.mem.subset_vertexSet
+ adj_comm
+ coe_nonempty
+ completeOn
+ completeOn_isNonempty
+ completeOn_not_isTrivial
+ eAdj_comm
+ edgeSet_subset_powerset_vertexSet
+ edge_isSubset_vertexSet
+ edge_not_mem_empty
+ edge_not_mem_trivial
+ emptyHypergraph
+ forall_of_forall_verts
+ image
+ image_image
+ image_mem_image
+ isComplete_completeOn
+ isComplete_not_isEmpty
+ isComplete_not_isTrivial
+ isEmpty_empty_hypergraph
+ isEmpty_eq_empty_hypergraph
+ isEmpty_iff_forall_not_mem
+ isEmpty_or_isNonempty
+ isLoop_encard_one
+ mem_completeOn
+ mem_image
+ mem_vertexSet_of_mem_edgeSet
+ not_exists_isolated_vertex_iff_sUnion_edgeSet_eq_vertexSet
+ not_isEmpty
+ not_isEmpty_trivial_hypergraph
+ not_isNonempty
+ sUnion_edgeSet_subset_vertexSet
+ star
+ stars
+ trivialHypergraph

You can run this locally as follows
## summary with just the declaration names:
./scripts/pr_summary/declarations_diff.sh <optional_commit>

## more verbose report:
./scripts/pr_summary/declarations_diff.sh long <optional_commit>

The doc-module for scripts/pr_summary/declarations_diff.sh contains some details about this script.


No changes to technical debt.

You can run this locally as

./scripts/reporting/technical-debt-metrics.sh pr_summary
  • The relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).

@github-actions github-actions bot removed the awaiting-CI This PR does not pass CI yet. This label is automatically removed once it does. label Aug 24, 2025
@mathlib4-merge-conflict-bot mathlib4-merge-conflict-bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Aug 28, 2025
@mathlib4-merge-conflict-bot
Copy link
Copy Markdown
Collaborator

This pull request has conflicts, please merge master and resolve them.

@github-actions github-actions bot removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Aug 29, 2025
@b-mehta
Copy link
Copy Markdown
Contributor

b-mehta commented Sep 2, 2025

Just to note that this is marked awaiting-author for the comments above, once those are fixed you can remove the tag by commenting "-awaiting-author".

Copy link
Copy Markdown
Collaborator

@jt496 jt496 left a comment

Choose a reason for hiding this comment

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

This looks good. It will be great to have Hypergraphs in mathlib!

I know this was already raised but I also prefer "edgeSet" to "hyperedgeSet" on the basis that "hyperedges" are almost always referred to as "edges" and it will make theorem names a little shorter. (Also why E(H) if they are hyperedges?)

@espottesmith
Copy link
Copy Markdown
Author

Thanks for the heads up, @b-mehta. I still wanted to look a bit more deeply into using simp, as @lauramonk had suggested, before I claimed to be totally done.

And thanks for your comments, @jt496. I disagree that hyperedges are usually called edges (at least in the papers I read, they're frequently referred to as "hyperedges", even if the E(H) notation is used). But, since multiple folks have brought this up, I'm happy acquiescing.

@espottesmith
Copy link
Copy Markdown
Author

-awaiting-author

@github-actions github-actions bot removed the awaiting-author A reviewer has asked the author a question or requested changes. label Sep 5, 2025
@mathlib4-merge-conflict-bot mathlib4-merge-conflict-bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Nov 19, 2025
@mathlib4-merge-conflict-bot
Copy link
Copy Markdown
Collaborator

This pull request has conflicts, please merge master and resolve them.

@github-actions github-actions bot removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Nov 19, 2025
@mathlib4-merge-conflict-bot mathlib4-merge-conflict-bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Dec 10, 2025
@mathlib4-merge-conflict-bot
Copy link
Copy Markdown
Collaborator

This pull request has conflicts, please merge master and resolve them.

@github-actions github-actions bot removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! t-combinatorics Combinatorics

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants