Transcript

On Two Forms of Structural Recursion ?Dan Suciu1 and Limsoon Wong21 University of Pennsylvania, Philadelphia. Email: [email protected] Institute of Systems Science, Singapore. Email: [email protected]. We investigate and compare two forms of recursion on setsfor querying nested collections. The �rst one is called sri and it corre-sponds to sequential processing of data. The second one is called sru andit corresponds to data-parallel processing. A uniform �rst-order trans-lation from sru into sri was known from previous work. The conversetranslation is by necessity more di�cult and we have obtained three mainresults concerning it. First, we exhibit a uniform translation of sri queriesinto sru queries over the nested relational algebra. We observe that thistranslation maps PTIME algorithms into exponential-space queries. Thesecond result proves that any uniform translation of sri queries into sruqueries over the nested relational algebra must map some PTIME queriesinto exponential-space ones. In fact, in the presence of certain externalfunctions, we provide a PTIME sri query for which any equivalent sruquery requires exponential space. Thus, as a mechanism for implement-ing algorithms over complex objects, sru is strictly less powerful thansri. This ine�ciency is in contrast to a previous result that uniformlytranslates e�cient sri programs into e�cient sru programs, but over alanguage with higher-order functions. Our third result proves that, in theabsence of external functions, higher-order functions do not add more ex-pressive power to the nested relational algebra with sri or sru. However,elimination of higher-order functions cannot be done uniformly, becausein the presence of certain external functions, more expressive power canbe gained from the higher-order functions. These three results suggestthat higher-order functions could be useful in query languages.1 IntroductionStructural recursion is an attractive paradigm for programming with sets. It canbe conceived in two distinct ways, corresponding to the two distinct universalproperties that the �nite set construction enjoys [7]. The �rst gives rise to a formof structural recursion that Tannen, Buneman, and Wong call sri [8]. It is closelyrelated to the set reduce of Stemple and Sheard [21] and the fold operator infunctional programming languages [5]. Essentially, sri de�nes a function g ona set O by iteration in an order-independent manner over the elements of O.? An extended abstract of this paper appeared in the Proceedings of the 5th Interna-tional Conference on Database Theory, Prague, January 1995.

