Synthesizing Datalog Programs using Numerical Relaxation

Xujie Si, Mukund Raghothaman, Kihong Heo, Mayur Naik

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.

The Programming-by-Example (PBE) task for Datalog: given input tuples (EDB) and desired output tuples (IDB), the goal is to synthesize the underlying logic rules.

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:

  1. Newton’s Method: A gradient-based algorithm for fast local convergence.
  2. 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.

Performance comparison of running times across various benchmarks. DIFFLOG demonstrates significant speedups over the state-of-the-art ALPS solver in the majority of non-trivial tasks.

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 modref benchmark, 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

BibTeX
@inproceedings{si2019synthesizing,
  author = {Xujie Si and Mukund Raghothaman and Kihong Heo and Mayur Naik},
  title = {{Synthesizing Datalog Programs using Numerical Relaxation}},
  booktitle = {International Joint Conference on Artificial Intelligence},
  year = {2019},
  doi = {10.24963/ijcai.2019/847},
}
Figure