<<

Proceedings of the Twenty-Fifth International Joint Conference on (IJCAI-16)

Eliminating Disjunctions in by Restricted Unfolding 1 2 3 3 2 2 Jianmin Ji , Hai Wan ⇤, Kewen Wang , Zhe Wang , Chuhan Zhang , and Jiangtao Xu 1School of Computer Science and Technology, University of Science and Technology of China, Hefei, China [email protected] 2School of Data and Computer Science, Sun Yat-sen University, Guangzhou, China [email protected] 3School of Information and Communication Technology, Griffith University, Griffith, Australia k.wang,zhe.wang @griffith.edu.au { } Abstract such a disjunctive program can be efficiently rewritten to an equivalent normal program under the answer set semantics. A disjunctive program under the answer set Ben-Eliyahu and Dechter [1994] identified a class of dis- semantics can be equivalently translated to a nor- junctive programs, called “Head-Cycle-Free” (HCF), and mal logic program by the shifting transformation, showed that each HCF program can be converted into an if the program is head-cycle-free. In this paper, equivalent normal program in polynomial time by shifting we provide an answer-set-preserving rewriting of head atoms into the body. The class of HCF programs is fur- a general disjunctive program to a normal program ther generalised to that of Head-Elementary-loop-Free (HEF) by first applying the unfolding transformation on programs [Gebser et al., 2011], which can be transformed atoms that prevent the program from being head- into normal programs in polynomial time by shifting too. One cycle-free, then shifting the resulting program. Dif- could identify another proper super class of HEF programs ferent from other transformations that eliminate that are polynomial time convertible to normal programs but disjunctions in answer set programming, the new it would be getting harder to check if a given disjunctive pro- rewriting is efficient for “almost” head-cycle-free gram is in such a class [Ji et al., 2015]. programs, i.e., programs that have only a few atoms On the other hand, it is well known that a disjunctive pro- that prevent them to be head-cycle-free. Based on gram can be equivalently transformed into a negative dis- the new rewriting, we provide an anytime algo- junctive program by a set of program transformations in- rithm to compute answer sets of a disjunctive pro- cluding the unfolding transformation [Brass and Dix, 1997; gram by calling solvers for normal logic programs. Eiter and Wang, 2008]. Since shifting preserves the answer The experiment shows that the is efficient set semantics for negative disjunctive programs, each disjunc- for some disjunctive programs. We also extend the tive program can be equivalently transformed into a normal rewriting to non-ground answer set programs on fi- program [Zhou, 2014]. Given that the unfolding transforma- nite structures. tion is exponential in the worst case, an exponential blow- up may occur in the unfolding-based rewriting. One source for this blow-up is from that unfolding can be applied on 1 Introduction all atoms in the given disjunctive program. However, it has Disjunctive logic programs extend normal logic programs by not been explored how the efficiency of unfolding can be im- permitting disjunctions to appear in rule heads, which in- proved in the context of disjunctive answer set programming. creases the expressive power of logic programs under the an- Especially, it is unclear if the unfolding transformation can be swer set semantics [Baral, 2003] and brings computational applied on only some atoms that are necessary. penalty as well. In particular, deciding whether a disjunctive A natural idea is to apply unfolding on atoms of the pro- P program has an answer set is ⌃2 -complete [Eiter and Got- gram one by one until the resulting program is HCF. However, tlob, 1995] while deciding whether a normal program has unfolding may introduce new head-cycles and increase the an answer set is NP-complete. In practice, significant per- set of atoms to be unfolded. Hence, generally speaking, one formance difference can be observed after adding disjunctive may need to unfold at all the atoms to achieve an HCF pro- rules into normal programs, even if only a very small number gram, which indeed results in a negative program as in [Zhou, of disjunctive rules are involved. Meanwhile, it is arguable 2014]. In this paper, we show that we can restrict unfolding that many real-life problems can be characterized by pro- to “culprit” atoms, i.e., atoms that prevent the initial program grams consisting of a large number of normal rules and a few to be HCF, and ignore new atoms that prevent the resulting disjunctive rules. Hence, an interesting question is whether program to be HCF. We prove that the result of our restricted unfolding, although not necessarily HCF, can be equivalently ⇤Corresponding author transformed to a normal program via shifting.

