• Aucun résultat trouvé

Typed Lambda Calculus

N/A
N/A
Protected

Academic year: 2022

Partager "Typed Lambda Calculus"

Copied!
62
0
0

Texte intégral

(1)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Typed Lambda Calculus

(2)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Motivations

Partial specification of programs Avoid meaningless programs (1+true) Avoid memory violation

Avoid programs with undefined semantics

(3)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Contents

Monomorphic Types Church-style Curry-style

Type Inference

Polymorphic Types Church-style Curry-style

Type Inference

(4)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Simply Typed Lambda Calculus

(5)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Curry-Howard Isomorphism

Logical systemLanguage

Propositions ⇔ Types

Proofs ⇔ Programs

Proof normalisation ⇔ Program Evaluation

(6)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Curry’58, Howard’68

(7)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Adding (simply) types to λ -calculus

Grammar for types:

A,B::= b (base types) |

A→B (functional types)

Example :

int→bool bool→(bool→int) (bool→bool)→int

Remark

→is right-associative,e.g.A1→A2→A3abbreviatesA1→(A2→A3). Every typeAcan be written asA1→. . .→An→b, whereA1, . . . ,An(n≥0)are arbitrary types andbis a base type.

The standard order between types is given by A<A→BandB<A→B.

Thus base types are minimal with respect this order.

In a typed framework substitutions are always well-typed, i.e,t{x\u}means thatx anduhave the same type.

(8)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Typing Environment

Atyping environmentΓis afinitefunction from variables to types, usually written x1:A1, . . . ,xn:An.

Thus for example,x:A,y:Bandy:B,x:Aare two different notations for the same typing environment.

ThedomainofΓ =x1:A1, . . . ,xn:An, writtendom(Γ), is the set{x1, . . . ,xn}. We writeΓ,x:Afor the typing environment extendingΓwith the pairx:A. It is only defined iffx<dom(Γ).

(9)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Typed Lambda Calculus in Church-Style

Γ,x:A`x:A (ax) Γ,x:A`t:B

Γ`λx:A.t:A→B (→i) Γ`t:A→B Γ`u:A Γ`t u:B (→e)

We can also add constants: each constantchas an associated typeTC(c) :A.

Γ`c:TC(c) We can also add the let constructor:

Γ`t:A Γ,x:A`u:B Γ`letx:A=tinu:B

We denote byΓ`Ct:Athe derivability/typing relation. We say thattistypablein Church-Style iff there isΓandAsuch thatΓ`Ct:A.

Remark:Γ`t:Adenotes a sequent not a derivation!

(10)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Examples

Example of typable term in an empty environment:

y:A→A`y:A→A

`λy:A→A.y: (A→A)→(A→A)

x:A`x:A

`λx:A.x:A→A

`(λy:A→A.y)(λx:A.x) :A→A Example of typable term in a non-empty environment:

ci:int→int`ci:int→int

ci:int→int`ci:int→int ci:int→int`3 :int ciint→int`ci3 :int

ci:int→int`ci(ci3) :int Example of non-typable term:λx.xx.

(11)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Typed Properties

[Unicity]: IfΓ`Ct:AandΓ`Ct:B, thenA≡B.

Proof.

By induction ont.

[Weakening and Strengthening]: LetΓ ={x:B|x∈fv(t)}andΓ⊆∆1⊆∆2. Then∆1`Ct:Aiff∆2`Ct:A.

Proof.

By induction ont.

[Subject Reduction] IfΓ`Ct:Aandt→β t0, thenΓ`Ct0:A.

Proof.

By induction onΓ`Ct:A(blackboard).

(12)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Typing Algorithm

Type(Γ,c) =TC(c)

Type(Γ,x) =A ifx:A∈Γ

Type(Γ, λx:A.t) =A→B ifType((Γ,x:A),t)=B

