Introduction
Synthesizing logic programs from examples—a paradigm known as Programming-by-Example (PBE)—offers a powerful interface for non-experts to generate complex relational queries and rules. Datalog, a declarative logic programming language, is a primary target for such synthesis due to its widespread use in data analytics and software verification. However, the search space for Datalog programs is discrete and combinatorial, making the synthesis of programs involving recursion or complex joins an NP-hard challenge.
Traditional approaches rely on exhaustive search or SAT solvers, which often struggle with scalability and recursion. This paper introduces DIFFLOG, a framework that transforms this discrete challenge into a continuous optimization problem through numerical relaxation, allowing logic programs to be "trained" much like neural networks.
Methodology: Numerical Relaxation
The core innovation of DIFFLOG is the extension of Datalog into the continuous domain. Instead of a binary choice where a rule is either included or excluded, every candidate rule is assigned a real-valued weight $w \in [0, 1]$.
The Viterbi Semiring
To maintain computational efficiency, DIFFLOG employs the Viterbi semiring for inference. In this framework, the "truth value" of a conclusion is the product of the weights of the rules used to derive it. If a tuple can be derived in multiple ways, DIFFLOG takes the maximum value among all possible derivations. Unlike standard probabilistic logic, which is #P-complete, Viterbi-based inference remains polynomial-time, enabling efficient automatic differentiation.
Hybrid Optimization
The optimization landscape for logic programs is highly non-convex. To navigate this, DIFFLOG uses a two-pronged hybrid strategy:
- Newton’s Method: A gradient-based algorithm for fast local convergence.
- MCMC (Simulated Annealing): Periodic random jumps to help the solver escape local minima and saddle points.
By tracking "provenance"—the mapping of which rules contribute to which output—the system calculates exactly how changing a rule's weight affects the final error, allowing for effective gradient descent.
Evaluation and Results
DIFFLOG was evaluated on a suite of 34 benchmarks across domains such as knowledge discovery (e.g., family trees), program analysis (e.g., pointer analysis), and relational queries. The system demonstrated a significant performance advantage over the previous state-of-the-art tool, ALPS.
Key results include:
- Superior Performance: DIFFLOG outperformed ALPS on 19 out of 20 non-trivial benchmarks.
- Massive Speedups: In program analysis tasks, DIFFLOG was often orders of magnitude faster. For example, on the
modrefbenchmark, DIFFLOG found a solution in just 1 second, while ALPS required over 47 minutes. - Optimization Robustness: The hybrid approach proved essential; Newton's method alone frequently stalled in local minima, whereas the combined approach successfully synthesized programs for nearly all benchmarks with minimal timeouts.
Conclusion
By bridging the gap between discrete logic and continuous calculus, DIFFLOG provides a scalable and efficient path for Datalog synthesis. While challenges remain in handling the most complex relational queries, the use of numerical relaxation and the Viterbi semiring represents a major step forward in the field of differentiable logic programming.
Summary updated