Comparing cubes of typed and type assignment systems

30
Comparing Cubes of Typed and Type Assignment Systems Steffen van Bakel 1 , Luigi Liquori 2, Simona Ronchi della Rocca 2 , and Pawel Urzyczyn 3 1 Department of Computing, Imperial College, 180 Queen’s Gate, London SW7 2BZ, U.K, [email protected] 2 Dipartimento di Informatica, Universit` a degli Studi di Torino, Corso Svizzera 185, 10145 Torino, Italia, {liquori,ronchi}@di.unito.it 3 Instytut Informatyki Uniwersytetu Warszawskiego, ul. Banacha 2, 02-097 Warszawa, Polska, [email protected] Abstract We study the cube of type assignment systems, as introduced in [13], and confront it with Barendregt’s typed λ-cube [4]. The first is obtained from the latter through applying a natural type erasing function E to derivation rules, that erases type information from terms. In particular, we address the question whether a judgement, derivable in a type assignment system, is always an erasure of a derivable judge- ment in a corresponding typed system; we show that this property holds only for the systems without polymorphism. The type assignment systems we consider satisfy the properties ‘subject reduction’ and ‘strong normalization’. Moreover, we define a new type assignment cube that is isomorphic to the typed one. Introduction Types can be used as predicates for terms of λ-calculus in two different ways. A first approach is to define terms directly decorated with types; in this fully typed approach, every closed term comes with a unique, intrinsic type. A typed system consists of a set of (derivation) rules for proving judgements of the shape Γ t t M t : φ t , where M t is a typed term, φ t is a type, and Γ t is a context. The meaning of such a judgement is that the term M t has type φ t under the context Γ t , where Γ t records the types of the free variables of M t and φ t . Alternatively, in the type assignment approach, types can be assigned to terms of the untyped λ- calculus. A type assignment system consists of a set of (derivation) rules for proving judgements of the shape Γ M : φ, where M is a term of the untyped λ-calculus, φ is a type, and Γ is a context that assigns types to the free variables of M and φ. Such a judgement can be understood as that we can assign the type φ to the λ-term M , when types are assigned to the free variables of M and φ as specified in the context Γ. In this approach, types are viewed as predicates , or properties , of terms, and each closed term can be assigned either none or infinitely many types. When we look at λ-calculus as a paradigmatic programming language, the first approach corresponds to explicitly typed languages, like for example Haskell, whereas the second corresponds to ML-like languages, where the user can write programs in a completely untyped language, and types are auto- matically inferred at compile time. The latter can be considered to be the construction of an abstract interpretation of the program, that can be used as a correctness criterion. In the typed approach, called ` a la Church by Barendregt, there exists several typed λ-calculi, where terms are decorated with types in various ways. Examples of typed λ-calculi are the simply typed λ- calculus (λ) of Church, the second order λ-calculus of Girard and Reynolds (λ2) [15, 20], and the calculus of constructions (λPω) [7, 8]. Barendregt gave in [4] a compact and appealing presentation of a class of typed systems (TS), arranging them in a cube . In this cube, every vertex represents * Partly supported by HCM project No. ERBCHRXCT920046 “Typed Lambda Calculus” Partly supported by grants NSF CCR–9113196, KBN 2 P301 031 06, and by a grant from the Commission of The European Communities ERB–CIPA–CT92–2266(294). 1

Transcript of Comparing cubes of typed and type assignment systems

Comparing Cubes of Typed and Type Assignment Systems

Steffen van Bakel1, Luigi Liquori2∗, Simona Ronchi della Rocca2∗, and Paweł Urzyczyn3†

1 Department of Computing, Imperial College, 180 Queen’s Gate, London SW7 2BZ, U.K,[email protected]

2 Dipartimento di Informatica, Universita degli Studi di Torino, Corso Svizzera 185, 10145 Torino, Italia,{liquori,ronchi}@di.unito.it

3 Instytut Informatyki Uniwersytetu Warszawskiego, ul. Banacha 2, 02-097 Warszawa, Polska,[email protected]

Abstract

We study thecube of type assignment systems, as introduced in [13], and confront it with Barendregt’stypedλ-cube [4]. The first is obtained from the latter through applying a natural type erasing functionE to derivation rules, that erases type information from terms. In particular, we address the questionwhether a judgement, derivable in a type assignment system,is always an erasure of a derivable judge-ment in a corresponding typed system; we show that this property holds only for the systems withoutpolymorphism. The type assignment systems we consider satisfy the properties ‘subject reduction’and ‘strong normalization’. Moreover, we define a new type assignment cube that is isomorphic tothe typed one.

Introduction

Types can be used as predicates for terms ofλ-calculus in two different ways. A first approach is todefine terms directlydecoratedwith types; in thisfully typedapproach, every closed term comes witha unique, intrinsic type. Atyped systemconsists of a set of (derivation) rules for proving judgementsof the shapeΓt ⊢t Mt : φt, whereMt is a typed term,φt is a type, andΓt is a context. The meaning ofsuch a judgement is that the termMt has typeφt under the contextΓt, whereΓt records the types ofthe free variables ofMt andφt.

Alternatively, in thetype assignmentapproach, types can be assigned to terms of the untypedλ-calculus. Atype assignment systemconsists of a set of (derivation) rules for proving judgements ofthe shapeΓ ⊢ M : φ, whereM is a term of the untypedλ-calculus,φ is a type, andΓ is a contextthat assigns types to the free variables ofM andφ. Such a judgement can be understood as that wecan assign the typeφ to theλ-termM , when types are assigned to the free variables ofM andφ asspecified in the contextΓ. In this approach, types are viewed aspredicates, orproperties, of terms, andeach closed term can be assigned either none or infinitely many types.

When we look atλ-calculus as a paradigmatic programming language, the firstapproach correspondsto explicitly typed languages, like for example Haskell, whereas the second corresponds to ML-likelanguages, where the user can write programs in a completelyuntyped language, and types are auto-matically inferred at compile time. The latter can be considered to be the construction of an abstractinterpretation of the program, that can be used as a correctness criterion.

In the typed approach, calleda la Churchby Barendregt, there exists several typedλ-calculi, whereterms are decorated with types in various ways. Examples of typedλ-calculi are the simply typedλ-calculus (λ→) of Church, the second orderλ-calculus of Girard and Reynolds (λ2) [15, 20], and thecalculus of constructions (λPω) [7, 8]. Barendregt gave in [4] a compact and appealing presentationof a class of typed systems (TS), arranging them in acube. In this cube, every vertex represents

∗Partly supported by HCM project No. ERBCHRXCT920046 “TypedLambda Calculus”†Partly supported by grants NSF CCR–9113196, KBN 2 P301 031 06, and by a grant from the Commission of The

European Communities ERB–CIPA–CT92–2266(294).

1

a different typed system. One vertex is theorigin and represents the simply typedλ-calculus; thethree dimensions of the cube represent the introduction of some new rules of type formation, namelyPolymorphism, Higher-OrderandDependencies(see Definition1.5). This three-dimensional structureallows for a deep comparative analysis of different typedλ-calculi.

In [13], a type assignment version of Barendregt’s cube (TAS) was defined trough an erasing functionE that erases type information from terms. To be precise, if a typed system consists of a setR ofderivation rules, the rules of the corresponding type assignment system can be obtained by applyingE to every object occurring in the rules ofR. The dependency-free plane of TAS contains some typeassignment systems already known in the literature, that are convertible to certain typed systems: theCurry type assignment system (F1) [9] that corresponds toλ→, the polymorphic type assignmentsystem (F2) [17] that corresponds toλ2, and the higher order type assignment system (Fω) [14] thatcorresponds toλω.

The fact that in [13] also systems that contain dependencieswere considered, was a first attempt tostudy dependent types in a type assignment approach. In thatpaper was proved that the introductionof dependencies does not increase the expressiveness of a system, i.e., the terms typable in a typeassignment system with dependencies are all nothing but those typable in the similar system, obtainedfrom the first by erasing the dependencies.

In [13], it was observed that, perhaps surprisingly, in presence of dependencies there no longer existsan isomorphism between corresponding systems of typed and type assignment cubes, in the sense thatnot every derivation in TAS is the image under erasure of a derivation in TS. However, in that paperwas conjectured that at least there exists an isomorphism between judgements rather than betweenderivations, i.e.: a judgementΓ ⊢ M : φ is true in one of the type assignment systems if and only if,in the corresponding typed system, a judgementΓt ⊢t Mt : φt can be proved such thatE (Mt) = M ,E (Γt) = Γ, andE (φt) = φ.

In this paper, where we focus closely on the differences and similarities between TS and TAS, wewill disprove this conjecture, showing that it is true only for systems without polymorphism. The typeassignment systems with polymorphism and dependencies (DF2 andDFω, that correspond respectivelyto λP2 andλPω) are in some sense more powerful than their typed versions. In fact, we prove thatthere are judgements, provable in one of these systems, thatcannot be obtained as erasures of typedjudgements. This implies that there are types, inhabited inthese systems, that are not erasures ofinhabited types in the corresponding typed systems, and, moreover, that a termM can be assignedmore types than just those that can be obtained, through erasure, from types belonging to any typedversion ofM .

This result gives then rise to a new question, namely if it is possible to build a cube of type assignmentsystems that is isomorphic to Barendregt’s cube, in the sense that typed and type assignment systems inthe corresponding vertices are isomorphic. We solve this problem by defining a cube of type assignmentsystemsTAS′ that enjoy this property. This cube is based on the definitionof a new erasing functionE′

that coincides withE when dependencies are not present. The main difference betweenE andE′ is that,while E always erases type information in terms,E′ is context dependent and erases type informationfrom a term only if that term does not occur in a type; otherwise it leaves the term unchanged. Thiscube has the the (somewhat unelegant) property that some type assignment rules use explicitly typedrules of the corresponding typed system in Barendregt’s cube. But this seems to be the price to pay forobtaining isomorphism.

As stated already in [13], the above mentioned erasing function E, at least for the dependency-freeplane of TS and TAS, induces an isomorphism between derivations in corresponding systems. Moreprecisely, ifD is a derivation in a typed system, by applyingE to every object (i.e. term, constructor,or kind) inD, a valid derivation in the corresponding type assignment system is obtained. Vice-versa,again only for dependency-free systems, every type assignment derivation can be obtained by applyingE to a typed one. Clearly, the fact that the classes of derivations for typed and a type assignment systemsare isomorphic means that they have the same underlying logical system.

2

The relation with (intuitionistic) logic through the so-called Curry-Howard isomorphism, or ‘formulae as types’principle, has been profoundly studied for Barendregt’s cube, and has been clearly established for theplane of the cube without dependencies. However, in the opposite plane, this relation is less clear, asdemonstrated by Berardi in [6]. As mentioned above, in this paper, we show an example of a inhabitedtype in TAS, that cannot be obtained through erasure of an inhabited type in TS. This negative resultof course implies that the logical sides of these two cubes are different; however, this difference onlyshows up in the plane of the cube with dependencies, where already TS has lost a clear connection withlogic. Moreover, the underlined logics of the cubeTAS′ are those of the typed cube of Barendregt.

Furthermore, it is also our opinion that there is more to types than just logic: studying types is notsolely justifiable through the connection between types andlogic, as is clearly shown by, for example,the type system developed for ML that models type-constantsand recursion [18], and the intersectiontype discipline [2]. In our view, the main motivation for TAScomes from the ML-style of approachingtypes: to have type-free code with type assignment seen as a correctness criterion, or safety means, butalways outside of programs rather than built in. Certainly,in order to be correctly applied in this way, atype assignment system must enjoy some fundamental properties, like the Church-Rosser property, thesubject-reduction property and normalization. We prove these properties in this paper for all systemsin TAS. So, TAS can make sense even if it does not fit the corresponding TS: it is just another wayto select legitimate code. Studying type systems with dependencies can be of value from the point ofview of abstract interpretation; such type assignment system could introduce a more refined notion oftypes in a programming language setting. For example, sincethe version ofF1 with dependencies isdecidable, and the core of the type system for ML is based onF1, designing a version of ML withdependent types seems feasible.

