Total correctness by local improvement in the transformation of functional programs

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 article 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 nonstrict) including lazy data structures. The main technical result is an improvement theorem which says that if the local transformation steps are guided by certain optimization concerns (a fairly natural condition for a transformation), then correctness of the transformation follows. The improvement theorem makes essential use of a formalized 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, and 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]  John C. Shepherdson,et al.  Unfold/fold transformations of logic programs , 1992, Mathematical Structures in Computer Science.

[2]  Philip Wadler The Concatenate Vanishes , 1987 .

[3]  Simon L. Peyton Jones,et al.  The Implementation of Functional Programming Languages , 1987 .

[4]  Matthias Felleisen,et al.  A call-by-need lambda calculus , 1995, POPL '95.

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

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

[7]  Martin S. Feather,et al.  A System for Assisting Program Transformation , 1982, TOPL.

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

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

[10]  中川 裕志,et al.  UNFOLD/FOLD TRANSFORMATION OF STRATIFIED PROGRAMS , 1989 .

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

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

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

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

[15]  David Sands,et al.  Higher-order expression procedures , 1995, PEPM '95.

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

[17]  David Sands,et al.  Calculi for time analysis of functional programs , 1990 .

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

[19]  John McCarthy,et al.  A basis for a mathematical theory of computation, preliminary report , 1899, IRE-AIEE-ACM '61 (Western).

[20]  Hirohisa Seki,et al.  Unfold/Fold Transformations of Stratified Programs , 1991, Theor. Comput. Sci..

[21]  Joyce L. Vedral,et al.  Functional Programming Languages and Computer Architecture , 1989, Lecture Notes in Computer Science.

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

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

[24]  Torben Amtoft,et al.  Sharing of Computations , 1993 .

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

[26]  Bard Bloom Can LCF be topped? Flat lattice models of typed lambda calculus , 1988, [1988] Proceedings. Third Annual Information Symposium on Logic in Computer Science.

[27]  Alberto Pettorossi,et al.  Total correctness of a goal replacement rule based on the unfold/fold proof method , 1994, GULP-PRODE.

[28]  Robin Milner,et al.  Co-Induction in Relational Semantics , 1991, Theor. Comput. Sci..

[29]  John W. Backus,et al.  Can programming be liberated from the von Neumann style?: a functional style and its algebra of programs , 1978, CACM.

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

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

[32]  R. J. M. Hughes,et al.  Super-combinators a new implementation method for applicative languages , 1982, LFP '82.

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

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

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

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

[37]  Ralf Steinbrüggen,et al.  Program Transformation Systems , 1983, CSUR.

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

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

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

[41]  Alberto Pettorossi,et al.  Semantics preserving transformation rules for Prolog , 1991, PEPM '91.

[42]  Philip Wadler,et al.  Theorems for free! , 1989, FPCA.

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

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

[45]  Andrew D. Gordon Bisimilarity as a theory of functional programming , 1995, MFPS.

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

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

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

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

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

[51]  David Sands,et al.  Proving the Correctness of Recursion-Based Automatic Program Transformations , 1995, Theor. Comput. Sci..

[52]  Simon Peyton Jones,et al.  The Implementation of Functional Programming Languages (Prentice-hall International Series in Computer Science) , 1987 .

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

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

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

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

[57]  Tadashi Kanamori,et al.  Preservation of Stronger Equivalence in Unfold/Fold Logic Program Transformation , 1990, Theor. Comput. Sci..

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