<!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>Labelled Variables in Logic Programming: A First Prototype in tuProlog</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Roberta Calegari</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Enrico Denti</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Andrea Omicini</string-name>
          <email>andrea.omicinig@unibo.it</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Dipartimento di Informatica, Scienza e Ingegneria (DISI) Alma Mater Studiorum</institution>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Universita di Bologna</institution>
          ,
          <country country="IT">Italy</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>We present the rst prototype of Labelled tuProlog, an extension of tuProlog exploiting labelled variables to enable a sort of multiparadigm / multi-language programming aimed at pervasive systems.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Motivation</title>
      <p>
        To face the challenges of today pervasive system, which are inherently complex,
distributed, situated [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ] and intelligent, suitable models and technologies are
required to e ectively support distributed situated intelligence. To this end, in this
paper we investigate a logic programming (LP) extension based on labelled
variables, and test it by means of a prototype rooted in the tuProlog system [
        <xref ref-type="bibr" rid="ref3 ref9">3, 9</xref>
        ],
called Labelled tuProlog. Our general aim is to de ne a unique blend of LP and
labelled variables { a sort of multi-paradigm and multi-language programming
framework for a distributed environment { where diverse computational models
can be tailored to the local needs of situated systems by means of suitable
labelled variables systems, and work together against the common LP background
according to the original tuProlog aim [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ].
      </p>
      <p>
        Our work builds upon the general notion of label de ned by Gabbay [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ], and
adopts the techniques introduced by Holzbaur [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ] to develop a generalisation of
LP where labels are exploited to de ne computations in domain-speci c contexts,
while retaining the conventional syntax of LP. More generally, our work moves
from the observation that pervasiveness of today systems requires awareness of
the environment as well as the ability of reacting to changes. This mandates for
models promoting system intelligence, and for technologies making it possible to
spread intelligence wherever needed. While logic-based approaches are natural
candidates for intelligent systems, a pure LP approach seems not to t the needs
of situated systems. Instead, a hybrid approach would make it possible to exploit
LP for what it is most suited { symbolic computation {, while possibly delegating
other aspects (such as situated computations) to other languages, or to other
levels of computation. This is precisely where the notion of labelled variables
can be of help: by enabling some parts of the computation to be expressed at a
separate level, while retaining the general coherence of the LP approach.
      </p>
      <p>Being light-weight, intentionally designed around a minimal core, and
Javabased, tuProlog is an ideal candidate to support the above goal|distributing
situated intelligence while supporting labelled-variable-based computations.</p>
      <p>
        While several works exists in this area { such as [
        <xref ref-type="bibr" rid="ref1 ref8">8, 1</xref>
        ] { they mostly focus onto
speci c scenarios and sorts of systems|e.g. modal logic, deductive systems, fuzzy
systems, etc. Instead, our model aims at providing a general-purpose mechanism
that could t several relevant context-speci c systems, while seamlessly rooted
in the LP framework.
      </p>
      <p>
        While in our rst prototype labels are only applied to variables { and not
generally to formulas like in Gabbay [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ] { the proposed notion of label is already
general enough to capture Holzbaur's attribute variables [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ], opening the way
towards the expressiveness and the computational power of Constraint Logic
Programming (CLP) [
        <xref ref-type="bibr" rid="ref10 ref5">10, 5</xref>
        ]|which is why the two case studies presented below
assume CLP as the reference label domain.
2
      </p>
    </sec>
    <sec id="sec-2">
      <title>The Labelled Variables Model in Logic Programming</title>
      <p>A Labelled Variables Model for Logic Programming is de ned by:
{ a set of basic labels b1,. . . , bn, each with the form of a logic term, which
represent entities in the domain of labels ;
{ a set of labels, each de ned as a set of basic labels|i.e., li = fb1i; ::; bnig;
{ a labelling association hv; li, associating label l to variable v: as a convenient
shortcut, such association can be written as vl;
{ a combining function fL, synthesising a new label from two given ones,
combining the two labels according to some scenario-speci c criteria.
The uni cation of two labelled variables is represented by the extended tuple
(true/false, , label) where true/false represents the existence of an answer,
represents the most general substitution, and label represents the new label
associated to the uni ed variables de ned by the combining function fL. Figure
1 reports the uni cation rules for two generic terms T1 and T2: to lighten the
notation, unde ned elements in the tuple are omitted|i.e., labels or
substitutions that do not exist/do not apply in a particular situation. Since, by design,
only variables can be labelled here, the only case to be added to the standard
uni cation table is represented by labelled variables.</p>
      <p>While this choice clearly con nes the impact of labelling, keeping the label
computational model well separate from the LP one, it is also too restrictive in
practice: in fact, application scenarios often need to express some relevant
properties via by suitable terms, so that they can in uence the label computation.
For this purpose, we introduce the notion of label-interpreted terms, as a set of
semantically-relevant terms in the domain of labels, along with a pre-processing
phase, where each label-interpreted term is intercepted and replaced with an
anonymous variable labelled with that term. In this way, any special term in the
domain of label can be treated normally by the fL combining function, with no
need to change the basic model above.
3</p>
    </sec>
    <sec id="sec-3">
      <title>Prototype in tuProlog</title>
      <p>In this Section we apply our model in the context of the tuProlog system,
designing a tuProlog extension that enables users to de ne their own labelled
applications for their speci c domains of interest.
3.1</p>
      <sec id="sec-3-1">
        <title>System architecture</title>
        <p>
          Since tuProlog is Java-based, a language extension can be provided both as a
Prolog meta-level or library, or via suitable Java methods [
          <xref ref-type="bibr" rid="ref3">3</xref>
          ]. We support both
ways, de ning rst a Prolog-language level to denote labelled variables, then two
language extensions (Prolog-based and Java-based) to be used in alterative to
denote the labelled application (Subsection 3.2).
        </p>
        <p>Moreover, practical reasons suggest to avoid the proliferation of anonymous
variables in the pre-processing phase, since they would pollute the name space
and make the code less readable: for this reason, the prototype adopts a language
shortcut to specify the label of a term directly, with no need to actually replace
terms with unbound variables explicitly. However, this is just a linguistic
extension { not a model extension {, thus leaving the model properties untouched.
3.2</p>
      </sec>
      <sec id="sec-3-2">
        <title>The language extension</title>
        <p>In order to enable users to de ne their labelled application, a suitable set of
Prolog predicates / Java methods is introduced to let users de ne: (i) the
label/variable association; (ii) the function fL that speci es under which conditions
two labels unify in the selected domain, returning the new label associated with
the uni ed term; (iii) a shortcut for the pre-processing transformation, moving
label-interpreted terms to the label world, making them labels of unde ned
variables. For the sake of brevity, we show here how to express the three entities just
on the Prolog side only|the Java side being conceptually identical.
{ the label/variable association is expressed by the label associate(+Var,
+Term ) predicate, which associates variable Var to label Term ; as a further
convenience, the °/2 in x operator is also provided for the same purpose.
{ the function fL is expressed by the label generate(+Label1, +Label2,
-Label3 ) predicate, which encodes how to build a new label from two given
ones.
{ the pre-processing phase is embedded in the label interpret(+Label,
+Term ) helper predicate, which succeeds if Term can potentially be
unied with the label Label in the label world, or fails otherwise. Only if the
check succeeds, the labelled variable is actually uni ed with the term.
4</p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>Case studies</title>
      <p>
        In the following we present two application examples: Interval CLP [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ] and Dress
Selection based on colour-match rules. There, gures show both the syntax (left),
and the prototype screenshot (right), which sometimes di ers due to the current
implementation shortcuts, as discussed below.
      </p>
      <sec id="sec-4-1">
        <title>4.1 Interval CLP</title>
        <p>In this application scenario, variables are labelled with their admissible numeric
interval|that is, X°[A,B] means that X can span over the range [A::B]. Uni
cation succeeds if two numeric intervals overlap, in which case the intersected
interval is the newly-computed label. Being speci c of the application scenario,
the behaviour is de ned by the fL function.</p>
        <p>
          In the code in Figure 2 (top), labelled variable Y is uni ed with labelled
variable X: the operation succeeds (X/Y), with both variables receiving the new
label [
          <xref ref-type="bibr" rid="ref2 ref3">2,3</xref>
          ]. Conversely, in the subsequent case the uni cation fails, because the
intersected interval is empty.
        </p>
        <p>
          In the third case, three aspects are worth highlighting. First of all, an explicit
uni cation is needed to link an unlabelled logic variable (X) to a labelled variable
(X°[
          <xref ref-type="bibr" rid="ref2 ref5">2,5</xref>
          ]). The second aspect concerns the last term: because the shortcut
notation Z°plus(X,Y) is not yet supported by the prototype, the uni cation with
a new (possibly anonymous) variable must be made explicit (Z= °plus(X,Y)).
This is why an auxiliary variable (T) is introduced|but Z could have been reused
in alternative, as above. Finally, plus(X,Y) is an example of a label-interpreted
term (whose meaning is obvious) requiring pre-processing.
4.2
        </p>
      </sec>
      <sec id="sec-4-2">
        <title>Dress Selection</title>
        <p>Here, the goal is to select from the wardrobe all the shirts that respect some given
colour constraints: the domain of labels includes then shirts and their colours.</p>
        <p>The predicate shirt(Colour,Description ) represents a shirt with of
colour Colour , expressed in terms of its RGB composition { a triple like
rgb(Red,Green,Blue ) {, synthetically described by Description . This means
that in standard LP the knowledge representation would include facts like
shirt(rgb(255,255,255), amy white blouse), and alike.</p>
        <p>In the labelled context, however, the objective is to move relevant information
to the domain of labels. Since labels can only be attached to variables, a di erent
knowledge representation is adopted, where Colour is seen as a labelled variable,
having the rgb/3 term above as its label. Accordingly, the wardrobe content
representation is as follows:
shirt(Argb(255,240,245), pink blouse).
shirt(Brgb(255,222,173), yellow tshirt).
shirt(Crgb(119,136,153), army tshirt).
shirt(Drgb(188,143,143), periwinkle blouse).</p>
        <p>shirt(Ergb(255,245,238), cream blouse).</p>
        <p>To obtain all the shirts in the wardrobe, a query such as</p>
        <p>?- shirt(Colour, Description)
would obviously generate all the possible solutions in backtracking (Figure 3,
top). By suitable exploiting labelled variables, however, the query can be re ned
by de ning a target colour in the goal, and exploiting the combining function to
get only the dresses whose dress colour is \similar enough" to the target.</p>
        <p>To this end, two RGB colours c1 = rgb(r1; g1; b1) and c2 = rgb(r2; g2; b2) are
considered similar { so, the corresponding labels unify { if their distance is below
a given threshold. For the sake of concreteness, we assume the threshold to be
100, and the colour distance to be normalised and computed as a distance in
a 3D Euclidean space.</p>
        <p>The fL function, checking whether two given labels (c1=target colour and
c2=dress colour ) are to be considered as similar, can be de ned as:
fL(c1; c2) =
(c2 if distance(c1; c2)</p>
        <p>threshold 2 [0::100]
fg if distance(c1; c2) &gt; threshold 2 [0::100]
During the uni cation of the two labelled variables whose label represent the
target colour and the dress colour, the following steps are performed: if the
dress colour is similar to the target colour, the returned label is dress colour |
that is, the colour of the selected shirt; if, instead, the two colours are not similar,
the empty label is returned, causing the uni cation process to fail.</p>
        <p>Now let us look for all the shirts similar to the papaya colour : assuming a
normalised similarity threshold of 30 (max is 100), the system returns just three
solutions (Figure 3, bottom) instead of the ve available in un unconstrained
world (Figure 3, top), thus actually pruning the solution tree.</p>
      </sec>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <surname>Alsinet</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          , Chesn~evar,
          <string-name>
            <given-names>C.I.</given-names>
            ,
            <surname>Godo</surname>
          </string-name>
          ,
          <string-name>
            <given-names>L.</given-names>
            ,
            <surname>Simari</surname>
          </string-name>
          ,
          <string-name>
            <surname>G.R.:</surname>
          </string-name>
          <article-title>A logic programming framework for possibilistic argumentation: Formalization and logical properties</article-title>
          .
          <source>Fuzzy Sets and Systems</source>
          <volume>159</volume>
          (
          <issue>10</issue>
          ),
          <volume>1208</volume>
          {
          <fpage>1228</fpage>
          (
          <year>2008</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <surname>Benhamou</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          :
          <article-title>Interval constraint logic programming</article-title>
          . In: Podelski,
          <string-name>
            <surname>A</surname>
          </string-name>
          . (ed.)
          <article-title>Constraint Programming: Basics and Trends, LNCS</article-title>
          , vol.
          <volume>910</volume>
          , pp.
          <volume>1</volume>
          {
          <fpage>21</fpage>
          . Springer (
          <year>1995</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <surname>Denti</surname>
            ,
            <given-names>E.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Omicini</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Ricci</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          <article-title>: Multi-paradigm Java-Prolog integration in tuProlog</article-title>
          .
          <source>Science of Computer Programming</source>
          <volume>57</volume>
          (
          <issue>2</issue>
          ),
          <volume>217</volume>
          {250 (Aug
          <year>2005</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <surname>Gabbay</surname>
            ,
            <given-names>D.M.</given-names>
          </string-name>
          :
          <source>Labelled Deductive Systems</source>
          , Volume
          <volume>1</volume>
          . Clarendon Press,
          <source>Oxford Logic Guides</source>
          <volume>33</volume>
          (
          <year>Sep 1996</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <surname>Gavanelli</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Rossi</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          :
          <article-title>Constraint logic programming</article-title>
          . In: Dovier,
          <string-name>
            <given-names>A.</given-names>
            ,
            <surname>Pontelli</surname>
          </string-name>
          , E. (eds.)
          <article-title>A 25-year Perspective on Logic Programming, LNCS</article-title>
          , vol.
          <volume>6125</volume>
          , pp.
          <volume>64</volume>
          {
          <fpage>86</fpage>
          . Springer (
          <year>2010</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <surname>Holzbaur</surname>
            ,
            <given-names>C.</given-names>
          </string-name>
          :
          <article-title>Metastructures vs. attributed variables in the context of extensible uni cation</article-title>
          . In: Bruynooghe,
          <string-name>
            <given-names>M.</given-names>
            ,
            <surname>Wirsing</surname>
          </string-name>
          ,
          <string-name>
            <surname>M.</surname>
          </string-name>
          <article-title>(eds.) Programming Language Implementation and Logic Programming, LNCS</article-title>
          , vol.
          <volume>631</volume>
          , pp.
          <volume>260</volume>
          {
          <fpage>268</fpage>
          . Springer (
          <year>1992</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <surname>Mariani</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Omicini</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          :
          <article-title>Coordinating activities and change: An event-driven architecture for situated MAS</article-title>
          .
          <source>Engineering Applications of Arti cial Intelligence</source>
          <volume>41</volume>
          ,
          <fpage>298</fpage>
          {309 (May
          <year>2015</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <surname>Russo</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          :
          <article-title>Generalising propositional modal logic using labelled deductive systems</article-title>
          . In: Baader,
          <string-name>
            <given-names>F.</given-names>
            ,
            <surname>Schulz</surname>
          </string-name>
          , K.U. (eds.)
          <source>Frontiers of Combining Systems, Applied Logic Series</source>
          , vol.
          <volume>3</volume>
          , pp.
          <volume>57</volume>
          {
          <fpage>73</fpage>
          . Springer (
          <year>1996</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9. tuProlog:
          <article-title>Home page</article-title>
          . http://tuprolog.unibo.it/
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          10. Van Hentenryck,
          <string-name>
            <surname>P.:</surname>
          </string-name>
          <article-title>Constraint logic programming</article-title>
          .
          <source>The Knowledge Engineering Review</source>
          <volume>6</volume>
          ,
          <issue>151</issue>
          {194 (Sep
          <year>1991</year>
          )
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>