NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Neural Guided Constraint Logic Programming for Program Synthesis

Lisa Zhang, Gregory Rosenblatt, Ethan Fetaya, Renjie Liao, William E. Byrd, Matthew Might, Raquel Urtasun, Richard S. Zemel

Introduction

This paper introduces a hybrid approach to Program Synthesis by Example (PBE) that combines the precision of symbolic logic with the pattern-recognition power of neural networks. By using a Recurrent Neural Network (RNN) to guide the search process of miniKanren (a constraint logic programming system), the authors significantly improve the efficiency of finding programs and demonstrate a remarkable ability to generalize to much larger programs than those seen during training.

High-level architecture of the neural-guided miniKanren loop.

The Challenge of Program Synthesis

Programming by Example (PBE) is often considered the "holy grail" of end-user programming: a user provides a few input/output pairs (e.g., [1, 2] -> [2, 1]), and the computer automatically synthesizes the code to perform that transformation.

The primary bottleneck in PBE is the exponential search space. Because there are an infinite number of possible programs, searching through them is akin to finding a needle in a haystack. Traditional symbolic methods are highly precise but struggle to scale as programs grow in length. Conversely, recent deep learning approaches attempt to "guess" the program directly, but they frequently fail to handle complex logic or generalize to programs longer than those in their training set.

This paper seeks to bridge that gap. Instead of using neural networks to write the code directly, the authors use them to act as a "scout" that tells the symbolic search engine which paths are most promising.

A Hybrid Approach: miniKanren Meets Neural Networks

The authors integrate a neural guide into miniKanren, a logic programming language that searches for programs by satisfying a set of recursive constraints (called "goals").

Detailed synthesis pipeline showing miniKanren building constraints and the ML agent scoring candidates.
  1. Constraint Representation: Unlike previous models that only look at raw input/output pairs, this model uses miniKanren’s internal state—specifically its constraints—as input. These constraints represent the "sub-problems" the system is currently trying to solve.
  2. RNN-Guided Search: The system uses a bi-directional LSTM to embed these constraints. Each constraint type (like evalo for evaluation or lookupo for variable lookup) has its own learned weights.
  3. Scoring and Selection: The RNN scores candidate "incomplete" programs. The system then performs a discrete choice to expand the highest-scoring candidate. This effectively replaces hard-coded heuristics with a learned intuition for which code snippet is likely to lead to a solution.
  4. Training Techniques: To make the model robust, the authors employed several advanced training strategies:
  5. Curriculum Learning: Starting with very short programs and gradually increasing complexity.
  6. Prioritized Experience Replay: Focusing training on "hard" examples the model previously failed.
  7. Scheduled Sampling: Gradually transitioning from "teacher forcing" (showing the model the right answer) to letting the model explore its own choices.

Experimental Setup and Baselines

The authors evaluated their model on a subset of Lisp, focusing on list manipulation functions like cons, car, and cdr.

  • Test Problems: 100 programmatically generated problems held out from training.
  • Generalization Benchmarks: Three families of programs with increasing complexity:
  • Repeat(N): Repeats a symbol $N$ times.
  • DropLast(N): Removes the last element of an $N$-element list.
  • BringToFront(N): Moves the last element to the front.
  • Comparison: They compared their results against state-of-the-art symbolic synthesis systems, including $\lambda^2$, Escher, and Myth.

Key Insights and Results

  • Symbolic Attention: The authors argue that miniKanren’s constraints act as a "symbolic attention mechanism." By selecting only the portions of the input/output relevant to a specific sub-problem, the constraints simplify the task for the neural network.
  • Internal State is Key: The "aha moment" of this research is that the neural network performs better when it understands the internal logic of the search engine, rather than just looking at the external data.
  • High Success Rate: The RNN-guided search solved 99% of test problems, compared to only 27% for a naive search and 82% for a search using manually designed heuristics.
  • Superior Generalization: Because the system is still fundamentally a symbolic search, the neural guide allows it to solve programs much larger than those in the training set. While the training programs were small (max 22 steps), the model successfully synthesized Repeat(N) for $N > 20$. Competitors like $\lambda^2$ failed at $N=4$ due to memory limits.
  • Efficiency: The model solved complex problems in roughly 11 minutes that caused other systems to time out or crash.

Limitations and Future Directions

While highly effective, the current work is limited to a small subset of Lisp. Expanding this to more complex, real-world Domain Specific Languages (DSLs) is a major next step. Furthermore, while miniKanren is capable of synthesizing recursive programs, the authors noted that learning to guide the synthesis of recursive logic specifically remains a challenge for future research. Finally, some competing systems use type information to prune the search space; this model does not currently leverage types, which could be a powerful addition in future iterations.

Summary updated

BibTeX
@inproceedings{zhang2018neural,
  author = {Lisa Zhang and Gregory Rosenblatt and Ethan Fetaya and Renjie Liao and William E. Byrd and Matthew Might and Raquel Urtasun and Richard S. Zemel},
  title = {{Neural Guided Constraint Logic Programming for Program Synthesis}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2018},
}
Figure