Author: Christian Holzbaur, ported to SWI-Prolog by Leslie De Koninck, K.U. Leuven
This CLP(Q,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.243http://www.ai.univie.ac.at/cgi-bin/tr-online?number+95-09 This manual is roughly based on the manual of the above mentioned CLP(Q,R) implementation.
The CLP(Q,R) system consists of two components: the CLP(Q) library for handling constraints over the rational numbers and the CLP(R) library for handling constraints over the real numbers (using floating point numbers as representation). Both libraries offer the same predicates (with exception of bb_inf/4 in CLP(Q) and bb_inf/5 in CLP(R)). It is allowed to use both libraries in one program, but using both CLP(Q) and CLP(R) constraints on the same variable will result in an exception.
Please note that the library(clpqr)
library is not
an
autoload library and therefore this library must be loaded
explicitly before using it:
:- use_module(library(clpq)).
or
:- use_module(library(clpr)).
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.
<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 | |
| | +<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 |
Instead of using the {}/1 predicate, you can also use the standard unification mechanism to store constraints. The following code samples are equivalent:
{X =:= Y} {X = Y} X = Y
{X =:= 5.0} {X = 5.0} X = 5.0
A = B * C | B or C is ground | A = 5 * C or A = B * 4 |
A and (B or C) are ground | 20 = 5 * C or 20 = B * 4 | |
A = B / C | C is ground | A = B / 3 |
A and B are ground | 4 = 12 / C | |
X = min(Y,Z) | Y and Z are ground | X = min(4,3) |
X = max(Y,Z) | Y and Z are ground | X = max(4,3) |
X = abs(Y) | Y is ground | X = abs(-7) |
X = pow(Y,Z) | X and Y are ground | 8 = 2 ^ Z |
X = exp(Y,Z) | X and Z are ground | 8 =
Y ^ 3 |
X = Y ^ Z | Y and Z are ground | X = 2 ^ 3 |
X = sin(Y) | X is ground | 1 = sin(Y) |
X = cos(Y) | Y is ground | X = sin(1.5707) |
X = tan(Y) |
The clpq and clpr libraries are‘orphaned', i.e., they currently have no maintainer.
?- {X+Y>=1}. {Y=1-X+_G2160, _G2160>=0}. ?-
Nonetheless, for linear constraints this kind of answer means unconditional satisfiability.
?- {X=1},dump([X],[Y],L). ERROR: Unhandled exception: Unknown message: instantiation_error(dump([1],[_G11],_G6),1) ?-