<!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>Graph representations of logic programs: properties and comparison</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Stefania Costantini</string-name>
          <email>stefania.costantini@univaq.it</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Alessandro Provetti</string-name>
          <email>ale@unime.it</email>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Universita` di L'Aquila</institution>
          ,
          <country country="IT">Italy</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Universita` di Messina</institution>
          ,
          <country country="IT">Italy</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>In this paper, we propose a formalization of the features that a graph representation of logic programs under the answer set semantics should in our opinion exhibit in order to be a satisfactory and useful representation formalism. We introduce a concept of isomorphism between a program and the corresponding graph. We show the importance of isomorphism for program analysis and we compare different graph representations w.r.t. isomorphism.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction</title>
      <p>
        Answer Set Programming (ASP) [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ] (also called Stable Logic Programming (SLP)
[
        <xref ref-type="bibr" rid="ref3">3</xref>
        ]), is a relatively recent but well-established style of logic programming: each solution
to a problem is represented by an answer set (also called stable model), and not by
answer substitutions produced in response to a query.
      </p>
      <p>With the growth of practical real-world ASP applications, the need is arising of
writing programs with a complicated structure, and of composing existing programs
into larger ones. Guidelines should be provided to programmers and system developers,
in order to write consistent (or, sometimes, purposedly inconsistent) programs, and to
combine them.</p>
      <p>These guidelines should be based upon some kind of representation of logic
programs. We believe that the properties of a good representation are at least the following:
(i) the relationship between the program and its representation is clearly understandable;
(ii) it is easy to shift back and forth from the program to the representation, so that a
change in the program reflects into a change in the representation, and vice versa; (iii)
it is possible to use the representation for developing techniques to define significant
subprograms, study their interactions and determine which program parts can influence
specific, critical points, and thus influence relevant program properties.</p>
      <p>Graph representations are in our opinion good candidates. In fact, graphs are simple
and understandable. Graph-theoretic structures are able to represent properties of
programs. Known properties of graphs can help improve the understanding of structural
properties of the programs themselves.</p>
      <p>In this paper we propose a formalization of the features that a graph representation
of logic programs should in our opinion exhibit in order to be a satisfactory and useful
representation formalism. We introduce a concept of isomorphism between a program
and the corresponding graph, and we show that isomorphism is possible only if a graph
representation formalism is able to distinguish the cycles occurring in the program, and
the different connections among them.</p>
      <p>
        We discuss isomorphism w.r.t. three graph representations: the traditional
Dependency Graph DG, the Extended Dependency Graph EDG [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ] and the Rule Graph RG
[
        <xref ref-type="bibr" rid="ref5 ref6 ref7">5,6,7</xref>
        ] (with some of its extensions). In a companion paper [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ] we we show that
isomorphic graphs can be used for characterizing properties of programs, first of all
consistency, and (in perspective) for program debugging and composition.
      </p>
      <p>The paper is organized as follows. In Section 2 we discuss properties of graph
representations and we introduce isomorphic graph representations, and their relationship to
cycles. In Section 3 we motivate these representations by showing how cycles occurring
in a program affect the existence and number of answer sets. In Sections 4, 5 and 6 we
examine various graph representations to establish their properties. Finally, Section 7
concludes the paper. The reader can find an introduction to ASP in Appendix A, and
some basic definitions about graphs in Appendix B.
2</p>
    </sec>
    <sec id="sec-2">
      <title>Properties of graph representations</title>
      <p>
        The main property of programs one wants in the first place to study under the answer
set semantics is consistency, i.e., the existence (and the number) of answer sets. In
general, one has to compute and often examine the answer sets (e.g., in order to check
whether some desired conclusion has been actually reached, or if a soft constraint is
satisfied). In some situations, for instance for debugging a program or for trying to
combine different program components, one may want to be able to investigate the
program structure, in order to understand which parts influence which others, and then
what ensures consistency, and what can spoil it [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ]. When modifying and updating
programs, it can be useful to reason about how the existence and content of answer sets
is affected by modifications and/or updates performed on the given program.
      </p>
      <p>As it is well-known, the Dependency Graph is not a satisfactory representation for
