Counting and generating lambda terms - ENS de Lyon - École normale supérieure de Lyon
Pré-Publication, Document De Travail Année : 2012

Counting and generating lambda terms

Résumé

Lambda calculus is the basis of functional programming and higher order proof assistants. However, few is known about combinatorial properties of lambda terms, in particular, about their asymptotic distribution and random generation. Among others, this paper tries to answer questions like: How many terms of a given size are there? What is a ''typical'' structure of a simply typed 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 afore-mentioned problems may be later extended to any language with bounded 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 computer algebra software, able to handle huge numbers efficiently. Thanks to de Bruijn indices, we provide formulas for the number of closed lambda terms of a given size and show their relevance to recursively defined integer polynomials. Knowledge on the asymptotic behavior of the polynomial coefficients suggests the approach toward the problem of the asymptotic behavior of numbers of closed lambda terms. Indeed, this problem is unamenable to standard generating function methods due to the unusual form of the recurrences. As a by-product of the counting formulas, we design an algorithm for generating lambda 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 typed terms among all terms? (Very small!) How are simply typed lambda terms distributed among all lambda terms? (A~typed term almost always starts with an abstraction.)
Fichier principal
Vignette du fichier
KG_PL_Counting_Lambdas.pdf (506.1 Ko) Télécharger le fichier
Origine Fichiers produits par l'(les) auteur(s)

Dates et versions

ensl-00740034 , version 1 (09-10-2012)
ensl-00740034 , version 2 (14-12-2012)
ensl-00740034 , version 3 (06-01-2013)
ensl-00740034 , version 4 (04-02-2013)
ensl-00740034 , version 5 (11-04-2013)
ensl-00740034 , version 6 (24-04-2013)
ensl-00740034 , version 7 (03-07-2013)

Identifiants

Citer

Katarzyna Grygiel, Pierre Lescanne. Counting and generating lambda terms. 2012. ⟨ensl-00740034v4⟩
286 Consultations
810 Téléchargements

Altmetric

Partager

More