A Compositional Semantics For Logic Prog PDF
A Compositional Semantics For Logic Prog PDF
Elsevier
A compositional semantics
for logic programs
A. Bossi
Dipartimento di Matematica Pura ed Applicata, Universitir di Padoua, Via Belzoni 7, I-35131 Padoua,
Italy
Abstract
Bossi, A., M. Gabbrielli, G. Levi and M.C. Meo, A compositional semantics for logic programs,
Theoretical Computer Science 122 (1994) 3-47.
This paper considers open logic programs originally introduced as a tool to build an OR-composi-
tional semantics of logic programs. We extend the original semantic definitions in the framework of
the general approach to the semantics,of logic programs described by Gabbrielli and Levi (1991). We
first define an operational semantic$Lno6P) which models computed answer substitutions and which
is compositional w.r.t. the union 6f programs. Next, we consider the semantic domain of
Q-denotations, which are sets of clauses with a suitable equivalence relation. The fixpoint semantics
F;(P) given by Bossi and Menegus (1991) is proved equivalent to the operational semantics. From
the model-theoretic viewpoint, an Q-denotation is mapped onto a set of Herbrand interpretations,
thus leading to a definition of an R-model based on the classical notion of truth. Moreower, we
consider a particular kind of Q-models (compositional modelsL and we show that I”,(P) is
a (nonminimal) compositional Q-model. A suitable abstraction oq0,( P) is compositional and fully
abstract w.r.t. the equivalence induced by successful derivations! Finally, some applications of our
semantics are discussed. In particular, $J,( P) can be viewed as the foundation of modular program
analysis.
1. Introduction
Correspondence to: A Bossi, Dipartimento di Matematica Pura ed Applicata, Universita di Padova, Via
Belzoni 7, I-35131 Padova, Italy. Email addresses of the authors: bossi(@pdmatl.unipd.it, {gabbri, levi,
meo}@di.unipi.it.
Namely, the only three important concepts are the program itself, the intended
interpretation (declarative semantics) and the theorem prover (operational semantics).
The program is a logic theory. The declarative semantics formalizes the application
that the program is trying to capture. It is an interpretation in the conventional logic
sense and a model of the program. Finally, the theorem prover is a proof procedure
which must be sound and complete with respect to the declarative semantics. Is that
really all there is to it?
The above view is appealing but too simple-minded to capture the difference
between theorem proving and programming. In fact, it applies to any formal system
for which there exists a sound and complete theorem prover. Theorem proving
becomes logic programming when we restrict the class of theories, for example, to
definite Horn clauses, so as to obtain a declarative semantics and a proof procedure
similar to the denotational and the operational semantics of conventional program-
ming languages. This is exactly what van Emden and Kowalski did in their seminal
paper [5.5], where the proof procedure was SLD resolution and the representative
model was the least Herbrand model. According to [SS], the semantics is a mathemat-
ical object which is defined in model-theoretic terms and which can be computed both
by a top-down and a bottom-up construction. Is the above classical and elegant result
a satisfactory solution?
The answer can be found if we first consider a different and more basic question.
What a semantics is used for? The first application of any semantics is to help
understanding the meaning of programs. Other useful applications include areas such
as program transformation and program analysis. One can argue that tens of thou-
sands of logic programmers were really helped by the declarative understanding of
their programs. One can also argue that semantics-based program transformation
and analysis do require deeper results and more elaborate theories, but still only using
basically the above-mentioned simple and straightforward semantics. The above
arguments can become more technical only if we understand which is the basic
semantic property of such formal activities as program transformation and analysis.
The answer coming from computer science is program equivalence, i.e. program
understanding is based on our ability to detect when two programs cannot be
distinguished by looking at their behaviors.
Defining an equivalence on programs = and a formal semantics Y(P) are two
strongly related tasks. A semantics Y(P) is correct w.r.t. z., if Y(P1)=9’(P2) implies
P1 zP2. Y(P) is fully abstract w.r.t. z, if the converse holds, i.e. if PI z P2 implies
Y(P,)= Y(P2). While full abstraction is known to be a desirable property for any
semantics, correctness is a must. The question on the adequacy of the van Emden and
Kowalski’s semantics can then be rephrased as follows. Is that semantics correct w.r.t.
a “natural” notion of program equivalence? And this in turn raises the problem of
choosing a satisfactory notion of program equivalence.
Equivalences can be defined by using logical arguments only. For example, one can
use model-theoretic properties, such as the set of models, the set of logical conse-
quences or the least Herbrand model, and proof-theoretic properties, such as the set of
A compositional semantics for logic programs 5
derivable atoms. However, this would lead us nowhere, since the equivalence we need
must be based on the operational behavior and on what we can observe from
a computation. In other words, we have to learn more from computer science than
from mathematical logic! From a computer science viewpoint, once we have a formal-
ization of program execution, we have a choice for the equivalence. One important
aspect of the formalization, in addition to the inference rules which specify how
derivations are made, is the concept of observable, i.e. the property we observe in
a computation. In logic programs we can be interested in different observable
properties such as successful derivations, finite failures, computed answer substitu-
tions, partial computed answer substitutions, etc. A given choice of the observable
X induces an observational equivalence c x on programs. Namely, P, cx P2 iff P, and
Pz are observationally indistinguishable according to X. For example, if the observ-
able s denotes successful derivations, PI zS P2 iff for any goal G, G is refutable in PI iff it
is refutable in P2. If the observable c denotes computed answer substitutions, PI z:, Pz
iff for any goal G, G has the same (up to renaming) computed answers in PI and in P2.
Since the observable is the property which allows us to distinguish programs and is
also the property we want to preserve in program transformations, the most natural
choice in the case of logic programs is computed answer substitutions, which are exactly
the result of a logic program execution. Other less abstract observables, such as partial
computed answers and call patterns, might be useful in some applications, for example
in semantics-based analysis and transformation. However, a more abstract observable
like success&l derivations would fail in capturing the essence of logic programming,
even if it is the most adequate to the case of first-order theorem proving, where there is
nothing to be returned as a result of the computation.
We can now note that, as first shown in [18, 191, the van Emden and Kowalski’s
semantics is not correct w.r.t. the observational equivalence based on computed answer
substitutions, while it is correct w.r.t. the one based on successful derivations. Namely,
there exist programs which have the same least Herbrand model and yet compute
different answer substitutions. While trying to understand the meaning of programs,
when analyzing and transforming programs, this semantics cannot be taken as the
reference semantics. This is the reason why the need for a different formal semantics,
correct w.r.t. answer substitutions, was recognized by many authors, giving rise to
several new definitions (see e.g. [lo, 21,57, 18, 311). The need for better semantics was
also recognized in the case of semantics-based abstract interpretation [48, 37, 11, 31
and transformation [36, 51, where, as already mentioned, less abstract observables,
such as partial computed answers or call patterns, have sometimes to be modeled.
The same problem was recognized even earlier in relation to some extensions of
pure logic programming. In fact, the weakness of the traditional semantics is even
more serious when trying to model the behavior of extensions such as constraint or
concurrent logic programs, where the observables play a more important role. For
example, finding definitions modeling the observable behavior was, from the very
beginning, the aim of most of the research on the semantics of concurrent logic
languages (see e.g. [43, 29, 24, 53, 131). This was primarily motivated by the fact that
6 A. Bossi et al
parent(elizabeth, j&n). } .
The semantics of open programs must be compositional w.r.t. program union, i.e.
the semantics of Pi uP2 must be derivable from the semantics of PI and PZ.
As already noted, the least Herbrand model semantics, as originally proposed
in [55], and the computed answer substitution semantics in [l&20], are not com-
positional w.r.t. program union. For example, in Example 1.1, the atom unces-
tor(unnu, elizubeth), which belongs to the least Herbrand model of Qr u Qz, cannot be
obtained from the least Herbrand model of Q1 and Qz (see also Example 2.1). Note
that here we are interested in a composition of programs which extends the definition
of a predicate already existing, and we do not consider any overriding mechanisms. Of
course, such mechanisms are also interesting. For example, when considering pro-
grams structured by using inheritance operators, in some cases we want the new
information to replace the old one. The specific semantic treatment for inheritance by
extension and/or overriding is described in [4], and is obtained by a modification of
the framework we show here.
In this paper we generalize the semantics given in [7] for !&open programs,
following the general approach in [23]. In the specific case of L&open programs,
rc-interpretations are called n-denotations and are sets of conditional atoms, i.e.,
clauses such that all the atoms in the body are open. We give a fixpoint semantics,
which is a variation of the one proposed in [7], described in terms of Q-denotations
and an equivalent operational semantics. The resulting denotation is then character-
ized from the model-theoretic viewpoint, by defining a set of denotations which
encompass standard Herbrand models. Particular denotations are called L&models,
and are based on the standard notion of truth and on the fact that each Q-denotation
represents the set of Herbrand interpretations that can be obtained by composing the
open program with a definition for the open predicates. !&models of open programs
are introduced to obtain a unique representative denotation, computable as the least
fixpoint of a suitable continuous operator, in cases where no such representative exists
in the set of Herbrand models. Our C&models are related to the &-models defined in
[7] by means of an ad hoc notion of truth.
The rest of this paper is organized as follows. Section 1.1 contains notation and
useful definitions on the semantics of logic programs. In Section 2 we define an
operational semantics O,(P) modeling computed answer substitutions which is OR-
compositional. Section 3 introduces a suitable semantic domain for the O,(P) semantics
and defines Q-denotations which are sets of clauses modulo a suitable equivalence
relation. In Section 4 the jixpoint semantics FQ(P) is proved equivalent to the
operational semantics. Section 5 is concerned with model theory. From the model-
theoretic viewpoint, an &denotation is mapped onto a set of Herbrand interpreta-
tions, thus leading to a definition of an Q-model based on the classical notion of truth.
A compositional semantics for logic programs 9
1.1. Preliminaries
The reader is assumed to be familiar with the terminology of and the basic results in
the semantics of logic programs [44,1]. Let the signature S consist of a set F of
function symbols, a finite set II of predicate symbols, a denumerable set V of variable
symbols. All the definitions in the following will assume a given signature S. Let T be
the set of terms built on F and V. Variable-free terms are called ground terms.
A substitution is a mapping 9: V+ T such that the set D( 8) = {X 13(X) #X} (domain
of 9) is finite. If WC V, we denote by 91w the restriction of 8 to the variables in W, i.e.
81w( Y) = Y for Y$ W. E denotes the empty substitution. The composition $a of the
substitutions 9 and o is defined as the functional composition. A renaming is a substi-
tution p for which there exists the inverse p-r such that pp-l =~-lp=~. The
preordering < (more general than) on substitutions is such that 96 g iff there exists 9’
such that ,%‘=a. The result of the application of the substitution 9 to a term t is an
instance of t denoted by t9. We define t < t’ (t is more general than t’) iff there exists
8 such that t9= t’. A substitution 9 is grounding for t if t9 is ground. The relation ,< is
a preorder. - denotes the associated equivalence relation (variance). A substitution
9 is a unijier of terms t and t’ if t9- t’9. It is well known that if two terms are unifiable
then they have an idempotent most general unifier which is unique up to renaming.
Therefore, mgu(t,, tz) will denote such a most general unifier of tl and t2. All the
above definitions can be extended to other syntactic expressions in the obvious way.
An atom is an object of the form p(tl, . . . . t,), where PEG, tl, . . . . &ET. A clause is
a formula of the form H :- L1, . . , L, with n 3 0, where H (the head) and L1, . . . , L, (the
body) are atoms. “:-” and “,” denote logic implication and conjunction, respectively,
and all variables are universally quantified. If the body is empty, the clause is a unit
clause. A clause H :- B1, . . , B, subsumes the clause K :-D,, . . , D, iff there exists
a substitution 9 such that H9= K and (B, 8,. .., B, 8} E (DI, . . . . Dm}. A program is
a finite set of clauses. A goal is a formula L1, . . . . L,, where each Li is an atom. By
Var(E) and Pred(E) we denote, respectively, the sets of variables and predicates
occurring in the expression E. A Herbrand interpretation I for a program P is a set of
ground atoms. The intersection M(P) of all the Herbrand models of a program P is
a model (least Herbrand model). M(P) is also the least fixpoint of a continuous
transformation Tp (immediate consequences operator) on the complete lattice of
Herbrand interpretations. If G is a goal, G A’p,R B1 , . . . , B, denotes an SLD derivation
10 A. Bossi et al.
of the resolvent B,, . . . , B, from G in the program P which uses the selection rule R and
where 9 is the composition of the mgu’s used in the derivation. If R is omitted, we
mean that any selection rule is used (and the definition is independent from the
selection rule). q denotes the empty clause, therefore G A,o denotes the refutation of
G in the program P. The computed answer substitution of a refutation G A,o is the
substitution obtained by the restriction of 9 to the variables occurring in G. G &
will denote explicitly the refutation of G in P with computed answer substitution
p. The notations 2 and r? will be used to denote tuples of terms and variables,
respectively, while B”denotes a (possibly empty) conjunction of atoms.
PI ={dX):-P(X). P*={P(b).l
r(X):-s(X).
s(b).
p(a). 1.
the union of the two programs cannot be obtained from the semantics of the
programs. Note that also the least Herbrand model is not compositional w.r.t.
u since, for previous programs Pi, P2 and Pi u P2, M(P) is the same as 0(P).
Definition 2.2 (Q-open program). An Q-open program @-program for short) is a logic
program P together with a set 52 of predicate symbols. A predicate symbol occurring
in Sz is considered to be only partially defined in P.
The definition of any predicate symbol p~!2 in an C&open program P can always be
extended or refined. For instance, in Example 1.1 program Q1 is open w.r.t. the
predicate parent and this predicate is refined in program Q2. Therefore, a deduction
concerned with a predicate symbol of an R-open program P can be either complete
(when it takes place completely in the program P) or partial (when it terminates in
P with an atom p(E) such that p~s2 and p(f) does not unify with the head of any clause
in P). A partial deduction can be completed by the addition of new clauses. Thus, we
have a hypothetic deduction, conditional on the extension of predicate p.
Let us consider again the program PI of Example 2.1 and assume Sz= { p}. Then, the
goal r(X) produces a complete deduction only, computing the answer substitution
{X/b}. The goal q(X) produces a complete deduction computing the answer substitu-
tion {X/a}, and a hypothetical deduction returning any answer that could be com-
puted by a definition of p external to PI. The goal q(b) has one hypothetical deduction
only, conditional on the provability (outside P,) of p(b). We want to express this
hypothetical reasoning, i.e. that q(b) is refutable if p(b) is refutable. Hence, we will
consider the following operational semantics.
Note that, for s2 = @,i.e. when all the predicates are considered completely defined,
the previous definition boils down to the definition of the s-semantics [18]. On(P) is
a set of resultants [45] obtained from goals of the form p(g) in P and is essentially the
result of the partial evaluation of P, where derivations terminate at open predicates
(i.e. predicates in Q). The set of clauses Ida in the previous definition is used to delay
the evaluation of open atoms. As shown by Proposition 2.6, this is a trick which allows
one to obtain, by using a fixed fair selection rule R, all the derivations
P(X lr ...Txk) ‘%,R I B,, . . , B, which use any selection rule R’ for Pred(B1, . . . , B,) E ~2.
Therefore, the previous definition is independent from the fair selection rule con-
sidered. Note that in the first step of the derivations we use clauses from P (instead of
from P*) because we want O,(P) to contain a clause p(g):-p(g) if and only if
p(X) App(X). The proof of the following proposition is in the appendix.
Proposition 2.6. Let R be a fair selection rule, let P* = Pvld,, x” a tuple of distinct
variables and Pred(B1, . . . . B,)GQ. Then there exists a rule R’ such that
p(Jf)z*p,R,B1 ,..., B, ifsp($&,.D, ,..., Dm&I,RB1 ,..., B, and p(Z?)ya=p(r?)S.
Example 2.7. Let PI, P2 be the Q-open programs of Example 2.1, where 52= { p}. Then
s,(P,)=(p(a),q(a),r(b),s(b),q(X):-p(X)),
%(P,)= {p(b)).
0, contains enough information to compute the semantics of the composition. In fact,
~(PluP,)~O,(PluPz)={p(a),p(b),q(a),q(b),r(b), s(b),q(X):-p(X)1
and
~n(pl~pz)=~*(~n(p1)~~n(Pz))
(see Theorem 2.13).
Definition 2.8. Let PI, P2 be Q-open programs. Then PI z R Pz if for every goal G and
for every Q-program Q s.t. PiuaQ, i= 1,2, is defined, G %P,Uoeu iff G %p,vnao and
G$r = G$ up to renaming.
Co, allows one to characterize a notion of answer substitution which enhances the
usual one, since (unresolved) atoms, with predicate symbols in Sz, are also considered.
Therefore, it is able to model computed answer substitutions in an OR-compositional
way. Indeed, Theorem 2.10 shows that a program P and its operational semantics
O,(P) are %:R equivalent. As a consequence, the semantics Q,(P) correctly captures
the computed answer substitution observable when considering also the programs
union, i.e. Co,(P) is correct w.r.t. the equivalence z R (Corollary 2.11). Theorem 2.13
shows the compositionality of the semantics w.r.t. the operator uo. The proof of
Lemma 2.12 is also in the appendix.
The proof of Lemma 2.9 is in the appendix and is an extension of the proof of the
completeness Theorem in [ 191.
Proof. We have to show that for every R-open program Q such that Lo,(P) uR Q and
P un Q are defined, G ~c,cPjva q iff G 2 PUa q, where Gy, = Gy, (up to renaming) (note
that if P un Q is defined then On(P) uR Q is also defined but the converse is not true).
By the independence from the selection rule for SLD refutations [44,1], we can
assume that the selection of the atoms is performed according to the following rule
denoted by Y:
(1) first select the nonopen atoms (i.e. the ~(2)‘s such that p$sZ),
(2) among the nonopen atoms, first select those which are added to the current
resolvent by the last inference step (i.e. those in the body of the last used clause).
We will show that, when considering successful derivations, G %Eno.JuQ,Y R in one
step iff there exists n such that G 2 PUp,y R in n steps and G9, = Ga2 (up to renaming).
The thesis follows from the above result by a straightforward inductive argument and
by definition of %a. In the following we consider resolvents as multisets, and we
denote by (G\A), B the multiset obtained from the multiset of atoms G by deleting the
atom A and by adding the multiset of atoms B. Let p(t) be the atom selected in G. If
p(f) is reduced by using a clause in Q, the thesis follows with n = 1. Otherwise let R be
defined as follows:
(1) (R = G\p(f)) 9,) B is the first resolvent (f G) in the derivation G GPUa,, q such
that Y(R)=A& and either Pred(A)ESZ or AEG. Note that by definition of Y,
Pred(B) C 52.
14 A. Bossi et al.
(2) If there does not exist an R as specified in (l), then R is the empty resolvent.
Such an R exists since we are considering finite (successful) derivations. For R as
specified in (l), we have
$1
G -'P~Q,Y R iff (by definition of R and of 9)
P(X) 2P,.Y & iff (by Definition 2.5 and Proposition 2.6)
G %n~~w@\p(f)b, Bzo,
where 0 = mgu( p(x)&, p(E)), Go = G9i and B2 o = B (by Lemma 2.9). For R as in (2)
the same holds with R,B,B2 and G\p(t”)=@ and this completes the proof. 0
Corollary 2.11 (Correctness). Let P, , P2 be O-open programs. Zf O,( PI) = O,( Pz) then
P1 =:R P2.
Lemma 2.12. Let P be a program and G be a goal. Then G Ap, R N i. G Ap, RCN, where
8’
$1VW(G)= Q’bar(G) and the derivation G -+P,Rs N is obtained from G zp,R N by changing
the order in which the atoms are selected.
A l,...,Ai-1,~(t),Ai+l,...,A,~,,,(p~).~,
(A 1,...,Ai-l,B1,...,B,,Ai+l, . . ..A.)$
(A ...,Ai-l)yl,
1, B’I, . . ..BX.(Ai+l, ...,Arn)yl.
By definition of B;, . . . . Bi and since the bindings for variables in Al, . . . . A, are
determined by the variables in p(t), we have
(A 1, . . ..Ai-l.P(t”),Ai+l,...,A,)yl=(A1, . . ..Ai-l.p(t”),Ai+l,...,A,)$
and
(Al,...,At_l)lu’l,B;,...,Bb(Ai+l,...,A,)1/1.
Therefore, the thesis holds by a straightforward inductive argument.
Only if: Assume that G zp, UP2,R B1 , . . . , B, with Pred(B,, . . . , B,) c 0, and, without
loss of generality, assume that the first atom selected is p(Z) and the first clause used in
the derivation is in Pi. Since Pred(Bi , . . . , B,)cQ, by Lemma 2.12 we can assume that
the selection rule R is Y as specified in the proof of Theorem 2.10, considering as
nonopen atoms the p($s such that ~$52,. Also, the notation (G \A), B is the same as in
such a proof. Let N be defined as follows:
(1) N = (G \ p(f)) 9,) B is the first resolvent (# G) in the derivation
iff
0
G-, CO,(Pl),YN,
3
G-t PIUP2,.Iy B 1, ..., Bn iff (by definition of N and of 9’)
3, V
G -YP,,YN -+P,~P~,.YBI, . . ..B. iff (by previous iff)
$1 Y
G-t CD,(PI),Y N-P,“P~,Y&, . . ..B.,
Note that when considering 52= 8, Theorem 2.18 is the completeness theorem of the
s-semantics in [ 1S].
In this section we formally define the semantic domain which characterizes the
above-introduced operational semantics On. Since On contains clauses (whose body
predicates are all in a), we have to accommodate clauses in the semantic domain
we use. The n-interpretations of Q-open programs will be called !2-denotations.
An Q-denotation can be viewed as a function from interpretations to interpreta-
tions since it contains conditional atoms. As usual, in the following, 52 is a set of
predicates.
In order to abstract from the purely syntactical details, we have to use an equiva-
lence on conditional atoms. We use variance, considering bodies as multisets. Coarser
definitions (correct w.r.t. z*) can be used. = denotes syntactic identity.
Definition 3.2. Let c1 =A1 :-B1, . . . . B,, c2 =A2 :-D,, . . . . D, be two clauses. Then
c1 d c c2 iff there exists a substitution o and there exists ( il, . . . , in} c { 1, . . , m} such
that (A,:-Bl,..., B,)~TEA~:-D;, )..., Di,. We denote by = the equivalence induced
by f,. Moreover, we denote still by N the equivalence on sets of clauses defined as
follows. P, N P2 iff Vc2~P23cI~P1 such that c1 ?c2 and vice versa.
A compositional semantics for logic programs 17
Note also that considering bodies of clauses as sets instead of multisets in the
definition of d E(i.e. considering subsumption equivalence as N) would not be correct
w.r.t. computed answer substitutions. The following is a simple counterexample.
Definition 3.5. The Gconditional base, GF?~,is the quotient set of all the C&conditional
atoms w.r.t. N.
Remark 3.6. In the following we will denote the equivalence class of a conditional
atom c by c itself. Moreover, any (semantic) subset I of %?*will implicitly be considered
also as an arbitrary (syntactic) a-open program ~(1) obtained by choosing for each
equivalence class CEI an arbitrary element ,u(c) as representative of c. The basic
derivation step (unfolding) is independent from the choice of p(I), i.e., N is a congru-
ence w.r.t. the unfolding operator. All the semantic operators that we will use on
subsets of (Zfi (such as Tf) can be reduced to several applications of this basic step.
Therefore, we can define any semantic operator on 1~9~ in terms of its syntactic
counterpart defined in p(Z), independently from the specific p(Z). In general, all the
18 A. Bossi et al.
Definition 3.7 (Cl-denotations). An Q-denotation I is any subset of Ce,. The set of all
the Q-denotations is denoted by 9%.
Remark 3.8. In the following the operational semantics 0, will be formally con-
sidered as an Gdenotation. All the previously stated results for O,(P) hold also with
such a definition. In fact, in every proof we can consider syntactic clauses as represent-
atives of --equivalence classes, and hence we can obtain a proof for the case of
Q-denotations also. This is correct since, as previously discussed, the derivation step is
independent from the choice of the representative of the equivalence class.
Remark 3.9. As shown by the following example, the converse of Corollary 2.11 does
not hold, i.e. the semantics O,(P) is not fully abstract w.r.t. z R. In fact, in general, it is
not sufficient to define denotations as sets of equivalence classes of clauses. A full
abstractness result (w.r.t. z n) was obtained in [31]. However, denotations in [31] are
not sets of clauses and the result is obtained by saturating the denotation of a program
using essentially the definition of zfi (restricted to union with atoms). A similar full
abstractness result could be obtained in our case by using the zQ equivalence on the
domain.
4. Fixpoint semantics
In this section we define a fixpoint semantics .!FD(P) which is proved in Section 4.1,
to be equivalent to Co,(P). This can be achieved by defining an immediate conse-
quence operator TF on the lattice (99, G) of Q-denotations. F,(P) is the least fixpoint
of TF.
A compositional semantics for logic programs 19
Definition 4.1 (Unfolding). Let P and Q be C&open programs. Then the unfolding of
P w.r.t. Q is defined as
unfp(Q)=((A:-~1,...,2,)9I~A:-B1,...,B,~P,3BI:-Zi~Q,renamedapart
for i= 1) . ..) n, s.t. 9=mgu((B1, . . . . B,), (B;, . ..) Bb))}.
r(X) :-s(X).
s(Y):+q(Y).
s(a). 13
unf,(P)=(p(X, Y):-@),q(Y).
p(X, a) :-s(X).
r(X) :-q(X).
r(a).
s(a). 1.
Definition 4.3 (Immediate consequences operator) (Bossi and Menegus [7]). Let P be
an a-open program and let I be an C&denotation. Then we define
Note that, for C2= 8, TF is the immediate consequence operator introduced in [ 181
whose least fixpoint is the s-semantics.
Proposition 4.4 (Bossi and Menegus [7]). TF is monotonic and continuous on the
complete lattice (9, C).
The notion
of ordinal powers for TF is defined as usual, namely
T,“TO=& TgTn+
1= TF(TFfn) and TgTo= U.aO(Tgtn). Since Tg is continuous
on (9, G), well-known results of lattice theory allow one to prove the following
proposition.
20 A. Bossi et al.
Proposition 4.5. TFro is the least fixpoint of Tp on the complete lattice (9, G).
Definition 4.6 (Bossi and Menegus [7])( Fixpoint semantics). Let P be an Q-open
program. The fixpoint semantics PO(P) of P is defined as FQ(P)= Tzto.
Example 4.7. Let P be the program of Example 4.2 and Sz= (4).
T~~2=unf,(T~f1uZdn)={r(X):-q(X). r(a).
s(Y):-q(Y). s(a).>,
s(Y):-q(Y). s(a). 1.
@-c(P)= TFf3
The equivalence between the operational and the fixpoint semantics can be proved
by introducing the intermediate notion of unfolding semantics q*(P) [41,42,14].
%a( P) is obtained as the limit of the (top-down) unfolding process. Since the unfolding
rule preserves computed answers in a compositional way, aa is equivalent to the
operational semantics &&n(p).The proof of this equivalence is straightforward, since
O,(P) and aD(P) are based on the same inference rule (applied in sequence and in
parallel, respectively). On the other hand, the equivalence between aa and the
bottom-up semantics FQ(P) can be based on the relation T;(Z) = unfp(Z u I&). Let us
first formally define the unfolding semantics.
L*(P)={cEPlcEG?&}.
Definition 4.9 (Unfolding semantics). Let P be an Q-open program. Then we define the
collection of programs
PI =P,
A compositional semantics for logic programs 21
Example 4.10. Let P be the program of Example 4.2 and 52= 14).
P,=P,
s(Y):-q(Y). s(a). 1,
s(Y):-q(Y). s(u). 1,
&(P)=P,.
In order to prove the equivalence we need two lemmata. The first one states the
associativity of the unfolding operator.
Lemma 4.11 (Denis and Dalahaye [14]). Let P,Q, W be programs. Then
un!(unfa(W))= un?JIspcQ,(W).
Lemma 4.12. Let P be an Q-open program and let P,, be us in Dejinition 4.9. Let
W be a set of clauses and let us define unf i( W)=unf,( W) and, for n> 1,
unf F( W) = unfp(unf ;-‘( W)). Then, for n 2 1, we have
(1) unfp(unf F’(W)=unf F’(unf4W)),
(2) unfP~+,(W)=~nfp(unf~,Id,(W)),
(3) unf “,,,,n(lda) = Ida u T; t n,
(4) TfTn=l,(PJ.
w~P,+ I ( W = ~~f,n~pn~~v~~,~(
W V-v Definition 4.9)
= unfp(unf~;:d,,(unfp”,d”
( W))) (by inductive hypothesis)
=unfp(Zd,uT~fn)uunfId,(T~~n)uZd,
(by definition of ZdQ)
= TFTn+ 1 uZdnuunfld,(T~fn)
(by definition of t and by Definition 4.3)
The last equality holds because, by definition of Id* and the unfolding rule,
unf&(T~fn)G T:lr~ and, since TF is monotonic, TFtns TF t n+ 1.
(4) First note that, by Definitions 4.9 and 4.3, lo(P,)= unfp,(Zdn)= TFn(@). Since
PI = P, ln(P1) = T!(O) = TFt 1. For n > 1 note that, by definition of r and by Definition
4.3, TFrn = unfp(ZdQ u Tg t n - 1). Then for n > 1 the following equalities hold:
The following theorem shows the equality of the unfolding and the fixpoint
semantics.
Proof. By definition, FO(P)= TFfw. Note that c~T:fo iff 3n such that c~T:fn and
G@*(P) iff 3n such that CEZ~(P,J. Then the thesis follows from part (4) of Lemma
4.12. 0
The following theorem states the equality of the unfolding and the operational
semantics. The proof (in the appendix) is straightforward since both the semantics are
top-down and are based on the same inference rule.
Proof. To simplify the notation let us denote TFro by F, and TFrn by F,. By
Definition 4.16, we have to prove that unfF,(F,uIdn)=F,. We show the two inclu-
sions separately.
unfF,(F,uZd,)EF,: Note that CEF, iff 3n such that CEF,,. We then prove, by
induction on n, that Vn 3 0, unfF,(F,u Idn) s F,.
For n=O, the proof is straightforward, since F,, =8 and unf(FouIdn)=@
24 A. Bossi et al.
unfF,(F,uzd,)=unf,(un~F~_,“ldn(Fwuzdn))
c_unfp(Fw u Id,)
(by inductive hypothesis and by definition of I&)
unf,(F, u Idn) 1 Fw: We prove, by induction on n, that Q n > 0, unf,(F, u Zdn) 2 F,,.
For n = 0, the proof is straightforward, since F,, = 8.
For n>O, we have
Proposition 4.18. Let IEW~. Then Tyrw is the least (w.r.t. set inclusion) subset of
%?owhich is u-closed and which contains I.
c T;(H) (since I E H)
=H (since H is u-closed).
Lemma 4.19. Let P be a u-closed set of clauses and let Q be a set of atoms with
Pred(Q)cSZ. Then, for any n> 1, TcUQtn= T$(Q)“Q.
A compositional semantics for logic programs 25
Proof. The proof is by induction on IZ.For n=2, by Definition 4.3, we have to prove
that
~rlfp,~(~nfp,~(0))=~n~(Q)uQ.
We show the two inclusions separately. By definition of unfolding,
unfp,n(unfpua(8))=unfp(unfp(8))uQ)uQzunfp(Q)uQ.
On the other hand,
=WY,n~,~Pu~~n~(Q)uQ
(byLemma 4.11)
=efp(Q)uQ (since P is u-closed)
and the thesis holds for the base case. The proof for the inductive case is identical and
thus omitted. 0
Proposition 4.20. Let P be an Q-open program and let Q be a set of atoms with
Pred(Q)Gfi. Then for any goal G=A1,...,A,, G4’Pu,Q~ ifs there exists
B 1,...,~n4~pd~~~~ such that Y=mga((A,, . . ..A.), (B,, . . ..B.)) and
YIVnr(G)=QIVar(G).
Proof. The completeness theorem of s-semantics [lS] can be obtained as the particu-
lar case g=$!l of Theorem 2.10 and can be stated as follows. G AP q iff there exists
B l,...,B,~T$tw such that Y=mgu((A1,...,A,)(B,,...,B,)) and YIv~~(~)=QIv~~,G).
By definition of F*(P) (and a straightforward inductive argument), T!,qtco=
T”F,>:,p),,afw. Since F&P) is u-closed, by Lemma 4.19 and by definition of T,
T%,,(P&~= T!&,P, (Q)uQ and the thesis holds. 0
5. Model theory
Zp is a “model” (O-model) of P iff all the Herbrand interpretations in #(lp) are models
of P. Depending on which sets J we allow to use as closures for Q-denotations we
obtain different classes of Q-models.
In this section, we first define Q-models which are obtained by using a restricted
definition %‘(Zp). Such a restriction allows to obtain a large class of !&models which
includes the standard Herbrand models. We show that the least upper bound of the
u-closed Q-models of a program P (according to a suitable ordering) is the least
Herbrand model of P. We then introduce a particular class of Q-models which are
obtained by using the more general definition of X(lp), and hence are compositional
w.r.t. uQ. We show that FQ( P) is a compositional Q-model. Finally, we prove the full
abstractness of a (compositional) model-theoretic semantics w.r.t. the equivalence
induced by the successful derivation notion of observable.
5.1. Q-models
~‘(Z)={M(luJ)IJcA,(Z)},
P={q(X):-P(X)
r(X):-s(X).
s(b).
P(a). ).
A compositional semantics for logic programs 27
Let us assume Q= { p> and consider the Q-denotation O,(P), which, according to
Definition 2.5 is
~,(P)=(q(X):-p(X),~(a),q(a),r(b),s(b)).
By Definition 5.1, &@‘(OQ(P,))=(H1, Hz, H3, . ..}. where, denoting by [p(X)] the set
of ground instances of p(X),
In general, we can prove that O,(P) is an Q-model of P. The proof follows from
a more general result that we will give in Section 5.2 (see corollary 5.24).
Note that in Definition 5.1 we impose a restriction on the set J of ground atoms
which are added to the R-denotation I in order to completely specify the “open”
predicates. Namely, we require that J contains only atoms which unify with atoms
already in bodies of clauses in 1. The reason for such a restriction is that we want that
standard Herbrand models are also Q-models (Proposition 5.5). Clearly, if M is
a Herbrand model of the program P and N is an arbitrary set of ground atoms, Mu N
could be not a model of P. Therefore, as shown by Example 5.6, if we drop our
restriction in Definition 5.1, Proposition 5.5 does not hold anymore.
Example 5.6. Let us consider the Q-open program P = { p(u) :-q(u)}, where Q= {q}.
Then 8 is a (the least) Herbrand model of P. If, by violating the condition J c An(Z),
Ma)WV)9 8 would not be an Q-model of P because (q(u)} is not a Herbrand
model of P.
property does not hold any more when considering Q-models with set-theoretic
operations.
464 1.
The O,(P)={p(b):-q(b),p(X),q(a)} and M(P)=(q(a)}u{p(~)lfis a ground term}.
By Definition 5.3 O,(P) and M(P) are Q-models of P. However, O,(P)n M(P) =
{q(a)} is not an Q-model of P.
Intuitively, the Q-model intersection property does not hold because set-theoretic
operations do not adequately model the operations on conditional atoms. Namely,
the information of an Q-denotation Ii may be contained in Z2 without Ii being
a subset of Z2. In order to define the model-theoretic semantics for Q-open programs
as a unique least u-closed Q-model, we then need a suitable partial order & on
Q-denotations. c should model the meaning of Q-denotations, in such a way
that (9, L) is a complete lattice. This can be obtained by considering c as
given in Definition 5.8. It is worth noting that the least u-closed Q-model is the
standard least Herbrand model (Proposition 5.17). Moreover, the most expressive
Q-model O,(P) is a nonminimal Q-model (see Section 5.2). The following definitions
are similar to those given in [20] for the noncompositional semantics of positive logic
programs.
The proof of the following proposition is the same of the analogous in [20].
Proposition 5.9. The relation <d is a preorder and the relation E is an ordering.
NotethatifZ,cZz,thenZ,cZ,,sinceZ,~Z2impliesZ, ddZ2.Toshowthattheset
of Q-denotations with c is a complete lattice we need two more propositions.
q(b) :-p(b)
4(b):-P(X)
Min(J)={q(X):-p(X),?.(X)
q(b) :-p(X)
r(b) 1.
Proposition 5.12. Let I1 and I, be Q-denotations. Then I1 <,I2 and Z2 ddZl iff
Min(Z,)=Min(Z,).
Note that Min(/l)=Min(U/1). We can now prove the following proposition. The
proof is essentially that one in [20], rephrased by using Proposition 5.12.
Proposition 5.14. For any set A ofQ-denotations there exists the least upper bound of
Proposition 5.15. The poset of all the Q-denotations (9, E) is a complete lattice with lub
operator given by UX (Dejnition 5.13). Wo is the top element and 0 is the bottom
element.
Proof. For any set n of !&denotations, the existence of its least upper bound is
ensured by Proposition 5.14. The greatest lower bound of n is then given by
glb(A)=lub({Z~9~VZ’~A, ZEZ’}). 0
Proposition 5.16. For any u-closed Q-model I of a program P there exists a standard
Herbrand model I’ of P such that I’ c 1.
Proposition 5.17. Let P be a program. Then glb( {ZEN 1I is an S&model of P>)= M(P)
(the least standard Herbrand model of P).
Proof. Note that the standard Herbrand models are ordered by set inclusion, then
apply Propositions 5.9 and 5.16. 0
A compositional semantics for logic programs 31
~(Z)={M(zuJ)~Js~‘n}.
Definition 5.19. Let PI, P2 be Q-open programs. Then PI z~,~P~ iff for any Q-open
program Q such that PI uo Q and P2 uoQ are defined and for any goal G,
8
G-t Plu,Q 0 iff G ‘Pz”,Q. 0
The following theorem generalizes the result given in [31] for the case R = ZZ.
Theorem 5.20 (Gabbrielli et al. [25] ). Let PI, P2 be programs. Then PI $ o P2 ifs there
exists a set of atoms Q ~69, such that PI uoQ $@Pz uo Q. Moreover, PI +og PZ
ifs there exists a set of (ground) atoms Qz@o such that PI unQ $:,,,Pz u~Q.
Corollary 5.21 (Gabbrielli et al. C2.51). Let PI and P2 be &open programs and let
assume that programs are defined on a signature containing infinite constant symbols.
Then for any Q~47o and for any goal G, G ~P,,,Q q implies G &VnQ q iff for every
set Q C B* of (ground) atoms M( PI u Q) E M( P2 u Q).
32 A. Bossi et al.
The following proposition shows that compositional S2-models satisfy the pre-
viously sketched compositional properties. Note that the proposition does not hold
for Gmodels.
J=M(O,(P)uZ)
where ZsBo and Z’={p(f)lp~52 and p(t”)~J). Since V’i=l, . . ..n. BioEJ, there exists
Bi:-Di,l, ..., Di, k, variants of clauses in cOo(P) u I& and 3oi such that B:ai = Bio and
Di,joiEZ’, Vj= 1, ...) ki. Then, by definition of Q&P), 3(A:-D1.1, . . . . Dl,k,, . . . .
Dn,l, . . . . D,,k,)y~On(P) and 30’ such that Aya’=Aa and Vi= 1, . . . . n, Vj= 1, ...) ki,
Di,jyo’~Z’. Thus, Aya’=.4o~J which contradicts the hypothesis. 0
Proof. The proof is straightforward from Theorem 5.23, Definitions 5.3 and 5.18. 0
In the following, we use the notation [ ] also for SZ-denotations, i.e. we denote by
[Z] the n-denotation (c~%?oj ~c’EZ, c=p(c’)S and c is ground}, where ,u(c) gives one
element of the equivalence class c. Clearly, the definition of [Z] is independent from
the choice of the element ,u(c’).
We have shown that Be(P) is a compositional Q-model. Clearly, since the
zo equivalence is finer than z~,~, the semantics Co,(P) is correct w.r.t. ~o,~, i.e. if
O,(P,)=Bn(Pz) then PI z R,gP2. Obviously, since O,(P) also models computed
answers, this semantics contains too much information to achieve also full abstract-
ness w.r.t. zR,g. In order to achieve such a result, we then need an abstraction on
O,(P).
First note that a goal G has a successful derivation iff a ground instance of G has
a successful derivation. Therefore, for successful derivations it is sufficient to consider
the ground version [I] of the denotation Z of a program. Note also that if a clause
c subsumes c’ then each successful derivation can be performed by using c instead of
c’. Moreover, tautological clauses can be deleted. Indeed, since a tautology contains in
the body, a copy of the head, if a successful derivation for the goal G in a program
P uses a tautology c then there exists also a successful derivation for G which does not
use c. All these observations allow to formally define the abstraction J&‘~(P) of @o(P)
as follows. We say that a clause c properly subsumes the clause c’ iff c subsumes c’ and
c’ does not subsume c.
c is not a tautology,
For a set Q of ground clauses, wcf(Q) returns the clauses in Q, modified by deleting
repetitions of atoms in the body, which are not subsumed by other clauses in Q, and
which are not tautologies. Note that wcf(Q) is the weak canonical form [46] of Q. The
(weak) canonical form of a set P of (possibly nonground) clauses can be obtained [46]
by “partitioning the clauses of P according to subsumption equivalence, by choosing
the reduced clause for each equivalence class and then deleting those clauses which are
subsumed by some other clauses (and tautologies)“. A clause c is reduced [Sl] if it
contains no identical atoms in the body and cannot be subsumed by a nonrenaming
instance of c. Reference [46] shows that each clause is subsumption-equal (up to
renaming) to a reduced clause and that the (weak) canonical form is unique up to
renaming (considering bodies as sets). The following theorem shows the relation of
these notions with the Tp operator. Recall that two sets of clauses P and Q are weakly
subsumption equivalent if for every CEP which is not a tautology there exists C’EQ
such that c’ subsumes c and vice versa. Moreover in the following by Tp + id = T, + id
we mean that for every set of ground atoms X, Tp(X)uX = TQ(X)uX (id is the
identity).
Theorem 5.27 (Maher [46]). Let P, Q be sets of clauses. P and Q are weakly subsump-
tion equivalent ifs Tp + id = T, + id.
Lemma 5.28. Let P, Q be (possibly injinite) sets of ground clauses. Then P is weakly
subsumption equivalent to Q ifs wcf(P) = wcf(Q).
For finite sets, the nonground version of the previous lemma was proved in [46]
(i.e. two finite sets of possibly nonground clauses are weakly subsumption equivalent
iff they have the same weak canonical form). However, note that Lemma 5.28 does not
A compositional semantics for logic programs 35
hold if we consider possibly nonground clauses, and therefore we consider kvcf as the
weak canonical form as in [46]. A counter example can be obtained by considering
the program P given in [30]
P=(c,)A:-R(X,,X,)
c2)A:-R(X1,X*),R(X2,X1)
since in this case we have an infinite chain c1 >cz> ‘.I (cl properly subsumed by
c2 . . . ).
Theorem 5.31 shows the full abstraction result. A different fully abstract invariant
w.r.t. z~,~ was already given in [30].
Lemma 5.29. Let PI, P2 be programs. Then PI z R,g Pz ifs [PI] z R,~[ Pz].
Lemma 5.30. Let .C?be a set of predicates and let P, W be u-closed sets of ground
clauses such that if H :-~EPU W then Pred(g)s 52. Then P %n,s W iff
wcf(P)= wcf( W).
Proof. By Lemma 5.28, since P and Ware sets of ground clauses, wcf( P) = wcf( W) iff
P and Ware weakly subsumption equivalent. By Theorem 5.27, P and Ware weakly
subsumption equivalent iff T, + id = T, + id. Moreover, by Corollary 5.21, P NN~,~W
iff VQ c 91n, M (P u Q) = M( WV Q). By hypothesis all the predicate symbols appearing
in the bodies of clauses in P and Ware contained in R. Then to prove the thesis we
only need to prove that VQC-W,, M(PuQ)=M(WuQ) iff T,+id=T,+id. We
prove the two implications separately.
“If”: SinceT,,,(X)=T,(X)uT,(X),ifT,+id=T,+idthenT,,~+id=Tw,,+id.
Since M(P)=T,to=T,+idtw, M(PuQ)=M(WuQ).
“Only if”: Let us consider a set Q of ground atoms. Note that, since P is u-closed,
M(PuQ)=TpUa(Q)=T,(Q)uQ. Analogously M(WuQ)=T,(Q)uQ. Then, since
VQ,M(PuQ)=M(WuQ), VQ set of ground atoms Tp(Q)uQ=Tw(Q)uQ, i.e.
T,+id= T,+ id and this completes the proof. 0
Proof. First note that, by (a particular case of) Theorem 2.10, P zOn,gOn(P) and
hence PI z,,~P, iff cO,(P,) x~,~ O,(P,). Therefore, we have the following implica-
tions:
~n(P1)=~n(P2)7
Let us finally show that A,(P) is a compositional O-model. Then A,(P) can be
considered as the compositional model-theoretic semantics of the program P.
Proof. Note that, by definition of Herbrand model, M(Z u J) = M( [I] u J) and there-
fore X(Z)=X([Z]). Then to prove the thesis, we only need to show that
s( [Z])= ~Y(wcf( [I])). Note that, by definition of wcf, [I] and wcf( [I]) are weakly
subsumption equivalent (i.e. they have the same weak canonical form). Then, by
Theorem 5.27, Trrl+ id = TwCfC[rlJ + id. Note that, in general, T,,,(X) = T,..(X) u Tp(X).
Then, V.Z set of atoms qIIUJ +id=TwCf,,,,,,J+id, and therefore M([Z]u.Z)=
M(wcf( [Z]) u .Z) (since M(P) = Tpru). Then &‘( [Z]) = X’(wcf( [Z])), and the thesis
holds. 0
6. SO-models
We will now consider the relation between Q-models (Definition 5.3) and the
So-models defined in [7] on the same set of denotations. Both the Q- and &-models
are intended to capture specific operational properties, from a model-theoretic point
of view. However, S,-models are based on an ad hoc notion of truth (S,-truth) and the
A compositional semantics for logic programs 37
least &-model is exactly F*(P). Conversely, !&models are based on the usual notion
of truth in a Herbrand interpretation through the function 2’. FQ(P) is a nonmini-
ma1 a-model.
Definition 6.1 (Bossi and Menegus [7]) (Sn-truth). Let 52 be a set of predicate symbols
and I be an Q-denotation. A definite clause c = A :- B1, . , B,, m 2 0 is SO-true in I iff
u&(Z u Zdo) E I.
SO-models are defined in the obvious way. Note that, by definition of SQ-truth, ZEN
is an &-model of P iff unfp(Z u ZdQ)E I.
Proposition 6.3 allows to define the model-theoretic semantics As,(P) for a pro-
gram P in terms of the &-models as follows.
Definition 6.4 (Bossi and Menegus [7]). Let P be an Q-open program and S be the set
of all the S,-models of P. Then M,,(P)= nMESM.
By definition and by Proposition 6.3, Msn(P) is the least SQ-model in the lattice
(9, G) (recall that 9 is the set of all the Q-denotations). The following proposition
shows that M,“(P) is also the least S,-model in the lattice (9, c).
Proposition 6.6. Let P be a program and let S be the set of all the Sn-models of P. Then
MsO(P)=glb(S) (according to the c ordering).
The following theorem shows the equivalence of the least &-model M,,(P) and the
fixpoint semantics (Definition 4.6).
Theorem 6.7 (Bossi and Menegus [7]). Let P be an Q-open program. Then
6(P) = M,,(P).
38 A. Bossi et al.
Proof. The proof is straightforward from Theorem 6.7 and Proposition 6.2. 0
It is worth noting that, since cO,( P) = FQ( P) = Ms,( P), Theorem 2.13 shows that the
least So-model Mso( P) is compositional w.r.t. Q-union of programs when considering
computed answer substitutions as observables. This result was already proved in [7]
for the MsO( P) model. Finally note that, as shown by the following example, TF is not
monotonic (and therefore it is not continuous) on the complete lattice (9, E).
However, Proposition 6.10 ensures us that gD(P) is still the least fixpoint of TF on
(9, c).
Example 6.9. Consider the program P= {p(x) :-q(x), r(b)}. Let !Z=@, Ii = (q(a), q(x)}
and 12=(r(b),q(x)}. Then Z,EZ, while T~(Il)={p(x),p(a),r(b)}$T~(12)={p(x),r(b)}.
Proposition 6.10. TFro is the least jixpoint of T; on the complete lattice (9, c).
The result of our semantic construction has several similarities with the proof-
theoretic semantics defined in [30,31]. Our construction, however, is closer to the
usual characterization of the semantics of logic programs. Namely, we define a top-
down operational and a bottom-up fixpoint semantics and, last but not least, a model-
theoretic semantics which allows us to obtain a declarative characterization of
syntactically defined models. The semantics in [30] does not characterize computed
answer substitutions, while the denotation defined by the fully abstract semantics in
[31] is not a set of clauses (i.e. a program). The framework of [30,31] can be useful for
defining a program-equivalence notion, even if our more declarative (model-theoretic)
characterization is even more adequate. Moreover, the presence of an operational or
a fixpoint semantics makes our construction useful as a formal basis for program
analysis.
Another related paper is [S], where Q-open logic programs are called open theories.
Open theories are provided with a model-theoretic semantics which is based on ideas
very similar to those underlying our Definition 5.1. However, [S] does not consider
semantic definitions in the style of our U,(P) which gives a unique denotation to any
open program and does not consider computed answers as observables.
A compositional semantics for logic programs 39
Our Q-semantics O,(P) has already been used for several applications. Let us
briefly discuss some of them.
l Suitable abstractions of the open semantics can be used to model nonstandard
observables useful for program analysis. For example, in [28] a fully abstract
semantics for partial answers is obtained essentially by considering the heads of the
clauses in U),(P). Moreover, [28] defines also an extension of the Q-semantics
which takes into account the selection rule and which allows to correctly model
those observables which depend on it. on(P) is also useful for studying new
equivalences of logic programs [26,25] based on computed answer substitutions
which are not considered in [46].
l The open semantics is useful to model incomplete knowledge bases, where new
chunks of knowledge can incrementally be assimilated, and logic languages pro-
vided with a module-like structure. Modified versions of Co,(P) allow to obtain
semantics compositional w.r.t. various composition operators. A semantic com-
positional w.r.t. a generalized inheritance operator is obtained in [4]. Static and
dynamic extension/overriding mechanisms can be expressed using the generalized
operator. Since the semantic domains are (equivalence classes of) clauses, we have
a uniform treatment of static and dynamic inheritance which in other composi-
tional semantics [9] require different semantic objects to coexist. Moreover, the
semantics in [4] is the first compositional semantics of units and inheritance which
correctly models computed answer substitutions.
l The open semantics can be considered as the semantic base for modular program
analysis. It may happen that in a system under development, not all the pieces of
the program are available for analysis at some point, but we might want to do some
analysis in any case. Clearly, this is possible only if the base semantics is modular,
i.e. compositional. Modularity helps considerably in reducing the complexity of
analysis and in proving correctness of programs, since it allows an incremental and
structured specification and verification of the software. A first use of our semantics
for modular analysis is in [12].
Let us finally remark some other interesting properties of the Q-semantics on(P)
which could be further investigated.
l By means of a syntactic device, we obtain a unique representation for a possibly
infinite set of Herbrand models when a unique representative Herbrand model does
not exist. A similar device was used in [ 1535,271 to characterize logic programs
with negation. A combination of these results with our semantics could be con-
sidered to develop a compositional semantics for programs with negation.
l Our framework is strongly related to abduction [17]. If R is the set of abducible
predicates, the abductive consequences of any goal G can be found by executing
G in Lo,(P).
l The delayed evaluation of open predicates which is typical of O,(P) can easily be
generalized to other logic languages, to achieve compositionality w.r.t. the union of
programs. In particular, this matches quite naturally the semantics of CLP and
concurrent constraint programs given in [22].
40 A. Bossi et al.
l The modification of the Bn( P) semantics developed in [4] could be used to develop
a modular analysis for programs which are structured by using inheritance mech-
anisms, according to the usual object-oriented style.
Appendix
In this appendix we give the proofs of some lemmata and theorems. Let us first
introduce some definitions about substitutions and equations. The interested reader
can see [16,40,50]. An equation is an atom s = t, where s, t are terms and = is
a predicate symbol which is interpreted as the syntactic equality over the Herbrand
universe. Given a set of equations E = {sl = tl, . . . , s, = t,}, the (most general) unifier of
(E) is a (most general) unifier of ((sl, . . . ,sn)(tl, . . . . t,)). It is well known that the
idempotent mgu of a set of equations (terms) is unique up to renaming (see e.g. [16]).
Moreover, if a set of equations E is unifiable, then there exists an idempotent mgu of E.
A solution of E is a grounding unifier of E. Two sets of equations El, E2 are equivalent
(E, =.e E,) if they have the same solutions. The lattice structure on idempotent
substitutions [16] is isomorphic to the lattice structure on equations introduced in
[40] ([SO] extends this result to include also the trivial Herbrand universe). Therefore,
we can use indifferently equations or idempotent mgu’s. In the following we will
always implicitly consider idempotent mgu’s and a nontrivial Herbrand universe.
Moreover, idempotent mgu’s are considered equal up to renaming, i.e. if 9, p = Q2,
where p is a renaming, we write (by a slight abuse of notation) 9, = QZ. 7=S denotes
a set of equations.
Definition A.l. Let 9= (Xl/tl, ..,, X,/t,} be a substitution. Then a($)= {X1 =tl, ....
x,= tn}.
Theorem A.3 (Lassez [40]). If the Herbrand universe is non trivial, then 8 is an
idempotent mgu of E if a($) z:e E.
Corollary A.4. Zf the Herbrand universe is nontrivial and El z:e EZ, then for any set of
equations E, mgu(E u El)= mgu(E u E,).
Corollary A.5. Let El, E2 be sets of equations with mgu(El)= 8 and mgu(E, 9)= y.
Then mgu(El u E2)= 9~.
A compositional semantics for logic programs 41
In order to prove the following results we will consider a CLP-like [33] version of
SLD derivation, denoted by -+;,R, which uses equations instead of mgu’s. The
previous stated isomorphism allows to prove the equivalence of the two versions of
SLD (see below). More precisely, given a goal p(S), G, E, where G is a set of atoms, E is
a set of equations and p(F) is the selected atom, and given a clause
c=p(Z):-B,,..., B,~P,wecandefinep(&G,E-+;,~s”=i,E,B, ,..., B,,Ginonestep
(using clause c) iff the set E u (i= t”>is unifiable. Provided that no equational atom is
considered (and hence chosen) by the selection rule and by replacing the atom p(Z) by
p(g), x”=t (where 2 are new distinct variables), we can then replace a derivation
d=(p(f) 2 P,RG’) by the equivalent derivation p(x), z=f-+;,R G, E, which uses the
same clauses as d. The equivalence is formally proved by the following result.
Lemma A.6 (Wolfram et al. [56]). Let P be a program, let -+* be defined as before and
let G=A 1, . . . . Ak be a goal, where Ai=pi(~i), i= 1, . . . . k. Let H=pl(X”,), . . . . pk(_Ck),
E={X”,=!~U...UX~,=~~) and let B={X/tIx=tE~i=ti, l<i<k}, with x”l,...,r?k
3
new distinct variables. Then G -+P,RG’ if H, E~Y~*,~H’, E’, with fl$=mgu(E’) and
G’=H’PS. Moreover, mgu(E’)(,,rC,,= QIVarCGj.
Note that the previous lemma holds for any selection rule. Then we have the
following lemma.
Lemma A.7 (Lemma 2.12). Let P be a program and let G be a goal. Then G 2r,R N ifs
8 8’
G -+P,R,N, where SIVarCG,=QiVarCG,
and the derivation G +P,R, N is obtained from
G A,,,. N by changing the order in which the atoms are selected.
Proof. Straightforward from Lemma A.6, by noting that in +;,R derivations the
computation is performed by accumulating equations and, since equations are con-
sidered as sets, the ordering in which equations are added is not relevant. 0
Proposition A.8 (Proposition 2.6). Let R be a given fair selection rule, let P * = P v Ida,
2 be new distinct variables and Pred(B,; . . . . B,)&Q. Then there exists
aruleR’suchthatp(X”)$,,,.B, ,..., B,ifSp(X”)-+,,nD, ,..., D,%:P*,RB1 ,..., B,and
p(Xl)ya=p(X)IP.
42 A. Bossi et al.
P(s+*p,RDl>...>
kPb+,R~l,..., B,
where B1, . . . ,B,=(B;, . . ..Bh)o and p(r?)cr=p(r?)pS=p(g)S, and this concludes the
proof. 0
Lemma A.9 (Lemma 2.9). Let P be a program. Then p(Z) %p,R G1 ifs the following hold
~(2) %, R G2
iff
~(2) -:, R E> G
P(S) %.. GI
A compositional semantics for logic programs 43
iff
p(X),X=E ,&G,E,~==
where /?,9i = y=mgu(Eu {x”= t”}) and Gy= G1 . By definition of the unification algo-
rithm and by definition of mgu, E u {r? = f} is unifiable iff t”= x9, is unifiable iff there
exists o = mgu (p(f), p(X) Q2). Therefore, by the previous equivalence of derivations -P *
and -+,
iff
~(0 %,, GI
In the proof of the following theorem we use a parallel derivation and its equiva-
lence to the SLD derivation with a fair rule. Note that the equivalence of the fair SLD
derivations and the parallel derivation was already proved in [56]. In the proof we
show a simple argument for such an equivalence for the sake of completeness.
Theorem A.10 (Theorem 4.14). Let P be an Q-open program. Then O,(P) =aQ(P).
for a fair selection rule R. By Proposition 2.6, we can assume that R is a fair rule such
that if it selects an atom Aj in the resolvent G = A 1, . . . , A,,,, all the atoms derived by
Aj are evaluated (i.e. selected) after the atoms Ai for i = 1, . . , m, i # j. Formally, we can
define such a rule R, as follows.
Let 4 be a given bijection on the set of natural numbers. Then R, selects in every
resolvent the atom A with the minimum value $(A), where the function $(A) is defined
inductively on the length h of derivation as follows.
For h=O: If Go=A,,...,A,is the goal then t,!/(Aj)=+(j)for l<j<n.
For h>O: Assume a given value I for the atoms in G,,= Al, . . . . A,,, and let
G,+, =(A,, . . . . Ai-i,Bl, ...,B,,Ai+l, ... , A,) 9 be the resolvent obtained by replacing
Ai=&(Gh+l) by Bi, ...y B,. Then for l<k<r, ~(Bk)=~(k)+max,_<j,,(~(Aj)).
It is clear from the definition that R, is a fair rule. To simplify the notation
we assume in the following that the function C$selects atoms from left to right. Note
that
P(X)~,,R~A~,...,A,~~*,R,
B1, . . ..B. in m+l steps iff
in k<m+ 1 steps and Pred(B1, . . . . B,, Ak, . . . , A,)cQ then we can obtain an equiva-
lent derivation whose length is m + 1 steps by simply rewriting the atoms Ak, . . . , A, by
clauses in I&. Therefore, by a straightforward inductive argument, we can prove that,
for Pred(B1, . . . . B,.,Ak, . . . . A,)EQ,
P(~?)~~,R*A~,...,A,~~‘,R,B~,...,B,
References
[l] K.R. Apt, Introduction to logic programming, in: J. van Leeuwen, ed., Handbook of Theoretical
Computer Science, Vol. B: Formal Models and Semantics (Elsevier, Amsterdam, 1990) 493-574.
[2] R. Barbuti, M. Codish, R. Giacobazzi and G. Levi, Modelling prolog control, in: Proc. 19th Ann.
ACM Symp. on Principles of Programming Languages (1992) 955104.
[3] R. Barbuti, R. Giacobazzi and G. Levi, A general framework for semantics-based bottom-up
abstract interpretation of logic programs, ACM Trans. Programming Languages Systems 15 (1993)
1333181.
[4] A. Bossi, M. Bugliesi, M. Gabbrielli, G. Levi and M.C. Meo, Differential logic programming, in: Proc.
20th Ann. ACM Symp. on Principles of Programming Languages (1993) 359-370.
[S] A. Bossi and N. Cocco, Basic transformation operations which preserve computed answer substitu-
tions of logic programs, J. Logic Programming 16 (1993) 47-87.
[6] A. Bossi, M. Gabbrielli, G. Levi and M.C. Meo, Contributions to the semantics of open logic
programs, in: Proc. Internat. Conf on Fifth Generation Computer Systems 1992 (1992) 570-580.
[7] A. Bossi and M. Menegus, Una semantica composizionale per programmi logici aperti, in: P. Asirelli,
ed., Proc. 6fh Italian Conf on Logic Programming (1991) 95-109.
[S] A. Brogi, E. Lamma and P. Mello, Composing open logic programs, J. Logic and Computation, to
appear.
[9] M. Bugliesi, A declarative view of inheritance in logic programming, in: K. Apt, ed., Proc. Joint
Internat. Conf and Symp. on Logic Programming (MIT Press, Cambridge, MA, 1992) 113-130.
[lo] K.L. Clark, Predicate logic as a computational formalism, Research Report DOC 79/59, Imperial
College, Dept. of Computing, London, 1979.
[1 l] M. Codish, D. Dams and E. Yardeni, Bottom-up abstract interpretation of logic programs, Technical
Report, Dept. of Computer Science, The Weizmann Institute, Rehovot, 1990; Theoret. Comput. Sci.
124, to appear.
[12] M. Codish, SK. Debray and R. Giacobazzi, Compositional analysis of modular logic programs, in:
Proc. 20th Ann. ACM Symp. on Principles of Programming Languages (1993) 451-464.
1133 F.S. de Boer and C. Palamidessi, Concurrent logic languages: asynchronism and language compari-
son, in: S. Debray and M. Hermenegildo, eds., Proc. North American Conf on Logic Programming ‘90,
(MIT Press, Cambridge, MA, 1990) 99-114.
1141 F. Denis and J.-P. Delahaye, Unfolding, procedural and fixpoint semantics of logic programs, in:
C. Choffrut and M. Jantzen, eds., STACS 91, Lecture Notes in Computer Science, Vol. 480 (Springer,
Berlin, 1991) 51 l-522.
[15] P.M. Dung and K. Kanchanasut, A fixpoint approach to declarative semantics of logic programs, in:
E. Lusk and R. Overbeck, eds., Proc. North American Conf on Logic Programming ‘89 (MIT Press,
Cambridge, MA, 1989) 604625.
[16] E. Eder, Properties of substitutions and unifications, J. Symbolic Comput. 1 (1985) 31-46.
1171 K. Eshghi and R.A. Kowalski, Abduction compared with negation by failure, in: G. Levi and M.
Martelli, eds., Proc. 6th Internat. Conf on Logic Programming (MIT Press, Cambridge, MA, 1989)
234-254.
[lS] M. Falaschi, G. Levi, M. Martelli and C. Palamidessi, A new declarative semantics for logic languages,
in: R.A. Kowalski and K.A. Bowen, eds., Proc. 5th Internat. Conf on Logic Programming (MIT Press,
Cambridge, MA, 1988) 993-1005.
1191 M. Falaschi, G. Levi, M. Martelli and C. Palamidessi, Declarative modeling of the operational
behavior of logic languages, Theoret. Comput. Sci. 69 (1989) 2899318.
[20] M. Falaschi, G. Levi, M. Martelli and C. Palamidessi, A model-theoretic reconstruction of the
operational semantics of logic programs, Technical Report TR 32/89, Dipartimento di Informatica,
Universita di Pisa, 1989; Inform. and Comput., to appear.
1213 G. Ferrand, Error diagnosis in logic programming, an adaptation of E.Y. Shapiro’s method, J. Logic
Programming 4 (1987) 1777198.
[22] M. Gabbrielli and G. Levi, Modeling answer constraints in constraint logic programs, in:
K. Furukawa, ed., Proc. Eighth Internat. Conf on Logic Programming (MIT Press, Cambridge, MA,
1991) 238-252.
46 A. Bossi et al.
~231 M. Gabbrielli and G. Levi, On the semantics of logic programs, in: J. Leach Albert, B. Monien and M.
Rodriguez-Artalejo, eds., Automata, Languages and Programming, 18th Internat. Colloquium, Lecture
Notes in Computer Science, Vol. 510 (Springer, Berlin, 1991) 1-19.
~241 M. Gabbrielli and G. Levi, Unfolding and Fixpoint Semantics of Concurrent Constraint Programs,
Theoret. Comput. Sci. 105 (1992) 85-128.
WI M. Gabbrielli, G. Levi and M.C. Meo, Observable behaviors and equivalences of logic programs,
Research Report HAS-RR-92-9E, International Institute for Advanced Study of Social Information
Science, FUJITSU LAB. Ltd., 1992.
WI M. Gabbrielli, G. Levi and M.C. Meo, Observational equivalences for logic programs, in: K. Apt, ed.,
Proc. Joint Internat. Conf: Symp. on Logic Programming (MIT Press, Cambridge, MA, 1992) 131-145.
1271 M. Gabbrielli, G. Levi and D. Turi, A two steps semantics for logic programs with negation, in: Proc.
Internat. Con& on Logic Programming and Automated Reasoning, Lecture Notes in Artificial Intelli-
gence, Vol. 624 (Springer, Berlin, 1992) 297-308.
WI M. Gabbrielli and M.C. Meo, Fixpoint semantics for partial computed answer substitutions and call
patterns, in: H. Kirchner and G. Levi, eds., Proc. 3rd Internat. Conf: on Algebraic and Logic
Programming, Lecture Notes in Computer Science, Vol. 632 (Springer, Berlin, 1992) 84-99.
~291 H. Gaifman, M.J. Maher and E.Y. Shapiro, Reactive behavior semantics for concurrent constraint
logic programs, in: E. Lusk and R. Overbeck, eds., Proc. North American Conf on Logic Programming
‘89 (MIT Press, Cambridge, MA, 1989) 553-572.
c301 H. Gaifman and E. Shapiro, Fully abstract compositional semantics for logic programs, in: Proc. 16th
Ann. ACM Symp. on Principles of Programming Languages (1989) 1344142.
c311 H. Gaifman and E. Shapiro, Proof theory and semantics of logic programs, in: Proc. 4th IEEE
Symp. on Logic In Computer Science (IEEE Computer Society Press, Silver Spring, MD, 1989)
50-62.
~321 R. Giacobazzi, SK. Debray and G. Levi, A generalized semantics for constraint logic programs, in:
Proc. Internat. Con& on Fifth Generation Computer Systems 1992 (1992) 581-591.
D31 J. Jaffar and J.-L. Lassez, Constraint logic programming, in Proc. 14th Ann. ACM Symp. on Principles
ofProgramming Languages (1987) 111-119.
c341 J. Jaffar and J.-L. Lassez, Constraint logic programming, Technical Report, Department of Computer
Science, Monash University, June 1986.
c351 K. Kanchanasut and P. Stuckey, Eliminating negation from normal logic programs, in: H. Kirchner
and W. Wechler, eds., Proc. 2nd Internat. Conf: on Algebraic and Logic Programming, Lecture Notes in
Computer Science, Vol. 463 (Springer, Berlin, 1990) 217-231.
[36] T. Kawamura and T. Kanamori, Preservation of stronger equivalence in unfold/fold logic program-
ming transformation, in: Proc. Internat. Conf on Fifth Generation Computer Systems (Institute for
New Generation Computer Technology, Tokyo, 1988) 413-422.
[37] R. Kemp and G. Ringwood, An algebraic framework for the abstract interpretation oflogic programs,
in: S. Debray and M. Hermenegildo, eds., Proc. North American Conf: on Logic Programming ‘90 (MIT
Press, Cambridge, MA, 1990) 506-520.
1381 G. Kreisel and J.L. Krivine, Elements of Mathematical Logic (Model Theory) (North-Holland,
Amsterdam, 1967).
[39] J.-L. Lassez and M.J. Maher, Closures and fairness in the semantics of programming logic, Theoret.
Comput. Sci. 29 (1984) 167-184.
[40] J.-L. Lassez, M.J. Maher and K. Marriott, Unification revisited, in: 3. Minker, ed., Foundations of
Deductive Databases and Logic Programming (Morgan Kaufmann, Los Altos, CA, 1988) 587-625.
[41] G. Levi, Models, Unfolding rules and fixpoint semantics, in: R.A. Kowalski and K.A. Bowen, eds.,
Proc. 5th Internat. Conf on Logic Programming (MIT Press, Cambridge, MA, 1988) 1649-1665.
1421 G. Levi and P. Mancarella, The unfolding semantics of logic programs, Technical Report TR-13/88,
Dipartimento di Informatica, Universita di Pisa, 1988.
[43] G. Levi and C. Palamidessi, An approach to the declarative semantics of synchronization in logic
languages, in: J.-L. Lassez, ed., Proc. 4th Internat. Co@ on Logic Programming (MIT Press,
Cambridge, MA, 1987) 877-893.
[44] J.W. Lloyd, Foundations of Logic Programming (Springer, Berlin, 2nd ed., 1987).
[45] J.W. Lloyd and J.C. Shepherdson, Partial evaluation in logic programming. J. Logic Programming 11
(1991) 2177242.
A compositional semantics for logic programs 47
[46] M.J. Maher, Equivalences of logic programs, in: J. Minker, ed., Foundations of Deductive Databases
and Logic Programming (Morgan Kaufmann, Los Altos, CA, 1988) 627-658.
[47] P. Mancarella and D. Pedreschi, An algebra of logic programs, in: R.A. Kowalski and K.A. Bowen,
eds., Proc. 5th Internat. Conf on Logic Programming (MIT Press, Cambridge, MA, 1988) 100661023.
[48] K. Marriott and H. Ssndergaard, Semantics-based dataflow analysis of logic programs, in: G. Ritter,
ed., Information Processing 89 (North-Holland, Amsterdam, 1989) 601-606.
[49] R.A. O’Keefe, Towards an algebra for constructing logic programs, in: Proc. IEEE Symp. on Logic
Programming (1985) 1522160.
[SO] C. Palamidessi, Algebraic properties of idempotent substitutions, in: M.S. Paterson, ed., Proc. 17th
Internat. Colloquium on Automata, Languages and Programming, Lecture Notes in Computer Science,
Vol. 443 (Springer, Berlin, 1990) 3866399.
[Sl] G. Plotkin, A note on inductive generalization, Machine Intelligence, 5 (1970) 153-165.
[52] H. Rasiowa and R. Sikorski, Tne Mathematics of Metamathematics (North-Holland, Amsterdam,
1963).
1531 V.A. Saraswat and M. Rinard, Concurrent constraint programming, in: Proc. 17th ACM Symposium
on Principles of Programming Languages (1990) 232-245.
[54] D. Turi, Extending S-models to logic programs with negation, in: K. Furukawa, ed., Proc. 8th
Internat. Conf on Logic Programming (MIT Press, Cambridge, MA, 1991) 397-411.
[55] M.H. van Emden and R.A. Kowalski, The semantics of predicate logic as a programming language,
J. ACM 23 (1976) 7333742.
[56] D.A. Wolfram, M.J. Maher and J-L. Lassez, A unified treatment of resolution strategies for logic
programs, in: Sten-Ake Tarnlund, ed., Proc. 2nd Internat. Con{ on Logic Programming (1984)
263-276.
[57] S. Yamasaki, M. Yoshida and S. Doshita, A fixpoint semantics of Horn sentences based on
substitution sets, Theoret. Comput. Sci. 51 (1987) 309-324.