Prolog如何得出无意义的结果,例如3 <2? [英] How can Prolog derive nonsense results such as 3 &lt; 2?

查看:56
本文介绍了Prolog如何得出无意义的结果,例如3 <2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读的一篇论文如下:

A paper I'm reading says the following:

Plaisted [3] 表明可以写出形式上正确的使用一阶谓词演算语义的 PROLOG 程序得出无意义的结果,例如 3 <2.

Plaisted [3] showed that it is possible to write formally correct PROLOG programs using first-order predicate-calculus semantics and yet derive nonsense results such as 3 < 2.

这是指 Prologs 没有使用 发生检查的事实(1980 年代).

It is referring to the fact that Prologs didn't use the occurs check back then (the 1980s).

不幸的是,它引用的论文是收费墙.我仍然希望看到这样的例子.直觉上,感觉就像省略发生检查只是将结构的范围扩大到包括循环结构(但根据作者的说法,这种直觉一定是错误的).

Unfortunately, the paper it cites is behind a paywall. I'd still like to see an example such as this. Intuitively, it feels like the omission of the occurs check just expands the universe of structures to include circular ones (but this intuition must be wrong, according to the author).

我希望这个例子不是

smaller(3, 2) :- X = f(X).

那会令人失望.

推荐答案

以下是现代语法论文中的示例:

Here is the example from the paper in modern syntax:

three_less_than_two :-
    less_than(s(X), X).

less_than(X, s(X)).

我们确实得到:

?- three_less_than_two.
true.

因为:

?- less_than(s(X), X).
X = s(s(X)).

具体来说,这解释了查询中 3 和 2 的选择:鉴于 X = s(s(X))s(X) 的值是 "三个"(如果不展开内部的 X,它包含 3 个 s),而 X 本身是两个".

Specifically, this explains the choice of 3 and 2 in the query: Given X = s(s(X)) the value of s(X) is "three-ish" (it contains three occurrences of s if you don't unfold the inner X), while X itself is "two-ish".

启用发生检查让我们回到逻辑行为:

Enabling the occurs check gets us back to logical behavior:

?- set_prolog_flag(occurs_check, true).
true.

?- three_less_than_two.
false.

?- less_than(s(X), X).
false.

所以这确实符合

arbitrary_statement :-
    arbitrary_unification_without_occurs_check.

这篇关于Prolog如何得出无意义的结果,例如3 <2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