On Knowledge Compilation for Two-Variable First-Order Logic

Qiaolan Meng, Juhua Pu, Hongting Niu, Yuyi Wang, Yuanhong Wang, Ondrej Kuzelka

TL;DR

This paper explores knowledge compilation for the two-variable fragment of first-order logic ($\text{FO}^2$). It proves a fundamental negative result—that compact, polynomial-size compilation is impossible in the worst case—but counters this with a novel, symmetry-aware two-stage compiler. By branching on high-level logical types rather than individual ground atoms, this new compiler significantly outperforms standard grounding-based propositional pipelines in both circuit size and compilation speed.

What Problem Does This Paper Address?

Knowledge compilation (KC) is a powerful paradigm in automated reasoning. It works by transforming complex logical theories into structured circuit representations—like Deterministic Decomposable Negation Normal Form (d-DNNF) or Ordered Binary Decision Diagrams (OBDDs)—that guarantee efficient, polynomial-time execution for downstream tasks like model counting, conditioning, and sampling.

However, when dealing with relational data described in first-order logic (FOL), standard practice requires "grounding" the formula into a massive propositional theory before compiling it. This grounding step is a brute-force process that destroys the rich relational symmetries and structural regularities inherent in the first-order description.

The authors tackle a fundamental question: Can we compile the propositional groundings of the two-variable fragment of first-order logic ($\text{FO}^2$) efficiently and compactly with respect to the domain size $n$?

Methods

The paper approaches the problem from both a theoretical and an algorithmic perspective.

1. Theoretical Hardness

First, the authors establish a lower bound. They prove that polynomial-size compilation is impossible in general by demonstrating that an $\text{FO}^2$ sentence representing permutation-like structures requires a DNNF circuit of exponential size ($2^{\Omega(n)}$).

2. The Two-Stage Type-Based Compiler

To achieve practical efficiency despite this worst-case hardness, the authors design a specialized two-stage compiler that operates on sentences transformed into Scott Normal Form. Instead of standard Davis-Putnam-Logemann-Loveland (DPLL) style branching on individual ground atoms, the compiler branches on unary and binary types (maximally consistent sets of literals):

  • Stage I (Unary Type Assignment): The compiler processes domain elements sequentially, branching on the valid unary types they can realize.
  • Stage II (Binary Type Assignment): Given the unary assignments, the compiler processes pairs of elements in lexicographic order, branching on valid binary types.

This block-branching structure naturally induces a structured variable ordering, as illustrated in the decision tree fragment below:

Decision structure used in Stage I when branching on unary types of an element.

3. Advanced Optimizations

  • Extendability Checks: To avoid wasting time on dead-end paths, the compiler uses a clever characterization of $\text{FO}^2$ model configurations to check whether a partial type assignment can be extended to a full model, pruning invalid branches early.
  • Subcircuit Caching and Merging: The authors introduce a context-abstraction technique. If two different partial assignments leave behind equivalent future constraints (measured by existential witness obligations and type compatibilities), the compiler reuses the already compiled subcircuit rather than recomputing it.

Datasets

The authors evaluated their compiler against state-of-the-art propositional d-DNNF compilers (Bella, d4, and c2d) using several synthetic relational benchmark families:

  • $\Gamma_{RB}$ & $\Gamma_E$: Formulations for 2-colored graphs and graphs without isolated vertices.
  • $\Gamma_P$: Permutation-like structures (the hard case from the theoretical proof).
  • $\Gamma_D$: Dominating sets.
  • ui-bj family: A parametric benchmark family representing complex structural constraints with symmetric, mutually exclusive binary predicates, along with several structural variants (u4-b2-ad, u4-b2-so, etc.).

Key Insights and Ideas

  • The Power of Types: Branching on types fixes an entire block of literals associated with an element or pair at once. This drastically reduces the search space compared to atom-by-atom branching.
  • Symmetry-Preserving Caching: By abstracting the compilation context into a "satisfaction state" matrix, the compiler can recognize structural equivalence across seemingly different branches, enabling massive subcircuit reuse.
  • Bridging the First-Order/Propositional Divide: The paper successfully positions itself between lifted inference (which reasons purely at the first-order level but struggles with arbitrary evidence) and propositional compilation (which handles arbitrary evidence but loses first-order structure).

Key Results

The type-based compiler consistently outperformed standard grounding-based baselines in both circuit size and compilation time across most benchmarks:

  • Massive Reductions in Circuit Size: On the graphs without isolated vertices benchmark ($\Gamma_E$) at domain size 15, standard compilers produced circuits that were up to 86x larger than the proposed method.
  • Substantial Speedups: For the same $\Gamma_E$ benchmark, the baseline compilers took up to 312x longer to complete the compilation.
  • The Independence Exception: The only exceptions occurred on benchmarks like $\Gamma_P$ and u4-b2-fo, where binary atoms are essentially unconstrained and independent. Because the proposed compiler operates strictly at the type/block level, it currently misses fine-grained propositional independence that standard compilers can exploit.

Limitations and Future Work

  • Coarse-Grained Independence: The current implementation cannot exploit independent subproblems if they occur within the same type block, leading to sub-optimal performance on highly unconstrained formulas.
  • Rigid Branching Order: The strict ordering (unary types before binary types) is essential for the efficient extendability checks but prevents the compiler from exploring more flexible variable orderings.
  • Scaling Beyond Two Variables: Extending this methodology to $\text{FO}^3$ (three-variable logic) is highly non-trivial because pairwise type compatibility is no longer sufficient to capture constraints. The authors suggest exploring restricted extensions of $\text{FO}^2$ (like adding tree or linear order axioms) as a more feasible next step.

Summary updated

BibTeX
@inproceedings{meng2026knowledge,
  author = {Qiaolan Meng and Juhua Pu and Hongting Niu and Yuyi Wang and Yuanhong Wang and Ondrej Kuzelka},
  title = {{On Knowledge Compilation for Two-Variable First-Order Logic}},
  booktitle = {SAT},
  year = {2026},
  doi = {10.4230/lipics.sat.2026.26},
}
Figure