3

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 ?

Community
  • 1
  • 1
Manfred
  • 75
  • 6
  • From a purely declarative viewpoint, there is no need to restore inconsistent values. But `contracting/1` might blow ob the representation of the domain so much that it becomes infeasible to use. Or the domain representation leads to an even more costly search thereafter. – false Mar 29 '16 at 08:51

1 Answers1

3

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 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.
mat
  • 40,498
  • 3
  • 51
  • 78