Documentation

CslibFrontier.Computability.Complexity.FineGrained.CountingSparsification

Algorithmic counting sparsification on native machines #

Implements the depth-first counting-sparsification search (Cslib.Complexity.CountingSparsify.search) for Lemma 6.3, Proposition 6.4, and Appendix A [OAI26k] on the native multi-tape Turing machines, parallel to the decision sparsifier Cslib.Complexity.Sparsify.search (CslibFrontier/Computability/Complexity/FineGrained/Sparsification.lean). In Lemma 6.3 (Section 6.4, printed p. 43), "The input count is the sum of the leaf counts", obtained in Appendix A (printed p. 44) by "repeatedly splitting a formula into two cases. Both children use the same n variables, and every satisfying assignment of the parent satisfies exactly one child."

Given a formula φ : CNF ℕ with n = φ.numVars occurring variables, the search maintains a state (n, (stk, acc)) (CountingSparsify.State, with n in unary and acc in binary capped at 2 ^ n):

To mirror Sparsify, this module packages the quantitative tree depth (w.length ≤ L_coeff * N) and fixed-parameter leaf-count (W.card ≤ 2 ^ (N / B + 1)) hypotheses into CountingTreeBound, a library adaptation of Appendix A.2–A.3 (Lemmas A.2–A.3, pp. 46–47). The module CslibFrontier.Computability.Complexity.FineGrained.CountingTreeBound supplies this hypothesis from an explicit integer parameter budget. Under CountingTreeBound, running step M K g for Sparsify.rounds B φ = 2 ^ (n / B + 2) steps (the round count shared with Sparsify) visits every leaf of the counting-sparsification tree and returns φ.modelCount (CountingSparsify.search_eq_modelCount). Given a total leaf routine g with hg : ComputableInO g encCNF encNat t t and a global bound ht holding for every ψ : CNF ℕ ((t ψ : ℝ) ≤ c * (2 ^ (δ * ψ.length) * (|encCNF ψ| + 1) ^ e) + c), CountingSparsify.exists_computableInO_search yields a combined time-and-space certificate ComputableInO (search M K k B g) encCNF encNat T T with the fixed-parameter library-adaptation transfer bound T φ ≤ C₀ * (2 ^ ((1 / B + occBound K M * δ) * n) * (|encCNF φ| + 1) ^ E) + C₀. The independent-space extension CountingSparsify.exists_computableInO_search_polySpace instead starts from one total certificate ComputableInO g encCNF encNat t s, with separate quantitative promises for sparse width-≤ k leaf inputs. It preserves this exponential time envelope and gives polynomial workspace in the full encCNF length. Initialization, every traversal prefix including the terminal state, the binary clock, retained declared variables, and the final output are charged. All parameters M, K, k, B, and L_coeff are fixed before the machine is chosen; runtime parameter uniformity and the native subexponential counting endpoint remain separate obligations.

Main definitions #

Main results #

References #

@[reducible, inline]

The states of the counting-sparsification search: the declared variable count n (in unary), a stack of formulas, and a binary accumulator capped at 2 ^ n.

@[reducible, inline]

States encoded as framed tuples, with the declared variable count in unary and the accumulator in binary.

Weight a leaf's occurring-variable model count c by 2 ^ (n - ψ.numVars) for the unused declared variables.

Update the search state when the top of the stack is a sparse leaf with occurring-variable count c, popping the leaf and adding its weighted count (capped at 2 ^ s.1).

One step of the depth-first search of the counting-sparsification tree, for threshold base M and width K: a sparse formula on top of the stack is popped and weighted by leafWeight applied to the leaf counter g; any other formula on top is replaced by its two counting children (countingNext).

The root of the counting-sparsification search: the nontautological normal form (countingNormalize) of a formula of width k, and the unsatisfiable formula [[]] otherwise.

The initial state of the counting-sparsification search on φ.

The counting-sparsification search: run step M K g for rounds B φ rounds from init k φ, and report the accumulated model count.

@[reducible, inline]

The list-level counting branching rule for width K and thresholds countingThreshold M.

The root #

The root as a state of the list-level counting branching rule.

The states of the tree #

The bound 2 ∑_{j < K} countingThreshold M j on the occurrences of a variable in a sparse formula.

theorem Cslib.Complexity.CountingSparsify.vars_walk_subset {M K : ℕ} (hM : 1 ≤ M) (hK : 1 ≤ K) {k : ℕ} (hkK : k ≤ K) {φ : Logic.PL.CNF ℕ} (w : List Bool) :
(↑((rule hM hK).tree.walk (rootState hkK φ) w)).vars.toFinset ⊆ φ.vars.toFinset
theorem Cslib.Complexity.CountingSparsify.numVars_walk_le {M K : ℕ} (hM : 1 ≤ M) (hK : 1 ≤ K) {k : ℕ} (hkK : k ≤ K) {φ : Logic.PL.CNF ℕ} (w : List Bool) :
(↑((rule hM hK).tree.walk (rootState hkK φ) w)).numVars ≤ φ.numVars
theorem Cslib.Complexity.CountingSparsify.length_walk_le {M K : ℕ} (hM : 1 ≤ M) (hK : 1 ≤ K) {k : ℕ} (hkK : k ≤ K) {φ : Logic.PL.CNF ℕ} {w : List Bool} (hw : (rule hM hK).tree.IsNodeWord (rootState hkK φ) w) {h : ℕ} (hwlen : w.length ≤ h) :
List.length ↑((rule hM hK).tree.walk (rootState hkK φ) w) ≤ List.length φ + 1 + K * h

