我在SWI-Prolog中编写了以下程序:
male(reza).
male(aliakbar).
male(behrooz).
male(said).
male(aliasghar).
male(taghi).
male(gholamreza).
male(hadi).
female(fatema).
female(tahere).
female(olya).
female(fatema).
mother(fateme,reza).
mother(olya,hasan).
mother(x,y) :-
wife(x,z),
father(z,y).
brother(said,reza).
brother(x,y) :-
father(z,x),
father(z,y),
x\==y,
male(x).
sister(tahere,fateme).
sister(x,y) :-
father(z,x),
father(z,y),
x\==y,
female(x).
sister(olya,aliakbar).
wife(tahere,gholamreza).
father(gholamreza,hadi).
father(gholamreza, nastaran).
father(abdollah,hasan).
father(aliakbar,reza).
father(taghi,olya).
father(taghi,aliakbar).
father(taghi,aliasghar).
father(aliakbar,said).
grandfather(x,z) :-
father(x,y),
father(y,z).
grandfather(x,z) :-
father(x,y),
mother(y,z).
uncle(y,x) :-
father(z,x),
brother(z,y),
male(y).
aunt(y,x) :-
mother(z,x),
sister(z,y),
female(y).
cousin(y,x) :-
aunt(z,x),
mother(z,y),
female(y).
cousin(y,x) :-
aunt(z,x),
mother(z,y),
male(y).
当我咨询“父亲(X,Y),父亲(Y,Z)。”它返回正确答案(名称以波斯语表示),即返回
X = taghi,
Y = aliakbar,
Z = reza ;
X = taghi,
Y = aliakbar,
Z = said ;
false.
但我找不到祖父(X,Y)的正确答案。请帮帮我。
感谢。
答案 0 :(得分:1)
小心:案件在Prolog中至关重要。您的规则无法正确解释,因为您没有对变量使用大写。