Prolog不工作的姐夫谓词

Prolog不工作的姐夫谓词,prolog,Prolog,以下是相关代码: married(X,Y) :- wife(X,Y);husband(X,Y). parent(X,Y) :- father(X,Y) ;mother(X,Y). brother(X,Y) :- man(X), parent(Z,X), parent(Z,Y), X \= Y. brother_in_law(X,Y) :- brother(X,Z),married(Z,Y). 我在谷歌上搜索过,似乎其他人一直在使用姐夫谓词的确切代码,所以应该没问题吧?我检查了其他谓词,它

以下是相关代码:

married(X,Y) :- wife(X,Y);husband(X,Y).

parent(X,Y) :- father(X,Y) ;mother(X,Y).

brother(X,Y) :-
man(X),
parent(Z,X),
parent(Z,Y),
X \= Y.

brother_in_law(X,Y) :-
brother(X,Z),married(Z,Y).
我在谷歌上搜索过,似乎其他人一直在使用姐夫谓词的确切代码,所以应该没问题吧?我检查了其他谓词,它们看起来也不错。。不知道发生了什么


此外,我所说的不工作是指我检查时它没有确认相关关系。

查看跟踪,您将看到问题:

?- trace,  brother_in_law(prins-daniel, Y).
   Call: (9) brother_in_law(prins-daniel, _11346) ? creep
   Call: (10) brother(prins-daniel, _11680) ? creep
   Call: (11) man(prins-daniel) ? creep
   Exit: (11) man(prins-daniel) ? creep
   Call: (11) parent(_11678, prins-daniel) ? creep
   Call: (12) father(_11678, prins-daniel) ? creep
   Fail: (12) father(_11678, prins-daniel) ? creep
   Redo: (11) parent(_11678, prins-daniel) ? creep
   Call: (12) mother(_11678, prins-daniel) ? creep
   Fail: (12) mother(_11678, prins-daniel) ? creep
   Fail: (11) parent(_11678, prins-daniel) ? creep
   Redo: (11) man(prins-daniel) ? creep
   Fail: (11) man(prins-daniel) ? creep
   Fail: (10) brother(prins-daniel, _11680) ? creep
   Fail: (9) brother_in_law(prins-daniel, _11346) ? creep
false.
谁是普林斯·丹尼尔的父亲?你没有这方面的事实。谁是丹尼尔王子的母亲?你也没有这方面的事实。因此,您无法找到任何兄弟,因此查询失败

这是否意味着您缺少事实或代码?密码上说如果X有一个与Y结婚的兄弟Z,那么X和Y是姐夫。这是拥有姐夫的唯一途径吗

旁注:
prins daniel
在Prolog中不像在Lisp中那样是atom。这是一个术语:

?- write_canonical(prins-daniel).
-(prins,daniel)
长期来看,情况更加复杂:

?- write_canonical(johann-georg-av-hohenzollern).
-(-(-(johann,georg),av),hohenzollern)

需要注意的是。

查看跟踪,您将看到问题:

?- trace,  brother_in_law(prins-daniel, Y).
   Call: (9) brother_in_law(prins-daniel, _11346) ? creep
   Call: (10) brother(prins-daniel, _11680) ? creep
   Call: (11) man(prins-daniel) ? creep
   Exit: (11) man(prins-daniel) ? creep
   Call: (11) parent(_11678, prins-daniel) ? creep
   Call: (12) father(_11678, prins-daniel) ? creep
   Fail: (12) father(_11678, prins-daniel) ? creep
   Redo: (11) parent(_11678, prins-daniel) ? creep
   Call: (12) mother(_11678, prins-daniel) ? creep
   Fail: (12) mother(_11678, prins-daniel) ? creep
   Fail: (11) parent(_11678, prins-daniel) ? creep
   Redo: (11) man(prins-daniel) ? creep
   Fail: (11) man(prins-daniel) ? creep
   Fail: (10) brother(prins-daniel, _11680) ? creep
   Fail: (9) brother_in_law(prins-daniel, _11346) ? creep
false.
谁是普林斯·丹尼尔的父亲?你没有这方面的事实。谁是丹尼尔王子的母亲?你也没有这方面的事实。因此,您无法找到任何兄弟,因此查询失败

这是否意味着您缺少事实或代码?密码上说如果X有一个与Y结婚的兄弟Z,那么X和Y是姐夫。这是拥有姐夫的唯一途径吗

旁注:
prins daniel
在Prolog中不像在Lisp中那样是atom。这是一个术语:

?- write_canonical(prins-daniel).
-(prins,daniel)
长期来看,情况更加复杂:

?- write_canonical(johann-georg-av-hohenzollern).
-(-(-(johann,georg),av),hohenzollern)

只是一些需要注意的事情。

您的事实在哪里?您的实际查询中有哪些不起作用?姐夫(普林斯·丹尼尔,Y)。这个数据库相当大,它甚至可能不包含你正在寻找的情况。你能在你期望程序工作的地方添加一些事实(这应该在大约5年内是可行的)吗?那么调试就容易多了。您的事实在哪里?您的实际查询中有哪些不起作用?姐夫(普林斯·丹尼尔,Y)。这个数据库相当大,它甚至可能不包含你正在寻找的情况。你能在你期望程序工作的地方添加一些事实(这应该在大约5年内是可行的)吗?那么调试就容易多了。问题是事实已经给了我,不应该被触动。你确定这不是我的密码的错吗?@MogulKhan你的密码说如果X有一个兄弟Z并且Z嫁给了Y,那么X就是Y的姐夫。但是有另一种方式成为姐夫,不是吗?克里斯托弗·奥尼尔和普林斯·丹尼尔有什么关系。我完全错过了。谢谢事实是事实已经给了我,不应该被触动。你确定这不是我的密码的错吗?@MogulKhan你的密码说如果X有一个兄弟Z并且Z嫁给了Y,那么X就是Y的姐夫。但是有另一种方式成为姐夫,不是吗?克里斯托弗·奥尼尔和普林斯·丹尼尔有什么关系。我完全错过了。谢谢