Automatic Program Annotation

Nachum DershowitzIJCAI 1977

Abstract

This paper explores the automation of program annotation, specifically the generation of invariants for formal verification. By integrating algorithmic rules for guaranteed relations with heuristic rules for candidate invariants, the proposed framework enables the automatic discovery of variable relationships in Algol-like programs. Implemented in QLISP, the system demonstrates how structured program analysis can reduce the manual burden of software verification.

Introduction

In the 1970s, the increasing complexity of software necessitated formal verification to ensure program correctness. The primary methodology, the "invariant-assertion technique," relies on identifying mathematical relationships between variables that remain constant throughout execution. Historically, these annotations were manually derived—a process both tedious and prone to error. This research addresses the automation of this discovery process for Algol-like programs.

Methodology

The proposed system utilizes a "catalog of annotation rules" implemented in the QLISP programming language. These rules are categorized into two distinct types:

Algorithmic Rules

These rules derive mathematically certain relations based on the program's structure:

  • Assignment Rules: Analyze variable updates (e.g., constant multiplication) to establish global invariants.
  • Control Rules: Examine program flow, such as loops and branches, to create local invariants. For instance, a loop rule might specify that at the start of an iteration, either the initialization condition or the result of the previous iteration must hold.

Heuristic Rules

These rules suggest "candidate" invariants that are likely true but require external verification:

  • Generalization Heuristic: Infers that a property holding for $k$ iterations might hold for all $n$ iterations, particularly in array processing.
  • Top-Down Heuristic: Reasons backward from a program's output specification to determine necessary internal loop conditions.

Key Insights and Ideas

A central contribution of this work is the unification of "top-down" (goal-oriented) and "bottom-up" (code-oriented) approaches to program analysis. By distinguishing between guaranteed algorithmic truths and suggested heuristics, the system provides a robust foundation for automated documentation.

One notable application is the use of specific algebraic rules for multiplication. If a variable is updated solely through multiplication by constants, the system can define the set of all possible values as a closed mathematical set.

Formal representation of an algebraic rule for variable multiplication.

Results and Implementation

The framework was successfully implemented in QLISP, demonstrating the computational feasibility of automatic documentation for structured programs. Key results include:

  • Formal Framework: A rigorous set of deduction rules for both global and local invariants.
  • Improved Accuracy: The unified approach often surpassed earlier methods by providing more precise bounds on variable ranges.

Limitations and Future Work

While the system significantly advances automated annotation, it is not fully autonomous. Heuristic rules generate candidates that require a separate verifier for confirmation. Furthermore, the current rule catalog is tailored to imperative, Algol-like code. Extending these techniques to modern paradigms, such as concurrent or functional programming, remains a subject for future research.

Summary updated

BibTeX
@inproceedings{dershowitz1977automatic,
  author = {Nachum Dershowitz},
  title = {{Automatic Program Annotation}},
  booktitle = {International Joint Conference on Artificial Intelligence},
  year = {1977},
}
Figure