Documentation

CslibFrontier.Computability.Complexity.FineGrained.CountingFiniteCSP

Fine-grained complexity of finite-domain #CSP and k-CSP #

This module proves that the binary-encoding compilation Cslib.Logic.PL.CSP.toBoolean from finite-domain CSPs over Fin q to Boolean CSPs runs in polynomial time on the native encoding encDeclaredCSP encRel (with compiled encoding length polynomially bounded in the native input encoding length), and composes it with the subexponential bounded-arity Boolean #CSP and k-CSP endpoints (Cslib.Complexity.CSP) to obtain native subexponential counting and decision over any fixed finite domain size q and arity bound k:

  1. Polynomial-time compilation (CSP.computableInPolyTime_toBoolean, CSP.computableInPolyTime_toBooleanDeclared, CSP.polyBounded_length_toBooleanDeclared): compiling (N, F) : DeclaredCSP Rel to (N * CSP.bitWidth q, F.toBoolean q N) is computable in polynomial time from encDeclaredCSP encRel to encDeclaredCSP (encOption encRel).
  2. Native declared-variable counting (CSP.exists_declaredCounter_finiteDomain_of_forall, CSP.exists_declaredCounter_finiteDomain): one machine on encDeclaredCSP encRel computes the exact guarded declared-variable model count F.modelCountOn sem (Finset.range N) in time O(2 ^ (A * interpolationScale N) * (|x| + 1) ^ e) and polynomial space in the native finite-domain input length |x|.
  3. Native occurring-variable counting (CSP.exists_modelCounter_finiteDomain_of_forall, CSP.exists_modelCounter_finiteDomain): one machine on encCSP encRel encV computes F.modelCount sem for every instance F : CSP Rel V of constraint arity ≤ k in time O(2 ^ (A * interpolationScale F.numVars) * (|F| + 1) ^ e) and polynomial space via dense variable relabeling.
  4. Subexponential decision (CSP.decidableInSubexpTime_finiteDomainKCSP_of_forall, CSP.decidableInSubexpTime_finiteDomainKCSP): CSP.KCSP k sem over Fin q is decidable in subexponential time with respect to CSP.numVars.

Main results #

References #

Polynomial-time compilation to Boolean CSP #

Expanding a variable index v into its b-bit variable block CSP.bitScope b v is computable in polynomial time.

Compiling a finite-domain CSP on declared variables 0, …, N - 1 into its equivalent Boolean CSP x.formula.toBoolean q x.numVars is computable in polynomial time from the native encoding encDeclaredCSP encRel.

Compiling a declared finite-domain CSP (N, F) into the declared Boolean CSP (N * CSP.bitWidth q, F.toBoolean q N) is computable in polynomial time.

The compiled Boolean CSP encoding length is polynomially bounded in the native finite-domain input encoding length.

Pattern-wise polynomial-time computability of the compiled Boolean semantics CSP.semBoolean q sem. Whenever fun R => sem R w is computable in polynomial time for each domain tuple w : List (Fin q) of length at most max 1 k, fun oR => CSP.semBoolean q sem oR bw is computable in polynomial time for every bit pattern bw of length at most max 1 k * CSP.bitWidth q.

Exact counting and decision endpoints #