We would like to emphasize that the scope of this paper is tocomparethe systems TS and TAS, notto propagandize any of these.

This paper is organized as follows. Section1 contains a presentation of Barendregt’s cube in a stratifiedversion, and of a cube of type assignment systems. In Section2, the properties of the type assignmentsystems belonging to the latter are studied; in particular,it contains the proofs of the subject reductionproperty, and of the strong normalization property. Section 3 is devoted to the study of the relationbetween the two cubes. In that section, we disprove the conjecture cited above. In Section4, a newerasing function, together with the induced new cube of typeassignment systems is presented. In thatsection, we will show that these type assignment systems areisomorphic to the systems in Barendregt’scube.

A preliminary version of this paper was presented in [1].

Notational conventions: In this paper, atermwill be either an(un)typedλ-term, aconstructor, akind,or a sort. The symbolsM , N , P , Q, . . . range over (un)typedλ-terms;φ, ψ, ξ, µ, . . . range overconstructors;K ranges over kinds;s ranges over sorts:A, B, C, D, . . . range over arbitrary terms;x,y, z, . . . range overλ-term-variables;α, β, γ, . . . range over constructor-variables;a, b, c, . . . rangeoverλ-term-variables and constructor-variables. The symbolΓ will range over contexts. All symbolscan appear indexed. The symbol≡ denotes the syntactic identity of terms, and we will consider termsmoduloα-conversion. The notationΠn

i=1ai:Ai.B is an abbreviation ofΠa1:A1. · · ·Πan:An.B.

1 Two Cubes

Barendregt’s cube of typed systems, already defined in [4], is normally presented using a rather compactnotation, usingrule schemesrather than rules. Before coming to the definition of a cube oftype as-signment systems related to Barendregt’s cube, in this section we will first present a ‘stratified‘ versionof the systems in that cube, by splitting the terms considered by Barendregt in three different classes,

3

being those ofλ-terms, constructors, and kinds. Starting from that stratified version, we will define anerasing functionE and, using this function, obtain the related cube of type assignment systems. Thesame approach can be found in [13].

1.1 The Cube of Typed Systems

In this subsection we will give a short overview of Barendregt’s cube. A number of formal notionsand properties for this cube (like ‘free variable’, ‘substitution’, or ‘context’) are used in this paper;however, in view of the strong similarity with definitions given in Subsection1.2, we will skip thosehere. Here we will limit ourselves to the presentation of theformal syntax and derivation rules in ourown denotation, since that differs from the one commonly used; this should enable the appreciationof the presentation of our cube of type assignment systems inthe next subsection. For a completedevelopment of Barendregt’s cube, we refer to [4, 11].

Definition 1.1 Iti) {∗,2} is the set ofsorts.I tii ) The sets oftypedλ-terms(Λt), typed constructors(Const), andtyped kinds(Kindt) are mutually

defined by the following grammar, whereM , φ, andK are metavariables forλ-terms, constructorsand kinds respectively:

M ::= x | λx:φ.M | MM | λα:K.M | Mφ

φ ::= α | Πx:φ.φ | Πα:K.φ | λx:φ.φ | λα:K.φ | φφ | φM

K ::= ∗ | Πx:φ.K | Πα:K.K

The setTt of typed termsis the union of the setsΛt, Const andKindt.

Definition 1.2 (TYPED REDUCTION) β-reduction on typed terms (denoted as→→β) is defined as usual,i.e., as the contextual, reflexive and transitive closure ofthe following one-step reduction rule:

(λa:A.B)C →β B[C/a].

The symbol=β denotesβ-conversion, i.e., the least equivalence relation generated by→→β.

The introduction of three classes of ‘terms’ in Definition1.1 induces a stratified version of the setderivation rules; each class comes with its own derivationsrules. The names of the rules are, to savespace, restricted to a few characters. We have tried to use anorthogonal approach in baptizing the rules:in general a name for a rule is composed like(X−YZ), meaning that:

• it is a rule that follows the syntax of objects in classX, whereX is omitted forλ-terms, isCfor constructors, andK for kinds,

• Y is either

– I for an introduction rule, that are used to deal with the variousλ-abstractions,

– E for an elimination rule, that deal with applications,

– F for a formation rule, that deal with theΠ-abstraction,

• andZ is used (asX above) to indicate the class either of the bound variable (incase of anintroduction or formation rule), or of the right-hand side term in an application (in case of a formationrule).

Definition 1.3 (BARENDREGT’ S GENERAL TYPED SYSTEM) The following rules are used to derivejudgementsof the formΓ ⊢t A :B, whereΓ is a context andA :B is a statement. The derivation rules can be di-vided in four groups, depending of the subjects of the statements:I ti) Common Rules

4

(Proj)Γ ⊢t A : s a 6∈ Dom(Γ)

Γ, a:A ⊢t a : A

(Weak)Γ ⊢t A : B Γ ⊢t C : s c 6∈ Dom(Γ)

Γ, c:C ⊢t A : B

(Conv)Γ ⊢t A : B Γ ⊢t C : s B =β C

Γ ⊢t A : C

I tii ) Typedλ-Term Rules

(I)Γ, x:φ ⊢t M : ψ

Γ ⊢t λx:φ.M : Πx:φ.ψ

(E)Γ ⊢t M : Πx:φ.ψ Γ ⊢t N : φ

Γ ⊢t MN : ψ[N/x]

(IK)Γ, α:K ⊢t M : φ

Γ ⊢t λα:K.M : Πα:K.φ

(EK)Γ ⊢t M : Πα:K.φ Γ ⊢t ψ : K

Γ ⊢t Mψ : φ[ψ/α]

I tiii ) Typed Constructor Rules

(C–IC )Γ, x:φ ⊢t ψ : K

Γ ⊢t λx:φ.ψ : Πx:φ.K

(C–EC)Γ ⊢t ψ : Πx:φ.K Γ ⊢t M : φ

Γ ⊢t ψM : K[M/x]

(C–IK)Γ, α:K1 ⊢t ψ : K2

Γ ⊢t λα:K1.ψ : Πα:K1.K2

(C–EK)Γ ⊢t φ : Πα:K1.K2 Γ ⊢t ψ : K1

Γ ⊢t φψ : K2[ψ/α]

(C–FC )Γ, x:φ ⊢t ψ : ∗

Γ ⊢t Πx:φ.ψ : ∗

(C–FK)Γ, α:K ⊢t φ : ∗

Γ ⊢t Πα:K.φ : ∗

I tiv) Typed Kind Rules

(Axiom)<> ⊢t ∗ : 2

(K–FC)Γ, x:φ ⊢t K : 2

Γ ⊢t Πx:φ.K : 2

(K–FK)Γ, α:K1 ⊢t K2 : 2

Γ ⊢t Πα:K1.K2 : 2

5

If Γ ⊢t M : φ for a typedλ-termM , thenΓ ⊢t φ : ∗ (see [4]). In this case we say thatφ is atypeor,to be more precise, a type with respect to the contextΓ.

In the next definition we present a notation for derivations,that is of use in the sequel.

Definition 1.4 Iti) We write D:: Γ ⊢t A :B to express thatD is a derivation for the judgementΓ ⊢t A :B.

I tii ) We writeD′ ⊆ D whenD′ is a subderivation ofD.I tiii ) We will use the notation

C1. . . Cn

D:: (R)C

to denote the derivationD, proving the judgementC, that is obtained by applying the rule (R) tothe premisesC1, . . . , Cn, which are conclusions of some derivations.

Definition 1.5 Iti) Let the following sets of rules be defined by:Base-Rules = {(Axiom), (Proj), (Weak), (I), (E), (C–FC )},Polymorphism= {(IK ), (EK ), (C–FK )},Dependencies= {(C–IC ), (C–EC), (K–FC ), (Conv)},Higher-Order = {(C–IK ), (C–EK), (K–FK ), (Conv)}.

I tii ) The eight typed systems in Barendregt’s cube can be represented by the set of derivation rulesused in each system.

λ→ = Base-Rules,

λω = λ→∪Higher-Order,

λ2 = λ→∪Polymorphism,

λω = λ→∪Higher-Order∪Polymorphism,

λP = λ→∪Dependencies,

λPω = λ→∪Dependencies∪Higher-Order,

λP2 = λ→∪Dependencies∪Polymorphism,

λPω = λ→∪Dependencies∪Higher-Order∪Polymorphism.

For each set of rulesS, we writeΓ ⊢S A :B to indicate thatΓ ⊢t A :B can be derived using onlythe rules inS. The expression ‘systemS’ refers to the typed system obtained by restricting thefull system to allow only the rules inS. Then the eight typed systems can be arranged as verticesof the following cube (Barendregt’s cube):

λ→

6

-���>

λω

6

-

λ2 -���>

λω -

λP�

��>

6

λPω

6

λP2�

��>λPω

We list a few of the properties of this cube, being those that are explicitly used in this paper.

Property 1.6 A[B/b][C/c] ≡ A[C/c][B[C/c]/b], providedb 6∈ FV (C).

6

Property 1.7(CHURCH-ROSSER FORTS) A =β B & Γ ⊢t A :C & Γ ⊢t B :C ⇒ ∃D [A →→β D &B →→β D].

Property 1.8 Barendregt’s general typed system derives judgements of the following shapes:

Γ ⊢t M : φ, Γ ⊢t φ :K, or Γ ⊢t K : 2.

Property 1.9 D:: Γ, c:C ⊢t A :B ⇒ ∃D′ ⊆ D [D′:: Γ ⊢t C : s].

Property 1.10(TYPED GENERATION LEMMA ) I ti) Γ ⊢t a :A ⇒ ∃ s, B [Γ ⊢t B : s & a:B ∈ Γ &A =β B].

I tii) Γ ⊢t λa:A.B :C ⇒ ∃ s,D [Γ ⊢t Πa:A.D : s & Γ, a:A ⊢t B :D & C =β Πa:A.D].I tiii) Γ ⊢t AB :C ⇒ ∃D, E [Γ ⊢t A : Πd:D.E & Γ ⊢t B :D & C =β E[B/d]].I tiv) Γ ⊢t Πa:A.B :C ⇒ ∃ s1, s2, s3 [Γ ⊢t A : s1 & Γ, a:A ⊢t B : s2 & C =β s3].

Property 1.11 Γ ⊢t A :B ⇒ B ≡ 2 ∨ Γt ⊢t B : s.

Property 1.12(TERMINATION FOR TYPED TERMS) If Γ ⊢t A :B, thenA andB are both strongly normalizing.

1.2 The Cube of Type Assignment Systems

In this subsection, we will present the cube of type assignment system as was first introduced in [13].The definition of the type assignment cube is based on the definition of the type-erasing functionE. Infact, both the syntax of terms, and the rules of the type assignment systems in the cube are obtaineddirectly from the corresponding syntax and rules of the typed systems in Barendregt’s cube, by applyingE.

From now on, we will reserve the nametyped systems(TS) for the systems of Barendregt’s cube,and we reserve the expressiontype assignment systems(TAS) for the systems to be defined below.

As we already mentioned in the introduction, for the plane ofthe TScube without dependencies,there exists a function that, erasing type information fromtyped λ-terms, allows to switch from atyped system to a corresponding type assignment system. To be precise, it erases type informationfrom λ-bindings occurring inλ-terms, while leaving all type information that decorates bindings inconstructors and kinds intact. In [13], a more general function E was defined, by extending the domainof the above function to terms with dependencies in a naturalway, as shown in the next definition.

Definition 1.13 Iti) {∗,2} is the set ofsorts.I tii ) The sets ofλ-terms(Λ), constructors(Cons), andkinds(Kind) are mutually defined by the follow-