logic programs under these respects, as shown by the following example.
Example 1. Consider the following programs 1, 2 and 3 (from left to right):
p ← not p; not e: p ← not p: p ← not p; not e:
a ← not b: p ← not e: a ← not b:
b ← not a: a ← not b: b ← not a:
e ← not f: b ← not a: e ← not f:
f ← not h: e ← not f: f ← not h:
h ← not e: f ← not h: h ← not e; not a:
h ← not a: h ← not e; not a:
It is easy to see that the dependency graphs of the three programs coincide. Namely, the
DG of the three programs is the leftmost graph of Figure 1. However, 1 has answer
set {b; e; h} while instead 2 has answer set {a; f; p} and 3 has no answer sets at all,
i.e. it is inconsistent.</p>
      <p>
        Inconsistency may arise only because of odd cycles: in fact, call-consistent
programs [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ], which do not contain odd-cycles, are never inconsistent. In the DG of the
above programs we can see two odd cycles: the first one involving atom p, which
depends on itself; the second one involving atoms e, f and h.
      </p>
      <p>However, the different connections between the odd cycles and the rest of the
program, that cannot be seen on the DG, influence the existence and the number of answer
sets.</p>
      <p>Moreover, based on the DG it is impossible to make predictions about what
happens in case of modifications. For instance, if adding fact e, the following happens: (i)
program 1 remains consistent, with the two answer sets {b; e; h} and {a; e; f }; (ii) 2
becomes inconsistent; (iii) 3 becomes consistent, with the two answer sets {b; e; f }
and {a; e; f }.</p>
      <p>Since we are interested in the syntactic structure of programs, let us characterize
those programs that have the same structure, but different names for the atoms occurring
in them.</p>
      <p>Definition 1. Let P be a logic program with Herbrand base BP = {a1; a2; : : : ; ah},
and let BP′ be a set of atoms with the same cardinality as BP . A renaming is
an injective and surjective function from BP to BP′ , that can be denoted as a set
{(a1; a′1); (a2; a′2); : : : ; (ah; a′h)} where ai ̸= aj implies a′i ̸= a′j , while for some k
we may have ak = a′k. can be applied to P , thus obtaining a new program P ′ = P ,
by replacing every occurrence of ai by a′i.</p>
      <p>Definition 2. Two logic programs P1 and P2 are renaming-equivalent if there exists a
renaming from BP1 to BP2 such that P2 = P1 .</p>
      <p>Let GF be any graph representation formalism (for instance the DG). By G ∈ GF
we mean a graph G which can be constructed for some program according to GF .
By GF (P) we mean the graph which represents program P according to GF . The
following is a straightforward property of any graph representation.</p>
      <p>Definition 3. A graph representation formalism GF is acceptable if for every logic
program P , GF (P ) is unique.</p>
      <p>A stronger requirement is that, given a graph, we can reconstruct the program that
is represented by this graph, or at least a program, if there is more than one choice. This
requirement is related to the usefulness of the representation as a software engineering
tool: given a program, one can determine how it is represented; given a graph, one can
guess which kind of program it represents.</p>
      <p>Definition 4. A graph representation formalism GF is adequate if for every graph G ∈
GF , it is possible to construct from G a logic program P such that G = GF (P).</p>
      <p>We may expect that two programs which are renaming-equivalent are represented
by graphs which have the same structure. Instead, it is reasonable to expect that different
programs have different representations.</p>
      <p>Definition 5. An adequate graph representation formalism GF is unambiguous if for
every two programs P1 and P2 which are not renaming-equivalent, we have that, apart
from the labeling of vertices (if any), GF (P1) ̸= GF (P2).</p>
      <p>For any graph representation formalism GF which is acceptable, adequate and
unambiguous, we say that GF (P) is isomorphic to P . In fact, P can uniquely be
determined from GF (P). More generally, we will say that the representation GF is
isomorphic to logic programs. For short, we say that GF is an isomorphic graph
representation.</p>
      <p>Clearly, the Dependency Graph representation formalism is acceptable and
adequate, but it is not unambiguous. In the example above in fact, it is impossible to say
from the graph which of the three programs is being represented. Consequently, on the
basis of the graph it is impossible to characterize consistency under the answer set
semantics: we do not know from the graph whether the program under consideration has
answer sets, and it is impossible to find these answer sets, and to predict whether they
will change after updates.
3</p>
    </sec>
    <sec id="sec-3">
      <title>The relationship between cycles and answer sets</title>
      <p>An active handle gives a truth value to an atom involved in a cycle.
