<!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>PrettyCLP: a Light Java Implementation for Teaching CLP</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Alessio Stalla</string-name>
          <email>alessiostalla@gmail.com</email>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Davide Zanucco</string-name>
          <email>zanucco.davide@spes.uniud.it</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Agostino Dovier</string-name>
          <email>agostino.dovier@uniud.it</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Viviana Mascardi</string-name>
          <email>mascardi@disi.unige.it</email>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>DIMI - Univ. of Udine</institution>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>DISI - Univ. of Genova</institution>
        </aff>
      </contrib-group>
      <abstract>
        <p>Recursion is nowadays taught to students since their rst programming days in order to embed it deeply in their brains. However, students' rst impact on Prolog programs execution sometimes weakens their faith in recursive programming thus invalidating our initial e orts. The selection and computation rules implemented by all Prolog systems, although clearly explained in textbooks, are hard to be interiorized by students also due to the poor system debugging primitives. Problems increase in Constraint Logic Programming when uni cation is replaced by constraint simpli cation in a suitable constraint domain. In this paper, we extend PrettyProlog, a light-weight Prolog interpreter written in Java capable of system primitives for SLD tree visualization, to deal with Constraint Logic Programming over Finite Domains. The user, in particular, can select the propagation strategies (e.g. arc consistency vs bound consistency) and can view the (usually hidden) details of the constraint propagation stage.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>
        PrettyProlog was developed two years ago by a team of the University of
Genova, for providing concrete answers to demands raised by Prolog novices [
        <xref ref-type="bibr" rid="ref14">14</xref>
        ].
Teaching experience demonstrated that one of the hardest concepts for Prolog
students is to understand the construction and the visit strategy of the SLD tree.
PrettyProlog was developed from scratch, without reusing any existing Prolog
implementation, and designed to be simple, modular, and easily expandable.
Research on visualization of the execution of Prolog programs has a long history
(just to make some examples, [
        <xref ref-type="bibr" rid="ref13 ref15 ref7">13, 7, 15</xref>
        ], many papers collected in [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ], and [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ]).
Nevertheless, nowadays few Prolog implementations o er a Stack Viewer and
an SLD tree visualizer as graphical means for debugging. The open-source
implementations that provide these facilities are even fewer. Among them,
SWIProlog1 o ers a debugging window showing current bindings, a diagrammatic
trace of the call history, and a highlighted source code listing. No SLD tree
visualization is given. On the other hand, many Java implementations of a Prolog
      </p>
    </sec>
    <sec id="sec-2">
      <title>1 http://www.swi-prolog.org/</title>
      <p>interpreter exist, starting from W-Prolog2. Although at a prototypical stage,
PrettyProlog presents three features that, to the best of our knowledge, cannot
be found together in any other Prolog implementation:</p>
      <sec id="sec-2-1">
        <title>1. it provides Stack and SLD Tree visualizers; 2. it is open source; 3. it is written in Java, and fully compliant with Java ME CDC application framework.</title>
        <p>The desirable architectural features of PrettyProlog have been exploited in the
research activity described in this paper where PrettyProlog has been extended
for dealing with Constraint Logic Programming on Finite Domains (brie y,
CLP(FD)). As a matter of fact, experience in teaching CLP(FD) evidenced
further problems for students, rst of all the replacement of uni cation with
constraint solving. The term 1 + 3 does not unify with the term 3 + 1. However,
they are both considered as 4 by CLP(FD). Moreover, the constraint
propagation stage is parametric on some choices. For instance, bounds consistency
and arc consistency return di erent \results" to the constraint 2X = Y where
the domain DX and DY of the variables X and Y are both the intervals 0::3
(DX = f0; 1g; DY = f0; 1; 2g in the former case, DX = f0; 1g; DY = f0; 2g
in the latter case). Although di erent propagation techniques are studied in
theory, Prolog interpreters supporting CLP(FD) usually implement only one of
them, and students using di erent systems can be confused. Another source of
confusion is introduced by some implementations of the SLD resolution with
constraints that manage the ordering of literals in goals in a di erent way
depending on whether they are constraint literals or user-de ned literals. Moreover,
during constraint's solution search (if explicitly required by a labeling) an
auxiliary tree named prop-labeling tree is created and visited. This tree is sometimes
wrongly confused with the SLD tree.</p>
        <p>The proposed extension of PrettyProlog, called PrettyCLP, has been
developed to help the new CLP programmers in a deeper understanding of what
happens during the execution of a CLP(FD) program. The basic procedures for
constraint propagation have been implemented in Java, either in the case of
(hyper) arc consistency or in the case of (hyper) bounds consistency. A labeling
built-in has also been developed for the solution's search using a prop-labeling
tree.</p>
        <p>This paper is organized in the following way: Section 2 recalls the
