On Odd and Even Cycles in Normal Logic Programs

Similar documents
UNIFORM CONVERGENCE. Contents 1. Uniform Convergence 1 2. Properties of uniform convergence 3

The Regulated and Riemann Integrals

p-adic Egyptian Fractions

Recitation 3: More Applications of the Derivative

KNOWLEDGE-BASED AGENTS INFERENCE

Handout: Natural deduction for first order logic

N 0 completions on partial matrices

20 MATHEMATICS POLYNOMIALS

(e) if x = y + z and a divides any two of the integers x, y, or z, then a divides the remaining integer

A recursive construction of efficiently decodable list-disjunct matrices

Duality # Second iteration for HW problem. Recall our LP example problem we have been working on, in equality form, is given below.

W. We shall do so one by one, starting with I 1, and we shall do it greedily, trying

State space systems analysis (continued) Stability. A. Definitions A system is said to be Asymptotically Stable (AS) when it satisfies

Farey Fractions. Rickard Fernström. U.U.D.M. Project Report 2017:24. Department of Mathematics Uppsala University

MAA 4212 Improper Integrals

CS5371 Theory of Computation. Lecture 20: Complexity V (Polynomial-Time Reducibility)

Math Lecture 23

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

CSCI FOUNDATIONS OF COMPUTER SCIENCE

Properties of Integrals, Indefinite Integrals. Goals: Definition of the Definite Integral Integral Calculations using Antiderivatives

Coalgebra, Lecture 15: Equations for Deterministic Automata

First Midterm Examination

Bases for Vector Spaces

Riemann Sums and Riemann Integrals

Reasoning with Bayesian Networks

Theoretical foundations of Gaussian quadrature

Riemann Sums and Riemann Integrals

Advanced Calculus: MATH 410 Notes on Integrals and Integrability Professor David Levermore 17 October 2004

Lecture 1. Functional series. Pointwise and uniform convergence.

CS 275 Automata and Formal Language Theory

Binding Numbers for all Fractional (a, b, k)-critical Graphs

Polynomial Approximations for the Natural Logarithm and Arctangent Functions. Math 230

Continuous Random Variables

5.7 Improper Integrals

Unit #9 : Definite Integral Properties; Fundamental Theorem of Calculus

Decomposition of terms in Lucas sequences

Math 4310 Solutions to homework 1 Due 9/1/16

Chapter 5 : Continuous Random Variables

Linearly Similar Polynomials

MIXED MODELS (Sections ) I) In the unrestricted model, interactions are treated as in the random effects model:

Lecture 3. Limits of Functions and Continuity

Intuitionistic Fuzzy Lattices and Intuitionistic Fuzzy Boolean Algebras

Riemann is the Mann! (But Lebesgue may besgue to differ.)

Quadratic Forms. Quadratic Forms

Convert the NFA into DFA

New data structures to reduce data size and search time

Notes on length and conformal metrics

New Expansion and Infinite Series

DISCRETE MATHEMATICS HOMEWORK 3 SOLUTIONS

1 The Lagrange interpolation formula

First Midterm Examination

Part 5 out of 5. Automata & languages. A primer on the Theory of Computation. Last week was all about. a superset of Regular Languages

Boolean Algebra. Boolean Algebras

7.2 The Definite Integral

Chapter 0. What is the Lebesgue integral about?

Lesson 1: Quadratic Equations

UniversitaireWiskundeCompetitie. Problem 2005/4-A We have k=1. Show that for every q Q satisfying 0 < q < 1, there exists a finite subset K N so that

Math 1B, lecture 4: Error bounds for numerical methods

Frobenius numbers of generalized Fibonacci semigroups

USA Mathematical Talent Search Round 1 Solutions Year 21 Academic Year