theorem Cslib.Complexity.CSP.exists_declaredCounter_toBoolean {Rel : Type} [Finite Rel] (encRel : Rel ↪ List Bool) (q : ℕ) [Inhabited (Fin q)] (k : ℕ) (sem : Rel → List (Fin q) → Bool) :
have b := Logic.PL.CSP.bitWidth q; have enc := encDeclaredCSP (Turing.MultiTapeTM.encOption encRel); ∃ (count : DeclaredCSP (Option Rel) → ℕ) (T : DeclaredCSP (Option Rel) → ℕ) (S : DeclaredCSP (Option Rel) → ℕ) (A : ℕ) (c : ℕ) (e : ℕ) (a : ℕ) (b_space : ℕ), Turing.MultiTapeTM.ComputableInO count enc Turing.MultiTapeTM.encNat T S ∧ (∀ (x : DeclaredCSP Rel), (∀ c ∈ x.formula, c.scope.length ≤ k) → (∀ v ∈ x.formula.vars, v < x.numVars) → count { numVars := x.numVars * b, formula := Logic.PL.CSP.toBoolean q x.numVars x.formula } = Logic.PL.CSP.modelCountOn sem x.formula (Finset.range x.numVars)) ∧ (∀ (x : DeclaredCSP Rel), ↑(T { numVars := x.numVars * b, formula := Logic.PL.CSP.toBoolean q x.numVars x.formula }) ≤ ↑c * (2 ^ (↑A * SubexponentialSAT.interpolationScale (x.numVars * b)) * (↑(enc { numVars := x.numVars * b, formula := Logic.PL.CSP.toBoolean q x.numVars x.formula }).length + 1) ^ e) + ↑c) ∧ ∀ (x : DeclaredCSP Rel), S { numVars := x.numVars * b, formula := Logic.PL.CSP.toBoolean q x.numVars x.formula } ≤ a * ((enc { numVars := x.numVars * b, formula := Logic.PL.CSP.toBoolean q x.numVars x.formula }).length + 1) ^ b_space

Declared-variable model counting transfer via Boolean compilation. For any fixed domain size q, arity bound k, and finite relation alphabet Rel with semantics sem : Rel → List (Fin q) → Bool, evaluating the bounded-arity Boolean CSP counter on the compiled Boolean instance (x.numVars * CSP.bitWidth q, x.formula.toBoolean q x.numVars) computes the exact declared-variable model count x.formula.modelCountOn sem (Finset.range x.numVars) for every valid finite-domain instance x of constraint width at most k.

theorem Cslib.Complexity.CSP.exists_counter_of_polyTime_toFiniteDeclaredCSP {Rel α : Type} {encA : α ↪ List Bool} (encRel : Rel ↪ List Bool) (q : ℕ) [Inhabited (Fin q)] (k : ℕ) (sem : Rel → List (Fin q) → Bool) (hsem : ∀ (w : List (Fin q)), w.length ≤ max 1 k → Turing.MultiTapeTM.ComputableInPolyTime (fun (R : Rel) => sem R w) encRel Turing.MultiTapeTM.encBool) {f : α → DeclaredCSP Rel} (hf : Turing.MultiTapeTM.ComputableInPolyTime f encA (encDeclaredCSP encRel)) {valid : α → Bool} (hvalid : Turing.MultiTapeTM.ComputableInPolyTime valid encA Turing.MultiTapeTM.encBool) (hvalid_imp : ∀ (x : α), valid x = true → Logic.PL.CSP.validDeclaredCSP k (f x).numVars (f x).formula = true) :
∃ (count : α → ℕ) (T : α → ℕ) (S : α → ℕ) (A : ℕ) (c : ℕ) (e : ℕ) (a : ℕ) (b_space : ℕ), Turing.MultiTapeTM.ComputableInO count encA Turing.MultiTapeTM.encNat T S ∧ (∀ (x : α), count x = if valid x = true then Logic.PL.CSP.modelCountOn sem (f x).formula (Finset.range (f x).numVars) else 0) ∧ (∀ (x : α), ↑(T x) ≤ ↑c * (2 ^ (↑A * SubexponentialSAT.interpolationScale (f x).numVars) * (↑(encA x).length + 1) ^ e) + ↑c) ∧ ∀ (x : α), S x ≤ a * ((encA x).length + 1) ^ b_space

General polynomial-time reduction to declared-variable finite-domain #CSP: Composing any polynomial-time reduction f : α → DeclaredCSP Rel and polynomial-time validity guard valid : α → Bool (implying validDeclaredCSP k (f x).numVars (f x).formula = true) with CSP.computableInPolyTime_toBooleanDeclared and CSP.exists_counter_of_polyTime_toDeclaredCSP, and rescaling interpolationScale ((f x).numVars * bitWidth q) via interpolationScale_mul_le, yields an exact guarded model counter in time O(2 ^ (A * interpolationScale (f x).numVars) * (|x| + 1) ^ e) and polynomial space.

