Compilation and Fast Model Counting beyond CNF

Alexis de Colnet, Stefan Szeider, Tianwei Zhang, Yufei Qiao, Yifan Zhu, Zhonghong Ou, Meina Song

Abstract

Model counting (#SAT)—the task of determining the number of satisfying assignments for a Boolean formula—is a central problem in artificial intelligence with broad applications in probabilistic reasoning and verification. While efficient algorithms exist for formulas in Conjunctive Normal Form (CNF) with low treewidth, many real-world problems involve complex constraints like XORs or cardinality constraints that are difficult to encode into CNF without destroying structural simplicity. This paper addresses this gap by introducing a framework for directly compiling and counting systems of "well-behaved" non-CNF constraints. By leveraging the concept of $w$-slim functions and incidence treewidth, the authors provide Fixed-Parameter Tractable (FPT) algorithms for both knowledge compilation and direct model counting, demonstrating that many global constraints can be handled efficiently by treating them as finite state machines.

Introduction

The efficiency of model counting often relies on Knowledge Compilation, where a formula is transformed into a tractable representation like d-DNNF (deterministic Decomposable Negation Normal Form). For CNF formulas, the complexity of this process is typically exponential in the formula's treewidth. However, real-world constraints often extend beyond simple clauses. Parity (XOR) or threshold constraints are common, and their standard CNF encodings often lead to a significant increase in treewidth, making traditional solvers inefficient. This research explores whether we can maintain efficiency by treating these complex constraints as first-class citizens rather than converting them to CNF.

The w-slim Framework

The authors identify a crucial property of many global constraints: they can be viewed as finite state machines. A constraint is defined as $w$-slim if, after assigning values to any subset of its variables, the number of possible "residual" functions is bounded by $w$. This "slimness" parameter captures the internal complexity of the constraint. For example, an XOR constraint or a cardinality constraint ("at least $k$ variables are true") has a small number of internal states regardless of the total number of variables. The core insight is that if $w$ is small, the constraint is "slim" enough to be handled efficiently.

Structural Complexity and Treewidth

To handle systems of these constraints, the paper focuses on the incidence graph $G_F$, which represents the relationships between variables and the constraints they participate in. The incidence treewidth ($k$) measures how "tree-like" this graph is.

A tree decomposition of the incidence graph $G_F$, which is used to guide the dynamic programming algorithm for model counting.

The authors prove that for a system of $w$-slim constraints, model counting can be performed using dynamic programming over a "nice" tree decomposition of the incidence graph. By using Commutative State Transition Systems (CSTS) to track the state of each constraint as the algorithm traverses the tree, the complexity is kept within FPT bounds relative to the treewidth.

Compilation to Tractable Circuits

Beyond direct counting, the paper establishes that systems of $w$-slim constraints can be compiled into d-DNNF (specifically, SDNNF) circuits. This is achieved by showing that such systems can be encoded into CNF using a modified Tseitin encoding that preserves a low treewidth, allowing the use of existing compilation pipelines.

An SDNNF circuit representation for a constraint $c_2$, demonstrating the target format for knowledge compilation.

Theorem 1 demonstrates that this compilation can be done in $2^{O(k)} \cdot \text{poly}(|F|)$ time. This result generalizes previous CNF-only compilation results to a much broader class of Boolean functions, provided they exhibit the $w$-slim property.

Key Results and Conclusion

The paper provides two main algorithmic contributions:

  • Theorem 1 (Compilation): Systems of $w$-slim constraints can be compiled into d-DNNF circuits in $2^{O(k)} \cdot \text{poly}(|F|)$ time, where $k$ is the incidence treewidth.
  • Theorem 17 (Faster Counting): If only the model count is required, a direct DP approach on the tree decomposition achieves a running time of $O(w^{2k} \cdot |G_F|)$.

The authors also prove a lower bound: the parameter $w$ must appear in the exponent of the running time, meaning that the "slimness" of constraints is a fundamental limit on efficiency. This work provides a theoretical foundation for more robust model counters that can handle the diverse constraints found in modern AI applications without the overhead of inefficient CNF translations.

Summary updated

BibTeX
@inproceedings{colnet2024compilation,
  author = {Alexis de Colnet and Stefan Szeider and Tianwei Zhang and Yufei Qiao and Yifan Zhu and Zhonghong Ou and Meina Song},
  title = {{Compilation and Fast Model Counting beyond CNF}},
  booktitle = {International Joint Conference on Artificial Intelligence},
  year = {2024},
}
Figure