You are on page 1of 18

CSC3113

Theory Of Computation

Finite Automaton
Computational Model
Finite State Machine

Formal Definition

Designing

Regular operations
Mashiour Rahman
Assistant Professor
Computer Science Department
American International University-Bangladesh

Finite Automata
We will use several different models, depending on
the features we want to focus on. Begin with the
simplest model, called the finite automaton.
Good models for computer with an extremely limited
amount of memory. For example, various household
appliances such as dishwashers and electronic
thermostats, as well as parts of digital watches and
calculators.
The design of such devices requires keeping the
methodology and terminology of finite automata in
mind.
Next we will analyze an example to get an idea.
CSC3113 Theory Of Computation

Mashiour Rahman

Finite Automaton 2

An Example
Front
pad

Rear
pad

Figure: Top view of an automatic door

REAR
BOTH
NEITHER

REAR
BOTH
FRONT
FRONT

CLOSED

OPEN

Figure: State diagram for Automatic door controller


Input Signal
NEITHER

FRONT

REAR

BOTH

CLOSED

CLOSED

OPEN

CLOSED

CLOSED

OPEN

CLOSED

OPEN

OPEN

OPEN

Figure: State Transition table for automatic door controller


CSC3113 Theory Of Computation

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

NEITHER

State

Automatic doors swing open


when sensing that a person is
approaching.

Mashiour Rahman

The controller can hold the


door long enough for the
person to pass all the way
through.
The door does not strike
someone standing behind it
as it opens.
Finite Automaton 3

Simulation
Input Example:
Initial State: CLOSED
Input Signal Sequence: FRONT, REAR, NEITHER, FRONT, BOTH, NEITHER,
REAR, NEITHER.
Present State:

CLOSED
OPEN

Input Signal:

NEITHER
FRONT
REAR
BOTH

REAR
BOTH
NEITHER

REAR
BOTH
FRONT
FRONT

Front
pad

Rear
pad

CLOSED

OPEN
NEITHER

Figure: Top view of an automatic door


CSC3113 Theory Of Computation

Figure: State diagram for Automatic door controller

Mashiour Rahman

Finite Automaton 4

Definition & Terminology


We will go through
a precise definition of a finite automaton,
terminology for describing and manipulating
finite automata,
theoretical results that describe their powers
and limitations.

Let us now look into the terminology through


an example.
CSC3113 Theory Of Computation

Mashiour Rahman

Finite Automaton 5

Terminology

q1

q2

q3
0,1

Figure: A finite automaton called M1 that has three states.

The above figure is called state diagram of M1.


It has three states, labeled q1, q2, and q3.
The start state is q1, indicated by the arrow pointing at it from no where.
The accept state, q2, is the one with a double circle.
The arrow going from one state from another are called transitions.
The symbol(s) along the transition is called label.
M1 works as follows
The automaton receives the symbols from the input string one by one from left to right.
After reading each symbol, M1 moves from one state to another along the transition
that has the symbol as its label.
When it reads the last symbol, M1 produces the output.
The output is ACCEPT if M1 is now in an accept state and REJECT if it is not.
CSC3113 Theory Of Computation

Mashiour Rahman

Finite Automaton 6

Simulation

q1

1101

1101
Figure: Finite Automaton M1.

q13

01
101
0,1

After feeding the input string 1101 to the above machine, the
processing proceeds as follows
Start in state q1;
Read 1, follow transition from q1 to q2;
Read 1, follow transition from q2 to q2;
Read 0, follow transition from q2 to q3;
Read 1, follow transition from q3 to q2;
Accept, as the machine M1 is in an accept state q2 at the end of
the input string.
CSC3113 Theory Of Computation

Mashiour Rahman

Finite Automaton 7

Formal Definition
A finite automaton is a 5-tuple (Q, , , q0, F), where
Q is a finite set called the states,
is a finite set called the alphabet,

: Q Q is the transition function,


q0 Q is the start state,
F Q is the set of accept (final) states.

