兄弟姐妹关系Prolog

时间:2016-12-20 21:37:13

标签: prolog

我是Prolog的新手,所以我完全没有意识到我得到的错误。我制作的代码描述了任何两个家庭成员之间的关系。 即两个人结婚,姐妹,兄弟,姐妹和兄弟等等。

wife(hussein,amina).
mother(amina,amira).
mother(amina,amany).
mother(amina,amna).
mother(amina,hassan).
mother(amina,hossam).

father(hussein,amira).
father(hussein,amany).
father(hussein,amna).
father(hussein,hassan).
father(hussein,hossam).

parent(X,Y):-
   mother(X,Y) ; father(X,Y).

married(X,Y) :- wife(X,Y).

sibling(X,Y) :-
   mother(Out1,X),
   father(Out2,X),
   mother(Out3,Y),
   father(Out4,Y),
   Out1 is Out3,Out2 is Out4.

该代码适用于父母,已婚规则,但我无法理解为什么兄弟姐妹不能工作。我得到他们的母亲的X和Y变量,并确保他们是相同的,他们的父亲,并确保他们相同,以确认他们的兄弟姐妹。但我得到这个错误:

ERROR: is/2: Arithmetic: `amina/0' is not a function

1 个答案:

答案 0 :(得分:1)

is/2适用于arithmetc;你可以写点像

X is 3 + Y

所以X统一为3加上Y的算术值。

但是,在您的情况下,您使用的字词(husseinaminaamira等)不是数字,因此您无法使用{{1为了统一他们。

您可以在is中使用sibling/2Out1Out3使用相等(Out2运算符)“统一”Out4

=

或更好(恕我直言)使用相同的变量(使用sibling(X,Y) :- mother(Out1,X), father(Out2,X), mother(Out3,Y), father(Out4,Y), Out1 = Out3, Out2 = Out4. 代替Out1Out3代替Out2

Out4