Documentation

CslibFrontier.Computability.Complexity.FineGrained.CountingCSP

Exact subexponential counting and decision for bounded-arity Boolean #CSP #

When the arity bound k is fixed and the relation semantics sem : Rel → List Bool → Bool is computable in polynomial time on patterns of length at most k (in particular whenever fun p : Rel × List Bool => sem p.1 p.2 is computable in polynomial time or Rel is finite), the width-guarded forbidden-pattern compiler CSP.toCNFBounded k sem runs in polynomial time. Its reusable encoding and compilation certificates live in Computability.PolyTime.CSP.ToCNF. Composing with CountingNativeEndpoint.exists_counter_of_polyTime_toDeclared yields:

  1. Exact declared-variable counting (CSP.exists_declaredCounter) in time O(2 ^ (A * interpolationScale N) * (|x| + 1) ^ e) and polynomial space;
  2. Exact occurring-variable counting (CSP.exists_modelCounter) in time O(2 ^ (A * interpolationScale F.numVars) * (|F| + 1) ^ e) and polynomial space via dense variable relabeling;
  3. Subexponential-time decision (CSP.decidableInSubexpTime_KCSP) for CSP.KCSP k sem with respect to CSP.numVars.

Source relation and library adaptations #

Main results #

References #

Computing the number of distinct occurring variables CSP.numVars in unary is computable in polynomial time.

Dense variable relabeling CSP.denseRelabel is computable in polynomial time.

The executable arity and variable-range guard CSP.validDeclaredCSP k is computable in polynomial time.

Every variable occurring in F.denseRelabel is strictly less than F.numVars.

When every constraint scope of F has length at most k, (F.numVars, F.denseRelabel) satisfies validDeclaredCSP k.

theorem Cslib.Complexity.CSP.exists_counter_of_polyTime_toDeclaredCSP {Rel α : Type} {encA : α ↪ List Bool} (encRel : Rel ↪ List Bool) (k : ℕ) (sem : Rel → List Bool → Bool) (hsem : ∀ (w : List Bool), w.length ≤ 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 : ℕ), 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

General polynomial-time reduction to declared-variable Boolean #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.toCNFBounded k sem and CountingNativeEndpoint.exists_counter_of_polyTime_toDeclared 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_of_forall {Rel : Type} (encRel : Rel ↪ List Bool) (k : ℕ) (sem : Rel → List Bool → Bool) (hsem : ∀ (w : List Bool), w.length ≤ 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 : ℕ), 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

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

theorem Cslib.Complexity.CSP.exists_declaredCounter {Rel : Type} (encRel : Rel ↪ List Bool) (k : ℕ) (sem : Rel → List Bool → Bool) (hsem : Turing.MultiTapeTM.ComputableInPolyTime (fun (p : Rel × List Bool) => sem p.1 p.2) (Turing.MultiTapeTM.encPair encRel Turing.MultiTapeTM.encBits) Turing.MultiTapeTM.encBool) :
∃ (count : DeclaredCSP Rel → ℕ) (T : DeclaredCSP Rel → ℕ) (S : DeclaredCSP Rel → ℕ) (A : ℕ) (c : ℕ) (e : ℕ) (a : ℕ) (b : ℕ), 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

Declared-variable exact counting for bounded-arity Boolean #CSP. For any polynomial-time computable relation semantics sem and arity bound k, one machine computes the exact guarded declared-variable model count F.modelCountOn sem (Finset.range N) on every input (N, F) : DeclaredCSP Rel in time O(2 ^ (A * interpolationScale N) * (|x| + 1) ^ e) and polynomial space.

theorem Cslib.Complexity.CSP.exists_declaredCounter_of_finite {Rel : Type} [Finite Rel] (encRel : Rel ↪ List Bool) (k : ℕ) (sem : Rel → List Bool → Bool) :
∃ (count : DeclaredCSP Rel → ℕ) (T : DeclaredCSP Rel → ℕ) (S : DeclaredCSP Rel → ℕ) (A : ℕ) (c : ℕ) (e : ℕ) (a : ℕ) (b : ℕ), 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

Declared-variable exact counting for bounded-arity Boolean #CSP over a finite relation alphabet.

theorem Cslib.Complexity.CSP.exists_modelCounter_of_forall {Rel V : Type} [DecidableEq V] (encRel : Rel ↪ List Bool) (encV : V ↪ List Bool) (k : ℕ) (sem : Rel → List Bool → Bool) (hsem : ∀ (w : List Bool), w.length ≤ 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 : ℕ), 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

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

theorem Cslib.Complexity.CSP.exists_modelCounter {Rel V : Type} [DecidableEq V] (encRel : Rel ↪ List Bool) (encV : V ↪ List Bool) (k : ℕ) (sem : Rel → List Bool → Bool) (hsem : Turing.MultiTapeTM.ComputableInPolyTime (fun (p : Rel × List Bool) => sem p.1 p.2) (Turing.MultiTapeTM.encPair encRel Turing.MultiTapeTM.encBits) 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 : ℕ), 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

Occurring-variable exact counting for bounded-arity Boolean #CSP. For any polynomial-time computable relation semantics sem, variable encoding encV, and arity bound k, one machine computes F.modelCount sem on every instance F : CSP Rel V of constraint arity ≤ k in time O(2 ^ (A * interpolationScale F.numVars) * (|F| + 1) ^ e) and polynomial space.

theorem Cslib.Complexity.CSP.exists_modelCounter_of_finite {Rel V : Type} [Finite Rel] [DecidableEq V] (encRel : Rel ↪ List Bool) (encV : V ↪ List Bool) (k : ℕ) (sem : Rel → List Bool → Bool) :
∃ (count : Logic.PL.CSP Rel V → ℕ) (T : Logic.PL.CSP Rel V → ℕ) (S : Logic.PL.CSP Rel V → ℕ) (A : ℕ) (c : ℕ) (e : ℕ) (a : ℕ) (b : ℕ), 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

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

theorem Cslib.Complexity.CSP.decidableInSubexpTime_KCSP_of_reduction {Rel V D β : Type} [DecidableEq V] {encB : β ↪ List Bool} (encRel : Rel ↪ List Bool) (encV : V ↪ List Bool) (k : ℕ) (sem : Rel → List D → Bool) {f : Logic.PL.CSP Rel V → β} (hf : Turing.MultiTapeTM.ComputableInPolyTime f (encCSP encRel encV) encB) {L : Set β} {μ : β → ℕ} (hL : DecidableInSubexpTime L encB μ) {c : ℕ} (hμ : ∀ (F : Logic.PL.CSP Rel V), μ (f F) ≤ c * F.numVars) (hiff : ∀ (F : Logic.PL.CSP Rel V), (∀ cl ∈ F, cl.scope.length ≤ k) → (Logic.PL.CSP.Satisfiable sem F ↔ f F ∈ L)) :

Domain-polymorphic subexponential reduction from CSP.KCSP: Whenever f : CSP Rel V → β is computable in polynomial time, L : Set β is decidable in subexponential time with respect to μ : β → ℕ with μ (f F) ≤ c * F.numVars, and f F ∈ L characterizes F.Satisfiable sem on instances of constraint arity ≤ k, CSP.KCSP k sem is decidable in subexponential time with respect to CSP.numVars.

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

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

Subexponential-time decision for bounded-arity Boolean CSP. For any polynomial-time computable relation semantics sem, variable encoding encV, and arity bound k, CSP.KCSP k sem is decidable in subexponential time in the number of occurring variables CSP.numVars.

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

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