2

我在 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)的正确答案。请帮我解释为什么。

谢谢。

4

1 回答 1

1

注意:大小写在 Prolog 中至关重要。你的规则不能被正确解释,因为你没有使用大写的变量。

于 2012-11-03T08:55:31.243 回答