next up previous contents
Next: Structural Induction Up: Specification of a Set Previous: Specification of a Bag

Other Atomic Constructors for Set

The specification of a set data type has a number of other interesting features which are worth exploring. Firstly, although we chose empty and add as the atomic constructors, other atomic constructors could be chosen. For example, the three constructors : form a collection of atomic constructors. The second operation takes a natural number n and produces the corresponding singleton set {n} while the third operation U is the familiar set union operation $\cup$. With this collection of atomic constructors, the mathematical set {1,5,3} is represented by the expression {1} U {5} U {3}. A sufficiently complete specification results by considering the outcomes of the operations is-in? and delete acting on these three atomic constructors. The corresponding axioms are
          is-in?(empty, n)  =  false
          is-in?({n1}, n2)  =  IF  n1 == n2  THEN  true  ELSE  false  ENDIF
        is-in?(s1 U s2, n)  =  is-in?(s1, n)  or  is-in?(s2, n)
          delete(empty, n)  =  empty
          delete({n1}, n2)  =  IF  n1 == n2  THEN  empty  ELSE  {n1}  ENDIF
        delete(s1 U s2, n)  =  delete(s1, n) U delete(s2, n)
where n, n1 $\in$ nat and s, s1, s2 $\in$ stack.

On a point of some subtlety, although this may appear at first sight to specify a set, it is unfortunately deficient with regards to the expected mathematical properties of a set in four respects !

1.
With reference to set union, the empty set ($\emptyset$) is an identity element, that is the empty set has the property :
2.
The union operation is commutative :
3.
The union operation is associative :
4.
The union operation is idempotent :
These results cannot be derived as a consequence of the six axioms given above and need to be added to the specification. The resulting specification with its eleven axioms is shown in Fig. 12.4 (version-3).


  
Figure 12.4: Algebraic specification of a set - version 3
\begin{figure}\footnotesize
\begin{tex2html_preform}\begin{verbatim}SPEC SetU...
...U s3(11) s U s = sENDSPEC\end{verbatim}\end{tex2html_preform}
\end{figure}


next up previous contents
Next: Structural Induction Up: Specification of a Set Previous: Specification of a Bag
Lee McCluskey
2002-12-18