Simple graphs #
This module defines simple graphs on a vertex type V
as an
irreflexive symmetric relation.
There is a basic API for locally finite graphs and for graphs with finitely many vertices.
Main definitions #
-
SimpleGraph
is a structure for symmetric, irreflexive relations -
SimpleGraph.neighborSet
is theSet
of vertices adjacent to a given vertex -
SimpleGraph.commonNeighbors
is the intersection of the neighbor sets of two given vertices -
SimpleGraph.neighborFinset
is theFinset
of vertices adjacent to a given vertex, ifneighborSet
is finite -
SimpleGraph.incidenceSet
is theSet
of edges containing a given vertex -
SimpleGraph.incidenceFinset
is theFinset
of edges containing a given vertex, ifincidenceSet
is finite -
SimpleGraph.Dart
is an ordered pair of adjacent vertices, thought of as being an orientated edge. These are also known as "half-edges" or "bonds." -
SimpleGraph.Hom
,SimpleGraph.Embedding
, andSimpleGraph.Iso
for graph homomorphisms, graph embeddings, and graph isomorphisms. Note that a graph embedding is a stronger notion than an injective graph homomorphism, since its image is an induced subgraph. -
CompleteAtomicBooleanAlgebra
instance: Under the subgraph relation,SimpleGraph
forms aCompleteAtomicBooleanAlgebra
. In other words, this is the complete lattice of spanning subgraphs of the complete graph.
Notations #
→g
,↪g
, and≃g
for graph homomorphisms, graph embeddings, and graph isomorphisms, respectively.
Implementation notes #
-
A locally finite graph is one with instances
Π v, Fintype (G.neighborSet v)
. -
Given instances
DecidableRel G.Adj
andFintype V
, then the graph is locally finite, too. -
Morphisms of graphs are abbreviations for
RelHom
,RelEmbedding
, andRelIso
. To make use of pre-existing simp lemmas, definitions involving morphisms are abbreviations as well.
Naming Conventions #
- If the vertex type of a graph is finite, we refer to its cardinality as
CardVerts
.
Todo #
- This is the simplest notion of an unoriented graph. This should eventually fit into a more complete combinatorics hierarchy which includes multigraphs and directed graphs. We begin with simple graphs in order to start learning what the combinatorics hierarchy should look like.
A variant of the aesop
tactic for use in the graph library. Changes relative
to standard aesop
:
- We use the
SimpleGraph
rule set in addition to the default rule sets. - We instruct Aesop's
intro
rule to unfold withdefault
transparency. - We instruct Aesop to fail if it can't fully solve the goal. This allows us to
use
aesop_graph
for auto-params.
Instances For
Use aesop_graph?
to pass along a Try this
suggestion when using aesop_graph
Instances For
A variant of aesop_graph
which does not fail if it is unable to solve the
goal. Use this only for exploration! Nonterminal Aesop is even worse than
nonterminal simp
.
Instances For
- Adj : V → V → Prop
- symm : Symmetric s.Adj
- loopless : Irreflexive s.Adj
A simple graph is an irreflexive symmetric relation Adj
on a vertex type V
.
The relation describes which pairs of vertices are adjacent.
There is exactly one edge for every pair of adjacent vertices;
see SimpleGraph.edgeSet
for the corresponding edge set.
Instances For
Constructor for simple graphs using a symmetric irreflexive boolean function.
Instances For
We can enumerate simple graphs by enumerating all functions V → V → Bool
and filtering on whether they are symmetric and irreflexive.
Construct the simple graph induced by the given relation. It symmetrizes the relation and makes it irreflexive.
Instances For
The complete graph on a type V
is the simple graph with all pairs of distinct vertices
adjacent. In Mathlib
, this is usually referred to as ⊤
.
Instances For
The graph with no edges on a given vertex type V
. Mathlib
prefers the notation ⊥
.
Instances For
Two vertices are adjacent in the complete bipartite graph on two vertex types if and only if they are not from the same side. Any bipartite graph may be regarded as a subgraph of one of these.
Instances For
The relation that one SimpleGraph
is a subgraph of another.
Note that this should be spelled ≤
.
Instances For
The supremum of two graphs x ⊔ y
has edges where either x
or y
have edges.
The infimum of two graphs x ⊓ y
has edges where both x
and y
have edges.
We define Gᶜ
to be the SimpleGraph V
such that no two adjacent vertices in G
are adjacent in the complement, and every nonadjacent pair of vertices is adjacent
(still ensuring that vertices are not adjacent to themselves).
The difference of two graphs x \ y
has the edges of x
with the edges of y
removed.
G.support
is the set of vertices that form edges in G
.
Instances For
G.neighborSet v
is the set of vertices adjacent to v
in G
.
Instances For
The edges of G consist of the unordered pairs of vertices related by
G.Adj
. This is the order embedding; for the edge set of a particular graph, see
SimpleGraph.edgeSet
.
The way edgeSet
is defined is such that mem_edgeSet
is proved by refl
.
(That is, ⟦(v, w)⟧ ∈ G.edgeSet
is definitionally equal to G.Adj v w
.)
Instances For
G.edgeSet
is the edge set for G
.
This is an abbreviation for edgeSetEmbedding G
that permits dot notation.
Instances For
Alias of the reverse direction of SimpleGraph.edgeSet_subset_edgeSet
.
Alias of the reverse direction of SimpleGraph.edgeSet_ssubset_edgeSet
.
This lemma, combined with edgeSet_sdiff
and edgeSet_from_edgeSet
,
allows proving (G \ from_edgeSet s).edge_set = G.edgeSet \ s
by simp
.
Two vertices are adjacent iff there is an edge between them. The
condition v ≠ w
ensures they are different endpoints of the edge,
which is necessary since when v = w
the existential
∃ (e ∈ G.edgeSet), v ∈ e ∧ w ∈ e
is satisfied by every edge
incident to v
.
fromEdgeSet
constructs a SimpleGraph
from a set of edges, without loops.
Instances For
Darts #
- fst : V
- snd : V
- is_adj : SimpleGraph.Adj G s.fst s.snd
A Dart
is an oriented edge, implemented as an ordered pair of adjacent vertices.
This terminology comes from combinatorial maps, and they are also known as "half-edges"
or "bonds."
Instances For
The edge associated to the dart.
Instances For
The dart with reversed orientation from a given dart.
Instances For
Two darts are said to be adjacent if they could be consecutive darts in a walk -- that is, the first dart's second vertex is equal to the second dart's first vertex.
Instances For
For a given vertex v
, this is the bijective map from the neighbor set at v
to the darts d
with d.fst = v
.
Instances For
Incidence set #
Set of edges incident to a given vertex, aka incidence set.
Instances For
The edgeSet
of the graph as a Finset
.
Instances For
Alias of the reverse direction of SimpleGraph.edgeFinset_subset_edgeFinset
.
Alias of the reverse direction of SimpleGraph.edgeFinset_ssubset_edgeFinset
.
The set of common neighbors between two vertices v
and w
in a graph G
is the
intersection of the neighbor sets of v
and w
.
Instances For
Given an edge incident to a particular vertex, get the other vertex on the edge.
Instances For
There is an equivalence between the set of edges incident to a given vertex and the set of vertices adjacent to the vertex.
Instances For
Edge deletion #
Given a set of vertex pairs, remove all of the corresponding edges from the graph's edge set, if present.
See also: SimpleGraph.Subgraph.deleteEdges
.
Instances For
A graph is r
-delete-far from a property p
if we must delete at least r
edges from it to
get a graph with the property p
.
Instances For
Alias of the forward direction of SimpleGraph.deleteFar_iff
.
Map and comap #
Given an injective function, there is a covariant induced map on graphs by pushing forward the adjacency relation.
This is injective (see SimpleGraph.map_injective
).
Instances For
Given a function, there is a contravariant induced map on graphs by pulling back the
adjacency relation.
This is one of the ways of creating induced graphs. See SimpleGraph.induce
for a wrapper.
This is surjective when f
is injective (see SimpleGraph.comap_surjective
).
Instances For
Given a family of vertex types indexed by ι
, pulling back from ⊤ : SimpleGraph ι
yields the complete multipartite graph on the family.
Two vertices are adjacent if and only if their indices are not equal.
Instances For
Induced graphs #
Restrict a graph to the vertices in the set s
, deleting all edges incident to vertices
outside the set. This is a wrapper around SimpleGraph.comap
.
Instances For
Given a graph on a set of vertices, we can make it be a SimpleGraph V
by
adding in the remaining vertices without adding in any additional edges.
This is a wrapper around SimpleGraph.map
.
Instances For
Finiteness at a vertex #
This section contains definitions and lemmas concerning vertices that
have finitely many adjacent vertices. We denote this condition by
Fintype (G.neighborSet v)
.
We define G.neighborFinset v
to be the Finset
version of G.neighborSet v
.
Use neighborFinset_eq_filter
to rewrite this definition as a Finset.filter
expression.
G.neighbors v
is the Finset
version of G.Adj v
in case G
is
locally finite at v
.
Instances For
G.degree v
is the number of vertices adjacent to v
.
Instances For
This is the Finset
version of incidenceSet
.
Instances For
A graph is locally finite if every vertex has a finite neighbor set.
Instances For
A locally finite simple graph is regular of degree d
if every vertex has degree d
.
Instances For
The minimum degree of all vertices (and 0
if there are no vertices).
The key properties of this are given in exists_minimal_degree_vertex
, minDegree_le_degree
and le_minDegree_of_forall_le_degree
.
Instances For
There exists a vertex of minimal degree. Note the assumption of being nonempty is necessary, as the lemma implies there exists a vertex.
The minimum degree in the graph is at most the degree of any particular vertex.
In a nonempty graph, if k
is at most the degree of every vertex, it is at most the minimum
degree. Note the assumption that the graph is nonempty is necessary as long as G.minDegree
is
defined to be a natural.
The maximum degree of all vertices (and 0
if there are no vertices).
The key properties of this are given in exists_maximal_degree_vertex
, degree_le_maxDegree
and maxDegree_le_of_forall_degree_le
.
Instances For
There exists a vertex of maximal degree. Note the assumption of being nonempty is necessary, as the lemma implies there exists a vertex.
The maximum degree in the graph is at least the degree of any particular vertex.
In a graph, if k
is at least the degree of every vertex, then it is at least the maximum
degree.
The maximum degree of a nonempty graph is less than the number of vertices. Note that the assumption
that V
is nonempty is necessary, as otherwise this would assert the existence of a
natural number less than zero.
If the condition G.Adj v w
fails, then card_commonNeighbors_le_degree
is
the best we can do in general.
A graph homomorphism is a map on vertex sets that respects adjacency relations.
The notation G →g G'
represents the type of graph homomorphisms.
Instances For
A graph embedding is an embedding f
such that for vertices v w : V
,
G.Adj (f v) (f w) ↔ G.Adj v w
. Its image is an induced subgraph of G'.
The notation G ↪g G'
represents the type of graph embeddings.
Instances For
A graph isomorphism is a bijective map on vertex sets that respects adjacency relations.
The notation G ≃g G'
represents the type of graph isomorphisms.
Instances For
The identity homomorphism from a graph to itself.
Instances For
The map between edge sets induced by a homomorphism.
The underlying map on edges is given by Sym2.map
.
Instances For
The map between neighbor sets induced by a homomorphism.
Instances For
The map between darts induced by a homomorphism.
Instances For
The induced map for spanning subgraphs, which is the identity on vertices.
Instances For
Every graph homomorphism from a complete graph is injective.
There is a homomorphism to a graph from a comapped graph.
When the function is injective, this is an embedding (see SimpleGraph.Embedding.comap
).
Instances For
Composition of graph homomorphisms.
Instances For
The identity embedding from a graph to itself.
Instances For
An embedding of graphs gives rise to a homomorphism of graphs.
Instances For
A graph embedding induces an embedding of edge sets.
Instances For
A graph embedding induces an embedding of neighbor sets.
Instances For
Given an injective function, there is an embedding from the comapped graph into the original graph.
Instances For
Given an injective function, there is an embedding from a graph into the mapped graph.
Instances For
Induced graphs embed in the original graph.
Note that if G.induce s = ⊤
(i.e., if s
is a clique) then this gives the embedding of a
complete graph.
Instances For
Graphs on a set of vertices embed in their spanningCoe
.
Instances For
Composition of graph embeddings.
Instances For
The restriction of a morphism of graphs to induced subgraphs.
Instances For
Given an inclusion of vertex subsets, the induced embedding on induced graphs.
This is not an abbreviation for induceHom
since we get an embedding in this case.
Instances For
The identity isomorphism of a graph with itself.
Instances For
An isomorphism of graphs gives rise to an embedding of graphs.
Instances For
An isomorphism of graphs gives rise to a homomorphism of graphs.
Instances For
The inverse of a graph isomorphism.
Instances For
An isomorphism of graphs induces an equivalence of edge sets.
Instances For
A graph isomorphism induces an equivalence of neighbor sets.
Instances For
Given a bijection, there is an embedding from the comapped graph into the original graph.
Instances For
Given an injective function, there is an embedding from a graph into the mapped graph.
Instances For
Composition of graph isomorphisms.
Instances For
The graph induced on Set.univ
is isomorphic to the original graph.