Type(Γ,t u) =B ifType(Γ,t)=A→BandType(Γ,u)=A Type(Γ,letx:A=tinu) =B ifType(Γ,t)=AandType((Γ,x:A),u)=B Type(Γ,t) =error otherwise

(13)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Properties of the Typing Algorithm

[Termination]

For every termtand every environmentΓ, the callType(Γ,t)terminates.

[Soundness]

IfType(Γ,t)=A, thenΓ`Ct:A. [Completeness]

IfΓ`Ct:A, thenType(Γ,t)=A. Said differently:

IfType(Γ,t)=erreur, thentis not typable inΓ.

(14)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Typed Lambda Calculus in Curry-Style

Γ,x:A`x:A (ax) Γ,x:A`t:B

Γ`λx.t:A→B (→i) Γ`t:A→B Γ`u:A Γ`t u:B (→e)

We can also add constants: each constantchas an associated typeTC(c) :A.

Γ`c:TC(c) We can also add lets:

Γ`t:A Γ,x:A`u:B Γ`letx=tinu:B

We denote byΓ`λt:Athe derivability/typing relation. We say thattistypablein Curry-Style iff there isΓandAsuch thatΓ`λt:A.

(15)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Properties

Unicitydoes not hold anymore:

`λλx.x:int→int `λλx.x:bool→bool The identity function behaves in the same way forintandbool:

Polymorphism

(16)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Difficulties for a Typing Algorithm

Type(Γ, λx.t)=A→B i f there existsAs.t.Type((Γ,x:A),T)=B Type(Γ,letx=tinu)=B i f there existsAs.t.Type(Γ,t)=Aand

Type((Γ,x:A),u)=B

(17)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Monomorphic Type Inference

Thetype inference problemfor a termt:∃Γ∃Asuch thatΓ`λt:A?

(18)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Towards a Monomorphic Type Inference Algorithm

General Technical Tools:

We consider a table oftypes for constants, calledT C. E.g.T C(3)=intand T C(ci)=int→int.

Lettbe a term. For each sub-termuoftwe introduce a type variableαu. We associate to every termta set of equationsS E(t)={α1u1, . . . , αmum}. The solution to the type inference problem for the termtwill be given by themost general unifier(mgu) of the corresponding set of equations.

t S E(t)

x {αtαx}

c {αtT C(c)}

u v {αuαv→αt} ∪S E(u)∪S E(v) λx.u {αtαx→αu} ∪S E(u)

letx=uinv {αtαvxαu} ∪S E(u)∪S E(v)

(19)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Examples

t0:=λf.λg.f g

S E(t0)={αt0αf →αλg.f g, αλg.f gαg→αf g, αf αg→αf g, αf αf, αgαg} The mgu ofS E(t0)is the substitutionσt0such thatσt0t0)=(αg→αf g)→(αg→αf g).

t0is typable withinstances ofσt0t0)which are types of the form(A→B)→(A→B), for any arbitrary typesAandB.

t1:=let f=λx.xin f(f z)

S E(t1)={αt1αf(f z), αf αλx.x, αλx.xαx→αx, αxαx, αf αf z→αf(f z), αf αf, αf αz→αf z, αzαz}

The mgu ofS E(t1)is the substitutionσt1such thatσt1t1)=αf(f z). t1is typable withinstances ofσt1t1)which are arbitrary typesA.

(20)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Properties of the Type Inference Algorithm

Theorem

(Soundness)Ifσis a solution ofS E(t), thentis (Curry) typable. Moreover,

∆`λt:σ0t), where∆ ={x:σ0x)|x∈fv(t)}andσ0is an instance ofσ.

Theorem

(Completeness)Iftis (Curry) typable, thenS E(t)admits a solution.

Theorem

