A Heuristic Implementation Method for a Constructive Negation ...

1 downloads 0 Views 247KB Size Report
constructive negation approach in logic programming. The constructive nega- tion approach is reformulated as a derivation rule. An heuristic method for e ciently ...
A Heuristic Implementation Method for a Constructive Negation Approach Lunjin Lu and John G. Cleary Department of Computer Science University of Waikato Hamilton, New Zealand flunjin,[email protected]

Abstract. This paper presents an ecient implementation method for a constructive negation approach in logic programming. The constructive negation approach is reformulated as a derivation rule. An heuristic method for eciently implementing the derivation rule is presented and the complexity of the heuristic method is analysed. Keywords: constructive negation, logic programming, existence properties

1 Introduction In logic programming, the \negation by failure" rule may lead to oundering when negative goals contain variables. To solve this problem, Chan introduces the \constructive negation" rule which allows non-ground negative goals to bind variables in the same way as positive ones [1, 2]. Answers to : Q are obtained by negating answers to Q. Foo et. al propose an approach for constructive negation for Datalog programs that transforms the program so that the negative goals in the transformed program are always ground when it is selected. Maluszynski and Naslund put forward another approach to constructive negation which allows a negative goal to directly return fail substitutions, as its answers [7]. Drabent de nes SLDFA resolution over the Herbrand universe that constructs answers for the negative goal from a nite number of answers to the negated sub-goal [5]. Stuckey provides a constructive negation method for constraint logic programs over arbitrary structures [8]. Stuckey's method which is sound and complete with respect to the three-valued consequences of the completion of the program can be thought of as a generalisation of Chan's. Fages proposes a simple concurrent pruning mechanism over standard SLD derivation trees for constructive negation in constraint logic programs [6]. Two derivation trees are concurrently constructed. The computed answers from one of the trees are used to prune the nodes of the other. Fages' method admits an ecient implementation as it is not necessary to deal with complex goals with explicit quanti ers outside the constraint part. Cleary makes use of existence properties of arithmetic constraints to construct answers to negative goals [3]. Existence properties are functional or partial functional dependencies between arguments to predicates (arithmetic constraint in [3]). Cleary's constructive negation approach consists of four rewrite rules. A clear advantage of Cleary's approach is that no SLD-derivation of the negated sub-goal is performed. The prerequisite that a functional or partial functional dependency exists between arguments to a predicate is restrictive. Cleary and Lu generalise [3] by generalising the notion of an existence property [4]. An input may now correspond to

multiple outputs provided that each of the outputs can be isolated into a subdomain. Thus, the generalised method is applicable to more negative goals than the original one. They also use types to make the expression of an existence property more precise and more concise. This paper extends work in [4]. We reformulate the rewriting rules in [4] as a derivation rule, present a heuristic method for implementing the derivation rule and analyse the complexity of the heuristic method. A crucial task of any implementation of [4] is introduce new variables into an atom inside a negative goal so as to make it satisfy a given existence property. An algorithm for that task is also presented. The main contributions of this paper are the heuristic implementation method and the algorithm for introducing new variables, though the rewrite rules in [4] have been substantially reformulated. The rest of the paper is organised as follows. Section 2 reformulates rewrite rules in [4] as a derivation rule. Section 3 describes a data structure for representing negative goals and section 4 presents the algorithm for introducing new variables. Section 5 describes the heuristic implementation method and section 6 analyses its complexity. Section 7 concludes the paper. Proofs are omitted due to space limit. We shall assume that variables are typed. y: stands for that variable y is of type . A type is a nite expression denoting a possibly in nite set of terms. We use all to denote the set of all terms and none to denote the empty set of terms. R and Zdenote the set of reals numbers and the set of integer numbers respectively. R and Zwith subscripts denote their subtypes. A subscript is either an interval or a logical formula.  v  is true if and if only  is a subtype of , and    is true if and only if  is equivalent to .

2 Rewrite Rules This section recalls the rewrite rules for constructive negation in [4] where a detailed presentation can be found. In the sequel, a bold face letter will denote a vector of di erent variables while a bold face letter with tildes denote a vector of terms that are not necessarily di erent.