ing grammar, whereM,φ andK, are metavariables forλ-terms, constructors and kinds respect-ively:

M ::= x | λx.M | MM

φ ::= α | Πx:φ.φ | Πα:K.φ | λx:φ.φ | λα:K.φ | φφ | φM

K ::= ∗ | Πx:φ.K | Πα:K.K

The setTu of termsis the union of the setsΛ, ConsandKind.I tiii ) Theerasing function E: Tt → Tu is inductively defined as follows:

I ta) OnΛt.

E (x) = x,

E (MN) = E (M)E (N),

E (Mφ) = E (M),

E (λx:φ.M) = λx.E (M),

7

E (λα:K.M) = E (M).

I tb) OnConst.

E (α) = α,

E (Πx:φ.ψ) = Πx:E (φ).E (ψ),

E (Πα:K.ψ) = Πα:E (K).E (ψ),

E (λx:φ.ψ) = λx:E (φ).E (ψ),

E (λα:K.ψ) = λα:E (K).E (ψ),

E (φψ) = E (φ)E (ψ),

E (φM) = E (φ)E (M).

I tc) OnKindt.

E (∗) = ∗,

E (Πx:φ.K) = Πx:E (φ).E (K),

E (Πα:K1.K2) = Πα:E (K1).E (K2).

The erasing function is extended to contexts in the obvious way and we use the notationE (Γ).Note that the behaviour ofE is such that, in the image ofE, λ-terms are completely untyped, whileconstructors and kinds are ‘partially’ typed.

The notions of free variables, subterms andβ-reduction, to be defined below, are similar to their ‘fullytyped’ counterparts as can be found in [4, 11], but slightly modified, according to the untyped termsyntax.

Definition 1.14 FV (A), the set offree variables ofA, and ST(A), the set ofsubtermsof A, areinductively defined by:

FV (∗) = ∅,

FV (a) = {a},

FV (BC) = FV (B) ∪ FV (C),

FV (Πa:B.C) = FV (B) ∪ (FV (C) \ {a}),

FV (λa:B.C) = FV (B) ∪ (FV (C) \ {a}),

FV (λx.M) = FV (M) \ {x},

ST(∗) = {∗},

ST(a) = {a},

ST(BC) = {BC} ∪ ST(B) ∪ ST(C),

ST(Πa:B.C) = {Πa:B.C} ∪ ST(B) ∪ ST(C),

ST(λa:B.C) = {λa:B.C} ∪ ST(B) ∪ ST(C),

ST(λx.M) = {λx.M} ∪ ST(M).

Definition 1.15 The result of a simultaneous substitutionS = [A1/a1, . . . ,An/an], applied to a term

8

D, is denoted either byD[A1/a1, . . . , An/an], or byDS . We normally assume that no variable boundin D is free in any of theAi’s and that the set{a1, . . . , an} is disjoint from the set of bound variablesof D. Formally, the substitution on terms is inductively definedby:

aSi ≡ Ai, for 1≤ i≤n,

bS ≡ b, for every b 6∈ {a1, . . . , an},

(BC)S ≡ BSCS,

(Πb:B.C)S ≡ Πb:BS .CS,

(λb:B.C)S ≡ λb:BS .CS,

(λx.M)S ≡ λx.MS .

The ‘untyped variant’ of Property1.6also holds:

Lemma 1.16A[B/b][C/c] ≡ A[C/c][B[C/c]/b], providedb 6∈ FV (C).

Proof: By easy induction on the definition of substitution.

Definition 1.17 β-reduction on terms can no longer be presented through a single generic rule as inDefinition 1.2. Instead, we have the following three rules:

(λx:φ.ψ)M →β ψ[M/x],

(λα:K.φ)ψ →β φ[ψ/α],

(λx.M)N →β M [N/x].

The relations→→β and=β are defined as usual, starting from the reduction rules defined above.

Lemma 1.18 IfB =β C, thenB[D/a] =β C[D/a].

Proof: By easy induction on the definition of=β, using Lemma1.16.

Definition 1.19 Iti) A statementis an expression of one of the forms:M : φ, φ :K, or K : 2,

whereM is aλ-term,φ is a constructor andK is a kind. The left part of the statement is calledthesubject, the right part is called thepredicate.

I tii ) A declarationis a statement whose subject is a variable.

Definition 1.20 Iti) A contextis a sequence of declarations, whose subjects are distinct.The emptycontext is denoted by<>.

I tii ) Equality on contexts is defined by:I ta) <> =<>;I tb) Γ, a:A = Γ′, b:B, if Γ = Γ′, a ≡ b, andA ≡ B.

I tiii ) We writea:A ∈ Γ, if the declarationa:A occurs inΓ.I tiv) Thedomainof Γ, denoted byDom(Γ), is the set{a | ∃A [a:A ∈ Γ]}.I tv) If Γ1 andΓ2 are contexts such thatDom(Γ1) ∩ Dom(Γ2) = ∅, thenΓ1, Γ2 is a context obtained by

concatenatingΓ1 to Γ2.I tvi) FV (Γ) =

⋃{FV (A) | ∃ a [a:A ∈ Γ]}.

I tvii) We extend the notion of substitution to contexts by:<>S =<>, and(Γ, b:B)S = ΓS , b:BS.

Given the difference in syntax, the type assignment rules aspresented in Definition1.21are only inappearance similar to those of Definition1.3. Note that the denotation of a rule is only different for therules (I), (IK ) and (EK ). We will, therefore, take the liberty of using the same notation and names forrules; note, however, that the similarity is only superficial.

9

Definition 1.21 (GENERAL TYPE ASSIGNMENT SYSTEM) The following rules are used to derivejudgementsof the formΓ ⊢ A :B, whereΓ is a context andA :B is a statement.I ti) Common Rules

(Proj)Γ ⊢ A : s a 6∈ Dom(Γ)

Γ, a:A ⊢ a : A

(Weak)Γ ⊢ A : B Γ ⊢ C : s c 6∈ Dom(Γ)

Γ, c:C ⊢ A : B

(Conv)Γ ⊢ A : B Γ ⊢ C : s B =β C

Γ ⊢ A : C

I tii ) λ-Term Rules

(I)Γ, x:φ ⊢ M : ψ

Γ ⊢ λx.M : Πx:φ.ψ

(E)Γ ⊢ M : Πx:φ.ψ Γ ⊢ N : φ

Γ ⊢ MN : ψ[N/x]

(IK)Γ, α:K ⊢ M : φ

Γ ⊢ M : Πα:K.φ

(EK)Γ ⊢ M : Πα:K.φ Γ ⊢ ψ : K

Γ ⊢ M : φ[ψ/α]

I tiii ) Constructor Rules

(C–IC )Γ, x:φ ⊢ ψ : K

Γ ⊢ λx:φ.ψ : Πx:φ.K

(C–EC)Γ ⊢ ψ : Πx:φ.K Γ ⊢ M : φ

Γ ⊢ ψM : K[M/x]

(C–IK)Γ, α:K1 ⊢ ψ : K2

Γ ⊢ λα:K1.ψ : Πα:K1.K2

(C–EK)Γ ⊢ φ : Πα:K1.K2 Γ ⊢ ψ : K1

Γ ⊢ φψ : K2[ψ/α]

(C–FC )Γ, x:φ ⊢ ψ : ∗

Γ ⊢ Πx:φ.ψ : ∗

(C–FK)Γ, α:K ⊢ φ : ∗

Γ ⊢ Πα:K.φ : ∗

I tiv) Kind Rules

(Axiom)<> ⊢ ∗ : 2

(K–FC)Γ, x:φ ⊢ K : 2

Γ ⊢ Πx:φ.K : 2

10

(K–FK)Γ, α:K1 ⊢ K2 : 2

Γ ⊢ Πα:K1.K2 : 2

Notice that, unlike for the derivation rules of Definition1.3, the subject does not change in the typeassignment rules (IK ) and (EK ). These two, together with the rules (Weak) and (Conv), are called thenot syntax-directed rules.

The notion of derivation and subderivation for a judgement are the same as in Definition1.4, and ananalogue of Property1.8also holds:

Lemma 1.22 The general type assignment system derives judgements of the following shapes:

Γ ⊢ M : φ, Γ ⊢ φ :K, or Γ ⊢ K : 2.

Proof: Easy, by looking at the rules and by observing that the setsConsandKind are closed for thesubstitution ofλ-term-variables byλ-terms and constructor-variables by constructors.

As before, atypeis a constructor of kind∗ (and this is again a context-dependent property). Aλ-termM is typableif there are a contextΓ and a constructorφ, such thatΓ ⊢ M : φ (we prove in Section2thatφ must be a type).

As in [13], we can distinguish eight different type assignment systems, defined using the same col-lection of rules given in Definition1.5 (I ti) for the TS-cube.

F1 = Base-Rules,

F′ = F1∪ Higher-Order,

F2 = F1∪ Polymorphism,

Fω = F1∪ Higher-Order∪Polymorphism,

DF1 = F1∪ Dependencies,

DF′ = F1∪ Dependencies∪Higher-Order,

DF2 = F1∪ Dependencies∪Polymorphism,

DFω = F1∪ Dependencies∪Higher-Order∪Polymorphism.

Like for TS we will use, for each set of rulesS, the expressionΓ ⊢S A :B to indicate thatΓ ⊢ A :Bcan be derived using only the rules inS. These systems can be arranged as vertices of the followingcube:

F1

6

-���>

F′

6

-

F2 -���>

Fω -

DF1�

��>

6

DF′

6

DF2�

��>DFω

Notice that, in the left-hand plane of the cube, the constructors coincide with the typed ones, becausethere they cannot depend onλ-terms. This no longer holds in the right-hand plane: here wecan buildconstructors like(λx:φ.ψ)N , whereN is a pure, untypedλ-term.

11

The systemF1 corresponds to the well-known Curry type assignment system, whereasF2 is thetype assignment version of the second orderλ-calculus. The three dimensions in this cube of typeassignment systems correspond, as for Barendregt’s cube, to the introduction ofpolymorphic types,higher-order typesanddependent types.

2 Properties of the Cube of Type Assignment Systems

In this section, we will prove that all systems in the TAS-cube satisfy good computational properties,like subject reduction, the Church-Rosser property, and strong normalization of typable terms. To provethese results, we need more definitions and technical lemmas, stating properties of the systems that arealso of independent interest.

2.1 Basic properties

In this subsection, we will focus on some of the basic properties that hold for the cube of Type As-signment Systems. They are those that can be expected, and that also hold (in their typed variants)for Barendregt’s cube; of course the results of section3 show that those results cannot be used for theproofs needed here.

The following lemma states that every term, typable by∗ or 2, cannot be typable by both, andguarantees consistency of the system.

Lemma 2.1 For every contextΓ, termA, and sortss1, s2: if Γ ⊢ A : s1 andΓ ⊢ A : s2, thens1 ≡ s2.

Proof: This is an obvious consequence of Lemma1.22.

Definition 2.2 A legal contextis inductively defined as follows:I ti) The empty context<> is legal;I tii ) If Γ is legal, and there existss, such thatΓ ⊢ A : s, then, for everya 6∈ Dom(Γ), alsoΓ, a:A is

legal.

Lemma 2.3 IfΓ ⊢ A :B, thenΓ is legal.

Proof: By easy induction on the structure of derivations, using Definition 2.2.

From now on, to avoid unnecessary complications in proofs and definitions, every context is assumedto be legal.

We define the following relations on contexts:

Definition 2.4 Iti) Γ ⊑ Γ′ ⇐⇒ Γ is a prefix ofΓ′.I tii ) The relation⊑· is inductively defined by:

I ta) <> ⊑· Γ.I tb) If Γ ⊑· Γ′, thenΓ, a:A ⊑· Γ′, a:A.I tc) If Γ ⊑· Γ′, thenΓ ⊑· Γ′, a:A.

For these relations, the following lemma holds.

