I have been trying to learn prolog but I am having issues with limiting the possible integers that can be used in my solutions. For example, In my SWI terminal, I ran
[X,Y,Z] ins 0..1,X #\= Y, Y #\= Z, Z#\= Y.
and as output I got
X in 0..1,
X#\=Y,
Y in 0..1,
Z#\=Y,
Y#\=Z,
Z in 0..1.
when I wanted to get false.
This is just an instance of an issue I have been having. I am working on a project that involves comparing permutations of lists of length 4. My code there is
:- use_module(library(clpfd)).
peice(Ps) :-
length(Ps,4),
Ps ins -2..2.
rotate(peice(X),peice(Y)) :-
X = [A,B,C,D],
Y = [B,C,D,A].
onedifrent(peice([A1,_,_,_]),peice([A2,_,_,_])) :- A1 #\= A2.
onedifrent(peice([_,B1,_,_]),peice([_,B2,_,_])) :- B1 #\= B2.
onedifrent(peice([_,_,C1,_]),peice([_,_,C2,_])) :- C1 #\= C2.
onedifrent(peice([_,_,_,D1]),peice([_,_,_,D2])) :- D1 #\= D2.
notequiv(peice(X),peice(Y)) :-
peice(X),
peice(Y),
rotate(peice(X),peice(X1)),
rotate(peice(X1),peice(X2)),
rotate(peice(X2),peice(X3)),
onedifrent(peice(X),peice(Y)),
onedifrent(peice(X1),peice(Y)),
onedifrent(peice(X2),peice(Y)),
onedifrent(peice(X3),peice(Y)).
notin(_,Ls) :- Ls = [].
notin(peice(X),[peice(Y)|Ls]) :-
notequiv(peice(X),peice(Y)),
notin(peice(X),Ls).
alldifrent(Ls) :- Ls = [].
alldifrent([peice(X)|Ls]) :-
notin(peice(X),Ls),
alldifrent(Ls).
From combinatorics, the longest list of all different peices should have a length 165. However, nothing stops prolog from creating impossible solutions and creating longer lists.