我不知道为什么我的丈夫功能给了我一个假,逻辑应该是正确的。当我移除男性(X)和女性(Y)时,它给出了正确的答案。其他一切都返回了正确的答案。我对这种语言很新。这是代码:
male(bob).
male(brody).
male(aaron).
male(daniel).
male(adam).
male(james).
male(jerry).
female(judy).
female(melinda).
female(erin).
female(lena).
female(cristin).
father(bob,lena).
father(bob,jeff).
father(james,adam).
father(jerry,cristin).
father(adam,brody).
father(adam,aaron).
father(jeff,daniel).
mother(judy,lena).
mother(judy,jeff).
mother(erin,adam).
mother(melinda,cristin).
mother(lena,brody).
mother(lena,aaron).
mother(cristin,daniel).
parent(X, Y) :- father(X, Y); mother(X, Y).
children(X,Y):-parent(Y,X).
grandfather(X, Y) :- father(X, Z), parent(Z, Y).
grandmother(X, Y) :- mother(X, Z), parent(Z, Y).
sibling(X,Y):-
parent(Z,X),
parent(Z,Y),
X\=Y.
sister(X,Y):-
sibling(X,Y),
female(X).
brother(X,Y):-
sibling(X,Y),
male(X).
husband(X,Y):-
male(X),
female(Y),
children(M,X),
children(M,Y).