Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SWI-Prolog 5.8, binary constraints and AC

0 views
Skip to first unread message

Mic

unread,
Nov 18, 2009, 4:29:44 AM11/18/09
to
Hi!

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

afa

unread,
Nov 19, 2009, 11:57:11 AM11/19/09
to

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

Ulrich Neumerkel

unread,
Nov 19, 2009, 5:39:04 PM11/19/09
to
afa <neng...@gmail.com> writes:

>On Nov 18, 5:29=A0am, Mic <a...@aaa.aaa> wrote:
>> Hi!
>>
>> 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 #=3D 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 #=3D 2*X.
>X =3D _0770:[0..2,4,7,12]
>Y =3D _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 #=3D
>2*X.
>
>X =3D X{[0 .. 2, 4, 7, 10 .. 12]}
>Y =3D 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 #=3D 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.

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.

afa

unread,
Nov 23, 2009, 2:47:32 PM11/23/09
to
On Nov 19, 5:39 pm, ulr...@mips.complang.tuwien.ac.at (Ulrich

Neumerkel) wrote:
> What one sees primarily is that syntax for clpdf is quite
> different and that also toplevels differ.

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


Ulrich Neumerkel

unread,
Nov 24, 2009, 12:00:23 AM11/24/09
to
afa <neng...@gmail.com> writes:
>On Nov 19, 5:39=A0pm, ulr...@mips.complang.tuwien.ac.at (Ulrich

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] ?;

afa

unread,
Nov 24, 2009, 10:24:12 AM11/24/09
to
On Nov 24, 12:00 am, ulr...@mips.complang.tuwien.ac.at (Ulrich
Neumerkel) wrote:

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

Ulrich Neumerkel

unread,
Nov 24, 2009, 10:56:29 AM11/24/09
to
afa <neng...@gmail.com> writes:
>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) ?;

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)

0 new messages