# Today Chapter 1: RE = Regular Languages, nonregular languages RL pumping lemma Chapter 2: Context-Free Languages (CFLs)

Post on 22-Dec-2015

213 views

Embed Size (px)

TRANSCRIPT

- Slide 1
- Today Chapter 1: RE = Regular Languages, nonregular languages RL pumping lemma Chapter 2: Context-Free Languages (CFLs)
- Slide 2
- Regular Expressions (Def. 1.26) Given an alphabet , R is a regular expression if: 1.R = a, with a 2.R = 3.R = 4.R = (R 1 R 2 ), with R 1 and R 2 regular expressions 5.R = (R 1 R 2 ), with R 1 and R 2 regular expressions 6.R = (R 1 *), with R 1 a regular expression
- Slide 3
- Thm 1.28: RL ~ RE We need to prove both ways: If a language is described by a regular expression, then it is regular (Lemma 1.29) (Last week we saw how we can convert a regular expression R into an NFA M such that L(R)=L(M)) Today we do the second part: If a language is regular, then it can be described by a regular expression (Lemma 1.32)
- Slide 4
- Generalized NFA Generalized nondeterministic 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 accept state :(Q\{q accept }) (Q\{q start }) R the transition function ( R is the set of regular expressions over )
- Slide 5
- Example GNFA qSqS qAqA 01* 0 0* 11 0110
- Slide 6
- Characteristics of GNFAs :(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 (q i,q j ) = qSqS qAqA RRRR Observation: This GNFA: recognizes the language L(R)
- Slide 7
- Proof Idea of Lemma 1.32 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 This regular expression R will be such that L(R) = L(M) qSqS qAqA R
- Slide 8
- DFA M Equivalent GNFA M Let M have k states Q={q 1,,q k } - Add two states q accept and q start qSqS q1q1 - Connect q start to earlier q 1 : qiqi qjqj - Complete missing transitions by qAqA qjqj - Connect old accepting states to q accept - Join multiple transitions: qiqi 0 qjqj 1 becomes qiqi 0101 qjqj
- Slide 9
- Remove Internal state of GNFA If the GNFA M has more than 2 states, rip internal q rip to get equivalent GNFA M by: - Removing state q rip : Q=Q\{q rip } - Changing the transition function by (q i,q j ) = (q i,q j ) ( (q i,q rip )( (q i,q j ))* (q rip,q j )) for every q i Q\{q accept } and q j Q\{q start } qiqi R 4 (R 1 R 2 *R 3 ) qjqj qiqi R2R2 qjqj R4R4 q rip R1R1 R3R3 =
- Slide 10
- Proof Lemma 1.32 Let M be DFA with k states Create equivalent GNFA M with k+2 states Reduce in k steps M to M with 2 states The resulting GNFA describes a single regular expressions R The regular language L(M) equals the language L(R) of the regular expression R
- Slide 11
- Recap Regular Languages = Regular Expressions Let R be a regular expression, then there exists an NFA M such that L(R) = L(M) The language L(M) of a DFA M is equivalent to a language L(M) of a GNFA = M, which can be converted to a two-state M The transition q start R q accept of M obeys L(R) = L(M) Hence: RE NFA = DFA GNFA RE
- Slide 12
- Nonregular Languages 1.4 Which languages cannot be recognized by finite automata? Example: L={ 0 n 1 n | n N } Playing around with FA convinces you that the finiteness of FA is problematic for all n N The problem occurs between the 0 n and the 1 n Informal: the memory of a FA is limited by the the number of states |Q|
- Slide 13
- Repeating DFA Paths q1q1 qkqk qjqj Consider an accepting DFA M with size |Q| On a string of length p, p+1 states get visited For p |Q|, there must be a j such that the computational path looks like: q 1,,q j,,q j,,q k
- Slide 14
- Repeating DFA Paths q1q1 qkqk qjqj The action of the DFA in q j is always the same. If we repeat (or ignore) the q j,,q j part, the new path will again be an accepting path
- Slide 15
- Line of Reasoning Proof by contradiction: Assume that L is regular Hence, there is a DFA M that recognizes L For strings of length |Q| the DFA M has to repeat itself Show that M will accept strings outside L Conclude that the assumption was wrong Note that we use the simple DFA, not the more elaborate (but equivalent) NFA or GNFA
- Slide 16
- Pumping Lemma (Thm 1.37) For every regular language L, there is a pumping length p, such that for any string s L and |s| p, we can write s=xyz with 1) x y i z L for every i {0,1,2,} 2) |y| 1 3) |xy| p Note that 1) implies that xz L 2) says that y cannot be the empty string Condition 3) is not always used
- Slide 17
- Formal Proof of Pumping Lemma Let M = (Q, , ,q 1,F) with Q = {q 1,,q p } Let s = s 1 s n L(M) with |s| = n p Computational path of M on s is the sequence r 1,,r n+1 Q n+1 with r 1 = q 1, r n+1 F and r t+1 = (r t,s t ) for 1 t n Because n+1 p+1, there are two states such that r j = r k (with j
- Slide 18
- Formal Proof of Pumping Lemma Let M = (Q, , ,q 1,F) with Q = {q 1,,q p } Let s = s 1 s n L(M) with |s| = n p Computational path of M on s is the sequence r 1,,r n+1 Q n+1 with r 1 = q 1, r n+1 F and r t+1 = (r t,s t ) for 1 t n Because n+1 p+1, there are two terms such that r j = r k (with j
- Slide 19
- Pumping 0 n 1 n (Ex. 1.38) Assume that B = {0 n 1 n | n 0} is regular Let p be the pumping length, and s = 0 p 1 p B P.L.: s = xyz = 0 p 1 p, with xy i z B for all i 0 Three options for y: 1) y=0 k, hence xyyz = 0 p+k 1 p B 2) y=1 k, hence xyyz = 0 p 1 k+p B 3) y=0 k 1 l, hence xyyz = 0 p 1 l 0 k 1 p B Conclusion: The pumping lemma does not hold, the language B is not regular.
- Slide 20
- F = { ww | w {0,1}* } (Ex. 1.40) Let p be the pumping length, and take s = 0 p 10 p 1 Let s = xyz = 0 p 10 p 1 with condition 3) |xy| p Only one option: y=0 k, with xyyz = 0 p+k 10 p 1 F Without 3) this would have been a pain.
- Slide 21
- Intersecting Regular Languages Let C = { w | # of 0s in w equals # of 1s in w} Problem: If xyz C with y C, then xy i z C Idea: If C is regular and F is regular, then the intersection C F has to be regular as well Solution: Assume that C is regular Take the regular F = { 0 n 1 m | n,m N}, then for the intersection: C F = { 0 n 1 n | n N } But we know that C F is not regular Conclusion: C is not regular
- Slide 22
- Pumping Down E = { 0 i 1 j | i j } Problem: pumping up s=0 p 1 p with y=0 k gives xyyz = 0 p+k 1 p, xy 3 z = 0 p+2k 1 p, which are all in E (hence do not give contradictions) Solution: pump down to xz = 0 pk 1 p. Overall for s = xyz = 0 p 1 p (with |xy| p): y=0 k, hence xz = 0 pk 1 p E Contradiction: E is not regular End Chapter One

Recommended

View more >