Graph connectivity #
In a simple graph,
A walk is a finite sequence of adjacent vertices, and can be thought of equally well as a sequence of directed edges.
A trail is a walk whose edges each appear no more than once.
A path is a trail whose vertices appear no more than once.
A cycle is a nonempty trail whose first and last vertices are the same and whose vertices except for the first appear no more than once.
Warning: graph theorists mean something different by "path" than do homotopy theorists. A "walk" in graph theory is a "path" in homotopy theory. Another warning: some graph theorists use "path" and "simple path" for "walk" and "path."
Some definitions and theorems have inspiration from multigraph counterparts in [Chou1994].
Main definitions #
SimpleGraph.Walk
(with accompanying pattern definitionsSimpleGraph.Walk.nil'
andSimpleGraph.Walk.cons'
)SimpleGraph.Walk.IsTrail
,SimpleGraph.Walk.IsPath
, andSimpleGraph.Walk.IsCycle
.SimpleGraph.Walk.map
andSimpleGraph.Path.map
for the induced map on walks, given an (injective) graph homomorphism.SimpleGraph.Reachable
for the relation of whether there exists a walk between a given pair of verticesSimpleGraph.Preconnected
andSimpleGraph.Connected
are predicates on simple graphs for whether every vertex can be reached from every other, and in the latter case, whether the vertex type is nonempty.SimpleGraph.ConnectedComponent
is the type of connected components of a given graph.SimpleGraph.IsBridge
for whether an edge is a bridge edge
Main statements #
SimpleGraph.isBridge_iff_mem_and_forall_cycle_not_mem
characterizes bridge edges in terms of there being no cycle containing them.
Tags #
walks, trails, paths, circuits, cycles, bridge edges
A walk is a sequence of adjacent vertices. For vertices u v : V
,
the type walk u v
consists of all walks starting at u
and ending at v
.
We say that a walk visits the vertices it contains. The set of vertices a
walk visits is SimpleGraph.Walk.support
.
See SimpleGraph.Walk.nil'
and SimpleGraph.Walk.cons'
for patterns that
can be useful in definitions since they make the vertices explicit.
- nil: {V : Type u} → {G : SimpleGraph V} → {u : V} → G.Walk u u
- cons: {V : Type u} → {G : SimpleGraph V} → {u v w : V} → G.Adj u v → G.Walk v w → G.Walk u w
Instances For
Equations
- SimpleGraph.instDecidableEqWalk = SimpleGraph.decEqWalk✝
Equations
- SimpleGraph.Walk.instInhabited G v = { default := SimpleGraph.Walk.nil }
The one-edge walk associated to a pair of adjacent vertices.
Equations
- h.toWalk = SimpleGraph.Walk.cons h SimpleGraph.Walk.nil
Instances For
Pattern to get Walk.nil
with the vertex as an explicit argument.
Equations
- SimpleGraph.Walk.nil' u = SimpleGraph.Walk.nil
Instances For
Pattern to get Walk.cons
with the vertices as explicit arguments.
Equations
- SimpleGraph.Walk.cons' u v w h p = SimpleGraph.Walk.cons h p
Instances For
Change the endpoints of a walk using equalities. This is helpful for relaxing
definitional equality constraints and to be able to state otherwise difficult-to-state
lemmas. While this is a simple wrapper around Eq.rec
, it gives a canonical way to write it.
The simp-normal form is for the copy
to be pushed outward. That way calculations can
occur within the "copy context."
Equations
- p.copy hu hv = hu ▸ hv ▸ p
Instances For
The length of a walk is the number of edges/darts along it.
Equations
- SimpleGraph.Walk.nil.length = 0
- (SimpleGraph.Walk.cons h q).length = q.length.succ
Instances For
The concatenation of two compatible walks.
Equations
- SimpleGraph.Walk.nil.append q = q
- (SimpleGraph.Walk.cons h p).append x = SimpleGraph.Walk.cons h (p.append x)
Instances For
The reversed version of SimpleGraph.Walk.cons
, concatenating an edge to
the end of a walk.
Equations
- p.concat h = p.append (SimpleGraph.Walk.cons h SimpleGraph.Walk.nil)
Instances For
The concatenation of the reverse of the first walk with the second walk.
Equations
- SimpleGraph.Walk.nil.reverseAux x = x
- (SimpleGraph.Walk.cons h p).reverseAux x = p.reverseAux (SimpleGraph.Walk.cons ⋯ x)
Instances For
The walk in reverse.
Equations
- w.reverse = w.reverseAux SimpleGraph.Walk.nil
Instances For
Get the n
th vertex from a walk, where n
is generally expected to be
between 0
and p.length
, inclusive.
If n
is greater than or equal to p.length
, the result is the path's endpoint.
Equations
- SimpleGraph.Walk.nil.getVert x = u
- (SimpleGraph.Walk.cons h p).getVert 0 = u
- (SimpleGraph.Walk.cons h q).getVert n.succ = q.getVert n
Instances For
Auxiliary definition for SimpleGraph.Walk.concatRec
Equations
- SimpleGraph.Walk.concatRecAux Hnil Hconcat SimpleGraph.Walk.nil = Hnil
- SimpleGraph.Walk.concatRecAux Hnil Hconcat (SimpleGraph.Walk.cons h q) = ⋯ ▸ Hconcat q.reverse ⋯ (SimpleGraph.Walk.concatRecAux Hnil Hconcat q)
Instances For
Recursor on walks by inducting on SimpleGraph.Walk.concat
.
This is inducting from the opposite end of the walk compared
to SimpleGraph.Walk.rec
, which inducts on SimpleGraph.Walk.cons
.
Equations
- SimpleGraph.Walk.concatRec Hnil Hconcat p = ⋯ ▸ SimpleGraph.Walk.concatRecAux Hnil Hconcat p.reverse
Instances For
The support
of a walk is the list of vertices it visits in order.
Equations
- SimpleGraph.Walk.nil.support = [u]
- (SimpleGraph.Walk.cons h q).support = u :: q.support
Instances For
The darts
of a walk is the list of darts it visits in order.
Equations
- SimpleGraph.Walk.nil.darts = []
- (SimpleGraph.Walk.cons h q).darts = { toProd := (u, v_3), adj := h } :: q.darts
Instances For
The edges
of a walk is the list of edges it visits in order.
This is defined to be the list of edges underlying SimpleGraph.Walk.darts
.
Instances For
Every edge in a walk's edge list is an edge of the graph.
It is written in this form (rather than using ⊆
) to avoid unsightly coercions.
Predicate for the empty walk.
Solves the dependent type problem where p = G.Walk.nil
typechecks
only if p
has defeq endpoints.
- nil: ∀ {V : Type u} {G : SimpleGraph V} {u : V}, SimpleGraph.Walk.nil.Nil
Instances For
Equations
- p.instDecidableNil = match w, p with | .(v), SimpleGraph.Walk.nil => isTrue ⋯ | w, SimpleGraph.Walk.cons h p => isFalse ⋯
A walk with its endpoints defeq is Nil
if and only if it is equal to nil
.
Alias of the forward direction of SimpleGraph.Walk.nil_iff_eq_nil
.
A walk with its endpoints defeq is Nil
if and only if it is equal to nil
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The second vertex along a non-nil walk.
Equations
- p.sndOfNotNil hp = SimpleGraph.Walk.notNilRec (fun (x u x_1 : V) (x : G.Adj x u) (x : G.Walk u x_1) => u) p hp
Instances For
The walk obtained by removing the first dart of a non-nil walk.
Equations
- p.tail hp = SimpleGraph.Walk.notNilRec (fun {u v w : V} (x : G.Adj u v) (q : G.Walk v w) => q) p hp
Instances For
The first dart of a walk.
Equations
- p.firstDart hp = { toProd := (v, p.sndOfNotNil hp), adj := ⋯ }
Instances For
Trails, paths, circuits, cycles #
A trail is a walk with no repeating edges.
- edges_nodup : p.edges.Nodup
Instances For
A path is a walk with no repeating vertices.
Use SimpleGraph.Walk.IsPath.mk'
for a simpler constructor.
- edges_nodup : p.edges.Nodup
- support_nodup : p.support.Nodup
Instances For
A circuit at u : V
is a nonempty trail beginning and ending at u
.
- edges_nodup : p.edges.Nodup
- ne_nil : p ≠ SimpleGraph.Walk.nil
Instances For
A cycle at u : V
is a circuit at u
whose only repeating vertex
is u
(which appears exactly twice).
- edges_nodup : p.edges.Nodup
- ne_nil : p ≠ SimpleGraph.Walk.nil
- support_nodup : p.support.tail.Nodup
Instances For
About paths #
Equations
- p.instDecidableIsPathOfDecidableEq = ⋯.mpr inferInstance
Walk decompositions #
Given a vertex in the support of a path, give the path up until (and including) that vertex.
Equations
- One or more equations did not get rendered due to their size.
- SimpleGraph.Walk.nil.takeUntil x x_1 = ⋯.mpr SimpleGraph.Walk.nil
Instances For
Given a vertex in the support of a path, give the path from (and including) that vertex to the end. In other words, drop vertices from the front of a path until (and not including) that vertex.
Equations
- One or more equations did not get rendered due to their size.
- SimpleGraph.Walk.nil.dropUntil x x_1 = ⋯.mpr SimpleGraph.Walk.nil
Instances For
The takeUntil
and dropUntil
functions split a walk into two pieces.
The lemma SimpleGraph.Walk.count_support_takeUntil_eq_one
specifies where this split occurs.
Rotate a loop walk such that it is centered at the given vertex.
Equations
- c.rotate h = (c.dropUntil u h).append (c.takeUntil u h)
Instances For
Given a set S
and a walk w
from u
to v
such that u ∈ S
but v ∉ S
,
there exists a dart in the walk whose start is in S
but whose end is not.
Type of paths #
The type for paths between two vertices.
Equations
- G.Path u v = { p : G.Walk u v // p.IsPath }
Instances For
The length-0 path at a vertex.
Equations
- SimpleGraph.Path.nil = ⟨SimpleGraph.Walk.nil, ⋯⟩
Instances For
The length-1 path between a pair of adjacent vertices.
Equations
- SimpleGraph.Path.singleton h = ⟨SimpleGraph.Walk.cons h SimpleGraph.Walk.nil, ⋯⟩
Instances For
The reverse of a path is another path. See also SimpleGraph.Walk.reverse
.
Equations
- p.reverse = ⟨(↑p).reverse, ⋯⟩
Instances For
Walks to paths #
Given a walk, produces a walk from it by bypassing subwalks between repeated vertices.
The result is a path, as shown in SimpleGraph.Walk.bypass_isPath
.
This is packaged up in SimpleGraph.Walk.toPath
.
Equations
- SimpleGraph.Walk.nil.bypass = SimpleGraph.Walk.nil
- (SimpleGraph.Walk.cons h q).bypass = let p' := q.bypass; if hs : u ∈ p'.support then p'.dropUntil u hs else SimpleGraph.Walk.cons h p'
Instances For
Given a walk, produces a path with the same endpoints using SimpleGraph.Walk.bypass
.
Equations
- p.toPath = ⟨p.bypass, ⋯⟩
Instances For
Mapping paths #
Given a graph homomorphism, map walks to walks.
Equations
- SimpleGraph.Walk.map f SimpleGraph.Walk.nil = SimpleGraph.Walk.nil
- SimpleGraph.Walk.map f (SimpleGraph.Walk.cons h q) = SimpleGraph.Walk.cons ⋯ (SimpleGraph.Walk.map f q)
Instances For
Unlike categories, for graphs vertex equality is an important notion, so needing to be able to work with equality of graph homomorphisms is a necessary evil.
Alias of the reverse direction of SimpleGraph.Walk.map_isTrail_iff_of_injective
.
Alias of the reverse direction of SimpleGraph.Walk.map_isCycle_iff_of_injective
.
The specialization of SimpleGraph.Walk.map
for mapping walks to supergraphs.
Equations
Instances For
Alias of the reverse direction of SimpleGraph.Walk.mapLe_isTrail
.
Alias of the forward direction of SimpleGraph.Walk.mapLe_isTrail
.
Alias of the forward direction of SimpleGraph.Walk.mapLe_isPath
.
Alias of the reverse direction of SimpleGraph.Walk.mapLe_isPath
.
Alias of the forward direction of SimpleGraph.Walk.mapLe_isCycle
.
Alias of the reverse direction of SimpleGraph.Walk.mapLe_isCycle
.
Given an injective graph homomorphism, map paths to paths.
Equations
- SimpleGraph.Path.map f hinj p = ⟨SimpleGraph.Walk.map f ↑p, ⋯⟩
Instances For
Given a graph embedding, map paths to paths.
Equations
- SimpleGraph.Path.mapEmbedding f p = SimpleGraph.Path.map f.toHom ⋯ p
Instances For
### Transferring between graphs
The walk p
transferred to lie in H
, given that H
contains its edges.
Equations
- SimpleGraph.Walk.nil.transfer H h_2 = SimpleGraph.Walk.nil
- (SimpleGraph.Walk.cons h_2 p_2).transfer H h_3 = SimpleGraph.Walk.cons ⋯ (p_2.transfer H ⋯)
Instances For
Deleting edges #
Given a walk that avoids a set of edges, produce a walk in the graph with those edges deleted.
Equations
- SimpleGraph.Walk.toDeleteEdges s p hp = p.transfer (G.deleteEdges s) ⋯
Instances For
Given a walk that avoids an edge, create a walk in the subgraph with that edge deleted.
This is an abbreviation for SimpleGraph.Walk.toDeleteEdges
.
Equations
- SimpleGraph.Walk.toDeleteEdge e p hp = SimpleGraph.Walk.toDeleteEdges {e} p ⋯
Instances For
Two vertices are reachable if there is a walk between them.
This is equivalent to Relation.ReflTransGen
of G.Adj
.
See SimpleGraph.reachable_iff_reflTransGen
.
Instances For
The equivalence relation on vertices given by SimpleGraph.Reachable
.
Equations
- G.reachableSetoid = { r := G.Reachable, iseqv := ⋯ }
Instances For
A graph is preconnected if every pair of vertices is reachable from one another.
Equations
- G.Preconnected = ∀ (u v : V), G.Reachable u v
Instances For
A graph is connected if it's preconnected and contains at least one vertex. This follows the convention observed by mathlib that something is connected iff it has exactly one connected component.
There is a CoeFun
instance so that h u v
can be used instead of h.Preconnected u v
.
- preconnected : G.Preconnected
- nonempty : Nonempty V
Instances For
Equations
- G.instCoeFunConnectedForallForallReachable = { coe := ⋯ }
The quotient of V
by the SimpleGraph.Reachable
relation gives the connected
components of a graph.
Instances For
Gives the connected component containing a particular vertex.
Instances For
Equations
- SimpleGraph.ConnectedComponent.inhabited = { default := G.connectedComponentMk default }
The ConnectedComponent
specialization of Quot.lift
. Provides the stronger
assumption that the vertices are connected by a path.
Equations
Instances For
This is Quot.recOn
specialized to connected components.
For convenience, it strengthens the assumptions in the hypothesis
to provide a path between the vertices.
Equations
- SimpleGraph.ConnectedComponent.recOn c f h = Quot.recOn c f ⋯
Instances For
The map on connected components induced by a graph homomorphism.
Equations
- SimpleGraph.ConnectedComponent.map φ C = SimpleGraph.ConnectedComponent.lift (fun (v : V) => G'.connectedComponentMk (φ v)) ⋯ C
Instances For
An isomorphism of graphs induces a bijection of connected components.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The set of vertices in a connected component of a graph.
Instances For
Equations
- SimpleGraph.ConnectedComponent.instSetLike = { coe := SimpleGraph.ConnectedComponent.supp, coe_injective' := ⋯ }
The equivalence between connected components, induced by an isomorphism of graphs, itself defines an equivalence on the supports of each connected component.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Bridge edges #
An edge of a graph is a bridge if, after removing it, its incident vertices are no longer reachable from one another.