« Lambda counting » : différence entre les versions

De Wiki du LAMA (UMR 5127)
Aller à la navigation Aller à la recherche
Aucun résumé des modifications
 
(113 versions intermédiaires par 6 utilisateurs non affichées)
Ligne 1 : Ligne 1 :
counting.pdf : [http://www.lama.univ-savoie.fr/~david/ftp/paper/counting.pdf] version on wednesday 07/01 at 17h30. the files below are the good ones. René




==Introduction==
==Introduction==




intro : [http://www.lama.univ-savoie.fr/~david/ftp/paper/intro.tex]
This paper addresses the following question. Having a
(theoretical) programming language and a property, 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 ? We consider,
in this introduction, that this notion of
probability is, at least intuitively, sufficiently clear but, of
course, this will have to be made precise.


This
kind of question has some known results for Turing machines and
cellular automata. Some of them will be given in section ??.
We will concentrate here on functional programming
languages and, more specifically, on the lambda calculus, the
simplest such language. Various properties can be studied. Some
concern the structure of a term, some concern its behaviour.


== lambda==
The first question for which it would be desirable to have an
[http://www.lama.univ-savoie.fr/~david/ftp/paper/section-2.tex]
answer is the following: give a "simple" equivalent for the number
of terms of size n. This question is, at present and as far as we
know, unsolved and the usual technics of generating functions does
not work. See section ??? for more details. We give here upper and
lower bounds for this number. This estimation will be enough for
our purpose but the gap between the lower and the upper bound is
to big to hope to find an equivalent.


==combinatorics==
For other questions, some experiments have already been done (see
section 3 : [http://www.lama.univ-savoie.fr/~david/ftp/paper/section-3.tex]
for example ...) which clearly indicates the desired result. For
example, they "show" that almost every closed lambda term begins
with a <math>\lambda</math> but, as far as we know, there was no
"proved" result of this form.


generating :
This paper proves some non trivial results on the structural form
[http://www.lama.univ-savoie.fr/~david/ftp/paper/generating.tex]
of a lambda term. In particular we show that almost every closed
lambda term begins with "many" <math>\lambda</math> (the precise
meaning of this is given in theorem ??), that they bound "many"
occurrences of the corresponding variables (theorem ??) and that,
given any fixed closed term, ''almost no''
<math>\lambda</math>-term has this term as a sub-term (theorem
??).


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
<math>(\delta \ \delta)</math> 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
<math>(\delta \ \delta)</math> and this is thus useless to have a
result for non SN. On the opposite direction, it is known that, if
a term t is not SN, then a pattern "looking like"
<math>(\delta \ \delta)</math> (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
probability of possessing the desired pattern). But, again, this experimental result would be of no use to guess the result.


Another question, which is also undecidable, and for which finding
the probability seems to be even more difficult, is to get the
probability of being weakly normalizable i.e. there is a sequence
of reduction that terminates.


==bounds==
[http://www.lama.univ-savoie.fr/~david/ftp/paper/section-4.tex]


==main results==
[http://www.lama.univ-savoie.fr/~david/ftp/paper/section-5.tex]

==section 5-2==
[http://www.lama.univ-savoie.fr/~david/ftp/paper/section-5-2.tex]

section 5-2-2 :
[http://www.lama.univ-savoie.fr/~david/ftp/paper/section-5-2-2.tex]


section 5-2-3 :
[http://www.lama.univ-savoie.fr/~david/ftp/paper/section-5-2-3.tex]

section 5-2-4 :
[http://www.lama.univ-savoie.fr/~david/ftp/paper/section-5-2-4.tex]


==section 5-3==
[http://www.lama.univ-savoie.fr/~david/ftp/paper/section-5-3.tex]

section 5-3-1 :
[http://www.lama.univ-savoie.fr/~david/ftp/paper/section-5-3-1.tex]


section 5-3-2 :
[http://www.lama.univ-savoie.fr/~david/ftp/paper/section-5-3-2.tex]

section 5-3-3 :
[http://www.lama.univ-savoie.fr/~david/ftp/paper/section-5-3-3.tex]

section 5-3-4 :
[http://www.lama.univ-savoie.fr/~david/ftp/paper/section-5-3-4.tex]

==other systems==
[http://www.lama.univ-savoie.fr/~david/ftp/paper/section-6.tex]

section 6.1 :
[http://www.lama.univ-savoie.fr/~david/ftp/paper/section-6.1.tex]

section 6.2 :
[http://www.lama.univ-savoie.fr/~david/ftp/paper/section-6.2.tex]


==conclusion==
[http://www.lama.univ-savoie.fr/~david/ftp/paper/section-7.tex]

section 7.1 :
[http://www.lama.univ-savoie.fr/~david/ftp/paper/section-7.1.tex]

section 7.2 :
[http://www.lama.univ-savoie.fr/~david/ftp/paper/section-7.2.tex]

section 7.3 :
[http://www.lama.univ-savoie.fr/~david/ftp/paper/section-7.3.tex]

==biblio ==
[http://www.lama.univ-savoie.fr/~david/ftp/paper/biblio.tex]

==appendix ==
[http://www.lama.univ-savoie.fr/~david/ftp/paper/appendix.tex]

appendix-1 :
[http://www.lama.univ-savoie.fr/~david/ftp/paper/appendix-1.tex]

appendix-2 :
[http://www.lama.univ-savoie.fr/~david/ftp/paper/appendix-2.tex]



What appears below is the old version


Combinatory logic is another programming language related to the
lambda calculus. It is a way of coding lambda terms without using
bound variables. The coding is fair for the questions we are
concerned with, in the sense that there are translations in both
directions which, for example, preserve the property of being SN.
We have also studied this language and, surprisingly, the results
are very different from those for the lambda calculus. For example
we show that, for every fixed term t_0, almost every term possess
t_0 as a sub-term and this of course implies that almost every
term is non SN. Note that the increase of size in the translation
from the lambda calculus to combinatory logic is not known (we
only have a lower bound) and thus results for combinatory logic
cannot be used to get results for the lambda calculus.


The organization of the paper is as follows. Section ?? briefly
recalls known results for Turing machines and cellular automata.
Section ?? shows that, in combinatory logic, every fixed term
appears in almost every term. In section ?? we recall the basic
definitions of the lambda calculus and we discuss the various
possibilities for counting the size of a term and the probability
measure we put on sets of terms. Section ?? gives the
combinatorial results we will need in our proofs and, in
particular, the lower and upper bounds for the number of terms of
size n. It also introduces Catalan and Motzkin numbers and the
so-called Lambert function. Our main results, i.e. theorems ??, ??
and ?? appear in section ?? Section ?? gives experimental results
for questions for which we have no proof. Finally, section ???
gives open questions and future work. The detailed proofs are
given in an appendix.


== Known results for Turing machines and cellular automata ==
== Known results for Turing machines and cellular automata ==
Ligne 123 : Ligne 123 :
Then, we can check that
Then, we can check that


<math>\frac{1}{24n+1}-\frac{1}{12 n + 12}-\frac{1}{12n}\right = \frac{-36 n^2 - 14 n - 12}{12(24n+1)(n+1)n \geq \frac{31}{144n}</math>
<math>\frac{1}{24n+1}-\frac{1}{12 n + 12}-\frac{1}{12n} = \frac{-36 n^2 - 14 n - 1}{12(24n+1)(n+1)n} \geq -\frac{51}{288n}</math>


Thus finally <math>C(n) \geq \frac{4^n}{\sqrt{\pi} (n+1)^{\frac{3}{2}}} e^{\left(-\frac{17}{96n}\right)} \geq \frac{4^n}{\sqrt{\pi} (n+1)^{\frac{3}{2}}} e^{\left(-\frac{17}{96}\right)} </math> for all <math>n\geq1</math>.
for all <math>n\geq1</math> but also for <math>n=0</math>.


===Motzkin numbers===
===Motzkin numbers===


Let us define <math>M(n,k)</math> the number of unary-binary trees with <math>n</math> inner nodes and <math>k</math> leafs. We get
In fact, these are not usual Motzkin's numbers because in <math>M(n)</math>, <math>n</math> is the number of inner nodes while
usually, this is the total number of nodes, including leaves. The number we use are known as large Schroeder numbers.
Let us define <math>M(n,k)</math> the number of unary-binary trees with <math>n</math> inner nodes and <math>k</math> leafs.
A tree with <math>n</math> inner node <math>k</math> leafs has exactly <math>k-1</math> binary nodes and therefore <math>n-k+1</math>.
Hence we get the following formula


<center><math>M(n,k) = \frac{(n+k-1)!}{(n-k+1)!(k-1)!k!}</math></center>
<center><math>M(n,k) = C(k-1){n+k-1 \choose n-k+1} </math></center>


Then, by summing we define <math>M(n)</math> the number of unary-binary trees with <math>n</math> inner nodes and give an equivalent:
Then, by summing we define <math>M(n)</math> the number of unary-binary trees with <math>n</math> inner nodes and give an equivalent:


<center><math>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}}</math></center>
<center><math>M(n) = \sum_{k \geq 1} M(n,k) \sim \left(\frac{1}{3-2\sqrt{2}}\right)^n \frac{1}{n^\frac{3}{2}}</math></center>


===Lambert W function===
===Lambert W function===


The Lambert function <math>W(x)</math> is defined by the equation <math>x = W(x) e ^ {W(x)} </math>
The Lambert function <math>W(x)</math> is defined by the equation <math>x = W(x) e ^ {W(x)} </math>
which has a unique solution in <math>\mathbb{R}</math>.
which has a unique solution in <math>\mathbb{R}_+</math>.


For <math>x \geq e</math>, we have <math>\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x)</math> which implies that
For <math>x \geq e</math>, we have <math>\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x)</math> which implies that
Ligne 147 : Ligne 152 :
<center><math>(\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)} </math></center>
<center><math>(\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)} </math></center>


This is not precise enough for our purpose. Using one step of the Newton method from <math>\ln(x) - \ln(\ln(x))</math>, we can find a better upper bound for <math>W(x)</math> because <math>y \mapsto y e^y</math> is increasing and convex. This gives:
This is not precise enough for our purpose. Using one step of the Newton method from <math>\ln(x) - \ln(\ln(x))</math>, we can find a better upper bound for <math>W(x)</math> because <math>y \mapsto y e^y</math> is increasing and convex when <math>y \geq 0</math>. This gives for <math>x \geq e</math>:


<center><math>\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x)) + \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1}</math></center>
<center><math>\ln(x) - \ln(\ln(x)) \leq W(x) \leq \ln(x) - \ln(\ln(x)) + \frac{\ln(\ln(x))}{\ln(x) - \ln(\ln(x)) + 1}</math></center>
Ligne 311 : Ligne 316 :
And therefore, for <math>n > k</math>, using our lower bound for <math>C(n)</math> and <math>n + 1 \geq n - k + 1</math>, we get:
And therefore, for <math>n > k</math>, using our lower bound for <math>C(n)</math> and <math>n + 1 \geq n - k + 1</math>, we get:


<center><math>LB(n,k) \geq K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}}</math> with <math>K=\frac{36}{49\sqrt{\pi}}</math></center>
<center><math>LB(n,k) \geq K \frac{(4k)^{n-k+1}}{(n+1)^\frac{3}{2}}</math> with <math>K=\frac{e^{-\frac{17}{96}}}{4\sqrt{\pi}}</math></center>


Now, for <math>n</math> fixed, we define <math>f(\alpha) = \left(4n\alpha\right)^{n(1-\alpha) + 1}</math> (so <math>LB(n,k) \geq \frac{K}{(n+1)^\frac{3}{2}} f\left(\frac{k}{n}\right)</math>) and look for the maximum of this function. We have <math>f'(\alpha) = f(\alpha) \left(-n\ln(4n\alpha) +\frac{n(1-\alpha) + 1}{\alpha}\right)</math>. Thus, <math>f'(\alpha) \geq 0</math> is equivalent to <math>\frac{n+1}{n\alpha}e^{\frac{n+1}{n\alpha}}\geq 4e(n+1)</math>. The Lambert function begin increasing this means that <math>f'(\alpha) \geq 0</math> is equivalent to <math>\alpha \leq \frac{n+1}{nW(4e(n+1))}</math>. Therefore, <math>f(\alpha)</math> reaches a maximum for <math>\alpha = \frac{n+1}{nW(4e(n+1))}</math>.
Now, for <math>n</math> fixed, we define <math>f(\alpha) = \left(4n\alpha\right)^{n(1-\alpha) + 1}</math> (so <math>LB(n,k) \geq \frac{K}{(n+1)^\frac{3}{2}} f\left(\frac{k}{n}\right)</math>) and look for the maximum of this function. We have <math>f'(\alpha) = f(\alpha) \left(-n\ln(4n\alpha) +\frac{n(1-\alpha) + 1}{\alpha}\right)</math>. Thus, <math>f'(\alpha) \geq 0</math> is equivalent to <math>\frac{n+1}{n\alpha}e^{\frac{n+1}{n\alpha}}\geq 4e(n+1)</math>. The Lambert function begin increasing this means that <math>f'(\alpha) \geq 0</math> is equivalent to <math>\alpha \leq \frac{n+1}{nW(4e(n+1))}</math>. Therefore, <math>f(\alpha)</math> reaches a maximum for <math>\alpha = \frac{n+1}{nW(4e(n+1))}</math>.


This means that <math>(4k)^{n-k}</math> reaches its maximum for <math>n</math> fixed when <math>k</math>
This means that <math>(4k)^{n-k}</math> reaches its maximum for <math>n</math> fixed when <math>k</math>
is near to <math>\frac{n+1}{W(4e(n+1))}</math> which is likely not to be an integer. However, there are at least <math>\left\lfloor \frac{n (\ln(\ln(4en)) - 1)}{\ln^2(4en)}\right\rfloor</math> integer between <math>\frac{n+1}{W(4e(n+1))}</math> and <math>\frac{n+1}{\ln(4e(n+1))}</math>. Indeed, using our inequalities on Lambert W function, we have:
is near to <math>\frac{n+1}{W(4e(n+1))}</math> which is likely not to be an integer. However, there are at least <math>\left\lfloor \frac{(n+1) (\ln(\ln(4en)) - 1)}{\ln^2(4en)}\right\rfloor</math> integer between <math>\frac{n+1}{W(4e(n+1))}</math> and <math>\frac{n+1}{\ln(4e(n+1))}</math>. Indeed, using our inequalities on Lambert W function, we have:


<center><math>\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))}</math></center>
<center><math>\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))}</math></center>
Ligne 324 : Ligne 329 :
<center><math>\#(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}}</math></center>
<center><math>\#(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}}</math></center>


To simplify, using the fact that <math>\lim_{n\to +\infty}\left(\frac{\ln(n)}{\ln(4en)}\right)^n = 0</math> and taking <math>n</math> large enough, we have the following lowerbound:
To simplify, we first remove the constant <math>K</math> and the integer part by replacing the <math>\ln(\ln(4e(n+1))) - 1</math> term by any constant <math>C</math>. This means that for any constant <math>C</math>, we can take <math>n</math> large enough to have:

<center><math>\#(L_n) \geq C\frac{n+1}{\ln^2(4e(n+1))}\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}}
= C\frac{\sqrt{n+1}}{\ln^3(4e(n+1))}\left(\frac{4(n+1)}{\ln(4e(n+1))}\right)^{n-\frac{n+1}{\ln(4e(n+1))}}
</math></center>

Then, using the facts that <math>\frac{n+1}{\ln(4e(n+1))} \leq \frac{n}{\ln(n)}</math>, <math>\lim_{n\to +\infty}\frac{\ln(n)}{\ln(4e(n+1))} = 1</math> and <math>\lim_{n\to +\infty}\left(\frac{\ln(n)}{\ln(4e(n+1))}\right)^n = 0</math>, we have the following lowerbound (still for <math>n</math> large enough, with <math>C = 1</math>):


<center><math>\#(L_n) \geq \frac{\sqrt{n}}{\ln^3(n)}\left(\frac{4n}{\ln(n)}\right)^{n-\frac{n}{\ln(n)}}</math></center>
<center><math>\#(L_n) \geq \frac{\sqrt{n}}{\ln^3(n)}\left(\frac{4n}{\ln(n)}\right)^{n-\frac{n}{\ln(n)}}</math></center>
Ligne 336 : Ligne 347 :
<center><math>\#(L_n) \leq M(n) \left(\frac{n+1}{W(e(n+1))}\right)^{n-\frac{n+1}{W(e(n+1))} + 1}</math></center>
<center><math>\#(L_n) \leq M(n) \left(\frac{n+1}{W(e(n+1))}\right)^{n-\frac{n+1}{W(e(n+1))} + 1}</math></center>


The ration between our upper bound and lower bound is equivalent to (NEEDS FURTHER CHECKING):
The ration between our upper bound and lower bound is equivalent to (NEEDS FURTHER CHECKING, OR IS REMOVED because we can do better using Jakob's remark at the end of 7.2):


<center><math>\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}</math></center>
<center><math>\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}</math></center>
Ligne 342 : Ligne 353 :
=== upper and lower bounds for number of lambdas in a term of size n ===
=== upper and lower bounds for number of lambdas in a term of size n ===


Let Ls be defined as follows: lambda term of size n belongs to Ls iff it contains more than <math>\frac{3 n}{ln(n)}</math> lambdas.
Let <math>S(n,k)</math> be the number of lambda term of size n containing more than <math>\frac{k n}{ln(n)}</math> lambdas.
We search <math>k</math> such that <math>\lim_{n \rightarrow +\infty} \frac{S(n,k)}{L_n} = 0</math>.

Using the previous notation, we may write <math>S_n \leq \sum_{p \geq \frac{k n}{ln(n)}} UB(n,p)</math>. We observed that
<math>UB(n,p)</math> is decreasing in <math>p</math> if <math>p > \frac{n+1}{W(e(n+1))}</math>.

Then, we have <math>W(e(n+1)) \geq \ln(e(n+1)) - \ln(\ln(e(n+1)))</math>. Therefore, if <math>\frac{k n}{ln(n)} > \frac{n+1}{\ln(e(n+1)) - \ln(\ln(e(n+1)))}</math> (i), we have

<center><math>S(n,k) \leq M(n)\left(\frac{k n}{ln(n)}\right)^{n+1-\frac{k n}{ln(n)}}</math></center>

Then, (i) is equivalent to <math>\frac{k n}{n+1} > \frac{ln(n)}{\ln(e(n+1)) - \ln(\ln(e(n+1)))}</math> which is true for <math>n</math>
large enough if <math>k>1</math> because <math>\lim_{n \rightarrow +\infty} \frac{ln(n)}{\ln(e(n+1)) - \ln(\ln(e(n+1)))} = 1</math>.

Using our lower bound for <math>L_n</math>, we find

<center><math>\frac{S(n,k)}{L_n} \leq \frac{M(n)\left(\frac{k n}{ln(n)}\right)^{n+1-\frac{k n}{ln(n)}}}{\frac{\sqrt{n}}{\ln^3(n)}\left(\frac{4n}{\ln(n)}\right)^{n-\frac{n}{\ln(n)}}}</math></center>

We now use the fact that <math>M(n) \sim \left(\frac{1}{3-2\sqrt{2}}\right)^n \frac{1}{n^\frac{3}{2}}</math>,
for <math>n</math> large enough, we have (we introduce an extra log to compensate for the equivalent)

<center><math>\frac{S(n,k)}{L_n} \leq \frac{\ln^4(n)\left(\frac{1}{3-2\sqrt{2}}\right)^n \left(\frac{k n}{ln(n)}\right)^{n+1-\frac{k n}{ln(n)}}}{n^2\left(\frac{4n}{\ln(n)}\right)^{n-\frac{n}{\ln(n)}}}</math></center>

We get a simpler upper bound by using the <math>n^2</math> to compensate for the <math>+1</math> exponent and the remaining <math>k\frac{\ln^4(n)}{\ln(n)}</math>, which gives:

<center><math>\frac{S(n,k)}{L_n} \leq \frac{\left(\frac{1}{3-2\sqrt{2}}\right)^n \left(\frac{k n}{ln(n)}\right)^{n-\frac{k n}{ln(n)}}}{\left(\frac{4n}{\ln(n)}\right)^{n-\frac{n}{\ln(n)}}} = \left(\frac{k}{4(3-2\sqrt{2})}\right)^n \left(\frac{k n}{ln(n)}\right)^{\frac{-kn}{\ln(n)}}\left(\frac{4n}{ln(n)}\right)^{\frac{n}{\ln(n)}}</math></center>

Let us remark that <math>\left(\frac{k n}{ln(n)}\right)^{\frac{-kn}{\ln(n)}} = e^{-kn}\left(\frac{k}{ln(n)}\right)^{\frac{-kn}{\ln(n)}} </math>
and <math>\left(\frac{4n}{ln(n)}\right)^{\frac{n}{\ln(n)}} = e^{n}\left(\frac{4}{ln(n)}\right)^{\frac{n}{\ln(n)}} </math> .

Thus we have:

<center><math>\frac{S(n,k)}{L_n} \leq \left(\frac{ke^{1-k}}{4(3-2\sqrt{2})}\right)^n \left(\frac{4 k^{-k}}{ln^2(n)}\right)^{\frac{n}{\ln(n)}}</math></center>

This means that <math>\frac{S(n,k)}{L_n}</math> converges toward zero if <math>\frac{ke^{1-k}}{4(3-2\sqrt{2})} < 1</math>.
<math>ke^{1-k}</math> reaches its maximum <math>1</math> in <math>k=1</math> and <math>0 < 4(3-2\sqrt{2}) < 1</math>
This means that <math>ke^{1-k} = 4(3-2\sqrt{2})</math> has two solutions, one for <math>k > 1</math> the other for <math>k<1</math>.
Because of (i) we need to keep the first solution. It is easy to see that the first solution is smaller than 3 because
<math>3e^{1-3} < 3\frac{4}{25} < 4(3-2\sqrt{2})</math>.

Corollary. Random lambda term of size n contains asymptotically no more then <math>\frac{3 n}{ln(n)}</math> lambdas.

In the same way, we can consider lambda-terms with less than <math>\frac{k n}{ln(n)}</math> and redo exactly the same computation,
but replacing (i) by <math>\frac{k n}{ln(n)} < \frac{n+1}{\ln(e(n+1))}</math> (ii). Then we have to take <math>k</math> smaller
than the other solution of the equation, and if it easy to see that <math>k < \frac{1}{3}</math> works.

Corollary. Random lambda term of size n contains asymptotically no less then <math>\frac{n}{3 ln(n)}</math> lambdas.


Claim 1. Density of Ls equals 0.


Proof: straighforward using lower and upper bounds.


<math>Ls_n</math> denote the number of elements of Ls of size n. It is clearly smaller then <math>M(n) \cdot (\frac{3 n}{ln(n)})^{n- \frac{3 n}{ln(n)} }.</math> Dividing by the lower bound <math>LB(n,\frac{n}{ln (n)})</math>, we get <math>\frac{M(n)}{C(n-\frac{ n}{ln(n)})} \frac{(\frac{3 n}{ln(n)})^{n-\frac{3 n}{ln(n)} }}{(\frac{n}{ln(n)})^{n-\frac{ n}{ln(n)} }}</math> which tends to 0 when <math>n \rightarrow \infty.</math>


Corollary. Random lambda term of size n contains no more then <math>\frac{3 n}{ln(n)}</math> lambdas.


Once we know this we can improve the upper bound.
Once we know this we can improve the upper bound.
Ligne 357 : Ligne 409 :


<math>
<math>
Ll_n \leq C(n) {n \choose \frac{3}{ln(n)}} ((1+\epsilon) \frac{n}{ln(n)})^n</math>
Ll_n \leq C(n) {n \choose \frac{3}{ln(n)}} ((1+\epsilon) \frac{n}{ln(n)})^n
</math>


where C(n) corresponds to the binary structure, <math>{n \choose \frac{3}{ln(n)}}</math> to the possible distribtions of lambdas in binary structure and <math>((1+\epsilon) \frac{n}{ln(n)})^n</math> to the possibilities of bindings (one can optimal number of unary nodes involving Lambert's function to get rid of epsilon here). The crucial observation now is that <math>{n \choose \frac{3}{ln(n)}}</math> is '''subexponential'''.
where C(n) corresponds to the binary structure, <math>{n \choose \frac{3}{ln(n)}}</math> to the possible distribtions of lambdas in binary structure and <math>((1+\epsilon) \frac{n}{ln(n)})^n</math> to the possibilities of bindings (one can optimal number of unary nodes involving Lambert's function to get rid of epsilon here). The crucial observation now is that <math>{n \choose \frac{3}{ln(n)}}</math> is '''subexponential'''.
Ligne 387 : Ligne 440 :


Yes, since it is used in the next theorem. However, it is enough to show that for fixed integers k and k' each of k head lambdas binds at least k' variables.
Yes, since it is used in the next theorem. However, it is enough to show that for fixed integers k and k' each of k head lambdas binds at least k' variables.


[http://tcs.uj.edu.pl/~grygiel/lambdan/manyheadlambdas.pdf pdf]

[http://tcs.uj.edu.pl/~grygiel/lambdan/manyheadlambdas.tex tex]


=== every fixed closed term (including the identity !) does not appear in a random term (in fact we have much more than that) ===
=== every fixed closed term (including the identity !) does not appear in a random term (in fact we have much more than that) ===
Ligne 440 : Ligne 498 :
* in the encoding, there is some substituion of variable to do in C (to have a closed term at the end, and also to ensure that the decoding is unambiguous)
* in the encoding, there is some substituion of variable to do in C (to have a closed term at the end, and also to ensure that the decoding is unambiguous)
* to complete the proof with the new definition of "dangerous redex" we need the result saying that terms containing identity have density 0 (as said by Jakub by e-mail). We don't see how to conclude without that. However, we have to further check if there is no shorter proof...
* to complete the proof with the new definition of "dangerous redex" we need the result saying that terms containing identity have density 0 (as said by Jakub by e-mail). We don't see how to conclude without that. However, we have to further check if there is no shorter proof...



== Experiments ==
== Experiments ==

Dernière version du 7 janvier 2009 à 16:33

counting.pdf : [1] version on wednesday 07/01 at 17h30. the files below are the good ones. René



Introduction

intro : [2]


lambda

[3]

combinatorics

section 3 : [4]

generating : [5]


bounds

[6]


main results

[7]

section 5-2

[8]

section 5-2-2  : [9]


section 5-2-3  : [10]

section 5-2-4  : [11]


section 5-3

[12]

section 5-3-1  : [13]


section 5-3-2  : [14]

section 5-3-3  : [15]

section 5-3-4  : [16]

other systems

[17]

section 6.1 : [18]

section 6.2 : [19]


conclusion

[20]

section 7.1 : [21]

section 7.2 : [22]

section 7.3 : [23]

biblio

[24]

appendix

[25]

appendix-1 : [26]

appendix-2 : [27]


What appears below is the old version


Known results for Turing machines and cellular automata

In this section I propose to comment on paper [28] and [29].

Guillaume says: I am very skeptical about paper 2 by D'Abramo. I suggest to replace it by the paper by Calude and Stay [30].

Lambert function, Catalan and Motzkin numbers

Catalan numbers

  •  : Catalan numbers

Usual equivalent: which is obtained using Strirling formula. However, using stirling formula which can be extended as the following double inequality:

Thus, using this and , we have:

Then, we can check that

Thus finally for all .

Motzkin numbers

In fact, these are not usual Motzkin's numbers because in , is the number of inner nodes while usually, this is the total number of nodes, including leaves. The number we use are known as large Schroeder numbers.

Let us define the number of unary-binary trees with inner nodes and leafs. A tree with inner node leafs has exactly binary nodes and therefore . Hence we get the following formula

Then, by summing we define the number of unary-binary trees with inner nodes and give an equivalent:

Lambert W function

The Lambert function is defined by the equation which has a unique solution in .

For , we have which implies that near . To prove this, it is enough to remark that

This is not precise enough for our purpose. Using one step of the Newton method from , we can find a better upper bound for because is increasing and convex when . This gives for :

Indeed, if we define , we have and therefore, newton's method from gives a point at position:

Finally, we show that for , we have:

Indeed, for , we have , which implies and therefore .

combinatory logic

Basically the paper already written by Marek

tex file : [31]

pdf file :[32]

+ the following


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.

The translation from combinatory logic to lambda calculus is linear, i.e. there is a constant such that, for all terms, but the translation in the other direction is not linear. As far as we know, there is no known bound on the size of but it is not difficult to find exemples where is of order .

The point is that has to code the binding in some way and this takes place. It will be interesting to compare the size of with the one of using other notion of size than the usual one. See section ?? for some complement.

Generality on lambda calculus

definition

The set of lambda terms (or, simply, terms) is defined by the following grammar


To be able to define the notion of a random term we have to define a distribution law on . There are many possibilities for that. We choose here the simplest one. Note that this is the one for which, at least at present, we are able to prove some results. It is based on densities. For that we first have to define the size of a term.

The usual definition is the following.

definition

The size (denoted as ) of a term is defined by the following rules.

- if is a variable.

-

-


In the rest of the paper we will use another definition (denoted as ) which is similar but gives simpler computations. We believe (but we have not yet checked the details) that, with we would have similar results. The computation, with , of the upper and lower bounds of the number of terms of size will be done in section ??

definition

The size (denoted as or, more simply ) of a term is defined by the following rules.

- if is a variable.

-

-


These definitions of the size are, for the implementation point of view, not realistic because, in case a term has a lot of distinct variables, it is not realistic to use a single bit to code them. The usual way to implement this coding is to replace the names of variables by their so called de Bruijn indices: a variable is replaced by the number of that occur, on the path from the variable to the root, between the variable and the that binds it. Note that, in this case, different occurrences of the same variable may be represented by different indices.

Choosing the way we code these de Bruijn indices gives different other ways of defining the size of a term. This can be done in the following ways

- Use unary notation, i.e. the size of the index simply is itself

- Use optimal binary notation, i.e. the size of the index is i.e. the logarithm of in base 2.

- Use uniform binary notation, i.e. the size of an index is the logarithm, in base 2, of the number of leaves of the term.

Remark

See section ?? for a discusion about these different size.


definition

Let be an integer. We denote by the set of terms of size n.


definition

Let A be a set of terms.

1) We denote by the cardinality of A.

2) We denote by the limit, for n going to , of .

Remark

Note that d is not exactly a measure since is undefined if the previous limit does not exist

definition

Let P be a property of terms. We will say that almost every term satisfies P (this will be also stated as P holds a.e.) if

generating functions

this does not work (by now) because radius of convergence 0

no known results for the number of terms of size n (denoted )

our results

(the proof of result of section k needs the result of section (k-1))

Upper and lower bounds for

For the lower bound, we will first count the number of lambda-terms of size starting with lambdas and having no other lambda below. This means that the lower part of the term is a binary tree with inner nodes with possibility for each leaf. Therefore we have:

And therefore, for , using our lower bound for and , we get:

with

Now, for fixed, we define (so ) and look for the maximum of this function. We have . Thus, is equivalent to . The Lambert function begin increasing this means that is equivalent to . Therefore, reaches a maximum for .

This means that reaches its maximum for fixed when is near to which is likely not to be an integer. However, there are at least integer between and . Indeed, using our inequalities on Lambert W function, we have:

Thus, we get the following lowerbound for :

To simplify, we first remove the constant and the integer part by replacing the term by any constant . This means that for any constant , we can take large enough to have:

Then, using the facts that , and , we have the following lowerbound (still for large enough, with ):

We now compute an upper bound for the number of lambda-terms of size with exactly lambdas (that is with leaves using the Motzkin numbers and allowing any lambda to bind any variable (regardless of the real scope):

If we sum this for all possible and get an upper bound of using Lambert function as for the lower bound, we get the following upper bound for :

The ration between our upper bound and lower bound is equivalent to (NEEDS FURTHER CHECKING, OR IS REMOVED because we can do better using Jakob's remark at the end of 7.2):

upper and lower bounds for number of lambdas in a term of size n

Let be the number of lambda term of size n containing more than lambdas. We search such that .

Using the previous notation, we may write . We observed that is decreasing in if .

Then, we have . Therefore, if (i), we have

Then, (i) is equivalent to which is true for large enough if because .

Using our lower bound for , we find

We now use the fact that , for large enough, we have (we introduce an extra log to compensate for the equivalent)

We get a simpler upper bound by using the to compensate for the exponent and the remaining , which gives:

Let us remark that and .

Thus we have:

This means that converges toward zero if . reaches its maximum in and This means that has two solutions, one for the other for . Because of (i) we need to keep the first solution. It is easy to see that the first solution is smaller than 3 because .

Corollary. Random lambda term of size n contains asymptotically no more then lambdas.

In the same way, we can consider lambda-terms with less than and redo exactly the same computation, but replacing (i) by (ii). Then we have to take smaller than the other solution of the equation, and if it easy to see that works.

Corollary. Random lambda term of size n contains asymptotically no less then lambdas.



Once we know this we can improve the upper bound.

Let Ll be . In a term from Ll the proportion between unary and binary nodes is smaller then which is far from typical proportion in unary-binary trees which tends to some nonzero constant. Rough estimation gives

where C(n) corresponds to the binary structure, to the possible distribtions of lambdas in binary structure and to the possibilities of bindings (one can optimal number of unary nodes involving Lambert's function to get rid of epsilon here). The crucial observation now is that is subexponential.

Comparing this upper bound with we would obtain that the asymptotic ratio between upper and lower bound is subexponential.

I think it has some serious consequences. In particular it seems that in a random lambda term almost all lambdas lie on one path.

Proposition. \label{prop:typical_depth} There exists a function such that the set of terms t having a -depth greater than has density 1.

Lambdas in head position

Theorem. \label{th:starting_lambdas} Let . The set of terms t starting with less than lambdas has density 0.

Proof. By proposition \ref{prop:typical_depth}, for some function f such that , we can restrict to the set of terms t having -depth at least (because has density 1). To prove the theorem it is sufficient to exhibit a one-to-one function from into whose image set has density 0. We now define by describing where t is an arbitrary term of size n belonging to . By hypothesis, the term t starts with a chain of p -nodes, where . So where A is a term starting by an application and containing at least one (for n large enough). Now let B be the maximal purely applicative prefix of A. Precisely, B is the maximal binary tree whose leaves are either special leaves or variables among and such that where are terms starting with a lambda, and denotes the term obtained by replacing successive special leaves of B by terms respectively. By hypothesis on term t, we have . Let denote the terms obtained from by removing the leading lambda. Consider the term which is of size , where b is the number of application nodes in B. Finally, let be the set of purely applicative terms of size b whose variables are chosen among a set of size . Consider the leftmost deepmost lambda of term T (leftmost among deepmost), and let denote the term rooted at this position. For any , we define the term by subsituting with in T and binding all variables of u according to their name to lambda above u. Firstly, is a well-defined closed term because the insertion of u occurs at depth at least and u has at most different variables. Secondly, has size exactly n.

The set of binary trees with b internal nodes and leaves labelled either 'special' or by a variable among has cardinality (where denotes the Catalan number). Besides, the set has carinality . Therefore, since and , there exists a function with and a function from to subsets of such that:

  • for each , contains elements;
  • for n large enough, .

What we have established so far is the following: to term we assosiate injectively the 4-uple ; then, if u is the first element of in some arbitrary (but fixed) order, we assotiate to the term . By hypothesis on function defined above, the function is injective for n large enough. Moreover, we have so the image set of has density 0 and the theorem follows.

Head lambdas bind "many" occurrences of the corresponding variables

Theorem. \label{th:biding_lambdas} Let g and h be two functions belonging to and let be the set of terms t where the total number of occurrences of variables bound to one of the head lambdas is less than . Then has density 0.

Remark. The proof of this theorem uses arguments similar to those used in proof of theorem 'starting lambdas'. But is this theorem useful ?

Yes, since it is used in the next theorem. However, it is enough to show that for fixed integers k and k' each of k head lambdas binds at least k' variables.


pdf

tex

every fixed closed term (including the identity !) does not appear in a random term (in fact we have much more than that)

Let denote the set of lambda terms which have as a subterm and let be the set of those lambda trees in which the number of unbounded leaves (occurrences of free variables) is equal to .

Theorem

For any integers and and for any term of length the following holds:


Proof

Fix and . Let be a lambda tree of size with exactly occurrences of free variables, denoted (not necessarily distinct). Since there are at most occurrences of lambdas and at most leaves in , there are at most

such trees and we can enumerate them in a fixed way. Let be the number of . The tree contains at least one occurrence of lambda, otherwise it would either contain more free variables or would be of a bigger size.


Let be an integer satisfying .


We will construct an injective function such that its image is of density 0 in .


Let be a term of size with as its subterm. Let us consider the tree which is built from the tree by adding an additional unary node (labelled with ) at depth . Next, let be the tree obtained by replacing the subtree in by the tree , where is a binary tree of size such that and , so the size of is equal to . Thus, the size of is equal to . The variable is bound by the -th lambda in the tree . Let us take . Since is the number of the tree , the function is injective.


By Theorem \ref{?}, each of head lambdas in a random tree of size binds more than variables. Trees from the image do not have this property, since the -th lmabda binds only variables. Thus, those trees are negligible among all trees of size .

Corollary

Let be a closed lambda term. Then the density of is equal to .

Corollary

Let be a lambda term in which there are at least two occurrences of lambdas. Then the density of is equal to .


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

Random lambda terms are strongly normalizable

Sketch of the proof pdf tex

Jakub says: I think that it might be possible to simplify the proof, by using other argument for the proof that the density of the image of encoding equals 0.

Chambéry says: we checked the proof and we are convinced by the result. Since Jakub made an important step for the second time, we suggest to explicitely acknowledge his contribution in the paper (for instance, by naming some key lemma/theorems "Jakub's lemma/theorem"). Here are the points to fix in the proof:

  • as René said, the definition of "dangerous redex" must be changed to allow a single occurrence of x in A (and a proof sketch of why "no dangerous redex" implies SN must be added)
  • version 1 of encoding is sufficient
  • in the encoding, there is some substituion of variable to do in C (to have a closed term at the end, and also to ensure that the decoding is unambiguous)
  • to complete the proof with the new definition of "dangerous redex" we need the result saying that terms containing identity have density 0 (as said by Jakub by e-mail). We don't see how to conclude without that. However, we have to further check if there is no shorter proof...

Experiments

results of the experiments we have done

some experiments that have to be done : e.g. density of terms having or big Omega pattern ...

to be done

Upper and lower bounds for with other size for variables especially one, binary with fixed size

Open questions and Future work

.....