<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="fr">
	<id>http://os-vps418.infomaniak.ch:1250/mediawiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Ren%C3%A9+David</id>
	<title>Wiki du LAMA (UMR 5127) - Contributions [fr]</title>
	<link rel="self" type="application/atom+xml" href="http://os-vps418.infomaniak.ch:1250/mediawiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Ren%C3%A9+David"/>
	<link rel="alternate" type="text/html" href="http://os-vps418.infomaniak.ch:1250/mediawiki/index.php/Sp%C3%A9cial:Contributions/Ren%C3%A9_David"/>
	<updated>2026-05-21T08:01:25Z</updated>
	<subtitle>Contributions</subtitle>
	<generator>MediaWiki 1.39.4</generator>
	<entry>
		<id>http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2751</id>
		<title>Lambda counting</title>
		<link rel="alternate" type="text/html" href="http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2751"/>
		<updated>2008-10-22T09:06:23Z</updated>

		<summary type="html">&lt;p&gt;René David : /* combinatory logic */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This paper addresses the following question. Having a&lt;br /&gt;
(theoretical) programming language and a property, what is the&lt;br /&gt;
probability that a random program satisfies the given property ?&lt;br /&gt;
In particular, is it the case that almost every random program&lt;br /&gt;
satisfies the desired property i.e. the probability is 1 ? We consider,  &lt;br /&gt;
in this introduction,   that this notion of&lt;br /&gt;
probability is, at least intuitively, sufficiently clear  but, of&lt;br /&gt;
course, this will have to be made precise.&lt;br /&gt;
&lt;br /&gt;
This&lt;br /&gt;
kind of question has some known results for Turing machines and&lt;br /&gt;
cellular automata. Some of them will be given in section ??.&lt;br /&gt;
We will concentrate here on functional programming&lt;br /&gt;
languages and, more specifically, on  the lambda calculus, the&lt;br /&gt;
simplest such language. Various properties can be studied. Some&lt;br /&gt;
concern the structure of a term, some concern its behaviour.&lt;br /&gt;
&lt;br /&gt;
The first question for which it would be desirable to have an&lt;br /&gt;
answer is the following: give a &amp;quot;simple&amp;quot; equivalent for the number&lt;br /&gt;
of terms of size n. This question is, at present and as far as we&lt;br /&gt;
know, unsolved and the usual technics of generating functions does&lt;br /&gt;
not work. See section ??? for more details. We give here upper and&lt;br /&gt;
lower bounds for this number. This estimation will be enough for&lt;br /&gt;
our purpose but the gap between the lower and the upper bound is&lt;br /&gt;
to big to hope to find an equivalent.&lt;br /&gt;
&lt;br /&gt;
For other questions, some experiments have already been done  (see&lt;br /&gt;
for example ...) which clearly indicates the desired result. For&lt;br /&gt;
example, they &amp;quot;show&amp;quot; that almost every closed lambda term begins&lt;br /&gt;
with a &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; but, as far as we know, there was no&lt;br /&gt;
&amp;quot;proved&amp;quot; result of this form.&lt;br /&gt;
&lt;br /&gt;
This paper proves some  non trivial results on the structural form&lt;br /&gt;
of a lambda term. In particular we show that almost every closed&lt;br /&gt;
lambda term begins with &amp;quot;many&amp;quot; &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; (the precise&lt;br /&gt;
meaning of this is given in theorem ??), that they bound &amp;quot;many&amp;quot;&lt;br /&gt;
occurrences of the corresponding variables (theorem ??) and that,&lt;br /&gt;
given any fixed closed term, &#039;&#039;almost no&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt;-term has this term as a sub-term (theorem&lt;br /&gt;
??).&lt;br /&gt;
&lt;br /&gt;
Our original motivation was to consider the property of being&lt;br /&gt;
terminating. Is a random term strongly normalizable (SN for short)&lt;br /&gt;
i.e. every sequence of reduction terminates ? This question is, at&lt;br /&gt;
present, unsolved and  the experiments we have done do not even&lt;br /&gt;
give an idea of what the result should be. It is known that being&lt;br /&gt;
SN is an undecidable question and it is thus not easy to count the&lt;br /&gt;
number of SN terms of big size. It is clear that having&lt;br /&gt;
&amp;lt;math&amp;gt;(\delta \ \delta)&amp;lt;/math&amp;gt; as a sub-term is a sufficient (but&lt;br /&gt;
not necessary) condition for being non SN but as the experiments&lt;br /&gt;
have shown (and as we have proved) almost no terms contains&lt;br /&gt;
&amp;lt;math&amp;gt;(\delta \ \delta)&amp;lt;/math&amp;gt;  and this is thus useless to have a&lt;br /&gt;
result for non SN. On the opposite direction, it is known that, if&lt;br /&gt;
a term t is not SN, then a pattern &amp;quot;looking like&amp;quot; &lt;br /&gt;
&amp;lt;math&amp;gt;(\delta \ \delta)&amp;lt;/math&amp;gt; (the precise meaning will be given in section ??)&lt;br /&gt;
must appear in t but the experiments seem to show that almost&lt;br /&gt;
every term possesses this pattern (actually, we have not been able&lt;br /&gt;
to count for big enough terms to have a clear idea of the&lt;br /&gt;
probability of possessing the desired pattern). But, again, this experimental result would be of no use to guess the result.&lt;br /&gt;
&lt;br /&gt;
Another question, which is also undecidable, and for which finding&lt;br /&gt;
the probability seems to be even more difficult, is to get the&lt;br /&gt;
probability of being weakly normalizable i.e. there is a sequence&lt;br /&gt;
of reduction that terminates.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Combinatory logic is another programming language  related to the&lt;br /&gt;
lambda calculus. It is a way of coding lambda terms without using&lt;br /&gt;
bound variables. The coding is fair for the questions we are&lt;br /&gt;
concerned with, in the sense that there are translations in both&lt;br /&gt;
directions which, for example, preserve the property of being SN.&lt;br /&gt;
We have also studied this language and, surprisingly, the results&lt;br /&gt;
are very different from those for the lambda calculus. For example&lt;br /&gt;
we show that, for every fixed term t_0,  almost every term possess&lt;br /&gt;
t_0 as a sub-term and this of course implies that almost every&lt;br /&gt;
term is non SN. Note that the increase of size in the translation&lt;br /&gt;
from the lambda calculus to combinatory logic is not known (we&lt;br /&gt;
only have a lower bound) and thus results for combinatory logic&lt;br /&gt;
cannot be used to get results for the lambda calculus.&lt;br /&gt;
&lt;br /&gt;
The organization of the paper is as follows. Section ?? briefly&lt;br /&gt;
recalls known results for Turing machines and cellular automata.&lt;br /&gt;
Section ?? shows that, in combinatory logic, every fixed term&lt;br /&gt;
appears in almost every term. In section ?? we recall the basic&lt;br /&gt;
definitions of the lambda calculus and we discuss the various&lt;br /&gt;
possibilities for counting the size of a term and the probability&lt;br /&gt;
measure we put on sets of terms. Section ?? gives the&lt;br /&gt;
combinatorial results we will need in our proofs and, in&lt;br /&gt;
particular, the lower and upper bounds for the number of terms of&lt;br /&gt;
size n. It also introduces Catalan and Motzkin numbers and the&lt;br /&gt;
so-called Lambert function. Our main results, i.e. theorems ??, ??&lt;br /&gt;
and ?? appear in section ?? Section ?? gives experimental results&lt;br /&gt;
for questions for which we have no proof. Finally, section ???&lt;br /&gt;
gives open questions and future work. The detailed proofs are&lt;br /&gt;
given in an appendix.&lt;br /&gt;
&lt;br /&gt;
== Known results for Turing machines and cellular automata ==&lt;br /&gt;
&lt;br /&gt;
== Lambert function, Catalan and Motzkin numbers ==&lt;br /&gt;
&lt;br /&gt;
=== Catalan numbers ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; : Catalan numbers &lt;br /&gt;
&lt;br /&gt;
Usual equivalent: &amp;lt;math&amp;gt;C(n) \sim \frac{4^n}{n^{3/2}\sqrt{\pi}}&amp;lt;/math&amp;gt; which is obtained using Strirling formula.&lt;br /&gt;
However, using stirling series: &amp;lt;math&amp;gt;&lt;br /&gt;
  n!=\sqrt{2\pi n}\left({n\over e}\right)^n&lt;br /&gt;
  \left(&lt;br /&gt;
   1&lt;br /&gt;
   +{1\over12n}&lt;br /&gt;
   +{1\over288n^2}&lt;br /&gt;
   -{139\over51840n^3}&lt;br /&gt;
   -{571\over2488320n^4}&lt;br /&gt;
   + \cdots&lt;br /&gt;
  \right)&lt;br /&gt;
 &amp;lt;/math&amp;gt;, we get that for &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; we have &amp;lt;math&amp;gt;\sqrt{2\pi n}\left({n\over e}\right)^n \leq n! \leq \frac{7}{6}\sqrt{2\pi n}\left({n\over e}\right)^n&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, using this and &amp;lt;math&amp;gt;\left(\frac{n}{n+1}\right)^{n} &amp;gt; e^{-1}&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C(n) = \frac{(2n)!}{(n+1)!n!} \geq \frac{36}{49\sqrt{\pi}} \frac{4^n}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; but also for &amp;lt;math&amp;gt;n=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Motzkin numbers===&lt;br /&gt;
&lt;br /&gt;
Let us define &amp;lt;math&amp;gt;M(n,k)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; leafs. We get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n,k) = \frac{(n+k-1)!}{(n-k+1)!(k-1)!k!}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, by summing we define &amp;lt;math&amp;gt;M(n)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and give an equivalent:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n) = \sum_{k=0}^n M(n,k) \sim \left(\frac{1}{3-2\sqrt{2}}\right)^n \frac{1}{n^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lambert W function===&lt;br /&gt;
&lt;br /&gt;
The Lambert function &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; is defined by the equation &amp;lt;math&amp;gt;x = W(x) e ^ {W(x)} &amp;lt;/math&amp;gt;&lt;br /&gt;
which has a unique solution in &amp;lt;math&amp;gt;\mathbb{R}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;x \geq e&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x)&amp;lt;/math&amp;gt; which implies that &lt;br /&gt;
&amp;lt;math&amp;gt;W(x) \sim \ln(x)&amp;lt;/math&amp;gt; near &amp;lt;math&amp;gt;+\infty&amp;lt;/math&amp;gt;. To prove this, it is enough to remark that&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;(\ln(x) - \ln(\ln(x))e^{\ln(x)-\ln(\ln(x))} = x \left(1 - \frac{\ln(\ln(x))}{\ln(x)}\right) \leq x \leq x \ln(x) = \ln(x) e^{\ln(x)} &amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is not precise enough for our purpose. Using one step of the Newton method from &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt;, we can find a better upper bound for &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; because &amp;lt;math&amp;gt;y \mapsto y e^y&amp;lt;/math&amp;gt; is increasing and convex. This gives:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, if we define &amp;lt;math&amp;gt;f(y) = y e^y&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;f&#039;(y)=(1+y)e^y&amp;lt;/math&amp;gt; and therefore, newton&#039;s method from &amp;lt;math&amp;gt;A = \ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt; gives a point at position:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;&lt;br /&gt;
A - \frac{f(A) - x}{f&#039;(A)} &lt;br /&gt;
  = A +  \frac{x \ln(\ln(x))}{\ln(x)} \frac{\ln(x)}{x(\ln(x) - \ln(\ln(x)) + 1)}&lt;br /&gt;
  = A +  \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1} &lt;br /&gt;
&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, we show that for &amp;lt;math&amp;gt;x\geq e&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + 1&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, for &amp;lt;math&amp;gt;x &amp;gt; 1&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;e^{\sqrt{ex}} \geq 1 + \sqrt{ex} + \frac{ex}{2} \geq x&amp;lt;/math&amp;gt;, which implies&lt;br /&gt;
&amp;lt;math&amp;gt;ex \geq \ln^2(x)&amp;lt;/math&amp;gt; and therefore &amp;lt;math&amp;gt;\ln(x) - \ln\ln(x) + 1 \geq \ln\ln(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==  combinatory logic ==&lt;br /&gt;
&lt;br /&gt;
Basically the paper already written by Marek&lt;br /&gt;
&lt;br /&gt;
tex file : [http://www.lama.univ-savoie.fr/~david/ftp/CL.tex]&lt;br /&gt;
&lt;br /&gt;
pdf file :[http://www.lama.univ-savoie.fr/~david/ftp/CL.pdf]&lt;br /&gt;
&lt;br /&gt;
+ the following&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As we will see in section ??, theorem ?? does not holds for the Lambda calculus. This may be surprising since there are translations between these systems which respect many properties (for exemple the one of being terminating). However these translations do not preserve the size. &lt;br /&gt;
&lt;br /&gt;
The translation T from combinatory logic to lambda calculus is linear, i.e. there is a constant k such that, for all terms, &amp;lt;math&amp;gt;size(T(t) \leq k.size(t)&amp;lt;/math&amp;gt; but the translation T&#039; in the other direction is not linear. As far as we know, there is no known bound on the size of T&#039;(t) but it is not difficult to find exemples where size(T&#039;(t)) is of order &amp;lt;math&amp;gt;size(t)^3&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The point is that T&#039; has to code the binding in some way and this takes place. It will be interesting to compare the size of T&#039;(t) with the one of t using other notion of size than the usual one. See section ?? for some complement.&lt;br /&gt;
&lt;br /&gt;
== Generality on lambda calculus ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition &lt;br /&gt;
&lt;br /&gt;
The set &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt; of lambda terms (or,&lt;br /&gt;
simply, terms) is defined by the following grammar&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;t, u  := Var \ \mid \ \lambda x.t \ \mid \ (t \ u)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To be able to define the notion of a &#039;&#039;random&#039;&#039; term we&lt;br /&gt;
have to define a distribution law on &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt;. There are many&lt;br /&gt;
possibilities for that. We choose here the simplest one. Note that this is the one for which, at least at present,  we are&lt;br /&gt;
able to prove some results. It is based on densities. For that we&lt;br /&gt;
first have to define the &#039;&#039;size&#039;&#039; of a term.&lt;br /&gt;
&lt;br /&gt;
The usual&lt;br /&gt;
definition is the following.&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
The size (denoted as &amp;lt;math&amp;gt;size_1(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
rules.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(\lambda x.t)=size_1(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1((t \ u))=size_1(t)+size_1(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the rest of the paper we will use another definition (denoted&lt;br /&gt;
as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt;) which is similar but  gives simpler computations.&lt;br /&gt;
We believe (but we have not yet checked the details) that, with&lt;br /&gt;
&amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt; we would have similar results. The&lt;br /&gt;
computation, with &amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt;,  of the upper and lower&lt;br /&gt;
bounds of the number of terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; will be done&lt;br /&gt;
in section ??&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
The size (denoted as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt; or, more simply &amp;lt;math&amp;gt;size(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
rules.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(\lambda x.t)=size_0(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0((t \ u))=size_0(t)+size_0(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These definitions of the size are, for the implementation point of&lt;br /&gt;
view, not realistic because, in case a term has a lot of distinct&lt;br /&gt;
variables, it is not realistic to use a single bit to code them.&lt;br /&gt;
The usual way to implement this coding is to replace the names of&lt;br /&gt;
variables by  their so called de Bruijn indices: a variable is&lt;br /&gt;
replaced by the number of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; that occur, on the&lt;br /&gt;
path from the variable to the root, between the variable and the&lt;br /&gt;
&amp;lt;math&amp;gt;lambda&amp;lt;/math&amp;gt; that binds it. Note that, in this case,&lt;br /&gt;
different occurrences of the same variable may be represented by&lt;br /&gt;
different indices.&lt;br /&gt;
&lt;br /&gt;
Choosing the way we code these de Bruijn indices gives different&lt;br /&gt;
other ways of defining the size of a term. This can be done in the&lt;br /&gt;
following ways&lt;br /&gt;
&lt;br /&gt;
- Use unary notation, i.e. the size of the index &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;&lt;br /&gt;
simply is &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; itself&lt;br /&gt;
&lt;br /&gt;
- Use optimal binary notation, i.e. the size of the index&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;log_2(n)&amp;lt;/math&amp;gt; i.e. the logarithm of&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; in base 2.&lt;br /&gt;
&lt;br /&gt;
- Use uniform binary notation, i.e. the size of an index is the&lt;br /&gt;
logarithm, in base 2, of the number of leaves of the term.&lt;br /&gt;
&lt;br /&gt;
Remark&lt;br /&gt;
&lt;br /&gt;
See section ?? for a discusion about these different size.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; be an integer. We denote by &amp;lt;math&amp;gt;\Lambda_n&amp;lt;/math&amp;gt; the set of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; terms of size n.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let A be a set of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; terms. &lt;br /&gt;
&lt;br /&gt;
1) We denote by &amp;lt;math&amp;gt;\#(A)&amp;lt;/math&amp;gt; the cardinality of A.&lt;br /&gt;
&lt;br /&gt;
2) We denote by &amp;lt;math&amp;gt;d(A)&amp;lt;/math&amp;gt; the limit, for n going to &amp;lt;math&amp;gt;\infty&amp;lt;/math&amp;gt;, &lt;br /&gt;
of &amp;lt;math&amp;gt;\frac{\#(A\cap \Lambda_n)}{\#(\Lambda_n)}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Remark&lt;br /&gt;
&lt;br /&gt;
Note that d is not exactly a measure since &amp;lt;math&amp;gt;d(A)&amp;lt;/math&amp;gt; is undefined if the previous limit does not exist&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let P be a property of terms. We will say that almost every term satisfies P &lt;br /&gt;
(this will be also stated as P holds a.e.) if&lt;br /&gt;
&amp;lt;math&amp;gt;d(\{t \ | \ P(t) holds\})=1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== generating functions ==&lt;br /&gt;
&lt;br /&gt;
this does not work (by now) because radius of convergence 0&lt;br /&gt;
&lt;br /&gt;
no known results for the number of terms of size n (denoted &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
== our results ==&lt;br /&gt;
&lt;br /&gt;
(the proof of result of section k needs the result of section (k-1))&lt;br /&gt;
&lt;br /&gt;
=== Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
For the lower bound, we will first count the number &amp;lt;math&amp;gt;LB(n,k)&amp;lt;/math&amp;gt; of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; starting with &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas and having no other lambda below. This means that the lower part of the term is a binary tree of size &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; with&lt;br /&gt;
&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; possibility for each leaf. Therefore we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) = C(n-k) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And therefore, for &amp;lt;math&amp;gt;n &amp;gt; k&amp;lt;/math&amp;gt;, using our lower bound for &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n + 1 \geq n - k + 1&amp;lt;/math&amp;gt;, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) \geq K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;K=\frac{36}{49\sqrt{\pi}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed, we define &amp;lt;math&amp;gt;f(\alpha) = \left(4n\alpha\right)^{n(1-\alpha) + 1}&amp;lt;/math&amp;gt; (so &amp;lt;math&amp;gt;LB(n,k) \geq \frac{K}{(n+1)^\frac{3}{2}} f\left(\frac{k}{n}\right)&amp;lt;/math&amp;gt;) and look for the maximum of this function. We have &amp;lt;math&amp;gt;f&#039;(\alpha) = f(\alpha) \left(-n\ln(4n\alpha) +\frac{n(1-\alpha) + 1}{\alpha}\right)&amp;lt;/math&amp;gt;. Thus, &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\frac{n+1}{n\alpha}e^{\frac{n+1}{n\alpha}}\geq 4e(n+1)&amp;lt;/math&amp;gt;. The Lambert function begin increasing this means that &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\alpha \leq \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;f(\alpha)&amp;lt;/math&amp;gt; reaches a maximum for &amp;lt;math&amp;gt;\alpha = \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This means that &amp;lt;math&amp;gt;(4k)^{n-k}&amp;lt;/math&amp;gt; reaches its maximum for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed when &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;&lt;br /&gt;
is near to &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; which is likely not to be an integer. However, there are at least &amp;lt;math&amp;gt;\left\lfloor \frac{n (\ln(\ln(4en)) - 1)}{\ln^2(4en)}\right\rfloor&amp;lt;/math&amp;gt; integer between &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\frac{n+1}{\ln(4e(n+1))}&amp;lt;/math&amp;gt;. Indeed, using our inequalities on Lambert W function, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}-\frac{n+1}{\ln(4e(n+1))} = \frac{(n+1) (\ln(4e(n+1)) - W(4e(n+1)))}{W(4e(n+1))\ln(4e(n+1))} \geq \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, we get the following lowerbound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \sum_{k=1}^{n} LB(n,k) \geq \sum_{k=\lceil\frac{n+1}{\ln(4e(n+1))}\rceil}^{\lfloor\frac{n+1}{W(4e(n+1))}\rfloor} K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}} \geq K \left\lfloor \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}\right\rfloor \frac{\left(\frac{4(n+1)}{\ln(4e(n+1))}\right)^{n-\frac{n+1}{\ln(4e(n+1))}+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To simplify, using the fact that &amp;lt;math&amp;gt;\lim_{n\to +\infty}\left(\frac{\ln(n)}{\ln(4en)}\right)^n = 0&amp;lt;/math&amp;gt; and taking &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; large enough, we have the following lowerbound:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \frac{\sqrt{n}}{\ln^3(n)}\left(\frac{4n}{\ln(n)}\right)^{n-\frac{n}{\ln(n)}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We now compute an upper bound &amp;lt;math&amp;gt;UB(n,k)&amp;lt;/math&amp;gt; for the number of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with exactly &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas (that is with &amp;lt;math&amp;gt;n - k + 1&amp;lt;/math&amp;gt; leaves using the Motzkin numbers and allowing any lambda to bind any variable (regardless of the real scope):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;UB(n,k) = M(n,n-k+1) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we sum this for all possible &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and get an upper bound of &amp;lt;math&amp;gt;k^{n-k+1}&amp;lt;/math&amp;gt; using Lambert function as for the lower bound, we get the following upper bound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \leq M(n) \left(\frac{n+1}{W(e(n+1))}\right)^{n-\frac{n+1}{W(e(n+1))} + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The ration between our upper bound and lower bound is equivalent to (NEEDS FURTHER CHECKING):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\left(\frac{1}{4(3-2\sqrt{2})}\right)^n\frac{\ln^3(n)}{n^2} \simeq 1.46^n\frac{\ln^3(n)}{n^2}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== upper and lower bounds for number of lambdas in a term of size n ===&lt;br /&gt;
&lt;br /&gt;
=== Jakub&#039;s trik : at least 1 lambda in head position ===&lt;br /&gt;
&lt;br /&gt;
=== at least &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; lambdas in head position and number of lambdas in one path ===&lt;br /&gt;
&lt;br /&gt;
Remark: (may be 4) can be done directly without 3))&lt;br /&gt;
&lt;br /&gt;
=== each of the  &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; head lambdas really bind &amp;quot;many&amp;quot;  occurrences of the variable ===&lt;br /&gt;
&lt;br /&gt;
=== every fixed closed term (including the identity !) does not appear in a random term (in fact we have much more than that) ===&lt;br /&gt;
&lt;br /&gt;
comment : so different situation in combinatory logic and lambda calculus ; the coding uses a big size so need to count variables in a different way&lt;br /&gt;
&lt;br /&gt;
== Experiments ==&lt;br /&gt;
&lt;br /&gt;
results of the experiments we have done&lt;br /&gt;
&lt;br /&gt;
some experiments that have to be done : e.g. density of terms having &amp;lt;math&amp;gt;\lambda x.y&amp;lt;/math&amp;gt; or big Omega pattern ...&lt;br /&gt;
&lt;br /&gt;
== to be done ==&lt;br /&gt;
&lt;br /&gt;
Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; with other size for variables especially one, binary with fixed size&lt;br /&gt;
&lt;br /&gt;
== Open questions and Future work ==&lt;br /&gt;
&lt;br /&gt;
.....&lt;/div&gt;</summary>
		<author><name>René David</name></author>
	</entry>
	<entry>
		<id>http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2750</id>
		<title>Lambda counting</title>
		<link rel="alternate" type="text/html" href="http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2750"/>
		<updated>2008-10-22T08:52:18Z</updated>

		<summary type="html">&lt;p&gt;René David : /* combinatory logic */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This paper addresses the following question. Having a&lt;br /&gt;
(theoretical) programming language and a property, what is the&lt;br /&gt;
probability that a random program satisfies the given property ?&lt;br /&gt;
In particular, is it the case that almost every random program&lt;br /&gt;
satisfies the desired property i.e. the probability is 1 ? We consider,  &lt;br /&gt;
in this introduction,   that this notion of&lt;br /&gt;
probability is, at least intuitively, sufficiently clear  but, of&lt;br /&gt;
course, this will have to be made precise.&lt;br /&gt;
&lt;br /&gt;
This&lt;br /&gt;
kind of question has some known results for Turing machines and&lt;br /&gt;
cellular automata. Some of them will be given in section ??.&lt;br /&gt;
We will concentrate here on functional programming&lt;br /&gt;
languages and, more specifically, on  the lambda calculus, the&lt;br /&gt;
simplest such language. Various properties can be studied. Some&lt;br /&gt;
concern the structure of a term, some concern its behaviour.&lt;br /&gt;
&lt;br /&gt;
The first question for which it would be desirable to have an&lt;br /&gt;
answer is the following: give a &amp;quot;simple&amp;quot; equivalent for the number&lt;br /&gt;
of terms of size n. This question is, at present and as far as we&lt;br /&gt;
know, unsolved and the usual technics of generating functions does&lt;br /&gt;
not work. See section ??? for more details. We give here upper and&lt;br /&gt;
lower bounds for this number. This estimation will be enough for&lt;br /&gt;
our purpose but the gap between the lower and the upper bound is&lt;br /&gt;
to big to hope to find an equivalent.&lt;br /&gt;
&lt;br /&gt;
For other questions, some experiments have already been done  (see&lt;br /&gt;
for example ...) which clearly indicates the desired result. For&lt;br /&gt;
example, they &amp;quot;show&amp;quot; that almost every closed lambda term begins&lt;br /&gt;
with a &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; but, as far as we know, there was no&lt;br /&gt;
&amp;quot;proved&amp;quot; result of this form.&lt;br /&gt;
&lt;br /&gt;
This paper proves some  non trivial results on the structural form&lt;br /&gt;
of a lambda term. In particular we show that almost every closed&lt;br /&gt;
lambda term begins with &amp;quot;many&amp;quot; &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; (the precise&lt;br /&gt;
meaning of this is given in theorem ??), that they bound &amp;quot;many&amp;quot;&lt;br /&gt;
occurrences of the corresponding variables (theorem ??) and that,&lt;br /&gt;
given any fixed closed term, &#039;&#039;almost no&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt;-term has this term as a sub-term (theorem&lt;br /&gt;
??).&lt;br /&gt;
&lt;br /&gt;
Our original motivation was to consider the property of being&lt;br /&gt;
terminating. Is a random term strongly normalizable (SN for short)&lt;br /&gt;
i.e. every sequence of reduction terminates ? This question is, at&lt;br /&gt;
present, unsolved and  the experiments we have done do not even&lt;br /&gt;
give an idea of what the result should be. It is known that being&lt;br /&gt;
SN is an undecidable question and it is thus not easy to count the&lt;br /&gt;
number of SN terms of big size. It is clear that having&lt;br /&gt;
&amp;lt;math&amp;gt;(\delta \ \delta)&amp;lt;/math&amp;gt; as a sub-term is a sufficient (but&lt;br /&gt;
not necessary) condition for being non SN but as the experiments&lt;br /&gt;
have shown (and as we have proved) almost no terms contains&lt;br /&gt;
&amp;lt;math&amp;gt;(\delta \ \delta)&amp;lt;/math&amp;gt;  and this is thus useless to have a&lt;br /&gt;
result for non SN. On the opposite direction, it is known that, if&lt;br /&gt;
a term t is not SN, then a pattern &amp;quot;looking like&amp;quot; &lt;br /&gt;
&amp;lt;math&amp;gt;(\delta \ \delta)&amp;lt;/math&amp;gt; (the precise meaning will be given in section ??)&lt;br /&gt;
must appear in t but the experiments seem to show that almost&lt;br /&gt;
every term possesses this pattern (actually, we have not been able&lt;br /&gt;
to count for big enough terms to have a clear idea of the&lt;br /&gt;
probability of possessing the desired pattern). But, again, this experimental result would be of no use to guess the result.&lt;br /&gt;
&lt;br /&gt;
Another question, which is also undecidable, and for which finding&lt;br /&gt;
the probability seems to be even more difficult, is to get the&lt;br /&gt;
probability of being weakly normalizable i.e. there is a sequence&lt;br /&gt;
of reduction that terminates.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Combinatory logic is another programming language  related to the&lt;br /&gt;
lambda calculus. It is a way of coding lambda terms without using&lt;br /&gt;
bound variables. The coding is fair for the questions we are&lt;br /&gt;
concerned with, in the sense that there are translations in both&lt;br /&gt;
directions which, for example, preserve the property of being SN.&lt;br /&gt;
We have also studied this language and, surprisingly, the results&lt;br /&gt;
are very different from those for the lambda calculus. For example&lt;br /&gt;
we show that, for every fixed term t_0,  almost every term possess&lt;br /&gt;
t_0 as a sub-term and this of course implies that almost every&lt;br /&gt;
term is non SN. Note that the increase of size in the translation&lt;br /&gt;
from the lambda calculus to combinatory logic is not known (we&lt;br /&gt;
only have a lower bound) and thus results for combinatory logic&lt;br /&gt;
cannot be used to get results for the lambda calculus.&lt;br /&gt;
&lt;br /&gt;
The organization of the paper is as follows. Section ?? briefly&lt;br /&gt;
recalls known results for Turing machines and cellular automata.&lt;br /&gt;
Section ?? shows that, in combinatory logic, every fixed term&lt;br /&gt;
appears in almost every term. In section ?? we recall the basic&lt;br /&gt;
definitions of the lambda calculus and we discuss the various&lt;br /&gt;
possibilities for counting the size of a term and the probability&lt;br /&gt;
measure we put on sets of terms. Section ?? gives the&lt;br /&gt;
combinatorial results we will need in our proofs and, in&lt;br /&gt;
particular, the lower and upper bounds for the number of terms of&lt;br /&gt;
size n. It also introduces Catalan and Motzkin numbers and the&lt;br /&gt;
so-called Lambert function. Our main results, i.e. theorems ??, ??&lt;br /&gt;
and ?? appear in section ?? Section ?? gives experimental results&lt;br /&gt;
for questions for which we have no proof. Finally, section ???&lt;br /&gt;
gives open questions and future work. The detailed proofs are&lt;br /&gt;
given in an appendix.&lt;br /&gt;
&lt;br /&gt;
== Known results for Turing machines and cellular automata ==&lt;br /&gt;
&lt;br /&gt;
== Lambert function, Catalan and Motzkin numbers ==&lt;br /&gt;
&lt;br /&gt;
=== Catalan numbers ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; : Catalan numbers &lt;br /&gt;
&lt;br /&gt;
Usual equivalent: &amp;lt;math&amp;gt;C(n) \sim \frac{4^n}{n^{3/2}\sqrt{\pi}}&amp;lt;/math&amp;gt; which is obtained using Strirling formula.&lt;br /&gt;
However, using stirling series: &amp;lt;math&amp;gt;&lt;br /&gt;
  n!=\sqrt{2\pi n}\left({n\over e}\right)^n&lt;br /&gt;
  \left(&lt;br /&gt;
   1&lt;br /&gt;
   +{1\over12n}&lt;br /&gt;
   +{1\over288n^2}&lt;br /&gt;
   -{139\over51840n^3}&lt;br /&gt;
   -{571\over2488320n^4}&lt;br /&gt;
   + \cdots&lt;br /&gt;
  \right)&lt;br /&gt;
 &amp;lt;/math&amp;gt;, we get that for &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; we have &amp;lt;math&amp;gt;\sqrt{2\pi n}\left({n\over e}\right)^n \leq n! \leq \frac{7}{6}\sqrt{2\pi n}\left({n\over e}\right)^n&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, using this and &amp;lt;math&amp;gt;\left(\frac{n}{n+1}\right)^{n} &amp;gt; e^{-1}&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C(n) = \frac{(2n)!}{(n+1)!n!} \geq \frac{36}{49\sqrt{\pi}} \frac{4^n}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; but also for &amp;lt;math&amp;gt;n=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Motzkin numbers===&lt;br /&gt;
&lt;br /&gt;
Let us define &amp;lt;math&amp;gt;M(n,k)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; leafs. We get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n,k) = \frac{(n+k-1)!}{(n-k+1)!(k-1)!k!}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, by summing we define &amp;lt;math&amp;gt;M(n)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and give an equivalent:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n) = \sum_{k=0}^n M(n,k) \sim \left(\frac{1}{3-2\sqrt{2}}\right)^n \frac{1}{n^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lambert W function===&lt;br /&gt;
&lt;br /&gt;
The Lambert function &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; is defined by the equation &amp;lt;math&amp;gt;x = W(x) e ^ {W(x)} &amp;lt;/math&amp;gt;&lt;br /&gt;
which has a unique solution in &amp;lt;math&amp;gt;\mathbb{R}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;x \geq e&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x)&amp;lt;/math&amp;gt; which implies that &lt;br /&gt;
&amp;lt;math&amp;gt;W(x) \sim \ln(x)&amp;lt;/math&amp;gt; near &amp;lt;math&amp;gt;+\infty&amp;lt;/math&amp;gt;. To prove this, it is enough to remark that&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;(\ln(x) - \ln(\ln(x))e^{\ln(x)-\ln(\ln(x))} = x \left(1 - \frac{\ln(\ln(x))}{\ln(x)}\right) \leq x \leq x \ln(x) = \ln(x) e^{\ln(x)} &amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is not precise enough for our purpose. Using one step of the Newton method from &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt;, we can find a better upper bound for &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; because &amp;lt;math&amp;gt;y \mapsto y e^y&amp;lt;/math&amp;gt; is increasing and convex. This gives:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, if we define &amp;lt;math&amp;gt;f(y) = y e^y&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;f&#039;(y)=(1+y)e^y&amp;lt;/math&amp;gt; and therefore, newton&#039;s method from &amp;lt;math&amp;gt;A = \ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt; gives a point at position:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;&lt;br /&gt;
A - \frac{f(A) - x}{f&#039;(A)} &lt;br /&gt;
  = A +  \frac{x \ln(\ln(x))}{\ln(x)} \frac{\ln(x)}{x(\ln(x) - \ln(\ln(x)) + 1)}&lt;br /&gt;
  = A +  \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1} &lt;br /&gt;
&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, we show that for &amp;lt;math&amp;gt;x\geq e&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + 1&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, for &amp;lt;math&amp;gt;x &amp;gt; 1&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;e^{\sqrt{ex}} \geq 1 + \sqrt{ex} + \frac{ex}{2} \geq x&amp;lt;/math&amp;gt;, which implies&lt;br /&gt;
&amp;lt;math&amp;gt;ex \geq \ln^2(x)&amp;lt;/math&amp;gt; and therefore &amp;lt;math&amp;gt;\ln(x) - \ln\ln(x) + 1 \geq \ln\ln(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==  combinatory logic ==&lt;br /&gt;
&lt;br /&gt;
Basically the paper already written by Marek&lt;br /&gt;
&lt;br /&gt;
tex file : [http://www.lama.univ-savoie.fr/~david/ftp/CL.pdf]&lt;br /&gt;
&lt;br /&gt;
pdf file :[http://www.lama.univ-savoie.fr/~david/ftp/CL.pdf]&lt;br /&gt;
&lt;br /&gt;
+ the following&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As we will see in section ??, theorem ?? does not holds for the Lambda calculus. This may be surprising since there are translations between these systems which respect many properties (for exemple the one of being terminating). However these translations do not preserve the size. &lt;br /&gt;
&lt;br /&gt;
The translation T from combinatory logic to lambda calculus is linear, i.e. there is a constant k such that, for all terms, &amp;lt;math&amp;gt;size(T(t) \leq k.size(t)&amp;lt;/math&amp;gt; but the translation T&#039; in the other direction is not linear. As far as we know, there is no known bound on the size of T&#039;(t) but it is not difficult to find exemples where size(T&#039;(t)) is of order &amp;lt;math&amp;gt;size(t)^3&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The point is that T&#039; has to code the binding in some way and this takes place. It will be interesting to compare the size of T&#039;(t) with the one of t using other notion of size than the usual one. See section ?? for some complement.&lt;br /&gt;
&lt;br /&gt;
== Generality on lambda calculus ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition &lt;br /&gt;
&lt;br /&gt;
The set &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt; of lambda terms (or,&lt;br /&gt;
simply, terms) is defined by the following grammar&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;t, u  := Var \ \mid \ \lambda x.t \ \mid \ (t \ u)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To be able to define the notion of a &#039;&#039;random&#039;&#039; term we&lt;br /&gt;
have to define a distribution law on &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt;. There are many&lt;br /&gt;
possibilities for that. We choose here the simplest one. Note that this is the one for which, at least at present,  we are&lt;br /&gt;
able to prove some results. It is based on densities. For that we&lt;br /&gt;
first have to define the &#039;&#039;size&#039;&#039; of a term.&lt;br /&gt;
&lt;br /&gt;
The usual&lt;br /&gt;
definition is the following.&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
The size (denoted as &amp;lt;math&amp;gt;size_1(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
rules.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(\lambda x.t)=size_1(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1((t \ u))=size_1(t)+size_1(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the rest of the paper we will use another definition (denoted&lt;br /&gt;
as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt;) which is similar but  gives simpler computations.&lt;br /&gt;
We believe (but we have not yet checked the details) that, with&lt;br /&gt;
&amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt; we would have similar results. The&lt;br /&gt;
computation, with &amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt;,  of the upper and lower&lt;br /&gt;
bounds of the number of terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; will be done&lt;br /&gt;
in section ??&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
The size (denoted as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt; or, more simply &amp;lt;math&amp;gt;size(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
rules.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(\lambda x.t)=size_0(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0((t \ u))=size_0(t)+size_0(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These definitions of the size are, for the implementation point of&lt;br /&gt;
view, not realistic because, in case a term has a lot of distinct&lt;br /&gt;
variables, it is not realistic to use a single bit to code them.&lt;br /&gt;
The usual way to implement this coding is to replace the names of&lt;br /&gt;
variables by  their so called de Bruijn indices: a variable is&lt;br /&gt;
replaced by the number of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; that occur, on the&lt;br /&gt;
path from the variable to the root, between the variable and the&lt;br /&gt;
&amp;lt;math&amp;gt;lambda&amp;lt;/math&amp;gt; that binds it. Note that, in this case,&lt;br /&gt;
different occurrences of the same variable may be represented by&lt;br /&gt;
different indices.&lt;br /&gt;
&lt;br /&gt;
Choosing the way we code these de Bruijn indices gives different&lt;br /&gt;
other ways of defining the size of a term. This can be done in the&lt;br /&gt;
following ways&lt;br /&gt;
&lt;br /&gt;
- Use unary notation, i.e. the size of the index &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;&lt;br /&gt;
simply is &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; itself&lt;br /&gt;
&lt;br /&gt;
- Use optimal binary notation, i.e. the size of the index&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;log_2(n)&amp;lt;/math&amp;gt; i.e. the logarithm of&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; in base 2.&lt;br /&gt;
&lt;br /&gt;
- Use uniform binary notation, i.e. the size of an index is the&lt;br /&gt;
logarithm, in base 2, of the number of leaves of the term.&lt;br /&gt;
&lt;br /&gt;
Remark&lt;br /&gt;
&lt;br /&gt;
See section ?? for a discusion about these different size.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; be an integer. We denote by &amp;lt;math&amp;gt;\Lambda_n&amp;lt;/math&amp;gt; the set of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; terms of size n.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let A be a set of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; terms. &lt;br /&gt;
&lt;br /&gt;
1) We denote by &amp;lt;math&amp;gt;\#(A)&amp;lt;/math&amp;gt; the cardinality of A.&lt;br /&gt;
&lt;br /&gt;
2) We denote by &amp;lt;math&amp;gt;d(A)&amp;lt;/math&amp;gt; the limit, for n going to &amp;lt;math&amp;gt;\infty&amp;lt;/math&amp;gt;, &lt;br /&gt;
of &amp;lt;math&amp;gt;\frac{\#(A\cap \Lambda_n)}{\#(\Lambda_n)}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Remark&lt;br /&gt;
&lt;br /&gt;
Note that d is not exactly a measure since &amp;lt;math&amp;gt;d(A)&amp;lt;/math&amp;gt; is undefined if the previous limit does not exist&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let P be a property of terms. We will say that almost every term satisfies P &lt;br /&gt;
(this will be also stated as P holds a.e.) if&lt;br /&gt;
&amp;lt;math&amp;gt;d(\{t \ | \ P(t) holds\})=1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== generating functions ==&lt;br /&gt;
&lt;br /&gt;
this does not work (by now) because radius of convergence 0&lt;br /&gt;
&lt;br /&gt;
no known results for the number of terms of size n (denoted &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
== our results ==&lt;br /&gt;
&lt;br /&gt;
(the proof of result of section k needs the result of section (k-1))&lt;br /&gt;
&lt;br /&gt;
=== Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
For the lower bound, we will first count the number &amp;lt;math&amp;gt;LB(n,k)&amp;lt;/math&amp;gt; of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; starting with &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas and having no other lambda below. This means that the lower part of the term is a binary tree of size &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; with&lt;br /&gt;
&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; possibility for each leaf. Therefore we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) = C(n-k) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And therefore, for &amp;lt;math&amp;gt;n &amp;gt; k&amp;lt;/math&amp;gt;, using our lower bound for &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n + 1 \geq n - k + 1&amp;lt;/math&amp;gt;, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) \geq K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;K=\frac{36}{49\sqrt{\pi}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed, we define &amp;lt;math&amp;gt;f(\alpha) = \left(4n\alpha\right)^{n(1-\alpha) + 1}&amp;lt;/math&amp;gt; (so &amp;lt;math&amp;gt;LB(n,k) \geq \frac{K}{(n+1)^\frac{3}{2}} f\left(\frac{k}{n}\right)&amp;lt;/math&amp;gt;) and look for the maximum of this function. We have &amp;lt;math&amp;gt;f&#039;(\alpha) = f(\alpha) \left(-n\ln(4n\alpha) +\frac{n(1-\alpha) + 1}{\alpha}\right)&amp;lt;/math&amp;gt;. Thus, &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\frac{n+1}{n\alpha}e^{\frac{n+1}{n\alpha}}\geq 4e(n+1)&amp;lt;/math&amp;gt;. The Lambert function begin increasing this means that &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\alpha \leq \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;f(\alpha)&amp;lt;/math&amp;gt; reaches a maximum for &amp;lt;math&amp;gt;\alpha = \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This means that &amp;lt;math&amp;gt;(4k)^{n-k}&amp;lt;/math&amp;gt; reaches its maximum for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed when &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;&lt;br /&gt;
is near to &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; which is likely not to be an integer. However, there are at least &amp;lt;math&amp;gt;\left\lfloor \frac{n (\ln(\ln(4en)) - 1)}{\ln^2(4en)}\right\rfloor&amp;lt;/math&amp;gt; integer between &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\frac{n+1}{\ln(4e(n+1))}&amp;lt;/math&amp;gt;. Indeed, using our inequalities on Lambert W function, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}-\frac{n+1}{\ln(4e(n+1))} = \frac{(n+1) (\ln(4e(n+1)) - W(4e(n+1)))}{W(4e(n+1))\ln(4e(n+1))} \geq \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, we get the following lowerbound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \sum_{k=1}^{n} LB(n,k) \geq \sum_{k=\lceil\frac{n+1}{\ln(4e(n+1))}\rceil}^{\lfloor\frac{n+1}{W(4e(n+1))}\rfloor} K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}} \geq K \left\lfloor \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}\right\rfloor \frac{\left(\frac{4(n+1)}{\ln(4e(n+1))}\right)^{n-\frac{n+1}{\ln(4e(n+1))}+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To simplify, using the fact that &amp;lt;math&amp;gt;\lim_{n\to +\infty}\left(\frac{\ln(n)}{\ln(4en)}\right)^n = 0&amp;lt;/math&amp;gt; and taking &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; large enough, we have the following lowerbound:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \frac{\sqrt{n}}{\ln^3(n)}\left(\frac{4n}{\ln(n)}\right)^{n-\frac{n}{\ln(n)}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We now compute an upper bound &amp;lt;math&amp;gt;UB(n,k)&amp;lt;/math&amp;gt; for the number of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with exactly &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas (that is with &amp;lt;math&amp;gt;n - k + 1&amp;lt;/math&amp;gt; leaves using the Motzkin numbers and allowing any lambda to bind any variable (regardless of the real scope):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;UB(n,k) = M(n,n-k+1) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we sum this for all possible &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and get an upper bound of &amp;lt;math&amp;gt;k^{n-k+1}&amp;lt;/math&amp;gt; using Lambert function as for the lower bound, we get the following upper bound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \leq M(n) \left(\frac{n+1}{W(e(n+1))}\right)^{n-\frac{n+1}{W(e(n+1))} + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The ration between our upper bound and lower bound is equivalent to (NEEDS FURTHER CHECKING):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\left(\frac{1}{4(3-2\sqrt{2})}\right)^n\frac{\ln^3(n)}{n^2} \simeq 1.46^n\frac{\ln^3(n)}{n^2}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== upper and lower bounds for number of lambdas in a term of size n ===&lt;br /&gt;
&lt;br /&gt;
=== Jakub&#039;s trik : at least 1 lambda in head position ===&lt;br /&gt;
&lt;br /&gt;
=== at least &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; lambdas in head position and number of lambdas in one path ===&lt;br /&gt;
&lt;br /&gt;
Remark: (may be 4) can be done directly without 3))&lt;br /&gt;
&lt;br /&gt;
=== each of the  &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; head lambdas really bind &amp;quot;many&amp;quot;  occurrences of the variable ===&lt;br /&gt;
&lt;br /&gt;
=== every fixed closed term (including the identity !) does not appear in a random term (in fact we have much more than that) ===&lt;br /&gt;
&lt;br /&gt;
comment : so different situation in combinatory logic and lambda calculus ; the coding uses a big size so need to count variables in a different way&lt;br /&gt;
&lt;br /&gt;
== Experiments ==&lt;br /&gt;
&lt;br /&gt;
results of the experiments we have done&lt;br /&gt;
&lt;br /&gt;
some experiments that have to be done : e.g. density of terms having &amp;lt;math&amp;gt;\lambda x.y&amp;lt;/math&amp;gt; or big Omega pattern ...&lt;br /&gt;
&lt;br /&gt;
== to be done ==&lt;br /&gt;
&lt;br /&gt;
Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; with other size for variables especially one, binary with fixed size&lt;br /&gt;
&lt;br /&gt;
== Open questions and Future work ==&lt;br /&gt;
&lt;br /&gt;
.....&lt;/div&gt;</summary>
		<author><name>René David</name></author>
	</entry>
	<entry>
		<id>http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2719</id>
		<title>Lambda counting</title>
		<link rel="alternate" type="text/html" href="http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2719"/>
		<updated>2008-10-21T09:34:52Z</updated>

		<summary type="html">&lt;p&gt;René David : /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This paper addresses the following question. Having a&lt;br /&gt;
(theoretical) programming language and a property, what is the&lt;br /&gt;
probability that a random program satisfies the given property ?&lt;br /&gt;
In particular, is it the case that almost every random program&lt;br /&gt;
satisfies the desired property i.e. the probability is 1 ? We consider,  &lt;br /&gt;
in this introduction,   that this notion of&lt;br /&gt;
probability is, at least intuitively, sufficiently clear  but, of&lt;br /&gt;
course, this will have to be made precise.&lt;br /&gt;
&lt;br /&gt;
This&lt;br /&gt;
kind of question has some known results for Turing machines and&lt;br /&gt;
cellular automata. Some of them will be given in section ??.&lt;br /&gt;
We will concentrate here on functional programming&lt;br /&gt;
languages and, more specifically, on  the lambda calculus, the&lt;br /&gt;
simplest such language. Various properties can be studied. Some&lt;br /&gt;
concern the structure of a term, some concern its behaviour.&lt;br /&gt;
&lt;br /&gt;
The first question for which it would be desirable to have an&lt;br /&gt;
answer is the following: give a &amp;quot;simple&amp;quot; equivalent for the number&lt;br /&gt;
of terms of size n. This question is, at present and as far as we&lt;br /&gt;
know, unsolved and the usual technics of generating functions does&lt;br /&gt;
not work. See section ??? for more details. We give here upper and&lt;br /&gt;
lower bounds for this number. This estimation will be enough for&lt;br /&gt;
our purpose but the gap between the lower and the upper bound is&lt;br /&gt;
to big to hope to find an equivalent.&lt;br /&gt;
&lt;br /&gt;
For other questions, some experiments have already been done  (see&lt;br /&gt;
for example ...) which clearly indicates the desired result. For&lt;br /&gt;
example, they &amp;quot;show&amp;quot; that almost every closed lambda term begins&lt;br /&gt;
with a &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; but, as far as we know, there was no&lt;br /&gt;
&amp;quot;proved&amp;quot; result of this form.&lt;br /&gt;
&lt;br /&gt;
This paper proves some  non trivial results on the structural form&lt;br /&gt;
of a lambda term. In particular we show that almost every closed&lt;br /&gt;
lambda term begins with &amp;quot;many&amp;quot; &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; (the precise&lt;br /&gt;
meaning of this is given in theorem ??), that they bound &amp;quot;many&amp;quot;&lt;br /&gt;
occurrences of the corresponding variables (theorem ??) and that,&lt;br /&gt;
given any fixed closed term, &#039;&#039;almost no&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt;-term has this term as a sub-term (theorem&lt;br /&gt;
??).&lt;br /&gt;
&lt;br /&gt;
Our original motivation was to consider the property of being&lt;br /&gt;
terminating. Is a random term strongly normalizable (SN for short)&lt;br /&gt;
i.e. every sequence of reduction terminates ? This question is, at&lt;br /&gt;
present, unsolved and  the experiments we have done do not even&lt;br /&gt;
give an idea of what the result should be. It is known that being&lt;br /&gt;
SN is an undecidable question and it is thus not easy to count the&lt;br /&gt;
number of SN terms of big size. It is clear that having&lt;br /&gt;
&amp;lt;math&amp;gt;(\delta \ \delta)&amp;lt;/math&amp;gt; as a sub-term is a sufficient (but&lt;br /&gt;
not necessary) condition for being non SN but as the experiments&lt;br /&gt;
have shown (and as we have proved) almost no terms contains&lt;br /&gt;
&amp;lt;math&amp;gt;(\delta \ \delta)&amp;lt;/math&amp;gt;  and this is thus useless to have a&lt;br /&gt;
result for non SN. On the opposite direction, it is known that, if&lt;br /&gt;
a term t is not SN, then a pattern &amp;quot;looking like&amp;quot; &lt;br /&gt;
&amp;lt;math&amp;gt;(\delta \ \delta)&amp;lt;/math&amp;gt; (the precise meaning will be given in section ??)&lt;br /&gt;
must appear in t but the experiments seem to show that almost&lt;br /&gt;
every term possesses this pattern (actually, we have not been able&lt;br /&gt;
to count for big enough terms to have a clear idea of the&lt;br /&gt;
probability of possessing the desired pattern). But, again, this experimental result would be of no use to guess the result.&lt;br /&gt;
&lt;br /&gt;
Another question, which is also undecidable, and for which finding&lt;br /&gt;
the probability seems to be even more difficult, is to get the&lt;br /&gt;
probability of being weakly normalizable i.e. there is a sequence&lt;br /&gt;
of reduction that terminates.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Combinatory logic is another programming language  related to the&lt;br /&gt;
lambda calculus. It is a way of coding lambda terms without using&lt;br /&gt;
bound variables. The coding is fair for the questions we are&lt;br /&gt;
concerned with, in the sense that there are translations in both&lt;br /&gt;
directions which, for example, preserve the property of being SN.&lt;br /&gt;
We have also studied this language and, surprisingly, the results&lt;br /&gt;
are very different from those for the lambda calculus. For example&lt;br /&gt;
we show that, for every fixed term t_0,  almost every term possess&lt;br /&gt;
t_0 as a sub-term and this of course implies that almost every&lt;br /&gt;
term is non SN. Note that the increase of size in the translation&lt;br /&gt;
from the lambda calculus to combinatory logic is not known (we&lt;br /&gt;
only have a lower bound) and thus results for combinatory logic&lt;br /&gt;
cannot be used to get results for the lambda calculus.&lt;br /&gt;
&lt;br /&gt;
The organization of the paper is as follows. Section ?? briefly&lt;br /&gt;
recalls known results for Turing machines and cellular automata.&lt;br /&gt;
Section ?? shows that, in combinatory logic, every fixed term&lt;br /&gt;
appears in almost every term. In section ?? we recall the basic&lt;br /&gt;
definitions of the lambda calculus and we discuss the various&lt;br /&gt;
possibilities for counting the size of a term and the probability&lt;br /&gt;
measure we put on sets of terms. Section ?? gives the&lt;br /&gt;
combinatorial results we will need in our proofs and, in&lt;br /&gt;
particular, the lower and upper bounds for the number of terms of&lt;br /&gt;
size n. It also introduces Catalan and Motzkin numbers and the&lt;br /&gt;
so-called Lambert function. Our main results, i.e. theorems ??, ??&lt;br /&gt;
and ?? appear in section ?? Section ?? gives experimental results&lt;br /&gt;
for questions for which we have no proof. Finally, section ???&lt;br /&gt;
gives open questions and future work. The detailed proofs are&lt;br /&gt;
given in an appendix.&lt;br /&gt;
&lt;br /&gt;
== Known results for Turing machines and cellular automata ==&lt;br /&gt;
&lt;br /&gt;
== Lambert function, Catalan and Motzkin numbers ==&lt;br /&gt;
&lt;br /&gt;
=== Catalan numbers ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; : Catalan numbers &lt;br /&gt;
&lt;br /&gt;
Usual equivalent: &amp;lt;math&amp;gt;C(n) \sim \frac{4^n}{n^{3/2}\sqrt{\pi}}&amp;lt;/math&amp;gt; which is obtained using Strirling formula.&lt;br /&gt;
However, using stirling series: &amp;lt;math&amp;gt;&lt;br /&gt;
  n!=\sqrt{2\pi n}\left({n\over e}\right)^n&lt;br /&gt;
  \left(&lt;br /&gt;
   1&lt;br /&gt;
   +{1\over12n}&lt;br /&gt;
   +{1\over288n^2}&lt;br /&gt;
   -{139\over51840n^3}&lt;br /&gt;
   -{571\over2488320n^4}&lt;br /&gt;
   + \cdots&lt;br /&gt;
  \right)&lt;br /&gt;
 &amp;lt;/math&amp;gt;, we get that for &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; we have &amp;lt;math&amp;gt;\sqrt{2\pi n}\left({n\over e}\right)^n \leq n! \leq \frac{7}{6}\sqrt{2\pi n}\left({n\over e}\right)^n&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, using this and &amp;lt;math&amp;gt;\left(\frac{n}{n+1}\right)^{n} &amp;gt; e^{-1}&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C(n) = \frac{(2n)!}{(n+1)!n!} \geq \frac{36}{49\sqrt{\pi}} \frac{4^n}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; but also for &amp;lt;math&amp;gt;n=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Motzkin numbers===&lt;br /&gt;
&lt;br /&gt;
Let us define &amp;lt;math&amp;gt;M(n,k)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; leafs. We get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n,k) = \frac{(n+k-1)!}{(n-k+1)!(k-1)!k!}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, by summing we define &amp;lt;math&amp;gt;M(n)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and give an equivalent:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n) = \sum_{k=0}^n M(n,k) \sim \left(\frac{1}{3-2\sqrt{2}}\right)^n \frac{1}{n^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lambert W function===&lt;br /&gt;
&lt;br /&gt;
The Lambert function &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; is defined by the equation &amp;lt;math&amp;gt;x = W(x) e ^ {W(x)} &amp;lt;/math&amp;gt;&lt;br /&gt;
which has a unique solution in &amp;lt;math&amp;gt;\mathbb{R}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;x \geq e&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x)&amp;lt;/math&amp;gt; which implies that &lt;br /&gt;
&amp;lt;math&amp;gt;W(x) \sim \ln(x)&amp;lt;/math&amp;gt; near &amp;lt;math&amp;gt;+\infty&amp;lt;/math&amp;gt;. To prove this, it is enough to remark that&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;(\ln(x) - \ln(\ln(x))e^{\ln(x)-\ln(\ln(x))} = x \left(1 - \frac{\ln(\ln(x))}{\ln(x)}\right) \leq x \leq x \ln(x) = \ln(x) e^{\ln(x)} &amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is not precise enough for our purpose. Using one step of the Newton method from &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt;, we can find a better upper bound for &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; because &amp;lt;math&amp;gt;y \mapsto y e^y&amp;lt;/math&amp;gt; is increasing and convex. This gives:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, if we define &amp;lt;math&amp;gt;f(y) = y e^y&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;f&#039;(y)=(1+y)e^y&amp;lt;/math&amp;gt; and therefore, newton&#039;s method from &amp;lt;math&amp;gt;A = \ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt; gives a point at position:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;&lt;br /&gt;
A - \frac{f(A) - x}{f&#039;(A)} &lt;br /&gt;
  = A +  \frac{x \ln(\ln(x))}{\ln(x)} \frac{\ln(x)}{x(\ln(x) - \ln(\ln(x)) + 1)}&lt;br /&gt;
  = A +  \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1} &lt;br /&gt;
&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, we show that for &amp;lt;math&amp;gt;x\geq e&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + 1&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, for &amp;lt;math&amp;gt;x &amp;gt; 1&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;e^{\sqrt{ex}} \geq 1 + \sqrt{ex} + \frac{ex}{2} \geq x&amp;lt;/math&amp;gt;, which implies&lt;br /&gt;
&amp;lt;math&amp;gt;ex \geq \ln^2(x)&amp;lt;/math&amp;gt; and therefore &amp;lt;math&amp;gt;\ln(x) - \ln\ln(x) + 1 \geq \ln\ln(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==  combinatory logic ==&lt;br /&gt;
&lt;br /&gt;
Basically the paper already written by Marek&lt;br /&gt;
&lt;br /&gt;
+ the following&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As we will see in section ??, theorem ?? does not holds for the Lambda calculus. This may be surprising since there are translations between these systems which respect many properties (for exemple the one of being terminating). However these translations do not preserve the size. &lt;br /&gt;
&lt;br /&gt;
The translation T from combinatory logic to lambda calculus is linear, i.e. there is a constant k such that, for all terms, &amp;lt;math&amp;gt;size(T(t) \leq k.size(t)&amp;lt;/math&amp;gt; but the translation T&#039; in the other direction is not linear. As far as we know, there is no known bound on the size of T&#039;(t) but it is not difficult to find exemples where size(T&#039;(t)) is of order &amp;lt;math&amp;gt;size(t)^3&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The point is that T&#039; has to code the binding in some way and this takes place. It will be interesting to compare the size of T&#039;(t) with the one of t using other notion of size than the usual one. See section ?? for some complement.&lt;br /&gt;
&lt;br /&gt;
== Generality on lambda calculus ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition &lt;br /&gt;
&lt;br /&gt;
The set &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt; of lambda terms (or,&lt;br /&gt;
simply, terms) is defined by the following grammar&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;t, u  := Var \ \mid \ \lambda x.t \ \mid \ (t \ u)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To be able to define the notion of a &#039;&#039;random&#039;&#039; term we&lt;br /&gt;
have to define a distribution law on &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt;. There are many&lt;br /&gt;
possibilities for that. We choose here the simplest one. Note that this is the one for which, at least at present,  we are&lt;br /&gt;
able to prove some results. It is based on densities. For that we&lt;br /&gt;
first have to define the &#039;&#039;size&#039;&#039; of a term.&lt;br /&gt;
&lt;br /&gt;
The usual&lt;br /&gt;
definition is the following.&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
The size (denoted as &amp;lt;math&amp;gt;size_1(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
rules.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(\lambda x.t)=size_1(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1((t \ u))=size_1(t)+size_1(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the rest of the paper we will use another definition (denoted&lt;br /&gt;
as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt;) which is similar but  gives simpler computations.&lt;br /&gt;
We believe (but we have not yet checked the details) that, with&lt;br /&gt;
&amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt; we would have similar results. The&lt;br /&gt;
computation, with &amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt;,  of the upper and lower&lt;br /&gt;
bounds of the number of terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; will be done&lt;br /&gt;
in section ??&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
The size (denoted as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt; or, more simply &amp;lt;math&amp;gt;size(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
rules.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(\lambda x.t)=size_0(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0((t \ u))=size_0(t)+size_0(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These definitions of the size are, for the implementation point of&lt;br /&gt;
view, not realistic because, in case a term has a lot of distinct&lt;br /&gt;
variables, it is not realistic to use a single bit to code them.&lt;br /&gt;
The usual way to implement this coding is to replace the names of&lt;br /&gt;
variables by  their so called de Bruijn indices: a variable is&lt;br /&gt;
replaced by the number of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; that occur, on the&lt;br /&gt;
path from the variable to the root, between the variable and the&lt;br /&gt;
&amp;lt;math&amp;gt;lambda&amp;lt;/math&amp;gt; that binds it. Note that, in this case,&lt;br /&gt;
different occurrences of the same variable may be represented by&lt;br /&gt;
different indices.&lt;br /&gt;
&lt;br /&gt;
Choosing the way we code these de Bruijn indices gives different&lt;br /&gt;
other ways of defining the size of a term. This can be done in the&lt;br /&gt;
following ways&lt;br /&gt;
&lt;br /&gt;
- Use unary notation, i.e. the size of the index &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;&lt;br /&gt;
simply is &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; itself&lt;br /&gt;
&lt;br /&gt;
- Use optimal binary notation, i.e. the size of the index&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;log_2(n)&amp;lt;/math&amp;gt; i.e. the logarithm of&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; in base 2.&lt;br /&gt;
&lt;br /&gt;
- Use uniform binary notation, i.e. the size of an index is the&lt;br /&gt;
logarithm, in base 2, of the number of leaves of the term.&lt;br /&gt;
&lt;br /&gt;
Remark&lt;br /&gt;
&lt;br /&gt;
See section ?? for a discusion about these different size.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; be an integer. We denote by &amp;lt;math&amp;gt;\Lambda_n&amp;lt;/math&amp;gt; the set of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; terms of size n.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let A be a set of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; terms. &lt;br /&gt;
&lt;br /&gt;
1) We denote by &amp;lt;math&amp;gt;\#(A)&amp;lt;/math&amp;gt; the cardinality of A.&lt;br /&gt;
&lt;br /&gt;
2) We denote by &amp;lt;math&amp;gt;d(A)&amp;lt;/math&amp;gt; the limit, for n going to &amp;lt;math&amp;gt;\infty&amp;lt;/math&amp;gt;, &lt;br /&gt;
of &amp;lt;math&amp;gt;\frac{\#(A\cap \Lambda_n)}{\#(\Lambda_n)}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Remark&lt;br /&gt;
&lt;br /&gt;
Note that d is not exactly a measure since &amp;lt;math&amp;gt;d(A)&amp;lt;/math&amp;gt; is undefined if the previous limit does not exist&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let P be a property of terms. We will say that almost every term satisfies P &lt;br /&gt;
(this will be also stated as P holds a.e.) if&lt;br /&gt;
&amp;lt;math&amp;gt;d(\{t \ | \ P(t) holds\})=1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== generating functions ==&lt;br /&gt;
&lt;br /&gt;
this does not work (by now) because radius of convergence 0&lt;br /&gt;
&lt;br /&gt;
no known results for the number of terms of size n (denoted &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
== our results ==&lt;br /&gt;
&lt;br /&gt;
(the proof of result of section k needs the result of section (k-1))&lt;br /&gt;
&lt;br /&gt;
=== Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
For the lower bound, we will first count the number &amp;lt;math&amp;gt;LB(n,k)&amp;lt;/math&amp;gt; of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; starting with &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas and having no other lambda below. This means that the lower part of the term is a binary tree of size &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; with&lt;br /&gt;
&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; possibility for each leaf. Therefore we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) = C(n-k) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And therefore, for &amp;lt;math&amp;gt;n &amp;gt; k&amp;lt;/math&amp;gt;, using our lower bound for &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n + 1 \geq n - k + 1&amp;lt;/math&amp;gt;, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) \geq K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;K=\frac{36}{49\sqrt{\pi}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed, we define &amp;lt;math&amp;gt;f(\alpha) = \left(4n\alpha\right)^{n(1-\alpha) + 1}&amp;lt;/math&amp;gt; (so &amp;lt;math&amp;gt;LB(n,k) \geq \frac{K}{(n+1)^\frac{3}{2}} f\left(\frac{k}{n}\right)&amp;lt;/math&amp;gt;) and look for the maximum of this function. We have &amp;lt;math&amp;gt;f&#039;(\alpha) = f(\alpha) \left(-n\ln(4n\alpha) +\frac{n(1-\alpha) + 1}{\alpha}\right)&amp;lt;/math&amp;gt;. Thus, &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\frac{n+1}{n\alpha}e^{\frac{n+1}{n\alpha}}\geq 4e(n+1)&amp;lt;/math&amp;gt;. The Lambert function begin increasing this means that &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\alpha \leq \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;f(\alpha)&amp;lt;/math&amp;gt; reaches a maximum for &amp;lt;math&amp;gt;\alpha = \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This means that &amp;lt;math&amp;gt;(4k)^{n-k}&amp;lt;/math&amp;gt; reaches its maximum for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed when &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;&lt;br /&gt;
is near to &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; which is likely not to be an integer. However, there are at least &amp;lt;math&amp;gt;\left\lfloor \frac{n (\ln(\ln(4en)) - 1)}{\ln^2(4en)}\right\rfloor&amp;lt;/math&amp;gt; integer between &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\frac{n+1}{\ln(4e(n+1))}&amp;lt;/math&amp;gt;. Indeed, using our inequalities on Lambert W function, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}-\frac{n+1}{\ln(4e(n+1))} = \frac{(n+1) (\ln(4e(n+1)) - W(4e(n+1)))}{W(4e(n+1))\ln(4e(n+1))} \geq \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, we get the following lowerbound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \sum_{k=1}^{n} LB(n,k) \geq \sum_{k=\lceil\frac{n+1}{\ln(4e(n+1))}\rceil}^{\lfloor\frac{n+1}{W(4e(n+1))}\rfloor} K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}} \geq K \left\lfloor \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}\right\rfloor \frac{\left(\frac{4(n+1)}{\ln(4e(n+1))}\right)^{n-\frac{n+1}{\ln(4e(n+1))}+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To simplify, using the fact that &amp;lt;math&amp;gt;\lim_{n\to +\infty}\left(\frac{\ln(n)}{\ln(4en)}\right)^n = 0&amp;lt;/math&amp;gt; and taking &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; large enough, we have the following lowerbound:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \frac{\sqrt{n}}{\ln^3(n)}\left(\frac{4n}{\ln(n)}\right)^{n-\frac{n}{\ln(n)}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We now compute an upper bound &amp;lt;math&amp;gt;UB(n,k)&amp;lt;/math&amp;gt; for the number of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with exactly &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas (that is with &amp;lt;math&amp;gt;n - k + 1&amp;lt;/math&amp;gt; leaves using the Motzkin numbers and allowing any lambda to bind any variable (regardless of the real scope):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;UB(n,k) = M(n,n-k+1) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we sum this for all possible &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and get an upper bound of &amp;lt;math&amp;gt;k^{n-k+1}&amp;lt;/math&amp;gt; using Lambert function as for the lower bound, we get the following upper bound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \leq M(n) \left(\frac{n+1}{W(e(n+1))}\right)^{n-\frac{n+1}{W(e(n+1))} + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The ration between our upper bound and lower bound is equivalent to (NEEDS FURTHER CHECKING):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\left(\frac{1}{4(3-2\sqrt{2})}\right)^n\frac{\ln^3(n)}{n^2} \simeq 1.46^n\frac{\ln^3(n)}{n^2}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== upper and lower bounds for number of lambdas in a term of size n ===&lt;br /&gt;
&lt;br /&gt;
=== Jakub&#039;s trik : at least 1 lambda in head position ===&lt;br /&gt;
&lt;br /&gt;
=== at least &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; lambdas in head position and number of lambdas in one path ===&lt;br /&gt;
&lt;br /&gt;
Remark: (may be 4) can be done directly without 3))&lt;br /&gt;
&lt;br /&gt;
=== each of the  &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; head lambdas really bind &amp;quot;many&amp;quot;  occurrences of the variable ===&lt;br /&gt;
&lt;br /&gt;
=== every fixed closed term (including the identity !) does not appear in a random term (in fact we have much more than that) ===&lt;br /&gt;
&lt;br /&gt;
comment : so different situation in combinatory logic and lambda calculus ; the coding uses a big size so need to count variables in a different way&lt;br /&gt;
&lt;br /&gt;
== Experiments ==&lt;br /&gt;
&lt;br /&gt;
results of the experiments we have done&lt;br /&gt;
&lt;br /&gt;
some experiments that have to be done : e.g. density of terms having &amp;lt;math&amp;gt;\lambda x.y&amp;lt;/math&amp;gt; or big Omega pattern ...&lt;br /&gt;
&lt;br /&gt;
== to be done ==&lt;br /&gt;
&lt;br /&gt;
Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; with other size for variables especially one, binary with fixed size&lt;br /&gt;
&lt;br /&gt;
== Open questions and Future work ==&lt;br /&gt;
&lt;br /&gt;
.....&lt;/div&gt;</summary>
		<author><name>René David</name></author>
	</entry>
	<entry>
		<id>http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2718</id>
		<title>Lambda counting</title>
		<link rel="alternate" type="text/html" href="http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2718"/>
		<updated>2008-10-21T09:24:33Z</updated>

		<summary type="html">&lt;p&gt;René David : /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This paper addresses the following question. Having a&lt;br /&gt;
(theoretical) programming language and a property, what is the&lt;br /&gt;
probability that a random program satisfies the given property ?&lt;br /&gt;
In particular, is it the case that almost every random program&lt;br /&gt;
satisfies the desired property i.e. the probability is 1 ? This&lt;br /&gt;
kind of question has some known results for Turing machines and&lt;br /&gt;
cellular automata. Some of them will be given in section ??.&lt;br /&gt;
&lt;br /&gt;
We consider,  in this introduction   that this notion of&lt;br /&gt;
probability is, at least intuitively, sufficiently clear  but, of&lt;br /&gt;
course, this will have to be made precise.&lt;br /&gt;
&lt;br /&gt;
We will concentrate in this paper on functional programming&lt;br /&gt;
languages and, more specifically, on  the lambda calculus, the&lt;br /&gt;
simplest such language. Various properties can be studied. Some&lt;br /&gt;
concern the structure of a term, some concern its behaviour.&lt;br /&gt;
&lt;br /&gt;
The first question for which it would be desirable to have an&lt;br /&gt;
answer is the following: give a &amp;quot;simple&amp;quot; equivalent for the number&lt;br /&gt;
of terms of size n. This question is, at present and as far as we&lt;br /&gt;
know, unsolved and the usual technics of generating functions does&lt;br /&gt;
not work. See section ??? for more details. We give here upper and&lt;br /&gt;
lower bounds for this number. This estimation will be enough for&lt;br /&gt;
our purpose but the gap between the lower and the upper bound is&lt;br /&gt;
to big to hope an equivalent.&lt;br /&gt;
&lt;br /&gt;
For other questions, some experiments have already been done  (see&lt;br /&gt;
for example ...) which clearly indicates the desired result. For&lt;br /&gt;
example, they &amp;quot;show&amp;quot; that almost every closed lambda term begins&lt;br /&gt;
with a &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; but, as far as we know, there was no&lt;br /&gt;
&amp;quot;proved&amp;quot; result of this form.&lt;br /&gt;
&lt;br /&gt;
This paper proves some  non trivial results on the structural form&lt;br /&gt;
of a lambda term. In particular we show that almost every closed&lt;br /&gt;
lambda term begins with &amp;quot;many&amp;quot; &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; (the precise&lt;br /&gt;
meaning of this is given in theorem ??), that they bound &amp;quot;many&amp;quot;&lt;br /&gt;
occurrences of the corresponding variables (theorem ??) and that,&lt;br /&gt;
given any fixed closed term, almost &#039;&#039;no&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt;-term has this term as a sub-term (theorem&lt;br /&gt;
??).&lt;br /&gt;
&lt;br /&gt;
Our original motivation was to consider the property of being&lt;br /&gt;
terminating. Is a random term strongly normalizable (SN for short)&lt;br /&gt;
i.e. every sequence of reduction terminates ? This question is, at&lt;br /&gt;
present, unsolved and  the experiments we have done do not even&lt;br /&gt;
give an idea of what the result should be. It is known that being&lt;br /&gt;
SN is an undecidable question and it is thus not easy to count the&lt;br /&gt;
number of SN terms of big size. It is clear that having&lt;br /&gt;
&amp;lt;math&amp;gt;(\delta \ \delta)&amp;lt;/math&amp;gt; as a sub-term is a sufficient (but&lt;br /&gt;
not necessary) condition for being non SN but as the experiments&lt;br /&gt;
have shown (and as we have proved) almost no terms contains&lt;br /&gt;
&amp;lt;math&amp;gt;(\delta \ \delta)&amp;lt;/math&amp;gt;  and this is thus useless to have a&lt;br /&gt;
result for non SN. On the opposite direction, it is known that, if&lt;br /&gt;
a term t is not SN, then a pattern &amp;quot;looking like&amp;quot; &lt;br /&gt;
&amp;lt;math&amp;gt;(\delta \ \delta)&amp;lt;/math&amp;gt; (the precise meaning will be given in section ??)&lt;br /&gt;
must appear in t but the experiments seem to show that almost&lt;br /&gt;
every term possesses this pattern (actually, we have not been able&lt;br /&gt;
to count for big enough terms to have a clear idea of the&lt;br /&gt;
probability of possessing the desired pattern).&lt;br /&gt;
&lt;br /&gt;
Another question, which is also undecidable, and for which finding&lt;br /&gt;
the probability seems to be even more difficult, is to get the&lt;br /&gt;
probability of being weakly normalizable i.e. there is a sequence&lt;br /&gt;
of reduction that terminates.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Combinatory logic is another programming language  related to the&lt;br /&gt;
lambda calculus. It is a way of coding lambda terms without using&lt;br /&gt;
bound variables. The coding is fair for the questions we are&lt;br /&gt;
concerned with in the sense that there are translations in both&lt;br /&gt;
directions which, for example, preserve the property of being SN.&lt;br /&gt;
We have also studied this language and, surprisingly, the results&lt;br /&gt;
are very different from those for the lambda calculus. For example&lt;br /&gt;
we show that, for every fixed term t_0,  almost every term possess&lt;br /&gt;
t_0 as a sub-term and this of course implies that almost every&lt;br /&gt;
term is non SN. Note that the increase of size in the translation&lt;br /&gt;
from the lambda calculus to combinatory logic is not known (we&lt;br /&gt;
only have a lower bound) and thus results for combinatory logic&lt;br /&gt;
cannot be used to get results for the lambda calculus.&lt;br /&gt;
&lt;br /&gt;
The organization of the paper is as follows. Section ?? briefly&lt;br /&gt;
recalls known results for Turing machines and cellular automata.&lt;br /&gt;
Section ?? shows that, in combinatory logic, every fixed term&lt;br /&gt;
appears in almost every term. In section ?? we recall the basic&lt;br /&gt;
definitions of the lambda calculus and we discuss the various&lt;br /&gt;
possibilities for counting the size of a term and the probability&lt;br /&gt;
measure we put on sets of terms. Section ?? gives the&lt;br /&gt;
combinatorial results we will need in our proofs and, in&lt;br /&gt;
particular, the lower and upper bounds for the number of terms of&lt;br /&gt;
size n. It also introduces Catalan and Motzkin numbers and the&lt;br /&gt;
so-called Lambert function. Our main results, i.e. theorems ??, ??&lt;br /&gt;
and ?? appear in section ?? Section ?? gives experimental results&lt;br /&gt;
for questions for which we have no proof. Finally, section ???&lt;br /&gt;
gives open questions and future work. The detailed proofs are&lt;br /&gt;
given in an appendix.&lt;br /&gt;
&lt;br /&gt;
== Known results for Turing machines and cellular automata ==&lt;br /&gt;
&lt;br /&gt;
== Lambert function, Catalan and Motzkin numbers ==&lt;br /&gt;
&lt;br /&gt;
=== Catalan numbers ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; : Catalan numbers &lt;br /&gt;
&lt;br /&gt;
Usual equivalent: &amp;lt;math&amp;gt;C(n) \sim \frac{4^n}{n^{3/2}\sqrt{\pi}}&amp;lt;/math&amp;gt; which is obtained using Strirling formula.&lt;br /&gt;
However, using stirling series: &amp;lt;math&amp;gt;&lt;br /&gt;
  n!=\sqrt{2\pi n}\left({n\over e}\right)^n&lt;br /&gt;
  \left(&lt;br /&gt;
   1&lt;br /&gt;
   +{1\over12n}&lt;br /&gt;
   +{1\over288n^2}&lt;br /&gt;
   -{139\over51840n^3}&lt;br /&gt;
   -{571\over2488320n^4}&lt;br /&gt;
   + \cdots&lt;br /&gt;
  \right)&lt;br /&gt;
 &amp;lt;/math&amp;gt;, we get that for &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; we have &amp;lt;math&amp;gt;\sqrt{2\pi n}\left({n\over e}\right)^n \leq n! \leq \frac{7}{6}\sqrt{2\pi n}\left({n\over e}\right)^n&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, using this and &amp;lt;math&amp;gt;\left(\frac{n}{n+1}\right)^{n} &amp;gt; e^{-1}&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C(n) = \frac{(2n)!}{(n+1)!n!} \geq \frac{36}{49\sqrt{\pi}} \frac{4^n}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; but also for &amp;lt;math&amp;gt;n=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Motzkin numbers===&lt;br /&gt;
&lt;br /&gt;
Let us define &amp;lt;math&amp;gt;M(n,k)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; leafs. We get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n,k) = \frac{(n+k-1)!}{(n-k+1)!(k-1)!k!}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, by summing we define &amp;lt;math&amp;gt;M(n)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and give an equivalent:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n) = \sum_{k=0}^n M(n,k) \sim \left(\frac{1}{3-2\sqrt{2}}\right)^n \frac{1}{n^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lambert W function===&lt;br /&gt;
&lt;br /&gt;
The Lambert function &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; is defined by the equation &amp;lt;math&amp;gt;x = W(x) e ^ {W(x)} &amp;lt;/math&amp;gt;&lt;br /&gt;
which has a unique solution in &amp;lt;math&amp;gt;\mathbb{R}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;x \geq e&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x)&amp;lt;/math&amp;gt; which implies that &lt;br /&gt;
&amp;lt;math&amp;gt;W(x) \sim \ln(x)&amp;lt;/math&amp;gt; near &amp;lt;math&amp;gt;+\infty&amp;lt;/math&amp;gt;. To prove this, it is enough to remark that&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;(\ln(x) - \ln(\ln(x))e^{\ln(x)-\ln(\ln(x))} = x \left(1 - \frac{\ln(\ln(x))}{\ln(x)}\right) \leq x \leq x \ln(x) = \ln(x) e^{\ln(x)} &amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is not precise enough for our purpose. Using one step of the Newton method from &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt;, we can find a better upper bound for &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; because &amp;lt;math&amp;gt;y \mapsto y e^y&amp;lt;/math&amp;gt; is increasing and convex. This gives:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, if we define &amp;lt;math&amp;gt;f(y) = y e^y&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;f&#039;(y)=(1+y)e^y&amp;lt;/math&amp;gt; and therefore, newton&#039;s method from &amp;lt;math&amp;gt;A = \ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt; gives a point at position:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;&lt;br /&gt;
A - \frac{f(A) - x}{f&#039;(A)} &lt;br /&gt;
  = A +  \frac{x \ln(\ln(x))}{\ln(x)} \frac{\ln(x)}{x(\ln(x) - \ln(\ln(x)) + 1)}&lt;br /&gt;
  = A +  \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1} &lt;br /&gt;
&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, we show that for &amp;lt;math&amp;gt;x\geq e&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + 1&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, for &amp;lt;math&amp;gt;x &amp;gt; 1&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;e^{\sqrt{ex}} \geq 1 + \sqrt{ex} + \frac{ex}{2} \geq x&amp;lt;/math&amp;gt;, which implies&lt;br /&gt;
&amp;lt;math&amp;gt;ex \geq \ln^2(x)&amp;lt;/math&amp;gt; and therefore &amp;lt;math&amp;gt;\ln(x) - \ln\ln(x) + 1 \geq \ln\ln(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==  combinatory logic ==&lt;br /&gt;
&lt;br /&gt;
Basically the paper already written by Marek&lt;br /&gt;
&lt;br /&gt;
+ the following&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As we will see in section ??, theorem ?? does not holds for the Lambda calculus. This may be surprising since there are translations between these systems which respect many properties (for exemple the one of being terminating). However these translations do not preserve the size. &lt;br /&gt;
&lt;br /&gt;
The translation T from combinatory logic to lambda calculus is linear, i.e. there is a constant k such that, for all terms, &amp;lt;math&amp;gt;size(T(t) \leq k.size(t)&amp;lt;/math&amp;gt; but the translation T&#039; in the other direction is not linear. As far as we know, there is no known bound on the size of T&#039;(t) but it is not difficult to find exemples where size(T&#039;(t)) is of order &amp;lt;math&amp;gt;size(t)^3&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The point is that T&#039; has to code the binding in some way and this takes place. It will be interesting to compare the size of T&#039;(t) with the one of t using other notion of size than the usual one. See section ?? for some complement.&lt;br /&gt;
&lt;br /&gt;
== Generality on lambda calculus ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition &lt;br /&gt;
&lt;br /&gt;
The set &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt; of lambda terms (or,&lt;br /&gt;
simply, terms) is defined by the following grammar&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;t, u  := Var \ \mid \ \lambda x.t \ \mid \ (t \ u)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To be able to define the notion of a &#039;&#039;random&#039;&#039; term we&lt;br /&gt;
have to define a distribution law on &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt;. There are many&lt;br /&gt;
possibilities for that. We choose here the simplest one. Note that this is the one for which, at least at present,  we are&lt;br /&gt;
able to prove some results. It is based on densities. For that we&lt;br /&gt;
first have to define the &#039;&#039;size&#039;&#039; of a term.&lt;br /&gt;
&lt;br /&gt;
The usual&lt;br /&gt;
definition is the following.&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
The size (denoted as &amp;lt;math&amp;gt;size_1(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
rules.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(\lambda x.t)=size_1(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1((t \ u))=size_1(t)+size_1(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the rest of the paper we will use another definition (denoted&lt;br /&gt;
as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt;) which is similar but  gives simpler computations.&lt;br /&gt;
We believe (but we have not yet checked the details) that, with&lt;br /&gt;
&amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt; we would have similar results. The&lt;br /&gt;
computation, with &amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt;,  of the upper and lower&lt;br /&gt;
bounds of the number of terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; will be done&lt;br /&gt;
in section ??&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
The size (denoted as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt; or, more simply &amp;lt;math&amp;gt;size(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
rules.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(\lambda x.t)=size_0(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0((t \ u))=size_0(t)+size_0(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These definitions of the size are, for the implementation point of&lt;br /&gt;
view, not realistic because, in case a term has a lot of distinct&lt;br /&gt;
variables, it is not realistic to use a single bit to code them.&lt;br /&gt;
The usual way to implement this coding is to replace the names of&lt;br /&gt;
variables by  their so called de Bruijn indices: a variable is&lt;br /&gt;
replaced by the number of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; that occur, on the&lt;br /&gt;
path from the variable to the root, between the variable and the&lt;br /&gt;
&amp;lt;math&amp;gt;lambda&amp;lt;/math&amp;gt; that binds it. Note that, in this case,&lt;br /&gt;
different occurrences of the same variable may be represented by&lt;br /&gt;
different indices.&lt;br /&gt;
&lt;br /&gt;
Choosing the way we code these de Bruijn indices gives different&lt;br /&gt;
other ways of defining the size of a term. This can be done in the&lt;br /&gt;
following ways&lt;br /&gt;
&lt;br /&gt;
- Use unary notation, i.e. the size of the index &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;&lt;br /&gt;
simply is &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; itself&lt;br /&gt;
&lt;br /&gt;
- Use optimal binary notation, i.e. the size of the index&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;log_2(n)&amp;lt;/math&amp;gt; i.e. the logarithm of&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; in base 2.&lt;br /&gt;
&lt;br /&gt;
- Use uniform binary notation, i.e. the size of an index is the&lt;br /&gt;
logarithm, in base 2, of the number of leaves of the term.&lt;br /&gt;
&lt;br /&gt;
Remark&lt;br /&gt;
&lt;br /&gt;
See section ?? for a discusion about these different size.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; be an integer. We denote by &amp;lt;math&amp;gt;\Lambda_n&amp;lt;/math&amp;gt; the set of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; terms of size n.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let A be a set of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; terms. &lt;br /&gt;
&lt;br /&gt;
1) We denote by &amp;lt;math&amp;gt;\#(A)&amp;lt;/math&amp;gt; the cardinality of A.&lt;br /&gt;
&lt;br /&gt;
2) We denote by &amp;lt;math&amp;gt;d(A)&amp;lt;/math&amp;gt; the limit, for n going to &amp;lt;math&amp;gt;\infty&amp;lt;/math&amp;gt;, &lt;br /&gt;
of &amp;lt;math&amp;gt;\frac{\#(A\cap \Lambda_n)}{\#(\Lambda_n)}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Remark&lt;br /&gt;
&lt;br /&gt;
Note that d is not exactly a measure since &amp;lt;math&amp;gt;d(A)&amp;lt;/math&amp;gt; is undefined if the previous limit does not exist&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let P be a property of terms. We will say that almost every term satisfies P &lt;br /&gt;
(this will be also stated as P holds a.e.) if&lt;br /&gt;
&amp;lt;math&amp;gt;d(\{t \ | \ P(t) holds\})=1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== generating functions ==&lt;br /&gt;
&lt;br /&gt;
this does not work (by now) because radius of convergence 0&lt;br /&gt;
&lt;br /&gt;
no known results for the number of terms of size n (denoted &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
== our results ==&lt;br /&gt;
&lt;br /&gt;
(the proof of result of section k needs the result of section (k-1))&lt;br /&gt;
&lt;br /&gt;
=== Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
For the lower bound, we will first count the number &amp;lt;math&amp;gt;LB(n,k)&amp;lt;/math&amp;gt; of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; starting with &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas and having no other lambda below. This means that the lower part of the term is a binary tree of size &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; with&lt;br /&gt;
&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; possibility for each leaf. Therefore we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) = C(n-k) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And therefore, for &amp;lt;math&amp;gt;n &amp;gt; k&amp;lt;/math&amp;gt;, using our lower bound for &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n + 1 \geq n - k + 1&amp;lt;/math&amp;gt;, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) \geq K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;K=\frac{36}{49\sqrt{\pi}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed, we define &amp;lt;math&amp;gt;f(\alpha) = \left(4n\alpha\right)^{n(1-\alpha) + 1}&amp;lt;/math&amp;gt; (so &amp;lt;math&amp;gt;LB(n,k) \geq \frac{K}{(n+1)^\frac{3}{2}} f\left(\frac{k}{n}\right)&amp;lt;/math&amp;gt;) and look for the maximum of this function. We have &amp;lt;math&amp;gt;f&#039;(\alpha) = f(\alpha) \left(-n\ln(4n\alpha) +\frac{n(1-\alpha) + 1}{\alpha}\right)&amp;lt;/math&amp;gt;. Thus, &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\frac{n+1}{n\alpha}e^{\frac{n+1}{n\alpha}}\geq 4e(n+1)&amp;lt;/math&amp;gt;. The Lambert function begin increasing this means that &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\alpha \leq \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;f(\alpha)&amp;lt;/math&amp;gt; reaches a maximum for &amp;lt;math&amp;gt;\alpha = \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This means that &amp;lt;math&amp;gt;(4k)^{n-k}&amp;lt;/math&amp;gt; reaches its maximum for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed when &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;&lt;br /&gt;
is near to &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; which is likely not to be an integer. However, there are at least &amp;lt;math&amp;gt;\left\lfloor \frac{n (\ln(\ln(4en)) - 1)}{\ln^2(4en)}\right\rfloor&amp;lt;/math&amp;gt; integer between &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\frac{n+1}{\ln(4e(n+1))}&amp;lt;/math&amp;gt;. Indeed, using our inequalities on Lambert W function, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}-\frac{n+1}{\ln(4e(n+1))} = \frac{(n+1) (\ln(4e(n+1)) - W(4e(n+1)))}{W(4e(n+1))\ln(4e(n+1))} \geq \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, we get the following lowerbound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \sum_{k=1}^{n} LB(n,k) \geq \sum_{k=\lceil\frac{n+1}{\ln(4e(n+1))}\rceil}^{\lfloor\frac{n+1}{W(4e(n+1))}\rfloor} K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}} \geq K \left\lfloor \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}\right\rfloor \frac{\left(\frac{4(n+1)}{\ln(4e(n+1))}\right)^{n-\frac{n+1}{\ln(4e(n+1))}+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To simplify, using the fact that &amp;lt;math&amp;gt;\lim_{n\to +\infty}\left(\frac{\ln(n)}{\ln(4en)}\right)^n = 0&amp;lt;/math&amp;gt; and taking &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; large enough, we have the following lowerbound:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \frac{\sqrt{n}}{\ln^3(n)}\left(\frac{4n}{\ln(n)}\right)^{n-\frac{n}{\ln(n)}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We now compute an upper bound &amp;lt;math&amp;gt;UB(n,k)&amp;lt;/math&amp;gt; for the number of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with exactly &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas (that is with &amp;lt;math&amp;gt;n - k + 1&amp;lt;/math&amp;gt; leaves using the Motzkin numbers and allowing any lambda to bind any variable (regardless of the real scope):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;UB(n,k) = M(n,n-k+1) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we sum this for all possible &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and get an upper bound of &amp;lt;math&amp;gt;k^{n-k+1}&amp;lt;/math&amp;gt; using Lambert function as for the lower bound, we get the following upper bound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \leq M(n) \left(\frac{n+1}{W(e(n+1))}\right)^{n-\frac{n+1}{W(e(n+1))} + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The ration between our upper bound and lower bound is equivalent to (NEEDS FURTHER CHECKING):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\left(\frac{1}{4(3-2\sqrt{2})}\right)^n\frac{\ln^3(n)}{n^2} \simeq 1.46^n\frac{\ln^3(n)}{n^2}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== upper and lower bounds for number of lambdas in a term of size n ===&lt;br /&gt;
&lt;br /&gt;
=== Jakub&#039;s trik : at least 1 lambda in head position ===&lt;br /&gt;
&lt;br /&gt;
=== at least &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; lambdas in head position and number of lambdas in one path ===&lt;br /&gt;
&lt;br /&gt;
Remark: (may be 4) can be done directly without 3))&lt;br /&gt;
&lt;br /&gt;
=== each of the  &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; head lambdas really bind &amp;quot;many&amp;quot;  occurrences of the variable ===&lt;br /&gt;
&lt;br /&gt;
=== every fixed closed term (including the identity !) does not appear in a random term (in fact we have much more than that) ===&lt;br /&gt;
&lt;br /&gt;
comment : so different situation in combinatory logic and lambda calculus ; the coding uses a big size so need to count variables in a different way&lt;br /&gt;
&lt;br /&gt;
== Experiments ==&lt;br /&gt;
&lt;br /&gt;
results of the experiments we have done&lt;br /&gt;
&lt;br /&gt;
some experiments that have to be done : e.g. density of terms having &amp;lt;math&amp;gt;\lambda x.y&amp;lt;/math&amp;gt; or big Omega pattern ...&lt;br /&gt;
&lt;br /&gt;
== to be done ==&lt;br /&gt;
&lt;br /&gt;
Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; with other size for variables especially one, binary with fixed size&lt;br /&gt;
&lt;br /&gt;
== Open questions and Future work ==&lt;br /&gt;
&lt;br /&gt;
.....&lt;/div&gt;</summary>
		<author><name>René David</name></author>
	</entry>
	<entry>
		<id>http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2717</id>
		<title>Lambda counting</title>
		<link rel="alternate" type="text/html" href="http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2717"/>
		<updated>2008-10-21T09:22:41Z</updated>

		<summary type="html">&lt;p&gt;René David : /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This paper addresses the following question. Having a&lt;br /&gt;
(theoretical) programming language and a property, what is the&lt;br /&gt;
probability that a random program satisfies the given property ?&lt;br /&gt;
In particular, is it the case that almost every random program&lt;br /&gt;
satisfies the desired property i.e. the probability is 1 ? This&lt;br /&gt;
kind of question has some known results for Turing machines and&lt;br /&gt;
cellular automata. Some of them will be given in section ??.&lt;br /&gt;
&lt;br /&gt;
We consider,  in this introduction   that this notion of&lt;br /&gt;
probability is, at least intuitively, sufficiently clear  but, of&lt;br /&gt;
course, this will have to be made precise.&lt;br /&gt;
&lt;br /&gt;
We will concentrate in this paper on functional programming&lt;br /&gt;
languages and, more specifically, on  the lambda calculus, the&lt;br /&gt;
simplest such language. Various properties can be studied. Some&lt;br /&gt;
concern the structure of a term, some concern its behaviour.&lt;br /&gt;
&lt;br /&gt;
The first question for which it would be desirable to have an&lt;br /&gt;
answer is the following: give a &amp;quot;simple&amp;quot; equivalent for the number&lt;br /&gt;
of terms of size n. This question is, at present and as far as we&lt;br /&gt;
know, unsolved and the usual technics of generating functions does&lt;br /&gt;
not work. See section ??? for more details. We give here upper and&lt;br /&gt;
lower bounds for this number. This estimation will be enough for&lt;br /&gt;
our purpose but the gap between the lower and the upper bound is&lt;br /&gt;
to big to hope an equivalent.&lt;br /&gt;
&lt;br /&gt;
For other questions, some experiments have already been done  (see&lt;br /&gt;
for example ...) which clearly indicates the desired result. For&lt;br /&gt;
example, they &amp;quot;show&amp;quot; that almost every closed lambda term begins&lt;br /&gt;
with a &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; but, as far as we know, there was no&lt;br /&gt;
&amp;quot;proved&amp;quot; result of this form.&lt;br /&gt;
&lt;br /&gt;
This paper proves some  non trivial results on the structural form&lt;br /&gt;
of a lambda term. In particular we show that almost every closed&lt;br /&gt;
lambda term begins with &amp;quot;many&amp;quot; &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; (the precise&lt;br /&gt;
meaning of this is given in theorem ??), that they bound &amp;quot;many&amp;quot;&lt;br /&gt;
occurrences of the corresponding variables (theorem ??) and that,&lt;br /&gt;
given any fixed closed term, almost &#039;&#039;no&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt;-term has this term as a sub-term (theorem&lt;br /&gt;
??).&lt;br /&gt;
&lt;br /&gt;
Our original motivation was to consider the property of being&lt;br /&gt;
terminating. Is a random term strongly normalizable (SN for short)&lt;br /&gt;
i.e. every sequence of reduction terminates ? This question is, at&lt;br /&gt;
present, unsolved and  the experiments we have done do not even&lt;br /&gt;
give an idea of what the result should be. It is known that being&lt;br /&gt;
SN is an undecidable question and it is thus not easy to count the&lt;br /&gt;
number of SN terms of big size. It is clear that having&lt;br /&gt;
&amp;lt;math&amp;gt;(\delta \ \delta)&amp;lt;/math&amp;gt; as a sub-term is a sufficient (but&lt;br /&gt;
not necessary) condition for being non SN but as the experiments&lt;br /&gt;
have shown (and as we have proved) almost no terms contains&lt;br /&gt;
&amp;lt;math&amp;gt;(\delta \ \delta)&amp;lt;/math&amp;gt;  and this is thus useless to have a&lt;br /&gt;
result for non SN. On the opposite direction, it is known that, if&lt;br /&gt;
a term t is not SN, then a pattern &amp;quot;looking like&amp;quot; &amp;lt;math&amp;gt;(\delta \&lt;br /&gt;
\delta)&amp;lt;/math&amp;gt; (the precise meaning will be given in section ??)&lt;br /&gt;
must appear in t but the experiments seem to show that almost&lt;br /&gt;
every term possesses this pattern (actually, we have not been able&lt;br /&gt;
to count for big enough terms to have a clear idea of the&lt;br /&gt;
probability of possessing the desired pattern).&lt;br /&gt;
&lt;br /&gt;
Another question, which is also undecidable, and for which finding&lt;br /&gt;
the probability seems to be even more difficult, is to get the&lt;br /&gt;
probability of being weakly normalizable i.e. there is a sequence&lt;br /&gt;
of reduction that terminates.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Combinatory logic is another programming language  related to the&lt;br /&gt;
lambda calculus. It is a way of coding lambda terms without using&lt;br /&gt;
bound variables. The coding is fair for the questions we are&lt;br /&gt;
concerned with in the sense that there are translations in both&lt;br /&gt;
directions which, for example, preserve the property of being SN.&lt;br /&gt;
We have also studied this language and, surprisingly, the results&lt;br /&gt;
are very different from those for the lambda calculus. For example&lt;br /&gt;
we show that, for every fixed term t_0,  almost every term possess&lt;br /&gt;
t_0 as a sub-term and this of course implies that almost every&lt;br /&gt;
term is non SN. Note that the increase of size in the translation&lt;br /&gt;
from the lambda calculus to combinatory logic is not known (we&lt;br /&gt;
only have a lower bound) and thus results for combinatory logic&lt;br /&gt;
cannot be used to get results for the lambda calculus.&lt;br /&gt;
&lt;br /&gt;
The organization of the paper is as follows. Section ?? briefly&lt;br /&gt;
recalls known results for Turing machines and cellular automata.&lt;br /&gt;
Section ?? shows that, in combinatory logic, every fixed term&lt;br /&gt;
appears in almost every term. In section ?? we recall the basic&lt;br /&gt;
definitions of the lambda calculus and we discuss the various&lt;br /&gt;
possibilities for counting the size of a term and the probability&lt;br /&gt;
measure we put on sets of terms. Section ?? gives the&lt;br /&gt;
combinatorial results we will need in our proofs and, in&lt;br /&gt;
particular, the lower and upper bounds for the number of terms of&lt;br /&gt;
size n. It also introduces Catalan and Motzkin numbers and the&lt;br /&gt;
so-called Lambert function. Our main results, i.e. theorems ??, ??&lt;br /&gt;
and ?? appear in section ?? Section ?? gives experimental results&lt;br /&gt;
for questions for which we have no proof. Finally, section ???&lt;br /&gt;
gives open questions and future work. The detailed proofs are&lt;br /&gt;
given in an appendix.&lt;br /&gt;
&lt;br /&gt;
== Known results for Turing machines and cellular automata ==&lt;br /&gt;
&lt;br /&gt;
== Lambert function, Catalan and Motzkin numbers ==&lt;br /&gt;
&lt;br /&gt;
=== Catalan numbers ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; : Catalan numbers &lt;br /&gt;
&lt;br /&gt;
Usual equivalent: &amp;lt;math&amp;gt;C(n) \sim \frac{4^n}{n^{3/2}\sqrt{\pi}}&amp;lt;/math&amp;gt; which is obtained using Strirling formula.&lt;br /&gt;
However, using stirling series: &amp;lt;math&amp;gt;&lt;br /&gt;
  n!=\sqrt{2\pi n}\left({n\over e}\right)^n&lt;br /&gt;
  \left(&lt;br /&gt;
   1&lt;br /&gt;
   +{1\over12n}&lt;br /&gt;
   +{1\over288n^2}&lt;br /&gt;
   -{139\over51840n^3}&lt;br /&gt;
   -{571\over2488320n^4}&lt;br /&gt;
   + \cdots&lt;br /&gt;
  \right)&lt;br /&gt;
 &amp;lt;/math&amp;gt;, we get that for &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; we have &amp;lt;math&amp;gt;\sqrt{2\pi n}\left({n\over e}\right)^n \leq n! \leq \frac{7}{6}\sqrt{2\pi n}\left({n\over e}\right)^n&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, using this and &amp;lt;math&amp;gt;\left(\frac{n}{n+1}\right)^{n} &amp;gt; e^{-1}&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C(n) = \frac{(2n)!}{(n+1)!n!} \geq \frac{36}{49\sqrt{\pi}} \frac{4^n}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; but also for &amp;lt;math&amp;gt;n=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Motzkin numbers===&lt;br /&gt;
&lt;br /&gt;
Let us define &amp;lt;math&amp;gt;M(n,k)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; leafs. We get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n,k) = \frac{(n+k-1)!}{(n-k+1)!(k-1)!k!}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, by summing we define &amp;lt;math&amp;gt;M(n)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and give an equivalent:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n) = \sum_{k=0}^n M(n,k) \sim \left(\frac{1}{3-2\sqrt{2}}\right)^n \frac{1}{n^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lambert W function===&lt;br /&gt;
&lt;br /&gt;
The Lambert function &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; is defined by the equation &amp;lt;math&amp;gt;x = W(x) e ^ {W(x)} &amp;lt;/math&amp;gt;&lt;br /&gt;
which has a unique solution in &amp;lt;math&amp;gt;\mathbb{R}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;x \geq e&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x)&amp;lt;/math&amp;gt; which implies that &lt;br /&gt;
&amp;lt;math&amp;gt;W(x) \sim \ln(x)&amp;lt;/math&amp;gt; near &amp;lt;math&amp;gt;+\infty&amp;lt;/math&amp;gt;. To prove this, it is enough to remark that&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;(\ln(x) - \ln(\ln(x))e^{\ln(x)-\ln(\ln(x))} = x \left(1 - \frac{\ln(\ln(x))}{\ln(x)}\right) \leq x \leq x \ln(x) = \ln(x) e^{\ln(x)} &amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is not precise enough for our purpose. Using one step of the Newton method from &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt;, we can find a better upper bound for &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; because &amp;lt;math&amp;gt;y \mapsto y e^y&amp;lt;/math&amp;gt; is increasing and convex. This gives:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, if we define &amp;lt;math&amp;gt;f(y) = y e^y&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;f&#039;(y)=(1+y)e^y&amp;lt;/math&amp;gt; and therefore, newton&#039;s method from &amp;lt;math&amp;gt;A = \ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt; gives a point at position:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;&lt;br /&gt;
A - \frac{f(A) - x}{f&#039;(A)} &lt;br /&gt;
  = A +  \frac{x \ln(\ln(x))}{\ln(x)} \frac{\ln(x)}{x(\ln(x) - \ln(\ln(x)) + 1)}&lt;br /&gt;
  = A +  \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1} &lt;br /&gt;
&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, we show that for &amp;lt;math&amp;gt;x\geq e&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + 1&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, for &amp;lt;math&amp;gt;x &amp;gt; 1&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;e^{\sqrt{ex}} \geq 1 + \sqrt{ex} + \frac{ex}{2} \geq x&amp;lt;/math&amp;gt;, which implies&lt;br /&gt;
&amp;lt;math&amp;gt;ex \geq \ln^2(x)&amp;lt;/math&amp;gt; and therefore &amp;lt;math&amp;gt;\ln(x) - \ln\ln(x) + 1 \geq \ln\ln(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==  combinatory logic ==&lt;br /&gt;
&lt;br /&gt;
Basically the paper already written by Marek&lt;br /&gt;
&lt;br /&gt;
+ the following&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As we will see in section ??, theorem ?? does not holds for the Lambda calculus. This may be surprising since there are translations between these systems which respect many properties (for exemple the one of being terminating). However these translations do not preserve the size. &lt;br /&gt;
&lt;br /&gt;
The translation T from combinatory logic to lambda calculus is linear, i.e. there is a constant k such that, for all terms, &amp;lt;math&amp;gt;size(T(t) \leq k.size(t)&amp;lt;/math&amp;gt; but the translation T&#039; in the other direction is not linear. As far as we know, there is no known bound on the size of T&#039;(t) but it is not difficult to find exemples where size(T&#039;(t)) is of order &amp;lt;math&amp;gt;size(t)^3&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The point is that T&#039; has to code the binding in some way and this takes place. It will be interesting to compare the size of T&#039;(t) with the one of t using other notion of size than the usual one. See section ?? for some complement.&lt;br /&gt;
&lt;br /&gt;
== Generality on lambda calculus ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition &lt;br /&gt;
&lt;br /&gt;
The set &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt; of lambda terms (or,&lt;br /&gt;
simply, terms) is defined by the following grammar&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;t, u  := Var \ \mid \ \lambda x.t \ \mid \ (t \ u)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To be able to define the notion of a &#039;&#039;random&#039;&#039; term we&lt;br /&gt;
have to define a distribution law on &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt;. There are many&lt;br /&gt;
possibilities for that. We choose here the simplest one. Note that this is the one for which, at least at present,  we are&lt;br /&gt;
able to prove some results. It is based on densities. For that we&lt;br /&gt;
first have to define the &#039;&#039;size&#039;&#039; of a term.&lt;br /&gt;
&lt;br /&gt;
The usual&lt;br /&gt;
definition is the following.&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
The size (denoted as &amp;lt;math&amp;gt;size_1(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
rules.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(\lambda x.t)=size_1(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1((t \ u))=size_1(t)+size_1(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the rest of the paper we will use another definition (denoted&lt;br /&gt;
as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt;) which is similar but  gives simpler computations.&lt;br /&gt;
We believe (but we have not yet checked the details) that, with&lt;br /&gt;
&amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt; we would have similar results. The&lt;br /&gt;
computation, with &amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt;,  of the upper and lower&lt;br /&gt;
bounds of the number of terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; will be done&lt;br /&gt;
in section ??&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
The size (denoted as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt; or, more simply &amp;lt;math&amp;gt;size(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
rules.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(\lambda x.t)=size_0(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0((t \ u))=size_0(t)+size_0(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These definitions of the size are, for the implementation point of&lt;br /&gt;
view, not realistic because, in case a term has a lot of distinct&lt;br /&gt;
variables, it is not realistic to use a single bit to code them.&lt;br /&gt;
The usual way to implement this coding is to replace the names of&lt;br /&gt;
variables by  their so called de Bruijn indices: a variable is&lt;br /&gt;
replaced by the number of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; that occur, on the&lt;br /&gt;
path from the variable to the root, between the variable and the&lt;br /&gt;
&amp;lt;math&amp;gt;lambda&amp;lt;/math&amp;gt; that binds it. Note that, in this case,&lt;br /&gt;
different occurrences of the same variable may be represented by&lt;br /&gt;
different indices.&lt;br /&gt;
&lt;br /&gt;
Choosing the way we code these de Bruijn indices gives different&lt;br /&gt;
other ways of defining the size of a term. This can be done in the&lt;br /&gt;
following ways&lt;br /&gt;
&lt;br /&gt;
- Use unary notation, i.e. the size of the index &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;&lt;br /&gt;
simply is &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; itself&lt;br /&gt;
&lt;br /&gt;
- Use optimal binary notation, i.e. the size of the index&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;log_2(n)&amp;lt;/math&amp;gt; i.e. the logarithm of&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; in base 2.&lt;br /&gt;
&lt;br /&gt;
- Use uniform binary notation, i.e. the size of an index is the&lt;br /&gt;
logarithm, in base 2, of the number of leaves of the term.&lt;br /&gt;
&lt;br /&gt;
Remark&lt;br /&gt;
&lt;br /&gt;
See section ?? for a discusion about these different size.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; be an integer. We denote by &amp;lt;math&amp;gt;\Lambda_n&amp;lt;/math&amp;gt; the set of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; terms of size n.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let A be a set of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; terms. &lt;br /&gt;
&lt;br /&gt;
1) We denote by &amp;lt;math&amp;gt;\#(A)&amp;lt;/math&amp;gt; the cardinality of A.&lt;br /&gt;
&lt;br /&gt;
2) We denote by &amp;lt;math&amp;gt;d(A)&amp;lt;/math&amp;gt; the limit, for n going to &amp;lt;math&amp;gt;\infty&amp;lt;/math&amp;gt;, &lt;br /&gt;
of &amp;lt;math&amp;gt;\frac{\#(A\cap \Lambda_n)}{\#(\Lambda_n)}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Remark&lt;br /&gt;
&lt;br /&gt;
Note that d is not exactly a measure since &amp;lt;math&amp;gt;d(A)&amp;lt;/math&amp;gt; is undefined if the previous limit does not exist&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let P be a property of terms. We will say that almost every term satisfies P &lt;br /&gt;
(this will be also stated as P holds a.e.) if&lt;br /&gt;
&amp;lt;math&amp;gt;d(\{t \ | \ P(t) holds\})=1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== generating functions ==&lt;br /&gt;
&lt;br /&gt;
this does not work (by now) because radius of convergence 0&lt;br /&gt;
&lt;br /&gt;
no known results for the number of terms of size n (denoted &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
== our results ==&lt;br /&gt;
&lt;br /&gt;
(the proof of result of section k needs the result of section (k-1))&lt;br /&gt;
&lt;br /&gt;
=== Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
For the lower bound, we will first count the number &amp;lt;math&amp;gt;LB(n,k)&amp;lt;/math&amp;gt; of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; starting with &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas and having no other lambda below. This means that the lower part of the term is a binary tree of size &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; with&lt;br /&gt;
&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; possibility for each leaf. Therefore we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) = C(n-k) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And therefore, for &amp;lt;math&amp;gt;n &amp;gt; k&amp;lt;/math&amp;gt;, using our lower bound for &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n + 1 \geq n - k + 1&amp;lt;/math&amp;gt;, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) \geq K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;K=\frac{36}{49\sqrt{\pi}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed, we define &amp;lt;math&amp;gt;f(\alpha) = \left(4n\alpha\right)^{n(1-\alpha) + 1}&amp;lt;/math&amp;gt; (so &amp;lt;math&amp;gt;LB(n,k) \geq \frac{K}{(n+1)^\frac{3}{2}} f\left(\frac{k}{n}\right)&amp;lt;/math&amp;gt;) and look for the maximum of this function. We have &amp;lt;math&amp;gt;f&#039;(\alpha) = f(\alpha) \left(-n\ln(4n\alpha) +\frac{n(1-\alpha) + 1}{\alpha}\right)&amp;lt;/math&amp;gt;. Thus, &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\frac{n+1}{n\alpha}e^{\frac{n+1}{n\alpha}}\geq 4e(n+1)&amp;lt;/math&amp;gt;. The Lambert function begin increasing this means that &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\alpha \leq \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;f(\alpha)&amp;lt;/math&amp;gt; reaches a maximum for &amp;lt;math&amp;gt;\alpha = \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This means that &amp;lt;math&amp;gt;(4k)^{n-k}&amp;lt;/math&amp;gt; reaches its maximum for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed when &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;&lt;br /&gt;
is near to &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; which is likely not to be an integer. However, there are at least &amp;lt;math&amp;gt;\left\lfloor \frac{n (\ln(\ln(4en)) - 1)}{\ln^2(4en)}\right\rfloor&amp;lt;/math&amp;gt; integer between &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\frac{n+1}{\ln(4e(n+1))}&amp;lt;/math&amp;gt;. Indeed, using our inequalities on Lambert W function, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}-\frac{n+1}{\ln(4e(n+1))} = \frac{(n+1) (\ln(4e(n+1)) - W(4e(n+1)))}{W(4e(n+1))\ln(4e(n+1))} \geq \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, we get the following lowerbound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \sum_{k=1}^{n} LB(n,k) \geq \sum_{k=\lceil\frac{n+1}{\ln(4e(n+1))}\rceil}^{\lfloor\frac{n+1}{W(4e(n+1))}\rfloor} K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}} \geq K \left\lfloor \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}\right\rfloor \frac{\left(\frac{4(n+1)}{\ln(4e(n+1))}\right)^{n-\frac{n+1}{\ln(4e(n+1))}+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To simplify, using the fact that &amp;lt;math&amp;gt;\lim_{n\to +\infty}\left(\frac{\ln(n)}{\ln(4en)}\right)^n = 0&amp;lt;/math&amp;gt; and taking &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; large enough, we have the following lowerbound:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \frac{\sqrt{n}}{\ln^3(n)}\left(\frac{4n}{\ln(n)}\right)^{n-\frac{n}{\ln(n)}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We now compute an upper bound &amp;lt;math&amp;gt;UB(n,k)&amp;lt;/math&amp;gt; for the number of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with exactly &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas (that is with &amp;lt;math&amp;gt;n - k + 1&amp;lt;/math&amp;gt; leaves using the Motzkin numbers and allowing any lambda to bind any variable (regardless of the real scope):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;UB(n,k) = M(n,n-k+1) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we sum this for all possible &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and get an upper bound of &amp;lt;math&amp;gt;k^{n-k+1}&amp;lt;/math&amp;gt; using Lambert function as for the lower bound, we get the following upper bound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \leq M(n) \left(\frac{n+1}{W(e(n+1))}\right)^{n-\frac{n+1}{W(e(n+1))} + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The ration between our upper bound and lower bound is equivalent to (NEEDS FURTHER CHECKING):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\left(\frac{1}{4(3-2\sqrt{2})}\right)^n\frac{\ln^3(n)}{n^2} \simeq 1.46^n\frac{\ln^3(n)}{n^2}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== upper and lower bounds for number of lambdas in a term of size n ===&lt;br /&gt;
&lt;br /&gt;
=== Jakub&#039;s trik : at least 1 lambda in head position ===&lt;br /&gt;
&lt;br /&gt;
=== at least &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; lambdas in head position and number of lambdas in one path ===&lt;br /&gt;
&lt;br /&gt;
Remark: (may be 4) can be done directly without 3))&lt;br /&gt;
&lt;br /&gt;
=== each of the  &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; head lambdas really bind &amp;quot;many&amp;quot;  occurrences of the variable ===&lt;br /&gt;
&lt;br /&gt;
=== every fixed closed term (including the identity !) does not appear in a random term (in fact we have much more than that) ===&lt;br /&gt;
&lt;br /&gt;
comment : so different situation in combinatory logic and lambda calculus ; the coding uses a big size so need to count variables in a different way&lt;br /&gt;
&lt;br /&gt;
== Experiments ==&lt;br /&gt;
&lt;br /&gt;
results of the experiments we have done&lt;br /&gt;
&lt;br /&gt;
some experiments that have to be done : e.g. density of terms having &amp;lt;math&amp;gt;\lambda x.y&amp;lt;/math&amp;gt; or big Omega pattern ...&lt;br /&gt;
&lt;br /&gt;
== to be done ==&lt;br /&gt;
&lt;br /&gt;
Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; with other size for variables especially one, binary with fixed size&lt;br /&gt;
&lt;br /&gt;
== Open questions and Future work ==&lt;br /&gt;
&lt;br /&gt;
.....&lt;/div&gt;</summary>
		<author><name>René David</name></author>
	</entry>
	<entry>
		<id>http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2715</id>
		<title>Lambda counting</title>
		<link rel="alternate" type="text/html" href="http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2715"/>
		<updated>2008-10-21T08:28:18Z</updated>

		<summary type="html">&lt;p&gt;René David : /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
what kind of properties : structural (for functional programs), behaviour (SN, weakly normalizable, ...&lt;br /&gt;
&lt;br /&gt;
references to known results on : turing machines, cellular automata&lt;br /&gt;
&lt;br /&gt;
we concentrate on combinatory logic, lambda calculus)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This paper adresses the following question. Having a (theoritical) programming language and a property of programs in that language. What is the probability that a random program satisfies the given property ? In particular, is it the case that almost every random program satisfies the desired property i.e. the probability is 1 ? &lt;br /&gt;
This question has some known results for Turing machines and cellular automata. Some of them will be given in section ??.&lt;br /&gt;
&lt;br /&gt;
In this introduction we consider that this notion of probabilty is, at least intuitively, sufficiently clear  but, of course, this will have to be made precise.&lt;br /&gt;
&lt;br /&gt;
We will consider this question for functional programming languages. For this kind of languages we can consider various properties. Some concern the structural of the program, some concern its behaviour.&lt;br /&gt;
&lt;br /&gt;
The simplest such language is the lambda calculus. &lt;br /&gt;
Some experiments have been done for it (see for example ...) which clearly indicates that, for example, almost every closed lambda term begins with a &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; but, as far as we know, there is no proved result of this form. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This paper proves some highly non trivial results of this form. In particular we show that almost every closed lambda term begins with &amp;quot;many&amp;quot; &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; (the precise meaning of this is given in theorem ??), that these &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; bound &amp;quot;many&amp;quot; occurences of the corresponding variables theorem ??) and that, given any fixed closed term, almost &#039;&#039;no&#039;&#039; &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt;-term has this term as a sub-term. &lt;br /&gt;
&lt;br /&gt;
Our original motivation was to consider the property of being terminating. Is a random term strongly normalizable (SN for short) i.e. every sequence of reduction terminates ? This question is, at present, unsolved and  the experiments we have done do not even give an idea of what the result should be. It is known that being SN is an undecidable question and it is thus not easy to count the number of SN terms of big size. It is clear that having &amp;lt;math&amp;gt;(\delta \ \delta)&amp;lt;/math&amp;gt; as a sub-term is a sufficient (but not necessary) condition for being non SN but as the experiments have shown (and as we have proved) almost no terms contains &amp;lt;math&amp;gt;(\delta \ \delta)&amp;lt;/math&amp;gt;  and this is thus useless to have a rsult for non SN. On the opposite direction, it is known that, if a term t is not SN, then a pattern &amp;quot;looking like&amp;quot; &amp;lt;math&amp;gt;(\delta \ \delta)&amp;lt;/math&amp;gt; (the precise meaning will be given in section ??)  must appear in t but the experiments seem to show that almost every term possesses this pattern (actually, we have not been able to count for big enough terms to have a clear idea of the probabilty of possessing the desired pattern). &lt;br /&gt;
&lt;br /&gt;
Another question, which is also undecidable, and for which finding the probability seems to be even more difficult is to get the probability of beeing weakly normalizable i.e. there is a sequence of reduction that terminates.&lt;br /&gt;
&lt;br /&gt;
Combinatory logic is another programming language that is very realted to the lambda calculus&lt;br /&gt;
&lt;br /&gt;
== Known results for Turing machines and cellular automata ==&lt;br /&gt;
&lt;br /&gt;
== Lambert function, Catalan and Motzkin numbers ==&lt;br /&gt;
&lt;br /&gt;
=== Catalan numbers ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; : Catalan numbers &lt;br /&gt;
&lt;br /&gt;
Usual equivalent: &amp;lt;math&amp;gt;C(n) \sim \frac{4^n}{n^{3/2}\sqrt{\pi}}&amp;lt;/math&amp;gt; which is obtained using Strirling formula.&lt;br /&gt;
However, using stirling series: &amp;lt;math&amp;gt;&lt;br /&gt;
  n!=\sqrt{2\pi n}\left({n\over e}\right)^n&lt;br /&gt;
  \left(&lt;br /&gt;
   1&lt;br /&gt;
   +{1\over12n}&lt;br /&gt;
   +{1\over288n^2}&lt;br /&gt;
   -{139\over51840n^3}&lt;br /&gt;
   -{571\over2488320n^4}&lt;br /&gt;
   + \cdots&lt;br /&gt;
  \right)&lt;br /&gt;
 &amp;lt;/math&amp;gt;, we get that for &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; we have &amp;lt;math&amp;gt;\sqrt{2\pi n}\left({n\over e}\right)^n \leq n! \leq \frac{7}{6}\sqrt{2\pi n}\left({n\over e}\right)^n&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, using this and &amp;lt;math&amp;gt;\left(\frac{n}{n+1}\right)^{n} &amp;gt; e^{-1}&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C(n) = \frac{(2n)!}{(n+1)!n!} \geq \frac{36}{49\sqrt{\pi}} \frac{4^n}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; but also for &amp;lt;math&amp;gt;n=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Motzkin numbers===&lt;br /&gt;
&lt;br /&gt;
Let us define &amp;lt;math&amp;gt;M(n,k)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; leafs. We get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n,k) = \frac{(n+k-1)!}{(n-k+1)!(k-1)!k!}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, by summing we define &amp;lt;math&amp;gt;M(n)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and give an equivalent:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n) = \sum_{k=0}^n M(n,k) \sim \left(\frac{1}{3-2\sqrt{2}}\right)^n \frac{1}{n^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lambert W function===&lt;br /&gt;
&lt;br /&gt;
The Lambert function &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; is defined by the equation &amp;lt;math&amp;gt;x = W(x) e ^ {W(x)} &amp;lt;/math&amp;gt;&lt;br /&gt;
which has a unique solution in &amp;lt;math&amp;gt;\mathbb{R}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;x \geq e&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x)&amp;lt;/math&amp;gt; which implies that &lt;br /&gt;
&amp;lt;math&amp;gt;W(x) \sim \ln(x)&amp;lt;/math&amp;gt; near &amp;lt;math&amp;gt;+\infty&amp;lt;/math&amp;gt;. To prove this, it is enough to remark that&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;(\ln(x) - \ln(\ln(x))e^{\ln(x)-\ln(\ln(x))} = x \left(1 - \frac{\ln(\ln(x))}{\ln(x)}\right) \leq x \leq x \ln(x) = \ln(x) e^{\ln(x)} &amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is not precise enough for our purpose. Using one step of the Newton method from &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt;, we can find a better upper bound for &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; because &amp;lt;math&amp;gt;y \mapsto y e^y&amp;lt;/math&amp;gt; is increasing and convex. This gives:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, if we define &amp;lt;math&amp;gt;f(y) = y e^y&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;f&#039;(y)=(1+y)e^y&amp;lt;/math&amp;gt; and therefore, newton&#039;s method from &amp;lt;math&amp;gt;A = \ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt; gives a point at position:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;&lt;br /&gt;
A - \frac{f(A) - x}{f&#039;(A)} &lt;br /&gt;
  = A +  \frac{x \ln(\ln(x))}{\ln(x)} \frac{\ln(x)}{x(\ln(x) - \ln(\ln(x)) + 1)}&lt;br /&gt;
  = A +  \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1} &lt;br /&gt;
&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, we show that for &amp;lt;math&amp;gt;x\geq e&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + 1&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, for &amp;lt;math&amp;gt;x &amp;gt; 1&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;e^{\sqrt{ex}} \geq 1 + \sqrt{ex} + \frac{ex}{2} \geq x&amp;lt;/math&amp;gt;, which implies&lt;br /&gt;
&amp;lt;math&amp;gt;ex \geq \ln^2(x)&amp;lt;/math&amp;gt; and therefore &amp;lt;math&amp;gt;\ln(x) - \ln\ln(x) + 1 \geq \ln\ln(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==  combinatory logic ==&lt;br /&gt;
&lt;br /&gt;
Basically the paper already written by Marek&lt;br /&gt;
&lt;br /&gt;
+ the following&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As we will see in section ??, theorem ?? does not holds for the Lambda calculus. This may be surprising since there are translations between these systems which respect many properties (for exemple the one of being terminating). However these translations do not preserve the size. &lt;br /&gt;
&lt;br /&gt;
The translation T from combinatory logic to lambda calculus is linear, i.e. there is a constant k such that, for all terms, &amp;lt;math&amp;gt;size(T(t) \leq k.size(t)&amp;lt;/math&amp;gt; but the translation T&#039; in the other direction is not linear. As far as we know, there is no known bound on the size of T&#039;(t) but it is not difficult to find exemples where size(T&#039;(t)) is of order &amp;lt;math&amp;gt;size(t)^3&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The point is that T&#039; has to code the binding in some way and this takes place. It will be interesting to compare the size of T&#039;(t) with the one of t using other notion of size than the usual one. See section ?? for some complement.&lt;br /&gt;
&lt;br /&gt;
== Generality on lambda calculus ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition &lt;br /&gt;
&lt;br /&gt;
The set &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt; of lambda terms (or,&lt;br /&gt;
simply, terms) is defined by the following grammar&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;t, u  := Var \ \mid \ \lambda x.t \ \mid \ (t \ u)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To be able to define the notion of a &#039;&#039;random&#039;&#039; term we&lt;br /&gt;
have to define a distribution law on &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt;. There are many&lt;br /&gt;
possibilities for that. We choose here the simplest one. Note that this is the one for which, at least at present,  we are&lt;br /&gt;
able to prove some results. It is based on densities. For that we&lt;br /&gt;
first have to define the &#039;&#039;size&#039;&#039; of a term.&lt;br /&gt;
&lt;br /&gt;
The usual&lt;br /&gt;
definition is the following.&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
The size (denoted as &amp;lt;math&amp;gt;size_1(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
rules.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(\lambda x.t)=size_1(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1((t \ u))=size_1(t)+size_1(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the rest of the paper we will use another definition (denoted&lt;br /&gt;
as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt;) which is similar but  gives simpler computations.&lt;br /&gt;
We believe (but we have not yet checked the details) that, with&lt;br /&gt;
&amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt; we would have similar results. The&lt;br /&gt;
computation, with &amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt;,  of the upper and lower&lt;br /&gt;
bounds of the number of terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; will be done&lt;br /&gt;
in section ??&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
The size (denoted as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt; or, more simply &amp;lt;math&amp;gt;size(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
rules.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(\lambda x.t)=size_0(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0((t \ u))=size_0(t)+size_0(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These definitions of the size are, for the implementation point of&lt;br /&gt;
view, not realistic because, in case a term has a lot of distinct&lt;br /&gt;
variables, it is not realistic to use a single bit to code them.&lt;br /&gt;
The usual way to implement this coding is to replace the names of&lt;br /&gt;
variables by  their so called de Bruijn indices: a variable is&lt;br /&gt;
replaced by the number of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; that occur, on the&lt;br /&gt;
path from the variable to the root, between the variable and the&lt;br /&gt;
&amp;lt;math&amp;gt;lambda&amp;lt;/math&amp;gt; that binds it. Note that, in this case,&lt;br /&gt;
different occurrences of the same variable may be represented by&lt;br /&gt;
different indices.&lt;br /&gt;
&lt;br /&gt;
Choosing the way we code these de Bruijn indices gives different&lt;br /&gt;
other ways of defining the size of a term. This can be done in the&lt;br /&gt;
following ways&lt;br /&gt;
&lt;br /&gt;
- Use unary notation, i.e. the size of the index &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;&lt;br /&gt;
simply is &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; itself&lt;br /&gt;
&lt;br /&gt;
- Use optimal binary notation, i.e. the size of the index&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;log_2(n)&amp;lt;/math&amp;gt; i.e. the logarithm of&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; in base 2.&lt;br /&gt;
&lt;br /&gt;
- Use uniform binary notation, i.e. the size of an index is the&lt;br /&gt;
logarithm, in base 2, of the number of leaves of the term.&lt;br /&gt;
&lt;br /&gt;
Remark&lt;br /&gt;
&lt;br /&gt;
See section ?? for a discusion about these different size.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; be an integer. We denote by &amp;lt;math&amp;gt;\Lambda_n&amp;lt;/math&amp;gt; the set of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; terms of size n.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let A be a set of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; terms. &lt;br /&gt;
&lt;br /&gt;
1) We denote by &amp;lt;math&amp;gt;\#(A)&amp;lt;/math&amp;gt; the cardinality of A.&lt;br /&gt;
&lt;br /&gt;
2) We denote by &amp;lt;math&amp;gt;d(A)&amp;lt;/math&amp;gt; the limit, for n going to &amp;lt;math&amp;gt;\infty&amp;lt;/math&amp;gt;, &lt;br /&gt;
of &amp;lt;math&amp;gt;\frac{\#(A\cap \Lambda_n)}{\#(\Lambda_n)}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Remark&lt;br /&gt;
&lt;br /&gt;
Note that d is not exactly a measure since &amp;lt;math&amp;gt;d(A)&amp;lt;/math&amp;gt; is undefined if the previous limit does not exist&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let P be a property of terms. We will say that almost every term satisfies P &lt;br /&gt;
(this will be also stated as P holds a.e.) if&lt;br /&gt;
&amp;lt;math&amp;gt;d(\{t \ | \ P(t) holds\})=1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== generating functions ==&lt;br /&gt;
&lt;br /&gt;
this does not work (by now) because radius of convergence 0&lt;br /&gt;
&lt;br /&gt;
no known results for the number of terms of size n (denoted &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
== our results ==&lt;br /&gt;
&lt;br /&gt;
(the proof of result of section k needs the result of section (k-1))&lt;br /&gt;
&lt;br /&gt;
=== Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
For the lower bound, we will first count the number &amp;lt;math&amp;gt;LB(n,k)&amp;lt;/math&amp;gt; of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; starting with &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas and having no other lambda below. This means that the lower part of the term is a binary tree of size &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; with&lt;br /&gt;
&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; possibility for each leaf. Therefore we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) = C(n-k) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And therefore, for &amp;lt;math&amp;gt;n &amp;gt; k&amp;lt;/math&amp;gt;, using our lower bound for &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n + 1 \geq n - k + 1&amp;lt;/math&amp;gt;, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) \geq K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;K=\frac{36}{49\sqrt{\pi}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed, we define &amp;lt;math&amp;gt;f(\alpha) = \left(4n\alpha\right)^{n(1-\alpha) + 1}&amp;lt;/math&amp;gt; (so &amp;lt;math&amp;gt;LB(n,k) \geq \frac{K}{(n+1)^\frac{3}{2}} f\left(\frac{k}{n}\right)&amp;lt;/math&amp;gt;) and look for the maximum of this function. We have &amp;lt;math&amp;gt;f&#039;(\alpha) = f(\alpha) \left(-n\ln(4n\alpha) +\frac{n(1-\alpha) + 1}{\alpha}\right)&amp;lt;/math&amp;gt;. Thus, &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\frac{n+1}{n\alpha}e^{\frac{n+1}{n\alpha}}\geq 4e(n+1)&amp;lt;/math&amp;gt;. The Lambert function begin increasing this means that &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\alpha \leq \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;f(\alpha)&amp;lt;/math&amp;gt; reaches a maximum for &amp;lt;math&amp;gt;\alpha = \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This means that &amp;lt;math&amp;gt;(4k)^{n-k}&amp;lt;/math&amp;gt; reaches its maximum for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed when &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;&lt;br /&gt;
is near to &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; which is likely not to be an integer. However, there are at least &amp;lt;math&amp;gt;\left\lfloor \frac{n (\ln(\ln(4en)) - 1)}{\ln^2(4en)}\right\rfloor&amp;lt;/math&amp;gt; integer between &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\frac{n+1}{\ln(4e(n+1))}&amp;lt;/math&amp;gt;. Indeed, using our inequalities on Lambert W function, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}-\frac{n+1}{\ln(4e(n+1))} = \frac{(n+1) (\ln(4e(n+1)) - W(4e(n+1)))}{W(4e(n+1))\ln(4e(n+1))} \geq \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, we get the following lowerbound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \sum_{k=1}^{n} LB(n,k) \geq \sum_{k=\lceil\frac{n+1}{\ln(4e(n+1))}\rceil}^{\lfloor\frac{n+1}{W(4e(n+1))}\rfloor} K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}} \geq K \left\lfloor \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}\right\rfloor \frac{\left(\frac{4(n+1)}{\ln(4e(n+1))}\right)^{n-\frac{n+1}{\ln(4e(n+1))}+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To simplify, using the fact that &amp;lt;math&amp;gt;\lim_{n\to +\infty}\left(\frac{\ln(n)}{\ln(4en)}\right)^n = 0&amp;lt;/math&amp;gt; and taking &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; large enough, we have the following lowerbound:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \frac{\sqrt{n}}{\ln^3(n)}\left(\frac{4n}{\ln(n)}\right)^{n-\frac{n}{\ln(n)}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We now compute an upper bound &amp;lt;math&amp;gt;UB(n,k)&amp;lt;/math&amp;gt; for the number of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with exactly &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas (that is with &amp;lt;math&amp;gt;n - k + 1&amp;lt;/math&amp;gt; leaves using the Motzkin numbers and allowing any lambda to bind any variable (regardless of the real scope):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;UB(n,k) = M(n,n-k+1) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we sum this for all possible &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and get an upper bound of &amp;lt;math&amp;gt;k^{n-k+1}&amp;lt;/math&amp;gt; using Lambert function as for the lower bound, we get the following upper bound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \leq M(n) \left(\frac{n+1}{W(e(n+1))}\right)^{n-\frac{n+1}{W(e(n+1))} + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The ration between our upper bound and lower bound is equivalent to (NEEDS FURTHER CHECKING):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\left(\frac{1}{4(3-2\sqrt{2})}\right)^n\frac{\ln^3(n)}{n^2} \simeq 1.46^n\frac{\ln^3(n)}{n^2}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== upper and lower bounds for number of lambdas in a term of size n ===&lt;br /&gt;
&lt;br /&gt;
=== Jakub&#039;s trik : at least 1 lambda in head position ===&lt;br /&gt;
&lt;br /&gt;
=== at least &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; lambdas in head position and number of lambdas in one path ===&lt;br /&gt;
&lt;br /&gt;
Remark: (may be 4) can be done directly without 3))&lt;br /&gt;
&lt;br /&gt;
=== each of the  &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; head lambdas really bind &amp;quot;many&amp;quot;  occurrences of the variable ===&lt;br /&gt;
&lt;br /&gt;
=== every fixed closed term (including the identity !) does not appear in a random term (in fact we have much more than that) ===&lt;br /&gt;
&lt;br /&gt;
comment : so different situation in combinatory logic and lambda calculus ; the coding uses a big size so need to count variables in a different way&lt;br /&gt;
&lt;br /&gt;
== Experiments ==&lt;br /&gt;
&lt;br /&gt;
results of the experiments we have done&lt;br /&gt;
&lt;br /&gt;
some experiments that have to be done : e.g. density of terms having &amp;lt;math&amp;gt;\lambda x.y&amp;lt;/math&amp;gt; or big Omega pattern ...&lt;br /&gt;
&lt;br /&gt;
== to be done ==&lt;br /&gt;
&lt;br /&gt;
Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; with other size for variables especially one, binary with fixed size&lt;br /&gt;
&lt;br /&gt;
== Open questions and Future work ==&lt;br /&gt;
&lt;br /&gt;
.....&lt;/div&gt;</summary>
		<author><name>René David</name></author>
	</entry>
	<entry>
		<id>http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2714</id>
		<title>Lambda counting</title>
		<link rel="alternate" type="text/html" href="http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2714"/>
		<updated>2008-10-21T08:17:34Z</updated>

		<summary type="html">&lt;p&gt;René David : /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
what kind of properties : structural (for functional programs), behaviour (SN, weakly normalizable, ...&lt;br /&gt;
&lt;br /&gt;
references to known results on : turing machines, cellular automata&lt;br /&gt;
&lt;br /&gt;
we concentrate on combinatory logic, lambda calculus)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This paper adresses the following question. Having a (theoritical) programming language and a property of programs in that language. What is the probability that a random program satisfies the given property ? In particular, is it the case that almost every random program satisfies the desired property i.e. the probability is 1 ? &lt;br /&gt;
This question has some known results for Turing machines and cellular automata. Some of them will be given in section ??.&lt;br /&gt;
&lt;br /&gt;
In this introduction we consider that this notion of probabilty is, at least intuitively, sufficiently clear  but, of course, this will have to be made precise.&lt;br /&gt;
&lt;br /&gt;
We will consider this question for functional programming languages. For this kind of languages we can consider various properties. Some concern the structural of the program, some concern its behaviour.&lt;br /&gt;
&lt;br /&gt;
The simplest such language is the lambda calculus. &lt;br /&gt;
Some experiments have been done for it (see for example ...) which clearly indicates that, for example, almost every closed lambda term begins with a &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; but, as far as we know, there is no proved result of this form. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This paper proves some highly non trivial results of this form. In particular we show that almost every closed lambda term begins with &amp;quot;many&amp;quot; &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; (the precise meaning of this is given in theorem ??), that these &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; bound &amp;quot;many&amp;quot; occurences of the corresponding variables theorem ??) and that, given any fixed closed term, almost &#039;&#039;no&#039;&#039; &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt;-term has this term as a sub-term. &lt;br /&gt;
&lt;br /&gt;
Our original motivation was to consider the property of being terminating. Is a random term strongly normalizable (SN for short)? This question is, at present, unsolved and  the experiments we have done do not even give an idea of what the result should be. It is known that being SN is an undecidable question and it is thus not easy to count the number of SN terms of big size. It is clear that having &amp;lt;math&amp;gt;(\delta \ \delta)&amp;lt;/math&amp;gt; as a sub-term is a sufficient (but not necessary) condition for being non SN but as the experiments have shown (and as we have proved) almost no terms contains &amp;lt;math&amp;gt;(\delta \ \delta)&amp;lt;/math&amp;gt;  and this is thus useless to have a rsult for non SN. On the opposite direction, it is known that, if a term t is not SN, then a pattern &amp;quot;looking like&amp;quot; &amp;lt;math&amp;gt;(\delta \ \delta)&amp;lt;/math&amp;gt; (the precise meaning will be given in sectioon ??)  must appear in t but the experiments seem to show that almost every term possesses this pattern (actually, we have not bee&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Known results for Turing machines and cellular automata ==&lt;br /&gt;
&lt;br /&gt;
== Lambert function, Catalan and Motzkin numbers ==&lt;br /&gt;
&lt;br /&gt;
=== Catalan numbers ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; : Catalan numbers &lt;br /&gt;
&lt;br /&gt;
Usual equivalent: &amp;lt;math&amp;gt;C(n) \sim \frac{4^n}{n^{3/2}\sqrt{\pi}}&amp;lt;/math&amp;gt; which is obtained using Strirling formula.&lt;br /&gt;
However, using stirling series: &amp;lt;math&amp;gt;&lt;br /&gt;
  n!=\sqrt{2\pi n}\left({n\over e}\right)^n&lt;br /&gt;
  \left(&lt;br /&gt;
   1&lt;br /&gt;
   +{1\over12n}&lt;br /&gt;
   +{1\over288n^2}&lt;br /&gt;
   -{139\over51840n^3}&lt;br /&gt;
   -{571\over2488320n^4}&lt;br /&gt;
   + \cdots&lt;br /&gt;
  \right)&lt;br /&gt;
 &amp;lt;/math&amp;gt;, we get that for &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; we have &amp;lt;math&amp;gt;\sqrt{2\pi n}\left({n\over e}\right)^n \leq n! \leq \frac{7}{6}\sqrt{2\pi n}\left({n\over e}\right)^n&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, using this and &amp;lt;math&amp;gt;\left(\frac{n}{n+1}\right)^{n} &amp;gt; e^{-1}&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C(n) = \frac{(2n)!}{(n+1)!n!} \geq \frac{36}{49\sqrt{\pi}} \frac{4^n}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; but also for &amp;lt;math&amp;gt;n=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Motzkin numbers===&lt;br /&gt;
&lt;br /&gt;
Let us define &amp;lt;math&amp;gt;M(n,k)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; leafs. We get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n,k) = \frac{(n+k-1)!}{(n-k+1)!(k-1)!k!}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, by summing we define &amp;lt;math&amp;gt;M(n)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and give an equivalent:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n) = \sum_{k=0}^n M(n,k) \sim \left(\frac{1}{3-2\sqrt{2}}\right)^n \frac{1}{n^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lambert W function===&lt;br /&gt;
&lt;br /&gt;
The Lambert function &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; is defined by the equation &amp;lt;math&amp;gt;x = W(x) e ^ {W(x)} &amp;lt;/math&amp;gt;&lt;br /&gt;
which has a unique solution in &amp;lt;math&amp;gt;\mathbb{R}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;x \geq e&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x)&amp;lt;/math&amp;gt; which implies that &lt;br /&gt;
&amp;lt;math&amp;gt;W(x) \sim \ln(x)&amp;lt;/math&amp;gt; near &amp;lt;math&amp;gt;+\infty&amp;lt;/math&amp;gt;. To prove this, it is enough to remark that&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;(\ln(x) - \ln(\ln(x))e^{\ln(x)-\ln(\ln(x))} = x \left(1 - \frac{\ln(\ln(x))}{\ln(x)}\right) \leq x \leq x \ln(x) = \ln(x) e^{\ln(x)} &amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is not precise enough for our purpose. Using one step of the Newton method from &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt;, we can find a better upper bound for &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; because &amp;lt;math&amp;gt;y \mapsto y e^y&amp;lt;/math&amp;gt; is increasing and convex. This gives:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, if we define &amp;lt;math&amp;gt;f(y) = y e^y&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;f&#039;(y)=(1+y)e^y&amp;lt;/math&amp;gt; and therefore, newton&#039;s method from &amp;lt;math&amp;gt;A = \ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt; gives a point at position:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;&lt;br /&gt;
A - \frac{f(A) - x}{f&#039;(A)} &lt;br /&gt;
  = A +  \frac{x \ln(\ln(x))}{\ln(x)} \frac{\ln(x)}{x(\ln(x) - \ln(\ln(x)) + 1)}&lt;br /&gt;
  = A +  \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1} &lt;br /&gt;
&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, we show that for &amp;lt;math&amp;gt;x\geq e&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + 1&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, for &amp;lt;math&amp;gt;x &amp;gt; 1&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;e^{\sqrt{ex}} \geq 1 + \sqrt{ex} + \frac{ex}{2} \geq x&amp;lt;/math&amp;gt;, which implies&lt;br /&gt;
&amp;lt;math&amp;gt;ex \geq \ln^2(x)&amp;lt;/math&amp;gt; and therefore &amp;lt;math&amp;gt;\ln(x) - \ln\ln(x) + 1 \geq \ln\ln(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==  combinatory logic ==&lt;br /&gt;
&lt;br /&gt;
Basically the paper already written by Marek&lt;br /&gt;
&lt;br /&gt;
+ the following&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As we will see in section ??, theorem ?? does not holds for the Lambda calculus. This may be surprising since there are translations between these systems which respect many properties (for exemple the one of being terminating). However these translations do not preserve the size. &lt;br /&gt;
&lt;br /&gt;
The translation T from combinatory logic to lambda calculus is linear, i.e. there is a constant k such that, for all terms, &amp;lt;math&amp;gt;size(T(t) \leq k.size(t)&amp;lt;/math&amp;gt; but the translation T&#039; in the other direction is not linear. As far as we know, there is no known bound on the size of T&#039;(t) but it is not difficult to find exemples where size(T&#039;(t)) is of order &amp;lt;math&amp;gt;size(t)^3&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The point is that T&#039; has to code the binding in some way and this takes place. It will be interesting to compare the size of T&#039;(t) with the one of t using other notion of size than the usual one. See section ?? for some complement.&lt;br /&gt;
&lt;br /&gt;
== Generality on lambda calculus ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition &lt;br /&gt;
&lt;br /&gt;
The set &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt; of lambda terms (or,&lt;br /&gt;
simply, terms) is defined by the following grammar&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;t, u  := Var \ \mid \ \lambda x.t \ \mid \ (t \ u)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To be able to define the notion of a &#039;&#039;random&#039;&#039; term we&lt;br /&gt;
have to define a distribution law on &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt;. There are many&lt;br /&gt;
possibilities for that. We choose here the simplest one. Note that this is the one for which, at least at present,  we are&lt;br /&gt;
able to prove some results. It is based on densities. For that we&lt;br /&gt;
first have to define the &#039;&#039;size&#039;&#039; of a term.&lt;br /&gt;
&lt;br /&gt;
The usual&lt;br /&gt;
definition is the following.&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
The size (denoted as &amp;lt;math&amp;gt;size_1(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
rules.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(\lambda x.t)=size_1(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1((t \ u))=size_1(t)+size_1(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the rest of the paper we will use another definition (denoted&lt;br /&gt;
as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt;) which is similar but  gives simpler computations.&lt;br /&gt;
We believe (but we have not yet checked the details) that, with&lt;br /&gt;
&amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt; we would have similar results. The&lt;br /&gt;
computation, with &amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt;,  of the upper and lower&lt;br /&gt;
bounds of the number of terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; will be done&lt;br /&gt;
in section ??&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
The size (denoted as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt; or, more simply &amp;lt;math&amp;gt;size(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
rules.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(\lambda x.t)=size_0(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0((t \ u))=size_0(t)+size_0(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These definitions of the size are, for the implementation point of&lt;br /&gt;
view, not realistic because, in case a term has a lot of distinct&lt;br /&gt;
variables, it is not realistic to use a single bit to code them.&lt;br /&gt;
The usual way to implement this coding is to replace the names of&lt;br /&gt;
variables by  their so called de Bruijn indices: a variable is&lt;br /&gt;
replaced by the number of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; that occur, on the&lt;br /&gt;
path from the variable to the root, between the variable and the&lt;br /&gt;
&amp;lt;math&amp;gt;lambda&amp;lt;/math&amp;gt; that binds it. Note that, in this case,&lt;br /&gt;
different occurrences of the same variable may be represented by&lt;br /&gt;
different indices.&lt;br /&gt;
&lt;br /&gt;
Choosing the way we code these de Bruijn indices gives different&lt;br /&gt;
other ways of defining the size of a term. This can be done in the&lt;br /&gt;
following ways&lt;br /&gt;
&lt;br /&gt;
- Use unary notation, i.e. the size of the index &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;&lt;br /&gt;
simply is &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; itself&lt;br /&gt;
&lt;br /&gt;
- Use optimal binary notation, i.e. the size of the index&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;log_2(n)&amp;lt;/math&amp;gt; i.e. the logarithm of&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; in base 2.&lt;br /&gt;
&lt;br /&gt;
- Use uniform binary notation, i.e. the size of an index is the&lt;br /&gt;
logarithm, in base 2, of the number of leaves of the term.&lt;br /&gt;
&lt;br /&gt;
Remark&lt;br /&gt;
&lt;br /&gt;
See section ?? for a discusion about these different size.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; be an integer. We denote by &amp;lt;math&amp;gt;\Lambda_n&amp;lt;/math&amp;gt; the set of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; terms of size n.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let A be a set of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; terms. &lt;br /&gt;
&lt;br /&gt;
1) We denote by &amp;lt;math&amp;gt;\#(A)&amp;lt;/math&amp;gt; the cardinality of A.&lt;br /&gt;
&lt;br /&gt;
2) We denote by &amp;lt;math&amp;gt;d(A)&amp;lt;/math&amp;gt; the limit, for n going to &amp;lt;math&amp;gt;\infty&amp;lt;/math&amp;gt;, &lt;br /&gt;
of &amp;lt;math&amp;gt;\frac{\#(A\cap \Lambda_n)}{\#(\Lambda_n)}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Remark&lt;br /&gt;
&lt;br /&gt;
Note that d is not exactly a measure since &amp;lt;math&amp;gt;d(A)&amp;lt;/math&amp;gt; is undefined if the previous limit does not exist&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let P be a property of terms. We will say that almost every term satisfies P &lt;br /&gt;
(this will be also stated as P holds a.e.) if&lt;br /&gt;
&amp;lt;math&amp;gt;d(\{t \ | \ P(t) holds\})=1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== generating functions ==&lt;br /&gt;
&lt;br /&gt;
this does not work (by now) because radius of convergence 0&lt;br /&gt;
&lt;br /&gt;
no known results for the number of terms of size n (denoted &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
== our results ==&lt;br /&gt;
&lt;br /&gt;
(the proof of result of section k needs the result of section (k-1))&lt;br /&gt;
&lt;br /&gt;
=== Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
For the lower bound, we will first count the number &amp;lt;math&amp;gt;LB(n,k)&amp;lt;/math&amp;gt; of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; starting with &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas and having no other lambda below. This means that the lower part of the term is a binary tree of size &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; with&lt;br /&gt;
&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; possibility for each leaf. Therefore we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) = C(n-k) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And therefore, for &amp;lt;math&amp;gt;n &amp;gt; k&amp;lt;/math&amp;gt;, using our lower bound for &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n + 1 \geq n - k + 1&amp;lt;/math&amp;gt;, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) \geq K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;K=\frac{36}{49\sqrt{\pi}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed, we define &amp;lt;math&amp;gt;f(\alpha) = \left(4n\alpha\right)^{n(1-\alpha) + 1}&amp;lt;/math&amp;gt; (so &amp;lt;math&amp;gt;LB(n,k) \geq \frac{K}{(n+1)^\frac{3}{2}} f\left(\frac{k}{n}\right)&amp;lt;/math&amp;gt;) and look for the maximum of this function. We have &amp;lt;math&amp;gt;f&#039;(\alpha) = f(\alpha) \left(-n\ln(4n\alpha) +\frac{n(1-\alpha) + 1}{\alpha}\right)&amp;lt;/math&amp;gt;. Thus, &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\frac{n+1}{n\alpha}e^{\frac{n+1}{n\alpha}}\geq 4e(n+1)&amp;lt;/math&amp;gt;. The Lambert function begin increasing this means that &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\alpha \leq \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;f(\alpha)&amp;lt;/math&amp;gt; reaches a maximum for &amp;lt;math&amp;gt;\alpha = \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This means that &amp;lt;math&amp;gt;(4k)^{n-k}&amp;lt;/math&amp;gt; reaches its maximum for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed when &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;&lt;br /&gt;
is near to &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; which is likely not to be an integer. However, there are at least &amp;lt;math&amp;gt;\left\lfloor \frac{n (\ln(\ln(4en)) - 1)}{\ln^2(4en)}\right\rfloor&amp;lt;/math&amp;gt; integer between &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\frac{n+1}{\ln(4e(n+1))}&amp;lt;/math&amp;gt;. Indeed, using our inequalities on Lambert W function, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}-\frac{n+1}{\ln(4e(n+1))} = \frac{(n+1) (\ln(4e(n+1)) - W(4e(n+1)))}{W(4e(n+1))\ln(4e(n+1))} \geq \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, we get the following lowerbound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \sum_{k=1}^{n} LB(n,k) \geq \sum_{k=\lceil\frac{n+1}{\ln(4e(n+1))}\rceil}^{\lfloor\frac{n+1}{W(4e(n+1))}\rfloor} K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}} \geq K \left\lfloor \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}\right\rfloor \frac{\left(\frac{4(n+1)}{\ln(4e(n+1))}\right)^{n-\frac{n+1}{\ln(4e(n+1))}+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To simplify, using the fact that &amp;lt;math&amp;gt;\lim_{n\to +\infty}\left(\frac{\ln(n)}{\ln(4en)}\right)^n = 0&amp;lt;/math&amp;gt; and taking &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; large enough, we have the following lowerbound:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \frac{\sqrt{n}}{\ln^3(n)}\left(\frac{4n}{\ln(n)}\right)^{n-\frac{n}{\ln(n)}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We now compute an upper bound &amp;lt;math&amp;gt;UB(n,k)&amp;lt;/math&amp;gt; for the number of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with exactly &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas (that is with &amp;lt;math&amp;gt;n - k + 1&amp;lt;/math&amp;gt; leaves using the Motzkin numbers and allowing any lambda to bind any variable (regardless of the real scope):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;UB(n,k) = M(n,n-k+1) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we sum this for all possible &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and get an upper bound of &amp;lt;math&amp;gt;k^{n-k+1}&amp;lt;/math&amp;gt; using Lambert function as for the lower bound, we get the following upper bound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \leq M(n) \left(\frac{n+1}{W(e(n+1))}\right)^{n-\frac{n+1}{W(e(n+1))} + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The ration between our upper bound and lower bound is equivalent to (NEEDS FURTHER CHECKING):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\left(\frac{1}{4(3-2\sqrt{2})}\right)^n\frac{\ln^3(n)}{n^2} \simeq 1.46^n\frac{\ln^3(n)}{n^2}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== upper and lower bounds for number of lambdas in a term of size n ===&lt;br /&gt;
&lt;br /&gt;
=== Jakub&#039;s trik : at least 1 lambda in head position ===&lt;br /&gt;
&lt;br /&gt;
=== at least &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; lambdas in head position and number of lambdas in one path ===&lt;br /&gt;
&lt;br /&gt;
Remark: (may be 4) can be done directly without 3))&lt;br /&gt;
&lt;br /&gt;
=== each of the  &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; head lambdas really bind &amp;quot;many&amp;quot;  occurrences of the variable ===&lt;br /&gt;
&lt;br /&gt;
=== every fixed closed term (including the identity !) does not appear in a random term (in fact we have much more than that) ===&lt;br /&gt;
&lt;br /&gt;
comment : so different situation in combinatory logic and lambda calculus ; the coding uses a big size so need to count variables in a different way&lt;br /&gt;
&lt;br /&gt;
== Experiments ==&lt;br /&gt;
&lt;br /&gt;
results of the experiments we have done&lt;br /&gt;
&lt;br /&gt;
some experiments that have to be done : e.g. density of terms having &amp;lt;math&amp;gt;\lambda x.y&amp;lt;/math&amp;gt; or big Omega pattern ...&lt;br /&gt;
&lt;br /&gt;
== to be done ==&lt;br /&gt;
&lt;br /&gt;
Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; with other size for variables especially one, binary with fixed size&lt;br /&gt;
&lt;br /&gt;
== Open questions and Future work ==&lt;br /&gt;
&lt;br /&gt;
.....&lt;/div&gt;</summary>
		<author><name>René David</name></author>
	</entry>
	<entry>
		<id>http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2713</id>
		<title>Lambda counting</title>
		<link rel="alternate" type="text/html" href="http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2713"/>
		<updated>2008-10-21T08:16:13Z</updated>

		<summary type="html">&lt;p&gt;René David : /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
what kind of properties : structural (for functional programs), behaviour (SN, weakly normalizable, ...&lt;br /&gt;
&lt;br /&gt;
references to known results on : turing machines, cellular automata&lt;br /&gt;
&lt;br /&gt;
we concentrate on combinatory logic, lambda calculus)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This paper adresses the following question. Having a (theoritical) programming language and a property of programs in that language. What is the probability that a random program satisfies the given property ? In particular, is it the case that almost every random program satisfies the desired property i.e. the probability is 1 ? &lt;br /&gt;
This question has some known results for Turing machines and cellular automata. Some of them will be given in section ??.&lt;br /&gt;
&lt;br /&gt;
In this introduction we consider that this notion of probabilty is, at least intuitively, sufficiently clear  but, of course, this will have to be made precise.&lt;br /&gt;
&lt;br /&gt;
We will consider this question for functional programming languages. For this kind of languages we can consider various properties. Some concern the structural of the program, some concern its behaviour.&lt;br /&gt;
&lt;br /&gt;
The simplest such language is the lambda calculus. &lt;br /&gt;
Some experiments have been done for it (see for example ...) which clearly indicates that, for example, almost every closed lambda term begins with a &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; but, as far as we know, there is no proved result of this form. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This paper proves some highly non trivial results of this form. In particular we show that almost every closed lambda term begins with &amp;quot;many&amp;quot; &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; (the precise meaning of this is given in theorem ??), that these &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; bound &amp;quot;many&amp;quot; occurences of the corresponding variables theorem ??) and that, given any fixed closed term, almost &#039;&#039;no&#039;&#039; &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt;-term has this term as a sub-term. &lt;br /&gt;
&lt;br /&gt;
Our original motivation was to consider the property of being terminating. Is a random term strongly normalizable (SN for short)? This question is, at present, unsolved and  the experiments we have done do not even give an idea of what the result should be. It is known that being SN is an undecidable question and it is thus not easy to count the number of SN terms of big size. It is clear that having &amp;lt;math&amp;gt;(\delta \ \delta)&amp;lt;/math&amp;gt; as a sub-term is a sufficient (but not necessary) condition for being non SN but as the experiments have shown (and as we have proved) almost no terms contains &amp;lt;math&amp;gt;(\delta \ \delta)&amp;lt;/math&amp;gt;  and this is thus useless to have a rsult for non SN. On the opposite direction, it is known that, if a term t is not SN, then a pattern &amp;quot;looking like&amp;quot; &amp;lt;math&amp;gt;(\delta \ \delta)&amp;lt;/math&amp;gt; (the precise meaning will be given in sectioon ??)  must appear in t but the experiments seem to show that almost every term possesses this pattern (actually, we have not bee&lt;br /&gt;
&lt;br /&gt;
== Lambert function, Catalan and Motzkin numbers ==&lt;br /&gt;
&lt;br /&gt;
=== Catalan numbers ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; : Catalan numbers &lt;br /&gt;
&lt;br /&gt;
Usual equivalent: &amp;lt;math&amp;gt;C(n) \sim \frac{4^n}{n^{3/2}\sqrt{\pi}}&amp;lt;/math&amp;gt; which is obtained using Strirling formula.&lt;br /&gt;
However, using stirling series: &amp;lt;math&amp;gt;&lt;br /&gt;
  n!=\sqrt{2\pi n}\left({n\over e}\right)^n&lt;br /&gt;
  \left(&lt;br /&gt;
   1&lt;br /&gt;
   +{1\over12n}&lt;br /&gt;
   +{1\over288n^2}&lt;br /&gt;
   -{139\over51840n^3}&lt;br /&gt;
   -{571\over2488320n^4}&lt;br /&gt;
   + \cdots&lt;br /&gt;
  \right)&lt;br /&gt;
 &amp;lt;/math&amp;gt;, we get that for &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; we have &amp;lt;math&amp;gt;\sqrt{2\pi n}\left({n\over e}\right)^n \leq n! \leq \frac{7}{6}\sqrt{2\pi n}\left({n\over e}\right)^n&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, using this and &amp;lt;math&amp;gt;\left(\frac{n}{n+1}\right)^{n} &amp;gt; e^{-1}&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C(n) = \frac{(2n)!}{(n+1)!n!} \geq \frac{36}{49\sqrt{\pi}} \frac{4^n}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; but also for &amp;lt;math&amp;gt;n=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Motzkin numbers===&lt;br /&gt;
&lt;br /&gt;
Let us define &amp;lt;math&amp;gt;M(n,k)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; leafs. We get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n,k) = \frac{(n+k-1)!}{(n-k+1)!(k-1)!k!}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, by summing we define &amp;lt;math&amp;gt;M(n)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and give an equivalent:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n) = \sum_{k=0}^n M(n,k) \sim \left(\frac{1}{3-2\sqrt{2}}\right)^n \frac{1}{n^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lambert W function===&lt;br /&gt;
&lt;br /&gt;
The Lambert function &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; is defined by the equation &amp;lt;math&amp;gt;x = W(x) e ^ {W(x)} &amp;lt;/math&amp;gt;&lt;br /&gt;
which has a unique solution in &amp;lt;math&amp;gt;\mathbb{R}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;x \geq e&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x)&amp;lt;/math&amp;gt; which implies that &lt;br /&gt;
&amp;lt;math&amp;gt;W(x) \sim \ln(x)&amp;lt;/math&amp;gt; near &amp;lt;math&amp;gt;+\infty&amp;lt;/math&amp;gt;. To prove this, it is enough to remark that&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;(\ln(x) - \ln(\ln(x))e^{\ln(x)-\ln(\ln(x))} = x \left(1 - \frac{\ln(\ln(x))}{\ln(x)}\right) \leq x \leq x \ln(x) = \ln(x) e^{\ln(x)} &amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is not precise enough for our purpose. Using one step of the Newton method from &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt;, we can find a better upper bound for &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; because &amp;lt;math&amp;gt;y \mapsto y e^y&amp;lt;/math&amp;gt; is increasing and convex. This gives:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, if we define &amp;lt;math&amp;gt;f(y) = y e^y&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;f&#039;(y)=(1+y)e^y&amp;lt;/math&amp;gt; and therefore, newton&#039;s method from &amp;lt;math&amp;gt;A = \ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt; gives a point at position:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;&lt;br /&gt;
A - \frac{f(A) - x}{f&#039;(A)} &lt;br /&gt;
  = A +  \frac{x \ln(\ln(x))}{\ln(x)} \frac{\ln(x)}{x(\ln(x) - \ln(\ln(x)) + 1)}&lt;br /&gt;
  = A +  \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1} &lt;br /&gt;
&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, we show that for &amp;lt;math&amp;gt;x\geq e&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + 1&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, for &amp;lt;math&amp;gt;x &amp;gt; 1&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;e^{\sqrt{ex}} \geq 1 + \sqrt{ex} + \frac{ex}{2} \geq x&amp;lt;/math&amp;gt;, which implies&lt;br /&gt;
&amp;lt;math&amp;gt;ex \geq \ln^2(x)&amp;lt;/math&amp;gt; and therefore &amp;lt;math&amp;gt;\ln(x) - \ln\ln(x) + 1 \geq \ln\ln(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==  combinatory logic ==&lt;br /&gt;
&lt;br /&gt;
Basically the paper already written by Marek&lt;br /&gt;
&lt;br /&gt;
+ the following&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As we will see in section ??, theorem ?? does not holds for the Lambda calculus. This may be surprising since there are translations between these systems which respect many properties (for exemple the one of being terminating). However these translations do not preserve the size. &lt;br /&gt;
&lt;br /&gt;
The translation T from combinatory logic to lambda calculus is linear, i.e. there is a constant k such that, for all terms, &amp;lt;math&amp;gt;size(T(t) \leq k.size(t)&amp;lt;/math&amp;gt; but the translation T&#039; in the other direction is not linear. As far as we know, there is no known bound on the size of T&#039;(t) but it is not difficult to find exemples where size(T&#039;(t)) is of order &amp;lt;math&amp;gt;size(t)^3&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The point is that T&#039; has to code the binding in some way and this takes place. It will be interesting to compare the size of T&#039;(t) with the one of t using other notion of size than the usual one. See section ?? for some complement.&lt;br /&gt;
&lt;br /&gt;
== Generality on lambda calculus ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition &lt;br /&gt;
&lt;br /&gt;
The set &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt; of lambda terms (or,&lt;br /&gt;
simply, terms) is defined by the following grammar&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;t, u  := Var \ \mid \ \lambda x.t \ \mid \ (t \ u)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To be able to define the notion of a &#039;&#039;random&#039;&#039; term we&lt;br /&gt;
have to define a distribution law on &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt;. There are many&lt;br /&gt;
possibilities for that. We choose here the simplest one. Note that this is the one for which, at least at present,  we are&lt;br /&gt;
able to prove some results. It is based on densities. For that we&lt;br /&gt;
first have to define the &#039;&#039;size&#039;&#039; of a term.&lt;br /&gt;
&lt;br /&gt;
The usual&lt;br /&gt;
definition is the following.&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
The size (denoted as &amp;lt;math&amp;gt;size_1(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
rules.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(\lambda x.t)=size_1(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1((t \ u))=size_1(t)+size_1(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the rest of the paper we will use another definition (denoted&lt;br /&gt;
as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt;) which is similar but  gives simpler computations.&lt;br /&gt;
We believe (but we have not yet checked the details) that, with&lt;br /&gt;
&amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt; we would have similar results. The&lt;br /&gt;
computation, with &amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt;,  of the upper and lower&lt;br /&gt;
bounds of the number of terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; will be done&lt;br /&gt;
in section ??&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
The size (denoted as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt; or, more simply &amp;lt;math&amp;gt;size(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
rules.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(\lambda x.t)=size_0(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0((t \ u))=size_0(t)+size_0(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These definitions of the size are, for the implementation point of&lt;br /&gt;
view, not realistic because, in case a term has a lot of distinct&lt;br /&gt;
variables, it is not realistic to use a single bit to code them.&lt;br /&gt;
The usual way to implement this coding is to replace the names of&lt;br /&gt;
variables by  their so called de Bruijn indices: a variable is&lt;br /&gt;
replaced by the number of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; that occur, on the&lt;br /&gt;
path from the variable to the root, between the variable and the&lt;br /&gt;
&amp;lt;math&amp;gt;lambda&amp;lt;/math&amp;gt; that binds it. Note that, in this case,&lt;br /&gt;
different occurrences of the same variable may be represented by&lt;br /&gt;
different indices.&lt;br /&gt;
&lt;br /&gt;
Choosing the way we code these de Bruijn indices gives different&lt;br /&gt;
other ways of defining the size of a term. This can be done in the&lt;br /&gt;
following ways&lt;br /&gt;
&lt;br /&gt;
- Use unary notation, i.e. the size of the index &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;&lt;br /&gt;
simply is &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; itself&lt;br /&gt;
&lt;br /&gt;
- Use optimal binary notation, i.e. the size of the index&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;log_2(n)&amp;lt;/math&amp;gt; i.e. the logarithm of&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; in base 2.&lt;br /&gt;
&lt;br /&gt;
- Use uniform binary notation, i.e. the size of an index is the&lt;br /&gt;
logarithm, in base 2, of the number of leaves of the term.&lt;br /&gt;
&lt;br /&gt;
Remark&lt;br /&gt;
&lt;br /&gt;
See section ?? for a discusion about these different size.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; be an integer. We denote by &amp;lt;math&amp;gt;\Lambda_n&amp;lt;/math&amp;gt; the set of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; terms of size n.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let A be a set of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; terms. &lt;br /&gt;
&lt;br /&gt;
1) We denote by &amp;lt;math&amp;gt;\#(A)&amp;lt;/math&amp;gt; the cardinality of A.&lt;br /&gt;
&lt;br /&gt;
2) We denote by &amp;lt;math&amp;gt;d(A)&amp;lt;/math&amp;gt; the limit, for n going to &amp;lt;math&amp;gt;\infty&amp;lt;/math&amp;gt;, &lt;br /&gt;
of &amp;lt;math&amp;gt;\frac{\#(A\cap \Lambda_n)}{\#(\Lambda_n)}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Remark&lt;br /&gt;
&lt;br /&gt;
Note that d is not exactly a measure since &amp;lt;math&amp;gt;d(A)&amp;lt;/math&amp;gt; is undefined if the previous limit does not exist&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let P be a property of terms. We will say that almost every term satisfies P &lt;br /&gt;
(this will be also stated as P holds a.e.) if&lt;br /&gt;
&amp;lt;math&amp;gt;d(\{t \ | \ P(t) holds\})=1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== generating functions ==&lt;br /&gt;
&lt;br /&gt;
this does not work (by now) because radius of convergence 0&lt;br /&gt;
&lt;br /&gt;
no known results for the number of terms of size n (denoted &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
== our results ==&lt;br /&gt;
&lt;br /&gt;
(the proof of result of section k needs the result of section (k-1))&lt;br /&gt;
&lt;br /&gt;
=== Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
For the lower bound, we will first count the number &amp;lt;math&amp;gt;LB(n,k)&amp;lt;/math&amp;gt; of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; starting with &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas and having no other lambda below. This means that the lower part of the term is a binary tree of size &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; with&lt;br /&gt;
&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; possibility for each leaf. Therefore we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) = C(n-k) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And therefore, for &amp;lt;math&amp;gt;n &amp;gt; k&amp;lt;/math&amp;gt;, using our lower bound for &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n + 1 \geq n - k + 1&amp;lt;/math&amp;gt;, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) \geq K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;K=\frac{36}{49\sqrt{\pi}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed, we define &amp;lt;math&amp;gt;f(\alpha) = \left(4n\alpha\right)^{n(1-\alpha) + 1}&amp;lt;/math&amp;gt; (so &amp;lt;math&amp;gt;LB(n,k) \geq \frac{K}{(n+1)^\frac{3}{2}} f\left(\frac{k}{n}\right)&amp;lt;/math&amp;gt;) and look for the maximum of this function. We have &amp;lt;math&amp;gt;f&#039;(\alpha) = f(\alpha) \left(-n\ln(4n\alpha) +\frac{n(1-\alpha) + 1}{\alpha}\right)&amp;lt;/math&amp;gt;. Thus, &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\frac{n+1}{n\alpha}e^{\frac{n+1}{n\alpha}}\geq 4e(n+1)&amp;lt;/math&amp;gt;. The Lambert function begin increasing this means that &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\alpha \leq \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;f(\alpha)&amp;lt;/math&amp;gt; reaches a maximum for &amp;lt;math&amp;gt;\alpha = \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This means that &amp;lt;math&amp;gt;(4k)^{n-k}&amp;lt;/math&amp;gt; reaches its maximum for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed when &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;&lt;br /&gt;
is near to &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; which is likely not to be an integer. However, there are at least &amp;lt;math&amp;gt;\left\lfloor \frac{n (\ln(\ln(4en)) - 1)}{\ln^2(4en)}\right\rfloor&amp;lt;/math&amp;gt; integer between &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\frac{n+1}{\ln(4e(n+1))}&amp;lt;/math&amp;gt;. Indeed, using our inequalities on Lambert W function, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}-\frac{n+1}{\ln(4e(n+1))} = \frac{(n+1) (\ln(4e(n+1)) - W(4e(n+1)))}{W(4e(n+1))\ln(4e(n+1))} \geq \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, we get the following lowerbound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \sum_{k=1}^{n} LB(n,k) \geq \sum_{k=\lceil\frac{n+1}{\ln(4e(n+1))}\rceil}^{\lfloor\frac{n+1}{W(4e(n+1))}\rfloor} K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}} \geq K \left\lfloor \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}\right\rfloor \frac{\left(\frac{4(n+1)}{\ln(4e(n+1))}\right)^{n-\frac{n+1}{\ln(4e(n+1))}+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To simplify, using the fact that &amp;lt;math&amp;gt;\lim_{n\to +\infty}\left(\frac{\ln(n)}{\ln(4en)}\right)^n = 0&amp;lt;/math&amp;gt; and taking &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; large enough, we have the following lowerbound:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \frac{\sqrt{n}}{\ln^3(n)}\left(\frac{4n}{\ln(n)}\right)^{n-\frac{n}{\ln(n)}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We now compute an upper bound &amp;lt;math&amp;gt;UB(n,k)&amp;lt;/math&amp;gt; for the number of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with exactly &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas (that is with &amp;lt;math&amp;gt;n - k + 1&amp;lt;/math&amp;gt; leaves using the Motzkin numbers and allowing any lambda to bind any variable (regardless of the real scope):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;UB(n,k) = M(n,n-k+1) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we sum this for all possible &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and get an upper bound of &amp;lt;math&amp;gt;k^{n-k+1}&amp;lt;/math&amp;gt; using Lambert function as for the lower bound, we get the following upper bound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \leq M(n) \left(\frac{n+1}{W(e(n+1))}\right)^{n-\frac{n+1}{W(e(n+1))} + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The ration between our upper bound and lower bound is equivalent to (NEEDS FURTHER CHECKING):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\left(\frac{1}{4(3-2\sqrt{2})}\right)^n\frac{\ln^3(n)}{n^2} \simeq 1.46^n\frac{\ln^3(n)}{n^2}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== upper and lower bounds for number of lambdas in a term of size n ===&lt;br /&gt;
&lt;br /&gt;
=== Jakub&#039;s trik : at least 1 lambda in head position ===&lt;br /&gt;
&lt;br /&gt;
=== at least &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; lambdas in head position and number of lambdas in one path ===&lt;br /&gt;
&lt;br /&gt;
Remark: (may be 4) can be done directly without 3))&lt;br /&gt;
&lt;br /&gt;
=== each of the  &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; head lambdas really bind &amp;quot;many&amp;quot;  occurrences of the variable ===&lt;br /&gt;
&lt;br /&gt;
=== every fixed closed term (including the identity !) does not appear in a random term (in fact we have much more than that) ===&lt;br /&gt;
&lt;br /&gt;
comment : so different situation in combinatory logic and lambda calculus ; the coding uses a big size so need to count variables in a different way&lt;br /&gt;
&lt;br /&gt;
== Experiments ==&lt;br /&gt;
&lt;br /&gt;
results of the experiments we have done&lt;br /&gt;
&lt;br /&gt;
some experiments that have to be done : e.g. density of terms having &amp;lt;math&amp;gt;\lambda x.y&amp;lt;/math&amp;gt; or big Omega pattern ...&lt;br /&gt;
&lt;br /&gt;
== to be done ==&lt;br /&gt;
&lt;br /&gt;
Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; with other size for variables especially one, binary with fixed size&lt;br /&gt;
&lt;br /&gt;
== Open questions and Future work ==&lt;br /&gt;
&lt;br /&gt;
.....&lt;/div&gt;</summary>
		<author><name>René David</name></author>
	</entry>
	<entry>
		<id>http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2712</id>
		<title>Lambda counting</title>
		<link rel="alternate" type="text/html" href="http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2712"/>
		<updated>2008-10-21T08:00:42Z</updated>

		<summary type="html">&lt;p&gt;René David : /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
what kind of properties : structural (for functional programs), behaviour (SN, weakly normalizable, ...&lt;br /&gt;
&lt;br /&gt;
references to known results on : turing machines, cellular automata&lt;br /&gt;
&lt;br /&gt;
we concentrate on combinatory logic, lambda calculus)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This paper adresses the following question. Having a (theoritical) programming language and a property of programs in that language. What is the probability that a random program satisfies the given property ? In particular, is it the case that almost every random program satisfies the desired property i.e. the probability is 1 ? &lt;br /&gt;
This question has some known results for Turing machines and cellular automata. Some of them will be given in section ??.&lt;br /&gt;
&lt;br /&gt;
We will consider this question for functional programming languages. The simplest such language is the lambda calculus. Some experiments have been done for it (see for example ...) which clearly indicates that, for example, almost every closed lambda term begins with a &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; but, as far as we know, there is no proved result of this form. &lt;br /&gt;
&lt;br /&gt;
In this introduction we consider that&lt;br /&gt;
&lt;br /&gt;
This paper proves some highly non trivial results of this form. In particular we show that almost every closed lambda term begins with &amp;quot;many&amp;quot; &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; (the precise meaning of this is given in theorem ??), that these &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; bound &amp;quot;many&amp;quot; occurences of the corresponding variables theorem ??) and that, given any fixed closed term, almost &#039;&#039;no&#039;&#039; &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt;-term has this term as a sub-term. &lt;br /&gt;
&lt;br /&gt;
Our original motivation was to consider the property of being terminating. Is a random term strongly normalizable (SN for short)? This question is, at present, unsolved and  the experiments we have done do not give an idea of the result. It is known that being SN is an undecidable question and it is thus not easy to the number of SN terms of big size. It is clear that having &amp;lt;math&amp;gt;(\delta \ \delta)&amp;lt;/math&amp;gt; as a sub-term is a sufficient (but not necessary) condition&lt;br /&gt;
&lt;br /&gt;
== Lambert function, Catalan and Motzkin numbers ==&lt;br /&gt;
&lt;br /&gt;
=== Catalan numbers ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; : Catalan numbers &lt;br /&gt;
&lt;br /&gt;
Usual equivalent: &amp;lt;math&amp;gt;C(n) \sim \frac{4^n}{n^{3/2}\sqrt{\pi}}&amp;lt;/math&amp;gt; which is obtained using Strirling formula.&lt;br /&gt;
However, using stirling series: &amp;lt;math&amp;gt;&lt;br /&gt;
  n!=\sqrt{2\pi n}\left({n\over e}\right)^n&lt;br /&gt;
  \left(&lt;br /&gt;
   1&lt;br /&gt;
   +{1\over12n}&lt;br /&gt;
   +{1\over288n^2}&lt;br /&gt;
   -{139\over51840n^3}&lt;br /&gt;
   -{571\over2488320n^4}&lt;br /&gt;
   + \cdots&lt;br /&gt;
  \right)&lt;br /&gt;
 &amp;lt;/math&amp;gt;, we get that for &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; we have &amp;lt;math&amp;gt;\sqrt{2\pi n}\left({n\over e}\right)^n \leq n! \leq \frac{7}{6}\sqrt{2\pi n}\left({n\over e}\right)^n&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, using this and &amp;lt;math&amp;gt;\left(\frac{n}{n+1}\right)^{n} &amp;gt; e^{-1}&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C(n) = \frac{(2n)!}{(n+1)!n!} \geq \frac{36}{49\sqrt{\pi}} \frac{4^n}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; but also for &amp;lt;math&amp;gt;n=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Motzkin numbers===&lt;br /&gt;
&lt;br /&gt;
Let us define &amp;lt;math&amp;gt;M(n,k)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; leafs. We get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n,k) = \frac{(n+k-1)!}{(n-k+1)!(k-1)!k!}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, by summing we define &amp;lt;math&amp;gt;M(n)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and give an equivalent:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n) = \sum_{k=0}^n M(n,k) \sim \left(\frac{1}{3-2\sqrt{2}}\right)^n \frac{1}{n^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lambert W function===&lt;br /&gt;
&lt;br /&gt;
The Lambert function &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; is defined by the equation &amp;lt;math&amp;gt;x = W(x) e ^ {W(x)} &amp;lt;/math&amp;gt;&lt;br /&gt;
which has a unique solution in &amp;lt;math&amp;gt;\mathbb{R}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;x \geq e&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x)&amp;lt;/math&amp;gt; which implies that &lt;br /&gt;
&amp;lt;math&amp;gt;W(x) \sim \ln(x)&amp;lt;/math&amp;gt; near &amp;lt;math&amp;gt;+\infty&amp;lt;/math&amp;gt;. To prove this, it is enough to remark that&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;(\ln(x) - \ln(\ln(x))e^{\ln(x)-\ln(\ln(x))} = x \left(1 - \frac{\ln(\ln(x))}{\ln(x)}\right) \leq x \leq x \ln(x) = \ln(x) e^{\ln(x)} &amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is not precise enough for our purpose. Using one step of the Newton method from &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt;, we can find a better upper bound for &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; because &amp;lt;math&amp;gt;y \mapsto y e^y&amp;lt;/math&amp;gt; is increasing and convex. This gives:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, if we define &amp;lt;math&amp;gt;f(y) = y e^y&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;f&#039;(y)=(1+y)e^y&amp;lt;/math&amp;gt; and therefore, newton&#039;s method from &amp;lt;math&amp;gt;A = \ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt; gives a point at position:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;&lt;br /&gt;
A - \frac{f(A) - x}{f&#039;(A)} &lt;br /&gt;
  = A +  \frac{x \ln(\ln(x))}{\ln(x)} \frac{\ln(x)}{x(\ln(x) - \ln(\ln(x)) + 1)}&lt;br /&gt;
  = A +  \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1} &lt;br /&gt;
&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, we show that for &amp;lt;math&amp;gt;x\geq e&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + 1&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, for &amp;lt;math&amp;gt;x &amp;gt; 1&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;e^{\sqrt{ex}} \geq 1 + \sqrt{ex} + \frac{ex}{2} \geq x&amp;lt;/math&amp;gt;, which implies&lt;br /&gt;
&amp;lt;math&amp;gt;ex \geq \ln^2(x)&amp;lt;/math&amp;gt; and therefore &amp;lt;math&amp;gt;\ln(x) - \ln\ln(x) + 1 \geq \ln\ln(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==  combinatory logic ==&lt;br /&gt;
&lt;br /&gt;
Basically the paper already written by Marek&lt;br /&gt;
&lt;br /&gt;
+ the following&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As we will see in section ??, theorem ?? does not holds for the Lambda calculus. This may be surprising since there are translations between these systems which respect many properties (for exemple the one of being terminating). However these translations do not preserve the size. &lt;br /&gt;
&lt;br /&gt;
The translation T from combinatory logic to lambda calculus is linear, i.e. there is a constant k such that, for all terms, &amp;lt;math&amp;gt;size(T(t) \leq k.size(t)&amp;lt;/math&amp;gt; but the translation T&#039; in the other direction is not linear. As far as we know, there is no known bound on the size of T&#039;(t) but it is not difficult to find exemples where size(T&#039;(t)) is of order &amp;lt;math&amp;gt;size(t)^3&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The point is that T&#039; has to code the binding in some way and this takes place. It will be interesting to compare the size of T&#039;(t) with the one of t using other notion of size than the usual one. See section ?? for some complement.&lt;br /&gt;
&lt;br /&gt;
== Generality on lambda calculus ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition &lt;br /&gt;
&lt;br /&gt;
The set &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt; of lambda terms (or,&lt;br /&gt;
simply, terms) is defined by the following grammar&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;t, u  := Var \ \mid \ \lambda x.t \ \mid \ (t \ u)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To be able to define the notion of a &#039;&#039;random&#039;&#039; term we&lt;br /&gt;
have to define a distribution law on &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt;. There are many&lt;br /&gt;
possibilities for that. We choose here the simplest one. Note that this is the one for which, at least at present,  we are&lt;br /&gt;
able to prove some results. It is based on densities. For that we&lt;br /&gt;
first have to define the &#039;&#039;size&#039;&#039; of a term.&lt;br /&gt;
&lt;br /&gt;
The usual&lt;br /&gt;
definition is the following.&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
The size (denoted as &amp;lt;math&amp;gt;size_1(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
rules.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(\lambda x.t)=size_1(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1((t \ u))=size_1(t)+size_1(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the rest of the paper we will use another definition (denoted&lt;br /&gt;
as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt;) which is similar but  gives simpler computations.&lt;br /&gt;
We believe (but we have not yet checked the details) that, with&lt;br /&gt;
&amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt; we would have similar results. The&lt;br /&gt;
computation, with &amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt;,  of the upper and lower&lt;br /&gt;
bounds of the number of terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; will be done&lt;br /&gt;
in section ??&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
The size (denoted as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt; or, more simply &amp;lt;math&amp;gt;size(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
rules.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(\lambda x.t)=size_0(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0((t \ u))=size_0(t)+size_0(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These definitions of the size are, for the implementation point of&lt;br /&gt;
view, not realistic because, in case a term has a lot of distinct&lt;br /&gt;
variables, it is not realistic to use a single bit to code them.&lt;br /&gt;
The usual way to implement this coding is to replace the names of&lt;br /&gt;
variables by  their so called de Bruijn indices: a variable is&lt;br /&gt;
replaced by the number of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; that occur, on the&lt;br /&gt;
path from the variable to the root, between the variable and the&lt;br /&gt;
&amp;lt;math&amp;gt;lambda&amp;lt;/math&amp;gt; that binds it. Note that, in this case,&lt;br /&gt;
different occurrences of the same variable may be represented by&lt;br /&gt;
different indices.&lt;br /&gt;
&lt;br /&gt;
Choosing the way we code these de Bruijn indices gives different&lt;br /&gt;
other ways of defining the size of a term. This can be done in the&lt;br /&gt;
following ways&lt;br /&gt;
&lt;br /&gt;
- Use unary notation, i.e. the size of the index &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;&lt;br /&gt;
simply is &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; itself&lt;br /&gt;
&lt;br /&gt;
- Use optimal binary notation, i.e. the size of the index&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;log_2(n)&amp;lt;/math&amp;gt; i.e. the logarithm of&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; in base 2.&lt;br /&gt;
&lt;br /&gt;
- Use uniform binary notation, i.e. the size of an index is the&lt;br /&gt;
logarithm, in base 2, of the number of leaves of the term.&lt;br /&gt;
&lt;br /&gt;
Remark&lt;br /&gt;
&lt;br /&gt;
See section ?? for a discusion about these different size.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; be an integer. We denote by &amp;lt;math&amp;gt;\Lambda_n&amp;lt;/math&amp;gt; the set of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; terms of size n.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let A be a set of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; terms. &lt;br /&gt;
&lt;br /&gt;
1) We denote by &amp;lt;math&amp;gt;\#(A)&amp;lt;/math&amp;gt; the cardinality of A.&lt;br /&gt;
&lt;br /&gt;
2) We denote by &amp;lt;math&amp;gt;d(A)&amp;lt;/math&amp;gt; the limit, for n going to &amp;lt;math&amp;gt;\infty&amp;lt;/math&amp;gt;, &lt;br /&gt;
of &amp;lt;math&amp;gt;\frac{\#(A\cap \Lambda_n)}{\#(\Lambda_n)}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Remark&lt;br /&gt;
&lt;br /&gt;
Note that d is not exactly a measure since &amp;lt;math&amp;gt;d(A)&amp;lt;/math&amp;gt; is undefined if the previous limit does not exist&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let P be a property of terms. We will say that almost every term satisfies P &lt;br /&gt;
(this will be also stated as P holds a.e.) if&lt;br /&gt;
&amp;lt;math&amp;gt;d(\{t \ | \ P(t) holds\})=1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== generating functions ==&lt;br /&gt;
&lt;br /&gt;
this does not work (by now) because radius of convergence 0&lt;br /&gt;
&lt;br /&gt;
no known results for the number of terms of size n (denoted &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
== our results ==&lt;br /&gt;
&lt;br /&gt;
(the proof of result of section k needs the result of section (k-1))&lt;br /&gt;
&lt;br /&gt;
=== Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
For the lower bound, we will first count the number &amp;lt;math&amp;gt;LB(n,k)&amp;lt;/math&amp;gt; of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; starting with &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas and having no other lambda below. This means that the lower part of the term is a binary tree of size &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; with&lt;br /&gt;
&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; possibility for each leaf. Therefore we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) = C(n-k) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And therefore, for &amp;lt;math&amp;gt;n &amp;gt; k&amp;lt;/math&amp;gt;, using our lower bound for &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n + 1 \geq n - k + 1&amp;lt;/math&amp;gt;, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) \geq K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;K=\frac{36}{49\sqrt{\pi}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed, we define &amp;lt;math&amp;gt;f(\alpha) = \left(4n\alpha\right)^{n(1-\alpha) + 1}&amp;lt;/math&amp;gt; (so &amp;lt;math&amp;gt;LB(n,k) \geq \frac{K}{(n+1)^\frac{3}{2}} f\left(\frac{k}{n}\right)&amp;lt;/math&amp;gt;) and look for the maximum of this function. We have &amp;lt;math&amp;gt;f&#039;(\alpha) = f(\alpha) \left(-n\ln(4n\alpha) +\frac{n(1-\alpha) + 1}{\alpha}\right)&amp;lt;/math&amp;gt;. Thus, &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\frac{n+1}{n\alpha}e^{\frac{n+1}{n\alpha}}\geq 4e(n+1)&amp;lt;/math&amp;gt;. The Lambert function begin increasing this means that &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\alpha \leq \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;f(\alpha)&amp;lt;/math&amp;gt; reaches a maximum for &amp;lt;math&amp;gt;\alpha = \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This means that &amp;lt;math&amp;gt;(4k)^{n-k}&amp;lt;/math&amp;gt; reaches its maximum for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed when &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;&lt;br /&gt;
is near to &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; which is likely not to be an integer. However, there are at least &amp;lt;math&amp;gt;\left\lfloor \frac{n (\ln(\ln(4en)) - 1)}{\ln^2(4en)}\right\rfloor&amp;lt;/math&amp;gt; integer between &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\frac{n+1}{\ln(4e(n+1))}&amp;lt;/math&amp;gt;. Indeed, using our inequalities on Lambert W function, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}-\frac{n+1}{\ln(4e(n+1))} = \frac{(n+1) (\ln(4e(n+1)) - W(4e(n+1)))}{W(4e(n+1))\ln(4e(n+1))} \geq \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, we get the following lowerbound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \sum_{k=1}^{n} LB(n,k) \geq \sum_{k=\lceil\frac{n+1}{\ln(4e(n+1))}\rceil}^{\lfloor\frac{n+1}{W(4e(n+1))}\rfloor} K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}} \geq K \left\lfloor \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}\right\rfloor \frac{\left(\frac{4(n+1)}{\ln(4e(n+1))}\right)^{n-\frac{n+1}{\ln(4e(n+1))}+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To simplify, using the fact that &amp;lt;math&amp;gt;\lim_{n\to +\infty}\left(\frac{\ln(n)}{\ln(4en)}\right)^n = 0&amp;lt;/math&amp;gt; and taking &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; large enough, we have the following lowerbound:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \frac{\sqrt{n}}{\ln^3(n)}\left(\frac{4n}{\ln(n)}\right)^{n-\frac{n}{\ln(n)}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We now compute an upper bound &amp;lt;math&amp;gt;UB(n,k)&amp;lt;/math&amp;gt; for the number of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with exactly &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas (that is with &amp;lt;math&amp;gt;n - k + 1&amp;lt;/math&amp;gt; leaves using the Motzkin numbers and allowing any lambda to bind any variable (regardless of the real scope):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;UB(n,k) = M(n,n-k+1) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we sum this for all possible &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and get an upper bound of &amp;lt;math&amp;gt;k^{n-k+1}&amp;lt;/math&amp;gt; using Lambert function as for the lower bound, we get the following upper bound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \leq M(n) \left(\frac{n+1}{W(e(n+1))}\right)^{n-\frac{n+1}{W(e(n+1))} + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The ration between our upper bound and lower bound is equivalent to (NEEDS FURTHER CHECKING):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\left(\frac{1}{4(3-2\sqrt{2})}\right)^n\frac{\ln^3(n)}{n^2} \simeq 1.46^n\frac{\ln^3(n)}{n^2}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== upper and lower bounds for number of lambdas in a term of size n ===&lt;br /&gt;
&lt;br /&gt;
=== Jakub&#039;s trik : at least 1 lambda in head position ===&lt;br /&gt;
&lt;br /&gt;
=== at least &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; lambdas in head position and number of lambdas in one path ===&lt;br /&gt;
&lt;br /&gt;
Remark: (may be 4) can be done directly without 3))&lt;br /&gt;
&lt;br /&gt;
=== each of the  &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; head lambdas really bind &amp;quot;many&amp;quot;  occurrences of the variable ===&lt;br /&gt;
&lt;br /&gt;
=== every fixed closed term (including the identity !) does not appear in a random term (in fact we have much more than that) ===&lt;br /&gt;
&lt;br /&gt;
comment : so different situation in combinatory logic and lambda calculus ; the coding uses a big size so need to count variables in a different way&lt;br /&gt;
&lt;br /&gt;
== Experiments ==&lt;br /&gt;
&lt;br /&gt;
results of the experiments we have done&lt;br /&gt;
&lt;br /&gt;
some experiments that have to be done : e.g. density of terms having &amp;lt;math&amp;gt;\lambda x.y&amp;lt;/math&amp;gt; or big Omega pattern ...&lt;br /&gt;
&lt;br /&gt;
== to be done ==&lt;br /&gt;
&lt;br /&gt;
Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; with other size for variables especially one, binary with fixed size&lt;br /&gt;
&lt;br /&gt;
== Open questions and Future work ==&lt;br /&gt;
&lt;br /&gt;
.....&lt;/div&gt;</summary>
		<author><name>René David</name></author>
	</entry>
	<entry>
		<id>http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Discussion:Lambda_counting&amp;diff=2668</id>
		<title>Discussion:Lambda counting</title>
		<link rel="alternate" type="text/html" href="http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Discussion:Lambda_counting&amp;diff=2668"/>
		<updated>2008-10-20T14:45:05Z</updated>

		<summary type="html">&lt;p&gt;René David : /* Current semaphore */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Current semaphore==&lt;br /&gt;
&lt;br /&gt;
Attribution of the work currently being done (this is a semaphore !)&lt;br /&gt;
&lt;br /&gt;
Rene: &lt;br /&gt;
* introduction&lt;br /&gt;
&lt;br /&gt;
Christophe:&lt;br /&gt;
* the lower and upper bound for size 0 variables&lt;br /&gt;
&lt;br /&gt;
Kasia:&lt;br /&gt;
* the result about closed-term (and much more)&lt;br /&gt;
&lt;br /&gt;
Marek:&lt;br /&gt;
&lt;br /&gt;
Jakub:&lt;br /&gt;
&lt;br /&gt;
Guillaume:&lt;br /&gt;
&lt;br /&gt;
==Reservation of future semaphore==&lt;br /&gt;
&lt;br /&gt;
Rene: &lt;br /&gt;
&lt;br /&gt;
Christophe:&lt;br /&gt;
&lt;br /&gt;
Kasia:&lt;br /&gt;
* generating function&lt;br /&gt;
&lt;br /&gt;
Marek:&lt;br /&gt;
&lt;br /&gt;
Jakub:&lt;br /&gt;
&lt;br /&gt;
Guillaume:&lt;br /&gt;
&lt;br /&gt;
== About the lower bound ==&lt;br /&gt;
&lt;br /&gt;
The lower bound can probably be improved by replacing Catalan with the sum of Mtzkin M(n,k) for&lt;br /&gt;
k between 0 and n/ln(n). This probably would give the same exponential factor for the lower and upper bound and get us nearer to an equivalent. Is it worth it ?&lt;/div&gt;</summary>
		<author><name>René David</name></author>
	</entry>
	<entry>
		<id>http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Discussion:Lambda_counting&amp;diff=2667</id>
		<title>Discussion:Lambda counting</title>
		<link rel="alternate" type="text/html" href="http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Discussion:Lambda_counting&amp;diff=2667"/>
		<updated>2008-10-20T14:44:46Z</updated>

		<summary type="html">&lt;p&gt;René David : /* Current semaphore */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Current semaphore==&lt;br /&gt;
&lt;br /&gt;
Attribution of the work currently being done (this is a semaphore !)&lt;br /&gt;
&lt;br /&gt;
Rene: introduction&lt;br /&gt;
* &lt;br /&gt;
&lt;br /&gt;
Christophe:&lt;br /&gt;
* the lower and upper bound for size 0 variables&lt;br /&gt;
&lt;br /&gt;
Kasia:&lt;br /&gt;
* the result about closed-term (and much more)&lt;br /&gt;
&lt;br /&gt;
Marek:&lt;br /&gt;
&lt;br /&gt;
Jakub:&lt;br /&gt;
&lt;br /&gt;
Guillaume:&lt;br /&gt;
&lt;br /&gt;
==Reservation of future semaphore==&lt;br /&gt;
&lt;br /&gt;
Rene: &lt;br /&gt;
&lt;br /&gt;
Christophe:&lt;br /&gt;
&lt;br /&gt;
Kasia:&lt;br /&gt;
* generating function&lt;br /&gt;
&lt;br /&gt;
Marek:&lt;br /&gt;
&lt;br /&gt;
Jakub:&lt;br /&gt;
&lt;br /&gt;
Guillaume:&lt;br /&gt;
&lt;br /&gt;
== About the lower bound ==&lt;br /&gt;
&lt;br /&gt;
The lower bound can probably be improved by replacing Catalan with the sum of Mtzkin M(n,k) for&lt;br /&gt;
k between 0 and n/ln(n). This probably would give the same exponential factor for the lower and upper bound and get us nearer to an equivalent. Is it worth it ?&lt;/div&gt;</summary>
		<author><name>René David</name></author>
	</entry>
	<entry>
		<id>http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Discussion:Lambda_counting&amp;diff=2666</id>
		<title>Discussion:Lambda counting</title>
		<link rel="alternate" type="text/html" href="http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Discussion:Lambda_counting&amp;diff=2666"/>
		<updated>2008-10-20T14:44:12Z</updated>

		<summary type="html">&lt;p&gt;René David : /* Current semaphore */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Current semaphore==&lt;br /&gt;
&lt;br /&gt;
Attribution of the work currently being done (this is a semaphore !)&lt;br /&gt;
&lt;br /&gt;
Rene: &lt;br /&gt;
* &lt;br /&gt;
&lt;br /&gt;
Christophe:&lt;br /&gt;
* the lower and upper bound for size 0 variables&lt;br /&gt;
&lt;br /&gt;
Kasia:&lt;br /&gt;
* the result about closed-term (and much more)&lt;br /&gt;
&lt;br /&gt;
Marek:&lt;br /&gt;
&lt;br /&gt;
Jakub:&lt;br /&gt;
&lt;br /&gt;
Guillaume:&lt;br /&gt;
&lt;br /&gt;
==Reservation of future semaphore==&lt;br /&gt;
&lt;br /&gt;
Rene: &lt;br /&gt;
&lt;br /&gt;
Christophe:&lt;br /&gt;
&lt;br /&gt;
Kasia:&lt;br /&gt;
* generating function&lt;br /&gt;
&lt;br /&gt;
Marek:&lt;br /&gt;
&lt;br /&gt;
Jakub:&lt;br /&gt;
&lt;br /&gt;
Guillaume:&lt;br /&gt;
&lt;br /&gt;
== About the lower bound ==&lt;br /&gt;
&lt;br /&gt;
The lower bound can probably be improved by replacing Catalan with the sum of Mtzkin M(n,k) for&lt;br /&gt;
k between 0 and n/ln(n). This probably would give the same exponential factor for the lower and upper bound and get us nearer to an equivalent. Is it worth it ?&lt;/div&gt;</summary>
		<author><name>René David</name></author>
	</entry>
	<entry>
		<id>http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2665</id>
		<title>Lambda counting</title>
		<link rel="alternate" type="text/html" href="http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2665"/>
		<updated>2008-10-20T14:43:32Z</updated>

		<summary type="html">&lt;p&gt;René David : /* combinatory logic */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
The question is: among programs, what is the probability of having a fixed property.&lt;br /&gt;
&lt;br /&gt;
what kind of program : turing machines, cellular automata, combinatory logic, lambda calculus&lt;br /&gt;
&lt;br /&gt;
what kind of properties : structural (for functional programs), behaviour (SN, weakly normalizable, ...&lt;br /&gt;
&lt;br /&gt;
references to known results on : turing machines, cellular automata&lt;br /&gt;
&lt;br /&gt;
we concentrate on combinatory logic, lambda calculus&lt;br /&gt;
&lt;br /&gt;
== Lambert function, Catalan and Motzkin numbers ==&lt;br /&gt;
&lt;br /&gt;
=== Catalan numbers ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; : Catalan numbers &lt;br /&gt;
&lt;br /&gt;
Usual equivalent: &amp;lt;math&amp;gt;C(n) \sim \frac{4^n}{n^{3/2}\sqrt{\pi}}&amp;lt;/math&amp;gt; which is obtained using Strirling formula.&lt;br /&gt;
However, using stirling series: &amp;lt;math&amp;gt;&lt;br /&gt;
  n!=\sqrt{2\pi n}\left({n\over e}\right)^n&lt;br /&gt;
  \left(&lt;br /&gt;
   1&lt;br /&gt;
   +{1\over12n}&lt;br /&gt;
   +{1\over288n^2}&lt;br /&gt;
   -{139\over51840n^3}&lt;br /&gt;
   -{571\over2488320n^4}&lt;br /&gt;
   + \cdots&lt;br /&gt;
  \right)&lt;br /&gt;
 &amp;lt;/math&amp;gt;, we get that for &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; we have &amp;lt;math&amp;gt;\sqrt{2\pi n}\left({n\over e}\right)^n \leq n! \leq \frac{7}{6}\sqrt{2\pi n}\left({n\over e}\right)^n&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, using this and &amp;lt;math&amp;gt;\left(\frac{n}{n+1}\right)^{n} &amp;gt; e^{-1}&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C(n) = \frac{(2n)!}{(n+1)!n!} \geq \frac{36}{49\sqrt{\pi}} \frac{4^n}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; but also for &amp;lt;math&amp;gt;n=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Motzkin numbers===&lt;br /&gt;
&lt;br /&gt;
Let us define &amp;lt;math&amp;gt;M(n,k)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; leafs. We get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n,k) = \frac{(n+k-1)!}{(n-k+1)!(k-1)!k!}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, by summing we define &amp;lt;math&amp;gt;M(n)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and give an equivalent:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n) = \sum_{k=0}^n M(n,k) \sim \left(\frac{1}{3-2\sqrt{2}}\right)^n \frac{1}{n^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lambert W function===&lt;br /&gt;
&lt;br /&gt;
The Lambert function &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; is defined by the equation &amp;lt;math&amp;gt;x = W(x) e ^ {W(x)} &amp;lt;/math&amp;gt;&lt;br /&gt;
which has a unique solution in &amp;lt;math&amp;gt;\mathbb{R}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;x \geq e&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x)&amp;lt;/math&amp;gt; which implies that &lt;br /&gt;
&amp;lt;math&amp;gt;W(x) \sim \ln(x)&amp;lt;/math&amp;gt; near &amp;lt;math&amp;gt;+\infty&amp;lt;/math&amp;gt;. To prove this, it is enough to remark that&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;(\ln(x) - \ln(\ln(x))e^{\ln(x)-\ln(\ln(x))} = x \left(1 - \frac{\ln(\ln(x))}{\ln(x)}\right) \leq x \leq x \ln(x) = \ln(x) e^{\ln(x)} &amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is not precise enough for our purpose. Using one step of the Newton method from &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt;, we can find a better upper bound for &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; because &amp;lt;math&amp;gt;y \mapsto y e^y&amp;lt;/math&amp;gt; is increasing and convex. This gives:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, if we define &amp;lt;math&amp;gt;f(y) = y e^y&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;f&#039;(y)=(1+y)e^y&amp;lt;/math&amp;gt; and therefore, newton&#039;s method from &amp;lt;math&amp;gt;A = \ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt; gives a point at position:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;&lt;br /&gt;
A - \frac{f(A) - x}{f&#039;(A)} &lt;br /&gt;
  = A +  \frac{x \ln(\ln(x))}{\ln(x)} \frac{\ln(x)}{x(\ln(x) - \ln(\ln(x)) + 1)}&lt;br /&gt;
  = A +  \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1} &lt;br /&gt;
&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, we show that for &amp;lt;math&amp;gt;x\geq e&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + 1&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, for &amp;lt;math&amp;gt;x &amp;gt; 1&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;e^{\sqrt{ex}} \geq 1 + \sqrt{ex} + \frac{ex}{2} \geq x&amp;lt;/math&amp;gt;, which implies&lt;br /&gt;
&amp;lt;math&amp;gt;ex \geq \ln^2(x)&amp;lt;/math&amp;gt; and therefore &amp;lt;math&amp;gt;\ln(x) - \ln\ln(x) + 1 \geq \ln\ln(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==  combinatory logic ==&lt;br /&gt;
&lt;br /&gt;
Basically the paper already written by Marek&lt;br /&gt;
&lt;br /&gt;
+ the following&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As we will see in section ??, theorem ?? does not holds for the Lambda calculus. This may be surprising since there are translations between these systems which respect many properties (for exemple the one of being terminating). However these translations do not preserve the size. &lt;br /&gt;
&lt;br /&gt;
The translation T from combinatory logic to lambda calculus is linear, i.e. there is a constant k such that, for all terms, &amp;lt;math&amp;gt;size(T(t) \leq k.size(t)&amp;lt;/math&amp;gt; but the translation T&#039; in the other direction is not linear. As far as we know, there is no known bound on the size of T&#039;(t) but it is not difficult to find exemples where size(T&#039;(t)) is of order &amp;lt;math&amp;gt;size(t)^3&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The point is that T&#039; has to code the binding in some way and this takes place. It will be interesting to compare the size of T&#039;(t) with the one of t using other notion of size than the usual one. See section ?? for some complement.&lt;br /&gt;
&lt;br /&gt;
== Generality on lambda calculus ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition &lt;br /&gt;
&lt;br /&gt;
The set &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt; of lambda terms (or,&lt;br /&gt;
simply, terms) is defined by the following grammar&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;t, u  := Var \ \mid \ \lambda x.t \ \mid \ (t \ u)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To be able to define the notion of a &#039;&#039;random&#039;&#039; term we&lt;br /&gt;
have to define a distribution law on &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt;. There are many&lt;br /&gt;
possibilities for that. We choose here the simplest one. Note that this is the one for which, at least at present,  we are&lt;br /&gt;
able to prove some results. It is based on densities. For that we&lt;br /&gt;
first have to define the &#039;&#039;size&#039;&#039; of a term.&lt;br /&gt;
&lt;br /&gt;
The usual&lt;br /&gt;
definition is the following.&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
The size (denoted as &amp;lt;math&amp;gt;size_1(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
rules.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(\lambda x.t)=size_1(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1((t \ u))=size_1(t)+size_1(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the rest of the paper we will use another definition (denoted&lt;br /&gt;
as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt;) which is similar but  gives simpler computations.&lt;br /&gt;
We believe (but we have not yet checked the details) that, with&lt;br /&gt;
&amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt; we would have similar results. The&lt;br /&gt;
computation, with &amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt;,  of the upper and lower&lt;br /&gt;
bounds of the number of terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; will be done&lt;br /&gt;
in section ??&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
The size (denoted as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt; or, more simply &amp;lt;math&amp;gt;size(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
rules.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(\lambda x.t)=size_0(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0((t \ u))=size_0(t)+size_0(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These definitions of the size are, for the implementation point of&lt;br /&gt;
view, not realistic because, in case a term has a lot of distinct&lt;br /&gt;
variables, it is not realistic to use a single bit to code them.&lt;br /&gt;
The usual way to implement this coding is to replace the names of&lt;br /&gt;
variables by  their so called de Bruijn indices: a variable is&lt;br /&gt;
replaced by the number of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; that occur, on the&lt;br /&gt;
path from the variable to the root, between the variable and the&lt;br /&gt;
&amp;lt;math&amp;gt;lambda&amp;lt;/math&amp;gt; that binds it. Note that, in this case,&lt;br /&gt;
different occurrences of the same variable may be represented by&lt;br /&gt;
different indices.&lt;br /&gt;
&lt;br /&gt;
Choosing the way we code these de Bruijn indices gives different&lt;br /&gt;
other ways of defining the size of a term. This can be done in the&lt;br /&gt;
following ways&lt;br /&gt;
&lt;br /&gt;
- Use unary notation, i.e. the size of the index &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;&lt;br /&gt;
simply is &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; itself&lt;br /&gt;
&lt;br /&gt;
- Use optimal binary notation, i.e. the size of the index&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;log_2(n)&amp;lt;/math&amp;gt; i.e. the logarithm of&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; in base 2.&lt;br /&gt;
&lt;br /&gt;
- Use uniform binary notation, i.e. the size of an index is the&lt;br /&gt;
logarithm, in base 2, of the number of leaves of the term.&lt;br /&gt;
&lt;br /&gt;
Remark&lt;br /&gt;
&lt;br /&gt;
See section ?? for a discusion about these different size.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; be an integer. We denote by &amp;lt;math&amp;gt;\Lambda_n&amp;lt;/math&amp;gt; the set of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; terms of size n.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let A be a set of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; terms. &lt;br /&gt;
&lt;br /&gt;
1) We denote by &amp;lt;math&amp;gt;\#(A)&amp;lt;/math&amp;gt; the cardinality of A.&lt;br /&gt;
&lt;br /&gt;
2) We denote by &amp;lt;math&amp;gt;d(A)&amp;lt;/math&amp;gt; the limit, for n going to &amp;lt;math&amp;gt;\infty&amp;lt;/math&amp;gt;, &lt;br /&gt;
of &amp;lt;math&amp;gt;\frac{\#(A\cap \Lambda_n)}{\#(\Lambda_n)}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Remark&lt;br /&gt;
&lt;br /&gt;
Note that d is not exactly a measure since &amp;lt;math&amp;gt;d(A)&amp;lt;/math&amp;gt; is undefined if the previous limit does not exist&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let P be a property of terms. We will say that almost every term satisfies P &lt;br /&gt;
(this will be also stated as P holds a.e.) if&lt;br /&gt;
&amp;lt;math&amp;gt;d(\{t \ | \ P(t) holds\})=1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== generating functions ==&lt;br /&gt;
&lt;br /&gt;
this does not work (by now) because radius of convergence 0&lt;br /&gt;
&lt;br /&gt;
no known results for the number of terms of size n (denoted &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
== our results ==&lt;br /&gt;
&lt;br /&gt;
(the proof of result of section k needs the result of section (k-1))&lt;br /&gt;
&lt;br /&gt;
=== Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
For the lower bound, we will first count the number &amp;lt;math&amp;gt;LB(n,k)&amp;lt;/math&amp;gt; of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; starting with &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas and having no other lambda below. This means that the lower part of the term is a binary tree of size &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; with&lt;br /&gt;
&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; possibility for each leaf. Therefore we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) = C(n-k) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And therefore, for &amp;lt;math&amp;gt;n &amp;gt; k&amp;lt;/math&amp;gt;, using our lower bound for &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n + 1 \geq n - k + 1&amp;lt;/math&amp;gt;, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) \geq K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;K=\frac{36}{49\sqrt{\pi}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed, we define &amp;lt;math&amp;gt;f(\alpha) = \left(4n\alpha\right)^{n(1-\alpha) + 1}&amp;lt;/math&amp;gt; (so &amp;lt;math&amp;gt;LB(n,k) \geq \frac{K}{(n+1)^\frac{3}{2}} f\left(\frac{k}{n}\right)&amp;lt;/math&amp;gt;) and look for the maximum of this function. We have &amp;lt;math&amp;gt;f&#039;(\alpha) = f(\alpha) \left(-n\ln(4n\alpha) +\frac{n(1-\alpha) + 1}{\alpha}\right)&amp;lt;/math&amp;gt;. Thus, &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\frac{n+1}{n\alpha}e^{\frac{n+1}{n\alpha}}\geq 4e(n+1)&amp;lt;/math&amp;gt;. The Lambert function begin increasing this means that &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\alpha \leq \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;f(\alpha)&amp;lt;/math&amp;gt; reaches a maximum for &amp;lt;math&amp;gt;\alpha = \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This means that &amp;lt;math&amp;gt;(4k)^{n-k}&amp;lt;/math&amp;gt; reaches its maximum for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed when &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;&lt;br /&gt;
is near to &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; which is likely not to be an integer. However, there are at least &amp;lt;math&amp;gt;\left\lfloor \frac{n (\ln(\ln(4en)) - 1)}{\ln^2(4en)}\right\rfloor&amp;lt;/math&amp;gt; integer between &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\frac{n+1}{\ln(4e(n+1))}&amp;lt;/math&amp;gt;. Indeed, using our inequalities on Lambert W function, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}-\frac{n+1}{\ln(4e(n+1))} = \frac{(n+1) (\ln(4e(n+1)) - W(4e(n+1)))}{W(4e(n+1))\ln(4e(n+1))} \geq \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, we get the following lowerbound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \sum_{k=1}^{n} LB(n,k) \geq \sum_{k=\lceil\frac{n+1}{\ln(4e(n+1))}\rceil}^{\lfloor\frac{n+1}{W(4e(n+1))}\rfloor} K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}} \geq K \left\lfloor \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}\right\rfloor \frac{\left(\frac{4(n+1)}{\ln(4e(n+1))}\right)^{n-\frac{n+1}{\ln(4e(n+1))}+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To simplify, using the fact that &amp;lt;math&amp;gt;\lim_{n\to +\infty}\left(\frac{\ln(n)}{\ln(4en)}\right)^n = 0&amp;lt;/math&amp;gt; and taking &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; large enough, we have the following lowerbound:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \frac{\sqrt{n}}{\ln^3(n)}\left(\frac{4n}{\ln(n)}\right)^{n-\frac{n}{\ln(n)}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We now compute an upper bound &amp;lt;math&amp;gt;UB(n,k)&amp;lt;/math&amp;gt; for the number of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with exactly &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas (that is with &amp;lt;math&amp;gt;n - k + 1&amp;lt;/math&amp;gt; leaves using the Motzkin numbers and allowing any lambda to bind any variable (regardless of the real scope):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;UB(n,k) = M(n,n-k+1) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we sum this for all possible &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and get an upper bound of &amp;lt;math&amp;gt;k^{n-k+1}&amp;lt;/math&amp;gt; using Lambert function as for the lower bound, we get the following upper bound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \leq M(n) \left(\frac{n+1}{W(e(n+1))}\right)^{n-\frac{n+1}{W(e(n+1))} + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The ration between our upper bound and lower bound is equivalent to (NEEDS FURTHER CHECKING):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\left(\frac{1}{4(3-2\sqrt{2})}\right)^n\frac{\ln^3(n)}{n^2} \simeq 1.46^n\frac{\ln^3(n)}{n^2}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== upper and lower bounds for number of lambdas in a term of size n ===&lt;br /&gt;
&lt;br /&gt;
=== Jakub&#039;s trik : at least 1 lambda in head position ===&lt;br /&gt;
&lt;br /&gt;
=== at least &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; lambdas in head position and number of lambdas in one path ===&lt;br /&gt;
&lt;br /&gt;
Remark: (may be 4) can be done directly without 3))&lt;br /&gt;
&lt;br /&gt;
=== each of the  &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; head lambdas really bind &amp;quot;many&amp;quot;  occurrences of the variable ===&lt;br /&gt;
&lt;br /&gt;
=== every fixed closed term (including the identity !) does not appear in a random term (in fact we have much more than that) ===&lt;br /&gt;
&lt;br /&gt;
comment : so different situation in combinatory logic and lambda calculus ; the coding uses a big size so need to count variables in a different way&lt;br /&gt;
&lt;br /&gt;
== Experiments ==&lt;br /&gt;
&lt;br /&gt;
results of the experiments we have done&lt;br /&gt;
&lt;br /&gt;
some experiments that have to be done : e.g. density of terms having &amp;lt;math&amp;gt;\lambda x.y&amp;lt;/math&amp;gt; or big Omega pattern ...&lt;br /&gt;
&lt;br /&gt;
== to be done ==&lt;br /&gt;
&lt;br /&gt;
Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; with other size for variables especially one, binary with fixed size&lt;br /&gt;
&lt;br /&gt;
== Open questions and Future work ==&lt;br /&gt;
&lt;br /&gt;
.....&lt;/div&gt;</summary>
		<author><name>René David</name></author>
	</entry>
	<entry>
		<id>http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2664</id>
		<title>Lambda counting</title>
		<link rel="alternate" type="text/html" href="http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2664"/>
		<updated>2008-10-20T14:37:54Z</updated>

		<summary type="html">&lt;p&gt;René David : /* combinatory logic */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
The question is: among programs, what is the probability of having a fixed property.&lt;br /&gt;
&lt;br /&gt;
what kind of program : turing machines, cellular automata, combinatory logic, lambda calculus&lt;br /&gt;
&lt;br /&gt;
what kind of properties : structural (for functional programs), behaviour (SN, weakly normalizable, ...&lt;br /&gt;
&lt;br /&gt;
references to known results on : turing machines, cellular automata&lt;br /&gt;
&lt;br /&gt;
we concentrate on combinatory logic, lambda calculus&lt;br /&gt;
&lt;br /&gt;
== Lambert function, Catalan and Motzkin numbers ==&lt;br /&gt;
&lt;br /&gt;
=== Catalan numbers ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; : Catalan numbers &lt;br /&gt;
&lt;br /&gt;
Usual equivalent: &amp;lt;math&amp;gt;C(n) \sim \frac{4^n}{n^{3/2}\sqrt{\pi}}&amp;lt;/math&amp;gt; which is obtained using Strirling formula.&lt;br /&gt;
However, using stirling series: &amp;lt;math&amp;gt;&lt;br /&gt;
  n!=\sqrt{2\pi n}\left({n\over e}\right)^n&lt;br /&gt;
  \left(&lt;br /&gt;
   1&lt;br /&gt;
   +{1\over12n}&lt;br /&gt;
   +{1\over288n^2}&lt;br /&gt;
   -{139\over51840n^3}&lt;br /&gt;
   -{571\over2488320n^4}&lt;br /&gt;
   + \cdots&lt;br /&gt;
  \right)&lt;br /&gt;
 &amp;lt;/math&amp;gt;, we get that for &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; we have &amp;lt;math&amp;gt;\sqrt{2\pi n}\left({n\over e}\right)^n \leq n! \leq \frac{7}{6}\sqrt{2\pi n}\left({n\over e}\right)^n&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, using this and &amp;lt;math&amp;gt;\left(\frac{n}{n+1}\right)^{n} &amp;gt; e^{-1}&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C(n) = \frac{(2n)!}{(n+1)!n!} \geq \frac{36}{49\sqrt{\pi}} \frac{4^n}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; but also for &amp;lt;math&amp;gt;n=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Motzkin numbers===&lt;br /&gt;
&lt;br /&gt;
Let us define &amp;lt;math&amp;gt;M(n,k)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; leafs. We get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n,k) = \frac{(n+k-1)!}{(n-k+1)!(k-1)!k!}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, by summing we define &amp;lt;math&amp;gt;M(n)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and give an equivalent:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n) = \sum_{k=0}^n M(n,k) \sim \left(\frac{1}{3-2\sqrt{2}}\right)^n \frac{1}{n^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lambert W function===&lt;br /&gt;
&lt;br /&gt;
The Lambert function &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; is defined by the equation &amp;lt;math&amp;gt;x = W(x) e ^ {W(x)} &amp;lt;/math&amp;gt;&lt;br /&gt;
which has a unique solution in &amp;lt;math&amp;gt;\mathbb{R}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;x \geq e&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x)&amp;lt;/math&amp;gt; which implies that &lt;br /&gt;
&amp;lt;math&amp;gt;W(x) \sim \ln(x)&amp;lt;/math&amp;gt; near &amp;lt;math&amp;gt;+\infty&amp;lt;/math&amp;gt;. To prove this, it is enough to remark that&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;(\ln(x) - \ln(\ln(x))e^{\ln(x)-\ln(\ln(x))} = x \left(1 - \frac{\ln(\ln(x))}{\ln(x)}\right) \leq x \leq x \ln(x) = \ln(x) e^{\ln(x)} &amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is not precise enough for our purpose. Using one step of the Newton method from &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt;, we can find a better upper bound for &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; because &amp;lt;math&amp;gt;y \mapsto y e^y&amp;lt;/math&amp;gt; is increasing and convex. This gives:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, if we define &amp;lt;math&amp;gt;f(y) = y e^y&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;f&#039;(y)=(1+y)e^y&amp;lt;/math&amp;gt; and therefore, newton&#039;s method from &amp;lt;math&amp;gt;A = \ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt; gives a point at position:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;&lt;br /&gt;
A - \frac{f(A) - x}{f&#039;(A)} &lt;br /&gt;
  = A +  \frac{x \ln(\ln(x))}{\ln(x)} \frac{\ln(x)}{x(\ln(x) - \ln(\ln(x)) + 1)}&lt;br /&gt;
  = A +  \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1} &lt;br /&gt;
&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, we show that for &amp;lt;math&amp;gt;x\geq e&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + 1&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, for &amp;lt;math&amp;gt;x &amp;gt; 1&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;e^{\sqrt{ex}} \geq 1 + \sqrt{ex} + \frac{ex}{2} \geq x&amp;lt;/math&amp;gt;, which implies&lt;br /&gt;
&amp;lt;math&amp;gt;ex \geq \ln^2(x)&amp;lt;/math&amp;gt; and therefore &amp;lt;math&amp;gt;\ln(x) - \ln\ln(x) + 1 \geq \ln\ln(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==  combinatory logic ==&lt;br /&gt;
&lt;br /&gt;
Basically the paper already written by Marek&lt;br /&gt;
&lt;br /&gt;
+ the following&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As we will see in section ??, theorem ?? does not holds for the Lambda calculus. This may be surprising since there are translations between these systems which respect many properties (for exemple the one of being terminating). However these translations do not preserve the size. &lt;br /&gt;
&lt;br /&gt;
The translation T from combinatory logic to lambda calculus is linear, i.e. there is a constant k such that, for all terms, &amp;lt;math&amp;gt;size(T(t) \leq k.size(t)&amp;lt;/math&amp;gt; but the translation T&#039; in the other direction is not linear. As far as we know, there is no known bound on the size of T&#039;(t) but it is not difficult to find exemples where size(T&#039;(t)) is of order &amp;lt;math&amp;gt;size(t)^3&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The point is that T&#039; has to code the binding in some way and this takes place. It will be intersting to compare&lt;br /&gt;
&lt;br /&gt;
== Generality on lambda calculus ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition &lt;br /&gt;
&lt;br /&gt;
The set &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt; of lambda terms (or,&lt;br /&gt;
simply, terms) is defined by the following grammar&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;t, u  := Var \ \mid \ \lambda x.t \ \mid \ (t \ u)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To be able to define the notion of a &#039;&#039;random&#039;&#039; term we&lt;br /&gt;
have to define a distribution law on &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt;. There are many&lt;br /&gt;
possibilities for that. We choose here the simplest one. Note that this is the one for which, at least at present,  we are&lt;br /&gt;
able to prove some results. It is based on densities. For that we&lt;br /&gt;
first have to define the &#039;&#039;size&#039;&#039; of a term.&lt;br /&gt;
&lt;br /&gt;
The usual&lt;br /&gt;
definition is the following.&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
The size (denoted as &amp;lt;math&amp;gt;size_1(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
rules.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(\lambda x.t)=size_1(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1((t \ u))=size_1(t)+size_1(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the rest of the paper we will use another definition (denoted&lt;br /&gt;
as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt;) which is similar but  gives simpler computations.&lt;br /&gt;
We believe (but we have not yet checked the details) that, with&lt;br /&gt;
&amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt; we would have similar results. The&lt;br /&gt;
computation, with &amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt;,  of the upper and lower&lt;br /&gt;
bounds of the number of terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; will be done&lt;br /&gt;
in section ??&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
The size (denoted as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt; or, more simply &amp;lt;math&amp;gt;size(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
rules.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(\lambda x.t)=size_0(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0((t \ u))=size_0(t)+size_0(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These definitions of the size are, for the implementation point of&lt;br /&gt;
view, not realistic because, in case a term has a lot of distinct&lt;br /&gt;
variables, it is not realistic to use a single bit to code them.&lt;br /&gt;
The usual way to implement this coding is to replace the names of&lt;br /&gt;
variables by  their so called de Bruijn indices: a variable is&lt;br /&gt;
replaced by the number of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; that occur, on the&lt;br /&gt;
path from the variable to the root, between the variable and the&lt;br /&gt;
&amp;lt;math&amp;gt;lambda&amp;lt;/math&amp;gt; that binds it. Note that, in this case,&lt;br /&gt;
different occurrences of the same variable may be represented by&lt;br /&gt;
different indices.&lt;br /&gt;
&lt;br /&gt;
Choosing the way we code these de Bruijn indices gives different&lt;br /&gt;
other ways of defining the size of a term. This can be done in the&lt;br /&gt;
following ways&lt;br /&gt;
&lt;br /&gt;
- Use unary notation, i.e. the size of the index &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;&lt;br /&gt;
simply is &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; itself&lt;br /&gt;
&lt;br /&gt;
- Use optimal binary notation, i.e. the size of the index&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;log_2(n)&amp;lt;/math&amp;gt; i.e. the logarithm of&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; in base 2.&lt;br /&gt;
&lt;br /&gt;
- Use uniform binary notation, i.e. the size of an index is the&lt;br /&gt;
logarithm, in base 2, of the number of leaves of the term.&lt;br /&gt;
&lt;br /&gt;
Remark&lt;br /&gt;
&lt;br /&gt;
See section ?? for a discusion about these different size.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; be an integer. We denote by &amp;lt;math&amp;gt;\Lambda_n&amp;lt;/math&amp;gt; the set of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; terms of size n.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let A be a set of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; terms. &lt;br /&gt;
&lt;br /&gt;
1) We denote by &amp;lt;math&amp;gt;\#(A)&amp;lt;/math&amp;gt; the cardinality of A.&lt;br /&gt;
&lt;br /&gt;
2) We denote by &amp;lt;math&amp;gt;d(A)&amp;lt;/math&amp;gt; the limit, for n going to &amp;lt;math&amp;gt;\infty&amp;lt;/math&amp;gt;, &lt;br /&gt;
of &amp;lt;math&amp;gt;\frac{\#(A\cap \Lambda_n)}{\#(\Lambda_n)}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Remark&lt;br /&gt;
&lt;br /&gt;
Note that d is not exactly a measure since &amp;lt;math&amp;gt;d(A)&amp;lt;/math&amp;gt; is undefined if the previous limit does not exist&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let P be a property of terms. We will say that almost every term satisfies P &lt;br /&gt;
(this will be also stated as P holds a.e.) if&lt;br /&gt;
&amp;lt;math&amp;gt;d(\{t \ | \ P(t) holds\})=1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== generating functions ==&lt;br /&gt;
&lt;br /&gt;
this does not work (by now) because radius of convergence 0&lt;br /&gt;
&lt;br /&gt;
no known results for the number of terms of size n (denoted &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
== our results ==&lt;br /&gt;
&lt;br /&gt;
(the proof of result of section k needs the result of section (k-1))&lt;br /&gt;
&lt;br /&gt;
=== Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
For the lower bound, we will first count the number &amp;lt;math&amp;gt;LB(n,k)&amp;lt;/math&amp;gt; of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; starting with &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas and having no other lambda below. This means that the lower part of the term is a binary tree of size &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; with&lt;br /&gt;
&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; possibility for each leaf. Therefore we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) = C(n-k) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And therefore, for &amp;lt;math&amp;gt;n &amp;gt; k&amp;lt;/math&amp;gt;, using our lower bound for &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n + 1 \geq n - k + 1&amp;lt;/math&amp;gt;, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) \geq K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;K=\frac{36}{49\sqrt{\pi}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed, we define &amp;lt;math&amp;gt;f(\alpha) = \left(4n\alpha\right)^{n(1-\alpha) + 1}&amp;lt;/math&amp;gt; (so &amp;lt;math&amp;gt;LB(n,k) \geq \frac{K}{(n+1)^\frac{3}{2}} f\left(\frac{k}{n}\right)&amp;lt;/math&amp;gt;) and look for the maximum of this function. We have &amp;lt;math&amp;gt;f&#039;(\alpha) = f(\alpha) \left(-n\ln(4n\alpha) +\frac{n(1-\alpha) + 1}{\alpha}\right)&amp;lt;/math&amp;gt;. Thus, &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\frac{n+1}{n\alpha}e^{\frac{n+1}{n\alpha}}\geq 4e(n+1)&amp;lt;/math&amp;gt;. The Lambert function begin increasing this means that &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\alpha \leq \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;f(\alpha)&amp;lt;/math&amp;gt; reaches a maximum for &amp;lt;math&amp;gt;\alpha = \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This means that &amp;lt;math&amp;gt;(4k)^{n-k}&amp;lt;/math&amp;gt; reaches its maximum for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed when &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;&lt;br /&gt;
is near to &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; which is likely not to be an integer. However, there are at least &amp;lt;math&amp;gt;\left\lfloor \frac{n (\ln(\ln(4en)) - 1)}{\ln^2(4en)}\right\rfloor&amp;lt;/math&amp;gt; integer between &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\frac{n+1}{\ln(4e(n+1))}&amp;lt;/math&amp;gt;. Indeed, using our inequalities on Lambert W function, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}-\frac{n+1}{\ln(4e(n+1))} = \frac{(n+1) (\ln(4e(n+1)) - W(4e(n+1)))}{W(4e(n+1))\ln(4e(n+1))} \geq \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, we get the following lowerbound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \sum_{k=1}^{n} LB(n,k) \geq \sum_{k=\lceil\frac{n+1}{\ln(4e(n+1))}\rceil}^{\lfloor\frac{n+1}{W(4e(n+1))}\rfloor} K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}} \geq K \left\lfloor \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}\right\rfloor \frac{\left(\frac{4(n+1)}{\ln(4e(n+1))}\right)^{n-\frac{n+1}{\ln(4e(n+1))}+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To simplify, using the fact that &amp;lt;math&amp;gt;\lim_{n\to +\infty}\left(\frac{\ln(n)}{\ln(4en)}\right)^n = 0&amp;lt;/math&amp;gt; and taking &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; large enough, we have the following lowerbound:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \frac{\sqrt{n}}{\ln^3(n)}\left(\frac{4n}{\ln(n)}\right)^{n-\frac{n}{\ln(n)}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We now compute an upper bound &amp;lt;math&amp;gt;UB(n,k)&amp;lt;/math&amp;gt; for the number of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with exactly &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas (that is with &amp;lt;math&amp;gt;n - k + 1&amp;lt;/math&amp;gt; leaves using the Motzkin numbers and allowing any lambda to bind any variable (regardless of the real scope):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;UB(n,k) = M(n,n-k+1) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we sum this for all possible &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and get an upper bound of &amp;lt;math&amp;gt;k^{n-k+1}&amp;lt;/math&amp;gt; using Lambert function as for the lower bound, we get the following upper bound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \leq M(n) \left(\frac{n+1}{W(e(n+1))}\right)^{n-\frac{n+1}{W(e(n+1))} + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The ration between our upper bound and lower bound is equivalent to (NEEDS FURTHER CHECKING):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\left(\frac{1}{4(3-2\sqrt{2})}\right)^n\frac{\ln^3(n)}{n^2} \simeq 1.46^n\frac{\ln^3(n)}{n^2}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== upper and lower bounds for number of lambdas in a term of size n ===&lt;br /&gt;
&lt;br /&gt;
=== Jakub&#039;s trik : at least 1 lambda in head position ===&lt;br /&gt;
&lt;br /&gt;
=== at least &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; lambdas in head position and number of lambdas in one path ===&lt;br /&gt;
&lt;br /&gt;
Remark: (may be 4) can be done directly without 3))&lt;br /&gt;
&lt;br /&gt;
=== each of the  &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; head lambdas really bind &amp;quot;many&amp;quot;  occurrences of the variable ===&lt;br /&gt;
&lt;br /&gt;
=== every fixed closed term (including the identity !) does not appear in a random term (in fact we have much more than that) ===&lt;br /&gt;
&lt;br /&gt;
comment : so different situation in combinatory logic and lambda calculus ; the coding uses a big size so need to count variables in a different way&lt;br /&gt;
&lt;br /&gt;
== Experiments ==&lt;br /&gt;
&lt;br /&gt;
results of the experiments we have done&lt;br /&gt;
&lt;br /&gt;
some experiments that have to be done : e.g. density of terms having &amp;lt;math&amp;gt;\lambda x.y&amp;lt;/math&amp;gt; or big Omega pattern ...&lt;br /&gt;
&lt;br /&gt;
== to be done ==&lt;br /&gt;
&lt;br /&gt;
Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; with other size for variables especially one, binary with fixed size&lt;br /&gt;
&lt;br /&gt;
== Open questions and Future work ==&lt;br /&gt;
&lt;br /&gt;
.....&lt;/div&gt;</summary>
		<author><name>René David</name></author>
	</entry>
	<entry>
		<id>http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2663</id>
		<title>Lambda counting</title>
		<link rel="alternate" type="text/html" href="http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2663"/>
		<updated>2008-10-20T14:09:08Z</updated>

		<summary type="html">&lt;p&gt;René David : /* combinatory logic */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
The question is: among programs, what is the probability of having a fixed property.&lt;br /&gt;
&lt;br /&gt;
what kind of program : turing machines, cellular automata, combinatory logic, lambda calculus&lt;br /&gt;
&lt;br /&gt;
what kind of properties : structural (for functional programs), behaviour (SN, weakly normalizable, ...&lt;br /&gt;
&lt;br /&gt;
references to known results on : turing machines, cellular automata&lt;br /&gt;
&lt;br /&gt;
we concentrate on combinatory logic, lambda calculus&lt;br /&gt;
&lt;br /&gt;
== Lambert function, Catalan and Motzkin numbers ==&lt;br /&gt;
&lt;br /&gt;
=== Catalan numbers ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; : Catalan numbers &lt;br /&gt;
&lt;br /&gt;
Usual equivalent: &amp;lt;math&amp;gt;C(n) \sim \frac{4^n}{n^{3/2}\sqrt{\pi}}&amp;lt;/math&amp;gt; which is obtained using Strirling formula.&lt;br /&gt;
However, using stirling series: &amp;lt;math&amp;gt;&lt;br /&gt;
  n!=\sqrt{2\pi n}\left({n\over e}\right)^n&lt;br /&gt;
  \left(&lt;br /&gt;
   1&lt;br /&gt;
   +{1\over12n}&lt;br /&gt;
   +{1\over288n^2}&lt;br /&gt;
   -{139\over51840n^3}&lt;br /&gt;
   -{571\over2488320n^4}&lt;br /&gt;
   + \cdots&lt;br /&gt;
  \right)&lt;br /&gt;
 &amp;lt;/math&amp;gt;, we get that for &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; we have &amp;lt;math&amp;gt;\sqrt{2\pi n}\left({n\over e}\right)^n \leq n! \leq \frac{7}{6}\sqrt{2\pi n}\left({n\over e}\right)^n&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, using this and &amp;lt;math&amp;gt;\left(\frac{n}{n+1}\right)^{n} &amp;gt; e^{-1}&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C(n) = \frac{(2n)!}{(n+1)!n!} \geq \frac{36}{49\sqrt{\pi}} \frac{4^n}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; but also for &amp;lt;math&amp;gt;n=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Motzkin numbers===&lt;br /&gt;
&lt;br /&gt;
Let us define &amp;lt;math&amp;gt;M(n,k)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; leafs. We get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n,k) = \frac{(n+k-1)!}{(n-k+1)!(k-1)!k!}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, by summing we define &amp;lt;math&amp;gt;M(n)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and give an equivalent:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n) = \sum_{k=0}^n M(n,k) \sim \left(\frac{1}{3-2\sqrt{2}}\right)^n \frac{1}{n^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lambert W function===&lt;br /&gt;
&lt;br /&gt;
The Lambert function &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; is defined by the equation &amp;lt;math&amp;gt;x = W(x) e ^ {W(x)} &amp;lt;/math&amp;gt;&lt;br /&gt;
which has a unique solution in &amp;lt;math&amp;gt;\mathbb{R}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;x \geq e&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x)&amp;lt;/math&amp;gt; which implies that &lt;br /&gt;
&amp;lt;math&amp;gt;W(x) \sim \ln(x)&amp;lt;/math&amp;gt; near &amp;lt;math&amp;gt;+\infty&amp;lt;/math&amp;gt;. To prove this, it is enough to remark that&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;(\ln(x) - \ln(\ln(x))e^{\ln(x)-\ln(\ln(x))} = x \left(1 - \frac{\ln(\ln(x))}{\ln(x)}\right) \leq x \leq x \ln(x) = \ln(x) e^{\ln(x)} &amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is not precise enough for our purpose. Using one step of the Newton method from &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt;, we can find a better upper bound for &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; because &amp;lt;math&amp;gt;y \mapsto y e^y&amp;lt;/math&amp;gt; is increasing and convex. This gives:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, if we define &amp;lt;math&amp;gt;f(y) = y e^y&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;f&#039;(y)=(1+y)e^y&amp;lt;/math&amp;gt; and therefore, newton&#039;s method from &amp;lt;math&amp;gt;A = \ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt; gives a point at position:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;&lt;br /&gt;
A - \frac{f(A) - x}{f&#039;(A)} &lt;br /&gt;
  = A +  \frac{x \ln(\ln(x))}{\ln(x)} \frac{\ln(x)}{x(\ln(x) - \ln(\ln(x)) + 1)}&lt;br /&gt;
  = A +  \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1} &lt;br /&gt;
&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, we show that for &amp;lt;math&amp;gt;x\geq e&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + 1&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, for &amp;lt;math&amp;gt;x &amp;gt; 1&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;e^{\sqrt{ex}} \geq 1 + \sqrt{ex} + \frac{ex}{2} \geq x&amp;lt;/math&amp;gt;, which implies&lt;br /&gt;
&amp;lt;math&amp;gt;ex \geq \ln^2(x)&amp;lt;/math&amp;gt; and therefore &amp;lt;math&amp;gt;\ln(x) - \ln\ln(x) + 1 \geq \ln\ln(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==  combinatory logic ==&lt;br /&gt;
&lt;br /&gt;
Basically the paper already written by Marek&lt;br /&gt;
&lt;br /&gt;
+ the following&lt;br /&gt;
&lt;br /&gt;
== Generality on lambda calculus ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition &lt;br /&gt;
&lt;br /&gt;
The set &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt; of lambda terms (or,&lt;br /&gt;
simply, terms) is defined by the following grammar&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;t, u  := Var \ \mid \ \lambda x.t \ \mid \ (t \ u)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To be able to define the notion of a &#039;&#039;random&#039;&#039; term we&lt;br /&gt;
have to define a distribution law on &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt;. There are many&lt;br /&gt;
possibilities for that. We choose here the simplest one. Note that this is the one for which, at least at present,  we are&lt;br /&gt;
able to prove some results. It is based on densities. For that we&lt;br /&gt;
first have to define the &#039;&#039;size&#039;&#039; of a term.&lt;br /&gt;
&lt;br /&gt;
The usual&lt;br /&gt;
definition is the following.&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
The size (denoted as &amp;lt;math&amp;gt;size_1(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
rules.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(\lambda x.t)=size_1(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1((t \ u))=size_1(t)+size_1(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the rest of the paper we will use another definition (denoted&lt;br /&gt;
as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt;) which is similar but  gives simpler computations.&lt;br /&gt;
We believe (but we have not yet checked the details) that, with&lt;br /&gt;
&amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt; we would have similar results. The&lt;br /&gt;
computation, with &amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt;,  of the upper and lower&lt;br /&gt;
bounds of the number of terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; will be done&lt;br /&gt;
in section ??&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
The size (denoted as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt; or, more simply &amp;lt;math&amp;gt;size(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
rules.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(\lambda x.t)=size_0(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0((t \ u))=size_0(t)+size_0(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These definitions of the size are, for the implementation point of&lt;br /&gt;
view, not realistic because, in case a term has a lot of distinct&lt;br /&gt;
variables, it is not realistic to use a single bit to code them.&lt;br /&gt;
The usual way to implement this coding is to replace the names of&lt;br /&gt;
variables by  their so called de Bruijn indices: a variable is&lt;br /&gt;
replaced by the number of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; that occur, on the&lt;br /&gt;
path from the variable to the root, between the variable and the&lt;br /&gt;
&amp;lt;math&amp;gt;lambda&amp;lt;/math&amp;gt; that binds it. Note that, in this case,&lt;br /&gt;
different occurrences of the same variable may be represented by&lt;br /&gt;
different indices.&lt;br /&gt;
&lt;br /&gt;
Choosing the way we code these de Bruijn indices gives different&lt;br /&gt;
other ways of defining the size of a term. This can be done in the&lt;br /&gt;
following ways&lt;br /&gt;
&lt;br /&gt;
- Use unary notation, i.e. the size of the index &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;&lt;br /&gt;
simply is &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; itself&lt;br /&gt;
&lt;br /&gt;
- Use optimal binary notation, i.e. the size of the index&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;log_2(n)&amp;lt;/math&amp;gt; i.e. the logarithm of&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; in base 2.&lt;br /&gt;
&lt;br /&gt;
- Use uniform binary notation, i.e. the size of an index is the&lt;br /&gt;
logarithm, in base 2, of the number of leaves of the term.&lt;br /&gt;
&lt;br /&gt;
Remark&lt;br /&gt;
&lt;br /&gt;
See section ?? for a discusion about these different size.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; be an integer. We denote by &amp;lt;math&amp;gt;\Lambda_n&amp;lt;/math&amp;gt; the set of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; terms of size n.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let A be a set of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; terms. &lt;br /&gt;
&lt;br /&gt;
1) We denote by &amp;lt;math&amp;gt;\#(A)&amp;lt;/math&amp;gt; the cardinality of A.&lt;br /&gt;
&lt;br /&gt;
2) We denote by &amp;lt;math&amp;gt;d(A)&amp;lt;/math&amp;gt; the limit, for n going to &amp;lt;math&amp;gt;\infty&amp;lt;/math&amp;gt;, &lt;br /&gt;
of &amp;lt;math&amp;gt;\frac{\#(A\cap \Lambda_n)}{\#(\Lambda_n)}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Remark&lt;br /&gt;
&lt;br /&gt;
Note that d is not exactly a measure since &amp;lt;math&amp;gt;d(A)&amp;lt;/math&amp;gt; is undefined if the previous limit does not exist&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let P be a property of terms. We will say that almost every term satisfies P &lt;br /&gt;
(this will be also stated as P holds a.e.) if&lt;br /&gt;
&amp;lt;math&amp;gt;d(\{t \ | \ P(t) holds\})=1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== generating functions ==&lt;br /&gt;
&lt;br /&gt;
this does not work (by now) because radius of convergence 0&lt;br /&gt;
&lt;br /&gt;
no known results for the number of terms of size n (denoted &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
== our results ==&lt;br /&gt;
&lt;br /&gt;
(the proof of result of section k needs the result of section (k-1))&lt;br /&gt;
&lt;br /&gt;
=== Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
For the lower bound, we will first count the number &amp;lt;math&amp;gt;LB(n,k)&amp;lt;/math&amp;gt; of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; starting with &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas and having no other lambda below. This means that the lower part of the term is a binary tree of size &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; with&lt;br /&gt;
&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; possibility for each leaf. Therefore we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) = C(n-k) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And therefore, for &amp;lt;math&amp;gt;n &amp;gt; k&amp;lt;/math&amp;gt;, using our lower bound for &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n + 1 \geq n - k + 1&amp;lt;/math&amp;gt;, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) \geq K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;K=\frac{36}{49\sqrt{\pi}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed, we define &amp;lt;math&amp;gt;f(\alpha) = \left(4n\alpha\right)^{n(1-\alpha) + 1}&amp;lt;/math&amp;gt; (so &amp;lt;math&amp;gt;LB(n,k) \geq \frac{K}{(n+1)^\frac{3}{2}} f\left(\frac{k}{n}\right)&amp;lt;/math&amp;gt;) and look for the maximum of this function. We have &amp;lt;math&amp;gt;f&#039;(\alpha) = f(\alpha) \left(-n\ln(4n\alpha) +\frac{n(1-\alpha) + 1}{\alpha}\right)&amp;lt;/math&amp;gt;. Thus, &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\frac{n+1}{n\alpha}e^{\frac{n+1}{n\alpha}}\geq 4e(n+1)&amp;lt;/math&amp;gt;. The Lambert function begin increasing this means that &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\alpha \leq \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;f(\alpha)&amp;lt;/math&amp;gt; reaches a maximum for &amp;lt;math&amp;gt;\alpha = \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This means that &amp;lt;math&amp;gt;(4k)^{n-k}&amp;lt;/math&amp;gt; reaches its maximum for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed when &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;&lt;br /&gt;
is near to &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; which is likely not to be an integer. However, there are at least &amp;lt;math&amp;gt;\left\lfloor \frac{n (\ln(\ln(4en)) - 1)}{\ln^2(4en)}\right\rfloor&amp;lt;/math&amp;gt; integer between &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\frac{n+1}{\ln(4e(n+1))}&amp;lt;/math&amp;gt;. Indeed, using our inequalities on Lambert W function, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}-\frac{n+1}{\ln(4e(n+1))} = \frac{(n+1) (\ln(4e(n+1)) - W(4e(n+1)))}{W(4e(n+1))\ln(4e(n+1))} \geq \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, we get the following lowerbound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \sum_{k=1}^{n} LB(n,k) \geq \sum_{k=\lceil\frac{n+1}{\ln(4e(n+1))}\rceil}^{\lfloor\frac{n+1}{W(4e(n+1))}\rfloor} K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}} \geq K \left\lfloor \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}\right\rfloor \frac{\left(\frac{4(n+1)}{\ln(4e(n+1))}\right)^{n-\frac{n+1}{\ln(4e(n+1))}+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To simplify, using the fact that &amp;lt;math&amp;gt;\lim_{n\to +\infty}\left(\frac{\ln(n)}{\ln(4en)}\right)^n = 0&amp;lt;/math&amp;gt; and taking &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; large enough, we have the following lowerbound:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \frac{\sqrt{n}}{\ln^3(n)}\left(\frac{4n}{\ln(n)}\right)^{n-\frac{n}{\ln(n)}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We now compute an upper bound &amp;lt;math&amp;gt;UB(n,k)&amp;lt;/math&amp;gt; for the number of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with exactly &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas (that is with &amp;lt;math&amp;gt;n - k + 1&amp;lt;/math&amp;gt; leaves using the Motzkin numbers and allowing any lambda to bind any variable (regardless of the real scope):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;UB(n,k) = M(n,n-k+1) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we sum this for all possible &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and get an upper bound of &amp;lt;math&amp;gt;k^{n-k+1}&amp;lt;/math&amp;gt; using Lambert function as for the lower bound, we get the following upper bound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \leq M(n) \left(\frac{n+1}{W(e(n+1))}\right)^{n-\frac{n+1}{W(e(n+1))} + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The ration between our upper bound and lower bound is equivalent to (NEEDS FURTHER CHECKING):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\left(\frac{1}{4(3-2\sqrt{2})}\right)^n\frac{\ln^3(n)}{n^2} \simeq 1.46^n\frac{\ln^3(n)}{n^2}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== upper and lower bounds for number of lambdas in a term of size n ===&lt;br /&gt;
&lt;br /&gt;
=== Jakub&#039;s trik : at least 1 lambda in head position ===&lt;br /&gt;
&lt;br /&gt;
=== at least &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; lambdas in head position and number of lambdas in one path ===&lt;br /&gt;
&lt;br /&gt;
Remark: (may be 4) can be done directly without 3))&lt;br /&gt;
&lt;br /&gt;
=== each of the  &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; head lambdas really bind &amp;quot;many&amp;quot;  occurrences of the variable ===&lt;br /&gt;
&lt;br /&gt;
=== every fixed closed term (including the identity !) does not appear in a random term (in fact we have much more than that) ===&lt;br /&gt;
&lt;br /&gt;
comment : so different situation in combinatory logic and lambda calculus ; the coding uses a big size so need to count variables in a different way&lt;br /&gt;
&lt;br /&gt;
== Experiments ==&lt;br /&gt;
&lt;br /&gt;
results of the experiments we have done&lt;br /&gt;
&lt;br /&gt;
some experiments that have to be done : e.g. density of terms having &amp;lt;math&amp;gt;\lambda x.y&amp;lt;/math&amp;gt; or big Omega pattern ...&lt;br /&gt;
&lt;br /&gt;
== to be done ==&lt;br /&gt;
&lt;br /&gt;
Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; with other size for variables especially one, binary with fixed size&lt;br /&gt;
&lt;br /&gt;
== Open questions and Future work ==&lt;br /&gt;
&lt;br /&gt;
.....&lt;/div&gt;</summary>
		<author><name>René David</name></author>
	</entry>
	<entry>
		<id>http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Discussion:Lambda_counting&amp;diff=2662</id>
		<title>Discussion:Lambda counting</title>
		<link rel="alternate" type="text/html" href="http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Discussion:Lambda_counting&amp;diff=2662"/>
		<updated>2008-10-20T14:07:27Z</updated>

		<summary type="html">&lt;p&gt;René David : /* Current semaphore */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Current semaphore==&lt;br /&gt;
&lt;br /&gt;
Attribution of the work currently being done (this is a semaphore !)&lt;br /&gt;
&lt;br /&gt;
Rene: &lt;br /&gt;
* section about combinatory logic&lt;br /&gt;
&lt;br /&gt;
Christophe:&lt;br /&gt;
* the lower and upper bound for size 0 variables&lt;br /&gt;
&lt;br /&gt;
Kasia:&lt;br /&gt;
* the result about closed-term (and much more)&lt;br /&gt;
&lt;br /&gt;
Marek:&lt;br /&gt;
&lt;br /&gt;
Jakub:&lt;br /&gt;
&lt;br /&gt;
Guillaume:&lt;br /&gt;
&lt;br /&gt;
==Reservation of future semaphore==&lt;br /&gt;
&lt;br /&gt;
Rene: &lt;br /&gt;
&lt;br /&gt;
Christophe:&lt;br /&gt;
&lt;br /&gt;
Kasia:&lt;br /&gt;
* generating function&lt;br /&gt;
&lt;br /&gt;
Marek:&lt;br /&gt;
&lt;br /&gt;
Jakub:&lt;br /&gt;
&lt;br /&gt;
Guillaume:&lt;br /&gt;
&lt;br /&gt;
== About the lower bound ==&lt;br /&gt;
&lt;br /&gt;
The lower bound can probably be improved by replacing Catalan with the sum of Mtzkin M(n,k) for&lt;br /&gt;
k between 0 and n/ln(n). This probably would give the same exponential factor for the lower and upper bound and get us nearer to an equivalent. Is it worth it ?&lt;/div&gt;</summary>
		<author><name>René David</name></author>
	</entry>
	<entry>
		<id>http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2661</id>
		<title>Lambda counting</title>
		<link rel="alternate" type="text/html" href="http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2661"/>
		<updated>2008-10-20T14:03:05Z</updated>

		<summary type="html">&lt;p&gt;René David : /* Generality on lambda calculus */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
The question is: among programs, what is the probability of having a fixed property.&lt;br /&gt;
&lt;br /&gt;
what kind of program : turing machines, cellular automata, combinatory logic, lambda calculus&lt;br /&gt;
&lt;br /&gt;
what kind of properties : structural (for functional programs), behaviour (SN, weakly normalizable, ...&lt;br /&gt;
&lt;br /&gt;
references to known results on : turing machines, cellular automata&lt;br /&gt;
&lt;br /&gt;
we concentrate on combinatory logic, lambda calculus&lt;br /&gt;
&lt;br /&gt;
== Lambert function, Catalan and Motzkin numbers ==&lt;br /&gt;
&lt;br /&gt;
=== Catalan numbers ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; : Catalan numbers &lt;br /&gt;
&lt;br /&gt;
Usual equivalent: &amp;lt;math&amp;gt;C(n) \sim \frac{4^n}{n^{3/2}\sqrt{\pi}}&amp;lt;/math&amp;gt; which is obtained using Strirling formula.&lt;br /&gt;
However, using stirling series: &amp;lt;math&amp;gt;&lt;br /&gt;
  n!=\sqrt{2\pi n}\left({n\over e}\right)^n&lt;br /&gt;
  \left(&lt;br /&gt;
   1&lt;br /&gt;
   +{1\over12n}&lt;br /&gt;
   +{1\over288n^2}&lt;br /&gt;
   -{139\over51840n^3}&lt;br /&gt;
   -{571\over2488320n^4}&lt;br /&gt;
   + \cdots&lt;br /&gt;
  \right)&lt;br /&gt;
 &amp;lt;/math&amp;gt;, we get that for &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; we have &amp;lt;math&amp;gt;\sqrt{2\pi n}\left({n\over e}\right)^n \leq n! \leq \frac{7}{6}\sqrt{2\pi n}\left({n\over e}\right)^n&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, using this and &amp;lt;math&amp;gt;\left(\frac{n}{n+1}\right)^{n} &amp;gt; e^{-1}&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C(n) = \frac{(2n)!}{(n+1)!n!} \geq \frac{36}{49\sqrt{\pi}} \frac{4^n}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; but also for &amp;lt;math&amp;gt;n=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Motzkin numbers===&lt;br /&gt;
&lt;br /&gt;
Let us define &amp;lt;math&amp;gt;M(n,k)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; leafs. We get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n,k) = \frac{(n+k-1)!}{(n-k+1)!(k-1)!k!}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, by summing we define &amp;lt;math&amp;gt;M(n)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and give an equivalent:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n) = \sum_{k=0}^n M(n,k) \sim \left(\frac{1}{3-2\sqrt{2}}\right)^n \frac{1}{n^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lambert W function===&lt;br /&gt;
&lt;br /&gt;
The Lambert function &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; is defined by the equation &amp;lt;math&amp;gt;x = W(x) e ^ {W(x)} &amp;lt;/math&amp;gt;&lt;br /&gt;
which has a unique solution in &amp;lt;math&amp;gt;\mathbb{R}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;x \geq e&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x)&amp;lt;/math&amp;gt; which implies that &lt;br /&gt;
&amp;lt;math&amp;gt;W(x) \sim \ln(x)&amp;lt;/math&amp;gt; near &amp;lt;math&amp;gt;+\infty&amp;lt;/math&amp;gt;. To prove this, it is enough to remark that&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;(\ln(x) - \ln(\ln(x))e^{\ln(x)-\ln(\ln(x))} = x \left(1 - \frac{\ln(\ln(x))}{\ln(x)}\right) \leq x \leq x \ln(x) = \ln(x) e^{\ln(x)} &amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is not precise enough for our purpose. Using one step of the Newton method from &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt;, we can find a better upper bound for &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; because &amp;lt;math&amp;gt;y \mapsto y e^y&amp;lt;/math&amp;gt; is increasing and convex. This gives:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, if we define &amp;lt;math&amp;gt;f(y) = y e^y&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;f&#039;(y)=(1+y)e^y&amp;lt;/math&amp;gt; and therefore, newton&#039;s method from &amp;lt;math&amp;gt;A = \ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt; gives a point at position:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;&lt;br /&gt;
A - \frac{f(A) - x}{f&#039;(A)} &lt;br /&gt;
  = A +  \frac{x \ln(\ln(x))}{\ln(x)} \frac{\ln(x)}{x(\ln(x) - \ln(\ln(x)) + 1)}&lt;br /&gt;
  = A +  \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1} &lt;br /&gt;
&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, we show that for &amp;lt;math&amp;gt;x\geq e&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + 1&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, for &amp;lt;math&amp;gt;x &amp;gt; 1&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;e^{\sqrt{ex}} \geq 1 + \sqrt{ex} + \frac{ex}{2} \geq x&amp;lt;/math&amp;gt;, which implies&lt;br /&gt;
&amp;lt;math&amp;gt;ex \geq \ln^2(x)&amp;lt;/math&amp;gt; and therefore &amp;lt;math&amp;gt;\ln(x) - \ln\ln(x) + 1 \geq \ln\ln(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==  combinatory logic ==&lt;br /&gt;
&lt;br /&gt;
results on  combinatory logic&lt;br /&gt;
&lt;br /&gt;
== Generality on lambda calculus ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition &lt;br /&gt;
&lt;br /&gt;
The set &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt; of lambda terms (or,&lt;br /&gt;
simply, terms) is defined by the following grammar&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;t, u  := Var \ \mid \ \lambda x.t \ \mid \ (t \ u)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To be able to define the notion of a &#039;&#039;random&#039;&#039; term we&lt;br /&gt;
have to define a distribution law on &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt;. There are many&lt;br /&gt;
possibilities for that. We choose here the simplest one. Note that this is the one for which, at least at present,  we are&lt;br /&gt;
able to prove some results. It is based on densities. For that we&lt;br /&gt;
first have to define the &#039;&#039;size&#039;&#039; of a term.&lt;br /&gt;
&lt;br /&gt;
The usual&lt;br /&gt;
definition is the following.&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
The size (denoted as &amp;lt;math&amp;gt;size_1(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
rules.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(\lambda x.t)=size_1(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1((t \ u))=size_1(t)+size_1(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the rest of the paper we will use another definition (denoted&lt;br /&gt;
as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt;) which is similar but  gives simpler computations.&lt;br /&gt;
We believe (but we have not yet checked the details) that, with&lt;br /&gt;
&amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt; we would have similar results. The&lt;br /&gt;
computation, with &amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt;,  of the upper and lower&lt;br /&gt;
bounds of the number of terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; will be done&lt;br /&gt;
in section ??&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
The size (denoted as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt; or, more simply &amp;lt;math&amp;gt;size(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
rules.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(\lambda x.t)=size_0(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0((t \ u))=size_0(t)+size_0(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These definitions of the size are, for the implementation point of&lt;br /&gt;
view, not realistic because, in case a term has a lot of distinct&lt;br /&gt;
variables, it is not realistic to use a single bit to code them.&lt;br /&gt;
The usual way to implement this coding is to replace the names of&lt;br /&gt;
variables by  their so called de Bruijn indices: a variable is&lt;br /&gt;
replaced by the number of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; that occur, on the&lt;br /&gt;
path from the variable to the root, between the variable and the&lt;br /&gt;
&amp;lt;math&amp;gt;lambda&amp;lt;/math&amp;gt; that binds it. Note that, in this case,&lt;br /&gt;
different occurrences of the same variable may be represented by&lt;br /&gt;
different indices.&lt;br /&gt;
&lt;br /&gt;
Choosing the way we code these de Bruijn indices gives different&lt;br /&gt;
other ways of defining the size of a term. This can be done in the&lt;br /&gt;
following ways&lt;br /&gt;
&lt;br /&gt;
- Use unary notation, i.e. the size of the index &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;&lt;br /&gt;
simply is &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; itself&lt;br /&gt;
&lt;br /&gt;
- Use optimal binary notation, i.e. the size of the index&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;log_2(n)&amp;lt;/math&amp;gt; i.e. the logarithm of&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; in base 2.&lt;br /&gt;
&lt;br /&gt;
- Use uniform binary notation, i.e. the size of an index is the&lt;br /&gt;
logarithm, in base 2, of the number of leaves of the term.&lt;br /&gt;
&lt;br /&gt;
Remark&lt;br /&gt;
&lt;br /&gt;
See section ?? for a discusion about these different size.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; be an integer. We denote by &amp;lt;math&amp;gt;\Lambda_n&amp;lt;/math&amp;gt; the set of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; terms of size n.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let A be a set of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; terms. &lt;br /&gt;
&lt;br /&gt;
1) We denote by &amp;lt;math&amp;gt;\#(A)&amp;lt;/math&amp;gt; the cardinality of A.&lt;br /&gt;
&lt;br /&gt;
2) We denote by &amp;lt;math&amp;gt;d(A)&amp;lt;/math&amp;gt; the limit, for n going to &amp;lt;math&amp;gt;\infty&amp;lt;/math&amp;gt;, &lt;br /&gt;
of &amp;lt;math&amp;gt;\frac{\#(A\cap \Lambda_n)}{\#(\Lambda_n)}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Remark&lt;br /&gt;
&lt;br /&gt;
Note that d is not exactly a measure since &amp;lt;math&amp;gt;d(A)&amp;lt;/math&amp;gt; is undefined if the previous limit does not exist&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let P be a property of terms. We will say that almost every term satisfies P &lt;br /&gt;
(this will be also stated as P holds a.e.) if&lt;br /&gt;
&amp;lt;math&amp;gt;d(\{t \ | \ P(t) holds\})=1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== generating functions ==&lt;br /&gt;
&lt;br /&gt;
this does not work (by now) because radius of convergence 0&lt;br /&gt;
&lt;br /&gt;
no known results for the number of terms of size n (denoted &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
== our results ==&lt;br /&gt;
&lt;br /&gt;
(the proof of result of section k needs the result of section (k-1))&lt;br /&gt;
&lt;br /&gt;
=== Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
For the lower bound, we will first count the number &amp;lt;math&amp;gt;LB(n,k)&amp;lt;/math&amp;gt; of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; starting with &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas and having no other lambda below. This means that the lower part of the term is a binary tree of size &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; with&lt;br /&gt;
&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; possibility for each leaf. Therefore we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) = C(n-k) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And therefore, for &amp;lt;math&amp;gt;n &amp;gt; k&amp;lt;/math&amp;gt;, using our lower bound for &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n + 1 \geq n - k + 1&amp;lt;/math&amp;gt;, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) \geq K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;K=\frac{36}{49\sqrt{\pi}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed, we define &amp;lt;math&amp;gt;f(\alpha) = \left(4n\alpha\right)^{n(1-\alpha) + 1}&amp;lt;/math&amp;gt; (so &amp;lt;math&amp;gt;LB(n,k) \geq \frac{K}{(n+1)^\frac{3}{2}} f\left(\frac{k}{n}\right)&amp;lt;/math&amp;gt;) and look for the maximum of this function. We have &amp;lt;math&amp;gt;f&#039;(\alpha) = f(\alpha) \left(-n\ln(4n\alpha) +\frac{n(1-\alpha) + 1}{\alpha}\right)&amp;lt;/math&amp;gt;. Thus, &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\frac{n+1}{n\alpha}e^{\frac{n+1}{n\alpha}}\geq 4e(n+1)&amp;lt;/math&amp;gt;. The Lambert function begin increasing this means that &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\alpha \leq \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;f(\alpha)&amp;lt;/math&amp;gt; reaches a maximum for &amp;lt;math&amp;gt;\alpha = \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This means that &amp;lt;math&amp;gt;(4k)^{n-k}&amp;lt;/math&amp;gt; reaches its maximum for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed when &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;&lt;br /&gt;
is near to &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; which is likely not to be an integer. However, there are at least &amp;lt;math&amp;gt;\left\lfloor \frac{n (\ln(\ln(4en)) - 1)}{\ln^2(4en)}\right\rfloor&amp;lt;/math&amp;gt; integer between &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\frac{n+1}{\ln(4e(n+1))}&amp;lt;/math&amp;gt;. Indeed, using our inequalities on Lambert W function, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}-\frac{n+1}{\ln(4e(n+1))} = \frac{(n+1) (\ln(4e(n+1)) - W(4e(n+1)))}{W(4e(n+1))\ln(4e(n+1))} \geq \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, we get the following lowerbound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \sum_{k=1}^{n} LB(n,k) \geq \sum_{k=\lceil\frac{n+1}{\ln(4e(n+1))}\rceil}^{\lfloor\frac{n+1}{W(4e(n+1))}\rfloor} K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}} \geq K \left\lfloor \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}\right\rfloor \frac{\left(\frac{4(n+1)}{\ln(4e(n+1))}\right)^{n-\frac{n+1}{\ln(4e(n+1))}+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To simplify, using the fact that &amp;lt;math&amp;gt;\lim_{n\to +\infty}\left(\frac{\ln(n)}{\ln(4en)}\right)^n = 0&amp;lt;/math&amp;gt; and taking &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; large enough, we have the following lowerbound:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \frac{\sqrt{n}}{\ln^3(n)}\left(\frac{4n}{\ln(n)}\right)^{n-\frac{n}{\ln(n)}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We now compute an upper bound &amp;lt;math&amp;gt;UB(n,k)&amp;lt;/math&amp;gt; for the number of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with exactly &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas (that is with &amp;lt;math&amp;gt;n - k + 1&amp;lt;/math&amp;gt; leaves using the Motzkin numbers and allowing any lambda to bind any variable (regardless of the real scope):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;UB(n,k) = M(n,n-k+1) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we sum this for all possible &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and get an upper bound of &amp;lt;math&amp;gt;k^{n-k+1}&amp;lt;/math&amp;gt; using Lambert function as for the lower bound, we get the following upper bound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \leq M(n) \left(\frac{n+1}{W(e(n+1))}\right)^{n-\frac{n+1}{W(e(n+1))} + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The ration between our upper bound and lower bound is equivalent to (NEEDS FURTHER CHECKING):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\left(\frac{1}{4(3-2\sqrt{2})}\right)^n\frac{\ln^3(n)}{n^2} \simeq 1.46^n\frac{\ln^3(n)}{n^2}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== upper and lower bounds for number of lambdas in a term of size n ===&lt;br /&gt;
&lt;br /&gt;
=== Jakub&#039;s trik : at least 1 lambda in head position ===&lt;br /&gt;
&lt;br /&gt;
=== at least &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; lambdas in head position and number of lambdas in one path ===&lt;br /&gt;
&lt;br /&gt;
Remark: (may be 4) can be done directly without 3))&lt;br /&gt;
&lt;br /&gt;
=== each of the  &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; head lambdas really bind &amp;quot;many&amp;quot;  occurrences of the variable ===&lt;br /&gt;
&lt;br /&gt;
=== every fixed closed term (including the identity !) does not appear in a random term (in fact we have much more than that) ===&lt;br /&gt;
&lt;br /&gt;
comment : so different situation in combinatory logic and lambda calculus ; the coding uses a big size so need to count variables in a different way&lt;br /&gt;
&lt;br /&gt;
== Experiments ==&lt;br /&gt;
&lt;br /&gt;
results of the experiments we have done&lt;br /&gt;
&lt;br /&gt;
some experiments that have to be done : e.g. density of terms having &amp;lt;math&amp;gt;\lambda x.y&amp;lt;/math&amp;gt; or big Omega pattern ...&lt;br /&gt;
&lt;br /&gt;
== to be done ==&lt;br /&gt;
&lt;br /&gt;
Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; with other size for variables especially one, binary with fixed size&lt;br /&gt;
&lt;br /&gt;
== Open questions and Future work ==&lt;br /&gt;
&lt;br /&gt;
.....&lt;/div&gt;</summary>
		<author><name>René David</name></author>
	</entry>
	<entry>
		<id>http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2660</id>
		<title>Lambda counting</title>
		<link rel="alternate" type="text/html" href="http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2660"/>
		<updated>2008-10-20T13:58:09Z</updated>

		<summary type="html">&lt;p&gt;René David : /* Generality on lambda calculus */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
The question is: among programs, what is the probability of having a fixed property.&lt;br /&gt;
&lt;br /&gt;
what kind of program : turing machines, cellular automata, combinatory logic, lambda calculus&lt;br /&gt;
&lt;br /&gt;
what kind of properties : structural (for functional programs), behaviour (SN, weakly normalizable, ...&lt;br /&gt;
&lt;br /&gt;
references to known results on : turing machines, cellular automata&lt;br /&gt;
&lt;br /&gt;
we concentrate on combinatory logic, lambda calculus&lt;br /&gt;
&lt;br /&gt;
== Lambert function, Catalan and Motzkin numbers ==&lt;br /&gt;
&lt;br /&gt;
=== Catalan numbers ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; : Catalan numbers &lt;br /&gt;
&lt;br /&gt;
Usual equivalent: &amp;lt;math&amp;gt;C(n) \sim \frac{4^n}{n^{3/2}\sqrt{\pi}}&amp;lt;/math&amp;gt; which is obtained using Strirling formula.&lt;br /&gt;
However, using stirling series: &amp;lt;math&amp;gt;&lt;br /&gt;
  n!=\sqrt{2\pi n}\left({n\over e}\right)^n&lt;br /&gt;
  \left(&lt;br /&gt;
   1&lt;br /&gt;
   +{1\over12n}&lt;br /&gt;
   +{1\over288n^2}&lt;br /&gt;
   -{139\over51840n^3}&lt;br /&gt;
   -{571\over2488320n^4}&lt;br /&gt;
   + \cdots&lt;br /&gt;
  \right)&lt;br /&gt;
 &amp;lt;/math&amp;gt;, we get that for &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; we have &amp;lt;math&amp;gt;\sqrt{2\pi n}\left({n\over e}\right)^n \leq n! \leq \frac{7}{6}\sqrt{2\pi n}\left({n\over e}\right)^n&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, using this and &amp;lt;math&amp;gt;\left(\frac{n}{n+1}\right)^{n} &amp;gt; e^{-1}&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C(n) = \frac{(2n)!}{(n+1)!n!} \geq \frac{36}{49\sqrt{\pi}} \frac{4^n}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; but also for &amp;lt;math&amp;gt;n=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Motzkin numbers===&lt;br /&gt;
&lt;br /&gt;
Let us define &amp;lt;math&amp;gt;M(n,k)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; leafs. We get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n,k) = \frac{(n+k-1)!}{(n-k+1)!(k-1)!k!}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, by summing we define &amp;lt;math&amp;gt;M(n)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and give an equivalent:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n) = \sum_{k=0}^n M(n,k) \sim \left(\frac{1}{3-2\sqrt{2}}\right)^n \frac{1}{n^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lambert W function===&lt;br /&gt;
&lt;br /&gt;
The Lambert function &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; is defined by the equation &amp;lt;math&amp;gt;x = W(x) e ^ {W(x)} &amp;lt;/math&amp;gt;&lt;br /&gt;
which has a unique solution in &amp;lt;math&amp;gt;\mathbb{R}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;x \geq e&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x)&amp;lt;/math&amp;gt; which implies that &lt;br /&gt;
&amp;lt;math&amp;gt;W(x) \sim \ln(x)&amp;lt;/math&amp;gt; near &amp;lt;math&amp;gt;+\infty&amp;lt;/math&amp;gt;. To prove this, it is enough to remark that&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;(\ln(x) - \ln(\ln(x))e^{\ln(x)-\ln(\ln(x))} = x \left(1 - \frac{\ln(\ln(x))}{\ln(x)}\right) \leq x \leq x \ln(x) = \ln(x) e^{\ln(x)} &amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is not precise enough for our purpose. Using one step of the Newton method from &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt;, we can find a better upper bound for &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; because &amp;lt;math&amp;gt;y \mapsto y e^y&amp;lt;/math&amp;gt; is increasing and convex. This gives:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, if we define &amp;lt;math&amp;gt;f(y) = y e^y&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;f&#039;(y)=(1+y)e^y&amp;lt;/math&amp;gt; and therefore, newton&#039;s method from &amp;lt;math&amp;gt;A = \ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt; gives a point at position:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;&lt;br /&gt;
A - \frac{f(A) - x}{f&#039;(A)} &lt;br /&gt;
  = A +  \frac{x \ln(\ln(x))}{\ln(x)} \frac{\ln(x)}{x(\ln(x) - \ln(\ln(x)) + 1)}&lt;br /&gt;
  = A +  \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1} &lt;br /&gt;
&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, we show that for &amp;lt;math&amp;gt;x\geq e&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + 1&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, for &amp;lt;math&amp;gt;x &amp;gt; 1&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;e^{\sqrt{ex}} \geq 1 + \sqrt{ex} + \frac{ex}{2} \geq x&amp;lt;/math&amp;gt;, which implies&lt;br /&gt;
&amp;lt;math&amp;gt;ex \geq \ln^2(x)&amp;lt;/math&amp;gt; and therefore &amp;lt;math&amp;gt;\ln(x) - \ln\ln(x) + 1 \geq \ln\ln(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==  combinatory logic ==&lt;br /&gt;
&lt;br /&gt;
results on  combinatory logic&lt;br /&gt;
&lt;br /&gt;
== Generality on lambda calculus ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition &lt;br /&gt;
&lt;br /&gt;
The set &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt; of lambda terms (or,&lt;br /&gt;
simply, terms) is defined by the following grammar&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;t, u  := Var \ \mid \ \lambda x.t \ \mid \ (t \ u)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To be able to define the notion of a &#039;&#039;random&#039;&#039; term we&lt;br /&gt;
have to define a distribution law on &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt;. There are many&lt;br /&gt;
possibilities for that. We choose here the simplest one. Note that this is the one for which, at least at present,  we are&lt;br /&gt;
able to prove some results. It is based on densities. For that we&lt;br /&gt;
first have to define the &#039;&#039;size&#039;&#039; of a term.&lt;br /&gt;
&lt;br /&gt;
The usual&lt;br /&gt;
definition is the following.&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
The size (denoted as &amp;lt;math&amp;gt;size_1(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
rules.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(\lambda x.t)=size_1(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1((t \ u))=size_1(t)+size_1(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the rest of the paper we will use another definition (denoted&lt;br /&gt;
as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt;) which is similar but  gives simpler computations.&lt;br /&gt;
We believe (but we have not yet checked the details) that, with&lt;br /&gt;
&amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt; we would have similar results. The&lt;br /&gt;
computation, with &amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt;,  of the upper and lower&lt;br /&gt;
bounds of the number of terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; will be done&lt;br /&gt;
in section ??&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
The size (denoted as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt; or, more simply &amp;lt;math&amp;gt;size(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
rules.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(\lambda x.t)=size_0(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0((t \ u))=size_0(t)+size_0(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These definitions of the size are, for the implementation point of&lt;br /&gt;
view, not realistic because, in case a term has a lot of distinct&lt;br /&gt;
variables, it is not realistic to use a single bit to code them.&lt;br /&gt;
The usual way to implement this coding is to replace the names of&lt;br /&gt;
variables by  their so called de Bruijn indices: a variable is&lt;br /&gt;
replaced by the number of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; that occur, on the&lt;br /&gt;
path from the variable to the root, between the variable and the&lt;br /&gt;
&amp;lt;math&amp;gt;lambda&amp;lt;/math&amp;gt; that binds it. Note that, in this case,&lt;br /&gt;
different occurrences of the same variable may be represented by&lt;br /&gt;
different indices.&lt;br /&gt;
&lt;br /&gt;
Choosing the way we code these de Bruijn indices gives different&lt;br /&gt;
other ways of defining the size of a term. This can be done in the&lt;br /&gt;
following ways&lt;br /&gt;
&lt;br /&gt;
- Use unary notation, i.e. the size of the index &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;&lt;br /&gt;
simply is &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; itself&lt;br /&gt;
&lt;br /&gt;
- Use optimal binary notation, i.e. the size of the index&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;log_2(n)&amp;lt;/math&amp;gt; i.e. the logarithm of&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; in base 2.&lt;br /&gt;
&lt;br /&gt;
- Use uniform binary notation, i.e. the size of an index is the&lt;br /&gt;
logarithm, in base 2, of the number of leaves of the term.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; be an integer. We denote by &amp;lt;math&amp;gt;\Lambda_n&amp;lt;/math&amp;gt; the set of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; terms of size n.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let A be a set of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; terms. &lt;br /&gt;
&lt;br /&gt;
1) We denote by &amp;lt;math&amp;gt;\#(A)&amp;lt;/math&amp;gt; the cardinality of A.&lt;br /&gt;
&lt;br /&gt;
2) We denote by &amp;lt;math&amp;gt;d(A)&amp;lt;/math&amp;gt; the limit, for n going to &amp;lt;math&amp;gt;\infty&amp;lt;/math&amp;gt;, &lt;br /&gt;
of &amp;lt;math&amp;gt;\frac{\#(A\cap \Lambda_n)}{\#(\Lambda_n)}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Remark&lt;br /&gt;
&lt;br /&gt;
Note that d is not exactly a measure since &amp;lt;math&amp;gt;d(A)&amp;lt;/math&amp;gt; is undefined is the previous limit does not exist&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
Let P be a property of terms. We will say that almost every term satisfies P &lt;br /&gt;
(this will be also stated as P holds a.e.) if&lt;br /&gt;
&lt;br /&gt;
== generating functions ==&lt;br /&gt;
&lt;br /&gt;
this does not work (by now) because radius of convergence 0&lt;br /&gt;
&lt;br /&gt;
no known results for the number of terms of size n (denoted &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
== our results ==&lt;br /&gt;
&lt;br /&gt;
(the proof of result of section k needs the result of section (k-1))&lt;br /&gt;
&lt;br /&gt;
=== Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
For the lower bound, we will first count the number &amp;lt;math&amp;gt;LB(n,k)&amp;lt;/math&amp;gt; of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; starting with &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas and having no other lambda below. This means that the lower part of the term is a binary tree of size &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; with&lt;br /&gt;
&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; possibility for each leaf. Therefore we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) = C(n-k) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And therefore, for &amp;lt;math&amp;gt;n &amp;gt; k&amp;lt;/math&amp;gt;, using our lower bound for &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n + 1 \geq n - k + 1&amp;lt;/math&amp;gt;, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) \geq K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;K=\frac{36}{49\sqrt{\pi}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed, we define &amp;lt;math&amp;gt;f(\alpha) = \left(4n\alpha\right)^{n(1-\alpha) + 1}&amp;lt;/math&amp;gt; (so &amp;lt;math&amp;gt;LB(n,k) \geq \frac{K}{(n+1)^\frac{3}{2}} f\left(\frac{k}{n}\right)&amp;lt;/math&amp;gt;) and look for the maximum of this function. We have &amp;lt;math&amp;gt;f&#039;(\alpha) = f(\alpha) \left(-n\ln(4n\alpha) +\frac{n(1-\alpha) + 1}{\alpha}\right)&amp;lt;/math&amp;gt;. Thus, &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\frac{n+1}{n\alpha}e^{\frac{n+1}{n\alpha}}\geq 4e(n+1)&amp;lt;/math&amp;gt;. The Lambert function begin increasing this means that &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\alpha \leq \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;f(\alpha)&amp;lt;/math&amp;gt; reaches a maximum for &amp;lt;math&amp;gt;\alpha = \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This means that &amp;lt;math&amp;gt;(4k)^{n-k}&amp;lt;/math&amp;gt; reaches its maximum for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed when &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;&lt;br /&gt;
is near to &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; which is likely not to be an integer. However, there are at least &amp;lt;math&amp;gt;\left\lfloor \frac{n (\ln(\ln(4en)) - 1)}{\ln^2(4en)}\right\rfloor&amp;lt;/math&amp;gt; integer between &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\frac{n+1}{\ln(4e(n+1))}&amp;lt;/math&amp;gt;. Indeed, using our inequalities on Lambert W function, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}-\frac{n+1}{\ln(4e(n+1))} = \frac{(n+1) (\ln(4e(n+1)) - W(4e(n+1)))}{W(4e(n+1))\ln(4e(n+1))} \geq \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, we get the following lowerbound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \sum_{k=1}^{n} LB(n,k) \geq \sum_{k=\lceil\frac{n+1}{\ln(4e(n+1))}\rceil}^{\lfloor\frac{n+1}{W(4e(n+1))}\rfloor} K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}} \geq K \left\lfloor \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}\right\rfloor \frac{\left(\frac{4(n+1)}{\ln(4e(n+1))}\right)^{n-\frac{n+1}{\ln(4e(n+1))}+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To simplify, using the fact that &amp;lt;math&amp;gt;\lim_{n\to +\infty}\left(\frac{\ln(n)}{\ln(4en)}\right)^n = 0&amp;lt;/math&amp;gt; and taking &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; large enough, we have the following lowerbound:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \frac{\sqrt{n}}{\ln^3(n)}\left(\frac{4n}{\ln(n)}\right)^{n-\frac{n}{\ln(n)}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We now compute an upper bound &amp;lt;math&amp;gt;UB(n,k)&amp;lt;/math&amp;gt; for the number of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with exactly &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas (that is with &amp;lt;math&amp;gt;n - k + 1&amp;lt;/math&amp;gt; leaves using the Motzkin numbers and allowing any lambda to bind any variable (regardless of the real scope):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;UB(n,k) = M(n,n-k+1) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we sum this for all possible &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and get an upper bound of &amp;lt;math&amp;gt;k^{n-k+1}&amp;lt;/math&amp;gt; using Lambert function as for the lower bound, we get the following upper bound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \leq M(n) \left(\frac{n+1}{W(e(n+1))}\right)^{n-\frac{n+1}{W(e(n+1))} + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The ration between our upper bound and lower bound is equivalent to (NEEDS FURTHER CHECKING):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\left(\frac{1}{4(3-2\sqrt{2})}\right)^n\frac{\ln^3(n)}{n^2} \simeq 1.46^n\frac{\ln^3(n)}{n^2}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== upper and lower bounds for number of lambdas in a term of size n ===&lt;br /&gt;
&lt;br /&gt;
=== Jakub&#039;s trik : at least 1 lambda in head position ===&lt;br /&gt;
&lt;br /&gt;
=== at least &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; lambdas in head position and number of lambdas in one path ===&lt;br /&gt;
&lt;br /&gt;
Remark: (may be 4) can be done directly without 3))&lt;br /&gt;
&lt;br /&gt;
=== each of the  &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; head lambdas really bind &amp;quot;many&amp;quot;  occurrences of the variable ===&lt;br /&gt;
&lt;br /&gt;
=== every fixed closed term (including the identity !) does not appear in a random term (in fact we have much more than that) ===&lt;br /&gt;
&lt;br /&gt;
comment : so different situation in combinatory logic and lambda calculus ; the coding uses a big size so need to count variables in a different way&lt;br /&gt;
&lt;br /&gt;
== Experiments ==&lt;br /&gt;
&lt;br /&gt;
results of the experiments we have done&lt;br /&gt;
&lt;br /&gt;
some experiments that have to be done : e.g. density of terms having &amp;lt;math&amp;gt;\lambda x.y&amp;lt;/math&amp;gt; or big Omega pattern ...&lt;br /&gt;
&lt;br /&gt;
== to be done ==&lt;br /&gt;
&lt;br /&gt;
Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; with other size for variables especially one, binary with fixed size&lt;br /&gt;
&lt;br /&gt;
== Open questions and Future work ==&lt;br /&gt;
&lt;br /&gt;
.....&lt;/div&gt;</summary>
		<author><name>René David</name></author>
	</entry>
	<entry>
		<id>http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2659</id>
		<title>Lambda counting</title>
		<link rel="alternate" type="text/html" href="http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2659"/>
		<updated>2008-10-20T13:42:16Z</updated>

		<summary type="html">&lt;p&gt;René David : /* Generality on lambda calculus */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
The question is: among programs, what is the probability of having a fixed property.&lt;br /&gt;
&lt;br /&gt;
what kind of program : turing machines, cellular automata, combinatory logic, lambda calculus&lt;br /&gt;
&lt;br /&gt;
what kind of properties : structural (for functional programs), behaviour (SN, weakly normalizable, ...&lt;br /&gt;
&lt;br /&gt;
references to known results on : turing machines, cellular automata&lt;br /&gt;
&lt;br /&gt;
we concentrate on combinatory logic, lambda calculus&lt;br /&gt;
&lt;br /&gt;
== Lambert function, Catalan and Motzkin numbers ==&lt;br /&gt;
&lt;br /&gt;
=== Catalan numbers ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; : Catalan numbers &lt;br /&gt;
&lt;br /&gt;
Usual equivalent: &amp;lt;math&amp;gt;C(n) \sim \frac{4^n}{n^{3/2}\sqrt{\pi}}&amp;lt;/math&amp;gt; which is obtained using Strirling formula.&lt;br /&gt;
However, using stirling series: &amp;lt;math&amp;gt;&lt;br /&gt;
  n!=\sqrt{2\pi n}\left({n\over e}\right)^n&lt;br /&gt;
  \left(&lt;br /&gt;
   1&lt;br /&gt;
   +{1\over12n}&lt;br /&gt;
   +{1\over288n^2}&lt;br /&gt;
   -{139\over51840n^3}&lt;br /&gt;
   -{571\over2488320n^4}&lt;br /&gt;
   + \cdots&lt;br /&gt;
  \right)&lt;br /&gt;
 &amp;lt;/math&amp;gt;, we get that for &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; we have &amp;lt;math&amp;gt;\sqrt{2\pi n}\left({n\over e}\right)^n \leq n! \leq \frac{7}{6}\sqrt{2\pi n}\left({n\over e}\right)^n&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, using this and &amp;lt;math&amp;gt;\left(\frac{n}{n+1}\right)^{n} &amp;gt; e^{-1}&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C(n) = \frac{(2n)!}{(n+1)!n!} \geq \frac{36}{49\sqrt{\pi}} \frac{4^n}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; but also for &amp;lt;math&amp;gt;n=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Motzkin numbers===&lt;br /&gt;
&lt;br /&gt;
Let us define &amp;lt;math&amp;gt;M(n,k)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; leafs. We get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n,k) = \frac{(n+k-1)!}{(n-k+1)!(k-1)!k!}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, by summing we define &amp;lt;math&amp;gt;M(n)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and give an equivalent:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n) = \sum_{k=0}^n M(n,k) \sim \left(\frac{1}{3-2\sqrt{2}}\right)^n \frac{1}{n^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lambert W function===&lt;br /&gt;
&lt;br /&gt;
The Lambert function &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; is defined by the equation &amp;lt;math&amp;gt;x = W(x) e ^ {W(x)} &amp;lt;/math&amp;gt;&lt;br /&gt;
which has a unique solution in &amp;lt;math&amp;gt;\mathbb{R}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;x \geq e&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x)&amp;lt;/math&amp;gt; which implies that &lt;br /&gt;
&amp;lt;math&amp;gt;W(x) \sim \ln(x)&amp;lt;/math&amp;gt; near &amp;lt;math&amp;gt;+\infty&amp;lt;/math&amp;gt;. To prove this, it is enough to remark that&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;(\ln(x) - \ln(\ln(x))e^{\ln(x)-\ln(\ln(x))} = x \left(1 - \frac{\ln(\ln(x))}{\ln(x)}\right) \leq x \leq x \ln(x) = \ln(x) e^{\ln(x)} &amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is not precise enough for our purpose. Using one step of the Newton method from &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt;, we can find a better upper bound for &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; because &amp;lt;math&amp;gt;y \mapsto y e^y&amp;lt;/math&amp;gt; is increasing and convex. This gives:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, if we define &amp;lt;math&amp;gt;f(y) = y e^y&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;f&#039;(y)=(1+y)e^y&amp;lt;/math&amp;gt; and therefore, newton&#039;s method from &amp;lt;math&amp;gt;A = \ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt; gives a point at position:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;&lt;br /&gt;
A - \frac{f(A) - x}{f&#039;(A)} &lt;br /&gt;
  = A +  \frac{x \ln(\ln(x))}{\ln(x)} \frac{\ln(x)}{x(\ln(x) - \ln(\ln(x)) + 1)}&lt;br /&gt;
  = A +  \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1} &lt;br /&gt;
&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, we show that for &amp;lt;math&amp;gt;x\geq e&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + 1&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, for &amp;lt;math&amp;gt;x &amp;gt; 1&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;e^{\sqrt{ex}} \geq 1 + \sqrt{ex} + \frac{ex}{2} \geq x&amp;lt;/math&amp;gt;, which implies&lt;br /&gt;
&amp;lt;math&amp;gt;ex \geq \ln^2(x)&amp;lt;/math&amp;gt; and therefore &amp;lt;math&amp;gt;\ln(x) - \ln\ln(x) + 1 \geq \ln\ln(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==  combinatory logic ==&lt;br /&gt;
&lt;br /&gt;
results on  combinatory logic&lt;br /&gt;
&lt;br /&gt;
== Generality on lambda calculus ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition The set &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt; of lambda terms (or,&lt;br /&gt;
simply, terms) is defined by the following grammar&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;t, u  := Var \ \mid \ \lambda x.t \ \mid \ (t \ u)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To be able to define the notion of a &#039;&#039;random&#039;&#039; term we&lt;br /&gt;
have to define a distribution law on &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt;. There are many&lt;br /&gt;
possibilities for that. We choose here the simplest one. Note that this is the one for which, at least at present,  we are&lt;br /&gt;
able to prove some results. It is based on densities. For that we&lt;br /&gt;
first have to define the &#039;&#039;size&#039;&#039; of a term.&lt;br /&gt;
&lt;br /&gt;
The usual&lt;br /&gt;
definition is the following.&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
The size (denoted as &amp;lt;math&amp;gt;size_1(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
rules.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(\lambda x.t)=size_1(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1((t \ u))=size_1(t)+size_1(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the rest of the paper we will use another definition (denoted&lt;br /&gt;
as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt;) which is similar but  gives simpler computations.&lt;br /&gt;
We believe (but we have not yet checked the details) that, with&lt;br /&gt;
&amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt; we would have similar results. The&lt;br /&gt;
computation, with &amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt;,  of the upper and lower&lt;br /&gt;
bounds of the number of terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; will be done&lt;br /&gt;
in section ??&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
The size (denoted as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt; or, more simply &amp;lt;math&amp;gt;size(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
rules.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(\lambda x.t)=size_0(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0((t \ u))=size_0(t)+size_0(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These definitions of the size are, for the implementation point of&lt;br /&gt;
view, not realistic because, in case a term has a lot of distinct&lt;br /&gt;
variables, it is not realistic to use a single bit to code them.&lt;br /&gt;
The usual way to implement this coding is to replace the names of&lt;br /&gt;
variables by  their so called de Bruijn indices: a variable is&lt;br /&gt;
replaced by the number of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; that occur, on the&lt;br /&gt;
path from the variable to the root, between the variable and the&lt;br /&gt;
&amp;lt;math&amp;gt;lambda&amp;lt;/math&amp;gt; that binds it. Note that, in this case,&lt;br /&gt;
different occurrences of the same variable may be represented by&lt;br /&gt;
different indices.&lt;br /&gt;
&lt;br /&gt;
Choosing the way we code these de Bruijn indices gives different&lt;br /&gt;
other ways of defining the size of a term. This can be done in the&lt;br /&gt;
following ways&lt;br /&gt;
&lt;br /&gt;
- Use unary notation, i.e. the size of the index &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;&lt;br /&gt;
simply is &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; itself&lt;br /&gt;
&lt;br /&gt;
- Use optimal binary notation, i.e. the size of the index&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;log_2(n)&amp;lt;/math&amp;gt; i.e. the logarithm of&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; in base 2.&lt;br /&gt;
&lt;br /&gt;
- Use uniform binary notation, i.e. the size of an index is the&lt;br /&gt;
logarithm, in base 2, of the number of leaves of the term.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
Let&lt;br /&gt;
&lt;br /&gt;
== generating functions ==&lt;br /&gt;
&lt;br /&gt;
this does not work (by now) because radius of convergence 0&lt;br /&gt;
&lt;br /&gt;
no known results for the number of terms of size n (denoted &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
== our results ==&lt;br /&gt;
&lt;br /&gt;
(the proof of result of section k needs the result of section (k-1))&lt;br /&gt;
&lt;br /&gt;
=== Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
For the lower bound, we will first count the number &amp;lt;math&amp;gt;LB(n,k)&amp;lt;/math&amp;gt; of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; starting with &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas and having no other lambda below. This means that the lower part of the term is a binary tree of size &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; with&lt;br /&gt;
&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; possibility for each leaf. Therefore we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) = C(n-k) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And therefore, for &amp;lt;math&amp;gt;n &amp;gt; k&amp;lt;/math&amp;gt;, using our lower bound for &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n + 1 \geq n - k + 1&amp;lt;/math&amp;gt;, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) \geq K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;K=\frac{36}{49\sqrt{\pi}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed, we define &amp;lt;math&amp;gt;f(\alpha) = \left(4n\alpha\right)^{n(1-\alpha) + 1}&amp;lt;/math&amp;gt; (so &amp;lt;math&amp;gt;LB(n,k) \geq \frac{K}{(n+1)^\frac{3}{2}} f\left(\frac{k}{n}\right)&amp;lt;/math&amp;gt;) and look for the maximum of this function. We have &amp;lt;math&amp;gt;f&#039;(\alpha) = f(\alpha) \left(-n\ln(4n\alpha) +\frac{n(1-\alpha) + 1}{\alpha}\right)&amp;lt;/math&amp;gt;. Thus, &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\frac{n+1}{n\alpha}e^{\frac{n+1}{n\alpha}}\geq 4e(n+1)&amp;lt;/math&amp;gt;. The Lambert function begin increasing this means that &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\alpha \leq \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;f(\alpha)&amp;lt;/math&amp;gt; reaches a maximum for &amp;lt;math&amp;gt;\alpha = \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This means that &amp;lt;math&amp;gt;(4k)^{n-k}&amp;lt;/math&amp;gt; reaches its maximum for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed when &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;&lt;br /&gt;
is near to &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; which is likely not to be an integer. However, there are at least &amp;lt;math&amp;gt;\left\lfloor \frac{n (\ln(\ln(4en)) - 1)}{\ln^2(4en)}\right\rfloor&amp;lt;/math&amp;gt; integer between &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\frac{n+1}{\ln(4e(n+1))}&amp;lt;/math&amp;gt;. Indeed, using our inequalities on Lambert W function, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}-\frac{n+1}{\ln(4e(n+1))} = \frac{(n+1) (\ln(4e(n+1)) - W(4e(n+1)))}{W(4e(n+1))\ln(4e(n+1))} \geq \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, we get the following lowerbound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \sum_{k=1}^{n} LB(n,k) \geq \sum_{k=\lceil\frac{n+1}{\ln(4e(n+1))}\rceil}^{\lfloor\frac{n+1}{W(4e(n+1))}\rfloor} K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}} \geq K \left\lfloor \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}\right\rfloor \frac{\left(\frac{4(n+1)}{\ln(4e(n+1))}\right)^{n-\frac{n+1}{\ln(4e(n+1))}+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To simplify, using the fact that &amp;lt;math&amp;gt;\lim_{n\to +\infty}\left(\frac{\ln(n)}{\ln(4en)}\right)^n = 0&amp;lt;/math&amp;gt; and taking &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; large enough, we have the following lowerbound:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \frac{\sqrt{n}}{\ln^3(n)}\left(\frac{4n}{\ln(n)}\right)^{n-\frac{n}{\ln(n)}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We now compute an upper bound &amp;lt;math&amp;gt;UB(n,k)&amp;lt;/math&amp;gt; for the number of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with exactly &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas (that is with &amp;lt;math&amp;gt;n - k + 1&amp;lt;/math&amp;gt; leaves using the Motzkin numbers and allowing any lambda to bind any variable (regardless of the real scope):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;UB(n,k) = M(n,n-k+1) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we sum this for all possible &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and get an upper bound of &amp;lt;math&amp;gt;k^{n-k+1}&amp;lt;/math&amp;gt; using Lambert function as for the lower bound, we get the following upper bound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \leq M(n) \left(\frac{n+1}{W(e(n+1))}\right)^{n-\frac{n+1}{W(e(n+1))} + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The ration between our upper bound and lower bound is equivalent to (NEEDS FURTHER CHECKING):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\left(\frac{1}{4(3-2\sqrt{2})}\right)^n\frac{\ln^3(n)}{n^2} \simeq 1.46^n\frac{\ln^3(n)}{n^2}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== upper and lower bounds for number of lambdas in a term of size n ===&lt;br /&gt;
&lt;br /&gt;
=== Jakub&#039;s trik : at least 1 lambda in head position ===&lt;br /&gt;
&lt;br /&gt;
=== at least &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; lambdas in head position and number of lambdas in one path ===&lt;br /&gt;
&lt;br /&gt;
Remark: (may be 4) can be done directly without 3))&lt;br /&gt;
&lt;br /&gt;
=== each of the  &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; head lambdas really bind &amp;quot;many&amp;quot;  occurrences of the variable ===&lt;br /&gt;
&lt;br /&gt;
=== every fixed closed term (including the identity !) does not appear in a random term (in fact we have much more than that) ===&lt;br /&gt;
&lt;br /&gt;
comment : so different situation in combinatory logic and lambda calculus ; the coding uses a big size so need to count variables in a different way&lt;br /&gt;
&lt;br /&gt;
== Experiments ==&lt;br /&gt;
&lt;br /&gt;
results of the experiments we have done&lt;br /&gt;
&lt;br /&gt;
some experiments that have to be done : e.g. density of terms having &amp;lt;math&amp;gt;\lambda x.y&amp;lt;/math&amp;gt; or big Omega pattern ...&lt;br /&gt;
&lt;br /&gt;
== to be done ==&lt;br /&gt;
&lt;br /&gt;
Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; with other size for variables especially one, binary with fixed size&lt;br /&gt;
&lt;br /&gt;
== Open questions and Future work ==&lt;br /&gt;
&lt;br /&gt;
.....&lt;/div&gt;</summary>
		<author><name>René David</name></author>
	</entry>
	<entry>
		<id>http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2658</id>
		<title>Lambda counting</title>
		<link rel="alternate" type="text/html" href="http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2658"/>
		<updated>2008-10-20T13:36:52Z</updated>

		<summary type="html">&lt;p&gt;René David : /* Generality on lambda calculus */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
The question is: among programs, what is the probability of having a fixed property.&lt;br /&gt;
&lt;br /&gt;
what kind of program : turing machines, cellular automata, combinatory logic, lambda calculus&lt;br /&gt;
&lt;br /&gt;
what kind of properties : structural (for functional programs), behaviour (SN, weakly normalizable, ...&lt;br /&gt;
&lt;br /&gt;
references to known results on : turing machines, cellular automata&lt;br /&gt;
&lt;br /&gt;
we concentrate on combinatory logic, lambda calculus&lt;br /&gt;
&lt;br /&gt;
== Lambert function, Catalan and Motzkin numbers ==&lt;br /&gt;
&lt;br /&gt;
=== Catalan numbers ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; : Catalan numbers &lt;br /&gt;
&lt;br /&gt;
Usual equivalent: &amp;lt;math&amp;gt;C(n) \sim \frac{4^n}{n^{3/2}\sqrt{\pi}}&amp;lt;/math&amp;gt; which is obtained using Strirling formula.&lt;br /&gt;
However, using stirling series: &amp;lt;math&amp;gt;&lt;br /&gt;
  n!=\sqrt{2\pi n}\left({n\over e}\right)^n&lt;br /&gt;
  \left(&lt;br /&gt;
   1&lt;br /&gt;
   +{1\over12n}&lt;br /&gt;
   +{1\over288n^2}&lt;br /&gt;
   -{139\over51840n^3}&lt;br /&gt;
   -{571\over2488320n^4}&lt;br /&gt;
   + \cdots&lt;br /&gt;
  \right)&lt;br /&gt;
 &amp;lt;/math&amp;gt;, we get that for &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; we have &amp;lt;math&amp;gt;\sqrt{2\pi n}\left({n\over e}\right)^n \leq n! \leq \frac{7}{6}\sqrt{2\pi n}\left({n\over e}\right)^n&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, using this and &amp;lt;math&amp;gt;\left(\frac{n}{n+1}\right)^{n} &amp;gt; e^{-1}&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C(n) = \frac{(2n)!}{(n+1)!n!} \geq \frac{36}{49\sqrt{\pi}} \frac{4^n}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; but also for &amp;lt;math&amp;gt;n=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Motzkin numbers===&lt;br /&gt;
&lt;br /&gt;
Let us define &amp;lt;math&amp;gt;M(n,k)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; leafs. We get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n,k) = \frac{(n+k-1)!}{(n-k+1)!(k-1)!k!}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, by summing we define &amp;lt;math&amp;gt;M(n)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and give an equivalent:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n) = \sum_{k=0}^n M(n,k) \sim \left(\frac{1}{3-2\sqrt{2}}\right)^n \frac{1}{n^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lambert W function===&lt;br /&gt;
&lt;br /&gt;
The Lambert function &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; is defined by the equation &amp;lt;math&amp;gt;x = W(x) e ^ {W(x)} &amp;lt;/math&amp;gt;&lt;br /&gt;
which has a unique solution in &amp;lt;math&amp;gt;\mathbb{R}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;x \geq e&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x)&amp;lt;/math&amp;gt; which implies that &lt;br /&gt;
&amp;lt;math&amp;gt;W(x) \sim \ln(x)&amp;lt;/math&amp;gt; near &amp;lt;math&amp;gt;+\infty&amp;lt;/math&amp;gt;. To prove this, it is enough to remark that&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;(\ln(x) - \ln(\ln(x))e^{\ln(x)-\ln(\ln(x))} = x \left(1 - \frac{\ln(\ln(x))}{\ln(x)}\right) \leq x \leq x \ln(x) = \ln(x) e^{\ln(x)} &amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is not precise enough for our purpose. Using one step of the Newton method from &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt;, we can find a better upper bound for &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; because &amp;lt;math&amp;gt;y \mapsto y e^y&amp;lt;/math&amp;gt; is increasing and convex. This gives:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, if we define &amp;lt;math&amp;gt;f(y) = y e^y&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;f&#039;(y)=(1+y)e^y&amp;lt;/math&amp;gt; and therefore, newton&#039;s method from &amp;lt;math&amp;gt;A = \ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt; gives a point at position:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;&lt;br /&gt;
A - \frac{f(A) - x}{f&#039;(A)} &lt;br /&gt;
  = A +  \frac{x \ln(\ln(x))}{\ln(x)} \frac{\ln(x)}{x(\ln(x) - \ln(\ln(x)) + 1)}&lt;br /&gt;
  = A +  \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1} &lt;br /&gt;
&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, we show that for &amp;lt;math&amp;gt;x\geq e&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + 1&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, for &amp;lt;math&amp;gt;x &amp;gt; 1&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;e^{\sqrt{ex}} \geq 1 + \sqrt{ex} + \frac{ex}{2} \geq x&amp;lt;/math&amp;gt;, which implies&lt;br /&gt;
&amp;lt;math&amp;gt;ex \geq \ln^2(x)&amp;lt;/math&amp;gt; and therefore &amp;lt;math&amp;gt;\ln(x) - \ln\ln(x) + 1 \geq \ln\ln(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==  combinatory logic ==&lt;br /&gt;
&lt;br /&gt;
results on  combinatory logic&lt;br /&gt;
&lt;br /&gt;
== Generality on lambda calculus ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition The set &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt; of lambda terms (or,&lt;br /&gt;
simply, terms) is defined by the following grammar&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;t, u  := Var \ \mid \ \lambda x.t \ \mid \ (t \ u)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To be able to define the notion of a &#039;&#039;random&#039;&#039; term we&lt;br /&gt;
have to define a distribution law on &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt;. There are many&lt;br /&gt;
possibilities for that. We choose here the simplest one. Note that this is the one for which, at least at present,  we are&lt;br /&gt;
able to prove some results. It is based on densities. For that we&lt;br /&gt;
first have to define the &#039;&#039;size&#039;&#039; of a term.&lt;br /&gt;
&lt;br /&gt;
The usual&lt;br /&gt;
definition is the following.&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
The size (denoted as &amp;lt;math&amp;gt;size_1(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
rules.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(\lambda x.t)=size_1(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1((t \ u))=size_1(t)+size_1(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the rest of the paper we will use another definition (denoted&lt;br /&gt;
as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt;) which is similar but  gives simpler computations.&lt;br /&gt;
We believe (but we have not yet checked the details) that, with&lt;br /&gt;
&amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt; we would have similar results. The&lt;br /&gt;
computation, with &amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt;,  of the upper and lower&lt;br /&gt;
bounds of the number of terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; will be done&lt;br /&gt;
in section ??&lt;br /&gt;
&lt;br /&gt;
 definition&lt;br /&gt;
 The size (denoted as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
 rules.&lt;br /&gt;
&lt;br /&gt;
 - &amp;lt;math&amp;gt;size_0(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(\lambda x.t)=size_0(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0((t \ u))=size_0(t)+size_0(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These definitions of the size are, for the implementation point of&lt;br /&gt;
view, not realistic because, in case a term has a lot of distinct&lt;br /&gt;
variables, it is not realistic to use a single bit to code them.&lt;br /&gt;
The usual way to implement this coding is to replace the names of&lt;br /&gt;
variables by  their so called de Bruijn indices: a variable is&lt;br /&gt;
replaced by the number of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; that occur, on the&lt;br /&gt;
path from the variable to the root, between the variable and the&lt;br /&gt;
&amp;lt;math&amp;gt;lambda&amp;lt;/math&amp;gt; that binds it. Note that, in this case,&lt;br /&gt;
different occurrences of the same variable may be represented by&lt;br /&gt;
different indices.&lt;br /&gt;
&lt;br /&gt;
Choosing the way we code these de Bruijn indices gives different&lt;br /&gt;
other ways of defining the size of a term. This can be done in the&lt;br /&gt;
following ways&lt;br /&gt;
&lt;br /&gt;
- Use unary notation, i.e. the size of the index &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;&lt;br /&gt;
simply is &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; itself&lt;br /&gt;
&lt;br /&gt;
- Use optimal binary notation, i.e. the size of the index&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;log_2(n)&amp;lt;/math&amp;gt; i.e. the logarithm of&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; in base 2.&lt;br /&gt;
&lt;br /&gt;
- Use uniform binary notation, i.e. the size of an index is the&lt;br /&gt;
logarithm, in base 2, of the number of leaves of the term.&lt;br /&gt;
&lt;br /&gt;
== generating functions ==&lt;br /&gt;
&lt;br /&gt;
this does not work (by now) because radius of convergence 0&lt;br /&gt;
&lt;br /&gt;
no known results for the number of terms of size n (denoted &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
== our results ==&lt;br /&gt;
&lt;br /&gt;
(the proof of result of section k needs the result of section (k-1))&lt;br /&gt;
&lt;br /&gt;
=== Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
For the lower bound, we will first count the number &amp;lt;math&amp;gt;LB(n,k)&amp;lt;/math&amp;gt; of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; starting with &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas and having no other lambda below. This means that the lower part of the term is a binary tree of size &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; with&lt;br /&gt;
&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; possibility for each leaf. Therefore we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) = C(n-k) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And therefore, for &amp;lt;math&amp;gt;n &amp;gt; k&amp;lt;/math&amp;gt;, using our lower bound for &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n + 1 \geq n - k + 1&amp;lt;/math&amp;gt;, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) \geq K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;K=\frac{36}{49\sqrt{\pi}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed, we define &amp;lt;math&amp;gt;f(\alpha) = \left(4n\alpha\right)^{n(1-\alpha) + 1}&amp;lt;/math&amp;gt; (so &amp;lt;math&amp;gt;LB(n,k) \geq \frac{K}{(n+1)^\frac{3}{2}} f\left(\frac{k}{n}\right)&amp;lt;/math&amp;gt;) and look for the maximum of this function. We have &amp;lt;math&amp;gt;f&#039;(\alpha) = f(\alpha) \left(-n\ln(4n\alpha) +\frac{n(1-\alpha) + 1}{\alpha}\right)&amp;lt;/math&amp;gt;. Thus, &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\frac{n+1}{n\alpha}e^{\frac{n+1}{n\alpha}}\geq 4e(n+1)&amp;lt;/math&amp;gt;. The Lambert function begin increasing this means that &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\alpha \leq \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;f(\alpha)&amp;lt;/math&amp;gt; reaches a maximum for &amp;lt;math&amp;gt;\alpha = \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This means that &amp;lt;math&amp;gt;(4k)^{n-k}&amp;lt;/math&amp;gt; reaches its maximum for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed when &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;&lt;br /&gt;
is near to &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; which is likely not to be an integer. However, there are at least &amp;lt;math&amp;gt;\left\lfloor \frac{n (\ln(\ln(4en)) - 1)}{\ln^2(4en)}\right\rfloor&amp;lt;/math&amp;gt; integer between &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\frac{n+1}{\ln(4e(n+1))}&amp;lt;/math&amp;gt;. Indeed, using our inequalities on Lambert W function, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}-\frac{n+1}{\ln(4e(n+1))} = \frac{(n+1) (\ln(4e(n+1)) - W(4e(n+1)))}{W(4e(n+1))\ln(4e(n+1))} \geq \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, we get the following lowerbound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \sum_{k=1}^{n} LB(n,k) \geq \sum_{k=\lceil\frac{n+1}{\ln(4e(n+1))}\rceil}^{\lfloor\frac{n+1}{W(4e(n+1))}\rfloor} K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}} \geq K \left\lfloor \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}\right\rfloor \frac{\left(\frac{4(n+1)}{\ln(4e(n+1))}\right)^{n-\frac{n+1}{\ln(4e(n+1))}+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To simplify, using the fact that &amp;lt;math&amp;gt;\lim_{n\to +\infty}\left(\frac{\ln(n)}{\ln(4en)}\right)^n = 0&amp;lt;/math&amp;gt; and taking &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; large enough, we have the following lowerbound:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \frac{\sqrt{n}}{\ln^3(n)}\left(\frac{4n}{\ln(n)}\right)^{n-\frac{n}{\ln(n)}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We now compute an upper bound &amp;lt;math&amp;gt;UB(n,k)&amp;lt;/math&amp;gt; for the number of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with exactly &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas (that is with &amp;lt;math&amp;gt;n - k + 1&amp;lt;/math&amp;gt; leaves using the Motzkin numbers and allowing any lambda to bind any variable (regardless of the real scope):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;UB(n,k) = M(n,n-k+1) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we sum this for all possible &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and get an upper bound of &amp;lt;math&amp;gt;k^{n-k+1}&amp;lt;/math&amp;gt; using Lambert function as for the lower bound, we get the following upper bound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \leq M(n) \left(\frac{n+1}{W(e(n+1))}\right)^{n-\frac{n+1}{W(e(n+1))} + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The ration between our upper bound and lower bound is equivalent to (NEEDS FURTHER CHECKING):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\left(\frac{1}{4(3-2\sqrt{2})}\right)^n\frac{\ln^3(n)}{n^2} \simeq 1.46^n\frac{\ln^3(n)}{n^2}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== upper and lower bounds for number of lambdas in a term of size n ===&lt;br /&gt;
&lt;br /&gt;
=== Jakub&#039;s trik : at least 1 lambda in head position ===&lt;br /&gt;
&lt;br /&gt;
=== at least &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; lambdas in head position and number of lambdas in one path ===&lt;br /&gt;
&lt;br /&gt;
Remark: (may be 4) can be done directly without 3))&lt;br /&gt;
&lt;br /&gt;
=== each of the  &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; head lambdas really bind &amp;quot;many&amp;quot;  occurrences of the variable ===&lt;br /&gt;
&lt;br /&gt;
=== every fixed closed term (including the identity !) does not appear in a random term (in fact we have much more than that) ===&lt;br /&gt;
&lt;br /&gt;
comment : so different situation in combinatory logic and lambda calculus ; the coding uses a big size so need to count variables in a different way&lt;br /&gt;
&lt;br /&gt;
== Experiments ==&lt;br /&gt;
&lt;br /&gt;
results of the experiments we have done&lt;br /&gt;
&lt;br /&gt;
some experiments that have to be done : e.g. density of terms having &amp;lt;math&amp;gt;\lambda x.y&amp;lt;/math&amp;gt; or big Omega pattern ...&lt;br /&gt;
&lt;br /&gt;
== to be done ==&lt;br /&gt;
&lt;br /&gt;
Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; with other size for variables especially one, binary with fixed size&lt;br /&gt;
&lt;br /&gt;
== Open questions and Future work ==&lt;br /&gt;
&lt;br /&gt;
.....&lt;/div&gt;</summary>
		<author><name>René David</name></author>
	</entry>
	<entry>
		<id>http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2657</id>
		<title>Lambda counting</title>
		<link rel="alternate" type="text/html" href="http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2657"/>
		<updated>2008-10-20T13:31:47Z</updated>

		<summary type="html">&lt;p&gt;René David : &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
The question is: among programs, what is the probability of having a fixed property.&lt;br /&gt;
&lt;br /&gt;
what kind of program : turing machines, cellular automata, combinatory logic, lambda calculus&lt;br /&gt;
&lt;br /&gt;
what kind of properties : structural (for functional programs), behaviour (SN, weakly normalizable, ...&lt;br /&gt;
&lt;br /&gt;
references to known results on : turing machines, cellular automata&lt;br /&gt;
&lt;br /&gt;
we concentrate on combinatory logic, lambda calculus&lt;br /&gt;
&lt;br /&gt;
== Lambert function, Catalan and Motzkin numbers ==&lt;br /&gt;
&lt;br /&gt;
=== Catalan numbers ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; : Catalan numbers &lt;br /&gt;
&lt;br /&gt;
Usual equivalent: &amp;lt;math&amp;gt;C(n) \sim \frac{4^n}{n^{3/2}\sqrt{\pi}}&amp;lt;/math&amp;gt; which is obtained using Strirling formula.&lt;br /&gt;
However, using stirling series: &amp;lt;math&amp;gt;&lt;br /&gt;
  n!=\sqrt{2\pi n}\left({n\over e}\right)^n&lt;br /&gt;
  \left(&lt;br /&gt;
   1&lt;br /&gt;
   +{1\over12n}&lt;br /&gt;
   +{1\over288n^2}&lt;br /&gt;
   -{139\over51840n^3}&lt;br /&gt;
   -{571\over2488320n^4}&lt;br /&gt;
   + \cdots&lt;br /&gt;
  \right)&lt;br /&gt;
 &amp;lt;/math&amp;gt;, we get that for &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; we have &amp;lt;math&amp;gt;\sqrt{2\pi n}\left({n\over e}\right)^n \leq n! \leq \frac{7}{6}\sqrt{2\pi n}\left({n\over e}\right)^n&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, using this and &amp;lt;math&amp;gt;\left(\frac{n}{n+1}\right)^{n} &amp;gt; e^{-1}&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C(n) = \frac{(2n)!}{(n+1)!n!} \geq \frac{36}{49\sqrt{\pi}} \frac{4^n}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; but also for &amp;lt;math&amp;gt;n=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Motzkin numbers===&lt;br /&gt;
&lt;br /&gt;
Let us define &amp;lt;math&amp;gt;M(n,k)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; leafs. We get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n,k) = \frac{(n+k-1)!}{(n-k+1)!(k-1)!k!}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, by summing we define &amp;lt;math&amp;gt;M(n)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and give an equivalent:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n) = \sum_{k=0}^n M(n,k) \sim \left(\frac{1}{3-2\sqrt{2}}\right)^n \frac{1}{n^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lambert W function===&lt;br /&gt;
&lt;br /&gt;
The Lambert function &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; is defined by the equation &amp;lt;math&amp;gt;x = W(x) e ^ {W(x)} &amp;lt;/math&amp;gt;&lt;br /&gt;
which has a unique solution in &amp;lt;math&amp;gt;\mathbb{R}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;x \geq e&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x)&amp;lt;/math&amp;gt; which implies that &lt;br /&gt;
&amp;lt;math&amp;gt;W(x) \sim \ln(x)&amp;lt;/math&amp;gt; near &amp;lt;math&amp;gt;+\infty&amp;lt;/math&amp;gt;. To prove this, it is enough to remark that&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;(\ln(x) - \ln(\ln(x))e^{\ln(x)-\ln(\ln(x))} = x \left(1 - \frac{\ln(\ln(x))}{\ln(x)}\right) \leq x \leq x \ln(x) = \ln(x) e^{\ln(x)} &amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is not precise enough for our purpose. Using one step of the Newton method from &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt;, we can find a better upper bound for &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; because &amp;lt;math&amp;gt;y \mapsto y e^y&amp;lt;/math&amp;gt; is increasing and convex. This gives:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, if we define &amp;lt;math&amp;gt;f(y) = y e^y&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;f&#039;(y)=(1+y)e^y&amp;lt;/math&amp;gt; and therefore, newton&#039;s method from &amp;lt;math&amp;gt;A = \ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt; gives a point at position:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;&lt;br /&gt;
A - \frac{f(A) - x}{f&#039;(A)} &lt;br /&gt;
  = A +  \frac{x \ln(\ln(x))}{\ln(x)} \frac{\ln(x)}{x(\ln(x) - \ln(\ln(x)) + 1)}&lt;br /&gt;
  = A +  \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1} &lt;br /&gt;
&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, we show that for &amp;lt;math&amp;gt;x\geq e&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + 1&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, for &amp;lt;math&amp;gt;x &amp;gt; 1&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;e^{\sqrt{ex}} \geq 1 + \sqrt{ex} + \frac{ex}{2} \geq x&amp;lt;/math&amp;gt;, which implies&lt;br /&gt;
&amp;lt;math&amp;gt;ex \geq \ln^2(x)&amp;lt;/math&amp;gt; and therefore &amp;lt;math&amp;gt;\ln(x) - \ln\ln(x) + 1 \geq \ln\ln(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==  combinatory logic ==&lt;br /&gt;
&lt;br /&gt;
results on  combinatory logic&lt;br /&gt;
&lt;br /&gt;
== Generality on lambda calculus ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition The set &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt; of lambda terms (or,&lt;br /&gt;
simply, terms) is defined by the following grammar&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;t, u  := Var \ \mid \ \lambda x.t \ \mid \ (t \ u)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To be able to define the notion of a {\it random} term we&lt;br /&gt;
have to define a distribution law on &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt;. There are many&lt;br /&gt;
possibilities for that. We choose here the simplest one. Note that this is the one for which, at least at present,  we are&lt;br /&gt;
able to prove some results. It is based on densities. For that we&lt;br /&gt;
first have to define the {\it size} of a term.&lt;br /&gt;
&lt;br /&gt;
The usual&lt;br /&gt;
definition is the following.&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
The size (denoted as &amp;lt;math&amp;gt;size_1(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
rules.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(\lambda x.t)=size_1(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1((t \ u))=size_1(t)+size_1(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the rest of the paper we will use another definition (denoted&lt;br /&gt;
as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt;)&lt;br /&gt;
  which is similar but  gives simpler computations.&lt;br /&gt;
We believe (but we have not yet checked the details) that, with&lt;br /&gt;
&amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt; we would have similar results. The&lt;br /&gt;
computation, with &amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt;,  of the upper and lower&lt;br /&gt;
bounds of the number of terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; will be done&lt;br /&gt;
in section ??&lt;br /&gt;
&lt;br /&gt;
 definition&lt;br /&gt;
 The size (denoted as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
 rules.&lt;br /&gt;
&lt;br /&gt;
 - &amp;lt;math&amp;gt;size_0(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(\lambda x.t)=size_0(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0((t \ u))=size_0(t)+size_0(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These definitions of the size are, for the implementation point of&lt;br /&gt;
view, not realistic because, in case a term has a lot of distinct&lt;br /&gt;
variables, it is not realistic to use a single bit to code them.&lt;br /&gt;
The usual way to implement this coding is to replace the names of&lt;br /&gt;
variables by  their so called de Bruijn indices: a variable is&lt;br /&gt;
replaced by the number of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; that occur, on the&lt;br /&gt;
path from the variable to the root, between the variable and the&lt;br /&gt;
&amp;lt;math&amp;gt;lambda&amp;lt;/math&amp;gt; that binds it. Note that, in this case,&lt;br /&gt;
different occurrences of the same variable may be represented by&lt;br /&gt;
different indices.&lt;br /&gt;
&lt;br /&gt;
Choosing the way we code these de Bruijn indices gives different&lt;br /&gt;
other ways of defining the size of a term. This can be done in the&lt;br /&gt;
following ways&lt;br /&gt;
&lt;br /&gt;
- Use unary notation, i.e. the size of the index &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;&lt;br /&gt;
simply is &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; itself&lt;br /&gt;
- Use optimal binary notation, i.e. the size of the index&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;log_2(n)&amp;lt;/math&amp;gt; i.e. the logarithm of&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; in base 2.&lt;br /&gt;
- Use uniform binary notation, i.e. the size of an index is the&lt;br /&gt;
logarithm, in base 2, of the number of leaves of the term.&lt;br /&gt;
&lt;br /&gt;
== generating functions ==&lt;br /&gt;
&lt;br /&gt;
this does not work (by now) because radius of convergence 0&lt;br /&gt;
&lt;br /&gt;
no known results for the number of terms of size n (denoted &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
== our results ==&lt;br /&gt;
&lt;br /&gt;
(the proof of result of section k needs the result of section (k-1))&lt;br /&gt;
&lt;br /&gt;
=== Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
For the lower bound, we will first count the number &amp;lt;math&amp;gt;LB(n,k)&amp;lt;/math&amp;gt; of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; starting with &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas and having no other lambda below. This means that the lower part of the term is a binary tree of size &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; with&lt;br /&gt;
&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; possibility for each leaf. Therefore we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) = C(n-k) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And therefore, for &amp;lt;math&amp;gt;n &amp;gt; k&amp;lt;/math&amp;gt;, using our lower bound for &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n + 1 \geq n - k + 1&amp;lt;/math&amp;gt;, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) \geq K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;K=\frac{36}{49\sqrt{\pi}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed, we define &amp;lt;math&amp;gt;f(\alpha) = \left(4n\alpha\right)^{n(1-\alpha) + 1}&amp;lt;/math&amp;gt; (so &amp;lt;math&amp;gt;LB(n,k) \geq \frac{K}{(n+1)^\frac{3}{2}} f\left(\frac{k}{n}\right)&amp;lt;/math&amp;gt;) and look for the maximum of this function. We have &amp;lt;math&amp;gt;f&#039;(\alpha) = f(\alpha) \left(-n\ln(4n\alpha) +\frac{n(1-\alpha) + 1}{\alpha}\right)&amp;lt;/math&amp;gt;. Thus, &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\frac{n+1}{n\alpha}e^{\frac{n+1}{n\alpha}}\geq 4e(n+1)&amp;lt;/math&amp;gt;. The Lambert function begin increasing this means that &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\alpha \leq \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;f(\alpha)&amp;lt;/math&amp;gt; reaches a maximum for &amp;lt;math&amp;gt;\alpha = \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This means that &amp;lt;math&amp;gt;(4k)^{n-k}&amp;lt;/math&amp;gt; reaches its maximum for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed when &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;&lt;br /&gt;
is near to &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; which is likely not to be an integer. However, there are at least &amp;lt;math&amp;gt;\left\lfloor \frac{n (\ln(\ln(4en)) - 1)}{\ln^2(4en)}\right\rfloor&amp;lt;/math&amp;gt; integer between &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\frac{n+1}{\ln(4e(n+1))}&amp;lt;/math&amp;gt;. Indeed, using our inequalities on Lambert W function, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}-\frac{n+1}{\ln(4e(n+1))} = \frac{(n+1) (\ln(4e(n+1)) - W(4e(n+1)))}{W(4e(n+1))\ln(4e(n+1))} \geq \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, we get the following lowerbound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \sum_{k=1}^{n} LB(n,k) \geq \sum_{k=\lceil\frac{n+1}{\ln(4e(n+1))}\rceil}^{\lfloor\frac{n+1}{W(4e(n+1))}\rfloor} K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}} \geq K \left\lfloor \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}\right\rfloor \frac{\left(\frac{4(n+1)}{\ln(4e(n+1))}\right)^{n-\frac{n+1}{\ln(4e(n+1))}+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To simplify, using the fact that &amp;lt;math&amp;gt;\lim_{n\to +\infty}\left(\frac{\ln(n)}{\ln(4en)}\right)^n = 0&amp;lt;/math&amp;gt; and taking &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; large enough, we have the following lowerbound:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \frac{\sqrt{n}}{\ln^3(n)}\left(\frac{4n}{\ln(n)}\right)^{n-\frac{n}{\ln(n)}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We now compute an upper bound &amp;lt;math&amp;gt;UB(n,k)&amp;lt;/math&amp;gt; for the number of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with exactly &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas (that is with &amp;lt;math&amp;gt;n - k + 1&amp;lt;/math&amp;gt; leaves using the Motzkin numbers and allowing any lambda to bind any variable (regardless of the real scope):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;UB(n,k) = M(n,n-k+1) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we sum this for all possible &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and get an upper bound of &amp;lt;math&amp;gt;k^{n-k+1}&amp;lt;/math&amp;gt; using Lambert function as for the lower bound, we get the following upper bound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \leq M(n) \left(\frac{n+1}{W(e(n+1))}\right)^{n-\frac{n+1}{W(e(n+1))} + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The ration between our upper bound and lower bound is equivalent to (NEEDS FURTHER CHECKING):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\left(\frac{1}{4(3-2\sqrt{2})}\right)^n\frac{\ln^3(n)}{n^2} \simeq 1.46^n\frac{\ln^3(n)}{n^2}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== upper and lower bounds for number of lambdas in a term of size n ===&lt;br /&gt;
&lt;br /&gt;
=== Jakub&#039;s trik : at least 1 lambda in head position ===&lt;br /&gt;
&lt;br /&gt;
=== at least &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; lambdas in head position and number of lambdas in one path ===&lt;br /&gt;
&lt;br /&gt;
Remark: (may be 4) can be done directly without 3))&lt;br /&gt;
&lt;br /&gt;
=== each of the  &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; head lambdas really bind &amp;quot;many&amp;quot;  occurrences of the variable ===&lt;br /&gt;
&lt;br /&gt;
=== every fixed closed term (including the identity !) does not appear in a random term (in fact we have much more than that) ===&lt;br /&gt;
&lt;br /&gt;
comment : so different situation in combinatory logic and lambda calculus ; the coding uses a big size so need to count variables in a different way&lt;br /&gt;
&lt;br /&gt;
== Experiments ==&lt;br /&gt;
&lt;br /&gt;
results of the experiments we have done&lt;br /&gt;
&lt;br /&gt;
some experiments that have to be done : e.g. density of terms having &amp;lt;math&amp;gt;\lambda x.y&amp;lt;/math&amp;gt; or big Omega pattern ...&lt;br /&gt;
&lt;br /&gt;
== to be done ==&lt;br /&gt;
&lt;br /&gt;
Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; with other size for variables especially one, binary with fixed size&lt;br /&gt;
&lt;br /&gt;
== Open questions and Future work ==&lt;br /&gt;
&lt;br /&gt;
.....&lt;/div&gt;</summary>
		<author><name>René David</name></author>
	</entry>
	<entry>
		<id>http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2656</id>
		<title>Lambda counting</title>
		<link rel="alternate" type="text/html" href="http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2656"/>
		<updated>2008-10-20T13:25:52Z</updated>

		<summary type="html">&lt;p&gt;René David : /* Generality on lambda calculus */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
The question is: among programs, what is the probability of having a fixed property.&lt;br /&gt;
&lt;br /&gt;
what kind of program : turing machines, cellular automata, combinatory logic, lambda calculus&lt;br /&gt;
&lt;br /&gt;
what kind of properties : structural (for functional programs), behaviour (SN, weakly normalizable, ...&lt;br /&gt;
&lt;br /&gt;
references to known results on : turing machines, cellular automata&lt;br /&gt;
&lt;br /&gt;
we concentrate on combinatory logic, lambda calculus&lt;br /&gt;
&lt;br /&gt;
== Lambert function, Catalan and Motzkin numbers ==&lt;br /&gt;
&lt;br /&gt;
=== Catalan numbers ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; : Catalan numbers &lt;br /&gt;
&lt;br /&gt;
Usual equivalent: &amp;lt;math&amp;gt;C(n) \sim \frac{4^n}{n^{3/2}\sqrt{\pi}}&amp;lt;/math&amp;gt; which is obtained using Strirling formula.&lt;br /&gt;
However, using stirling series: &amp;lt;math&amp;gt;&lt;br /&gt;
  n!=\sqrt{2\pi n}\left({n\over e}\right)^n&lt;br /&gt;
  \left(&lt;br /&gt;
   1&lt;br /&gt;
   +{1\over12n}&lt;br /&gt;
   +{1\over288n^2}&lt;br /&gt;
   -{139\over51840n^3}&lt;br /&gt;
   -{571\over2488320n^4}&lt;br /&gt;
   + \cdots&lt;br /&gt;
  \right)&lt;br /&gt;
 &amp;lt;/math&amp;gt;, we get that for &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; we have &amp;lt;math&amp;gt;\sqrt{2\pi n}\left({n\over e}\right)^n \leq n! \leq \frac{7}{6}\sqrt{2\pi n}\left({n\over e}\right)^n&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, using this and &amp;lt;math&amp;gt;\left(\frac{n}{n+1}\right)^{n} &amp;gt; e^{-1}&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C(n) = \frac{(2n)!}{(n+1)!n!} \geq \frac{36}{49\sqrt{\pi}} \frac{4^n}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; but also for &amp;lt;math&amp;gt;n=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Motzkin numbers===&lt;br /&gt;
&lt;br /&gt;
Let us define &amp;lt;math&amp;gt;M(n,k)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; leafs. We get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n,k) = \frac{(n+k-1)!}{(n-k+1)!(k-1)!k!}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, by summing we define &amp;lt;math&amp;gt;M(n)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and give an equivalent:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n) = \sum_{k=0}^n M(n,k) \sim \left(\frac{1}{3-2\sqrt{2}}\right)^n \frac{1}{n^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lambert W function===&lt;br /&gt;
&lt;br /&gt;
The Lambert function &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; is defined by the equation &amp;lt;math&amp;gt;x = W(x) e ^ {W(x)} &amp;lt;/math&amp;gt;&lt;br /&gt;
which has a unique solution in &amp;lt;math&amp;gt;\mathbb{R}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;x \geq e&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x)&amp;lt;/math&amp;gt; which implies that &lt;br /&gt;
&amp;lt;math&amp;gt;W(x) \sim \ln(x)&amp;lt;/math&amp;gt; near &amp;lt;math&amp;gt;+\infty&amp;lt;/math&amp;gt;. To prove this, it is enough to remark that&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;(\ln(x) - \ln(\ln(x))e^{\ln(x)-\ln(\ln(x))} = x \left(1 - \frac{\ln(\ln(x))}{\ln(x)}\right) \leq x \leq x \ln(x) = \ln(x) e^{\ln(x)} &amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is not precise enough for our purpose. Using one step of the Newton method from &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt;, we can find a better upper bound for &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; because &amp;lt;math&amp;gt;y \mapsto y e^y&amp;lt;/math&amp;gt; is increasing and convex. This gives:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, if we define &amp;lt;math&amp;gt;f(y) = y e^y&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;f&#039;(y)=(1+y)e^y&amp;lt;/math&amp;gt; and therefore, newton&#039;s method from &amp;lt;math&amp;gt;A = \ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt; gives a point at position:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;&lt;br /&gt;
A - \frac{f(A) - x}{f&#039;(A)} &lt;br /&gt;
  = A +  \frac{x \ln(\ln(x))}{\ln(x)} \frac{\ln(x)}{x(\ln(x) - \ln(\ln(x)) + 1)}&lt;br /&gt;
  = A +  \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1} &lt;br /&gt;
&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, we show that for &amp;lt;math&amp;gt;x\geq e&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + 1&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, for &amp;lt;math&amp;gt;x &amp;gt; 1&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;e^{\sqrt{ex}} \geq 1 + \sqrt{ex} + \frac{ex}{2} \geq x&amp;lt;/math&amp;gt;, which implies&lt;br /&gt;
&amp;lt;math&amp;gt;ex \geq \ln^2(x)&amp;lt;/math&amp;gt; and therefore &amp;lt;math&amp;gt;\ln(x) - \ln\ln(x) + 1 \geq \ln\ln(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==  combinatory logic ==&lt;br /&gt;
&lt;br /&gt;
results on  combinatory logic&lt;br /&gt;
&lt;br /&gt;
== Generality on lambda calculus ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition The set &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; of lambda terms (or,&lt;br /&gt;
simply, terms) is defined by the following grammar&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;t, u  := Var \ \mid \ \lambda x.t \ \mid \ (t \ u)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To be able to define the notion of a {\it random} term we&lt;br /&gt;
have to define a distribution law on &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt;. There are many&lt;br /&gt;
possibilities for that. We choose here the simplest one. Note that this is the one for which, at least at present,  we are&lt;br /&gt;
able to prove some results. It is based on densities. For that we&lt;br /&gt;
first have to define the {\it size} of a term.&lt;br /&gt;
&lt;br /&gt;
The usual&lt;br /&gt;
definition is the following.&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
The size (denoted as &amp;lt;math&amp;gt;size_1(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
rules.&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(\lambda x.t)=size_1(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1((t \ u))=size_1(t)+size_1(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the rest of the paper we will use another definition (denoted&lt;br /&gt;
as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt;)&lt;br /&gt;
  which is similar but  gives simpler computations.&lt;br /&gt;
We believe (but we have not yet checked the details) that, with&lt;br /&gt;
&amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt; we would have similar results. The&lt;br /&gt;
computation, with &amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt;,  of the upper and lower&lt;br /&gt;
bounds of the number of terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; will be done&lt;br /&gt;
in section ??&lt;br /&gt;
&lt;br /&gt;
 definition&lt;br /&gt;
 The size (denoted as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
 rules.&lt;br /&gt;
 - &amp;lt;math&amp;gt;size_0(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(\lambda x.t)=size_0(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0((t \ u))=size_0(t)+size_0(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These definitions of the size are, for the implementation point of&lt;br /&gt;
view, not realistic because, in case a term has a lot of distinct&lt;br /&gt;
variables, it is not realistic to use a single bit to code them.&lt;br /&gt;
The usual way to implement this coding is to replace the names of&lt;br /&gt;
variables by  their so called de Bruijn indices: a variable is&lt;br /&gt;
replaced by the number of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; that occur, on the&lt;br /&gt;
path from the variable to the root, between the variable and the&lt;br /&gt;
&amp;lt;math&amp;gt;lambda&amp;lt;/math&amp;gt; that binds it. Note that, in this case,&lt;br /&gt;
different occurrences of the same variable may be represented by&lt;br /&gt;
different indices.&lt;br /&gt;
&lt;br /&gt;
Choosing the way we code these de Bruijn indices gives different&lt;br /&gt;
other ways of defining the size of a term. This can be done in the&lt;br /&gt;
following ways&lt;br /&gt;
&lt;br /&gt;
- Use unary notation, i.e. the size of the index &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;&lt;br /&gt;
simply is &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; itself&lt;br /&gt;
- Use optimal binary notation, i.e. the size of the index&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;log_2(n)&amp;lt;/math&amp;gt; i.e. the logarithm of&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; in base 2.&lt;br /&gt;
- Use uniform binary notation, i.e. the size of an index is the&lt;br /&gt;
logarithm, in base 2, of the number of leaves of the term.&lt;br /&gt;
&lt;br /&gt;
== generating functions ==&lt;br /&gt;
&lt;br /&gt;
this does not work (by now) because radius of convergence 0&lt;br /&gt;
&lt;br /&gt;
no known results for the number of terms of size n (denoted &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
== our results ==&lt;br /&gt;
&lt;br /&gt;
(the proof of result of section k needs the result of section (k-1))&lt;br /&gt;
&lt;br /&gt;
=== Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
For the lower bound, we will first count the number &amp;lt;math&amp;gt;LB(n,k)&amp;lt;/math&amp;gt; of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; starting with &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas and having no other lambda below. This means that the lower part of the term is a binary tree of size &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; with&lt;br /&gt;
&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; possibility for each leaf. Therefore we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) = C(n-k) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And therefore, for &amp;lt;math&amp;gt;n &amp;gt; k&amp;lt;/math&amp;gt;, using our lower bound for &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n + 1 \geq n - k + 1&amp;lt;/math&amp;gt;, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) \geq K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;K=\frac{36}{49\sqrt{\pi}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed, we define &amp;lt;math&amp;gt;f(\alpha) = \left(4n\alpha\right)^{n(1-\alpha) + 1}&amp;lt;/math&amp;gt; (so &amp;lt;math&amp;gt;LB(n,k) \geq \frac{K}{(n+1)^\frac{3}{2}} f\left(\frac{k}{n}\right)&amp;lt;/math&amp;gt;) and look for the maximum of this function. We have &amp;lt;math&amp;gt;f&#039;(\alpha) = f(\alpha) \left(-n\ln(4n\alpha) +\frac{n(1-\alpha) + 1}{\alpha}\right)&amp;lt;/math&amp;gt;. Thus, &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\frac{n+1}{n\alpha}e^{\frac{n+1}{n\alpha}}\geq 4e(n+1)&amp;lt;/math&amp;gt;. The Lambert function begin increasing this means that &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\alpha \leq \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;f(\alpha)&amp;lt;/math&amp;gt; reaches a maximum for &amp;lt;math&amp;gt;\alpha = \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This means that &amp;lt;math&amp;gt;(4k)^{n-k}&amp;lt;/math&amp;gt; reaches its maximum for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed when &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;&lt;br /&gt;
is near to &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; which is likely not to be an integer. However, there are at least &amp;lt;math&amp;gt;\left\lfloor \frac{n (\ln(\ln(4en)) - 1)}{\ln^2(4en)}\right\rfloor&amp;lt;/math&amp;gt; integer between &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\frac{n+1}{\ln(4e(n+1))}&amp;lt;/math&amp;gt;. Indeed, using our inequalities on Lambert W function, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}-\frac{n+1}{\ln(4e(n+1))} = \frac{(n+1) (\ln(4e(n+1)) - W(4e(n+1)))}{W(4e(n+1))\ln(4e(n+1))} \geq \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, we get the following lowerbound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \sum_{k=1}^{n} LB(n,k) \geq \sum_{k=\lceil\frac{n+1}{\ln(4e(n+1))}\rceil}^{\lfloor\frac{n+1}{W(4e(n+1))}\rfloor} K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}} \geq K \left\lfloor \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}\right\rfloor \frac{\left(\frac{4(n+1)}{\ln(4e(n+1))}\right)^{n-\frac{n+1}{\ln(4e(n+1))}+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To simplify, using the fact that &amp;lt;math&amp;gt;\lim_{n\to +\infty}\left(\frac{\ln(n)}{\ln(4en)}\right)^n = 0&amp;lt;/math&amp;gt; and taking &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; large enough, we have the following lowerbound:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \frac{\sqrt{n}}{\ln^3(n)}\left(\frac{4n}{\ln(n)}\right)^{n-\frac{n}{\ln(n)}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We now compute an upper bound &amp;lt;math&amp;gt;UB(n,k)&amp;lt;/math&amp;gt; for the number of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with exactly &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas (that is with &amp;lt;math&amp;gt;n - k + 1&amp;lt;/math&amp;gt; leaves using the Motzkin numbers and allowing any lambda to bind any variable (regardless of the real scope):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;UB(n,k) = M(n,n-k+1) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we sum this for all possible &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and get an upper bound of &amp;lt;math&amp;gt;k^{n-k+1}&amp;lt;/math&amp;gt; using Lambert function as for the lower bound, we get the following upper bound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \leq M(n) \left(\frac{n+1}{W(e(n+1))}\right)^{n-\frac{n+1}{W(e(n+1))} + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The ration between our upper bound and lower bound is equivalent to (NEEDS FURTHER CHECKING):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\left(\frac{1}{4(3-2\sqrt{2})}\right)^n\frac{\ln^3(n)}{n^2} \simeq 1.46^n\frac{\ln^3(n)}{n^2}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== upper and lower bounds for number of lambdas in a term of size n ===&lt;br /&gt;
&lt;br /&gt;
=== Jakub&#039;s trik : at least 1 lambda in head position ===&lt;br /&gt;
&lt;br /&gt;
=== at least &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; lambdas in head position and number of lambdas in one path ===&lt;br /&gt;
&lt;br /&gt;
Remark: (may be 4) can be done directly without 3))&lt;br /&gt;
&lt;br /&gt;
=== each of the  &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; head lambdas really bind &amp;quot;many&amp;quot;  occurrences of the variable ===&lt;br /&gt;
&lt;br /&gt;
=== every fixed closed term (including the identity !) does not appear in a random term (in fact we have much more than that) ===&lt;br /&gt;
&lt;br /&gt;
comment : so different situation in combinatory logic and lambda calculus ; the coding uses a big size so need to count variables in a different way&lt;br /&gt;
&lt;br /&gt;
== Experiments ==&lt;br /&gt;
&lt;br /&gt;
results of the experiments we have done&lt;br /&gt;
&lt;br /&gt;
some experiments that have to be done : e.g. density of terms having &amp;lt;math&amp;gt;\lambda x.y&amp;lt;/math&amp;gt; or big Omega pattern ...&lt;br /&gt;
&lt;br /&gt;
== to be done ==&lt;br /&gt;
&lt;br /&gt;
Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; with other size for variables especially one, binary with fixed size&lt;br /&gt;
&lt;br /&gt;
== Open questions and Future work ==&lt;br /&gt;
&lt;br /&gt;
.....&lt;/div&gt;</summary>
		<author><name>René David</name></author>
	</entry>
	<entry>
		<id>http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2653</id>
		<title>Lambda counting</title>
		<link rel="alternate" type="text/html" href="http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2653"/>
		<updated>2008-10-20T13:11:45Z</updated>

		<summary type="html">&lt;p&gt;René David : /* Generality on lambda calculus */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
The question is: among programs, what is the probability of having a fixed property.&lt;br /&gt;
&lt;br /&gt;
what kind of program : turing machines, cellular automata, combinatory logic, lambda calculus&lt;br /&gt;
&lt;br /&gt;
what kind of properties : structural (for functional programs), behaviour (SN, weakly normalizable, ...&lt;br /&gt;
&lt;br /&gt;
references to known results on : turing machines, cellular automata&lt;br /&gt;
&lt;br /&gt;
we concentrate on combinatory logic, lambda calculus&lt;br /&gt;
&lt;br /&gt;
== Lambert function, Catalan and Motzkin numbers ==&lt;br /&gt;
&lt;br /&gt;
=== Catalan numbers ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; : Catalan numbers &lt;br /&gt;
&lt;br /&gt;
Usual equivalent: &amp;lt;math&amp;gt;C(n) \sim \frac{4^n}{n^{3/2}\sqrt{\pi}}&amp;lt;/math&amp;gt; which is obtained using Strirling formula.&lt;br /&gt;
However, using stirling series: &amp;lt;math&amp;gt;&lt;br /&gt;
  n!=\sqrt{2\pi n}\left({n\over e}\right)^n&lt;br /&gt;
  \left(&lt;br /&gt;
   1&lt;br /&gt;
   +{1\over12n}&lt;br /&gt;
   +{1\over288n^2}&lt;br /&gt;
   -{139\over51840n^3}&lt;br /&gt;
   -{571\over2488320n^4}&lt;br /&gt;
   + \cdots&lt;br /&gt;
  \right)&lt;br /&gt;
 &amp;lt;/math&amp;gt;, we get that for &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; we have &amp;lt;math&amp;gt;\sqrt{2\pi n}\left({n\over e}\right)^n \leq n! \leq \frac{7}{6}\sqrt{2\pi n}\left({n\over e}\right)^n&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, using this and &amp;lt;math&amp;gt;\left(\frac{n}{n+1}\right)^{n} &amp;gt; e^{-1}&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C(n) = \frac{(2n)!}{(n+1)!n!} \geq \frac{36}{49\sqrt{\pi}} \frac{4^n}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; but also for &amp;lt;math&amp;gt;n=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Motzkin numbers===&lt;br /&gt;
&lt;br /&gt;
Let us define &amp;lt;math&amp;gt;M(n,k)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; leafs. We get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n,k) = \frac{(n+k-1)!}{(n-k+1)!(k-1)!k!}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, by summing we define &amp;lt;math&amp;gt;M(n)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and give an equivalent:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n) = \sum_{k=0}^n M(n,k) \sim \left(\frac{1}{3-2\sqrt{2}}\right)^n \frac{1}{n^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lambert W function===&lt;br /&gt;
&lt;br /&gt;
The Lambert function &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; is defined by the equation &amp;lt;math&amp;gt;x = W(x) e ^ {W(x)} &amp;lt;/math&amp;gt;&lt;br /&gt;
which has a unique solution in &amp;lt;math&amp;gt;\mathbb{R}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;x \geq e&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x)&amp;lt;/math&amp;gt; which implies that &lt;br /&gt;
&amp;lt;math&amp;gt;W(x) \sim \ln(x)&amp;lt;/math&amp;gt; near &amp;lt;math&amp;gt;+\infty&amp;lt;/math&amp;gt;. To prove this, it is enough to remark that&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;(\ln(x) - \ln(\ln(x))e^{\ln(x)-\ln(\ln(x))} = x \left(1 - \frac{\ln(\ln(x))}{\ln(x)}\right) \leq x \leq x \ln(x) = \ln(x) e^{\ln(x)} &amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is not precise enough for our purpose. Using one step of the Newton method from &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt;, we can find a better upper bound for &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; because &amp;lt;math&amp;gt;y \mapsto y e^y&amp;lt;/math&amp;gt; is increasing and convex. This gives:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, if we define &amp;lt;math&amp;gt;f(y) = y e^y&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;f&#039;(y)=(1+y)e^y&amp;lt;/math&amp;gt; and therefore, newton&#039;s method from &amp;lt;math&amp;gt;A = \ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt; gives a point at position:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;&lt;br /&gt;
A - \frac{f(A) - x}{f&#039;(A)} &lt;br /&gt;
  = A +  \frac{x \ln(\ln(x))}{\ln(x)} \frac{\ln(x)}{x(\ln(x) - \ln(\ln(x)) + 1)}&lt;br /&gt;
  = A +  \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1} &lt;br /&gt;
&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, we show that for &amp;lt;math&amp;gt;x\geq e&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + 1&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, for &amp;lt;math&amp;gt;x &amp;gt; 1&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;e^{\sqrt{ex}} \geq 1 + \sqrt{ex} + \frac{ex}{2} \geq x&amp;lt;/math&amp;gt;, which implies&lt;br /&gt;
&amp;lt;math&amp;gt;ex \geq \ln^2(x)&amp;lt;/math&amp;gt; and therefore &amp;lt;math&amp;gt;\ln(x) - \ln\ln(x) + 1 \geq \ln\ln(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==  combinatory logic ==&lt;br /&gt;
&lt;br /&gt;
results on  combinatory logic&lt;br /&gt;
&lt;br /&gt;
== Generality on lambda calculus ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition The set &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; of lambda terms (or,&lt;br /&gt;
simply, terms) is defined by the following grammar&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;t, u  := Var \ \mid \ \lambda x.t \ \mid \ (t \ u)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To be able to define the notion of a {\it random} term we&lt;br /&gt;
 have to define a distribution law on &amp;lt;math&amp;gt;\Lambda&amp;lt;/math&amp;gt;. There are many&lt;br /&gt;
 possibilities for that. We choose here the simplest one. Note that this is the one for which, at least at present,  we are&lt;br /&gt;
 able to prove some results. It is based on densities. For that we&lt;br /&gt;
 first have to define the {\it size} of a term.&lt;br /&gt;
&lt;br /&gt;
 The usual&lt;br /&gt;
 definition is the following.&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
 The size (denoted as &amp;lt;math&amp;gt;size_1(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
 rules.&lt;br /&gt;
&lt;br /&gt;
 - &amp;lt;math&amp;gt;size_1(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(\lambda x.t)=size_1(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1((t \ u))=size_1(t)+size_1(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the rest of the paper we will use another definition (denoted&lt;br /&gt;
as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt;)&lt;br /&gt;
  which is similar but  gives simpler computations.&lt;br /&gt;
We believe (but we have not yet checked the details) that, with&lt;br /&gt;
&amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt; we would have similar results. The&lt;br /&gt;
computation, with &amp;lt;math&amp;gt;size_1&amp;lt;/math&amp;gt;,  of the upper and lower&lt;br /&gt;
bounds of the number of terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; will be done&lt;br /&gt;
in section ??&lt;br /&gt;
&lt;br /&gt;
 definition&lt;br /&gt;
 The size (denoted as &amp;lt;math&amp;gt;size_0(t)&amp;lt;/math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is defined by the following&lt;br /&gt;
 rules.&lt;br /&gt;
&lt;br /&gt;
 - &amp;lt;math&amp;gt;size_0(t)=1&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(\lambda x.t)=size_0(t)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0((t \ u))=size_0(t)+size_0(u)+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These definitions of the size are, for the implementation point of&lt;br /&gt;
view, not realistic because, in case a term has a lot of distinct&lt;br /&gt;
variables, it is not realistic to use a single bit to code them.&lt;br /&gt;
The usual way to implement this coding is to replace the names of&lt;br /&gt;
variables by  their so called de Bruijn indices: a variable is&lt;br /&gt;
replaced by the number of &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; that occur, on the&lt;br /&gt;
path from the variable to the root, between the variable and the&lt;br /&gt;
&amp;lt;math&amp;gt;lambda&amp;lt;/math&amp;gt; that binds it. Note that, in this case,&lt;br /&gt;
different occurrences of the same variable may be represented by&lt;br /&gt;
different indices.&lt;br /&gt;
&lt;br /&gt;
Choosing the way we code these de Bruijn indices gives different&lt;br /&gt;
other ways of defining the size of a term. This can be done in the&lt;br /&gt;
following ways&lt;br /&gt;
&lt;br /&gt;
- Use unary notation, i.e. the size of the index &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;&lt;br /&gt;
simply is &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; itself&lt;br /&gt;
&lt;br /&gt;
- Use optimal binary notation, i.e. the size of the index&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;log_2(n)&amp;lt;/math&amp;gt; i.e. the logarithm of&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; in base 2.&lt;br /&gt;
&lt;br /&gt;
- Use uniform binary notation, i.e. the size of an index is the&lt;br /&gt;
logarithm, in base 2, of the number of leaves of the term.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== generating functions ==&lt;br /&gt;
&lt;br /&gt;
this does not work (by now) because radius of convergence 0&lt;br /&gt;
&lt;br /&gt;
no known results for the number of terms of size n (denoted &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
== our results ==&lt;br /&gt;
&lt;br /&gt;
(the proof of result of section k needs the result of section (k-1))&lt;br /&gt;
&lt;br /&gt;
=== Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
For the lower bound, we will first count the number &amp;lt;math&amp;gt;LB(n,k)&amp;lt;/math&amp;gt; of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; starting with &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas and having no other lambda below. This means that the lower part of the term is a binary tree of size &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; with&lt;br /&gt;
&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; possibility for each leaf. Therefore we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) = C(n-k) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And therefore, for &amp;lt;math&amp;gt;n &amp;gt; k&amp;lt;/math&amp;gt;, using our lower bound for &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n + 1 \geq n - k + 1&amp;lt;/math&amp;gt;, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) \geq K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;K=\frac{36}{49\sqrt{\pi}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed, we define &amp;lt;math&amp;gt;f(\alpha) = \left(4n\alpha\right)^{n(1-\alpha) + 1}&amp;lt;/math&amp;gt; (so &amp;lt;math&amp;gt;LB(n,k) \geq \frac{K}{(n+1)^\frac{3}{2}} f\left(\frac{k}{n}\right)&amp;lt;/math&amp;gt;) and look for the maximum of this function. We have &amp;lt;math&amp;gt;f&#039;(\alpha) = f(\alpha) \left(-n\ln(4n\alpha) +\frac{n(1-\alpha) + 1}{\alpha}\right)&amp;lt;/math&amp;gt;. Thus, &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\frac{n+1}{n\alpha}e^{\frac{n+1}{n\alpha}}\geq 4e(n+1)&amp;lt;/math&amp;gt;. The Lambert function begin increasing this means that &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\alpha \leq \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;f(\alpha)&amp;lt;/math&amp;gt; reaches a maximum for &amp;lt;math&amp;gt;\alpha = \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This means that &amp;lt;math&amp;gt;(4k)^{n-k}&amp;lt;/math&amp;gt; reaches its maximum for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed when &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;&lt;br /&gt;
is near to &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; which is likely not to be an integer. However, there are at least &amp;lt;math&amp;gt;\left\lfloor \frac{n (\ln(\ln(4en)) - 1)}{\ln^2(4en)}\right\rfloor&amp;lt;/math&amp;gt; integer between &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\frac{n+1}{\ln(4e(n+1))}&amp;lt;/math&amp;gt;. Indeed, using our inequalities on Lambert W function, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}-\frac{n+1}{\ln(4e(n+1))} = \frac{(n+1) (\ln(4e(n+1)) - W(4e(n+1)))}{W(4e(n+1))\ln(4e(n+1))} \geq \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, we get the following lowerbound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \sum_{k=1}^{n} LB(n,k) \geq \sum_{k=\lceil\frac{n+1}{\ln(4e(n+1))}\rceil}^{\lfloor\frac{n+1}{W(4e(n+1))}\rfloor} K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}} \geq K \left\lfloor \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}\right\rfloor \frac{\left(\frac{4(n+1)}{\ln(4e(n+1))}\right)^{n-\frac{n+1}{\ln(4e(n+1))}+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To simplify, using the fact that &amp;lt;math&amp;gt;\lim_{n\to +\infty}\left(\frac{\ln(n)}{\ln(4en)}\right)^n = 0&amp;lt;/math&amp;gt; and taking &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; large enough, we have the following lowerbound:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \frac{\sqrt{n}}{\ln^3(n)}\left(\frac{4n}{\ln(n)}\right)^{n-\frac{n}{\ln(n)}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We now compute an upper bound &amp;lt;math&amp;gt;UB(n,k)&amp;lt;/math&amp;gt; for the number of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with exactly &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas (that is with &amp;lt;math&amp;gt;n - k + 1&amp;lt;/math&amp;gt; leaves using the Motzkin numbers and allowing any lambda to bind any variable (regardless of the real scope):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;UB(n,k) = M(n,n-k+1) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we sum this for all possible &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and get an upper bound of &amp;lt;math&amp;gt;k^{n-k+1}&amp;lt;/math&amp;gt; using Lambert function as for the lower bound, we get the following upper bound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \leq M(n) \left(\frac{n+1}{W(e(n+1))}\right)^{n-\frac{n+1}{W(e(n+1))} + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The ration between our upper bound and lower bound is equivalent to (NEEDS FURTHER CHECKING):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\left(\frac{1}{4(3-2\sqrt{2})}\right)^n\frac{\ln^3(n)}{n^2} \simeq 1.46^n\frac{\ln^3(n)}{n^2}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== upper and lower bounds for number of lambdas in a term of size n ===&lt;br /&gt;
&lt;br /&gt;
=== Jakub&#039;s trik : at least 1 lambda in head position ===&lt;br /&gt;
&lt;br /&gt;
=== at least &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; lambdas in head position and number of lambdas in one path ===&lt;br /&gt;
&lt;br /&gt;
Remark: (may be 4) can be done directly without 3))&lt;br /&gt;
&lt;br /&gt;
=== each of the  &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; head lambdas really bind &amp;quot;many&amp;quot;  occurrences of the variable ===&lt;br /&gt;
&lt;br /&gt;
=== every fixed closed term (including the identity !) does not appear in a random term (in fact we have much more than that) ===&lt;br /&gt;
&lt;br /&gt;
comment : so different situation in combinatory logic and lambda calculus ; the coding uses a big size so need to count variables in a different way&lt;br /&gt;
&lt;br /&gt;
== Experiments ==&lt;br /&gt;
&lt;br /&gt;
results of the experiments we have done&lt;br /&gt;
&lt;br /&gt;
some experiments that have to be done : e.g. density of terms having &amp;lt;math&amp;gt;\lambda x.y&amp;lt;/math&amp;gt; or big Omega pattern ...&lt;br /&gt;
&lt;br /&gt;
== to be done ==&lt;br /&gt;
&lt;br /&gt;
Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; with other size for variables especially one, binary with fixed size&lt;br /&gt;
&lt;br /&gt;
== Open questions and Future work ==&lt;br /&gt;
&lt;br /&gt;
.....&lt;/div&gt;</summary>
		<author><name>René David</name></author>
	</entry>
	<entry>
		<id>http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2652</id>
		<title>Lambda counting</title>
		<link rel="alternate" type="text/html" href="http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2652"/>
		<updated>2008-10-20T13:09:10Z</updated>

		<summary type="html">&lt;p&gt;René David : /* Generality on lambda calculus */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
The question is: among programs, what is the probability of having a fixed property.&lt;br /&gt;
&lt;br /&gt;
what kind of program : turing machines, cellular automata, combinatory logic, lambda calculus&lt;br /&gt;
&lt;br /&gt;
what kind of properties : structural (for functional programs), behaviour (SN, weakly normalizable, ...&lt;br /&gt;
&lt;br /&gt;
references to known results on : turing machines, cellular automata&lt;br /&gt;
&lt;br /&gt;
we concentrate on combinatory logic, lambda calculus&lt;br /&gt;
&lt;br /&gt;
== Lambert function, Catalan and Motzkin numbers ==&lt;br /&gt;
&lt;br /&gt;
=== Catalan numbers ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; : Catalan numbers &lt;br /&gt;
&lt;br /&gt;
Usual equivalent: &amp;lt;math&amp;gt;C(n) \sim \frac{4^n}{n^{3/2}\sqrt{\pi}}&amp;lt;/math&amp;gt; which is obtained using Strirling formula.&lt;br /&gt;
However, using stirling series: &amp;lt;math&amp;gt;&lt;br /&gt;
  n!=\sqrt{2\pi n}\left({n\over e}\right)^n&lt;br /&gt;
  \left(&lt;br /&gt;
   1&lt;br /&gt;
   +{1\over12n}&lt;br /&gt;
   +{1\over288n^2}&lt;br /&gt;
   -{139\over51840n^3}&lt;br /&gt;
   -{571\over2488320n^4}&lt;br /&gt;
   + \cdots&lt;br /&gt;
  \right)&lt;br /&gt;
 &amp;lt;/math&amp;gt;, we get that for &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; we have &amp;lt;math&amp;gt;\sqrt{2\pi n}\left({n\over e}\right)^n \leq n! \leq \frac{7}{6}\sqrt{2\pi n}\left({n\over e}\right)^n&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, using this and &amp;lt;math&amp;gt;\left(\frac{n}{n+1}\right)^{n} &amp;gt; e^{-1}&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C(n) = \frac{(2n)!}{(n+1)!n!} \geq \frac{36}{49\sqrt{\pi}} \frac{4^n}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; but also for &amp;lt;math&amp;gt;n=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Motzkin numbers===&lt;br /&gt;
&lt;br /&gt;
Let us define &amp;lt;math&amp;gt;M(n,k)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; leafs. We get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n,k) = \frac{(n+k-1)!}{(n-k+1)!(k-1)!k!}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, by summing we define &amp;lt;math&amp;gt;M(n)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and give an equivalent:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n) = \sum_{k=0}^n M(n,k) \sim \left(\frac{1}{3-2\sqrt{2}}\right)^n \frac{1}{n^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lambert W function===&lt;br /&gt;
&lt;br /&gt;
The Lambert function &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; is defined by the equation &amp;lt;math&amp;gt;x = W(x) e ^ {W(x)} &amp;lt;/math&amp;gt;&lt;br /&gt;
which has a unique solution in &amp;lt;math&amp;gt;\mathbb{R}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;x \geq e&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x)&amp;lt;/math&amp;gt; which implies that &lt;br /&gt;
&amp;lt;math&amp;gt;W(x) \sim \ln(x)&amp;lt;/math&amp;gt; near &amp;lt;math&amp;gt;+\infty&amp;lt;/math&amp;gt;. To prove this, it is enough to remark that&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;(\ln(x) - \ln(\ln(x))e^{\ln(x)-\ln(\ln(x))} = x \left(1 - \frac{\ln(\ln(x))}{\ln(x)}\right) \leq x \leq x \ln(x) = \ln(x) e^{\ln(x)} &amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is not precise enough for our purpose. Using one step of the Newton method from &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt;, we can find a better upper bound for &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; because &amp;lt;math&amp;gt;y \mapsto y e^y&amp;lt;/math&amp;gt; is increasing and convex. This gives:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, if we define &amp;lt;math&amp;gt;f(y) = y e^y&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;f&#039;(y)=(1+y)e^y&amp;lt;/math&amp;gt; and therefore, newton&#039;s method from &amp;lt;math&amp;gt;A = \ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt; gives a point at position:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;&lt;br /&gt;
A - \frac{f(A) - x}{f&#039;(A)} &lt;br /&gt;
  = A +  \frac{x \ln(\ln(x))}{\ln(x)} \frac{\ln(x)}{x(\ln(x) - \ln(\ln(x)) + 1)}&lt;br /&gt;
  = A +  \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1} &lt;br /&gt;
&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, we show that for &amp;lt;math&amp;gt;x\geq e&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + 1&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, for &amp;lt;math&amp;gt;x &amp;gt; 1&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;e^{\sqrt{ex}} \geq 1 + \sqrt{ex} + \frac{ex}{2} \geq x&amp;lt;/math&amp;gt;, which implies&lt;br /&gt;
&amp;lt;math&amp;gt;ex \geq \ln^2(x)&amp;lt;/math&amp;gt; and therefore &amp;lt;math&amp;gt;\ln(x) - \ln\ln(x) + 1 \geq \ln\ln(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==  combinatory logic ==&lt;br /&gt;
&lt;br /&gt;
results on  combinatory logic&lt;br /&gt;
&lt;br /&gt;
== Generality on lambda calculus ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
definition The set &amp;lt;math&amp;gt;\lambda&amp;lt;\math&amp;gt; of lambda terms (or,&lt;br /&gt;
simply, terms) is defined by the following grammar&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;t, u  := Var \ \mid \ \lambda x.t \ \mid \ (t \ u)&amp;lt;\math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To be able to define the notion of a {\it random} term we&lt;br /&gt;
 have to define a distribution law on &amp;lt;math&amp;gt;\Lambda&amp;lt;\math&amp;gt;. There are many&lt;br /&gt;
 possibilities for that. We choose here the simplest one. Note that this is the one for which, at least at present,  we are&lt;br /&gt;
 able to prove some results. It is based on densities. For that we&lt;br /&gt;
 first have to define the {\it size} of a term.&lt;br /&gt;
&lt;br /&gt;
 The usual&lt;br /&gt;
 definition is the following.&lt;br /&gt;
&lt;br /&gt;
definition&lt;br /&gt;
 The size (denoted as &amp;lt;math&amp;gt;size_1(t)&amp;lt;\math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;\math&amp;gt; is defined by the following&lt;br /&gt;
 rules.&lt;br /&gt;
&lt;br /&gt;
 - &amp;lt;math&amp;gt;size_1(t)=1&amp;lt;\math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;\math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(\lambda x.t)=size_1(t)+1&amp;lt;\math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1((t \ u))=size_1(t)+size_1(u)+1&amp;lt;\math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the rest of the paper we will use another definition (denoted&lt;br /&gt;
as &amp;lt;math&amp;gt;size_0(t)&amp;lt;\math&amp;gt;)&lt;br /&gt;
  which is similar but  gives simpler computations.&lt;br /&gt;
We believe (but we have not yet checked the details) that, with&lt;br /&gt;
&amp;lt;math&amp;gt;size_1&amp;lt;\math&amp;gt; we would have similar results. The&lt;br /&gt;
computation, with &amp;lt;math&amp;gt;size_1&amp;lt;\math&amp;gt;,  of the upper and lower&lt;br /&gt;
bounds of the number of terms of size &amp;lt;math&amp;gt;n&amp;lt;\math&amp;gt; will be done&lt;br /&gt;
in section ??&lt;br /&gt;
&lt;br /&gt;
 definition&lt;br /&gt;
 The size (denoted as &amp;lt;math&amp;gt;size_0(t)&amp;lt;\math&amp;gt;) of a  term &amp;lt;math&amp;gt;t&amp;lt;\math&amp;gt; is defined by the following&lt;br /&gt;
 rules.&lt;br /&gt;
&lt;br /&gt;
 - &amp;lt;math&amp;gt;size_0(t)=1&amp;lt;\math&amp;gt; if &amp;lt;math&amp;gt;t&amp;lt;\math&amp;gt; is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(\lambda x.t)=size_0(t)+1&amp;lt;\math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0((t \ u))=size_0(t)+size_0(u)+1&amp;lt;\math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These definitions of the size are, for the implementation point of&lt;br /&gt;
view, not realistic because, in case a term has a lot of distinct&lt;br /&gt;
variables, it is not realistic to use a single bit to code them.&lt;br /&gt;
The usual way to implement this coding is to replace the names of&lt;br /&gt;
variables by  their so called de Bruijn indices: a variable is&lt;br /&gt;
replaced by the number of &amp;lt;math&amp;gt;\lambda&amp;lt;\math&amp;gt; that occur, on the&lt;br /&gt;
path from the variable to the root, between the variable and the&lt;br /&gt;
&amp;lt;math&amp;gt;lambda&amp;lt;\math&amp;gt; that binds it. Note that, in this case,&lt;br /&gt;
different occurrences of the same variable may be represented by&lt;br /&gt;
different indices.&lt;br /&gt;
&lt;br /&gt;
Choosing the way we code these de Bruijn indices gives different&lt;br /&gt;
other ways of defining the size of a term. This can be done in the&lt;br /&gt;
following ways&lt;br /&gt;
&lt;br /&gt;
- Use unary notation, i.e. the size of the index &amp;lt;math&amp;gt;n&amp;lt;\math&amp;gt;&lt;br /&gt;
simply is &amp;lt;math&amp;gt;n&amp;lt;\math&amp;gt; itself&lt;br /&gt;
&lt;br /&gt;
- Use optimal binary notation, i.e. the size of the index&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;\math&amp;gt; is &amp;lt;math&amp;gt;log_2(n)&amp;lt;\math&amp;gt; i.e. the logarithm of&lt;br /&gt;
&amp;lt;math&amp;gt;n&amp;lt;\math&amp;gt; in base 2.&lt;br /&gt;
&lt;br /&gt;
- Use uniform binary notation, i.e. the size of an index is the&lt;br /&gt;
logarithm, in base 2, of the number of leaves of the term.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== generating functions ==&lt;br /&gt;
&lt;br /&gt;
this does not work (by now) because radius of convergence 0&lt;br /&gt;
&lt;br /&gt;
no known results for the number of terms of size n (denoted &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
== our results ==&lt;br /&gt;
&lt;br /&gt;
(the proof of result of section k needs the result of section (k-1))&lt;br /&gt;
&lt;br /&gt;
=== Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
For the lower bound, we will first count the number &amp;lt;math&amp;gt;LB(n,k)&amp;lt;/math&amp;gt; of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; starting with &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas and having no other lambda below. This means that the lower part of the term is a binary tree of size &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; with&lt;br /&gt;
&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; possibility for each leaf. Therefore we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) = C(n-k) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And therefore, for &amp;lt;math&amp;gt;n &amp;gt; k&amp;lt;/math&amp;gt;, using our lower bound for &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n + 1 \geq n - k + 1&amp;lt;/math&amp;gt;, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) \geq K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;K=\frac{36}{49\sqrt{\pi}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed, we define &amp;lt;math&amp;gt;f(\alpha) = \left(4n\alpha\right)^{n(1-\alpha) + 1}&amp;lt;/math&amp;gt; (so &amp;lt;math&amp;gt;LB(n,k) \geq \frac{K}{(n+1)^\frac{3}{2}} f\left(\frac{k}{n}\right)&amp;lt;/math&amp;gt;) and look for the maximum of this function. We have &amp;lt;math&amp;gt;f&#039;(\alpha) = f(\alpha) \left(-n\ln(4n\alpha) +\frac{n(1-\alpha) + 1}{\alpha}\right)&amp;lt;/math&amp;gt;. Thus, &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\frac{n+1}{n\alpha}e^{\frac{n+1}{n\alpha}}\geq 4e(n+1)&amp;lt;/math&amp;gt;. The Lambert function begin increasing this means that &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\alpha \leq \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;f(\alpha)&amp;lt;/math&amp;gt; reaches a maximum for &amp;lt;math&amp;gt;\alpha = \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This means that &amp;lt;math&amp;gt;(4k)^{n-k}&amp;lt;/math&amp;gt; reaches its maximum for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed when &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;&lt;br /&gt;
is near to &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; which is likely not to be an integer. However, there are at least &amp;lt;math&amp;gt;\left\lfloor \frac{n (\ln(\ln(4en)) - 1)}{\ln^2(4en)}\right\rfloor&amp;lt;/math&amp;gt; integer between &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\frac{n+1}{\ln(4e(n+1))}&amp;lt;/math&amp;gt;. Indeed, using our inequalities on Lambert W function, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}-\frac{n+1}{\ln(4e(n+1))} = \frac{(n+1) (\ln(4e(n+1)) - W(4e(n+1)))}{W(4e(n+1))\ln(4e(n+1))} \geq \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, we get the following lowerbound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \sum_{k=1}^{n} LB(n,k) \geq \sum_{k=\lceil\frac{n+1}{\ln(4e(n+1))}\rceil}^{\lfloor\frac{n+1}{W(4e(n+1))}\rfloor} K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}} \geq K \left\lfloor \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}\right\rfloor \frac{\left(\frac{4(n+1)}{\ln(4e(n+1))}\right)^{n-\frac{n+1}{\ln(4e(n+1))}+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To simplify, using the fact that &amp;lt;math&amp;gt;\lim_{n\to +\infty}\left(\frac{\ln(n)}{\ln(4en)}\right)^n = 0&amp;lt;/math&amp;gt; and taking &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; large enough, we have the following lowerbound:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \frac{\sqrt{n}}{\ln^3(n)}\left(\frac{4n}{\ln(n)}\right)^{n-\frac{n}{\ln(n)}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We now compute an upper bound &amp;lt;math&amp;gt;UB(n,k)&amp;lt;/math&amp;gt; for the number of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with exactly &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas (that is with &amp;lt;math&amp;gt;n - k + 1&amp;lt;/math&amp;gt; leaves using the Motzkin numbers and allowing any lambda to bind any variable (regardless of the real scope):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;UB(n,k) = M(n,n-k+1) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we sum this for all possible &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and get an upper bound of &amp;lt;math&amp;gt;k^{n-k+1}&amp;lt;/math&amp;gt; using Lambert function as for the lower bound, we get the following upper bound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \leq M(n) \left(\frac{n+1}{W(e(n+1))}\right)^{n-\frac{n+1}{W(e(n+1))} + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The ration between our upper bound and lower bound is equivalent to (NEEDS FURTHER CHECKING):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\left(\frac{1}{4(3-2\sqrt{2})}\right)^n\frac{\ln^3(n)}{n^2} \simeq 1.46^n\frac{\ln^3(n)}{n^2}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== upper and lower bounds for number of lambdas in a term of size n ===&lt;br /&gt;
&lt;br /&gt;
=== Jakub&#039;s trik : at least 1 lambda in head position ===&lt;br /&gt;
&lt;br /&gt;
=== at least &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; lambdas in head position and number of lambdas in one path ===&lt;br /&gt;
&lt;br /&gt;
Remark: (may be 4) can be done directly without 3))&lt;br /&gt;
&lt;br /&gt;
=== each of the  &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; head lambdas really bind &amp;quot;many&amp;quot;  occurrences of the variable ===&lt;br /&gt;
&lt;br /&gt;
=== every fixed closed term (including the identity !) does not appear in a random term (in fact we have much more than that) ===&lt;br /&gt;
&lt;br /&gt;
comment : so different situation in combinatory logic and lambda calculus ; the coding uses a big size so need to count variables in a different way&lt;br /&gt;
&lt;br /&gt;
== Experiments ==&lt;br /&gt;
&lt;br /&gt;
results of the experiments we have done&lt;br /&gt;
&lt;br /&gt;
some experiments that have to be done : e.g. density of terms having &amp;lt;math&amp;gt;\lambda x.y&amp;lt;/math&amp;gt; or big Omega pattern ...&lt;br /&gt;
&lt;br /&gt;
== to be done ==&lt;br /&gt;
&lt;br /&gt;
Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; with other size for variables especially one, binary with fixed size&lt;br /&gt;
&lt;br /&gt;
== Open questions and Future work ==&lt;br /&gt;
&lt;br /&gt;
.....&lt;/div&gt;</summary>
		<author><name>René David</name></author>
	</entry>
	<entry>
		<id>http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2651</id>
		<title>Lambda counting</title>
		<link rel="alternate" type="text/html" href="http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2651"/>
		<updated>2008-10-20T13:00:29Z</updated>

		<summary type="html">&lt;p&gt;René David : /* Generality on lambda calculus */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
The question is: among programs, what is the probability of having a fixed property.&lt;br /&gt;
&lt;br /&gt;
what kind of program : turing machines, cellular automata, combinatory logic, lambda calculus&lt;br /&gt;
&lt;br /&gt;
what kind of properties : structural (for functional programs), behaviour (SN, weakly normalizable, ...&lt;br /&gt;
&lt;br /&gt;
references to known results on : turing machines, cellular automata&lt;br /&gt;
&lt;br /&gt;
we concentrate on combinatory logic, lambda calculus&lt;br /&gt;
&lt;br /&gt;
== Lambert function, Catalan and Motzkin numbers ==&lt;br /&gt;
&lt;br /&gt;
=== Catalan numbers ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; : Catalan numbers &lt;br /&gt;
&lt;br /&gt;
Usual equivalent: &amp;lt;math&amp;gt;C(n) \sim \frac{4^n}{n^{3/2}\sqrt{\pi}}&amp;lt;/math&amp;gt; which is obtained using Strirling formula.&lt;br /&gt;
However, using stirling series: &amp;lt;math&amp;gt;&lt;br /&gt;
  n!=\sqrt{2\pi n}\left({n\over e}\right)^n&lt;br /&gt;
  \left(&lt;br /&gt;
   1&lt;br /&gt;
   +{1\over12n}&lt;br /&gt;
   +{1\over288n^2}&lt;br /&gt;
   -{139\over51840n^3}&lt;br /&gt;
   -{571\over2488320n^4}&lt;br /&gt;
   + \cdots&lt;br /&gt;
  \right)&lt;br /&gt;
 &amp;lt;/math&amp;gt;, we get that for &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; we have &amp;lt;math&amp;gt;\sqrt{2\pi n}\left({n\over e}\right)^n \leq n! \leq \frac{7}{6}\sqrt{2\pi n}\left({n\over e}\right)^n&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, using this and &amp;lt;math&amp;gt;\left(\frac{n}{n+1}\right)^{n} &amp;gt; e^{-1}&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C(n) = \frac{(2n)!}{(n+1)!n!} \geq \frac{36}{49\sqrt{\pi}} \frac{4^n}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;n\geq1&amp;lt;/math&amp;gt; but also for &amp;lt;math&amp;gt;n=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Motzkin numbers===&lt;br /&gt;
&lt;br /&gt;
Let us define &amp;lt;math&amp;gt;M(n,k)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; leafs. We get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n,k) = \frac{(n+k-1)!}{(n-k+1)!(k-1)!k!}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, by summing we define &amp;lt;math&amp;gt;M(n)&amp;lt;/math&amp;gt; the number of unary-binary trees with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; inner nodes and give an equivalent:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;M(n) = \sum_{k=0}^n M(n,k) \sim \left(\frac{1}{3-2\sqrt{2}}\right)^n \frac{1}{n^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lambert W function===&lt;br /&gt;
&lt;br /&gt;
The Lambert function &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; is defined by the equation &amp;lt;math&amp;gt;x = W(x) e ^ {W(x)} &amp;lt;/math&amp;gt;&lt;br /&gt;
which has a unique solution in &amp;lt;math&amp;gt;\mathbb{R}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;x \geq e&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x)&amp;lt;/math&amp;gt; which implies that &lt;br /&gt;
&amp;lt;math&amp;gt;W(x) \sim \ln(x)&amp;lt;/math&amp;gt; near &amp;lt;math&amp;gt;+\infty&amp;lt;/math&amp;gt;. To prove this, it is enough to remark that&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;(\ln(x) - \ln(\ln(x))e^{\ln(x)-\ln(\ln(x))} = x \left(1 - \frac{\ln(\ln(x))}{\ln(x)}\right) \leq x \leq x \ln(x) = \ln(x) e^{\ln(x)} &amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is not precise enough for our purpose. Using one step of the Newton method from &amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt;, we can find a better upper bound for &amp;lt;math&amp;gt;W(x)&amp;lt;/math&amp;gt; because &amp;lt;math&amp;gt;y \mapsto y e^y&amp;lt;/math&amp;gt; is increasing and convex. This gives:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, if we define &amp;lt;math&amp;gt;f(y) = y e^y&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;f&#039;(y)=(1+y)e^y&amp;lt;/math&amp;gt; and therefore, newton&#039;s method from &amp;lt;math&amp;gt;A = \ln(x) - \ln(\ln(x))&amp;lt;/math&amp;gt; gives a point at position:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;&lt;br /&gt;
A - \frac{f(A) - x}{f&#039;(A)} &lt;br /&gt;
  = A +  \frac{x \ln(\ln(x))}{\ln(x)} \frac{\ln(x)}{x(\ln(x) - \ln(\ln(x)) + 1)}&lt;br /&gt;
  = A +  \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1} &lt;br /&gt;
&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, we show that for &amp;lt;math&amp;gt;x\geq e&amp;lt;/math&amp;gt;, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x))  + 1&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Indeed, for &amp;lt;math&amp;gt;x &amp;gt; 1&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;e^{\sqrt{ex}} \geq 1 + \sqrt{ex} + \frac{ex}{2} \geq x&amp;lt;/math&amp;gt;, which implies&lt;br /&gt;
&amp;lt;math&amp;gt;ex \geq \ln^2(x)&amp;lt;/math&amp;gt; and therefore &amp;lt;math&amp;gt;\ln(x) - \ln\ln(x) + 1 \geq \ln\ln(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==  combinatory logic ==&lt;br /&gt;
&lt;br /&gt;
results on  combinatory logic&lt;br /&gt;
&lt;br /&gt;
== Generality on lambda calculus ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
\begin{definition}&lt;br /&gt;
The set $\lambda$ of lambda terms (or, simply, terms) is defined&lt;br /&gt;
by the following grammar&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;t, u  := Var \ \mid \ \lambda x.t \ \mid \ (t \ u)$$&lt;br /&gt;
&lt;br /&gt;
\end{definition}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To be able to define the notion of a {\it random} term we&lt;br /&gt;
 have to define a distribution law on &amp;lt;math&amp;gt;\Lambda$. There are many&lt;br /&gt;
 possibilities for that. We choose here the simplest one. Note that this is the one for which, at least at present,  we are&lt;br /&gt;
 able to prove some results. It is based on densities. For that we&lt;br /&gt;
 first have to define the {\it size} of a term.&lt;br /&gt;
&lt;br /&gt;
 The usual&lt;br /&gt;
 definition is the following.&lt;br /&gt;
&lt;br /&gt;
 \begin{definition}&lt;br /&gt;
 The size (denoted as &amp;lt;math&amp;gt;size_1(t)$) of a  term &amp;lt;math&amp;gt;t$ is defined by the following&lt;br /&gt;
 rules.&lt;br /&gt;
&lt;br /&gt;
 - &amp;lt;math&amp;gt;size_1(t)=1$ if &amp;lt;math&amp;gt;t$ is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1(\lambda x.t)=size_1(t)+1$&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_1((t \ u))=size_1(t)+size_1(u)+1$&lt;br /&gt;
\end{definition}&lt;br /&gt;
&lt;br /&gt;
In the rest of the paper we will use another definition (denoted&lt;br /&gt;
as &amp;lt;math&amp;gt;size_0(t)$)&lt;br /&gt;
  which is similar but  gives simpler computations.&lt;br /&gt;
We believe (but we have not yet checked the details) that, with&lt;br /&gt;
&amp;lt;math&amp;gt;size_1$ we would have similar results. The computation, with&lt;br /&gt;
&amp;lt;math&amp;gt;size_1$,  of the upper and lower bounds of the number of&lt;br /&gt;
terms of size &amp;lt;math&amp;gt;n$ will be done in section ??&lt;br /&gt;
&lt;br /&gt;
 \begin{definition}&lt;br /&gt;
 The size (denoted as &amp;lt;math&amp;gt;size_0(t)$) of a  term &amp;lt;math&amp;gt;t$ is defined by the following&lt;br /&gt;
 rules.&lt;br /&gt;
&lt;br /&gt;
 - &amp;lt;math&amp;gt;size_0(t)=1$ if &amp;lt;math&amp;gt;t$ is a variable.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0(\lambda x.t)=size_0(t)+1$&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;math&amp;gt;size_0((t \ u))=size_0(t)+size_0(u)+1$&lt;br /&gt;
\end{definition}&lt;br /&gt;
&lt;br /&gt;
These definitions of the size are, for the implementation point of&lt;br /&gt;
view, not realistic because, in case a term has a lot of distinct&lt;br /&gt;
variables, it is not realistic to use a single bit to code them.&lt;br /&gt;
The usual way to implement this coding is to replace the names of&lt;br /&gt;
variables by  their so called de Bruijn indices: a variable is&lt;br /&gt;
replaced by the number of &amp;lt;math&amp;gt;\lambda$ that occur, on the path&lt;br /&gt;
from the variable to the root, between the variable and the&lt;br /&gt;
&amp;lt;math&amp;gt;lambda$ that binds it. Note that, in this case, different&lt;br /&gt;
occurrences of the same variable may be represented by different&lt;br /&gt;
indices.&lt;br /&gt;
&lt;br /&gt;
Choosing the way we code these de Bruijn indices gives different&lt;br /&gt;
other ways of defining the size of a term. This can be done in the&lt;br /&gt;
following ways&lt;br /&gt;
&lt;br /&gt;
- Use unary notation, i.e. the size of the index &amp;lt;math&amp;gt;n$ simply&lt;br /&gt;
is &amp;lt;math&amp;gt;n$ itself&lt;br /&gt;
&lt;br /&gt;
- Use optimal binary notation, i.e. the size of the index &amp;lt;math&amp;gt;n$&lt;br /&gt;
is &amp;lt;math&amp;gt;log_2(n)$ i.e. the logarithm of &amp;lt;math&amp;gt;n$ in base 2.&lt;br /&gt;
&lt;br /&gt;
- Use uniform binary notation, i.e. the size of an index is the&lt;br /&gt;
logarithm, in base 2, of the number of leaves of the term.&lt;br /&gt;
&lt;br /&gt;
== generating functions ==&lt;br /&gt;
&lt;br /&gt;
this does not work (by now) because radius of convergence 0&lt;br /&gt;
&lt;br /&gt;
no known results for the number of terms of size n (denoted &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
== our results ==&lt;br /&gt;
&lt;br /&gt;
(the proof of result of section k needs the result of section (k-1))&lt;br /&gt;
&lt;br /&gt;
=== Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
For the lower bound, we will first count the number &amp;lt;math&amp;gt;LB(n,k)&amp;lt;/math&amp;gt; of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; starting with &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas and having no other lambda below. This means that the lower part of the term is a binary tree of size &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; with&lt;br /&gt;
&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; possibility for each leaf. Therefore we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) = C(n-k) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And therefore, for &amp;lt;math&amp;gt;n &amp;gt; k&amp;lt;/math&amp;gt;, using our lower bound for &amp;lt;math&amp;gt;C(n)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n + 1 \geq n - k + 1&amp;lt;/math&amp;gt;, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;LB(n,k) \geq K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;K=\frac{36}{49\sqrt{\pi}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed, we define &amp;lt;math&amp;gt;f(\alpha) = \left(4n\alpha\right)^{n(1-\alpha) + 1}&amp;lt;/math&amp;gt; (so &amp;lt;math&amp;gt;LB(n,k) \geq \frac{K}{(n+1)^\frac{3}{2}} f\left(\frac{k}{n}\right)&amp;lt;/math&amp;gt;) and look for the maximum of this function. We have &amp;lt;math&amp;gt;f&#039;(\alpha) = f(\alpha) \left(-n\ln(4n\alpha) +\frac{n(1-\alpha) + 1}{\alpha}\right)&amp;lt;/math&amp;gt;. Thus, &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\frac{n+1}{n\alpha}e^{\frac{n+1}{n\alpha}}\geq 4e(n+1)&amp;lt;/math&amp;gt;. The Lambert function begin increasing this means that &amp;lt;math&amp;gt;f&#039;(\alpha) \geq 0&amp;lt;/math&amp;gt; is equivalent to &amp;lt;math&amp;gt;\alpha \leq \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;f(\alpha)&amp;lt;/math&amp;gt; reaches a maximum for &amp;lt;math&amp;gt;\alpha = \frac{n+1}{nW(4e(n+1))}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This means that &amp;lt;math&amp;gt;(4k)^{n-k}&amp;lt;/math&amp;gt; reaches its maximum for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; fixed when &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;&lt;br /&gt;
is near to &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; which is likely not to be an integer. However, there are at least &amp;lt;math&amp;gt;\left\lfloor \frac{n (\ln(\ln(4en)) - 1)}{\ln^2(4en)}\right\rfloor&amp;lt;/math&amp;gt; integer between &amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\frac{n+1}{\ln(4e(n+1))}&amp;lt;/math&amp;gt;. Indeed, using our inequalities on Lambert W function, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\frac{n+1}{W(4e(n+1))}-\frac{n+1}{\ln(4e(n+1))} = \frac{(n+1) (\ln(4e(n+1)) - W(4e(n+1)))}{W(4e(n+1))\ln(4e(n+1))} \geq \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, we get the following lowerbound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \sum_{k=1}^{n} LB(n,k) \geq \sum_{k=\lceil\frac{n+1}{\ln(4e(n+1))}\rceil}^{\lfloor\frac{n+1}{W(4e(n+1))}\rfloor} K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}} \geq K \left\lfloor \frac{(n+1) (\ln(\ln(4e(n+1))) - 1)}{\ln^2(4e(n+1))}\right\rfloor \frac{\left(\frac{4(n+1)}{\ln(4e(n+1))}\right)^{n-\frac{n+1}{\ln(4e(n+1))}+1}}{(n+1)^\frac{3}{2}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To simplify, using the fact that &amp;lt;math&amp;gt;\lim_{n\to +\infty}\left(\frac{\ln(n)}{\ln(4en)}\right)^n = 0&amp;lt;/math&amp;gt; and taking &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; large enough, we have the following lowerbound:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \geq \frac{\sqrt{n}}{\ln^3(n)}\left(\frac{4n}{\ln(n)}\right)^{n-\frac{n}{\ln(n)}}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We now compute an upper bound &amp;lt;math&amp;gt;UB(n,k)&amp;lt;/math&amp;gt; for the number of lambda-terms of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with exactly &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; lambdas (that is with &amp;lt;math&amp;gt;n - k + 1&amp;lt;/math&amp;gt; leaves using the Motzkin numbers and allowing any lambda to bind any variable (regardless of the real scope):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;UB(n,k) = M(n,n-k+1) k^{n-k+1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we sum this for all possible &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and get an upper bound of &amp;lt;math&amp;gt;k^{n-k+1}&amp;lt;/math&amp;gt; using Lambert function as for the lower bound, we get the following upper bound for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\#(L_n) \leq M(n) \left(\frac{n+1}{W(e(n+1))}\right)^{n-\frac{n+1}{W(e(n+1))} + 1}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The ration between our upper bound and lower bound is equivalent to (NEEDS FURTHER CHECKING):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;\left(\frac{1}{4(3-2\sqrt{2})}\right)^n\frac{\ln^3(n)}{n^2} \simeq 1.46^n\frac{\ln^3(n)}{n^2}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== upper and lower bounds for number of lambdas in a term of size n ===&lt;br /&gt;
&lt;br /&gt;
=== Jakub&#039;s trik : at least 1 lambda in head position ===&lt;br /&gt;
&lt;br /&gt;
=== at least &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; lambdas in head position and number of lambdas in one path ===&lt;br /&gt;
&lt;br /&gt;
Remark: (may be 4) can be done directly without 3))&lt;br /&gt;
&lt;br /&gt;
=== each of the  &amp;lt;math&amp;gt;o(\sqrt{n/\ln(n)})&amp;lt;/math&amp;gt; head lambdas really bind &amp;quot;many&amp;quot;  occurrences of the variable ===&lt;br /&gt;
&lt;br /&gt;
=== every fixed closed term (including the identity !) does not appear in a random term (in fact we have much more than that) ===&lt;br /&gt;
&lt;br /&gt;
comment : so different situation in combinatory logic and lambda calculus ; the coding uses a big size so need to count variables in a different way&lt;br /&gt;
&lt;br /&gt;
== Experiments ==&lt;br /&gt;
&lt;br /&gt;
results of the experiments we have done&lt;br /&gt;
&lt;br /&gt;
some experiments that have to be done : e.g. density of terms having &amp;lt;math&amp;gt;\lambda x.y&amp;lt;/math&amp;gt; or big Omega pattern ...&lt;br /&gt;
&lt;br /&gt;
== to be done ==&lt;br /&gt;
&lt;br /&gt;
Upper and lower bounds for &amp;lt;math&amp;gt;L_n&amp;lt;/math&amp;gt; with other size for variables especially one, binary with fixed size&lt;br /&gt;
&lt;br /&gt;
== Open questions and Future work ==&lt;br /&gt;
&lt;br /&gt;
.....&lt;/div&gt;</summary>
		<author><name>René David</name></author>
	</entry>
	<entry>
		<id>http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2486</id>
		<title>Lambda counting</title>
		<link rel="alternate" type="text/html" href="http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2486"/>
		<updated>2008-10-17T07:43:10Z</updated>

		<summary type="html">&lt;p&gt;René David : /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&amp;lt;math&amp;gt;\sqrt{3}&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>René David</name></author>
	</entry>
	<entry>
		<id>http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2485</id>
		<title>Lambda counting</title>
		<link rel="alternate" type="text/html" href="http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2485"/>
		<updated>2008-10-17T07:37:23Z</updated>

		<summary type="html">&lt;p&gt;René David : /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&amp;lt;math&amp;gt;\sqrt{2}&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>René David</name></author>
	</entry>
	<entry>
		<id>http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2484</id>
		<title>Lambda counting</title>
		<link rel="alternate" type="text/html" href="http://os-vps418.infomaniak.ch:1250/mediawiki/index.php?title=Lambda_counting&amp;diff=2484"/>
		<updated>2008-10-17T07:36:09Z</updated>

		<summary type="html">&lt;p&gt;René David : &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;/div&gt;</summary>
		<author><name>René David</name></author>
	</entry>
</feed>