Trail, Path, and Cycle #
In a simple graph,
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.IsTrail
,SimpleGraph.Walk.IsPath
, andSimpleGraph.Walk.IsCycle
.SimpleGraph.Path.map
for the induced map on paths, 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 #
trails, paths, circuits, cycles, bridge edges
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).
Instances For
About paths #
Equations
- p.instDecidableIsPathOfDecidableEq = ⋯.mpr inferInstance
Walk decompositions #
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 ha p).bypass = if hs : u ∈ p.bypass.support then p.bypass.dropUntil u hs else SimpleGraph.Walk.cons ha p.bypass
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 #
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
.
Alias of the forward direction of SimpleGraph.Walk.mapLe_isTrail
.
Alias of the reverse direction of SimpleGraph.Walk.mapLe_isTrail
.
Alias of the reverse direction of SimpleGraph.Walk.mapLe_isPath
.
Alias of the forward 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 #
Deleting edges #
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 }
Equations
- ⋯ = ⋯
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.