querying clocked databases

14
Querying Clocked Databases Mehmet A. Orgun and Chuchang Liu Department of Computing, Macquarie University, NSW 2109, Australia Information Technology Division, Defence Science and Technology Organisation, PO Box 1500, Salisbury, SA 5108, Australia Abstract. We propose a temporal extension of Datalog which can be used to model and query temporal databases with relations based on multiple clocks. The extension, called Clocked Temporal Datalog, is based on a clocked temporal logic in which each predicate and hence each formula can be assigned a separate clock. A Clocked Temporal Datalog program consists of three parts: (1) a clock definition, (2) a clock assignment, and (3) a program body. The clock definition specifies all the available clocks. The clock assignment assigns to each predicate defined in the program body a clock from the clock definition. The meaning of the program body naturally depends on the provided clock definition and assign- ment. Therefore a Clocked Temporal Datalog program models intensionally a clocked database in which each relation is defined over a clock. Programmable clock definitions are very flexible in specifying periodic as well as some non- periodic clocks, and in specifying relationships between clocks on the fly. 1 Introduction While there is not a wealth of reported research on deductive database systems for temporal data, temporal databases based on the relational model have been extensively studied in the literature. A comprehensive survey of temporal query languages is pro- vided by Chomicki [5]. The recent status of research in temporal databases is summa- rized in ¨ Ozsoyo˘ glu and Snodgrass [17]. Temporal extensions based on logic program- ming are considered by Chomicki and Imieli´ nski [6], Chomicki [4], Baudinet et al [2] and B¨ ohlen and Marti [3]. These proposals are concerned with modeling and querying infinite temporal data in logic languages (such as extensions of DATALOG) in which predicates are extended with explicit time parameters. A temporal extension of Datalog is considered by Orgun [15], based on the function-free subset of the temporal language Chronolog [16]. These languages are not designed to deal with multiple granularities and/or multiple clocks. However, they make the representation of infinite temporal in- formation possible and often enable a more compact representation of finite informa- tion. They also improve the expressivity of query languages for temporal data. One important issue is that the relations in a temporal database are not necessarily defined on the same granularity of time. Some events occur at irregular intervals, and it seems unnatural to force them all onto a prescribed notion of time. Doing so would lead to semantic mismatches [9, 10]. Ladkin [10] recognized that distinct granularities cannot be mixed, and developed an algebra where the granularity of the source time- stamps is considered. Wiederhold, Jajodia and Litwin [20] also recognized the prob- lem, and provided an algebra in which data with multiple granularities are converted

Upload: mq

Post on 15-Nov-2023

0 views

Category:

Documents


0 download

TRANSCRIPT

Querying Clocked Databases

Mehmet A. Orgun1 and Chuchang Liu21 Department of Computing, Macquarie University, NSW 2109, Australia2 Information Technology Division, Defence Science and Technology Organisation, PO Box1500, Salisbury, SA 5108, Australia

Abstract. We propose a temporal extension of Datalog which can be used tomodel and query temporal databases with relations based on multiple clocks.The extension, called Clocked Temporal Datalog, is based ona clocked temporallogic in which each predicate and hence each formula can be assigned a separateclock. A Clocked Temporal Datalog program consists of threeparts: (1) a clockdefinition, (2) a clock assignment, and (3) a program body. The clock definitionspecifies all the available clocks. The clock assignment assigns to each predicatedefined in the program body a clock from the clock definition. The meaning ofthe program body naturally depends on the provided clock definition and assign-ment. Therefore a Clocked Temporal Datalog program models intensionally aclocked database in which each relation is defined over a clock. Programmableclock definitions are very flexible in specifying periodic aswell as some non-periodic clocks, and in specifying relationships between clocks on the fly.

1 Introduction

While there is not a wealth of reported research on deductive database systemsfortemporal data, temporal databases based on the relational model have been extensivelystudied in the literature. A comprehensive survey of temporal query languages is pro-vided by Chomicki [5]. The recent status of research in temporal databases is summa-rized inOzsoyoglu and Snodgrass [17]. Temporal extensions based on logic program-ming are considered by Chomicki and Imielinski [6], Chomicki [4], Baudinet et al [2]and Bohlen and Marti [3]. These proposals are concerned with modeling and queryinginfinite temporal data in logic languages (such as extensions of DATALOG) in whichpredicates are extended with explicit time parameters. A temporal extensionof Datalogis considered by Orgun [15], based on the function-free subset of the temporal languageChronolog [16]. These languages are not designed to deal with multiplegranularitiesand/or multiple clocks. However, they make the representation of infinite temporal in-formation possible and often enable a more compact representation of finite informa-tion. They also improve the expressivity of query languages for temporal data.

One important issue is that the relations in a temporal database are not necessarilydefined on the same granularity of time. Some events occur at irregular intervals, andit seems unnatural to force them all onto a prescribed notion of time. Doing so wouldlead to semantic mismatches [9, 10]. Ladkin [10] recognized that distinct granularitiescannot be mixed, and developed an algebra where the granularity of the source time-stamps is considered. Wiederhold, Jajodia and Litwin [20] also recognizedthe prob-lem, and provided an algebra in which data with multiple granularities areconverted

