Documentation

Mathlib.Combinatorics.SimpleGraph.Acyclic

Acyclic graphs and trees #

This module introduces acyclic graphs (a.k.a. forests) and trees.

Main definitions #

Main statements #

References #

The structure of the proofs for SimpleGraph.IsAcyclic and SimpleGraph.IsTree, including supporting lemmas about SimpleGraph.IsBridge, generally follows the high-level description for these theorems for multigraphs from [Chou1994].

Tags #

acyclic graphs, trees

A graph is acyclic (or a forest) if it has no cycles.

Instances For
    structure SimpleGraph.IsTree {V : Type u_1} (G : SimpleGraph V) extends G.Connected :

    A tree is a connected acyclic graph.

    Instances For
      theorem SimpleGraph.isTree_iff {V : Type u_1} (G : SimpleGraph V) :
      G.IsTree โ†” G.Connected โˆง G.IsAcyclic
      @[deprecated SimpleGraph.IsTree.connected (since := "2026-03-18")]
      theorem SimpleGraph.IsTree.isConnected {V : Type u_1} {G : SimpleGraph V} (self : G.IsTree) :

      Alias of SimpleGraph.IsTree.connected.

      @[deprecated SimpleGraph.IsTree.isAcyclic (since := "2026-03-18")]
      theorem SimpleGraph.IsTree.IsAcyclic {V : Type u_1} {G : SimpleGraph V} (self : G.IsTree) :

      Alias of SimpleGraph.IsTree.isAcyclic.


      A tree is acyclic.

      theorem SimpleGraph.IsAcyclic.comap {V : Type u_1} {V' : Type u_2} {G : SimpleGraph V} {G' : SimpleGraph V'} (f : G โ†’g G') (hinj : Function.Injective โ‡‘f) (h : G'.IsAcyclic) :

      A graph that has an injective homomorphism to an acyclic graph is acyclic.

      theorem SimpleGraph.IsAcyclic.embedding {V : Type u_1} {V' : Type u_2} {G : SimpleGraph V} {G' : SimpleGraph V'} (f : G โ†ชg G') (h : G'.IsAcyclic) :
      theorem SimpleGraph.Iso.isAcyclic_iff {V : Type u_1} {V' : Type u_2} {G : SimpleGraph V} {G' : SimpleGraph V'} (f : G โ‰ƒg G') :
      G.IsAcyclic โ†” G'.IsAcyclic

      Isomorphic graphs are acyclic together.

      theorem SimpleGraph.Iso.isTree_iff {V : Type u_1} {V' : Type u_2} {G : SimpleGraph V} {G' : SimpleGraph V'} (f : G โ‰ƒg G') :
      G.IsTree โ†” G'.IsTree

      Isomorphic graphs are trees together.

      theorem SimpleGraph.IsAcyclic.of_map {V : Type u_1} {V' : Type u_2} {G : SimpleGraph V} (f : V โ†ช V') (h : (SimpleGraph.map (โ‡‘f) G).IsAcyclic) :
      theorem SimpleGraph.IsAcyclic.of_comap {V : Type u_1} {V' : Type u_2} {G : SimpleGraph V} (f : V' โ†ช V) (h : G.IsAcyclic) :
      theorem SimpleGraph.IsAcyclic.induce {V : Type u_1} {G : SimpleGraph V} (h : G.IsAcyclic) (s : Set V) :

      A graph induced from an acyclic graph is acyclic.

      theorem SimpleGraph.IsAcyclic.subgraph {V : Type u_1} {G : SimpleGraph V} (h : G.IsAcyclic) (H : G.Subgraph) :

      A subgraph of an acyclic graph is acyclic.

      theorem SimpleGraph.IsAcyclic.anti {V : Type u_1} {G G' : SimpleGraph V} (hsub : G โ‰ค G') (h : G'.IsAcyclic) :

      A spanning subgraph of an acyclic graph is acyclic.

      theorem SimpleGraph.isAcyclic_sSup_of_isAcyclic_directedOn {V : Type u_1} (Hs : Set (SimpleGraph V)) (h_acyc : โˆ€ H โˆˆ Hs, H.IsAcyclic) (h_dir : DirectedOn (fun (x1 x2 : SimpleGraph V) => x1 โ‰ค x2) Hs) :

      The directed supremum of acyclic graphs is acylic.

      theorem SimpleGraph.exists_maximal_isAcyclic_of_le_isAcyclic {V : Type u_1} {G H : SimpleGraph V} (hHG : H โ‰ค G) (hH : H.IsAcyclic) :
      โˆƒ (H' : SimpleGraph V), H โ‰ค H' โˆง Maximal (fun (H : SimpleGraph V) => H โ‰ค G โˆง H.IsAcyclic) H'

      Every acyclic subgraph H โ‰ค G is contained in a maximal such subgraph.

      A connected component of an acyclic graph is a tree.

      theorem SimpleGraph.IsTree.of_subsingleton {V : Type u_1} [Nonempty V] [Subsingleton V] {G : SimpleGraph V} :
      theorem SimpleGraph.isAcyclic_iff_forall_adj_isBridge {V : Type u_1} {G : SimpleGraph V} :
      G.IsAcyclic โ†” โˆ€ โฆƒv w : Vโฆ„, G.Adj v w โ†’ G.IsBridge s(v, w)
      theorem SimpleGraph.isAcyclic_iff_forall_edge_isBridge {V : Type u_1} {G : SimpleGraph V} :
      G.IsAcyclic โ†” โˆ€ โฆƒe : Sym2 Vโฆ„, e โˆˆ G.edgeSet โ†’ G.IsBridge e
      theorem SimpleGraph.IsAcyclic.path_unique {V : Type u_1} {G : SimpleGraph V} (h : G.IsAcyclic) {v w : V} (p q : G.Path v w) :
      p = q
      theorem SimpleGraph.isAcyclic_of_path_unique {V : Type u_1} {G : SimpleGraph V} (h : โˆ€ (v w : V) (p q : G.Path v w), p = q) :
      theorem SimpleGraph.isAcyclic_iff_path_unique {V : Type u_1} {G : SimpleGraph V} :
      G.IsAcyclic โ†” โˆ€ โฆƒv w : Vโฆ„ (p q : G.Path v w), p = q
      theorem SimpleGraph.IsAcyclic.mem_support_of_ne_mem_support_of_adj_of_isPath {V : Type u_1} {G : SimpleGraph V} (hG : G.IsAcyclic) {u v w : V} {p : G.Walk u v} {q : G.Walk u w} (hp : p.IsPath) (hq : q.IsPath) (hadj : G.Adj v w) (hv : v โˆ‰ q.support) :
      w โˆˆ p.support
      theorem SimpleGraph.IsAcyclic.ne_mem_support_of_support_of_adj_of_isPath {V : Type u_1} {G : SimpleGraph V} (hG : G.IsAcyclic) {u v w : V} {p : G.Walk u v} {q : G.Walk u w} (hp : p.IsPath) (hq : q.IsPath) (hadj : G.Adj v w) (hw : w โˆˆ p.support) :
      v โˆ‰ q.support
      theorem SimpleGraph.IsAcyclic.path_concat {V : Type u_1} {G : SimpleGraph V} (hG : G.IsAcyclic) {u v w : V} {p : G.Walk u v} {q : G.Walk u w} (hp : p.IsPath) (hq : q.IsPath) (hadj : G.Adj v w) (hv : v โˆˆ q.support) :
      q = p.concat hadj
      theorem SimpleGraph.isTree_iff_existsUnique_path {V : Type u_1} {G : SimpleGraph V} :
      G.IsTree โ†” Nonempty V โˆง โˆ€ (v w : V), โˆƒ! p : G.Walk v w, p.IsPath
      theorem SimpleGraph.IsAcyclic.isPath_iff_isChain {V : Type u_1} {G : SimpleGraph V} (hG : G.IsAcyclic) {v w : V} (p : G.Walk v w) :
      p.IsPath โ†” List.IsChain (fun (x1 x2 : Sym2 V) => x1 โ‰  x2) p.edges
      theorem SimpleGraph.IsAcyclic.isPath_iff_isTrail {V : Type u_1} {G : SimpleGraph V} (hG : G.IsAcyclic) {v w : V} (p : G.Walk v w) :
      p.IsPath โ†” p.IsTrail

      A minimally connected graph is a tree.

      theorem SimpleGraph.IsAcyclic.isAcyclic_sup_fromEdgeSet_of_not_reachable {V : Type u_1} {G : SimpleGraph V} {u v : V} (hnreach : ยฌG.Reachable u v) (hacyc : G.IsAcyclic) :
      (G โŠ” fromEdgeSet {s(u, v)}).IsAcyclic

      Connecting two unreachable vertices by an edge preserves acyclicity.

      theorem SimpleGraph.isAcyclic_add_edge_iff_of_not_reachable {V : Type u_1} {G : SimpleGraph V} (x y : V) (hxy : ยฌG.Reachable x y) :
      (G โŠ” fromEdgeSet {s(x, y)}).IsAcyclic โ†” G.IsAcyclic
      theorem SimpleGraph.isAcyclic_sup_fromEdgeSet_iff {V : Type u_1} {G : SimpleGraph V} {u v : V} :
      (G โŠ” fromEdgeSet {s(u, v)}).IsAcyclic โ†” G.IsAcyclic โˆง (G.Reachable u v โ†’ u = v โˆจ G.Adj u v)

      Adding an edge results in an acyclic graph iff the original graph was acyclic and the edge connects vertices that previously had no path between them.

      theorem SimpleGraph.reachable_eq_of_maximal_isAcyclic {V : Type u_1} {G : SimpleGraph V} (F : SimpleGraph V) (h : Maximal (fun (H : SimpleGraph V) => H โ‰ค G โˆง H.IsAcyclic) F) :

      The reachability relation of a maximal acyclic subgraph agrees with that of the larger graph.

      theorem SimpleGraph.maximal_isAcyclic_iff_reachable_eq {V : Type u_1} {G F : SimpleGraph V} (hle : F โ‰ค G) (hF : F.IsAcyclic) :
      Maximal (fun (F : SimpleGraph V) => F โ‰ค G โˆง F.IsAcyclic) F โ†” F.Reachable = G.Reachable

      A subgraph is maximal acyclic iff its reachability relation agrees with the larger graph.

      theorem SimpleGraph.Connected.maximal_le_isAcyclic_iff_isTree {V : Type u_1} {G T : SimpleGraph V} (hG : G.Connected) (hT : T โ‰ค G) :
      Maximal (fun (H : SimpleGraph V) => H โ‰ค G โˆง H.IsAcyclic) T โ†” T.IsTree

      A subgraph of a connected graph is maximal acyclic iff it is a tree.

      theorem SimpleGraph.isTree_iff_maximal_isAcyclic {V : Type u_1} {G : SimpleGraph V} :
      G.IsTree โ†” Nonempty V โˆง Maximal IsAcyclic G

      A maximally acyclic graph is a tree. This is similar to maximal_isAcyclic_iff_isTree except with Nonempty V as part of the iff rather than an assumption.

      theorem SimpleGraph.exists_isAcyclic_reachable_eq_le_of_le_of_isAcyclic {V : Type u_1} {G H : SimpleGraph V} (hH_le : H โ‰ค G) (hH_isAcyclic : H.IsAcyclic) :
      โˆƒ (F : SimpleGraph V), H โ‰ค F โˆง F โ‰ค G โˆง F.IsAcyclic โˆง F.Reachable = G.Reachable

      Every acyclic subgraph can be extended to a spanning forest.

      theorem SimpleGraph.exists_isAcyclic_reachable_eq_le {V : Type u_1} {G : SimpleGraph V} :
      โˆƒ F โ‰ค G, F.IsAcyclic โˆง F.Reachable = G.Reachable

      Every graph has a spanning forest.

      theorem SimpleGraph.Connected.exists_isTree_le_of_le_of_isAcyclic {V : Type u_1} {G H : SimpleGraph V} (h : G.Connected) (hH_le : H โ‰ค G) (hH_isAcyclic : H.IsAcyclic) :
      โˆƒ (F : SimpleGraph V), H โ‰ค F โˆง F โ‰ค G โˆง F.IsTree

      Every acyclic subgraph of a connected graph can be extended to a spanning tree.

      theorem SimpleGraph.Connected.exists_isTree_le {V : Type u_1} {G : SimpleGraph V} (h : G.Connected) :
      โˆƒ T โ‰ค G, T.IsTree

      Every connected graph has a spanning tree.

      Every connected graph on n vertices has at least n-1 edges.

      theorem SimpleGraph.IsTree.minDegree_eq_one_of_nontrivial {V : Type u_1} {G : SimpleGraph V} (h : G.IsTree) [Fintype V] [Nontrivial V] [DecidableRel G.Adj] :
      G.minDegree = 1

      The minimum degree of all vertices in a nontrivial tree is one.

      theorem SimpleGraph.IsTree.exists_vert_degree_one_of_nontrivial {V : Type u_1} {G : SimpleGraph V} [Fintype V] [Nontrivial V] [DecidableRel G.Adj] (h : G.IsTree) :
      โˆƒ (v : V), G.degree v = 1

      A nontrivial tree has a vertex of degree one.

      theorem SimpleGraph.Connected.induce_compl_singleton_of_degree_eq_one {V : Type u_1} {G : SimpleGraph V} (hconn : G.Connected) {v : V} [Fintype โ†‘(G.neighborSet v)] (hdeg : G.degree v = 1) :

      The graph resulting from removing a vertex of degree one from a connected graph is connected.

      A finite nontrivial connected graph contains a vertex that leaves the graph connected if removed.

      A finite connected graph contains a vertex that leaves the graph preconnected if removed.

      theorem SimpleGraph.IsAcyclic.dist_ne_of_adj {V : Type u_1} {G : SimpleGraph V} (hG : G.IsAcyclic) {u v w : V} (hadj : G.Adj v w) (hreach : G.Reachable u v) :
      G.dist u v โ‰  G.dist u w
      theorem SimpleGraph.IsTree.dist_ne_of_adj {V : Type u_1} {G : SimpleGraph V} (hG : G.IsTree) (u : V) {v w : V} (hadj : G.Adj v w) :
      G.dist u v โ‰  G.dist u w
      theorem SimpleGraph.IsAcyclic.dist_eq_dist_add_one_of_adj_of_reachable {V : Type u_1} {G : SimpleGraph V} (hG : G.IsAcyclic) (u : V) {v w : V} (hadj : G.Adj v w) (hreach : G.Reachable u v) :
      G.dist u v = G.dist u w + 1 โˆจ G.dist u w = G.dist u v + 1
      theorem SimpleGraph.IsTree.dist_eq_dist_add_one_of_adj {V : Type u_1} {G : SimpleGraph V} (hG : G.IsTree) (u : V) {v w : V} (hadj : G.Adj v w) :
      G.dist u v = G.dist u w + 1 โˆจ G.dist u w = G.dist u v + 1
      noncomputable def SimpleGraph.IsTree.coloringTwoOfVert {V : Type u_1} {G : SimpleGraph V} (hG : G.IsTree) (u : V) :
      G.Coloring (Fin 2)

      The unique two-coloring of a tree that colors the given vertex with zero

      Instances For
        noncomputable def SimpleGraph.IsTree.coloringTwo {V : Type u_1} {G : SimpleGraph V} (hG : G.IsTree) :
        G.Coloring (Fin 2)

        Arbitrary coloring with two colors for a tree

        Instances For
          noncomputable def SimpleGraph.IsAcyclic.coloringTwoOfVerts {V : Type u_1} {G : SimpleGraph V} (hG : G.IsAcyclic) (verts : G.ConnectedComponent โ†’ V) (h : โˆ€ (C : G.ConnectedComponent), verts C โˆˆ C) :
          G.Coloring (Fin 2)

          The unique two-coloring of a forest that colors the given vertices with zero

          Instances For
            noncomputable def SimpleGraph.IsAcyclic.coloringTwo {V : Type u_1} {G : SimpleGraph V} (hG : G.IsAcyclic) :
            G.Coloring (Fin 2)

            Arbitrary coloring with two colors for a forest

            Instances For

              An acyclic graph (forest) is 2-colorable.

              theorem SimpleGraph.IsTree.colorable_two {V : Type u_1} {G : SimpleGraph V} (hG : G.IsTree) :

              A tree is 2-colorable.

              The chromatic number of an acyclic graph (forest) is at most 2.

              The chromatic number of a tree is at most 2.

              theorem SimpleGraph.exists_isCycle_of_two_le_isEdgeReachable {V : Type u_1} {G : SimpleGraph V} {u v : V} (huv : u โ‰  v) {n : โ„•} (hn : 2 โ‰ค n) (h : G.IsEdgeReachable n u v) :
              โˆƒ (w : G.Walk u u), w.IsCycle