Date post: | 02-Jun-2018 |
Category: |
Documents |
Upload: | san-lizas-airen |
View: | 245 times |
Download: | 3 times |
of 61
8/10/2019 Chapter04 Martin
1/61
Chapter : 04
Non determinism Kleenes theorem
8/10/2019 Chapter04 Martin
2/61
A language is regular if & only if it can be accepted by a finite
automata.
An alternate approach is to consider a formal device.
NFA accepts exactly the same languages as FAs.
There is a straight forward procedure of converting an NFA to
FA
8/10/2019 Chapter04 Martin
3/61
Example: A simpler approach to accept{11,110}*{0}
FA for {11,110}* {0} as per on page 113
p s
q0
r
tu
01
0,1
0
0
0
0,1
1 11
8/10/2019 Chapter04 Martin
4/61
NFA for {11,110}*{0}
q1
q3q2
q0q4
0
011
1
1
NFA
8/10/2019 Chapter04 Martin
5/61
Differences b/w an NFA & FA
An ordinary FA is deterministic:
The moves it makes while processing an input string are
completely determined by input symbols and the states .
wrong guesses will never cause us to accept a string that is
not in the language .
If a string is in language then at least one guess will lead it tothe accepting state and for a string not in the language no
sequence of guesses will cause the string to be accepted .
8/10/2019 Chapter04 Martin
6/61
In FA the transitions (that are possible)depends on:
Q(state set) and (set of symbols)
:Q x Q
8/10/2019 Chapter04 Martin
7/61
Where as the behavior of an NFA is unpredictable, the moves
are based on guesses
In NFA there are no transitions for both signals or with more
than one same output degree from a state thus it no longer
represents Alanguage recognizing machine or Recognitionalgorithm.
Guessing wrong might result in a NOanswer for a string that
is actually in the language
8/10/2019 Chapter04 Martin
8/61
In NFA we say :
:Q x 2Q
(where 2Q
is the subset of Q).
Every state may/may not be accessible when is applied.
8/10/2019 Chapter04 Martin
9/61
Definition of Non-deterministic Finite
Automata
A NFA (NON-DETERMINISTIC FINITE AUTOMATA) is a 5tuple
M= (Q, , q0, A, ).
Where:
q0Q , A c Q.
Q and are non-empty finite sets.
is set of alphabets, Q is the set of states.
q0is the initial state ,A is the accepting state. set of transitions.
8/10/2019 Chapter04 Martin
10/61
Like FA the transition * for an NFA M is the set of states
that M can legally be in result .
For example:
* (p,xa) = (*(p,x)a)
Where x is a string in *, pis any state and ais a symbol.
Its possible that the same input string leads to two or more
different accepting states or to different states ,thus in NFA we
must write * (p,) = {p} where as * (p,) = p in FA.
8/10/2019 Chapter04 Martin
11/61
A simpler way to say Mcan be obtained from pi-1to pi
processing aiOR p is one of the states to which M can get
from pi-1 by processing aiis:
pi( pi-1 , ai)
8/10/2019 Chapter04 Martin
12/61
NONRECURSIVE DEFINITION OF
* FOR NFA
For an NFA M= (Q, , q0, A, ) and any p Q, *(p, ) = {p}.
For any p Q any x=a1,a2,a3.an * (with n1),*(p,x) is
the set of all states q for which there is a sequence of states
p=p0,p1,pn-1,pn = q satisfying.
pi(pi-1,ai) for each iwith 1 i n
(pg # 126)
8/10/2019 Chapter04 Martin
13/61
RECURSIVE DEFINITION OF *
FOR NFA
Let M= (Q, , q0, A, ) be an NFA .
The function *:Q x *2Q
is defined as follow:
1. For any q Q , * (q, ) = {q}.
2. For any q Q, y * and a.
* (q, y,a) = U r *(q,y)(r,a)
(pg # 127)
8/10/2019 Chapter04 Martin
14/61
For example if pi* (p0,a1,a2,.ai)
e.g. if i= n-1
pn-1* (p,y) and pn(pn-1,an)
Where we assume y= a1,a2,a3,.an-1.
If pn= q * (p,y,an) then there is a state r (namely r= pn-1) in
the set *(p,y) so that q (r,an).
8/10/2019 Chapter04 Martin
15/61
Its clear that this agreement can be reversed :
If q (r,an) for some r * (p,y, an)
Thus by recursive formula we need:
=> * (p,y, an) = U r *(p,y) (r,an)
8/10/2019 Chapter04 Martin
16/61
Acceptance by an NFA
Let M= (Q, ,q0, A, ) be an NFA .
The string x * is accepted by M if * (q0,x) n A
(i.e. there exists at least one state which is also an acceptingstate )
For any language L,L c *,L is recognized by M if L=L(M).
8/10/2019 Chapter04 Martin
17/61
Example 4.2 Using the recursive
definition of * in NFA Let M= (Q, , q0, A, ) be an NFA .
Where Q= {q0,q1,q2,q3} , = {0,1} , A= {q3} and is given by the
following table:
Table 4.1:
q (q,0) (q,1)
q0 {q0} {q0,q1}
q1 {q2} {q2}q2 {q3} {q3}
q3
8/10/2019 Chapter04 Martin
18/61
NFA:
q0 q1 q2 q31 0,1 0,1
0,1
Now here we try to determine L(M) by calculating *(q0,x)
for few strings x of increasing length.
Using the table 4.1:
*(q0,0) = {q1} and *(q0,1) = {q0,q1}
8/10/2019 Chapter04 Martin
19/61
1. *(q0,11) = U r *(q0,1)(r,1) = U r {q0,q1}(r,1)
(q0,1) U (q1,1)
{q0
,q1
} U {q2
}
{q0,q1,q2}
2.*(q0,01) = U r *(q0,0)(r,1) = U r {q0}(r,1)
(q0,1)
{q0,q1}
8/10/2019 Chapter04 Martin
20/61
3. *(q0,111) = U r *(q0,11)(r,1)
(q0,1) U (q1,1)U (q3,1)
{q0,q1,q2,q3} accepting M
4. *(q0,011) = U r *(q0,01)(r,1)
(q0,1) (q1,1)
{q0,q1,q2}
8/10/2019 Chapter04 Martin
21/61
The language recognized by M is {0,1}*{1} {0,1}2
the language (0+1)* 1 (0+1)* has length at least 3 thus calledL3with one at the 3rdlast position as we need 4 states for L3
in diagram.
Thus in general we can construct NFA with string length n1using (n+1) states that recognize Ln.
NFA recognizing the language may have fewer states than an
FA recognizing the same language.
8/10/2019 Chapter04 Martin
22/61
COMPUTATION TREES FOR NFAs
Are used to visualize the behavior of the NFA. If x=101101 is a
string from the language {0,1}* U {1} U {0,1}2 then the
computation tree is given by:-
8/10/2019 Chapter04 Martin
23/61
q0
q2q0
q1q0
q0
q1q3
q2
q3
q0 q1
q2
q3
q0
q0 q1
A computation tree for the NFA
processing 101101
0
1 1
0
1
1 1
1
0
11
0
1 1
0
1
8/10/2019 Chapter04 Martin
24/61
SUBSET CONSTRUCTION
SUBSET construction rule is used to convert an NFA FA
Consider the NFA :
q0 q1 q2 q3
1 0,1 0,1
0,1
8/10/2019 Chapter04 Martin
25/61
Here let:
Q= {q0,q1,q2,q3} , = {0,1} , A= {q3} and is given by the following
table:
Table 4.1:
M= (Q, , q0, A, )
q (q,0) (q,1)
q0 {q0} {q0,q1}
q1 {q
2} {q
2}
q2 {q3} {q3}
q3
8/10/2019 Chapter04 Martin
26/61
The subset construction can produce an FA with as many as
16 states, since Q has 16 subsets
In general if an NFA has n states then the corresponding FA
will have 2nstates
The transitions are computed using the recursive definition of* for NFA (page# 127 Martin )
From calculation we obtain 8 different states i.e.
{q0, q0q1, q0q2, q0q1q2, q0q3, q0q1q3, q0q2q3, q0q1q2q3}
8/10/2019 Chapter04 Martin
27/61
INPUT:
See diagram on pg#132
PG#132
state 0 1
q0 q0 {q0q1}
q0q1 {q0q2} {q0q1q2}
q0q2 {q0q3} {q0q1q3}
8/10/2019 Chapter04 Martin
28/61
Example NFADFA: the subset
constructionConsider the NFA:
q1
q0
q3q2
q4
1 10
01
1
8/10/2019 Chapter04 Martin
29/61
The transitions are:
The distinct states of FA that are necessary in the order thaey
appear turn out to be
{q0}, {q4},{q1q2}, {q0q3} , {}, {q0q3}, {q0q4}
States(q) (q,0) (q,1)q0 q4 q1q2
q4
q1q2 q0q3
q0q3 q0q4 q1q2
q0q4 q4 q1q2
8/10/2019 Chapter04 Martin
30/61
Thus the DFA obtained is :
q0
q1q2
q0q3
q4
q0q4
0,1
01
0,1 0
0
0
1 11
8/10/2019 Chapter04 Martin
31/61
Solve exercise 4.20
8/10/2019 Chapter04 Martin
32/61
NONDETERMINISTIC FINITE
AUTOMATA WITH -TRANSITIONS
The transitions from state to state in both NFA and FA are
initiated by processing an input symbol. The definition of NFA
is now relaxed to allow state transitions without requiring
input to be processed.
A transition without any input string is called - transition.
The class of NFA that utilizes -transitions is denoted NFA
such transitions give further differences b/w NFA and DFA the
-NFA provides a useful tool for the design of machines
accepting complex languages
8/10/2019 Chapter04 Martin
33/61
Definition of NFA with -transitions
NFA with -transitions (abbreviated as NFA- ) is a 5-tuple
M= (Q, , q0, A, ) ,where Q and are finite sets, q0Q ,
A c Q and :Q x( U { }) 2Q.
8/10/2019 Chapter04 Martin
34/61
Example:
suppose we have an NFA for the two languages L1={0} {1}* &
L2= {0}* {1},respectively over {0,1}
NFA accepting {0} {1}*
NFA accepting {0}* {1}
p0
q1
0
1
q0
p1
0
1
8/10/2019 Chapter04 Martin
35/61
The concatenation of the two languages L1 and L2 is 01*0*1
with NFA- as:-
NFA for 01*0*1:
M1 M2
q0 q1 p0 p1
0
1
0,1
0
1
1
8/10/2019 Chapter04 Martin
36/61
NFA- for 01*0*1:-
The union of the two languages is L1 U L2 is 01* +0*1
NFA accepting 01* + 0*1:-
p0q1q0p1
0
1 0
1
q0 q1
p0 p1
0
1
10
01
8/10/2019 Chapter04 Martin
37/61
NFAaccepting 01* + 0*1:
q0
p0 p1
q1
0
0
1
1
8/10/2019 Chapter04 Martin
38/61
As before in NFA we need to define an extended function *
in order to give a precise definition of a string by a NFA-
There is now further complications as processing the string x
allows the possibility of -transitions interspersed among
ordinary transitions therefore 01 is same as 01.
8/10/2019 Chapter04 Martin
39/61
NON-RECURSIVE DEFINITION OF *
FOR NFA- For NFA- , M= (Q, , q0, A, ).,states p , q Q , A c Q.
String x=a1,a2,a3.an *.
We will say M moves from p to q by a sequence of transitions
corresponding to x if there exists an integer m n.
A sequence b1,b2,b3b.m U {} satisfyingb1,b2,b3.bm=x and a sequence of states
p=p1,p2,p3.pm =q, so that for each I with 1im, pi(pi-1,pi)
8/10/2019 Chapter04 Martin
40/61
For x * and p Q, *(p,x) is the set of states qQ.
There is a sequence of transitions corresponding to x by which
M moves from p to q.
Study only definition (-closure of set of states pg # 137)
Study Recursive definition of * for an NFA-
l l h d f f
8/10/2019 Chapter04 Martin
41/61
Example: applying the definition of
(s)and*
q0
p
t
r s
uv
w
1
1
0 0
0
0
0
1
8/10/2019 Chapter04 Martin
42/61
Here;
*(q0,) = ({qo})
=> {q0,p,t}
=> *(q0,0) =
=> ({p} U {p} u {U}) = {p,u} => {p,u}
(U p*(q0,)(p.0)) = (q0,0) U (p,0) U (t,0)
8/10/2019 Chapter04 Martin
43/61
*(q0,01) = (U r *(q0,0)(p,1)
=> ((p,1) U S(u,) )
({r,})
({r})
{r}
*(q0,010) = (U p *(q0,0)(p,0)
((r,0) U () )
({s})
{s,w, q0,p,t}
i.e. 010 is accepting string
8/10/2019 Chapter04 Martin
44/61
The NFAs are no more powerful than FAs regarding to the
languages they accept .Thus we have to convert NFA-toequivalent NFA.
Theorem:(pg# 139)
If L c *is a language accepted by the NFA-, M= (Q, , q0, A, )
then there is an NFA M1 M1= (Q, , q1, A1, ) that also
accepts L
Note: technically we think NFA as generalization of FA
NFA-as generalization of NFA
8/10/2019 Chapter04 Martin
45/61
Theorem : (pg# 142)
For any alphabet and the language L c *, the three
statements are equivalent
1. L can be recognized by FA
2. L can be recognized by NFA
3. L can be recognized by NFA-
E l 4 7 ti NFA t
8/10/2019 Chapter04 Martin
46/61
Example :4.7 converting NFA- to
NFA
Let M be an NFA- which accepts {0}*{01}*{0}*.
The transitions are shown in tabular form :
Table 4.2:
States q (q, ) (q, 0) (q, 1)
A {B} {A}
B {D} {C}
C {B}
D {D}
8/10/2019 Chapter04 Martin
47/61
NFA- FOR 0* (01)*0*:
A B
C
D
1000
8/10/2019 Chapter04 Martin
48/61
CONVERTING NFA- DFA
INPUT:
NFA-
input transition function t of M
1. Initialize Q to -closure (q0)
2. Repeat
M= (Q, , q0, A, )
8/10/2019 Chapter04 Martin
49/61
2.1 If there is a node XQ and a symbol awith no
leaving X labeled a
2.1.2 If Y Q, then set Q:= Q U {Y}
2.1.3 Add on arc from X to Y labeled a
Else done:= true
Until done
3.Set of accepting states of DFA is F = {X Q| X contains an
element qiF }
8/10/2019 Chapter04 Martin
50/61
From the table 4.2 for NFA- to NFA we get:
We can simply write:A{A,B}; B {C,D} ; C {B} And D ={D}
A
C
B
D
00
0
0
0 1
0
0
1
8/10/2019 Chapter04 Martin
51/61
NFA FA
q * (q,0) *(q,1)
A ABCD
ABCD ABCD BD
BD CD
CD D BD
D D
8/10/2019 Chapter04 Martin
52/61
THE FA OBTAINED:
D
ABCD
BD
D
CD
0
1
1
0
0,11
0
0
1
0
1
ANOTHER EXAMPLE OF
8/10/2019 Chapter04 Martin
53/61
ANOTHER EXAMPLE OF
CONVERTING NFA- NFA
Suppose we are given an NFA- that accepts 0*((01)*1 U 1*0)
q (q, ) (q,0) (q,1)A {B,D} {A,C} {D}
B {C} {E}
C {B}
D {E} {D}
E
8/10/2019 Chapter04 Martin
54/61
NFA- that accepts 0*((01)*1 U 1*0)
A
C
B
D
E
0
0 1
1
1
0
8/10/2019 Chapter04 Martin
55/61
NFA FA
NFA accepting 0*((01)*1 U 1*0)
q (q,0) (q,1)
A {A,B,C,D,E} {D,E}
B {C} {E}
C {B}
D {E} {D}
E
A
B
C
D
E
0
0
0,1
0
01
1
0
0,1
8/10/2019 Chapter04 Martin
56/61
NFA-FAq 0 1
A ABCDE DE
ABCDE ABCDE BDE
DE E D
BDE CE DE
E
D E D
CE B
DE E D
B C E
C B
TRANSITIONS ARE GIVEN DRAW THE FINAL FA
8/10/2019 Chapter04 Martin
57/61
EXAMPLE (PG#151)
NFA- FOR ((0 + 1)*10 + (00)*(11)*)*
For ((0 + 1)*10)
0
0
0
1
1
1
8/10/2019 Chapter04 Martin
58/61
For ((00)* (11)*)
0
0
1
1
1
1
0
0,1 dead state
8/10/2019 Chapter04 Martin
59/61
NFA- for ((0 + 1)*10 + (00)* (11)*)
0
0
0
1
1
0 0
1
1
0,1
1
0
1
1
8/10/2019 Chapter04 Martin
60/61
Kleenes theorem (part 2): (pg#151)
Language accepted by any FA is regular
See example of theorem application (part 2) pg# 154-155
8/10/2019 Chapter04 Martin
61/61
end of chapter 04