Weighted First-Order Model Counting over Ordered Domains

Jan Tóth, Qipeng Kuang, Kuncheng Zou, Václav Kůla, Yuyi Wang, Yuanhong Wang, Ondřej KuželkaarXiv 2026

TL;DR

This paper establishes that Weighted First-Order Model Counting (WFOMC)—a core problem in statistical relational learning—can be solved in polynomial time over domains with a linear order by incorporating the ordering as a logical axiom rather than explicit formulas. The authors map out the exact boundary of tractability, providing efficient dynamic programming algorithms for domains with successor relations, while proving that adding a second distinct linear order pushes the problem into $\mathsf{\#P}_1$-hardness.

What Problem Does This Paper Address?

In statistical relational learning (SRL), researchers combine first-order logic with probabilistic models to reason about complex, interconnected data. A foundational task here is Weighted First-Order Model Counting (WFOMC), which computes the weighted sum of all possible worlds that satisfy a given logical sentence.

To be practically useful, an algorithm's runtime should scale polynomially with the size of the domain (e.g., the number of people in a social network), a property known as domain-liftability. While two-variable logic ($FO^2$) is domain-liftable, three-variable logic ($FO^3$) is notoriously intractable ($\mathsf{\#P}_1$-hard).

This creates a massive roadblock for real-world applications: modeling sequences, time-series data, or queues requires a linear order (a total ordering of elements). Defining a linear order using standard logic inherently requires three variables (to enforce transitivity: $\forall x,y,z : x \le y \wedge y \le z \rightarrow x \le z$). Consequently, standard ordered domains instantly break tractability. The authors set out to bypass this variable bottleneck and determine exactly how much ordering structure can be introduced before inference becomes impossible.

Methods

Instead of forcing the logic to define a linear order explicitly, the authors introduce a linear order axiom directly into the language of $C^2$ (two-variable logic with counting quantifiers). This semantic constraint forces a binary predicate to act as a total order in every valid model without introducing a third variable.

The paper introduces three novel algorithms under a framework called IncrementalWFOMC:

  1. Algorithm 1 (Base Linear Order): Uses dynamic programming to enlarge the domain inductively, element by element, computing partial model counts based on "cell configurations" (how elements realize unary predicates).
  2. Algorithm 2 (Extended Linear Order with Successors): Explicitly defining immediate or $k$-th successors using two variables causes a massive computational blowup. Algorithm 2 tracks the cell assignments of the last $k$ elements natively within the dynamic programming state, handling successor relations implicitly and dramatically reducing overhead.
  3. Algorithm 3 (The Hybrid Setting): Solves a hybrid scenario featuring one full linear order and the immediate successor relation of a second, completely distinct linear order.

To establish the limits of these methods, the authors also present a hardness proof. They reduce a variant of the classic Wang tiling problem to a "grid axiom," demonstrating that evaluating sentences with two full linear orders is strictly $\mathsf{\#P}_1$-hard.

Datasets

The algorithms were evaluated on several synthetic and dataset-derived benchmarks:

  • Combinatorics Math Problems: 28 permutation-counting problems extracted from the "counting_and_statistics" category of the MATH dataset. These were encoded as first-order theories using linear orders and successor relations.
  • Watts-Strogatz Model: A Markov Logic Network (MLN) designed to exactly replicate the structure of Watts-Strogatz random graphs.
  • Synthetic HMMs: Hidden Markov Models with higher-order dependencies to test $k$-th successor performance.
  • OEIS Benchmarks: Problems matched against the On-Line Encyclopedia of Integer Sequences (entries A000670, A000629, and A002464) to verify correctness against known combinatorial sequences (like Hertzsprung’s problem).

Key Insights and Ideas

  • Axioms as a Loophole: The core conceptual breakthrough is that treating structural properties (like totality and transitivity) as background axioms rather than explicit sentences allows researchers to dodge the $FO^3$ variable trap entirely.
  • Implicit vs. Explicit Tracking: When dealing with successors, explicitly writing the constraints in $C^2$ explodes the number of valid logical "cells." By shifting this burden into the dynamic programming state transition (tracking the history of the last $k$ elements), the algorithm keeps the polynomial degree dependent only on the original formula's complexity.
  • The Tractability Frontier: The paper elegantly brackets the frontier of tractability. One linear order is easy; two linear orders are impossible; one linear order plus the immediate successor of another is just barely manageable.

Key Results

  • Exponential Speedups: On the Watts-Strogatz and HMM benchmarks, standard propositional model counters (like GANAK and d4) failed to scale past a domain size of $n=17$ due to combinatorial explosion. In contrast, Algorithm 2 seamlessly scaled to hundreds of domain elements, demonstrating true polynomial scaling.
  • Complexity Bounds: The authors proved that Algorithm 1 runs in $O(n^{p+1})$ time, where $p$ is the number of valid cells. Algorithm 3, handling the hybrid two-order case, scales at $O(n^{p^2+p+1})$, proving that while the hybrid case is domain-liftable, it pays a steep price in its polynomial exponent.

Limitations and Future Work

  • Algorithmic Overhead of the Hybrid Case: While Algorithm 3 is theoretically polynomial, its quadratic exponent ($p^2$) means its practical scaling capabilities diminish rapidly as the logical formula becomes more complex.
  • Unoptimized Implementation: The current evaluation relies on an unoptimized Python implementation. A production-grade, compiled implementation is needed to realize its full potential for real-world SRL tasks.
  • The Unresolved Gap: A theoretical gap remains between one linear order + one successor (tractable) and two full linear orders (intractable). Future work will explore exactly where the intractability barrier drops when moving between a successor relation and a fully-fledged second total order.

Summary updated

BibTeX
@misc{toth2026weighted,
  author = {Jan Tóth and Qipeng Kuang and Kuncheng Zou and Václav Kůla and Yuyi Wang and Yuanhong Wang and Ondřej Kuželka},
  title = {{Weighted First-Order Model Counting over Ordered Domains}},
  year = {2026},
  eprint = {2608.10877},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2608.10877},
}
Figure