Anda di halaman 1dari 18

Theory of computation (IT 010 404) Course File Nov 12 May13 MODULE: II INTRODUCTION TO AUTOMATA THEORY MODULE DESCRIPTION

Lecture Notes -Module : I

This module describes the introduction to automata theory 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

LEARNING OUTCOME

Sl. No.

TOPIC

TIME REQUIRED 1.5 hr 1.5 hr

LECTURE #

01 02 03
04 05 06 07 08 09 10 11

Introduction to Automata theory - Definition of Automation Deterministic Finite Automata Language acceptability by Deterministic Finite Automata Non Deterministic Finite Automata Language acceptability by Non Deterministic Finite Automata Finite Automation with -Transitions Conversion of NFA to DFA Minimization of DFA Regular Expressions DFA to Regular Expressions conversion Pumping lemma for regular languages Applications of finite automata NFA with o/p ( Moore /Mealy) REFERENCES

LN 01 LN 02 LN 03 LN 04 LN 05 LN 06 LN 07 LN 08 LN 09 LN 10 LN 11

02 hr 01 hr 01 hr 01 hr 02 hr 02 hr 01 hr 01 hr 02 hr

Michael Sipser, Introduction to the Theory of Computation, Cengage Learning,New Delhi,2007 Peter Linz, An Introduction to Formal Languages and Automata ,Fourth Edition, 02. Narosa Kamala Krithivasan, Rama R, Introduction to Formal Languages,Automata 03. Theory and Computation, Pearson Education Asia,2009 04. S. P. Eugene Xavier, Theory of Automata Formal Language & Computation,New Age International, New Delhi ,2004 1.

TEST ITEMS

Department of Information Technology

Theory of computation (IT 010 404) Course File Nov 12 May13

Lecture Notes -Module : I

LECTURE # 01 INTRODUCTION TO AUTOMATA THEORY OBJECTIVE To introduce the concept of automata theory and define automaton EXPLANATION Finite Automata Applications Software for designing and checking the behavior of digital circuits

Department of Information Technology

Theory of computation (IT 010 404) Course File Nov 12 May13 Lexical analyzer of a typical compiler

Lecture Notes -Module : I

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 # 02 DETERMINISTIC FINITE AUTOMATA LANGUAGE ACCEPTABILITY BY DETERMINISTIC FINITE AUTOMATA OBJECTIVE To explain deterministic finite automata and language acceptability by finite automata EXPLANATION Two types of finite automata (FA): o Deterministic FA (DFA) o Nondeterministic FA (NFA) Department of Information Technology

Theory of computation (IT 010 404) Course File Nov 12 May13 Deterministic Finite automata

Lecture Notes -Module : I Non Deterministic Finite automata

The transition function is defined as a The transition fn. is defined as mapping from Q X to Q ie. : Q X mapping from Q X into finite subsets of Q. Q (q, a) =p means if the automaton is in (q, a) = { p1,..pr} means if the state q and reads a , then it goes to state automaton is in state q and reads a p in the next instant. , then it can go to any one of the states p1,..pr If the automaton is in particular state and If the automaton is in particular reads an input symbol, the next state is state and reads an input symbol, a uniquely determined. choice can be made from a set of possible transitions. Every state has exactly one exiting A state may have zero, one or many transition for each symbol in the alphabet. 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 Automaton A Deterministic Finite State Automaton (DFSA) is a 5-tuple M = (Q, , , q0 , F ) where Q is a finite set of states is a finite set of input symbols Department of Information Technology

Theory of computation (IT 010 404) Course File Nov 12 May13 q0 in Q is the start state or initial state F Q is set of final states

Lecture Notes -Module : I

