Repository navigation
Conversation
PR summary 2e866b5759Import changes for modified filesNo significant changes to the import graph Import changes for all files
|
| 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
relativevalue is the weighted sum of the differences with weight given by the inverse of the current value of the statistic. - The
absolutevalue is therelativevalue divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).
✅ PR Title Formatted CorrectlyThe title of this PR has been updated to match our commit style conventions. |
HypergraphLike class
|
This PR definitely needs to be split up. |
|
🚀 Pull request has been placed on the maintainer queue by YaelDillies. |
|
🎉 Does this mean we're not doing |
No, the question of whether |
|
The algebraic hierarchy uses Should this be called |
|
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 |
|
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.
Hmm actually I'm not sure. But I think operations on walks might be, and possibly regardless of which approach we take. |
|
Ah you mean why not define |
|
The algebraic hierachy does two things:
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. |
|
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 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 |
|
This is indeed an alternative to |
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.
Oh based on #37878 (comment) I thought it was one or the other. Interesting! In that case doing both sounds great!
Like the algebraic hierarchy I thought we could |
I'd prefer the name |
|
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.
The |
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
left a comment
There was a problem hiding this comment.
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, 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 |
YaelDillies
left a comment
There was a problem hiding this comment.
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
|
🚀 Pull request has been placed on the maintainer queue by YaelDillies. |
|
maintainer merge pinging as requested |
|
🚀 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. -/ |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
I have docs update to explain the terminology. If Link is fine, it is ready for merge.
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
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.
(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.
HypergraphLikeis the way to view a graph as a setting. Various different graph structures are ways to view a graph as an algebraic object.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:
V,I,EV(G),I(G),E(G)attach',edgeMap'IsSource,IsTargetEvery 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.
HypergraphLikedoes 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 aHypergraphLikeinstance. 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 ofefromutov, retaining a source incidence and a distinct target incidence. Distinctness prevents entering and leaving an undirected edge through the same incidence.IsLinkandAdj: the existence of a link through a specified edge, and the existence of an edge linking two vertices.attachandedgeMap: total extensions of the incidence maps when the corresponding types are nonempty.edgeFiberandvertexFiber: the incidences belonging to an edge or vertex.incVertsandincEdges: 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
extendthe particular def to inherit them)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
extendmethod 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
HypergraphLikeby associating it with a Cayley graph, a CW complex with its 1-skeleton graph, or a lattice with its Hasse graph, in the same mannerSimpleGraphisHypergraphLike. Withextend, 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
GandH, each with vertex set{u, v}and single edge between them. In the naive approach where you defineSimpleGraphlike this:Then,
G = Hmay 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:
Now, any
multigraphthat happens to be a simple graph cannot useSimpleGraphresults 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 canonicalSimpleGraphrepresentation. 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
HasAdjPR (#35776) without critical thinking. In the discussion forQuiver(#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
HypergraphLikeinstance to each graph object but virtually all proofs worked without any changes.Philosophically, it makes the role of
HypergraphLikeclearer.HypergraphLikeis 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 byHypergraphLikeas now we supply the edge type along with the specificQuiverinstance, not before.Another benefit is that you can use
HypergraphLikeeven 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 onHypergraphLike. (#43768, #43748)G : Graph V Ecould happen to be a simple graph. A subset of a plane could be graph-like.Why ambient labels and support sets?
The
idfunction holds a special place in our heads. ConsiderG, K4 graph with vertex set{1, 2, 3, 4}, andH, K5 graph with vertex set{1, 2, 3, 4, 5}. Remove edges(1, 2)fromH. Up to isomorphism,Gis still a subgraph ofH. But, with respect to theidfunction,Gis no longer a subgraph ofH.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,
HypergraphLikewill sayGis a subgraph ofHas there exists embedding ofGintoH.Support sets in the type class are exactly the mechanism that allows "special treatment" for subtypes.
Related work (Not dependency)
GraphLiketypeclass #36743Co-authored-by: OpenAI Codex [email protected]