Consequently, the truth value of all the other atoms of the cycle follows without
contradictions. A necessary condition for consistency is that every odd cycle has at least one
handle. This condition is not sufficient, since two handles can be in conflict, in the
sense that they cannot be active simultaneously. For instance, take program fragment
{v ← not v; not w; t ← not t; t ← not w}: there are two odd cycles, one
involving v with AND handle not w, and the other one involving t with OR handle not w.
Since the same condition not w occurs in two handles of different kind, they cannot
be simultaneously active, and therefore the cycle, and the overall program, will be
inconsistent. Whenever we have an even cycle without handles (unconstrained even
cycle) we can choose any of the two answer sets of the corresponding program fragment
in order to form an answer set of the overall program. For instance, for even cycle
a ← not b; b ← not a any of the two answer sets {a}; {b} can be selected.</p>
      <p>
        In [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ] we prove that a graph representation formalism GF which does not
distinguish between AND and OR handles of cycles cannot be an isomorphic representation
of logic programs.
4
      </p>
    </sec>
    <sec id="sec-4">
      <title>The Extended Dependency Graph EDG</title>
      <p>
        The Extended Dependency Graph (EDG) has been introduced in [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ], where its
properties were discussed for negative programs, i.e., program including only negative literals
in the body of rules. These results are generalized to general programs in [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ]. The EDG
is similar to the DG, except it is more accurate for negative dependencies. The
definition is based upon distinguishing among rules defining the same atom, i.e, having the
same head. To establish this distinction, we assign to each head an upper index, starting
from 1, where upper index 0 is reserved to atoms with no defining rules. E.g., {a ←
c; not b: a ← not d: b ← :} becomes {a(1) ← c(0); not b(1): a(2) ← not d(0): b(1) ← :}.
Definition 6. (Extended dependency graph for general programs) (EDG)
Given a general logic program , its associated Extended Dependency Graph
EDG( ) is the directed finite labeled graph ⟨V; E; {+; −}⟩ where {+; −} are the
labels associated to the edges, and the sets V and E are defined as follows.
V:1 vertices For each rule in there is a vertex ai(k), k ≥ 1, where ai is the name of
the head and k is the index of the rule in the definition of ai.
      </p>
      <p>V:2 vertices For each atom ai in that does not occur in the head of any rule there is
a vertex ai(0).</p>
      <p>E:1 edges For each c(jl) ∈ V , there is an edge ⟨c(jl); ai(k); +⟩, if and only if cj appears
as a positive condition in the k-th rule defining ai.</p>
      <p>E:2 edges For each c(jl) ∈ V , there is an edge ⟨c(jl); ai(k); −⟩, if and only if not cj
appears as a negative condition in the k-th rule defining ai.
to an edge ⟨c(jl); ai(k); −⟩.</p>
      <p>The EDG for negative programs can be seen as a shortcut of the EDG for general
programs, where each edge ⟨c(jl); ai(k)⟩ is implicitly labeled with “−”, i.e., corresponds</p>
      <p>The definition of EDG extends that of DG in the sense that for programs where
atoms are defined by at most one rule the two coincide. Consider in Figure 1 the EDGs
of the programs in Example 1 (where h(1), h(2), p(1), p(2) are indicated as h, h′, p, p′
respectively, and all edges are implicitly labeled with ’−’).</p>
      <p>a
?nb -Ænf</p>
      <p>a
Æ6</p>
      <p>Æ6
h
Æn
a
?nb Æ- nf</p>
      <p>On the EDGs, we clearly see the cycles, and also the handles. Consider EDG( 1)
(center): rule {f ← not h:} is represented by the two edges ⟨h; f ⟩ and ⟨h′; f ⟩, since
truth of h may depend on any of its defining rules; the second rule for h is auxiliary to
the cycle, and corresponds to an OR handle. Therefore, we can see on the EDG that the
cycle has an OR handle because the edge incoming into h′ originates in a duplication of
one of the atoms of the cycle. In the same graph, edge ⟨e; p⟩ represents instead an AN D
handle. In fact, we can see on the EDG that the cycle has an AND handle because there
is an incoming edge into that cycle, originated in a duplication of an atom not belonging
to the cycle itself. The even cycle involving a and b has no incoming edges and then it
is unconstrained.</p>
      <p>In general: given program , a cycle in corresponds to a cycle in EDG( ).
