I have written a CSP program using CLP(FD) and SWI-Prolog.
I think I need to improve my constraints' writing when I use the mod
operator
together with #\/
in my predicates.
A short example :
:- use_module(library(clpfd)).
constr(X,Y,Z) :-
X in {1,2,3,4,5,6,7},
Y in {3,5,7},
Z in {1,2},
((X #= 3)) #==> ((Y mod 3 #= 0) #\/ (Y mod 7 #= 0)),
((Z #= 1)) #<==> ((Y mod 3 #= 0) #\/ (Y mod 7 #= 0)).
If I call constr(3,Y,Z).
, I get Z #= 1
or Z #= 2
.
This is because some intermediate variables (relative to the mod
expressions) still need to be evaluated.
Of course the ideal would be to only obtain Z #= 1
.
How could this be done ?
I know that if I write instead
((X #= 3)) #==> ((Z #= 1)),
((Z #= 1)) #<==> ((Y mod 3 #= 0) #\/ (Y mod 7 #= 0)).
everything works as expected.
But is this reification mandatory ? I mean, do I have to create a reification variable each time I have this pattern in my constraints :
(A mod n1 #= 0) #\/ (B mod n2 #= 0) #\/ ... #\/ (Z mod n26 #= 0)
Thanks in advance for your ideas.