Intensional Negation in Constraint Logic Programs Paola Bruscoli, Francesca Levi, Giorgio Levi, Maria Chiara Meo
Dipartimento di Informatica, Universita di Pisa, C.so Italia, 40 - 56125 Pisa, Italy e-mail:
[email protected] flevifran, levi,
[email protected]
Abstract In this paper we de ne a new compilative version of constructive negation (intensional negation) in CLP and we prove its (non-ground) correctness and completeness wrt the 3-valued completion. We show that intensional negation is essentially equivalent to constructive negation and that it is indeed more ecient, as one would expect from the fact that it is a compilative technique, with the transformation and the associated normalization process being performed once and for all on the source program. We de ne several formal non-ground semantics, based either on the derivation rule or on the least xpoint of an immediate consequence operator. All these semantics are proved to correctly model the observable behavior, from the viewpoint of answer constraints. We give some equivalence theorems and we show that all our denotations are the non-ground representation of a single partial interpretation, which is P " !, where P is the Fitting's operator [12].
1 Introduction The most popular semantics for normal logic programs is based on SLDNF-resolution (SLD-resolution with Negation As Failure) as operational semantics and on the program completion as declarative semantics [8, 22]. The reference xpoint semantics is usually based on Fitting's operator [12]. Unfortunately, the nice equivalence and completeness results proved for the semantics of positive logic programs [29, 2, 22, 1] are not valid in the case of normal programs. In particular, we need to impose strong conditions on programs and goals, in order to deal with various incompleteness problems (e.g.
oundering, inconsistency of the completion, the combination of tertium non datur and non-termination). The completeness of SLDNF-resolution holds for a larger class of programs, if we consider the logical consequences of the completion P in a 3-valued logic. Theorem 1.1 [19] Let P be a normal program, G = L1; : : :; Ln be a normal goal, such that P SfGg is allowed, if (L1 ^ : : : ^ LnS) is a 3-valued logical consequence of P , then there exists an SLDNF-refutation of P fGg which computes an answer such that (L1 ^ : : : ^ Ln) is more general than (L1 ^ : : : ^ Ln). The 3-valued completion is also strongly related to the Fitting's operator P [12], which acts upon 3-valued interpretations. The minimal 3-valued model MP of P is its least xpoint P " . Kunen's semantics [18] is also de ned in terms of P , namely fL j P " n j=3 L for a nite ng = fL j P j=3 Lg. If we choose the 3-valued completion, the only source of incompleteness has to do with the oundering problem, i.e. with non-ground negative literals. Another serious drawback of SLDNF is also related to the non-ground literal problem, namely the fact that Negation As Failure can only be used as a test and never computes answers. The problem of handling \non-ground" literals was tackled by various extensions of Negation As Failure, called constructive negation. Examples are intensional negation [3, 4], Chan's constructive negation [6, 7], the fail substitutions [23] and the fail answers [10, 9] techniques. The idea of intensional negation, originally formalized for positive logic programs [3, 4], is the following. Given a normal program P , we derive a new program P 0, which contains clauses which allow us to compute the answers to negative queries.
Example 1.2 Let P be the program
even(0) even(s(s(X ))) even(X ). The new clauses in P 0 generated by intensional negation are the following even:(s(0)) even:(s(s(X ))) even:(X ). A (possibly non-ground) literal of the form :even(t) (in a goal or in the body of a normal clause) is transformed to even:(t) and evaluated in P 0.
The new clauses are built in such a way that the answers to negative queries are \the complement" of the set of answers to the corresponding positive query. The complement is computed by assuming the Domain Closure Axiom (DCA). The negative literals (not only in the goal, but also in clause bodies) can be replaced by (positive) calls to the new predicates. Note that if the result of intensional negation were really a positive program, 1
we could simply apply SLD-resolution. Moreover, the standard least Herbrand model and least xpoint of TP semantics would be applicable. Finally, the resulting denotation could be viewed as a 3-valued interpretation. Unfortunately, there exist logic programs for which the intensional negation transformation introduces universal quanti cation in clause bodies, coming from local variables in the original program. The standard semantics of positive logic programs is then applicable to the result of the intensional negation transformation for restricted classes of normal programs only [25]. The range of applicability of intensional negation was increased by de ning an extended derivation rule for positive logic programs with universal quanti cation parametric w.r.t. the DCA [20, 21]. Chan's constructive negation, which is a re nement of previous proposals [17, 30] in its original formulation [6] can be described as follows. De nition 1.3 Let :A be a (possibly non-ground) literal in the normal program P . Let T be the complete SLD-tree rooted at A and let e1; : : : ; en be the sets of equations in solved form corresponding to the answer substitutions computed by the success paths in T . The answer to :A is the (normalization of the) constraint :(e1 _ : : : _ en). The normalization is a disjunction of constraints, i.e. equalities and inequalities. Note that Chan's constructive negation does not require the DCA. The application of the above inference rule is unde ned when the SLD?tree is in nite. The mechanism of negative literals evaluation, inherited from Negation As Failure, is not \incremental", since it requires the construction of a full SLD-tree. This problem was solved in [7], by considering a nite part of the SLD-tree, de ned by a frontier, instead of the complete SLD?tree. Using the Constraint Logic Programming (CLP) notation [16, 15], each node of the frontier is a goal ei2Bi containing both constraints (equalities) and literals. The literal :A is now rewritten as the result of the normalization of the formula :(e12B1 _ : : : _ en2Bn ). The result of the computation is independent from the choice of the frontier. The above technique was then extended to CLP [27, 28] and a completeness result was proved. In this paper we de ne intensional negation in CLP and we prove its (non-ground) correctness and completeness w.r.t. the 3-valued completion. There are several motivations for choosing the CLP setting instead of the logic programming one. First, even if we start from normal logic programs, constructive negation forces the introduction of (possibly universally quanti ed) inequalities. One can stay within the logic programming setting based on substitution only by assuming the Domain Closure Axiom. This is, for example, the solution chosen in [23]. The most natural solution is then choosing the instance of CLP , where constraints are equalities and inequalities on the Herbrand domain. Moving to the CLP (X ) framework allows us to get more generality and to use the only existing formalization of constructive negation [27] for which there exists a completeness theorem. We consider the relation among the various constructive techniques. Intensional negation is clearly a \compile-time" technique. The transformation and the associated normalization process are performed once and for all on the source program. All the versions of constructive negation are instead interpretative. Intensional negation is therefore much more ecient. But is indeed intensional negation the compilative version of constructive negation? In order to get an answer to this question we need a common 2
foundation, to be used as a basis for a formal framework to compare the compilative and interpretative versions. We show that both intensional and constructive negation can simply be viewed as mechanisms to eciently implement \computing in the completion". The optimization is concerned with the management of disjunctions, which are handled by using essentially the SLD?tree structure of positive Horn clauses. The resulting theory allows us to identify commonalities and dierences between the various constructive negation techniques. It is worth noting that there exists one example [10, 9] of constructive negation technique, which is not based on the program completion and is not therefore easily comparable to our technique. Another problem is related to the formal semantics. In fact the existing semantics do not correctly model answer constraints and are therefore useless for semantics-based program analysis and transformation. We propose several formal non-ground semantics which are based either on the top-down derivation rules or on the bottom-up application of immediate consequences operators. All these semantics are proved to be correct (and fully abstract) with respect to the answer constraints observable. We give some equivalence theorems and we show that all our denotations are the non-ground representation of a single partial interpretation, which is P " !. Some technical proofs are deferred to the appendix.
2 The language and its semantic domains We will rst recall the basic CLP concepts as de ned in [16]. TheSCLP framework is de ned using a many-sorted rst order language, where SORT = SORTi denotes a nite set of sorts. A signature of an n-ary function, predicate or variable symbol f is a sequence of respectively n + 1; n; 1 elements of SORT. By the term sort of f we mean the last element in the signature of the function symbol f . By , and V (possibly subscripted) we denote possibly denumerable collections of function symbols, predicate symbols and variables with their signatures. We assume there is a denumerable number of variables symbols for each sort and that each sort contains at least two symbols. ([V ) and () denote the set of terms and ground terms (i.e. terms without variables) built on and V . A (; )-atom is an element p(t1; : : :; tn) where p 2 is n-ary and ti 2 ( [ V ), i = 1; : : : ; n. A (; )-literal is a (; )-atom or its negation. A (; )constraint is a rst order formula over (; ). The empty constraint will be denoted by true. In the following the symbol will denote a nite sequence of symbols. If t is a syntactic object, FV (t) is the set of variables which are not explicitely quanti ed in t. A sentence is a well formed formula with no free variables.
De nition 2.1 (CLP normal programs) [16] Let = C [ B and C \ B = ;. A
(; )-normal program is a nite set of clauses of the form H : ?c2: or H : ?c2B1; : : :; Bn : where c is a nite (C ; )-constraint, H (the head) is a (B ; )-atom and B1; : : : ; Bn (the body) are (B; )-literals. A normal goal is a program clause with no head and with a non-empty body. In the following we will consider clause heads of the form p(X ), where X is a sequence of distinct variables. 3
De nition 2.2 Let = C [ B and C \ B = ;. A (B ; )-constrained atom is an
object of the form c2p(X ), where c is a (C ; )-constraint and p(X ) is a (B ; )-atom.
In the CLP(X) framework, X stands for a speci c constraint domain on which the computation is performed. The notion of structure gives the semantic interpretation of such a domain and is the key element in the algebraic semantics.
De nition 2.3 [16] Let = C [ B and C \ B = ;. A structure