Lemma 2.5 I ti) If Γ1 ⊑ Γ2, thenΓ1 ⊑· Γ2.I tii) If Γ1, a:A,Γ2 ⊑· Γ′, thenΓ′ = Γ′

1, a:A,Γ′2, with Γ1 ⊑· Γ′

1, andΓ′2 contains at least all statements of

Γ2.

Proof: Easy.

12

Notice that, in part(I tii) , in general the subcontextsΓ2 andΓ′2 are not legal contexts.

Lemma 2.6 IfΓ ⊑· Γ′andΓ ⊢ A :B, thenI ti) (Free Variable Lemma) FV(A) ∪ FV (B) ⊆ Dom(Γ).I tii) (Thinning Lemma)Γ′ ⊢ A :B.

Proof: I ti) By induction on the structure of derivations. The only interesting cases are the elim-ination rules; take for instance (E):

Γ ⊢ M : Πx:φ.ψ Γ ⊢ N : φ

Γ ⊢ MN : ψ[N/x](E).

By induction, if c ∈ FV (M) ∪ FV (Πx:φ.ψ), thenc ∈ Dom(Γ), and if c ∈ FV (N) ∪ FV (φ),thenc ∈ Dom(Γ). Observe that FV(ψ[N/x]) = FV (ψ)\{x} ∪ FV (N).

I tii ) By induction on the structure of derivations. The only interesting cases are (Proj) and (Weak).

(I t(Proj)) : ThenΓ = Γ1, a:A, for someΓ1, such thatΓ1 ⊢ A : s andΓ1, a:A⊑· Γ′. Then, by Lemma2.5 (I tii) , Γ′ = Γ′

1, a:A,Γ′2, with Γ1 ⊑· Γ′

1, and, by induction,Γ′1 ⊢ A : s. To deriveΓ′ ⊢ a :A,

apply (Proj) once, and then (Weak) a suitable number of times.

(I t(Weak)) : Then Γ = Γ1, c:C. SinceΓ1, c:C ⊑· Γ′, by Lemma2.5 (I tii) , we have thatΓ′ =Γ′

1, c:C,Γ′2 andΓ1 ⊑· Γ′

1. By induction,Γ′1 ⊢ A :B, and, by applying a series of (Weak),

we deriveΓ′ ⊢ A :B.

The following relation is introduced to abbreviate a sequence of derivation rules (IK ) and (EK ), thattogether correspond to polymorphism, and also takes the presence of rule (Conv) into account. It willbe of use in Lemma2.8and in Theorem2.18.

Definition 2.7 We define the relation� on constructors inductively by:

φ =β ψ ⇒ φ � ψ,

φ � Πα:K.φ,

Πα:K.φ � φ[ξ/α],

φ � ψ � ξ ⇒ φ � ξ.

The four cases in Definition2.7 reflect, respectively, an application of rule (Conv), (IK ), or (EK ),and a sequence of not syntax directed rules.

Worth noticing is the second case of Definition2.7, because it illustrates an important differencebetween the original presentation of the polymorphic type assignment system [17], and our presentationas a system in the topology of the TAS-cube. The equivalent rule for (IK) in the polymorphic typeassignment system is:

(∀ I)Γ ⊢ M : σ

Γ ⊢ M : ∀α.σα 6∈ FV (Γ)

The type∀α.σ is essentially the constructorΠα:∗.σ, andα 6∈ FV (Γ) is a side-condition, indicating thatbinding of the type variableα is only allowed whenα does not occur free in any predicate belongingto the context. The polymorphic type assignment system needs this side-condition to avoid to assign,for example,

x:α ⊢ x : ∀α.α.

13

The TAS presentation of this system does not require this extra condition on the derivation rule (IK):in fact, types are generated by the system itself, using onlylegal contexts, which are essentially linearordered sets of declarations in the derivations. In these systems, it is impossible to apply a (IK) rule tothe derivation for

α:∗, x:α ⊢ x : α,

becauseα:∗ is not the right-most declaration in the context; whenΓ, α:∗ ⊢ M : α, then, by legality ofthe context,α does not occur inΓ, so especially does not occur free inΓ. We can say that the extracondition on (IK) is hiddenin the definition of legal context.

For TAS the following properties hold:

Lemma 2.8(GENERATION LEMMA FOR λ-TERMS) I ti) If Γ ⊢ x : ξ, then there isξ′, such thatx:ξ′ ∈ Γandξ′ � ξ.

I tii) If D:: Γ ⊢ MN : ξ, then there areΓ′, φ, ψ, andD′ ⊆ D, such thatψ[N/x] � ξ and

D′::Γ′ ⊢ M : Πx:φ.ψ Γ′ ⊢ N : φ

Γ′ ⊢ MN : ψ[N/x](E).

I tiii) If D:: Γ ⊢ λx.M : ξ, then there areΓ′, φ, ψ, andD′ ⊆ D, such thatΠx:φ.ψ � ξ and

D′::Γ′, x:φ ⊢ M : ψ

Γ′ ⊢ λx.M : Πx:φ.ψ(I).

Proof: By induction on the structure of derivations, using Definition 2.7.

Notice that this lemma states more than, for example, Property 1.10, since it explicitly states theexistence of a subderivation. This will be convenient in theproof of Theorem2.18. Also the followingproperties hold.

Lemma 2.9(GENERATION LEMMA FOR CONSTRUCTORS AND KINDS) I ti) If Γ ⊢ α : K, then there isK ′, such thatα:K ′ ∈ Γ andK ′ =β K.

I tii) If Γ ⊢ λa:A.B :C, then there areΓ′ ⊑ Γ, andD, such thatΓ′, a:A ⊢ B :D andΠa:A.D =β C.I tiii) If Γ ⊢ AB :C, then there areΓ′ ⊑ Γ, D, andE, such thatΓ′ ⊢ A : Πd:D.E, Γ′ ⊢ B :D and

E[B/d] =β C.I tiv) If Γ ⊢ Πa:A.B : s, then there isΓ′ ⊑ Γ, such thatΓ′, a:A ⊢ B : s.

Proof: By easy induction on the structure of derivations.

2.2 Typability

In this subsection, we will focus on a number of more evolved properties of the cube of Type Assign-ment Systems. First we prove that the notion of reduction as presented in Definition1.17satisfies thefollowing property.

Property 2.10(CHURCH-ROSSER FORTAS) If A→→β A′ andB →→β B

′, then there existsC, such thatA′ →→β C andB′ →→β C.

Proof: In the terminology of Klop [16], ourβ-reduction is a regular combinatory reduction system,and thus the Church-Rosser property follows from Theorem 3.11 in [16].

The following lemma shows that all subterms of typable termsare typable.

14

Lemma 2.11 LetB ∈ ST(A). If Γ ⊢ A :C, then there existΓ′,E, such thatΓ′ ⊢ B :E.

Proof: By induction on the structure of derivations. The only interesting cases are the introductionrules (C–IC ) and (C–IK); the others follow by easy induction. Take for instance (C–IC):

Γ, x:φ ⊢ ψ : K

Γ ⊢ λx:φ.ψ : Πx:φ.K(C–IC).

Recall that ST(λx:φ.ψ) = {λx:φ.ψ} ∪ ST(φ) ∪ ST(ψ). The result follows directly forB ≡ λx:φ.ψ,by induction forB ∈ ST(ψ), and by induction and Lemma2.3 for B ∈ ST(φ).

The next lemma formulates that the class of derivable statements is closed for substitution on terms.

Lemma 2.12(SUBSTITUTION LEMMA ) If Γ1, c:C,Γ2 ⊢ A :B, andΓ1 ⊢ D :C, thenΓ1,Γ2[D/c] ⊢ A[D/c] :B[D/c].

Proof: By induction on the structure of derivations. The most interesting cases are when the last ruleis (Proj), (Weak), or (Conv).

(I t(Proj)) : If this rule is applied to the variablec, then we have

Γ1 ⊢ C : s c 6∈ Dom(Γ1)

Γ1, c:C ⊢ c :C(Proj),

and the result follows immediately from the assumptionΓ1 ⊢ D :C.

Otherwise, (Proj) is applied to a variable different fromc, i.e.,Γ2 = Γ′2, b:B and

Γ1, c:C,Γ′2 ⊢ B : s b 6∈ Dom(Γ1, c:C,Γ2)

Γ1, c:C,Γ′2, b:B ⊢ b :B

(Proj).

Then, by induction, we obtainΓ1,Γ2[D/c] ⊢ B[D/c] : s. Notice that, from the assumptionΓ1 ⊢ D :Cand Lemma2.6 (I ti), we know that FV(D) ⊆ Dom(Γ1). Then, sinceb 6∈ Dom(Γ1, c:C,Γ2), alsob 6∈Dom(Γ1,Γ2[D/c]). ThenΓ1,Γ2[D/c], b:B[D/c] ⊢ b :B[D/c], as desired.

(I t(Weak)) : Like for (Proj), we have to consider two subcases, of which the first is of theform

Γ1 ⊢ A :B Γ1 ⊢ C : s c 6∈ Dom(Γ1)

Γ1, c:C ⊢ A :B(Weak).

The result follows directly from the assumptionΓ1 ⊢ A :B and the observation that, sincec 6∈Dom(Γ1) ⊇ FV (A) ∪ FV (B), by Lemma2.6 (I ti), alsoA[D/c] ≡A andB[D/c] ≡B. The secondcase follows by straightforward induction.

(I t(Conv)) : By induction and Lemma1.18.

Now we are able to prove the property that all predicates in derivable statements are typable.

Lemma 2.13 IfΓ ⊢ E : F , then eitherF ≡ 2, or Γ ⊢ F : s.

Proof: By induction on the structure of derivations.

(I t(Axiom), (Conv), (Proj)) : Immediate.

(I t(Weak)) : By induction.

15

(I tElimination Rules) : ThenF ≡B[D/a], Γ ⊢ C : Πa:A.B andΓ ⊢ D :A. By induction, eitherΠa:A.B ≡2, or Γ ⊢ Πa:A.B : s, for somes. The first is impossible; for the second, by the GenerationLemma (2.9 (I tiv)), there is aΓ′, such thatΓ′, a:A ⊢ B : s andΓ′ ⊑ Γ. ThenΓ, a:A ⊢ B : s fol-lows from Lemmas2.5 (I ti) and2.6 (I tii) . By applying the Substitution Lemma (2.12), we obtainΓ ⊢ B[D/a] : s.

(I tIntroduction Rules) : ThenF ≡Πa:A.B, andΓ, a:A ⊢ E :B. By induction, eitherB ≡2, orΓ, a:A ⊢ B : s,for somes. The first case is impossible; for the second, apply a formation rule to obtainΓ ⊢ Πa:A.B : s.

(I tFormation Rules) : ThenF ≡ s, andΓ, a:A ⊢ B : s. ClearlyF ≡ 2, or F ≡ ∗. The first case isimmediate; in the second, observe thatΓ′ ⊢ ∗ : 2 is derivable for all legal contexts.

Lemma 2.14 IfΓ ⊢ M : φ, thenΓ ⊢ φ : ∗, i.e.,φ is a type with respect toΓ.

Proof: By Lemma2.13, eitherφ ≡ 2, or Γ ⊢ φ : s. But, by Lemma1.22, φ 6≡2, sinceM ∈ Λ. Wefinish the proof by showing thatΓ ⊢ φ : s impliess ≡ ∗, by induction on the structure of derivations.The only important cases are the elimination rules, of whichwe show one example, and the (Proj) rulefor constructors; the others follow by easy induction.

(I t(C–EC)) : ThenΓ ⊢ φ :K[N/x] andK[N/x] is a sort. By the syntax of kinds we have thatK[N/x] ≡∗.

(I t(Proj)) : Thenφ is a constructor variable, sayα. ThenΓ = Γ′, α:s and, by legality of contexts, alsoΓ′ ⊢ s : s′. But this is possible only ifs ≡ ∗.

2.3 Subject reduction

