user2852171
user2852171

Reputation: 103

Prolog Family Tree Issues

I've been having a novice issue with setting up a family tree in Prolog. For some reason, I can't seem to get 'sibling' to return 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).

Thanks very much in advance, this issue has been driving me nuts!

Upvotes: 0

Views: 346

Answers (1)

CapelliC
CapelliC

Reputation: 60024

as an initial step, use an established relation (mother/2 will do, as well):

sibling(X, Y) :- father(F, X), father(F, Y), X @< Y.

yields

?- sibling(X,Y).
X = bartholomew,
Y = lisa ;
X = bartholomew,
Y = margaret ;
X = lisa,
Y = margaret ;
false.

Upvotes: 1

Related Questions