lambda calculus...lambda calculus ii 1 lambda calculus part ii lambda calculi with types based on...
TRANSCRIPT
Lambda calculus II 1
Lambda calculus
Part IILambda Calculi with Types
Based on materials provided by H. Barendregt
Lambda calculus II 2
Types
are certain objects, usually syntactic expressions (e.g. boolean, integer, Char), that may be assigned to terms denoting programs.
Types serve to classify the (objects denoted by the) terms.
Semantics.
Each type Ο has as semantics a set of objects of type Ο. There are several systems of type assignment with different collections of types.
For more complicated type systems the semantics will in general be not a set, but an object in some category.
ΟΟΟΟD
ΟΟΟΟD
Lambda calculus II 3
Type assignment is done for the following reasons.
Firstly, the type of a term F gives partial specification of what the function F is supposed to do. Usually specification of this type is given before the term as program is constructed.
Once this term has been constructed, the verification whether this term is indeed of the required type provides partial correctness proof for the program.
Secondly, types play a role in efficiency. If it is known that a subterm S of a program has a certain type, then S may be executed more efficiently by making use of the type information.
Lambda calculus II 4
To explain the idea of type assignment, we present type systems of various strengths.
We start with the system of simply typed lambda calculus. We shall distinguish between typing a la Curry and a la Church by introducing in both ways.
ββββλλλλ
ββββλλλλ
Several other systems of typed lambda calculus exist in a Curry and a Church version. However it is not so for all systems.
For example, for the Curry system of intersection types it is not clear how to define its Church version and for the Church system (calculus of constructions) it is not clear how to define a Curry version.
For the systems that exist in both styles there is a clear relation.
β©β©β©β©Ξ»Ξ»Ξ»Ξ»
Cλλλλ
Lambda calculus II 5
The system -Curry
is assigning elements of a given set T of types to type free lambda terms. For this reason the calculi a la Curry are sometimes called systems of type assignement.
ββββλλλλ
The system -Curry consists of
(i) the set of types of , notation Type( ). We write T= Type( ) for short.
(ii) the finite set of rules.
ββββλλλλ
ββββλλλλ ββββλλλλββββλλλλ
We shall start with a lot of definitions.
Lambda calculus II 6
Definition.(The set of types of )
The set of types T=Type( ) is defined inductively,
ββββλλλλ
ββββλλλλ
T)(T,T´´,´,,
ββββΟΟΟΟββββΟΟΟΟββββββββΟΟΟΟΟΟΟΟββββΞ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ± K (type variables)
(function space types)
or in abstract syntax
TT|VT ββββ====
where V is defined by
V'|V Ξ±Ξ±Ξ±Ξ±==== (type variables)
Lambda calculus II 7
Notation.
(i) If thenT,, ββββΟΟΟΟΟΟΟΟ n1 K
n21 ΟΟΟΟββββββββΟΟΟΟββββΟΟΟΟ K
stands for)),)((( KK n1n21 ΟΟΟΟββββΟΟΟΟββββββββΟΟΟΟββββΟΟΟΟ ββββ
hence , we use association to the right.
(ii) denote arbitrary type variables. K,,, Ξ³Ξ³Ξ³Ξ³Ξ²Ξ²Ξ²Ξ²Ξ±Ξ±Ξ±Ξ±
Lambda calculus II 8
Definition ( -Curry).
A statement M:Ο is derivable from a basis Ξ, notationββββλλλλ
ΟΟΟΟββββΞΞΞΞ ββββββββλλλλ :| MCurry
(orΟΟΟΟββββΞΞΞΞ ββββλλλλ :| M
orΟΟΟΟββββΞΞΞΞ :| M
if there is no danger of confusion) if can be produced by the folowing rules
ΟΟΟΟββββΞΞΞΞ :| M
Lambda calculus II 9
ββββλλλλ -Curry (version 0)
ΟΟΟΟββββΞΞΞΞββββΞΞΞΞββββΟΟΟΟ :|):( xx
ΟΟΟΟββββΞΞΞΞββββΟΟΟΟββββΞΞΞΞΟΟΟΟββββΟΟΟΟββββΞΞΞΞ :)(|:|),(:| MNNM
)(:).(|:|:, ΟΟΟΟββββΟΟΟΟλλλλββββΞΞΞΞββββΟΟΟΟββββΟΟΟΟΞΞΞΞ MxMx
Here stands for and in order to be a basis.
ΟΟΟΟΞΞΞΞ :, x : ΟΟΟΟβͺβͺβͺβͺΞΞΞΞ x )(ΞΞΞΞββββ Domx: ΟΟΟΟβͺβͺβͺβͺΞΞΞΞ x
If we can write instead of:,,: nn11 xx ΟΟΟΟΟΟΟΟ====ΞΞΞΞ K ΟΟΟΟββββΞΞΞΞ :| M.:|:,,: ΟΟΟΟββββΟΟΟΟΟΟΟΟ Mxx nn11 K If Ξ is empty, we write .:| ΟΟΟΟββββM
We pronounce |- as yields or is derivable.
Lambda calculus II 10
The rules given in Version 0 are usually expressed as follows. ββββλλλλ
(axiom) ):(| ΟΟΟΟββββΞΞΞΞ x if ΞΞΞΞββββΟΟΟΟ):(x
(ββββ -elimination) ΟΟΟΟββββΞΞΞΞΟΟΟΟββββΞΞΞΞΟΟΟΟββββΟΟΟΟββββΞΞΞΞ
:)(|:|)(:|
MNNM
-Curry (Version 1)
( -introduction)ββββ)(:).(|
:|:,ΟΟΟΟββββΟΟΟΟλλλλββββΞΞΞΞ
ΟΟΟΟββββΟΟΟΟΞΞΞΞMx
Mx
Lambda calculus II 11
The following is the natural deduction formulation-Curry (Version 2)ββββλλλλ
Elimination rule Introduction rule
ΟΟΟΟΟΟΟΟΟΟΟΟββββΟΟΟΟ
:)(:)(:
MNNM
)(:).(:
ΟΟΟΟββββΟΟΟΟλλλλΟΟΟΟ
MxM
M
ΟΟΟΟ////:x
Lambda calculus II 12
The basic axiom of Versions 0 and 1 is considered here as implicit and is not mentioned. The notation
M
ΟΟΟΟ:x
ΟΟΟΟ:MMeans that from the assumption together with a set Ξ of other statements, one can derive
ΟΟΟΟ:x.: ΟΟΟΟM
Lambda calculus II 13
The basic axiom of Versions 0 and 1 is considered here as implicit and is not mentioned. The notation
M
ΟΟΟΟ:x
ΟΟΟΟ:MMeans that from the assumption together with a set Ξ of other statements, one can derive
ΟΟΟΟ:x.: ΟΟΟΟM
The rule of -introduction in the table states that ββββ)(:).( ΟΟΟΟββββΟΟΟΟλλλλ Mx
is derivable even without the assumption but still using Ξ. This process is called cancellation of an assumption and is indicated by the striking through the statement
ΟΟΟΟ:x
.: ΟΟΟΟx
Lambda calculus II 14
Example.
(a) Using Version 1 of the system the derivation
)(:).(|)(:).(|:
:|:,:
ΟΟΟΟββββΟΟΟΟββββΟΟΟΟλλλλββββΟΟΟΟββββΟΟΟΟλλλλββββΟΟΟΟ
ΟΟΟΟββββΟΟΟΟΟΟΟΟ
xxyxyx
xyx
Shows that for all)(:).(| ΟΟΟΟββββΟΟΟΟββββΟΟΟΟλλλλββββ xxy .T, ββββΟΟΟΟΟΟΟΟ
Lambda calculus II 15
Example.
(a) Using Version 1 of the system the derivation
)(:).(|)(:).(|:
:|:,:
ΟΟΟΟββββΟΟΟΟββββΟΟΟΟλλλλββββΟΟΟΟββββΟΟΟΟλλλλββββΟΟΟΟ
ΟΟΟΟββββΟΟΟΟΟΟΟΟ
xxyxyx
xyx
Shows that for all)(:).(| ΟΟΟΟββββΟΟΟΟββββΟΟΟΟλλλλββββ xxy .T, ββββΟΟΟΟΟΟΟΟ
(b) Using Version 2, a natural deduction derivation of the same type assignment is
2
1
12
xxyxy
xyx
)(:).()(:).(
:::
ΟΟΟΟββββΟΟΟΟββββΟΟΟΟλλλλΟΟΟΟββββΟΟΟΟλλλλ
ΟΟΟΟΟΟΟΟΟΟΟΟ
The indices 1 and 2 are bookkeeping devices that indicate at which application of a rule a particular assumption is being cancelled.
Lambda calculus II 16
(c) For all we haveTββββΟΟΟΟ
)(:).(| ΟΟΟΟββββΟΟΟΟλλλλββββ xx
Lambda calculus II 17
(c) For all we haveTββββΟΟΟΟ
)(:).(| ΟΟΟΟββββΟΟΟΟλλλλββββ xx
Indeed
)(:).(|:|:
ΟΟΟΟββββΟΟΟΟλλλλββββΟΟΟΟββββΟΟΟΟ
xxxx
Lambda calculus II 18
(c) For all we haveTββββΟΟΟΟ
)(:).(| ΟΟΟΟββββΟΟΟΟλλλλββββ xx
Indeed
)(:).(|:|:
ΟΟΟΟββββΟΟΟΟλλλλββββΟΟΟΟββββΟΟΟΟ
xxxx
(d) ΟΟΟΟλλλλββββΟΟΟΟ :).(|: yxxy
Lambda calculus II 19
(c) For all we haveTββββΟΟΟΟ
)(:).(| ΟΟΟΟββββΟΟΟΟλλλλββββ xx
Indeed
)(:).(|:|:
ΟΟΟΟββββΟΟΟΟλλλλββββΟΟΟΟββββΟΟΟΟ
xxxx
(d) ΟΟΟΟλλλλββββΟΟΟΟ :).(|: yxxy
It follows from (c) and Elimination rule that
ΟΟΟΟλλλλββββΟΟΟΟΟΟΟΟββββΟΟΟΟλλλλββββ
:).(|:)(:).(|
yxxyxx
Lambda calculus II 20
Properties of -Curry ββββλλλλ
Several properties of type assignment in are valid. First, we analyse how much of a basis is necessary in order to derive a type assignment.
ββββλλλλ
Definition.
(i) Let be a basis. We consider Ξ as a partial function from the set of term variables to the set of types.
:,,: nn11 xx ΟΟΟΟΟΟΟΟ====ΞΞΞΞ K
(ii) Then dom(Ξ) = is the domain of Ξ and we write ,, n1 xx K
iix ΟΟΟΟ====ΞΞΞΞ )( for the value of Ξ i.e. The type which is assigned to the variable .ix
(iii) Let be a set of term variables, the restriction of Ξ to
is defined as follows
'V 'V).('&|:'| xVxxV ΞΞΞΞ====ΟΟΟΟββββΟΟΟΟ====ΞΞΞΞ
Lambda calculus II 21
(iv) For types and a type variable Ξ±, the substitution of Ο for Ξ± in Ο is denoted by
,T, ββββΟΟΟΟΟΟΟΟ].:[ ΟΟΟΟ====Ξ±Ξ±Ξ±Ξ±ΟΟΟΟ
Basis lemma for -Curryββββλλλλ
Let Ξ be a basis.
(i) If is another basis, then
(ii)
(iii)
',' ΞΞΞΞββββΞΞΞΞΞΞΞΞ .:|':| ΟΟΟΟββββΞΞΞΞββββΟΟΟΟββββΞΞΞΞ MM
).()(:| ΞΞΞΞββββββββΟΟΟΟββββΞΞΞΞ domMFVM
.:|)(|:| ΟΟΟΟββββΞΞΞΞββββΟΟΟΟββββΞΞΞΞ MMFVM
Lambda calculus II 22
Proof.
Since such proofs will occur frequently, we produce it in full only for the first statement in order to be briefer later on.
(i) We proceed by induction on the derivation of
Case 1. M : Ο is x : Ο and this declaration is an element of Ξ. Then also
.:| ΟΟΟΟββββΞΞΞΞ M
': ΞΞΞΞββββΟΟΟΟx and thus .:|' ΟΟΟΟββββΞΞΞΞ M
Case 2. M : Ο is and it follows directly from two assignments and for some Ο. By the Induction Hypothesis one has and Thus
ΟΟΟΟ:)( 21MM)(: ΟΟΟΟββββΟΟΟΟ1M ΟΟΟΟ:2M
)(:|' ΟΟΟΟββββΟΟΟΟββββΞΞΞΞ 1M.:|' ΟΟΟΟββββΞΞΞΞ 2M .:)(|' ΟΟΟΟββββΞΞΞΞ 21MM
Lambda calculus II 23
(ii) By induction on derivation of M : Ο. We prove only the case that M : Ο is and follows directly from the assumption
)(:).( 211Mx ΟΟΟΟββββΟΟΟΟλλλλ.:|:, 211 Mx ΟΟΟΟββββΟΟΟΟΞΞΞΞ
Let then and By the Induction Hypothesis one has and hence
),.( 1MxFVy λλλλββββ )( 1MFVy ββββ .xy β‘β‘β‘β‘////):,( 1xdomy ΟΟΟΟΞΞΞΞββββ
.ΞΞΞΞββββ domy
Case 3. M : Ο is and it follows directly from by the convention concerning bounded variables, one may assume that the variable x does notoccur in the domain of Therefore by the Induction Hypothesis one has and thus
)(:).( 211Mx ΟΟΟΟββββΟΟΟΟλλλλ.:|:, 211 Mx ΟΟΟΟββββΟΟΟΟΞΞΞΞ
'.ΞΞΞΞ211 Mx ΟΟΟΟββββΟΟΟΟΞΞΞΞ :|:,'
).(:).(|' 211Mx ΟΟΟΟββββΟΟΟΟλλλλββββΞΞΞΞ
Lambda calculus II 24
(iii) By induction on the derivation of M :Ο. We only treat the case that M :Ο is and follows directly from ΟΟΟΟ:)( 21 MM
and for some Ξ, Ο. By the Induction Hypothesis one has
)(:| ΟΟΟΟββββΟΟΟΟββββΞΞΞΞ 1M ΟΟΟΟββββΞΞΞΞ :| 2M
)(:|)(| ΟΟΟΟββββΟΟΟΟββββΞΞΞΞ 11 MMFV and .:|)(| ΟΟΟΟββββΞΞΞΞ 22 MMFV
As by (i) one has that ),()()( 2121 MFVMFVMMFV βͺβͺβͺβͺ====
)(:|)(| ΟΟΟΟββββΟΟΟΟββββΞΞΞΞ 121 MMMFV and ΟΟΟΟββββΞΞΞΞ :|)(| 221 MMMFV
and hence .:)(|)(| ΟΟΟΟββββΞΞΞΞ 2121 MMMMFV
Lambda calculus II 25
Now we show how terms of a certain form get typed. It gives us new insight, among other things we can show that certain terms have no types.
Generation lemma for -Curryββββλλλλ
(i) ΞΞΞΞββββΟΟΟΟββββΟΟΟΟββββΞΞΞΞ ):(:| xx
(ii) ]:|&)(:|[:)(| ΟΟΟΟββββΞΞΞΞΟΟΟΟββββΟΟΟΟββββΞΞΞΞΟΟΟΟββββββββΟΟΟΟββββΞΞΞΞ NMMN
(iii) )](&:|:,[,:).(| ΟΟΟΟββββΟΟΟΟβ‘β‘β‘β‘ΟΟΟΟΟΟΟΟββββΟΟΟΟΞΞΞΞΟΟΟΟΟΟΟΟββββββββΟΟΟΟλλλλββββΞΞΞΞ MxMx
Proof. By induction on the length of derivation.
Lambda calculus II 26
Typability of subterms in -Curryββββλλλλ
Let be a subterm of M. Then 'M
':'|':| ΟΟΟΟββββΞΞΞΞββββΟΟΟΟββββΞΞΞΞ MM
for some '.and ΟΟΟΟΞΞΞΞ'
In other words: if M has a type which means that for some ` then every subterm has a type as well. Note that the subterm may be typed from a different basis.
MM of'
Proof. By induction on the complexity of M.
ΟΟΟΟββββΞΞΞΞ :| M
Lambda calculus II 27
Substitution lemma for -Curry.ββββλλλλ
]:[:|]:[:| ΟΟΟΟ====Ξ±Ξ±Ξ±Ξ±ΟΟΟΟββββΟΟΟΟ====Ξ±Ξ±Ξ±Ξ±ΞΞΞΞββββΟΟΟΟββββΞΞΞΞ MM(i)
where Ξ± is a type variable.
(ii) If and thenΟΟΟΟββββΟΟΟΟΞΞΞΞ :|:, Mx ,:| ΟΟΟΟββββΞΞΞΞ N ΟΟΟΟ====ββββΞΞΞΞ :]:[| NxM
Proof.
(i) By induction on derivation of .:| ΟΟΟΟββββΞΞΞΞ M
(ii) By induction on generation of ΟΟΟΟββββΟΟΟΟΞΞΞΞ :|:, Mx
Lambda calculus II 28
Subject reduction theorem for -Curryββββλλλλ
Let Then'.MM Ξ²Ξ²Ξ²Ξ²β>β>β>β>
.:'|:| ΟΟΟΟββββΞΞΞΞββββΟΟΟΟββββΞΞΞΞ MM
Proof.
By induction on generation of using Generation lemma and Substitution lemma. We shall treat the prime case Assume that
Ξ²Ξ²Ξ²Ξ²β>β>β>β>
'.MM Ξ²Ξ²Ξ²Ξ²ββββand]:[',).( QxPMQPxM ====β‘β‘β‘β‘λλλλβ‘β‘β‘β‘
ΟΟΟΟλλλλββββΞΞΞΞ :).(| QPx
Then it follows by the Generation lemma that for some Ο one has
ΟΟΟΟββββΞΞΞΞΟΟΟΟββββΟΟΟΟλλλλββββΞΞΞΞ :|)(:).(| QPx and
Lambda calculus II 29
Using once more the Generation lemma, we get
ΟΟΟΟββββΞΞΞΞΟΟΟΟββββΟΟΟΟΞΞΞΞ :|:|:, QPx andAnd therefore by the Substitution lemma, we have
ΟΟΟΟ====ββββΞΞΞΞ :]:[| QxP
Lambda calculus II 30
Using once more the Generation lemma, we get
ΟΟΟΟββββΞΞΞΞΟΟΟΟββββΟΟΟΟΞΞΞΞ :|:|:, QPx andand therefore by the Substitution lemma, we have
ΟΟΟΟ====ββββΞΞΞΞ :]:[| QxP
Exercises.)).(.(S).(K),.(I yzxyxyzxxyxx λλλλ====λλλλ====λλλλ==== andLet
has one,,allforthatShow ,TββββΟΟΟΟΟΟΟΟΟΟΟΟ
)(:KI|)()(:SK|)(
)()()(:S|)(
ΟΟΟΟββββΟΟΟΟββββΟΟΟΟββββΟΟΟΟββββΟΟΟΟββββΟΟΟΟββββΟΟΟΟββββ
ΟΟΟΟββββΟΟΟΟββββΟΟΟΟββββΟΟΟΟββββΟΟΟΟββββΟΟΟΟββββΟΟΟΟββββ
cba
Lambda calculus II 31
3
2
1
123
yzxzxyzyzxzyz
yzxzzyzxz
xzyzzyx
)()()(:))(.()()(:))(.(
)(:))(.(:))((
)(:)(:)(:)(:)(:
ΟΟΟΟββββΟΟΟΟββββΟΟΟΟββββΟΟΟΟββββΟΟΟΟββββΟΟΟΟββββΟΟΟΟλλλλΟΟΟΟββββΟΟΟΟββββΟΟΟΟββββΟΟΟΟλλλλ
ΟΟΟΟββββΟΟΟΟλλλλΟΟΟΟ
ΟΟΟΟββββΟΟΟΟΟΟΟΟΟΟΟΟΟΟΟΟββββΟΟΟΟΟΟΟΟββββΟΟΟΟββββΟΟΟΟ
)(.S yzxzxyzλλλλβ‘β‘β‘β‘
Type assignments.
(a)
Lambda calculus II 32
(b) ).))((.().))((.(SK uuvyzxzxyzxxyyzxzxyz λλλλλλλλβ‘β‘β‘β‘λλλλλλλλβ‘β‘β‘β‘
We have
2
1
12
uvuv
vu
)(:)(:.::
ΟΟΟΟββββΟΟΟΟββββΟΟΟΟλλλλΟΟΟΟββββΟΟΟΟλλλλ
ΟΟΟΟΟΟΟΟ
Hence
)(:.-K| ΟΟΟΟββββΟΟΟΟββββΟΟΟΟλλλλβ‘β‘β‘β‘ xxy
by introduction ββββββββ
It follows from (a) and elimination that ββββββββ
.)(:-SK| ΟΟΟΟββββΟΟΟΟββββΟΟΟΟββββΟΟΟΟ
Lambda calculus II 33
The set of Typable terms is not closed under expansion.
A stronger failure of subject expansion has shown van Bakel.
and
such that and are There 'T',', MMMM Ξ²Ξ²Ξ²Ξ²β>β>β>β>ββββΟΟΟΟΟΟΟΟΞΞΞΞββββ
.:'|
,':'|,:|
ΟΟΟΟββββ////
ΟΟΟΟββββΟΟΟΟββββ
M
MM
but
We have ).(:).(KI|),(:I| ΟΟΟΟββββΟΟΟΟλλλλββββ////ΟΟΟΟββββΟΟΟΟββββ xxxbut
Observation. (van Bakel 1991)
Lambda calculus II 34
Proof.).()('
)(,SK',.Ξ²Ξ²Ξ²Ξ²ββββΞ²Ξ²Ξ²Ξ²ββββΞ±Ξ±Ξ±Ξ±ββββΞ²Ξ²Ξ²Ξ²β‘β‘β‘β‘ΟΟΟΟ
Ξ²Ξ²Ξ²Ξ²ββββΞ²Ξ²Ξ²Ξ²ββββΞ±Ξ±Ξ±Ξ±β‘β‘β‘β‘ΟΟΟΟβ‘β‘β‘β‘λλλλβ‘β‘β‘β‘
and Take MyxyM
).(:SK| Ξ²Ξ²Ξ²Ξ²ββββΞ²Ξ²Ξ²Ξ²ββββΞ±Ξ±Ξ±Ξ±ββββ//// fact that theuseThen
.).(KI).()(:SK|
ββββλλλλλλλλλλλλΟΟΟΟΟΟΟΟΟΟΟΟββββΟΟΟΟββββΟΟΟΟββββ////
in typeno have and (b).,allfor (a)
xxxxxx
Exercises. thatShow
Lambda calculus II 35
Proof.
(a) If )(:).))((.(-SK| ΟΟΟΟββββΟΟΟΟββββΟΟΟΟλλλλλλλλβ‘β‘β‘β‘ xxyyzxzxyz
Then by the generation lemma
]:).(|)&()(&:))(.(|:[
]:).(|&)(:))(.([|
ΟΟΟΟλλλλββββΞ½Ξ½Ξ½Ξ½ββββ¡¡¡¡β‘β‘β‘β‘ΟΟΟΟββββΟΟΟΟββββΟΟΟΟββββΟΟΟΟννννλλλλββββ¡¡¡¡νννν¡¡¡¡ββββΟΟΟΟββββ
ΟΟΟΟλλλλββββΟΟΟΟββββΟΟΟΟββββΟΟΟΟββββΟΟΟΟλλλλββββΟΟΟΟββββ
xxyyzxzyzx
xxyyzxzxyz
,obtain weagain, lemma Generation theusing
Lambda calculus II 36
]:).(|)&()(&:))(. ΟΟΟΟλλλλββββΟΟΟΟββββΟΟΟΟββββΟΟΟΟβ‘β‘β‘β‘ΟΟΟΟββββΡΡΡΡΟΟΟΟλλλλΡΡΡΡΟΟΟΟΟΟΟΟΡΡΡΡββββΟΟΟΟββββ
xxyyzxzz-(|:y,:[x,
have we,repeatedly lemma Generation theusing
].:).:))(.(|: ΟΟΟΟλλλλΟΟΟΟββββΟΟΟΟββββΟΟΟΟλλλλββββΟΟΟΟΟΟΟΟββββ
ΟΟΟΟββββΟΟΟΟββββΟΟΟΟβ‘β‘β‘β‘Ο Ο Ο Ο ΟΟΟΟβ‘β‘β‘β‘¡¡¡¡
xxyyzxzyzx -(|)&([hence
)(& thatfollowsIt
Lambda calculus II 37
have wehence,
thusΟΟΟΟββββΟΟΟΟβ‘β‘β‘β‘ΟΟΟΟΟΟΟΟβ‘β‘β‘β‘ΡΡΡΡ &
ion.contradict a
now)](:).(|&:))(.(|:,:[
]:).(|&:))(.(|:,:[
ΟΟΟΟββββΟΟΟΟββββΟΟΟΟλλλλββββΟΟΟΟλλλλββββΟΟΟΟΟΟΟΟΟΟΟΟββββ
ΟΟΟΟλλλλββββΟΟΟΟλλλλββββΟΟΟΟΟΟΟΟΟΟΟΟββββ
xxyyzxzzyx
xxyyzxzzyx
thatlemma Generation thefrom followsIt holds somefor that Assume(b) .:).(|,, ΟΟΟΟλλλλββββΞΞΞΞΟΟΟΟΞΞΞΞ xxx
]:&)(:&:|:,[,
])(&:|:,[,
ΞΆΞΆΞΆΞΆΟΟΟΟββββΞΆΞΆΞΆΞΆΟΟΟΟββββΟΟΟΟΞΞΞΞΞΆΞΆΞΆΞΆββββΟΟΟΟΟΟΟΟββββ
ΟΟΟΟβ‘β‘β‘β‘ΟΟΟΟββββΟΟΟΟΟΟΟΟββββΟΟΟΟΞΞΞΞΟΟΟΟΟΟΟΟββββ
xxxxx
xxxthen
SnΓmek 40
Lambda calculus II 38
hence
])(&)(:|:,[, ΟΟΟΟβ‘β‘β‘β‘ΟΟΟΟββββΟΟΟΟΟΟΟΟββββΟΟΟΟββββΟΟΟΟΞΞΞΞΟΟΟΟΟΟΟΟββββ xx
)](:|:,[, ΟΟΟΟββββΟΟΟΟββββΟΟΟΟΞΞΞΞΟΟΟΟΟΟΟΟββββ xx
])(&:&)(:|:,[, ΟΟΟΟβ‘β‘β‘β‘ΟΟΟΟββββΟΟΟΟΞΆΞΆΞΆΞΆΟΟΟΟββββΞΆΞΆΞΆΞΆββββΟΟΟΟΞΞΞΞΞΆΞΆΞΆΞΆββββΟΟΟΟΟΟΟΟββββ xxx
a contradiction. Thus has no type in ).( xxxλλλλ Curry.ββββββββλλλλ
lemma. subterms of Typability by the typeno has ).(KI xxxλλλλ
Lambda calculus II 39
The system A digression.Churchββββββββλλλλ
At the first sight, the main difference between the Curry systems of type assignment and Church typing systems consists in the fact that in the Curry system, the bounded variables are typed implicitely by the system while in the Church typing system, the bounded variables are typed explicitely.
But there is in it more than that:
).(:).:(|
,)(:).(|
ΟΟΟΟββββΟΟΟΟΟΟΟΟλλλλββββ
ΟΟΟΟΟΟΟΟββββΟΟΟΟλλλλββββ
xx
xx
Church
Curry
while
every typefor has one
Lambda calculus II 40
The term (Ξ»x.x) is annotated in the Church sustem by :Ο, in fact it is not a lambda term in the strict sense.
The intuitive meaning is that (Ξ»x:Ο.x) takes the argument x from the domain of the type Ο. The explicit mention of types in terms make it possible the type checking i.e. to decide whether a term has a certain type. For some Curry systems this question is undecidable.
Definition. (pseudoterms)
Let T be some set of types. The set of T-annotated Ξ»-terms (also calledpseudoterms), denoted by is defined as follows: ,TΞΞΞΞ
TTTT T:|| ΞΞΞΞλλλλΞΞΞΞΞΞΞΞ====ΞΞΞΞ xV
where V is the set of term variables.
Lambda calculus II 41
The same syntactic conventions are used for as for e.g. TΞΞΞΞ ,ΞΞΞΞ
))).:(:(:(.:: LLL Mnnx22x11xMnnx11x ΟΟΟΟλλλλΟΟΟΟλλλλΟΟΟΟλλλλβ‘β‘β‘β‘ΟΟΟΟλλλλΟΟΟΟλλλλ
Mx .: ΟΟΟΟλλλλβ‘β‘β‘β‘ rr
Remark.
Several systems of typed Ξ»-calculi `a la Church resemble to the Curry systems of type assignments since they consist of a choice of the set T of types and of an assignment of types to termsTββββΟΟΟΟ
.TΞΞΞΞββββM
However, this is not the case in all systems `a la Church. In some such systems the sets of terms and types are defined simultaneous-ly.
Lambda calculus II 42
Anyway, for the separate definition of the sets of types and and (pseudo)terms is possible and one may have the same set of types as for
Churchββββββββλλλλ
)(T ββββλλλλ==== Type Curry.ββββββββλλλλ
Definition.The typed lambda calculus consists ofChurchββββββββλλλλ
(i) the set of types defined by )(T ββββλλλλ==== TypeTT|VT ββββ====
where V is the set of type variables.
(ii) statements of the form T.: T ββββΟΟΟΟΞΞΞΞββββΟΟΟΟ andwith MM
Lambda calculus II 43
(iii) bases which are again sets of statements with only distinct (term) variables as subjects.
(iv) axioms and rules Churchββββββββλλλλ
(axiom) ΞΞΞΞββββΟΟΟΟΟΟΟΟββββΞΞΞΞ ):(:| xx if
ΟΟΟΟΞΞΞΞΟΟΟΟΞΞΞΞΟΟΟΟββββΟΟΟΟΞΞΞΞββββ
:(MN)-|:N-|)(:M-| on)-eliminati(
):,
ΟΟΟΟββββΟΟΟΟΟΟΟΟλλλλΞΞΞΞΟΟΟΟΟΟΟΟΞΞΞΞββββ
(:M).:x(-|:M-| ion)-introduct( x
Definition.A statement M :Ο is derivable from the basis Ξ, notation Ξ |- M :Ο, if M :Ο can be produced using the above axioms and rules.
Lambda calculus II 44
As we have seen, derivations can be given in several styles. We will not repeat it here, although we slightly prefere the Gentzen (natural deduct-ion) style.
Definition.The set of legal by defined is (by denoted terms, ),ββββλλλλΞΞΞΞββββββββλλλλ
.:|,|) T ΟΟΟΟββββΞΞΞΞΟΟΟΟΞΞΞΞββββΞΞΞΞββββ====ββββλλλλΞΞΞΞ MM(
To refer specifically to one uses the notation Church,ββββββββλλλλ
.:| ΟΟΟΟββββΞΞΞΞ ββββββββλλλλ MChurch
If there is little danger of ambiguity one uses also
.||,| ββββββββββββ ββββλλλλ or Church
Lambda calculus II 45
Exercises.
)(:).:(| ΟΟΟΟββββΟΟΟΟΟΟΟΟλλλλββββ xx (a)
)(:).::(| ΟΟΟΟββββΟΟΟΟββββΟΟΟΟΟΟΟΟλλλλΟΟΟΟλλλλββββ xyx (b)
)(:).:(| ΟΟΟΟββββΟΟΟΟΟΟΟΟλλλλββββ xy (c)
Similarly as for the type-free theory, one can define reduction and conversion on the set of pseudoterms .TΞΞΞΞ
Definition.
The binary relations denoting one-step Ξ²-reduction, many-steps Ξ²-reduction and Ξ²-convertibility on respectively, are generated by the contraction rule
,, Ξ²Ξ²Ξ²Ξ²Ξ²Ξ²Ξ²Ξ²Ξ²Ξ²Ξ²Ξ² ====β>β>β>β>ββββ and
].:[).:( NxMNMx ====ββββΟΟΟΟλλλλ
.TΞΞΞΞ
Lambda calculus II 46
Examples.
).:().:)(.:( yyyyyyxx ΟΟΟΟλλλλββββΟΟΟΟλλλλΟΟΟΟλλλλ Ξ²Ξ²Ξ²Ξ² (a)
).:().:)(.::()( yyzzxyyx ΟΟΟΟλλλλβ>β>β>β>ΟΟΟΟλλλλΟΟΟΟλλλλΟΟΟΟλλλλ Ξ²Ξ²Ξ²Ξ² b
)().:)(.::( zzzzzzyyx Ξ²Ξ²Ξ²Ξ²β>β>β>β>ΟΟΟΟλλλλΟΟΟΟλλλλΟΟΟΟλλλλ (c)
Remarks.
(i) It can be shown that the Church-Rosser theorem for also holds on
Ξ²Ξ²Ξ²Ξ²β>β>β>β>.TΞΞΞΞ
(ii) The following results for are essentially the same as the corresponding propositions for
ChurchββββββββλλλλCurry.ββββββββλλλλ
Lambda calculus II 47
Basis lemma for
Let Ξ be a basis, we have
Church.ββββββββλλλλ
(i) If is another basis, then´´, ΞΞΞΞββββΞΞΞΞΞΞΞΞ .:Β΄|:| ΟΟΟΟββββΞΞΞΞββββΟΟΟΟββββΞΞΞΞ MM
(ii) ).()(:| ΞΞΞΞββββββββΟΟΟΟββββΞΞΞΞ dom MFVM(iii) .:|)(|:| ΟΟΟΟββββΞΞΞΞββββΟΟΟΟββββΞΞΞΞ MMFVM
Generation lemma for Church.ββββββββλλλλ
(i) .):(:| ΞΞΞΞββββΟΟΟΟββββΟΟΟΟββββΞΞΞΞ xx
(ii) ].:|&)(:|[:| ΟΟΟΟββββΞΞΞΞΟΟΟΟββββΟΟΟΟββββΞΞΞΞΟΟΟΟββββββββΟΟΟΟββββΞΞΞΞ NMMN
(iii) ].:|:,&)([:).:(| ΟΟΟΟββββΟΟΟΟΞΞΞΞΟΟΟΟββββΟΟΟΟ====ΟΟΟΟΟΟΟΟββββββββΟΟΟΟΟΟΟΟλλλλββββΞΞΞΞ MxMx
Lambda calculus II 48
Typability of subterms in Church.ββββββββλλλλIf MΒ΄ is a subterm of M and M has a type i.e. if
for some then MΒ΄ has a type as well, i.e.
for some
ΟΟΟΟββββΞΞΞΞ :| MChurch
´´:Β΄| ΟΟΟΟββββΞΞΞΞ MChurch
Β΄.Β΄ ΟΟΟΟΞΞΞΞ and
,ΟΟΟΟΞΞΞΞ and
Substitution lemma for Church.ββββββββλλλλ(i) ].:[:]:[|]:[:| ΟΟΟΟ====Ξ±Ξ±Ξ±Ξ±ΟΟΟΟΟΟΟΟ====Ξ±Ξ±Ξ±Ξ±ββββΟΟΟΟ====Ξ±Ξ±Ξ±Ξ±ΞΞΞΞββββΟΟΟΟββββΞΞΞΞ MM
(ii) Suppose and .:|:|:, ΟΟΟΟββββΞΞΞΞΟΟΟΟββββΟΟΟΟΞΞΞΞ NMx,:]:[| ΟΟΟΟ====ββββΞΞΞΞ NxM Then
where Ξ±, x are a type and a term variable respectively and Ο, Ο are types.
Lambda calculus II 49
Subject reduction Theorem for Church.ββββββββλλλλ
Let ThenΒ΄.MM Ξ²Ξ²Ξ²Ξ²β>β>β>β> .Β΄:|:| ΟΟΟΟββββΞΞΞΞββββΟΟΟΟββββΞΞΞΞ MM
Remark.
This theorem implies that the set of legal expressions is closed under reduction. It is not closed under expansion and conversion.
Take annotated with appropriate types. It follows from the Typability of subterms lemma that has no type.
ΩΩΩΩ====ββββ KIIΩΩΩΩKI
On the other hand convertible legal terms have the same type with respect to a given basis.
Lambda calculus II 50
Lemma on uniqueness of types for Church.ββββββββλλλλ
(i) Let Β΄.Β΄.:|:| ΟΟΟΟβ‘β‘β‘β‘ΟΟΟΟΟΟΟΟββββΞΞΞΞΟΟΟΟββββΞΞΞΞ Then and MM
(ii) Let Β΄.Β΄.´´:|,:| ΟΟΟΟ====ΟΟΟΟ====ΟΟΟΟββββΞΞΞΞΟΟΟΟββββΞΞΞΞ Ξ²Ξ²Ξ²Ξ² Then and MMMM
Proof.(i) By induction on the structure of M.
(ii) Use the Church-Rosser Theorem for the subject reduction theorem for
,TΞΞΞΞ(i). and Church,ββββββββλλλλ
We have seen that this proposition does not hold for Curry.ββββββββλλλλ
Lambda calculus II 51
Relating the Curry and Church systems
For typed lambda calculi that can be described in both ways Γ‘ la Curry and Γ‘ la Church, often a simple relations can be defined between the two versions. We shall show it for the simplest calculus .ββββλλλλ
Definition
There is a forgetful mapping defined as followsΞΞΞΞββββΞΞΞΞ T:.
xx β‘β‘β‘β‘NMMN β‘β‘β‘β‘
MxMx ..: λλλλβ‘β‘β‘β‘ΟΟΟΟλλλλ
The mapping just erases all annotations of a term in .TΞΞΞΞ
Lambda calculus II 52
The following results show that legal pseudoterms in the Church version of Β΄projectΒ΄ to legal terms in the Curry version of ββββλλλλ
.ββββλλλλOn the other hand, legal terms in can be Β΄liftedΒ΄ to legal terms in
CurryββββββββλλλλChurch.ββββββββλλλλ
Theorem.(i) (projection) Let Then .TΞΞΞΞββββM
.:|:| ΟΟΟΟββββΞΞΞΞββββΟΟΟΟββββΞΞΞΞ MM CurryChurch
(ii) (lifting) Let Then .ΞΞΞΞββββM
].Β΄&Β΄:|[Β΄:| T MMMMM ChurchCurry β‘β‘β‘β‘ΟΟΟΟββββΞΞΞΞΞΞΞΞββββββββββββΟΟΟΟββββΞΞΞΞ
Proof.By induction on the derivation of the respective type assignment.
Lambda calculus II 53
Corollary.
For an arbitrary type have we,TββββΟΟΟΟ
-Church. in inhabited is in inhabited is ββββλλλλΟΟΟΟββββββββββββλλλλΟΟΟΟ Curry
Lambda calculus II 54
BΕhm trees and Approximation. A digression.
To the rule A we need to introduce BΕhm trees which are a kind of Β΄infinite normal formsΒ΄.
Lemma.Each is in one of the following forms. ΞΞΞΞββββM
variable.a and with (i) y0mnNyNxxM m1n1 ,,,. β₯β₯β₯β₯λλλλβ‘β‘β‘β‘ KK
.,,)..( 1m0nNNNyxxM m10n1 β₯β₯β₯β₯β₯β₯β₯β₯λλλλλλλλβ‘β‘β‘β‘ with (ii) KK
Lambda calculus II 55
Proof.
By the definition a Ξ»-term is either a variable, or of the form of application PQ or an abstraction Ξ»x.P. We have to analyze three cases:
(a) if M is a variable, then M is of the form (i) with n = m = 0.
(b) if M is an application, then
nabstractioan or (i)) (giving variablea is on whether depending with (ii)or (i) form theof is Then n.applicatioan not with
0
0m10
P0nMPPPPM
,====β‘β‘β‘β‘ K
giving (ii).
Lambda calculus II 56
(c) if and Q is notan abstraction. Then Q is a variable or an application and it follows from the Induction hypothesis that Q is in one of forms (i) or (ii) for n = 0. Adding the prefix does not change the form.
0kQxxxPPxM k21 β₯β₯β₯β₯λλλλλλλλλλλλβ‘β‘β‘β‘λλλλβ‘β‘β‘β‘ ,.. K where,
k21 xxxx λλλλλλλλλλλλλλλλ K
Lambda calculus II 57
Definition. (head normal form, head redex)
(i) A Ξ»-term M is in head normal form (hnf) if M is in the form (i) of the above lemma. In that case y is called the head variable of M.
The following definition deals with the two forms of Ξ»-terms from the above lemma.
(ii) We say that M has an head normal form if there is N in hnf such that .NM Ξ²Ξ²Ξ²Ξ²====
(iii) If M is in the form (ii), we call the head redex of M.10 NNy ).(λλλλ
Lambda calculus II 58
Lemma. (convertibility of head normal forms)
If and Β΄MM Ξ²Ξ²Ξ²Ξ²====
M has hnf ,. m1n11 NNyxxM KKλλλλβ‘β‘β‘β‘
MΒ΄ has hnf Β΄,´´.Β΄ Β΄ m1n11 NNyxxM KKλλλλβ‘β‘β‘β‘
.Β΄,,´´´,Β΄, mm11 NNNNmmyynn Ξ²Ξ²Ξ²Ξ²Ξ²Ξ²Ξ²Ξ² ============β‘β‘β‘β‘==== K and then
Lambda calculus II 59
Proof.
By the Church-Rosser theorem have a common reduct L. But then the only possibility is that
11 MM Β΄ and
´´´´ ´´´´´´. m1n1 NNyxxL KKλλλλβ‘β‘β‘β‘
where
K,´´´´´´´,´´´,´´ 111 NNNmmmyyynnn ββββββββ ================================ and
Lambda calculus II 60
calculus a digression.βββββ₯β₯β₯β₯λλλλ
Definition.
calculus is the extension of the lambda calculus defined as follows. One of the (term) variables is selected for use as a constant and is given the name .β₯β₯β₯β₯
(i) two contraction rules are added:
β₯β₯β₯β₯βββββ₯β₯β₯β₯β₯β₯β₯β₯βββββ₯β₯β₯β₯λλλλ
Mx.
(ii) A reduced. becannot it such that is βββββ₯β₯β₯β₯Ξ²Ξ²Ξ²Ξ²βββββ₯β₯β₯β₯Ξ²Ξ²Ξ²Ξ² form normal
βββββ₯β₯β₯β₯λλλλ
Lambda calculus II 61
We are going to introduce the notion of BΓΆhm tree. The definition is not complete, because it does not specify the ordering of the direct successors of a node. However this ordering is displayed in the pictures of the trees. This suffices for our purposes.
The precise definition of the order can be found in (Barendregt 1984).
Definition.
Let The BΓΆhm tree of M, denoted by BT(M), is the labelled tree defined as follows
.ΞΞΞΞββββM
β₯β₯β₯β₯
λλλλλλλλ
====
hnf no has M if
is M of hnf theif
)()(.
.
)( m1
m1n1
n1
NBTNBTNyNxx
yxx
MBT K
KK
K
Lambda calculus II 62
BΓΆhm trees for calculus are defined under condition that a term
βββββ₯β₯β₯β₯λλλλm1n1 NyNxx KK .λλλλ
is in only if or form normal headβββββ₯β₯β₯β₯Ξ²Ξ²Ξ²Ξ²
Note that if M has Ξ²-hnf, then M has a This is because an hnf m1n1 NyNxx KK .λλλλis also unless If it is the case, then.β₯β₯β₯β₯====y
β₯β₯β₯β₯β>β>β>β>λλλλ β₯β₯β₯β₯Ξ²Ξ²Ξ²Ξ²m1n1 NyNxx KK .
and hence M has a
.0mn ========
hnfβββββ₯β₯β₯β₯Ξ²Ξ²Ξ²Ξ²
too.hnf,βββββ₯β₯β₯β₯Ξ²Ξ²Ξ²Ξ²
β₯β₯β₯β₯β‘β‘β‘β‘////y
hnf.βββββ₯β₯β₯β₯Ξ²Ξ²Ξ²Ξ²
βββββ₯β₯β₯β₯λλλλ
Lambda calculus II 63
Examples.
(a)
c
bc
aabcbcacabcBT .))(.( λλλλ====λλλλ
(b) β₯β₯β₯β₯====λλλλλλλλ )).)(.(( xxxxxxBT
Lambda calculus II 64
(c) Recall that the Fixed point operator Y is defined by.))(.())(.(.Y
4342143421ff
xxfxxxfxfΟΟΟΟΟΟΟΟ
λλλλλλλλλλλλβ‘β‘β‘β‘
It follows that and we have)(..Y ffff fff ΟΟΟΟΟΟΟΟλλλλ====ΟΟΟΟΟΟΟΟλλλλβ‘β‘β‘β‘
)(
.)Y(
ffBT
ffBT
ΟΟΟΟΟΟΟΟ
λλλλ====
Now )( ffff f ΟΟΟΟΟΟΟΟ====ΟΟΟΟΟΟΟΟ
M
f
fBT
ffBT
ff
ff
)(
)(
ΟΟΟΟΟΟΟΟ
========ΟΟΟΟΟΟΟΟthus
Lambda calculus II 65
Hence
M
f
f
f
ffBT .)Y( λλλλ====
Lambda calculus II 66
Remark.
The definition of the BΓΆhm tree is not an inductive definitionof BT(M), although it seems to be according to presented examples. The terms m1 NN ,,Kin the tail of an hnf of M may be more complex than the term M itself. [Barendregt 1984, Chapter 10]
Lemma. (Correctnost of the definition of BΓΆhm trees )(i) BΓΆhm trees are well defined,
(ii) ).()( NBTMBTNM ====ββββ====Ξ²Ξ²Ξ²Ξ²
Proof.The definition is correct as it is independent of the choice of the head normal forms. This and (ii) follows from the lemma on convertibility of hnfs.
Lambda calculus II 67
Definition. Approximate normal forms.
(i) Let A and B be BΓΆhm trees of some terms. We say that A is included in B and write if Aresults from B by cutting of some subtrees, leaving an empty subtree
,BA ββββ
(ii) Let P, Q be terms. We say that P approximates Q and write
βββββ₯β₯β₯β₯λλλλ
).()(, QBTPBTQP ββββββββ if
(iii) Let P be a term. The set of approximate normal forms (anfs) of P, is defined as follows
nf.a is βββββ₯β₯β₯β₯Ξ²Ξ²Ξ²Ξ²ββββ==== QPQP |)(A
βββββ₯β₯β₯β₯λλλλ
.β₯β₯β₯β₯
βββββ₯β₯β₯β₯λλλλ
Lambda calculus II 68
cc
bcb
bcacabcBTaabcaabc
β₯β₯β₯β₯
λλλλ====λλλλββββλλλλ ))(.(..
Example.
The set of approximate normal forms for the fixed point operator Y is
,.,.,.,)Y( Kβ₯β₯β₯β₯λλλλβ₯β₯β₯β₯λλλλβ₯β₯β₯β₯λλλλβ₯β₯β₯β₯==== 32 ffffffA
Lambda calculus II 69
Typing Γ‘ la Curry
The basic system can be extended in various ways to stronger systems by adding new types and by adding new rules. Some of the new rules are related to combinatorial properties of the trees representing the terms.
Curryββββββββλλλλ
The systems to be discussed are To each of these can be added one of the extra derivation rules EQ and A.
. and β©β©β©β©Ξ»Ξ»Ξ»Ξ»Ξ»Β΅Ξ»Β΅Ξ»Β΅Ξ»Β΅Ξ»Ξ»Ξ»Ξ»ββββλλλλ ,, 2
Lambda calculus II 70
β©β©β©β©Ξ»Ξ»Ξ»Ξ»++++
λ¡λ¡λ¡λ¡ββββλλλλ++++
λλλλ
A
EQ2
The systems Γ‘ la Curry
Lambda calculus II 71
Definition. Rules of equality (EQ) and approximation (A).
(i) The equality rule EQ
ΟΟΟΟ====ΟΟΟΟ Ξ²Ξ²Ξ²Ξ²
::
NNMM
(ii) The approximation rules A
ΟΟΟΟβ₯β₯β₯β₯ββββΞΞΞΞ
ΟΟΟΟββββΞΞΞΞββββΟΟΟΟββββΞΞΞΞ
:|
:|)(:|
MMP APallfor
Lambda calculus II 72
Remark. (Side conditions)
Note that in these rules the assumptions are not type assignments. We call them side conditions. The last rule states that has any type.
)(MPNM Aββββ====Ξ²Ξ²Ξ²Ξ² and
β₯β₯β₯β₯
Notation.
Let Ξ»- be any of the systems We denote by
.,, β©β©β©β©Ξ»Ξ»Ξ»Ξ»Ξ»Β΅Ξ»Β΅Ξ»Β΅Ξ»Β΅Ξ»Ξ»Ξ»Ξ»ββββλλλλ or 2
(i) EQ. rule by the extended system the ββββλλλλββββλλλλ ++++ ,
. rule by the extended system the AA ββββλλλλββββλλλλ ,(ii)
So for example.AA ++++λ¡λ¡λ¡λ¡====λ¡λ¡λ¡λ¡++++λλλλ====λλλλ ++++ and EQ22
Lambda calculus II 73
Examples.
(a) One has
)(:)))(..((| ΟΟΟΟββββΟΟΟΟββββΟΟΟΟλλλλλλλλββββ ++++ββββλλλλqpprpq
It follows from the equality Note that this statement is not provable in general in itself. The term has in only types of the form
as follows from the generation lemma.
ppqqpprpq .))(..( λλλλ====λλλλλλλλ
ββββλλλλ,)( ΟΟΟΟββββΟΟΟΟββββΟΟΟΟββββΟΟΟΟ
ββββλλλλ
Lambda calculus II 74
(b) Let be the fixed point operator. Then
))(.))((..(Y xxfxxxfxf λλλλλλλλλλλλβ‘β‘β‘β‘
))((:Y| ΟΟΟΟββββΟΟΟΟββββΟΟΟΟββββ ββββλλλλ A
Indeed, the set of approximate normal forms of Y is
,.,.,., KK β₯β₯β₯β₯λλλλβ₯β₯β₯β₯λλλλβ₯β₯β₯β₯λλλλβ₯β₯β₯β₯ n2 ffffff
And all these terms have type Again, this statement is not derivable in itself. (In all typable terms have a normal form as we shall see later on.)
).)(( ΟΟΟΟββββΟΟΟΟββββΟΟΟΟββββλλλλ ββββλλλλ
Lambda calculus II 75
We are going to show that the rule A is stronger than the rule EQ.
Proposition.
Let Ξ»- be one of the systems of type assignments. In all systems Ξ»-A, we have
β©β©β©β©Ξ»Ξ»Ξ»Ξ»Ξ»Β΅Ξ»Β΅Ξ»Β΅Ξ»Β΅Ξ»Ξ»Ξ»Ξ» or ,2
(i) ΟΟΟΟββββΞΞΞΞββββββββΟΟΟΟββββΞΞΞΞ :|)(:| PMPM A and
(ii) Let Then Β΄).()( MBTMBT ====
ΟΟΟΟββββΞΞΞΞββββΟΟΟΟββββΞΞΞΞ Β΄:|:| MM(iii) Let Then Β΄.MM Ξ²Ξ²Ξ²Ξ²====
ΟΟΟΟββββΞΞΞΞββββΟΟΟΟββββΞΞΞΞ Β΄:|:| MM
Note that (iii) is the rule EQ.
Lambda calculus II 76
Proof.
(i) If P is an approximate normal form of M, then Presults from BT(M) by replacing some subtrees by and writing the result as a Ξ»-term by one of the rules A. Therefore P has the same type as M. (see an Example below).
β₯β₯β₯β₯
(ii) Suppose Then and, consequently
Β΄).()( MBTMBT ==== )(MA Β΄),(MA====
ββββββββββββΟΟΟΟββββΞΞΞΞ PM (:| (i),by ],:|Β΄))[()( ΟΟΟΟββββΞΞΞΞ==== PMM AA
.,Β΄:| A ruleby ΟΟΟΟββββΞΞΞΞββββ M
Lambda calculus II 77
(iii) If by thelemma on the correctness of the definition of BΓΆhm trees. The result then follows by (ii).
Β΄),()(Β΄, MBTMBTMM ========Ξ²Ξ²Ξ²Ξ² then
Example.)(., β₯β₯β₯β₯λλλλβ‘β‘β‘β‘β‘β‘β‘β‘ fffPM let and combinatorpoint fixed theLet Y
be an approximant. We haveΟΟΟΟββββΟΟΟΟββββΟΟΟΟββββ )(:| Y
By choosing Ο as a type for one obtains ,β₯β₯β₯β₯
ΟΟΟΟββββΟΟΟΟββββΟΟΟΟββββ )(:| P
Lambda calculus II 78
System Ξ»2
Polymorphic typed lambda calculus Second-order typed lambda calculus Second-order polymorphic typed Ξ»-calculus System F
Girard (1972) Reynolds (1974)
Lambda calculus II 79
Motivation.
(i) Usually these names refer to Ξ»2-Church, we shall introduce the Curry version of Ξ»2 to discuss the Church version later.
(ii) The idea of polymorphism: while in we have
for arbitrary (type) variable Ξ± (and for arbitrary type Ο as
well), one stipulates in Ξ»2
to indicate that has all types or that the type
of depends uniformly on Ξ±.
ββββλλλλ)(:).( Ξ±Ξ±Ξ±Ξ±ββββααααλλλλ xx
)).((:).( Ξ±Ξ±Ξ±Ξ±ββββΞ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±ββββλλλλ xxΟΟΟΟββββΟΟΟΟ
As we shall see later, the mechanism is rather powerful.
xx.λλλλxx.λλλλ
Lambda calculus II 80
Definition. The set of types of Ξ»2.The set T = Type( ) is defined by the following abstract grammar
Ξ»2
TV|TT|VT ββββββββ====Notation.
(i) The parentheses by quantifiers cumulate to the right, so we have ))))((( KK ΟΟΟΟΞ±Ξ±Ξ±Ξ±ββββΞ±Ξ±Ξ±Ξ±ββββΞ±Ξ±Ξ±Ξ±ββββ n21(
(ii) If there are no parentheses, .han strongly t more binds ββββββββ
Hence).(.,)( ΟΟΟΟββββΟΟΟΟΞ±Ξ±Ξ±Ξ±βββββ‘β‘β‘β‘ΟΟΟΟββββΟΟΟΟΞ±Ξ±Ξ±Ξ±ββββΟΟΟΟββββΟΟΟΟΞ±Ξ±Ξ±Ξ±βββββ‘β‘β‘β‘ΟΟΟΟββββΟΟΟΟΞ±Ξ±Ξ±Ξ±ββββ but
for shorthand a as ΟΟΟΟΞ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±ββββ .n1 K
Lambda calculus II 81
Definition. Type assignment in Ξ»2-Curry.
Ξ»2
(start rule) ΟΟΟΟββββΞΞΞΞΞΞΞΞββββΟΟΟΟ
:|):(x
x
n)eliminatioβ(ΟΟΟΟββββΞΞΞΞ
ΟΟΟΟββββΞΞΞΞΟΟΟΟββββΟΟΟΟββββΞΞΞΞ:)(|
:|)(:|MN
NM
on)introductiβ( )(:).(|:|:,
ΟΟΟΟββββΟΟΟΟλλλλββββΞΞΞΞΟΟΟΟββββΟΟΟΟΞΞΞΞ
MxMx
)( neliminatioββ]):[(:|
)(:|ΟΟΟΟ====Ξ±Ξ±Ξ±Ξ±ΟΟΟΟββββΞΞΞΞ
ΟΟΟΟΞ±Ξ±Ξ±Ξ±ββββββββΞΞΞΞM
M
)( onintroductiββ ).(:|:|
ΟΟΟΟΞ±Ξ±Ξ±Ξ±ββββββββΞΞΞΞΟΟΟΟββββΞΞΞΞ
MM
Lambda calculus II 82
Exercises.).(:).( Ξ±Ξ±Ξ±Ξ±ββββΞ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±ββββλλλλ xx-| (a)
).(:).( Ξ±Ξ±Ξ±Ξ±ββββΞ²Ξ²Ξ²Ξ²ββββΞ±Ξ±Ξ±Ξ±Ξ±Ξ²Ξ±Ξ²Ξ±Ξ²Ξ±Ξ²ββββλλλλ yxy-| (b)
).(| xffx nλλλλββββ (c) )).((: Ξ±Ξ±Ξ±Ξ±ββββΞ±Ξ±Ξ±Ξ±ββββΞ±Ξ±Ξ±Ξ±ββββΞ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±ββββ
).( xxxλλλλ-| (d)
).(| xxxλλλλββββ (e)
).(: Ξ²Ξ²Ξ²Ξ²ββββΞ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±ββββΞ²Ξ²Ξ²Ξ²ββββ
))(.(: Ξ²Ξ²Ξ²Ξ²ββββΞ²Ξ²Ξ²Ξ²ββββΞ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±ββββΞ²Ξ²Ξ²Ξ²ββββ
).(| xxxλλλλββββ (f) )()(: Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±ββββββββΞ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±ββββ
Lambda calculus II 83
Remarks.(i) Exercise (c) shows that the Church numerals
have type which is sometimes called polynat.
).( xffx nn c λλλλβ‘β‘β‘β‘ )).(( Ξ±Ξ±Ξ±Ξ±ββββΞ±Ξ±Ξ±Ξ±ββββΞ±Ξ±Ξ±Ξ±ββββΞ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±ββββ
(ii) One reason for the strength of Ξ»2 is that the Church numerals may be used as iterators for functions of types for arbitrary and not only for functions of a fixed type
ΟΟΟΟββββΟΟΟΟ
.Ξ±Ξ±Ξ±Ξ±ββββΞ±Ξ±Ξ±Ξ±
(iii) We shall show later that the typable terms in Ξ»2 have a normal form, in fact they are strongly normalizing.
ΟΟΟΟ
Lambda calculus II 84
The system λ¡
It is the system of recursive types. The recursive types come together with an equivalence
relation . The type assignment rules consist of the rules of
and the following rule
ββββββββλλλλ
Β΄:|Β΄:|
ΟΟΟΟββββΞΞΞΞΟΟΟΟββββΟΟΟΟΟΟΟΟββββΞΞΞΞ
MM
Lambda calculus II 85
Motivation
A typical example of a recursive type is a type 0ΟΟΟΟ
(1) 000 ΟΟΟΟββββΟΟΟΟββββΟΟΟΟ
This particular type can be used to type arbitrary terms As an example, we shall show that has as a type
.ΞΞΞΞββββM).)(.( xxxxxx λλλλλλλλβ‘β‘β‘β‘ΩΩΩΩ
00 xxx ΟΟΟΟββββΟΟΟΟ :|:000 xx ΟΟΟΟββββΟΟΟΟββββΟΟΟΟ :|:
00xxx ΟΟΟΟββββΟΟΟΟλλλλββββ :.|
0xxx ΟΟΟΟλλλλββββ :.|
0xxxxxx ΟΟΟΟλλλλλλλλββββΩΩΩΩ
:).)(.(|44 344 21
0ΟΟΟΟ
Lambda calculus II 86
Here is the proof of the same statement in a natural deduction setting
000
10
xxx
ΟΟΟΟΟΟΟΟββββΟΟΟΟΟΟΟΟ
:::
1xxx
xx00
0
ΟΟΟΟββββΟΟΟΟλλλλΟΟΟΟ
:).(:)(
0
000
xxxxxxxxxxxx
ΟΟΟΟλλλλλλλλΟΟΟΟλλλλΟΟΟΟββββΟΟΟΟλλλλ
ΩΩΩΩ
:).)(.(:).(:).(
44 344 21
Lambda calculus II 87
Remarks.
(i) The equation (1) is similar to a recursive domain equation
][ DDD βββββ β β β
that enables to interpret elements of Ξ in denotational semantics.
(ii) In order to construct a type satisfying (1), there is an operator Β΅ such that putting implies (1).
0ΟΟΟΟΞ±Ξ±Ξ±Ξ±ββββαααα¡α¡α¡α¡αβ‘β‘β‘β‘ΟΟΟΟ .0
Lambda calculus II 88
Definition. The set T=Type(λ¡), trees of types of λ¡.
(i) The set of types of λ¡, T = Type(λ¡), is defined by the following abstract grammar.
V.T|TT|VT ¡¡¡¡ββββ====
where V is the set of type variables.
Lambda calculus II 89
(ii) Let be a type. The tree of Ο, T(Ο) is defined byinduction on the structure of Ο as follows:
TββββΟΟΟΟ
====Ξ±Ξ±Ξ±Ξ± )(T Ξ±Ξ±Ξ±Ξ±====ΟΟΟΟββββΟΟΟΟ )(T
)()( ΟΟΟΟΟΟΟΟ
ββββ
TT
ΟΟΟΟ¡α¡α¡α¡α====Ξ±Ξ±Ξ±Ξ±ΟΟΟΟ
β₯β₯β₯β₯====ΟΟΟΟ¡α¡α¡α¡α
]).:[().(
TT
if is a type variableΞ±Ξ±Ξ±Ξ±
If for some
ααααββββ¡β¡β¡β¡ββ‘β‘β‘β‘ΟΟΟΟ .n1K
0n β₯β₯β₯β₯
else
Lambda calculus II 90
(iii) The equivalence relation on trees is defined as follows:ββββ)()( ΟΟΟΟ====ΟΟΟΟββββΟΟΟΟββββΟΟΟΟ TT
Exercises.
(a) Assume then ,. Ξ³Ξ³Ξ³Ξ³ββββαααα¡α¡α¡α¡αβ‘β‘β‘β‘ΟΟΟΟ
Ξ³Ξ³Ξ³Ξ³
Ξ³Ξ³Ξ³Ξ³ββββ
Ξ³Ξ³Ξ³Ξ³ββββΞ³Ξ³Ξ³Ξ³ΟΟΟΟ
ββββ====ββββ====ΟΟΟΟ
K
)(
)(
T
T
Lambda calculus II 91
Ξ³Ξ³Ξ³Ξ³
Ξ³Ξ³Ξ³Ξ³ββββ
β₯β₯β₯β₯ββββ
ββββ====ΟΟΟΟ
K
)(T
(b) Assume then,.).( ββββ¡δ¡β¡δ¡β¡δ¡β¡δ¡βββββΞ³Ξ³Ξ³Ξ³ββββαααα¡α¡α¡α¡αβ‘β‘β‘β‘ΟΟΟΟ
Lambda calculus II 92
(c) ).)(().( Ξ³Ξ³Ξ³Ξ³ββββΞ³Ξ³Ξ³Ξ³ββββαααα¡α¡α¡α¡αββββΞ³Ξ³Ξ³Ξ³ββββαααα¡α¡α¡α¡α
(d) for all Ο, even if Ξ±.].:[. ΟΟΟΟ¡α¡α¡α¡α====Ξ±Ξ±Ξ±Ξ±ΟΟΟΟββββΟΟΟΟ¡α¡α¡α¡α .ββββ¡¡¡¡β‘β‘β‘β‘ΟΟΟΟ
Definition.
The type assignment system λ¡ is defined by the natural deduction system presented in the following picture
Lambda calculus II 93
λ¡λ¡λ¡λ¡
(start rule)
n)eliminatioββββββββ(
on)introductiββββββββ(
)( ruleββββββββ
ΟΟΟΟββββΞΞΞΞΞΞΞΞββββΟΟΟΟ
:|):(x
x
ΟΟΟΟββββΞΞΞΞΟΟΟΟββββΞΞΞΞΟΟΟΟββββΟΟΟΟββββΞΞΞΞ
:)(|:|)(:|
MNNM
)(:).(|:|:,
ΟΟΟΟββββΟΟΟΟλλλλββββΞΞΞΞΟΟΟΟββββΟΟΟΟΞΞΞΞ
MxMx
ΟΟΟΟββββΞΞΞΞΟΟΟΟββββΟΟΟΟΟΟΟΟββββΞΞΞΞ
:|:|
MM
Lambda calculus II 94
Proposition. (Coppo 1985)
For an arbitrary type Ο, we have in λ¡
ΟΟΟΟββββΟΟΟΟββββΟΟΟΟββββ )(:Y|)(i
ΟΟΟΟΩΩΩΩββββ :|(ii)
Proof.
(i) If we put then We will derive,. Ξ±Ξ±Ξ±Ξ±ββββαααα¡α¡α¡α¡αβ‘β‘β‘β‘ΟΟΟΟ .ΟΟΟΟββββΟΟΟΟββββΟΟΟΟ
ΟΟΟΟββββΟΟΟΟββββΟΟΟΟλλλλλλλλλλλλβ‘β‘β‘β‘ )(:))(.))((..(Y xxfxxxfxf
Lambda calculus II 95
ΟΟΟΟΟΟΟΟββββΟΟΟΟΟΟΟΟ
:::
xxx 1
ΟΟΟΟΟΟΟΟΟΟΟΟββββΟΟΟΟ:)(
::xxfxxf 2
ΟΟΟΟλλλλΟΟΟΟββββΟΟΟΟλλλλΟΟΟΟββββΟΟΟΟλλλλ
:)(.:)(.:)(.
xxfxxxfxxxfx
ΟΟΟΟββββΟΟΟΟββββΟΟΟΟλλλλλλλλλλλλβ‘β‘β‘β‘ΟΟΟΟλλλλλλλλ
)(:))(.))((..(Y:))(.))((.(
xxfxxxfxfxxfxxxfx
2
1
Lambda calculus II 96
(ii) Note that the result follows from the fact that
and the subject reduction theorem. It is possible to prove (ii) directly.
ΩΩΩΩβ>β>β>β>Ξ²Ξ²Ξ²Ξ²YI),(:).(I ΟΟΟΟββββΟΟΟΟλλλλβ‘β‘β‘β‘ xx )( neliminatioββββββββ
Lambda calculus II 97
The system
It is called the system of intersection types or Torino system.
Barendregt, Coppo, Dezani, Honsell and Longo (1981 -1987)
The system makes it possible that a (term) variable x has exactly two types Ο and Ο at the same time.
β©β©β©β©Ξ»Ξ»Ξ»Ξ»
Lambda calculus II 98
The set of types of the system comes together with a preorder on the set of types.
β©β©β©β©Ξ»Ξ»Ξ»Ξ»
Definition. The set of types.
(i) The set of types is defined by an abstract grammar as follows:
),(T β©β©β©β©Ξ»Ξ»Ξ»Ξ»==== Type
TT|TT|VT β©β©β©β©ββββ====where V is the set of type variables.
(ii) We select one of the type variables as a constant and name it as Ο.
Lambda calculus II 99
Definition. The preorder on T.
(i) The relation is defined on T by the following axioms and rules
β€β€β€β€
ΟΟΟΟβ€β€β€β€ΟΟΟΟββββΟΟΟΟβ€β€β€β€ΟΟΟΟΟΟΟΟβ€β€β€β€ΟΟΟΟΟΟΟΟβ€β€β€β€ΟΟΟΟ,
ΟΟΟΟββββΟΟΟΟβ€β€β€β€ΟΟΟΟΟΟΟΟβ€β€β€β€ΟΟΟΟ
ΟΟΟΟβ€β€β€β€ΟΟΟΟβ©β©β©β©ΟΟΟΟΟΟΟΟβ€β€β€β€ΟΟΟΟβ©β©β©β©ΟΟΟΟΟΟΟΟβ©β©β©β©ΟΟΟΟββββΟΟΟΟβ€β€β€β€ΟΟΟΟββββΟΟΟΟβ©β©β©β©ΟΟΟΟββββΟΟΟΟ
,))(()()(
´´´´,,
ΟΟΟΟββββΟΟΟΟβ€β€β€β€ΟΟΟΟββββΟΟΟΟββββΟΟΟΟβ€β€β€β€ΟΟΟΟΟΟΟΟβ€β€β€β€ΟΟΟΟΟΟΟΟβ©β©β©β©ΟΟΟΟβ€β€β€β€ΟΟΟΟββββΟΟΟΟβ€β€β€β€ΟΟΟΟΟΟΟΟβ€β€β€β€ΟΟΟΟ
(ii) ) & ΟΟΟΟβ€β€β€β€ΟΟΟΟΟΟΟΟβ€β€β€β€ΟΟΟΟββββΟΟΟΟΟΟΟΟ (pf
Lambda calculus II 100
Exercises.
(a) )( ΟΟΟΟββββΟΟΟΟΟΟΟΟpf
(b) )Β΄)(())Β΄()(( ΟΟΟΟββββΟΟΟΟβ©β©β©β©ΟΟΟΟβ€β€β€β€ΟΟΟΟββββΟΟΟΟβ©β©β©β©ΟΟΟΟββββΟΟΟΟ
Lambda calculus II 101
Exercises.
(a) )( ΟΟΟΟββββΟΟΟΟΟΟΟΟpf
(b) )Β΄)(())Β΄()(( ΟΟΟΟββββΟΟΟΟβ©β©β©β©ΟΟΟΟβ€β€β€β€ΟΟΟΟββββΟΟΟΟβ©β©β©β©ΟΟΟΟββββΟΟΟΟ
Proof.
(a) obvious
(b) We know thusΟΟΟΟβ€β€β€β€ΟΟΟΟβ©β©β©β©ΟΟΟΟ Β΄)Β΄)(( ΟΟΟΟββββΟΟΟΟβ©β©β©β©ΟΟΟΟβ€β€β€β€ΟΟΟΟββββΟΟΟΟ )(1
trivially)()Β΄()( ΟΟΟΟββββΟΟΟΟβ€β€β€β€ΟΟΟΟββββΟΟΟΟβ©β©β©β©ΟΟΟΟββββΟΟΟΟ )(2
Then (b) follows from (1) and (2) by transitivity.
Lambda calculus II 102
Definition. The system of type assignment .β©β©β©β©Ξ»Ξ»Ξ»Ξ»
(start rule)
n)eliminatioββββββββ(
on)introductiββββββββ(
n)eliminatioβββββ©β©β©β©(
on)introductiβββββ©β©β©β©(
on)introductiββββΟΟΟΟ(
rule)βββββ€β€β€β€(
ΟΟΟΟββββΞΞΞΞΞΞΞΞββββΟΟΟΟ
:|):(x
x
ΟΟΟΟββββΞΞΞΞΟΟΟΟββββΞΞΞΞΟΟΟΟββββΟΟΟΟββββΞΞΞΞ
:)(|:|)(:|
MNNM
)(:).(|:|:,
ΟΟΟΟββββΟΟΟΟλλλλββββΞΞΞΞΟΟΟΟββββΟΟΟΟΞΞΞΞ
MxMx
ΟΟΟΟββββΞΞΞΞΟΟΟΟββββΞΞΞΞΟΟΟΟβ©β©β©β©ΟΟΟΟββββΞΞΞΞ
:|:|)(:|MM
M
)(:|:|:|
ΟΟΟΟβ©β©β©β©ΟΟΟΟββββΞΞΞΞΟΟΟΟββββΞΞΞΞΟΟΟΟββββΞΞΞΞ
MMM
ΟΟΟΟββββΞΞΞΞ :| M
ΟΟΟΟββββΞΞΞΞΟΟΟΟβ€β€β€β€ΟΟΟΟΟΟΟΟββββΞΞΞΞ
:|:|
MM
Lambda calculus II 103
Exercises.
ΟΟΟΟβββββ©β©β©β©ΟΟΟΟββββΟΟΟΟλλλλββββ ))((:.| xxx (a)
ΟΟΟΟΩΩΩΩββββ :| (b)
)).((:)))(..((| ΟΟΟΟββββΟΟΟΟββββΟΟΟΟλλλλλλλλββββ qpprpq (c)
Lambda calculus II 104
Proof.
(a) ΟΟΟΟΟΟΟΟββββΟΟΟΟΟΟΟΟβ©β©β©β©ΟΟΟΟββββΟΟΟΟ::
)(:xx
x
ΟΟΟΟββββΟΟΟΟβ©β©β©β©ΟΟΟΟββββΟΟΟΟλλλλΟΟΟΟ
))((:).(:)(
xxxxx
1
1
(b) Obvious, it can be shown that M has no head normal form iff Ο is the only possible type for M. (Barendregt 1983)
(c) )(:).(:::ΟΟΟΟββββΟΟΟΟλλλλ
ΟΟΟΟΟΟΟΟΟΟΟΟpr
rpqΟΟΟΟ:)(qp
ΟΟΟΟλλλλ :))(.( qppr
))((:)))(..(()(:)))(..((
ΟΟΟΟββββΟΟΟΟββββΟΟΟΟλλλλλλλλΟΟΟΟββββΟΟΟΟλλλλλλλλ
qpprpqqpprq
21
3
3
1
2
Lambda calculus II 105
Combining the systems Γ‘ la Curry
(i) there are some variants of the system in one of them the rule (axiom) that assigns Ο to any term.
.β©β©β©β©Ξ»Ξ»Ξ»Ξ»
(ii) The systems are all extensions of They can be combined into other systems, an extreme case is
which includes all these systems. It can be extended by cartesian products and direct sums in order to fall into the cartesian closed category.
β©β©β©β©Ξ»Ξ»Ξ»Ξ»Ξ»Β΅Ξ»Β΅Ξ»Β΅Ξ»Β΅Ξ»Ξ»Ξ»Ξ»ββββλλλλ and ,, 2 .ββββλλλλ
β©β©β©β©Β΅Β΅Β΅Β΅Ξ»Ξ»Ξ»Ξ»2
Lambda calculus II 106
Basic properties.
The Curry systems enjoy several propertiesβ©β©β©β©Ξ»Ξ»Ξ»Ξ»Ξ»Β΅Ξ»Β΅Ξ»Β΅Ξ»Β΅Ξ»Ξ»Ξ»Ξ»ββββλλλλ and ,, 2
Basis lemma
Subterm lemma
Substitution lemma
Subject reduction Theorem
Common to all systems:
Each system has a proper variantGeneration lemma
Strong normalizationdoes not hold for all
Lambda calculus II 107
In the following refers to one of Curry systems ββββ| .,, β©β©β©β©Ξ»Ξ»Ξ»Ξ»Ξ»Β΅Ξ»Β΅Ξ»Β΅Ξ»Β΅Ξ»Ξ»Ξ»Ξ»ββββλλλλ and 2
The following three common properties are proved in the same way as we have done for .ββββλλλλ
Basis lemma for the Curry systems.
Let Ξ be a basis.
(i) If is another basis, then´´, ΞΞΞΞββββΞΞΞΞΞΞΞΞ ΟΟΟΟββββΞΞΞΞββββΟΟΟΟββββΞΞΞΞ :Β΄|:| MM
(ii) )()(:| ΞΞΞΞββββββββΟΟΟΟββββΞΞΞΞ domMFVM
(iii) ΟΟΟΟββββΞΞΞΞββββΟΟΟΟββββΞΞΞΞ :|)(|:| MMFVM
Lambda calculus II 108
Subterm lemma for the Curry systems.
Let MΒ΄ be a subterm of M. Then
':'|':| ΟΟΟΟββββΞΞΞΞββββΟΟΟΟββββΞΞΞΞ MM
For some Β΄.Β΄ ΟΟΟΟΞΞΞΞ and
Substitution lemma for the Curry systems.
(i) ]:[:|]:[:| ΟΟΟΟ====Ξ±Ξ±Ξ±Ξ±ΟΟΟΟββββΟΟΟΟ====Ξ±Ξ±Ξ±Ξ±ΞΞΞΞββββΟΟΟΟββββΞΞΞΞ MM
(ii) ΟΟΟΟ====ββββΞΞΞΞββββΟΟΟΟββββΞΞΞΞΟΟΟΟββββΟΟΟΟΞΞΞΞ :]:[|):|&:|:,( NxMNMx
Lambda calculus II 109
Exercise.
Show that for each of the systems one has
β©β©β©β©Ξ»Ξ»Ξ»Ξ»Ξ»Β΅Ξ»Β΅Ξ»Β΅Ξ»Β΅Ξ»Ξ»Ξ»Ξ»ββββλλλλ and ,, 2
)(:| Ξ±Ξ±Ξ±Ξ±ββββΞ±Ξ±Ξ±Ξ±ββββ//// K
in that system.
Lambda calculus II 110
Subject reduction and subject conversion.
Subject reduction
ΟΟΟΟββββΞΞΞΞβββββ>β>β>β>ΟΟΟΟββββΞΞΞΞ :'|':| MMMM Ξ² and
holds for the main systems of type assignment Γ‘ la Curry, namely
with or without the additional rules EQ and A.,,, β©β©β©β©Ξ»Ξ»Ξ»Ξ»Ξ»Β΅Ξ»Β΅Ξ»Β΅Ξ»Β΅Ξ»Ξ»Ξ»Ξ»ββββλλλλ and 2
Subject conversion
ΟΟΟΟββββΞΞΞΞββββ====ΟΟΟΟββββΞΞΞΞ :'|':| MMMM Ξ² and
Holds only for the systems including or rule A or if the rule EQ is included.
β©β©β©β©Ξ»Ξ»Ξ»Ξ»
Lambda calculus II 111
Subject reduction.
We have already proved the Subject reduction theorem for the basic system and we are going to prove it for We need some definitions and throughout the proof T = Type( ).
ββββλλλλ .2λλλλ2λλλλ
Definition.
(i) Write if one of the following conditions is satisfiedΟΟΟΟ>>>>ΟΟΟΟ
ΟΟΟΟΟΟΟΟ====Ξ±Ξ±Ξ±Ξ±ΟΟΟΟβ‘β‘β‘β‘ΟΟΟΟΟΟΟΟΞ±Ξ±Ξ±Ξ±βββββ‘β‘β‘β‘ΟΟΟΟ
ΟΟΟΟΟΟΟΟΞ±Ξ±Ξ±Ξ±βββββ‘β‘β‘β‘ΟΟΟΟ
somefor
or somefor
],:[&.
,,.
1
1
(ii) The relation is the reflexive and transitive closure of > .β₯β₯β₯β₯
Lambda calculus II 112
(iii) A map o : is defined as followsTT ββββ
oo
o
o
ΟΟΟΟ====ΟΟΟΟΞ±Ξ±Ξ±Ξ±ββββΟΟΟΟββββΟΟΟΟ====ΟΟΟΟββββΟΟΟΟ
Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±====Ξ±Ξ±Ξ±Ξ±
).()(
variable typea is if
Remark.
Note that the -introduction and -elimination rules are the only ones in which the subject does not change. Several instances of these rules may be applied consecutively, giving
ββββ β βββ
ΟΟΟΟ
ΟΟΟΟ
:
:
M
M
M
M
In this case By this reasoning, one obtains the following: .ΟΟΟΟβ₯β₯β₯β₯ΟΟΟΟ
Lambda calculus II 113
Lemma.Let an assume that no free type variable in Ο occurs in Ξ. Then
ΟΟΟΟβ₯β₯β₯β₯ΟΟΟΟΟΟΟΟββββΞΞΞΞββββΟΟΟΟββββΞΞΞΞ :|:| MM
Proof.
ΟΟΟΟββββΞΞΞΞ :| M .ΟΟΟΟβ₯β₯β₯β₯ΟΟΟΟSuppose and Then for some if necessary, by renaming some bound type variables, we may assume that for we have
ΟΟΟΟβ‘β‘β‘β‘ΟΟΟΟ>>>>>>>>ΟΟΟΟβ‘β‘β‘β‘ΟΟΟΟ n1 L.,, n1 ΟΟΟΟΟΟΟΟ L
,, ni1i <<<<β€β€β€β€)(. ΞΞΞΞββββΞ±Ξ±Ξ±Ξ±ββββΟΟΟΟΞ±Ξ±Ξ±Ξ±βββββ‘β‘β‘β‘ΟΟΟΟ ++++ FV11i
By the definition of the relation > and the rules of Ξ»2, it follows that we have
1ii MM ++++ΟΟΟΟββββΞΞΞΞββββΟΟΟΟββββΞΞΞΞ :|:|
for all i < n. Hence .:| ΟΟΟΟβ‘β‘β‘β‘ΟΟΟΟββββΞΞΞΞ nM
Lambda calculus II 114
Generation lemma for Ξ»2-Curry.
]:|&Β΄:|[Β΄:)(| ΟΟΟΟββββΞΞΞΞΟΟΟΟββββΟΟΟΟββββΞΞΞΞΟΟΟΟβ₯β₯β₯β₯ΟΟΟΟββββΟΟΟΟββββββββΟΟΟΟββββΞΞΞΞ NMMN (ii)
ΞΞΞΞββββΟΟΟΟΟΟΟΟβ₯β₯β₯β₯ΟΟΟΟββββββββΟΟΟΟββββΞΞΞΞ ):((Β΄:| xx (i)
]&:|:,[:).(| ΟΟΟΟβ₯β₯β₯β₯ΟΟΟΟββββΟΟΟΟΟΟΟΟββββΟΟΟΟΞΞΞΞΟΟΟΟββββΟΟΟΟββββββββΟΟΟΟλλλλββββΞΞΞΞ MxMx (iii)
Proof.
By induction on derivations.
Lambda calculus II 115
Lemma on preorder of types.
(i) Given types Ο, Ο, there exists a type ΟΒ΄ such that
Β΄]:[]):[( ΟΟΟΟ====Ξ±Ξ±Ξ±Ξ±ΟΟΟΟβ‘β‘β‘β‘ΟΟΟΟ====Ξ±Ξ±Ξ±Ξ±ΟΟΟΟ oo
(ii) ]:[( ΟΟΟΟ====Ξ±Ξ±Ξ±Ξ±ΟΟΟΟβ‘β‘β‘β‘ΟΟΟΟΟΟΟΟββββΞ±Ξ±Ξ±Ξ±ββββββββΟΟΟΟβ₯β₯β₯β₯ΟΟΟΟ rro1
o221
(iii) ]:)[(Β΄)Β΄(Β΄)Β΄()( ΟΟΟΟ====Ξ±Ξ±Ξ±Ξ±ΟΟΟΟββββΟΟΟΟβ‘β‘β‘β‘ΟΟΟΟββββΟΟΟΟΟΟΟΟββββΞ±Ξ±Ξ±Ξ±ββββββββΟΟΟΟββββΟΟΟΟβ₯β₯β₯β₯ΟΟΟΟββββΟΟΟΟ rrrr
Lambda calculus II 116
Proof.
(i) By induction on the structure of Ο.
(ii) It suffices to prove it for We have to consider two cases .21 ΟΟΟΟβ₯β₯β₯β₯ΟΟΟΟ
Case 1. ... o1
o212 ΟΟΟΟβ‘β‘β‘β‘ΟΟΟΟΟΟΟΟΞ±Ξ±Ξ±Ξ±βββββ‘β‘β‘β‘ΟΟΟΟ Then
Case 2. ]:[. ΟΟΟΟ====Ξ±Ξ±Ξ±Ξ±ΟΟΟΟβ‘β‘β‘β‘ΟΟΟΟΟΟΟΟΞ±Ξ±Ξ±Ξ±βββββ‘β‘β‘β‘ΟΟΟΟ 21 and
Then by (i) we have Β΄]:[Β΄]:[ ΟΟΟΟ====Ξ±Ξ±Ξ±Ξ±ΟΟΟΟβ‘β‘β‘β‘ΟΟΟΟ====Ξ±Ξ±Ξ±Ξ±ΟΟΟΟβ‘β‘β‘β‘ΟΟΟΟ o1
oo2
(iii) By (ii), we have
])[(]:[)(Β΄)Β΄(Β΄)Β΄( ΟΟΟΟββββΞ±Ξ±Ξ±Ξ±ΟΟΟΟββββΟΟΟΟβ‘β‘β‘β‘ΟΟΟΟ====Ξ±Ξ±Ξ±Ξ±ΟΟΟΟββββΟΟΟΟβ‘β‘β‘β‘ΟΟΟΟββββΟΟΟΟβ‘β‘β‘β‘ΟΟΟΟββββΟΟΟΟ rrrroo
Lambda calculus II 117
Subject reduction theorem for Ξ»2-Curry.
If then we haveΒ΄,MM Ξ²Ξ²Ξ²Ξ²β>β>β>β>
ΟΟΟΟββββΞΞΞΞββββΟΟΟΟββββΞΞΞΞ Β΄:|:| MM
Lambda calculus II 118
Proof.
By induction on the derivation of We will treat only the case of Ξ²-reduction i.e. the case that
Β΄.MM Ξ²Ξ²Ξ²Ξ²β>β>β>β>].:[Β΄).( QxPMQPxM ====β‘β‘β‘β‘λλλλβ‘β‘β‘β‘ and
By the generation lemma, we obtain
]:|&´)(´´)´(&´´:´|:,[´´´]:|&´)(:).(|[´
:)).((|
ΟΟΟΟββββΞΞΞΞΟΟΟΟββββΟΟΟΟβ₯β₯β₯β₯ΟΟΟΟββββΟΟΟΟΟΟΟΟββββΟΟΟΟΞΞΞΞΟΟΟΟβ₯β₯β₯β₯ΟΟΟΟββββΟΟΟΟββββββββΟΟΟΟββββΞΞΞΞΟΟΟΟββββΟΟΟΟλλλλββββΞΞΞΞΟΟΟΟβ₯β₯β₯β₯ΟΟΟΟββββΟΟΟΟββββββββ
ΟΟΟΟλλλλββββΞΞΞΞ
QPxQPx
QPx
From (iii) of the lemma on preorder of types, it follows
]:´´)[Β΄(Β΄)( ΟΟΟΟ====Ξ±Ξ±Ξ±Ξ±ΟΟΟΟββββΟΟΟΟβ‘β‘β‘β‘ΟΟΟΟββββΟΟΟΟ rr
Lambda calculus II 119
and hence by (i) of the the Substitution lemma
pe.smaller ty a of assignment theimplies terma toebigger typ a of assignment that stating lemma by the
lemmaon Substituti theof (ii)by and and
ΟΟΟΟ====ββββΞΞΞΞββββΟΟΟΟβ₯β₯β₯β₯ΟΟΟΟΟΟΟΟ====ββββΞΞΞΞββββ
ΟΟΟΟβ₯β₯β₯β₯ΟΟΟΟΟΟΟΟββββΞΞΞΞΟΟΟΟββββΟΟΟΟΞΞΞΞββββ
:]:[|´´:]:[|
Β΄:|Β΄,:|:,
QxPQxP
QPx
Lambda calculus II 120
Subject reduction theorem for λ¡.
Let then for λ¡ one has Β΄,MM Ξ²Ξ²Ξ²Ξ²β>β>β>β>
ΟΟΟΟββββΞΞΞΞββββΟΟΟΟββββΞΞΞΞ Β΄:|:| MM
Lambda calculus II 121
Proof.
The proof of the subject reduction theorem for λ¡ is somewhat easier than that for Ξ»2. It follows similar steps but using the relation insted ofββββ .β₯β₯β₯β₯
Lambda calculus II 122
Remark.
The subject reduction theorem holds also for This system is also closed under the rule EQ as we will showlater on. We will see that in the systems and Ξ»-A the subject conversion theorem holds. This is not so for
.β©β©β©β©Ξ»Ξ»Ξ»Ξ»
.β©β©β©β©Ξ»Ξ»Ξ»Ξ»
., λ¡λ¡λ¡λ¡λλλλββββλλλλ and 2
Lambda calculus II 123
Example. What makes closed under Ξ²-expansion. β©β©β©β©Ξ»Ξ»Ξ»Ξ»
Let
.contractum its andredex thebe ]:[Β΄).( QxPMQPxM ====β‘β‘β‘β‘λλλλβ‘β‘β‘β‘
To show that Ξ²-expansion holds for this pair assume that
.Β΄:| ΟΟΟΟββββΞΞΞΞ β©β©β©β©Ξ»Ξ»Ξ»Ξ» MNow Q occurs each occurence having its proper type Define
Β΄,M0n in timesβ₯β₯β₯β₯.ni1i β€β€β€β€β€β€β€β€ΟΟΟΟ for
====ΟΟΟΟ>>>>ΟΟΟΟβ©β©β©β©β©β©β©β©ΟΟΟΟ
β‘β‘β‘β‘ΟΟΟΟ0n0nn1
if ifL
Then
ΟΟΟΟββββΟΟΟΟΞΞΞΞΟΟΟΟββββΞΞΞΞ
:|:,:|
PxQ
Hence .:):(|)(:).(| ΟΟΟΟλλλλββββΞΞΞΞΟΟΟΟββββΟΟΟΟλλλλββββΞΞΞΞ QPxPx and
Lambda calculus II 124
In it is not guaranteed that there is a common type for the different occurrences of Q. Note that the type Ο is essential in case when Q has no occurrence in P[x:= Q].
., λ¡λ¡λ¡λ¡λλλλββββλλλλ and 2
Subject conversion theorem for .β©β©β©β©Ξ»Ξ»Ξ»Ξ»
Let then for one has Β΄,MM Ξ²Ξ²Ξ²Ξ²====ΟΟΟΟββββΞΞΞΞββββΟΟΟΟββββΞΞΞΞ Β΄:|:| MM
Without proof
β©β©β©β©Ξ»Ξ»Ξ»Ξ»
Lambda calculus II 125
Strong normalization
DefinitionA lambda term M is called strongly normalizing iff all reduction sequences starting with M terminate.
KIK is strongly normalizing, while KIΞ© is not.
We are going to show that every term typable in is strongly normalizing. This is not true for since in these systems, all terms are typable.
and 2λλλλββββλλλλβ©β©β©β©Ξ»Ξ»Ξ»Ξ»Ξ»Β΅Ξ»Β΅Ξ»Β΅Ξ»Β΅ and
Lambda calculus II 126
We start with the proof of strong normalization for .ββββλλλλ
Definition.
(i) | gnormalizinstrongly is MMSN ΞΞΞΞββββ====
(ii) Let Define a subset as follows: ., ΞΞΞΞββββBA ΞΞΞΞββββ of BA
)(| BFaAaAFBA ββββββββββββββββ====ββββ
(iii) For every we define a set as follows
), Type( ββββλλλλββββΟΟΟΟ ΞΞΞΞββββΟΟΟΟ
variable typea is if Ξ±Ξ±Ξ±Ξ±====Ξ±Ξ±Ξ±Ξ± SN
ΟΟΟΟββββΟΟΟΟ====ΟΟΟΟββββΟΟΟΟ
Lambda calculus II 127
Definition.
(i) We call a subset saturated ifSNX ββββ
])[,,)( XRxSNRR0n n1 βββββββββββββ₯β₯β₯β₯ββββr
K( (a)
where x is any term variable.
))(,,)( SNQSNRR0n n1 βββββββββββββββββ₯β₯β₯β₯ββββ K( (b)]).(]:[[ XRQPxXRQxP ββββλλλλββββββββ====
rr
(ii) | saturated is XXSAT ΞΞΞΞββββ====
Note that saturated sets are non-empty, as they contain all term variables, and that they are closed under a particular type of expansion.
Lambda calculus II 128
Lemma on saturated sets.
SATSN ββββ (i)
SATBASATBA ββββββββββββββββ, (ii)
SATASATA
iIi
Iii
ββββββββ
ββββ
I then of members of collection a be Let (iii) ,
SAT has one )Type( allFor (iv) ββββΟΟΟΟββββλλλλββββΟΟΟΟ
Lambda calculus II 129
Proof.
(i) Obviously and it satisfies the condition (a). As to the condition (b), suppose
SNSN ββββ
SNRQSNRQxP ββββββββ====rr
,&]:[ )(1
We claim that alsoSNRQPx ββββλλλλ
r).( )(2
Note that the reductions inside must terminate since these terms are strongly normalising by assumption. The term
RQPr
or the ,
]:[ QxP ====
is a subterm of a term in SN by (1) hence it is itself in SN and, consequently, P is i n SN. So after finitely many reduction steps applied to the term in (2), we obtain
etcetera Β΄&´´´).( PPRQPx Ξ²Ξ²Ξ²Ξ²β>β>β>β>λλλλr
Lambda calculus II 130
´´´).( RQPxr
λλλλThen the contraction of gives
´´]:´[ RQxPr
==== )(3
This is a reduct of and since this term is SN, then (3) and the term are SN.
RQxPr
]:[ ====QPx ).(λλλλ
(ii) Let Then by definition for all variables x.., SATBA ββββ Ax ββββ
Hence
SNFSNFx
BFxBAF
ββββββββββββββββ
ββββββββββββββββ
So indeed We prove the condition (i) (a) of saturation, let We must show for a variable x that . which means
.SNBA ββββββββ.SNR ββββ
r
BARx ββββββββr
)( BQRxAQ ββββββββββββ
which is true since and B is saturated.SNA ββββ
Lambda calculus II 131
(iii) Similarly
(iv) By induction on the generation of Ο, using (i) and (ii).
Definition.
In order to prove the key Soundness Theorem, we need the folowing
(i) A valuation in Ξ is a map where V is the set of term variables.
,: ΞΞΞΞββββΟΟΟΟ V
(ii) Let Ο be a valuation in Ξ. We define
)](:,),(:[ nn11 xxxxMM ΟΟΟΟ====ΟΟΟΟ========ΟΟΟΟ
K
where is the set of free variables in M.n1 xxx ,,Kr ====
Lambda calculus II 132
(iii) Let Ο be a valuation in Ξ. We say that Ο satisfies M : Ο and write
.,:| ΟΟΟΟββββΟΟΟΟ====ΟΟΟΟΟΟΟΟ
MM if
If Ξ is a basis, we say that Ο satisfies Ξ and write for all
ΟΟΟΟ====ΟΟΟΟΞΞΞΞ====ΟΟΟΟ :|,| x if .):( ΞΞΞΞββββΟΟΟΟx
(iv) A basis Ξ satisfies M : Ο and write if,:| ΟΟΟΟ====ΞΞΞΞ M
]:||[ ΟΟΟΟ====ΟΟΟΟββββΞΞΞΞ====ΟΟΟΟΟΟΟΟββββ M
Lambda calculus II 133
(iii) Let Ο be a valuation in Ξ. We say that Ο satisfies M : Ο and write
.,:| ΟΟΟΟββββΟΟΟΟ====ΟΟΟΟΟΟΟΟ
MM if
If Ξ is a basis, we say that Ο satisfies Ξ and write for all
ΟΟΟΟ====ΟΟΟΟΞΞΞΞ====ΟΟΟΟ :|,| x if .):( ΞΞΞΞββββΟΟΟΟx
(iv) A basis Ξ satisfies M : Ο and write if,:| ΟΟΟΟ====ΞΞΞΞ M
]:||[ ΟΟΟΟ====ΟΟΟΟββββΞΞΞΞ====ΟΟΟΟΟΟΟΟββββ M
Soundness Theorem.
ΟΟΟΟ====ΞΞΞΞββββΟΟΟΟββββΞΞΞΞ ββββλλλλ :|:| MM
Lambda calculus II 134
Proof.
By induction on derivation of .: ΟΟΟΟM
Case 1. If follows from then trivially
ΟΟΟΟββββΞΞΞΞβ‘β‘β‘β‘ :| MxM and ,):( ΞΞΞΞββββΟΟΟΟx.:| ΟΟΟΟ====ΞΞΞΞ x
Case 2. If is a direct consequence ofΟΟΟΟββββΞΞΞΞβ‘β‘β‘β‘ :| MMMM 21 and ,:|:| ΟΟΟΟββββΞΞΞΞΟΟΟΟββββΟΟΟΟββββΞΞΞΞ 21 MM and In order to show ,:| ΟΟΟΟ====ΟΟΟΟ 21MM
We suppose Then which means
.| ΞΞΞΞ====ΟΟΟΟ ΟΟΟΟ====ΟΟΟΟΟΟΟΟββββΟΟΟΟ====ΟΟΟΟ :|:| 21 MM and
ΟΟΟΟββββΟΟΟΟββββΟΟΟΟ====ΟΟΟΟββββΟΟΟΟββββΟΟΟΟΟΟΟΟ 2M and 1M
But then
ΟΟΟΟ====ΟΟΟΟΟΟΟΟββββ====ΟΟΟΟΟΟΟΟΟΟΟΟ
:| 212121 MMMMMM means which
Lambda calculus II 135
Case 3. Let be a direct consequence of
21MMxM ΟΟΟΟββββΟΟΟΟβ‘β‘β‘β‘ΟΟΟΟΟΟΟΟββββΞΞΞΞλλλλβ‘β‘β‘β‘ let and :|Β΄,..Β΄:|:, 21 Mx ΟΟΟΟββββΟΟΟΟΞΞΞΞ
By the induction hypothesis, we have
21 Mx ΟΟΟΟ====ΟΟΟΟΞΞΞΞ Β΄:|:, )(1
In order to show suppose We have to show
,Β΄:.| 21Mx ΟΟΟΟββββΟΟΟΟλλλλ====ΟΟΟΟ .| ΞΞΞΞ====ΟΟΟΟ
12 NNMx ΟΟΟΟββββΟΟΟΟββββλλλλΟΟΟΟ
allfor Β΄.
Let Then and hence .1N ΟΟΟΟββββ ,:,|):( 1xNx ΟΟΟΟΞΞΞΞ========ΟΟΟΟ
2NxM ΟΟΟΟββββ
====ΟΟΟΟ ):(Β΄
by (1).
Lambda calculus II 136
Since
):(Β΄
]),(:Β΄[
)](:Β΄)[.(Β΄.
NxM
NxyyM
NyyMxNMx
====ΟΟΟΟ
Ξ²Ξ²Ξ²Ξ²
ΟΟΟΟ
β‘β‘β‘β‘
====ΟΟΟΟ====ββββ
ΟΟΟΟ====λλλλβ‘β‘β‘β‘λλλλrr
vr
it follows from the saturation of .Β΄. 22 NMx ΟΟΟΟββββλλλλΟΟΟΟΟΟΟΟ
that
Lambda calculus II 137
Strong normalization theorem for -Curry ββββλλλλ
Suppose
ΟΟΟΟββββΞΞΞΞ ββββλλλλ :| M
then M is strongly normalizing.
Lambda calculus II 138
Proof.
Suppose Then according to the Soundness Theorem. If we put then Note that since is saturated.
.:| ΟΟΟΟββββΞΞΞΞ M ΟΟΟΟ====ΞΞΞΞ :| M.| ΞΞΞΞ====ΟΟΟΟ0
ΟΟΟΟββββx,)( xxx0 allfor ====ΟΟΟΟ
ΟΟΟΟ is saturated.
Therefore hence,:| ΟΟΟΟ====ΟΟΟΟ M0 .SNMM0
ββββΟΟΟΟβββββ‘β‘β‘β‘ΟΟΟΟ
Lambda calculus II 139
Proof.
Suppose Then according to the Soundness Theorem. If we put then Note that since is saturated.
.:| ΟΟΟΟββββΞΞΞΞ M ΟΟΟΟ====ΞΞΞΞ :| M.| ΞΞΞΞ====ΟΟΟΟ0
ΟΟΟΟββββx,)( xxx0 allfor ====ΟΟΟΟ
ΟΟΟΟ is saturated.
Therefore hence,:| ΟΟΟΟ====ΟΟΟΟ M0 .SNMM0
ββββΟΟΟΟβββββ‘β‘β‘β‘ΟΟΟΟ
Remark.
A simple generalization of the method proves the Strong Normalization Theorem for Ξ»2.
Lambda calculus II 140
Definition.
(i) A valuation in SAT is a map
SATββββΞΎΞΎΞΎΞΎ V:Where V is the set of type variables.
(ii) Given a valuation ΞΎ in SAT one defines a set for every type Ο in Ξ»2 as follows:
ΞΞΞΞββββΟΟΟΟΞΎΞΎΞΎΞΎ
):(.
V),(
XSATX ====Ξ±Ξ±Ξ±Ξ±ΞΎΞΎΞΎΞΎββββΞΎΞΎΞΎΞΎ
ΞΎΞΎΞΎΞΎΞΎΞΎΞΎΞΎΞΎΞΎΞΎΞΎ
ΞΎΞΎΞΎΞΎ
ΟΟΟΟ====ΟΟΟΟΞ±Ξ±Ξ±Ξ±ββββ
ΟΟΟΟββββΟΟΟΟ====ΟΟΟΟββββΟΟΟΟ
ββββΞ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±ΞΎΞΎΞΎΞΎ====Ξ±Ξ±Ξ±Ξ±
I
where
Lambda calculus II 141
Lemma.
Given a valuation ΞΎ in SAT and a type Ο in Ξ»2, then .SATββββΟΟΟΟΞΎΞΎΞΎΞΎ
Proof.As the proof of (iv) in lemma on saturated sets using the fact that SAT is closed under arbitrary intersections.
Lambda calculus II 142
Definition.
Let Ο be a valuation in Ξ and ΞΎ be a valuation in SAT.
(i) We write ΞΎΞΎΞΎΞΎΟΟΟΟΟΟΟΟββββΟΟΟΟ====ΞΎΞΎΞΎΞΎΟΟΟΟ MM iff :|,
(ii) If Ξ is a basis, we write
ΞΞΞΞΟΟΟΟΟΟΟΟ====ΞΎΞΎΞΎΞΎΟΟΟΟΞΞΞΞ====ΞΎΞΎΞΎΞΎΟΟΟΟ in allfor iff ::|,|, xx
(iii) We write
]:|,|,[,:| ΟΟΟΟ====ΞΎΞΎΞΎΞΎΟΟΟΟββββΞΞΞΞ====ΞΎΞΎΞΎΞΎΟΟΟΟΞΎΞΎΞΎΞΎΟΟΟΟββββΟΟΟΟ====ΞΞΞΞ MM iff
Lambda calculus II 143
Soundness Theorem for Ξ»2.
ΟΟΟΟ====ΞΞΞΞββββΟΟΟΟββββΞΞΞΠλλλλ :|:| MM2
Lambda calculus II 144
Soundness Theorem for Ξ»2.
ΟΟΟΟ====ΞΞΞΞββββΟΟΟΟββββΞΞΞΠλλλλ :|:| MM2
Proof.
By induction on the derivation of as in the proof of Soundness Theorem for There are two more cases corresponding to
ΟΟΟΟββββΞΞΞΞ :| M.ββββλλλλ
rules.ββββββββ
Case 4. is a direct consequence of By the Induction Hypothesis, we have
]:[:| ΟΟΟΟ====Ξ±Ξ±Ξ±Ξ±ΟΟΟΟβ‘β‘β‘β‘ΟΟΟΟΟΟΟΟββββΞΞΞΞ 0M where..:| 0M ΟΟΟΟΞ±Ξ±Ξ±Ξ±ββββββββΞΞΞΞ
0M ΟΟΟΟΞ±Ξ±Ξ±Ξ±ββββ====ΞΞΞΞ .:| )(1
In order to show]:[:|, ΟΟΟΟ====Ξ±Ξ±Ξ±Ξ±ΟΟΟΟ====ΞΎΞΎΞΎΞΎΟΟΟΟ 0M
suppose.|, ΞΞΞΞ====ΞΎΞΎΞΎΞΎΟΟΟΟ
Lambda calculus II 145
It follows from (1) that
):(.
X0SATX
0M====Ξ±Ξ±Ξ±Ξ±ΞΎΞΎΞΎΞΎ
ββββΞΎΞΎΞΎΞΎΟΟΟΟ
ΟΟΟΟ====ΟΟΟΟΞ±Ξ±Ξ±Ξ±ββββββββ I
Hence
):( ΞΎΞΎΞΎΞΎΟΟΟΟ====Ξ±Ξ±Ξ±Ξ±ΞΎΞΎΞΎΞΎΟΟΟΟΟΟΟΟββββ 0M
By induction on (some care is needed in case 2)Type( λλλλββββΟΟΟΟ0 ). 00 ΟΟΟΟΞ²Ξ²Ξ²Ξ²βββββ‘β‘β‘β‘ΟΟΟΟ
we prove
]:[):(
ΟΟΟΟ====Ξ±Ξ±Ξ±Ξ±ΟΟΟΟ====ΟΟΟΟΞΎΞΎΞΎΞΎΟΟΟΟ====Ξ±Ξ±Ξ±Ξ±ΞΎΞΎΞΎΞΎ 00
which completes the proof of the Case 4.
Lambda calculus II 146
Case 5. Let is a direct consequence of By the Induction Hypothesis, we have
)(.:| ΞΞΞΞββββΞ±Ξ±Ξ±Ξ±ΟΟΟΟΞ±Ξ±Ξ±Ξ±βββββ‘β‘β‘β‘ΟΟΟΟΟΟΟΟββββΞΞΞΞ FVM 0 and with .:| 0M ΟΟΟΟββββΞΞΞΞ
0M ΟΟΟΟ====ΞΞΞΞ :|
In order to show Since .|,,.:|, ΞΞΞΞ====ΞΎΞΎΞΎΞΎΟΟΟΟΟΟΟΟΞ±Ξ±Ξ±Ξ±ββββ====ΞΎΞΎΞΎΞΎΟΟΟΟ suppose we0M ),(ΞΞΞΞββββΞ±Ξ±Ξ±Ξ± FV
we have Therefore .|):(, SATXX ββββΞΞΞΞ========Ξ±Ξ±Ξ±Ξ±ΞΎΞΎΞΎΞΎΟΟΟΟ allfor
SATXMX0 ββββΟΟΟΟββββ
====Ξ±Ξ±Ξ±Ξ±ΞΎΞΎΞΎΞΎΟΟΟΟ allfor
):(
)(2
It follows from (2) that
ΞΎΞΎΞΎΞΎΟΟΟΟΟΟΟΟΞ±Ξ±Ξ±Ξ±ββββββββ 0M .
Hence321
ΟΟΟΟ
ΟΟΟΟΞ±Ξ±Ξ±Ξ±ββββ====ΞΎΞΎΞΎΞΎΟΟΟΟ 0M .:|,
Lambda calculus II 147
Strong Normalization Theorem for Ξ»2-Curry
gnormalizinstrongly is MM2 ββββΟΟΟΟββββΞΞΞΠλλλλ :|
Lambda calculus II 148
Strong Normalization Theorem for Ξ»2-Curry
gnormalizinstrongly is MM2 ββββΟΟΟΟββββΞΞΞΠλλλλ :|
Proof of the theorem is similar to the proof of Strong Normalizing Theorem for Curry.ββββββββλλλλ
Lambda calculus II 149
Decidability of type assignment.
Note that for arbitrary base one has:,,: nn11 xx ΟΟΟΟΟΟΟΟ====ΞΞΞΞ K
)(:).(|:| ΟΟΟΟββββΟΟΟΟββββΟΟΟΟλλλλλλλλββββββββΟΟΟΟββββΞΞΞΞ n1n1 MxxM KK
Consequently, analysing the type assignment, we may assume that the base is always empty. Typical questions are
Given M and Ο, does it hold ?
Given M, does there exist a Ο such that ?
Given Ο, does there exist an M such that ?
ΟΟΟΟββββ :| M
ΟΟΟΟββββ :| M
ΟΟΟΟββββ :| M
These three problems are called type checking, typability andinhabitation respectively and we shall denote them ,
.:? ΟΟΟΟ and?: ΟΟΟΟM
?,:MLambda calculus II 150
We shall examine the decidability of these three problems for the various systems of type assignments. The results can be summarized
in the following table
?:ΟΟΟΟM ?:M ΟΟΟΟ:?ββββλλλλ yes yes yes2λλλλ ?? ?? no
λ¡λ¡λ¡λ¡ yes yes, always yes, alwaysβ©β©β©β©Ξ»Ξ»Ξ»Ξ» no yes, always ??
++++ββββλλλλ no no yes++++λλλλ2 no no no++++λ¡λ¡λ¡λ¡ no yes,always yes, always
Aββββλλλλ no no yes, alwaysA2λλλλ no no yes, alwaysAλ¡λ¡λ¡λ¡ no yes, always yes, always
Aβ©β©β©β©Ξ»Ξ»Ξ»Ξ» no yes, always yes, always
Lambda calculus II 151
We first show decidability of the three questions for In what follows
Curry.ββββββββλλλλ.||) Curryββββλλλλββββββββββββλλλλ denotes and Type( denotes T
We define some operations on the set of types: substitutor, unifier, unification and some concepts concerning type assignments: pricipal pair and principal type.
Definition.
(i) A substitutor is an operation on the set of types such that
TT: ββββββββ
)()()( ΟΟΟΟββββββββΟΟΟΟβββββ‘β‘β‘β‘ΟΟΟΟββββΟΟΟΟββββ
Lambda calculus II 152
Notation.
a) We write ).(ΟΟΟΟββββΟΟΟΟββββ for
b) In cases that are of interest for us, a substitutor has a finite support, which means that for all but finitely many type variables Ξ± one has the support of being
ββββ
,Ξ±Ξ±Ξ±Ξ±β‘β‘β‘β‘Ξ±Ξ±Ξ±Ξ± ββββ ββββ .Ξ±Ξ±Ξ±Ξ±β‘β‘β‘β‘////Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±====ββββ ββββ|)sup(
In that case we write]:,,:[)( ββββββββ Ξ±Ξ±Ξ±Ξ±====Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±====Ξ±Ξ±Ξ±Ξ±ΟΟΟΟ====ΟΟΟΟββββ nn11 K
Where is the support of We also write,, n1 Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ± K .ββββ
].:,,:[ ββββββββ Ξ±Ξ±Ξ±Ξ±====Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±====Ξ±Ξ±Ξ±Ξ±====ββββ nn11 K
Lambda calculus II 153
Definition. Unifiers.
(i) Let Ο and Ο be two types. A unifier for Ο and Ο is a substitutor ββββsuch that .ββββββββ ΟΟΟΟβ‘β‘β‘β‘ΟΟΟΟ
(ii) The substitutor is a most general unifier for Ο and Ο if ββββ
(a) is a unifier for Ο and Ο ββββ(b) if an arbitrary unifier for Ο and Ο, then there is a substitutor such that
1ββββ2ββββ .βββββββββ‘β‘β‘β‘ββββ o21
(iii) Let be a finite set of equations between types. The equations do not need to be valid. A unifier for E is a substitutor such that In that case one writes Similarly one defines the notion of a most general unifier for E.
,, nn11E ΟΟΟΟ====ΟΟΟΟΟΟΟΟ====ΟΟΟΟ==== K
ββββ .,, ββββββββββββββββ ΟΟΟΟ====ΟΟΟΟΟΟΟΟ====ΟΟΟΟ nn11 K
.| E====ββββ
Lambda calculus II 154
Examples.
The types
δδδδββββΞ³Ξ³Ξ³Ξ³ββββΞ³Ξ³Ξ³Ξ³Ξ²Ξ²Ξ²Ξ²ββββΞ±Ξ±Ξ±Ξ±ββββΞ²Ξ²Ξ²Ξ² )()(
have unfiers
)]()(:,:,:[)](:,:[
Ξ³Ξ³Ξ³Ξ³ββββΞ³Ξ³Ξ³Ξ³ββββΡΡΡΡββββΡΡΡΡ====δδδδΡΡΡΡββββΡΡΡΡ====Ξ±Ξ±Ξ±Ξ±Ξ³Ξ³Ξ³Ξ³ββββΞ³Ξ³Ξ³Ξ³====Ξ²Ξ²Ξ²Ξ²====ββββΞ³Ξ³Ξ³Ξ³ββββΞ³Ξ³Ξ³Ξ³ββββΞ±Ξ±Ξ±Ξ±====δδδδγγγγββββΞ³Ξ³Ξ³Ξ³====Ξ²Ξ²Ξ²Ξ²====ββββ
1
The unifier is most general, the unifier is not.ββββ 1ββββ
Lambda calculus II 155
Definition. Variants.The type Ο is a variant of the type Ο if there are substitutors 21 ββββββββ ,such that
21 ββββββββ ΟΟΟΟ====ΟΟΟΟΟΟΟΟ====ΟΟΟΟ and
Examples.
Ξ±Ξ±Ξ±Ξ±ββββΞ²Ξ²Ξ²Ξ²ββββΞ±Ξ±Ξ±Ξ±Ξ²Ξ²Ξ²Ξ²ββββΞ²Ξ²Ξ²Ξ²ββββααααδδδδββββδδδδββββΞ³Ξ³Ξ³Ξ³Ξ²Ξ²Ξ²Ξ²ββββΞ²Ξ²Ξ²Ξ²ββββΞ±Ξ±Ξ±Ξ±
of variant anot is othereach of variantsare and
Note that if are two most general unifiers of types Ο and Ο then are variants of each other and similarly for Ο.
21 and ββββββββ21 ββββββββ ΟΟΟΟΟΟΟΟ and
Lambda calculus II 156
Unification Theorem.
(i) There is a recursive function U with input (after coding) a pair of types and with output which is either a substitutor or fail such that
ΟΟΟΟΟΟΟΟΟΟΟΟΟΟΟΟ
ΟΟΟΟΟΟΟΟ====ΟΟΟΟΟΟΟΟ
unifier no have and ifunifier a have and if
and for unifier generalmost a
fail),(U
(ii) There is a recursive function U with input (after coding) finite sets of equations between types and with output either a substitutor or fail such that
====
unifier no has E ifunifier a has E if
Efor unifier generalmost a
fail)(EU
Lambda calculus II 157
Proof.
Note that22112121 ΟΟΟΟβ‘β‘β‘β‘ΟΟΟΟΟΟΟΟβ‘β‘β‘β‘ΟΟΟΟββββΟΟΟΟββββΟΟΟΟβ‘β‘β‘β‘ΟΟΟΟββββΟΟΟΟ &
(i) Define by the following recursive loop with case distinction.
),( ΟΟΟΟΟΟΟΟU
Ξ±Ξ±Ξ±Ξ±====ΟΟΟΟ
ΟΟΟΟββββΞ±Ξ±Ξ±Ξ±ΟΟΟΟ====Ξ±Ξ±Ξ±Ξ±====ΟΟΟΟΞ±Ξ±Ξ±Ξ±
else if identity) (the if
failId
FVU
)(]:[),(
),(),( 2121 UU ΟΟΟΟββββΟΟΟΟΞ±Ξ±Ξ±Ξ±====Ξ±Ξ±Ξ±Ξ±ΟΟΟΟββββΟΟΟΟ
),(),(),( ),(),(22
U1
U12121 UUU 2222 ΟΟΟΟΟΟΟΟΟΟΟΟΟΟΟΟ====ΟΟΟΟββββΟΟΟΟΟΟΟΟββββΟΟΟΟ ΟΟΟΟΟΟΟΟΟΟΟΟΟΟΟΟ o
Where the last expression is considered to be fail if one of its parts is.
Lambda calculus II 158
Proof.
(i) By induction on the lexicografic order of pairs of natural numbers defined as follows:
# the number of variables in and #====ΟΟΟΟΟΟΟΟ ),(var ΟΟΟΟββββΟΟΟΟ ====ΟΟΟΟΟΟΟΟββββ ),(the number of arrows in .ΟΟΟΟββββΟΟΟΟ
By induction on pairs (# ,# ) ordered lexicograph-ically, one can show that is always defined. Moreover Usatisfies the specification.
),(var ΟΟΟΟΟΟΟΟ ),( ΟΟΟΟΟΟΟΟββββ
),( ΟΟΟΟΟΟΟΟU
(ii) If then define ,, nn11E ΟΟΟΟ====ΟΟΟΟΟΟΟΟ====ΟΟΟΟ==== K ),,()( ΟΟΟΟΟΟΟΟ====UEU
Where
n1 ΟΟΟΟββββββββΟΟΟΟ====ΟΟΟΟ L .n1 ΟΟΟΟββββββββΟΟΟΟ====ΟΟΟΟ L and
Lambda calculus II 159
Proposition on substitutors and equations.
Let Ξ be a basis, a term and a type such that ΞΞΞΞββββM TββββΟΟΟΟ).dom(ΞΞΞΞββββ)(MFV Then there is a finite set of equations
),,( ΟΟΟΟΞΞΞΞ==== MEE such that for all substitutors one hasββββ
ββββββββ ΟΟΟΟββββΞΞΞΞββββΟΟΟΟΞΞΞΞ====ββββ :|),,(| MME
),,(|:| ΟΟΟΟΞΞΞΞ====ββββββββΟΟΟΟββββΞΞΞΞ ββββββββ MEM 1
)(1
)(2
For some such that and have the same effect on type variables in
1ββββ ββββ 1ββββ. and ΟΟΟΟΞΞΞΞ
Lambda calculus II 160
Proof.
Define the set by induction on the structure of M:),,( ΟΟΟΟΞΞΞΞ ME
)(),,( xxE ΞΞΞΞ====ΟΟΟΟ====ΟΟΟΟΞΞΞΞ
),,(),,(),,( Ξ±Ξ±Ξ±Ξ±ΞΞΞΞβͺβͺβͺβͺΟΟΟΟββββΞ±Ξ±Ξ±Ξ±ΞΞΞΞ====ΟΟΟΟΞΞΞΞ NEMEMNEwhere Ξ± is a fresh variable
),,:(),.,( ΟΟΟΟ====Ξ²Ξ²Ξ²Ξ²ββββΞ±Ξ±Ξ±Ξ±βͺβͺβͺβͺΞ²Ξ²Ξ²Ξ²ΟΟΟΟβͺβͺβͺβͺΞΞΞΞ====ΟΟΟΟλλλλΞΞΞΞ MxEMxEwhere Ξ±, Ξ² are fresh variables
By induction on M one can show (using generation lemma) that (1) and (2) hold.
Lambda calculus II 161
Definition. Principal pair, principal type.
(i) Let Then (Ξ,Ο) is a principal pair (pp) for M if .ΞΞΞΞββββM
Β΄]&Β΄[Β΄:Β΄|)(:|)(
ΟΟΟΟβ‘β‘β‘β‘ΟΟΟΟΞΞΞΞββββΞΞΞΞββββββββββββΟΟΟΟββββΞΞΞΞΟΟΟΟββββΞΞΞΞ
ββββββββM2M1
Here .:,,::,,: ββββββββββββ ΟΟΟΟΟΟΟΟ====ΟΟΟΟΟΟΟΟ nn11nn11 xxxx KK
(ii) Let be closed. Then Ο is a principal type (pt) for M ifΞΞΞΞββββM
Β΄][Β΄:|)(:|)(
ΟΟΟΟβ‘β‘β‘β‘ΟΟΟΟββββββββββββΟΟΟΟββββΟΟΟΟββββ
ββββM2M1
Lambda calculus II 162
Remarks.
Note that if (Ξ,Ο) is a principal pair for M, then every variant (ΞΒ΄,ΟΒ΄) of (Ξ,Ο), in the obvious sense, is a principal pair for M.
Conversely, if (Ξ,Ο) and (ΞΒ΄,ΟΒ΄) are both principal pairs for M,then (ΞΒ΄,ΟΒ΄) is a variant of (Ξ,Ο) .
Moreover, if (Ξ,Ο) is a principal pair for M, then ).dom( ΞΞΞΞ====)(MFV
Lambda calculus II 163
Principal Type Theorem for Curry. ββββββββλλλλ
(i) There exists (after coding) a recursive function pp such that
ΟΟΟΟΞΞΞΞ
==== typeno has if
exists for typea if for pair principal a M
MMMpp
fail),(
)(
(ii) There exists (after coding) a recursive function pt such that for closed terms M one has
ΟΟΟΟ
==== typeno has if
exists for typea if for typeprincipal a M
MMMpt
fail)(
Lambda calculus II 164
Proof.(i) Let .:,,:,,)( nn11n1 xxxxMFV Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±Ξ±====ΞΞΞΞ==== KK 0 define and
If we put we have,Ξ²Ξ²Ξ²Ξ²====ΟΟΟΟ0
),,(|:|
:|
00
00
MEM
MM
ΟΟΟΟΞΞΞΞ====ββββββββββββββββΟΟΟΟββββΞΞΞΞββββββββββββ
ΟΟΟΟββββΞΞΞΞΟΟΟΟββββΞΞΞΞββββββββββββββββ
typea has
Define
====ΟΟΟΟΞΞΞΞββββ====ΟΟΟΟΞΞΞΞΟΟΟΟΞΞΞΞ
====ββββββββ
if if
failfail )),,(()),,((),(
)(00
0000
MEUMEU
Mpp
Then pp(M) satisfies the statement (i) of the theorem. Indeed, if M has a type, then follows from (i) in the proposition on substitutors and equations.
ββββββββ ΟΟΟΟββββΞΞΞΞββββ====ΟΟΟΟΞΞΞΞ 0000 MMEU :|)),,(( and
Lambda calculus II 165
To show that is a principal pair, suppose that also),( ββββββββ ΟΟΟΟΞΞΞΞ 00 Β΄.:Β΄| ΟΟΟΟββββΞΞΞΞ M
Let write Then also),(Β΄|~ MFVΞΞΞΞ====ΞΞΞΞ .Β΄~ 000ββββΟΟΟΟ====ΟΟΟΟΞΞΞΞ====ΞΞΞΞ ββββ and
0000 M ββββββββ ΟΟΟΟββββΞΞΞΞ :|
Hence by (ii) in the proposition on substitutors and equations, there is
1ββββ , acting in the same way as on such that 0ββββ 00 ΟΟΟΟΞΞΞΞ , ).,,(| 001 ME ΟΟΟΟΞΞΞΞ====ββββ
By the Unification Theorem is a most general unifier, hencethere is a such that
ββββ2ββββ .ββββββββ====ββββ o21
NowΒ΄~)( ΞΞΞΞ====ΞΞΞΞ====ΞΞΞΞ====ΞΞΞΞ====ΞΞΞΞ ββββββββββββββββ 012
000
andΒ΄)( ΟΟΟΟ====ΟΟΟΟ====ΟΟΟΟ====ΟΟΟΟ ββββββββββββββββ 012
000
This completes the case when M has a type.
Lambda calculus II 166
If M has no type, then there is no substitutor satisfying ),,,( 00 ME ΟΟΟΟΞΞΞΞ
hence
)()),,(( MppMEU 00 ========ΟΟΟΟΞΞΞΞ fail
(ii) Let M be closed and Then and we can put
).,()( ΟΟΟΟΞΞΞΞ====Mpp 0////====ΞΞΞΞ
ΟΟΟΟ====)(Mpt
Lambda calculus II 167
Proof.
(a) Type checking: given M and Ο, we have
])([:| ββββ====ΟΟΟΟββββββββββββΟΟΟΟββββ MptM
This is decidable by a pattern matching algorithm similar to the unification algorithm.
(b) Typability: given M, then M has a type iff fail.====////)(Mpt
Lambda calculus II 168
Decidability of the inhabitation problem for is shown equivalent to provability of Ο in the minimal intuitionistic proposition calculus PROP with only as connective and Ο considered as an element of PROP. Using finite Kripke models it can be shown that provability of Ο is decidable.
ββββββββλλλλ
ββββ
Theorem.the inhabitation problem for that is,ββββββββλλλλ ΟΟΟΟββββΞΞΞΞββββββββ ββββλλλλ :| MMis a decidable property of Ο.
Lambda calculus II 169
Decidability of the inhabitation problem for is shown equivalent to provability of Ο in the minimal intuitionistic proposition calculus PROP with only as connective and Ο considered as an element of PROP. Using finite Kripke models it can be shown that provability of Ο is decidable.
ββββββββλλλλ
ββββ
Theorem.the inhabitation problem for that is,ββββλλλλ ΟΟΟΟββββΞΞΞΞββββββββ ββββλλλλ :| MMis a decidable property of Ο.
Proof.
PROPin provable is -Churchin inhabited is -Curryin inhabited is
ΟΟΟΟββββββββλλλλΟΟΟΟββββββββλλλλΟΟΟΟ
Lambda calculus II 170
Now, we consider Ξ»2. The question whether type checking and typability is open. There is only a result showing that the problem of typability in Ξ»2 can be reduced to that of type checking.
Proposition.
decidable is decidable is :||:||):( ΟΟΟΟββββΟΟΟΟββββββββΟΟΟΟββββΟΟΟΟ Ξ»Ξ»Ξ»Ξ»Ξ»Ξ»Ξ»Ξ» MMMM 22
Proof.One has
)(:).(|:| Ξ±Ξ±Ξ±Ξ±ββββααααλλλλββββββββΟΟΟΟββββΟΟΟΟββββ MyxyM
The implication is obvious, sinceββββ
ΟΟΟΟΞ±Ξ±Ξ±Ξ±ββββΞ±Ξ±Ξ±Ξ±ββββΟΟΟΟλλλλββββ allfor )(:).(| yxy
The other implication follows from the lemma on typability of subterms.
Lambda calculus II 171
Theorem.
The inhabitation problem for Ξ»2 is undecidable.
Proof.
As for one can show the first equivalence,ββββλλλλ
PROP2in provable is Churchin inhabited is Curryin inhabited is
ΟΟΟΟββββββββλλλλΟΟΟΟββββββββλλλλΟΟΟΟ 22
where PROP2 is the constructive second-order propositional calculus. LΓΆb (1976) proved that the last property is undecidable.
Lambda calculus II 172
Theorem.
For λ¡ one has the following:
(i) Type checking is decidable.
(ii) Typability is trivially decidable, we showed that every Ξ»-term has a type.
(iii) The inhabitation problem for λ¡ is trivially decidable: all types are inhabited.
Lambda calculus II 173
Proof.
(i) Use the same method as for and the fact that T(Ο) = T(Ο) is decidable.
ββββλλλλ
(ii) In a motivation example for λ¡, we have shown that every Ξ»-term has a type .. where, 0 Ξ±Ξ±Ξ±Ξ±ββββαααα¡α¡α¡α¡α====ΟΟΟΟΟΟΟΟ0
(iii) All types are inhabited by the term Ξ.
Lambda calculus II 174
Lemma. Systems with subject conversion Let Ξ»- be a system of type assignment satisfying subject conversion i.e.
ΟΟΟΟββββΞΞΞΞββββ====ΟΟΟΟββββΞΞΞΞ ββββλλλλββββββββλλλλ :|&:| NNMM
(i) Suppose that some closed terms have the type and others not. Then the problem of type checking is undecidable.
Ξ±Ξ±Ξ±Ξ±ββββΞ±Ξ±Ξ±Ξ±
(ii) Suppose that some terms have a type and others not. Then the problem of typability is undecidable.
Lambda calculus II 175
Proof.
(i) If the set is decidable, then so is the set :|||),( ΟΟΟΟββββΟΟΟΟ MM
.:||| Ξ±Ξ±Ξ±Ξ±ββββΞ±Ξ±Ξ±Ξ±ββββ MM
This set is by assumption closed under = and non-trivial, hence by the ScottΒ΄s theorem is not recursive, a contradiction.
(ii) Similarly.
Lambda calculus II 176
Proposition.
For one has the followingβ©β©β©β©Ξ»Ξ»Ξ»Ξ»(i) Type checking problem is undecidable.(ii) Typability is trivially decidable: all terms have a type.
Proof.
(i) Using the subject conversion for , the statement (i) of the previous lemma applies and there are facts
β©β©β©β©Ξ»Ξ»Ξ»Ξ»
Ξ±Ξ±Ξ±Ξ±ββββΞ±Ξ±Ξ±Ξ±ββββ////Ξ±Ξ±Ξ±Ξ±ββββΞ±Ξ±Ξ±Ξ±ββββ :K|:I| and
(ii) For all .: ΟΟΟΟMM has one
It is not known whether inhabitation in is decidable. β©β©β©β©Ξ»Ξ»Ξ»Ξ»
Lambda calculus II 177
Lemma on reduction.Let be one of the systems Γ‘ la Curry. Then we haveββββλλλλ(i) ]Β΄:|&´´[:| ΟΟΟΟββββΞΞΞΞβ>β>β>β>ββββββββΟΟΟΟββββΞΞΞΞ ββββλλλλββββββββλλλλ ++++ MMMMM(ii) Ο is ihabited in Ο is inhabited in ββββββββλλλλ ++++ ββββλλλλ
Proof.(i) Β΄.Β΄)( MMMM Ξ²Ξ²Ξ²Ξ²Ξ²Ξ²Ξ²Ξ² ====β>β>β>β>ββββ implies since trivialis
.:)( ΟΟΟΟββββ M of derivation on theinduction by The only interesting case is when the last applied rule is an application of rule EQ. Suppose
ΟΟΟΟ====ΟΟΟΟ Ξ²Ξ²Ξ²Ξ²
::
MMMM 11
The induction hypothesis says that there is ´´ 111 MMM Ξ²Ξ²Ξ²Ξ²β>β>β>β> such that and one has By the Church-Rosser theorem,.Β΄:| ΟΟΟΟββββΞΞΞΞ ββββλλλλ 1M MM1 and Β΄have a common reduct, say M Β΄. But by the subject reduction theorem, we have and the proof is complete. ΟΟΟΟββββΞΞΞΞ ββββλλλλ Β΄:| M
Lambda calculus II 178
(ii) By (i).
Proposition. The systems . ++++ββββλλλλ
For the systems one has the following: ++++ββββλλλλ
(i) Type checking is undecidable
(ii) Typability is undecidable for but trivially decidable for
,++++++++ λλλλββββλλλλ 2 and .++++++++ β©β©β©β©Ξ»Ξ»Ξ»Ξ»Ξ»Β΅Ξ»Β΅Ξ»Β΅Ξ»Β΅ and
(iii) The status of the inhabitation problem is the same for both.ββββλλλλββββλλλλ ++++ and
Lambda calculus II 179
Proof.
(i) Subject conversion holds for the systems by definition. In all systems It follows from (i) of the lemma on reduction and the fact that that type checking is undecidable by (i) of the lemma on systems
++++ββββλλλλ.:I Ξ±Ξ±Ξ±Ξ±ββββΞ±Ξ±Ξ±Ξ±
Ξ±Ξ±Ξ±Ξ±ββββΞ±Ξ±Ξ±Ξ±ββββ//// :K|.ββββλλλλ
(ii) We have already shown that terms without a normal form have no type in Hence by the reduction lemma these terms have no type in Since for these systems there are terms that have a type by (ii) of lemma on systems with subject conversion the undecidability of typability for follows.
.2λλλλββββλλλλ and .++++++++ λλλλββββλλλλ 2or
2λλλλββββλλλλ and
(iii) By (ii) of the reduction lemma.
Lambda calculus II 180
Lemma. Typing of normal forms.
Let M be a term in normal form. Then
ΟΟΟΟββββββββΟΟΟΟββββ ββββλλλλββββλλλλ :|:| MMA
Lambda calculus II 181
Lemma. Typing of normal forms.
Let M be a term in normal form. Then
ΟΟΟΟββββββββΟΟΟΟββββ ββββλλλλββββλλλλ :|:| MMA
Proof.
By induction on the given derivation, using the fact that ).(MM Aββββ
Lambda calculus II 182
Proposition. Systems .Aββββλλλλ
For systems we have the following:,Aββββλλλλ
(i) The problem of type checking is undecidable for the systems ,Aββββλλλλ. and AAA β©β©β©β©Ξ»Ξ»Ξ»Ξ»Ξ»Β΅Ξ»Β΅Ξ»Β΅Ξ»Β΅Ξ»Ξ»Ξ»Ξ» ,2
(ii) The problem of typability is undecidable for the systems and but it is trivially decidable for the systems
,Aββββλλλλ,A2λλλλ AA β©β©β©β©Ξ»Ξ»Ξ»Ξ»Ξ»Β΅Ξ»Β΅Ξ»Β΅Ξ»Β΅ and
(all terms are typable).
(iii) The problem of inhabitation is trivially decidable for all four systems includin the rule A (all types are inhabited).
Lambda calculus II 183
Proof.
(i) By lemma on typing normal forms and the fact that in all four basic Curry systems and (i) of subject conversion systemslemma, we get undecidability.
Ξ±Ξ±Ξ±Ξ±ββββΞ±Ξ±Ξ±Ξ±ββββ//// :K|
(ii) similarly.
(iii) The inhabitation problem becomes trivial: in all four systems one has for all types Ο. This follows from the facts thatΟΟΟΟΩΩΩΩββββ :|
),)((:Y| ΟΟΟΟββββΟΟΟΟββββΟΟΟΟββββ ββββλλλλ A AββββλλλλΩΩΩΩ====Ξ²Ξ²Ξ²Ξ² and YI is closed under the rule EQ.