(Principality)Iftis (Curry) typable, i.e.∆`λt:A, thenAis an instance of the principal type (i.e.A=σ0(σ(αt))), whereσis the mgu of systemS E(t)andσ0is a substitution.

(21)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Polymorphic Lambda Calculus

(22)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Motivations

General behaviour of an operator, i.e. without looking at the particular nature (or type) of its parameters.

More clear and concise programs.

Reutilisation of operators.

(23)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Different Forms of Polymorphism

Ad-hoc polymorphisme (overloaded constructors), originally described by Strachey.

Subtyping polymorphism, introduced by Wegner and Cardelli: SiΓ`t:A→B, Γ`u:A0etA0≤Aalorstu:B.

Parametric polymorphism, introduced by Reynolds and Girard.

(24)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Parametric Polymorphism

Motivation:

Many indentity functions:

Idint :int→int,Idbool:bool→bool,Idint→int: (int→int)→(int→int), . . . Many functions to add an element to a list:

A jint:int→list(int)→list(int),A jbool:bool→list(bool)→list(bool), . . . Idea:

Id:∀α.α→α and thus:

Idint =Id[int]

Idbool=Id[bool]

Idint→int=Id[int→int]

RemarkThe key idea is theinstantiationrelation between the general typeα, and the particular used typesint,bool,int→int.

(25)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Girard-Reynolds Polymorphism

Types:A::=b|α|A→A|∀α.A Notation :∀α.∀β.A=∀(α, β).A. Expressions:

t::= x|c|t t|

λx:A.t|letx:A=tint| t[A]|Λαt

Reduction Rules:

(λx:A.t)u → t{x\u}

letx:A=uint → t{x\u}

(Λαt)[A] → t{α\A} Reduction Rules:

LetId= Λαλx:α.x

Id[int] → λx:int.x (Id[int]) 3 → (λx:int.x) 3→ 3

(26)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Type Free Variables

By induction on types:

tfv(b) = ∅

tfv(α) = {α}

tfv(∀α.A) = tfv(A)\ {α}

tfv(A→B) = tfv(A)∪tfv(B) A typeAisclosedifftfv(A)=∅.

Example :tfv(β→(∀α.α→γ))={β, γ}and∀α.∀β.(α→β)is closed.

(27)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Polymorphic Lambda Calculus in Church-Style (Girard)

The same rules used for monomorphic Church-style plus:

Γ`t:A α<tfv(Γ) Γ`Λαt:∀α.A

Γ`t:∀α.A Γ`t[B] :A{α\B}

wheretfv(Γ) :=S

x∈Γtfv(Γ(x))is the set oftype free variablesofΓ. We denote byΓ`Gt:Athe derivability/typing relation.

Example :

x:α`x:α

`λx:α.x:α→α

`Λαλx:α.x:∀α.(α→α)

`(Λαλx:α.x)[int] :int→int `3 :int

`((Λαλx:α.x)[int]) 3 :int

(28)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Polymorphic Type Inference

Theorem

(Schubert)The inference problem in Girard system isundecidable.

Idea to become decidable:to restrict the grammar of types.

(29)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

ML Polymorphism

Type matrix:M::=b|α|M→M ML Type:S::=∀α1. . . .∀αn.M

A type matrix is a particular case of type.

Type for constants:

T C(+) : int→int→int T C(fst) : ∀α∀β.(α→β)→α T C(snd) : ∀α∀β.(α→β)→β T C(ifthenelse) : ∀α.(bool→α→α)→α T C(fix) : ∀α.(α→α)→α

(30)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Type Instance

Definition

An ML typeAis an instance of an ML type∀α1. . . .∀αn.B, writtenA≤ ∀α1. . . .∀αn.Biff there existC1, . . . ,Cns.t.A=B{α1, . . . , αn\C1, . . . ,Cn}.

In particular, forn=0, we haveA≤BiffA≡B. Example :

int→int ≤ ∀α.α→α

bool→int ≤ ∀α.∀β.α→β

bool→int ∀α.α→α

∀β.int→β ≤ ∀α.∀β.α→β

∀β.(β→β)→ ∀β.(β→β) ∀α.α→α

(31)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Type Generalization

Definition

