Some results let me think SWI-Prolog achieves arc consistency in case of
binary constraints, anyway I cannot find anything about in the manual.
Try this CSP:
X in 0..2\/4\/7\/10..12,
Y in 0..4\/7..16\/18\/21\/23\/24,
Y #= 2*X.
You will get:
X in 0..2\/4\/7\/12
Y in 0..4\/8\/14\/24
So, is it only a coincidence or is it a real implemented functionality?
Thanks!
Mic
No so many CLP(FD) systems maintain AC by default. Here are what I got
from three other systems:
B-Prolog:
| ?- X in [0..2,4,7,10..12],Y in [0..4,7..16,18,21,23,24],Y #= 2*X.
X = _0770:[0..2,4,7,12]
Y = _07a4:[0,2,4,8,14,24]
Eclipse:
[eclipse 2]: X :: [0..2,4,7,10..12],Y :: [0..4,7..16,18,21,23,24],Y #=
2*X.
X = X{[0 .. 2, 4, 7, 10 .. 12]}
Y = Y{[0 .. 4, 7 .. 16, 18, 21, 23, 24]}
Sicstus:
| ?- X in {0,1,2,4,7,10,12},Y in
{0,1,2,3,4,7,8,9,10,11,12,13,14,15,16,18,21,23,24},Y #= 2*X.
X in(0..2)\/{4}\/{7}\/{10}\/{12},
Y in(0..4)\/(7..16)\/{18}\/{21}\/(23..24) ? yes
As you can see, only B-Prolog maintains AC for this example.
Cheers,
Neng-Fa
What one sees primarily is that syntax for clpdf is quite
different and that also toplevels differ.
SICStus and SWI produce answers that are valid Prolog text
and can be pasted back to the toplevel. ECLiPse has some
syntax similar but not identical to actual goals.
B does not show any answers on the toplevel - not clear how you
produce them.
You don't need to worry about losing your job if you work on the ISO
committee:-) There are simply lots of things to standardize for clp
(FD).
I think that the notation [1..3,5..6] used in B-Prolog and Eclipse is
more readable than {1..3}\/{5..6} or 1..3\/5..6.
Cheers,
Neng-Fa
Readability is difficult to evaluate. I am used to \/ so much
that I am biased as well. So let us just start with the meaning.
What does
?- X :: [1..2,[3]].
mean? It is accepted in both systems. In B even labeling is possible,
but with unusual results:
| ?- X :: [1..2,[3]].
X = 1..2 ?
X = [3] ?;
You get this output because the system treats the domain as non-
integer (an integer set is a list of integers and integer intervals).
In general, a domain can be a list of arbitrary ground terms in B-
Prolog. For example,
| ?- X :: [a,1,f(b)], indomain(X)
X = a ?;
X = 1 ?;
X = f(b) ?;
Cheers,
Neng-Fa
The list can contain arbitrary ground terms - except (..)/2
which sometimes means an interval and sometimes means the
term literally. Also, the interpretation of the list as
description for a domain of integers depends on
all elements in the list. You cannot tell whether or not
you have an fd variable by simply reading from left.
?- X :: [1..2,6,8,9,*********
Depending on what follows at ***, you have either integers:
?- X :: [1..2,6,8,9,120].
or you have arbitrary terms:
?- X :: [1..2,6,8,9,12.0].
To recapitulate:
| ?- X :: 1..2, labeling(X).
X = 1 ?;
X = 2 ?;
no
| ?- X :: [1..2], labeling(X).
X = 1 ?;
X = 2 ?;
no
| ?- X :: [[1..2]], labeling(X).
X = [1..2] ?;
no
The first two are valid domains for 1 and 2. But the last is
the element itself.
| ?- X :: [x,l..2], labeling(X).
X = x ?;
X = l..2 ?;
no
| ?- X :: [l..2], labeling(X).
*** error(invalid_argument,c_integers_intervals_list/4)