Upload
urivermundo
View
217
Download
0
Embed Size (px)
Citation preview
8/20/2019 CS25 Lecture Presentation 4
1/16
1
CS 25Automata Theory & Formal Languages
Lecture 4
8/20/2019 CS25 Lecture Presentation 4
2/16
EQUIVALENCE OF FINITE AUTOMATA WITHREGULAR EXPRESSIONS:
● Regular express!"s a"# $"%e au%!&a%a are e'u(ale"% " %)er#es*rp%(e p!+er,
● A la"guage s regular $ a"# !"l- $ s!&e regular express!"#es*r.es %,
8/20/2019 CS25 Lecture Presentation 4
3/16
GENERALI/E0 NON0ETERMINISTIC FINITE AUTOMATA 1GNFA2
● NFA wherein transition arrows may have any regular expressions as labels.
● Special Form:
3, T)ere are %ra"s%!"s g!"g $r!& %)e "%al s%a%e %! all !%)er s%a%es4 a"# %)ereare "! %ra"s%!"s "%! %)e "%al s%a%e,
5, T)ere s a s"gle a**ep% s%a%e %)a% )as !"l- %ra"s%!"s *!&"g "%! % 1a"# "!!u%g!"g %ra"s%!"s2,
6, T)e a**ep% s%a%e s #s%"*% $r!& %)e "%al s%a%e,
7, Ex*ep% $!r %)e "%al a"# a**ep%"g s%a%es4 all !%)er s%a%es are *!""e*%e# %! all!%)er s%a%es (a a %ra"s%!", I" par%*ular4 ea*) s%a%e )as a %ra"s%!" %! %sel$,
8/20/2019 CS25 Lecture Presentation 4
4/16
CONVERTING GNFA TO SPECIAL FORM
3, A## "e+ s%ar% s%a%e +%) a" 8 arr!+ %! %)e !l# s%ar% s%a%e,
5, A## "e+ a**ep% s%a%e +%) 8 arr!+s p!"%"g $r!& %)e !l# a**ep%s%a%es,
6, I$ %)ere are &ul%ple arr!+s .e%+ee" 5 s%a%es a"# " sa&e
#re*%!"4 +e repla*e ea*) +%) a s"gle arr!+ +)!se la.el s %)eu"!" !$ %)e pre(!us la.els,
7, A## arr!+s la.ele# 9 .e%+ee" s%a%es %)a% )a# "! arr!+s,
8/20/2019 CS25 Lecture Presentation 4
5/16
FORMAL 0EFINITION OF A GNFA
;%uple 1Q4 Σ4 δ4 's%ar%4 'a**ep%24 +)ere
3, Q s a $"%e se% *alle# states
2. Σ s %)e input alphabet
3. δ: 1Q;
8/20/2019 CS25 Lecture Presentation 4
6/16
CONVERTING 0FA TO REGULAR EXPRESSION
1.Convert DFA to a GNFA, adding new initial andfinal states.
2.Remove all states one-by-one, until we ave
only te initial and final states.!."ut#ut regular e$#ression is te label on te
%single& transition left in te GNFA.
8/20/2019 CS25 Lecture Presentation 4
7/16
CONVERTING GNFA TO REGULAR EXPRESSION
● I$ > 1"u&.er !$ s%a%es2 ? 54 *!"s%ru*% a" e'u(ale"% GNFA $!r& +%)>;3 s%a%es@ repea% u"%l >5,
● I$ >54 %)ere s !"l- a s"gle arr!+ $r!& %)e s%ar% %! %)e a**ep% s%a%e,T)e la.el !" %)s arr!+ s %)e regular express!",
8/20/2019 CS25 Lecture Presentation 4
8/16
CONVERTING GNFA TO REGULAR EXPRESSION
Algorithm for ripping a single state:
For e(er- s%a%e qrip do
For e(er- "*!&"g s%a%e qi do For e(er- !u%g!"g s%a%e q j do
Re&!(e all %ra"s%!" pa%)s $r!& qi %! q j (a qrip .-
*rea%"g a #re*% %ra"s%!" .e%+ee" qi a"# q j ,
8/20/2019 CS25 Lecture Presentation 4
9/16
EXAMPLE OF CONVERTING 0FABNFA TO REGULAREXPRESSION
1. The original 3-state DFA.
8/20/2019 CS25 Lecture Presentation 4
10/16
EXAMPLE OF CONVERTING 0FABNFA TO REGULAREXPRESSION
2. Convert to 5-state GNFA %null transitions are unre#resented&.
∪
8/20/2019 CS25 Lecture Presentation 4
11/16
EXAMPLE OF CONVERTING 0FABNFA TO REGULAREXPRESSION
3. Convert to 4-state GNFA by eliminating state A.
∪
∪
8/20/2019 CS25 Lecture Presentation 4
12/16
EXAMPLE OF CONVERTING 0FABNFA TO REGULAREXPRESSION
4. Convert to 3-state GNFA by eliminating state B.
∪
∪
∪
8/20/2019 CS25 Lecture Presentation 4
13/16
EXAMPLE OF CONVERTING 0FABNFA TO REGULAREXPRESSION
5. Convert to 2-state GNFA by eliminating state C.
∪
∪
∪∪
∪
∪
∪
'us, te automata is e(uivalent to te regular e$#ression %ab)a * b&%a * b&).
8/20/2019 CS25 Lecture Presentation 4
14/16
EXERCISE:
C!"(er% %)e g(e" 0FA .el!+ %! a" e'u(ale"% Regular Express!",
1 2 !a a
b
b
a, b
1 2
8/20/2019 CS25 Lecture Presentation 4
15/16
15
Alge.ra* La+s $!r REs
● *nion and +on+atenation beave sort of lie
addition and multi#li+ation.
– *nion is +ommutative and asso+iative +on+atenation
is asso+iative.
– Con+atenation distributes over union.
– $+e#tion/ Con+atenation is not +ommutative.
8/20/2019 CS25 Lecture Presentation 4
16/16
16
0dentities and Anniilators
● ∅ is te identity for∪.
– R∪∅ R.
● ε is te identity for +on+atenation.
– εR Rε R.
● ∅ is te anniilator for +on+atenation.
– ∅R R∅ ∅.