Comparing CLPR with CLPBNR for constraints on reals

It seems there are some interesting differences between these modules (CLPR is bundled with SWI Prolog; CLPBNR is available as a pack courtesy of @ridgeworks).

With CLPR (use_module(library(clpr)).)

?- {4 = 2/X}.
X = 0.5.

?- {4 = (4 - 2) / (2 - X)}.
{4-2.0/(2-X)=0.0}.

?- {4 = (4 - 2) / (X - 2)}.
{4-2.0/(-2.0+X)=0.0}.

?- {1 = (4 - 2)/(8 - X)}.
{1-2.0/(8-X)=0.0}.

With CLPBNR (use_module(library(clpbnr)).)

?- {4 == 2/X}.
X = 1r2.

?- {4 == (4 - 2) / (2 - X)}.
X = 3r2.

?- {4 == (4 - 2) / (X - 2)}.
X = 5r2.

?- {1 == (4 - 2)/(8 - X)}.
X = 6.

/JCR

1 Like

There are many differences but I think the main one you’re pointing out here is explained by the clpr documentation in the SWIP manual:

A.10.4 Non-linear constraints

The CLP(Q,R) system deals only passively with non-linear constraints. They remain in a passive state until certain conditions are satisfied.

When the conditions are satisfied the variables are unified with a floating point number. (Caveat: SWIP floating point is a small subset of reals.)

With clpBNR all constraints are “activated” but the variables (intervals) represent sets (compact range) of real numbers until a single (point) value remains in the set. In your examples, the built-in constraint solver finds this quickly since all the constants are precise (integer or rational) and there is only one solution.

3 Likes

Yes, I noted that as well. I have been experimenting with clpBNR and I am very impressed. Seems powerful. And the documentation is very clear and readable :slight_smile: Thanks!

1 Like

By the way, are there any plans to make clp(BNR) part of the SWI Prolog installation? Would be cool. clpr does not seem to have a maintainer and clp(BNR) has support for integers as well as reals.

So I currently have no plans in this direction and I’m not exactly clear what the criteria would be for doing this. At a minimum, currently missing is good reference documentation (in the style of the SWIP Manual) and an adequate set of unit test cases.

In the meantime, I think the very good (IMO) SWIP “pack” mechanism and GitHub open sourcing provides most of the benefits of builtin libraries. Ultimately this decision should be driven by SWIP development (Jan) and user requirements, and right now there are few users. Any feedback welcome.

Helpful comment because the author is probably the least qualified to pass judgement. Feel free to use the GitHub project Issues to report any problems with doc or software.

2 Likes

I agree, the pack mechanism is very easy to work with.

I will try to make time to read through the documentation and (if its needed) suggest any improvements.

Thanks again for porting clpBNR :slight_smile:

/JCR