On the EDG: (1) An AND handle for a cycle C relative to atom occurring in C is
represented by an edge incoming into (additional condition of the rule defining ).
Atom (and cycle C) may have either none or one or several AND handles. (2) An
OR handle for a cycle C relative to atom occurring in C is represented by a sibling
node of (additional rule defining ). More precisely, if C actually includes vertex i,
another vertex j j ̸= i is also present in the EDG. Atom (and cycle C) may have
either none or one or several OR handles.</p>
      <p>
        It is proved in [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ] that the EDG is an isomorphic graph representation formalism.
5
      </p>
    </sec>
    <sec id="sec-5">
      <title>The Rule Graph RG</title>
      <p>
        An important graph representation of negative logic programs is the Rule Graph (RG)
introduced in [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ]. Given program g, assume first obtained a reduced program , where
rules with the same body that may occur in g are all merged into a single rule, whose
head is the conjunction of the heads of the original rules. Let r1; : : : ; rn be the rules
of the (reduced) program , Then, the rule graph RG of is a directed graph, with
vertices corresponding to the ri’s, and there is and edge (r1; r2) whenever one of the
conclusions of r1 appears in the body of r2.
      </p>
      <p>The rule graph allows useful conditions about existence of answer sets to be
obtained, corresponding to formal properties coming from graph theory. In particular,
answer sets correspond to kernels of the RG.</p>
      <p>Notice that merging rules with the same head is an essential feature of the approach,
which leads to increased ambiguity with respect to the original program. Take for
instance the program:
l1: a ← not b:
l2 c ← not b:
l3: b ← not a:
l4: b ← not c:
l5: c ← not a:</p>
      <p>The reduced version is
r1: a; c ← not b:
r2: b; c ← not a:
r3: b ← not c:</p>
      <p>The kernels of the rule graph of the reduced version are two, namely r1 and r3.
From the first one, going back to the reduced program one gets a stable model as the
body of the corresponding rule, i.e., {b}. From the second one, again by taking the body
of the corresponding rule, you get the stable model {c}. If, by abuse of notation, one
draws the rule graph of the original program, no kernels are found.</p>
      <p>For this reason, the RG and the EDG can be compared only on reduced programs,
or, equivalently, on programs where all rules have different bodies. On this class of
graphs, the RG and the EDG have the same structure, but with the important difference
that vertices are labeled not with the name of the rules, but with (instances of) atoms.
In particular, whenever there is only one atom in the body of each rule, this does not
make any real difference, since the head of a rule being in the body of another collapses
into the dependency between the two atoms. The difference instead exists and has a
relevance whenever there are more atoms in the body of rules: in this case, the RG
does not distinguish whether atoms in the body are one or more, and which one is the
particular atom that is in common between two rules. Then, the RG cannot distinguish
between AND and OR handles, and consequently it cannot be an isomorphic graph
representation formalism.</p>
      <p>In fact, below we exhibit two different programs, which are not
renamingequivalent, and have both different answer sets and different EDGs, but the same RG.</p>
      <p>Let 1 be:
r1: a ← not b:
r2: b ← not a:
r3: g ← not g; not f:
r4: f ← not q:
r5: q ← not q; not a:</p>
      <p>The unique answer set of 1 is {a; f }. In fact, not f is the unique AND handle for
the odd cycle involving g. Then f must be true, and its truth is guaranteed by the truth
of a, where not a is the unique AND handle of the odd cycle involving q. Consequently
q is false.</p>
      <p>Let 2 be:
r1: a ← not b:
r2: b ← not a:
r3: g ← not g:
r4: g ← not q:
r5: q ← not q; not a:</p>
      <p>The unique answer set of 2 is {a; g}. Again a must be true, since not a is the
unique AND handle of the odd cycle involving q, which becomes false. In this program
however, not q is the unique OR handle of the odd cycle involving g. The handle is thus
active, and g is true.</p>
      <p>The two programs have the same RG, shown in Figure 2.</p>
      <p>r1
r5
r2
r4</p>
      <p>r3</p>
      <p>This is because in both cases we have that: the head of rule r4 is in the body of rule
r3; the head of rule r5 is in the body of rule r4; atom a, which is the head of rule r1, is
in the body of rule r5.</p>
      <p>We can instantiate the general argument performed in the proof of Theorem 1 for