If A is the set of all strings that a machine M accepts,


we say that A is the language of machine M and
write L(M)=A, M recognizes A or M accepts A.
CSC3113 Theory Of Computation

Mashiour Rahman

Finite Automaton 8

Example
0

q1
M1 = (Q, , , q0, F), where
Q = {q1, q2, q3},

q2

q3
0,1

Figure: Finite Automaton M1

= {0, 1},

is describe as
0 1
q1 q1 q2
q2 q3 q2
q3 q2 q2

or

(q1,0) = q1, (q1,1) = q2,


(q2,0) = q3, (q2,1) = q2,
(q3,0) = q2, (q3,1) = q2.

q 0 = q 1,
F = {q2}.
CSC3113 Theory Of Computation

Mashiour Rahman

Finite Automaton 9

Formal Definition of Computation


Now we formalize the finite automatons
computation, mathematically.
Let,
M = (Q, , , q0, F) be a finite automaton,
w = w1w2wn be a string over the alphabet ,

Then M accepts w if a sequence of states r0,r1,,rn


exists in Q with the following three conditions
r0=q0,

(ri, wi+1) = ri+1, for i = 0, 1, 2, , n-1, and


rn F.

M recognizes language L if L = {w : M accepts w}.


CSC3113 Theory Of Computation

Mashiour Rahman

Finite Automaton 10

Example

a1

Language A1 = {w : the sum of all the symbols in w is


multiple of 3 }.

2
1
0

Can be represented as follows

a0

Alphabet ={0,1,2}.

2
1

S= the sum of all the symbols in w.

a2
0

Input example: 01120101


Present State:

a201
Input symbol:
01120101

Accepted
CSC3113 Theory Of Computation

If S modulo 3 = 0 then the sum is multiple of 3.


So the sum of all the symbols in w is 0 modulo 3.
Here, ai is modeled as S modulo 3 = i.

The finite state machine M1= (Q1, , 1, q1, F1), where

Q1 = {a0,a1,a2},
q1 = a0,
F1 = {a0},

1
a0
a1
a2

|
|
|
|

Mashiour Rahman

0
a0
a1
a2

1
a1
a2
a0

2 .
a2
a0
a1
Finite Automaton 11

Example
0,2

b0

1
1

b1
0,2

Alphabet ={0,1,2}.
Language A1 = {w : the sum of all the symbols
in w is an even number }.
Can be represented as follows
S= the sum of all the symbols in w.
If S modulo 2 = 0 then the sum is even.
Here, bi is modeled as S modulo 2 = i.

Input example: 01120101


Present State:

b10
Input symbol:
01120101

Accepted
CSC3113 Theory Of Computation

The finite state machine M2= (Q2, , 2, q2, F2),


where
Q2 = {b0,b1},
q2 = b0,
F2 = {b0},

2
b0
b1

|
|
|

Mashiour Rahman

0
b0
b1

1
b1
b0

2 .
b0
b1
Finite Automaton 12

Regular Language
A language is called a regular language if some finite
automaton recognizes it.
Regular Operations: Let A={good, bad}, B = {boy, girl}.
Basic three operations used to study the properties of the regular
languages
Union: AB = {x : x A or x B} = {good, bad, boy, girl}.
Takes all the strings in both A and B and lumps them together into
one language.

Concatenation: A B = {xy : x A and y B} = {goodboy,


goodgirl, badboy, badgirl}.
Attaches a string from A in front of a string B in all possible ways to
get the strings in the new language.

Star: A* = {x1x2xk : k 0 and each xi A} = {, good, bad,


goodgood, goodbad, badgood, badbad, goodgoodgood,
goodgoodbad, }.
Attaching any number of strings in A together to get a string in the
new language. It is an unary operation, where is always a
member of A* (as any number also includes 0).
CSC3113 Theory Of Computation

Mashiour Rahman

Finite Automaton 13

