How do I get a prolog number from this clpfd code

This would be in a file tmp.pl

:-use_module(library(clpfd)).
tst(R,G,X):-
(R + G) // 2  #= X.

These queries works as I expect

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

?- tst(100,400,250).
true

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

?- tst(100,X,250).
X in 400..401,
100+X#=_6404,
_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.

Thanks.

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.

e.g.

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