first-order theories for pure prolog programs with negation

32
Arch. Math. Logic (t995) 34: 113-144 Archive fo~ Mathematical Logic Springer-Verlag 1995 First-order theories for pure Prolog programs with negation Robert F. St/irk* Mathematisches Institut, UniversitS.tMiinchen, Theresienstrage39, D-80333 Miinchen, Germany e-mail: staerk @rz.malhematik.uni-muenchen.de Received October 10, 1994 / in revised form February 3, 1995 Abstract The standard theory of logic programming is not applicable to Prolog pro- grams even not to pure code. Modifying the theory to take account of reality more is the motivation of this article. For this purpose we introduce the f-completion and the inductive extension of a logic program. Both are first-order theories in a language with operators for success, failure and termination of goals. The g-completion of a logic program is a sound and complete axiomatization of the Prolog depth-first search under certain natural conditions; the inductive extension of the f-completion is a suit- able theory for proving termination and equivalence of pure Prolog programs with negation. 1 Introduction There are several reasons that the standard theory of logic programming cannot be applied to Prolog programs. The main reason is the search strategy of Prolog. In gen- eral, the search strategy of a logic programming system consists of two components: the literal selection rule and the clause selection rule. The literal selection rule (also called computation rule or simply selection rule) says in each step of a computation which literal of the goal has to be selected. The clause selection rule says which clause of the logic program has to be tried. It is well-known that for definite Horn clause programs SLD-resolution is inde- pendent of the literal selection rule. Independence means, that if a goal succeeds under one rule, then it will succeed under every rule. In the context of negation, however, the situation changes. It is no longer true that SLDNF-resolution is independent of the literal selection rule. As remarked by Shepherdson in [24], it may happen that a goal succeeds under one rule and loops under another rule. Since Prolog always selects the leftmost literal in a goal and uses the order of the clauses in the program as a fixed order in which they are to be tried, the various completeness results, linking the procedural and declarative semantics of logic pro- grams, cannot be applied to Prolog programs. This is one of the reasons for the gap between theory and practice in logic programming. * Sponsored by the Alexander von HumboldtFoundation, Germany

Upload: robert-f

Post on 08-Dec-2016

216 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: First-order theories for pure Prolog programs with negation

Arch. Math. Logic (t995) 34: 113-144 Archive fo~

Mathematical Logic

�9 Springer-Verlag 1995

First-order theories for pure Prolog programs with negation

Robert F. St/irk*

Mathematisches Institut, UniversitS.t Miinchen, Theresienstrage 39, D-80333 Miinchen, Germany e-mail: staerk @rz.malhematik.uni-muenchen.de

Received October 10, 1994 / in revised form February 3, 1995

Abstract The standard theory of logic programming is not applicable to Prolog pro- grams even not to pure code. Modifying the theory to take account of reality more is the motivation of this article. For this purpose we introduce the f-completion and the inductive extension of a logic program. Both are first-order theories in a language with operators for success, failure and termination of goals. The g-completion of a logic program is a sound and complete axiomatization of the Prolog depth-first search under certain natural conditions; the inductive extension of the f-completion is a suit- able theory for proving termination and equivalence of pure Prolog programs with negation.

1 Introduction

There are several reasons that the standard theory of logic programming cannot be applied to Prolog programs. The main reason is the search strategy of Prolog. In gen- eral, the search strategy of a logic programming system consists of two components: the literal selection rule and the clause selection rule. The literal selection rule (also called computation rule or simply selection rule) says in each step of a computation which literal of the goal has to be selected. The clause selection rule says which clause of the logic program has to be tried.

It is well-known that for definite Horn clause programs SLD-resolution is inde- pendent of the literal selection rule. Independence means, that if a goal succeeds under one rule, then it will succeed under every rule. In the context of negation, however, the situation changes. It is no longer true that SLDNF-resolution is independent of the literal selection rule. As remarked by Shepherdson in [24], it may happen that a goal succeeds under one rule and loops under another rule.

Since Prolog always selects the leftmost literal in a goal and uses the order of the clauses in the program as a fixed order in which they are to be tried, the various completeness results, linking the procedural and declarative semantics of logic pro- grams, cannot be applied to Prolog programs. This is one of the reasons for the gap between theory and practice in logic programming.

* Sponsored by the Alexander von Humboldt Foundation, Germany

Page 2: First-order theories for pure Prolog programs with negation

114 R.F. St~k

Another reason is that completeness is usually obtained only for very restricted classes of logic programs like, for instance, allowed programs. Allowedness is the syntactic condition that in every clause every variable must occur also in a positive literal of the body. This condition is very stringent and excludes many common Prolog constructs. Both clauses in the definition of the standard meraber/2 predicate are not allowed.

A third reason which makes it difficult to apply the theory of logic programming is that the completeness result of Kunen [17] and its extension in [30] are for three- valued logic and not for classical two-valued logic.

In this article we try to solve these problems. We introduce a new modified com- pletion of a logic program, called the g-completion of a logic program, which is tailored for the Prolog search strategy. The g-completion is a first-order theory in a language with three operators S, F and T. For every goal G we construct first-order formulas S G, F G and T G expressing success, failure and (universal) termination of the goal. If a goal G succeeds (resp. fails) under Prolog-resolution, then the for- mula S G (resp. F G) is provable from the g-completion of the program. This result is true for arbitrary goals and logic programs. The converse can only be proved for strongly terminating, non-floundering goals. A goal is called strongly terminating if every possible SLDNF-derivation using the Prolog literal selection rule is finite. We show that for each non-floundering goal G the formula T G is provable from the g-completion of the logic program if, and only if, the goal G is strongly terminat- ing. Moreover, if the formula T G A S G (resp. T G A F G) is provable from the g-completion and the goal G does not flounder, then G succeeds (resp. fails) under the Prolog depth-first search.

The restriction to non-floundering goals is not essential. We show that if a program and a goal are correct with respect to some mode assignment, then the goal does not flounder. The notion of a mode is very familiar to Prolog programmers. A mode declares some arguments of a predicate as input arguments and some arguments as output arguments. The remaining arguments are just the usual logical arguments. To every predicate a finite set of modes is assigned. A program (goal) is called correct with respect to a mode assignment if it satisfies certain natural syntactic conditions which can be checked efficiently (by an algorithm which we introduce in this article). Since one has always some modes in mind, when one writes Prolog predicates, we believe that most goals and programs of practical interest do not flounder.

Finally we extend the g-completion by suitable induction principles to the so called inductive extension of logic programs. This first-order theory is used as a meta- theory for doing (fully formalized) termination and equivalence proofs of pure Prolog programs with negation. Our results imply for example the following: If the formula Vz(S l i s t ( z ) --+ T r(z)) is provable in the inductive extension of a logic program, then the goal r(t) terminates under the Prolog depth-first search for every list t. The usefulness of the inductive extension is shown with a non-trivial example program from the field of parsing.

This article is an extended version of [29].

2 Related work

Andrews introduces in [1] a logical semantics for depth-first Prolog which is based on fold/unfold transformations.

Apt and Pedreschi study in [5] the termination of logic programs under the Pro- log selection rule. They introduce the notion of acceptable programs and prove that

Page 3: First-order theories for pure Prolog programs with negation

First-order theories for pure Prolog programswith negation 115

acceptable programs and bounded goals terminate under the Prolog depth-first search. In order to show that a program is acceptable one has to find a Herbrand model of the completion of the program and a level mapping such that certain conditions are satisfied. Our approach is different. We prove inside the inductive extension of a program, in classical first-order logic using appropriate induction axioms, that a goal strongly terminates under the Prolog depth-first search.

The Apt-Pedreschi method may be of greater value in practice. However, if a program is acceptable then its completion has exactly one Herbrand model. In this model an atom is true if and only if it succeeds. Thus in order to apply the Apt- Pedreschi method one has to know in advance the set of atoms that succeed from the program. This is not necessary in our approach. In our approach one can prove that a program terminates in Prolog without knowing the set of atoms that succeed from the program.

Apt introduces in [3] a Hoare-like formalism for verification of logic programs. The results he obtains are applicable to terminating logic programs, i.e. logic programs which have the property that every ground atom A does not flounder and every possible LDNF-computation of A is finite. In our approach the termination proofs can be done inside the verification process.

B/Srger and Rosenzweig use in [6] the framework of evolving algebras of Gurevich for a semantics of full Prolog including non-logical features like cut, assert andfindall. Their model directly reflects the basic intuitions underlying the implementation of the language. The logical background of Prolog however gets lost. Their description is a pseudocode over abstract data. Our approach can only treat a subset of Prolog, because we use purely logical methods.

Drabent proves in [ 10] completeness of SLDNF-resolution for arbitrary programs, fair selection rules and non-floundering goals with respect to Kunen's three-valued semantics. The Prolog selection rule we consider in this article is not fair, and thus the results of Drabent are independent from ours.

Fitting uses in [12] many-valued logics as a general basis for semantics of logic programs. Our g-completion can be viewed as a many-valued system too. It is for- mulated, however, as a classical two-valued theory. We simply extend the language with three new predicates R s, R e, R t for every predicate symbol R. This corresponds to a eight-valued system.

