Prolog Family tree
Posted
by Tania
on Stack Overflow
See other posts from Stack Overflow
or by Tania
Published on 2009-03-24T23:51:48Z
Indexed on
2010/05/03
7:58 UTC
Read the original article
Hit count: 922
Hi I have a Question in prolog ,
I did it but its not showing answers When i ask about the brothers,sisters,uncles,aunts
This is what I wrote, what's wrong ?
/*uncle(X, Y) :– male(X), sibling(X, Z), parent(Z, Y).*/
/*uncle(X, Y) :– male(X), spouse(X, W), sibling(W, Z), parent(Z, Y).*/
uncle(X,Y) :-
parent(Z,Y), brother(X,Z).
aunt(X,Y) :-
parent(Z,Y), sister(X,Z).
sibling(X, Y) :-
parent(Z, X),
parent(Z, Y),
X \= Y.
sister(X, Y) :-
sibling(X, Y),
female(X).
brother(X, Y) :-
sibling(X, Y),
male(X).
parent(Z,Y) :- father(Z,Y).
parent(Z,Y) :- mother(Z,Y).
grandparent(C,D) :- parent(C,E), parent(E,D).
aunt(X, Y) :– female(X), sibling(X, Z), parent(Z, Y).
aunt(X, Y) :– female(X), spouse(X, W), sibling(W, Z), parent(Z, Y).
male(john).
male(bob).
male(bill).
male(ron).
male(jeff).
female(mary).
female(sue).
female(nancy).
mother(mary, sue).
mother(mary, bill).
mother(sue, nancy).
mother(sue, jeff).
mother(jane, ron).
father(john, sue).
father(john, bill).
father(bob, nancy).
father(bob, jeff).
father(bill, ron).
sibling(bob,bill).
sibling(sue,bill).
sibling(nancy,jeff).
sibling(nancy,ron).
sibling(jell,ron).
And one more thing, how do I optimize the rule of the brother so that X is not brother to itself.
© Stack Overflow or respective owner