Documentation

CslibFrontier.Computability.Complexity.FineGrained.CountingEncodings

Runtime transfers and polynomial-time bounded-width CNF counting compilations #

This module connects the six bounded-width CNF counting encodings to polynomial-time machine certificates and conditional exponential/subexponential runtime transfers:

  1. General conditional runtime transfer (CountingTransfer.transfer_declaredCounter, CountingTransfer.declaredCounter_of_modelCounter): any declared k-CNF counter (or plain (max k 2)-CNF model counter via tautology variable padding CNF.padDeclaredVars) running in time 2 ^ E N * poly(|x|) and polynomial space transfers along any polynomial-time compilation g : α → DeclaredCNF satisfying (g x).numVars ≤ C * μ x + D under a polynomial-time guard.
  2. Polynomial-time bounded one-hot CSP compilation (CSP.computableInPolyTime_toOneHotDeclaredCNF_of_forall, CSP.computableInPolyTime_toOneHotDeclaredCNF_of_finite): compiles a finite-domain CSP over Fin q of arity ≤ k on N declared variables into an equivalent CNF formula on q * N variables of clause width ≤ max q (max k 2) (Cslib.Complexity.CSP.toOneHotDeclaredCNF).
  3. Explicit assignment bijection for constant-locality Boolean maps (LocalMap.preimageDeclaredEquiv): pairs LocalMap.toDeclaredCNF with an explicit bijection between declared-range satisfying assignments and n-bit preimages.
  4. Six conditional counting runtime transfers: independent sets (width = 2, parameter |V|), proper q-colourings (width = max q 2, parameter |V|), general-graph perfect matchings (width = 3, parameter |V| + |E|), fixed-arity finite-domain #CSP via one-hot encoding (width = max q (max k 2), parameter N), #k-SetSplitting (width = k, parameter |U|), and constant-locality Boolean map preimage counting (width = k, parameter numVars).

Main definitions #

Main results #

References #

Tautology variable padding for declared-variable CNF formulas #

Prepend width-2 tautology clauses (v ∨ ¬v) for all v < N so that every declared variable occurs explicitly without changing truth values on any assignment.

@[simp]
theorem Cslib.Logic.PL.CNF.eval_padDeclaredVars (N : ℕ) (φ : CNF ℕ) (σ : ℕ → Bool) :
eval σ (padDeclaredVars N φ) = eval σ φ
theorem Cslib.Logic.PL.CNF.length_clause_padDeclaredVars_le {k N : ℕ} {φ : CNF ℕ} (hφ : ∀ cl ∈ φ, List.length cl ≤ k) {cl : Clause ℕ} (hcl : cl ∈ padDeclaredVars N φ) :

Row 6 explicit assignment bijection #

