General Techniques for Automatic Program Optimization and Synthesis Through Theorem Proving

We report on program optimization research within the proofs as programs paradigm. Firstly, we describe program optimization by the transformation of program synthesis proofs (i.e. constructive existence proofs). Synthesis proofs which yield inefficient programs are transformed into analogous proofs which yield more efficient programs. The key to program optimization lies in the transformation of the various induction schemas employed in synthesis proofs. This belief stems from the extensive work of Boyer and Moore concerning the dualities between induction and recursion. A system has been implemented which optimizes simple recursive behaviour by automatically transforming the associated synthesis proof structures (notably, the forms of mathematical induction used to synthesize recursive program constucts). A second approach to program optimization does not concern how target synthesis proofs can be "mapped" from source proofs. Rather, the question is can we devise a means by which these proofs can be automatically constructed. without the use of a source proof (but only the source equational definitions). A promising strategy is to use the "proof planning" approach [Bundy et aI, 199J.b] to theorem proving and to employ meta-variables at the meta-level planning phase which allow the planning to proceed even though certain object-level objects are (partially) unknown (such a strategy being known as middle-out reasoning [Bundy et aI, 1990a]). Subsequent planning provides the necessary information which, together with the original definitional equations. will allow us to instantiate such meta-variables through higher-order unification procedures. The control provided by proof planning allows us to view program synthesis as verification together with MaR. This approach has already been investigated for the purposes of synthesizing tail-recursive programs from non-tail-recursive specifications [Hesketh et at, 1992], IThis research was supported by SERC grant GR/H/23610, and a SERC Postdoctoral Fellowshio to the author. as well as other forms of program optimization such as tupling transformations and deforestation [Madden et at, 1993a, Wiggins et at, 1991]. This research has direct applications regarding the improvement of the quality of software produced through automatic programming. In a broader sense, applications of formal methods in software engineering depend critically on the use of automated theorem provers to provide improved support for the development of safety critical systems. The development of correctness preserving program synthesis and opt imization systems will help provide such support. Subject area (key words): Automated Reasoning (program verification/synthesis/optimization), theorem provin~, formal methods, planning).