Skip to content

feat(Combinatorics/HypergraphLike): add HypergraphLike class - #40204

Open
Jun2M wants to merge 31 commits into
leanprover-community:masterfrom
Jun2M:GraphLikeInc
Open

Jun2M wants to merge 31 commits into
leanprover-community:masterfrom
Jun2M:GraphLikeInc

Conversation

@Jun2M

@Jun2M Jun2M commented Jun 4, 2026 •

Copy link
Copy Markdown
Collaborator

Introduces HypergraphLike V I E G, an object-indexed incidence interface for developing common graph theory across different representations.

Defines links and adjacency, incidence maps and fibers, and sets of incident vertices and edges. The basic API provides membership characterizations, fiber disjointness and union identities, and relationships between incidence data, links, and adjacency.

Codex assisted with the initial implementation and review; the code was subsequently revised by me.

The following is a longer write-up about what this PR is for, what this PR has, and why it is in this shape.

Considerations

  1. The main consideration for this PR is to create a common language different graph types can use to communicate their structure. The data in the type class is deliberately chosen to be as general as possible, accommodating hypergraphs, digraphs, simple graphs, and more.

  2. (Hyper)Graphs are used both as a setting in which vertices, edges, walks, and colorings live, and as an algebraic object that can be modified. These two viewpoints can sometimes be at odds with each other. This typeclass is an acknowledgement that these two viewpoints are different, and both need to be fully supported separately with explicit connection. HypergraphLike is the way to view a graph as a setting. Various different graph structures are ways to view a graph as an algebraic object.

  3. Graph theory has a lot of uses outside of graph theory. For example, group theory, topology, and more. The type class is designed to be easily applied to an arbitrary object that can be associated with a graph structure.

Contents

The definition consists of:

Data Meaning
V, I, E Ambient types of vertex, incidence, and edge labels
V(G), I(G), E(G) The set of objects of the (hyper)graph structure
attach', edgeMap' The vertex and edge assigned to each incidence
IsSource, IsTarget The directions in which an incidence can be traversed

Every incidence is a source, a target, or both. This allows directed and undirected incidences in the same object. Distinct incidences may belong to the same vertex and edge.

HypergraphLike does not require the object to be a graph or hypergraph, or to be related to one. Any object can be associated with a (hyper)graph structure and use the graph theory API as such via a HypergraphLike instance. As a result, it is possible for an arbitrary object to be associated with a graph structure that it has nothing to do with.

  • Link G e u v: a traversal of e from u to v, retaining a source incidence and a distinct target incidence. Distinctness prevents entering and leaving an undirected edge through the same incidence.
  • IsLink and Adj: the existence of a link through a specified edge, and the existence of an edge linking two vertices.
  • attach and edgeMap: total extensions of the incidence maps when the corresponding types are nonempty.
  • edgeFiber and vertexFiber: the incidences belonging to an edge or vertex.
  • incVerts and incEdges: the vertices incident to an edge and the edges incident to a vertex.

Apart from operations, graph API should be built on this type class. More specialized theories can add assumptions such as undirectedness, looplessness, or restrictions on the incidences of each edge. See PRs #43768, #43748 and more to come.

Design decisions

Why not require one concrete representation?

Alternative approach to unify various graph structures is to have one very general hypergraph definition and put all possible API there. By extending the definition with other conditions, you can inherit all the API while describing the graph class you want.

