II. Notes on Data Structuring * - Cornell University
II. Notes on Data Structuring * - Cornell University
II. Notes on Data Structuring * - Cornell University
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
124 c.A.R. HOARE<br />
those values as members. As in the case of the Cartesian Product, the type<br />
name is used as the transfer functi<strong>on</strong>, but for sets, the number of arguments<br />
is variable from zero upwards. For example"<br />
primary colour (red, yellow) i.e. orange<br />
liftcall (ground) i.e. <strong>on</strong>ly a single butt<strong>on</strong> has been<br />
pressed<br />
statusword ( ) i.e. no excepti<strong>on</strong> c<strong>on</strong>diti<strong>on</strong>.<br />
The last two examples illustrate the c<strong>on</strong>cept of a unit set (which must be<br />
clearly distinguished from its <strong>on</strong>ly member) and the null or empty set, which<br />
c<strong>on</strong>tains no member at all. If the type name is omitted in this c<strong>on</strong>structi<strong>on</strong>,<br />
curly brackets should be used instead of round <strong>on</strong>es in the normal way.<br />
The c<strong>on</strong>verse of the null set is the universal set, which c<strong>on</strong>tains all values<br />
from the base type. This may be denoted<br />
T. all.<br />
However, this universal set exists as a storable data value <strong>on</strong>ly when the base<br />
type is finite.<br />
The basic operati<strong>on</strong>s <strong>on</strong> sets are very familiar to mathematicians and<br />
logicians.<br />
(1) Test of membership: If x is in the set s, the Boolean expressi<strong>on</strong> "x in s"<br />
yields the value true, otherwise the value false.<br />
(2) Equality: two sets are equal if and <strong>on</strong>ly if they have the same members.<br />
(3) Intersecti<strong>on</strong>" sl ^ s2 c<strong>on</strong>tains just those values which are in both sl<br />
and s2.<br />
(4) Uni<strong>on</strong>s" sl v s2 c<strong>on</strong>tain just those values which are either in sl or s2,<br />
or both.<br />
(5) Relative complement" s 1 - s2 c<strong>on</strong>tains just those members of sl which<br />
are not in s2.<br />
(6) Test of inclusi<strong>on</strong>: s l c s2 yields the value true whenever all members<br />
of s l are also members of s2, and false otherwise.<br />
(7) The size of a set tells how many members it has.<br />
If the domain type of a set has certain operators defined up<strong>on</strong> it, it is often<br />
useful to c<strong>on</strong>struct corresp<strong>on</strong>ding operati<strong>on</strong>s <strong>on</strong> sets. In particular, if the<br />
domain type of a set is ordered, the following operators apply:<br />
(8) rain (s) the smallest member of s; undefined if s is empty.<br />
(9) x down n is a set c<strong>on</strong>taining just those values whose nth successors are<br />
in s.<br />
(10) x up n is a set c<strong>on</strong>taining just those values whose nth predecessors<br />
are in s.