We now come to the proof that the here defined notion of type assignment is closed for subject reductionon typableλ-terms, i.e., ifΓ ⊢ M :ψ andM →→β N , then alsoΓ ⊢ N :ψ. The proof of this result isnot immediate, because of the presence of the derivations rules that are not syntax directed. It requiresa sequence of lemmas; to start with, the next lemma states that contexts can be considered moduloβ-conversion of predicates.

Lemma 2.15 IfΓ1, a:A,Γ2 ⊢ B :C, thenΓ1, a:A′,Γ2 ⊢ B :C, for all A′ such thatΓ1, a:A

′ is legal andA′ =β A.

Proof: By induction on the structure of derivations. Most cases aredealt with by straightforwardinduction, except for:

(I t(Proj)) : If B ≡ a, alsoC ≡ A and Γ2 = <>. ThenΓ1 ⊢ A : s and a 6∈ Dom(Γ1). The result isobtained from the following derivation (which exists, sinceΓ1, a:A

′ is legal):

Γ1 ⊢ A′ : s a 6∈ Dom(Γ1) (Proj)Γ1, a:A

′ ⊢ a :A′

Γ1 ⊢ A : s Γ1 ⊢ A′ : s a 6∈ Dom(Γ1) (Weak)Γ1, a:A

′ ⊢ A : s A =β A′

(Conv)Γ1, a:A

′ ⊢ a :A.

If B is a variable different froma, the result follows by induction.

(I t(Weak)) : If this rule is applied to the variablea, thenΓ1 ⊢ B :C anda 6∈ Dom(Γ1). Then we can alsoderive (again, by assumption,Γ1, a:A

′ is legal):

Γ1 ⊢ B :C Γ1 ⊢ A′ : s a 6∈ Dom(Γ1)

Γ1, a:A′ ⊢ B :C

(Weak).

Again, if this rule is applied to a variablec different froma, the result follows by induction.

The following two lemmas together prove that ifΠx:φ.ψ is derivable forλx.M from the contextΓ,thenψ is derivable forM from the contextΓ, x:φ.

16

Lemma 2.16 IfΓ ⊢ λx.M : ξ, then there areK1, . . . ,Kk, φ andψ, such thatΠki=1αi:Ki.Πx:φ.ψ =β

ξ, andΓ, α1:K1, . . . , αk:Kk, x:φ ⊢ M : ψ.

Proof: By induction on the structure of derivations.

(I t(I)) : Immediate, withk = 0.

(I t(Weak)) : Let Γ beΓ′, c:C, thenΓ′ ⊢ λx.M : ξ andΓ′ ⊢ C : s. By induction,

ξ =β Πki=1αi:Ki.Πx:φ.ψ andΓ′, α1:K1, . . . , αk:Kk, x:φ ⊢ M : ψ.

Since

Γ′, α1:K1, . . . , αk:Kk, x:φ ⊑· Γ′, c:C,α1:K1, . . . , αk:Kk, x:φ,

we can apply Lemma2.6 (I tii) to obtainΓ′, c:C,α1:K1, . . . , αk:Kk, x:φ ⊢ M :ψ.

(I t(Conv), (IK)) : Easy.

(I t(EK)) : Let ξ ≡ ξ′[µ/α], then there existsK, such thatΓ ⊢ λx.M : Πα:K.ξ′ andΓ ⊢ µ :K. Byinduction, we have

Πα:K.ξ′ =β Πki=1αi:Ki.Πx:φ.ψ andΓ, α1:K1, α2:K2, . . . , αk:Kk, x:φ ⊢ M : ψ.

By the Church-Rosser Property (2.10), β-convertible terms have a common reduct, so it must bethat k≥ 1, K =β K1 (assuming byα-conversion thatα is α1) andξ′ =β Πk

i=2αi:Ki.Πx:φ.ψ. ByLemma1.18, we haveξ ≡ ξ′S =β Πk

i=2αi:KSi .Πx:φ

S .ψS , whereS stands for the substitution[µ/α].By Lemma2.15, we have

Γ, α:K,α2:K2, . . . , αk:Kk, x:φ ⊢ M : ψ,

and by the Substitution Lemma (2.12), we obtain

Γ, α2:KS2 , . . . , αk:K

Sk , x:φ

S ⊢ M :ψS .

The other cases are impossible.

Lemma 2.17(TERM ABSTRACTION LEMMA ) If Γ ⊢ λx.M : Πx:φ.ψ, thenΓ, x:φ ⊢ M : ψ.

Proof: By Lemma2.16, we haveΠx:φ.ψ =β Πki=1αi:Ki.Πx:φ

′.ψ′, and since these two expressionshave a common reduct, it must be thatk = 0, φ =β φ

′ andψ =β ψ′. Also by Lemma2.16, we know

that Γ, x:φ′ ⊢ M :ψ′. SinceΓ ⊢ λx.M : Πx:φ.ψ, by Lemma2.13, alsoΓ ⊢ Πx:φ.ψ : ∗. By Lemma2.9 (I tiv), there existsΓ′ ⊑ Γ, such thatΓ′, x:φ ⊢ ψ : ∗, so by the Thinning Lemma2.6 (I tii) , alsoΓ, x:φ ⊢ ψ : ∗ and, by Lemma2.3, Γ, x:φ is legal. Sinceφ =β φ

′, by Lemma2.15, Γ, x:φ ⊢ M :ψ′.Moreover, sinceΓ, x:φ ⊢ ψ : ∗ andψ =β ψ

′, we can apply rule (Conv) to this last derivation and obtainΓ, x:φ ⊢ M :ψ.

Using this last lemma, is becomes easy to prove that the notion of type assignment we consider inthis paper is closed for subject reduction on terms.

Theorem 2.18 (SUBJECT REDUCTION FORTERMS) If Γ ⊢ M :ψ andM →→β N , thenΓ ⊢ N :ψ.

Proof: By induction on the number ofβ-reduction steps inM →→β N . We just consider the base case,the inductive step is straightforward. The base case is proved by structural induction on the contextin which the redex occurs: we only consider the caseM ≡ (λx.P )Q andN ≡ P [Q/x]. Let D be aderivation forΓ ⊢ (λx.P )Q : ψ. By the Generation Lemma (2.8 (I tii) ), D has the following structure:

17

...Γ′ ⊢ (λx.P ) : Πx:φ′.ψ′

...Γ′ ⊢ Q : φ′

D1:: (E)Γ′ ⊢ (λx.P )Q :ψ′[Q/x]

...D::

Γ ⊢ (λx.P )Q : ψ

with ψ′[Q/x] � ψ. That is, there is a subderivationD1, ending with an application of rule (E), thatis followed by a (possibly empty) sequence of applications of the not syntax-directed rules (Weak),(Conv), (IK ) and (EK ). By the Term Abstraction Lemma (2.17), we obtain

Γ′, x:φ′ ⊢ P : ψ′.

SinceΓ′ ⊢ Q : φ′, by the Substitution Lemma (2.12), we obtain

Γ′ ⊢ P [Q/x] :ψ′[Q/x].

Apply the same rules as used to go fromD1 to D to obtain

Γ ⊢ P [Q/x] :ψ,

as desired.

2.4 Normalization

An important property of type assignment systems is the strong normalization of typable terms; this isalready know to hold for the systemsFω, F1, F2 andF′ [13]. Using this result, we will show that italso holds for the other four systems of the cube of type assignment systems.

For this, we use the functionED that ‘erases dependencies’, i.e., removes theλ-term informationin dependent types, as defined in [13], that is based on a similar definition given in [19]. A similarfunction, erasing term-dependencies in the Theory of Generalized Functionality of [21], can also befound in [5].

Definition 2.19 The functionED : Tu → Tu is defined as follows:I ti) OnΛ.

ED (M) = M.

I tii ) OnCons.

ED (α) = α,

ED (Πx:φ.ψ) = Πx:ED (φ).ED (ψ),

ED (Πα:K.ψ) = Πα:ED (K).ED (ψ),

ED (λx:φ.ψ) = ED (ψ),

ED (λα:K.ψ) = λα:ED (K).ED (ψ),

ED (φψ) = ED (φ)ED (ψ),

ED (φM) = ED (φ).

I tiii ) OnKind.

ED (∗) = ∗,

ED (Πx:φ.K) = ED (K),

ED (Πα:K1.K2) = Πα:ED (K1).ED (K2).

18

Lemma 2.20 For ED, the following properties hold:

ED ((λx.M)N) = (λx.ED (M))(ED (N)),

ED (M [N/x]) = ED (M)[ED (N)/x],

ED ((λα:K.φ)ψ) = (λα:ED (K).ED (φ))(ED (ψ)),

ED (φ[ψ/α]) = ED (φ)[ED (ψ)/α],

ED ((λx:φ.ψ)M) = ED (ψ),

ED (ψ[M/x]) = ED (ψ).

Let →β denote the one-stepβ-reduction rule. ThenA→β B implies either ED(A) →β ED (B), orED (A) ≡ ED (B).

Proof: Easy.

Using this dependency-erasing function, we can relate the strong normalization problem for the fullcube to that of the plane without dependencies, as done in thefollowing theorem.

Theorem 2.21 (TERMINATION FOR TERMS) If Γ ⊢ A :B, thenA is strongly normalizing.

Proof: In [13], Theorem2.2.1 states that ifΓ ⊢ A :B is a derived judgement inDFω (DF1, DF2,DF′), thenED (Γ) ⊢ ED (A) : ED (B) is derivable inFω (F1, F2, F′). Suppose now thatA ≡ A0 →β

A1 →β A2 →β . . . is a sequence ofβ-reductions. By Lemma2.20, for everyi ≥ 1, eitherED (Ai) →β

ED (Ai+1), or ED (Ai) ≡ ED (Ai+1). Suppose the sequenceA0 →β A1 →β A2 →β . . . is infinite.Sinceβ-reduction inFω (F1, F2, F′) is strongly normalizing, there is ann, such thatED (Aj) ≡ED (Aj+1), for everyj ≥ n. So from stepn, every step in the infinite sequenceA0 →β A1 →β A2 →β

. . . corresponds to a reduction of a redex of the form(λx:φ.ψ)M . However, sinceM is a λ-term,such a reduction cannot create new abstractions of the formλx:φ.ψ. Therefore, the number of suchabstractions must decrease after every step, and our reduction cannot be infinite.

Corollary 2.22 IfΓ ⊢ A :B, then:I ti) B is strongly normalizing.I tii) all predicates inΓ are strongly normalizing.

Proof: Immediate, using Lemmas2.13and2.3.

3 The relation between the cubes of Typed and Type AssignmentSystems

In this section we will focus on the relation between Barendregt’s cube and the cube of Type Assign-ment Systems.

3.1 Consistency, similarity, and isomorphism between systems

In this subsection, we first introduce the notions ofconsistency, similarity,andisomorphismbetweentyped and type assignment systems. Note that these notions depend on the choice of an erasing functionE .

Definition 3.1 Let St andSu be, respectively, a typed and type assignment system, and let E be anerasing function from terms inSt to terms inSu.I ti) We say thatSt andSu areconsistent(via E) if E is sound with respect to provable judgements, i.e.

Γt ⊢StAt :Bt impliesE (Γt) ⊢Su

E (At) : E (Bt).

19

I tii ) SystemsSt andSu aresimilar (via E) if they are consistent and, moreover,E is complete withrespect to provable judgements, i.e.Γ ⊢Su

A :B implies that there existsΓt,At andBt, such thatΓt ⊢St

At :Bt andE (Γt) = Γ, E (At) ≡ A andE (Bt) ≡ B.I tiii ) Let Dert andDeru be the sets of all derivations inSt andSu. SystemsSt andSu areisomorphic

(via E) if and only if there areF : Dert→Deru andG: Deru→Dert, such that:I ta) If D:: Γ ⊢St

A :B, thenF(D):: E (Γ) ⊢SuE (At) : E (Bt).

