Lecture3
Lecture3
FORMAL LANGUAGES,
AUTOMATA AND
COMPUTABILITY
THE PUMPING LEMMA FOR
REGULAR LANGUAGES
and
REGULAR EXPRESSIONS
TUESDAY Jan 21
WHICH OF THESE ARE REGULAR ?
B = {0n1n | n ≥ 0}
…
r0 rj rk r|w|
…
r0 rj= rk r|w|
Contradiction!
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
Contradiction!
WHAT DOES D LOOK LIKE?
1 ∪ 0 ∪ ε ∪ 0(0∪1)*0 ∪ 1(0∪1)*1
REGULAR EXPRESSIONS
(expressions representing languages)
* ⋅ ∪
EXAMPLE
R1*R2 ∪ R3 = ( ( R1* ) R2 ) ∪ R3
{ w | w has exactly a single 1 }
0*10*
What language does ∅* represent?
What language does ∅* represent?
{ε}
{ w | w has length ≥ 3 and its 3rd symbol is 0 }
{ w | w has length ≥ 3 and its 3rd symbol is 0 }
(0∪1)(0∪1)0(0∪1)*
{ w | every odd position of w is a 1 }
{ w | every odd position of w is a 1 }
(1(0 ∪ 1))*(1 ∪ ε)
EQUIVALENCE
L can be represented by a regexp
⇔ L is regular
R=ε
R=∅
Inductive Step:
Assume R has length k > 1,
and that every regular expression of length < k
represents a regular language
R = R1 ∪ R2 (Union Theorem!)
R = R1 R2 (Concatenation)
R = (R1)* (Star)
ε 1 1,0
ε
2. L can be represented by a regexp
⇐
⇒
L is a regular language
1
ε
ε
ε
ε 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
ε
ε
ε
ε GNFA
ε
While machine has more than 2 states:
More generally:
R(q1,q3)
R(q1,q2) R(q2,q3)
q1 q2 q3
R(q2,q2)
ε
ε
ε
ε GNFA
ε
While machine has more than 2 states:
More generally:
R(q1,q2)R(q2,q2)*R(q2,q3)
q1 q3
∪ R(q1,q3)
a a,b
ε b ε
q0 q1 q2 q3
R(q0,q3) =
represents L(N)
a a,b
ε b ε
q0 q1 q2 q3
R(q0,q3) = (a*b)(a∪b)*
represents L(N)
Formally: Add qstart and qaccept to create G (GNFA)
Run CONVERT(G): (Outputs a regexp)
If #states = 2
return the expression on the arrow
going from qstart to qaccept
Formally: Add qstart and qaccept to create G (GNFA)
Run CONVERT(G): (Outputs a regexp)
If #states > 2
select qrip∈Q different from qstart and qaccept
define Q′ = Q – {qrip}
define R′ as:
} Defines: G′ (GNFA)
return CONVERT(G′)
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′)
a
q1 q2
a
b
b a
q3
b
a
q1 q2
a
ε
b
ε
b a
q3 ε
b
bb
a
q1 q2
a
ε
b
ε
a
ε
bb ∪ (a ∪ ba)b*a
q1
ε
b ∪ (a ∪ ba)b*
a, b
q1 q2 b
b
a b
q3
DFA NFA
DEFINITION
Regular Regular
Language Expression
WWW.FLAC.WS
Finish Chapter 1 of the book for next time