Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Алгебра_1 / Gilbert - Modern algebra with applications.pdf
Скачиваний:
34
Добавлен:
23.02.2015
Размер:
2.55 Mб
Скачать

142

7 MONOIDS AND MACHINES

FINITE-STATE MACHINES

We now look at mathematical models of sequential machines. These are machines that accept a finite set of inputs in sequential order. At any one time, the machine can be in one of a finite set of internal configurations or states. There may be a finite set of outputs. These outputs and internal states depend not only on the previous input but also on the stored information in the machine, that is, on the previous state of the machine. A pushbutton elevator is an example of such a machine. A digital computer is a very complex finite-state machine. It can be broken down into its component parts, each of which is also a machine. The RS and JK flip-flops, discussed in Exercises 2.69 and 2.70, are examples of two widely used components.

For simplicity, we only consider machines with a finite set of inputs and a finite set of states. We do not mention any outputs explicitly, because the state set can be enlarged, if necessary, to include any outputs. The states can be arranged so that a particular state always gives rise to a certain output.

A finite-state machine, (S, I, m) consists of a set of states S = {s1, s2, . . . , sn}, a set of input values I = {i1, i2, . . . , it }, and a transition function

m: I × S S,

which describes how each input value changes the states. If the machine is in state sp and an input iq is applied, the machine will change to state m(iq , sp ).

For example, consider a pushbutton elevator that travels between two levels, 1 and 2, and stops at the lower level 1 when not in use. We take the time for the elevator to travel from one level to the other to be the basic time interval, and the controlling machine can change states at the end of each interval. We allow the machine three inputs, so that I = {0, 1, 2}.

0 if no button is pressed in the preceding time interval

input =

1 if button 1 only is pressed in the preceding time interval

2 if button 2 or both buttons are pressed

in the preceding time interval.

Since the elevator is to stop at the bottom when not in use, we only consider states that end with the elevator going down. Let the set of states be

S = {stop, down, up–down, down–up–down}.

For example, in the “up–down” state, the elevator is traveling up, but must remember to come down. If no button is pressed or just button 1 is pressed while it is going up, the machine will revert to the “down” state when the elevator reaches level 2. On the other hand, if someone arrives at level 1 and presses button 2, the machine will change to the “down–up–down” state when the elevator reaches level 2.

FINITE-STATE MACHINES

143

1, 2

 

 

 

2

 

 

 

 

 

 

Up-down

 

 

 

 

Down

 

 

 

 

 

 

 

Down-up-down

 

 

 

0, 1

 

 

0, 1, 2

 

 

0

 

1, 2

 

 

 

 

 

 

Stop 0

Figure 7.3. State diagram of the elevator.

The machine can be pictured by the state diagram in Figure 7.3. If the input i causes the machine to change from state sp to state sq , we draw an arrow labeled i from sp to sq in the diagram.

As another example, consider the following machine that checks the parity of the number of 1’s fed into it. The set of states is S = {start, even, odd}, and the set of input values is I = {0, 1}. The function m: I × S S is described by Table 7.2, and the state diagram is given in Figure 7.4. If any sequence of 0’s and 1’s is fed into this machine, it will be in the even state if there is an even number of 1s in the sequence, and in an odd state otherwise.

Let I be the set of input values for any finite-state machine with state set S and function m: I × S S. Each input value defines a function from the set of states to itself, the image of any state being the subsequent state produced by the given input. Hence we have a function

m˜ : I SS ,

where SS is the set of functions from S to itself, and m(i)˜ : S S is defined by [m(i)˜ ](s) = m(i, s).

TABLE 7.2. Transition Function

of the Parity Checker

 

Next State

 

 

 

Initial

 

Input

 

 

State

0

1

 

 

 

Start

Even

Odd

Even

Even

Odd

Odd

Odd

Even

 

 

 

1

Even

0

Odd 1 0

0 1 Start

Figure 7.4. State diagram of the parity checker.

144

7 MONOIDS AND MACHINES

i1

i2

i3

ir

Machine

Figure 7.5. Input sequence being fed into a machine.

Any set of input values can be fed into the machine in sequence. The set of all such input sequences is the underlying set of the free monoid of input values, FM(I ). By Theorem 7.4, the function m˜ : I SS can be extended to a

monoid morphism

h: (FM(I ), ) (SS , Ž ),

where h(i1i2 . . . ir ) = m(i˜ 1) Ž m(i˜ 2) Ž · · · Ž m(i˜ r ). Note that the input value ir is fed into the machine first, and we can visualize this feeding of the input sequence in Figure 7.5. (The reader should be aware that many authors use the opposite convention in which the left input is fed into the machine first.)

For example, in the machine that checks the parity of the number of 1s in a sequence, the state set is S = {start, even, odd} with functions

m˜ : {0, 1} → SS and h: FM({0, 1}) SS .

