Documentation

CslibFrontier.Logics.Propositional.CNF.GraphCountingEncodings

CNF counting encodings for independent sets, vertex colourings, and set splitting #

Executable CNF encodings with explicit assignment bijections (Equiv), exact model counts, and clause/variable parameter bounds for three combinatorial counting problems:

  1. Independent sets (indepSetCNF, parameter n = |V|, width 2): one variable per declared vertex, a width-2 tautology per vertex so every declared vertex occurs, and ¬x_u ∨ ¬x_v per edge. Bijects satisfying assignments with independent vertex sets (indepSetCNFEquiv).
  2. Proper q-colourings (coloringCNF, parameter n = q * |V|, width ≤ max q 2): one-hot colour indicators CNF.exactlyOne per vertex and pairwise conflict clauses ¬x_{u,c} ∨ ¬x_{v,c} per edge and colour c < q. Bijects satisfying assignments with SimpleGraph.Coloring (Fin q) (coloringCNFEquiv).
  3. Ordered k-set splitting (setSplittingCNF, parameter n = |U|, width ≤ k): positive and negative clauses per subset (CNF.evalNAE). Bijects satisfying assignments with ordered splitting bipartitions (A, B) (setSplittingCNFEquiv).

Main definitions #

References #

Graph adjacency helper from vertex and edge lists #

def Cslib.Logic.PL.CNF.edgePairs {V : Type u_1} [DecidableEq V] (vs : List V) (es : List (V × V)) :
List (V × V)

Edges between distinct declared vertices of vs.

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

def Cslib.Logic.PL.CNF.indepSetCNF {V : Type u_1} [DecidableEq V] (vs : List V) (es : List (V × V)) :
CNF V

CNF encoding of independent sets: one variable per vertex v ∈ vs, tautology [(v, true), (v, false)] so all declared vertices occur, and [(e.1, false), (e.2, false)] for every declared edge e ∈ es. Every clause has width 2.

theorem Cslib.Logic.PL.CNF.length_clause_indepSetCNF {V : Type u_1} [DecidableEq V] {vs : List V} {es : List (V × V)} {c : Clause V} (hc : c ∈ indepSetCNF vs es) :

Every clause of indepSetCNF vs es has length 2.

@[simp]
theorem Cslib.Logic.PL.CNF.mem_vars_indepSetCNF {V : Type u_1} [DecidableEq V] {vs : List V} {es : List (V × V)} {v : V} :
v ∈ (indepSetCNF vs es).vars ↔ v ∈ vs

The occurring variables of indepSetCNF vs es are precisely the vertices in vs.

@[simp]
theorem Cslib.Logic.PL.CNF.numVars_indepSetCNF {V : Type u_1} [DecidableEq V] (vs : List V) (es : List (V × V)) :

indepSetCNF vs es has at most vs.toFinset.card variables (equality holds always).

theorem Cslib.Logic.PL.CNF.eval_indepSetCNF {V : Type u_1} [DecidableEq V] (vs : List V) (es : List (V × V)) (σ : V → Bool) :
eval σ (indepSetCNF vs es) = true ↔ ∀ e ∈ es, e.1 ∈ vs → e.2 ∈ vs → e.1 ≠ e.2 → σ e.1 = true → σ e.2 = true → False

Evaluation of indepSetCNF vs es under σ: no declared edge has both endpoints true.

