Preprin t 0 (1999) ?{? 1hudson/papers/amai-nlp.pdf · 2007-07-18 · o ccurrence of p in (6) b y (q...

26

Transcript of Preprin t 0 (1999) ?{? 1hudson/papers/amai-nlp.pdf · 2007-07-18 · o ccurrence of p in (6) b y (q...

Page 1: Preprin t 0 (1999) ?{? 1hudson/papers/amai-nlp.pdf · 2007-07-18 · o ccurrence of p in (6) b y (q ; r) is a form ula, but result applying the same op eration to second o ccurrence

Preprint 0 (1999) ?{? 1Nested Expressions in Logic ProgramsVladimir Lifschitz and Lappoon R. TangDepartment of Computer SciencesUniversity of Texas at AustinAustin, TX 78712, USAHudson TurnerDepartment of Computer ScienceUniversity of Minnesota at DuluthDuluth, MN 55812, USAWe extend the answer set semantics to a class of logic programs with nestedexpressions permitted in the bodies and heads of rules. These expressions are formedfrom literals using negation as failure, conjunction (,) and disjunction (;) that canbe nested arbitrarily. Conditional expressions are introduced as abbreviations. Thestudy of equivalent transformations of programs with nested expressions shows thatany such program is equivalent to a set of disjunctive rules, possibly with negationas failure in the heads. The generalized answer set semantics is related to the Lloyd-Topor generalization of Clark's completion and to the logic of minimal belief andnegation as failure.1. IntroductionIn most papers on the semantics of logic programming, the body of a rule issupposed to be a list of syntactically simple expressions, such as atoms or literals.The syntax of Prolog, however, permits nested expressions. Besides conjunctions(p; q) and negation as failure (not p), these expressions may include, for instance,disjunctions (p; q) and if-then-else constructs (p! q; r), nested arbitrarily.The use of such expressions does not appear to make a program any lessdeclarative. Declaratively, the rules (p! q; r); t (1)

Page 2: Preprin t 0 (1999) ?{? 1hudson/papers/amai-nlp.pdf · 2007-07-18 · o ccurrence of p in (6) b y (q ; r) is a form ula, but result applying the same op eration to second o ccurrence

2has the same meaning as the pair of ruless p; q; ts not p; r; t (2)but it is more concise. The usefulness of the if-then-else operator is related alsoto the fact that p is evaluated only once when (1) is processed by Prolog; in (2),p may be evaluated twice. To eliminate this unnecessary recomputation withoutthe use of the if-then-else construct, one would have to use cut. For these reasons,the use of nested expressions is standard practice in Prolog programming.The �rst declarative semantics for logic programs with nested expressionswas proposed by Lloyd and Topor [17], who extended the completion semantics[3] to programs with arbitrary �rst-order formulas in the bodies of rules. In thisnote, we propose a semantics for programs with nested expressions that is basedon the answer set (\stable model") approach [7]. The role of logic programsunder the answer set semantics as a knowledge representation language has beengrowing in recent years. This is evidenced by the development of software systemsfor computing answer sets, such as smodels [19] and dlv [5], by the emergenceof \stable model programming" as an alternative logic programming paradigm[18] and by the use of answer sets for specifying planning problems [21,14] and forthe development of e�cient planning algorithms [4]. The extension of the answerset semantics proposed below can serve as a speci�cation for extending systemslike smodels and dlv to programs with nested expressions.In this paper, we restrict attention to propositional programs; the semanticscan be extended to programs with variables by grounding. Both the heads andbodies of the rules in such programs are formed from literals (atoms possiblypreceded by the classical negation sign :) using the operators; ; not (3)that can be nested arbitrarily. Conditional expressions are introduced as abbre-viations.An interesting fact about nested expressions under the answer set semanticsis that two negation as failure operators in a row do not, generally, cancel eachother. Our de�nition, applied, for instance, to the programp not not p ; (4)

Page 3: Preprin t 0 (1999) ?{? 1hudson/papers/amai-nlp.pdf · 2007-07-18 · o ccurrence of p in (6) b y (q ; r) is a form ula, but result applying the same op eration to second o ccurrence

3gives both ; and fpg as the answer sets, althoughp phas only one answer set ;. The following informal argument shows that this is infact reasonable. In (4), we can \denote" the subformula not p by q, and (4) willturn into p not q ;q not p :The answer sets for this program are fpg and fqg. After dropping the \auxiliary"symbol q from each of them, we will get the two answer sets shown above.In Sections 2 and 3 we de�ne the syntax and semantics of programs withnested expressions. In Section 4, we turn to the study of equivalent transfor-mations of programs with nested expressions,1 and show that any such programcan be equivalently transformed into a set of \disjunctive rules" in the sense ofSection 5.1 of [13]|expressions of the formL1; : : : ;Lk;not Lk+1; : : : ;not Ll Ll+1; : : : ; Lm;not Lm+1; : : : ;not Ln (5)where 0 � k � l � m � n and all Li are literals.2 A somewhat unorthodoxfeature of (5) is the possibility of negation as failure in the head. This possibility,useful in abductive logic programming [10] and in the theory of updates [1], isessential here also, because in the process of \unwinding" a nested expression inthe body some occurrences of negation as failure can move to the head.In Section 5 we discuss the relation of our proposal to the Lloyd and Toporsystem mentioned above. Several authors, including Lin and Shoham [16], Lif-schitz [12], Herre and Wagner [8] and Pearce [20], described ways to embed logicprograms under the answer set semantics into languages that are closed underthe formation rules of propositional logic. In Section 6 the embedding due toLifschitz is extended to logic programs with nested expressions.Proofs of theorems are given in Section 7.1 These transformations are somewhat similar to the \algebraic laws" of Prolog discussed in [9]on the basis of a procedural view of logic programming.2 In [13], the vertical bar is used instead of the semicolon to separate literals in the head of arule.

Page 4: Preprin t 0 (1999) ?{? 1hudson/papers/amai-nlp.pdf · 2007-07-18 · o ccurrence of p in (6) b y (q ; r) is a form ula, but result applying the same op eration to second o ccurrence

42. SyntaxThe words atom and literal are understood here as in propositional logic.Elementary formulas are literals and the 0-place connectives ? (\false") and >(\true"). Formulas are built from elementary formulas using the unary connectivenot and the binary connectives ; (conjunction) and ; (disjunction). A rule is anexpression of the form F Gwhere F and G are formulas, called the head and the body of the rule.For any formulas F , G and H,F ! G;Hstands for the formula (F;G); (not F;H) :We will write a rule of the form F > as F and identify it with for-mula F . Rules of the form ? G will be called constraints and written as G.Given these conventions, the de�nition of a rule given above is a generalizationof rules in the sense of [7], and even of \disjunctive rules" (5).A program is a set of rules.Note that, syntactically, the status of the classical negation operator : isdi�erent from the status of operators (3): classical negation is allowed only infront of an atom. About an occurrence of a formula F in a formula or a rule wewill say that it is singular if the symbol before this occurrence is :; otherwise theoccurrence is regular. It is clear that an occurrence of F can be singular only ifF is an atom. For instance, in the formulanot p;not :p (6)the �rst occurrence of p is regular, and the second is singular. This di�erence isimportant because the result of replacing a regular occurrence of F in a formulaor a rule by another formula G is again a formula or a rule, but for a singularoccurrence this is not necessarily the case. For instance, the result of replacingthe �rst occurrence of p in (6) by (q; r) is a formula, but the result of applyingthe same operation to the second occurrence is not.

Page 5: Preprin t 0 (1999) ?{? 1hudson/papers/amai-nlp.pdf · 2007-07-18 · o ccurrence of p in (6) b y (q ; r) is a form ula, but result applying the same op eration to second o ccurrence

53. SemanticsRecall that the de�nition of an answer set [7] consists of two parts. First thisconcept is de�ned for the \basic" case of programs that do not contain negationas failure. Then the \reduct" of a program relative to a set of literals is de�ned,and this is used to reduce the general case to the basic case. The extension ofthis de�nition to programs with nesting follows the same plan.The formulas, rules and programs that do not contain the negation as failureoperator not will be called basic. We de�ne when a consistent set X of literalssatis�es a basic formula F (symbolically, X j= F ) recursively, as follows:� for elementary F , X j= F if F 2 X or F = >.� X j= (F;G) if X j= F and X j= G .� X j= (F ;G) if X j= F or X j= G .Let � be a basic program. A consistent set X of literals is closed under �if, for every rule F G in �, X j= F whenever X j= G. We say that X is ananswer set for � if X is minimal among the consistent sets of literals closed under�.Example 1. Consider the program whose only rule isq p;:p : (7)Being closed under (7) is characterized by the following condition: if p 2 X or:p 2 X then q 2 X. It is clear that the only answer set for (7) is empty. Ifwe add the rule p (that is, p >) to this program then fp; qg will be the onlyanswer set.The reduct of a formula, rule or program relative to a consistent set X ofliterals is de�ned recursively, as follows:� for elementary F , FX = F .� (F;G)X = (FX ; GX) .� (F ;G)X = (FX ;GX) .� (not F )X = (?; if X j= FX ,>; otherwise.� (F G)X = FX GX .� �X = f(F G)X : F G 2 �g .

Page 6: Preprin t 0 (1999) ?{? 1hudson/papers/amai-nlp.pdf · 2007-07-18 · o ccurrence of p in (6) b y (q ; r) is a form ula, but result applying the same op eration to second o ccurrence

6 A consistent set X of literals is an answer set for � if it is an answer set forthe reduct �X .Example 2. Consider the program whose only rule isp (q ! r;not s) ; (8)that is, p (q; r); (not q;not s) :Take X = fpg; let us check that X is an answer set for this program. Note thatqX = q, so that qX =2 X and X 6j= qX . Consequently (not q)X = >. Similarly,(not s)X = >. It follows that((q; r); (not q;not s))X = (q; r); (>;>) :Consequently the reduct of (8) relative to X isp (q; r); (>;>) :The only answer set for this program is fpg, so X is indeed an answer set for (8).(There are no other answer sets.)Example 3. Consider program (4). For X1 = ;, pX1 =2 X1, which means thatX1 6j= pX1 and consequently (not p)X1 = >. It follows that X1 j= (not p)X1 , sothat (not not p)X1 = ?. Hence the reduct of (4) relative to X1 isp ? :The only answer set for this program is empty, so X1 is indeed an answer setfor (4). Now take X2 = fpg. Note that pX2 2 X2, so X2 j= pX2 . Consequently(not p)X2 = ?. It follows that X2 6j= (not p)X2 , so that (not not p)X2 = >. Hencethe reduct of (4) relative to X2 is p > :The only answer set for this program is fpg, so X2 is an answer set for (4) also.Proposition 1. For a program whose rules have form (5), the answer setsaccording to the de�nition of an answer set given above are exactly the consistentanswer sets according to the de�nition from [13].

Page 7: Preprin t 0 (1999) ?{? 1hudson/papers/amai-nlp.pdf · 2007-07-18 · o ccurrence of p in (6) b y (q ; r) is a form ula, but result applying the same op eration to second o ccurrence

7Unlike the de�nitions of an answer set given in [7,15,13], the de�nition in-troduced above does not allow for an inconsistent answer set. All three previousde�nitions agree, where they overlap, on the question of consistent answer sets,but there is some disagreement among them on inconsistent answer sets. Forinstance, according to [15], the programnot phas two answer sets: ; and the set of all literals. According to [13], it has onlythe empty answer set. (In [7], negation as failure in the head is not considered.)As another example, consider the programp ; p :According to [7] and [13], this program has no answer sets. In [15], it has a singleanswer set: the set of all literals.Let � be a set of constraints. A consistent set X of literals violates � if itis not closed under �X , that is to say, if � includes a constraint G such thatX j= GX . For instance, X violates f pg if p 2 X; X violates f not pg ifp 62 X. The e�ect of adding a set of constraints to a program is to rule out theanswer sets that violate these constraints. More precisely:Proposition 2. Let �1, �2 be programs such that every rule in �2 is a con-straint. A consistent set of literals is an answer set for �1 [�2 i� it is an answerset for �1 and does not violate �2.4. Equivalent TransformationsIn this section we describe several equivalent transformations of programswith nested expressions. These transformations can turn any program into anequivalent program whose rules have form (5).Equivalence can be understood here as a condition stronger than merelyhaving the same answer sets. About programs �1 and �2 we say that they areequivalent if, for any consistent sets X and Y of literals, X is closed under �Y1i� X is closed under �Y2 . It is clear that the reducts of two equivalent programsrelative to the same set of literals have the same answer sets. Consequently, anytwo equivalent programs have the same answer sets.

Page 8: Preprin t 0 (1999) ?{? 1hudson/papers/amai-nlp.pdf · 2007-07-18 · o ccurrence of p in (6) b y (q ; r) is a form ula, but result applying the same op eration to second o ccurrence

8 It is clear also that if �1 is equivalent to �2 then, for any program �, �1[�is equivalent to �2 [�.Some of the transformations discussed in this section replace subformulasin the program by other formulas. Some transformations move subformulas fromthe body of a rule to its head, or from the head to the body. We will also considertransformations that break a rule into two rules.In connection with transformations of the �rst kind, we need the followingde�nition. A formula F is equivalent to a formula G (symbolically, F , G) if,for any consistent sets X and Y of literals, X j= F Y i� X j= GY . Here is whythis de�nition is of interest to us:Proposition 3. Let � be a program, and let F , G be a pair of equivalentformulas. Any program obtained from � by replacing some regular occurrencesof F by G is equivalent to �.Here is a collection of useful facts about the equivalence of formulas:Proposition 4. For any formulas F , G, H,(i) F;G, G;F and F ;G, G;F .(ii) (F;G);H , F; (G;H) and (F ;G);H , F ; (G;H) .(iii) F; (G;H), (F;G); (F;H) and F ; (G;H), (F ;G); (F ;H) .(iv) not (F;G), not F ;not G and not (F ;G), not F;not G .(v) not not not F , not F .(vi) F;> , F and F ;> , > .(vii) F;? , ? and F ;? , F .(viii) if p is an atom then p;:p, ? and not p;not :p, > .(ix) not > , ? and not ? , > .Using Propositions 3 and 4, we can show that any formula can be convertedto \disjunctive" and \conjunctive" normal forms, described in Proposition 5 be-low. A simple conjunction is a formula of the formL1; : : : ; Lk;not Lk+1; : : : ;not Lm;not not Lm+1; : : : ;not not Ln (9)

Page 9: Preprin t 0 (1999) ?{? 1hudson/papers/amai-nlp.pdf · 2007-07-18 · o ccurrence of p in (6) b y (q ; r) is a form ula, but result applying the same op eration to second o ccurrence

9and a simple disjunction is a formula of the formL1; : : : ;Lk;not Lk+1; : : : ;not Lm;not not Lm+1; : : : ;not not Ln (10)where 0 � k � m � n, n > 0 and all Li are literals.Proposition 5. Any formula is equivalent to(i) a formula of the form F1; : : : ;Fn where n � 1 and each Fi is a simple con-junction, and(ii) a formula of the form F1; : : : ; Fn where n � 1 and each Fi is a simple dis-junction.The following proposition describes further equivalent transformations ofprograms.Proposition 6.(i) F;G H is equivalent to F H ;G H :(ii) F G;H is equivalent to F G ;F H :(iii) F G;not not H is equivalent to F ;not H G :(iv) F ;not not G H is equivalent to F not G;H :From the facts stated above, we can derive:Proposition 7. Any program is equivalent to a set of rules of form (5).Examination of the proof of Proposition 7 shows that the rules of form (5)generated from a program � do not contain negation as failure in the heads(k = l) if negation as failure in �(i) does not occur in the heads of rules, and(ii) is not nested, that is, not applied to formulas containing negation as failure.

Page 10: Preprin t 0 (1999) ?{? 1hudson/papers/amai-nlp.pdf · 2007-07-18 · o ccurrence of p in (6) b y (q ; r) is a form ula, but result applying the same op eration to second o ccurrence

10The answer sets for any collection of rules of form (5) without negation as failurein the heads are known to have the anti-chain property: an answer set for such aprogram cannot be a proper subset of another answer set for the same program.It follows that the answer sets for any collection of rules satisfying conditions (i)and (ii) form an anti-chain. Program (4) does not satisfy condition (ii), and oneof its two answer sets is a subset of the other.5. Relation to the Lloyd-Topor SemanticsThe review of the Lloyd-Topor semantics below di�ers from its descriptionin [17] in two ways. First, it is restricted to the propositional case. Second, it isstated in terms of \supported models" [2] instead of completion, which allows usto extend the theory to in�nite programs. For �nite programs, the two de�nitionsare equivalent.A (propositional) Lloyd-Topor rule is an expression of the formp Fwhere p is an atom and F is a propositional formula. A Lloyd-Topor program isa set of Lloyd-Topor rules.Recall that a (propositional) interpretation is a function from atoms to truthvalues. We will identify an interpetation with the set of atoms to which it assignsthe value true.Let � be a Lloyd-Topor program. A model of � is an interpretation I suchthat, for any rule p F in � such that I satis�es F , I satis�es p also. A modelI of � is supported if, for any atom p such that I satis�es p, there is a rule p Fin � such that I satis�es F .For instance, the Lloyd-Topor program whose only rule is p p has twosupported models: ; and fpg.The translation � of propositional formulas, and of Lloyd-Topor rules andprograms, to our language is de�ned as follows, assuming that all connectivesother than ^, _ and : have been eliminated:� for atomic F , �F = not not F .� �(F ^G) = �F; �G .� �(F _G) = �F ; �G .� �(:F ) = not �F .

Page 11: Preprin t 0 (1999) ?{? 1hudson/papers/amai-nlp.pdf · 2007-07-18 · o ccurrence of p in (6) b y (q ; r) is a form ula, but result applying the same op eration to second o ccurrence

11� �(p F ) = p �F .� �� = f�(p F ) : p F 2 �g .The soundness of this translation is expressed by the following theorem:Proposition 8. For any Lloyd-Topor program � and any interpretation I, Iis a supported model of � i� I is an answer set for ��.Since the heads of the rules of �� are atoms, any answer set for this programis a set of atoms, that is to say, an interpretation. Consequently, we can concludefrom Proposition 8 that every answer set for �� is a supported model of �.For instance, �(p p) is (4). In accordance with Proposition 8, the twoanswer sets for (4) computed in Example 3 are identical to the two supportedmodels of p p. As another example, the result of applying � top :q (11)is p not not not q :According to Propositions 3 and 4(v), this program is equivalent top not q :We see that, in application to (11), the Lloyd-Topor semantics is equivalent tothe answer set semantics, modulo replacing : by not . This is not surprising inview of the fact that the result of this replacement is a tight program (see [13],and the result from [6] reproduced there as Proposition 3.5).Proposition 8 is similar to Theorem 5.10 from [11], which is limited to pro-grams without nested expressions.6. Relation to MBNFIn the propositional fragment of the logic of minimal belief and negation asfailure (MBNF) [12], formulas are built from atoms using propositional connec-tives and two modal operators: B (\minimal belief") and not . An MBNF theoryis a set of formulas (axioms) in this language. We will introduce a translation� that maps formulas and rules to formulas of MBNF, and maps programs toMBNF theories. The translation is de�ned recursively, as follows:

Page 12: Preprin t 0 (1999) ?{? 1hudson/papers/amai-nlp.pdf · 2007-07-18 · o ccurrence of p in (6) b y (q ; r) is a form ula, but result applying the same op eration to second o ccurrence

12� for elementary F , �F = BF .� �(F;G) = �F ^ �G .� �(F ;G) = �F _ �G .� for elementary F , �(not F ) = not F .� �(not (F;G)) = �(not F ) _ �(not G) .� �(not (F ;G)) = �(not F ) ^ �(not G) .� �(not not F ) = :�(not F ) .� �(F G) = �G � �F .� �� = f�(F G) : F G 2 �g .As an example, note that, in application to (4), � gives the formula:not p � Bp :This translation is essentially an extension of the translation from Section 5of [12] to programs with nested expressions. The translation �� of any program �is an MBNF theory of the special type studied in [15]|a \theory with protectedliterals." This means that every occurrence of an atom in an axiom of this theoryis a part of an expression of the form BL or not L, where L is a literal.Recall that models of a propositional MBNF theory are de�ned as the pairs(I; S), where I is an interpretation and S is a set of interpretations, that satisfya certain �xpoint condition (see [12], Section 4).The following theorem establishes a correspondence between the answer setsfor a program � and the consistent models of the MBNF theory �� (that is, themodels (I; S) with nonempty S). For any consistent set X of literals, by Mod(X)we denote the (nonempty) set of interpretations that satisfy all members of X.Proposition 9. For any program �, consistent set X of literals, and interpre-tation I, X is an answer set for � i� (I;Mod(X)) is a model of ��. Moreover,every consistent model of �� can be represented in the form (I;Mod(X)), whereI is an interpretation and X is a consistent set of literals.

Page 13: Preprin t 0 (1999) ?{? 1hudson/papers/amai-nlp.pdf · 2007-07-18 · o ccurrence of p in (6) b y (q ; r) is a form ula, but result applying the same op eration to second o ccurrence

137. Proofs of Theorems7.1. Proof of Proposition 1Proposition 1. For a program whose rules have form (5), the answer setsaccording to the de�nition of an answer set given above are exactly the consistentanswer sets according to the de�nition from [13].The de�nition of an answer set in [13] di�ers from the one given above inthree ways: the de�nition of closure under a basic program is di�erent; the de�ni-tion of the reduct is di�erent; the inconsistent answer set is allowed. Proposition 1follows from two lemmas:Lemma 1. Let � be a program whose rules have the formL1; : : : ;Lk Lk+1; : : : ; Lm (12)where 0 � k � m and all Li are literals, and let X be a consistent set of literals.X is closed under � in the sense of this paper i� X is closed under � in the senseof [13].Lemma 2. Let � be a program whose rules have the form (5), and let X, Y beconsistent sets of literals. Y is closed under �X i� Y is closed under the reductof � relative to X in the sense of [13].(According to the �rst lemma, there is no need to distinguish between thetwo meanings of \closed under" in the statement of the second lemma.)Proof of Lemma 1. It is easy to verify that X is closed under � in the senseof this paper i�, for every rule (12) in �, X includes at least one of the literalsL1; : : : ; Lk provided that X includes all of Lk+1; : : : ; Lm. This is exactly what itis for X to be closed under � in the sense of [13].Proof of Lemma 2. For a program � whose rules have form (5) and for a con-sistent set X of literals, �X can be characterized as the result of replacing eachsubformula of the form not L in � by ? if L 2 X, and by > otherwise. On theother hand, the reduct of � relative to X in the sense of [13] is de�ned as theprogram obtained from � by

Page 14: Preprin t 0 (1999) ?{? 1hudson/papers/amai-nlp.pdf · 2007-07-18 · o ccurrence of p in (6) b y (q ; r) is a form ula, but result applying the same op eration to second o ccurrence

14� deleting every rule (5) such that at least one of Lk+1; : : : ; Ll is not in X, or atleast one of Lm+1; : : : ; Ln is in X, and� replacing each remaining rule (5) byL1; : : : ;Lk Ll+1; : : : ; Lm :It is easy to verify that this program can be obtained from �X by� deleting every rule (5) such that its head contains > or body contains ?, and� removing every ? in the head, and every > in the body, of each remainingrule.It is clear that these steps have no e�ect on whether a consistent set Y of literalsis closed under the program.7.2. Proof of Proposition 2Lemma 3. Let � be a set of basic constraints, and let X be a consistent setof literals. If X is closed under � then every subset of X is closed under �.Proof. It is easy to see that, for any consistent sets X, Y of literals and anybasic formula G, if Y � X and Y j= G then X j= G.Proposition 2. Let �1, �2 be programs such that every rule in �2 is a con-straint. A consistent set of literals is an answer set for �1 [�2 i� it is an answerset for �1 and does not violate �2.Proof. Let X be a consistent set of literals. We need to show that X is ananswer for �X1 [�X2 i� it is an answer set for �X1 and does not violate �2.Left-to-right: Assume that X is an answer for �X1 [�X2 . Then X is closedunder both �X1 and �X2 . The second condition means that X does not violate�2. It remains to check the minimality of X. Let Y be a subset of X closedunder �X1 . Since X is closed under �X2 , it follows by Lemma 3 that Y is closedunder �X2 also. Since X is minimal under the sets closed under �X1 [ �X2 , itfollows that Y = X.Right-to-left: Assume that X is an answer set for �X1 and does not violate�2. The second condition means that X is closed under �X2 . Consequently, X isclosed under both �X1 and �X2 . It remains to check the minimality of X. Let Y

Page 15: Preprin t 0 (1999) ?{? 1hudson/papers/amai-nlp.pdf · 2007-07-18 · o ccurrence of p in (6) b y (q ; r) is a form ula, but result applying the same op eration to second o ccurrence

15be a subset of X closed under �X1 [ �X2 Then, in particular, Y is closed under�X1 . Since X is minimal among such sets, it follows that Y = X.7.3. Proof of Proposition 3Lemma 4. Let F , G, H be formulas such that F , G. If a formula H 0 isobtained from H by replacing some regular occurrences of F by G then H , H 0.Proof. By structural induction on H.Case 1: H is elementary. Then the only regular occurrence of a formula inH is H itself. Consequently either H = F and H 0 = G or H 0 = H. In both cases,H , H 0.Case 2: H = H1;H2. If H = F and H 0 = G then the assertion is trivial.Otherwise, H 0 = H 01;H 02 and, by the induction hypothesis, H1 , H 01, H2 , H 02.Then X j= HY i� X j= (H1;H2)Yi� X j= (H1)Y ; (H2)Yi� X j= (H1)Y and X j= (H2)Yi� X j= (H 01)Y and X j= (H 02)Yi� X j= (H 01)Y ; (H 02)Yi� X j= (H 01;H 02)Yi� X j= (H 0)Y :Case 3: H = H1;H2. Similar to Case 2.Case 4: H = not H1. If H = F and H 0 = G then the assertion is trivial.Otherwise, H 0 = not H 01 and, by the induction hypothesis, H1 , H 01. ThenX j= HY i� X j= (not H1)Yi� (not H1)Y = >i� Y 6j= (H1)Yi� Y 6j= (H 01)Yi� (not H 01)Y = >i� X j= (not H 01)Yi� X j= (H 0)Y :Proposition 3. Let � be a program, and let F , G be a pair of equivalent

Page 16: Preprin t 0 (1999) ?{? 1hudson/papers/amai-nlp.pdf · 2007-07-18 · o ccurrence of p in (6) b y (q ; r) is a form ula, but result applying the same op eration to second o ccurrence

16formulas. Any program obtained from � by replacing some regular occurrencesof F by G is equivalent to �.Proof. Assume that �0 can be obtained from � by replacing some regular oc-currences of F by an equivalent formula G, and assume that X is closed under(�0)Y . Take any rule H1 H2 in �. For the corresponding rule H 01 H 02 in �0,if X j= (H 02)Y then X j= (H 01)Y . By Lemma 4, H1 is equivalent to H 01, and H2 isequivalent to H 02. Consequently, if X j= (H2)Y then X j= (H1)Y . It follows thatX is closed under �Y . The proof in the other direction is similar.7.4. Proof of Proposition 4Proposition 4. For any formulas F , G, H,(i) F;G, G;F and F ;G, G;F .(ii) (F;G);H , F; (G;H) and (F ;G);H , F ; (G;H) .(iii) F; (G;H), (F;G); (F;H) and F ; (G;H), (F ;G); (F ;H) .(iv) not (F;G), not F ;not G and not (F ;G), not F;not G .(v) not not not F , not F .(vi) F;> , F and F ;> , > .(vii) F;? , ? and F ;? , F .(viii) if p is an atom then p;:p, ? and not p;not :p, > .(ix) not > , ? and not ? , > .Proof. All parts other than (iv) and (v) follow directly from the de�nitions. Forthe �rst assertion of part (iv),X j= (not (F;G))Y i� (not (F;G))Y = >i� Y 6j= (F;G)Yi� Y 6j= F Y ; GYi� Y 6j= F Y or Y 6j= GYi� (not F )Y = > or (not G)Y = >i� X j= (not F )Y or X j= (not G)Yi� X j= (not F )Y ; (not G)Yi� X j= (not F ;not G)Y :

Page 17: Preprin t 0 (1999) ?{? 1hudson/papers/amai-nlp.pdf · 2007-07-18 · o ccurrence of p in (6) b y (q ; r) is a form ula, but result applying the same op eration to second o ccurrence

17The proof of the second assertion is similar.For part (v),X j= (not not not F )Y i� (not not not F )Y = >i� Y 6j= (not not F )Yi� (not not F )Y = ?i� Y j= (not F )Yi� (not F )Y = >i� X j= (not F )Y :7.5. Proof of Proposition 5Lemma 5. (i) If F is equivalent to a simple conjunction then not F is equivalentto a simple disjunction. (ii) If F is equivalent to a simple disjunction then not Fis equivalent to a simple conjunction.Proof. Immediate from Proposition 4(i,ii,iv,v) and Lemma 4.Proposition 5. Any formula is equivalent to(i) a formula of the form F1; : : : ;Fn where n � 1 and each Fi is a simple con-junction, and(ii) a formula of the form F1; : : : ; Fn where n � 1 and each Fi is a simple dis-junction.Proof. Both parts are proved simultaneously by structural induction. Every ele-mentary formula is a literal or > or ?; in the latter cases, use Proposition 4(viii).Otherwise, assume that formulas F and G are each equivalent to formulas of theforms described in parts (i) and (ii) of Proposition 5. We need to check the samefor formulas F;G and F ;G. This follows from Proposition 4(ii,iii) and Lemma 4.We also need to check that not F is equivalent to formulas of the forms describedin parts (i) and (ii) of Proposition 5. This follows from Proposition 4(iv) andLemmas 4 and 5.7.6. Proof of Proposition 6Proposition 6.

Page 18: Preprin t 0 (1999) ?{? 1hudson/papers/amai-nlp.pdf · 2007-07-18 · o ccurrence of p in (6) b y (q ; r) is a form ula, but result applying the same op eration to second o ccurrence

18(i) F;G H is equivalent to F H ;G H :(ii) F G;H is equivalent to F G ;F H :(iii) F G;not not H is equivalent to F ;not H G :(iv) F ;not not G H is equivalent to F not G;H :Proof. Let X;Y be consistent sets of literals.Part (i): we need to check that X is closed under F Y ; GY HY i� X isclosed under F Y HY and GY HY . This is immediate from the de�nitionsof closure and satisfaction.The proof of part (ii) is similar.Part (iii): we need to check that X is closed underF Y GY ; (not not H)Y (13)i� X is closed under F Y ; (not H)Y GY : (14)If (not H)Y = > then (not not H)Y = ?, so that (13), (14) turn intoF Y GY ;?and F Y ;> GY :Clearly X is closed under both rules. Otherwise (not H)Y = ? and so(not not H)Y = >. Then (13), (14) turn intoF Y GY ;>and F Y ;? GY :Clearly X is closed under the �rst of these rules i� X is closed under the second.

Page 19: Preprin t 0 (1999) ?{? 1hudson/papers/amai-nlp.pdf · 2007-07-18 · o ccurrence of p in (6) b y (q ; r) is a form ula, but result applying the same op eration to second o ccurrence

19Part (iv): we need to check that X is closed underF Y ; (not not G)Y HY (15)i� X is closed under F Y (not G)Y ;HY : (16)If GY = ?, then (15) turns into F Y ;? HY ;while (16) turns into F Y >;HY :Clearly X is closed under the latter i� it is closed under the former. On the otherhand, if GY = >, then (15) turns intoF Y ;> HY ;while (16) turns into F Y ?;HY :Clearly X is closed under both rules.7.7. Proof of Proposition 7Proposition 7. Any program is equivalent to a set of rules of form (5).Proof. Propositions 3, 5 and 6(i,ii) show that any program is equivalent to a setof rules of the following form: the head is a simple disjunction, and the body isa simple conjunction. Thus we arrive at a set of rules of the formF1; : : : ;Fm Fm+1; : : : ; Fn (17)where 0 < m < n and each Fi has one of the formsL;not L;not not Lwhere L is a literal. Proposition 6(iii,iv) shows that any such rule is equivalentto a rule of the same form (17) in which every Fi has one of the formsL;not L :

Page 20: Preprin t 0 (1999) ?{? 1hudson/papers/amai-nlp.pdf · 2007-07-18 · o ccurrence of p in (6) b y (q ; r) is a form ula, but result applying the same op eration to second o ccurrence

207.8. Proof of Proposition 8Lemma 6. For any propositional formula F , interpretation I and consistentset X of literals, X j= (�F )I i� I satis�es F .Proof. By structural induction on F . If F is atomic thenX j= (�F )I i� X j= (not not F )Ii� (not not F )I = >i� I 6j= (not F )Ii� (not F )I = ?i� I j= F Ii� I j= Fi� F 2 Ii� I satis�es F:If F is G ^H thenX j= (�F )I i� X j= (�G; �H)Ii� X j= (�G)I ; (�H)Ii� X j= (�G)I and X j= (�H)Ii� I satis�es G and I satis�es Hi� I satis�es G ^H:In the case when F is G _H the proof is similar. If F is :G thenX j= (�F )I i� X j= (not �G)Ii� (not �G)I = >i� I 6j= (�G)Ii� I does not satisfy Gi� I satis�es :G:Proposition 8. For any Lloyd-Topor program � and any interpretation I, Iis a supported model of � i� I is an answer set for ��.Proof. The rules of (��)I have the form p (�F )I , where p F is a rulefrom �. Consequently, a consistent set X of literals is closed under (��)I i� Xincludes every atom p such that there is a rule p F in � for which X j= (�F )I .According to Lemma 6, the last formula simply says that I satis�es F . It follows

Page 21: Preprin t 0 (1999) ?{? 1hudson/papers/amai-nlp.pdf · 2007-07-18 · o ccurrence of p in (6) b y (q ; r) is a form ula, but result applying the same op eration to second o ccurrence

21that (��)I has a unique answer set|the set of all atoms p such that there is arule p F in � for which I satis�es F . Consequently I is an answer set for �� i�it satis�es the following condition: for any atom p, p 2 I i� there is a rule p Fin � for which I satis�es F . This is equivalent to saying that I is a supportedmodel of �.7.9. Proof of Proposition 9For any nonempty set S of interpretations, let L(S) be the (consistent) setof literals satis�ed by every member of S.The �rst lemma addresses the four equations in the recursive de�nition ofthe translation � that apply to formulas that begin with not .Lemma 7. For any formula F and nonempty sets S; S0 of interpretations suchthat S � S0, (not F )L(S) = > i� �(not F ) is true in (I; S0; S).Proof. By structural induction.Case 1: F is an elementary formula. Then(not F )L(S) = > i� L(S) 6j= FL(S)i� L(S) 6j= Fi� some member of S does not satisfy Fi� for some J 2 S, F is not true in (J; S0; S)i� not F is true in (I; S0; S)i� �(not F ) is true in (I; S0; S).Case 2: F is (G;H). By the induction hypothesis, (not G)L(S) = > i��(not G) is true in (I; S0; S), and (not H)L(S) = > i� �(not H) is true in (I; S0; S).Thus, (not (G;H))L(S) = > i� L(S) 6j= (G;H)L(S)i� L(S) 6j= (GL(S);HL(S))i� L(S) 6j= GL(S) or L(S) 6j= HL(S)i� (not G)L(S) = > or (not H)L(S) = >i� �(not G) is true in (I; S0; S)or �(not H) is true in (I; S0; S)i� �(not G) _ �(not H) is true in (I; S0; S)i� �(not (G;H)) is true in (I; S0; S) .Case 3: F is (G;H). Similar to Case 2.

Page 22: Preprin t 0 (1999) ?{? 1hudson/papers/amai-nlp.pdf · 2007-07-18 · o ccurrence of p in (6) b y (q ; r) is a form ula, but result applying the same op eration to second o ccurrence

22 Case 4: F is not G. By the induction hypothesis, (not G)L(S) = > i��(not G) is true in (I; S0; S). Thus,(not not G)L(S) = > i� L(S) 6j= (not G)L(S)i� (not G)L(S) 6= >i� �(not G) is not true in (I; S0; S)i� :�(not G) is true in (I; S0; S)i� �(not not G) is true in (I; S0; S) .Lemma 8. For any formula F and nonempty sets S; S0 of interpretations suchthat S � S0, L(S0) j= FL(S) i� �F is true in (I; S0; S).Proof. By structural induction.Case 1: F is elementary. ThenL(S0) j= FL(S) i� L(S0) j= Fi� every member of S0 satis�es Fi� for every J 2 S0, F is true in (J; S0; S)i� BF is true in (I; S0; S)i� �F is true in (I; S0; S) .Case 2: F is (G;H). By the induction hypothesis, L(S0) j= GL(S) i� �G istrue in (I; S0; S), and L(S0) j= HL(S) i� �H is true in (I; S0; S). Thus,L(S0) j= (G;H)L(S) i� L(S0) j= (GL(S);HL(S))i� L(S0) j= GL(S) and L(S0) j= HL(S)i� both �G and �H are true in (I; S0; S)i� �G ^ �H is true in (I; S0; S)i� �(G;H) is true in (I; S0; S) .Case 3: F is (G;H). Similar to Case 2.Case 4: F is not G. Since L(S0) j= (not G)L(S) i� (not G)L(S) = >, the claimfollows from the previous lemma.Lemma 9. For any program � and nonempty sets S; S0 of interpretations suchthat S � S0, L(S0) is closed under �L(S) i� every formula in �� is true in (I; S0; S).Proof. By de�nition, L(S0) is closed under �L(S) i�, for every rule F G 2 �,L(S0) j= FL(S) if L(S0) j= GL(S). The previous lemma shows that L(S0) j= FL(S)

Page 23: Preprin t 0 (1999) ?{? 1hudson/papers/amai-nlp.pdf · 2007-07-18 · o ccurrence of p in (6) b y (q ; r) is a form ula, but result applying the same op eration to second o ccurrence

23i� �F is true in (I; S0; S), and that L(S0) j= GL(S) i� �G is true in (I; S0; S).Hence, L(S0) j= FL(S) if L(S0) j= GL(S) i� �F is true in (I; S0; S) if �G isi� �G � �F is true in (I; S0; S)i� �(F G) is true in (I; S0; S) .Since �� = f�(F G) : F G 2 �g, we're done.Proposition 9. For any program �, consistent set X of literals, and interpre-tation I, X is an answer set for � i� (I;Mod(X)) is a model of ��. Moreover,every consistent model of �� can be represented in the form (I;Mod(X)), whereI is an interpretation and X is a consistent set of literals.Proof. We show the second part �rst. Assume that (I; S) is a consistent modelof ��. It follows that every formula in �� is true in (I; S; S). So by Lemma 9,L(S) is closed under �L(S). Let X = L(S). Notice that X = L(Mod(X)), sowe know by Lemma 9 that every formula in �� is true in (I;Mod(X); S). Nextnotice that S � Mod(L(S)). That is, S � Mod(X). Since (I; S) is a model of ��,it follows that S = Mod(X).For the right-to-left direction of the �rst part, assume that (I;Mod(X)) isa model of ��, where X is consistent set of literals. It follows that every formulain �� is true in (I;Mod(X);Mod(X)), and since X = L(Mod(X)), we knowby Lemma 9 that X is closed under �X . Let Y be a subset of X that is closedunder �X . Since Y = L(Mod(Y )), we know by Lemma 9 that every formula in ��is true in (I;Mod(Y );Mod(X)). Since Mod(X) � Mod(Y ) and (I;Mod(X)) is amodel of ��, we can conclude that X = Y , which shows that X is an answer setfor �.Now assume that X is an answer set for �. It follows that X is closed un-der �X . By Lemma 9, every formula in �� is true in (I;Mod(X);Mod(X)).Let S be a superset of Mod(X) such that every formula in �� is truein (I; S;Mod(X)). By Lemma 9, L(S) is closed under �X . Since L(S) � Xand X is an answer set for �, we conclude that L(S) = X. It follows thatS � Mod(X), and since Mod(X) � S, Mod(X) = S. We can conclude that(I;Mod(X)) is a model of ��.

Page 24: Preprin t 0 (1999) ?{? 1hudson/papers/amai-nlp.pdf · 2007-07-18 · o ccurrence of p in (6) b y (q ; r) is a form ula, but result applying the same op eration to second o ccurrence

248. ConclusionsWe showed how the answer set semantics can be extended to a class of logicprograms with nested expressions in the bodies and heads of rules. In the specialcase of disjunctive logic programs, the answer sets according to the new de�nitionare exactly the consistent answer sets according to the traditional de�nition. Inpublished papers, inconsistent answer sets were treated in di�erent ways; thenew de�nition does not allow for an inconsistent answer set at all. Our proposalcan be used as a speci�cation for extending systems like smodels and dlv toprograms with nested expressions.The study of equivalent transformations of programs with nested expressionsshows that such expressions can be always eliminated, altough this process maylead to the emergence of additional occurrences of negation as failure in the headsof rules.The proposed de�nition is related to the completion semantics for programswith formulas in the bodies of rules due to Lloyd and Topor and to the logic ofminimal belief and negation as failure.AcknowledgementsWe are grateful to Esra Erdem, Michael Gelfond, Katsumi Inoue, DavidPearce, David S. Warren and Phoebe Weidmann, and to anonymous referees, foruseful comments on the subject of this paper. This work was partially supportedby National Science Foundation under grants IRI-9306751 and IRI-9732744.References[1] J.J. Alferes, J.A. Leite, L.M. Pereira, H. Przymusinska, and T.C. Przymusinski. Dynamiclogic programming. In Anthony Cohn, Lenhart Schubert, and Stuart Shapiro, editors,Principles of Knowledge Representation and Reasoning: Proc. Sixth Int'l Conf., pages 98{109, 1998.[2] Krzysztof Apt, Howard Blair, and Adrian Walker. Towards a theory of declarative knowl-edge. In Jack Minker, editor, Foundations of Deductive Databases and Logic Programming,pages 89{148. Morgan Kaufmann, San Mateo, CA, 1988.[3] Keith Clark. Negation as failure. In Herve Gallaire and Jack Minker, editors, Logic andData Bases, pages 293{322. Plenum Press, New York, 1978.

Page 25: Preprin t 0 (1999) ?{? 1hudson/papers/amai-nlp.pdf · 2007-07-18 · o ccurrence of p in (6) b y (q ; r) is a form ula, but result applying the same op eration to second o ccurrence

25[4] Yannis Dimopoulos, Bernhard Nebel, and Jana Koehler. Encoding planning problems innon-monotonic logic programs. In Proc. European Conference on Planning 1997, pages169{181, 1997.[5] Thomas Eiter, Nicola Leone, Cristinel Mateis, Gerald Pfeifer, and Francesco Scarcello. TheKR system dlv: Progress report, comparisons and benchmarks. In Anthony Cohn, LenhartSchubert, and Stuart Shapiro, editors, Proc. Sixth Int'l Conf. on Principles of KnowledgeRepresentation and Reasoning, pages 406{417, 1998.[6] Fran�cois Fages. Consistency of Clark's completion and existence of stable models. Journalof Methods of Logic in Computer Science, 1:51{60, 1994.[7] Michael Gelfond and Vladimir Lifschitz. Classical negation in logic programs and disjunc-tive databases. New Generation Computing, 9:365{385, 1991.[8] Heinrich Herre and Gerd Wagner. Stable models are generated by a stable chain. Journalof Logic Programming, 30:165{177, 1997.[9] C.A.R. Hoare. Programs are predicates. In Proc. Int'l Conf. on Fifth Generation ComputerSystems, pages 211{218, 1992.[10] Katsumi Inoue and Chiaki Sakama. On positive occurrences of negation as failure. InProc. Fourth Int'l Conf. on Principles of Knowledge Representation and Reasoning, pages293{304, 1994.[11] Katsumi Inoue and Chiaki Sakama. Negation as failure in the head. Journal of LogicProgramming, 35:39{78, 1998.[12] Vladimir Lifschitz. Minimal belief and negation as failure. Arti�cial Intelligence, 70:53{72,1994.[13] Vladimir Lifschitz. Foundations of logic programming. In Gerhard Brewka, editor, Princi-ples of Knowledge Representation, pages 69{128. CSLI Publications, 1996.[14] Vladimir Lifschitz. Action languages, answer sets and planning. In The Logic ProgrammingParadigm: a 25-Year Perspective. Springer Verlag, 1999. To appear.[15] Vladimir Lifschitz and Thomas Woo. Answer sets in general nonmonotonic reasoning(preliminary report). In Bernhard Nebel, Charles Rich, and William Swartout, editors,Proc. Third Int'l Conf. on Principles of Knowledge Representation and Reasoning, pages603{614, 1992.[16] Fangzhen Lin and Yoav Shoham. A logic of knowledge and justi�ed assumptions. Arti�cialIntelligence, 57:271{289, 1992.[17] John Lloyd and Rodney Topor. Making Prolog more expressive. Journal of Logic Program-ming, 3:225{240, 1984.[18] Victor Marek and Miros law Truszczy�nski. Stable models and an alternative logic program-ming paradigm. In The Logic Programming Paradigm: a 25-Year Perspective. SpringerVerlag, 1999. To appear.[19] Ilkka Niemel�a and Patrik Simons. E�cient implementation of the well-founded and stablemodel semantics. In Proc. Joint Int'l Conf. and Symp. on Logic Programming, pages 289{303, 1996.[20] David Pearce. A new logical characterization of stable models and answer sets. In J�urgenDix, Luis Pereira, and Teodor Przymusinski, editors, Non-Monotonic Extensions of Logic

Page 26: Preprin t 0 (1999) ?{? 1hudson/papers/amai-nlp.pdf · 2007-07-18 · o ccurrence of p in (6) b y (q ; r) is a form ula, but result applying the same op eration to second o ccurrence

26 Programming (Lecture Notes in Arti�cial Intelligence 1216), pages 57{70. Springer-Verlag,1997.[21] V.S. Subrahmanian and Carlo Zaniolo. Relating stable models and AI planning domains.In Proc. ICLP-95, 1995.