Upload
phungtuong
View
224
Download
0
Embed Size (px)
Citation preview
Formal Languages and Automata - Yonsei CS 2
Finite Accepter
Input
“Accept”or
“Reject”
String
FiniteAutomaton
Output
Formal Languages and Automata - Yonsei CS 3
Contents
For Models of Language Generation
• Deterministic Finite Accepters(DFA)- What is DFA? transition graph- The languages which DFA accepts regular language
• Nondeterministic Finite Accepters (NFA)- What is NFA?- Equivalence of DFA & NFA- Reduction of Number of States in FA
Formal Languages and Automata - Yonsei CS 4
Deterministic Accepters
statesfinal ofset a:stateinitial:
function) (totalfunction transition:alphabetinput ofset finite a:
statesinternal ofset finite a :),,,,(DFA.
0
0
QFQq
QFqQMDef
⊆∈
→∑×∑
∑=⋅
δ
δ
10 ),( qaq =δ
Finite Accepters: Deterministic in their operation
• At the initial time, q0 with input mechanism on the leftmost symbol of the input string.•When the end of the string, the string is accepted if the automaton is one of its final states. Otherwise, reject.•The transitions from one internal state to another by δ
Formal Languages and Automata - Yonsei CS 5
DFA : Transition Graph
: states finalstate initial
) symbolinput : label (on transiti: edge
states :vertex
⋅⋅
⋅q1q0
aiq|Q|
a
To visualize and represent finite automata
10 ),( qaq =δ
Formal Languages and Automata - Yonsei CS 6
Input Alphabet Σ
0q 1q 2q 3q 4qa b b a
5qa a bb
ba,
{ }ba,=Σ
ba,
),,,,(DFA 0 FqQM δ∑=
Formal Languages and Automata - Yonsei CS 7
Set of Internal States Q
0q 1q 2q 3q 4qa b b a
5qa a bb
ba,
{ }543210 ,,,,, qqqqqqQ =
ba,
),,,,(DFA 0 FqQM δ∑=
Formal Languages and Automata - Yonsei CS 8
Initial State 0q
1q 2q 3q 4qa b b a
5qa a bb
ba,
ba,
0q
),,,,(DFA 0 FqQM δ∑=
Formal Languages and Automata - Yonsei CS 9
Set of Final States F
0q 1q 2q 3qa b b a
5qa a bb
ba,
{ }4qF =
ba,
4q
),,,,(DFA 0 FqQM δ∑=
Formal Languages and Automata - Yonsei CS 10
Transition Function δ
0q 1q 2q 3q 4qa b b a
5qa a bb
ba,
QQ →Σ×:δ
ba,
),,,,(DFA 0 FqQM δ∑=
Formal Languages and Automata - Yonsei CS 14
Transition Function δ
0q 1q 2q 3q 4qa b b a
5qa a bb
ba,
δ a b0q1q2q3q4q5q
1q 5q5q 2q5q 3q4q 5q
ba,5q5q5q5q
Formal Languages and Automata - Yonsei CS 15
Transition Graph
initialstate
finalstate
“accept”statetransition
abba -Finite Accepter
0q 1q 2q 3q 4qa b b a
5qa a bb
ba,
ba,
Formal Languages and Automata - Yonsei CS 16
Initial Configuration
1q 2q 3q 4qa b b a
5qa a bb
ba,
Input Stringa b b a
ba,
0q
Formal Languages and Automata - Yonsei CS 17
Reading the Input
0q 1q 2q 3q 4qa b b a
5qa a bb
ba,
a b b a
ba,
Formal Languages and Automata - Yonsei CS 21
0q 1q 2q 3q 4qa b b a
Output: “accept”
5qa a bb
ba,
a b b a
ba,
Input finished
Formal Languages and Automata - Yonsei CS 26
0q 1q 2q 3q 4qa b b a
5qa a bb
ba,Output:“reject”
a b a
ba,
Input finished
Formal Languages and Automata - Yonsei CS 27
Another Rejection
1q 2q 3q 4qa b b a
5qa a bb
ba,
ba,
0q
λ
Formal Languages and Automata - Yonsei CS 28
1q 2q 3q 4qa b b a
5qa a bb
ba,
ba,
0q
Output:“reject”
λ
Formal Languages and Automata - Yonsei CS 29
Extended Transition Function *δ
QQ →Σ× *:*δ
0q 1q 2q 3q 4qa b b a
5qa a bb
ba,
ba,
String rather than a symbol
Thus, its value gives the state the automaton will be in after reading that string.
Formal Languages and Automata - Yonsei CS 30
( ) 20,* qabq =δ
3q 4qa b b a
5qa a bb
ba,
ba,
0q 1q 2q
Formal Languages and Automata - Yonsei CS 31
( ) 40,* qabbaq =δ
0q 1q 2q 3q 4qa b b a
5qa a bb
ba,
ba,
Formal Languages and Automata - Yonsei CS 32
( ) 50,* qabbbaaq =δ
1q 2q 3q 4qa b b a
5qa a bb
ba,
ba,
0q
Formal Languages and Automata - Yonsei CS 33
( ) qwq ′=,*δ
Observation: There is a walk from to with label
q q′w
q q′w
q q′kw σσσ L21=
1σ 2σ kσ
Formal Languages and Automata - Yonsei CS 34
( ) 50,* qabbbaaq =δ
1q 2q 3q 4qa b b a
5qa a bb
ba,
ba,
0q
Example: There is a walk from to with label
0qabbbaa
5q
Formal Languages and Automata - Yonsei CS 35
Recursive Definition
( )( ) )),,(*(,*
,*σδδσδ
λδwqwq
qq=
=
q q′σw1q
( )
qwq
′=
′=
),(
,*
1 σδ
σδ
( )
( ) 1
1
,*
),(,*
qwq
qwq
=
=
δ
σδσδ
( ) )),,(*(,* σδδσδ wqwq =
Formally, can be defined recursively by*δ
Formal Languages and Automata - Yonsei CS 36
0q 1q 2q 3q 4qa b b a
5qa a bb
ba,
ba,
( )( )
( )( )( )( )( )
( )2
1
0
0
0
0
,,,
,,,*),,(*
,*
qbq
baqbaq
baqabq
=
=
=
=
=
δδδ
λδδδδδ
δ
Formal Languages and Automata - Yonsei CS 37
Languages Accepted by DFAsTake a DFA
Definition:The language contains all input strings accepted by
= { strings that drive to a final state}
M
( )MLM
M( )ML
Formal Languages and Automata - Yonsei CS 38
Example
0q 1q 2q 3q 4qa b b a
5qa a bb
ba,
ba,
( ) { }abbaML = M
accept
Formal Languages and Automata - Yonsei CS 39
Another Example
0q 1q 2q 3q 4qa b b a
5qa a bb
ba,
ba,
( ) { }abbaabML ,,λ= M
acceptacceptaccept
Formal Languages and Automata - Yonsei CS 40
FormallyFor a DFA
Language accepted by :
( )FqQM ,,,, 0δΣ=
M
( ) ( ){ }FwqwML ∈Σ∈= ,*:* 0δ
0q q′w Fq ∈′
Formal Languages and Automata - Yonsei CS 41
ObservationLanguage rejected by :
( ) ( ){ }FwqwML ∉Σ∈= ,*:* 0δ
M
0q q′w Fq ∉′
Formal Languages and Automata - Yonsei CS 42
More Examples
a
b ba,
ba,
0q 1q 2q
( ) }0:{ ≥= nbaML n
accept trap state
If b is the last symbol of the input, accept.Otherwise, the dfa goes into q2.
Formal Languages and Automata - Yonsei CS 43
( )ML = { all strings with prefix }ab
a b
ba,
0q 1q 2q
accept
ba,3q
ab
Issue: After the first two symbols are read, no further decision:Solve the problem with an automaton with 4 states: initial, two for recognizing ab ending in a final trap state and one nonfinal trap state (1st is not a or 2nd is not b).
Formal Languages and Automata - Yonsei CS 44
( )ML = { all strings without substring }001
λ 0 00 001
1
110
0 1,0
0
Find a dfa that accepts all the strings on {0,1} except those containing 001.
Need to remember if or not the current symbol has been preceded by on or two 0s. -> The state in which two 0s were the immediately preceding symbols can be labeled simply 00.
Formal Languages and Automata - Yonsei CS 45
Regular Languages
A language is regular if there is a DFA such that
LM ( )MLL =
{ all strings with prefix }{ all strings without substring }
Examples of regular languages:
There exist automata that accept theseLanguages (see previous slides).
ab001
Formal Languages and Automata - Yonsei CS 46
Another ExampleThe language is regular: - No explit way of testing the end of string: Simply putting
the dfa into a final state whenever the second a is encountered. But, if another b is found, it will take the dfa out of the final state.
{ }{ }*,: bawawaL ∈=
a
b
ba,
a
bb a
0q 2q 3q
4q
( )MLL =
Formal Languages and Automata - Yonsei CS 47
IS a regular language?2LThen, find a dfa which accepts
{ }{ }*,:212 bawaaawawL ∈=
- The vertex q3 has to be modified: To recognize thesubstring (the same form), we replicate the states of the first part with q3- The dfa is found in Fig. 2.7.- Thus, if a language is regular, so are K,, 32 LL