#= 在 Prolog 中是什么意思?
What does #= mean in Prolog?
我最近在 Prolog 中看到一个使用谓词 #=/2 的程序。我在 the SWI prolog website 上查找了这个,他们将其定义为
The arithmetic expression X equals Y. When reasoning over integers, replace is/2 by #=/2 to obtain more general relations.
我不明白的是 #=/2 怎么可以比 'general' 多,因为它 仅 用于整数。
来自文档entry page:
They implement pure relations between integer expressions and can be used in all directions
举个例子:
?- X+3 #= X*2.
X = 3.
看似简单,实际上用常规的算术表达式求值很难得到这样的结果
?- X+3 is X*2.
ERROR: is/2: Arguments are not sufficiently instantiated
从is/2页可以看到签名
-Number is +Expr
其中 +Expr
表示它 必须 研磨。
此外,is/2 的左参数实际上 应该 是原子的:
?- 3+3 is 3*2.
false.
尽管我们知道以上说法应该是正确的...
注意:正如@false 所指出的那样,名称 CLP(FD) 有点 'understatement',可以命名为 CLP(Z),因为域的有限性通常可以放宽。
我最近在 Prolog 中看到一个使用谓词 #=/2 的程序。我在 the SWI prolog website 上查找了这个,他们将其定义为
The arithmetic expression X equals Y. When reasoning over integers, replace is/2 by #=/2 to obtain more general relations.
我不明白的是 #=/2 怎么可以比 'general' 多,因为它 仅 用于整数。
来自文档entry page:
They implement pure relations between integer expressions and can be used in all directions
举个例子:
?- X+3 #= X*2.
X = 3.
看似简单,实际上用常规的算术表达式求值很难得到这样的结果
?- X+3 is X*2.
ERROR: is/2: Arguments are not sufficiently instantiated
从is/2页可以看到签名
-Number is +Expr
其中 +Expr
表示它 必须 研磨。
此外,is/2 的左参数实际上 应该 是原子的:
?- 3+3 is 3*2.
false.
尽管我们知道以上说法应该是正确的...
注意:正如@false 所指出的那样,名称 CLP(FD) 有点 'understatement',可以命名为 CLP(Z),因为域的有限性通常可以放宽。