Search code examples
prolog

family tree in SWI PROLOG


there is some error with the grandma , cousin, brother, uncle rules i tried so many rules but still could not find the correct one it returns false , please helpppppppppp

/*rules*/
male(james).
male(charles).
male(william).
female(megan).
male(george).
female(catherine).
female(diana).
female(elizabith).
parent(james, charles).
parent(james, elizabeth).
parent(charles, catherine).
parent(charles, william).
parent(charles, megan).
parent(elizabeth, diana).
parent(diana, george).

/*rules*/
father(X, Y) :-  parent(X,Y), male(X).
mother(X, Y) :- parent(X,Y), female(X).
child(Y, X) :- parent(X, Y).
grandparent(X, Y) :- parent(X, Z), parent(Z, Y).
grandpa(X, Y) :- grandparent(X, Y), male(X).
grandma(X, Y) :- grandparent(X, Y), female(X).
brother(X, Y) :- male(X), parent(X, Z), parent(Y, Z), X \= Y.

uncle(X, Y) :- brother(X, Z), parent(Y, Z).
grandchild(X, Y) :- grandparent(Y, X).
        grandson(X, Y) :- grandchild(X, Y), male(X).
        granddaughter(X, Y) :- grandchild(X, Y), female(X).
siblings(B,G) :- parent(P,B), parent(P,G), B\=G.
cousins(X,Y) :- parent(A,X), parent(B,Y), siblings(A,B), X\=Y.

Solution

  • Found: female(elizabith). elizabeth is wrongly spelled !

    With this correction, your code should work as normal. Did I reply to your quest for help ?