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 に答える