TheGenoperator is given byGen(A,Γ)=∀α1. . . .∀αn.A, where each variableαiis free in Abut not inΓ, ı.e. foralli=1. . .n, we haveαi∈tfv(A)\tfv(Γ).

Example :LetA=α→βandΓ=x:β,y:∀α.α. ThenGen(A,Γ)=∀α.α→β.

(32)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Polymorphic Lambda Calculus in Curry-Style

A≤Γ(x) Γ`x:A

A≤T C(c) Γ`c:A Γ`t:A→B Γ`u:A

Γ`t u:B

Γ,x:A`t:B Γ`λx.t:A→B Γ`u:A Γ,x:Gen(A,Γ)`t:B

Γ`letx=uint:B

We denote byΓ`MLt:Athe derivability/typing relation.

(33)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Example

LetA=∀α.α→α

y:α`y:α

`λy.y:α→α

int→int≤A

f:A` f:int→int f :A`1 :int f :∀α.α→α` f1 :int

`let f=λy.yin f1 :int

(34)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Properties

[Substitution]:

IfΓ,x:∀α1. . . .∀αn.B`MLt:AandΓ`MLu:B, thenΓ`MLt{x\u}:A.

[Subject Reduction]:

IfΓ`MLt:Aandt→ t0, thenΓ`MLt0:A.

(35)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Polymorphic Type Inference

Lett:=letx=λy.yinx. Let consider the set of equations:

tαx, αxGen(αλy.y,∅), αλy.yαy→αy}

If we treat the second equation we obtainαx≡ ∀αλy.yλy.y, which isincorrect sinceαx

should be a functional type (an arrow).

(36)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Towards a Type Inference Algorithm: Notations

LetΓ =x1:A1, . . . ,xn:Anbe an environment and letσbe a type substitution. then σ(Γ)=x1:σ(A1), . . . ,xn:σ(An).

We noteinst(∀α1. . . .∀αn.A)the typeA{α1, . . . , αn1, . . . , βn}, whereβ1, . . . , βnarefresh variables.

(37)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Damas-Milner-Tofte Algorithm

Input: an environmentΓand a termts.t.fv(t)⊆Γ.

Output: an ML typeAand a type substitutionσs.t.σ(Γ)`MLt:A(idis the empty type substitution).

W((∆,x:A),x) = (inst(A),id)

W(∆,c) = (inst(T C(c)),id)

W(∆,λx.u) = (ρBx)→B, ρB)

whereW((∆,x:αx),u)=(B, ρB)andαxis a fresh variable

W(∆,u v) = (µ(α), µ◦ρC◦ρB)

whereW(∆,u)=(B, ρB),W(ρB(∆),v)=(C, ρC), αis a fresh variable andµ=mgu{ρC(B)C→α} W(∆,letx=uinv) = (C, ρC◦ρB)

whereW(∆,u)=(B, ρB)andW((ρB(∆),x:Gen(B, ρB(∆))),v)=(C, ρC)

(38)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Premier exemple

W(∅, λx.∗4x)=(int→int,{α/int→int, β/int, αx/int})

W(x:αx,∗4x)=(int,{α/int→int, β/int, αx/int}), computesmgu{int→intαx→β} W(x:αx,∗4)=(int→int,{α/int→int}), computesmgu{int→int→intint→α}

W(x:αx,∗)=(int→int→int,id) W(x:αx,4)=(int,id)

W(x:αx,x)=(αx,id)

Then∅ `MLλx.∗4x:int→int.

(39)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Second Example

W(∅,let f =λx.xinf2)=(int,{β/int, γ/int}) W(∅, λx.x)=(αx→αx,id)

W(x:αx,x)=(αx,id)

W(f:∀αxx→αx,f2)=(int,{β/int, γ/int}), wheremgu{β→βint→γ}={β/int, γ/int}

W(f:∀αxx→αx,f)=(β→β,id) W(f:∀αxx→αx,2)=(int,id)

