Compositional Characterisations of λ-terms using Intersection Types ?
M. Dezani-Ciancaglini a F. Honsell b Y. Motohama b a Dipartimento
di Informatica, Universit` a di Torino, corso Svizzera 185, 10149 Torino, Italy
b Dipartimento
di Matematica ed Informatica, Universit` a di Udine, via delle Scienze 208, 33100 Udine, Italy
Abstract We show how to characterise compositionally a number of evaluation properties of λ-terms using Intersection Type assignment systems. In particular, we focus on termination properties, such as strong normalisation, normalisation, head normalisation, and weak head normalisation. We consider also the persistent versions of such notions. By way of example, we consider also another evaluation property, unrelated to termination, namely reducibility to a closed term. Many of these characterisation results are new, to our knowledge, or else they streamline, strengthen, or generalise earlier results in the literature. The completeness parts of the characterisations are proved uniformly for all the properties, using a set-theoretical semantics of intersection types over suitable kinds of stable sets. This technique generalises Krivine’s and Mitchell’s methods for strong normalisation to other evaluation properties. Key words: λ-calculus; Intersection Types; Normalisation Properties; Set-theoretical Semantics of Types.
? Partially supported by EU within the FET - Global Computing initiative, project DART ST-2001-33477 and by MURST Cofin’01 project COMETA, MURST Cofin’02 project McTati. The funding bodies are not responsible for any use that might be made of the results presented here. Email addresses:
[email protected] (M. Dezani-Ciancaglini),
[email protected] (F. Honsell),
[email protected] (Y. Motohama).
Preprint submitted to Elsevier Preprint
14 April 2005
Introduction The intersection-types discipline was introduced in [10] as a means of overcoming the limitations of Curry’s type assignment system. Subsequently it was used in [5] as a tool for proving Scott’s conjecture concerning the completeness of the set-theoretic semantics for simple types. Very early on, however, it was realised that intersection type theories are a very expressive tool for giving compositional characterisations (i.e. a characterisations based on properties of proper subterms) of evaluation properties of λ-terms. There are two seminal results in this respect. The first result is that the Ω-free fragment of intersection-types allows one to type all and only the strongly normalising terms. This is largely a folklore result; the first published proof appears in [25]. The second result is the filter model construction based on the intersection type theory BCD, carried out in [5]. This result was the first to show that there is a very tight connection between intersection types and compact elements in ω-algebraic denotational models of λ-calculus. This connection later received a categorically principled explanation by Abramsky in the broader perspective of “domain theory in logical form” [1]. Since then, the number of intersection type theories, used for studying the fine structure of the denotational semantics of untyped λ-calculus, has increased considerably (e.g. [12,11,19,16,2,24,18]). In all these cases the corresponding intersection type assignment systems are used to provide finite logical presentations of particular domain models, which can thereby be viewed also as filter models. And hence, intersection type theories provide characterisations of particular semantical properties. In this paper we address the problem of investigating uniformly the use of intersection type theories, and corresponding type assignment systems, for giving a compositional characterisation of evaluation properties of λ-terms. In particular we discuss termination properties such as strong normalisation, normalisation, head normalisation, weak head normalisation. We consider also the persistent versions of such notions (see Definition 2.2). By way of example we consider also another evaluation property, unrelated to termination, namely reducibility to a closed term. Many of the characterisation results that we give are indeed inspired by earlier semantical work on filter models of the untyped λ-calculus, but they are rather novel in spirit. We focus, in fact, on proof-theoretic properties of intersection type assignment systems per se. Most of our characterisations are therefore 2
new, to our knowledge, or else they streamline, strengthen, or generalise earlier results in the literature. The completeness part of the characterisations is proved uniformly for all the properties. We use a very elementary presentation of the technique of logical relations phrased in terms of a set-theoretical semantics of intersection types over suitable kinds of stable sets. This technique generalises Krivine’s [20] and Mitchell’s [22] proof methods for strong normalisation, to other evaluation properties. The paper is organised as follows. In Section 1 we introduce the intersection type language, intersection type theories and type assignment systems. We prove also some general results about such systems. In Section 2 we introduce the various properties of λ-terms on which we shall focus. In Section 3 we give the compositional characterisations of such properties and we prove the soundness of the characterisations. Completeness is proved in Section 4. Final remarks and open problems appear in Section 5. The auxiliary notion of polarised normal form, which is instrumental to the study of persistent normal forms, is discussed in the Appendix. An extended abstract of the present paper is [15].
1
Intersection type theories and type assignment systems
Intersection types are syntactical objects which are built inductively by closing a given set C of type atoms (constants) under the function type constructor → and the intersection type constructor ∩. Definition 1.1 (Intersection type languages) The intersection type language over C, denoted by T = T(C), is defined by the following abstract syntax: T = C | T→T | T ∩ T. Notation 1.2 Upper case Roman letters i.e. A, B, . . ., will denote arbitrary types. In writing intersection-types we shall use the following convention: the constructor ∩ takes precedence over the constructor → and both associate to the right. Moreover An → B will be short for A · · → A} → B. | → ·{z n
Much of the expressive power of intersection type disciplines comes from the fact that types can be endowed with a preorder relation ≤, which induces the structure of a meet semi-lattice with respect to ∩.
3
Definition 1.3 (Intersection type preorder) Let T = T(C) be an intersection type language. An intersection type preorder over T is a binary relation ≤ on T satisfying the following set 50 (“nabla-zero”) of axioms and rules: (refl) A ≤ A
(idem) A ≤ A ∩ A
(inclL ) A ∩ B ≤ A (mon)
(inclR ) A ∩ B ≤ B
A ≤ A0 B ≤ B 0 A≤B B≤C (trans) A ∩ B ≤ A0 ∩ B 0 A≤C
Notation 1.4 We will write A ∼ B for A ≤ B and B ≤ A. Notice that associativity and commutativity of ∩ (modulo ∼) follow easily from the above axioms and rules. T
Notation 1.5 Since ∩ is commutative and associative, we will write i≤n Ai T for A1 ∩ . . . ∩ An . Similarly we will write i∈I Ai where we assume that I denotes always a finite non-empty set. Possibly effective, syntactical presentations of intersection type preorders can be given using the notion of intersection type theory. An intersection type theory includes always the basic set 50 for ≤ and possibly other special purpose axioms and rules. Definition 1.6 (Intersection type theories) Let T = T(C) be an intersection type language, and let 5 be a collection of axioms and rules for deriving judgements of the shape A ≤ B, with A, B ∈ T. The intersection type theory Σ(C, 5) is the set of all judgements A ≤ B derivable from the axioms and rules in 50 ∪ 5. Notation 1.7 When we consider the intersection type theory Σ(C, 5), we will write C5 for C, T5 for T(C), Σ5 for Σ(C, 5). Moreover A ≤5 B will be short for (A ≤ B) ∈ Σ5 . Finally we will write A∼5 B for A ≤5 B ≤5 A. In Figure 1 appears a list of special purpose axioms and rules which have been considered in the literature. We give just a few lines of motivation for each. Axiom (Ω) states that the resulting type preorder has a maximal element. Axiom (Ω) is particularly meaningful when used in combination with the Ωtype assignment system, which essentially treats Ω as the universal type of all 4
(Ω)
A≤Ω
(Ω-η)
Ω ≤ Ω→Ω
(Ω-lazy)
A→B ≤ Ω→Ω
(→-∩)
(A→B) ∩ (A→C) ≤ A→B ∩ C
(η)
A0 ≤ A B ≤ B0 A→B ≤ A0 →B 0
(ω-Scott)
Ω→ω ∼ ω
(ω-Park)
ω→ω ∼ ω
(ωϕ)
ω≤ϕ
(ϕ→ω)
ϕ→ω ∼ ω
(ω→ϕ)
ω→ϕ ∼ ϕ
Fig. 1. Some special purpose Axioms and Rules concerning ≤.
λ-terms (see Definition 1.11). The meaning of the axioms (Ω-η), (Ω-lazy), (→-∩) and of the rule (η) can be grasped easily if we consider the set theoretic semantics of intersection types. According to this semantics types are interpreted as subsets of the domain of discourse, ∩ is interpreted as set-theoretic intersection, ≤ is interpreted as set inclusion, A→B as the set of functions which map each element of A into an element of B. For instance, in combination with Axiom (Ω), Axiom (Ω-η) expresses the fact that all the objects in our domain of discourse are total functions, i.e. that Ω is equal to Ω→Ω [5]. However, if we want to capture only those terms which truly represent functions, as is necessary, for instance, in discussing the lazy λ-calculus [2], we cannot assume axiom (Ω-η) in order to ensure that all functions are total. To this end we can postulate instead the weaker property (Ω-lazy). According to the set theoretic semantics, this axiom states, in effect, simply that an element which is a function, (since it maps A into B) maps also the whole universe into itself. The set-theoretic meaning of Axiom (→-∩) is immediate: if a function maps 5
CB a
= C∞
Ba
= {(→-∩), (η)}
[4]
CAO
= {Ω}
AO
= Ba ∪ {(Ω), (Ω-lazy)}
[2]
CBCD = {Ω} ∪ C∞
BCD
= Ba ∪ {(Ω), (Ω-η)}
[5]
CS c
= {Ω, ω}
Sc
= BCD ∪ {(ω-Scott)}
[26]
CP a
= {Ω, ω}
Pa
= BCD ∪ {(ω-Park)}
[23]
CCDZ = {Ω, ϕ, ω}
CDZ
= BCD ∪ {(ωϕ), (ϕ→ω), (ω→ϕ)}
[11]
CDHM = {Ω, ϕ, ω}
DHM = BCD ∪ {(ωϕ), (ω-Scott), (ω→ϕ)} [15]
Fig. 2. Type Theories: atoms, axioms and rules.
A into B, and also A into C, then, actually, it maps the whole A into the intersection of B and C [5]. Rule (η) is also very natural set-theoretically: it asserts that the arrow constructor is contra-variant in the first argument and covariant in the second one. Namely, if a function maps A into B, and we take a subset A0 of A and a superset B 0 of B, then this function will map also A0 into B 0 [5]. The remaining axioms express peculiar properties of D∞ -like inverse limit models [12,11,19]. The element Ω plays a very special role in the development of the theory. Therefore we stipulate the following blanket assumption: if Ω ∈ C5 then (Ω) ∈ 5. We introduce in Figure 2 a list of significant intersection type theories which have been extensively considered in the literature. We shall denote such theories as Σ5 with various different names 5, corresponding to the initial of the authors which have first considered the λ-model induced by such a theory [4,2,5,26,23,11,15]. For each such 5 we specify in Figure 2 the type theory Σ5 = Σ(C, 5) by giving the set of constants C5 and the set 5 of extra axioms and rules taken from Figure 1. Here C∞ is an infinite set of fresh atoms, i.e. different from Ω, ϕ, ω. The last column contains the reference to the paper where the λ-model induced by such a theory was defined. Now that we have introduced intersection type theories we have to explain how to capitalise effectively on their expressive power. This is achieved via 6
the crucial notion of intersection type assignment system. This is a natural extension of Curry’s type assignment type to intersection types. First we need some preliminary definitions and notations. Definition 1.8 i) A 5-basis is a set of statements of the shape x:B, where B ∈ T5 , all whose variables are distinct. ii) We will write x ∈ Γ as short for ∃A x:A ∈ Γ, i.e. x occurs as the subject of an assertion in Γ. iii) If Γ, Γ0 are 5-basis then Γ ] Γ0 is the 5-basis defined by: Γ ] Γ0 = {x: A ∩ B | x: A ∈ Γ and x: B ∈ Γ0 } ∪{x: A | x: A ∈ Γ and x ∈ / Γ0 } ∪{x: B | x: B ∈ Γ0 and x ∈ / Γ}. iv) An intersection type assignment system λ∩5 relative to Σ5 is a formal system for deriving judgements of the form Γ `5 M : A, where the subject M is an untyped λ-term, the predicate A is in T5 , and Γ is a 5-basis. v) We say that a term M is typable in λ∩5 , for a given 5-basis Γ, if there is a type A ∈ T5 such that the judgement Γ `5 M : A is derivable. As usual λ-terms are considered modulo α-conversion. We denote by V the set of term variables and by F V (M) the set of free variables of the term M. Definition 1.9 (Basic Type Assignment System) Let Σ5 be a type theory. The basic type assignment system λ∩5 B is a formal system for deriving judgements of the shape Γ `5 M : A. Its rules are the following: B Γ, x:A `5 B M : B (→I) 5 Γ `B λx.M : A→B
x:A ∈ Γ (Ax) Γ `5 B x:A (→E)
5 5 Γ `5 Γ `5 B M : A → B Γ `B N : A B M : A Γ `B M : B (∩I) Γ `5 Γ `5 B MN : B B M : A∩B
Γ `5 B M : A A ≤5 B (≤5 ) Γ `5 B M : B Example 1.10 Self-application can be easily typed in λ∩5 B , as follows. x:(A→B) ∩ A `5 B x:(A→B) ∩ A x:(A→B) ∩ A `5 B x:A→B
(≤5 )
x:(A→B) ∩ A `5 B x:(A→B) ∩ A x:(A→B) ∩ A `5 B x:A
x:(A→B) ∩ A `5 B xx : B `5 B λx.xx : (A→B) ∩ A→B 7
(→I)
(≤5 )
(→E)
If Ω ∈ C5 , in line with the intended set-theoretic interpretation of Ω as the universe, we extend the Basic Type Assignment System with a suitable axiom for Ω: Definition 1.11 (Ω-type Assignment System) Let Σ5 be a type theory with Ω ∈ C5 . The axioms and rules of the Ω-type assignment system λ∩5 Ω are those of the Basic type Assignment System, together with the further axiom: (Ax-Ω)
Γ `5 Ω M : Ω.
Example 1.12 Also non-strongly normalising terms can be typed in λ∩5 Ω even with a type A6∼5 Ω. Note the usage of the axiom (Ax-Ω). Let ∆ ≡ λx.xx. y:Ω, x:A `5 Ω x:A y:Ω `5 Ω λx.x : A→A `5 Ω λyx.x : Ω→A→A
(→I) (→I)
`5 Ω ∆∆ : Ω
`5 Ω (λyx.x)(∆∆) : A→A
(→E)
An interesting example is that the Fixed-point Combinator Y ≡ λf.(λx.f (xx))(λx.f (xx)) can be typed in λ∩5 Ω as follows. f :Ω → A, x:Ω `5 Ω f :Ω → A
f :Ω → A, x:Ω `5 Ω xx : Ω
f :Ω → A, x:Ω `5 Ω f (xx) : A f :Ω → A `5 Ω λx.f (xx) : Ω → A
(→I)
(→E) f :Ω → A `5 Ω λx.f (xx) : Ω
f :Ω → A `5 Ω (λx.f (xx))(λx.f (xx)) : A `5 Ω λf.(λx.f (xx))(λx.f (xx)) : (Ω → A) → A
(→I)
For ease of notation, we assume that the symbol Ω is reserved for the type 5 constant used in the system λ∩5 Ω , and hence we forbid Ω ∈ C when we deal 5 with λ∩B . 5 Notation 1.13 In the following λ∩5 will range over λ∩5 B and λ∩Ω . More 5 precisely we convene that λ∩5 stands for λ∩5 Ω whenever Ω ∈ C , and for 5 λ∩5 B otherwise. Similarly for ` .
We refer to [7] for a detailed account on the interest and differences of the two intersection type assignment systems introduced above. Notice that the structural rules of (weakening) and (strengthening) are admissible in all λ∩5 s: (weakening)
Γ `5 M : A Γ `5 M : A (strengthening) Γ, x:B `5 M : A ΓdM `5 M : B
where ΓdM = {x:B | x ∈ F V (M)}. 8
(→E)
Another admissible rule allowing us to strengthen the premises is the following: (≤5 L)
Γ, x:B `5 M : A C ≤5 B 5 Γ, x:C ` M : A
Lastly notice also that the intersection elimination rules (∩E)
Γ `5 M : A ∩ B Γ `5 M : A
Γ `5 M : A ∩ B Γ `5 M : B
can immediately be proved to be derivable in all λ∩5 ’s using (≤5 ). We prove now a crucial technical result concerning intersection-type theories. It is a form of generation (or inversion) lemma, which provides conditions for “reversing” some of the rules of the type assignment systems λ∩5 . Notation 1.14 When we write “...assume A6∼5 Ω...” we mean that this con5 dition is always true when we deal with `5 B , while it must be checked for `Ω . Theorem 1.15 (Generation Lemma) Let Σ5 be a type theory. i) Assume A6∼5 Ω. Then Γ `5 x:A if and only if x:B ∈ Γ and B ≤5 A for some B ∈ T5 . ii) Assume A6∼5 Ω. Then Γ `5 MN : A if and only if Γ `5 M : Bi →Ci , T Γ `5 N : Bi , and i∈I Ci ≤5 A for some non-empty set I and Bi , Ci ∈ T5 . iii) Γ `5 λx.M : A if and only if Γ, x:Bi `5 M : Ci , and for some non-empty set I and Bi , Ci ∈ T5 .
T
i∈I (Bi →Ci )
≤5 A
Proof. The proof of each (⇐) is easy. So we only treat (⇒). i) Easy by induction on derivations, since only the axioms (Ax), (Ax-Ω), and the rules (∩I), (≤5 ) can be applied. Notice that the condition A6∼5 Ω implies that Γ `5 x : A cannot be obtained just using axiom (Ax-Ω). ii) By induction on derivations. The only interesting case is when A ≡ A1 ∩ A2 and the last rule applied is (∩I): (∩I)
Γ `5 MN : A1 Γ `5 MN : A2 . Γ `5 MN : A1 ∩ A2
The condition A6∼5 Ω implies that we cannot have A1 ∼5 A2 ∼5 Ω. We do the proof for A1 6∼5 Ω and A2 6∼5 Ω, the other cases can be treated 9
similarly. By induction there are I, Bi , Ci , J, Dj , Ej such that ∀i ∈ I. Γ `5 M : Bi →Ci , Γ `5 N : Bi , ∀j ∈ J. Γ `5 M : Dj →Ej , Γ `5 N : Dj , T
and moreover i∈I Ci ≤5 A1 , T T ( i∈I Ci ) ∩ ( j∈J Ej ) ≤5 A.
T
j∈J
Ej ≤5 A2 . So we are done since
iii) If A∼5 Ω we can choose B ≡ C ≡ Ω. Otherwise the proof is by induction on derivations. Notice that Γ `5 λx.M : A cannot be obtained just using axiom (Ax-Ω). The only interesting case is again when A ≡ A1 ∩ A2 and the last rule applied is (∩I): (∩I)
Γ `5 λx.M : A1 Γ `5 λx.M : A2 . Γ `5 λx.M : A1 ∩ A2
As in the proof of (ii) we only consider the case A1 6∼5 Ω, and A2 6∼5 Ω .By induction there are I, Bi , Ci , J, Dj , Ej such that ∀i ∈ I. Γ, x:Bi `5 M : Ci , ∀j ∈ J. Γ, x:Dj `5 M : Ej , T
i∈I (Bi →Ci )
So we are done since (
≤5 A1 &
T
T
j∈J (Dj →Ej )
i∈I (Bi →Ci ))
∩(
≤5 A2 .
T
j∈J (Dj →Ej ))
≤5 A.
Special cases of this theorem have already appeared in the literature [5,12,11,19]. We conclude this section by characterising those type assignment systems for which types are preserved under β-expansion, i.e. those systems for which the following rule is admissible: (β-exp)
M −→β N Γ `5 N : A Γ `5 M : A
It will be convenient to consider also the rule of βI-expansion, denoted by (βI-exp), which amounts to the restriction of Rule (β-exp) to the case where M −→β N is obtained by contracting only λ-I-redexes. We recall that (λx.M)N is a λ-I-redex if x ∈ F V (M). Theorem 1.16 (Characterization of β-expansion) i) Rule (βI-exp) is admissible in λ∩5 for all theories Σ5 . 5 ii) Rule (β-exp) is admissible in λ∩5 Ω for all theories Σ . 5 iii) Rule (β-exp) is not admissible in λ∩5 B for any theory Σ .
10
Proof. i) We will only show in detail that if Γ `5 M[x := N] : A then Γ `5 (λx.M)N : A. Then by a straightforward, double induction on −→β and on derivations we get the result. So assume that D is a derivation of Γ `5 M[x := N] : A. Let Γi `5 N : Bi for i ∈ I be all the statements in D whose subject is N. Without loss of generality we can assume that x does not occur in Γ. Since x ∈ F V (M), I is non empty, hence we have that Γ ⊆ Γi but Γ F V (N) = Γi F V (N). So using rules (strengthening) T and (∩I), we have that Γ `5 N : i∈I Bi . Moreover, one can easily T see, by induction on M, that Γ, x : i∈I Bi `5 M : A. Thus, by rule T (→I), we have Γ `5 λx.M : i∈I Bi →A. Hence, by (→E) we can get Γ `5 (λx.M)N : A. ii) The proof proceeds as above except for the fact that we have to consider also the case that x ∈ / F V (M). Using first (weakening) and then (→I) 5 we get Γ `Ω λx.M : Ω→A, then using (Ax-Ω) and (→E) we finally get Γ `5 Ω (λxM)N : A. iii) Recall that the Generation Lemma implies that in a theory where Ω ∈ / 5 C , a term with a free variable is typable if and only if that variable occurs in the context. So for any theory 5, such that Ω ∈ / C5 , (λyx.x)z 5 is not typable from the empty context in λ∩B , but clearly `5 B λx.x : A→A for all types A.
2
Some distinguished properties of λ-terms
In this section we introduce the distinguished classes of λ-terms which we shall focus on in this paper. We shall consider first termination properties. In particular we shall discuss the crucial property of being strongly normalising and the three properties of having a β-normal form, of having a head normal form, and of having a weak head normal form. Definition 2.1 (Normalization property) i) M is a normal form, M ∈ NF, if M cannot be further reduced; ii) M is strongly normalising, M ∈ SN, if all reductions starting at M are finite; iii) M has a normal form, M ∈ N, if M reduces to a normal form; iv) M has a head normal form, M ∈ HN, if M reduces to a term of the form ~ (where possibly y appears in ~x); λ~x.y M 11
v) M has a weak head normal form, M ∈ WN, if M reduces to an abstraction or to a term starting with a free variable. For each of the above properties, but SN, in the above definition, we shall consider also the corresponding persistent version (see Definition 2.2). Persistently normalising terms have been introduced in [9]. Definition 2.2 (Persistent normalisation property) ~ ∈ N for all terms i) A term M is persistently normalising, M ∈ PN, if M N ~ in N. N ii) A term M is a persistently normalising normal form, M ∈ PNF, if it is both persistently normalising and it is a normal form. ~ ∈ HN for iii) A term M is persistently head normalising, M ∈ PHN, if M N ~. all terms N ~ ∈ WN iv) A term M is persistently weak normalising, M ∈ PWN, if M N ~ for all terms N. Example 2.3 Let I ≡ λx.x, ∆ ≡ λx.xx, Y ≡ λf.(λx.f (xx))(λx.f (xx)), K ≡ λxy.x. • • • • • • • • •
λx.yx ∈ PNF. λx.x∆∆ ∈ NF, but λx.x∆∆ ∈ / PNF, since (λx.x∆∆)I −→ −→β ∆∆ ∈ / N. II ∈ SN, but II ∈ / NF and II ∈ / PN, since II∆∆ −→ −→β ∆∆ ∈ / N. (λx.y)(∆∆) ∈ PN, but (λx.y)(∆∆) ∈ / PNF and (λx.y)(∆∆) ∈ / SN. λy.(λx.y∆)(∆∆) ∈ N, but λy.(λx.y∆)(∆∆) ∈ / SN and λy.(λx.y∆)(∆∆) ∈ / PN, since (λy.(λx.y∆)(∆∆))∆ −→ −→β ∆∆ ∈ / N. λx.y(∆∆) ∈ PHN, but λx.y(∆∆) ∈ / N. λx.x(∆∆) ∈ HN, but λx.x(∆∆) ∈ / N and λx.x(∆∆) ∈ / PHN, since (λx.x(∆∆))∆ −→β ∆(∆∆) ∈ / HN. YK ∈ PWN, but YK ∈ / HN. λx.∆∆ ∈ WN, but λx.∆∆ ∈ / HN and λx.∆∆ ∈ / PWN, since (λx.∆∆)M −→β ∆∆ ∈ / WN.
The following proposition, represented pictorially by Figure 3, illustrates mutual implications between the above notions: Proposition 2.4 The following strict inclusions hold: PNF NF SN N PNF PN N HN PN PHN HN WN PHN PWN WN. No other inclusion holds between the above sets. 12
WN A Z444 4
PWN ];;
HN D U+ ;;
++
PHN Z44 N I W. 44 ...
PNV, SNY22 ,, ,, ,, ,,
22
NF E
PNF
Fig. 3. Inclusion between sets of λ-terms
The following characterisation of strongly normalising terms will be very useful in the sequel. Proposition 2.5 ([27,18]) The set SN is the least set of terms closed under the following rules: M1 ∈ SN, . . . , Mn ∈ SN, (n ≥ 0) xM1 . . . Mn ∈ SN
M ∈ SN λx.M ∈ SN
M[x := N]M1 . . . Mn ∈ SN N ∈ SN, (n ≥ 0) (λx.M)NM1 . . . Mn ∈ SN The proof of the above proposition follows by suitable inductions. Intersection types can be used to characterise compositionally also other evaluation properties of terms, which are not linked to termination. In this paper we shall consider, by way of example, the property of reducing to a closed term. Hence we conclude this section with the definition of: Definition 2.6 (Closable term) M is closable, M ∈ C, if M reduces to a closed term.
3
Characterising compositionally properties of λ-terms
In this section we put to use intersection type disciplines to give a compositional characterisation of evaluation properties of λ-terms. In view of Theorem 1.16(i) we can only characterise properties which are closed under, at least, βI-expansion, hence we will not be able to characterise NF and PNF. In this section we give the main result of the paper, Theorem 3.2. For each of the properties introduced in Section 2, Theorem 3.2 provides a compositional 13
characterisations in terms of intersection type assignment systems. Soundness of these characterisations will be proved in the present section (and in the Appendix) and completeness will be proved in Section 4. Some of the properties characterised in Theorem 3.2 had received already characterisations in terms of intersection type disciplines. The most significant case is that of strongly normalising terms. One of the original motivations for introducing intersection types in [25] was precisely that of achieving such a characterisation. Alternative characterisations appear in [21,4,20,17,3,18]. In [11] both normalising and persistently normalising terms had been characterised using intersection types. The type assignment system in [11] has also been discussed in [8]. Closed terms were characterised in [19]. The characterisations appearing in Theorem 3.2 strengthen and generalise all earlier results, since all previous papers consider only specific type theories, and hence in our view Theorem 3.2 appears more intrinsic. Before giving the main theorem a last definition is necessary. Definition 3.1 i) A type theory Σ5 is an arrow-type theory if Ω ∈ C5 , the T axioms of Ba are admissible in Σ5 and ∀ψ ∈ C5 ∃I, {Ai , Bi }i∈I .ψ∼5 i∈I (Ai →Bi ). ii) A type A contains a type B (notation B ∈ A) if and only if A ≡ C[B] for some context C[ ]. iii) A basis Γ contains a type A (notation A ∈ Γ) if and only if there is x:B ∈ Γ such that A ∈ B. iv) A type A contains a type B modulo ∼5 (notation B ∈5 A) if and only if there is A0 ∼5 A such that B ∈ A0 . v) A basis Γ contains a type A modulo ∼5 (notation A ∈5 Γ) if and only if there is x:B ∈ Γ such that A ∈5 B. The theories ΣS c , ΣP a , ΣCDZ and ΣDHM of Figure 2 are arrow-type theories. For example, Ω ∈ / ω but Ω ∈S c ω since ω ∼S c Ω → ω and Ω ∈ Ω → ω. Finally we can state the main result: Theorem 3.2 (Characterization) 1 Normalisation properties i) (strongly normalising terms) A λ-term M ∈ SN if and only if for all type theories Σ5 there exist A ∈ T5 and a 5-basis Γ such that Γ `5 M : A. Moreover in the system λ∩BBa the terms satisfying the latter property are precisely the strongly normalising ones. ii) (normalising terms) A λ-term M ∈ N if and only if for all type theories 14
Σ5 such that {Ω} ⊂ C5 , 1 there exist A ∈ T5 and a 5-basis Γ such that Γ `5 / A, Γ. Moreover in the system λ∩BCD the terms Ω M : A and Ω ∈ Ω satisfying the latter property are precisely the ones which have a normal the terms typable with type ϕ in form. Furthermore, in the system λ∩CDZ Ω the CDZ-basis all of whose predicates are ω, are precisely the ones which have a normal form. iii) (head normalising terms) A λ-term M ∈ HN if and only if for all type theories Σ5 such that Ω ∈ C5 , and for all A ∈ T5 there exist a 5-basis Γ m n and two integers m, n such that Γ `5 Ω M : (Ω → A) → A. Moreover in the system λ∩BCD the terms satisfying the latter property are precisely the Ω ones which have a head normal form. Furthermore, in the system λ∩DHM Ω the terms typable with type ϕ in the DHM-basis all of whose predicates are ω, are precisely the ones which have a head normal form. iv) (weak head normalising terms) A λ-term M ∈ WN if and only if for all type theories Σ5 such that Ω ∈ C5 , there exists a 5-basis Γ such that AO Γ `5 the terms satisfying Ω M : Ω → Ω. Moreover in the system λ∩Ω the latter property are precisely the ones which have a weak head normal form. 2 Persistent normalisation properties i) (persistently normalising terms) A λ-term M ∈ PN if and only if for all arrow-type theories Σ5 and all A ∈ T5 with Ω ∈ / 5 A there exists a 55 basis Γ such that Ω ∈ / 5 Γ and Γ `Ω M : A. Moreover in the system λ∩CDZ Ω the terms typable with type ω in the CDZ-basis all of whose predicates are ω are precisely the persistently normalising ones. ii) (persistently head normalising terms) A λ-term M ∈ PHN if and only if for all type theories Σ5 such that Ω ∈ C5 and all A ∈ T5 there exists a n 5-basis Γ and an integer n such that Γ `5 Ω M : Ω → A. Moreover in the systems λ∩SΩc and λ∩DHM the terms typable with type ω in the basis all Ω of whose predicates are ω, are precisely the persistently head normalising ones. iii) (persistently weak normalising terms) A λ-term M ∈ PWN if and only if for all type theories Σ5 such that Ω ∈ C5 and all integers n there exists n AO a 5-basis Γ such that Γ `5 Ω M : Ω → Ω. Moreover in the system λ∩Ω the terms satisfying the latter property are precisely the persistently weak normalising ones. 3 Closability(closed terms) A λ-term M ∈ C if and only if for all type theories Σ5 such that Ω ∈ C5 and ω ∼5 ω → ω for some ω ∈ C5 , M is typable with type ω, for the empty 5-basis. Moreover in the system λ∩PΩ a the terms satisfying the latter property are precisely the terms which reduce to closed terms. 1
The condition {Ω} ⊂ C5 says that C5 contains Ω and at least one other constant.
15
The proofs of the only if parts of the Theorem are mainly straightforward inductions and case split, and follow, but the case of persistently normalising terms (2.i), which is proved in the Appendix. The syntactic characterisation of the persistently normalising normal forms is quite technical. Our proof essentially follows the line of [11], but here we completely develop arguments that there were only sketched. The proofs of the if parts require the set-theoretic semantics of intersection types using stable sets [7,14], which is developed in Section 4.
Proof of (⇒). (1.iv) By Theorem 1.16(ii) it suffices to consider M in weak head normal form. 5 If M ≡ λx.N then we get `5 Ω N : Ω by (Ax-Ω) and `Ω M : Ω → Ω ~ , where m is the length of M ~ , we derive x : by rule (→I). If M ≡ xM 5 m+1 Ω → Ω `Ω M : Ω → Ω using (Ax-Ω) and (→E). (1.iii) Again by Theorem 1.16(ii) it suffices to consider M in head normal ~ where ~y has length n and M ~ has length m. We form. Let M ≡ λ~y .xM 5 ~ : A using rule (→E). By rule (→I) this implies have x:Ωm →A `Ω xM 5 m m x:Ω →A `Ω M : (Ω →A)n →A. For λ∩DHM by choosing A ≡ ω we get Ω m DHM m from above x:Ω → ω `Ω M : (Ω → ω)n → ω. By rules (≤DHM ) and (≤DHM L) this implies x:ω `DHM M : ϕ since ω ∼DHM Ω → ω, Ω ω ≤DHM ϕ and ϕ ∼DHM ω → ϕ. (1.ii) Similarly, it’s sufficient to consider M in normal form. The proof is by ~ where M ~ ≡ induction on M. The only interesting case is M ≡ xM 5 M1 . . . Mm . By induction we have Γj `Ω Mj : Aj , for some Γj , Aj not containing Ω and for j ≤ m. This implies: ]j≤m Γj ]{x:A1 → . . . →Am →A} `5 Ω ~ : A, where A is an arbitrary type not containing Ω. xM ~ then by inlet Γ = {x:ω | x ∈ FV(M)}. If M ≡ xM For λ∩CDZ Ω ~ : ω, xM Mj : ϕ and this implies Γ `CDZ duction we have Γ `CDZ Ω Ω CDZ since ω ∼CDZ ϕ → ω. By rule (≤CDZ ) we conclude Γ `Ω M : ϕ. If CDZ N : ϕ and this M ≡ λy.N then by induction we have Γ, y : ω `Ω CDZ implies Γ `Ω M : ω → ϕ. By rule (≤CDZ ) we conclude Γ `CDZ M : ϕ. Ω (1.i) By induction on the structure of strongly normalising terms (see Propo~ where m is sition 2.5). The only interesting case is M ≡ (λx.R)N M ~ ~ the length of M and both R[x := N]M and N are strongly normalising. By induction hypothesis there are Γ, A, Γ0 , B such that Γ `5 R[x := ~ : A and Γ0 `5 N : B. We get Γ ] Γ0 `5 R[x := N]M ~ : A and N]M 0 5 Γ ] Γ ` N : B, so if m = 0 we are done by a proof similar to that of Theorem 1.16(i). If m > 0 by iterated applications of Generation Lemma 16
~ : A we have 1.15(ii) to Γ `5 R[x := N]M (i)
(i)
(i) Γ `5 R[x := N] : B1 → . . . →Bm →B (i) , Γ `5 Mj : Bj , (j ≤ m)
T
(i)
and i∈I B (i) ≤5 A for some I, Bj (j ≤ m), B (i) ∈ T5 . As in case m = 0 (i) (i) we obtain Γ]Γ0 `5 (λx.R)N : B1 → . . . →Bm →B (i) . So we can conclude ~ : A. Γ ] Γ0 `5 (λx.R)N M (2.iii) If M is persistently weak head normalising then either M is an unsolvable term of order ∞ (as defined in [2]), i.e. for all n there is N such that M =β λx1 . . . xn .N, or M is a solvable term such that the head variable of its head normal form is free. In fact if M is an unsolvable term of a finite order, i.e. M =β λx1 . . . xn .N where N is unsolvable and it does ~ ∈ ~ are n arbitrary not reduce to an abstraction, then M N / WN where N ~ ~0 ∈ λ-terms. If M =β λ~xy~z.y N we get M~x(∆∆)~z −→ −→β ∆∆N / WN, where 0 ~ ~ N = N [y := ∆∆]. If M is an unsolvable term of order ∞, i.e. for all n, there is N such that n M =β λx1 . . . xn .N, we can derive `5 Ω λx1 . . . xn .N : Ω → Ω by (Ax-Ω) and rule (→I). If M is a solvable term such that the head variable of ~ we can derive for all l its head normal form is free, i.e. M =β λ~x.y N, 5 ~ : Ωn+l → Ω, where m is the length of N ~ and n y : Ωm+l → Ω `Ω λ~x.y N is the length of ~x. (2.ii) By (2.iii) the head variable of the head normal form of M must be free. ~ where y ∈ We can type a term of the shape λ~x.y N / ~x as follows y : Ωm → 5 ~ : Ωn → A, where m is the length of N ~ and n is the length of A `Ω λ~x.y N DHM m ~x. For λ∩Ω by choosing A ≡ ω we get y:Ω → ω `DHM M : Ωn → ω, Ω M : ω since ω ∼DHM Ω → ω. so we conclude y:ω `DHM Ω (3) Let Γω = {x : ω | x ∈ V}. It is easy to verify by induction on the definition of λ-terms that using ω ∼5 ω → ω we can derive Γω `5 Ω M : ω for all λ-terms M. By Theorem 1.16(ii) and (strengthening) we obtain that `5 Ω M : ω whenever M reduces to a closed term. Remark 3.3 From the proofs of (2.iii) and (2.ii) it follows that PHN = PWN∩ HN.
4
Set-theoretic semantics using stable sets
This section is devoted to prove the if parts of Theorem 3.2, by showing that all the given characterisations are complete. The proof technique which we shall adopt to achieve this is uniform for all properties, and it is based on the set theoretic semantics of intersection types 17
[14]. The set-theoretic semantics of a type, for a given applicative structure, is a subset of the structure itself. Intersection is interpreted as set-theoretic intersection, ≤ is interpreted as set-theoretic inclusion, and A→B is interpreted `a la logical relation, i.e. as a subset of the points of the structure whose functional behaviour is that of mapping all points in A into B. In the present context, there is only one applicative structure under consideration. This is the term structure Λ, i.e. the applicative structure whose domain are the λ-terms and where application is just juxtaposition of terms. In order to ensure that the interpretations of types consist of terms which satisfy appropriate properties, we need to give the set-theoretic semantics using special classes of stable sets, for suitable notions of stability. These stability properties amount essentially to suitable invariants for the set-theoretic operators corresponding to the type constructors. This proof technique has been used by various authors, e.g. stable sets [20], admissible relations [22], essentially in connection with strongly normalising terms. Here we develop a full-blown version of this technique, which is applicable to many other evaluation properties. We will consider two interpretations of the arrow type constructor, the simple semantics and the weak semantics. To this end we give the following definition: Definition 4.1 Let X, Y ⊆ Λ: i) X ⇒ Y = {M ∈ Λ | ∀N ∈ X MN ∈ Y } ii) X ⇒W Y = {M ∈ WN | ∀N ∈ X MN ∈ Y }. Now, in accordance to the set-theoretic semantics we put: Definition 4.2 (Type Interpretation) i) The simple interpretation [[ ]] of types in T5 induced by the type environment V : C5 → P(Λ) is defined by: (a) [[Ω]]V = Λ if Ω ∈ C5 ; (b) [[A]]V = V(A) if A ∈ C5 and A 6∼5 Ω; (c) [[A→B]]V = [[A]]V ⇒ [[B]]V ; (d) [[A ∩ B]]V = [[A]]V ∩ [[B]]V . ii) The weak interpretation [[ ]]W of types in T5 induced by the type environment V : C5 → P(Λ) is defined as the simple interpretation but for clause (c), which now is taken to be: W W W (c0 ) [[A→B]]W V = [[A]]V ⇒ [[B]]V . W Notice that if Ω ∈ C5 then [[Ω]]V = [[Ω]]W V = [[Ω → Ω]]V = Λ and [[Ω → Ω]]V = WN.
18
The interest of these semantics lies in the Soundness Theorem 4.5, below. But in order to be able to state it we need some further definitions. Definition 4.3 i) A type environment V agrees with a type theory Σ5 if and only if (a) ∀N ∈ [[A]]V . M[x := N] ∈ [[B]]V implies λx.M ∈ [[A → B]]V ; (b) if A ≤5 B then [[A]]V ⊆ [[B]]V . ii) A type environment V W-agrees with a type theory Σ5 if and only if W W (a) ∀N ∈ [[A]]W V . M[x := N] ∈ [[B]]V implies λx.M ∈ [[A → B]]V ; W W (b) if A ≤5 B then [[A]]V ⊆ [[B]]V . Looking at the weak interpretations of Ω and Ω → Ω it is clear that no environment can W-agree with Σ5 whenever Ω ∼5 Ω → Ω. Definition 4.4 (Semantic Satisfiability) Let ρ : V→Λ. ~ ] where ~x = F V (M) and ρ(~x) = N ~; i) [[M]]ρ = M[~x := N ii) ρ, V |= M : A if and only if [[M]]ρ ∈ [[A]]V ; iii) ρ, V |= Γ if and only if ρ, V |= x : B for all x:B ∈ Γ; iv) Γ |=5 M : A if and only if ρ, V |= Γ implies ρ, V |= M : A for all V which agree with Σ5 , and all ρ. v) Similarly • ρ, V |=W Γ if and only if [[x]]ρ ∈ [[B]]W V for all x:B ∈ Γ; 5 • Γ |=W M : A if and only if ρ, V |=W Γ implies [[M]]ρ ∈ [[A]]W V for all V which W-agrees with Σ5 and all ρ. Finally we can give: Theorem 4.5 (Soundness) Γ `5 M : A implies Γ |=5 M : A and Γ |=5 W M : A.
Proof. By induction on derivations. The restriction to type environments which agree with Σ5 is essential for the soundness of rules (→I) and (≤5 ).
The above theorem is a very powerful tool for proving properties of typable terms, which will be constantly used in the completeness part of the proof of Theorem 3.2. Roughly the idea is the following. In order to show that a term, typable in a given type theory (or with a given type, in a given type theory) has a given property, we pick a suitable type environment which agrees with that type theory and show that all terms in the interpretations of all the types (or in the interpretation of the type in question) satisfy that property. Usually variables belong to the interpretations of types, or else we are interested only 19
in closable terms. So, in both cases, by taking the identity term environment ρ0 (x) = x one has that [[M]]ρ0 = M, and so, if a term is typable, then it satisfies the property in question. The difficulty, of course, lies in showing that the properties in question are satisfied by the sets in the range of the type environments and that they are preserved by the “intersection” and the “arrow” constructions. As is normal with these inductive proofs, a possibly stronger hypothesis than the one that all terms in the interpretation of the type satisfy the property in question has to be assumed. After [20] we shall refer to these induction hypotheses as stability properties. The stability properties we shall be interested in are the following: ~ for Definition 4.6 i) A set X ⊆ WN is WN-type-stable if it contains xM ~ ∈ Λ, and it is closed under head expansion of redexes; all M ~ for all M ~ ∈ Λ and it ii) A set X ⊆ HN is HN-type-stable if it contains xM is closed under head expansion of redexes; ~ for all M ~ ∈ N and it is iii) A set X ⊆ N is N-type-stable if it contains xM closed under head expansion of redexes; ~ for all M ~ ∈ SN and it iv) A set X ⊆ SN is SN-type-stable if it contains xM is closed under head expansion of λ-I-redexes or of λ-K-redexes 2 whose argument is in SN. Notice that none of the stable sets in the above definition can be empty. The above definitions were given essentially to be able to show the following proposition, namely that the stability properties are preserved under suitable set-theoretic constructions. This result will imply, inter alia, that all sets in the range of the appropriate type interpretations satisfy the appropriate stability property. Proposition 4.7 Let S ∈ {WN, HN, N, SN}, T ∈ {HN, N, SN}, and X, Y ⊆ Λ. i) If Y is closed under head expansion of some kinds of redexes then both X ⇒W Y and X ⇒ Y are closed under head expansion of the same kinds of redexes for all X ⊆ Λ; ii) If X, Y are closed under head expansion of some kinds of redexes then X ∩ Y is closed under head expansion of the same kinds of redexes; iii) Each S is S-type-stable; iv) Λ ⇒W Λ is WN-type-stable; 2
(λx.M )N is a λ-K-redex if and only if x ∈ / F V (M ).
20
v) If Y is WN-type-stable then Λ ⇒W Y is WN-type-stable; vi) If X, Y are WN-type-stable then X ⇒W Y is WN-type-stable; vii) If Y is HN-type-stable then Λ ⇒ Y is HN-type-stable; viii) If X, Y are T-type-stable then X ⇒ Y is T-type-stable; ix) If X, Y are S-type-stable then X ∩ Y is S-type-stable; x) If X is S-type-stable then X ∩ Λ is S-type-stable.
Proof. We show only (iv), (v), (vi), (vii), and (viii), the other points being immediate. First notice that X ⇒W Y ⊆ WN for all X, Y ⊆ Λ by definition. Moreover Mx ∈ T implies M ∈ T for T ∈ {HN, N, SN}, and therefore from Y ⊆ T and x ∈ X we get X ⇒ Y ⊆ T. ~ for all M ~ ∈ Λ and If Y is Λ or it is WN-type-stable, then it contains xM ~ ∈ X ⇒W Y for all M ~ ∈ Λ and for all X ⊆ Λ. Similarly therefore xM ~ ∈ X ⇒ Y for all M ~ ∈ T and for all X ⊆ Λ whenever Y is T-type-stable xM for T ∈ {HN, N, SN}. We conclude using points (i) and (ii).
Now we define the type environments which will be considered in the completeness part of the proof of Theorem 3.2. Definition 4.8 (Type Environments) i) The type environment VBa is defined by: V(A) = SN if A ∈ C∞ . 1 ii) The type environment VBCD is defined by:
V(A) = HN if A ∈ C∞ . 2 iii) The type environment VBCD is defined by:
V(A) = N if A ∈ C∞ . iv) The type environment VCDZ is defined by: V(ω) = PN; V(ϕ) = N. v) The type environment VDHM is defined by: V(ω) = PHN; V(ϕ) = HN.
21
vi) The type environment VS c is defined by: V(ω) = PHN. vii) The type environment VP a is defined by: V(ω) = C. 1 2 Notation 4.9 VBCD stands for both VBCD and VBCD .
It is easy to verify, using the following Propositions 4.10 and 4.11, that each type environment V5 above agrees (or W-agrees) with the corresponding type theory Σ5 . Moreover all type environments agree and W-agree with the type theory ΣAO : this follows from Proposition 4.11(iii) taking into account the interpretations of Ω and Ω → Ω (see Definition 4.2 and the following sentence). Proposition 4.10
i) PN = N ⇒ PN.
ii) PHN = Λ ⇒ PHN. iii) N = PN ⇒ N. iv) HN = PHN ⇒ HN. v) C = C ⇒ C. Proof. All cases are immediate but the inclusion N ⊆ PN ⇒ N. We show that if M ∈ PN and N ∈ NF then NM ∈ N. If N is λ-free, i.e. N is of the ~ , then NM is the normal form xN ~ M. Otherwise let N ≡ λx.N 0 . The shape xN proof is by induction on the number of occurrences of x in N 0 . The basic step, that is x does not occur in N 0 , is immediate since NM −→β N 0 . If x occurs in N 0 , let N 0 ≡ C[x], where the hole in C[ ] identifies the left-most occurrence of x in N 0 . Let y be fresh: by induction (λx.C[y])M −→ −→β C 0 [y] ∈ NF. By ~ be all the terms to which construction there is exactly one hole in C 0 [ ]. Let N 0 ~ ∈ N and therefore (λy.C 0 [y])M ∈ N [ ] is applied in C [ ]. Since M ∈ PN, M N too. We conclude NM ∈ N since NM =β (λxy.C[y])MM =β (λy.C 0[y])M. Proposition 4.11 i) For 5 ∈ {BCD, CDZ, Sc, Pa, DHM} and for all types A ∈ T5 , all M, N ∈ Λ: If M[x := N] ∈ [[A]]V5 then (λx.M)N ∈ [[A]]V5 . ii) For all types A ∈ TBa and all M ∈ Λ, all N ∈ SN: If M[x := N] ∈ [[A]]VBa then (λx.M)N ∈ [[A]]VBa . iii) For all types A ∈ TAO , all M, N ∈ Λ and all environments V: W If M[x := N] ∈ [[A]]W V then (λx.M)N ∈ [[A]]V .
22
Proof. The proofs by induction on the structure of A follow from Definition 4.8 and Proposition 4.7(i),(ii).
Proof of Theorem 3.2(⇐). Take ρ0 (x) = x. Notice that ρ0 , V |= Γ and ρ0 , V |=W Γ for all V and Γ such that if x:B ∈ Γ then either [[B]]V is Λ or [[B]]V is S-type-stable for some S ∈ {WN, HN, N, SN}, since in both cases [[B]]V will contain all free variables. (1.iv) It is easy to check using Proposition 4.7 that for all A ∈ TAO and all V W either A ∼AO Ω and [[A]]W V = Λ or A 6∼AO Ω and [[A]]V is WN-type-stable. From above we get ρ0 , V |=W Γ for all V and Γ. Moreover [[Ω → Ω]]W V = AO WN. Then from Γ `AO M : Ω → Ω we get by soundness Γ |= M : Ω → Ω W W Ω, i.e. M = [[M]]ρ0 ∈ [[Ω → Ω]]V ⊆ WN, so we conclude M ∈ WN. (1.iii) For λ∩BCD it is easy to check using Proposition 4.7 that for all A ∈ TBCD Ω 1 1 either A ∼BCD Ω and [[A]]VBCD = Λ or A 6∼BCD Ω and [[A]]VBCD is HN-typeBCD 1 stable. So we have ρ0 , VBCD |= Γ for all Γ. From Γ `Ω M : (Ωm → A)n → A we get by soundness Γ |=BCD M : (Ωm → A)n → A, i.e. M = [[M]]ρ0 ∈ HN. For λ∩DHM let Γω be the DHM-basis all whose predicates are ω. By DefΩ inition 2.2 each free variable belongs to PHN and therefore ρ0 , VDHM |= Γω . From Γω `DHM M : ϕ we get by soundness M ∈ HN. 2 (1.ii) For λ∩BCD observe that by Proposition 4.7 [[A]]VBCD is N-type-stable whenΩ 2 ever Ω does not occur in A. Therefore ρ0 , VBCD |= Γ, since by hypothesis Ω does not occur in Γ. So as in case (1.iii) we get by soundness M ∈ N. For λ∩CDZ the proof is similar to that of case (1.iii) for λ∩DHM . Ω Ω
(1.i) The proof is similar to that of case (1.ii) for λ∩BCD by observing that Ω Ba [[A]]VBa is SN-type-stable for all A ∈ T . ~ ~ (2.iii) By definition [[Ωn+1 → Ω]]W V = {M ∈ WN | ∀N of length n, M N ∈ WN}, T n W then M ∈ n∈N [[Ω → Ω]]V if and only if M ∈ PWN. The result follows by soundness as in case (1.iv). (2.ii) For λ∩SΩc first notice that ω ≤S c A for all A ∈ TS c . This can be easily checked by induction on A. If A ≡ B → C then by induction ω ≤S c C so we get ω ∼S c Ω → ω ≤S c B → C by rule (η) since B ≤S c Ω by axiom (Ω). If for all A ∈ TS c there are a Sc-basis Γ and an integer n such that Γ `SΩc M : Ωn → A, by choosing A ≡ ω we get that there is a Sc-basis Γ0 such that Γ0 `SΩc M : ω by rule (≤S c ) since Ωn → ω ∼S c ω. This implies Γω `SΩc M : ω by rule (≤S c L). So it suffices to show that Γω `SΩc M : ω implies M ∈ PHN. This can be proved similarly to case (1.ii) for λ∩CDZ Ω using the type interpretation VS c . the proof is similar since ω ≤DHM ϕ and ω ∼DHM Ω → ω. For λ∩DHM Ω (2.i) The first observation is that Ω ∈ A iff Ω ∈CDZ A. We now show that 23
ω ≤CDZ A ≤CDZ ϕ for all A ∈ TCDZ such that Ω ∈ / A by induction on A. The only interesting case is A ≡ B → C: in this case by induction ω ≤CDZ B ≤CDZ ϕ, ω ≤CDZ C ≤CDZ ϕ so we get ω ∼CDZ ϕ → ω ≤CDZ B → C ∼CDZ ω → ϕ ∼CDZ ϕ by rule (η). If for all A ∈ TCDZ such that Ω∈ / A there is a CDZ-basis Γ such that Ω ∈ / Γ and Γ `CDZ M : A, by Ω choosing A ≡ ω we get that there is a CDZ-basis Γ0 such that Ω ∈ / Γ0 CDZ CDZ and Γ0 `Ω M : ω. This implies Γω `Ω M : ω by rule (≤CDZ L). So it suffices to show that Γω `CDZ M : ω implies M ∈ PN. This can be Ω proved similarly to case (1.ii) for λ∩CDZ . Ω (3) Clearly ρ, V |= ∅ for all ρ, V. The result follows immediately by soundness.
5
Concluding remarks
Two natural questions, at least, lurk behind this paper: “can we characterise in some significant way the class of evaluation properties which we can characterise using intersection types?” and “is there a method for going from a logical specification of a property to the appropriate intersection type theory?”. Regarding the first question, we have seen that the properties have to be closed, at least, under some form of β-expansion. But clearly this is not the whole story. Probably the answer to this question is linked to some very important open problems in the theory of the denotational semantics of untyped λ-calculus, like the existence of a denotational model whose theory is precisely λβ. As far as the latter question is concerned, we really have no idea. It seems that we are still missing something in our understanding of intersection types. Of course there are some partial answers. For instance by looking at what happens in particular filter models, one can draw some inspiration and sometimes even provide some interesting characterisations. In this paper we discussed closable sets. Another example would have been, for instance, that of those terms which reduce to terms of the λ-I-calculus. Here the filter model under consideration is the one in [19], generated by the theory ΣHR = Σ({Ω, ϕ, ω}, BCD∪ {(ωϕ), (ϕ→ω), (ω-I)}), where (ω-I) is the rule (ϕ→ϕ)∩(ω→ω) ∼ ϕ. The terms typable with ϕ in λ∩HR Ω , for the HR-basis where all variables have type ϕ, are then precisely those which reduce to terms of the λ-I-calculus [19]. These characterisations however appear quite accidental. And we feel that we lack yet a general theory which could allow us to streamline the approach. Given the model we can start to guess. And when we are successful, as in this case, we can achieve generality only artificially, by considering all those type theories which extend the theory of the filter model in question. For one thing this method of drawing inspiration from filter models is in24
teresting, in that it provides some very interesting conjectures. Perhaps the best example concerns persistently strongly normalising terms. These are those ~ of strongly norstrongly normalising terms M, such that for all vectors N ~ is still strongly normalising. Consider the filter model malising terms, M N introduced in [18], generated by the type theory obtained by pruning the type theory ΣCDZ of all types including Ω, i.e. generated by the theory ΣHL = Σ({ϕ, ω}, Ba ∪ {(ωϕ), (ϕ→ω), (ω→ϕ)}). The natural conjecture is then, in analogy to what happens for persistently normalising terms, “are the terms typable with ω in λ∩HL B , for the HL-basis where all variables have type ω precisely the persistently strongly normalising ones?”. Completeness is clear, but to show soundness some independent syntactical characterisation of that class of terms appears necessary. The set of persistently strongly normalising terms does not include PN ∩ SN. A counter example is M ≡ λx.a((λy.b)(xx)) since M(λz.zz) ∈ / SN. This conjecture still resists proof. The results and the techniques of the present paper have been widely used and developed in [13], which mainly focus on the construction of λ-models characterising computational properties of terms.
Acknowledgements The authors are very grateful to F. Alessi for very stimulating discussions on the subject of the present paper. Moreover they like to thank the referees of MFCS and TCS submissions for their useful remarks and suggestions.
Appendix
Polarised normal forms
In this Appendix we will show that, for all arrow-type theories Σ5 , each persistently normalising λ-term M can be typed with an arbitrary type not containing Ω modulo ∼5 from a suitable 5-basis. Our proof is organised as follows. First we introduce the notions of adjacent occurrences of variables, positive and negative variables, polarised normal forms, principal decorations and replacement paths. Then we show the key property (Lemma A.13): for each normal form with adjacent occurrences of negative variables we can build a substitution such that the resulting term does not have normal form. This fact suggests the notions of positive normal forms and strongly polarised normal forms. We conclude by showing that: • each persistently normalising normal form is a positive normal form (The25
orem A.15); • the principal decoration of a positive normal form is a strongly polarised normal form (Proposition A.20); • each strongly polarised normal form which is a principal decoration can be typed with an arbitrary type not containing Ω modulo ∼5 from a suitable 5-basis in all arrow-type theories Σ5 (Theorem A.23). We give now some definitions concerning only terms in normal form. We do forbid α-conversion: in this way also the names of bound variables are meaningful. Moreover this leads us to consider λ-terms in which different bound variables may have the same names, and also bound and free variables may have the same name. ~ (λ~z.y N) ~ we say that Definition A.1 i) In a normal form of the shape xM the showed occurrences of x and y are adjacent. Notice that we can have x ≡ y. ii) Two (not necessary distinct!) variables have adjacent occurrences in a normal form M if and only if they have adjacent occurrences in a subterm of M. iii) If M ≡ xN1 . . . Ni . . . Nm we say that the subterm Ni is the i-th argument of x in M. ~ we say that: iv) If M ≡ λy1 . . . yj . . . yn .xN (a) the variables y1 . . . yj . . . yn are the variable bound by the initial abstractions of M; (b) the variable yj is the variable bound by the j-th abstraction of M. Remark A.2 An alternative definition of adjacent occurrences can be done using the B¨ohm trees of λ-terms as defined in [6] (Definition 10.1.4): two occurrences x, y are adjacent in M if and only if they correspond to two nodes father-son in the B¨ohm tree of M with labels λ~z .x and λ~t.y for some ~z, ~t. Example A.3 In the normal form λx.x(λt.x)(λuz.u(zt)): • the underlined occurrences of variables are adjacent: λx.x(λt.x)(λuz.u(zt))
λx.x(λt.x)(λuz.u(zt))
λx.x(λt.x)(λuz.u(zt))
λx.x(λt.x)(λuz.u(zt))
• λuz.u(zv) is the 2-th argument of x in x(λt.x)(λuz.u(zt)) • x is the variable bound by the initial abstraction of λx.x(λt.x)(λuz.u(zt)) • z is the variable bound by the 2-th abstraction of λuz.u(zt). Figure 4 shows the B¨ohm tree of λx.x(λt.x)(λuz.u(zt)). 26
λx.x
|C|. We can choose A0 ≡ B 0 ∩ C 0 . (ii) By (i) it suffices to show that for each A ∈ T5 with |A| ≥ n there is T ~ i → Ci ) where B ~ i has length A0 ∈ T5 such that A0 ∼5 A and A0 ≡ i∈I (B n for all i ∈ I. The proof is by induction on A. The case A ∈ C5 is trivial since n = 0. If A ≡ B → C then |C| ≥ n − 1. By induction there is T ~ i → Ei ) where D ~ i has length C 0 ∈ T5 such that C 0 ∼5 C and C 0 ≡ i∈I (D T 0 ~ i → Ei ), since A0 ∼5 A n−1 for all i ∈ I. We can choose A ≡ i∈I (B → D by rules (→-∩) and (η). The case A ≡ B ∩ C is easy by induction. Theorem A.23 Let Σ5 be an arrow type theory. Let M ∈ SNFi,j and let x~+ 41
and y~− be the positive and negative variables which occur free in M: ~ with Ω ∈ ~ and for all types i) if i = + and j = − then for all types A /5 A ~ with Ω ∈ ~ such that x~+ : A, ~ y~− : A with Ω ∈ / 5 A there exist types B /5 B ~ `5 M : A. B ~ with Ω ∈ ~ there exist types B ~ with Ω ∈ ~ ii) otherwise for all types A /5 A /5 B 5 ~ y~− : B ~ ` M : A. and a type A with Ω ∈ / 5 A such that x~+ : A,
Proof. We prove (i) and (ii) simultaneously by induction on the structure of strongly polarised normal forms. We convene that all considered types do not contain occurrences of Ω modulo ∼5 . By x+ we denote an arbitrary element of ~x. Similarly for y − . ~ where N ~ ∈ SNF−,+ ∪ (i) If M ∈ SNF+,− then M is of the shape λz~+ .y − N −,− 5 SNF . Since Σ is an arrow type theory, then by Lemma A.22(ii) each type is equivalent to an intersection of arrow types, each one of the shape ~ → D where the length of C ~ is an arbitrary integer. So it suffices to C ~ → D, where C ~ has the length prove that M has all types of the shape C ~ and E ~ such that of ~z . By the induction hypothesis (ii) there are types B ~ and C ~ we have: x~+ : A, ~ z~+ : C, ~ y~− : B ~ `5 N ~ : E. ~ Now for all types A − ~ → D to let Γ be the 5-basis obtained by adding the premise y : E 5 −~ + + − ~ ~ ~ ~ ~ ~ x : A, z : C, y : B. We get Γ ` y N : D and we can conclude using rule (→ I). ~ where N ~ ∈ SNF−,+ ∪ (ii) If M ∈ SNF−,− then M is of the shape λz~− .t− N SNF−,− and t− ∈ y~− ∪ z~− . By the induction hypothesis (ii) there are ~ C ~ and E ~ such that for all types A ~ we get: x~+ : A, ~ z~− : C, ~ y~− : types B, ~ `5 N ~ : E. ~ Now let Γ be the 5-basis obtained by adding the premise B − ~ → D, where D is arbitrary, to x~+ : A, ~ z~− : C, ~ y~− : B. ~ We get t : E 5 −~ Γ ` t N : D and we can conclude using rule (→ I). ~ where N ~ ∈ SNF+,− . Let If M ∈ SNF−,+ then M is of the shape λz~− .x+ N 0 + ~ By Lemma A.22(ii) A be the type of the variable x and n the length of N. ~ → D such that E ~ has length ≥ n and A0 ≤5 E ~ → D. there is a type E ~ and C ~ such that for By the induction hypothesis (i) there are types B 5 + − − ~ and E ~ we have: x~ : A, ~ z~ : C, ~ y~ : B ~ ` N ~ : E. ~ We get all types A 5 +~ + − − ~ ~ ~ ~ ~ ~ x : A, z : C, y : B ` x N : D and we can conclude using rule (→ I). ~ where N ~ ∈ SNF+,− and If M ∈ SNF+,+ then M is of the shape λz~+ .t+ N t+ ∈ x~+ ∪ z~+ . If t+ ∈ x~+ the proof goes as in previous case. Otherwise ~ → D, where E ~ has the the proof is similar, since we can assume t+ : E ~ for arbitrary types E, ~ D and conclude as in previous case. length of N,
42
Proof of Theorem 3.2(2.i)(⇒). The theory of polarised normal forms has been introduced to get this result. If M ∈ PN then by definition its normal form M 0 ∈ PNF. By Theorem A.15 M 0 ∈ NF+ , so M 0 has all types not containing Ω modulo ∼5 (from 5-bases not containing Ω modulo ∼5 ) in an arbitrary arrow type theory by Proposition A.20 and Theorem A.23. We can conclude that also M has the same types in an arbitrary arrow type theory by Theorem 1.16(ii). Remark A.24 By Theorems 3.2(2.i)(⇐), A.23, and Proposition A.20 we get NF+ ⊆ PNF. Therefore from Theorem A.15 we can conclude that the persistently normalising normal forms are exactly the positive normal forms, i.e. PNF = NF+ .
References [1] S. Abramsky. Domain theory in logical form. Ann. Pure Appl. Logic, 51(1-2):1– 77, 1991. [2] S. Abramsky and C.-H. L. Ong. Full abstraction in the lazy lambda calculus. Inform. and Comput., 105(2):159–267, 1993. [3] R. M. Amadio and P.-L. Curien. Domains and Lambda-calculi. Cambridge University Press, Cambridge, 1998. [4] S. van Bakel. Complete restrictions of the intersection type discipline. Theoret. Comput. Sci., 102(1):135–163, 1992. [5] H. Barendregt, M. Coppo, and M. Dezani-Ciancaglini. A filter lambda model and the completeness of type assignment. J. Symbolic Logic, 48(4):931–940, 1983. [6] H.P. Barendregt. The Lambda Calculus: its Syntax and Semantics. NorthHolland, Amsterdam, revised edition, 1984. [7] H.P. Barendregt and et. al. Typed λ-calculus and Applications. North-Holland, 200X. (to appear). [8] C. Berline. From computation to foundations via functions and application: The λ-calculus and its webbed models. Theoret. Comput. Sci., 249:81–161, 2000. [9] C. B¨ ohm and M. Dezani-Ciancaglini. λ-terms as total or partial functions on normal forms. In C. B¨ ohm, editor, λ-calculus and Computer Science Theory, volume 37 of Lecture Notes in Computer Science, pages 96–121, Berlin, 1975. Springer. [10] M. Coppo and M. Dezani-Ciancaglini. An extension of the basic functionality theory for the λ-calculus. Notre Dame J. Formal Logic, 21(4):685–693, 1980.
43
[11] M. Coppo, M. Dezani-Ciancaglini, and M. Zacchi. Type theories, normal forms, and D∞ -lambda-models. Inform. and Comput., 72(2):85–116, 1987. [12] M. Coppo, F. Honsell, M. Dezani-Ciancaglini, and G. Longo. Extended type structures and filter lambda models. In G.Lolli, G.Longo, and A.Marcja, editors, Logic Colloquium ’82, pages 241–262. North-Holland, Amsterdam, 1984. [13] M. Dezani-Ciancaglini and S. Ghilezan. Two behavioural lambda models. In H.Geuvers and F.Wiedijk, editors, Types for Proofs and Programs, volume 2646 of Lecture Notes in Computer Science, pages 127–147, Berlin, 2003. SpringerVerlag. [14] M. Dezani-Ciancaglini, F. Honsell, and F. Alessi. A complete characterization of the complete intersection-type preorders. ACM Trans. On Comput. Logic, 1(4):120–147, 2003. [15] M. Dezani-Ciancaglini, F. Honsell, and Y. Motohama. Compositional characterization of λ-terms using intersection types. In M. Nielsen and B. Rovan, editors, Mathematical Foundations of Computer Science 2000, volume 1893 of Lecture Notes in Computer Science, pages 304–313. Springer, 2000. [16] L. Egidi, F. Honsell, and S. Ronchi della Rocca. Operational, denotational and logical descriptions: a case study. Fund. Inform., 16(2):149–169, 1992. [17] S. Ghilezan. Strong normalization and typability with intersection types. Notre Dame J. Formal Logic, 37(1):44–52, 1996. [18] F. Honsell and M. Lenisa. Semantical analysis of perpetual strategies in λcalculus. Theoret. Comput. Sci., 212(1-2):183–209, 1999. [19] F. Honsell and S. Ronchi della Rocca. An approximation theorem for topological lambda models and the topological incompleteness of lambda calculus. J. Comput. System Sci., 45(1):49–75, 1992. [20] J.-L. Krivine. Lambda-calcul Types et Mod`eles. Masson, Paris, 1990. English translation: Lambda-calculus, types and models, Ellis Horwood, Crystal City, 1993. [21] D. Leivant. Typing and computational properties of lambda expressions. Theoret. Comput. Sci., 44(1):51–68, 1986. [22] J. Mitchell. Foundations for Programming Languages. MIT Press, Boston, 1996. [23] D. Park. The Y-combinator in Scott’s λ-calculus models (revised version). Theory of Computation Report 13, Department of Computer Science, University of Warwick, 1976. [24] G. D. Plotkin. Set-theoretical and other elementary models of the λ-calculus. Theoret. Comput. Sci., 121(1-2):351–409, 1993.
44
[25] G. Pottinger. A type assignment for the strongly normalizable λ-terms. In J.R. Hindley and J.P. Seldin, editors, To H. B. Curry: Essays on Combinatory Logic, Lambda Calculus and Formalism, pages 561–577. Academic Press, London, 1980. [26] D. Scott. Continuous lattices. In F.W. Lawvere, editor, Toposes, Algebraic Geometry and Logic, volume 274 of Lecture Notes in Mathematics, pages 97– 136. Springer, Berlin, 1972. [27] P. Severi. Normalisation in Lambda calculus and its Relation to Type Inference. Eindhoven University of Technology, 1996. Ph D. thesis.
45