Simple graphs #
This module defines simple graphs on a vertex type V
as an irreflexive symmetric relation.
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.incidenceSet
is theSet
of edges containing a given vertex.CompleteAtomicBooleanAlgebra
instance: Under the subgraph relation,SimpleGraph
forms aCompleteAtomicBooleanAlgebra
. In other words, this is the complete lattice of spanning subgraphs of the complete graph.
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.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Use aesop_graph?
to pass along a Try this
suggestion when using aesop_graph
Equations
- One or more equations did not get rendered due to their size.
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
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
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.
- Adj : V → V → Prop
The adjacency relation of a simple graph.
- symm : Symmetric self.Adj
- loopless : Irreflexive self.Adj
Instances For
Constructor for simple graphs using a symmetric irreflexive boolean function.
Equations
- One or more equations did not get rendered due to their size.
Instances For
We can enumerate simple graphs by enumerating all functions V → V → Bool
and filtering on whether they are symmetric and irreflexive.
Equations
- instFintypeSimpleGraphOfDecidableEq = { elems := Finset.map SimpleGraph.mk' Finset.univ, complete := ⋯ }
There are finitely many simple graphs on a given finite type.
Construct the simple graph induced by the given relation. It symmetrizes the relation and makes it irreflexive.
Equations
- SimpleGraph.fromRel r = { Adj := fun (a b : V) => a ≠ b ∧ (r a b ∨ r b a), symm := ⋯, loopless := ⋯ }
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 ⊤
.
Equations
- completeGraph V = { Adj := Ne, symm := ⋯, loopless := ⋯ }
Instances For
The graph with no edges on a given vertex type V
. Mathlib
prefers the notation ⊥
.
Equations
- emptyGraph V = { Adj := fun (x x : V) => False, symm := ⋯, loopless := ⋯ }
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.
Equations
Instances For
The relation that one SimpleGraph
is a subgraph of another.
Note that this should be spelled ≤
.
Equations
- x.IsSubgraph y = ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w
Instances For
Equations
- SimpleGraph.instLE = { le := SimpleGraph.IsSubgraph }
The supremum of two graphs x ⊔ y
has edges where either x
or y
have edges.
Equations
- SimpleGraph.instMax = { max := fun (x y : SimpleGraph V) => { Adj := x.Adj ⊔ y.Adj, symm := ⋯, loopless := ⋯ } }
The infimum of two graphs x ⊓ y
has edges where both x
and y
have edges.
Equations
- SimpleGraph.instMin = { min := fun (x y : SimpleGraph V) => { Adj := x.Adj ⊓ y.Adj, symm := ⋯, loopless := ⋯ } }
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).
Equations
- SimpleGraph.hasCompl = { compl := fun (G : SimpleGraph V) => { Adj := fun (v w : V) => v ≠ w ∧ ¬G.Adj v w, symm := ⋯, loopless := ⋯ } }
The difference of two graphs x \ y
has the edges of x
with the edges of y
removed.
Equations
- SimpleGraph.sdiff = { sdiff := fun (x y : SimpleGraph V) => { Adj := x.Adj \ y.Adj, symm := ⋯, loopless := ⋯ } }
Equations
- SimpleGraph.supSet = { sSup := fun (s : Set (SimpleGraph V)) => { Adj := fun (a b : V) => ∃ G ∈ s, G.Adj a b, symm := ⋯, loopless := ⋯ } }
Equations
- SimpleGraph.infSet = { sInf := fun (s : Set (SimpleGraph V)) => { Adj := fun (a b : V) => (∀ ⦃G : SimpleGraph V⦄, G ∈ s → G.Adj a b) ∧ a ≠ b, symm := ⋯, loopless := ⋯ } }
For graphs G
, H
, G ≤ H
iff ∀ a b, G.Adj a b → H.Adj a b
.
Equations
- SimpleGraph.distribLattice = DistribLattice.mk ⋯
Equations
- SimpleGraph.completeAtomicBooleanAlgebra = CompleteAtomicBooleanAlgebra.mk ⋯ ⋯ ⋯ ⋯ ⋯ ⋯
Equations
- SimpleGraph.instInhabited V = { default := ⊥ }
Equations
- SimpleGraph.Bot.adjDecidable V = inferInstanceAs (DecidableRel fun (x x : V) => False)
Equations
- SimpleGraph.Sup.adjDecidable V G H = inferInstanceAs (DecidableRel fun (v w : V) => G.Adj v w ∨ H.Adj v w)
Equations
- SimpleGraph.Inf.adjDecidable V G H = inferInstanceAs (DecidableRel fun (v w : V) => G.Adj v w ∧ H.Adj v w)
Equations
- SimpleGraph.Sdiff.adjDecidable V G H = inferInstanceAs (DecidableRel fun (v w : V) => G.Adj v w ∧ ¬H.Adj v w)
Equations
- SimpleGraph.Top.adjDecidable V = inferInstanceAs (DecidableRel fun (v w : V) => v ≠ w)
Equations
- SimpleGraph.Compl.adjDecidable V G = inferInstanceAs (DecidableRel fun (v w : V) => v ≠ w ∧ ¬G.Adj v w)
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
.
Equations
- G.neighborSet v = {w : V | G.Adj v w}
Instances For
Equations
- SimpleGraph.neighborSet.memDecidable G v = inferInstanceAs (DecidablePred (G.Adj v))
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 Iff.rfl
.
(That is, s(v, w) ∈ G.edgeSet
is definitionally equal to G.Adj v w
.)
Equations
- SimpleGraph.edgeSetEmbedding V = OrderEmbedding.ofMapLEIff (fun (G : SimpleGraph V) => Sym2.fromRel ⋯) ⋯
Instances For
G.edgeSet
is the edge set for G
.
This is an abbreviation for edgeSetEmbedding G
that permits dot notation.
Equations
- G.edgeSet = (SimpleGraph.edgeSetEmbedding V) G
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
.
Equations
- G.decidableMemEdgeSet = Sym2.fromRel.decidablePred ⋯
Equations
- G.fintypeEdgeSet = Subtype.fintype (Membership.mem G.edgeSet)
Equations
- G₁.fintypeEdgeSetSup G₂ = ⋯.mpr inferInstance
Equations
- G₁.fintypeEdgeSetInf G₂ = ⋯.mpr (G₁.edgeSet.fintypeInter G₂.edgeSet)
Equations
- G₁.fintypeEdgeSetSdiff G₂ = ⋯.mpr (G₁.edgeSet.fintypeDiff G₂.edgeSet)
fromEdgeSet
constructs a SimpleGraph
from a set of edges, without loops.
Equations
- SimpleGraph.fromEdgeSet s = { Adj := Sym2.ToRel s ⊓ Ne, symm := ⋯, loopless := ⋯ }
Instances For
Equations
- SimpleGraph.instFintypeElemSym2EdgeSetFromEdgeSetOfDecidableEq s = ⋯.mpr inferInstance
Incidence set #
Equations
- G.decidableMemIncidenceSet v = inferInstanceAs (DecidablePred fun (e : Sym2 V) => e ∈ G.edgeSet ∧ v ∈ e)
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
Equations
- G.decidableMemCommonNeighbors v w = inferInstanceAs (DecidablePred fun (u : V) => u ∈ G.neighborSet v ∧ u ∈ G.neighborSet w)
Given an edge incident to a particular vertex, get the other vertex on the edge.
Equations
- G.otherVertexOfIncident h = Sym2.Mem.other' ⋯
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.
Equations
- One or more equations did not get rendered due to their size.
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
.
Equations
- G.deleteEdges s = G \ SimpleGraph.fromEdgeSet s