Documentation

CslibFrontier.Logics.Propositional.CSP.ToOneHotCNF

One-hot CNF compilation for fixed-arity finite-domain CSPs #

Given a finite-domain CSP instance F : CSP Rel ℕ over Fin q on declared variables 0, …, N - 1, CSP.toOneHotCNF q N F sem introduces q Boolean variables v * q + a (a < q) for each source variable v < N:

For fixed domain size q ≥ 1 and arity bound k, the compiled formula uses q * N variables (linear in N), clauses of width at most max q (max k 2), and preserves exact solution counts with an explicit assignment bijection (CSP.toOneHotCNFEquiv).

Main definitions #

Main results #

References #

All lists of length r over Fin q.

@[simp]
theorem Cslib.Logic.PL.CSP.mem_finTuples {q r : ℕ} {ts : List (Fin q)} :
ts ∈ finTuples q r ↔ ts.length = r

Membership in finTuples q r characterizes lists of length r.

finTuples q r has length q ^ r.

Clause forbidding local tuple ts on scope vs in the one-hot variable numbering.

def Cslib.Logic.PL.Constraint.toOneHotCNF {Rel : Type u_1} (q : ℕ) (sem : Rel → List (Fin q) → Bool) (c : Constraint Rel ℕ) :

One-hot forbidden-tuple clauses for a single constraint c over Fin q.

def Cslib.Logic.PL.Constraint.toOneHotCNFBounded {Rel : Type u_1} (q k : ℕ) (sem : Rel → List (Fin q) → Bool) (c : Constraint Rel ℕ) :

Width-guarded one-hot forbidden-tuple clauses: emits toOneHotCNF when c.scope.length ≤ k, and [] otherwise.

theorem Cslib.Logic.PL.Constraint.toOneHotCNFBounded_eq_toOneHotCNF {Rel : Type u_1} {q k : ℕ} {sem : Rel → List (Fin q) → Bool} {c : Constraint Rel ℕ} (hc : c.scope.length ≤ k) :
toOneHotCNFBounded q k sem c = toOneHotCNF q sem c
theorem Cslib.Logic.PL.Constraint.length_clause_toOneHotCNFBounded_le {Rel : Type u_1} {q k : ℕ} {sem : Rel → List (Fin q) → Bool} {c : Constraint Rel ℕ} {cl : Clause ℕ} (hcl : cl ∈ toOneHotCNFBounded q k sem c) :
def Cslib.Logic.PL.CSP.toOneHotCNF {Rel : Type u_1} (q N : ℕ) (F : CSP Rel ℕ) (sem : Rel → List (Fin q) → Bool) :

One-hot CNF compilation of a finite-domain CSP F : CSP Rel ℕ over Fin q on declared variables 0, …, N - 1. Uses Boolean variables v * q + a (v < N, a < q).

theorem Cslib.Logic.PL.CSP.length_clause_toOneHotCNF_le {Rel : Type u_1} {q N k : ℕ} {F : CSP Rel ℕ} (sem : Rel → List (Fin q) → Bool) (hF : ∀ c ∈ F, c.scope.length ≤ k) {cl : Clause ℕ} (hcl : cl ∈ toOneHotCNF q N F sem) :
List.length cl ≤ max q (max k 2)

If every constraint scope has length at most k, every clause of toOneHotCNF q N F sem has width at most max q (max k 2).

theorem Cslib.Logic.PL.CSP.vars_toOneHotCNF_subset_range {Rel : Type u_1} {q N : ℕ} {F : CSP Rel ℕ} (sem : Rel → List (Fin q) → Bool) (hvars : ∀ v ∈ F.vars, v < N) {x : ℕ} (hx : x ∈ (toOneHotCNF q N F sem).vars) :
x < N * q

When all variables of F are < N, every variable of toOneHotCNF q N F sem is < N * q.

@[simp]
theorem Cslib.Logic.PL.CSP.vars_toOneHotCNF_toFinset {Rel : Type u_1} {q N : ℕ} (hq : 0 < q) {F : CSP Rel ℕ} (sem : Rel → List (Fin q) → Bool) (hvars : ∀ v ∈ F.vars, v < N) :

When 0 < q and all variables of F are < N, the occurring variables of toOneHotCNF are precisely Finset.range (N * q).