The morphism h is defined by

m(˜ 0)

h(sequence) = m(˜ 1)

identity function on S

if the sequence contains an even number of 1’s

if the sequence contains an odd number of 1’s

if the sequence is empty.

QUOTIENT MONOIDS AND THE MONOID OF A MACHINE

We have seen that different input sequences may have the same effect on a machine. For example, in the machine that checks the parity of the number of 1’s in a sequence,

h(0101101) = h(0000) = h(11) = h(0);

thus the sequences 0101101, 0000, 11, and 0 cannot be distinguished by the machine.

In any machine with n states, the input sequences can have at most |SS | = nn different effects. Since there are an infinite number of sequences in FM(I ), there must always be many different input sequences that have the same effect.

The effect that an input has on a finite-state machine defines an equivalence relation on the input monoid FM(I ). The monoid of a machine will be the quotient

QUOTIENT MONOIDS AND THE MONOID OF A MACHINE

145

monoid of FM(I ) by this relation. It will always be a finite monoid with, at most, nn elements. We first define the notion of a quotient monoid.

Suppose that R is an equivalence relation on a monoid (M, ). Then R is

called a congruence relation on M if aRb implies

that (a c)R(b c) and

(c a)R(c b) for all c M. The congruence class

containing the element

a M is the set

 

[a] = {x M|xRa}.

 

Proposition 7.5. If R is a congruence relation on the monoid (M, ), the quotient set M/R = {[a]|a M} is a monoid under the operation defined by

[a] [b] = [a b].

This monoid is called the quotient monoid of M by R.

Proof. We first have to verify that the operation is well defined on congruence

classes. Suppose that [a] = [a ]

and [b] = [b ] so that aRa and bRb . Then

(a b)R(a b ) and (a b )R(a

b ). Since R is transitive, (a b)R(a b ) so

[a b] = [a b ]. This shows that is well defined on M/R. The associativity of in M/R follows from the associativity of in M. If e is the identity of M, then [e] is the identity of M/R. Hence (M/R, ) is a monoid.

Let (S, I, m) be a finite-state machine and let the effect of an input sequence

be given by

h: FM(I ) SS .

Define the relation R on FM(I ) by

αRβ if and only if h(α) = h(β).

This is easily verified to be an equivalence relation. Furthermore, it is a congruence relation on the free monoid (FM(I ), ), because if αRβ, then h(α) = h(β), and h(α γ ) = h(α) Ž h(γ ) = h(β) Ž h(γ ) = h(β γ ); thus (α γ )R(β γ ), and similarly, (γ α)R(γ β).

The quotient monoid (FM(I )/R, ) is called the monoid of the machine

(S, I, m).

We can apply the same construction to the free semigroup of input sequences to obtain the semigroup of the machine.

The monoid of a machine reflects the capability of the machine to respond to the input sequences. There are an infinite number of sequences in FM(I ), whereas the number of elements in the quotient monoid is less than or equal to nn. Two sequences are in the same congruence class if and only if they have the same effect on the machine.

A morphism theorem for monoids can be proved in a similar way to the morphism theorem for groups (Theorem 4.25; see Exercise 7.24). Applying this

146

7 MONOIDS AND MACHINES

to the monoid morphism h: FM(I ) SS , it follows that the quotient monoid FM(I )/R is isomorphic to Im h. This isomorphism assigns to each congruence class a unique transition between states.

Example 7.6. Draw the state diagram and find the monoid of the following machine (S, I, m). The machine has two states, s0 and s1, and two input symbols, 0 and 1. The effects of the input symbols are given by the functions h(0), h(1): S S, defined in Table 7.3.

Solution. Let us calculate the effect of inputs of length 2. We have h(ij ) = h(i) Ž h(j ), where j is fed into the machine first. It follows from Tables 7.3 and 7.4 that h(00) = h(01) = h(0) and [00] = [01] = [0] in the monoid of the machine. There are only four functions from {s0, s1} to {s0, s1}, and these are h(0), h(1), h(10), and h(11). Hence the monoid of the machine consists of the four congruence classes [0], [1], [10], and [11]. The table of this quotient monoid is given in Table 7.5, and the state diagram is given in Figure 7.6. For example,

 

 

 

 

TABLE 7.3

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Initial

 

Next State

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

State

 

h(0)

h(1)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

s0

 

s0

s1

 

 

 

 

 

s1

 

s0

s0

 

TABLE 7.4

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Initial

 

 

 

 

 

 

End State

 

 

 

 

 

 

 

 

 

 

 

 

State

 

h(00)

h(01)

h(10)

h(11)

 

 

 

 

 

 

 

 

 

 

 

 

s0

 

 

s0

s0

 

s1

s0

s1

 

 

s0

s0

 

s1

s1

TABLE 7.5. Monoid of the Machine

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

[0]

 

 

 

