<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Implementing the p-stable semantics</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Angel Mar n George</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Claudia Zepeda Cortes</string-name>
          <email>czepedac@gmail.com</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Benemerita Universidad Autonoma de Puebla, Facultad de Ciencias de la Computacion</institution>
        </aff>
      </contrib-group>
      <abstract>
        <p>In this paper we review some theoretical results about the p-stable semantics, and based on that, we design some algorithms that search for the p-stable models of a normal program. An important point is that some of these algorithms can also be used to compute the strati ed minimal models of a normal program.</p>
      </abstract>
      <kwd-group>
        <kwd>non-monotonic reasoning</kwd>
        <kwd>p-stable</kwd>
        <kwd>strati ed minimal model</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction</title>
      <p>
        Currently, is a promising approach to model features of commonsense reasoning.
In order to formalize NMR the research community has applied monotonic logics.
In [
        <xref ref-type="bibr" rid="ref6">7</xref>
        ], Gelfond and Lifschitz de ned the stable model semantics by means of an
easy transformation. The stable semantics has been successfully used in the
modeling of non-monotonic reasoning (NMR). Additionally, Pearce presented a
characterization of the stable model semantics in terms of a collection of logics in
[
        <xref ref-type="bibr" rid="ref19">20</xref>
        ]. He proved that a formula is \entailed by a disjunctive program in the stable
model semantics if and only if it belongs to every intuitionistically complete and
consistent extension of the program formed by adding only negated atoms". He
also showed that in place of intuitionistic logic, any proper intermediate logic
can be used. The construction used by Pearce is called a weak completion.
      </p>
      <p>
        In [
        <xref ref-type="bibr" rid="ref13">14</xref>
        ], a new semantics for normal programs based on weak completions
is de ned with a three valued logic called G03 logic. The authors call it the
Pstable semantics. In [
        <xref ref-type="bibr" rid="ref11">12</xref>
        ], the authors de ne the p-stable semantics for disjunctive
programs by means of a transformation similar to the one used by Gelfond and
Lifschitz in their de nition of the stable semantics. The authors also prove that
the p-stable semantics for disjunctive programs can be characterized by means of
a concept called weak completions and the G03 logic, with the same two conditions
used by Pearce to characterize the stable semantics of disjunctive programs, that
is to say, for normal programs it coincides with the semantics de ned in [
        <xref ref-type="bibr" rid="ref13">14</xref>
        ].
In fact, a family of paraconsistent logics studied in [
        <xref ref-type="bibr" rid="ref11">12</xref>
        ] can be used in this
characterization of the p-stable semantics.
      </p>
      <p>
        In [
        <xref ref-type="bibr" rid="ref12">13</xref>
        ], the authors o er an axiomatization of the G03 logic along with a
soundness and completeness theorem, i.e., every theorem is a tautology and
vice-versa. We also remark that the authors of [
        <xref ref-type="bibr" rid="ref11">12</xref>
        ] present some results that
give conditions under which the concepts of stable and p-stable models agree.
They present a translation of a disjunctive program D into a normal program N ,
such that the p-stable model semantics of N corresponds to the stable semantics
of D when restricted to the common language of the theories. Besides, they show
that if the size of the program D is n then the size of the program N is bounded
by An2 for a constant A. The relevance of this last result is that it shows that the
p-stable model semantics for normal programs is powerful enough to express any
problem that can be expressed with the stable model semantics for disjunctive
programs.
      </p>
      <p>
        One major recent result of the p-stable semantics is in the context of
argumentation theory [
        <xref ref-type="bibr" rid="ref5">6</xref>
        ], which explores ways to carry out into the theory of
computation the mechanisms humans use in argumentation. The three major semantics
of argumentation theory (grounded, stable, and preferred) can be characterized
in terms of three logic programming semantics: the well founded semantics [
        <xref ref-type="bibr" rid="ref21">22</xref>
        ],
the stable semantics [
        <xref ref-type="bibr" rid="ref6">7</xref>
        ] and the p-stable semantics, respectively in terms of a
unique normal logic program P , that is constructed only in terms of the
argumentation framework AF [
        <xref ref-type="bibr" rid="ref2">3</xref>
        ]. Argumentation theory does not depend on a
particular semantics. Then, if we want to obtain the stable semantics of AF , we
compute the stable semantics of logic programming over PAF . If, on the other
hand, we want to obtain the preferred semantics of AF , we compute the p-stable
semantics over PAF . Moreover, if we want to obtain the grounded semantics of
AF , we compute the well founded semantics over PAF .
      </p>
      <p>
        There are also initial work about other two approaches for knowledge
representation based on the p-stable semantics: updates, and preferences. In case
intelligent agents get new knowledge and this knowledge must be added or
updated to their knowledge base, it is important to avoid inconsistencies. An
update semantics for update sequences of programs based on p-stable semantics is
proposed in [
        <xref ref-type="bibr" rid="ref14">15</xref>
        ]. The concept of preferences is considered a vital component of
reasoning with real-world knowledge. In [
        <xref ref-type="bibr" rid="ref15">16</xref>
        ], the authors introduce preference
rules which allow us to specify preferences as an ordering among the possible
solutions of a problem. Their approach allow us to express preferences for
arbitrary programs. They also de ne a semantics for those programs. The formalism
used to develop their work is p-stable semantics.
      </p>
      <p>It is important to mention that the p-stable semantics, which can be
dened in terms of paraconsistent logics, shares several properties with the stable
semantics, but is closer to classical logic. For example, the following program
P = fa :b; a b; b ag does not have stable models. However, the set
fa; bg could be considered the intended model for P in classical logic. In fact, it
is the only p-stable model of P .</p>
      <p>
        In [
        <xref ref-type="bibr" rid="ref17">18</xref>
        ], a schema for the implementation of the p-stable semantic using two