Every state reached along a node word of length at most h has at most φ.length + 1 + K * h clauses.

Sparse leaves are small. The sparse states of the counting-sparsification tree have at most occBound K M * φ.numVars + 1 clauses.

theorem Cslib.Complexity.CountingSparsify.length_le_of_mem_walk {M K : ℕ} (hM : 1 ≤ M) (hK : 1 ≤ K) {k : ℕ} (hkK : k ≤ K) {φ : Logic.PL.CNF ℕ} {w : List Bool} (hw : (rule hM hK).tree.IsNodeWord (rootState hkK φ) w) {C : Logic.PL.Clause ℕ} (hC : C ∈ ↑((rule hM hK).tree.walk (rootState hkK φ) w)) :

Every state of the tree has clause width at most k (for every φ : CNF ℕ and every k : ℕ, including k = 0).

def Cslib.Complexity.CountingSparsify.CountingTreeBound (M K B L_coeff : ℕ) (hM : 1 ≤ M) (hK : 1 ≤ K) :

The fixed-parameter quantitative depth and leaf-count hypotheses for the counting-sparsification tree (a library adaptation of Appendix A.2–A.3, Lemmas A.2–A.3, pp. 46–47 [OAI26k]): from any CountingNormalized K root formula ψ whose occurring variables lie in a finite set declared of size N = declared.card, every leaf word of rule hM hK has length at most L_coeff * N, and any finset of leaf words has cardinality at most 2 ^ (N / B + 1). countingTreeBound_of_budget proves them with L_coeff = countingDepthCoeff K M for 2 ≤ M and 1 ≤ B under an integer parameter budget, and countingTreeBound_countingThresholdBase proves them, with the same L_coeff, at M = countingThresholdBase K B for every 1 ≤ B.

