<!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>A simple framework for theta-subsumption testing in Prolog</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Hendrik Blockeel</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Svetlana Valevich</string-name>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Department of Computer Science</institution>
          ,
          <addr-line>KU Leuven</addr-line>
        </aff>
      </contrib-group>
      <fpage>14</fpage>
      <lpage>19</lpage>
      <abstract>
        <p>We present a simple framework for theta-subsumption testing in Prolog. In its simplest instantiation, it yields an algorithm that takes only a few dozen lines of code. Despite its simplicity, the framework has turned out to work very well on data where a state-of-the-art subsumption engine su ered from excessive run times. The framework can easily be instantiated in di erent ways, precisely because of its simplicity, and can o er an interesting view on how existing methods compare to each other.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction</title>
      <p>2.1</p>
    </sec>
    <sec id="sec-2">
      <title>Theta-subsumption</title>
      <sec id="sec-2-1">
        <title>De nition</title>
        <p>We assume familiarity with standard terminology from logic programming and
relational databases, and with Prolog. Theta-subsumption, or brie y
subsumption, is de ned as follows: A clause c theta-subsumes another clause d, denoted
c d, if and only if there exists a variable substitution such that c d.
2.2</p>
      </sec>
      <sec id="sec-2-2">
        <title>Testing theta-subsumption in Prolog</title>
        <p>We assume clauses are represented as lists of literals. The following code can
then be used to test whether a clause C subsumes a clause D:
subsumes(C,D) :- \+ \+ (copy_term(D,D2), numbervars(D2,0,_), subset(C,D2)).
subset([], D).</p>
        <p>subset([A|B], D) :- member(A, D), subset(B,D).</p>
        <p>It makes a copy D2 of D to rename its variables apart from those in C, then
skolemizes D2 (i.e., instantiates each variable in it to a di erent constant), and
tries to unify C with a subset of D2. Skolemizing D2 avoids that the uni cation
procedure applies variable substitutions to both C and D, instead of only to C.
The double negation (\+ \+) ensures that the uni cations do not survive the
call, so that subsumes(C,D) does not have any side e ects.</p>
        <p>This code exploits Prolog's uni cation and backtracking mechanisms. A call
to member(A,D) may have multiple solutions, requiring di erent substitutions for
the variables in A. Some of these substitutions may make other literals (which
share variables with A) un-uni able with any member of D. This may be noticed
only later on. Prolog then has to backtrack and try other substitutions for A.</p>
        <p>When the rst clause contains variables, the subset predicate de nes a search
through the space of all possible variable substitutions. The size of this space is
the product of the number of possible instantiations for each variable, and hence
exponential in the number of variables occurring in C.
2.3</p>
      </sec>
      <sec id="sec-2-3">
        <title>Partitioning into independent components</title>
        <p>
          A simple way to make the search more e cient is to rst partition the clause C
into minimal subsets such that di erent subsets share no variables. The choice of
a substitution for one subset then cannot a ect the existence of a substitution for
another subset. Each subset can then be tested separately using the code listed
above. The complexity of this method is exponential in the largest number of
variables in any one subset (as opposed to the total number of variables).
Example 1. Let C = fp(X); q(X; Y ); r(Z; 2))g and D = fp(
          <xref ref-type="bibr" rid="ref1">1</xref>
          ); p(
          <xref ref-type="bibr" rid="ref2">2</xref>
          ); p(
          <xref ref-type="bibr" rid="ref3">3</xref>
          ); p(
          <xref ref-type="bibr" rid="ref4">4</xref>
          );
q(2; a); q(4; b); r(b; 1)g. After nding a substitution for p(X) and q(X,Y), Prolog
tries to nd a substitution for r(Z,2). There is none. Prolog will then backtrack,
trying to nd a di erent substitution for X and Y . But it is clear that none of
these alternatives will change the fact that no substitution exists for Z that
makes r(Z,2) an element of D. Alternative solutions for X and Y do not a ect
the existence of solutions for Z. Therefore, it is more e cient to split C into
C1 = fp(X); q(X; Y )g and C2 = fr(Z; 2)g and perform the search for each of
these separately. The complexity of this is O(jSXY j+jSZ j) instead of O(SXY Z ) =
O(jSXY j jSZ j).
        </p>
        <p>
          The splitting of clauses into independent parts, each solved separately, is a
