Advertisement

Swapping Arguments and Results of Recursive Functions

  • Akimasa Morihata
  • Kazuhiko Kakehi
  • Zhenjiang Hu
  • Masato Takeichi
Part of the Lecture Notes in Computer Science book series (LNCS, volume 4014)

Abstract

Many useful calculation rules, such as fusion and tupling, rely on well-structured functions, especially in terms of inputs and outputs. For instance, fusion requires that well-produced outputs should be connected to well-consumed inputs, so that unnecessary intermediate data structures can be eliminated. These calculation rules generally fail to work unless functions are well-structured. In this paper, we propose a new calculation rule called IO swapping. IO swapping exchanges call-time computations (occurring in the arguments) and return-time computations (occurring in the results) of a function, while guaranteeing that the original and resulting function compute the same value. IO swapping enables us to rearrange inputs and outputs so that the existing calculation rules can be applied. We present new systematic derivations of efficient programs for detecting palindromes, and a method of higher-order removal that can be applied to defunctionalize function arguments, as two concrete applications.

Keywords

Recursive Function Recursive Call Program Transformation Proof Tree Calculation Rule 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 1.
    Bird, R., de Moor, O.: Algebra of Programming. Prentice Hall Int. Series in Computer Science. Prentice Hall, Englewood Cliffs (1996)Google Scholar
  2. 2.
    Bird, R.: Algebraic identities for program calculation. Computer J. 32(2), 122–126 (1989)CrossRefMathSciNetGoogle Scholar
  3. 3.
    Meijer, E., Fokkinga, M., Paterson, R.: Functional programming with bananas, lenses, envelopes and barbed wire. In: Hughes, J. (ed.) FPCA 1991. LNCS, vol. 523, pp. 124–144. Springer, Heidelberg (1991)Google Scholar
  4. 4.
    Bird, R.: Using circular programs to eliminate multiple traversals of data. Acta Inform. 21, 239–250 (1984)MATHCrossRefGoogle Scholar
  5. 5.
    Chin, W.N.: Towards an automated tupling strategy. In: Proc. of 1993 ACM SIGPLAN Symp. on Partial Evaluation and Semantics-Based Program Manipulation, PEPM 1993, pp. 119–132. ACM Press, New York (1993)CrossRefGoogle Scholar
  6. 6.
    Pettorossi, A., Proietti, M.: Rules and strategies for transforming functional and logic programs. ACM Comput. Surveys 28(2), 360–414 (1996)CrossRefGoogle Scholar
  7. 7.
    Hu, Z., Iwasaki, H., Takeichi, M., Takano, A.: Tupling calculation eliminates multiple data traversals. In: Proc. of 2nd ACM SIGPLAN Int. Conf. on Functional Programming, ICFP 1997, pp. 164–175. ACM Press, New York (1997)CrossRefGoogle Scholar
  8. 8.
    Bird, R.: Introduction to Functional Programming using Haskell. Prentice Hall Int. Series in Computer Science. Prentice Hall, Englewood Cliffs (1998)Google Scholar
  9. 9.
    Hu, Z., Iwasaki, H., Takeichi, M.: Deriving structural hylomorphisms from recursive definitions. In: Proc. of 1st ACM SIGPLAN Int. Conf. on Functional Programming, ICFP 1996, pp. 73–82. ACM Press, New York (1996)CrossRefGoogle Scholar
  10. 10.
    Morihata, A.: Relationship between arguments and results of recursive functions. Master’s thesis. University of Tokyo (2006)Google Scholar
  11. 11.
    Chin, W.N.: Fully lazy higher-order removal. In: Proc. of 1992 ACM SIGPLAN Wksh. on Partial Evaluation and Semantics-Based Program Manipulation, PEPM 1992. TR YALEU/DCS/RR-909, Yale University, pp. 38–47 (1992)Google Scholar
  12. 12.
    Danvy, O., Goldberg, M.: There and back again. In: Proc. of 7th ACM SIGPLAN Int. Conf. on Functional Programming, ICFP 2002, pp. 230–234. ACM Press, New York (2002)CrossRefGoogle Scholar
  13. 13.
    Morihata, A., Kakehi, K., Hu, Z., Takeichi, M.: IO swapping leads you there and back again. In: Rutherford, M.J. (ed.) Proc. of 7th GPCE Young Researchers Wksh., GPCE-YRW 2005, pp. 7–13. Inst. of Cybernetics, Tallinn (2005); Extended abstract of [14]Google Scholar
  14. 14.
    Morihata, A., Kakehi, K., Hu, Z., Takeichi, M.: Reversing iterations: IO swapping leads you there and back again. Techn. Report METR 2005-11, Dept. of Mathematical Informatics, University of Tokyo (2005)Google Scholar
  15. 15.
    Reynolds, J.C.: Definitional interpreters for higher-order programming languages. Higher-Order and Symb. Comput. 11(4), 363–397 (1998); Reprinted from Proc. of 25th ACM Nat. Conf. (1972), with a forewordMATHCrossRefGoogle Scholar
  16. 16.
    Danvy, O., Goldberg, M.: There and back again. Fund. Inform. 66(4), 397–413 (2005)MATHMathSciNetGoogle Scholar
  17. 17.
    Nishimura, S.: Fusion with stacks and accumulating parameters. In: Proc. of 2004 ACM SIGPLAN Wksh. on Partial Evaluation and Semantics-Based Program Manipulation, PEPM 2004, pp. 101–112. ACM Press, New York (2004)CrossRefGoogle Scholar
  18. 18.
    Ganzinger, H., Giegerich, R.: Attribute coupled grammars. In: Proc. of 1984 SIGPLAN Symp. on Compiler Construction, pp. 157–170. ACM Press, New York (1984)CrossRefGoogle Scholar
  19. 19.
    Knuth, D.E.: Semantics of context-free languages. Math. Syst. Theory 2(2), 127–145 (1968)MATHCrossRefMathSciNetGoogle Scholar
  20. 20.
    Kühnemann, A.: Benefits of tree transducers for optimizing functional programs. In: Arvind, V., Ramanujam, R. (eds.) FST TCS 1998. LNCS, vol. 1530, pp. 146–158. Springer, Heidelberg (1998)CrossRefGoogle Scholar
  21. 21.
    Kühnemann, A.: Comparison of deforestation techniques for functional programs and for tree transducers. In: Middeldorp, A. (ed.) FLOPS 1999. LNCS, vol. 1722, pp. 114–130. Springer, Heidelberg (1999)CrossRefGoogle Scholar
  22. 22.
    Correnson, L., Duris, E., Parigot, D., Roussel, G.: Declarative program transformation: A deforestation case-study. In: Nadathur, G. (ed.) PPDP 1999. LNCS, vol. 1702, pp. 360–377. Springer, Heidelberg (1999)CrossRefGoogle Scholar
  23. 23.
    Voigtländer, J.: Using circular programs to deforest in accumulating parameters. Higher-Order and Symb. Comput. 17(1-2), 129–163 (2004)MATHCrossRefGoogle Scholar
  24. 24.
    Boiten, E.A.: Improving recursive functions by inverting the order of evaluation. Sci. of Comput. Programming 18(2), 139–179 (1992)MATHCrossRefMathSciNetGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2006

Authors and Affiliations

  • Akimasa Morihata
    • 1
  • Kazuhiko Kakehi
    • 2
  • Zhenjiang Hu
    • 1
  • Masato Takeichi
    • 1
  1. 1.Graduate School of Information Science and TechnologyUniversity of TokyoJapan
  2. 2.Division of University Corporate RelationsUniversity of TokyoTokyoJapan

Personalised recommendations