为什么在 Prolog 中不绑定双重否定 [英] Why double negation doesn't bind in Prolog

查看:113
本文介绍了为什么在 Prolog 中不绑定双重否定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有以下理论:

a(X) :- \+ b(X).

b(X) :- \+ c(X).

c(a).

它只是说真的,这当然是正确的,a(X) 是真的,因为没有 b(X)(否定为有限失败).因为如果没有 c(X) 并且我们有 c(a),那么只有一个 b(X),可以这样说是真的.我想知道为什么 Prolog 不提供答案 X = a?比如说我介绍了一些语义:

It simply says true, which is of course correct, a(X) is true because there is no b(X) (with negation as finite failure). Since there is only a b(X) if there is no c(X) and we have c(a), one can state this is true. I was wondering however why Prolog does not provide the answer X = a? Say for instance I introduce some semantics:

noOrphan(X) :- \+ orphan(X).

orphan(X) :- \+ parent(_,X).

parent(david,michael).

当然,如果我查询 noOrphan(michael),这将导致 truenoOrphan(david)false(因为我没有为 david 定义父级),但我想知道为什么没有主动检测哪些人的方法(michael>david,...) 属于 noOrphan/1 关系?

Of course if I query noOrphan(michael), this will result in true and noOrphan(david) in false (since I didn't define a parent for david)., but I was wondering why there is no proactive way of detecting which persons (michael, david,...) belong to the noOrphan/1 relation?

这可能是 Prolog 回溯机制的结果,但 Prolog 可以保持一种状态,以验证是否以积极方式 (0,2,4,...) 否定深度搜索,或消极方式 (1,3,5,...) 否定深.

This probably is a result of the backtracking mechanism of Prolog, but Prolog could maintain a state which validates if one is searching in the positive way (0,2,4,...) negations deep, or the negative way (1,3,5,...) negations deep.

推荐答案

让我们从更简单的事情开始.说 \+ X = Y.这里,否定目标是一个预定义的内置谓词.所以事情就更清楚了:XY 应该是不同的.但是, \+ X = Y 失败了,因为 X = Y 成功了.因此,在何种精确条件下目标失败,没有留下任何痕迹.

Let's start with something simpler. Say \+ X = Y. Here, the negated goal is a predefined built-in predicate. So things are even clearer: X and Y should be different. However, \+ X = Y fails, because X = Y succeeds. So no trace is left under which precise condition the goal failed.

因此,\+ \+ X = Y 确实会产生一个空答案,而不是预期的 X = Y.查看此答案了解详情.

Thus, \+ \+ X = Y does produce an empty answer, and not the expected X = Y. See this answer for more.

鉴于这种简单的查询已经显示出问题,您不能对像您这样的用户定义的目标期望过高.

Given that such simple queries already show problems, you cannot expect too much of user defined goals such as yours.

在一般情况下,您必须首先重新考虑否定的实际含义.答案比乍一看要复杂得多.想想程序 p :- \+ p. 应该 p 成功还是失败?p 应该是真的还是假的?这里实际上有两个模型不再适合 Prolog 使用最小模型的观点.这些考虑为逻辑编程开辟了新的分支,如答案集编程 (ASP).

In the general case, you would have to first reconsider what you actually mean by negation. The answer is much more complex than it seems at first glance. Think of the program p :- \+ p. should p succeed or fail? Should p be true or not? There are actually two models here which no longer fits into Prolog's view of going with the minimal model. Considerations as these opened new branches to Logic Programming like Answer Set Programming (ASP).

但让我们坚持使用 Prolog.否定只能在非常有限的上下文中使用,例如当目标充分实例化并且定义分层时.不幸的是,对于安全执行否定的目标没有普遍接受的标准.我们可以等到目标是可变的自由(地面),但这通常意味着我们必须等待太久 - 用行话来说:否定的目标挣扎.

But let's stick to Prolog. Negation can only be used in very restricted contexts, such as when the goal is sufficiently instantiated and the definition is stratified. Unfortunately, there are no generally accepted criteria for the safe execution of a negated goal. We could wait until the goal is variable free (ground), but this means quite often that we have to wait way too long - in jargon: the negated goal flounders.

如此有效,一般否定与纯 Prolog 程序不能很好地配合.Prolog 的核心确实是该语言的纯单调子集.不过,在 Prolog(或其各自的扩展)的约束部分中,否定可能工作得很好.

So effectively, general negation does not go very well together with pure Prolog programs. The heart of Prolog really is the pure, monotonic subset of the language. Within the constraint part of Prolog (or its respective extensions) negation might work quite well, though.

这篇关于为什么在 Prolog 中不绑定双重否定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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