1
votes

I'm just starting to learn PROLOG and I was given the task of creating both a aunt/uncle relationship in a family tree. The aunt can be created using a sister relationship, however, the uncle relationship must be created without it.

The current predicates are: male, female, parent & the rules created so far are: father, mother, grandfather, grandmother, sister

Here's what I have so far:

sister(Sister,Individual):- 
female(Sister),
parent(X,Sister),
parent(X,Individual), 
Sister \= Individual.

aunt(Aunt, Individual):- sister(Aunt, X), parent(X, Individual).

How would I go about creating the uncle relationship without the use of brother? I understand that the parent(parent(Individual)) == parent(uncle) but how would I go about stating that given my current relations?

Thanks in advance for your help!

1

1 Answers

2
votes

I wouldn't consider myself the best with Prolog, but I believe this will work. Please comment on anything that may be incorrect and I'll fix it!

We know the following:

  • The uncle of the individual must be male.
  • The uncle would share a parent with the individual's parent.

Therefore, we can define the rule as follows:

uncle(Uncle, Individual) :- 
    male(Uncle),            % The uncle must be male.
    parent(X, Individual),  % Assume there's some parent of the individual, X.
    parent(Y, Uncle),       % Assume there's some parent of the uncle, Y.
    parent(Y, X).           % Y must be the parent of X.