A Knowledge-Based System for Automatic Program Construction

David R. Barstow

Introduction

Presented at a landmark 1977 conference, David Barstow’s work on PECOS represents a foundational moment in the history of automatic programming. The system was designed to bridge the significant gap between high-level "what-to-do" specifications and the low-level "how-to-do-it" code required for execution. By codifying programming expertise into a machine-readable format, PECOS demonstrated that the transition from abstract algorithm to concrete implementation could be treated as a systematic search through a space of design decisions.

The Problem of Automatic Programming

In the late 1970s, the field of automatic programming faced a critical dilemma. Existing systems tended to fall into two extremes: they were either too general, relying on theorem-proving techniques that struggled with computational complexity, or too narrow, mapping abstract concepts directly to machine code without any architectural flexibility.

Barstow argued that the missing link was explicit programming knowledge. Human programmers do not leap directly from an idea to a finished program; instead, they navigate a series of design decisions, such as choosing between a linked list or an array. PECOS was built to automate this "middle layer" of expertise, allowing for the construction of varied and efficient implementations of symbolic algorithms.

Methodology: Gradual Refinement

The core mechanism of PECOS is a process known as gradual refinement. Rather than attempting a single-step translation, the system iteratively transforms an abstract description into a more concrete one by applying a library of programming rules.

The process of gradual refinement from abstract description to concrete program.

This process begins with an original abstract description and moves through several intermediate stages. At each stage, the system applies rules from its knowledge base to refine the current description. This continues until a concrete description—a functional program—is produced. This approach allows the system to explore a "refinement tree" where different branches represent different implementation choices.

The Role of the Knowledge Base

PECOS relies on a Knowledge Base containing approximately 200–300 hand-codified rules. These rules are categorized into three primary types:

  • Refinement Rules: These transform one concept into a more concrete version. For example, a rule might refine a generic "collection" into a specific "linked list."
  • Property Rules: These attach specific constraints or decisions to a node, such as specifying that a list should be stored in increasing order.
  • Query Rules: These allow the system to inspect the current state of the program to determine if a specific refinement is applicable or valid.

An example of a starting point for this process is a high-level membership test specification:

An example of an initial abstract specification for a membership test.

From this simple abstract query, PECOS can generate a dozen different implementations using various data structures like hash tables, arrays, or linked lists. To manage the potential explosion of the search tree, PECOS utilizes task-directed control and works alongside a companion system called LIBRA. While PECOS identifies what is possible, LIBRA acts as an "Efficiency Expert," using cost estimation to select the most efficient path through the refinement tree.

Key Insights and Results

One of the most significant contributions of the PECOS project was the conceptualization of programming as a science. By codifying programming facts and relationships, Barstow moved the discipline away from an intuitive "art" toward a structured methodology.

Key insights from the project include:

  • Intermediate Abstractions: The power of the system lies in its intermediate levels. By understanding concepts like "Sequential Collection" or "Stored Collection" rather than just jumping to "LISP List," the system can share knowledge across many different implementation types.
  • Delaying Choice Points: PECOS postpones specific implementation decisions as long as possible. This strategy results in "skinny" trees at the top and "bushy" trees at the bottom, which significantly reduces the total number of rule applications required.
  • Complexity and Scaling: The system successfully synthesized complex programs, such as an "inverted correspondence" (a database index). From a half-page specification, PECOS could generate roughly 100 lines of INTERLISP code. The author noted that the refinement process is roughly linear, requiring approximately two rule applications for every basic unit of memory (CONS cell) in the final program.

Limitations and Future Directions

Despite its successes, PECOS had notable limitations. It was primarily focused on symbolic computation; expanding it to numerical analysis would require a massive new library of rules. Additionally, the system struggled with specifications longer than a single page due to the time and space constraints of 1970s hardware. Some complex concepts, such as merging loops over the same set, remained difficult to express in the rule-based formalism. Finally, while the system was "automatic," it still required a human to provide the initial specification and resolve high-level ambiguities that the planning phase could not handle.

Summary updated

BibTeX
@inproceedings{barstow1977knowledge,
  author = {David R. Barstow},
  title = {{A Knowledge-Based System for Automatic Program Construction}},
  booktitle = {International Joint Conference on Artificial Intelligence},
  year = {1977},
}
Figure