计算理论导引4
4. q1 is the start state, 5. F={q2}. how °{1}*°{0}∪ ∪ by ° ∪°∗ {0}*°{1}to describe A {1})°{1}*∪ {0}*°operations?(∪,°,∗) 0*11*0(0∪1)1*∪0*11* the regular°{1}°{1}* ∪ °({0}∪ ∪ °
CHAPTER 2 COMPUTATIONAL MODELS(3)
A={w|w contains at least one 1 and even number of 0s follow the last 1}
0 1 0,1 q1 1 q2 0 q3
1.Q ={q1, q2, q3}, 2. Σ ={0,1}, 3. δ is desribed as 0 1 q1 q1 q2 q2 q3 q2 q3 q2 q2
CHAPTER 2 COMPUTATIONAL MODELS(3)
•Regular Expressions FORMAL DEFINITION OF A REGULAR EXPRESSION Say that R is a regular expression if R is 1.a for some a in the alphabet Σ, 2.ε, 3. ∅, 4.(R1∪R2), where R1 and R2 are regular expressions, 5.(R1°R2), where R1 and R2 are regular expressions,or * 6.(R1), where R1 is a regular expression.
CHAPTER 2 COMPUTATIONAL MODELS(3)
PROOF IDEA M=(Q, Σ, δ, q1,F), A=L(M), p is the number of states of M, s=s1s2…sn is a string in A of length n ,where n≥p. r1,…,rn+1 is sequence of states that M enters while computing s. So, n+1>p. In r1,…,rp+1, there must be a special state which occurs twice. r1,…, rj ,…, rk ,…, rp+1,…,rn+1, where rj=rk, j≠k and k≤p+1. x=s1…sj-1, y=sj…sk-1, z=sk…sn. y z x r1→ rj, rj→rk, rk→rn+1. When i=0, for s1…sj-1sk…sn=xz there is r1,…,rk ,…, rp+1,…,rn+1. When i>0, for s1…sj-1sj…sk-1…sj…sk-1sk…sn=xy iz.
CHAPTER 2 COMPUTATIONAL MODELS(3)
0*1 1* ε 0 ∪ 0*11* ∪ 0*11*0 (0∪1) 1* ε qs 1 ε q2 1 0 0∪1 ∪ q3 (0∪1)1* ε ∪
qs
q1
ε0*1 0*11* 0
CHAPTER 2 COMPUTATIONAL MODELS(3)
a sequence of states q0,q1, … ,qk exists such that 1.q0=qstart is the start state, 2.qk=qaccept is the accept state,and 3.for each i, we have wi∈L(Ri), where Ri=δ(qi-1,qi). ∈
ε qs ε q1 1 q2 0 0∪1 ∪ q3
CHAPTER 2 COMPUTATIONAL MODELS(3)
A GNFA accept a string w in Σ* if w=w1w2…wk, where each wi is in Σ* and a sequence of states q0,q1, … ,qk exists such that 1.q0=qstart is the start state, 2.qk=qaccept is the accept state,and 3.for each i, we have wi∈L(Ri), where Ri=δ(qi-1,qi). CONVERT(G): 1.Let k be the number of states of G. 2.If k=2, then Q must consist of a start state, an accept state, and a single arrow connecting them and labeled with a regular expression R. Return the expression. 3.If k>2,we select any state qdrip∈Q different from qstart and qaccept and let G’ be the GNFA (Q’, Σ, δ’ qstart,qaccept ) δ’(qi,qj)=(R1)(R2)*(R3)∪(R4),for R1= δ(qi,qdrip), R2= δ(qdrip,qdrip) ∪ R3=δ(qdrip,qj), R4= δ(qi,qj). pute CONVERT(G’) and return this value.
CHAPTER 2 COMPUTATIONAL MODELS(3)
CLAIM 2.1 For any GNFA G,CONVERT(G) is equivalent to G. PROOF IDEA 1. For any GNFA G(Q, Σ, δ, qstart,qaccept), if |Σ|=2, then CONVERT(G) is equivalent to G obviously ; 2. Assume that the claim is true for G with |Σ|=k-1; Let G’ is a GNFA converted from G by CONVERT(G) and |G’|=k 1, so for G’ the claim is true. If we can prove that G is equivalent to G’, then the claim is also true for G with |Σ|=k. So we should prove that any string w=w1w2…wk accepted by … G can also be accepted by G’, vice versa.
•NONREGULAR LANGUAGES Σ={0,1} C={w|w has an equal number of 0s and 1s} D={w|w has an equal number of occurrences 01 and 10 as substrings} THEOREM 2.7 Pumping lemma If A is a regular language, then there is a number p (the pumping length) where, if s is any string in A of length at least p, then s may be divide into three pieces, s=xyz, satisfy the following conditions: 1.For each i ≥0, xy iz∈A ∈ 2.|y|>0, and 3.|xy|≤p. ≤
y i y
there is r1,…, rj,…,rk,…,rj,…,rk,…,rp+1,…,rn+1 . As j≠k and k≤p+1,so |y|>0, |xy| ≤p.
CHAPTER 2 COMPUTATIONAL MODELS(3)
Σ={0,1} B={0n1n|n≥0} ≥ p: the p pumping length p S= 0 1 =xyz 1.When y consists only of 0s, xyyz will have more 0s than 1s; 2.When y consists only of 1s, xyyz will have more 1s than 0s; 3. When y consists of both0s and 1s, xyyz will have the incorrect order of 1s and 0s; Σ={0,1} C={w|w has an equal number of 0s and 1s} p=? s=?
CHAPTER 2 COMPUTATIONAL MODELS(3)
Precedence: *,°,∪ °∪ + R=RR* Rk L(R) Σ={0,1} A={w|w contains a single 1}= L(0*10*) A={w|w has at last one 1}= L(Σ*1Σ*) Σ Σ A={w|w contains the string 001 as substring 1}=L(Σ*001Σ*) Σ Σ A={w|every 0 in w is followed by at last one 1 }= L((01+)*) A={w|w is a string of even length}=L((ΣΣ ΣΣ)*) ΣΣ A={w|the length of w is a multiple of three}=L((ΣΣΣ ΣΣΣ)*) ΣΣΣ A={01,10}=L(01∪10) ∪ Σ ∪ Σ A={w|w starts and ends with the same symbol}= L(0Σ*0∪1Σ* 1∪0∪1) ∪ ∪ (0∪ε ∪ε)1*=01*∪1*,L((0∪ε ∪ε ∪ε)(1∪ε ∪ε ∪ ∪ε ∪ε))={ε,0,1,01},L(1*∅)= ∅, L(∅*)={ε} ε ∅ ∅ ε