Q Q. , the transition function is a mapping from (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 {q 0 , 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 0s and 1s}. Examples of strings in L: 01, 11010, 100011 Transitions: (q0, 1) = q0, (q0, 0) = q2, (q2, 1) = q1, (q2, 0) = q2, (q1, 0) = q1, (q1, 1) = q1 M = ({q0, q1, q2}, {0, 1}, , q0, {q1}) Transition diagram

Transition table: : initial state; *: final state Q/ 0 q0 *q1 q2 q1 1 q0 q1 q1

q2 q2

Department of Information Technology

Theory of computation (IT 010 404) Course File Nov 12 May13

Lecture Notes -Module : I

LECTURE # 03 NON DETERMINISTIC FINITE AUTOMATA LANGUAGE ACCEPTABILITY BY NON DETERMINISTIC FINITE AUTOMATA OBJECTIVE To explain non deterministic finite automata and language acceptability by NFA EXPLANATION A Nondeterministic Finite State Automaton (NFSA) is a 5-tuple M= (K, , , q o , 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,

Department of Information Technology

Theory of computation (IT 010 404) Course File Nov 12 May13

Lecture Notes -Module : I

a) = {p 1 , . . . , pr } which means if the automaton is in state q and reads a then it can go to any one of the states p 1 , . . . , pr . 1. Construct an NFA equivalent to the regular expression (0+1) (00+11) (0+1). 0 0 0 1 1 1 1 0

2. 3. Design an NFA accepting the following language and ends in 01}.

L = {w | w{0, 1}*

Non-determinism creates many transition paths, but if there is one path leading to a final state, then the input is accepted.

LECTURE # 04 NONDETERMINISTIC FINITE STATE A UTOMATON WITH

-TRANSITIONS

OBJECTIVE To explain non deterministic finite automaton with transitions. EXPLANATION Nondeterministic Finite State A utomaton with -transitions

Department of Information Technology

Theory of computation (IT 010 404) Course File Nov 12 May13

Lecture Notes -Module : I

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. (q )= , -closure(q).

LECTURE # 05 CONVERSION OF NFA TO DFA OBJECTIVE To explain conversion of NFA to DFA KEY POINTS Equivalence of NFAs and DFAs Conversion of NFA to DFA EXPLANATION Department of Information Technology

Theory of computation (IT 010 404) Course File Nov 12 May13

Lecture Notes -Module : I

Equivalence of NFAs and DFAs DFAs and NFAs accept exactly the same set of languages. nondeterminism does not make a finite automaton any more powerful.

That is,

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 any language accepted by a NFA can also be accepted by some DFA Proof strategy To 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.

Department of Information Technology

Theory of computation (IT 010 404) Course File Nov 12 May13

Lecture Notes -Module : I

([q0 , q1 ], a) = [ (q0 , a) (q1 , a)] = [{q0 , q1 } ] = (3) ([q0 , q1 ], b) = = The state diagram is given = [ (q0 , b) (q1 , b)] [ {q1 , q2 }] [q1 , q2 ]

(1) (2) [q0 , q1 ] (4) (5) (6)

LECTURE # 06 MINIMIZATION OF DFA OBJECTIVE

Department of Information Technology

Theory of computation (IT 010 404) Course File Nov 12 May13 To explain minimization of DFA EXPLANATION Minimization of DFSA

Lecture Notes -Module : I

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)= and (q, r 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 {q1 , . . . , qk } into {q1 , . . . , qi } {qi+1 , . . . , qj } {qj +1 , . . . , qk }. Step 3 For each block Bi , consider a state bi . Construct M 0 ) where 0 0 0 0 = (Q , , , q 0 , F

0 Q = {bi |Bi is a block of the partition obtained in step 2}.

0 q 0 corresponds to the block containing q0 .

q0

Department of Information Technology

Theory of computation (IT 010 404) Course File Nov 12 May13

Lecture Notes -Module : I

(bi , a) = bj if there exits qi Bi and qj Bj such that (q , a) = q . i j 0 F c o n sof tstates corresponding to the blocks containing states in F . is s Consider the following FSA M over = {b,c} accepting strings which have bcc as a substrings. A nondeterministic automaton for this will be,

0 Converting to DFSA we get M as:

where,

p0 = [q0 ] p1 = [q0 , q1 ] p3 = [q0 , q3 ] p4 = [q0 , q1 , q3 ] p5 = [q0 , q2 , q3 ].

p2 = [q0 , q2 ]

Finding the minimum state automaton 0 for M

Department of Information Technology

Theory of computation (IT 010 404) Course File Nov 12 May13

Lecture Notes -Module : I

LECTURE # 07 REGULAR EXPRESSIONS OBJECTIVE To explain the concept of regular expression EXPLANATION 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 r 1 and r2 are

regular expressions representing the regular sets R1 and R2 respectively, then r1 + r2 is a regular expression representing R1 R2 . r1 r2 is a regularexpression representing R1 R2 . 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|n1} 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

