Sather Home Page

Section 8.11.1.2:
$ENUM_SET

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

Inheritance map

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 set of an enumeration whose size is the cardinality of the enumeration when implementation class sub-typing from it is 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

Since the argument is not optional, this pre-condition is vacuously 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{STP, ELEM < $ENUMS{ELEM}} < $ENUM_SET, $IS_LT{STP}
$STR $FMT $ANCHORED_FMT $INSTR $IS_LT $HASH $ENUMS $ENUMSET $IS_EQ $IMMUTABLE $BINARY

Inheritance map

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_STP_ELEM = set of object_type

state

multi : $ENUM_SET_STP_ELEM
   inv multi_types ==
      forall obj in set multi_types &
         sub_type($ENUM_SET_STP_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 : STP
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 : STP
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 | 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 STP union
minus STP difference times STP intersection
div STP sym difference is_eq STP equality
is_leq STP simple sub-set is_lt STP 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
) : STP
Formal Signature
plus(self : T, elem : ELEM) res : T
Pre-condition

Since there are no constraints on either the set or the element values for this operation, this pre=condition is vacuoculy 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 : STP
) : STP
Formal Signature
plus(self : T, other : T) res : T
Pre-condition

Since there are no constraints on either set for this operation, this pre=condition os vacuously 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 : STP
) : STP
Formal Signature
minus(self : T, other : T) res : T
Pre-condition

Since there are no constraints on either set for this operation, this pre-condition is vacuously 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 : STP
) : STP
Formal Signature
times(self : T, other : T) res : T
Pre-condition

Since there are no constraints on either set for this operation, this pre=condition is vacuously 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 : STP
) : STP
Formal Signature
div(self : T, other : T) res : T
Pre-condition

Since there are no constraints on either set for this operation, this pre-condition is vacuously 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
) : STP
Formal Signature
contains(self : T, elem : ELEM) res : BOOL
Pre-condition

Since there are no constraints on either the set or the element values for this operation, this pre-condition is vacuously 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 : STP
) : STP
Formal Signature
is_eq(self : T, other : T) res : BOOL
Pre-condition

Since there are no constraints on either the set or the element values for this operation, this pre-condition is vacuously 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 : STP
) : STP
Formal Signature
is_leq(self : T, other : T) res : BOOL
Pre-condition

Since there are no constraints on either the set or the element values for this operation, this pre-condition is vacuously 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 : STP
) : STP
Formal Signature
is_lt(self : T, other : T) res : BOOL
Pre-condition

Since there are no constraints on either the set or the element values for this operation, this pre-condition is vacuously 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 toKeith Hopper.
Page last modified: Wednesday, 30 May 2001.
Produced with Amaya