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

Improved Tree Search for Automatic Program Synthesis

Aran Carmon, Lior WolfarXiv 2023 · DOI

Abstract

Automatic program synthesis aims to generate executable code from high-level specifications, such as input-output examples. However, the vast search space of possible programs often makes this task computationally intractable. This paper presents a novel approach that enhances program synthesis by combining a specialized variant of Monte Carlo Tree Search (MCTS) with dataset pruning and history-aware encoding. By prioritizing environment states over tree topology and simplifying training data, the proposed method achieves a significant performance leap, increasing accuracy from 50.2% to 85.2% on the DeepCoder benchmark.

Introduction: The Challenge of Program Synthesis

The "holy grail" of software engineering is the ability for computers to automatically write code based on a few examples. For instance, given an input list and a desired output, a system should synthesize the underlying logic.

Example of a program synthesis task where a sequence of operations (Filter, Map, Sort, Reverse) transforms an input list into the desired output.

The primary obstacle is the combinatorial explosion of the search space. Even within restricted domain-specific languages (DSLs), the number of possible command sequences is astronomical. While Reinforcement Learning (RL) has been explored, standard Maximum Likelihood Estimation (MLE)—training a model to predict the next token—remains a strong baseline. However, MLE struggles with ambiguity: multiple distinct programs can often produce the same output, creating "noise" during training.

Methodology

The researchers introduced three core innovations to streamline the synthesis process:

1. MCTS with Shared Counts

Traditional MCTS tracks visits based on nodes in a search tree. In this work, the authors propose a variant that focuses on the environment state. If two different code sequences lead to the exact same memory or variable state, they share the same visit count. This "Shared Counts" mechanism prevents the search from redundantly exploring paths that lead to identical outcomes, effectively collapsing the search tree into a more manageable graph of states.

2. Dataset Pruning

To address the issue of multiple correct solutions, the authors preprocessed the training data. Using a pre-trained model, they identified the shortest possible program for every example in the dataset. By replacing verbose or redundant ground-truth programs with concise versions, the model receives a much clearer and more consistent signal during the MLE training phase.

Distribution of program lengths in the training datasets before and after pruning. Pruning significantly shifts the distribution toward shorter, more efficient programs.

3. Encoding Program History

Standard synthesis models often lack context regarding their previous actions. To remedy this, the authors integrated an LSTM-based encoder that tracks the sequence of commands already executed. This "history" provides the model with the necessary context to make more informed decisions about the next line of code.

Evaluation and Results

The methods were evaluated on two DSLs: DeepCoder (list manipulation) and Karel (robot navigation in a 2D grid).

The results on DeepCoder were particularly striking. The baseline CAB search achieved 50.2% accuracy. Implementing MCTS with Shared Counts raised this to 76.0%. When combined with dataset pruning and history encoding, the full method reached 85.2% accuracy.

On the Karel benchmark, the combination of pruning and history encoding (MCTS+) consistently outperformed standard search methods. However, the "Shared Counts" optimization was less impactful here, as the complexity of the 2D grid states meant that reaching identical states via different paths was relatively rare.

Key Insights

  • State over Topology: In structured domains like programming, the state of the environment (memory/variables) is a more useful metric for search than the path taken to reach it.
  • Pruning as Regularization: Dataset pruning acts as a powerful regularizer. For DeepCoder, shortening 82% of the longest programs removed significant noise, allowing the model to learn more efficiently.
  • Search Efficiency: The study reinforces that for structured tasks, a well-optimized search algorithm paired with a strong MLE-trained prior can outperform complex RL schemes.

Conclusion and Future Work

This research demonstrates that significant gains in program synthesis can be achieved by optimizing the search process and cleaning the training signal. While "Shared Counts" showed limitations in complex environments like Karel, future work could explore more flexible definitions of "equivalent states." These improved search techniques also hold promise for generating high-quality trajectories to further refine models through reinforcement learning.

Summary updated

BibTeX
@misc{carmon2023improved,
  author = {Aran Carmon and Lior Wolf},
  title = {{Improved Tree Search for Automatic Program Synthesis}},
  year = {2023},
  eprint = {2303.07166},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2303.07166},
}
Figure