Processing Negation and Disjunction in Logic Programs ... - CiteSeerX

0 downloads 0 Views 232KB Size Report
Mar 4, 1994 - Integrity constraints on a database contain semantic information about the ... all allowed states of the database, the answers for the negative ...
Processing Negation and Disjunction in Logic Programs Through Integrity Constraints Terry Gaasterland Mathematics and Computer Science Division, Argonne National Laboratory, [email protected] Jorge Lobo Department of Electrical Engineering and Computer Science, University of Illinois at Chicago, [email protected] March 4, 1994 Abstract

Integrity constraints were initially de ned to verify the correctness of the data that is stored in a database. They were used to restrict the modi cations that can be applied to a database. However, there are many other applications in which integrity constraints can play an important role. For example, the semantic query optimization method developed by Chakravarthy, Grant, and Minker for de nite deductive databases uses integrity constraints during query processing to prevent the exploration of search space that is bound to fail. In this paper, we generalize the semantic query optimization method to apply to negated atoms. The generalized method is referred to as semantic compilation. This exploration has led to two signi cant results. First, semantic compilation provides an alternative search space for negative query literals. The alternative search space can nd answers in cases for which negationas- nite-failure and constructive negation cannot. Second, we show how semantic compilation can be used to transform a disjunctive database with or without functions and denial constraints without negation into a new disjunctive database that complies with the integrity constraints.

Keywords: Integrity constraints, semantic compilation, negation, disjunctive logic programs.

1

1 Introduction Integrity constraints on a database contain semantic information about the database that cannot be derived directly from the contents of the database. Integrity constraints were initially de ned to verify the correctness of the data that is stored in a database. They describe states that must be true in the database, and any modi cations to the database must leave the database in a state consistent with the integrity constraints. However, there are many other applications in which integrity constraints can play an important role. For example, before expanding a database query, it is possible to incorporate the integrity constraints into the query to obtain a semantically equivalent query. The new query contains constraint information that prevents the exploration of search space that is bound to fail. In Chakravarthy et al. (1990), a semantic query optimization method is described that compiles integrity constraints into queries based on common positive literals that occur in both the constraint and the query. Database rules are optimized at compile time in order to minimize the amount of computation that must be done at run time. If queries are known at compile time, the entire query can be optimized. Otherwise, any remaining optimization is done at run time. Based on the same principles, integrity constraints can be also used to generate cooperative and informative answers and model user needs (see Minker and Gal (1990), Gaasterland (1992)). In this paper, we generalize the semantic query optimization method to apply to negated atoms. The generalized method is referred to as semantic compilation. This exploration has led to two signi cant results. The rst result a ords a new method to process negative query literals. Semantic compilation provides an alternative search space for negative query literals. Traversing the alternative search space can nd answers in cases for which negation-as- nite-failure and constructive negation may not. To use the negation-as- nite-failure method to expand a negative query literal, the negative literal must be ground, and the search space of the positive ground atom must be nite. To use constructive negation e ectively, the literal does not need to be ground but the search space must still be nite. Semantic compilation with negation as described in this paper allows correct answers to be found for negative literals that are neither ground nor nite. However, unless the integrity constraints completely describe all allowed states of the database, the answers for the negative literal may not be complete. The second result applies to disjunctive deductive databases. Fernandez and Minker (1991) noticed that there are many situations that can be represented directly with a set of disjunctive statements and a set of constraints that restrict the statements. Fernandez et al. (1993) used this observation to describe the stable model semantics in terms of disjunctive databases without negation. To answer queries over such databases Fernandez and Minker generate the minimal models of the database and use the constraints to select the models that give the 2

semantics of the database. Their algorithms work for strati ed, function-free databases. In this paper, we show how for positive disjunctive deductive databases with or without functions and denial constraints without negation, semantic compilation can be adapted to avoid the construction of the minimal models. The compilation transforms the disjunctive logic program into a new disjunctive logic program that complies with the integrity constraints. Other advantages of this approach are that minimal models do not have to be nite, and we can use any proof procedure for disjunctive logic programs to evaluate queries. The next section gives background de nitions. Section 3 describes and analyzes the method for handling negative literals with semantic compilation. Section 4 describes the compilation of constraints into disjunctive logic programs.

2 Background This section provides basic de nitions and a description of the semantic compilation method for positive literals de ned by Chakravarthy et al. (1990) (see also Chakravarthy (1985)).

2.1 De nitions

Deductive databases are comprised of syntactic information and semantic information. The syntactic information consists of an intensional database (IDB) which is a set of clauses (or rules) of the form A1 Am B1 ; : : :; Bn, m; n > 0, where each Ai is an atom and each Bi is a literal (i.e. an atom or its negation), and the extensional database (EDB) which is the set of clauses of the form A1 Am . IDB clauses are also called rules. EDB clauses are also called facts. If all the Bi s in the IDB rules are positive literals and m = 1, then the deductive database is called de nite. If m is larger than 1 in at least one of the clauses, the database is called disjunctive. A pair of literals is said to be a pair of complementary literals if one is an atom and the other a negated atom. The semantic information about the database consists of a set of integrity constraints (IC). The constraints considered in this paper have the form C1, : : :, Cn , E1 , : : :, Em where each Ci is a literal whose predicate appears in an EDB fact or the head of an IDB rule and each Ei is an evaluable expression. An integrity constraint restricts the states that a database can take. For example, the integrity constraint \No person can be both male and female," person(X),male(X),female(X), restricts people in a database from having both properties. Because the constraints on a database do not enable the deduction of new answers but rather give information about existing knowledge and answers, they are considered semantic information rather than syntactic information. Integrity constraints can be compiled into a query to identify space that is bound to fail. The next section describes a semantic query optimization _  _

