What is a Universal Higher-Order Programming Language

14

Transcript of What is a Universal Higher-Order Programming Language

What is a Universal Higher-OrderProgramming Language?Ramarao Kanneganti and Robert Cartwright ?Department of Computer ScienceRice UniversityHouston, TX 77251-1892Abstract. In this paper, we develop a theory of higher-order com-putability suitable for comparing the expressiveness of sequential, deter-ministic programming languages. The theory is based on the constructionof a new universal domain T and corresponding universal language KL.The domain T is universal for observably sequential domains; KL can de-�ne all the computable elements ofT, including the elements correspond-ing to computable observably sequential functions. In addition, domainembeddings in T preserve the maximality of �nite elements|preservingthe termination behavior of programs over the embedded domains.1 Background and MotivationClassic recursion theory [7, 13, 18] asserts that all conventional programminglanguages are equally expressive because they can de�ne all partial recursivefunctions over the natural numbers. This statement, however, is misleading be-cause real programming languages support and enforce a more abstract view ofdata than bitstrings. In particular, most real programming languages supportsome form of higher-order data such as potentially in�nite streams (input andoutput), lazy trees, and functions. In contrast to conventional data objects likenumbers, characters, arrays, and lists, higher-order data objects do not have �-nite canonical representations. As a result, computations involving higher-orderobjects cannot be modeled as ordinary computations over the natural numbers.The integrity of higher-order data abstractions critically depends on the fact thatprograms obey constraints on how higher-order representations are manipulated.Since classic recursion theory ignores these constraints, it does not address theexpressiveness of languages that manipulate higher-order data.To assess the expressiveness of real languages, we need to develop a theory ofcomputability that includes higher-order data. To be comprehensive, this theorymust accommodate all of the data objects that occur in conventional languages,including ordinary �nite data objects and higher-order data objects such aslazy trees and functions. In this paper, we present a theory of higher-ordercomputability suitable for sequential, deterministic programming languages. Thetheory is based on the construction of a new universal domain T suitable for? This research was partially supported by the National Science Foundation under thegrant CCR-9122518.

embedding all \sequential"2 domains. Roughly speaking, a Scott-domain (seeSect. 4) is \sequential" if its elements can be represented as lazy trees. The\sequential" domains correspond to \�liform concrete data structures" studiedby Curien [9], which are a restriction of \concrete domains" originally introducedby Kahn and Plotkin [11].We show that the new universal domain T has two important properties:1. Every \sequential" domain D can be embedded by a \sequential" retrac-tion as a subdomain D0 of T such that the maximality of �nite elements ispreserved.2. There is a simple metalanguage called KL that is universal for T: everycomputable element of T and every computable \sequential" operation onT can be expressed in KL.This two properties imply that KL is a universal \sequential" higher-orderprogramming language. Every computable \sequential" function f over a \se-quential" domainD can be de�ned inKL by �rst embeddingD inT. In addition,the termination behavior of f is preserved inT because embeddings inT preservethe �nite maximality of elements. Finite maximal elements are the denotationsof terminating computations.2 Previous Work On Universal LanguagesThe issue of higher-order computation has previously been studied in two con-texts: (i) the extension of classic recursion theory to computable functionals [10,14] and (ii) domain theory [15, 17], the mathematical framework underlyingdenotational semantics. In the classic theory of computable functionals, func-tions are represented intensionally as strings of symbols. Since programs caninspect the representations of higher order data objects, this model of higherorder computation does not capture the linguistic restrictions imposed by realprogramming languages.Scott and Plotkin developed domain theory to address this issue. In domaintheory, denotational de�nitions for programming languages are written in a met-alanguage LAMBDA corresponding to a universal domain U (either P! [17] orT! [15]). In essence, a denotational de�nition of a programming language is afunctional program written in LAMBDA that maps source program phrases intotheir meanings, which are data objects in the universal domain. The languageLAMBDA appears to be a promising candidate for a universal, higher-orderprogramming language for higher-order computation. Unfortunately, the modelof computation underlying LAMBDA is too abstract to simulate the behavior2 The quotation marks indicate that we are using this term informally. Our usagedoes not exactly match the technical meaning of the term sequential in the liter-ature [11]. Sequential functions do not provide a satisfactory basis for de�ning auniversal language because the sequential functions and corresponding domains donot form a cartesian closed category [1]. Sequential algorithms do form a cartesianclosed category but they are intensional.

