析取运算符的等价性和具有若干规则的定义 [英] Equivalence of disjunction operator and definition with several rules

查看:58
本文介绍了析取运算符的等价性和具有若干规则的定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在 SWI Prolog 手册 其中指出:

I just stumbled over the definition of ;/2 in the SWI Prolog Manual which states:

The `or' predicate is defined as:

Goal1 ; _Goal2 :- Goal1.
_Goal1 ; Goal2 :- Goal2.

这是否意味着 ;/2 的行为就像我们编写自己的由两个规则组成的辅助谓词一样?我记得 ;/2 是一个不纯的结构(但我有可能将它与 if-then-else 混在一起),但这个定义是纯的(虽然是元逻辑的).

Wouldn't that mean that ;/2 behaves exactly as if we wrote our own helper predicate consisting of two rules? I had memorized that ;/2 was an impure construct (but it's possible I'm mixing this up with if-then-else) but this definition is pure (although meta-logical).

;/2 的语义在 ISO 标准的第 7.8.6 段中定义,但这是在操作当前状态、选择点等方面完成的.

The semantics of ;/2 are defined in the ISO standard in paragraph 7.8.6 but this is done in terms of manipulation of the current state, choice points etc.

SWI 手册中的定义是否等同于 ISO 定义?如果不是,您知道它们不同的例子吗?

Is the definition in the SWI manual equivalent to the ISO definition? If no, do you know an example where they differ?

推荐答案

这是否意味着 ;/2 的行为就像我们编写自己的由两个规则组成的辅助谓词一样?

Wouldn't that mean that ;/2 behaves exactly as if we wrote our own helper predicate consisting of two rules?

没有.术语到正文的转换大有不同.

No. Term-to-body conversion makes the difference.

但首先,它的 (;)/2 定义在两者 7.8.6(分离)和 7.8.8(if-then-else)—正如 7.8.6 中的第一句话所暗示的那样.; 周围的圆括号见 7.1.6.6 中的注释.

But first, its (;)/2 which is defined in both 7.8.6 (disjunction) and 7.8.8 (if-then-else) — as the very first sentence in 7.8.6 suggests. For the round brackets around ; see the note in 7.1.6.6.

因此,第一个问题是,如果您在程序中看到 ( G_0 ; H_0 ),如何确定适用哪个子条款.这不取决于调用 (;)/2 时出现的实例化,而是取决于术语到正文转换 (7.6.2) 期间的实例化.

So the first question is how it is possible to decide which subclause applies in case you see ( G_0 ; H_0 ) in your program. This does not depend on the instantiation present when calling (;)/2 but rather it depends on the instantiation during term-to-body conversion (7.6.2).

?- G_0 = ( true -> X = si ), ( G_0 ; X = nisi ).
   G_0 =  (true->si=si),
   X = si
;  G_0 =  (true->nisi=si),
   X = nisi.

?- G_0 = ( true -> X = si ), call( ( G_0 ; X = nisi ) ).
   G_0 =  (true->si=si),
   X = si.

在第一个查询中,词到正文的转换在析取 G_0 内替换为 call(G_0),因此

In the first query term-to-body conversion replaces within the disjunction G_0 by call(G_0) and thus

( call( ( true -> X = si ) ) ; X = nisi ) )

将被执行.

在第二个查询中,有两个词到正文的转换,一次用于整个查询,一次用于显式call/1,但都保持原样,因此

In the second query there are two term-to-body conversions once for the entire query and once for the explicit call/1, but both leave everything as is, and thus

call( ( true -> X = si ; X = nisi ) )

将被执行,else 情况被排除.

will be executed and the else case is left out.

由于术语到正文转换的进一步差异是由于身体畸形导致的切割和错误.

Further differences due to term-to-body conversion are for cuts and errors due to malformed bodies.

这篇关于析取运算符的等价性和具有若干规则的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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