![]() |
Section 8.11.2.1
|
![]() |
types SAME = BOOL ; BOOL = bool ;
This class provides the functionality of the basic Boolean logic domain. BOOL objects represent boolean values and either have the value `true' or the value `false'. The pervasive class BOOL bool defines only the three fundamental operations and, or and not. This library class defines several additional operators and conversion routines.
The following feature is required to be implemented for this class in accordance with the specification given in $IS_EQ :-
The following features are required to be implemented for this class in accordance with the specification given by inheritance in $INSTR of which $ANCHORED_FMT is a sub-type :-
The following features are required to be implemented for this class in accordance with the specifications given by inheritance in $STR of which $ANCHORED_FMT and $IMMUTABLE are both sub-types :-
The following features are required to be implemented for this class in accordance with the specifications given by inheritance in $ANCHORED_FMT :-
The following features are required to be implemented for this class in accordance with the specifications given in $BINARY of which $IMMUTABLE is a sub-type :-
This feature provides a mechanism for creating a truth value from an octet. An implementation is free to use any bit-pattern to represent the truth value, provided that it is the identical bit-pattern to that produced when the binstr feature is applied (producing a single element binary string).
create1(val : OCTET) res : SAME
Note that the selector applied to the binstr operation result is accessing the first (and only) component.
pre val = binstr(res)(1)
post card(res) = OCTET.card(val)
This routine returns the truth value corresponding to the bit-pattern in the argument val.
This final variant of the create operation creates a truth value from the encoding of a string representation in the executing environment repertoire and encoding. The 'word' to be converted is expected to be in the language of the local culture.
create3(bool_str : STR) res : SAME
pre is_bool(str)
The string method is_prefix is defined in the class STR.
post STR.is_prefix(str(res),bool_str)
This routine returns the truth value corresponding to the text string argument. The actual characters required (and their encoding) are determined by the current cultural environment.
NOTE | The internationally defined default characters for 'true' and 'false' are the digits '1' and '0' respectively in the local encoding. Most cultures will define pairs of values such as 'True/False' in English speaking cultures, 'Wahr/Falsch' in German speaking cultures, etc. |
This feature provides the standard Boolean inversion operation.
not | : SAME |
The name of the formal operation corresponding to 'not' has been modified since the word 'not' is a keyword in vdm-sl.
not_v(self : SAME) res : SAME
post res = not self
This feature returns the logical complement of self.
This feature provides the Boolean conjunction operation.
and | ( |
other : SAME | |
) : SAME |
The name of the formal operation corresponding to 'and' has been modified since the word 'and' is a keyword in vdm-sl.
and_v(self : SAME, other : SAME) res : SAME
res = (self and other)
This routine returns true if and only if self and other are both true, otherwise false.
This feature provides the Boolean union operation.
or | ( |
other : SAME | |
) : SAME |
or_v(self : SAME, other : SAME) res : SAME
post res = (self or other)
This routine returns true if and only if either self or other or both are true, otherwise false.
This feature provides the logical equality operation for Boolean values. It may be used in infix logical expressions.
is_eq | ( |
other : SAME | |
) : SAME |
is_eq(self : SAME, other : SAME) res : SAME
post res = (self >= other)
This routine returns true if and only if both self and other have the same value, otherwise false.
This feature provides the logical equality operation for a logical value which may be 'hidden' in an abstract type and self. It may be used in infix logical expressions. Note, however, that object equality will be used if the argument is not of this type.
The formal argument type is 'any object type', but an actual argument must, of course, be an instantiated object.
is_eq2(self : SAME, other : $OB) res : SAME
post res = (self = other)
This routine returns true if and only if both self and other have the same value, otherwise false. This version is provided for use where some abstract type object happens to derive from $IS_EQ. True can only be returned if the actual object is of this type.
This feature returns a validity indicator if the string contained in the argument is a valid representation of either the value true or the value false. If empty then the corresponding indication is given, otherwise an out of range indication. The string does not have to be a complete 'word', rather it must be at least as long as needed to differentiate the two values - thus, in English where "True" and "False" are the two values, then the first character alone is all that is needed. If the rest of the word is there and does not correspond to 'rue' or 'alse' then, of course, out of range is returned.
is_bool | ( |
str : STR | |
) : CONVERSION_RESULTS |
is_bool(str : STR) res : CONVERSION_RESULTS
post (res = CONVERSION_RESULTS.All_Right and (STR.is_prefix(str(true)) or STR.is_prefix(str(false)))) or (res = CONVERSION_RESULTS.Empty and STR.asize(str) = 0) or (res = CONVERSION_RESULTS.Out_of_Range)
This routine returns All_Right if str is a valid text representation of a truth value, Empty if the string was empty and Out_of_Range for any other string content.
This is the first of those routines provided to complete the possible binary operations in the logical domain. They all have their usual mathematical meaning.
xor | ( |
other : SAME | |
) : SAME |
xor(self : SAME, other : SAME) res : SAME
post res = ((self and not other) or (other and not self))
This routine returns true if and only if only one of self and other is true, otherwise false. It is identical to a not equal predicate.
xnor | ( |
other : SAME | |
) : SAME |
xnor(self : SAME, other : SAME) res : SAME
post res = ((self and other) or (not other and not self))
This routine returns true if and only if self and other have the same logical value. It is identical to the is_eq predicate.
nand | ( |
other : SAME | |
) : SAME |
nand(self : SAME, other : SAME) res : SAME
post res = not (self and other)
This routine returns the logical complement of the result of anding self and other.
nor | ( |
other : SAME | |
) : SAME |
nor(self : SAME, other : SAME) res : SAME
post res = not (self or other)
This routine returns the logical complement of the result of oring self and other.
implies | ( |
other : SAME | |
) : SAME |
implies(self : SAME, other : SAME) res : SAME
post res = (not self or other)
This routine returns if and only if self implies other. It is the same operation as nand_not.
This routine is identical to the and operation built in to the language. It is provided for possible use as a bound routine.
and_rout | ( |
other : SAME | |
) : SAME |
and_rout(self : SAME, other : SAME) res : SAME
post res = (self and other)
This routine is the same as the and operation useful when making bound routines.
This routine also corresponds to a built-in operator - or. It is provided for possible use as a bound routine.
or_rout | ( |
other : SAME | |
) : SAME |
or_rout(self : SAME, other : SAME) res : SAME
post res = (self or other)
This routine is the same as the or operation - provided for use when making bound routines.
and_not | ( |
other : SAME | |
) : SAME |
and_not(self : SAME, other : SAME) res : SAME
post res = (self
and not other)
This routine returns the result of self and the complement of other.
or_not | ( |
other : SAME | |
) : SAME |
or_not(self : SAME, other : SAME) res : SAME
post res = (self or not other)
This routine returns the result of self or the complement of other.
nand_not | ( |
other : SAME | |
) : SAME |
nand_not(self : SAME, other : SAME) res : SAME
post res = not (self and not other)
This routine returns the result of self nanded with the complement of other. It is the same as the complement of self or other.
nor_not | ( |
other : SAME | |
) : SAME |
nor_not(self : SAME, other : SAME) res : SAME
post res = not (self and other)
This routine returns the result of self nored with the complement of other. It is the same as the complement of self and other.
This operation is provided solely for backward compatibility with earlier versions of the library. It returns the value 1 when self is true and the value zero otherwise.
card(self : SAME) res : CARD
post (self and (res = 1)) or (not self and (res = 0))
This routine returns the value 1 if self is true, otherwise the value zero.
![]() |
Language Index | ![]() |
Library Index | ![]() |
Non-numeric Index |
Comments
or enquiries should be made toKeith Hopper. Page last modified: Wednesday, 4 April 2001. |
![]() |