You are on page 1of 4

CHAPTER 10

Automata, Grammars and Languages


10.1. Finite State Machines 10.1.1. Finite-State Machines. Combinatorial circuits have no memory or internal states, their output depends only on the current values of their inputs. Finite state machines on the other hand have internal states, so their output may depend not only on its current inputs but also on the past history of those inputs. A nite-state machine consists of the following: 1. 2. 3. 4. 5. 6. A nite set of states S. A nite set of input symbols I. A nite set of output symbols O. A next-state or transition function f : S I S. An output function g : S I O. An initial state S.

We represent the machine M = (S, I, O, f, g, ) Example : We describe a nite state machine with two input symbols I = {a, b} and two output symbols O = {0, 1} that accepts any string from I and outputs as many 1s as as there are at the beginning of the string, then it outputs only 0s. The internal states are S = {0 , 1 }, where 0 is the initial statewe interpret it as not having seeing any b yet; then the machine will switch to 1 as soon as the rst b arrives. The next-state and output functions are as follows: f I S 0 1 a b g a b

0 1 1 0 1 1 0 0
133

10.1. FINITE STATE MACHINES

134

This nite-state machine also can be represented with the following transition diagram :
a/1 a/0

start

b/0 @ABC @ABC / GFED / GFED 0 1 g

b/0

The vertices of the diagram are the states. If in state an input i causes the machine to output o and go to state then we draw an arrow from to labeled i/o or i, o. Example : The following example is similar to the previous one but the machine outputs 1 only after a change of input symbol, otherwise it outputs 0:
@ABC / GFED 0 BB | BB b/0 | a/0 || BB | BB || B | b/ 1 | ~ , GFED @ABC @ABC 3 GFED 1 m 2 k

start

a/0

a/1

b/0

Example : A Serial-Adder. A serial adder accepts two bits and outputs its sum. So the input set is I = {00, 01, 10, 11}. The output set is O = {0, 1}. The set of states is S = {N C, C }, which stands for no carry and carry respectively. The transition diagram is the following:
00/0 01/1 01/0 10/0

start

 11/0 , @ABC HIJK GFED / ONML NC l C r L X 00/1


10/1 11/1

10.1.2. Finite-State Automata. A nite-state automaton is similar to a nite-state machine but with no output, and with a set of states called accepting or nal states. More specically, nite-state automaton consists of: 1. A nite set of states S. 2. A nite set of input symbols I. 3. A next-state or transition function f : S I S.

10.1. FINITE STATE MACHINES

135

4. An initial state S. 5. A subset F S of accepting or nal states. We represent the automaton A = (S, I, f, , F). We say that an automaton accepts or recognizes a given string of input symbols if that strings takes the automaton from the start state to a nal state. Example : The following transition diagrams represent an automaton accepting any string of as and bs ending with an a. The rst diagram uses the same scheme as with nite-state machines, with 1 representing accept or recognize, and 0 representing not accept:
b/0 a/1

start

a/1 , @ABC @ABC GFED / GFED 0 l 1


b/0

The second kind of diagram omits the outputs and represents the accepting states with double circles:
b a

start

a , @ABC @ABC GFED 89:; ?>=< / GFED 0 l 1


b

Two nite-state automata that accept exactly the same set of strings are said to be equivalent. For instance the following automaton also accepts precisely strings of as abd bs that end with an a, so it is equivalent to the automaton shown above:
b a a

start

a , @ABC @ABC GFED 89:; ?>=< / GFED 0 l 1 Z b


b

@ABC 89:; ?>=< / GFED 2

Example : The following automaton accepts strings of as and bs with exactly an even number of as:

10.1. FINITE STATE MACHINES


b b

136

start

a + @ABC @ABC 89:; ?>=< GFED / GFED E k O


a

Example : The following automaton accepts strings starting with one a followed by any number of bs:
b a a

start

@ABC / GFED 0

@ABC 89:; ?>=< / GFED 1


b

@ABC / GFED 2 g D

Example : The following automaton accepts strings ending with aba:


b

start

@ABC / GFED 0 R

@ABC / GFED 1 F Z
a

@ABC / GFED 2 l
a

a b

, GFED @ABC 89:; ?>=<

You might also like