I tb) F◦G andG◦F are the identity onDeru andDert, respectively.I tc) BothF andG preserve the structure of derivations, (i.e., the tree obtained from a derivation

by erasing all judgements, but not the names of the rules).

Notice that the definition of isomorphism expresses more than just soundness and completeness ofE .Notice, moreover, thatF is not defined by induction on derivations, a detail that willbe of importancein Section4. Finally, notice that, in the previous definition,Su is not assumed to be obtained fromSt

through the application ofE to the rules ofSt.

The definition of isomorphism between two systems was already given in [13], but in a less general way.We have defined isomorphism with respect to an erasing function E ; the definition of isomorphism in[13] used afixedfunction. To be more precise, two systems are isomorphic according to the definitionin [13], if they are isomorphic in the sense of Definition3.1 with respect to the functionF that isdefined as follows:F (D) is obtained fromD by applying the erasing functionE to all terms inD; byabuse of notation, we denoteF (D) by E (D).

The following lemma states that, for the TS and TAS-cubes, the two notions of isomorphism coin-cide.

Lemma 3.2 Let St and Su be systems in corresponding vertices of theTS andTAS-cube, respectively,and suppose they are isomorphic through the functionsF andG. ThenF(D) = E (D), for every typedderivationD.

Proof: By easy induction.

To show consistency of our systems we need the following lemma that shows that type erasure doesnot affectβ-reduction.

Lemma 3.3 I ti) E (A[B/b]) ≡ E (A)[E (B)/b].I tii) If A→→β B, then E(A) →→β E (B).

Proof: I ti) By easy induction on the definition of substitution.

I tii ) By induction on the definition of→→β, using part(I ti).

A similar result forβ-conversion follows easily.

In [13], some results about the relation between TS and TAS have been proved. They are summarizedin the following proposition.

Proposition 3.4([13]) Let St and Su be systems in corresponding vertices of theTS and TAS-cube,respectively.I ti) Systems St and Su are consistent.I tii) If St and Su do not contain Dependencies as subset rules, then St and Su are isomorphic.

I tiii) If the assumption of part (I tii) is not satisfied, then St and Su are not isomorphic.

Proof: See [13]. The proof of parts(I ti) and (I tii) uses Lemma3.3.

20

So, all typed systemsSt are consistents with respect to the corresponding untyped systemsSu. Inaddition, applying the erasing functionE to all judgements used in a derivation inSt yields a correctderivation inSu. This implies thatSt andSu are similar. Unfortunately, systems with dependenciesneed not be isomorphic, as we will show below.

Although a counterexample for proving Proposition3.4 (I tiii) can be found in [13], we will give hereanother, both for the convenience of the reader, and becauseit is an easier example than that in [13] (itdoes not make use of the (Conv) rule).

Example 3.5Consider the following derivation inDF1 (for reasons of readability, we use the notationA→B for Πa:A.B, whena does not occur inB).

Let O stand for theλ-term(λxy.y) and letI denote the identity(λx.x). LetΓ be a context consistingof the following declarations:

α:∗, β:∗, γ:∗, a:(γ→γ)→ ∗ .

Clearly, we can derive bothΓ ⊢ I : α→α andΓ ⊢ O : (α→α)→γ→γ; combining these givesΓ ⊢ OI : γ→γ,with which we can deriveΓ ⊢ a(OI) : ∗; let Di be the derivation for this result:

D1:: Γ ⊢ a(OI) : ∗.

By applying rules (Weak) and (C–FC ), we getΓ ⊢ a(OI)→γ : ∗. Applying rule (Proj) givesΓ, u:a(OI)→γ ⊢ u : a(OI)→and by applying a (Weak) (using again derivationD1), we get

D2:: Γ, u:a(OI)→γ, v:a(OI) ⊢ u : a(OI)→γ.

On the other hand, we can also deriveΓ ⊢ I : β→β andΓ ⊢ O : (β→β)→γ→γ, which can be used,as above, to obtainΓ ⊢ a(OI)→γ : ∗, and by applying rules (Weak), (C–FC) and (Proj), we obtain

D3:: Γ, u:a(OI)→γ, v:a(OI) ⊢ v : a(OI).

Thus, using derivationsD2 andD3, and applying rule (E), we may conclude with

D4:: Γ, u:a(OI)→γ, v:a(OI) ⊢ uv : γ.

The above described derivation, although legal inDF1, is not an erasure of any derivation in the fullytyped systemλP. To see this, note that we used two different types for different occurrences of theλ-term I (and thus also for different occurrences ofO) to obtain the two derivationsD2 andD3. TheexpressionOI , however, is free of types, so the final typing for the application uv is correct. But if wewant to obtain a correct derivation inλP of whichD4 is the erasure, we have to assignthe same typeto the occurrences ofI in the types ofu andv.

More precisely, assume thatD4 is obtained by erasure of a typed derivationD′4, such that

D′4:: Γt, u:aMt→γ, v:aMt ⊢t uv : γ.

whereMt is a typedλ-term of typeγ→γ, such thatE (Mt) ≡ OI . The latter implies that

Mt ≡ (λα1:K1 . . . λαn:Kn.OtI t)φ1 · · ·φm,

for somen,m ≥ 0, whereE (Ot) ≡ O andE (I t) ≡ I . But the fact thatMt must have typeγ→γ impliesthatn = m = 0, and soMt ≡ OtI t.

SinceD4 is obtained fromD′4 by erasure, there must be two subderivations ofD′

4 proving, respect-ively,

21

Γt ⊢t Ot : (α→α)→γ→γ, andΓt ⊢t Ot : (β→β)→γ→γ,

such thatE (Ot) ≡ O. But this is not possible, since this implies that

Ot ≡ λx:α→α.λy:γ.y, andOt ≡ λx:β→β.λy:γ.y,

at the same time, whileα andβ are different constructor variables.

Notice however, that wecan deriveΓt, u : a(OtI t)→γ, v:a(OtI t) ⊢t uv : γ, because in constructing aderivation we are not forced to construct different typesα→α andβ→β for I t, but are free to chooseβ ≡ α; therefore, this example is not a counterexample against similarity.

After the negative result of Proposition3.4 (I tiii) , it is natural to ask if the corresponding systems inthe TS and TAS-cubes are at least similar, like was stated as conjecture in [13]. This property will beshown to hold in Theorem3.12, but only for those systems with dependencies that are without poly-morphism, namely, forDF1 versusλP, and forDF′ versusλPω. Unfortunately, adding polymorphismmakes a difference: the systems with both polymorphism and dependencies are not similar.

Theorem 3.6 Let St be eitherλP2, or λPω, and let Su be, respectively, DF2 and DFω. Then St andSu are not similar.

Proof: As a counterexample, we show a derivable judgement ofDF2, that cannot be obtained as anerasure of any derivable judgement inλP2.

Let Γ0 be a context consisting of the following declarations:

(type variables) α:∗, β:∗, γ:∗, δ:∗,(constructor variable)ǫ:β→∗,(λ-term variables) u : Πη:∗.((η→η)→α)→β, x:α, y:γ, z:δ.

Let K denote theλ-term(λxy.x), and let the untypedλ-termsM ,M0 andM1 be defined by:

M ≡ u(λf.x), M0 ≡ u(λf.Kx(fy)), and M1 ≡ u(λf.Kx(fz)).

Clearly, bothM0 andM1 β-reduce toM , and all these terms can correctly be assigned the typeβ inthe contextΓ0. Thus, we can assert

Γ0 ⊢ ǫM0→α : ∗, and Γ0 ⊢ ǫM1 : ∗,

and this means that the contextΓ = Γ0, p:ǫM0→α, q:ǫM1 is legal. With help of the rules (Proj), (Conv)

and (E), we can easily derive

Γ ⊢ pq : α.

We claim that the above judgement cannot be obtained as an erasure of any judgementΓt ⊢t Nt : φderivable inλP2, i.e., that we cannot haveE (Γt) = Γ, E (Nt) ≡ pq andE (φ) ≡ α. To justify ourclaim, let us assume the opposite. First note thatφ ≡ α, since no terms occur inα (the erasing functioncan only modify types containing occurrences of terms, in which case the result must also containterms). Similarly,Γt may differ fromΓ only in the declarations ofp andq, which must be of the form:

p:ǫM0t →α, and q:ǫM1

t ,

22

whereE (M0t ) ≡M0 andE (M1

t ) ≡M1.

We can assume thatNt is of the formPtQt, whereE (Pt) ≡ p andE (Qt) ≡ q (otherwise we consideran appropriate subterm ofNt instead). SincePt is applied toQt, and the type ofPtQt is α, it followsthatPt has a type of the formǫM0

t′→ α, whereE (M0

t′) ≡M0. Similarly,Qt has a type of the form

ǫM1t′, whereE (M1

t′) ≡ M1. In order to make the application well-typed (after a possible series of

applications of rule (Conv)), it must be thatM0t′=β M

1t′.

So we haveβ-convertibleλ-termsM0t′ andM1

t′, that erase toM0 andM1, respectively, and both are

of typeβ. Without loss of generality, we can assume that theseλ-terms have noβ-redexes involvingpolymorphic abstraction and/or application, and thus we may write:

M0t′≡ uγ(λf :γ→γ.Ktx(fy)), and M1

t′≡ uδ(λf :δ→δ.K′

tx(fz)),

whereKt andK′t both erase toK. The types off used in the above are forced by the applications

fy andfz. Note that the type off may not be externally quantified: if the polymorphic variable u isapplied to a typeµ, thenf must be of typeµ→µ, and no constructor applicationfφ is possible. Theβ-normal forms of these terms are as follows:M0

t′ reduces touγ(λf :γ→γ.x), whileM1

t′ reduces to

uδ(λf :δ→δ.x). But theseβ-normal forms are different, and this contradicts the previous claim thatM0

t′=β M

1t′.

The following picture graphically summarizes this proof.

6=βM0t′ =β

AAAAU

E

M0t

��

���

E

M0

β--

M1t

AAAAU

E

M1t′

��

���

E

M1

�

Tt

Tu

M

In the above system, we have shown the existence of two typedλ-terms, namelyM0t′ andM1

t′, and

of a contextΓ and typeβ that allow the construction of the counterexample to the similarity, i.e. suchthat:

• M0t′6=β M

1t′;

• E (M0t′) =β E (M1

t′);

• Γ ⊢t M0t′: β andΓ ⊢t M

1t′: β.

The heart of the counterexample lies in both the polymorphicrules, and the fact that it is possible toabstract with respect to variables not occurring in the body. In fact, in the proof above, the polymorphicbehaviour of the variableu makes that this term can be applied to both the termsλf :γ→γ.Ktx(fy)andλf :δ→δ.Ktx(fy). Also the use of theλ-term K is essential in order to obtain the correct finaltyping; becauseK is a cancelling term, the type assumed for the variablef has no effect on the type ofthe full termsM0

t′ andM1

t′.

It is natural to ask if this result allows some comparison between the power (with respect to typabilityand inhabitation) of the corresponding systems, respectively DF2 andλP2, DFω andλPω. Recallthat a (closed) typeφ is inhabited in a systemS, if and only if there is a (closed) termM such that<> ⊢ M : φ.

The following corollary states that the set of types inhabited inSu includes properly those types thatare obtained throughE from inhabited types inSt, and states that also the set of types assignable to aterm inSu is larger than its corresponding set inSt.

23

Corollary 3.7 Let St be eitherλP2 or λPω, and Su be, respectively, DF2 or DFω.I ti) {φ | ∃M [<> ⊢Su

M : φ]} ⊃6=

{φ | ∃φt,Mt [<> ⊢StMt : φt & E (φt) = φ]}.

I tii) Let M be a closed term. Then{φ | <> ⊢SuM : φ} ⊃

6={φ | ∃φt,Mt [<> ⊢St

Mt : φt & E (Mt) = M & E (φt) = φ]}.