theorem Cslib.Complexity.CSP.exists_declaredCounter_finiteDomain_of_forall {Rel : Type} (encRel : Rel ↪ List Bool) (q : ℕ) [Inhabited (Fin q)] (k : ℕ) (sem : Rel → List (Fin q) → Bool) (hsem : ∀ (w : List (Fin q)), w.length ≤ max 1 k → Turing.MultiTapeTM.ComputableInPolyTime (fun (R : Rel) => sem R w) encRel Turing.MultiTapeTM.encBool) :
∃ (count : DeclaredCSP Rel → ℕ) (T : DeclaredCSP Rel → ℕ) (S : DeclaredCSP Rel → ℕ) (A : ℕ) (c : ℕ) (e : ℕ) (a : ℕ) (b_space : ℕ), Turing.MultiTapeTM.ComputableInO count (encDeclaredCSP encRel) Turing.MultiTapeTM.encNat T S ∧ (∀ (x : DeclaredCSP Rel), count x = if Logic.PL.CSP.validDeclaredCSP k x.numVars x.formula = true then Logic.PL.CSP.modelCountOn sem x.formula (Finset.range x.numVars) else 0) ∧ (∀ (x : DeclaredCSP Rel), ↑(T x) ≤ ↑c * (2 ^ (↑A * SubexponentialSAT.interpolationScale x.numVars) * (↑((encDeclaredCSP encRel) x).length + 1) ^ e) + ↑c) ∧ ∀ (x : DeclaredCSP Rel), S x ≤ a * (((encDeclaredCSP encRel) x).length + 1) ^ b_space

Declared-variable exact counting for bounded-arity finite-domain #CSP (pattern-wise hypothesis). Whenever fun R => sem R w is computable in polynomial time for each domain tuple w : List (Fin q) of length at most max 1 k, one native machine on encDeclaredCSP encRel computes the exact guarded declared-variable model count F.modelCountOn sem (Finset.range N) on every input x = (N, F) : DeclaredCSP Rel in time O(2 ^ (A * interpolationScale N) * (|x| + 1) ^ e) and polynomial space in the native finite-domain input length |x|.

theorem Cslib.Complexity.CSP.exists_declaredCounter_finiteDomain {Rel : Type} [Finite Rel] (encRel : Rel ↪ List Bool) (q : ℕ) [Inhabited (Fin q)] (k : ℕ) (sem : Rel → List (Fin q) → Bool) :
∃ (count : DeclaredCSP Rel → ℕ) (T : DeclaredCSP Rel → ℕ) (S : DeclaredCSP Rel → ℕ) (A : ℕ) (c : ℕ) (e : ℕ) (a : ℕ) (b_space : ℕ), Turing.MultiTapeTM.ComputableInO count (encDeclaredCSP encRel) Turing.MultiTapeTM.encNat T S ∧ (∀ (x : DeclaredCSP Rel), count x = if Logic.PL.CSP.validDeclaredCSP k x.numVars x.formula = true then Logic.PL.CSP.modelCountOn sem x.formula (Finset.range x.numVars) else 0) ∧ (∀ (x : DeclaredCSP Rel), ↑(T x) ≤ ↑c * (2 ^ (↑A * SubexponentialSAT.interpolationScale x.numVars) * (↑((encDeclaredCSP encRel) x).length + 1) ^ e) + ↑c) ∧ ∀ (x : DeclaredCSP Rel), S x ≤ a * (((encDeclaredCSP encRel) x).length + 1) ^ b_space

Declared-variable exact counting for bounded-arity finite-domain #CSP over a finite relation alphabet. For any fixed domain size q, arity bound k, and finite relation alphabet Rel, one native machine on encDeclaredCSP encRel computes the exact guarded declared-variable model count F.modelCountOn sem (Finset.range N) on every input x = (N, F) in time O(2 ^ (A * interpolationScale N) * (|x| + 1) ^ e) and polynomial space.

