在一阶逻辑中表达爱因斯坦拼图作为一组封闭公式

时间:2013-03-15 04:25:01

标签: prolog first-order-logic zebra-puzzle

我以这种形式获得了经典的爱因斯坦/斑马拼图:

让我们假设在同一条道路上有五个不同颜色的房子彼此相邻。在每个房子里住着一个不同国籍的人。每个人都有他最喜欢的饮料,他最喜欢的香烟品牌,并饲养特定类型的宠物。

The Englishman lives in the red house. 
The Swede keeps dogs. 
The Dane drinks tea. 
The green house is just to the left of the white one. 
The owner of the green house drinks coffee. 
The Pall Mall smoker keeps birds. 
The owner of the yellow house smokes Dunhills. 
The man in the center house drinks milk. 
The Norwegian lives in the first house. 
The Blend smoker has a neighbor who keeps cats. 
The man who smokes Blue Masters drinks bier. 
The man who keeps horses lives next to the Dunhill smoker. 
The German smokes Prince. 
The Norwegian lives next to the blue house. 
The Blend smoker has a neighbor who drinks water. 
The question to be answered is: Who keeps fish?

任务是将这些陈述表达为一阶逻辑中的一组封闭式,每个陈述一个,假设拼图中的五个人由英国人,瑞典人,丹麦人,挪威人,德国人代表保持(X,Y)表示人X保持宠物Y.然后这些将转换为prolog。

我的问题是,我是否要以正确的方式转换语句。现在,我有类似的东西:

color(X, red) → lives(englishman, X)
keep(swede, dog)
drinks(dane, tea)
color(X, red) ∧ color(Y, green) → leftof(X, Y)
color(X, green) ∧ lives(Y, X) → drinks(Y, coffee)
smokes(X, pallmall) → keep(X, birds)
color(X, yellow) ∧ lives(Y, X) → smokes(Y, dunhills)

这是正确的,还是应该更像我尝试过的另一种方式:

house(X) ∧ color(X, red) → lives(englishman, X)
dog(X) → keep(swede, X)
tea(X) → drinks(dane, X)
house(X) ∧ house(Y) ∧ color(X, green) ∧ color(Y, white) → leftof(X, Y)
house(X) ∧ color(X, green) ∧ lives(Y, X) ∧ coffee(Z) → drinks(Y, Z)
pallmalls(X) ∧ smokes(Y, X) ∧ birds(Z) → keep(Y, Z)
house(X) ∧ color(X, yellow) ∧ lives(Y, X) ∧ dunhills(Z) → smokes(Y, Z)

我也尝试过类似的事情:

lives(englishman, redhouse)
keep(swede, dogs)
drinks(dane, tea)
leftof(greenhouse, whitehouse)
lives(X, greenhouse) → drinks(X, coffee)
smokes(X, pallmall) → keep(X, birds)
lives(X, yellowhouse) → smokes(X, dunhills)

我认为第一个是最正确的,但我不确定。我也不确定如何在一阶逻辑中表示像中心或邻居这样的东西。这些都接近正确吗?

编辑:我想出了一个我认为可能正确的解决方案。我注意到它说的是CLOSED公式,所以我这样做了:

lives(englishman, red)
keep(swede, dogs)
drinks(dane, tea)
leftof(green, white)
∃X lives(X, green) ∧ drinks(X, coffee)
∃X smokes(X, pallmalls) ∧ keep(X, birds)
∃X lives(X, yellow) ∧ smokes(X, dunhills)
∃X position(X, 3) ∧ drinks(X, milk)
position(norwegian, 1)
∃X,Y smokes(X, blend) ∧ neighbor(X, Y) ∧ smokes(Y, dunhill)
∃X smokes(X, bluemasters) ∧ drinks(X, bier)
∃X,Y keep(X, horses) ∧ neighbor(X, Y) ∧ smoke(Y, dunhill)
smokes(german, prince)
∃X neighbor(norwegian, X) ∧ lives(X, blue)
∃X,Y smokes(X, blends) ∧ neighbor(X,Y) ∧ drinks(Y, water)

这是正确的方法吗?任何帮助将不胜感激。

0 个答案:

没有答案