<!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>Compilation-based Techniques for Evaluating Normal Logic Programs Under the Well-founded Semantics</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Andrea Cuteri</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Giuseppe Mazzotta</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Francesco Ricca</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>University of Calabria</institution>
          ,
          <addr-line>Rende 87036</addr-line>
          ,
          <country country="IT">Italy</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>Recent studies have demonstrated that compilation-based techniques can be beneficial for evaluating Datalog and ASP programs. In this paper, we develop a compiler that is able to generate solvers for normal logic programs under the well-founded semantics. The proposed system has been evaluated on diferent settings and preliminary results highlight significant improvements in the evaluation of non-stratified programs.</p>
      </abstract>
      <kwd-group>
        <kwd>eol&gt;Logic Programming</kwd>
        <kwd>Well-founded semantics</kwd>
        <kwd>Compilation</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction</title>
      <p>
        Logic programming is a declarative programming paradigm that can be used to model complex
problems in terms of logical implications [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ]. Logic programs are often evaluated by means of
general-purpose systems that implement a given semantics [
        <xref ref-type="bibr" rid="ref2 ref3">2, 3</xref>
        ]. The need for handling with
the same algorithm any possible input, in some cases, makes it impossible to apply specific
optimizations that would work only for a subclass of programs. Thus, considerable speedups
can be obtained by using ad-hoc evaluation procedures for the program in input. Following
this consideration, compilation-based techniques have been recently proposed to speed up the
evaluation of Datalog [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ] and Answer Set Programming (ASP) [
        <xref ref-type="bibr" rid="ref5 ref6">5, 6</xref>
        ]. In particular, the idea
behind this approach is to compile the input program into a custom system that is optimized
by exploiting the syntactic properties of the modeled program and can be used for evaluating
diferent instances of the compiled program. Concerning Datalog, the system souflé [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ] was
demonstrated to be very efective, especially for solving tasks connected with software
development, but also other prototypical systems were revealed to be very promising [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ]. Concerning
ASP, compilation techniques have been successfully employed for the evaluation of
groundingintensive ASP programs outperforming state-of-the-art ASP solvers [
        <xref ref-type="bibr" rid="ref6 ref8">6, 8</xref>
        ] and reducing both
time and memory consumption. However, none of the aforementioned systems support the
well-known well-founded semantics [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ] when no restriction is posed on the usage of negation.
      </p>
      <p>In this paper, we propose a compilation-based technique for evaluating normal logic programs
under the well-founded semantics and present a system that is able to generate ad-hoc solvers
for programs.</p>
      <p>
        An empirical evaluation of the proposed approach has been conducted on hard
benchmarks [
        <xref ref-type="bibr" rid="ref10 ref11">10, 11</xref>
        ]. Obtained results demonstrate that the proposed approach is competitive with
existing implementations capable of evaluating both Datalog programs (i.e. positive programs)
and program with negation. Notably, our approach outperforms dlv2 [
        <xref ref-type="bibr" rid="ref12">12</xref>
        ] on normal logic
programs with not-stratified negation.
      </p>
    </sec>
    <sec id="sec-2">
      <title>2. Logic Programs Under the Well-founded Semantics</title>
      <p>
        In this section, some preliminaries are provided on normal logic programs under the
wellfounded semantics [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ].
      </p>
      <sec id="sec-2-1">
        <title>2.1. Syntax</title>
        <p>A term is a constant or a variable. Constants are strings starting with lowercase letter or integers
instead variables are terms starting with uppercase letter. An atom  is an expression of the form
(1, ..., ) where  is a predicate of arity  and 1, ...,  are terms. If all the terms are constants
then  is a ground atom. A literal is an atom , or its negation   where  represents default
negation. A literal is positive if it is of the form , negative otherwise. Given a literal , the
complement of , denoted by , is  if  =  ,   otherwise. A rule  is an expression of the form:
ℎ ← 1, ..., ,  +1, ...,  .
where ℎ is an atom referred to as head, , 1, ...,   is a conjunction of literals referred
to as body of the rule, , and  &gt; 0. If  = 0 then  is a fact. A program Π is a set of rules.
Given a set of literals , + (resp. − ) denotes the set of positive (resp. negative) literals in
. The dependency graph of a program Π, Π, is a directed labeled graph where the nodes
are predicates appearing in Π and the set of the edges contains a positive (resp. negative) edge
(, ) if exists a rule  ←  ∈ Π where  appears in + (resp.  appears in − ). Π is said to
be Datalog if it does not contain any negative literals; Datalog with stratified negation if Π
does not contain cycles with negative edges.</p>
      </sec>
      <sec id="sec-2-2">
        <title>2.2. Well-founded Semantics</title>
        <p>
          Given a program Π, the Herbrand Universe is the set of constants appearing in Π; the Herbrand
