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 {V : Type u} {x y : SimpleGraph V} (Adj : x.Adj = y.Adj) :
                x = y
                def SimpleGraph.mk' {V : Type u} :
                { adj : V โ†’ V โ†’ Bool // (โˆ€ (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 : V โ†’ V โ†’ Bool // (โˆ€ (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 : V โ†’ V โ†’ Prop) :

                      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 : V โ†’ V โ†’ Prop) (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 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) :
                              theorem SimpleGraph.Adj.ne {V : Type u} {G : SimpleGraph V} {a b : V} (h : G.Adj a b) :
                              theorem SimpleGraph.Adj.ne' {V : Type u} {G : SimpleGraph V} {a b : V} (h : G.Adj a b) :
                              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) :
                              @[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
                              instance SimpleGraph.symm_adj {ฮน : Sort u_1} {V : Type u} (G : SimpleGraph V) (f : ฮน โ†’ V) :
                              Std.Symm fun (i j : ฮน) => G.Adj (f i) (f j)

                              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} :

                                  For graphs G, H, G โ‰ค H iff โˆ€ a b, G.Adj a b โ†’ H.Adj a b.

                                  Equations
                                    theorem SimpleGraph.le_iff_adj {V : Type u} {G H : SimpleGraph V} :
                                    G โ‰ค H โ†” โˆ€ (v w : V), G.Adj v w โ†’ H.Adj v w
                                    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) :
                                      (x โŠ” y).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) :
                                        (x โŠ“ y).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) :
                                          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
                                            @[simp]
                                            theorem SimpleGraph.sSup_adj {V : Type u} {s : Set (SimpleGraph V)} {a b : V} :
                                            (sSup s).Adj a b โ†” โˆƒ G โˆˆ s, G.Adj a b
                                            @[simp]
                                            theorem SimpleGraph.sInf_adj {V : Type u} {a b : V} {s : Set (SimpleGraph V)} :
                                            (sInf s).Adj a b โ†” (โˆ€ G โˆˆ s, 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 โ†” โˆ€ G โˆˆ s, 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
                                            @[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) :
                                                    theorem SimpleGraph.ne_bot_iff_exists_adj {V : Type u} {G : SimpleGraph V} :
                                                    G โ‰  โŠฅ โ†” โˆƒ (a : V) (b : V), G.Adj a b
                                                    theorem SimpleGraph.eq_top_iff_forall_ne_adj {V : Type u} {G : SimpleGraph V} :
                                                    G = โŠค โ†” โˆ€ (a b : V), a โ‰  b โ†’ G.Adj a b
                                                    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
                                                        @[simp]

                                                        All vertices are in the support of the complete graph if there is more than one vertex.

                                                        @[simp]

                                                        The support of the empty graph is empty.

                                                        @[simp]

                                                        Only the empty graph has empty support.

                                                        @[simp]

                                                        The support of a graph is empty if there at most one vertex.

                                                        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

                                                            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} :
                                                                    @[simp]
                                                                    theorem SimpleGraph.not_mem_edgeSet_of_isDiag {V : Type u} (G : SimpleGraph V) {e : Sym2 V} :
                                                                    e.IsDiag โ†’ e โˆ‰ G.edgeSet
                                                                    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.

                                                                    @[deprecated SimpleGraph.edgeSet_subset_compl_diagSet (since := "2025-12-10")]

                                                                    Alias of SimpleGraph.edgeSet_subset_compl_diagSet.

                                                                    @[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]

                                                                    This lemma, combined with edgeSet_sdiff and edgeSet_fromEdgeSet, allows proving (G \ fromEdgeSet s).edgeSet = 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 โˆง โˆƒ e โˆˆ G.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) :
                                                                    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)) :
                                                                              theorem SimpleGraph.disjoint_left {V : Type u} {G H : SimpleGraph V} :
                                                                              Disjoint G H โ†” โˆ€ (x y : V), G.Adj x y โ†’ ยฌH.Adj x y

                                                                              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.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
                                                                                  @[simp]
                                                                                  theorem SimpleGraph.mem_neighborSet {V : Type u} (G : SimpleGraph V) (v w : V) :
                                                                                  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
                                                                                      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
                                                                                          def SimpleGraph.incidenceSetEquivNeighborSet {V : Type u} (G : SimpleGraph V) [DecidableEq V] (v : V) :
                                                                                          โ†‘(G.incidenceSet v) โ‰ƒ โ†‘(G.neighborSet v)

                                                                                          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
                                                                                              def SimpleGraph.IsCompleteBetween {V : Type u} (G : SimpleGraph V) (s t : Set V) :

                                                                                              The condition that the portion of the simple graph G between s and t is complete, that is, every vertex in s is adjacent to every vertex in t, and vice versa.

                                                                                              Equations
                                                                                                Instances For
                                                                                                  theorem SimpleGraph.IsCompleteBetween.symm {V : Type u} (G : SimpleGraph V) {s t : Set V} :

                                                                                                  Alias of the forward direction of SimpleGraph.isCompleteBetween_comm.