Documentation

Mathlib.Combinatorics.SimpleGraph.Connectivity.Connected

Main definitions #

Main statements #

TODO #

IsBridge is unpractical: we shouldn't require the edge to be present. See https://github.com/leanprover-community/mathlib4/issues/31690.

Tags #

trails, paths, cycles, bridge edges

Reachable and Connected #

def SimpleGraph.Reachable {V : Type u} (G : SimpleGraph V) (u v : V) :

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.

Equations
    Instances For
      theorem SimpleGraph.Reachable.elim {V : Type u} {G : SimpleGraph V} {p : Prop} {u v : V} (h : G.Reachable u v) (hp : βˆ€ (a : G.Walk u v), p) :
      p
      theorem SimpleGraph.Reachable.elim_path {V : Type u} {G : SimpleGraph V} {p : Prop} {u v : V} (h : G.Reachable u v) (hp : βˆ€ (a : G.Path u v), p) :
      p
      theorem SimpleGraph.Walk.reachable {V : Type u} {G : SimpleGraph V} {u v : V} (p : G.Walk u v) :
      G.Reachable u v
      theorem SimpleGraph.Adj.reachable {V : Type u} {G : SimpleGraph V} {u v : V} (h : G.Adj u v) :
      G.Reachable u v
      @[simp]
      theorem SimpleGraph.Reachable.rfl {V : Type u} {G : SimpleGraph V} {u : V} :
      G.Reachable u u
      theorem SimpleGraph.Reachable.symm {V : Type u} {G : SimpleGraph V} {u v : V} (huv : G.Reachable u v) :
      G.Reachable v u
      theorem SimpleGraph.Reachable.trans {V : Type u} {G : SimpleGraph V} {u v w : V} (huv : G.Reachable u v) (hvw : G.Reachable v w) :
      G.Reachable u w
      theorem SimpleGraph.Reachable.map {V : Type u} {V' : Type v} {u v : V} {G : SimpleGraph V} {G' : SimpleGraph V'} (f : G β†’g G') (h : G.Reachable u v) :
      G'.Reachable (f u) (f v)
      theorem SimpleGraph.Reachable.mono {V : Type u} {u v : V} {G G' : SimpleGraph V} (h : G ≀ G') (Guv : G.Reachable u v) :
      G'.Reachable u v
      theorem SimpleGraph.Reachable.exists_isPath {V : Type u} {G : SimpleGraph V} {u v : V} (hr : G.Reachable u v) :
      βˆƒ (p : G.Walk u v), p.IsPath
      theorem SimpleGraph.Iso.reachable_iff {V : Type u} {V' : Type v} {G : SimpleGraph V} {G' : SimpleGraph V'} {Ο† : G ≃g G'} {u v : V} :
      G'.Reachable (Ο† u) (Ο† v) ↔ G.Reachable u v
      theorem SimpleGraph.Iso.symm_apply_reachable {V : Type u} {V' : Type v} {G : SimpleGraph V} {G' : SimpleGraph V'} {Ο† : G ≃g G'} {u : V} {v : V'} :
      G.Reachable (Ο†.symm v) u ↔ G'.Reachable v (Ο† u)
      theorem SimpleGraph.Reachable.mem_subgraphVerts {V : Type u} {G : SimpleGraph V} {u v : V} {H : G.Subgraph} (hr : G.Reachable u v) (h : βˆ€ v ∈ H.verts, βˆ€ (w : V), G.Adj v w β†’ H.Adj v w) (hu : u ∈ H.verts) :
      @[simp]
      theorem SimpleGraph.reachable_bot {V : Type u} {u v : V} :

      Distinct vertices are not reachable in the empty graph.

      theorem SimpleGraph.not_reachable_of_left_degree_zero {V : Type u} {G : SimpleGraph V} {u v : V} [Fintype ↑(G.neighborSet u)] (huv : u β‰  v) (hu : G.degree u = 0) :
      theorem SimpleGraph.not_reachable_of_right_degree_zero {V : Type u} {G : SimpleGraph V} {u v : V} [Fintype ↑(G.neighborSet v)] (huv : u β‰  v) (hu : G.degree v = 0) :

      The equivalence relation on vertices given by SimpleGraph.Reachable.

      Equations
        Instances For

          A graph is preconnected if every pair of vertices is reachable from one another.

          Equations
            Instances For
              theorem SimpleGraph.Preconnected.map {V : Type u} {V' : Type v} {G : SimpleGraph V} {H : SimpleGraph V'} (f : G β†’g H) (hf : Function.Surjective ⇑f) (hG : G.Preconnected) :
              theorem SimpleGraph.Preconnected.mono {V : Type u} {G G' : SimpleGraph V} (h : G ≀ G') (hG : G.Preconnected) :
              @[deprecated SimpleGraph.preconnected_bot (since := "2025-09-23")]

              Alias of SimpleGraph.preconnected_bot.

              @[deprecated SimpleGraph.preconnected_bot_iff_subsingleton (since := "2025-09-23")]

              Alias of SimpleGraph.preconnected_bot_iff_subsingleton.

              @[deprecated SimpleGraph.not_preconnected_bot (since := "2025-09-23")]

              Alias of SimpleGraph.not_preconnected_bot.

              @[deprecated SimpleGraph.preconnected_top (since := "2025-09-23")]

              Alias of SimpleGraph.preconnected_top.

              theorem SimpleGraph.adj_of_mem_walk_support {V : Type u} {G : SimpleGraph V} {u v : V} (p : G.Walk u v) (hp : ¬p.Nil) {x : V} (hx : x ∈ p.support) :
              βˆƒ y ∈ p.support, G.Adj x y
              theorem SimpleGraph.mem_support_of_mem_walk_support {V : Type u} {G : SimpleGraph V} {u v : V} (p : G.Walk u v) (hp : ¬p.Nil) {w : V} (hw : w ∈ p.support) :
              theorem SimpleGraph.mem_support_of_reachable {V : Type u} {G : SimpleGraph V} {u v : V} (huv : u β‰  v) (h : G.Reachable u v) :
              theorem SimpleGraph.Preconnected.exists_isPath {V : Type u} {G : SimpleGraph V} (h : G.Preconnected) (u v : V) :
              βˆƒ (p : G.Walk u v), p.IsPath
              structure SimpleGraph.Connected {V : Type u} (G : SimpleGraph V) :

              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.

              Instances For
                instance SimpleGraph.instCoeFunConnectedForallForallReachable {V : Type u} (G : SimpleGraph V) :
                CoeFun G.Connected fun (x : G.Connected) => βˆ€ (u v : V), G.Reachable u v
                Equations
                  theorem SimpleGraph.Connected.map {V : Type u} {V' : Type v} {G : SimpleGraph V} {H : SimpleGraph V'} (f : G β†’g H) (hf : Function.Surjective ⇑f) (hG : G.Connected) :
                  theorem SimpleGraph.Connected.mono {V : Type u} {G G' : SimpleGraph V} (h : G ≀ G') (hG : G.Connected) :
                  theorem SimpleGraph.Connected.exists_isPath {V : Type u} {G : SimpleGraph V} (h : G.Connected) (u v : V) :
                  βˆƒ (p : G.Walk u v), p.IsPath
                  @[deprecated SimpleGraph.not_connected_bot (since := "2025-09-23")]

                  Alias of SimpleGraph.not_connected_bot.

                  @[deprecated SimpleGraph.connected_top (since := "2025-09-23")]

                  Alias of SimpleGraph.connected_top.

                  The quotient of V by the SimpleGraph.Reachable relation gives the connected components of a graph.

                  Equations
                    Instances For

                      Gives the connected component containing a particular vertex.

                      Equations
                        Instances For
                          theorem SimpleGraph.ConnectedComponent.ind {V : Type u} {G : SimpleGraph V} {Ξ² : G.ConnectedComponent β†’ Prop} (h : βˆ€ (v : V), Ξ² (G.connectedComponentMk v)) (c : G.ConnectedComponent) :
                          Ξ² c
                          theorem SimpleGraph.ConnectedComponent.indβ‚‚ {V : Type u} {G : SimpleGraph V} {Ξ² : G.ConnectedComponent β†’ G.ConnectedComponent β†’ Prop} (h : βˆ€ (v w : V), Ξ² (G.connectedComponentMk v) (G.connectedComponentMk w)) (c d : G.ConnectedComponent) :
                          Ξ² c d
                          def SimpleGraph.ConnectedComponent.lift {V : Type u} {G : SimpleGraph V} {Ξ² : Sort u_1} (f : V β†’ Ξ²) (h : βˆ€ (v w : V) (p : G.Walk v w), p.IsPath β†’ f v = f w) :
                          G.ConnectedComponent β†’ Ξ²

                          The ConnectedComponent specialization of Quot.lift. Provides the stronger assumption that the vertices are connected by a path.

                          Equations
                            Instances For
                              @[simp]
                              theorem SimpleGraph.ConnectedComponent.lift_mk {V : Type u} {G : SimpleGraph V} {Ξ² : Sort u_1} {f : V β†’ Ξ²} {h : βˆ€ (v w : V) (p : G.Walk v w), p.IsPath β†’ f v = f w} {v : V} :
                              theorem SimpleGraph.ConnectedComponent.exists {V : Type u} {G : SimpleGraph V} {p : G.ConnectedComponent β†’ Prop} :
                              (βˆƒ (c : G.ConnectedComponent), p c) ↔ βˆƒ (v : V), p (G.connectedComponentMk v)
                              theorem SimpleGraph.ConnectedComponent.forall {V : Type u} {G : SimpleGraph V} {p : G.ConnectedComponent β†’ Prop} :
                              (βˆ€ (c : G.ConnectedComponent), p c) ↔ βˆ€ (v : V), p (G.connectedComponentMk v)
                              def SimpleGraph.ConnectedComponent.recOn {V : Type u} {G : SimpleGraph V} {motive : G.ConnectedComponent β†’ Sort u_1} (c : G.ConnectedComponent) (f : (v : V) β†’ motive (G.connectedComponentMk v)) (h : βˆ€ (u v : V) (p : G.Walk u v), p.IsPath β†’ β‹― β–Έ f u = f v) :
                              motive c

                              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
                                Instances For
                                  def SimpleGraph.ConnectedComponent.map {V : Type u} {V' : Type v} {G : SimpleGraph V} {G' : SimpleGraph V'} (Ο† : G β†’g G') (C : G.ConnectedComponent) :

                                  The map on connected components induced by a graph homomorphism.

                                  Equations
                                    Instances For
                                      @[simp]
                                      theorem SimpleGraph.ConnectedComponent.map_mk {V : Type u} {V' : Type v} {G : SimpleGraph V} {G' : SimpleGraph V'} (Ο† : G β†’g G') (v : V) :
                                      @[simp]
                                      theorem SimpleGraph.ConnectedComponent.map_comp {V : Type u} {V' : Type v} {V'' : Type w} {G : SimpleGraph V} {G' : SimpleGraph V'} {G'' : SimpleGraph V''} (C : G.ConnectedComponent) (Ο† : G β†’g G') (ψ : G' β†’g G'') :
                                      map ψ (map Ο† C) = map (ψ.comp Ο†) C

                                      An isomorphism of graphs induces a bijection of connected components.

                                      Equations
                                        Instances For
                                          @[simp]
                                          theorem SimpleGraph.Iso.connectedComponentEquiv_trans {V : Type u} {V' : Type v} {V'' : Type w} {G : SimpleGraph V} {G' : SimpleGraph V'} {G'' : SimpleGraph V''} (Ο† : G ≃g G') (Ο†' : G' ≃g G'') :

                                          The set of vertices in a connected component of a graph.

                                          Equations
                                            Instances For
                                              theorem SimpleGraph.ConnectedComponent.supp_injective_iff {V : Type u} {G : SimpleGraph V} {a₁ aβ‚‚ : G.ConnectedComponent} :
                                              a₁ = aβ‚‚ ↔ a₁.supp = aβ‚‚.supp
                                              def SimpleGraph.ConnectedComponent.isoEquivSupp {V : Type u} {V' : Type v} {G : SimpleGraph V} {G' : SimpleGraph V'} (Ο† : G ≃g G') (C : G.ConnectedComponent) :
                                              ↑C.supp ≃ ↑(Ο†.connectedComponentEquiv C).supp

                                              The equivalence between connected components, induced by an isomorphism of graphs, itself defines an equivalence on the supports of each connected component.

                                              Equations
                                                Instances For
                                                  theorem SimpleGraph.ConnectedComponent.mem_coe_supp_of_adj {V : Type u} {G : SimpleGraph V} {v w : V} {H : G.Subgraph} {c : H.coe.ConnectedComponent} (hv : v ∈ Subtype.val '' ↑c) (hw : w ∈ H.verts) (hadj : H.Adj v w) :
                                                  theorem SimpleGraph.ConnectedComponent.eq_of_common_vertex {V : Type u} {G : SimpleGraph V} {v : V} {c c' : G.ConnectedComponent} (hc : v ∈ c.supp) (hc' : v ∈ c'.supp) :
                                                  c = c'
                                                  theorem SimpleGraph.ConnectedComponent.mem_supp_of_adj_mem_supp {V : Type u} {G : SimpleGraph V} (C : G.ConnectedComponent) {u v : V} (hu : u ∈ C.supp) (hadj : G.Adj u v) :

                                                  Given a connected component C of a simple graph G, produce the induced graph on C. The declaration connected_toSimpleGraph shows it is connected, and toSimpleGraph_hom provides the homomorphism back to G.

                                                  Equations
                                                    Instances For

                                                      Homomorphism from a connected component graph to the original graph.

                                                      Equations
                                                        Instances For

                                                          There is a walk between every pair of vertices in a connected component.

                                                          def SimpleGraph.homOfConnectedComponents {V : Type u} {V' : Type v} (G : SimpleGraph V) {H : SimpleGraph V'} (C : (c : G.ConnectedComponent) β†’ c.toSimpleGraph β†’g H) :

                                                          Given graph homomorphisms from each connected component of G to H, this is the graph homomorphism from G to H.

                                                          Equations
                                                            Instances For

                                                              Bridge edges #

                                                              def SimpleGraph.IsBridge {V : Type u} (G : SimpleGraph V) (e : Sym2 V) :

                                                              An edge of a graph is a bridge if, after removing it, its incident vertices are no longer reachable from one another.

                                                              Equations
                                                                Instances For
                                                                  theorem SimpleGraph.reachable_delete_edges_iff_exists_walk {V : Type u} {G : SimpleGraph V} {v w v' w' : V} :
                                                                  (G \ fromEdgeSet {s(v, w)}).Reachable v' w' ↔ βˆƒ (p : G.Walk v' w'), s(v, w) βˆ‰ p.edges
                                                                  theorem SimpleGraph.reachable_deleteEdges_iff_exists_cycle.aux {V : Type u} {G : SimpleGraph V} [DecidableEq V] {u v w : V} (hb : βˆ€ (p : G.Walk v w), s(v, w) ∈ p.edges) (c : G.Walk u u) (hc : c.IsTrail) (he : s(v, w) ∈ c.edges) (hw : w ∈ (c.takeUntil v β‹―).support) :
                                                                  theorem SimpleGraph.isBridge_iff_adj_and_forall_cycle_notMem {V : Type u} {G : SimpleGraph V} {v w : V} :
                                                                  G.IsBridge s(v, w) ↔ G.Adj v w ∧ βˆ€ ⦃u : V⦄ (p : G.Walk u u), p.IsCycle β†’ s(v, w) βˆ‰ p.edges
                                                                  theorem SimpleGraph.isBridge_iff_mem_and_forall_cycle_notMem {V : Type u} {G : SimpleGraph V} {e : Sym2 V} :
                                                                  G.IsBridge e ↔ e ∈ G.edgeSet ∧ βˆ€ ⦃u : V⦄ (p : G.Walk u u), p.IsCycle β†’ e βˆ‰ p.edges

                                                                  Deleting a non-bridge edge from a connected graph preserves connectedness.

                                                                  theorem SimpleGraph.IsBridge.anti_of_mem_edgeSet {V : Type u} {G G' : SimpleGraph V} {e : Sym2 V} (hle : G ≀ G') (h : e ∈ G.edgeSet) (h' : G'.IsBridge e) :

                                                                  If e is an edge in G and is a bridge in a larger graph G', then it's a bridge in G.

                                                                  2-reachability #

                                                                  In this section, we prove results about 2-connected components of a graph, but without naming them.

                                                                  theorem SimpleGraph.Walk.exists_mem_edges_of_not_reachable_deleteEdges {V : Type u} {G : SimpleGraph V} {u v : V} (w : G.Walk u v) {s : Set (Sym2 V)} (huv : Β¬(G.deleteEdges s).Reachable u v) :
                                                                  βˆƒ e ∈ s, e ∈ w.edges

                                                                  A walk between two vertices separated by a set of edges must go through one of those edges.

                                                                  theorem SimpleGraph.Walk.mem_edges_of_not_reachable_deleteEdges {V : Type u} {G : SimpleGraph V} {u v : V} (w : G.Walk u v) {e : Sym2 V} (huv : Β¬(G.deleteEdges {e}).Reachable u v) :

                                                                  A walk between two vertices separated by an edge must go through that edge.

                                                                  theorem SimpleGraph.Walk.IsTrail.not_mem_edges_of_not_reachable {V : Type u} {G : SimpleGraph V} {u v x y : V} {w : G.Walk u v} (hw : w.IsTrail) (huy : Β¬(G.deleteEdges {s(x, y)}).Reachable u y) (hvy : Β¬(G.deleteEdges {s(x, y)}).Reachable v y) :
                                                                  s(x, y) βˆ‰ w.edges

                                                                  A trail doesn't go through an edge that disconnects one of its endpoints from the endpoints of the trail.

                                                                  theorem SimpleGraph.Walk.IsTrail.not_mem_support_of_not_reachable {V : Type u} {G : SimpleGraph V} {u v x y : V} {w : G.Walk u v} (hw : w.IsTrail) (huy : Β¬(G.deleteEdges {s(x, y)}).Reachable u y) (hvy : Β¬(G.deleteEdges {s(x, y)}).Reachable v y) :
                                                                  y βˆ‰ w.support

                                                                  A trail doesn't go through a vertex that is disconnected from its endpoints by an edge.

                                                                  theorem SimpleGraph.Walk.IsTrail.not_mem_support_of_subsingleton_neighborSet {V : Type u} {G : SimpleGraph V} {u v x : V} {w : G.Walk u v} (hw : w.IsTrail) (hxu : x β‰  u) (hxv : x β‰  v) (hx : (G.neighborSet x).Subsingleton) :
                                                                  x βˆ‰ w.support

                                                                  A trail doesn't go through any leaf vertex, except possibly at its endpoints.

                                                                  theorem SimpleGraph.Preconnected.induce_of_degree_eq_one {V : Type u} {G : SimpleGraph V} (hG : G.Preconnected) {s : Set V} (hs : βˆ€ v βˆ‰ s, (G.neighborSet v).Subsingleton) :

                                                                  Removing leaves from a connected graph keeps it connected.