Documentation

CslibFrontier.Computability.Complexity.FineGrained.BinaryWeightedCounting

Native weighted counting with polynomially many weight bits #

For fixed arity and polynomial bit-budget parameters, one native machine computes the partition function of a Boolean CSP with input-dependent natural weights. The reduction constructs its existing constraint network and applies exact binary-weight tensor contraction. The weight magnitudes have no constant bound: only the total encoded length of the network's tables must be polynomial in the number of occurrences.

The counter checks the arity, excludes empty scopes, and checks this bit budget before invoking contraction. It returns one on the empty instance and zero on other rejected inputs. Thus its resource certificate holds on every encoded input. On the promised inputs the answer is the partition function, in polynomial space and time poly(L) * 2 ^ O(N / √log(N + 2)), where N counts occurrences, n counts variables, and L is the complete encoded input length. Bounded occurrence gives the corresponding variable bound.

Main definitions #

Main results #

def Cslib.Complexity.BinaryWeightedCounting.guard {Rel : Type} (k D d : ℕ) (wt : Rel → List Bool → ℕ) (F : Logic.PL.CSP Rel ℕ) :

The existing scope check together with the polynomial bound on all table bits.

def Cslib.Complexity.BinaryWeightedCounting.count {Rel : Type} (k D d : ℕ) (wt : Rel → List Bool → ℕ) (F : Logic.PL.CSP Rel ℕ) :

Exact contraction on the guarded instances, with one on the empty instance and zero on other rejected instances.

@[simp]
theorem Cslib.Complexity.BinaryWeightedCounting.count_nil {Rel : Type} (k D d : ℕ) (wt : Rel → List Bool → ℕ) :
count k D d wt [] = 1

The empty input always has answer one, independently of the bit budget.

The counter computes the partition function whenever its arity and bit-budget promises hold.

The scope and bit-budget checks are polynomial-time for the fixed parameters.

Native construction of the constraint network followed by exact binary-weight contraction.

noncomputable def Cslib.Complexity.BinaryWeightedCounting.certificate {Rel : Type} (encRel : Rel ↪ List Bool) (k D d : ℕ) (wt : Rel → List Bool → ℕ) (hwt : ∀ (w : List Bool), w.length ≤ k → Turing.MultiTapeTM.ComputableInPolyTime (fun (R : Rel) => wt R w) encRel Turing.MultiTapeTM.encNat) :

The guarded native counter. Both the guard and the rejected-input answer have polynomial time certificates in the original input encoding.

theorem Cslib.Complexity.BinaryWeightedCounting.certificate_bound {Rel : Type} (encRel : Rel ↪ List Bool) (k D d : ℕ) (wt : Rel → List Bool → ℕ) (hwt : ∀ (w : List Bool), w.length ≤ k → Turing.MultiTapeTM.ComputableInPolyTime (fun (R : Rel) => wt R w) encRel Turing.MultiTapeTM.encNat) :
∃ (A : ℕ) (C : ℕ) (e : ℕ), ∀ (F : Logic.PL.CSP Rel ℕ), (certificate encRel k D d wt hwt).time F ≤ C * (((encCSP encRel Turing.MultiTapeTM.encNat) F).length + 1) ^ e * 2 ^ (A * (F.vars.length + 1) / (Nat.log 2 (F.vars.length + 2)).sqrt) ∧ (certificate encRel k D d wt hwt).space F ≤ C * (((encCSP encRel Turing.MultiTapeTM.encNat) F).length + 1) ^ e

One fixed occurrence exponent and polynomial bound control the total guarded machine, including inputs rejected by either check.

theorem Cslib.Complexity.BinaryWeightedCounting.exists_partitionFunctionCounter {Rel : Type} (encRel : Rel ↪ List Bool) (k D d : ℕ) (wt : Rel → List Bool → ℕ) (hwt : ∀ (w : List Bool), w.length ≤ k → Turing.MultiTapeTM.ComputableInPolyTime (fun (R : Rel) => wt R w) encRel Turing.MultiTapeTM.encNat) :
∃ (counter : Logic.PL.CSP Rel ℕ → ℕ) (A : ℕ) (e : ℕ) (b : ℕ), (∀ (F : Logic.PL.CSP Rel ℕ), (∀ c ∈ F, 1 ≤ c.scope.length ∧ c.scope.length ≤ k) → (Circuits.Frontier.ClauseNetwork.cspNetwork k wt F).2.binaryTableBound ≤ D * ((Circuits.Frontier.ClauseNetwork.cspNetwork k wt F).2.numEdges + 1) ^ d → counter F = Logic.PL.CSP.partitionFunction wt F) ∧ Turing.MultiTapeTM.ComputableInO counter (encCSP encRel Turing.MultiTapeTM.encNat) Turing.MultiTapeTM.encNat (fun (F : Logic.PL.CSP Rel ℕ) => 2 ^ (A * (F.vars.length + 1) / (Nat.log 2 (F.vars.length + 2)).sqrt) * (((encCSP encRel Turing.MultiTapeTM.encNat) F).length + 1) ^ e) fun (F : Logic.PL.CSP Rel ℕ) => (((encCSP encRel Turing.MultiTapeTM.encNat) F).length + 1) ^ b

Exact natural weighted counting with a fixed polynomial table-bit budget. The relation symbol, including its potentially large numeric weights, is part of the input encoding.

