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

Inferring LISP Programs From Examples

David E. Shaw, William R. Swartout, C. Cordell GreenIJCAI 1975

Introduction

In the field of automatic programming, a primary objective is to bridge the gap between human intent and executable code. While formal specifications are often as difficult to write as the code itself, providing examples is a natural and intuitive way for humans to communicate logic. This paper, originating from Stanford’s AI Lab in 1975, introduces EXAMPLE, a system designed to synthesize recursive LISP programs from a single input-output pair. By leveraging the structural regularities of list processing, EXAMPLE addresses the "inductive inference" problem—generalizing a universal recursive procedure from a specific instance.

The Challenge of Plausible Synthesis

A central difficulty in program synthesis from examples is the "implausible synthesis" problem. Given an input like (A B C) and an output (C B A), a naive system might simply generate a sequence of CAR and CDR operations that work only for lists of length three. To be truly useful, a system must find a plausible generalization—a recursive algorithm that functions correctly regardless of input length. EXAMPLE achieves this by prioritizing recursive structures over literal re-mappings, ensuring the synthesized code reflects the underlying logic of the transformation.

The Synthesis Pipeline

The EXAMPLE system operates through a structured pipeline that progressively increases in complexity until a solution is found.

1. Non-recursive Synthesis

The system first attempts to construct the output using basic LISP constructors like CONS and LIST without recursion. To prevent overfitting, the system employs heuristic guardrails that forbid decomposing the input into individual atoms unless no other path is available. This ensures that if a simple reordering exists, it is found; if not, the system moves to recursive analysis.

2. Recursive Decomposition: Head and Recurrate

If non-recursive methods fail, EXAMPLE attempts to decompose the output into two segments: a head (the portion produced by the current recursive step) and a recurrate (the portion produced by subsequent recursive calls). This decomposition is the core of the system’s intelligence. It uses a template-matching procedure to identify patterns across groups of elements, determining how elements change (e.g., identifying successors) to find the optimal split point.

3. Subgoal Generation and Auxiliary Functions

Once a head is identified, generating the code for that head becomes a new synthesis sub-problem. If the head itself requires a complex transformation, EXAMPLE can recursively invoke its synthesis engine to create auxiliary functions. This allows the system to solve multi-layered problems, such as finding all combinations of elements or interleaving lists, by breaking them into manageable functional units.

4. Conjoining and Termination

Finally, the system determines how to combine the head and the recursive result—typically using CONS or APPEND. It then selects a termination condition, which in this implementation is generally a NULL check on the input list, to complete the recursive definition.

Heuristic Insights

The success of EXAMPLE relies on several key heuristic strategies:

  • Scanning Direction: The system decides whether to process the output list forward or backward based on where input elements appear. This choice fundamentally dictates the recursive structure of the resulting code.
  • Head Distinguishers: To narrow the search space, the system identifies "head distinguishers"—specific atoms that appear in the head but not in the recurrate. These atoms help the system determine which parts of the input should be passed to sub-functions.
  • Interactive Refinement: EXAMPLE is designed to be semi-interactive. If the system makes a faulty conjecture regarding the segmentation of the output, it can query the user. A negative response triggers a revised search for a different recursive pattern.

Evaluation and Results

EXAMPLE was evaluated on a suite of classic LISP list-processing tasks, demonstrating a remarkable ability to generalize from a single example. Key successes include:

  • List Reversal: Correctly synthesizing REVERSE and REVDBL (for nested lists).
  • Interleaving and Selection: Successfully generating programs for SHUFFLE (interleaving two lists) and ALTERNATE (extracting every other element).
  • Complex Combinatorics: In tasks like COMB2 (finding combinations of two elements), the system correctly identified the need for and synthesized the necessary auxiliary functions.

Limitations and Future Directions

Despite its innovative approach to inductive inference, the 1975 EXAMPLE system has notable limitations. It lacks the ability to perform arithmetic or numerical comparisons, meaning it cannot synthesize functions like SORT or SUM. Furthermore, its termination logic is restricted to NULL tests, and its reliance on atom propagation means it struggles when the relationship between input and output atoms is obscured.

The authors suggest that future work should include formal studies on how users naturally provide examples, which would further refine the heuristics used for automatic programming. Nevertheless, EXAMPLE remains a foundational step in showing that high-level recursive logic can be inferred from minimal data by exploiting the inherent structure of the problem domain.

Summary updated

BibTeX
@inproceedings{shaw1975inferring,
  author = {David E. Shaw and William R. Swartout and C. Cordell Green},
  title = {{Inferring LISP Programs From Examples}},
  booktitle = {International Joint Conference on Artificial Intelligence},
  year = {1975},
}
Figure