List of Figures - Semantic Scholar

9 downloads 1697 Views 356KB Size Report
Natural transformations associated to a generalized free extension : : : : : : : : : : 10. 5 .... and, as illustration, their application to the class of de nite logic programs; ...
List of Figures 1 2 3 4 5 6

Pushout diagram HCL-pushout diagram Free extension diagram Natural transformations associated to a generalized free extension Standard union of programs Union compositionality

: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :

: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :

: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :

7 8 10 10 12 12

An algebraic framework for the de nition of compositional semantics of Normal Logic Programs Paqui Lucio

Dpto de L.S.I., Universidad del Pas Vasco, San Sebastian, SPAIN. E-mail: [email protected] Fernando Orejas, Elvira Pino

Dpto de L.S.I., Universidad Politecnica de Catalunya, Barcelona, SPAIN. E-mail: forejas,[email protected]



Abstract

The aim of our work is the de nition of compositional semantics for modular units over the class of normal logic programs. In this sense, we propose a declarative semantics for normal logic programs in terms of model classes that is monotonic in the sense that Mod(P [ P 0 )  Mod(P ), for any programs P and P', and we show that in the model class associated to every program there is a least model that can be seen as the semantics of the program, which may be built upwards as the least x point of a continuous immediate consequence operator. In addition, it is proved that this least model is \typical" for the class of models of the Clark-Kunen's completion of the program. This means that our semantics is equivalent to Clark-Kunen's completion. On the other hand, following the approach de ned in a previous paper, it is shown that our semantics constitutes a \speci cation frame" equipped with the adequate categorical constructions needed to de ne compositional and fully abstract (categorical) semantics for a number of program units. In particular, we provide a categorical semantics of arbitrary normal logic program fragments which is compositional and fully abstract with respect to the (standard) union.

Keywords: normal logic programs, model-theoretic semantics, compositionality, institu-

tions, monotonic semantics, constructive negation, modular logic programs.

1 Introduction Despite the amount of papers on the semantics of negation (see e.g. [3]), there are several semantics issues that are insuciently explored. One such basics issue is modularity. The reason is that a proper semantics for any kind of modular unit must be shown to be compositional with respect to the kind of module operations considered, but the non-monotonic nature of negation in Logic Programming does not seem to t too well with compositionality. In particular, for di erent reasons, none of the various operational semantics [14, 12, 37], neither the di erent model-theoretic approaches (see e.g. [3]), nor the completion semantics  Address correspondence to Fernando Orejas, UPC-Department LSI, Campus Nord, C/ Jordi Girona Salgado,

1-3, 08034-Barcelona, SPAIN. Tel: +34 3 4017018, Fax: +34 3 4017014, e-mail: [email protected]

1

[13, 27], seems to be adequate to be the basis for de ning a compositional semantics for normal logic programs units. To our knowledge, only [18, 20, 29, 40, 9] provide some compositional semantic constructs for normal logic programs. In section 6 we compare the results presented in this paper and these approaches. It must be noted that compositionality is a very important property for de ning the semantics of a modular unit. In particular, if the semantics of a unit is not compositional with respect to the given module operations this means that, for reasoning about a program consisting of several such units, we would need to previously \ atten" the program (or its semantics) \forgetting" the modular structure of the program. Also, when dealing with modular units, another important property, is full abstraction with respect to composition, which holds if the semantics of two modules coincide if and only if the two modules \behave" equally in every context. In particular, if a semantics is fully abstract this guarantees that our notion of program equivalence is the right one for reasoning about implementation, i.e. a program unit could be substituted by another unit implementing the same abstraction if and only if they have the same semantics. In [31], a methodology is presented for the semantic de nition of modular logic programs ensuring compositionality and full abstraction, and it is applied to study several kinds of program units for the class of de nite logic programs. The approach is based on the fact that most modular constructions can be de ned and studied independently of the underlying formalism used \inside" the modules, as far as this formalism is an \institution" [25] or a \speci cation frame" [17] (or some similar notion) equipped with some categorical constructions. In particular, the proposed methodology for de ning the semantics of a certain kind of modular unit consists, essentially, of three steps. Firstly, one has to study the given unit, and the associated composition operations, at the general level. This means de ning the meaning of the construction in terms of the categorical constructions that the speci cation frames will be assumed to provide. Secondly, one has to de ne the given class of logic programs as an institution or speci cation frame with the needed constructions. At this point one may obtain, already, a compositional and fully-abstract semantic de nition for the given unit. However, such de nition could be considered too abstract, since it would be stated in terms of the categorical constructions of the speci cation frame. Finally, a third step can be performed by showing that this categorical semantics is equivalent to some speci c concrete semantics. Applying this methodology not only may save some work (since some results must be proved just once, independently of the classes of logic programs considered) but, what is more important, it provides clear guidelines about how the concrete semantics for the various constructions must be de ned. In particular, these guidelines were extremely valuable for the work reported in this paper. In principle, the main problem found in order to apply this methodology to study modularity and compositionality issues for the class of normal logic programs is (the lack of) monotonicity. Institutions and speci cation frames can be seen as characterizations of monotonic formalisms. This seems to be in contradiction with the non-monotonic nature of negation as failure and constructive negation. However, if we look at the simpler case of the class of de nite logic programs with negative queries, then we could see one of the basic ideas of our proposal: the class of de nite logic programs (Horn Clause Logic) is, obviously, a monotonic logic; the non-monotonicity of the negative queries is related to the selection of an arbitrary model (the least one) to de ne what is assumed to be \false". Similarly, in this paper we propose a declarative semantics for normal logic programs in terms of model classes that is monotonic in the sense that Mod(P [ P 0 )  Mod(P ) for any programs P and P 0 . This is enough for de ning an speci cation frame of normal logic programs equipped with the categorical constructions needed to apply the results in [31] to the class of normal logic programs, obtaining compositional and fully abstract (categorical) semantics for a number of

2

program units [7, 23]. In particular, we apply these results to provide a (categorical) semantics of arbitrary program fragments which is compositional and fully abstract with respect to (standard) union. In addition, we show that in the model class associated to every program there is a least model that can be seen as the (non-compositional) semantics of the program. This least model is \typical" for the class of models of the Clark-Kunen's completion of the program. In that sense, our semantics is equivalent to Clark-Kunen's completion. Moreover, we provide a continuous immediate consequence operator and show that this least model can be built \upwards" as the least xpoint of that operator. We have not considered any possible relation of our semantics and well-founded semantics. The main reason is that, being well-founded models not semi-computable in general, we do not think that they could be considered a reasonable semantics for a programming language. Nevertheless, we believe that an adequate modi cation of our semantics would provide ranked models that could be proved equivalent to well-founded ones. We are convinced that, not only with respect to compositionality issues, our semantics is just the \right" kind of model-theoretic semantics for normal logic programs. There are several reasons for this. On the one hand, if model-theoretic semantics are usually the most adequate tool for meta-logical reasoning, the structure of our classes of models, together with the closeness to ranked resolution, makes our semantics highly adequate for the proof of such kind of properties, especially for the case of properties of operational approaches (e.g. completeness). On the other hand, one may think that our semantics is more complicated than needed, in the sense of dealing with complex ranked structures instead of just three-valued ones. We disagree with that: ranked structures are just a special case of Beth structures, used to provide semantics to intuitionistic logic (e.g. see [38]). In this sense, our semantics establishes an explicit link (already mentioned by other authors) between constructive negation and intuitionistic logic that may be worth to study. In particular, it could serve as a basis for extending with negation those approaches to modularity based on the use of an intuitionistic implication (e.g. see [30]). In this line, the only work we know is [5] where a semantics of programs including an intuitionistic implication and negation as failure is de ned in terms of Kripke models under some severe restrictions. In particular, programs must be strati ed and signatures may only contain predicate symbols, i.e. function symbols are not allowed. The paper is organized as follows: in the next section we introduce some basic notions and notation; in section 3, we review the basic de nitions and results about speci cation frames and, as illustration, their application to the class of de nite logic programs; in section 4, we present the declarative model-theoretic semantics for normal logic programs, including a x point construction of least models, and show its connection with Clark-Kunen's completion; in section 5, we discuss the results presented with respect to compositionality and full abstraction issues; nally, in section 6, we give some conclusions and relationships with other works. The reader is assumed to have certain familiarity with basic constructs from category theory. For details one may consult any basic text in on the subject (e.g. [4]).

2 Preliminaries

A countable signature  consists of a pair of sets (FS ; PS ) of function and predicate symbols, respectively, with some arity associated. -terms and -atoms are built using functions and predicates from  and, also, variables from a pre xed countable set X of variable symbols. Terms will be denoted by t; s; : : :, and var(t) will denote the variables appearing in t.

3

Normal programs over a signature  (or -programs) are sets of -clauses a : ?l1 ; : : :lk where a is a -atom, k  0, and each li is a -literal, that is b or :b where b is an atom. For simplifying some technical constructions, we consider that any -program is written as its equivalent constraint normal program with at head. That is, any clause p(t1 ; : : :; tn) : ?l1; : : :lk is written as the constraint clause p(x1 ; : : :; xn) : ?l1; : : :lk 2 x1 = t1; : : :; xn = tn ; Moreover, we suppose identical tuple x1; : : :; xn of fresh variables for all clauses (in a program) with predicate p in its head. We denote by HdP (p(x)) the set fp(x) : ?lk 2 x = tk j k = 1; : : :; mg of all clauses with head p appearing in P . Constraints appearing in programs are a special kind of simple constraints. In general, we consider that -constraints are arbitrary rst order -formulas over equality atoms. That is, formulas composing equality atoms with the connectives: :; ^; _; !, and the quanti ers: 8; 9. For a formula ', in particular for a constraint, free(') is the set of all free variables in ', and '(x) speci es that free(')  x. We will identify the list of constraints in any program clause with the corresponding conjunction (i.e., a formula). We denote constraints by c; d; : : : (possibly with sub- or superscripts). Formulas '8; '9 stand for the universal and existential closures of ', respectively. The atomic formulas naming the two classical truth values are T and F. We will handle constraints in a logical way, using logical consequence of the free equality theory. The free equality theory FET for a signature  is the following set of formulas: 8x(x = x) 8x8y(x = y $ f (x) = f (y)) for each f 2 FS 8x8y(x = y ! (p(x) $ p(y))) for each p 2 PS [ f=g 8x8y(f (x) 6= g(y)) for each pair f; g 2 FS such that f 6 g 8x(x 6= t) for each -term t and variable x such that x 2 var(t) and x 6 t. A constraint c is satis able (resp. unsatis able) if and only if FET j= c9 (resp. FET j= :(c9)). A ground substitution x = t (where ti are closed terms) is called a solution of a constraint c if and only if FET j= (x = t ! c)8. A constraint d is less general than c i FET j= (d ! c)8. From a logical point of view, programs are sets of formulas. There are, mainly, two logical ways of interpreting a normal program P . The rst one, denoted by P 8, interprets every clause as the universal closure of the formula which results from substituting \commas" and 2 (in the clause body) by logical conjunction, and the symbol \:-" by logical implication (right-to-left). The second one is Clark's program completion, denoted by Comp(P ). The completion of a -program P consists of the free equality theory FET together with, for each p 2 PS , a predicate completion formula: m _ 8x(p(x) $ 9yk (x = tk ^ lk )) k=1

4

where yk are the variables appearing in tk and lk which do not belong to x, and HdP (p(x)) = fp(x) : ?lk 2 x = tk j k = 1; : : :; mg. In both interpretations, conjunction (resp. disjunction) of an empty set is simpli ed to the atomic formula T (resp. F). However, clauses like p : ?:p are inconsistent when program completion is considered. To avoid this problem [27] proposed to interpret Clark's program completion in three-valued logic. In particular, in this logic the three truth values are true (t), false (f ) or unde ned (u); the connectives :; ^; _ are interpreted in Kleene's partial logic, $ is interpreted as the identity of truth values, so it is two-valued; nally, existential quanti cation can be seen as in nite disjunction, and universal quanti cation is treated as in nite conjunction. Equality is two-valued. Currently, this interpretation of Clark's completion (from now on Clark-Kunen completion) is considered the standard declarative meaning of normal logic programs. Anyhow, it must be noted that, in the context of completion, any three valued extension of classical implication can be considered. The reason is that implication does not appear in predicate completion formulas and FET contains only implication between two-valued formulas, i.e. the choice of a three-valued semantics for implication becomes an important matter when the program itself is treated as a logical theory. In this sense, we will use Przymusinski's implication

! t f u

t t t t

f f t f

u f t t

whose intuitive meaning is \' ! is true if and only if whenever ' is true is also true and whenever is false ' is also false". Then, ' $ is equivalent to (' ! ) ^ ( ! ') and, in particular, we have that Comp(P ) j= P 8. Note that the classical equivalence ' !  :' _ does not hold. However, in the case of ' being two-valued (e. g. an equality formula) it holds that ' ! is true i :' _ is true, so that ' ! is false i :' _ is false or unde ned. A three-valued -structure A consist of a universe of values A and an interpretation of every function symbol by a (total) function from An to A (of adequate arity n) and of every predicate symbol by a partial relation, which can be seen as a (total) function from An to the set of the three boolean values ft; f ; ug. In that way, every closed -term can be interpreted as a value belonging to the universe of a -structure (they could not be unde ned), every equality ground atom t1 = t2 is associated to one of the classical truth values, but every ground atom p(t1 ; : : :; tn ) is associated to one of the three boolean values: ft; f ; ug. A Herbrand three-valued structure H is a three-valued -structure whose universe H is the Herbrand base for , function symbols are trivially interpreted and the predicate interpretation is given by a pair of disjoint sets: H + of true ground atoms and H ? of false ground atoms, so that any other ground atom is unde ned. The value of any rst order sentence ' in a three-valued structure A will be denoted by A('). A three-valued structure A is a model of a set of formulas , denoted by A j= , i A(') = t for any formula ' 2 . Three-valued logical consequence  j= ' means that for all three-valued structure A if A j=  then A j= '.

5

3 The algebraic framework In this section we review some basic notions on algebraic speci cation needed in this paper (for further detail see e.g. [16, 41] and also [24, 25] and [15] for more detail on institutions and speci cation frames). In subsection 3.1, we introduce the notion of speci cation frame. A speci cation frame can be seen as a formal description of a logic formalism with certain compositionality properties. From our point of view, this notion provides an adequate theoretical framework for studying structuring issues in logic programming. In the following subsection, we introduce some algebraic properties of speci cation frames which are specially interesting for our work. In particular, these properties allow us to study di erent structuring constructs at the abstract level, that means, independently of the concrete class of logic programs used to build modular or structured logic programs. In order to show the gains of using this framework, we present, in subsection 3.3, a compositional and fully abstract semantics with respect to the union of logic programs [31]. These results are obtained independently from the concrete class of logic programs considered as long as the required algebraic properties are satis ed. Throughout the section, we illustrate the introduced notions with the results obtained in [31] for Horn Clause Logic.

3.1 Speci cation frames

The notion of speci cation frame was introduced in [17] to axiomatize formalisms with certain basic compositionality properties, in order to study the structuring and modularization of speci cations with independence of any logic formalism. The notion was de ned as a \slight" abstraction of the notion of institution [24] de ned, some years before, by Goguen and Burstall with similar aims. That idea was connected with the design of the Clear speci cation language [11]. In particular, Clear was de ned as providing operations for structuring speci cations independently of the underlying logic. Speci cation frames are \indexed categories" that satisfy some additional \structural" properties:

De nition 1 A speci cation frame SF is a pair (Spec; Mod), where  Spec is a category of abstract speci cations (or programs), and  Mod : Specop ! Cat is a functor, that associates to every speci cation SP in Spec its category of models Mod(SP ), and to every speci cation morphism f : SP 1 ! SP 2 a functor Mod(f ) : Mod(SP 2) ! Mod(SP 1), usually denoted by Vf ,

such that the following two properties are satis ed: (a) Spec has pushouts (b) Mod transforms pushouts in Spec into pullbacks in Cat (i.e. SF has amalgamations).

Remarks 2

1. Pushouts are the operations that allow to combine speci cations, while amalgamation is the semantic (compositional) counterpart to pushouts. In particular, pushouts are diagrams in the category of speci cations. Essentially, if we want to put together two speci cations SP 1 and SP 2, having a common sub-speci cation SP 0, the pushout SP 3 (of SP 1 and SP 2, with respect to SP 0) would provide the right

6

combination. Almost all logics of practical interest have pushouts (see [16] for more detail). Amalgamation allows us to de ne the semantics of a combined speci cation purely on the semantic level as the amalgamation of the models classes of the speci cations which are combined. The reason is that, as we show below, given a pushout of speci cations as the diagram of gure 1, amalgamation can be characterized as an operation for \building" the models of SP 3 in terms of the models of SP 0, SP 1 and SP 2. SP 0 f 1 - SP 1

f2

?

SP 2

g1

g2

- SP?3

Figure 1: Pushout diagram Most logics have amalgamation. This is the case, for instance, of Horn Clause Logic (HCL), Equational Logic (EQL), Conditional Equational Logic (CEQL), Clausal Logic (CL), and First Order Logic (FOL). 2. It must be noted that the functorial character of Mod implies, in some sense, that speci cation frames are monotonic formalisms. In particular, if we consider a speci cation frame where speci cations are pairs (; ) (where  is some kind of signature and  is a set of axioms over that signature), then for any sets of formulas  and 0 over : Mod(;  [ 0)  Mod(; ) when speci cation inclusions, as (; )  (;  [ 0), are considered morphisms in Spec.

Theorem 3 ([17]) Given SF = (Spec; Mod), Mod transforms pushouts in Spec into pullbacks in Cat i for every pushout diagram in Spec , given in gure 1, the following three facts hold: (i) For every Ai 2 Mod(SPi) (i = 0; 1; 2) such that Vf 1(A1) = A0 = Vf 2(A2) there is a unique A3 2 Mod(SP 3), called amalgamation of A1 and A2 via A0, written A3 = A1 +A0 A2, such that we have: Vg1(A3) = A1 and Vg2(A3) = A2: (ii) Conversely, every A3 2 Mod(SP 3) has a unique decomposition A3 = Vg1(A3) +Vg1f1(A3) Vg2(A3) (iii) Similar properties to 1 and 2 above hold if we replace objects Ai by morphisms hi in Mod(SPi) (for 0  i  3), leading to a unique amalgamated sum of morphisms h3 = h1 +h0 h2 with Vg1(h3) = h1 and Vg2 (h3) = h2. The next example de nes an speci cation frame for Horn Clause Logic. After de ning it, we will analyze its properties.

Example 4 Horn Clause Logic HCL = (HCL; Mod), can be de ned as the following speci -

cation frame:

7

 Speci cations are pairs (; ) formed by a signature and a set of Horn clauses over , and speci cation morphisms h : (; ) ! (0; 0), where  and 0 are, respectively, (FS ; PS ) and (FS0 ; PS0 ), are pairs of mappings, (hFS ; hPS ), with hFS : FS ! FS0 and hPS : PS ! PS0 such that 1) arities are preserved and 2) h# ()  0, where h#

denotes the translation induced by h.  (; )-models, in HCL are Herbrand structures, i.e. sets of -atoms, that satisfy the axioms in  (according to the standard notion of satisfaction). A (; )-homomorphism between (; )-models, f : A1 ! A2, is just an inclusion, A1  A2. Then, Mod : HCLop ! Cat maps every speci cation (; ) in HCL into the category of all (; )models and (; )-homomorphisms, and every speci cation morphism h : (; ) ! (0 ; 0) into the corresponding forgetful functor Vh : Mod(0 ; 0) ! Mod(; ) de ned as usual, i.e. for every 0-model A0 we de ne Vh (A0) as the set of atoms whose translation via h is in A', i.e.: Vh (A0) = fa 2 Atoms()=h# (a) 2 A0 g Also, if f 0 : A10 ! A20 is a homomorphism in Mod(0 ; 0), i.e. A10 is included in A20, then Vh (f 0 ) is the inclusion Vh (A10)  Vh (A20). Let P 0 = (0; C 0), P 1 = (1; C 1) and P 2 = (2; C 2) be programs in HCL, with h1 : P 0 ! P 1 and h2 : P 0 ! P 2. If h1 and h2 are inclusions and 1 \ 2 = 0 then the pushout of P 1 and P 2 is just P 3 = P 1 [ P 2, i.e. (1 [ 2; C 1 [ C 2). In the general case, the construction of the pushout in HCL is a little more complicated but quite standard. Essentially, the pushout in the general case, is a kind of disjoint union where the symbols in 1 and 2, but not in 0, are renamed adequately and the morphisms g 1 and g 2 map each symbol in P 1 and P 2, respectively, into the corresponding symbol in P 3. Given the pushout diagram of gure 2, for h1 - P 1 P0

h2

?

P2

g1

- P 3?

g2

Figure 2: HCL-pushout diagram every Ai 2 Mod(Pi) (0  i  2), with Vh1 (A1) = Vh2 (A2) = A0, the amalgamation of A1 and A2 via A0, that is A3 = A1 +A0 A2, is de ned just as A1 [ A2, whenever h1 and h2 are inclusions and 1 \ 2 = 0. In the general case, A3 would be A3 = g 1#(A1) [ g 2# (A2). Horn Clause Logic, HCL, seems to be the most obvious choice for a speci cation frame for de ning the (declarative) semantics of de nite logic programs. Actually, this is (implicitly) done by most authors. In particular, the \standard" declarative meaning of a logic program P is de ned as the least Herbrand model of P (see, for instance, [28, 1]). In algebraic terms, this is equivalent to de ne the semantics of P as the least (initial) model in Mod(P ). However, if we are interested in logic programming languages as programming languages, then a reasonable choice would be one in which the input/output behaviour of programs were better captured. In that sense, [31] provides the de nition of another speci cation frame, DLP for De nite Logic Programs, which, obviously, shares the syntax with HCL, i.e. it has the same category of programs, but it is based on di erent notions of model and satisfaction.

8

3.2 Other properties of speci cation frames

In this subsection, we present some other properties of speci cation frames that may be required when studying speci c structuring or modular constructs. As we have already mentioned, the satisfaction of these properties provides the adequate setting for proving some usually desired semantic properties for these constructs. Moreover, that can be made independently of the underlying logic formalism (used to build speci cations or programs) whenever this formalism is a speci cation frame. In what follows, we also sketch, as an example, that these properties hold for the speci cation frame HCL.

De nition 5 A speci cation frame SF = (Spec; Mod : Specop ! Cat) has free constructions i for every speci cation morphism f : SP 1 ! SP 2 in Spec there is a free functor Ff : Mod(SP 1) ! Mod(SP 2) which is left adjoint to Vf . Ff (and, in general, any functor F : Mod(SP 1) ! Mod(SP 2)) is strongly persistent i Vf  Ff = ID. The intuition of the free construction, in this context, is quite simple. Consider, for instance, an inclusion of programs (or speci cations) P  P 0 . The free construction associated to this inclusion would build, for each model A of P , the least P 0 -model that can be build over A, i.e. if P and P 0 are de nite logic programs F (A) the least model associated to P 0 [ A, where A denotes the program consisting of all the atoms in A.If the morphism is more general than an inclusion (i.e. it de nes some form of translation between the signatures of P and P 0 ) then, similarly, F (A) could also be de ned as the least model associated to P 0 [A, where A would mean here the program consisting of the corresponding translation of all atoms in A. It may be noticed that the existence of free constructions in a given speci cation frame implies the existence of \initial" models (least models). Since the least model of a program P can be de ned as F (;) where ; denotes the empty model and F is the free construction associated to the inclusion E  P where E denotes the empty program. Conversely, it can be shown that for most speci cation frames the existence of initial (least) models associated to every speci cation (or program) ensures the existence of free constructions.

Example 6 (Properties of HCL, [31]) HCL has free constructions. It is almost obvious to see that, given a program P = (; C ) of HCL, the category Mod(P ) is closed under intersection. This means that there is a least model MP in Mod(P ) which

happens to be trivially initial, according to the notion of homomorphism used (inclusions) in the categories of models. Therefore, in the case of HCL, the existence of free constructions is a consequence of the existence of initial objects. In particular, given a morphism h : P ! P 0 , with P = (; C ) and P 0 = (0 ; C 0), the free construction Fh : Mod(P ) ! Mod(P 0) can be de ned for every A in Mod(P ) as the initial model of the program (0; C 0 [ h# (A)), noted MP (A), where h# (A)) is the program consisting of the translation through h of all the atoms in A.

Free constructions have been used at the model level to give semantics to parameterized speci cations. In [31] free constructions are considered as the semantics of the di erent kinds of open (or modular) logic programs. Horn Clause Logic (HCL), Equational Logic (EQL) and Conditional Equational Logic (CEQL) have free constructions (see [16]). In contrast Clausal Logic (CL) and First Order Logic (FOL), in general, do not.

De nition 7 A speci cation frame SF = (Spec; Mod) has free extensions i for every pushout diagram in Spec as gure 1, if F : Mod(SP 0) ! Mod(SP 1) is a strongly persistent free functor 9

with respect to f 1, then there is a strongly persistent functor F  : Mod(SP 2) ! Mod(SP 3), called the extension of F via f 2, such that: (a) F* is free with respect to g2 (b) The diagram of gure 3 commutes.

Mod(SP 0)

6V

F

f2

Mod(SP 2)

- Mod(SP 1) 6V g1

F

- Mod(SP 3)

Figure 3: Free extension diagram Extension may be, in some cases, a key construction for proving compositionality and full abstraction results. This is the case, in particular, when the semantics of the given construction is expressed as a persistent free functor. Every logic having amalgamations has also free extensions.

Theorem 8 ([17]) Speci cation frames have free extensions. This result is a consequence of the existence of amalgamation. Being more concrete, if F : Mod(SP 0) ! Mod(SP 1) is a strongly persistent free functor with respect to f 1 then the extension of F via f 2 is the strongly persistent free functor F  : Mod(SP 2) ! Mod(SP 3), such that for each model A2 in Mod(SP 2), F  (A2) is the amalgamated sum A2 +Vf2 (A2);f 2 F (Vf 2(A2)).

Example 9 (Properties of HCL, [31]) HCL has free extensions , since it has amalgama-

tions.

The existence of extensions for strongly persistent free functors can be generalized to the non-persistent case under certain circumstances:

Vf 2

 Vf 2  u Vf 3  F 

? @@ ? u  Vf 2 @ ? Vf 1  v @R ? Vf 1  F  V f 2

Figure 4: Natural transformations associated to a generalized free extension

De nition 10 A speci cation frame SF = (Spec; Mod) has generalized free extensions i for every pushout diagram as in gure 1, if F : Mod(SP 0) ! Mod(SP 1) is a free functor with respect to f 1, then there is a functor F  : Mod(SP 2) ! Mod(SP 3), called the generalized extension of F via f 2, such that: 10

(a) F  is free with respect to g2 (b) There is a natural transformation v : F  Vf 2 ! Vg1  F  such that the diagram of natural transformations in gure 4 commutes, where f 3 = g 1  f 1 = g 2  f 2 and u and u are, respectively, the universal transformations associated to F and F  .

Theorem 11 ([25]) If a speci cation frame SF has free constructions and pushouts in all

model categories Mod(SP ), for all abstract speci cations SP in Spec, then SF has generalized free extensions.

Example 12 (Properties of HCL, [31]) HCL has generalized free extensions because, according to de nition 10, it is enough to check that for every program P , there are pushouts in Mod(P ): Given models A0; A1; A2 in Mod(P ), with f 1 : A0  A1 and f 2 : A0  A2, we can de ne the pushout of A1 and A2 along f 1 and f 2 is just the join A1 t A2.

3.3 Standard Union of Logic Programs

In this subsection, we present compositionality and full abstraction results ([31]) for a semantics of the standard union of logic programs, which are general in the sense that they are independent of the class of logic programs considered, as long as it is a speci cation frame with the properties introduced in the subsection 3.2. As it is well known, the least model semantics of logic programs is neither compositional nor fully abstract (in a compositional way). As a result, some form of more complex semantics must be considered if we intend to capture a compositional behaviour. For instance, [23] studies the (standard) union of logic programs and the composition of logic modules, where a logic module can be seen as a logic program including an additional import/export interface, with the restriction that clauses in the module do not include imported predicates in their heads. In both cases, the meaning of these constructions is de ned in terms of sets of minimal clauses, that are logical consequences of the given program. In our context, we can see these meanings as concrete representatives of our general algebraic constructions. In this sense, the full abstraction results in [23] can be seen just as ad-hoc versions of variations of the results obtained in [31]. In our approach, for studying the operation of union, we consider that a logic program P = (; C ) may be seen as a special kind of open program where all predicates are partially de ned, in the sense that more information about the predicates in PS , can be added by union with other programs. In our context, this implies that the meaning of a program P can be seen as a mapping that given a -structure A (that can be seen as including the \missing" de nitions of the predicates in P ), yields as result the \complete" interpretation ofP , i.e. we may consider that the meaning of P is the free construction associated to the program inclusion: (; ;)  P . De nition 13 The semantics of a program P = (; C ), noted by Sem(P ), is the free functor F : Mod(; ;) ! Mod(P ), associated to the inclusion (; ;)  P . It may be noted that, in this case, the semantics of P is never a persistent functor, since given a program P and a -model A, F (A) is in general di erent from A.

De nition 14 Let P 1 = (1; C 1) and P 2 = (2; C 2) be programs, the standard union of P 1 and P 2, P 1 [ P 2, is the program (1 [ 2; C 1 [ C 2). 11

It must be noted that P 1 [ P 2 coincides with the result of the pushout diagram, in the category of programs of the underlying speci cation frame, given by gure 5. (1 \ 2; ;)

- P1

?

- P 1 [?P 2

P2

Figure 5: Standard union of programs Dealing with programs whose semantics is persistent, compositionality of our semantics, with respect to standard union, is a direct consequence of the existence of free extensions in the speci cation frame. However, in the general case, we have to use the more complex construction of generalized free extension. Mod(1; ;) Sem(P 1)- Mod(P1)

6

Mod(2; ;)  Sem(P 2)

?

Mod(P 2)



6

0 Mod(; ;) Sem (P 1)- Mod(2 [ 1 ; C 1)

Sem0(P 2)

F2

? ? Mod(1 [ 2; C 2) F 1 - Mod(P1 [ P2 )

Figure 6: Union compositionality

Theorem 15 (Compositionality, [31]) The semantics of P 1 [ P 2 can be obtained as: Sem(P 1 [ P 2) = F 1  Sem0(P 2) = F 2  Sem0 (P 1), where (i)  = 1 [ 2 (ii) Sem0(P 1) and Sem0(P 2) are the generalized extensions of Sem(P 1) and Sem(P 2) via the inclusions (1; ;)  (; ;) and (2; ;)  (; ;), respectively (iii) F 1 and F 2 are the generalized extensions of Sem0(P 1) and Sem0(P 2) via the inclusions (; ;)  (; C 1) and (; ;)  (; C 2), respectively. It must be noted that theorem 15 really proves the compositionality of Sem with respect to standard union, in the sense that the meaning of P 1 [ P 2 is de ned in terms of the meaning of P 1 and P 2, since the generalized extension of free functor F via an inclusion i, is uniquely determined by F and i. On the other hand, the following lemma is a consequence of the fact that free constructions are unique up to natural isomorphism:

12

Lemma 16 ([31]) Given two programs P 1 and P 2,

Sem(P 1) = Sem(P 2) i for every P : Sem(P [ P 1) = Sem(P [ P 2).

This lemma can be used to prove full abstraction of the given semantics. In particular, a semantic de nition of a program unit is fully abstract with respect to a given composition operation, for instance [, and a given observation criteria Obs if and only if for all programs P 1 and P 2 Sem(P 1) = Sem(P 2) i for every P : Obs(P [ P 1) = Obs(P [ P 2). Now, there are several observation criteria that may be used in the context of logic programming. The most obvious one is to consider two programs P 1 and P 2 observationally equivalent if and only if the ground consequences of the two programs coincide, or equivalently if and only if their associated least models coincide (in [31] it is also considered observations associated to the computed answers of the given programs). In this sense, full abstraction can be reformulated as: Sem(P 1) = Sem(P 2) i for every P : TP [P 1 = TP [P 2 where TP denotes the initial model of P in the corresponding speci cation frame, for example, if the underlying speci cation frame is HCL then TP is the minimal Herbrand model of P , that is, TP = MP . The abstract result of full abstraction works for all \algebraic" speci cation frames (in particular HCL is algebraic:

De nition 17 A speci cation frame SF = (Spec; Mod) is algebraic if for each speci cation SP in Spec and for each model A in Mod(P ) there exists a speci cation SP 0 such that A = TSP 0 , where TSP 0 denotes the initial model of SP 0. Theorem 18 (Full abstraction, [31]) Let SF = (Prog; Mod) be an algebraic speci cation frame. Then, given two programs P 1 and P 2 in Prog, Sem(P 1) = Sem(P 2) i for every P : TP [P 1 = TP [P 2. In [31], these results are used to analyze and improve previous ones. More speci cally, with respect to standard union, it is proved that the semantics proposed in [23] is equivalent to the above \abstract" semantics: this allows us to conclude that their semantics is not only fully abstract, as they prove, but also compositional. Being more concrete, the semantics of a logic program P = (; C ), as de ned in [23], can be seen as a speci c representative of the free construction associated to the inclusion (; ;)  (; C ) in the speci cation frame HCL. Then, the full abstraction results of [23] are just a consequence of the results in subsection 3.2 applied to the speci cation frame HCL. On the other hand, according to these results, the compositionality of the semantics, with respect to the union, is a consequence of theorem 15.

13

4 A model-theoretic semantics for normal logic programs As said in the introduction, our aim is to de ne a model-theoretic semantics for normal programs (i.e. the meaning of a program P is the set Mod(P ) of all models of P , for a given notion of model), such that the following monotonicity property holds Mod(P )  Mod(P [ P 0 ) for all P; P 0 In addition, we also want this semantics to be adequate for applying the general results presented in the previous section. this means that it must be possible , based on this semantics, to de ne a speci cation frame satisfying all the properties needed for de ning the the meaning of the kind of programs units considered. In particular, this means that this speci cation frame must have free constructions and, as a consequence, every program P must have a least model, denoted MP , that could be considered its \standard" meaning. On the other hand, obviously, this semantics should be proved equivalent to the \standard" meaning associated to normal logic programs. An obvious choice is to consider that the models of a program P are three-valued structures. Then, one would try to nd an ordering among models satisfying that there is a least element that can be proved equivalent to the intended meaning of P . Unfortunately, as the following counter-example shows, this is not possible. Example 19 Let us consider the normal program P 1  fa : ?:bg, its least model MP 1 should be the pair (fag; fbg), and consider P 10  fb : ?g, then MP 1[P 10  (fbg; fag). Then we must have (fag; fbg)  (fbg; fag). Now, by considering the program P 2  fb : ?:ag and extending it with the clause fa : ?g we obtain that (fbg; fag)  (fag; fbg) should hold. From our point of view, the problem in this counter-example is that MP 1[P 10 and MP 2 should not be identical and should re ect, in some sense, the \dependences from negative information" which make a given atom to be in the model. For instance, MP 2 includes b as a consequence of the negative information provided by a, while MP 1[P 10 includes b without any dependency of negative information. This consideration has led us to consider models having \layers" that re ect these dependencies. We call these models ranked structures because of their relation with ranked resolution. For instance, if we consider again the above Example 19, the \intended" model for P 1 has a rst layer given by (;; fbg) and a second layer (fag; fbg). However for P 1 [ P 10 the rst layer is (fbg; ;), and the second layer (fbg; fag). Similarly, for P 2 the rst layer is (;; fag) and the second layer is (fbg; fag). Now the intended models associated to P 1 [ P 10 and to P 2 are di erent, since their rst layers di er. In what follows, rst we sketch the propositional case to provide some intuition. In subsection 4.2 we extend the already presented semantical notions to the class of all normal logic programs. Then, in subsection 4.3 we prove the existence of a least model and we provide a continuous immediate consequence operator for obtaining it in a bottom-up constructive way. Finally, we show the equivalence of our semantics with Clark-Kunen semantics, proving that our least model is a\typical" element in the class of all models of program completion.

4.1 A rst approach: The propositional case

In the propositional case, it is enough to consider sequences of Herbrand three-valued structures. In the next subsection we extend this notion of semantical structure to deal with

14

normal programs with variables.

De nition 20 (propositional case) A ranked three-valued -structure A is a sequence of pairs h(A+i ; A?i )ii2IN such that for any i 2 IN :  A+i  A+i+1 and A?i  A?i+1  A+i \ A?i = ;.

The \layers" of our structures could also be related to the notion of strati cation ([2, 39]), but strati cation is a syntactic restriction on the class of programs for ensuring the existence of certain semantic constructions, whereas ranked structures are models. Actually, as it can be seen below, we do not impose any restriction on the kind of programs we deal with (they do not have to be strati ed in any sense). Now, we de ne when one of these structures is a model of a program: De nition 21 A ranked three-valued -structure A is a model of a propositional normal program P (denoted by A j= P ) i the following four conditions are satis ed: (a) If P 8 [ A+0 j= a then a 2 A+0 (in particular if a : ? 2 P ) (b) If a 2 A?0 then there is not any clause a : ?l in P (c) If P 8 [ A+i+1 [ :A?i j= a then a 2 A+i+1, where :A?i meansf:aja 2 A?i g (d) If a 2 A?i+1 then for every a : ?l 2 P it holds one of the following two fact:  there exists b 2 l such that b 2 A?i  there exists :b 2 l such that b 2 A+i . Notice that for the program P 1  fa : ?:bg of Example 19, the following are some of its models 1 : M1 = h(;; fbg); (fag; fbg)i M2 = h(fag; fbg)i M3 = h(fa; bg; ;)i M4 = h(;; ;)i M5 = h(fbg; ;); (fbg; fag)i but M6 = h(fbg; fag)i is not a model of P . Our model notion allows us to include (in any layer) more positive information than what is supported as logical consequence of the previous layers, but the negative information of each layer must be supported (in that sense). Thus, if we want to de ne an ordering  on ranked structures such that the least model is the one having, at each layer, the least amount of positive information and the greatest amount of negative information supported by the previous layer, it suces to consider that  is the lexicographic extension over sequences h(A+i ; A?i )ii2IN of the standard ordering over three-valued structures: (A+ ; A? )  (B + ; B ? ) i A+  B + and A?  B ? . It is easy to see that, for the above program P 1, M1 is the -least model in Mod(P 1). Now, consider the case where we add the clause b : ?b to P 1, then M1 and M2 are not models of the new program. In this case, the least model is M4. Furthermore, by adding a third clause b : ?, M4 is not model of the new program fa : ?:b; b : ?b; b : ?g, and the least model would now be M5.

1

if we just write n layers, it must be assumed that the following layers are equal to the nth layer

15

4.2 Normal logic programs

In this subsection, we extend the model-theoretic semantics to the general case of normal programs with variables. Firstly, it must be noticed that this extension can not just consist on seeing normal programs with variables as abbreviations for programs including all possible ground instances of the given clauses. For instance, the programs P 1  fnat(0) : ?; nat(s(x)) : ?nat(x)g and P 2  fnat(x) : ?g have exactly the same instances (considering the signature including, as unique function symbols, the constant 0 and the unary function symbol s), but they have a completely di erent behaviour. By example, the query ? ? :nat(x) would be unde ned for P 1 and false for P 2. The solution proposed is rather to handle the rst-order case in a similar manner to the propositional case, by considering ranked structures including not just ground atoms but constrained atoms with variables.

De nition 22 A ranked three-valued -structure is a sequence A = h(A+i ; A?i )ii2IN such that for any i 2 IN :  A+i and A?i are sets of pairs p(x)2c(x), where p 2 PS and c(x) is a satis able constraint  A+i and A?i are closed under renaming of variables  A+i  A+i+1 and A?i  A?i+1  (Consistency Property) For any p 2 PS , if there exists -constraints c and d such that p(x)2c 2 A+i and p(x)2d 2 A?i , then c ^ d is unsatis able.

We will not make explicit the free variables of a constrained atom whenever they are not relevant. A pair p2c 2 A+i is logically interpreted as the formula (c ! p)8, and a pair p2c 2 A?i has the logical meaning of (c ! :p)8. Consequently, we de ne the sets: A+i 8  f(c ! p)8jp2c 2 A+i g ? 8 A?8 i  f(c ! :p) jp2c 2 Ai g

A8i  A+i 8 [ A?8 i

De nition 23 A ranked three-valued -structure A is a model of a normal program P (denoted: A j= P ) i the following four conditions are rati ed: (a) If FET [ P 8 [ A+0 8 j= (c ! p)8 and c is satis able, then p2c 2 A+0 (b) If p(x)2c(x) 2 A?0 then c ^ c0 is unsatis able for every (properly renamed) clause p(x) : ?l2c0 2 P + 8 (c) If FET [ P 8 [ A+i+18 [ A?8 i j= (c ! p) and c is satis able, then p2c 2 Ai+1 (d) If p(x)2c 2 A?i+1 then FET [ A8i j= ((c ^ c0) ! :l))8 for every (properly renamed) clause p(x) : ?l2c0 2 P . Remarks 24 Conditions (a) and (c) can be slightly simpli ed into: 16

(a') If FET [ P 8 j= (c ! p)8 and c is satis able, then p2c 2 A+0 + 8 (c') If FET [ P 8 [ A?8 i j= (c ! p) and c is satis able, then p2c 2 Ai+1

if we would not have the aim of proving that this semantics de nes a speci cation frame. Unfortunately, properties (a) and (c) are needed for proving the so-called amalgamation property of speci cation frames. Now, we can de ne a model theoretic semantics for normal programs, in terms of the class of models, for a program P : Mod(P ) = fAjA j= P g. This semantics is monotonic with respect to program extension. Theorem 25 For all program P; P 0. Mod(P )  Mod(P [ P 0) Proof: Suppose that A j= P [ P 0, for proving that A j= P conditions (b) and (d) are trivial. In order to prove conditions (a) and (c), it is enough to consider that (P [ P 0 )8  P 8 [ P 08, which means that, for any set of formulas  [ f'g, it holds: if FET [ P 8 [  j= ' then FET [ (P [ P 0 )8 [  j= '. Likewise in the propositional case, the ordering considered over Mod(P ) is the lexicographical extension  over sequences h(A+i ; A?i )ii2IN of the standard ordering. As in the propositional case, we have: Theorem 26 For any -program P there exists a -least -model MP in the class Mod(P ). Proof: Let P be any -program, we de ne MP as the ranked -structure h(Mi+; Mi?)ii2IN such that  M0+ is the -least set satisfying condition (a).  M0? is the -greatest set satisfying condition (b).  Mi++1 is the -least set satisfying condition (c).  Mi?+1 is the -greatest set satisfying condition (d). By de nition MP is a model of P . In order to prove that it is the least one, suppose any other A 2 Mod(P ) such that A  MP . Then, there is some i 2 IN such that A+j = Mj+ and A?j = Mj? for any j < i, but it holds one of the two facts: (i) there is p2c 2 A?i n Mi? (ii) there is p2c 2 Mi+ n A+i We will prove that both facts are not possible. (i) Suppose that p2c 2 A?i . If i = 0 then for every clause p(x) : ?l2x = t in P , the constraint c ^ x = t is unsatis able, but this is a sucient condition for p2c 2 M0? . For i > 0, the case p2c 2 A?j for some j < i is trivial since A+i  A+j = Mj+ . Otherwise, we have that for every clause p(x) : ?l2x = t in P it holds that: FET [ A8i?1 j= ((c ^ x = t) ! :l)8 since Mi8?1 = A8i?1 , we have that p2c also belongs to Mi? . (ii) Now, suppose that p2c 2 Mi+ . For i = 0 that means FET [ P 8 [ M0+ j= (c ! p)8, since A 2 Mod(P ) and M0+  A+0 , this suces to ensure that p2c 2 A+0 . For i > 0 there are two cases. First, p2c 2 Mj+ for some j < i, but A+i  A+j = Mj+ and A?i?1  A?j ?1 = Mj??1 . Otherwise, we have that

17

8 FET [ P 8 [ Mi+8 [ Mi?8 ?1 j= (c ! p) ?8 since (i), we have that A?8 i?1 = Mi?1 , and because of the construction of MP we also have that A+i 8  Mi+8, so that we obtain p2c 2 A+i .

4.3 The least model

In this subsection we study some interesting properties of least models. In particular, di erent characterizations by logical consequence closure and its constructive de nition through an immediate consequence operator. From now on, h(Mi+ ; Mi?)ii2IN will denote the least model MP of a given program P . Our rst least model characterization is made in terms of a logical consequence closure of the equality theory and the standard logical interpretation of the program.

Lemma 27 For any program P : (i) p2c 2 M0+ () FET [ P 8 j= (c ! p)8 (ii) p2c 2 Mi++1 () FET [ P 8 [ Mi8 j= (c ! p)8 (iii) p2c 2 Mi? () FET [ P 8 [ Mi8 j= (c ! :p)8 Proof: Right-to-left implication of (i) and (ii), as well as (iii)-left-to-right, are trivial. We will

prove the others by simultaneous induction on i. For the converse implication of (i), we de ne the set B  fq2d j FET [ P 8 j= (d ! q)8 and d is satis ableg Now, using the fact that for every set of formulas  [ f g:  [ f' j  j= 'g j= =)  j= it is easy to see that B satis es de nition 23(a). Therefore, M0+  B . The proof for the converse implication of (ii) is similar, but taking the set B  fq2d j FET [ P 8 [ Mi+8 j= (d ! q)8 and d is satis ableg . For the right-to-left implication of (iii), the key idea is that the program P cannot "add" new negative logical consequences. In particular, if we assume that a2c is not in Mi? , then we can build a model of FET [ P 8 [ Mi8 which is not a model of (c ! :a)8: it is enough to consider the Herbrand structure (A+ ; A? ) where A? consists of all atoms b such that b2d 2 Mi? and  is a (ground substitution) solution of d, and A+ includes the rest of the atoms. A trivial consequence of the previous lemma is that MP is closed with respect to less general constraints.

Lemma 28 For any program P and for every i 2 IN : (i) if p2c 2 Mi+ and FET j= (d ! c)8 and d is satis able, then p2d 2 Mi+ 18

(ii) if p2c 2 Mi? and FET j= (d ! c)8 and d is satis able, then p2d 2 Mi? Proof: It is enough to notice that for any set of formulas  [ f'g, if FET [  j= (c ! ')8 and FET j= (d ! c)8, then FET [  j= (d ! ')8. Now, we are going to characterize the least model in the usual constructive way: as the least x point of a monotonic and continuous immediate consequence operator. For that purpose we order ranked structures by the trivial extension of Fitting's ordering: A F B i A+i  Bi+ and A?i  Bi? for all i 2 IN It is easy to see that ranked structures are a cpo with respect to F , whose bottom is the in nite sequence of pairs of empty sets and the least upper bound, for every in nite increasing chain of ranked structures, is the level-by level union of positive and negative parts of all of them. We de ne an immediate consequence operator in the following way:

De nition 29 Let P be a program and A a ranked structure, TP (A) = B where B is the ranked structure de ned for each i 2 IN by:

Bi+ = VP (A+i ; A?i?1) and Bi? = RP (A+i?1 ; A?i?1 ) where A+?1  A??1  ;, by convention, and VP and RP are the following two operators over pairs of sets of constrained atoms:

VP (C; D) = fp(x)2c(x) j For some n  1, some satis able constraints c1 ; : : :; cn , and some P 's subset of (properly renamed) clauses fp(x) : ?lk 2dk jW1  k  ng: FET j= (c ! nk=1 (dk ^ ck ))8 and FET [ C 8 [ D8 j= (ck ! lk)8 for all k = 1; : : :; ng RP (C; D) = fp(x)2c(x) j For every (properly renamed) clause p(x) : ?l2d 2 P : FET [ C 8 [ D8 j= ((c ^ d) ! :l))8g The monotonicity of logical consequence trivially implies that VP and RP are monotonic with respect to , hence TP is monotonic with respect to F . Moreover, we will proof that it is continuous and, therefore, we will obtain MP at the ! iteration of TP over the always empty ranked structure.

Lemma 30 For any program P , TP is continuous. Proof: Consider any in nite chain of ranked structures A0 F A1 F : : : F An F : : : By monotonicity of TP it is enough to prove that TP (tAn) F tTP (An). Consider, rstly, p(x)2c(x) 2 (TP (tAn))+0 , then there exists n  1, constraints c1 ; : : :; cn , and a subset fp(x) : ?lk 2dk j1  k  ng of P , such that FET j= (c ! Wnk=1 (dk ^ ck ))8 and FET [ (tAn)+0 8 j= (ck ! lk )8 for all k = 1; : : :; n. Hence, by compactness of the logic, there exists some Ar (in the chain) such that 19

FET [ (Ar)+0 8 j= (ck ! lk )8 for all k = 1; : : :; n. Therefore p(x)2c(x) 2 (TP (Ar))+0 , and so, it belongs to (tTP (An))+0 . Similarly, by considering that p(x)2c(x) 2 (TP (tAn))+i+1 , we have that: FET j= (c ! Wnk=1 (dk ^ ck ))8 and k 8 FET [ (Ar)+i+18 [ (Ar)?8 i j= (ck ! l ) for all k = 1; : : :; n. so that, p(x)2c(x) 2 (TP (Ar))+i+1 .

The proof for the inclusion of negative parts is similar and easier. The following lemma provides an useful induction principle for reasoning about the least model. In particular, it settles the basis for the least model characterization in terms of least xpoints and to compare TP with the Fitting's operator.

Lemma 31 For any program P : (i) M0+ = VP " !(;; ;) (ii) M0? = RP (;; ;) (iii) Mi++1 = VP " !(Mi+; Mi?) (iv) Mi?+1 = RP (Mi+; Mi?) where VP " 0(C; D) = C and VP " (i + 1)(C; D) = VP (VP " i(C; D); D) Proof: Facts (ii) and (iv) are trivial since M0? and Mi?+1 are, respectively, the -greatest

sets satisfying conditions (b) and (d) in de nition 23. The right-to-left inclusions of (i) and (iii) are also trivial from the fact that MP is a model of P . Since MP is the least model of P , we will prove the left-to-right inclusions of (i) and (iii) by proving that VP " ! (;; ;) and VP " ! (Mi+ ; Mi? ) satisfy, respectively, de nition 23(a) and (c), that is, for any satis able constraint c: (1) FET [ P 8 [ VP " ! (;; ;)8 j= (c ! p)8 =) p2c 2 VP " ! (;; ;) (2) FET [ P 8 [ VP " ! (Mi+ ; Mi? )8 [ Mi?8 j= (c ! p)8 =) p2c 2 VP " ! (Mi+ ; Mi?) In order to proof (1), let us consider a constrained atom p(x)2c(x) 62 VP " ! (;; ;) with c satis able, we will prove the existence of a three-valued -model of FET [ P 8 [ (VP " ! (;; ;))8 which is a counter-model of 8x(c(x) ! p(x)). Firstly, notice that the set VP " ! (;; ;) is closed with respect to less general constraints and nite disjunction of constraints. So that, by p(x)2c(x) 62 VP " ! (;; ;) and logical compactness, we prove the existence of a 0-model for the following set of formulas:   FET [ fc[a=x]g [ f:d[a=x] j p2d 2 VP " ! (;; ;)g where 0 is the extension of  by the new constant symbols a. Since  is a set of closed universal equality formulas, we can choose the initial 0 -model of , namely A, and we can assume that A gives any arbitrary predicate interpretation, provided that it satis es coherence with respect to the congruence relation on terms. So that, we can de ne: (  j= (x = s ! e)8 for some q (x)2e(x) 2 VP " ! (;; ;) qA (s) = tu ifotherwise

20

for each n-ary predicate symbol q 2 PS and each s 2 (H0 )n . It is trivial, by construction, that A is a model of FET [ (VP " ! (;; ;))8, and a countermodel of 8x(c(x) ! p(x)). For proving that A is also a model of P 8 , let q (x) : ?l1; : : :; lk 2g be a clause in P (with x; y as free variables in the body), and let s 2 (H0 )n and r 2 (H0 )m, such that A j= (l ^ g)[s; r=x; y]. Then, l1; : : :; lk must be atoms (because our model does not make true any negated atom) such that for all i = 1; : : :; k there exists a constraint di such that li(x; y)2di(x; y) 2 VP " !(;; ;) and  j= (x = s ! 9y(g (x; y) ^

k ^ i=1

di (x; y)))8:

Moreover, by logical compactness and the de nition of VP , the following constrained atom belongs to VP " ! (;; ;):

q(x)29y(g(x; y) ^

k ^ i=1

di (x; y))

So that, q A (s) = t. Finally, the 0-structure A must be transformed into a -structure, by interpreting (over the same universe) only function symbols in FS (but not new constants symbols). The proof for (2) is very similar. For a constrained atom p2c 62 VP " ! (Mi+ ; Mi? ) with c satis able, we obtain the initial 0-model A of   FET [ fc[a=x]g [ f:d[a=x] j p2d 2 VP " ! (Mi+ ; Mi? )g with interpretation for predicate symbols given by: 8 > t if  j= (x = s ! e)8 for some q 2e 2 VP " ! (Mi+ ; Mi? ) < A q (s) = > f if  j= (x = s ! e)8 for some q2e 2 Mi? : u otherwise

Proving that A is a model of P is very similar to the previous case. Now it can be shown that MP coincides with the least x point of TP .

Lemma 32 For any -program P : TP " !(?) = MP , where ? is the ranked structure h(;; ;); (;; ;); : : :i. Proof: It is trivial that for all j 2 IN : TP " j (?) F MP , hence TP " !(?) F MP . We will prove the opposite inclusion, that is, for all i 2 IN : Mi+  (TP " !(?))+i and Mi?  (TP " !(?))?i We make induction on i, using that, by lemma 31, for all i 2 IN : Mi+ = VP " !(Mi+?1; Mi??1 ) and Mi? = RP (Mi+?1 ; Mi??1) (where M?+1 = M??1 = ;). For i = 0 it is trivial by de nition of TP . In the inductive step

for i + 1, the inclusion of negative parts is trivial. For the positive ones, it is easy to prove that for all j 2 IN : VP " j (Mi+; Mi? )  (TP " ! (?))+i+1, using induction on j and the induction hypothesis about Mi+ and Mi? . Therefore, MP F TP " ! (?).

21

4.4 Equivalence with Clark-Kunnen semantics

In this subsection we are going to prove that our model-theoretic semantics is equivalent to the Clark-Kunen semantics. In particular what we will prove is that, on the one hand, for every program P its least model MP is also a model of Comp(P ) and, on the other hand, MP is \typical" in the class of models of Comp(P ), in the sense that if MP satis es any constrained literal l2c, then any model of Comp(P ) also satis es l2c. Now, in order to show that MP j= Comp(p), we should rst de ne the truth-value of rst-order sentences in any ranked three-value structure A, so that A can also be considered a \standard" three-valued structure. We begin by assigning truth-values to constrained atoms trough the key (and obvious) de nition:

De nition 33 Let A  h(A+i ; A?i )ii2IN be a ranked -structure, then: 8 > < t if p(x)2c(x) 2 A+i? for some i 2 IN A(p(x)2c(x)) = > f if p(x)2c(x) 2 Ai for some i 2 IN : u otherwise This de nition can be extended to any arbitrary constrained formula:

De nition 34 Let A  h(A+i ; A?i )ii2IN be a ranked -structure, ' a -formula such that free(') = x and c(x) a satis able -constraint, we de ne A('2c(x)) by inductively extending

previous de nition as follows:

8 8 > > < t if A('2c) = f < t if FET j= (c ! t1 = t2 )8 8 A(:'2c) = > f if A('2c) = t A(t1 = t22c) = > f if FET j= (c ! :(t1 = t2)) : u otherwise : u otherwise 8 t if A('12c1) = A('22c2) = t for c ! c1 ^ c2 > > > < f if A('12c1 ) = f for c ! c1 or A('2 2c2) = f for c ! c2 A('1 ^ '22c) = > or A('1 2c1) = A('22c2) = f for c ! c1 _ c2 > : u otherwise 8 t A(' 2c ) = f for c ! c > 1 1 1 > > for c ! c or A ( ' 2 c ) = t > < or A('122c12) = A('22c2 ) =2 u for c ! c1 ^ c2 A('1 ! '22c) = > f A('12c1) = t and A('22c2) 6= t for c ! c1 ^ c2 > > > : or A('12c1) = u and A('2 2c2) = f for c ! c1 ^ c2

u otherwise

8 > < t if A('1 2c1) = A('2 2c2) for c ! c1 ^ c2 A('1 $ '22c) = > f if A('12c1) 6= A('22c2) for c ! c1 _ c2 : u otherwise 8 W > < t if A('2c0i ) = t (for all i) for0 c ! 8y i ci A(8y'2c) = > f if A('2c ) = f for c ! 9yc : u otherwise

22

A('1 _ '22c) = A(:(:'1 ^ :'2)2c) A(9y'2c) = A(:8y:'2c). where \ for c ! (c1  c2)" (resp. \for c ! ci", i = 1; 2) abbreviates \for some c1 ; c2 (resp. ci ) such that any free variable of ci appears free in 'i and FET j= (c ! (c1  c2))8 (resp. FET j= (c ! ci)8)".

A very similar de nition, to interpret goals of CLP-programs, is made in [37]. Now, we de ne the value of rst-order sentences in ranked three-valued structures:

De nition 35 For any ranked three-valued -structure Let A  h(A+i ; A?i )ii2IN , and any rst-order -sentence ', we de ne A(') = A('2T). We will prove that our least model is a model of program completion:

Theorem 36 For every -program P : MP j= Comp(P ) Proof: We will show that MP (') = t for all ' 2 Comp(P ). This is trivial for every ' 2 FET.

Now, consider any predicate completion formula m _ 8x(p(x) $ 9yk (dk ^ lk )) k=1

where HdP (p(x)) = fp(x) : ?lk 2dk j k = 1; : : :; mg. and each lk = l1k ; : : :; lnk k . It is enough to prove that, for any satis able constraint c(x), the following two facts hold: m [ _ (1) p(x)2c(x) 2 Mi+ () MP ( 9yk (dk ^ lk )2c(x)) = t i

(2) p(x)2c(x) 2

[ ? Mi () MP ( i

k=1 m _

k=1

9yk (dk ^ lk )2c(x)) = f

In order to prove the left-to-right implication of (1), consider any p(x)2c(x) 2 Mi+ for some i 2 IN then, by lemma 31, there is some S  f1; : : :; mg and some set of satis able constraints fciji 2 S g such that: FET j= (c ! Wk2S 9yk (dk ^ ck ))8 and FET [ Mi8?1 j= (ck ! lk )8, for all k 2 S . By lemma 27, each ljk is either an atom q such that q 2ck 2 Mi++1 or a negated atom :q such that q 2ck 2 Mi? . Then, it is easy to see that: m _ _ MP ( 9yk (dk ^ lk )2 9yk (dk ^ ck )) = t k2S

k=1

Since MP is closed with respect to less general constraints, by lemma 28, we have that m _ MP ( 9yk (dk ^ lk )2c(x)) = t k=1

23

The proof for the converse implication of (1) is very easy by application of de nition 34. To prove the left-to-right implication of (2), we made induction in layers. Firstly, consider any p(x)2c(x) 2 M0? . Then, for all k = 1; : : :; m: FET j= (c ! :9yk dk )8, and therefore: MP (9yk dk 2c) = f . So that, m _ MP ( 9yk (dk ^ lk )2c(x)) = f k=1

Now, consider any p(x)2c(x) 2 Mi?+1 then, FET [ Mi8 j= (c ! (:9yk (dk ^ lk )))8, for all k = 1; : : :; m. Then, using the induction hypothesis, we can obtain that MP (9yk (dk ^ lk )2c(x)) = f for all k = 1; : : :; m. Therefore, by de nition 34, it holds: m _ MP ( 9yk (dk ^ lk )2c) = f : k=1

Finally, the proof for the converse implication of (2) is straightforward using de nition 34. In order to prove the \typicity" property of MP , the key result is the following lemma:

Lemma 37 For all n 2 IN : (i) p2c 2 Mn+ =) Comp(P ) j= (c ! p)8 (ii) p2c 2 Mn? =) Comp(P ) j= (c ! :p)8 Proof: By simultaneous induction on n. For n = 0, if p2c 2 M0+ then, by lemma 27, FET [ P 8 j= (c ! p)8. Since Comp(P ) j= FET [ P 8 (see section 2), that means Comp(P ) j= (c ! p)8. Now, if p(x)2c(x) 2 M0? then c ^ dk is unsatis able for every p(x) : ?lk 2dk 2 P . Then, for all k = 1::m (where m is the number of clauses with head p): FET j= 8x(c ! :9yk dk ). So that, Comp(P ) j= 8x(c ! : Therefore, Comp(P ) j= 8x(c(x) ! :p(x)).

m _ k=1

9yk (dk ^ lk)):

The inductive step, for i +1, is based on the induction hypothesis (for i): Comp(P ) j= Mi8. So that, for part (i) we have that Comp(P ) j= FET [ P 8 [ Mi8. Now, if p2c 2 Mi++1 then, by lemma 27, FET [ P 8 [ Mi8 j= (c ! p)8, and hence, the last formula is also a logical consequence of Comp(P ). For part (ii), if p(x)2c(x) 2 Mi?+1 , then m _ FET [ Mi8 j= 8x(c ! : 9yk (dk ^ lk )) k=1

Then, the last formula is, also, logical consequence of Comp(P ), and therefore Comp(P ) j=

8x(c(x) ! :p(x)).

The \typicity" property of MP is a trivial consequence of the previous lemma:

24

Theorem 38 For any normal program P and any constrained literal l2c: MP j= l2c =) Comp(P ) j= l2c. This property is indeed a consequence of the following well-known result (the original result is due to Kunen and it was adapted to the Constraint Logic Programming framework by Stuckey): Theorem 39 ([27],[37]) Let P be a normal -program and let l2c a constrained literal:

FPH() " k(l2c) = t for some k 2 IN () Comp(P ) j= (c ! l)8.

where H() denotes the Herbrand structure of signature  and FPA is the Stuckey's constrainedbased version of Fitting's operator over a structure A. It provides a good three-valued modeltheoretic justi cation for cutting o , at the ! step, the iteration of the (non continuous) Fitting's operator. Actually, our continuous operator TP ranges over ranked structures, placing information at layers, whereas FPH() obtains information without taking into account the negative dependences, however both operators (by iteration over the empty structure) obtain the same information, although not at the same step. That is, more technically: FPH() " k(p2c) = t for some k 2 IN () p2c 2 (TP " j (?))+i for some i; j 2 IN FPH() " k(:p2c) = t for some k 2 IN () p2c 2 (TP " j (?))?i for some i; j 2 IN The relationship between FPH() and TP is not closer because one step of TP adds (in every layer) all positive logical consequences (of previous layers), but not only the immediate ones, as FPH() does.

5 An speci cation frame for normal logic programs In this section, we show how the model-theoretic semantics de ned in Section 4 can be the basis for de ning a speci cation frame, which has the additional properties of ensuring the existence of compositional and fully abstract semantics for most kinds of modular units. In particular, we prove, as a consequence of these properties, the existence of a compositional and fully abstract semantics for the standard union of normal logic programs.

De nition 40 Let  = (FS; PS) be some pre xed signature. Let NLP be the category of

normal logic programs over , whose objects are the pairs (; ), with  being a set of normal clauses over  and whose morphisms are just inclusions of sets of normal clauses. We de ne the model functor Mod mapping every program P in NLP into the category Mod(P ), whose objects are ranked -structures satisfying P and where a morphism is just the ordering relation between two ranked structures. For every morphism h : P ! P 0 , Vh = Mod(h) is just the identity.

Now, we show that the above de ned pair is, in fact, an speci cation frame.

Lemma 41 NLP  = (NLP; Mod : NLPop ! Cat) is a speci cation frame, i.e. it satis es:

25

(i) NLP has pushouts (ii) Mod transforms pushouts in NLP into pullbacks in Cat. Proof: The pushout of three programs (; 0), (; 1) and (; 2), with 0  1 and 0  2 is just P 1 [ P 2, i.e. (; 1 [ 2).

On the other hand, to show existence of amalgamation, on the current context, is trivial, since A j= P 1 and A j= P 2 =) A j= P 1 [ P 2 is an obvious consequence of de nition 23 (although it does not hold for the simpli cation discussed in remark 24). Therefore Mod(P 1) +Mod(P 0) Mod(P 2) = Mod(P 1) \ Mod(P 2).

Remarks 42 It may be noted that we consider a xed signature for all programs in the speci-

cation frame. The main reason for this is technical, as the below counter-example shows. In particular, in the general case we can not de ne a forgetful functor. It can be argued that this is highly inconvenient with respect to modularity issues, however we do not think that this is important as far as visibility is treated completely at the static semantics level. On the other hand, we believe that this situation is in some sense related with the nature of negation-asfailure where one can always expect to obtain (negative) answers to queries over predicates which are not in the signature of the given program.

Example 43 Let 1 and 2 be two signatures with PS1 = fpg and PS2 = fp; qg. Let A = h(;; fqg); (fpg; fqg)i and B = h(;; ;); (;; ;)i. Then A  B in 2, but B j1 A j1 in Mod(1; ;), where A j1 (resp. B j1 ) is Vi (A) (resp. Vi (B), and Vi is the forgetful functor associated to the inclusion i : (1; ;)  (2; ;). That is, A j1 (resp. B j1) is obtained from A (resp. B) by deleting all atoms including symbols not in 1, which is the most obvious de nition of a forgetful functor in this context.

Before proving further \structural" properties of this speci cation frame we will show that the class of models associated to a given program forms a complete lattice. On the other hand, this result will be used as a lemma for showing the other properties of the speci cation frame.

Lemma 44 For any program P , Mod(P ) is a complete lattice. Proof: In order to show that Mod(P ) is a complete lattice we have to prove that, for each subset S of Mod(P ), we can de ne the join and meet of the models of S , tS and uS . (a) The join C = tS can be de ned as follows: C0+ = fTa2c j FET [ P 8 [ SfA+0 8jA 2 S0g j= (c ! a)8g C0? = fA?0 jA 2 S0g where S0 = S . For all layers i > 0 such that Si = 6 ;: Ci+ = fTa2c j FET [ P 8 [ Ci8?1 [ SfA+i 8jA 2 Si g j= (c ! a)8g Ci? = fA?i jA 2 Sig where Si = Si?1 n fAjAi?1 = 6 Ci?1g If there is k 2 IN such that Sk?1 = 6 ; but Sk = ;, then for all layers i with i  k: 26

Ci+ = fa2c j FET [ P 8 [ Ci8?1 j= (c ! a)8g Ci? = fa2c j For all a : ?l2d 2 P : FET [ Ci8?1 j= ((c ^ d) ! :l)8g.

(b) The meet D = uS is de ned as follows: For all layers i 2 IN such that Ri = 6 ;: T Di+ = SfA+i jA 2 Ri g Di? = fA?i jA 2 Ri g where R0 = S and Ri = Ri?1 n fAjAi?1 6= Di?1g If there exists k 2 IN such that Rk?1 = 6 ;, and Rk = ;, then for all layers i 2 IN such that i  k: Di+ = fa2c j if for every a2d 2 Di? , c ^ d is unsatis ableg Di? = Di??1

(a) First of all, we have to prove the consistency property: Let us suppose that a2c1 2 Ci+ and a2c2 2 Ci? for some i < k, such that c1 ^ c2 is satis able. Let c = c1 ^ c2, then a2c 2 Ci+ \ Ci? because the construction guarantees that layers are closed with respect to less general constraints. If a2c 2 Ci? then a2c 2 A?i for all A 2 Si , what means: FET [ A8i?1 j= (c ^ d) ! :l)8, for all a : ?l2d 2 P . But Ai?1 = Ci?1 holds for all A 2 Si . Then, by monotonicity: FET [ Ci8?1 [ SfA+i 8jA 2 Si g j= ((c ^ d) ! :l)8, for all a : ?l2d 2 P , contradicting a2c 2 Ci+ , because (c ! a)8 can never be a consequence of FET [ P 8 [ Ci8?1 [ S +8 fAi jA 2 Sig. The consistency property is guaranteed for all layers i  k because they are just an \if and only if" version of the satisfaction condition in de nition 23. In order to prove that C is a model of P , it suces to note that Ci+ , for any layer i, contains all the positive information that is supported as logical consequence of the previous layers, and that Ci? only contains supported negative information in the same sense. Finally, we prove that C is the least model which is greater than every model in S . The construction of C implies that for each model A 2 S , it holds either A 2 Si?1 n Si, for some i 2 IN , implying A+i?1  Ci+?1 and A?i?1  Ci??1 and Ai?1 6= Ci?1 and Aj = Ci?1 for all j < i ? 1; or A 2 Si, for all i 2 IN , but in this case the de nition ensures A+i  Ci+ and A?i  Ci? , for each i. Hence, A  C . In order to prove that C is the least model satisfying A  C for all A 2 S , let us suppose that B is a model satisfying A  B for all A 2 S . First, it may be noted that, according to the de nition of C , if the given k does not exist then, for every layer i, there is an A 2 S such that for each j , 0  j < i, Aj = Cj . Then, for every i, Ci+  Bi+ and Ci?  Bi? . Hence B  C . If the given k exists then, similarly, there is an A 2 S such that for each j , 0  j < k, Aj = Cj . Therefore, for every j , 0  j < k, Cj+  Bj+ and Cj?  Bj? . On the other hand, the construction of C ensures that for all layers i  k, Ci contains the least positive information and the greatest negative information supported by the previous layers. This means that also for each i  k, Ci+  Bi+ and Ci?  Bi? . (b) In this case, the consistency of D is a trivial consequence of the consistency of the models in S . Let us prove that D is a model of P . Firstly, suppose that +8 8 FET [ P 8 [ Di?8 ?1 [ Di j= (c ! a) where i < k, if k exists, and i 2 IN is arbitrary, otherwise. We know that all A 2 Ri satis es: A+i  Di+ and A?i?1 = Di??1 so, by monotonicity

27

+8 8 FET [ P 8 [ A?8 i?1 [ Ai j= (c ! a) . This means a2c 2 A+i for all A 2 Ri , so a2c 2 Di+ . Now, suppose that a2c 2 Di? for any i (i < k if the given k exists). Then, a2c 2 A?i for some A 2 Ri, and FET [ Di8?1 j= ((c ^ d) ! :l)8 for all a : ?l2d 2 P , because every A 2 Ri satis es A+i?1 = Di+?1 and A?i?1 = Di??1. If there exists the given layer k then, for any layer Di with i  k, the satisfaction condition trivially holds, since they contain

more positive information than what is supported by the previous layers, but just the negative information from Di?1 . It is not dicult to seeTthat D is the greatest model which is smaller than Tall models in S , because itSis trivial that fA+i jA 2 Ri g is the greatest setSsuch that Bi+  fA+i jA 2 Ri g, and that f(A?i )jA 2 Ri g is the least set such that Bk+  f(A?i )jA 2 Ri g for all B 2 S . If there exists the given layer k then Di , for each i  k, contains the greatest positive information and the least negative information supported by the previous layers. The following example gives some hints about the constructions in the previous proof.

Example 45 Let the program P = fp : ?qg, the symbols PS = fp; q; r; sg and the following structures2 : A1 = h(fpg; ;); (fpg; ;)i A2 = h(fpg; fqg); (fpg; fqg)i A3 = h(fpg; ;); (fp; rg; ;)i A4 = h(;; fqg); (;; fqg)i A5 = h(;; fqg); (fpg; fq; rg)i Then, A1 t A2 t A3 = h(fpg; ;); (fp; rg; ;)i A1 u A4 u A5 = h(;; fqg); (;; fq; rg); (fp; sg; fq; rg)i.

Now, using the previous lemma we can prove that NLP  satis es all the properties needed for giving adequate compositional semantics to the intended program units.

Theorem 46 (Properties of NLP  ) NLP  has free constructions, free extensions and

generalized free extensions.

Proof: NLP  has free constructions, since given a morphism h : P ! P 0 , with P = (; C ) and P 0 = (; C 0), the free construction Fh : Mod(P ) ! Mod(P 0) is de ned for every A in Mod(P ) as C = Fh (A) such that:  C0+ = fa2c j FET [ P 8 [ A+0 8 j= (c ! a)8g C0? = A?0 \ M0?  For all layers i > 0 such that Ai?1 = Ci?1: Ci+ = fa2c j FET [ P 8 [ Ci8?1 [ A+i 8 j= (c ! a)8g Ci? = A?i \ Mi?  If there exists k 2 IN such that Ak?1 =6 Ck?1, then for all layers i with i  k: Ci+ = fa2c j FET [ P 08 [ Ci8?1 j= (c ! a)8g Ci? = fa2c j For all a : ?l2d 2 P : FET [ Ci8?1 j= ((c ^ d) ! :l)8g. 2

if we just write n layers, it must be assumed that the following layers are equal to the nth layer

28

Note that if A 2 Mod(P 0 ), then the above construction coincides with the de nition of the join model in lemma 44, for the particular case when S = fA; MP 0 g, that is tfA; MP 0 g. Nevertheless, it is quite easy to see that even in this case, the result is the least model of P 0 greater than A. The reason is that the de nition guarantees that, at any layer i (i < k if k exist), Ci+ contains the least positive information supported by the previous layers and A+i , and Ci? contains the greatest negative information supported by the previous layers which belongs to A?i . When k exists, Ci, for all layers i  k, contains the least positive information and the greatest negative information supported by the previous layers. Now, we have to prove that Fh (A) satis es the universal property of free constructions: for each model A0 in Mod(P 0 ), such that A  Vh (A0 )(= A0 ), it holds that tfA; MP 0 g  A0 . This property holds by de nition of the join operation t. NLP  has free extensions since it has amalgamations. To see that NLP  has generalized free extensions, according to theorem 11, it is enough to prove that for every program P , there are pushouts in Mod(P ). Given models A0,A1,A2 in Mod(P), with f 1 : A0  A1 and f 2 : A0  A2, the pushout A3 of A1 and A2 via f 1 and f 2 must be the least model greater than A1 and A2, thus again A3 is just the join A1 t A2. Once proved the needed properties of NLP we can provide a categorical semantics for programs fragments which is compositional with respect to standard union. The compositionality result is just a consequence of theorem 15. However, as we can see below, full abstraction is not a direct consequence of theorem 18. Nevertheless, in this case we were also able to prove full abstraction making use of the speci c properties of our semantics.

Theorem 47 (Compositionality) For any normal logic program P , the semantics Sem(P ) = F such that F is the free construction associated to the inclusion (; ;)  P , is compositional

with respect to the standard union of programs.

Proof: Is a direct consequence of theorems 15 and 46. Let us now see a counter-example showing that NLP is not algebraic: Example 48 The model A = h(;; ;); (fqg; ;); : : :i can never be a least model of any normal logic program. In particular in A, the fact q is not supported by the previous layer. Nevertheless, as said above, we can still prove full abstraction using the speci c properties of our semantic constructions.

Theorem 49 (Full Abstraction) Given two normal programs P 1 and P 2, the following three facts are equivalent: (i) Sem(P 1) = Sem(P 2) (ii) For every program P , Sem(P [ P 1) = Sem(P [ P 2) (iii) For every program P , MP [P 1 = MP [P 2.

Proof: It is enough to prove that (iii) implies (i), because the other implications are direct

consequences of lemma 16 and theorem 46. Let us suppose that there exists a model A in Mod(; ;) such that F 1(A) 6= F 2(A), where F 1 = Sem(P 1) and F 2 = Sem(P 2). Then, we will show that there exists a program P such that MP [P 1 6= MP [P 2. Let j 2 IN be the least layer such that F 1(A)+j 6= F 2(A)+j

29

or F 1(A)?j 6= F 2(A)?j . Then we can consider two cases. First, if there exists the given level k 2 IN , and F 1(A)+j 6= F 2(A)+j , for some j < k, then F 1(B) 6= F 2(B) for all models B 2 Mod(; ;) such that A+j = Bi+ and A?j?1 = Bi??1 for some layer i. This is the case for the model B such that, for all i 2 IN : Bi+ = A+j Bi? = A?j?1 In any other case, F 1(B) 6= F 2(B) for all models B 2 Mod(; ;) such that Bi = F 1(A)j ?1 = F 2(A)j?1 for some layer i. Now, we choose the model B such that, for all i 2 IN : Bi+ = F 1(A)+j?1 = F 2(A)+j?1 Bi? = F 1(A)?j?1 = F 2(A)?j?1 It is easy to see that, in both cases, B = MP , for P being the program: P = (; Bi+8 [ fa : ?a2d=a2c 2 Bi? and c ^ d is unsatis ableg), Hence, we can conclude that F 1(MP [P ) = MP [P 1 6= MP [P 2 = F 2(MP [P ).

6 Conclusions and related work We have presented a new monotonic semantic framework for normal logic programs. The main characteristics of this semantics are the following ones: We do not consider any restrictions on programs (e.g. strati cation). We associate to every program a class of models which forms a complete lattice whose least element is shown to be typical for the class of models of the Clark-Kunen's completion of the program. As a consequence, this least model can be seen as the standard semantics of the given program. Finally, the models of a program are a special case of Beth structures, where the ordering relating the \worlds" of the structure is total. Actually, our semantics could have been de ned, without any problem, in terms of general Beth structures. In this sense, we believe that our semantics could also be valuable for knowledge representation considering the intuition behind Beth (and also Kripke) structures where each world in a model represents the knowledge one has at a given moment (see e.g. [38]). The motivation for this new semantics was the de nition of a \speci cation frame" of normal logic programs that could be used for de ning compositional semantics to a variety of program units. In this sense, we have shown that the proposed semantics de nes indeed a speci cation frame with the required properties. In particular, we have provided a categorical semantics for arbitrary program fragments which is compositional and fully abstract with respect to standard program union. Actually, other kind of units and composition operations can be seen just as a special case. The kind of compositionality results obtained are quite more powerful than the results presented in [18, 20, 29, 40, 9]. In [18, 20, 29] di erent semantic de nitions are provided for certain kinds of modular units which are shown to be compositional. However, they all impose (at least) the restriction (not needed in our work) that, for putting together (through the corresponding composition operation) two units, the sets of predicates de ned in each unit must be disjoint. This means that, there can not be clauses de ning the same predicate p (i.e. having p in the head of a clause) in both units. This restriction hinders the application of those results to approaches where the given system of modules supports the incremental de nition of predicates through some form of inheritance (e.g. [6]). In [40] a slightly more general framework is considered. In particular they study open programs where the open predicates

30

can be axiomatized by arbitrary rst order axioms. They provide a semantic de nition based on well-founded semantics and show its compositionality under certain sucient conditions which are quite close to the restrictions imposed in [18]. Finally, [9] prove that Fittings's immediate consequence operator can be used for de ning a semantics for arbitrary program fragments which is compositional with respect to union, intersection and ltering. The main problem here is that, if only union is considered, the given semantics is too abstract to be of any use. We have not directly related our approach with other kinds of semantics, although the relation established with completion implies, by transitivity, that our semantics can be considered equivalent to constructive negation approaches as [14, 37]. Actually, the relation to [14] is quite more direct, in the sense that the construction of our least model is closely related to ranked resolution as de ned there. There is also a certain relation between the construction of our least model and Fitting's x point semantics [21], or rather with the version de ned in [19], although not as close as it may seem: notice that in each \layer" of our least model we add not just the immediate consequences of the previous layer, but all logical consequences.

Acknowledgments

This work has been partially supported by the Spanish CICYT project COSMOS (ref. TIC951016-C02-01) and the UPV-project 141.226-EA209/94 TIC.

References 1. Apt, K. R., Logic Programming, in: Handbook of Theoretical Computer Science, Vol B: Formal Models and Semantics, Chapter 10, Elsevier, 1990. 2. Apt, K. R., Blair, H., Walker, A., Towards a theory of declarative Knowledge, in: Minker, J. (ed), Foundations of Deductive Databases and Logic Programs, Morgan Kaufmann, Los Altos, CA, 1988. 3. Apt, K. R., Bol, R. N., Logic Programming and Negation: A Survey, The Journal of Logic Programming 19:9-71 (1994). 4. Barr, M., Wells, C., Category Theory for Computing Science, Prentice Hall, 1990. 5. Bonner, A. J., McCarty, L. T., Adding Negation-as-Failure to Intuitionistic Logic Programming, in: Proc. of NACLP'90, 1990. 6. Bossi, A., Bugliesi, M., Gabbrielli, M., Levi, G., Meo, M. C., Di erential Logic Programming, in: Proc. ACM SIGPLAN-SIGACT Symp. on Princ. of Programming Languages POPL'93, ACM, 1993. 7. Bossi, A., Gabrielli, M., Levi, G., Meo, M. C., Contributions to the Semantics of Open Logics Programs, in: Proc. 5th Gen. Comp. Systems (1992). 8. Bruscoli, P., Levi, F., Levi, G., Meo, M. C., Compilative Constructive Negation in Constraint Logic Programs, in: Tison, S. (ed.), Proc. of CAAP'94, LNCS, Springer-Verlag, 1994. 9. Brogi, A., Contiero, S., Turini, F. Programming by combining general logic programs, Technical Report 97/02, Dept. of Comp. Science, Univ. of Pisa (1997). 10. Brogi, A., Lamma, E., Mello, P., Compositional model-theoretic semantics for logic programs, New Generation Computing 11:1-21 (1992).

31

11. Burstall, R.M., Goguen, J.A., The semantics of Clear, a speci cation language, in: Proc. Copenhagen Winter School on Abstract Software Speci cation, Springer LNCS 86:292-332, 1980. 12. Chang, D., Constructive negation based on the completed database, in: Kowalski, R. A., Bowen, K. A. (eds.), Proc. 5th Int. Conf. and Symp. on Logic Programmming, The MIT Press, 1988. 13. Clark, K. L., Negation as failure, in: Gallaire, H., Minker, J. (eds), Logic and Databases, Plenum, 1978. 14. Drabent, W., What is failure? An approach to constructive negation, Acta Informatica 32:27-59 (1995). 15. Ehrig, H., Baldamus, M., Orejas, F., New concepts for amalgamation and extension in the framework of speci cation logics, in: Current Trends in Theoretical Computer Science Rozenberg, G., Salomaa, A. (eds.), Word Scienti c (1993). 16. Ehrig, H., Mahr, B., Fundamentals of Algebraic Speci cation 1, Springer-Verlag, 1985. 17. Ehrig, H., Pepper, P., Orejas, F., On Recent Trends in Algebraic Speci cations, in: Proc. ICALP'89, LNCS 372, Springer-Verlag, 1989. 18. Etalle, S., Teusink, F., A compositional semantics for normal open programs, in: Proc. Int. Conf. and Symp. on Logic Programming'96, The MIT Press, 1996. 19. Fages, F., Constructive negation by pruning, The Journal of Logic Programming 32:85-11 (1997). 20. Ferrand, G., Lallouet, A., A compositional proof method of partial correctness for normal logic programs, in Proc. Int. Logic Programming Symp., Lloyd, J. (ed.), 1995. 21. Fitting, M., A Kripke-Kleene Semantics for Logic Programs, The Journal of Logic Programming, 4:295-312 (1985). 22. Fitting, M., Partial Models and Logic Programming, Theoretical Computer Science 48:229-255 (1986). 23. Gaifman, H., Shapiro, E., Fully abstract compositional semantics for logic programs, in: Proc. Sixteenth Annual ACM Symp. on Principles of Programming Languages, 1989. 24. Goguen, J. A., Burstall, R. M., Introducing institutions, in: Proc. Logics of Programming Workshop, Carnegie-Mellon. Springer-Verlag, LNCS 164, 1984. 25. Goguen, J. A., Burstall, R. M., Institution: Abstract model theory for speci cation and programming, Journal of the ACM 39:95-146 (1992). 26. Kleene, S. C., Introduction to Metamathematics . North-Holland, 1952. 27. Kunen, K., Negation in Logic Programming, The Journal of Logic Programming 4:289-308 (1987). 28. Lloyd, J. W., Foundations of Logic Programming, Springer-Verlag, 1987. 29. Maher, M., A logic programming view of CLP, in: Warren, D. S. (ed) Proc. 10th Int. Conf. on Logic Programming, 1993. 30. Miller, D., A Logical Analysis of Modules in Logic Programming, The Journal of Logic Programming 6:79-108 (1989).

32

31. Orejas, F., Pino, E., Ehrig, H., Institutions for Logic Programmming, Theoretical Computer Science 173:485-511 (1997). 32. Przymusinski, T. C., On the declarative semantics of strati ed deductive databases and logic programs, in: Minker, J. (ed), Foundations of Deductive Databases and Logic Programs, Morgan Kaufmann, Los Altos, CA, 1988. 33. Shepherdson, J. C., Negation as Failure II, The Journal of Logic Programming 3:185-202 (1985). 34. Shepherdson, J. C., Negation in Logic Programming, in: Minker, J. (ed), Foundations of Deductive Databases and Logic Programs, Morgan Kaufmann, Los Altos, CA, 1988. 35. Shepherdson, J. C., A sound and complete semantics for a version of negation as failure, Theoretical Computer Science 65:343-371 (1989). 36. Shepherdson, J. C., SLDNF-Resolution with Equality, Journal of Automated Reasoning 8:297-306 (1992). 37. Stuckey, P. J., Negation and Constraint Logic Programmming, Information and Computation 118:12-23 (1995). 38. van Dalen, D., Intuitionistic Logic, in: Gabbay, D., Guenthner, F. (eds), Handbook of Philosophical Logic Vol III, 1986. 39. van Gelder, A., Negation as failure using tight derivations for general logic programs, in: Minker, J. (ed), Foundations of Deductive Databases and Logic Programs, Morgan Kaufmann, Los Altos, CA, 1988. 40. Verbaeten, S., Denecker, M., De Schreye, D., Compositionality of normal open logic programs, to appear in: Proc. of ILPS'97, 1997. 41. Wirsing, M., Algebraic Speci cation, in: Handbook of Theoretical Computer Science, Vol B: Formal Models and Semantics, Elsevier, 1990. 42. You, J.-H., Yuan, L. Y., A Three-Valued Semantics for Deductive Database and Logic Programs, Journal of Computer and Systems Sciences 49:334-361 (1994). 43. You, J.-H., Yuan, L. Y., On the equivalence of semantics for normal logic programs, The Journal of Logic Programming 22:211-222 (1995).

33