【发布时间】:2016-04-17 20:50:23
【问题描述】:
我正在尝试使用最多允许 3 个事实的简单家谱与 Prolog 一起使用,但是我似乎无法将我的妹妹定义为我父母的孩子。这是我写的:
father(dad,me).
mother(mom,me).
siblings(me,sis).
parents(X,Z):-father(X,Z).
parents(Y,Z):-mother(Y,Z).
child(Z,X):-siblings(Z,Z2),parents(X,Z).
child(Z,Y):-siblings(Z,Z2),parents(Y,Z).
child(Z2,X):-siblings(Z,Z2),parents(X,Z).
child(Z2,Y):-siblings(Z,Z2),parents(Y,Z).
son(Z,X):-siblings(Z,Z2),parents(X,Z).
daughter(Z2,X):-siblings(Z,Z2),parents(X,Z).
brother(Z,Z2):-siblings(Z,Z2).
sister(Z2,Z):-siblings(Z,Z2).
当我在 Prolog 中输入father(ZFather,ZChild) 时,它只显示me 作为孩子而不是我的sis。我知道我没有在事实中定义它,但我尝试在规则中使用child(Z2,X) 和child(Z2,Y) 来定义它,这意味着Z2 是我的sis。
我们将不胜感激。
【问题讨论】:
标签: prolog logic family-tree