Equivalence with FA
* Any Regex can be converted to FA and vice versa,
because:
* Regex and FA are equivalent in their des...
Lemma: If a language is regular, then it is
descried by a RegEx.
Because A is regular, it is accepted by a DFA. We
descri...
GNFA is NFA, but Regex could be used as labels
on arrows. Figure 1.61 P.70 shows an example of
GNFA, which is on the spec...
To convert a NFA to GNFA (and
keep the special form)
Add a new start state with ε arrow to the old start
Add a new accep...
Convert the GNFA to RegEx
In GNFA, the start and accept states are must,
and they're different, hence no. of states (k) o...
Convert the GNFA to RegEx
The Challenge in reducing the states if greater than
2, by Ripping the a state out of the machin...
Formal definition of GNFA
Just like the DFA, it's a 5-tuple with same parameters
except for δ, which can be given as:
δ: ...
Nonregular Languages
Some languages cannot be recognized by any
FA (a limitation of FA)
Assume the language B = {0n1n | ...
Nonregular Languages
Assume we have 2 languages C and D, over the
alphabet ∑ = {0,1}, where:
C = { w | w has an equal no. ...
The pumping lemma for regular
languages
Theorem (Pumping Lemma): “All regular
languages have a special property, if a lan...
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 o...
Non­regular languages

n

{a b : n≥ 0}
vv

R

:

Regular languages
a∗b

b∗c + a

b + c ( a + b )∗¿
¿

etc . ..

11/25/13

...
How can we prove that a language L
is not regular?
Prove that there is no DFA or NFA or RE 
that accepts L 
Difficulty: th...
The Pigeonhole Principle

11/25/13
4

3

11/25/13

pigeons

pigeonholes
A pigeonhole must
contain at least two pigeons

11/25/13
n

pigeons
...........

m

pigeonholes
...........

11/25/13

n> m
The Pigeonhole Principle

pigeons

n

pigeonholes

m

n> m

There is a pigeonhole
with at least 2 pigeons

...........

11...
The Pigeonhole Principle
and
DFAs

11/25/13
Consider a DFA with 4
b

q1

b

b

a

q2

a

a
11/25/13

states

b

q3
a

q4
aaaab
Consider the walk of a “long’’ string:

(length at least 4)

A state is repeated in the walk of aaaab
a

q1

q2

b

...
The state is repeated as a result of 
the pigeonhole principle

Walk of
Pigeons:

(walk states)

q1

a

q2

a

q3

a

aaaa...
aabb
Consider the walk of a “long’’ string:
(length at least 4)

Due to the pigeonhole principle:
A state is repeated in t...
The state is repeated as a result of
the pigeonhole principle
aabb

Walk of
Pigeons:

q1

a

a

q2

q3

b

q4

b

q4

(wal...
In General:

If ∣w∣ ≥ #states of DFA,
by the pigeonhole principle,
a state is repeated in the walk

Walk of
q1

σ1

σ2

.....
∣w∣ ≥ #states of DFA =m

Pigeons: (walk states)
....
q1

Walk of
qi

....

w

qi

....

qz

Are
more
than
Nests:

q1

q2

...
The Pumping Lemma

11/25/13
Take an infinite regular language

L

(contains an infinite number of strings)

There exists a DFA that accepts

L

m

sta...
Take string

w ∈L

∣w∣ ≥ m

with

(number of
states of DFA)

then, at least one state is repeated
in the walk of w
Walk in...
There could be many states repeated
Take q to be the first state repeated
One dimensional projection of walk

w
:

First
o...
We can write

w = xyz

One dimensional projection of walk

w
:

First
occurrence
σ1

σ2

....

x=σ 1 ⋯σ i
11/25/13

σi

Se...
In DFA:

w=x y z

contains only
first occurrence of

y

...

σj

...

σ1

11/25/13

x

σi

σ i +1

q

σ j+1

...

...
z

σ...
Observation:

length

∣x y∣ ≤ m

number
of states
of DFA

y

...
Unique States
σj

...

σ1

11/25/13

x

σi

σ i +1

q

Si...
Observation:

length

∣ y∣ ≥ 1

Since there is at least one transition in loop
y

...

σj

σ i +1

q

11/25/13
We do not care about the form of string

z

x
may actually overlap with the paths of

y

...
z

...
11/25/13

x

q

z

y
a...
Additional string:

The string
is accepted

Do not follow loop

x z

y

...

σj

...

σ1

11/25/13

x

σi

σ i +1

q

σ j+...
Additional string:

The string
is accepted

Follow loop
2 times

y

...

σj

...

σ1

11/25/13

x y y z

x

σi

σ i +1

q
...
The string
is accepted

Additional string:

Follow loop
3 times

y

...

σj

...

σ1

11/25/13

x y y y z

x

σi

σ i +1

...
In General:

The string
is accepted

Follow loop
i times

xy z
i=0, 1, 2, . ..

y

...

σj

...

σ1

11/25/13

i

x

σi

σ...
i

Therefore:

x y z ∈L

i=0, 1, 2, . ..

Language accepted by the DFA
y

...

σj

...

σ1

11/25/13

x

σi

σ i +1

q

σ ...
We just described:

The Pumping Lemma !!!

11/25/13
The Pumping Lemma:
• Given a infinite regular language
• there exists an integer
• for any string w ∈ L
• we can write

(c...
In the book:
Critical length m

11/25/13

p
= Pumping length
Applications
of
the Pumping Lemma

11/25/13
Observation:
Every language of finite size has to be regular
(we can easily construct an NFA
that accepts every string in ...
Suppose you want to prove that
An infinite language L is not regular
1. Assume the opposite: L

is regular

2. The pumping...
Explanation of Step 3: How to get a contradiction
1. Let m

be the critical length for

2. Choose a particular stringw ∈ L...
Note:

It suffices to show that
only one string w ∈ L
gives a contradiction

You don’t need to obtain
contradiction for ev...
Example
Theorem: L = { 0 n 1 n | n ∈ N } is not regular.
Proof: By contradiction; assume L is regular. Let n
be the pumpin...
Case 1: y consists solely of 0s. Then xyiz = xz = 0 n - |y| 1 n ,
and since
|y| > 0, xz ∉ L.
Case 2: y consists solely of ...
Example of Pumping Lemma application

Theorem:

The language

n

n

L={a b : n≥0}
is not regular

Proof:

11/25/13

Use th...
n

n

L={a b : n≥0}
Assume for contradiction
thatL
is a regular language

SinceL
is infinite
we can apply the Pumping Lemm...
n

n

L={a b : n≥0}
Let

m

be the critical length for L

Pick a string

w

such that: w ∈ L
and length ∣w∣ ≥m
We pick

11...
From the Pumping Lemma:
m m

we can write

w=a b =x y z

with lengths

∣x y∣ ≤m , ∣ y∣≥1
m

w=

m

m m

xyz=a b = a ...aa ...
m m

k

y =a , 1≤k ≤m

x y z=a b

From the Pumping Lemma:

i

x y z ∈L
i=0, 1, 2, . ..

Thus:

11/25/13

2

x y z ∈L
m m

k

y =a , 1≤k ≤m

x y z=a b

2

x y z ∈L

From the Pumping Lemma:
m+k

m

2

xy z= a...aa...aa ...aa...ab...b ∈L
x

T...
a

BUT:

m+k

m

b ∈L

n

n

L={a b : n≥0}

a

m+k

m

b ∉L

CONTRADICTION!!!
11/25/13

k≥ 1
Therefore:

Our assumption thatL
is a regular language is not true

Conclusion: L

11/25/13

is not a regular language

EN...
Non-regular language

n n

{a b : n≥0}

Regular languages
¿ ¿

L(a b )

11/25/13
Read
P. 80 – 82 (examples)
Solve Exercises and Problems (P. 83 – 98)
Prepare for a quiz!

11/25/13
Upcoming SlideShare
Loading in …5
×

Theory of Computation - Lectures 6 & 7

563 views

Published on

Theory of Computation, GNFA, Pigeonhole, Pumping Lemma

Published in: Education, Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
563
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Theory of Computation - Lectures 6 & 7

  1. 1. Equivalence with FA * Any Regex can be converted to FA and vice versa, because: * Regex and FA are equivalent in their descriptive power ** Regular language is one that is recognized by some FA, remember? Hence: (Lemma) if a language is described by a RegEx, then it is a regular language. See Proof: P.67, example 1.56 11/25/13
  2. 2. Lemma: If a language is regular, then it is descried by a RegEx. Because A is regular, it is accepted by a DFA. We describe a procedure for converting DFAs into equivalent RegEx. Breaking the procedure into 2 parts, using a new type of FA called Generalized Nondeterministic Finite Automaton (GNFA) Hence, 1st convert DFA to GNFA, then GNFA to RegEx 11/25/13
  3. 3. GNFA is NFA, but Regex could be used as labels on arrows. Figure 1.61 P.70 shows an example of GNFA, which is on the special form that it should ALWAYS have. 11/25/13
  4. 4. To convert a NFA to GNFA (and keep the special form) Add a new start state with ε arrow to the old start Add a new accept state with ε arrow coming from the old accept state. If any arrow has more than one label, or there are more than one arrow between two states on the same direction, replace with one arrow and “union” the labels If two states have no arrows between them, add an arrow with Φ label 11/25/13
  5. 5. Convert the GNFA to RegEx In GNFA, the start and accept states are must, and they're different, hence no. of states (k) of any GNFA is always >=2. If k>2, then GNFA is constructed by reducing the number to k=2 (an arrow form start to accept states) whose label is the RegEx. Example, converting a 3 state DFA to RegEx. 3k DFA > 5k GNFA > 4k GNFA > 3k GNFA > 2k GNFA > RegEx 11/25/13
  6. 6. Convert the GNFA to RegEx The Challenge in reducing the states if greater than 2, by Ripping the a state out of the machine (other than the start, accept states), we call it q rip , we repair the machine by altering the removed qrip with labeled arrow. The label should cover the absence of qrip .The new label form start to accept states is the RegEx. Figure 1.63 P. 72 11/25/13
  7. 7. Formal definition of GNFA Just like the DFA, it's a 5-tuple with same parameters except for δ, which can be given as: δ: (Q - {qaccept }) X (Q – {qstart}) → R R is the collection of all RegEx over the alphabet ∑, The domain of the transition function is (Q - {qaccept }) X (Q – {qstart}) simply because in GNFA, an arrow connects every state to every other state, except no arrows are coming from qaccept or going to qstart. Read: P.73 - 76 11/25/13
  8. 8. Nonregular Languages Some languages cannot be recognized by any FA (a limitation of FA) Assume the language B = {0n1n | n>=0}. No DFA can recognize it because the resulting number of 0s is unlimited, and therefore no DFA can remember this number of possibilities. But just because the language appears to require unbounded memory doesn't mean it's nonregular. So we need a method to prove the nonregularity 11/25/13
  9. 9. Nonregular Languages Assume we have 2 languages C and D, over the alphabet ∑ = {0,1}, where: C = { w | w has an equal no. of 0s and 1s}, and D = { w | w has an equal number of occurrences of 01 and 10 as substrings} Which one is nonregular? See problem 1.48 >> Difficult? We need a mathematical proof for certainty. 11/25/13
  10. 10. The pumping lemma for regular languages Theorem (Pumping Lemma): “All regular languages have a special property, if a language doesn't have that property, it is not regular”. The property states that all strings in the language can be “pumped” if they are at least as long as a certain special value called the “pumping length”. In other words: Such string contains a section that can be repeated any number of times with the resulting string remaining in the language 11/25/13
  11. 11. 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 divided into three pieces, s=xyz, satisfying the conditions: 1- for each i>=0, xyiz ∈ A 2- |y| >0, and 3- |xy| <= p. Figure 1.71 P.78 11/25/13
  12. 12. Non­regular languages n {a b : n≥ 0} vv R : Regular languages a∗b b∗c + a b + c ( a + b )∗¿ ¿ etc . .. 11/25/13 n v ∈ {a , b } ∗¿ ¿ ¿ ¿
  13. 13. How can we prove that a language L is not regular? Prove that there is no DFA or NFA or RE  that accepts L  Difficulty: this is not easy to prove (since there is an infinite number  of them) Solution: use the Pumping Lemma !!! 11/25/13
  14. 14. The Pigeonhole Principle 11/25/13
  15. 15. 4 3 11/25/13 pigeons pigeonholes
  16. 16. A pigeonhole must contain at least two pigeons 11/25/13
  17. 17. n pigeons ........... m pigeonholes ........... 11/25/13 n> m
  18. 18. The Pigeonhole Principle pigeons n pigeonholes m n> m There is a pigeonhole with at least 2 pigeons ........... 11/25/13
  19. 19. The Pigeonhole Principle and DFAs 11/25/13
  20. 20. Consider a DFA with 4 b q1 b b a q2 a a 11/25/13 states b q3 a q4
  21. 21. aaaab Consider the walk of a “long’’ string: (length at least 4) A state is repeated in the walk of aaaab a q1 q2 b q1 a q3 a a q3 b a q2 b q4 b a a 11/25/13 q2 q3 b a q4
  22. 22. The state is repeated as a result of  the pigeonhole principle Walk of Pigeons: (walk states) q1 a q2 a q3 a aaaab q2 a q3 b q4 Are more than q1 Nests: (Automaton states) 11/25/13 q2 q3 Repeated state q4
  23. 23. aabb Consider the walk of a “long’’ string: (length at least 4) Due to the pigeonhole principle: A state is repeated in the walk of aabb a q1 q2 b a q3 b q4 b q4 b b q1 a q2 a a 11/25/13 q3 b a q4
  24. 24. The state is repeated as a result of the pigeonhole principle aabb Walk of Pigeons: q1 a a q2 q3 b q4 b q4 (walk states) Are more than Nests: (Automaton states) 11/25/13 q1 q2 q3 Automaton States q4 Repeated state
  25. 25. In General: If ∣w∣ ≥ #states of DFA, by the pigeonhole principle, a state is repeated in the walk Walk of q1 σ1 σ2 .... σi w = σ 1 σ 2 ⋯σ k qi σ i +1 σj .... qi σ j+1 .... σk Arbitrary DFA q1 11/25/13 σ1 σ2 w ...... qi ...... Repeated state σk qz qz
  26. 26. ∣w∣ ≥ #states of DFA =m Pigeons: (walk states) .... q1 Walk of qi .... w qi .... qz Are more than Nests: q1 q2 (Automaton states) 11/25/13 .... qi .... A state is repeated q m−1 qm
  27. 27. The Pumping Lemma 11/25/13
  28. 28. Take an infinite regular language L (contains an infinite number of strings) There exists a DFA that accepts L m states 11/25/13
  29. 29. Take string w ∈L ∣w∣ ≥ m with (number of states of DFA) then, at least one state is repeated in the walk of w Walk in DFA of w = σ 1 σ 2 ⋯σ k σ1 σ2 ...... q ...... σk Repeated state in DFA 11/25/13
  30. 30. There could be many states repeated Take q to be the first state repeated One dimensional projection of walk w : First occurrence σ1 σ2 .... σi Second occurrence q σ i +1 Unique states 11/25/13 .... σj q σ j+1 .... σk
  31. 31. We can write w = xyz One dimensional projection of walk w : First occurrence σ1 σ2 .... x=σ 1 ⋯σ i 11/25/13 σi Second occurrence q σ i +1 .... y =σ i +1 ⋯σ j σj q σ j+1 .... σk z=σ j +1 ⋯σ k
  32. 32. In DFA: w=x y z contains only first occurrence of y ... σj ... σ1 11/25/13 x σi σ i +1 q σ j+1 ... ... z σk q
  33. 33. Observation: length ∣x y∣ ≤ m number of states of DFA y ... Unique States σj ... σ1 11/25/13 x σi σ i +1 q Since, in xy no state is repeated (except q)
  34. 34. Observation: length ∣ y∣ ≥ 1 Since there is at least one transition in loop y ... σj σ i +1 q 11/25/13
  35. 35. We do not care about the form of string z x may actually overlap with the paths of y ... z ... 11/25/13 x q z y and
  36. 36. Additional string: The string is accepted Do not follow loop x z y ... σj ... σ1 11/25/13 x σi σ i +1 q σ j+1 ... ... z σk
  37. 37. Additional string: The string is accepted Follow loop 2 times y ... σj ... σ1 11/25/13 x y y z x σi σ i +1 q σ j+1 ... ... z σk
  38. 38. The string is accepted Additional string: Follow loop 3 times y ... σj ... σ1 11/25/13 x y y y z x σi σ i +1 q σ j+1 ... ... z σk
  39. 39. In General: The string is accepted Follow loop i times xy z i=0, 1, 2, . .. y ... σj ... σ1 11/25/13 i x σi σ i +1 q σ j+1 ... ... z σk
  40. 40. i Therefore: x y z ∈L i=0, 1, 2, . .. Language accepted by the DFA y ... σj ... σ1 11/25/13 x σi σ i +1 q σ j+1 ... ... z σk
  41. 41. We just described: The Pumping Lemma !!! 11/25/13
  42. 42. The Pumping Lemma: • Given a infinite regular language • there exists an integer • for any string w ∈ L • we can write (critical length) with length ∣w∣ ≥ m w=x y z • with ∣x y∣ ≤ m • such that: 11/25/13 m L i and x y z ∈L ∣ y∣ ≥ 1 i=0, 1, 2, . ..
  43. 43. In the book: Critical length m 11/25/13 p = Pumping length
  44. 44. Applications of the Pumping Lemma 11/25/13
  45. 45. Observation: Every language of finite size has to be regular (we can easily construct an NFA that accepts every string in the language) Therefore, every non-regular language has to be of infinite size (contains an infinite number of strings) 11/25/13
  46. 46. Suppose you want to prove that An infinite language L is not regular 1. Assume the opposite: L is regular 2. The pumping lemma should hold forL 3. Use the pumping lemma to obtain a contradiction 4. Therefore, L is not regular 11/25/13
  47. 47. Explanation of Step 3: How to get a contradiction 1. Let m be the critical length for 2. Choose a particular stringw ∈ L ∣w∣≥m the length condition 3. Write L which satisfies w=xyz 4. Show that ' i w =xy z∉L for some 5. This gives a contradiction, since from ' i pumping lemma w =xy z∈L 11/25/13 i≠1
  48. 48. Note: It suffices to show that only one string w ∈ L gives a contradiction You don’t need to obtain contradiction for everyw ∈ L 11/25/13
  49. 49. Example Theorem: L = { 0 n 1 n | n ∈ N } is not regular. Proof: By contradiction; assume L is regular. Let n be the pumping length guaranteed by the pumping lemma. Consider the string w = 0 n 1 n . Then |w| = 2n ≥ n and w ∈ L, so we can write w = xyz such that y ≠ ε and for any natural number i, xyiz ∈ L. We consider three cases:
  50. 50. Case 1: y consists solely of 0s. Then xyiz = xz = 0 n - |y| 1 n , and since |y| > 0, xz ∉ L. Case 2: y consists solely of 1s. Then xy i z = xz = 0 n 1 n - |y| , and since |y| > 0, xz ∉ L. Case 3: y consists of k 0s followed by m 1s. Then xy i z has the form 0 n 1 m 0 k 1 n + m , so xy i z ∉ L. In all three cases we reach a contradiction, so our assumption was wrong and L is not regular. ■
  51. 51. Example of Pumping Lemma application Theorem: The language n n L={a b : n≥0} is not regular Proof: 11/25/13 Use the Pumping Lemma
  52. 52. n n L={a b : n≥0} Assume for contradiction thatL is a regular language SinceL is infinite we can apply the Pumping Lemma 11/25/13
  53. 53. n n L={a b : n≥0} Let m be the critical length for L Pick a string w such that: w ∈ L and length ∣w∣ ≥m We pick 11/25/13 m w=a b m
  54. 54. From the Pumping Lemma: m m we can write w=a b =x y z with lengths ∣x y∣ ≤m , ∣ y∣≥1 m w= m m m xyz=a b = a ...aa ... aa .. . ab.. . b x 11/25/13 Thus: k y z y =a , 1≤k ≤m
  55. 55. m m k y =a , 1≤k ≤m x y z=a b From the Pumping Lemma: i x y z ∈L i=0, 1, 2, . .. Thus: 11/25/13 2 x y z ∈L
  56. 56. m m k y =a , 1≤k ≤m x y z=a b 2 x y z ∈L From the Pumping Lemma: m+k m 2 xy z= a...aa...aa ...aa...ab...b ∈L x Thus: 11/25/13 y a y m+k z m b ∈L
  57. 57. a BUT: m+k m b ∈L n n L={a b : n≥0} a m+k m b ∉L CONTRADICTION!!! 11/25/13 k≥ 1
  58. 58. Therefore: Our assumption thatL is a regular language is not true Conclusion: L 11/25/13 is not a regular language END OF PROOF
  59. 59. Non-regular language n n {a b : n≥0} Regular languages ¿ ¿ L(a b ) 11/25/13
  60. 60. Read P. 80 – 82 (examples) Solve Exercises and Problems (P. 83 – 98) Prepare for a quiz! 11/25/13

×