Generating Random Lambda Calculus Terms

We explore the problem of generating lambda calculus terms of a given size uniformly at random. This work has several motivations. First, through performing statistical sampling experiments with randomly generated terms, we can study interesting properties of lambda calculus terms. Second, random lambda calculus terms can serve as inputs to program analysis algorithms such as type inference algorithms to evaluate both their performance and correctness. In this report, we present an algorithm (implemented in OCaml) that generates a random lambda calculus term of a given size, assuming a uniform distribution over all terms of a given size. To improve the efficiency of generating a term, the current algorithm makes use of memoization techniques and also employs a system of number representation that represents numbers approximately. In addition, we also present some of the possible applications for such a tool along with some preliminary results.