The range library does very little itself, but it provides a common basis for the interval and the MIP libraries. By contrast with the finite domain library, the range library admits ranges whose lower and upper bound are either real numbers or integers. The library enables the programmer to associate a range with one or more variables, as illustrated below.
[eclipse 1]: lib(range). * range loaded [eclipse 2]: X::0.0..9.5, lwb(X,4.5). * X = X{4.5 .. 9.5} * yes. [eclipse 3]: X::4.5..9.5, X=6.0. * X = 6.0 * yes. [eclipse 4]: X::4.5..9.5, X=1.0. * no (more) solution. [eclipse 5]: X::0.0..9.5, lwb(X,4.5), integers([X]). * X = X{5 .. 9} * yes.Example Queries Using the range Library
In query 2, the programmer enters
X::0.0..9.5, lwb(X,4.5).
,
and the system responds by printing out the resulting range.
When the variable is instantiated, the range is checked for
compatibility, as shown by queries 3 and 4.
Finally, what might be treated as type information in other programming paradigms, can be treated as a constraint in the constraint programming paradigm. Thus we can add a constraint that something is an integer in the middle of a program, as shown by query 5.