Documentation

HexGraph.Basic

structure Hex.Graph (n : Nat) :

A finite simple undirected graph on the vertex set Fin n, as a dense Boolean adjacency matrix constrained to be symmetric and loopless.

Instances For
    @[inline]
    def Hex.Graph.adj {n : Nat} (G : Graph n) (i j : Fin n) :

    Executable adjacency test: G.adj i j is true exactly when {i, j} is an edge of G. O(1).

    Equations
    Instances For
      theorem Hex.Graph.adj_eq_getElem {n : Nat} (G : Graph n) (i j : Fin n) :
      G.adj i j = G.adjMatrix[i][j]

      adj reads the adjacency matrix entry.

      theorem Hex.Graph.adj_symm {n : Nat} (G : Graph n) (i j : Fin n) :
      G.adj i j = G.adj j i

      Adjacency is symmetric.

      @[simp]
      theorem Hex.Graph.adj_self {n : Nat} (G : Graph n) (i : Fin n) :
      G.adj i i = false

      Adjacency is irreflexive.

      theorem Hex.Graph.ne_of_adj {n : Nat} {G : Graph n} {i j : Fin n} (h : G.adj i j = true) :
      i j

      Adjacent vertices are distinct.

      theorem Hex.Graph.ext_adjMatrix {n : Nat} {G H : Graph n} (h : G.adjMatrix = H.adjMatrix) :
      G = H

      Two graphs with equal adjacency matrices are equal.

      theorem Hex.Graph.ext {n : Nat} {G H : Graph n} (h : ∀ (i j : Fin n), G.adj i j = H.adj i j) :
      G = H

      Two graphs are equal when they have the same edges.

      theorem Hex.Graph.ext_iff {n : Nat} {G H : Graph n} :
      G = H ∀ (i j : Fin n), G.adj i j = H.adj i j
      theorem Hex.Graph.eq_iff_adj {n : Nat} {G H : Graph n} :
      G = H ∀ (i j : Fin n), G.adj i j = H.adj i j

      Equality of graphs is exactly equality of the represented edge relation.

      @[instance_reducible]
      Equations
      def Hex.Graph.ofAdj {n : Nat} (f : Fin nFin nBool) (hs : ∀ (i j : Fin n), f i j = f j i) (hi : ∀ (i : Fin n), f i i = false) :

      Build a graph from a symmetric irreflexive Boolean adjacency function.

      Equations
      Instances For
        @[simp]
        theorem Hex.Graph.adj_ofAdj {n : Nat} (f : Fin nFin nBool) (hs : ∀ (i j : Fin n), f i j = f j i) (hi : ∀ (i : Fin n), f i i = false) (i j : Fin n) :
        (ofAdj f hs hi).adj i j = f i j
        def Hex.Graph.ofRel {n : Nat} (f : Fin nFin nBool) :

        Build a graph from an arbitrary Boolean relation by symmetrizing it and removing loops: i and j are adjacent when i ≠ j and the relation holds in either direction.

        Equations
        Instances For
          @[simp]
          theorem Hex.Graph.adj_ofRel {n : Nat} (f : Fin nFin nBool) (i j : Fin n) :
          (ofRel f).adj i j = (i != j && (f i j || f j i))

          The graph on n vertices with no edges.

          Equations
          Instances For
            @[simp]
            theorem Hex.Graph.adj_empty {n : Nat} (i j : Fin n) :
            (empty n).adj i j = false

            The complete graph on n vertices.

            Equations
            Instances For
              @[simp]
              theorem Hex.Graph.adj_complete {n : Nat} (i j : Fin n) :
              (complete n).adj i j = (i != j)
              def Hex.Graph.edgeListAdj {n : Nat} (edges : List (Nat × Nat)) (i j : Fin n) :

              The membership test behind ofEdges?: an unordered edge {i, j} is present when the input list contains it in either orientation.

              Equations
              Instances For
                theorem Hex.Graph.edgeListAdj_symm {n : Nat} (edges : List (Nat × Nat)) (i j : Fin n) :
                edgeListAdj edges i j = edgeListAdj edges j i

                A well-formed input for ofEdges? n: both endpoints in range, no loops.

                Equations
                Instances For
                  def Hex.Graph.ofEdges? (n : Nat) (edges : List (Nat × Nat)) :

                  Checked edge-list builder. Returns none when some listed edge has an endpoint out of range or is a loop; otherwise builds the graph whose edges are the listed unordered pairs, collapsing duplicates in either orientation.

                  Equations
                  Instances For
                    def Hex.Graph.ofEdges {n : Nat} (edges : List (Fin n × Fin n)) :

                    Total edge-list builder over Fin pairs: the graph whose edges are the listed unordered pairs, collapsing duplicates in either orientation and dropping diagonal pairs. Beware that numeric literals in a Fin n pair wrap modulo n; use ofEdges? to range-check plain Nat input instead.

                    Equations
                    Instances For
                      @[simp]
                      theorem Hex.Graph.adj_ofEdges {n : Nat} (edges : List (Fin n × Fin n)) (i j : Fin n) :
                      (ofEdges edges).adj i j = (i != j && (decide ((i, j) edges) || decide ((j, i) edges)))

                      The graph built by ofEdges has exactly the listed undirected edges, less the diagonal.

                      theorem Hex.Graph.isSome_ofEdges? (n : Nat) (edges : List (Nat × Nat)) :
                      (ofEdges? n edges).isSome = edges.all (validEdge n)

                      ofEdges? succeeds exactly on well-formed inputs.

                      theorem Hex.Graph.adj_ofEdges? {n : Nat} {edges : List (Nat × Nat)} {G : Graph n} (h : ofEdges? n edges = some G) (i j : Fin n) :
                      G.adj i j = (decide ((i, j) edges) || decide ((j, i) edges))

                      The graph built by ofEdges? has exactly the listed undirected edges.

                      def Hex.Graph.nbrs {n : Nat} (G : Graph n) (i : Fin n) :

                      The sorted duplicate-free array of neighbours of i. O(n) adjacency reads; the order is increasing vertex order.

                      Equations
                      Instances For
                        theorem Hex.Graph.mem_nbrs {n : Nat} {G : Graph n} {i j : Fin n} :
                        j G.nbrs i G.adj i j = true
                        def Hex.Graph.degree {n : Nat} (G : Graph n) (i : Fin n) :

                        The degree of a vertex.

                        Equations
                        Instances For
                          def Hex.Graph.relabel {n : Nat} (G : Graph n) (f : Fin nFin n) :

                          Relabel a graph along a vertex map: (G.relabel f).adj i j = G.adj (f i) (f j). For a bijective f this is relabelling by the inverse bijection; stated for an arbitrary map because neither invariant needs injectivity.

                          Equations
                          Instances For
                            @[simp]
                            theorem Hex.Graph.adj_relabel {n : Nat} (G : Graph n) (f : Fin nFin n) (i j : Fin n) :
                            (G.relabel f).adj i j = G.adj (f i) (f j)

                            The adjacency correspondence for relabelling.

                            @[simp]
                            theorem Hex.Graph.relabel_id {n : Nat} (G : Graph n) :
                            theorem Hex.Graph.relabel_relabel {n : Nat} (G : Graph n) (f g : Fin nFin n) :
                            (G.relabel f).relabel g = G.relabel (f g)