CSE 2001: Introduction to Theory of Computation Summer 2013 Yves Lesperance lesperan@cse.yorku.ca Office: CSEB 3052A Phone: 416-736-2100 ext 70146 Course page: http://www.cse.yorku.ca/course/2001 Slides are mostly taken from Suprakash Datta’s for Winter 2013 13-06-03 CSE 2001, Summer 2013 1 Recall: Regular Languages The language recognized by a finite automaton M is denoted by L(M). A regular language is a language for which there exists a recognizing finite automaton. 13-06-03 CSE 2001, Summer 2013 2 1
Terminology: closure • A set is defined to be closed under an operation if that operation on members of the set always produces a member of the same set. (adapted from wikipedia) E.g.: • The integers are closed under addition, multiplication. • The integers are not closed under division • Σ * is closed under concatenation • A set can be defined by closure -- Σ * is called the (Kleene) closure of Σ under concatenation. 13-06-03 CSE 2001, Summer 2013 3 Terminology: Regular Operations Pages 44-47 (Sipser) The regular operations are: 1. Union 2. Concatenation 3. Star (Kleene Closure): For a language A, A* = {w 1 w 2 w 3 … w k | k ≥ 0, and each w i ∈ A} 13-06-03 CSE 2001, Summer 2013 4 2
Closure Properties • Set of regular languages is closed under -- Complementation – Union – Concatenation – Star (Kleene Closure) 13-06-03 CSE 2001, Summer 2013 5 Complement of a regular language • Swap the accepting and non-accept states of M to get M ’ . • The complement of a regular language is regular. 13-06-03 CSE 2001, Summer 2013 6 3
Other closure properties Union: Can be done with DFA, but using a complicated construction. Concatenation: We tried and failed Star: ??? We introduced non-determinism in FA 13-06-03 CSE 2001, Summer 2013 7 Recall: NFA drawing conventions • Not all transitions are labeled • Unlabeled transitions are assumed to go to a reject state from which the automaton cannot escape 13-06-03 CSE 2001, Summer 2013 8 4
Closure under regular operations Union (new proof): 13-06-03 CSE 2001, Summer 2013 9 Closure under regular operations Concatenation: 13-06-03 CSE 2001, Summer 2013 10 5
Closure under regular operations Star: 13-06-03 CSE 2001, Summer 2013 11 Incorrect reasoning about RL • Since L 1 = {w| w=a n , n ∈ N }, L 2 = {w| w = b n , n ∈ N } are regular, therefore L 1 • L 2 = {w| w=a n b n , n ∈ N } is regular • If L 1 is a regular language, then L 2 = {w R | w ∈ L 1 } is regular, and Therefore L 1 • L 2 = {w w R | w ∈ L 1 } is regular 13-06-03 CSE 2001, Summer 2013 12 6
Are NFA more powerful than DFA? • NFA can solve every problem that DFA can (DFA are also NFA) • Can DFA solve every problem that NFA can? 13-06-03 CSE 2001, Summer 2013 13 Equivalence of NFA, DFA • Pages 54-58 (Sipser, 2 nd ed) • We will prove that every NFA is equivalent to a DFA (with upto exponentially more states). • Non-determinism does not help FA ’ s to recognize more languages! 13-06-03 CSE 2001, Summer 2013 14 7
Epsilon Closure • Let N=(Q, Σ , δ ,q 0 ,F) be any NFA • Consider any set R ⊆ Q • E(R) = {q|q can be reached from a state in R by following 0 or more ε -transitions} • E(R) is the epsilon closure of R under ε - transitions 13-06-03 CSE 2001, Summer 2013 15 Proving equivalence For all languages L * ⊆ Σ L L ( N ) iff L L ( M ) = = for some for some NFA N DFA M One direction is easy: A DFA M is also a NFA N. So N does not have to be `constructed ’ from M 13-06-03 CSE 2001, Summer 2013 16 8
Proving equivalence – contd. The other direction : Construct M from N • N = (Q, Σ , δ ,q 0 ,F) • Construct M= (Q ’ , Σ , δ ’ ,q ’ 0 ,F ’ ) such that, – for any string w ∈ Σ *, – w is accepted by N iff w is accepted by M 13-06-03 CSE 2001, Summer 2013 17 Special case • Assume that ε is not used in the NFA N. - Need to keep track of each subset of N - So Q ’ = P (Q), q ’ 0 = {q 0 } - δ ’ (R,a) = ∪ ( δ (r,a)) over all r ∈ R, R ∈ Q ’ - F ’ = {R ∈ Q ’ | R contains an accept state of N} • Now let us assume that ε is used. 13-06-03 CSE 2001, Summer 2013 18 9
Construction (general case) 1. Q ’ = P (Q) 2. q ’ 0 = E({q 0 }) 3. for all R ∈ Q ’ and a ∈ Σ δ ’ (R, a) = {q ∈ Q|q ∈ E( δ (r,a)) for some r ∈ R} 4. F ’ = { R ∈ Q ’ | R contains an accept state of N} 13-06-03 CSE 2001, Summer 2013 19 Why the construction works • for any string w ∈ Σ *, • w is accepted by N iff w is accepted by M • Can prove using induction on the number of steps of computation … 13-06-03 CSE 2001, Summer 2013 20 10
State minimization It may be possible to design DFA ’ s without the exponential blowup in the number of states. Consider the NFA and DFA below. 0,1 0,1 0 1 0 1 0 0,1 0 1 0 0 1 1 1 13-06-03 CSE 2001, Summer 2013 21 Characterizing FA languages • Regular expressions 13-06-03 CSE 2001, Summer 2013 22 11
Regular Expressions (Def. 1.52) Given an alphabet Σ , R is a regular expression if: (INDUCTIVE DEFINITION) • R = a, with a ∈Σ • R = ε • R = ∅ • R = (R 1 ∪ R 2 ), with R 1 and R 2 regular expressions • R = (R 1 • R 2 ), with R 1 and R 2 regular expressions • R = (R 1 *), with R 1 a regular expression Precedence order: *, • , ∪ 13-06-03 CSE 2001, Summer 2013 23 Regular Expressions • Unix ‘ grep ’ command: Global Regular Expression and Print • Lexical Analyzer Generators (part of compilers) • Both use regular expression to DFA conversion 13-06-03 CSE 2001, Summer 2013 24 12
Examples • e 1 = a ∪ b, L(e 1 ) = {a,b} • e 2 = ab ∪ ba, L(e 2 ) = {ab,ba} • e 3 = a*, L(e 3 ) = {a}* • e 4 = (a ∪ b)*, L(e 4 ) = {a,b}* • e 5 = (e m . e n ), L(e 5 ) = L(e m ) • L(e n ) • e 6 = a*b ∪ a*bb, L(e 6 ) = {w| w ∈ {a,b}* and w has 0 or more a ’ s followed by 1 or 2 b ’ s} 13-06-03 CSE 2001, Summer 2013 25 Characterizing Regular Expressions We prove that languages described by Regular expressions (RE) and Regular Languages are the same set, i.e., RE = RL 13-06-03 CSE 2001, Summer 2013 26 13
Thm 1.54: RL ~ RE We need to prove both ways: • If a language is described by a regular expression, then it is regular (Lemma 1.55) (We will show we can convert a regular expression R into an NFA M such that L(R)=L(M)) • The second part: If a language is regular, then it can be described by a regular expression (Lemma 1.60) 13-06-03 CSE 2001, Summer 2013 27 Regular expression to NFA Claim: If L = L(e) for some RE e , then L = L(M) for some NFA M Construction: Use inductive a 1. definition 1. R = a, with a ∈Σ 2. R = ε 2. 3. R = ∅ 4. R = (R 1 ∪ R 2 ), with R 1 and R 2 3. regular expressions 5. R = (R 1 • R 2 ), with R 1 and R 2 4,5,6 : similar to regular expressions closure of RL under 6. R = (R 1 *), with R 1 a regular regular operations. expression 13-06-03 CSE 2001, Summer 2013 28 14
Examples of RE to NFA conv. L = {ab,ba} L = {ab,abab,ababab, …… } L = {w | w = a m b n , m<10, n>10} 13-06-03 CSE 2001, Summer 2013 29 Back to RL ~ RE • The second part (Lemma 1.60): If a language is regular, then it can be described by a regular expression. • Proof strategy: § regular implies equivalent DFA. § convert DFA to GNFA (generalized NFA) § convert GNFA to NFA. GNFA: NFA that have regular expressions as transition labels 13-06-03 CSE 2001, Summer 2013 30 15
Example GNFA 0110 0 ∅ q S q A 01* ε 0* ∪ 11 13-06-03 CSE 2001, Summer 2013 31 Generalized NFA - defn Generalized non-deterministic finite automaton M=(Q, Σ , δ , q start , q accept ) with • Q finite set of states • Σ the input alphabet • q start the start state • q accept the (unique) accept state • δ :(Q - {q accept }) × (Q - {q start }) → R is the transition function ( R is the set of regular expressions over Σ ) (NOTE THE NEW DEFN OF δ ) 13-06-03 CSE 2001, Summer 2013 32 16
Characteristics of GNFA ’ s δ • δ :(Q\{q accept }) × (Q\{q start }) → R The interior Q\{q accept ,q start } is fully connected by δ From q start only ‘ outgoing transitions ’ To q accept only ‘ ingoing transitions ’ Impossible q i → q j transitions are labeled “ δ (q i ,q j ) = ∅ ” Observation: This GNFA R ∈ R q S q A recognizes the language L(R) 13-06-03 CSE 2001, Summer 2013 33 Proof Idea of Lemma 1.60 Proof idea (given a DFA M): Construct an equivalent GNFA M ’ with k ≥ 2 states Reduce one-by-one the internal states until k=2 This GNFA will be of the form R q S q A This regular expression R will be such that L(R) = L(M) 13-06-03 CSE 2001, Summer 2013 34 17
Recommend
More recommend