PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is...
Transcript of PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is...
![Page 1: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/1.jpg)
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
15-453
![Page 2: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/2.jpg)
THE PUMPING LEMMA FOR REGULAR LANGUAGES
and REGULAR EXPRESSIONS
TUESDAY Jan 21
![Page 3: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/3.jpg)
WHICH OF THESE ARE REGULAR ?
D = { w | w has equal number of 1s and 0s}
C = { w | w has equal number of occurrences of 01 and 10 }
B = {0n1n | n ≥ 0}
![Page 4: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/4.jpg)
THE PUMPING LEMMA
Let L be a regular language with |L| = ∞
Then there is a positive integer P s.t.
1. |y| > 0 (y isn’t ε) 2. |xy| ≤ P 3. For every i ≥ 0, xyiz ∈ L
if w ∈ L and |w| ≥ P then can write w = xyz, where:
Why is it called the pumping lemma? The word w gets PUMPED into something longer…
![Page 5: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/5.jpg)
Let P be the number of states in M
Assume w ∈ L is such that |w| ≥ P
r0 rj rk r|w|
…
There must be j and k such that j < k ≤ P, and rj = rk (why?) (Note: k - j > 0)
Proof: Let M be a DFA that recognizes L
1. |y| > 0 2. |xy| ≤ P 3. xyiz ∈ L for all i ≥ 0
We show: w = xyz
![Page 6: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/6.jpg)
Let P be the number of states in M
Assume w ∈ L is such that |w| ≥ P
r0 rj= rk
r|w| …
There must be j and k such that j < k ≤ P, and rj = rk
Proof: Let M be a DFA that recognizes L
1. |y| > 0 2. |xy| ≤ P 3. xyiz ∈ L for all i ≥ 0
We show: w = xyz
y
![Page 7: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/7.jpg)
z
Let P be the number of states in M
Assume w ∈ L is such that |w| ≥ P
r0 rj= rk
r|w| …
There must be j and k such that j < k ≤ P, and rj = rk
Proof: Let M be a DFA that recognizes L
1. |y| > 0 2. |xy| ≤ P 3. xyiz ∈ L for all i ≥ 0
We show: w = xyz
x
y
![Page 8: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/8.jpg)
USING THE PUMPING LEMMA
Let’s prove that B = {0n1n | n ≥ 0} is not regular
Assume B is regular. Let w = 0P1P
If B is regular, can write w = xyz, |y| > 0, |xy| ≤ P, and for any i ≥ 0, xyiz is also in B
y must be all 0s:
xyyz has more 0s than 1s
|xy| ≤ P
Contradiction!
Why?
![Page 9: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/9.jpg)
USING THE PUMPING LEMMA
D = { w | w has equal number of 1s and 0s} is not regular Assume D is regular. Let w = 0P1P (w is in D!)
If D is regular, can write w = xyz, |y| > 0, |xy| ≤ P, where for any i ≥ 0, xyiz is also in D
y must be all 0s:
xyyz has more 0s than 1s
|xy| ≤ P
Contradiction!
Why?
![Page 10: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/10.jpg)
WHAT DOES D LOOK LIKE?
D = { w | w has equal number of occurrences of 01 and 10}
![Page 11: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/11.jpg)
WHAT DOES C LOOK LIKE?
1 ∪ 0 ∪ ε ∪ 0(0∪1)*0 ∪ 1(0∪1)*1
C = { w | w has equal number of occurrences of 01 and 10}
= { w | w = 1, w = 0, w = ε or w starts with a 0 and ends with a 0 or w starts with a 1 and ends with a 1 }
![Page 12: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/12.jpg)
REGULAR EXPRESSIONS (expressions representing languages)
σ is a regexp representing {σ}
ε is a regexp representing {ε}
∅ is a regexp representing ∅
If R1 and R2 are regular expressions representing L1 and L2 then:
(R1R2) represents L1 ⋅ L2 (R1 ∪ R2) represents L1 ∪ L2 (R1)* represents L1*
![Page 13: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/13.jpg)
PRECEDENCE
* ⋅ ∪
![Page 14: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/14.jpg)
R2 R1* (
EXAMPLE
R1*R2 ∪ R3 = ( ) ) ∪ R3
![Page 15: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/15.jpg)
{ w | w has exactly a single 1 }
0*10*
![Page 16: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/16.jpg)
What language does ∅* represent?
![Page 17: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/17.jpg)
What language does ∅* represent?
{ε}
![Page 18: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/18.jpg)
{ w | w has length ≥ 3 and its 3rd symbol is 0 }
![Page 19: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/19.jpg)
{ w | w has length ≥ 3 and its 3rd symbol is 0 }
(0∪1)(0∪1)0(0∪1)*
![Page 20: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/20.jpg)
{ w | every odd position of w is a 1 }
![Page 21: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/21.jpg)
{ w | every odd position of w is a 1 }
(1(0 ∪ 1))*(1 ∪ ε)
![Page 22: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/22.jpg)
L can be represented by a regexp ⇔ L is regular
EQUIVALENCE
L can be represented by a regexp ⇒ L is regular
1.
L can be represented by a regexp
L is a regular language ⇐
2.
![Page 23: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/23.jpg)
Base Cases (R has length 1):
R = σ σ
R = ε
R = ∅
Given regular expression R, we show there exists NFA N such that R represents L(N)
Induction on the length of R:
1.
![Page 24: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/24.jpg)
Inductive Step:
Assume R has length k > 1, and that every regular expression of length < k represents a regular language
Three possibilities for R:
R = R1 ∪ R2
R = R1 R2
R = (R1)*
(Union Theorem!) (Concatenation)
(Star)
Therefore: L can be represented by a regexp ⇒ L is regular
![Page 25: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/25.jpg)
Give an NFA that accepts the language represented by (1(0 ∪ 1))*
1 ε 1,0
ε
![Page 26: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/26.jpg)
L can be represented by a regexp ⇒
L is a regular language ⇐
Proof idea: Transform an NFA for L into a regular expression by removing states and re-labeling arrows with regular expressions
2.
![Page 27: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/27.jpg)
NFA ε ε
ε
ε
ε
Add unique and distinct start and accept states While machine has more than 2 states: Pick an internal state, rip it out and re-label the arrows with regexps, to account for the missing state
0
1
0
![Page 28: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/28.jpg)
NFA ε ε
ε
ε
ε
Add unique and distinct start and accept states While machine has more than 2 states: Pick an internal state, rip it out and re-label the arrows with regexps, to account for the missing state
01*0
![Page 29: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/29.jpg)
NFA ε ε
ε
ε
ε
While machine has more than 2 states:
R(q1,q2)
R(q2,q2)
R(q2,q3) q1 q2 q3
G
R(q1,q3)
More generally:
![Page 30: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/30.jpg)
NFA ε ε
ε
ε
ε
While machine has more than 2 states:
More generally:
G
R(q1,q2)R(q2,q2)*R(q2,q3)
∪ R(q1,q3) q1 q3
![Page 31: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/31.jpg)
q1 b
a
ε q2
a,b
ε q0 q3
R(q0,q3) = represents L(N)
![Page 32: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/32.jpg)
q1 b
a
ε q2
a,b
ε q0 q3
R(q0,q3) = represents L(N)
R(q0,q3) = (a*b)(a∪b)*
![Page 33: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/33.jpg)
Formally:
Run CONVERT(G): (Outputs a regexp) If #states = 2
return the expression on the arrow going from qstart to qaccept
Add qstart and qaccept to create G (GNFA)
![Page 34: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/34.jpg)
Formally: Add qstart and qaccept to create G (GNFA)
If #states > 2 select qrip∈Q different from qstart and qaccept
define Q′ = Q – {qrip}
define R′ as: R′(qi,qj) = R(qi,qrip)R(qrip,qrip)*R(qrip,qj) ∪ R(qi,qj)
return CONVERT(G′)
Run CONVERT(G): (Outputs a regexp)
} Defines: G′ (GNFA)
(R′ = the regexps for edges in G′) We note that G and G′ are equivalent
![Page 35: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/35.jpg)
Claim: CONVERT(G) is equivalent to G Proof by induction on k (number of states in G)
Base Case: k = 2
Inductive Step: Assume claim is true for k-1 state GNFAs
Recall that G and G′ are equivalent
But, by the induction hypothesis, G′ is equivalent to CONVERT(G′)
Thus: CONVERT(G′) equivalent to CONVERT(G)
QED
![Page 36: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/36.jpg)
q3
q2
b
a
b
q1
b
a
a
![Page 37: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/37.jpg)
q3
q2
b
a
b
q1
b
a
a
ε
ε
ε
![Page 38: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/38.jpg)
q2
b
a
b
q1 a
a
ε
ε
ε
bb
![Page 39: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/39.jpg)
bb ∪ (a ∪ ba)b*a
q1
ε
b b ∪ (a ∪ ba)b*
(bb ∪ (a ∪ ba)b*a)* (b ∪ (a ∪ ba)b*)
![Page 40: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/40.jpg)
Convert the NFA to a regular expression
q3
q2
b
b q1
a
a, b
b
![Page 41: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/41.jpg)
DFA NFA
Regular Language
Regular Expression
DEFINITION
![Page 42: PowerPoint Presentationlblum/flac/Lectures_pdf/Lecture3.pdf · 2014-02-03 · Claim: CONVERT(G) is . equivalent. to G . Proof by induction on k (number of states in G) Base Case:](https://reader033.fdocuments.net/reader033/viewer/2022042019/5e7690efc4e88503c417ab78/html5/thumbnails/42.jpg)
WWW.FLAC.WS Finish Chapter 1 of the book for next time