Equational Theories for Inductive Types Ralph Loader August 1995, revised March 1996. Abstract
This paper provides characterisations of the equational theory of the per model of a typed lambda calculus with inductive types. The characterisation may be cast as a full abstraction result; in other words we show that the equations between terms valid in this model coincides with a certain syntactically de ned equivalence relation. Along the way we give other characterisations of this equivalence; from below, from above, and from a domain model; a version of the Kreisel-LacombeShoen eld theorem allows us to transfer the result from the domain model to the per model.
0 Introduction This paper concerns a typed calculus with inductive types which correspond semantically to initial algebras of (covariant) functors; the calculus lies between Godel's T and Girard's F in proof-theoretic strength. The goal of the paper is to analyse the structure of the model of this calculus given by the category PER of partial equivalence relations over the natural numbers. We shall show that the equational theory of this model has nice syntactical characterisations, and that the model is fully abstract in the sense that equality in the model coincides with being indistinguishable with respect to certain \observable" properties of programs (formally, terms). In the case of calculi such as pcf, the observables are the termination or non-termination of programs. In our case, the calculus is strongly normalising, so that everything terminates, and termination is not suitable for distinguishing terms. Instead we take as our observable whether a term of sum type A _ B comes from the left (A) part, or from the right (B ) part, of the sum. The development of this material is in 6 sections: 1. The calculus of inductive types which this paper concerns is de ned. 2. We de ne the categorical models of the calculus. 3. The category PER is shown to be a model. 4. A \totality domain" model is given that will be used as a stepping-stone between the syntactical notions and the model PER. Merton College, Oxford OX1 4JD, ENGLAND.
[email protected]. I am indebted to my doctoral supervisor, Dr. L. Wallen, and to Dr. D. Normann, for useful advice and suggestions. The author is grateful for the nancial support of a Commonwealth Scholarship.
1
5. A term model is constructed. 6. We show that various equational theories coincide, concluding that PER is fully abstract. There is an appendix in which the category theoretic constructs needed to model the calculus are de ned and discussed. The choice of this calculus to consider was motivated by the power of the techniques available; the abstraction involved meant that rather more than T could be analysed, while the degree of abstraction was not sucient to look at F. The calculus is essentially the propositional fragment of Martin-Lof's Iterated Inductive De nitions [ML71], although the presentation is rather dierent as we wish to expedite semantical, rather than syntactical, constructions. The author considers the category PER to be an intended model of the calculus. Indeed, the calculus is meant to be (the core of) a programming language implementable on a recursive, Turing-complete, stored-program machine. Following arguments such as theorems II.5.7 and II.5.8 of [Odi89], it appears that a mathematical representation of such an implementation must have function application isomorphic to Kleene application. Since we wish to study the calculus from an extensional viewpoint, we impose on this structure extensional notions of equality. These considerations appear to x the interpretation of types up to isomorphism.1 The view taken of the r^ole of the model ToDE (and also of the term model) is that it is merely a technical construction to enable an analysis of the more important model PER. It could be argued that ToDE is a natural representation of an implementation where programs are distinct from data (in the sense that one part of the program cannot have intensional access to the structure of another part of the program|many high level computer languages present the user/programmer with an abstraction of this nature); however, to do so would seemingly require an analysis of issues such as sequentiality, beyond the scope of what is addressed here.
0.1 Notation and Conventions
We use the logical notation ^, _ and ) for the types of our -calculus. The logical entailment ` is overloaded; a sequent ? ` r : A is used both as a noun referring to a syntactical object, and as a proposition asserting that the syntactical object is derivable. In categorical models, we use the notation for the propositional connectives to also represent the corresponding categorical structure. In particular, we use ^ and _ for categorical products and sums. This may seem rather odd given the well entrenched , + notation; it is however the lesser of two evils, as we shall be in the confusing situation of considering structures that are objects of two categories with dierent structure. The notation for linear logic shall mostly follow that of the category theory, for the good reason that it is only the categories, not the logic, that are used. Speci cally, a monoidal closed category has tensor , unit I and internal hom-set (, while products and coproducts will be and +. We use the conventional ! for Girard's linear exponential, of course. In the category of sets, we use and + for product and coproduct (i.e., cartesian product and disjoint union). This ignores the question of what is the appropriate notion of extensional equality|however, this point is one addressed by this paper; the dierent sensible notions of extensional equality in fact coincide. 1
2
We shall often consider nite sets; niteness will be indicated with a subscript ` n': a n r means that a is a nite subset of the (possibly in nite) set r. P nS = f a j a n S g. Relations are identi ed with their graphs when this is convenient; we shall write either (x; y) 2 R or x R y. The image of a set under a relation is u[a] = f y j 9x 2 a : (x; y) 2 u g, and the backwards image is [b]u = f x j 9y 2 b : (x; y) 2 u g. We shall also consider an application f (r) = f [P nr]. We shall use the Kleene bracket notation feg(n) to indicate the e th recursive function applied to n. fegm is the nite fragment of the function feg that can be computed in m or fewer steps. We and Wem are the domains of feg and fegm respectively. We choose some xed recursive enumeration of structures such as nite sets and nite tuples, and, when appropriate, identify without further comment such objects with their encodings. In section 4, we will make use of recursive functionals. In fact we need that composition of r.e. relations is a recursive functional. With the usual representation of r.e. sets as the domains of partial recursive functions, and the usual notion of recursive functional, this is not the case. There are two alternatives; choose a dierent representation of r.e. sets, or allow non-sequential functionals. We take the latter option; a recursive functional for the purposes of this paper is a recursive functional in the usual sense but allowing the use of an oracle F given by: F (f ) = 0 if 9n : f (n) #, else F (f ) ". This is a minor change; F has an r.e. graph, so that the basic results about recursive functionals apply immediately to our notion of recursive functional.
1 The Calculus of Inductive Types
De nition 1.1 Fix a countably in nite set V of type variables. Given any sequence 1; : : :; n of distinct members of V , we de ne the set I1:::n of inductive types over free type variables 1; : : :; n by the following clauses:
i 2 I1:::n for 1 6 i 6 n; A 2 I~ B 2 I~ ; A 2 I~ B 2 I~ ; A ^ B 2 I~ A _ B 2 I~ E 2 I A 2 I~ ; A 2 I~ ; : E ) A 2 I~ :A 2 I~ Note that the condition E 2 I in the clause for ) ensures that all free type variables in a member of I~ only occur strictly positively, i.e., not in the left scope of any ). A system of terms for these types is given in gure 1. Although we shall deal only with terms inhabiting closed types, what follows could easily be extended to terms inhabiting open types. The type constructors ^, _ and ) have their usual meanings as product, sum and function space respectively. We motivate, informally, the operator, and its associated term constructs. Since the free variable occurs only positively in a type A[], the type will be (interpreted as) a monotone operator; Tarski's theorem suggests that in suitable models, we may take a least xed point :A[]. Then in is the inclusion of A[:A] in :A, and out gives de nitions by induction over elements of :A. 3
x1: A1; : : :; xn: An ` xi : Ai ?; x: A ` s : B ? ` f : A)B ? ` s : A ? ` (x: A) s : A ^ B ? ` f (s) : B ?`u:A^B ? ` u : A^B ?`r:A ?`s:B ? ` hr; si : A ^ B ? ` left u : A ? ` right u : B ?`r:A ?`s:B ? ` inlA_B r : A _ B ? ` inrA_B s : A _ B ? ` u : A? _ B ?; x: A ` r : C ?; y: B ` s : C ? ` case u of inl x ) r j inr y ) s : C ? ` r : A[=:A] ? ` r : :A ?; x: A[=B ] ` s : B ? ` in:A(r) : :A ? ` outB (r; x:s) : B Figure 1: Term Assignment for Inductive Types We consider an example, reasoning informally about types as sets. Let 0 = :, 1 = 0 ) 0 and Nat = :(1 _ ). 0, as the least xed point of the identity, is the empty set, so 1 is the singleton containing just the empty function on 0. Any function F : 1 _ A ) A is determined by a = F (inl ) 2 A and f = F inr : A ) A. In particular, in : (1 _ Nat) ) Nat may be decomposed into zero = in(inl()) : Nat and succ = in inr : Nat ) Nat. The terms built from succ and zero are just succn (zero), for n 2 N , and may be identi ed with the natural numbers. Further, given F : 1 _ A ) A determined by a and f as above, the object out(n; F ) should f n (a). This last fact will
be expressed by the reduction rules given later. We shall need to give constructions on terms by induction over their derivations; the next lemma provides the appropriate unique reading property to justify this. The proof, a simple induction over terms, is omitted. Lemma 1.2 A term inhabits at most one type in a given context, and derivations of a sequent are unique. The reduction rules for ^, _ and ) types are exactly the usual reductions for these types. To state the reductions for types, we need to rst turn types into functors. Since can only appear positively in a type A[ ] 2 I , given a term of type B ) C , we should be able to derive a term of type A[B ] ) A[C ]. We do this, although using terms with free variables rather than terms with function types. Given A 2 I1 :::n and ?; yi: Bi ` ti : Ci for 1 6 i 6 n, and ?; ` s : A[~ =B~ ] we de ne a term A 1=(y1)t1; : : :; n=(yn )tn (s) by the clauses in gure 2. An induction over the de nition shows that the inference (1.1) valid. ?; ` s : A[~ =B~ ] (1.1) ?; ` A[=(~y)~t ](s) : A[~ =D~ ] In lemma 2.4 we shall show that this de nition really does give functors in the appropriate categorical models. In gure 3 we give the basic reductions ?!1. -reduction is the least 4
If A is i E ) A0 A1 ^ A2 A1 _ A2 :A0
then A[~ =(~y)~t ](s) is ti[yi=s] (x: E ) A0[~ =(~y)~t ](sx)
A1[~ =(~y)~t ](left s); A2[~ =(~y)~t ](right s) case s of inl x1 ) inl A1[~ =(~y )~t ](x1) j inr x2 ) inr A2[~ =(~y)~t ](x2) ? out s; (x) in A0 [~ =(~y )~t; =(z )z ](x) Figure 2: Using Types as Functors
((x: A) s)(r) ?!1 s[x=r] lefthr; si ?!1 r righthr; si ?!1 s case inl r0 of inl x ) r j inr y ) s ?!1 r[x=r0] case inr s0 of inl x ) r j inr y ) s ?!1 s[y=s0] outB (in:A r; (x)s) ?!1 s x=A[=(u) outB (u; (x)s)](r) Figure 3: Basic Reductions for Terms partial order ?! that contains ?!1 and is compatible with the term constructs of gure 1. The next proposition, whose proof is omitted, can be shown either directly using standard techniques, or by interpreting the calculus in the polymorphic -calculus.
Proposition 1.3 -reduction is strongly normalising and Church-Rosser.
Also, note that the types-as-functors of gure 2 is well behaved under substitution:
Lemma 1.4 Suppose that A 2 I1 :::n ; and Then, the equality
holds for any u.
Bi 2 I 1 ::: m for 1 6 i 6 n;
?; xj : Cj ` tj : Dj for 1 6 j 6 m:
A i=B i ni=1 j =(xj )tj mj=1(u) = A i=(yi)Bi[ j =(xj )tj ]mj=1(yi) ni=1(u):
2 Categorical Semantics
So that we can give a reasonably uni ed treatment of the semantics of I in various models, we develop a categorical semantics; later we will construct three models by showing that they give suitable categories. In the appendix, there is a brief discussion of the categorical 5
constructs used here; for a more complete presentation of the technicalities, see e.g. [Mac70]. While the models can be readily understood without the category, a precise presentation without categorical ideas would be dicult; in particular, invariance under reduction, and the de nition of the term model, both make essential use of functors.
A type A 2 I1:::n will be represented by an n-ary functor. The connectives ^, _ and ) will be interpreted by applying the corresponding
constructs of a bicartesian closed category point-wise to functors representing types. The constructor will be interpreted as an initial algebra (see the appendix, de nition A.2). In fact, we need to give the functors interpreting types a little additional structure. In the types-as-functors translation of gure 2, a term may have addition free variables. We use the categorical notion of a strong functor (de nition A.1) to model this.
De nition 2.1 A model of inductive types consists of a bicartesian closed category C with collections Cn (n 2 N ) of strong functors from C n to C , along with an assignment of an initial algebra in Cn to each member of Cn+1 , such that the following are satis ed: 1. Each Cn contains the n projections on n parameters, and the Cn are collectively closed under composition. 2. Each Cn is closed under taking point-wise products and coproducts. 3. For each A 2 Cn and E 2 C0, the point-wise function space E ) A is a member of Cn .
The interpretation of types is straightforward to de ne: a type A 2 I1:::n will have an interpretation JAKC 2 Cn. JAKC is de ned by induction on A so that: ~ ) = Xi ; Ji K(X
A ^ B K(X~ ) = JAK(X~ ) ^ JB K(X~ ); ~ ) = JAK(X~ ) _ JB K(X~ ); JA _ B K(X
J
E ) AK(X~ ) = JE K() ) JAK(X~ );
J
and
:AK = JAK
J
where the initial algebra is taken in the argument of JAK corresponding to . This interpretation of types behaves correctly under substitutions: Lemma 2.2 If A 2 I1:::n and Bi 2 I 1::: m for 1 6 i 6 n, then2 q
y
A[1=B1; : : :; n=Bn ] = JAK JB1K; : : :; JBn K :
In general this only holds up to coherent isomorphism. However, in each of the cases considered in this paper, these isomorphisms are actually identities. 2
6
Given a derivable judgement x1: A1; : : : ; xn: An ` r : A, the interpretation JrKC is a morphism from JA1KC ^ ^ JAnKC to JAKC .3 The de nition of JrK is by induction on a derivation of the sequent4 typing r. The clauses of this induction use the categorical structure associated with the appropriate types, as follows: 1. JxiK is the i th projection i : JA1K ^ ^ JAn K ?! JAK. 2. For ?; x: A ` s : B , let J(x: A) sK be the transpose of JsK in the adjunction ?
?
^ JAK a JAK ) :
3. For ? ` f : A ) B and ? ` a : A, let Jf (a)K = ev hf; ri, where ev is the evaluation map ? ev : JAK ) JB K ^ JAK ?! JB K: 4. 5. 6. 7.
q
y
For ? ` a : A, ? ` b : B , let ha; bi = JaK; JbK . For ? ` p : A ^ B , let Jleft pK = 1 JpK and Jright pK = 2 JpK. For ? ` a : A or ? ` b : B , let Jinl aK = 1 JaK or Jinr bK = 2 JbK respectively. For ? ` c : A _ B; ?; x: A ` r : C and ?; y: B ` s : C , let Jcase
c of inl x ) r j inr y ) sK
be the composite ?
J K
hid; c i J?K ^ JA _ B K J K
?
dist
/
/
?
? ^ JB K _ J?K ^ JB K
J K
[r;s] J KJ K
/
C
where dist is the morphism giving the distributivity of products over sums in a cartesian closed category. 8. For ? ` a : A[=:A], let Jin:A aK = in JaK. 9. For ? ` a : :A and ?; x: A[=B ] ` b : B , let JoutB (a; (x)b)K be the composite ?
J K
hid; r i J?K ^ J:AK J K
/
out JbK /
B;
where outJbK is given by the fact that J:AK is a strong initial algebra of the strong functor JAK (see the appendix, lemma A.3). Just like the interpretation of types, the interpretation of terms behaves correctly under substitution: Lemma 2.3 Suppose that y1: B1; : : :; yn: Bn ` a : A and ? ` bi : Bi (for 1 6 i 6 n) are derivable. Then q y
a[y1=b1; : : :; yn =bn] = JaK Jb1K; : : : ; JbnK : 3 4
If we allowed terms with types that are not closed, then JrK would be a strong natural transformation. And thus more precisely, we de ne interpretations of derivable sequents, rather than of terms.
7
We can now show that the types-as-functors de ned in gure 2, when interpreted in a model, gives the same functor as the interpretation JK of types. We then use this fact to show that the interpretation of terms is invariant under reduction. Lemma 2.4 Take A 2 I1:::n and suppose that ?; xi: Bi ` ti : Ci is derivable for 1 6 i 6 n, so that ?; y: A[~ =B~ ] ` A[~ =(~x)~t ](y) : A[~ =C~ ] is also derivable. Then q y A[~ =(~x)~t ](y) = JAKJ~t K: Note the use of the strength of the strong functor JAK (de nition A.1) in the statement above. Proof: By induction on the type A. Each induction step follows by the uniqueness part of the appropriate universal property of the interpretation of the connective in question. We do only the induction step for the case A = :A0 and, for notation convenience, we assume that n = 1. q y We need to show that J :A0K maps JtK to A[=(x)t](y) . Writing A[] for A[=] and A0[;y ] forq A0[=;y? = ], a case of the induction hypothesisy is that the strong functor q q 0 A [ ; E ] = A0[; ] ; JE K maps JtK to A0[(y)t; (x)x](y0) for any E 2 I , where y0 is a freshqvariable ofytype A0[B; E ]. Now A[(x)t](y) is the unique morphism f making the diagram below commute, q y
q
? ^ A0[B; A[B ]]
h
i ? ^ qA0[B; A[C ]]y
y 1 ;JA0 [B; ]Kf q y /
A0[C; A[C ]]
id^in
q y
g
q
q
f
y
in
q
y
y
? ^ A[B ] A[C ] q y q y where g is A0[(y)t; A[C ]](y0) = A0[; A[C ]] JtK. But this diagram also commutes with f = JAKJtK, so that the two morphisms are equal, as required. Proposition 2.5 The valuation of a term is invariant under -reduction. Proof: For the ^, _ and ) reductions, this is standard [LS86]. For the reduction for types, suppose that ? ` r : A[=:A] and ?; x: A[=B ] ` s : B are derivable, so that ? ` out(in r; (x)s) : B is also derivable. The valuation of the term outB (in r; (x)s) is the composite from J?K to JB K along the lower left edges of the diagram (2.1). h1; A out s iJ?K ^ JAKJB K hid;ri J?K ^ JAKJ:AK J?K (2.1) s h1 ;ini
/
J K
J K
/
/
J K
out s ? ^ J:AK JB K Using the previous lemma, the valuation of s x=A[=(y) out(y; (x)s)](r) is the composite along the top right edges of (2.1). This diagram commutes, as the square is an instance of (A.2), which shows the result for reductions for types. J K
J K
/
8
3 Interpretation in PER The calculus of inductive types has a straightforward recursion theoretic interpretation. We show that the category PER of partial equivalence relations over the natural numbers is a model.
De nition 3.1 The category PER is given as follows. Objects of PER are partial equivalence (i.e., symmetric and transitive) relations on the set N of natural numbers. Given objects A and B , we de ne the partial equivalence A)B by (e1; e2)?2 A)B if and only if, for all (x1; x2) 2 A, both fe1g(x1) and fe2g(x2) are de ned, with fe1g(x1); fe2g(x2) 2 B . The hom-set PER(A; B ) is the set of equivalence classes of A ) B . Identities and composition are induced from the appropriate operations on indices of recursive functions. It is well known that PER is a bicartesian closed category. Letting h; i : N 2 ?! N be a recursive bijection, we have
?
A ^ B = ha; bi; ha0; b0i (a; a0) 2 A; (b; b0) 2 B ; while A _ B is the union
(2a; 2a0) (a; a0) 2 A [ (2b + 1; 2b0 + 1) (b; b0) 2 B :
The internal hom-set is ) as given above. The projections, injections and evaluation maps etc. are given in the obvious manner. To interpret I , we need to nd a collection of (strong) functors closed under all the type constructors. This is provided by the following de nition.
De nition 3.2 An inclusion f between two objects A, B of PER is a morphism f : A ?! B that is the equivalence class of the identity; i.e., A is contained in B , with f
the morphism witnesses this fact. The functor F is called monotone if it maps inclusions to inclusions. A functor F is called eective if its behaviour on morphisms is given by a recursive function F on indices, so that F (g) = [F(g)] : F (A) ?! F (B ) whenever g = [g] : A ?! B . Note that if F is an eective functor, then F is a strong functor, with the natural transformation F : X ) Y ?! F (X ) ) F (Y ) being the equivalence class of (an index of) the recursive function F. The eective, monotone functors are easily seen to be closed under the bicartesian closed structure of PER as given above.
Lemma 3.3 Let F : PERn+1 ?! PER be a monotone, eective functor on partial equivalence relations. Then the least xed point F on objects given by Tarski's theorem gives initial algebras, and the functor that results is monotone and eective.
With a little extra work, it can be shown that an eective functor has an initial algebra that is again an eective functor, and thus our use of monotonicity could be dropped; however, the use of monotonicity simpli es the details, by allowing us to use the Tarski theorem to de ne the initial algebra in a quite simple manner. 9
Proof: For the veri cation that the least xed point is indeed an initial algebra, we may assume that F is unary. F (F ) = F , so we let in : F (F ) ?! F be the identity. Given s = [s] : F (A) ?! A, let out s be given be the second recursion theorem so as to satisfy out s = s F(out s) : By induction over F , this gives a well-de ned morphism out s = [out s] : F ?! A that makes the universal diagram (A.1) commute, and this is the only such morphism. That F is eective can be seen using the fact that the action of F on morphisms may be de ned in terms of out, which is in turn given by the recursive function out. Monotonicity follows by an induction over F .
Proposition 3.4 The collection of eective and monotone functors on the category PER forms a model of I .
4 The Totality Domain Model In this section, we de ne a model using certain (eective) topological spaces and (eectively) continuous functions between them. The model is de ned by certain domains of sets with a \totality" structure; hence we use the name totality domain (ToD) for our model. In section 6, we will use this model as an intermediary to analyse the relation between the model PER and the syntax of I . Instead of de ning the totality domains directly, we build the model in several steps; this approach has the advantage of making the de nition of the categorical structure of the model signi cantly easier to follow. First we de ne a simple domain model of intuitionistic linear logic.5 On top of this we de ne totality structures. The co-Kleisli category of this is cartesian closed. We identify a full subcategory of the co-Kleisli category given by objects with certain nice features. On this subcategory, there is a natural equivalence relation; factoring hom-sets by this equivalence relation gives the category of totality domains. Since we shall wish to compare this category with PER, we eventually work with an eective version of this construction, showing that it gives a model of I . Nearly identical notions of totality structures, with developments of their basic properties (in particular, the crucial density property of de nition 4.8) correlating closely to this section, have appeared previously in the literature in articles by D. Normann and L. Kristiansen [Kri93], [KN92], [KN95a], [KN95b] and [Nor90]. There, type systems involving inductive types, as well as other constructs such as dependent types are considered. They present similar de nitions and properties concerning their structures, although using function spaces of stable functions, and not being specialised to the purpose we have in mind. The use of stable functions seems to make it easier to obtain cartesian closedness, but it is essential that we eventually use continuous functions. We must include|in a rather ad. hoc. manner|a space with no total objects, which again makes our treatment less smooth than that given by Kristiansen and Normann. U. Berger [Ber93] considers notions of totality in the more abstract setting of Scott domains, leading to results similar to proposition 6.8; this work appears very nearly sucient for No knowledge of linear logic itself is required|only the structures that give models of linear logic are used. 5
10
out totality domains are used for, although working with very concrete presentations seems to be an advantage for the purposes of this paper (e.g., lemma 6.5). It is notable that the works mentioned above, and the present ones, arrive at pleasantly similar notions of totality despite having dierent motivations driving their development; in particular, the duality of de nition 4.5, and the extensionality, density and separation properties of de nition 4.8 all have analogs in the mentioned work.
4.1 Set Domains
De nition 4.1 A set-domain A is a pair ?jAj; ACon where jAj is a set, and ACon PjAj satis es A1. r 2 ACon if and only if a 2 ACon for every nite a r. A2. fxg 2 ACon for each x 2 jAj. jAj is called the underlying set of A, and members of ACon are said to be consistent in A. The set domains are similar to Girard's qualitative domains [Gir86], however, in addition to not requiring that ; 2 ACon, we consider, via the translation A ) B = !A ( B , a function space of continuous, rather than stable, functions.
De nition 4.2 The multiplicative linear operators and ( on the set-domains are de ned by: jA B j = jAj jB j = jA ( B j; (A B )Con = t jAj jB j 1[t] 2 ACon; 2[t] 2 BCon ; (A ( B )Con = t jAj jB j t[r] 2 BCon 8r 2 ACon : The unit I for is given by jI j = fg. The category sD of set-domains is de ned to have set-domains as objects, the hom-set sD(A; B )is de ned (A ( B )Con, with identities and composition being the identity to be
relation (x; x) x 2 jAj , and composition of relations, respectively. The tensor is extended to a functor by setting
f f 0 = ((x; x0); (y; y0)) (x; y) 2 f; (x0; y0) 2 f 0 : It is trivial but boring to verify that and ( make sD into a symmetric monoidal closed category, so that sD is a model of MILL (see [See89] and [Bie95]). We content ourselves with proving that and ( are adjoint. S Note that if R ACon is such that ACon = r2R P r, then for any t jA? jjB j, we have t 2 (A ( B )Con i whenever r 2 R. In particular, t[r] 2 BCon ? taking u jAjjB j jC j and letting v = (x; (y; z)) ((x; y); z) 2 u , we have u 2 (A B ) (?C Con i v[r][s] = u[r s] 2 CCon for all r 2 ACon and s 2 BCon, which in turn holds i v 2 A((B (C ) Con. It follows immediately that sD(A B; C ) and sD(A; B ( C ) are isomorphic.
11
De nition 4.3 The additive operators + and (i.e., coproducts and products) are given by jA + B j = jAj + jB j; (A + B )Con = r + ; r 2 ACon [ ; + s s 2 BCon ; S (A B )Con = r + s r 2 ACon; s 2 BCon ; jA B j = (A B )Con: Their units 0 and 1 are de ned by j0j = ; = j1j and 0Con = ;, 1Con = f;g. The veri cation that these really are coproduct, product, initial object and terminal object is easy and omitted. Note that jA B j = jAj + jB j unless either ACon = ; or BCon = ;. We can also give the exponential ! on set-domains:
De nition 4.4 For a set-domain A, the set-domain !A is de ned by: j!Aj = P njAj \ ACon = f nite elements of ACong; S (!A)Con = r j!Aj r 2 ACon : Given f : A ?! B , de ne !f to be the set ? n 2 N ; fx1 : : : xn g 2 ACon; : fx1 : : : xng; fy1 : : :yng (x1; y1); : : : ; (xn; yn) 2 f Clearly !f : !A ?! !B .
To make this functor ! model the ! of ILL, we need six natural transformations satisfying certain equalities. The natural transformations are
A = (fxg; x) x 2 jAj : !A ?! A;
S
A = ( a; a) a 2 j!!Aj : !A ?! !!A;
mA;B = ((1c; 2c); c) c 2 j!(A B )j : !A !B ?! !(A B );
mI = (; fg) : I ?! !I;
eA = (;; ) ; 2 j!Aj : !A ?! I;
dA = (a1 [ a2; (a1; a2)) a1 [ a2 2 j!Aj : !A ?! !A !A: The details that these satisfy the required equations are trivial but tedious. The interested reader is referred to [Bie95] for details of what is needed.
12
4.2 Weak Totality Domains
The weak totality domains form a category built from set-domains, where objects are set-domains with a `totality' structure. Later we shall isolate amongst these the `totality domains' that satisfy certain properties we will need. The axioms for totality given here were isolated for their own sake and gave rise to the work [Loa94]. The next two paragraphs discuss informally how one can consider the (weak) totality domains. The totality domains are presentations of certain topological spaces, working from an axiomatisation of sub-bases. A totality domain A will be a set-domain with certain extra structure. The set jAj can be thought of as representing a sub-basis for a topology. A subset r of jAj represents some set in the topological space by taking the intersection of the sub-basic sets represented by the elements of r. If r is nite, then this represented set is a basic open set. The consistent sets r 2 ACon can be thought of as those sets for which there is \nearly" a point in the intersection of the represented sub-basic opens. Points of the topology are represented by certain consistent sets that represent a singleton set in the topology. Such consistent sets are called total. These are subject to a certain closure axiom, which is vital to the proof of proposition 6.8, which is the technical heart of our analysis of the model PER. This closure axiom also has a certain computational explanation, in terms of the relation between objects of a type and programs accepting objects of that type; see the introduction of [Loa94] for a discussion of this. The weak totality domains are somewhere between Kristiansen's qualitative domains with totality [Kri93] and her and Normann's coherence spaces with totality [KN95b]. ? such that De nition 4.5 A weak totality domain is a quadruple A = j A j ; A ; A ; A Con > ? ? jAj; ACon is a set-domain and: (T1) 6 ; 8r? 2 A? : A> = r+ 2 ACon r+ \ r? = (T2) 6 ; 8r+ 2 A> ; A? = r? jAj r+ \ r? = The members of A> and A? will be called total and cototal respectively.
This de nition is very close to those of D. Normann and L. Kristiansen. Their cototal objects (called chains by them) are subsets of P njAj rather than just jAj; however this dierence more or less disappears due to our eventual use of the linear exponential !. The following observation is immediate from the axioms: Lemma 4.6 If A is a weak totality domain, then A> and A? are upwards closed subsets respectively of ACon and PjAj. It is convenient to introduce a notation for the rhs of the axioms (T1) and (T2). Therefore we de ne6 R?!> = r+ 2 ACon r+ \ r? 6= ; 8r? 2 R : and
R>!? = r? jAj r+ \ r? 6= ; 8r+ 2 R
Note that these notations implicitly depend on the choice of set-domain A. However, it will always be clear when we use them which set domain is intended. 6
13
The axioms (T1) and (T2) can now be read A> = A?!> and A? = A>!? ? > . Letting >!> >!? ?!> R = (R ) , we could clearly remove A? from de nition 4.5, replacing (T1) ?!> i R? R>!? for all R> ACon and (T2) with A> = A>!> > . Also, R> R? > ?!> form a Galois connection. In particular, we and R? ?PjAj, so that ()>!? and ( ) have that jAj; ACon; R>!> ; R>!? is a weak totality domain for any set-domain A and R ACon. We extend the linear operators on set-domains to weak totality domains as follows:
(A ( B )> = r s r 2 A>; s 2 B?
(A B )> = r s r 2 A>; s 2 B>
>!>
?!>
;
?
>!>
(A + B )> = f r + ; j r 2 A> g [ f ; + s j s 2 B> g
(!A)> = P nr r 2 A>
>!>
;
; 2 1>
(A B )> = r + s r 2 A>; s 2 B> ; and
I> = fg ;
;
:
Lemma 4.7
1. If R ACon and S BCon are such that A> = R>!> and B> = S ?!> then, for u 2 (A ( B )Con, we have that u 2 (A ( B )> is equivalent to
and also equivalent to
u[r] 2 B> whenever r 2 R
(4.1)
[s]u 2 A? whenever s 2 S:
(4.2)
2. If A> = R>!> and B> = S >!> then
(A B )> = r s r 2 R; s 2 S
>!>
:
Proof: 1. Suppose that u 2 (A ( B )>. Then for any r 2 R A>, we have u[r] 2 BCon as u 2 (A ( B )Con, and for any s 2 B? , we have that u \ (r s) 6= ; and thus u[r] \ s = 2[u \ (r s)] 6= ;, which shows that (4.1) holds. Conversely, suppose that (4.1) holds for some u 2 (A ( B )Con. Given s 2 B? , for any r 2 R, we have u[r] \ s = 6 ; so that r \ [s]u =6 ;, which shows that [s]u 2 R>!? = A? . Now, for any r 2 A>, s 2 B? , we have that r \ [s]u = 6 ;, so that u \ (r s) =6 ; also. Hence u 2 (A ( B )>. The equivalence with (4.2) is similar. 2. Arguments similar to those for 1. show that for u jAjjB j, we have that u 2 (A B )? is equivalent to u[r] 2 B? for all r 2 R:
Since B? = S >!? , we have u 2 (A B )? equivalent to s \ u[r] 6= ; whenever r 2 R, s 2 S , which is in turn equivalent to (r s) \ u 6= ; for all r 2 R, s 2 S . Thus (A B )? = f r s j r 2 R; s 2 S g>!? and 2. follows.
14
We de ne the category WToD to have as objects the weak totality domains and with hom-sets WToD(A; B ) = (A ( B )>. There is the obvious faithful functor to sD that throws away the totality structure. It is easy to verify that all the categorical structure of sD in section 4.1 is inherited by WToD. As the functor from WToD to sD is faithful, it suces to verify that the functors giving this structure, and their associated natural transformations, restrict to the category WToD. For example, that WToD is closed under composition ? follows easily from lemma 4.7(1), while for the associativity of , note that by 4.7(2), (A B ) C > is
>!>
(r s) t r 2 A> ; s 2 B>; t 2 C> ? while A (B C ) > is
;
r (s t) r 2 A> ; s 2 B>; t 2 C> >!> ; which clearly give isomorphic objects of WToD. The co-Kleisli category ToD0 of ! : WToD ?! WToD has the same objects as WToD, hom-sets given by ToD0(A; B ) = WToD(!A; B ), the identity is A 2 WToD(!A; A) = ToD0 (A; A), and the composite of f 2 ToD0 (A; B ) and g 2 ToD0(B; C ) is the composite in WToD of !f g !A A !!A !B C: For any model of ILL, the ! co-Kleisli category is cartesian closed [Bie95], with product A ^ B = A B and internal hom-set A ) B = !A ( B . This category also has a weak coproduct A _ B = !A + !B . In the following we take a subcategory ToD0, and form a quotient, giving the category ToD of totality domains. /
/
4.3 Totality Domains
/
We now specialise our weak totality domains to give the totality domains. The totality domains are weak totality domains satisfying some desirable properties; several of these properties are sensible in the light of the previous subsection; a reading of the totality domains in computational terms that attempts to justify these conditions is given below. Having de ned the totality domains, we proceed to verify that they form a cartesian closed sub-category of the weak totality domains. After this, we construct sucient initial algebras, in an eective setting, to model the inductive types. De nition 4.8 Let X be a weak totality domain. A set r 2 XCon is extensional when x r [ fxg 2 XCon 2 XCon: X is extensional if every r 2 X> is extensional. X is dense if for every nite a 2 XCon there is r 2 X> with a r. X is separated if X ) 2 is dense, where 2 = 1 _ 1. X is strongly dense if A ) X is dense whenever A is separated. Note that the terminal object 1 is separated, so that strong density implies density. A totality domain is an extensional, strongly dense and separated weak totality domain. 15
These notions are virtually identical to similar de nitions made in [Kri93], [KN95b], [KN95a] and [Nor90]. The use in those works of stable function spaces seems to avoid the use of strong density. In [Ber93], similar de nitions are made, although as properties that are proved to be preserved by various constructs, rather than as axioms. He includes separation in a version of our duality (de nition 4.5) to form a single predicate. A (non-trivial) totality domain determines an information system [Sco92] and thus a Scott Tdomain; the closure for the information system is, for nite a 2 ACon, given by a = f r j a r; r is maximal total g. Without having worked through the details, it appears that, following the correspondence between information systems and Scott domains, our totality domains are very close to the total and dense subsets of Scott domains used in [Ber93]. The elements of the underlying set jAj of a totality domain A may be considered to represent `pieces of information' about the values of a datatype A represented by A; a member r of A>, or ACon, represents a set of pieces of information that are valid for a particular value, or program, respectively of the type A. In computational terms, consistency is meant to indicate that computations always exhibit well and uniquely de ned behaviour|in other words, our computations are deterministic. Since any computation can use only nitely much information about an object, a putative object gives rise to well and uniquely de ned behaviour in any context if and only if every nite fragment of that putative object does. This justi es having a set r consistent if and only if every nite a r is consistent. In this reading, extensionality states that values are somehow completely determined: given r 2 A> representing an object, the information in r should be sucient to characterise that object, so that any piece consistent with r should actually be of information true of that object. Then the set x 2 jAj r [ fxg 2 ACon is a set describing the same object that r does, and in particular should be consistent. Below it is shown that the extensionality of A is equivalent to having a well de ned notion of extensional equality on A, which is the motivation for the term `extensional'. Density shows how the notion of consistency relates to the values of a datatype: a nite set is consistent precisely when it (partially) describes some value. Allowing in nite consistent sets that do not hold for some object corresponds to the fact that our computations are nite; an in nite consistent set may not describe an object, but no nite computation will ever reveal this fact. The canonical example of this is the minimisation operation on Nat ) Bool, which clearly has no computable extension to a total functional. Density becomes the familiar topological notion, with A> dense in ACon for the Scott topology given by taking as sub-basic opens the sets in the form f r j x 2 r g for each x 2 jAj. Separation states that any two inconsistent pieces of information of type A can be found to be inconsistent by some program producing clearly distinct results; programs have access to all the information in our representations of objects. From the point of view of notions of observability (cf., full abstraction), this is saying that inconsistent pieces of information are observably distinct in a certain sense. Since we wish to model function spaces, we want a cartesian-closed category. The notion of strong density was introduced to ensure that this is indeed the case; the author does not know any particular informal justi cation of this property. We now verify that the totality domains are closed under the operations of the cartesian closed category of weak totality domains. The details are very similar to those given by Normann and Kristiansen, although this is slightly complicated for us by the 16
need to use strong density.
Lemma 4.9 A weak totality domain A is extensional if and only if the relation r1 [ r2 2 ACon is an equivalence relation on r1; r2 2 A>. This equivalence relation on A> will be written A or just . Proof: The given relation is clearly always re exive and symmetric. Suppose that A is extensional. In order to show transitivity, take r1; r2; r3 2 A> with r1 r2 r3. Then for i 2 f1; 3g and x 2 ri we have r2 [ fxg r2 [ ri 2 ACon; so that r1 [ r3 x r2 [ fxg 2 ACon 2 ACon as required. Conversely, suppose that the given relation is an equivalence. Fix r 2 A>. Take x1; : : :; xn such that r [ fxig 2 ACon for 1 6 i 6 n. Let rk = r [ fx1; : : :; xk g for 0 6 k 6 n. We show by induction on k that rk 2 ACon. r0 = r 2 A> ACon. If ri 2 ACon, then by lemma 4.6, also ri 2 A> so as both ri [ r = ri 2 ACon and r [ (r [ fxi+1g = r [ fxi+1g 2 ACon, we have ri+1 = ri [ (r [ fxi+1g) 2 ACon by our supposition. It follows that
fx1; : : :; xng rn 2 ACon:
Now x r [ fxg 2 ACon is a member of ACon as each of its nite subsets is. This shows that r is extensional. The next lemma is straightforward, and the details are left to the reader. Note that the density property is needed for parts 1 and 3.
Lemma 4.10 For any totality domains A and B : 1. Take u jA ) B j. u 2 (A ) B )Con if and only if u(r) 2 BCon whenever r 2 A> . u 2 (A ) B )> if and only if u(r) 2 B> whenever r 2 A>. 2. A ^ B and A _ B are extensional. 3. For u; v 2 (A ) B )> , we have u A)B v if and only if u(r) B v(r) whenever r 2 A>. Therefore A ) B is extensional. The totality domain 2 used in the de nition of separation has j 2j equal to a two element set, which we shall write as f1; 2g, and has 2> = f1g; f2g . Lemma 4.11 A weak totality domain A is separated if and only if: (a1; 1); (a2; 2) 2 u for some u 2 (A ) 2)> (4.3) whenever a1; a2 2 ACon are nite and such that a1 [ a2 2= ACon.
17
Proof: If a1; a2 2 n ACon but a1 [ a2 2= ACon, then (a1; 1); (a2; 2) 2 (A ) 2)Con, so
that (4.3) follows from separation. For the other direction, suppose that the given condition is satis ed, and x nite u0 2 (A ) 2)Con, say
u0 = (a1; 1); : : :; (am; 1) [ (a01; 2); : : : ; (a0n; 2) : For 1 6 i 6 m and 1 6 j 6 n, we have ai [ a0j 2= ACon as else f1; 2g u0(ai [ a0j ) 2 2Con. Therefore, by (4.3), there are uij 2 (A ) 2)> with (ai; 1); (a0j ; 2) 2 uij . Let u be the set of those: (1 [ [ n ; 1), where 1 [ [ n 2 ACon, and, for some i, (j ; 1) 2 uij whenever 1 6 j 6 n. (01 [ [ 0m; 2), where 01 [ [ 0n 2 ACon, and, there are j1; : : :; jm 2 f1; : : :; ng such that (0i; 2) 2 uiji for 1 6 i 6 m. This u is de ned so that for r 2 ACon we have 1 2 u(r) if and only if there is i 2 f1; : : :; mg such that for each j 2 f1; : : : ; ng, we have 1 2 uij (r), and 2 2 u(r) if and only if for all i 2 f1; : : : ; mg there is j 2 f1; : : : ; ng such that 2 2 uij (r). Clearly, for r 2 ACon, we cannot have 1; 2 2 u(r), and, for r 2 A>, we have exactly one of 1 2 u(r) or 2 2 u(r). Hence u 2 (A ) 2)> . Given i 2 f1; : : : ; mg, we have (ai; 1) 2 uij for all j = 1; : : : ; n, so that (ai; 1) = (ai [ [ ai; 1) 2 u. Given j 2 f1; : : :; ng, for any i = 1; : : : ; m we have (a0j ; 2) 2 uij so that (a0j ; 2) = (a0j [ [ a0j ; 2) 2 uij . Thus u0 u, so that A is separated.
Lemma 4.12 Let A and B be totality domains. Then A ) B , A ^ B and A _ B are separated and strongly dense.
Proof: We do the case of A ) B ; the others are simpler. We rst show that A ^ B is separated, using only that A and B are separated weak
totality domains. We verify the condition of the previous lemma. Suppose that a1 + b1; a2 + b2 2 (A ^ B )Con, but (a1 + b1) [ (a2 + b2) 2= (A ^ B )Con, so that either a1 [ a2 2= ACon, or b1 [ b2 2= BCon. We consider the case of a1 [ a2 2= ACon; the other is similar. Now there is u such that (a1; 1); (a2; 2) 2 u 2 (A ) 2)> , so that with
w = (a + b; c) (a; c) 2 u; b 2 n BCon 2 (A ^ B ) 2)> ; we have, as required to use lemma 4.11, (a1 + b1; 1); (a2 + b2; 2) 2 w 2 (A ^ B ) 2)> : Now, for any separated C , and totality domains A, B , we have that C ^ A is separated, so that C ) (A ) B ) = (C ^ A) ) B is dense as B is strongly dense. Therefore A ) B is strongly dense. 18
We show that A ) B is separated, using lemma 4.11 again. Take nite d; d0 2 (A ) B )Con, with d [ d0 2= (A ) B )Con, say
d = (a1; b1); : : : ; (am; bm) and d0 = (a01; b01); : : :; (a0n; b0n) : There must be I f1; : : : ; mg and J f1; : : : ; ng such that [
i2I
ai [
[
j 2J
a0j 2 ACon
but f bi j i 2 I g [ f b0j j j 2 J g 2= BCon. By the density of A, we may take r 2 A> such that [ [ ai [ a0j r: i2I
j 2J
?
?
By lemma 4.11, there is v 2 (B ) 2)> such that? f bi j i 2 I g; 1 ; f b0j j j 2 J g; 2 2 v. By the cartesian closedness of ToD0, there is w 2 (A)B ))2 > such that w(f ) = v(f (r)) for all f 2 (A ) B )>. For f 2 (A ) B )>, if d f , then 1 2 v(f ( r)) = w(f ), while 0 0 ?if d f , then 2 2 v (f (r)) = w(f ). ?Hence w [ (d; 1 ); (d ; 2) is a member of (A ) B ) ) 2 Con and, by lemma 4.6, of (A ) B ) ) 2 > . Clearly A ^ B and A _ B are extensional whenever A and B are totality domains, so that lemma 4.10(3) and lemma 4.12 show that:
Proposition 4.13 If A and B are totality domains, then so are A ) B , A ^ B and A _ B. De nition 4.14 Let ToD1 be the full sub-category of ToD0 whose objects are the totality domains. By proposition 4.13, ToD1 is in fact a sub cartesian closed category of ToD0. We de ne the category ToD to have the same objects as ToD1, but with the hom-sets factored by extensional equivalence: ToD(A; B ) = ToD1 (A; B )=A)B :
It is easy to check that composition and identities in ToD, and its cartesian closed structure, is compatible with extensional equivalence, so that the quotient ToD1 ?! ToD is cartesian closed. Also, the weak coproduct _ on ToD0 induces a weak coproduct on ToD. Using the extensionality, it is easy to verify that this weak coproduct is in fact a true coproduct on ToD.
4.4 Eective Totality Domains
Because we are going to be dealing with recursion-theoretic ideas, we need to work with an of ToD. An eective weak totality domain is given by a quadruple ? eective version jAj; ACon; A>; A? , where jAj is a recursively enumerable set, the relation a 2 ACon for nite a jAj is a recursive subset of P njAj,7 and the sets A> and A? are collections of r.e. subsets of jAj satisfying the relativisations of (T1) and (T2) to r.e. sets:
A> = r+ 2 ACon r+ is r:e:; r+ \ r? 6= ; 8r? 2 A? ; 7
In the sense that the relation has a characteristic function de ned in P njAj.
19
(T1E)
A? = r? jAj r is r:e:; r+ \ r? 6= ; 8r+ 2 A> :
(T2E)
The entire development of ToD can be carried out in the setting of eective totality domains; essentially all that is needed is the observation that the development of ToD needs only constructive, rather than classical, reasoning. We give eective versions of (strong) density and separation below, in terms of there being suitable witnesses of these properties. It is convenient if we use recursive functionals, rather than eective operations on Godel numbers, where appropriate.
De nition 4.15 A density witness for an eective weak totality domain is a partial recursive function such that for any nite a 2 ACon we have a f x j (a; x) # g 2 A> . A separation witness for an eective weak totality domain A is a density witness for A ) 2. A strong density witness for A is a recursive functional such that () is a density witness for B ) A whenever B is an eective weak totality domain with a separation witness . An eective totality domain is an extensional eective weak totality domain along with witnesses for strong density and separation. An eective version of proposition 4.13 holds, so that the bicartesian closed category ToD has an eective version ToDE, which is also bicartesian closed.
4.5 Interpretation of I in ToDE
The collection of strong endofunctors on ToDE that we use to interpret the inductive types are those satisfying the following monotonicity conditions.
De nition 4.16 Let F be an endofunctor on ToDE.
If all the eective structure of F (X ) can be given as recursive functionals8 of the eective structure of X , and the operation of F on morphisms is also given by a recursive functional, then F will be called eective. F is called monotone when it preserves the inclusion relation @ on objects de ned by A @ B if and only if: @1 jAj jB j, A> B> , and if ; 2 ACon, then ACon = BCon \ PjAj. @2 A (C ; d) B (C ; d), for any eective totality domain C and nite d 2 (C ) A)Con. @3 A(a) B (a) for any nite a 2 (A ) 2)Con. @4 If r 2 A>, s 2 B>, r B s, then s 2 A>. The slightly odd conditional in @1 is to make the initial object of ToDE also initial with respect to @; without it, the proofs of section 6 would not work.
Note that as the strong density witness is already a recursive functional, we need to consider higher type functionals. 8
20
Note that once again, eective functors are strong, since recursive functionals are suitably continuous such that the eect of F on morphisms gives a strength as a natural transformation A ) B ?! F (A) ) F (B ). Examining the proof of proposition 4.13, we see that the bicartesian closed structure of ToDE is given by eective, monotone functors. To show that this class of functors is closed under initial algebras is reasonably straightforward, except for one matter. The set of total objects will be given by a least xed point, but the axioms (T1E) and (T2E), are not necessarily preserved by taking unions of increasing chains. Taking a hint from the fact that ToD0(A; B ) = WToD(!A; B ), we actually take the least xed point of !F rather than of F . This will then enable us to use @4 to show (T1E) and (T2E). In [Kri93], a similar interpretation of type constructors including inductive types is given, into a collection of qualitative domains with totality. The treatment there is simpli ed compared to ours due to not working in an eective situation; the need to make sure a co-total object is r.e. rather complicates the argument below.
Proposition 4.17 If F is an n+1-ary eective, monotone functor on
ToDE, then F has an initial algebra F which is a n-ary eective, monotone functor on ToDE. Thus the monotone eective functionals on ToDE give a model of I .
Proof: To construct the initial algebra, we may assume that n = 0. We de ne F for
any ordinal by 1. F 0 = 0 where j0j = ; = 0>. 2. F +1 = !F (F ). 3. When is a limit ordinal, de ne
jF j =
[
=
[
)>!? . i a 2 S Note that for limit ordinals and nite a jF j we have that a 2 FCon = (F?)?!> for limit ordinals . S to show Let R = P nr r 2 . We rst show that
F? = r? jF j r? is r:e:; r+ \ r? 6= ; 8r+ 2 R :
(4.4)
Clearly R F>, from which it follows that F? is contained in the rhs of (4.4). Conversely, for an arbitrary element r? of Sthe rhs, we have that r? \ jF +1j 2 F?+1 for all < . Hence r+ \ r? 6= ; for all r+ 2 +1 = F>, so that r? 2 F?. This shows (4.4). 21
S
S
De neSjF0j = )>!> FCon > S
a 2 jF j r [ a 2= (F0)Con : , we have S r 2 (F )Con , so that r \ r? = ;, and we must have r? 2 Since r 2 FCon = F?. 0 Hence there is P nr+ 2 R such that P nr+ \ r? = ; also. SThere is < such that r+ 2 F (F )>. By r [ a 2 (F0)Con for any S the choice of r? and r+ , we S have S that a n r+, so that r [ r+ 2 (F0 )Con and thus r r [ r+ 2 F (F )Con using @4, and +1. hence r 2 FCon We will show that r 2 FS>+1. Fix any s? 2 F?+1; we wish to show that r \ s? 6= ;. Let s0? = s? [ a 2 jF j r [ a 2= F (F )Con , which is clearly r.e. Given P ns+ 2 R, one of the following two cases must hold: r+ [ s+ 2 (F0)Con. Then by @4, we have s+ 2 F (F )>, so that P ns+ \ s0? P ns+ \ s? 6= ;. r+ [ s+ 2= (F0)Con. Then = (F0)Con. Now S there is a n s + such that r+ [ a 2 a 2 P ns+ \ a 2 jF j r [ a 2= F (F )Con P ns+ \ s0?. 0 2 F , so that r \ s0 6= ;. But clearly r \ a 2 jF j S r [ a 2 = This shows that s ? ? ? \ s? 6= ;. F (F )Con = ;, so that r S This veri es that r 2 = F> for arbitrary r 2 (F>)>!> , as required to show that F> = (F?)?!> . Clearly the sequence F? is eventually constant. We de ne F to be F for large . The morphism in 2 ToDE F (F ); F is the equivalence class of the WToD-identity on !F (F ) = F . Given a morphism f 2 (F (A) ) A)> and g 2 (F ) A)> such that F (F ) F (g) F (A) /
f
in
F
g
(4.5)
A commutes in ToDE, letting g be the restriction of g to F , we have that (4.6) commutes for all . Now take g to be given as the least xed point of f F () (considered
/
F (F ) F (g ) F (A) /
in
g+1
f
(4.6)
A F +1 as a recursive functional9 on representatives of morphisms). By induction on , (4.6) commutes for any , so that taking suciently large, (4.5) commutes also. If we have two g making (4.5) commute, then using (4.6) one can show by induction that for each the restrictions of the two g are identical, which gives the uniqueness of the morphisms making (4.5) commute.
/
It is here that we need composition to be a recursive functional; see the comments at the end of the `Notation and Conventions' in the introduction. 9
22
When the functor F has additional parameters, we have to verify that the resulting functor F is monotone and eective. Monotonicity is immediate by induction on the F , and eectiveness follows by noting that the functionals associated with F are given by the least xed points of recursive functionals, and thus are themselves recursive functionals.
5 A Term Model The construction of a term model is reasonably standard, although we have to be a little more careful than say, with the simply typed -calculus, as we are dealing with a less predicative calculus. We de ne certain equivalence relations on the collections of terms at each type, and show that these give rise to a model. Thus the construction is similar to that of the model PER, but using terms instead of natural numbers.
De nition 5.1 We de ne a category T0 of partial equivalences on terms. Objects of T0 are the partial equivalences A on the closed terms of closed types A, that are compatible with -reduction (i.e., two terms are equivalent if and only if their normal forms are equivalent). Given objects A and B , de ne (A) ) (B ) to be the equivalence on type A ) B given by (f1; f2) 2 (A) ) (B ) i f1(a1) B f2(a2) whenever a1 A a2. The hom-set T0(A; B ) is the set of equivalence classes of (A) ) (B ). Identities and composition are given by the obvious (x) x and f; g 7! (x) f (g(x)). The term model T is the full sub-category of T0 containing those objects A of T such that ? (x: A) A[ ](x); (x: A) x 2 (A) ) (A): (5.1) An object A of T0 that satis es (5.1) we refer to as being associated with the type A.10 We generalise, to a type in I1:::n , the notion of being associated with a type in I ; this gives us the functors that we shall use to model the inductive types.
De nition 5.2 An n-ary functor F on T is associated with a type A 2 I1:::n if it satis es the following: If (i) 2 T are associated with Di (for 1 6 i 6 n), then F (1; : : :; n) is an object of T associated with A[1=D1; : : : ; n=Dn ]:
If fi : (i) ?! (0i) is the equivalence class of ti, for 1 6 i 6 n, then F (f1; : : : ; fn) is the equivalence class of
(y) A 1=(x1)t1(x1); : : :; n =(xn)tn(xn) (y):
In the term model of say, the simply typed -calculus, the equivalence relation on terms at each type contains , as well as , conversion. The term A[ ](r) can be thought of as an -expansion of r, which gives an explanation of the use of (5.1). 10
23
Note that the condition (5.1) means that the constant functors on T are associated with the corresponding closed types. A functor associated with a closed type is completely determined by its behaviour on objects. By lemma 1.4, the composite of functors associated with some types is associated with the type given by the appropriate substitution. The category T has a bicartesian closed structure associated with the corresponding type constructs given as follows: (p; p0 ) 2 (1) ^ (2) if and only if
p ?! ha1; a2i and p0 ?! ha01; a02i with a1 1 a01 and a2 2 a02. (s; s0) 2 (1) _ (2) if and only if either 1. s ?! inl a1 and s0 ?! inl a01 with a1 1 a01, or 2. s ?! inl a2 and s0 ?! inl a02 with a2 2 a02. () ) (0) is as given in de nition 5.1. In each case, the canonical natural transformations associated with these structures is given by the obvious constructs on terms. E.g., the projections are the equivalence classes of (p) left p and (p) right p. That these satisfy the equations required to give the appropriate categorical structure is a straightforward use of -reduction and (5.1). The details are similar to, but simpler than, the calculation in the proof of lemma 5.3 below. A functor F associated with a type A 2 I is easily seen to be strong; given objects and 0 associated with D and D0 respectively, a strength|given as a natural transformation from () ) (0) to F () ) F (0)|is the equivalence class of ?
?
u: D ) D0 y: A[=D] A =(z)u(z) (y):
By considering the action of F on (x) x, a functor F associated with a type A 2 I is monotone, in the sense that if and 0 are associated with some type and () (0 ), then F () F (0).
Lemma 5.3 If F is a functor associated with a type B 2 I1:::n , then F has an initial algebra associated with A = :B 2 I1 :::n . Proof: For ease of notation, we consider the case B 2 I; ; the general case is similar. De ne the sequence F () for an object associated with D 2 I by F 0() = ;; ? (a; a0) 2 F +1() if and only if (a0; a00) 2 F ; F () where a ?! in a0 and a0 ?! in a00, and [ F () = F ();
isSsuch that y 2 a(r), then clearly y 2 b( r) and thus y 2 JtK( r) JsK(r). Hence a JsK as required. Suppose that A is B ^ C and the conditions of 2. are satis ed. Then a is in the form (a1 + b1; L); : : : ; (am + bm; L); (a01 + b01; R); : : :; (a0n + b0n; R) :
We must have for 1 6 i 6 m and 1 6 j 6 n that either ai [ a0i 2= JAKCon or bi [ b0i 2= JB KCon. In the former case,Sthe induction hypothesis gives a term r such that x: A ` r : 2 and (ai; L); (a0j ; R) 2 JrK, so that with tij [y] = r[x= left y] we have
y: A ^ B ` tij [y] : 2 and (ai + bi; L); (a0j + b0j ; R) 2
[q
tij K:
(6.2)
In the case bi [ b0i 2= JB KCon, a term tij satisfying (6.2) is similarly constructed. Letting and be the term case of inl z1 ) j inr z2 ) R, de ne
ui = ti1 and : : : and tin: Letting or be the term case of inl z1 ) L j inr z2 ) , de ne v = u1 or : : : or um: Take r 2 JA^B K>. If r[(ai+bi) 2 JA^B KCon for some i 2 f1; : : : ; mg, then Jtij K(r) = fLg for j 2 f1; : : : ; ng, so that JuiK(r) = fLg and thus JvK = fLg. On the other hand, if r [ (a0j + b0j ) 2 JA ^ B KCon for some j , then for each i = 1; : : :; m we have Jtij K(r) = fRg so that JuiK(r) = fRg, andShence JvK(r) = fRg. It follows that a is consistent with, and therefore contained in, JvK as required. that A is B _C and the conditions of 1. are satis ed. Then a is in the form Suppose (ai; 1bi) 1 6 i 6 m [ (a0j ; 2cj ) 1 6 j 6 n . De ne
a0 = (ai; L) 1 6 i 6 m [ (a0i; R) 1 6 i 6 n ; b = (ai; y) 1 6 i 6 m; y 2 bi and
c = (a0j ; z) 1 6 j 6 n; z 2 cj : By is u such thatSa0 S the case for ^ done above, and the induction hypothesis, there S JuK. By the induction hypothesis, there are s and t such that b JsK and c JtK. S It follows easily that a JrK where r = case u of inl z1 ) s j inr z2 ) t. Using the separation axiom, and the fact that application is continuous, the following proposition is immediate from the lemma.
Proposition ?6.6 ToDE is extensional, and thus is identical to T . Given A 2 I and r1; r2 2 ToDE 1; JAK , we have r1 = r2 if and only if Jf K(r1) = Jf K(r2) for all closed terms f of type A ) 2. 29
6.3 The Theory of PER
We now proceed to analyse the model PER of the inductive types, and show that its equational theory coincides with the preceding theories. This is carried out by showing that a certain functor from ToDE to PER preserves the interpretation of the inductive types.
De nition 6.7 The functor E : ToDE ?! PER is de ned as follows: 1. For an object A 2 ToDE, let E (A) be given by m = n i Wm and Wn are equivalent members of A>. 2. If u 2 (A)B )>, then as a function from A> to B> , u gives a recursive function E (u) on r.e. indexes of members of A>. By lemma 4.10(3), this induces a well de ned map E : ToDE(A; B ) ?! PER(EA; EB ); clearly this map preserves identities and composition.
It is not hard to see that E preserves products and sums. This is more or less given by the fact that the obvious faithful functors from ToDE and PER to Set preserve products and sums. It is not so obvious that E preserves internal hom-sets. We rst show that E preserves external hom-sets. That E is faithful is immediate from its de nition; that E is full is an extension of the Kreisel-Lacombe-Shoen eld theorem [KLS59]. The proof given here uses ideas from Gandy's proof [Gan62]. In [Ber93], a proof of a similar result is given for his total subsets of domains. The generality of the results appears to be very similar despite the diering abstractions in the presentation. The use of concrete presentations of the spaces involved seems to simplify our arguments (in extremis, there is a simple, but useless, de nition of the topologies on PER); this also perhaps re ects the fact that the proof below was obtained by `reverse engineering' to see what was required of the spaces involved, whereas Berger seems to have had the goal of extending the original theorem to Scott domains in as general manner as possible.
Proposition 6.8 The functor E is eectively full|given (the recursive index of) 2 PER(EA; EB ), we can nd (recursively, an r.e. index of) some f 2 ToDE(A; B ) with Ef = .
Proof: Fix a representative of a member of PER(EA; EB ). Given r; s 2 N , we de ne (r; s), (r; s), n(r; s) and R(r; s), partial recursive functions of r and s. It is convenient to rst de ne n, and in terms of R, and then de ne the latter. We shall use members of Ws to encode nite subsets of jB j, and identify b 2 Ws with the encoded b n jB j. n(r; s), (r; s) and (r; s) are computed by searching for a member of the r.e. set Ws \ P nWfg(R(r;s)). If this search succeeds, let (r; s) be the element found, let n(r; s) be the number of steps taken to nd it, and let (r; s) be (a code of the nite set) Wrn(r;s). R(r; s) is now given, using the second recursion theorem11, as follows. In other words, R(r; s) is taken to satisfy fR(r; s)g(x) ' (R(r; s); r; s; x) for some recursive . Thus R(r; s) is used in the following speci cation, both explicitly, and implicitly through the use of n, and . 11
30
If the computation of frg(x) converges in fewer12 steps than it takes to nd some member of Ws \ P nWfg(R(r;s)), then set
fR(r; s)g(x) = frg(x): On the other hand, if some member of Ws \ P nWfg(R(r;s)) is found (so that (r; s) etc. are de ned) before the computation of frg(x) terminates, then search for some nite a and b such that (r; s) a 2 ACon, b Wfg((a)), where a W(a) 2 A> as given by the density of A, and b [ (r; s) 2= ACon. On nding such an a|which does not depend on x|put
fR(r; s)g(x) ' f(a)g(x): Claims: Suppose that r and s are such that (r; s) and (r; s) are de ned. In the computation above, 1. The search for a and b never succeeds, for any r and s. Also,
Wfg((a)) [ (r; s) 2 BCon whenever a has (r; s) a 2 ACon:
(6.3)
2. For any u such that (r; s) Wu 2 A>, we have Wfg(u) [ (r; s) 2 BCon. Note that ? if the search for a and b succeeded, then we would have WR(r;s) = W(a) 2 A> , so that fg(R(r; s)); fg((a)) 2 EB , and thus
b [ (r; s) Wfg((a)) [ Wfg(R(r;s)) 2 BCon; contradicting our choice of a and b. Thus the search fails. To show (6.3), take a such that (r; s) a 2 ACon. Then for any nite b Wfg((a)), we have b [ (r; s) 2 BCon, so that any nite subset of Wfg((a)) [ (r; s) is in BCon. Assume, contrary to claim 2, that (r; s) Wu 2 A> but
Wfg(u) [ (r; s) 2= BCon: Let v be an index of the r.e. set
(6.4)
b 2 BCon b is nite; b [ (r; s) 2= BCon :
Suppose that (u; v) etc. were unde ned. Then for any nite b Wfg(R(u;v)), we would have b 2= Wv , and thus b [ (r; s) 2 BCon: This should be taken in an algorithmic sense, rather than in the sense of an arithmetic comparison. In other words, run the two computations in parallel, and when one terminates, take the appropriate action, without waiting to see if the other computation terminates. 12
31
This would imply that Wfg(R(u;v)) [ (r; s) 2 BCon. By the supposition, we would have WR(u;v) = Wu , and thus Wfg(R(u;v)) B Wfg(u), so that by the extensionality of B ,
Wfg(u) [ (r; s) 2 BCon contradicting (6.4). Thus our supposition cannot hold, and n(u; v), (u; v) and (u; v) are de ned. Let a = (r; s) [ (u; v) u, so that a 2 n ACon. Now using (6.3) twice,
Wfg((a)) [ (u; v); Wfg((a)) [ (r; s) 2 BCon; so that, since Wfg((a)) 2 B> , and B is extensional, (u; v)[ (r; s) 2 BCon, contradicting the fact that (u; v) 2 Wv . Therefore our assumption was false, and claim 2 holds. Given any s 2 N , let P1s be an r.e. index of fyg y 2 Ws . Set f = ((r; P1s); y) r; s 2 N ; (r; P1s) #; (r; P1s) = fyg so that f is r.e. We prove the proposition by showing that f 2 (A ) B )>, and that E maps the equivalence class of f to that of . Take Wu 2 A>. By claim 2, we have Wfg(u) [ fyg 2 BCon for any y 2 f (Wu ), so that as B is extensional, f (Wu ) y Wfg(u) [ fyg 2 BCon 2 BCon: (6.5) To show that f (Wu ) 2 B>, we show that f (Wu ) \Ws = 6 ; for any Ws 2 B?. Suppose that f (Wu ) \ Ws = ;. Then in particular, (u; P1s) must be unde ned, so that WR(u;P1s) = Wu 2 A> and Wfg(R(u;P1s)) 2 B> . Hence Wfg(R(u;P1s)) \ Ws =6 ; which implies that (u; P1s) is de ned, a contradiction. Therefore f (Wu ) 2 B>. By (6.5), we have f (Wu ) Wfg(u) for any Wu 2 A>, so that by lemma 4.10, E maps f to , as required. Corollary 6.9 The functor E presents ToDE as a full sub-category of PER. Up to isomorphism, internal hom-sets are preserved by E , the isomorphism being given by the map corresponding to E of the evaluation map in the correspondence
= ToDE?E (A ) B ) ^ EA; EB = ToDE?E (A ) B ); EA ) EB : The inverse of the isomorphism is given by the map 7! f constructed in the proof above. ?
ToDE E ((A ) B ) ^ A); EB
Note that the indexes of both the isomorphism above, and its inverse, can be given recursively in recursive indexes for the density of A and of the sets jAj, ACon, jB j and BCon.
Proposition 6.10 The functor E preserves (up to isomorphism) all the categorical structure needed to model the inductive types. The models ToDE and PER have identical equational theories.
Proof: It is easy to see that, up to isomorphism, the functor E preserves products and
sums; corollary 6.9 shows that internal hom-sets are preserved. We show that E also preserves initial algebras. Let F and G be eective monotone endofunctors on ToDE and PER respectively, and let be a natural isomorphism from G E to E F . 32
Let be the unique natural transformation such that (6.6) commutes, and let ?1 be
G(G)
G( ) /
G(EF ) (F ) EF (F ) /
E in
in
G
(6.6)
EF
/
given by the second recursion theorem so as to satisfy ?1
' E in? 1 fGg( ?1) ? 1 ;
where ? 1, G and E in? 1 are r.e. indexes of the inverse of ?1(F ), of the eect of G on morphisms, and of E in : EF (F ) ?! EF , respectively. By induction, for any ordinal , this gives a well de ned and commutative diagram ?1 ?1 EF (F ) [ ] G(EF ) G[ ] G(G) /
/
O
[E in? 1 ]
?1
[ ] G: EF +1 Similar inductions show that [ ?1] : EF ?! G is inverse to . This shows that G is isomorphic to an object (in fact EF ) in the range of E . Using the uniqueness of initial algebras in the range of E , this shows that EF and G give isomorphic initial algebras. We have shown that W preserves all the categorical structure used to de ne the valuation of terms. Therefore E preserves valuations: given A 2 I , there is an isomorphism between E JAKToDE and JAKPER, and for derivable ? ` r : A, these are such that (6.7) /
E J?K =
?
J K
E JrK /
E JAK
r
=
J K
(6.7)
/
A
J K
commutes. The proposition follows since E is faithful.
Theorem 6.11 The model PER is extensional, so that its equational theory coincides with the minimum extensional and maximum consistent theories. This model is also fully abstract in the sense that given elements a1; a2 of JAKPER, we have a1 = a2 if and only if JsK a1 = JsK a2 whenever x: A ` s : 2. It is worth noting that this gives a slightly surprising result about the logical complexity of the inductive types. It can be shown that the relation (n; m) 2 JAKPER is complete for the logical complexity class one would expect by inspecting the de nition; so that, for example, JNat ) NatK is 02-complete. However, this complexity lies in the domain of JAK, not in the actual equivalences:
Corollary 6.12 The predicate (n; m) 2 JAKPER is the restriction of a co-r.e. relation of n, m and A. 33
7 Conclusion We have carried out, quite successfully, an analysis of the equational theory of the intended model (PER) of the calculus of inductive types, along the way showing that a variety of equational theories are identical, and deriving structural information about certain models. As mentioned in the introduction, these can be seen as full abstraction results for the models. However, some discussion of the relationship between the results here and the more usual full abstraction in the setting of pcf is in order. In the case of pcf, fully abstract models are quite intentional ; for example, the constant zero function (i: N ) 0 is distinguished from the function (i: N ) 0i that \just happens" to be zero everywhere. This is not the case for our calculus of inductive types; it is clear that the results of this paper show that the models are very extensional. The motivation for studying full abstraction for pcf was this very intensionality; speci cally, the problem there was to produce a good analysis of sequentiality in the setting of higher order functions. In our case the models do not carry information about the manner in which computations are carried out; presumably a notion of full-abstraction, closer to that for pcf, could be introduced by embedding our calculus in an extension which has non-normalising terms. The reader may have noted that there is an obvious model of I not mentioned so far in this article; namely the set theoretic model. We can model I by taking those functors F for which there is an ordinal such that F preserves the union of increasing sequences of sets with co nality greater than . If desired, foundational problems can be avoided by restricting to some V, with provably existing in ZF. The reason for omitting this model is that an example due to Kreisel (see the nal exercises in the appendices to [Bar81]) can be used to show that the equational theory of Set is dierent from that of PER. The author does not feel too bad about this discrepancy; rather than detracting from our results, this is another example of how classical sets give bad models of -calculi. Presumably our results could be stated in terms of some universe of constructive sets, cf., [Rey84] and [Pit87]. Given the modern history of typed -calculi, the choice of calculus considered needs some comment; typical sensibilities about what calculi to study seem to be to consider at least system F if one is going to consider something strictly stronger than Godel's T. The author is not immune to such prejudices, however, the techniques of this paper seem not to extend readily to F, a point also raised in [Kri93] and [Ber93]. The constructions of this paper are x-point of this, and xed point of that, ad nauseum, and in more than one crucial place, proofs work because we can approach an arbitrary element `from below' using an induction. Extending these results very far seems quite dicult; for example, so far as I know, no topological model in which terms are dense has been given for system F. Only further work will reveal whether or not our results are extendible to such settings.
References [Bie95] G. Bierman. What is a Categorical Model of Intuitionistic Linear Logic? In M. Dezani-Ciancaglini and G. Plotkin, editors, Typed Lambda Calculi and Applications. Lecture Notes in Computer Science 902. Springer, 1995. [Bar81] H. Barendregt. The Lambda Calculus: Its Syntax and Semantics. NorthHolland, 1981. 34
[Ber93] U. Berger. Total Sets and Objects in Domain Theory. Annals of Pure and Applied Logic, volume 60, number 2. North-Holland, 1993. [Gan62] R. Gandy. Eective Operations and Recursive Functionals. Abstract. Journal of Symbolic Logic, volume 27. Association of Symbolic Logic, 1962. [Gir86] J.-Y. Girard. The System F of Variable Types, Fifteen Years Later. Theoretical Computer Science 45. North-Holland, 1986. [LS86] J. Lambek and P. J. Scott. Introduction to Higher Order Categorical Logic. Cambridge University Press, 1986. [Loa94] R. Loader. Linear Logic, Totality and Full Completeness. In Proceedings of the Ninth Annual Symposium on Logic in Computer Science. IEEE, 1994. [KLS59] G. Kreisel, D. Lacombe and J. R. Shoen eld. Partial Recursive Functionals and Eective Operations. In A. Heyting, editor, Constructivity in Mathematics : proceedings of the colloquium held at Amsterdam, 1957. North-Holland, 1959. [Kri93] L. Kristiansen. Totality in Qualitative Domains. Ph.D. thesis. University of Oslo, 1993. [KN92] L. Kristiansen and D. Normann. Interpreting higher computations as types with totality. Technical report, Institute of Mathematics, University of Oslo, 1992. [KN95a] L. Kristiansen and D. Normann. Semantics for some constructors of type theory. In Behara, Fritsch and Lintz, editors, Symposia Gaussiana Conf. A, Walter deGruyter & co., 1995. [KN95b] L. Kristiansen and D. Normann. Total objects in inductively de ned types. Oslo Preprint Series in Mathematics number 4. University of Oslo, 1995. [Mac70] S. Mac Lane. Categories for the Working Mathematician. Graduate Texts in Mathematics 5. Springer-Verlag, 1970. [ML71] P. Martin-Lof. Iterated Inductive De nitions. In J. Fenstad, editor, Proceedings of the Second Scandinavian Logic Symposium. North-Holland, 1971. [Nor90] D. Normann. Formalizing the notion of total information. P. Petkov, editor, Mathematical Logic. Plenum Press, 1990. [Odi89] P. Odifreddi. Classical Recursion Theory. Studies in Logic and the Foundations of Mathematics, volume 125. North-Holland, 1989. [Pit87] A. Pitts. Polymorphism is Set Theoretic, Constructively. In D. Pitt et al, editors, Category Theory and Computer Science. Lecture Notes in Computer Science 283. Springer, 1987. [Sco92] D. S. Scott. Domains for Denotational Semantics. In M. Nielson and E. M. Schmidt, editors, International Colloquium on Automata, Languages and Programs. Lecture Notes in Computer Science 140. Springer, 1982. 35
[See89] R. Seely. Linear logic, -autonomous categories and cofree coalgebras. In J. W. Gray and A. Scedrov, editors, Categories in Computer Science and Logic, Contemporary Mathematics 92. American Mathematical Society, 1989. [Rey84] J. Reynolds. Polymorphism is not set-theoretic. In G. Kahn et al, editors, Semantics of Data Types. Lecture Notes in Computer Science 173. Springer, 1984.
A Appendix We give the categorical constructs required to model the inductive types; bicartesian categories are merely de ned, while strong functors and initial algebras are developed in more detail. Additional category theoretic material can be found in [Mac70], while categorical models of -calculi can be found in [LS86]. The constructs used to model the inductive types follow quite closely the syntax of the language. Types (and contexts) are represented by objects, and a term of type A in context ? by a morphism from ? to A. Products should have the following property: that pairing and the projections give a bijection between terms of type A ^ B (in context ?) and pairs consisting of a term of type A and a term of type B (in context ?). This suggests that we have a bijection between hom(?; A) hom(?; B ) and hom(?; A ^ B ). So that the pairing and projections commute with substitution, we require that this bijection be natural in ?. This gives us a categorical product. The nullary version of this construction gives a terminal object 1 with hom(?; 1) a singleton for all ?. The eliminator case : : : for _ allows us to construct a term of type C in context A _ B given terms of type C in contexts A and B . Conversely, substituting the injections gives terms of type C in contexts A and B from a term of type C in context A_B . Making these inverse give a bijection between hom(A _ B; C ) and hom(A; C ) hom(B; C ). Requiring that this be natural in C makes these operations commute with being substituted, and gives us a coproduct. The nullary version of this is an initial object 0 with hom(0; C ) a singleton for all C . The operation of lambda abstraction takes a term of type B in context ?; A and gives a term of type A ) B in context ?. Conversely, applying a function to a variable takes a term of type A ) B in context ? and gives a term of type B in context ?; A. Making these inverse, and natural in ?, gives us an internal hom-set.13 A category is called cartesian when it has products and a terminal object, and bicartesian when it is cartesian and has also coproducts and initial object. If a (bi)cartesian category has internal-homs, then it is called (bi)cartesian closed. Following gure 2 and (1.1), a type A 2 I with a free type variable acts as a functor on terms. This construction is valid when the terms concerned contain additional free variables; for this reason we need to consider functors that are strong in the sense given below.
De nition A.1 A strong functor (on a category C with nite products), is a functor F along with a transformation F : C (Y ^ X1; X2) ?! C (Y ^ F (X1); F (X2), natural in Y , The terminology exponential is perhaps more common, but would con ict with our usage of the linear exponential !. 13
36
X1 and X2, that preserves composition and identities in the sense that the diagram Y ^ F (X ) @ 1
F (f2 h1 ;fi i)
@@ @@ @@ @@ 1 ;F (f1 ) @@@ @
h
i
/
F (X3)
~~ ~~ ~ ~~ ~~ F (f2 ) ~ ~ ~~ ?
Y ^ F (X2)
commutes for any f1 : Y ^ X1 ?! X2 and f2 : Y ^ X2 ?! X3 , and that the two natural transformations below are equal.
Y ^ FX
F (2 ) 2
/
/
FX
The natural transformation F is called a strength of the functor F . Note that a strength is equivalent to lifting F to the co-Kleisli category of Y ^ () in a manner natural in Y . The naturality of F states that whenever the left diagram below commutes, then so does the right diagram.
Y ^ X1
f /
O
g^f1
Y 0 ^ X10
f0
Y ^ FX1
X2 f2
g^Ff1
Y 0 ^ FX10
X20
/
F f /
O
F f 0
FX2 Ff2
/
FX20
By considering the case when g : 1 ?! Y and f1 = id : X1 ?! X1, we see that if C is well-pointed|as are the three models considered in this article|then any functor has at most one strength. If C is cartesian closed, then there are equivalences
C ( ^ X; Y ) ?! C ( ^ FX; FY ) C (; X ) Y ) ?! C (; FX ) FY ) C (X ) Y; FX ) FY ); with the rst being given by the adjunction between ^ and ), and the second by the
Yoneda lemma. Thus having a strength for a functor F is equivalent to having a natural transformation from X ) Y to F (X ) ) F (Y ) preserving composition and identity appropriately|in other words, the action of F on morphisms is given on internal, as well as external, hom-sets. The product functor is always strong, while a coproduct functor is strong when products distribute over coproducts; in particular, sums in a bicartesian closed category are strong. The categorical notion corresponding to the least xed point type constructor is that of an initial algebra. An initial algebra has two categorical constructs associated with it: in corresponding to x: F (F ) ` in x : F and, when y: F (B ) ` g : B , out g corresponds to x: F ` out(x; g) : B . The uniqueness property of out follows from the fact that a recursion should de ne a unique object. 37
De nition A.2 An initial algebra for an endofunctor F is an object F with a morphism in F (F ) ?! F , such that for any object X and s : F (X ) ?! X there is a unique morphism out s such that (A.1) commutes.
F (F ) F (out s) F (X ) /
(A.1)
s
in
F out s X If F is a strong functor, then F is a strong initial algebra if, for any s : Y ^ F (X ) ?! X , there is a unique out s : Y ^ F ?! X making (A.2) commute. This is equivalent to
/
h1;F (out s)i Y ^ F (X )
Y ^ F (F )
/
(A.2)
s
Y ^in
out s Y ^ F X in : F (F ) ?! F giving an initial algebra in the co-Kleisli category of Y ^ (). If F is an n+1-ary (strong) functor, such that X 7! F (X1; : : : ; Xn; X ) has a (strong) initial algebra F (X1; : : :; Xn ) for any X1 ; : : :; Xn , then F extends to a (strong) functor, such that in is a natural transformation, in a unique manner. Indeed the diagram
/
F (f~;g)
~ F (X~ )) F (X;
/
F (Y~ ; F (Y~ ))
in
in
(A.3)
g F (X~ ) F (Y~ ) commutes if and only if the diagram (A.4) also commutes. Thus there is a unique
/
~ F (Y~ )) ~ F (X~ )) F (i~d;g) F (X; F (X; /
F (f~;id)
F (Y~ ; F (Y~ ))
in
in
g
(A.4)
F (X~ ) F (Y~ ) g = F (f~) making (A.3) commute. The functoriality of F follows immediately from the uniqueness property. Lifting this to the co-Kleisli categories of the product functors, we have that strong initial algebras of n+1-ary strong functors are n-ary strong functors. If F has an initial algebra in : F (F ) ?! F , then letting in?1 be the unique morphism making the left square of the diagram below commute, we see that the outside
/
F (g)
F (F ) F (in?1) F (F (F )) F (in) F (F ) *
/
/
F (in)
in
F
in?1
F (F ) #
/
g
38
in in
F
/
5
of the diagram commutes both with g = in in?1 or with g = id, so that in in?1 = id. Then the diagonal of the left square is F (in) F (in?1) = F (in in?1) = id, so that in?1 in = id also. Thus in is an isomorphism. The following lemma is used in the de nition of the interpretation of terms of inductive types in models. It probably follows from some general property about adjoints and cartesian closed categories, but a direct diagram chasing argument is not dicult.
Lemma A.3 Suppose that F is a strong endofunctor on a cartesian closed closed category C , with an initial algebra. This initial algebra is strong. Proof: Fix a morphism s : B ^ F (A) ?! A. We de ne s^ : F (B ) A) ?! B ) A to be the transpose of the composite
B ^ F (B ) A) Now note that
h1 ;F(ev)i B ^ F (A)
s
/
F (F )
F (g) /
s^
g
F
A:
F (B ) A)
in
/
B)A
/
commutes if and only if the diagram
B ^ F (F )
B ^F (g) /
B ^ F (B ) A)
h1;F(ev)i B ^ F (A) /
s
B ^in
B ^ F
ev(B ^g)
?
A
/
?
commutes also. The naturality of F gives F ev (B ^ g) = F(ev) B ^ F (g) , which is the second component of the composite of the top edge of the diagram above. It follows that setting out s = ev (B ^ out s^), we make F a strong initial algebra for F .
39