Abstract
Constrained counting, or calculating the number of assignments that satisfy a set of logical constraints, is a fundamental problem in computer science with applications ranging from probabilistic AI to software vulnerability analysis. However, the problem is #P-complete, making exact solutions computationally explosive. This paper introduces STAC (Satisfiability Testing based Approximate Counter), a novel probabilistic algorithm that replaces slow solution enumeration with simple satisfiability (SAT) queries. By leveraging the statistical probability of a formula becoming unsatisfiable under random hashing, STAC achieves a 10x to 100x speedup over state-of-the-art tools while extending support to complex numeric domains like Linear Integer Arithmetic (LIA).
Introduction
Calculating the number of solutions to a logical formula—known as model counting—is essential for quantifying uncertainty and risk in complex systems. Despite its importance, the computational complexity of exact counting limits its practical application to small-scale problems. Current state-of-the-art approximate counters typically rely on universal hashing. These methods randomly partition the search space into smaller "cells" using hash functions and then count the solutions in a single representative cell to estimate the total count.
The primary bottleneck in these "gold standard" approaches is the requirement for an "enumeration oracle." To count solutions in a final cell, the solver must find every individual solution one by one. This process is inherently slow and scales poorly as problems grow in size or complexity, particularly when moving into numeric domains such as bit-vectors or integers.
The STAC Algorithm
STAC (Satisfiability Testing based Approximate Counter) represents a paradigm shift in approximate counting by moving from counting solutions to sampling satisfiability. The algorithm is built upon several core innovations:
The "Unsat" Assumption
Instead of counting how many solutions reside within a cell, STAC analyzes the probability that a cell is completely empty (unsatisfiable). The researchers posit that as the number of hash constraints ($d$) increases, the probability that the formula remains satisfiable relates directly to the total model count ($\#F$). By identifying the threshold where a formula transitions from satisfiable to unsatisfiable under random hashing, the algorithm can infer the total solution space size.
Pure SAT Queries
Unlike previous tools that require repeated solution enumeration, STAC only requires a standard SAT solver to provide a binary "Satisfiable" or "Unsatisfiable" response. This significantly reduces the computational overhead per query, allowing the algorithm to explore the search space much faster than enumeration-based methods.
Dynamic Stopping and Leap-frogging
To optimize performance, STAC employs two key heuristics:
- Leap-frogging: The algorithm uses a heuristic to quickly jump to the relevant "depth" (the number of hash constraints) where the formula is likely to become unsatisfiable, avoiding redundant queries at low depths where solutions are abundant.
- Dynamic Stopping Criterion: Rather than running for a fixed number of iterations, STAC uses binomial confidence intervals to monitor the accuracy of its estimate in real-time. Once the estimate reaches a statistically "tight" bound that meets the user's specified error tolerances ($\epsilon, \delta$), the algorithm terminates.
Extension to Numeric Domains
To handle SMT(LIA) (Linear Integer Arithmetic), the authors developed a method to encode XOR-based hash functions—which are typically bit-level operations—into linear arithmetic. By transforming the modulo operation $(f(x) \pmod 2 = 1)$ into a linear constraint $(f(x) = 2y + 1)$, STAC allows standard SMT solvers to process hashes efficiently within numeric domains.
Experimental Evaluation
The authors evaluated STAC against a broad suite of benchmarks, including Propositional Logic (CNF) and Bit-Vectors (SMT-BV). Benchmarks included grid networks, plan recognition, circuit synthesis, and software analysis problems. STAC was compared against industry standards such as ApproxMC2 (for CNF) and SMTApproxMC (for bit-vectors).
Key Results
- Performance: STAC demonstrated a significant performance advantage, outperforming existing tools by one to two orders of magnitude (10x–100x speedup) on the majority of benchmarks.
- Accuracy: In 100-run trials, the algorithm's estimates fell within the predicted theoretical error bounds approximately 80-90% of the time, validating the empirical "Unsat Assumption."
- Robustness: The number of iterations ($T$) required for a stable estimate remained consistent across diverse problem types, suggesting that the algorithm is not overly sensitive to specific input characteristics.
Discussion and Limitations
While STAC provides a massive leap in efficiency, the authors note a "theoretical gap": the core equation linking unsatisfiability probability to model count is currently an empirical assumption. While it holds up under rigorous testing, a formal mathematical proof for all classes of formulas is still being researched. Additionally, the approach can encounter difficulties with "loose" formulas—those where almost every possible assignment is a solution—though specific test cases show that STAC remains competitive even in these scenarios.
Conclusion
STAC demonstrates that knowing when a space becomes empty is as mathematically informative as counting its contents, but significantly cheaper to compute. By replacing enumeration with satisfiability testing, STAC opens the door for approximate counting in complex domains that were previously computationally unreachable. Future work will focus on extending this logic to non-linear arithmetic and constraints involving strings and arrays.
Summary updated