enhancing disjunctive datalog by constraints

36

Upload: unirc

Post on 10-Nov-2023

0 views

Category:

Documents


0 download

TRANSCRIPT

I N F S Y SResearchR e p o r t

Institut f�ur InformationssystemeAbtg. Wissensbasierte SystemeTechnische Universit�at WienTreitlstra�e 3A-1040 Wien, AustriaTel: +43-1-58801-18405Fax: [email protected]

Institut f�ur InformationssystemeAbteilung Wissensbasierte SystemeEnhancing DisjunctiveDatalog by ConstraintsF. Buccafurri N. Leone P. RulloINFSYS Research Report 1843-99-03February 1999

INFSYS Research ReportINFSYS Research Report 1843-99-03, February 1999Enhancing Disjunctive Datalogby ConstraintsFrancesco Buccafurri1 Nicola Leone2 Pasquale Rullo3Abstract. This paper presents an extension of Disjunctive Datalog (DATALOG_;:)by integrity constraints. These are of two types: strong, that is, classical integrityconstraints, and weak, that is, constraints that are satis�ed if possible. While strongconstraints must be satis�ed, weak constraints express desiderata, that is, theymay be violated - actually, their semantics tends to minimize the number of vio-lated instances of weak constraints. Weak constraints may be ordered accordingto their importance to express di�erent priority levels. As a result, the proposedlanguage (call it DATALOG_;:;c) is well-suited to represent commonsense reasoningand knowledge-based problems arising in di�erent areas of computer science suchas planning, graph theory optimizations and abductive reasoning.The formal de�nition of the language is �rst given. The declarative semantics ofDATALOG_;:;c is de�ned in a general way that allows us to put constraints on topof any existing (model-theoretic) semantics for DATALOG_;: programs. Knowl-edge representation issues are then addressed, and the complexity of reasoning onDATALOG_;:;c programs is carefully determined. An in-depth discussion on com-plexity and expressiveness of DATALOG_;:;c is �nally reported. The discussioncontrasts DATALOG_;:;c to DATALOG_;: and highlights the signi�cant increasein knowledge modeling ability carried out by constraints.Keywords. Knowledge Representation, Non-Monotonic Reasoning, DeductiveDatabases, Disjunctive Datalog, Computational Complexity.1DIMET Dep., University of Reggio Calabria, 89100 Reggio Cal., Italy, e-mail:[email protected] Systems Dept., Technical University of Vienna, A-1040 Vienna, Austria, e-mail:[email protected] Rullo is with the Dip. di Matematica, University of Calabria, 87030 Rende, Italy,e-mail: [email protected]: This work has been supported in part by FWF (Austrian ScienceFunds) under project P11580-MAT \A Query System for Disjunctive Deductive Databases".A short abridged version of this paper appeared in the Proc. of the conference LPNMR'97, pp. 2{17, SpringerCopyright c 1999 by the authors

