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 [Cho94].
Main definitions #
For G : Graph α β
, ...
V(G)
denotes the vertex set ofG
as a term inSet α
.E(G)
denotes the edge set ofG
as a term inSet β
.G.IsLink e x y
means that the edgee : β
has verticesx : α
andy : α
as its ends.G.Inc e x
means that the edgee : β
hasx
as one of its ends.G.Adj x y
means that there is an edgee
havingx
andy
as its ends.G.IsLoopAt e x
means thate
is a loop edge with both ends equal tox
.G.IsNonloopAt e x
means thate
is 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
x
andy
are the ends of an edgee
. IfG.IsLink e x y
then we refer toe
asedge
andx
andy
asleft
andright
. - edgeSet : Set β
The edge set.
If
e
goes fromx
toy
, it goes fromy
tox
.- 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
e
is incident to something if and only ife
is in the edge set.If some edge
e
is 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.)