Equality constraints are added to the store implicitly each time variables that have been mentioned in explicit constraints are bound—either to another such variable or to a number.
clp(r) ?- {2*A+3*B=C/2}, C=10.0, A=B. A = 1.0, B = 1.0, C = 10.0
Is equivalent modulo rounding errors to
clp(r) ?- {2*A+3*B=C/2, C=10, A=B}. A = 1.0, B = 0.9999999999999999, C = 10.0
The shortcut bypassing the use of {}/1
is allowed and makes
sense because the interpretation of this equality in Prolog and clp(R)
coincides. In general, equations involving interpreted functors,
+/2
in this case, must be fed to the solver explicitly:
clp(r) ?- X=3.0+1.0, X=4.0. no
Moreover, variables known by clp(R) may be bound directly to floats only. Likewise, variables known by clp(Q) may be bound directly to rational numbers only; see CLPQR Fragments and Bits. Failing to do so is rewarded with an exception:
clp(q) ?- {2*A+3*B=C/2}, C=10.0, A=B. ! Type error in argument 2 of = /2 ! 'a rational number' expected, but 10.0 found ! goal: _254=10.0
This is because 10.0
is not a rational constant. To make clp(Q) happy
you have to say:
clp(q) ?- {2*A+3*B=C/2}, C=rat(10,1), A=B. A = 1, B = 1, C = 10
If you use {}/1
, you don't have to worry about such details.