the RG.
(i) The RG is an adequate representation formalism if one guesses the Herbrand base
of a program corresponding to the graph; many guesses are possible, the simplest
one being to assign a different atom as the head of each different rule; other guesses
are of course possible, where different rules have the same head.
(ii) as a consequence of not being able to tell the heads of the rules, the RG as a
representation formalism is not unambiguous: in fact, it is impossible to distinguish
between 1 and 2 on the basis of the rule graph; Since 1 and 2 are reduced
programs, it is moreover impossible to get back to the original programs.
(iii) consequently, the RG is not an isomorphic graph representation formalism.</p>
      <p>Then, in our opinion it would not be easy to define an interactive programming
methodology on the basis of the rule graph, since it does not graphically distinguish
among cases which are semantically very different.</p>
      <p>
        This does not mean that the RG is not useful: on the contrary, it can be an effective
program analysis tool. In fact, in [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ] many examples are provided of useful program
properties that can be identified on the RG, based on exploiting graph-theoretical
properties.
6
      </p>
    </sec>
    <sec id="sec-6">
      <title>Extensions to the Rule Graph</title>
      <p>
        The Rule Graph RG has been extended in [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ] to general logic programs, by introducing
labeled edges so as to denote both positive and negative dependencies. Further
extensions have then been introduced in [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ]. They are based on identifying in a program
P : the set of rules; the set Head(P ) of atoms occurring in the head of rules; the set
Body(P ) of the conjunctions occurring as bodies in rules. In a body B ∈ Body(P )
one can distinguish the conjunction B+ of positive literals and the conjunction B− of
negative literals.
      </p>
      <p>– The Body-Head Graph has bodies and heads as vertices, and: an edge (B; h) from
each body B ∈ Body(P ) and the head h ∈ Head(P ) of each rule where B occurs;
a positive edge (h; B) from h to each body where it occurs positively; a negative
edge (h; B) from h to each body where it occurs negatively.
– The Rule-Head Graph has rules and heads as vertices, and: an edge (r; h) from
each rule r ∈ P and its head h; a positive edge (h; r) from h to each rule where it
occurs positively in the body; a negative edge (h; r) from h to each rule where it
occurs negatively in the body.
– The Body-Rule Graph has bodies and rules as vertices, and: an edge (B; r) from
each body B ∈ Body(P ) to each rule r ∈ P whose body is B; a positive edge
(r; B) from r to each body where the head h of r occurs positively; a negative edge
(r; B) from r to each body where the head h of r occurs negatively.</p>
      <p>Some combinations/variations of the above three representations are also defined in
the above-mentioned papers.</p>
      <p>
        These representations have been used as a basis for implementing the noMoRe
answer set solver [
        <xref ref-type="bibr" rid="ref11">11</xref>
        ]. They have also been used in order to reason about loop formulas
(positive cycles) [
        <xref ref-type="bibr" rid="ref12">12</xref>
        ].
      </p>
      <p>However, none of them is isomorphic. In particular, they are acceptable and
adequate but not unambiguous. In fact, atoms that are not defined (i.e., that do not occur in
the head of any rule) are never considered in the definitions. Take for instance the
programs {a ← b:} and {a ← b; c:}. Indicate, e.g., the rule with r1 and its body with B1.
These two programs have structurally identical graphs. We cannot distinguish between
the two cases unless we explicitly associate the program to the graph (e.g., by copying
rules and bodies into the vertices as labels).
7</p>
    </sec>
    <sec id="sec-7">
      <title>Conclusions</title>
      <p>Graph representations of logic programs can be useful from a software engineering
perspective. We have defined which properties a graph representation should posses in
order to be a good program representation tool, and we have compared different
representations w.r.t. these properties. Topics of further research are that of demonstrating
effective usefulness of graph representations for program analysis and construction.</p>
    </sec>
    <sec id="sec-8">
      <title>Answer Set Programming</title>
      <p>
        We consider the language DAT ALOG¬ for deductive databases, which is more
restricted than traditional logic programming (the reader may refer to [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] for a
discussion). In the following, we will implicitly refer to the ground version of DAT ALOG¬
programs.
      </p>
      <p>A general logic program (or simply “logic program”) is composed of rules may
