一个(非常)奇怪的故事:我和一个寡妇结婚了,她有一个女儿。我父亲(F)和我的继女(D)结婚了。我妻子生了一个儿子(S1)。我父亲(继女)的妻子也有一个儿子(s2)。
这个项目的目标是输入:
grandfather(i,i).并在prolog中返回yes。
这是我到目前为止所知道的:
%facts
father(f,i).
husband(i,w).
husband(f,d).
mother(w,d).
mother(w,s1).
father(i,s1).
mother(d,s2).
father(f,s2).
%rules
father(X,Y) :- f_in_law(X,Y).
father(X,Y) :- husband(X,Z),mother(Z,Y).
f_in_law(X,Y) :- husband(Z,Y),father(X,Z).
b_in_law(X,Y) :- husband(Z,Y),brother(X,Z).
%brother(X,Y) :- b_in_law(X,Y).
uncle(X,Y) :- father(Z,Y),brother(X,Z).
grandfather(X,Y) :- father(Z,Y),father(X,Z).我查了一遍,看看哪里出了问题。father(f,i)是真的,所以这很好!但是father(i,f)被认为是错误的。关于如何纠正这个问题,有什么建议/想法吗?我非常感谢大家的意见,因为我对prolog还很陌生。
发布于 2013-02-25 17:24:10
谓词应该是
f_in_law(X,Y) :- husband(Y,Z),father(X,Z).而不是
f_in_law(X,Y) :- husband(Z,Y),father(X,Z).发布于 2013-02-25 19:02:39
我重新定义了这个谜语
father(i, s1).
father(f, i).
father(f, s2).
fatlaw(X, Y) :- husband(X, Z), mother(Z, Y).
mother(w, d).
mother(w, s1).
mother(d, s2).
motlaw(X, Y) :- husband(Z, X), father(Z, Y).
husband(i, w).
husband(f, d).
grandfather(X, Y) :-
( father(X, Z) ; fatlaw(X, Z) )
, ( father(Z, Y) ; fatlaw(Z, Y) ; mother(Z, Y) ; motlaw(Z, Y) )
.重点似乎是,祖父必须接受假的亲生后代(我希望这是合理的英语)。
这样就可以了
?- grandfather(X,X).
X = i ;
false.https://stackoverflow.com/questions/15063544
复制相似问题