Re: constraint

Timo Karjalainen <[email protected]>
Newsgroups gmane.comp.gnu.prolog.general
Message-ID <[email protected]>
On Wed, 22 Mar 2006, michel levy wrote:

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

Looks like X is taken as integer variable by gprolog. 23 is not a square,
so there is no (integer) solution. 25 is 5*5, so you get precisely 5 as
solution.

Note that we're talking of _finite_ domains. Real numbers are anything but
finite...

(If you want two-factor factorizations of some integer, try X*Y to get
other solutions besides the square root. Prolog can't bind the variable X
as two different values at the same time, i.e. X*X equals N only if X is
the square root of N.)


-- 
TOK
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.