Prolog 家谱 [英] Prolog Family tree
本文介绍了Prolog 家谱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我做到了,但当我询问兄弟、姐妹、叔叔、阿姨时,它没有显示答案
I did it but its not showing answers When i ask about the brothers,sisters,uncles,aunts
这是我写的,有什么问题吗?
This is what I wrote, what's wrong ?
/*uncle(X, Y) :– male(X), sibling(X, Z), parent(Z, Y).*/
/*uncle(X, Y) :– male(X), spouse(X, W), sibling(W, Z), parent(Z, Y).*/
uncle(X,Y) :-
parent(Z,Y), brother(X,Z).
aunt(X,Y) :-
parent(Z,Y), sister(X,Z).
sibling(X, Y) :-
parent(Z, X),
parent(Z, Y),
X \= Y.
sister(X, Y) :-
sibling(X, Y),
female(X).
brother(X, Y) :-
sibling(X, Y),
male(X).
parent(Z,Y) :- father(Z,Y).
parent(Z,Y) :- mother(Z,Y).
grandparent(C,D) :- parent(C,E), parent(E,D).
aunt(X, Y) :– female(X), sibling(X, Z), parent(Z, Y).
aunt(X, Y) :– female(X), spouse(X, W), sibling(W, Z), parent(Z, Y).
male(john).
male(bob).
male(bill).
male(ron).
male(jeff).
female(mary).
female(sue).
female(nancy).
mother(mary, sue).
mother(mary, bill).
mother(sue, nancy).
mother(sue, jeff).
mother(jane, ron).
father(john, sue).
father(john, bill).
father(bob, nancy).
father(bob, jeff).
father(bill, ron).
sibling(bob,bill).
sibling(sue,bill).
sibling(nancy,jeff).
sibling(nancy,ron).
sibling(jell,ron).
还有一件事,我如何优化兄弟的规则,使 X 不是自己的兄弟.
And one more thing, how do I optimize the rule of the brother so that X is not brother to itself.
推荐答案
如果您试图复制图表,那么您的某些公理似乎是错误的或缺失的.
It looks like some of your axioms are wrong or missing, if you are trying to replicate the diagram.
缺失:
female(jane).
father(john, bob).
错误:
father(john, sue).
这可能会导致兄弟规则发生冲突.但是我对 prolog 了解多少
This might cause the sibling rule to conflict. But what do I know about prolog
这篇关于Prolog 家谱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文