crucial element in all e cient theta-subsumption testers.
c: p(a,X,Y), p(b,Y,X), q(Y,Z), r(Y)
d: p(a,1,2), p(a,3,5), p(a,1,0), p(b,1,1), p(b,5,3), p(b,1,0), p(b,2,0), q(5,a), q(3,b), r(
          <xref ref-type="bibr" rid="ref1">1</xref>
          ), r(
          <xref ref-type="bibr" rid="ref2">2</xref>
          ), r(
          <xref ref-type="bibr" rid="ref3">3</xref>
          )
p(b,Y,X),
q(Y,Z),
r(Y)
d: p(a,1,2), p(a,3,5), p(a,1,0), p(b,1,1), p(b,5,3), p(b,1,0), p(b,2,0), q(5,a), q(3,b), r(
          <xref ref-type="bibr" rid="ref1">1</xref>
          ), r(
          <xref ref-type="bibr" rid="ref2">2</xref>
          ), r(
          <xref ref-type="bibr" rid="ref3">3</xref>
          )
X
3
        </p>
        <p>Y
5
In the context of testing C D, let d be the skolemized version of D and c
one of the independent subsets of C. A solution is a variable substitution such
that c d. A literal l1 matches a literal l2 if and only if a variable substitution
exists such that l1 = l2. The instantiation list of a literal l 2 c is the set of
all literals l0 2 d that match l. Figure 1 shows an example pair of clauses c and
d (a), and for each literal in c the matching literals in d (b).</p>
        <p>Using terminology from relational databases, we de ne the instantiation table
of a literal l as a table with as attributes the variables in l, and as tuples the
value combinations for these variables that occur in the instantiation list. An
instantiation table is simply a di erent representation for an instantiation list.
Figure 1(c) shows the instantiation tables of the four literals in c.</p>
        <p>Note that the instantiation tables serve as constraints on the possible
