The choice of programming primitives for SETL-like ... - Springer Link

11 downloads 0 Views 945KB Size Report
The question we want to discuss here ls the choice of programming ..... RemaTlc: It does not really matter how we handle the "freak" cases, and any other ...
The choice of programming primitives for SETL-like programming languages. (Extended abstract)

E. D a h t h a u s 1 D e p a r t m e n t of M a t h e m a t i c s (FB 20) T e c h n i c a l U n i v e r s i t y B e r l i n (West B e r l i n )

and J.A. ~ ! a k o w s k y 2 Department

of C o m p u t e r S c i e n c e , T e c h n i o l L Haifa, I s r a e l

Abstract: We discuss the choice of programming primitives for set oriented programnung languages such as SETL For this purpose we introduce a mathematical model (hereditarily finite sets with urelements). In this model criteria for the choice of programming prknittves are defined. The criteria are complexity, independence and computational completeness of the basic constructs. "fie propose primitives satisfying our criteria and also discuss briefly the possibility of defining abstract data types within our mathematical model. We give a characterization of the data types whose objects are recognizable in NP. Our work is a synthesis of several approaches previously introduced in other frameworks, such as query languages, generalized recursion theory and high level programruinglanguage design.

I D u r ~ the work on this paper visiting (Spring 1985) at due Department of Computer Science. Techmon. Haifa, Israel, sponsored hy Minerva Foundation. During work on this paper visiting at the [nstitut fuer [nformatik (Winter 1984/8~) and the Forsehungsinstitut fuer Mathemntik (Summer 1985), ETH-Zuerieh, Switzerland,

161

i. I n t r o d u c t i o n Programming languageswhich manipulate higher order objects have been considered for a long time, e.g. [Sch75] and [Ho83] for a historic survey. Mostly, the motivation behind such set oriented languages stems f r o m the need to implement readily arbitrary, abstractly defined data structures. The purpose of very high level languages is to " provide high level abstract objects and operations between them, high level control structures and the abilityto select data representation in an easy and flexible m a n n e r " [SSS79]. The most prominent example is ~

introduced by J. Schwartz [Sch75]. Also "object oriented" programming can

be viewed as set oriented. Our paper can also be viewed as a contribution to the theoretical foundations of set oriented prograrnnling. The question we want to discuss here ls the choice of programming primitives for SETLlike p r o g r a m m i n g languages. To m a k e such a discussion reasonable we have to choose flrst a mathematical model for the meaning of our programming languages. Within such a model we then can address the following issues: (1) Each program has to c o m p u t e a "computable" function. ]n other words we have to relate our model to a traditional model of computability. There are various attempts in the literature to generalize the notion of computability (over natural numbers or strings) to arbitrary objects, see [Sh73, Mo74, Mo84, Ca80] a m o n g others, and especially [Fe80] for a survey. (2) Once we have identified the computable functions for our objects we can define computational completeness of a prograrnnling language by requiring that all computable functions can be represented by a program, cf [CH80]. (3) The next criterion in the choice of p r o g r a m m i n g primitives should be the low complexity of the basic operations and constructs. This will, to a certain extent, depend on the exact model of computation (RAI/, Turing Machines, etc), but it is safe to require that the basic p r o g r a m m i n g primitives be polynomial in time or space. For iterative and parallel constructs the question of complexity is a bit m o r e delicate. The best one can hope for naturally is s o m e form of additivity: A while-construct has very little overhead and takes as m u c h time is the s u m of its iterations; for a parallel construct one would require the s a m e for the parallelly executed subprograms. In other words, the overhead of such construets should be uniform/y small (4) If one thinks of imp[ementation of higher order languages one has to address the issue of redundancy in the p r o g r a m m i n g primitives. Though independence of the constructs is not a value in itself, it is stillsignificant to have an independent basic set of p r o g r a m m i n g primitives available. Other primitives can then be added depending on the particular prog r a m m i n g applications or computer architecture features one has in mind. (5) Since we are dealing with very high level languages one has also to address their inherent data abstraction possibilities and their naturalness of expression. It should not be the case tha{ the c o m p l e m e n t of a finite set is computable only by a rather awkward prograin, as is the case in [Mo84], or that simple recursions can only be expressed by invoking a universal function or machine, as in [No78]. 19. Gandy, in [Ga80], discusses s o m e philosophical aspects of Church's Thesis which are related to our work. G a n d y postulates four principles concerning frameworks of computability from which, in contrast to Church's Thesis, it is provable that functions in these frameworks

162

a r e p a r t i a l l y r e c u r s i v e . He also p r o v e s t h e m i n i m a l i t y of t h o s e four p r i n c i p l e s in the s e n s e that no three of t h e m suffice to prove this result. The universe of discourse in [GAS0] are the hereditary finitesets with urelements, which also form the background of our work here. The computable transformations, introduced in this paper, however, do not satisfy all of G a n d / s principles. This shows, that not all computable functions satisfyGandy's principles. In particular, Gandy ties to capture mechanistic aspects of Computation machines, rather than to axiomatize the meaning of computability, as was initiatedin [CHS0]. It might be stimulating to reconcile the two approaches to computability. The main problem we address in this paper is that of defining precisely the semantic notion of a

coTnputable

object trans]'orr~at~. This is the content of section 2 and 3. Our

m a t h e m a t i c a l m o d e l a r e t h e hered~aTi2yffnite sets ~ t h urzternents. Finite o b j e c t s a r e u s u ally b u i l t f r o m s o m e , n o t f u r t h e r specified, a t o m s s u c h as v e r t i c e s in g r a p h s or t h e c o m p o n e n t s of t u p l e s [n r e l a t i o n a l d a t a b a s e s . T h e s e u n s p e c i f i e d e l e m e n t s a r e s u i t a b l y m o d e l l e d b y t h e old ( a n d in t i m e s u n p o p u l a r ) u r e l e m e n t s of c l a s s i c a l s e t t h e o r y (cf. [Ba75]). F r o m t h e s e a t o m s t h e o b j e c t s t h e n a r e b u i l t i n a s t r u c t u r e d way with t h e only r e s t r i c t i o n t h a t a t e v e r y s t e p of a c o n s t r u c t i o n only finitely m a n y o b j e c t s a r e involved a n d t h a t n o o b j e c t s c a n b e infinitely d e c o m p o s e d . Infinite c o l l e c t i o n s of objects, t h e r e f o r e , a r e n o t objects. If t h e y h a v e t o b e c o n s i d e r e d t h e y h a v e t o b e t r e a t e d like classes in s e t t h e o r y . The c o m p u t a b l e c l a s s e s of o b j e c t s c a n b e viewed as abstract data types. In t h i s p a p e r we shall d i s c u s s a b s t r a c t d a t a t y p e s as computable classes o f objects. S p e c i a l a t t e n t i o n s h o u l d b e g i v e n t o c l a s s e s w h o s e o b j e c t s a r e r e c o g n i z a b l e ( d e t e r m i n i s t i c a l l y or n o n - d e t e r m i n i s t i c a l t y ) in p o l y n o m i a l t i m e o r space. In t h i s f r a m e w o r k p r o g r a m s t a k e as i n p u t s o m e o b j e c t s ( f r o m a g i v e n d a t a t y p e ) a n d t r a n s f o r m t h e m i n t o o t h e r o b j e c t s (of s o m e o t h e r d a t a type). With s u c h a d e f i n i t i o n o n e c a n now define t h e s e m a n t i c s of v a r i o u s o b j e c t t r a n s f o r m a t i o n l a n g u a g e s . A o b j e c t t r a n s f o r m a t i o n l a n g u a g e L is co~zplete if for e v e r y c o m p u t a b l e o b j e c t t r a n s f o r m a t i o n t h e r e is a n e x p r e s s i o n ( p r o g r a m ) in L c o r r e s p o n d i n g to it. In s e c t i o n 4 we define a o b j e c t t r a n s f o r m a t i o n l a n g u a g e OTL w h i c h is c o m p l e t e . OTL h a s a v e r y s m a l l n u m b e r of b a s i c o b j e c t h a n d l i n g c o n s t r u c t s . They c o r r e s p o n d t o t h e s e t t h e o r e t i c o p e r a t i o n s union, c o m p l e m e n t , p o w e r set, u n o r d e r e d p a i r a n d t h e r e p l a c e m e n t a n d i n d u c t i o n principle. The i n d u c t i o n p r i n c i p l e o c c u r s in t h e f o r m of t h e w h i l e - c o n s t r u c t . The r e p l a c e m e n t p r i n c i p l e l e a d s to a new p r o g r a m m i n g c o n s t r u c t m k o b y~ f r o m yj i n y~ b y P. This c o n s t r u c t is v e r y m u c h in t h e s p i r i t of p a r a l l e l p r o g r a m m i n g or of d a t a flow l a n g u a g e s . It is s i m i l a r to t h e f o r all c o n s t r u c t of VAL (cf. [Ho83]). It r e p l a c e s t h e s u b o b j e c t s of y~ simult a n e o u s l y a n d p u t s t h e m i n t o t h e o b j e c t y~. The c o n s t r u c t also allows p a r a l l e l t r a n s f o r m a t i o n p r o c e s s i n g t o b e e x p r e s s i b l e i n DL. As m e n t i o n e d before, t h e p r o g r a m m i n g l a n g u a g e OTL t u r n s o u t t o b e a n a b s t r a c t a n d well d e f i n e d s u b l a n g u a g e of b'ETL w h i c h is e q u i v a l e n t t o b o t h in c o m p u t i n g p o w e r a n d flexibility. We also a n a l y z e t h e c o n s t r u c t s of OTL a n d e x h i b i t a n i n d e p e n d e n t ( n o n r e d u n d a n t ) s u b s e t GTLo of OTL w h i c h is of t h e s a m e e x p r e s s i v e power. At t h e e n d of s e c t i o n 4 we s t a t e o u r m a i n m a t h e m a t i c a l r e s u l t s , w h i c h s t a n d h e r e to i l l u s t r a t e t h e s u i t a b i l i t y of o u r a p p r o a c h . In s e c t i o n 5 we give a s k e t c h of o u r proofs. For t h i s we h a v e to d i s c u s s t h e r e l a t i o n s h i p between computable object transformations and various set theoretic definability concepts.

163

This s e c t i o n is m o r e of f o u n d a t i o n a l i n t e r e s t t h a n c o m p u t a t i o n a l r e l e v a n c e . It r e l a t e s c o m p u t a b i l i t y in h e r e d i t a r i l y finite s e t s over u r e t e m e n t s t o El-definability in t h e s e n s e of A. Levy [Le65]. In s e c t i o n 6 we d i s c u s s t h e d e f i n i t i o n of a b s t r a c t d a t a t y p e s in our m o d e l f r o m a c o m p l e x i t y p o i n t of view. We i n t r o d u c e a p r o g r a m m i n g l a n g u a g e of w h i l e - f r e e p r o g r a m s of w h i l e - f r e e p r o g r a m s

with t r a n s i t i v e

s p e c i f i c a t i o n l a n g u a g e s E1P a n d g r a m s in

E1P(HTC)

closure

TROTL(HTC),

respectively.

and

TNOTL, and

a s s o c i a t e w i t h it

a

Our m a i n r e s u l t s a r e t h a t all p r o -

TROTL are p o l y n o m i a l - t i m e c o m p u t a b l e a n d t h a t t h e c l a s s e s of ~lP(HTC)-defmabte c l a s s e s . O t h e r c h a r a c t e r i z a t i o n s

NP a r e e x a c t l y t h e

o b j e c t s which a r e in a r e also given. This

shows t h a t our c h o i c e of p r o g r a m m i n g a n d s p e c i f i c a t i o n c o n s t r u c t s satisfies also our c o m p l e x ity r e q u i r e m e n t s .

2. T h e s e m a n t i c

model.

The p u r p o s e of this s e c t i o n is to define finite o b j e c t s of h i g h e r o r d e r , The s i m p l e s t o b j e c t s a r e t h e u r e l e m e n t s (or a t o m s ) , w h i c h a r e all i s o m o r p h i c to e a c h o t h e r and have no e l e m e n t s . On t h e n e x t level we have finite s e t s of u r e l e m e n t s , w h i c h a r e i s o m o r p h i c if a n d only if t h e y have the same cardinality.

More c o m p l i c a t e d o b j e c t s c a n be f o r m e d by allowing o b j e c t s t o

c o n t a i n finite s e t s of b o t h u r e l e m e n t s a n d o b j e c t s of lower o r d e r . ~fore formally, we s t a r t our d e f i r i t i o n s i m i l a r as in [DMB5]. Let U d e n o t e a fixed c o u n t able set, c a l l e d t h e u n i v e r s a l d o m a i n , w h i c h is a n infinite s e t of

urelernents,

Let D c U b e

finite and nonempty, We now define inductively our objects over D: The o b j e c t s of o r d e r 0 a r e e x a c t l y t h e e l e m e n t s of D ( t h e u r e l e m e n t s ) . The o b j e c t s of o r d e r 1 a r e t h e finite s e t s of o b j e c t s of o r d e r 0 (including t h e e m p t y s e t ¢). The o b j e c t s of o r d e r n + l

a r e e x a c t l y t h e finite s e t s of o b j e c t s of o r d e r s m a l l e r or equal to n .

We d e n o t e the c o l l e c t i o n of o b j e c t s of o r d e r n by

Vn(D).

We also write

V(I))=

C) Vn(D) for t h e

n~N

c o l l e c t i o n of all o b j e c t s . Since

Vn(D ) is

an e l e m e n t of Vn+I(D) t h e c o l l e c t i o n of o b j e c t s of o r d e r

n is itself a n o b j e c t (i.e. a h e r e d i t a r i l y finite set).

V(D)

itself is n o t an object, s i n c e it is

infinite. We shall call c o l l e c t i o n s of o b j e c t s which a r e n o t o b j e c t s

classes.

(This follows t h e

tradition of axiomatic set theory adapted to finite sets.) Let h:D -,/)~ a function between two domains. W e define an extension ]~:V(D) -~ V(D $) in the following way: (i) For urelements d g V0(/))we put h(d)=h(d); (ii)For ~ c Vrn(D) we put

