Theory of computation (IT 010 404) Course File Lecture Notes -Module : I Nov ’12 – May’13 MODULE: II INTRODUCTION TO AUTOMATA THEORY MODULE DESCRIPTION This module describes the introduction to automata theory LEARNING OUTCOME At the end of the module students will be able to: Understand the design and applications of finite automata Solve problems related to language acceptability of NFA and DFA Understand the conversions NFA-DFA, DFA-Regular Expression Understand regular expressions and regular languages TOPICS Sl. No. TOPIC TIME REQUIRED LECTURE # 01 Introduction to Automata theory - Definition of Automation 1.5 hr LN 01 02 Deterministic Finite Automata –Language acceptability by Deterministic Finite Automata 1.5 hr LN 02 03 Non Deterministic Finite Automata –Language acceptability by Non Deterministic Finite Automata 02 hr LN 03 04 Finite Automation with -Transitions 01 hr LN 04 05 Conversion of NFA to DFA 01 hr LN 05 06 Minimization of DFA 01 hr LN 06 07 Regular Expressions 02 hr LN 07 Department of Information Technology
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Theory of computation (IT 010 404) Course File Lecture Notes -Module : I Nov ’12 – May’13
MODULE: II
INTRODUCTION TO AUTOMATA THEORY
MODULE DESCRIPTION This module describes the introduction to automata theory
LEARNING OUTCOME
At the end of the module students will be able to:
Understand the design and applications of finite automata
Solve problems related to language acceptability of NFA and DFA
Understand the conversions NFA-DFA, DFA-Regular Expression
Understand regular expressions and regular languages
TOPICS
Sl.
No.TOPIC
TIME
REQUIREDLECTURE #
01 Introduction to Automata theory - Definition of Automation
1.5 hr LN 01
02 Deterministic Finite Automata –Language acceptability by Deterministic Finite Automata
1.5 hr LN 02
03 Non Deterministic Finite Automata –Language acceptability by Non Deterministic Finite Automata
02 hr LN 03
04 Finite Automation with -Transitions 01 hr LN 04
05 Conversion of NFA to DFA 01 hr LN 0506 Minimization of DFA 01 hr LN 0607 Regular Expressions 02 hr LN 0708 DFA to Regular Expressions conversion 02 hr LN 0809 Pumping lemma for regular languages 01 hr LN 0910 Applications of finite automata 01 hr LN 10
11 NFA with o/p ( Moore /Mealy) 02 hr LN 11
REFERENCES
01.
02.
03.
04.
Michael Sipser, Introduction to the Theory of Computation, Cengage Learning,New Delhi,2007Peter Linz, An Introduction to Formal Languages and Automata ,Fourth Edition, Narosa Kamala Krithivasan, Rama R, Introduction to Formal Languages,Automata Theory and Computation, Pearson Education Asia,2009S. P. Eugene Xavier, Theory of Automata Formal Language & Computation,New Age International, New Delhi ,2004
Department of Information Technology
Theory of computation (IT 010 404) Course File Lecture Notes -Module : I Nov ’12 – May’13
TEST ITEMS
LECTURE # 01INTRODUCTION TO AUTOMATA THEORY
OBJECTIVETo introduce the concept of automata theory and define automatonEXPLANATION Finite Automata Applications
Department of Information Technology
Theory of computation (IT 010 404) Course File Lecture Notes -Module : I Nov ’12 – May’13
Software for designing and checking the behavior of digital circuits
Lexical analyzer of a typical compiler
Software for scanning large bodies of text (e.g., web pages) for pattern finding
Software for verifying systems of all types that have a finite number of states (e.g., stock market transaction, communication/network protocol)
Finite Automata: Examples
LECTURE # 02DETERMINISTIC FINITE AUTOMATA
LANGUAGE ACCEPTABILITY BY DETERMINISTIC FINITE AUTOMATA
OBJECTIVE To explain deterministic finite automata and language acceptability by finite automataEXPLANATION
Department of Information Technology
Theory of computation (IT 010 404) Course File Lecture Notes -Module : I Nov ’12 – May’13
Two types of finite automata (FA):oDeterministic FA (DFA)oNondeterministic FA (NFA)
The transition function is defined as a mapping from Q X ∑ to Q ie. : Q X ∑ Q
The transition fn. is defined as mapping from Q X ∑ into finite subsets of Q.
(q, a) =p means if the automaton is in state q and reads ‘a’ , then it goes to state p in the next instant.
(q, a) = { p1,…..pr} means if the automaton is in state q and reads ‘a’ , then it can go to any one of the states p1,…..pr
If the automaton is in particular state and reads an input symbol, the next state is uniquely determined.
If the automaton is in particular state and reads an input symbol, a choice can be made from a set of possible transitions.
Every state has exactly one exiting transition for each symbol in the alphabet.
A state may have zero, one or many exiting transitions for each symbol in the alphabet.
Both types are of the same power, The former is easier for hardware and software implementations. The latter is more efficient for descriptions of applications of FA.
Graphic Representation of Finite automata
Deterministic Finite State AutomatonA Deterministic Finite State Automaton (DFSA) is a 5-tuple
M = (Q, Σ, δ, q0 , F ) where
Department of Information Technology
Theory of computation (IT 010 404) Course File Lecture Notes -Module : I Nov ’12 – May’13
Q is a finite set of states
Σ is a finite set of input symbols
q0 in Q is the start state or initial state
F ⊆ Q is set of final states
δ, the transition function is a mapping from Q × Σ → Q .
δ(q, a) = p means, if the automaton is in state q and reading a symbol a, it goes to state p in the next instant.
Example 1: Let a DFSA have state set {q0, q1, q2, D}; q0 is the initial state; q2 is the only final state. The state diagram of the DFSA is given in the following figure.
Example 2: Design an DFA to accept the language L = {x01y | x and y are any strings of 0’s and 1’s}. Examples of strings in L: 01, 11010, 100011…Transitions:
Transition table: ®: initial state; *: final state
Q / Σ 0 1
® q0 q2 q0
*q1 q1 q1
q2 q2 q1
Department of Information Technology
Theory of computation (IT 010 404) Course File Lecture Notes -Module : I Nov ’12 – May’13
LECTURE # 03NON DETERMINISTIC FINITE AUTOMATA
LANGUAGE ACCEPTABILITY BY NON DETERMINISTIC FINITE AUTOMATA
OBJECTIVE To explain non deterministic finite automata and language acceptability by NFAEXPLANATION
A Nondeterministic Finite State Automaton (NFSA) is a 5-tuple M= (K, Σ, δ, qo, F ) where K, Σ, δ, q0, F are as given for DFSA and δ, thetransition function is a
mapping from K × Σ into finite subsets of K . The mappings are of the form δ(q, a) = {p1, . . . , pr } which means if the automaton is in state q and reads ‘a’ then it can go to any one of the states p1, . . . , pr .
Department of Information Technology
Theory of computation (IT 010 404) Course File Lecture Notes -Module : I Nov ’12 – May’13
1. Construct an NFA equivalent to the regular expression (0+1) (00+11) (0+1).
0 0 0 0 1 1 1 1
2. 3. Design an NFA accepting the following language L = {w | w{0, 1}*
and ends in 01}.
Non-determinism creates many transition paths, but if there is one path leading to a final state, then the input is accepted.
LECTURE # 04NONDETERMINISTIC FINITE STATE A UTOMATON WITH ε-
TRANSITIONS
OBJECTIVETo explain non deterministic finite automaton with transitions.EXPLANATION Nondeterministic Finite State A utomaton with ε-transitions
Definition: An NFSA with ε -transition is a 5-tuple M = (Q, Σ, δ, q0 , F ).
where Q, Σ, δ, q0 , F are as defined for NFSA and δ is a mapping from Q × (Σ ∪
{ε}) into finite subsets of Q . δ can be extended as δˆ
to Q× Σ∗
as follows. First we define the ε - closure of a state q. It is the set of states which can be reached from q by reading ε only. ε-closure of a state includes itself.
Department of Information Technology
Theory of computation (IT 010 404) Course File Lecture Notes -Module : I Nov ’12 – May’13
δˆ (q,ε)=
ε-closure(q).
LECTURE # 05CONVERSION OF NFA TO DFA
OBJECTIVETo explain conversion of NFA to DFAKEY POINTS Equivalence of NFAs and DFAs Conversion of NFA to DFAEXPLANATION
Equivalence of NFAs and DFAs DFAs and NFAs accept exactly the same set of languages. That is, nondeterminism does not make a finite automaton any more powerful.
To show that NFAs and DFAs accept the same class of languages, we show two things:
– any language accepted by a DFA can also be accepted by some NFA
Department of Information Technology
Theory of computation (IT 010 404) Course File Lecture Notes -Module : I Nov ’12 – May’13
– any language accepted by a NFA can also be accepted by some DFA Proof strategyTo show that any language accepted by a NFA is also accepted by some DFA, consider an algorithm that takes any NFA and converts it into a DFA that accepts the same language. The algorithm is called the “subset construction algorithm”. We can use mathematical induction (on the length of a string accepted by the automaton) to prove that the DFA that is constructed accepts the same language as the NFA. Subset construction algorithm Given a NFA, it constructs a DFA that accepts the same language
The equivalent DFA simulates the NFA by keeping track of the possible states it could be in. Each state of the DFA corresponds to a subset of the set of states of the NFA -- hence, the name of the algorithm.
If the NFA has n states, the DFA can have as many as 2n states, although it usually has many less.
Steps of subset construction algorithm The initial state of the DFA is the set of all states the NFA can be in
without reading any input.
For any state {qi,qj,…,qk} of the DFA and any input a, the next state of
the DFA is the set of all states of the NFA that can result as next states if the NFA is in any of the states qi,qj,…,qk when it reads a. This includes
states that can be reached by reading a followed by any number of ε-transitions. Use this rule to keep adding new states and transitions until it is no longer possible to do so.
The accepting states of the DFA are those states that contain an accepting state of the NFA.
Example: Construct the DFSA for the NFSA given by the table. We construct the table for DFSA.
δ([q0, q1], a) = [δ(q0, a) ∪ δ(q1, a)] (1)
= [{q0, q1} ∪ φ] (2)
Department of Information Technology
Theory of computation (IT 010 404) Course File Lecture Notes -Module : I Nov ’12 – May’13
= [q0, q1]
(3) δ([q0, q1], b) = [δ(q0, b) ∪ δ(q1, b)] (4)
= [φ ∪ {q1, q2}] (5)
= [q1, q2] (6)
The state diagram is given
LECTURE # 06MINIMIZATION OF DFA
OBJECTIVETo explain minimization of DFAEXPLANATION Minimization of DFSA
Let M = (Q, Σ, δ, q0, F ) be a DFSA. Let R be an equivalence relation on Q such
that pRq, if and only if for each input string x, δ(p, x) ∈ F if and only if δ(q, x) ∈
F . This essentially means that if p and q are equivalent, then either δ(p, x) and δ(q, x) both are in F or both are not in F for any string x. p is distinguishable from q if there exists a string x such that one of δ(q, x), δ(p, x) is in F and the other is not. x is called the distinguishing string for the pair < p, q >. If p and q are equivalent δ(p, a) and δ(q, a) will be equivalent for any a. If δ(p, a)=r and δ(q,
Department of Information Technology
0
q0
Theory of computation (IT 010 404) Course File Lecture Notes -Module : I Nov ’12 – May’13
a) = s and r and s are distinguishable by x, then p and q are distinguishable by
ax.Algorithm to find minimum DFSA
We get a partition of the set of states of Q as follows: Step 1-Consider the set of states in Q . Divide them into two blocks F and Q - F. (Any state in F is
distinguishable from a state in Q− F by ε)
Repeat the following step till no more split is possible.
Step 2 - Consider the set of states in a block. Consider the a-successors of them for a ∈ Σ. If they belong to different blocks, split this block into two or more blocks depending on the a-successors of the states.
For example if a block has {q1, . . . , qk }. δ(q1, a) = p1, δ(q2, a) = p2, . . . ,
δ(qk , a) = pk and p1, . . . , pi belong to one block, pi+1, . . . , pj belong to
another block and pj+1, . . . , pk belong to third block, then split
Step 3 For each block Bi, consider a state bi. Construct M 0 = (Q
0, Σ, δ
0, q0
0 , F
0) where Q
0 = {bi|Bi is a block of the partition obtained in step 2}.
q00corresponds to the block containing q0.
δ(bi, a) = bj if there exits qi ∈ Bi and qj∈ Bj such that δ(qi, a) = qj .
F 0
consists of states corresponding to the blocks containing states in F .
Consider the following FSA M over ∑ = {b,c} accepting strings which have bcc as a substrings. A nondeterministic automaton for this will be,
Converting to DFSA we get M 0 as:
Department of Information Technology
Theory of computation (IT 010 404) Course File Lecture Notes -Module : I Nov ’12 – May’13
where, p0 = [q0] p1 = [q0, q1] p2 = [q0, q2]
p3 = [q0, q3]
p4 = [q0, q1, q3]
p5 = [q0, q2, q3]. Finding the minimum state automaton
for M 0
LECTURE # 07REGULAR EXPRESSIONS
OBJECTIVETo explain the concept of regular expressionEXPLANATION Definition Let Σ be an alphabet. For each a in Σ, a is a regular expression representing the regular set {a}. φ is a regular expression representing the empty set. ε is a regular expression representing the set { }. If r1 and r2 are
regular expressions representing the regular sets R1 and R2 respectively, then
r1 + r2 is a regular expression representing R1 ∪ R2. r1r2 is a
Department of Information Technology
11
Theory of computation (IT 010 404) Course File Lecture Notes -Module : I Nov ’12 – May’13
regularexpression representing R1R2. r∗is a regular expression representing
R∗. Any expression obtained from φ,ε, a(a ∈ Σ) using the above operations and
parentheses where required is a regular expression.
Example :(ab)∗
abcd represent the regular set {(ab)ncd|n≥1}Theorem- If r is a regular expression representing a regular set, we can construct an NFSA with ε -moves to accept r.r is obtained from a, (a ∈ Σ), ε , φ by finite number of applications of +, . and ∗ .
For ε, φ, a we can construct NFSA with ε -moves
LECTURE # 08CONVERSION OF REGULAR EXPRESSION TO ε – NFA AND
DFA TO REGULAR EXPRESSION
OBJECTIVETo explain the conversion of Regular expression to - NFAEXPLANATION Let r1 represent the regular set R1 and R1 is accepted by the NFSA M1 with ε -
transitions. Without loss of generality we can assume that each such NFSA with ε-moves has only one final state. R2 is similarly accepted by an NFSA M2 with ε-
transition.
Department of Information Technology
Theory of computation (IT 010 404) Course File Lecture Notes -Module : I Nov ’12 – May’13
Now we can easily see that R1 ∪ R2 (represented by r1 + r2) is accepted by the
NFSA
Algorithm to find the regular expression corresponding to DFSA
q = a1qi1 + a2qi2 + · · · + ak qik, if q is not a final state and δ(q, aj ) = qij
1 ≤ j ≤ k.
q = a1qi1 + a2qi2 + · · · + ak qik + λ, if q is a final state and δ(q, aj ) =
qij 1 ≤ j ≤ k.
Step 2 Take the n equations with n variables qi, 1 ≤ i ≤ n, and solve for q0 using
the above lemma and substitution.Step 3 Solution for q0 gives the desired regular expression. Let us execute this
algorithm for the following DFSA given in the figure.
Department of Information Technology
Theory of computation (IT 010 404) Course File Lecture Notes -Module : I Nov ’12 – May’13
LECTURE # 09PUMPING LEMMA FOR REGULAR LANGUAGES
OBJECTIVETo explain Pumping lemma for regular languagesEXPLANATIONPumping Lemma for Regular Sets
Department of Information Technology
Theory of computation (IT 010 404) Course File Lecture Notes -Module : I Nov ’12 – May’13
[Pumping Lemma] Let L be a regular language over T . Then there exists a constant
k depending on L such that for each w ∈ L with |w| ≥ k, there exists x, y, z ∈ T ∗
such that w = xyz and
(i) |xy| ≤ k
(ii) |y| ≥ 1
(iii) xyiz ∈ L ∀i ≥ 0.
Let M = (K, Σ, δ, q0, F ) be a DFSA accepting L. Let K = {q1, . . . , qn}. Let w
= a1, . . . , am ∈ L where ai ∈ Σ, 1 ≤ i ≤ m, m ≥ k.
Let the transitions on w be as below: q1a1 . . . am ├ a1q2a2 . . . am ├ · · · ├ a1 . . . amqm+1
where qj∈ K , 1 ≤ j ≤ m + 1. Here a1 . . . ai−1qai . . . am means the FSA is in
state q after reading a1 . . . ai−1 and the input head is pointing to ai. Clearly in the
above transitions, m + 1 states are visited, but M has only n states. Hence there exists qi, qj such that qi = qj . Hence for q1a1 . . . am ├ a1q2a2 . . . am ├ · · · ├
end at qi, where the transitions between the brackets start and processing a string
αt
for t ≥ 0. Hence if x = a1 . . . ai−1, y = ai . . . aj , z = aj+1 . . . am, xytz ∈
L ∀t ≥ 0 where |xy| ≤ m, since qi is the first state identified to repeat in the
transition and |y| ≥ 1. Hence the lemma. Example:
Let L = {an
bn
|n ≤ 1}. If L is regular, then by the above lemma there exists a
constant ‘k’ satisfying the pumping lemma conditions. Choose w = ak
bk
. Clearly |w| > k. Then w = xyz, |xy| ≤ k and |y| ≥ 1. If |x| = p, |y| = q, |z| = r, p + q + r = 2k and p + q ≤ k. Hence xy consists of only a’s and since |y| > 1, xz ∈/ L as number of a’s in x is less than k and |z| = k. Hence pumping lemma is not true for i
= 0 as xyiz must be in L for i ≥ 0. Hence L is not regular.
LECTURE # 10APPLICATIONS OF FINITE AUTOMATA
OBJECTIVETo explain applications of finite automata
Department of Information Technology
Theory of computation (IT 010 404) Course File Lecture Notes -Module : I Nov ’12 – May’13
EXPLANATIONFinite Automata Applications Software for designing and checking the behavior of digital circuits
Lexical analyzer of a typical compiler
Software for scanning large bodies of text (e.g., web pages) for pattern finding
Software for verifying systems of all types that have a finite number of states (e.g., stock market transaction, communication/network protocol)
Hardware applications
In a digital circuit, an FSM may be built using a programmable logic device, a programmable logic controller, logic gates and flip flops or relays. More specifically, a hardware implementation requires a register to store state variables, a block of combinational logic which determines the state transition, and a second block of combinational logic that determines the output of an FSM. One of the classic hardware implementations is the Richards controller.
Mealy and Moore machines produce logic with asynchronous output, because there is a propagation delay between the flip-flop and output. This causes slower operating frequencies in FSM. A Mealy or Moore machine can be convertible to a FSM which output is directly from a flip-flop, which makes the FSM run at higher frequencies. This kind of FSM is sometimes called Medvedev FSM. A counter is the simplest form of this kind of FSM.
LECTURE # 11FINITE AUTOMATA WITH OUTPUT
OBJECTIVETo explain NFA with outputKEY POINTS NFA with output Moore Machine NFA with output Mealy MachineEXPLANATIONMoore machineThe FSM uses only entry actions, i.e., output depends only on the state. The advantage of the Moore model is a simplification of the behaviour. Consider an
Theory of computation (IT 010 404) Course File Lecture Notes -Module : I Nov ’12 – May’13
elevator door. The state machine recognizes two commands: "command_open" and "command_close" which trigger state changes. The entry action (E:) in state "Opening" starts a motor opening the door, the entry action in state "Closing" starts a motor in the other direction closing the door. States "Opened" and "Closed" stop the motor when fully opened or closed. They signal to the outside world (e.g., to other state machines) the situation: "door is open" or "door is closed".Mealy machineThe FSM uses only input actions, i.e., output depends on input and state. The use of a Mealy FSM leads often to a reduction of the number of states. The behaviour depends on the implemented FSM execution model and will work, e.g., for virtual FSM but not for event driven FSM. There are two input actions (I:): "start motor to close the door if command_close arrives" and "start motor in the other direction to open the door if command_open arrives". The "opening" and "closing" intermediate states are not shown.