Skip to main content Accessibility help
×
Home
Hostname: page-component-559fc8cf4f-28jzs Total loading time: 0.593 Render date: 2021-02-26T08:39:58.100Z Has data issue: true Feature Flags: { "shouldUseShareProductTool": true, "shouldUseHypothesis": true, "isUnsiloEnabled": true, "metricsAbstractViews": false, "figures": false, "newCiteModal": false, "newCitedByModal": true }

Counting and generating lambda terms

Published online by Cambridge University Press:  30 October 2013

KATARZYNA GRYGIEL
Affiliation:
Theoretical Computer Science Department, Faculty of Mathematics and Computer Science, Jagiellonian University, ul. Prof. Łojasiewicza 6, 30-348 Kraków, Poland (e-mail: grygiel@tcs.uj.edu.pl)
PIERRE LESCANNE
Affiliation:
Theoretical Computer Science Department, Faculty of Mathematics and Computer Science, Jagiellonian University, ul. Prof. Łojasiewicza 6, 30-348 Kraków, Poland; ENS de Lyon, University of Lyon, LIP (UMR 5668 CNRS ENS Lyon UCBL INRIA), 46 allée d'Italie, 69364 Lyon, France (e-mail: pierre.lescanne@ens-lyon.fr)
Corresponding

Abstract

Lambda calculus is the basis of functional programming and higher order proof assistants. However, little is known about combinatorial properties of lambda terms, in particular, about their asymptotic distribution and random generation. This paper tries to answer questions like: How many terms of a given size are there? What is a ‘typical’ structure of a simply typable term? Despite their ostensible simplicity, these questions still remain unanswered, whereas solutions to such problems are essential for testing compilers and optimizing programs whose expected efficiency depends on the size of terms. Our approach toward the aforementioned problems may be later extended to any language with bound variables, i.e., with scopes and declarations. This paper presents two complementary approaches: one, theoretical, uses complex analysis and generating functions, the other, experimental, is based on a generator of lambda terms. Thanks to de Bruijn indices (de Bruijn, N. (1972) Lambda calculus notation with nameless dummies, a tool for automatic formula manipulation, with application to the Church-Rosser theorem. Indagat. Math.34(5), 381–392), we provide three families of formulas for the number of closed lambda terms of a given size and we give four relations between these numbers which have interesting combinatorial interpretations. As a by-product of the counting formulas, we design an algorithm for generating λ-terms. Performed tests provide us with experimental data, like the average depth of bound variables and the average number of head lambdas. We also create random generators for various sorts of terms. Thereafter, we conduct experiments that answer questions like: What is the ratio of simply typable terms among all terms? (Very small!) How are simply typable lambda terms distributed among all lambda terms? (A typable term almost always starts with an abstraction.) In this paper, abstractions and applications have size 1 and variables have size 0.

Type
Articles
Copyright
Copyright © Cambridge University Press 2013 

Access options

Get access to the full version of this content by using one of the access options below.

References

