Towards Practical First-Order Model Counting

Ananth K. Kidambi, Guramrit Singh, Paulius Dilkas, Kuldeep S. Meel

TL;DR

Crane2 is a fully automated compiler for First-Order Model Counting (FOMC) that turns logical formulas into closed-form, recursive C++ programs equipped with memoization and arbitrary-precision arithmetic. By automatically discovering and smoothing recursion base cases, Crane2 eliminates the manual intervention required by its predecessor, scaling to domain sizes over 500,000 times larger than existing state-of-the-art tools.

What Problem Does This Paper Address?

First-order model counting (FOMC)—and its weighted variant (WFOMC)—asks: given a first-order logic sentence and a finite domain, how many valid interpretations (models) satisfy it? This task is fundamental to lifted probabilistic inference, statistical relational AI, and reasoning over probabilistic databases.

Traditional model counters struggle because grounding a logical formula over large domains causes an exponential blow-up in propositional variables. While lifted algorithms exploit symmetries to achieve polynomial data complexity relative to domain size, existing systems run into severe bottlenecks:

  • Ground-breaking tools like ForcLift are limited by finite-precision integers ($< 2^{31}$) and restricted syntactic rules.
  • Modern solvers like FastWFOMC are typically confined to two-variable logics ($C^2$ or $\text{UFO}^2 + \text{CC}$) and struggle on specific relation structures.
  • A recent framework named Crane showed that knowledge compilation could express model counts as recursive mathematical functions, but it left recursion incomplete: it could not compute base cases automatically and required users to evaluate equations by hand.

Methods

Crane2 introduces an end-to-end pipeline that transforms an input first-order logic sentence $\phi$ into an executable, high-performance C++ binary:

  1. Automatic Base Case Synthesis (CompileWithBaseCases & FindBaseCases): Crane2 recursively inspects the function definitions generated by Crane. It identifies which argument combinations represent terminal boundaries (e.g., domain sizes hitting zero or specific constants) and proves that the recursion depth is bounded by the number of logical domains.
  2. Assumption Propagation & Novel Smoothing (Propagate): When fixing a domain size to zero, logical clauses can become vacuously true, accidentally causing relations to vanish from the model count. Crane2 introduces a first-order smoothing step: when a clause is partially satisfied by an empty domain, it inserts tautological clauses (e.g., $P(y, z) \lor \neg P(y, z)$) to preserve the free degrees of freedom of the remaining predicates.
  3. Algebraic Simplification (Simplify): Sums over bounded ranges (e.g., $\sum_{m=0}^n [a \le m \le b] f(m)$) and trivial identities ($0 \cdot x = 0$, $x^0 = 1$) are simplified symbolically before code emission.
  4. C++ Code Generation: The final equations are translated into standalone C++ code using the GNU Multiple Precision (GMP) library for arbitrary-precision arithmetic and custom per-function hash tables for memoization.

Datasets

The authors evaluate Crane2 against standard benchmarks from the lifted inference literature, checking count correctness against the On-Line Encyclopedia of Integer Sequences (OEIS):

  • Bijections: Counting bijective relations between two sets (involving 3 variables and equality in standard FO; expressed with counting/cardinality quantifiers in $C^2$/$\text{UFO}^2 + \text{CC}$).
  • Friends & Smokers: A standard Markov logic network benchmark modeling homophily and disease transmission across a single domain with 3 predicates and 2 variables.
  • Functions: Counting valid functions from domain $\Gamma$ to $\Delta$ (a 3-variable formula in FO).

Key Insights and Ideas

  • Treating counting as program compilation, not just circuit evaluation: Instead of evaluating circuits per domain size at query time, compiling sentences into native recursive C++ code decouples logical reasoning from numerical evaluation.
  • First-order smoothing for empty domains: In propositional model counting, smoothing ensures all variables appear in every branch of a d-DNNF circuit. Crane2 adapts this principle to first-order domains: fixing $|\Delta| = 0$ must not artificially drop predicates operating on disjoint domains.
  • Topological recursion guarantees: Because Crane constructs directed acyclic compilation graphs, Crane2 proves that synthesized recursive functions admit a strict topological ordering with no mutual recursion, guaranteeing termination on any non-negative integer input.

Key Results

Crane2 (evaluated in greedy and BFS search variants) was compared against ForcLift and FastWFOMC:

  • Functions Benchmark: ForcLift stopped at domain size $2^7 = 128$ due to 32-bit integer overflow. FastWFOMC timed out at $2^6 = 64$. Crane2 scaled all the way to $2^{26} = 67,108,864$—over $500,000\times$ larger than ForcLift and $1,000,000\times$ larger than FastWFOMC.
  • Bijections Benchmark: ForcLift failed entirely to compile the sentence. FastWFOMC accommodated domain sizes up to $64$, whereas Crane2-BFS scaled to $4,096$ ($64\times$ larger).
  • Friends & Smokers: ForcLift overflowed at domain size $16$, FastWFOMC reached $1,024$, while Crane2 scaled to $8,192$.
  • Compilation Overhead: Synthesizing the C++ code took only 2–8 seconds across all benchmarks.

Limitations and Future Work

  • Theoretical Completeness: While Crane2 succeeds empirically on sentences beyond two-variable logic, formal completeness proofs for specific fragments (e.g., $C^2$ with tree or linear order axioms) remain open.
  • Fine-Grained Complexity: The exact computational complexity classes of the synthesized recurrences have not yet been fully characterized.
  • Weighted Arithmetic: Although the paper notes that floating-point support for arbitrary-precision WFOMC is straightforward, the current implementation primarily targets exact integer counts (FOMC).

Summary updated

Abstract

First-order model counting (FOMC) is the problem of counting the number of models of a sentence in first-order logic. Since lifted inference techniques rely on reductions to variants of FOMC, the design of scalable methods for FOMC has attracted attention from both theoreticians and practitioners over the past decade. Recently, a new approach based on first-order knowledge compilation was proposed. This approach, called Crane, instead of simply providing the final count, generates definitions of (possibly recursive) functions that can be evaluated with different arguments to compute the model count for any domain size. However, this approach is not fully automated, as it requires manual evaluation of the constructed functions. The primary contribution of this work is a fully automated compilation algorithm, called Crane2, which transforms the function definitions into C++ code equipped with arbitrary-precision arithmetic. These additions allow the new FOMC algorithm to scale to domain sizes over 500,000 times larger than the current state of the art, as demonstrated through experimental results.
BibTeX
@inproceedings{kidambi2025towards,
  author = {Ananth K. Kidambi and Guramrit Singh and Paulius Dilkas and Kuldeep S. Meel},
  title = {{Towards Practical First-Order Model Counting}},
  booktitle = {SAT},
  year = {2025},
  url = {https://openreview.net/forum?id=cr1tKx66Fp},
}

Loading related content...

Figure