theorem Cslib.Complexity.BinaryWeightedCounting.exists_partitionFunctionCounter_boundedDegree {Rel : Type} (encRel : Rel ↪ List Bool) (k D d : ℕ) (wt : Rel → List Bool → ℕ) (hwt : ∀ (w : List Bool), w.length ≤ k → Turing.MultiTapeTM.ComputableInPolyTime (fun (R : Rel) => wt R w) encRel Turing.MultiTapeTM.encNat) :
∃ (counter : Logic.PL.CSP Rel ℕ → ℕ) (T : Logic.PL.CSP Rel ℕ → ℕ) (S : Logic.PL.CSP Rel ℕ → ℕ) (e : ℕ) (b : ℕ), (∀ (F : Logic.PL.CSP Rel ℕ), (∀ c ∈ F, 1 ≤ c.scope.length ∧ c.scope.length ≤ k) → (Circuits.Frontier.ClauseNetwork.cspNetwork k wt F).2.binaryTableBound ≤ D * ((Circuits.Frontier.ClauseNetwork.cspNetwork k wt F).2.numEdges + 1) ^ d → counter F = Logic.PL.CSP.partitionFunction wt F) ∧ Turing.MultiTapeTM.ComputableInO counter (encCSP encRel Turing.MultiTapeTM.encNat) Turing.MultiTapeTM.encNat T S ∧ (∀ (F : Logic.PL.CSP Rel ℕ), S F = (((encCSP encRel Turing.MultiTapeTM.encNat) F).length + 1) ^ b) ∧ ∀ (Δ : ℕ), ∃ (A : ℕ), ∀ (F : Logic.PL.CSP Rel ℕ), (∀ (v : ℕ), List.count v F.vars ≤ Δ) → T F ≤ 2 ^ (A * (F.numVars + 1) / (Nat.log 2 (F.numVars + 2)).sqrt) * (((encCSP encRel Turing.MultiTapeTM.encNat) F).length + 1) ^ e

Bounded variable occurrence converts the occurrence numerator to a variable numerator. The machine and polynomial exponents are selected before the occurrence bound.

theorem Cslib.Complexity.BinaryWeightedCounting.exists_partitionFunctionCounter_of_weightBits {Rel : Type} (encRel : Rel ↪ List Bool) (k d : ℕ) (wt : Rel → List Bool → ℕ) (hwt : ∀ (w : List Bool), w.length ≤ k → Turing.MultiTapeTM.ComputableInPolyTime (fun (R : Rel) => wt R w) encRel Turing.MultiTapeTM.encNat) :
∃ (counter : Logic.PL.CSP Rel ℕ → ℕ) (A : ℕ) (e : ℕ) (b : ℕ), (∀ (F : Logic.PL.CSP Rel ℕ), (∀ c ∈ F, 1 ≤ c.scope.length ∧ c.scope.length ≤ k) → (∀ c ∈ F, ∀ (w : List Bool), w.length = c.scope.length → (wt c.rel w).size ≤ (F.vars.length + 1) ^ d) → counter F = Logic.PL.CSP.partitionFunction wt F) ∧ Turing.MultiTapeTM.ComputableInO counter (encCSP encRel Turing.MultiTapeTM.encNat) Turing.MultiTapeTM.encNat (fun (F : Logic.PL.CSP Rel ℕ) => 2 ^ (A * (F.vars.length + 1) / (Nat.log 2 (F.vars.length + 2)).sqrt) * (((encCSP encRel Turing.MultiTapeTM.encNat) F).length + 1) ^ e) fun (F : Logic.PL.CSP Rel ℕ) => (((encCSP encRel Turing.MultiTapeTM.encNat) F).length + 1) ^ b

Polynomially many bits per local weight suffice: the total network bit budget follows with the explicit coefficient 3 * 2 ^ (max k 4) + 1 and exponent d + 1. The natural weight magnitudes may be exponential in (N + 1) ^ d.

theorem Cslib.Complexity.BinaryWeightedCounting.exists_partitionFunctionCounter_boundedDegree_of_weightBits {Rel : Type} (encRel : Rel ↪ List Bool) (k d : ℕ) (wt : Rel → List Bool → ℕ) (hwt : ∀ (w : List Bool), w.length ≤ k → Turing.MultiTapeTM.ComputableInPolyTime (fun (R : Rel) => wt R w) encRel Turing.MultiTapeTM.encNat) :
∃ (counter : Logic.PL.CSP Rel ℕ → ℕ) (T : Logic.PL.CSP Rel ℕ → ℕ) (S : Logic.PL.CSP Rel ℕ → ℕ) (e : ℕ) (b : ℕ), (∀ (F : Logic.PL.CSP Rel ℕ), (∀ c ∈ F, 1 ≤ c.scope.length ∧ c.scope.length ≤ k) → (∀ c ∈ F, ∀ (w : List Bool), w.length = c.scope.length → (wt c.rel w).size ≤ (F.vars.length + 1) ^ d) → counter F = Logic.PL.CSP.partitionFunction wt F) ∧ Turing.MultiTapeTM.ComputableInO counter (encCSP encRel Turing.MultiTapeTM.encNat) Turing.MultiTapeTM.encNat T S ∧ (∀ (F : Logic.PL.CSP Rel ℕ), S F = (((encCSP encRel Turing.MultiTapeTM.encNat) F).length + 1) ^ b) ∧ ∀ (Δ : ℕ), ∃ (A : ℕ), ∀ (F : Logic.PL.CSP Rel ℕ), (∀ (v : ℕ), List.count v F.vars ≤ Δ) → T F ≤ 2 ^ (A * (F.numVars + 1) / (Nat.log 2 (F.numVars + 2)).sqrt) * (((encCSP encRel Turing.MultiTapeTM.encNat) F).length + 1) ^ e

The polynomial-bit counter has the variable bound on bounded-occurrence inputs. Its machine and polynomial exponents are independent of the occurrence bound Δ.