Documentation

GraphLib.Graph.Basic

Graph structures #

This file introduces a small hierarchy of graph-like combinatorial structures on a vertex type α. Each structure carries its vertex and edge sets explicitly.

Design rationale #

We intentionally diverge from Mathlib's graph definitions (Mathlib.Combinatorics.Graph.Basic, Mathlib.Combinatorics.SimpleGraph.Basic), prioritizing representations that support algorithmic reasoning. In graph algorithm design, it is common to manipulate graphs dynamically (adding or removing nodes/edges, contracting edges, etc.). We therefore use set-based definitions for both vertex and edge sets with minimal additional axioms, reducing early proof obligations and keeping proofs closer to their textbook counterparts.

Main definitions #

Notation #

Main API #

The structure fields are named with a ' suffix (e.g. incidence', loopless'). The preferred API restates these in terms of V(G) and E(G):

Main forgetful maps #

The corresponding Coe instances are registered.

structure GraphLib.Edge (α : Type u_3) (β : Type u_4) :
Type (max u_3 u_4)

An undirected edge with a label of type β and an unordered pair of endpoints.

  • edgeLabel : β

    The edge label, used to distinguish parallel edges.

  • endpoints : Sym2 α

    The unordered pair of endpoints.

Instances For
    @[implicit_reducible]
    instance GraphLib.instDecidableEqEdge {α✝ : Type u_3} {β✝ : Type u_4} [DecidableEq α✝] [DecidableEq β✝] :
    DecidableEq (Edge α✝ β✝)
    Equations
    def GraphLib.instDecidableEqEdge.decEq {α✝ : Type u_3} {β✝ : Type u_4} [DecidableEq α✝] [DecidableEq β✝] (x✝ x✝¹ : Edge α✝ β✝) :
    Decidable (x✝ = x✝¹)
    Equations
    Instances For
      structure GraphLib.DiEdge (α : Type u_3) (β : Type u_4) :
      Type (max u_3 u_4)

      A directed edge with a label of type β and an ordered pair of endpoints.

      • edgeLabel : β

        The edge label, used to distinguish parallel edges.

      • endpoints : α × α

        The ordered pair (source, target) of endpoints.

      Instances For
        def GraphLib.instDecidableEqDiEdge.decEq {α✝ : Type u_3} {β✝ : Type u_4} [DecidableEq α✝] [DecidableEq β✝] (x✝ x✝¹ : DiEdge α✝ β✝) :
        Decidable (x✝ = x✝¹)
        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          @[implicit_reducible]
          instance GraphLib.instDecidableEqDiEdge {α✝ : Type u_3} {β✝ : Type u_4} [DecidableEq α✝] [DecidableEq β✝] :
          DecidableEq (DiEdge α✝ β✝)
          Equations
          structure GraphLib.Graph (α : Type u_3) (β : Type u_4) :
          Type (max u_3 u_4)

          A general graph on vertex type α with edge labels in β. Each edge bundles a label and an unordered pair of endpoints. Parallel edges and loops are permitted, and both the vertex and edge sets may be infinite.

          Instances For
            structure GraphLib.SimpleGraph (α : Type u_3) :
            Type u_3

            A simple graph on α with edges as unordered pairs of distinct vertices.

            Instances For
              structure GraphLib.DiGraph (α : Type u_3) (β : Type u_4) :
              Type (max u_3 u_4)

              A directed graph on vertex type α with edge labels in β. Each edge bundles a label and an ordered pair of endpoints. Parallel edges and loops are permitted, and both the vertex and edge sets may be infinite.

              Instances For
                structure GraphLib.SimpleDiGraph (α : Type u_3) :
                Type u_3

                A simple directed graph on α with edges as ordered pairs of distinct vertices.

                Instances For
                  def GraphLib.SimpleGraph.toGraph {α : Type u_1} (G : SimpleGraph α) :
                  Graph α (Sym2 α)

                  Forget the looplessness axiom of a SimpleGraph, viewing it as a Graph whose edges are Edge α (Sym2 α) with the pair as both label and endpoints.

                  Equations
                  Instances For
                    def GraphLib.SimpleDiGraph.toDiGraph {α : Type u_1} (G : SimpleDiGraph α) :
                    DiGraph α (α × α)

                    Forget the looplessness axiom of a SimpleDiGraph, viewing it as a DiGraph whose edges are DiEdge α (α × α) with the pair as both label and endpoints.

                    Equations
                    Instances For
                      class GraphLib.HasVertexSet (G : Type u_3) (V : outParam (Type u_4)) :
                      Type (max u_3 u_4)

                      Typeclass for graph-like structures that have a vertex set.

                      • vertexSet : GV

                        The vertex set of the graph.

                      Instances
                        class GraphLib.HasEdgeSet (G : Type u_3) (E : outParam (Type u_4)) :
                        Type (max u_3 u_4)

                        Typeclass for graph-like structures that have an edge set.

                        • edgeSet : GE

                          The edge set of the graph.

                        Instances
                          @[implicit_reducible]
                          instance GraphLib.instHasVertexSetGraphSet {α : Type u_3} {β : Type u_4} :
                          HasVertexSet (Graph α β) (Set α)
                          Equations
                          @[implicit_reducible]
                          instance GraphLib.instHasVertexSetDiGraphSet {α : Type u_3} {β : Type u_4} :
                          HasVertexSet (DiGraph α β) (Set α)
                          Equations
                          @[implicit_reducible]
                          instance GraphLib.instHasEdgeSetGraphSetSym2 {α : Type u_3} {β : Type u_4} :
                          HasEdgeSet (Graph α β) (Set (Sym2 α))
                          Equations
                          @[implicit_reducible]
                          instance GraphLib.instHasEdgeSetDiGraphSetProd {α : Type u_3} {β : Type u_4} :
                          HasEdgeSet (DiGraph α β) (Set (α × α))
                          Equations

                          Notation for the vertex set of a graph.

                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For

                            Notation for the edge set of a graph.

                            Equations
                            • One or more equations did not get rendered due to their size.
                            Instances For
                              theorem GraphLib.Graph.incidence {α : Type u_1} {β : Type u_2} (G : Graph α β) {e : Sym2 α} (he : e HasEdgeSet.edgeSet G) {v : α} (hv : v e) :
                              theorem GraphLib.SimpleGraph.incidence {α : Type u_1} (G : SimpleGraph α) {e : Sym2 α} (he : e HasEdgeSet.edgeSet G) {v : α} (hv : v e) :
                              theorem GraphLib.SimpleGraph.loopless {α : Type u_1} (G : SimpleGraph α) {e : Sym2 α} (he : e HasEdgeSet.edgeSet G) :
                              theorem GraphLib.DiGraph.incidence {α : Type u_1} {β : Type u_2} (G : DiGraph α β) {e : α × α} (he : e HasEdgeSet.edgeSet G) :
                              theorem GraphLib.SimpleDiGraph.loopless {α : Type u_1} (G : SimpleDiGraph α) {e : α × α} (he : e HasEdgeSet.edgeSet G) :
                              e.1 e.2