• Aucun résultat trouvé

Lambda-Calculus (III-3) Termination

N/A
N/A
Protected

Academic year: 2022

Partager "Lambda-Calculus (III-3) Termination"

Copied!
6
0
0

Texte intégral

(1)

Lambda-Calculus (III-3)

jean-jacques.levy@inria.fr Tsinghua University, September 10, 2010

http://moscova.inria.fr/~levy/courses/tsinghua/lambda

Plan

Normalization

Strong normalization

Standardization theorem

Normalization strategies

Reminders

Redexes may be tracked with residuals

One can define parallel reduction of a given set of redexes by considering any of its finite developments.

Lemma of parallel moves (other version of confluency lemma 1111)

Cube lemma (consistency of residual relation w.r.t. finite developments)

F F

The labeled calculus was a technical tool to name redexes and prove Curry’s Finite Development Theorem.

Termination

(2)

Strong Normalization

Exercice: which of following terms is strongly normalizable ?

M is strongly normalizable iff every reduction from M is finite

I,II,∆∆,∆I,Y,YI,YK,KI(∆∆) whereI=λx.x,∆=λx.xx,K=λx.λy.x andY =λf.(λx.f(xx))(λx.f(xx)).

M

N normal form

Strong Normalization

In typed lambda-calculi, all terms are strongly normalizable:

in 1st-order typed calculus, in system F , F-omega, terms are in

terms of Coq are also strongly normalizable.

SN

SN + confluency

unique normal forms typed λ-terms

type-free λ-calculus

Non termination

In a fully expressive language, you have non-termination:

in PCF + Y operator, in Ocaml, in Haskell, some terms are not in SN

Confluency ensures deterministic calculations

but possibly not terminating with a normal form.

Normalization

Exercice: which of following terms is normalizable ?

M is normalizable iff a reduction from M leads to a normal form.

M

N

I,II,∆∆,∆I,Y,YI,YK,KI(∆∆) whereI=λx.x,∆=λx.xx,K=λx.λy.x andY =λf.(λx.f(xx))(λx.f(xx)).

normal form

infinite reduction

but normal form

(3)

Normalization strategies

Suppose M is normalizable. Is there a strategy to reach the normal form ? (normalizing strategy)

Conversely, if M has an infinite reduction, is there a strategy to fall in an infinite reduction ?

(perpetual strategies) [see Barendregt + Klop]

Take: M=I(∆(KI(∆∆))) I

but M=I(∆(KI(∆∆))) I(∆(KI(∆∆))) · · ·

Take: M= (λx.y)(∆∆) y

but (λx.y)(∆∆) (λx.y)(∆∆) · · ·

Take: M=I(∆(K(∆∆)I)) ∆∆ ∆∆ · · · but M Nin normal form ??

Normalization strategies

Take:M=Y(KI) I

whereY= (λxy.y(xxy))(λxy.y(xxy))

M=Y(KI) KI(Y(KI)) KI(KI(Y(KI))) · · · but

Comparable to evaluation strategies in programming languages:

what is value of ???

In PCF, it would be:

Y(λf x y.ifzxthen 1elsef(x−1) (f x y)) 1 0

Normalization strategies

In programming languages, evaluation strategies could be:

-

call-by-value: compute value of arguments of functions and pass values to the function parameters (Ocaml, Java)

-

call-by-name: pass symbolic expression of arguments to the function parameters and calculate them when needed.

-

call-by-need: variation of call-by-name in order to avoid recalculations of arguments (lazy languages -- Haskell)

there are also CBV, CBN strategies in the lambda-calculus (we don’t do it here)

Call-by-need is more complex [JJL’78, Lamping’90, Gonthier-Abadi-JJL’92]

Standardization

(4)

Standard reduction

R

S

M=· · ·(λx.A)B· · ·(λy.C)D· · · or

M=· · ·(λx.· · ·(λy.C)D· · ·)B· · · or

M=· · ·(λx.A)(· · ·(λy.C)D· · ·)· · · S

R

R

S

RedexR isto the left ofredexSif theλofRis to the left of theλofS.

The reductionM=M0 R1

M1 R2

M2· · · Rn Mn=N isstandardifffor all i,j (0<i<j≤n), redexRjis not a residual of redexRjto the left ofRi in Mi1.

M =

N =

Standard reduction

standard

Standardization

The normal reduction (each step contracts the leftmost-outermost redex) is a standard reduction.

Theorem [standardization] (Curry) Any reduction can be standardized.

Corollary [normalization] If M has a normal form, the normal reduction reaches the normal form.

st

norm nf

Lemma 1

[one cannot create a redex through another more-to-the-left]

Standardization lemma

Proof of standardization thm: [Klop] application of the finite developments theorem and previous lemma.

M N

R S

R’

M N

R S

R’

T T’

Notation:

LetR,S be redexes inM such thatR<S. LetM S N.

