users-prolog
[Top][All Lists]
Advanced

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

Re: constraint


From: Timo Karjalainen
Subject: Re: constraint
Date: Wed, 22 Mar 2006 13:21:36 +0200 (EET)

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




reply via email to

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