2012-03-21 12 views
1

私はswi-prologで非常に簡単なプログラムを持っています。これは家族関係のすべての述語を定義しています。私はまた、いくつかの事実(聖書のアブラハムの家族に基づいて)を定義しました。 だから私はこのように述語 "mother_in_law" を定義した:私はプログラムswi-prolog述語が機能しない

?- mother_in_law(sarah,X). 

に入力するとだから今、それは私を与える必要があり

female(sarah). 
mother(sarah,isaac). 
married(rebekah,isaac). 

mother_in_law(X,Y):- female(X),mother(X,Z),married(Z,Y). 

といくつかの事実X =レベッカのみ。しかし、それは私が定義した条件には立たないXのためのいくつかの他の値を与えてくれます。

誰かが私に間違っていることを教えてもらえますか?たくさん

おかげで私は、全体のテキスト部分を追加します。

father(X,Y). % Define Predicates% 
mother(X,Y). 
married(X,Y). 
male(X). 
female(X). 
parent(X,Y). 
diff(X,Y). 
male_cousin(X,Y). 
brother_in_law(X,Y). 
mother_in_law(X,Y). 
cousin_three(X,Y). 
cousin(X,Y). 
sib(X,Y). 

%Define Facts% 
male(terah). male(abram). male(nahor). male(haran). male(isaac). 
male(lot). male(moab). male(ben_ami). male(bethuel). male(laban). 
male(esau). male(jacob). male(reuben). 
female(sarah). female(milcah). female(lot_daughter_1). female(lot_daughter_2). 
female(rebekah). female(leah). female(dinah). 
father(terah,abram). father(terah,nahor). father(terah,haran). 
father(abram,isaac). father(haran,lot). father(nahor,bethuel). 
father(bethuel,laban). father(laban,leah). father(isaac,jacob). 
father(isaac,esau). 
father(jacob,reuben). 
mother(sarah,isaac). mother(milcah, bethuel). mother(rebekah,jacob). 
mother(rebekah,esau). mother(leah,reuben). 
mother(lot_daughter_1,moab). mother(lot_daughter_2,ben_ami). 
married(abram,sarah). married(nahor,milcah). 
married(isaac,rebekah). married(jacob,leah). 
married(sarah,abram). married(milcah,nahor). 
married(rebekah,isaac). married(leah,jacob). 



%Define complicated predicates% 
    parent(X,Y) :- father(X,Y). 
    parent(X,Y) :- mother(X,Y). 
    diff(X,Y) :- not(X=Y). 
    sib(X,Y):- parent(Z,X), parent(Z,Y), diff(X,Y). %define sibling % 
    mother_in_law(X,Y):- female(X),mother(X,Z),married(Z,Y). %question 1% 
    male_cousin(X,Y):- male(X),father(W,X),parent(Z,Y),sib(W,Z). %question 2% 
    cousin(X,Y):- parent(Z,X), parent(W,Y), sib(W,Z).  %question 3% 
    cousin_three(X,Y):- parent(Z,X),parent(G,Z),parent(H,Y),parent(K,H),cousin(G,K). 
    brother_in_law(X,Y):- male(X),married(X,Z),sib(Y,Z). %question 5-X is married to Y's sibling% 
    brother_in_law(X,Y):- male(X),sib(X,Z),married(Y,Z). %X's sibling is married to Y% 
    brother_in_law(X,Y):- male(X),married(X,W),married(Y,Z),sib(W,Z). % Y is married to the sibling of X's spouse% 

答えて

0

結婚(B、A)と同じであるという事実の世話を持っているかもしれないより良い方法次の事実のために:

mother_in_law(X,Y). 

誰かが誰の法律上の母親であると述べている。

ドロップ

father(X,Y). % Define Predicates% 
mother(X,Y). 
married(X,Y). 
male(X). 
female(X). 
parent(X,Y). 
diff(X,Y). 
male_cousin(X,Y). 
brother_in_law(X,Y). 
mother_in_law(X,Y). 
cousin_three(X,Y). 
cousin(X,Y). 
sib(X,Y). 
0

はあなたの事実に次の行を追加します。それはその後動作します。

married(isaac,rebekah). 

結婚関係自体があなたのソリューションに問題がある結婚(A、B)は

+0

感謝。実際に私はあなたの言うことをやったが、それでもまだサラの義理の息子(?!?!)のジェイコブのようなものがある。 –

+0

残りのファクトも同様に投稿できますか?それから私もそれを試すことができます –

関連する問題