x と y に共通の祖先があるが同一人物ではない場合、x が y に関連するように、述語 related(X,Y) を追加します。
私の宿題では、述語を .PL に追加する必要があります。2 人が関連しているかどうかを証明する必要があります。私はそれを解決したので、彼らが兄弟姉妹であるかどうかは関係があると言うでしょうが、いとこのコードなどを理解することはできません. どんな助けでも大歓迎です。
% File FAMILY.PL% Part of a family tree expressed in Prolog
% In father/2, mother/2, and parent/2,
% first arg. is parent and second arg. is child.
father(michael,cathy).
father(michael,sharon).
father(charles_gordon,michael).
father(charles_gordon,julie).
father(charles,charles_gordon).
father(jim,melody).
father(jim,crystal).
father(elmo,jim).
father(greg,stephanie).
father(greg,danielle).
mother(melody,cathy).
mother(melody,sharon).
mother(hazel,michael).
mother(hazel,julie).
mother(eleanor,melody).
mother(eleanor,crystal).
mother(crystal,stephanie).
mother(crystal,danielle).
parent(X,Y) :- father(X,Y).
parent(X,Y) :- mother(X,Y).
sibling(X,Y) :- mother(M,X), mother(M,Y), \+ X == Y.
ancestor(X,Y) :- parent(X,Z), ancestor(Z,Y).
related(X,Y) :- sibling(X,Y), \+ X == Y.
このようなものを追加しようとしましたが、うまくいきませんでした。関連(X、Y):-祖先(Z、X)、祖先(Z、Y)。
だから私は追加しました
related(X,Y) :- parent(Z,X),parent(P,Y),parent(Q,Z),parent(Q,P), \+ X == Y.
それは私のすべてのテストで機能しています。それは何か問題がありますか?またはそれを書くためのより良い方法は?