Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 ?

like image 354
Manfred Avatar asked Jun 01 '26 11:06

Manfred


1 Answers

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.
like image 187
mat Avatar answered Jun 04 '26 04:06

mat