Search code examples
dynamicprologclpfd

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 ?


Solution

  • 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.