0

在 Prolog 中设置家谱时,我遇到了一个新手问题。出于某种原因,我似乎无法让“兄弟”返回 true。

% 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).

提前非常感谢,这个问题一直让我发疯!

4

1 回答 1

1

作为第一步,使用已建立的关系(mother/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.
于 2013-11-03T19:34:22.070 回答