Shepherdson extends in [25] a deductive Prolog calculus of Mints [20] to SLDNF- resolution. In this calculus a goal G is derivable if, and only if, G succeeds in Prolog. The expression ( '-0G is derivable in the calculus if, and only if G fails in Prolog. Our g-completion is not a deductive calculus. It is a first-order theory. Shepherdson and Mints can handle the Prolog cut. This is not possible in our formalism.

Stroetmann proves in [31] also a completeness theorem for the Prolog selection rule. He proves completeness under the assumption that there exists a well-founded relation on the terms of a program such that the terms in the body of a clause are smaller than the terms in the head. We show in this article that, if a goal is provably terminating, then it terminates under Prolog. Therefore, in our completeness proof we cannot assume that the program is terminating as Stroetmann does.

3 Basic notions

Let S be a first order language given by a set of function symbols and a set of predicate symbols. The function symbols of arity zero are called constants. The terms

Page 4: First-order theories for pure Prolog programs with negation

116 R.F. St~k

[a, b, s, t] 1 o f ~ are built up from variables [u, v, x, y, z] and function symbols [f , g]; terms are of the form x or f ( t l , . . . ,t,0. Atoms [A, B] are built up with predicate symbols [Q, _R] and are of the form R( t l , . . . , t • ) . An atom is called ground if it does not contain any variable. Literals [L, M] are atoms or negated atoms of the form -~A. Formulas [cp, X, ~b] are of the form s = t, R ( t l , . . . , tn), T, • -,~, ~ A ~b,

V % ~ --* ~b, ~ ~ r Vx ~ or 3x ~. We write s 5i t for ~(s = t). The set of positive formulas is the least set of formulas .~g" such that

1. s = t, s 5r and R ( t l , . . . , t ~ ) are in ~ , 2. if ~ and ~b are in ~c~, then ~ A ~b, ~ V ~b, Vx ~ and 3x ~ are in ~ .

Predicate symbols occur only positively in such formulas. The equality symbol can occur negatively in a positive formula.

The vector notation v is used as shorthand for a finite string Vl , . . . , vn whose length will be specified by the context. The universal closure of a formula ~ is denoted by V(~). We write qo[x] to indicate that all free variables of qo are from the list x; a formula ~(x) may contain other free variables than the variables x. The notion T F T means that the formula ~ is derivable from the theory T using the rules of the classical first-order predicate calculus with equality. The notion 9,1 h ~ means that V(~) is true in the structure 9.1.

Goals [G, H] are finite sequences of literals; Z is the empty goal. If G is the goal L 1 , . . . , Lm and H is the goal M 1 , . . . , Mn then we write G* H for the concatenation L 1 , . . . , L m , M 1 , . . . , M s of G and H; A . G is the goal A, L 1 , . . . , L m . A clause [C] is an expression of the form A : - G. The symbol " : - " is read as "if". The atom A is the head of the clause and G is the body of the clause. In the literature clauses with empty bodies are often called facts and clauses with non-empty bodies are called rules. In examples we identify facts B : - Z with B. The equality symbol does not occur in goals and clauses. A logic program [P] is a finite set of clauses.

For notions like substitutions [0, a, T] and the identity substitution ~ we refer to Apt [2], Doets [9] or Lloyd [18]. If the two atoms A and B are unifiable then mgu(A, B) denotes an idempotent most general unifier of A and B. Throughout the article P denotes a logic program.

4 The ~-completion of logic programs

In this section we introduce the g-completion of a logic program. The g stands for the leftmost literal selection rule of Prolog. The g-completion is formulated in an

extended language ~ . For every predicate symbol R of S we take in ~ three new predicate symbols R s, R f and R t of the same arity as R. The intended meaning of R s, R f and R t is: R succeeds, R fails and R strongly terminates. The function

symbols of ~ are the same as in ~ . We define three operators S, F and T which transform goals of the language S

into 2~-formulas. S, F and T are not basic symbols of the language, they are defined. For S- l i te ra ls L the expressions S L, F L and T L are defined as follows:

$ R(t) := RS(t), F R(t) := Rf ( t ) , T R(t) := R t ( t ) ,

S-~A : = F A , F- ,A : = S A , T ~ A : = T A .

1 In brackets we indicate the meta-symbols for the syntactic categories.

Page 5: First-order theories for pure Prolog programs with negation

F i r s t - o r d e r t h e o r i e s f o r p u r e P r o l o g p r o g r a m s w i t h n e g a t i o n 1 1 7

For ~ - g o a l s with more than one literal the operators S, F and T are defined in the following way:

S ( L , G ) : = S L A S G , F ( L , G ) : = F L V F G , T ( L * G ) : = T L A ( F L V T G ) .

For the empty goal ~ we set $ O := T, F:O := _L and TO := 7-. The operators S and F do not respect the ordering of literals in a goal. The operator T, however, does. Therefore in the following we will consider the operators S and F always in connection with T. The success of a goal G, for instance, will be expressed by the formula T G/x S G; the failure of G will be expressed by T G/x F G. The formulas S G and F G alone, without T G, express success and failure of G in SLDNF-resolution. Together, with T G, the formulas S GAT G and F G/xT G express success and failure of G in LDNF-resolution (see Sect. 5).

For each program P and n-ary predicate symbol R we define three ~- formulas S~, F ~ and T~. S~ is called the success formula of R with respect to P; F ~ is called the failure formula of R with respect to P; T~ is called the termination formula of R with respect to P. We assume that there are m clauses in P whose heads are of the form R(. . . ) and that the ith clause is of the form R(ti,1 [y ] , . . . , tw~[y]):- Hi[y].

S~[x l , . . . , xn] := 3y x 5 =ti , j [y] A S H i [ y , i = l ~ j = l

F~[Xl , . . . ,x,~] : = / ~ V y xj = ti,j[y] --+ F H d y ] , i = l \ j = l

TP[zl,... ,Xn] : = / )~Vy xj = ti,j[y] ~ THi[y] . i=1 \ j = l

Since these formulas have the obvious positive equivalents, they will be considered positive themselves.

The formula S~[x] means: there exists a clause in P which defines R and there exist parameters y of the clause such that the head matches with x and the body of the clause succeeds.

The formula Fff[x] means: for all clauses in P which define R, for all parameters y of the clause, if the head matches with x then the body of the clause fails.

The formula Tff[x] means: for all clauses in P which define R, for all parame- ters y of the clause, if the head matches with x then the body of the clause strongly terminates.

Definition 4.1. The /-completion of a logic program P, [comp(P), comprises the

universal closures of the following ~- formulas for each predicate symbol R of S and goal G:

A1. S~Ex] ~ RS(x), A2. F~[x] --+ Re(x), A3. T~[x] ~ Rt(x), A4. the axioms of Clark's equational theory CET, A5. ~(S G A F G), A6. T G - * S G V F G .

Clark's equational theory CET consists of the following two axiom schemata for t e r m s s 1 ~ . . . ~ 8 n , ~1 ~ �9 - - ~ ~ n and a, b:

Page 6: First-order theories for pure Prolog programs with negation

118 R.F. St~irk

El . ~(sl = tl A . . . Asn = t~), if the set of equations {Sl = t l , . . . , sn = tn} is not unifiable.

E2. sl = t l A . . . A s n = t n ' - + a = b , if the set of equations {Sl = t l , . . . , s~ = tn} is unifiable and a a = bey for a most general unifier (7 of {sl = t l , . . . , s~ = tn}.

This formulation of CET differs from Clark's original version, but using the results of [7] it is easy to see that both versions are equivalent.

One can derive the axioms A5 and A6 from the following two more elementary axioms:

U. ~(RS(x) A Rf(x)) T. Rt(x) ~ RS(x) V Rf(x)

By U and T we mean the collection of the axioms for all predicate symbols _R of 2~. U stands for uniqueness and T for termination or totality.

If one omits the axioms A3 and A6 in the definition of the g-completion, then one obtains a weaker theory which has the same strength as the three-valued completion in the sense of Fitting [11] and Kunen [16]. To see this one has to interpret R s with the part of R that is true and R f with the part of R that is false. The predicates /:~t are not used in the weaker theory.

If one omits the axioms A3, A5 and A6, then one obtains the partial completion of J/iger [14] and Stgrk [28] or the doubled program of Van Gelder and Sehlipf [33].

If one omits axiom A3 and changes axiom A6 to S G V F G, then one obtains a theory which is equivalent to Clark's completion in [7]. The axiom S G v F G, however, is too strong. It expresses that every goal either succeeds of fails. This is not true in general, since a goal can loop.

In the g-completion we weaken $ G V F G to T G ~ $ G v F G, since for strongly terminating goals it is true that they either succeed or fail. The axioms A5 and A6 together yield

T G ~ ( F G ~ - ~ S G ) . In this way it is expressed that for strongly terminating goals negation as failure is classical negation.

How can we construct models of the g-completion? For each logic program P we define a monotonic operator Fp which assigns to an ~ - s t r u c t u r e 9.1 a new struc-

ture/ 'p(92). We consider the usual partial ordering between ;~-structures. The notion 92.1 _< ~3 means that 92.1 and ~3 have the same universe, the same interpretation of

the function symbols and that 9.1(Q) _c ~3(Q) for every predicate symbol Q of S . 9.1(Q) denotes the extension of the predicate Q in the structure 92. Positive formulas are monotonic with respect to this ordering. If qa[x] is a positive formula, 92.1 _< ~3, a E 1921 and 92.1 ~ ~[a], then also ~3 ~ (y[a].

The operator Fp is defined in the following way. The structure Fp(92) has the same universe and the same interpretation of function symbols as the structure 92.1.

The extensions of the predicates of ~ in the structure Fp(92) are given by

rp(92)(R S) := {(a> -92 ~ s,~[a]}, rp(92)(R f) := {(a) " 9.1 ~ FP[a ]} , Cp(92)(R t) := {{a)" 92 ~ Tff[a]}.

The ope ra to r / ' p is a generalization of the van Emden-Kowalski operator Tp in [32]. It is also a generalization of Fitting's (~p operator in [11] or Kunen's operator ext in [16].

Page 7: First-order theories for pure Prolog programs with negation

First-order theories for pure Prolog programswith negation 119

Lemma 4.2. Let 92, ~3 be ~-structures.

1. If92 <_ ~3 then Fp(92) <_ Fp(~) . 2. If92 satisfies CET, U and T, then92 ~ gcomp(P) r Fp(92) <_ ~. 3. If92 satisfies U, then f p(92) satisfies U. 4. 1f92 satisfies T, then 1"p(92) satisfies T.

The definition of the stages of the operator Fp is canonical:

Definition 4.3. Let 92 be an S-s t ruc ture so that 92(Q) = 0 for each predicate sym-

bol Q of ~ . Then one defines for ordinal numbers c~ the stages 1P'm in the following way:

i P , 9.1 . p , ~ P, fa o~ ~ -o~ . :=92, o + , ) , : : U := U

a<A c~COn

It is easy to see that Iff ,~t < rP'9~ provided that a < /3. Therefore we obtain the following proposition (cf. Moschovakis [21]):

Proposition 4.4. Let 91 be an ~-structure with the empty interpretation for the pred- icate symbols. Then Io~ 9~ is the least fixed point o f l " p o v e r 92 and I ~ ~ is a model of the g-completion of P.

The results of [9] and [16] on the closure ordinal of ext and ~bp can be transformed to the operator Fp without any problems.

5 An operational model of LDNF-resolution

LDNF-resolution is the procedural counterpart to the &completion. It has been in- vestigated by Apt and Pedreschi in [4, 5]. They introduce LDNF-resolution as SLDNF-resolution with the Prolog literal selection rule which always selects the left-most literal in a goal. We choose a different approach. We describe LDNF- computations directly by eight transformations rules for the states of a Prolog based interpreter/compiler. The transformation rules reflect the stack based efficient memory management of commonly used Prolog systems.

Let P be a logic program. Frames [E, F] are triples frm(G, I, cO consisting of a goal G, a subset I of clauses of the logic program P and a substitution or. The set I is called the set of unused clauses of the frame. We always have I C_ P. The goal G can be the empty goal. The substitution a can act on variables that do not occur in the goal G. A frame stack IS] is a stack of frames, i. e. a finite list (F~ . . . Fn), n _> 0, of frames. The frame Fn is called the topmost frame of the frame stack. The empty frame stack is denoted by 0-

A state of an LDNF-computation for the program P is a non-empty stack of frame stacks. In other words, a state is a finite list ($1 . . . S,0, n _> 1, of frame stacks. The list is sometimes also called the main stack of the computation. The frame Sn is called the topmost frame stack of the state.

We use the vector notation S as a shorthand for $1 . . . Sn. We omit the enclosing angle brackets of the main stack, i. e. we write, for example, S (F) instead of (S (F)) for the state that appends the frame stack F at the end of the state S.

The initial state for a goal G with respect to the logic program P is denoted by initp(G) and consists of exactly one frame stack S. The frame stack S consists of

Page 8: First-order theories for pure Prolog programs with negation

120 R.F. Stark

the single frame frm(G, P, e). The set of unused clauses of the frame is the whole program P and the substitution of the frame is the identity substitution. We thus have initp(G) = ( ([rm(G, P, e)) ).

An LDNF-computation with respect to P starts with some initial state initp(G). Then there are the following four possibilities.

1. The computation does not terminate. 2. The computation terminates with success and returns the answer y e s ( a ) , 3. The computation terminates with failure and returns the answer no. 4. The computation terminates and returns the error message floundering.

The following transformation rules transform a main stack into a new main stack. Case 1. The topmost frame stack of the main stack is not empty: Case 1.1. The goal of the topmost frame is not empty: Case 1.1.1. The first literal of the goal is positive: We assume that the main stack

is of the form S <F frm(A * G, I, O-)). If there exists a standardized apart variant B : - H of a clause C in the set of unused clauses I such that the head B is unifiable with Ao-, then we can make a resolution step: Let r be the most general unifier of Ao- and B. In the set I the clause C is deleted and the new triple frm(H * G, P, aT) is pushed on top of the topmost frame stack. The main stack is now of the form S <F frm(A * G, J, O-) frm(H * G, P, O-~-)}, where J is I \ {C}. If later backtracking starts, then we have to know that the clause C has already been used for A. This is the reason that it is deleted from the set I .

If there exists no standardized apart variant B : - H of a clause C in I such that the head B is unifiable with Ao- then we make a backtracking step: The topmost triple of the frame stack is popped. The state is now of the form S (F). This means that we have more or less an old state, but the set of unused clauses in this state is smaller than it was before.

Standardizing apart means the following (cf. Shepherdson [26]): The clause is renamed in a canonical way such that it does not contain any variable which occurs somewhere in a goal or a substitution of a frame of the current main stack. In partic- ular, we have Ho- = H in a resolution step. By standardizing apart one prevents that a variable which disappears in a goal via a resolution step is introduced afterwards again by a new clause in a further resolution step.

Case 1.1.2. The first literal of the goal is negative: In this case the main stack is of the form S <F frm(~A * G, I, O-)>. If the negative literal -~Ao- is not ground then the computation terminates and returns the error message f l o u n d e r i n g . If the negative literal -~Ao- is ground then we can start a subcomputation. A new frame stack is created and pushed on the main stack. The first frame of this new frame stack is the triple frm(A, P, O-). The set of unused clauses for the new goal A is the whole program P. The main stack is now of the form S <F frm(-~A.G, I, a)) ([rm(A, P, O-)).

Case 1.2. The goal of the topmost frame is empty: Case 1.2.1. There is only one frame stack on the main stack: In this case we

have a global success and the computation terminates. The main stack is of the form (F frm(o, I , O-)). The substitution O- restricted to the variables of the initial goal G in the first frame of F is returned as y e s ( o - I vars(G)).

Case 1.2.2. There are more than one frame stacks on the main stack: In this case the main stack is of the form S (F frm(~A �9 G, I, O-)> (E frm(O, J, T)> and we have a success of a subcomputation. Note, that the topmost frame stack (the so called subcomputation) has been started by the atom Ao-. Since Ao- succeeds, the literal ~Ao- fails and we have to backtrack. The stack is transformed to S <F).

Page 9: First-order theories for pure Prolog programs with negation

First-order theories for pure Prolog programswith negation 121

Case 2. The topmost frame stack of the main stack is empty: Case 2.1. The main stack contains more than one frame stack: In this case the

main stack is of the form S <F frm(-~A * G, I , o-)) <) and we have a failure of a subcomputation. The atom Ao- which has started the subcomputation fails, hence the literal ~Ao- succeeds and we can delete it from the goal. The empty frame stack is popped from the main stack, i. e. the main stack is transformed into the state S <F frm(G, P, or)). The set of unused clauses for the new goal G is the whole program P .

Case 2.2. The main stack consist of the single empty frame stack: In this case we have a global failure and the answer n o is returned.

The transformation rules for LDNF-resolution can be written in a more compact way as follows:

L1. Resolution step: S (F frm(A * G, I, cr)) ~ S (F frm(A * G, J, o-) f rm(H �9 G, P, ~r-c)), if there exists a clause C C I such that for the standardized apart variant B : - H of C the head B is unifiable with Ao-, -r = mgu(Ao-, B), and J is the set I \ {C}.

L2. Backtrack step: S (F frm(A �9 G, I , o-)) ~ S (F), if A~r is not unifiable with the head B of the standardized apart variant B : - H of any clause C E I.

L3. Floundering: S (F frm(-~A * G, I, o-)) ~ floundering, if Act is not ground.

L4. Subcomputation step: S (F f rm(~A * G, I, or)) ~ S <F frm(-~A * G, I, cr)) (frm(A, P, o-)), if Act is ground.

