Documentation

HexGraph.Sparse

def Hex.SparseGraph.offsetsFrom {α : Type u_1} :
List (List α) → Nat → List Nat

Kernel-reducible offset accumulation, including the final endpoint.

Equations
Instances For
    @[simp]
    theorem Hex.SparseGraph.offsetsFrom_eq {α : Type u_1} (rows : List (List α)) (start : Nat) :
    offsetsFrom rows start = List.scanl (fun (off : Nat) (row : List α) => off + row.length) start rows
    def Hex.SparseGraph.offsetsOf {α : Type u_1} (rows : List (List α)) :

    Offsets of consecutive adjacency rows, including the final endpoint.

    Equations
    Instances For
      @[simp]
      theorem Hex.SparseGraph.length_offsetsOf {α : Type u_1} (rows : List (List α)) :
      (offsetsOf rows).length = rows.length + 1
      theorem Hex.SparseGraph.get_offsetsOf {α : Type u_1} (rows : List (List α)) (i : Nat) (hi : i ≤ rows.length) :

      An offset is the size of the preceding rows.

      def Hex.SparseGraph.row {α : Type u_1} (offsets : Array Nat) (neighbors : Array α) (i : Nat) :

      A row of compressed adjacency, with an exclusive end offset.

      Equations
      Instances For
        theorem Hex.SparseGraph.row_pack {α : Type u_1} (rows : List (List α)) (i : Nat) (hi : i < rows.length) :
        (row (offsetsOf rows).toArray rows.flatten.toArray i).toList = rows[i]

        Packing consecutive rows and extracting one recovers it exactly.

        def Hex.SparseGraph.Layout {α : Type u_1} (n : Nat) (offsets : Array Nat) (neighbors : Array α) :

        The arrays consist of exactly n consecutive rows, without gaps or padding. The row witness is proof data and is erased from the executable graph.

        Equations
        Instances For
          structure Hex.SparseGraph (n : Nat) :

          A finite simple undirected graph with compressed, sorted adjacency lists.

          Instances For
            def Hex.SparseGraph.nbrs {n : Nat} (G : SparseGraph n) (i : Fin n) :

            The sorted neighbours of a vertex. Extracting a row copies its entries.

            Equations
            Instances For
              def Hex.SparseGraph.adj {n : Nat} (G : SparseGraph n) (i j : Fin n) :

              Adjacency is membership in a compressed row.

              Equations
              Instances For
                @[simp]
                theorem Hex.SparseGraph.mem_nbrs {n : Nat} (G : SparseGraph n) (i j : Fin n) :
                j ∈ G.nbrs i ↔ G.adj i j = true
                theorem Hex.SparseGraph.adj_symm {n : Nat} (G : SparseGraph n) (i j : Fin n) :
                G.adj i j = G.adj j i
                @[simp]
                theorem Hex.SparseGraph.adj_self {n : Nat} (G : SparseGraph n) (i : Fin n) :
                G.adj i i = false
                def Hex.SparseGraph.degree {n : Nat} (G : SparseGraph n) (i : Fin n) :

                Degree is the difference between consecutive offsets.

                Equations
                Instances For
                  def Hex.SparseGraph.ofRows {n : Nat} (rows : Vector (List (Fin n)) n) (hs : ∀ (i : Fin n), List.Pairwise (fun (x1 x2 : Fin n) => x1 < x2) rows[i]) (hr : ∀ (i j : Fin n), j ∈ rows[i] ↔ i ∈ rows[j]) (hl : ∀ (i : Fin n), ¬i ∈ rows[i]) :

                  Pack a vector of sorted, symmetric, loopless neighbour lists.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    @[simp]
                    theorem Hex.SparseGraph.nbrs_ofRows {n : Nat} (rows : Vector (List (Fin n)) n) (hs : ∀ (i : Fin n), List.Pairwise (fun (x1 x2 : Fin n) => x1 < x2) rows[i]) (hr : ∀ (i j : Fin n), j ∈ rows[i] ↔ i ∈ rows[j]) (hl : ∀ (i : Fin n), ¬i ∈ rows[i]) (i : Fin n) :
                    ((ofRows rows hs hr hl).nbrs i).toList = rows[i]

                    Dense conversion is explicit and allocates the full Boolean matrix.

                    Equations
                    Instances For
                      @[simp]
                      theorem Hex.SparseGraph.adj_toDense {n : Nat} (G : SparseGraph n) (i j : Fin n) :
                      G.toDense.adj i j = G.adj i j
                      @[simp]

                      The offset array includes both endpoints of every row.

                      @[simp]
                      theorem Hex.SparseGraph.degree_eq_size {n : Nat} (G : SparseGraph n) (i : Fin n) :
                      G.degree i = (G.nbrs i).size

                      The constant-time degree operation counts the entries of the row.

                      theorem Hex.SparseGraph.ext_arrays {n : Nat} {G H : SparseGraph n} (ho : G.offsets = H.offsets) (hn : G.neighbors = H.neighbors) :
                      G = H

                      Equality of the two stored arrays determines the graph.

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

                      Sorted rows and a packed layout make graph equality extensional.

                      theorem Hex.SparseGraph.ext_iff {n : Nat} {G H : SparseGraph n} :
                      G = H ↔ ∀ (i j : Fin n), G.adj i j = H.adj i j
                      theorem Hex.SparseGraph.eq_iff_adj {n : Nat} {G H : SparseGraph n} :
                      G = H ↔ ∀ (i j : Fin n), G.adj i j = H.adj i j
                      @[instance_reducible]
                      Equations

                      The edgeless graph stores n + 1 zero offsets and no neighbours.

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

                        Explicit conversion scans the dense matrix once to build sorted sparse rows.

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