theorem Cslib.Logic.PL.CSP.eval_toOneHotCNF {Rel : Type u_1} {q N : ℕ} {F : CSP Rel ℕ} (sem : Rel → List (Fin q) → Bool) (σ : ℕ → Bool) :
CNF.eval σ (toOneHotCNF q N F sem) = true ↔ (∀ v < N, (∃ a < q, σ (v * q + a) = true) ∧ ∀ a₁ < q, ∀ a₂ < q, σ (v * q + a₁) = true → σ (v * q + a₂) = true → a₁ = a₂) ∧ ∀ c ∈ F, ∀ (ts : List (Fin q)), ts.length = c.scope.length → sem c.rel ts = false → Clause.eval σ (forbidOneHotClause q c.scope ts) = true

Evaluation correctness of toOneHotCNF: for 0 < q, σ satisfies toOneHotCNF q N F sem iff every v < N has a unique true one-hot bit a < q and the induced assignment satisfies F.

noncomputable def Cslib.Logic.PL.CSP.toOneHotCNFEquiv {Rel : Type u_1} {q N : ℕ} (hq : 0 < q) (F : CSP Rel ℕ) (sem : Rel → List (Fin q) → Bool) (hvars : ∀ v ∈ F.vars, v < N) :
{ τ : ↥(Finset.range N) → Fin q // eval sem (fun (v : ℕ) => if hv : v ∈ Finset.range N then τ ⟨v, hv⟩ else default) F = true } ≃ { σ : ↥(Finset.range (N * q)) → Bool // CNF.eval (fun (x : ℕ) => if hx : x ∈ Finset.range (N * q) then σ ⟨x, hx⟩ else false) (toOneHotCNF q N F sem) = true }

Explicit assignment bijection for toOneHotCNF: when 0 < q and all variables of F are < N, declared solutions of F on Finset.range N biject with satisfying assignments of toOneHotCNF q N F sem on Finset.range (N * q).

theorem Cslib.Logic.PL.CSP.modelCountOn_toOneHotCNF {Rel : Type u_1} {q N : ℕ} (hq : 0 < q) (F : CSP Rel ℕ) (sem : Rel → List (Fin q) → Bool) (hvars : ∀ v ∈ F.vars, v < N) :

toOneHotCNF preserves exact declared-variable model counts.

theorem Cslib.Logic.PL.CSP.modelCount_toOneHotCNF {Rel : Type u_1} {q N : ℕ} (hq : 0 < q) (F : CSP Rel ℕ) (sem : Rel → List (Fin q) → Bool) (hvars : ∀ v ∈ F.vars, v < N) :

toOneHotCNF preserves exact occurring-variable model counts when all v < N appear.

Width-guarded and declared-variable one-hot CNF compilation #

def Cslib.Logic.PL.CSP.toOneHotCNFBounded {Rel : Type u_1} (q k N : ℕ) (F : CSP Rel ℕ) (sem : Rel → List (Fin q) → Bool) :

Width-guarded one-hot CNF compilation of a finite-domain CSP F : CSP Rel ℕ over Fin q on declared variables 0, …, N - 1.

theorem Cslib.Logic.PL.CSP.toOneHotCNFBounded_eq_toOneHotCNF {Rel : Type u_1} {q k N : ℕ} {F : CSP Rel ℕ} (sem : Rel → List (Fin q) → Bool) (hF : ∀ c ∈ F, c.scope.length ≤ k) :
toOneHotCNFBounded q k N F sem = toOneHotCNF q N F sem
theorem Cslib.Logic.PL.CSP.length_clause_toOneHotCNFBounded_le {Rel : Type u_1} {q k N : ℕ} {F : CSP Rel ℕ} {sem : Rel → List (Fin q) → Bool} {cl : Clause ℕ} (hcl : cl ∈ toOneHotCNFBounded q k N F sem) :
List.length cl ≤ max q (max k 2)
theorem Cslib.Logic.PL.CSP.validDeclaredInput_toOneHotCNFBounded {Rel : Type u_1} {q k N : ℕ} {F : CSP Rel ℕ} (sem : Rel → List (Fin q) → Bool) (hv : validDeclaredCSP k N F = true) :
CNF.validDeclaredInput (max q (max k 2)) (N * q) (toOneHotCNFBounded q k N F sem) = true
theorem Cslib.Logic.PL.CSP.modelCountOn_toOneHotCNFBounded {Rel : Type u_1} {q k N : ℕ} (hq : 0 < q) {F : CSP Rel ℕ} (sem : Rel → List (Fin q) → Bool) (hv : validDeclaredCSP k N F = true) :