skip to main content
article
Open Access

Total correctness by local improvement in the transformation of functional programs

Authors Info & Claims
Published:01 March 1996Publication History
Skip Abstract Section

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.

References

  1. ABRAMSKY, S. 1990. The lazy lambda calculus. In Research Topics in Functional Programming, D. Turner, Ed. Addison-Wesley, Reading, Mass., 65-116. Google ScholarGoogle Scholar
  2. 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 ScholarGoogle Scholar
  3. AMTOFT, T. 1993. Sharing of computations. Ph.D. thesis, DAIMI, Aarhus Univ., Aarhus, Denmark.Google ScholarGoogle Scholar
  4. 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 ScholarGoogle Scholar
  5. 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 ScholarGoogle Scholar
  6. BIRD, R. 1984. Using circular programs to eliminate multiple traversals of data. Acta Informatica 21, 1, 239-250.Google ScholarGoogle Scholar
  7. 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 ScholarGoogle Scholar
  8. 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 ScholarGoogle Scholar
  9. 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 ScholarGoogle Scholar
  10. BOUDOL, G. AND KOTT, L. 1983. Recursion induction principle revisited. Theor. Comput. Sci. 22, 1, 135-173.Google ScholarGoogle Scholar
  11. BURSTALL, R. AND DARLINGTON, J. 1977. A transformation system for developing recursive programs. J. ACM 2g, 1 (Jan.), 44-67. Google ScholarGoogle Scholar
  12. 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 ScholarGoogle Scholar
  13. COURCELLE, B. 1979. Infinite trees in normal form and recursive equations having a unique solution. Math. Syst. Theor. 13, 1, 131-180.Google ScholarGoogle Scholar
  14. COURCELLE, B. 1986. Equivalences and transformations of regular systems--applications to recursive program schemes and grammars. Theor. Comput. Sci. 42, 1, 1-122.Google ScholarGoogle Scholar
  15. FEATHER, M. 1979. A system for assisting program transformations. Ph.D. thesis, Univ. of Edinburgh, Edinburgh.Google ScholarGoogle Scholar
  16. FELLEISEN, M., FRIEDMAN, D., AND KOHLBECKER, E. 1987. A syntactic theory of sequential control. Theor. Comput. Sci. 52, 1, 205-237. Google ScholarGoogle Scholar
  17. 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 ScholarGoogle Scholar
  18. 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 ScholarGoogle Scholar
  19. 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 ScholarGoogle Scholar
  20. 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 ScholarGoogle Scholar
  21. HUET, G. AND LANG, B. 1978. Proving and applying program transformations expressed with second order patterns. Acta Inf. 11, 1 (Jan.), 31-55.Google ScholarGoogle Scholar
  22. 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 ScholarGoogle Scholar
  23. JONES, N. D., GOMARD, C., AND SESTOFT, P. 1993. Partial Evaluation and Automatic Program Generation. Prentice-Hall, Englewood Cliffs, N.J. Google ScholarGoogle Scholar
  24. KANAMORI, T. AND FUJITA, H. 1986. Unfold/fold transformation of logic programs with counters. Tech. Rep. ICOT TR-179, ICOT Research Center, Tokyo.Google ScholarGoogle Scholar
  25. KAWAMURA, T. AND KANAMORI, T. 1990. Preservation of stronger equivalence in unfold/fold logic program transformation. Theor. Comput. Sci. 1, 73, 139-154. Google ScholarGoogle Scholar
  26. KOTT, L. 1978. About transformation system: A theoretical study. In Program Transformations, B. Robinet, Ed. Dunod, Paris, 232-247.Google ScholarGoogle Scholar
  27. 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 ScholarGoogle Scholar
  28. 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 ScholarGoogle Scholar
  29. MAHER, ~/{. 1987. Correctness of a logic program transformation system. Tech. rep., IBM T. J. Watson Research Center, Yorktown Heights, N.Y. Revised 1989.Google ScholarGoogle Scholar
  30. MANNA, Z. AND WALDINGER, R. 1979. Synthesis: Dreams =~ programs. ACM Trans. Program. Lang. Syst. 5, 4.Google ScholarGoogle Scholar
  31. MCCARTHY, J. 1967. A Basis for a Mathematical Theory of Computation. North-Holland, Aresterdam.Google ScholarGoogle Scholar
  32. MILNER, R. 1977. Fully abstract models of the typed ~-cMculus. Theor. Comput. Sci. 4, 1.Google ScholarGoogle Scholar
  33. MILNER, R. 1989. Communication and Concurrency. Prentice-HM1, Englewwood Cliffs, N.J. Google ScholarGoogle Scholar
  34. M{ILNER, R. AND TOFTE, ~/{. 1991. Co-induction in relational semantics. Theor. Comput. Sci. 87, 1, 209-220. Google ScholarGoogle Scholar
  35. PALSBERG, J. 1993. Correctness of binding time analysis. J. of Funct. Program. 3, 3, 347-364.Google ScholarGoogle Scholar
  36. PARTSCH, P. AND STEINBRUGGEN, R. 1983. Program transformation systems. ACM Comput. Surv. 15, 1, 199-236. Google ScholarGoogle Scholar
  37. 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 ScholarGoogle Scholar
  38. PEYTON JONES, S. L. 1987. The Implementation of Functional Programming Languages. Prentice- Hall International Ltd. London. Google ScholarGoogle Scholar
  39. PLOTKIN, G. D. 1975. CMl-by-name, CMl-by-vMue and the ~-cMculus. Theor. Comput. Sci. 1, 1, 125-159.Google ScholarGoogle Scholar
  40. 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 ScholarGoogle Scholar
  41. 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 ScholarGoogle Scholar
  42. 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 ScholarGoogle Scholar
  43. 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 ScholarGoogle Scholar
  44. SANDS, D. 1990. Calculi for time analysis of functional programs. Ph.D. thesis, Dept. of Computing, Imperial College, Univ. of London, London.Google ScholarGoogle Scholar
  45. 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 ScholarGoogle Scholar
  46. 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 ScholarGoogle Scholar
  47. 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 ScholarGoogle Scholar
  48. 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 ScholarGoogle Scholar
  49. 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 ScholarGoogle Scholar
  50. 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 ScholarGoogle Scholar
  51. SCHERLIS, W. L. 1981. Program improvement by internal speciMisation. In The 8th Symposium on Principals of Programming Languages. ACM, New York. Google ScholarGoogle Scholar
  52. SEKI, H. 1991. Unfold/fold transformation of stratified programs. Theor. Comput. Sci. 86, 1, 107-139. Google ScholarGoogle Scholar
  53. SEKI, H. 1993. Unfold/fold transformation of general logic programs for the well-founded semantics. J. Logic Program. 16, 1, 5-23.Google ScholarGoogle Scholar
  54. 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 ScholarGoogle Scholar
  55. TURCHIN~ V. F. 1986. The concept of a supercompiler. ACM Trans. Program. Lang. Syst. 8, 3 (July), 292-325. Google ScholarGoogle Scholar
  56. WADLER, P. 19890o. The concatenate vanishes. Univ. of Glasgow, Glasgow, Scotland. Preliminary version circulated on the fp mailing list, 1987.Google ScholarGoogle Scholar
  57. WADLER, P. 1989b. Theorems for free! In Functional Programming Languages and Computer Architecture, FPCA '89 Conference Proceedings. ACM, New York, 347-359. Google ScholarGoogle Scholar
  58. 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 ScholarGoogle Scholar
  59. WAND~ M. 1993. Specifying the correctness of binding time analysis. J. Funct. Program. 3, 3, 365-387.Google ScholarGoogle Scholar
  60. 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 ScholarGoogle Scholar
  61. ZHU, H. 1994. How powerful are folding/unfolding transformations? J. Funct. Program. J, 1 (Jan.), 89-112.Google ScholarGoogle Scholar

Index Terms

  1. Total correctness by local improvement in the transformation of functional programs

          Recommendations

          Reviews

          Jan Hendrik Jongejan

          Sands discusses program transformations (such as the unfold/fold method [1]). More specifically, this paper is about the (total) correctness of such transformations. It is intended for researchers in functional programming languages. The author presents a generic functional language with higher-order functions, lazy data structures, and strict as well as nonstrict application. The language is defined by its syntax and an operational semantics for its evaluation. Transformation is defined in terms of substitution and equivalence of expressions. In general, these transformations do not guarantee correctness, although they are based on locally equivalence-preserving steps. A restriction, namely improvement, is needed to guarantee total correctness. Improvement is defined in terms of the cost of evaluating an expression. If e1 costs the same as or more than e2 , then e1 is improved by e2 . The main theorem of the paper states that a transformation guarantees total correctness if all transformation steps are improvements: if fx=e and e is improved by e ? (where the free variables of e ? are included in the vector x of formal parameters of f ) then f is improved by g , where gx=e ? f/g . The proof of the theorem is technically involved, needing several auxiliary definitions and lemmas. However, this part of the paper may be safely skipped if the reader is more interested in the applications. One application is the correctness proof of a simple mechanizable transformation [2], which aims to eliminate calls to the concatenate function: the transformation rules are proven to be improvements. Another application is the development of a totally correct, improved unfold/fold transformation. There is a substantive section on related work and a large list of references, although the author states that not much work has been done on correctness of transformations. <__?__Pub Caret>Since the paper is rather long, some readers might choose to read only the first two sections, which depict the problem and present an overview of the solution. I found reading the paper a stimulating experience, so I recommend it heartily.

          Access critical reviews of Computing literature here

          Become a reviewer for Computing Reviews.

          Comments

          Login options

          Check if you have access through your login credentials or your institution to get full access on this article.

          Sign in

          Full Access

          PDF Format

          View or Download as a PDF file.

          PDF

          eReader

          View online with eReader.

          eReader