Base, Π, is the set of possible ground atoms that can be built using predicate in Π and
constants in the Herbrand Universe. Given a rule  ∈ Π, () represents all possible
instantiations of  replacing variables with constants in the Herbrand Universe. Given a program
Π, (Π) = ⋃︀∈Π (). An interpretation  is a set of literals whose atoms belong
to Π.  is consistent if for each literal  ∈ ,   ∈/ .  is total if for each atom  ∈ Π
either  or   belongs to . Given a consistent interpretation , a literal  is true (resp. false)
w.r.t.  if  ∈  (resp.   ∈ ). A literal is undefined w.r.t.  if it is neither true nor false.
A conjunction of literals is true w.r.t.  if all the literals are true w.r.t. ; it is false if at least
one literal is false w.r.t. ; it is undefined otherwise. A set of atoms, Π, is an unfounded set
w.r.t.  if for every atom  ∈ Π and for every rule  ∈ (Π) such that  = ,  is
false w.r.t.  or  contains some positive literals whose atoms belong to Π. Intuitively, all
well-founded model is defined as
 =  +1. Basically,  is the least fixed point  [
          <xref ref-type="bibr" rid="ref9">9</xref>
          ]
        </p>
        <p>=  where  ≥
rules defining atoms in Π have a false body or depend on atoms in Π and so they cannot be
inferred as true. The greatest unfounded set, Π(), is the union of possible unfounded sets
Π. Let Π() be a transformation defined as the set of atoms  such that there exists a rule
 ∈ (Π) where  =  and  is true w.r.t. , we define
where ¬Π() = {  |  ∈ Π()}. Let 0 = ∅,  +1 =  ( ), with  ≥
Π() = Π() ∪ ¬Π()</p>
        <p>0, the (partial)
0 is the smallest ordinal such that</p>
        <sec id="sec-2-2-1">
          <title>Algorithm 1 compileProgram</title>
          <p>Input : A normal program</p>
          <p>Output : Prints evaluation procedure for 
for all  ∈  (, ) do</p>
          <p>(, , )
≪ while _ ̸= ∅ do≫
 = _.()≫
switch ()≫
for all  ∈ [1, . . . , ||] do
for all  ∈ (, ) do
if ([]) ∈  ∧ [] is positive literal then
≪
≪ done≫
≪ do≫
 = ⊥≫
for  ∈ ℬ do≫
 =  = ⊥≫
 = _.()≫
switch ()≫
done≫
≪ while  == ⊤ ≫
≪ end def≫</p>
          <p>((, ), )
Algorithm 2 compileRuleForHeadDerivation</p>
          <p>Input : A list of literals , an atom , a set of predicates</p>
          <p>Output : Prints a procedure that instantiates  and derives new atoms matching</p>
        </sec>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>3. Compilation of Well-founded Semantics</title>
      <p>
        In this section, we describe the compilation procedure for generating an ad-hoc solver for
an input program Π. In particular, proposed algorithms (see Algorithms 1-5) describe the
compilation of a normal program with not-stratified negation. However, our approach is also
able to generate simplified code for the case of Datalog programs with stratified negation that
is indeed a particular case. Reported algorithms follow the syntactic convention used in [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ].
To recall, the code enclosed between ≪≫
      </p>
      <p>is printed by the compiler as it is. Instead, the code</p>
      <p>JK
enclosed in</p>
      <p>, is first substituted with its run-time value and then is printed. For example, let
[] = (), Algorithm 1 at line 17 prints “case “” :”.</p>
      <p>Description of the Compilation Algorithms.</p>
      <sec id="sec-3-1">
        <title>As the first step, the compiler builds the</title>
        <p>dependency graph of Π (Alg. 1 lines 5-6) and computes its strongly connected components
