Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prolog Family Relation, unexpected failure

Could anyone tell me why my aunt relation isn't working? It just returns false whenever I try to call it.

The Uncle relation I wrote under it seems to work perfectly. I can't figure out what the difference is. I tried (not(mother(X,Y)). at the end also but that doesn't change anything.

/* FACTS */
parents(david, george, noreen).
parents(jennifer, george, noreen).
parents(georgejr, george, noreen).
parents(scott, george, noreen).
parents(joanne, george, noreen).
parents(jessica, david, edel).
parents(clara, david, edel).
parents(michael, david, edel).
parents(laura, georgejr, susan).
parents(anna, scott, siobhan).


/* Relationships */
father(X, Y) :- parents(Y, X, _).
male(X) :- father(X, _).

mother(X, Y) :- parents(Y, _, X).
female(X) :- mother(X, _).

grandfather(X, Y) :- father(X, Z), father(Z, Y).
grandfather(X, Y) :- father(X, Z), mother(Z, Y).

grandmother(X, Y) :- mother(X, Z), mother(Z, Y).
grandmother(X, Y) :- mother(X, Z), father(Z, Y).

brother(X, Y) :- male(X), father(Z, X), father(Z, Y).

sister(X, Y) :- female(X), father(Z, X), father(Z, Y).

aunt(X,Y) :- sister(X,Z), parents(Y, Z, _).
aunt(X,Y) :- sister(X,Z), parents(Y, _, Z).

uncle(X, Y) :- brother(X, Z), parents(Y, Z, _), not(father(X,Y)).
uncle(X, Y) :- brother(X, Z), parents(Y, _, Z), not(father(X,Y)).
like image 838
Danny Avatar asked Mar 23 '23 01:03

Danny


1 Answers

The short answer is that an uncle is working (sort of) and the aunt does not because your definition of male and female is deficient: it does not recognize people a male or a female unless they have kids. In your set of facts there is no female (judging by name) who would have kids and have a sibling who has kids. It is for the same reason that scott should not be showing up among the list of uncles.

Fixing this is simple: you could either

  1. drop the rules that infer gender and state the gender instead, or
  2. replace the parents facts with son/daughter facts + parents rule, and infer the gender from the fact that someone is a daughter of someone.
like image 133
Sergey Kalinichenko Avatar answered Mar 30 '23 01:03

Sergey Kalinichenko