Documentation

CslibFrontier.Computability.Complexity.Problems.SharpTwoSAT

#2SAT on general 2-CNF formulas is #P-complete under counting Turing reductions #

Counting the satisfying assignments of a 2-CNF formula whose literals may have either sign (SharpTwoSAT) belongs to #P and is #P-hard under polynomial-time counting Turing reductions (CountingTuringComplete encCNF SharpTwoSAT).

This is not Valiant's theorem. Valiant 1979 (§4, problem 7 and Theorem 1, p. 414, with reductions 6–7 on p. 415) proves that counting is #P-complete already for monotone 2-CNF formulas, those in which no variable is negated (p. 413), for an oracle that returns the function value (§2, p. 411). Hardness for general 2-CNF follows from the monotone case and not conversely. The reduction below queries formulas with literals of both signs (clauseWeightVarTauts, clauseWeightGadget), so it cannot call a monotone-only oracle. The monotone theorem is not proved in this library and remains open in #3672.

The construction and proof are original and do not follow the paper's route through matchings. For a CNF φ with m clauses, clauseWeightTwoSAT φ r is a 2-CNF formula with ∑ σ, (r + 1) ^ φ.countUnsat σ models, the sum being over assignments to the variables of φ. This is the value at r + 1 of a polynomial of degree at most m whose value at 0 is the model count of φ, and a division-free finite difference recovers that value from the counts for r = 0, …, m. Oracle answers are read through the library's bit-graph convention (AnswersBits).

Main definitions #

Main results #

References #

Number of satisfying assignments of φ on its occurring variables when every clause has length at most 2, and 0 otherwise (#2SAT). Literals of both signs are allowed: this is not the monotone problem of Valiant 1979.

The 2-CNF clause-weight gadget (original construction) #

Auxiliary clause-indicator variable index for clause i at weight parameter r.

Auxiliary chain variable index (i, j) (j < r - 1) at weight parameter r.

Width-2 tautology clauses ensuring every occurring variable v of φ appears at 2 * v.

Weight gadget for clause (c, i) at parameter r: forces zVar r i = false if c holds, and otherwise permits r + 1 extensions of (zVar r i, uVar r i 0, …, uVar r i (r - 2)).

The clause-weight 2-CNF formula at interpolation parameter r : ℕ.

Every clause of clauseWeightTwoSAT φ r has length at most 2.

SharpTwoSAT agrees with CNF.modelCount on clauseWeightTwoSAT φ r, whose clauses all have length at most 2.

Number of occurring variables of clauseWeightTwoSAT φ r is at most φ.vars.length + φ.length * (r + 1).

Binary size bound for SharpTwoSAT (clauseWeightTwoSAT φ r) whenever r ≤ φ.length.

Exact fibre counting and monotone Boolean chain cardinality #

theorem Cslib.Complexity.modelCount_clauseWeightTwoSAT (φ : Logic.PL.CNF ℕ) (r : ℕ) :
(clauseWeightTwoSAT φ r).modelCount = ∑ σ : ↥φ.vars.toFinset → Bool, (r + 1) ^ Logic.PL.CNF.countUnsat (fun (v : ℕ) => if hv : v ∈ φ.vars.toFinset then σ ⟨v, hv⟩ else false) φ

Exact model count of the clause-weight 2-CNF formula: clauseWeightTwoSAT φ r has ∑ σ : φ.vars.toFinset → Bool, (r + 1) ^ φ.countUnsat ext(σ) models, where ext(σ) extends σ by false outside the variables of φ.

Binomial finite-difference interpolation over ℤ and ℕ #

Exact integer finite-difference identity recovering SharpSAT φ from the 2-CNF counts SharpTwoSAT (clauseWeightTwoSAT φ r) for r = 0, …, φ.length.

Pure nonnegative combination recovering SharpSAT φ from the list of r = 0..φ.length answers [SharpTwoSAT (clauseWeightTwoSAT φ 0), …, SharpTwoSAT (clauseWeightTwoSAT φ φ.length)].

Polynomial-time certificates and #P-completeness of #2SAT #

#SAT reduces to #2SAT on general 2-CNF formulas by a polynomial-time counting Turing reduction. The reduction queries clauseWeightTwoSAT φ r for r = 0, …, φ.length; these formulas contain negated literals.

#2SAT on general 2-CNF formulas is #P-complete under polynomial-time counting Turing reductions. This is weaker than Theorem 1 of Valiant 1979, which proves completeness for monotone 2-CNF formulas: the hardness reduction used here queries formulas with negated literals.

If #2SAT is computable in polynomial time (FP), then P = NP.