Many uses of SAT solving need more than one satisfying assignment, and more than one count. They need to know, across all valid configurations of a system, how often each feature is switched on. They also need to know how often a failure condition holds given some mode of operation. Formally, this is a family of marginal and conditional probabilities under the uniform distribution over the solutions of a formula. The two tools the field offers both fall short. An almost-uniform sampler generates solutions whose probabilities are each within a small factor of uniform. Counting frequencies in its output gives additive error, which is useless for a feature present in one configuration in a million. An approximate model counter estimates the number of solutions to within a guaranteed factor. It handles a rare feature correctly, but costs a full run per query, so asking about every variable of a 100,000-variable instance is out of reach.
We propose one randomized procedure that answers the whole batch with per-query relative-error guarantees. It draws a single chain of random parity (XOR) constraints, in which each constraint cuts the solution set roughly in half. It then answers each query at its own depth in that chain, using incremental SAT calls that add the query literal as an assumption. Common queries are answered from one enumerated cell, which is effectively a sample. Rare queries fall back to shallower cells, which is effectively counting. Every answer comes with a two-sided bound that holds simultaneously for all queries with probability $1-\delta$. The goal is to get close to the cost of one counting run instead of one run per query.
Core Claim
Let $F$ be a formula over variables projected onto a sampling set $S$, and let $\ell_1,\dots,\ell_q$ be query literals or small query formulas. We want $p_j = |R_{F\wedge \ell_j}|/|R_F|$, where $R_G$ denotes the solutions of $G$ projected on $S$. A random matrix-vector pair $(A,b)$ over GF(2) defines nested cells $C_m = \{x : A_{1..m}x = b_{1..m}\}$, where $A_{1..m}$ is the first $m$ rows. Because the family is pairwise independent, any fixed solution set $T$ satisfies
$$\mathbb{E}\,|T\cap C_m| = |T|/2^m,\qquad \mathrm{Var}\,|T\cap C_m| \le |T|/2^m .$$
This single fact carries two uses. First, the rows of one matrix can be read at many depths. Second, the count at depth $m_j$ is reliable for query $j$ whenever $|R_{F\wedge\ell_j}|/2^{m_j}$ exceeds roughly $1/\epsilon^2$. That threshold follows from Chebyshev's inequality on the variance above.
The procedure first runs the counter's depth search once for $F$. It enumerates the cell at the chosen depth and reads off estimates for every query with enough support there. For each remaining rare query, it walks back up the same nested prefix to the depth where $F\wedge\ell_j$ has about a threshold's worth of solutions. It reuses the solver's learned clauses and passes $\ell_j$ as an assumption. Medians over $O(\log(q/\delta))$ independent chains, together with a union bound, give simultaneous $(1+\epsilon)$ bounds on each numerator. Combined with the denominator bound, this gives a $(1+\epsilon)^2$ relative bound on each $p_j$.
The claim to test is empirical as well as theoretical. On industrial instances where exact methods fail, this should cost close to a single counting run plus a logarithmic number of cheap incremental calls per rare query. It should also keep relative error small on the rare queries, which is exactly where sampler frequencies break.
Relation to Prior Work
The mechanism comes from the hashing line. Near-Uniform Sampling of Combinatorial Spaces Using Combinatorial Constraints introduced random parity slicing for sampling. Approximate Model Counting via Universal Hashing turned it into the ApproxMC counter, with a median-of-trials PAC guarantee. Towards Real-Time Approximate Counting (ApproxMC7) cut SAT calls using single-solution cell checks and a galloping depth search. We reuse all of this, but it answers one count per run. Our change is to treat one hash chain as a shared resource across many queries.
UniGen, in Balancing Scalability and Uniformity in SAT Witness Generator, already calls the counter to pick a cell depth and then samples from a cell. That is the closest existing work. However, it outputs witnesses, and it gives no guarantee about the marginals a user later computes from them.
The motivation for relative, per-query guarantees comes from the error-bounds direction. On the Hardness of Approximating Distributions with Tractable Probabilistic Models shows that small global distance says nothing about conditional queries on rare events. Bias Reduction for Sum Estimation proves that estimates from a sampler whose probabilities are within a factor $(1\pm\gamma)$ of uniform carry bias of order $\gamma\mu$. It proposes corrections but leaves practical implementations open. We sidestep both problems by never estimating from sampler output: each answer is a ratio of hashed counts.
In graphical models, Bounds on marginal probability distributions bounds marginals deterministically, and Optimization With Parity Constraints: From Binary Codes to Discrete Integration together with Tight Variational Bounds via Random Projections and I-Projections use parity constraints to bound partition functions. These solve the analogous problem with integer programming and variational solvers that stop at hundreds of variables. We stay with conflict-driven SAT solvers and hard logical constraints, and we target marginals rather than the partition function.
Research Program
The first component is the analysis. We will prove the simultaneous guarantee for prefix-shared chains. The key point is that each query sees a hash distributed exactly as in a fresh ApproxMC run, so correlation across queries does not weaken the union bound.
We will also study whether sharing one chain between numerator and denominator helps beyond saving cost. Both counts are taken in the same cells, so their errors are positively correlated, and the ratio could be tighter than $(1+\epsilon)^2$. We treat this as a hypothesis to measure, not a promise.
We will also handle projection. Queries on variables outside $S$ are sound only when those variables are functionally determined by $S$. Otherwise the query must be added to the projection set, and we will state when that is needed.
The second component is the implementation on CryptoMiniSat's incremental interface. It covers three things: enumeration of the shared cell with literal tallies, assumption-based depth search for each rare query that starts from a depth predicted by the shared-cell tally, and scheduling that orders rare queries to maximize clause reuse.
The third component is certification. The per-query answers inherit the structure of Formally Certified Approximate Model Counting, whose certificate only needs the unsatisfiable calls to be checked. We will measure how much proof-log size grows when many queries share one chain. We will not attempt a full formal verification.
Baselines
The naive reference point draws $N$ witnesses from UniGen and reports empirical frequencies. The error bars add Hoeffding's additive term to the sampler's $(1+\epsilon)$ closeness factor. It will get the same wall-clock budget as our method.
The stronger version of that baseline applies the bias-reducing estimators of Bias Reduction for Sum Estimation to the same samples. We will implement these ourselves, since the paper is purely theoretical and there is no reported result on Lacuna for it on SAT benchmarks. Beating these baselines means achieving bounded relative error on rare queries (marginal below $10^{-3}$), where we expect them to give intervals containing zero, while matching them on common queries at equal time.
The strongest correct competitor is $q+1$ independent ApproxMC7 runs. There is one per numerator plus the denominator, each at failure probability $\delta/(q+1)$, with identical $\epsilon$, solver version, time limit and memory. The most relevant reported figures are that ApproxMC7 solved 1,072 of 2,247 instances in its suite, and that its observed error of 1.59 was well below the guaranteed $\epsilon$ of 13, both from Towards Real-Time Approximate Counting. There is no reported result on Lacuna for batched marginal estimation with ApproxMC. Beating this baseline means a total SAT-call count and wall time several-fold lower at matched empirical error. The crucial case is instances where running $q+1$ separate counts exceeds the time limit while ours finishes.
On compilable instances, exact knowledge compilation (Knowledge Compilation meets Uniform Sampling; the Ace results in Partition Function Estimation: A Quantitative Study) provides ground truth. We will also report it as a competitor wherever it finishes.
Three ablations isolate the key ingredients. The first draws a fresh hash per query, which tests prefix sharing. The second removes incremental solving, which tests clause reuse. The third disables the rare-query fallback, which tests whether counting at shallower depths is what rescues rare queries.
Why not just…?
Why not just draw many UniGen samples and count frequencies? Frequencies give additive error of about $1/\sqrt{N}$ plus a multiplicative bias from the sampler's closeness factor. With a marginal of $10^{-6}$, you need millions of witnesses before a single hit appears. The conditional-trap result in On the Hardness of Approximating Distributions with Tractable Probabilistic Models says global closeness cannot fix this. For common marginals, however, this baseline is a real threat, and our method should roughly match it rather than beat it. The experiments stratify results by marginal size so this will be visible.
Why not just run ApproxMC once per query? It is correct, and it is our main competitor. Its cost grows linearly in $q$ and repeats the depth search and clause learning from scratch each time. If the prefix-sharing ablation turns out as fast as the full method, the contribution shrinks to an engineering detail, and we will report that.
Why not just compile the formula once and read off all marginals exactly? When compilation succeeds, it wins, and we will say so. The study in Partition Function Estimation: A Quantitative Study reports Ace solving 611 of 672 benchmarks within a 32-factor. Our target is the regime compilation does not reach: industrial instances like the 486,193-variable formulas handled by UniGen in Balancing Scalability and Uniformity in SAT Witness Generator. The main results table will be restricted to instances where exact tools time out, and the compilable instances are used only to check correctness.
Proposed Experiments
We evaluate on three sources: the 2,247-instance ApproxMC7 suite from Towards Real-Time Approximate Counting, the Model Counting Competition instances used there and in Fast Converging Anytime Model Counting, and the 50 Barbarik benchmarks from On Quantitative Testing of Samplers. The query set on each instance is every literal in the sampling set, plus 100 random conditional queries built from conjunctions of two literals. The latter deliberately include rare conditioning events.
We report three measures. The first is per-query log relative error against exact values wherever an exact counter finishes, stratified by marginal size in decades. The second is the fraction of queries falling outside the $(1+\epsilon)^2$ band, which the guarantee caps at $\delta$ simultaneously. The third is total SAT calls, wall time, and the number of instances where the full batch finishes within the limit.
Three decisive checks follow. The first is that, on instances with ground truth, the simultaneous coverage rate meets $1-\delta$, including for marginals below $10^{-4}$. The second is that the time ratio against the per-query ApproxMC7 baseline grows with $q$, rather than staying flat. The third is that the prefix-sharing ablation loses most of that gain. If the second or third check fails, the idea reduces to running counts more carefully, and we would drop the sharing claim and report only the rare-query guarantee.
References
- Near-Uniform Sampling of Combinatorial Spaces Using XOR Constraints
- A Scalable Approximate Model Counter
- Towards Real-Time Approximate Counting
- Balancing Scalability and Uniformity in SAT Witness Generator
- On the Hardness of Approximating Distributions with Tractable Probabilistic Models
- Bias Reduction for Sum Estimation
- Bounds on marginal probability distributions
- Optimization With Parity Constraints: From Binary Codes to Discrete Integration
- Tight Variational Bounds via Random Projections and I-Projections
- Formally Certified Approximate Model Counting
- Knowledge Compilation meets Uniform Sampling
- Partition Function Estimation: A Quantitative Study
- Fast Converging Anytime Model Counting
- On Quantitative Testing of Samplers