of real programs faithfully. In particular, LAMBDA eliminates the distinctionbetween terminating and non-terminating computations: the evaluation of anexpression M in LAMBDA simply enumerates all �nite approximations to thedata object d denoted byM . This enumeration process cannot terminate becauseno approximation in U is maximal.Cartwright and Demers [3] have developed a new formulation of domain the-ory that addresses the issue of program termination. They constructed a newuniversal domain r (pronounced \Grad") and metalanguage Cons that distin-guish terminating and non-terminating computations. In contrast to previousuniversal domains, r includes �nite maximal elements. Any Scott-domain (seeSect. 5.2) that is e�ectively presented can be e�ectively embedded inside r suchthat the �niteness and maximality of elements are preserved. The evaluation ofan expression M in Cons terminates i� M denotes a �nite maximal element ofr. However, their theory has two liabilities. First, the syntax of the universallanguageCons is not recursive; a programmermust prove that a programwrittenin Cons is well-formed. Second, the continuous function space construction doesnot preserve maximality information. Given e�ective presentations of the do-mains A and B, it is impossible in general to construct an e�ective presentationfor the domain A!c B (the continuous functions from A to B).3 Continuous Functions Are Too GeneralWe can trace the liabilities ofr directly to two properties of the continuous func-tion space construction. First, the continuous function space constructor !c iscontravariant in its �rst argument. As a result, the maximality information fora constructed space A !c B cannot in general be computed from the maxi-mality information and e�ective presentations [15, 17] of A and B. Second, the!c constructor introduces in�nitely descending chains of elements in domainconstructions. Both of these properties make it di�cult to construct a univer-sal domain and programming language based on continuous functions. In theabsence of maximality information for a domain D, we cannot preserve the ter-mination behavior of programs over D when D is embedded in the universal do-main. The presence of in�nite descending chains prevents e�ective presentationsfrom enumerating �nite elements in topologically sorted order, complicating thetask of embedding domains in a universal domain. In addition, it is di�cult todevise metalanguages for the domains with in�nite descending chains becausecomputations climb the approximation ordering, but the inductive de�nition ofthe �nite elements does not.We can avoid the pathologies caused by the contravariance of the contin-uous function space construction by using a more restrictive formulation offunctions than the continuous functions. We recently developed a subspace ofthe continuous functions called the observably sequential functions that encom-passes all of the functions de�nable in practical deterministic programming lan-guages [5, 6, 12]. The observably sequential functions exclude continuous func-

tions that cannot be evaluated without multiple threads of control. In practice,non-sequential functions are unimportant in deterministic computation. We arenot aware of any practical deterministic language that can de�ne non-sequentialfunctions like por, the \parallel-or" function.3 Even pedagogic functional lan-guages like Miranda and Haskell do not support this class of functions becauseit would encourage insidiously ine�cient programming.The rest of the paper is organized as follows. In Sect. 4, we introduce the classof domains, called OS -domains, suitable for sequential computation. In Sect. 5,we present a domainT that is universal for OS -domains. We show how to embedany OS -domain in T while preserving the maximality of �nite elements. We alsopresent a language KL for de�ning operations on the domain T. In Sect. 6, weprove that KL is universal by showing that every computable element of thedomain T is expressible in KL.4 OS -DomainsIn this section, we de�ne the class of observably sequential domains (OS -domains);the construction is spelled out in greater detail in a previous report [12]. Thesedomains have the structure required to support observably sequential computa-tion.A Scott-domain (D;v) is the ideal completion of a Scott-basis (E;�), whichis a partial order closed under least upper bounds for �nite bounded subsets. The�nite elements of the domain are the principal ideals generated by the elementsof the Scott-basis E. As is customary, we will identify all Scott-domains thatare order-isomorphic, eliminating the distinction between a Scott-basis and thecorresponding �nite elements.OS -domains are Scott-domains with special structure: they can be generatedfrom a subset of �nite elements called the prime basis. The topological constraintsgoverning OS -domains are formulated as constraints on the prime basis. Thesenotions are formally de�ned as follows.Notation: In a partial order hS;vi, if a v b, we say that a approximatesb. An element a precedes b, written as a � b, if a @ b and there are no elementsbetween a and b in the partial order.De�nition 4.1. (Prime Basis) A triple (P;�; C) is a prime basis i�[PO] (P;�) is a countable partial order.[UP] Each element of the partial order (P;�) has at most one predecessor.[F] each element of P is approximated by only a �nite number of elements.[C] C = fQ1; Q2; : : :g is a partitioning of P into non-empty con ict sets (orC-sets) Q1; Q2; : : : such that p; q 2 Qi implies that p and q have the sameset of predecessors.3 por(x, true) = true; por(true, y)= true; and por(false, false) = false.

A prime basis (P;�; C) is error-rich i� each C-set Q 2 C has two designatedelements errorQ1 , errorQ2 that are maximal in (P;�). In addition, every C-set Qmust contain at least one element other than errorQ1 , errorQ2 .An OS -domain is the \prime-closure" of an error-rich prime basis.De�nition 4.2. (Prime-Domain, OS-domain) A prime-domain is a partialorder (D;v) generated from a prime basis (P;�; C) where1. the elements of D are downward-closed subsets of P that do not containcon icting primes (distinct primes from the same C-set).2. the relation v is the subset ordering � on D.The domain generated by the prime basis (P;�; C) is denoted D(P;�; C). Ifthe prime basis (P;�; C) is error-rich, then the prime-domain D(P;�; C) is anOS -domain.Most domains used for the models of deterministic languages are prime-domains. The most notable exceptions are the domains generated by the contin-uous function construction. Consider the following simple examples.1. The at domain B? of truth values ftt;�g is a prime-domain.2. The at domain N? of natural numbers is a prime-domain; every number isa prime element.3. The continuous function space B? !c B? is not a prime-domain; the primefunctions (the \one-step" functions) cannot be partitioned into C-sets.5 A Universal Sequential DomainTo perform arbitrary sequential computations, we need to construct a universaldomain U in which any OS -domain can be embedded. Thus, we can reducesequential computation over an arbitrary domain D to sequential computationover U by embedding D in U .Our universal domain T is a domain of lazy binary trees over the naturalnumbers and error elements. The domain T is de�ned by its prime basis asfollows.De�nition 5.1. (Universal Domain T) The universal domain T is D(P;�; C)where hP;�; Ci is de�ned as the following:1. The set of primes P is given by the inductive de�nition:P = error1 j error2 j n 2 N j h?;?i j h?; pi j hp;?i p 2 P2. The ordering relation � on P is de�ned by the rules:x � x for x 2 N [ ferror1; error2gha; bi � hc; di i� [(a = ?) _ (a � c)] and [(b = ?) _ (b � d)]

3. The con ict sets (C-sets) are de�ned by the equivalence closure of the rela-tion C 0 over P : (0; errori); (0; h?;?i) 2 C 0(0; n) 2 C 0 for n 2 N(ha;?i; hb;?i); (h?; ai; h?; bi) 2 C 0 for (a; b) 2 C 0Every tree in the domain T corresponds to a distinct set of prime approxi-mations. Each prime approximating the tree t identi�es the value of a node in t.If two trees are inconsistent, there is a node where the trees have di�erent valuesother than ?.Each C-set in the domain T identi�es a position in the tree; the elements ofthe C-set specify di�erent values for the node identi�ed by the C-set. Hence twotrees are inconsistent i� they are approximated by two di�erent prime elementsfrom the same C-set. We refer to C-sets by capital letters such as Q;R and S.A position Q in a tree is open i� the tree has ? at that position. We say that atree A is strictly below a tree B at position Q, written A �Q B, i� the tree Ahas a ? and B has a node value other than ? at position Q. Similarly, we saythat a tree a precedes Q, written a � Q, i� a is is open at the position Q andin all the positions less than Q, a is de�ned, i.e., it has non-? values at thosepositions.The universal OS -domain has the property that any OS -domain D canbe embedded in T. Moreover, there is an observably sequential function (OS -function) �D over T such that �D(T) = D0 where D0 is isomorphic to D. Toformulate the class of embeddings we must rigorously de�ne the OS -functions.5.1 OS -Function Space ConstructionThe observably sequential functions from T into T are a subset of continuousfunctions, T !c T. These functions propagate any error element that they en-counter during the evaluation of the input. More precisely, if a function encoun-ters an error element errori in its input while it is computing the node value for aposition Q, it must output the value errori at position Q of the output element.We formally de�ne this class of functions in the following de�nitions.De�nition 5.2. (Sequentiality Index) For a continuous function f : T! T, anopen position R in a is a sequentiality index for the input a and an open positionQ in f(a), i� for any x � a such that f(x) �Q f(a), x �R a.If R is a sequentiality index at an input a and an output position Q, thenthe function f explores the input at position R to generate an output at theposition Q. If the function f propagates errors, then it must generate the valueerrori at position Q if it encounters the value errori at R. A function f withsuch a behavior has a sequential strategy to evaluate its arguments. Moreover,the behavior of f over error elements determines that evaluation strategy. Sincethis information is a part of the graph of f , f is called an observably sequentialfunction (OS -function).

De�nition 5.3. (Observably Sequential Function) A continuous function f :T!c T is observably sequential if it is:sequential: for every pair (a;Q) where Q is an open position in f(a) and Q isde�ned in f(x) for some x � a, f has a sequentiality index; anderror-sensitive: if R is the sequentiality index of f for the input a and theoutput position Q, errorQ1 2 (f(a [ ferrorR1 g)) and errorQ2 2 f(a [ ferrorR2 g).Every OS -function has a unique evaluation strategy manifest in its graph [5].If an OS -function f has two sequentiality indices R;R0 for input a and openposition Q in f(a), it is easy to show that f is not continuous.4 Since the se-quentiality indices for an OS -function f are unique, it makes sense to introducea function sif , where sif (a;Q) is the sequentiality index of f for input a andoutput position Q .The function space T!os T is an OS -domain. Its prime basis (P!;�!; C!)can be described as follows:P!: The members of P can be divided into two disjoint subsets:(a) Output Primes: An OS -function f in T !os T is an output primei� there exists a �nite element a and a prime element p in T such thatf is a minimal function satisfying the constraint f(a) = p and for alla0 � a; f(a0) � f(a). The function f has a C-set label ha;Q; F 0i whereQ is the position of p and F 0 = fg 2 T!os T j g � fg.(b) Schedule Primes: an OS -function f in T !os T is a schedule primei� there exists a �nite element a and C-sets R;Q in T where a � R suchthat f is a minimal function with the property f(a t errorRi ) = errorQiand f(a) � errorQ1 . The function f has the C-set label ha;Q; F 0i whereF 0 = fg 2 T!os T j g � fg.�!: The prime functions are ordered under usual pointwise ordering, i.e., f � gi� 8x 2 T : f(x) � g(x).C!: The partitioning of P! determined by the equivalence relation � on P!where p � q , the C-set label of p = the C-set label of q:It is easy to verify that (P!;�!; C!) forms a prime basis. The two desig-nated error elements of a C-set with label ha;Q; F 0i are F 0 [ f(a; errorQ1 )g andF 0 [ f(a; errorQ2 )g. We also need to verify that D(P!;�!; C!) is isomorphic tothe domain T!os T. The proof breaks down into two parts. First, we can provethat any function in the domain D(P!;�!; C!) is an OS -function. Second, wecan prove that any �nite function in T !os T is the least upper bound of itsprime approximations in P!. Together, these two facts imply that (P!;�!; C!)generates the OS -function domain T!os T.4 Otherwise, on the input extending a with error1 at R and error2 at R0 the functionhas to generate the least upper bound of two inconsistent elements, error1 and error2,at position Q [6].

5.2 Embeddings that Preserve MaximalityThe universal domain T is universal for the class of OS -domains. That is, anyOS -domain can be embedded inT by anOS -function such that the maximality ofthe �nite elements is preserved. In addition, any prime-domain can be embeddedin T by enriching it with su�cient number of error elements. Since T !os T isan OS -domain, it can be embedded in T by an OS -function. This embeddingallows functions to be represented as trees.A computation in a domain D is an enumeration producing �nite approxi-mations to the answer with progressively higher accuracy. A computation ter-minates if and only if the answer is �nite maximal element. To preserve thebehavior of computations over D, an embedding of D in T must map the �niteelements in terminating computations to �nite elements of T and their answersto �nite maximal elements of T.To satisfy this property, embeddings must preserve more structure than theembeddings used in classical domain theory [15, 17] which do not preserve �nitemaximality. To describe the embedding process and make it e�ective, we needto de�ne what we mean by an e�ective presentation of a domain. Since ourdomains are constructed from prime elements and our embedding must preserve�nite maximality, our de�nition di�ers from others in the literature:De�nition 5.4. (E�ective Presentation) An e�ective presentation P of thedomain D(P;�; C) is a tuple hE; c;pr; arity; sizei such that:1. E : P ! N is an injective function that enumerates the prime elementsof the domain excluding errors in topologically sorted order. That is, if anelement a approximates b, a is enumerated before b. The error elements arenot enumerated because their presence is implied by the fact that D(P;�; C)is an OS -domain. We use the notation pi for q when E(q) = i.2. c : range(E)! N is a function that maps the index of the prime element toits C-set code. That is, 8i; j > 0 : c(i) = c(j) i� pi; pj 2 Q for Q 2 C. Therange of the function c is the set of C-set numbers.3. pr is a recursive function over N de�ned by pr(i) = j i� pi � pj.4. arity is a recursive function that maps the index of a prime element to thenumber in N [ f!g of C-sets above that element;5 and5. size is a recursive function that maps the index of a C-set to its cardinalityin N [ f!g.All at domains such as numbers, booleans, and non-lazy lists obviouslyhave e�ective presentations. Moreover the domain constructions like cartesianproducts, disjoint unions, lifting,OS -function construction preserve the e�ectivepresentation. As a result, all the domains typically encountered in deterministicsequential computation can e�ectively be embedded in T while preserving themaximality of �nite elements.5 A prime element may have ! C-sets above it.

In particular, the OS -function construction preserves maximality informa-tion. If two domains D and E have e�ective presentations, the correspondingOS -function space D !os E has an e�ective presentation. The functions ar-ity and size for the function space can be computed from the functions arityand size of the domains D and E. The details of the e�ective presentation ofOS -functions is given in appendix I.A domain D is embedded in T by a function fd mapping its prime elementsinto T. For each prime p, fd(p) is computed by inserting a subtree into the treecorresponding to predecessor of p. Since all the prime elements are enumeratedin topologically sorted order, the embedding can be de�ned inductively. Thedetails of the embedding are given in appendix II. An arbitrary element of thedomain D can be embedded by embedding all its prime approximations.5.3 A Universal Language for Sequential ComputationTo embed an arbitrary domain D, we must de�ne a retraction (an idempotentfunction) fD over T such that its range fD(T) is isomorphic to D. Then, se-quential computations over D can be performed in the universal domain T. Toexpress sequential computations over arbitrary OS -domains, we must design alanguage that can express all computable OS -functions over T. In this section,we introduce such a universal language KL (Kleene's Language) for the domainT. The languageKL includes a binary operator Apply : T�T!os T and a set ofconstants: f0; errori; 1+; 1�; pair?; left; right; cons; if0g. These primitives constructtrees, select subtrees, and perform arithmetic operations on natural numbers.All the constants except 0 and errori are elements of T!os T (embedded in T);they are interpreted as functions by Apply . In Fig. 1, we present the constantsin T !os T as uncurried functions instead of the explicit tree representationsfor clarity.In the tradition of Kleene, programs in KL are sets of recursive de�nitionsover the primitive operations using Apply . Thus, a function is de�ned by com-position and application of other functions and recursion. The denotation of afunction de�ned by a recursive de�nition is the least �xed point of correspondingfunctional [13, 2].All the primitive operations andApply overT are observably sequential. Sincecomposition, application, and least �xed points preserve observable sequentiality,KL can only express the OS -functions.Figure 2 de�nes the operational semantics of KL, where f(x) abbreviatesApply(f; x). The operational semantics de�ned by these rewrite rules exactlymatch the mathematical semantics. In other words, the evaluation of an expres-sion M yields the potentially in�nite canonical form for the tree d denoted byM . The evaluation of M terminates i� d is �nite and maximal.Compatibility with �-Notation: It is easy to de�ne an alternate syntax forKL based on �-notation. In that notation, �-abstractions are abbreviations forterms constructed by the combinators S and K, and the primitive operations

Nullary Operations:0 = d0e errori = erroriUnary Operations:1+ = fn 7! n+ 1g [ ferrori 7! errorig1� = f0 7! 0g [ fn+ 1 7! ng [ ferrori 7! errorigpair? = fh?;?i 7! 0g [ fn 7! 1g [ ferrori 7! errorigleft = fhx;?i 7! xg [ ferrori 7! errorigright = fh?; yi 7! yg [ ferrori 7! errorigBinary Operations:cons = fx� y 7! hx; yigTernary Operations:if0 = f0� x�? 7! xg [ f1�?� y 7! yg[ferrori �?�? 7! errorigFig. 1. Primitive Operators of KL1+(n) �! n+ 1 cons(a)(b) �! ha; bi1+(errori) �! errori if0(0)(a)(b) �! a1�(0) �! 0 if0(n+ 1)(a)(b) �! b1�(n+ 1) �! n if0(errori)(a)(b) �! errori1�(errori) �! errori pair?(errori) �! erroripair?(ha; bi) �! 0 pair?(n) �! 1left(ha; bi) �! a right(ha; bi) �! bleft(errori) �! errori right(errori) �! erroriFig. 2. Rewriting Rules for KLf1+; 1�; left; right; cons; pair?; if0g. The combinators S and K are de�nable byrecursive equations in KL, but the de�nitions are a bit tedious [4]. Since theset of OS -domains and OS -functions form a cartesian closed category [8], weknow that S and K are OS -functions. For the proofs in this paper, it is moreconvenient to write programs as recursion equations.6 Computability and UniversalityKL can be used to perform arbitrary sequential computations over an OS -domain if it can express all computable OS -functions. The proof for the ex-pressiveness of KL has two parts: First we must show that any partial recursivefunction over the natural numbers can be de�ned in KL. Second, we must showthat any element or OS -function that is computable on the domain T can bede�ned in KL.We show that the languageKL is partially recursive by encoding an arbitrarypartial recursive function in the language. It is well known [16] that any par-

tial recursive function can be expressed by the operations: 0; 1+; 1�, selection,composition, primitive recursion, and minimization. All these operations can beexpressed in KL over the natural numbers.A programming language L is universal for a domain D i� the language canexpress all the computable elements of D and all the computable functions overD. If we encode the prime elements of D as natural numbers, an element in Dis computable if the prime approximations are recursively enumerable. An OS -function is computable if its graph, i.e., the set f(b; f(b))g where b are �niteelements, is recursively enumerable. Since the OS -functions can be embeddedin T and interpreted by Apply , it su�ces to show that KL can de�ne all thecomputable elements of T to prove the universality of KL.We can encode the prime elements of the Universal Domain T as follows.We can map numbers into the possible values at the end of the node with afunction val de�ned as val(0) = cons, val(1) = error1, val(2) = error2, and forall other numbers val(m) = m � 3. Each path of the tree can be encoded asa binary number where the leading 1 represents the beginning of the tree andevery subsequent 0 or 1 represents a left branch or right branch, respectively.For example 1001 is the binary encoding of the path left, left, right.If the prime approximations to a computable element d are r.e., then thereis a partial recursive function, called the characteristic function, fd such thatfd(n) = m i� the element of the node at the end of the path represented by n isval(m). Using such an encoding, the language KL can express any computableelement d in T. Since the element d is computable, it has a characteristic functionfd that is partially recursive. Since any partial recursive function can be writtenin the languageKL, some function f inKL can express fd. Given such a functionf, we can recursively construct the element d as follows:2times(n) = if0(n; n; 1+(1+(2times(1�(n)))))g(n) = if0(f (n); cons(g(2times(n)); g(1+ (2times(n))))); val(n))d = g(1)The expression d recursively constructs the tree corresponding to the elementd with the help of the function g.Full abstraction of KL: Since every �nite element of the domain is com-putable, every �nite element can be de�ned in KL. From that fact we can provethat the domain T is a full abstract model for KL as follows. If KL is not fullyabstract, then there are two terms M and N that are operationally equivalentbut denotationally di�erent. Since their denotations are di�erent, there mustbe a prime element (a tree node) in one of the denotations, but not the other.Therefore, we can write a simple program P using left and right operations thatextracts the di�erentiating node. Hence P distinguishes M and N contradictingthe assumption that they are operationally equivalent. Thus, we conclude thatin KL denotational equivalence implies operational equivalence.

7 Conclusions and AcknowledgmentsOur investigation of OS -domains provides strong support for the claim thatKL is a universal programming language for sequential computation. Any OS -domainD can be embedded in the domainT by an observably sequential retrac-tion that preserves the maximality of �nite elements. Moreover, any computablefunction f over D is de�nable in KL over the embedded image of D. Since themaximality of �nite elements is preserved by the embedding, the image of f inKL behaves exactly like f|including termination behavior.We thank Matthias Felleisen and Pierre-Louis Curien for correcting errors inan earlier draft of the paper and making many helpful suggestions on how topresent our technical results and intuitive explanations.References1. G. Berry and P-L. Curien. Sequential algorithms on concrete data structures.Theor. Comput. Sci., 20:265{321, 1982.2. R. Cartwright. Recursive programs as de�nitions in �rst order logic. SIAM Journalof Computing, 13:374{408, 1984.3. R. Cartwright and A. Demers. The topology of program termination. In Proc.Symposium on Logic in Computer Science, pages 296{308, 1988.4. R. Cartwright and J. Donahue. The semantics of lazy (and industrious) evaluation.In Proc. 1982 ACM Symposium on Lisp and Functional Programming, pages 253{264, 1982.5. Robert Cartwright and Matthias Felleisen. Observable sequentiality and full ab-straction. In Conference Record of the Nineteenth Annual ACM Symposium onPrinciples of Programming Languages, pages 328{342, January 1992.6. R.S. Cartwright, P.-L. Curien, and M. Felleisen. Fully abstract models of observ-ably sequential languages. Information and Computation. To appear.7. Alonzo Church. An unsolvable problem of elementary number theory. AmericalJournal of Mathematics, 58:345{363, 1936.8. P.-L. Curien. Observable algorithms on concrete data structures. In Proc 7thSymposium on Logic in Computer Science, 1992.9. P.L. Curien. Categorical Combinators, Sequential Algorithms and Functional Pro-gramming. Research Notes in Theoretical Computer Science. Birkhauser, 1993.10. Martin Davis. Computable functionals of arbitrary �nite type. In A. Heyting,editor, Constructivity in Mathematics. North Holland Publishing Company, Ams-terdam, 1959.11. G. Kahn and G. Plotkin. Concrete domains. In Fertschirift for C. Boehm, 1993.12. R. Kanneganti, R. Cartwright, and M. Felleisen. Spcf: its model, calculus, andcomputational power. In Proc. REX Workshop on Semantics and Concurrency.Lecture Notes in Computer Science. Springer Verlag, 1992.13. Stephen C. Kleene. General recursive functions of natural numbers. Mathematis-che Annalen, 112:727{742, 1936.14. G. Kreisel, D. Lacombe, and J. R. Scoen�eld. Partial recursive functionals ande�ective operations. In A. Heyting, editor, Constructivity in Mathematics. NorthHolland Publishing Company, Amsterdam, 1959.15. G.D. Plotkin. T! as a universal domain. J. Comput. Sci., 17:209{236, 1978.

16. Hartley Rogers. Theory of Recursive Functions and E�ective Computability.McGraw-Hill, New York, 1967. McGraw-Hill series in higher mathematics.17. D.S. Scott. Data types as lattices. SIAM J. Computing, 5:522{587, 1976.18. Alan M. Turing. Computability and �-de�nability. The Jounal of Symbolic Logic,2:153{163, 1937.Appendix I: E�ective Presentation of Function SpacesIn this appendix, we show how to construct an e�ective presentation P of thefunction space D1 !os D2 given the e�ective presentations P1 and P2 forD1 andD2. Since the �nite elements of Di are the least upper bounds of sets of primes,we can assign unique codes in N to the �nite elements of Di using standardmethods for encoding sequences. Let the indices I; J range over the indices of�nite elements and i; j; k range over the indices of prime elements. We refer tothe �nite element with index I as aI and the prime element with index i as pi.We superscript elements with their domains whenever it is necessary to avoidconfusion.The index of each prime function is de�ned inductively as follows. Let theindex of the ? !os ? be 0. Let f be a prime function immediately above f 0.Let the index of f 0 be l. Then,E(f) = � hh0; I; ki; li if f is an output prime determined by f 0; aI , and pkhh1; hI;mi; ni; li if f is a schedule prime with sif (aI ; Cm) = Cnwhere h�; �i is the standard bijective pairing function on N. It is clear from theabove encoding that the enumeration is topologically sorted.pr is the function that selects the second component of a tuple hi; ji since pjis the immediate predecessor of the prime element phi; ji.The function c is de�ned by the equations:c(hh0; I; ki; li) = hhI; c2(k)i; lic(hh1; hI;mi; ni; li) = hhI;mi; liFrom the above encoding, it is easy to show that elements in the same C-set aremapped to same number.The function arity is de�ned by the equations:arity(hh0; I; ki; li) = arity2(k)arity(hh1; hI;mi; ni; li) = size1(n)The number of C-sets above an output prime f depends on the number of C-setsabove the �nal output pk of f . The function f may generate incremental outputsin all the directions above pk; therefore arity(f) = arity2(k). If f is a scheduleprime with sif (aI ; Cm) = Cn, f may generate a C-set for each element in theinput C-set Cn; therefore arity(f) = size1(n).

The function size is de�ned as follows. Let the index of the C-set Q behhI;mi; li. Let SI be the set of indices primes on the \fringe" of aI , i.e., if i 2 SIthen pi 2 aI and there is no pj 2 aI such that pr(j) = i. Then,size(hhI;mi; li) = size2(m) +Xi2SI arity1(i)where the addition operator + has been extended to the domain N [ f!g. Wecan easily verify that the function size gives the cardinality of the C-set inD1 !os D2. It is clear that the number of output primes in the C-set Q is exactlythe number of primes in the output C-set Cm. The C-set Q has a schedule primefor each direction above aI . Thus, the preceding de�nition of size computes thenumber of elements in the C-set.Appendix II: Embedding in the Universal DomainIn this appendix, we show how to embed an e�ectively presented domain Dwithin T. We de�ne the embedding function f mapping each prime element piinto T by induction on i. At each stage in the construction of f , we prove thefollowing hypotheses.1. f maps the prime element pi to a tree formed by substituting a subtree sifor a ? leaf in the tree corresponding to its predecessor. The subtree si hassame number of ?'s as the number of C-sets above pi.2. If p; q 2 Ci (the same set in the partitioning), then the trees f(p) and f(q)are inconsistent.3. If p � q, then f(p) v f(q).4. If a �nite element a represented by the set A of prime elements is maximal,the tree Fff(p) j p 2 Ag is maximal.Base Case: f maps p0, which must be ?, to hn;?ni where n is the numberof C-sets above ?.Induction Step: Assume that we have embedded all the primes in theenumeration from p0 through pi�1. We de�ne f(pi) as follows:Let k be the cardinality of the set of the already enumerated elements that arein con ict with pi. Let si, the subtree for pi be hhhsize(c(pi)); ki; arity(pi)i;?li,where l is the number of C-sets above pi. Note that l can be !. Let q be theelement immediately below pi. By induction, q has been embedded in T as a treef(q). The element q was embedded in T by adding a subtree sq to the image of q'spredecessor. (In the special case where q = ?, let sq be f(?).) In the subtree sq ,insert si (the subtree corresponding to pi) at position g(pi), where the functiong(pi) is de�ned as follows. If a prime p0 belonging to the same C-set as pi hasbeen enumerated, then g(pi) = g(p0). Otherwise, g(pi) is the number of distinctC-sets above q that are already enumerated. By the induction hypothesis, theposition g(pi) has ? in the subtree sq .It is easy to show that by the preceding construction satis�es the hypotheses.This article was processed using the LaTEX macro package with LLNCS style