TL DR: sibling(a,X)
fails with a response X = a
, but sibling(a,a)
fails.
I have the following Prolog file:
children(a, c).
children(a, d).
children(b, c).
children(b, d).
sibling(X, Y) :-
X \== Y, A \== B,
children(X, A), children(X, B),
children(Y, A), children(Y, B).
It seems clear enough to me that two people are brothers and sisters if their parents are the same. In addition, a person is not their sibling.
But when I tried to run some queries in GNU Prolog, I get some strange results:
| ?- sibling(a, b).
true ? a
true
true
yes
This is the intended behavior. a
and b
are brothers and sisters. There are three results that are a bit strange, but I assume that Prolog has a binding A = c, B = d
and A = d, B = c
.
| ?- sibling(a, a).
no
I think what it means a
, and a
not brothers and sisters.
| ?- sibling(a, X).
X = a ? a
X = b
X = a
X = b
X = a
X = b
X = a
X = b
(15 ms) yes
: X = a
, , sibling(a,a)
, sibling(a,a)
!
, , \==
Prolog.
?