Delia KESNER IRIF, CNRS et Universit ´e Paris kesner@irif.fr www.irif.fr/˜kesner
The Untyped Lambda Calculus
Delia KESNER IRIF, CNRS et Universit ´e Paris kesner@irif.fr www.irif.fr/˜kesner
Alonzo Church (1903 - 1995)
Delia KESNER IRIF, CNRS et Universit ´e Paris kesner@irif.fr www.irif.fr/˜kesner
λ -calculus: syntax
Grammar for terms:
t, u, v ::= x (variable) | t u (application) | λx.t (abstraction) Notation :
Application is left-associative so that t
1t
2. . . t
nmeans (. . . (t
1t
2) . . . t
n) .
λx
1. . . x
n.t means λx
1. . . . λx
n.t .
Delia KESNER IRIF, CNRS et Universit ´e Paris kesner@irif.fr www.irif.fr/˜kesner
Inductive definition of λ -terms
x is a variable (Var) x is a λ -term
t is a λ -term u is a λ -term (App) t u is a λ -term
t is a λ -term x is a variable
(Lamb)
λx.t is a λ -term
Delia KESNER IRIF, CNRS et Universit ´e Paris kesner@irif.fr www.irif.fr/˜kesner
Size of λ -terms
size(x) := 1
size(uv) := 1 + size(u) + size(v)
size(λx.u) := 1 + size(u)
Delia KESNER IRIF, CNRS et Universit ´e Paris kesner@irif.fr www.irif.fr/˜kesner
Free and bound variables
λx.(z x y (λz.z y)) The set of free and bound variables are defined as follows
fv(x) : = { x } bv(x) : = ∅
fv(t u) := fv(t) ∪ fv(u) bv(t u) := bv(t) ∪ bv(u) fv(λx.t) := fv(t) \ {x} bv(λx.t) := bv(t) ∪ {x}
But for t = x (λx.x)
fv(x (λx.x)) = {x} = bv(x (λx.x))
A term is closed iff fv(t) = ∅ .
Delia KESNER IRIF, CNRS et Universit ´e Paris kesner@irif.fr www.irif.fr/˜kesner
Alpha-conversion
The relation =
α, usually called renaming or alpha-conversion, is inductively defined as:
y is a fresh variable λx.t =
αλy.t[x\\y]
t=
αt
0λx.t=
αλx.t
0t=
αt
0u=
αu
0t u=
αt
0u
0where the operation t[x\\y] denotes the replacement of all the free occurrences of x in t by a fresh variable y . Formally,
x[x\\y] : = y
z[x\\y] := z x , z
(t u)[x\\y] := t[x\\y] u[ x\\y]
(λx.t)[x \\ y] : = λx.t
(λz.t)[x\\y] := λz.t[x\\y] x , z
Delia KESNER IRIF, CNRS et Universit ´e Paris kesner@irif.fr www.irif.fr/˜kesner
Examples
λx.(λx.x z) =
αλy.(λx.x z) =
αλy.(λy.y z)
x (λx.x) =
αx (λz.z)
Delia KESNER IRIF, CNRS et Universit ´e Paris kesner@irif.fr www.irif.fr/˜kesner
Barendregt variable convention
From now on we assume the following variable convention:
1
No variable is both free and bound.
2
Bound variables have all different names.
Example
x (λz.z) is OK, x (λx.x) is not OK, λx.λy.x z is OK but λx.λx.x z is not OK.
Theorem
For every λ -term t there is λ -term u verifying the Barendregt convention such that t =
αu .
Indeed, x (λx.x) =
αx (λz.z) and λx.λx.x z =
αλy.λx.x z .
Delia KESNER IRIF, CNRS et Universit ´e Paris kesner@irif.fr www.irif.fr/˜kesner
Operational semantics of λ -calculus
A one-step β -reduction is given inductively by
(λx.t) u →
βt{x\u}
t →
βt
0λx.t →
βλx.t
0t →
βt
0t u →
βt
0u
u →
βu
0t u →
βt u
0What is exactly { \ } ?
Delia KESNER IRIF, CNRS et Universit ´e Paris kesner@irif.fr www.irif.fr/˜kesner
Towards a notion of substitution: warning!
(λx.(λy.x)) y →
β(λy.x){x\y} = λy.y Incorrect
(λx.(λy.x)) y =
α(λx.(λz.x)) y →
β(λz.x){ x\y} = λz.y
Correct
Delia KESNER IRIF, CNRS et Universit ´e Paris kesner@irif.fr www.irif.fr/˜kesner
A simple notion of higher-order substitution
t{x/u} means replace all the free occurrences of x in t by u . This operation is defined modulo α -conversion as follows:
x{x/u} := u
y { x/u } : = y
(λy.v){x/u} := λy.v{x/u} if x , y and y < fv(u) (no capture holds)
(t v){x/u} := (t{x/u} v{x/u})
Delia KESNER IRIF, CNRS et Universit ´e Paris kesner@irif.fr www.irif.fr/˜kesner
A terminating β -reduction sequences
(λx.λ f.x f y) (λz.z) (λw.w w) →
β(λ f.x f y) { x \ λz.z } (λw.w w) = (λ f.(λz.z) f y) (λw.w w) →
β(λ f. f y) (λw.w w) →
β( f y){ f \λw.w w} =
(λw.w w) y →
β(w w) { w \ y } =
(y y)
Delia KESNER IRIF, CNRS et Universit ´e Paris kesner@irif.fr www.irif.fr/˜kesner
A non terminating β -reduction sequences
Let ∆
f= λx. f (x x) .
∆
f∆
f→
β( f (x x)){x\ ∆
f} =
f (∆
f∆
f) →
βf ( f (x x)){ x\ ∆
f} =
f ( f ( ∆
f∆
f)) →
β.. .
Delia KESNER IRIF, CNRS et Universit ´e Paris kesner@irif.fr www.irif.fr/˜kesner
Expressivity
Arithmetic.
Booleans.
Recursion.
The λ -calculus is Turing complete.
Delia KESNER IRIF, CNRS et Universit ´e Paris kesner@irif.fr www.irif.fr/˜kesner
Properties of λ -calculus
[Free variables decrease] If t →
βt
0, then f v(t) ⊇ f v(t
0) .
Example
In t
0= (λx.x)(λz.zz) →
βλz.zz = t
1we have fv(t
0) = fv(t
1) .
In t
0= (λx.y)(zz) →
βy = t
1we have fv(t
0) ⊇ fv(t
1) .
Delia KESNER IRIF, CNRS et Universit ´e Paris kesner@irif.fr www.irif.fr/˜kesner