• Aucun résultat trouvé

The Untyped Lambda Calculus

N/A
N/A
Protected

Academic year: 2022

Partager "The Untyped Lambda Calculus"

Copied!
17
0
0

Texte intégral

(1)

Delia KESNER IRIF, CNRS et Universit ´e Paris kesner@irif.fr www.irif.fr/˜kesner

The Untyped Lambda Calculus

(2)

Delia KESNER IRIF, CNRS et Universit ´e Paris kesner@irif.fr www.irif.fr/˜kesner

Alonzo Church (1903 - 1995)

(3)

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

1

t

2

. . . t

n

means (. . . (t

1

t

2

) . . . t

n

) .

λx

1

. . . x

n

.t means λx

1

. . . . λx

n

.t .

(4)

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

(5)

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)

(6)

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) = ∅ .

(7)

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

0

t=

α

t

0

u=

α

u

0

t u=

α

t

0

u

0

where 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

(8)

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)

(9)

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 .

(10)

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

0

t →

β

t

0

t u →

β

t

0

u

u →

β

u

0

t u →

β

t u

0

What is exactly { \ } ?

(11)

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

(12)

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})

(13)

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)

(14)

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

)) →

β

.. .

(15)

Delia KESNER IRIF, CNRS et Universit ´e Paris kesner@irif.fr www.irif.fr/˜kesner

Expressivity

Arithmetic.

Booleans.

Recursion.

The λ -calculus is Turing complete.

(16)

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

1

we have fv(t

0

) = fv(t

1

) .

In t

0

= (λx.y)(zz) →

β

y = t

1

we have fv(t

0

) ⊇ fv(t

1

) .

(17)

Delia KESNER IRIF, CNRS et Universit ´e Paris kesner@irif.fr www.irif.fr/˜kesner

Properties of λ -calculus

[Confluence] The reduction relation →

β

is confluent.

Proof.

By Tait-Martin-Lo ¨ef technique (on blackboard).

Références

Documents relatifs

Arnaud Sangnier IRIF - Universit´e de Paris.

Delia Kesner et Giovanni Bernardi IRIF, Université Paris-Diderot. Emails : kesner@irif.fr

dénitions inductives, principe d'induction bien fondée, preuves par induction, ordres bien fondés.. Calcul

dénitions inductives, principe d'induction bien fondée, preuves par induction, ordres bien fondés.. Calcul

Delia KESNER IRIF, CNRS et Universit ´e Paris kesner@irif.fr www.irif.fr/˜kesner.. S ´emantique des langages

Delia KESNER IRIF, CNRS et Universit ´e Paris kesner@irif.fr www.irif.fr/˜kesner..

Delia KESNER IRIF, CNRS et Universit ´e Paris kesner@irif.fr www.irif.fr/˜kesner.. Typed

Delia KESNER IRIF, CNRS et Universit ´e Paris kesner@irif.fr www.irif.fr/˜kesner.. Term Algebras and