well known open source tools: Lparse and Minisat is described. In [
        <xref ref-type="bibr" rid="ref17">18</xref>
        ], a
prototype1 written in Java of a tool based on that schema is also presented. In
this paper we present an implementation of the p-stable semantics
implementation with aim to improve the implementation presented in [
        <xref ref-type="bibr" rid="ref17">18</xref>
        ], considerable
e ort has been made in the optimization the code and in the design of the
algorithms used, which are theoretically more e cient than those used in [
        <xref ref-type="bibr" rid="ref17">18</xref>
        ]. As
this implementation started recently, we have not yet made de nitive tests to
warrantee that the solver is error-free, nor we can give conclusive comparative
tests between our implementation and that on [
        <xref ref-type="bibr" rid="ref17">18</xref>
        ].
      </p>
      <p>In the section 2 the basic concepts about the p-stable semantics are
introduced, specially the transformations. In the section 3 are presented the
algorithms used to apply the transformations. In the section 4 and 5 is explained
how to construct the graph of dependencies of the program and how this graph
is used to reduce the search space when looking for the p-stable models.
2</p>
    </sec>
    <sec id="sec-2">
      <title>Background</title>
      <p>2.1</p>
      <sec id="sec-2-1">
        <title>Syntax</title>
        <p>In this section, we de ne some basic concepts in terms of logic programming
semantics, including the de nitions of the transformations, which are used to
simplify a program.</p>
        <p>A signature L is a nite set of elements that we call atoms. A literal is either
an atom a, called positive literal, or the negation of an atom :a, called negative
literal. Given a set of atoms fa1; :::; ang, we write :fa1; :::; ang to denote the set
of atoms f:a1; :::; :ang. A normal clause or normal rule, r, is a clause of the
form
a</p>
        <p>b1; : : : ; bn; :bn+1; : : : ; :bn+m:
