Finding the exact number of satisfying assignments for a Boolean formula—a problem known as model counting or #SAT—is notoriously difficult. While deciding whether a formula has at least one solution is NP-complete, counting all of them is #P-complete. This makes exact counting computationally intractable for large-scale real-world problems, as the solution space grows exponentially with the number of variables.
To bypass this exponential wall, a powerful paradigm has emerged: hashing-based approximate counting. Instead of exhaustively searching the entire state space, this approach uses random parity constraints to slice the solution space into smaller, evenly distributed cells. By counting the solutions within a single, manageable cell using a standard SAT solver, we can extrapolate the total count with rigorous statistical guarantees.
The Intuition: Slicing the Space Uniformly
Imagine a high-dimensional cube representing all $2^n$ possible variable assignments. Scattered hidden within this cube are an unknown number of solutions. If we want to estimate how many solutions exist without checking every single assignment, we need a way to isolate a representative fraction of the space.
This is achieved by adding random XOR (parity) constraints to the formula. A random XOR constraint looks like this:
$$x_1 \oplus x_3 \oplus x_7 = 1$$
For any given assignment of variables, this equation has exactly a 50% chance of being true. Therefore, adding a single random XOR constraint acts as a filter that, in expectation, eliminates exactly half of the remaining assignments.
[ All $2^n$ Assignments ]
│
├─► +1 XOR Constraint ──► Eliminates ~50% of assignments
│
├─► +2 XOR Constraints ──► Eliminates ~75% of assignments
│
└─► +m XOR Constraints ──► Leaves a cell of size $1/2^m$
If we add $m$ independent random XOR constraints, we partition the entire solution space into $2^m$ discrete cells. If these constraints act like an ideal hash function, they will distribute the solutions uniformly across all cells. If we can find a cell that contains a small, easily countable number of solutions, we can simply count the solutions in that single cell and multiply the result by $2^m$ to get an estimate of the total population.
Why XOR Constraints Work as Universal Hashes
The core challenge is ensuring that the solutions are distributed uniformly across the cells, regardless of how clustered or structured they were originally. If our partitioning mechanism is biased, some cells might be completely empty while others are overcrowded, destroying the accuracy of our estimate.
As shown by Gomes et al. in 2006, random XOR constraints function as pairwise-independent hash functions. This means that the probability of any two distinct assignments landing in the same cell is completely independent. In a follow-up work on near-uniform sampling, Gomes et al. demonstrated that this pairwise independence is theoretically sufficient to guarantee that the solution space is pruned without introducing bias.
To achieve even stronger theoretical guarantees, modern approximate counters often employ $k$-wise independent hashing. For instance, Meel et al. utilized 3-wise independent XOR hash functions to ensure that the variance between cell densities remains tightly bounded, allowing for highly accurate scaling.
From Slicing to Counting: The Algorithm
How do we know how many constraints ($m$) to add? If we add too few, the cell will still be too large for a SAT solver to handle. If we add too many, the cell will be empty.
The breakthrough tool ApproxMC, introduced by Meel et al., solves this via an algorithmic framework that treats a standard SAT solver as a modular oracle. The process works as follows:
- Set a Pivot Threshold: Choose a small threshold, $pivot$ (e.g., 30), which represents a number of solutions that a SAT solver can enumerate almost instantly.
- Iteratively Add Constraints: Start adding random XOR constraints one by one. Each constraint halves the remaining solutions.
- Check Satisfiability: After adding $m$ constraints, ask the SAT solver to find up to $pivot + 1$ solutions within that specific cell.
- Scale the Result: If the solver finds a number of solutions less than or equal to $pivot$, the cell is small enough. The total model count is estimated as:
$$\text{Total Count} = \text{Solutions in Cell} \times 2^m$$
If the solver finds more than $pivot$ solutions, the cell is still too crowded, so the algorithm increments $m$ and tries again. By repeating this process across multiple independent trials, the median of the estimates converges tightly to the true count.
Rigorous PAC Guarantees
The beauty of this approach is that it does not just provide a heuristic guess; it delivers a Probably Approximately Correct (PAC) guarantee. A user can specify two parameters:
- $\epsilon$: The tolerance error (how close the estimate is to the true count).
- $\delta$: The confidence parameter (the probability that the estimate falls outside the tolerance error).
By leveraging concentration inequalities (such as the Chernoff and Chebyshev bounds), the framework guarantees that the estimated count $\hat{c}$ and the true count $c$ satisfy:
$$\Pr\left[ \frac{c}{1+\epsilon} \le \hat{c} \le c(1+\epsilon) \right] \ge 1 - \delta$$
As highlighted in a comprehensive review by Meel et al., this bridges a decades-old gap in computer science between algorithms that are provably correct but too slow, and heuristics that are fast but unreliable.
Beyond Discrete SAT: Broadening the Scope
The principle of XOR-based space partitioning has proven incredibly versatile, expanding far beyond basic Boolean formulas:
- Weighted Model Counting: In probabilistic inference, solutions often have weights. Chakraborty et al. introduced WeightMC, which uses hashing to approximate the total weight of a solution space, scaling to problems with tens of thousands of variables by introducing a complexity parameter known as tilt.
- Discrete Integration: Summing a non-negative function over a massive domain can be framed as an optimization problem under parity constraints. Ermon et al. introduced low-density parity constraints to make the added XOR clauses sparser, preventing the SAT solver from getting bogged down by long, dense equations.
- Hybrid Domains: Real-world applications often involve both discrete logic and continuous variables. Belle et al. generalized hashing-based counting to Weighted Model Integration (WMI), allowing practitioners to compute volumes of hybrid spaces with formal tolerance and confidence bounds.
By transforming the intractable task of global counting into a sequence of localized optimization queries, universal hashing has fundamentally shifted the boundaries of what is scalable in automated reasoning.
Key Foundational Work
Model Counting: A New Strategy for Obtaining Good Bounds (2006) — contributed 5 concept elements to this direction.
Near-Uniform Sampling of Combinatorial Spaces Using XOR Constraints (2006) — contributed 3 concept elements to this direction.