Documentation

CslibFrontier.Computability.Complexity.FineGrained.ContractionCounting

Model counting by tensor contraction: the fixed-density bound of Theorem 1.1 #

For every fixed clause width k, one native machine computes the number of satisfying assignments CNF.modelCount φ of every formula φ whose clauses have at most k literals, in time 2 ^ (A (m + 1) / √⌊log₂ (n + 2)⌋) times a polynomial in the encoding length, and in polynomial space, where m is the number of clauses and n the number of variables (ContractionCounting.exists_modelCounter). For formulas with at most D n clauses this is time 2 ^ O_{k,D}(n / √log n) times a polynomial, the fixed-density bound of Theorem 1.1 of [OAI26k] (ContractionCounting.exists_modelCounter_fixedDensity). Measured by the number N of literal occurrences instead, the time is 2 ^ (A (N + 1) / √⌊log₂ (N + 2)⌋) times a polynomial (ContractionCounting.exists_modelCounter_occurrences), with no logarithm of the number of variables in the exponent; this form extends to formulas of unbounded clause width (Cslib.Complexity.ContractionCounting.exists_modelCounter_unboundedWidth).

The machine is the proof of Appendix D.2: it writes out the clause network of the formula (Cslib.Circuits.Frontier.ClauseNetwork.clauseNetwork), whose contraction is the model count, and contracts it modulo 2 ^ (3 N), where N is the number of literal occurrences, with the contraction algorithm of Theorem D.1 (CountingSimulation.fastContractionAlgorithm). The network has s = 3 N edges, at most 3 N vertices and degree at most max k 4, so it is admissible at size s and the contraction takes 2 ^ O(s / √log s) steps; since n + 2 ≤ s ≤ 3 k m, the exponent is O_k(m / √log n). Formulas that are empty, have an empty clause or have a clause longer than k are answered directly.

This does not prove the arbitrary-density bound 2 ^ O_k(n log log n / √log n) of Theorem 1.1, which Appendix D.3 obtains from Theorem D.1 with truncation order ℓ = n + 1; the contraction algorithm here has ℓ = 1. For dense formulas the exponent above exceeds n; the interpolation-scale counter CountingNativeEndpoint.exists_modelCounter remains the bound for them.

Main results #

References #

The formulas handed to the contraction algorithm: nonempty, with every clause of between one and k literals.

The input of the contraction algorithm: the precision 3 N, for N literal occurrences, and the clause network.

The answer off the guard: one for the empty formula, zero otherwise.

The count computed by the machine.

The machine: the guard, then the contraction algorithm on the clause network or the direct answer.

Correctness #

A formula whose clauses are nonempty has at least as many literals as clauses.

theorem Cslib.Complexity.ContractionCounting.count_eq {k : ℕ} {φ : Logic.PL.CNF ℕ} (hk : ∀ c ∈ φ, List.length c ≤ k) :

The machine counts models of every formula whose clauses have at most k literals.

Resources #

Admissibility: the clause network of a guarded formula with N literal occurrences is admissible at size 3 N, its number of edges, with constant k + 4.

theorem Cslib.Complexity.ContractionCounting.exponent_le {k K N m n : ℕ} (hN : 1 ≤ N) (hNm : N ≤ k * m) (hnN : n ≤ N) :
K * (3 * N) / (Nat.log 2 (3 * N)).sqrt ≤ 3 * k * K * (m + 1) / (Nat.log 2 (n + 2)).sqrt

The exponent of the contraction is at most 3 k K (m + 1) / √⌊log₂ (n + 2)⌋.

theorem Cslib.Complexity.ContractionCounting.exponent_le_occurrences {K N : ℕ} (hN : 1 ≤ N) :
K * (3 * N) / (Nat.log 2 (3 * N)).sqrt ≤ 3 * K * (N + 1) / (Nat.log 2 (N + 2)).sqrt

The exponent of the contraction is at most 3 K (N + 1) / √⌊log₂ (N + 2)⌋ for N ≥ 1 literal occurrences.