contain negated atoms of the form ¬a. A rule is defined as usual, and can be seen as
composed of a conclusion head( ), and a set of conditions body( ). The latter can be
divided into positive conditions pos( ) each one of the form A, and negative conditions
neg( ), each one of the form not A. The literal A is either an atom a, or a negated atom
¬a. A negative logic programs is composed of rules without positive conditions.</p>
      <p>
        The answer sets semantics [
        <xref ref-type="bibr" rid="ref1 ref13">1,13</xref>
        ] is a view of logic programs as sets of inference
rules (more precisely, default inference rules). Alternatively, one can see a program as
a set of constraints on the solution of a problem, where each answer set represents a
solution compatible with the constraints expressed by the program. Consider the simple
program {q ← not p: p ← not q:}. For instance, the first rule is read as “assuming that
p is false, we can conclude that q is true.” This program has two answer sets. In the first
one, q is true while p is false; in the second one, p is true while q is false.
      </p>
      <p>A subset M of the Herbrand base BP of a DAT ALOG¬ program P is an answer
set of P , if M coincides with the least model of the reduct P M of P with respect to M .
This reduct is obtained by deleting from P all rules containing a condition not a, for
some a in M , and by deleting all negative conditions form the other rules. Answer sets
are minimal supported models, and form an anti-chain.</p>
      <p>Unlike with other semantics, a logic program may have several answer sets, or may
have no answer set, because conclusions are included in an answer set only if they can
be justified. The following program has no answer set:
{a ← not b: b ← not c: c ← not a:}
The reason is that in every minimal model of this program there is a true atom that
depends (in the program) on the negation of another true atom. Whenever a program has
no answer sets, we will say that the program is inconsistent. Correspondingly, checking
for consistency means checking for the existence of answer sets.</p>
      <p>
        Every logic program can be reduced to its kernel normal form [
        <xref ref-type="bibr" rid="ref14">14</xref>
        ] [
        <xref ref-type="bibr" rid="ref15">15</xref>
        ]. A kernel
program is characterized by having: i) well-founded model W F S( ) = ⟨∅; ∅⟩; ii)
no positive conditions in rules, i.e. for every rule , pos( ) = ∅; iii) every atom which
is in the body of a rule must also appear in the head of some rule (possibly the same
one). In [
        <xref ref-type="bibr" rid="ref15">15</xref>
        ] we have defined simple algorithms for shifting back and forth from logic
programs to their kernel normal form.
      </p>
      <p>In the following sections, by “logic program” we will implicitly refer to a general
logic program. When explicitly indicated, we will refer to a negative program or to a
kernel program.</p>
      <p>B</p>
    </sec>
    <sec id="sec-9">
      <title>Graphs</title>
      <p>
        The graph representations that we introduce in the following are all based on directed
graphs. Then, in this paper the term “graph” refers implicitly to directed graphs. Below
we introduce some basic definitions about graphs. For a comprehensive presentation
and discussion on graphs and graph theory the reader may refer for instance to [
        <xref ref-type="bibr" rid="ref16">16</xref>
        ].
      </p>
      <p>A directed graph or graph G is a pair ⟨V; E⟩. V is a set, whose elements are called
vertices or nodes. The elements of E, where E ⊆ V × V , are called the edges of the
graph. For each edge e ∈ E, where e = (vi; vj ), vi; vj ∈ V , we say that e goes from
vi to vj , and, referring to vj , that e is an edge coming from vi. Let G be a graph, and
V ′ ⊆ V . Let V \ V ′ be the set of vertices that are are in V but not in V ′.</p>
      <p>A labeled directed graph or labeled graph G is a triple ⟨V; E; L⟩ where V is as
before, L is a set of labels, and the elements of E, where E ⊆ V × V × L, are now of
the form e = (vi; vj ; l), vi; vj ∈ V , l ∈ L. All definitions given here for directed graphs
can be easily rephrased for labeled directed graphs, and then in the rest of the paper we
often give this reformulation for granted.</p>
      <p>Given a directed graph and vertices a; b ∈ V (where it can be a = b) a path P from
a to b is a subset E′ of E where either E′ = (a; b) or there exists edge (a; c) ∈ E′ such
that E′ \ (a; c) is a path from c to b. We say that P is composed of the edges (x; y) in
E′ and involves vertices x; y. By abuse of notation we also consider these vertices as
belonging to the path, and we say x; y ∈ P . A cycle C is a set of edges which constitutes
a path from v to v, for some v ∈ V .</p>
      <p>A simple path from a to b is a path P such that there not exist P ′ ⊂ P such that P ′
