Previous Up Next

5.2  Set Variables

5.2.1  Declaring

Set variables are variables which can eventually take a ground integer set as their value. They are characterized by a lower bound (the set of elements that are definitely in the set) and an upper bound (the set of elements that may be in the set). A set variable can be declared as follows:

        SetVar :: []..[1,2,3,4,5,6,7]

If the lower bound is the empty set (like in this case) this can be written as

        SetVar subset [1,2,3,4,5,6,7]

If the lower bound is the empty set and the upper bound is a set of consecutive integers, one can also declare it like

        intset(SetVar, 1, 7)

which is equivalent to the above.

The predicates to declare sets are:

?Set :: ++Lwb..++Upb
Set is an integer set within the given bounds
intset(?Set, +Min, +Max)
Set is a set containing numbers between Min and Max
intsets(?Sets, ?N, +Min, +Max)
Sets is a list of N sets containing numbers between Min and Max

5.2.2  Printing

Set variables are by default printed in a particular way, e.g.

?- X :: [2,3]..[1,2,3,4], write(X).
X{[2, 3] \/ ([] .. [1, 4]) : _308{[2 .. 4]}}

The curly brackets contain

  1. the lower bound of the set
  2. the union symbol
  3. the set of optional values (that may or may not be in the set)
  4. a colon
  5. a finite domain indicating the admissible cardinality for the set

5.2.3  Domain Access

potential_members(?Set, -List)
List is the list of elements of whose membership in Set is currently uncertain
set_range(?Set, -Lwb, -Upb)
Lwb and Upb are the current lower and upper bounds on Set

Previous Up Next