CLPB 的不良特性 [英] Undesirable properties of CLPB
问题描述
library(clpb)
目前在 SICStus(原始版本)和 SWI(通过 mat)中可用.让我很快进入本质:
?- X = 1+1, sat(X), X = 1+1.X = 1+1.?- sat(X),X = 1+1.错误的.
所以这是一个类似的问题,因为它存在于library(clpfd)
的默认状态.
遇到这种情况怎么办?
更新:在mat的library(clpfd)
中,现在有用于此目的的函子#/1
.理想情况下,加上运算符声明 op(150,fx,#)
,我们现在可以这样写:
?- X = 1+1, #X #= Y.错误:类型错误:应为整数",找到1+1"(复合)
为了确保完整的代数属性,必须声明:
:- set_prolog_flag(clpfd_monotonic, true).
现在,不明确的变量(因此,只能是整数或表达式)会产生实例化错误:
?- 1 + 1 #= Y.错误:参数未充分实例化?- 1 + 1 #= #Y.Y = 2.
<块引用>
遇到这种情况怎么办?
同时,library(clpb)
也确保了类似于 library(clpz)
/library(clfd)
的单调性.在这种执行模式下,显式变量必须用 (v)/1
修饰.
?- current_prolog_flag(clpb_monotonic,B).B = 错误.% 默认?- 坐(X).X = 1.?- set_prolog_flag(clpb_monotonic,true).真的.?- 坐(X).错误:参数未充分实例化?- sat(v(X)).X = 1.
在 Scryer 中,说:
?- use_module(library(clpb)).真的.?-断言(clpb:单调).真的.?- 坐(X).捕获:错误(实例化错误,实例化错误(未知(_67),1))?- sat(v(X)).X = 1;错误的.
library(clpb)
is currently available in SICStus (original version), and SWI (by mat). Let me come to the essence quite rapidly:
?- X = 1+1, sat(X), X = 1+1.
X = 1+1.
?- sat(X), X = 1+1.
false.
So this is a similar problem as it exists in the default state of library(clpfd)
.
What to do in such a situation?
Update: In library(clpfd)
of mat, there is now the functor # /1
for this purpose. Ideally, accompanied with an operator declaration op(150,fx,#)
, we now can write:
?- X = 1+1, #X #= Y.
ERROR: Type error: `integer' expected, found `1+1' (a compound)
To ensure full algebraic properties one has to declare:
:- set_prolog_flag(clpfd_monotonic, true).
Now, variables that are left ambiguous (thus, being either integers only, or expressions) produce instantiation errors:
?- 1 + 1 #= Y.
ERROR: Arguments are not sufficiently instantiated
?- 1 + 1 #= #Y.
Y = 2.
What to do in such a situation?
In the meantime, also library(clpb)
ensures monotonicity similar to library(clpz)
/library(clfd)
. Within this execution mode, explicit variables have to be decorated with (v)/1
.
?- current_prolog_flag(clpb_monotonic,B).
B = false. % the default
?- sat(X).
X = 1.
?- set_prolog_flag(clpb_monotonic,true).
true.
?- sat(X).
ERROR: Arguments are not sufficiently instantiated
?- sat(v(X)).
X = 1.
In Scryer, say:
?- use_module(library(clpb)).
true.
?- asserta(clpb:monotonic).
true.
?- sat(X).
caught: error(instantiation_error,instantiation_error(unknown(_67),1))
?- sat(v(X)).
X = 1
; false.
这篇关于CLPB 的不良特性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!