As a bit of an ongoing hobby I’ve been working on a version of CLP(R)
based on interval arithmetic. A version was originally implemented as CLP(BNR)
(Booleans, Naturals, Reals) some 30 years ago. Similar systems of the same era or a little later include CLIP (Tim Hickey et. al. at Brandeis U.), Newton, and Numerica (Pascal van Hentenryk et.al., which I think was subsumed by ILOG Solver). This version is written entirely in SWI-Prolog (no “foreign” code) and is available as package clpBNR
, although it’s still somewhat of a work in progress.
A version of the circles
problem in CLP(BNR):
?- {X**2 + (Y-3)**2 == 25, (X-3)**2 + (Y-5)**2 == 25}, solve([X,Y]).
X:: -1.0869494955077...,
Y:: 7.8804242432615... ;
X:: 4.0869494955077...,
Y:: 0.11957575673840... .
Note that the answers aren’t floating point numbers; they’re intervals (attributed variables) represented by a lower and upper bound which contain the “real” answer which, in general, isn’t a precise floating point value. (The ellipsis format shown displays common digits of both bounds with ...
suffix.) Unlike floating point arithmetic, interval arithmetic strives to be mathematically sound:
?- 1.21 is 1.1*1.1.
false.
?- {1.21 is 1.1*1.1}.
true.
As shown with the example, non-linear constraints are active (rather than being deferred pending satisfaction of linearity), which can be quite powerful:
?- {X==cos(X)}.
X:: 0.73908513321516... .
?- {X>=0,Y>=0, tan(X)==Y, X**2 + Y**2 == 5 }.
X:: 1.096668128705471...,
Y:: 1.94867108960995... .
?- X::real(0.0,1.0), {35*X**256 - 14*X**17 + X == 0.0}, solve(X).
X:: 0.0000000000000000... ;
X:: 0.847943660827315... ;
X:: 0.995842494200498... .
So just a sample. I’m still exploring possibilities and limitations. For example, although it can deal with linear systems:
?- [AX,AY]::real,{AY =:= 2*AX - 2, AY =:= -AX + 3}.
AX:: 1.666666666666666...,
AY:: 1.333333333333333... .
It may not scale particularly well. But many of these kinds of issues can be addressed in combination with symbolic approaches (e.g., gaussian pivoting for linear systems).