A Fast Algorithm and Datalog Inexpressibility for Temporal Reasoning
We introduce a new tractable temporal constraint language, which strictly contains the Ord-Horn language of Buerkert and Nebel and the class of AND/OR precedence constraints. The algorithm we present for this language decides whether a given set of c…
Authors: Manuel Bodirsky, Jan Kara
A F AST ALGORITHM AND D A T ALOG INEXPRESSIBILI TY F OR TEMPORAL REASONING MANUEL BODIRSKY AND JAN K ´ ARA Humboldt-U niversi t¨ at z u Berlin, Germany E-mail addr ess : bodirsky@i nformatik.hu-berlin.de Charles Universit y , Prag ue, Czech Republic E-mail addr ess : kara@kam.m ff.cuni.cz Abstra ct. W e introduce a new tractable temporal co nstraint language, whic h strictly conta ins the Ord-Horn language of B ¨ urkert and Neb el and the class of AND/OR p recedence constrain ts. The algorithm w e present for th is language decides wheth er a given set of constrain ts is consisten t in time that is q uadratic in th e inp u t size. W e also prov e that (unlike O rd-Horn) the constraint s atisfaction p roblem of this language cannot b e solv ed by Data log or by establishing local consis tency . 1. In tro duction T emp oral reasoning pla ys an imp ortan t role in Artificial In telligence. Al most any a rea in AI – for in stance common-sense reasoning, natur al language pro cessing, sc heduling, plan- ning – in vo lv es some sort of temp oral reasoning. In 1993, Golumbic and Shamir [16] listed applications of temp oral reasoning p roblems in arc heology , b eha vioral ps y cholog y , op er- ations research, and circuit d esign. Since then, temp oral reasoning b ecame one of the b enchmark applications of constraint pro cessing in general [8]. Con tr ibutions to the field ha v e v arious backg round , for example data base theory [31], sc heduling [27], constrain t sat- isfaction complexity [5], the theory of relation algebras [11, 24], com binatorics [16], and artificial int elligence [14]. This pap er deals w ith temp or al c onstr aint languages . A temp or al c onstr aint language (TCL) is a coun table collectio n of relations with a first-order defin ition in ( Q , < ), the linear order of the rational n um b ers ; a detailed definition is giv en in Section 2. One of the m ost fu ndamenta l TCLs is the so-ca lled p oint algebr a . This language con tains relations for = , <, ≤ , and 6 =, in terpreted o v er an infin ite dense linear order in the usual w a y . Vilain, Kautz, and v an Beek show ed th at consistency of a giv en set of constraints o ve r this language (ak a the c onstr aint satisfaction pr oblem for this language) can b e d ecided in p olynomial time b y lo cal co nsistency tec hn iques [25]. Later, v an Beek described an alg orithm that r u ns in O ( n 2 ), where n is the num b er of v ariables [30]. A considerably larger tractable TCL wa s introd uced b y B ¨ urke rt and Neb el [28]. Their language, called Or d-Horn , strictly conta ins the p oint algebra. B ¨ urk ert and Neb el u sed resolution to sh ow that consistency of a set of O rd-Horn constrain ts can b e decided in O ( s 3 ), Key wor ds and phr ases: constrain t satisfactio n, t emp oral reasoning, compu tational complex ity , Ord-Horn, algorithms, Datalog, precedence constraints. Supp orted by Pro ject 1M0021620 808 of th e Ministry of Edu cation of the Czech Repub lic. 1 2 M. BODIRSKY AND J. K ´ ARA where s is the size of the inpu t. They also show ed that establishing path-consistency can b e used to decide w hether a giv en set of O r d-Horn constr aints has a solution. Koubarakis [22] later presen ted an algorithm with a r unning time in O ( s 2 ). Ord-Horn is motiv ated b y temp oral reasoning tasks for c onstraints on time intervals . The study of constrain ts on inte rv als (whic h can b e used to mo del temp oral information ab out ev ent s) w as initiated b y Allen [1], who introdu ced an algebra of binary constraint relations on interv als. The complexit y to decide the consistency of a giv en set of constraint s from Allen’s algebra is NP-complete in general [1]. Ho w ev er, for sev eral fragments of Allen’s in terv al algebra th e consistency p r oblem is decidable in p olynomial time. All suc h fragmen ts ha v e b een classified [10, 23 ]. It is well-kno wn that ev ery relation on intervals fr om Allen’s algebra can b e translated to a relation on time p oints . Hence, algorithmic resu lts f or temp o- ral reasoning with time p oints can b e used for reasoning with time interv als as well . B ¨ urke rt and Neb el used this translation to iden tify one of the tractable fragmen ts of Allen’s inte rv al algebra, n amely the set of all interv al constraint s that trans late to Ord-Horn constraints on p oints. Another imp ortan t temp oral constraint language with applications in scheduling are AND/OR-precedence constrain ts [27]. An AND-co nstraint can b e used to exp ress that some job cannot b e started b efore a set of other jobs has b een completed. An OR-constrain t can b e used to expr ess that a job cannot b e started b efore one of a giv en set of jobs has b een completed. F easibilit y of AND/OR precedence constraints can indeed b e modeled as a constrain t satisfactio n p roblem for a TC L: AND-constrain ts can b e represented b y conjunctions of form ulas of the form x > y , and OR-constrain ts b y formulas o f the form x > x 1 ∨ · · · ∨ x > x n . There are temp oral constrain t languages where one cannot exp ect a p olynomial time algorithm. A w ell-kno wn TCL with an NP-complete consistency problem consists of a single ternary relation, the b etwe enness r e lation { ( x, y, z ) | x z 1 ∨ · · · ∨ z 0 > z l ) , or ( x 1 = y 1 ∧ · · · ∧ x k = y k ) → ( z 0 > z 1 ∨ · · · ∨ z 0 > z l ∨ ( z 0 = z 1 = · · · = z l )) (where k and l m igh t b e 0). It has b een sho wn in [4] that ll-closed constrain ts are a lar gest tr actable language in the sense that every T CL that s trictly con tains one of our t w o languages has an NP-complete constrain t satisfact ion problem. The presented algorithm for ll-closed constrain ts has a run ning time th at is qu adratic in the size of its inpu t. T raditionally , one of the main a lgorithmic tools in constraint satisfactio n, and in par- ticular in temp oral reasoning, are lo c al c onsistency te chniques [1, 10, 16, 25, 28], for instance algorithms b ased on establishing path-consistency . Consistency based algorithms can b e A F AST ALGORITHM AND DA T ALOG INEXPRESSIBILITY FOR TEMPORAL REASON ING 3 form ulated conv enientl y as Datalog p rograms [2, 13, 21] . Roughly sp eaking, Datalog is Pro- log w ithout f u nction sym b ols, and comes from Database th eory [12]. W e sh o w that, unlike Ord-Horn [28], ll-closed and d ual ll-closed constrain ts can not b e solv ed b y a Datalog pro- gram. In our pro of w e apply a peb b le-game argumen t that w as originally introd uced for finite domains [13, 21], but has b een sh o wn to generalize to a wide ran ge of infi nite domain constrain t languages, includin g T CLs [2] . This is interesting from a theoretical p oint of view: f or constraint satisfaction p roblems of languages o v er a fin ite d omain, all known algo- rithms are essentiall y based on algebraic algorithms or Datal og [13]. Ho wev er, the algorithm w e present for temp oral reasoning is n either algebraic nor based on Datalog. 2. T emp oral Constrain t Langu ages A (qualitative) temp or al r elation is a relation that is fi rst-order d efinable in an un - b ound ed countable dense s tr ict lin ear order. All su c h linear orders are isomorphic [19, 26], but for con v enience w e alwa ys use ( Q , < ), i.e., the dense linear order on th e rational num- b ers 1 . An example of a temp oral relation is the ternary Betwe enness relation { ( x, y , z ) ∈ Q 3 | ( x 0 and b < b ′ • a > 0 and b = b ′ and a < a ′ See Figure 1 f or illustration. In diagrams lik e in Fig ure 1 w e draw a directed edge from ( a, b ) to ( a ′ , b ′ ) if ll( a, b ) < ll( a ′ , b ′ ). Again, it is easy to s ee that the set of temp oral relations preserve d by ll is not affected b y the exact choice of the b inary op eration ll. Also observe that ev ery temp oral r elation that is preserved by ll is also preserv ed by lex. W e sa y that a relation is ll-closed if it is p reserv ed by ll. It is p ossible to decide algorithmically whether a constraint language is ll-closed. Prop osition 3.1. Given a finite c onstr aint language wher e al l r elations ar e r e pr esente d as lists of we ak line ar or ders, one c an de cide in p olynomial time in the input size whether the c onstr aint lan guage is l l-close d. Pr o of. W e test for eac h r elation R in the constrain t language sep arately whether it is ll- closed. A k -ary relation R is p reserv ed by ll if and only if for every tw o we ak orders o 1 and o 2 in R and every in dex e ≤ k the weak ord er o 3 is also in R , where o 3 is defined as follo w s: ( i, j ) ∈ o 3 iff one of the follo w ing h olds • ( i, j ) ∈ o 1 and ( i, j ) ∈ o 2 , • ( i, j ) ∈ o 1 , ( j, i ) / ∈ o 1 , and ( i, e ) ∈ o 1 , or • ( i, j ) ∈ o 2 , ( j, i ) / ∈ o 2 , ( e, j ) ∈ o 1 , and ( j, e ) / ∈ o 1 . F or all pairs ( o 1 , o 2 ) of wea k linear orders on { 1 , . . . , k } in the representat ion of R , and for eac h index e ≤ k , w e can v erif y in linear time in k whether the weak linear order o 3 as describ ed ab ov e is also con tained in the representati on of R . 6 M. BODIRSKY AND J. K ´ ARA y x y x Figure 1: A visualization of the ll (left sid e) and the dual ll op eration (righ t sid e). Similarly to the ll op eration we can defin e a dual ll op eration, as d epicted in Figure 1. T o show that the language of all ll-closed relations is different from the language of all dual ll-closed r elations, w e use the fol lo wing t wo relations, whic h will b e also of imp ortance in later argumen ts. Definition 3.2. W e defi ne R min to b e the ternary relation { ( x, y , z ) | x>y ∨ x> z } , and R max to b e { ( x, y , z ) | x x 2 ∨ · · · ∨ x > x k are l l -closed as w ell, whic h are the relat ions to mo d el AND/OR precedence constrain ts. Prop osition 3.3. The language of l l-close d r elations do es not c ontain the class of dual l l-close d r elations and v ic e versa. Pr o of. T o sho w that the language of ll-closed constraint s do es not con tain the language of dual ll-closed constrain ts, we sho w that there is a temp oral relation that is p reserv ed b y ll but n ot by du al ll. W e claim that the relation R min is preserved b y th e ll op- eration: Let ( x 1 , x 2 , x 3 ) and ( y 1 , y 2 , y 3 ) b e triples that are b oth in the relation R min . Without loss of generalit y , x 1 > x 2 (note that the relation is symmetric in the second and third argumen t). If in this case y 1 ≥ y 2 , then, b ecause ll preserve s ≤ , w e ha v e that ll( x 1 , y 1 ) ≥ ll( x 2 , y 2 ), and b ecause ll is inj ective , we h a v e that ll( x 1 , y 1 ) > ll( x 2 , y 2 ). There- fore (ll( x 1 , y 1 ) , ll ( x 2 , y 2 ) , ll ( x 3 , y 3 )) is in R min , and w e are done. So let us assume th at y 1 < y 2 and therefore y 1 > y 3 . W e can again apply the previous a rgument to show that (ll( x 1 , y 1 ) , ll ( x 2 , y 2 ) , ll ( x 3 , y 3 )) is in R min unless x 1 < x 3 . So let us assume that x 1 < x 3 . No w, in case that x 2 > 0, the op eration ll preserv es R min , s ince in this case ll acts lik e a lexicographic order on the t wo triples. Otherwise, x 2 ≤ 0. It is easy to c hec k that then ll( x 2 , y 2 ) < ll( x 1 , y 1 ) b ecause x 1 > x 2 . Ho w ev er, R min is not preserv ed by the dual ll op eration: consider th e tuples t 1 := ( − 1 , 1 , − 2) and t 2 := ( − 1 , − 2 , 1) that are b oth in R min . If w e apply the dual ll op eration to th ese t w o tuples, we obtain dual-ll( − 1 , − 1) < d ual-ll( − 2 , 1) < dual-ll(1 , − 2), and hence the tuple dual-ll( t 1 , t 2 ) is not in the relation R min . A F AST ALGORITHM AND DA T ALOG INEXPRESSIBILITY FOR TEMPORAL REASON ING 7 This shows that the language of ll-closed constrain ts d o es not con tain the language of du al ll-close d constrain ts. Analogously , w e ca n use the relat ion R max to sh o w that the language of d ual ll-closed constraint s do es not con tain the language of ll-closed constrain ts. The temp oral constrain t language of all ll-closed r elations also con tains the imp ortant class of Ord-Horn relations, in tro duced by B ¨ urck ert and Neb el [28] to iden tify a tractable class of inte rv al constr aints. A relation is Ord -Horn if it can b e defi n ed by a conju nction of form ulas of the form ( x 1 = y 1 ∧ · · · ∧ x k = y k ) → x 0 O y 0 , where O ∈ { = , <, ≤ , 6 = } . It is alw a ys p ossible to translate interv al constraints int o temp oral constrain ts [2 5]. If the translati on of an interv al constraint language f alls int o a tr actable TCL, th e interv al constrain t language is tractable as well. B¨ urck ert and Neb el show ed that the class of interval constrain ts having a translation in to Or d-Horn temp oral constrain ts is a largest tractable fragmen t of Allen’s int erv al algebra. Note that this does not imply that the class of Ord-Horn constraint s is a largest trac table TCL on time p oin ts. Indeed, this is not the case. Prop ositio n 3.4 b elo w shows that the class of Ord-Horn constraints is ll-closed. S ince the relation R min defined in this section is ll-closed but not Ord-Horn, th e class of ll-closed constrain ts is strictly larger than O rd-Horn. Finally , we p r o v e in Section 4 that ll-closed constrain ts are tractable. Prop osition 3.4. Al l r elations i n Or d-Horn ar e pr eserve d by l l and b y dual l l. Pr o of. W e will giv e the argumen t for the ll op eration only; the argumen t for the dual ll op eration is analogo us. It suffices to sho w that ev ery relation that can b e defined by a form ula Φ of the form ( x 1 = y 1 ∧ · · · ∧ x k − 1 = y k − 1 ) → x k O y k is pr eserv ed by ll, w here O ∈ { = , <, ≤ , 6 = } . Let t 1 and t 2 b e t wo 2 k -tuples that satisfy Φ. Consider a 2 k -tup le k 3 obtained by app lying ll comp onent wise to t 1 and t 2 . W e d istinguish t wo cases: either there is an i ≤ k − 1 suc h that in one of the tup les x i = y i is n ot s atisfied – in this case x i = y i is not satisfied in t 3 as w ell by injectivit y of ll, and therefore the tup le t 3 satisfies Φ. Or x i = y i holds for all i ≤ k − 1 in b oth tuples t 1 and t 2 . But then, as t 1 and t 2 satisfy Φ, th e literal x k O y k holds in b oth t 1 and t 2 . Since ll preserv es all relations in { = , <, ≤ , 6 = } , the literal x k O y k holds in t 3 , and therefore t 3 satisfies Φ as w ell. It tur ns out that a temp oral relation is p r eserv ed b y ll if and only if it can b e defined b y a class of formulas which we call l l-Horn formulas . This class prop erly extends the class of Or d-Horn formulas. A form ula is called l l-Horn if it is a conjunction of formula s of the follo w ing form (slightly abu sing terminology , w e call these formulas the clauses of the ll-Horn formula ) ( x 1 = y 1 ∧ · · · ∧ x k = y k ) → ( z 0 > z 1 ∨ · · · ∨ z 0 > z l ) , or ( x 1 = y 1 ∧ · · · ∧ x k = y k ) → ( z 0 > z 1 ∨ · · · ∨ z 0 > z l ∨ ( z 0 = z 1 = · · · = z l )) where 0 ≤ k , l . Note th at k or l migh t b e 0: if k = 0, we obtain a formula of the form z 0 > z 1 ∨ · · · ∨ z 0 > z l or ( z 0 > z 1 ∨ · · · ∨ z 0 > z l ∨ ( z 0 = z 1 = · · · = z l )), and if l = 0 we obtain a disjun ction of disequalities. Also note that th e v ariables x 1 , . . . , x k , y 1 , . . . , y k , z 0 , . . . , z l need n ot b e p airwise distinct. Also note that the clause z 1 > z 2 ∨ z 3 > z 4 is not equiv alen t to an ll-Horn f orm ula. Prop osition 3.5. A temp or al r elation is l l-close d if and only if it c an b e define d by an l l-Horn formula. 8 M. BODIRSKY AND J. K ´ ARA W e fir st p ro v e Lemma 3.6 b elo w ab out relations that only con tain inje ctive tuples. A tuple is said to b e inje ctive if all en tries of the tuple are pairw ise distinct. Note that ev ery temp oral relation R can b e defined by a quan tifier-free f ormula in conjunctiv e norm al form where all literals are of th e form x > y or x = y ; to see this, tak e any quantifier-free formula in conjunctiv e normal form th at defines R and • replace x ≤ y b y the t w o literals x < y ∨ x = y ; • replace x 6 = y b y the t w o literals x > y ∨ y > x ; • replace x < y b y y > x . W e call form ulas in qu an tifier-free conjunctiv e normal f orm wh ere all literals are of the form x > y or x = y standar d formulas . A clause is b ad if it is not of the form z 0 > z 1 ∨ · · · ∨ z 0 > z l . Lemma 3.6. L et R b e a temp or al r elation that only c ontains inje ctive tuples, and let φ b e a standar d formula with minimal numb er of b ad clauses such that a) an inje ctive tuple is in R i f and only if it satisfies φ ; b) any formula obtaine d fr om φ by r emoving a liter al fr om a clause do es not have this pr op erty. If R is l l -close d, then φ do es no t c ontain b ad clauses. Pr o of. Su pp ose that R is n -ary , and th at x 1 , . . . , x n are the v ariables of φ . Because R only con tains injectiv e tuples, w e can remo v e literals of the form y = z from φ . But this w ould con tradict assump tion a), so we assu me th at φ only con tains literals of the form x > y . Supp ose f or cont radiction that φ co nta ins a bad clause C . Then C m ust conta in t w o literals l 1 := x u > x v and l 2 := x r > x s where x u and x r are distinct v ariables. W e claim that there is an injectiv e tuple t 1 suc h that l 1 is the only literal satisfied in C if w e assign t 1 [ i ] to x i for 1 ≤ i ≤ n . O therwise, the form ula obta ined from φ b y remo ving l 1 from C still has th e p rop erty that ev ery inj ective tuple is in R if an d only if it satisfies φ . Moreo v er, the n umb er of bad clauses in th e new formula is also minimal, w hic h is imp ossible by the c hoice of φ . Similarly one can see that there is an injectiv e tuple t 2 suc h th at l 2 is the only literal satisfied in C if we assign t 2 [ i ] to x i . W e first study th e case that t 1 can b e chosen su c h that t 1 [ r ] is smaller than t 1 [ s ], t 1 [ u ], and t 1 [ v ]. Let α b e an au tomorp h ism of ( Q , < ) suc h that t 1 [ r ] is mapp ed to 0. Consider the tuple t = l l ( α ( t 1 ) , t 2 ). Ob serv e that t is injectiv e since ll pr eserv es 6 =. If a lit eral in some clause of φ is n ot satisfied in b oth tuples t 1 and t 2 , then it is also not satisfied in t , b ecause ll and α preserv e ≤ . T herefore only th e literals l 1 and l 2 of C can b e satisfied by t . Since t [ r ] is strictly smaller than t [ s ] (by the p rop erties of ll), the literal l 2 cannot b e satisfied by t in C . S ince t 2 [ v ] > t 2 [ u ], it also h olds that t [ v ] > t [ u ] (b y the pr op erties of ll), and hence l 1 is not satisfied in t either. So t d o es not giv e a satisfying assignment for φ , in con tradiction with the assumption that R is ll-closed. An analogous argument shows th at t 2 cannot b e c hosen s uc h th at t 2 [ u ] is smaller than t 2 [ v ], t 2 [ r ], and t 2 [ s ]. W e claim that any injectiv e tu ple that satisfies φ also s atisfies ( x u > x v ∨ x u > x s ). If there w as an injectiv e tuple t with t [ u ] < t [ v ] and t [ u ] < t [ s ], then t [ u ] > t [ r ] to satisfy the pr op erty from the b eginning of the paragraph. Hence, t [ r ] < t [ v ] and t [ r ] < t [ s ]. But then t [ r ] is sm aller than t 2 [ v ], t 2 [ r ], and t 2 [ s ], in contradict ion to what w e ha v e sho wn b efore. Analogously w e c an sho w that an y injectiv e tuple that satisfies φ also s atisfies ( x r > x v ∨ x r > x s ). Let φ ′ b e the formula ob tained from φ by r emo ving C and adding these tw o clauses. W e sho w that an injectiv e tuple sati sfies φ ′ if and only if it sati sfies φ . By what we ha ve see abov e, it suffices to sho w that φ ′ implies φ . Let t b e any satisfying assignmen t of φ ′ . A F AST ALGORITHM AND DA T ALOG INEXPRESSIBILITY FOR TEMPORAL REASON ING 9 Clearly , all the clauses of φ except for C are satisfied by t , b ecause they are also pr esen t in φ ′ . W e can r eformulate the t w o additional clauses in φ ′ to ( x u > x v ∧ x r > x v ) ∨ ( x u > x v ∧ x r > x s ) ∨ ( x u > x s ∧ x r > x v ) ∨ ( x u > x s ∧ x r > x s ) . If the fi rst, the second, or the fourth d isjunct is satisfied b y t , then t [ x u ] > t [ x v ] ∨ t [ x r ] > t [ x s ], and therefore C holds in t . If th e third disju nct is satisfied b y t and the literal l 1 do es not hold (i.e., t [ x u ] < t [ x v ]), we ha v e the chain of inequalities t [ x s ] < t [ x u ] < t [ x v ] < t [ x r ] and hence t [ x r ] > t [ x s ]. Th us, also in this last case C holds . The formula φ ′ has f ew er b ad clauses than φ . Let φ ′′ b e the formula obtained fr om φ ′ b y r ep eatedly remo ving literals from clauses as long as an injectiv e tup le is in R if and only if it satisfies φ ′′ . Since remo ving literals do es not create new bad clauses, we ev en tually obtain a formula that con tradicts the c h oice of φ . W e thus h a v e sho wn that φ cannot conta in bad clauses. Pr o of of Pr op osition 3.5. The p ro of that ev ery r elation defined by an ll-Horn form ula is ll-closed is similar to the pro of of Prop osition 3.4. W e just need to add itionally c hec k that the relation defin ed by z 0 > z 1 ∨ · · · ∨ z 0 > z l and th e relation d efined b y z 0 > z 1 ∨ · · · ∨ z 0 > z l ∨ ( z 0 = · · · = z l ) are preserved by ll, which is straigh tforw ard. The pro of of the rev erse imp lication is by induction on the arit y n of the temp oral relation R . W e assume that R is ll-closed. F or n = 2 th e statemen t of the prop osition holds, b ecause all binary temp oral relations can b e defin ed b y ll-Horn formulas. F or n > 2, w e construct the formula ψ that defines R as f ollo ws . Let φ b e a standard formula w ith m inimal n umb er of bad clauses suc h that a) an injectiv e tu ple is in R if and only if it satisfies φ , and b) an y formula obtained from φ b y r emo ving a literal fr om a clause do es not satisfy condition a). C learly , suc h a form ula exists: we can start from an y standard form ula that defines R an d h as a minimal num b er of b ad clauses, and then remov e r ep eatedly literals fr om clauses if th e r esulting f orm ula still satisfies a); sin ce d eleting literals d o es not create bad clauses, we ev en tually fi nd a formula that satisfies b oth cond itions a) and b). Lemma 3.6 sho ws that φ d o es n ot con tain bad clauses. F or all pairs of en tries i, j ∈ { 1 , . . . , n } , i < j , let R i,j b e the pr o jection of the relation R ( x 1 , . . . , x i − 1 , x j , x i +1 , . . . , x n ) to x 1 , . . . , x j − 1 , x j +1 , . . . , x n . Because also R i,j is ll-closed, it h as an ll-Horn defin ition φ i,j b y inductiv e assu m ption. W e add to eac h clause of φ i,j a literal x i = x j to the p remise of the imp lication, su ch that φ i,j remains an ll-Horn formula. Let ψ b e the formula that is a conjun ction of • all the mo dified clauses fr om all f ormulas φ i,j ; • all clauses C ( z 0 , . . . , z l ) of φ such th at R do es n ot con tain a tuple where z 0 , z 1 , . . . , z l all get the same v alue; • the formula C ( z 0 , . . . , z l ) ∨ ( z 0 = z 1 = · · · = z l ) for all other clauses C of φ with v ariables z 0 , z 1 , . . . , z l . Ob viously , ψ is an ll-Horn form ula. W e h a v e to verify that ψ defin es R . Let t b e an n -tuple suc h th at t / ∈ R . If t is injectiv e, then some clause C ( z 0 , z 1 , . . . , z l ) of φ is not satisfied b y t . The v ariables z 0 , z 1 , . . . , z l of C cann ot all ha v e the same v alue in t , and so ψ is not satisfied either. If there are i, j suc h that t [ i ] = t [ j ] then the tup le t j = ( t [1] , . . . , t [ j − 1] , t [ j + 1] , . . . , t [ n ]) / ∈ R i,j . Therefore some clause C of φ i,j is not satisfied by t j , and C ∨ x i 6 = x j is not satisfied by t . Thus, in this case t do es not satisfy ψ , to o. 10 M. BODIRSKY AND J. K ´ ARA W e also ha v e to verify that all t ∈ R satisfy ψ . Let C b e a conjun ct of ψ created fr om some clause in φ i,j . If t [ i ] 6 = t [ j ], then C is satisfied b y t b ecause C con tains x i 6 = x j . If t [ i ] = t [ j ], then ( t [1] , . . . , t [ j − 1] , t [ j + 1] , . . . , t [ n ]) ∈ R i,j and thus this tuple s atisfies φ i,j . This also implies that t satisfies C . Finally , let C b e a conjunct of ψ created fr om some clause of φ . Then C is of the form x u 0 > x u 1 ∨ · · · ∨ x u 0 > x u m or of the form x u 0 > x u 1 ∨ · · · ∨ x u 0 > x u m ∨ ( x u 0 = x u 1 = · · · = x u m ). If t is constant on the v ariables of C , then, by construction of ψ , C con tains the disjunct x u 0 = x u 1 = · · · = x u m and is satisfied. So supp ose t is not constant o n the v ariables of C . Assume for con tr adiction that t [ u 0 ] ≤ t [ u i ] for all i ∈ [ m ]. S ince t is n ot constan t, there is a j ∈ [ m ] suc h that t [ u 0 ] < t [ u j ]. By our assu mptions on φ , there is an injectiv e tup le t ′ ∈ R that s atisfies only the li teral x u 0 > x u j in C . C onsider the tuple t ′′ = lex ( t, t ′ ). Because t ′ has pairwise distinct entries and lex is an injectiv e op eratio n, t ′′ also has pairwise distinct ent ries. Since t [ u 0 ] ≤ t [ u i ] for all i ∈ [ m ], t ′ [ u 0 ] < t ′ [ u i ] for all i ∈ [ m ] \ { j } , and b ecause lex preserv es ≤ , w e get that t ′′ [ u 0 ] < t ′′ [ u i ] for all i ∈ [ m ] \ { j } . Finally , since t [ u 0 ] < t [ u j ] we also ha ve that t ′′ [ u 0 ] < t ′′ [ u j ] by the prop erties of lex. Hence, t ′′ [ u 0 ] < t ′′ [ u i ] for all i ∈ [ m ]. Therefore t ′′ do es not satisfy C and thus also do es not satisfy φ . Bu t t ′′ is injectiv e and is from R (b ecause R is ll-closed), in con tradiction to the prop erties of φ . The syntacti c c haracterizat ion of ll-closed temp oral r elations m otiv ates our the s econd w a y of rep r esen ting the constraints in the input instances of the constrain t satisfaction problem for ll-closed te mp oral constraint languages — the constraints ma y b e giv en as ll- Horn f orm ulas. W e w ou ld lik e to remark that there are ll-closed temp oral relations where the tuple r ep resen tation is more succinct than the ll-Horn represen tation, and vice versa. Note that sin ce ev ery Ord-Horn f ormula is ob viously an ll-Horn form ula, the algorithm w e present for the ll-Horn representa tion in Section 4 strictly generalizes the existing algo rithms for Ord -Horn constrain ts. F or simplicit y , we assume that in instances of the constrain t satisfaction problem f or ll-closed TC Ls the formulas r ep resen ting the constrain ts consist of just one clause (we can alwa ys trans f orm a constr aint into several constraint s of this f orm). 4. An Algorithm for ll-closed Constrain ts In th is sec tion w e p resen t an algorithm for ll-closed constrain ts. It is straig ht forward to ‘dualize’ the algorithm and all arguments, and we will therefore also obtain an algorithm for dual ll-closed constrain ts. One of the underlying ideas of the algo rithm is to use a subroutine that tries to find a solution where every v ariable has a differen t v alue. If this is imp ossible, the subroutine m ust r eturn a set of at least t wo v ariables that denote the same v alue in all solutions. It is one of the fund amen tal pr op erties of ll-closed constrain ts that th is is alwa ys p ossible. T o formally introdu ce our algorithm we need the follo wing d efinitions. Let φ = R ( x 1 , . . . , x k ) b e an atomic formula where R is a temp oral relation that is preserved by an op eratio n f . Clearly , for all x i from x 1 , . . . , x k the temp oral relation defined b y ∃ x i .φ is pr eserv ed by f as we ll. Therefore, if Φ is an instance of the CS P with constrain ts th at are pr eserv ed b y f , and y is a sequen ce of some of the v ariables of Φ, th en Φ ′ := {∃ y .φ | φ ∈ Φ } can also b e view ed as an instance of the CSP with constraints p reserv ed b y f . W e call Φ ′ the pr oje ction of Φ to X \ y . Note that if Φ ′ is u nsatisfiable, then Φ is uns atisfiable as well. The i -th en try in a k -tuple t is called minimal if t [ i ] ≤ t [ j ] for ev ery j ∈ [ k ]. It is called strictly minimal if t [ i ] < t [ j ] for every j ∈ [ k ] \ { i } . A F AST ALGORITHM AND DA T ALOG INEXPRESSIBILITY FOR TEMPORAL REASON ING 11 Definition 4.1. Let R b e a k -ary relatio n. A set S ⊆ [ k ] is called a min-set for the i -th entry in R if there exists a tuple t ∈ R su c h that the i -th entry is minimal in t , and f or all j ≤ k it h olds that j ∈ S if and only if t [ i ] = t [ j ]. W e sa y that t is a witness for this min-set. Let R b e a k -ary relation that is preserved by lex (recall that ll-closed constrain ts are preserve d b y lex as well), and su pp ose that the i -th entry has the min-sets S 1 , . . . , S l , f or l ≥ 1, w ith the corresp onding witnesses t 1 , . . . , t l . C onsider the tup le t := lex( t 1 , lex ( t 2 , . . . lex( t l − 1 , t l ))). Since th e ent ry i is minimal in every tuple t 1 , . . . , t l , and since lex p r eserv es b oth < and ≤ , it is also minim al in t . Because lex is in jectiv e, w e ha ve that t [ i ] = t [ j ] if and only if these t wo en tries are equal in eac h tuple t 1 , . . . , t l . Hence, the min-set for th e i -th ent ry in R witnessed by the tuple t is a subset of ev ery other min-set S 1 , . . . , S l . W e then call this set the minimal min-set for the i -th entry in R . Lemma 4.2. L et R b e a k -ary r elation pr eserve d b y lex, t ∈ R , i ∈ [ k ] and S b e the minimal min-set for the i -th entry in R . If t is such that t [ j ] ≥ t [ i ] for every j ∈ S , then t [ i ] = t [ j ] for every j ∈ S . Pr o of. Let t ′ ∈ R b e the tup le that witnesses the minimal min-set S . Supp ose there is a tuple t ∈ R suc h that not all entries in S are equal (in particular, | S | > 1). Consid er the tuple t ′′ := l ex ( t ′ , t ). By the pr op erties of lex it holds that t ′′ [ i ] < t ′′ [ j ] for ev ery j ∈ [ k ] \ S . F urther m ore, t ′′ [ i ] ≤ t ′′ [ j ] for j ∈ S if and only if t [ i ] ≤ t [ j ]. Th us, unless t ′′ witnesses a smaller min-set f or i in R (wh ic h would b e a con tradiction), w e hav e that t ′′ [ i ] > t ′′ [ j ] for some j ∈ S . T o develo p our alg orithm, w e use a sp ecific notio n of c onstr aint gr aph of a temp oral CSP in stance, defin ed as follo ws. Definition 4.3. T h e c onstr aint gr aph G Φ of a temp oral CSP instance Φ is a directed graph ( X, E ) defined on the v ariables X of Φ. F or eac h constrain t of the form R ( x 1 , . . . , x k ) f r om Φ w e add a directed ed ge x i x j to E if in eve ry tuple f r om R wh ere th e i -th en try is minimal the j -th en try is min imal as well. Example. W e r etur n to the example from S ection 2. The constraint graph G Φ 1 for the instance Φ 1 in this example has the v ertices x 1 , x 2 , y 1 , y 2 , y 3 , ed ges from eac h of y 1 , y 2 , y 3 to all other v ariables, and an edge fr om x 2 to x 1 . Definition 4.4. I f Φ con tains a constrain t φ imp osed on y suc h that φ does not adm it a solution where y den otes th e minimal v alue, the we sa y that y is blo cke d (by φ ) . W e can easily determine for eac h constrain t whic h v ariables are blo ck ed by this co n- strain t: F or a constrain t r epresen ted b y w eak linear ord ers we just c hec k all w eak linear orders and build a set of v ariables that are not minimal in an y of th em. F or a co nstraint represent ed by an ll-Horn form ula, a v ariable x i is blo c k ed if and only if th e form ula is of the form x i > z 1 ∨ · · · ∨ x i > z l . Thus, b y insp ecting all the constraints it is p ossible to compute the blo c k ed v ariables in linear ti me in th e inpu t size. W e w ould lik e to use the constrain t graph to iden tify v ariables that ha ve to denote the same v alue in all solutions, and therefore introdu ce the follo wing concepts. Definition 4.5. A s trongly connected comp onent K of the constrain t graph G Φ for a temp oral CS P instance Φ is called a sink c omp onent if n o edge in G Φ lea ves K , and no v ariable in K is blo c k ed. A v ertex of G that b elongs to a sink comp onen t of size one is called a sink . 12 M. BODIRSKY AND J. K ´ ARA Example. In the previous example, the v ariables y 1 , y 2 , y 3 are blo ck ed, an d x 1 and x 2 are not blo ck ed. The set of v ertices { y 1 , y 2 , y 3 } forms a strongly connected comp onent, whic h is not a sink comp onen t, b ecause there are outgoing edges. (Moreo ver, the v ariables in K are blo c k ed.) The singleton-set { x 1 } is a strongly connected comp onent without outgoing edges and without blo ck ed v ertices, and thus x 1 is a sink. The follo wing lemma sh o ws an im p ortan t consequence of lex-closure of constraints. Lemma 4.6. L et K b e a sink c omp onent of the gr aph G Φ for an instanc e Φ with lex-close d c onstr aints. Then al l variables fr om K must have e qual values in al l solutions of Φ . Pr o of. W e assu me that Φ has a solution, and that K has at least tw o ve rtices (otherwise the lemma is trivial). Let t b e a solution of Φ, and let M ⊆ K b e the set of v ariables that ha v e in t the minimal v alue among the v ariables of th e sink comp onen t K . If M = K , we are done. Otherwise, b ecause K is a s trongly connected comp onen t, there is an edge in G Φ from some vertex u ∈ M to some v ertex v ∈ K \ M . By the definition of G Φ , th ere is a constraint φ in Φ suc h that wheneve r u denotes the minimal v alue of a sol ution of φ , then v has to denote the minimal v alue as w ell. By p ermuting arguments, w e can assume without loss of generalit y that φ is of the form R ( w 1 , . . . , w k ) where w 1 = u and w 2 = v . Because K is a sink comp onent, the v ariable u cannot b e blo c k ed, and h ence there is a minimal min -set S for the first en try in R . Clearly , S contai ns 2, b ecause v is the second argument of φ . Note that G Φ con tains an edge from u to w i for all i ∈ S . Since K is a str on gly connected comp onent, all these v ariables w i are in K . Because u has in t the minim al v alue among the v ariables in K , ther e is n o v ariable w i , i ∈ S , whic h has a smaller v alue than u in t . This cont radicts Lemma 4 .2, b ecause the v alue for u in t is differen t than the v alue for v . Lemma 4.6 immediately imp lies that w e can add co nstraints of the t yp e x = y for all v ariables x, y from the s ame sink comp onent K . Equiv alen tly , we can consider the CSP instance Φ ′ where all th e v ariables in K are c ontr acte d , i.e., where all v ariables from K are r eplaced by the same v ariable. In some cases, a solution to a pr o jected instance w ith ll-closed constraints can b e used to construct a solution to th e original constrain t. W e sa y that a tuple (in particular, a solution of an in stance) x is inje ctiv e if x i 6 = x j for all i 6 = j . Lemma 4.7. L et Φ b e an instanc e of the CSP with variables X and l l- close d c onstr aints. L et x b e a sink in G Φ . If the pr oje ction Φ ′ of Φ to X \ { x } has an inje ctive solution, then Φ has a n inje ctive solution as wel l. Pr o of. Let s b e an injectiv e solutio n to Φ ′ . C on s ider a constraint φ = R ( x 1 , . . . , x k ) from Φ that is imp osed on x . By th e definition of Φ ′ there is a tuple t ∈ R suc h that t agrees with s on { x 1 , . . . , x k } \ { x } . Because x is a sink, there is tup le t ′ ∈ R suc h that the ent ry corresp ondin g to x is strictly minimal. It is no w easy to c hec k th at there are automorphisms α, β of ( Q , < ) suc h that the tuple t ′′ = α ( l l ( β ( t ′ ) , t )) agrees with s o n X \ { x } , and suc h that the en try corresp onding to x is s tr ictly minimal. As R is ll-closed, t ′′ ∈ R . Th us we see that for eac h constrain t R ( x 1 , . . . , x k ) imp osed on x th ere is a tuple in R where the entry corresp ondin g to x is strictly minimal, and the rest of the tup le agrees with s on X \ { x } . Hence, we can extend s by assigning to x a v alue smaller than any v alue u s ed in s , and the lemma readily follo ws. A F AST ALGORITHM AND DA T ALOG INEXPRESSIBILITY FOR TEMPORAL REASON ING 13 Algorithm 4.8 . Spec( Φ ) { // Input: Φ c o nstraints with v ariables X // Output: If a lgorithm returns fa lse // then Φ has no s olution // If Φ has an injective solutio n, then r eturn true // Otherwis e retur n S ⊆ X , | S | ≥ 2, s.t. for all // x, y ∈ S we have x = y in a ll so lutio ns of Φ G := Co nstruc tGrap h( Φ ) Y := ∅ , Φ ′ := Φ , G ′ := G While G ′ contai ns a sink s Y := Y ∪ { s } Φ ′ := proj ectio n of Φ ′ to X \ Y G ′ := Reco nstru ctGra ph( Φ ′ ) If Y = X then retu rn true else if G ′ has sink compon ent S return S else retur n fal se end if } Algorithm 4.9. Solve( Φ ): { // Input: instance Φ with v ariables X // Output: true o r f alse S := Spec( Φ ) If S = fal se then return false else if S = tru e then return true else Let Φ ′ be contrac tion of S in Φ return Solve( Φ ′ ) end if } Figure 2: An algorithm for ll-closed constr aints. W e are r eady to state our al gorithm for instances with ll- closed co nstraints; the alg o- rithm w orks f or b oth r epresent ations of the constrain ts (sets of w eak linear ord ers, ll-Horn form ulas). Theorem 4.10. The pr o c e dur e Solve (Φ) i n Algorithm 4.9 de cides whether a given set of l l-close d c onstr aints Φ (wh er e the r elations ar e either r epr esente d by sets of we ak line ar or ders, or by l l-H orn formulas) has a solution. Ther e is an implementation of the algorithm that runs in time O ( nm ) , wher e n is the numb er of variables of Φ and m is the size of th e input. Pr o of. Th e correctness of the pro cedur e Sp ec immediately implies the correctness of the pro cedur e Solv e. In the pro cedure Sp ec, after iterated deletion of sinks in G ′ , we hav e to distinguish three cases. In the fir s t case, Y = X . W e pr o v e by induction that Φ h as an injectiv e solution. Let x 1 , . . . , x n b e the elemen ts from Y in the rev erse order in whic h they were includ ed in to Y . F or 0 ≤ i ≤ n , let Φ i b e the in stance Φ pro jected to X \ { x 1 , . . . , x i } . Note that Φ 0 = Φ, and that Φ n = Φ ′ is the p ro jection of Φ to the empt y set, whic h trivially has an injectiv e solution. W e inductiv ely assume that Φ i , for i ≤ n , has an injectiv e solution. Then Lemm a 4.7 applied to x i , the instance Φ i − 1 , and the injectiv e solution to Φ i implies that also Φ i − 1 has an injectiv e solution. By induction, Φ i has an in j ectiv e solution for all 0 ≤ i ≤ n , and in particular Φ 0 = Φ has an injectiv e solution. Th erefore, the output tr ue of Sp ec is correct. Otherwise, in the second case, G ′ con tains a sink comp onen t S with | S | ≥ 2. W e claim that for all v ariables x, y ∈ S w e ha v e x = y in all solutions to Φ. Lemma 4.6 applied to the pr o jection of Φ to X \ Y implies that whenev er some v ariables are in the same sink comp onent , th ey must ha ve the same v alue in ev ery solution, and hence th e output is correct in this case as w ell. 14 M. BODIRSKY AND J. K ´ ARA In the third case, Y 6 = X , but G ′ do es not con tain a sink comp onent. Note that in ev ery solution to Φ ′ some v ariable m ust tak e the minimal v alue. Ho w ev er, sin ce eac h strongly c onnected comp onent without outgo ing edges conta ins a bloc ke d v ertex, there is no v ariable that can d enote the minimal element, an d hence Φ ′ has no solution. Because Φ ′ is a pro jection of Φ to X \ Y , the ins tance Φ is inconsistent as well. Since in eac h recursiv e call of S olv e the ins tance in th e argum en t has at least one v ariable less, Solve is executed at most n times. It is not difficult to implement the algorithm su c h that the total runnin g time is cubic in the inpu t size. How eve r, it is p ossible to implicitely represent the constrain t graph and to imp lemen t all sub -pro cedures such that the total runn in g time is in O ( nm ), for b oth typ es of representa tions of the constrain ts studied in this pap er. W e w ill no w d escrib e the details h o w this can b e ac hiev ed. W e ha v e already sho wn the correctness of the algorithm, an d only h a v e to discuss how to implemen t the algorithm s u c h that it runs in O ( nm ). In fact, w e describ e an implemen tation of the pro cedur e Sp ec that is linear in the in put size. First w e sho w ho w to deal with constrain ts represente d by ll-Horn clauses. Observ e that if an ll-Horn clause has a non-empt y left h an d sid e of the implicatio n, then a constraint for th is clause creates neither edges nor blo c k ed vertic es in the constrain t graph. Also constrain ts of the t yp e z 0 > z 1 ∨ · · · ∨ z 0 > z l do not create edges in G Φ . Thus, when constructing G Φ , w e only care ab out constraints of the t yp e z 0 > z 1 ∨ · · · ∨ z 0 > z l ∨ ( z 0 = z 1 = · · · = z l ). F or suc h constraint s we add ed ges f rom z 0 to z 1 , . . . , z l to G Φ . When the constrains in th e inpu t instance are repr esen ted by sets of weak linear orders w e hav e to b e more careful, and do not repr esen t the edges of G Φ explicitly , sin ce there migh t b e quadratically many edges which sp oils the desired ru nning time. W e sort the weak linear orders ≺ in eac h set according to the num b er of equiv alence classes (of the equiv alence relation defined by x ≺ y ∧ y ≺ x ). No w, the d ata s tr ucture con tains for eac h v ariable and eac h constrain t that is imp osed on this v ariable a r eference to the we ak linear order ≺ in this constraint su ch that v is smallest with resp ect to ≺ , and ≺ has the largest n umb er of equiv alence classes. Moreo v er, for eac h elemen t in eac h w eak linear order ≺ w e create a list that con tains the elemen ts from the same equiv alence class in ≺ . Finally , for eac h v ariable v w e also ha v e a list that con tains the constrain ts that are imp osed on v and that block v . With buc k et sort, the total cost to set up this data str u cture is linear in th e inpu t size. Ev en though the constrain t graph G Φ is not exp licitely rep resen ted, it is p ossible to use the ab o v e d ata structur e to compute the strongly connected comp onen ts of G Φ in linear time, using depth-firs t searc h. No w we h a v e to describ e h o w the algorithm find s s inks, how the data s tr ucture is up d ated after pro jections, and ho w the algorithm fin ds s in k comp on ents if th er e is no sink left and n ot all v ariables hav e b een pr o jected out. T o find sinks and sink comp onent s, we also h a v e to b e able to d etermin e efficient ly whether a no d e is blo ck ed or not. Initially , b ecause we hav e computed th e strongly conn ected comp onents, and b ecause w e kno w which v ariables are blo ck ed, we can create a list that con tains all sin ks of the initial instance. Supp ose that s is a sin k of G at some ite ration of the wh ile-lo op. W e then first compute the p ro jection of Φ ′ to X \ Y by u p dating only the constrain ts imp osed on s in Φ ′ . A t this step we can also determine wh ether a constraint no longer blo cks a v ariable v , and in this case we can up date the list of blo c king constraints for v . As so on as this list b ecomes empt y , we know that v is no longer b lo c k ed. In this case, if v d o es not hav e outgoing edges in the current constraint graph , which w e can determine efficient ly u s ing our up dated data A F AST ALGORITHM AND DA T ALOG INEXPRESSIBILITY FOR TEMPORAL REASON ING 15 structure, we add v to the list of sinks. The total num b er of op erations we ha v e to p erform in all iterations of the while-lo op is then b ound ed by m . Finally , if there is no sink left, but not all v ariables ha ve b een pr o jected out, then we can compute the str ongly connected comp onen ts of the resu lting constraint (again, this can b e done in linea r time using depth-fi rst searc h on our d ata structure), and since w e know whic h v ariables are blo c k ed, we can also fin d the sink comp onent s. Note that w e c an assume that n is sm aller than m . Otherwise, the constraint is not connected (w e use the notion of connectivit y for instances of the CS P as e.g. in [18]). W e can in this case u se the same implemen tation, an alyse the running time for eac h of the connected comp onents separately , and get the same result. This concludes the pr o of that for b oth representat ions s tudied in this p ap er the algo- rithm can b e implemente d su c h that it run s in time O ( nm ). 5. ll-closed Constr ain ts and Datalog In this sectio n, w e pro v e that the constraint s atisfaction problem for ll-closed constraints cannot b e solv ed by Data log programs 4 . F or simplicit y , the definition of the sematic s of Datalo g that w e use here will b e p urely op erational; for the stand ard seman tical approac h to the ev aluation of Datalog p rograms see [12]. A Datalog p rogram is a fin ite set of Horn clauses, i.e., clauses of the form ψ ← φ 1 , . . . , φ l , where l ≥ 0 and where ψ , φ 1 , . . . , φ l are atomic formulas of the form R ( x ). The form ula ψ is called the he ad of the ru le, and φ 1 , . . . , φ l are called the b o dy . W e assume that all v ariables in the head also o ccur in the b o d y . The relation symb ols o ccurr ing in the head of some clause are called intentional , and all other relation sym b ols in the clauses are called extensional . If Γ is a finite T CL, we migh t use Datalog programs to solve CSP(Γ) as follo ws. Let Π b e a Datalog p rogram wh ose extensional s ym b ols are from Γ. W e assume that there is one distinguished 0-ary inte ntio nal relatio n symb ol false . Now, supp ose we are giv en an instance Φ of CS P(Γ). An evaluation of Π on Φ pr o ceeds in steps i = 0 , 1 , . . . A t eac h step i we m ain tain a set of literals Φ i with extensional and inten tional relation sym b ols; it alw a ys h olds that Φ i ⊂ Φ i +1 . Eac h clause of Π is u ndersto o d as a ru le that ma y deriv e a new literal from the literals in Φ i . Initially , we ha ve Φ 0 := Φ. No w supp ose that R 1 ( x 1 1 , . . . , x 1 k 1 ) , . . . , R l ( x l 1 , . . . , x l k l ) are literals in Φ i , and R 0 ( y 0 1 , . . . , y 0 k 0 ) ← R 1 ( y 1 1 , . . . , y 1 k 1 ) , . . . , R l ( y l 1 , . . . , y l k l ) is a ru le from Π, w here y i j = y i ′ j ′ if and only if x i j = x i ′ j ′ . Then R 0 ( x 0 1 , . . . , x 0 l ) is the newly deriv ed literal in Φ i +1 , w here x 0 j = x i j ′ if and only if y 0 j = y i j ′ . The p ro cedure stops if no new literal can b e deriv ed. W e sa y that Π solv es CSP(Γ), if for every instance Φ of CSP(Γ) there exists an ev aluation of Π on Φ that derive s false if and only if Φ has no solution. W e wa nt to remark that the so-cal led metho d of establishing p ath-c onsistency , w hic h is very well -kno wn and f r equen tly applied in Artificial Inte lligence, can b e form ulated with Datalo g pr ograms where the in ten tional sym b ols are at most bin ary and all rules us e at most three v ariables in the b o dy . 4 This result should not b e confused with the weak er fact that establishing k - con sistency do es not imply global consistency , for any k . This w as shown for O rd-Horn in [22]. But recall t hat Ord-Horn c an b e solv ed by a D atalog p rogram [28]. 16 M. BODIRSKY AND J. K ´ ARA W e pr o v e that already for the T CL that only consists of R min there is n o Datalog program that solve s the corresp onding co nstraint satisfac tion problem. W e us e a p ebble- game c haracterizatio n of th e expressiv e p ow er of Datalog, wh ic h w as originally sho wn in [13] and [21] f or fi nite domain constraint satisfaction, and whic h holds f or a wide v ariet y of infinite domain constrain t languages as we ll, including qualita tiv e TC L s (see the journal v ersion of [3]). Let Γ b e a finite TCL, and let Φ b e an instance of CSP(Γ). Then the existential k - p ebble g ame on Φ is the follo w ing game b et we en the play ers Sp oiler and D uplic ator . Sp oiler has k p ebbles p 1 , . . . , p k . He places h is p ebbles on v ariables from Φ. Initially , no p ebbles are placed. In eac h round of th e game Sp oiler picks some of these p ebbles. If they are already p laced on Φ , then Sp oiler first r emo v es them from Φ. He then p laces the p ebbles on v ariables from Φ, and Duplicator resp ond s by assigning elemen ts from Q to these v ariables. This assignment has to satisfy all the constrain ts φ ∈ Φ where all v ariables in φ are p ebbled, otherwise Sp oiler wins the game. Dup licator wins, if the ga me con tin ues for ever , i.e., if Sp oiler can nev er win th e game. Theorem 5.1 (from [2]) . L et Γ b e a finite TCL. Ther e is no Datalo g pr o gr am that solves CSP (Γ) if and only if for e v ery k ther e exists an inc onsistent instanc e of CSP (Γ) such that Duplic ator wins the existential k - p ebble game on Φ . The rest of this section is devo ted to the p ro of of the follo wing theorem. Theorem 5.2 . Ther e is no Datalo g pr o gr am tha t solves CSP ( { R min } ) . Pr o of. Let k b e an arb itrary num b er. T o app ly Theorem 5.1 we ha v e to constru ct an inconsisten t instance Φ of CSP( { R min } ) suc h th at Duplicator wins the existenti al k -p ebble game on Φ. F or this, let G b e a 4-regular g raph of g irth at least 2 k + 1, i.e., all cycle s in G ha v e more than 2 k v ertices. It is kno wn and easy to see that su c h graphs exist, e.g. with the metho ds in [20] . Or ien t the e dges in G suc h that there are exa ctly t wo outgoing a nd t wo incoming edges for eac h vertex in G . Sin ce G is 4-regular, there exists an Euler tour for G (see e.g. [9]), which shows that such an orien tation exists. No w we can defin e our instance Φ o f CSP( { R min } ) as follo ws. The v ariables of Φ are the v ertices from G . The instance Φ con tains the constrain t R min ( w, u, v ) iff uw and v w are the t w o incoming edges at vertex w . W e claim th at Φ d o es not ha v e a solution: if there w as a solution, some v ariable w m u st denote the minimal v alue. But for ev ery v ariable w w e find a constrain t R min ( w, u, v ) in Φ, and th is co nstraint is violate d since either u or v m ust b e strictly smaller than w . W e now show that Duplicator has a w inning s trategy for the existen tial k -p ebble game on this instance. C on s ider a connected non-empty subgrap h G ′ of G ha ving at most 2 k v ertices where only one vertex r has no outgoing edges, and wher e all v ertices ha ve either t w o or no in coming edges. Sin ce G h as girth 2 k + 1, G ′ m ust b e a bin ary tree with ro ot r . W e call G ′ dominate d , if all lea ve s in G ′ are p ebb led. Duplicator alw a ys mainta ins the prop ert y that whenever the ro ot r in a dominated tree is p ebbled during the game, then the v alue assigned to r is strictly larger than the minim um of all the v alues assigned to the lea v es. Clearly , this p rop erty is satisfied at the b eginning of the game. Supp ose that dur ing the game Sp oiler p ebbles the v ariable u . Let T 1 , . . . , T s b e those newly created d ominated trees in G that hav e p ebbled ro ots r 1 , . . . , r s , for s ≥ 0. If s > 0, A F AST ALGORITHM AND DA T ALOG INEXPRESSIBILITY FOR TEMPORAL REASON ING 17 let r i b e the ro ot that r eceiv ed the minimal v alue a among all the ro ots r 1 , . . . , r s . W e claim that if u is the root of a dominated tree T , then a is str ictly larger than the m inim um b of all the v alues assigned to the lea ves of T . Other w ise, the graph T ∪ T i w as a dominated tree (since th e num b er of p ebb les is at m ost k ) that violates the inv arian t even b efore the v ariable u has b een p ebbled, a contradicti on. Therefore, in this case Duplicator can c ho ose a v alue c b et we en b and a f or the v ariable u . Sin ce c is s maller than a , in all the new dominated trees T 1 , . . . , T s in G the v alue assigned to r 1 , . . . , r s is strictly larger than c , and hence the in v ariant is p reserv ed. In particular, if R min ( w, u, v ) (or R min ( w, v , u )) is a constrain t in Φ wh er e w and v ha ve b een p ebbled, then this constraint is sat isfied b y the assignmen t. Since c is larger than b , this choic e also guaran tees that if v, v ′ are p ebbled v ariables then an y constrain t of the f orm R min ( u, v , v ′ ) is satisfied, b ecause in this case the v ariables u, v , v ′ induce a dominated tree with ro ot u in G . If there is n o d ominated tree T w here u is the ro ot, then Duplicator assigns a v alue to u that is smaller than all v alues a ssigned to o ther v ariables. If s = 0, Duplicator pla ys a v alue that is larger than all v alues assigned to other v ariables. In both cases it is ea sy to c hec k that Dup licator main tains the inv arian t, and satisfies all constraints φ ∈ Φ where all v ariables are p ebb led. By indu ction, w e h a v e shown that Dup licator h as a winn in g s tr ategy for the existen tial k -p ebble game on Φ . 6. Conclusion While most of the p olynomial algorithms that are kno wn and used to solv e infinite- domain constrain t satisfaction pr oblems are b ased on lo cal consistency tec hniqu es, we used graph algorithms on an appropriately d efined notion of constraint graph to b oth imp ro v e applicabilit y (the constrain t la nguages w e can solve with our approac h co nta in constrain t relations whose C SP can not b e s olved w ith lo cal consistency tec hniques – Theorem 5.2) and runn in g time (our algorithm has quadr atic runn ing time, wh ereas r esolution or establishing path consistency wo uld r equire cub ic time). W e b eliev e that similar approac hes can lead to faster algorithms and larger tractable languages for many problems wh ere the only kno wn algorithms are based on lo cal consistency tec hniqu es. Ac kno wledgemen ts W e wo uld lik e to thank Christopher Rudolf for implemen tin g th e algorithm, and the anon ymous referees for their h elpful comments. References [1] J. F. Allen. Maintaining kn o wledge ab out temp oral interv als. Communic ations of the ACM , 26(11):832– 843, 1983. [2] M. Bo dirsky and V. Dalmau. Datalog and constrain t satisf action with infinite templates. In Pr o c e e dings of ST ACS’06 , pages 646–659 , 2006. [3] M. Bo dirsky and V. Dalmau. Datalog and constrain t satisfactio n with infinite temp lates. An extende d ab- str act app e ar e d i n the pr o c e e dings of ST ACS’06. The ful l version is avail able online at arXi v:0809.2386v1 [cs.LO] , 2008. [4] M. Bod irsky and J. K´ ara. The complexity of temp oral constraint satisfaction p roblems. In Pr o c e e dings of STOC’ 08 , p ages 29–38, 2008. 18 M. BODIRSKY AND J. K ´ ARA [5] A. Bulatov, P . Jea vons, and A . Krok hin. The complexity of constrain t satisfaction: A n algebraic ap- proac h (a survey pap er). I n: Structur al The ory of Auto mata, Semigr oups and Universal Algebr a (Mon- tr e al, 2003), NA TO Scienc e Series II: M athematics, Physics, Chemi stry , 207:181–213, 2005. [6] A. Bulato v, A. Krokh in, and P . G. Jeav ons. Classifying the comp lexity of constrain ts using finite algebras. SIAM Journal on Computing , 34:720–74 2, 2005. [7] N. Creignou, M. Hermann, A. Krokhin, and G. Salzer. Complexity of clausal constraints ov er c hains. Researc h Rep ort, Ecole Po lytechnique, 2005. [8] R. Dech ter. Constr aint Pr o c essing . Morgan Kaufmann, 2003. [9] R. Diestel. Gr aph The ory, 3r d e dition . S pringer–V erlag, N ew Y ork, 2005. [10] T. Drakengren and P . Jonsson. Twen ty-one large t ractable sub class es of Allen’s algebra. A rtificial Intel l igenc e , 93:297–319 , 1997. [11] I . Duentsch. Relation algebras and th eir app lication in temp oral and spatial reasoning. Artificial Intel- ligenc e R eview , 23:315–3 57, 2005. [12] H .-D. Ebb inghaus and J. Flum. Fini te Mo del The ory . Sp ringer, 1999. 2nd edition. [13] T. F eder and M. V ardi. The compu t ational structure of monotone monadic S N P and constraint satis- faction: A stud y through Datalog and group th eory . SIAM Journal on Computing , 28:57–1 04, 1999. [14] M. Fisher, D . Gabbay , and L. Vila, editors. Handb o ok of T emp or al R e asoning in Artificial Intel ligenc e . Elsevier, 2005. [15] M. Garey and D. Johnson. A guide to N P-c ompleteness . CSLI Press, 1978. [16] M. C. Golumbic and R. Sh amir. Complexity and algorithms for reasoning ab out time: a graph-theoretic approac h. Journal of the ACM , 40(5):1108 – 1133, 1933. [17] W . Guttmann and M. Mauc her. V ariatio ns on an ordering th eme with constrain ts. In F ourth I FIP International Confer enc e on The or etic al Computer Scienc e (TCS’06), IFIP International F e der ation for Inf ormation Pr o c essing 209 , pages 77–90, 2006. [18] P . Hell and J. Ne ˇ set ˇ ril. Gr aphs and Homomorphisms . Ox ford Universit y Press, 2004. [19] W . H od ges. A shorter mo del the ory . Cambridge Universit y Press, 1997. [20] S . Janson, T. Lu czak, and A. Rucinsk i. R andom Gr aphs . John Wiley and Sons, 2000. [21] P . G. Kolaitis an d M. Y. V ardi. Conjunctive-query containmen t and constraint satisfactio n. I n Pr o c e e d- ings of PODS’98 , pages 205–213, 1998. [22] M. Koubarakis. T ractable disjunctions of linear constraints: Basic results and applications to temp oral reasoning. T he or etic al C omputer Sci enc e , 266:311–33 9, 2001. [23] A . Krokhin , P . Jeav ons, and P . Jonsson. R easoning ab out temp oral relations: The t ractable subalgebras of Allen’s interv al algebra. JACM , 50(5):591–640 , 2003. [24] P . B. Lad k in and R. D. Maddux. On binary constrain t problems. Journal of the Asso ciation for Com- puting Machinery , 41(3):435–469, 1994. [25] H . K. Marc Vilain and P . v an Beek. Constrai nt propagatio n algorithms for temporal reasoning: A revised rep ort. Re ading i n Qualitative R e asoning ab out Physic al Systems , pages 373–381, 1989. [26] D . Marker. Mo del T he ory: An I ntr o duction . Sp ringer, 2002. [27] R . H. M¨ ohring, M. Skutella, and F. S tork. Scheduling with and /or precedence constrain ts. SIAM J. Comput. , 33(2):393–415, 2004. [28] B. Nebel and H .-J. B ¨ urc kert. Reasoning ab out temp oral relations: A maximal tractable subclass of Allen’s interv al algebra. JACM , 42(1):43–66, 1995. [29] A . Szend rei. Clones in universal Algeb r a . Seminaire de mathematiqu es superieures. Les Presses de L’Universite de Montreal, 1986. [30] P . v an Beek. R easoning about q ualitative temp oral information. Ar tificial Intel ligenc e , 58:297– 326, 1992. [31] R . v an der Meyden. The complexity of q uerying indefinite information ab out linearly ordered d omains. Journal of Computer and Systems Scienc e , 54(1):113–135, 1997.
Original Paper
Loading high-quality paper...
Comments & Academic Discussion
Loading comments...
Leave a Comment