to a uniform model of data based on time intervals. Gagne and Plaice [9] propose anon-standard temporal deductive database system in which time is modeled by pairs ofnumbershr; ni wherer is a real number andn is an integer. Their model is based on adense model of time rather than a discrete model, and it is not clear how it can be used inpractice. Dyreson and Snodgrass [7] extended SQL-92 to support mixed granularitieswith respect to a granularity lattice. There are also some other recent works extend-ing the relational model and algebra to deal with multiple granularities,for instance,another calendar-based approach is proposed by Lee et al [11].

In this paper, we first propose a model for clocked databases in which relationsare defined over multiple time-lines or more precisely, multiple histories. We then con-sider a deductive system for clocked databases, featuring a clocked temporal extensionof Datalog. Clocked Temporal Datalog is based on TLC [12], a temporal logicwhichcan be used to model predicates defined over multiple clocks. In TLC, each predicateand hence each formula can be assigned a clock which is a subsequence of a discretetime-line modeled by the sequence of natural numbers. In TLC, a calendar-dependentpartitioning of the time-line is not assumed, and hence granularity conversion operatorsare not required. Our approach is therefore more restrictive in modelling granularitythan some others reported in the literature, however, it does not require a predeterminedgranularity lattice, it involves programmable clock definitions, and it is grounded intemporal logic. Temporal logic [19] provides a clean framework in which the temporalproperties of certain applications such as temporal databases can be formalized, studied,and then generalized and applied to other application domains. Clocked Temporal Dat-alog can also be used as a deductive front-end to clocked databases to enhance the ex-pressivity of their query languages. Through programmable clock definitions, temporaldata in a clocked database can also be viewed and summarized at different granularities.

There are also other approaches to temporal databases based on temporal logic.For instance, Orgun [14] proposed a temporal algebra, with algebraic counterparts oftemporal operatorsfirst, next andfby, which also includes temporal aggregationoperators. Tuzhilin and Clifford [18] proposed a temporal algebra (calledTA ) as a basisfor temporal relational completeness. The algebra is equivalent in expressive power toa temporal calculus based on a temporal logic with temporal operatorssinceanduntil .Gabbay and McBrien’s [8] considered a refinement ofTA which is also based on atemporal logic withsince and until . They introduce two linear recursive operators,namely,since-product(S�) anduntil-product(U�). These operators closely resembletheir counterparts in temporal logic. We do not consider these operators in ClockedTemporal Datalog because their properties in a logic programming settinghave notbeen studied yet. Also, they do not have a straightforward operationalsemantics.

This paper is structured as follows. Section 2 proposes a model for clockeddatabases.Section 3 gives an introduction to TLC, including its clock calculus, syntax and seman-tics. Section 4 introduces Clocked Temporal Datalog. Section 5 presents the declarativesemantics of Clocked Temporal Datalog programs and establishes the connectionbe-tween clocked databases and programs.

2 A Model for Clocked Databases

A clocked database consists of three components: (1) a set of relation symbols, (2) aclock assignment, and (3) a relation mapping. The clock assignment assignsa clock(a subsequence of an assumed discrete time-line) to each relation symbol; therelationmapping assigns to each relation symbol a clocked relation defined over its clock. Inthe following, we denote the set of natural numbersf0; 1; 2; 3; : : :g by!.

Definition 1 (Clocks). A clock is a strictly increasing sequence of natural numbers.The global clockgc is the sequence of natural numbers:h0; 1; 2; 3; : : :i. The emptyclock is the empty sequence:h i.

Let ck be a clock. We writet 2 ck if t occurs inck (t is a moment on clockck). Forany given clockck, the notationck(i) denotes the ith element onck.

We now define an ordering relation on clocks as follows.

Definition 2 (v). For any given clocksck1 and ck2, we write ck1 v ck2 if for allt 2 ck1, we havet 2 ck2. If ck1 v ck2 then we also say thatck1 is a sub-clock ofck2.

It can be shown that the set of clocks, denoted byCK, with the orderingv, isa complete lattice in which the global clock is the maximum element and the emptyclock is the minimum element. Note thatCK contains uncountably many clocks, all ofwhich are conceivably available to the user. We do not provide a calendar-dependentpartitioning of the time-line at this stage. The only structure available inCK is providedby the orderingv. In particular, ifck1 v ck2 for clocksck1 andck2, we say thatck2has a finer granularity thanck1.

We now define two operations on clocks that correspond to the greatest lowerbound(g.l.b) and least upper bound (l.u.b.) of clocks with respect tov. The least upper boundof two given clocks can be obtained by merging them; the greatest lower boundcan beobtained by taking the common moments in them.

Definition 3 (u;t). Letck1; ck2 2 CK. We define two operations on clocks as follows:ck1 u ck2 � g:l:b:fck1; ck2g andck1 t ck2 � l:u:b:fck1; ck2g.LetD be a domain of values of interest. Here we are not concerned with the actual