[1]

[10]

[11]

 

 

 

 

 

 

 

 

 

 

 

 

[0]

 

 

[0]

 

 

 

[0]

[0]

[0]

[1]

 

 

[10]

 

 

 

[11]

[0]

[1]

[10]

 

 

[10]

 

 

 

[10]

[10]

[10]

[11]

 

 

[0]

 

 

 

[1]

[10]

[11]

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1

 

 

 

 

s1

 

 

 

 

s0

 

 

 

 

 

 

0

 

 

 

 

 

 

0, 1

 

 

 

 

 

 

Figure 7.6.

State diagram.

 

QUOTIENT MONOIDS AND THE MONOID OF A MACHINE

147

[1] [10] = [110]. Since h(110)(s0) = s0 and h(110)(s1) = s0, it follows

that

[110] = [0]. Notice that [11] is the identity; thus, in the monoid of the machine, [ ] = [11].

Example 7.7. Describe the monoid of the machine ({start, even, odd}, {0, 1}, m) that determines the parity of the number of 1’s in the input.

Solution. We have already seen that any input sequence with an even number of 1’s has the same effect as 0 and that any sequence with an odd number of 1’s has the same effect as 1. It follows from Table 7.6 that the monoid of the machine contains the three elements [ ], [0], and [1]. The table for this monoid is given in Table 7.7.

Finite-state machines can easily be designed to recognize certain types of input sequences. For example, most numbers inside a computer are in binary form and have a check digit attached to them so that there is always an even number of 1’s in each sequence. This is used to detect any machine errors (see Chapter 14). A finite-state machine like Example 7.7 can be used to perform a parity check on all the sequences of numbers in the computer. The machine can be designed to signal a parity check error whenever it ends in the “odd” state.

Let us now look at a machine that will recognize the pattern 010 in any binary input sequence that is fed into the machine. Figure 7.7 is the state diagram of such a machine. If the machine is initiated in state s1, it will be in state s4 if and only if the preceding inputs were 010, and in this case, the machine sends an output signal.

This machine has four states; thus the total possible number of different functions between states is 44 = 256. Table 7.8 shows that the input sequences of length 0, 1, and 2 all have different effects on the various states. However, seven of the eight sequences of length 3 have the same effect as sequences of length

TABLE 7.6

Initial

 

Next State

 

 

 

 

State

h( )

h(0)

h(1)

 

 

 

 

 

Start

Start

Even

Odd

Even

Even

Even

Odd

Odd

Odd

Odd

Even

 

 

 

TABLE 7.7. Monoid of the Parity Checker Machine

 

 

 

 

 

 

 

[ ]

[0]

[1]

 

 

 

 

 

[ ]

 

[ ]

[0]

[1]

[0]

 

[0]

[0]

[1]

[1]

 

[1]

[1]

[0]

 

 

 

 

 

148

 

 

7 MONOIDS AND MACHINES

1

0

1

1

1

0

Sends an

0

s1

s2

s3

s4 output signal

 

 

 

0

Figure 7.7. State diagram of a machine that recognizes the sequence 010.

TABLE 7.8. Effects of the Input Sequences on the States of the Machine

Initial

 

 

 

 

 

 

 

 

End State

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

State

0

1 00 01 10 11

 

000 001 010 011 100 101 110 111 0010 1010

 

 

 

 

 

 

 

 

 

 

 

 

 

 

s1

s1

s2 s1 s2 s2 s3 s1

 

s2

s2

s4

s2

s3

s3

s1

s1

s2

s3

s2

s2

s2

s3

s2

s4

s3 s1

 

s2

s2

s4

s2

s3

s3

s1

s1

s2

s3

s3

s3

s4

s1

s2

s2

s3 s1

 

s2

s2

s4

s2

s3

s3

s1

s1

s2

s3

s4

s4

s2

s3

s2

s4

s3 s1

 

s2

s2

s4

s2

s3

s3

s1

s1

s2

s3

 

 

 

 

0010

1010

 

 

 

 

 

 

 

 

 

 

 

000

100

010

110

 

001

 

101

 

011

 

111

 

 

 

 

00

 

 

 

10

 

 

01

 

 

 

11

 

 

 

 

 

 

 

 

0

 

 

 

 

 

 

1

 

 

 

 

Λ

Figure 7.8. Tree diagram of input sequences.

2. The only input sequence with a different effect is 010, the sequence that the machine is designed to recognize. Therefore, the only sequences of length 4 that we check are those whose initial inputs are 010, namely, 0010 and 1010.

We can use the tree diagram in Figure 7.8 to check that we have covered all the possible transition functions obtainable by any input sequence. We label the nodes of the tree by input sequences. At any node α, there will be two upward branches ending in the nodes 0 α and 1 α, corresponding to the two input symbols. We prune the tree at node α, if α gives rise to the same transition function as another