Documentation

CslibFrontier.Computability.Complexity.FineGrained.ContractionCircuitCounting

Counting satisfying inputs of circuits by tensor contraction #

For every finite Boolean signature, one native machine computes the number of satisfying inputs of every circuit with s gates in time 2 ^ (A (s + 1) / √⌊log₂ (s + 2)⌋) times a polynomial in the encoding length, and in polynomial space (ContractionCounting.exists_circuitSatCounter). On circuits with at most C n + C gates, for n inputs, this is time 2 ^ O_C(n / √log n) times a polynomial (ContractionCounting.exists_linearSizeCircuitSatCounter), with the machine fixed before C.

The machine compiles the circuit with the frontier compiler (Frontier.Compiler.toCNF), which introduces one variable for each reachable wire and preserves the count up to the factor 2 ^ Compiler.freeShift (Compiler.acceptCount_eq_two_pow_freeShift_mul_modelCount), and counts the models of the formula with the tensor-contraction counter ContractionCounting.exists_modelCounter. That counter runs in time 2 ^ (A (m + 1) / √⌊log₂ (n + 2)⌋) for m clauses on n variables, so it needs the formula to be sparse: every reachable gate's wire is a variable, so a circuit of fan-in k with o outputs compiles to at most 2 ^ (k + 1) (n + o) clauses on n variables (Compiler.length_toCNF_le_numVars). The number of variables is at most k s + o.

This replaces the interpolationScale rate of CircuitCounting.exists_circuitSatCounter, the §6.4 rate of [OAI26k], by the fixed-density rate of its Theorem 1.1.

Source relation #

Appendix C.1 of [OAI26k] (p. 51) encodes a circuit with n inputs and s gates as a 3-CNF with a variable for each gate and O(n + s) variables and clauses, to decide satisfiability of linear-size circuits in time 2 ^ o(n); Theorem 1.1 (p. 2) gives the fixed-density counting rate 2 ^ O(n / √log n) for #k-SAT with at most D n clauses. Exact counting over arbitrary finite signatures, with the exponent in the number of gates, is a library extension.

Main results #

References #

Composing the counter with a compilation to sparse formulas #

theorem Cslib.Complexity.ContractionCounting.exists_shiftedCounter_of_polyTime_toCNF {α : Type} {encA : α ↪ List Bool} (k D C : ℕ) {φ : α → Logic.PL.CNF ℕ} (hφ : Turing.MultiTapeTM.ComputableInPolyTime φ encA encCNF) {shift : α → ℕ} (hshift : Turing.MultiTapeTM.ComputableInPolyTime shift encA Turing.MultiTapeTM.encUnary) (μ : α → ℕ) (hwidth : ∀ (x : α), ∀ cl ∈ φ x, List.length cl ≤ k) (hdense : ∀ (x : α), List.length (φ x) ≤ D * ((φ x).numVars + 1)) (hvars : ∀ (x : α), (φ x).numVars ≤ C * μ x + C) :
∃ (count : α → ℕ) (A : ℕ) (e : ℕ) (b : ℕ), (∀ (x : α), count x = 2 ^ shift x * (φ x).modelCount) ∧ Turing.MultiTapeTM.ComputableInO count encA Turing.MultiTapeTM.encNat (fun (x : α) => 2 ^ (A * (μ x + 1) / (Nat.log 2 (μ x + 2)).sqrt) * ((encA x).length + 1) ^ e) fun (x : α) => ((encA x).length + 1) ^ b

Counting through a sparse compilation. Given a polynomial-time compilation φ to formulas whose clauses have at most k literals, with at most D (n + 1) clauses on n variables and at most C μ + C variables, and a polynomial-time shift, one machine computes 2 ^ shift x * (φ x).modelCount in time 2 ^ (A (μ x + 1) / √⌊log₂ (μ x + 2)⌋) times a polynomial in the encoding length, and in polynomial space.

Circuits #

theorem Cslib.Complexity.ContractionCounting.exists_circuitAcceptCounter {σ : Circuits.Signature} [Finite σ.Op] (encOp : σ.Op ↪ List Bool) (I : Circuits.Interpretation σ Bool) {m : ℕ} (acc : Fin m → Bool → Bool) :
∃ (count : (n : ℕ) × Circuits.Circuit σ n m → ℕ) (A : ℕ) (e : ℕ) (b : ℕ), (∀ (c : (n : ℕ) × Circuits.Circuit σ n m), count c = c.snd.acceptCount I acc) ∧ Turing.MultiTapeTM.ComputableInO count (Circuits.Circuit.encCircuit encOp m) Turing.MultiTapeTM.encNat (fun (c : (n : ℕ) × Circuits.Circuit σ n m) => 2 ^ (A * (c.snd.size + 1) / (Nat.log 2 (c.snd.size + 2)).sqrt) * (((Circuits.Circuit.encCircuit encOp m) c).length + 1) ^ e) fun (c : (n : ℕ) × Circuits.Circuit σ n m) => (((Circuits.Circuit.encCircuit encOp m) c).length + 1) ^ b

