Prolog如何得出3 <;2? [英] How can Prolog derive nonsense results such as 3 &lt; 2?

查看:10
本文介绍了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,它包含三个出现的 s),而 X 本身是two-ish".

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天全站免登陆