Proof: I ti) The inclusion follows immediately from the fact thatSt andSu are consistent vieE. To prove that the inclusion is proper, take the derivation for Γ ⊢ pq : α as constructed inthe proof of Theorem3.6. Clearly,<> ⊢ λxyzpq.pq : φ, whereφ is the closure ofα with re-spect to the contextΓ. Then there is a derivation provingξ:φ→∗ ⊢ λxyzpq.pq : ∗, and, therefore,<> ⊢ Πξ:φ→∗λxyzpq.pq : ∗. Letψ be short forΠξ:φ→∗λxyzpq.pq, then obviouslyψ→ψ is atype inhabited inSu by the termλx.x, while it is not the erasure of an inhabited type inSt.

I tii ) Also in this case, the inclusion follows from the consistency via E betweenSu andSt. Toprove that the inclusion is proper, it is sufficient to observe that, for every closed termM typeablein Su, there is a typing forM of the shapeα:∗ ⊢ M : ξ[α]. Then<> ⊢ M : Πα:∗.ξ[α], and, byrule (EK ), <> ⊢ M : ξ[ψ], whereψ is defined as in part(I ti). Clearly this type cannot be theerasure of an inhabited type inSt.

3.2 Systems without polymorphism

In case polymorphism is not permitted, we can prove that the corresponding TS and TAS are similar.In what follows, the symbol⊢ denotes⊢S , for S ∈ {F1, F′, DF1, DF′}, while ⊢t refers to thecorresponding TS. That is, we consider only systems withoutpolymorphism. It is important to pointout that, restricting the systems in this way, the derivation rules (IK), (EK) and (C–FK ) are eliminated.Moreover, the syntax of terms is limited by no longer allowing for terms of the shapeMφ, λα:K.φ andΠα:K.φ.

Before we come to the main proof, we need some preliminary lemmas.

Lemma 3.8 I ti) If Γ ⊢t A :B andA is in β-normal form, then so is E(A).I tii) If E (A) is of the form∗, variable, application, abstraction, or product, then so isA.

Proof: Easy.

The following lemma formulates that, in the absence of polymorphism, the erasing functionE isinjective on terms in normal form that can be assigned the same predicate.

Lemma 3.9 SupposeΓ ⊢t B1 :A and Γ ⊢t B2 :A, and let bothB1 andB2 be β-normal forms. IfE (B1) ≡ E (B2), thenB1 ≡ B2.

Proof: By induction on the structure of terms.

(I tVariable or sort constant) : This case is immediate.

(I tAbstractions) : We only consider the case thatB1 is a λ-term, the other are essentially the same.Let B1 ≡ λx:φ1.M1, with φ1 andM1 in β-normal form. By Property1.10 (I tii) , we haveA =β

Πx:φ1.ψ1, for someψ1, such thatΓ, x:φ1 ⊢t M1 : ψ1. SinceE (B2) ≡ E (B1) ≡ λx.E (M1), it mustbe thatB2 ≡ λx:φ2.M2, for someφ2 andM2 in β-normal form. Furthermore,Γ ⊢t λx:φ2.M2 :Aand, by (Conv), we haveΓ ⊢t λx:φ2.M2 : Πx:φ1.ψ1. By Property1.10 (I tii) , we have thatΓ, x:φ2 ⊢t M2 : ψ2,for someψ2, such thatΠx:φ1.ψ1 =β A =β Πx:φ2.ψ2. By the Church-Rosser Property for TS (1.7),this impliesφ1 =β φ2 andψ1 =β ψ2. Sinceφ1 andφ2 areβ-normal forms, they must be identical.Thus, we have in factΓ, x:φ1 ⊢t M2 :ψ1 (with help of (Conv)) and, by induction, we getM1 ≡M2,soB1 ≡ B2.

24

(I tApplications) : If B1 is an application inβ-normal form, thenB1 ≡ aC1 · · ·Cn, wherea is a variable.Assume thata:D ∈ Γ. By Property1.10 (I tiii) , there areF1, . . . ,Fn andG, such that:

I ta) D =β Πni=1bi:Fi.G;

I tb) A =β G[C1/b1] · · · [Cn/bn];

I tc) Γ ⊢t Ci : Fi[C1/b1] · · · [Ci−1/bi−1], for all 1≤ i≤n.

SinceE (B1) ≡E (B2), we haveB2 ≡ aC ′1 · · ·C

′n, with E (Ci) ≡E (C ′

i). Repeating forB2 the sameargument as above, we get

I td) D =β Πni=1bi:F

′i .G

′;

I te) A =β G′[C ′

1/b1] · · · [C′n/bn];

I tf) Γ ⊢t C′i : F ′

i [C′1/b1] · · · [C

′i−1/bi−1], for all 1≤ i≤n.

We haveΠni=1bi:Fi.G =β D =β Πn

i=1bi:F′i .G

′. Using the Church-Rosser Property for TS (1.7), weeasily getG =β G

′ andFi =β F′i , for all 1≤ i≤n. It remains to show thatCi ≡ C ′

i, for all i. Notethat, by induction, and by the above properties(I tc) and (I tf), the termsCi andC ′

i have the sametype (the same kind) and are inβ-normal form. SinceCi is a subterm ofB1, by induction, we obtainCi ≡ C ′

i.

(I tProducts) : LetB1 ≡Πc:C1.D1. AsE (B2) ≡E (B1), we haveB2 ≡Πc:C2.D2. By Property1.10 (I tiv),we haveΓ, c:C1 ⊢t D1 : s andΓ, c:C2 ⊢t D2 : s. Since the contexts are legal, we have alsoΓ ⊢t C1 : sandΓ ⊢t C2 : s. By induction, we obtainC1 ≡ C2. ThusΓ, c:C1 ⊢t D2 : s and, once more by in-duction, we getD1 ≡ D2.

Using this result, in the following lemma we will prove that,in the absence of polymorphism, theerasing functionE is injective on terms, moduloβ-equality, that can be assigned the same predicate.

Lemma 3.10 LetΓ ⊢t B1 :A andΓ ⊢t B2 :A. If E (B1) =β E (B2), thenB1 =β B2.

Proof: Let B′1 be theβ-normal form ofB1 and letB′

2 be theβ-normal form ofB2 (by Theorem1.12, both terms are strong normalizable). SinceB1 reduces toB′

1, we haveE (B1) =β E (B′1), by

Lemma3.3 (I tii) , and similarly forB2. Thus, by Lemma3.8 (I ti), we haveE (B′1) ≡ E (B′

2) as theyareβ-normal forms. Finally, by Lemma3.9, we haveB′

1 ≡ B′2, and thusB1 =β B2.

Lemma 3.11 Suppose thatΓ ⊢ A :B. Then the following conditions hold:I ti) There exists a typed legal contextΓt, and typed termsAt, Bt, satisfying E(Γt) = Γ, E(At) ≡ A

and E(Bt) ≡ B, such thatΓt ⊢t At :Bt.I tii) For every typed legal contextΓt, and every typed termBt, satisfying E(Γt) = Γ, E(Bt) ≡ B and

Γt ⊢t Bt : s, there exists a typed termAt, such thatΓt ⊢t At :Bt and E(At) ≡ A.

Proof: By mutual induction on the structure of derivations.

(I t(Proj)) : ThenΓ = Γ′, a:B. Part (I ti) follows by induction. To show part(I tii) , assumeE (Γt) =Γ′, a:B andE (Bt) ≡ B andΓt ⊢t Bt : s. Note that we haveΓt = Γ′

t, a:B′t, with E (B′

t) ≡ B. ByLemma3.10,B′

t =β Bt. We want to prove thatΓt ⊢t a :Bt, which is accomplished as follows: sinceΓ′

t, a:B′t ⊢t Bt : s, by Property1.9, we know thatΓ′

t ⊢t B′t : s. We apply (Proj) to obtainΓt ⊢t a :B′

t

and, finally, (Conv) to concludeΓt ⊢t a :Bt.

(I t(Weak)) : Then Γ = Γ′, c:C, andΓ′ ⊢ A :B and Γ′ ⊢ C : s. To prove part(I ti), by induction onpart (I ti) to the first premise, we obtainΓ′

t ⊢t At :Bt. Then use part(I tii) to get Γ′t ⊢t Ct : s

(with the same context), and apply (Weak). For part (I tii) , by induction we obtainAt such thatΓ′

t, c:Ct ⊢t At :Bt. To be able to conclude the desired result by applying a (Weak), we also needΓ′

t ⊢t Ct : s; this is obtained by Property1.9 from the second premise.

25

(I t(Conv)) : Then there isC, such thatΓ ⊢ A :C andΓ ⊢ B : s, withB =β C. By induction, we deriveΓt ⊢t At :Ct andΓt ⊢t Bt : s. SinceE (Bt) ≡ B =β C ≡ E (Ct), by Lemma3.10, we haveBt =β

Ct, and we can apply (Conv) to prove part(I ti). Part (I tii) is similar.

(I tIntroduction Rules) : Part (I ti) follows immediately by induction; part(I tii) is similar, but here weuse Lemma3.8 (I tii) .

(I tElimination Rules) : Part (I ti) is easy (use Lemmas3.8 (I tii) and3.3 (I ti)). For part (I tii) , assumethat fromΓ ⊢ F : Πa:G.C andΓ ⊢ D :G we derivedΓ ⊢ FD :C[D/a]. Let Γt andHt be such thatE (Γt) = Γ andE (Ht) ≡ C[D/a]. Then by inductionΓt ⊢t Ft : Πa:Gt.Ct andΓt ⊢t Dt :Gt, and wecan deriveΓt ⊢t FtDt :Ct[Dt/a], using the same elimination rule. By Lemma3.3 (I ti), we haveE (Ct[Dt/a]) ≡ C[D/a] ≡ E (Ht).

SinceCt[Dt/a] is a predicate of a derivable judgement, alsoΓt ⊢t Ct[Dt/a] : s, by Property1.11.The termHt is assumed to satisfyΓt ⊢t Ht : s, and we may apply Lemma3.10to obtainCt[Dt/a] =β

Ht. By applying (Conv), we deriveΓt ⊢t FtDt :Ht.

The remaining cases are easy.

With the last lemma, we can prove the main theorem of this subsection.

Theorem 3.12 Let St be aTSsystem whose set of rules does not contain Polymorphism as subset, andlet Su be the correspondingTAS system. Then St and Su are similar.

Proof: By Theorem3.4 (I ti), and Lemma3.11 (I ti).

4 How to obtain an isomorphism

In this section, we will briefly discuss a way to define a cube oftype assignment systems that is iso-morphic to TS. As discussed above, the main problem that causes loss of isomorphism between TS andTAS, is that the erasure, throughE, of two typed terms can beβ-equivalent, while the originals werenot (a thorough investigation on the possible alternative definitions of the (Conv) rule on typed systemscan be found in [12]). We will show that it is possible to defineanother erasing function, namedE′,that gives rise to a second type assignment cubeTAS′ which is isomorphic to the TS-cube (viaE′).

Remember that the behaviour ofE was to erase type information fromλ-terms. So, in case ofdependencies, ifA is a typed constructor, occurring in a typed kind,E (A) can either coincide withA(in caseA does not contain occurrences ofλ-terms), orE (A) can be partially typed. The new erasingfunctionE′ we will present below has a context-dependent behaviour, inthe sense that it erases typeinformation fromλ-terms, butnot when these occur as subterms of constructors or kinds.

Definition 4.1 The new erasing functionE′ : Tt → T ′u is defined as follows:

E′ (M) = E (M),

E′ (φ) = φ,

E′ (K) = K.

Now we will define a new type assignment cubeTAS′. Note that, in contrast to the TAS-cube, thiscube is not obtained by applying an erasing functin to all rules of TS. Instead, the new derivation rulesare defined independently; however, the objects in the conclusion of each rule are in the codomain ofE′.

