0

当我试图看看谁是谁的兄弟和姐妹时,它给了我儿子和女儿,我找不到错误......

    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)).

我欣赏的任何其他意见

    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).
4

1 回答 1

1

您的子句brother(X,Y) :- ancestor(Z,Y),X\==Y,if_then_else(X,Y,male).要求 Y 有一个祖先,但 X 也需要有一个祖先——同一个祖先:

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

您还需要消除最后 X 是 Y 的父亲的要求。

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

male需要简单地取决于个人(你不需要成为父亲才能成为男性。) male (fernando-i).等。

于 2017-03-06T16:48:08.190 回答