Then∅ `MLlet f=λx.xin f2 :int.

(40)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Properties of the Type Inference Algorithm

Theorem

(Soundness)IfW(∆,t)=(A, σ), thenσ(∆)`MLt:A.

Theorem

(Completeness)Let∆ =x1!, . . . ,xnnwherefv(t)⊆ {x1, . . . ,xn}. Letτbe a type substitution, Ifτ(∆)`MLt:B, thenW(∆,t)=(A, σ), whereBis an instance ofAandτis an instance ofσ.

Corollary :∅ `MLt:AiffW(∅,t)=(B, σ)andAis an instance ofB.

(41)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Strong Normalization of Simply Typed

Lambda Calculus

(42)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Typed Properties

[Strong Normalization] Everysimply typedterm is normalising:

ifΓ`λt:A, thent∈S Nβ.

(43)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Defining Strongly Normalizing Terms

t∈S Nβ

iff there is no infiniteβ-reduction sequence starting att. t∈S Nβ

iff everyβ-reduction sequence starting attis finite.

Firstinductive alternative:

Iftis aβ-normal form, thent∈S N

If∀t0[(t→β t0)impliest0∈S N], thent∈S N (the first line is a special case of the second one) Secondinductive alternative:

t1, . . . ,tn∈S Nimpliesx~t=x t1 . . .tn∈S N.

t∈S Nimpliesλx.t∈S N.

t{x\u}~r∈S Nandu∈S Nimplies(λx.t)u~r∈S N.

In both cases one shows that t∈S Nifft∈S Nβ .

Definition (Measuring

S Nβ

-terms)

Givent∈S Nβ, we define themeasureµβ(t)asmax{n∈IN| t→nβt0}.

Note thatt→β t0impliesµβ(t0)< µβ(t), so thatt∈S Nβandt→β t0impliest0∈S Nβ.

(44)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Some General Remarks About S N

β

-Terms

u∈S Nβiffλy.u∈S Nβ.

u1, . . . ,un∈S Nβiffx u1. . .un∈S Nβ.

In general, ift∈S Nβ, then every subterm oftis alsoS Nβ. but the converse is not true, e.g.(λx..xx)(λx..xx).

This is becauseS Nβis not stable by substitution. Example:x x∈S Nβ,λy.y y∈S Nβ, but(x x){x\λy.y y}= ∆ ∆<S Nβ.

(45)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

First Proof of the SN property

This first proof is due to Tait.

Uses thefirstalternative definition ofS Nβ

It is based on a predicateS Cto characterizestrong computableterms.

Definition

Lettbe of typeA=A1→. . .→An→τ. Thent∈S Ciff forallui∈S Cof typeAiwe havet~u=t u1. . .un∈S Nβ.

The previous definition implies

1 S C⊆S Nβ.

2 S Cis closed underβ(i.e.t∈S Candt→β t0impliest0∈S C).

3 x∈S Cfor every variablex(using 1).

(46)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Lemma

Ift,u1, . . . ,un(n≥1)∈S Nβandt{x\u1}u2. . .un∈S Nβ, then(λx.t)u1u2. . .un∈S Nβ.

Proof.

By the first alternative definition ofS Nβ, it is sufficient to show thatallthe reducts of (λx.t)u1. . .unare inS Nβ. We reason byinductiononµ(t)+ Σiµ(ui). Case analysis on the reducts:

(λx.t0)u1. . .un, wheret→ t0. Thenµ(t0)< µ(t), we conclude by thei.h.

(λx.t)u1. . .u0i. . .un, whereui→ u0i. Thenµ(u0i)< µ(ui), we conclude by thei.h.

t{x\u1}u2. . .un. We conclude by the hypothesis.

(47)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Lemma

Lettbe a typed term. Letσbe a type preserving substitution mapping all the free variables oftto terms inSC. Thentσ∈S C.

Proof.

We proceed byinductionon the typed termt. Ift=x, thenxσ=σ(x)∈S Cby hypothesis.

Ift=uv, then let~r∈S C. We haveuσandvσinS Cbyi.h.Then (uv)σ~r=uσvσ~r∈S Nβby definition.

Ift=λx.u, then(λx.u)σ=αλx.uσ. Sinceσ∪ {x\x}verifies the hypothesis of the lemma, then by thei.h.u(σ∪ {x\x})=uσ∈S C⊆S Nβ. To showλx.uσ∈S Cwe show(λx.uσ)~r∈S Nβfor~r∈S C⊆S Nβ. This follows from the previous lemma.

(48)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Lemma

Every typed term is inS C.

Proof.

Using the previous lemma with the identity substitution (which verifies the hypothesis of

the current lemma).

(49)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Theorem

Every typed term is inS Nβ.

Proof.

Using the previous lemma and the fact theS C⊆S Nβ.

(50)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Second proof of the SN property

Can be found in Femke van Raamsdonk’s Thesis.

Uses thesecondalternative definition ofS Nβ 1 DefineΛA(terms of typeA) inductively:

Ifxis a variable of typeA, thenx∈ΛA.

Ift∈ΛCandxis a variable of typeB, thenλx.t∈ΛBC. Ift∈ΛB→Aandu∈ΛB, thent u∈ΛA.

2 DefineS NA=S N∩ΛA.

3 DefineX→Y={t| ∀u.(u∈Ximpliestu∈Y)}.

4 ShowΛA→B= ΛA→ΛB.

5 ShowS NA→S NB⊆S NA→B(easy).

6 Ifu∈S NA1→S NA2→. . .→S NAmwithAma base type andt∈S NB, then t{x\u} ∈S NB(induction on SN using 5).

7 ShowS NA→B⊆S NA→S NB(using 6).

8 Show thatΛA⊆S NA(by induction using 7).

9 SinceS NA⊆S N=S Nβwe conclude.

(51)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Third Proof of the SN property

Lemma

Iftanduare typed and belong toS Nβ, thent{x\u} ∈S Nβ.

Proof.

Byinductiononhtype(u), µβ(t),size(t)i. The base casehbase type, 0, 1iis trivial.

Caset=λy.vis by thei.h.onv(size( )strictly decreases).

Caset=y~cwithx,yis by thei.h.onciβ( )decreases andsize( )strictly decreases.).

Caset=x. We havex{x\u}=u∈S Nβby hypothesis.

Caset=x b~c. By thei.h.B=b{x\u}andCi=ci{x\u}are inS Nβ. We want to show thatu BC~∈S Nβ. It is sufficient (first alternative definition ofS Nβ) to show that all its reducts are inS Nβ. We reason byinductiononµβ(u)+µβ(B)+ Σiµβ(Ci). The reducts are

u0BC, where~ u→ u0. Apply thei.h.

u B0C, where~ B→ B0. Apply thei.h.

u0B C1. . .Ci0. . .Cn, whereCi→ C0i. Apply thei.h.

v{y\B}C, where~ u=λy.v. Butv{y\B}C~=(zC){z\v{y\B}}~ andtype(v{y\B})<type(u). We thus conclude by thei.h.sincezC~andv{y\B}are typed and inS Nβby thei.h.

(52)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Caset=(λz.b)cd~. By thei.h.B=b{x\u}andC=c{x\u}andDi=di{x\u}are in S Nβ. Supposet{x\u}=(λz.B)CD~<S Nβ. ThenB{z\C}D~<S Nβ. But

B{z\C}D~=(b{z\c}d){x\u}~ andµβ(b{z\c}d)~ < µβ(t). ThusB{z\C}D~∈S Nβby thei.h.

Contradiction. Thust{x\u}=(λz.B)CD~∈S Nβ.

(53)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Theorem

Iftis typable, thent∈S Nβ.

Proof.

By induction on the typing derivation oft. Caset=xis trivial.

Caset=λy.uholds by the i.h.

For the caset=u vuse the fact thatt=(z v){z\u}and apply previous lemma (verification of the hypothesis is easy).

(54)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Fourth proof of the SN property

See for example Gandy’s proof by Alexandre Miquel.

A combinatorial proof of strong normalisation for the simply typed lambda-calculus.

http://www.pps.univ-paris-diderot.fr/˜miquel/publis/snlam.pdf

(55)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Strong Normalization of System F

(56)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Reducibility Candidates

Neutral Terms:Terms that are not abstractions.

Strongly Normalizing Terms:S NF

Definition

Areducibility candidateof typeAis a setRof terms of typeAsuch that (CR1) Ift∈ R, thent∈S NF

(CR2) Ift∈ Randt→F t0, thent0∈ R

(CR3) Iftis neutral and (t→F t0impliest0∈ R), thent∈ R.

IfRandSare reducibility candidates of typeAandBrespectively, thenR → Sis a set of terms of typeA→Bdefined by

t∈ R → Siff∀u.(u∈ Rimpliestu∈ S)

(57)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Remarks

A consequence of(CR3): Iftis neutral and normal, thent∈ R. Rof typeAis never empty, it contains at least the variables of typeA. The set{t∈S NFandtof typeA}is a reducibility candidate.

R → Sis a reducibility candidate.

(58)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Reducibility with Parameters

LetTbe a type wheretfv(T)⊆~α. We writeT{~α\A}~ for the simultaneous substitution of

~αbyA~. Given~Ra sequence of reducibility candidates, we define a setREDT(~α, ~R)of terms of typeT{~α\A~}.

IfT=αi, thenREDT(~α, ~R)=Ri

IfT=A→B, thenREDA→B(~α, ~R)=REDA(~α, ~R)→REDB(~α, ~R)

IfT =∀γ.B, thenRED∀γ.B(~α, ~R)is the set of termstof typeT{~α\A}~ such that for every typeCand reducibility candidateSof this type, thent[C]∈REDB(~αγ, ~RS)

(59)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Properties

Lemma

REDT(~α, ~R)is a reducibility candidate of typeT{~α\A~}

Lemma

REDT{γ\B}(~α, ~R)=REDT(~αγ, ~RREDB(~α, ~R))

Lemma

If for every typeBand candidateS,t{γ\B} ∈REDA(~αγ, ~RS), thenΛγt∈RED∀γ.A(~α, ~R)

Lemma

Ift∈RED∀γ.A(~α, ~R),t[B]∈REDA{γ\B}(~α, ~R)for evert typeB.

(60)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Reducible Terms

A termtof typeAisreducibleift∈REDA(~α, ~S N)where~α=α1. . . αnare the free type variables ofA, andS N~ isS N1. . .S Nn, whereS Niis the set of terms ofS NFof typeαi.

(61)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Final Theorem

Theorem

All terms of systemFare reducible.

Corollary (by CR1)

Corollary

All terms of systemFare inS NF.

(62)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Key Lemma

Lemma

Lettbe a term of typeA. Supposefvt⊆ {x1, . . . ,xn}andxiis of typeBi. Suppose tfv(A,B1, . . . ,Bn)⊆ {α1, . . . , αm}. If{R1, . . . ,Rm}are reducibility candidates of types {C1, . . . ,Cm}andv1, . . . ,vnare terms of typesB1{~α\C}, . . . ,~ Bn{~α\C}~ which are in REDB1(~α, ~~R), . . . ,REDBn(~α, ~~R), thent{~α\C}{~~ x\~v} ∈REDA(~α, ~R)

Références

Documents relatifs

Delia Kesner et Giovanni Bernardi IRIF, Université Paris-Diderot. Emails : [email protected]

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 [email protected] www.irif.fr/˜kesner.. S ´emantique des langages

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner..

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner.. The Untyped

Let t be a typed term and let σ be a type preserving substitution mapping all the free variables of t to terms in SC.. Since σ ∪ {x\x} verifies the second hypothesis of the lemma,

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