functionalities of PrettyProlog and its implementation; Section 3 provides some background
on CLP; Section 4 describes the original contribution of this paper, namely the
design and implementation of PrettyCLP. In particular, it discusses PrettyCLP
syntax, the supported mechanism for constraint propagation and labeling, and
the output renderer. Section 5 analyzes the related work and concludes by
outlining some future extensions.
2 http://waitaki.otago.ac.nz/~michael/wp/</p>
        <sec id="sec-2-1-1">
          <title>PrettyProlog</title>
          <p>Functionalities
PrettyProlog implements a Prolog engine able to deal with basic data types
(integer and real numbers, lists, strings), and o ering metaprogramming
facilities that, combined with the \cut" predicate, make the de nition of negation
as failure possible. Despite to some simpli cations that were made during its
design and implementation, sophisticated programs may be implemented with
PrettyProlog thanks to these features.</p>
          <p>The main functionality of PrettyProlog, however, is that it allows the user
to visualize how the Stack and the SLD Tree evolve during a computation made
by the interpreter to solve a given goal.</p>
          <p>The SLD tree viewer panel shows the steps the PrettyProlog engine has
performed as a tree. Each branch represents the selection of a clause from the
theory, which can be selected in the \theory panel", whereas leaves are either
solutions or dead ends, i.e. goals that could not be solved. The substitution that
was valid at a given point is shown aside the corresponding node in the tree.
Also, the SLD tree shows which frames are removed from the stack as the e ect
of a cut, by printing them with a di erent font and icon.</p>
          <p>Figure 1 shows the SLD tree of a Prolog program that implements a classical
instance of a search problem: that of moving from a city in Romania (Arad, in
our case) to Bucharest [11, Chapter 3]. We implemented a depth rst search
with control of cycles, as well as the auxiliary not and member predicates.</p>
          <p>
            Because of space constraints, we do not show here the code of the
implemented \DFS with control of cycles" program. It can be found in [
            <xref ref-type="bibr" rid="ref14">14</xref>
            ], as well
as in most Prolog textbooks.
          </p>
          <p>Besides showing what happens both to the stack and to the SLD tree (while it
is built), PrettyProlog correctly visualizes the e ect of a \cut" on the SLD tree. In
the upper part of Figure 1 there are goals written in italic (from not(member(arad,
[oradea, zerind, arad])), ... to !, fail, write(....) ). These nodes
are cut after the execution of the ! in the rst clause de ning not, called with
member(arad, [oradea, zerind, arad])) as argument. PrettyProlog SLD
viewer keeps the cut goals for didactic purposes, but shows them in a di erent
font to emphasize that they no longer belong to the tree. The system
predicates supported by PrettyProlog, although limited, include simple predicates for
input-output, such as write and nl.</p>
          <p>The stack viewer shows each frame pushed onto the stack. When the user
clicks on a frame, its content is displayed: the goal that still had to be solved at
the time the frame was pushed on the stack; the substitution that is the partial
solution to such goal at this point; the clause that has been used to obtain the
goal; the index from where, on backtracking, the engine will search for the next
clause.</p>
          <p>When the PrettyProlog engine solves a goal step-by-step, the clause used in