1130 This result is of both theoretical and practical interests—it A set S of atoms satisfies a rule r if S p p/S = not only shows that the complexity penalty is closely tied to tr(r) in the sense of propositional logic.[S{¬satisfies| 2 a}| pro- these “culprit” atoms, but also suggests the practicality of our gram ⇧ if S satisfies every rule in ⇧. rewriting approach on disjunctive programs that are “almost” The answer sets of a DLP are defined in [Gelfond and HCF, i.e., with only a small number of “culprit” atoms. We Lifschitz, 1991]. Given a DLP ⇧ and a set S of atoms, the make the following contributions: Gelfond-Lifschitz reduct of ⇧ on S, written ⇧S, is obtained We provide an answer-set-preserving rewriting from a from ⇧ by deleting: • disjunctive program to a normal program by only un- 1. each rule that has a formula not p in its body with p S, 2 folding at “culprit” atoms and shifting the resulting pro- 2. all formulas of the form not p in the bodies of the re- gram, which is efficient for “almost” HCF programs. maining rules. If ⇧0 is a normal program rewritten from a disjunctive • A set S of atoms is an answer set of ⇧ if S is a minimal set program ⇧ by restricted unfolding and shifting, we show satisfying ⇧S. We use AS (⇧) to denote the set of answer sets that the computation of answer sets for ⇧0 can be im- of ⇧. proved. In particular, although the rewriting may intro- duce new loops to ⇧0, we only need to consider loops 2.2 Loops and Loop Formulas constructed from loops of ⇧ for computing answer sets Lee and Lifschitz [2003] extended the notions of loops and of ⇧0. This result suggests that although our rewriting loop formulas [Lin and Zhao, 2004] to DLPs. For a DLP ⇧, to a normal logic program may lead to an exponential the positive dependency graph of ⇧, written G⇧, is the di- blow-up, there is not necessarily a blow-up in loop for- rected graph whose vertices are atoms in ⇧, and there is an mulas. arc from p to q if there is a rule r ⇧ such that p head(r) As another application of the rewriting, we present an and q body+(r). A set L of atoms2 is a loop of2 ⇧ if the • 2 anytime algorithm to compute answer sets of a disjunc- L-induced subgraph of G⇧ is strongly connected. Note that, tive program ⇧ by calling solvers for normal logic pro- every singleton whose atom occurs in ⇧ is also a loop of ⇧. grams. In each iteration, the algorithm outputs the an- We use Loop(⇧) to denote the set of loops of ⇧. swer sets of the shifted program ⇧0 obtained from ⇧ by Given a DLP ⇧ and a loop L of ⇧, a rule r ⇧ is an unfolding at a set A of atoms. The algorithm will output external support of L under ⇧ if head(r) L 2= and + \ 6 ; more answer sets of ⇧ when a larger A is applied. L body (r)= . Let R(L, ⇧) be the set of external sup- \ L ; ⇧ (conjunctive) loop formula L At last, we extend the rewriting to non-ground answer port rules of under . The of ⇧ LF (L, ⇧) • set programs on finite structures. As a result, we are able under , written , is the following implication: to compute answer sets of some first-order disjunctive logic programs by a solver for first-order normal pro- p body(r) q . grams such as [Asuncion et al., 2012]. 0 ^ ¬ 1 p L r R (L,⇧) q head(r) L ^2 2 _ 2 ^ \ @ A 2 Preliminaries Theorem 1 (Theorem 1 in [Lee and Lifschitz, 2003]) For a DLP ⇧ and a set S of atoms, S is an an- 2.1 Disjunctive Logic Programs swer set of ⇧ iff S p p/S is a model of [{¬ | 2 } We consider fully finite logic programs based on a proposi- tr(⇧) L Loop(⇧) LF (L, ⇧). tional language until Section 7. A (disjunctive) logic pro- ^ 2 gram (DLP) is aL finite set of (disjunctive) rules of the form 2.3 UnfoldingV and Shifting [ a a a ,...,a , not a ,...,not a . (1) We first review the unfolding transformation Gergatsoulis, 1 _···_ k k+1 m m+1 n 1997; Brass and Dix, 1997]. where n m k 1 and a1,...,an are atoms. If k =1, it Definition 1 (Elementary unfolding) Let r1, r2 be two is a normal rule; if k = m, it is a negative rule; if m = n, it is + rules and there is an atom a head(r1) body (r2). a positive rule.Anormal logic program (NLP) is a finite set 2 \ The rule obtained by elementary unfolding r2 using r1 at of normal rules and a negative logic program (resp. positive a, denoted by unfold(r1,r2,a), is the rule r such that logic program) is a finite set of negative (resp. positive) rules. head(r)=(head(r1) a ) head(r2) and body(r)= We will also write a rule r of form (1) as body(r ) (body(r ) \{a )}. [ 1 [ 2 \{ } head(r) body(r). Definition 2 (Unfolding rules at an atom) Let ⇧ be a DLP

+ and a an atom in ⇧. The set of rules obtained by unfold- where head(r) is a1 ak, body(r)=body (r) + _···_ ^ ing rules at a in ⇧, denoted by unfold⇧(a), is the set body(r), body (r) is ak+1 am, and body(r) ^···^ + unfold(r1,r2,a) r1,r2 ⇧ and a head(r1) is am+1 an, and we identify head(r), body (r), { + | 2 2 \ ¬ ^···^¬ body (r2) . body(r) with their corresponding sets of atoms, and body(r) } the set a ,...,a , a ,..., a . Given a DLP ⇧, Let ⇧ be a DLP and a Atoms(⇧). We denote { k+1 m ¬ m+1 ¬ n } 2 we use Atoms(⇧) to denote the set of atoms occurring in ⇧. + We use tr(r) to denote the propositional formula body(r) remove(⇧,a)=⇧ r r ⇧ and a body (r) \{ | 2 2 } head(r) and tr(⇧) = r ⇧ tr(r). unfold⇧(a). 2 [ V

1131 Example 1 Consider the logic program ⇧1: Lemma 1 Let ⇧ be a DLP and E Atoms(⇧). Then ✓ a b c. d b. e a, d. c e. c . LF ( a , ⇧) (tr(⇧) tr(remove(⇧,E))) . _ { } ⌘ a b. b a. a E ^2 unfold ⇧1 (a) is the set of rules: Lemma 2 Let ⇧ be a DLP, E Atoms(⇧), and ✓ b e c, d. e b, d. b c. b b. L Loop(remove(⇧,E)). If L HC (⇧) = then _ LF (2L, remove(⇧,E)) LF (L, sh(\remove(⇧,E))); . remove(⇧1,a)=⇧1 e a, d. b a. unfold⇧1 (a). ⌘ \{ }[ As discussed in Introduction, unfolding may introduce new From Theorem 13 in [Gergatsoulis, 1997], we have the fol- head-cycles and hence increase the set of atoms in HC . lowing theorem. Example 1 (Continued) b, c, e is not a loop of ⇧1, Theorem 2 Let ⇧ be a DLP and a an atom in ⇧. Then { } AS (⇧) = AS (remove(⇧,a)). while it is a loop of the program remove(⇧1, a ), then HC (remove(⇧ , a )) = b, e while HC (⇧ )={ }a, b . Given a DLP ⇧, E Atoms(⇧), and a E, we can 1 { } { } 1 { } inductively define remove✓ (⇧,E) as follows: 2 For some DLP ⇧ and E Atoms(⇧), exponen- tially many loops can be introduced✓ by unfolding and remove(⇧, a )=remove(⇧,a), • { } HC (remove(⇧,E)) can be greatly larger than HC (⇧). remove(⇧,E)= Consider the logic program ⇧ : • remove(remove(⇧,E a ), a ). Example 2 2 \{ } { } a b c. e a, d. a b. b a. Corollary 3 Let ⇧ be a DLP and E Atoms(⇧). Then _ AS (⇧) = AS (remove(⇧,E)). ✓ a a b. d a . (1 i n) 1 _···_ n i   Gelfond et al. [1991] provided a mapping from a DLP to where n 1. Note that Loop(⇧2)= p Atoms(⇧ ) p an NLP by “shifting” head atoms into the bodies. We denote 2 2 {{ }}[ a, b , HC (⇧2)= a, b . remove(⇧2,a)=(⇧2 e sh(⇧) to be the NLP obtained from a DLP ⇧ by substituting a,{{ d. b}} a. ) b{ e} c, d. bS c. e \{b, d. . every rule of form (1) with the k rules For any nonempty} [{ set_S a ,...,a , S b, d is} a ✓{1 n} [{ } a not a ,...,not a , not a ,...,not a , loop of remove(⇧2,a). Then Loop(remove(⇧2,a)) = i 1 i 1 i+1 k n | | 4+n+2 , Loop(⇧2) =6+n, and HC (remove(⇧2,a)) = ak+1,...,am, not am+1,...,not an. (1 i k) | |   b, d, a1,...,an . It is known that every answer set of sh(⇧) is also an an- { } Lemma 3 Let ⇧ be a DLP and E Atoms(⇧). Then for ⇧ swer set of , but the converse is not true in general. Ben- each L Loop(remove(⇧,E)), either✓ L E = or L = [ ] Eliyahu and Dechter 1994 identified a class of DLP, called a for2 some a E. \ ; “Head-Cycle-Free” (HCF), and showed that the converse is { } 2 true if ⇧ is an HCF program. In particular, a DLP ⇧ is called From Theorem 1 and above lemmas, we get our main result. HCF, if head(r) L 1 for every rule r of ⇧ and every Theorem 4 For any DLP ⇧, loop L of| ⇧, and the\ answer| sets of an HCF program ⇧ coin- cide with the answer sets of the NLP sh(⇧). AS (⇧) = AS (sh(remove(⇧,HC(⇧)))). Given a DLP ⇧, remove(⇧, Atoms(⇧)) is equivalent Then we can equivalently rewrite a DLP ⇧ to the NLP to a negative program [Brass and Dix, 1997], which is sh(remove(⇧,HC(⇧))). HCF. Then AS (⇧) = AS (remove(⇧, Atoms(⇧))) = Now we discuss some optimizations for the new rewriting. AS (sh(remove(⇧, Atoms(⇧)))). Based on this result, Given a DLP ⇧ with n different atoms and m different Zhou [2014] provided a syntactic transformation from a DLP rules, (the number of rules) remove(⇧,a) for an atom a is to an NLP by first applying the unfolding transformation on m+m2 in the worst case, remove| (⇧,HC(|⇧)) is O(m2n), all the atoms, then shifting the resulting program to the NLP. and sh(remove(⇧,HC(|⇧))) is O(n m2n)|. As proved in [Eiter| et al., 2004], any answer-set-preserving| · rewriting 3 Eliminating Disjunctions by Restricted of a DLP to an NLP must lead in general to an exponential Unfolding blow-up, providing the polynomial hierarchy does not col- lapse. However, when ⇧ is “almost” HCF, the rewriting could In this section, we show that a disjunctive program can be be efficient. In particular, if HC (⇧) = k for a constant k, equivalently translated to a normal program by first apply- then sh(remove(⇧,HC(⇧|))) is O|(n m2k), which is poly- ing the unfolding transformation only on “culprit” atoms, i.e., nomial| for the size of ⇧, i.e., n and| m. · atoms that prevent the program from being HCF. We can further reduce the number of unfolded atoms by For a DLP ⇧, we denote considering only special loops. HC (⇧) = a there exist r ⇧ and L Loop(⇧) Firstly, HC (⇧) can be replaced by one of its subsets in the { | 2 2 such that head(r) L > 1 and a head(r) L . rewriting. For a DLP ⇧, we denote | \ | 2 \ } Intuitively, HC (⇧) specifies the set of atoms that prevent ⇧ HC ⇤(⇧) = a there exist r ⇧ and L Loop(⇧) to be HCF. { | 2 2 such that head(r) L > 1, r R(L, ⇧), Now we provide the lemmas that draw a sketch of the proof | \ | 2 and a head(r) L . for our main result. 2 \ }

1132 Clearly, HC ⇤(⇧) HC (⇧). From Theorem 1, if HC ⇤(⇧) = Lemma 4 Let ⇧ be a DLP and a an atom in ⇧. Then the , then AS (⇧) = ✓AS (sh(⇧)), even when ⇧ is not HCF. So following statements hold: ; the class of HCF programs can be extended to HCF⇤ pro- L L Loop(⇧),a/L Loop(remove(⇧,a)). grams with HC ⇤(⇧) = , for which shifting is answer-set- •{ | 2 2 }✓ ; L a L Loop(⇧) Loop(remove(⇧,a)). preserving. We have the following corollary of Theorem 4. •{ \{ }| 2 }\;✓ For any set L Atoms(⇧), if a L then LF (L, ⇧) Corollary 5 For any DLP ⇧, • LF (L, remove✓(⇧,a)). 2 ⌘ AS (⇧) = AS (sh(remove(⇧,HC⇤(⇧)))). For any set L Atoms(⇧), if a/L then • ✓ 2 Secondly, based on the notions of elementary loops and – tr(⇧) (LF (L, remove(⇧,a)) LF (L, ⇧)), proper loops, HC ⇤(⇧) can be further reduced to some of its and subsets in the rewriting. – (LF (L a , ⇧) LF (L, ⇧)) Gebser et al. [2011] showed that not all loops are neces- LF (L, remove[{ } (⇧^,a)). sary for identifying the answer sets among the models of a Given a DLP ⇧ and E Atoms(⇧), we denote DLP. They introduced the subclass elementary loops of loops, ✓ and refined Theorem 1 by considering elementary loops only. Loop⇤(⇧,E)= a L L E = and there Later, Ji et al. [2015] introduced the subclass proper loops {{ }}[{ | \ ; a E of elementary loops and refined Theorem 1 by considering a [2 exists S E such that L S Loop(⇧) . special form of loop formulas for proper loops only. As recog- ✓ [ 2 } nizing elementary loops and proper loops for DLPs are coNP- From Lemma 4, Loop⇤(⇧,E) Loop(remove(⇧,E)). et al. [ ] weak elementary loops ✓ complete, Ji 2015 introduced remove(⇧,E) may have loops that are not in Loop⇤(⇧,E). and weak proper loops which can be identified in polynomial For some DLPs, the size of Loop(remove(⇧,E)) can be time. exponentially larger than the size of Loop⇤(⇧,E). Based on these notions, we can further refine HC ⇤(⇧) in Example 2 (Continued) Loop⇤(⇧2, a )=Loop(⇧2) the rewriting. For a DLP ⇧, we denote { } \ a, b and Loop(remove(⇧2,a)) Loop⇤(⇧2, a ) = {{n }} | \ { } | HEL(⇧) = a there exist r ⇧ and an elementary 2 1. { | 2 loop L of ⇧ such that head(r) L > 1, The following theorem shows that, we only need to con- | \ | sider loops in Loop⇤(⇧,E) for identifying answer sets r R(L, ⇧), and a head(r) L . 2 2 \ } among the models of tr(remove(⇧,E)). HPL(⇧), HWEL(⇧), and HWPL(⇧) denote the sets spec- Theorem 7 Let ⇧ be a DLP and E Atoms(⇧). Then S ified by the definition of HEL(⇧) by replacing “elemen- AS (remove(⇧,E)) iff S p p/✓ S is a model of 2 tary loop” with “proper loop”, “weak elementary loop”, and [{¬ | 2 } tr(⇧) LF (L, remove(⇧,E)). “weak proper loop”, respectively. Then we have the following ^ L Loop (⇧,E) corollary of Theorem 4. 2 ^⇤ Corollary 6 For any DLP ⇧, Recalling Theorem 1, we can improve the computation of answer sets for remove(⇧,E) on SAT-based answer set AS (⇧) = AS (sh(remove(⇧,HEL(⇧)))) programming solvers by only considering loop formulas for = AS (sh(remove(⇧,HPL(⇧)))) loops in a subset of Loop(remove(⇧,E)). = AS (sh(remove(⇧,HWEL(⇧)))) Corollary 8 Let ⇧ be a DLP and E Atoms(⇧). Then S ✓ 2 = AS (sh(remove(⇧,HWPL(⇧)))). AS (sh(remove(⇧,E))) iff S p p/S is a model of [{¬ | 2 } tr(⇧) LF (L, sh(remove(⇧,E))). 4 Reducing Loop Formulas for Computing ^ L Loop⇤(⇧,E) Answer Sets of Rewritten Programs 2 ^ Theorem 7 and Corollary 8 show that although our trans- From Theorem 1, answer sets can be identified from mod- formation to NLP may result in an exponential blow-up, there els of the program that satisfy loop formulas of all loops. In is not necessarily a blow-up in loop formulas for the compu- this section, we show that we only need to consider a sub- tation. In particular, Loop⇤(⇧,E) Loop(⇧) for any set set of loops of an unfolded program, i.e., remove(⇧,E) E Atoms(⇧), then| the number| of| loops that| need to be for a DLP ⇧ and E Atoms(⇧), for obtaining answer ✓ ✓ considered for computing answer sets of remove(⇧,E) or sets. This result could be beneficial for SAT-based answer sh(remove(⇧,E)) is not larger than that of ⇧. set programming solvers, such as ASSAT [Lin and Zhao, 2004], cmodels [Giunchiglia et al., 2006], and clasp [Gebser 5 Approximating a DLP by Restricted et al., 2007], for computing answer sets of remove(⇧,E) and sh(remove(⇧,E)). Unfolding We first provide a lemma to specify relations of loops and In this section, we consider another application of the new loop formulas between a DLP ⇧ and the unfolded program rewriting for approximating a DLP ⇧ by an NLP. First, we remove(⇧,a) for an atom a. specify the notion of approximation.

1133 Definition 3 (Sound Approximation) A DLP ⇧⇤ is a We can apply the approaches discussed in previous sec- (sound) approximation of a DLP ⇧, if AS (⇧⇤) AS (⇧). tions to optimize Algorithm 1 as well. In particular, we can ✓ HC (⇧) HC (⇧) HWEL(⇧) The intuition behind the definition is that, when it is hard to replace by ⇤ or in the algorithm. compute answer sets of a DLP ⇧, we would like to construct We can also use the approach proposed in Section 4 to im- prove the computation of answer sets for sh(⇧). an approximation ⇧⇤ of ⇧ so that ⇧⇤ can compute some an- swer sets of ⇧ easier. The approximation is sound in the sense Algorithm 1 provides an approach to compute an answer [ ] that every computed answer set is an answer set of ⇧. set of a DLP by calling NLP solvers. Janhunen et al. 2006 also provided such an approach. In their approach, a DLP ⇧ is Definition 4 (Closed Sequence of Sound Approximations) A se- first rewritten to an NLP Gen(⇧) to produce candidate mod- quence of DLPs ⇧1,...,⇧n is a closed sequence of (sound) h i els S, then another NLP Test(⇧,S) is constructed to check approximations of a DLP ⇧, if AS (⇧i) AS (⇧i+1) for each ✓ whether S is an answer set of ⇧. The rewriting proposed 1 i n 1, and AS (⇧n)=AS (⇧).   in [Janhunen et al., 2006] is different from our rewriting in the Intuitively, given a closed sequence of sound approxima- sense that AS (⇧) AS (Gen(⇧)), i.e., Gen(⇧) is not a sound tions of a DLP ⇧, we can construct an anytime algorithm by approximation of ✓⇧, while we provide a closed sequence of computing answer sets of ⇧i’s one by one, which is expected sound approximations. to find better solutions the more time it keeps running. Even- tually, the algorithm would return all answer sets of ⇧. 6 Some Experiments In the following, we specify a closed sequence of sound 1 P approximations of a DLP by restricted unfolding and shifting. We have implemented a program for rewriting a DLP to an NLP P n, where P n is a simplified program from Lemma 5 For any DLP ⇧ and a Atoms(⇧), sh(remove(P, HC(P ))) by removing redundancies like 2 AS (remove(sh(⇧),a)) AS (sh(remove(⇧,a))). rules r with head(r) body+(r) = or body+(r) ✓ body (r) = . By Theorem\ 4, AS (P6 )=; AS (P n). If the\ Theorem 9 Let ⇧ be a DLP and E1 E2 HC (⇧). Then ✓ ✓ size of the NLP6 ; P n is similar to the size of the DLP P , it will AS (sh(⇧)) AS (sh(remove(⇧,E ))) be more efficient to compute answer sets of P n using NLP ✓ 1 AS (sh(remove(⇧,E ))) AS (⇧). solvers than to compute answer sets of P using DLP solvers. ✓ 2 ✓ To corroborate this observation, we tested our program on From Theorem 9, we can construct a closed sequence of some benchmarks constructed from Niemela’s¨ [1999] encod- sound approximations of a DLP. ing H of the Hamiltonian Circuit (HC) problem. Specifically, we constructed programs of the form Q = Q0 H G where Corollary 10 Let ⇧ be a DLP, HC (⇧) = a1,...,an . [ [ Then { } H is Niemela’s¨ encoding for the HC problem, G is the en- coding of the graph for a given HC instance, and the program sh(⇧), sh(remove(⇧, a )), Q0 is given as the following: h { 1} sh(remove(⇧, a1,a2 )),..., a b reached(1).ab. b a. { } _ sh(remove(⇧, a ,...,a )) { 1 n} i where reached(1) is an atom in H and a, b are new atoms not is a closed sequence of sound approximations of ⇧. appearing in H. Our program will rewrite such a disjunctive program Q into Example 1 (Continued) AS (sh(⇧1)) = and AS (⇧1)= n n ; a normal program Q = Q0 H G. It can be seen that AS (remove(⇧1,a)) = AS (sh(remove(⇧1,a))) = Qn = sh(remove(Q, HC(Q)))[ . Here[ Qn is the program: a, b, c, d, e . 0 {{ }} b reached(1), not a. a reached(1), not b. Now we provide an anytime algorithm (Algorithm 1) to a reached(1).breached(1). compute answer sets of a DLP by using NLP solvers. In Table 1, we compare the running times of computing an n 2 Algorithm 1: Computing answer sets of a DLP ⇧ answer set of Q and Q using solvers clasp and cmodels . In the table, rand m k(t) stands for a class of randomly gener- 1 H := HC (⇧); ated t graphs with m vertexes and k arcs. The numbers under 2 as := AS (sh(⇧)); “Q” refer to the average running times for computing an an- 3 output as; // current computed answer sets of ⇧ swer set of corresponding programs Q, using corresponding DLP solvers, i.e., clasp3 (version 3.1.4) and cmodels4 (ver- 4 for each a H do 2 Qn 5 ⇧:=remove(⇧,a); sion 3.8.5), and those under “ ” refer to the average running 6 as := AS (sh(⇧)); 1Our implementation is available on the web 7 output as; http://ss.sysu.edu.cn/%7ewh/dlp2nlp.html. 2Our experiments were done on an Intel(R) Core(TM) i7-2600 8 return as; 3.40GHz CPU and 32GB RAM. The reported times are in CPU sec- onds as reported by Linux “/usr/bin/time” command. 3The modern versions of clasp have built-in support for DLPs. Theorem 11 For any DLP ⇧, Algorithm 1 outputs a subset http://www.cs.uni-potsdam.de/clasp/ of AS (⇧) at each step and returns AS (⇧) at last. 4http://www.cs.utexas.edu/users/tag/cmodels/

1134 times for computing an answer set of corresponding programs of ⇧ if the subgraph of G⇧ induced by L is strongly con- Qn, using corresponding NLP solvers, i.e., clasp and cmod- nected. Specially, for each atom a V , a is a loop of ⇧. els. As can be seen, for these programs, computing an answer We use Loop(⇧) to denote the set of2 loops{ of} ⇧. set of Qn by NLP solvers is more efficient. Given a loop L of a DLP ⇧ in normal form, we first rename variables in ⇧ so that no variables of ⇧ occur in L. Then the Table 1: Comparing Q and Qn (first-order) external support formula of L for ⇧, denoted by ES(L, ⇧), is the following disjunction Q Qn Graphs clasp cmodels clasp cmodels rand 200 1800(5) 1.47 4.25 1.14 3.12 ~y body(r)✓ rand 250 2200(5) 43.91 1080.47(3) 6.67 508.17(1) 9 ^ rand 300 2700(5) 616.76 1081.37(3) 332.80 1080.77(3) ✓,r: r ⇧, head(r)✓2 L= rand 350 3000(5) 1102.61(3) 1800(5) 1080.56(3) 1800(5) _\ 6 ; * When a solver could not compute an answer set of a program in 1800 seconds, ~ (~t = t0) we count the running time as 1800 seconds. We also report the number of such 6 programs in the parentheses. P (~t) body+(r)✓,P(t~ ) L 2 ^ 0 2

We also tested some benchmarks that were frequently used P (~t) (~t = ~t ) . ^¬ ^ 6 0 to evaluate performance of DLP solvers [Denecker et al., ~ ~ ! ⇣ P (t) head(r)✓ P (t0) L ⌘ 2009; Gebser et al., 2013]. However, for most non-HCF 2_ ^2 DLPs P in these benchmarks, the size of P n is much larger The (first-order) loop formula of L in ⇧, denoted by than the size of P and as a result, our method failed to show LF (L, ⇧), is the universal closure of a ES(L, ⇧). a L advantage over direct use of DLP solvers. We use LF (⇧) to denote the set of all loop2 formulas in ⇧. V Theorem 12 (Proposition 4 in [Lee and Meng, 2008]) Let 7 Eliminating Disjunctions for First-order ⇧ be a DLP and a finite structure. is an answer set of ⇧ if and only if Mis a model of tr(⇧M) LF (⇧). Programs on Finite Structures M { }[ Given a first-order DLP ⇧, the shifting result sh(⇧) is de- In this section, we extend the new rewriting to non-ground fined in the same way as in the propositional case. Every an- programs with first-order answer set semantics on finite struc- swer set of sh(⇧) is also an answer set of ⇧, but the converse tures. We first review some basic notions. is not true in general. Similarly, a first-order DLP ⇧ is called In the following, we consider the first-order disjunctive “Head-Cycle-Free” (HCF), if there is no loop L, rule r in ⇧, [ ] logic programs Ferraris et al., 2011 , with similar syntactic and substitution ✓ such that L head(r)✓ > 1. forms as DLP programs. A distinction is made between pred- Based on the progression| semantics\ of answer| sets [Zhou icates occurring only in rule bodies and the reminder pred- and Zhang, 2011], Zhou [2015] provided the following P ⇧ icates. A predicate in a first-order DLP is intensional proposition. (or IDB) if P occurs in head(r) for some r ⇧, and ex- 2 tensional (or EDB) otherwise. We use (⇧), IDB(⇧), and Proposition 1 Let P be an HCF first-order DLP. Then, (⇧) to denote sets of predicates, intensionalP P predicates, AS (sh(⇧)) = AS (⇧). PEDB extensional predicates occurring in ⇧ respectively. As with Definition 5 (Elementary unfolding in first-order case) [ ] Lee and Meng, 2008 , we assume w.l.o.g. that ⇧ is in nor- Given two rules r1 and r2 (with suitable variable renam- + mal form without object constants occurring in rule heads. ing), there are atoms a head(r1) and b body (r2) We use first-order (ground) substitution, unifier, most gen- such that a and b are unifiable2 with an mgu2 ✓. The rule eral unifier (mgu) defined in the standard way. In contrast to obtained by elementary unfolding r2 at b using r1 at grounded DLP, the answer sets of a first-order DLP is defined a, denoted by unfold(r1,r2,a,b), is the rule r such using first-order structures. In particular, a finite structure that head(r)=((head(r ) a ) head(r ))✓ and M 1 \{} [ 2 is a tuple (D, c1M,...,cmM,P1M,...,PnM), where D is a fi- body(r)=(body(r1) (body(r2) b ))✓. nite set called the domain of , cM A (the interpretation [ \{ } M i 2 Let ⇧ be a DLP, r a rule in ⇧, and b an atom in body+(r). of constant c )(1 i m), and P (the interpretation of a i jM We denote U (⇧,r,b) to be the set of rules constructed by k-ary predicate symbol P )(1 j n)ak-ary relation on set j the following procedure: D. We refer the readers to [Asuncion et al., 2012] for the def- S := (r0,a0) r0 ⇧, there is an atom a0 head(r0) inition of answer sets of first-order DLP on finite structures. 0 { | 2 2 such that a0 and b are unifiable ; The answer set semantics of a first-order DLP on finite } structures can be captured by first-order loop formulas [Chen i := 0; et al., 2006; Lee and Meng, 2008] as well. while Si = For a first-order DLP ⇧, the positive dependency graph of 6 ; S := ; ⇧, written G⇧, is the infinite graph (V,E), where V is the set i+1 ; of atoms constructed from (⇧), (a, b) E if there is a Ri+1 := ; PIDB 2 ; rule r ⇧ and a substitution ✓ such that P (~t)✓ = a for some for each (r0,a0) Si if a0 and b are unifiable 2 + 2 P (~t) head(r) and Q(~t )✓ = b for some Q(~t ) body (r). r00 := unfold(r0,r,a0,b); 2 0 0 2 A finite nonempty subset L of V is called a (first-order) loop R = R r00 ; i+1 i+1 [{ }

1135 ✓ := the mgu that a0 and b are unfiable with; Lemma 6 Let ⇧ be a DLP, A head(⇧), and ✓ S := S remove(⇧,A) exists. Then the following statements hold: i+1 i+1[ (r00,a⇤✓) (r0,a⇤) Si,a⇤ = a0 ; A finite structure M satisfies (⇧) and tr(⇧) if { | 2 6 } i := i +1; • and only if M satisfies (LFremove(⇧,A)) and LF tr(remove(⇧,A)), where (⇧) = LF ( a0 , ⇧) Uset(⇧,r,b):=R1 R2 Ri. LF { { } | [ [···[ a0 = a✓ for some a A and substitution ✓ . [Gergatsoulis, 1997] showed that the procedure would al- 2 } For each L Loop(remove(⇧,A)), if there ways terminate. We denote remove(⇧,r,b)=(⇧ r ) • does not exist2 a substitution ✓ such that L U (⇧,r,b). From Theorem 13 in [Gergatsoulis, 1997\{]}, we[ set HC (⇧)✓ = , then LF (L, remove(⇧,A)) \ have the following proposition. LF (L, sh(remove6 ; (⇧,A))). ⌘ Proposition 2 Let P be a DLP, r a rule in ⇧, and b an atom + for each L Loop(remove(⇧,A)), either there does in body (r). Then AS (⇧) = AS (remove(⇧,r,b)). • not exist a substitution2 ✓ with L A✓ = or L = a \ 6 ; { } Let ⇧ be a DLP and a an atom in head(r) for some r ⇧. for some a0 A and substitution with a0 = a. 2 2 We denote remove(⇧,a) to be a set of rules constructed by Theorem 15 Let ⇧ be a DLP and remove(⇧,HC(⇧)) ex- the following procedure: ists. Then AS (⇧) = AS (sh(remove(⇧,HC(⇧)))). R := ⇧; Asuncion et al. [2012] provided a solver of first-order NLPs while there is a rule r R and b body+(r) such that a by translating them to first-order sentences on finite struc- and b are unifiable 2 2 tures. From Theorem 15, we can use the solver to compute answer sets of some first-order DLPs. R := remove(R, r, b); remove(⇧,a):=R. 8 Conclusion Note that, by choosing different rules and corresponding In this paper, we provide a new answer-set-preserving rewrit- atoms in the procedure, remove(⇧,a) would return differ- ing of a DLP to an NLP by first apply the unfolding trans- ent programs. However, they are equivalent in the sense of formation on “culprit” atoms, i.e., atoms that prevent the pro- having the same sets of answer sets. gram from being HCF, then shift the resulting program. This The above procedure may not terminate for some DLPs result shows that the complexity penalty for extending NLPs due to the unfolding process. Zhou [2015] identified a class by including disjunctive rules is closely tied to these “culprit” of first-order DLPs called choice-bounded and showed that atoms. Hence, different from other transformations for elim- the process of applying the unfolding transformation when it inating disjunctions in literature, our rewriting is efficient for is possible would always terminate for choice-bounded DLPs. “almost” HCF programs, i.e., DLPs that have only a few “cul- Then for a choice-bounded DLP ⇧, the above procedure ter- prit” atoms. Later, we show that the computation of answer minates and remove(⇧,a) always exists. sets for a rewritten program can be improved by reducing the Theorem 13 Let ⇧ be a DLP, a an atom in head(r) for number of loops that need to be considered and the size of some r ⇧, and remove(⇧,a) exists. Then AS (⇧) = these loops is not larger than that of the original program. AS (remove2 (⇧,a)). This result shows that although our transformation to NLP may result in an exponential blow-up, there is not necessar- Given a DLP ⇧, we denote head(⇧) = a a ily a blow-up in loop formulas for the computation. Based on head(r) for some r ⇧ . Let ⇧ be a DLP and{ a set| A 2 2 } ✓ the new writing, we provide an anytime algorithm to com- head(⇧). We denote remove(⇧,A) to be a set of rules con- pute answer sets of a DLP by calling NLP solvers. At last, we structed by the following procedure: extend the rewriting to non-ground answer set programs on R := ⇧; finite structures. for each a A 2 9 Acknowledgments R := remove(R, a); We thank Xiaoping Chen and his research group for their use- remove(⇧,A):=R. ful discussions. Jianmin Ji’s research was partially supported Corollary 14 Let P be a DLP, A head(⇧), and by the National Natural Science Foundation of China under remove(⇧,A) exists. Then AS (⇧) = AS✓(remove(⇧,A)). grant 61175057, the National Natural Science Foundation for the Youth of China under grant 61403359, as well as the Now we extend our rewriting to first-order DLPs. USTC Key Direction Project and the USTC 985 Project. Hai For a DLP ⇧, we denote Wan’s research was in part supported by the National Natural Science Foundation of China under grant 61573386, Natu- HC (⇧) = a a head(⇧), there exists r ⇧, { | 2 2 ral Science Foundation of Guangdong Province under grant a loop L of ⇧, and a substitution ✓ such that 508257922126, Guangdong Province Science and Technol- L head(r)✓ > 1, a head(r) and a✓ L . ogy Plan projects under grant 509208496103, and Sun Yat- | \ | 2 2 } sen University Young Teachers Cultivation Project under We provide the following lemma to draw a sketch of the grant 16lgpy40. This work was also partially supported by proof for the main result. ARC under grant DP130102302.

1136 References [Gelfond and Lifschitz, 1991] Michael Gelfond and [Asuncion et al., 2012] Vernon Asuncion, Fangzhen Lin, Vladimir Lifschitz. Classical negation in logic pro- Yan Zhang, and Yi Zhou. Ordered completion for first- grams and disjunctive . New generation order logic programs on finite structures. Artificial Intelli- computing, 9(3-4):365–385, 1991. gence, 177:1–24, 2012. [Gelfond et al., 1991] Michael Gelfond, Vladimir Lifschitz, [Baral, 2003] C. Baral. Knowledge Representation, Reason- Halina Przymusinska, and Miroslaw Truszczynski. Dis- ing and Declarative . Cambridge Univer- junctive defaults. In Proceedings of the 2nd International sity Press, 2003. Conference on Principles of Knowledge Representation and Reasoning (KR-91), pages 230–237, 1991. [Ben-Eliyahu and Dechter, 1994] Rachel Ben-Eliyahu and Rina Dechter. Propositional semantics for disjunctive logic [Gergatsoulis, 1997] Manolis Gergatsoulis. Unfold/fold programs. Annals of Mathematics and Artificial intelli- transformations for disjunctive logic programs. Informa- gence, 12(1-2):53–87, 1994. tion processing letters, 62(1):23–29, 1997. [Brass and Dix, 1997] Stefan Brass and Jurgen¨ Dix. Char- [Giunchiglia et al., 2006] Enrico Giunchiglia, Yuliya Lierler, acterizations of the disjunctive stable semantics by par- and Marco Maratea. Answer set programming based on tial evaluation. The Journal of Logic Programming, propositional satisfiability. Journal of Automated Reason- 32(3):207–228, 1997. ing, 36(4):345–377, 2006. [Chen et al., 2006] Yin Chen, Fangzhen Lin, Yisong Wang, [Janhunen et al., 2006] Tomi Janhunen, Ilkka Niemela,¨ Diet- and Mingyi Zhang. First-order loop formulas for normal mar Seipel, Patrik Simons, and Jia-Huai You. Unfolding logic programs. In Proceedings of the 10th International partiality and disjunctions in . ACM Conference on Principles of Knowledge Representation Transactions on , 7(1):1–37, 2006. and Reasoning (KR-06), pages 298–307, 2006. [Ji et al., 2015] Jianmin Ji, Hai Wan, and Peng Xiao. On el- [Denecker et al., 2009] Marc Denecker, Joost Ven- ementary loops and proper loops for disjunctive logic pro- nekens, Stephen Bond, Martin Gebser, and Mirosław grams. In Proceedings of the 29th AAAI Conference on Truszczynski.´ The second answer set programming Artificial Intelligence (AAAI-15), pages 1518–1524, 2015. competition. In Proceedgins of the 10th International [Lee and Lifschitz, 2003] J. Lee and V. Lifschitz. Loop for- Converence on Logic Programming and Nonmonotonic mulas for disjunctive logic programs. In Proceedings of Reasoning (LPNMR-09), pages 637–654. Springer, 2009. the 19th International Conference on Logic Programming [Eiter and Gottlob, 1995] Thomas Eiter and Georg Gottlob. (ICLP-03), pages 451–465, 2003. On the computational cost of disjunctive logic program- [Lee and Meng, 2008] Joohyung Lee and Yunsong Meng. ming: Propositional case. Annals of Mathematics and Ar- On loop formulas with variables. In Proceedings of the tificial Intelligence, 15(3-4):289–323, 1995. 11th International Conference on Principles of Knowledge [Eiter and Wang, 2008] Thomas Eiter and Kewen Wang. Se- Representation and Reasoning (KR-08), pages 444–453, mantic forgetting in answer set programming. Artificial 2008. Intelligence, 172(14):1644–1672, 2008. [Lin and Zhao, 2004] F. Lin and Y. Zhao. ASSAT: comput- [Eiter et al., 2004] Thomas Eiter, Michael Fink, Hans Tom- ing answer sets of a logic program by SAT solvers. Artifi- pits, and Stefan Woltran. On eliminating disjunctions in cial Intelligence, 157(1-2):115–137, 2004. stable logic programming. In Principles of the 9th Interna- [Niemela,¨ 1999] I. Niemela.¨ Logic programs with sta- tional Conference on Knowledge Representation and Rea- ble model semantics as a soning (KR-04), pages 447–457, 2004. paradigm. Annals of Mathematics and Artificial Intelli- [Ferraris et al., 2011] Paolo Ferraris, Joohyung Lee, and gence, 25(3):241–273, 1999. Vladimir Lifschitz. Stable models and . [Zhou and Zhang, 2011] Yi Zhou and Yan Zhang. Progres- Artificial Intelligence, 175(1):236–263, 2011. sion semantics for disjunctive logic programs. In Proceed- [Gebser et al., 2007] M. Gebser, B. Kaufmann, A. Neumann, ings of the 25th AAAI Conference on Artificial Intelligence and T. Schaub. Conflict-driven answer set solving. In Pro- (AAAI-11), pages 286–291, 2011. ceedings of the 20th International Joint Conference on Ar- [Zhou, 2014] Yi Zhou. From disjunctive to normal logic tificial Intelligence (IJCAI-07), pages 386–392, 2007. programs via unfolding and shifting. In Proceedings of [Gebser et al., 2011] Martin Gebser, Joohyung Lee, and the 21st European Conference on Artificial Intelligence Yuliya Lierler. On elementary loops of logic programs. (ECAI-14), pages 1139–1140, 2014. Theory and Practice of Logic Programming, 11(06):953– [Zhou, 2015] Yi Zhou. First-order disjunctive logic pro- 988, 2011. gramming vs normal logic programming. In Proceedings [Gebser et al., 2013] Martin Gebser, Benjamin Kaufmann, of the 24th International Joint Conference on Artificial In- and Torsten Schaub. Advanced conflict-driven disjunctive telligence (IJCAI-15), pages 3292–3298, 2015. answer set solving. In Proceedings of the 23rd Interna- tional Joint Conference on Artificial Intelligence (IJCAI- 13), pages 912–918. AAAI Press, 2013.

1137