instantiation of tuples of variables. Let T be an instantiation table and X the set of
variables corresponding to its attributes. Any solution must instantiate X such
that X occurs in T . Therefore:
{ when tables T and T 0 have the same attribute set, attr(T ) = attr(T 0), they
can be replaced by a single table that contains their intersection.
{ more generally, when attr(T ) attr(T 0), all t0 2 T 0 for which attr(T )(t0) 62 T
can be removed from T 0, and after doing this, T can be dropped (it no longer
imposes a constraint that is not already imposed by T 0)
{ even more generally, let A = attr(T ) \ attr(T 0); when A 6= ;, all tuples t0
of T 0 for which A(t0) 62 A(T ) can be removed from T 0, and vice vera, all
t 2 T for which A(t) 62 A(T 0) can be removed from T .
When the search space can no longer be reduced in the way described, an
exhaustive search is needed. The following procedure is then recursively applied: choose
a table T ; for each tuple t 2 T : lter the other tables by leaving out all tuples
incompatible with t (that is, remove each t0 2 T 0 such that A(t0) 62 A(T ) with
A = attr(T ) \ attr(T 0)); call the search procedure recursively on the resulting
set of tables. When there are no tables left to choose from, a solution has been
found. If at any point, a table becomes empty, the search must backtrack and
choose the next t; if no alternatives for t are left, this means no solutions exist.</p>
        <p>The selection of T can be done according to a heuristic. Ideally, it maximally
reduces the search space. A table with n attribute, each with domain size m, has
domain size mn. Of all values in this domain, only the tuples in the table are
valid; so, if the table contains l tuples, the search space is reduced by a factor
mn=l (compared to exhaustively trying all values). This factor can be used as
a heuristic. Another factor to take into account is: in how many other tables
lists do the attributes occur, and to what extent will those tables be reduced?
Finally, as observed by Santos and Muggleton [5], the instantiation may cause
further decomposition of the clause. A heuristic that tries to maximize such
decomposition is likely to be advantageous.
The above points give rise to a simple algorithm for e cient subsumption
testing. A number of auxiliary functions and procedures of the algorithm can be
instantiated in di erent manners. The algorithm thus gives rise to a framework
that we an easily experiment with.</p>
        <p>Our current implementation uses a very simple and rough heuristic: it simply
uses 5n=l (that is, it assumes an average domain size of 5). It performs semi-joins
until a xpoint is reached. The ltering during the search uses a single step of
semi-joining the chosen tuple with the other tables. Decomposition into
independent components is done only at the beginning, not after each instantiation.
2.7</p>
      </sec>
      <sec id="sec-2-4">
        <title>Situating existing methods in this framework</title>
        <p>Existing subsumption algorithms can be situated within this framework, making
it easier to explain and compare them. We focus on Subsumer [5], Resumer [3],
Django [4], and the algorithm proposed by Sche er, Herbrich and Wysotzky [6],
which we call SHW here. For lack of space, we focus on two main di erences.</p>
        <p>All methods mentioned above phrase the problem as a constraint
programming problem and use advanced constraint solving methods. An important
difference among methods is in how they de ne the variables and domains for the
solver. Subsumer and Resumer use as variables the logical variables that
occur in the clauses. Django and SHW use as variables the literals in c, and as
possible values the (matching) literals in d. From the constraint solving point
of view, our method uses tuples of logical variables as the variables to solve
for, and tuples of values as their values. The use of single variables is inherently
less e cient, as information about which combinations of values occur in clause
d is ignored. Using variable tuples as opposed to literals has the advantage that
when the same tuple of variables occurs in multiple literals, only one variable is
introduced for them in the constraint solver.</p>
        <p>Instantiating a variable tuple may cause a connected component to
decompose into independent components. Subsumer is the only method to exploit this.
Santos and Muggleton showed that this can yield important e ciency gains [5].
The idea can easily be incorporated into our framework. The selection heuristic
can be adapted to take the ensuing search space reduction into account.
3</p>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>Experimental Evaluation</title>
      <p>This work was motivated by work on learning language from sentences in a
context, where the context is described as a logical interpretation [1, 2]. The
incremental learning algorithm proposed there repeatedly computes lggs, which
themselves involve multiple subsumption tests, and the straightforward
implementation of subsumption testing quickly turned out too slow. Somewhat to our
surprise, also Subsumer, the most recently proposed subsumption engine, turned
out to be problematically slow on some cases. Repeated attempts to improve our
own straightforward subsumption algorithm yielded a simple instantiation of the
framework described above.</p>
      <p>We compared the runtimes of Subsumer and our algorithm, dubbed Subtle,3
on a dataset of 10000 sentence/context examples. Due to the NP-hardness of the
problem, average timings take very long to obtain and are not very informative
(they are strongly in uenced by the heavy tails of the runtime distribution).
We have therefore followed the following methodology. The incremental learner
processes examples one by one. When the processing of a single example takes
over a minute (indicating that it gave rise to a \di cult" pair of clauses), the
example is commented out and the learner restarted. As more and more such
3 \SUBsumption Testing with Little E ort"
\problematic" examples are removed, the learner gets further into the dataset
before getting stuck. After removing 10 problematic examples, we stopped.</p>
      <p>Subsumer had its 10th problematic example at index 73. Subtle had only 7
problematic examples; the remaining 9993 were processed in 27 minutes.</p>
      <p>On one benchmark included in the Subsumer distribution (speci cally, testing
40 hypotheses from the le hyp1 00.pl on the 400 examples in exs 00.pl), we
found CPU time ratios for Django, Subsumer and Subtle of roughly 1:5:30. On
separate sets of subsumption problems generated from the language learning
problem, we found the ratios of roughly 1: { : 5 on one dataset, and { : 7 : 12
on another dataset, where { indicates that the system did not run to completion
(due to memory problems or excessive time). While Subtle is not the fastest
method on either dataset, it is the only one that could handle both.</p>
      <p>All this indicates that di erent methods are best for di erent datasets, and
a versatile framework is therefore useful. We believe that our simple framework
can o er that versatility, but more experiments are needed to con rm this.
4</p>
    </sec>
    <sec id="sec-4">
      <title>Conclusions</title>
      <p>We have proposed an framework for testing theta-subsumption that is easy to
understand, easy to implement in Prolog, and signi cantly outperforms a
stateof-the-art system on a practically motivated problem. Given the NP-hardness of
theta subsumption, it is to be expected that di erent algorithms will be optimal
under di erent circumstances. An important advantage of our framework is that
it can easily be adapted to di erent types of datasets. The simplicity of the
framework also makes it possible to incorporate ideas from di erent existing
systems into it.</p>
      <p>A more extensive experimental evaluation is needed to evaluate the true
potential of the method. This will include experiments on a variety of datasets,
and with di erent instantiations of the method.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <surname>Becerra-Bonache</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Blockeel</surname>
            ,
            <given-names>H.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Galvan</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Jacquenet</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          :
          <article-title>A rst-order-logic based model for grounded language learning</article-title>
          .
          <source>In: Proc. 14th Int'l Symp. on Intelligent Data Analysis (IDA</source>
          <year>2015</year>
          ). pp.
          <volume>49</volume>
          {
          <issue>60</issue>
          (
          <year>2015</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <surname>Becerra-Bonache</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Blockeel</surname>
            ,
            <given-names>H.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Galvan</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Jacquenet</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          :
          <article-title>Relational grounded language learning</article-title>
          .
          <source>In: Proc. 22nd Eur. Conf. on Artif. Int</source>
          . pp.
          <volume>1764</volume>
          {
          <issue>1765</issue>
          (
          <year>2016</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <surname>Kuzelka</surname>
            ,
            <given-names>O.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Zelezny</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          :
          <article-title>A restarted strategy for e cient subsumption testing</article-title>
          .
          <source>Fundam. Inform</source>
          .
          <volume>89</volume>
          (
          <issue>1</issue>
          ),
          <volume>95</volume>
          {
          <fpage>109</fpage>
          (
          <year>2008</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <surname>Maloberti</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Sebag</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          :
          <article-title>Fast theta-subsumption with constraint satisfaction algorithms</article-title>
          .
          <source>Machine Learning</source>
          <volume>55</volume>
          (
          <issue>2</issue>
          ),
          <volume>137</volume>
          {
          <fpage>174</fpage>
          (
          <year>2004</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <surname>Santos</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Muggleton</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          :
          <article-title>Subsumer: A prolog theta-subsumption engine</article-title>
          .
          <source>In: Technical Communications of the 26th International Conference on Logic Programming</source>
          ,
          <source>ICLP 2010, July 16-19</source>
          ,
          <year>2010</year>
          , Edinburgh, Scotland, UK. pp.
          <volume>172</volume>
          {
          <issue>181</issue>
          (
          <year>2010</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6. Sche er, T.,
          <string-name>
            <surname>Herbrich</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Wysotzki</surname>
          </string-name>
          , F.:
          <article-title>E cient theta-subsumption based on graph algorithms</article-title>
          .
          <source>In: Inductive Logic Programming</source>
          , 6th International Workshop, ILP-
          <volume>96</volume>
          , Stockholm, Sweden,
          <source>August 26-28</source>
          ,
          <year>1996</year>
          ,
          <string-name>
            <given-names>Selected</given-names>
            <surname>Papers</surname>
          </string-name>
          . pp.
          <volume>212</volume>
          {
          <issue>228</issue>
          (
          <year>1996</year>
          )
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>