Counting and Sampling Models in First-Order Logic

Ondrej Kuzelka

Introduction

In the field of logic and artificial intelligence, we often encounter the challenge of determining how many ways a logical statement can be true—a task known as Model Counting—or selecting one of those ways at random, known as Sampling. While these tasks are straightforward for simple constraints, they become computationally explosive when applied to complex relational structures like permutations, trees, or social networks.

This paper provides a high-level overview of recent breakthroughs in Weighted First-Order Model Counting (WFOMC) and Sampling (WFOMS). It explores the identification of "tractable" fragments of logic that allow researchers to perform these operations in polynomial time relative to the number of elements (the domain size), bypassing the exponential time usually required by traditional propositional methods.

The Problem: The Scalability of Relational Reasoning

In Statistical Relational Learning (SRL), logic is used to describe relationships while probability handles uncertainty. However, the core bottleneck is that counting models is generally #P-complete, meaning it is computationally extremely difficult. As the number of objects ($n$) in a system grows, the number of possible relationships between them grows exponentially.

To address this, researchers focus on Domain Liftability. An algorithm is considered domain-liftable if its complexity is polynomial in the domain size ($n$) for a fixed logical formula. Achieving domain liftability is the "gold standard" for high-level probabilistic reasoning, as it allows systems to scale to large populations without hitting a computational wall.

Methods and Tractable Fragments

The evolution of "lifted" inference techniques has centered on identifying specific subsets of first-order logic where counting remains efficient:

  • WFOMC (Weighted First-Order Model Counting): This framework assigns weights to different predicates, allowing it to represent complex probabilistic models like Markov Logic Networks.
  • $FO^2$ and $C^2$: The paper highlights that while general first-order logic is intractable, the two-variable fragment ($FO^2$) is domain-liftable. Adding "counting quantifiers" (e.g., "there exist exactly $k$ elements") results in the $C^2$ fragment, which is significantly more expressive yet remains tractable.
  • Axiomatic Extensions: Recent advancements have shown that we can impose structural requirements—such as forcing a relationship to form a Tree, a Linear Order, or a Directed Acyclic Graph (DAG)—and still maintain polynomial-time computation.
  • WFOMS (Weighted First-Order Model Sampling): Beyond counting, the paper discusses techniques for exact sampling. Unlike traditional Markov Chain Monte Carlo (MCMC) methods, which provide approximations, WFOMS aims to provide exact samples from the distribution defined by the logic.

Key Insights: The Complexity Cliff and the Sampling Gap

One of the most striking observations in this field is the "Complexity Cliff." There is a sharp boundary in tractability: while $FO^2$ is domain-liftable, adding just one more variable ($FO^3$) generally makes the problem intractable. This makes $C^2$ a powerful "Universal Calculator"; instead of deriving a unique combinatorial formula for every specific problem (like derangements or $k$-regular graphs), researchers can describe the structure in $C^2$ logic and utilize a general-purpose WFOMC solver to find the answer.

Furthermore, the paper notes a surprising Sampling Gap. In standard computer science, being able to count efficiently often implies being able to sample efficiently. However, in the "lifted" setting, these reductions do not always translate easily while maintaining polynomial scaling relative to domain size. Closing this theoretical gap remains a major research goal.

Results and Practical Applications

Though primarily a survey, the paper references several significant outcomes of these logical methods:

  • Combinatorial Discovery: These methods have been used to automatically generate and contribute new sequences to the Online Encyclopedia of Integer Sequences (OEIS).
  • Performance: Current WFOMS algorithms have been shown to outperform state-of-the-art propositional (SAT-based) samplers on first-order problems because they exploit the inherent symmetries of the domain rather than breaking them down into individual propositions.
  • Machine Learning: WFOMC serves as the engine for maximum-likelihood learning in Markov Logic Networks, enabling them to be trained efficiently on large-scale relational data.

Limitations and Future Directions

Despite these breakthroughs, several challenges remain:

  1. Polynomial Degree: While "polynomial time" is a theoretical victory, a complexity of $n^{10}$ is still too slow for many real-world applications. Future work must focus on reducing the degree of these polynomials.
  2. Practical Tooling: Many of these methods exist as academic prototypes. There is a pressing need to integrate these algorithms into standard programming libraries (like NumPy) to make them accessible to the broader AI community.
  3. The $FO^3$ Frontier: Finding ways to handle even limited instances of three-variable logic without triggering exponential growth remains one of the most significant open problems in the field.

By bridging the gap between formal logic and probabilistic inference, WFOMC and WFOMS provide a path toward AI systems that can reason about complex, large-scale worlds with both mathematical rigor and computational efficiency.

Summary updated

BibTeX
@inproceedings{kuzelka2023counting,
  author = {Ondrej Kuzelka},
  title = {{Counting and Sampling Models in First-Order Logic}},
  booktitle = {International Joint Conference on Artificial Intelligence},
  year = {2023},
  doi = {10.24963/ijcai.2023/801},
}
Figure