Unexpected behavior of tuples_in

I would (naively) expect that the following query would fail to unify:

tuples_in([[X, Y]], [[1, 2], [2, 1]]), tuples_in([[X, Y]], [[1, 1], [2, 2]]).

but it evaluates to:

X in 1..2,
tuples_in([[X, Y]], [[1, 1], [2, 2]]),
tuples_in([[X, Y]], [[1, 2], [2, 1]]),
Y in 1..2.

Similarly, I would expect

tuples_in([[X, X]], [[1, 2]]).```

to be false but I instead get:

X = 1.

I would greatly appreciate an interpretation that helps me better understand this.

I guess tuples_in/2 is not really designed with this in mind and its propagation is not strong enough to find this. If you add a label/1 call, we get.

?- tuples_in([[X, Y]], [[1, 2], [2, 1]]), tuples_in([[X, Y]], [[1, 1], [2, 2]]), label([X,Y]).
false.

In general constraint systems may answer with conflicting constraints or constraints that could have been a concrete value because there is only a single solution.

Seems you are on an old version. There has been a bug report on tuples_in/2 not so long ago. Now fails, at least in the development version.

Thank you very much Jan. Much appreciated.

Is there any way to know how strong the propagation will be for particular predicates (other than trying it out in test cases where you know the answer)?

I see in the documentation that all_different and all_distinct are distinguished by the strength of propagation but most predicates do not seem to mention propagation strength.

Or, in practice, is labeling used in most cases, in order to ensure adequate propagation?

Thanks. This is a great forum and I’m really enjoying learning prolog and clp.

Best,
bat

I’m not an expert in CLP (Constraint Logic Programming). As I understand it, only “posting” the constraints and calling the labeling predicate has well defined semantics. If you don’t call labeling you may end up with a set of conflicting constraints, a concrete answer or a legitimate set of constraints. Documentation, source or trying are FAIK your only answers.

Note that this is somewhat related to clause indexing and choice points discussed here before: there are no guarantees. Clause indexing typically reduces search and choice points,but whether or not it makes a call deterministic remains largely undefined.