Advanced Lambda Calculus Henk Barendregt & Giulio Manzonetto ICIS Faculty of Science Radboud University Nijmegen, The Netherlands
Form of the course Ordinary lecture Seminar form Exam: working out an exercise or writing a short paper
Topics (sneak preview) Lambda calculus untyped λ Lambda Calculus with Simple types Recursive types Ordered types Intersection types where respectively A A = A, S = S,, S = S,,, λ A freely generated from A λ A = with equations A = A B λ S with inequalities A A B λ S with inequalities and intersections A (A B) B is a set of type atoms is a type algebra is a type structure is an intersection type structure λx.x : A A λx.xx : A, λx.xx : A B, λx.xx : (A (A B)) B. if A = A B if A A B
1.1 Lambda terms and calculus Lambda terms can express: Computations on numbers - on data types Infinite processes Hardware design functional programming languages like Scheme, ML, Haskell, Clean Proofs (certification) computer mathematics
1.2 Untyped lambda terms (1933) Lambda terms var ::= c var term ::= var term term λvar term Lambda calculus (λx.m)n = M[x: = N] M = M M = N N = M M = N & N = L M = L M = N MP = NP M = N PM = PN M = N λx.m = λx.n mathematical axiom logical axiom and rules We write λ M = N if M = N is provable by these axioms and rules.
1.3 Notations Notations for variables and terms x,y,z,,f,g,,f,g,, Φ, Ψ, M,N,L, Abbreviations MN 1 N n ( (MN 1 ) N n ) λx 1 x n.m (λx 1 ( (λx n.m) )) Standard terms: combinators I λx.x K λxy.x S λxyz.xz(yz) ω λx.xx Ω ωω Y λf.(λx.f(xx))(λx.f(xx)) range over V range over Λ
1.4 Reduction Def. A notion of reduction on Λ is a relation R Λ 2 Def. (i) The notion of reduction β is (ii) Write (β-contraction) β = { (λx.m)n,m[x := N] M,N Λ} M β N M,N β (iii) One step β-reduction β is the compatible closure of β, i.e. M β N M β N M β N MP β NP M β N PM β PN M β N λxm β λxn (iv) Many step β-reduction, notation β is the reflexive transitive closure of β, i.e. M β M M β N M β N M β N & N β L M β L
1.5 Reduction graphs Def. The β-reduction graph of an M Λ, notation G β (M), is {N M β N}, β i.e. the set of reducts of M directed by β Exercise. Draw G β (M) for the following terms (i) M WWW, (ii) M UU, (iii) M V V, with W λxy.xyy with U λx.ixx with V λx.i(xx) (iv) M TTx, with T λtxz.z(ttx) You get in a different order a cube, an infinite tower of cubes, an increasing chain of n-dimensional cubes with 0 n <, and an icecream cone with two scoops!
1.6 Normal forms Def. (i) A term M is said to be in β-normal form (β-nf) if for no term N one has M β N (ii) A term M has a β-nf if for some term N in nf M β N. (iii) M is β-weakly normalizing (β-wn) if there is a finite reduction path M β M 1 β M 2 β β M k (1) such that M k is in β-nf. This is equivalent to having a β-nf. (iv) M is β-strongly normalizing (β-sn) if all reduction paths as in (1) terminate in a nf. This states that there are no infinite β-reduction paths starting with M. We often leave out the prefix β- Examples. I, K, S are in nf. KISS has a nf. Ω has no nf. KIΩ is WN but not SN. It has a subterm that has no nf. (λx.(λy.i)(xx))(λx.(λy.i)(xx)) is not SN, even if each subterm is WN.
2.1 Coding & decoding terms For M 1 M n Λ define M 1,,M n λz.zm 1 M n U n i λx 1 x n.x i Then M 1,,M n U n i = M i
2.2. Coding data types (Böhm-Piperno-Guerrini) Let A = A,c,f,g be freely generated data type with c : A f : A A g : A 2 A Here free means that equations like c = g(f(c),c) are never valid. There is a categorical formulation of being free. Def. The elements of A can be represented by λ-terms c λe.eu 3 1e f λxe.eu 3 2xe g λxye.eu 3 3xye. A term like g(f(c),c) is represented by g(f(c),c) g(fc)c
2.3 General recursion Thm. Given A 1.A 2,A 3 Λ there is an F Λ such that Fc = A 1 F (1) F(fx) = A 2 xf (2) F(gxy) = A 3 xyf (3) Proof. Try F = X 0,X 1,X 2, the X to be determined In order to satisfy (1) one should have Fc = X 0,X 1,X 2 c = c X 0,X 1,X 2 = (λe.eu 3 1e) X 0,X 1,X 2 = X 0,X 1,X 2 U 3 1 X 0,X 1,X 2 = X 0 X 0,X 1,X 2 = A 1 F, by choosing X 0 λa.a 1 a. Similarly one can choose X 1, X 2 to satisfy (2), (3).
Encoding λ-terms as λ-terms Consider a data type with constructors var,app,abs Represent these in λ by var, app, abs Def. (Mogensen) x PQ varx app P Q λx.p abs(λx. P ) By the recursion principle we can find an E such that E(varx) x E(appxy) (Ex)(Ey) E(absz) λx.e(zx) Then E x x E PQ E P E Q E λx.p λx.e( P ) Therefore M Λ.E M = M
Applications of coding and E Show that for no P one has Find terms P i such that P(xy) = x P i M 1 M 2 = M i Show that F Λ M Λ.F M = M. See Barendregt [1984]. Show that Y 2 Λ F Λ.F Y 2 F = Y 2 ( F ) I am not sure whether the last two are true!