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
  • One or more equations did not get rendered due to their size.
Instances For

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

    Equations
    • One or more equations did not get rendered due to their size.
    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
      • One or more equations did not get rendered due to their size.
      Instances For
        theorem SimpleGraph.ext {V : Type u} (x : SimpleGraph V) (y : SimpleGraph V) (Adj : x.Adj = y.Adj) :
        x = y
        theorem SimpleGraph.ext_iff {V : Type u} (x : SimpleGraph V) (y : SimpleGraph V) :
        x = y x.Adj = y.Adj
        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
          @[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 : V) (w : V) :
          (SimpleGraph.mk' x).Adj v w = (x v w = true)
          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
          • One or more equations did not get rendered due to their size.
          Instances For

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

            Equations
            • instFintypeSimpleGraph = { elems := Finset.map SimpleGraph.mk' Finset.univ, complete := }
            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 : V) (w : V) :
              (SimpleGraph.fromRel r).Adj v w v w (r v w r w v)

              The complete graph on a type V is the simple graph with all pairs of distinct vertices adjacent. In Mathlib, this is usually referred to as .

              Equations
              Instances For
                def emptyGraph (V : Type u) :

                The graph with no edges on a given vertex type V. Mathlib prefers the notation .

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

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

                    Equations
                    Instances For
                      Equations
                      • SimpleGraph.instLESimpleGraph = { le := SimpleGraph.IsSubgraph }
                      @[simp]
                      theorem SimpleGraph.isSubgraph_eq_le {V : Type u} :
                      SimpleGraph.IsSubgraph = fun (x x_1 : SimpleGraph V) => x x_1

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

                      Equations
                      • SimpleGraph.instSupSimpleGraph = { sup := fun (x y : SimpleGraph V) => { Adj := x.Adj y.Adj, symm := , loopless := } }
                      @[simp]
                      theorem SimpleGraph.sup_adj {V : Type u} (x : SimpleGraph V) (y : SimpleGraph V) (v : V) (w : V) :
                      (x y).Adj v w x.Adj v w y.Adj v w

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

                      Equations
                      • SimpleGraph.instInfSimpleGraph = { inf := fun (x y : SimpleGraph V) => { Adj := x.Adj y.Adj, symm := , loopless := } }
                      @[simp]
                      theorem SimpleGraph.inf_adj {V : Type u} (x : SimpleGraph V) (y : SimpleGraph V) (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
                      • SimpleGraph.hasCompl = { compl := fun (G : SimpleGraph V) => { Adj := fun (v w : V) => v w ¬G.Adj v w, symm := , loopless := } }
                      @[simp]
                      theorem SimpleGraph.compl_adj {V : Type u} (G : SimpleGraph V) (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
                      • SimpleGraph.sdiff = { sdiff := fun (x y : SimpleGraph V) => { Adj := x.Adj \ y.Adj, symm := , loopless := } }
                      @[simp]
                      theorem SimpleGraph.sdiff_adj {V : Type u} (x : SimpleGraph V) (y : SimpleGraph V) (v : V) (w : V) :
                      (x \ y).Adj v w x.Adj v w ¬y.Adj v w
                      Equations
                      • SimpleGraph.supSet = { sSup := fun (s : Set (SimpleGraph V)) => { Adj := fun (a b : V) => ∃ G ∈ s, G.Adj a b, symm := , loopless := } }
                      Equations
                      • SimpleGraph.infSet = { sInf := fun (s : Set (SimpleGraph V)) => { Adj := fun (a b : V) => (∀ ⦃G : SimpleGraph V⦄, G sG.Adj a b) a b, symm := , loopless := } }
                      @[simp]
                      theorem SimpleGraph.sSup_adj {V : Type u} {s : Set (SimpleGraph V)} {a : V} {b : V} :
                      (sSup s).Adj a b ∃ G ∈ s, G.Adj a b
                      @[simp]
                      theorem SimpleGraph.sInf_adj {V : Type u} {a : V} {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 : V} {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 : V} {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 : V} {b : V} {s : Set (SimpleGraph V)} (hs : Set.Nonempty s) :
                      (sInf s).Adj a b Gs, G.Adj a b
                      theorem SimpleGraph.iInf_adj_of_nonempty {ι : Sort u_1} {V : Type u} {a : V} {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
                      Equations
                      @[simp]
                      theorem SimpleGraph.top_adj {V : Type u} (v : V) (w : V) :
                      .Adj v w v w
                      @[simp]
                      theorem SimpleGraph.bot_adj {V : Type u} (v : V) (w : V) :
                      .Adj v w False
                      Equations
                      • SimpleGraph.instUniqueSimpleGraph = { toInhabited := { default := }, uniq := }
                      instance SimpleGraph.Sup.adjDecidable (V : Type u) (G : SimpleGraph V) (H : SimpleGraph V) [DecidableRel G.Adj] [DecidableRel H.Adj] :
                      DecidableRel (G H).Adj
                      Equations
                      instance SimpleGraph.Inf.adjDecidable (V : Type u) (G : SimpleGraph V) (H : SimpleGraph V) [DecidableRel G.Adj] [DecidableRel H.Adj] :
                      DecidableRel (G H).Adj
                      Equations
                      instance SimpleGraph.Sdiff.adjDecidable (V : Type u) (G : SimpleGraph V) (H : SimpleGraph V) [DecidableRel G.Adj] [DecidableRel H.Adj] :
                      DecidableRel (G \ H).Adj
                      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 SimpleGraph.support G ∃ (w : V), G.Adj v w
                        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 refl. (That is, s(v, w) ∈ G.edgeSet is definitionally equal to G.Adj v w.)

                          Equations
                          Instances For
                            @[inline, reducible]
                            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 : V} {w : V} :
                              s(v, w) SimpleGraph.edgeSet G G.Adj v w
                              theorem SimpleGraph.edgeSet_inj {V : Type u} {G₁ : SimpleGraph V} {G₂ : SimpleGraph V} :
                              @[simp]
                              theorem SimpleGraph.edgeSet_injective {V : Type u} :
                              Function.Injective SimpleGraph.edgeSet
                              theorem SimpleGraph.edgeSet_mono {V : Type u} {G₁ : SimpleGraph V} {G₂ : SimpleGraph V} :

                              Alias of the reverse direction of SimpleGraph.edgeSet_subset_edgeSet.

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

                              Alias of the reverse direction of SimpleGraph.edgeSet_ssubset_edgeSet.

                              @[simp]
                              @[simp]
                              @[simp]

                              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 : V} {w : V} :
                              G.Adj v w v w ∃ e ∈ SimpleGraph.edgeSet G, 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 : V} {b : V} :
                              G.Adj a b ∃ (e : (SimpleGraph.edgeSet G)), e = s(a, b)
                              theorem SimpleGraph.edge_other_ne {V : Type u} (G : SimpleGraph V) {e : Sym2 V} (he : e SimpleGraph.edgeSet G) {v : V} (h : v e) :
                              Equations
                              • SimpleGraph.fintypeEdgeSetBot = Eq.mpr inferInstance
                              Equations

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

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

                                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 : V} {b : V} {c : V} :
                                  s(b, c) SimpleGraph.incidenceSet G a G.Adj b c (a = b a = c)
                                  theorem SimpleGraph.mk'_mem_incidenceSet_left_iff {V : Type u} (G : SimpleGraph V) {a : V} {b : V} :
                                  s(a, b) SimpleGraph.incidenceSet G a G.Adj a b
                                  theorem SimpleGraph.mk'_mem_incidenceSet_right_iff {V : Type u} (G : SimpleGraph V) {a : V} {b : V} :
                                  s(a, b) SimpleGraph.incidenceSet G b G.Adj a b
                                  theorem SimpleGraph.adj_of_mem_incidenceSet {V : Type u} (G : SimpleGraph V) {a : V} {b : V} {e : Sym2 V} (h : a b) (ha : e SimpleGraph.incidenceSet G a) (hb : e SimpleGraph.incidenceSet G b) :
                                  G.Adj a b
                                  @[simp]
                                  theorem SimpleGraph.mem_neighborSet {V : Type u} (G : SimpleGraph V) (v : V) (w : V) :
                                  @[simp]
                                  theorem SimpleGraph.mem_incidenceSet {V : Type u} (G : SimpleGraph V) (v : V) (w : V) :
                                  s(v, w) SimpleGraph.incidenceSet G v G.Adj v w
                                  def SimpleGraph.commonNeighbors {V : Type u} (G : SimpleGraph V) (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} {v : V} {w : V} :
                                    u SimpleGraph.commonNeighbors G v w G.Adj v u G.Adj w u
                                    theorem SimpleGraph.commonNeighbors_top_eq {V : Type u} {v : V} {w : V} :
                                    SimpleGraph.commonNeighbors v w = Set.univ \ {v, w}
                                    def SimpleGraph.otherVertexOfIncident {V : Type u} (G : SimpleGraph V) [DecidableEq V] {v : V} {e : Sym2 V} (h : e SimpleGraph.incidenceSet G 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
                                      • One or more equations did not get rendered due to their size.
                                      Instances For

                                        Edge deletion #

                                        def SimpleGraph.deleteEdges {V : Type u} (G : SimpleGraph V) (s : Set (Sym2 V)) :

                                        Given a set of vertex pairs, remove all of the corresponding edges from the graph's edge set, if present.

                                        See also: SimpleGraph.Subgraph.deleteEdges.

                                        Equations
                                        Instances For
                                          @[simp]
                                          theorem SimpleGraph.deleteEdges_adj {V : Type u} (G : SimpleGraph V) (s : Set (Sym2 V)) (v : V) (w : V) :
                                          (SimpleGraph.deleteEdges G s).Adj v w G.Adj v w s(v, w)s