users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Daniel Diaz
Subject: Re: Constraints: Bug? X*X*X #= 0 fails
Date: Sat, 06 Jun 2009 16:49:13 +0200
User-agent: Thunderbird 2.0.0.21 (Windows/20090302)

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






reply via email to

[Prev in Thread] Current Thread [Next in Thread]