0% found this document useful (0 votes)
46 views10 pages

Introduction To Finite State Machines: 4.1. Cyclops, The Simplest Possible Computer

This document introduces finite state machines as a model of computation. It begins by describing the simplest possible computer, called Cyclops, which has one input key, one bit of memory/output displayed as a light bulb, and a fixed program. This demonstrates a basic 1-input, 2-state computer. The document then provides a more formal definition of a finite state machine as having an input alphabet, set of states, transition function, and initial state. An example 2-input, 4-state machine is given to model operating an amusement park ride. Finally, the document notes that finite state machines can be implemented electronically and that computers themselves operate as finite state machines.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views10 pages

Introduction To Finite State Machines: 4.1. Cyclops, The Simplest Possible Computer

This document introduces finite state machines as a model of computation. It begins by describing the simplest possible computer, called Cyclops, which has one input key, one bit of memory/output displayed as a light bulb, and a fixed program. This demonstrates a basic 1-input, 2-state computer. The document then provides a more formal definition of a finite state machine as having an input alphabet, set of states, transition function, and initial state. An example 2-input, 4-state machine is given to model operating an amusement park ride. Finally, the document notes that finite state machines can be implemented electronically and that computers themselves operate as finite state machines.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

67

4. INTRODUCTION TO
FINITE STATE MACHINES
§4.1. Cyclops, The Simplest Possible Computer
We now begin our study of the Theory of Computation. Here we are not interested in
the latest software or hardware, knowledge that changes by the month and which becomes
obsolete after only a few years. Instead we are going to ask some rather deep questions about
the nature of computation. While it is clear that this should be valuable background
knowledge for the professional computer scientist, it should be pointed out that it also has
relevance for the student of mathematics. After all, a large part of mathematics involves
computation, and algorithms – procedures for computing something – have been around for
thousands of years.
Questions about the fundamental nature of computation were asked, not by computer
scientists, but by mathematicians and when such questions began to be asked (in the first half
of the 20th century) there were no such people as computer scientists and no such machines as
computers. Indeed it was the pioneering work of mathematicians such as Alan Turing that
helped to give birth to the computer.
Now a modern computer is an exceedingly complicated machine. In order to
understand its essential nature we must strip away all this complexity and consider the
simplest possible computer. We shall call this simplest-of-all-possible-computers, “Cyclops”.
[Cyclops was the name given to a character from Greek mythology with only one eye, placed
in the middle of his forehead. You will see shortly why this name is quite appropriate for this
most primitive machine.]
There are four essential features of any computing device:
* a mechanism for input
* a mechanism for output
* memory
* programs.
Input can come through a variety of devices such as CD-ROMs or broadband
modems, but the most familiar input device is the keyboard. We will provide Cyclops with a
keyboard with just one key with the numeral “1” engraved on it. So a typical input to
Cyclops can only be a string of 1's, such as11111. This means that we cannot use binary
notation for numbers. Instead, to input the number n we will have to press the “1” key n
times.
Output can also come through a variety of channels, but probably the most familiar is
the video display unit, or computer screen. Our simplest-of-all possible computers will have
to have a monochrome display. On a typical LCD screen there are many thousands of tiny
“pixels” – points that can be either on or off (lit or dark). Cyclops will have to be content
with just a single pixel screen – or equivalently, a single light bulb which can either be ON or
OFF.
In all computers a part of the RAM (random access memory) is devoted to providing
the screen output. (In the early days of home computers when there was very limited memory
programmers were forced to make use of this memory for their calculations and so while the
program was running all sorts of “garbage” would appear on the screen until the final output
was displayed. Today memory is measured in gigabytes and each gigabyte consists of a very
large number of tiny units of memory called “bits”. One bit is the amount of memory
68
contained in a light switch that “remembers” whether it is ON or OFF. In order to create the
simplest-of-all-possible-computers we will insist that the single light bulb that Cyclops has
for its display has to double up as a one bit memory.
Finally there is the program. Normally computers use part of their memory to store a
program, but this is a bit much to ask of our single-bit midget! Instead we will “hard-wire”
the program into Cyclops in much the same way that there is a program hard-wired into the
micro-processor that controls an automatic washing machine. This means, of course, that
unless we re-wire him, Cyclops will be a single program computer. So our minimal computer
is a one bit, single program machine with just one key and a single light-bulb as the display!
At any given stage the light bulb is either on or off. As the keys are pressed, the
program will determine whether the bulb should be on or off. Since our intention is to make
Cyclops a deterministic machine, the decisions made by the program must be determined
solely by two things – which key has been pressed and what state the machine is currently in.
The decision rule can be set out in a table of the following form:
Each of these two cells needs to contain the name of the next state into which the
machine goes, that is each is either an “ON” or an “OFF”.
Since there are two possibilities for each cell there are 4 combinations altogether.
Each of these can be thought of as a program that can be hard-wired into Cyclops. Here is
one such program.
Example 1:
When the light is OFF a key-press will turn it ON. When it is ON, pressing the key
turns it OFF. This program will cause Cyclops to repeatedly switch the output bulb on and
off every time the “1” key is pressed.
This very simple computer, running this very simple program, is in fact actually
manufactured, though not as a computing device. Rather it's a toggle light switch such as you
get on many desk lamps. Push the button, and if the light is OFF it then goes ON. Push it
again and the light goes OFF. Many years ago such switches were connected to long cords
from the ceiling and each time you pulled on the cord the ceiling light would change its state.
Now you may never have thought of such a mechanism as a primitive computer, but it
can in fact compute. We can use it to compute whether a given number n is odd or even by
examining the effect of n pushes of the key. We first reset the machine by switching the light
off. Then we push the button n times. If, when we've finished, the light is ON, then n is odd.
If it ends up being OFF, the number is even.
Altogether there are 4 different “programs” that Cyclops can be given. One was given
in Example 1. The other three are:
1
OFF
ON
1
OFF ON
ON OFF
1
OFF ON
ON
ON
1
OFF OFF
ON
ON
1
OFF OFF
ON OFF

69
These three are not nearly so useful as the light-switch model. In the first one the
input has no effect whatsoever, just as if the key was a dummy one – not connected to
anything. The other two can change the state, but the effect can’t be reversed. The buttons
on a lift work like this last one. Once they’re ON they can’t be switched off (until they are
reset when you reach the required floor).
So we have learnt all there is to know about 1-input 2-state machines, which is not
much! So let us generalise Cyclops to a machine with m input keys and n states.
§4.2. Finite State Machines
A finite state machine consists of the following:
(1) a set I called the input alphabet;
(2) a set S whose elements are calledst at es;
(3) a function T:S× I→ S called the transition function;
(4) a particular element, s0∈ S called the initial state;
The functioning of the machine is as follows:
The machine starts in the initial state s0. The input is a string of characters from the input
alphabet which are read one at a time (from the left). At each stage the machine is in some
state s∈ S. If the machine is in state s, and the next input character is c∈ I, the machine
moves to state T(s, c) and awaits the next input character. The process continues in this way
until all the input characters have been processed.
Example 2:
I = {1, 2}; S = {A, B, C, D}; s0 = A.
T is given by the table:
Suppose the input to this machine is 1121221121. The successive transitions of the machine
are:
1
1
2
1
2
2
1
1
2
1
A→ B→ C→ A→ B→ D→ C→ D→ A→ C→D
Although we described it abstractly, this particular machine can have a very familiar
interpretation. Imagine that you are the operator of an amusement park ride and you have to
fill four-seater cars from a succession of couples and single customers.
Your instructions are to wait until the car is full before letting it go. However if a
couple arrives, rather than splitting them, you let the car go with just 3 passengers and put the
couple in the next one.
The input consists of the customers who arrive in 1's and 2's. The four states, A to D,
correspond to the four possible situations you can have with the current car. State A is
where you have a completely empty car and states B, C and D are where there are one, two
or three passengers waiting in the car. Examine the state table to see that you agree that it
accurately describes the situation.
1
2
→AB
C
B
C
D
C
D
A
D
A
C

70
Both examples 1 and 2 serve some other purpose than computation. The fact that a
light switch can distinguish between odd and even numbers is not the purpose for which it
was made, and the operator of the ghost train ride certainly doesn't see himself as a cog in
some giant, but rather feeble, computer.
In what follows we shall concentrate on finite state machines as devices to perform
some sort of computation. The physical nature of the states won’t concern us, only the
abstract movement from state to state.
In practice, finite state machines are implemented electronically in one of two ways.
We can build an electronic chip, incorporating the logic of the machine. This is done where
the machine is part of a piece of equipment that is designed to react to external input in some
definite way. Or we can incorporate the finite state machine within some computer program,
where the computer simulates to machine.
In fact a computer itself is a finite state machine. The set of states is the set of all
possible combinations of bits of internal memory. This is huge, but finite.
§4.3. Mealy Machines
To be of any use in computation a finite state machine must have some form of output.
There are several ways we can provide that output. An obvious way is to have the machine
print it (on a screen, or on paper, or perhaps as a sequence of tones). We need an output
alphabet, O, that may or may not be the same as the input alphabet. Every time the machine
reads a character from the input, it outputs a character as well as changing its state.
To describe the output of such a machine we can have an additional function that
assigns to each combination of state and input character, an output character. In other words
we have a function P: S× I→ O. When the machine is in state s and reads the character c,
the output is P(s, c).
A machine of this type is known as a Mealy Machine. We can describe a Mealy
machine by a pair of tables. The state table provides the new state, for each combination of
state and character and the output table provides the character that is output at each stage.
The initial state is indicated by putting a short arrow in front of that state in the left-hand
column.
Example 3:The following Mealy machine echoes the input after a two step delay. The first
two output characters are both 0's. Thereafter the output at each stage is the input from two
steps earlier. The last two input characters are ignored.
I = O = {0, 1}; S = {A, B, C, D} with s0 = A.
The meaning of these states will be as follows:
A means next two output characters are to be 0, 0
B means next two output characters are to be 0, 1
C means next two output characters are to be 1, 0
D means next two output characters are to be 1, 1
Giving an interpretation to the states is not a part of the description of the machine.
One can “operate” the machine mindlessly without such knowledge. However when
designing finite state machines, and understanding their function, it is quite important to be
able to attach a meaning to each state.
The transition and output tables for this machine are as follows (we indicate the fact
that A is the initial state by putting an arrow in front of it):
State Table
Output Table
71
0
1
0
1



→A
A
B
0
0
B
C
D
0
0
C
A
B
1
1
D
C
D
1
1
So if the input is 111001111 the output will be 001110011 as shown below:
input
1
1
1
0
0
1
1
1
1
states
A→ B→ D→ D→ C→ A→ B→ D→ D→ D









output
0
0
1
1
1
0
0
1
1
The effect is to print two initial 0's and then to repeat the input with a two-step delay.
Of course because the output has the same length as the input the last two input characters
will be ignored.
§4.4. Moore Machines
An alternative arrangement for output is to have the machine print a certain output
character as it enters a state. These machines are called Moore machines. The output is
attached to the states rather than to the transitions.
Formally, the output of a Moore machine is described by a function P: S→ O, where
as before, O is the output alphabet.
Example 4:
The following Moore machine is also a two-step delay machine, behaving equivalently to the
Mealy machine in example 3.
I = O ={0, 1}; S = {A, B, C, D} with s0 = A.
T
P
INTERPRETATION
0
1
last 3 inputs



→A
A
B
0
0 0 0
B
C
D
0
0 0 1
C
E
F
0
0 1 0
D
G
H
0
0 1 1
E
A
B
1
1 0 0
F
C
D
1
1 0 1
G
E
F
1
1 1 0
H
G
H
1
1 1 1
Using the same input string as before we get the same output. The only difference is
that the output responds only to the state being entered.
input
1
1
1
0
0
1
1
1
1
states
A→ B→ D→ H→ G→ E→ B→ D→ H→ H









output
0
0
1
1
1
0
0
1
1

You might also like