Two o b j e c t s h o v e r a d o m a i n D a n d A# over a d o m a i n D g a r e one a n d a n d onto m a p A:D-~D # s u c h t h a t h(h)=h#.

isomorphic

if t h e r e is a o n e -

In t r a d i t i o n a l s e t t h e o r y w i t h o u t u r e l e m e n t s two s e t s are i s o m o r p h i c iff t h e y a r e equal (by t h e i r e x t e n s i o n s ) . Once we i n t r o d u c e u r e l e m e n t s , t h i s is no l o n g e r t r u e .

164

For the complexity considerations in section 6 we need stilla stronger definition: Definition: (i) Let Ob b e a n object. We define i n d u c t i v e l y t h e subobjeets of depth n for n > 0 a naturW,

nuznber. The s u b o b j e c t s of d e p t h 1 a r e t h e s u b o h j e c t s Ob i E ~ . The s u b o b j e c t s of d e p t h n + l a r e t h e s u b o b j e e t s Ob~ w h i c h a r e e l e m e n t s of t h e s u b o b j e e t s of d e p t h n b u t w h i c h a r e n o t s u b o b ] e c t s of d e p t h n b y t h e m s e l v e s . (ii) L e t 0b b e a n o b j e c t a n d n > 0 a n a t u r a l n u m b e r . We define a m o d i f i e d o b j e c t Ob ~ n b y r e p l a c i n g d i s t i n c t s u b o b j e c t s of d e p t h n of 0b b y d i s t i n c t new u r e l e m e n t s . (iii) Let n > 0 b e a n a t u r a l n u m b e r . We s a y t h a t two o b j e c t s Obl, Ob 2 a r e n - i s o m o r p h i c if Ob i I n ~-Ob2 t n .

3. Computable

object

transformations.

Let D be a finite s e t a n d V(D) b e t h e s e t of o b j e c t s over D. A n / c - a r y o b j e c t t r a n s f o r m a t i o n is

61. . . . .

a function

T:V(D) n-~ V(D) s u c h t h a t

for e v e r y b i j e c t i o n h:D ~ D a n d

every

~ e V(D) we h a v e T ( ~ ( ~ l ) ..... ~ ( ~ ) ) = ~ ( T ( ~ I . . . . .

~))

This definition is a n a l o g o u s to t h e i s o m o r p h i s m i n v a r i a n c e of q u e r i e s in [CH80]. S i n c e all t h e e l e m e n t s of V(D) a r e finite o b j e c t s it m a k e s s e n s e to s p e a k of a " s t a n d a r d " c o d i n g of V(D) in t h e n a t u r a l n u m b e r s N. This allows u s to u s e f r e e l y t h e n o t i o n of c o m p u t a b l e

functions over V(D). An/c-ary object transformation is comput~zble

ifit is computable using the standard coding.

Examples: (i) Let & he an object and let ~61 be the object containing 6 as its only subobjeet.

The

transformation T~gb~on which m a p s 6 into ~61 is clearly a computable object transformation. (ii) Let 61, 6~ be two objects and let 6 i • 52 be the object which contains exactly the subobjects of ~i and 62 as its subobjects. The transformation T u which m a p s 61 and 62 into 6 i u ~2 is clearly a computable object transformation. (iii)Let 6i0 62 be two objects and let 61 ~62 be the object which contains exactly the subohjects of 6 i which are not in 62 as its subobjects. The transformation T~ify~rer~ which m a p s 6 i and 62 into 6i ~ 2 is clearly a computable object transformation. (iv) Let 6 be an object and let Po%u(6) be the obiect containing exactly each subset of subobjects of 6 as a subobject. The transformation T ~ r which m a p s 6 into Po%v(6) is clearly a computable object transformation. (v) Let 6 be an object and let U(6) be the object containing exactly each subobject of a subobjeet of ~ as a subobjeet. The transformation T U which m a p s 6 into U(5) is clearly a computable object transformation. (vi) Let 6 be an object and let Ur(~) be the object of order 1 containing exactly the urelements which are leaves of 6 as its subobiects, The transformation T ~ which m a p s 6 into Ur(6) is clearly a computable object transformation. (vii) (Kuratowski pair) S e t

Clearly Pair is a c o m p u t a b l e o b j e c t t r a n s f o r m a t i o n .

165

(viii) Let ~5b e a n o b j e c t a n d let HTCo(6 ) b e t h e t h e s e t of all o b j e c t s a n d r e i a t i o n s , which are in its t r a n s i ~ e

closur~ under me~nbership ( t h e h e r e d i t a r y t r a n s i t N e closure). Now we p u t HTC(~) t o be HTCo(6) u t5]. Then c l e a r l y HTC is a c o m p u t a b l e o b j e c t t r a n s f o r m a t i o n . Note that HTC p r e s e r v e s i s o m o r p h i s m s but, in c o n t r a s t to t h e p r e v i o u s e x a m p l e s , for no n > 0 d o e s it p r e s e r v e n - i s o m o r p h i s m s . (ix) We c a n u s e ~¢t as t r u t h value true a n d ¢ as t r u t h value f a l s e . This allows us to define

computable predicates as o b j e c t t r a n s f o r m a t i o n s w h o s e value a r e t~ue o r f a l s e . The collect i o n of o b j e c t s w h i c h s a t i s f y a c o m p u t a b l e p r e d i c a t e g e n e r a l l y is a class. C o m p u t a b l e p r e d i c a t e s c a n b e u s e d to define auxiliary d a t a s t r u c t u r e s s u c h as Naturalnurnbers ,lists ,stacks etc. (x) To give one e x a m p l e of a auxiliary d a t a s t r u c t u r e we shall define t h e s e t of n a t u r a l n u m b e r s with t h e i r s u c c e s s o r , following t h e c l a s s i c a l r e p r e s e n t a t i o n of (finite) ordinals a t t r i b u t e d to J.v.Neurnann. Zero is t h e e m p t y set, ]f A is a n a t u r a l n u m b e r t h e n s(A)=A u IA~ is t h e s u c c e s s o r of A. Clearly s(A) is a c o m p u t a b l e o b j e c t t r a n s f o r m atior~ The t r a d i t i o n a l d e f i n i t i o n of t h e n a t u r a l n u m b e r s is t h e s m a l l e s t class c o n t a i n i n g t h e e m p t y s e t a n d b e i n g c l o s e d u n d e r t h e s u c c e s s o r (Dedeidnd). This definition involves a fixed point. We now give a f i x e d - p o i n t - f r e e definition of t h e n a t u r a l n u m b e r s : An o b j e c t Ob is transitive if w h e n e v e r z ~ob

thenx

is a s u b s e t of Ob. Ob is c o n n e x if w h e n e v e r x , y ~ O b t h e n e i t h e r x E y , x = y

o r y E x . Ob is urelernent-free if n o m e m b e r of Ob is an u r e l e m e n t . It is folklore knowledge in s e t t h e o r y t h a t t h e o r d i n a l s a r e e x a c t l y t h e c l a s s of t r a n s i t i v e , c o n n e x a n d u r e l e m e n t - f r e e

sets. Here, the natural n u m b e r s are exactly the ordinals, since all our sets are hereditarily finite. It will follow from the Definability theorem in section 5 that the class of natural n u m b e r s is computable. W e shall discuss computable data structures in m o r e detail in section 6, The examples (i)-(v) (or slight variations thereof) will be a m o n g the basic constructs of our object transformation language DL, defined in the next section, The reader can easily find m o r e examples. As an exercise for computable predicates we suggest comparison of relations via file length, arity of relations and testing whether an object is in V~(D).

4. The object

transformation

language

OTL.

The o b j e c t t r a n s f o r m a t i o n l a n g u a g e OTL we define is e s s e n t i a l l y a p r o g r a m r r d n g l a n g u a g e c o m p u t i n g finite h i g h e r o r d e r o b j e c t s over s o m e finite d o m a i n . 4.1. L a n g u a g e d e f i n i t i o n : Syntax.

Yl,Y2 ...... are va~ables of OTL. Let Objects b e a s e t of o b j e c t n a m e s (i.e. c o n s t a n t n a m e s for e i t h e r u r e l e m e n t s , s e t s , s e t s of s e t s , ere). The s e t of t e r m s (over Objects) of OTL is i n d u c t i v e l y d e f i n e d as follows: (i) D is a t e r m of OTL; for i ~ t yi a r e t e r m s of OTL; if 0hi is a n o b j e c t n a m e t h e n 05 i is a t e r m of OTL. (ii) F o r a n y t e r m s tl, t ~ of OTL

~tl,t~l, u(tl), P(tl), s~gz(ti), (tl-t~). (tl u t2) a r e t e r m s of GTL.

166

The s e t of p r o g r a m s of OTL is i n d u c t i v e l y defined as follows: (i) If t is a t e r m of OTL t h e n yi:=t is a p r o g r a m of OTL. (ii) If P1,P~ is a p r o g r a m of OTL t h e n ( P i ; P e ) a n d w h i l e y~ do P i a r e p r o g r a m s of OTL. (iii) If P is a p r o g r a m of OTL t h e n m k o b y~ f r o m ?]~ i n y~ b y P (yl . . . . .

Y,~)

is a p r o g r a m of OTL. The v a r i a b l e y j o c c u r s h e r e as a bounded v a r i a b l e s i m i l a r to j in ~ a ~ . J

4.2. L a n g u a g e d e f i n i t i o n : S e m a n t l c s . Let D b e a finite set of u r e l e m e n t s a n d V(D) b e t h e class of o b j e c t s over D. (i) Let z b e a f u n c t i o n f r o m t h e v a r i a b l e s Yl,Y2, ' " ' into V(D), t h e s e t of o b j e c t s o v e r D. We call s u c h a f u n c t i o n a object a s s i g n m e n t

over D or a s s i g n m e n t for short. We t h i n k of t h e s e t

of all o b j e c t a s s i g n m e n t s over D as t h e s e t of states for our o b j e c t t r a n s f o r m a t i o n . We d e n o t e t h i s s e t b y Sta2es(D). (ii) The meaning

of

a

fz(P):States (D) ~ States (D). F i r s t we define for e v e r y

program term

P t

acting

of

OTL

on

D

inductively

is

a the

partial

function

meaning

function

~o(t ):States (D) -~ V(D) in the following way:

~(D)(~)=~=:= c DI,

~(~)(z)=~(y~), Let t I a n d t~ b e t e r m s in OTL. T h e n for e a c h z E States (D):