Department of Information Technology

Theory of computation (IT 010 404) Course File Nov 12 May13

Lecture Notes -Module : I

LECTURE # 08 CONVERSION OF REGULAR EXPRESSION TO NFA AND DFA TO REGULAR EXPRESSION OBJECTIVE To explain the conversion of Regular expression to - NFA EXPLANATION Let r1 represent the regular set R 1 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.

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 Let M = (K, , , q0 , F ) be the DFSA.

Department of Information Technology

Theory of computation (IT 010 404) Course File Nov 12 May13 = {a1 , a2 , . . . , ak },K = {q0 , q1 , . . . , qn1 }. Step 1 Write an equation for each state in K .

Lecture Notes -Module : I

q = a1 qi1 + a2 qi2 + + ak qik, if q is not a final state and (q, aj ) = qij 1 j k. q = a1 qi1 + a2 qi2 + + ak qik + , qij 1 j k. if q is a final state and (q, aj ) =

Step 2 Take the n equations with n variables q i , 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 Nov 12 May13

Lecture Notes -Module : I

LECTURE # 09 PUMPING LEMMA FOR REGULAR LANGUAGES OBJECTIVE To explain Pumping lemma for regular languages EXPLANATION Pumping Lemma for Regular Sets [Pumping Lemma] Let L be a regular language over T . Then there exists a constant |w| k, there exists x, y, z T s u c h k depending on L such that for each w L with that w = xyz and (i) |xy| k (ii) |y| 1 i (iii) xy z 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: q1 a1 . . . am a1 q2 a2 . . . am a1 . . . am qm+1 where qj K , 1 j m + 1. Here a . . . a 1 i1 qai . . . am means the FSA is in state q after reading a1 . . . ai1 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 q1 a1 . . . am a1 q2 a2 . . . am (a1 . . . ai1 qi ai . . . am . . . a1 . . . aj1 qi aj . . . am ) a1 . . . am qm+1 end at

Department of Information Technology

Theory of computation (IT 010 404) Course File Nov 12 May13

Lecture Notes -Module : I

t qi , where the transitions between the brackets start and processing a string for t t x = a1 . . . ai1 , y = ai . . . aj , z = aj + . . . am , 1 0. Hence if xy z 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: n n Let L = {a b |n 1}. If L is regular, then by the above lemma there exists a k k constant k satisfying the pumping lemma conditions. Choose w = a b . 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 as and since |y| > 1, xz / L as number of as in x is less than k and |z | = k. Hence pumping lemma is not true for i i = 0 as xy z must be in L for i 0. Hence L is not regular. LECTURE # 10 APPLICATIONS OF FINITE AUTOMATA OBJECTIVE To explain applications of finite automata EXPLANATION Finite 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. Department of Information Technology

Theory of computation (IT 010 404) Course File Nov 12 May13

Lecture Notes -Module : I

LECTURE # 11 FINITE AUTOMATA WITH OUTPUT OBJECTIVE To explain NFA with output KEY POINTS NFA with output Moore Machine NFA with output Mealy Machine EXPLANATION Moore machine The 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 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 machine The 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.

Department of Information Technology

Anda mungkin juga menyukai