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

Program Synthesis Through Reinforcement Learning Guided Tree Search

Riley Simmons-Edler, Anders Miltner, H. Sebastian SeungarXiv 2018

Abstract

Program Synthesis is the task of generating a program from a provided specification. Traditionally, this has been treated as a search problem by the programming languages (PL) community and more recently as a supervised learning problem by the machine learning community. Here, we propose a third approach, representing the task of synthesizing a given program as a Markov decision process solvable via reinforcement learning (RL). From observations about the states of partial programs, we attempt to find a program that is optimal over a provided reward metric on pairs of programs and states. We instantiate this approach on a subset of the RISC-V assembly language operating on floating point numbers, and as an optimization inspired by search-based techniques from the PL community, we combine RL with a priority search tree. We evaluate this instantiation and demonstrate the effectiveness of our combined method compared to a variety of baselines, including a pure RL ablation and a state of the art Markov chain Monte Carlo search method on this task.

Introduction

Program synthesis—the goal of enabling computers to write their own code—has historically been divided into two distinct methodologies. The Programming Languages (PL) community typically treats synthesis as a search problem, utilizing brute-force enumeration or sophisticated pruning techniques. While reliable, these methods often struggle to scale as program length and complexity increase. Conversely, the Machine Learning (ML) community often frames synthesis as a supervised learning task, training models on extensive datasets of specification-to-code pairs. However, these models frequently struggle to generalize to novel languages and require massive amounts of labeled data.

This paper introduces Reinforcement Learning Guided Tree Search (RLGTS), a framework that bridges these two worlds. By treating program synthesis as a Markov Decision Process (MDP), the system can learn to navigate vast discrete search spaces without requiring a pre-existing dataset of correct programs.

Methodology

The core innovation of RLGTS is the representation of program synthesis as an MDP where the State is a combination of the current program's memory state and the partial program itself, and the Action involves appending a new instruction to the program. The system is driven by a Reward function that balances correctness (proximity of output to target) with efficiency (minimizing program length).

Overview of the RLGTS framework showing the flow from I/O examples to the final program via a priority tree search guided by a Q-function.

RLGTS integrates two primary components:

  1. Deep RL Agent: A dueling double Q-network utilizing LSTMs to process partial programs and fully connected layers for memory states. It learns to predict the expected future reward (Q-value) of adding specific lines of code.
  2. Prioritized Search Tree: To avoid the local minima that often plague pure RL agents, the system maintains a search tree. The RL agent's Q-values serve as a priority guide, directing the tree toward the most promising branches for exploration.

This hybrid approach leverages the intelligence of a learned model while maintaining the exhaustive reliability of a search algorithm. The method was evaluated on a subset of the RISC-V assembly language, focusing on floating-point arithmetic across tasks with search spaces ranging from $2.1 \times 10^6$ to $4.0 \times 10^{31}$ possible programs.

Results and Key Insights

Experimental results demonstrate that RLGTS significantly outperforms traditional baselines. The system solved up to 100% more programs than a pure RL agent and 800% more than simple enumerative search on synthetic benchmarks.

Performance comparison of RLGTS against baselines across varying program lengths.

A critical finding is the existence of a "Program Gradient." The authors show that the reward landscape for assembly synthesis is not entirely flat; partial programs often provide a signal of being "closer" to the goal, which the RL agent can exploit. Furthermore, RLGTS proved robust as the action space increased. While Markov Chain Monte Carlo (MCMC) baselines saw performance drop sharply when more than four instructions were available, RLGTS remained effective even with a full 17-instruction set. The system also demonstrated resilience when the target program length was unknown, a common failure point for MCMC methods.

Conclusion

While RLGTS shows great promise, it currently focuses on "straight-line" linear programs without control flow (loops or conditionals). Its success also depends on a reward function that provides incremental signals; in purely binary "all-or-nothing" reward scenarios, the agent may struggle to find an initial foothold. Future work aims to integrate deductive reasoning techniques from the PL community to further prune the search tree, potentially enabling the synthesis of significantly more complex software structures.

Summary updated

BibTeX
@misc{simmonsedler2018program,
  author = {Riley Simmons-Edler and Anders Miltner and H. Sebastian Seung},
  title = {{Program Synthesis Through Reinforcement Learning Guided Tree Search}},
  year = {2018},
  eprint = {1806.02932},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1806.02932},
}
Figure