theorem Cslib.Complexity.CountingSparsify.iterate_step {M K : ℕ} (hM : 1 ≤ M) (hK : 1 ≤ K) (hM2 : 2 ≤ M) {k B L_coeff : ℕ} (hkK : k ≤ K) (hTB : CountingTreeBound M K B L_coeff hM hK) (g : Logic.PL.CNF ℕ → ℕ) (φ : Logic.PL.CNF ℕ) :
(∃ (W : Finset (List Bool)), (∀ (w : List Bool), w ∈ W ↔ (rule hM hK).tree.IsLeafWord (rootState hkK φ) w) ∧ (step M K g)^[Sparsify.rounds B φ] (init k φ) = (φ.distinctVars.length, [], min (2 ^ φ.distinctVars.length) (∑ w ∈ W, leafWeight φ.distinctVars.length (↑((rule hM hK).tree.walk (rootState hkK φ) w)) (g ↑((rule hM hK).tree.walk (rootState hkK φ) w))))) ∧ ∀ (i : ℕ), ∃ (stk : List { ψ : Logic.PL.CNF ℕ // Logic.PL.CNF.Sparsification.CountingNormalized K ψ }) (acc : ℕ), (step M K g)^[i] (init k φ) = (φ.distinctVars.length, List.map Subtype.val stk, acc) ∧ stk.length ≤ L_coeff * φ.numVars + 1 ∧ acc ≤ 2 ^ φ.numVars ∧ ∀ t ∈ stk, ∃ (w : List Bool), (rule hM hK).tree.IsNodeWord (rootState hkK φ) w ∧ w.length ≤ L_coeff * φ.numVars ∧ (rule hM hK).tree.walk (rootState hkK φ) w = t

The run of the counting-sparsification search. Under CountingTreeBound, after rounds B φ rounds the stack is empty and the accumulator records the capped sum of leafWeight over the leaf words of rootState hkK φ. At every round i, the stack holds at most L_coeff * φ.numVars + 1 nodes of depth at most L_coeff * φ.numVars, and the accumulator is at most 2 ^ φ.numVars.

theorem Cslib.Complexity.CountingSparsify.search_eq_ite_modelCount_of_normalized {M K : ℕ} (hM : 1 ≤ M) (hK : 1 ≤ K) (hM2 : 2 ≤ M) {k B L_coeff : ℕ} (hkK : k ≤ K) (hTB : CountingTreeBound M K B L_coeff hM hK) {g : Logic.PL.CNF ℕ → ℕ} {φ : Logic.PL.CNF ℕ} (hg : ∀ (ψ : Logic.PL.CNF ℕ), Logic.PL.CNF.Sparsification.CountingNormalized K ψ → (∀ c ∈ ψ, List.length c ≤ k) → Logic.PL.CNF.Sparsification.isSparse (Logic.PL.CNF.Sparsification.countingThreshold M) K ψ = true → ψ.vars.toFinset ⊆ φ.vars.toFinset → List.length ψ ≤ occBound K M * φ.numVars + 1 → g ψ = ψ.modelCount) :
search M K k B g φ = if (List.all φ fun (c : Logic.PL.Clause ℕ) => decide (List.length c ≤ k)) = true then φ.modelCount else 0

Correctness from the invariants of sparse leaves. The counter need only be exact on normalized sparse formulas of width at most k, supported on the input's variables, with at most occBound K M * φ.numVars + 1 clauses. Its values outside this domain do not affect the result. The additive 1 includes the normalized contradiction [[]] when the input has no variables.

theorem Cslib.Complexity.CountingSparsify.search_eq_ite_modelCount_of_subset {M K : ℕ} (hM : 1 ≤ M) (hK : 1 ≤ K) (hM2 : 2 ≤ M) {k B L_coeff : ℕ} (hkK : k ≤ K) (hTB : CountingTreeBound M K B L_coeff hM hK) {g : Logic.PL.CNF ℕ → ℕ} {φ : Logic.PL.CNF ℕ} (hg : ∀ (ψ : Logic.PL.CNF ℕ), (∀ c ∈ ψ, List.length c ≤ k) → Logic.PL.CNF.Sparsification.isSparse (Logic.PL.CNF.Sparsification.countingThreshold M) K ψ = true → ψ.vars.toFinset ⊆ φ.vars.toFinset → g ψ = ψ.modelCount) :
search M K k B g φ = if (List.all φ fun (c : Logic.PL.Clause ℕ) => decide (List.length c ≤ k)) = true then φ.modelCount else 0

The search computes the model count (occurring-variable support promise). If g computes ψ.modelCount on sparse formulas ψ of width at most k whose occurring variables lie in φ.vars.toFinset, then search M K k B g φ returns φ.modelCount on formulas of width at most k and 0 otherwise.

theorem Cslib.Complexity.CountingSparsify.search_eq_ite_modelCount {M K : ℕ} (hM : 1 ≤ M) (hK : 1 ≤ K) (hM2 : 2 ≤ M) {k B L_coeff : ℕ} (hkK : k ≤ K) (hTB : CountingTreeBound M K B L_coeff hM hK) {g : Logic.PL.CNF ℕ → ℕ} (hg : ∀ (ψ : Logic.PL.CNF ℕ), (∀ c ∈ ψ, List.length c ≤ k) → Logic.PL.CNF.Sparsification.isSparse (Logic.PL.CNF.Sparsification.countingThreshold M) K ψ = true → g ψ = ψ.modelCount) (φ : Logic.PL.CNF ℕ) :
search M K k B g φ = if (List.all φ fun (c : Logic.PL.Clause ℕ) => decide (List.length c ≤ k)) = true then φ.modelCount else 0

The search computes the model count. If g computes ψ.modelCount on sparse formulas ψ of width at most k, then search M K k B g φ returns φ.modelCount on formulas of width at most k and 0 otherwise.

theorem Cslib.Complexity.CountingSparsify.search_eq_modelCount {M K : ℕ} (hM : 1 ≤ M) (hK : 1 ≤ K) (hM2 : 2 ≤ M) {k B L_coeff : ℕ} (hkK : k ≤ K) (hTB : CountingTreeBound M K B L_coeff hM hK) {g : Logic.PL.CNF ℕ → ℕ} (hg : ∀ (ψ : Logic.PL.CNF ℕ), (∀ c ∈ ψ, List.length c ≤ k) → Logic.PL.CNF.Sparsification.isSparse (Logic.PL.CNF.Sparsification.countingThreshold M) K ψ = true → g ψ = ψ.modelCount) {φ : Logic.PL.CNF ℕ} (hφ : ∀ c ∈ φ, List.length c ≤ k) :
search M K k B g φ = φ.modelCount

The search computes φ.modelCount on formulas of width at most k.

Polynomial-time parts #

Encoded state sizes #

A bound on the length of the encoded formulas in the counting-sparsification tree.

A bound on the length of the encoded states of the counting-sparsification search.

theorem Cslib.Complexity.CountingSparsify.nodeBound_polyBounded {α : Type u_1} {size depth : α → ℕ} {φ : α → Logic.PL.CNF ℕ} (K : ℕ) (hφ : Turing.MultiTapeTM.PolyBounded size fun (x : α) => (encCNF (φ x)).length) (hdepth : Turing.MultiTapeTM.PolyBounded size depth) :
Turing.MultiTapeTM.PolyBounded size fun (x : α) => nodeBound K (depth x) (φ x)

The encoded-node bound is polynomial in any input size that polynomially bounds both the encoded formula length and the tree-depth coefficient.

nodeBound is polynomial in the encoded length of the formula at fixed depth coefficient.

stateBound is polynomial in the encoded length of the formula.

theorem Cslib.Complexity.CountingSparsify.length_encCNF_walk_le {M K : ℕ} (hM : 1 ≤ M) (hK : 1 ≤ K) {k L_coeff : ℕ} (hkK : k ≤ K) {φ : Logic.PL.CNF ℕ} {w : List Bool} (hw : (rule hM hK).tree.IsNodeWord (rootState hkK φ) w) (hwlen : w.length ≤ L_coeff * φ.numVars) :
(encCNF ↑((rule hM hK).tree.walk (rootState hkK φ) w)).length ≤ nodeBound K L_coeff φ
theorem Cslib.Complexity.CountingSparsify.length_encState_le {M K : ℕ} (hM : 1 ≤ M) (hK : 1 ≤ K) {k L_coeff : ℕ} (hkK : k ≤ K) {φ : Logic.PL.CNF ℕ} {stk : List { ψ : Logic.PL.CNF ℕ // Logic.PL.CNF.Sparsification.CountingNormalized K ψ }} {acc : ℕ} (hstk : stk.length ≤ L_coeff * φ.numVars + 1) (hacc : acc ≤ 2 ^ φ.numVars) (hmem : ∀ t ∈ stk, ∃ (w : List Bool), (rule hM hK).tree.IsNodeWord (rootState hkK φ) w ∧ w.length ≤ L_coeff * φ.numVars ∧ (rule hM hK).tree.walk (rootState hkK φ) w = t) :
theorem Cslib.Complexity.CountingSparsify.iterate_step_prefix_bounds {M K : ℕ} (hM : 1 ≤ M) (hK : 1 ≤ K) (hM2 : 2 ≤ M) {k B L_coeff : ℕ} (hkK : k ≤ K) (hTB : CountingTreeBound M K B L_coeff hM hK) (g : Logic.PL.CNF ℕ → ℕ) (φ : Logic.PL.CNF ℕ) (i : ℕ) :
have s := (step M K g)^[i] (init k φ); s.1 = φ.distinctVars.length ∧ (encState s).length ≤ stateBound K L_coeff φ ∧ φ.numVars + 1 ≤ stateBound K L_coeff φ ∧ (s.2.1.isEmpty = false ∧ Logic.PL.CNF.Sparsification.isSparse (Logic.PL.CNF.Sparsification.countingThreshold M) K (s.2.1.headD []) = true → have ψ := s.2.1.headD []; (∀ c ∈ ψ, List.length c ≤ k) ∧ ψ.vars.toFinset ⊆ φ.vars.toFinset ∧ ψ.numVars ≤ φ.numVars ∧ List.length ψ ≤ occBound K M * φ.numVars + 1 ∧ (encCNF ψ).length ≤ nodeBound K L_coeff φ)

Packaged all-prefix invariants of CountingSparsify.step. Under CountingTreeBound M K B L_coeff hM hK, for every round i : ℕ:

  1. the retained variable count .1 is φ.distinctVars.length and the encoded state has length at most stateBound K L_coeff φ (with φ.numVars + 1 ≤ stateBound K L_coeff φ);
  2. whenever the stack is nonempty and its top formula ψ is (countingThreshold M, K)-sparse, ψ has clause width ≤ k, variable support contained in φ.vars.toFinset, ψ.numVars ≤ φ.numVars, ψ.length ≤ occBound K M * φ.numVars + 1, and (encCNF ψ).length ≤ nodeBound K L_coeff φ.
theorem Cslib.Complexity.CountingSparsify.acceptCount_search_pos_error_le {M K : ℕ} (hM : 1 ≤ M) (hK : 1 ≤ K) (hM2 : 2 ≤ M) {k B L_coeff : ℕ} (hkK : k ≤ K) (hTB : CountingTreeBound M K B L_coeff hM hK) {φ : Logic.PL.CNF ℕ} (hφ : ∀ c ∈ φ, List.length c ≤ k) (V : Logic.PL.CNF ℕ × List Bool → ℕ) (width : Logic.PL.CNF ℕ → ℕ) (n : ℕ) {ε : ℝ} (hε : 0 ≤ ε) (hleaf : ∀ (ψ : Logic.PL.CNF ℕ), Logic.PL.CNF.Sparsification.CountingNormalized K ψ → (∀ c ∈ ψ, List.length c ≤ k) → Logic.PL.CNF.Sparsification.isSparse (Logic.PL.CNF.Sparsification.countingThreshold M) K ψ = true → ψ.vars.toFinset ⊆ φ.vars.toFinset → List.length ψ ≤ occBound K M * φ.numVars + 1 → (encCNF ψ).length ≤ nodeBound K L_coeff φ → width ψ ≤ n ∧ ↑(acceptCount (fun (p : Logic.PL.CNF ℕ × List Bool) => decide (0 < V p) != decide (0 < p.1.modelCount)) ψ (width ψ)) ≤ ε * 2 ^ width ψ) :
↑(acceptCount (fun (p : Logic.PL.CNF ℕ × List Bool) => decide (0 < search M K k B (fun (ψ : Logic.PL.CNF ℕ) => V (ψ, List.take (width ψ) p.2)) p.1) != decide (0 < p.1.modelCount)) φ n) ≤ 2 ^ (φ.numVars / B + 1) * (ε * 2 ^ n)

The counting-sparsification search detects satisfiability by testing its output for positivity. With a shared seed, its error fraction is at most 2 ^ (φ.numVars / B + 1) * ε when each leaf routine has error fraction at most ε. The leaf contract includes the root's variable support, the leaf clause bound, and the encoded-length bound, so a shared seed can cover lengths that depend on the leaf encoding. For a valid declared input the same positivity test applies to searchDeclaredWith by searchDeclaredWith_eq_ite_mul.

theorem Cslib.Complexity.CountingSparsify.acceptCount_search_error_le {M K : ℕ} (hM : 1 ≤ M) (hK : 1 ≤ K) (hM2 : 2 ≤ M) {k B L_coeff : ℕ} (hkK : k ≤ K) (hTB : CountingTreeBound M K B L_coeff hM hK) {φ : Logic.PL.CNF ℕ} (hφ : ∀ c ∈ φ, List.length c ≤ k) (V : Logic.PL.CNF ℕ × List Bool → ℕ) (width : Logic.PL.CNF ℕ → ℕ) (n : ℕ) {ε : ℝ} (hε : 0 ≤ ε) (hleaf : ∀ (ψ : Logic.PL.CNF ℕ), Logic.PL.CNF.Sparsification.CountingNormalized K ψ → (∀ c ∈ ψ, List.length c ≤ k) → Logic.PL.CNF.Sparsification.isSparse (Logic.PL.CNF.Sparsification.countingThreshold M) K ψ = true → ψ.vars.toFinset ⊆ φ.vars.toFinset → List.length ψ ≤ occBound K M * φ.numVars + 1 → (encCNF ψ).length ≤ nodeBound K L_coeff φ → width ψ ≤ n ∧ ↑(acceptCount (fun (p : Logic.PL.CNF ℕ × List Bool) => V p != p.1.modelCount) ψ (width ψ)) ≤ ε * 2 ^ width ψ) :
↑(acceptCount (fun (p : Logic.PL.CNF ℕ × List Bool) => search M K k B (fun (ψ : Logic.PL.CNF ℕ) => V (ψ, List.take (width ψ) p.2)) p.1 != p.1.modelCount) φ n) ≤ 2 ^ (φ.numVars / B + 1) * (ε * 2 ^ n)

Counting sparsification on a shared uniform seed returns the exact model count except with probability at most 2 ^ (φ.numVars / B + 1) * ε. Each leaf reads a prefix of its own prescribed width and returns the count over its occurring variables. The search supplies the multiplicities for variables omitted from the leaf.

theorem Cslib.Complexity.CountingSparsify.exists_computableInO_search_polySpace {M K : ℕ} (hM : 1 ≤ M) (hK : 1 ≤ K) (hM2 : 2 ≤ M) {k B L_coeff : ℕ} (hkK : k ≤ K) (hTB : CountingTreeBound M K B L_coeff hM hK) {g t s : Logic.PL.CNF ℕ → ℕ} (hg : Turing.MultiTapeTM.ComputableInO g encCNF Turing.MultiTapeTM.encNat t s) (hg_le : ∀ (ψ : Logic.PL.CNF ℕ), (∀ c ∈ ψ, List.length c ≤ k) → Logic.PL.CNF.Sparsification.isSparse (Logic.PL.CNF.Sparsification.countingThreshold M) K ψ = true → g ψ ≤ 2 ^ ψ.numVars) {δ : ℝ} (hδ : 0 ≤ δ) {c e a b : ℕ} (ht : ∀ (ψ : Logic.PL.CNF ℕ), (∀ C ∈ ψ, List.length C ≤ k) → Logic.PL.CNF.Sparsification.isSparse (Logic.PL.CNF.Sparsification.countingThreshold M) K ψ = true → ↑(t ψ) ≤ ↑c * (2 ^ (δ * ↑(List.length ψ)) * (↑(encCNF ψ).length + 1) ^ e) + ↑c) (hs : ∀ (ψ : Logic.PL.CNF ℕ), (∀ C ∈ ψ, List.length C ≤ k) → Logic.PL.CNF.Sparsification.isSparse (Logic.PL.CNF.Sparsification.countingThreshold M) K ψ = true → s ψ ≤ a * ((encCNF ψ).length + 1) ^ b) :
∃ (T : Logic.PL.CNF ℕ → ℕ) (S : Logic.PL.CNF ℕ → ℕ) (C₀ : ℕ) (E : ℕ), Turing.MultiTapeTM.ComputableInO (search M K k B g) encCNF Turing.MultiTapeTM.encNat T S ∧ Turing.MultiTapeTM.PolyBounded (fun (φ : Logic.PL.CNF ℕ) => (encCNF φ).length) S ∧ ∀ (φ : Logic.PL.CNF ℕ), ↑(T φ) ≤ ↑C₀ * (2 ^ ((1 / ↑B + ↑(occBound K M) * δ) * ↑φ.numVars) * (↑(encCNF φ).length + 1) ^ E) + ↑C₀

Independent polynomial workspace for counting sparsification. A single total leaf machine with separate time t and workspace s gives a single total machine for the existing search. Only sparse width-≤ k inputs need satisfy the quantitative leaf promises ht, hs, and hg_le. The workspace includes all traversal prefixes and the terminal state, the full encoded formulas, initialization, binary loop clock, retained declared-variable count, and output accumulator.

The parameters M, K, k, B, and L_coeff, and all leaf-bound constants are fixed before the machine is chosen. Polynomial workspace is measured in the full encCNF length, independently of the exponential number of rounds and leaf time. This resource transfer does not construct a leaf counter or provide a uniform machine for runtime choices of these parameters.

Captured runtime context and declared-variable wrapper #

def Cslib.Complexity.CountingSparsify.stepWith {P : Type u_1} (θ : P → ℕ → ℕ) (K : ℕ) (g : P × Logic.PL.CNF ℕ → ℕ) (ps : P × State) :

One step of the depth-first search of the counting-sparsification tree carrying an unchanged runtime context p : P, using threshold family θ p and context-aware leaf counter g (returning the occurring-variable count ψ.modelCount on sparse leaves).

@[simp]
theorem Cslib.Complexity.CountingSparsify.stepWith_fst {P : Type u_1} (θ : P → ℕ → ℕ) (K : ℕ) (g : P × Logic.PL.CNF ℕ → ℕ) (ps : P × State) :
(stepWith θ K g ps).1 = ps.1
@[simp]
theorem Cslib.Complexity.CountingSparsify.iterate_stepWith_fst {P : Type u_1} (θ : P → ℕ → ℕ) (K : ℕ) (g : P × Logic.PL.CNF ℕ → ℕ) (r : ℕ) (ps : P × State) :
((stepWith θ K g)^[r] ps).1 = ps.1
@[simp]
theorem Cslib.Complexity.CountingSparsify.stepWith_countingThreshold {P : Type u_1} (MOf : P → ℕ) (K : ℕ) (g : P × Logic.PL.CNF ℕ → ℕ) (p : P) (s : State) :
stepWith (fun (q : P) => Logic.PL.CNF.Sparsification.countingThreshold (MOf q)) K g (p, s) = (p, step (MOf p) K (fun (ψ : Logic.PL.CNF ℕ) => g (p, ψ)) s)
@[simp]
theorem Cslib.Complexity.CountingSparsify.iterate_stepWith_countingThreshold {P : Type u_1} (MOf : P → ℕ) (K : ℕ) (g : P × Logic.PL.CNF ℕ → ℕ) (r : ℕ) (p : P) (s : State) :
(stepWith (fun (q : P) => Logic.PL.CNF.Sparsification.countingThreshold (MOf q)) K g)^[r] (p, s) = (p, (step (MOf p) K fun (ψ : Logic.PL.CNF ℕ) => g (p, ψ))^[r] s)
def Cslib.Complexity.CountingSparsify.searchWith {P : Type u_1} (MOf BOf : P → ℕ) (K k : ℕ) (g : P × Logic.PL.CNF ℕ → ℕ) (p : P) (φ : Logic.PL.CNF ℕ) :

Runtime-context counting-sparsification search (occurring-variable count): run stepWith (fun q => countingThreshold (MOf q)) K g for rounds (BOf p) φ steps from (p, init k φ) and return the accumulated occurring-variable count.

def Cslib.Complexity.CountingSparsify.searchDeclaredWith {P : Type u_1} (NOf MOf BOf : P → ℕ) (K k : ℕ) (g : P × Logic.PL.CNF ℕ → ℕ) (p : P) (φ : Logic.PL.CNF ℕ) :

Declared-variable counting-sparsification wrapper: guards width ≤ k and variable support ⊆ Finset.range (NOf p), runs searchWith MOf BOf K k g p φ (retaining State.1 = φ.numVars), and shifts left by NOf p - φ.distinctVars.length (= * 2 ^ (NOf p - φ.numVars)). Returns φ.modelCountOn (Finset.range (NOf p)) on valid inputs (including 2 ^ NOf p on the empty formula []) and 0 otherwise.

theorem Cslib.Complexity.CountingSparsify.searchDeclaredWith_eq_ite_mul {P : Type u_1} (NOf MOf BOf : P → ℕ) (K k : ℕ) (g : P × Logic.PL.CNF ℕ → ℕ) (p : P) (φ : Logic.PL.CNF ℕ) :
searchDeclaredWith NOf MOf BOf K k g p φ = if Logic.PL.CNF.validDeclaredInput k (NOf p) φ = true then 2 ^ (NOf p - φ.numVars) * search (MOf p) K k (BOf p) (fun (ψ : Logic.PL.CNF ℕ) => g (p, ψ)) φ else 0
theorem Cslib.Complexity.CountingSparsify.searchDeclaredWith_pos_iff_of_normalized {P : Type u_1} {NOf MOf BOf : P → ℕ} {K k L_coeff : ℕ} {p : P} (hM : 1 ≤ MOf p) (hK : 1 ≤ K) (hM2 : 2 ≤ MOf p) (hkK : k ≤ K) (hTB : CountingTreeBound (MOf p) K (BOf p) L_coeff hM hK) {g : P × Logic.PL.CNF ℕ → ℕ} (hg : ∀ (ψ : Logic.PL.CNF ℕ), Logic.PL.CNF.Sparsification.CountingNormalized K ψ → (∀ c ∈ ψ, List.length c ≤ k) → Logic.PL.CNF.Sparsification.isSparse (Logic.PL.CNF.Sparsification.countingThreshold (MOf p)) K ψ = true → ψ.vars.toFinset ⊆ Finset.range (NOf p) → List.length ψ ≤ occBound K (MOf p) * NOf p + 1 → (0 < g (p, ψ) ↔ ψ.Satisfiable)) (φ : Logic.PL.CNF ℕ) :
0 < searchDeclaredWith NOf MOf BOf K k g p φ ↔ Logic.PL.CNF.validDeclaredInput k (NOf p) φ = true ∧ φ.Satisfiable

The declared search detects satisfiability if the leaf routine returns a positive value exactly on satisfiable normalized sparse leaves within the declared support and clause bound. An invalid width or support fails the test. This gives the semantic step for using a leaf decision routine toward the decision transfer in [MITHardnessGroup2026SH, v2, §2.2, Corollary 2.3], tracked in #8457.

theorem Cslib.Complexity.CountingSparsify.searchDeclaredWith_eq_ite_modelCountOn_of_normalized {P : Type u_1} {NOf MOf BOf : P → ℕ} {K k L_coeff : ℕ} {p : P} (hM : 1 ≤ MOf p) (hK : 1 ≤ K) (hM2 : 2 ≤ MOf p) (hkK : k ≤ K) (hTB : CountingTreeBound (MOf p) K (BOf p) L_coeff hM hK) {g : P × Logic.PL.CNF ℕ → ℕ} (hg : ∀ (ψ : Logic.PL.CNF ℕ), Logic.PL.CNF.Sparsification.CountingNormalized K ψ → (∀ c ∈ ψ, List.length c ≤ k) → Logic.PL.CNF.Sparsification.isSparse (Logic.PL.CNF.Sparsification.countingThreshold (MOf p)) K ψ = true → ψ.vars.toFinset ⊆ Finset.range (NOf p) → List.length ψ ≤ occBound K (MOf p) * NOf p + 1 → g (p, ψ) = ψ.modelCount) (φ : Logic.PL.CNF ℕ) :
searchDeclaredWith NOf MOf BOf K k g p φ = if Logic.PL.CNF.validDeclaredInput k (NOf p) φ = true then φ.modelCountOn (Finset.range (NOf p)) else 0

Declared-variable correctness from normalized bounded leaves. The occurring-variable counter need only be exact on normalized sparse width-≤ k formulas supported on the declared range and having at most occBound K (MOf p) * NOf p + 1 clauses.

theorem Cslib.Complexity.CountingSparsify.searchDeclaredWith_eq_modelCountOn_of_normalized {P : Type u_1} {NOf MOf BOf : P → ℕ} {K k L_coeff : ℕ} {p : P} (hM : 1 ≤ MOf p) (hK : 1 ≤ K) (hM2 : 2 ≤ MOf p) (hkK : k ≤ K) (hTB : CountingTreeBound (MOf p) K (BOf p) L_coeff hM hK) {g : P × Logic.PL.CNF ℕ → ℕ} (hg : ∀ (ψ : Logic.PL.CNF ℕ), Logic.PL.CNF.Sparsification.CountingNormalized K ψ → (∀ c ∈ ψ, List.length c ≤ k) → Logic.PL.CNF.Sparsification.isSparse (Logic.PL.CNF.Sparsification.countingThreshold (MOf p)) K ψ = true → ψ.vars.toFinset ⊆ Finset.range (NOf p) → List.length ψ ≤ occBound K (MOf p) * NOf p + 1 → g (p, ψ) = ψ.modelCount) {φ : Logic.PL.CNF ℕ} (hw : ∀ c ∈ φ, List.length c ≤ k) (hsub : φ.vars.toFinset ⊆ Finset.range (NOf p)) :
searchDeclaredWith NOf MOf BOf K k g p φ = φ.modelCountOn (Finset.range (NOf p))

Declared-variable correctness on valid inputs, from the invariants of sparse leaves.

theorem Cslib.Complexity.CountingSparsify.searchDeclaredWith_eq_ite_modelCountOn {P : Type u_1} {NOf MOf BOf : P → ℕ} {K k L_coeff : ℕ} {p : P} (hM : 1 ≤ MOf p) (hK : 1 ≤ K) (hM2 : 2 ≤ MOf p) (hkK : k ≤ K) (hTB : CountingTreeBound (MOf p) K (BOf p) L_coeff hM hK) {g : P × Logic.PL.CNF ℕ → ℕ} (hg : ∀ (ψ : Logic.PL.CNF ℕ), (∀ c ∈ ψ, List.length c ≤ k) → Logic.PL.CNF.Sparsification.isSparse (Logic.PL.CNF.Sparsification.countingThreshold (MOf p)) K ψ = true → ψ.vars.toFinset ⊆ Finset.range (NOf p) → g (p, ψ) = ψ.modelCount) (φ : Logic.PL.CNF ℕ) :
searchDeclaredWith NOf MOf BOf K k g p φ = if Logic.PL.CNF.validDeclaredInput k (NOf p) φ = true then φ.modelCountOn (Finset.range (NOf p)) else 0

Correctness of searchDeclaredWith under CountingTreeBound. If g (p, ψ) = ψ.modelCount on sparse formulas ψ of width ≤ k whose occurring variables lie in Finset.range (NOf p), then searchDeclaredWith returns φ.modelCountOn (Finset.range (NOf p)) when validDeclaredInput k (NOf p) φ = true and 0 otherwise.

theorem Cslib.Complexity.CountingSparsify.searchDeclaredWith_eq_modelCountOn {P : Type u_1} {NOf MOf BOf : P → ℕ} {K k L_coeff : ℕ} {p : P} (hM : 1 ≤ MOf p) (hK : 1 ≤ K) (hM2 : 2 ≤ MOf p) (hkK : k ≤ K) (hTB : CountingTreeBound (MOf p) K (BOf p) L_coeff hM hK) {g : P × Logic.PL.CNF ℕ → ℕ} (hg : ∀ (ψ : Logic.PL.CNF ℕ), (∀ c ∈ ψ, List.length c ≤ k) → Logic.PL.CNF.Sparsification.isSparse (Logic.PL.CNF.Sparsification.countingThreshold (MOf p)) K ψ = true → ψ.vars.toFinset ⊆ Finset.range (NOf p) → g (p, ψ) = ψ.modelCount) {φ : Logic.PL.CNF ℕ} (hw : ∀ c ∈ φ, List.length c ≤ k) (hsub : φ.vars.toFinset ⊆ Finset.range (NOf p)) :
searchDeclaredWith NOf MOf BOf K k g p φ = φ.modelCountOn (Finset.range (NOf p))

Correctness of searchDeclaredWith on valid inputs under CountingTreeBound.

theorem Cslib.Complexity.CountingSparsify.searchDeclaredWith_normalizeDeclaredLeaf_eq_ite_modelCountOn_of_normalized {P : Type u_1} {NOf MOf BOf : P → ℕ} {K k L_coeff : ℕ} {p : P} (hM : 1 ≤ MOf p) (hK : 1 ≤ K) (hM2 : 2 ≤ MOf p) (hkK : k ≤ K) (hTB : CountingTreeBound (MOf p) K (BOf p) L_coeff hM hK) {h : P × Logic.PL.CNF ℕ → ℕ} (hh : ∀ (ψ : Logic.PL.CNF ℕ), Logic.PL.CNF.Sparsification.CountingNormalized K ψ → (∀ c ∈ ψ, List.length c ≤ k) → Logic.PL.CNF.Sparsification.isSparse (Logic.PL.CNF.Sparsification.countingThreshold (MOf p)) K ψ = true → ψ.vars.toFinset ⊆ Finset.range (NOf p) → List.length ψ ≤ occBound K (MOf p) * NOf p + 1 → h (p, ψ) = ψ.modelCountOn (Finset.range (NOf p))) (φ : Logic.PL.CNF ℕ) :

Normalize a declared-variable leaf counter that is exact only on normalized bounded leaves, then recover the original declared-variable count. The input guard returns zero on invalid inputs.

theorem Cslib.Complexity.CountingSparsify.searchDeclaredWith_normalizeDeclaredLeaf_eq_modelCountOn_of_normalized {P : Type u_1} {NOf MOf BOf : P → ℕ} {K k L_coeff : ℕ} {p : P} (hM : 1 ≤ MOf p) (hK : 1 ≤ K) (hM2 : 2 ≤ MOf p) (hkK : k ≤ K) (hTB : CountingTreeBound (MOf p) K (BOf p) L_coeff hM hK) {h : P × Logic.PL.CNF ℕ → ℕ} (hh : ∀ (ψ : Logic.PL.CNF ℕ), Logic.PL.CNF.Sparsification.CountingNormalized K ψ → (∀ c ∈ ψ, List.length c ≤ k) → Logic.PL.CNF.Sparsification.isSparse (Logic.PL.CNF.Sparsification.countingThreshold (MOf p)) K ψ = true → ψ.vars.toFinset ⊆ Finset.range (NOf p) → List.length ψ ≤ occBound K (MOf p) * NOf p + 1 → h (p, ψ) = ψ.modelCountOn (Finset.range (NOf p))) {φ : Logic.PL.CNF ℕ} (hw : ∀ c ∈ φ, List.length c ≤ k) (hsub : φ.vars.toFinset ⊆ Finset.range (NOf p)) :

Declared-variable correctness on valid inputs after normalizing a counter whose correctness is restricted to normalized bounded sparse leaves.

theorem Cslib.Complexity.CountingSparsify.searchDeclaredWith_normalizeDeclaredLeaf_eq_ite_modelCountOn {P : Type u_1} {NOf MOf BOf : P → ℕ} {K k L_coeff : ℕ} {p : P} (hM : 1 ≤ MOf p) (hK : 1 ≤ K) (hM2 : 2 ≤ MOf p) (hkK : k ≤ K) (hTB : CountingTreeBound (MOf p) K (BOf p) L_coeff hM hK) {h : P × Logic.PL.CNF ℕ → ℕ} (hh : ∀ (ψ : Logic.PL.CNF ℕ), (∀ c ∈ ψ, List.length c ≤ k) → Logic.PL.CNF.Sparsification.isSparse (Logic.PL.CNF.Sparsification.countingThreshold (MOf p)) K ψ = true → ψ.vars.toFinset ⊆ Finset.range (NOf p) → h (p, ψ) = ψ.modelCountOn (Finset.range (NOf p))) (φ : Logic.PL.CNF ℕ) :

Correctness of searchDeclaredWith composed with normalizeDeclaredLeaf. When a leaf provider h : P × CNF ℕ → ℕ returns the declared-range count ψ.modelCountOn (Finset.range (NOf p)) on sparse width-≤ k leaves with ψ.vars.toFinset ⊆ Finset.range (NOf p), normalizing h via normalizeDeclaredLeaf NOf h makes searchDeclaredWith compute φ.modelCountOn (Finset.range (NOf p)) on valid inputs and 0 otherwise.

theorem Cslib.Complexity.CountingSparsify.searchDeclaredWith_normalizeDeclaredLeaf_eq_modelCountOn {P : Type u_1} {NOf MOf BOf : P → ℕ} {K k L_coeff : ℕ} {p : P} (hM : 1 ≤ MOf p) (hK : 1 ≤ K) (hM2 : 2 ≤ MOf p) (hkK : k ≤ K) (hTB : CountingTreeBound (MOf p) K (BOf p) L_coeff hM hK) {h : P × Logic.PL.CNF ℕ → ℕ} (hh : ∀ (ψ : Logic.PL.CNF ℕ), (∀ c ∈ ψ, List.length c ≤ k) → Logic.PL.CNF.Sparsification.isSparse (Logic.PL.CNF.Sparsification.countingThreshold (MOf p)) K ψ = true → ψ.vars.toFinset ⊆ Finset.range (NOf p) → h (p, ψ) = ψ.modelCountOn (Finset.range (NOf p))) {φ : Logic.PL.CNF ℕ} (hw : ∀ c ∈ φ, List.length c ≤ k) (hsub : φ.vars.toFinset ⊆ Finset.range (NOf p)) :

Correctness of searchDeclaredWith composed with normalizeDeclaredLeaf on valid inputs.