Documentation

CslibFrontier.Computability.Complexity.Problems.Coloring

Graph coloring #

KColoring k is the set of graphs, given by a list of vertices and a list of edges, whose declared vertices can be colored with k colors so that adjacent vertices get different colors [Kar72]; ThreeColoring is KColoring 3. Graphs are read through Cslib.Complexity.Graph.toSimpleGraph restricted to the declared vertices (SimpleGraph.induce), and colorings through SimpleGraph.Colorable. Edges with an undeclared endpoint and self-loops are therefore ignored. A graph without declared vertices belongs to every KColoring k, and for k = 0 these are the only members.

A certificate for KColoring k gives each declared vertex k bits, at the position of its first occurrence; the color is the number of set bits, which must be below k.

The reduction SAT.toThreeColoring is the palette, variable and clause gadget construction for 3-colorability, a standard exercise Sipser, Chapter 7. Three palette vertices T, F and B form a triangle; the two literals of each variable form a triangle with B, so they take the colors of T and F in some order. The gadget of a clause is a chain of OR gadgets: its stage 0 is adjacent to T and B, hence colored like F; stage j + 1 is a triangle attached to the output of stage j and to the j-th literal, whose output can take the color of T exactly when one of them does; and the output of the last stage is adjacent to F and B, hence colored like T. Chaining handles clauses of every width, including the empty clause, so the reduction is from SAT; it also reduces ThreeSAT after rejecting clauses with more than three literals.

For k = m + 3 colors, SAT.toKColoring m adds m universal vertices adjacent to every vertex and to each other. They take m colors of their own, and the gadget vertices are colored with the remaining three, so KColoring k is NP-complete for every k ≥ 3.

Main definitions #

Main results #

References #

The graphs whose declared vertices can be colored with k colors, adjacent vertices getting different colors [Kar72].

Instances For
    @[reducible, inline]

    The graphs whose declared vertices can be colored with three colors, adjacent vertices getting different colors Sipser, Chapter 7.

    Instances For
      theorem Cslib.Complexity.mem_KColoring_iff {k : ℕ} {G : Graph} :
      G ∈ KColoring k ↔ ∃ (c : ℕ → ℕ), (∀ v ∈ G.vertices, c v < k) ∧ ∀ u ∈ G.vertices, ∀ v ∈ G.vertices, G.toSimpleGraph.Adj u v → c u ≠ c v

      Membership in KColoring k as a coloring by natural numbers below k.

      The verifier #

      The color of v described by the certificate w: the number of set bits among the k bits of w from position k * i on, where i is the first occurrence of v in V.

      Instances For

        The verifier for KColoring k: every declared vertex gets a color below k from the certificate, and no two adjacent declared vertices get the same color.

        Instances For

          KColoring.verifier k verifies KColoring k with certificates of k bits per symbol of the encoded graph.

          The gadget graph #

          The palette vertex of color c: color 0 reads true, 1 reads false and 2 is the base color.

          Instances For

            The vertex of a literal of φ, numbered by the first occurrence of its variable in φ.

            Instances For

              Vertex r of stage j of the gadget of clause i; vertex 2 is the output of the stage.

              Instances For

                The edges between the two literals of the variable x and the base palette vertex.

                Instances For

                  Stage j + 1 of the gadget of clause i: a triangle attached to the output of stage j and to the literal l.

                  Instances For

                    The gadget of the clause c with index i: the output of stage 0 is adjacent to the true and base palette vertices, one stage follows for each literal, and the output of the last stage is adjacent to the false and base palette vertices.

                    Instances For

                      The edges of the gadget graph of φ: the palette triangle, the variable triangles and the clause gadgets.

                      Instances For

                        The reduction from SAT to ThreeColoring: the gadget graph of φ, whose declared vertices are the endpoints of its edges.

                        Instances For

                          Correctness of the reduction #

                          Correctness of the 3-coloring reduction. A formula is satisfiable exactly when its gadget graph is 3-colorable.

                          Polynomial-time reduction #

                          The reduction toThreeColoring is computable in polynomial time: vertex labels are computed in unary from clause, position and first-occurrence indices, then converted to binary.

                          Size #

                          The 3-coloring reduction has linear size. On formulas with m clauses of at most k literals, the graph of SAT.toThreeColoring has at most (24 k + 12) m + 9 vertices and edges in total, counted as listed.

                          More colors #

                          The r-th universal vertex of the reduction to KColoring (m + 3).

                          Instances For

                            The edges of the gadget graph of φ together with m universal vertices, each adjacent to every vertex of the gadget graph and to the other universal vertices.

                            Instances For

                              The reduction from SAT to KColoring (m + 3): the gadget graph of φ with m universal vertices, which take m colors of their own.

                              Instances For

                                Correctness of the (m + 3)-coloring reduction. A formula is satisfiable exactly when its gadget graph with m universal vertices is (m + 3)-colorable.

                                The reduction toKColoring m is computable in polynomial time for every fixed m.

                                ThreeSAT reduces to ThreeColoring in polynomial time: a formula with a clause of more than three literals is mapped to the gadget graph of the empty clause, which is not 3-colorable.

                                For k ≥ 3, SAT reduces to KColoring k in polynomial time via SAT.toKColoring (k - 3).

                                For k ≥ 3, KColoring k is NP-hard.