# Comparing CLPR with CLPBNR for constraints on reals

**URL:** <https://swi-prolog.discourse.group/t/comparing-clpr-with-clpbnr-for-constraints-on-reals/2950>\
**Category:** General\
**Tags:** discussion\
**Created:** [September 20, 2020, 7:45am UTC](https://swi-prolog.discourse.group/t/comparing-clpr-with-clpbnr-for-constraints-on-reals/2950 "2020-09-20T07:45:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JCR](https://avatars.discourse-cdn.com/v4/letter/j/258eb7/32.png) [@JCR](https://swi-prolog.discourse.group/u/JCR)\
**Post date:** [September 20, 2020, 7:45am UTC](https://swi-prolog.discourse.group/t/comparing-clpr-with-clpbnr-for-constraints-on-reals/2950/1 "2020-09-20T07:45:23Z")

</div>

It seems there are some interesting differences between these modules (CLPR is bundled with SWI Prolog; CLPBNR is available as a [pack](https://www.swi-prolog.org/pack/list) 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

---

<div class="post-metadata">

**Author:** ![ridgeworks](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ridgeworks/32/886_2.png) [@ridgeworks](https://swi-prolog.discourse.group/u/ridgeworks)\
**Post date:** [September 20, 2020, 4:14pm UTC](https://swi-prolog.discourse.group/t/comparing-clpr-with-clpbnr-for-constraints-on-reals/2950/2 "2020-09-20T16:14:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![JCR](https://avatars.discourse-cdn.com/v4/letter/j/258eb7/32.png) [@JCR](https://swi-prolog.discourse.group/u/JCR)\
**Post date:** [September 22, 2020, 12:57am UTC](https://swi-prolog.discourse.group/t/comparing-clpr-with-clpbnr-for-constraints-on-reals/2950/3 "2020-09-22T00:57:50Z")

</div>

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 🙂 Thanks!

---

<div class="post-metadata">

**Author:** ![JCR](https://avatars.discourse-cdn.com/v4/letter/j/258eb7/32.png) [@JCR](https://swi-prolog.discourse.group/u/JCR)\
**Post date:** [September 22, 2020, 1:01am UTC](https://swi-prolog.discourse.group/t/comparing-clpr-with-clpbnr-for-constraints-on-reals/2950/4 "2020-09-22T01:01:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ridgeworks](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ridgeworks/32/886_2.png) [@ridgeworks](https://swi-prolog.discourse.group/u/ridgeworks)\
**Post date:** [September 22, 2020, 3:37pm UTC](https://swi-prolog.discourse.group/t/comparing-clpr-with-clpbnr-for-constraints-on-reals/2950/5 "2020-09-22T15:37:32Z")

</div>

> [@JCR](#):
>
> 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.

> [@JCR](#):
>
> And the documentation is very clear and readable

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.

---

<div class="post-metadata">

**Author:** ![JCR](https://avatars.discourse-cdn.com/v4/letter/j/258eb7/32.png) [@JCR](https://swi-prolog.discourse.group/u/JCR)\
**Post date:** [September 23, 2020, 7:10am UTC](https://swi-prolog.discourse.group/t/comparing-clpr-with-clpbnr-for-constraints-on-reals/2950/6 "2020-09-23T07:10:11Z")

</div>

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 🙂

/JCR