is a path from a to b. Vertex a is called the source of the path, while vertex b is called
the sink. A simple cycle C is a set of edges which constitutes a simple path from v to v,
for some v ∈ V . In the following, by “a cycle” we will implicitly mean a simple cycle.
A cycle is even (resp. odd) if it is composed of an even (resp. odd) number of distinct
edges.</p>
      <p>A kernel in a directed graph is a subset V ′ of V such that (i) no two vertices in V ′
are joined by an edge in E (we say that V ′ is independent), and (ii) for every vertex
v ∈ V − V ′ there is some vertex v′ ∈ V ′ where (v′; v) belongs to E (we say that V ′ is
dominating).</p>
      <p>Let E=V ′ be E ∩ (V ′ × V ′). The subgraph of G induced by V ′ is the graph G′ =
⟨V ′; E=V ′⟩. If V ′ is a kernel, it is easy to see that (by condition (i) above) the induced
subgraph has an empty set of edges.</p>
      <p>For a negative logic program P (and in particular for a kernel program P ), its
dependency graph DG(P ) is a finite directed graph whose vertices are the atoms occurring
in P . There is an edge (w; v) if and only if there is a rule in P with v in its head and
not w occurring in its body. In the DG, we say that atom a depends on atom b if there
is a path from b to a.</p>
      <p>For a general logic program P , its dependency graph DG(P ) is a finite directed
labeled graph whose vertices are the atoms occurring in P and whose set of labels is
{+; −}. There is an edge (w; v; +) if and only if there is a rule in P with v in its head
and w occurring in its body (positive edge). There is an edge (w; v; −) if and only if
there is a rule in P with v in its head and not w occurring in its body (negative edge).</p>
      <p>In the DG, we say that atom a depends on atom b if there is a path from b to a. Atom
a depends evenly (resp. oddly) on b if there exists a path between a and b composed of
an even (resp. odd) number of arcs. A program is stratified if no atom depends on itself.
As a special case one can have positive dependencies, that can be either even or odd,
by considering (and thus counting) only the positive edges of the path. Similarly, one
can consider negative dependencies, that can be either even or odd, by considering (and
thus counting) only the negative edges of the path. A program is stratified if in its DG
no atom depends on itself: i.e., for no atom a there is a cycle involving a.</p>
      <p>A loop, or cycle, in a program corresponds to a cycle on its Dependency Graph
