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

查看:16
本文介绍了为什么双重否定在 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 定义父级).但我想知道为什么没有主动检测哪些人的方法(michaeldavid,...) 属于 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天全站免登陆