Today
• Chapter 1: • RE = Regular Languages,
• nonregular languages
• RL pumping lemma
• Chapter 2:• Context-Free Languages (CFLs)
Regular Expressions (Def. 1.26)
Given an alphabet , R is a regular expression if:
1. R = a, with a2. R = 3. R = 4. R = (R1R2), with R1 and R2 regular expressions5. R = (R1R2), with R1 and R2 regular expressions6. R = (R1*), with R1 a regular expression
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 regularexpression 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 bya regular expression (Lemma 1.32)
Generalized NFA
Generalized nondeterministic finite automaton M=(Q, , , qstart, qaccept) with• Q finite set of states• the input alphabet• qstart the start state • qaccept the accept state
• :(Q\{qaccept})(Q\{qstart}) R the transition function
• (R is the set of regular expressions over )
Example GNFA
qS qA
01*
0
0* 11
0110
Characteristics of GNFA’s
• :(Q\{qaccept})(Q\{qstart}) R
The interior Q\{qaccept,qstart} is fully connected by From qstart only ‘outgoing transitions’To qaccept only ‘ingoing transitions’Impossible qiqj transitions are “(qi,qj) = ”
qS qARRObservation: This GNFA:
recognizes the language L(R)
Proof Idea of Lemma 1.32
Proof idea (given a DFA M):
Construct an equivalent GNFA M’ with k2 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)
qS qAR
DFA M Equivalent GNFA M’
Let M have k states Q={q1,…,qk}
- Add two states qaccept and qstartqS
q1
- Connect qstart to earlier q1:
qi qj- Complete missing transitions by
qAqj
- Connect old accepting states to qaccept
- Join multiple transitions:
qi 0qj
1 becomes qi01 qj
Remove Internal state of GNFA
If the GNFA M has more than 2 states, ‘rip’internal qrip to get equivalent GNFA M’ by:- Removing state qrip: Q’=Q\{qrip}- Changing the transition function by
’(qi,qj) = (qi,qj) ((qi,qrip)((qi,qj))*(qrip,qj))
for every qiQ’\{qaccept} and qjQ’\{qstart}
qi
R4(R1R2*R3) qjqi
R2
qjR4
qripR1
R3 =
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 languageL(R) of the regular expression R
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 toa language L(M’) of a GNFA = M’, which canbe converted to a two-state M’’
The transition qstart R qacceptof M’’ obeys L(R) = L(M’’)
Hence: RE NFA = DFA GNFA RE
Nonregular Languages §1.4
Which languages cannot be recognized by finite automata?
Example: L={ 0n1n | nN }• ‘Playing around’ with FA convinces you that the ‘finiteness’ of FA is problematic for “all nN”• The problem occurs between the 0n and the 1n
• Informal: the memory of a FA is limited by the the number of states |Q|
Repeating DFA Paths
q1
qk
qj
Consider an accepting DFA M with size |Q|On a string of length p, p+1 states get visitedFor p|Q|, there must be a j such that the computational path looks like: q1,…,qj,…,qj,…,qk
Repeating DFA Paths
q1
qk
qj
The action of the DFA in qj is always the same.If we repeat (or ignore) the qj,…,qj part, the newpath will again be an accepting path
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 themore elaborate (but equivalent) NFA or GNFA
Pumping Lemma (Thm 1.37)
For every regular language L, there is a pumping length p, such that for any string sL and |s|p, we can write s=xyz with
1) x yi z L for every i{0,1,2,…}2) |y| 13) |xy| p
Note that 1) implies that xz L 2) says that y cannot be the empty string Condition 3) is not always used
Formal Proof of Pumping Lemma
Let M = (Q,,,q1,F) with Q = {q1,…,qp}Let s = s1…snL(M) with |s| = n pComputational path of M on s is thesequence r1,…,rn+1 Qn+1 withr1 = q1, rn+1F and rt+1= (rt,st) for 1tnBecause n+1 p+1, there are two statessuch that rj = rk (with j<k and k p+1)Let x = s1…sj–1, y = sj…sk–1, and z = sk…sn+1
x takes M from q1=r1 to rj, y takes M from rj to rj, and z takes M from rj to rn+1FAs a result: xyiz takes M from q1 to rn+1F (i 0)
Formal Proof of Pumping Lemma
Let M = (Q,,,q1,F) with Q = {q1,…,qp}Let s = s1…snL(M) with |s| = n pComputational path of M on s is thesequence r1,…,rn+1 Qn+1 withr1 = q1, rn+1F and rt+1= (rt,st) for 1tnBecause n+1 p+1, there are two termssuch that rj = rk (with j<k and k p+1)Let x = s1…sj–1, y = sj…sk–1, and z = sk…sn+1
x takes M from q1=r1 to rj, y takes M from rj to rj, and z takes M from rj to rn+1FAs a result: xyiz takes M from q1 to rn+1F (i 0)
|y| 1 and |xy| p
x yi z L(M) for every i{0,1,2,…}
Pumping 0n1n (Ex. 1.38)
Assume that B = {0n1n | n0} is regularLet p be the pumping length, and s = 0p1p BP.L.: s = xyz = 0p1p, with xyiz B for all i0Three options for y:
1) y=0k, hence xyyz = 0p+k1p B2) y=1k, hence xyyz = 0p1k+p B3) y=0k1l, hence xyyz = 0p1l0k1p B
Conclusion: The pumping lemma does not hold,the language B is not regular.
F = { ww | w{0,1}* } (Ex. 1.40)
Let p be the pumping length, and take s = 0p10p1Let s = xyz = 0p10p1 with condition 3) |xy|pOnly one option: y=0k, with xyyz = 0p+k10p1 F
Without 3) this would have been a pain.
Intersecting Regular Languages
Let C = { w | # of 0s in w equals # of 1s in w}Problem: If xyzC with yC, then xyizCIdea: If C is regular and F is regular, then the intersection CF has to be regular as well
Solution: Assume that C is regularTake the regular F = { 0n1m | n,mN}, then for the intersection: CF = { 0n1n | nN }But we know that CF is not regularConclusion: C is not regular
Pumping Down E = { 0i1j | ij }
Problem: ‘pumping up’ s=0p1p with y=0k givesxyyz = 0p+k1p, xy3z = 0p+2k1p, which are all in E(hence do not give contradictions)Solution: pump down to xz = 0p–k1p. Overall for s = xyz = 0p1p (with |xy|p):
y=0k, hence xz = 0p–k1p E
Contradiction: E is not regular
End Chapter One