INFSYS RR 1843-99-03 21 IntroductionDisjunctive Datalog (or DATALOG_;:) programs [18, 15] are nowadays widely recognized asa valuable tool for knowledge representation and commonsense reasoning [2, 34, 25, 20]. Animportant merit of DATALOG_;: programs over normal (that is, disjunction-free) Datalogprograms is their capability to model incomplete knowledge [2, 34]. Much research work hasbeen done so far on the semantics of disjunctive programs and several alternative proposalshave been formulated [5, 20, 40, 46, 47, 48, 51, 59]. One which is widely accepted is theextension to the disjunctive case of the stable model semantics of Gelfond and Lifschitz.According to this semantics [20, 46], a disjunctive program may have several alternativemodels (possibly none), each corresponding to a possible view of the reality. In [11, 15],Eiter, Gottlob and Mannila show that DATALOG_;: has a very high expressive power, as(under stable model semantics) the language captures the complexity class �P2 (i.e., it allowsus to express every property which is decidable in non-deterministic polynomial time withan oracle in NP).In this paper, we propose an extension of DATALOG_;: by constraints. In particular, be-sides classical integrity constraints (that we call �trongconstraints), we introduce the notionof weak constraints, that is, constraints that should possibly be satis�ed. Contrary to strongconstraints, that express conditions that must be satis�ed, weak constraints allow us to ex-press desiderata. The addition of (both weak and strong) constraints to DATALOG_;: makesthe language (call it DATALOG_;:;c) well-suited to represent a wide class of knowledge-basedproblems (including, e.g., planning problems, NP optimization problems, and abductive rea-soning) in a very natural and compact way.As an example, consider the problem SCHEDULING which consists in the scheduling ofexaminations for courses. That is, we want to assign course exams to time slots in such away that no two exams are assigned with the same time slot if the respective courses havea student in common (we call such courses � ncompatible"). Supposing that there arethree time slots available, namely, ts1, ts2 and ts3, we express the problem in DATALOG_;:;cby the following program Psch:r1 : assign(X; ts1) _ assign(X; ts2) _ assign(X; ts3) course(X)s1 : assign(X;S); assign(Y; S); incompatible(X; Y )Here we assumed that the courses and the pair of incompatible courses are speci�ed by anumber of input facts with predicate course and incompatible, respectively. Rule r1 saysthat every course is assigned to either one of the three time slots ts1, ts2 or ts3; the strongconstraint s1 (a rule with empty head) expresses that no two incompatible courses can beoverlapped, that is, they cannot be assigned to the same time slot. In general, the presenceof strong constraints modi�es the semantics of a program by discarding all models which donot satisfy some of them. Clearly, it may happen that no model satis�es all constraints. Forinstance, in a speci�c instance of problem above, there could be no way to assign courses totime slots without having some overlapping between incompatible courses. In this case, theproblem does not admit any solution. However, in real life, one is often satis�ed with an

INFSYS RR 1843-99-03 3approximate solution, that is, one in which constraints are satis�ed as much as possible. Inthis light, the problem at hand can be restated as follows (APPROX SCHEDULING): �assigncourses to time slots trying to not overlap incompatible courses". To express this problemwe resort to the notion of weak constraint, as shown by the following program Pa sch:r1 : assign(X; ts1) _ assign(X; ts2) _ assign(X; ts3) course(X)w1 : ( assign(X;S); assign(Y; S); incompatible(X; Y )From a syntactical point of view, a weak constraint is like a strong one where the implicationsymbol is replaced by (. The semantics of weak constraints minimizes the number ofviolated instances of constraints. An informal reading of the above weak constraint w1 is:"preferably, do not assign the courses X and Y to the same time slot if they are incompati-ble". Note that the above two programs Psch and Pa sch have exactly the same models if allincompatible courses can be assigned to di�erent time slots (i.e., if the problem admits an\exact" solution).In general, the informal meaning of a weak constraint, say, ( B, is try to falsify B�or "Bis preferably false", etc. (thus, weak constraints reveal to be very powerful for capturing theconcept of preference� n commonsense reasoning).Since preferences may have, in real life, di�erent priorities, weak constraints in DATALOG_;:;ccan be assigned with di�erent priorities too, according to their � mportance". 1 For ex-ample, assume that incompatibilities among courses may be either strong or weak (e.g., basiccourses with common students can be considered strongly incompatible, while complemen-tary courses give weak incompatibilities). Consider the following problem (SCHEDULINGWITH PRIORITIES): �chedule courses by trying to avoid overlapping between stronglyincompatible courses �rst, and by trying to avoid overlapping between weakly incompati-ble courses then"(i.e., privilege the elimination of overlapping between strongly incompat-ible courses). If strong and weak incompatibilities are speci�ed through input facts withpredicates strongly incompatible and weakly incompatible, respectively, we can representSCHEDULING WITH PRIORITIES by the following program Pp sch:r1 : assign(X; ts1) _ assign(X; ts2) _ assign(X; ts3) course(X)w2 : ( assign(X;S); assign(Y; S); strongly incompatible(X; Y )w3 : ( assign(X;S); assign(Y; S); weakly incompatible(X; Y )where the weak constraint w2 is de�ned �tronger than"w3. The models of the above pro-gram are the assignments of courses to time slots that minimize the number of overlappingsbetween strongly incompatible courses and, among these, those which minimize the numberof overlappings between weakly incompatible courses.The main contributions of the paper are the following:� We add weak constraints to DATALOG_;: and provide a formal de�nition of the lan-guage DATALOG_;:;c. The semantics of constraints is given in a general way that1Note that priorities are meaningless among strong constraints, as all of them must be satis�ed.

INFSYS RR 1843-99-03 4allows us to de�ne them on top of any existing model-theoretic semantics for Disjunc-tive Datalog.� We show how constraints can be pro�tably used for knowledge representation andreasoning, presenting several examples of DATALOG_;:;c encoding. DATALOG_;:;cturns out to be both general and powerful, as it is able to represent in a simple andcoincise way hard problems arising in di�erent domains ranging from planning, graphtheory, and abduction.� We analyze the computational complexity of reasoning with DATALOG_;:;c (propo-sitional case under stable model semantics). The analysis pays particular attentionto the impact of syntactical restrictions on DATALOG_;:;c programs in the form oflimited use of weak constraints, strong constraints, disjunction, and negation. It ap-pears that, while strong constraints do not a�ect the complexity of the language,weak constraints \mildly" increase the computational complexity. Indeed, we showthat brave reasoning is �P3 -complete (resp., �P2 -complete) for DATALOG_;:;c (resp.,DATALOG:;c) programs. Interestingly, priorities among constraints a�ect the com-plexity, which decreases to �P3 [O(logn)] (�P2 [O(logn)] for DATALOG:;c) if prioritiesare disallowed. The complexity results may support in choosing an appropriate frag-ment of the language, which �ts the needs in practice (see Section 5).� We carry out an in-depth discussion on expressiveness and complexity of DATALOG_;:;c,contrasting the language to DATALOG_;:. Besides adding expressive power from thetheoretical view point (as DATALOG_;:;c can encode problems which cannot be rep-resented at all in DATALOG_;:), it turns out that constraints improve also usabilityand knowledge modeling features of the language. Indeed, well-known problems canbe encoded in a simple and easy-to-understand way in DATALOG_;:;c; while theirDATALOG_;: encoding is unusable (long and di�cult to understand).Even if strong constraints (traditionally called integrity constraints) are well-known in thelogic programming community (see, e.g., [15, 10, 17, 33, 12]), to our knowledge this is the�rst paper which formally studies weak constraints and proposes their use for knowledge rep-resentation and reasoning. Related works can be considered the interesting papers of Grecoand Sacc�a [24, 23] which analyze other extensions of Datalog to express NP optimizationsproblems. Related studies on complexity of knowledge representation languages have beencarried out in [15, 50, 8, 14, 21, 39, 52, 9, 12]. Priority levels have been used also in thecontext of theory update and revision [16] and [22], in prioritized circumscription [31], inthe preferred subtheories approach for default reasoning [6], and in the preferred answer setsemantics for extended logic programs [7].The paper is organized as follows. In Section 2 we provide both the syntax and the seman-tics of the language. Then, in Section 3 we describe the knowledge representation capabilitiesof DATALOG_;:;c by a number of examples. In particular, we show how the language canbe used to easily formulate complex knowledge-based problems arising in various areas of

INFSYS RR 1843-99-03 5computer science, including planning, graph theory and abduction. In Section 4 we analyzethe complexity of the language under the possibility version of the stable model semantics.Finally, Section 5 reports an in-depth discussion on the language and draws our conclu-sions. Appendix A shows the encoding of a number of classical optimization problems inDATALOG_;:;c; while Appendix B reports the proofs of the complexity results for the frag-ments of DATALOG_;:;c where disjunction is either disallowed or constrained to the headcycle free case.2 The DATALOG_;:;c LanguageWe assume that the reader is familiar with the basic concepts of deductive databases [55, 34]and logic programming [32]. We describe next the extension of Disjunctive Datalog byconstraints.2.1 SyntaxA term is either a constant or a variable2. An atom is a(t1; :::; tn), where a is a predicate ofarity n and t1; :::; tn are terms. A literal is either a positive literal p or a negative literal:p, where p is an atom.A (disjunctive) rule r is a clause of the forma1 _ � � � _ an b1; � � � ; bk;:bk+1; � � � ;:bm; n � 1; m � 0where a1; � � � ; an; b1; � � � ; bm are atoms. The disjunction a1 _ � � � _ an is the head of r, whilethe conjunction b1; :::; bk;:bk+1; :::;:bm is the body of r. If n = 1 (i.e., the head is _-free),then r is normal; if m = 0 (the body is :-free), then r is positive. A DATALOG_;: programLP is a �nite set of rules; LP is normal (resp., positive) if all rules in LP are normal (resp.positive).A strong constraint is a syntactic of the form L1; � � � ; Lk, where Li, 1 � i � k, is aliteral (i.e., it is a rule with empty head).A weak constraint is a syntactic of the form ( L1; � � � ; Lk, where Li, 1 � i � k, is aliteral.De�nition 1 A DATALOG_;:;cprogram (often simply program") is a triple P = (LP ; S;W ),where LP is a DATALOG_;: program, S a (possibly empty) �nite set of strong constraintsand W = hW1; :::;Wni; is a (possibly empty) �nite list of components, each consisting of a�nite set of weak constraints. If w 2 Wi, w0 2 Wj and i < j, then we say that w0 is �trongerthan�or more important than"w (hence, the last component Wn is the strongest).2Note that function symbols are not considered in this paper.

INFSYS RR 1843-99-03 6Example 2 Consider the program Pp sch of Section 1. Here, LP p sch = fr1g, Sp sch = ;and Wp sch = hW1;W2i, where W1 = fw3g and W2 = fw2g (that is, w2 is stronger than w3).42.2 General SemanticsLet P = (LP ; S;W ) be a program. The Herbrand universe UP of P is the set of allconstants appearing in P. The Herbrand base BP of P is the set of all possible groundatoms constructible from the predicates appearing in P and the constants occurring inUP (clearly, both UP and BP are �nite). The instantiation of rules, strong and weakconstraints is de�ned in the obvious way over the constants in UP , and are denoted byground(LP ), ground(S) and ground(W ), respectively; we denote the instantiation of P byground(P) = (ground(LP ); ground(S); ground(W )).A (total) interpretation for P is a subset I of BP . A ground positive literal a is true (resp.,false) w.r.t. I if a 2 I (resp., a =2 I). A ground negative literal :a is true (resp., false) w.r.t.I if a =2 I (resp., a 2 I).Let r be a ground rule in ground(LP ). Rule r is satis�ed (or true) w.r.t. I if its head istrue w.r.t. I (i.e., some head atom is true) or its body is false (i.e., some body literal is false)w.r.t. I. A ground (strong or weak) constraint c in (ground(S) [ ground(W )) is satis�edw.r.t. I if (at least) one literal appearing in c is false w.r.t. I; otherwise, c is violated.We next de�ne the semantics of DATALOG_;:;c in a general way which does not rely on aspeci�c semantical proposal for DATALOG_;:; but, rather, it can be applied to any semanticsof Disjunctive Datalog. 3 To this end, we de�ne a candidate model for P = (LP; S;W ) as aninterpretationM for P which satis�es every rule r 2 ground(LP ). A ground semantics for Pis a �nite set of candidate models for P. Clearly, every classical semantics for LP provides aground semantics for P. For example the semantics presented in [20, 40, 46, 47, 48, 51, 59]can be taken as ground semantics.Now, to de�ne the meaning of a program P = (LP ; S;W ) in the context of a given groundsemantics, we need to take into account the presence of constraints. To this end, sinceweak constraints may have di�erent priorities, we associate with each component Wi 2 W ,1 � i � n, a positive weight f(Wi) inductively de�ned as follows:f(W1) = 1f(Wi) = f(Wi�1) � jground(W )j+ 1; 1 < i � nwhere jground(W )j denotes the total number of ground instances of the weak constraintsappearing in W . Further, given an interpretation M for a program P, we denote by HP;Mthe following sum of products:HP;M = f(W1) �NM1 + ::: + f(Wn) �NMn3Note that, although we consider only total model semantics in this paper, the semantics of weak con-straints simply extends to the case of partial model semantics.

INFSYS RR 1843-99-03 7where NMi (1 � i � n) is the number of ground instances of weak constraints in thecomponent Wi which are violated in M .Now, we are ready to de�ne the notion of model for P = (LP ; S;W ) w.r.t. a given groundsemantics.De�nition 3 Given a ground semantics � for P = (LP ; S;W ), a �-model of P is a candidatemodel M 2 � such that: (1) every strong constraint s 2 ground(S) is satis�ed w.r.t. M ,and (2) HP;M is minimum, that is, there is no candidate model N 2 � verifying Point (1)such that HP;N < HP;MThus, a �-modelM of P, by minimizingHP;M selects those candidate models that, besidessatisfying strong constraints, minimize the number of unsatis�ed (instances of) weak con-straints according to their importance - that is, those with the minimal number of violatedconstraints in Wn are chosen, and, among these, those with the minimal number of violatedconstraints in Wn�1, and so on and so forth.2.3 Stable Model SemanticsUsing the notion of candidate model we have parametrized the semantics of DATALOG_;:;cprograms, that is, the actual semantics of a program P relies on the semantics we choosefor LP . Several proposals can be found in the literature for disjunctive logic programs[5, 20, 40, 46, 47, 48, 51]. One which is generally acknowledged is the extension of the stablemodel semantics to take into account disjunction [20, 46]. We next report a brief discussionon this semantics.In [40], Minker proposed a model-theoretic semantics for positive (disjunctive) programs,whereby a positive program LP is assigned with a set MM(LP ) of minimal models, eachrepresenting a possible meaning of LP (recall that a modelM for LP is minimal if no propersubset of M is a model for LP ).Example 4 For the positive program LP = fa _ b g the (total) interpretations fag andfbg are its minimal models (i.e., MM(LP ) = f fag; fbg g). 4The stable model semantics generalises the above approach to programs with negation.Given a program LP and a total interpretation I, the Gelfond-Lifschitz transformation ofLP with respect to I, denoted by LP I , is the positive program de�ned as follows:LP I = fa1 _ � � � _ an b1; � � � ; bk ja1 _ � � � _ an b1; � � � ; bk;:bk+1; � � � ;:bm 2 ground(LP ) and bi =2 I; k < i � mgNow, let I be an interpretation for a program LP . I is a stable model for LP if I 2MM(LP I) (i.e., I is a minimal model of the positive program LP I). We denote the set ofall stable models for LP by SM(LP ).

INFSYS RR 1843-99-03 8Example 5 Let LP = fa _ b c; b :a;:c; a _ c :bg: Consider I = fbg.Then, LP I = fa _ b c; b g:It is easy to verify that I is a minimal model for LP I; thus, I is a stable model for LP . 4Clearly, if LP is positive then LP I coincides with ground(LP ). It turns out that, for apositive program, minimal and stable models coincide. A normal positive programs LP hasexactly one stable model which coincides with the least model of LP (i.e., it is the uniqueminimal model of LP ). When negation is allowed, however, even a normal program canadmit several stable models.We conclude this section observing that De�nition 3 provides the stable model semanticsof a DATALOG_;:;c program P = (LP ; S;W ) if the choosen ground semantics is SM(LP ),the set of the stable models of LP .De�nition 6 A �-model for a program P = (LP ; S;W ) is a stable model for P if � =SM(LP ).Example 7 Consider the program Psch = (LP sch; Ssch;Wsch) of Section 1; here, LP sch =fr1g, Ssch = fs1g andWsch = ;. According to the stable model semantics, LP sch has as manystable models as the possibilities of assigning all courses, say n, to 3 time slots (namely, 3n).The stable models of Psch are the stable models of LP sch satisfying the strong constraint s1,that is, those (if any) for which no two incompatible courses are assigned with the same timeslot.The program Pa sch = (LP a sch; Sa sch;Wa sch) of Section 1, where LP a sch = fr1g, Sa sch =; and Wa sch = hfw1gi, is obtained from LP sch by replacing s1 by w1 (note that LP a sch =LP sch). The stable models of Pa sch are the stable models of LP a sch which minimize thenumber of violated instances of w1, that is, the number of incompatible courses assigned tothe same time slots. Thus, Pa sch provides a di�erent solution from Pa sch only if the latterdoes not admit any stable model, i.e., the problem has no \exact" solution - there is no wayto assign di�erent time slots to all incompatible courses. Otherwise, the two programs haveexactly the same stable models.Finally, consider the program Pp sch = (LP p sch; Sp sch;Wp sch) of Section 1, where LP p sch =fr1g, Sp sch = ; andWp sch = hfw3g; fw2gi (read "w3 is weaker than w2"). Each stable modelof LP p sch is a possible assignment of courses to time slots. The stable models of Pp sch arethe stable models of LP p sch that, �rst of all, minimize the number of violated instance of w2and, in second order, minimize the number of violated instances of w3. 4It is worth noting that a DATALOG_;:;c program P may have several stable models (therecan also be no one). The modalities of brave and cautious reasoning are used to handle this.Brave reasoning (or credulous reasoning) infers that a ground literalQ is true in P (denotedP j=brave Q) i� Q is true w.r.t. M for some stable model M of P.Cautious reasoning (or skeptical reasoning) infers that a ground literal Q is true in P(denoted P j=cautious Q) i� Q is true w.r.t. M for every stable model M of P.The inferences j=brave and j=cautious extend to sets of literals as usual.

INFSYS RR 1843-99-03 93 Knowledge Representation in DATALOG_;:;cIn this section we provide a number of examples that show how DATALOG_;:;c can be usedto easily formulate many interesting and di�cult knowledge-based problems. Among those,we consider planning problems, classical optimization problems from Graph Theory andvarious forms of abductive reasoning. We show how the language provides natural supportfor their representation. A number of further examples are reported in AppendixA.As we shall see, most programs have a common structure of the form guess, check, choose-best. Candidate solutions are �rst nondeterministically generated (through disjunctiverules); then, mandatory properties are checked (through strong constraints), �nally, solu-tions that best satisfy desiderata are selected (through weak constraints). Such a modularstructure shows quite natural for expressing complex problems and, further, makes programseasy to understand.3.1 PlanningA �rst example of planning, namely the APPROX SCHEDULING problem, has been pre-sented in the introduction. A further example is next reported.Example 8 PROJECT GROUPS. Consider the problem of organizing a given set of em-ployees into two (disjoint) project groups p1 and p2. We wish each group to be possiblyheterogeneous as far as skills are concerned. Further, it is preferable that couple of personsmarried to each other do not work in the same group. And, �nally, we would like that themembers of the same group already know each other. We consider the former two require-ments more important than the latter one. Supposing that the information about employees,skills, known and married persons, are speci�ed through a number of input facts a simpleway of solving this problem is given by the following program Pproj:4r1 : member(X; p1) _member(X; p2) employee(X)w1 : ( member(X;P ); member(Y; P ); X 6= Y;:know(X; Y )w2 : ( member(X;P ); member(Y; P ); married(X; Y )w3 : ( member(X;P ); member(Y; P ); same skill(X; Y ); X 6= Ywhere w2 and w3 are stronger than w1 (i.e., W = hfw1g; fw2; w3gi. The �rst rule r1 aboveassigns each employee to either one of the two projects p1 and p2 (recall that, by minimalityof a stable model, exactly one of member(X; p1) and member(X; p2) is true in it, for eachemployee X). The weak constraint w1 expresses the aim of forming groups with persons thatpossibly already know each other; w2, in turn, expresses the preference of having groups withno persons married each other; and, �nally, the weak constraint w3 tries avoid that persons4For notational simplicity, in the examples we represent programs just as sets of rules and constraints.Observe also that we use the inequality predicate 6= as a built-in, this is legal as inequality can be easilysimulated in DATALOG_;:;c.

INFSYS RR 1843-99-03 10with the same skill work in same project. It is easy to recognize that each stable model of theDATALOG_;: program LP = fr1g is a possible assignment of employees to projects. Dueto the priority of weak constraints (recall that w2 and w3 are both �tronger than"w1) thestable models of Pproj are those of LP that minimize the overall number of violated instancesof both w2 and w3 and, among these, those minimizing the number of violated instances ofw1. For an instance, suppose that the employees are a; b; c; d; e, of which a and b havethe same skill, c and d are married to each other and, �nally, the following pairs knowreciprocally: (b; c), (c; d), (a; e), (d; e). In this case, Pproj has two stable models M1 andM2, which correspond to the following division in project teams (we list only the atoms withpredicate member of the two models).M1 : f member(a; p1); member(d; p1); member(e; p1); member(b; p2); member(c; p2)gM2 : f member(a; p2); member(d; p2); member(e; p2); member(b; p1); member(c; p1)gObserve that both M1 and M2 violate only two instances of w1 (as a and b do not knoweach other), and they satisfy all instances of w2 and w3. 43.2 Optimization from Graph TheoryIn the above example we have regarded weak constraints essentially as desiderata - that is,conditions to be possibly satis�ed. However, a useful way of regarding weak constraints is as�objective functions�of optimization problems. That is, a program with a weak constraint ofthe form( B can be regarded as modeling a minimization problem whose objective functionis the cardinality of the relation B (from this perspective, a strong constraint B can thenbe seen as a particular case in which the cardinality of the relation B is required to be zero).This suggests us to use DATALOG_;:;c to model optimization problems. Next we showsome classical NP optimization problems from graph theory formulated in our language. Anumber of further examples can be found in AppendixA.Example 9 MAX CLIQUE : Given a graph G = hV;Ei, �nd a maximum clique, that is,a subset of maximum cardinality C of V such that every two vertices in C are joined by anedge in E. To this end, we de�ne the following program Pcliq:r1 : c(X) _ not c(X) vertex(X)s1 : c(X); c(Y ); X 6= Y;:edge(X; Y )w1 : ( not c(X)Here, r1 partitions the set of vertices into two subsets, namely, c and not c - i.e., it guessesa clique c. The strong constraint s1 checks the guess, that is, every pair of vertices in c (theclique) must be joined by an edge. Finally, the weak constraint w1 minimizes the number ofvertices that are not in the clique c (thus, maximizing the size of c, by discarding all cliqueswhose size is not maximum). It holds that each stable model of Pcliq is a maximum clique ofG. 4

INFSYS RR 1843-99-03 11Example 10 MIN COLORING. Given a graph G = hV;Ei, a coloring of G is an assign-ment of colors to vertices, in such a way that every pair of vertices joined by an edge havedi�erent colors. A coloring is minimum if it uses a minimum number of colors. We deter-mine a minimum coloring by the following program Pcol:r1 : col(X; I) _ not col(X; I) vertex(X); color(I)s1 : col(X; I); col(Y; I); edge(X; Y )s2 : col(X; I); col(X; J); I 6= Js3 : vertex(X);:colored(X)r2 : colored(X) col(X; I)r3 : used col(I) col(X; I)w1 : ( used col(I)The �rst rule r1 guesses a graph coloring; col(X; I) says that vertex X is assigned to color Iand not col(X; I) that it is not. Strong constraints s1-s3 check the guess: two joined verticescannot have the same color (s1), and each vertex is assigned to exactly one color (s2 ands3). Finally, the weak constraint w1 requires the cardinality of the relation used col to beminimum (i.e., the number of used colors is minimum). It holds that there is a one-to-onecorrespondence between the stable models of Pcol and the minimum colorings of the graph G.43.3 AbductionWe next show that some important forms of abduction over (disjunctive) logic programs,namely abduction with prioritization and abduction under minimum-cardinality solutionpreference [14], can be represented in a very easy and natural way in DATALOG_;:;c (while,in general, they cannot be encoded in DATALOG_;:).Abduction, �rst studied by Peirce [43], is an important kind of reasoning, having wideapplicability in di�erent areas of computer science; in particular, it has been recognized asan important principle of common-sense reasoning. For these reasons, abduction plays acentral role in Arti�cial Intelligence, and has recently received growing attention also in the�eld of Logic Programming.Abductive logic programming deals with the problem of �nding an explanation for ob-servations, based on a theory represented by a logic program [35, 36]. Roughly speaking,abduction is an inverse of modus ponens: Given the clause a b and the observation a,abduction concludes b as a possible explanation. Following [13, 35, 36], an abductive logicprogramming problem (LPAP) can be formally described as a tuple P = hHyp;Obs; LP i,where Hyp is a set of ground atoms (called hypotheses), Obs is a set of ground literals(called manifestations or observations), and LP is a logic program (with disjunction andnegation allowed). An explanation for P is a subset E � Hyp which satis�es the followingproperty:

INFSYS RR 1843-99-03 12c db e

aFigure 1: A computer networkLP [E j=brave Obs, i.e., there exists a stable model M of LP [E, where all literals in Obsare true.In general, an LPAP may have no, a single, or several explanations. In accordance withOccam's principle of parsimony [42], which states that from two explanations the simplerexplanation is preferable, some minimality criterion is usually imposed on abductive expla-nations. Two important minimality criterions are Minimum Cardinality and Prioritization[14]. The minimum cardinality criterion states that a solution A � Hyp is preferable to asolution B � Hyp if jAj < jBj (where jXj denotes the cardinality of set X). According tothis criterion, the acceptable solutions of P are restricted to the explanations of minimumcardinality (that are considered the most likely).Example 11 ABDUCTION Consider the computer network depicted in Figure 1. We makethe observation that, sitting at machine a, which is online, we cannot reach machine e. Whichmachines are o�ine?This can be easily modeled as the LPAP Pnet = hHypnet; Obsnet; LPneti, where the theoryLPnet isLPnet = f reaches(X;X) node(X); : offline(X);reaches(X;Z) reaches(X; Y ); connected(Y; Z); : offline(Z);connected(a; b); connected(b; c); connected(b; d); connected(c; e);connected(d; e); node(a); node(b); node(c); node(d); node(e)gand the hypotheses and observations areHypnet = f offline(a); offline(b); offline(c); offline(d); offline(e) g;and Obsnet = f : offline(a); : reaches(a; e) g:respectively.For example, according with the intuition, E1 = foffline(b)g is an explanation for Pnet;but also E2 = foffline(b); offline(c)g is an explanation and even E3 = f offline(b);

INFSYS RR 1843-99-03 13offline(c); offline(d); offline(e) g is an explanation. However, under the minimum car-dinality criterion, only E1 = foffline(b)g, and E4 = foffline(e)g are the solutions of Pnet(we can see them as the most probable ones). 4Abduction with minimum cardinality can be represented very simply in DATALOG_;:;c.Given a LPAP P = hHyp;Obs; LP i, let pr(P) be the DATALOG_;:;c program (LP [G; S; hW0i), whereG = fh _ not h j h 2 HypgS = f �(o) j o 2 Obs gW0 = f( h j h 2 Hypgwhere �(o) = :o if o is a positive literal, and �(o) = a if o = :a (for each h 2 Hyp, not hdenotes a new symbol). It is easy to see that the stable models of pr(P) correspond exactlyto the minimum cardinality solutions of P5. Intuitively, the clauses in G "guess\ a solution(i.e., a set of hypoteses), the strong constraints in S check that the observations are entailed,and the weak constraints in W0 enforce the solution to have minimum cardinality.Example 12 (cont'd) The DATALOG_;:;c program for our network problem is pr(Pnet) =(LPnet [G; S; hW0i), where LPnet is the theory of Pnet andG = foffline(x) _ not offline(x) j x 2 fa; b; c; d; egg;S = f offline(a); reaches(a; e)g;W0 = f( offline(x) j x 2 fa; b; c; d; eggThe stable models of LPnet [ G that satisfy both strong constraints offline(a) and reaches(a; e) encode one-to-one the abductive explanations of Pnet; among them, the weakconstraints in W0 select the explanations with minimum cardinality. Indeed, pr(Pnet) hasonly two stable models: one contains offline(b) and the other contains offline(e). 4The method of abduction with priorities [14] is a re�nement of the above minimality cri-terion. Roughly speaking, it operates as follows. The set of hypotheses Hyp is partitionedinto groups with di�erent priorities, and explanations which are (cardinality) minimal on thelowest priority hypotheses are selected from the solutions. The quality of the selected solu-tions on the hypotheses of the next priority level is taken into account for further screening;5Without loss of generality, we assume that no hypothesis in Hyp appears in the head of a rule in LP .

INFSYS RR 1843-99-03 14this process is continued over all priority levels. As pointed out in [14], prioritization is alsoa qualitative version of probability, where the di�erent priorities levels represent di�erentmagnitude of probabilities. It is well suited in case no precise numerical values are known,but the hypotheses can be grouped in clusters such that the probabilities of hypothesesbelonging to the same cluster do not (basically) di�er compared to the di�erence betweenhypotheses from di�erent clusters [14].Example 13 (cont'd) Suppose that statistical data about the computers in the network ofFigure 1 tell us that b falls down very often, e is always online, while c and d sometimesare o�ine. Then, we restate the LPAP Pnet as an abductive problem with prioritizationP0net = hHyp<net; Obsnet; LPneti, whereHyp<net = hfoffline(b)g; foffline(c); offline(d)g; foffline(e)giAccording with the prioritization, the abductive explainations are ordered as follows:foffline(b)g < foffline(c); offline(d)g < foffline(e)gTherefore, foffline(b)g becomes the preferred (i.e., most likely) solution. (Note that, dif-ferently from the convention we adopted for weak constraints, the hypotheses of the smallestpriority level are the most important here). 4By using priorities among weak constraints, we obtain a very natural encoding of abductionwith prioritization. Given P = hhH1; :::; Hni; Obs; LP i, let pr(P) be the DATALOG_;:;cprogram (LP [G; S; hW1; :::;Wni), whereWi = f( h j h 2 Hn�i+1g (1 � i � n)and S and G are de�ned as above. Then, the stable models of pr(P) correspond exactly tothe preferred solutions of P according with the prioritization.Example 14 (cont'd)The DATALOG_;:;c program simulating abduction with priorities for the network of Ex-ample 11 is pr(P0net) = (LPnet [G; S; hW1;W2;W3i), where G and S are as above, andW1 = f( offline(e)g;W2 = f( offline(c);( offline(d)g;W3 = f( offline(b)g(recall that W3 is the strongest component). It is easy to see that pr(P0net) has only one stablemodel M which contains (only) the hypothesys offline(b). 4

INFSYS RR 1843-99-03 154 The Complexity of Constraints: Propositional CaseIn this section we analyze the complexity of brave reasoning over disjunctive Datalog pro-grams with constraints. Since the complexity is not independent from the underlying groundsemantics, we consider in this section the stable model semantics [20, 46], which is a widelyacknowledged semantics for normal and disjunctive Datalog programs.4.1 Preliminaries on Complexity TheoryFor NP-completeness and complexity theory, cf. [41]. The classes �Pk ;�Pk and �Pk of thePolynomial Hierarchy (PH) (cf. [53]) are de�ned as follows:�P0 = �P0 = �P0 = P and for all k � 1,�Pk = P�Pk�1 ;�Pk = NP�Pk�1 ;�Pk = co-�Pk :In particular, NP = �P1 , co-NP = �P1 , and �P2 = PNP. Here PC (resp. NPC) denotes the classof problems that are solvable in polynomial time on a deterministic (resp. nondeterministic)Turing machine with an oracle for any problem � in the class C.The oracle replies to a query in unit time, and thus, roughly speaking, models a call to asubroutine for � that is evaluated in unit time. If C has complete problems, then instancesof any problem �0 in C can be solved in polynomial time using an oracle for any C-completeproblem �, by transforming them into instances of �; we refer to this by stating that anoracle for C is used. Notice that all classes C considered here have complete problems.The classes �Pk , k � 2, have been re�ned by the class �Pk [O(logn)], in which the numberof calls to the oracle is in each computation bounded by O(logn), where n is the size of theinput.Observe that for all k � 1,�Pk � �Pk+1[O(logn)] � �Pk+1 � �Pk+1 � PSPACE;each inclusion is widely conjectured to be strict. Note that, by the rightmost inclusion,all these classes contain only problems that are solvable in polynomial space. They allow,however, a �ner grained distinction between NP-hard problems that are in PSPACE.The above complexity classes have complete problems under polynomial-time transfor-mations involving Quanti�ed Boolean Formulas (QBFs). A QBF is an expression of theform Q1X1Q2X2 � � � QkXk E; k � 1; (1)where E is a Boolean expression whose atoms are from pairwise disjoint nonempty sets ofvariables X1; : : : ; Xk, and the Qi's are alternating quanti�ers from f9; 8g, for all i = 1; : : : ; k.If Q1 = 9 then we say the QBF is k-existential, otherwise it is k-universal. Validity of QBFsis de�ned in the obvious way by recursion to variable-free Boolean expressions. We denoteby QBFk;9 (resp., QBFk;8) the set of all valid k-existential (resp., k-universal) QBFs (1).

INFSYS RR 1843-99-03 16Given a k-existential QBF � (resp. a k-universal QBF ), deciding whether � 2 QBFk;9(resp. 2 QBFk;8), is a classical �Pk -complete (resp. �Pk -complete) problem.�Pk has also complete problems for all k � 2; for example, given a formula E on variablesX1; :::; Xn; Y1; :::; Yr, r � 0, and a quanti�er patternQ1Y1; :::; QrYr, deciding whether the withrespect to hX1; :::; Xni lexicographically minimum truth assignment6 � to X1; : : : ; Xn suchthat Q1Y1 � � �QrYrE� 2 QBFk�2;8 (where such a � is known to exist) ful�lls �(Xn) = true(cf. [37, 58]).7 Also �Pk+1[O(logn)] has complete problems for all k � 1; for example, givenQBFs �1; : : : ;�m, such that �i =2 QBFk;9 implies �i+1 =2 QBFk;9, for 1 � i < m, decidewhether maxfi : 1 � i � m;�i 2 QBFk;9g is odd ([58, 14]).The problems remain as hard under the following restrictions: (a) E in (1) is in conjunctivenormal form and each clause contains three literals (3CNF) if Qk = 9, and (b) E is indisjunctive normal form and each monom contains three literals (3DNF) if Qk = 8 [54].4.2 Complexity ResultsWe analyze the complexity of the propositional case; therefore, throughout this section weassume that the programs and query literals are ground (i.e., variable-free). The complexityresults, however, can be easily extended to data complexity [57].Given a program P = (LP ; S; hW1; � � � ;Wni), we denote by maxH(P) the value that HP;Massumes when the interpretation M violates all the ground instances of weak constraints(in each component). More precisely, maxH(P) = �1�i�nf(Wi) � jground(Wi)j, wherejground(Wi)j is the cardinality of the set of the ground instances of the constraints in Wi.Observe that maxH(P) is exponential in the number of components of P; indeed, from the(inductive) de�nition of f(Wi) (see Section 2.2), it can be easily seen that maxH(P) =�(jground(W )jn). It turns out that (the value of) maxH(P) can be exponential in the sizeof the input; however, it is computable in polynomial time (its binary representation haspolynomial size).We next report detailed proofs of all complexity results of DATALOG_;:;c programs wherefull disjunction is allowed (these proofs are the most involved and technically interesting).The demonstrations of the results on disjunction-free programs and on head-cycle free dis-junctive programs are reported in AppendixB. All complexity results are sumarized in Table1, and discussed in-depth in Section 5.First of all, we look for an upper bound to the complexity of brave reasoning on DATALOG_;:;c.To this end, we provide two preliminary lemmata.Lemma 15 Given a DATALOG_;:;c program P = (LP; S;W ), and a positive integer n asinput, it is in �P2 deciding whether there exists a stable model M of LP satisfying S suchthat HP;M � n.6� is lexicographically greater than w.r.t. hX1; : : : ; Xni i� �(Xj) = true, (Xj) = false for the least jsuch that �(Xj) 6= (Xj).7QBF0;8 = QBF0;9 is the set of all variable-free true formulas.

INFSYS RR 1843-99-03 17Proof. We can decide the problem as follows. Guess M � BP , and check that: (1) M isa stable model of LP , (2) all constraints in S are satis�ed, and (3) HP;M � n. Clearly,property (2) and (3) can be checked in polynomial time; while (1) can be decided by a singlecall to an NP oracle [39, 15]. The problem is therefore in �P2 . 2Lemma 16 Given a DATALOG_;:;c program P = (LP; S;W ), a positive integer n, and aliteral q as input, it is in �P2 deciding whether there exists a stable model M of LP satisfyingS such that HP;M = n and q is true w.r.t. M .Proof. We can decide the problem as follows. Guess M � BP , and check that: (1) M isa stable model of LP , (2) all constraints in ground(S) are satis�ed, (3) HP;M = n, and (4)q is true w.r.t. M . Clearly, property (2), (3), and (4) can be checked in polynomial time;while (1) can be decided by a single call to an NP oracle [39, 15]. The problem is thereforein �P2 . 2Now, we are in the position to determine the upper bound to brave reasoning on fullDATALOG_;:;c programs.Theorem 17 Given a DATALOG_;:;c program P = (LP; S;W ), and a literal q as input,deciding whether q is true in some stable model of P is in �P3 .Proof. We �rst call a �P2 oracle to verify that P admits some stable model satisfying S(otherwise, q cannot be a brave consequence). We compute then (in polynomial time)k = maxH(P). After that, by binary search on [0::k], we determine the cost � of the stablemodels of P, by a polynomial number of calls to an oracle deciding whether there exists astable model M of LP satisfying S such that HP;M � n (n = k=2 on the �rst call; then ifthe oracle answers "yes", n = k=4; otherwise, n is set to k=2 + k=4, and so on, accordingto standard binary search) { the oracle is in �P2 by virtue of Lemma 15. (Observe that thenumber of calls to the oracle is logarithmic in k, and, as a consequence, is polynomial in thesize of the input, as the value k is O(2jPj).) Finally, a further call to a �P2 oracle veri�esthat q is true in some stable model of P, that is a stable model M of LP satisfying S withHP;M = � (this is doable in �P2 from Lemma 16). 2We will next strenghten the above result on �P3 -membership, to a completeness resultin this class. Hardness will be proven by reductions from QBFs into problems related tostable models of DATALOG_;:;c programs; the utilized disjunctive Datalog programs willbe suitable adaptations and extensions of the disjunctive program reported next (which hasbeen �rst described in [12]).Let � be a formula of form 8Y E, where E is a Boolean expression over propositionalvariables from X [ Y , where X = fx1; : : : ; xng and Y = fy1; : : : ; ymg. We assume that E is

INFSYS RR 1843-99-03 18in 3DNF, i.e., E = D1 _ � � � _Dr and each Di = Li;1 ^ Li;2 ^ Li;3 is a conjunction of literalsLi;j. De�ne the following (positive) Disjunctive Datalog program LP (�):xi _ x0i for each i = 1; : : : ; nyj _ y0j yj v y0j v for each j = 1; : : : ; mv yj; y0j for each j = 1; : : : ; mv �(Lk;1); �(Lk;2); �(Lk;3) for each k = 1; : : : ; rwhere � maps literals to atoms as follows:�(L) = 8><>: x0i if L = :xi for some i = 1; : : : ; ny0j if L = :yj for some j = 1; : : : ; mL otherwiseIntuitively, x0i corresponds to :xi and y0j corresponds to :yj.Given a truth assignment �(X) to X = fx1; : : : ; xng, we denote by M� � BLP (�) thefollowing interpretationM� = fxi j �(xi) = trueg [ fx0i j �(xi) = falseg [ fvg [ fy1; : : : ; ymg [ fy01; : : : ; y0mg:Moreover, given an interpretation M of LP (�), we denote by �M the truth assignment toX = fx1; : : : ; xng:�M(xi) = true iff xi 2M:Lemma 18 Let � = 8Y E and LP (�) be the formula and the disjunctive Datalog programde�ned above, respectively. Then, there is a one-to-one correspondence between the truthassignments �(X) to X = fx1; : : : ; xng such that �� = 8Y E�(X) is valid and the stablemodels of LP (�) which contain the atom v. In particular:1. if �� = 8Y E�(X) 2 QBF1;8, then M� 2 SM(LP (�)), and2. if M 2 SM(LP (�)) contains v, then ��M 2 QBF1;8.Proof. It follows from Theorems 3.1 of [12]. 2Note that LP (�) is constructible from � in polynomial time.We are now ready to determine exactly the complexity of reasoning over programs withconstraints.

INFSYS RR 1843-99-03 19Theorem 19 Given a DATALOG_;:;c program P = (LP; S;W ), and a literal q as input,deciding whether q is true in some stable model of P is �P3 -complete.Proof. From Theorem 17 it remains to prove only hardness. �P3 -hardness is shown byexhibiting a DATALOG_;:;c program that, under brave reasoning, solves the following �P3 -complete problem �: let �(X), X = fx1; : : : ; xng, be the lexicographically minimum truthassignment with respect to hx1; :::; xni such that �� = 8Y E�(X) is valid (we assume such a� exists); now, is it true that �(xn) = true?". W.l.o.g. we assume that E is in 3DNF of theform de�ned above. Let P 0 = fLP (�); ;;W 0g be a DATALOG_;:;c program where LP (�) isthe positive disjunctive Datalog program de�ned above, andW 0 = hf( xng; � � � ; f( x1g; f(:vgi. We next show that the answer to � is true i� xn is true in some stable model of P 0.Let SMv(LP (�)) denote the set of the stable models of LP (�) which contain v. FromLemma 18 we know that there is a one-to-one correspondence between SMv(LP (�)) andthe set of truth assignments � which make �� valid. Since �� is valid by hypothesis, thisimplies that SMv(LP (�)) 6= ;. Consequently, P 0 has some stable models (as there is nostrong constraint in P 0), and each stable model of P 0 contains v as ( :v is the strongestconstraint in W 0. The priorities among constraints ff( xng; � � � ; f( x1gg impose a totalorder on SMv(LP (�)). In particular, given two stable models M and M 0 in SMv(LP (�)),HP 0;M < HP 0;M 0 i� the truth assignment �M 0 is greater than �M in the lexicographically order.Therefore, P 0 has a unique stable modelM (which is in SMv(LP (�))), corresponding to thelexicographically minimum truth assignment � such that �� = 8Y E�(X) is valid. Hence, thelexicographically minimum truth assignment �(X) making �� valid ful�lls �(xn) = true ifand only if xn is true in some stable model of P 0. Therefore, brave reasoning is �P3 -hard forDATALOG_;:;c. 2Next we show that neither strong constraints nor negation a�ect the complexity of DATALOG_;:;cthat remains unchanged even if we disallow both of them.Corollary 20 Given a DATALOG_;:;c program P = (LP ; S;W ), and a literal q as input,deciding whether q is true in some stable model of P is �P3 -complete even if strong constraintsare disallowed (S = ;) and LP is strati�ed or even positive.Proof. Membership in �P3 trivially holds from Theorem 17. As far as hardness is concerned,observe that in the reduction of Theorem 19 the DATALOG_;:;c program P 0 has no strongconstraints (i.e., S = ;) and its logic program LP (�) is positive (and therefore strati�ed).2 Thus, the syntactic restrictions imposed in Corollary 20 do not decrease the complexityof DATALOG_;:;c. Interestingly, the complexity of the language decreases if we disallowpriorities among weak constraints.

INFSYS RR 1843-99-03 20Theorem 21 Given a DATALOG_;:;c program P = (LP ; S;W ), where W consists of asingle component, and a literal q as input, deciding whether q is true in some stable modelof P is �P3 [O(logn)]-complete.Proof. �P3 [O(logn)]-Membership. We proceed exactly as in the proof of Theorem 17. How-ever, since W consists of one only component, this time k = maxH(P) is O(jPj) (while forprograms with priorities is O(2jPj)), as there is only one component in W and its weight is1. Consequently, the number of calls to the �P2 oracle is logarithmic in the size of the input,as it is logarithmic in k (because we perform a binary search on [0::k]).�P3 [O(logn)]-Hardness. Let �1; : : : ;�m be 2-existential QBFs, such that �i =2 QBF2;9 implies�i+1 =2 QBF2;9, for 1 � i < m. We next reduce the �P3 [O(logn)]-hard problem of decidingwhether maxfi : 1 � i � m;�i 2 QBF2;9g is odd to brave reasoning on DATALOG_;:;cprograms without priorities (i.e., with one only component in W ). W.l.o.g. we assume that1) m is even, 2) the same propositional variable does not appear in two distinct QBFs. and3) the QBFs �1; : : : ;�m are as in the proof of Theorem 19.Now, let P 0 = (LP 0; S 0;W 0), where:a) LP 0 = LP (�1) [ � � � [ LP (�m) [1�i�m=2 fodd v2i�1;:v2ig and LP (�i) is de�ned asin Theorem 19 apart from replacing each occurrence of v by vi;b) S 0 = ;;c) W 0 = hf( :v1; ( :v1;:v2; � � � ( :v1; :::;:vmgi.The weak constraints in W 0 enable to select the stable models of LP (�) where the numberof valid QBFs is maximum. Then, maxfi : 1 � i � m;�i 2 QBFk;9g is odd if and only if oddis true in some stable model of P. 2As for DATALOG_;:;c programs with prioritized weak constraints, the complexity is nota�ected at all by negation and strong constraints.Corollary 22 Let P = (LP; S;W ) be a DATALOG_;:;c program where W has a singlecomponent. Then, brave reasoning is �P3 [O(logn)]-complete even if P is subject to thefollowing restrictions:1) S = ;, and2) LP is strati�ed or even positive.Proof. Membership in �P3 [O(logn)] comes from Theorem 21. Hardness under the restriction1 for strati�ed programs comes from the hardness proof of Theorem 21, as the reductionthere does not make use of both priorities and strong constraints and utilizes only strati�ednegation. To complete the proof we have only to demonstrate hardness for the case ofpositive programs. To this end, we just need to eliminate negation from the logic programLP 0 (of the proof of Theorem 21) as follows:

INFSYS RR 1843-99-03 211. Eliminate from LP 0 all rules with head odd (that are the only rules containing nega-tion).2. Insert the following weak constraints in W :( v2i�1;:v2i; even (1 � i � m=2)25 Discussion on Complexity and Expressiveness of DATALOG_;:;cIn this section we discuss the results on the complexity of DATALOG_;:;c that we establishedin the previous section. Interestingly, these results allow us to draw some useful remarks alsoon the expressive power of our language, which turns out to be strictly more powerful thandisjunctive Datalog (without constraints). We show also that the increased expressive powerof our language has a relevance even from the practical side, providing some meaningfulexamples that can be represented very naturally in DATALOG_;:;c, while their disjunctiveDatalog encoding is impossible (or so complex to be unusable).

INFSYS RR 1843-99-03 221 2 3 4 5 6fg fsg fwg fs;wg fw<g fs;w<g1 fg P P P P P P2 f:sg P P P P P P3 f:g NP NP �P2 [O(log n)] �P2 [O(log n)] �P2 �P24 f_hg NP NP �P2 [O(log n)] �P2 [O(log n)] �P2 �P25 f_h;:sg NP NP �P2 [O(log n)] �P2 [O(log n)] �P2 �P26 f_h;:g NP NP �P2 [O(log n)] �P2 [O(log n)] �P2 �P27 f_g �P2 �P2 �P3 [O(log n)] �P3 [O(log n)] �P3 �P38 f_;:sg �P2 �P2 �P3 [O(log n)] �P3 [O(log n)] �P3 �P39 f_;:g �P2 �P2 �P3 [O(log n)] �P3 [O(log n)] �P3 �P3Table 1: The Complexity of Brave Reasoning in various Extensions of Datalog with Con-straints (Propositional Case under Stable Model Semantics)Table 1 sumarizes the complexity results of the previous section, complemented with otherresults (on the complexity of programs without constraints) already known in the literature.Therein, each column refers to a speci�c form of constraints, namely: fg = no constraints, s= strong constraints, w< = weak constraints with priorities, w = weak constraints withoutpriorities (i.e., W has only one component). The lines of Table 1 specify the allowance ofdisjunction and negation; in particular, :s stands for strati�ed negation [45] and _h standsfor HCF disjunction [3] (see AppendixB). Each entry of the table provides the complexityclass of the corresponding fragment of the language. For an instance, the entry (8; 5) de�nesthe fragment of DATALOG_;:;c allowing disjunction and strati�ed negation (f_;:sg) and,as far as constraints is concerned, only weak constraints with priorities (fw<g); that is,unstrati�ed negation and strong constraints are disallowed in this fragment. The languagesDATALOG: and DATALOG_;: correspond to the fragments (3,1) and (9,1), respectively.Full DATALOG_;:;c is the fragment (9,6), whose complexity is reported in the lower rightcorner of the table. The corresponding entry in the table, namely �P3 , expresses that thebrave reasoning for DATALOG_;:;c is �P3 -complete.The �rst observation is that DATALOG_;:;c is strictly more expressive than DATALOG_;:.Indeed, the former language can express all problems that can be represented in the lat-ter, as DATALOG_;:;c is an extension of DATALOG_;:. Moreover, the �P3 -completenessof DATALOG_;:;c witnesses that DATALOG_;:;c can express some �P3 -complete problems,while DATALOG_;: cannot (unless the Polynomial Hierarchy collapses) [15]. An example of

INFSYS RR 1843-99-03 23encoding of a �P3 -complete problem has been reported in the proof of Theorem 19. To seeanother example, consider again abductive reasoning addressed in Section 3.3. A hypothesisis relevant for a logic programming abductive problem P if it occurs in some explanation ofP; under minimum cardinality (resp. prioritized) abduction, relevance requires membershipto a minimum cardinality solution (resp. minimal solution according to the prioritization).From the results of [13, 14], deciding relevance is �P3 [O(logn)]-complete for abduction withminimum cardinality criterion, while it is �P3 -complete for prioritized abduction. There-fore, relevance of an hypothesis h for a logic programming abduction problem cannot beexpressed reasoning on disjunctive Datalog (as �P2 is an upper bound to the complexity ofbrave reasoning on DATALOG_;: [15]). On the other hand, from the translation we providedin Section 3.3, it is easy to see that h is relevant for P i� it is a brave consequence of pr(P)(i.e., relevance can be reduced to brave reasoning on DATALOG_;:;c). 8Considering that DATALOG_;:;c is a linguistic extension of DATALOG_;: by constraints,it turns out that constraints do add expressive power to DATALOG_;:. However, it is notthe case of strong constraints, as it can be seen from Table 1. Indeed, if we look at the variousfragments of the language that di�er only for the presence of strong constraints, we can notethat complexity is constant (compare column 1 to 2, or 3 to 4, or 5 to 6). In fact, under stablemodel semantics, a strong constraint of the form B is actually a shorthand for p B;:p.As an example, consider the problem SCHEDULING of Section 1. The program Psch we usedto express SCHEDULING relies on HCF disjunction with strati�ed negation and containsonly one strong constraint (no weak constraints occur in it - fragment (5,2)). This problemcan be easily formulated in HCF DATALOG_;: with unstrati�ed negation (fragment (6,1))simply by replacing the strong constraint assign(X;S); assign(Y; S); incompatible(X; Y )by the DATALOG: rulep assign(X;S); assign(Y; S); incompatible(X; Y );:pwhere p is a new atom.9 It is worth noting that brave reasoning allows us to simulate strongconstraints if negation is not allowed in the program: replace each strong constraint Bby the rule p B (where p is a fresh atom), and require that :p is a brave consequence.Thus, it is rather clear that strong constraints do not a�ect at all the complexity andexpressiveness of the language. Therefore, the increased expressive power of DATALOG_;:;c(w.r.t. DATALOG_;:) is due entirely to weak constraints. However, weak constraints do not8Note that we have �P3 -hardness only if disjunction is allowed in the abductive theory LP . Thus, examplePnet is not an hard instance of the problem; but the translation we gave is general and holds also for hardinstances with disjunction in the abductive theory LP .9actually, the SCHEDULING problem can be even formulated in DATALOG:, as HCF disjunctioncan be simulated by unstrati�ed negation. Indeed, the \guess" expressed by the disjunctive rule can beimplemented by the following three nondisjunctive rulesassign(X; ts1) course(X);:assign(X; ts2);:assign(X; ts3)assign(X; ts2) course(X);:assign(X; ts1);:assign(X; ts3)assign(X; ts3) course(X);:assign(X; ts1);:assign(X; ts2)

INFSYS RR 1843-99-03 24cause a tremendous increase of the computational cost, they \mildly" increase the complexity,as we can see by comparing column 1 to columns 3 and 5 of Table 1. For example, ifwe add weak constraints to HCF disjunction (with or without negation - see lines 4-6)we increase the complexity from NP to �P2 [O(logn)] or �P2 , depending on whether weakconstraints are prioritized or not, respectively. Note that the program Pcliq of Example 9consists of a weak constraint on top of an HCF program. Likewise, weak constraints addedto DATALOG_;: increase its complexity from �P2 to �P3 [O(logn)] or �P3 , depending on thepossible prioritization of weak constraints (see lines 7-9). Therefore, adding weak constraints,the complexity of the language always remains at the same level of the polynomial hierarchy;for instance, from NP we can reach �P2 [O(logn)] or �P2 , but we will never jump to �P2 or toother classes of the second level of the polynomial hierarchy.Clearly, weak constraints do not impact on the complexity of fragments admitting a uniquestable model (see lines 1 and 2).Further remarks on the complexity of the various fragments of the language are the fol-lowing. First, the presence of negation does not impact on the complexity of the fragmentsallowing disjunction (see lines 4 to 9). Second, the complexity of the _-free fragmentswith full negation (see line 3) coincides with that of HCF disjunction (lines 4 to 6) andlies one level down in the polynomial hierarchy with respect to fragments based on plainDATALOG_;: (see line 9).Besides the increase in theoretical expressiveness { the ability to express problems thatcannot be represented in DATALOG_;: { DATALOG_;:;c provides another even more im-portant advantage: several problems that can be represented also in DATALOG_;: (whosecomplexity is thus not greater than �P2 ) admit a much more natural and easy-to-understandencoding in DATALOG_;:;c. This is because coupling both disjunction and constraints, pro-vides a powerful and elegant tool to encode knowledge. To better appreciate the simplicityand readability of DATALOG_;:;c, consider again the problem MAX CLIQUE, that hasbeen represented very simply and elegantly in DATALOG_;:;c (see Example 9). We nextshow that it can be encoded also in DATALOG_;: but, unfortunately, the resulting programis very tricky and di�cult to understand. The technique we use to build a DATALOG_;:version of MAX CLIQUE is that described in [15], based on a modular approach. A �rstmodule LP1 generates candidate solutions (cliques in this case) and a second module LP2discards those that do not satisfy certain criteria (maximal cardinality here).r1 : c(X) _ not c(X) node(X)r2 : p c(X); c(Y ); X 6= Y;:edge(X; Y );:pr3 : count(0; 0) r4 : count(I; J) c(I); count(A;B); succ(A; I); succ(B; J)r5 : count(I; B) not c(I); count(A;B); succ(A; I)r6 : c size(K) greatestV ertex(X); count(X;K)r7 : greatestV ertex(X) node(X);:greaterThan(X)r8 : greaterThan(X) succ(X; Y )The above disjunctive program LP1 generates all cliques and their sizes. We have assumed

INFSYS RR 1843-99-03 25that the nodes are ordered by the relation succ that is provided in input (but could also be\guessed" by another module). Rule r1 guesses a clique c and rule r2 enforces the constraintthat every two nodes in c must be joined by an edge. By this rule the constraint must besatis�ed in every stable model (if the constraint is unsatis�able, then no stable model exist).The atom count(I; J) expresses that the node I is the J-th node of the clique c. Thus, ruler6 de�nes the size (number of nodes) of c.Now, to restrict to only maximum size cliques, we add to LP1 the following DATALOG_;:program LP2 which discards clique nonmaximal in size.r01 : c0(X) _ not c0(X) node(X)r02 : notGreater c0(X); c0(Y ); X 6= Y;:edge(X; Y )r03 : count1(0; 0) r04 : count1(I; J) count1(A;B); succ(A; I); succ(B; J); c0(I)r05 : count1(I; B) count1(A;B); succ(A; I); not c0(I)r06 : c0 size(K) greatestV ertex(N); count1(N;K)r07 : notGreater c size(K); c0 size(I); I � Kr08 : c0(X) node(X); notGreaterr09 : not c0(X) node(X); notGreaterr010 : q :notGreater;:qHere, r01 guesses another clique c0. notGreater is true if c0 is not a clique. count1 countsthe elements of c0 and c0 size de�ne the size of c0. If the size of c0 is less than or equal tothat of c then notGreater is true. If so, c0 and not c0 are assigned the maximum extensionby rules r08 and r09. In this way, if all cliques c0 are smaller than c then all stable models ofLP2 collapse into a single stable model with the maximum extension for both c and c0 andcontaining notGreater. If, on the contrary, there is some clique c0 bigger than c, then nostable model of LP2 contains notGreater. Thus, the rule r010 imposes every stable model tocontain notGreater (if any). It is easy to recognize that, for the program LP = LP1 [ LP2,there is a one-to-one correspondence between stable models and maximum cliques of G.Comparing the above DATALOG_;: program with the DATALOG_;:;c version of Example9,10 it is quite apparent the advantage that weak constraints provide in terms of simplicityand naturalness of programming.Concluding, we would like to bring reader's attention to the fragment of DATALOG_;:;cwith HCF disjunction and strati�ed negation ((5,6) in Table 1): it has a very clear and easy-to-understand semantics and, at the same time, allows us to express several hard problems(up to �P2 -complete problems) in a natural and compact fashion. (In our opinion, recursionthrough disjunction or negation makes programs more di�cult to understand).10Perhaps our DATALOG_;: encoding of MAX CLIQUE is not the best; but we are very skeptical on theexistence of a DATALOG_;: encoding which is simpler than the DATALOG_;:;c encoding (of example 9).

INFSYS RR 1843-99-03 26References[1] Apt, K.R., Bol, R.N. (1994), Logic Programming and Negation: A Survey, Journal ofLogic Programming, 19/20, 9{71.[2] Baral, C., Gelfond, M. (1994), Logic Programming and Knowledge Representation Jour-nal of Logic Programming, 19/20, 73{148.[3] Ben-Eliyahu, R., Dechter, R. (1994), Propositional Semantics for Disjunctive Logic Pro-grams. Annals of Mathematics and Arti�cial Intelligence, 12, 53{87.[4] Ben-Eliyahu, R., Palopoli, L. (1994), Reasoning with Minimal Models: E�cient Al-gorithms and Applications. In Proc. Fourth International Conference on Principles ofKnowledge Representation and Reasoning (KR-94), pp. 39{50.[5] Brass, S., Dix, J. (1995), Disjunctive Semantics Based upon Partial and Bottom-UpEvaluation, In Proc. of the 12th Int. Conf. on Logic Programming, Tokyo, pp. 199{213,MIT Press.[6] Brewka, G. (1991), Nonmonotonic Reasoning: Logical Foundations of Commonsense.Cambridge University Press.[7] Brewka, G., Eiter, T. (1998), Preferred Answer Sets for Extended Logic Programs, InProc. KR'98. Forthcoming.[8] Cadoli, M., Schaerf, M. (1993), A Survey of Complexity Results for Non-monotonicLogics, Journal of Logic Programming, 17, pp. 127-160.[9] Chomicki, J., Subrahmanian, V.S. (1990), Generalized Closed World Assumption is�02-Complete. Information Processing Letters, 34, pp. 289{291.[10] Decker, H., Celma, M. (1994) A slick procedure for integrity checking in deductivedatabases, In Proc. of the Eleventh Int. Conference on Logic Programming, S. MargheritaLigure", Italy, pp. 456 { 469, MIT Press.[11] Eiter, T., Gottlob, G., Mannila, H. (1994), Adding Disjunction to Datalog, In Proc.ACM PODS-94, pp. 267{278.[12] Eiter, T., Gottlob, G. (1995), On the Computational Cost of Disjunctive Logic Pro-gramming: Propositional Case, Annals of Mathematics and Arti�cial Intelligence, J. C.Baltzer AG, Science Publishers, 15, 289{323.[13] Eiter, T., Gottlob, G., Leone, N. (1997), Abduction From Logic Programs: Seman-tics and Complexity. Theoretical Computer Science { Logic, Semantics and Theory ofprogramming, Elsevier, 189(1-2), pp. 129{177.

INFSYS RR 1843-99-03 27[14] Eiter, T., Gottlob, G. (1995) The Complexity of Logic-Based Abduction, Journal of theACM, 42(1), 3{42.[15] Eiter, T., Gottlob, G., Mannila, H. (1997) Disjunctive Datalog, ACM Trans. DatabaseSyst., 22(3), 315{363.[16] Fagin, R., Ullman, J. D., Vardi, M. Y. (1983) On the Semantics of Updates in Databases,In Proc. PODS-83, pp 352{365.[17] Fern�andez, J.A., Lobo, J., Minker, J., Subrahmanian V.S. (1993), Disjunctive LP +Integrity Constraints = Stable Model Semantics, Annals of Mathematics and Arti�cialIntelligence, 8(3-4), 449{474.[18] Fern�andez, J.A., Minker, J. (1992), Semantics of Disjunctive Deductive Databases, InProc. 4th Intl. Conference on Database Theory (ICDT-92), Berlin, pp. 21{50.[19] Garey, M., Johnson, D.S. (1979) Computers and Intractability { A Guide to the Theoryof NP-Completeness, W. H. Freeman, New York.[20] Gelfond, M., Lifschitz, V. (1991), Classical Negation in Logic Programs and DisjunctiveDatabases, New Generation Computing, 9, 365{385.[21] Gottlob, G. (1994), Complexity and Expressive Power of Disjunctive Logic Pro-gramming, In Proc. of the International Logic Programming Symposium (ILPS-'94),M. Bruynooghe ed., Ithaca NY, pp. 23{42, MIT Press.[22] Ginsberg, M. L. (1986) Counterfactuals, Arti�cial Intelligence, 30, 35{79.[23] Greco, S. (1996), Extending Datalog with Choice and Weak Constraints, In Proc. of theJoint Conference on Declarative Programming APPIA-GULP-PRODE'96, Donostia-SanSebastian, Spain, pp.329{340.[24] Greco, S., Sacc�a, D. (1997), NP Optimization Problems in Datalog, In Proc. of theInternational Logic Programming Symposium (ILPS '97), Port Je�erson, USA.[25] IFIP-GI Workshop (1994), "Disjunctive Logic Programming and Disjunctive Data-bases," 13-th IFIP World Computer Congress.[26] Kadin, J. (1989), PNP [O(logn)] and Sparse Turing-Complete Sets for NP , Journal ofComputer and System Sciences, 39, 282{298.[27] Krentel, M. (1988), The Complexity of Optimization Problems. Journal of Computerand System Sciences, 36, 490{509.[28] Kowalski, R., Sadri, F. (1988) A theorem-proving approach to database integrity, inJ. Minker (ed), Foundations of Deductive Databases and Logic Programming, 313{362,Morgan Kaufman.

INFSYS RR 1843-99-03 28[29] Leone, N., Rullo, P., Scarcello, F. (1995) Declarative and Fixpoint Characterizations ofDisjunctive Stable Models, In Proceedings of International Logic Programming Sympo-sium (ILPS'95), Portland, Oregon, pp. 399{413, MIT Press.[30] Leone, N., Rullo, P., Scarcello, F. (1997) Disjunctive Stable Models: Unfounded Sets,Fixpoint Semantics and Computation, Information and Computation, Academic Press,135(2), 69{112.[31] Lifschitz, V. (1985) Computing Circumscription, In Proc. of IJCAI-85, pp 121{127.[32] Lloyd, J. W. (1984) Foundations of Logic Programming. Springer, Berlin.[33] Lloyd, J.W., Sonenberg, E.A., Topor, R.W. (1987) Integrity constraint checking instrati�ed databases, Journal of Logic Programming, 2, 331{343.[34] Lobo, J., Minker, J., Rajasekar, A. (1992) Foundations of Disjunctive Logic Program-ming MIT Press, Cambridge, MA.[35] Kakas, A., Mancarella, P. (1990) Generalized stable models: a semantics for abduction,In Proc. of ECAI-90, pp. 385{391.[36] Kakas, A., Kowalski, R., Toni, F. (1992) Abductive Logic Programming. Journal ofLogic and Computation, 2(6), 719{771.[37] Krentel, M. (1992), Generalizations of OptP to the Polynomial Hierarchy, TheoreticalComputer Science, 97(2) 183{198.[38] Marek, W., Subrahmanian, V.S. (1989), The Relationship between Logic Program Se-mantics and Non-Monotonic Reasoning, In Proc. of the 6th International Conference onLogic Programming { ICLP'89, pp. 600{617, MIT Press.[39] Marek, W., Truszczy�nski, M. (1991), Autoepistemic Logic, Journal of ACM, 38(3),588{619.[40] Minker, J. (1982), On Inde�nite Data Bases and the Closed World Assumption, In Proc.of the 6th Conference on Automated Deduction (CADE-82), pp. 292{308.[41] Papadimitriou, C.H. (1994), Computational Complexity, Addison-Wesley.[42] Peng, Y., Reggia, J. (1990) Abductive Inference Models for Diagnostic Problem Solving,Springer.[43] Peirce, C.S. (1955) Abduction and induction, In J. Buchler, editor, PhilosophicalWritings of Peirce, chapter 11. Dover, New York.[44] Przymusinska, H., Przymusinski, T. (1988), Weakly Perfect Model Semantics for LogicPrograms, In Proc. Fifth Int. Conf. and Symp. on Logic Programming, pp.1106-1120.

INFSYS RR 1843-99-03 29[45] Przymusinski, T. (1988), On the Declarative Semantics of Deductive Databases andLogic Programming, in \Foundations of deductive databases and logic programming,"Minker, J. ed., ch. 5, pp.193{216, Morgan Kaufman, Washington, D.C.[46] Przymusinski, T. (1991), Stable Semantics for Disjunctive Programs, New GenerationComputing, 9, 401{424.[47] Przymusinski, T. (1995), Static Semantics for Normal and Disjunctive Logic Programs,Annals of Mathematics and Arti�cial Intelligence, J. C. Baltzer AG, Science Publishers,14, 323{357.[48] Ross. K.A. (1990), The Well Founded Semantics for Disjunctive Logic Programs, in\Deductive and Object{Oriented Databases," W. Kim, J.{M. Nicolas and S. Nishio, ed.,pp.385{402, Elsevier Science Publishers B. V.[49] Ross, K.A. (1990), Modular Strati�cation and Magic Sets for Datalog Programs withNegation, In Proc. ACM Symposium on Principles of Database Systems, pp.161-171.[50] D. Sacc�a (1997) The Expressive Powers of Stable Models for Bound and UnboundDATALOG Queries, Journal of Computer and System Sciences, 54(3), 441{464.[51] Sakama, C. (1989), Possible model semantics for disjunctive databases, In Proc. of the�rst international conference on deductive and object oriented databases, pp.1055{1060.[52] Schlipf, J.S. (1990) The Expressive Powers of Logic Programming Semantics, In Proc.ACM Symposium on Principles of Database Systems, pp. 196-204.[53] Stockmeyer, L. (1987) Classifying the Computational Complexity of Problems,. Journalof Symbolic Logic, 52(1), 1{43.[54] Stockmeyer, L., Meyer, A. (1973), Word Problems Requiring Exponential Time, InProceedings of the Fifth ACM Symposium on the Theory of Computing, pp. 1{9.[55] Ullman, J.D. (1989) Principles of Database and Knowledge-Base Systems, ComputerScience Press, Rockville, Maryland (USA).[56] Van Gelder, A., Ross, K. A., Schlipf, J. S. (1991), The Well-Founded Semantics forGeneral Logic Programs, Journal of ACM, 38(3), 620{650.[57] Vardi, M. (1982), Complexity of relational query languages, In Proc. oh the 14th ACMSTOC, pp. 137{146.[58] Wagner, K. (1990), Bounded query classes; SIAM J. Comp., 19(5), 833{846.[59] You J.H., Yuan, L. (1994), A Three-Valued Semantics for Deductive Databases andLogic Programs, Journal of Computer and System Sciences, 49, 334{361.

INFSYS RR 1843-99-03 30AppendicesA Sample Optimization Problems in DATALOG_;:;cWe list below a number of optimization problems [19] and their representation in DATALOG_;:;c.MAX SATISFIABILITY. Let E be a boolean formula in conjunctive normal form; �nda truth assignment that satisfy simultaneously the maximum number of clauses of E. Tothis end, we are given two unary relations clause and var such that a fact clause(x) saysthat x is a clause and var(v) that v is a variable occurring in some clause. We also havetwo binary relations pos and neg such that pos(x; v) and neg(x; v) say that the variable voccurs in the clause x positively or negatively, respectively. Finally, val(v; t) (resp. val(v; f)expresses that the variable V is assigned the truth value t(rue) (resp. f(alse)).val(V; t) _ val(V; f) var(V )sat(X) clause(X); pos(X; V ); val(V; t)sat(X) clause(X); neg(X; V ); val(V; f)( clause(X);:sat(X)MIN NODE COVER. Let G = hV;Ei be a graph. Find a minimum node cover, that is, asubset of minimum cardinality V 0 of V such that for each edge fu; vg 2 E at least one of uand v belongs to V 0.cover(X) _ not cover(X) node(X) edge(X; Y );:cover(X);:cover(Y )( cover(X)MIN KERNEL. Let G = hV;Ei be a directed graph. Find a minimum kernel, that is, asubset of minimum cardinality V 0 of V such that no two nodes in V 0 are joined by an edgein E and, further, for every node u in V � V 0 there is a node v in V 0 such that (v; u) 2 E.r1 : kernel(X) _ not kernel(X) node(X)s1 : kernel(X); kernel(Y ); edge(X; Y ); X 6= Ys2 : not kernel(X);:connected to kernel(X)r2 : connected to kernel(X) kernel(Y ); edge(Y;X)w1 : ( kernel(X)MAX CUT. Let G = hV;Ei be a graph. A maximal cut is a partition of V into sets V1and V2 such that the number of edges of G having one endpoint in V1 and one endpoint inV2 is maximum.r1 : v1(X) _ v2(X) vertex(X)w1 : ( v1(X); v1(Y ); edge(X; Y )w2 : ( v2(X); v2(Y ); edge(X; Y )

INFSYS RR 1843-99-03 31MAX BIPARTITE SUBGRAPH. Let G = hV;Ei be a planar graph. Find a subset E 0 � Eof maximum cardinality such that G0 = hV;E 0i is bipartite.r1 : e0(X; Y ) _ not e0(X; Y ) edge(X)r2 : v0(X) _ not v0(X) vertex(X)s1 : v0(X); v0(Y ); e0(X; Y )s2 : not v0(X); not v0(Y ); e0(X; Y )w1 : ( not e0(X; Y )B Complexity of Head-Cycle Free and Normal DATALOG_;:;cProgramsB.1 Preliminaries: HCF and Strati�ed ProgramsA disjunctive Datalog program LP is (locally) strati�ed if each atom p 2 BLP can be associ-ated a positive integer l(p) such that, for each rule r 2 ground(LP ) with p 2 H(r) and eachground atom q the following holds: (i) if q 2 H(r), then l(p) = l(q); (ii) if :q 2 B�(r), thenl(p) > l(q); (iii) if q 2 B+(r), then l(p) � l(q). In particular, if all ground atoms with thesame predicate have the same number associated, then LP is globally strati�ed.Proposition 23 Let LP be a ground normal logic program. If LP is strati�ed, then LP hasexactly one stable model that can be computed in polynomial time.HCF disjunction is a syntactical property of programs that gives no account to negation.A program LP is (locally) head-cycle-free if each atom p 2 BLP can be associated a positiveinteger l(p) such that, for each rule r 2 ground(LP ) with p 2 H(r) and each ground atomq 6= p the following holds: (i) if q 2 H(r), then l(p) 6= l(q); (ii) if q 2 B+(r), then l(p) � l(q).In particular, if all ground atoms with the same predicate have the same number associated,then LP is globally head-cycle-free.The following proposition, which is implicit in [3], is straightforward from the fact thatchecking whether a total model of a positive HCF program is minimal is polynomial [4].Proposition 24 (cf. [3, 4]) Let LP be a ground HCF program and letM be an interpretationof it. Then, deciding if M is a stable model of LP is polynomial.We say that a DATALOG_;:;c program P = (LP ; S;W ) is head-cycle-free (resp., strati�ed)i� LP is head-cycle-free (resp., strati�ed).B.2 Complexity of Head-Cycle-Free Disjunctive ProgramsIn the case of Disjunctive Datalog without constraints, the complexity of brave reasoningfalls back from �P2 to NP if disjunction is required to be head-cycle-free (often, simply HCF).

INFSYS RR 1843-99-03 32Not surprisingly, we obtain a decrease of one level in the polynomial hierarchy (from �P3 and�P3 [O(logn)] to �P2 and �P2 [O(logn)], respectively) in the complexity of brave reasoningwhen we impose head-cycle-free disjunction to DATALOG_;:;c.Lemma 25 Let a positive integer n and a DATALOG_;:;c program P = (LP ; S;W ) be givenas input, where LP is head-cycle-free. It is in NP deciding whether there exists a stable modelM of LP satisfying S such that HP;M � nProof. We can decide the problem as follows. Guess M � BP , and check that: (1) M isa stable model of LP , (2) all constraints in S are satis�ed, and (3) HP;M � n. Clearly,property (2) and (3) can be checked in polynomial time. Moreover, since LP is head-cycle-free, stable model checking (i.e., task (1)) is also polynomial [30, 3]. Hence, the problem liesin NP. 2Lemma 26 Let a positive integer n and a DATALOG_;:;c program P = (LP ; S;W ) givenas input, where LP is head-cycle-free. It is in NP deciding whether there exists a stablemodel M of LP satisfying S such that HP;M = n and q is true w.r.t. M .Proof. We can decide the problem as follows. Guess M � BP , and check that: (1) M isa stable model of LP , (2) all constraints in ground(S) are satis�ed, (3) HP;M = n, and(4) q is true w.r.t. M . Clearly, property (2), (3), and (4) can be checked in polynomialtime. Moreover, since LP is head-cycle-free, stable model checking (i.e., task (1)) is alsopolynomial [30, 3]. Therefore, problem is in NP. 2Theorem 27 Let a DATALOG_;:;c program P = (LP ; S;W ), and a literal q be given asinput, where LP is an HCF program. Then, deciding whether q is true in some stable modelof P is �P2 -complete.Proof. The proof of �P2 -membership is exactly like in Theorem 17, where the �P2 oracles arereplaced by NP oracles, because the respective tasks are one level down in the polynomialhierarchy in this case (just compare the results of Lemma 15 and 16 with those of Lemma25 and 26, respectively).We show �P2 -hardness by a polynomial time reduction of the following �P2 -complete prob-lem [26, 27]: Given a satis�able clause set C = fC1; : : : ; Cmg on X = fx1; : : : ; xng, decidewhether the with respect to hx1; : : : ; xni lexicographically minimum �(X) satisfying C, whichwe denote by �min(X), ful�lls �min(xn) = true.Consider the normal program LP containing: (i) for each clause a1_� � �_al_:b1_� � �_:bk 2C (k; l � 0), the ruleabs b1; � � � ; bk; :a1; � � � ; :al

INFSYS RR 1843-99-03 33and, (ii) for each 1 � i � n, the rule xi _ x0i ; where abs and x0i (1 � i � n) are freshatoms.Clearly, LP is head-cycle-free. Moreover, there is a one-to-one correspondence betweenthe stable models of LP which do not contain abs and the truth assignments to X satisfyingC. In particular, given a stable model M of LP not containing abs, the truth assignment�M satis�es C, where �M(xi) = true i� xi 2 M . Vice versa, given a truth assignment �satisfying C, the interpretation I� is a stable model of LP which does not contain abs, whereI� = fxi 2 fx1; : : : ; xng j xi 2Mg [ fx0i 2 fx01; : : : ; x0ng j x0i 2MgConsider now the DATALOG_;:;c program P = (LP ; S;W ), where LP is the HCF programabove, S = f absg and W = hf( xng; � � � ; f( x1gi. It is easy to see that P has exactlyone stable model M . Moreover, the lexicographically minimum truth assignment �min(X)satisfying C ful�lls �min(xn) = true if and only if xn is true in M (that is, i� xn is a braveconsequence of P).Therefore, brave reasoning on HCF DATALOG_;:;c programs is �P2 -complete. 2Theorem 28 Given a DATALOG_;:;c program P = (LP ; S;W ), where LP is an HCFprogram, and a literal q as input, deciding whether q is true in some stable model of P is�P2 -complete even if strong constraints are disallowed (S = ;) and LP is strati�ed or evenpositive.Proof. Membership comes from previous theorem. To show hardness, we have to eliminateboth strong constraints and negation from program P of the prof of theorem 27. To this endwe rede�ne LP as follows: (i) for each clause a1 _ � � � _ al _ :b1 _ � � � _ :bk 2 C (k; l � 0),LP contains the ruleabs b1; � � � ; bk; a01; � � � ; a0land, (ii) for each 1 � i � n, LP contains the rule xi _ x0i ; where abs and x0i (1 � i � n)are fresh atoms. Moreover, W is hf( xng; � � � ; f( x1g; f( :absgi, and S = ;.The new DATALOG_;:;c program P behaves exactly like the program of Theorem 27.Therefore, the lexicographically minimum truth assignment �min(X) satisfying C ful�lls�min(xn) = true if and only if xn is true in M (that is, i� xn is a brave consequence of P).2Theorem 29 Let a ground literal q and a DATALOG_;:;c program P = (LP; S;W ) givenas input, where LP is HCF and W consists of a single component. Then, deciding whetherq is true in some stable model of P is �P2 [O(logn)]-complete.

INFSYS RR 1843-99-03 34Proof. Membership stems by applying the same reasoning we did in Theorem 21.To show �P2 -hardness we resort to abductive reasoning tasks discussed in Section 3.3.Given an LPAP (see Section 3.3), P = hHyp;Obs; LP i, where LP is a normal logic program,and a ground atom �h, deciding whether �h belongs to some cardinality mimimal explanationof P is �P2 [O(logn)]-hard [13]. (This decision problem is called relevance in the literature,and �h is said relevant for P.) Now, consider the DATALOG_;:;c program of Section 3.3pr(P) = (LP [G; S; hW0i), whereS = f ::o j o 2 Obs gG = fh _ not h j h 2 HypgW0 = f( h j h 2 HypgLP [ G is clearly head-cycle-free (as LP is _-free and the rules in G have an emptybody). Since the cardinality minimal solutions of P correspond one-to-one to the stablemodels of pr(P), it is easy to see that �h is relevant for P (under the cardinality minimalcriterion) i� pr(P) j=brave �h. Therefore, brave reasoning on HCF DATALOG_;:;c programsis �P2 -complete. 2Theorem 30 Let a ground literal q and a DATALOG_;:;c program P = (LP; S;W ) givenas input, where LP is HCF and W consists of a single component. Then, deciding whether qis true in some stable model of P is �P2 [O(logn)]-complete even under the following furtherrestictions on P:1) S = ;, and2) LP is strati�ed or even positive.Proof. Membership comes from Theorem 29. We recall that deciding whether a groundatom �h belongs to some cardinality mimimal explanation of a given LPAP P is �P2 [O(logn)]-hard even if LP is a positive program (i.e., a de�nite Horn theory), and Obs = fo1; :::; omg ismade of positive literals only [14]. Therefore, we can use a reduction from this problem (wefurther assume that P has at least one explanation; it is clear that this assumption does notdecrease the complexity of the problem). To this end, consider the following DATALOG_;:;cprogram pr(P) = (LP [G; ;; hW0i), whereG = fh _ not h j h 2 Hypg [ foi _ o0i j oi 2 Obsg [ fh o0i j oi 2 Obs h 2 HypgW0 = f( h j h 2 Hypg

INFSYS RR 1843-99-03 35It is evident that LP [ G is a positive HCF program. The rules in fh o0i j oi 2 Obs h 2Hypg enforce that all observations are entailed in the stable models of P (if one observationis missed then all constraints of W0 are violated). Because of the constraints in W0, thestable models of P correspond one-to-one to the cardinality minimal explainations of P.Thus, �h belongs to a cardinality minimal explaination of P if and only if P j=brave �h. (Weare done). 2B.3 Complexity of Normal ProgramsThe computational complexity of brave reasoning for an _-free program P = (LP ; S;W )strongly depends on the kind of negation that we allow in LP . Indeed, if the logic programLP is strati�ed (or even positive), then it admits a unique stable model that can be computedin polynomial time. Therefore, in all _-free fragments of DATALOG_;:;c that allow onlystrati�ed negation, brave reasoning is always polynomial and its complexity is not a�ectedat all from the presence of (strong or weak) constraints.If unstrati�ed negation is allowed in LP , and then multiple stable models are possible, thecomplexity does increase and is a�ected from the presence of weak constraints. We claim that(under brave reasoning) each _-free fragment of DATALOG_;:;c which allows unstrati�ednegation has exactly the same complexity of the corresponding :-free fragment which allowsHCF disjunction. In proof, we make the following remarks:� Since stable model checking is polynomial for both (:-free) HCF disjunctive programsand (_-free) unstrati�ed programs, it is easy to see that all upper complexity boundsthat we determined for the former programs, apply to the latters as well (actually, thesame proofs can be applied).� The lower complexity bounds derived for (:-free) HCF disjunctive programs hold alsofor (_-free) unstrati�ed programs, because every HCF program LP can be rewritteninto an unstrati�ed _-free program having exactly the same stable models as LP (byusing this rewriting, we can again utilize the same proofs we used for HCF programsto derive the hardness results for normal unstrati�ed programs).