【发布时间】:2012-01-25 20:19:51
【问题描述】:
我必须编写一个小的序言程序来检查给定的人是否是第二个人的祖先。 这些是事实和规则:
mother(tim, anna).
mother(anna, fanny).
mother(daniel, fanny).
mother(celine, gertrude).
father(tim, bernd).
father(anna, ephraim).
father(daniel, ephraim).
father(celine, daniel).
parent(X,Y) :- mother(X,Y).
parent(X,Y) :- father(X,Y).
测试一个人是否是另一个人的祖先很容易:
ancestor(X, Y) :- parent(X, Y).
ancestor(X, Y) :- parent(X, Z), ancestor(Z, Y).
但现在我必须编写一个方法祖先(X,Y,Z),它也打印出两个人之间的关系。它应该是这样的
?- ancestor(ephraim, tim, X).
false.
?- ancestor(tim, ephraim, X).
X = father(mother(tim)).
这就是问题所在:我不知道该怎么做。
【问题讨论】:
标签: prolog