SCCs, 1, ..., , that give us a topological order of Π such that no paths exist from  to 
if  &lt; . By following that order, the compiler produces for each component  the code that
evaluates the rules defining atoms in  (i.e., whose predicate belongs to ), referred to as  .
Then, each rule  is compiled into a sub-procedure that iterates over possible instantiations of
 that are either true or undefined w.r.t.  ∪ ℬ and, successively, derives  (Alg. 1 lines 9-10).
Such sub-procedures are generated by means of Algorithm 2. Algorithm 2 starts by calling
Algorithm 3 that prints diferent nested join loops or if statements for each literal in
. These
nested blocks implement iterations over possible rule instantiations (Alg. 3 lines 3-13). Inside
the deepest block, the code that collects negative dependencies within the component  into
the set  is printed (Alg. 3 lines 15-19). Then Algorithm 2 prints the code that derives new
atoms matching  by calling Algorithm 4. In particular, the code generated by Algorithm 4
checks if the current body (i.e. 1, · · ·</p>
        <p>, ) is true w.r.t.  ∪ ℬ. In particular, if all positive literals
belong to , no negative literals are undefined (i.e.
¬−
∩ ℬ), and no negative literals in the
same component occur in the current body (i.e.  = ∅), then all literals 1, · · ·
w.r.t. . Thus, if it is the case then the head of the rule is derived as true, otherwise it is derived
,  are true
as undefined (code generated by lines 5 and 10 of Alg. 4). In both cases, derived atoms are
collected into the derivation stack in order to be used in the second derivation phase. As the last
step, for each literal  ∈ , if  is a positive literal then a nested for-loop is closed by restoring
the variable substitution  (Alg. 2 lines 5-7). Otherwise, an if-statement scope is closed (Alg. 2
lines 8-9). The second derivation scenario is generated by looking at recursive rules defining
atoms whose predicate belongs to . In this case, the generated procedure will consume literals
collected into _ and, for each of them, diferent sub-procedures are executed according
to the predicate name of the consumed literal (Alg. 1 lines 11-13). In particular, the compiler, for
each rule , generates diferent switch-cases for each literal  ∈ + whose predicate belongs
to  (Alg. 1 lines 15-22). Inside each case, a sub-procedure that evaluates  starting from a
literal, , that matches  is generated. Each sub-procedure starts with the initialization of
a variable substitution  from variables in  to constant in  (Alg. 1 lines 18-21) and then
contains the code that evaluates the remaining part of , generated by Algorithm 2. In this
way, the generated procedure is able to simulate a semi-naive evaluation of recursive rules. Out
of the while-loop scope, the compiler generates the code that derives, if it is possible, undefined
atoms either as true or false (Alg. 1 lines 24-32). At this point, atoms in Π with predicates
in  that do not belong to  ∪  are considered false since no rule instantiations that can
derive them exists. Thus, the generated procedure, in this case, will iterate until some undefined
atoms (i.e. atoms belonging to ℬ) are derived either as true or false. For each iteration, the
generated procedure evaluates possible rules defining remaining atoms in ℬ and so diferent
switch-cases, one for each recursive rule , are generated. Each case contains the procedure
that evaluates a rule  starting from an undefined atom  that can be substituted to .
These sub-procedures are generated by Algorithm 5 that, for each switch-case, prints the code
that initializes a variable substitution  from variables in  to constants in  (Alg. 5</p>
      </sec>
      <sec id="sec-3-2">
        <title>Algorithm 3 compileRuleBody</title>
        <p>Input : A list of literals , a set of predicate</p>
        <p>Output : Prints the instantiation procedure for the rule body 
1 begin
2 ≪  =  ≫
3 for all  ∈ 1, ..., || do
4 ≪  JK =  ≫
5 if [] is a positive literal then
67 ≪≪ foJrKall = J{K ∈∈( ∪JKℬ)d|o≫ ℎ( ( J[]K ), )}≫
8 for all  ∈ 1, ..., |([])| do
9 if ([])[] is variable then
10 ≪  =  ∪ { J([])[]K ↦→ ( JK )[ JK ]}≫
lines 4-7) and then prints the nested block needed for evaluating  by means of Algorithm 3.
Then, inside the last nested level, the code for head derivation is generated (Alg. 5 lines 9-16). If
the conjunction 1, · · · , , with  = ||, is true w.r.t.  ∪ ℬ (i.e. all positive literals are in 
and all atoms appearing in some negative literals are not in ℬ, Alg. 5 line 10) then  is
derived as true, otherwise a flag variable stating that a ground rule with  as head and an
undefined body w.r.t.  ∪ ℬ exists is enabled (Alg. 5 line 15). Then, nested blocks’ scopes are
closed (Alg. 5 lines 17-22). After evaluating all switch-cases, if neither  has not been
derived as true nor the  flag is true then  is derived as false (Alg. 5 lines 23-27).
Example of Compilation. In order to help understanding the outcome of our compiler, an
example is described in the following. Consider the following program Π:
1 : ( ) ← (,  ), (, ),  ()
2 : () ←  (),  ()
3 : () ← (),  ()</p>
        <p>The SCCs of Π are 0 = {}, 1 = {}, 2 = {}, 3 = { }, 4 = {}, 5 = {, }.
