Does the predicate `contracting/1` restore deleted inconsistent values?

半腔热情 提交于 2019-12-10 18:26:30

问题


This question is subsequent to another one I posted earlier on custom labeling in Prolog.

Does the contracting/1 predicate, when used after a value assignment to a variable in a custom labeling predicate, delete the "inconsistent" values from the domain permanently ? Or are these values restored when backtracking ?


回答1:


These values are of course restored on backtracking.

It is the nature of pure Prolog predicates, such as CLP(FD) constraints, that everything they state is completely undone on backtracking. Without this, many important declarative properties would not hold. See logical-purity for more information.

You can see easily that this also holds for clpfd:contracting/1, using for example a sample session:

?- X in 0..5, X mod Y #= 2, Y in 0..2.
X in 0..5,
X mod Y#=2,
Y in 1..2.

?- X in 0..5, X mod Y #= 2, Y in 0..2, clpfd:contracting([X,Y]).
false.

?- X in 0..5, X mod Y #= 2, Y in 0..2, ( clpfd:contracting([X,Y]) ; true ).
X in 0..5,
X mod Y#=2,
Y in 1..2.


来源:https://stackoverflow.com/questions/36272417/does-the-predicate-contracting-1-restore-deleted-inconsistent-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!