1
我得到了以下问题的探析:
以下事实和谓词的定义:防止无限循环的Prolog
father(avr, yit).
male(avr).
married(avr, sara).
father(yit, yaak).
married(rivka, yit).
father(yaak, yosef).
mother(rachel, yosef).
father(yaak, levi).
mother(leaa, levi).
mother(zilpa, gad).
father(yaak, dan).
mother(bilhaa, dan).
father(yosef, menashe).
father(yosef, ephraim).
are_married(X,Y) :- married(X,Y).
are_married(X,Y) :- married(Y,X).
我定义了以下谓词:
married(X,Y) :- mother(X,Z) , father(Y,Z).
mother(X) :- are_married(X,Y) , father(Y,_).
目前,该问题的探析是母亲由婚姻定义,婚姻是由母亲定义的 - 结果是无限循环,程序崩溃。
我该如何防止无限循环?有没有办法告诉谓词不要使用不同的谓词?
不,只是使用不同的名称。这是最近问及回答,只是[浏览](http://stackoverflow.com/questions/tagged/prolog)通过一些最近的问题,并[这里](http://stackoverflow.com/tags/prolog/new )通过答案。 – 2013-05-02 09:05:17
[序列艺术中的左练习]的可能重复(http://stackoverflow.com/questions/16325238/left-of-exercise-from-the-art-of-prolog) – 2013-05-02 09:05:36