23

Computation of Non-Ground Disjunctive Well-Founded Semantics with Constraint Logic Programming

Embed Size (px)

Citation preview

Computation of Non-GroundDisjunctive Well-Founded Semanticswith Constraint Logic ProgrammingJ�urgen Dix and Frieder StolzenburgUniversity of Koblenz, Department of Computer ScienceRheinau 1, D-56075 Koblenz, Germanyfdixjstolzeng@@informatik.uni-koblenz.deAbstract. Impressive work has been done in the last years concerningthe meaning of negation and disjunction in logic programs, but mostof this research concentrated on propositional programs only. While itsu�ces to consider the propositional case for investigating general prop-erties and the overall behaviour of a semantics, we feel that for realapplications and for computational purposes an implementation shouldbe able to handle �rst-order programs without grounding them.In this paper we present a theoretical framework by de�ning a calculus ofprogram transformations that apply directly to rules with variables andfunction symbols. Our main results are that (1) this calculus is con uentfor arbitrary programs, (2) for �nite ground programs it is equivalent toa terminating calculus introduced by Brass and Dix (1995), and (3) itapproximates a generalisation of D-WFS for arbitrary programs.We achieve this by transforming program rules into rules with equa-tional constraints thereby using heavily methods and techniques fromconstraint logic programming. In particular, disconnection-methods playa crucial role. In principle, any constraint theory known from the �eldof constraint logic programming can be exploited in the context of non-monotonic reasoning, not only equational constraints over the Herbranddomain. However, the respective constraint solver must be able to treatnegative constraints of the considered constraint domain.In summary, this work yields the basis for a general combination of twoparadigms: constraint logic programming and non-monotonic reasoning.Keywords: constraint logic programming, equational constraints, dis-junctive logic programming, well-founded semantics, non-monotonic rea-soning.1 IntroductionRecent years have seen an enormous number of di�erent semantics of logic pro-grams with negation. Fewer semantics have been developed for disjunctive pro-grams and nearly all approaches assume \without loss of generality"|as mostauthors put it|that the underlying programs are grounded, i.e. they do notcontain variables.

We think that one of the most important advantages of the logic program-ming paradigm and therefore the success of Prolog is its ability to computeanswer-substitutions for a given query. Although semantics for logic programswith negation are undecidable if function symbols and variables are allowed, weare convinced that query answering mechanisms for the non-ground-case havegreat advantages over the propositional case. Of course, such procedures canonly be sound and not complete. But completeness can hold for certain restrictedclasses of programs as well as for certain queries.Our approach is essentially based on a calculus of program transformationsthat has been recently shown to be con uent and terminating for ground pro-grams [BD96]. The most important transformation in this calculus is the partialevaluation property (GPPE) introduced for disjunctive programs independentlyby [SS95,BD94]. Unfortunately, GPPE is not sound for rules with variables be-cause of the occurrence of uni�able atoms in the heads of rules (see Section 4). Inthis paper we make GPPE sound|which allows us to use the results of [BD96]|by introducing inequality constraints . This immediately leads us to introduceconstraint disjunctive logic programs and consequently to extend our transfor-mations to this class of programs. Surprisingly, this framework shares the samenice properties as our original calculus. In fact we can lift the results of [BD96]to the non-ground case.We know the approach [EGLS96] that also considers non-ground disjunctiveprograms. In this approach, the authors de�ne a Gelfond-Lifschitz transforma-tion for �rst-order programs and consider instantiation by need techniques. It isrelated to [KNS95] where de�nite non-ground programs are treated. But theyonly consider normal logic programs, i.e. without disjunctions. In addition, theydo not consider the case with function symbols in its full generality. [Stu91]also considers normal logic programs only. He employs constructive negationand gives a clean approach to negation in constraint logic programming. Lastbut not least, we want to mention [AD94,SS95]. These papers present methodsbased on partial deduction|as also done here|for normal logic programs anddisjunctive logic programs, respectively, but both do not aim at incorporatingconstraint logic programming.The paper is structured as follows. In Section 2 we introduce the basicnotation we will use throughout the paper. In Section 3 we consider groundprograms. After introducing our calculus of transformations originally de�nedin [BD94,BD96], we cite its con uence and termination for �nite ground pro-grams: this gives rise to the semantics D-WFS. We then generalise D-WFS to ar-bitrary in�nite ground programs by introducing a loop-detection rule and show-ing that the original calculus still is con uent but does not always terminate.Our overall framework is introduced in Section 4 where we consider arbitrary�rst-order programs. We extend program rules by a constraint theory and in-vestigate how techniques from constraint logic programming apply. In Section 5we extend our original transformations using the new framework so that theydirectly apply to programs with variables. We introduce CD-WFS using the new

calculus and show how it can be computed and used for query-answering. We alsoshow its relation with WFS, GCWA and D-WFS. We conclude with Section 6.2 PreliminariesIn the �rst part of this paper we restrict to propositional programs. We also allowthat they are in�nite, i.e. they are full instantiations of �rst order programs. Letsome �xed �nite signature � containing the binary connectives ^;_;!, theunary connective : and the falsum ? be given.De�nition 1 (Logic Program �).A logic program � is a (possibly in�nite) set of rules of the formA1 _ � � � _Al B1 ^ � � � ^ Bm ^ :C1 ^ � � � ^ :Cnwhere the Ai, Bi and Ci are �-atoms di�erent from ?, l � 1, m � 0, n � 0.We allow empty conjunctions: they are considered as abbreviations for :? (theverum) which we also denote by >.We identify such a rule with the triple consisting of the following sets ofatoms A := fA1; : : : ; Akg, B := fB1; : : : ; Bmg, C := fC1; : : : ; Cng, and write itas A B^:C. This means, in particular, that we assume the Ai (resp. the Bi,resp. the Ci) to be pairwise distinct.We write heads(�) for the set of all atoms occurring in rule heads in �: theseare atoms that are possibly true. By pure disjunctions we mean disjunctionsconsisting solely of positive or solely of negative literals. We also want to allowintegrity constraints, i.e. rules with empty heads (l = 0). This will sometimeslead to inconsistent programs of course, i.e. a program � may semantically implyboth a proposition and its negation.De�nition 2 (Operator j�, Semantics Sj�).By a semantic operator j� we mean a binary relation between logic programs andpure disjunctions which satis�es the following three arguably obvious conditions:(1) Right Weakening: If � j� and � 0 (i.e. is a subdisjunction of 0),then � j� 0.(2) Necessarily True: If (A ) 2 � for a disjunction A, then � j� A.(3) Necessarily False: If A 62 heads(�) for some �-ground atom A,then � j� :A.Given such an operator j� and a logic program �, by the semantics Sj�(�)of � determined by j� we mean the set of all pure disjunctions derivable by j�from �, i.e. Sj�(�) := f j � j� g.Note that both model-based as well as completion-based approaches �t wellinto this framework, because these approaches provide in a natural way a set ofderivable disjunctions. We simply take the sceptical view: truth in all intended