Namely, it allows us to de�ne g by:g(fg) = eg(fxg [ O) = i(x; g(O))Here i is a previously de�ned function and e is some value. We write sri(i; e)to denote the function g thus de�ned. In order for g to be well de�ned, i has tosatisfy the following two conditions: i(x; i(y; a)) = i(y; i(x; a)) (commutativity),and i(x; i(x; a)) = i(x; a) (idempotence). This form of recursion is related to theprimitive recursion schema in the theory of recursive functions [17].The second form of structural recursion is called sru by Tannen, Buneman,and Wong [8], from structural recursion on the union presentation. It is relatedto the hom operator of Machiavelli [18] and the pump operator of FAD [4].Essentially, sru allows us to de�ne a function h on a set O in a divide-and-conquer manner. To compute h, one has to divide O recursively in an order-independent way into ever smaller subsets until one reaches sets with 0 or 1elements. More precisely, sru allows us to de�ne some function h by:h(fg) = eh(fxg) = f(x)h(O1 [ O2) = u(h(O1); h(O2))We use sru(u; f; e) to denote the h thus de�ned. Note that it is not well de�nedunless the following conditions are satis�ed: u(e; a) = u(a; e) = a (identity),u(a; b) = u(b; a) (commutativity), and u(a; a) = a (idempotence).When sri and sru are considered as candidates to be incorporated in adatabase query language, it is necessary to compare the relative expressive powerof the two resultant languages. A straightforward and e�cient translation of sruinto sri is described in Tannen and Subrahmanyam [7]. This translation is �rst-order expressible. This implies that any reasonable language augmented with sriis at least as powerful as the same language augmented with sru. Furthermore,any e�cient algorithm expressed in the language with sru is tranlated into ane�cient one in the language with sri. Tannen and Subrahmanyam also give asimple translation of sri into sru. However, this translation uses higher-orderfunctions. This paper investigates alternative translations of sri into sru overquery languages for complex objects without higher-order functions.We use the nested relational calculusNRC of Wong [25] as the ambient querylanguage in this investigation. NRC has the same power as the query languagesfor nested relations of Thomas and Fischer [24], Schek and Scholl [20], Colby [9],etc. We add the two forms of structural recursion above to NRC. Our �rst resultis a uniform translation of queries in NRC(sri) into queries in NRC(sru). Thistranslation works in the presence of arbitrary external functions. Furthermore,it works equally well for other collection types, such as bags and lists. However,the translation is expensive. In particular, it maps some PTIME algorithm intoone that requires exponential space.Our second result proves that any uniform translation of queries fromNRC(sri) into NRC(sru) has to be expensive. In particular, any such uni-form translation must map some PTIME algorithms into exponential space ones.

\Uniformity" is a desirable condition that makes separate compilation possible.A uniform translation has to translate or compile sri(i; e) by independentlytranslating or compiling sri, i, and e. It should be stressed that this result doesnot compare the relative expressive power of the two languages, which is thesame. Rather, this result compares their ability to express e�cient algorithms.It is in the same spirit as that of Abiteboul and Vianu [3], proving that paritycannot be expressed in PTIME by a Generic Machine, and as that of Suciu andParedaens [23], proving that Abiteboul and Beeri's algebra for complex objectsneeds exponential space to express transitive closure. We need to associate toeach expression in NRC(sru) and NRC(sri) a certain algorithm. This associa-tion is accomplished by formally de�ning an evaluation strategy for these expres-sions [23]. Our result depends on the particular evaluation strategy considered,which is the unoptimized \call-by-value" evaluation strategy, and may not holdfor more advanced evaluation techniques. A weakness of our result is that wedo not have a particular PTIME query in NRC(sri) for which no equivalentPTIME query in NRC(sru) exists. However, given certain external functions,we can construct such a query; see Proposition 3. Still our result suggests thatNRC(sri) can implement more e�cient algorithms than NRC(sru).In the context of database query languages and ordered databases, it isknown [22] that �rst-order logic extended with divide and conquer recursion,which is a form of recursion closely related to sru, captures the complexity classNC, while �rst-order logic extended with sri captures PTIME. Here NC is theclass of functions computable by polynomially many processors in polylogarith-mic parallel time. NC is known to be included in PTIME, but it is unknownwhether they are equal. Thus our result here (Theorem 2) can be interpretedas saying that there is no uniform translation of a certain query language forPTIME into another query language for NC.Our third result is motivated by the e�cient translation of sri into sruusing higher-order functions given by Tannen and Subrahmanyam [7]. Whilepractical programming languages with higher-order functions such as ML andScheme exists, they have received little attention in the context of database querylanguages. This e�cient translation of sri into sru using higher-order functionstogether with the proven ine�cency of any uniform translation of NRC(sri)into NRC(sru) suggests that higher-order functions could be useful in querylanguages. Our third result proves that the expressive power of NRC(sru) andNRC(sri) is not changed by adding higher-order functions to them. However,we also show that higher-order functions can increase expressive power givencertain additional primitives.Organization Section 2 introduces NRC, NRC(sru), and NRC(sri). Section 3presents the uniform translation of sri into sru. This translation proves thatNRC(sru) and NRC(sri) have the same expressive power, even in the presenceof external functions. Section 4 proves that any such translation is very costly,in the sense that the translated query has to create large objects. Section 5considers the in uence of intermediate higher-order functions on the expressivepower of our languages. We prove that over complex objects the same expressive

power is preserved when higher-order functions are added to our languages; butwhen certain external functions are also added to our languages, the presence ofhigher-order functions increases expressive power.2 Languages to be StudiedThe calculus NRC.As our ambient language in comparing the two forms of structural recursion weuse the nested relational calculus NRC of Wong [25]. It is a language having thesame expressive power as other tractable formalisms for complex objects, such asThomas and Fischer's algebra [24], Schek and Scholl's NF 2 [20], Colby's recur-sive algebra [9], Abiteboul and Beeri's algebra without powerset [2], Paredaensand Van Gucht's nested algebra [19], etc. NRC is an algebraic language | thename \calculus" should be taken with the same meaning as in \lambda calculus"and not with the meaning in \�rst-order calculus" [8].NRC is a strongly typed language. The complex object types are given bythe grammar: s; t ::= b j unit j s� t j fsgHere b ranges over base types such as numbers N and booleans B . An objectof type s � t is a pair whose �rst component is an object of type s and whosesecond component an object of type t. An object of type fsg is a �nite set whoseelements are objects of type s. The only object of type unit is the empty tuple(). NRC de�nes two kinds of expressions: complex objects expressions and func-tion expressions. A complex object expression denotes a complex object. Wewrite e : t to mean that e is a complex object expression and the complex objectit denotes has type t. A function expression denotes a function from complexobjects to complex objects. We write e : s ! t to mean that e is a functionexpression with domain s and codomain t. The language is parameterized by acollection � of constants c and external functions p. Each c 2 � has some �xedtype tc and each p 2 � has some type dp ! cp. For each type s, Xs is an in�niteset of variables of type s. NRC is de�ned by the following rules:x 2 Xsx : s p 2 �p : dp ! cp x 2 Xs e : t�x:e : s! t e1 : s! t e2 : se1 e2 : tc 2 �c : tc () : unit e1 : s e2 : t(e1; e2) : s� t e : s� t�1 e : s e : s� t�2 e : tfg : fsg e1 : fsg e2 : fsge1 [ e2 : fsg e : sfeg : fsg e1 : ftg e2 : fsgSfe1 j x 2 e2g : ftgtrue : B false : B e1 : B e2 : s e3 : sif e1 then e2 else e3 : s e1 : s e2 : se1 = e2 : BThe meanings of these expressions are as follows. �x:e is the function f suchthat f(x) = e. e1e2 is function application, and applies the function e1 to the

complex object e2. (e1; e2) forms a pair whose �rst component is e1 and secondcomponent e2. �1 e retrieves the �rst component of the pair e. �2 e returns thesecond component of the pair e. fg is the empty set. feg forms the singleton setcontaining e. e1[e2 is the union of sets e1 and e2.Sfe1 j x 2 e2g is the set denotedby sru([; �x:e1; fg)(e2), i.e. e1[o1=x] [ : : : [ e1[on=x], where e2 = fo1; : : : ; ong.A query of type s! t is a closed function expression e : s! t.It is convenient to use the syntactic sugar fe j x1 2 e1; � � � ; xn 2 eng as ashorthand for SfSf� � �Sffeg j xn 2 eng � � � j x2 2 e2g j x1 2 e1g. Also, we useabbreviations like �(x; y):x [ y for �z:�1 z [ �2 z, or Sfx j (x; y) 2 eg, insteadof Sf�1 z j z 2 eg.We write NRC(�) to emphasize the external functions present in the lan-guage, or simply NRC when there is no external function. We allow a limitedamout of polymophism, like in the unnest query: unnest(x) def= f(x; z) j (x; y) 2r; z 2 yg, whose type is fs� ftgg ! fs� tg, for arbitrary s and t.The augmented languagesWe extend NRC(�) with the two constructions sru(u; f; e) and sri(i; e) de�nedin Section 1. For this, we add the following typing rules:u : t� t! t f : s! t e : tsru(u; f; e) : fsg ! t i : s� t! t e : tsru(i; e) : fsg ! tWe write NRC(sri), NRC(sru), NRC(sri; �), and NRC(sru;�) for the ex-tensions of NRC and NRC(�) with sri and sru respectively. In the remainderof this paper, we consider several aspects of the question of NRC(sru;�) =NRC(sri; �) for various signatures �.3 Equivalence in the Absence of Higher-Order FunctionsIn the absence of external functions, NRC(sri) and NRC(sru) have the sameexpressive power as that of Abiteboul and Beeri's algebra (with powerset) [8],which in turn has the same expressive power as NRC(powerset). In this sectionwe extend the equivalence of NRC(sri) and NRC(sru) to the equivalence ofNRC(sri; �) and NRC(sru;�), where external functions are present in �. Wedo that by constructing a uniform translation between the two languages.Informally, a uniform translation from NRC(sri; �) to NRC(sru, �) isa translation having the following property. Let i : s � t ! t and e : t be twoadditional variables. Then the translation should map the expression sri(i; e) tosome expressionE inNRC(sru) having i and e as free variables such that sri(i; e)and E are equivalent, for every instantiation of i and e. In particular, a uniformtranslation extends to a mapping from NRC(sri; �) to NRC(sru;�) for anarbitrary set � of external functions. Similarly we de�ne uniform translationsfrom NRC(sru;�) to NRC(sri; �).From a practical point of view, the uniformity of a translation is connectedto the possibility of separate compilation and polymorphism. We want to be

able separate the translation or compilation of sri(i; e) from the translation orcompilation of i and e. Tannen and Subrahmanyam [7] give the following uniformand e�cient translations between sru and sri:sru(u; f; e)(O) def= sri(�(x; y):u(f(x); y); e)(O).sri(i; e)(O) def= sru(U; I; id)(O)(e), where id is the identity function, Iis a function such that I(x) = �y:i(x; y), and U is function composition,that is U(x; y) = �z:x(y(z)).The �rst de�nition gives us a uniform translation from NRC(sru) to NRC(sri).The second translation, from sri to sru, assumes a language with higher-orderfunctions. In particular sru(U; I; id), I , and U are all higher-order functions.Unlike general purpose functional languages, database query languages usuallydo not have higher-order functions and thus cannot express the above uniformtranslation of sri into sru.We show that a di�erent uniform translation of sri to sru that does not usehigher-order functions is possible. In particular, we give a uniform translationfrom NRC(sri; �) to NRC(sru;�).Theorem1. There exists a uniform translation of NRC(sri) into NRC(sru).Therefore, for any set � of external functions we have:NRC(sri; �) = NRC(sru;�) :The proof is given in Appendix A. The idea is to observe that the computation ofsru(u; f; e)(O0) is given by a balanced binary tree, whose leaves are labeled withthe elements of O0. In order to compute sri(i; e)(O) where O = fo1; : : : ; ong,one has to apply i consecutively n times. One can do that with a balancedbinary tree, provided the tree has height n and therefore 2n leaves. Thus, in thetranslation, we de�ne O0 to be a set with 2n elements.The proof of the theorem above is robust in the sense that it extends directlyto languages for bags and lists. See Tannen and Subrahmanyam [7] for a discus-sion of how sru and sri extend to these collection types. See also Libkin andWong [16, 26] for extensions of NRC to languages for bags and lists.Due to the way our translation works, a PTIME query in NRC(sri) mayget translated into a query in NRC(sru) that has exponential complexity. Forexample, the implementation of transitive closure inNRC(sri) by Tannen, Bune-man, and Naqvi [6] has polynomial complexity. But its translation to NRC(sru)via Theorem 1 results in an implementation having exponential complexity. Ofcourse, this does not rule out the existence of e�cient expressions for transi-tive closure in NRC(sru). Nonetheless, we conjecture that there is no PTIMEexpression for transitive closure in NRC(sru).4 The Cost of the TranslationWe prove in this section that any uniform �rst-order translation from NRC(sri)to NRC(sru) is inherently expensive. More precisely, we show that for a certain

external function i and constant e, the expression sri(i; e) denotes a query forwhich any \algorithm" in NRC(sru) requires exponential space, whereas the\algorithm" denoted by sri(i; e) is in PTIME. This shows a mismatch in theability of NRC(sri; �) and NRC(sru;�) in expressing algorithms. It also im-plies that any expression in NRC(sri) in which sri is used in an essential way,is mapped by any uniform translation into an expression in NRC(sru) denotingan exponential-space algorithm.This result is of a di�erent nature than inexpressibility results showing thata database query language cannot express certain queries. It states that of thetwo equivalent languages, NRC(sri; �) and NRC(sru;�), the former can ex-press certain queries in a more e�cient way than the latter. It is in the samespirit as the result [3] stating that parity cannot be expressed in PSPACE on aGeneric Machine and the result [23] stating that NRA(powerset) cannot imple-ment transitive closure e�ciently (even though it can express it.) Our result hereis somewhat weaker than these: in the absence of external functions we do notknow any particular query that can be expressed more e�ciently in NRC(sri)than NRC(sru). However, we conjecture that NRC(sru) cannot express tran-sitive closure in PTIME, while NRC(sri) obviously can [6].We start by de�ning an evaluation strategy for NRC(�). As in Suciu andParedaens [23], this strategy is essentially the eager or call-by-value evaluationstrategy in programming languages, presented in a natural deduction style. (SeeHennessy [13] for an introduction to this style of operational semantics.) Ourresult holds only in conjunction with this evaluation strategy. It may fail for alazy or call-by-need strategy. However, it does not depend on the particular formof presentation.First, let us de�ne a grammar for complex objects O:O ::= c j true j false j () j (O;O) j fO; : : : ; Ogwhere c stands for some constant such as a number, a string, etc.; (O1; O2) is apair; and fO1; : : : ; Ong is a set. The notation for a complex objects is subjectto the restriction that the sets have no duplicates and we consider two sets tobe equal if they di�er only in the order of their elements. For example, fc1; c2gand fc2; c1g denote the same complex object, while fc1; c2; c1g is illegal. Com-plex objects are typed; for example, fO1; O2; O3g is of type ftg, provided thatO1; O2; O3 are all of type t.Recall that NRC has two kinds of expressions: complex object expressionsand function expressions. We want to de�ne a binary relation e + O betweenan expression e and a complex object O, by induction on the structure of e. Itsintended meaning is \e fully evaluates to O." However, since NRC is a languagewith variables, we are forced to evaluate expressions e with free variables, whichhave been bound to complex objects. Following Curien [11] we de�ne an envi-ronment to be a set of the form � = fx1 := O1; : : : ; xn := Ong, where x1, ...,xn are variables and O1; : : : ; On are complex objects. Finally we de�ne belowthe relations � � e + O and � � e(O) + O0, with the intended meaning: \underthe environment �, the complex object expression e fully evaluates to O" and

\under the environment �, the function expression e applied to O fully evaluatesto O0." We write �; x := O instead of � [ fx := Og.c 2 �� � c + c p 2 � p(O) = O0� � p(O) + O0 f: : : ; x := O; : : :g � x + O�; x := O � e + O0� � (�x:e)(O) + O0 � � e2 + O � � e1(O) + O0� � e1 e2 + O0� � () + () � � e1 + O1 � � e2 + O2� � (e1; e2) + (O1; O2) � � e + (O1; O2)� � �1e + O1 � � e + (O1; O2)� � �2e + O2� � fg + fg � � e + O� � feg + fOg � � e1 + O1 � � e2 + O2� � e1 [ e2 + Owhere O = O1 [ O2� � e2 + fO1; : : : ; Ong �; x := O1 � e1 + O01 : : : �; x := On � e1 + O0n� �Sfe1 j x 2 e2g + O0where O0 = O01 [ : : : [ O0n� � true + true � � false + false� � e1 + true � � e2 + O� � (if e1 then e2 else e3) + O � � e1 + false � � e3 + O� � (if e1 then e2 else e3) + ORecall that a query is a function expression e with no free variables. Theevaluation fg � e(O) + O0 of a query e applied to a complex object O under thisoperational semantics should be viewed as a derivation tree whose root is labeledby fg � e(O) + O0 and whose nodes are labeled by the rules above. Note that fora certain query e, the height of the tree is independent of O but its width mayvary with O (see the rule for Sfe1 j x 2 e2g).This operational semantics is extended to NRC(sru;�) by adding the fol-lowing three evaluation rules for sru.� � e + O� � sru(u; f; e)(fg) + O � � f(O) + O0sru(u; f; e)(fOg) + O0� � sru(u; f; e)(fO1; � � � ; Obn=2cg) + O0� � sru(u; f; e)(fObn=2c+1; � � � ; Ong) + O00� � u(O0; O00) + O n � 2� � sru(u; f; e)(fO1; � � � ; Ong) + ONote that the evaluation of expressions in NRC(sru) is not deterministic dueto the last rule for sru, which says that we may choose any way of splittingthe set fO1; : : : ; Ong into two roughly equal disjoint halves. However, the well-de�nedness preconditions on sru guarantee the uniqueness of the output. Also,in contrast to NRC(�), for queries e in NRC(sru), the height of the evaluationtree for fg�e(O) + varies with O. But the height is bounded by a polylogarithmof the size of O.Similarly, we extend the operational semantics for NRC(�) to NRC(sri; �)by adding the two rules below. Note that the height of an evaluation treefg � e(O) + is bounded by a polynomial of the size of O.

� � e + O� � sri(i; e)(fg) + O� � sri(i; e)(fO2; � � � ; Ong) + O � � i(O1; O) + O0sri(i; e)(fO1; : : : ; Ong) + O0Next, we de�ne the size of complex objects. Up to a constant factor, size(O)gives us the number of symbols needed in the notation for O, assuming onesymbol su�ces for any value at base types. Formally, size(c) = 1, for constantsc of base types, size(true) = size(false) = size(()) = 1, size(O1; O2) = size(O1) +size(O2) + 1, and sizefO1; � � � ; Ong = size(O1) + � � �+ size(On) + 1.We de�ne complex(T ) = max(fsize(O00) j O00 occurs in Tg), for some deriva-tion tree T . For a query e and complex object O, the complexity of the eval-uation fg � e(O) + is de�ned to be: complex(e;O) = min(fcomplex(T ) j T is aderivation tree of fg � e(O) + O0g).Since the height of a tree T is polynomially related to complex(T ), the lattergives a rough approximation of the space needed to compute e(O), according tothe choices embodied by T . Then complex(e;O) gives us the smallest amount ofspace needed to evaluate e(O), among all possible nondeterministic choices.Now suppose there is a measure # : b! N on complex objects of base typeb. Extend this measure to all types as follows:#(c) = 0, if tc 6= b.#(O1; O2) = max(#(O1);#(O2)).#fO1; � � � ; Ong = max(#(O1); � � � ;#(On)).This measure is domain dependent and unrelated to the size of the complexobjects. It only becomes interesting through its interaction with the externalfunctions in �. Throughout this section, we assume that any external functionp in � only increases the measure of its argument by a constant amount; thatis, there is cp such that for every O, we have #(p(O)) � cp +#(O). This meansthat, for any evaluation tree T of e(O), we have #(e(O)) � #(O)+ c � height(T )for some constant c, depending only on �, leading us to the following theorem:Theorem2. Suppose that every primitive p in the language increases the mea-sure of its input object only by a constant amount. Then the following hold:1. For every query e in NRC(�) or NRC(powerset;�), there is a constant cesuch that for every complex object O, we have #(e(O)) � ce +#(O).2. For every query e in NRC(sru;�), there are constants ce and pe such thatfor every complex object O, we have #(e(O)) � ce � logpe(complex(e;O)) +#(O).3. For every query e in NRC(sri; �), there are constants ce and pe such thatfor every complex object O, we have #(e(O)) � ce �(complex(e;O))pe+#(O).The proof is given in Appendix B. The intuition behind it is that the mea-sure of complex objects may increase only by applying external functions, andthat the number of successive applications of external functions is bounded by

the depth of the derivation tree. Hence it su�ces to observe that the depth ofthe derivation tree T for an expression e is: constant, when e is in NRC(�)or NRC(powerset;�); polylogarithmic in the complexity of T , when e is inNRC(sru;�); and polynomial in the complexity of T , when e is in NRC(sri; �).The function powerset is handled as an external function, and it preserves themeasure of its input.The bounds given above are also tight. In fact, we prove that in the pres-ence of certain external functions, sri is strictly more e�cient than sru. Indeed,suppose � contains two base types N and D. N is the type of natural numbers,while D contains pairs (x;X), with x 2 N and X a �nite set of natural numbers.On these types we have an external function i : N � D ! D and a constante : D, de�ned by: i(x; (y;X)) = if x 2 X then (y;X) else (1 + y; fxg [ X),e = (0; fg). Note that, from the point of view of NRC(�), the values of typeD are atomic values as they can only be accessed through i, e, and the equalitytest. For example, �1(e) is not a well-de�ned expression in NRC(�) because it isillegally typed. Consider the query f : fNg ! D in NRC(sri; �), f def= sri(i; e),with meaning f(X) = (card (X); X), of polynomial (in fact linear) complexity.Corollary 3. Any expression in NRC(sru;�) equivalent to f has exponentialcomplexity. Speci�cally, for any equivalent query g in NRC(sru;�), there areconstants p and c such that the complexity of g(X) iscomplex(g;X) = (2 ppcard (X)=c) :Proof. De�ne the measure of an object of type D to be #(n;X) = n. ByTheorem 2, we have card (X) = #(g(X)) � cg logpg (complex(g;X)) + 0 (since#(X) = 0). Hence, complex(g;X) � 2 pgpcard (X)=cg . utConsequently, any uniform translation of NRC(sri) into NRC(sru) mustmap the PTIME expression e for transitive closure of Tannen, Buneman, andNaqvi [6] into an expression with exponential complexity. Indeed, e applies srito a set of size n. Due to the uniformity condition, the derivation tree for thetranslation of e must contain a subtree isomorphic to the derivation tree of g(O)above, for a set O with n elements. Hence it has at least the complexity of g(O).This ine�ciency is in contrast to the higher-order translation of Tannen andSubrahmanyam [7], which is both uniform and e�cient (that is, preserves com-plexity classes). A similar situation was described by Colson [10]. He gave ex-amples of functions that can be e�ciently computed using primitive recursionwhen functional input and output are allowed, but cannot be e�ciently com-puted when functional input and output are not allowed. This result, as well asthat of Colson, indicates the important e�ects higher-order functions have onperformance.We should also remark on the hom operator of Machiavelli [18], called dcrelsewhere [22]. If sru(u; f; e) is well de�ned, then so is hom(u; f; e) and theycompute the same function. The di�erence is that hom(u; f; e) does not have toobey idempotence axiom. Instead, it is required to satisfy hom(u; f; e)(O1[O2) =

u(hom(u; f; e)(O1); hom(u; f; e)(O2)) when O1 and O2 are disjoint sets. Conse-quently, the translation given in Section 3 can also be used to implement sri interms of hom. More interestingly, the proof of Theorem 2 holds also when homis used instead of sru. In the view of the result that sri and dcr correspond tothe complexity classes PTIME and NC respectively [22], Theorem 2 can be in-terpreted as saying that there is no uniform translation of a language for PTIMEinto a language for NC.Since any uniform translation from sri to sru requires exponential space,it cannot be expressed only over at relations. Let us denote with NRC1 therestriction of NRC to types of set height � 1; it is known [6, 25] that NRC1 hasthe same expressive power as the relational algebra. Then, using Theorem 2, wecan prove that, over the base type N with constant 0 and external function succ,sri is strictly more powerful than sru over at relations:Corollary 4. NRC1(sru;N; 0; succ) < NRC1(sri;N; 0; succ).The proof is given in Appendix C. This result is connected to a result byImmerman [15] stating that QR[logk n] < FO + LFP , for any k � 1. Thatresult does not imply our result, since it is not obvious whether NRC1(sru) isincluded in Sk QR[logk n]. However, his result is somewhat stronger than ours,because the presence of 0 and succ is not needed.5 Higher-Order FunctionsConsider now an extension of NRC(sri; �) and NRC(sru;�) to languages withhigher-order functions, which we call HNRC(sri; �) and HNRC(sru;�) re-spectively. The interesting aspect of these languages is that they are able to usestructural recursion in order to compute functions, in the style of Tannen andSubrahmanian's translation of sri into sru with higher-order functions.Since computing with sets needs an equality predicate on its elements, we donot allow the construction of sets of function in these higher-order languages.Hence we separate the types into two levels: the complex object types s; t andthe functional types S; T : s; t ::= b j unit j s� t j fsgS; T ::= s j t j S � T j S ! TThe operations at the object level are the same those for NRC(sru) andNRC(sri) respectivley, but sru and sri are extended over functions as well:e : T i : s� T ! Tsri(i; e) : fsg ! T e : T f : s! T u : T � T ! Tsru(u; f; e) : fsg ! TAlso, we have pairing, projections, lambda abstraction, and application at thefunction level:

e : T�x:e : S ! T e1 : S ! T e2 : Se1e2 : Te1 : S e2 : T(e1; e2) : S � T e : S � T�1e : S e : S � T�2e : TIn this section we show that every �rst-order function de�nable in thesehigher-order languages is also de�nable in their �rst-order fragments. That is,if f : s ! t can be expressed using some expression containing higher-orderfunctions, then we can �nd another expression having no higher-order functionto implement it. The proof requires several technical de�nitions.De�ne the �rst-order \equivalent" of a type S to be rel(S) as: rel(unit) def=unit , rel(B ) def= B , rel(b) def= b, rel(S�T ) def= rel(S)�rel(T ), rel(fsg) def= frel(s)g,and rel(S ! T ) def= frel(S)� rel(T )g. Note that if S is a complex object type,then S = rel(S).De�ne the \restriction" of the domain of a type S with respect to a �nite setb0 of objects of type b, restrictb0(S) � rel(S), by: restrictb0(unit) def= f()g,restrictb0(B ) def= ftrue; falseg, restrictb0(b) def= b0, restrictb0 (S � T ) def=f(x; y) j x 2 restrictb0 (S); y 2 restrictb0(T )g, restrictb0 (fsg) def= fx j x �restrictb0(s)g, and restrictb0(S ! T ) def= ff j f 2 frestrictb0(S)�restrictb0(T )g;f is functionalg. Note that if b0 is given, then restrictb0 (S) can be expressed us-ing NRC(sri), and that restrictb0 (S) : frel(S)g.De�ne restrictSb0 : S ! restrictb0 (S) to be a partial function \restrict-ing" an object O : S with respect to a �nite subset b0 of objects of typeb. Namely: restrictunitb0 () def= (); restrictBb0(x) def= x; restrictbb0 (x) def= x,if x 2 b0; restrictS�Tb0 (x; y) def= (restrictSb0 (x); restrictTb0 (y)), if restrictSb0 (x)and restrictTb0(y) are de�ned; restrictfsgb0 (X) def= frestrictsb0(x) j x 2 Xg, ifrestrictsb0(x) is de�ned for each x 2 X ; restrictS!Tb0 (f) def= f(x; y) j x =restrictSb0(x0) and y = restrictTb0(y0) where y0 = f(x0)g, if the latter is functional.In all other cases restrictSb0 (O) is unde�ned. Note that if o 2 restrictb0(s), thenrestrictsb0(o) = o. For a �rst-order function f : s! t, restricts!tb0 (f) is preciselythe graph of f restricted to b0.A function p : s ! t is said to be internal in the sense of Hull [14] ifrestricttb0(p(o)) = p(o) for all �nite b0 � b for which o = restrictsb0(o). In otherwords, a function is internal if it does not generate new values.Proposition5. Let all external primitives mentioned in � be internal. Let e : Sbe an expression of HNRC(sri; �) with x1 : S1, ..., xn : Sn as free variables.Let b0 be a �nite subset of b that includes all constants c : b occurring in e. Thenthere is an expression rel(e) : rel(S) of NRC(sri; �) with �x1 : rel(S1), ..., �xn :rel(Sn) as free variables such that for all O1 : S1, ..., On : Sn, if restrictSib0 (Oi)is de�ned for each i, then restrictSb0(e[O1=x1; :::; On=xn]) is de�ned and equalsrel(e)[restrictS1b0 (O1)= �x1; :::; restrictSnb0 (On)= �xn].

The proof is given in Appendix D. The main idea used in the proof is thathereditarily-�nite functions can be represented by hereditarily-�nite sets, andhence we can simulate any computation at higher order with some computationover complex objects. So for any signature satisfying the same conditions, weconclude that using higher-order functions at intermediate stages has no in u-ence on the class of �rst-order functions expressible in our languages.Theorem6. Let all external primitives mentioned in � be internal. Supposef : s ! t is a �rst-order function in HNRC(sri; �), or HNRC(sru;�). Thenf is also expressible in NRC(sri; �), or NRC(sru;�) respectively.Proof. We prove the case for HNRC(sri; �) and NRC(sri; �); the other caseis similar. Suppose f : s ! t is de�ned by �x:e. Let b0 be treated as a newconstant of type fbg. Apply the proposition above to e to get rel(e) with �x asits only free variable and with b0 appearing as a constant. Let C : fbg be thecollection of constants c : b appearing in e. Let Ds : s ! fbg be the functionthat extracts objects of type b from its input. This function is readily de�nablein NRC. Since s and t are complex object types, we know that s = rel(s) andt = rel(t). Then for any o : s, we have f(o) = rel(e)[o=�x; (C [ Ds(o))=b0]. So��x:rel(e)[(C [Ds(�x))=b0] is an expression in NRC(sri; �) implementing f . utHowever, in the presence of certain external functions that are not internal,higher-order functions give more expressive power. Indeed, consider the signature� containing the base type N and the external functions + : N � N ! N,: : N � N ! N, and gen : N ! fNg. + is the usual addition operation. : is theone-sided subtraction operation; that is, m : n = m�n if m > n and m : n = 0otherwise. gen is the function gen(n) = f0; : : : ; ng. Then we haveTheorem7. 1. The class of functions f : N � : : : � N ! N representable inNRC(sri; �) coincides with the class of primitive recursive functions [16].2. All functions f : N � : : : � N ! N expressible in Godel's system T [12] arealso expressible in HNRC(sri; �). Hence HNRC(sri; �) can express theAckermann function [12].Hence, for this particular �, HNRC(sri; �) is strictly more expressive thanNRC(sri; �). More, Theorem 1 also implies thatHNRC(sru;�) is strictly moreexpressive than NRC(sru;�).6 Conclusion and Future WorkIn summary, we presented three results in this paper. First, we exhibited a uni-form �rst-order translation of sri into sru. Second, we proved that any suchtranslation must create very large intermediate data and hence caused a degra-dation in performance. Third, we proved that every �rst-order function de�nableusing higher-order structural recursion is also de�nable using �rst-order struc-tural recursion. In the course of this work, we have observed several interestingphenomena that we would like to pursue further:

As concluded in Section 4, the ability to de�ne higher-order functions leads toconsiderably more e�cient programs. However, such functions are often excludedfrom query languages as can be seen from the survey of Abiteboul and Kanellakis[1]. As performance is an important factor in database queries, we should beginto pay serious attention to the use of higher-order functions in query languages.As remarked in Section 4, sru can be replaced by hom everywhere. Also,there exists a uniform translation from hom to sru, namely going through sri,but which is ine�cient. Does a result similar to Theorem 2 hold between sruand hom, stating that any uniform translation from hom to sru is ine�cient?In our search for the proof in Section 3, we found that the greatest di�cultywas in discovering a u which is both idempotent and associative. For example, letA �B be composition of binary relations, and consider the following expressionfor transitive closure: tc(R) def= hom(u; f; e)(R), where e def= fg, f(x) def= R, andu(A;B) def= A[B[ ((A[B)� (A[B)). Replacing hom with sru will not give usa correct expression, because u is not idempotent. In fact we do not know howto de�ne an e�cient transitive closure function using sru. We conjecture thatthere is no e�cient expression for transitive closure in NRC(sru).Acknowledgements We thank Peter Buneman and Val Tannen, they providedthe inspiration for this paper, as well as some useful simpli�cation. We thankLeonid Libkin for discussions. Suciu is supported by National Science Foundationgrants CCR-90-57570 and IRI-90-04137. Wong is supported by Army ReseachO�ce grant DAALO3-89-C-0031-PRIME. This research was carried out whenWong was at the University of Pennsylvania.References1. S. Abiteboul and P. Kanellakis. Database theory column: Query languages forcomplex object databases. SIGACT News, 21(3):9{18, 1990.2. S. Abiteboul and C. Beeri. On the power of languages for the manipulation ofcomplex objects. In Proceedings of International Workshop on Theory and Appli-cations of Nested Relations and Complex Objects, Darmstadt, 1988.3. S. Abiteboul and V. Vianu. Generic computation and its complexity. In Proceed-ings of 23rd ACM Symposium on the Theory of Computing, 1991.4. F. Bancilhon, T. Briggs, S. Khosha�an, and P. Valduriez. A powerful and simpledatabase language. In Proceedings of International Conference on Very Large DataBases, pages 97{105, 1988.5. R. S. Bird and P. Wadler. Introduction to Functional Programming. Prentice-HallInternational, 1988.6. V. Breazu-Tannen, P. Buneman, and S. Naqvi. Structural recursion as a querylanguage. In Proceedings of 3rd International Workshop on Database ProgrammingLanguages, Naphlion, Greece, pages 9{19. Morgan Kaufmann, August 1991.7. V. Breazu-Tannen and R. Subrahmanyam. Logical and computational aspects ofprogramming with Sets/Bags/Lists. In LNCS 510: Proceedings of 18th Interna-tional Colloquium on Automata, Languages, and Programming, Madrid, Spain,July 1991, pages 60{75.

8. V. Breazu-Tannen, P. Buneman, and L. Wong. Naturally embedded query lan-guages. In LNCS 646: Proceedings of 4th International Conference on DatabaseTheory, Berlin, Germany, October, 1992, pages 140{154.9. L. S. Colby. A recursive algebra for nested relations. Information Systems,15(5):567{582, 1990.10. L. Colson. About primitive recursive algorithms. Theoretical Computer Science,83:57{69, 1991.11. P. L. Curien. The ��-calculus: An abstract framework for environment machines.Technical Report URA 725, Laboratoire d'Informatique, Departement de Mathe-matiques et d'Informatique, Ecole Normale Superieure, 45 Rue d'Ulm, 75230 ParisCedex 05, France, 1988.12. J.-Y. Girard, Y. Lafont, and P. Taylor. Proofs and Types, volume 7 of CombridgeTracts in Theoretical Computer Science. Cambridge University Press, Cambridge,1989.13. M. Hennessy. The Semantics of Programming Languages: An Elementary Intro-duction using Structural Operational Semantics. John Wiley and Sons, Chichester,England, 1990.14. R. Hull. Relative information capacity of simple relational database schemata.SIAM Journal of Computing, 15(3):865{886, August 1986.15. N. Immerman. Length of predicate calculus formulas as a new complexity measure.In Proceedings of 20th Symposium on Foundations of Computer Science, San Juan,Puerto Rico, October 1979, pages 337{347.16. L. Libkin and L. Wong. Some properties of query languages for bags. In Proceed-ings of 4th International Workshop on Database Programming Languages, NewYork, August 1993, pages 97{114.17. P. Odifreddi. Classical Recursion Theory. North Holland, 1989.18. A. Ohori, P. Buneman, and V. Breazu-Tannen. Database programming in Machi-avelli, a polymorphic language with static type inference. In Proceedings of ACM-SIGMOD International Conference on Management of Data, pages 46{57, Port-land, Oregon, June 1989.19. J. Paredaens and D. Van Gucht. Converting nested relational algebra expressionsinto at algebra expressions. ACM Transaction on Database Systems, 17(1):65{93,March 1992.20. H.-J. Schek and M. H. Scholl. The relational model with relation-valued attributes.Information Systems, 11(2):137{147, 1986.21. D. Stemple and T. Sheard. A recursive base for database programming. In LNCS504: Next Generation Information System Technology, pages 311{332, Berlin, 1990.22. D. Suciu and V. Breazu-Tannen. A query language for NC. In Proceedings of 13thACM Symposium on Principles of Database Systems, pages 167{178, Minneapolis,Minnesota, May 1994.23. D. Suciu and J. Paredaens. Any algorithm in the complex object algebra needsexponential space to compute transitive closure. In Proceedings of 13th ACM Sym-posium on Principles of Database Systems, pages 201{209, Minneapolis, Minnesota,May 1994.24. S. J. Thomas and P. C. Fischer. Nested relational structures. In Advances inComputing Research: The Theory of Databases, pages 269{307, London, England,1986. JAI Press.25. L. Wong. Normal forms and conservative properties for query languages overcollection types. In Proceedings of 12th ACM Symposium on Principles of DatabaseSystems, pages 26{36, Washington, D. C., May 1993.

26. L. Wong. Querying Nested Collections. PhD thesis, Department of Computer andInformation Science, University of Pennsylvania, Philadelphia, PA 19104, August1994.

A Proof of Theorem 1We give the proof in two steps. In the �rst step, we prove that sri is de�nablein NRC(sru) augmented with natural numbers and a few operators on naturalnumbers. In the second step, we show that the extra primitives we have addedcan be removed. The new primitives that we need are:�: N � N ! B . This is the usual comparison operator on numbers.2� : N ! N. This is the multiply-by-2 function.cards : fsg ! N. This function returns the cardinality of the input set.Now we prove that sri can be de�ned using sru without using higher-orderfunctions, when the extra primitives above are available. That is,Proposition 8. Let sri(i; e) : fsg ! t be well de�ned. Then it is expressible inNRC(sru;N;�; 2�; card).Proof. We want to de�ne sri(i; e)(D) in terms of sru without using higher-orderfunctions. First let E : ffsgg�(N�ffsg�tg), F : fsg ! ffsgg�(N�ffsg�tg),and U : (ffsgg � (N � ffsg � tg))� (ffsgg � (N � ffsg � tg))! ffsgg� (N �ffsg � tg) be de�ned as follows:E def= (fg; (1; f(fg; e)g)),F (X) def= (fXg; (2; f(fg; e)g)), andU((A; (m;M)); (B; (n;N))) def= let (w;W ) be if m � n then (m;M) else(n;N) in if card(A [ B) � w then (A [B; (2 � w; f(fdg [ Y; i(d; y)) j(Y; y) 2 W;d 2 Dg)) else (A [ B; (w;W )).Next we de�ne a triple (A; (m;M)) to be proper if all three conditions below aresatis�ed:1. m is a power of 2. That is, m = 2i.2. bm=2c � card(A) < m.3. (fo1g[ : : :[fong; i(o1; i(o2; : : : i(on; e) : : :)) 2M i� o1 2 D, ..., on 2 D, andn = log(m)� 1. Note that o1, ..., on are not required to be distinct.The followings are readily veri�ed:Claim 1. Suppose (A; (m;M)) is proper. Then the cardinality of A completelydetermines m and M .2. E is proper.3. F (X) is proper.4. Suppose A and B are proper. Then U(A;B) is proper.5. Suppose A is proper. Then U(A;E) = U(E;A) = A.6. Suppose A is proper. Then U(A;A) = U(A).7. Suppose A and B are proper. Then U(A;B) = U(B;A).8. Suppose A, B, and C are proper. Then U(A;U(B;C)) = U(U(A;B); C).

Proof of claim. We prove only the last item. Let X def= (X1; (X2; X3)) def=U(A;U(B;C)). Let Y def= (Y1; (Y2; Y3)) def= U(U(A;B); C). By the fourth bullet,both X and Y are proper. It is clear that X1 = Y1 = (�1 A) [ (�1 B) [ (�1 C).Then by the �rst bullet, X = Y as desired.Thus sru(U; F;E) is well de�ned on any subset of powerset(D), wherepowerset(D) def= sru(�X:fr [ s j r 2 �1 X; s 2 �2 Xg; �x:ffg; fxgg; ffgg).Claim fsri(i; e)(D)g = f�2B j A 2 sru(U; F;E)(powerset(D)), B 2 �2(�2A),�1B = Dg.Proof of claim. First observe that sru(U; F;E)(powerset(D)) = (powerset(D),(m;M)) for some m and M . By being proper, we know that n def= card(D) =log(m) � 1. Therefore, (D; i(o1; i(o2; : : : ; i(on; e) : : :))) 2 M , where fo1; : : : ; ongis the set D. By the idempotent and commutative properties on i, we know thatif (D; x) 2M , then x = i(o1; i(o2; : : : ; i(on; e) : : :)). Hence the claim is proved.However, we still need a function hd : ftg ! t such that hdfxg = xand hd(S) = e if S is not a singleton set. But this is easy to de�ne: hd def=�2(sru(�X:if �1(�1 X) = false then �2 X else if �1(�2 X) = false then �1 Xelse if �2(�1 X) = �2(�2 X) then �1 X else (true; e); �x:(true ; x); (false ; e)).Then sri(i; e) = hd(f�2 B j A 2 sru(U; F;E)(powerset(D)); B 2 �3 A; �1 B =Dg. utThe extra primitives above are not critical to the proof of the propositionabove. Observe that to compute sri(i; e)(D) using the implementation above,we only need natural numbers 0, ..., 21+card(D). Given the set D : fsg, thenumber i can be represented by the set rep(i) : ffffsgggg such that L 2 rep(i)i� L 2 powerset(powerset(D)) and card(L) � i. For example, rep(0) is ffgg.Having established our representation of numbers, we demonstrate below therepresentation of the three new primitives introduced earlier. (We use the short-hand rep(N) for the type ffffsgggg.)Proposition9. 1. There is a function rep(2�) : rep(N) ! rep(N) such that forany i � 2card(D), it is the case that rep(2�)(rep(i)) = rep(2 � i).2. There is a function rep(�) : rep(N) � rep(N) ! B such that for any i �21+card(D) and j � 21+card(D), it is the case that rep(�)(rep(i); rep(j)) =(i � j).3. There is a function rep(cards �) : fffsggg � rep(N) ! B such that for anyR : fffsggg � powerset(powerset(D)) whose cardinality is at most 2card(D)and for any i � 21+card(D), it is the case that rep(card �)(R; rep(i)) =(card(R) � i).Proof. LetX or Y def= if X then true else Y ,X and Y def= if X then Y else false ,and X isin W def= sru(or; �Y:Y = X; false)(W ). Then

1. rep(2�)(W ) def= fL j L 2 powerset(powerset(D)); L isin fl1 [ l2 j l1 2W; l2 2 Wgg.2. rep(�)(X;Y ) def= sru(and; �y:y isin X; true)(Y ).3. rep(card �)(R;W ) def= R isin W . utWhence,Theorem 1 NRC(sru;�) = NRC(sri; �), for any collection � of base typesb, primitive functions p, and constants c.B Proof of Theorem 2Theorem 2 Suppose that every primitive p in the language increases the mea-sure of its input object only by a constant amount; that is, for all p 2 �, there iscp, such that for all complex objects O, #(p(O)) � cp+#(O). Then the followinghold:1. For every query e in NRC(�) or NRC(�; powerset), there is a constant cesuch that for every complex object O, we have #(e(O)) � ce +#(O).2. For every query e in NRC(sru;�), there is are constants ce and pe such thatfor every complex object O, we have #(e(O)) � ce � logpe(complex(e;O)) +#(O).3. For every query e in NRC(sri; �), there are constants ce and pe such thatfor every complex object O, we have #(e(O)) � ce �(complex(e;O))pe+#(O).Proof sketch. We prove a stronger statement, which we only state for the lan-guage NRC(sru;�). (It is similar for the other languages.) First extend thede�nition of the complexity of the evaluation of a query f on a object O,complex(f;O), to the complexity of the evaluation of a complex object expressione under environment �, complex(�; e), and to the complexity of the evaluationof a function expression e applied to a complex object O, under environment �,complex(�; e; O). Then the statement we prove is:1. For any complex object expression e, there are constants ce and pe such thatfor any environment � = fx1 := O1; : : : ; xn := Ong:#(O0) � ce � logpe(complex(�; e)) + #(�)where � � e + O0. Here #(�) def= #(fO1; : : : ; Ong).2. For any function expression f , there are constants cf and pf such that forany environment �, and complex object O:#(O0) � cf � logpf (complex(�; f; O)) + max(#(O);#(�))where � � f(O) + O0.

In fact, this is the statement of the theorem, in which each expression withfree variables is considered as a query having its free variables as inputs. Theproof of the statement goes by induction on the structure of e. We illustrate themost di�cult case, namely for a function expression f of the form sru(u; g; e).Suppose f is applied to some object O = fO1; : : : ; Ong, namely � � f(O) + O0.Then the last evaluation rule is:� � sru(u; g; e)(fO1; : : : ; Obn=2cg) + O11� � sru(u; g; e)(fObn=2c+1; : : : ; Ong) + O12� � u(O11; O12) + O� � sru(u; g; e)(fO1; : : : Ong) + O0 where n � 2.Going backwards, to the leaves of the evaluation tree, we �nd:� � sru(u; g; e)(fO1; : : : ; Obn=4cg) + O21� � sru(u; g; e)(fObn=4c+1; � � � ; Obn=2cg + O22� � u((O21; O22)) + O11� � sru(u; g; e)(fO1; � � � ; Obn=2cg) + O11and � � sru(u; g; e)(fObn=2c+1; � � � ; Ob3�n=4cg) + O23� � sru(u; g; e)(fOb3�n=4c+1; � � � ; Ong) + O24� � u((O23; O24)) + O12� � sru(u; g; e)(fObn=2c+1; � � � ; Ong) + O12At each level l, for any intermediate result Oli, there are two values at the levell + 1, say O(l+1)j and O(l+1)(j+1), such that � � u((O(l+1)j ; O(l+1)(j+1))) + Oli.By induction hypothesis, there are some constants pu and cu such that:#(Oli) � cu � logpu(complex(�; u; (O(l+1)j ; O(l+1)(j+1))))+max(#(�);#(O(l+1)j );#(O(l+1)(j+1)))� cu � logpu(complex(�; f; O)) + max(#(�);#(O(l+1)j );#(O(l+1)(j+1)))The last inequality is true because the complexity of computing f(O) is at leastas large as the complexity of computing u(O(l+1)j ; O(l+1)(j+1)). By induction onthe level l, we prove that:#(O0) � l � cu logpu(complex(�; f; O)) + max(#(�);#(Ol1);#(Ol2);#(Ol3); � � �)Indeed, suppose this holds for some l. Then:#(O0) � l � cu � logpu(complex(�; f; O)) + max(#(�);cu � logpu(complex(�; f; O)) + max(#(�);#(O(l+1)1);#(O(l+1)2));cu � logpu(complex(�; f; O)) + max(#(�);#(O(l+1)3);#(O(l+1)4)); � � �)� l � cu � logpu(complex(�; f; O))+cu � logpu(complex(�; f; O)) + max(#(�);#(O(l+1)1);#(O(l+1)2); � � �)Now let l be the depth of the balanced tree for computing � � sru(u; g; e)(fO1,: : : ; Ong); that is, let l = log(n). At that level, we apply the rule:

� � g(Ok) + Oli� � sru(u; g; e)(fOkg) + Oli for some iNow we apply the induction hypothesis for g, to get:#(Oli) � cg � logpg (complex(�; f; O)) + max(#(�);#(Ok))Combining the last two inequations with l = log(n) and noticing that n �complex(�; f; O) we get:#(O0) � cu � logpu+1(complex(�; f; O)) + max(#(�);#(Ol1);#(Ol2); � � �)� cu � logpu+1(complex(�; f; O)) + max(#(�);cs � logps(complex(�; f; O)) + max(#(�);#(O1));...;cs � logps(complex(�; f; O)) + max(#(�);#(On)))� cu � logpu+1(complex(�; f; O))+cs � logps(complex(�; f; O)) + max(#(�);#(O1); � � � ;#(On))= cu � logpu+1(complex(�; f; O))+cs � logps(complex(�; f; O)) + max(#(�);#(fO1; � � � ; Ong))� cf � logpf (complex(�; f; O)) + max(#(�);#(O))where pf def= max(pu + 1; ps) and cf def= cu + cs. utC Proof of Corollary 4Corollary 4 NRC1(sru;N; 0; succ) < NRC1(sri;N; 0; succ).Proof. The complex objects in this Corollary are considerably simpler than inother parts of this paper. They are now either tuples of atomic objects or are at relations, as oppose to nested relations in the general case. We use A and Bto denote these simple types.We de�ne a notion of limiting size limsize(A; n) of type A, where ht(A) � 1,with respect to n as follows:limsize(N; n) = 2 + n;limsize(unit ; n) = 2;limsize(A�B; n) = limsize(A; n) � limsize(B; n); andlimsize(fAg; n) = limsize(A; n). Note that ht(A) = 0 in this case.And we de�ne the measure of an object of type N to be #(succn(0)) def= n. Thenthe corollary follows from the claim below.Claim 1. limsize(A; n) � np, where 2 � n and p is a constant depending onlyon A.2. Suppose O : A is a complex object such that #(O) � n, where 2 � n. Thensize(O) � limsize(A; n).

3. There is a function f : fNg ! N in NRC1(sri;N; 0; succ) such that#(f(O)) � 2card(O).4. There is no function f : fNg ! N in NRC1(sru;N; 0; succ) such that#(f(O)) � 2card(O).Proof of claim. We prove only the last item, as the other three are easy. Let G beany function of type fNg ! N de�ned in NRC1(sru;N; 0; succ). Let A be a typein the type derivation of G so that limsize(A; n) is maximum for all n � 2 (thisis possible since the de�nition of limsize is monotone in its second argument).Let N = #(O) � 2. Let M be the maximum measure over all intermediate datain all executions of G(O). Let O0 : A0 be the intermediate data whose size isgreatest in all executions of G(O). Then the corollary follows immediately formthe following claim.#(G(O)) � a � logb(size(O0)) +N Theorem 2� a � logb(limsize(A0;M)) +N Claim 2� a � logb(limsize(A;M)) +N Choice of A� a � logb(M c) +N Claim 1Clearly, M � a � logb(M c) +N= d � logb(M) +N With d = a � cbBut M = N +D for some D,N +D � d � logb(N +D) +NHence D � d � logb(N +D)So 2 bpD=d �D � NIt is clear that D cannot be exponential with respect to N . Since #(G(O)) �M ,as M was chosen to be the maximum measure over all intermediate data, weconclude that #(G(O)) cannot be exponential with respect to N . This provesthe claim and the corollary. utD Proof of Proposition 5Assume that � is a signature containing some constants c : b and �rst-orderprimitives p : s ! t and nothing else. Each p : s ! t must be internal in thesense of Hull [14]. That is, we require that restricttb0 (p(o)) = p(o) for all �niteb0 � b and o = restrictsb0(o).

Proposition 5 Let e : S be an expression of HNRC(sri; �) with x1 : S1, ...,xn : Sn as free variables. Let b0 be a �nite subset of b that includes all constantsc : b occurring in e. Then there is an expression rel(e) : rel(S) of NRC(sri; �)with �x1 : rel(S1), ..., �xn : rel(Sn) as free variables such that for all O1 : S1,..., On : Sn, where restrictSib0 (Oi) : rel(Si) is in restrictb0(Si) for each i, thenrestrictSb0 (e[O1=x1; :::; On=xn]) is de�ned and equals rel(e)[restrictS1b0 (O1)= �x1,..., restrictSnb0 (On)= �xn].Proof. It su�ces to de�ned rel(e) by induction on the structure of e as follows.rel(true) def= truerel(false) def= falserel(if e1 then e2 else e3) def= if rel(e1) then rel(e2) else rel(e3) rel() def= ()rel(c) def= crel(�i e) def= �i(rel(e))rel(e1; e2) def= (rel(e1); rel(e2))rel(e1 = e2) def= rel(e1) = rel(e2)rel(x) def= �xrel(fg) def= fgrel(feg) def= frel(e)grel(e1 [ e2) def= rel(e1) [ rel(e2)rel(p : s! t) def= f(x; y) j (x; y) 2 restrictb0(s� t); y = p(x)grel(�x:e : S ! T ) def= f(�x; rel(e)) j �x 2 restrictb0(S)g.rel(e1 e2) def= app(rel(e1); rel(e2)), where app(F;E) def= hd(Sfif E =x then fyg else fg j (x; y) 2 Fg)rel(sri(i; e) : fsg ! t) def= SRI(rel(i); rel(e)), where SRI(I; E) def=f(X; sri(�x:app(I; x); E)(X)) j X 2 restrictb0(fsg)g. ut

This article was processed using the LATEX macro package with LLNCS style