1
在程序中出現了一個奇怪的問題,就像使用了叔叔,阿姨和表親這樣的一些子句時,他們給出的顯然不是邏輯上相同的答案,例如, uncle(david, Y).
應該給所有的人大衛是一個叔叔,而是給所有的孩子上市,然後循環他們兩次。Unwated使用簡單的家譜樹循環Prolog程序
如果任何人都可以幫助我,這將是偉大的,我只是開始瞭解一些語言的來龍去脈,並已陷入這種mu調試。
parents(jennifer, george, noreen).
parents(david, george, noreen).
parents(georgejr, george, noreen).
parents(scott, george, noreen).
parents(joanne, george, noreen).
parents(jessica, david, edel).
parents(clara, david, edel).
parents(michael, david, edel).
parents(laura, georgejr, susan).
parents(anna, scott, siobhan).
father(X, Y) :- parents(Y, X, _).
male(X) :- father(X, _).
mother(X, Y) :- parents(Y, _, X).
female(X) :- mother(X, _).
grandfather(X, Y) :- father(X, Z), father(Z, Y).
grandfather(X, Y) :- father(X, Z), mother(Z, Y).
grandmother(X, Y) :- mother(X, Z), mother(Z, Y).
grandmother(X, Y) :- mother(X, Z), father(Z, Y).
brother(X, Y) :- male(X), father(Z, X), father(Z, Y).
sister(X, Y) :- female(X), father(Z, X), father(Z, Y).
uncle(X, Y) :- brother(X, Z), father(Z, Y).
aunt(X, Y) :- sister(X, Z), father(Z, Y).
cousin(X, Y) :- father(M, X), father(N, Y), brother(M, N).
謝謝你,我完全沒有注意到這微小的錯誤。 –