3

I have:

:-use_module(library(clpr)).
comp(X, Y, Z):-
    {X = Y * Z, Y = Z, Y > 0, Z > 0}.

Which with the query:

?-comp(X,3,Z).

Yields:

X = 9.0,
Z = 3.0

as expected. But why doesn't

comp(9,Y,Z).

also give me values for Y and Z? What I get is instead:

{Z>0.0,Y=Z,9-Y*Z=0.0},
{9-Y*Z=0.0},
{9-Y*Z=0.0}

Thanks!

2 Answers2

2

Probably a weakness of the used CLP(R) that quadratic case doesn't work so well. After Y = Z, it is evident that X = Y**2, and then with X = 9 and Y > 0, you should easily get Y = 3. Which CLP(R) do you use?

A CLP(R) need not only support linear equalities and inequalities. Using for example Gröbner Basis algorithm a CLP(R) could do more, even algebraically. Some computer algebra system can do that easily.

So I guess its not a problem of Prolog per se, rather of the library. Strictly speaking CLP(X) only indicates a domain X. For the domain R of real numbers there is wide variety of potential equation and inequation solvers.

  • jumping to X = Y**2 is easy for humans, but even X = Y*Y with a known X should conclude Y must be discoverable as well. How, is another issue. But it could be done even numerically... – Will Ness Aug 27 '18 at 18:21
1

Better with constraints over finite domains using this module:

:-use_module(library(clpfd)).
comp(X, Y, Z):-
    X #= Y * Z, Y #= Z, Y #> 0, Z #> 0.

With

comp(9,Y,Z).

I get:

Y = Z, Z = 3