Constraints: Bug? X*X*X #= 0 fails

View: New views
2 Messages — Rating Filter:   Alert me  

Constraints: Bug? X*X*X #= 0 fails

by - --14 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

In gnu prolog 1.3.0 no value for X is found for the constraint X*X*X #= 0 and additionally, gprolog states there is no solution:

| ?- X*X*X #= 0.

no

On the other hand, the (correct) solution X #= 1 is found for X*X*X #= 1:

| ?- X*X*X #= 1.

X = 1

yes

and X #= 2 is found for X*X*X = 8.

GNU Prolog gives no solutions for X*X*X #= 27 (X #= 3), X*X*X #= 64 (X #= 4), and even states there are none. Is this behaviour intentional?

_______________________________________________
Users-prolog mailing list
Users-prolog@...
http://lists.gnu.org/mailman/listinfo/users-prolog

Re: Constraints: Bug? X*X*X #= 0 fails

by Daniel Diaz-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,
> In gnu prolog 1.3.0 no value for X is found for the constraint X*X*X
> #= 0 and additionally, gprolog states there is no solution:
>
> | ?- X*X*X #= 0.
>
> no
>

The problem comes from integer overflow (X*X*X computes the upper bound
as the max of X ** 3, which overflows the integer encoding). Generally
it is recommended to first define the domain of the variable (e.g. using
fd_domain) and then to add constraints. Example:

| ?- fd_domain(X,0,1000), X*X*X #= 0.

X = _#3(0..1000)

Note: in this example X=0 is not detected until labeling, but the
solution is obtained with a labeling:

| ?- fd_domain(X,0,1000), X*X*X#=0, fd_labeling(X).

X = 0 ? ;
no

It is better to use the ** operator (power) for this:

| ?- X**3 #= 0.

X = 0

> On the other hand, the (correct) solution X #= 1 is found for X*X*X #= 1:
>
> | ?- X*X*X #= 1.
>
> X = 1
>
> yes
>
> and X #= 2 is found for X*X*X = 8.
>
> GNU Prolog gives no solutions for X*X*X #= 27 (X #= 3), X*X*X #= 64 (X
> #= 4), and even states there are none. Is this behaviour intentional?
>
| ?- fd_domain(X,0,1000), X*X*X#=27, fd_labeling(X).

X = 3

or better

| ?- X**3 #= 27.

X = 3




_______________________________________________
Users-prolog mailing list
Users-prolog@...
http://lists.gnu.org/mailman/listinfo/users-prolog