Top-Down Synthesis for Library Learning

Matthew Bowers, Theo X. Olausson, Lionel Wong, Gabriel Grand, Joshua B. Tenenbaum, Kevin Ellis, Armando Solar-LezamaProc. ACM Program. Lang 2022 · DOI

Abstract

This paper introduces corpus-guided top-down synthesis as a mechanism for synthesizing library functions that capture common functionality from a corpus of programs in a domain specific language (DSL). The algorithm builds abstractions directly from initial DSL primitives, using syntactic pattern matching of intermediate abstractions to intelligently prune the search space and guide the algorithm towards abstractions that maximally capture shared structures in the corpus. We present an implementation of the approach in a tool called Stitch and evaluate it against the state-of-the-art deductive library learning algorithm from DreamCoder. Our evaluation shows that Stitch is 3-4 orders of magnitude faster and uses 2 orders of magnitude less memory while maintaining comparable or better library quality (as measured by compressivity). We also demonstrate Stitch's scalability on corpora containing hundreds of complex programs that are intractable with prior deductive approaches and show empirically that it is robust to terminating the search procedure early -- further allowing it to scale to challenging datasets by means of early stopping.

Introduction

In software engineering, complexity is managed through abstractions—functions that encapsulate recurring patterns to reduce redundancy. In the field of program synthesis, "library learning" automates this discovery process by identifying reusable abstractions within a corpus of programs written in a Domain Specific Language (DSL).

Historically, the state-of-the-art approach (exemplified by the DreamCoder system) relied on a "deductive" method: refactoring every program in a corpus using rewrite rules to find commonalities. However, this approach suffers from an exponential search space that scales poorly with program length and corpus size, often leading to memory exhaustion and prohibitive runtimes on complex datasets.

The Stitch Algorithm

To overcome these limitations, we introduce Corpus-Guided Top-Down Synthesis (CTS), implemented in a tool called Stitch. Rather than refactoring existing programs bottom-up, Stitch synthesizes new abstraction candidates from the top down, starting from the DSL primitives themselves.

Overview of the Stitch library learning pipeline, showing the transition from an initial DSL to a compressed corpus using top-down synthesis.

Methodology

  1. Top-Down Search: The algorithm begins with a "hole" (??) and iteratively populates it with DSL primitives (e.g., +, map, line). This allows the system to propose structures and then verify their presence in the corpus, which is computationally more efficient than deriving them through permutation.
  2. Lambda-Aware Unification: Stitch employs a specialized unification algorithm to determine if a candidate abstraction fits a program in the corpus. This process handles variable bindings (using de Bruijn indices) even when abstractions are partial.
  3. Aggressive Pruning: The core efficiency of Stitch stems from a branch-and-bound algorithm utilizing two key strategies:
  4. Upper Bound Pruning: By observing that refining a partial abstraction can only ever match a subset of its current locations, Stitch calculates the maximum possible compression gain for a branch. If this bound is lower than the current best, the branch is discarded.
  5. Strict Dominance Pruning: Abstractions that are mathematically guaranteed to be inferior (e.g., those with redundant arguments) are discarded immediately.
The top-down search process iteratively fills 'holes' (??) with DSL primitives to find common abstractions.

Evaluation and Results

Stitch was evaluated on standard DreamCoder benchmarks (Lists, Text, LOGO, etc.) and a new, large-scale dataset featuring complex CAD-like drawings and architectural planning programs.

Performance and Scalability

  • Speed: Stitch is 3 to 4 orders of magnitude faster than previous deductive methods. Tasks that previously required hours are now completed in seconds.
  • Memory Efficiency: Stitch uses 2 orders of magnitude less memory, typically staying under 1GB of RAM, whereas prior methods often crashed even with 256GB.
  • Anytime Property: Because Stitch maintains a "best-so-far" candidate, it can be stopped early to provide useful results, a feature that significantly enhances its utility for real-time or resource-constrained applications.

Quality of Abstractions

Despite the massive speedup, the quality of the learned libraries—measured by their ability to compress the corpus—remains comparable to or better than the deductive baseline. Stitch successfully processed datasets like "nuts and bolts" and "castles," where DreamCoder failed to find any abstractions within reasonable time and memory limits.

Conclusion

Stitch represents a paradigm shift in library learning by demonstrating that top-down synthesis, guided by corpus-driven pruning, is vastly more scalable than traditional deductive refactoring. While currently focused on tree-structured programs and syntactic patterns, future work aims to extend these techniques to semantic equivalences (e.g., commutativity) and more complex data structures like dataflow graphs.

Summary updated

BibTeX
@article{bowers2022top,
  author = {Matthew Bowers and Theo X. Olausson and Lionel Wong and Gabriel Grand and Joshua B. Tenenbaum and Kevin Ellis and Armando Solar-Lezama},
  title = {{Top-Down Synthesis for Library Learning}},
  journal = {Proc. ACM Program. Lang.},
  year = {2022},
  doi = {10.1145/3571234},
}
Figure