0
votes

When I try to see who is brother to who and same for sister it gives me the sons and daughter, I cannot find the mistake...

    father(pedro-i,fernando-i).
    father(pedro-i,beatriz(1347)).
    father(pedro-i,joão(1349)).
    father(pedro-i,dinis(1354)).
    father(pedro-i,joão_grão_mestre_da_ordem_de_avis).
    mother(constança(1320),luis).
    mother(constança(1320),maria(1342)).
    mother(constança(1320),fernando-i).
    mother(inês_de_castro,beatriz(1347)).

Any other opinion I appreciate that

    ancestor(X,Y) :- mother(X,Y).
    ancestor(X,Y) :- father(X,Y).

    if_then_else(X,Y,male) :- father(X,Y).
    if_then_else(X,Y,female) :- mother(X,Y).

    son(X,Y) :- father(X,Y).
    sister(X,Y) :- ancestor(Z,Y),X\==Y,if_then_else(X,Y,female).
    brother(X,Y) :- ancestor(Z,Y),X\==Y,if_then_else(X,Y,male).
    descendent (X,Y) :- filho(X,Y). 
    descendent (X,Y) :- filho(X,Z),descendent (Z,Y).
    grandfather(X,Y) :- ancestor(X,Z),ancestor(Z,Y).
    grandmother(X,Y) :- ancestor(X,Z),ancestor(Z,Y).
    grandchildren(X,Y) :- ancestor(Z,X),ancestor(Y,Z).

    uncle(X,Y) :- brother(X,Z),ancestor(Z,Y).
1
What query do you enter? What results do you get? What results do you expect?lurker
for example if I enter this query: 'brother(X,fernando-i).' I get: 'X=pedro-i' and I want to get: ' X=joão(1349). X=dinis(1354). X=joão_grão_mestre_da_ordem_de_avis) ' only those who are male, if I ask sister only the females @lurkerAfonso Pinto
s/pedro-i/pedro_i/gfalse
@false Did not understand what you were trying to say.Afonso Pinto
Don't use - directly in names as in pedro-i, instead, use _. And if you really insist on it, put the entire name in quotes like 'pedro-i'false

1 Answers

1
votes

Your clause brother(X,Y) :- ancestor(Z,Y),X\==Y,if_then_else(X,Y,male). requires Y to have an ancestor, but X also needs to have an ancestor -- the same ancestor:

brother(X,Y) :- ancestor(Z,Y),ancestor(Z,X), X\==Y,if_then_else(X,Y,male).

You also need to eliminate the requirement at the end that X be the father of Y.

brother(X,Y) :- ancestor(Z,Y),ancestor(Z,X), X\==Y,male(X).

male needs to depend simply on the individual (you don't need to be a father to be a male.) male (fernando-i)., etc.