Family Tree Exercise

8

I have to create a relationship of uncle according to the genealogy tree below:

I already have the following code:

mãe(ana, eva).
mãe(eva, noé).
mãe(bia, raí).
mãe(bia, clô).
mãe(bia, ary).
mãe(lia, gal).
pai(ivo, eva).
pai(raí, noé).
pai(gil, raí).
pai(gil, clô).
pai(gil, ary).
pai(ary, gal).
mulher(ana).
mulher(eva).
mulher(bia).
mulher(clô).
mulher(lia).
mulher(gal).
homem(ivo).
homem(raí).
homem(noé).
homem(gil).
homem(ary).
gerou(ana, eva).
gerou(ivo, eva).
gerou(eva, noé).
gerou(raí, noé).
gerou(bia, raí).
gerou(bia, clô).
gerou(bia, ary).
gerou(gil, raí).
gerou(gil, clô).
gerou(gil, ary).
gerou(ary, gal).
gerou(lia, gal).
avô(X, Y) :- pai(X, Z), pai(Z, Y); pai(X, Z), mãe(Z, Y).
avó(X, Y) :- mãe(X, Z), mãe(Z, Y); mãe(X, Z), pai(Z, Y).


filho(X, Y) :- gerou(Y, X), homem(X).
filha(X, Y) :- gerou(Y, X), mulher(X).

/* irmãos(raí, clô).
irmãos(clô, raí).
irmãos(ary, clô).
irmãos(ary, raí).
irmãos(clô, ary).
irmãos(raí, ary). */ 

In the exercise I'm doing, I do not ask to create the sibling relationship, but can I use it to create the Uncle relationship? If not, which relationships should I use? Thank you and sorry if I did not express myself correctly.

    
asked by anonymous 14.08.2014 / 14:06

2 answers

7

If two people have the same mother, they are brothers. The easiest way would be to create the brother and sister relationship:

irmao(X,Y) :- gerou(Z,X), gerou(Z,Y), homem(X)
irma(X,Y) :- gerou(Z,X), gerou(Z,Y), mulher(X)

Finally, the relation uncle would be:

tio(X,Y) :- irmao(X,Z), pai(Z,Y); irma(Z, X), mae(Z, Y)

Now if creating the brother and sister relationship is not allowed, it is possible to resolve with the rule below:

tio(X,Y) :- homem(X), gerou(M, X), gerou(M, I), pai(I,Y); 
            homem(X), gerou(M, X), gerou(M, I), mae(I,Y)
    
14.08.2014 / 14:29
1

For simplicity, I will ignore the issues of male / female.

You should avoid:

  • all be brothers of yourselves
  • parents are your children's uncles

For this I have added a condition X ≠ Y in this case coded as X \== Y

irmao(X,Y) :- gerou(PAI,X), gerou(PAI,Y), X \== Y.    
tio(T,Y)   :- gerou(AVO, T), gerou(AVO, PAI), gerou(PAI,Y), T \== PAI. 

Similarly we can remove many redundant elementary facts from putting together two more rules:

mulher(A):-  mae(A,_).
homem(A) :- pai(A,_).
    
02.03.2015 / 18:04