L5. Global success: (F frm(O, I, 0)) ~ yes(o" I vars(G)), where G is the goal of the first frame of F.

L6. Success of a subcomputation: S (F frm(-~A * G, I , o-)) (E frm(O, or, T)) ~ S (F).

L7. Failure of a subcomputation: S (F frm(-~A * G, I, cr)) () ~ S <F frm(G, P, ~r)).

L8. Global failure: <> n o .

An LDNF-computation (with respect to the program P) is a finite or infinite sequence So, $1,. �9 �9 of states such that for all i the state Si can by transformed into the state Si+~ by one of the eight rules L1-L8.

The transformation rules L2-L8 are deterministic. At most one of them can be applied to a state. Rule L1, however, is non-deterministic. One can choose an arbitrary clause of the set of unused clauses I . This is the difference to the usual Prolog search. In Prolog a program is not a set of clauses but a sequence of clauses. The ordering of the clauses is given by the order in which they are written in the program.

The model described in L1-L8 can be easily modified to accommodate Prolog's behavior with regard to clause choice. In the Prolog computation model the set of unused clauses in a frame is not a set but a finite sequence. In a resolution step always the first clause in the sequence of unused clauses has to be tried and not an arbitrary one.

Page 10: First-order theories for pure Prolog programs with negation

122 R.F. St~k

It may happen that the Prolog computation of a goal does not terminate, whereas there are terminating LDNF-computations for the goal. Take, for example, the program with the rule q : - q and the fact q. If one starts a computation with the goal q, then Prolog always tries the first clause, the rule q : - q, and the computation does not terminate. In LDNF-resolution, however, the goal q has a successful computation. One simply takes the fact q in the first resolution step and immediately gets the empty goal.

For most programs used in practice, however, all LDNF-computations terminate on the intended inputs. If there is a solution in LDNF-resolution for a goal, then Prolog will compute the solution as well.

The ordering of the literals in the bodies of the clauses cannot be neglected. The difference between LDNF-resolution and SLDNF-resolution is that in LDNF- resolution the ordering of the literals is taken into consideration whereas in SLDNF- resolution the bodies of clauses are considered as multisets, as unordered sequences of literals.

Definition 5.1. 1. A goal G returns the answer c~ in LDNF-resolution (with respect to the logic program P) if there exists an LDNF-computation which starts in the state inite(G) and terminates with the answer y e s ( a ) .

2. A goal G fails in LDNF-resolution (with respect to the logic program P) if there exists an LDNF-computation which starts in the state inite(G) and terminates with the answer no.

3. A goal G strongly terminates in LDNF-resolution (with respect to the logic pro- gram P) if every LDNF-computation which starts in the state initp(G) is finite and returns an answer yes(or) or the answer no.

4. A goal G flounders in LDNF-resolution (with respect to the logic program P) if there exists an LDNF-computation which starts in the state initp(G) and stops with the error message floundering.

These four notions can be characterized directly without frames and stacks. We define below for each logic program P four sets N(P), IF(P), T(P) and S(P) such that we have the following: a goal G returns cr iff (G, or) E It~(P); a goal G fails iff G E IF(P); a goal G strongly terminates iff G E T(P); a goal G does not flounder (i.e. it is safe) iff G e ~(P).

Definition 5.2. We write G I~v(P) 0 for <G, 0) E IRv(P). V is a set of protected variables. Let Nv(P) and IF(P) be the least sets which are closed under the following six conditions:

R1. 0 R v ( P ) e. R2. Let B : - H be a variant of a clause of P which contains no variables from V

or A �9 G. Let ~ = mgu(A, B) and W = V [3 (vars(Acr) \ vars(tIt7 �9 GtT)). If (H * G)cr I~w(P) T, then A * G I~v(P) (~r'r) ~ vars(A * G).

R3. If A is ground, A E ~(P) and G I~v(P) O, then -~A * G ]Rv(P) O. F1. Let P(A) be the collection of all clauses of P which have a variant so that its

head is unifiable with A. If for each element of/5(A) there exists a variant B : - H containing no variables from A * G so that (H * G)a E IF(P) for cr = mgu(A, B), then A * G E IF(P).

Fi. If A is ground and A II%~(P) e, then --,A �9 G E IF(P). F3. If A is ground, A E IF(P) and G E ]F(P), then -~A * G E 1F(P).

We write G II~(P) 0 for G I ~ ( P ) 0.

Page 11: First-order theories for pure Prolog programs with negation

First-order theories for pure Prolog programswith negation 123

Definition 5.3. The set q~(P) is the least set of goals which is closed under the following four conditions:

T1. o E T(P). T2. Let P(A) be the collection of all clauses of P which have a variant so that its

head is unifiable with A. If for each element of/5(A) there exists a variant B : - H containing no variables from A �9 G so that (H �9 G)e E T(P) for e = mgu(A, B), then A * G E T(P).

T3. If A is ground, A E T(P) and A II~(P) e, then ~A �9 G E ~I'(P). T4. If A is ground, A E ~(P) and G E ~Y(P), then -,A �9 G c T(P).

Definition 5.4. The set g(P) is the largest set of goals which satisfies the following four conditions:

S 1. If G E ~(P) then, G~r E ~(P) for every substitution e. $2. If A* G E ~(P), (B : - H) E P and A = Be, then H e * G E ~(P). $3. If ~A * G E 5(P), then A is ground and A E 5(P). $4. If ~A * G E S(P) and A E F(P), then G E S(P).

Note, that the set ]I'(P) is inductively defined and the set $(P) is co-inductively defined. ~(P) is a least set satisfying some conditions; ~(P) is a largest set satisfying some conditions. S(P) is the union of all sets of goals that satisfy conditions S 1-$4. The ~ in the set of safe goals ~(P) should not be confused with the operator $ in S G which expresses the success of G.

Theorem 5.5. Let P be a logic program and G be a goal.

1. G returns the answer e in LDNF-resolution wrt. P if, and only if, G IR(P) c~. 2. G fails in LDNF-resolution wrt. P if, and only if, G E F(P). 3. G strongly terminates in LDNF-resolution wrt. P if, and only if, G E V(P). 4. G does not flounder in LDNF-resolution wrt. P if, and only if, G E 5(P).

Proof. We only show assertion 4, since it is not obvious. 4.1. Assume that the goal Go does not flounder. Let ~ be the sets of goals G

that have the following property: there exists a state reachable from the initial state initp(Go) so that the topmost frame of the topmost frame stack of the state is of the form frm(G', I , e ' ) and there exists a substitution 0 such that G = G'e'O. Obviously, the goal Go belongs to , ~ . We claim that ~ satisfies the conditions S1-$4 of Definition 5.4. Since g(P) is the largest set of goals that satisfies S1-$4, ~ is a subset of S(P) and thus the goal Go is in S(P).

Case S1. By definition, ~ is closed under substitutions. Case $2. Assume that A * G E ,~f', (B : - H) E P and A = BT. Then, there exists