type of each domain element, but the model can be easily extended to include types ofelements. LetDn denote then-folded Cartesian product ofD, andP (Dn) the set of allsubsets ofDn. We denote the set of all functions from setX to setY by [X ! Y ].Definition 4 (Clocked relations).Let ck 2 CK. A clocked relation with arityn is amap fromck toP (Dn). The set of clocked relations is denoted by[n2! [ck2CK [ck !P (Dn)].

LetR be the set of relation symbols we are allowed to have in a clocked database. Aclock assignment tells us those times at which each relation symbol has a definedvalue(let it be the empty relation or a non-empty relation). Note that we alsowrite r=n for arelation symbolr with arity n.

Definition 5. A clock assignment� is a map fromR to CK, that is,� 2 [R ! CK].The clock associated with a relation symbolr=n 2 R over� is denoted by�(r=n).

Definition 6 (Clocked database).Let R be a set of relation symbols, and� a clockassignment. A clocked databaseDB is a triple hR;�; �i where� assigns a clockedrelation over�(r=n) to all r=n 2 R.

We write �(r=n) to denote the clocked relation which is assigned tor=n by �;�(r=n) is in fact a map from�(r=n) toP (Dn). Intuitively,� tells us when a particularrelation symbol has a defined value, while� tells us the value associated with a relationsymbol whenever it is defined.

3 Temporal Logic with Clocks

To make the paper relatively self-contained, we give an introduction to the syntax andsemantics of TLC. Most of the material presented in this section is from [12] with somemodifications to extend TLC with temporal operatorfby.

In the vocabulary of TLC, apart from variables, constants and predicate symbols, wealso have propositional connectives::, _ and^, universal quantifier:8, three temporaloperators: unaryfirst andnext, and binaryfby, and punctuation symbols: “(” and“)”. In TLC, the definition of terms is as usual. The other connectives!, $ and thequantifier9 can be derived from the primitive connectives and universal quantifier asusual.

The intuitive meaning of the temporal operators is as follows: (1)first A: A istrue at the initial moment in time, (2)next A: A is true at the next moment in time,and (3)A fby B: A is true at the initial moment in time and from then onB is true.It should be kept in mind that these readings are relative to the given formula clocks(see below). We writenext[n] for n successive applications ofnext. If n = 0, thennext[n] is the empty string.

3.1 Clock calculus

Just like in a clocked database, we use a clock assignment to assign a clock to eachpredicate symbol. Formally, we have the following definition:

Definition 7. A clock assignment� is a map from the setSP of predicate symbols tothe setCK of clocks, that is,� 2 [SP ! CK]. The notation�(p ) denotes the clockwhich is associated with a predicate symbolp on�.

We extend the notion of a clock to formulas as follows:

Definition 8. LetA be a formula and� a clock assignment. The clock associated withA, denoted as��(A), is defined inductively as follows:

- If A is an atomic formulap(e1; : : : ; en), then��(A) = �(p).- If A = :B, firstB, (8x)B or (9x)B then��(A) = ��(B).- If A = B ^ C, B _ C, B ! C or B $ C, then��(A) = ��(B) u ��(C).- If A = nextB, then (1)��(A) = ht0; t1; : : : ; tn�1iwhen��(B) = ht0; t1; : : : ; tni

is non-empty and finite; (2)��(A) = ��(B) when��(B) is infinite or empty.

- If A = B fby C, then��(A) = hb0; ck; ck+1; ck+2; : : :iwhere��(B) = hb0; b1; : : :iand��(C) = hc0; c1; : : : ; ck�1; ck; ck+1; ck+2; : : :i andck�1 � b0 < ck for somek � 0.

Theu�rule says that the corresponding formulas will have a defined value at aparticular moment in time only if that time occurs in the clocks of all sub-formulas init. Note that the above clock calculus is an extension of the one given in [12] to dealwith fby.

We now define the rank of a moment on a given clock.

Definition 9. Given a clockck = ht0; t1; t2; : : :i we define the rank oftn on ck to ben, written asrank(tn; ck) = n. Inversely, we writetn = ck(n), which means thattn isthe moment in time onck whose rank isn.

The following definitions will be very useful in developing the declarative semanticsof Clocked Temporal Datalog programs.

Definition 10. Temporal atoms are defined inductively as follows:

- Any atomic formula is a temporal atom.- If A is a temporal atom then so arefirst A andnext A.

Definition 11. A temporal atom is fixed-time if it has an application offirst followedby a number of applications ofnext; otherwise it is open. A formula is fixed-time if allatoms contained in it are fixed-time; otherwise it is open.

3.2 Semantics

LetB = h ffalse; trueg;�i denote a Boolean algebra of truth values with the orderingfalse � true and the following standard operations:

- comp = ftrue 7! false; false 7! trueg (complementation),- X � Y = the g.l.b. offX;Y g with respect to�,- X+Y = the l.u.b. offX;Y g with respect to�.

In TLC, at a given timet 2 !, the value of a formula can betrue, false or un-defined, depending on the clocks of predicate symbols appearing in it. We donot havea representation for undefined values, rather we use partial mappings. The meaning ofa predicate symbolp is actually a clocked relation, i.e., a partial mapping from! toP (Dn) wheren is the arity ofp andD is the domain of discourse. For anyt 2 �(p),the image is naturally defined.

A temporal interpretation together with a clock assignment assigns meanings to allthe basic elements ofTLC.

Definition 12. A temporal interpretationI on a given clock assignment� of TLCcomprises a non-empty setD, called the domain of the interpretation, over which thevariables range, together with for each variable, an element ofD; for each term anelement ofD; and for each n-ary predicate symbolp=n, a clocked relation of�(p=n)!P (Dn).

We denote the clocked relation represented byp=n on I over� by I(p=n). To referto the value ofp=n at a particular moment in time, we use the notationI(p=n)(t).

In the following, the notation[[A]]t�;I is used to denote the value ofA under inter-pretationI on clock assignment� at momentt.Definition 13. Let I be a temporal interpretation on a given clock assignment� ofTLC. For any formulaA of TLC, [[A]]t�;I def= [[A]]t��(A);I whenevert 2 ��(A). The

function[[A]]t�;I is defined inductively as follows:

(1) If e is a term, then[[e]]t�;I = I(e) 2 D.(2) For any n-ary predicate symbolp=n and termse1; : : : ; en,[[p=n(e1; : : : ; en)]]t��(p=n(e1;:::;en));I = true if h [[e1]]t�;I ; : : : ; [[en]]t�;I i 2 I(p=n)(t);false otherwise.(3) For any formula of the form:A, [[:A]]t��(:A);I = comp([[A]]t��(A);I).(4) For any formula of the formA ^B, [[A^B]]t��(A^B);I = [[A]]t��(A);I� [[B]]t��(B);I .

(5) For any formula of the formA _ B, [[A_B]]t��(A_B);I = [[A]]t��(A);I+[[B]]t��(B);I .

(6) For any formula of the form(8x)A, [[(8x)A]]t��((8x)A);I = true if [[A]]t��(A);I[d=x] =true for all d 2 D where the interpretationI [d=x] is just likeI except that thevariblex is assigned the valued in I [d=x]; false otherwise.

(7) For any formula of the formfirst A, [[first A]]t��(first A);I = [[A]]s��(A);Iwheres = ��(first A)(0).

(8) For any formula of the formnext A, [[nextA]]t��(next A);I = [[A]]s��(A);Iwheres = ��(next A)(n+1) andn = rank(t; ��(next A)).

(9) For any formula of the formA fby B, [[A fby B]]t��(A fby B);I = [[A]]t��(A);Iif rank(t; ��(A fby B)) = 0; otherwise,[[A fby B]]t��(A fby B);I = [[B]]s��(B);Iwheres = ��(B)(n�1) andn = rank(t; ��(A fby B)).Let j=I;� A denote the fact thatA is true underI on clock assignment�, in other

words,[[A]]t�;I = [[A]]t��(A);I = true for all t 2 ��(A). We also use the notationj=� Ato denote the fact thatj=I;� A for any temporal interpretationI over clock assignment�. In particular, if j=I;� A, then we say that the temporal interpretationI on � is amodel of the formulaA and usej= A to denote the fact that for any interpretationI andany clock assignment� we havej=I;� A.

Axioms and rules of inference of TLC can be found in [12]. The version ofTLC pre-sented in this paper would have additional axioms and rules to formalize the temporaloperatorfby.

4 Clocked Temporal Datalog

A Clocked Temporal Datalog program consists of three components:P = Pc 1 Pa 1Pb wherePc, Pa andPb are the clock definition, the clock assignment and the programbody of the programP . The symbol1 means “jointing”, that is,Pc, Pa andPb jointlyform the programP . The main point is that the clock assignment� of Pb is totallydetermined byPc andPa.

The formal definition of program clauses is given below. We assume that somebuiltin Prolog predicates are also available in Clocked Temporal Datalog (e.g., theispredicate).

Definition 14 (Temporal units).

- A temporal atom is a temporal unit.- If A1; : : : ; Am and B1; : : : ; Bn (for m;n � 1) are temporal units, then so is(A1; : : : ; Am) fby (B1; : : : ; Bn).

Definition 15 (Program clauses).

- A program clause inPc and Pb is of the formA <- B1; : : : ; Bn whereA is atemporal atom and allBi’s are temporal units. Ifn = 0, then the program clauseis also called a fact.

- A program clause inPa is of the formassign(p/n, cki) wherep=n is a pred-icate symbol defined inPb and cki is a predicate symbol with arity 1 defined inPc.All the predicates inPc are assumed to be defined on the global clockgc. It should

be noted thatPc, except for temporal operatorfby, is just like a program of Chronolog[16], a temporal logic programming language with temporal operatorsfirst andnext only. SincePc is a program, the definition of eachcki in general may or may not“represent” an actual clock. To ensure that it does, we stipulate that eachcki satisfy thefollowing clock constraints:

Definition 16 (clock constraints [12]).

- For any successful queryfirst next(m) cki(X), we have thatm � X.- For any pair of successful queriesfirst next(m) cki(X) andfirst next(m)cki(Y), we have thatX = Y.

- For any pair of successful queriesfirst next(m) cki(X) andfirst next(n)cki(Y), if m < n, then X < Y.

The first constraint says that the rank of a moment on a clock is not greater than themoment. The last two constraints ensure that clocks are linear and monotonic. Whenthe second constraint is relaxed, we may have branching time. The main motivation forthe first constraint is computational.Pa is a Prolog program, which assigns clocks for all the predicate symbols in theprogram body. A clause such asassign(p/n,cki) in Pa says thatcki is the clockassociated with the predicate symbolp=n defined inPb.

We now give an example Clocked Temporal Datalog program. Suppose that thereis a library which only holds books. Book acquisitions are dealt withat the end of eachweek. We may define the following predicates (among others):

stock(X): bookX is in stock.acquisition(X): bookX has been acquired by the library.onloan(X): bookX in on loan.

In the following program, the clock definition defines two clocks, i.e.,ck1 andck2.The clock assignment assigns clocks for the predicate symbols defined in the programbody.

% CLOCK DEFINITION (ck1, ck2) %ck1(N) <- N = 0 fby (ck1(M), N is M+1).ck2(N) <- ck1(M), N is M*7.

% CLOCK ASSIGNMENT (ck) %assign(stock,ck1).assign(onloan,ck1).assign(acquisition,ck2)....% PROGRAM BODY %first stock(mobbydick).first stock(oliver).first next stock(the_hobbit).next stock(X) <- stock(X).stock(X) <- acquisition(X).first next acquisition(war_and_peace).first next[2] acquisition(germinal)....

Hereck1 represents the clockh0; 1; 2; 3; : : :i in which each moment can be inter-preted as a day. Thenck2 can be interpreted as representing weeks, i.e.,h0; 7; 14; 21; : : :i.At time t = 0, the left-hand-side offby in the clause forck1 is used; therefore theinitial value forck1 is 0. At timest > 0, the right-hand-side offby is used; thereforethe subsequent values forck1 are determined by the previous value forck1 plus1.

The program body includes facts to define the initial stock in the library and somerules. Once a book is in stock, it remains in stock forever. Since predicatesstock andacquisition are defined overck1 andck2 respectively and these clocks synchro-nize at0; 7; 14 etc., the bookwar_and_peace is included in stock at time7, the bookgerminal at time14 and so on.

Suppose that we want to find which books are in stock at time1:

<- first next stock(X).

The answers to the goal areX = mobbydick, X = oliver, X = the_hobbitand so on. We now ask “which books are in stock at the end of week 1?”:

<- first next[7] stock(X).

Then the answers will include all those books which are already in stock from time0 totime7 plus all the books acquired until time7, eg,X = mobbydick,X = war_and_peaceand so on.

If all atoms of a goal are fixed-time, then the goal is a fixed-time goal; otherwiseit is an open goal. An open goal stands for a series of independent fixed-timegoals.

For example, the open goal<- stock(X) stands for a series of independent fixed-time goals of form<- first next[n] stock(X) for all t 2 ck1 wheren =rank(t; ck1). Answers to fixed-time goals can be obtained by using a clocked extensionof SLD-resolution [12].

5 Declarative Semantics

This section develops the meaning (declarative semantics) of Clocked Datalogpro-grams based on an extension of the declarative semantics of Chronolog(MC)programs[12]. The meaning of the program body of a Clocked Temporal Datalog program is nat-urally presented as the meaning of the program. However, the meaning of the programbody naturally depends on the meaning of the clock definition and assignment.

5.1 Clock definitions

LetP = Pc 1 Pa 1 Pb be a Clocked Temporal Datalog program. The clock assignmentPa is a set of facts, i.e. a Prolog program. The semantics results for Prolog programs canbe found in Lloyd [13].Pc is an ordinary Chronolog program [16], except for temporaloperatorfby, butfby does not add any expressive power when all the predicates aredefined over the global clock.

It is shown below that the temporal operatorfby in clock definitions of ClockedTemporal Datalog is not essential.

Lemma 1. LetP = Pc 1 Pa 1 Pb be a Clocked Temporal Datalog program. ThenPcis equivalent to anfby-free programP 0c .

Proof. We provide an informal proof. Let� be a clock assignment that assignsgc toeach predicate symbol. Without any loss of generality, consider the following programclause:C = A <- B1 fby B2.We have that��(C) = ��(A <- B1 fby B2) = gc. By the semantics offby, attime0, the value ofA is determined by the value ofB1; at all times> 0, the value ofAis determined by the previous value ofB2. Therefore the clauseC is equivalent to thetwo clauses given below:C1 = first A <- first B1.C2 = next A <- B2.It is easy to verify thatC1 is applicable at time0; andC2 is applicable at all times> 0.Nestedfby’s can be eliminated in a similar manner.

The results given below applies tofby-free clock definitions, and by lemma 1 theyapply to any clock definition of Clocked Temporal Datalog.

The declarative semantics ofPc can be developed in terms of temporal Herbrandmodels as follows. Herbrand universe ofPc, denoted byUPc , is generated by constantsand function symbols that appear inPc. Note that the Herbrand universes ofPc andP 0c

coincide. The Herbrand baseBPc of Pc consists of all those fixed-time temporal atomsgenerated by predicate symbols appearing inPc with terms inUPc used as arguments.Subsets ofBPc are regarded as temporal Herbrand interpretations ofPc. Note that theHerbrand bases ofPc andP 0c also coincide.

Let I be a temporal interpretation ofPc with UPc as its domain. Let� be a clockassignment which maps each predicate symbol defined inPc to gc. ThenI is identifiedwith a subsetH of BPc by the following.[[p(e1; : : : ; en)]]t�;I = true iff first next[t]p(e1; : : : ; en) 2 H , t 2�(p):[[p(e1; : : : ; en)]]t�;I = false iff first next[t]p(e1; : : : ; en) 62 H , t 2�(p):

Orgun and Wadge [16] showed that the minimum temporal Herbrand model ofaChronolog program exists, and it consists of all the logical consequences of the pro-gram. We denote the minimum model ofPc by MMOD(Pc). The following resultfollows from lemma 1 and analogous results for Chronolog [16].

Theorem 1. LetP = Pc 1 Pa 1 Pb be a Clocked Temporal Datalog program. Let�be a clock assignment which maps each predicate symbol defined inPc to gc. Then wehave:MMOD(Pc) =MMOD(P 0c) = fA 2 BPc jP 0c j=� Ag.

In a given programP = Pc 1 Pa 1 Pb, the clock assignment� is determinedby Pc andPa. To discuss clocked Herbrand models ofPb, we have to know how toobtain� for Pb. We can obtain a clock assignment� from the clock definitionPc andassignmentPa if all the clock constraints are satisfied.

We first have the following sufficiency result which states that if a clock definitionin Pc satisfies the clock constraints given in section 3, then it represents an actual clockin CK.

Lemma 2. LetP = Pc 1 Pa 1 Pb be a Clocked Temporal Datalog program. For eachpredicate symbolcki defined inP 0c with a clause of the formassign(cki,p/n) inPa, if cki satisfies the clock constraints with respect toMMOD(Pc), then the clockrepresented bycki is given as:h t j first next[k] cki(t) 2MMOD(Pc) ik2! .

We now define the notion of an admissible clock definition:

Definition 17. LetP = Pc 1 Pa 1 Pb be a Clocked Temporal Datalog program andSP the set of predicate symbols appearing inPb. LetCP = fcki j assign(p; cki) 2Pa andp 2 SPg. We callPc andPa an admissible clock definition if the followingconditions are satisfied:

- eachcki 2 CP is defined as a unary predicate inPc- eachcki 2 CP satisfies the clock constraints with respect toMMOD(Pc)- eachp 2 SP occurs in at most one clause of the formassign(p; cki) 2 Pa

The clock assignment determined byPc andPa, can be recovered as follows:

Definition 18. LetP = Pc 1 Pa 1 Pb be a Clocked Temporal Datalog program andSP the set of all predicate symbols appearing inPb. If the clock definitionPa andPc isadmissible, then the clock assignment� ofPb is determined as follows: For allp 2 SP ,

- �(p) = h t j first next(k) cki(t)2MMOD(Pc) ik2! if assign(p,cki)2Pa (this case is provided by lemma 2);- �(p) = h 0; 1; 2; 3; : : : i = gc if p is not assigned a clock inPa (default).

In general, there is no easy way of automatically checking whether clock constraintsare satisfied by each clock definition. In [12], a syntactic restriction on clock defini-tions is imposed. It is also shown that a clock definition with the restriction satisfiesthe clock constraints. However, the restriction allows a small set of clock definitionsonly, therefore, here we use the clock constraints in a prescriptive manner to restrict theadmissibility of clock definitions.

Programmable clock definitions are very flexible in specifying periodic aswell assome non-periodic clocks. For instance, the following program clausesdefine a non-periodic Fibonacci-like clock, that is,h1; 2; 3; 5; 8; 13; : : :i:

first cki(1).first next cki(2).next[2] cki(N) <- next cki(X), cki(Y), N is X+Y.

The first clause says that the first value forcki is 1; the second clause says that thesecond value forcki is 2; and the third clause says that the subsequent values forckiare determined by the sum of the previous two values. This clock definition would beruled out by the restriction imposed in [12]. The restriction does not allow mutual clockdefinitions, such as the ones given below, either.

even(N) <- N = 0 fby (odd(M), N is M+1).odd(N) <- even(M), N is M+1.

Here predicateseven andodd define the sequences of even numbers and odd numbersover time, respectively. Note that it is the programmer’s responsibility to ensure thatclock definitions are admissible.

5.2 Clocked Herbrand models

Let P = Pc 1 Pa 1 Pb be a Clocked Temporal Datalog program. Since the predicatesymbols appearing inPb have their own clocks, the semantics ofPb depends on thegiven clock assignment�. We know thatPb is true in a temporal interpretationI ona given clock assignment� if and only if all program clauses inPb are true inI on�. It can be shown that a program clause is true inI on� if and only if all fixed-timeinstances of the clause are true inI on�. Therefore, as far as the declarative semanticsis concerned, we can regardPb as the set of fixed-time instances of its program clauses.

A fixed-time instance of a program clause will only contain fixed-time temporalatoms and it will be fixed to a particular moment in time on its clock. We refer thereader to [12] for details of fixed-time instances offby-free program clauses. InPb,we cannot directly eliminate the occurrences offby’s because the clocks of involvedsub-formulas may be different. However, given a particular momentt on the clock ofa program clause withfby, we have the knowledge of which side of thefby operatoris involved at that time. Then, a fixed-time instance of the clause can be obtained by

referring to the involved side offby; the other side will simply be dropped from theinstance. Nestedfby’s can be eliminated one at a time.

We therefore have the following result, which complements lemma 1:

Lemma 3. LetP = Pc 1 Pa 1 Pb be a Clocked Temporal Datalog program. ThenPbis equivalent to anfby-free programP 0b .

LetUPb denote the clocked Herbrand universe ofPb which is generated by constantsand function symbols that appear inPb. The clocked Herbrand baseBPb of Pb consistsof all those fixed-time temporal atoms generated by predicate symbols appearing inPb with terms inUPb used as arguments. Again, the Herbrand universes ofPb andP 0bcoincide; and so do their Herbrand bases. We regard subsets ofBPb as clocked Herbrandinterpretations ofPb. Let� be the clock assignment determined byP 0c andPa andI atemporal interpretation ofPb with UPb as its domain. ThenI is identified with a subsetH of BPb by the following:[[p(e1; : : : ; en)]]t�;I = true iff first next(rank(t; �(p)))p(e1; : : : ; en) 2H; t 2 �(p):[[p(e1; : : : ; en)]]t�;I = false iff first next(rank(t; �(p)))p(e1; : : : ; en) 62H; t 2 �(p):

Again, as far as the declarative semantics is concerned,Pb andP 0b are equivalentby lemma 3. IfPc 1 Pa 1 Pb is a Clocked Temporal Datalog program with an admis-sible clock definition, then,P 0c 1 Pa 1 P 0b is an equivalent Chronolog(MC) program,restricted to its function-free subset. The declarative semantics of Chronolog(MC) pro-grams can then be applied toP 0c 1 Pa 1 P 0b. The following result follows from lemmas1 and 3, and the analogous results for Chronolog(MC) programs [12].

Theorem 2. Let Pc 1 Pa 1 Pb be a Clocked Temporal Datalog program, with anadmissible clock definition. ThenP 0c 1 Pa 1 P 0b is a Chronolog(MC) program with anadmissible clock definition. Let� be the clock assignment determined byP 0c andPa.ThenMMOD(Pb) = MMOD(P 0b) = fA 2 BP j P 0b j=� Ag.

If Clocked Temporal Datalog is used to query a clocked database, the clocks of rela-tions defined in a program will be determined by the clock assignment of the program,while the clocks of relations defined in the clocked database will be determined by theclock assignment of the database. We assume that the set of relation symbolsin theclocked database are distinct from the set of predicate symbols defined in theprogram.

LetP = Pc 1 Pa 1 Pb be a Clocked Temporal Datalog program with an admissibleclock definition, andDB = hR; �; �i a clocked database. NowP andDB togethercorrespond to the clocked databaseDB0 = hR [ SP; � [ �; �i where

- SP is the set of predicate symbols that appear inP 0b whereSP \R = ;.- � is the clock determined byPa andPc.- Pdb is a set of facts (fixed-time temporal atoms) that corresponds to the clocked

databaseDB,- � is a map determined as follows. For anyp 2 R, �(p) = �(p). For anyp 2(SP nR), �(p) = ft 7! I(p)(t) j t 2 �(p)g whereI is the temporal interpretation

over clock� [ � identified withMMOD(Pb [ Pdb).

When a Clocked Temporal Datalog program is used on its own as a deductive clockeddatabase, the clocked database the program models is a special case of the above defi-nition withR = ;, � = ; and� = ;.

Bottom-up evaluation strategies such as the fixed point computation areused tocompute the entire minimum Herbrand model of a given Datalog program [1]. In ClockedTemporal Datalog, this is not possible due to the infinitary nature of clocked relationsover infinite clocks. However, in practice, we are interested in finite portions of a givenclocked database, and, at any given moment in time, all predicates represent finite re-lations. Note that Clocked Temporal Datalog also introduces a form of stratification,which we calltemporal stratification, due to time-dependencies that exist in programs.When a program is temporally stratified (all future data is defined in termsof past and/orpresent data), then we can use bottom-up evaluation strategies over any period of time.However, we may need discuss the fixed-point semantics in two levels (theclock defi-nition level and the program body level). We omit the details due to space limitations.

6 Conclusions

We have proposed a deductive system for temporal data, based on the function-freesubset of the temporal language Chronolog(MC) [12] extended with temporal operatorfby. We have been able to use the results for Chronolog(MC) with some modifications.Our interpretation of a granularity in the underlying model for timeis a clock. How-ever, if we interpret granularity as periodicity, our model is not yet quite satisfactory,because the following clocks are based on the same periodicity:h0; 7; 14; 21; : : :i andh1; 8; 15; 22; : : :i and yet they are interpreted as different granularities. We are planningto include in TLC some temporal operators to provide various alignments of clocks ina seamless manner.

A promising avenue of further research is to relax the second clock constraint toobtain branching time. Then, finding answers to a given goal would also involve findinga branch of time in which the goal can be proved. To the best of our knowledge, no otherdeductive system for temporal data offers such flexibility. We are also considering aclocked temporal relational calculus based on TLC.

7 Acknowledgements

The work presented in this article is partly sponsored by an Australian Research Council(ARC) Grant.

References

1. K. R. Apt, H. A. Blair, and A. Walker. Towards a theory of declarative knowledge. InJ. Minker, editor,Foundations of Deductive Databases and Logic Programming, pages 89–148. Morgan Kaufmann, Los Altos, Calif, 1988.

2. M. Baudinet, M. Niezette, and P. Wolper. On the representation of infinite temporal dataand queries. InProceedings of the Tenth ACM SIGACT-SIGMOD-SIGART Symposium onPrinciples of Database Systems, pages 280–290. The Association for Computing Machinery,1991.

3. M. Bohlen and R. Marti. On the completeness of temporal database query languages. InD. M. Gabbay and H. J. Ohlbach, editors,Proceedings of ICTL’94: The First InternationalConference on Temporal Logic, volume 827 ofLNAI, pages 283–300, Gustav StresemannInstitut, Bonn, Germany, 1994. Springer-Verlag.

4. J. Chomicki. Polynomial time query processing in temporal deductive databases. InProceed-ings of the Seventh ACM SIGACT-SIGMOD-SIGART Symposium on Principles of DatabaseSystems, Nashville, Tennessee, USA, April 1990. The Association for Computing Machin-ery.

5. J. Chomicki. Temporal query languages: A survey. In D. M. Gabbay and H. J. Ohlbach,editors,Proceedings of ICTL’94: The First International Conference on Temporal Logic,volume 827 ofLNAI, pages 506–534, Gustav Stresemann Institut, Bonn, Germany, 1994.Springer-Verlag.

6. J. Chomicki and T. Imielinski. Temporal deductive databases and infinite objects. InProceedings of the Seventh ACM SIGACT-SIGMOD-SIGART Symposium on Principles ofDatabase Systems, pages 61–73. The Association for Computing Machinery, 1988.

7. C. E. Dyreson and R. T. Snodgrass. Temporal granularity. In R. T. Snodgrass, editor,TheTSQL2 Temporal Query Language, pages 347–383. Kluwer Academic Press, 1995.

8. D. Gabbay and P. McBrien. Temporal logic & historical databases. InProceedings of the17th Very Large Data Bases Conference, pages 423–430, Barcelona, Spain, September 1991.Morgan Kauffman, Los Altos, Calif.

9. J.-R. Gagne and J. Plaice. A non-standard temporal deductive database system.Journal ofSymbolic Computation, 22(5&6), 1996.

10. P. Ladkin.The Logic of Time Representation. PhD thesis, University of California, Berkeley,California, USA, 1987.

11. J. Y. Lee, R. Elmasri, and J. Won. An integrated temporal data model incorporating timeseries concept. Department of Computer Science and Engineering, The University of Texasat Arlington, Texas, U.S.A., February 1997.

12. C. Liu and M. A. Orgun. Dealing with multiple granularityof time in temporal logic pro-gramming.Journal of Symbolic Computation, 22(5&6):699–720, 1996.

13. J. W. Lloyd.Foundations of Logic Programming. Springer-Verlag, 1984.14. M. A. Orgun. Incorporating an implicit time dimension into the relational model and algebra.

RAIRO Theoretical Informatics and Applications, 30(3):231–260, 1996.15. M. A. Orgun. On temporal deductive databases.Computational Intelligence, 12(2):235–259,

1996.16. M. A. Orgun and W. W. Wadge. Theory and practice of temporal logic programming. In

L. Farinas del Cerro and M. Penttonen, editors,Intensional Logics for Programming, pages23–50. Oxford University Press, 1992.

17. G. Ozsoyoglu and R. T. Snodgrass. Temporal and real-time databases: A survey.IEEETransactions on Knowledge and Data Engineering, 7(4):513–532, August 1995.

18. A. Tuzhilin and J. Clifford. A temporal relational algebra as a basis for temporal relationalcompleteness. In D. McLeod, R. Sacks-Davis, and H. Schek, editors, Proceedings of the16th International Conference on Very Large Data Bases, pages 13–23, Brisbane, Australia,August 13–16 1990. Morgan Kaufmann Publishers Inc., Los Altos, Calif.

19. J. van Benthem. Temporal logic. In D. M. Gabbay, C. J. Hogger, and J. A. Robinson,editors,Handbook of Logic in Artificial Intelligence and Logic Programming, volume 4.Oxford University Press, 1993.

20. G. Wiederhold, S. Jajodia, and W. Litwin. Dealing with granularity of time in temporaldatabases. In R. Andersen, J. A. Bubenko, and A . Sølvberg, editors,Advanced InformationSystems Enginering: Proceedings of the Third International Conference CAiSE’91, pages124–140, Trondheim, Norway, May 13–15 1991. Springer-Verlag.