skip to main content
research-article

Maximal sharing in the Lambda calculus with letrec

Published:19 August 2014Publication History
Skip Abstract Section

Abstract

Increasing sharing in programs is desirable to compactify the code, and to avoid duplication of reduction work at run-time, thereby speeding up execution. We show how a maximal degree of sharing can be obtained for programs expressed as terms in the lambda calculus with letrec. We introduce a notion of 'maximal compactness' for λletrec-terms among all terms with the same infinite unfolding. Instead of defined purely syntactically, this notion is based on a graph semantics. λletrec-terms are interpreted as first-order term graphs so that unfolding equivalence between terms is preserved and reflected through bisimilarity of the term graph interpretations. Compactness of the term graphs can then be compared via functional bisimulation.

We describe practical and efficient methods for the following two problems: transforming a λletrec-term into a maximally compact form; and deciding whether two λletrec-terms are unfolding-equivalent. The transformation of a λletrec-terms L into maximally compact form L0 proceeds in three steps: (i) translate L into its term graph G = [[L]] ; (ii) compute the maximally shared form of G as its bisimulation collapse G0 ; (iii) read back a λletrec-term L0 from the term graph G0 with the property [[L0]] = G0. Then L0 represents a maximally shared term graph, and it has the same unfolding as L.

The procedure for deciding whether two given λletrec-terms L1 and L2 are unfolding-equivalent computes their term graph interpretations [[L1]] and [[L2]], and checks whether these are bisimilar.

For illustration, we also provide a readily usable implementation.

Skip Supplemental Material Section

Supplemental Material

References

  1. A. Asperti and S. Guerrini. The Optimal Implementation of Functional Programming Languages. Cambridge University Press, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. T. Balabonski. A unified approach to fully lazy sharing. In Proceedings of POPL '12, pages 469--480, New York, NY, USA, 2012. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. R. S. Bird and R. Patterson. de Bruijn notation as a nested datatype. Journal of Functional Programming, 9(1):77--91, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. S. Blom. Term Graph Rewriting - Syntax and Semantics. PhD thesis, Vrije Universiteit Amsterdam, 2001.Google ScholarGoogle Scholar
  5. M. v. d. Brand and P. Klint. ATERMs for manipulation and exchange of structured data: It's all about sharing. Information and Software Technology, 49(1):55--64, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. O. Chitil. Common Subexpressions Are Uncommon in Lazy Functional Languages. In Selected Papers from the 9th International Workshop IFL (IFL '97), pages 53--71, London, UK, UK, 1998. Springer-Verlag. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. O. Danvy and U. P. Schultz. Lambda-lifting in quadratic time. Journal of Functional and Logic Programming, 2004, 2004.Google ScholarGoogle Scholar
  8. N. G. de Bruijn. Lambda Calculus Notation with Nameless Dummies, a Tool for Automatic Formula Manipulation, with Applic. to the Church-Rosser Theorem. Indagationes Mathematicae, 34:381--392, 1972.Google ScholarGoogle ScholarCross RefCross Ref
  9. A. L. de Medeiros Santos. Compilation by Transformation in Non-Strict Functional Languages. PhD thesis, University of Glasgow, 1995.Google ScholarGoogle Scholar
  10. B. Goldberg and P. Hudak. Detecting Sharing of Partial Applications in Functional Programs. Technical Report YALEU/DCS/RR-526, Department of Computer Science, Yale University, March 1987.Google ScholarGoogle Scholar
  11. C. Grabmayer and J. Rochel. Expressibility in the Lambda Calculus with Letrec. Technical report, arXiv, August 2012. arXiv:1208.2383.Google ScholarGoogle Scholar
  12. C. Grabmayer and J. Rochel. Term Graph Representations for Cyclic Lambda Terms. In Proceedings of TERMGRAPH 2013, number 110 in EPTCS, 2013. For an extended report see: arXiv:1308.1034.Google ScholarGoogle ScholarCross RefCross Ref
  13. C. Grabmayer and J. Rochel. Expressibility in the Lambda Calculus withμ. In Proceedings of RTA 2013, 2013. Report: arXiv:1304.6284.Google ScholarGoogle Scholar
  14. C. Grabmayer and J. Rochel. Confluent Let-Floating. In Proceedings of IWC 2013 (2nd International Workshop on Confluence), 2013.Google ScholarGoogle Scholar
  15. C. Grabmayer and J. Rochel. Maximal Sharing in the Lambda Calculus with letrec. Technical report, 2014. arXiv:1401.1460.Google ScholarGoogle Scholar
  16. C. Grabmayer and V. van Oostrom. Nested Term Graphs. Technical report, arXiv, May 2014. arXiv:1405.6380.Google ScholarGoogle Scholar
  17. D. Hendriks and V. van Oostrom. λ. In F. Baader, editor, Proceedings CADE-19, volume 2741 of LNAI, pages 136--150. Springer, 2003.Google ScholarGoogle Scholar
  18. J. Hopcroft. An nlog n Algorithm for Minimizing States in a Finite Automata. Technical report, Stanford University, CA, USA, 1971. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. J. Hopcroft and R. Karp. A Linear Algorithm for Testing Equivalence of Finite Automata. Technical report, Cornell University, 1971.Google ScholarGoogle Scholar
  20. R. Hughes. Supercombinators: A new implementation method for applicative languages. In LFP '82: Proceedings of the 1982 ACM symposium on LISP and functional programming, pages 1--10, 1982. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. T. Johnsson. Lambda lifting: Transforming programs to recursive equations. In FPCA, pages 190--203, 1985. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. J. Ketema and J. G. Simonsen. Infinitary Combinatory Reduction Systems. Information and Computation, 209(6):893--926, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. R. Milner. Communicating and mobile systems: the π-calculus. Cambridge University Press, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. M. T. Morazán and U. P. Schultz. Optimal lambda lifting in quadratic time. In Workshop IAFL 2007, number 5083 in LNCS. Springer, 2008.Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. D. A. Norton. Algorithms for Testing Equivalence of Finite Automata. Master's thesis, Dept. of Computer Science, Rochester Institute of Technology, 2009. https://ritdml.rit.edu/handle/1850/8712.Google ScholarGoogle Scholar
  26. V. v. Oostrom, K.-J. van de Looij, and M. Zwitserlood. Lambdascope. Extended Abstract, Workshop ALPS, Kyoto, April 10th 2004, 2004.Google ScholarGoogle Scholar
  27. J. Palsberg and M. Schwartzbach. Binding-time analysis: abstract interpretation versus type inference. In Int. Conf. on Computer Languages, 1994, pages 289--298, 1994.Google ScholarGoogle ScholarCross RefCross Ref
  28. S. L. Peyton Jones. The Implementation of Functional Programming Languages. Prentice-Hall, Inc., 1987. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. D. Plump. Evaluation of Functional Expressions by Hypergraph Rewriting. PhD thesis, Universität Bremen, 1993.Google ScholarGoogle Scholar
  30. Terese. Term Rewriting Systems, volume 55 of Cambridge Tracts in Theoretical Computer Science. Cambridge University Press, 2003.Google ScholarGoogle Scholar
  31. C. P. Wadsworth. Semantics and Pragmatics of the Lambda-Calculus. PhD thesis, University of Oxford, 1971.Google ScholarGoogle Scholar

Index Terms

  1. Maximal sharing in the Lambda calculus with letrec

      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

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader
      About Cookies On This Site

      We use cookies to ensure that we give you the best experience on our website.

      Learn more

      Got it!