-1

比如我有这个祖先,我怎么能说谁是混蛋儿子或女儿?

ancestor(frank,mary).
ancestor(frank,andrew).
ancestor(frank,jake).
ancestor(joanne,mary).
ancestor(joanne,andrew).

married(frank,joanne).

法律(我没有发布更多代码,因为它不相关)

mother(X,Y) :- ancester(X,Y),gender(X,female).
father(X,Y) :- ancester(X,Y),gender(X,male).

son(X,Y) :- father(Y,X).

sister(X,Y) :- ancester(Z,X),ancester(Z,Y),X\==Y,gender(Y,female).
brother(X,Y) :- ancester(Z,Y),ancester(Z,X), X\==Y,gender(Y,male).

grandfahter(X,Y) :- ancester(X,Z),ancester(Z,Y),gender(X,male).
grandmother(X,Y) :- ancester(X,Z),ancester(Z,Y),gender(X,female).
4

1 回答 1

0

只是根据评论总结这个问题的答案。

假设这个人是一个混蛋,如果他们的父母没有结婚,可以写

bastard(X) :- father(F, X), mother(M, X), \+ married(F, M).

如果您的 Prolog 方言不支持\+(尽管它在 ISO 标准中),您应该使用not

bastard(X) :- father(F, X), mother(M, X), not(married(F, M)).

于 2017-03-09T20:14:31.793 回答