Documentation

CslibFrontier.Computability.Complexity.Problems.Graph.CountingCNF

Polynomial-time counting CNF reductions for graph problems #

Executable polynomial-time CNF encodings for three classical graph counting problems on Cslib.Complexity.Graph, preserving exact solution counts with explicit assignment bijections:

  1. Independent sets (Graph.toIndepSetCNF): n = |V| variables, clause width 2, preserving Nat.card {S // G.induced.IsIndepSet S}.
  2. Proper q-colourings (Graph.toColoringCNF q): n = q * |V| variables, clause width ≤ max q 2, preserving Nat.card (G.induced.Coloring (Fin q)).
  3. Perfect matchings (Graph.toPerfectMatchingCNF): n ≤ 1 + 4 |V| + 7 |E| = O(|V| + |E|) variables, exact clause width 3, compiled via sequential linear-size exact-one De Morgan circuits (Cslib.Circuits.Boolean.seqExactlyOneAll) and tseitinSatCNF, preserving Nat.card {M : G.induced.Subgraph // M.IsPerfectMatching} (Tseitin 1983, Cygan et al.).

Main definitions #

Main results #

References #

1. Independent sets (n = |V|, width 2) #

Executable width-2 CNF encoding of the independent sets of G.induced on |V| variables.

Every clause of G.toIndepSetCNF has exact length 2.

@[simp]

G.toIndepSetCNF has exactly G.1.toFinset.card occurring variables.

Occurring variables of G.toIndepSetCNF are bounded by (encGraph G).length.

Explicit bijection between satisfying assignments of G.toIndepSetCNF on G.1.toFinset and independent sets of G.induced.

Exact model count of G.toIndepSetCNF: number of independent sets of G.induced.

2. Proper q-colourings (n = q * |V|, width ≤ max q 2) #

Natural variable index encoding (v, c) as q * G.distinctVertices.idxOf v + c.

Executable CNF encoding of proper q-colourings of G.induced over dense natural variables 0, …, q * |V| - 1, with clause width at most max q 2.

Every clause of G.toColoringCNF q has width at most max q 2.

The occurring variables of G.toColoringCNF q are precisely Finset.range (q * |V|).

@[simp]

G.toColoringCNF q uses exactly q * G.1.toFinset.card variables.

noncomputable def Cslib.Complexity.Graph.coloringCNFEquiv (q : ℕ) (G : Graph) :
{ σ : ↥(Finset.range (q * G.distinctVertices.length)) → Bool // Logic.PL.CNF.eval (fun (k : ℕ) => if hk : k ∈ Finset.range (q * G.distinctVertices.length) then σ ⟨k, hk⟩ else false) (toColoringCNF q G) = true } ≃ G.induced.Coloring (Fin q)

Explicit bijection between satisfying assignments of G.toColoringCNF q on Finset.range (q * |V|) and proper q-colourings of G.induced.

Exact model count of G.toColoringCNF q: number of proper q-colourings of G.induced.

3. Perfect matchings (n = O(|V| + |E|), width 3) #

Exact-one wire lists for G.edgeList: for each distinct vertex v ∈ G.distinctVertices, the positions i < G.edgeList.length of edges incident to v.

Linear-size sequential exact-one De Morgan gate list and output wire for G.

Width-3 CNF encoding of perfect matchings via sequential exact-one De Morgan circuits and Tseitin compilation: exact clause width 3 and O(|V| + |E|) variables and clauses.

G.edgeList has at most G.2.length entries.

Total length of all vertex-incidence lists is at most 2 * G.edgeList.length, since each edge contributes to at most two vertex constraints.

Explicit bijection between declared-range models of G.toPerfectMatchingCNF and perfect matchings of G.induced.

Exact model count of G.toPerfectMatchingCNF (modelCount), preserving the number of perfect matchings up to unused free wires (and exact equality when every wire occurs).

Polynomial-time certificate for Graph.toPerfectMatchingCNF #