Exists unique One rewrite rule applies when it is known that for any input u in a particular domain, there is exactly one output x in each of a xed number of domains such that A(ux) holds where A is a predicate. It also requires that, for any u, any x such that A(ux) holds lies in one of those domains. Such a property is called an exists unique property and is formalised as follows. 8u::8x:[A(ux) ! _i2I x 2 i ] (1) 8u:: ^i2I 9!xi:i :A(uxi ) (2) where domains are denoted by types. Each i is called a solution subtype of the output parameter x. We now delevop a rewrite rule that makes use of exists unique properties to extract positive information from negative goals. Let :9l : :[A(~ux~ ) ^ Q] be the negative goal. To make use of (1) and (2), u~ must be of type  and cannot contain 1

1

The type of a variable in a formula follows the rst occurrence of the variable.

any existentially quanti ed variables, also called local variables. Let VE be the set of variables in E and iarg(~u; ; z) def = u~ 2  ^ Vu \ z = ; where z is a set of variables which are local when iarg(~u;  ; z) is invoked. The negative goal can be rewritten to :9l::x:[A(~ux) ^ (~x = x) ^ Q] where x be a vector of new local variables each for an element of x~ . Using (1) and (2), we can rewrite the above negative goal to ^i2I [A(~uxi :  i) ^ :9l::((~x = xi ) ^ Q)] provided that iarg(~u; ; l) is true. If the type of x~ does not intersects with  i then A(~uxi :  i) ^ :9l::((~x = xi ) ^ Q) can be removed from the conjunction because (~x = xi ) is unsatis able and any further instantiation of xi has no e ect on the variables of the original goal since xi does not occur in the original goal. A solution subtype is relevant for an atom inside a negative goal if and only if it intersects with the type of the output argument of the atom. We call an index a relevant index if its corresponding solution subtype is relevant. We only need to consider relevant solution subtypes when rewriting the negative goal. Let J = fi 2 I j (typeof (~x) and i ) 6 noneg. Then J is the set of relevant indices. Let w: be the vector of those elements of l that occur in x~ and y: be the vector of those elements of l that do not occur in x~ . Then :9l::((~x = xj ) ^ Q) for each j 2 J is equivalent to :9wj : :(~x[w := wj ] = xj ) _ (~x[w := wj ] = xj ) ^ :9y~: :Q[w := wj ] where R[w := wj ] is the result of substituting wj for w in R and :9wj : :(~x[w := wj ] = xj ) is a disequality constraint can be dealt with by augmenting Chan's method with types. A new local variable is introduced for each output argument of A in the above formula. As the cost of simplifying :9wj :  :(~x[w := wj ] = xj ) increases with the number of equations it contains, it is desirable to avoid introducing new local variables whenever possible. In order to avoid introducing a new local variable for an output argument, the output argument must be a local variable and if its type intersects with a solution subtype of its corresponding output parameter then its type must be a supertype of that solution subtype. Let x~ be a vector of terms, y~ a sub-vector of x~ and  a vector of types of the same length as x~ .  y/x denotes the vector of elements in  that correspond in position to elements of y~ in x~ . Let typeof (E) denote the type of E where E is a term or a vector of terms. As each variable in a term is typed, the type of the term is de ned. The above considerations lead to the following rewrite rule for exists unique properties. ~

2

~

~

Given (1), (2) and iarg(~u; ; l) :9l::[A(~ ux~ ) ^ Q] $ let J = fi 2 I j (typeof (~x) and i ) 6 noneg r: be a subvector of x~ such that 8j 2 J:(jr/x~ v ) ~s be the vector of the elements of x~ other than those in r w: be the vector of those elements of l that occur in ~s QVT y: be the vector of those elements of l that do not occur in x~

in

0 j2J @

A(~uzj:js~ /x~ rj:jr/x~ )

1

wj::(~s[rw := rj wj ] = zj ) A ~ /x ~ ~ s r / x y::Q[rw := rj wj ] A(~uzj:j rj :j ) (~s[rw := rj wj ] = zj ) 2 x has been renamed into xi for each solution subtype i . ^ :9

_

^

^

^ :9

where zj rj and wj are variables that do not occur in the lefthand side of the rewrite rule. zj rj is typed with j th solution subtype while wj inherits the type of w. r: is a sub-vector of x~ for which no new local variables need be introduced. The choice of r: in the (QVT) rewrite rule is nondeterministic so long as it is subvector of x~ and it satis es 8j 2 J:( jr/x v ). In the extreme case, r: is of zero length and a new variable is introduced for each output argument of A. ~