a state of the form S (F f rm(A' �9 G', I , ~')) which is reachable from initp(Go) and a substitution 0 such that A * G = (A t �9 G')e'O. Let B ' : - H ' the standardized apart variant of B : - H. Since By = A = Xa 'O , the atoms A ' a ' and B ' are unifiable. Let "r' = mgu(A' e' , B') .

There exists a substitution 0' such that H'r �9 G = (H' * G')a'~-'O'. By a resolution step L1 we obtain a state with a topmost frame f rm(H' * G', P, ~r'C). Thus, we see that the goal H~- * G is in .~" as well.

Cases $3 and $4. Assume that ~A * G E ~ . By the definition of ~ , there exists a state of the form S (F f r m ( ~ X �9 G', I , a')) which is reachable from initp(Go) and a substitution 0' such that ~ A * G = (~A ' * G')~r'O'. Since Go does not flounder, the atom A'~ ' is ground, and thus A is ground.

Page 12: First-order theories for pure Prolog programs with negation

124 R.F. StSxk

We can start a subcomputation and obtain the state

S (F frm(-~A' * G', I, or')) (frm(A', P, or')).

The atom A is identical to Atcr ' and thus in ~qF. Assume now that the atom A is in 1F(P). By assertion 2 of the theorem one can continue the LDNF-computation into the state S (F frm(~A' * G', I , ~r')) (}. By transformation L7, we obtain the state S (F frm(G ~, P, or')). Since G'~r'O ~ = G, the goal G is in ~ .

4.2. Assume that the goal Go is in S(P). Let S0, Sa , . . . be a possibly infinite LDNF-computation starting with the initial state initp(Go). We show by induction on i that the state Si is not f l o u n d e r i n g and that, for every frame frm(G, I, a) of Si, the goal G(r is in 5(P). This is obviously true for the state So. We assume now that it is true for the state Si. There are eight cases for Si+1 which correspond to L1-L8.

Case L1. Assume that the topmost frame of the topmost frame stack of Si is of the form frm(A * G, I, c~) and Si+l has been obtained from Si by a resolution step. Then there exists a variant B : - H of a clause of P and the topmost frame of Si+l is of the form frm(H �9 G, P, aT), where ~- = mgu(Aa, B). By the induction hypothesis, (A.G)cr is in S(P). By S1, we obtain that (A.G)~r~- is also in S(P). Since A(77 = B? and H a = H, we obtain, by $2, that (H �9 G)cr~- is in g(P).

Case L2. If Si+1 has been obtained from Si by a backtrack step there is nothing to show.

Cases L3 and L4. Assume that the topmost frame of the state Si is of the form frm(~A �9 G, I, a). By the induction hypothesis, we know that (-~A * G)cr is in g(P). Thus the atom Act is ground and S/+l is not floundering. The state Si+l is ob- tained from Si by a subcomputation step. The only new frame of Si+l is of the form frm(A, P, c9. Since (-~A * G)a is in S(P), by $3, we obtain that Act is also in S(P).

Case L5. If Si is a global success state then it is the last state of the LDNF- computation and we are done.

Case L6. In the case of a success of a subcomputation the state Si+l is a initial segment of Si and there is nothing to show.

Case L7. Assume that S~ is of the form S (F frm(-~A �9 G, I, or)} (). The state S~+1 is in this case the state S (F frm(G, P, ~r)). By the induction hypothesis, we know that the goal (~A * G)a is in $(P). By assertion 2 of the theorem, we obtain that A~r is in F(P). By $4, it follows that the goal Ga is in $(P).

Case L8. If Si is the empty stack then we have a global failure and Si is the last state of the computation. []

In the completeness proof in Sect. 8 it is convenient to work with the sets Y(P) and N(P) which have a very simple inductive definition. It turns out that if a goal G returns the answer cr in LDNF-resolution, then the goal G~r is in Y(P); if G fails in LDNF-resolution then G is in N(P). Conversely, assume that G is a safe (non- floundering) goal. If GO is in Y(P), then there exists an answer ~r for G, computed by LDNF-resolution, so that Ga is more general than GO. If a non-floundering goal G is in N(P), then G fails in LDNF-resolution.

Definition 5.6. The sets Y(P) and N(P) are the least sets of goals which are closed under the following six conditions:

Y1. o E Y(P). Y2. If (B : - H) c P, A = Bcr and Her * G C Y(P), then A * G E Y(P).

Page 13: First-order theories for pure Prolog programs with negation

First-order theories for pure Prolog programswith negation 125

Y3. If A E H(P) and G E Y(P), then ~ A �9 G E Y(P). N1. If H~- . G a E H(P) for all clauses (B : - H) E P and all substitutions a and ~-

so that Act = BT, then A * G E I~(P). N2. If A E Y(P), then --A * G E H(P). N3. If A E H(P) and G E H(P), then ~ A * G E H(P).

Note that in Y3, N2 and N3 it is not required that the negative literal ~A is ground.

L e m m a 5.7. 1. I f G I~(P) (7, then G(7 E Y(P). 2. I f G E IF(P), then G E H(P). 3. I f GO E U(P) and G E $(P) then there exist substitutions cr and ~- such that

G ~ (P) c~ and GcrT = GO. 4. I f G 6 H(P) and G E ~(P) then G E IF(P).

Proof We only show 3 and 4, since they are used in the completeness theorem in Sect. 8. We prove by induction on the definition of Y(P) and H(P) simultaneously the following two statements.

a. If GO E Y(P) , G E 5(P), and V is a set of protected variables which is disjoint from vats(G) then there exist substitutions cr and ~- such that G IRv(P) ~r, G~rT = GO and V N vars(cr) = ~.

b. If G E H(P) and G E g(P) then G E IF(P).

Here, vars(a) is the set of variables {z I z 5~ zcr} U U{vars(z~r) I z 4 :ca}. Case 1"1. G = 2~: Take a = c and ~- = 0. Case Y2. (A �9 G)O E V(P); (A * G) E g(P) ; V is a set of protected variables such

that V N vars(A * G) = V); (B : - H) is a variant of a clause of P that does not contain variables from vats(A* G)U V; AO = B'y; H T , GO 6 ~(P) : Let ~5 = mgu(A, B). Then VNvars(6) = !? and there exists a substitution r/such that (A,H,G)~Sr I = AO,HT ,GO.

Let W := V U (vars(A~5) \ vars(H6 * G~5). By S 1 and $2, we obtain that (H * G)g is in g(P). Since (H * G)~Srl is in ~ ( P ) and W N vars(H(5 �9 G~5) = (b, by the induction hypothesis, there exist ~r' and ~-' such that (H * G)~5 R w ( P ) or', ( H * G)&r'~-' = HT*GO, and WSvars(cr') = @. Let ~r := (&r') [ vars(A*G). Then VAvars(o') = ~ and A * G R v ( P ) cr by R2. Finally, with U := vars((H,G)&r') and ~- := (7 I W)U( ~J [ U) we obtain (A * G)c~'r = (A * G)O, since or'7" acts like r /on (A * G)6.

Case Y3. (~A �9 G)O E Y(P); -~A * G E $(P); V is a set of protected variables such that V A vars(~A �9 G) = (~; AO E H(P) and GO E Sf(P): By $3, we obtain that A is ground and A E S(P). Thus AO = A and, by the induction hypothesis, we obtain that A E IF(P). By $4, we obtain that G E S(P) and therefore there exist substitutions c~ and ~- such that G lieu(P) o', GcrT = GO and V C3 vats(or) = @. By R3, we obtain that ~A * G R v ( P ) a. Since A is ground, we have Acre- = A = AO and (~A * G)o-~- = (-~A * G)O.

Case N1. A �9 G E H(P); A * G E g(P) ; HT �9 G(7 E H(P) for all clauses (/3 : - H) E P and or, ~- with A a = BT: Let /3 : - H be a variant of a clause of P and 0 = mgu(A, B). By $1 and $2, we obtain that (H * G)O E S(P). Since (H * G)O E H(P), by the induction hypothesis, we have (H * G)O E IF(P). Since the clause B : - H was chosen arbitrarily, we obtain, by F1, that A * G E IF(P).

Case N2. ~A * G E H(P); ~A * G E g(P); A E ~ (P ) : By $3, we obtain that A is ground and A E S(P). By the induction hypothesis, we obtain that A Ro(P) e and, by F2, that -~A * G E IF(P).

Case N3. - , A * G E H(P); ~ A * G E g(P) ; A E H(P); G E H(P): By $3, we obtain that A is ground and A 6 g(P). By the induction hypothesis, we obtain that

Page 14: First-order theories for pure Prolog programs with negation

126 R.F. St'ark

A E IF(P). By S4, we obtain that G E S(P) and, again by the induction hypothesis, that G c F(P). By F3, we have -~A �9 G E IF(P). []

The aim of the next three sections is to prove the following: (i) For non-floundering goals G the formula T G is provable from the g-completion of a logic program if, and only if, the goal G strongly terminates in LDNF-resolution, i. e. if all LDNF- computations for G are finite. (ii) For non-floundering and strongly terminating goals G the formula T G A $ GO is provable from the e-completion if, and only if, there exists a substitution cr computed by LDNF-resolution so that Gcr is more general than GO. (iii) For non-floundering and strongly terminating goals G the for- mula T G A F G is provable form the g-completion if, and only if, the goal G fails in LDNF-resolution.

6 Soundness of LDNF-resolution

By soundness of LDNF-resolution we mean that every LDNF-computation can be transformed into a proof from the g-completion. More precisely, if a goal G returns the answer ~r in LDNF-resolution, then the formula $ G~r is provable from the g- completion; if G fails in LDNF-resolution, then F G is provable; if every LDNF- computation of G is finite and does not flounder, then T G is provable. We need the following lemma on the termination operator T.

Lemma 6.1. Let G and H be goals. Then the formula T(G * H) is equivalent to T G A ( F G V T H ) .

Proof The lemma is proved by induction on the length of G. If G has length one, then the lemma is the definition of T. Assume now that T(G * H) is equivalent to T G A (F G V T H). Then we have:

T(L * G * H) T L A ( F L v T ( G . H ) ) T L A (F L v (T G A (FG v T H)))

~-~ T L A ( F L V T G ) A ( F L V F G V T H ) T(L �9 G) A (F(L �9 G) V T H)

This concludes the proof. []

Parts 1 and 2 of the soundness theorem below are just the transformation of Clark's result [7] into out formalism. Part 3 on the termination operator "1- is new.

Theorem 6.2 (Soundness of LDNF-resolution). Let P be a logic program and G be a goal.

1. I f G returns the answer ~r in LDNF-resolution wrt. P, then gcomp(P) F- 8 Gcr. 2. I f G fails in LDNF-resolution wrt. P, then gcomp(P) ~- F G. 3. I f G strongly terminates in LDNF-resolution wrt. P, then gcomp(P) F- T G.

Proof First we prove 1 and 2. We show by induction on the definition of •(P) and IF(P) the following two assertions:

a. If G ~ ( P ) ~r then gcomp(P) F- 8 Ga. b. If G E IF(P) then gcomp(P) F- F G.

Page 15: First-order theories for pure Prolog programs with negation

First-order theories for pure Prolog programswith negation 127

In the proof we write F qo for gcomp(P) F ~. Case R1. S 2Je = q-. Case R2. B : - H is a variant of a clause of P; a is the most general unifier of A

and B; (H * G)cr I~(P) ~-; F S(H * G)a'r: By definition, S ( H , G)cr~r is equivalent to S Hcr~-/x S G~r~'. Since F S H~r~- ~ S A~rT, we obtain F S(A �9 G)crT".

Case R3. A is ground; A E N(P); G N(P) (7; ~- F A; F S Gcr: By definition, S -,A = F A and S(~A * G)a = F A A S G~r. Thus, t- S(-~A * G)~r.

Case F1. A is of the form R ( s l , . . . , Sn); for each clause of P which has a variant whose head is unifiable with A, there exists a variant B : - H which contains no variables from A * G so that (H �9 G)~r E IF(P) for the most general unifier ~r of A and B: Assume that

F g [ S l , . . . , Sn] = ] / ) ~ V y Sj = ti,j[y] ~ FHi[y .

i=l ~ j = l

Let 1 < i < ra and u be a string of variables which do not occur in G. Assume that cr is the most general unifier of R(Sl,..., Sn) and R( t i j [u ] , . . . ,ti,~[u]). By assumption, the goal (Hi[u] * G)a is in ~(P) and, by the induction hypothesis, we obtain t- FHi[u]cr V FGa. Now, for every binding y ~ a of ~r, the theory CET

n

proves /~ sj = ti,j [u] ~ y = a. Therefore, we obtain j=l

n

I- ~ [ s j 4 t { , j [ . ] V FHi[u] V FG. j=l

Since the variables u do not occur in G, we obtain

Vy sj = t~,j [y] --+ F H~[y] v F G.

If the atoms R ( s t , . . . , S n ) and R(ti,l[U],... ,t~,n[U]) are not unifiable then CET n

proves ~ / s j =/ti,j [u] and we obtain the same formula. Since i was chosen arbitrarily, 3=I

we have F F f f [S l , . . . , sn ] V FG. Using A2, we obtain F R f ( s l , . . . , s n ) V F G and F F ( A , G).

Case F2. A is ground; A R(P) r F S A: Since F-~A = S A, we obtain that F F ~A and hence F F ~A V F G and F F(~A �9 G).

Case F3. A is ground; A E ~(P); G c F(P); F FA; F FG: We obtain immedi- ately F F(-~A �9 G).

Now we prove 3. We show by induction on the definition of "Y(P) the following: If G c "Y(P) then gcomp(P) h- T G.

Case T1. T 0 = T. Case T2. A is of the form R(81,..., Sn); (H* G)a C qr(P) for each variant B : - H

of clauses of P and (7 = mgu(A, B): Assume that

1) T P [ s I , . . . ~ S n ] = ~ ~y sj = ti,j[y] ~ T U i [ y .

i=l - j = l

Page 16: First-order theories for pure Prolog programs with negation

128 R.F. Stfirk

Let 1 < i < m and u be a string 'of variables which do not occur in G. Assume that ~r is the most general unifier of R(s l , . . . , sn) and R(ti,1 [ n ] , . . . , t~,~[n]). By assumption, (Hi[n] * G)a is in qr(P) and, by the induction hypothesis, we obtain ~- T(Hi[u] * G)a. From this we obtain, by Lemma 6.1, ~- T H i [ u ] a and ~- F H i [ u ] a V T G a . In the same way as in Case F1 we obtain

~- Vy sj = t~,j[y] --~ Y H i [ y , " j = l

~- Vy sj = t~,j [y] --. F Hi[y V Y G. " j = l

If the atoms R(Sl , . . . , Sn) and R(ti,l [ u ] , . . . , ti,~[u]) are not unifiable then we obtain the same formulas. Since i was chosen arbitrarily, we obtain

t -T~[s l , . . . , sn] and ~-F~[s~,...,snlVTC.

From this we obtain ~- T A and ~- F A V T G and thus f- T(A * G). Case T3. A is ground; A c T(P); A R ( P ) e: By the induction hypothesis, we

obtain F- T A and, by assertion 1, ~- S A. Since F-~A = S A and T ~A = T A, we obtain f- T -~A A (F ~A V T G) and thus ~- T(~A * G).

Case T4. A is ground; A E ~I"(P); G c ~(P) : By the induction hypothesis, we obtain ~- T A and ~- T G. Since T ~ A = T A, we have ~- T ~ A A ( F ~ A V T G ) and ~- T(~A * G). rq

The converse of this theorem is not true for arbitrary goals. Consider the program P consisting of the following three clauses:

O(c), R(z ) : - O(x), R(x) : - ~O(x) .

The following formulas are derivable from gcomp(P):

x : c ~ QS(z), x 4 c ~ Qf(x), QS(x) v Qf(x) ~ RS(x).

Thus, gcomp(P) F- S R(x), but the goal R(x) does not return the answer e in LDNF- resolution. The reason for this incompleteness is floundering. Starting with the goal R(x), after a resolution step with the clause R(x) : - -~Q(x) we obtain the goal ~Q(x).

7 The positive fragment of the s

In this section we prove a theorem which is used in Sect. 8 for the completeness proof of LDNF-resolution. For this purpose, we define a hierarchy of free term-

P structures (~n),~c~. Let ~ be the ~ - s t m c t u r e whose universe the set of all ~ - terms (with variables). The variables play the role of infinitely many new constant symbols. The interpretation of the function symbols in :~ is the free interpretation, i.e. e ~n ( f ) ( t l , . . . , tm) = f ( t l , . . . , tm) . The extension of any predicate in ~ is the empty set. Then we define 3 P := I ff''~ according to Definition 4.3. Thus 30 P is the

P structure 3 and ~P is the structure Fp(3~ ). The following theorem is a variant of n+l Theorem 6.3 in [16] or Corollary 32 in [27].

Page 17: First-order theories for pure Prolog programs with negation

First-order theories for pure Prolog programswith negation 129

Theorem 7.1. Let qo[x] be a positive B-formula. I f gcomp(P) I- g~[x] then there exists a natural number n E ca such that ~P On b Vx~[x].

This theorem is not trivial, since in general 3~ is not a model of @omp(P). In order to prove the theorem, we introduce a sequent calculus seq(P) in which one can derive exactly those positive formulas which are provable from gcomp(P).

Sequents [F, A] are finite multisets of positive B- fo rmulas . The comma denotes concatenation of multisets. Sequents are interpreted disjunctively. If F is the sequent

#1,. �9 �9 ~Yn and 92 is an 5~f-structure then we write 92 # F for 92 h V(~l V . . . V ~ n ) and say that F is true in the structure 92. The sequent calculus seq(P) has the following axioms (cf. [15] and [22]):

1. If {Sl = t l , . . . , sn = tn} is not unifiable, then we have the axiom sequent

F, Sl 5 / t l , . . . , S n S t t n �9

2. If {Sl = t l , . . . , s~ = t~} is unifiable and a~r = bcr for a most general unifier ~r of {sl = t l , . . . , s~ = t~}, then we have the axiom sequent

F, sl ~ ' t l , . . . , s ~ =/t~,a = b.

The rules of seq(P) are:

s ~(0, 3z ~(z) s ss F, 3x p(x) F, Rs(t)

1", ~(y) (*)

r , F ~ [t] r , T P [t]

F, Rf(t) F, Rt(t)

The condition (*) requires that the variable y does not occur free in F, Vx ~(x). It is easy to prove that the sequent calculus seq(P) is sound. If a sequent is provable in seq(P) then the disjunction of the formulas of the sequent is true in any model of the g-completion of P .

L e m m a 7.2. I f 1" is provable in seq(P) then @omp(P) ~ F.

One can prove, however, the following stronger statement. The notion F(n)(92) denotes the n-fold application of the operator I'p to the structure 92.

Lemma 7.3. Let 92 be a model of CET sueh that 92 <_ 1"p(92). Then for every sequent F which is provable in seq(P) there exists a natural number n such that l'(pn)(92) ~ 1".

Proof Since 92 _< Fp(92) and Fp is monotonic, we have F(pn)(92) <_ /,(~+1)(92) for all n. The theorem is proved by induction on the length of a derivation of F in seq(P). []

In order to prove that the sequent system seq(P) is complete, i.e. that every sequent which is true in all models of gcomp(P) is also provable in seq(P), we need the notion of D-chain which goes back to Schiitte (cf. [23]). We use the notions of [13].

Definition 7.4. Let a0, a l , . . , be an enumeration of all terms and z0, Z l , . . . be an

enumeration of all variables of the language B . A D-chain (deduction chain) for a sequent F with respect to a program P is a sequence F0, El , . �9 �9 of sequences (not multisets) of positive formulas which is formed as follows:

Page 18: First-order theories for pure Prolog programs with negation

130 R.F. Stiirk

1. Fo is F. 2. I f / ' ~ is an axiom of seq(P) then / ~ is the last element of the D-chain. In this

case we say that the D-chain has length n. 3. If Fn is A, ~p A r then Fn+I is either ~, A or ~b, A. 4. If Fn is A, qo V ~ then Fn+l is ~, r A. 5. If Fn is A, Vx ~(z) then Fn+l is ~(zi), A, where i is the least number such that

zi does not occur free in _E,~. 6. If Fn is A, 3x~(x) then Fn+l is 3x ~(x), g)(ai), A, where i is the least number

such that ~(ai) does not occur in F 0 , . . . , / ' ~ . 7. If Fn is Zl, s = t then Fn+l is s = t, A. 8. I f / ' ~ is A, s 4 t then Fn+l is s : / t , A . 9. If Fn is A, RS(t) then Fn+l is SP[t l , A.

10. If F~ is A, Rf(t) then F~+1 is Fff[ t l , A. 11. If F~ is A, Rt(t) then Fn+l is Tff[t] , A.

L e m m a 7.5 (Principal syntactic lemma). Let 1" be a sequent. I f all D-chains for F with respect to P end in an axiom then F is provable in seq(P).

Proof The set of D-chains is a finitely branching tree. Since all D-chains are finite, by K6nig's Lemma, it follows that the tree is finite. Let m be the maximal length of a D-chain. It is easy to prove, by induction on ra - n, that if Fn occurs in the nth place of one of the D-chains then Fn is provable in seq(P). []

L e m m a 7.6 (Principal semantic lemma). Let F be a sequent. I f there exists a D-chain for F with respect to P which does not end in an axiom then there exists a model 9.1 of @omp(P) such that 9.1 ~ F.

Proof Let F0, F1 , . . . be a D-chain for F with respect to P which does not end in an axiom. Let N be the set of formulas which occur in one of the 1"i. The set N has the following properties:

1. If ( ~ A ~ ) E 2. If (~V~b) c 3. If g x r E 4. If 3x ~(x) c 5. If RS(t) E N 6. If Rf(t) c N 7. If 8. If 9. If {sl 4 t l , . . . , s n 4 t~,a = b}

{sl = t l , . . . , Sn = tn} then aO 7~ bO.

N then p C N or r C N . N then ~ E N and ~p E N. N then there exists a variable z such that ~(z) E N. N then ~(t) E N for all terms t: then sP [ t ] c N . then FRP[t] C N.

Rt(t) E N then TP[t] C N. {sl 5 / t l , . . . , s , ~ =/tn} C_ N then {sl = t l , . . . , S n = tn} is unifiable.

C_ N and 0 is a most general unifier of

A structure ~3 is defined as follows:

1. The universe ]f13[ of f13 is the set of all terms. 2. If f is n-ary and t l , . . . , t n C [f131 then 98( f ) ( t l , . . . , t n ) := f ( t l , . . . , t n ) . 3. For a, b C 1~31 we define a , - ~ b if there exists a subset {Sl 5 / t l , . . . , sn q t~}

of N such that aO = bO for each unifier 0 of {sl = t l , . . . , sn = tn}.

4. For each predicate symbol Q of ~ we define ~ ( Q ) := {(t) :Vs(t ~ s ==~ Q(s) ~ N)}.

Page 19: First-order theories for pure Prolog programs with negation

First-order theories for pure Prolog programswith negation 131

Equality is treated as a binary relation and is interpreted by the equivalence rela- tion ~ 3 . It is easy to see that ~ satisfies axioms E1 and E2 of CET. The notion ~3 ~ 79 means that the formula 79 is true in ~3 under the canonical variable assignment that assigns to a variable x the value x E I~1.

Now we prove by induction on the length of a formula 79 that ~3 ~r 79 if 79 E N . We consider only the base cases. The induction steps are easy.

79 is a = b: We have to show that a ~ b. Let {st ~ t ~ , . . . ,sn 5r C_ N and let 0 be a most general unifier of {sl = t l , . . . , Sn = tn}. Then we have aO 5r bO, since otherwise {sl -~ t l , . . . , sn -7 (tn, a = b} would be an axiom.

7) is a ~ b: We have to show that a ~ b. But this is trivial, because {a 5t b} __ N and, for each unifier 0 of {a = b}, we have aO = bO.

7) is Q(t): We have t ~ t and Q(t) E N. Thus, (t) r ~3(Q), and ~ [r Q(t). Now we claim that F p ( ~ ) <_ ~ . Suppose that t E I~1 and ~ [r RS(t). Then

(t) ~ ~3(R ~) and there exist s E I~] such that t ~ s and R~(s) E N . But then, we have SP[s] E N , and ~3 [r SP[s] and, since t ,,o~ s, ~ ~ SPIt] .

By Proposition 4.4 we obtain a structure 92 < ~3 which is a fixed-point of Fp and satisfies U and T. Thus 9.1 ~ gcomp(P) and 9.1 ~ F. []

Theorem 7.7. Let 79 be a positive formula. Then 79 is provable in seq(P) if, and only if, 79 is true in all models of gcomp(P).

Proof If 79 is provable in seq(P) then, by Lemma 7.2, 79 is true in all models of gcomp(P). If 7) is not provable in seq(P) then, by the principal syntactic lemma, there exists a D-chain for 79 which does not end in an axiom and, by the principal semantic temma, there exists a model of gcomp(P) in which 79 is not true. []

Proof (of Theorem 7.1) Assume that 79[x] is a positive ~ - f o r m u l a which is provable from gcomp(P). Then, by the previous theorem, we obtain that 79[x] is provable in the sequent calculus seq(P). Since ~P _< Fp(~P), by Lemma 7.3, there exists a natural

number n such that F(p~)(~ P) ~ Vx79[x]. []

8 Completeness of LDNF-resolution for non-floundering goals

By completeness of LDNF-resolution we mean the following: Let G be a non- floundering goal. (i) I f gcomp(P) ~- G then G is strongly terminating in LDNF- resolution. (ii) If gcomp(P) t- T G A S GO then there exists an LDNF-computed answer a for G which is more general. Since G is strongly terminating by (i), the substitution cr is one of the answers of Prolog. (iii) I f gcomp(P) ~- T G A S GO then G fails in LDNF-resolution. Since G is strongly terminating, it fails in Prolog.

The notion j R ~ 79 means in this section that the formula 7) is true in the term n

structure ~ under the canonical variable assignment which assigns to a variable x the value x. It does not mean that 3~ ~ V(7)).

Definition 8.1. Let L t , . . �9 Lk be a goal and let n l , . . . , T/, k be natural numbers. The k-tuple ( n l , . . . , n k ) is called a t-rank for the goal L 1 , . . . , L k (wrt. P ) if for all substitutions ~r one of the following two statements is true:

1. d~,~P ~ T Licr for all i, 1 < i < k, 2. there exists an i, 1 <_ i < k, such that ~n P ~ FLicr and dn~~P ~ T L j a for all j ,

l <_j <_i.

Page 20: First-order theories for pure Prolog programs with negation

132 R.F. S t ~ k

Note that if 3 P ~ VT(L1 , . . . ,Lk) , then the k-tuple ( n , . . . , n ) is a t-rank for L I , . . . , Lk wrt. P, since T(L1 , . . . , Lk) is equivalent to

k - 1

(T L1 A . . . A T L t ) V ~ / ( T L1 A . . . A T Li A F LO. i=l

Lemma 8.2. Assume that (n l , . . �9 nk) is a t-rank for the goal L1, . �9 Lk and that L1 is a positive literal. Let B : - M1, . . . , M t be a clause o f P. Let cr and ~- be substitutions such that L1~ = B'c. Then n 1 is greater than 0 and the (g + k - 1)-tuple

( h i - 1 , . . . , n l - - l , n 2 , . . . , n k )

is a t-rank f o r the goal MI T, . . . , Me: r, L2a, . �9 �9 Lka.

Proof That nl is greater than 0 can easily be seen as follows. By assumption, we have ~n P ~ T L1. But this is only possible if nl > 0, since LI is positive and at stage 0 all atoms are false. [3

Lemma 8.3. Assume that (n l , . . �9 nk) is a t-rank fo r the goal L 1 , . . �9 Lk and that L1, . . . , Lk is in S(P).

1. I f ~ n P ~ $ L i f o r all i, 1 < i < k, then L x , . . . , L k is in ~ ( P ) .

2. I f f o r all substitutions ~ there exists an i, 1 < i < k, such that ~n P ~ FLicr, then L 1 , . . . , Lk is in N(P).

Proof Let r be a natural number which is greater than the number of literals in the body of any clause of P. Such a number always exists, since programs are finite. Statements 1 and 2 are proved simultaneously by induction on the natural number r TM + . . . + r nk. Let L 1 , . . . , Lk be a goal of ~(P). If k = 0 then, by Y1, 0 c Y(P).

Case 1. ~n P ~ $ Li for all i, 1 < i < k; L1 is of the form R ( S l , . . . , s,~): Assume that

S P [ s l , . . . , s ~ ] = ~V~hy s j = ti,j[y] A SHi[y] . i=1 - j= l

Since ~PI ~ S Ll, we have nl > 0 and ~Pna-1 ~ S~[S]. There exists an i, 1 < i < m,

and terms a such that ~P1-1 ~ S Hi[a] and sj = tid[a] for all j , 1 _< j _< n. Assume that the length of Hi[a] is g. The (g+ k - 1)-tuple (nl - 1 , . . . , nl - 1, n 2 , . . . , nk) is a t-rank for Hi[a], L 2 , . . . , Lk. By $2, the goal Hi[a], L 2 , . . . , Lk is in S(P). By the induction hypothesis, since g. r n ' - I < r TM, the goal Hi[a], L 2 , . . . , L~ is in Y(P). Hence, by Y2, the goal L I , . . . , Lk is in Y(P).

Case 2. For all substitutions a there exists an i, 1 < i < k, such that ~n P ~ F Lia; L1 is of the form R ( s l , . . . , sn): Assume that

F P [ 8 1 , . . . , Sn] = / ~ V y sj = ti,j[y] --~ FHi[y] . i = l \ j = l

Let 1 < i < m. Let a be a vector of terms and 0 be a substitution such that R ( s l , . . . , s~)O is equal to R ( t i 4 [ a ] , . . . , ti,n[a]). By N1, the goal L 1 , . . . , Lk is in I~(P) if we can show that the goal Hi[a], L 2 0 , . . . , LkO is in N(P). Assume that Hi[a] = M1, . . . ,Me. Then the ( g + k - 1)-tuple (nl - 1 , . . . ,nl - 1 ,n2 , . . . ,nk) is a t-rank for Hi[a], L 2 0 , . . . , LkO. By S1 and $2, the goal Hi[a], L 2 0 , . . . , LkO belongs

Page 21: First-order theories for pure Prolog programs with negation

First-order theories for pure Prolog programswith negation 133

to S(P). Let c~ be a substitution. There exists a j , t _< j _< k, such that ~n~ ~ F Lj 0~r.

Assume that j = 1. Then 3 P F~[sOa] it follows that 3 P n,-1 ~ and nl--I ~ FHda]o-. Thus, there exists a j , 1 < j < g, such that 3 e - - nl-1 ~ F Mjf f . Since g. r n~-I < r TM, by the induction hypothesis, the goal Hi[a], L 2 0 , . . . , LkO is in I~(P).

Case 3. ~ ~ S Li for all i, 1 < i < k; L1 = --A: Since L l , . . . , Lk is in 5(P), by $3, A is ground and A is in S(P). Since S ~ A = FA, we have ~n~ ~ FA. By assumption, we have 3~ ~ T ~A and thus 3~ P ~ T A. By Case 2, we obtain that A is in I~(P). Since A is in $(P), we obtain, by Lemma 5.7, that A belongs to IF(P) and, by $4, it follows that L2 , . . . , Lk is in 5(P). It is not possible that ~n~ ~ FLICk, since ~ satisfies the uniqueness axiom U, L, is ground and ~n~ ~ $ L,. Therefore, the tuple (n2, . . . , nk ) is a t-rank for L2 , . . . , L k and, since r n2 +. . . + r nk < r TM +. . .+ r nk , by the induction hypothesis, we obtain that L 2 , . . . , La is in SJ(P). By Y3, the goal L 1 , . . . , La is in S{(P).

Case 4. For all substitutions cr there exists an i, 1 < i < k and ~ ~ F Licr; L1 = ~A: Since the goal L l , . . . , L k is in 5(P), by $3, A is ground and A is in ~(P). By assumption, ~P ~ "1" A. Since ~v satisfies the totality axiom T, we have 't2, 721

~[en, ~ S A or ~ ~ F A. Assume first that ~n~ ~ S A. By Case 1, A is in Sf(P) and, by N2, the goal L l , . . . , Lk is in N(P). Assume that ~n~ ~ F A. Then ~n~ ~ F L1. By Case 2, A is in N(P). Since A is in 5(P), we obtain, by Lemma 5.7, that A is in ~'(P) and, by $4, that L2, . . . , L t is in 5(P). Since the tuple (n2, . . . , n t ) is a t-rank for L2,.. �9 Lk, we obtain, by the induction hypothesis, that L2,. �9 �9 Lk is in I~(P). By N3, the goal L~ , . . . ,L~ is in N(P). []

The next lemma is proved in a similar way. In its proof Lemma 8.3 is used.

Lemma 8.4. Assume that ( n t , . . . , nk) is a t-rank for the goal L 1 , . . . , Lk and that L I , . . . , L k is in S(P). Then L 1 , . . . , L k is in qY(P).

Now the completeness theorem follows easily from the previous lemmas.

Theorem 8.5 (Completeness o f LDNF-resolution). Let P be a logic program and G be a non-floundering goal, i.e. G E ~(P).

1. I f gcomp(P) F- T G, then G strongly terminates in LDNF-resolution, i.e. G E •(P) and thus G terminates in Prolog.

2. I f s ~- T G A $ GO, then there exists an LDNF-computed answer ~ for G which is more general than O, i.e. G C ~(P), G ~ ( P ) cr and there exists a substitution T such that G ~ " = GO. The substitution ~r is one of the answers o f Prolog.

3. l f s ~- T G A F G, then the goal G fails in LDNF-resolution, i.e. G E qF(P), G E lF(P) and thus G fails in Prolog.

Proof. Let G be a non-floundering goal. 1. Assume that gcomp(P) F- T G. Since T G is a positive formula, by Theorem 7.1

there exists a natural number n so that ~ ~ TG. Hence ( n , . . . , n) is a t-rank for G. By Lemma 8.4, we obtain that G is in ql"(P).

2. Assume that tcomp(P) ~- T G A S GO. In the same way as in 1 we obtain a natural number n so that ~P ~ TG and ~ ~ S GO. Since ( n , . . . , n ) is a t-rank for G, by Lemma 8.3, we obtain that GO is in ~{(P). By Lemma 5.7, we obtain substitutions cr and T SO that G II~(P) cr and Gc~7 = GO. Theorem 5.5 says that the

Page 22: First-order theories for pure Prolog programs with negation

134 R.F. St~k

goal G returns the answer cr in LDNF-resolution. Since G strongly terminates under LDNF-resolution, Prolog will also compute the answer or.

3. Assume that tcomp(P) F- T G A F G. In the same way as in 2 we obtain, by Lemma 8.3, that G is in I~(P). By Lemma 5.7, it follows that G is in F(P). Theorem 5.5 says that the goal G fails in LDNF-resolution. []

9 Modes prevent floundering

The main assumption of the previous theorem is that the goal does not flounder. In general the problem of floundering is not decidable. In fact, the set of all (G, P) so that G E ~(P) is//~ For every program P, however, there is a syntactically defined, decidable subset f f c_ $(P) which covers most goals of practical interest. The set ~ - is defined by means of modes. It is the set of those goals G for which there exists a mode assignment # so that P and G are #-correct. Modes have been widely used in the field of compilation of Prolog programs (see, for example, [19]).

In our context, a mode [a, fl, "7] for an n-ary predicate symbol R is an n-tuple (xl , . �9 �9 xn) so that xj E {in , o u t , l og} . If xj = i n then the j th argument of R is called an input argument. If xj = o u t then the j th argument of R is called an output argument. Otherwise, if xj = l o g then the j th argument of R is called a logical or a neutral argument. A mode assignment is a function # which assigns to every predicate symbol R of S a (possibly empty) set #(R) of modes for R. The intended meaning of a mode is the following: if all input arguments of an atoms are ground, then the answer terms for the variables in output arguments will also be ground.

We define below what it means that a program and a goal is correct with respect to a mode assignment #. The main theorem of this section is that if a program P and a goal G are correct with respect to some mode assignment, then the goal G does not flounder in LDNF-resolufion, i.e. G is in $(P). In the second part of the section we will provide two quadratic algorithms which decide whether a goal or a clause is correct with respect to (the closure of) a given mode assignment.

A mode assignment # is extended to literals in the obvious way. We set #(R(t)) := #(-~R(t)) := #(R). Let A be the atom R ( t l , . . . , tn) and a be the mode ( x l , . . . , Xn). Then the set of input variables of A with respect to o~ is the set of variables which occur in input arguments. It is defined by

in(A, c~) := U { vars(tj)" 1 < j < n, xj = i n ).

The set of output variables is defined analogously by

out(A, cO := U(vars ( t j ) : 1 < j < n, xj = o u t }.

The idea is now that a program must be written in such a way that in a computed answer the output variables are contained in the input variables. In a certain way a mode assignment reflects the data flow of a logic program. Formally, this can be expressed by the following definitions.

Definition 9.1. Let # be a mode assignment and A : - L 1 , . . . , Ln be a clause such that OL E ]~(A),/~1 E ~(L1) , . . . ~/~n E ]d(Ln). We say that A : - L1 , . . . ,Ln is correc t

with respect to the modes ~,/31,. �9 if

Page 23: First-order theories for pure Prolog programs with negation

First-order theories for pure Prolog programswith negation 135

1. for the head A out(A, oO C_ in(A, cO U U{out(Lj , /3j) " 1 <_ j <_ n, Lj positive},

2. for every positive literal Li of the body

in(Li,/30 C_ in(A, oO U U{out (L j , flj) : 1 < j < i, Lj positive}, 3. for every negative literal Li of the body

vars(LO C_ in(A, ~) U U{out (L j , flj) : 1 < j < i, L j positive}.

The conditions say that the output variables of the head A must be input variables of A or output variables of the positive literals of the body. For every positive literal Li of the body the input variables must be input variables of the head or output variables of positive literals on the left-hand side of L~. If a literal L~ is negative then all its variables must be input variables of the head or output variables of positive literals on the left-hand side of L~.

Definition 9.2. Let # be a mode assignment. A clause A : - L1, . . �9 Ln is called #-correct if for each c~ E #(A) there exist/31 E # ( L I ) , . . . ,fin C #(Ln) such that A : - L 1 , . . . , Ln is correct with respect to the modes c~,/31,...,/3n.

In particular, a fact A is/z-correct if for all modes c~ in #(A) the output variables of A with respect to c~ are also input variables of A with respect to c~.

Definition 9.3. A logic program P is called #-correct if all clauses of P are/z-correct.

Definition 9.4. Let # be a mode assignment. A goal L1, �9 �9 �9 Ln is called #-correct if there exist modes/31 E #(L1) , . . . , /3n E #(Ln) such that

1. for every positive literal Li in(Li,/30 C_ U{out(Lj , /3 j ) . 1 <_ j < i, Lj positive},

2. for every negative literal Li

vars(LO C_ U{out(Lj , /3j) : 1 <_ j < i, Lj positive}.

In particular, we have that an atom A is a/z-correct goal if there exists a mode/3 in /z(A) such that A has no input variables with respect to/3, i.e. if all input arguments of A with respect to /3are instantiated with ground terms.

The next theorem says that if a program is/z-correct then all/z-correct goals do not flounder. Therefore the set of/z-correct goals is a decidable approximation of S(P).

Theorem 9.5. Let/z be a mode assignment. I f P is a ~z-correct program and G a ~z-correct goal, then G does not flounder in LDNF-resolution.

Proof Let ~ r be the set of all /z-correct goals. It is easy to see that ~" satisfies conditions S 1-$4 of Definition 5.4. Since S(P) is the largest set with this property, we obtain that ~ r C_ S(P). []

Mode assignments are best understood by looking at an example program.

Example 9.6. We write [xly ] for c o n s ( x , y).

subset(Ll, L2):-- ~ notsubset(Ll, L2). notsubset(Ll, L2) :-- member(X, LI), ~ member(X, L2). member(X, [XlL]). member(X, [YIL]) :-- member(X, m).

Page 24: First-order theories for pure Prolog programs with negation

136 R.F. StSxk

This program is correct with respect to the following mode assignment #:

~(member/2) := {(log, log), (out, in)}, #(notsubset/2) :: {(in, in)}, #(subset/2) := {(in, in)}.

How can we check whether a clause A : - L1, � 9 Ln is correct with respect to a given mode assignment #? We have to show that for each ~ E #(A) there exist modes /31 E # ( L 1 ) , . . . ,/3n E /z(Ln) such that conditions 1-3 of Definition 9.1 are satisfied. In general we have to check exponentially many possibilities for /31, . . �9 This seems to be not feasible. It turns out, however, that there is a quadratic test. The test does not answer the question whether the clause is correct with respect to /z but whether the clause is correct with respect to the closure of #. For our purposes it suffices to check correctness with respect to the closure of #, since (i) correctness with respect to # implies correctness with respect to the closure of/z (cf. Lemma 9.10) and (ii) the modes of # are contained in the closure of #. What is the closure of #?

On the set {ou t , l o g , i n } a total ordering is defined by out; < l o g < i n . We write x < y if x < y or x = y. Thus we have x < y if x = out : or x = y or y = i n . For modes c~ = ( x l , . . . , x n ) and fl = (Y l , . . . ,Yn) we define c~ < /3 if xi _< yi for all i, 1 < i < n. If c~ < /3 then we say that the mode c~ is more general than /3. This means that it has more output and less input than/3. Thus 'more general ' means 'more output ' . If c~ < / 3 then in(A, c~) C in(A,/3) and out(A,/3) C_ out(A, c~),

Let f be the function defined by f ( l o g ) := 0, f ( o u t ) := 1 and f ( i n ) := 2. Then, for all x, y E { o u t , l o g , i n } , we set x + y := f - l ( m a x ( f ( x ) , f(y))). Thus we have:

in, if x = in or y = in; x+y = out, if x ~ in and y ~ in and (x = out ory =out);

log, ifx=logandy=log.

The operation + is associative, commutative and idempotent. The neutral element is l o g . The operation + is also monotonic with respect to <. If y < z, then x+y < x+z. If c~ = ( X l , . . . , x n ) and/3 = ( y l , . . . , y n ) then we set

c~+/3 := (xl + Y l , . . . , X n +Yn).

We write Y'~{c~l, . . . , c~n} for c~1 + . . . + C~n. For atoms A we have:

in(A, oz +/3) = in(A, oO U in(A,/3), out(A, c~ +/3) C_ out(A, cO tO out(A,/3), out(A, ~) C out(A, c~ +/3) U in(A,/3).

Definit ion 9.7. For a mode ass ignment /z we define the closure /2 in the following way. For each predicate symbol R of S we set

/2(R) := { c~ : 3n >_ 1, 3/3~ E lz (R) . . . 3/3~ ~ tz(R)/31 + - . - +/3~ < ~ }.

Thus, /2(R) is the least set of modes closed under the following conditions:

1. ~(R) C_/2(R). 2. If c~ E/2(R) and/3 E/2(R) then c~ +/3 E/2(R). 3. If c~ E/2(R) and c~ _</3 then/3 E/2(R).

In Fig. 1 and Fig. 2 two algorithms, correct_goal and correct_clause, are defined which decide in quadratic time whether a goal or a clause is /2-correct or not. The size of the input is the size of the goal or the clause plus the size of #.

Page 25: First-order theories for pure Prolog programs with negation

First-order theories for pure Prolog programswith negation 137

algorithm correct_goal(L1,..., Ln ; #) begin

X0 := 0; f o r i : = l tondo

if Li = R(t) then if V'y E #(R)(in(Li, "7) ~ Xi-1) then return(no) else

13i := ~ ( 7 E p(R) : in(Li, 7) C Xi-1 }; Xi := Xi-1 Uout(Li,13i)

end end; if Li = ~R(t) then

if #(R) = 0 V vars(Li) ~ Xi_ 1 then return(no) else Xi := X~-I end end

end; return(yes)

end correct_goal.

Fig. 1. The algorithm correct_goal

Theorem 9.8. The goal G is f~-correct if, and only if, correct_goal(G; #) returns yes.

Proof 1. Assume that L 1 , . . . , L , ~ is a /~-correct goal. This means that there exist modes ~ E / 2 ( L I ) , . . . ,/3~ E/~(L~) such that if Li is positive then

in(Li,/3~) C_ U { out(Lj, fl~) : 1 <_ j < i, L j positive }

and if Li is negative then

vars(Ld c_ U { out(Lj, 5'j) : 1 <<_ j < i, Lj positive }.

We claim that

U { out(Lj, t3j) : 1 <_ j < i, L j positive} C X i - i

is a loop invariant of the for-loop of correct_goal(L1,. . . , Ln; p). It is certainly true for i = 1. Assume now that L~ is positive and that

U { out(Lj,/3~) : 1 <_ j < i, Lj positive} ___ Xi-1.

There exist 71 E #(LO, . �9 �9 7k C #(Li ) such that 3'1 + "" �9 + 3'k _< fl~- We have

in(Li, Tj) C_ in(Li, 71 + . " + Tk) C in(L~,/3~) C_ X i _ 1

and

out(Li,/3~) C_ out(L~, ~/1 +' ' " + ~k) C_ out(Li, /30 U in(Li, /3i) C X i U X i_ 1 C Xi ,

where/3i = ~ { " / E # ( L O : i n ( L i , 7 ) _C X i - i }. Thus,

U { out(Lj,/33) : 1 < j <_ i, L j positive } _C Xi.

Assume that Li is negative. Then t l(Li) ~ 0 and

Page 26: First-order theories for pure Prolog programs with negation

138 R.F. St~k

vars(Li) C U { out(Lj , 3~) " 1 <_ j < i, L j positive } C_ X~_1.

2. If correct_goal(L1,. . . , Ln ;p ) returns yes then the modes/3~ obtained during the computation belong to/2(Li) . If Li is negative, then # ( L 0 ~ 0 and one can choose an arbitrary mode from p(Li) . Thus, the goal L 1 , . . . , Lu is/2-correct. []

algorithm correct_clause( A : - L1, . . . , Ln ; # ) begin

forall a E ~(A) do Xo := in(A, a); for i := l to n do

if Li = R(t) then if V 7 E #(R)(in(Li, 7) g Xi - l ) then return(no) else

fli := )-~{ 7 E #(R) : in(Li, 7) C X i - I }; Xi := Xi-I U out(Li, 3i)

end end; if Li = ~R(t) then

if #(R) = O V vars(Li) fs X i - 1 then return(no) else Xi := Xi-1 end end

end; if out(A, a) ~ X~ then return(no) end

end; return(yes)

end correct_clause.

Fig. 2. The algorithm correct_clause

T h e o r e m 9.9. The clause A : - G is ~2-correct if, and only if, correct_clause(A : - G; #) returns yes.

Proof. 1. Assume that A : - L1 , . . �9 Ln is/2-correct. Let a E #(A). There exist modes /3~ E /2 (L1) , . . . , ~ c /2 (Ln) such that A : - L j , . . . , L~ is correct with respect to the modes a , / 3 ~ , . . . , 3~- In the same way as in the proof of Theorem 9.8 one can show that

in(A, a) u U { out(Lj , 3~) : 1 <_ j < i, L j positive } C_ X i _ 1

is a loop invariant of the for-loop of correct_clause(A : - L l , . �9 Ln; #). 2. Assume that correct_clause(A : - L 1 , . . . , Ln; #) returns yes. Let a t be a mode

of /2(A). By the definition of /2 there exist modes a l c p ( A ) , . . . , a k E #(A) such that a l + . . . + ak _< a r. For every a~ the algorithm computes modes /3~,1 E /2(LI), . . . , /3~,n E/2(L~) such that the clause A : - L 1 , . . . , Ln is correct with respect to the modes a~,/3~,1,... ,/3~,n. By Lemrna 9 . t0 below, the clause is also correct

k k in(A, )-~-~=l C_ in(A, a ') with respect to ~'~-i~l a i , )-'~i=l f l i ,1 , . . . , ~'~.i=l/3~,n. Since a i )

and out(A, a ') C__ out(A, ~ki= 1 aO, the clause is correct with respect to the modes

L e m m a 9.10. I f a clause A : - L 1 , . . . , L n is correct with respect to the modes a , /31 , . . . ,3n and correct with respect to the modes a ' , / 3 [ , . . . ,3tn, then it is also correct with respect to the modes a + ce', 131 + t3~, . . . , t3n + fl~n"

Page 27: First-order theories for pure Prolog programs with negation

First-order theories for pure Prolog programswith negation ! 39

Proof For i = 0 , . . . , n + 1 we define

Xi := in(A, c~) U U{out(Lj , /3j)" 1 <<_ j < i, Lj positive },

Z~ := in(A, ~') U U{out(Lj , /3j) " 1 <_ j < i, Lj positive },

Yi := in(A, c~ + c~') U U{out(L5, /35 +/3j) : 1 < j < i, Lj positive ).

We first show that Xi U X~ = Y~. Since we have in(A, c~ + ~') = in(A, ~) U in(A, ~'), this is certainly true for i = 0. Since out(Lj,/3j +/3~) C out(Lj,/3j) U out(Lj,/3~) the inclusion Y~ C_ Xi U X~ is trivial. Assume now that Xi U X~ = Yi. Then

out(L~, fli) c_ out(L~,/3~ + t3~) U in(L~,/3~) C_ Y~+~ U X~ C Y~+t.

In the same way we obtain that out(Li,/3~) C_ Yi+l. Hence, Xi+ 1 U X~+ 1 (~_ Y/+I. Now we have to show that conditions 1-3 of Definition 9.1 are satisfied.

1. We have out(A, a + a') C_ out(A, a) U out(A, a') C Xn+ 1 U Xln+l : Yn+l. 2. If Li is positive then in(Li, ~ + 13~) = in(Li,/30 U in(L~, ~ ) C_ Xi U X~ = Y~. 3. If Li is negative then vars(LO C_ Xi C__ Yi. []

10 The inductive extension of logic programs

For proving general statements on logic programs one has to add induction principles to the g-completion. Consider the following set of formulas

p = { VX I(R](XI) ~ ~ I ( X l ) ) , . . - , V X n ( / ~ ( X n ) ~ ~n(Xn)) },

where the R~ are pairwise different and the r are arbitrary ~ - fo rmu la s . A natural way to prove the formulas of p is to use simultaneous induction on the definition of the predicates R 1 , . . . , Rn in the given program. For this purpose we need the

following abbreviations. For a positive ~ - a t o m A we define the S - f o r m u l a Ap by

f ~i(t), if A is of the form R~(t); Ap := ~. S A, if A is not of the form Ri(t) for i = 1 , . . . , n.

For negative f - l i t e r a l s ~A we set (-~A)p := F A; for a sequence of ~ - l i t e r a l s L1 , . . . ,L ,~ we define ( L l , . . . , L n ) p := L a p A . . . AL~p.

For a clause A : - G we define (A : - G)p to be the formula Vy(H[y]p --~ B[y]p), where B[y] : - H[y] is a variant of A : - G so that the variables y do not occur free in p.

For a program P the set of all clauses of P whose heads are of the form Ri(t) for / = 1 , . . . , n is denoted by Pp. Finally, the simultaneous induction axiom for p with respect to P, sim(P, p), is defined to be the formula

A { ( A : - G)p: (A : - G) E Pp } ~ A p .

The collection of all axioms sim(P, p) for all p expresses that the relations R ~ are the least definable sets satisfying the clauses of the program/9.

Example 10,1. Let P be the program consisting of the following clauses:

Page 28: First-order theories for pure Prolog programs with negation

140 R.F. Stiirk

even(0). even(s(X)) :-- odd(X). odd(s(X)) : - even(X).

Let p : : {Vx(evenS(x) --+ 99(x)),Vx(oddS(z) ~ ~(x))}. Then sim(P,p) is the formula

Vx(cp(x) --~ r -~ Vx(oddS(x) ~ r "

By adding the simultaneous induction scheme to the g-completion one obtains a theory which is appropriate for proving termination and equivalence of logic programs.

Definition 10.2. The inductive extension of P, ind(P), is the g-completion of P together with the simultaneous induction scheme sire(P, p) and the following fixed point axioms:

1. RS(x) ~ S~[x] 2. Rf(x) --+ F ~ [x] 3. Rt(x) --+ T~'~P [x]

The inductive extension of a program P is conservative over the g-completion for positive formulas.

Theorem 10.3. Let qo be a positive formula. Then g) is provable in ind(P) if, and only if, ~ is provable in gcomp(P).

Proof Since gcomp(P) is a subtheory of ind(P) one direction is trivial. Assume now that ind(P) ~- ~ and T is positive. We show that ~ is true in all models of gcomp(P). Let N ~ gcomp(P). This means that Fp(92) < 92. Let ~3 be the same structure as 92

but with empty interpretations for the predicate symbols of S . Then I ~ ~ is a model of the inductive extension ind(P). By assumption we have I ~ ~ b qD and since I ~ ~e _< 92, we obtain that 9 / b cP. []

This theorem is important for verification of logic programs. It allows to transform results on programs which have been proven in the inductive extension into results on the computational behavior of the programs. An example is given in the next section.

11 An example for verification of logic programs

We consider a simple parser for expressions (cf. [8]). The input for the parser con- sists of lists of tokens. A token is either a literal l ( z ) or one of the four constants +, *, l p a r and r p a r . We use the standard Prolog notation for lists: the symbol [] is the constant n i l ; [zly] stands for c o n s ( z , y); [Zl, z 2 , . . . , zn] denotes the term c o n s ( z l , c o n s ( z 2 , . . . , cons(Zn, n i l ) . . . ) ) . The list [1(1), +, 1(2)] corresponds to the arithmetical expression 1 + 2; the list [ l p a r , 1(1), +, 1(2), r p a r , *, 1(3)] corre- sponds to (1 + 2) �9 3.

The predicate e x p / 1 in Fig. 3 tests whether a list of tokens is a correct expression. Since the clauses in Fig. 3 do not contain negation, one can assign the trivial mode (log,..., log) to every predicate and obtains a mode assignment # so that the program is/z-correct.

The program of Fig. 3 is not very efficient, since it uses the a p p e n d / 3 predicate to decompose a given list of tokens in all possible sublists. At least the program

Page 29: First-order theories for pure Prolog programs with negation

First-order theories for pure Prolog programswith negation 141

exp(C) :- append(A, [+IB],C), exp(A), term(B).

exp(C) :- term(C).

term(C) :- append(A, [*IB],C), term(A), factor(B).

term(C) :- factor(C).

factor(C) :- append([iparlA], [rpar],C) , exp(A}.

factor([l(X)]).

append([],L,L).

append([XILl],L2, [XIL3]) :- append(Li,L2,L3).

Fig. 3. A simple parser for expressions

list([]).

list([XlL]) :- list(L).

nat(0).

nat(s(N)) :- nat(N).

0 < s(N).

s(M) < s(N) :- M < N.

length([],0).

length([XlL],s(N)) :- length(L,N).

Fig. 4. Some auxiliary predicates

terminates for the intended inputs. This can be shown as follows. Let P be the logic program consisting of the clauses of Fig. 3, 4 and 5. Then one can prove in the inductive extension of P the following formula:

Vl (S l i s t ( l ) -~ T exp(/)) (1)

From this formula one can then conclude that the goal exp( t ) strongly terminates for each list t: Let t be a term so that l i s t ( t ) succeeds in LDNF-resolution. It follows, by Theorem 6.2, that S l i s t ( t ) is provable from the g-completion of P and therefore also from the inductive extension of P. By 1, we obtain that T exp( t ) is provable from the inductive extension. Since T exp( t ) is a positive formula, by Theorem 10.3, we obtain that T exp( t ) is also provable from the g-completion. By Theorem 8.5, it follows that the goal exp( t ) terminates in LDNF-resolution, i.e. every possible computation is finite. In particular, the Prolog computation terminates.

Formula 1 is not provabIe directly using induction on the predicate l i s t . It follows from the following more general formula which is proved by induction on the predicate n a t :

Vm (Snat(m) -+ Vl, n( S length(/, n) -~ T term(l) )) (2) S n < m T exp(l)

A more efficient version of the parser is shown in Fig. 5. This program is com- pletely deterministic. The idea is that the binary predicate e x p / 2 takes as much as it can from an input token list and returns the rest in the second argument. The program of Fig. 5 is correct with respect to the following mode assignment #:

Page 30: First-order theories for pure Prolog programs with negation

142 R.F. Stark

#(exp/2) := {( in , out)}, #(term/2) := {( in , out)}, #(factor/2) := {(in, out)}, #(moreexps/2) := {(in, out)}, ~(moreterms/2) := {(in~ out)}, ~(plus/1) : : {(log)}, #(times/l) := {(log)}.

Having this mode assignment one shows that exp/2 strongly terminates. The follow- ing formula is provable in the inductive extension of P:

Vl, z (5 list(1) -~ T exp(l , m)) (3)

As in the case of exp /1 one can conclude that e x p / 2 strongly terminates in LDNF- resolution. More precisely, if t is a ground list, then exp(t , z) is a #-correct goal and terminates. Again, Formula 3 is not provable directly but it follows from the more general Formula 4 below which is proven by induction on the predicate n a t :

T f a c t o r ( l l , 1 2 ) }

(51ength(ll,n) } Tte rm( l l , / 2 ) T exp(l l , 12) ))

Vm (Snat(m) -~ Vll,12, n( S n < m Tmore t e rms( l l , 12 )

T m o r e e x p s ( l l , 12)

Now we know that both versions of the parser strongly terminate under LDNF- resolution and thus terminate in Prolog. In a next step we show that the two programs are equivalent with respect to success and failure:

Vl (5 list(1) -~ (5 exp(1) ~ 5 exp(l, []))) Vl (5 list(1) -~ (F exp(l) ~+ F exp(l, [])))

(5) (6)

Both formulas follow from the more general Formulas 7-14 below:

Va, b (S factor(a, b) -~ 3c(S append(c, b, a) A S factor(c))) Va, b (S term(a, b) -+ 3e (S append(c, b, a) A $ term(c))) Va, b (5 exp(a, b) -~ 3c (5 append(c, b, a) A 5 exp(e))) Va, b (5 moreterms(a, b) ~ He (S append(c, b, a) A

Vd, e (S append(d, e, e) A S term(d) -~ 5 term(e)))) Va, b (5 m o r e e x p s ( a , b) -~ 9e(5 append(c , b, a) A

Vd, e (5 append(d , c, e) A 5 exp(d) -~ 5 exp(e))))

(7) (8) (9)

(10)

(11)

Formulas 7-11 are proved using sim(P, p) where p consists of 7-11. The converse directions are more complicated:

Va (8 factor(a) -+ Vb, c, d ($ append(a, b, c) -+ (S factor(e,d) +~ d = b)))

Va ($ term(a) -~ Vb, c, d (S append(a, b, c) -~ ($ term(e, d) +~ Smoreterms(b, d))))

Va (S exp(a) -~ Vb, c, d (S append(a, b, c) A F times(b) -+ ($ exp(e, d) +~ Smoreexps(b, d))))

(12)

(13)

(14)

Page 31: First-order theories for pure Prolog programs with negation

First-order theories for pure Prolog programswith negation 143

exp(A,C) : - term(A,B), moreexps(B,C).

term(A,C) : - factor(A,B), moreterms(B,C).

factor([iparlAl,B) :- exp(A, [rparlB]). factor([l(X) IA],A).

moreexps([+IA],C) :- term(A,B), moreexps(B,C). moreexps(A,A) :- not plus(A).

moreterms([*IA],C) : - factor(A,B), moreterms(B,C). moreterms(A,A) :- not times(A).

plus([+IX]). times([*IX]).

Fig. 5. The efficient version of the parser

Formulas 12-14 are also proved by simultaneous induction. Thus all Formulas 1-14 are provable from the inductive extension of P.

Why do 5 and 6 imply that the predicates e x p / 1 and e x p / 2 are computation- ally equivalent? Let t be a ground list so that exp( t ) succeeds in LDNF-resolution. By the soundness of LDNF-resolution (Theorem 6.2) it follows that S l i s t ( t ) and S exp( t ) are provable from the g-completion. Since the &completion is contained in the inductive extension of the program, the two formulas are also provable from the inductive extension. By 5, it follows that S exp( t , []) is provable from the inductive extension. Since the inductive extension is conservative over the g-completion for pos- itive formulas (Theorem 10.3) and S exp( t , []) is a positive formula, we obtain that $ exp( t , []) is provable from the g-completion. Now we can apply the completeness theorem for LDNF-resolution (Theorem 8.5) and obtain that S exp( t , []) succeeds in LDNF-resolution.

In order to apply the completeness theorem we have to know that exp( t , []) does not flounder. But this is obviously true, since the input argument of exp( t , []) with respect to the mode (in, out) is the term t and t is ground. Thus exp(t, []) is a #-correct goal and it does not flounder by Theorem 9.5. Since we already know by 3 that e x p / 2 strongly terminates under condition that the first argument is a list, we can conclude that exp( t , []) succeeds in Prolog. Thus, if t is ground, then Prolog will answer the query exp( t , []) with yes.

Similar reasoning yields that if t is a ground list and exp( t , []) succeeds in LDNF- resolution, then also exp( t ) succeeds in LDNF-resolution. Formula 6 finally says that for ground lists t the goal exp( t ) fails, if and only if, the goal exp( t , []) fails in LDNF- resolution. Thus we have established that e x p / 1 and e x p / 2 are computationally equivalent by purely logical reasoning without referring to the operational semantics of the predicates.

References

h Andrews, J.: A logical semantics for depth-first Prolog with ground negation. Technical Report CSS/LCCR TR93-10, Centre for Systems Science, Simon Fraser University 1993

2. Apt, K.R.: Logic programming. In: van Leeuwen, J. (ed.) Handbook of Theoretical Computer Science, Vol. B, chapter 10, pp. 495-574. Amsterdam: Elsevier 1990

Page 32: First-order theories for pure Prolog programs with negation

144 R.F. Stark

3. Apt, K.R.: Declarative programming in Prolog. In: Miller, D. (ed.) Logic Programming - - Proceed- ings of the 1993 International Symposium, pp 11-35. MIT Press 1993

4. Apt, K.R., Pedreschi, D.: Proving termination of general Prolog programs. In: Ito, T., Meyer, A.R. (eds.) Theoretical Aspects of Computer Software, pp. 265-289. Lect. Notes Comput. Sci. 526. Berlin Heidelberg New York: Springer 1991

5. Apt, K.R., Pedreschi, D.: Reasoning about termination of pure Prolog programs. Information and Computation 106(1), 109-157 (1993)

6. B6rger, E., Rosenzweig, D.: A mathematical definition of full Prolog. Sci. Comput. Program (to appear)

7. Clark, K.L.: Negation as failure. In: Gallaire, H., Minker, J. (eds.) Logic and Data Bases, pp. 293-322. New York: Plenum Press 1978

8. Cohen, J., Hickey, T.J.: Parsing and compiling using Prolog. ACM Trans. Program. Lang. Syst. 9(2), 125-163 (1987)

9. Doets, K.: From Logic to Logic Programming. MIT-Press 1994 10. Drabent, W.: Completeness of SLDNF-resolution for non-floundering queries. J. Logic Program. (to

appear) 11. Fitting, M.: A Kripke-Kleene semantics for logic programs. J. Logic Program. 2, 295-312 (1985) 12. Fitting, M.: Bilattices and the semantics of logic programming. J. Logic Program. 11, 91-116 (1991) 13. H6sli, B., Jfiger, G.: About some symmetries of negation. J. Symb. Logic 59(2), 473-485 (1994) 14. J~iger, G. A deductive approach to logic programming. In: Schwichtenberg, H. (ed.) Proof and

Computation, pp. 133-172. NATO Advanced Study Institute, International Summer School held in Marktoberdorf, Germany, Berlin: Springer (to appear)

15. J~iger, G., Stark, R.F.: A proof-theoretic framework for logic programming. In: Buss, S. (ed.) Hand- book of Proof Theory. In preparation

16. Kunen, K.: Negation in logic programming. J. Log Program. 4(4), 289-308 (1987) 17. Kunen, K.: Signed data dependencies in logic programs. J. Log Program. 7(3), 231-245 (1989) 18. Lloyd, J.W.: Foundations of Logic Programming, 2nd edn. Berlin Heidelberg New York: Springer

1987 19. Mellish, C.S.: Automatic generation of mode declarations for Prolog programs. DAI research paper

163, Dept. of Artificial Intelligence, University of Edinburgh, 1981 20. Mints, G.E.: Complete calculus for pure Prolog. Proc. Acad. Sci. Estonian SSR 35(4), 367-380

(1986) 21. Moschovakis, Y.N.: Elementary Induction on Abstract Structures. Amsterdam: North-Holland 1974 22. Schroeder-Heister, P.: Definitional reflection and the completion. In: Dyckhoff, R. (ed.) Extensions

of Logic Programming. 4th International Workshop, ELP '93, pp. 333-347. Lect. Notes Artificial Intelligence 798. Berin Heidelberg New York: Springer 1994

23. Schiitte, K.: Proof Theory. Berlin: Springer 1977 24. Shepherdson, J.C.: Negation as failure: A comparison of Clark's completed data base and Reiter's

closed world assumption. J. Log Program. 1(1), 51-79(1984) 25. Shepherdson, J.C.: Mints type deductive calculi for logic programming. Ann. Pure Appl. Logic

56(1-3), 7-17 (1992) 26. Shepherdson, J.C.: The role of standardising apart in logic programming. Theor. Comput. Sci. 129,

143-166 (1994) 27. Stark, R.F.: A complete axiomatization of the three-valued completion of logic programs. J. Logic

Comput. 1(6), 811-834 (1991) 28. Stark, R.F.: From logic programs to inductive definitions. In: Hodges, W. (ed.) Logic Colloquium

'93. Oxford University Press (to appear) 29. Stark, R.F.: The declarative semantics of the Prolog selection rule. In: Proceedings of the Ninth

Annual IEEE Symposium on Logic in Computer Science, LICS '94, pp. 252-261, Paris, France, July 1994. Paris: IEEE Computer Society Press 1994

30. Stark, R.F.: Input/output dependencies of normal logic programs. J. Logic Comput. 4(3), 249-262 (1994)

31. Stroetmann, K.: A completeness result for SLDNF-resolution. J. Log Program. 15(4), 337-355 (1993) 32. van Emden, M.H., Kowalski, R.A.: The semantics of predicate logic as a programming language. J.

Assoc. Comput. Mach. 4(23), 733-742 (1976) 33. Van Gelder, A., Schlipf, J.S.: Commonsense axiomatizations for logic programs. J. Log Program.

17(2,3,4), 16t-195 (1993)