models or in all models of the completion. In this respect, we contribute to thediscussion about the usefulness of model theory. On the one hand, our approachis not against model theory. But on the other hand, we do not explicitly need amodel theory.In addition to satisfying the general conditions from De�nition 2, we maywant a speci�c semantic operator j� to be invariant under certain natural pro-gram transformations. So, we will give a set of reasonable transformation rulesin the sequel.De�nition 3 (Invariance of j� under a Transformation).Suppose that a program transformation Trans is given. We view such a trans-formation as a relation (not necessarily a function) which speci�es under whatconditions a program � is a transformation of another program �0. To facil-itate notation we also write such a transformation sometimes as a functionTrans : � 7! Trans(�), mapping logic programs into logic programs. In gen-eral, however, a particular transformation can be applied in di�erent ways to aprogram so that Trans(�) is not uniquely de�ned. We say that the operator j�is invariant under Trans (or that Trans is a j�-equivalence transformation) i�� j� () Trans(�) j� for any pure disjunction and any program �.Why do we only consider pure disjunctions? This is simply because we areinterested in the sceptical viewpoint and therefore we can not assume that anysemantics is given as a set of models. For example, SLDNF-like semantics usuallyare given in proof-theoretic terms. In order to be as general as possible|i.e. tocover as many semantics as possible in our framework|, we can only assume thata semantics provides us at least with the notion of deriving arbitrary conjunctionsof either positive or either negative literals and of negations of these conjunctions.But these are exactly the pure disjunctions. Some semantics simply do not de�newhat it means to derive a mixed disjunction.3 D-WFS for ground programsWe now describe several transformations Trans which will be later used to de�nethe D-WFS semantics. By abuse of language (and to facilitate reading) we willsimply say \j� satis�es Trans\ meaning that \j� is invariant under Trans". Amore complete discussion of our calculus can be found in [BD96,BD97a,BD95b].3.1 The Calculus of TransformationsWe begin with partial evaluation in the sense of the \unfolding" operation. It isthe generalised principle of partial evaluation (GPPE) [BD94,SS95]:

