Every Logic Program Has a Natural Strati cation And an Iterated Least Fixed Point Model Teodor C. Przymusinski University of Texas at El Paso El Paso, TX 79968 (teodor%
[email protected]) Extended Abstract
1 Introduction The perfect model semantics [ABW88, VG89b, Prz88a, Prz89b] provides an attractive alternative to the traditionally used semantics of logic programs based on Clark's completion of the program [Cla78, Llo84, Fit85, Kun87]. Perfect models are minimal models of the program, which can be equivalently described as iterated least xed points of natural operators [ABW88, VG89b], as iterated least models of the program [ABW88, VG89b] or as preferred models with respect to a natural priority relation [Prz88a, Prz89b]. As a result, the perfect model semantics is not only very intuitive, but it also has been proven equivalent to suitable forms of all four major formalizations of non-monotonic reasoning in AI (see [Prz88b]) and is used in existing database [Zan88] and truth maintenance systems. Additionally, the perfect model semantics eliminates some serious drawbacks of Clark's semantics [Prz89b] and admits a natural sound and complete procedural mechanism, called SLSresolution [Prz89b]. One of the drawbacks of the perfect model semantics, however, was the fact that it was only de ned for a relatively narrow class of strati ed logic programs [CH85, ABW88, VG89b]. Consequently, several exten1
sions of the perfect model semantics have been introduced in the literature [GL88, VGRS90, PP88]. In this paper we show that the well-founded semantics, proposed in [VGRS90] and de ned for all logic programs, has properties entirely analogous to the properties of the perfect model semantics and also leads to a natural notion of strati cation of an arbitrary logic program.
First, we provide a constructive and, in our opinion, more intuitive description of the well-founded model MP of the program P, as an iterated least xed point of a natural operator and we prove that MP is a minimal (3-valued) model of P. The above de nition of MP allows us to de ne a dynamic strati cation fSg of an arbitrary program P, which has properties analogous to the properties of standard strati cation. We apply it to show that the well-founded model can also be de ned as an iterated least model of P, with respect to dynamic strati cation. We also give a de nition of the well-founded model MP based on the preference relation between atoms, which is analogous to the de nition of perfect models [Prz88a, Prz89b]. Finally, we employ the concept of dynamic strati cation to extend the de nition of SLS-resolution [Prz89b], a top-down proof procedure previously described only for strati ed programs, to the class of all logic programs and to prove that SLS-resolution is sound and complete (for non- oundering queries) with respect to the well-founded model semantics. The concept of dynamic strati cation and the characterizations of the well-founded model of P mentioned above can be used to prove [Prz89c] that, for an arbitrary logic program, the well-founded semantics is equivalent to suitable 3-valued extensions of all four major formalizations of non-monotonic reasoning in AI: McCarthy's circumscription, Reiter's closed world assumption, Moore's autoepistemic logic and Reiter's default theory. This result not only provides a further justi cation of the well-founded semantics, but it also establishes a large class of theories for which natural forms of dierent non-monotonic formalisms coincide. In [Bry89] logic programs were investigated from the point of view of constructivistic logic. Bry proposed a natural semantics for constructively 2
consistent logic programs, extended the Magic Sets query processing method and showed its completeness with respect to his semantics. One can prove that Bry's semantics also coincides with the well-founded semantics, thus providing yet another, constructivistic argument in favor of the well-founded semantics, and showing that, in addition to the top-down SLS-resolution, also the bottom-up Magic Sets method can be used to compute the well-founded semantics. The precise description of the relationship between Bry's constructivistic semantics and the well-founded semantics, together with complete proofs of the results presented here, will appear in the full version of the paper.
2 Three-Valued Models By a logic program we mean a nite set of universally quanti ed clauses of the form 8 (A L1 ^ : : : ^ Lm ); where m0, A is an atom and Li are positive or negative literals (see [Llo84]). Following a standard convention, such clauses will be simply written as: A L1 ; : : : ; L m : The alphabet of a program P consists of all the constant, predicate and function symbols that appear in P, a countably in nite set of variable symbols, connectives (:; ^; _; ), quanti ers (9; 8) and the usual punctuation symbols. We assume that if P does not contain any constants, then one is added to the alphabet. The language L of P consists of all the well-formed formulae of the so obtained rst order theory. The Herbrand base HP of P is the set of all ground atoms of the theory. Throughout the paper we assume that Clark's Equality Axioms (CET) are satis ed (see [Kun87, Prz89b]). By a 3-valued interpretation I of the program P we mean a pair < T ; F >, where T and F are subsets of the Herbrand base HP of P. The set T contains all ground atoms true in I, the set F contains all ground atoms false in I and the truth value of the remaining atoms in U = HP ? (T [ F ) is unde ned. If L = :C is a negative literal and if C is true (false) in I then L is said to be false (true) in I. If the sets T and F are not disjoint then the same atom may be true and false at the same time. An interpretation is consistent if the sets T and F 3
are disjoint. Obviously, only consistent interpretations are meaningful, but it will be convenient not to require that all interpretations are consistent. Suppose now that I is a consistent interpretation. If A is a ground atom from HP then we write valI (A) = t (resp. valI (A) = f ; resp. valI (A) = u ) if A is true (resp. false; resp. unde ned) in I. We call valI (A) the truth value of A in I. A 3-valued interpretation of P is called a 2-valued interpretation of P if all ground atoms are either true or false in I, i.e. if HP = T [ F . Using the truth values of ground atoms we can extend the truth valuation valI to the set of all sentences as follows. For any sentences F and G we de ne: valI (:F ) = :valI (F ); where : t = f , : f = t and : u = u , valI (F _ G) = maxfvalI (F ); valI (G)g; valI (F ^ G) = minfvalI (F ); valI (G)g; ( valI (G) valI (F ) valI (F ! G) = tf ;; ifotherwise, where the truth values are ordered by: t > u > f . Similarly, for a formula F(x) with unbounded variable x we de ne: valI (9x F (x)) = maxfvalI (F (A)) : A 2 HP g; valI (8x F (x)) = minfvalI (F (A)) : A 2 HP g; where the minimum (resp. maximum) of an empty set of values is de ned as t (resp. f ). A consistent 3-valued interpretation M is a 3-valued model of P if valM (C ) = t , for every clause in P. Equivalently, M is a model of P if for every ground instance A L1 ; : : : ; L m of a program clause C we have valM (A) valM (L1 ^ : : : ^ Lm ) (= minfvalM (Li ) : i mg): If M is 2-valued then it is called a 2-valued model of P. 4
Remark 2.1 Observe, that our approach is dierent from the one proposed
in [Fit85, Kun87] (and also used in [VGRS90]). Since their goal was to extend the semantics based on Clark's completion, rather than the perfect model semantics, their models were 3-valued models of Clark's completion COMP(P) of the program P rather than 3-valued models of the program P itself. Also notice, that if we de ne another implication connective ( by: F ( G F _ :G; then { although the two implications " " and "(" coincide in 2-valued logic { they are dierent in 3-valued logic. For example, valM (F F ) = t no matter what is the truth value of F in M, but valM (F ( F ) = u if valM (F ) = u . This is a re ection of the fact, that in 3-valued logic we have more than one natural notion of an implication, which are applicable in dierent contexts. Similar remarks apply to the two associated equivalence connectives $ and ,. For example, in [Fit85, Kun87] the equivalence connective "$" represents the equivalence relation needed to build Clark's completion of the program P, while the equivalence connective "," is used in P itself. In the sequel by an interpretation (resp. model) we will mean a 3-valued interpretation (resp. model). We will speci cally indicate those instances when interpretations are 2-valued. We will say that an interpretation I 0 =< T 0; F 0 > extends an interpretation I =< T; F > if T 0 T and F 0 F . We will denote this fact by I0 I. If Is =< Ts; Fs >, for s 2 ST, are interpretations, then by their intersection T T we mean the interpretation s2S Is =< s2S Ts; s2S Fs >. Clearly, A is true (false) in the intersection i it is true (false) in all interpretations Is. Similarly, byS the union of these interpretations we mean the interpretation S S s2S Is =< s2S Ts ; s2S Fs >. We will say that a model M =< T ; F > of P is less than or equal to a model M 0 =< T 0; F 0 > of P if T T 0 and F F 0. In other words, M M 0 if M has no more true facts and no less false facts than M 0 does. A model M is a minimal model of P if there is no model M 0 distinct from M such that M 0 M . A model M is the least model of P if M M 0 for every model M 0 of P. Thus minimal models minimize the set of true values, while maximizing 5
the set of false values. Clearly, when restricted to 2-valued models, the above de nitions coincide with standard de nitions. Any consistent 3-valued intrepretation can be viewed as a function from the Herbrand base HP to the three-element set ff,u,tg, ordered by f < u < t. As observed by Van Gelder, a model M is less than or equal to a model M 0 if and only if M is less than or equal to M 0 under the usual (pointwise) ordering of functions. Consequently, least (minimal) models can be simply viewed as least (minimal) functions.
Remark 2.2 Observe, that our notion of minimality of a model is again
dierent from that considered in [Fit85, Kun87]. Using their de nition, the least model of the program p p is obtained when p is unde ned, while using our de nition the least model is obtained when p is false. This re ects fundamental dierences between semantics based on Clark's completion and `model theoretic' semantics, such as the least model semantics, perfect model semantics and well-founded semantics.
3 Well-Founded Model: Point De nition
Iterated Fixed
In this section we give a new and, in our opinion, more intuitive de nition of the well-founded model, as an iterated least xed point of a natural operator. As opposed to the original de nition given in [VGRS90], our de nition is also constructive1 . Suppose that P is a program and I is its xed interpretation. We rst introduce two operators TI and FI . The operator TI (resp. FI ) assigns to every set T (resp. F) of ground atoms a new set TI (T ) (resp. FI (F )) of ground atoms. Intuitively, I represents facts currently known to be true or false and TI (T ) (resp. FI (F )) contains new facts (i.e. facts not contained in I), whose truth (resp. falsity) can be immediately derived from the program P assuming that all facts in I hold and assuming that all facts in T are true (resp. all facts in F are false).
De nition 3.1 For sets T and F of ground atoms we de ne: 1 Independently, [VG89a] proposed a dierent constructive de nition of the well-founded model.
6
TI (T ) = fA : valI (A) 6= t and there is a clause B
L1 ; : : : ; Lm in P and a ground substitution such that A = B and for every i m either Li is true in I or Li 2 T g; FI (F ) = fA : valI (A) 6= f and for every clause B L1 ; : : : ; Lm in P and a ground substitution such that A = B there exists an i m such that either Li is false in I or Li 2 F g. 2 The conditions valI (A) 6= t and valI (A) 6= f are inessential and they appear in the above de nition solely for the purpose of ensuring that only new (true or false) facts will be included. We will consider TI (resp. FI ) to be the operator de ned on the set of all subsets of HP , ordered by standard inclusion (resp. by reverse inclusion).
Proposition 3.1 The operators TI and FI are monotonic, i.e. TI (T ) TI (T 0) if T T 0 and FI (F ) FI (F 0) if F F 0: Proof: Suppose that T T 0 and A 2 TI (T ). There is a clause B
L1 ; : : : ; Lm in P and a ground substitution such that A = B and for every i m either Li is true in I or Li 2 T . However, if Li 2 T then also Li 2 T 0, which implies that A 2 TI (T 0). Thus the operator TI is monotonic. The proof for FI is analogous. 2 We will now de ne two subsets TI and FI of the Herbrand base obtained by iterating the operators TI and FI . De nition 3.2 Let I =< T ; F > be an interpretation. De ne: TI"0 = ; and FI#0 = HP ; TI"n+1 = TI (TI"n) and FI#n+1 = FI (FI#n); \ [ TI = TI"n and FI = FI#n: 2 n
n
Proposition 3.2 The trans nite sequence f TI"ng is monotonically increasing and the trans nite sequence fFI#n g is monotonically decreasing. The set TI is the least xed point of the operator TI and the set FI is the least2 xed point of the operator FI . 2
Recall, that for this operator the ordering is de ned as reverse inclusion.
7
Proof: Clearly, TI"0 TI"1 . If TI"n TI"n+1 , then TI"n+1 TI"n+2 , by monotonicity of TI . This shows that the sequence fTI"ng is monotonically increasing. Now we Sshow that TI is a xed point of TI , i.e. we show that TI (TI ) = TI . Since TI = n : 2 The operator I extends the interpretation I to I (I ) by adding to I new atomic facts TI which can be derived from P knowing I and negations of new atomic facts FI which can be assumed false about P knowing I. Proposition 3.3 The operator I is monotonic, i.e. I (I ) I (I 0) if I I 0: Proof: Let I =< T; F >, I 0 =< T 0; F 0 >, T T 0 and F F 0. In order to show that TI T 0 [ TI , we will prove that TI"n T 0 [ TI"n, for all n's. This is true for n=0. Suppose it holds true for some n and let A 2 TI"n+1. There is a clause B L1 ; : : : ; Lm in P and a ground substitution such that A = B and for every i m either Li is true in I or Li 2 TI"n. If Li is true in I, then also Li is true in I 0, and if Li 2 TI"n then either Li 2 TI"n or LI is true in T 0, which implies that A 2 T 0 [ TI"n+1. The proof for FI is similar. 2 We now de ne the model MP of the program P. 0
0
0
0
8
De nition 3.4 Let:
M0 =< ;; ; >; M+1 = I (M ); i.e. M+1 = M [ < TM ; FM >; [ M = M ; for limit : <
Since the trans nite sequence fM g of interpretations is clearly monotonically increasing there exists the smallest countable ordinal such that M is a xed point of the operator I , i.e. such that
M = I (M ) = M+1 : In other words, there exists the rst such that both sets TM and FM are empty. We call = (P ) the depth of the program P. We denote the xed point interpretation M by MP . 2 It turns out that the interpretation MP is in fact a model of P and has other important properties.
Theorem 3.1 The interpretation MP is a minimal 3-valued model of P. It is also the least xed point of the operator I . Proof: Suppose that MP =< T; F >. (a) We rst prove that MP is the least xed point of I . Suppose that K is another xed point. Clearly, M0 K . Suppose that is such that M K for every < . It suces to show that M K . This is obvious if is a limit ordinal. Otherwise, = + 1 and, by monotonicity, I (M ) I (K ) and therefore M K . (b) Next, we prove that MP is consistent. Clearly, [ [ T = TM ; F = FM ; S0 = fag; P0 is empty; M2 =< fbg; fag >; S1 = fbg; P1 consists of clause (1); M3 =< fbg; fa; cg >; S2 = fcg; P2 consists of clauses (2) and (3). Moreover, M3 is the well-founded model MP of P and the last stratum S3 = fp; qg consists of all atoms unde ned in MP , P3 consists of clauses (4) and (5) and the depth (P ) of P is 3. 13
When restricted to the class of (locally) strati ed programs, dynamic strati cation is essentially the same as standard strati cations, but the two notions, in general, do not coincide. The causes of this discrepancy can be easily explained. First of all, dynamic strati cation, as opposed to standard strati cations, is uniquely de ned. Secondly, standard strati cations are determined `statically', based on the syntactical form of the program or { more precisely { on the dependency graph of the program. Therefore they do not depend in any way on the truth or falsity of the atoms appearing in the graph. This makes them very simple and natural to use, but, at the same time, limits their applicability to a relatively narrow class of programs. On the other hand, dynamic strati cation { as the name indicates { is generated `dynamically'. This means that, in the process of strati cation, irrelevant dependencies between atoms (i.e. those that can never be satis ed) are eliminated. As a result, we obtain a strati cation that may be considered preferable to the standard ones in the sense described by the following theorem. Theorem 4.1 Suppose that P is a (locally) strati ed program. Let fTg be any of its standard strati cations and let fS g be its dynamic strati cation. For every ground atom A, (A 2 S ^ A 2 T ) ) : In other words, the levels that the dynamic strati cation assigns to ground atoms are less than or equal to those assigned by standard strati cations. One can say that dynamic strati cation is the `tightest' of all strati cations. The idea of dynamic strati cation was rst introduced in [PP88]. To illustrate the phenomenon discussed above, consider the following example. Example 4.2 Let P be given by: b :a; (6) c :b; a (7) This program is strati ed and its (standard) strati cation is given by: T0 = fag, T1 = fbg, T2 = fcg. On the other hand, we have: M1 =< ;; fag > S0 = fag; M2 =< fbg; fa; cg > S1 = fb; cg: 14
Consequently, dynamic strati cation requires only two strata instead of three required by standard strati cations. This is caused by the fact that, in the process of constructing the second dynamic stratum, S1, we observe that one of the premises of the second clause, namely `a', is false. Therefore, the second clause is at this point irrelevant. Consequently, `c' does not need to be put into a higher stratum, because it does not really depend negatively on `b'. Remark 4.1 It is clear, that { if one is to ignore unde ned atoms { the dierences between standard strati cation and dynamic strati cation are caused exclusively by the existence of some (ground instances) of program clauses, which aect the dependency graph and thus in uence standard strati cations, but are irrelevant from the point of view of dynamic strati cation, because they contain some premises which are false in the well-founded model. The second clause in the previous example illustrates this point. If it were replaced by the clause: c c; a then the resulting strati ed program P 0 would be semantically equivalent to the original program P, and the (dynamic or standard) strati cation of P 0 would coincide with the dynamic strati cation of the original program P. One can show that a similar construction can be performed for an arbitrary (instantiated) saturated logic program P (i.e. a program whose wellfounded model is 2-valued), leading to a semantically equivalent strati ed program P', with the property that the dynamic strati cation of P coincides with the standard strati cation of P'. One may therefore view saturated programs as `strati ed programs in disguise', because they only `pretend' not to be strati ed, by including some irrelevant clauses which destroy their strati ability.
5 Well-Founded Model: Model De nition
Iterated Least
In this section, we show that the well-founded model, MP , of P can also be viewed as an iterated least model of P, with respect to the dynamic strati cation of P. This further illustrates the analogy with perfect models, which are iterated least models of the program (with respect to standard strati cation). 15
Let us denote by
S =
[ <
S
the union of all strata S for < and by [ P = P <
the union of all layers P for < . Thus S represents the set of all atoms whose truth value was de ned below level and P consists of all ground instances of program clauses, whose heads belong to S . Clearly, P = P+1 and HP = S+1 , where is the depth of the program. We de ne: P = P and S = S: Thus S consists of all atoms, which are either true or false in MP and P consists of clauses, whose heads belong to S . The program is saturated if and only if P = P or {equivalently { if and only if HP = S . Observe that it is possible for the 's layer P of the program to contain atoms not belonging to S+1 (i.e. atoms whose truth value has not been determined at the level or below). For instance, the layer P2 in Example 4.1 contains such an atom, namely `p'. Such a situation is not possible for (locally) strati ed programs, because any clause whose head belongs to the n'th stratum involves only atoms de ned at level n or below. In our de nition, however, we need to make an additional provision for such atoms.
Theorem 5.1 For every < , the interpretation M+1 is the least model
of the program P+1 which extends the interpretation M and gives unde ned values to all atoms not in S+1 . Moreover, the well-founded model MP is the unique model of P with the property that for every < its restriction to S+1 is the least model of the program P+1 which extends the restriction of MP to S and gives unde ned values to all atoms not in S+1 .
Example 5.1 In example 4.1, the well-founded model MP coincides with
the interpretation M3 , which is the least model of the subprogram P3 of P, consisting of clauses (1), (2) and (3), which extends M2 and assigns the unde ned value to p. 16
6 Well-Founded Model: Preference Relation De nition It is known [VGRS90] that, for (locally) strati ed programs, well-founded models coincide with (Herbrand) perfect models [ABW88, VG89b, Prz88a, Prz89b]. In particular, if the program P is positive then the well-founded model of P coincides with the least model of P. Since every (locally) strati ed program is weakly strati ed [PP88] (but not conversely), the following result is even stronger:
Theorem 6.1 [PP88] If the program P is weakly strati ed [PP88] then the well-founded model of P coincides with the weakly perfect model of P.
In this section, we will show that the well-founded model MP can in fact be de ned using the preference relation between atoms, in a manner entirely analogous to the de nition of perfect models [Prz88a, Prz89b]. However, we need to adjust the de nition to account for the fact that we are considering 3-valued models. Observe rst that, due to this fact, the characterization of least models needs to be slightly modi ed:
Proposition 6.1 M is the least model of a program P if and only if for every model N of P and for every ground atom A: if valM (A) = t then valN (A) = t ;
if valN (A) = f then valM (A) = f .
Clearly, for 2-valued models, the rst condition is sucient, because it immediately implies the second. The above conditions state that the least model of P has the smallest set of true facts and the largest set of false facts of all models of P. Following [Prz88a, Prz89b], we will now give a characterization of the well-founded model MP using the priority relation. We rst introduce the dependency graph G of the program P (cf. [ABW88, VG89b]), whose vertices are ground atoms from HP . If A and B are such atoms, then there is a directed edge in G from B to A if, and only if, there is a ground instance of a clause in P such that A occurs in its head and B in one of its premises. If this premise is negative, then the edge is called negative. For any two atoms A 17
and B in P we say that A has lower priority than B (brie y, A < B ) if there is a directed path in G leading from A to B and passing through at least one negative edge and if A belongs to a lower stratum S than B3 . We call the above de ned relation the priority relation (cf. [Prz88a, Prz89b]) between ground atoms. When using the priority relation to characterize the well-founded model, we will be guided by the following two goals: I. Our rst goal is to minimize the set of true facts among low priority atoms as much as possible, even at the cost of adding some true facts among atoms of higher priority. It follows, that if M and N are two models of P then, in order to consider the model N preferable to M, we will require that, for any atom A, the fact that A is true in N but not in M is always justi ed by the existence of some other atom B, with lower priority than A (i.e. such that B < A), which is true in M, but not in N. II. Our second goal is dual to the rst and consists in maximizing the set of false facts among low priority atoms as much as possible, even at the cost of removing some false facts from among atoms of higher priority. It follows, that if M and N are two models of P then, in order to consider the model N preferable to M, we will require that, for any atom A, the fact that A is false in M but not in N is always justi ed by the existence of some other atom B, with lower priority than A (i.e. such that B < A), which is false in N, but not in M. Combining the two goals discussed above, we arrive at the following formal de nition:
De nition 6.1 Suppose that M and N are two distinct models of a program P. We say that N is preferable to M (brie y, N M ), if for every ground atom A:
if valN (A) = t 6= valM (A) then there exists a B < A such that valM (B ) = t 6= valN (B ); The last condition is needed in view of the fact that { as discussed in Section 4 { the dynamic strati cation eliminates some static dependency graph relations. 3
18
if valM (A) = f 6= valN (A) then there exists a B < A such that valN (B ) = f 6= valM (B ).
We will call a model M preferred if there are no models preferable to M, i.e. if there are no models N such that N M . Clearly, for 2-valued models, the rst condition is sucient, since it immediately implies the second. Moreover, it is identical to the condition describing perfect models in [Prz88a, Prz89b] . The following theorem characterizes well-founded models in terms of the above preferred models. Theorem 6.2 The well-founded model MP is a preferred model of P. Moreover, MP is fully characterized as the intersection of all preferred models of P.
7 Relationship to Non-Monotonic Formalisms It has been shown, that the perfect model semantics for strati ed programs is equivalent to suitable forms of all four major formalizations of non-monotonic reasoning in AI { McCarthy's circumscription, Reiter's closed world assumption, Moore's autoepistemic logic and Reiter's default theory { thus establishing a close link between the areas of logic programming and non-monotonic reasoning (see [Prz88b]). One can use the concept of dynamic strati cation and the above characterizations of the well-founded model of P, as the iterated xed point and the iterated least model of P, together with suitable 3-valued extensions of non-monotonic formalisms, to show that an analogous result is valid for the well-founded model semantics and for arbitrary logic programs. Theorem 7.1 The well-founded model semantics for arbitrary logic programs is equivalent to suitable forms of all four major formalizations of non-monotonic reasoning in AI: McCarthy's circumscription, Reiter's closed world assumption, Moore's autoepistemic logic and Reiter's default theory. The above result not only provides a further justi cation of the wellfounded semantics, but it also establishes a large class of theories for which natural forms of all four non-monotonic formalisms coincide. Details can be found in [Prz89c]. 19
8 Well-Founded Semantics What we discussed so far is a 3-valued well-founded Herbrand model MP of the program P. Due to the `universal query problem' discussed in [Prz89b], without additional assumptions, the semantics of a logic program P cannot be based on a single Herbrand model of P. There are two natural solutions: 1. One can extend the language of the program by asserting the existence of in nitely many function symbols (see e.g. [Kun87]) or the existence of `dummy' functions (see e.g. [VGRS90]) and then consider the wellfounded semantics of the program P to be the set WF(P) of all sentences satis ed in the well-founded model MP of the so extended theory. From a semantic point of view various such assumptions are essentially equivalent, but they also share a common problem that in some applications they may not be very natural. The reason is that, knowing that p(a) holds, one may not be willing to conclude that there is an x for which not p(x) holds, because one may not wish to automatically assume the existence of objects that are not mentioned explicitly in the program (in essence, such an assumption could be interpreted as the opposite of the closed world assumption). 2. Another approach (see [Prz89b]) is to extend the de nition of the Herbrand well-founded model MP to non-Herbrand models and to de ne the semantics WF (P ) of P as the set of sentences satis ed in all wellfounded models of P. Then, knowing only that p(a) holds, the answer to the query `Does there exist an x for which not p(x) holds?' is, in general, unde ned. The results presented in the remainder of this paper are valid under both approaches. If a sentence F is in WF(P) then we will write WF (P ) j= F . A substitution will be called a correct-answer-substitution for a formula F if WF (P ) j= 8(F). One can show [VGRS90] that the well-founded model semantics is strictly stronger than the semantics based on Clark's completion of the program (see [Cla78, Llo84, Fit85, Kun87]).
20
9 Procedural Semantics: SLS-Resolution In this section we use dynamic strati cation de ned in Section 4 to extend the SLS-resolution (Linear resolution with Selection function for Strati ed programs) [Prz89b] from the class of all strati ed programs to the class of all logic programs and we show that SLS-resolution is sound and complete (for non- oundering queries) w.r.t. the well-founded model semantics. The only essential dierence between the extended SLS-resolution and the one de ned in [Prz89b] is its ability to handle unde ned answers. Independently, [Ros89] proposed a similar extension of SLS-resolution and proved its soundness and completeness. Observe that in view of the equivalence of non-monotonic formalisms to the well-founded semantics (see Section 7), the extended SLS-resolution can also be used as an inference engine to compute (suitable forms of) circumscription, autoepistemic logic, CWA and default theory for logic programs. Suppose that P is a logic program, HP is its Herbrand base and fSg is the dynamic strati cation of HP , with = depth(P). For any ground atom A let stratum(A) = , where is the unique ordinal number such that A belongs to S . In general, for any atom A let
stratum(A) = supfstratum(A) : is a ground substitutiong and let stratum(:A) = minf; stratum(A) + 1g. Recall that a goal G is a headless clause L1 ,..., Lk , where k0 and Li's are literals. We also write, G = Q, where Q = L1 ,..., Lk is a query. We often use goals and queries interchangeably. We de ne stratum(G) as follows: ( 0; if G is empty; stratum(G) = max fstratum(Li ) : i = 1; :::; kg; otherwise. For example, if G = A; :B and stratum(A)=stratum(B)=2, then stratum(G)=3. From now on we assume that R is any xed positively safe computation rule, i.e. a rule that selects { whenever possible { exactly one literal from any goal, so that negative literals are selected only if they are ground and if no positive literals are available. Now we are ready to de ne SLS-resolution. 21
De nition 9.1 (De nition of SLS-trees) By induction on the stratum of
G, we de ne the notions of an SLS-tree, a success leaf, a failure leaf, a
ounder leaf and an unde ned leaf for a given program P and goal G. If stratum(G)=0, then G is an empty clause and its SLS-tree T consists of only one node, namely G itself. Its only leaf is a success leaf. Assume now that stratum(G) = , > 0, and that SLS-trees have already been de ned for goals G0, for which stratum(G0 ) < . We de ne the SLS-tree T for G. The root node of T is G. If H is any node of T then its immediate descendents (successors) are obtained as follows:
if H is empty, then H has no immediate descendents and is a success leaf;
if the literal l selected by R from H is positive, then the immediate descendents of H are all goals K that can be obtained from the goal H by resolving H with (a variant of) one of the program clauses upon the literal l using most general uni ers; if there are no such K's, then H has no immediate descendents and is a failure leaf;
otherwise, the goal H contains only negative subgoals and we try to use the computation rule R to select the rst negative subgoal :A such that A is a ground atom and stratum(A) < ;
{ if we succeed, then the SLS-tree T 0 for the goal
A was already de ned and we consider three cases: if all leaves of T 0 are failed, then the only immediate descendent of H is H ? f:Ag, i.e. the goal H with :A removed; else, if T 0 contains a success leaf, then H has no immediate descendents and is a failure leaf; else, H has no immediate descendents and is a ounder leaf; { else, if at least one of the negative subgoals is non-ground, then H has no immediate descendents and is a ounder leaf; { else, H has no immediate descendents and is an unde ned leaf. 2
We now make the following de nitions. 22
De nition 9.2 (De nition of SLS-resolution) An SLS-tree is successful
if it has a success leaf, i.e. an empty node 2. An SLS-tree is oundered if it has a ounder leaf. An SLS-tree is failed if all of its leaves are failed (equivalently, if all of its branches are in nite or end with a failure leaf). An SLS-tree is unde ned if it is neither successful, nor oundered nor failed. A branch beginning at the root and ending with a success leaf is a successful branch and is also called an SLS-refutation of G. The substitution obtained as a composition of the corresponding most general uni ers for a successful branch is called an SLS-answer-substitution for G. Any partial branch of the SLS-tree beginning at the root is called an SLS-derivation from G. The process of constructing SLS-derivations is called SLS-resolution. A branch is called failed if it is either in nite or ends with a failure leaf. A branch ending with a ounder leaf is called oundered. A goal G is oundered (resp. unde ned) if its SLS-tree is oundered (resp. unde ned) and if G = Q, where Q is a query, then we say that the query Q is oundered (unde ned). We say that a substitution is more general than a substitution if there exists a substitution such that = . 2
Every leaf of an SLS-tree is either a success leaf or a failure leaf or a
ounder leaf or an unde ned leaf, and therefore every SLS-tree is either successful or oundered or failed or unde ned. An SLS-tree is failed i all of its branches are failed. Notice that an SLS-tree can be both successful and
oundered, but a failed tree is neither successful nor oundered. Also, an unde ned tree is neither successful nor failed nor oundered. Observe, that since all the negative subgoals in SLS-resolution must be ground, they do not have any eect upon answer substitutions.
Remark 9.1 Although the requirement `stratum(A) < ' used in the de -
nition of SLS-resolution appears { on the face of it { to be very non-eective (how are we supposed to know the strati cation level of A?), in practice it translates into an eectively veri able requirement: `no negative recursion is allowed in the derivation'. This is because, :A always belongs to a higher stratum than A itself (except when A is unde ned). Thus, although the program's dependency graph may contain negative cycles, indicating potential negative recursion, no actual negative recursion is allowed in the proof. This observation further con rms the remark made in Section 4 asserting that saturated programs (i.e. programs having a 2-valued well-founded 23
model) are in essence `strati ed programs in disguise': negative recursions in such programs { even if present { are never actually used in derivations. We illustrate the above remark with the following example.
Example 9.1 Consider the following program: a :b; :c b :a c
and the query a. Selecting rst the leftmost negative literal :b, leads to the goal :a, thus resulting in a negative recursion from `a' to `:a'. Consequently, this branch is abandoned and the second negative literal :c is tried. Since it immediately fails, the goal a also fails. Our rst theorem, showing that for non- oundered existential queries (and for their negations) the well-founded model semantics WF(P) of P is equivalent to the semantics generated by the unique Herbrand well-founded model MP of P, is obviously meaningful only in the case when the wellfounded semantics WF(P) is de ned using the second approach described in Section 8.
Theorem 9.1 Suppose that P is a logic program, R is any positively safe computation rule and Q is a non- oundered query. Then
WF (P ) j= 9(Q) () MP j= 9(Q): WF (P ) j= :9(Q) () MP j= :9(Q): The above result is important, because it con rms that, as far as existential queries are concerned, using all well-founded models or just the Herbrand well-founded model MP of P produces exactly the same results, as long as the query is not oundered. However, because of the universal query problem [Prz89b], analogous results are in general false for universal queries. As in [Prz89b], one can show that the assumption that Q is non- oundered is essential. The following two theorems prove that SLS-resolution: 24
is always sound with respect to the well-founded model semantics; is complete for goals, which are not oundered. Since, when using resolution, it is generally not possible to properly handle non-ground negative literals, the last result is in a sense the most we could expect (see [Cha88, Prz89a], however, for a discussion of constructive negation). Notice also, that because of the universal query problem, an analogous completeness result is in general not valid for the semantics based on the Herbrand well-founded model MP [Prz89b].
Theorem 9.2 (Soundness of SLS-resolution) Suppose that P is a logic program, R is a positively safe computation rule and Q is a query. Then
(i) If is any SLS-answer-substitution for Q, then WF (P ) j= 8(Q) (i.e. is a correct-answer-substitution for Q) and { in particular { WF (P ) j= 9(Q); (ii) If the SLS-tree for Q is failed, then WF(P) j= :9(Q) ; (iii) If the SLS-tree for Q is unde ned, then WF (P ) 6j= 9(Q) and WF (P ) 6j= :9(Q), i.e. the status of the query Q is unde ned. Theorem 9.3 (Soundness and Completeness of SLS-resolution) Suppose that P is a logic program, R is a positively safe computation rule and Q is a non- oundered query. Then: (i) WF (P ) j= 9(Q) i there exists an SLS-answer-substitution for Q; (ii) WF (P ) j= :9(Q) i SLS-tree for Q is failed. (iii) WF (P ) j= 8(Q) (i.e. is a correct-answer-substitution for Q) i there exists an SLS-answer-substitution for Q more general than ; (iv) WF (P ) 6j= 9(Q) and WF(P) 6j= :9(Q) (i.e. the status of the query Q is unde ned) i SLS-tree for Q is unde ned.
25
As shown in [Prz89b], the assumption that Q is non- oundered is essential. We can also show that SLS-resolution is strictly more powerful than SLDNF-resolution as de ned in [Llo84]. This is closely related to the fact that well-founded semantics is strictly stronger than the semantics based on Clark's completion of the program. Theorem 9.4 Suppose that P is a logic program, R is a positively safe computation rule and Q is a query. (i) If is an SLDNF-answer substitution for Q, then is also an SLSanswer substitution for Q; (ii) If the SLDNF-tree for Q is nite and failed, then the SLS-tree for Q is also nite and failed. In particular, SLDNF-resolution is always sound with respect to the wellfounded model semantics. Soundness and completeness of the extended SLS-resolution with respect to the well-founded model semantics suggests that SLS-resolution can be considered as a theoretical construct, describing an `ideal' sound and complete query answering procedure for general logic programs under the wellfounded semantics. On the other hand, as it was the case with standard SLS-resolution [KT88, SI88], the extended SLS-resolution can be eectively implemented for large classes of programs, thus constituting a practical query answering mechanism. The details of such an eective procedure are beyond the scope of this paper, but, somewhat simplifying, one can say, that loop checking will be used to cut in nite branches and negative recursion checking will be used to eliminate unde ned branches.
Acknowledgments The author is grateful to Allen Van Gelder, Vladimir Lifschitz and Ken Ross for their helpful comments.
References [ABW88] K. Apt, H. Blair, and A. Walker. Towards a theory of declarative knowledge. In J. Minker, editor, Foundations of Deductive Databases and Logic Programming, pages 89{142. Morgan Kaufmann, Los Altos, CA., 1988. 26
[Bry89]
[CH85] [Cha88]
[Cla78] [Fit85] [GL88]
[KT88]
[Kun87] [Llo84] [PP88]
F. Bry. Logic programming as constructivism: A formalization and its application to databases. In Proceedings of the Symposium on Principles of Database Systems, pages 34{50. ACM SIGACTSIGMOD, 1989. A. Chandra and D. Harel. Horn clause queries and generalizations. Journal of Logic Programming, 1:1{15, 1985. D. Chan. Constructive negation based on the completed database. In R. Kowalski and K. Bowen, editors, Proceedings of the Fifth Logic Programming Symposium, pages 111{125, Cambridge, Mass., 1988. Association for Logic Programming, MIT Press. K.L. Clark. Negation as failure. In H. Gallaire and J. Minker, editors, Logic and Data Bases, pages 293{322. Plenum Press, New York, 1978. M. Fitting. A Kripke-Kleene semantics for logic programs. Journal of Logic Programming, 2(4):295{312, 1985. M. Gelfond and V. Lifschitz. The stable model semantics for logic programming. In R. Kowalski and K. Bowen, editors, Proceedings of the Fifth Logic Programming Symposium, pages 1070{ 1080, Cambridge, Mass., 1988. Association for Logic Programming, MIT Press. D. Kemp and R. Topor. Completeness of a top-down query evaluation procedure for strati ed databases. In R. Kowalski and K. Bowen, editors, Proceedings of the Fifth Logic Programming Symposium, pages 178{194, Cambridge, Mass., 1988. Association for Logic Programming, MIT Press. K. Kunen. Negation in logic programming. Journal of Logic Programming, 4(4):289{308, 1987. J.W. Lloyd. Foundations of Logic Programming. Springer Verlag, New York, N.Y., rst edition, 1984. H. Przymusinska and T. C. Przymusinski. Weakly perfect model semantics for logic programs. In R. Kowalski and K. Bowen, 27
[Prz88a]
[Prz88b]
[Prz89a]
[Prz89b] [Prz89c]
[Ros89]
editors, Proceedings of the Fifth Logic Programming Symposium, pages 1106{1122, Cambridge, Mass., 1988. Association for Logic Programming, MIT Press. T. C. Przymusinski. On the declarative semantics of strati ed deductive databases and logic programs. In J. Minker, editor, Foundations of Deductive Databases and Logic Programming, pages 193{216. Morgan Kaufmann, Los Altos, CA., 1988. T. C. Przymusinski. On the relationship between non-monotonic reasoning and logic programming. In Proceedings AAAI-88, pages 444{448, Los Altos, CA, 1988. American Association for Arti cial Intelligence, Morgan Kaufmann. [The full version appeared in: T. C. Przymusinski. Non-Monotonic Reasoning vs. Logic Programming: A New Perspective. In The Foundations of Arti cial Intelligence. A Sourcebook, D. Partridge and Y. Wilks, editors, Cambridge University Press, London, 1990, 49-71.]. T. C. Przymusinski. On constructive negation in logic programming. In Proceedings of the North American Logic Programming Conference, Cleveland, Ohio, October 1989, page (Addendum to the Volume.), Cambridge, Mass., 1989. Association for Logic Programming, MIT Press. T. C. Przymusinski. On the declarative and procedural semantics of logic programs. Journal of Automated Reasoning, 5:167{205, 1989. T. C. Przymusinski. Three-valued non-monotonic formalisms and logic programming. In R. Brachman, H. Leveque, and R. Reiter, editors, Proceedings of the First International Conference on Principles of Knowledge Representation and Reasoning (KR'89), Toronto, Canada, pages 341{348. Morgan Kaufmann, 1989. K. Ross. A procedural semantics for well founded negation in logic programs. In Proceedings of the Eighth Symposium on Principles of Database Systems, pages 22{33. ACM SIGACT-SIGMOD, 1989. 28
[SI88]
H. Seki and H. Itoh. A query evaluation method for strati ed programs under the extended cwa. In R. Kowalski and K. Bowen, editors, Proceedings of the Fifth Logic Programming Symposium, pages 195{211, Cambridge, Mass., 1988. Association for Logic Programming, MIT Press. [VG89a] A. Van Gelder. The alternating xpoint of logic programs with negation. In Proceedings of the Symposium on Principles of Database Systems, pages 1{10. ACM SIGACT-SIGMOD, 1989. [VG89b] A. Van Gelder. Negation as failure using tight derivations for general logic programs. Journal of Logic Programming, 6(1):109{ 133, 1989. Preliminary versions appeared in Third IEEE Symposium Logic Programming (1986), and Foundations of Deductive Databases and Logic Programming, J. Minker, ed., Morgan Kaufmann, 1988. [VGRS90] A. Van Gelder, K. A. Ross, and J. S. Schlipf. The well-founded semantics for general logic programs. Journal of the ACM, 1990. (to appear). Preliminary abstract appeared in Seventh ACM Symposium on Principles of Database Systems, March 1988, pp. 221{ 230. [Zan88] C. Zaniolo. Design and implementation of logic-based language for data intensive applications. In R. Kowalski and K. Bowen, editors, Proceedings of the Fifth Logic Programming Symposium, pages 1666{1688, Cambridge, Mass., 1988. Association for Logic Programming, MIT Press.
29