Certified Knowledge Compilation with Application to Formally Verified Model Counting

Randal E. Bryant, Wojciech Nawrocki, Jeremy Avigad, Marijn J. H. Heule

Model counting (#SAT) is a fundamental problem in computer science with applications ranging from artificial intelligence and security to statistical sampling. Unlike the standard Boolean satisfiability (SAT) problem, which asks if a solution exists, model counting requires determining the exact number of satisfying assignments for a given formula. To handle the computational complexity of this task, researchers employ "knowledge compilers" to transform formulas in Conjunctive Normal Form (CNF) into structured representations, such as decision-DNNFs, where counting becomes mathematically tractable.

However, these compilers are highly optimized, complex software systems. While modern SAT solvers provide proofs of unsatisfiability that can be independently verified, knowledge compilers have traditionally lacked such guarantees. A bug in a compiler can lead to an incorrect count without any indication of failure. This paper addresses this gap by introducing the first formally verified, end-to-end toolchain for model counting.

The CPOG Framework

The authors propose a new approach centered on Partitioned-Operation Graphs (POGs) and the Certified POG (CPOG) framework. POGs serve as a universal, generalized format for representing the outputs of various knowledge compilers. The CPOG framework utilizes a proof format based on extended resolution and reverse unit propagation (RUP)—techniques well-established in the SAT solving community.

To certify a compilation, the framework must prove logical equivalence between the input CNF and the resulting POG. This involves demonstrating both forward implication (the CNF implies the POG) and reverse implication (the POG implies the CNF). By establishing this equivalence, the toolchain ensures that the model count derived from the graph is identical to the count of the original formula.

Scaling and Proof Generation

A significant challenge in verifying knowledge compilation is the sheer size of the resulting graphs. Knowledge compilers achieve efficiency through aggressive subgraph reuse (clause caching). If a verification tool does not account for this reuse, the proof size can explode exponentially. The authors address this by implementing a "lemma" system: proofs for shared nodes are generated once and reused throughout the graph, mirroring the compiler's internal optimizations.

The framework employs a hybrid proof generation strategy to balance efficiency and flexibility:

  • Monolithic Method: For smaller subgraphs, a SAT solver proves equivalence in a single step. This approach is agnostic to the compiler's specific optimization techniques, making the toolchain robust against various preprocessing tricks.
  • Structural Method: For larger graphs, the tool recursively traverses the structure, generating proofs node-by-node to maintain scalability.

Formal Verification in Lean 4

To eliminate the possibility of bugs within the checker itself, the authors implemented the CPOG proof checker and the model counter (a ring evaluator) in the Lean 4 proof assistant. This provides a rigorous, machine-checked mathematical guarantee of soundness.

One of the critical insights driving this work was the discovery of flaws in previous verification frameworks. For instance, the authors found that the CD4 framework could be "spoofed"; a buggy compiler could potentially trick the checker into accepting an incorrect count by manipulating specific clause types. By using Lean 4, the authors ensure their checker is not susceptible to such logical vulnerabilities. Despite the overhead typically associated with verified software, the Lean 4 implementation is highly efficient, running only 3.5 times slower than an unverified C prototype.

Experimental Results

The toolchain was evaluated using 180 benchmark problems from the 2022 unweighted and weighted model counting competitions. These benchmarks included CNF files ranging from 250 to over 2.7 million clauses, representing a realistic and challenging set of modern problems.

Using the state-of-the-art D4 compiler, 123 problems were successfully compiled within a 4,000-second limit. The CPOG toolchain successfully generated and verified proofs for 111 of these instances. While the median verification time was 12.5 times the compilation time, this overhead is considered manageable given the high level of assurance provided. Furthermore, the generated proof files remained reasonably sized, with a median ratio of 2.29x relative to the compiled graph's defining clauses.

Conclusion and Future Directions

This work represents a major step toward trustworthy model counting. While the current implementation primarily supports outputs from the D4 compiler, future work aims to extend the toolchain to support arbitrary POGs, enabling the verification of other formats like Sentential Decision Diagrams (SDDs). Additionally, the authors plan to generalize the framework to support semiring evaluation, which would allow for the certified computation of a wider range of Boolean formula properties beyond simple counting.

Summary updated

BibTeX
@article{bryant2025certified,
  author = {Randal E. Bryant and Wojciech Nawrocki and Jeremy Avigad and Marijn J. H. Heule},
  title = {{Certified Knowledge Compilation with Application to Formally Verified Model Counting}},
  journal = {J. Artif. Intell. Res.},
  year = {2025},
  doi = {10.1613/jair.1.15958},
}
Figure