theorem Cslib.Complexity.ContractionCounting.exists_modelCounter (k : ℕ) :
∃ (count : Logic.PL.CNF ℕ → ℕ) (A : ℕ) (e : ℕ) (b : ℕ), (∀ (φ : Logic.PL.CNF ℕ), (∀ c ∈ φ, List.length c ≤ k) → count φ = φ.modelCount) ∧ Turing.MultiTapeTM.ComputableInO count encCNF Turing.MultiTapeTM.encNat (fun (φ : Logic.PL.CNF ℕ) => 2 ^ (A * (List.length φ + 1) / (Nat.log 2 (φ.numVars + 2)).sqrt) * ((encCNF φ).length + 1) ^ e) fun (φ : Logic.PL.CNF ℕ) => ((encCNF φ).length + 1) ^ b

Model counting by tensor contraction. For each clause width k, one machine computes φ.modelCount on every formula φ whose clauses have at most k literals, in time 2 ^ (A (m + 1) / √⌊log₂ (n + 2)⌋) times a polynomial in the encoding length and in polynomial space, where m is the number of clauses and n the number of variables.

theorem Cslib.Complexity.ContractionCounting.exists_modelCounter_occurrences (k : ℕ) :
∃ (count : Logic.PL.CNF ℕ → ℕ) (A : ℕ) (e : ℕ) (b : ℕ), (∀ (φ : Logic.PL.CNF ℕ), (∀ c ∈ φ, List.length c ≤ k) → count φ = φ.modelCount) ∧ Turing.MultiTapeTM.ComputableInO count encCNF Turing.MultiTapeTM.encNat (fun (φ : Logic.PL.CNF ℕ) => 2 ^ (A * (φ.vars.length + 1) / (Nat.log 2 (φ.vars.length + 2)).sqrt) * ((encCNF φ).length + 1) ^ e) fun (φ : Logic.PL.CNF ℕ) => ((encCNF φ).length + 1) ^ b

Model counting by tensor contraction, measured by literal occurrences. For each clause width k, one machine computes φ.modelCount on every formula φ whose clauses have at most k literals, in time 2 ^ (A (N + 1) / √⌊log₂ (N + 2)⌋) times a polynomial in the encoding length and in polynomial space, where N is the number of literal occurrences. Unlike exists_modelCounter, the exponent does not divide by the logarithm of the number of variables, so it stays O(N / √log N) for formulas with many clauses on few variables.

theorem Cslib.Complexity.ContractionCounting.exists_modelCounter_fixedDensity (k : ℕ) :
∃ (count : Logic.PL.CNF ℕ → ℕ) (T : Logic.PL.CNF ℕ → ℕ) (S : Logic.PL.CNF ℕ → ℕ) (e : ℕ) (b : ℕ), (∀ (φ : Logic.PL.CNF ℕ), (∀ c ∈ φ, List.length c ≤ k) → count φ = φ.modelCount) ∧ Turing.MultiTapeTM.ComputableInO count encCNF Turing.MultiTapeTM.encNat T S ∧ (∀ (φ : Logic.PL.CNF ℕ), S φ = ((encCNF φ).length + 1) ^ b) ∧ ∀ (D : ℕ), ∃ (A : ℕ), ∀ (φ : Logic.PL.CNF ℕ), List.length φ ≤ D * φ.numVars → T φ ≤ 2 ^ (A * (φ.numVars + 1) / (Nat.log 2 (φ.numVars + 2)).sqrt) * ((encCNF φ).length + 1) ^ e

The fixed-density bound of Theorem 1.1. For each clause width k, one machine computes φ.modelCount on every formula φ whose clauses have at most k literals, in polynomial space, and for each density D its time on formulas with at most D n clauses, for n variables, is 2 ^ (A (n + 1) / √⌊log₂ (n + 2)⌋) times a polynomial in the encoding length. The machine, its time and space functions and the degree e of the polynomial are fixed before D; only A depends on D.