where a and each of the bi are atoms for 1 i n + m, and the commas mean
logical conjunction. In a slight abuse of notation we will denote such a clause by
the formula a B+(r) [ :B (r) where the set fb1; : : : ; bng will be denoted by
B+(r), the set fbn+1; : : : ; bn+mg will be denoted by B (r), and B+(r) [ B (r)
denoted by B(r). We use H(r) to denote a, called the head of r. We de ne a
normal program P , as a nite set of normal clauses. If for a normal clause r,
B(r) = ;, H(r) is known as a fact . We write LP , to denote the set of atoms
that appear in the clauses of P .
2.2</p>
      </sec>
      <sec id="sec-2-2">
        <title>Semantics</title>
        <p>
          From now on, we assume that the reader is familiar with the single notion of
minimal model [
          <xref ref-type="bibr" rid="ref7">8</xref>
          ]. In order to illustrate this basic notion, let P be the normal
program fa :b:; b :a:; a :c:; c :a:g. As we can see, P has
ve models: fag, fb; cg, fa; cg, fa; bg, fa; b; cg; however, P has just two minimal
models: fb; cg, f g
        </p>
        <p>a . We will denote by M M (P ) the set of all the minimal models
of a given logic program P . Usually M M is called minimal model semantics.</p>
        <p>
          Now we give the de nition of p-stable model semantics for normal programs.
De nition 1. [
          <xref ref-type="bibr" rid="ref18">19</xref>
          ] Let P be a normal program and M be a set of atoms. We
de ne the reduction of P with respect to M as RED(P; M ) = fa B+ [:(B \
M )ja B+ [ :B 2 P g.
        </p>
        <p>
          De nition 2. [
          <xref ref-type="bibr" rid="ref18">19</xref>
          ] A set of atoms M is a p-stable model of a normal program
P i RED(P; M ) j= M , where the symbol j= means logical consequence under
classical logic semantics. The set of p-stable models of P is denoted by P S(P ).
        </p>
        <p>
          We say that two normal programs P and P 0 are equivalent if and only if they
have the same set of p-stable models, this relation is denoted by P P 0. An
important theorem relating the p-stable and minimal models is the following.
Theorem 1. [
          <xref ref-type="bibr" rid="ref13">14</xref>
          ] Let P be a normal program. If M
MM(P ).
2 P S(P ) then M 2
        </p>
      </sec>
      <sec id="sec-2-3">
        <title>2.3 Transformations preserving equivalence</title>
        <p>
          The main purpose of the transformations presented in this section is to simplify
the input normal program, reducing its size. What allows the use of those
transformations under the p-stable semantics are the propositions proved in [
          <xref ref-type="bibr" rid="ref16 ref3">17, 4</xref>
          ]
about equivalence of normal programs under these transformations. Let P be a
normal program, the de nition of the transformations SUB, TAUT, RED ,
RED+, SUCC, LOOP, NAF and EQUIV when applied to P is as follows
1. SUB(P ) = P n fr0g () r0 2 P , 9r00 2 P : r0 6= r00; B (r00) B (r0); B+(r00)
        </p>
        <p>B+(r0); H(r) = H(r0).
2. TAUT(P ) = P n fr0g () r0 2 P , H(r0) 2 B+(r0).
3. EQUIV(P ) = (P n fr0g) [ frg () r0 2 P; H(r0) 2 B (r0); B (r) = B (r0) n
fH(r0)g; B+(r) = B+(r0); H(r) = H(r0).
4. SUCC(P ) = (P n fr0g) [ frg () r0 2 P; B (r) = B (r0); H(r) = H(r0); 9r00 2</p>
        <p>P : B(r00) = ;; H(r00) 2 B+(r0); B+(r) = B+(r0) n fH(r00)g.
5. RED+(P ) = (P n fr0g) [ frg () r0 2 P; B+(r) = B+(r0); H(r) = H(r0); 9a 2</p>
        <p>LP : a 2 B (r0); B (r) = B (r0) n fag; 6 9r00 2 P : H(r00) = a:
6. RED (P ) = P n fr0g () r0 2 P; 9r00 2 P : B(r00) = ;; H(r00) 2 B (r0).
7. NAF(P ) = P n fr0g () r0 2 P; 9a 2 LP : a 2 B+(r0); 6 9r00 2 P : H(r00) = a.
8. LOOP(P ) = fr0 : r0 2 P; B+(r0) M g, where M is the unique minimal model of
MM(POS(P )). The de nition of POS(P ) is given by</p>
        <p>
          POS(P ) = fr0 : B (r0) = ;, 9r 2 P : B+(r) = B+(r0); H(r) = H(r0)g.
Proposition 1. [
          <xref ref-type="bibr" rid="ref16 ref3">17, 4</xref>
          ] Let P be a normal program, and let P 0 be the resulting
program from the application to P of any of the transformations SUB, TAUT,
EQUIV, SUCC, RED+, RED , NAF or LOOP. Then P P 0.
3
        </p>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>Computing the p-stable models</title>
      <p>Now we present the implementation of a p-stable model solver. To nd the
p-stable models of a program P we can rst apply the transformations to P ,
however the application of the transformations is not absolutely necessary nor
su cient to nd the p-stable models of P . In this section we start presenting the
implementation of the application of the transformations, and then we give three
approaches to nd the p-stable models of P , one that follows from the theorem
1, and the others from the theorem 2 which is also presented in this section.</p>
      <sec id="sec-3-1">
        <title>Implementing the transformations</title>
        <p>Given a program P as input to the p-stable solver, we associate to each atom
a 2 LP three sets that are used for the application of the transformations, those
sets are initialized as follows,
1. H(a) = fr : r 2 P; H(r) = ag.
2. P (a) = fr : a 2 P; B+(r)g.
3. N (a) = fr : a 2 P; B (r)g.</p>
        <p>With the information in those sets it is e cient the application of some
transformations, because it is avoided the use of a search algorithm, for example, it
will not be necessary to search through all the program P when we require all
the rules whose head is a particular atom a. Each atom a 2 LP also has
associated a variable state(a), which can hold one of the following values (we refer
to this variable as the state of a): if state(a) = state f act then a is a fact, if
state(a) = state no f act then a can not be a fact, if state undef ined then we
can not tell yet if a is or can not be a fact.</p>
        <p>
          The application of the transformations TAUT and EQUIV is easily
implemented, and in this paper we do not write the algorithms that apply those
transformations. The transformations SUCC, RED+, RED , NAF and a
particular case of SUB are applied iteratively by the algorithm
transf ormations iterated(:::). This particular version of SUB consists in
deleting the rules whose head is a fact. For the general case of SUB it is necessary
to check for set inclusion between the bodies of all pairs of rules with the same
head, some of our experimental implementations showed that it was very
ine cient and in most cases only a few rules were deleted. The LOOP
transform was implemented using the Dowling-Gallier algorithm [
          <xref ref-type="bibr" rid="ref4">5</xref>
          ] (which nds the
unique minimal model of a positive program in linear time) it is presented in the
LOOP (:::) algorithm. Also a watched variables scheme[
          <xref ref-type="bibr" rid="ref8">9</xref>
          ] might be used, this
technique is e ective in some cases when the deletion of atoms from rules needs
to be continuously undone, but at this stage we do not need undo any changes.
        </p>
        <p>For the algorithm transf ormations iterated(:::) we need two lists (see the
algorithm at the end of the paper), they are Lp and Lf , which have to be
initialized before calling to transf ormations iterated(:::). Lp is initialized with the
atoms that are facts, then for all a 2 Lp it is assigned state(a) = state f act. Lf
initialized with the atoms a such that there is no rule with head a, then for all
a 2 Lf it is assigned state(a) = state no f act. In transf ormations iterated(:::)
the auxiliary algorithms remove rule(r) and remove atom f rom rule(a; r; B)
are used. remove rule(r) removes the rule r and if all the rules with head
H(r) have been removed, set state(H(r)) = state no f act and add a to Lf .
remove atom f rom rule(a; r; B) removes the atom a from B, where B = B+(r)
or B = B (r), if after removing a from B, jBj = 0, then set state(H(r)) =
state f act and add a to Lp</p>
        <p>In the next example we illustrate how the algorithm transf ormations iterated(:::)
behaves with the program P as input
Example 1. Example of the execution of transf ormations iterated
P =f 1 =f
r1 : u not v: r1 : u not v:
r2 : v not u: r2 : v not u:
r3 : u not r; not x; b: r3 : u not r; not x; b:
r4 : x y; r; not c: r4 : x y; r; not c:
r5 : y not x; z; not v: r5 : y not x; z; not v:
r6 : x not z; t; not d: r6 : x not z; t; not d:
r7 : z t; v: r7 : z t; v:
r8 : z r; not u; not x: r8 : z r; not u; not x:
r9 : r not t; not a: r9 : r not t; not a:
r10 : t not r; b: r10 : t not r; b:
r11 : a not a; c: r11 : a c:
r12 : b not d: r12 : b not d:
r13 : d c; d: r14 : c not a; b; d; z:
r14 : c not a; b; d; z: r15 : c not b; a; x:
r15 : c not b; a; x: r16 : b not a; not u:g
r16 : b not a; not u:g Lp = fg, Lf = fdg.</p>
        <p>2 =f
r1 : u not v:
r2 : v not u:
r3 : u not r; not x; b:
r4 : x y; r; not c:
r5 : y not x; z; not v:
r6 : x not z; t:
r7 : z t; v:
r8 : z r; not u; not x:
r9 : r not t; not a:
r10 : t not r; b:
r11 : a c:
r12 : b :
r15 : c not b; a; x:
r16 : b not a; not u:g
Lp = fbg, Lf = fg.</p>
        <p>3 =f
r1 : u not v:
r2 : v not u:
r3 : u not r; not x:
r4 : x y; r; not c:
r5 : y not x; z; not v:
r6 : x not z; t:
r7 : z t; v:
r8 : z r; not u; not x:
r9 : r not t; not a:
r10 : t not r:
r11 : a c:g
Lp = fg, Lf = fcg.</p>
        <p>4 =f
r1 : u not v:
r2 : v not u:
r3 : u not r; not x:
r4 : x y; r:
r5 : y not x; z; not v:
r6 : x not z; t:
r7 : z t; v:
r8 : z r; not u; not x:
r9 : r not t; not a:
r10 : t not r:g
Lp = fg, Lf = fag.</p>
        <p>5 =f
r1 : u not v:
r2 : v not u:
r3 : u not r; not x:
r4 : x y; r:
r5 : y not x; z; not v:
r6 : x not z; t:
r7 : z t; v:
r8 : z r; not u; not x:
r9 : r not t:
r10 : t not r:g
Lp = fg, Lf = fg.</p>
        <p>Before starting the transf ormations iterated(:::) algorithm, the EQUIV
and TAUT transformations are applied obtaining 1 (this is an optional step),
also Lp and Lf have to be initialized. Then we call transf ormations iterated( 1).
In the rst iteration d is removed from Lf , we apply NAF and RED+ until d
do not appear in the program, obtaining 2. In the second iteration remove b
from Lp then apply SUB by removing all the rules whose head is b, then SUCC
and RED are applied until b do not appear in the program, obtaining 3. In
the third iteration remove c from Lf , and apply NAF and RED+ until c do
not appear in the program obtaining 4. In the fourth iteration remove a from
Lf , and apply NAF and RED+ until a do not appear in the program obtaining
5. At this point Lp and Lf are empty making the algorithm stop.</p>
        <p>During the execution of transf ormations iterated(P ) have been removed all
the rules whose head is a fact, including the rules r for which B(r) = ;, which
are precisely the rules that indicate that H(r) is a fact, it does not represent
any problem because we can recover the atoms that are facts just by gathering
the atoms whose state is state f act. As the transformations applied preserve
equivalence, P 5 [ fb g, we added the rule b to 5 because state(b) =
state f act. The state of all the atoms that were added to Lp was set to state f act
(in this case fbg), and the state of the atoms that were added to Lf was set to
state no f act (fd; a; cg), it means that b must be in all the p-stable models of P
and fd; a; cg can not be in any.</p>
        <p>It is not hard to see that after the application of this algorithm we can no
longer apply SUCC, RED , RED+ or NAF.
3.2</p>
      </sec>
      <sec id="sec-3-2">
        <title>The graph of dependencies</title>
        <p>In most cases the application of the transformations is not enough to nd a
p-stable model of a normal program, and other techniques are required. One of
those techniques is to partition the program into sets of rules called modules.
Those modules are created based on its graph of dependencies. Before explaining
this technique in detail we give the next de nition
De nition 3. A strongly connected component C of a graph G is a subset of
nodes of G. C is a maximal set of nodes(maximal respect to inclusion) such that
there is a directed cycle in G that contains all the nodes in C.</p>
        <p>When we have the rule ah a1; a2; :::; am; not am+1; not am+2; :::; not an:,
ah is dependent of all the a0is; i = 1:::n, in a graph this dependencies can be
represented with the directed edges (ai; ah); i = 1; :::; n. The graph of dependencies
of a program P represents all the dependencies between the atoms in LP , given
by all the rules of P .</p>
        <p>The following de nition states the de nition of strati cation and module of
a program P .</p>
        <p>De nition 4. Let P be a normal program which can be partitioned into the
disjoint sets of rules fP1; :::; Png. Let Pi; Pj 2 fP1; :::; Png; Pi 6= Pj , we say that
Pi &lt; Pj if 9r 2 Pj : 9r0 2 Pi : H(r0) 2 B(r), if from this condition we do not
conclude that Pi &lt; Pj or Pj &lt; Pi then we can choose to hold whether Pi &lt; Pj or
Pj &lt; Pi as long as the following properties hold. For every X; Y; Z 2 fP1; :::; Png,
the strict partial order relation properties and the totality property hold:
1. X &lt; X is false (this property holds trivially).
2. If X &lt; Y then (Y &lt; X is false).
3. If (X &lt; Y and Y &lt; Z) then X &lt; Z.
4. P1 &lt; ::: &lt; Pn
then we refer to this partition as the strati cation of P , sometimes we will write
it as P = P0 [ ::: [ Pn. And we will refer to Pi; 1 i n as a module of P .</p>
        <p>
          Fortunately we do not have to worry about how to construct this order
because there exists a well known algorithm [
          <xref ref-type="bibr" rid="ref20">21</xref>
          ](that we implemented in the
algorithm getM odules(P )) which obtains a sequence C1; :::; Cn of strongly connected
components of the graph of dependencies of P , from which we can construct a
strati cation of P , P = P1[:::[Pn, where Pi = fr : r 2 P; H(r) 2 Cig; 1 i n.
        </p>
        <p>Now we de ne h(Pi; P )
De nition 5. Let P be a normal program, Ci a strongly connected component
of the graph of dependencies of P , and Pi the module constructed from Ci. We
de ne h(Pi; P ) as the atoms which are represented as nodes in Ci.
3.3</p>
      </sec>
      <sec id="sec-3-3">
        <title>Computing the p-stable models</title>
        <p>The purpose of this section is to show how to compute the p-stable models of
a program, three approaches to nd the p-stable models of a program P are
presented. One way is a direct application of the theorem 1, it consist in
computing the minimal models of P and choosing those which satisfy the de nition
of p-stable model. By theorem 2 the p-stable models of P can be computed
by computing the p-stable models of the modules of P after the application of
certain transformations.</p>
        <p>
          Theorem 2. [
          <xref ref-type="bibr" rid="ref18">19</xref>
          ] Let P be a normal logic program, and M a model of P with
strati cation P = P1 [ P2, then RED(P; M ) j= M i RED(P1; M1) j= M1 and
RED(P20; M2) j= M2 with P 0, M1, and M2 de ned as follows: M = M1 [ M2,
2
M1 = h(P1; P ) \ M , M2 = h(P2; P ) \ M , and P20 is obtained by transforming
P2 as follows:
1. Removing from P2 the rules r0 such that B (r0) \ M1 6= ; or B+(r0) \
(h(P1; P ) n M1) 6= ;, obtaining a new program P 00.
2
2. For every r 2 P200, removing from B(r) the occurrences of the atoms in
h(P1; P ), obtaining P 0.
        </p>
        <p>2</p>
        <p>In other words M is a p-stable model of P i M1 is a p-stable model of P1
and M2 is a p-stable model of P 0, where P20 is obtained by removing from P2
2
the occurrences of the atoms in h(P1; P ) according to the theorem 2. If P can
be strati ed as P = P1 [ ::: [ Pn, n &gt; 2, then P = P1 [ Q with Q = P2 [ ::: [ Pn
is also an strati cation of P that has only two modules, and then we can apply
the theorem 2.</p>
        <p>
          From theorems 1 and 2, three di erent approaches to compute the p-stable
models of a program P are known. The rst approach has been implemented in
[
          <xref ref-type="bibr" rid="ref17">18</xref>
          ]. We propose the other two approaches that reduce the search space respecto
to the rst approach in many practical examples.
1. From theorem 1, it follows that in order to nd the p-stable models of P , we
can generate minimal models M 2 MM(P ) and accept as p-stable models
those for which the consequence test RED(P; M ) j= M is true. To implement
the consequence test we take advantage of the fact that RED(P; M ) j=
M () RED(P; M ) [ f:M g is unsatis able, to test if RED(P; M ) [ f:M g
is unsatis able it is used a SAT solver, in this case we used MINISAT[1], the
consequence test is implemented in the algorithm consequence test(:::)(not
presented here for lack of space). Using this approach the search space to
nd the p-stable models of P is M M (P ). The computation of the p-stable
models following this approach is implemented in new P S(:::).
2. As we have said, if P can be strati ed into n modules P = P1 [ ::: [ Pn,
then P can also be strati ed into two modules P = P1 [ Q, where Q =
P2 [ ::: [ Pn; n &gt; 2, and now we can apply the theorem 2 to nd the
pstable models of P , this approach is based on the fact that Q0 (obtained
from Q according to theorem 2) can be strati ed as Q0 = Q20 [ ::: [ Qn0
where Qi0; 2 i n is obtained by removing from Pi the occurrences of LP1
according to theorem 2. If n &gt; 3, to compute the p-stable models of Q0, we
argument the same way but now instead of P , we have Q0 with strati cation
Q0 = Q20 [ ::: [ Qn0. We can proceed this way whenever we want to compute
the p-stable models of a program strati ed into more than two modules,
when it only has two modules, we just apply the theorem 2. The search
space to nd all the p-stable models of a program P using this approach is
in the worst case M M (P ), but sometime this search space is bigger than in
the third approach. The advantage of this approach over the third approach
is that it is not necessary to compute the strati cation of a module before
computing its p-stable models, we compute only once the strati cation of P .
3. Again following the theorem 2, to compute a p-stable model of P with
strati cation P = P1 [ P2(as we have said a program with n modules can also be
strati ed into two modules), we can compute a p-stable model of P1 and one
p-stable model of P20, and if P20 can be strati ed into P20 = Q1 [ Q2, we can
apply again the theorem and compute the p-stable models of Q1 and Q02.
The di erence with the second approach is that in the second approach the
strati cation is computed only once, and in this approach we compute the
strati cation with getM odules(:::) each time we want to compute a p-stable
model of a module. Using this approach the search space is in many cases
considerably smaller than M M (P ), this is because the problem of nding
the p-stable models of a program is translated into the problem of nding the
p-stable models of many small subprograms, the smaller these subprogram,
more chances are to reduce the search space. We distinguish between nding
the rst and the subsequent p-stable models, to nd the rst p-stable model
use the f irst P S recursive(:::) algorithm and to nd the another p-stable
model use next P S recursive(:::).
        </p>
        <p>We illustrate the second approach by nding the p-stable models of the
program 5 that resulted from the application of the transformations in the example
1. In the graph 1 we see the graph of dependencies of 5, the dotted edges trace
maximal cycles, and determine the strongly connected components of 5.
Based on the graph of dependencies of 5 (graph 1), we see that 5 can be
strati ed into two modules 5 = P1 [ P2. To compute a p-stable model of 5 we
start by nding a p-stable model of P1, in this case we found frg to be a p-stable
model of P1. Then compute P20 by removing the occurrences of the atoms r and
t from P2 according to the theorem 2, in the next gure you can see P1, P2 and
P 0
2
P2 =f P1 =f
r1 : u not v: r9 : r not t:
r2 : v not u: r10 : t not r:g
r3 : u not r; not x: P20 = f
r4 : x y; r: r1 : u not v:
r5 : y not x; z; not v: r2 : v not u:
r6 : x not z; t: r4 : x y:
r7 : z t; v: r5 : y not x; z; not v:
r8 : z r; not u; not x:g r8 : z not u; not x:g</p>
        <p>Then nd a minimal model of P20 and do the consequence test, a
minimal model of P20 is fv; xg, but when doing the consequence test we nd that
RED(P20; fv; xg) [ f:fv; xgg = RED(P20; fv; xg) [ f:v _ :xg is satis able, thus
fv; xg is not a p-stable model of P 0. We generate another minimal model of
2
P 0, fv; zg, this time RED(P20; fv; zg) [ f:v _ :zg is unsatis able and fv; zg is
2
accepted as a p-stable model of P 0. Merging the p-stable model of P1 and the
2
p-stable model of P20 we obtain a p-stable of 5, fr; v; zg. To look for another
p-stable model of 5, we start by looking for another p-stable model of P20, we
nd that fug is a p-stable model of P20, for instance another p-stable model of
5 is fr; ug. Again we try to generate another p-stable model of P20, but we note
that all the p-stable models of P20 have been generated (all M 2 M M (P20) have
been computed), then we go to the anterior module(P1) and try to generate
another p-stable model of P1, we nd that ftg is another p-stable model of P1,
then compute P20 again :
P20 =f
r1 : u
r2 : v
r3 : u
r5 : y
r6 : x
r7 : z
not v:
not u:
not x:
not x; z; not v:
not z:
v:g
We encounter the two p-stable models of P 0, ffx; ug; fx; vgg, from which
2
we nd another two p-stable models of 5, fft; x; ug; ft; x; vgg. When trying to
generate another p-stable model of P20 we can not nd any so we go to P1, and
can not nd another p-stable model of P1 so we stop. We end up with the four
pstable models of 5, PS( 5) = fft; x; ug; ft; x; vg; fr; v; zg; fr; ugg. Recall form
the example 1 that b was found to be a fact after the application of the
transformations to P , for instance PS(P ) = ffb; t; x; ug; fb; t; x; vg; fb; r; v; zg; fb; r; ugg.
y:
not x; z; not v:
not u; not x:g</p>
        <p>Applying again the theorem 2, rst choose a minimal model of Q1, fvg and
when doing the consequence test we nd that fvg is a p-stable model of Q1.
Now obtain Q02 (see the anterior gure) which is further partitioned into Q02 =
R1 [ R2 [ R3 which are respectively the sets of rules with head y, x and z. Then
compute a p-stable model of R1, the only p-stable model of R1 is the empty set,
R20 is also empty and also has an empty p-stable model. R30 (obtained by removing
from R3 the occurrences of LR1 and LR2 ) only has an empty rule z and its
unique p-stable model is fzg. Merging the p-stable model of the modules P1, Q1,
R1, R20 and R30 we get a p-stable model of 5, it is frg [ fvg [ fg [ fg [ fzg =
fr; v; zg. When trying to generate another p-stable model, rst we try to generate
another p-stable model of R30, it does not have more p-stable models, thus we go
back and try on R20 but it has neither, then try on R1 that has no more p-stable
models, nally we nd that Q1 has another p-stable model, fug, from this point,
to nd the other p-stable models of 5, we proceed as we did when we had fvg
as a p-stable model of Q1.</p>
        <p>
          To show the performance of each approach we use some examples in [
          <xref ref-type="bibr" rid="ref1">2</xref>
          ]. In
the next table we can see the time in seconds it took to nd a p-stable model
of some of those examples using each of the three approaches. A "-" character
means that we stopped the execution after 10 seconds. In the fth column is the
time to nd a stable model by smodels. The sixth and seventh columns show
the number of atoms and rules of each test program. In the last column is the
number of modules in which the program was initially partitioned.
        </p>
        <p>problem
blocks world
blocks world variant</p>
        <p>n queens
spanning tree
planning from initial</p>
        <p>weight constraints
planning in observations</p>
        <p>
          It is worth to mention that if we modify the consequence test(:::) such that it
always return true, instead of using tranf ormations iterated(:::) we apply some
similar reductions (see [
          <xref ref-type="bibr" rid="ref9">10</xref>
          ]), and if all the tautological rules like a b; not b; c
are removed, then we end up with a strati ed minimal model solver, a detailed
description of our strati ed minimal model semantics solver can be found in [
          <xref ref-type="bibr" rid="ref9">10</xref>
          ].
4
        </p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>Conclusions and future work</title>
      <p>
        Some preliminary tests to the p-stable solver presented in this paper, shows a bad
performance respect to a stable semantics solver(smodels[
        <xref ref-type="bibr" rid="ref10">11</xref>
        ]), for big programs,
due to the backtracking driven by the failure of the consequence test, one of the
inconveniences of this implementation is that the search space is very big for
some programs, research is needed to develop algorithms that reduce the search
space or heuristics that show a good performance for some classes of programs.
      </p>
      <sec id="sec-4-1">
        <title>Algorithm 1 function getM odules()</title>
        <p>ModuleList modules flist of modulesg
create the graph of dependencies G
numerate the nodes of G according to the DFS exiting time
transpose the graph(compute GT )
Do a DFS(depth rst search), and in the main loop choose the nodes with bigger
exiting time rst.
fEach tree found by the DFS represents a strongly connected componentg
for each strongly connected component c do
create a new module mod
for each atom a in c do</p>
        <p>add to mod all the rules r that H(r) = a
end for
modules.add(mod)
end for
Algorithm 2 function transf ormations iterated(M odule P ))</p>
      </sec>
      <sec id="sec-4-2">
        <title>Algorithm 3 function LOOP(M odule P )</title>
        <p>Algorithm 4 function bool new P S(M odule P )
Algorithm 5 function bool f irst P S recursive(M odule P )
fstratify(P) returns true i P could be strati ed into more than two modules g
fIf P is strati ed into P = P1 [ ::: [ Pn, as the modules Pi are in the list submodules,
head(submodules(P )) = P1, rear(submodules(P )) = Pn, next(Pi) = Pi+1 1 &lt;= i &lt;
n, back(Pi) = Pi 1 1 &lt; i &lt;= n, next(Pn) = back(P1) = N U LLg
if stratif y(P ) then
reductions iterated(P )
set Q = head(submodules(P )) fpicks the rst element of submodules(P )g
if not new P S(Q) then</p>
        <p>return false
end if
set Q = next(Q)
while Q 6= N U LL fvisits all the modules in submodules(P )g do
while not f irst P S recursive(Q) do
fbacktrackingg
if not next P S recursive(back(Q)) then</p>
        <p>return false
end if
end while
set Q = next(Q)
end while
else
if not new P S(P ) then</p>
        <p>return false
end if
end if
return true
Algorithm 6 function bool next P S recursive(P )
repeat
fif P was not divided into more than one modulesg
if jsubmodules(P )j = 0 then
if new P S(P ) then</p>
        <p>return true
end if
else</p>
        <p>Q = rear(submodules(P ))
if next P S recursive(Q) then</p>
        <p>return true
end if
end if
if back(P ) = N U LL or not next P S recursive(back(P )) then</p>
        <p>return false
end if
fleaves the module as it was when createdg
reset component(P )
until f irst P S recursive(P )
return true</p>
      </sec>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          2.
          <string-name>
            <given-names>Chitta</given-names>
            <surname>Baral</surname>
          </string-name>
          .
          <article-title>Knowledge representation, reasoning and declarative problem solving</article-title>
          . http://www.baral.us/bookone/code/smodels.html.
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          3.
          <string-name>
            <given-names>J.</given-names>
            <surname>Carballido</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.C.</given-names>
            <surname>Nieves</surname>
          </string-name>
          , and
          <string-name>
            <given-names>M.</given-names>
            <surname>Osorio</surname>
          </string-name>
          .
          <article-title>Inferring preferred extensions by pstable semantics</article-title>
          . Accepted in Revista Iberomericana de Inteligencia Arti cial,
          <year>2008</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          4.
          <string-name>
            <given-names>J. L.</given-names>
            <surname>Carballido</surname>
          </string-name>
          .
          <source>PhD thesis</source>
          , BUAP,
          <year>2008</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          5.
          <string-name>
            <given-names>W.F.</given-names>
            <surname>Dowling</surname>
          </string-name>
          and
          <string-name>
            <given-names>J.H.</given-names>
            <surname>Gallier</surname>
          </string-name>
          .
          <article-title>Linear time algorithm for testing the satis ability of propositional horn formulae</article-title>
          .
          <source>Journal of logic programming</source>
          ,
          <year>1984</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          6.
          <string-name>
            <given-names>Phan</given-names>
            <surname>Minh Dung</surname>
          </string-name>
          .
          <article-title>On the acceptability of arguments and its fundamental role in nonmonotonic reasoning, logic programming and n-person games</article-title>
          .
          <source>Arti cial Intelligence</source>
          ,
          <volume>77</volume>
          (
          <issue>2</issue>
          ):
          <volume>321</volume>
          {
          <fpage>358</fpage>
          ,
          <year>1995</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          7.
          <string-name>
            <given-names>Michael</given-names>
            <surname>Gelfond</surname>
          </string-name>
          and
          <string-name>
            <given-names>Vladimir</given-names>
            <surname>Lifschitz</surname>
          </string-name>
          .
          <article-title>The Stable Model Semantics for Logic Programming</article-title>
          . In R. Kowalski and K. Bowen, editors,
          <source>5th Conference on Logic Programming</source>
          , pages
          <volume>1070</volume>
          {
          <fpage>1080</fpage>
          . MIT Press,
          <year>1988</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          8. John W. Lloyd.
          <source>Foundations of Logic Programming</source>
          . Springer, Berlin, second edition,
          <year>1987</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          9.
          <string-name>
            <given-names>Yuting</given-names>
            <surname>Zhao Lintao Zhang Matthew H. Moskewicz</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Conor F.</given-names>
            <surname>Madigan</surname>
          </string-name>
          and
          <string-name>
            <given-names>Sharad</given-names>
            <surname>Malik</surname>
          </string-name>
          . Cha . Cha :
          <article-title>Engineering an e cient sat solver</article-title>
          .
          <source>In DAC 01: Proceedings of the 38th Conference on Design Automation</source>
          , Las Vegas,
          <string-name>
            <surname>NV</surname>
          </string-name>
          , USA,
          <year>June 2001</year>
          .,
          <year>2001</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          10.
          <string-name>
            <surname>Angel Marin George Mauricio Osorio</surname>
          </string-name>
          ,
          <source>Juan Carlos Nieves. Computing the strati ed minimal models semantic(unpublished)</source>
          .
          <year>2009</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          11.
          <string-name>
            <given-names>Ilkka</given-names>
            <surname>Niemela</surname>
          </string-name>
          and
          <string-name>
            <given-names>Patrik</given-names>
            <surname>Simons</surname>
          </string-name>
          .
          <article-title>Smodels - an implementation of the stable model and well-founded semantics for normal logic programs</article-title>
          .
          <source>volume 1265 of Lecture Notes in Arti cial Intelligence (LNCS)</source>
          , pages
          <fpage>420</fpage>
          {
          <fpage>429</fpage>
          ,
          <year>1997</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          12.
          <string-name>
            <surname>Mauricio</surname>
            <given-names>Osorio</given-names>
          </string-name>
          , Jose Arrazola, and Jose Luis Carballido.
          <article-title>Logical weak completions of paraconsistent logics</article-title>
          .
          <source>Journal of Logic and Computation, Published on line on May 9</source>
          ,
          <year>2008</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          13.
          <string-name>
            <given-names>Mauricio</given-names>
            <surname>Osorio</surname>
          </string-name>
          and Jose Luis Carballido.
          <article-title>Brief study of G'3 logic</article-title>
          . To appear
          <source>in Journal of Applied Non-Classical Logic</source>
          ,
          <volume>18</volume>
          (
          <issue>4</issue>
          ):
          <volume>79</volume>
          {
          <fpage>103</fpage>
          ,
          <year>2009</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          14.
          <string-name>
            <surname>Mauricio</surname>
            <given-names>Osorio</given-names>
          </string-name>
          , Juan Antonio Navarro, Jose Arrazola, and
          <string-name>
            <given-names>Veronica</given-names>
            <surname>Borja</surname>
          </string-name>
          .
          <article-title>Logics with common weak completions</article-title>
          .
          <source>Journal of Logic and Computation</source>
          ,
          <volume>16</volume>
          (
          <issue>6</issue>
          ):
          <volume>867</volume>
          {
          <fpage>890</fpage>
          ,
          <year>2006</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          15.
          <string-name>
            <given-names>Mauricio</given-names>
            <surname>Osorio</surname>
          </string-name>
          and
          <string-name>
            <given-names>Claudia</given-names>
            <surname>Zepeda</surname>
          </string-name>
          .
          <article-title>Update sequences based on minimal generalized pstable models</article-title>
          .
          <source>In MICAI</source>
          , pages
          <volume>283</volume>
          {
          <fpage>293</fpage>
          ,
          <year>2007</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref15">
        <mixed-citation>
          16.
          <string-name>
            <given-names>Mauricio</given-names>
            <surname>Osorio</surname>
          </string-name>
          and
          <string-name>
            <given-names>Claudia</given-names>
            <surname>Zepeda</surname>
          </string-name>
          .
          <article-title>Pstable theories and preferences</article-title>
          .
          <source>In Electronic Proceedings of the 18th International Conference on Electronics, Communications, and Computers (CONIELECOMP</source>
          <year>2008</year>
          ),
          <year>March</year>
          ,
          <year>2008</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref16">
        <mixed-citation>
          17.
          <string-name>
            <given-names>S.</given-names>
            <surname>Pascucci</surname>
          </string-name>
          and
          <string-name>
            <given-names>A.</given-names>
            <surname>Lopez</surname>
          </string-name>
          .
          <article-title>Syntactic transformation rules under p-stable semantics: theory and implementation</article-title>
          .
          <year>2009</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref17">
        <mixed-citation>
          18.
          <string-name>
            <given-names>S.</given-names>
            <surname>Pascucci</surname>
          </string-name>
          and
          <string-name>
            <given-names>A.</given-names>
            <surname>Lopez. Implementing</surname>
          </string-name>
          p
          <article-title>-stable with simpli cation capabilities. Submmited to Inteligencia Arti cial</article-title>
          , Revista Iberoamericana de
          <string-name>
            <given-names>I.A.</given-names>
            ,
            <surname>Spain</surname>
          </string-name>
          ,
          <year>2008</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref18">
        <mixed-citation>
          19.
          <string-name>
            <given-names>Simone</given-names>
            <surname>Pascucci</surname>
          </string-name>
          .
          <article-title>Syntactic properties of normal logic program under pstable semantics: theory and implementation</article-title>
          .
          <source>Master's thesis</source>
          ,
          <year>March 2009</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref19">
        <mixed-citation>
          20.
          <string-name>
            <given-names>David</given-names>
            <surname>Pearce</surname>
          </string-name>
          .
          <article-title>Stable Inference as Intuitionistic Validity</article-title>
          .
          <source>Logic Programming</source>
          ,
          <volume>38</volume>
          :
          <fpage>79</fpage>
          {
          <fpage>91</fpage>
          ,
          <year>1999</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref20">
        <mixed-citation>
          21.
          <string-name>
            <surname>Cli ord Stain Thomas H. Cormen</surname>
            ,
            <given-names>Charles E. Leiserson Ronald L.</given-names>
          </string-name>
          <string-name>
            <surname>Rivest</surname>
          </string-name>
          .
        </mixed-citation>
      </ref>
      <ref id="ref21">
        <mixed-citation>
          22. Allen van Gelder,
          <article-title>Kenneth A</article-title>
          .
          <string-name>
            <surname>Ross</surname>
            ,
            <given-names>and John S. Schlipf.</given-names>
          </string-name>
          <article-title>The well-founded semantics for general logic programs</article-title>
          .
          <source>Journal of the ACM</source>
          ,
          <volume>38</volume>
          :
          <fpage>620</fpage>
          {
          <fpage>650</fpage>
          ,
          <year>1991</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>