Abadi, M., Cardelli, L., Curien, P.-L. & Lévy, J.-J. (1991) Explicit substitutionss. J. Funct. Program. 1 (4), 375416.CrossRefGoogle Scholar
Bodini, O., Gardy, D. & Gittenberger, B. (2011) Lambda terms of bounded unary height. In Proceedings of the Eighth Workshop on Analytic Algorithmics and Combinatorics (ANALCO 2011), San Francisco, CA. pp. 2332.CrossRefGoogle Scholar
Curien, P.-L. (2005) Introduction to linear logic and ludics, part I. Corr abs/cs/0501035. Accessed October 17, 2013. Available at: http://arxiv.org/abs/cs/0501035.Google Scholar
Damas, L. & Milner, R. (1982) Principal type-schemes for functional programs. In Conference Record of the Ninth Annual ACM Symposium on Principles of Programming Languages, Albuquerque, NM, January 1982, DeMillo, R. A. (ed). New York, NY: ACM Press, pp. 207212.Google Scholar
David, R., Grygiel, K., Kozik, J., Raffalli, C., Theyssier, G. & Zaionc, M. (2013) Asymptotically almost all λ-terms are strongly normalizing. Log. Meth. Comput. Sci. 9, 130.CrossRefGoogle Scholar
de Bruijn, N. (1972) Lambda calculus notation with nameless dummies, a tool for automatic formula manipulation, with application to the Church-Rosser theorem. Indagat. Math. 34 (5), 381392.CrossRefGoogle Scholar
Duregård, J., Jansson, P. & Wang, M. (2012) Feat: Functional enumeration of algebraic types. In Proceedings of the 5th ACM SIGPLAN Symposium on Haskell (Haskell 2012), Copenhagen, Denmark, 13 September, Voigtländer, J. (ed). New York, NY: ACM, pp. 6172.Google Scholar
Flajolet, P. & Sedgewick, R. (2008) Analytic Combinatorics. Cambridge, UK: Cambridge University Press.Google Scholar
Gallier, J. & Snyder, W. (1989) Complete sets of transformations for general E-unification. Theoret. Comput. Sci. 67 (2–3), 203260.CrossRefGoogle Scholar
Graham, R. L., Knuth, D. E. & Patashnik, O. (1989) Concrete Mathematics. Reading, MA: Addison-Wesley.Google Scholar
Hindley, J. R. (2008) M. H. Newman's typability algorithm for lambda-calculus. J. Log. Comput. 18 (2), 229238.CrossRefGoogle Scholar
Jouannaud, J.-P., & Kirchner, C. (1991) Solving equations in abstract algebras: A rule-based survey of unification. In Computational Logic. Essays in Honor of Alan Robinson, Chap. 8, Lassez, J.-L. & Plotkin, G. (eds). Cambridge, MA: MIT Press, pp. 257321.Google Scholar
Kennedy, A. J. & Vytiniotis, D. (2012) Every bit counts: The binary representation of typed data and programs. J. Funct. Program. 22 (4–5), 529573.CrossRefGoogle Scholar
Knuth, D. E. (2006) The Art of Computer Programming, Generating All Trees-History of Combinatorial Generation, Vol. 4 (fascicle 4). Reading, MA: Addison-Wesley.Google Scholar
Lang, W. (2002) On polynomials related to derivatives of the generative functions of the Catalan numbers. Fibonacci Q. 40 (4), 299313.Google Scholar
Lescanne, P. (1994) From λσ to λυ, a journey through calculi of explicit substitutions. In Proceedings of the 21st Annual ACM Symposium on Principles of Programming Languages, Portland, OR, Boehm, H. (ed). New York, NY: ACM, pp. 6069.Google Scholar
Lescanne, P. (2013) On counting untyped lambda terms. Theor. Comput. Sci. 474, 8097.CrossRefGoogle Scholar
Li, M. & Vitányi, P. (1997) An Introduction to Kolmogorov Complexity and Its Applications, 2nd ed. Secaucus, NJ: Springer-Verlag.CrossRefGoogle Scholar
Newman, M. H. A. (1943) Stratified systems of logic. Proc. Camb. Phil. Soc. 39, 6983.CrossRefGoogle Scholar
Pałka, M. (2012, May) Testing an Optimising Compiler by Generating Random Lambda Terms. Technical Report, Department of Computer Science and Engineering, Chalmers University of Technology and Göteborg University, Gothenburg, Sweden (Licentiatavhandling).Google Scholar
Pałka, M. H., Claessen, K., Russo, A. & Hughes, J. (2011) Testing an optimising compiler by generating random lambda terms. In Proceedings of the 6th International Workshop on Automation of Software Test (AST'11). New York, NY: ACM, pp. 9197.CrossRefGoogle Scholar
Rodriguez, Yakushev A. & Jeuring, J. (2009) Enumerating well-typed terms generically. In Third International Workshop, AAIP, Edinburgh, UK, September 4, Schmid, U., Kitzelmann, E. & Plasmeijer, R. (eds), Lecture Notes in Computer Science, vol. 5812. New York, NY: Springer, pp. 93116.Google Scholar
Stein, W.et al. (2012) Sage Mathematics Software (Version 4.8) (The Sage Development Team). Available at: http://www.sagemath.org. Accessed October 17, 2013.Google Scholar
The On-Line Encyclopedia of Integer Sequences (OEIS)® Wiki. (2013) Ranking and Unranking Functions. Available at: https://oeis.org/wiki/Ranking_and_unranking_functions. Accessed June 18, 2013.Google Scholar
Tromp, J. (2006) Binary lambda calculus and combinatory logic. In Kolmogorov Complexity and Applications, Hutter, M., Merkle, W. & Vitányi, P. M. B. (eds), Dagstuhl Seminar Proceedings, vol. 06051. Schloss Dagstuhl, Germany: Internationales Begegnungs- und Forschungszentrum fuer Informatik (IBFI). Available at http://drops.dagstuhl.de/opus/volltexte/2006/628/. Accessed October 17, 2013.Google Scholar
Wang, J. (2004, May) The Efficient Generation of Random Programs and Their Applications, MPhil thesis, Honors Thesis, Wellesley College, Wellesley, MA.Google Scholar
Wang, J. (2005) Generating Random Lambda Calculus Terms. Citeseer. Available at: http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.95.2624. Accessed October 17, 2013.Google Scholar
Yang, X., Chen, Y., Eide, E. & Regehr, J. (2011) Finding and understanding bugs in C compilers. In Proceedings of the 32nd ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI 2011), San Jose, CA, June 4–8, Hall, M. W. & Padua, D. A. (eds). New York, NY: ACM, pp. 283294.Google Scholar
Submit a response

Discussions

No Discussions have been published for this article.

Full text views

Full text views reflects PDF downloads, PDFs sent to Google Drive, Dropbox and Kindle and HTML full text views.

Total number of HTML views: 0
Total number of PDF views: 59 *
View data table for this chart

* Views captured on Cambridge Core between September 2016 - 26th February 2021. This data will be updated every 24 hours.

Send article to Kindle

To send this article to your Kindle, first ensure no-reply@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about sending to your Kindle. Find out more about sending to your Kindle.

Note you can select to send to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be sent to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

Counting and generating lambda terms
Available formats
×

Send article to Dropbox

To send this article to your Dropbox account, please select one or more formats and confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your <service> account. Find out more about sending content to Dropbox.

Counting and generating lambda terms
Available formats
×

Send article to Google Drive

To send this article to your Google Drive account, please select one or more formats and confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your <service> account. Find out more about sending content to Google Drive.

Counting and generating lambda terms
Available formats
×
×

Reply to: Submit a response


Your details


Conflicting interests

Do you have any conflicting interests? *