4.4.1
Examples of Algebras for Basic Data Types
Let us illustrate the new definition and notations for algebras by interpreting some of the signatures for the Booleans and numbers given in Section 4.2 Our examples will be displayed rather than presented as tuples.
Booleans Given the signature ΣBooleans for a standard set of Boolean operations, first we
apply the general notation for interpreting ΣBooleans. An arbitrary ΣBooleans-algebra has the
form:
algebra A carriers ABool
constants trueA,falseA
: →ABool
operations andA : ABool ×ABool →ABool
notA: A
Bool →ABool
The standard interpretation of the Booleans is based on the set B={tt,ff}
4.4. EXAMPLES OF ALGEBRAS 97 algebra AStandard carriers B constants tt,ff : →B operations ∧: B×B→B ¬: B→B
Since tt,ff ∈B, and ∧ and ¬are functions on B, we do not have need of superscriptsB etc. Integers We introduced a signature IntegersInfix for an algebra of integers using a prefix notation for addition, subtraction and multiplication. Here is the general form of aIntegersInfix- algebra using the general notation:
algebra A carriers Aint
constants zeroA,oneA :
→Aint
operations addA: Aint×Aint →Aint
minusA: A
int →Aint
timesA : A
int×Aint →Aint
We also introduced a signatureIntegers for the integers that uses the standard infix notation for addition, subtraction and multiplication. The standard form of a Integers-algebra is based on the set
Z={. . . ,−2,−1,0,1,2, . . . ,}
of integers in decimal notation. In the standard case, we need not drop the reference to Z on the operators of the signature, say by writing + for +Z.
algebra A carriers Z constants 0,1 : →Z operations +Z : Z×Z→Z −Z : Z→Z .Z : Z ×Z→Z
Reals Here is a ΣReals-algebra of real numbers containing some infix and some postfix nota-
algebra Reals carriers R,B constants 0R: →R 1R: →R πR : →R trueR,falseR : →B operations +R : R×R→R −R : R→R .R : R×R→R −1R : R→R √ R: R →R | |R: R→R sinR : R →R cosR : R→R tanR: R→R expR : R →R logR : R →R =R: R×R→B <R: R×R→B andR : B×B→B notR: B→B
In many situations we might drop the superscript and subscript reference to R providing there could be no confusion as to which functions on reals were intended.
4.4.2
Storage Media
Thinking abstractly, an implementation of a storage medium is simply an algebra of signature ΣStorage which, using the general notation for interpreting signatures, has the form:
algebra A
carriers Astore,Aaddress,Adata
constants emptyA: →A store
operations inA: A
data ×Aaddress×Astore →Astore
outA: A
address ×Astore →Adata
4.4. EXAMPLES OF ALGEBRAS 99
algebra A
carriers Store,Address,Data constants emptyA : →Store
operations inA: Data
×Address×Store →Store outA: Address
×Store →Data
4.4.3
Machines
Thinking abstractly, an implementation of a machine is simply an algebra of signatureΣMachine.
Using a suggestive notation for the carriers, a typical machine is an algebra of the form: algebra A
carriers State,Input,Output constants initialA : →State
operations nextA: State×Input →State
writeA: State
×Input →Output
If the set State is a finite set thenA is called a finite state machine.
4.4.4
Sets
Using the signature ΣSubsets-algebra of Section 4.2.2 any ΣSubsets-algebra A using the general
notation can be displayed in the following form: algebra A carriers Asubset constants emptyA : →A subset universeA: →Asubset operations unionA: A
subset ×Asubset →Asubset
intersectionA: A
subset ×Asubset →Asubset
complementA: Asubset →Asubset.
The intended interpretation is an algebra Ain which
(i) the carrier set Asubset is the power set P(X) of a non-empty set X, i.e., the set of all
subsets of the set X; (ii) the constants are
emptyA=∅,the empty set; universeA=X,the given set X;
(iii) the operations are defined for any V,W ∈ P(X) by unionA(V,W) =V ∪W; intersetA(V,W) =V ∩W; complementA(V) =X −V This gives us the algebra:
algebra A carriers Asubset =P(X) constants ∅: → P(X) X : → P(X) operations ∪ : P(X)× P(X)→ P(X) ∩ : P(X)× P(X)→ P(X) − : P(X)→ P(X)
4.4.5
Strings
Using the signatureStringsfrom Section4.2.3and applying our general mathematical notation, any ΣBasic Strings with Length-algebra Awill have the following mathematical form:
algebra A
carriers Aalphabet,Astring,Anat
constants emptyA: →A string
zeroA : →A nat
operations prefixA : Aalphabet ×Astring →Astring
lengthA : Astring →Anat
However, when we interpret ΣBasic Strings with Length, we will actually have an algebra of strings
of the form defined in Section 3.7.2, where (i) the carrier sets
Aalphabet =T, Astring =T∗, and Anat =N;
(ii) the constants
emptyA=², zeroA=0;
and
(iii) the operations
emptyA=², prefixA
=Prefix, lengthA=| |, and succA = +1.
4.5. ALGEBRAS WITH BOOLEANS AND FLAGS 101