Re: constraint

Daniel Diaz <[email protected]>
Newsgroups gmane.comp.gnu.prolog.general
Message-ID <[email protected]>
michel levy a écrit :
> ?- X*X #=23.
> no
> I don't understand how this answer is produced.
> I was expecting X #= 1..23

this is simplified as X = sqrt(23) which is not an integer.

> ?- X*X #=25.
> X = 5
> yes
> I don't understand how this answer is produced.
> I was expecting X #= 1..25

similarly this is X=sqrt(25)


BTW when dealing with non-linear constraint in GNU Prolog it is 
important to define the initial domain of the variables.

For instance:
| ?- X*Y#=25.
No

because the max(X)*max(Y) overflows. So use for instance:
| ?- fd_domain(X,1,1000), X*Y#=23.

X = _#3(1..23)
Y = _#25(1..23)

You can also obtain a more precise domain using full lookahead
(using #= # instead of #= but the computation is more costly) :

| ?- fd_domain(X,1,1000), X*Y#=#25.

X = _#3(1:5:25@)
Y = _#25(1:5:25@)


> Where (papers, books,..) is it possible to have informations on the 
> finite domains constraints resolution ?

You can have a look at the PVH's book:

P. Van Hentenryck. Constraint Satisfaction in Logic Programming.
Logic Programming Series, The MIT Press, 1989.

There a lot of other articles (do a search on google with:
constraint finite domain propagation)...

Hope this helps
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.