Exists sometimes Another rewrite rule applies when it is known that for any input u in a particular domain, there is at most one output x in each of a xed number of domains such that A(ux) holds where A is a predicate. It also requires that, for any u, any x such that A(ux) holds lies in one of those domains. Such a property is called an exists sometimes property and is expressed by (1) and the following equation. 8u:: ^i2I 9?xi:i:A(uxi ) (3) where 9? denotes \there is at most one". The same considerations as in the case for exists unique properties lead to the following rewrite rule for exists sometimes properties. Given (1), (3) and iarg(~u; ; l) :9l::[A(~ ux~ ) ^ Q] $ let J = fi 2 I j (typeof (~x) and  i ) 6 noneg r: be a subvector of x~ such that 8j 2 J:(jr/x~ v ) ~s be the vector of the elements of x~ other than those in r w: be the vector of those elements of l that occur in ~s y : be the vector of those elements of l that do not occur in x~ SVT

in

1 zj:sj~/x~ rj:jr/x~ :A(~uzj rj ) CC ~ /x ~ ~ s r / x CC wj::(~s[rw := rj wj ] = zj ) A(~uzj:j rj:j ) A ~ /x ~ ~ s r / x ::Q[rw := rj wj ] A(~uzj:j rj:j ) (~s[rw := rj wj ] = zj )

0 B B j2J B B @

^

:9

_

^ :9

_

^

^ :9

Example 1. Let sq(x; y) def = (x = y). The fact that, in the domain of integer num2

bers, a positive number has at most one negative square root and at most one positive square root can be expressed as the following exists sometimes property. 8y:Z> :8x:(sq(x; y) ! x 2 Z< _ x 2 Z> ) 8y:Z> :(9?x :Z< :sq(x ; y) ^ 9?x :Z> :sq(x ; y)) The local variable x in the negative goal :9x: Z ; :(sq(x; y: Z> ) ^ b(x)) has a type Z ; which is not a supertype of the sole relevant solution subtype Z> of the corresponding output parameter. Therefore, a new variable z of type Z> is introduced and the negative goal is rewritten to the following. :9z :Z> :sq(z ; y:Z> ) _ sq(z :Z> ; y:Z> ) ^ :9x:Z ; :(x = z ) _ sq(z :Z> ; y:Z> ) ^ (x:Z ; = z ) ^ : b(z ) 0

0

0

1

0

1

0

2

0

2

0

[0 20]

0

[0 20]

2

2

0

2

0

2

0

0

2

0

0

2

[0 20]

[0 20]

2

2

0

Exists Yet another rewrite rule makes use of exists properties. An exists property 8u :  :9x : :A(ux) states that for every u of type  there are some x of type  such that A(ux) holds. For instance, letting list( ) denote the set of the lists whose elements are of type , the append=3 program satis es 8z:list( ):9x:list( ):y: list( ):append(x; y; z)

which states that every list z can be split into two lists x and y. The following rewrite rule veri es that an input argument is of the type of the corresponding input parameter and that the type of an output argument is a supertype of the type of the corresponding output parameter. 8u::9x::A(ux) and iarg (~ u; ; x) ^  v  ET Given :9x::A(~ ux) $ false

It is shown in [4] that introducing local variables does not bring any bene t for the rewrite rule for exists properties.

Miscellaneous A fourth rewrite rule makes use of miscellaneous properties. A miscellaneous property 8u::(:A(u) $ B(u)) states that, for every u of type  , :A(u) can be replaced by B(u). For instance, we have 8x: Z:y:Z:(:(x < y) $ (x  y)).

The following miscellaneous rewrite rule veri es that an input argument is of the type of the corresponding input parameter. ~ 2 8u::(:A(u) $ B (u)) and u RT Given :A(~ u) $ B (~u)

2.1 Derivation rule

