Automata Theory Lecture 4 and 5 Introduction To Finite State Machines
Automata Theory Lecture 4 and 5 Introduction To Finite State Machines
Finite State
Machines
The theory of computation begins with a question: What is a computer? It is
perhaps a silly question, as everyone knows that this “thing I type on” is a
computer.
We begin with the simplest model, called the finite state machine or finite
automaton.
• FINITE AUTOMATA
Finite automata are good models for computers with an extremely limited amount of
memory.
What can a computer do with such a small memory? Many useful things!
In fact, we interact with such computers all the time, as they lie at the heart of
various electromechanical devices.
The controller for an automatic door is one example of such a device. Often found at
supermarket entrances and exits, automatic doors swing open when sensing that a
person is approaching.
An automatic door has a pad in front to detect the presence of a person about to
walk through the doorway.
Another pad is located to the rear of the doorway so that the controller can hold the
door open long enough for the person to pass all the way through and also so that the
door does not strike someone standing behind it as it opens. This configuration is
shown in the following figure.
The controller is in either of two states: "OPEN"
or "CLOSED," representing the corresponding
condition of the door.
But if the input FRONT arrives, it moves to the OPEN state. In the
OPEN state, if input FRONT, REAR, or BOTH is received, it remains in
OPEN. If input NEITHER arrives, it returns to CLOSED.
• For example, a controller might start in state CLOSED and receive the series of
input signals FRONT, REAR, NEITHER, FRONT, BOTH, NEITHER, REAR, and
NEITHER.
• It then would go through the series of states CLOSED (starting), OPEN, OPEN,
CLOSED, OPEN, OPEN, CLOSED, CLOSED, and CLOSED
• This controller is a computer that has just a single bit of memory, capable of
recording which of the two states the controller is in.
• This computer might need several bits to keep track of this information.
Controllers for various household appliances such as dishwashers and electronic
thermostats, as well as parts of digital watches and calculators, are additional
examples of computers with limited memories.
• Finite automata and their probabilistic counterpart Markov chains are useful
tools when we are attempting to recognize patterns in data.
• Markov chains have even been used to model and predict price changes in
financial markets.
• Besides giving you a clearer understanding of what finite automata are and
what they can and cannot do, this theoretical development will allow you to
practice and become more comfortable with mathematical definitions,
• The figure above is called the state diagram of Ml. It has three states, labeled ql,
q2, and q3. The start state, q1, is indicated by the arrow pointing at it from
nowhere.
• The arrows going from one state to another are called transitions.
• When this automaton receives an input string such as 1101, it processes that string
and produces an output. The output is either accept or reject.
• We will consider only this yes/no type of output for now to keep things simple. The
processing begins in Ml's start state. The automaton receives the symbols from the
input string one by one from left to right. After reading each symbol, Ml moves from
one state to another along the transition that has that symbol as its label.
• When it reads the last symbol, Ml produces its output. The output is accept if Ml is
now in an accept state and reject if it is not.
• For example, when we feed the input string 1101 to the
machine M1 in Figure above, the processing proceeds as
follows.
• If you were uncertain about whether finite automata were allowed to have
0 accept states or whether they must have exactly one transition exiting
every state for each possible input symbol, you could consult the formal
definition and verify that the answer is yes in both cases.
• Second, a formal definition provides notation. Good notation helps you think
and express your thoughts clearly.
• The language of a formal definition is somewhat arcane, having some similarity to
the language of a legal document. Both need to be precise, and every detail must
be spelled out.
• It has a set of states and rules for going from one state to another, depending
on the input symbol.
• It has an input alphabet that indicates the allowed input symbols.
• It has a start state and a set of accept states.
• The formal definition says that a finite automaton is a list of those five objects:
set of states, input alphabet, rules for moving, start state, and accept states.
• If the finite automaton has an arrow from a state “x” to a state “y”
labeled with the input symbol 1, that means that, if the automaton is in
state “x” when it reads a 1, it then moves to state “y”.
• We can indicate the same thing with the transition function by saying that
δ(x, 1) = y. This notation is a kind of mathematical shorthand. Putting it
all together we arrive at the formal definition of finite automata.
• If A is the set of all strings that machine M accepts, we say that A is the
language of machine M and write L(M) = A. We say that M recognizes A or
that M accepts A.
• Because the term accept has different meanings when we refer to machines
accepting strings and machines accepting languages, we prefer the term
recognize for languages in order to avoid confusion.
• A machine may accept several strings, but it always recognizes only one
language.
Condition 2 says that the machine goes from state to state according to
the transition function.
It starts at the initial state and transit from state to state until it gets
to the final state or the accepting state
• The process continues in this way until all the input characters
have been processed.
• A finite state machine can be represented in two forms
State table
State graph (state transition diagram)
s1 s2 s1 1
S2 /1
s2 s2 s0 1 0
• Example
• Given the following
I = {1, 2}; S = {A, B, C, D}; s0 = A.
• T is given by the table:
• 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.
• We wait for the machine to read the entire input string and only
then are we interested in the answer. (Compiler construction
phases)
• In a finite state acceptor (FSA) the output is determined by
selecting a subset of states as the accepting states or final state.
• This is done by drawing a small circle for each state, with the name
of the state inside, and drawing arrows connecting the states to
depict the transitions.
• Mealy Machines:
• The output is written beside the input character for each transition
as follows:
• This indicates that if the machine is in state A and receives input “1”
then it outputs a “0” and moves to state G.
• Moore Machines:
• The output is attached to the name of the state as follows:
• FSA's:
• The accepting states are distinguished by drawing a double ring around
them as follows: