skip to main content
article
Free Access

From recursion to iteration: what are the optimizations?

Authors Info & Claims
Published:01 November 1999Publication History
Skip Abstract Section

Abstract

Transforming recursion into iteration eliminates the use of stack frames during program execution. It has been studied extensively. This paper describes a powerful and systematic method, based on incrementalization, for transforming general recursion into iteration: identify an input increment, derive an incremental version under the input increment, and form an iterative computation using the incremental version. Exploiting incrementalization yields iterative computation in a uniform way and also allows additional optimizations to be explored cleanly and applied systematically, in most cases yielding iterative programs that use constant additional space, reducing additional space usage asymptotically, and run much faster. We summarize major optimizations, complexity improvements, and performance measurements.

References

  1. 1 H. Abelson, R. K. Dybvig, et al. Revised rept, rt on the algorithmic language Scheme. Hi'gher-Order and Symbolic Computation, 11(1):7-105, Aug. 1998.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. 2 A. V. Aho, J. E. ttopcroft, and J. D. Ullman. The Design and Analysis of Computer Algorithms. Addison-'Wesley, Reading, Mass., 1974.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. 3 A. W. Appel. Modern C6rnpiler fmpiementation in Java. Cambridge University Pres,% 1998.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. 4 J. Arsac and Y. Kodrateff. Some techniques for reeursion removal from recursive functions. A CM 7~.ans. Program. Lang. Syst., 4(2):295-322, Apr. 1982.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. 5 J. Backus. Can programming be liberated from the yon Neumann style? a functional style and its algebra o.f programs. Commun. ACM, 21(8):613-641, Aug. 1978.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. 6 J..Backus. From function level semantics to program transformation and optimization. In H. Ehrig et al., editors, Proceedings of the International Joint Confedence on Theory and Practice of Software Development, "volume 185 of Lecture Notes in Computer Science, pages 60-91. Springer-Verlag, Berlin, Mar. 1985.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. 7 F. L. Batier a,xd H. ",VSs~uie,'. Algorithmic La~gut, ge ~nd Program Development. Springer-Verlag, Berlin, 1982.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. 8 L. Blaine and A. Goldberg. DTRE--A semi-automatic transformation system. In B. M511er, editor, Constructing Programs from Specifications, pages 165-203. North-Holland, Amsterdam, 1991.]]Google ScholarGoogle Scholar
  9. 9 E. A. Boiten. Improving recursive functions by inverting the order of evaluation. Sci. Comput. Program., 18(2):139-179, Apr. 1992.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. 10 R. M. Burstall and J. Darlington. A transformation system for developing recursive programs. J. ACM, 24(1):44-67, Jan. 1977.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. 11 J. Cai and R. Paige. Program derivation by fixed point computation. Sci. Comput. Program., 11:197-261, Sept. 1988/89.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. 12 N. H. Cohen. Eliminating redundant recursive calls. ACM Trans. Program. Lang. Syst., 5(3):265--299. July 1983.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. 13 T. H. Cormen, C. E. Leiserson, and R. L. Rivest,. Introduction to Algorithms. The MIT Press/McGraw-Hill, 1990.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. 14 J. Darlington and ~. Burstall. A system which automatically improves programs. Acts Informatica, 6(1):41--60, 1976.]]Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. 15 A. FiIinski. Recursion from iteration. Lisp and Symbolic Computation, 7(1):11-38, Jan. 1994.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. 16 D. P. Friedman, M. Wand, and C. T. Haynes. Essentials of Programming Languages. MIT Press and McGraw-Hill, 1992.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. 17 S. J Garland and D. C. Luckham. Program schemes, recursion schemes, and formal languages. J. Computer System Sciences, 7:119-160, 1973. Also appeared as technical report UCLA-ENG- 7154, June 2971.]]Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. 18 J. Golsing, B. Joy, and G. Steele. The Java Language Specification. Addison-WesIey, Reading, Mass., 1997.]]Google ScholarGoogle Scholar
  19. 19 S. A. Greibach. Theory of Program Structures: Schemes, Se. mantics, Verification, volume 36 of Lecture Notes in Computer Science. Springer-Verlag, Berlin, 1975.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. 20 P. G. Harrison. Linearisation: An optimization for nonlinear functional programs. Sci. Comput. Program., 10:281-318, 1988.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. 21 P. G. Harrison and H. Khoshnevisan. A new approach to recursion removal. Theoret. Comput. Sci., 93(1):91-113, 1992.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. 22 P. G. Harrison and H. Khoshnevisan. On the synthesis of function inverses. Acta Informatica, 29(3):211-239, 1992.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. 23 W. L. Harrison, III. The interprocedural analysis and automatic parallellization of scheme programs. Lisp and Symbolic Computation, 2(3;/4):179-396, Oct. 1989.]]Google ScholarGoogle Scholar
  24. 24 P. Hadak. t, semantic model of reference counting and its abstraction, in Conference Record of the 1986 A CM Symposium on LISP and Functional Programming, pages 351-363. ACM, New Yorl~. Aug. 1986.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. 25 :3. Huet and B. Lang. Proving and applying program transformations expressed with second-order patterns. Acta Informatica, 11(1):31-55, 1978.]]Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. 26 N. D. Jones. The expressive power of higher-order types or, life without CONS. Journal of Functional Programming. To appear.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. 27 S. B. Jones and D. Le M~tayer. Compile-time garbage collection by sharing analysis. In Proceedings of the $th International Conference on Functional Programming Languages and Computer Architecture~ pages 54-74. ACM, New York, Sept. 1989.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. 28 A. J. Kfoury. Recursion versus iteration at higher-orders. In Fov.ndations of Software Technology and Theoretical Computer .$cienc~, volume 1346 of Lecture Notes in Computer Science, pages 57"-? Springer-Verlag, Berlin, Dec. 1997.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. 29 R. B. Kieburtz and J. Shultis. Transformations of fp program ~chemes. In Proceedings of the ACM Conference on Functional Programming Lnnguages and Computer Architecture. ACM, N ew York, 1981.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. 30 N. Klarlund. MONA Version 1.3 User Manual, Oct. 1998.]]Google ScholarGoogle Scholar
  31. 31 Y. A. Liu. CACHET: An interactive, incremental-attributionbased program transformation system for deriving incremental programs. In Proceedings of the l Oth Knowledge-Based Software Engineering Conference, pages 19-26. IEEE CS Press, Los Alamitos, Calif, Nov. 1995.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. 32 Y. A. Liu. Principled strength reduction. In Proceedings of the IFIP TC2 Working Conference on Algorithmic Languages and Calcul~ Chapman &: Hall, London, U.K., Feb. 1997.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. 33 Y. A. Liu and S. D. Stoller. Dynamic programming via static incrementalization. In Proceedings of the 8th European Symposium on Programming, volume 1576 of Lecture Notes in Computer Science, pages 288-305. Springer-Verlag, Berlin, Mar. 1999.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. 34 Y. A. Liu and S. D. Stolter. From recursion to iteration: what are the optimizations? Technical Report TR 527, Computer Science Department, Indiana University, Bloomington, Indiana, July 1999.]]Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. 35 Y. A. Liu, S. D. Stoller, and T. Teitelbaum. Discovering auxiliary information for incremental computation. In Conference Record of the $3rd Annual A CM Symposium on Principles of Programming Languages, pages 157-170. ACM, New York, Jan. 1996.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. 36 Y. A. Liu, S. D. Stoller, and T. Teitelbaum. Static caching for incremental computation. ACM Trans. Program. Lang. Syst., 20(3):546--585, May 1998.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. 37 Y. A. Liu and T. Teitelbaum. Systematic derivation of incremental programs. Sci~ Comput. Program., 24(1):1-39, Feb. 1995.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. 38 M. Odersky. Programming with variable functions. In Proceedings of the 1998 A CM SIGPLAN International Conference on Functional Programming, pages 105-1!6. ACM, New York, Sept. 1998.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. 39 R. Paige. Real-time simulation of a set machine on a RAM. In Computing and information, Vol. II, pages 69-73. Canadian Scholars Press, 1989. Proceedings of ICCI '89: The International Conference on Computing and Information. Toronto, Canada, May 23-27, 1989.]]Google ScholarGoogle Scholar
  40. 40 R. Paige and S. Koenig. Finite differencing of computable expressions. ACM Trans. Program. Lan9. Syst., 4(3):402-454, July 1982.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. 41 H. A. Partsch. Specification and Transformation of Prcgrams-- A Formal Approach to Software Development. Springer-Verlag, Berlin, 1990.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. 42 M. S. Paterson and C. E. Hewitt. Comparative schematology. In Project MAC Conference on Concurrent Systems and Parallel Computation, pages 119-127. ACM, New York, 1970.]]Google ScholarGoogle ScholarDigital LibraryDigital Library
  43. 43 A. Pettorossi. A powerful strategy for deriving efficient programs by transformation. In Conference Record of the 198~ A CM" Symposium on LISP and Functional Prograrnminq. ACM, New York, Aug. 1984.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  44. 44 A. Pettorossi and M. Proietti. Rules and strategies for transforming functional and logic programs. A CM Comput. Surv., .28(2):360-414, June 1996.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  45. 45 W. Pugh. The Omega Test: A fast and practical integer programming algorithm for dependence analysis. Commun. A CM, 31(8), Aug. 1992.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. 46 P. W. Purdom and C. A. Brown- The Analysis of Algorithms. Holt, Rinehart and Winston, 1985.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  47. 47 W. L. Scherlis. Program improvement by internal specialize, tion. tn Conference Record of the 8th Annual A CM Symposium on Principles of Programming Languages, pages 41-49. ACM, New York, Jan. 1981.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  48. 48 H. Schorr and W. M. Waite. An efficient machine-independent procedure for grabage collection in various list structures. Commun. ACM, 10(8):501-506, Aug. a967.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  49. 49 D. R. Smith. KIDS: A semiautomatic program development system. IEEE Trans. Softw. Eng., i6(9):1024-1043, Sept. 1990.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  50. 50 S. A. Walker and H. R. Strong. Characterizations of flowchartable recursions. Journal of Computer anti System Sciences, 7:404-447, 1973.]]Google ScholarGoogle Scholar
  51. 51 M. Wand. Continuation-based program transfolmation strategies. J. ACM, 27(1):164-180, Jan. 1980.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  52. 52 M. Wand and W. D. Clinger. Set constraints for destructive array update optimization. In Proceedings of the IEEE 1998 International Conference on Computer Languages, pages 184-193. IEEE CS Press, Los Alamitos~ Calif., May 1998.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  53. 53 R. C. Waters. Automatic transformation of series expressions into loops. ACM Trans. Program. Lang. Syst., 13(1):52-98, Jan. 1991.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  54. 54 B. Wegbreit. Goal-directed program transformation. IEEE Trans. Softw. Eng., SE-.q(9~):69-80. June 1976.]]Google ScholarGoogle Scholar

Index Terms

  1. From recursion to iteration: what are the optimizations?

      Recommendations

      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

      • Published in

        cover image ACM SIGPLAN Notices
        ACM SIGPLAN Notices  Volume 34, Issue 11
        Nov. 1999
        113 pages
        ISSN:0362-1340
        EISSN:1558-1160
        DOI:10.1145/328691
        Issue’s Table of Contents
        • cover image ACM Conferences
          PEPM '00: Proceedings of the 2000 ACM SIGPLAN workshop on Partial evaluation and semantics-based program manipulation
          January 2000
          113 pages
          ISBN:1581132018
          DOI:10.1145/328690

        Copyright © 1999 ACM

        Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 1 November 1999

        Check for updates

        Qualifiers

        • article

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader