A natural counting of lambda terms Maciej Bendkowski Theoretical Computer Science Jagiellonian University joint work with Katarzyna Grygiel, Pierre Lescanne and Marek Zaionc FIT 2016 Warsaw, February 2016 Bendkowski, Grygiel, Lescanne, Zaionc A natural counting of lambda terms
Motivations Combinatorics – design new methods for counting 1 structures with binders and local scopes, Computer Science – develop tools for random λ -term 2 generation used in software testing (see, e.g. Quickcheck), Computational Logic – study quantitative aspects of 3 semantic properties in λ -calculus and related systems, . . . 4 Bendkowski, Grygiel, Lescanne, Zaionc A natural counting of lambda terms
Natural size notion λ λ @ @ λ 0 @ λ 0 0 2 λ x . (( λ y . y ) x )( λ z . z ( λ w . x )) λ (( λ 0)0)( λ 0( λ 2)) | t | = 13 Bendkowski, Grygiel, Lescanne, Zaionc A natural counting of lambda terms
Natural counting of λ -terms L ∞ = L ∞ L ∞ � λ L ∞ � D D = S D � 0 · � z L ∞ ( z ) = zL 2 ∞ ( z ) + zL ∞ ( z ) + 1 − z √ L ∞ ( z ) = (1 − z ) 3 / 2 − 1 − 3 z − z 2 − z 3 2 z √ 1 − z Bendkowski, Grygiel, Lescanne, Zaionc A natural counting of lambda terms
Asymptotic approximation of ([ z n ] L ∞ ) n ∈ N Theorem (B, Grygiel, Lescanne, Zaionc) The asymptotic approximation of the number of λ -terms of size n is given by [ z n ] L ∞ ∼ (3 . 38298 . . . ) n C C . 3 / 2 , where = 0 . 60676 . n Bendkowski, Grygiel, Lescanne, Zaionc A natural counting of lambda terms
Holonomic presentation of L ∞ √ L ∞ ( z ) = (1 − z ) 3 / 2 − 1 − 3 z − z 2 − z 3 2 z √ 1 − z � Maple: package gfun z 3 + z 2 − 2 z +( z 3 +3 z 2 − 3 z +1) L ∞ +( z 5 +2 z 3 − 4 z 2 + z ) L ′ ∞ = 0 . Bendkowski, Grygiel, Lescanne, Zaionc A natural counting of lambda terms
Computing L ∞ , n ’Holonomic’ recursion for L ∞ , n L ∞ , 0 = 0 , L ∞ , 1 = 1 , L ∞ , 2 = 2 , L ∞ , 3 = 4 , ( n + 1) L ∞ , n = (4 n − 1) L ∞ , n − 1 − (2 n − 1) L ∞ , n − 2 − L ∞ , n − 3 − ( n − 4) L ∞ , n − 4 . Bendkowski, Grygiel, Lescanne, Zaionc A natural counting of lambda terms
λ -terms with bounded number of free indices L m = L m L m � λ L m +1 � D m D m = { 0 , 1 , . . . , m-1 } � � L m +1 ( z ) + 1 − z m 1 − 4 z 2 � � 1 − 1 − z L m ( z ) = 2 z Bendkowski, Grygiel, Lescanne, Zaionc A natural counting of lambda terms
λ -terms with bounded number of free indices L m = L m L m � λ L m +1 � D m D m = { 0 , 1 , . . . , m-1 } � � L m +1 ( z ) + 1 − z m 1 − 4 z 2 � � 1 − 1 − z L m ( z ) = 2 z L m is expressed by means of infinitely nested radicals! Bendkowski, Grygiel, Lescanne, Zaionc A natural counting of lambda terms
Counting λ -terms containing fixed subterms Theorem (B, Grygiel, Lescanne, Zaionc) For an arbitrary fixed term M, asymptotically almost all λ -terms contain M as a subterm. Bendkowski, Grygiel, Lescanne, Zaionc A natural counting of lambda terms
Counting λ -terms containing fixed subterms Theorem (B, Grygiel, Lescanne, Zaionc) For an arbitrary fixed term M, asymptotically almost all λ -terms contain M as a subterm. Proof sketch T M = M � λ T M � T M L ∞ � L ∞ T M � T M T M . 1 Consider L ∞ ( z ) − T M ( z ). Show that it has density 0. 2 Bendkowski, Grygiel, Lescanne, Zaionc A natural counting of lambda terms
Counting λ -terms containing fixed subterms - cnd. Theorem (B, Grygiel, Lescanne, Zaionc) Asymptotically almost no λ -term is strongly normalizing. Bendkowski, Grygiel, Lescanne, Zaionc A natural counting of lambda terms
The sequence ([ z n ] L ∞ ) n ∈ N The sequence ([ z n ] L ∞ ) n ∈ N is known as A105633 in Online Encyclopedia of Integer Sequences ( http://oeis.org )! 0, 1, 2, 4, 9, 22, 57, 154, 429, 1223, 3550, 10455, 31160, 93802, 284789, 871008, 2681019, 8298933, 25817396,. . . Bendkowski, Grygiel, Lescanne, Zaionc A natural counting of lambda terms
E -free black-white binary trees Black-white binary trees ( A105633 ) A 1 = { • • ◦ ◦ • } , , , , 1 ◦ • ◦ Roots are black. 2 � BW • ( z ) = z + zBW • ( z ) + zBW ◦ ( z ) BW ◦ ( z ) = z + zBW ◦ ( z ) + zBW • ( z ) + zBW ◦ ( z ) BW • ( z ) Bendkowski, Grygiel, Lescanne, Zaionc A natural counting of lambda terms
Bijection between λ -terms and black-white trees LtoBw BwtoL · · 0 − − − → • • − − − → 0 LtoBw BwtoL LtoBw( n ) T S n − − − → − − − → S BwtoL( T ) • • LtoBw BwtoL LtoBw( M ) T − − − → − − − → λ BwtoL( T ) λ M ◦ ◦ LtoBw( M 2 ) T 2 LtoBw BwtoL M 1 M 2 − − − → − − − → BwtoL( T 1 ) BwtoL( T 2 ) ◦ ◦ LtoBw( M 1 ) T 1 Bendkowski, Grygiel, Lescanne, Zaionc A natural counting of lambda terms
Example • • λ • ◦ λ @ ◦ ◦ • @ ⇔ λ ◦ 0 @ λ ◦ • 0 0 ◦ 2 • ◦ Bendkowski, Grygiel, Lescanne, Zaionc A natural counting of lambda terms
Binary trees without zigzags Zigzag-free binary trees ( A105633 ) × × × � BZ 1 = × � BZ 2 BZ 1 × × BZ 2 = × � � BZ 2 BZ 2 BZ 1 Bendkowski, Grygiel, Lescanne, Zaionc A natural counting of lambda terms
Binary trees without zigzags - continued Theorem (B, Grygiel, Lescanne, Zaionc) There exists a computable (linear) bijection between black-white and zigzag-free trees and thus between λ -terms and zigzag-free trees. Bendkowski, Grygiel, Lescanne, Zaionc A natural counting of lambda terms
References (2016) A natural counting of lambda terms. 1 Bendkowski, Grygiel, Lescanne and Zaionc. In proceedings of SOFSEM 2016, LNCS vol. 9587 pp 183-194. Bendkowski, Grygiel, Lescanne, Zaionc A natural counting of lambda terms
Thank you! Questions & Answers Bendkowski, Grygiel, Lescanne, Zaionc A natural counting of lambda terms
Recommend
More recommend