<s>
Constraint	B-Application
logic	I-Application
programming	I-Application
is	O
a	O
form	O
of	O
constraint	B-Application
programming	I-Application
,	O
in	O
which	O
logic	B-Language
programming	I-Language
is	O
extended	O
to	O
include	O
concepts	O
from	O
constraint	B-Application
satisfaction	I-Application
.	O
</s>
<s>
A	O
constraint	O
logic	B-Language
program	I-Language
is	O
a	O
logic	B-Language
program	I-Language
that	O
contains	O
constraints	O
in	O
the	O
body	O
of	O
clauses	O
.	O
</s>
<s>
In	O
this	O
clause	O
,	O
is	O
a	O
constraint	O
;	O
A(X,Y )	O
,	O
B(X )	O
,	O
and	O
C(Y )	O
are	O
literals	O
as	O
in	O
regular	O
logic	B-Language
programming	I-Language
.	O
</s>
<s>
As	O
in	O
regular	O
logic	B-Language
programming	I-Language
,	O
programs	O
are	O
queried	O
about	O
the	O
provability	O
of	O
a	O
goal	O
,	O
which	O
may	O
contain	O
constraints	O
in	O
addition	O
to	O
literals	O
.	O
</s>
<s>
Execution	O
is	O
performed	O
by	O
an	O
interpreter	B-Application
,	O
which	O
starts	O
from	O
the	O
goal	O
and	O
recursively	O
scans	O
the	O
clauses	O
trying	O
to	O
prove	O
the	O
goal	O
.	O
</s>
<s>
Constraints	O
encountered	O
during	O
this	O
scan	O
are	O
placed	O
in	O
a	O
set	O
called	O
constraint	B-Application
store	I-Application
.	O
</s>
<s>
If	O
this	O
set	O
is	O
found	O
out	O
to	O
be	O
unsatisfiable	O
,	O
the	O
interpreter	B-Application
backtracks	B-Algorithm
,	O
trying	O
to	O
use	O
other	O
clauses	O
for	O
proving	O
the	O
goal	O
.	O
</s>
<s>
In	O
practice	O
,	O
satisfiability	O
of	O
the	O
constraint	B-Application
store	I-Application
may	O
be	O
checked	O
using	O
an	O
incomplete	O
algorithm	O
,	O
which	O
does	O
not	O
always	O
detect	O
inconsistency	O
.	O
</s>
<s>
Formally	O
,	O
constraint	O
logic	B-Language
programs	I-Language
are	O
like	O
regular	O
logic	B-Language
programs	I-Language
,	O
but	O
the	O
body	O
of	O
clauses	O
can	O
contain	O
constraints	O
,	O
in	O
addition	O
to	O
the	O
regular	O
logic	B-Language
programming	I-Language
literals	O
.	O
</s>
<s>
As	O
an	O
example	O
,	O
X>0	O
is	O
a	O
constraint	O
,	O
and	O
is	O
included	O
in	O
the	O
last	O
clause	O
of	O
the	O
following	O
constraint	O
logic	B-Language
program	I-Language
.	O
</s>
<s>
Like	O
in	O
regular	O
logic	B-Language
programming	I-Language
,	O
evaluating	O
a	O
goal	O
such	O
as	O
A(X,1 )	O
requires	O
evaluating	O
the	O
body	O
of	O
the	O
last	O
clause	O
with	O
Y	O
=	O
1	O
.	O
</s>
<s>
Like	O
in	O
regular	O
logic	B-Language
programming	I-Language
,	O
this	O
in	O
turn	O
requires	O
proving	O
the	O
goal	O
B(X,1 )	O
.	O
</s>
<s>
Contrary	O
to	O
regular	O
logic	B-Language
programming	I-Language
,	O
this	O
also	O
requires	O
a	O
constraint	O
to	O
be	O
satisfied	O
:	O
X>0	O
,	O
the	O
constraint	O
in	O
the	O
body	O
of	O
the	O
last	O
clause	O
(	O
in	O
regular	O
logic	B-Language
programming	I-Language
,	O
X>0	O
cannot	O
be	O
proved	O
unless	O
X	O
is	O
bound	O
to	O
a	O
fully	O
ground	O
term	O
and	O
execution	O
of	O
the	O
program	O
will	O
fail	O
if	O
that	O
is	O
not	O
the	O
case	O
)	O
.	O
</s>
<s>
Rather	O
than	O
proceeding	O
in	O
the	O
evaluation	O
of	O
B(X,1 )	O
and	O
then	O
checking	O
whether	O
the	O
resulting	O
value	O
of	O
X	O
is	O
positive	O
afterwards	O
,	O
the	O
interpreter	B-Application
stores	O
the	O
constraint	O
X>0	O
and	O
then	O
proceeds	O
in	O
the	O
evaluation	O
of	O
B(X,1 )	O
;	O
this	O
way	O
,	O
the	O
interpreter	B-Application
can	O
detect	O
violation	O
of	O
the	O
constraint	O
X>0	O
during	O
the	O
evaluation	O
of	O
B(X,1 )	O
,	O
and	O
backtrack	O
immediately	O
if	O
this	O
is	O
the	O
case	O
,	O
rather	O
than	O
waiting	O
for	O
the	O
evaluation	O
of	O
B(X,1 )	O
to	O
conclude	O
.	O
</s>
<s>
In	O
general	O
,	O
the	O
evaluation	O
of	O
a	O
constraint	O
logic	B-Language
program	I-Language
proceeds	O
as	O
does	O
a	O
regular	O
logic	B-Language
program	I-Language
.	O
</s>
<s>
However	O
,	O
constraints	O
encountered	O
during	O
evaluation	O
are	O
placed	O
in	O
a	O
set	O
called	O
a	O
constraint	B-Application
store	I-Application
.	O
</s>
<s>
As	O
an	O
example	O
,	O
the	O
evaluation	O
of	O
the	O
goal	O
A(X,1 )	O
proceeds	O
by	O
evaluating	O
the	O
body	O
of	O
the	O
first	O
clause	O
with	O
Y	O
=	O
1	O
;	O
this	O
evaluation	O
adds	O
X>0	O
to	O
the	O
constraint	B-Application
store	I-Application
and	O
requires	O
the	O
goal	O
B(X,1 )	O
to	O
be	O
proven	O
.	O
</s>
<s>
While	O
trying	O
to	O
prove	O
this	O
goal	O
,	O
the	O
first	O
clause	O
is	O
applied	O
but	O
its	O
evaluation	O
adds	O
X	O
<	O
0	O
to	O
the	O
constraint	B-Application
store	I-Application
.	O
</s>
<s>
This	O
addition	O
makes	O
the	O
constraint	B-Application
store	I-Application
unsatisfiable	O
.	O
</s>
<s>
The	O
interpreter	B-Application
then	O
backtracks	B-Algorithm
,	O
removing	O
the	O
last	O
addition	O
from	O
the	O
constraint	B-Application
store	I-Application
.	O
</s>
<s>
The	O
evaluation	O
of	O
the	O
second	O
clause	O
adds	O
X	O
=	O
1	O
and	O
Y>0	O
to	O
the	O
constraint	B-Application
store	I-Application
.	O
</s>
<s>
Since	O
the	O
constraint	B-Application
store	I-Application
is	O
satisfiable	O
and	O
no	O
other	O
literal	O
is	O
left	O
to	O
prove	O
,	O
the	O
interpreter	B-Application
stops	O
with	O
the	O
solution	O
X	O
=	O
1	O
,	O
Y	O
=	O
1	O
.	O
</s>
<s>
The	O
semantics	O
of	O
constraint	O
logic	B-Language
programs	I-Language
can	O
be	O
defined	O
in	O
terms	O
of	O
a	O
virtual	O
interpreter	B-Application
that	O
maintains	O
a	O
pair	O
during	O
execution	O
.	O
</s>
<s>
The	O
first	O
element	O
of	O
this	O
pair	O
is	O
called	O
current	O
goal	O
;	O
the	O
second	O
element	O
is	O
called	O
constraint	B-Application
store	I-Application
.	O
</s>
<s>
The	O
current	O
goal	O
contains	O
the	O
literals	O
the	O
interpreter	B-Application
is	O
trying	O
to	O
prove	O
and	O
may	O
also	O
contain	O
some	O
constraints	O
it	O
is	O
trying	O
to	O
satisfy	O
;	O
the	O
constraint	B-Application
store	I-Application
contains	O
all	O
constraints	O
the	O
interpreter	B-Application
has	O
assumed	O
satisfiable	O
so	O
far	O
.	O
</s>
<s>
Initially	O
,	O
the	O
current	O
goal	O
is	O
the	O
goal	O
and	O
the	O
constraint	B-Application
store	I-Application
is	O
empty	O
.	O
</s>
<s>
The	O
interpreter	B-Application
proceeds	O
by	O
removing	O
the	O
first	O
element	O
from	O
the	O
current	O
goal	O
and	O
analyzing	O
it	O
.	O
</s>
<s>
This	O
analysis	O
may	O
involve	O
recursive	O
calls	O
and	O
addition	O
of	O
new	O
literals	O
to	O
the	O
current	O
goal	O
and	O
new	O
constraint	O
to	O
the	O
constraint	B-Application
store	I-Application
.	O
</s>
<s>
The	O
interpreter	B-Application
backtracks	B-Algorithm
if	O
a	O
failure	O
is	O
generated	O
.	O
</s>
<s>
A	O
successful	O
termination	O
is	O
generated	O
when	O
the	O
current	O
goal	O
is	O
empty	O
and	O
the	O
constraint	B-Application
store	I-Application
is	O
satisfiable	O
.	O
</s>
<s>
If	O
it	O
is	O
a	O
constraint	O
,	O
it	O
is	O
added	O
to	O
the	O
constraint	B-Application
store	I-Application
.	O
</s>
<s>
In	O
particular	O
,	O
the	O
constraint	B-Application
store	I-Application
is	O
checked	O
for	O
consistency	O
every	O
time	O
a	O
new	O
constraint	O
is	O
added	O
to	O
it	O
.	O
</s>
<s>
In	O
principle	O
,	O
whenever	O
the	O
constraint	B-Application
store	I-Application
is	O
unsatisfiable	O
the	O
algorithm	O
could	O
backtrack	O
.	O
</s>
<s>
In	O
practice	O
,	O
satisfiability	O
is	O
checked	O
using	O
methods	O
that	O
simplify	O
the	O
constraint	B-Application
store	I-Application
,	O
that	O
is	O
,	O
rewrite	O
it	O
into	O
an	O
equivalent	O
but	O
simpler-to-solve	O
form	O
.	O
</s>
<s>
These	O
methods	O
can	O
sometimes	O
but	O
not	O
always	O
prove	O
unsatisfiability	O
of	O
an	O
unsatisfiable	O
constraint	B-Application
store	I-Application
.	O
</s>
<s>
The	O
interpreter	B-Application
has	O
proved	O
the	O
goal	O
when	O
the	O
current	O
goal	O
is	O
empty	O
and	O
the	O
constraint	B-Application
store	I-Application
is	O
not	O
detected	O
unsatisfiable	O
.	O
</s>
<s>
Formally	O
,	O
the	O
semantics	O
of	O
constraint	B-Application
logic	I-Application
programming	I-Application
is	O
defined	O
in	O
terms	O
of	O
derivations	O
.	O
</s>
<s>
A	O
goal	O
can	O
be	O
proved	O
if	O
there	O
exists	O
a	O
derivation	O
from	O
to	O
for	O
some	O
satisfiable	O
constraint	B-Application
store	I-Application
.	O
</s>
<s>
This	O
semantics	O
formalizes	O
the	O
possible	O
evolutions	O
of	O
an	O
interpreter	B-Application
that	O
arbitrarily	O
chooses	O
the	O
literal	O
of	O
the	O
goal	O
to	O
process	O
and	O
the	O
clause	O
to	O
replace	O
literals	O
.	O
</s>
<s>
Actual	O
interpreters	B-Application
process	O
the	O
goal	O
elements	O
in	O
a	O
LIFO	B-Application
order	O
:	O
elements	O
are	O
added	O
in	O
the	O
front	O
and	O
processed	O
from	O
the	O
front	O
.	O
</s>
<s>
They	O
also	O
choose	O
the	O
clause	O
of	O
the	O
second	O
rule	O
according	O
to	O
the	O
order	O
in	O
which	O
they	O
are	O
written	O
,	O
and	O
rewrite	O
the	O
constraint	B-Application
store	I-Application
when	O
it	O
is	O
modified	O
.	O
</s>
<s>
The	O
third	O
possible	O
kind	O
of	O
transition	O
is	O
a	O
replacement	O
of	O
the	O
constraint	B-Application
store	I-Application
with	O
an	O
equivalent	O
one	O
.	O
</s>
<s>
This	O
replacement	O
is	O
limited	O
to	O
those	O
done	O
by	O
specific	O
methods	O
,	O
such	O
as	O
constraint	B-Application
propagation	I-Application
.	O
</s>
<s>
The	O
semantics	O
of	O
constraint	B-Application
logic	I-Application
programming	I-Application
is	O
parametric	O
not	O
only	O
to	O
the	O
kind	O
of	O
constraints	O
used	O
but	O
also	O
to	O
the	O
method	O
for	O
rewriting	O
the	O
constraint	B-Application
store	I-Application
.	O
</s>
<s>
The	O
specific	O
methods	O
used	O
in	O
practice	O
replace	O
the	O
constraint	B-Application
store	I-Application
with	O
one	O
that	O
is	O
simpler	O
to	O
solve	O
.	O
</s>
<s>
If	O
the	O
constraint	B-Application
store	I-Application
is	O
unsatisfiable	O
,	O
this	O
simplification	O
may	O
detect	O
this	O
unsatisfiability	O
sometimes	O
,	O
but	O
not	O
always	O
.	O
</s>
<s>
The	O
result	O
of	O
evaluating	O
a	O
goal	O
against	O
a	O
constraint	O
logic	B-Language
program	I-Language
is	O
defined	O
if	O
the	O
goal	O
is	O
proved	O
.	O
</s>
<s>
The	O
constraint	B-Application
store	I-Application
of	O
this	O
second	O
pair	O
is	O
considered	O
the	O
result	O
of	O
the	O
evaluation	O
.	O
</s>
<s>
This	O
is	O
because	O
the	O
constraint	B-Application
store	I-Application
contains	O
all	O
constraints	O
assumed	O
satisfiable	O
to	O
prove	O
the	O
goal	O
.	O
</s>
<s>
A	O
common	O
variant	O
of	O
the	O
semantics	O
for	O
constraint	B-Application
logic	I-Application
programming	I-Application
adds	O
directly	O
to	O
the	O
constraint	B-Application
store	I-Application
rather	O
than	O
to	O
the	O
goal	O
.	O
</s>
<s>
Different	O
definitions	O
of	O
terms	O
are	O
used	O
,	O
generating	O
different	O
kinds	O
of	O
constraint	B-Application
logic	I-Application
programming	I-Application
:	O
over	O
trees	O
,	O
reals	O
,	O
or	O
finite	O
domains	O
.	O
</s>
<s>
Such	O
constraints	O
are	O
necessary	O
because	O
the	O
interpreter	B-Application
adds	O
t1	O
=	O
t2	O
to	O
the	O
goal	O
whenever	O
a	O
literal	O
P( 	O
t1	O
...	O
)	O
is	O
replaced	O
with	O
the	O
body	O
of	O
a	O
clause	O
fresh	O
variant	O
whose	O
head	O
is	O
P( 	O
t2	O
...	O
)	O
.	O
</s>
<s>
Constraint	B-Application
logic	I-Application
programming	I-Application
with	O
tree	O
terms	O
emulates	O
regular	O
logic	B-Language
programming	I-Language
by	O
storing	O
substitutions	O
as	O
constraints	O
in	O
the	O
constraint	B-Application
store	I-Application
.	O
</s>
<s>
Equality	O
is	O
particularly	O
important	O
,	O
as	O
constraints	O
like	O
t1	O
=	O
t2	O
are	O
often	O
generated	O
by	O
the	O
interpreter	B-Application
.	O
</s>
<s>
Equality	O
constraints	O
on	O
terms	O
can	O
be	O
simplified	O
,	O
that	O
is	O
solved	O
,	O
via	O
unification	B-Algorithm
:	O
</s>
<s>
As	O
a	O
result	O
,	O
the	O
other	O
term	O
can	O
replace	O
the	O
variable	O
in	O
the	O
current	O
goal	O
and	O
constraint	B-Application
store	I-Application
,	O
thus	O
practically	O
removing	O
the	O
variable	O
from	O
consideration	O
.	O
</s>
<s>
In	O
this	O
form	O
of	O
constraint	B-Application
satisfaction	I-Application
,	O
variable	O
values	O
are	O
terms	O
.	O
</s>
<s>
Constraint	B-Application
logic	I-Application
programming	I-Application
with	O
real	O
numbers	O
uses	O
real	O
expressions	O
as	O
terms	O
.	O
</s>
<s>
Equality	O
between	O
terms	O
is	O
a	O
kind	O
of	O
constraint	O
that	O
is	O
always	O
present	O
,	O
as	O
the	O
interpreter	B-Application
generates	O
equality	O
of	O
terms	O
during	O
execution	O
.	O
</s>
<s>
As	O
an	O
example	O
,	O
if	O
the	O
first	O
literal	O
of	O
the	O
current	O
goal	O
is	O
A( X+1	O
)	O
and	O
the	O
interpreter	B-Application
has	O
chosen	O
a	O
clause	O
that	O
is	O
A(Y-1 )	O
:-Y	O
=	O
1	O
after	O
rewriting	O
is	O
variables	O
,	O
the	O
constraints	O
added	O
to	O
the	O
current	O
goal	O
are	O
X+1	O
=	O
Y-1	O
and	O
.	O
</s>
<s>
The	O
third	O
class	O
of	O
constraints	O
used	O
in	O
constraint	B-Application
logic	I-Application
programming	I-Application
is	O
that	O
of	O
finite	O
domains	O
.	O
</s>
<s>
Indeed	O
,	O
as	O
the	O
interpreter	B-Application
adds	O
constraints	O
to	O
the	O
constraint	B-Application
store	I-Application
,	O
it	O
performs	O
constraint	B-Application
propagation	I-Application
to	O
enforce	O
a	O
form	O
of	O
local	B-Application
consistency	I-Application
,	O
and	O
these	O
operations	O
may	O
reduce	O
the	O
domain	O
of	O
variables	O
.	O
</s>
<s>
If	O
the	O
domain	O
of	O
a	O
variable	O
becomes	O
empty	O
,	O
the	O
constraint	B-Application
store	I-Application
is	O
inconsistent	O
,	O
and	O
the	O
algorithm	O
backtracks	B-Algorithm
.	O
</s>
<s>
The	O
forms	O
of	O
consistency	O
typically	O
enforced	O
are	O
arc	O
consistency	O
,	O
hyper-arc	B-Application
consistency	I-Application
,	O
and	O
bound	B-Application
consistency	I-Application
.	O
</s>
<s>
The	O
constraint	B-Application
store	I-Application
contains	O
the	O
constraints	O
that	O
are	O
currently	O
assumed	O
satisfiable	O
.	O
</s>
<s>
It	O
can	O
be	O
considered	O
what	O
the	O
current	O
substitution	O
is	O
for	O
regular	O
logic	B-Language
programming	I-Language
.	O
</s>
<s>
When	O
only	O
tree	O
terms	O
are	O
allowed	O
,	O
the	O
constraint	B-Application
store	I-Application
contains	O
constraints	O
in	O
the	O
form	O
t1	O
=	O
t2	O
;	O
these	O
constraints	O
are	O
simplified	O
by	O
unification	B-Algorithm
,	O
resulting	O
in	O
constraints	O
of	O
the	O
form	O
variable	O
=	O
term	O
;	O
such	O
constraints	O
are	O
equivalent	O
to	O
a	O
substitution	O
.	O
</s>
<s>
However	O
,	O
the	O
constraint	B-Application
store	I-Application
may	O
also	O
contain	O
constraints	O
in	O
the	O
form	O
t1	O
!=	O
t2	O
,	O
if	O
the	O
difference	O
!=	O
between	O
terms	O
is	O
allowed	O
.	O
</s>
<s>
When	O
constraints	O
over	O
reals	O
or	O
finite	O
domains	O
are	O
allowed	O
,	O
the	O
constraint	B-Application
store	I-Application
may	O
also	O
contain	O
domain-specific	O
constraints	O
like	O
X+2	O
=	O
Y/2	O
,	O
etc	O
.	O
</s>
<s>
The	O
constraint	B-Application
store	I-Application
extends	O
the	O
concept	O
of	O
current	O
substitution	O
in	O
two	O
ways	O
.	O
</s>
<s>
While	O
the	O
result	O
of	O
a	O
successful	O
evaluation	O
of	O
a	O
regular	O
logic	B-Language
program	I-Language
is	O
the	O
final	O
substitution	O
,	O
the	O
result	O
for	O
a	O
constraint	O
logic	B-Language
program	I-Language
is	O
the	O
final	O
constraint	B-Application
store	I-Application
,	O
which	O
may	O
contain	O
constraint	O
of	O
the	O
form	O
variable	O
=	O
value	O
but	O
in	O
general	O
may	O
contain	O
arbitrary	O
constraints	O
.	O
</s>
<s>
Domain-specific	O
constraints	O
may	O
come	O
to	O
the	O
constraint	B-Application
store	I-Application
both	O
from	O
the	O
body	O
of	O
a	O
clauses	O
and	O
from	O
equating	O
a	O
literal	O
with	O
a	O
clause	O
head	O
:	O
for	O
example	O
,	O
if	O
the	O
interpreter	B-Application
rewrites	O
the	O
literal	O
A( X+2	O
)	O
with	O
a	O
clause	O
whose	O
fresh	O
variant	O
head	O
is	O
A( 	O
Y/2	O
)	O
,	O
the	O
constraint	O
X+2	O
=	O
Y/2	O
is	O
added	O
to	O
the	O
constraint	B-Application
store	I-Application
.	O
</s>
<s>
The	O
constraint	B-Application
store	I-Application
is	O
unsatisfiable	O
if	O
a	O
variable	O
is	O
bound	O
to	O
take	O
both	O
a	O
value	O
of	O
the	O
specific	O
domain	O
and	O
a	O
functor	O
applied	O
to	O
terms	O
.	O
</s>
<s>
After	O
a	O
constraint	O
is	O
added	O
to	O
the	O
constraint	B-Application
store	I-Application
,	O
some	O
operations	O
are	O
performed	O
on	O
the	O
constraint	B-Application
store	I-Application
.	O
</s>
<s>
For	O
example	O
,	O
unification	B-Algorithm
is	O
used	O
for	O
finite	O
tree	O
equalities	O
,	O
variable	O
elimination	O
for	O
polynomial	O
equations	O
over	O
reals	O
,	O
constraint	B-Application
propagation	I-Application
to	O
enforce	O
a	O
form	O
of	O
local	B-Application
consistency	I-Application
for	O
finite	O
domains	O
.	O
</s>
<s>
These	O
operations	O
are	O
aimed	O
at	O
making	O
the	O
constraint	B-Application
store	I-Application
simpler	O
to	O
be	O
checked	O
for	O
satisfiability	O
and	O
solved	O
.	O
</s>
<s>
It	O
is	O
essential	O
that	O
the	O
interpreter	B-Application
is	O
able	O
to	O
undo	O
these	O
changes	O
when	O
it	O
backtracks	B-Algorithm
.	O
</s>
<s>
The	O
simplest	O
case	O
method	O
is	O
for	O
the	O
interpreter	B-Application
to	O
save	O
the	O
complete	O
state	O
of	O
the	O
store	O
every	O
time	O
it	O
makes	O
a	O
choice	O
(	O
it	O
chooses	O
a	O
clause	O
to	O
rewrite	O
a	O
goal	O
)	O
.	O
</s>
<s>
More	O
efficient	O
methods	O
for	O
allowing	O
the	O
constraint	B-Application
store	I-Application
to	O
return	O
to	O
a	O
previous	O
state	O
exist	O
.	O
</s>
<s>
In	O
particular	O
,	O
one	O
may	O
just	O
save	O
the	O
changes	O
to	O
the	O
constraint	B-Application
store	I-Application
made	O
between	O
two	O
points	O
of	O
choice	O
,	O
including	O
the	O
changes	O
made	O
to	O
the	O
old	O
constraints	O
.	O
</s>
<s>
This	O
second	O
method	O
is	O
called	O
semantic	O
backtracking	B-Algorithm
,	O
</s>
<s>
The	O
labeling	O
literals	O
are	O
used	O
on	O
variables	O
over	O
finite	O
domains	O
to	O
check	O
satisfiability	O
or	O
partial	O
satisfiability	O
of	O
the	O
constraint	B-Application
store	I-Application
and	O
to	O
find	O
a	O
satisfying	O
assignment	O
.	O
</s>
<s>
Whenever	O
the	O
interpreter	B-Application
evaluates	O
such	O
a	O
literal	O
,	O
it	O
performs	O
a	O
search	O
over	O
the	O
domains	O
of	O
the	O
variables	O
of	O
the	O
list	O
to	O
find	O
an	O
assignment	O
that	O
satisfies	O
all	O
relevant	O
constraints	O
.	O
</s>
<s>
Typically	O
,	O
this	O
is	O
done	O
by	O
a	O
form	O
of	O
backtracking	B-Algorithm
:	O
variables	O
are	O
evaluated	O
in	O
order	O
,	O
trying	O
all	O
possible	O
values	O
for	O
each	O
of	O
them	O
,	O
and	O
backtracking	B-Algorithm
when	O
inconsistency	O
is	O
detected	O
.	O
</s>
<s>
The	O
first	O
use	O
of	O
the	O
labeling	O
literal	O
is	O
to	O
actual	O
check	O
satisfiability	O
or	O
partial	O
satisfiability	O
of	O
the	O
constraint	B-Application
store	I-Application
.	O
</s>
<s>
When	O
the	O
interpreter	B-Application
adds	O
a	O
constraint	O
to	O
the	O
constraint	B-Application
store	I-Application
,	O
it	O
only	O
enforces	O
a	O
form	O
of	O
local	B-Application
consistency	I-Application
on	O
it	O
.	O
</s>
<s>
This	O
operation	O
may	O
not	O
detect	O
inconsistency	O
even	O
if	O
the	O
constraint	B-Application
store	I-Application
is	O
unsatisfiable	O
.	O
</s>
<s>
As	O
a	O
result	O
,	O
using	O
all	O
variables	O
mentioned	O
in	O
the	O
constraint	B-Application
store	I-Application
results	O
in	O
checking	O
satisfiability	O
of	O
the	O
store	O
.	O
</s>
<s>
The	O
second	O
use	O
of	O
the	O
labeling	O
literal	O
is	O
to	O
actually	O
determine	O
an	O
evaluation	O
of	O
the	O
variables	O
that	O
satisfies	O
the	O
constraint	B-Application
store	I-Application
.	O
</s>
<s>
Without	O
the	O
labeling	O
literal	O
,	O
variables	O
are	O
assigned	O
values	O
only	O
when	O
the	O
constraint	B-Application
store	I-Application
contains	O
a	O
constraint	O
of	O
the	O
form	O
X	O
=	O
value	O
and	O
when	O
local	B-Application
consistency	I-Application
reduces	O
the	O
domain	O
of	O
a	O
variable	O
to	O
a	O
single	O
value	O
.	O
</s>
<s>
Typically	O
,	O
constraint	O
logic	B-Language
programs	I-Language
are	O
written	O
in	O
such	O
a	O
way	O
labeling	O
literals	O
are	O
evaluated	O
only	O
after	O
as	O
many	O
constraints	O
as	O
possible	O
have	O
been	O
accumulated	O
in	O
the	O
constraint	B-Application
store	I-Application
.	O
</s>
<s>
A	O
constraint	B-Application
satisfaction	I-Application
problem	I-Application
is	O
typical	O
solved	O
by	O
a	O
constraint	O
logic	B-Language
program	I-Language
having	O
the	O
following	O
structure	O
:	O
</s>
<s>
When	O
the	O
interpreter	B-Application
evaluates	O
the	O
goal	O
solve(args )	O
,	O
it	O
places	O
the	O
body	O
of	O
a	O
fresh	O
variant	O
of	O
the	O
first	O
clause	O
in	O
the	O
current	O
goal	O
.	O
</s>
<s>
Since	O
the	O
first	O
goal	O
is	O
constraints(X' )	O
,	O
the	O
second	O
clause	O
is	O
evaluated	O
,	O
and	O
this	O
operation	O
moves	O
all	O
constraints	O
in	O
the	O
current	O
goal	O
and	O
eventually	O
in	O
the	O
constraint	B-Application
store	I-Application
.	O
</s>
<s>
The	O
literal	O
labeling(X' )	O
is	O
then	O
evaluated	O
,	O
forcing	O
a	O
search	O
for	O
a	O
solution	O
of	O
the	O
constraint	B-Application
store	I-Application
.	O
</s>
<s>
Since	O
the	O
constraint	B-Application
store	I-Application
contains	O
exactly	O
the	O
constraints	O
of	O
the	O
original	O
constraint	B-Application
satisfaction	I-Application
problem	I-Application
,	O
this	O
operation	O
searches	O
for	O
a	O
solution	O
of	O
the	O
original	O
problem	O
.	O
</s>
<s>
A	O
given	O
constraint	O
logic	B-Language
program	I-Language
may	O
be	O
reformulated	O
to	O
improve	O
its	O
efficiency	O
.	O
</s>
<s>
A	O
first	O
rule	O
is	O
that	O
labeling	O
literals	O
should	O
be	O
placed	O
after	O
as	O
much	O
constraints	O
on	O
the	O
labeled	O
literals	O
are	O
accumulated	O
in	O
the	O
constraint	B-Application
store	I-Application
.	O
</s>
<s>
While	O
in	O
theory	O
is	O
equivalent	O
to	O
,	O
the	O
search	O
that	O
is	O
performed	O
when	O
the	O
interpreter	B-Application
encounters	O
the	O
labeling	O
literal	O
is	O
on	O
a	O
constraint	B-Application
store	I-Application
that	O
does	O
not	O
contain	O
the	O
constraint	O
X>0	O
.	O
</s>
<s>
On	O
the	O
other	O
hand	O
,	O
in	O
the	O
second	O
formulation	O
the	O
search	O
is	O
performed	O
only	O
when	O
the	O
constraint	O
is	O
already	O
in	O
the	O
constraint	B-Application
store	I-Application
.	O
</s>
<s>
For	O
example	O
,	O
if	O
the	O
constraint	B-Application
store	I-Application
contains	O
the	O
constraint	O
X	O
<-	O
2	O
,	O
the	O
interpreter	B-Application
recursively	O
evaluates	O
B(X )	O
in	O
the	O
first	O
case	O
;	O
if	O
it	O
succeeds	O
,	O
it	O
then	O
finds	O
out	O
that	O
the	O
constraint	B-Application
store	I-Application
is	O
inconsistent	O
when	O
adding	O
X>0	O
.	O
</s>
<s>
In	O
the	O
second	O
case	O
,	O
when	O
evaluating	O
that	O
clause	O
,	O
the	O
interpreter	B-Application
first	O
adds	O
X>0	O
to	O
the	O
constraint	B-Application
store	I-Application
and	O
then	O
possibly	O
evaluates	O
B(X )	O
.	O
</s>
<s>
Since	O
the	O
constraint	B-Application
store	I-Application
after	O
the	O
addition	O
of	O
X>0	O
turns	O
out	O
to	O
be	O
inconsistent	O
,	O
the	O
recursive	O
evaluation	O
of	O
B(X )	O
is	O
not	O
performed	O
at	O
all	O
.	O
</s>
<s>
If	O
the	O
programmer	O
knows	O
(	O
by	O
whatever	O
means	O
)	O
that	O
the	O
solution	O
of	O
a	O
problem	O
satisfies	O
a	O
specific	O
constraint	O
,	O
they	O
can	O
include	O
that	O
constraint	O
to	O
cause	O
inconsistency	O
of	O
the	O
constraint	B-Application
store	I-Application
as	O
soon	O
as	O
possible	O
.	O
</s>
<s>
On	O
the	O
other	O
hand	O
,	O
if	O
the	O
above	O
clause	O
is	O
replaced	O
by	O
,	O
the	O
interpreter	B-Application
backtracks	B-Algorithm
as	O
soon	O
as	O
the	O
constraint	O
X>0	O
is	O
added	O
to	O
the	O
constraint	B-Application
store	I-Application
,	O
which	O
happens	O
before	O
the	O
evaluation	O
of	O
B(X )	O
even	O
starts	O
.	O
</s>
<s>
Constraint	B-Application
handling	I-Application
rules	I-Application
were	O
initially	O
defined	O
as	O
a	O
stand-alone	O
formalism	O
for	O
specifying	O
constraint	B-Application
solvers	I-Application
,	O
and	O
were	O
later	O
embedded	O
in	O
logic	B-Language
programming	I-Language
.	O
</s>
<s>
There	O
are	O
two	O
kinds	O
of	O
constraint	B-Application
handling	I-Application
rules	I-Application
.	O
</s>
<s>
In	O
a	O
constraint	B-Application
logic	I-Application
programming	I-Application
language	O
supporting	O
constraint	B-Application
handling	I-Application
rules	I-Application
,	O
a	O
programmer	O
can	O
use	O
these	O
rules	O
to	O
specify	O
possible	O
rewritings	O
of	O
the	O
constraint	B-Application
store	I-Application
and	O
possible	O
additions	O
of	O
constraints	O
to	O
it	O
.	O
</s>
<s>
The	O
second	O
rule	O
instead	O
specifies	O
that	O
the	O
latter	O
constraint	O
is	O
a	O
consequence	O
of	O
the	O
first	O
,	O
if	O
the	O
constraint	O
in	O
the	O
middle	O
is	O
entailed	O
by	O
the	O
constraint	B-Application
store	I-Application
.	O
</s>
<s>
As	O
a	O
result	O
,	O
if	O
A(X )	O
is	O
in	O
the	O
constraint	B-Application
store	I-Application
and	O
B(X )	O
is	O
entailed	O
by	O
the	O
constraint	B-Application
store	I-Application
,	O
then	O
C(X )	O
can	O
be	O
added	O
to	O
the	O
store	O
.	O
</s>
<s>
Equivalence	O
allows	O
for	O
simplifying	O
the	O
constraint	B-Application
store	I-Application
by	O
replacing	O
some	O
constraints	O
with	O
simpler	O
ones	O
;	O
in	O
particular	O
,	O
if	O
the	O
third	O
constraint	O
in	O
an	O
equivalence	O
rule	O
is	O
true	O
,	O
and	O
the	O
second	O
constraint	O
is	O
entailed	O
,	O
the	O
first	O
constraint	O
is	O
removed	O
from	O
the	O
constraint	B-Application
store	I-Application
.	O
</s>
<s>
Inference	O
allows	O
for	O
the	O
addition	O
of	O
new	O
constraints	O
,	O
which	O
may	O
lead	O
to	O
proving	O
inconsistency	O
of	O
the	O
constraint	B-Application
store	I-Application
,	O
and	O
may	O
generally	O
reduce	O
the	O
amount	O
of	O
search	O
needed	O
to	O
establish	O
its	O
satisfiability	O
.	O
</s>
<s>
Logic	B-Language
programming	I-Language
clauses	O
in	O
conjunction	O
with	O
constraint	B-Application
handling	I-Application
rules	I-Application
can	O
be	O
used	O
to	O
specify	O
a	O
method	O
for	O
establishing	O
the	O
satisfiability	O
of	O
the	O
constraint	B-Application
store	I-Application
.	O
</s>
<s>
Different	O
clauses	O
are	O
used	O
to	O
implement	O
the	O
different	O
choices	O
of	O
the	O
method	O
;	O
the	O
constraint	B-Application
handling	I-Application
rules	I-Application
are	O
used	O
for	O
rewriting	O
the	O
constraint	B-Application
store	I-Application
during	O
execution	O
.	O
</s>
<s>
As	O
an	O
example	O
,	O
one	O
can	O
implement	O
backtracking	B-Algorithm
with	O
unit	O
propagation	O
this	O
way	O
.	O
</s>
<s>
The	O
algorithm	O
can	O
be	O
implemented	O
using	O
clauses	O
for	O
the	O
choice	O
of	O
assigning	O
a	O
literal	O
to	O
true	O
or	O
false	O
,	O
and	O
constraint	B-Application
handling	I-Application
rules	I-Application
to	O
specify	O
propagation	O
.	O
</s>
<s>
example	O
,	O
the	O
choice	O
of	O
value	O
for	O
a	O
variable	O
is	O
implemented	O
using	O
clauses	O
of	O
logic	B-Language
programming	I-Language
;	O
however	O
,	O
it	O
can	O
be	O
encoded	O
in	O
constraint	B-Application
handling	I-Application
rules	I-Application
using	O
an	O
extension	O
called	O
disjunctive	O
constraint	B-Application
handling	I-Application
rules	I-Application
or	O
CHR∨	O
.	O
</s>
<s>
The	O
standard	O
strategy	O
of	O
evaluation	O
of	O
logic	B-Language
programs	I-Language
is	O
top-down	O
and	O
depth-first	B-Algorithm
:	O
from	O
the	O
goal	O
,	O
a	O
number	O
of	O
clauses	O
are	O
identified	O
as	O
being	O
possibly	O
able	O
to	O
prove	O
the	O
goal	O
,	O
and	O
recursion	O
over	O
the	O
literals	O
of	O
their	O
bodies	O
is	O
performed	O
.	O
</s>
<s>
In	O
particular	O
,	O
finding	O
all	O
consequences	O
of	O
a	O
program	O
in	O
the	O
standard	O
top-down	O
and	O
depth-first	B-Algorithm
manner	O
may	O
not	O
terminate	O
while	O
the	O
bottom-up	O
evaluation	B-Language
strategy	I-Language
terminates	O
.	O
</s>
<s>
The	O
bottom-up	O
evaluation	B-Language
strategy	I-Language
maintains	O
the	O
set	O
of	O
facts	O
proved	O
so	O
far	O
during	O
evaluation	O
.	O
</s>
<s>
The	O
advantage	O
of	O
the	O
bottom-up	O
evaluation	O
over	O
the	O
top-down	O
one	O
is	O
that	O
cycles	O
of	O
derivations	O
do	O
not	O
produce	O
an	O
infinite	B-Algorithm
loop	I-Algorithm
.	O
</s>
<s>
More	O
generally	O
,	O
the	O
top-down	O
evaluation	B-Language
strategy	I-Language
may	O
cycle	O
over	O
possible	O
derivations	O
,	O
possibly	O
when	O
other	O
ones	O
exist	O
.	O
</s>
<s>
The	O
concurrent	O
versions	O
of	O
constraint	B-Application
logic	I-Application
programming	I-Application
are	O
aimed	O
at	O
programming	O
concurrent	O
processes	O
rather	O
than	O
solving	O
constraint	B-Application
satisfaction	I-Application
problems	I-Application
.	O
</s>
<s>
Goals	O
in	O
constraint	B-Application
logic	I-Application
programming	I-Application
are	O
evaluated	O
concurrently	O
;	O
a	O
concurrent	B-Architecture
process	I-Architecture
is	O
therefore	O
programmed	O
as	O
the	O
evaluation	O
of	O
a	O
goal	O
by	O
the	O
interpreter	B-Application
.	O
</s>
<s>
Syntactically	O
,	O
concurrent	O
constraints	O
logic	B-Language
programs	I-Language
are	O
similar	O
to	O
non-concurrent	O
programs	O
,	O
the	O
only	O
exception	O
being	O
that	O
clauses	O
includes	O
guards	O
,	O
which	O
are	O
constraints	O
that	O
may	O
block	O
the	O
applicability	O
of	O
the	O
clause	O
under	O
some	O
conditions	O
.	O
</s>
<s>
Semantically	O
,	O
concurrent	O
constraint	B-Application
logic	I-Application
programming	I-Application
differs	O
from	O
its	O
non-concurrent	O
versions	O
because	O
a	O
goal	O
evaluation	O
is	O
intended	O
to	O
realize	O
a	O
concurrent	B-Architecture
process	I-Architecture
rather	O
than	O
finding	O
a	O
solution	O
to	O
a	O
problem	O
.	O
</s>
<s>
Most	O
notably	O
,	O
this	O
difference	O
affects	O
how	O
the	O
interpreter	B-Application
behaves	O
when	O
more	O
than	O
one	O
clause	O
is	O
applicable	O
:	O
non-concurrent	O
constraint	B-Application
logic	I-Application
programming	I-Application
recursively	O
tries	O
all	O
clauses	O
;	O
concurrent	O
constraint	B-Application
logic	I-Application
programming	I-Application
chooses	O
only	O
one	O
.	O
</s>
<s>
This	O
is	O
the	O
most	O
evident	O
effect	O
of	O
an	O
intended	O
directionality	O
of	O
the	O
interpreter	B-Application
,	O
which	O
never	O
revises	O
a	O
choice	O
it	O
has	O
previously	O
taken	O
.	O
</s>
<s>
Constraint	B-Application
logic	I-Application
programming	I-Application
has	O
been	O
applied	O
to	O
a	O
number	O
of	O
fields	O
,	O
such	O
as	O
automated	B-Application
scheduling	I-Application
,	O
type	O
inference	O
,	O
civil	O
engineering	O
,	O
mechanical	O
engineering	O
,	O
digital	O
circuit	O
verification	O
,	O
air	B-Application
traffic	I-Application
control	I-Application
,	O
finance	O
,	O
and	O
others	O
.	O
</s>
<s>
Constraint	B-Application
logic	I-Application
programming	I-Application
was	O
introduced	O
by	O
Jaffar	O
and	O
Lassez	O
in	O
1987	O
.	O
</s>
<s>
They	O
generalized	O
the	O
observation	O
that	O
the	O
term	O
equations	O
and	O
disequations	O
of	O
Prolog	B-Language
II	I-Language
were	O
a	O
specific	O
form	O
of	O
constraints	O
,	O
and	O
generalized	O
this	O
idea	O
to	O
arbitrary	O
constraint	O
languages	O
.	O
</s>
<s>
The	O
first	O
implementations	O
of	O
this	O
concept	O
were	O
Prolog	B-Language
III	O
,	O
CLP(R )	O
,	O
and	O
CHIP	B-Application
.	O
</s>
