The Automatic Synthesis of Systems of Recursive Programs

Zohar Manna, Richard J. Waldinger

Introduction

In their foundational 1977 paper, Zohar Manna and Richard Waldinger introduced SYNSYS, a system designed to bridge the gap between "what" a program should do (mathematical specifications) and "how" it should do it (executable code). This work represents a landmark in the fields of formal methods and artificial intelligence, presenting a deductive approach to program synthesis that transforms high-level specifications into recursive LISP programs.

Addressing the "Software Crisis"

In the late 1970s, the "software crisis" made the idea of automatically generating provably correct code highly attractive. However, most synthesis systems of the era were limited to generating simple, single-function programs. Manna and Waldinger tackled two main challenges:

  1. The Abstraction Gap: Turning non-computable mathematical statements (e.g., "find the maximum element of a set") into a sequence of primitive, executable instructions.
  2. Decomposition: Recognizing when a sub-task is distinct enough to warrant its own auxiliary function and ensuring these generated helpers are correct and guaranteed to terminate.

The SYNSYS Methodology

The authors treated program synthesis as a deductive process—a series of mathematical transformations.

Transformation Rules and Goal-Directed Synthesis

SYNSYS utilizes a library of rules representing both domain knowledge (e.g., "any integer divides zero") and programming logic (e.g., conditional if-then-else constructs). The process is goal-directed, starting with the output specification and repeatedly applying rules to simplify the goal until only primitive LISP constructs remain.

Recursion and the Folding Rule

A breakthrough of the system is its ability to introduce recursion via the Folding Rule. If a subgoal matches the original top-level goal, the system realizes it can solve that part of the problem by calling itself. This recursive call is only permitted if the system can prove it moves closer to a base case.

Auxiliary Function Formation

If a subgoal is complex but does not match the top-level goal, SYNSYS can decide to create a new auxiliary function. It derives new input/output specifications for this helper and synthesizes it using the same recursive process. This allows for the creation of interconnected systems of programs, such as the Cartesian product generator which requires nested iterations.

Formal Verification and Termination

To ensure the resulting programs do not loop indefinitely, the system attempts to find a "well-founded ordering"—a mathematical proof of termination—for every recursive call it introduces. This ensures that the program is not only logically correct but also computationally sound.

Key Insights and Implementation

SYNSYS was implemented using QLISP, leveraging pattern-directed function invocation and backtracking. This allowed the system to explore different transformation paths, discarding those that led to logical dead ends.

The paper reinforces the idea that programming is equivalent to theorem proving: if a transformation can be proven, the resulting code is "correct by construction." Additionally, the system performs automatic case analysis; when a transformation rule has a logical condition, SYNSYS automatically generates a conditional branch in the code to handle all cases.

Results and Benchmarks

The paper demonstrated the automatic synthesis of several classic algorithms:

  • The Euclidean Algorithm: SYNSYS correctly identified the need for a recursive call to gcd(rem(y, x), x) and proved termination using the properties of the remainder function.
  • Cartesian Product System: The system successfully decomposed the task of multiplying two sets into a main function and an auxiliary function (cart2), a significant step forward in synthesizing multi-function systems.

Limitations and Future Work

Despite its success, SYNSYS faced several hurdles:

  • Functional Purity: The system only produced "pure" LISP and could not handle side effects or state modifications.
  • Generalization: It occasionally failed to see that a specific problem was a version of a broader problem it already knew how to solve.
  • Search Space: As the rule library grew, the number of possible transformations became massive, leading to performance issues.

Manna and Waldinger's work remains a cornerstone of automated programming, illustrating the power of deductive logic in software engineering.

Summary updated

BibTeX
@inproceedings{manna1977automatic,
  author = {Zohar Manna and Richard J. Waldinger},
  title = {{The Automatic Synthesis of Systems of Recursive Programs}},
  booktitle = {International Joint Conference on Artificial Intelligence},
  year = {1977},
}
Figure