Home Contents Index Previous Next

A.11 library( clpr ): Constraint Logic Programming over Reals

Author: Leslie De Koninck, K.U. Leuven as part of a thesis with supervisor Bart Demoen and daily advisor Tom Schrijvers.

This CLP(R) system is a port of the CLP(Q,R) system of Sicstus Prolog by Christian Holzbaur: Holzbaur C.: OFAI clp(q,r) Manual, Edition 1.3.3, Austrian Research Institute for Artificial Intelligence, Vienna, TR-95-09, 1995. (84) This port only contains the part concerning real arithmetics. This manual is roughly based on the manual of the above mentioned CLP(QR) implementation.

Please note that the library(clpr) library is not an autoload library and therefore this library must be loaded explicitely before using it:


:- use_module(library(clpr)).

A.11.1 Solver predicates

The following predicates are provided to work with constraints:

{}(+Constraints)
Adds the constraints given by Constraints to the constraint store.

entailed(+Constraint)
Succeeds if Constraint is necessarily true within the current constraint store. This means that adding the negation of the constraint to the store results in failure.

inf(+Expression, -Inf)
Computes the infimum of Expression within the current state of the constraint store and returns that infimum in Inf. This predicate does not change the constraint store.

sup(+Expression, -Sup)
Computes the supremum of Expression within the current state of the constraint store and returns that supremum in Sup. This predicate does not change the constraint store.

min(+Expression)
Minimizes Expression within the current constraint store. This is the same as computing the infimum and equation the expression to that infimum.

max(+Expression)
Maximizes Expression within the current constraint store. This is the same as computing the supremum and equating the expression to that supremum.

bb_inf(+Ints, +Expression, -Inf, -Vertex, +Eps)
Computes the infimum of Expression within the current constraint store, with the additional constraint that in that infimum, all variables in Ints have integral values. Vertex will contain the values of Ints in the infimum. Eps denotes how much a value may differ from an integer to be considered an integer. E.g. when Eps = 0.001, then X = 4.999 will be considered as an integer (5 in this case). Eps should be between 0 and 0.5.

bb_inf(+ints, +Expression, -Inf)
The same as bb_inf/5 but without returning the values of the integers and with an eps of 0.001.

dump(+Target, +Newvars, -CodedAnswer)
Returns the constraints on Target in the list CodedAnswer where all variables of Target have veen replaced by NewVars. This operation does not change the constraint store. E.g. in


dump([X,Y,Z],[x,y,z],Cons)

Cons will contain the constraints on X, Y and Z where these variables have been replaced by atoms x, y and z.

A.11.2 Syntax of the predicate arguments

The arguments of the predicates defined in the subsection above are defined in table 9. Failing to meet the syntax rules will result in an exception.

<Constraints> ::=<Constraint> single constraint
|<Constraint> , <Constraints> conjunction
|<Constraint> ; <Constraints> disjunction

<Constraint>

::=<Expression> < <Expression> less than
|<Expression> > <Expression> greater than
|<Expression> =< <Expression> less or equal
|<=(<Expression>, <Expression>)less or equal
|<Expression> >= <Expression> greater or equal
|<Expression> =\= <Expression> not equal
|<Expression> =:= <Expression> equal
|<Expression> = <Expression> equal

<Expression>

::=<Variable> Prolog variable
|<Number> Prolog number (float, integer)
|+<Expression> unary plus
|-<Expression> unary minus
|<Expression> + <Expression> addition
|<Expression> - <Expression> substraction
|<Expression> * <Expression> multiplication
|<Expression> / <Expression> division
|abs(<Expression>)absolute value
|sin(<Expression>)sine
|cos(<Expression>)cosine
|tan(<Expression>)tangent
|exp(<Expression>)exponent
|pow(<Expression>)exponent
|<Expression> ^ <Expression> exponent
|min(<Expression>, <Expression>)minimum
|max(<Expression>, <Expression>)maximum
Table 9 : CLP(R) constraint BNF

A.11.3 Use of unification

Instead of using the {}/1 predicate, you can also use the standard unification mechanism to store constraints. The following code samples are equivalent:

A.11.4 Non-linear constraints

In this version, non-linear constraints do not get solved until certain conditions are satisfied. We call these conditions the isolation axioms. They are given in table 10.

A = B * C B or C is groundA = 5 * C or A = B * 4
A and (B or C) are ground20 = 5 * C or 20 = B * 4
A = B / C C is groundA = B / 3
A and B are ground4 = 12 / C
X = min(Y,Z) Y and Z are groundX = min(4,3)
X = max(Y,Z) Y and Z are groundX = max(4,3)
X = abs(Y) Y is groundX = abs(-7)
X = pow(Y,Z) X and Y are ground8 = 2 ^ Z
X = exp(Y,Z) X and Z are ground8 = Y ^ 3
X = Y ^ Z Y and Z are groundX = 2 ^ 3
X = sin(Y) X is ground1 = sin(Y)
X = cos(Y) Y is groundX = sin(1.5707)
X = tan(Y)
Table 10 : CLP(R) isolating axioms