# Section 8.11.1.2:
$ENUM_SET

###### abstract class $ENUM_SET < $IS_EQ, $IMMUTABLE

#### Formal Definitions

This abstract class defines a state component which is a set of all instantiations of objects of any class sub-typing from this class in addition to the vdm model types used wherever this class name is used. Note that SAME has to be an instantiated class, not an abstract one.

types
SAME = object_type ;
$ENUM_SET = set of object_type
state
multi : $ENUM_SET
inv multi_types ==
forall obj in set multi_types & sub_type($ENUM_SET,obj)

NOTE | See the important note about vdm state in the notes on vdm-sl usage in this specification.

This abstraction models an arbitrary bit set whose size in bits is known when implementation classes sub-typing from it are instantiated.

The purpose of this abstraction is to provide a facility for manipulating externally specified 'flag' or 'option' bits in some value read from or written to an operating system or hardware device.

#### size

The number of binary digits in such a set will in general not exceed the number of bits in a machine word. This feature, however, does not have any such restriction.

size | : CARD

##### Formal Signature

size(self : SAME) res : CARD

##### Pre-condition

pre true

##### Post-condition

post res = card dom self

This feature provides the count of the number of binary digits (bits) which constitute the set.

#### size

Provided that there are no more bits in the set than will fit into a number-sized binary object, this feature provides a bit-pattern in which the bits of the set are in the least significant end of the resulting value, the remaining 'unused' bits being clearbit.

num_bits | : NUM_BITS

##### Formal Signature

num_bits(self : SAME) res : NUM_BITS

##### Pre-condition

pre size(self) <= NUM_BITS.asize

##### Post-condition

post res = self

This feature returns the set in the lowest size bits of the result - other bits being clear.

###### abstract class $ENUM_SET{T, ELEM < $ENUMS{ELEM}} < $ENUM_SET, $IS_LT{T}

#### Formal Definitions

This abstract class defines a state component which is a set of all instantiations of objects of any class sub-typing from this class in addition to the vdm model types used wherever this class name is used. Note that SAME has to be an instantiated class, not an abstract one.

types
SAME = object_type ;
$ENUM_SET_T_ELEM = set of object_type
state
multi : $ENUM_SET_T_ELEM
inv multi_types ==
forall obj in set multi_types & sub_type($ENUM_SET_T_ELEM,obj)

NOTE | See the important note about vdm state in the notes on vdm-sl usage in this specification.

This abstraction models arbitrary bit sets whose size (in bits) is determined by the element type ELEM which must be an enumeration.

#### empty

This is the sole creation routine; it returns the empty set.

empty | : T

##### Formal Signature

empty() res : T

##### Pre-condition

This is a creation routine without arguments and the pre-condition is therefore vacuously true.

##### Post-condition

post is_empty(res)

This feature returns the empty set - not void.

#### is_empty

This predicate returns true if no elements are contained in the set - ie it is the mathematical set written in vdm-sl as '{}'.

is_empty | : T

##### Formal Signature

is_empty(self : SAME) res : BOOL

##### Pre-condition

This is a predicate with self as the only (non-optional) argument; the pre-condition is therefore vacuously true.

##### Post-condition

post forall elem in set dom self & elem = clearbit

This feature returns true if and only if self is the empty set.

### Set Operations

The remaining features of this abstraction are the logical operations on sets. Except for the set membership operation (contains) they are specified in terms of the named operations which permit the use of infix notation in accordance with the following set operation equivalence -

Name | Operand | Function | Name | Operand | Function
plus | ELEM | union | plus | T | union
minus | T | difference | times | T | intersection
div | T | sym difference | is_eq | T | equality
is_leq | T | simple sub-set | is_lt | T | proper sub-set

#### plus

This variant of the plus feature is required as a useful convenience to include the argument in the set.

plus | (
| elem : ELEM
| ) : T

##### Formal Signature

plus(self : T, elem : ELEM) res : T

##### Pre-condition

There are no constraints on either the set or the element values for this operation, thus -

pre true

##### Post-condition

post contains(res, elem)

This feature includes the argument element into the set returned. It is needed in the absence of any other create operation but empty.

#### plus

This variant of the plus feature provides the mathematical set union operation.

plus | (
| other : T
| ) : T

##### Formal Signature

plus(self : T, other : T) res : T

##### Pre-condition

There are no constraints on either set for this operation, thus -

pre true

##### Post-condition

post res = self union other

This feature returns the set which is the set union of the argument and self.

#### minus

This feature provides the mathematical set difference operation.

minus | (
| other : T
| ) : T

##### Formal Signature

minus(self : T, other : T) res : T

##### Pre-condition

There are no constraints on either set for this operation, thus -

pre true

##### Post-condition

post res = self \ other

This feature returns the set which is the set difference of the argument and self.

#### times

This feature provides the mathematical set intersection operation.

times | (
| other : T
| ) : T

##### Formal Signature

times(self : T, other : T) res : T

##### Pre-condition

There are no constraints on either set for this operation, thus -

pre true

##### Post-condition

post res = self inter other

This feature returns the set which is the set intersection of the argument and self.

#### div

This feature provides the mathematical set symmetric difference operation.

div | (
| other : T
| ) : T

##### Formal Signature

div(self : T, other : T) res : T

##### Pre-condition

There are no constraints on either set for this operation, thus -

pre true

##### Post-condition

post res inter self = self
and res inter other = other

This feature returns the set which is the set symmetric difference of the argument and self.

#### contains

This predicate provides the mathematical set membership operation.

contains | (
| elem : ELEM
| ) : T

##### Formal Signature

contains(self : T, elem : ELEM) res : BOOL

##### Pre-condition

There are no constraints on either the set or the element values for this operation, thus -

pre true

##### Post-condition

post res = (elem in set self)

This feature returns true if and only if elem is in the set.

#### is_eq

This predicate provides the mathematical set equality relation.

is_eq | (
| other : T
| ) : T

##### Formal Signature

is_eq(self : T, other : T) res : BOOL

##### Pre-condition

There are no constraints on either the set or the element values for this operation, thus -

pre true

##### Post-condition

post res = (self = other)

This feature returns true if and only if the two sets contain the same elements and no others.

#### is_leq

This predicate provides the mathematical subset relation.

is_leq | (
| other : T
| ) : T

##### Formal Signature

is_leq(self : T, other : T) res : BOOL

##### Pre-condition

There are no constraints on either the set or the element values for this operation, thus -

pre true

##### Post-condition

post res = (self subset other)

This feature returns true if and only if self is a simple sub-set of other.

#### is_lt

This predicate provides the mathematical proper subset relation.

is_lt | (
| other : T
| ) : T

##### Formal Signature

is_leq(self : T, other : T) res : BOOL

##### Pre-condition

There are no constraints on either the set or the element values for this operation, thus -

pre true

##### Post-condition

post res = ((self subset other)
and not (self = other))

This feature returns true if and only if self is a proper sub-set of other.

| Language Index |  | Library Index |  | Non-numeric Index

Comments or enquiries should be made to Keith Hopper . Page last modified: Wednesday, 24 May 2000. |