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.
Supplemental Material
Available for Download
"Maximal Sharing in the Lambda Calculus with letrec" for ICFP 2014 by Clemens Grabmayer and Jan Rochel.
- A. Asperti and S. Guerrini. The Optimal Implementation of Functional Programming Languages. Cambridge University Press, 1998. Google Scholar
Digital Library
- T. Balabonski. A unified approach to fully lazy sharing. In Proceedings of POPL '12, pages 469--480, New York, NY, USA, 2012. ACM. Google Scholar
Digital Library
- R. S. Bird and R. Patterson. de Bruijn notation as a nested datatype. Journal of Functional Programming, 9(1):77--91, 1999. Google Scholar
Digital Library
- S. Blom. Term Graph Rewriting - Syntax and Semantics. PhD thesis, Vrije Universiteit Amsterdam, 2001.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- O. Danvy and U. P. Schultz. Lambda-lifting in quadratic time. Journal of Functional and Logic Programming, 2004, 2004.Google Scholar
- 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 Scholar
Cross Ref
- A. L. de Medeiros Santos. Compilation by Transformation in Non-Strict Functional Languages. PhD thesis, University of Glasgow, 1995.Google Scholar
- 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 Scholar
- C. Grabmayer and J. Rochel. Expressibility in the Lambda Calculus with Letrec. Technical report, arXiv, August 2012. arXiv:1208.2383.Google Scholar
- 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 Scholar
Cross Ref
- C. Grabmayer and J. Rochel. Expressibility in the Lambda Calculus withμ. In Proceedings of RTA 2013, 2013. Report: arXiv:1304.6284.Google Scholar
- C. Grabmayer and J. Rochel. Confluent Let-Floating. In Proceedings of IWC 2013 (2nd International Workshop on Confluence), 2013.Google Scholar
- C. Grabmayer and J. Rochel. Maximal Sharing in the Lambda Calculus with letrec. Technical report, 2014. arXiv:1401.1460.Google Scholar
- C. Grabmayer and V. van Oostrom. Nested Term Graphs. Technical report, arXiv, May 2014. arXiv:1405.6380.Google Scholar
- D. Hendriks and V. van Oostrom. λ. In F. Baader, editor, Proceedings CADE-19, volume 2741 of LNAI, pages 136--150. Springer, 2003.Google Scholar
- J. Hopcroft. An nlog n Algorithm for Minimizing States in a Finite Automata. Technical report, Stanford University, CA, USA, 1971. Google Scholar
Digital Library
- J. Hopcroft and R. Karp. A Linear Algorithm for Testing Equivalence of Finite Automata. Technical report, Cornell University, 1971.Google Scholar
- 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 Scholar
Digital Library
- T. Johnsson. Lambda lifting: Transforming programs to recursive equations. In FPCA, pages 190--203, 1985. Google Scholar
Digital Library
- J. Ketema and J. G. Simonsen. Infinitary Combinatory Reduction Systems. Information and Computation, 209(6):893--926, 2011. Google Scholar
Digital Library
- R. Milner. Communicating and mobile systems: the π-calculus. Cambridge University Press, 1999. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- V. v. Oostrom, K.-J. van de Looij, and M. Zwitserlood. Lambdascope. Extended Abstract, Workshop ALPS, Kyoto, April 10th 2004, 2004.Google Scholar
- 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 Scholar
Cross Ref
- S. L. Peyton Jones. The Implementation of Functional Programming Languages. Prentice-Hall, Inc., 1987. Google Scholar
Digital Library
- D. Plump. Evaluation of Functional Expressions by Hypergraph Rewriting. PhD thesis, Universität Bremen, 1993.Google Scholar
- Terese. Term Rewriting Systems, volume 55 of Cambridge Tracts in Theoretical Computer Science. Cambridge University Press, 2003.Google Scholar
- C. P. Wadsworth. Semantics and Pragmatics of the Lambda-Calculus. PhD thesis, University of Oxford, 1971.Google Scholar
Index Terms
Maximal sharing in the Lambda calculus with letrec
Recommendations
Maximal sharing in the Lambda calculus with letrec
ICFP '14: Proceedings of the 19th ACM SIGPLAN international conference on Functional programmingIncreasing 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 ...
The Intensional Lambda Calculus
LFCS '07: Proceedings of the international symposium on Logical Foundations of Computer ScienceWe introduce a natural deduction formulation for the Logic of Proofs, a refinement of modal logic S4 in which the assertion □ A is replaced by [[ s ]] A whose intended reading is " s is a proof of A ". A term calculus for this formulation yields a typed ...
A Finite Simulation Method in a Non-deterministic Call-by-Need Lambda-Calculus with Letrec, Constructors, and Case
RTA '08: Proceedings of the 19th international conference on Rewriting Techniques and ApplicationsThe paper proposes a variation of simulation for checking and proving contextual equivalence in a non-deterministic call-by-need lambda-calculus with constructors, case, seq, and a letrec with cyclic dependencies. It also proposes a novel method to ...







Comments