Multigraphs #
A multigraph is a set of vertices and a set of edges,
together with incidence data that associates each edge e
with an unordered pair s(x,y) of vertices called the ends of e.
The pair of e and s(x,y) is called a link.
The vertices x and y may be equal, in which case e is a loop.
There may be more than one edge with the same ends.
If a multigraph has no loops and has at most one edge for every given ends, it is called simple,
and these objects are also formalized as SimpleGraph.
This module defines Graph α β for a vertex type α and an edge type β,
and gives basic API for incidence, adjacency and extensionality.
The design broadly follows [Chou1994].
Main definitions #
For G : Graph α β, ...
V(G)denotes the vertex set ofGas a term inSet α.E(G)denotes the edge set ofGas a term inSet β.G.IsLink e x ymeans that the edgee : βhas verticesx : αandy : αas its ends.G.Inc e xmeans that the edgee : βhasxas one of its ends.G.Adj x ymeans that there is an edgeehavingxandyas its ends.G.IsLoopAt e xmeans thateis a loop edge with both ends equal tox.G.IsNonloopAt e xmeans thateis a non-loop edge with one end equal tox.
Implementation notes #
Unlike the design of SimpleGraph, the vertex and edge sets of G are modelled as sets
V(G) : Set α and E(G) : Set β, within ambient types, rather than being types themselves.
This mimics the 'embedded set' design used in Matroid, which seems to be more convenient for
formalizing real-world proofs in combinatorics.
A specific advantage is that this allows subgraphs of G : Graph α β to also exist on
an equal footing with G as terms in Graph α β,
and so there is no need for a Graph.subgraph type and all the associated
definitions and canonical coercion maps. The same will go for minors and the various other
partial orders on multigraphs.
The main tradeoff is that parts of the API will need to care about whether a term
x : α or e : β is a 'real' vertex or edge of the graph, rather than something outside
the vertex or edge set. This is an issue, but is likely amenable to automation.
Notation #
Reflecting written mathematics, we use the compact notations V(G) and E(G) to
refer to the vertexSet and edgeSet of G : Graph α β.
If G.IsLink e x y then we refer to e as edge and x and y as left and right in names.
A multigraph with vertices of type α and edges of type β,
as described by vertex and edge sets vertexSet : Set α and edgeSet : Set β,
and a predicate IsLink describing whether an edge e : β has vertices x y : α as its ends.
The edgeSet structure field can be inferred from IsLink
via edge_mem_iff_exists_isLink (and this structure provides default values
for edgeSet and edge_mem_iff_exists_isLink that use IsLink).
While the field is not strictly necessary, when defining a graph we often
immediately know what the edge set should be,
and furthermore having edgeSet separate can be convenient for
definitional equality reasons.
- vertexSet : Set α
The vertex set.
- IsLink : β → α → α → Prop
The binary incidence predicate, stating that
xandyare the ends of an edgee. IfG.IsLink e x ythen we refer toeasedgeandxandyasleftandright. - edgeSet : Set β
The edge set.
If
egoes fromxtoy, it goes fromytox.- eq_or_eq_of_isLink_of_isLink ⦃e : β⦄ ⦃x y v w : α⦄ : self.IsLink e x y → self.IsLink e v w → x = v ∨ x = w
An edge is incident with at most one pair of vertices.
An edge
eis incident to something if and only ifeis in the edge set.If some edge
eis incident tox, thenx ∈ V.
Instances For
V(G) denotes the vertexSet of a graph G.
Equations
- One or more equations did not get rendered due to their size.
Instances For
E(G) denotes the edgeSet of a graph G.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Edge-vertex-vertex incidence #
Edge-vertex incidence #
Given a proof that the edge e is incident with the vertex x in G,
noncomputably find the other end of e. (If e is a loop, this is equal to x itself).
Equations
- h.other = Exists.choose h
Instances For
G.IsNonloopAt e x means that the vertex x is one but not both of the ends of the edge =e,
or equivalently that e is incident with x but not a loop at x -
see Graph.isNonloopAt_iff_inc_not_isLoopAt.
Equations
- G.IsNonloopAt e x = ∃ (y : α), y ≠ x ∧ G.IsLink e x y
Instances For
Adjacency #
Extensionality #
Two graphs with the same vertex set and binary incidences are equal.
(We use this as the default extensionality lemma rather than adding @[ext]
to the definition of Graph, so it doesn't require equality of the edge sets.)