You could try what lurker wrote : using X @< Y
instead of not(X = Y)
, but then you'll get :
?- sibling(X,Y).
X = daughter ,
Y = son;
X = daughter ,
Y = son;
And then sibling(son,daughter).
will return no
whereas it should return true
.
Or you can just hit enter after getting the first result and you will not be prompted the other results (but this depends on which environment you use as some do prompt every result without asking if you want them or not).
Edit:
What you can do to limit the results is the following :
sibling(X,Y):-
parent(Z,X),
parent(Z,Y),
parent(A,X),
parent(A,Y),
not(X=Y),
Z @< A.
Let me explain : in your current implementation you get 4 results because
- son & daughter have the same mom
- daughter & son have the same mom
- son & daughter have the same dad
- daughter & son have the same dad
With the previous implementation, for sibling(X,Y) to be true, X and Y need to have the same two parents, so you'll only get :
- son & daughter have the same two parents
- daughter & son have the same two parents
And this is to my knowledge the minimum two results you can have if you want both sibling(son,daughter)
& sibling(daughter,son)
to be true.