__

3

algorithm de ned by Chakravarthy et al. (1990) for compiling constraints into queries and rules.

2.2 Semantic Query Optimization Using Positive Atoms

For semantic optimization of deductive database queries as de ned by Chakravarthy, Grant, and Minker, the EDB and IDB contain function-free de nite clauses, and the IC is a nite set of rst order clauses that always hold in the theory EDB IDB. It is assumed that the set IC contains constraints that can be derived from other constraints in IC. The semantic optimization process performs two preliminary steps: attening of the IDB clauses so that all IDB clause bodies contain only EDB predicates or recursive predicates and variable substitution of the IC clauses. Flattening is performed according to Reiter (1978) and consists of a series of unfoldings of the rules in the IDB. A program with direct recursion can be attened by

attening the nonrecursive predicates in the recursive rules before merging the rules with the constraints Gaasterland et al. (1993). Partial attening can be done in rules with nondirect recursion by inspecting the dependency graph associated with the rules Gaasterland et al. (1993). Without loss of generality, but possibly with some loss of potential query processing eciency at run time, the attening process does not have to be complete. Moreover, the negative literals are not attened. [

Background de nition: Variable substitution

A variable substituted form of an integrity constraint is a clause obtained by 1. Replacing each distinct constant in the constraint by a distinct variable and adding the fact that the constant equals the variable. 2. Replacing each variable that occurs more than once by new distinct variables, and adding equalities that represent the bindings. For example, consider the constraint trade(usa,Z),trade(Z,iraq) meaning \the

USA does not trade with any entity that trades with Iraq." The variable substituted form of the integrity constraint is trade(A,B), trade(Z,C), A = usa, C = iraq, B = Z. Notice that the variable substituted form of the constraint places the nonevaluable literal trade in a most general form. After preprocessing the IDB and the IC using variable substitution, the next step in semantic optimization is to nd all partial constraints that apply to each IDB clause. A residue is obtained by determining whether part of some clause in IC partially subsumes an IDB clause. If so, then the remaining part of the IC clause becomes a residue that constrains the IDB clause { the residue expresses something that must be true when the clause is true. The general form of the integrity constraints that was produced by variable substitution allows us to nd all possible residues. 4

Background de nition: Partial subsumption

A (variable substituted) integrity constraint I partially subsumes a rule A if a subset of I subsumes A but I does not subsume A. An integrity constraint I = C1; : : :; Cn partially subsumes a rule R = A

B1 ; B2; : : :; Bm , if and only if there exists a nonempty subset S of C1; : : :; Cn and a substitution  such that S B1 ; : : :; Bm . f

 f

g

g

Background de nition: Residue

If Ci1 ; : : :; Ci are the literals in the constraint that are not in S, then the clause (Ci1 ; : : :; Ci ) is the residue obtained from R and I . k

k

Once a set of residues is found for an IDB clause, each residue may be incorporated into the clause. Attaching the residue to the IDB clause produces a semantically equivalent clause.

Background de nition: Semantically constrained rules

A semantically constrained rule is de ned to be of the form A B1 ; : : :; Bm , fR1; : : :; Rng. Here A is the procedure head of the rule, each literal Bi is either a regular literal or an evaluable predicate, and the Rj s are residues obtained from the rule A B1 ; : : :; Bm and the integrity constraints.

Background de nition: Semantically constrained database

Let D be a de nite database and let E, I, and C be the EDB, IDB, and ICs that form D. The semantically constrained database of D, D0 , is the set of semantically constrained rules obtained from D.

Consider a database consisting of two IDB clauses:

economic ties(C1,C2) trade(C1,Z), trade(Z,C2). trade(C1,C2) friends(C1,C2).

meaning \C1 has economic ties with C2 if C1 trades with some Z that trades with C2" and \C1 trades with C2 if C1 is friends with C2." The variable substituted integrity constraint above partially subsumes the rst IDB clause to produce the residue C1=usa, C2=iraq . A new semantically constrained clause is produced when the residue is merged with the IDB clause f

economic ties(C1,C2)

g

trade(C1,Z), trade(Z,C2), f C1=usa, C2=iraqg.

The constrained axiom says that it is not possible for the countries C1 and C2 to have economic ties if C1 is usa and C2 is iraq. The semantically constrained database consists of the semantically constrained clauses together with the EDB facts and the integrity constraint above.1 1 See Lobo and Minker (1988), Gaasterland et al. (1993) for algorithms to construct semantically constrained databases. In Gaasterland et al. (1993), experiments show that for useful classes of deductive database applications, the semantic optimization process signi cantly improves performance.

5

3 Handling Negative Literals

The semantic optimization method of Chakravarthy et al. (1990) described in the preceding section augments queries and rules in de nite deductive databases with semantic information about the search space of positive atoms in a query or the rules when those atoms occur positively in the body of one or more integrity constraints. In this section, we generalize the approach so that it provides semantic information about the search space of negative as well as positive literals in the query. The generalized method handles all cases in which literals with the same predicate occur positively or negatively in one or more constraints. Semantic information can be obtained in four cases: 1. When a predicate symbol of a positive constraint literal appears in a positive literal in the query or the rules. 2. When a predicate symbol of a negative constraint literal appears in a negative literal in the query or the rules. 3. When a predicate symbol of a negative constraint literal appears in a positive literal in the query or the rules. 4. When a predicate symbol of a positive constraint literal appears in a negative literal in the query or the rules. Case 1 is covered by Chakravarthy, Grant and Minker and forms the basis for the treatment of Cases 2, 3 and 4. Case 2 can be treated like Case 1 by temporarily renaming the negated predicates as unique new positive predicates and applying semantic compilation as in case 1. Case 3 reduces to using the integrity constraint as a deductive rule and is not particularly interesting. Case 4 is the most interesting: semantic compilation with negation provides a means to nd answers for queries that contain possibly nonground negative literals, in which case regular procedures such as SLDNF-resolution do not apply, and/or possibly an in nite number of answers, in which case approaches such as constructive negation (see Chan (1988) and Przymusinski (1989)b) cannot be used. The remainder of this section de nes the generalized semantic compilation algorithm and gives examples to illustrate its utility. Section 3.1 describes an addition to the partial subsumption algorithm that nds partial constraints for complementary query and constraint literals as in Cases 3 and 4. Section 3.2 shows two practical situations in which semantically compiling a program with negation produces a new program that is either more ecient or nds answers that could not be found with the original program. Section 3.3 contains the theorem that shows that the alternative answers obtained for queries with negative literals are correct. Section 3.4 compares the generalized semantic compilation to constructive negation and negation-as- nite-failure. Finally, Section 3.5 addresses some observations that Chakravarthy (1985) made about using the original semantic query optimization method to glean information about the 6

search space of negative query literals. Section 3.5 also describes the renaming process that allows the semantic query optimization method to handle Case 2.

3.1 Algorithm for Generalized Semantic Compilation

Semantically compiling a set of integrity constraints with a database rule or query has two main steps: (1) obtaining partial constraints, and (2) integrating the partial constraints into the body of the query or rule. A query may be regarded as a rule of the form Query Q1, : : : , Qn. From now on, we will refer to both queries and rules as axioms. To compile an integrity constraint into an axiom based on the correspondence of a positive or negative axiom literal and a positive or negative integrity constraint literal, we de ne mixed partial subsumption for nding partial constraints. The term mixed refers to the fact that the correlation is done on two complementary literals, one from the constraint and one from the axiom. Since the residues produced by mixed partial subsumption contain a di erent type of information from the constraints found by regular partial subsumption, we call them mixed residues. We also de ne a merging algorithm that replaces the axiom literal with the disjunction of its mixed partial constraints.

De nition 1. Mixed partial subsumption

The mixed partial subsumption of an axiom R = A B1 ; B2; : : :; Bm , by an integrity constraint I = C1; : : :; Cn, can occur if and only if there exist a Bi and a Cj such that 1. Bi and Cj are complementary literals. 2. There is a substitution  such that Cj   :Bi . The clause ( C1, : : : , Cj ?1, Cj +1, : : : , Cn), is the mixed residue obtained from R and I .

The integrity constraint C1; : : :; Cn can be interpreted to say that it is not the case that C1 , and C2 , : : :, and Cn are simultaneously true in the database. In particular, if the constraint is restricted with the substitution , it is not the case that the conjunction C1 Cn is true in the database. Hence, if the conjunction C1 Cj ?1 Cj +1 Cn is true, then it is not possible for Cj  to be true. Since in deductive databases negation is interpreted as negation-as-failure, this is equivalent to saying that Cj  is true. In other words, we can rewrite the constraint to be ( Cj  C1, : : :, Cj ?1, Cj +1, : : :, Cn). But notice that Cj  Bi . Therefore, we have (Bi C1, : : :, Cj ?1, Cj +1, : : :, Cn). The mixed residue obtained through mixed partial subsumption de nes a search space that is an alternative to the search space of Bi . This new implication deduced from the semantic information motivates the following de nition of merging a rule with an integrity constraint. ^ ^

^^

^

^^

:

:

:



De nition 2. Mixed merging

To merge the mixed residue (C1,: : : ,Cj ?1,Cj +1,: : : ,Cn) with the rule R, replace

7

the rule by the new rule A B1 ; B2, : : : , Bi?1, C1,: : : ,Cj ?1,Cj +1 ,: : : ,Cn, Bi+1 ,: : : ,Bm .

Algorithm 1. Semantic Compilation with Negations

Let DB be an initial deductive database. Let DB contain only the EDB of DB. Then, 1. For each integrity constraint in the database, use mixed partial subsumption to nd all mixed residues between the integrity constraint and the axiom. 2. For each literal in the axiom that has a corresponding mixed residue, use mixed merging to replace the literal with the mixed residue. 3. For each integrity constraint in the database, use partial subsumption to nd residues for the new axiom and the original attened axiom in DB. 4. Add all regular residues to the new axiom and the original axiom using the usual merge de nition. Add the new axioms to DB . DB contains the new semantically compiled database. 0

0

0

This algorithm performs semantic compilation for cases 1, 3, and 4 above. In the next section, we give two examples of how the algorithm can be used. In Section 3.3, a proof of correctness shows that the new database is semantically equivalent to the original database.

3.2 Two Examples

Handling negation by semantically compiling constraint information into the query is useful in two very di erent scenarios.

3.2.1 Example 1

The program below describes two disjoint groups of points connected by edges (i.e., two distinct connected components of the graph). The disjointness can be described by an integrity constraint. The predicate reachable computes all ordered pairs that are connected by an edge. The predicate unreachable has a search tree with a cycle on reachable. IC1 is sucient to describe the disjoint edge groups. The program consists of the following clauses: % group 1: edge(a,b). edge(b,a).

% group 2: edge(c,d). edge(d,c).

8

reachable(X,Y) edge(X,Y). reachable(X,Y) reachable(X,Z),edge(Z,Y). unreachable(X,Y) :reachable(X,Y). IC1: reachable(a,W1),reachable(c,W1).

Variable substitution of the integrity constraint produces a new form of the constraint: VS IC1: reachable(A,W1),reachable(C,W2), A=a,C=c,W1=W2. Mixed partial subsumption of IC1 with the recursive rule for unreachable produces the following set of residues: f

reachable(C,X2),X=a,C=c,Y=X2. reachable(A,X1),X=c,A=a,Y=X1. g

Merging the residues with the rule produces the following new rule: unreachable(X,Y) ((:reachable(X,Y)) _ (reachable(C,X2),X=a,C=c,Y=X2) _ (reachable(A,X1),A=a,X=c,Y=X1)).

Unfolding the semantically compiled rule gives three new rules: R1: unreachable(X,Y) R2: unreachable(X,Y) R3: unreachable(X,Y)

:reachable(X,Y). reachable(C,X2),X=a,C=c,Y=X2. reachable(A,X1),X=c,A=a,Y=X1.

R2 and R3 can be reduced to R20: unreachable(a,Y) R30: unreachable(c,Y)

reachable(c,Y). reachable(a,Y).

From R1, which contains a negative literal, the query unreachable(X; Y ) cannot be answered using a procedure such as SLDNF-resolution since the unground query reachable(X; Y ) has to be solved. One possibility is to extend the proof procedure with constructive negation. However, to use constructive negation, one must carefully extend SLDNF-resolution to incorporate constructive answers. Even though there is a nite number of answers for the query reachable(X; Y ), a simple application of SLD-resolution to obtain the answers will result in an in nite computation. However, with R20 and R30, pro:

9

duced by Algorithm 1, two answer substitutions can be computed: X/a,Y/d and X/a,Y/c . Moreover, suppose the integrity constraint f

f

g

g

IC10 = reachable(a; W1); reachable(c; W2); reachable(W1; W2). is also added to the database. Then, after the compilation, the following two rules are generated: R4: unreachable(X,Y) R5: unreachable(Y,X)

reachable(a,X),reachable(c,Y). reachable(a,X),reachable(c,Y).

From these two rules the rest of the answers for unreachable(X,Y) are obtained. We will discuss constructive negation in more detail later in the paper.

3.2.2 Example 2

Consider the following deductive database with function symbols: even(0). even(s(X))

even(X).

:

This two rule deductive database has an in nite Herbrand base. If the query even(X) is asked, SLDNF-resolution returns only one answer 0=X and then stops. Constructive negation is unable to answer since the query has an in nite number of solutions. Suppose the following integrity constraint f

g

even(X),even(s(X)).

is added to the database. Then, after the compilation with Algorithm 1, we obtain the following new rule: even(s(s(X)))

even(X).

With the new rule all the other answers for even are obtained by using SLDresolution.

3.3 Proof of Correctness

Every answer that is obtained in the new database can also be obtained in the old database and vice versa. This result is formally written in Theorem 1.

Theorem 1. Let the tuple DB = (IDB,EDB,IC) be a deductive database. Let DB = (IDB ,EDB,IC) be the database obtained after applying Algorithm 1. Let 0

0

10

Q be a query. A substitution  is a correct answer substitution for DB Q if and only if  is a correct answer substitution for DB Q . Proof: Since IDB is a subset of IDB , one direction of the \if and only if" is direct. To prove the other direction, we can show that each new rule in IDB is a logical consequence of DB. Let A B1 ; B2 , : : :, Bi?1, C1, : : : , Cj ?1, Cj +1, : : : , Cn, Bi+1 , : : : , Bm be a rule in IDB not in IDB. Then, by the compilation algorithm, there exists a rule R = A B1 ; B2; : : :; Bm in IDB and an integrity constraint I = C1; : : :; Cn such that Bi and Cj are complementary literals and Cj  Bi . Therefore, resolving R with I we obtain precisely A B1 ; B2, : : :, Bi?1 , Cj +1,: : :,Cn,Bi+1 ,: : :,Bm . Hence, by soundness of resolution we have R; I = A B1 ; B2, : : :, Bi?1 , Cj +1,: : :,Cn,Bi+1 ,: : :,Bm . Then DB = A B1 ; B2, : : :, Bi?1 , Cj +1,: : :,Cn,Bi+1 ,: : :,Bm . 2 0

0

[ f

[ f

g

g

0

0

 :

f

g j

j

3.4 Comparison with Constructive Negation

When a query contains a negative literal, there are several procedural methods for expanding the search space of the negative literal. Take, for example, negation-as- nite-failure (NAFF). NAFF, used in SLDNF-resolution, expands the entire search tree for the positive atom that occurs in the literal. If the entire tree fails nitely, then the negated atom can be considered to be true. However, NAFF requires the negative literal to be ground in order to ensure soundness. It also requires the positive atom's SLDNF search tree to be nite in order to ensure termination. To obtain soundness and completeness, one must impose additional restrictions on the syntactic structure of the program. The restrictions of groundedness and nite search are present in almost all of the di erent procedural interpretations of logic programs that use negation. Even in \ideal" procedures where niteness is not required, the restriction on ground negative literals is still imposed Ross (1989), Przymusinski (1989)a. To partially overcome this inconvenience, Chan (1988) developed the concept of constructive negation. He proposed to represent answers by formulas involving the equality predicate only, instead of the traditional method of answer substitutions. These restricted formulas are called equality formulas. To illustrate the underlying idea behind constructive negation, let us assume that we have the logic program P = p(X) q(X); q(X) r(X); r(a); r(b) . We know that q(X) is true either when X is equal to a or X is equal to b. Then, possible answers for the query q(X) may be the equality formula X = a or the equality formula X = b or the disjunctive equality formula (X = a X = b). In general, given a (positive) logic program P and a query Q(X1 ; : : :; Xm ), a correct answer substitution  for Q can be transformed to the following equality formula: E = (X1 = X1  Xm = Xm ) which indicates that P = (E Q). The equality formula E is called a f

:

g

_

^^

j

8

)

11

partial answer for Q. If we consider the semantics associated with a logic program, which di ers from the traditional semantics associated with rst-order theories, the de nition of partial answers can be strengthened to de ne complete or full answers. A full answer for a query, Q, is an equality formula EQ such that EQ satis es the condition: P =S (EQ Q), where is the logic programming semantics associated with P (for example, could be the minimal model semantics or the completion semantics of Clark). This equivalence permits negative queries to be answered with equality formulas since we can write that P =S ( EQ Q). In the program P above, p(X) will be true whenever q(X) is false. Using the negation-as- nite-failure rule of Clark (1978), we are able to conclude that q(X) is false if X is bound to a term not equal to a and not equal to b. From this information, we conclude that a possible answer for p(X) may be the equality formula X = a X = b. As a result, for normal logic programs, partial and full answers can also involve inequalities as in the previous example. Przymusinski (1989)b developed a full theory of constructive negation for normal logic programs in which the answers are parameterized in terms of the semantics used to interpret negation. He also developed an algorithm that returns constructive answers based on the well-founded semantics. However, the theory of constructive answers has two major drawbacks. First, there may exist queries whose full answers cannot be represented with an equality formula; and second, the process of building a constructive answer may be very costly, since it requires the construction of full answers even in cases when a single answer suces, the user posing the query to the database. Moreover, the construction of a full answer may be computationally ine ective since deciding whether or not a query has a full answer that can be represented with a equality formula may not be recursive. As in constructive negation, Algorithm 1 enables a search for values of variables in nonground negative literals. It uses constraint information to identify search space that cannot co-occur with the query's negated literal. The algorithm produces a new semantically equivalent query that covers the search space and constructs substitutions of allowed values for the variables that appear in the negative literal. Unlike constructive negation, the set of substitutions obtained using the algorithm is not necessarily complete. However, the answers that are found are correct. For example, consider the following query, constraint and residue: j

8



S

S

j

8 :

 :

6

^

6

Q: P(X,Y,Z),S(Y). IC: P(X,Y,Z),R(X,Z). Residue: R(X,Z) :

f

g

Suppose the residue R(X,Z) is expanded as a query and produces the answer substitutions 1 = a/X,b/Z and 2 = aa/X, bb/Z . The constraint says f

g

f

12

g

that no state of the database will contain both R(X,Z)1 and P(X,Y,Z)1 or both R(X,Z)2 and P(X,Y,Z)2. Thus, any bindings that are obtained for Y through S(Y) can be concatenated with the 1 and 2 to produce answer substitutions for the query. Suppose expansion of S(Y) produces two substitutions, c/Y and cc/Y . Then the nal set of answer expressions for the query is the following: f

g

f

g

a/X, c/Y, b/Zg, aa/X, cc/Y, bb/Zg, fa/X, cc/Y, b/Zg, faa/X, c/Y, bb/Zg, f

f

Moreover, in a Prolog-like interpreter, the answers are given one at a time, and if only one answer is required, the computation process can be stopped after the rst answer is obtained. There may still be other answers that are not found in the search space for R(X,Z).

3.5 General Issues

We now turn brie y to two issues that remain to be discussed.

3.5.1 Partial Subsumption with Two Negative Literals

The preceding sections show that the generalized semantic compilation algorithm deals with cases in which either the matching constraint and axiom literals are both positive or one is negative and the other is positive. To use the algorithm to treat the case in which the matching constraint literal and axiom literal are both negative, we temporarily rename the negated predicates as unique new positive predicates, as in Kowalski (1979). Next, semantic compilation is performed as if all literals were positive. Finally, the original predicates are restored. Take, for example, the following IDB clause: boycott(C1,C2)

:

friends(C1,C2), aggressive(C1,C2).

and the following integrity constraint: trade(C1,C2), : friends(C1,C2).

The literal friends(C1,C2) is transformed into the atom not friends(C1,C2) in both the integrity constraint and the IDB rule. Then, the compilation is applied and the atom is returned to its original form to obtain the following semantically constrained axiom :

13

boycott(C1,C2)

friends(C1,C2), aggressive(C1,C2), f trade(C1,C2)g.

:

3.5.2 Completeness

Theorem 1 in Section 3.3 indicates that all answers found with the new semantically compiled axioms are correct. For certain classes of integrity constraints, the set of answers that can be found over the new axioms will be complete. For example, consider the following complete IC for male and female: human(X) ! (female(X) ! :male(X)). human(X) ! (:male(X) ! female(X)).

which can be rewritten as male(X),female(X),human(X). male(X),:female(X),human(X).

:

When a query contains male(X) and the residue female(X) is expanded instead of male(X), then the set of answers will be complete. How to detect such constraints remains an open question. :

:

4 Disjunctive Databases and Constraints One way to describe the semantics of a deductive database is to characterize some subset of its models. Generally, this subset is a (not necessarily proper) subset of its minimal models. Whatever is true in every one of these models is considered to be a consequence of the database. When a set of integrity constraints IC is associated with a database P, the semantics of (P + IC) can be described in two basic ways. We consider the set of models associated with P alone:2 1. If each constraint is true in each model, then the database is considered consistent with IC, and together the models give the meaning of the database. Otherwise, the database is considered inconsistent with IC, and the database has no meaning. 2. If there is some model in which all the constraints are true, then the database is considered to be consistent with IC. The set of models in which all constraints are true describes the meaning of the database. Otherwise, the database is considered inconsistent with IC, and the database has no meaning. 2 Where the models are obtained by whatever semantics is selected to describe the meaning of disjunctive logic database.

14

For de nite databases, under minimal model semantics, these two cases are equivalent because only one model is associated with a database: its minimal model. However, under minimal model semantics, disjunctive databases may be inconsistent with IC by the rst de nition yet be consistent by the second de nition. This is possible because such databases have multiple minimal models. The following disjunctive database illustrates this point: IDB1: covalent bond(A,B) _ double bond(A,B) carbon(A), bonded(A,B). EDB1: carbon(item1). EDB2: hydroxyl(item2). EDB3: bonded(item1,item2).

The rule IDB1 says, If some entity A is a carbon atom and it is bonded to some other entity B, then the bond is either a covalent bond or a double bond.

The facts indicate that item1 is a carbon atom, item2 is a hydroxyl group, and the two items are bonded. The database has two minimal models: M1 = f carbon(item1), hydroxyl(item2), bonded(item1,item2), double bond(item1,item2)g M2 = f carbon(item1), hydroxyl(item2), bonded(item1,item2), covalent bond(item1,item2)g

Now consider a constraint that says, Nothing can be a hydroxyl group and be

double-bonded to something else:

IC1:

double bond(A,B), hydroxyl(B).

The rst minimal model violates the constraint with the substitution item1/A, item2/B . Thus, according to the integrity constraint, the rst minimal model should be disregarded when answering queries to the database. Fernandez and Minker (1991) have de ned an algorithm that takes a disjunctive database without function symbols, computes its minimal models, and eliminates the models that are not consistent with the set of constraints. Answers to queries are computed over these models. An alternative way to give answers to queries that are consistent with the integrity constraints is to transform the database into a new program that incorporates the integrity constraint information. If all of the minimal models of the new program are consistent with the constraints, then any answers obtained through any disjunctive query processing mechanism would be consistent with the constraints as well. We modify the de nition of mixed partial subsumption and mixed merging in order to describe a procedure that performs such a transformation on (not necessarily function-free) disjunctive deductive data bases and constraints f

g

15

without negation.

De nition 3. Disjunctive subsumption

The disjunctive subsumption of an axiom R = A1 _    _ Ak B1 ; B2 ; : : :; Bm , by an integrity constraint I = C1 ; : : :; Cn, can occur if and only if there exist a Ai and a Cj such that they unify with mgu . The clause ( C1, : : : , Cj ?1, Cj +1, : : : , Cn), is the disjunctive residue obtained from R and I .

De nition 4. Disjunctive merging

To merge the disjunctive residue ( R, replace the rule by the new rule

C1,: : : ,Cj ?1,Cj +1,: : : ,Cn) with the rule

(A1

B1 ; : : :; Bm ; C1 : : :; Cj ?1; Cj +1; : : :; Cn):

__

Ai?1 Ai+1 _

__

Ak

Procedure 1. Semantic Compilation in Disjunctive Databases

Repeat the following steps until no I in IC disjunctive subsumes any rule in P: 1. Select I from IC; let IC be IC{fIg. 2. Let P be P. 3. While P 6= ; do (a) Use disjunctive subsumption to obtain all disjunctive residues between I and the axioms in P . (b) Use disjunctive merging to generate the new disjunctive rules NR. (c) If the empty clause is in NR report that P is inconsistent with IC and stop. (d) Remove each rule with an empty head from NR and add it to IC. (e) Let P be P [ NR. (f) Let P be NR. End of Procedure 1. 0

0

0

0

Consider our disjunctive deductive database about a carbon atom and a hydroxyl group. When the procedure is applied to IC1 and EDB2, the rst iteration produces the following intermediate constraint: IC2:

double bond(A,item2).

The intermediate constraint is added to the database, and the procedure is applied again to produce a new IDB rule, IDB2, from IC2 and IDB1: IDB2: covalent bond(A,item2)

carbon(A), bonded(A,item2).

After all the interactions, the nal program produced by the procedure consists of the following rules and facts (note the addition of IDB3): 16

IDB1: covalent bond(A,B) double bond(A,B) _

carbon(A), bonded(A,B). IDB2: covalent bond(A,item2) carbon(A), bonded(A,item2). IDB3: covalent bond(A,B) _ double bond(A,B) carbon(A), bonded(A,B), : hydroxyl(B). EDB1: carbon(item1). EDB2: hydroxyl(item2). EDB3: bonded(item1,item2).

The new program has one minimal model: f carbon(item1), hydroxyl(item2), bonded(item1,item2), covalent bond(item1,item2)g. The model is consistent with the integrity constraint IC1.

Theorem 2.

Let P be a positive disjunctive logic program. Let IC be a set of integrity constraints. Let P0 be a positive disjunctive logic program produced by Procedure 1 from P and IC. Then the following holds: 0  Any minimal model of P that satis es IC is a model for P . 0  Any minimal model of P is a model for P [ IC.

Proof: First, we must show that a minimal model of P that is consistent with

IC is also a model of P0 . Let M be such a minimal model. Each rule in P0 that occurs in P is satis ed by M. Let r0 be a rule in P0 that does not occur in P. By Procedure 1, r0 is obtained through disjunctive merging of some rule r in P with members of IC. The rule r has the general form A1 : : : An B1 ; : : :; Bm . The new rule r0 has the form (A0 B1 ; : : :; Bm ; D1; : : :; Dp ), where A0 is a positive clause that subsumes A1 : : : An and each Di  is an instance of a disjunctive residue. Take a ground instance (A1 : : : An B1 ; : : :; Bm ; D1 ; : : :; Dp ) of the rule r0 . If (B1 ; : : :; Bm ) is false in M, then the body of r0 is false and r0 is true in M. If the ground instance is true in M, then some atom in the head, A0 , of the ground instance of r0 must true for r0 to be true in M. Now, since M is a model of P then there exists an Aj in A1 : : : An such that Aj  is true in M. For each Di in r0 there is an Ai in A1 : : : An that does not appear in A0 . If j=i, then Di  must be false; the body of r0 is then false and r0 is true in M. If j = i, then the head of r0 is true because it contains Aj ; r0 is then true in M. Second, we must show that any minimal model M of P0 is a model of P. Let M be a minimal model of P0 . By Procedure 1, each rule R in P also occurs in P0 and is thus supported by M. _

_

_

_

_

_

_

_

_

_

6

17

We shall show by contradiction that all members of IC are also supported by M. Each member of IC has the form C1; : : :; Ck . Assume that a member of IC is false in M. This implies that there is some ground instance C10 ; : : :; Ck0 of a member of IC that is false in M. That is, each Ci0 is a member of M. Then k ground instances of rules from P of the following form must be true in M: Ci0 A01 : : : A0n B10 ; : : :; Bm0 , with 1 i k. _

i

_

_



i

i

i



In order for each Ci0 to be true in M, each disjunction A01 : : : A0n must be false when B10 ; : : :; Bm0 is true; otherwise M would not be a minimal model. Let C 00i A1 : : : An B1 ; : : :; Bm be the noninstantiated rule in P. Procedure 1 disjunctive merges the constraints with each such rule to produce a new rule r0 of the following form: i

(A1

i _

i _

: : : An _

_

i

i

i

_

_

i

_

i

i

i

B1 ; : : :; Bm ; C1; : : :Ci?1; Ci+1; : : :; Ck)i . i

i

Since Ci and C 00i unify and Ci0 is an instance of Ci, then (A01 : : : A0n B10 , : : :, Bm0 , C10 , : : :, Ci0?1, Ci0+1 , : : :, Ck0 ) is a ground instance of r0 . Then, each rule r0 is true in M, since M is a model of P. We just noted that A01 : : : A0n must be false when B10 ; : : :; Bm0 is true; we have assumed that each Ci0 in the grounded constraint is true. Therefore, the body of a ground instance of r0 is true while the head is false. But then r0 is false in M. Thus, each constraint in IC is satis ed by each minimal model of P0. It follows that each minimal model M of P0 supports P and IC. 2 We are not able to guarantee termination of Procedure 1 since it applies to all disjunctive programs and the question of whether or not a set of ICs is consistent with a set of disjunctive clauses is only semi-decidable. However, Procedure 1 is a step toward the extension of semantic compilation to disjunctive theories. We believe that with minor modi cations, the same procedure can be used for more general constraints and programs. The modi cations will depend on the semantics chosen for negation in disjunctive logic programs. i

_

_

i

i

i

i

i

_

_

i

i

5 Conclusion

Chakravarthy et al. (1990) gave an e ective method to optimize queries to de nite deductive databases for cases in which partial subsumption involves positive atoms. We have generalized the method to apply to negative literals in either the database axioms or the integrity constraints or both. We have studied all possible syntactic interactions between the literals in the query and the literals in the integrity constraints: positive-positive, negative-negative and negative-positive. The generalized method, called semantic compilation, enables answers to be found for queries with negative literals in cases for which constructive negation or SLDNF nd no answers. We have shown that the answers obtained from a 18

semantically compiled database are correct and, in some cases, complete. When the generalized semantic compilationis applied to disjunctive databases that are inconsistent with the integrity constraints for some minimal models, a new disjunctive program is produced whose minimal models are all consistent with the integrity constraints if that program exists. In this new program, queries can be answered using any procedure for disjunctive databases without requiring a special mechanism to check the constraints. It remains to be seen how semantic compilation can be applied to disjunctive logic programs in the presence of negation.

Acknowledgments Terry Gaasterland was supported for this work by the Oce of Scienti c Computing, U.S. Department of Energy, under Contract W-31-109-Eng-38. The NSF partially supported Jorge Lobo for this work under The grant #IRI-9210220.

References Chakravarthy U.S., Grant J., and Minker J. (1990). Logic based approach to semantic query optimization, ACM Transactions on Database Systems, 5(2):62{207. Chakravarthy U. (1985). Semantic Query Optimization in Deductive Databases. PhD thesis, University of Maryland, Department of Computer Science, College Park. Chan David. (1988). Constructive Negation Based on the Completed Database. In Kowalski R. and Bowen K., editors, Proceedings of the Fifth Logic Programming Symposium, pages 111{125, Seattle, Washington, (1988). Association for Logic Programming, MIT Press. Clark K. L. (1978). Negation as failure. In Gallaire H. and Minker J., editors, Logic and Data Bases, pages 293{322. Plenum Press, New York. Fernandez J. A. and Minker J. (1991). Bottom-Up Evaluation of Hierarchical Disjunctive Deductive Databases. In Furukawa Koichi, editor, Logic Programming Proceedings of the Eighth International Conference, pages 660{675. MIT Press. Fernandez J. A., Lobo J., Minker J., and Subrahmanian V. S. (1993). Disjunctive LP + integrity constraints = stable model semantics, Annals of Mathematics and Arti cial Intelligence, 8(3{4). Preliminary version presented at the Second International Symposium on Arti cial Intelligence and Mathematics, Florida, 1992. 19

Gaasterland T., Giuliano M., Litcher A., Liu Y., and Minker J. (1993). Using integrity constraints to control search in knowlege base systems, Journal of Expert Systems (to appear). Gaasterland T. (1992). Cooperative Answers for Database Queries. PhD thesis, University of Maryland, Department of Computer Science, College Park, Dissertation work in progress. Kowalski R. (1979). Logic For Problem Solving. Elsevier Science Publishing Co, Inc. Lobo J. and Minker J. (1988). A metainterpreter to semantically optimize queries in deductive databases. In Kerschberg L., editor, Proc. Workshop on Expert Database Systems, pages 387{420, Tysons Corner, Virginia, (1988). Minker J. and Gal A. (1990). Producing cooperative answers in deductive databases. In Saint-Dizier P. and Szpakowics S., editors, Logic and Logic Grammar for Language Processing. L.S. Horward, Ltd., to appear. Przymusinski T.C. (1989). Every logic program has a natural strati cation and an iterated xed point model. In Proceedings of the 8th ACM SIGACTSIGMOD-SIGART Symposium on Principle of Database Systems, pages 11{ 21. Przymusinski T.C. (1989). On constructive negation in logic programming. In Lusk E.L. and Overbeek R.A., editors, Proc. of the North American Conference of Logic Programming. Addendum to Proceedings. Reiter R. (1978). On closed world data bases. In Minker H. Gallaire J., editor, Logic and Data Bases, pages 55{76. Plenum Press, New York. Ross K.A. (1989). A procedural semantics for well founded negation in logic programs. In Proceedings of the 8th ACM SIGACT-SIGMOD-SIGART Symposium on Principle of Database Systems.

20

Suggest Documents