De�nition 4 (GPPE).A Semantics Sj� satis�es GPPE i� it is invariant under the following transfor-mation: Replace a rule A B^:C where B contains a distinguished atom B bythe rulesA [ �Ai � fBg� �B � fBg� [ Bi ^ :�C [ Ci� (i = 1; : : : ; k)where Ai Bi ^ :Ci (i = 1; : : : ; k) are all the rules with B 2 Ai.Note that we are free to select a speci�c positive occurrence of an atomB and then perform the transformation: this is just to say that the GPPE-transformation is a relation between programs. It is uniquely determined only ifwe �x a speci�c occurrence of an atom that we want to replace. The new rulesare obtained by replacing B by the bodies of all rules r with head literal B andadding the remaining head atoms of r to the head of the new rule. GPPE alsocovers the degenerate case when the atom B to be replaced does not appear inany head: then the whole rule is simply deleted.The next transformation, elimination of tautologies, states that tautologicalclauses like p p do not in uence the semantics of a logic program. Withthe help of elimination of non-minimal rules we can get rid of clauses that aresubsumed by others.De�nition 5 (Elimination of Tautologies, Non-Minimal Rules).A semantics Sj� satis�es the elimination of tautologies (TAUT), resp. the elim-ination of non-minimal rules (NMIN) i� j� is invariant under the followingtransformations:(TAUT) Delete a rule A B ^ :C with A\ B 6= ;.(NMIN) Delete a rule A B ^ :C if there is another rule A0 B0 ^ :C0with A0 � A, B0 � B, and C0 � C.The last two transformations (stated below) allow us to do some simplereductions. We want :L to be derivable if L appears in no rule head. Therefore,it should be possible to evaluate the body literal :L to true, i.e. to delete :Lfrom all rule bodies: this is guaranteed by positive reduction. Conversely, if thelogic program contains a disjunctive fact (A1 _ � � � _Ak ), at least one of theatoms occurring in it must be true, so a rule body containing :A1 ^ � � � ^ :Akis surely false, so the entire rule is useless, and it should be possible to delete it:this gives us negative reduction.De�nition 6 (Positive and Negative Reduction).Semantics Sj� satis�es positive reduction (RED+), resp. negative reduction(RED�) i� j� is invariant under the following transformations:(RED+) Replace a rule A B ^ :C by A B ^ :(C \ heads(�)).(RED�) Delete a rule A B ^ :C if there is a rule (A0 ) with A0 � C.

3.2 Finite Ground ProgramsIf our programs are �nite, our calculus has some very nice properties:Theorem 7 (Con uence and Termination [BD96]).Our calculus of transformations is con uent and terminating for �nite groundprograms, i.e. if � !� �0 and � !� �00 and both �0; �00 are irreducible, then�0 = �00. In addition, for any program � there is an irreducible �0 with �!� �0.We call such irreducible �0 the residual program res(�) from �.Originally, the semantics D-WFS has been de�ned as follows:Theorem 8 (D-WFS [BD97b]).There exists the weakest semantics Sj� which is invariant under GPPE, Elimi-nation of Tautologies and Non-Minimal Rules, Positive and Negative Reduction.Moreover, this semantics is consistent (i.e. it does not derive a literal A and itsnegation :A) and closed under logical consequences (as a set consisting of puredisjunctions). We call it the Disjunctive Well-Founded Semantics, or, brie y,D-WFS. It coincides with the well-founded semantics WFS for normal and withGCWA for positive disjunctive programs.With the help of our calculus and the residual program, we can computeD-WFS quite nicely:Theorem 9 (Completeness of D-WFS wrt. res(�) [BD97b]).� j�D�WFS () there is A � with (A ) 2 res(�) orthere is :A 2 and A 62 heads(res(�)):This theorem is especially important. It tells us that once the residual programres(�) has been produced, the semantics D-WFS can be immediately deter-mined. In fact, res(�) contains enough information to compute the stable se-mantics by hyper-resolution (see [BD95a]).3.3 In�nite Ground ProgramsWhat happens if our programs are in�nite? Our transformations are also de�nedfor in�nite programs but it is not guaranteed that the calculus always terminates.We consider the program p(x) p(s(x))or the corresponding in�nite propositional program Ploopp0 p1; p1 p2; : : : ; pi pi+1; : : :which can be seen as the full instantiation of the former program. Our GPPEcan not \unfold" such an in�nite loop and eliminate all these rules. To do this,something like an !-inference rule is needed which is not a constructive rule. Of

course we can try to de�ne a particular loop detection|see De�nition 10 andthe remarks in Subsection 6.1|, but since the general problem is undecidable,there is no constructive solution in general. If the above loop is �nite, this canbe recognised in a �nite number of steps and D-WFS does this.Although the very de�nition of D-WFS given in Theorem 8 does not dependon �nite programs, we can not just use this formulation for arbitrary programs.This is because the resulting semantics would not extend WFS or GCWA inthat case. The weakest such semantics would simply derive nothing from Ploop,instead of f:p0;:p1; : : : ;:pi; : : : g. The reason is that for in�nite programs wecan not always get rid of all the positive body atoms|like in Ploop. But thiswas the main achievement of the residual program in Theorem 9: the residualprogram contains only negative literals in the body.For in�nite ground programs our GPPE is a transformation replacing a ruleby a possibly in�nite set of other rules. It can now happen that in�nite appli-cations of GPPE exist or do not exist. Let us shortly illustrate this. We applyGPPE to Ploop to replace �rst p1 in the �rst rule. Then we replace p2 in thesecond rule and so on (i.e. replacing pi in the i-th rule). We get a sequence ofprograms that converges:Ploop :p0 p1p1 p2p2 p3...pi pi+1...P1 :p0 p2p1 p2p2 p3...pi pi+1...

P2 :p0 p2p1 p3p2 p3...pi pi+1... : : : Pi :p0 p2p1 p3...pi�1 pi+1pi pi+1... : : : P! :p0 p2p1 p3p2 p4...pi pi+2...But if we �rst replace p1 in all rules, and then p2 in all rules and so on (i.e. re-placing pi in the �rst i rules with i-fold application of GPPE), we get a non-converging series of programs:Ploop :p0 p1p1 p2p2 p3...pi pi+1...P 01 :p0 p2p1 p2p2 p3...pi pi+1...

P 02 :p0 p3p1 p3p2 p3...pi pi+1... : : : P 0i :p0 pip1 pi...pi�1 pipi pi+1... : : :Nevertheless we allow the in�nite application of our rules, if it leads to a well-de�ned program. We can now formulate a non-constructive rule which is similarto condition (3) of De�nition 2:De�nition 10 (Loop-Detection Rule).Let A be an atom and � be a program. Delete all rules (A B ^:C) 2 � with

A 2 A, if for all �0 with � !� �0 it is B 6= ; for all (A0 B0 ^ :C0) 2 �0 withA 2 A0.In the above rule, \!�" denotes the transitive closure of the transforma-tions GPPE, TAUT, NMIN, RED+ and RED�. Of course, an application ofthe loop-detection rule can allow new applications of the other rules. Therefore,we denote with \!�" by now the transitive closure of all our rules (includingloop-detection).This rule formalises the intuition that if an atom always (and forever) de-pends positively on other atoms, then they all should be considered false: thisis obviously true for WFS and GCWA. We are now in a position to generaliseD-WFS:Theorem 11 (D-WFS for In�nite Programs).There exists the weakest semantics Sj� which is invariant under GPPE, elimi-nation of tautologies and non-minimal rules, positive and negative reduction andsatis�es the loop-detection rule. Moreover, this semantics is consistent (i.e. itdoes not derive a literal A and its negation :A) and closed under logical conse-quences (as a set consisting of pure disjunctions). It extends D-WFS from The-orem 9 and is therefore also called D-WFS. It coincides with the well-foundedsemantics WFS for normal and with GCWA for positive disjunctive programs.We also have the subsequent con uence result. We will later comment on howapproximations of the loop-detection rule can be constructively incorporated inour calculus (see Section 6).Theorem 12 (Con uence for In�nite Programs).Our set of transformations is con uent for in�nite ground programs, i.e. if �!��0 and � !� �00 and both �0; �00 are irreducible, then �0 = �00. If a program �0is irreducible, then D-WFS can be computed by using the characterisation givenin Corollary 9.4 Non-Ground ProgramsWhat are the problems to extend our transformations to �rst-order programs?One of the main problems is already built-in in De�nition 1 where we identi�ed arule with sets of atoms: this means that we do not allow for duplicate occurrences.This is not just a technical point: without this restriction, GPPE would not evenbe a sound transformation.Example 13 (Duplicate Occurrences and GPPE).In the following program � we apply the GPPE and obtain GPPEB(�).� : A BB _ B GPPEB(�) : A _ B B _ B GPPEB(�) is irreducible, or even worse, if B_B is identi�ed with B, it reducesto \B " only. (\A _ B " is deleted because of NMIN). In any case, if

we apply the characterisation given in Corollary 9 we can no more derive A,although this is derivable by D-WFS.Example 14 (First-Order Program).In the last example the problem does not occur if we replace B _ B by B.But similar problems can occur for �rst-order programs. Suppose we have theprogram � : p(x) q(x) (1)q(x) _ q(a) (2)and we want to replace q(x) in the �rst clause. If we do this without taking careof the variables, we get p(x) _ q(a) (1�)p(a) _ q(x) (1��)q(x) _ q(a) (2)from which p(a) is not derivable, although it should! In order to make the GPPEsound we should split the rule (2) q(x) _ q(a) into two rulesp(x) q(x) (1)q(x) _ q(a) / x 6= a (20)q(a) (200)such that we now can apply the GPPE in a sound way:p(x) _ q(a) / x 6= a (10)p(a) _ q(x) / x 6= a (100)p(a) (1000)q(x) _ q(a) / x 6= a (20)q(a) (200)Therefore we are forced to generalise our rules by adding equational con-straints. These constraints are not only equations and their negations as in Pro-log II [Col86], but also conjunctions, disjunctions and universally quanti�ed for-mulae of them (see [Mah88,CL89]). Such constructs arise when we generalise ourtransformations and take care of the associated constraints. In order to performthe splitting as explained above, we have to introduce a factorisation rule whichwill be formally de�ned in De�nition 17.By an extended version of the non-minimal rule (see De�nition 24) we can�nally reduce � to what one may expect, namely:p(a) (1000)q(a) (200)In Subsection 4.1 we extend our framework to disjunctive programs withconstraints. In Subsection 4.2 we introduce the Head Atoms, the Factorisationand add some remarks about constraint simpli�cation in general in Section 4.3.

4.1 Constraint Disjunctive Logic ProgramsEquational Constraints are introduced and discussed in detail in [Mah88,CL89].There, it is shown that the satis�ability problem for equational constraints isdecidable. [CL89] presents also a complete simpli�cation algorithm for equationalconstraints, formulated by some rewrite rules. [Mah88] gives a more abstractquanti�er elimination procedure.We will now state the theoretical framework for computing non-ground dis-junctive well-founded semantics and start with the de�nition of the syntax forequational constraints. The equality theory in our context is just syntacticalequality.De�nition 15 (Equational Constraints E).Let V be a set of variables and F a set of function symbols. Then T (F; V )denotes the set of terms over F and V as usual. We de�ne the set of equationalconstraints E as the smallest set satisfying the following properties:1. ?;> 2 E .2. For all s; t 2 T (F; V ), s = t 2 E .3. If R;R0 2 E and x 2 V , then :R;R ^ R0; R _ R0; 9xR;8xR are in E .To facilitate reading, we write s 6= t for :(s = t), and R ! R0 for :R _ R0.We are now able to lift the notion of disjunctive logic program to the non-groundcase, by de�ning a disjunctive logic program � as a �nite set of (not necessarilyground) rules(A1 _ � � � _ Al) (B1 ^ � � � ^ Bm) ^ (:C1 ^ � � � ^ :Cn)where l � 1 andm;n � 0. It is often abbreviated as A B^:C. We will identifyA, B and C by their sets of atoms fA1; : : : ; Alg, fB1; : : : ; Bmg and fC1; : : : ; Cng,respectively. An atom has the form p(t1; : : : ; tk) where t1; : : : ; tk 2 T (F; V ), andp stems from a �nite set of predicate symbols.The next de�nition introduces a further variant with equational constraints.We always assume that all constraint programs and rules are normalised (seeDe�nition 18). For this, we need the de�nitions of two transformation rules:elimination of tautologies TAUT and factorisation FACTOR. Both rules arelocal, i.e. they do not refer to the whole rule set. Therefore they can be imple-mented e�ciently. Thus, it makes sense to integrate them into the normalisationprocess.De�nition 16 (Non-Ground Constraint Disjunctive Logic Program).A constraint disjunctive logic program � (or just constraint program for short)is a �nite set of rules of the form L / Rwhere L is a (not necessarily ground) disjunctive rule but without function sym-bols occurring in L, and R is an equational constraint.

De�nition 17 (TAUT-, FACTOR- and MERGE-rules).We �rst introduce elimination of tautologies, factorisation and the MERGE rule.Using these rules we de�ne the normalisations of constraint rules and programs.(TAUT) We a replace the rule A B^:C / R by A B^:C / R^ (A 6= B)where A 2 A and B 2 B are atoms with the same predicate symbol.(FACTOR) Let A B ^ :C / R be a rule, and A;B 2 A atoms with thesame predicate symbol, i.e. they have the form A = p(x1; : : : ; xk) and B =p(y1; : : : ; yk). Then the two rulesA B ^ :C / R ^ (A 6= B)(A� fBg) B ^ :C / R ^ (A = B)are the factorisation of L / R. Here, A = B means x1 = y1 ^ � � � ^ xk = yk,and A 6= B means x1 6= y1 _ � � � _ xk 6= yk.(MERGE) Let A B^:C / R and A0 B0^:C0 / R0 be variants of programrules such that A = A0, B = B0, and C = C0. Then we can replace the originalprogram rules by: A B ^ :C / R _ R0It is important to notice, that two rules which are merged by the MERGE-rule may be variants of one and the same rule. We need this in order to establish astrong notion of equivalence for irreducible and normalised constraint programs.Two programs � and �0 are called strongly equivalent (written � � �0) i� there isa bijection between the respective �nite sets of rules such that any correspondingrules are equal. Two rules are called equal i� their corresponding atom sets arevariants of each other, and the constraints renamed accordingly are equivalent.Let us consider the two programs�1 : p(x) _ p(y) = (x = a ^ y = b) _ (x = c _ y = d)�2 : p(x) _ p(y) = (x = a ^ y = b) _ (x = d ^ y = c)which are not equivalent in the strong sense. This is left as an exercise to thereader. Nevertheless, their ground instantiations are identical, namely�ground = fp(a) _ p(b) ; p(c) _ p(d) gwhich means they are equivalent in a weaker sense. However, if we apply MERGEon �1 and �2, respectively, then we get in both casesp(x) _ p(y) / (x = a ^ y = b) _ (x = c ^ y = d) _ (x = b ^ y = a) _ (x = d ^ y = c)which means MERGE(�1) �MERGE(�2).De�nition 18 (Normalisation).A constraint rule L=R is normalised by

1. existentially quantifying all free variables in R not occurring in L with 9,2. applying TAUT where possible, and3. performing FACTOR as long as possible.A constraint program � is normalised by1. normalising all rules in the program, and2. applying the MERGE-rule as long as possible.We can easily associate to each non-ground constraint disjunctive logic pro-gram � a possibly in�nite ground program. For this, we identify each rule L / Rwith all L� where � is a solution of the constraint R, i.e. a substitution thatmaps the free variables in R to ground terms. But we also have to think aboutanother problem: how can we translate a non-ground disjunctive logic programto one with constraints? The answer is given by the following de�nition.De�nition 19 (Variable Abstraction).We associate with each disjunctive logic program � a constraint disjunctive logicprogram �0 as follows. For a rule L in �, let L0 be the result of replacing eachargument t of a predicate in L by a fresh variable x. Then �0 contains the ruleL0 / ^x2var(L0) (x = t)for each rule L in �. Here, var(E) denotes the set of all (free) variables occurringin the expression E. In addition, each rule has to be replaced by its normalisationintroduced in De�nition 17.Before stating more formal de�nitions, we illustrate what is going on withthe following example.Example 20 (Running Example).Consider the program�0 : p(0) p(x) :p(x) ^ :p(s(x))p(s(x)) _ p(s(s(x))) q(0) p(x) ^ :q(x)which is translated into�1 : p(x) / x = 0 (1)p(x) :p(x) ^ :p(y) / y = s(x) (2)p(u) _ p(v) / 9x : u = s(x) ^ v = s(s(x)) (3)q(w) p(x) ^ :q(x) / w = 0 (4)by variable abstraction. Note that we will sometimes write rules in a form with-out variable abstraction in order to keep notation shorter. Our in�nite groundprogram Ploop from Subsection 3.3 can now be written easily as�loop : p(x) p(y) / y = s(x)

4.2 Head Atoms and Simpli�cationOne of the most important results of Section 3.2 was the de�nition of the residualprogram and Theorem 9. Using these notions we can do query answering by justlooking at the head atoms of the residual program. In order to de�ne an analogueof heads(�) for constraint programs, we needDe�nition 21 (Head-Atoms heads(�)).For a constraint program �, we de�ne the possibly true facts heads(�) (or headatoms) as the smallest set heads(�) satisfying the condition:If (A B^:C) / R is a rule in �, and A 2 A then A / (9�x R) where�x = var(R) � var(A) is also contained in heads(�).The set of constraint atoms has to be normalised. For all predicate symbols A0,not used so far, we add A0=?.Note, that heads(�) is �nite because � is �nite. For our example, the possiblytrue facts are as follows. The constraints are given in an already simpli�ed formhere. p(x) / x = 0 _> _ 9z x = s(z) _ 9z x = s(s(z))q(y) / y = 0An important feature while handling constraints is to simplify them, i.e.rewriting them into \simpler" ones while preserving equivalence. Since the un-derlying equational constraint theory is monotonic, simpli�cation can be per-formed at any time. If a constraint R in a rule reduces to ?, then the respectiverule can be discarded. We have to distinguish two cases:{ If the set of function symbols F is in�nite, then Clark's axiomatisation of theHerbrand domain yields a satisfaction-complete constraint theory for equa-tional constraints. In this case, basic equational constraints (i.e. uni�cationequations of the form s = t, but not general equational constraints) enjoythe independence of negative constraints property:E j= 9(R ^ :R1 ^ � � � ^ :Rk) () E j= 9(R ^ :Ri) for 1 � i � kThis is equivalent to the very strong completeness property, i.e. we can re-strict to only one derivation while answering any query, provided that we donot have any inequalities. For details, the reader is referred to [Mah93].{ If we assume the set of function symbols F to be �nite, then we need theweak domain closure axiom in order to make our theory complete [Mah88]:8x_f2F9�z x = f(�z)This case is mainly considered in [CL89]. But this point of view is restrictedto Herbrand models only and increases the computational complexity. Be-cause of this we will assume that F is in�nite in the sequel.

4.3 Reasoning with Arbitrary Constraint TheoriesUntil now we only considered equational constraints (De�nition 15). But ourframework can easily be generalised for arbitrary constraint systems and theories.Thus, we are not restricted to equality constraints over the Herbrand domain.We may consider other domains and other constraints predicates besides =.Surprisingly, all de�nitions (including the transformation rules introduced inSection 5) can also be applied to the general case. Here is the general de�nitionof a constraint system.De�nition 22 (Constraint System).A constraint system (often identi�ed by its constraint theory T , see below)consists of four components:{ a domain D, that is a non-empty set,{ an alphabet �, including a set V of variables, the equality symbol = whichhas to be interpreted by the equality relation on D and the constants ? and> with the meaning \false" and \true", respectively,{ a set R of (open) �-formulae, called constraints, including all atomic �-formulae and closed under all logical connective, i.e. especially negation :,and{ the constraint theory T ; T should be satisfaction-complete, i.e. for all con-straint formulae R 2 R either T j= R or T j= :R holds; therefore we canidentify T with a �-interpretation.The main di�erence to conventional constraint logic programming is the re-quirement that the set of constraint-formulae must be closed not only under con-junction ^, existential quanti�cation 9 and instantiation of variables|as statedin [JM94]|but under all logical connectives. We will see that this is necessarybecause of the �rst-order versions of the NMIN, RED+ and RED� rules in Def-inition 24. Thus, the respective constraint solvers must be able to treat negativeconstraints of the considered constraint domain. For example, we could do non-monotonic reasoning with integer domain constraints. Example 20 can easily beviewed as such a problem:p(x) / x = 0 (1)p(x) :p(x) ^ :p(y) / y = x+ 1 (2)p(u) _ p(v) / u � 1 ^ v = u+ 1 (3)q(w) p(x) ^ :q(x) / w = 0 (4)Now we are also in a position to extend our notion of a semantics forground programs (De�nition 2) straightforwardly to one for constraint disjunc-tive programs. We say that a constraint disjunctive rule A / R subsumes an-other rule A0 / R0 if there is a variant A00 / R00 of A / R such that A00 � A0and 8(R00 ! R0).

De�nition 23 (Operator j�, Semantics Sj�).By a semantic operator j� we mean a binary relation between constraint disjunc-tive logic programs and pure constraint disjunctions which satis�es the followingthree conditions:(1) Right Weakening: If � j� L / R and L / R subsumes L0 / R0,then � j� L0 / R0.(2) Necessarily True: If (A / R) 2 � for a constraint disjunction A / R,then � j� A / R.(3) Necessarily False: Let A / R be a constraint atom. If there exists a variantA=R0 of an atom in heads(�) and 8(R! :R0) (y), then� j� :A=R.Given such an operator j� and a constraint disjunctive program �, by thesemantics Sj�(�) of � (determined by j�) we mean the set of all constraint puredisjunctions derivable by j� from �, i.e. Sj�(�) := fL / R j � j� L=Rg.5 A Calculus for Non-Ground ProgramsWe have now introduced all necessary machinery to extend our original calculusto constraint programs in Subsection 5.1: Our main results are Theorems 25, 26,28, 29 and 31. In Subsection 5.2 we consider query answering and approximateTheorem 9.5.1 Extending our Original TransformationsWe are now able to state the transformation rules for the new calculus withconstraints. We will state the rules in a very abstract way, i.e. without mentioningcontrol of the applicability of the rules. But it is clear that our procedure cannotalways terminate because of the undecidability of the underlying problem. Notethat our former elimination of tautologies rule will be incorporated into GPPEby normalisation.De�nition 24 (Transformation Rules).If A B ^ :C / Ris a rule in the constraint program �, then it can be replaced by one of thefollowing (sets of) rules. Constraint simpli�cation can be applied immediatelyon each newly generated rule.(GPPE) (GPPE plus normalisation of rules)Replace the rule A B ^ :C / R by:

A[ (A1 � fBg) (B � fBg) [ B1 ^ :(C [ C1) / R ^ R1...A [ (Ak � fBg) (B � fBg) [ Bk ^ :(C [ Ck) / R ^ Rkfor all variants of rules Ai Bi ^ :Ci / Ri (1 � i � k) with B 2 Ai whereB is a distinguished atom in B. Each generated rule is replaced immediatelyby its normalisation. Note, that FACTOR has only to be done with respectto the predicate symbol of B.(NMIN) (Extended Elimination of Non-Minimal Rules)Replace the rule A B ^ :C / R by:A B ^ :C / R ^ :R0for some variant A0 B0 ^:C0 / R of a rule in � such that A0 � A, B0 � Band C0 � C hold.(RED+) (Extended Positive Reduction)Replace the rule A B ^ :C / R by the two rules:A B ^ :C / R ^R0A B ^ :(C � fCg) / R ^ :R0where C is an atom in C and C 0=R0 is a variant of a constraint atom inheads(�) such that C = C 0.(RED�) (Extended Negative Reduction)Replace the rule A B ^ :C / R by:A B ^ :C / R ^ :R0for some variant A0 / R0 of a rule in � such that A0 � C.We will now state a derivation for Example 20. We start with RED� on (2)with clause (3). This causes the replacement of (2) by:p(x) :p(x) ^ :p(y) / y = s(x) ^ :9z(x = s(z) ^ y = s(s(z))) (20)After applying the non-minimal rule with (1) which is essentially subsumption,the constraint can be simpli�ed to y = s(x) ^ x 6= 0 ^ 8z x 6= s(z). This couldbe further simpli�ed to ? if we assume that F is �nite, i.e. F = f0; sg.

Since for the predicate q only q(0) is in the set of possibly true facts, we canreplace (4) with q(w) p(x) ^ :q(x) / w = 0 ^ x = 0 (40)by RED+. Applying the GPPE on p(x) (where x = 0) we get �nally:q(w) :q(x) / w = 0 ^ x = 0 (400)When the reader compares De�nition 24 with Section 3.1, then we notice that(1) TAUT has been integrated into the GPPE, and (2) RED+ has been turnedinto a more exible incremental rule. Especially (1) de�nes some problems awayone may have with the proof of the following important Theorem 25. After that,we can state an analogue of Theorem 8.Theorem 25 (Con uence).Let � be a constraint disjunctive logic program. The relation !, given by thetransformation rules in De�nition 24, is con uent, i.e. � !� �1 and � !� �2where both �1 and �2 are irreducible implies �1 � �2. However, there does notalways exist an irreducible program �0 with �!� �0.Theorem 26 (CD-WFS).For the class of all constraint disjunctive programs � that possess an irreducibleprogram �0 with � !� �0, there exists the weakest semantics Sj� which is in-variant under GPPE, elimination of non-minimal rules, positive and negativereduction. We call it the Constraint Disjunctive Well-Founded Semantics, or,brie y, CD-WFS and abbreviate it by j�CD�WFS.We could have also de�ned the semantics on the class of all programs. Thereason we did not so is because then the semantics would be too weak comparedwith WFS or GCWA. For the program �loop it would not derive anything, be-cause �loop does not have an irreducible program below it (we have not stateda loop-detection rule as we did for in�nite ground programs (De�nition 10). Ofcourse, we aim to extend our de�nition to a larger class of programs. CD-WFScan be seen as a constructive approximation of D-WFS (see Theorem 31).5.2 Residual Program and Query AnsweringNow we can de�ne a constructive approximation of D-WFS for non-ground pro-grams. Since our procedure is not guaranteed to terminate we cannot alwayscompute the residual program (see De�nition 27). But when it exists, we can doquery answering similar as in the case of D-WFS (Theorem 9). Before doing so,let us summarise the result of applying the transformation to our example. Weend with an irreducible program.res(�) : p(x) / x = 0 (1)p(x) :p(x) ^ :p(y)/ y = s(x) ^ x 6= 0 ^ 8z x 6= s(z) (200)p(u) _ p(v) / 9x : u = s(x) ^ v = s(s(x)) (3)q(w) :q(x) / w = 0 ^ x = 0 (400)

De�nition 27 (Residual Program, Query).A constraint program � is called a residual program if no transformation rules areapplicable to it, i.e. if it is irreducible. A query is a pure disjunction of literals.We identify it with its translation into the rule L / R by variable abstraction.Theorem 28 (Computation of CD-WFS).Let � be a (variable abstraction of a disjunctive) program with the residual pro-gram res(�), and = L / R be a pure constraint disjunction. Then� j�CD�WFS i� one of the following two cases appliesCase 1: there is a rule (A ) / R in res(�) which subsumes .Case 2: L contains a negative literal :A such that the condition (y) from Def-inition 23 holds.In the last theorem we started with checking a statement = L / R whereR is a set of constraints. A more natural setting is given when we ask a query with free variables and try to instantiate these variables in order to �nd solutions.Such query-answering can also be done.Theorem 29 (Query Answering).Let � be a (variable abstraction of a disjunctive) program with the residual pro-gram res(�), and be a query with variable abstraction L / R. Then� j�CD�WFS [�]i� � is a solution of one of the following two constraints R+ and R�.Case 1: There is a rule (A ) / R in res(�), and A � L1 [ � � � [ Lk whereL1 / R1; : : : ; Lk / Rk are di�erent variants of L / R and the constraintR+ = (R1 ^ � � � ^ Rk) ^ R is satis�able.Case 2: L contains a negative literal :A and condition (y) from De�nition 23holds. Then R� = R ^ :R0 is satis�able.The solutions � of the constraints are called answers of the query. If in theformer case k > 0 holds, then the answer is called disjunctive or inde�nite.For our example it holds p(0) and :q(s(z)), but neither q(0) nor :q(0) be-cause (400) is a conditional fact. Sometimes it is not su�cient to look for onlyone rule while answering queries. For example, the queryp(x) _ p(y) / (x = 0 ^ y = 0) _ 9z(x = s(z) ^ y = s(s(z)))fails, although one should expect one positive answer. But we can split the queryby factorisation and constraint simpli�cation into:p(x) _ p(y) / x = y = 0p(x) _ p(y) / 9z(x = s(z) ^ y = s(s(z))) ^ x 6= yThen the former query has the answer x = y = 0 and the latter 9z(x = s(z)^y =s(s(z))). Both answers can be combined to the desired disjunctive constraint ofthe original query. Nevertheless, the MERGE-rule helps us to bundle answers.

Example 30. Consider the program:p(x) (1)p(a) (2)If we apply NMIN on (1) and variable abstraction on (2) we get:p(x) / x 6= a (10)p(x) / x = a (20)But this would give us two answers for the query p(z). However, the MERGE-ruleyields p(x) / x = a _ x 6= awhich is clearly equivalent to (1) after constraint simpli�cation. This is exactlywhat one should expect, because (2) can be deleted from the original programby NMIN on (2) with (1). Thus, the query p(z) can now be answered positivelyby looking at the only remaining rule (1).Finally we have the following relations of j�CD�WFS to other well-knownnon-monotonic semantics.Theorem 31 (CD-WFS Related to Other Semantics).Let � be a �rst-order disjunctive logic program, and be a purely positive ornegative clause. We identify � with its variable abstracted form, i.e. with itscorresponding constraint program. We also assume that res(�) exists. Then thefollowing holds:1. Let �inst be the possibly in�nite instantiation of � and inst the set of allground instances of . Then � j�CD�WFS i� �inst j�D�WFS inst. Inparticular, if � is a ground program (i.e. there are only nullary predicatesymbols in �), then � j�CD�WFS i� � j�D�WFS ).2. If � is a positive disjunctive program (i.e. there are no negative literals inthe body of any rule in �), then � j�CD�WFS i� � j�GCWA .3. If � is a normal program (i.e. any rule in � contains exactly one literal inits head), then � j�CD�WFS i� � j�WFS .6 ConclusionsThe careful reader may have noticed that we did not at all incorporate theloop detection rule into our framework. The reason is that this rule is essen-tially the only non-constructive rule that can only be approximated. For ex-ample Chen and Warren do such loop detection in their SLG or XSB system[CW95,CSW95,CW96] for non-disjunctive programs (under WFS and STABLE)by tabling techniques. However, the main focus of this paper was to introduce

the constraint machinery and to combine it with our former calculus. Loop de-tection is beyond the scope of this paper and we only give some hints in the nextsubsection.Another improvement is to apply the relevance-property (see [BD97a]). Rele-vance is the condition that a query does only depend on the subprogram formedby the call-graph below that query. This property holds for D-WFS [BD95a]and therefore, given a query Q we do not have to consider the whole residualprogram of �, but only the relevant part of it with respect to the query. Thisoften has the e�ect that this subprogram is much smaller than the original one.6.1 Explicit Loop DetectionObviously, by the undecidability of D-WFS, there are always cases where ourprocedure will not terminate. But sometimes we can overcome this problem. Letus consider the following example:� : p(x) p(s(x))p(s(0))) Applying the GPPE and NMIN we get:�0 : p(x) p(s(s(x))) / x 6= 0 ^ x 6= s(0) (�)p(s(0)) p(0) We notice, that the GPPE rule can be applied on (�) again and again, al-though it is clear that only p(0)) and p(s(0)) hold in the D-WFS semantics forthis example (and :p(si(0)) for all i � 2), because both facts cannot be replacedby any of the transformation rules. Here we need a sort of loop detection. Asfar as we know that GPPE can only be applied to the clause itself and that thecorresponding term of the predicate to be replaced gets larger and larger, we canimmediately delete such a rule|it will only cause an in�nite loop that is notgrounded. Such a deletion is in fact nothing but an approximation of the loopdetection rule. Finally we get then the following residual programres(�) : p(s(0)) p(0) from which D-WFS follows immediately. Of course such approximations needfurther investigation.6.2 OutlookDisjunctive logic programs are natural candidates for e.g. knowledge representa-tion tasks. Often WFS for non-disjunctive programs is too weak. The possibilityto explicitly write down disjunctive statements extends the expressive power andmakes the formulation of many statements quite naturally. On the other hand,

when such information is not needed, our semantics D-WFS coincides with WFSand hence shares its computational advantages. In contrast to the stable seman-tics, D-WFS is consistent and goal-directed since the GPPE acts top-down. Forthis, it seems a good idea to make the GPPE more incremental, i.e. to drop therequirement that all de�nitions of one predicate have to be inserted at once.A constraint logic programming implementation is currently undertakenin ECLiPSe-Prolog [ECR95] at the University of Koblenz as part of the4-year project on Disjunctive Logic Programming (see [DF96,ADN97] andhttp://www.uni-koblenz.de/ag-ki/DLP/). We expect to improve e�ciency of non-monotonic systems by exploiting constraint logic programming. For positive dis-junctive logic programming, the advantage of such a combination has been showne.g. in [ST96]. Termination criteria and control are currently elaborated moreprecisely and are subject of future research. But here for the �rst time, we haveconsidered a framework for a non-ground disjunctive semantics.We also mentioned in Subsection 4.3 that our framework can be even moregeneralised. It is possible to introduce more constraint predicates than just equal-ity \=". But in contrast to usual constraint logic programming, the constraintlanguage must be closed not only under conjunction and existential quanti�-cation, but under all logical connectives. In this respect, our work yields thebasis for a general combination of two paradigms: constraint logic programmingand non-monotonic reasoning. This would lead to a very powerful programminglanguage.References[AD94] Chandrabose Aravindan and Phan Minh Dung. Partial deduction of logicprograms wrt well-founded semantics. New Generation Computing, 13:45{74, 1994.[ADN97] Chandrabose Aravindan, J�urgen Dix, and Ilkka Niemel�a. The DisLoP-project. Technical Report TR 1/97, University of Koblenz, Department ofComputer Science, Rheinau 1, January 1997.[BD94] Stefan Brass and J�urgen Dix. A disjunctive semantics based on unfold-ing and bottom-up evaluation. In Bernd Wol�nger, editor, Innovationenbei Rechen- und Kommunikationssystemen, (IFIP '94-Congress, WorkshopFG2: Disjunctive Logic Programming and Disjunctive Databases), pages83{91, Berlin, 1994. Springer.[BD95a] Stefan Brass and J�urgen Dix. A General Approach to Bottom-Up Compu-tation of Disjunctive Semantics. In J. Dix, L. Pereira, and T. Przymusinski,editors, Nonmonotonic Extensions of Logic Programming, LNAI 927, pages127{155. Springer, Berlin, 1995.[BD95b] Stefan Brass and J�urgen Dix. Disjunctive Semantics based upon Partialand Bottom-Up Evaluation. In Leon Sterling, editor, Proceedings of the12th Int. Conf. on Logic Programming, Tokyo, pages 199{213. MIT Press,June 1995.[BD96] Stefan Brass and J�urgen Dix. Characterizing D-WFS: Con uence andIterated GCWA. In L.M. Pereira J.J. Alferes and E. Orlowska, editors,Logics in Arti�cial Intelligence (JELIA '96), LNCS 1126, pages 268{283.

Springer, 1996. (Extended version will appear in the Journal of AutomatedReasoning in 1997.).[BD97a] Stefan Brass and J�urgen Dix. Characterizations of the Disjunctive StableSemantics by Partial Evaluation. Journal of Logic Programming, forth-coming, 1997. (Extended abstract appeared in: Characterizations of theStable Semantics by Partial Evaluation LPNMR, Proceedings of the ThirdInternational Conference, Kentucky , pages 85{98, 1995. Springer.).[BD97b] Stefan Brass and J�urgen Dix. Semantics of Disjunctive Logic ProgramsBased on Partial Evaluation. Journal of Logic Programming, accepted forpublication, 1997. (Extended abstract appeared in: Disjunctive SemanticsBased upon Partial and Bottom-Up Evaluation, Proceedings of the 12-thInternational Logic Programming Conference, Tokyo, pages 199{213, 1995.MIT Press.).[CL89] Hubert Comon and Pierre Lescanne. Equational problems and disuni�ca-tion. Journal of Symbolic Computation, 7:371{425, 1989.[Col86] Alain Colmerauer. Theoretical model of Prolog II. In Michel van Caneghamand David H.D. Warren, editors, Logic programming and its applications,pages 3{31. Ablex Publishing Corporation, Norwood, NJ, 1986.[CSW95] Weidong Chen, Terrance Swift, and David S. Warren. E�cient Top-DownComputation of Queries under the Well-Founded Semantics. Journal ofLogic Programming, 24(3):219{245, 1995.[CW95] Weidong Chen and David S. Warren. Computing of Stable Models and itsIntegration with Logical Query Processing. IEEE Transactions on Knowl-edge and Data Engineering, 17:279{300, 1995.[CW96] Weidong Chen and David S. Warren. Tabled Evaluation with Delaying forGeneral Logic Programs. Journal of the ACM, 43(1):20{74, January 1996.[DF96] J. Dix and U. Furbach. The DFG-Project DisLoP on Disjunctive LogicProgramming. Computational Logic, 2:89{90, 1996.[DLMW96] J�urgen Dix, Donald Loveland, Jack Minker, and David. S. Warren. Dis-junctive Logic Programming and databases: Nonmonotonic Aspects. Tech-nical Report Dagstuhl Seminar Report 150, IBFI GmbH, Schlo� Dagstuhl,1996.[ECR95] ECRC GmbH, M�unchen. ECLiPSe 3.5: User Manual { Extensions UserManual, 1995.[EGLS96] T. Eiter, G. Gottlob, J. Lu, and V. S. Subrahmanian. Computing Non-Ground Representations of Stable Models. Technical report, University ofMaryland, 1996.[JM94] Joxan Ja�ar and Michael J. Maher. Constraint logic programming: a sur-vey. Journal of Logic Programming, 19,20:503{581, 1994.[KNS95] Vadim Kagan, Anil Nerode, and V. S. Subrahmanian. Computing MinimalModels by Partial Instantiation. Theoretical Computer Science, 155:157{177, 1995.[KSS91] David B. Kemp, Peter J. Stuckey, and Divesh Srivastava. Magic Sets andBottom-Up Evaluation of Well-Founded Models. In Vijay Saraswat andKazunori Ueda, editors, Proceedings of the 1991 Int. Symposium on LogicProgramming, pages 337{351. MIT, June 1991.[Mah88] Michael J. Maher. Complete axiomatizations of the algebras of �nite, ra-tional and in�nite trees. In Proceedings of the 3rd Annual Symposium onLogic in Computer Science, pages 348{359. Computer Society Press, 1988.

[Mah93] Michael J. Maher. A logic programming view of CLP. In David S. Warren,editor, Proceedings of the 10th International Conference on Logic Program-ming, pages 737{753. MIT Press, Cambridge, MA, London, England, 1993.Budapest, 1993.[SS95] Chiaki Sakama and Hirohisa Seki. Partial Deduction of Disjunctive LogicPrograms: A Declarative Approach. In Logic Program Synthesis and Trans-formation { Meta Programming in Logic, LNCS 883, pages 170{182, Berlin,1995. Springer. Extended version to appear in Journal of Logic Program-ming.[ST96] Frieder Stolzenburg and Bernd Thomas. Analysing rule sets for the calcu-lation of banking fees by a theorem prover with constraints. In Proceedingsof the 2nd International Conference on Practical Application of ConstraintTechnology, pages 269{282, London, 1996. Practical Application Company.[Stu91] Peter J. Stuckey. Constructive negation for constraint logic programming.In Proceedings of the 6th Annual Symposium on Logic in Computer Science,pages 328{339, 1991.