我在Prolog中设置家谱时遇到了新手问题。出于某种原因,我似乎无法让“兄弟姐妹”回归真实。
% male(+Person)
% Specifies the Person is a male.
%
male(abraham).
male(homer).
male(bartholomew).
% female(+Person)
% Specifies the Person is a female.
%
female(mona).
female(marjorie).
female(lisa).
female(margaret).
% mother(+Parent,+Child)
% Specifies Parent is a mother of Child.
%
mother(mona,homer).
mother(marjorie,bartholomew).
mother(marjorie,lisa).
mother(marjorie,margaret).
% father(+Parent,+Child)
% Specifies Parent is a father of Child.
%
father(abraham,homer).
father(homer,bartholomew).
father(homer,lisa).
father(homer,margaret).
% sibling(+Person1,+Person2)
% Specifies Person1 is a sibling of Person2
%
sibling(X,Y) :-
father(X,Z),
mother(Y,Z).
非常感谢,这个问题让我疯狂!
答案 0 :(得分:1)
作为初始步骤,使用已建立的关系(母亲/ 2也会这样做):
sibling(X, Y) :- father(F, X), father(F, Y), X @< Y.
产量
?- sibling(X,Y).
X = bartholomew,
Y = lisa ;
X = bartholomew,
Y = margaret ;
X = lisa,
Y = margaret ;
false.