ThenR/S={R}. Furthermore, ifT<R, then∃T,T<R,T∈T/S.

writeR<Sif redexRis to the left of redexS.

(5)

Standardization axioms

3 axioms are sufficient to get lemma 1

Axiom 2 [context-freeness]

Axiom 3 [left barrier creation]

S�≤R andR∈R/SandT∈T/S implies

Axiom 1 [linearity] S�≤R implies ∃!R,R∈R/S

T�R iff T�R where�is <or>

(R<S and�T,T∈T/S) implies R<T whereR/S={R}

Standardization proof

Proof: M F1 M1 F2 M2 Mn−1 Fn

R1

R2

R3

R4

R5

Mn=N

P1

P2

P3

P4

P5 F11

F12

F13

F14

F15 F21

F22

F23

F24

F25

Fn1

Fn2

Fn3

Fn4

Fn5 N

N

N

N

N R1

R2 R��2 Rn2

Rn5 R3

R4 R��4

R��5 R5

Each square is an application of the lemma of parallel moves. Let ρi be the horizontal reductions andσj the vertical ones. Each horizontal step is a parallel step, vertical steps are either elementary or empty.

We start with reductionρ0fromMtoN.

LetR1be the leftmost redex inM with residual contracted inρ0. By lemma 1, it has a single residual R1 in M1, M2, . . . until it belongs to some Fk. Here R1 ∈ F2. There are no more residuals ofR1inMk+1,Mk+2, . . . .

LetR2be leftmost redex inP1with resid- ual contracted in ρ1. Here the unique residual is contracted at step n. Again withR3leftmost with residual contracted inρ2. Etc.

Standardization proof

Proof (cont’d):

Now reduction σ0 starting fromM can- not be infinite and stops for some p. If not, there is a rightmost columnσk with infinitely non-empty steps. After a while, this reduction is a reduction relative to a set Fij, which cannot be infinite by the Finite Development theorem.

Thenρpis an empty reduction and there- fore the final term ofσ0isN.

M F1 M1 F2 M2 Mn−1 Fn R1

R2

R3

R4

R5

Mn=N

P1

P2

P3

P4

P5 F11

F12

F13

F14

F15 F12

F22

F32

F42

F52

Fn1

F2n

F3n

F4n

F5n N

N

N

N

N R1

R2 R2�� R2n

R5n R3

R4 R4��

R5��

R5

N N

Standardization proof

Proof (cont’d):

M F1 M1 F2 M2 Mn−1 Fn R1

R2

R3

R4

R5

Mn=N

P1

P2

P3

P4

P5 F11

F12

F13

F14

F15 F12

F22

F32

F42

F52

Fn1

F2n

F3n

F4n

F5n N

N

N

N

N R1

R2 R2�� R2n

R5n R3

R4 R4��

R5��

R5

We claimσ0is a standard reduction. Sup- poseRk (k >i) is residual ofSi to the left ofRi inPi−1.

By constructionRkhas residualSkj along ρi1contracted at somej step. SoSkj is residual ofSi.

By the cube lemma, it is also residual of someSij along σj1. Therefore there is Sij inFij residual ofSi leftmore or outer thanRi.

Contradiction.

(6)

Homeworks

Exercices

Show that∆∆M1M2· · ·Mnhas no normal form for anyM1,M2, . . .Mn(n≥0).

1- Show that∆∆(II) has no normal form whenI=λx.xand∆=λx.xx.

2- 3-

M

N M1 M2 M3

4- Show that rightmost-outermost reduction may miss normal forms.

Show that ifM λx.N, there is a minimalN0such that for allP, such that if

M λx.P, thenN0 P.

5-

Show there is noM whose reduction graph is exactly the following:

Références

Documents relatifs

Talking about monetary consequences associated with eCall not only involves the costs of installing eCall devices into vehicles but also the effects of reducing congestion,

For this we give ourselves the possibility of marking λ-redexes and forbid reductions under their (marked) bindings, so that, if in the assoc -reduction above we make sure

Potential valu- ability relates Na¨ıve Open CBV to Closed CBV via a meta-level substitution closing open terms: a (possibly open) term t is potentially valuable if there is

For the sake of completeness, Figure 6 sketches the ordinary CBV translation from λ -terms (possibly with iterated applications) to proof nets (including the case for

Fireballs are Reasonable: they show that the number of β-steps in the fireball calculus is nonetheless a reasonable cost model by exhibiting a reasonable abstract machine,

Surprisingly, the known criteria for the representation of the call-by-name λ-calculus (with explicit substitutions) fail to characterize the fragment encoding the

We prove that in the value-substitution calculus solvable terms can be char- acterised internally as the terms having normal form with respect to a sub- reduction of the calculus

De Groote (2001) introduced the typed λµ ∧∨ -calculus to code the classical natural deduction system, and showed that it enjoys the main important properties: the strong