Closure
A collection of objects is closed under some
operation, if applying that operation to the
members of the collection returns an object
still in the collection.
Theorem: Collection of regular languages is
closed under all three of the regular
operations.
Next, we will prove it for Union operation.

CSC3113 Theory Of Computation

Mashiour Rahman

Finite Automaton 14

Regular Language closed under Union


We will prove it by construction.
Let M1 recognize A1, where M1= (Q1, , 1, q1, F1), and M2 recognize A2,
where M2= (Q2, , 2, q2, F2).
Construct M to recognize A1 A2, where M= (Q, , , q0, F).
Q = {(r1, r2) : r1 Q1 and r2 Q2}.
Q = Q1 Q2. (All combination of states of machine M1 and M2).

= 1 2.
But here, for simplicity, we have considered 1 = 2 to be same.

For each (r1,r2) Q and each a , let ((r1,r2), a) = ((r1, a), (r2, a)).
Hence gets a state of M (which actually is a pair of states from M1 and
M2), together with an input symbol, and returns Ms next state.

q0 is the pair (q1, q2).


F = { (r1, r2) : r1 F1 or r2 F2 }
F = (F1 Q2) (Q1 F2)
CSC3113 Theory Of Computation

Mashiour Rahman

Finite Automaton 15

Example
Let,

So,

M1= (Q1, , 1, q1, F1),


where

M= (Q, , , q0, F), where

Q1 = {a0,a1,a2},

Q = {(a0,b0), (a0, b1),(a1, b0), (a1, b1),(a2, b0), (a2, b1)},

= {0, 1, 2}

= {0, 1, 2}

q1 = a0,

q0 = (a0, b0),

F1 = {a0},

|0
a0 | a 0
a1 | a 1
a2 | a 2

F = {(a0, b0), (a0, b1), (a1, b0), (a2, b0)}


1
a1
a2
a0

2 .
a2
a0
a1

M2= (Q2, , 2, q2, F2),


where
Q2 = {b0,b1},
= {0, 1, 2}
F2 = {b0},
|0
b0 | b 0
b1 | b 1

|
|
|
|
|
|
|

0
(a0, b0)
(a0, b1)
(a1, b0)
(a1, b1)
(a2, b0)
(a2, b1)

1
(a1, b1)
(a1, b0)
(a2, b1)
(a2, b0)
(a0, b1)
(a0, b0)

2
.
(a2, b0)
(a2, b1)
(a0, b0)
(a0, b1)
(a1, b0)
(a1, b1)

The above finite automata machine should give the


same output for any given input to machine M1 or M2.

q2 = b0,

(a0, b0)
(a0, b1)
(a1, b0)
(a1, b1)
(a2, b0)
(a2, b1)

1
b1
b0

CSC3113 Theory Of Computation

2 .
b0
b1

Here M1 recognizes A1 and M2 recognizes A2. So M


should recognize A = A1 A2.
A1={w: sum of all the symbols in w is multiple of 3}.
A2 = {w:
sum
Mashiour
Rahman

of all the symbols in w is even}.


Finite Automaton 16

Simulation
2

(a1,b0)

(a2,b1)
0
1

Input example: 01120101

(a0,b0)

(a1,b1)
2

(a2,b0)

(a0,b1)

0
1

Input symbol:

Accepted
CSC3113 Theory Of Computation

Mashiour Rahman

Finite Automaton 17

Closure under Concatenation


Let M1 recognize A1, where M1= (Q1, , 1, q1, F1),
and M2 recognize A2, where M2= (Q2, , 2, q2, F2).
Construct M to recognize A1A2,
where M = (Q, , , q0, F).
M must accept if its input can be broken into two
pieces where M1 accepts the first piece and M2
accepts the second piece.
Problem: M doesnt know where to break its input.
i.e., where the first part ends and the second begins.
To solve the problem we will learn a new technique
called nondeterministic automaton in the next class.
CSC3113 Theory Of Computation

Mashiour Rahman

Finite Automaton 18

You might also like