为什么 gprolog 不将 modus ponens 的使用链接在一起?

发布于 2024-11-27 22:54:49 字数 533 浏览 9 评论 0原文

我正在阅读 立即学习 Prolog1.1.2 知识库 2 他们写了关于将肯定前件的使用链接在一起。

KB2.pl 文件:

listensToMusic(mia).
happy(yolanda).
playsAirGuitar(mia) :- listensToMusic(mia).
playsAirGuitar(yolanda) :- listensToMusic(yolanda).
listensToMusic(yolanda) :- happy(yolanda).

当查询:

playsAirGuitar(yolanda).

提交给 gprolog 时,它应该响应 yes,因为它应该能够从 yolanda 快乐的事实推断出这一点。

但 gprolog 的响应为 no。这是为什么?

I am reading Learn Prolog Now, 1.1.2 Knowledge Base 2 where they write about chaining together uses of modus ponens.

The KB2.pl file:

listensToMusic(mia).
happy(yolanda).
playsAirGuitar(mia) :- listensToMusic(mia).
playsAirGuitar(yolanda) :- listensToMusic(yolanda).
listensToMusic(yolanda) :- happy(yolanda).

When the query:

playsAirGuitar(yolanda).

is submitted to gprolog, it is supposed to respond yes, because it should be able to infer it from the fact that yolanda is happy.

But gprolog responds with no. Why is that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黑色毁心梦 2024-12-04 22:54:49

我认为问题在于谓词 ListensToMusic/1 的子句是分开的。

以下代码对我返回 yes:

listensToMusic(mia).
listensToMusic(yolanda) :- happy(yolanda).
happy(yolanda).
playsAirGuitar(mia) :- listensToMusic(mia).
playsAirGuitar(yolanda) :- listensToMusic(yolanda).

您应该收到类似的警告

warning: discontiguous predicate listensToMusic/1 - clause ignored

i think that the problem is that the clauses of the predicate listensToMusic/1 are separated.

the following code returns yes for me:

listensToMusic(mia).
listensToMusic(yolanda) :- happy(yolanda).
happy(yolanda).
playsAirGuitar(mia) :- listensToMusic(mia).
playsAirGuitar(yolanda) :- listensToMusic(yolanda).

you should get a warning like

warning: discontiguous predicate listensToMusic/1 - clause ignored
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文