Abstract
The formal verification of computer programs using the Floyd-Hoare method traditionally requires the manual specification of inductive assertions—mathematical invariants that hold true across loop iterations. This paper, originally presented at IJCAI 1973, introduces a heuristic framework for the automated generation of these assertions. By integrating top-down analysis of entry/exit conditions with bottom-up algebraic analysis of loop bodies, the proposed system can discover complex invariants in algorithmic benchmarks, bridging a critical gap in automated reasoning.
Introduction
In the early 1970s, while "verifiers" could check the validity of program proofs, the discovery of the necessary inductive assertions remained a significant bottleneck. Finding these assertions typically required deep human intuition and a thorough understanding of program performance. This work addresses the challenge by replacing human "understanding" with a set of automated heuristic rules designed to "cut" loops and attach invariants systematically.
Methodology
The authors propose a dual-strategy approach to assertion generation:
Top-Down Approach
This method analyzes the predicates known at the loop's entrance (entry rules) and the conditions required at its exit (exit rules). It effectively "pushes" known information into the loop to determine what properties must be maintained.
Bottom-Up Approach
The more innovative contribution is the bottom-up analysis, which examines the statements within the loop body to find invariants "naturally." The system utilizes an operator table to track variable transformations over $n$ iterations. For instance, if a variable $y$ is incremented by $k$ in each step, its value after $n$ steps is represented as $y^{(n)} = y^{(0)} + n \cdot k$. By treating the iteration counter $n$ as a symbolic variable and algebraically eliminating it from equations involving multiple variables, the system discovers invariant relationships that hold regardless of the number of iterations.
Array Handling and Quantifiers
To handle arrays, the framework introduces rules for quantification ($\forall$ and $\exists$). It uses "one-pass" assertions to describe the effect of a single iteration on an array segment and generalizes this effect to the entire loop structure.
Benchmarks and Evaluation
The heuristics were evaluated on several classic algorithmic benchmarks, ranging from simple arithmetic to complex hardware simulations.
The system successfully derived assertions for:
- Integer Square Root: A fundamental single-loop test case.
- Real Division: Division performed within a specified tolerance.
- Hardware Integer Division: A complex simulation involving bit-shifting and subtraction.
- Hoare’s Partition Algorithm: A non-trivial component of Quicksort requiring complex quantified predicates.
Key Insights
- Invariants as Search Targets: The search for inductive assertions is fundamentally a search for mathematical invariants.
- Symbolic Iteration: Treating the number of loop executions as a variable allows the application of difference equations, transforming a logic problem into an algebraic one.
- Hybridization: While top-down rules suffice for simple examples, non-trivial programs require a combination of both strategies, with bottom-up techniques often proving more powerful.
Conclusion and Future Work
The paper demonstrates that a heuristic system can "discover" necessary assertions for complex programs without prior knowledge of the program's intended function. However, limitations remain regarding the ordering of heuristic rules and the complexity of assertions for nested loops and arrays. The authors suggest that future systems might benefit from a "man-machine interaction" model, where the computer queries the programmer to resolve problematic relations, and point toward proving total correctness as a next step.
Summary updated