Automatic Program Synthesis in Second-Order Logic

Jared L. Darlington

Abstract

This paper presents a pioneering approach to automatic program synthesis by framing programming as a theorem-proving task within second-order logic. By extending standard resolution techniques with a specialized higher-order unification algorithm, the proposed system can derive executable SNOBOL-4 programs directly from formal specifications. The methodology is validated through the successful synthesis of programs for factorial calculation and iterative integer division.

Introduction

In the early 1970s, the field of automatic programming aimed to bridge the conceptual gap between a formal specification (the "what") and the resulting executable code (the "how"). While first-order logic proved effective for verifying mathematical properties, it struggled to represent the dynamic state changes and iterative structures inherent in computer programs. This paper addresses these challenges by formalizing program features—such as assignment and loops—as logical axioms within a higher-order framework, allowing a theorem prover to manipulate functions and predicates that evolve over time.

Methodology

The core of the system is a resolution-based theorem prover enhanced with several specialized components:

Second-Order Logic and Higher-Order Unification

Unlike standard first-order systems, this framework allows variables to represent predicates or functions. This capability is essential for implementing Hoare-style logic, where one must reason about assertions that hold true across program state transitions. To facilitate this, the author implemented a restricted higher-order unification algorithm capable of handling lambda expressions.

Example of a complex state tuple T' incorporating lambda expressions for substitution during the synthesis process.

This algorithm allows the system to "solve" for missing program steps by matching logical expressions through lambda-normalization, effectively handling variable substitution—the fundamental mechanism of the assignment command.

Hoare-based Axioms and Search Strategy

The system utilizes axioms derived from C.A.R. Hoare’s logic for assignment and iteration. For instance, the "axiom of assignment" describes how a state changes when a value is assigned to a variable. To navigate the resulting search space, the prover employs S-L Resolution (Linear resolution with selection function), a depth-first search strategy. Additionally, an algebraic simplifier applies ad hoc rules to reduce mathematical expressions (e.g., simplifying 0 + x to x), ensuring the generated code remains clean.

Evaluation and Results

The system was evaluated on two classic algorithmic benchmarks: the calculation of the factorial function ($K = N!$) and iterative integer division (finding quotient $J$ and remainder $K$ for $H = J \cdot N + K$).

Performance and Output

Running on an IBM 360/50 mainframe, the synthesis process for these tasks typically took between three and five minutes. The system produced line-by-line SNOBOL-4 code, including labels and GOTO statements for loops. A post-processing routine called ANSPRINT was used to polish the final output for readability.

Discussion

The fundamental insight of this work is that a program can be viewed as a side effect of a constructive proof. If a prover can demonstrate that a state satisfying the output requirements is reachable from the input state, the steps of that proof correspond directly to program instructions.

Limitations and Future Work

Despite its success, the system faces several limitations:

  • Incompleteness: The unification algorithm is optimized for second-order logic and is not complete for higher orders.
  • Search Space: The search space for complex programs can expand rapidly; while S-L resolution keeps simple tasks tractable, more complex logic would require more sophisticated heuristics.
  • Simplification: The algebraic simplifier was built specifically for the test cases; a more generalized "algebraic amplifier" would be necessary for a production-grade tool.

Conclusion

By moving beyond first-order logic, this research demonstrated that complex program structures like loops and assignments could be synthesized automatically. This work laid early groundwork for the "programs as proofs" paradigm, showing that formal logic could indeed serve as a foundation for automated software engineering.

Summary updated

BibTeX
@inproceedings{darlington1973automatic,
  author = {Jared L. Darlington},
  title = {{Automatic Program Synthesis in Second-Order Logic}},
  booktitle = {International Joint Conference on Artificial Intelligence},
  year = {1973},
}
Figure