(1) ~ ( ~ ~,~I)(~ )= l~(t ~)(~ ),~(t ~)(~ )I, (3) rot ~ ( s ( t , ) ( ~ )we distinguish three cases: (3i) If all s u b o b j e c t s of # o ( t l ) ( z ) a r e d i f f e r e n t f r o m u r e l e m e n t s t h e n we s e t p ~ ( U ( t i ) ( z ) =

u(~(t,))(~,); (3ii) If p.0(ti)(z) has at least two subobjects we take the union as in (3i) treating its subobjeets which are urelements as e m p t y sets. (3iii) If/z0(t 1)(z) h a s e x a c t l y one s u b o b j e et w h i c h is a n u r e l e m e n t UT t h e n ~z0(U(t i ) ( z ) = Ur.

RemaTlc: It does n o t r e a l l y m a t t e r how we h a n d l e t h e " f r e a k " cases, a n d a n y o t h e r " r e a s o n a b l e " way of doing it will n o t affect our r e s u l t s . (4) p ~ ( t i O t 2 ) ( z ) = / ~ o ( t i ) ( z ) u p ~ ( f 2 ) ( z ) . tf /z0(ti)(z) or /Zo(t~)(z) is a n u r e l e m e n t

then

p o ( t i v t ~ ) ( z ) is empty.

(5) ~ ( t , - t~)(~ )= ~ ( t ,)(z ) - ~ ( t ~)(~ ) H e r e X - Y is t h e s e t of all e l e m e n t s of X n o t b e i n g in Y. (S) p~(S~ngZ(t l ) ) ( z ) = l l x l : z E ~ 0 ( t D ( z ) I Next we define for e v e r y p r o g r a m P E GTL i n d u c t i v e l y t h e m e a n i n g f u n c t i o n / ~ ( F ) in t h e following way=. (a) ]f P is of t h e form y~:=t t h e n we p u t / z ( P ) ( z ) ( y i ) = z (!ti) if j # i

and/~(P)(z)(y~)=/zo(t)(z)

otherwise. (b) If P is Pi;P2 t h e n / z ( P ) ( z ) = / ~ ( P ~ ) ( / ~ ( P i ) ( Z ) ) . This is t h e u s u a l c o m p o s i t i o n of f u n c t i o n s . (e) If P is while yj do Pi then ~(P)(z) is defined in the usual way on a sequence of states zi+i=~(Pi)(zi) with z0=z. Iz(P)(z) is the first z~ such that z~(yi) is not an e m p t y relation or object. (d) I f P i s m k o b

y~ f r o m yj i n y ~ b y P l ( Y i . . . . .

y,n) t h e n

167

I.z(P)(z)(yi)= Ila,(P1)(zl)(yj):Zl(y~)=z(yt) for l ~ j

~,(u,)=z(y,)

for z ~ j

and

and z l ( y j ) E z ( y ~ ) l, if for all zl, s.t is defined, o t h e ~ i s e ~(P)(~)(y~) i~

=,(y~)c z(y~) ~(P~)(z~)(yj)

undefined. ]n words tl/s says, for the case ~r~=]=l, that the n e w object y~ ~s obtained in the following way: one applies in :Daru//el to all the subobjects yi of y~ the p r o g r a m PI and puts in to y~ all the results so obtained.

If j>rn the n e w object contains exactly one subobject cf the f o r m

~(Y~ ..... Ym)- Otherwise, t h e objects y~ ..... Yi-l,Yi+~ .... a r e free p a r a m e t e r s . R e m e m b e r t h a t Yi occurs here as a bounded variable, The reader acquainted with axiomatic set theory will easily r e c o g n i z e in this d e f n / t l o n the replacernen~ axiom of Ze~wzelo-2~ran]cel se~ theory. 4.3. Main results. Let 0b I.....Ob~ be/c given objects and let z i ~

be the assignment with zm~a~(y~)=Ob~ for

Given a p r o g r a m P(Yl ..... Yn) ~ OTL end a ve~riable y]

all £k.

we look at the function T2j: V(D) ~ -~ V(D) Tpj( Ob I..... Ob~)=]~(P)(zi~a~)(yj). Theorem

(Computability of OTL-programs): For every p r o g r a m P 6 0 T L

and each vari-

able yj the the function Tpj: V(D) ;~ -* V(D) is a computable object transformation. Proof." For programs of the form yi:=t this follows from the examples (i)-(iv) of section 3. For P of the form PI;P2 or while Yi do PI this follows from the closure properties of partial recursive functions.

For the mkob-eonstruct this follows from the following closure property

of partial recursive functions: Let

f

be

a

partial

reeursive

(it). (ii) -> (i) is trivial. (i) -> (ifi): A s s u m e A is r e c o g n i z e d b y a Turing n m c h i n e P. T h e n 6 E A iff

there is a correct coding of ~ a n d there is a P- comp'u2ation on th~ coding giving a positive a n s w e r . Codings o n Turing m a c h i n e s a n d c o m p u t a t i o n s c a n b e c o d e d as s e t s in V(D), prov i d e d t h a t A is i s o m o r p h i s m i n v a r i a n t . H e n c e we g e t a ~ l - f o r m u l a e x p r e s s i n g A. (iii) - > (it): We w a n t t o p r o v e t h a t e a c h SfMAl-expressible s u b s e t of V(D) is r e c o g n i z a b l e b y a p r o g r a m in OTL. At first we c a n p r o v e t h a t e is d e c i d a b l e b y a OTL-pragrarn( x c y iff

~x~ u y ~ ¢. Cairn:if P is a p r e d i c a t e , d e c i d a b l e b y a OTL-program t h e n also ( 3 x e y ) P . This c l a i m c a n b e p r o v e d b y t h e following cornprehension scheme in OTL: Given a c o m p u t a b l e p r e d i c a t e P in OTL, t h e n t h e f u n c t i o n G w h i c h m a p s e a c h o b j e c t 5 to t h e set of its subobjects 51, s.t. P(&I) is expressible in OTL. To see this we observe: (i) Let H he the function which m a p s each 51 to its singleton if P(tl) and to the e m p t y set otherwise. H is obviously expressible in OTL if P is in OTL.

