II. Notes on Data Structuring * - Cornell University
II. Notes on Data Structuring * - Cornell University
II. Notes on Data Structuring * - Cornell University
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
NOTES ON DATA STRUCTURING 123<br />
floor (see Secti<strong>on</strong> 3) is capable of indicating <strong>on</strong>e particular stop of a lift.<br />
But if we wish to record the status of the whole panel of butt<strong>on</strong>s inside a<br />
lift, it would be necessary to represent this as a subset of all possible floors<br />
in the building, namely, the subset c<strong>on</strong>sisting of those floors for which a<br />
request butt<strong>on</strong> has been depressed. Thus the type liftcall may be defined<br />
as the powerset of the floor type:<br />
type liftcall = powerset floor.<br />
A third example is provided by a hand of cards in some card game, for<br />
example, poker or bridge. A hand is a subset of playing cards, without<br />
repetiti<strong>on</strong>s, and is therefore c<strong>on</strong>veniently represented by a value from the<br />
powerset type:<br />
type hand = powerset cardface;<br />
This type covers all hands of up to fifty-two cards, even though for a<br />
particular game there may be standard size of a hand, or a limit less than<br />
fifty-two.<br />
A final example expresses the status of a computer peripheral device, for<br />
example, a paper tape reader. There are a number of excepti<strong>on</strong> c<strong>on</strong>diti<strong>on</strong>s<br />
which can arise <strong>on</strong> attempted input of a character:<br />
(1) Device switched to "manual" by operator.<br />
(2) No tape loaded.<br />
(3) Parity error <strong>on</strong> last character read.<br />
(4) Skew detected <strong>on</strong> last character read.<br />
These c<strong>on</strong>diti<strong>on</strong>s can be defined as an enumerati<strong>on</strong><br />
type excepti<strong>on</strong> = (manual, unloaded, parity, skew);<br />
and since several of these c<strong>on</strong>diti<strong>on</strong>s can be detected simultaneously, the<br />
status of the reader can be specified as a value of a powerset type:<br />
type statusword = powerset excepti<strong>on</strong>.<br />
The cardinality of the powerset type is two raised to the power of the<br />
cardinality of the base type, i.e.<br />
cardinality (powerset D) = 2 cardinality (D)<br />
This may be proved by c<strong>on</strong>sidering the number of decisi<strong>on</strong>s which have<br />
to be made to specify completely a value of the type. For each value of the<br />
base type there are two alternatives, either it is in the set or it is not. This<br />
decisi<strong>on</strong> may be made independently cardinality (D) times.<br />
7.1. MANIPULATION<br />
The basic c<strong>on</strong>structi<strong>on</strong> operati<strong>on</strong> <strong>on</strong> sets is the <strong>on</strong>e that takes a number of<br />
values from the domain type, and c<strong>on</strong>verts them into a set c<strong>on</strong>taining just<br />
i