Re: Solving arithmetic constraints (with ic?)

From: Andrew John Sadler <ajs2_at_icparc.ic.ac.uk>
Date: Wed 08 Dec 2004 04:43:43 PM GMT
Message-Id: <E1Cc4ul-0004uP-I5@tempest.icparc.ic.ac.uk>
> Dear all,
> 
> I'm looking for a way to solve sets of arithmetic constraints (on real
> variables).
> 
> For example, the constraints
> 
> Y=2*Y, Y=3*X
> 
> should yield the solution X=0, Y=0, and

?- lib(ic).
Yes (0.18s cpu)

?- Y $= 2 * Y, Y $= 3 * X.
Y = 0
X = 0
Yes (0.00s cpu)

It does (at least in ECLiPSe 5.7 #25 it does).

> 
> X^2-4
> 
> should yield the two possibilities
> 
> X=2 and X=-2

Well there are a number of ways to write this (note the use of
locate() to find the possibly many different values that satisfy the
constraint)...

   X*X $= 4, locate([X], 0.0001).

or

   sqr(X) $= 4, locate([X], 0.0001).

or

   X^2 $= 4, locate([X], 0.0001).

And in the latest patch release of ECLiPSe 5.7 (i.e. patch #66) the
first two work correctly, but the last appears to be broken, in that
it returns a fixed range which encompases all the solution values.


?- X * X $= 4, locate([X], 0.001).
X = 1.9999999999999998__2.0000000000000004
Yes (0.00s cpu, solution 1, maybe more)
X = -2.0000000000000004__-1.9999999999999998
Yes (0.00s cpu, solution 2)

?- sqr(X) $= 4, locate([X], 0.001).
X = 1.9999999999999998__2.0000000000000004
Yes (0.00s cpu, solution 1, maybe more)
X = -2.0000000000000004__-1.9999999999999998
Yes (0.03s cpu, solution 2)

?- X ^ 2 $= 4, locate([X], 0.001).
X = -2.0000000000000004__2.0000000000000004
There is 1 delayed goal.
Yes (0.00s cpu)


However, in the upcoming ECLiPSe 5.8 release, they all function
correctly and return the two values 2 and -2.  Note that the actual
values are very tight bounded reals that enclose the true value, this
is an artifact of the floating pointmaths used to comute the values.
In order to be safe, lib(ic) sometimes has to "round out" the values
in this fashion.

If possible change your code to use the alternate forms of the
constraints that do work, otherwise wait for the next version of
ECLiPSe which should be released any day now.

Hope that helped

Andrew Sadler
Received on Wed Dec 08 16:45:01 2004

This archive was generated by hypermail 2.1.8 : Wed 16 Nov 2005 06:07:32 PM GMT GMT