# Restrictions on clp(q/r) (Division)

**URL:** <https://swi-prolog.discourse.group/t/restrictions-on-clp-q-r-division/6826>\
**Category:** General\
**Created:** [September 8, 2023, 11:03am UTC](https://swi-prolog.discourse.group/t/restrictions-on-clp-q-r-division/6826 "2023-09-08T11:03:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![firefrorefiddle](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/firefrorefiddle/32/4619_2.png) [@firefrorefiddle](https://swi-prolog.discourse.group/u/firefrorefiddle)\
**Post date:** [September 8, 2023, 11:03am UTC](https://swi-prolog.discourse.group/t/restrictions-on-clp-q-r-division/6826/1 "2023-09-08T11:03:30Z")

</div>

I have been trying to apply library(clpq) (same with clpr) to this problem: [https://www.youtube.com/watch?v=ABj3IC9pYlQ](https://www.youtube.com/watch?v=ABj3IC9pYlQ)

You don’t need to watch this, the question which is posed is this:

> Alice and Bob take 2 hours to finish a job. Alice and Charlie take three hours. Bob and Charlie take four hours. How long does it take when they work all together?

In the end, I found out that it worked with the formulation of the equations that Presh uses in the video, namely:

```prolog
?- {1=2*(A+B), 3*(A+C)=1, 4*(B+C)=1, X*(A+B+C)=1}.
A = 7r24,
B = 5r24,
C = 1r24,
X = 24r13.

```

However, I had originally written the equations like `1/(A+B)=2` instead of `1=2*(A+B)`. This doesn’t work at all:

```prolog
?- {1/(A+B)=2, 3*(A+C)=1, 4*(B+C)=1, X*(A+B+C)=1}.
{B=1r4-C, A=1r3-C, -1+A*X+B*X+C*X=0, -2+1/(A+B)=0},
{-1+A*X+B*X+C*X=0, -2+1/(A+B)=0},
{-1+A*X+B*X+C*X=0, -2+1/(A+B)=0},
{-1+A*X+B*X+C*X=0, -2+1/(A+B)=0},
{-1+A*X+B*X+C*X=0, -2+1/(A+B)=0}.

?- {1/(A+B)=2, 3*(A+C)=1, 4*(B+C)=1, X*(A+B+C)=1}, minimize(X).
false.

```

Being unexperienced with this library, that surprised me, because I would have thought that constraints would be converted to some canonical form anyway. Should this be expected? Perhaps some kind of warning in the documentation would be appropriate?

---

<div class="post-metadata">

**Author:** ![brebs](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@brebs](https://swi-prolog.discourse.group/u/brebs)\
**Post date:** [September 8, 2023, 2:31pm UTC](https://swi-prolog.discourse.group/t/restrictions-on-clp-q-r-division/6826/2 "2023-09-08T14:31:23Z")

</div>

Just as a (hopefully interesting) aside, clpBNR works for both:

```prolog
?- {1==2*(A+B), 3*(A+C)==1, 4*(B+C)==1, X*(A+B+C)==1}, solve([A,B,C,X]).
A:: 0.2916666...,
B:: 0.2083333...,
C:: 0.0416666...,
X:: 1.846153... .

?- {1/(A+B)==2, 3*(A+C)==1, 4*(B+C)==1, X*(A+B+C)==1}, solve([A,B,C,X]).
A:: 0.2916666...,
B:: 0.2083333...,
C:: 0.0416666...,
X:: 1.846153... .

```
