How do I get a prolog number from this clpfd code

This would be in a file

(R + G) // 2  #= X.

These queries works as I expect

?- tst(100,400,X).
X = 250.

?- tst(100,400,250).

Why am I getting this, I expect X to be 400

?- tst(100,X,250).
X in 400..401,
_6404 in 500..501.

Very possibly I don’t know enough clpfd, but how do I convert the ‘X in 400…401’ to a Prolog number? I am running a version 8.1.17.


You may want to try the label/1 or labeling/2 predicate to generate all solutions. I think it’s giving multiple solutions since the integer division means that either 400 or 401 will satisfy.


?- tst(100, X, 250), label([X]).
X = 400 ;
X = 401.
1 Like