Since for components , with  from 0 to 4, there are no rules the code produced for them is
empty and so let us focus on 5. In this case, 5 is the entire program so Algorithm 1 prints a
sub-procedure for each rule of Π. Algorithm 6 reports the code produced by Algorithm 2 for
rule 1.</p>
        <p>For evaluating 1, Algorithm 3 generates an external for-loop that iterates over ground
literals 1 that are not false w.r.t.  ∪ ℬ and match (,  ) (Alg. 6 lines 4-35). For every 1,
the variable substitution  is updated mapping  and  to the first and the second term of 1
respectively (Alg. 6 lines 6-7). Nested into this for-loop, another for-loop is printed to iterate
over ground literals 2 matching  ((, )) (Alg. 6 lines 9-33). Note that the application of
 to a literal will replace mapped variables with the value they are mapped to (i.e.  ↦→ 1
then  ((, )) = (1, )). Inside this for-loop  is updated by mapping  to the second term
of 2 (Alg. 6 lines 11-12). Then, the last literal to evaluate is  () and so, since the value
of  is already fixed by 2 then, the last nested block is an if-statement that checks whether
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
≪
≪
≪
≪
≪
≪
≪
≪
≪
≪
if ≫
≪
≪


if ≫
 =  ∪ {ℎ}≫
ℬ = ℬ ∖ {ℎ}≫
 =  = ⊤≫
else if ((+</p>
        <p>= ⊤≫
ℎ =  (</p>
        <p>J K )≫
if + ⊆  ∧ (¬− ∩ ℬ) = ∅ ∧ ℎ ∈/  then≫
=  ∪ { J()[]K ↦→ ()[ JK ]}≫</p>
        <p>∪ ¬− ) ∩ ℬ) ̸= ∅ ∧ ℎ ∈/  then≫
for all  ∈ [||, . . . , 1] do
if [] is positive literal then
else
is an instantiation of  and the generated code should derive the ( ) (Alg. 6 lines 20-30).
Thus, if the body is true w.r.t.  ∪ ℬ then ℎ =  (( )) is added to , otherwise it is added
. Then, Algorithm 1 produces other two analogues procedures also for 2 and 3. Since
in this case, recursive rules are 2 and 3, but no positive literals have predicates in 5 then
no switch-cases are generated at all and so the while-loop over _ can be omitted. Thus,
Algorithm 1 continues by printing the last derivation scenario as previously described. In
particular, Algorithm 7 reports the switch-cases generated by Algorithm 5 for rules 2 and
3 w.r.t. the component 5. The first switch-case refers to rule 2 (Alg. 7 lines 2-24) and so
it contains the code for evaluating 2 starting from a literal matching the (). Thus,  is
initialized by mapping  to the first term of  literal (Alg. 7 lines 3-4), and then the
nested blocks are generated according to 2 (Alg. 7 lines 5-13). Inside the last block, the head
derivation code has been printed (Alg. 7 lines 14-21). If the body instantiation 1, 2 is true w.r.t.
 ∪ ℬ then ℎ =  is derived as true, otherwise the  flag is enabled. The second
