Family tree exercise

I have to create an uncle relationship according to the following family tree: Family Tree

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, it doesn't ask to create the siblings relationship, but can I use it to create the uncle relationship? Otherwise, what relationships should I use? Thank you and forgiveness in case I did not express myself correctly.

 8
Author: Wellington Viana, 2014-08-14

2 answers

If two people have the same mother, then 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 relationship 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 solve 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)
 7
Author: Edgar Muniz Berlinck, 2014-08-14 13:31:48

For simplicity, I will ignore the male / female questions.

Should be avoided:

  • all be brothers of themselves
  • parents are uncles of their children

For this I added a condition X ≠ Y in this case encoded 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 joining two more Rules:

mulher(A):-  mae(A,_).
homem(A) :- pai(A,_).
 1
Author: JJoao, 2015-03-02 17:53:02