1
votes

When using the sibling rule from my knowledge base the question ?- issibling(jo,X). returns ali which is correct but also returns jo (meaning jo is the sister of jo). Any help would be appreciated.

mother(ali,jess).
father(dom,dan).
mother(ali,dan).
father(dom,jess).
father(dom,tom).
mother(ali,tom).
father(dom,george).
mother(ali,george).
mother(jo,tracey).

father(eddie,ali).
mother(jenny,ali).
father(eddie,jo).
mother(jenny,jo).

mother(belinda,dom).
father(kieth,dom).
mother(belinda,ben).
father(kieth,ben).

male(dom).
male(tom).
male(dan).
male(george).
male(eddie).
male(kieth).
female(jess).
female(ali).
female(jo).
female(jenny).
female(belida).
male(ben).
female(tracey).

isparent(X,Y):-father(X,Y).
isparent(X,Y):-mother(X,Y).
ischild(Y,X):-isparent(X,Y).

isgrandparent(X,Z) :- isparent(X,Y), isparent(Y,Z).
issibling(X,Y) :- father(F,X),father(F,Y),mother(M,X),mother(M,Y).
issister(X,Y) :- issibling(X,Y), female(X).
isbrother(X,Y) :- issibling(X,Y), male(X).
isaunt(X,Z) :- issister(X,Y),isparent(Y,Z).
isuncle(X,Z) :- isbrother(X,Y),isparent(Y,Z).
isson(X,Y) :- male(X),isparent(Y,X).
isdaughter(X,Y) :- female(X),isparent(Y,X).
iscousin(X,Y) :- isaunt(Z,Y),isparent(Z,X).
isnephew(X,Z) :-ischild(X,Y),issibling(Z,Y).
1

1 Answers

1
votes

You could consider more readable code: instead of issibling(X,Y), maybe siblings(S1,S2).

It's of help to 'break' symmetrical relations, and to use more abstract relations as possible: I would try (untested example)

siblings(S1, S1) :- parent_of(P, S1), parent_of(P, S2), dif(S1, S2).

Instead of dif/2, (@<)/2 could be used as well.