Documentation

CslibFrontier.Computability.Complexity.Problems.Graph

Graphs given by vertex and edge lists #

The graph problems (IndependentSet, Clique, VertexCover, KColoring, the Hamiltonian problems, GraphIsomorphism, …) take a graph (Cslib.Complexity.Graph) as a list of declared vertices, possibly with repetitions, and a list of edges, encoded in binary (Cslib.Complexity.encGraph). Its mathematical reading is a Mathlib simple graph on ℕ (Cslib.Complexity.Graph.toSimpleGraph), or the simple graph induced on the subtype of declared vertices (Cslib.Complexity.Graph.induced): two distinct vertices are adjacent when an edge joins them in either direction.

This module holds the tools these problems share:

Main definitions #

Main results #

References #

A graph on natural numbers, given by its vertices and its edges.

  • vertices : List ℕ

    The declared vertices of the graph, possibly with repetitions.

  • edges : List (ℕ × ℕ)

    The declared edges of the graph as pairs of vertex identifiers.

Instances For
    theorem Cslib.Complexity.Graph.ext {x y : Graph} (vertices : x.vertices = y.vertices) (edges : x.edges = y.edges) :
    x = y
    Instances For
      @[instance_reducible]
      theorem Cslib.Complexity.encGraph_vertices_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → Graph} :
      @[reducible, inline]

      The tuple of the fields of encGraph.

      Instances For
        theorem Cslib.Complexity.encGraph_mk_inO {γ : Type} {encIn : γ ↪ List Bool} {x0 : γ → List ℕ} {T0 S0 : γ → ℕ} {x1 : γ → List (ℕ × ℕ)} {T1 S1 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInO x0 encIn (Turing.MultiTapeTM.encList Turing.MultiTapeTM.encNat) T0 S0) (h1 : Turing.MultiTapeTM.ComputableInO x1 encIn (Turing.MultiTapeTM.encList (Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encNat Turing.MultiTapeTM.encNat)) T1 S1) :
        Turing.MultiTapeTM.ComputableInO (fun (x : γ) => { vertices := x0 x, edges := x1 x }) encIn encGraph (fun (x : γ) => T0 x + T1 x) fun (x : γ) => S0 x + S1 x

        Graphs encoded by framed lists of binary vertex labels and binary edge pairs.

        Instances For

          The simple graph of an edge list: two distinct vertices are adjacent when an edge joins them, in either direction.

          Instances For

            Adjacency in the simple graph of an edge list: two distinct vertices joined by an edge in either direction. It is not a simp lemma, so that the adjacency stays folded until a proof unfolds it.

            The simple graph induced by G on its declared vertices.

            Instances For
              @[simp]
              theorem Cslib.Complexity.Graph.induced_adj {G : Graph} {u v : { v : ℕ // v ∈ G.vertices }} :
              G.induced.Adj u v ↔ G.toSimpleGraph.Adj ↑u ↑v

              Declared vertices #

              A graph has no more declared vertices than the length of its encoding.

              A graph lists no more vertices and edges than the length of its encoding.

              The declared vertices of G without repetitions, in the order of their first occurrences.

              Instances For

                The distinct declared vertices are the declared vertices.

                The distinct declared vertices are listed without repetitions.

                The distinct declared vertices are as many as the elements of the vertex list.

                A graph has no more distinct vertices than the length of its encoding.

                Positions in G.distinctVertices enumerate the declared vertices.

                Instances For

                  Subset verification on encoded graphs #

                  Executable adjacency test on an edge list: two distinct vertices are adjacent when an edge joins them in either direction.

                  Instances For

                    Testing adjacency between computed vertices of a computed graph is polynomial-time. This is Cslib.Complexity.Graph.computableInPolyTime_adjBool in the compositional form that fun_prop uses.

                    Verify a cardinality-m vertex subset problem with pairwise relation rel: select distinct declared vertices from G.vertices by the certificate mask, compare the selected count with m in binary, and test rel on all distinct selected pairs.

                    Instances For
                      theorem Cslib.Complexity.Graph.exists_subtype_pairwise_iff {G : Graph} {P : ℕ → ℕ → Prop} {m : ℕ} :
                      (∃ (S : Finset { v : ℕ // v ∈ G.vertices }), ((↑S).Pairwise fun (u v : { v : ℕ // v ∈ G.vertices }) => P ↑u ↑v) ∧ S.card = m) ↔ ∃ (S : Finset ℕ), (∀ v ∈ S, v ∈ G.vertices) ∧ (↑S).Pairwise P ∧ S.card = m

                      A finite subset of declared vertices with a pairwise property corresponds to a finite subset of ℕ contained in G.vertices with the same pairwise property and cardinality.

                      theorem Cslib.Complexity.Graph.isVerifier_verifySubset {rel : Graph → ℕ → ℕ → Bool} {P : Graph → ℕ → ℕ → Prop} (hrel : ∀ (G : Graph) (u v : ℕ), u ≠ v → (rel G u v = true ↔ P G u v)) :
                      IsVerifier (Turing.MultiTapeTM.encPair encGraph Turing.MultiTapeTM.encNat) Polynomial.X (verifySubset rel) {x : Graph × ℕ | ∃ (S : Finset { v : ℕ // v ∈ x.1.vertices }), ((↑S).Pairwise fun (u v : { v : ℕ // v ∈ x.1.vertices }) => P x.1 ↑u ↑v) ∧ S.card = x.2}

                      verifySubset is a polynomial-length verifier for any graph subset problem whose pairwise relation agrees with rel on distinct vertices.

                      Unary blocks #

                      The certificate of N bits writing the numbers f a in unary blocks of width m: bit m * a + c is set when c < f a.

                      Instances For
                        @[simp]
                        theorem Cslib.Complexity.length_unaryBlocks (m N : ℕ) (f : ℕ → ℕ) :
                        (unaryBlocks m N f).length = N
                        theorem Cslib.Complexity.countP_unaryBlocks {m N a : ℕ} {f : ℕ → ℕ} (hf : f a ≤ m) (hN : m * (a + 1) ≤ N) :
                        List.countP (fun (c : ℕ) => (unaryBlocks m N f).getD (m * a + c) false) (List.range m) = f a

                        Counting the set bits of block a of unaryBlocks m N f reads f a, when f a fits in the block and the block fits in the certificate.

                        Ordering verification #

                        Executable test that p lists every vertex of V exactly once and nothing else.

                        Instances For

                          enumeratesBool V p holds exactly when p lists the members of V without repetition.

                          The list of vertices described by a certificate w, for a vertex list V of length m: w is read as blocks of m bits, one for each distinct vertex of V, and the block numbered a names the entry of V whose position is its number of set bits, or 0 if there is none.

                          Instances For
                            theorem Cslib.Complexity.Graph.exists_decodeVertexList_eq {V p : List ℕ} (hp : p.Nodup) (hpV : ∀ (v : ℕ), v ∈ p ↔ v ∈ V) {n : ℕ} (hn : V.length ≤ n) :
                            ∃ (w : List Bool), w.length = n ^ 2 ∧ decodeVertexList V w = p

                            Every list of the distinct vertices of V, each listed once, is described by a certificate of length n ^ 2, for every n at least the length of V.

                            def Cslib.Complexity.Graph.verifyOrdering {α : Type} (V : α → List ℕ) (check : α → List ℕ → Bool) (x : α × List Bool) :

                            Verify a vertex ordering problem: decode a list of vertices from the certificate (decodeVertexList), check that it lists every vertex of V x exactly once, and test it with check.

                            Instances For
                              theorem Cslib.Complexity.Graph.isVerifier_verifyOrdering {α : Type} {enc : α ↪ List Bool} {V : α → List ℕ} {check : α → List ℕ → Bool} {P : α → List ℕ → Prop} (hV : ∀ (a : α), (V a).length ≤ (enc a).length) (hcheck : ∀ (a : α) (p : List ℕ), check a p = true ↔ P a p) :
                              IsVerifier enc (Polynomial.X ^ 2) (verifyOrdering V check) {a : α | ∃ (p : List ℕ), p.Nodup ∧ (∀ (v : ℕ), v ∈ p ↔ v ∈ V a) ∧ P a p}

                              verifyOrdering verifies the existence of an ordering of the vertices satisfying P, with certificates of length n ^ 2 for instances of encoded length n, as long as check decides P and the vertex list is not longer than the encoded instance.