Abstract
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.
- ABRAMSKY, S. 1990. The lazy lambda calculus. In Research Topics in Functional Programming, D. Turner, Ed. Addison-Wesley, Reading, Mass., 65-116. Google Scholar
- AMTOFT, T. 1992. Unfold/fold transformations preserving termination properties. In PLILP '92. Lecture Notes in Computer Science, vol. 631. Springer-Verlag, Berlin, 187-201. Google Scholar
- AMTOFT, T. 1993. Sharing of computations. Ph.D. thesis, DAIMI, Aarhus Univ., Aarhus, Denmark.Google Scholar
- ARIOLA, Z., FELLEISEN, ~/{., ~/{ARAIST, J., ODERSKY, ~/{., AND WADLER, P. 1995. The cMl-by-need lambda calculus. In The 22nd Annual A CM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL '95). ACM Press, New York. Google Scholar
- BACKUS, J. 1978. Can programming be liberated from the von Neumann style? A functional style and its algebra of programs. Commun. ACM 21, 8 (Aug.), 613-641. Google Scholar
- BIRD, R. 1984. Using circular programs to eliminate multiple traversals of data. Acta Informatica 21, 1, 239-250.Google Scholar
- BLOOM, B. 1988. Can LCF be topped7 Flat lattice models of typed lambda calculus. In The 3rd Annual Symposium on Logic in Computer Science. IEEE, New York.Google Scholar
- BOSSI, A., Cocco, N., AND ETALLE, S. 1992a. On safe folding. In PLILP '92. Lecture Notes in Computer Science, vol. 631. Springer-Verlag, Berlin, 172-186. Google Scholar
- BOSSI, A., Cocco, N., AND ETALLE, S. 1992b. Transforming normal programs by replacement. In The 3rd Workshop on Meta-Programming in Logic, META 92. Lecture Notes in Computer Science, vol. 649. Springer-Verlag, Berlin, 265-279. Google Scholar
- BOUDOL, G. AND KOTT, L. 1983. Recursion induction principle revisited. Theor. Comput. Sci. 22, 1, 135-173.Google Scholar
- BURSTALL, R. AND DARLINGTON, J. 1977. A transformation system for developing recursive programs. J. ACM 2g, 1 (Jan.), 44-67. Google Scholar
- CONSEL, C. AND KHOO, S. 1993. On-line and off-line partial evaluation: Semantic specification and correctness proofs. Tech. rep., Yale Univ., New Haven, Conn. Apr.Google Scholar
- COURCELLE, B. 1979. Infinite trees in normal form and recursive equations having a unique solution. Math. Syst. Theor. 13, 1, 131-180.Google Scholar
- COURCELLE, B. 1986. Equivalences and transformations of regular systems--applications to recursive program schemes and grammars. Theor. Comput. Sci. 42, 1, 1-122.Google Scholar
- FEATHER, M. 1979. A system for assisting program transformations. Ph.D. thesis, Univ. of Edinburgh, Edinburgh.Google Scholar
- FELLEISEN, M., FRIEDMAN, D., AND KOHLBECKER, E. 1987. A syntactic theory of sequential control. Theor. Comput. Sci. 52, 1, 205-237. Google Scholar
- GARDNER, P. AND SHEPHERDSON, J. 1991. Unfold/fold transformations of logic programs. In Computational Logic: Essays in Honor of Alan Robinson, J.-L. Lassez and G. Plotkin, Eds. HIT Press, Cambridge, Mass.Google Scholar
- GOMARD, C. 1992. A self-applicable partial evaluator for the lambda calculus: Correctness and pragmatics. ACM Trans. Program. Lang. Syst. 14, 2, 147-172. Google Scholar
- GORDON, A. D. 1995. Bisimilarity as a theory of functional programming. In Proceedings of the 11th Conference on Mathematical Foundations of Programming Semantics, MFPS'95. Electronic Notes in Computer Science, vol. 1. Elsevier Science, Amsterdam.Google Scholar
- HOWE, D. J. 1989. Equality in lazy computation systems. In The ~th Annual Symposium on Logic in Computer Science. IEEE, New York, 198-203. Google Scholar
- HUET, G. AND LANG, B. 1978. Proving and applying program transformations expressed with second order patterns. Acta Inf. 11, 1 (Jan.), 31-55.Google Scholar
- HUGHES, R. 1982. Super-combinators: A new implementation method for applicative languages. In Proceedings of the 1982 ACM Symposium on Lisp and Functional Languages. ACM, New York, 1-10. Google Scholar
- JONES, N. D., GOMARD, C., AND SESTOFT, P. 1993. Partial Evaluation and Automatic Program Generation. Prentice-Hall, Englewood Cliffs, N.J. Google Scholar
- KANAMORI, T. AND FUJITA, H. 1986. Unfold/fold transformation of logic programs with counters. Tech. Rep. ICOT TR-179, ICOT Research Center, Tokyo.Google Scholar
- KAWAMURA, T. AND KANAMORI, T. 1990. Preservation of stronger equivalence in unfold/fold logic program transformation. Theor. Comput. Sci. 1, 73, 139-154. Google Scholar
- KOTT, L. 1978. About transformation system: A theoretical study. In Program Transformations, B. Robinet, Ed. Dunod, Paris, 232-247.Google Scholar
- KOTT, L. 1980. A system for proving equivalences of recursive programs. In The 5th Conference on Automated Deduction, W. Bibel and R. Kowalski, Eds. Lecture Notes in Computer Science, vol. 87. Springer-Verlag, Berlin, 63-69. Google Scholar
- KOTT, L. 1985. Unfold/fold transformations. In Algebraic Methods in Semantics, M. Nivat and J. Reynolds, Eds. Cambridge University Press, Cambridge, Chapter 12, 412-433. Google Scholar
- MAHER, ~/{. 1987. Correctness of a logic program transformation system. Tech. rep., IBM T. J. Watson Research Center, Yorktown Heights, N.Y. Revised 1989.Google Scholar
- MANNA, Z. AND WALDINGER, R. 1979. Synthesis: Dreams =~ programs. ACM Trans. Program. Lang. Syst. 5, 4.Google Scholar
- MCCARTHY, J. 1967. A Basis for a Mathematical Theory of Computation. North-Holland, Aresterdam.Google Scholar
- MILNER, R. 1977. Fully abstract models of the typed ~-cMculus. Theor. Comput. Sci. 4, 1.Google Scholar
- MILNER, R. 1989. Communication and Concurrency. Prentice-HM1, Englewwood Cliffs, N.J. Google Scholar
- M{ILNER, R. AND TOFTE, ~/{. 1991. Co-induction in relational semantics. Theor. Comput. Sci. 87, 1, 209-220. Google Scholar
- PALSBERG, J. 1993. Correctness of binding time analysis. J. of Funct. Program. 3, 3, 347-364.Google Scholar
- PARTSCH, P. AND STEINBRUGGEN, R. 1983. Program transformation systems. ACM Comput. Surv. 15, 1, 199-236. Google Scholar
- PETTOROSSI, t. AND PROIETTI, ~/{. 1993. Transformation of logic programs: Foundations and techniques. Tech. Rep. R 369, CNR Istituto di AnMisi dei Sistemi ed Informatica, Rome.Google Scholar
- PEYTON JONES, S. L. 1987. The Implementation of Functional Programming Languages. Prentice- Hall International Ltd. London. Google Scholar
- PLOTKIN, G. D. 1975. CMl-by-name, CMl-by-vMue and the ~-cMculus. Theor. Comput. Sci. 1, 1, 125-159.Google Scholar
- PROIETTI, ~/{. AND PETTOROSSI, t. 1991. Semantics preserving transformation rules for Prolog. In Proceedings of the Symposium on Partial Evaluation and Semantics-Based Program Manipulation, PEPM '91. SIGPLAN Not. 26, 9 (Sept.). Google Scholar
- PROIETTI, ~/{. AND PETTOROSSI, t. 1994. Total correctness of a goal replacement rule based on the unfold-fold proof method. CNR Istituto di AnMisi dei Sistemi ed Informatica, Rome.Google Scholar
- REDDY, U. 1989. Rewriting techniques for program synthesis. In Rewriting Techniques and Applications. Lecture Notes in Computer Science, vol. 355. Springer-Verlag, Berlin, 388-403. Google Scholar
- RUNCIMAN, C., FIRTH, ~/{., AND JAGGER, N. 1989. Transformation in a non-strict language: An approach to instantiation. In Functional Programming, Glasgow 1989: Proceedings of the 1st Glasgow Workshop on Functional Programming. Springer-Verlag, Berlin. Google Scholar
- SANDS, D. 1990. Calculi for time analysis of functional programs. Ph.D. thesis, Dept. of Computing, Imperial College, Univ. of London, London.Google Scholar
- SANDS, D. 1991. Operational theories of improvement in functional languages (extended abstract). In Proceedings of the ~th Glasgow Workshop on Functional Programming (Skye, Scotland). Springer-Verlag, Berlin, 298-311. Google Scholar
- SANDS, D. 1993. A n~'fve time analysis and its theory of cost equivalence. TOPPS Rep. D-173, DIKU. Also in Logic and Comput., 5, 4, 495-541.Google Scholar
- SANDS, D. 1995a. Higher-order expression procedures. In Proceeding of the ACM SIGPLAN Syposium on Partial Evaluation and Semantics-Based Program Manipulation, PEPM'95. ACM, New York, 190-201. Google Scholar
- SANDS, D. 1995b. Proving the correctness of recursion-based automatic program transformations. In The International Joint Conference on Theory and Practice of Software Development (TAPSOFT//FASE '95). Lecture Notes in Computer Science, vol. 915. Springer-Verlag, Berlin. Extended version to appear in Theor. Comput. Sci. Google Scholar
- SATO, T. 1990. An equivalence preserving first order unfold/fold transformation system. In The 2nd International Conference on Algebraic and Logic Programming. Lecture Notes in Computer Science, vol. 462. Springer-Verlag, Berlin, 175-188. Google Scholar
- SCHERLIS, W. 1980. Expression procedures and program derivation. Ph.D. thesis, Stanford Rep. STAN-CS-80-818, Dept. of Computer Science, Stanford Univ., Stanford, Calif. Google Scholar
- SCHERLIS, W. L. 1981. Program improvement by internal speciMisation. In The 8th Symposium on Principals of Programming Languages. ACM, New York. Google Scholar
- SEKI, H. 1991. Unfold/fold transformation of stratified programs. Theor. Comput. Sci. 86, 1, 107-139. Google Scholar
- SEKI, H. 1993. Unfold/fold transformation of general logic programs for the well-founded semantics. J. Logic Program. 16, 1, 5-23.Google Scholar
- TAMAKI~ H. AND SATO~ T. 1984. Unfold/fold transformation of logic programs. In The 2nd International Logic Programming Conference, S. Tarnlund, Ed. MIT Press, Cambridge, Mass., 127-138.Google Scholar
- TURCHIN~ V. F. 1986. The concept of a supercompiler. ACM Trans. Program. Lang. Syst. 8, 3 (July), 292-325. Google Scholar
- WADLER, P. 19890o. The concatenate vanishes. Univ. of Glasgow, Glasgow, Scotland. Preliminary version circulated on the fp mailing list, 1987.Google Scholar
- WADLER, P. 1989b. Theorems for free! In Functional Programming Languages and Computer Architecture, FPCA '89 Conference Proceedings. ACM, New York, 347-359. Google Scholar
- WADLER~ P. 1990. Deforestation: Transforming programs to eliminate trees. Theor. Comput. Sci. 73, 1, 231-248. Preliminary version in ESOP 88, Lecture Notes in Computer Science, vol. 300. Google Scholar
- WAND~ M. 1993. Specifying the correctness of binding time analysis. J. Funct. Program. 3, 3, 365-387.Google Scholar
- YONQUIANG~ S., RUZHAN~ L., AND XIAORONG~ H. 1987. Termination preserving problem in the transformation of applicative programs. J. Comput. Sci. Tech. 2, 3, 191-201.Google Scholar
- ZHU, H. 1994. How powerful are folding/unfolding transformations? J. Funct. Program. J, 1 (Jan.), 89-112.Google Scholar
Index Terms
- Total correctness by local improvement in the transformation of functional programs
Recommendations
Total correctness by local improvement in program transformation
POPL '95: Proceedings of the 22nd ACM SIGPLAN-SIGACT symposium on Principles of programming languagesThe 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 ...
An unfold/fold transformation framework for definite logic programs
Given a logic program P, an unfold/fold program transformation system derives a sequence of programs P = P0, P1, …, Pn, such that Pi+1 is derived from Pi by application of either an unfolding or a folding step. Unfold/fold transformations have been ...
Transformation Rules and Strategies for Functional-Logic Programs: Thesis
CASCThis paper abstracts the contents of a PhD dissertation entitled ‘Transformation Rules and Strategies for Functional-Logic Programs’ which has been recently defended. These techniques are based on fold/unfold transformations and they can be used to ...
Comments