THE QUADRATIC RECIPROCITY LAW OF DUKE-HOPKINS. Circa 1870, G. Zolotarev observed that the Legendre symbol ( a p

Improper Integrals. Type I Improper Integrals How do we evaluate an integral such as

and that at t = 0 the object is at position 5. Find the position of the object at t = 2.

Jim Lambers MAT 169 Fall Semester Lecture 4 Notes

Harvard University Computer Science 121 Midterm October 23, 2012

How can we approximate the area of a region in the plane? What is an interpretation of the area under the graph of a velocity function?

We partition C into n small arcs by forming a partition of [a, b] by picking s i as follows: a = s 0 < s 1 < < s n = b.

Student Activity 3: Single Factor ANOVA

f(x) dx, If one of these two conditions is not met, we call the integral improper. Our usual definition for the value for the definite integral

Bernoulli Numbers Jeff Morton

PARTIAL FRACTION DECOMPOSITION

AQA Further Pure 1. Complex Numbers. Section 1: Introduction to Complex Numbers. The number system

Lecture 3: Equivalence Relations

are fractions which may or may not be reduced to lowest terms, the mediant of ( a

Let S be a numerical semigroup generated by a generalized arithmetic sequence,

8 Laplace s Method and Local Limit Theorems

THE EXISTENCE-UNIQUENESS THEOREM FOR FIRST-ORDER DIFFERENTIAL EQUATIONS.

Anatomy of a Deterministic Finite Automaton. Deterministic Finite Automata. A machine so simple that you can understand it in less than one minute

CS 330 Formal Methods and Models

arxiv: v1 [math.ra] 1 Nov 2014

The First Fundamental Theorem of Calculus. If f(x) is continuous on [a, b] and F (x) is any antiderivative. f(x) dx = F (b) F (a).

Physics 116C Solution of inhomogeneous ordinary differential equations using Green s functions

Integral points on the rational curve

Revision Sheet. (a) Give a regular expression for each of the following languages:

Connected-components. Summary of lecture 9. Algorithms and Data Structures Disjoint sets. Example: connected components in graphs

Surface maps into free groups

Introduction to Group Theory

Lecture 3 ( ) (translated and slightly adapted from lecture notes by Martin Klazar)

Homework Solution - Set 5 Due: Friday 10/03/08

1 Nondeterministic Finite Automata

Precalculus Spring 2017

Review of Calculus, cont d

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true.

Simple Gamma Rings With Involutions.

Is there an easy way to find examples of such triples? Why yes! Just look at an ordinary multiplication table to find them!

ARITHMETIC OPERATIONS. The real numbers have the following properties: a b c ab ac

Improper Integrals, and Differential Equations

RELATIONAL MODEL.

Finite Automata. Informatics 2A: Lecture 3. John Longley. 22 September School of Informatics University of Edinburgh

Math 61CM - Solutions to homework 9

Transcription:

On Odd nd Even Cycles in Norml Logic Progrms Fngzhen Lin Deprtment of Computer Science Hong Kong University of Science nd Technology Cler Wter By, Kowloon, Hong Kong flin@cs.hst.hk Xishun Zho Institute of Logic nd Cognition Sun Yt-Sen University 510275, Gungzhou, P. R. Chin hsdp08@zsu.edu.cn Abstrct An odd cycle of logic progrm is simple cycle tht hs n odd number of negtive edges in the dependency grph of the progrm. Similrly, n even cycle is one tht hs n even number of negtive edges. For norml logic progrm tht hs no odd cycles, while it is known tht such progrm lwys hs stble model, nd such stble model cn be computed in polynomil time, we show in this pper tht checking whether n tom is in stble model is NP-complete, nd checking whether n tom is in ll stble models is co-np complete, both re the sme s in the generl cse for norml logic progrms. Furthermore, we show tht if norml logic progrm hs exctly one odd cycle, then checking whether it hs stble model is NP-complete, gin the sme s in the generl cse. For norml logic progrms with fixed number of even cycles, we show tht there is polynomil time lgorithm for computing ll stble models. Furthermore, this polynomil time lgorithm cn be improved significntly if the number of odd cycles is lso fixed. Introduction One of the significnt events in non-monotonic resoning in recent yers hs been the emergence of nswer set progrmming (see, for exmple (Niemelä 1999)), constrint progrmming prdigm bsed on Gelfond nd Lifschitz s stble model nd nswer set semntics of logic progrms (Gelfond&Lifschitz 1988; 1991). In generl, most resoning problems in ASP re NP-hrd. For instnce, checking if there exists n nswer set of norml logic progrm is n NP-complete problem. Recently, Gottlob et l (2002) considered the following decision nd serch problems in logic progrms: 1. Consistency: Determining whether progrm P hs stble model. We thnk the reviewers for comments to this pper. Much of this work ws done during the visit of the second uthor to HKUST. This work hs been supported in prt by HK RGC under CERG HKUST6205/02E, nd by the NSFC under its mjor reserch progrm Bsic Theory nd Core Techniques of Non- Cnonicl Knowledge. Copyright c 2004, Americn Assocition for Artificil Intelligence (www.i.org). All rights reserved. 2. Brve Resoning: Check whether n tom ppers in stble model of progrm P. 3. Cutious Resoning: Check whether n tom ppers in ll stble models of progrm P. 4. SM Computtion: Find n rbitrry stble model of progrm P. 5. SM Enumertion: Compute ll stble models of progrm P. They defined the feedbck width of logic progrm to be the size of smllest set of toms such tht when these toms re deleted from the progrm s dependency grph, the resulting un-directed version of the grph hs no cycles with negtive edge, nd showed tht the bove tsks cn ll be solved in O(2 k n), where n is the size the progrm nd k the feedbck width. So for the clss of logic progrms tht hve bounded feedbck width, ll of the resoning problems cn be solved in liner time on the size of the given input logic progrm. One problem with this result is tht there re lot more cycles in the un-directed version thn in the directed version of the dependency grph of logic progrm. So in this pper, we consider cycles in the directed version of the dependency grph of logic progrm. We distinguish two types of cycles. An even (odd, respectively) cycle is simple cycle with non-zero even (odd, respectively) number of negtive edges. Progrms tht hve no odd cycles re lso clled cllconsistent (Kunen ; Sto 1987). An erly result by Ppdimitriou nd Ynnkkis (1992), done in the context of deductive dtbses more thn 10 yers go, showed tht if norml logic progrm is cll-consistent, then there is polynomil lgorithm tht cn return stble model of the logic progrm. This would suggest tht perhps other resoning tsks, such s checking if there is stble model contining given tom, would be trctble s well. In this pper we show tht this is not the cse. In prticulr, checking if there is stble model contining given tom is n NP-complete problem, just s hrd s in the generl cse. It hs lso been shown tht if progrm hs no even cycle, then it hs t most one stble model (You&Yun 1994): if the well-founded model of the progrm is lso its stble model, then this is the only one; otherwise, it hs no stble model (Zho 2002). In this pper we extend this result nd 80 AUTOMATED REASONING

show tht logic progrm with t most k even cycles hs t most 2 k stble models. In summry, the min results of this pper re s follows: 1. For cll-consistent progrms we show tht the brve resoning problem is NP-complete, nd the cutious resoning problem is co-np-complete, 2. If progrm hs exctly one odd cycle (it could hve ny number of even cycles), then the consistency problem is NP-complete. 3. If progrm hs k even cycles (it could hve ny number of odd cycles), then it hs t most 2 k stble models. Furthermore, the set of ll stble models cn be computed in 2 2k O(n k2 ) time, where n is the size of the given progrm. 4. If the number of the totl odd nd even cycles of logic progrm is t most k, then we show tht the set of ll stble models of the progrm cn be computed in 2 2k O(n 2 ) time, where n is the size of the progrm. As we shll see, besides of theoreticl interests, these results suggest tht for computing nswer sets of logic progrm, good heuristic is to brnch on the vrible tht would brek the most number of even cycles. This pper is orgnized s follows. In section 2, we review some bsic concepts of logic progrmming. In section 3, we prove our results for cll-consistent progrms. We discuss progrms with exctly one odd cycle in section 4, progrms with fixed number of even cycles in section 5, nd progrms with fixed number of odd nd even cycles in Section 6. We conclude this pper in section 7. Preliminries We consider only norml propositionl logic progrms, which re finite sets of rules of the following form r : b 1,, b m, not c 1,, not c n, where r is the nme of the rule,, b i, 1 i m, nd c j, 1 j n re toms, nd m n 1. In the following, we let Hed(r)= (the hed of r), Pos(r)={b 1,, b m } (the positive body of r), nd Neg(r)={c 1,, c n } (the negtive body of r). The body of r is Pos(r) Neg(r). In the following, given (norml) logic progrm P, we denote by At(P ) the set of toms occurring in P. We shll lso cll toms positive literls. A negtive literl is n expression of the form not, where is n tom. A literl is either positive or negtive literl. Given logic progrm P, S At(P ) is sid to be stble model (Gelfond&Lifschitz 1988) of P if S = Cons(P S ), where P S is obtined from P nd S by the following Gelfond-Lifschitz trnsformtion: (1) for ech tom p nd ny rule r P, if p Neg(r) nd p S, then remove not p from r, nd (2) in the set of remining rules, delete those rules tht still contin negtive literl in their bodies, nd Cons(P S ) is the set of toms derivble from the definite logic progrm P S. A logic progrm my hve zero, one, or more thn one stble models. In comprison, the well-founded model semntics (Vn Gelder et l 1991) produces unique 3-vlued model for norml logic progrm. Formlly, 3-vlued interprettion I is pir of two disjoint sets of toms, (I, I ). Atoms in I re ssigned true nd those in I flse. Atoms occurring in neither I nor I re undefined. Given logic progrm P, the opertion Γ P defined by Γ P (S) := Cons(P S ), is nti-monotone, i.e., if S 1 S 2 then Γ P (S 2 ) Γ P (S 1 ). Thus the opertion Γ 2 P, defined s Γ 2 P (S) := Γ P (Γ P (S)), is monotone. Therefore, Γ 2 P hs the lest fixed-point, sy S, nd the gretest fixed-point, sy T. The well-founded model of P is (S, At(P ) T ). The well-founded model cn be computed in qudrtic time (Vn Gelder et l 1991), nd hs been used to simplify logic progrm in lmost ll of the current nswer set progrmming systems. In the following, we denote by WFM(P ) = (WFM(P ), WFM(P ) ) the well-founded model of P. We use WFM(P ) to simplify P s follows: (1) Delete ll rules r P such tht either Hed(r) WFM (P ), Pos(r) WFM (P ), or Neg(r) WFM (P ). (2) From the bodies of the remining rules, remove ll positive literls in WFM (P ) nd ll negtive literls not q with q WFM (P ). The resulting progrm is written s P \ WFM(P ). The dependency grph (Apt et l 1988) of norml logic progrm P, denoted by G P, is directed grph with signed edges. The vertices of G P re toms in At(P ). There is positive (negtive, respectively) edge from vertex p to vertex q if there is rule r P such tht Hed(r) = q nd p Pos(r) (p Neg(r), respectively). Informlly, positive (negtive, respectively) edge from p to q mens tht q depends positively (negtively, respectively) on p. If simple cycle of G P hs n odd ( non-zero even, respectively) number of negtive edges then we cll it n odd (even, respectively) cycle. In the following, we denote by NOC(P ) (NEC(P ), respectively) the number of odd (even, respectively) cycles in the dependency grph of P. Cll-Consistent Progrms As mentioned erlier, cll-consistent progrm is norml logic progrm tht hs no odd cycles. It hs been shown tht cll-consistent progrm lwys hs stble model, nd such stble model cn be computed in polynomil time. Despite this, checking if n tom is in stble model of cll-consistent progrm is still NP-complete, nd checking if n tom is in ll the stble models of cll-consistent progrm is still co-np complete. Theorem 1 () Brve resoning for cll-consistent progrms is NPcomplete. (b) Cutious resoning for cll-consistent progrms is co- NP-complete. AUTOMATED REASONING 81

Proof. (Sketched) Memberships in NP for (), nd co-np for (b) is obvious. For hrdness, consider set ϕ of cluses with vribles x 1,..., x n. Let y 1,..., y n, nd b be new vribles. Let P (ϕ) be the progrm consisting of rules in the following groups. (I) For ech x i (1 i m), the rules: y i not x i, x i not y i. (II) For ech C in ϕ, the rule: C, where for cluse C, if x C, then x C, nd if n tom x C, then not x C. (III) The single rule: b not. The only cycles of P (ϕ) re generted by rules in group (I), nd they re ll even cycles. Thus the progrm is cllconsistent. We show tht ϕ is stisfible iff b is in t lest one stble model of P (ϕ), nd ϕ is unstisfible iff is in every stble model of P (ϕ). From these, the NP-hrdness of the brve resoning, nd the co-np-hrdness of the cutious resoning follow. Suppose ϕ is stisfible. We cn then generte truth ssignment stisfying it using the rules in (I). Under this truth ssignment, rules in group (II) re not pplicble. Hence we cn not use them to get. In this cse, we get b by using the rule in (III). Therefore, we get stble model of P (ϕ) contining b. Suppose ϕ is not stisfible. Then ny truth ssignment mkes some cluse C in ϕ flse, nd hence the rule in (II) is pplicble. Thus, is in every stble model of P (ϕ). Notice tht well-known technique for finding stble model contining n tom is to dd the constrint not to the originl logic progrm. According to our theorem, nd the fct tht there is polynomil time lgorithm tht cn return stble model of cll-consistent logic progrm, one cnnot replce this constrint by polynomil number of rules without introducing some odd cycles unless the polynomil hierrchy collpses. It is worth mentioning here tht in disjunctive logic progrms, the so-clled hed-cycle free progrms (Ben- Eliyhu-Zohry&Ploponi 1997; Ben-Eliyhu-Zohry et ll 2000) pper to exhibit similr properties like cll-consistent progrms. In prticulr, finding one nswer set is trctble for these disjunctive logic progrms, but brve resoning nd cutious resoning re hrd. Progrms with Exctly One Odd Cycle Progrms with odd cycles my or my not hve stble models. For instnce, consider the following progrms P 0 = {b not, c not b, not c}, P 1 = P 0 { }. Both hve exctly one odd loop, but P 0 hs no stble model while P 1 hs one {, c}. In generl, even cycles generte models while odd cycles eliminte models. For instnce, the following set of rules {x 1 not y 1, y 1 not x 1,, x n not y n, y n not x n } (1) hs n even cycles nd 2 n stble models. Now if we dd n odd cycle such s x 1 not x 1 to it, then in principle, we my hve to go through ll these 2 n models before we re sure tht there is no stble model of the new progrm. This is bsiclly the reson why the consistency problem for progrms with exctly one odd cycle is intrctble. Theorem 2 The consistency problem for progrms whose dependency grphs hve exctly one odd cycle is NPcomplete. Proof. Membership in NP is obvious. The proof of hrdness is similr to tht of Theorem 1. Consider gin set ϕ of cluses with vribles x 1,..., x n. Let y 1,..., y n, nd b be new vribles. Let P (ϕ) be s in the proof of Theorem 1 but with the rule (III) replced by the following rule: (III ) b, not b. Clerly, P (ϕ) hs exctly one odd cycle formed by rule (III ), nd it hs stble model if nd only if ϕ is stisfible. Progrms with Fixed Number of Even Cycles From the result in the lst section, we see tht restricting the number of odd cycles to fixed positive number cnnot reduce the complexity. As we mentioned bove, the reson is tht even cycles cn generte n exponentil number of models. We now consider wht hppens if we restrict the number of even cycles. As mentioned in Introduction, if progrm hs no even cycle, then it hs t most one stble model (You&Yun 1994). Furthermore, if the well-founded model of the progrm is lso its stble model, then this is the only one; otherwise, it hs no stble model (Zho 2002). To study the generl cse, we first introduce the following definition, which ws first introduced in (Cholewinski&Truszczynski 1999). Definition 1 Let P be progrm, nd n tom in At(P ). Define P to be the progrm obtined from P by 1. deleting ll rules whose bodies contin not, nd 2. removing from the bodies of remining rules. Similrly define P to be the progrm obtined from P by 1. deleting ll rules whose bodies contin, nd 2. removing not from the remining rules. Notice tht G P re subgrphs of G P, nd tht in G P there re no edges going out from. Lemm 1 (Cholewinski&Truszczynski 1999) Let P be progrm, At(P ). Suppose S is stble model of P. Then 1. If S then S is stble model of P. 2. If S then S is stble model of P. Cholewinski nd Truszczynski (1999) lso proved tht progrm with n rules hs t most O(3 n/3 ) stble models. Our following result gives the upper bound of the number of stble models ccording to the number of even cycles. Recll tht for progrm P, NEC(P ) denotes the number of even cycles in P, nd NOC(P ) the number of odd cycles in P. 82 AUTOMATED REASONING

Lemm 2 Let P be progrm such tht NEC(P ) k. Then P hs t most 2 k stble models. Proof. We show the theorem by induction on k, here k is NEC(P ). If k = 0 then the lemm follows from the forementioned result by You nd Yun (1994). Suppose NEC(P ) 1. Then pick n tom At(P ) such tht occurs in n even cycle. Plese note tht G P re subgrphs of G P, nd tht in G P there re no edges going out from.thus NEC(P ) k1 nd NEC(P ) k1. By the induction hypothesis, P (P, respectively) hs t most 2 k1 stble models. By the bove lemm, we know tht P hs t most 2 k1 2 k1 = 2 k stble models. From these two lemms, nd the fct tht when NEC(P ) is zero, either P hs no stble model or its well-founded model is its stble model, nive wy to compute the stble models of progrm with NEC(P ) k is to choose n tom tht lies in n even cycle, split the current progrm P into P nd P, nd then inductively compute the stble models of P nd P, which hve fewer numbers of even cycles thn P. Unfortuntely, finding n tom tht lies in n even loop of progrm is n intrctble problem: Lemm 3 Given progrm P nd n tom. The problem of determining whether lies in n even cycle of G P is NPcomplete. Proof. (Sketched) The proof of this this lemm is similr to the proof of Theorem 16 of (Gottlob et l 2002). The membership in NP is obvious. To prove the hrdness we reduce the node-disjoint pth problem for directed grphs, which is NP-complete problem (Grey&Johnson 1979), to our problem. Let G = (N, E) be directed grph, nd x 1, y 1 nd x 2, y 2 two pirs of nodes of G. The problem is deciding whether there re two node-disjoint pths linking x 1 to x 2 nd y 1 to y 2. From G, we construct logic progrm P (G) contining rule t s for ech edge (s, t) E, plus two dditionl rules x 1 not y 2, nd y 1 not x 2. We cn show tht x 1 lies in n even cycle in P G if nd only if there re two node-disjoint pths linking x 1 to x 2 nd y 1 to y 2 in G. So insted of looking for n tom tht lies in n even cycle of progrm, nd split the progrm on the tom, we simply split the progrm on every tom of the progrm. This is the bsic ide behind our lgorithm for computing Ans(P, k) in Figure 1. Lemm 4 Let k be fixed nturl number, P progrm with NEC(P ) k. Then every stble model of P ppers in Ans(P, k). Proof. We prove the ssertion by induction on k. When k = 0, the ssertion follows from the known result. Suppose k > 0. If the dependency grph G P hs n even cycle, then the cycle will be broken in G P nd G P for some. Tht is, NEC(P ) k 1 nd NEC(P ) k 1. By the induction hypothesis, ll stble models of P (P ), respectively) pper in Ans(P, k 1) (Ans(P, k 1), respectively). Now the lemm follows from Lemm 2. Function Ans(P, k) Input A norml progrm P, nd nturl number k. Output A set of stble models of P begin if k = 0 then if WFM (P ) is stble model of P then return {WFM (P )} else return. Π :=. for ech tom At(P ) for ech S Ans(P, k 1) Ans(P, k 1) if S is stble model of P then Π := Π {S}. return Π end Figure 1: An lgorithm for computing the stble models of logic progrm with t most k even cycles Lemm 5 Let P be progrm, nd k fixed nturl number. Then 1. Ans(P, k) contins t most 2 k n k sets, where n is the size of P. 2. Ans(P, k) cn be computed in 2 2k O(n k2 ) time. Proof. (1) We shll proceed by induction on k. The ssertion clerly holds when k = 0. Suppose k > 0. By the induction hypothesis, Ans(P, k 1) (Ans((P, k 1), respectively) contins t most 2 k1 n k1 sets for ech tom. Thus, Ans(P, k) hs t most 2n(2 k1 n k1 ) = 2 k n k sets. (2) We shll prove the clim by induction on k. When k = 0 the clim is obviously vlid becuse the well-founded model cn be computed in qudrtic time nd to check whether it is stble model costs not more thn qudrtic time. Suppose k > 0. By the induction hypothesis, to compute Ans(P, k 1) nd Ans(P, k 1) for ll will cost time not more thn 2n(2 2(k1) n k1 ) = 2 2k1 n k2. From (1), to check whether the sets in ll Ans(P, k 1) Ans(P, k 1) re stble models needs time not more thn 2n(2 k1 n k1 )O(n 2 ) = 2 k O(n k2 ). Altogether, the totl running time is 2 2k1 n k2 2 k n k2 2 2k n k2. From these two lemms we obtin the following theorem. Theorem 3 For n rbitrry fixed nturl number k, the set of stble models of progrm with t most k even cycles cn be computed in 2 2k O(n k2 ) time, where n is the size of P. Notice tht in the theorem, the time complexity is bounded by n k2 which is polynomil whose degree depends on the prmeter k. It remins n open question whether there is n lgorithm computing ll stble models in time bounded by polynomil whose degree does not depend on k. In the next section, we show tht this is true for logic progrms with t most k totl number of odd nd even cycles. AUTOMATED REASONING 83

Function All-Ans(P ) Input: A norml progrm P Output: The set of stble models of P begin if WFM (P ) is stble model of P then return {WFM (P )}. Q := P \ WFM(P ) (now Q is non-empty). compute bottom H of Q. pick n tom H such tht there is nother tom b in H, nd negtive edge to b in G Q. Π :=. for ech S All-Ans(P ) All-Ans(P ) if S is stble model of P then Π := Π {S} return Π end Figure 2: An lgorithm for computing the stble models of logic progrm Progrms with Fixed Number of Cycles In this section we show tht for ny given k, there is n lgorithm tht computes in qudrtic time ll stble models of ny given progrm P with NEC(P ) NOC(P ) k. Recll tht strongly connected component of grph is set of nodes such tht for ny two nodes in the set, there is pth from one node to the other, nd it is not proper subset of ny such sets. There is liner time lgorithm tht cn compute ll strongly connected components of grph (Trjn 1972). Given norml progrm P, we cll set B of toms bottom if it is strongly connected component of G P, nd there is no other strongly connected component B such tht there is pth from n tom in B to nother tom in B. Proposition 1 Let P be norml logic progrm. If Q = P \ WFM(P ) is not empty, then every bottom of Q must hve pir of nodes nd b such tht there is negtive edge from to b. Proof. We prove by contrdiction. Suppose Q is not empty, H is bottom of Q, nd ll pths in H re positive. Let R(H) = {r Q Hed(r) H}. Since H is bottom of Q, nd Q is the result of simpifying P by its well-founded model, there cnnot be ny tom p in Q such tht p H, nd there is pth from p to n tom in H. For otherwise, since there is no more cycles below p, its truth vlue would hve been dertermined in the well-founded model of P, thus eliminted when P is simplified using its well-founded model. Thus the bodies of ll rules in R(H) must ll be in H. As consequence, no rule in R(H) cn hve negtive literl in its body. Moreover, since Q = P \ WFM(P ), every rule in Q hs to hve non-empty body. Then ccording to the procedure for clculting well-founded models, ll toms in H re flse in the well-founded model of P, nd hence they cnnot occur in Q. This contrdicts the ssumption tht H is strongly connected component of Q. Lemm 6 Let P be norml logic progrm. Then All- Ans(P ) defined in Figure 2 contins ll stble models of P. Proof. We show the theorem by induction on k, the number of cycles of G P. When k = 0, i.e., NEC(P )=NOC(P )=0, the theorem follows from the fct tht P hs exct one stble model which is the well-founded model of P. Suppose k > 0, nd NEC(P )NOC(P ) = k. If WFM(P ) is stble model of P, then it is the unique stble model of P, nd the theorem follows. So, we ssume tht WFM(P ) is not stble model of P. Thus Q := P \ WFM(P ) is not empty. Suppose H is bottom of Q, let nd b be two toms in H such tht there is negtive edge from to b. Since H is connected component, there must pth from b to. Thus, there is t lest one cycle in H tht goes through the negtive edge from to b. Then NEC(P )NOC(P ) k 1, nd NEC(P ) NOC(P ) k 1. We know tht every stble model of P is stble model of either P or P. By the inductive ssumption, every stble model of P (P, respectively) ppers in All-Ans(P ) (All-Ans(P ), respectively). Therefore, every stble model of P ppers in All-Ans(P ). Lemm 7 For ech fixed nturl number k, the function in Figure 2 runs in time 2 2k O(n 2 ) for ny given progrm P such tht NEC(P )NOC(P ) k, where n is the size of P. Proof. We proceed by induction on k. When k = 0, the lemm follows from the fct tht P hs exct one stble model, i.e., the well-founded model, which cn be computed in qudrtic time nd tht to check whether the well-founded model is stble model costs no more thn qudrtic time. Suppose k > 0. To compute the well-founded model of progrm costs qudrtic time, to computer bottom tkes liner time, nd the tom nd P, P cn be computed in liner time. By the inductive ssumption, to compute All- Ans(P ) nd All-Ans(P ) costs not more thn 2 2(k1) O((n 1) 2 ) 2 2(k1) O((n 1) 2 ) 2 2k1 O(n 2 ) time. From Lemm 2, we know tht All-Ans(P ) All-Ans(P ) hs t most 2 k elements. Thus to check whether they re stble models of P needs no more thn time 2 k O(n 2 ). Altogether the lgorithm costs no more thn O(n 2 ) O(n) 2 2k1 O(n 2 ) 2 k O(n 2 ) 2 2k O(n 2 ) By Lemms 6 nd 7 we obtin the following theorem. Theorem 4 The set of ll stble models of progrm with fixed number of even nd odd cycles cn be computed in qudrtic time 2 2k O(n 2 ), where k is the number of even nd odd loops, nd n the size of the given progrm. We wnt to emphsize tht this result ssumes fixed k, nd the co-efficient 2 2k mens tht this number should not be too big for the lgorithm in Figure 2 to be prcticl. Of course, this is the worst cse complexity. Problems normlly encountered in prctice could be much esier even for lrge k. 84 AUTOMATED REASONING

Conclusions We hve performed detiled complexity nlysis of norml logic progrms with limited number of odd nd/or even cycles. To recst, for norml logic progrm without ny odd cycles, others hve shown tht it lwys hs stble models (Dung 1992; You&Yun 1994), nd one of them cn be computed in polynomil time (Ppdimitriou&Ynnkkis 1992). Wht we hve shown here is tht despite these positive results, given n tom, checking whether it is in one of its stble models is n NP-complete problem, nd checking whether it is in ll of its stble models is conp-complete problem. We hve lso shown tht if we relx the condition little bit, llowing just one odd cycle, then whether there is stble model becomes n NP-complete progrm, the sme s in the generl cse. For norml logic progrm without even cycles, others hve shown tht it hs t most one stble model (You&Yun 1994), nd if it hs stble model, then the stble model must lso be its well-founded model (Zho 2002). We hve extended these results, nd shown tht if norml logic progrm hs t most k even cycles, then it hs t most 2 k stble models, nd ll of them cn be computed in polynomil time for the fixed prmeter k. It is cler tht there is disprity between the results for progrms with limited number of odd cycles nd those for progrms with limited even cycles. The reson is tht these two types of cycles ply very different roles. The even cycles re stble model genertors, nd the odd cycles re stble model elimintors. We believe tht our results re not just of theoreticl interest. The lgorithms in Figures 1 nd 2, suggest tht for computing nswer sets of generl logic progrms, good heuristic is to choose the next vrible tht would brek the most number of even cycles. The key of course is how to efficiently compute the vribles tht would brek lrge number of even cycles. One future work for us is to ddress this problem nd to experiment with this heuristic. References Apt, K.R., Blir, H.A., nd Wlker, A. 1988. Towrds Theory of Declrtive Knowledge. In Foundtion of Deductive Dtbse nd Logic Progrmming (ed. J. Minker), 293 322, Morgn Kufmnn, Los Altos, 1988. Apt, K.R., nd Bol, R.N., 1994. Logic Progrmming nd Negtion: A Survey. Journl of Logic Progrmming 19/20:9 71. Ben-Eliyhu-Zohry, R. nd Ploponi, L. 1997. Resoning with miniml models: efficient lgorithms nd pplictions. Artificil Intelligence 96(2):421 449. Ben-Eliyhu-Zohry, R., Ploponi, L., nd Zemlynker, V. 2000. More on trctble disjunctive dtlog. Journl of Logic Progrmming 46(1-2):61 101. Bidoit, N., nd Froidevux, C. 1991. Negtion by Defult nd Unstrtifible Logic Progrms. Theoreticl Computer Science 78:85 112. Cholewinski, P., nd Truszczynski, M. 1999. Extreml Problems in Logic Progrmming nd Stble Model Computtion. Journl of Logic Progrmming 38:219 242. Dung, P.M. 1992. On the Reltion between Stble nd Well- Founded Semntics of Logic Progrms. Theoreticl Computer Science: Logic, Semntics nd Theory of Progrmming 105:7 26. Eiter, T., Leone, N., Mteis, C., Pfeifer, G., nd Scrnello, F. 1998. The KR-System DLV: Progress Report, Comprison nd Benchmrks. In Proceedings of the 6th Interntionl Conference on Principles of Knowledge Representtion nd Resoning, 406 417. Morgn Kufmnn Publishers. Grey, M.R., nd Johnson, D.S. 1979. Computers nd Intrctbility, A Guide to the Theory of NP-Completeness. Freemn, Newyork. Gelfond, M., nd Lifschitz, V. 1988. The Stble Model Semntics for Logic Progrmming. In Proceedings of the 5th Interntionl Conference on Logic Progrmming, 1070 1080. The MIT Press. Gelfond, M., Lifschitz, V., 1991. Clssicl Negtion in Logic Progrms nd Disjunctive Dtbse. New Genertion Computing 9: 365 385. Gottlob, G., nd Scrcello, F., nd Sideri, M. 2002. Fixed- Prmeter Complexity in AI nd Nonmonotonic Resoning. Artificil Intelligence 138:55 86. Kleine Büning, H., nd Lettmnn, T. 1999. Propositionl Logic: Deduction nd Algorithms. Cmbridge University Press. Kunen, K. 1989. Signed Dd Dependencies in Logic Progrms. Journl of Logic Progrmming, 7:231 245. Lifschitz, V., nd Turner, H. 1994. Splitting Logic Progrm. In Proceedings of Interntionl Conference on Logic Progrmming, 23 37. Lin, F., nd You, J.H. 2002. Abduction in Logic Progrmming: A New Definition nd n Abductive Procedure Bsed on Rewritting. Artificil Intelligence, 140(1/2):175 205. Lin, F., nd Zho, Y. 2002. ASSAT: Computing Answer Sets of Logic Progrm by SAT Solvers. In Proceedings of AAAI-2002, 112 117. Niemelä, I. 1999. Logic Progrms with Stble Model Semntics s Constrint Progrmming Prdigm. Annls of mthemtics nd Artificil Intelligence 25:241 273. Ppdimitriou, C.H., nd Ynnkkis, M. 1992. Tie-Breking Semntics nd Structurl Totlity. In Proceedings of 11th ACM conference on Principles of Dtbse Systems (PODS 1992), 16 22. Sto, T. 1987. On the Consistency of First-Order Logic Progrms, ETL Technique Report, TR-87-12. Trjn, R.E. 1972. Depth-First Serch nd Liner Grph Algorithms, SIAM Journl of on Computing 1:146 160. Vn Gelder, A., Ross, K.R., nd Schlipf, J.S. 1991. The Well- Founded Semntics for Generl Logic Progrms. Journl of the ACM 38:620 650. You, J.H., nd Yun, L. 1994. A Three-Vlued Semntics for Deductive Dtbse nd Logic Progrms. Journl of Computer nd System Science 49:334 361. Zho, J. 2002. A Study of Answer set Progrmming, MPhil Thesis, Dept. of Computer Science, The Hong Kong University of Science nd Technology. AUTOMATED REASONING 85