each resolution step is highlighted in the theory panel.
2.2 Implementation
PrettyProlog is made of several modules, each one corresponding roughly to a
Java package. Modules are pretty much organized in a layered fashion, with
the lower-level ones providing services to the upper-level ones. Currently
implemented modules include: the Data Types Module, the Parser Module, the
Engine Module, the GUI Module.</p>
          <p>{ The Data Types Module includes data types that are commonly used
throughout many other PrettyProlog modules. From this point of view, the Data
Types Module is the lowest-level one.
{ The Parser Module contains the Parser class and some parser exception
classes. This module lies just above the Data Types Module; its task is to
read characters from a stream and produce instances of PrettyProlog data
types, or throw an exception if something goes wrong.
{ The GUI Module includes the classes that make up the PrettyProlog GUI,
including the viewers for the Stack, Theory, and SLD Tree.
{ The Engine Module is the main PrettyProlog module. It contains the Engine
class as well as many helper classes such as Theory, Goal and Clause. This
module contains also two sub-modules: EventListeners , which provides
classes and interfaces used to attach listeners to the Engine, the Stack, and
the Theory; and Syspreds, which de nes the built-in system predicates and
gives the programmer the possibility to easily add new ones.</p>
          <p>The classes that make up the Engine Module are the following:
Unifier. This class provides a single public method, unify(Term, Term),
that returns a substitution that uni es the two terms passed as
arguments, or null if they are not uni able. This class exists as a separate
class for reasons of modularity and extensibility.</p>
          <p>Clause. A clause is an object made of a Callable (the head) and a body,
again a nameless callable.</p>
          <p>Theory. This class implements a list of clauses, with the usual operations
for adding to, removing from, or navigating through the list.</p>
          <p>Frame. A Frame is a single piece of data that is contained in a stack.
Stack. In addition to the usual stack operations, this class can register
StackListeners which are noti ed of every change in the stack's state.
The lack of an explicit representation of the stack in many prolog
implementations, and the requirement to have such a data structure for
inspecting the behavior of the Prolog engine were the main motivations
for building a new interpreter from scratch.</p>
          <p>Goal. A goal is a list of callables.</p>
          <p>Engine. The main class of the Engine module.
3</p>
        </sec>
        <sec id="sec-2-1-2">
          <title>Constraint Logic Programming</title>
          <p>
            We brie y recall here some basic notions of Constraint Logic Programming
(CLP). The reader is referred to [
            <xref ref-type="bibr" rid="ref10">10</xref>
            ] for a recent survey. We mix syntax and
semantics to shorten the presentation.
          </p>
          <p>Let us consider a rst-order language h ; F ; Vi, where ; F ; V are the sets
of predicate symbols, functional symbols, and variables, respectively. The set
is partitioned in the two sets C and P ( = C [ P and C \ P = ;).</p>
          <p>C ( P ) is the set of constraints (resp., program de ned\) predicate symbols.</p>
          <p>C is assumed to contain the equality symbol \=". Similarly, F is partitioned
into FC and FP . In this paper we focus on CLP on nite domains (CLP(FD)),
therefore, we assume that FC contains the binary arithmetic function symbols
+; ; ; =; mod etc. as well as a constant symbol for any integer number, and</p>
          <p>C contains ; &lt;, etc. false is assumed to be a special predicate in P which
has no rules de ning it. domain is assumed to be a predicate in C assigning a
domain to a list of variable or re ning it, if the variables already have one.</p>
          <p>An atom built on h P ; FP ; Vi (resp. h C ; FC ; Vi) is said to be a program
(resp. constraint) atom. Any constraint atom and any subterm based on hFC ; Vi
is interpreted in a constraint domain, namely, ful lling the intended semantics
of its symbols (in this case, the arithmetical properties on integer numbers).
The same happens to constraint atoms. To this aim, each variable X used in
constraint atoms is associated with a domain DX . We will use the functions min
and max that return the smallest (resp., largest) value of a domain.</p>
          <p>A primitive constraint is a constraint atom or its negation and a constraint
is a conjunction of primitive constraints. We denote the empty conjunction by
true. This syntactic notion of constraint has a semantic counterpart: a constraint
C on n variables X1; : : : ; Xn with domains D1; : : : ; Dn, respectively, is a relation
on D1 Dn. A solution for C is a mapping [X1=d1; : : : ; Xn=dn] such that
hd1; : : : ; dni 2 C. If there are no solutions, then C is inconsistent.</p>
          <p>A goal CLP is of the form B, where B is a conjunction of program atoms
and primitive constraints. A CLP rule is of the form A B where A is a
program atom and B is a CLP goal. A CLP program is a set of CLP rules.</p>
          <p>The operational semantics of CLP is parametric on the function solve that
given a constraint C should detect whether C is satis able (consistent) in the
constraint domain chosen (in this paper nite domains). During its computation,
solve(C) might rewrite C to an equivalent simpli ed constraint. In practice, for
complexity reasons, solve is an incomplete procedure, in the sense that instead
of verifying consistency of the (entire) constraints, acts locally in each primitive
constraint, removing some values in domains that cannot belong to any solution
until a local property is satis ed. Typical local properties are (hyper)arc
consistency and (hyper)bounds consistency (see below for details). This operation is
called constraint propagation and is required to be as fast as possible. During this
computation, inconsistency of C can be detected. In this case solve(C) returns
false. But, even if solve(C) 6= false we cannot be sure of the consistency
of the constraint. As we will see below, the user might require the search for a
solution using the labeling predicate.</p>
          <p>As an example, let us consider the constraint X 6= Y; X 6= W; X 6= Z; Y 6=
W; Y 6= Z; W 6= Z, where DX = DY = DZ = DW = f0; 1; 2g. Although it is
inconsistent, default options in Prolog implementations are such that it is left
unaltered by solve and, therefore, inconsistency is not detected. This constraint
is the encoding of the 3-coloring problem of a graph (in this case, of four nodes,
fX; Y; W; Zg, disequations are added for each edge). Checking consistency of this
class of constraints is therefore NP-complete and a fast propagation algorithm
can not check it (unless P=NP).</p>
          <p>Operational semantics of CLP is based on the notion of state. Some variants
are possible. The one presented here is the one we believe is the closest to
standard SLD resolution.</p>
          <p>A state is a pair hG j Ci where G is a CLP goal and C is a constraint (also
known as the constraint store). A state hG j Ci is said to be:
{ successful if G = true and solve(C) 6= false.
{ failing if either solve(C) = false or there are no clauses in P with the
same predicate of the head of the selected atom in G.
{ unsolved if G 6= true and it is not failing.</p>
          <p>Let hG1 j C1i be an unsolved state, where G1 = L1; : : : ; Lm, and P a
program. A CLP-derivation step hG1 j C1i ) hG2 j C2i is de ned as follows:
{ Let Li be the selected literal in G1 (for simplicity, let us assume it is L1).
{ Then hG2 j C2i is obtained from S and P in one of the following ways:
L1 is a primitive constraint, C2 = L1 ^ C1. If solve(C2) = false, then
G2 = false, otherwise G2 = L2; : : : ; Ln.</p>
          <p>If L1 = p(t1; : : : ; tn) is a program atom, and p(s1; : : : ; sn) B is a
renaming of a clause of P then G2 = t1 = s1; : : : ; tn = sn; B; L2; : : : ; Ln
and C2 = C1.</p>
          <p>A derivation for a state S0 in P is a maximal sequence of derivations such
that S0 ) S1 ) . A derivation for a goal G is a derivation for the state
hG j truei.</p>
          <p>A nite derivation S0 ) ) Sn is said successful (resp. failing ) if Sn
is a successful (resp., failing) state. In the case of a successful derivation the
computed answer is the projection of the constraint store of Sn on the variables
in S0. Of course, a simpli cation, based on solve, is usually employed to make
the output readable.</p>
          <p>Although the computed answer is returned in implicit form, explicit
enumeration of the solutions can be forced by using the built-in predicate labeling. In
this stage inconsistency of a constraint is discovered. The main parameter is a list
of variables to be instantiated (labeled). Other optional parameters are related
to the search heuristics and are di erent in di erent Prolog implementations.
We use here the choice of not allowing extra parameters.</p>
          <p>Basically, starting from a successful state htrue j Ci (or equivalently, by a
constraint C) the labeling builds a search tree that alternates two stages: a
constraint propagation stage followed by a non deterministic assignment of a
(selected) variable. During the propagation stage the constraint is simpli ed
and, possibly, its inconsistency is detected. In this case, the search backtracks
to the last non deterministic choice. If all variables are assigned (labeled) a
solution is found. If all possible backtracks are applied and no solution is found,
the constraint is inconsistent. The derivation step is extended with:
If L1 = labeling([V1; : : : ; Vn]) then G2 = V1 = v1; : : : ; Vn = vn; L2; : : : ; Ln
and C2 = C1 if [V1=v1; : : : ; Vn=vn] is an assignment that do not lead C1 to
inconsistency. If there are not such assignments, then G2 = false.</p>
          <p>Every variable X used in constraint is associated with a domain DX . This
is done initially by the built-in predicate domain; domains and later reduced by
e ect of the computation. As common in CLP, we denote the interval fa; a +
1; a + 2; : : : ; bg by a::b.</p>
          <p>Let us consider a primitive constraint c on the variables X1; : : : ; Xn. c is arc
consistent (hyper arc consistent if n &gt; 2) if for all i 2 f1; : : : ; ng and for all
di 2 Di exist d1 2 D1; : : : di 1 2 Di 1; di+1 2 Di+1; : : : ; dn 2 Dn such that
[X1=d1; : : : ; Xn=dn] is a solution of c.</p>
          <p>
            As explained in [
            <xref ref-type="bibr" rid="ref5">5</xref>
            ] there are several de nitions of bounds consistency in
literature. We refer to the one implemented by SICStus Prolog3, by B Prolog4,
and by SWI Prolog, just to cite a few, and and called interval consistency in [
            <xref ref-type="bibr" rid="ref2">2</xref>
            ].
          </p>
        </sec>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>3 http://www.sics.se/isl/sicstuswww/site/</title>
    </sec>
    <sec id="sec-4">
      <title>4 http://www.probp.com/</title>
      <p>Let us consider a primitive constraint c on the variables X1; : : : ; Xn. c is
bounds consistent (hyper bounds consistent if n &gt; 2) if for all i 2 f1; : : : ; ng and
for all di 2 fmin Di; max Dig (the two interval bounds), exist
d1 2 min D1:: max D1; : : : ; di 1 2 min Di 1:: max Di 1;
di+1 2 min Di+1:: max Di+1; : : : ; dn 2 min Dn:: max Dn
such that [X1=d1; : : : ; Xn=dn] is a solution of c.</p>
      <p>Going back to the example in the Introduction, the constraint 2X = Y
where the domains DX = f0; 1g; DY = f0; 1; 2g is bounds consistent but not arc
consistent.
4</p>
      <sec id="sec-4-1">
        <title>PrettyCLP</title>
        <p>This section introduces PrettyCLP: Section 4.1 reports the concrete syntax of
the CLP part of PrettyCLP, Section 4.2 describes the procedures implemented
for constraint propagation and labeling, and Section 4.3 shows how the output
primitives have been modi ed and reports some system screenshots.
4.1</p>
        <p>Concrete CLP syntax for PrettyCLP
Concretely, the set C contains the constraint predicate symbols #= and #=&lt;;
symbols #\=; #&gt;; #&gt;=; #&lt; are accepted as a syntactic sugar for building negated
constraint literals. Standard arithmetic functional symbols are allowed as well.</p>
        <p>The built-in instruction domain for assigning a nite domain to variables can
be used in two ways (lists are usual Prolog lists):
{ domain(VARS, min, max), where VARS is a list of variables, and the domain
is the interval min..max.
{ domain(VARS, DOMAIN): where VARS is a list of variables, and DOMAIN is a
list of integer numbers.</p>
        <p>The labeling built-in has a unique argument: labeling(VARS), where VARS
is a list of variables assigned to a nite domain.
4.2</p>
        <p>Constraint Propagation and Labeling
Every nite domain variable is assigned to a domain, namely a set of points that
can monotonically decrease during the computation, or increase again due to
backtracking. Domains are stored in a vector of integer values (we recall that
Java vectors are in fact a dynamic data structures that can be increased and
decreased as needed). This is realized by modifying the class Variable within
the module Data Types.</p>
        <p>More in detail, a Java constructor is changed in order to characterize a
variable by a symbol. symbol is a PrettyProlog class, and a symbol can be the string
naming a variable or a constant or functional symbol of FC .</p>
        <p>Moreover, the class Domain is de ned in the module Engine. This class stores
an array (again, a Java dynamic array) with an entry for each of the variables
occurring in the derivation and implements the methods for domain manipulation.
Among them, we would like to point out the methods:
{ getDomain(Var X) that returns the (vector storing the) domain of a variable</p>
        <p>X.
{ domainVar(Var X, int min, int max) that initializes the domain of the
variable X with the interval min..max.
{ updateDomain(Var X, Vector D) that replaces the current domain of the
variable X with the domain array D. This method simpli es propagation and
backtracking operations.</p>
        <p>The parser of Pretty Prolog has been slightly modi ed to be able to deal
with constraint terms and atoms.</p>
        <p>The class Engine is the core of the computation. Since the SLD resolution
is now coupled with constraint solving, we need to act on the class Engine.
Uni cation is called for standard terms, constraint solving for constraint terms.
The constructor that creates a new instance has been modi ed for dealing with
the array domains. Then the method ContinueSolving is called. Its role is
to either call the Constraint Solver procedure, called SolveConstraint, or the
uni cation procedures already developed in PrettyProlog.</p>
        <p>The Constraint Solver returns a Boolean value: false can be obtained as
e ect of constraint propagation; if constraint propagation ends without failing
it returns true. Constraint Propagation operates on both arc and bounds
consistency. The procedures called by the Constraint Solver are:
{ Solve that receives as input a constraint and the domains of the variables
in it and elaborates it on the basis of its main predicate symbol. When
selected, unary constraints are used to reduce the domain of the corresponding
variable and removed. Constraints with two or more variables, instead, are
dealt with by:</p>
        <p>ArcSolveConstraint, implementing arc consistency, and</p>
        <p>BoundSolveConstraint, that implements bounds consistency.</p>
        <p>In these two procedures, one variable per time is selected, then every value
in its domain is considered and a support for it is looked for in the domains
of the remaining variables (but with a di erent rule for arc vs bounds). In
the case of bounds, of course, a faster algorithm based on the bounds of the
domains is employed.
{ SolveConstraint repeatedly applies the Solve procedures on all the
constraints until a xpoint is reached.
{ ExprEval computes the various expressions involved in constraints when
values are assigned to variables and is used as auxiliary procedure by ArcSolve/
BoundSolveConstraint.</p>
        <p>The handling of labeling is made by a homonymous method. Variables in
the argument list are selected from left to right (heuristics leftmost of other
CLP(FD) systems) and smallest domain values are tried rst (heuristics up).5
5 It it easy to implement other heuristics here. This will be done as future work.
This method also deals with backtracking, handling,choice points, and storing
and retrieving intermediate constraint stores.</p>
        <p>Remark 1. As a nal observation for this section, we would like to underline
a typical problem in CLP implementations coming from the weak typing of
constraint functional symbols and variables. In theory, terms and variables are
sorted, in practice this is not true. If the two terms 1 + 3 and 3 + 1 are found
within a uni cation they are assumed to be di erent even if the arguments are
integer numbers and the binary symbol + 2 FC . On the contrary the constraint
1 + 3 #= 3 + 1 is true. This is also the behavior of our interpreter, but this may
lead a student, the target of PrettyCLP, to confusion.</p>
        <p>Similarly, let us assume to nd the constraint atom X #&lt; 3 and the variable
X is not yet assigned to a domain. Some Prolog implementations will answer
X in -inf..2, thus implicitly assuming a starting domain -inf..+inf for each
nite domain variable. We have chosen a more rigid option: if the variable has
been not yet associated with a domain, it cannot be used in a constraint atom.
An error (a sort of type error) is returned.
4.3</p>
        <p>Output rendering
After the parametric propagation procedures and the procedures for the labeling
have been implemented, we modi ed the graphical applet of PrettyProlog for
showing the new information. In particular:
{ buttons for visualizing and erasing domains have been added to the applet
window;
{ the eld Constraint can be inspected from the Stack Viewer;
{ two windows for inspecting Arc Consistency and Bounds Consistency based
propagation have been made available to PrettyCLP users.</p>
        <sec id="sec-4-1-1">
          <title>Changes are done in the method TheoryViewer.</title>
          <p>In Figures 2 and 3 we report the rendering of the two alternative executions
to a goal p(X,Y) where the predicate p is de ned by the constraint:
domain([X],0,2), domain([Y],0,5), Y #= 2 * X.</p>
          <p>In the current implementation, we decided to leave an unique SLD tree, while
di erent computed answers are returned in the Arc Consistency and Bounds
Consistency windows. Since Arc Consistency is more e ective in reducing the
domains, it can be the case that an inconsistent branch of the SLD tree is found
some steps before than using bounds consistency. However, this case is extremely
rare. We have preferred to leave the tree obtained using Bounds Consistency (the
same computed by Standard Prolog system) only. However, the user can view
what would have happened with the other propagation technique looking at the
Arc Consistency window. In particular, all domains computed during the
computation are included in those computed with Bounds Consistency. Sometimes
they are strictly included and it may happen that one domain becomes empty
before arriving at the end of the tree. This choice can be changed as future
work, namely, we could leave the user to select in advance (with a button) the
propagation choice and report the selected computation only.</p>
          <p>In Figures 4{5 we report the execution of PrettyCLP on a Knapsack
problem. The explicit labeling is required for variable W only. The computed solution
is shown in the main picture (Fig 4). In the labeling case the di erences
between Arc and Bounds become evident. An excerpt of the executed constraint
propagation is shown in Fig 5.
5</p>
        </sec>
      </sec>
      <sec id="sec-4-2">
        <title>Related Work and Conclusions</title>
        <p>Although visualization and tracing of constraint programs do not constitute a
new research area, implemented systems that provide dynamic visualization and
control functionalities for CLP(FD) are still few.</p>
        <p>
          Among the oldest ones we may mention the Oz-Explorer system by C. Schulte
[
          <xref ref-type="bibr" rid="ref12">12</xref>
          ] which uses the search tree of a constraint problem as its central metaphor,
and exploration and visualization of the search tree are user-driven and
interactive. Within the community of constraint programming, ILOG debugger6 is a
con gurable tool with nice graphics capabilities. But, according to our opinion,
it is not suitable for beginners (and it is not a CLP visual debugger).
Similarly, CPVisu tracer7 is a module of the Java constraint solver on nite domains
CHOCO, producing XML les that, once interpreted using CPViz8, allow to see
information on the tree search, the states of constraints and variables at
different points of computations, and a con guration le. It is a professional tool
(together with CHOCO, which is developed by a large group of people
including Francois Laburthe, Narendra Jussien, Xavier Lorca, and other contributors,
such as Nicolas Beldiceanu), but its scope is for debugging large programs rather
than for learning CP (and, in any case, it does not deal with CLP).
        </p>
        <p>
          In [
          <xref ref-type="bibr" rid="ref3">3</xref>
          ], M. Carro and M. V. Hermenegildo address the design and
implementation of visual paradigms for observing the execution of constraint logic programs,
aiming at debugging, tuning and optimization, and teaching. They describe two
tools, VIFID and TRIFID, exemplifying the devised depictions. In the
companion paper [
          <xref ref-type="bibr" rid="ref4">4</xref>
          ] they describe the APT tool for running constraint logic programs
while depicting a (modi ed\) search tree, keeping information about the state of
the variables at every moment in the execution. This information can be used to
replay the execution at will, both forwards and backwards in time. The
searchtree view is used as a framework onto which constraint-level visualizations can
be attached.
        </p>
        <p>
          The integration of explanations in the trace structure and some ideas on how
to implement the trace structure in a high-end system like SICStus are addressed
by [
          <xref ref-type="bibr" rid="ref1">1</xref>
          ].
        </p>
      </sec>
    </sec>
    <sec id="sec-5">
      <title>6 http://www.cs.cornell.edu/w8/iisi/ilog/cp11/pdf/debugsolver.pdf</title>
    </sec>
    <sec id="sec-6">
      <title>7 http://www.emn.fr/z-info/choco-solver/cpvisu-tracer/index.html</title>
    </sec>
    <sec id="sec-7">
      <title>8 http://cpviz.sourceforge.net/</title>
      <p>
        More recently, F. Fages, S. Soliman, and R. Coolen developed CLPGUI [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ],
a generic graphical user interface for visualizing and controlling the execution of
constraint logic programs. CLPGUI is based on a client-server architecture for
connecting a CLP process to a Java-based GUI process, and integrates a
nonintrusive tracing and control method based on annotations in the CLP program.
Arbitrary constraints and goals can be posted incrementally from the GUI in an
interactive manner, and arbitrary states can be recomputed. Several generic 2D
and 3D viewers of the variables and of the search tree are supported.
      </p>
      <p>Although de nitely simpler than some of the above systems as far as the
visualization of variables is concerned, PrettyCLP shows the original feature of
allowing the user to select the propagation strategies (e.g. arc consistency vs
bound consistency), which { to the best of our knowledge { is not supported by
any other tool.</p>
      <p>As part of our close future activities we are planning to incorporate some
global constraints, such as the alldifferent one, into PrettyCLP. Propagation
procedures of global constraints allow to sensibly prune the search tree. This
has e ects on the size and on the form of the SLD tree too. Therefore, we will
add buttons to enable/disable global consistency vs simple consistency so as to
select one or the other search tree.</p>
      <p>Because of our teaching mission, from which the development of both
PrettyProlog and PrettyCLP stemmed, we are currently facing the problem of
guiding the student in his/her CLP learning activity. To this aim, we are designing
a set of benchmarks for supporting self-evaluation and for helping students in
identifying those aspects of CLP design and programming that they still need
to better understand. This benchmark will heavily ground upon PrettyCLP as
the tool that the students will be suggested to use in order to appreciate CLP
not only on the stage, but also behind the scene.</p>
      <p>All the material relevant to PrettyProlog and PrettyCLP can be found at
http://code.google.com/p/prettyprolog/.</p>
      <p>Acknowledgments
This work is partially supported by INdAM-GNCS 2010, INdAM-GNCS 2011,
and PRIN 20089M932N. We would like to thank Maurizio Martelli for the
precious discussions during the design and implementation of the PrettyProlog
visualizer.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <surname>Agren</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Szeredi</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Beldiceanu</surname>
            ,
            <given-names>N.</given-names>
          </string-name>
          , and
          <string-name>
            <surname>Carlsson</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          <article-title>Tracing and explaining execution of clp(fd) programs</article-title>
          . In WLPE (
          <year>2002</year>
          ), pp.
          <volume>1</volume>
          {
          <fpage>16</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <surname>Carlsson</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Ottosson</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          , and
          <string-name>
            <surname>Carlson</surname>
            ,
            <given-names>B.</given-names>
          </string-name>
          <article-title>An open-ended nite domain constraint solver</article-title>
          .
          <source>In Proc. Programming Languages: Implementations</source>
          , Logics, and
          <string-name>
            <surname>Programs</surname>
          </string-name>
          (
          <year>1997</year>
          ), vol.
          <volume>1292</volume>
          of LNCS, Springer, pp.
          <volume>191</volume>
          {
          <fpage>206</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <surname>Carro</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          , and
          <string-name>
            <surname>Hermenegildo</surname>
          </string-name>
          , M. V.
          <article-title>Tools for constraint visualisation: The vi d/tri d tool. In Analysis and Visualization Tools for Constraint Programming (</article-title>
          <year>2000</year>
          ), P. Deransart,
          <string-name>
            <given-names>M. V.</given-names>
            <surname>Hermenegildo</surname>
          </string-name>
          , and J. Maluszynski, Eds., vol.
          <source>1870 of Lecture Notes in Computer Science</source>
          , Springer, pp.
          <volume>253</volume>
          {
          <fpage>272</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <surname>Carro</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          , and
          <string-name>
            <surname>Hermenegildo</surname>
          </string-name>
          , M. V.
          <article-title>Tools for search-tree visualisation: The apt tool. In Analysis and Visualization Tools for Constraint Programming (</article-title>
          <year>2000</year>
          ), P. Deransart,
          <string-name>
            <given-names>M. V.</given-names>
            <surname>Hermenegildo</surname>
          </string-name>
          , and J. Maluszynski, Eds., vol.
          <source>1870 of Lecture Notes in Computer Science</source>
          , Springer, pp.
          <volume>237</volume>
          {
          <fpage>252</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <surname>Choi</surname>
            ,
            <given-names>C. W.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Harvey</surname>
            ,
            <given-names>W.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Lee</surname>
            ,
            <given-names>J. H. M.</given-names>
          </string-name>
          , and
          <string-name>
            <surname>Stuckey</surname>
            ,
            <given-names>P. J.</given-names>
          </string-name>
          <article-title>Finite domain bounds consistency revisited</article-title>
          .
          <source>In Australian Conference on Arti cial Intelligence</source>
          (
          <year>2006</year>
          ), vol.
          <volume>4304</volume>
          of LNCS, Springer, pp.
          <volume>49</volume>
          {
          <fpage>58</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <surname>Ducasse</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Emde</surname>
            ,
            <given-names>A.-M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Kusalik</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          , and
          <string-name>
            <surname>Levy</surname>
          </string-name>
          , J.,
          <source>Eds. Logic Programming Environments, ICLP'90 Preconference Workshop</source>
          .
          <year>1990</year>
          .
          <source>ECRC Technical Report IR-LP-31-25.</source>
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <surname>Eisenstadt</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          , and
          <string-name>
            <surname>Brayshaw</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          <article-title>A ne-grained account of Prolog execution for teaching and debugging</article-title>
          .
          <source>Instructional Science</source>
          <volume>19</volume>
          ,
          <issue>4</issue>
          /5 (
          <year>1990</year>
          ),
          <volume>407</volume>
          {
          <fpage>436</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <surname>Fages</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Soliman</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          , and
          <string-name>
            <surname>Coolen</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          <string-name>
            <surname>Clpgui</surname>
          </string-name>
          :
          <article-title>A generic graphical user interface for constraint logic programming</article-title>
          .
          <source>Constraints 9</source>
          ,
          <issue>4</issue>
          (
          <year>2004</year>
          ),
          <volume>241</volume>
          {
          <fpage>262</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9.
          <string-name>
            <surname>Gavanelli</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          <article-title>SLDNF-Draw: a visualisation tool of prolog operational semantics</article-title>
          .
          <source>In CILC'07</source>
          ,
          <string-name>
            <surname>Messina</surname>
          </string-name>
          (
          <year>June 2007</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          10.
          <string-name>
            <surname>Gavanelli</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          , and
          <string-name>
            <surname>Rossi</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          <article-title>Constraint logic programming</article-title>
          .
          <source>In A 25-Year Perspective on Logic Programming</source>
          (
          <year>2010</year>
          ), vol.
          <volume>6125</volume>
          of LNCS, pp.
          <volume>64</volume>
          {
          <fpage>86</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          11.
          <string-name>
            <surname>Russell</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          , and
          <string-name>
            <surname>Norvig</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          <article-title>Arti cial Intelligence: A Modern Approach</article-title>
          , Second Edition. Prentice Hall,
          <year>2003</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          12.
          <string-name>
            <surname>Schulte</surname>
            ,
            <given-names>C.</given-names>
          </string-name>
          <article-title>Using the oz explorer for the development of constraint programs</article-title>
          .
          <source>In LPE</source>
          (
          <year>1997</year>
          ), pp.
          <volume>55</volume>
          {
          <fpage>56</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          13.
          <string-name>
            <surname>Shinomi</surname>
            ,
            <given-names>H.</given-names>
          </string-name>
          <article-title>Graphical representation and execution animation for Prolog programs</article-title>
          . In MIV (
          <year>1989</year>
          ), IEEE Computer Society, pp.
          <volume>181</volume>
          {
          <fpage>186</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          14.
          <string-name>
            <surname>Stalla</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Mascardi</surname>
            ,
            <given-names>V.</given-names>
          </string-name>
          , and
          <string-name>
            <surname>Martelli</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          <article-title>PrettyProlog: A Java Interpreter and Visualizer of Prolog Programs</article-title>
          .
          <source>In CILC'09</source>
          ,
          <string-name>
            <surname>Ferrara</surname>
          </string-name>
          (
          <year>June 2009</year>
          ). System available at http://code.google.com/p/prettyprolog/.
        </mixed-citation>
      </ref>
      <ref id="ref15">
        <mixed-citation>
          15.
          <string-name>
            <surname>Tamir</surname>
            ,
            <given-names>D. E.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Ananthakrishnan</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          , and
          <string-name>
            <surname>Kandel</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          <article-title>A visual debugger for pure Prolog</article-title>
          .
          <source>Inf. Sci. Appl</source>
          .
          <volume>3</volume>
          ,
          <issue>2</issue>
          (
          <year>1995</year>
          ),
          <volume>127</volume>
          {
          <fpage>147</fpage>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>