In general, there are many ways to express the same linear relationship
between variables. clp(Q,R) does not care to distinguish between them,
but the user might. The predicate ordering(+
Spec)
gives
you some control over the variable ordering. Suppose that instead of
B, you want Mp to be the defined variable:
clp(r) ?- mg(P,12,0.01,B,Mp). {B=1.1268250301319698*P-12.682503013196973*Mp}This is achieved with:
clp(r) ?- mg(P,12,0.01,B,Mp), ordering([Mp]). {Mp= -0.0788487886783417*B+0.08884878867834171*P}One could go one step further and require P to appear before (to the left of) B in a addition:
clp(r) ?- mg(P,12,0.01,B,Mp), ordering([Mp,P]). {Mp=0.08884878867834171*P-0.0788487886783417*B}
Spec in ordering(+
Spec)
is either a list of variables with
the intended ordering, or of the form A
<
B.
The latter form means that A goes to the left of B.
In fact,
ordering([A,B,C,D])
is shorthand for:
ordering(A < B), ordering(A < C), ordering(A < D), ordering(B < C), ordering(B < D), ordering(C < D)
The ordering specification only affects the final presentation of the
constraints. For all other operations of clp(Q,R), the ordering is immaterial.
Note that ordering/1
acts like a constraint: you can put it anywhere
in the computation, and you can submit multiple specifications.
clp(r) ?- ordering(B < Mp), mg(P,12,0.01,B,Mp). {B= -12.682503013196973*Mp+1.1268250301319698*P} yes clp(r) ?- ordering(B < Mp), mg(P,12,0.01,B,Mp), ordering(P < Mp). {P=0.8874492252651537*B+11.255077473484631*Mp}