def Cslib.Logic.PL.CNF.indepSetCNFEquiv {V : Type u_1} [DecidableEq V] {vs : List V} {es : List (V × V)} {G : SimpleGraph { v : V // v ∈ vs }} (hG : ∀ (u w : { v : V // v ∈ vs }), G.Adj u w ↔ ↑u ≠ ↑w ∧ ((↑u, ↑w) ∈ es ∨ (↑w, ↑u) ∈ es)) :
{ σ : ↥vs.toFinset → Bool // eval (fun (v : V) => if hv : v ∈ vs.toFinset then σ ⟨v, hv⟩ else false) (indepSetCNF vs es) = true } ≃ { S : Finset { v : V // v ∈ vs } // G.IsIndepSet ↑S }

Assignment bijection for indepSetCNF: given a simple graph G on vertex subtype {v // v ∈ vs} whose adjacency matches es, satisfying assignments on vs.toFinset biject with independent sets of G.

theorem Cslib.Logic.PL.CNF.modelCount_indepSetCNF {V : Type u_1} [DecidableEq V] {vs : List V} {es : List (V × V)} {G : SimpleGraph { v : V // v ∈ vs }} (hG : ∀ (u w : { v : V // v ∈ vs }), G.Adj u w ↔ ↑u ≠ ↑w ∧ ((↑u, ↑w) ∈ es ∨ (↑w, ↑u) ∈ es)) :
(indepSetCNF vs es).modelCount = Nat.card { S : Finset { v : V // v ∈ vs } // G.IsIndepSet ↑S }

indepSetCNF preserves the exact count of independent sets.

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

def Cslib.Logic.PL.CNF.coloringCNF {V : Type u_1} [DecidableEq V] (q : ℕ) (vs : List V) (es : List (V × V)) :
CNF (V × ℕ)

CNF encoding of proper q-colourings: one-hot variables (v, c) (c < q) per vertex v ∈ vs, CNF.exactlyOne constraints for every vertex, and edge exclusions [((e.1, c), false), ((e.2, c), false)] for every declared edge e and colour c < q.

theorem Cslib.Logic.PL.CNF.length_clause_coloringCNF_le {V : Type u_1} [DecidableEq V] {q : ℕ} {vs : List V} {es : List (V × V)} {c : Clause (V × ℕ)} (hc : c ∈ coloringCNF q vs es) :

Every clause of coloringCNF q vs es has width at most max q 2.

@[simp]
theorem Cslib.Logic.PL.CNF.mem_vars_coloringCNF {V : Type u_1} [DecidableEq V] {q : ℕ} {vs : List V} {es : List (V × V)} {p : V × ℕ} :
p ∈ (coloringCNF q vs es).vars ↔ p.1 ∈ vs ∧ p.2 < q

The occurring variables of coloringCNF q vs es are {v ∈ vs} × {c < q}.

theorem Cslib.Logic.PL.CNF.numVars_coloringCNF {V : Type u_1} [DecidableEq V] (q : ℕ) (vs : List V) (es : List (V × V)) :

coloringCNF q vs es has q * |vs.toFinset| occurring variables.

theorem Cslib.Logic.PL.CNF.eval_coloringCNF {V : Type u_1} [DecidableEq V] (q : ℕ) (vs : List V) (es : List (V × V)) (σ : V × ℕ → Bool) :
eval σ (coloringCNF q vs es) = true ↔ (∀ v ∈ vs, (∃ c < q, σ (v, c) = true) ∧ ∀ c₁ < q, ∀ c₂ < q, σ (v, c₁) = true → σ (v, c₂) = true → c₁ = c₂) ∧ ∀ e ∈ es, e.1 ∈ vs → e.2 ∈ vs → e.1 ≠ e.2 → ∀ c < q, σ (e.1, c) = true → σ (e.2, c) = true → False

Evaluation of coloringCNF q vs es under σ: every v ∈ vs has a unique true colour < q, and adjacent vertices never share a colour.

noncomputable def Cslib.Logic.PL.CNF.coloringCNFEquiv {V : Type u_1} [DecidableEq V] {q : ℕ} {vs : List V} {es : List (V × V)} {G : SimpleGraph { v : V // v ∈ vs }} (hG : ∀ (u w : { v : V // v ∈ vs }), G.Adj u w ↔ ↑u ≠ ↑w ∧ ((↑u, ↑w) ∈ es ∨ (↑w, ↑u) ∈ es)) :
{ σ : ↥(vs.toFinset ×ˢ Finset.range q) → Bool // eval (fun (p : V × ℕ) => if hp : p ∈ vs.toFinset ×ˢ Finset.range q then σ ⟨p, hp⟩ else false) (coloringCNF q vs es) = true } ≃ G.Coloring (Fin q)

Assignment bijection for coloringCNF: satisfying assignments on the one-hot variables vs.toFinset ×ˢ Finset.range q biject with proper Fin q-colourings of G.

theorem Cslib.Logic.PL.CNF.modelCount_coloringCNF {V : Type u_1} [DecidableEq V] {q : ℕ} {vs : List V} {es : List (V × V)} {G : SimpleGraph { v : V // v ∈ vs }} (hG : ∀ (u w : { v : V // v ∈ vs }), G.Adj u w ↔ ↑u ≠ ↑w ∧ ((↑u, ↑w) ∈ es ∨ (↑w, ↑u) ∈ es)) :

coloringCNF preserves the exact count of proper q-colourings.

3. Ordered k-set splitting (n = |U|, width ≤ k) #

def Cslib.Logic.PL.CNF.setSplittingCNF {V : Type u_1} (sets : List (List V)) :
CNF V

CNF encoding of ordered k-set splitting: each subset s ∈ sets produces both its positive clause s.map (·, true) and its negative clause s.map (·, false).

theorem Cslib.Logic.PL.CNF.length_clause_setSplittingCNF_le {V : Type u_1} {k : ℕ} {sets : List (List V)} (hsets : ∀ s ∈ sets, s.length ≤ k) {c : Clause V} (hc : c ∈ setSplittingCNF sets) :

Every clause of setSplittingCNF sets has length at most k when every set has size ≤ k.

theorem Cslib.Logic.PL.CNF.mem_vars_setSplittingCNF {V : Type u_1} {sets : List (List V)} {v : V} :

All variables of setSplittingCNF sets belong to sets.flatten.

theorem Cslib.Logic.PL.CNF.eval_setSplittingCNF {V : Type u_1} (sets : List (List V)) (σ : V → Bool) :
eval σ (setSplittingCNF sets) = true ↔ ∀ s ∈ sets, (∃ x ∈ s, σ x = true) ∧ ∃ y ∈ s, σ y = false

Evaluation of setSplittingCNF sets matches CNF.evalNAE on the positive clauses: every set contains at least one true and one false element.

theorem Cslib.Logic.PL.CNF.eval_setSplittingCNF_eq_evalNAE {V : Type u_1} (sets : List (List V)) (σ : V → Bool) :
eval σ (setSplittingCNF sets) = evalNAE σ (List.map (fun (s : List V) => List.map (fun (x : V) => (x, true)) s) sets)

Bridge to CNF.evalNAE: setSplittingCNF evaluates identically to evalNAE on the positive hyperedge clauses.

def Cslib.Logic.PL.CNF.setSplittingCNFEquiv {V : Type u_1} [DecidableEq V] (U : Finset V) (sets : List (List V)) (hsets : ∀ s ∈ sets, ∀ x ∈ s, x ∈ U) :
{ σ : ↥U → Bool // eval (fun (v : V) => if hv : v ∈ U then σ ⟨v, hv⟩ else false) (setSplittingCNF sets) = true } ≃ { P : Finset V × Finset V // P.1 ∪ P.2 = U ∧ Disjoint P.1 P.2 ∧ ∀ s ∈ sets, (∃ x ∈ s, x ∈ P.1) ∧ ∃ y ∈ s, y ∈ P.2 }

Assignment bijection for setSplittingCNF: on any declared universe U : Finset V covering sets, satisfying assignments on U biject with ordered bipartitions (A, B) of U such that every s ∈ sets meets both A and B.

theorem Cslib.Logic.PL.CNF.modelCountOn_setSplittingCNF {V : Type u_1} [DecidableEq V] (U : Finset V) (sets : List (List V)) (hsets : ∀ s ∈ sets, ∀ x ∈ s, x ∈ U) :
(setSplittingCNF sets).modelCountOn U = Nat.card { P : Finset V × Finset V // P.1 ∪ P.2 = U ∧ Disjoint P.1 P.2 ∧ ∀ s ∈ sets, (∃ x ∈ s, x ∈ P.1) ∧ ∃ y ∈ s, y ∈ P.2 }

setSplittingCNF preserves the exact count of ordered splitting bipartitions.