Total correctness by local improvement in program transformation

The goal of program transformation is to improve efficiency while preserving meaning. One of the best known transformation techniques is Burstall and Darlington's unfold-fold method. Unfortunately the unfold-fold method itself guarantees neither improvement in efficiency nor total-correctness. The correctness problem for unfold-fold is an instance of a strictly more general problem: transformation by locally equivalence-preserving steps does not necessarily preserve (global) equivalence. This paper presents a condition for the total correctness of transformations on recursive programs, which, for the first time, deals with higher-order functional languages (both strict and non-strict) including lazy data structures. The main technical result is an improvement theorem which says that if the local transformation steps are guided by certain optimisation concerns (a fairly natural condition for a transformation, then correctness of the transformation follows. The improvement theorem makes essential use of a formalised improvement-theory; as a rather pleasing corollary it also guarantees that the transformed program is a formal improvement over the original. The theorem has immediate practical consequences: • It is a powerful tool for proving the correctness of existing transformation methods for higher-order functional programs, without having to ignore crucial factors such as memoization or folding. We have applied the theorem to obtain a particularly simple proof of correctness for a higher-order variant of deforestation. • It yields a simple syntactic method for guiding and constraining the unfold/fold method in the general case so that total correctness (and improvement) is always guaranteed.

[1]  Taisuke Sato,et al.  Equivalence-Preserving First-Order Unfold/Fold Transformation Systems , 1990, Theor. Comput. Sci..

[2]  Hirohisa Seki,et al.  Unfold/Fold Transformation of General Logic Programs for the Well-Founded Semantics , 1993, J. Log. Program..

[3]  John C. Shepherdson,et al.  Unfold/fold transformations of logic programs , 1992, Mathematical Structures in Computer Science.

[4]  Sandro Etalle,et al.  Transforming Normal Programs by Replacement , 1992, META.

[5]  Michael J. Maher Correctness of a Logic Program Transformation System , 1987 .

[6]  Siau-Cheng Khoo,et al.  On-line & O(cid:11)-line Partial Evaluation: Semantic Speci(cid:12)cations and Correctness Proofs (cid:3) , 1993 .

[7]  Hisao Tamaki,et al.  Unfold/Fold Transformation of Logic Programs , 1984, ICLP.

[8]  David Sands,et al.  A Naïve Time Analysis and its Theory of Cost Equivalence , 1995, J. Log. Comput..

[9]  David Sands,et al.  Operational Theories of Improvement in Functional Languages (Extended Abstract) , 1991, Functional Programming.

[10]  Robin Milner,et al.  Communication and concurrency , 1989, PHI Series in computer science.

[11]  Mitchell Wand,et al.  Specifying the correctness of binding-time analysis , 1993, POPL '93.

[12]  Sandro Etalle,et al.  On Safe Folding , 1992, PLILP.

[13]  Bruno Courcelle,et al.  Equivalences and Transformations of Regular Systems-Applications to Recursive Program Schemes and Grammars , 1986, Theor. Comput. Sci..

[14]  Alberto Pettorossi,et al.  Semantics preserving transformation rules for Prolog , 1991 .

[15]  Douglas J. Howe Equality in lazy computation systems , 1989, [1989] Proceedings. Fourth Annual Symposium on Logic in Computer Science.

[16]  Laurent Kott A System for Proving Equivalences of Recursive Programs , 1980, CADE.

[17]  William L. Scherlis,et al.  Expression procedures and program derivation , 1980 .

[18]  John Darlington,et al.  A Transformation System for Developing Recursive Programs , 1977, J. ACM.

[19]  Alberto Pettorossi,et al.  Transformation of Logic Programs: Foundations and Techniques , 1994, J. Log. Program..

[20]  Matthias Felleisen,et al.  A Syntactic Theory of Sequential Control , 1987, Theor. Comput. Sci..

[21]  Torben Amtoft Unfold/fold Transformations Preserving Termination Properties , 1992, PLILP.

[22]  Peter Sestoft,et al.  Partial evaluation and automatic program generation , 1993, Prentice Hall international series in computer science.

[23]  Gordon D. Plotkin,et al.  Call-by-Name, Call-by-Value and the lambda-Calculus , 1975, Theor. Comput. Sci..

[24]  Jens Palsberg,et al.  Correctness of binding-time analysis , 1993, Journal of Functional Programming.

[25]  Colin Runciman,et al.  Transformation in a Non-Strict Language: An Approach to Instantiation , 1989, Functional Programming.

[26]  Philip Wadler,et al.  Deforestation: Transforming Programs to Eliminate Trees , 1990, Theor. Comput. Sci..

[27]  Hong Zhu,et al.  How powerful are folding/unfolding transformations? , 1994, Journal of Functional Programming.

[28]  Zohar Manna,et al.  Synthesis: Dreams - Programs , 1979, IEEE Trans. Software Eng..

[29]  S. Abramsky The lazy lambda calculus , 1990 .

[30]  William L. Scherlis,et al.  Program improvement by internal specialization , 1981, POPL '81.

[31]  Mitchell Wand Specifying the Correctness of Binding-Time Analysis , 1993, J. Funct. Program..

[32]  Carsten K. Gomard A self-applicable partial evaluator for the lambda calculus: correctness and pragmatics , 1992, TOPL.

[33]  Uday S. Reddy,et al.  Rewriting Techniques for Program Synthesis , 1989, RTA.

[34]  Taisuke Sato,et al.  An Equivalence Preserving First Order Unfold/fold Transformation System , 1990, International Conference on Algebraic and Logic Programming.

[35]  Valentin F. Turchin,et al.  The concept of a supercompiler , 1986, TOPL.

[36]  Gérard Boudol,et al.  Recursion Induction Principle Revisited , 1983, Theor. Comput. Sci..

[37]  Robin Milner,et al.  Fully Abstract Models of Typed lambda-Calculi , 1977, Theor. Comput. Sci..