Documentation

CslibFrontier.Computability.Complexity.Problems.MaxTwoSAT

MAX 2-SAT is NP-complete #

MaxTwoSAT consists of instances x : MaxTwoSATInstance (Cslib.Complexity.encMaxTwoSAT) pairing a formula x.formula in conjunctive normal form with at most two literals per clause and a target x.target such that some assignment satisfies at least x.target clauses of x.formula, counted with multiplicity. Garey, Johnson and Stockmeyer proved it NP-complete Garey, Johnson and Stockmeyer (attribution from secondary sources; the theorem number is not checked against the paper), although 2-satisfiability itself is in NL (Cslib.Complexity.TwoSAT.mem_NL).

The reduction is their ten-clause gadget. For a clause a ∨ b ∨ c and a fresh variable w, the formula MaxTwoSAT.gadget a b c w has the ten clauses a, b, c, w, ¬a ∨ ¬b, ¬a ∨ ¬c, ¬b ∨ ¬c, a ∨ ¬w, b ∨ ¬w, c ∨ ¬w. Every assignment satisfies at most seven of them; some value of w reaches seven exactly when the assignment satisfies a ∨ b ∨ c, and otherwise at most six are satisfied (MaxTwoSAT.gadgetScore). The table depends only on the truth values of a, b, c, so repeated literals are harmless. The reduction toMaxTwoSAT starts from ExactThreeSAT, doubles the source variables so that the odd numbers are fresh, puts one gadget on each clause, and asks for seven satisfied clauses per gadget; a formula with a clause of another width becomes a fixed no-instance. Composed with the padding toExactThreeSAT, which repeats a literal of every clause of one or two literals, this reduces ThreeSAT to MaxTwoSAT.

Main definitions #

Main results #

References #

An instance (formula, target) of MAX 2-SAT.

  • formula : Logic.PL.CNF ℕ

    The formula in conjunctive normal form, with at most two literals per clause.

  • target : ℕ

    The minimum number of clauses that must be satisfied.

Instances For
    theorem Cslib.Complexity.MaxTwoSATInstance.ext {x y : MaxTwoSATInstance} (formula : x.formula = y.formula) (target : x.target = y.target) :
    x = y
    theorem Cslib.Complexity.encMaxTwoSAT_formula_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → MaxTwoSATInstance} :
    Turing.MultiTapeTM.ComputableInSpace g✝ encIn✝ encMaxTwoSAT S✝ → Turing.MultiTapeTM.ComputableInSpace (fun (a : γ✝) => (g✝ a).formula) encIn✝ encCNF S✝

    Encoding of MaxTwoSATInstance as (formula, target) with target in binary.

    Instances For
      theorem Cslib.Complexity.encMaxTwoSAT_target_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → MaxTwoSATInstance} :
      theorem Cslib.Complexity.encMaxTwoSAT_mk_inO {γ : Type} {encIn : γ ↪ List Bool} {x0 : γ → Logic.PL.CNF ℕ} {T0 S0 x1 T1 S1 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInO x0 encIn encCNF T0 S0) (h1 : Turing.MultiTapeTM.ComputableInO x1 encIn Turing.MultiTapeTM.encNat T1 S1) :
      Turing.MultiTapeTM.ComputableInO (fun (x : γ) => { formula := x0 x, target := x1 x }) encIn encMaxTwoSAT (fun (x : γ) => T0 x + T1 x) fun (x : γ) => S0 x + S1 x
      theorem Cslib.Complexity.encMaxTwoSAT_mk_budget {γ : Type} {encIn : γ ↪ List Bool} {budget : γ → ℕ} {x0 : γ → Logic.PL.CNF ℕ} {x1 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInSpace x0 encIn encCNF budget) (h1 : Turing.MultiTapeTM.ComputableInSpace x1 encIn Turing.MultiTapeTM.encNat budget) :
      Turing.MultiTapeTM.ComputableInSpace (fun (x : γ) => { formula := x0 x, target := x1 x }) encIn encMaxTwoSAT budget
      @[reducible, inline]

      The tuple of the fields of encMaxTwoSAT.

      Instances For

        Maximum 2-satisfiability: the instances x : MaxTwoSATInstance such that every clause of x.formula has at most two literals and some assignment satisfies at least x.target clauses of x.formula, counted with multiplicity.

        Instances For
          @[simp]
          theorem Cslib.Complexity.mem_MaxTwoSAT_iff {φ : Logic.PL.CNF ℕ} {K : ℕ} :
          { formula := φ, target := K } ∈ MaxTwoSAT ↔ (∀ c ∈ φ, List.length c ≤ 2) ∧ ∃ (σ : ℕ → Bool), K ≤ List.countP (Logic.PL.Clause.eval σ) φ

          Membership in MaxTwoSAT, unfolded.

          Membership in NP #

          The verifier for MaxTwoSAT: check that every clause has at most two literals and count the clauses satisfied by the certificate assignment of SAT.assignment.

          Instances For

            MaxTwoSAT.verifier verifies MaxTwoSAT with certificates as long as the encoded instance: the certificate lists the values of the variables in order of first occurrence.

            Checking the clause widths and counting the satisfied clauses is polynomial-time: the count is computed in unary and compared with the binary target.

            The gadget #

            The ten-clause gadget of Garey, Johnson and Stockmeyer for the clause a ∨ b ∨ c, with the variable w: the unit clauses a, b, c, w, the clauses ¬a ∨ ¬b, ¬a ∨ ¬c, ¬b ∨ ¬c, and the clauses a ∨ ¬w, b ∨ ¬w, c ∨ ¬w.

            Instances For

              The number of satisfied clauses of a gadget whose literals take the values x, y, z and whose variable takes the value q.

              Instances For

                The number of satisfied clauses of a gadget depends only on the values of its literals and of its variable.

                A gadget never has more than seven satisfied clauses.

                The majority of three truth values.

                Instances For
                  theorem Cslib.Complexity.MaxTwoSAT.gadgetScore_majority {x y z : Bool} (h : (x || y || z) = true) :
                  gadgetScore x y z (majority x y z) = 7

                  If the clause holds, setting the variable to the majority of its literals satisfies seven clauses of the gadget.

                  If the clause fails, the gadget has at most six satisfied clauses.

                  The reduction #

                  Double the variable of a literal; the odd variables are then free for the gadgets.

                  Instances For

                    The gadget of the clause numbered i, whose first three literals are doubled, with the fresh variable 2 i + 1.

                    Instances For

                      The reduction from ExactThreeSAT to MaxTwoSAT: a formula all of whose clauses have three literals becomes the gadgets of its clauses, with target seven satisfied clauses per gadget. Any other formula becomes the formula with one empty clause and target one, a fixed no-instance: no assignment satisfies the empty clause.

                      Instances For

                        A formula is in ExactThreeSAT exactly when its image under toMaxTwoSAT is in MaxTwoSAT.

                        Polynomial time #

                        ThreeSAT reduces to MaxTwoSAT in polynomial time: pad every clause to three literals by repetition (toExactThreeSAT), then apply toMaxTwoSAT.

                        MAX 2-SAT is NP-complete Garey, Johnson and Stockmeyer (attribution from secondary sources). The target K is in binary, and clauses of one literal are allowed.