DG(P ). A cycle composed of positive edges only is called a positive cycle. A cycle
composed of negative edges only is called a negative cycle. Positive and negative cycles
are either even or odd depending on the number of edges. A cycle which is not positive
is said to be either even or odd according to the number of negative edges only, because
consistency of the program is mainly affected by negative dependencies. A program is
call–consistent if on its DG no atom has an odd negative dependency on itself: i.e., there
is no cycle involving a and including an odd number of negative edges. Stratified and
call–consistent programs are guaranteed to be consistent under the answer set semantics
(answer sets always exist).</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <surname>Gelfond</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Lifschitz</surname>
            ,
            <given-names>V.</given-names>
          </string-name>
          :
          <article-title>The stable model semantics for logic programming</article-title>
          . In Kowalski, R.,
          <string-name>
            <surname>Bowen</surname>
          </string-name>
          , K., eds.
          <source>: Proc. of the 5th Intl. Conference and Symposium on Logic Programming</source>
          , The MIT Press (
          <year>1988</year>
          )
          <fpage>1070</fpage>
          -
          <lpage>1080</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <surname>Lifschitz</surname>
          </string-name>
          , V.:
          <article-title>Answer set planning</article-title>
          .
          <source>In: Proc. of the 16th Intl. Conference on Logic Programming</source>
          . (
          <year>1999</year>
          )
          <fpage>23</fpage>
          -
          <lpage>37</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <surname>Marek</surname>
            ,
            <given-names>V.W.</given-names>
          </string-name>
          , Truszczyn´ski, M. In:
          <article-title>Stable logic programming - an alternative logic programming paradigm</article-title>
          . Springer-Verlag, Berlin (
          <year>1999</year>
          )
          <fpage>375</fpage>
          -
          <lpage>398</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <surname>Brignoli</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Costantini</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>D'Antona</surname>
            ,
            <given-names>O.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Provetti</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          :
          <article-title>Characterizing and computing stable models of logic programs: the non-stratified case</article-title>
          .
          <source>In: Proceedings of the 1999 Conference on Information Technology</source>
          , Bhubaneswar,
          <string-name>
            <surname>India.</surname>
          </string-name>
          (
          <year>1999</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <surname>Dimopoulos</surname>
            ,
            <given-names>Y.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Torres</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          :
          <article-title>Graph theoretical structures in logic programs and default theories</article-title>
          .
          <source>Theoretical Computer Science</source>
          <volume>170</volume>
          (
          <year>1996</year>
          )
          <fpage>209</fpage>
          -
          <lpage>244</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <surname>Linke</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          :
          <article-title>Graph theoretical characterization and computation of answer sets</article-title>
          .
          <source>In: Proceedings of IJCAI'01</source>
          . (
          <year>2001</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <surname>Konczak</surname>
            ,
            <given-names>K.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Schaub</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Linke</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          :
          <article-title>Graphs and colorings for answer set programming: Abridged report</article-title>
          . In Vos, M.D.,
          <string-name>
            <surname>Provetti</surname>
          </string-name>
          , A., eds.:
          <source>Answer Set Programming: Advances in Theory and Implementation</source>
          ,
          <source>ASP03</source>
          . Volume
          <volume>78</volume>
          of The CEUR Workshop Proceedings Series (
          <year>2003</year>
          ) http://eur-ws.
          <source>org/</source>
          Vol-
          <volume>78</volume>
          /.
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <surname>Costantini</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          :
          <article-title>About graph representations of logic programs under the answer set semantics. Submitted, available from the author (</article-title>
          <year>2010</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9.
          <string-name>
            <surname>Costantini</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          :
          <article-title>On the existence of stable models of non-stratified logic programs</article-title>
          .
          <source>J. on Theory and Practice of Logic Programming</source>
          <volume>6</volume>
          (
          <issue>1</issue>
          -2) (
          <year>2006</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          10.
          <string-name>
            <surname>Fages</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          :
          <article-title>Consistency of clark's completion and existence of stable models</article-title>
          .
          <source>Methods of Logic in Computer Science</source>
          <volume>2</volume>
          <fpage>51</fpage>
          -
          <lpage>60</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          11.
          <string-name>
            <surname>Anger</surname>
            ,
            <given-names>C.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Konczak</surname>
            ,
            <given-names>K.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Linke</surname>
          </string-name>
          , T.:
          <article-title>NoMoRe : A system for non-monotonic reasoning with logic programs under answer set semantics</article-title>
          .
          <source>Number 2083 in LNAI</source>
          , Springer-Verlag, Berlin (
          <year>2001</year>
          )
          <fpage>325</fpage>
          -
          <lpage>330</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          12.
          <string-name>
            <surname>Gebser</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Schaub</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          :
          <article-title>Loops: Relevant or redundant? Number 3662 in LNAI</article-title>
          , Springer Verlag, Berlin (
          <year>2005</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          13.
          <string-name>
            <surname>Gelfond</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Lifschitz</surname>
            ,
            <given-names>V.</given-names>
          </string-name>
          :
          <article-title>Classical negation in logic programs</article-title>
          and disjunctive databases.
          <source>New Generation Computing</source>
          <volume>9</volume>
          (
          <year>1991</year>
          )
          <fpage>365</fpage>
          -
          <lpage>385</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          14.
          <string-name>
            <surname>Costantini</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          :
          <article-title>Contributions to the stable model semantics of logic programs with negation</article-title>
          .
          <source>Theoretical Computer Science</source>
          <volume>149</volume>
          (
          <year>1995</year>
          )
          <article-title>(prelim</article-title>
          . version
          <source>in Proc. of LPNMR93).</source>
        </mixed-citation>
      </ref>
      <ref id="ref15">
        <mixed-citation>
          15.
          <string-name>
            <surname>Costantini</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Provetti</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          :
          <article-title>Normal forms for answer sets programming</article-title>
          .
          <source>J. on Theory and Practice of Logic Programming</source>
          <volume>5</volume>
          (
          <issue>6</issue>
          ) (
          <year>2005</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref16">
        <mixed-citation>
          16.
          <string-name>
            <surname>Berge</surname>
          </string-name>
          , G.:
          <article-title>Graphs and Hypergraphs</article-title>
          . North Holland, Amsterdam (
          <year>1973</year>
          )
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>