本文介绍了谓词“contracting / 1”是否恢复删除不一致的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题是在Prolog中的另一个关于自定义标签的问题。

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

在自定义标签谓词中的变量赋值后使用 contracting / 1 谓词时,删除不一致值域永久?还是在追溯时恢复这些值?

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 ?

推荐答案

在追溯时,这些值当然还原

These values are of course restored on backtracking.

这是 Prolog谓词(例如CLP(FD)约束)的性质,他们声明的一切完全撤回。没有这个,许多重要的声明属性将不成立。有关更多信息,请参阅的问题

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.

您可以轻松看到这也适用于 clpfd:contracting / 1 ,使用示例会话:

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.

这篇关于谓词“contracting / 1”是否恢复删除不一致的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 09:51