def Cslib.Complexity.LocalMap.preimageDeclaredEquiv {k : ℕ} {q : LocalMap × List Bool} (hq : Valid k q.1 = true) :
{ σ : ↥(Finset.range q.1.numVars) → Bool // Logic.PL.CNF.eval (fun (v : ℕ) => if hv : v ∈ Finset.range q.1.numVars then σ ⟨v, hv⟩ else false) (toDeclaredCNF k q).formula = true } ≃ { σ : ↥(Finset.range q.1.numVars) → Bool // (q.1.eval fun (v : ℕ) => if hv : v ∈ Finset.range q.1.numVars then σ ⟨v, hv⟩ else false) = q.2 }

Explicit bijection between declared-range satisfying assignments of LocalMap.toDeclaredCNF k q and n-bit preimages of q.2 under q.1 when q.1.Valid k = true.

Row 4 polynomial-time one-hot CSP compilation #

def Cslib.Complexity.CSP.toOneHotDeclaredCNF {Rel : Type} (q k : ℕ) (sem : Rel → List (Fin q) → Bool) (x : DeclaredCSP Rel) :

Declared-variable one-hot CNF compilation ⟨x.numVars * q, toOneHotCNFBounded ...⟩.

Compiling x : DeclaredCSP Rel to toOneHotDeclaredCNF q k sem x is polynomial-time whenever fun R => sem R ts is polynomial-time on tuples of length ≤ k.

Over a finite relation alphabet Rel, toOneHotDeclaredCNF q k sem is polynomial-time.

General conditional counting runtime transfers #

theorem Cslib.Complexity.CountingTransfer.declaredCounter_of_modelCounter {k : ℕ} {countCNF T₀ S₀ : Logic.PL.CNF ℕ → ℕ} {E : ℕ → ℕ} {e₀ b₀ : ℕ} (hcount : Turing.MultiTapeTM.ComputableInO countCNF encCNF Turing.MultiTapeTM.encNat T₀ S₀) (hspec : ∀ (φ : Logic.PL.CNF ℕ), (∀ cl ∈ φ, List.length cl ≤ max k 2) → countCNF φ = φ.modelCount) (hT₀ : ∀ (φ : Logic.PL.CNF ℕ), T₀ φ ≤ 2 ^ E φ.numVars * ((encCNF φ).length + 1) ^ e₀) (hS₀ : ∀ (φ : Logic.PL.CNF ℕ), S₀ φ ≤ ((encCNF φ).length + 1) ^ b₀) :

Convert any plain (max k 2)-CNF model counter on encCNF running in time 2 ^ E φ.numVars * (|φ| + 1) ^ e₀ and polynomial space into a declared k-CNF counter on encDeclaredCNF running in time 2 ^ E p.numVars * (|p| + 1) ^ e and polynomial space.

theorem Cslib.Complexity.CountingTransfer.transfer_declaredCounter {α : Type} {encA : α ↪ List Bool} (k : ℕ) {countDecl T₀ S₀ : DeclaredCNF → ℕ} {E : ℕ → ℕ} (hE : Monotone E) {e₀ b₀ : ℕ} (hcount : Turing.MultiTapeTM.ComputableInO countDecl encDeclaredCNF Turing.MultiTapeTM.encNat T₀ S₀) (hspec : ∀ (p : DeclaredCNF), Logic.PL.CNF.validDeclaredInput k p.numVars p.formula = true → countDecl p = p.formula.modelCountOn (Finset.range p.numVars)) (hT₀ : ∀ (p : DeclaredCNF), T₀ p ≤ 2 ^ E p.numVars * ((encDeclaredCNF p).length + 1) ^ e₀) (hS₀ : ∀ (p : DeclaredCNF), S₀ p ≤ ((encDeclaredCNF p).length + 1) ^ b₀) {g : α → DeclaredCNF} (hg : Turing.MultiTapeTM.ComputableInPolyTime g encA encDeclaredCNF) {valid : α → Bool} (hvalid : Turing.MultiTapeTM.ComputableInPolyTime valid encA Turing.MultiTapeTM.encBool) (μ : α → ℕ) (C D : ℕ) (hvalid_imp : ∀ (x : α), valid x = true → Logic.PL.CNF.validDeclaredInput k (g x).numVars (g x).formula = true ∧ (g x).numVars ≤ C * μ x + D) :
∃ (count : α → ℕ) (e : ℕ) (b : ℕ), (∀ (x : α), count x = if valid x = true then (g x).formula.modelCountOn (Finset.range (g x).numVars) else 0) ∧ Turing.MultiTapeTM.ComputableInO count encA Turing.MultiTapeTM.encNat (fun (x : α) => 2 ^ E (C * μ x + D) * ((encA x).length + 1) ^ e) fun (x : α) => ((encA x).length + 1) ^ b

General conditional counting runtime transfer: any declared k-CNF counter running in time 2 ^ E N * (|p| + 1) ^ e₀ and polynomial space with monotone E transfers across any polynomial-time compilation g : α → DeclaredCNF and guard valid : α → Bool satisfying (g x).numVars ≤ C * μ x + D under valid x = true.

Conditional runtime transfers for the six CNF counting encodings #

theorem Cslib.Complexity.CountingTransfer.exists_indepSetCounter_of_declaredCounter {countDecl T₀ S₀ : DeclaredCNF → ℕ} {E : ℕ → ℕ} (hE : Monotone E) {e₀ b₀ : ℕ} (hcount : Turing.MultiTapeTM.ComputableInO countDecl encDeclaredCNF Turing.MultiTapeTM.encNat T₀ S₀) (hspec : ∀ (p : DeclaredCNF), Logic.PL.CNF.validDeclaredInput 2 p.numVars p.formula = true → countDecl p = p.formula.modelCountOn (Finset.range p.numVars)) (hT₀ : ∀ (p : DeclaredCNF), T₀ p ≤ 2 ^ E p.numVars * ((encDeclaredCNF p).length + 1) ^ e₀) (hS₀ : ∀ (p : DeclaredCNF), S₀ p ≤ ((encDeclaredCNF p).length + 1) ^ b₀) :
∃ (count : Graph → ℕ) (e : ℕ) (b : ℕ), (∀ (G : Graph), count G = Nat.card { S : Finset { v : ℕ // v ∈ G.vertices } // G.induced.IsIndepSet ↑S }) ∧ Turing.MultiTapeTM.ComputableInO count encGraph Turing.MultiTapeTM.encNat (fun (G : Graph) => 2 ^ E G.vertices.toFinset.card * ((encGraph G).length + 1) ^ e) fun (G : Graph) => ((encGraph G).length + 1) ^ b

Row 1 conditional transfer (#IndependentSet, width 2, n = |V|): any declared 2-CNF counter with monotone exponent E yields an independent-set counter in time 2 ^ E G.vertices.toFinset.card * (|G| + 1) ^ e and polynomial space.

theorem Cslib.Complexity.CountingTransfer.exists_coloringCounter_of_declaredCounter (q : ℕ) {countDecl T₀ S₀ : DeclaredCNF → ℕ} {E : ℕ → ℕ} (hE : Monotone E) {e₀ b₀ : ℕ} (hcount : Turing.MultiTapeTM.ComputableInO countDecl encDeclaredCNF Turing.MultiTapeTM.encNat T₀ S₀) (hspec : ∀ (p : DeclaredCNF), Logic.PL.CNF.validDeclaredInput (max q 2) p.numVars p.formula = true → countDecl p = p.formula.modelCountOn (Finset.range p.numVars)) (hT₀ : ∀ (p : DeclaredCNF), T₀ p ≤ 2 ^ E p.numVars * ((encDeclaredCNF p).length + 1) ^ e₀) (hS₀ : ∀ (p : DeclaredCNF), S₀ p ≤ ((encDeclaredCNF p).length + 1) ^ b₀) :
∃ (count : Graph → ℕ) (e : ℕ) (b : ℕ), (∀ (G : Graph), count G = Nat.card (G.induced.Coloring (Fin q))) ∧ Turing.MultiTapeTM.ComputableInO count encGraph Turing.MultiTapeTM.encNat (fun (G : Graph) => 2 ^ E (q * G.vertices.toFinset.card) * ((encGraph G).length + 1) ^ e) fun (G : Graph) => ((encGraph G).length + 1) ^ b

Row 2 conditional transfer (#q-Coloring, width max q 2, n = q * |V|): any declared (max q 2)-CNF counter with monotone exponent E yields a proper q-colouring counter in time 2 ^ E (q * G.vertices.toFinset.card) * (|G| + 1) ^ e and polynomial space.

theorem Cslib.Complexity.CountingTransfer.exists_perfectMatchingCounter_of_declaredCounter {countDecl T₀ S₀ : DeclaredCNF → ℕ} {E : ℕ → ℕ} (hE : Monotone E) {e₀ b₀ : ℕ} (hcount : Turing.MultiTapeTM.ComputableInO countDecl encDeclaredCNF Turing.MultiTapeTM.encNat T₀ S₀) (hspec : ∀ (p : DeclaredCNF), Logic.PL.CNF.validDeclaredInput 3 p.numVars p.formula = true → countDecl p = p.formula.modelCountOn (Finset.range p.numVars)) (hT₀ : ∀ (p : DeclaredCNF), T₀ p ≤ 2 ^ E p.numVars * ((encDeclaredCNF p).length + 1) ^ e₀) (hS₀ : ∀ (p : DeclaredCNF), S₀ p ≤ ((encDeclaredCNF p).length + 1) ^ b₀) :
∃ (count : Graph → ℕ) (e : ℕ) (b : ℕ), (∀ (G : Graph), count G = Nat.card { M : G.induced.Subgraph // M.IsPerfectMatching }) ∧ Turing.MultiTapeTM.ComputableInO count encGraph Turing.MultiTapeTM.encNat (fun (G : Graph) => 2 ^ E (7 * (G.vertices.toFinset.card + G.edgeList.length) + 1) * ((encGraph G).length + 1) ^ e) fun (G : Graph) => ((encGraph G).length + 1) ^ b

Row 3 conditional transfer (#PerfectMatching, width 3, n ≤ 7 * (|V| + |E|) + 1): any declared 3-CNF counter with monotone exponent E yields an exact perfect-matching counter on general graphs in time 2 ^ E (7 * (|V| + |E|) + 1) * (|G| + 1) ^ e and polynomial space.

theorem Cslib.Complexity.CountingTransfer.exists_oneHotCSPCounter_of_declaredCounter {Rel : Type} (encRel : Rel ↪ List Bool) {q : ℕ} (hq : 0 < q) (k : ℕ) (sem : Rel → List (Fin q) → Bool) (hsem : ∀ (ts : List (Fin q)), ts.length ≤ k → Turing.MultiTapeTM.ComputableInPolyTime (fun (R : Rel) => sem R ts) encRel Turing.MultiTapeTM.encBool) {countDecl T₀ S₀ : DeclaredCNF → ℕ} {E : ℕ → ℕ} (hE : Monotone E) {e₀ b₀ : ℕ} (hcount : Turing.MultiTapeTM.ComputableInO countDecl encDeclaredCNF Turing.MultiTapeTM.encNat T₀ S₀) (hspec : ∀ (p : DeclaredCNF), Logic.PL.CNF.validDeclaredInput (max q (max k 2)) p.numVars p.formula = true → countDecl p = p.formula.modelCountOn (Finset.range p.numVars)) (hT₀ : ∀ (p : DeclaredCNF), T₀ p ≤ 2 ^ E p.numVars * ((encDeclaredCNF p).length + 1) ^ e₀) (hS₀ : ∀ (p : DeclaredCNF), S₀ p ≤ ((encDeclaredCNF p).length + 1) ^ b₀) :
∃ (count : DeclaredCSP Rel → ℕ) (e : ℕ) (b : ℕ), (∀ (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) ∧ Turing.MultiTapeTM.ComputableInO count (encDeclaredCSP encRel) Turing.MultiTapeTM.encNat (fun (x : DeclaredCSP Rel) => 2 ^ E (q * x.numVars) * (((encDeclaredCSP encRel) x).length + 1) ^ e) fun (x : DeclaredCSP Rel) => (((encDeclaredCSP encRel) x).length + 1) ^ b

Row 4 conditional transfer (one-hot #CSP over Fin q, width max q (max k 2), n = q * N): any declared (max q (max k 2))-CNF counter with monotone exponent E transfers to finite-domain #CSP in time 2 ^ E (q * N) * (|x| + 1) ^ e and polynomial space.

Row 5 conditional transfer (#k-SetSplitting, width k, n = |U|): any declared k-CNF counter with monotone exponent E counts ordered splitting bipartitions on valid instances of set size ≤ k in time 2 ^ E x.ground.toFinset.card * (|x| + 1) ^ e and polynomial space.

theorem Cslib.Complexity.CountingTransfer.exists_localMapPreimageCounter_of_declaredCounter (k : ℕ) {countDecl T₀ S₀ : DeclaredCNF → ℕ} {E : ℕ → ℕ} (hE : Monotone E) {e₀ b₀ : ℕ} (hcount : Turing.MultiTapeTM.ComputableInO countDecl encDeclaredCNF Turing.MultiTapeTM.encNat T₀ S₀) (hspec : ∀ (p : DeclaredCNF), Logic.PL.CNF.validDeclaredInput k p.numVars p.formula = true → countDecl p = p.formula.modelCountOn (Finset.range p.numVars)) (hT₀ : ∀ (p : DeclaredCNF), T₀ p ≤ 2 ^ E p.numVars * ((encDeclaredCNF p).length + 1) ^ e₀) (hS₀ : ∀ (p : DeclaredCNF), S₀ p ≤ ((encDeclaredCNF p).length + 1) ^ b₀) :

Row 6 conditional transfer (constant-locality Boolean map preimage counting, width k, n = G.numVars): any declared k-CNF counter with monotone exponent E counts preimages of k-local Boolean maps in time 2 ^ E q.1.numVars * (|q| + 1) ^ e and polynomial space.