SWI-Prolog and Limitations, CLP Library (FD)

I play with restrictions in the (swi) prolog using the clpfd library.

I am trying to determine when one set of constraints encapsulates or includes another, for example. X <4 encapsulates X <7 as always, when the former is true, the latter is true. This can be easily imagined using logical implication. However, I could not force the operator # ==> to give me the result that I needed, so I resorted to using not (Co1 # / \ # \ Co2), where Co1 and Co2 are limitations. This is normal for individual constraints, but then I wanted to convey constraint conjunctions in Co1 and Co2.

Now here is the rubbing. When i try

X#<7 #/\ #\X#<4.

I'm coming back

X in 4..6,
X+1#=_G822,
X+1#=_G834,
_G822 in 5..7,
_G834 in 5..7.

(oddly enough, doing this in Sicstus results in a segmentation error)

When i turn in

X#<7,X#<4

I get the desired

X in inf..3.

, (Co1 #/\ #\Co2), , . - , , ?

+5
2

, CLP (FD). .

CLP (FD) . . , , , "" , CLP (FD). "" .

, CLP (FD). CLP (FD) , - . , GNU Prolog , SWI Prolog . , , , :

SWI-:

?- X #< Y, Y #< Z, Z #< X.
Z#=<X+ -1,
X#=<Y+ -1,
Y#=<Z+ -1.

GNU Prolog:

?- X #< Y, Y #< Z, Z #< X.
(7842 ms) no

, , , . , . :

SWI-:

?- X #< 4 #==> X #< 7.
X+1#=_G1330,
X+1#=_G1342,
7#>=_G1330#<==>_G1354,
_G1354 in 0..1,
_G1377#==>_G1354,
_G1377 in 0..1,
4#>=_G1342#<==>_G1377.

GNU Prolog:

?- X #< 4 #==> X #< 7.
X = _#22(0..268435455)

. . , :

SWI-:

?- X in 0..9, X #< 4 #==> X #< 7, label([X]).
X = 0 ;
X = 1 ;
X = 2 ;
X = 3 ;
X = 4 ;
X = 5 ;
X = 6 ;
X = 7 ;
X = 8 ;
X = 9.

GNU Prolog:

?- fd_domain(X,0,9), X #< 4 #==> X #< 7, fd_labeling([X]).
X = 0 ? ;
X = 1 ? ;
X = 2 ? ;
X = 3 ? ;
X = 4 ? ;
X = 5 ? ;
X = 6 ? ;
X = 7 ? ;
X = 8 ? ;
X = 9

SICStus Prolog B-Prolog. , - SWI-Prolog GNU Prolog.

CLP (Q) , FD, "" , CLP (FD) . , CLP (FD), CLP (Q):

X = Y + 1, Y < Z, Z < X.

Bye

+2

. , , , . , , , , , /2. , Q , SWI-Prolog (clpq) . , CLP (Q) :

?- use_module(library(clpq)).
true.

?- { X < 4, X >= 7 }.
false.

, Q (, Z), , , .

+4

All Articles