The four rewrite rules can be used to extract positive information from negative goals. The following derivation rules can be obtained straightforwardly from the rewrite rules. (`qvt ) 1 ; :9l : :[A(~ux~ ) ^ Q]; 2 `qvt 1; Nl ; 2 for each 1  l  k if (1), (2), iarg(~u;  ; l) and N _ N _  _ Nk is a disjunctive normal form of the righthand side of (QVT). (`svt) 1 ; :9l : :[A(~ux~ ) ^ Q]; 2 `svt 1 ; Nl ; 2 for each 1  l  k if (1), (3), iarg(~u;  ; l) and N _ N _  _ Nk is a disjunctive normal form of the righthand side of (SVT). (`et ) 1 ; :9x~::A(~ux~ ); 2 `et false if 8u::9x::A(ux) and iarg(~u;  ; x~ ) ^  v . (`rt ) 1 ; :A(~u); 2 `et 1 ; B(~u); 2 if 8u::(:A(u) $ B(u)) and u~ 2  . Let 1 ` 2 denote either 1 `qvt 2 , or 1 `svt 2 or 1 `et 2 or 1 `rt 2 . ` is a derivation rule which makes use of the aforementioned kinds of property. An application of ` to a negative goal results in an atom inside negation being moved outside. In other words, ` extracts an atom from a negative goal each time it is applied. 1

2

1

2

3 Digraph The derivation rule ` can be applied repeatedly to extract positive information from a negative goal :9w :  :G ; G ;    ; Gn. A naive implementation of ` would 1

2

repeatedly scan a conjunction of goals and check if an atom is extractable. After an atom is extracted, some local variables become global, i.e. non-local. This makes it necessary to check if other atoms are extractable. That would result in an inecient implementation because most of those checks would fail. We now present a heuristic version of `. Since `et and `rt are only applicable when n = 1, which is simple, we will only be concerned with `qvt and `svt. Let `sqvt denote either `qvt or `svt . We rst present a representation of negative goals. A previously inextractable atom becomes extractable only after some of its local variables become global or some of its global variables are given a value or a smaller type. However, `sqvt doesn't change the type of global variables, nor will it assign any value to them. So, after an atom is extracted, it is only necessary to check those other atoms that share with the extracted atom some of the variables that have become global. For that reason, we use a list  consisting of atoms to be checked and a digraph D which links each atom with local variables it contains. The method repeatedly remove one atom from  and check for its extractability until  becomes empty. D is used in order to quickly retrieve local variables an atom contains and atoms containing a local variable. After an atom is extracted, it is moved out of the scope of negation and the local variables it contains become global. This is done by removing the atom and the local variables from D. Before the removal of the local variables, other atoms linked to them are added to  as their extractability need be checked for again. Initially, every atom needs be checked. Let us rst consider the case where an existence property has one solution subtype for its output parameter. When an atom is extracted by `sqvt without introducing any new local variable, it is moved out of the scope of negation and the local variables in it are promoted to being global. The atom is deleted from  and D. The other atoms that are linked to the local variables are then added into  and the local variables are deleted from D. The method continues by applying `sqvt to the residual negative sub-goal with the updated D and . When an atom is extracted by `sqvt by means of introducing local variables, only some of local variables become global and derived goals is more complex. However, the residual negative sub-goals can be obtained in the same way. When the output parameter of an existence property has more than one solution subtypes, several complex goals may be derived from the negative goal. Each of these complex goals may contain a number of residual negative sub-goals to which `sqvt may be applicable. However, these residual negative sub-goals di er only in the names and types of newly promoted global variables. So, the digraph and the checklist for each of these residual negative sub-goals are obtained in the same way.

4 Extractability Given an atom inside a negation and an existence property, `qvt and `svt have to decide if the atom satisfy the existence property and, if so, to decide for which output arguments new local variables need be introduced. `qvt and `svt di er only in that `svt has an extra disjunct :9zj :  sj /x rj :  rj /x :A(~uzj rj ) for each relevant solution subtype. Otherwise, they are in common. They test if an atom satis es an existence property, introduce new local variables, decide if a solution subtype is relevant, and rename and type local variables in the ~

~

~

same way. We factor out these common functionalities of `qvt and `svt by means of a function sqvt. An exists unique property is represented as follows. Each input parameter u: in u: is represented by i(). Each output parameter x in x with solution subtypes  where  is a mapping which maps k in I to k . fk j k 2 I g is represented by o() An exists unique property has the following representation where input and output parameters may be interspersed.    ); I i hA(   ; i();    ; o(); The set of exists unique properties is denoted by ? . We use the same representation for an exists sometimes property and denote the set of exists sometimes properties by ? . !

?

function sqvt(P; G; l) begin (01) Let G = B (   ; tu ;    ; tx ;   ) and P = hA(   ; i();    ; o( );   ); I i; (02) if B = A and tu 2  ^ Vt \ l = ; for every tu matching an i() (03) then (04) r := ;; xm := ; z := ; s~ := ; w := ; J := I ; (05) for each tx matching an o( ) do (06) J := J \ fk j (typeof (tx ) and  (k)) 6 noneg; (07) if tx 2 lnr ^ 8j 2 J:( (j ) v typeof (tx )) (08) then (09) r := ftx g [ r; (10) xm := (tx ;  ) :: xm ; (11) else (12) ~s := tx :: ~s; (13) for each v 2 (Vt \ l)nr ^ v 62 w do w := v :: w od; (14) z := newv(all); z := z :: z; G := G[tx := z ]; (15) xm := (z;  ) :: xm (16) ; (17) od; (18) x := map S (fst; xm ); (19) xcs := j2J fmap(e:newv((snd(e))(j )); xm )g; (20) return (G; x; xcs ; s~; z; r; w) (21) else return nil (22) end; u

x

Fig.1. De nition of the sqvt function Figure 1 de nes sqvt. Given an exists unique or exists sometimes property P =

   ); I i and an atom G = B(   ; tu;    ; tx;   ) and a set l of hA(   ; i();    ; o();

local variables, sqvt rst checks if it is possible to replace some output arguments in G with newly introduced local variables so as to make G satisfy P. Since a new local variable can be introduced for any output argument in G, G can be made to 3

3

The order between the members of l is not essential. Hence a set is a sucient representation for l.

satisfy P if B = A and each of its input argument is of the type speci ed by P and contains no local variable. This is tested in line (02). sqvt returns nil from line (21) if this test fails. Otherwise, sqvt classi es every output argument according to whether a new local variable needs be introduced for it or not. r are the set of output arguments for which no new local variables need be introduced, ~s is the vector of other output arguments and z is the vector of corresponding newly introduced local variables. Whenever a new local variable z is introduced for an output argument tx , sqvt substitutes z for tx in G. sqvt collects the vector w of the local variables that occur in ~s but not in r. sqvt also builds up the vector xm of the new output arguments of G of which each is associated with a mapping which maps indices in I to types and collects the set J of relevant indices for G. Line (04) initialises these vectors and sets. The (05)-(17) loop iterates through all output arguments. Line (06) narrows the set J of relevant indices. Line (07) determines if it is necessary to introduce a new local variable for the output argument tx under consideration. If not, line (09) adds tx into r and line (10) adds to xm a pair consisting of tx and the mapping for the corresponding output parameter in P. Otherwise, line (12) adds tx to ~s, line (13) adds to w the local variables in tx that do not occur in r or w, line (14) introduces a new local variable z of type all, adds z to z and substitutes z for tx in G, and line (15) adds to xm a pair consisting of z and the mapping for the corresponding output parameter in P. newv(T) creates a new variable of type T. The newly introduced local variable z in line (14) will be renamed and attached with an appropriate type from the mapping paired with it in xm . Line (18) extracts the vector x of the new output arguments of G. fst is a function which, given a pair, returns its rst component while map is a high order function which applies a function f to every element in a vector and collects the vector of the results of the applications of f. Line (19) makes, for each relevant index in J, a new copy of x and types the copy with an appropriate type, and collects the set xcs of all the copies made. For a xed index j 2 J, line (19) does the following for each pair in xm . It rst takes the second component of the pair which is a mapping from indices to types, then nds the type for the index j, and creates a new variable of that type. Line (20) returns with information that is necessary for the heuristic version of `sqvt. Example 2. The following P in ? is the representation of the exists sometimes property in example 1. hsq(o(f1 7! Z< ; 2 7! Z> g); i(Z> )); f1; 2gi Let G = sq(x:Z ; ; y:Z> ) and l = fx:Z ; g. Then sqvt(P; G; l) = (G0; x; xcs;~s; z; r; w) with G0 = sq(z:all; y:Z> ), x = z:all, xcs = fz :Z> g, ~s = x:Z ; , z = z:all, r = ;, and w = fx:Z ; g. 4

?

0

0

[0 20]

0

0

0

[0 20]

2

0

[0 20]

[0 20]

Lemma 1. The time complexity of the test for the extractability of an atom is linear to the size of the atom.

5 Heuristic Derivation Rule With a negative goal being represented by neg(; D) where  is the checklist for the negative goal and D is its digraph, the following is the heuristic version ;sqvt 4

The order relationship between members of r is captured by xm that is a vector.

of `sqvt where loc (D) denotes the set of local variables in D.

{ 1 ; neg(fGg [ ; D); 2 ;sqvt 1; Nl ; 2 for each 1  l  k if 9P 2 ? :sqvt(P; G; loc (D)) = (G0; x; xcs;~s; z; r; w) and N _ N _    _ Nk is !

1

a disjunctive normal form of 2 let w0 = map(newv  typeof ; w) in 0 6 (G0 ^ :9w0: :(~s[w := w0 ] = z))[x := x0] 6 ^0

x 2x 4 @

2

3 17 A 75

_

cs

(G0 ^ (~s[w := w0 ] = z) ^ neg(0 ; D0)[w := w0 ])[x := x0 ] where 0 =  [ fN j link(N; r [ w; D)gnfGg and D0 = delete(r [ w [ fGg; D); { 1 ; neg(fGg [ ; D); 2 ;sqvt 1; Nl ; 2 for each 1  l  k if 9P 2 ? :sqvt(P; G; loc(D)) = (G0 ; x; xcs;~s; z; r; w) and N _ N _    _ Nk is a disjunctive normal form of 3 2 let w0 = map(newv  typeof ; w) in 0 1 77 66 :9x0 :G0[x := x0 ] ?

1

6B ^x0 2x 66 B 6 BB cs

2

CC 77 CC 77 A5

_

(G0 ^ :9w0: :(~s[w := w0 ] = z))[x := x0]

4@

_

(G0 ^ (~s[w := w0 ] = z) ^ neg(0 ; D0)[w := w0 ])[x := x0 ] where 0 =  [ fN j link(N; r [ w; D)gnfGg and D0 = delete(r [ w [ fGg; D); { 1 ; neg(fGg [ ; D); 2 ;sqvt 1; neg(; D); 2 if 8P 2 ? [ ? :sqvt(P; G; loc(D)) = nil; { 1 ; neg(;; ); 2 ;sqvt false. In the above delete(Ns; D) is the result from deleting nodes in Ns from D, link(N; Ns; D) is true if and only if D links node N with some node in Ns, and neg(;; ) represents :true. The third de nition in the above removes from the checklist an atom which doesn't satisfy any exists unique or exists sometimes property. !

?

Example 3. Let add(x; y; z) def = ((x + y) = z). The goal :9x:R ? ; :u:R :(sq(x; y:

R> ) ^ add(x; u; ?1)) is represented as F below where the checklist is the set of [

0

0

20 20]

0

pointers to atoms.

R

sq (x; y:

F = neg(

R?

0

x:

>0)add(x,u,-1)

R

[ 20;20] u:

0

)

The following is an exists unique property. 8y:R> :8x:(sq(x; y) ! x 2 R> _ x 2 R< ) 8y:R> :(9!x :R> :sq(x ; y) ^ 9!x :R< :sq(x ; y)) Using this exists unique property, we have F ;sqvt F , F ;sqvt F , F ;sqvt F and F ;sqvt F and fF ; F ; F ; F g is a frontier of F where F = sq(z :R< ; y:R> )^:9x :R ? ; :(x = z )^sq(z :R> ; y)^:9x :R ? ; :(x = z ) F = sq(z :R< ; y:R> )^:9x :R ? ; :(x = z )^sq(z :R> ; y)^(x :R ? ; = z )^F F = sq(z :R< ; y:R> )^(x :R ? ; = z )^F ^sq(z :R> ; y)^:9x :R ? ; :(x = z ) 0

0

0

1

0

1

2

0

0

0

4

1

2

3

0

2

1

4

0

2

2

1

1

0

0

1

[

20 20]

1

1

2

0

2

1

0

0

1

[

20 20]

1

1

2

0

3

1

0

0

1

[

20 20]

0

3

0

1

5

2

0

[

2

20 20]

2

[

20 20]

2

[

20 20]

2

2

2

6

2

F = sq(z :R< ; y:R> )^(x :R ? ; = z )^F ^sq(z :R> ; y)^(x :R ? ; = z )^F with 4

1

0

0

1

[

R?

add(x1 :

1

20 20]

[ 20;20]; u;

5

2

0

2

[

R?

?1)

add(x2 :

2

20 20]

[ 20;20]; u;

?1)

6

F = neg( ) F = neg( ) R R The following is an exists unique property for addition. 8x:R:y:R:z:(add(x;z; y) ! z 2 R) 8x:R:y:R:9!z:R:add(x;z; y) Using this property, we have F ;sqvt add(x :R ? ; ; v :R; ?1) ^ :9u :R :(u = v ) and F ;sqvt add(x : R ? ; ; v : R; ?1) ^ (u : R = v ) ^ neg(;; ) and F ;sqvt add(x : R ? ; ; v : R; ?1) ^ :9u : R :(u = v ) and F ;sqvt add(x : R ? ; ; v :R; ?1) ^ (u :R = v ) ^ neg(;; ). Since the sub-goals :9u :R :(u = v : R) and :9u : R :(u = v : R) are equivalent to type constraints v : R< and v :R< respectively and neg(;; ) is unsatis able, fadd(x :R ? ; ; v :R< ; ?1)g is a frontier of F and fadd(x :R ? ; ; v :R< ; ?1)g is a frontier of F . :9x : R ? ; :(x = z : R< ) is equivalent to type constraint z : R? , :9x : R ? ; :(x = z :R> ) to z :R> , Solving (x :R ? ; = z :R< ) restricts the types of both x and z to R ? ; whilst solving (x :R ? ; = z :R> ) restricts the types of both x and z to R ? ; . Therefore fF ; F ; F ; F g is a frontier of F where F = sq(z :R? ; y:R> ) ^ sq(z :R> ; y) F = sq(z :R? ; y:R> ) ^ sq(z :R ? ; ; y) ^ add(z ; v :R< ; ?1) F = sq(z :R ? ; ; y:R> ) ^ add(z ; v :R< ; ?1) ^ sq(z :R> ; y:R) F = sq(z :R ? ; ; y:R> )^add(z ; v :R< ; ?1)^sq(z :R ? ; ; y)^add(z ; v :R< ; ?1) None of F ; F ; F and F contain negation. 5

u:

6

0

5

1

5

1

6 [

2

20 20]

[

2

2

0

20 20]

[

2

0

20 20]

0

0

2

2

2

[

2

20 20]

1

20 20] 2

0

1

1

2

20 20]

[

[

1

0

1

2

1

1

[

[

7

20 0]

1

20 20]

2

20 0) (

0

0

6

20

2

1

20 20]

0

0

2

2

1

1

[

1

0

6

2

2

1

1

2

1

1

0

1

1

0

5

[

1

1

2

20 20]

2

1

2

[

u:

2

20 20]

8

20

9

2

0

0

10

0

7

8

1

9

10

1

7

1

[

20 0)

8

9

1

20

[

20

0

0

2

0

20 0)

0

(

1

1

1

0

2

20

2

20 0]

1

0

2

(

2

0

2

20

2

20 0]

2

0

10

6 Complexities

We now analyse the time complexities of ;sqvt and `sqvt. Given a negative goal, a ;sqvt (respectively `sqvt) derivation step extracts an atom out of negation and produces several residual negative goals which are then processed in subsequent ;sqvt (respectively `sqvt ) derivation steps. The time complexity of ;sqvt (respectively `sqvt ) with respect to a negative goal is measured by the time spent on all possible ;sqvt (respectively `sqvt) derivations from the negative goal.

Consider extracting an atom using an exists unique property with k relevant solution subtypes for the atom. The disjunctive normal form of the righthand side of the (QVT) rewrite rule has at most 2k disjuncts. Each of k di erent residual negative goals occurs in 2k? of the 2k disjuncts. Therefore, the negative goal spawns k  2k? occurrences of residual negative goals. If we take A(~uzj rj ) _ A(~uzj:sj /x rj:  rj /x ) ^:9wj: :(~s[rw := rj wj ] = zj ) as atomic when normalising the righthand side of the (SVT) rewrite rule then the negative goal also spawns k  2k? occurrences of residual negative goals when an atom is extracted using an exists sometimes property with k relevant solution subtypes for the atom. 1

~

1

1

When an existence property is used to extract an atom, the number of the relevant solution subtypes of the existence property for the atom may vary. For simplicity, we assume that the number of the relevant solution subtypes be a xed number k for all the atoms and all the existence properties. The relationship between negative goals and the residual negative goals they spawns forms a tree called a spawning tree. Let D consist of n atoms with non-decreasing sizes si ; 1  i  n. Consider rst the time complexity of `sqvt . Each atom in D could ultimately be extracted. Thus, the tree in the worst has n levels and level i has (k  2k? )i? nodes. In the worst case every atom in a node needs be tested for its extractability and an atom with the minimal size is extracted. Thus, the time spent on the extractability tests performed at a level i node is O(ij sj ). Therefore, we have the following result. 1

1

Theorem2. The time complexity of `sqvt is O(i ((k  2k? )i?  ij sj )) 1

1

Now consider the time complexity of ;sqvt. We weigh the ith atom in D by the number wi of those atoms that the share local variables with ith atom and are smaller in size than the ith atom. The following lemma gives the time complexity of the extractability tests performed along a path in the spawning tree for D.

Lemma 3. The time complexity of the extractability tests performed along a path in the spawning tree for D is O(i (wi + 1)  si ). The above lemma states that in the worst case the nth atom will be tested at levels n; (n ? 1);    ; n ? wn, the (n ? 1)th atom at levels (n ? 1); (n ? 2);    ; (n ? 1) ? wn? , and so on. This gives rise to the following result. 1

Theorem4. The time complexity of ;sqvt is O(j sj  [j ?w ij (k  2k? )i? ]) When an atom in D shares with every other atom, the time complexity of ;sqvt is the same as that of `sqvt since wi = i ? 1. When wi is much smaller, which is usually the case, ;sqvt is much fast than `sqvt. The following two examples 1

1

j

illustrate those points.

Example 4. Let p be of arity 2 with the following exists unique property.

8x:all:8y:(p(x; y) ! y 2 all) 8x:all:9!y:all:p(x; y)

Let D be the digraph for :9x :all:    xn :all:(p(xn; xn ) ^    ^ p(xi? ; xi) ^    ^ p(x ; x )) We have k = 1, si = 2 and wi = 1. ;sqvt takes O(i 2  2) = O(n) time to prove the falsity of D where `sqvt takes O(i 2  i) = O(n ) time. 2

+1

+1

1

2

1

2

Example 5. Let p ;    ; pn be predicates with pi being of arity i + 1 which has the following exists unique property. 8x :all:    xi:all:8xi :(pi(x ;    ; xi; xi ) ! xi 2 all) 8x :all:    xi:all:9!xi :all:pi (x ;    ; xi; xi ) Let D be the digraph for :9x :all:    xn :all:(pn(x ; x ;    ; xn ) ^    ^ p (x ; x )) We have k = 1, si = i+1 and wi = i?1. Both `sqvt and ;sqvt take O(i (i+1)(i?1)) time to prove the falsity of the negative goal D. 1

1

+1

1

1

2

+1

+1

1

2

+1

1

+1

+1

+1

1

1

2

7 Conclusion We have presented a heuristic method for implementing the constructive negation approach in [4]. The method uses a digraph to represent a negative goal so as to avoid futile extractability tests of atoms in the negative goal. The complexity of the method is analysed. An algorithm is presented that does the extractability test given an atom and an existence property and introducs new local variables into the atom to make it satisfy the existence property. The complexity of the algorithm is linear in size of the atom.

References 1. D. Chan. Constructive Negation Based on the Completed Database. In R. A. Kowalski and K. A. Bowen, editors, Proceedings of the Fifth International Conference and Symposium on Logic Programming, pages 111{125. The MIT Press, 1988. 2. D. Chan. An Extension of Constructive Negation and its Application in Coroutining. In Ewing L. Lusk and Ross A. Overbeek, editors, Proceedings of the North American Conference on Logic Programming, pages 477{496, 1989. 3. J.G. Cleary. Constructive Negation of Arithmetic Constraints Using Data-Flow Graphs. Constraints: An International Journal, 2:131{162, 1997. 4. J.G. Cleary and L. Lu. Constructive Negation Using Typed Existence Properties. To appear in Proceedings of PLILP/ALP98. Springer-Verlag, 1998. http://www.cs.waikato.ac.nz/lunjin/cneg.ps. 5. W. Drabent. What Is Failure? An Approach to Constructive Negation. Acta Informatica, 32:27{59, 1995. 6. F. Fages. Constructive Negation by Pruning. Journal of Logic Programming, 32(2):85{ 118, 1997. 7. J. Maluszynski and T. Naslund. Fail Substitutions for Negation as Failure. In Ewing L. Lusk and Ross A. Overbeek, editors, Proceedings of the North American Conference on Logic Programming, pages 461{476. The MIT Press, 1989. 8. P.J. Stuckey. Negation and Constraint Logic Programming. Information and Computation, 118:12{33, 1995.

This article was processed using the LaTEX macro package with LLNCS style