(ii) U(~H(~I):~, e &~ is the set G(~). F r o m this comprehension

s c h e m e it follows easily that each ~0-predieate is decidable by a

OTL -progranl. N o w we have to consider a 7.i formula ~ z~. We get a computable object transformation which computes for each for each natural n u m b e r Ic the set V~(D)TWe only have to write a

OTL-program which computes the smallest V~(D), which has an z satisfying %#. The class of natural n u m b e r s is computable in OTL since it is ~0-definable as one can see by looking again at example (x) of section 3. }'roof of the Independence Theorem: The proof of the independence of the constructs of OTL 0 is always based on variations of the s a m e idea: Omitting a construct adds to the resulting sublanguage a closure property which does not hold for OTLo. For example, to show that the c o m p l e m e n t observe that complement-free programs c o m m u t e

with h o m o m o r p h i e

- is needed we

images of the domain.

The least non-trivial result here is the necessity of the nlkob-construct. Our proof uses the fact that we do not have the full power set operation a m o n g

our basic constructs. The full

power set, however, can be obtained using nlkob and construct of unordered pairs ~,I. To see that the construct of unordered pairs l,I cannot be omitted we observe that without it the class of constant terms has the following property: Given an interpretation of a constant t e r m then all its elements are isomorphic.

6. P o l y n o m J a l l y

recognizable

classes

and abstract

data

types.

In t h i s s e c t i o n we w a n t t o d e s c r i b e t h e m e c h a n i s m i n h e r e n t in SETL-like l a n g u a g e s f o r t h e s p e c i f i c a t i o n of a b s t r a c t d a t a types. B e f o r e we p r e s e n t t h e r e a d e r with a f o r m a l definition we w a n t t o d i s c u s s a m o t i v a t i n g e x a m p l e . A s s u m e we w a n t to i n t r o d u c e a new d a t a t y p e GRAPH(D) of flnnite u n d i r e c t e d g r a p h s w i t h a b o u n d e d n u m b e r of u n s p e c i f i e d v e r t i c e s . F o r t h i s p u r p o s e we t h i n k of t h e v e r t i c e s as u r e l e m e n t s a n d t h e e d g e s as u n o r d e r e d p a i r s of v e r t i c e s . The c l a s s o f g r a p h s GEAPH(D) t h e n c o n s i s t s of all o b j e c t s of t h e f o r m w h e r e V is a s u b s e t of b ( t h e u r e l e m e n t s ) a n d E is a

170

subset of the unordered pairs of V (denoted by [ V]~). If we want to look at the class of n u m b e r e d graphs N G R A P H we would require additionally that V is an initialsegment of the class N A T of natural numbers, as introduced in example (x) of section 2. It is easy to verify that data types defined in this way have the property that their objects are polynomially recognizable. The s a m e holds for all the other c o m m o n

data types such as

LISTS, STACKS, TREES, etc. The purpose of this section is to define a specification language for data types recognizable non-deterministically in polynomial time. Let C be a class of objects. W e shall write C is in P (C is in NP) if C is recognizable (non-deterministicaily) in polynomial time. Here the size of an object is given by the n u m b e r of elements in its transitive closure HTC. First w e observe the following: Proposition: Let C be a class of objects which is Y,0-deflnable, i.e. there is a Y.0-formula ~(x) such that C is the collection of objects satisfying g. Then C is in P and there is a natural n u m b e r 7/>0 such that C is closed under ~z-isomorphisms. To characterize the classes of objects in N P we define the while-free terms of OTL 0 and denote t h e m by TRO?7, (terms and replacement of OTL). (i) The terms of

OTLoare in TROTL.

(2) If tl,~2 are terms of TROTL and Yi is a variable then M K O B ( ~ I t~,%/~)is a term of TROTL. The semantics of TROTL is defined as for OTto with the di~erenee that M K O B

s a term

construct replacing mkob. The interpretation of M K O B ( t I tz,yj) is the object interpreting !/i in

mkoby,~ f r o m y i int2 by tl. W e also define the set of terms TROTL(HTC) which is obtained from TROTL by closing it under the operation H T C as defined in example (viii)of section 3. Proposition: Every term in TROTL (IITC) represents a polynomial time computable object transformation. W e next define the specificaion im-lguage ~0 P and zoP(HTC). (I) If tl,t2 are terms of TROTL (TROTL(HTC)) then tl E t 2 and it=t2 are formulas of Y,0P.

(ZoP(HTC) ). (2) If ~ and ~ are formulas of E0 P (EoP(HTC)), then also g A~p,g V %, ~

are formulas of Z0 P

(ZJ(,~TC)). (3)

If t , is a t e r m

TROTL (TROTL(HTC)) a n d ~ is a f o r m u l a of ~oP (Y.oP(HTC)). of E 0 P - f o r m u l a s a n d EoP(HTC)-formulas is obvious. of

20 P

(EoP(HTC)), t h e n

~[ Yi E ~1~ is a l s o a f o r m u l a of The s e m a n t i c s Proposition: (i) E v e r y c l a s s C d e f i n a b l e in

EoP(HTC) is

i n P.

(ii) T h e r e a r e c l a s s e s C in P w h i c h a r e n o t ZoP(HTC)-definable. (iii) F o r e v e r y c l a s s C d e f i n a b l e in E0P t h e r e is a n a t u r a l n u m b e r n > 0 s u c h t h a t C is c l o s e d under n-isomorphisms.

Proof:

(i) is o b v i o u s a n d (ii) c a n b e p r o v e d in a s i m i l a r w a y a s t h e s t a t e m e n t

in [CH82]

t h a t t h e r e a r e p o l y n o m i a l t i m e q u e r i e s w h i c h a r e n o t f i r s t o r d e r d e f i n a b l e . To s e e (iii) we

171 o b s e r v e t h a t t h e r~ is d e t e r m i n e d by t h e n u m b e r of b o u n d e d q u a n t i f i e r s o c c u r r i n g in t h e form u l a defining C.

PuP(HTC)-formulas:

Next we define t h e s e t of Z i P - f o r m u l a s a n d

(i) All~oP-formulas (E)

(goP ( HTC)-formulas) are

RiP-formulas

(giP (f~TC)-formulas).

If t I is a t e r m of TROTL (TROTL(HTC)) a n d ~ is a f o r m u l a of y~ C t,~0is also a formula of ~iP (PuP(HTC)).

E1P (YI,tP(HTC)),

then

T h e o r e m (Characterization of NP-recognizable classes): Let C be a class of objects which is closed under isomorphisms. (i) Then C is in N P iff C is

1P(HTC)-definable. (ii) C iS ZiP-deflnabIe iff there is a natural number n > 0 such that C is closed under nisomorphisms and C is in NP. Proef: The proof is a simple modification of Fagin's characterization of NP-recognizable classes of finite first order structures [FaY4]. Here it is essential that objects 0b are always represented by their transitive closure HTC(Ob ). This last theorem suggests that ZIP and

P.IP(IITC) are very reasonable specification

languages for abstract data types. The class N P arises naturally here since we have no order on the urelements. Characterizations of lower complexity classes as in [Im83] always require s o m e auxiliary predicates. Problem: Find a rz=tlzra/ehofee of basic constructs which allows to characterize the lower complexity classes such as logarithmic space and polynomial time.

7. R e f e r e n c e s .

[Ba75]

J.K.Barwise, A d m i s s i b l e s e t s a n d s t r u c t u r e s , Springer, Berlin 1975.

[CH80]

A.K.Chandra a n d D.Harel, C o m p u t a b l e q u e r i e s for r e l a t i o n a l d a t a b a s e s , JCSS voL 21.~ (1980) pp. 156-178.

[cH82]

A.K.Chandra and D.Harel, Structure and complexity of relational queries, JCSS voL 25, (1982) pp. 99-128.

[DM85]

E. Dahlhaus and J.A.Makowsky, Computable Directory Queries, Technical report of the Institut fuer Informat[k, ETH-Zuerich, No. 85 (September 1985), extended abstract to appear in the Proceedings of CAAP '86, LNCS, Springer, Berlin 1986.

[Fa74]

R_ Fagin, Generalized first order spectra and polynomial-time recognizable sets, in: Complexity of Computation, R.Karp ed., SIA_M-AMS Proceedings no. 7 (1974) p.27-41.

[FeSO] [GaSO]

J.E. Fenstad, General Reeursion Theory, Springer, Heidelberg 1980.

[Ho8a]

E. Horowftz, Fundamentals of programming languages, Computer Science Press, Rockville 1983.

[HP84]

D. Hare[ and D. Peleg, On static logics, dynamic logics and complexity classes, Information and Control voL 60, (1984) p. 86-I0~.

R. Candy, Church's Thesis and principles for mechanisms, in: The Kleene Symposium, J.Bar-~se et al. eds., Amsterdam 1980, pp.123-148.

172

[]m8~]

N. Immerman, Relational queries computable in polynomial time, 14th A C M Symposium on Theory of Computing, (1982) p. 147-152.

[Im83]

N. Immerman, Languages which capture complexity classes, 15th A C M Symposium on Theory of Computing, (1983) p. 347-354.

[he85]

A, Levy, A h i e r a r c h y of formulas in set theory, Memoirs of the American Mathemati-

[MoV4]

Y.N. Moschovakis, Elementary Amsterdam 1974.

[Mo80] [Mo84]

Y.N. Moschovakis, Descriptive set theory, North Holland, Amsterdam 1980.

cal Society 57, Providence 1965.

induction on abstract structures, North Holland,

Y.N. Moschovakis, Abstract recurs[on as a foundation for the theory of algorithms, in: Computation and Proof Theory, M.M.P~ichter et al. eds. L N M vol. 1104, Springer, Berlin-Heidelberg 1984, p. 289-362.

[No78]

D. Normann, Set recursion, in: Generalized recurs[on theory If, J.E. Fenstad et al. eds., North Holland, A m s t e r d a m 1978, p. 303-320,

[sss79]

E. Schonberg, J.T. Schwartz and M. Sharir, Automatic data structure selection in SETL, 6. Annual A C M Symposium on Principles of Programming Languages (1979) pp. 197-210.

[Sch75] [Sh79]

LT. Schwartz, On progranlnling: An interim report on fihe SETL project, 2nd ed., Courant Institute of Mathematical Sciences, N e w York 1975.J.C. Shepherdson, Computations over abstract structures, in: Logic Colloquium '73, H.E. Rose at aL eds., North Holland, Amsterdam 1973, p.445-513.

Suggest Documents