TL;DR
The paper introduces Cofola, a novel declarative programming language designed to automatically solve complex combinatorial counting problems. By compiling high-level problem descriptions into Weighted First-Order Model Counting (WFOMC) instances, Cofola preserves domain-level symmetries, allowing it to solve textbook and synthetic math problems in polynomial time relative to domain size.
What Problem Does This Paper Address?
Combinatorial counting problems—asking "how many ways can $X$ be configured under constraints $C$?"—are fundamental to AI, statistics, and discrete mathematics. Currently, solving them forces a choice between two unsatisfactory extremes:
- Closed-form symbolic derivations: Highly concise but brittle; a tiny change in the problem statement requires completely recalculating the math from scratch.
- Generic computer solvers (#SAT or Constraint Satisfaction): These require "propositionalizing" the problem, meaning they label every individual entity and count combinations one by one. This destroys exchangeability (the inherent symmetry where swapping two identical items doesn't change the count), causing solvers to choke as the number of items grows.
Prior attempts to bridge this gap were limited to single-stage configurations and relied on highly specialized, custom solvers. The authors tackle this by creating a uniform, end-to-end pipeline that handles complex, multi-stage counting problems while keeping computations tractable.
Methods
The authors present Cofola (COmbinatorial counting LAnguage with First-Order logic), which natively supports seven core combinatorial object types: sets, bags (multisets), tuples, sequences, circles, partitions, and compositions.
Unlike previous tools, Cofola allows users to model multi-stage problems using a Directed Acyclic Graph (DAG) of dependencies (e.g., "choose a starting team, then select a goalie from that team, then partition the remaining players").
The core innovation is Cofola's three-phase compilation pipeline:
- Preprocessing: Performs entity analysis and uses Linear Programming (LP) to infer maximum size bounds and optimize the problem structure.
- Decomposition: Uses Shannon expansion and independent-subproblem splitting to break complex constraints into simpler, parallelizable components.
- Symmetry-Preserving Encoding: Translates the simplified problem into a WFOMC instance. Crucially, it groups indistinguishable entities in bags, uses lexicographic ordering to break symmetries in unordered partitions, and applies order axioms for sequences and circles. This ensures the backend solver can reason about groups of identical objects simultaneously ("lifted inference").
Datasets
The authors evaluated Cofola using three distinct benchmarks:
- Real-World Benchmark: 408 combinatorial counting problems extracted from the "counting and statistics" category of the standard MATH dataset. After filtering out problems requiring visual aids or basic inclusion-exclusion, 272 problems were successfully encoded in Cofola.
- Growing-Domains Benchmark: 100 instances across 5 parameterized problem families, scaling the number of base entities ($n$) from 5 up to 100 to test how well the system handles large scales.
- Synthetic Benchmark: 100 randomly generated Cofola programs designed to stress-test the pipeline by mixing various operators and constraints in non-standard ways.
Key Insights and Ideas
- Preserving Symmetries is Essential: The "aha moment" of this architecture is that you don't need a bespoke counting solver if you can translate high-level combinatorial structures into first-order logic without breaking domain symmetries.
- Leveraging Advanced Logic Backends: By targeting WFOMC, Cofola inherits decades of engineering and theoretical guarantees from off-the-shelf first-order logic solvers, effectively decoupling language modeling from solver mechanics.
- Handling Bags vs. Sets: For sets, symmetry breaking relies on tracking part sizes. For bags (multisets), the authors realized they must use a full "multiplicity vector" (or signature) sorted lexicographically to prevent overcounting without destroying tractability.
Key Results
Cofola, backed by lifted WFOMC solvers, dramatically outperformed existing state-of-the-art modeling and solving pipelines:
- Real-World Performance: On the 272 MATH dataset problems, Cofola solved 271 out of 272 instances within a 100-second timeout. In comparison, the closest prior framework (CoLa-CoSo) solved only 145, while standard Answer Set Programming (Clingo) and Constraint Modeling (Conjure) solved 118 and 123, respectively.
- Domain Scaling: As the number of entities scaled to $n=100$, Cofola’s runtime remained nearly flat or grew modestly. Meanwhile, propositional solvers (like CNF-Ganak) scaled exponentially, timing out rapidly as $n$ increased because their underlying graph sizes exploded.
- Robustness: Cofola successfully solved 99 out of 100 complex synthetic benchmarks, proving its stability across arbitrary combinations of sets, sequences, and partitions.
Solver Coverage Comparison (Out of 272 Real Problems)
======================================================
Cofola-WFOMC | ███████████████████████████████████ 271
CNF-Ganak | █████████████████████████████████▍ 269
CoLa-CoSo | ██████████████████ 145
ESSENCE-Conjure | █████████████▌ 123
ASP-Clingo | ████████████▊ 118
Limitations and Future Work
Despite its strengths, Cofola cannot yet encode or solve about 30% of the real-world MATH dataset due to a few distinct boundaries:
- Entity-Level Attributes: Cofola treats entities as opaque names. It cannot handle problems where individual items carry intrinsic values that undergo arithmetic (e.g., "coins of thicknesses 1.55mm and 1.95mm summing to exactly 14mm"). Integrating a counting-SMT solver is a proposed fix.
- Advanced Geometric & Structural Constraints: Problems involving two-dimensional grid placements (like non-attacking rooks on a chessboard), palindromes, complex rotation groups (e.g., coloring the vertices of a 3D cube), or fixed-offset circular relationships ("sitting opposite to each other") currently sit outside Cofola's grammar and push against the tractability frontier of modern WFOMC.
Summary updated