This is not used here because

  1. It either loses the expected extensionality or restricts which representations can use the API.
  2. The API can be inherited using the current instance method more generally (you don't need to extend the particular def to inherit them)
  3. These two approaches have virtually no difference in formalization cost.

Asterisk for number 3 is that I have not tried to formalize every part of graph theory so it should be taken with a grain of salt. Nevertheless, I have not found cases where extend method reduces the formalization cost significantly.

The generality of application is the strong suit of the current approach. The discussion that led to this PR started with efforts to unify different graph structures in Mathlib and future structures to be implemented. The instance method allows even more flexibility. We could talk about a group (with a chosen generating set) being HypergraphLike by associating it with a Cayley graph, a CW complex with its 1-skeleton graph, or a lattice with its Hasse graph, in the same manner SimpleGraph is HypergraphLike. With extend, these will require a separate, bespoke association with the appropriate graph structure.

So, it suffices to argue that number 1 is true. The difficulty comes from the fact that the child structures have to contain additional data and therefore additional freedom that it really doesn't need. Consider two simple graphs G and H, each with vertex set {u, v} and single edge between them. In the naive approach where you define SimpleGraph like this:

structure SimpleGraph (ν ι ε : Type*) extends undirected ν ι ε, noMultiEdges ν ι ε ... where

Then, G = H may not hold. They could have different edge type, incidence type, edge set, incidence set, etc. That is, we have extensionality issue.

The fix is to constrain further until simple graph structure uniquely determines the rest. Here is one possible definition:

structure SimpleGraph (ν : Type*) extends undirected ν (ν × ν) (Sym2 ν), noMultiEdges ν (ν × ν) (Sym2 ν) ... where
  edgeMap'_eq (i) : edgeMap' i = Sym2.mk i.val.fst i.val.snd
  attach'_eq (i) : attach' i = i.val.fst

Now, any multigraph that happens to be a simple graph cannot use SimpleGraph results without going through the normalization function, showing that normalization only changed the labels and showing that the normalization function preserves whatever properties, etc. Results that depend on simplicity should be available for arbitrary incidence representations satisfying simplicity, rather than only for a canonical SimpleGraph representation. This happens every time a canonical form is chosen to resolve extensionality issues.

Why per-object indexing?

Indexing by graph type was something I have adopted from HasAdj PR (#35776) without critical thinking. In the discussion for Quiver (#45034), as soon as I wrote "HypergraphLike expects you to know the edge type before you know what graph you are working with.", I started to think why this is necessary. It is not.

All the code I have about HypergraphLike can be migrated to per-object indexing very easily. The statements did get longer due to adding HypergraphLike instance to each graph object but virtually all proofs worked without any changes.

Philosophically, it makes the role of HypergraphLike clearer. HypergraphLike is defined to have one common language between different graph structures and that common language is the label types and incidence data. Merely belonging to the same Lean type should not impose additional uniformity. Where a result needs shared labels or compatible incidence maps, it can state those requirements explicitly.

In the cases of Quiver, it can be supported by HypergraphLike as now we supply the edge type along with the specific Quiver instance, not before.

Another benefit is that you can use HypergraphLike even when not all elements of a type can be interpreted as a graph. This aligns with the rest of the type class hierarchy being built on HypergraphLike. (#43768, #43748) G : Graph V E could happen to be a simple graph. A subset of a plane could be graph-like.

Why ambient labels and support sets?

The id function holds a special place in our heads. Consider G, K4 graph with vertex set {1, 2, 3, 4}, and H, K5 graph with vertex set {1, 2, 3, 4, 5}. Remove edge s(1, 2) from H. Up to isomorphism, G is still a subgraph of H. But, with respect to the id function, G is no longer a subgraph of H.

Without support sets, the vertex set is the whole type, so graphs on different vertex sets live on different types. Then only embeddings can be stated, and you lose the labelled subgraph relation. That is, without some special treatment for subtypes, HypergraphLike will say G is a subgraph of H as there exists embedding of G into H.

Support sets in the type class are exactly the mechanism that allows "special treatment" for subtypes.

Related work (Not dependency)

Co-authored-by: OpenAI Codex [email protected]


Open in Gitpod

@github-actions

github-actions Bot commented Jun 4, 2026 •

Copy link
Copy Markdown

PR summary 2e866b5759

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference
Mathlib.Combinatorics.HypergraphLike.Basic (new file) 362

Declarations diff (regex)

+ Adj
+ Adj.left_mem_vertexSet
+ Adj.right_mem_vertexSet
+ HypergraphLike
+ IsLink
+ IsLink.adj
+ IsLink.edge_mem_edgeSet
+ IsLink.left_mem_incVerts
+ IsLink.left_mem_vertexSet
+ IsLink.mem_incEdges_left
+ IsLink.mem_incEdges_right
+ IsLink.right_mem_incVerts
+ IsLink.right_mem_vertexSet
+ IsSource.mem_incs
+ IsTarget.mem_incs
+ Link
+ Link.attach_source
+ Link.attach_target
+ Link.edgeMap_source
+ Link.edgeMap_target
+ Link.edge_mem_edgeSet
+ Link.isLink
+ Link.left_mem_vertexSet
+ Link.right_mem_vertexSet
+ adj_iff_exists_incidence
+ attach
+ attach_mem_incVerts
+ attach_mem_verts
+ biUnion_edgeFiber
+ biUnion_vertexFiber
+ edgeFiber
+ edgeFiber_eq_inter_preimage
+ edgeFiber_of_notMem_edges
+ edgeFiber_subset_incs
+ edgeMap
+ edgeMap_mem_edges
+ edgeMap_mem_incEdges
+ edges_nonempty_of_incs_nonempty
+ iUnion_edgeFiber
+ iUnion_vertexFiber
+ incEdges
+ incEdges_eq_empty
+ incEdges_eq_image
+ incEdges_nonempty
+ incEdges_of_notMem_verts
+ incEdges_subset_edges
+ incVerts
+ incVerts_eq_empty
+ incVerts_eq_image
+ incVerts_nonempty
+ incVerts_of_notMem_edges
+ incVerts_subset_verts
+ incs_eq_empty_of_edges_eq_empty
+ incs_eq_empty_of_verts_eq_empty
+ isLink_attach
+ isLink_iff_exists_incidence
+ mem_edgeFiber
+ mem_edges_of_mem_edgeFiber
+ mem_edges_of_mem_incVerts
+ mem_incEdges
+ mem_incEdges_iff_exists_incidence
+ mem_incVerts_iff_exists_incidence
+ mem_vertexFiber
+ mem_verts_of_mem_incEdges
+ mem_verts_of_mem_vertexFiber
+ not_adj_of_left_notMem_verts
+ not_adj_of_right_notMem_verts
+ not_isLink_of_notMem_edges
+ pairwise_disjoint_edgeFiber
+ pairwise_disjoint_vertexFiber
+ val_attach'
+ val_edgeMap'
+ vertexFiber
+ vertexFiber_eq_inter_preimage
+ vertexFiber_of_notMem_verts
+ vertexFiber_subset_incs
+ verts_nonempty_of_incs_nonempty

You can run this locally as follows
## from your `mathlib4` directory:
git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci

## summary with just the declaration names:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh <optional_commit>

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

The doc-module for scripts/pr_summary/declarations_diff.sh in the mathlib-ci repository contains some details about this script.

Declarations diff (Lean)

✅ Lean-aware diff — post-build, computed from the Lean environment (commit 2e866b5).

  • +122 new declarations
  • −0 removed declarations
+HypergraphLike
+HypergraphLike.Adj
+HypergraphLike.Adj.left_mem_vertexSet
+HypergraphLike.Adj.right_mem_vertexSet
+HypergraphLike.IsLink
+HypergraphLike.IsLink.adj
+HypergraphLike.IsLink.edge_mem_edgeSet
+HypergraphLike.IsLink.left_mem_incVerts
+HypergraphLike.IsLink.left_mem_vertexSet
+HypergraphLike.IsLink.mem_incEdges_left
+HypergraphLike.IsLink.mem_incEdges_right
+HypergraphLike.IsLink.right_mem_incVerts
+HypergraphLike.IsLink.right_mem_vertexSet
+HypergraphLike.IsSource
+HypergraphLike.IsSource.mem_incs
+HypergraphLike.IsTarget
+HypergraphLike.IsTarget.mem_incs
+HypergraphLike.Link
+HypergraphLike.Link.attach'_source
+HypergraphLike.Link.attach'_target
+HypergraphLike.Link.attach_source
+HypergraphLike.Link.attach_target
+HypergraphLike.Link.casesOn
+HypergraphLike.Link.ctorIdx
+HypergraphLike.Link.edgeMap'_source
+HypergraphLike.Link.edgeMap'_target
+HypergraphLike.Link.edgeMap_source
+HypergraphLike.Link.edgeMap_target
+HypergraphLike.Link.edge_mem_edgeSet
+HypergraphLike.Link.ext
+HypergraphLike.Link.ext_iff
+HypergraphLike.Link.isLink
+HypergraphLike.Link.isSource_source
+HypergraphLike.Link.isTarget_target
+HypergraphLike.Link.left_mem_vertexSet
+HypergraphLike.Link.mk
+HypergraphLike.Link.mk.inj
+HypergraphLike.Link.mk.injEq
+HypergraphLike.Link.mk.noConfusion
+HypergraphLike.Link.mk.sizeOf_spec
+HypergraphLike.Link.noConfusion
+HypergraphLike.Link.noConfusionType
+HypergraphLike.Link.rec
+HypergraphLike.Link.recOn
+HypergraphLike.Link.right_mem_vertexSet
+HypergraphLike.Link.source
+HypergraphLike.Link.source_ne_target
+HypergraphLike.Link.target
+HypergraphLike.adj_iff_exists_incidence
+HypergraphLike.attach
+HypergraphLike.attach'
+HypergraphLike.attach.congr_simp
+HypergraphLike.attach_mem_incVerts
+HypergraphLike.attach_mem_verts
+HypergraphLike.biUnion_edgeFiber
+HypergraphLike.biUnion_vertexFiber
+HypergraphLike.casesOn
+HypergraphLike.ctorIdx
+HypergraphLike.edgeFiber
+HypergraphLike.edgeFiber_eq_inter_preimage
+HypergraphLike.edgeFiber_of_notMem_edges
+HypergraphLike.edgeFiber_subset_incs
+HypergraphLike.edgeMap
+HypergraphLike.edgeMap'
+HypergraphLike.edgeMap.congr_simp
+HypergraphLike.edgeMap_mem_edges
+HypergraphLike.edgeMap_mem_incEdges
+HypergraphLike.edges
+HypergraphLike.edges_nonempty_of_incs_nonempty
+HypergraphLike.iUnion_edgeFiber
+HypergraphLike.iUnion_vertexFiber
+HypergraphLike.incEdges
+HypergraphLike.incEdges_eq_empty
+HypergraphLike.incEdges_eq_image
+HypergraphLike.incEdges_nonempty
+HypergraphLike.incEdges_of_notMem_verts
+HypergraphLike.incEdges_subset_edges
+HypergraphLike.incVerts
+HypergraphLike.incVerts_eq_empty
+HypergraphLike.incVerts_eq_image
+HypergraphLike.incVerts_nonempty
+HypergraphLike.incVerts_of_notMem_edges
+HypergraphLike.incVerts_subset_verts
+HypergraphLike.incs
+HypergraphLike.incs_eq_empty_of_edges_eq_empty
+HypergraphLike.incs_eq_empty_of_verts_eq_empty
+HypergraphLike.isLink_attach
+HypergraphLike.isLink_iff_exists_incidence
+HypergraphLike.mem_edgeFiber
+HypergraphLike.mem_edges_of_mem_edgeFiber
+HypergraphLike.mem_edges_of_mem_incVerts
+HypergraphLike.mem_incEdges
+HypergraphLike.mem_incEdges_iff_exists_incidence
+HypergraphLike.mem_incVerts_iff_exists_incidence
+HypergraphLike.mem_incs_iff
+HypergraphLike.mem_vertexFiber
+HypergraphLike.mem_verts_of_mem_incEdges
+HypergraphLike.mem_verts_of_mem_vertexFiber
+HypergraphLike.mk
+HypergraphLike.mk.noConfusion
+HypergraphLike.noConfusion
+HypergraphLike.noConfusionType
+HypergraphLike.not_adj_of_left_notMem_verts
+HypergraphLike.not_adj_of_right_notMem_verts
+HypergraphLike.not_isLink_of_notMem_edges
+HypergraphLike.pairwise_disjoint_edgeFiber
+HypergraphLike.pairwise_disjoint_vertexFiber
+HypergraphLike.rec
+HypergraphLike.recOn
+HypergraphLike.val_attach'
+HypergraphLike.val_edgeMap'
+HypergraphLike.vertexFiber
+HypergraphLike.vertexFiber_eq_inter_preimage
+HypergraphLike.vertexFiber_of_notMem_verts
+HypergraphLike.vertexFiber_subset_incs
+HypergraphLike.verts
+HypergraphLike.verts_nonempty_of_incs_nonempty
+HypergraphLike.«termE(_)»
+HypergraphLike.«termI(_)»
+HypergraphLike.«termV(_)»
+HypergraphLike.«term_~[_;_]_»
+HypergraphLike.«term_~[_]_»

No changes to strong technical debt.

Increase in weak tech debt: (relative, absolute) = (1.00, 0.00)
Current number Change Type (weak)
5159 1 exposed public sections

Current commit 2e866b5759
Reference commit f5df3eeab4

This script lives in the mathlib-ci repository. To run it locally, from your mathlib4 directory:

git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci
../mathlib-ci/scripts/reporting/technical-debt-metrics.py 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 commented Jun 4, 2026 •

Copy link
Copy Markdown

✅ PR Title Formatted Correctly

The title of this PR has been updated to match our commit style conventions.
Thank you!

@Jun2M Jun2M changed the title feat(Combinatorics): Incidence-based HypergraphLike class feat(Combinatorics): incidence-based HypergraphLike class Jun 4, 2026
@Jun2M
Jun2M temporarily deployed to cache-upload-forks June 4, 2026 02:04 — with GitHub Actions Inactive
@Jun2M
Jun2M temporarily deployed to cache-upload-forks June 4, 2026 03:33 — with GitHub Actions Inactive
@b-mehta b-mehta self-assigned this Jul 25, 2026
@tb65536 tb65536 added the LLM-generated PRs with substantial input from LLMs - review accordingly label Aug 25, 2026
@tb65536

tb65536 commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

This PR definitely needs to be split up.

@YaelDillies YaelDillies removed the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown

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

@mathlib-triage mathlib-triage Bot added the maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. label Oct 6, 2026
@SnirBroshi

Copy link
Copy Markdown
Collaborator

🎉

Does this mean we're not doing SimpleGraph extends Digraph and such? What changed from #36743 (comment)?

@Jun2M
Jun2M requested a review from b-mehta October 8, 2026 02:08
@YaelDillies

Copy link
Copy Markdown
Contributor

Does this mean we're not doing SimpleGraph extends Digraph and such?

No, the question of whether SimpleGraph should exist as a type is (mostly) orthogonal. The current PR is about moving as much API as possible away from SimpleGraph, but it cannot move away the operations.

@SnirBroshi

Copy link
Copy Markdown
Collaborator

The algebraic hierarchy uses extends everywhere, so I thought the plan was to try to do the same for a graph hierarchy (including hypergraphs, multigraphs, digraphs), then everything including the operations could be generalized.

Should this be called GraphLike btw? (this is an alternative to the original GraphLike, right?)

@YaelDillies

Copy link
Copy Markdown
Contributor

As explained in plenty of places by now, the graph hierarchy will look pretty different from the algebraic hierarchy because graphs can be modified much more flexibly than algebraic structures. The parallel is therefore of limited interest.

How would you generalise the operations? We don't have a general map operation for subobject, even in algebra.

@SnirBroshi

Copy link
Copy Markdown
Collaborator

The point isn't to imitate the algebraic hierarchy, but since it works great for algebra then it might work great for graphs. Indeed there are differences, but I thought unifying objects and subobjects (aka having vertex sets) solves the issues.
I'm partial to both approaches, but I'm want to understand why you seemingly changed your opinion. Have we ruled out the extends approach?

How would you generalise the operations? We don't have a general map operation for subobject, even in algebra.

Hmm actually I'm not sure. But I think operations on walks might be, and possibly regardless of which approach we take.

@YaelDillies

Copy link
Copy Markdown
Contributor

Ah you mean why not define Hypergraph directly instead of HypergraphLike? This is a valid question. I believe it is mostly to avoid having eg the useless IsSource/IsTarget fields when dealing with a type of undirected graphs.

@Jun2M

Jun2M commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator Author

The algebraic hierachy does two things:

  1. All algebraic structure goes in the typeclass and allow any type to have a ring or semigroup rather than having something like
    structure Semigroup' (X : Type*) : Type _ where
    mul : X → X → X
    mul_assoc (x y z) : mul (mul x y) z = mul x (mul y z)
  2. The algebraic typeclasses are built using extends heavily

So my first question is, why is extending a structure directly being described as closer to algebraic hierachy than this HypergraphLike typeclass which can then be extended or composed to describe graphs, undirectedness, simple or loopless. This is of course not an argument. This does not show any merit of this approach or disadvantage of that approach. But it is something I don't quite understand.

@Jun2M

Jun2M commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator Author

The way I see it, the question here is whether we want a typeclass description or a structure that we know it has the (hyper)graph structure and nothing else. Both approaches can use extend and that question belongs in the next PR that extends this PR (pun intended). Or rather, this PR does not settle which concrete graph structures should extend which others.

I think the second approach could work, although I would need to experiment with it. The tradeoff I see is between the applicability to arbitrary types and ability to describe/generalize operations. Typeclass does not care which type you feed it as "supposedly graph type", as long as you supply the association with a graph structure. That means we could talk about a group (with a chosen generating set) being "HypergraphLike" by associating with a caley graph, CW complex with 1-skeleton graph or a lattice with hasse graph. The loss here is ability to describe operations: deleting one edge from a Caley graph need not produce another Cayley graph. Thus a common interface can expose graph-theoretic data and support theorems without promising that every graph operation returns another object of the original type.

I would argue we should have both. In fact, my later PR 43684 is defining undirected multigraph with extending undirected hypergraph. That said, I don't think I would argue for extending directed graph to define simple graph. I would argue for extending multigraph instead.

@Jun2M

Jun2M commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator Author

This is indeed an alternative to GraphLike. I don't have a strong attachment to names so I can change it if people want. I did recently learn that there is graphlike space and graphlike continuum used by math literature already and relevant to matroids, area I work with. (link.springer.com/article/10.1007/s00493-014-3079-2). Naming is hard.

@SnirBroshi

Copy link
Copy Markdown
Collaborator

I believe it is mostly to avoid having eg the useless IsSource/IsTarget fields when dealing with a type of undirected graphs.

Yeah useless fields were part of the reason we wanted to go with a class approach in the first place, but custom constructors can avoid them.
IIRC we we're more worried about Walk becoming annoying, since destructing walks is very common. Although maybe custom recursors / match_patterns would help.
But those reasons we're already discussed before. I'm still interested in the reasons to avoid something like SimpleGraph extends Digraph extends MultiDigraph extends MultiHyperDigraph etc.

I would argue we should have both.

Oh based on #37878 (comment) I thought it was one or the other. Interesting! In that case doing both sounds great!

I don't think I would argue for extending directed graph to define simple graph. I would argue for extending multigraph instead.

Like the algebraic hierarchy I thought we could extends multiple things, so there would be some base (directed) Hypergraph (probably defined very similar to HypergraphLike) and all the other kinds would just add proof fields. So SimpleGraph could extend Hypergraph & UndirectedGraph & LooplessGraph, etc.
Of course this design is off the top of my head and not thought out, but I thought the plan was to think it out.

@SnirBroshi

Copy link
Copy Markdown
Collaborator

This is indeed an alternative to GraphLike. I don't have a strong attachment to names so I can change it if people want.

I'd prefer the name GraphLike, as it is the basis of all types of graphs (hyper/multi/directed/loopless/...). But we should probably wait for other opinions before renaming.

@Jun2M

Jun2M commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator Author

What you described works. I was just saying A to communicate B.

I am not very good at communicating my ideas even when they really should be. What I failed to explain by saying, probably not "extending directed graph to define simple graph", is that there are two incompatible ways to go between directed and undirected edge.

  1. Take two directed edges going opposite way and group them into one undirected edge.
  2. Take a directed edge and forget about the direction.

The HypergraphLike uses the second method using IsTarget and IsSource. This method generalize very well to hypergraphs. However, with the first approach, an hyperedge with order n is a quotient of n choose 2 directed edges? some grouping of directed hyperedges that covers all ordered pairs of vertices?

The other classes going on top of `HypergraphLike` are already defined
per graph, instead of a whole type as it was originally defined. This
commit changes the def of `HypergraphLike` to be per graph, matching
them.

This allows supporting `Quiver` as-is.

@YaelDillies YaelDillies left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am not sure I understand why you would perform this last change. IMO Quiver is misdesigned and should be changed, instead of HypergraphLike jumping through more hoops.

Regardless, your PR description is now outdated and should also be expanded to explain why a per-graph class is better than a per-type one. It would also be nice to explain why HypergraphLike is better than having all graph types extend Hypergraph.

@YaelDillies YaelDillies added awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. and removed maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. labels Oct 23, 2026
@Jun2M

Jun2M commented Oct 24, 2026

Copy link
Copy Markdown
Collaborator Author

@YaelDillies, I am sorry I made the change after maintainer merge tag was applied. If I had considered the PR more carefully, I would've made the change earlier. That is to say, I am not making the change solely to support Quiver. I truly believe that per graph definition is better.
I have ended up writing a whole essay in the PR description, I am sorry. I have tried my best to lay out my thoughts as clearly as possible. I thought many problems so far has been due to not enough communication. Please let me know if I have swung too far to the other direction.

@Jun2M Jun2M removed the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Oct 24, 2026

@YaelDillies YaelDillies left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Okay, I am convinced! A good example you didn't mention for why per-object indexing is useful is that of a group being considered as its Cayley graph: The group has type Type _ and one cannot write a HypergraphLike instance on Type, you further need the data of the group and its generators.

maintainer merge

@github-actions

Copy link
Copy Markdown

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

@mathlib-triage mathlib-triage Bot added the maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. label Oct 24, 2026
@artie2000

Copy link
Copy Markdown
Collaborator

maintainer merge

pinging as requested

@github-actions

Copy link
Copy Markdown

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


lemma IsTarget.mem_incs (h : IsTarget G i) : i ∈ I(G) := mem_incs_iff.mpr (Or.inr h)

/-- A link from `u` to `v` through `e`, retaining its ordered pair of distinct incidences. -/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we have a little more for this docstring? Alternatively, mentioning in the module doc would be nice. Currently, if a reader doesn't know what "link" means, the docstring doesn't give them any help!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@b-mehta, I am now thinking that maybe "Link" and "IsLink" is not a suitable name for what they are about, in particular, they sound too undirected.
I think "Step"&"HasStep" or "Dart"&"HasDart" (with clear docs about how the name "dart" differ from "incidence" in hypergraph) would be a better name. If you give a thumbs up, I will make a quick renaming change.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I have docs update to explain the terminology. If Link is fine, it is ready for merge.

This branch was previously deployed

1 inactive (outdated) deployment
cache-upload-forks — 1e926cca Deployed Jun 4, 2026 by Jun2M via ci (fork) / Upload to cache #302723
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LLM-generated PRs with substantial input from LLMs - review accordingly maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. t-combinatorics Combinatorics

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants