Node:FD Set Operations, Next:A Global Constraint Example, Previous:Reflection Predicates, Up:Defining Global Constraints
The domains of variables are internally represented compactly as FD set terms. The details of this representation are subject to change and should not be relied on. Therefore, a number of operations on FD sets are provided, as such terms play an important role in the interface. The following operations are the primitive ones:
is_fdset(
+Set)
Set is a valid FD set.
empty_fdset(
?Set)
Set is the empty FD set.
fdset_parts(
?Set,
?Min,
?Max,
?Rest)
Set is an FD set which is a union of the non-empty interval
Min..Max and the FD set Rest, and all elements of
Rest are greater than Max+1.
Min and Max are both integers or the atoms inf
and sup
, denoting minus and plus infinity, respectively.
Either Set or all the other arguments must be ground.
The following operations can all be defined in terms of the primitive ones, but in most cases, a more efficient implementation is used:
empty_interval(
+Min,
+Max)
Min..Max is an empty interval.
fdset_interval(
?Set,
?Min,
?Max)
Set is an fdset which is the non-empty interval Min..Max.
fdset_singleton(
?Set,
?Elt)
Set is an FD set containing Elt only.
At least one of the arguments must be ground.
fdset_min(
+Set,
-Min)
Min is the lower bound of Set.
fdset_max(
+Set,
-Min)
Max is the upper bound of Set.
This operation is linear in the number of intervals of Set.
fdset_size(
+Set,
-Size)
Size is the cardinality of Set, represented as sup
if Set is infinite.
This operation is linear in the number of intervals of Set.
list_to_fdset(
+List,
-Set)
Set is the FD set containing the elements of List.
Slightly more efficient if List is ordered.
fdset_to_list(
+Set,
-List)
List is an ordered list of the elements of Set,
which must be finite.
range_to_fdset(
+Range,
-Set)
Set is the FD set containing the elements of the
ConstantRange (see Syntax of Indexicals) Range.
fdset_to_range(
+Set,
-Range)
Range is a constant interval, a singleton constant set, or a
union of such, denoting the same set as Set.
fdset_add_element(
+Set1,
+Elt
-Set2)
Set2 is Set1 with Elt inserted in it.
fdset_del_element(
+Set1,
+Elt,
-Set2)
Set2 is like Set1 but with Elt removed.
fdset_disjoint(
+Set1,
+Set2)
The two FD sets have no elements in common.
fdset_intersect(
+Set1,
+Set2)
The two FD sets have at least one element in common.
fdset_intersection(
+Set1,
+Set2,
-Intersection)
Intersection is the intersection between Set1 and Set2.
fdset_intersection(
+Sets,
-Intersection)
Intersection is the intersection
of all the sets in Sets.
fdset_member(
?Elt,
+Set)
is true when Elt is a member of Set.
If Elt is unbound, Set must be finite.
fdset_eq(
+Set1,
+Set2)
Is true when the two arguments represent the same set i.e. they are
identical.
fdset_subset(
+Set1,
+Set2)
Every element of Set1 appears in Set2.
fdset_subtract(
+Set1,
+Set2,
-Difference)
Difference contains all and only the elements of Set1 which
are not also in Set2.
fdset_union(
+Set1,
+Set2,
-Union)
Union is the union of Set1 and Set2.
fdset_union(
+Sets,
-Union)
Union is the union of all the sets in Sets.
fdset_complement(
+Set,
-Complement)
Complement is the complement of Set wrt. inf..sup
.