switch-case is analogous to the first one but it refers to 3 and so the evaluation starts from a
literal, , matching the atom ( ). Out of the scope of the switch-statement if no rule
instantiations have been founded for the atom  then it is derived as false (Alg. 7 lines 48-51).</p>
        <p>Algorithm 6 Output example compileRuleForHeadDerivation</p>
        <p>
          Input : {(,  ), (, ),  ()}, ( ), {′′,′ ′}
if  == ∅ ∧ + ⊆  ∧ (¬− ∩ ℬ) = ∅ then
 = 
done
done
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
else
ℬ = ℬ ∪ {ℎ}
_ = _ ∪ {ℎ}
 =  ∪ { ↦→ ()[
          <xref ref-type="bibr" rid="ref1">1</xref>
          ]}
done
case ’g’
        </p>
        <p>= 
Algorithm 7 Output example compileRulesForSupportDerivation
1 = { ∈ ( ∪ ℬ) | ℎ( (()), )}
done
if
if  = ⊥ ∧  = ⊥ then
 = ⊤
ℬ = ℬ ∖ {}</p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>4. Implementation and Experiments</title>
      <p>Implementation Details. The compilation strategy described in the previous section has
been entirely implemented in C++ and so both compiler and generated procedures are written
in C++. Generated code is built on top of optimized data structures that allow to speed up the
whole computation process. In particular, it uses a numerical representation of constant terms
that allows a compact and uniform representation. Moreover, diferent indexing structures
are used for each predicate. Indexes are defined on the subset of terms of predicates, for fast
retrieval of the list of literals that match a possible tuple.</p>
      <p>
        Benchmarks, Systems and Experiments Setup. In order to assess the performances of
the proposed approach we conducted an empirical evaluation both on positive programs (i.e.,
Datalog) and programs with negation. Among positive programs, we considered:
• Large-join problem [
        <xref ref-type="bibr" rid="ref11">11</xref>
        ] defined as follows:
(,  ) ← 1(, ), 2(,  ).
1(,  ) ← 1(, ), 2(,  ).
2(,  ) ← 3(, ), 4(,  ).
      </p>
      <p>1(,  ) ← 1(, ), 2(,  ).
where 1/2, 2/2, 2/2, 3/2, and 4/2 are defined as facts that represent an instance
of the problem. For this benchmark, we have generated instances of diferent sizes in
a random fashion. More precisely, for each instance, we set the size (number of facts)
roughly from 10000 to 10000000 and we randomly divided the number of facts among the
previous predicates (around 10-25% for each predicate). Then for each predicate , we
randomly estimated the max value for each term,  and , in such a way that  *  = ,
where  is the size of the predicate set of .
• Reachability problem defined as follows:</p>
      <p>ℎ(,  ) ← (,  ).</p>
      <p>ℎ(,  ) ← ℎ(, ), (,  ).</p>
      <p>Instances of this problem are directed graphs that we have generated varying the number
of nodes and the density of the edges. In particular, we considered graphs with a number
of nodes from 100 to 2000 and density 20, 40, 60, 80, and 100%.</p>
      <p>
        Among programs with negation, instead, we considered three hard benchmarks from asp
competitions that are Knight Tour with Holes, Stable Marriage, and Graph Colouring [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ].
      </p>
      <p>
        Our approach, labeled wf-comp, was compared with the following tools:
• General-purpose systems that can evaluate Datalog programs: idlv [
        <xref ref-type="bibr" rid="ref13">13</xref>
        ] and gringo [
        <xref ref-type="bibr" rid="ref14">14</xref>
        ]
• The souflé framework [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ] for which we have rewritten the encoding to produce a suitable
encoding for this framework. In particular, two versions have been considered, the
interpreted, souffle, and compiled, souffle-comp, ones.
• Compilation-based approach for stratified normal programs wasp-lazy [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ].
10
      </p>
      <p>20 30 40 50
Number of solved instances
60
1,800</p>
      <p>
        • ASP system dlv2 [
        <xref ref-type="bibr" rid="ref12">12</xref>
        ] that can evaluate normal programs under well-founded semantics.
