2012-03-21 71 views
1

我在swi-prolog中有一个非常简单的程序,它定义了所有关于家庭关系的谓词。我还定义了一些事实(基于圣经的亚伯拉罕的家庭)。所以,现在swi-prolog谓词不起作用

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

,当我在节目类型

?- mother_in_law(sarah,X). 

它应该给我: 所以我定义了一个谓语 “mother_in_law” 是这样的:

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

和一些事实只有X = rebekah。但是它给了我一些其他的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

的问题,您的解决方案由于以下事实

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)是一样的已婚(B,A)

+0

感谢。其实我做了你说的话,它仍然给出了一些其他的垃圾,像雅各是莎拉的女婿(?!?!)...所以我仍然不知道问题是什么。 – 2012-03-21 17:19:10

+0

你可以发布其他事实吗?那么我也可以尝试一下 – 2012-03-21 17:22:38