3
votes

If I have

A in 0..4, A * A #=A.

Is it possible that

A in 0..1.

?

I would say no because 0*0 = 0, and 1*1 = 1, so these two can not be A?

Thank you in advance.

1
But these two can be A. - Grzegorz Adam Kowalski
Why do you think it could not while it satisfies all the contraints? - m09
and please stay on your first question, no need to create many of them - m09
nice question, about identity... - CapelliC
I think Markus Triska (author of SWI-Prolog CLP(FD)) could have posted about this in SWI-Prolog mailing list, some month ago... not sure it's relevant. Try searching the mailing list - CapelliC

1 Answers

3
votes

What you are asking here is about the consistency of CLPFD-systems. Generally speaking, systems try to maintain consistency "as good as they can" with different kinds of tradeoff to consistency vs. speed. But most of the time they deliver only safe approximations. In this case, however, everything seems perfect (here using SICStus):

| ?- A in 0..4, A * A #=A.
clpfd:(A*A#=A),
A in 0..1 ? ;
no

So, we get as an answer: Yes, there are solutions, provided clpfd(:A*A#=A), A in 0..1 is true. A priori we cannot say whether or not that is the case, but we might try it out:

| ?- A in 0..4, A * A #=A, A = 1.
A = 1 ? ;
no
| ?- A in 0..4, A * A #=A, A = 0.
A = 0 ? ;
no

So: Both 0 and 1 are a solution, and thus A in 0..1 is a perfect answer!

BTW, you get (essentially) the same answer in SICStus, SWI, B, and GNU.