Definition 4.2 (THE TAS′ CUBE) LetM range overΛ, φ range over typed constructors andK rangesover typed kinds;A, B, andC range overT ′

u.

26

I ti) The untyped and typedλ-terms, typed constructors, and typed kinds are defined as before (Defin-itions 1.1and1.13). LetT ′

u be the union of the setsΛ, Const andKindt.I tii ) The general type assignment system proves judgements of the following form:

Γ ⊢′ M : φ, Γ ⊢′ φ :K, or Γ ⊢′ K : 2.whereφ ∈ Const, andK ∈ Kindt.

I tiii ) The type assignment rules are:

(Axiom)<> ⊢′ ∗ : 2

(Conv)Γ ⊢′ A : B Γ ⊢′ C : s B =β C

Γ ⊢′ A : C

(Proj)Γ ⊢′ A : s a 6∈ Dom(Γ)

Γ, a:A ⊢′ a : A

(Weak)Γ ⊢′ A : B Γ ⊢′ C : s c 6∈ Dom(Γ)

Γ, c:C ⊢′ A : B

(I)Γ, x:φ ⊢′ M : ψ

Γ ⊢′ λx.M : Πx:φ.ψ

(E)Γ ⊢′ M : Πx:φ.ψ Γ ⊢t Nt : φ

Γ ⊢′ M(E (Nt)) : ψ[Nt/x]

(IK)Γ, α:K ⊢′ M : φ

Γ ⊢′ M : Πα:K.φ

(EK)Γ ⊢′ M : Πα:K.φ Γ ⊢′ ψ : K

Γ ⊢′ M : φ[ψ/α]

(C–IC )Γ, x:φ ⊢′ ψ : K

Γ ⊢′ λx:φ.ψ : Πx:φ.K

(C–EC)Γ ⊢′ ψ : Πx:φ.K Γ ⊢t Mt : φ

Γ ⊢′ ψMt : K[Mt/x]

(C–IK)Γ, α:K1 ⊢′ ψ : K2

Γ ⊢′ λα:K1.ψ : Πα:K1.K2

(C–EK)Γ ⊢′ φ : Πα:K1.K2 Γ ⊢′ ψ : K1

Γ ⊢′ φψ : K2[ψ/α]

(C–FC )Γ, x:φ ⊢′ ψ : ∗

Γ ⊢′ Πx:φ.ψ : ∗

(C–FK)Γ, α:K ⊢′ φ : ∗

Γ ⊢′ Πα:K.φ : ∗

(K–FC)Γ, x:φ ⊢′ K : 2

Γ ⊢′ Πx:φ.K : 2

27

(K–FK)Γ, α:K1 ⊢′ K2 : 2

Γ ⊢′ Πα:K1.K2 : 2

Notice that the derivation rules (E) and (C–EC) require derivations in TS, although restrictedto typedλ-terms. This means that, officially, all rules of TS belong tothe set of rules. Notice,moreover, thatonly types dependent ontypedλ-terms are created in this way.

I tiv) As in Definition1.5 (I ti), the rules can be grouped in sets. Again eight type assignment systemscan be defined, whose relation can be represented as before bydrawing a cube.

The main result on the relation between the TS-cube and theTAS′-cube is:

Theorem 4.3 Let St be any typed system in theTS-cube, and let Su be the corresponding system intheTAS′-cube. Then St and Su are isomorphic (via E′).

Proof: I ti) The functionF : Dert→Deru can be defined by induction on the structure ofD ∈Dert in the following way:

(I t(E)) : In this case, the typed derivation has the following shape:

D::D′:: Γ ⊢t M : Πx:φ.ψ Γ ⊢t N : φ

Γ ⊢t MN :ψ[N/x](E).

By induction,F(D′):: E′ (Γ) ⊢′ E′ (M) : E′ (Πx:φ.ψ). SinceE′ (Πx:φ.ψ) ≡Πx:φ.ψ andE′ (Γ)= Γ, we can define:

F(D)::Γ ⊢′ E′ (M) : Πx:φ.ψ Γ ⊢t N : φ

Γ ⊢′ E′ (MN) : ψ[N/x](E).

(I t(C–EC)) : The typed derivation has the following shape:

D::D′:: Γ ⊢t ψ : Πx:φ.K Γ ⊢t N : φ

Γ ⊢t ψN :K[N/x](C–EC).

By induction,F(D′):: E′ (Γ) ⊢′ E′ (ψ) : E′ (Πx:φ.K). SinceE′ (ψ) =ψ, E′ (Γ) = Γ andE′ (Πx:φ.K) ≡Πx:φ.K, we can define:

F (D)::Γ ⊢′ ψ : Πx:φ.K Γ ⊢t N : φ

Γ ⊢′ ψN :K[N/x](C–EC ).

For all other rules, the definition ofF is given by straightforward induction.

I tii ) The functionG: Deru→Dert can be defined by induction on the structure ofD ∈ Deru in asimilar way:

(I t(E)) : Then the derivation has the following shape:

D::D′:: Γ ⊢′ M : Πx:φ.ψ Γ ⊢t N : φ

Γ ⊢′ M(E′ (N)) : ψ[N/x](E).

By induction, G(D′):: Γt ⊢t Mt : ξ, whereE′ (Γt) = Γ, E′ (Mt) ≡ M andE′ (ξ) ≡ Πx:φ.ψ.This implies thatΓt = Γ andξ ≡ Πx:φ.ψ. So, we can define:

G(D)::Γ ⊢t Mt : Πx:φ.ψ Γ ⊢t N : φ

Γ ⊢t MtN :ψ[N/x](E).

28

(I t(C–EC)) : In this case, the derivation has the following shape:

D::D′:: Γ ⊢′ ψ : Πx:φ.K Γ ⊢t N : φ

Γ ⊢′ ψN :K[N/x](C–EC).

By induction,G(D′):: Γt ⊢t θ : ξ, whereE′ (Γt) = Γ, E′ (θ) ≡ ψ andE′ (ξ) ≡ Πx:φ.K. Thisimplies thatΓt = Γ, θ ≡ ψ andξ ≡ Πx:φ.ψ. So, we can define:

G(D)::Γ ⊢t ψ : Πx:φ.K Γ ⊢t N : φ

Γ ⊢t ψN :K[N/x](C–EC ).

For all other rules, the definition is straightforward.

It is easy to verify that these two functions realize an isomorphism between the corresponding systemsin the two cubes.

While the definition of the erasing functionE′ is (apparently) easy, the definition of the related cubeis rather involved, since some rules require TS-derivations, and the erasing function occurs explicitly inthe conclusion of rule (E). So, this cube does not satisfy the property of compositionality of derivations:not all subderivations of a derivationD are valid derivations in the system⊢′ . This is the price paidfor defining a cube that is isomorphic to the typed one.

5 Related work

This paper, together with [13], can be seen as the first attempt to study type assignment systems withdependent types. In fact, all systems in the dependency-free part of the cubes TAS andTAS′ havebeen extensively studied in the literature. The only type assignment system with dependent typesalready defined in the literature is the system of Dowek [10],which is based on the typed systemλP. Strictly speaking, this is not a type assignment system in the usual sense. In [10], there is noformal system to derive judgements; instead, a valid judgement of this system is defined as one of theform Γ ⊢ E(M) :B, whereΓ ⊢t M :B is a valid judgement ofλP. The type checking problem forDowek’s system was shown to be undecidable in that paper. Dowek’s system is equivalent to the systemcorresponding toλP in theTAS′-cube. We conjecture that this undecidability result is true for all oursystems with dependencies. A further step of the work done inthis paper could be made by looking fora type assignment counterpart to the Generalized Type Systems, as defined in [3, 4, 6].

References

[1] S. van Bakel, L. Liquori, S. Ronchi della Rocca, and P. Urzyczyn. Comparing Cubes. In A. Nerode and Yu.V.Matiyasevich, editors,Proceedings of LFCS ’94. Third International Symposium on Logical Foundationsof Computer Science,St. Petersburg, Russia, volume 813 ofLecture Notes in Computer Science, pages353–365. Springer-Verlag, 1994.

[2] H. Barendregt, M. Coppo, and M. Dezani-Ciancaglini. A filter lambda model and the completeness of typeassignment.Journal of Symbolic Logic, 48(4):931–940, 1983.

[3] H.P. Barendregt. Introduction to Generalised Type Systems.Journal of Functional Programming, 1(2):125–154, 1991.

[4] H.P. Barendregt. Lambda Calculi with Types. In S. Abramsky, Dov.M. Gabbay, and T.S.E. Maibaum,editors,Handbook of Logic in Computer Science, volume 2, chapter 1, pages 118–310. Clarendon Press,1992.

[5] C.B. Ben-Yelles. g-Stratification is Equivalent tof -Stratification. Zeitschr. f. Math. und Grundlagen d.Math, Bd. 27:141–150, 1981.

[6] S. Berardi. Towards a Mathematical Analysis of Type Dependence in Coquand–Huet Calculus of Construc-tions and the Other Systems in Barendregt’s Cube. Technicalreport, Department of Computer Science,CMU, and Dipartimento di Matematica, Torino, 1988.

29

[7] T. Coquand. Metamathematical Investigations of a Calculus of Constructions. In P. Odifreddi, editor,Logicand Computer Science, pages 91–122. Academic press, New York, 1991.

[8] T. Coquand and G. Huet. The Calculus of Constructions.Information and Computation, 76(2,3):95–120,1988.

[9] H.B. Curry. Functionality in Combinatory Logic. InProc. Nat. Acad. Sci. U.S.A., volume 20, pages 584–590, 1934.

[10] G. Dowek. The Undecidability of Typability in the Lambda-Pi-Calculus. In M. Bezem and J.F. Groote,editors,Proceedings of TLCA ’93. International Conference on TypedLambda Calculi and Applications,Utrecht, the Netherlands, volume 664 ofLecture Notes in Computer Science, pages 139–145. Springer-Verlag, 1993.

[11] H. Geuvers and M. Nederhof. Modular Proof of Strong Normalization for the Calculus of Constructions.Journal of Functional Programming, 1(2):155–189, 1991.

[12] H. Geuvers and B. Werner. On the Church-Rosser Propertyfor Expressive Type Systems and its Con-sequences for their Metatheoretic Study. InProceedings of the Ninth Annual IEEE Symposium on Logic inComputer Science, pages 320–329, 1994.

[13] P. Giannini, F. Honsell, and S. Ronchi della Rocca. Typeinference: some results, some problems.Funda-menta Informaticae, 19(1,2):87–126, 1993.

[14] P. Giannini and S. Ronchi della Rocca. Characterization of Typings in Polymorphic Type Discipline. InProceedings of the Third Annual IEEE Symposium on Logic in Computer Science, pages 61–70, 1988.

[15] J.Y. Girard. The System F of Variable Types, Fifteen years later. Theoretical Computer Science, 45:159–192, 1986.

[16] J.W. Klop.Combinatory Reduction Systems. PhD thesis, Department of Computer Science, RijksuniversiteitUtrecht, 1980.

[17] D. Leivant. Polymorphic Type Inference. InProceedings 10th ACM Symposium on Principles of Program-ming Languages,Austin Texas, pages 88–98, Austin Texas, 1983.

[18] R. Milner. A theory of type polymorphism in programming. Journal of Computer and System Sciences,17:348–375, 1978.

[19] Christine Paulin-Mohring. ExtractingFω ’s programs from proofs in the Calculus of Constructions. InProceedings Sixteenth Annual ACM Symposium on Principles of Programming Languages, Austin, Texas,1989. Association for Computing Machinery.

[20] J.C. Reynolds. Towards a Theory of Type Structures. In B. Robinet, editor,Proceedings of ProgrammingSymposium,Paris, France, volume 19 ofLecture Notes in Computer Science, pages 408–425. Springer-Verlag, 1974.

[21] J.P. Seldin. Progress Report on Generalised Functionality. Annals of Math. Logic, 17:29–59, 1979.

30