theorem Cslib.Complexity.CSP.exists_modelCounter_finiteDomain_of_forall {Rel V : Type} [DecidableEq V] (encRel : Rel ↪ List Bool) (encV : V ↪ List Bool) (q : ℕ) [Inhabited (Fin q)] (k : ℕ) (sem : Rel → List (Fin q) → Bool) (hsem : ∀ (w : List (Fin q)), w.length ≤ max 1 k → Turing.MultiTapeTM.ComputableInPolyTime (fun (R : Rel) => sem R w) encRel Turing.MultiTapeTM.encBool) :
∃ (count : Logic.PL.CSP Rel V → ℕ) (T : Logic.PL.CSP Rel V → ℕ) (S : Logic.PL.CSP Rel V → ℕ) (A : ℕ) (c : ℕ) (e : ℕ) (a : ℕ) (b_space : ℕ), Turing.MultiTapeTM.ComputableInO count (encCSP encRel encV) Turing.MultiTapeTM.encNat T S ∧ (∀ (F : Logic.PL.CSP Rel V), (∀ c ∈ F, c.scope.length ≤ k) → count F = Logic.PL.CSP.modelCount sem F) ∧ (∀ (F : Logic.PL.CSP Rel V), ↑(T F) ≤ ↑c * (2 ^ (↑A * SubexponentialSAT.interpolationScale F.numVars) * (↑((encCSP encRel encV) F).length + 1) ^ e) + ↑c) ∧ ∀ (F : Logic.PL.CSP Rel V), S F ≤ a * (((encCSP encRel encV) F).length + 1) ^ b_space

Occurring-variable exact counting for bounded-arity finite-domain #CSP (pattern-wise hypothesis).

theorem Cslib.Complexity.CSP.exists_modelCounter_finiteDomain {Rel V : Type} [Finite Rel] [DecidableEq V] (encRel : Rel ↪ List Bool) (encV : V ↪ List Bool) (q : ℕ) [Inhabited (Fin q)] (k : ℕ) (sem : Rel → List (Fin q) → Bool) :
∃ (count : Logic.PL.CSP Rel V → ℕ) (T : Logic.PL.CSP Rel V → ℕ) (S : Logic.PL.CSP Rel V → ℕ) (A : ℕ) (c : ℕ) (e : ℕ) (a : ℕ) (b_space : ℕ), Turing.MultiTapeTM.ComputableInO count (encCSP encRel encV) Turing.MultiTapeTM.encNat T S ∧ (∀ (F : Logic.PL.CSP Rel V), (∀ c ∈ F, c.scope.length ≤ k) → count F = Logic.PL.CSP.modelCount sem F) ∧ (∀ (F : Logic.PL.CSP Rel V), ↑(T F) ≤ ↑c * (2 ^ (↑A * SubexponentialSAT.interpolationScale F.numVars) * (↑((encCSP encRel encV) F).length + 1) ^ e) + ↑c) ∧ ∀ (F : Logic.PL.CSP Rel V), S F ≤ a * (((encCSP encRel encV) F).length + 1) ^ b_space

Occurring-variable exact counting for bounded-arity finite-domain #CSP over a finite relation alphabet.

theorem Cslib.Complexity.CSP.decidableInSubexpTime_finiteDomainKCSP_of_forall {Rel V : Type} [DecidableEq V] (encRel : Rel ↪ List Bool) (encV : V ↪ List Bool) (q : ℕ) [Inhabited (Fin q)] (k : ℕ) (sem : Rel → List (Fin q) → Bool) (hsem : ∀ (w : List (Fin q)), w.length ≤ max 1 k → Turing.MultiTapeTM.ComputableInPolyTime (fun (R : Rel) => sem R w) encRel Turing.MultiTapeTM.encBool) :

Subexponential-time decision for bounded-arity finite-domain CSP (pattern-wise hypothesis).

theorem Cslib.Complexity.CSP.decidableInSubexpTime_finiteDomainKCSP {Rel V : Type} [Finite Rel] [DecidableEq V] (encRel : Rel ↪ List Bool) (encV : V ↪ List Bool) (q : ℕ) [Inhabited (Fin q)] (k : ℕ) (sem : Rel → List (Fin q) → Bool) :

Subexponential-time decision for bounded-arity finite-domain CSP over a finite relation alphabet.