Upload
juniper-cameron
View
213
Download
0
Embed Size (px)
DESCRIPTION
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.
Citation preview
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
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
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.
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
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
Convert the GNFA to RegExThe 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 qrip , 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
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
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
Nonregular LanguagesAssume we have 2 languages C and D, over
the alphabet ∑ = {0,1}, where:
C = { w | w has an equal no. of 0s and 1s}, andD = { 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.
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
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
Fall 2006 Costas Busch - RPI 12
Regular languages
ba* acb *
...etc*)( bacb
Non-regular languages }0:{ nba nn
}*},{:{ bavvvR
Fall 2006 Costas Busch - RPI 13
How can we prove that a language Lis 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 !!!
Fall 2006 Costas Busch - RPI 14
The Pigeonhole Principle
pigeons
pigeonholes
4
3
Fall 2006 Costas Busch - RPI 16
A pigeonhole mustcontain at least two pigeons
Fall 2006 Costas Busch - RPI 17
...........
...........
pigeons
pigeonholes
n
m mn
Fall 2006 Costas Busch - RPI 18
The Pigeonhole Principle
...........
pigeonspigeonholesnm
mn There is a pigeonhole with at least 2 pigeons
Fall 2006 Costas Busch - RPI 19
The Pigeonhole Principle
and
DFAs
Fall 2006 Costas Busch - RPI 20
Consider a DFA with states 4
1q 2q 3qa
b
4q
b
a b
b
a a
Fall 2006 Costas Busch - RPI 21
Consider the walk of a “long’’ string:
1q 2q 3qa
b
4q
b
b
b
a a
a
aaaab
1q 2q 3q 2q 3q 4qa a a a b
A state is repeated in the walk of
(length at least 4)
aaaab
Fall 2006 Costas Busch - RPI 22
aaaab
1q 2q 3q 2q 3q 4qa a a a b
1q 2q 3q 4q
Pigeons:
Nests:(Automaton states)
Are more than
Walk of
The state is repeated as a result of the pigeonhole principle
(walk states)
Repeatedstate
Fall 2006 Costas Busch - RPI 23
Consider the walk of a “long’’ string:
1q 2q 3qa
b
4q
b
bb
a a
a
aabb
1q 2q 3q 4q 4qa a b b
A state is repeated in the walk of
(length at least 4)Due to the pigeonhole principle:
aabb
Fall 2006 Costas Busch - RPI 24
aabb
1q 2q 3q 4qAutomaton States
Pigeons:
Nests:(Automaton states)
Are more than
Walk of
The state is repeated as a result of the pigeonhole principle
(walk states)1q 2q 3q 4q 4qa a b b
Repeatedstate
Fall 2006 Costas Busch - RPI 25
iq...... ......Repeated state
kw 21
1 2 k
Walk of
iq.... iq.... ....1 2 ki j1i 1j
Arbitrary DFA
DFA of states#|| wIf ,by the pigeonhole principle,a state is repeated in the walk
In General:
1q zq
zq1q
w
Fall 2006 Costas Busch - RPI 26
mDFA of states#|| w
1q 2q 1mq mq
Walk of wPigeons:
Nests:(Automaton states)
Are morethan
(walk states)iq....
iq.... ....1q
iq.... ....
zq
A state is repeated
Fall 2006 Costas Busch - RPI 27
The Pumping Lemma
Fall 2006 Costas Busch - RPI 28
Take an infinite regular language L
There exists a DFA that accepts L
mstates
(contains an infinite number of strings)
Fall 2006 Costas Busch - RPI 29
mw ||(number of states of DFA)
then, at least one state is repeated in the walk of w
q...... ......1 2 k
Take string with Lw
kw 21Walk in DFA of
Repeated state in DFA
Fall 2006 Costas Busch - RPI 30
Take to be the first state repeatedq
q....
w
There could be many states repeated
q.... ....
Second occurrence
First occurrence
Unique states
One dimensional projection of walk :
1 2 ki j1i 1j
Fall 2006 Costas Busch - RPI 31
q.... q.... ....
Second occurrence
First occurrence
1 2 ki j1i 1j
wOne dimensional projection of walk :
ix 1 jiy 1 kjz 1
xyzwWe can write
Fall 2006 Costas Busch - RPI 32
zyxw
q... ...
x
y
z
In DFA:
...
...
1 ki1ij
1j
contains only first occurrence of q
Fall 2006 Costas Busch - RPI 33
Observation: myx ||length numberof statesof DFA
Since, in no state is repeated (except q)
xy
Unique States
q...
x
y
...
1 i1ij
Fall 2006 Costas Busch - RPI 34
Observation: 1|| ylength
Since there is at least one transition in loop
q
y
...
1ij
Fall 2006 Costas Busch - RPI 35
We do not care about the form of string z
q...
x
y
z
...
zmay actually overlap with the paths of and x y
Fall 2006 Costas Busch - RPI 36
The string is accepted
zxAdditional string:
q... ...
x z
...
Do not follow loopy
...
1 ki1ij
1j
Fall 2006 Costas Busch - RPI 37
The string is accepted
zyyx
q... ... ...
x z
Follow loop2 times
Additional string:
y
...
1 ki1ij
1j
Fall 2006 Costas Busch - RPI 38
The string is accepted
zyyyx
q... ... ...
x z
Follow loop3 times
Additional string:
y
...
1 ki1ij
1j
Fall 2006 Costas Busch - RPI 39
The string is accepted
zyx iIn General:...,2,1,0i
q... ... ...
x z
Follow loop timesi
y
...
1 ki1ij
1j
Fall 2006 Costas Busch - RPI 40
Lzyx i Therefore: ...,2,1,0i
Language accepted by the DFA
q... ... ...
x z
y
...
1 ki1ij
1j
Fall 2006 Costas Busch - RPI 41
In other words, we described:
The Pumping Lemma !!!
Fall 2006 Costas Busch - RPI 42
The Pumping Lemma:• Given a infinite regular language L
• there exists an integer m
• for any string with length Lw mw ||
• we can write zyxw
• with andmyx || 1|| y
• such that: Lzyx i ...,2,1,0i
(critical length)
Fall 2006 Costas Busch - RPI 43
In the book:
Critical length = Pumping lengthm p
Fall 2006 Costas Busch - RPI 44
Applications
of
the Pumping Lemma
Fall 2006 Costas Busch - RPI 45
Observation:Every language of finite size has to be regular
Therefore, every non-regular languagehas to be of infinite size (contains an infinite number of strings)
(we can easily construct an NFA that accepts every string in the language)
Fall 2006 Costas Busch - RPI 46
Suppose you want to prove thatAn infinite language is not regular
1. Assume the opposite: is regular
2. The pumping lemma should hold for
3. Use the pumping lemma to obtain a contradiction
L
L
L
4. Therefore, is not regular L
Fall 2006 Costas Busch - RPI 47
Explanation of Step 3: How to get a contradiction
2. Choose a particular string which satisfies the length condition
Lw
3. Write xyzw
4. Show that Lzxyw i for some 1i
5. This gives a contradiction, since from pumping lemma Lzxyw i
mw ||
1. Let be the critical length for m L
Fall 2006 Costas Busch - RPI 48
Note: It suffices to show that only one stringgives a contradiction
Lw
You don’t need to obtaincontradiction for every Lw
Fall 2006 Costas Busch - RPI 49
Theorem: The language }0:{ nbaL nn
is not regular
Proof: Use the Pumping Lemma
Example of Pumping Lemma application
Fall 2006 Costas Busch - RPI 50
Assume for contradictionthat is a regular languageL
Since is infinitewe can apply the Pumping Lemma
L
}0:{ nbaL nn
Fall 2006 Costas Busch - RPI 51
Let be the critical length for
Pick a string such that: w Lw
mw ||and length
mmbawWe pick
m
}0:{ nbaL nn
L
Fall 2006 Costas Busch - RPI 52
with lengths
From the Pumping Lemma:
1||,|| ymyx
babaaaaabaxyz mm ............
mkay k 1,
x y z
m m
we can write zyxbaw mm
Thus:
w
Fall 2006 Costas Busch - RPI 53
From the Pumping Lemma: Lzyx i
...,2,1,0i
Thus:
mmbazyx
Lzyx 2
mkay k 1,
Fall 2006 Costas Busch - RPI 54
From the Pumping Lemma:
Lbabaaaaaaazxy ...............2
x y z
km m
Thus:
Lzyx 2
mmbazyx
y
Lba mkm
mkay k 1,
Fall 2006 Costas Busch - RPI 55
Lba mkm
}0:{ nbaL nnBUT:
Lba mkm
CONTRADICTION!!!
1≥k
Fall 2006 Costas Busch - RPI 56
Our assumption thatis a regular language is not true
L
Conclusion:L is not a regular language
Therefore:
END OF PROOF
Fall 2006 Costas Busch - RPI 57
Regular languages
Non-regular language }0:{ nba nn
)( **baL
Read
P. 80 – 82 (examples)Solve Exercises and Problems (P. 83 – 98) Prepare for a quiz!