Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Like this document? Why not share!

- The art of problem solving introduc... by CuteGirl218 70 views
- Introduction to Computer theory (Au... by Farwa Ansari 11170 views
- Test bank and solutions manual for... by Legit_Testbanks 68 views
- Introduction to the theory of compu... by prasadmvreddy 2422 views
- Intro automata theory by Rajendran 350 views

708 views

Published on

MELJUN CORTES Automata manual handouts

No Downloads

Total views

708

On SlideShare

0

From Embeds

0

Number of Embeds

1

Shares

0

Downloads

10

Comments

0

Likes

1

No embeds

No notes for slide

- 1. June 23, 2012 MELJUN P. CORTES, MBA,MPA,BSCS,ACS FINITE AUTOMATA It is a mathematical model of a system with discrete inputs and outputs. It consist of finite set of a sets and a set of transitions from state to state the occur on input symbol chosen from alphabet (Σ). CONVENTIONS: 1. states q’s and p’s 2. q0 initial state 3. 0, 1, a, b input symbols 4. w, x, y, z strings of input symbols.NOTE:Finite Automata are limited in strength but they are a thoroughly understood subclass of more powerful computational models. a further reason for studying FA is their applicability to the design of several common types of computer algorithms and programs. Example: Lexical analysis phase of Compilers is often based on the simulation of automation.Three (3) Ways Of Presenting Finite Automata 1. State Diagram (DIAGRAM) Vertices denotes the state Edges transition function Initial State Final State Example: State Diagram x,y x,y 2. State Table Page 1 / aav
- 2. June 23, 2012 MELJUN P. CORTES, MBA,MPA,BSCS,ACS State Table x y q0 q1 q1 *q1 q0 q0 3. Transition Function δ ( set of states, set of input alphabet )Transition Function δ (q0,x) = q1 δ (q0,y) = q1 δ (q1,x) = q0 δ (q1,y) = q0 TWO TYPES OF FINITE AUTOMATA : 1. Deterministic Finite Automata (DFA) 0 1 1 0 0 Finite Control One-way, infinite tape, broken into cells One-way, read-only tape head. Finite control, I.e., a program, containing the position of the read head, current symbol being scanned, and the current “state.” A string is placed on the tape, read head is positioned at the left end, and the DFA will read the string one symbol at a time until all symbols have been read. The DFA will then either accept or reject. For each input symbol in Σ, there is exactly one transition of each state (possibly back to the state itself). It do not accept empty strings. It is a quintuple where M = (Q, Σ, q0, δ, F)where: Q = finite set of all sets Σ = finite set of input symbols q0 = initial state δ = transition function F = set of final state Page 2 / aav
- 3. June 23, 2012 MELJUN P. CORTES, MBA,MPA,BSCS,ACSTransition Diagram Examples: 1. Diagrams that ends with 10.State Diagram 0 1 1 0 qo q1 q2 1 0Transition Table 0 1 q0 q0 q1 q1 q2 q1 *q2 q0 q1 Strings that can be derived: 10 0110 010 01010Transition Function δ (q0,0) = q0 δ (q1,1) = q1 δ (q0,1) = q1 δ (q2,0) = q0 δ (q1,0) = q2 δ (q2,1) = q12. Draw a transition diagram that will end with 001. 1 0 0 0 1 qo q1 q2 q3 1 0 13. 1 0 q0 q1 1 0 1 0 0 1 1 q0 q0 q1 q0 q0 q0 Page 3 / aav
- 4. June 23, 2012 MELJUN P. CORTES, MBA,MPA,BSCS,ACS One state is final/accepting, all others are rejecting. The above DFA accepts those strings that contain an even number of 0’s 4. Accepts those strings that contain at least two c’s a a a/b/c c c q0 q1 q2 b b a c c c b accepted q0 q0 q1 q2 q2 q2 a a c rejected q0 q0 q0 q1 Extension of δ to Stringsδ^ : (Q x Σ*) –> Qδ^(q,w) – The state entered after reading string w having started in state q.Formally:1) δ^(q, ε) = q, and2) For all w in Σ* and a in Σ δ^(q,wa) = δ (δ^(q,w), a)Recall Example #3: 1 0 q0 q1 1 0What is δ^(q0, 011)? Informally, it is the state entered by M after processing 011 having started instate q0.Formally: Page 4 / aav
- 5. June 23, 2012 MELJUN P. CORTES, MBA,MPA,BSCS,ACS δ^(q0, 011) = δ (δ^(q0,01), 1) by rule #2 = δ (δ ( δ^(q0,0), 1), 1) by rule #2 = δ (δ (δ (δ^(q0, λ), 0), 1), 1) by rule #2 = δ (δ (δ(q0,0), 1), 1) by rule #1 = δ (δ (q1, 1), 1) by definition of δ = δ (q1, 1) by definition of δ = q1 by definition of δIs 011 accepted? No, since δ^(q0, 011) = q1 is not a final state. Note that: δ^ (q,a) = δ(δ^(q, ε), a) by definition of δ^, rule #2 = δ(q, a) by definition of δ^, rule #1 Therefore: δ (q, a1a2…an) = δ(δ(…δ(δ(q, a1), a2)…), an) ^ Hence, we can use δ in place of δ^: δ^(q, a1a2…an) = δ(q, a1a2…an) Definitions for DFAs Let M = (Q, Σ, δ,q0,F) be a DFA and let w be in Σ*. Then w is accepted by M iff δ(q0,w) = p for some state p in F. Let M = (Q, Σ, δ,q0,F) be a DFA. Then the language accepted by M is the set: L(M) = {w | w is in Σ* and δ(q0,w) is in F} Another equivalent definition: L(M) = {w | w is in Σ* and w is accepted by M} Let L be a language. Then L is a regular language iff there exists a DFA M such that L = L(M). Let M1 = (Q1, Σ1, δ1, q0, F1) and M2 = (Q2, Σ2, δ2, p0, F2) be DFAs. Then M1 and M2 are equivalent iff L(M1) = L(M2).Notes: – A DFA M = (Q, Σ, δ,q0,F) partitions the set Σ* into two sets: L(M) and Σ* - L(M). – If L = L(M) then L is a subset of L(M) and L(M) is a subset of L. – Similarly, if L(M1) = L(M2) then L(M1) is a subset of L(M2) and L(M2) is a subset of L(M1). – Some languages are regular, others are not. For example, if L1 = {x | x is a string of 0s and 1s containing an even number of 1s} and L2 = {x | x = 0n1n for some n >= 0} then L1 is regular but L2 is not. • Questions: – How do we determine whether or not a given language is regular? – How could a program “simulate” a DFA? Page 5 / aav
- 6. June 23, 2012 MELJUN P. CORTES, MBA,MPA,BSCS,ACSSeatwork: 1. Give the following DFA M such that: a. L(M) = {x | x is a string of 0’s and 1’s and |x| >= 2} no. states 3 b. L(M) = {x | x is a string of (zero or more) a’s, b’s and c’s such that x does not contain the substring aa} # states 3 c. L(M) = {x | x is a string of a’s, b’s and c’s such that x contains the substring aba} # states 4 d. L(M) = {x | x is a string of a’s and b’s such that x contains both aa and bb} no of states 8 Nondeterministic Finite State Automata (NFA)*RECALL: In FA or DFA, for each input there is exactly one transition output of each state.Let’s try to modify the finite automaton by alowing zero, one or more transitions from a state onthe same input symbol. The modified model is called Non-Deterministic Finite Automaton.If for some of ∈Q, a∈Σ, δ (q,a) does either to a unique state or several states or not states at all,then the FA is a NFA. A Non-Deterministic Finite Automaton is a quintuple M=(Q,Σ,q0,ε,F)where: Q = set of states Σ = set of input alphabets δ = transition function δ: (Q x Σ) –> 2Q -2Q is the power set of Q, the set of all subsets of Q δ(q,s) - The set of all states p such that there is a transition labeled s from q to p q0 = initial state F = set of final state It allows zero, one or more transitions for every inputs symbol. Empty string accepted A sequence of symbols, say a1, a2, ...an is accepted by NFA if there exists a sequence of transition corresponding to the input sequence that leads from the initial states to the final state. Example: Construct a NFA that accepts string ending with 011. 1 0 1 1 qo q1 q2 q3 0 δ(q0,011)--> q3 Page 6 / aav
- 7. June 23, 2012 MELJUN P. CORTES, MBA,MPA,BSCS,ACS To check if 1011 is a valid string q0q0q1q2q2 valid q0q0q0 not valid * The reason for the word “nondeterministic” is that we are in a state where there aremultiple outgoing edges all having the same input symbol – we have a choice of next state. *The only difference between a NFA & DFA is that in DFA the next state function takes usto a uniquely defined state whereas in NFA the next state takes us to a set of states. Example : NFA Diagram 1 0 0 0 0 q0 qo q3 q4 1 1 q1 1 1,0 q2 State Table 0 1 q0 {q0,q3} {q0,q1} q1 0 {q2} q2 {q2} {q2} q3 {q4} 0 q4 {q4} {q4} Transition Function Let the input be 01001 δ (q0, ∈) = q0 δ (q0, ∈0) = δ(δ(q0, ∈)0) = δ(q0,0)={q0,q3} δ (q1, ∈01) = δ(δ(q0,0)1) =δ(q0,1) U δ(q3,1)={q0,q1}U{ }={q0,q1} δ (q1, ∈010) = δ(δ(q0,01)0)=δ(q0,0) U δ(q1,0)={q0,q3}U{ }={q0,q3} δ (q2, ∈0100) = δ(δ(q0,010)0)=δ(q0,1) U δ(q3,1) U δ(q3,0)={q0,q3} U δ {q4}={q0,q3,q4} δ (q2, ∈01001) = δ(δ(q0,1) U δ(q3,1) U δ(q4,1) = {q0,q1} U {} U {q4} = {q0,q1,q4}Example: pair os 0’s or pair of 1’s Page 7 / aav
- 8. June 23, 2012 MELJUN P. CORTES, MBA,MPA,BSCS,ACS Q = {q0, q1, q2 , q3 , q4} Σ = {0, 1} Start state is q0 F = {q2, q4}Determining if a given NFA accepts a given string (001) can be done algorithmically: Each level will have at most n statesAnother example (010): All paths have been explored, and none lead to an accepting stateLet Σ = {a, b, c}. Give an NFA M that accepts: L = {x | x is in Σ* and x contains ab} Is L a subset of L(M)? Is L(M) a subset of L? • Is an NFA necessary? Could a DFA accept L? Try and give an equivalent DFA as an exercise. • Designing NFAs is not a typical task.Let Σ = {a, b}. Give an NFA M that accepts:L = {x | x is in Σ* and the third to the last symbol in x is b}Extension of δ to Strings and Sets of States What we currently have: δ : (Q x Σ) –> 2Q What we want (why?): δ : (2Q x Σ*) –> 2Q Page 8 / aav
- 9. June 23, 2012 MELJUN P. CORTES, MBA,MPA,BSCS,ACSWe will do this in two steps, which will be slightly different from the book, and we will make use ofthe following NFA.Step #1: Given δ: (Q x Σ) –> 2Q define δ#: (2Q x Σ) –> 2Q as follows: 1) δ#(R, a) = δ(q, a) for all subsets R of Q, and symbols a in Σ Note that: δ ({p},a) = # δ(q, a) by definition of δ#, rule #1 above = δ(p, a) Hence, we can use δ for δ # δ({q0, q2}, 0) These now make sense, but previously δ({q0, q1, q2}, 0) they did not.Example:δ({q0, q2}, 0) = δ(q0, 0) U δ(q2, 0) δ({q0, q1, q2}, 1) = δ(q0, 1) U δ(q1, 1) U δ(q2, 1) = {q1, q3} U {q3, q4} = {} U {q2, q3} U {} = {q1, q3, q4} = {q2, q3}Step #2: Given δ: (2Q x Σ) –> 2Q define δ^: (2Q x Σ*) –> 2Q as follows: δ^(R,w) – The set of states M could be in after processing string w, having starting from any state in R. Formally: 2) δ^(R, ε) = R for any subset R of Q 3) δ^(R,wa) = δ (δ^(R,w), a) for any w in Σ*, a in Σ, and subset R of Q Note that: δ^(R, a) = δ(δ^(R, ε), a) by definition of δ^, rule #3 above = δ(R, a) by definition of δ^, rule #2 above Hence, we can use δ for δ^ δ({q0, q2}, 0110) These now make sense, but previously δ({q0, q1, q2}, 101101) they did not.Example: Page 9 / aav
- 10. June 23, 2012 MELJUN P. CORTES, MBA,MPA,BSCS,ACSWhat is δ({q0}, 10)?Informally: The set of states the NFA could be in after processing 10,having started in state q 0,i.e., {q1, q2, q3}. Formally: δ({q0}, 10) = δ(δ({q0}, 1), 0) = δ({q0}, 0) = {q1, q2, q3} Is 10 accepted? Yes!What is δ({q0, q1}, 1)? δ({q0 , q1}, 1)= δ({q0}, 1) U δ({q1}, 1) = {q0} U {q2, q3} = {q0, q2, q3}What is δ({q0, q2}, 10)? δ({q0 , q2}, 10) = δ(δ({q0 , q2}, 1), 0) = δ(δ({q0}, 1) U δ({q2}, 1), 0) = δ({q0} U {q3}, 0) = δ({q0,q3}, 0) = δ({q0}, 0) U δ({q3}, 0) = {q1, q2, q3} U {} = {q1, q2, q3}δ({q0}, 101) = δ(δ({q0}, 10), 1) = δ(δ(δ({q0}, 1), 0), 1) = δ(δ({q0}, 0), 1) = δ({q1 , q2, q3}, 1) = δ({q1}, 1) U δ({q2}, 1) U δ({q3}, 1) = {q2, q3} U {q3} U {} = {q2, q3} Is 101 accepted? Yes! Definitions for NFAs • Let M = (Q, Σ, δ,q0,F) be an NFA and let w be in Σ*. Then w is accepted by M iff δ({q0}, w) contains at least one state in F. • Let M = (Q, Σ, δ,q0,F) be an NFA. Then the language accepted by M is the set: Page 10 / aav
- 11. June 23, 2012 MELJUN P. CORTES, MBA,MPA,BSCS,ACS L(M) = {w | w is in Σ* and δ({q0},w) contains at least one state in F} • Another equivalent definition: L(M) = {w | w is in Σ* and w is accepted by M}Notes: – δ(q,s) may not be defined for some q and s (why?). – Informally, a string is said to be accepted if there exists a path to some state in F. – The language accepted by an NFA is the set of all accepted strings. – Question: How does an NFA find the correct/accepting path for a given string? – NFAs are a non-intuitive computing model. – We are primarily interested in NFAs as language defining devices, i.e., do NFAs accept languages that DFAs do not? – Other questions are secondary, including practical questions such as whether or not there is an algorithm for finding an accepting path through an NFA for a given string, EQUIVALENCE OF DFAs AND NFAsTheorem: For every NFA model, there exist one and only one equivalent DFA Let M’ be the equivalent DFA of a NFA M. M’=(Q’, Σ,δ’,q0’,F’)Example: Transform the given NFA to DFA 0,1 0 0 1 0 qo q1 q2Q’={{},q0,q1,q2,{q0,q1},{q0,q1},{q0,q2},{q1,q2},{q0,q1,q2}}F =q2F’={q2,{q0,q2},{q1,q2},{q0,q1,q2}}Transition Table of NFA 0 1 q0 {q0} {q0,q1} q1 {q1,q2} {} q2 {q2} {}Transition Functionδ’ ({},0) = {} δ’ (q1,0) = {q1,q2}δ’ ({},1) = {} δ’ (q1,1) = {}δ’ (q0,0) = q0 δ’ (q2,0) = q2δ’ (q0,1) = {q0,q1} δ’ (q2,1) = {} Page 11 / aav
- 12. June 23, 2012 MELJUN P. CORTES, MBA,MPA,BSCS,ACSδ’ ((q0,q1),0) = δ{q0,0} U δ(q1,0) = q0 U {q1,q2} = {q0,q1,q2}δ’ ((q0,q1),1) = δ{q0,1) U δ(q1,1) = {q0,q1} U {} = {q0,q1}δ’ ((q0,q2),0) = δ{q0,0) U δ(q2,0) = {q0} U {q2} = {q0,q2}δ’ ((q0,q2),1) = δ{q0,1) U δ(q2,1) = {q0,q1} U {q2} = {q0,q1,q2}δ’ ((q1,q2),0) = δ{q1,0) U δ(q2,0) = {q1,q2} U {q2} = {q1,q2}δ’ ((q0,q1,q2),0) = δ{q0,0) U δ(q1,0) U δ(q2,0) = {q0} U {q1,q2} U {q2} = {q0,q1,q2}δ’ ((q0,q1,q2),1) = δ{q0,1) U δ(q1,1) U δ(q2,1) = {q0,q1} U {} U {} = {q0,q1}State Table of DFA 0 1 q0 {q0} {q0,q1} q1 {q1,q2} {} q2 {q2} {} q0,q1 {q0,q1,q2 {q0,q1} } q0,q2 {q0,q2} {q0,q1} q1,q2 {q1,q2} {} q0,q1,q2 {q0,q1,q2 {q0,q1} } {} {} {}Transition Diagram Of DFA 0 1 q1 0 1 q1q2 {} 1 q2 0,1 0 q0 q0,q q0 ,q 1,q2 q0 ,q • Do DFAs and NFAs accept the same class of languages? – Is there a language L that is accepted by a DFA, but not by any NFA? – Is there a language L that is accepted by an NFA, but not by any DFA? • Observation: Every DFA is an NFA. Page 12 / aav
- 13. June 23, 2012 MELJUN P. CORTES, MBA,MPA,BSCS,ACS • Therefore, if L is a regular language then there exists an NFA M such that L = L(M). • It follows that NFAs accept all regular languages. • But do NFAs accept more?Consider the following DFA: 2 or more c’s Q = {q0, q1, q2} Σ = {a, b, c} Start state is q0 F = {q2}An Equivalent NFA:Lemma 1: Let M be an DFA. Then there exists a NFA M’ such that L(M) = L(M’).Proof: Every DFA is an NFA. Hence, if we let M’ = M, then it follows that L(M’) = L(M).Lemma 2: Let M be an NFA. Then there exists a DFA M’ such that L(M) = L(M’).Proof: (sketch) Let M = (Q, Σ, δ,q0,F). Define a DFA M’ = (Q’, Σ, δ’,q’0,F’) as: Q’ = 2Q Each state in M’ corresponds to a = {Q0, Q1,…,} subset of states from M where Qu = [qi0, qi1,…qij] F’ = {Qu | Qu contains at least one state in F} q’0 = [q0] δ’(Qu, a) = Qv iff δ(Qu, a) = QvExample: empty string or start and end with 0 Q = {q0, q1} Σ = {0, 1} Start state is q0 F = {q1}Construct DFA M’ as follows δ({q0}, 0) = {q1} => δ’([q0], 0) = [q1] δ({q0}, 1) = {} => δ’([q0], 1) = [ ] δ({q1}, 0) = {q0, q1} => δ’([q1], 0) = [q0, q1] Page 13 / aav
- 14. June 23, 2012 MELJUN P. CORTES, MBA,MPA,BSCS,ACSδ({q1}, 1) = {q1} => δ’([q1], 1) = [q1]δ({q0, q1}, 0) = {q0, q1} => δ’([q0, q1], 0) = [q0, q1]δ({q0, q1}, 1) = {q1}=> δ’([q0, q1], 1) = [q1]δ({}, 0) = {} => δ’([ ], 0) = [ ]δ({}, 1) = {} => δ’([ ], 1) = [ ]Theorem: Let L be a language. Then there exists an DFA M such that L = L(M) iff there exists anNFA M’ such that L = L(M’).Proof: (if) Suppose there exists an NFA M’ such that L = L(M’). Then by Lemma 2 there exists anDFA M such that L = L(M). (only if) Suppose there exists an DFA M such that L = L(M). Then byLemma 1 there exists an NFA M’ such that L = L(M’).Corollary: The NFAs define the regular languages. Note: Suppose R = {} δ(R, 0) = δ(δ(R, ε), 0) = δ(R, 0) = δ(q, 0) = {} Since R = {} NFAs with ε Moves It is quintuple M = {Q,Σ,δ,q0,F} where the transition functions δ maps. δ:Q x (Σ U {Є}) 2Q δ(q,a)={p | δ(q,a) p and a=Є or aЄΣ ∗will consist of all states p such that there is a transition labeled a from q to p where a is either Є or a symbol in the Σ. Є-closure(q)= { p | , a path from q to p marked Є } Є-closure(p)= UqЄp Є-closure where p is a set of states δ : Q x Σ∗ →2Q δ (q,w) →{ p | δ(q,w) contains p including edges labeled Є δ(q,Є) = Є-closure (q) *δ (q,w) will be all states p such that one can go from q to p doing a path labeled w, perhaps including edges labeled Є. • Sometimes referred to as an NFA-ε other times, simply as an NFA. Example: a Є Є a qo q1 q2 q3 Page 14 / aav
- 15. June 23, 2012 MELJUN P. CORTES, MBA,MPA,BSCS,ACS transition: δ (q0,a) → q0 δ (q1,Є) → q2 δ (q0,Є) → q1 δ (q2,a) → q3 Є-closure: Є-closure (q0) = {q0,q1,q2} q0 Є-closure (q1) = {q1,q2} Є-closure(p) = Є-closure of {q0,q1} Є q0 q1 = Є-closure {q0} U Є-closure {q1} Є Є = {q0,q1,q2} U {q1,q2} q0 q1 q2 = {q0,q1,q2} EQUIVALENT NFA of NFAЄ Theorem: For each NFA’s there is one and only one equivalent NFA. NFA or NFA’s: M = {Q, Σ, δ, q0, F} Let Equivalent NFA be M’ = {Q, Σ, δ1, q0, F1} where: F’ = {F U Є–closure (qo)1 l Є−closure (qo) contains state of F } Example: 1. Convert the given NFAε to NFA. 0 1 2 Є Є qo q1 q3 q2NFAЄ 0 1 2 εq0 {q0} {} {} q1q1 {} q1 {} q2q2 {} {} q2 {}NFA 0 1 2q0 {q0,q1,q2 {q1,q2} {q2} }q1 0 {q1,q2} {q2}q2 {} {} {q2} Page 15 / aav
- 16. June 23, 2012 MELJUN P. CORTES, MBA,MPA,BSCS,ACSF’ = {F U Є–closure (q0)} F’ = {q0,q1,q2}Transformed NFA 0 1 2 0,1 1,2 qo q1 q3 q2 0,1,22. Convert the given NFAε to NFA. a,b a,b a a q1 q2 q2 q3 Є q0 b Є b q4 q5 q5F = {q3,q5} Є-closure (q0) = {q0,q1,q4} q0 = {q0} Σ = {a,b}NFAЄ a b E NFAq0 {} {} {q1,q4} a bq1 {q1,q2} q1 {} q0 {q1,q2} {q1,q5}q2 {q3} {} {} q1 {q1,q2} {q1}q3 {q3} {q3} {} q2 {q3} 0q4 {} {q4} {} q3 {q3} {q3}q5 {} {q5} {} q4 {} {q5} q5 {} {q5}F’ = {q3,q5} a,b a,b q1 a a,b q0 a a q2 q2 q3 b q4 b b q5 q5 Page 16 / aav
- 17. June 23, 2012 MELJUN P. CORTES, MBA,MPA,BSCS,ACS Transformed NFAExample:- A string w = w1w2…wn is processed as w = ε*w1ε*w2ε* … ε*wnε* - Example: all computations on 00: 0 ε 0 q0 q0 q1 q2Informal Definitions • Let M = (Q, Σ, δ,q0,F) be an NFA-ε. • A String w in Σ* is accepted by M iff there exists a path in M from q 0 to a state in F labeled by w and zero or more ε transitions. • The language accepted by M is the set of all strings from Σ* that are accepted by M.Step #2: Given δ: (2Q x (Σ U {ε})) –> 2Q define δ^: (2Q x Σ*) –> 2Q as follows:δ^(R,w) – The set of states M could be in after processing string w, having starting from any statein R. Formally: 2) δ^(R, ε) = ε-closure(R) - for any subset R of Q 3) δ (R,wa) = ε-closure(δ(δ (R,w), a)) - for any w in Σ*, a in Σ, and subset R of Q ^ ^Can we use δ for δ^?Lemma 1: Let M be an NFA. Then there exists a NFA-ε M’ such that L(M) = L(M’).Proof: Every NFA is an NFA-ε. Hence, if we let M’ = M, then it follows that L(M’) = L(M).Lemma 2: Let M be an NFA-ε. Then there exists a NFA M’ such that L(M) = L(M’).Proof: (sketch) Let M = (Q, Σ, δ,q0,F) be an NFA-ε. Define an NFA M’ = (Q, Σ, δ’,q0,F’) as: F’ = F U {q0} if ε-closure(q0) contains at least one state from F F’ = F otherwise δ’(q, a) = δ^(q, a) - for all q in Q and a in Σ Page 17 / aav
- 18. June 23, 2012 MELJUN P. CORTES, MBA,MPA,BSCS,ACSNotes: - δ’: (Q x Σ) –> 2Q is a function – M’ has the same state set, the same alphabet, and the same start state as M – M’ has no ε transitionsTheorem: Let L be a language. Then there exists an NFA M such that L= L(M) iff there exists anNFA-ε M’ such that L = L(M’).Proof: (if) Suppose there exists an NFA-ε M’ such that L = L(M’). Then by Lemma 2 there existsan NFA M such that L = L(M). (only if) Suppose there exists an NFA M such that L = L(M).Then by Lemma 1 there exists an NFA-ε M’ such that L = L(M’).Corollary: The NFA-ε machines define the regular languages. OPERATIONS ON LANGUAGES Let L, L1, L2 be subsets of Σ* Concatenation: L1L2 = {xy | x is in L1 and y is in L2} Concatenating a language with itself:L0 = {ε} Li = LLi-1, for all i >= 1 Kleene Closure: L* = Li = L0 U L1 U L2 U… L1 ={a, abc, ba}, on Σ ={a,b,c} Then, L2 = {aa, aabc, aba, abca, abcabc, abcba, baa, baabc, baba} L3= {a, abc, ba}. L2 L* = {ε, L1, L2, L3, . . .} Positive Closure: L+ = Li = L1 U L2 U… REGULAR EXPRESSIONS – A regular expression is used to specify a language, and it does so precisely. Page 18 / aav
- 19. June 23, 2012 MELJUN P. CORTES, MBA,MPA,BSCS,ACS – Regular expressions are very intuitive. – Regular expressions are very useful in a variety of contexts. – Given a regular expression, an NFA-ε can be constructed from it automatically. – Thus, so can an NFA, a DFA, and a corresponding program, all automatically!Definition of a Regular Expression • Let Σ be an alphabet. The regular expressions over Σ are: – Ø Represents the empty set { } – ε Represents the set {ε} – a Represents the set {a}, for any symbol a in Σ Let r and s be regular expressions that represent the sets R and S, respectively. – r+s Represents the set RUS (precedence 3) – rs Represents the set RS (precedence 2) – r* Represents the set R* (highest precedence) – (r) Represents the set R (not an op, provides precedence) • If r is a regular expression, then L(r) is used to denote the corresponding language. Examples: Let Σ = {0, 1} 1. (0 + 1)* All strings of 0’s and 1’s 2. 0(0 + 1)* All strings of 0’s and 1’s, beginning with a 0 3. (0 + 1)*1 All strings of 0’s and 1’s, ending with a 1 4. (0 + 1)*0(0 + 1)* All strings of 0’s and 1’s containing at least one 0 5. (0 + 1)*0(0 + 1)*0(0 + 1)* All strings of 0’s and 1’s containing at least two 0’s 6. (0 + 1)*01*01* All strings of 0’s and 1’s containing at least two 0’s 7. (1 + 01*0)* All strings of 0’s and 1’s containing an even number of 0’s 8. 1*(01*01*)* All strings of 0’s and 1’s containing an even number of 0’s 9. (1*01*0)*1* All strings of 0’s and 1’s containing an even number of 0’sBasis: OP(r) = 0 Then r is either Ø, ε, or a, for some symbol a in Σ Page 19 / aav
- 20. June 23, 2012 MELJUN P. CORTES, MBA,MPA,BSCS,ACSInductive Hypothesis: Suppose there exists a k ≥ 0 such that for any regular expression rwhere 0 ≤ OP(r) ≤ k, there exists an NFA-ε such that L(M) = L(r). Furthermore, suppose that Mhas exactly one final state.Inductive Step: Let r be a regular expression with k + 1 operators (OP(r) = k + 1), where k + 1>= 1.Case 1) r = r1 + r2Since OP(r) = k +1, it follows that 0<= OP(r1), OP(r2) <= k. By the inductive hypothesis thereexist NFA-ε machines M1 and M2 such that L(M1) = L(r1) and L(M2) = L(r2). Furthermore, bothM1 and M2 have exactly one final state.Construct M as:Case 2) r = r1r2 Page 20 / aav
- 21. June 23, 2012 MELJUN P. CORTES, MBA,MPA,BSCS,ACSSince OP(r) = k+1, it follows that 0<= OP(r1), OP(r2) <= k. By the inductive hypothesis thereexist NFA-ε machines M1 and M2 such that L(M1) = L(r1) and L(M2) = L(r2). Furthermore, bothM1 and M2 have exactly one final state.Construct M as:Case 3) r = r1*Since OP(r) = k+1, it follows that 0<= OP(r1) <= k. By the inductive hypothesis there exists anNFA-ε machine M1 such that L(M1) = L(r1). Furthermore, M1 has exactly one final state.Construct M as:Example: r = 0(0+1)* r = r1r2 r1 = 0 r2 = (0+1)* r2 = r3* r3 = 0+1 r3 = r4 + r5 r4 = 0 r5 = 1Seatwork: Construct the equivalent NFAe of the ff, reg. expression: 1. 0 Page 21 / aav
- 22. June 23, 2012 MELJUN P. CORTES, MBA,MPA,BSCS,ACS2. 013. 0+14. 1*5. 11+0 CONTEXT-FREE GRAMMARS Context-free Grammars describe context-free languages. Regular set is an example of Context Free language. Context-Free grammar (CFG) is a quadruple G = (V,T,P,S) where V – set of variables {S,B} T – set of terminals (a,b,c) P – Production or rule (How to form the string) S – the starting symbolExamples : Construct CFG for the following:1. ab*c = {ac,abc,abbc,abbbc,….} given: S aBc B bB BЄ ac abc abbbbbc S aBc S aBc S aBc aЄc abBc abbBc ac abЄc abbbBc abc abbbbBc abbbbbBc abbbbbЄc abbbbbc2. Construct a CFG for anbn; n>0={ab,aabb,aaabbb..} V=S S=S T={a,b} P: S aSb SЄ ab aabb S aSb S aSb aЄb aaSbb ab aaЄbb aabbSeatwork: Construct a CFG for the following: a. 0*1 = {1,01,001,..} V=S,B T={0,1} Page 22 / aav
- 23. June 23, 2012 MELJUN P. CORTES, MBA,MPA,BSCS,ACS S=S P: S B1 B 0B B Є 1. 1 2. 0001 b. (0+1)* S 1s|0s S Є 3. 01 4. 111001 c. ambn | m>= n S aMb M aMb | aM | Є 5. aabb 6. aaabb d. {anbncmdm | n,m > 0} S abcd| aMbcNd M aMb | Є N cNd | Є 7. aabbcd 8. aabbccdd e. {xmyxm| m >= 0} S xSx |y 9. xyx 10. xxxyxxx PUSHDOWN AUTOMATA Context Free Grammar’s machine counterpart.(Just as the RE have an equivalent automaton-FA). Non deterministic device.(Deterministic version is only a subset of all CFL’s). Page 23 / aav
- 24. June 23, 2012 MELJUN P. CORTES, MBA,MPA,BSCS,ACS Have input tape, finite control and a stack Essentially a FA with control of both input and stack “FILO” list. Stack – is a string of symbols from some alphabet. The leftmost symbol of the stack is considered to be the “tape” of the stack. MOVES 1. An input symbol is used. ⇒ Depending on the input symbol, the top symbol on the stack, and state of the finite control, a number of choices are possible. Each choice consist of next state for the finite control and a (possibly empty) string of symbols to replace the top stack symbol. After selecting a choice, the input head is advanced one symbol. 2. Input symbol is not used (Є-move). ⇒ Similar to the first except that the input symbol is not used and the input head is not advanced after the move. ⇒ Allows the PDA to manipulate the stack without reading input symbols. WAYS TO DEFINE THE LANGUAGE ACCEPTED BY PDA Σ no final state – empty bothinput tape & stack 1. Set of all inputs for which some sequence of moves causes the PDA to empty a stack. 2. Designate some states as final sates define the accepted language as the set of all inputs for which some choice of moves causes the PDA to enter final state. with final state – empty input tape M = (Q, Σ, Г, δ, qo, Zo, F) where: Q = finite set of all sets Σ = finite set of input symbols Г = stack alphabet q0 = in Q, initial state Zo = in Г, start symbol F = ⊆ Q, set of final states δ = mapping Q x (Σ U {Є}) x Г to Q x Г* δ(q, a, Z) = {(P1, y1)…(Pm, ym)} initial state Pop Push Input Destination State Example: M = ( {q1,q2}, {0,1}, {R, B, G}, δ, q1, R, q2 ) 1. δ( q1, 0, R ) = {( q1, BR )} 2. δ( q1, 1, R ) = {( q1, GR )} 3. δ( q1, 0, B ) = {( q1, BB )}, {( q2, Є )} Page 24 / aav
- 25. June 23, 2012 MELJUN P. CORTES, MBA,MPA,BSCS,ACS 4. δ( q1, 0, G ) = {( q1, BG )} 5. δ( q1, 1, B ) = {( q1, GB )} 6. δ( q1, 1, G ) = {( q1, GG )}, {( q2, Є )} 7. δ( q2, 0, B ) = {( q2, Є )} 8. δ( q2, 1, G ) = {( q2, Є )} 9. δ( q1, Є, R ) = {( q2, Є )} 10. δ( q2, Є, R ) = {( q2, Є )}Determine if the input 001100 is valid for PUSHDOWN AUTOMATA.(q1,001100,R)(q1,01100,BR) (q2,001100,Є) (q1,1100,BBR) (q2,1100,R) (q2,1100,Є)(q1,100,GBBR) (q1,0,BGGBBR)(q1,00,GGBBR) (q2,00,BBR)(q1,0,BGGBBR) ( q2, 0, BR ) ( q2, Є, R ) ( q2, Є, Є ) Accepted(q1,Є,BBGGBBR) (q2,Є,GGBBR) ? ? Page 25 / aav
- 26. June 23, 2012 MELJUN P. CORTES, MBA,MPA,BSCS,ACSExample: (balanced parentheses) M = ({q1}, {“(“, “)”}, {L, #}, δ, q1, #, Ø) δ: (1) δ(q1, (, #) = {(q1, L#)} (2) δ(q1, ), #) = Ø (3) δ(q1, (, L) = {(q1, LL)} (4) δ(q1, ), L) = {(q1, ε)} (5) δ(q1, ε, #) = {(q1, ε)} (6) δ(q1, ε, L) = Ø • Goal: (acceptance) – Terminate in a non-null state – Read the entire input string – Terminate with an empty stack Transition Diagram:Current Input Stack Transition (()) # ()) L# (1) - Could have applied rule (5), )) LL# (3) but it would have ) L# (4) done no good ε # (4) ε - (5)Example PDA: For the language {x | x = wcwr and w in {0,1}*}M = ({q1, q2}, {0, 1, c}, {R, B, G}, δ, q1, R, Ø) δ: (1) δ(q1, 0, R) = {(q1, BR)} (7) δ(q2, 0, B) = {(q2, ε)} (2) δ(q1, 0, B) = {(q1, BB)} (8) δ(q2, ε, R) = {(q2, ε)} (3) δ(q1, 0, G) = {(q1, BG)} (9) δ(q1, 1, R) = {(q1, GR)} (4) δ(q1, c, R) = {(q2, R)} (10) δ(q1, 1, B) = {(q1, GB)} (5) δ(q1, c, B) = {(q2, B)} (11) δ(q1, 1, G) = {(q1, GG)} (6) δ(q1, c, G) = {(q2, G)} (12) δ(q2, 1, G) = {(q2, ε)} Notes: – Only rule #8 is non-deterministic. – Rule #8 is used to pop the final stack symbol off at the end of a computation. Page 26 / aav
- 27. June 23, 2012 MELJUN P. CORTES, MBA,MPA,BSCS,ACSState Input Stack Rule Applied Rules Applicableq1 01c10 R (1)q1 1c10 BR (1) (10)q1 c10 GBR (10) (6)q2 10 GBR (6) (12)q2 0 BR (12) (7)q2 ε R (7) (8)q2 ε ε (8) -Seatwork: For the language {x | x = wwr and w in {0,1}*} M = ({q1, q2}, {0, 1}, {R, B, G}, δ, q1, R, Ø) δ: (1) δ(q1, 0, R) = {(q1, BR)} (6) δ(q1, 1, G) = {(q1, GG), (q2, ε)} (2) δ(q1, 1, R) = {(q1, GR)} (7) δ(q2, 0, B) = {(q2, ε)} (3) δ(q1, 0, B) = {(q1, BB), (q2, ε)} (8) δ(q2, 1, G) = {(q2, ε)} (4) δ(q1, 0, G) = {(q1, BG)} (9) δ(q1, ε, R) = {(q2, ε)} (5) δ(q1, 1, B) = {(q1, GB)} (10) δ(q2, ε, R) = {(q2, ε)}State Input Stack Rule Applied Rules Applicable1. q1 000000 R (1), (9)2. q1 010010 R TURING MACHINE • Generalize the class of CFLs: Another Part of the Hierarchy: Page 27 / aav
- 28. June 23, 2012 MELJUN P. CORTES, MBA,MPA,BSCS,ACS• Recursively enumerable languages are also known as type 0 languages.• Context-sensitive languages are also known as type 1 languages.• Context-free languages are also known as type 2 languages.• Regular languages are also known as type 3 languages.• TMs model the computing capability of a general purpose computer, which informally can be described as: – Effective procedure • Finitely describable • Well defined, discrete, “mechanical” steps • Always terminates – Computable function • A function computable by an effective procedure• TMs formalize the above notion.• Church-Turing Thesis: There is an effective procedure for solving a problem if and only if there is a TM that halts for all inputs and solves the problem. – There are many other computing models, but all are equivalent to or subsumed by TMs. There is no more powerful machine (Technically cannot be proved).• DFAs and PDAs do not model all effective procedures or computable functions, but only a subset. Deterministic Turing Machine (DTM) Page 28 / aav
- 29. June 23, 2012 MELJUN P. CORTES, MBA,MPA,BSCS,ACS • Two-way, infinite tape, broken into cells, each containing one symbol. • Two-way, read/write tape head. • Finite control, i.e., a program, containing the position of the read head, current symbol being scanned, and the current state. • An input string is placed on the tape, padded to the left and right infinitely with blanks, read/write head is positioned at the left end of input string. • In one move, depending on the current state and the current symbol being scanned, the TM 1) changes state, 2) prints a symbol over the cell being scanned, and 3) moves its’ tape head one cell left or right. • Many modifications possible. A DTM is a seven-tuple: M = (Q, Σ, Γ, δ, q0, B, F) Q A finite set of states Γ A finite tape alphabet B A distinguished blank symbol, which is in Γ Σ A finite input alphabet, which is a subset of Γ– {B} q0 The initial/starting state, q0 is in Q F A set of final/accepting states, which is a subset of Q δ A next-move function, which is a mapping (i.e., may be undefined) from Q x Γ –> Q x Γ x {L,R} Intuitively, δ(q,s) specifies the next state, symbol to be written, and the direction of tapehead movement by M after reading symbol s while in state q. Page 29 / aav
- 30. June 23, 2012 MELJUN P. CORTES, MBA,MPA,BSCS,ACSExample : {0n1n | n >= 1} 0 1 X Y B q0 (q1, X, R) - - (q3, Y, R) - q1 (q1, 0, R) (q2, Y, L) - (q1, Y, R) - q2 (q2, 0, L) - (q0, X, R) (q2, Y, L) - q3 - - - (q3, Y, R) (q4, B, R) q4 - - - - -Sample Computation: (on 0011)q00011 |— Xq1011 |— X0q111 |— Xq20Y1 |— q2X0Y1 |— Xq00Y1 |— XXq1Y1 |— XXYq11 |— XXq2YY |— Xq2XYY |— XXq0YY |— XXYq3Y |— XXYYq3 |— XXYYBq4 Page 30 / aav
- 31. June 23, 2012 MELJUN P. CORTES, MBA,MPA,BSCS,ACSExample: M = ({qo, q1… q4}, {0,1}, {0,1,x,y,B}, δ, q0, B, q4) 0 1 x Y B qo q1,x,R) ------- ------- (q3,y,R) ------- q1 q1,0,R) (q2,y,L) ------- (q1,y,R) ------- q2 (q2,0,L) ------- (q0,x,R) (q2,y,L) ------- q3 ------- ------- ------- (q3,y,R) (q4,B,R) q4 ------- ------- ------- ------- -------Determine if the given inputs are accepted by TM 1. 0011 State Head Position qo 0011 q1 x011 q1 x011 q2 x0y1 q2 x0y1 qo x0y1 q1 xxy1 q1 xxy1 q2 xxyy q2 xxyy qo xxyy q3 xxyy q3 xxyyB q4 xxyyBB Therefore, accepted 2. 0011 State Head Position qo 0011 01 q1 x01101 q1 x01101 q2 x0y101 q2 x0y101 qo x0y101 q1 xxy101 q1 xxy101 q2 xxyy01 Page 31 / aav
- 32. June 23, 2012 MELJUN P. CORTES, MBA,MPA,BSCS,ACS q2 xxyy01 qo xxyy01 q3 xxyy01 q3 xxyy01 ? Therefore, not acceptedSeatwork: Construct a DTM for each of the following. – {w | w is in {0,1}* and w ends in 00} – {w | w is in {0,1}* and w contains at least 2 0’s} – {w | w is in {0,1}* and w contains at least one 0 and one 1} Q = {q0, q1, q2} Γ = {0, 1, B} Σ = {0, 1} F = {q2} δ: 0 1 B q0 (q0, 0, R) (q0, 1, R) (q1, B, L) q1 (q2, 0, R) - - q2 - - - Page 32 / aav

No public clipboards found for this slide

×
### Save the most important slides with Clipping

Clipping is a handy way to collect and organize the most important slides from a presentation. You can keep your great finds in clipboards organized around topics.

Be the first to comment