finite automata and non determinism yukita
TRANSCRIPT
2
Definition 1.1: Finite Automaton
. theis 5.
and , theis 4.
, theis : 3.
, thecalledset finite a is 2.
, thecalledset finite a is 1.
where),,,,,( tupple-5 a is A
0
0
states accept of set
state start
function transition
alphabet
states
automatonfinite
QF
Q
FqQ
4
Data Representation for M1
.}{ 5.
and state,start theis 4.
,
10
as described is 3.
{0,1} 2.
},,{ 1.
2
1
223
232
211
321
qF
q
qqq
qqq
qqq
qqqQ
5
Task 01DFA
1. Implement M1 with your favorite programming language.
2. GUI• Two buttons for input 0 and 1• State chart with the current state highlighted
6
Language of M1
}1last thefollow 0s ofnumber even an
and 1 oneleast at contains |{)(
. say that can We
accepts. machine that strings all ofset theis
),( as written , The
1 wwML
AM
M
MLM
recognizes
machine oflanguage
8
Data Representation for M5
.}{ 5.
and state,start theis 4.
,
210
as described is 3.
,0,1,2}RESET{ 2.
},,{ 1.
0
0
10202
02101
21000
210
qF
q
qqqqq
qqqqq
qqqqq
R
qqqQ
9
Informal Description of M5
• M5 keeps a running count of the sum of the numerical symbols it reads, modulo 3.
• Every time it receives the <RESET> symbol it resets the count to 0.
• M5 accepts if the sum is 0, modulo 3.
10
Definition 1.7: Regular Language
• A language is called a regular language if some finite automaton recognizes it.
11
Example 1.9: A finite automaton E2
• E2 recognizes the regular language of all strings that contain the string 001 as a substring.
• 0010, 1001, 001, and 1111110011110 are all accepted,
• but 11 and 0000 are not.
12
Find a set of states of E2
You
1. haven’t just seen any symbols of the pattern,
2. have just seen a 0,
3. have just seen 00 or,
4. have just seen the entire pattern 001.
Assign the states q,q0,q00, and q001 to these possibilities.
14
Regular Operations on Languages
operation. a onelast theand
,operations are operations first two The
}.each and 0|{ :
}. and |{ :
}.or |{ :
languages. be and Let
21*
unary
binary
AxkxxxA
ByAxxyBA
BxAxxBA
BA
ik
Star
ionConcatenat
Union
15
Example 1.11
}. ,goodbadbad
d,goodbadgoo goodbad, good od,goodgoodgo
badbad, goodbad, goodgood, bad, good, ,{
and },badgirl badboy, goodgirl, goodboy,{
},girl boy, bad, good,{
have weThen, }.girl boy,{ and }bad good,{Let
}.z,,ba,{ be alphabet Let the
*
A
BA
BA
BA
16
Theorem 1.12 Closedness for Union
. is so
languages,regular are and if s,other wordIn
operation.union the
under closed is languagesregular of class The
21
21
AA
AA
Proof of Th 1.12 17
Proof of Theorem 1.12
on.constructi theof scorrectnes check the Then,
.),,,,( where
, recognize toConstruct
.),,,,( where, recognize and
),,,,,( where, recognize Let
21
2222222
1111111
FqQM
AAM
FqQMAM
FqQMAM
Proof of Th 1.12 18
Construction of M
}.or |),{()()( 5.
).,( 4.
)),(),,(()),,((;,),( 3.
(Why?) .alphabet
same thehave and that assumecan We2.
}. and |),{( 1.
2211212121
210
22112121
21
22112121
FrFrrrFQQFF
qqq
arararraQrr
MM
QrQrrrQQQ
Proof of Th 1.12 19
Correctness
You should check the following.
1. For any string recognized by M1 is recognized by M.
2. For any string recognized by M2 is recognized by M.
3. For any string recognized by M is recognized by M1 or M2.
20
Theorem 1.13 Closedness for concatenation
. is so
languages,regular are and if s,other wordIn operation.
ionconcatenatunder closed is languagesregular of class The
21
21
AA
AA
21
Nondeterminism
• To prove Theorem 1.13, we need nondeterminism.
• Nondeterminism is a generalization of determinism. So, every deterministic automaton is automatically a nondeterministic automaton.
22
Nondetermistic Finite Automata
• A nondeterministic finite automaton can be different from a deterministic one in that– for any input symbol, nondeterministic one
can transit to more than one states.– epsilon transition
• NFA and DFA stand for nondeterministic finite automaton and deterministic finite automaton, respectively.
25
Example 1.14 NFA N2
q3q1 q2
0,1
1 0, q4
0,1
Let language A consist of all strings over {0,1} containing a 1 in the third position from the end. N2 recognizes A.
27
Example 1.15 NFA N3
0
Let language A consist of all strings 0k , where k is a multiple of 2 or 3. N3 recognizes A.
0
0
0
0
29
Example 1.16 NFA N4
q1
q2q3
a
b
a,b
a
N4 accepts , a, baba, and baa. N4 does not accept b, nor babba.
30
Definition 1.17: NFA
. theis 5.
and , theis 4.
, theis 2: 3.
, thecalledset finite a is 2.
, thecalledset finite a is 1.
where),,,,,( tupple-5 a is A
0
0
states accept of set
state start
function transition
alphabet
states
automatonfinite nistic nondetermi
QF
Q
Q
FqQ
Q
31
Example 1.18 NFA N1
}.{ 5.
state.start theis 4.
}{}{
}{
}{}{
},{}{
10
asgiven is 3.
}1,0{ 2.
},,,,{ 1.
4
1
444
43
332
2111
4321
qF
q
qqq
qqq
qqqq
qqqqQ
q3q1 q2
0,1
1 0,q4
0,1
1
32
In what situation is Non Determinism relevant?
• Von Neumann machines are deterministic.
• However, there are many cases where machine specification is all we need.
33
Theorem 1.19
• Every nondeterministic finite automaton has an equivalent deterministic finite automaton.– Def. The two machines are equivalent is they
recognize the same language.
Proof of Th 1.19 34
Proof of Th. 1.19
}.|{ 4.
and },{ 3.
,),(),( 2.
,2 1.
such that ),,,,(Construct
arrows. no has first that assume usLet
. language some grecognizinNFA thebe ),,,,(Let
00
0
0
FRQRF
araR
Q
FqQM
N
AFqQN
Rr
Q
Proof of Th 1.19 35
Incorporate arrows
0
0 0
( ) { | can be reached from by traveling along zero or
more arrows.}
We modify as follows.
( , ) { | ( ( , )) for some }.
We modify as follows.
({ }).
We omit the correctness p
E R q q R
R a q Q q E r a r R
q
q E q
roof.
36
Corollary 1.20
• A language is regular if and only if some nondeterministic finite automaton recognizes it.
37
Example 1.21 NFA N4 to DFA
1
2 3a
b
a,b
a
}}.3,2,1{},3,2{},3,1{},2,1{},3{},2{},1{,{2
as takesbemay set state s' The .DFA equivalentan
construct want to we,}}3{,1,},,{},3,2,1{{Given
}3,2,1{
4
DD
baN
38
Task 02Parallel World
1. Write a program that simulates N4.
2. GUI– Three buttons for input 0, 1, and epsion.– State chart that reflect the branching of the
world.
39
Start and Accept states
follows. asgiven is diagram state The
}}.3,2,1{},3,2{},3,1{},3{{ is statesaccept ofset The
}.3,1{})1({ is statestart The E
42
Proof of Th. 1.22
. and for
and for },{
for ),(
for ),(
),( 4.
3.
of statestart theis state The 2.
}{ 1.
. recognize to),,,,{ Construct
. recognize ),,,,(
and , recognize ),,,,(Let
0
021
22
11
21
0
210
210
222222
111111
aqq
aqqqq
Qqaq
Qqaq
aq
FFF
N.q
QQqQ
AAFqQN
AFqQN
AFqQN
44
Proof of Th. 1.23
.for ),(
and for }{),(
and for ),(
and for ),(
),( 4.
of that as same theis statesaccept ofset The 3.
. of that as same theis statestart The 2.
1.
. recognize to),,,,{ Construct
. recognize ),,,,(
and , recognize ),,,,(Let
22
121
11
111
2
11
21
2121
222222
111111
Qqaq
aFqqaq
aFqaq
FqQqaq
aq
N
Nq
QQQ
AAFqQN
AFqQN
AFqQN