All the experiments were executed on a machine equipped with Xeon(R) Gold 5118 CPUs,
running Ubuntu Linux (kernel 5.4.0-77-generic). Time and memory were limited to 1800
seconds and 8GB, respectively. Source code and benchmark suite are available at https://osf.io/
g9n2z/?view_only=aeb0777c469e46499247284b56dfb598
Evaluation on Positive Programs. In this comparison, we run the systems on instances of
large-join and reachability. Obtained results are summarized by the cactus plots in Figures 1-2.
)
s
(
e
m
i
T
n
o
i
t
u
c
e
x
E
      </p>
      <p>dlv2
wf-comp
Recall that a cactus plot reports a line for each system and each line contains a point (,  ) if
a given system is able to solve  within a time limit of  seconds.</p>
      <p>In both cases, wf-comp outperforms state-of-the-art ASP systems gringo and idlv solving
more instances (roughly 15 for reachability and 2 for large-join) and in less time overall. Our
approach also outperforms wasp-lazy on reachability problem solving 16 more instances than
the latter, while wf-comp is comparable on the large-join domain with wasp-lazy. The best
method in this comparison is souffle system. The diference with our tool ( souffle is preferable
in complete graphs) is due to diferent data structures and also to the diferent input formats.
Indeed, souffle takes as input a numeric format where input facts are organized in files for</p>
      <p>dlv2
wf-comp
40
80
120</p>
      <p>160</p>
      <p>Number of solved instances
each input predicate while wf-comp reads plain text files.</p>
      <p>Evaluation on Programs with Negation. In the case of programs with negation, we
compare wf-comp and dlv2 (the other methods do not support unrestricted negation). For each
considered benchmark we report a cactus plot see Figures 3, 4, and 5. Obtained results highlight
the strength of the proposed approach that outperforms dlv2 on considered benchmarks. In
particular, both systems are able to solve all problem instances within time and memory limits,
but wf-comp significantly reduced the total execution time for each benchmark (33.24% on
Graph Colouring, 63.26% on Knight Tour With Holes, and 22.37% on Stable Marriage).</p>
    </sec>
    <sec id="sec-5">
      <title>5. Conclusion</title>
      <p>
        Logic programming is a widely employed programming paradigm for modeling complex
problems in a declarative fashion. Eficient implementations are needed in order to exploit
the strength of such formalism in real-world applications. Compilation-based techniques
were revealed to be efective in tackling diferent issues raised in the evaluation of logic
programs [
        <xref ref-type="bibr" rid="ref4 ref6 ref7 ref8">4, 7, 6, 8</xref>
        ]. In this paper, we proposed a compilation-based approach for logic programs
under well-founded semantics. Obtained results demonstrate the efectiveness of the proposed
approach both for positive programs and programs with negation. The improvements are
significant on programs with negation while in the evaluation of positive programs our
implementation is competitive with existing systems. As future works, we planned to extend our
technique also to the class of disjunctive programs and to programs with aggregates (again
under the well-founded semantics). Also, there is space for improvements in the data structures
used for evaluating Datalog programs, where better performance could possibly be achieved
(especially on dense graphs) by employing more eficient indexing structures.
      </p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>J. W.</given-names>
            <surname>Lloyd</surname>
          </string-name>
          ,
          <source>Foundations of Logic Programming, 2nd Edition</source>
          , Springer,
          <year>1987</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>C.</given-names>
            <surname>Baral</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Gelfond</surname>
          </string-name>
          ,
          <article-title>Logic programming and knowledge representation</article-title>
          ,
          <source>The Journal of Logic Programming</source>
          <volume>19</volume>
          (
          <year>1994</year>
          )
          <fpage>73</fpage>
          -
          <lpage>148</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>E.</given-names>
            <surname>Dantsin</surname>
          </string-name>
          ,
          <string-name>
            <given-names>T.</given-names>
            <surname>Eiter</surname>
          </string-name>
          ,
          <string-name>
            <given-names>G.</given-names>
            <surname>Gottlob</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Voronkov</surname>
          </string-name>
          ,
          <article-title>Complexity and expressive power of logic programming</article-title>
          ,
          <source>ACM Comput. Surv</source>
          .
          <volume>33</volume>
          (
          <year>2001</year>
          )
          <fpage>374</fpage>
          -
          <lpage>425</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>H.</given-names>
            <surname>Jordan</surname>
          </string-name>
          ,
          <string-name>
            <given-names>B.</given-names>
            <surname>Scholz</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P.</given-names>
            <surname>Subotic</surname>
          </string-name>
          , Souflé:
          <article-title>On synthesis of program analyzers</article-title>
          , in: S. Chaudhuri,
          <string-name>
            <surname>A</surname>
          </string-name>
          . Farzan (Eds.),
          <source>Computer Aided Verification - 28th International Conference, CAV 2016</source>
          , Toronto, ON, Canada,
          <source>July 17-23</source>
          ,
          <year>2016</year>
          , Proceedings,
          <string-name>
            <surname>Part</surname>
            <given-names>II</given-names>
          </string-name>
          , volume
          <volume>9780</volume>
          of Lecture Notes in Computer Science, Springer,
          <year>2016</year>
          , pp.
          <fpage>422</fpage>
          -
          <lpage>430</lpage>
          . URL: https: //doi.org/10.1007/978-3-
          <fpage>319</fpage>
          -41540-6_
          <fpage>23</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>B.</given-names>
            <surname>Cuteri</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C.</given-names>
            <surname>Dodaro</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F.</given-names>
            <surname>Ricca</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P.</given-names>
            <surname>Schüller</surname>
          </string-name>
          ,
          <article-title>Partial compilation of ASP programs</article-title>
          ,
          <source>Theory Pract. Log. Program</source>
          .
          <volume>19</volume>
          (
          <year>2019</year>
          )
          <fpage>857</fpage>
          -
          <lpage>873</lpage>
          . URL: https://doi.org/10.1017/S1471068419000231.
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>B.</given-names>
            <surname>Cuteri</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C.</given-names>
            <surname>Dodaro</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F.</given-names>
            <surname>Ricca</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P.</given-names>
            <surname>Schüller</surname>
          </string-name>
          ,
          <article-title>Overcoming the grounding bottleneck due to constraints in ASP solving: Constraints become propagators</article-title>
          , in: C.
          <string-name>
            <surname>Bessiere</surname>
          </string-name>
          (Ed.),
          <source>Proceedings of the Twenty-Ninth International Joint Conference on Artificial Intelligence, IJCAI</source>
          <year>2020</year>
          ,
          <article-title>ijcai</article-title>
          .org,
          <year>2020</year>
          , pp.
          <fpage>1688</fpage>
          -
          <lpage>1694</lpage>
          . URL: https://doi.org/10.24963/ijcai.
          <year>2020</year>
          /234.
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>B.</given-names>
            <surname>Cuteri</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F.</given-names>
            <surname>Ricca</surname>
          </string-name>
          ,
          <article-title>A compiler for stratified datalog programs: preliminary results</article-title>
          , in: S. Flesca,
          <string-name>
            <given-names>S.</given-names>
            <surname>Greco</surname>
          </string-name>
          ,
          <string-name>
            <given-names>E.</given-names>
            <surname>Masciari</surname>
          </string-name>
          , D. Saccà (Eds.),
          <source>Proceedings of the 25th Italian Symposium on Advanced Database Systems</source>
          , Squillace Lido (Catanzaro), Italy, June 25-29,
          <year>2017</year>
          , volume
          <volume>2037</volume>
          <source>of CEUR Workshop Proceedings, CEUR-WS.org</source>
          ,
          <year>2017</year>
          , p.
          <fpage>158</fpage>
          . URL: http://ceur-ws.
          <source>org/</source>
          Vol-2037/paper_23.pdf.
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>G.</given-names>
            <surname>Mazzotta</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F.</given-names>
            <surname>Ricca</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C.</given-names>
            <surname>Dodaro</surname>
          </string-name>
          ,
          <article-title>Compilation of aggregates in ASP systems</article-title>
          , in: AAAI, AAAI Press,
          <year>2022</year>
          , pp.
          <fpage>5834</fpage>
          -
          <lpage>5841</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <given-names>A.</given-names>
            <surname>Van Gelder</surname>
          </string-name>
          ,
          <string-name>
            <given-names>K. A.</given-names>
            <surname>Ross</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J. S.</given-names>
            <surname>Schlipf</surname>
          </string-name>
          ,
          <article-title>The well-founded semantics for general logic programs</article-title>
          ,
          <source>J. ACM</source>
          <volume>38</volume>
          (
          <year>1991</year>
          )
          <fpage>620</fpage>
          -
          <lpage>650</lpage>
          . URL: https://doi.org/10.1145/116825.116838.
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10]
          <string-name>
            <given-names>M.</given-names>
            <surname>Gebser</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Maratea</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F.</given-names>
            <surname>Ricca</surname>
          </string-name>
          ,
          <article-title>The sixth answer set programming competition</article-title>
          ,
          <source>Journal of Artificial Intelligence Research</source>
          <volume>60</volume>
          (
          <year>2017</year>
          )
          <fpage>41</fpage>
          -
          <lpage>95</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          [11]
          <string-name>
            <given-names>S.</given-names>
            <surname>Liang</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P.</given-names>
            <surname>Fodor</surname>
          </string-name>
          ,
          <string-name>
            <given-names>H.</given-names>
            <surname>Wan</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Kifer</surname>
          </string-name>
          ,
          <article-title>Openrulebench: an analysis of the performance of rule engines</article-title>
          , in: J.
          <string-name>
            <surname>Quemada</surname>
            , G. León,
            <given-names>Y. S.</given-names>
          </string-name>
          <string-name>
            <surname>Maarek</surname>
          </string-name>
          , W. Nejdl (Eds.),
          <source>Proceedings of the 18th International Conference on World Wide Web, WWW</source>
          <year>2009</year>
          , Madrid, Spain,
          <source>April 20-24</source>
          ,
          <year>2009</year>
          , ACM,
          <year>2009</year>
          , pp.
          <fpage>601</fpage>
          -
          <lpage>610</lpage>
          . URL: https://doi.org/10.1145/1526709.1526790.
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          [12]
          <string-name>
            <given-names>M.</given-names>
            <surname>Alviano</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F.</given-names>
            <surname>Calimeri</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C.</given-names>
            <surname>Dodaro</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.</given-names>
            <surname>Fuscà</surname>
          </string-name>
          ,
          <string-name>
            <given-names>N.</given-names>
            <surname>Leone</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Perri</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F.</given-names>
            <surname>Ricca</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P.</given-names>
            <surname>Veltri</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Zangari</surname>
          </string-name>
          ,
          <article-title>The ASP system DLV2, in: Logic Programming and Nonmonotonic Reasoning -</article-title>
          14th International Conference, LPNMR 2017, Espoo,
          <source>Finland, July 3-6</source>
          ,
          <year>2017</year>
          , Proceedings, volume
          <volume>10377</volume>
          of Lecture Notes in Computer Science,
          <year>2017</year>
          , pp.
          <fpage>215</fpage>
          -
          <lpage>221</lpage>
          . URL: https://doi.org/10.1007/ 978-3-
          <fpage>319</fpage>
          -61660-5_
          <fpage>19</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          [13]
          <string-name>
            <given-names>F.</given-names>
            <surname>Calimeri</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.</given-names>
            <surname>Fuscà</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Perri</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Zangari</surname>
          </string-name>
          ,
          <string-name>
            <surname>I-DLV</surname>
          </string-name>
          :
          <article-title>the new intelligent grounder of DLV, Intelligenza Artificiale 11 (</article-title>
          <year>2017</year>
          )
          <fpage>5</fpage>
          -
          <lpage>20</lpage>
          . URL: https://doi.org/10.3233/IA-170104.
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          [14]
          <string-name>
            <given-names>M.</given-names>
            <surname>Gebser</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Kaminski</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>König</surname>
          </string-name>
          , T. Schaub,
          <source>Advances in gringo series 3</source>
          , in: J. P. Delgrande, W. Faber (Eds.),
          <source>Logic Programming and Nonmonotonic Reasoning - 11th International Conference, LPNMR 2011</source>
          , Vancouver, Canada, May
          <volume>16</volume>
          -19,
          <year>2011</year>
          . Proceedings, volume
          <volume>6645</volume>
          of Lecture Notes in Computer Science,
          <year>2011</year>
          , pp.
          <fpage>345</fpage>
          -
          <lpage>351</lpage>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>