Acceptance counting for circuits by tensor contraction. For every finite Boolean signature σ and output predicate acc, one machine computes c.2.acceptCount I acc on every circuit c, in time 2 ^ (A (s + 1) / √⌊log₂ (s + 2)⌋) times a polynomial in the encoding length, where s is the number of gates, and in polynomial space.

theorem Cslib.Complexity.ContractionCounting.exists_circuitSatCounter {σ : Circuits.Signature} [Finite σ.Op] (encOp : σ.Op ↪ List Bool) (I : Circuits.Interpretation σ Bool) :
∃ (count : (n : ℕ) × Circuits.Circuit σ n 1 → ℕ) (A : ℕ) (e : ℕ) (b : ℕ), (∀ (c : (n : ℕ) × Circuits.Circuit σ n 1), count c = c.snd.satCount I) ∧ Turing.MultiTapeTM.ComputableInO count (Circuits.Circuit.encCircuit encOp 1) Turing.MultiTapeTM.encNat (fun (c : (n : ℕ) × Circuits.Circuit σ n 1) => 2 ^ (A * (c.snd.size + 1) / (Nat.log 2 (c.snd.size + 2)).sqrt) * (((Circuits.Circuit.encCircuit encOp 1) c).length + 1) ^ e) fun (c : (n : ℕ) × Circuits.Circuit σ n 1) => (((Circuits.Circuit.encCircuit encOp 1) c).length + 1) ^ b

#Circuit-SAT by tensor contraction. For every finite Boolean signature σ, one machine computes the number c.2.satCount I of satisfying inputs of every circuit c, in time 2 ^ (A (s + 1) / √⌊log₂ (s + 2)⌋) times a polynomial in the encoding length, where s is the number of gates, and in polynomial space.

De Morgan #Circuit-SAT by tensor contraction. One machine computes the number of satisfying inputs of every De Morgan circuit with s gates in time 2 ^ (A (s + 1) / √⌊log₂ (s + 2)⌋) times a polynomial in the encoding length, and in polynomial space.

theorem Cslib.Complexity.ContractionCounting.exists_linearSizeCircuitSatCounter {σ : Circuits.Signature} [Finite σ.Op] (encOp : σ.Op ↪ List Bool) (I : Circuits.Interpretation σ Bool) :
∃ (count : (n : ℕ) × Circuits.Circuit σ n 1 → ℕ) (T : (n : ℕ) × Circuits.Circuit σ n 1 → ℕ) (S : (n : ℕ) × Circuits.Circuit σ n 1 → ℕ) (e : ℕ) (b : ℕ), (∀ (c : (n : ℕ) × Circuits.Circuit σ n 1), count c = c.snd.satCount I) ∧ Turing.MultiTapeTM.ComputableInO count (Circuits.Circuit.encCircuit encOp 1) Turing.MultiTapeTM.encNat T S ∧ (∀ (c : (n : ℕ) × Circuits.Circuit σ n 1), S c = (((Circuits.Circuit.encCircuit encOp 1) c).length + 1) ^ b) ∧ ∀ (C : ℕ), ∃ (A : ℕ), ∀ (c : (n : ℕ) × Circuits.Circuit σ n 1), c.snd.size ≤ C * c.fst + C → T c ≤ 2 ^ (A * (c.fst + 1) / (Nat.log 2 (c.fst + 2)).sqrt) * (((Circuits.Circuit.encCircuit encOp 1) c).length + 1) ^ e

#Circuit-SAT for linear-size circuits. For every finite Boolean signature σ, one machine computes c.2.satCount I on every circuit c, in polynomial space, and for each size constant C its time on circuits with at most C n + C gates, for n inputs, 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 C; only A depends on C.

De Morgan #Circuit-SAT for linear-size circuits. One machine computes the number of satisfying inputs of every De Morgan circuit, in polynomial space, and for each size constant C its time on circuits with at most C n + C gates, for n inputs, 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 are fixed before C; only A depends on C.