Documentation

Mathlib.Combinatorics.SimpleGraph.Basic

Simple graphs #

This module defines simple graphs on a vertex type V as an irreflexive symmetric relation.

Main definitions #

TODO #

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 with default 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
    Instances For

      Use aesop_graph? to pass along a Try this suggestion when using aesop_graph

      Equations
        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
            Instances For
              structure SimpleGraph (V : Type u) :

              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.

              Instances For
                theorem SimpleGraph.ext_iff {V : Type u} {x y : SimpleGraph V} :
                x = y x.Adj = y.Adj
                theorem SimpleGraph.ext {V : Type u} {x y : SimpleGraph V} (Adj : x.Adj = y.Adj) :
                x = y
                def SimpleGraph.mk' {V : Type u} :
                { adj : VVBool // (∀ (x y : V), adj x y = adj y x) ∀ (x : V), ¬adj x x = true } SimpleGraph V

                Constructor for simple graphs using a symmetric irreflexive boolean function.

                Equations
                  Instances For
                    @[simp]
                    theorem SimpleGraph.mk'_apply_adj {V : Type u} (x : { adj : VVBool // (∀ (x y : V), adj x y = adj y x) ∀ (x : V), ¬adj x x = true }) (v w : V) :
                    (mk' x).Adj v w = (x v w = true)

                    We can enumerate simple graphs by enumerating all functions V → V → Bool and filtering on whether they are symmetric and irreflexive.

                    Equations

                      There are finitely many simple graphs on a given finite type.

                      def SimpleGraph.fromRel {V : Type u} (r : VVProp) :

                      Construct the simple graph induced by the given relation. It symmetrizes the relation and makes it irreflexive.

                      Equations
                        Instances For
                          @[simp]
                          theorem SimpleGraph.fromRel_adj {V : Type u} (r : VVProp) (v w : V) :
                          (fromRel r).Adj v w v w (r v w r w v)
                          def completeBipartiteGraph (V : Type u_1) (W : Type u_2) :

                          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
                              @[simp]
                              theorem completeBipartiteGraph_adj (V : Type u_1) (W : Type u_2) (v w : V W) :
                              @[simp]
                              theorem SimpleGraph.irrefl {V : Type u} (G : SimpleGraph V) {v : V} :
                              ¬G.Adj v v
                              theorem SimpleGraph.adj_comm {V : Type u} (G : SimpleGraph V) (u v : V) :
                              G.Adj u v G.Adj v u
                              theorem SimpleGraph.adj_symm {V : Type u} (G : SimpleGraph V) {u v : V} (h : G.Adj u v) :
                              G.Adj v u
                              theorem SimpleGraph.Adj.symm {V : Type u} {G : SimpleGraph V} {u v : V} (h : G.Adj u v) :
                              G.Adj v u
                              theorem SimpleGraph.ne_of_adj {V : Type u} (G : SimpleGraph V) {a b : V} (h : G.Adj a b) :
                              a b
                              theorem SimpleGraph.Adj.ne {V : Type u} {G : SimpleGraph V} {a b : V} (h : G.Adj a b) :
                              a b
                              theorem SimpleGraph.Adj.ne' {V : Type u} {G : SimpleGraph V} {a b : V} (h : G.Adj a b) :
                              b a
                              theorem SimpleGraph.ne_of_adj_of_not_adj {V : Type u} (G : SimpleGraph V) {v w x : V} (h : G.Adj v x) (hn : ¬G.Adj w x) :
                              v w
                              @[simp]
                              theorem SimpleGraph.adj_inj {V : Type u} {G H : SimpleGraph V} :
                              G.Adj = H.Adj G = H
                              theorem SimpleGraph.adj_congr_of_sym2 {V : Type u} (G : SimpleGraph V) {u v w x : V} (h : s(u, v) = s(w, x)) :
                              G.Adj u v G.Adj w x

                              The relation that one SimpleGraph is a subgraph of another. Note that this should be spelled .

                              Equations
                                Instances For
                                  instance SimpleGraph.instLE {V : Type u} :
                                  Equations
                                    @[simp]
                                    theorem SimpleGraph.isSubgraph_eq_le {V : Type u} :
                                    IsSubgraph = fun (x1 x2 : SimpleGraph V) => x1 x2
                                    instance SimpleGraph.instMax {V : Type u} :

                                    The supremum of two graphs x ⊔ y has edges where either x or y have edges.

                                    Equations
                                      @[simp]
                                      theorem SimpleGraph.sup_adj {V : Type u} (x y : SimpleGraph V) (v w : V) :
                                      (xy).Adj v w x.Adj v w y.Adj v w
                                      instance SimpleGraph.instMin {V : Type u} :

                                      The infimum of two graphs x ⊓ y has edges where both x and y have edges.

                                      Equations
                                        @[simp]
                                        theorem SimpleGraph.inf_adj {V : Type u} (x y : SimpleGraph V) (v w : V) :
                                        (xy).Adj v w x.Adj v w y.Adj v w

                                        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
                                          @[simp]
                                          theorem SimpleGraph.compl_adj {V : Type u} (G : SimpleGraph V) (v w : V) :
                                          G.Adj v w v w ¬G.Adj v w
                                          instance SimpleGraph.sdiff {V : Type u} :

                                          The difference of two graphs x \ y has the edges of x with the edges of y removed.

                                          Equations
                                            @[simp]
                                            theorem SimpleGraph.sdiff_adj {V : Type u} (x y : SimpleGraph V) (v w : V) :
                                            (x \ y).Adj v w x.Adj v w ¬y.Adj v w
                                            Equations
                                              Equations
                                                @[simp]
                                                theorem SimpleGraph.sSup_adj {V : Type u} {s : Set (SimpleGraph V)} {a b : V} :
                                                (sSup s).Adj a b Gs, G.Adj a b
                                                @[simp]
                                                theorem SimpleGraph.sInf_adj {V : Type u} {a b : V} {s : Set (SimpleGraph V)} :
                                                (sInf s).Adj a b (∀ Gs, G.Adj a b) a b
                                                @[simp]
                                                theorem SimpleGraph.iSup_adj {ι : Sort u_1} {V : Type u} {a b : V} {f : ιSimpleGraph V} :
                                                (⨆ (i : ι), f i).Adj a b ∃ (i : ι), (f i).Adj a b
                                                @[simp]
                                                theorem SimpleGraph.iInf_adj {ι : Sort u_1} {V : Type u} {a b : V} {f : ιSimpleGraph V} :
                                                (⨅ (i : ι), f i).Adj a b (∀ (i : ι), (f i).Adj a b) a b
                                                theorem SimpleGraph.sInf_adj_of_nonempty {V : Type u} {a b : V} {s : Set (SimpleGraph V)} (hs : s.Nonempty) :
                                                (sInf s).Adj a b Gs, G.Adj a b
                                                theorem SimpleGraph.iInf_adj_of_nonempty {ι : Sort u_1} {V : Type u} {a b : V} [Nonempty ι] {f : ιSimpleGraph V} :
                                                (⨅ (i : ι), f i).Adj a b ∀ (i : ι), (f i).Adj a b

                                                For graphs G, H, G ≤ H iff ∀ a b, G.Adj a b → H.Adj a b.

                                                Equations
                                                  @[reducible, inline]

                                                  The complete graph on a type V is the simple graph with all pairs of distinct vertices.

                                                  Equations
                                                    Instances For
                                                      @[reducible, inline]

                                                      The graph with no edges on a given vertex type V.

                                                      Equations
                                                        Instances For
                                                          @[simp]
                                                          theorem SimpleGraph.top_adj {V : Type u} (v w : V) :
                                                          .Adj v w v w
                                                          @[simp]
                                                          theorem SimpleGraph.bot_adj {V : Type u} (v w : V) :
                                                          Equations
                                                            Equations
                                                              def SimpleGraph.support {V : Type u} (G : SimpleGraph V) :
                                                              Set V

                                                              G.support is the set of vertices that form edges in G.

                                                              Equations
                                                                Instances For
                                                                  theorem SimpleGraph.mem_support {V : Type u} (G : SimpleGraph V) {v : V} :
                                                                  v G.support ∃ (w : V), G.Adj v w
                                                                  theorem SimpleGraph.support_mono {V : Type u} {G G' : SimpleGraph V} (h : G G') :
                                                                  def SimpleGraph.neighborSet {V : Type u} (G : SimpleGraph V) (v : V) :
                                                                  Set V

                                                                  G.neighborSet v is the set of vertices adjacent to v in G.

                                                                  Equations
                                                                    Instances For
                                                                      instance SimpleGraph.neighborSet.memDecidable {V : Type u} (G : SimpleGraph V) (v : V) [DecidableRel G.Adj] :
                                                                      DecidablePred fun (x : V) => x G.neighborSet v
                                                                      Equations

                                                                        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
                                                                          Instances For
                                                                            @[reducible, inline]
                                                                            abbrev SimpleGraph.edgeSet {V : Type u} (G : SimpleGraph V) :
                                                                            Set (Sym2 V)

                                                                            G.edgeSet is the edge set for G. This is an abbreviation for edgeSetEmbedding G that permits dot notation.

                                                                            Equations
                                                                              Instances For
                                                                                @[simp]
                                                                                theorem SimpleGraph.mem_edgeSet {V : Type u} (G : SimpleGraph V) {v w : V} :
                                                                                s(v, w) G.edgeSet G.Adj v w
                                                                                theorem SimpleGraph.edgeSet_inj {V : Type u} {G₁ G₂ : SimpleGraph V} :
                                                                                G₁.edgeSet = G₂.edgeSet G₁ = G₂
                                                                                @[simp]
                                                                                theorem SimpleGraph.edgeSet_subset_edgeSet {V : Type u} {G₁ G₂ : SimpleGraph V} :
                                                                                G₁.edgeSet G₂.edgeSet G₁ G₂
                                                                                @[simp]
                                                                                theorem SimpleGraph.edgeSet_ssubset_edgeSet {V : Type u} {G₁ G₂ : SimpleGraph V} :
                                                                                G₁.edgeSet G₂.edgeSet G₁ < G₂
                                                                                theorem SimpleGraph.edgeSet_mono {V : Type u} {G₁ G₂ : SimpleGraph V} :
                                                                                G₁ G₂G₁.edgeSet G₂.edgeSet

                                                                                Alias of the reverse direction of SimpleGraph.edgeSet_subset_edgeSet.

                                                                                theorem SimpleGraph.edgeSet_strict_mono {V : Type u} {G₁ G₂ : SimpleGraph V} :
                                                                                G₁ < G₂G₁.edgeSet G₂.edgeSet

                                                                                Alias of the reverse direction of SimpleGraph.edgeSet_ssubset_edgeSet.

                                                                                @[simp]
                                                                                theorem SimpleGraph.edgeSet_sup {V : Type u} (G₁ G₂ : SimpleGraph V) :
                                                                                (G₁G₂).edgeSet = G₁.edgeSet G₂.edgeSet
                                                                                @[simp]
                                                                                theorem SimpleGraph.edgeSet_inf {V : Type u} (G₁ G₂ : SimpleGraph V) :
                                                                                (G₁G₂).edgeSet = G₁.edgeSet G₂.edgeSet
                                                                                @[simp]
                                                                                theorem SimpleGraph.edgeSet_sdiff {V : Type u} (G₁ G₂ : SimpleGraph V) :
                                                                                (G₁ \ G₂).edgeSet = G₁.edgeSet \ G₂.edgeSet
                                                                                @[simp]
                                                                                theorem SimpleGraph.disjoint_edgeSet {V : Type u} {G₁ G₂ : SimpleGraph V} :
                                                                                Disjoint G₁.edgeSet G₂.edgeSet Disjoint G₁ G₂
                                                                                @[simp]
                                                                                @[simp]
                                                                                theorem SimpleGraph.edgeSet_sdiff_sdiff_isDiag {V : Type u} (G : SimpleGraph V) (s : Set (Sym2 V)) :
                                                                                G.edgeSet \ (s \ {e : Sym2 V | e.IsDiag}) = G.edgeSet \ s

                                                                                This lemma, combined with edgeSet_sdiff and edgeSet_from_edgeSet, allows proving (G \ from_edgeSet s).edge_set = G.edgeSet \ s by simp.

                                                                                theorem SimpleGraph.adj_iff_exists_edge {V : Type u} {G : SimpleGraph V} {v w : V} :
                                                                                G.Adj v w v w eG.edgeSet, v e w e

                                                                                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.

                                                                                theorem SimpleGraph.adj_iff_exists_edge_coe {V : Type u} {G : SimpleGraph V} {a b : V} :
                                                                                G.Adj a b ∃ (e : G.edgeSet), e = s(a, b)
                                                                                theorem SimpleGraph.edge_other_ne {V : Type u} (G : SimpleGraph V) {e : Sym2 V} (he : e G.edgeSet) {v : V} (h : v e) :
                                                                                Equations
                                                                                  Equations
                                                                                    instance SimpleGraph.fintypeEdgeSetSup {V : Type u} (G₁ G₂ : SimpleGraph V) [DecidableEq V] [Fintype G₁.edgeSet] [Fintype G₂.edgeSet] :
                                                                                    Fintype (G₁G₂).edgeSet
                                                                                    Equations
                                                                                      instance SimpleGraph.fintypeEdgeSetInf {V : Type u} (G₁ G₂ : SimpleGraph V) [DecidableEq V] [Fintype G₁.edgeSet] [Fintype G₂.edgeSet] :
                                                                                      Fintype (G₁G₂).edgeSet
                                                                                      Equations
                                                                                        instance SimpleGraph.fintypeEdgeSetSdiff {V : Type u} (G₁ G₂ : SimpleGraph V) [DecidableEq V] [Fintype G₁.edgeSet] [Fintype G₂.edgeSet] :
                                                                                        Fintype (G₁ \ G₂).edgeSet
                                                                                        Equations

                                                                                          fromEdgeSet constructs a SimpleGraph from a set of edges, without loops.

                                                                                          Equations
                                                                                            Instances For
                                                                                              @[simp]
                                                                                              theorem SimpleGraph.fromEdgeSet_adj {V : Type u} {v w : V} (s : Set (Sym2 V)) :
                                                                                              (fromEdgeSet s).Adj v w s(v, w) s v w
                                                                                              @[simp]
                                                                                              @[simp]
                                                                                              @[simp]
                                                                                              @[simp]
                                                                                              theorem SimpleGraph.fromEdgeSet_mono {V : Type u} {s t : Set (Sym2 V)} (h : s t) :

                                                                                              Incidence set #

                                                                                              def SimpleGraph.incidenceSet {V : Type u} (G : SimpleGraph V) (v : V) :
                                                                                              Set (Sym2 V)

                                                                                              Set of edges incident to a given vertex, aka incidence set.

                                                                                              Equations
                                                                                                Instances For
                                                                                                  theorem SimpleGraph.mk'_mem_incidenceSet_iff {V : Type u} (G : SimpleGraph V) {a b c : V} :
                                                                                                  s(b, c) G.incidenceSet a G.Adj b c (a = b a = c)
                                                                                                  theorem SimpleGraph.edge_mem_incidenceSet_iff {V : Type u} (G : SimpleGraph V) {a : V} {e : G.edgeSet} :
                                                                                                  e G.incidenceSet a a e
                                                                                                  theorem SimpleGraph.adj_of_mem_incidenceSet {V : Type u} (G : SimpleGraph V) {a b : V} {e : Sym2 V} (h : a b) (ha : e G.incidenceSet a) (hb : e G.incidenceSet b) :
                                                                                                  G.Adj a b
                                                                                                  Equations
                                                                                                    @[simp]
                                                                                                    theorem SimpleGraph.mem_neighborSet {V : Type u} (G : SimpleGraph V) (v w : V) :
                                                                                                    w G.neighborSet v G.Adj v w
                                                                                                    theorem SimpleGraph.notMem_neighborSet_self {V : Type u} (G : SimpleGraph V) {a : V} :
                                                                                                    aG.neighborSet a
                                                                                                    @[deprecated SimpleGraph.notMem_neighborSet_self (since := "2025-05-23")]
                                                                                                    theorem SimpleGraph.not_mem_neighborSet_self {V : Type u} (G : SimpleGraph V) {a : V} :
                                                                                                    aG.neighborSet a

                                                                                                    Alias of SimpleGraph.notMem_neighborSet_self.

                                                                                                    @[simp]
                                                                                                    theorem SimpleGraph.mem_incidenceSet {V : Type u} (G : SimpleGraph V) (v w : V) :
                                                                                                    s(v, w) G.incidenceSet v G.Adj v w
                                                                                                    theorem SimpleGraph.adj_incidenceSet_inter {V : Type u} (G : SimpleGraph V) {v : V} {e : Sym2 V} (he : e G.edgeSet) (h : v e) :
                                                                                                    def SimpleGraph.commonNeighbors {V : Type u} (G : SimpleGraph V) (v w : V) :
                                                                                                    Set V

                                                                                                    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.

                                                                                                    Equations
                                                                                                      Instances For
                                                                                                        theorem SimpleGraph.mem_commonNeighbors {V : Type u} (G : SimpleGraph V) {u v w : V} :
                                                                                                        u G.commonNeighbors v w G.Adj v u G.Adj w u
                                                                                                        theorem SimpleGraph.notMem_commonNeighbors_left {V : Type u} (G : SimpleGraph V) (v w : V) :
                                                                                                        vG.commonNeighbors v w
                                                                                                        @[deprecated SimpleGraph.notMem_commonNeighbors_left (since := "2025-05-23")]
                                                                                                        theorem SimpleGraph.not_mem_commonNeighbors_left {V : Type u} (G : SimpleGraph V) (v w : V) :
                                                                                                        vG.commonNeighbors v w

                                                                                                        Alias of SimpleGraph.notMem_commonNeighbors_left.

                                                                                                        @[deprecated SimpleGraph.notMem_commonNeighbors_right (since := "2025-05-23")]
                                                                                                        theorem SimpleGraph.not_mem_commonNeighbors_right {V : Type u} (G : SimpleGraph V) (v w : V) :
                                                                                                        wG.commonNeighbors v w

                                                                                                        Alias of SimpleGraph.notMem_commonNeighbors_right.

                                                                                                        instance SimpleGraph.decidableMemCommonNeighbors {V : Type u} (G : SimpleGraph V) [DecidableRel G.Adj] (v w : V) :
                                                                                                        DecidablePred fun (x : V) => x G.commonNeighbors v w
                                                                                                        Equations
                                                                                                          def SimpleGraph.otherVertexOfIncident {V : Type u} (G : SimpleGraph V) [DecidableEq V] {v : V} {e : Sym2 V} (h : e G.incidenceSet v) :
                                                                                                          V

                                                                                                          Given an edge incident to a particular vertex, get the other vertex on the edge.

                                                                                                          Equations
                                                                                                            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
                                                                                                                Instances For