Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 350 โ€” Fall 2018 gilray.org/classes/fall2018/cs350/

Similar presentations


Presentation on theme: "CS 350 โ€” Fall 2018 gilray.org/classes/fall2018/cs350/"โ€” Presentation transcript:

1 CS 350 โ€” Fall 2018 gilray.org/classes/fall2018/cs350/
Deterministic finite automata (DFA) & Non-deterministic finite automata (NFA) CS 350 โ€” Fall 2018 gilray.org/classes/fall2018/cs350/

2 DFA transition diagram
๐ฟ={hello} h e l o q0 q1 q2 q3 l q4 q5 DFA transition diagram

3 Formally, each DFA is a 5-tuple:
A set of final states Formally, each DFA is a 5-tuple: (๐‘„,ฮฃ,๐›ฟ, ๐‘ž 0 ,๐น) A starting state A finite set of states {qโ€ฆ} A transition function An alphabet

4 Formally, each DFA is a 5-tuple:
(๐‘„,ฮฃ,๐›ฟ, ๐‘ž 0 ,๐น) ๐›ฟโŠ†(๐‘„ร—ฮฃโ‡€๐‘„) ๐นโŠ†๐‘„ ๐‘ž 0 โˆˆ๐‘„

5 (๐‘„,ฮฃ,๐›ฟ, ๐‘ž 0 ,๐น),where ๐‘„={ ๐‘ž 0 ,โ€ฆ, ๐‘ž 5 } ฮฃ={a,b,โ€ฆ,z} ๐น={ ๐‘ž 5 }
l l o q0 q1 q2 q3 q4 q5 (๐‘„,ฮฃ,๐›ฟ, ๐‘ž 0 ,๐น),where ๐‘„={ ๐‘ž 0 ,โ€ฆ, ๐‘ž 5 } ฮฃ={a,b,โ€ฆ,z} ๐›ฟ={( ๐‘ž 0 ,h, ๐‘ž 1 ),( ๐‘ž 1 ,e, ๐‘ž 2 ), ( ๐‘ž 2 ,l, ๐‘ž 3 ),( ๐‘ž 3 ,l, ๐‘ž 4 ),( ๐‘ž 4 ,o, ๐‘ž 5 )} ๐น={ ๐‘ž 5 }

6 h e l o q0 q1 q2 q3 l q4 q5 ๐›ฟ h l e o โ€ฆ โ€ฆ ๐‘ž 0 ๐‘ž 1 DFA transition table ๐‘ž 1 ๐‘ž 2 ๐‘ž 2 ๐‘ž 3 ๐‘ž 3 ๐‘ž 4 ๐‘ž 4 ๐‘ž 5 ๐‘ž 5 ๐›ฟ={( ๐‘ž 0 ,h, ๐‘ž 1 ),( ๐‘ž 1 ,e, ๐‘ž 2 ), ( ๐‘ž 2 ,l, ๐‘ž 3 ),( ๐‘ž 3 ,l, ๐‘ž 4 ),( ๐‘ž 4 ,o, ๐‘ž 5 )}

7 Extended transition function
h e l q3 l o q0 q1 q2 q4 q5 Extended transition function ๐›ฟ ฬ‚ ={( ๐‘ž 0 ,h, ๐‘ž 1 ),( ๐‘ž 1 ,e, ๐‘ž 2 ), ( ๐‘ž 2 ,l, ๐‘ž 3 ),( ๐‘ž 3 ,l, ๐‘ž 4 ),( ๐‘ž 4 ,o, ๐‘ž 5 ), ( ๐‘ž 0 ,he, ๐‘ž 2 ),( ๐‘ž 1 ,el, ๐‘ž 3 ),( ๐‘ž 2 ,ll, ๐‘ž 4 ),( ๐‘ž 3 ,lo, ๐‘ž 5 ), ( ๐‘ž 0 ,hel, ๐‘ž 3 ),( ๐‘ž 1 ,ell, ๐‘ž 4 ),( ๐‘ž 2 ,llo, ๐‘ž 5 ), ( ๐‘ž 0 ,hell, ๐‘ž 4 ),( ๐‘ž 1 ,ello, ๐‘ž 5 ),( ๐‘ž 0 ,hello, ๐‘ž 5 )} ๐›ฟ={( ๐‘ž 0 ,h, ๐‘ž 1 ),( ๐‘ž 1 ,e, ๐‘ž 2 ), ( ๐‘ž 2 ,l, ๐‘ž 3 ),( ๐‘ž 3 ,l, ๐‘ž 4 ),( ๐‘ž 4 ,o, ๐‘ž 5 )}

8 Computing the extended transition function as a least fixed point
๐›ฟ ฬ‚ ,where ๐‘“ ๐›ฟ,๐‘„ ( ๐›ฟ ฬ‚ )= ๐›ฟ ฬ‚ ๐‘“ ๐›ฟ,๐‘„ ( ๐›ฟ ฬ‚ )={( ๐‘ž ๐‘– , ๐‘  0 ๐‘  1 , ๐‘ž ๐‘— )|( ๐‘ž ๐‘– , ๐‘  0 , ๐‘ž ๐‘˜ )โˆˆ๐›ฟโˆง( ๐‘ž ๐‘˜ , ๐‘  1 , ๐‘ž ๐‘— )โˆˆ ๐›ฟ ฬ‚ } โˆช{( ๐‘ž ๐‘– ,๐œ–, ๐‘ž ๐‘– )| ๐‘ž ๐‘– โˆˆ๐‘„}

9 Computing the extended transition function as a least fixed point
๐‘“ ๐›ฟ,๐‘„ ( ๐›ฟ ฬ‚ )={( ๐‘ž ๐‘– , ๐‘  0 ๐‘  1 , ๐‘ž ๐‘— )|( ๐‘ž ๐‘– , ๐‘  0 , ๐‘ž ๐‘˜ )โˆˆ๐›ฟโˆง( ๐‘ž ๐‘˜ , ๐‘  1 , ๐‘ž ๐‘— )โˆˆ ๐›ฟ ฬ‚ } โˆช{( ๐‘ž ๐‘– ,๐œ–, ๐‘ž ๐‘– )| ๐‘ž ๐‘– โˆˆ๐‘„} โ„’( a โˆ— ) ๐›ฟ a ๐‘ž 0 ๐‘ž 0 a q0

10 Computing the extended transition function as a least fixed point
๐‘“ ๐›ฟ,๐‘„ ( ๐›ฟ ฬ‚ )={( ๐‘ž ๐‘– , ๐‘  0 ๐‘  1 , ๐‘ž ๐‘— )|( ๐‘ž ๐‘– , ๐‘  0 , ๐‘ž ๐‘˜ )โˆˆ๐›ฟโˆง( ๐‘ž ๐‘˜ , ๐‘  1 , ๐‘ž ๐‘— )โˆˆ ๐›ฟ ฬ‚ } โˆช{( ๐‘ž ๐‘– ,๐œ–, ๐‘ž ๐‘– )| ๐‘ž ๐‘– โˆˆ๐‘„} โ„’( a โˆ— ) ๐›ฟ ฬ‚ ๐œ– a ๐‘ž 0 ๐‘ž 0 ๐‘ž 0 a q0

11 Computing the extended transition function as a least fixed point
๐‘“ ๐›ฟ,๐‘„ ( ๐›ฟ ฬ‚ )={( ๐‘ž ๐‘– , ๐‘  0 ๐‘  1 , ๐‘ž ๐‘— )|( ๐‘ž ๐‘– , ๐‘  0 , ๐‘ž ๐‘˜ )โˆˆ๐›ฟโˆง( ๐‘ž ๐‘˜ , ๐‘  1 , ๐‘ž ๐‘— )โˆˆ ๐›ฟ ฬ‚ } โˆช{( ๐‘ž ๐‘– ,๐œ–, ๐‘ž ๐‘– )| ๐‘ž ๐‘– โˆˆ๐‘„} โ„’( a โˆ— ) ๐›ฟ ฬ‚ ๐œ– a aa aaa ๐‘ž 0 ๐‘ž 0 ๐‘ž 0 ๐‘ž 0 ๐‘ž 0 a q0

12 โ„’(๐‘„,ฮฃ,๐›ฟ, ๐‘ž 0 ,๐น)={๐‘ |( ๐‘ž 0 ,๐‘ , ๐‘ž ๐‘“ )โˆˆ ๐›ฟ ฬ‚ โˆง ๐‘ž ๐‘“ โˆˆ๐น}
The Language L of a DFA: and ๐›ฟ ฬ‚ (๐‘„,ฮฃ,๐›ฟ, ๐‘ž 0 ,๐น) โ„’(๐‘„,ฮฃ,๐›ฟ, ๐‘ž 0 ,๐น)={๐‘ |( ๐‘ž 0 ,๐‘ , ๐‘ž ๐‘“ )โˆˆ ๐›ฟ ฬ‚ โˆง ๐‘ž ๐‘“ โˆˆ๐น} where ๐›ฟ ฬ‚ is the least fixed point ๐›ฟ ฬ‚ = ๐‘“ ๐›ฟ,๐‘„ ( ๐›ฟ ฬ‚ )

13 L is the language L((a|b)*cc(a|b)*).
Try an example: L is the language L((a|b)*cc(a|b)*).

14 L is the language L((a|b)*cc(a|b)*).
Try an example: L is the language L((a|b)*cc(a|b)*). c c q0 q1 q2 a,b a,b

15 L is the language L((a|b)*bab).
Try an example: L is the language L((a|b)*bab).

16 L is the language L((a|b)*bab).
Try an example: L is the language L((a|b)*bab). b b b a b q0 q1 q2 q3 a a a

17 Try an example: L is the language, over {a,b}, of strings
with an even number of aโ€™s and of bโ€™s.

18 Try an example: L is the language, over {a,b}, of strings
with an even number of aโ€™s and of bโ€™s. a q0 q2 a b b b b q1 a q3 a

19 There are an even number of aโ€™s There are an odd number of aโ€™s
q0 q2 a b b b b q1 a q3 a

20 a a b b b b a a There are an even number of bโ€™s
q0 q2 a b b b b q1 a q3 a There are an odd number of bs

21 So this is just the DFAs for (aa). and for (bb). composed
So this is just the DFAs for (aa)* and for (bb)* composed. Can this idea be generalized? a (E,E) (O,E) a b b b b (E,O) a (O,O) a

22 ๐น โˆฉ ={( ๐‘ž 0๐น , ๐‘ž 1๐น )| ๐‘ž 0๐น โˆˆ ๐น 0 โˆง ๐‘ž 1๐น โˆˆ ๐น 1 }
โ„’( ๐‘„ 0 ,ฮฃ, ๐›ฟ 0 , ๐‘ž 00 , ๐น 0 )โˆฉโ„’( ๐‘„ 1 ,ฮฃ, ๐›ฟ 1 , ๐‘ž 10 , ๐น 1 ) =โ„’( ๐‘„ โˆฉ ,ฮฃ, ๐›ฟ โˆฉ , ๐‘ž โˆฉ , ๐น โˆฉ ) ๐‘„ โˆฉ = ๐‘„ 0 ร— ๐‘„ 1 ๐›ฟ โˆฉ ={(( ๐‘ž 0 , ๐‘ž 1 ),๐‘ ,( ๐‘ž 0 โ€ฒ , ๐‘ž 1 โ€ฒ )) |( ๐‘ž 0 ,๐‘ , ๐‘ž 0 โ€ฒ )โˆˆ ๐›ฟ 0 ๐‘ž โˆฉ =( ๐‘ž 00 , ๐‘ž 10 ) โˆง( ๐‘ž 1 ,๐‘ , ๐‘ž 1 โ€ฒ )โˆˆ ๐›ฟ 1 } ๐น โˆฉ ={( ๐‘ž 0๐น , ๐‘ž 1๐น )| ๐‘ž 0๐น โˆˆ ๐น 0 โˆง ๐‘ž 1๐น โˆˆ ๐น 1 }

23 Try an example: L is the language, over {0,1}, of strings
with an even number of 0s and two 1s.

24 Try an example: L is the language, over {0,1}, of strings
with an even number of 0s and two 1s. 1 1 q0 q1 q2 q0 q1 1 1

25 Try an example: L is the language, over {0,1}, of strings
with an even number of 0s and two 1s. 1 1 q0,q0 q0,q1 q0,q2 1 1 q1,q0 q1,q1 q1,q2

26 is the complement of language (a|b)*bab
Try an example: is the complement of language (a|b)*bab ๐ฟ

27 (Recall that this is how we defined L as a DFA.)
Try an example: is the complement of language (a|b)*bab ๐ฟ b b b a b q0 q1 q2 q3 a a a (Recall that this is how we defined L as a DFA.)

28 is the complement of language (a|b)*bab
Try an example: is the complement of language (a|b)*bab ๐ฟ b b b a b q0 q1 q2 q3 a a a

29 (Recall that this is how we defined {a} as a DFA.)
Try an example: is the complement of language a ๐ฟ a q0 q1 (Recall that this is how we defined {a} as a DFA.)

30 is the complement of language a
Try an example: is the complement of language a ๐ฟ a a q0 q1 q2 a

31 ๐‘„ โ€ฒ =๐‘„โˆช{ ๐‘ž dead } ๐น โ€ฒ = ๐‘„ โ€ฒ โˆ’๐น ๐›ฟ โ€ฒ =๐›ฟโˆช{( ๐‘ž dead ,๐‘ , ๐‘ž dead )|๐‘ โˆˆฮฃ}
The complement ofโ„’(๐‘„,ฮฃ,๐›ฟ, ๐‘ž 0 ,๐น)isโ„’( ๐‘„ โ€ฒ ,ฮฃ, ๐›ฟ โ€ฒ , ๐‘ž 0 , ๐น โ€ฒ ) ๐‘„ โ€ฒ =๐‘„โˆช{ ๐‘ž dead } ๐น โ€ฒ = ๐‘„ โ€ฒ โˆ’๐น ๐›ฟ โ€ฒ =๐›ฟโˆช{( ๐‘ž dead ,๐‘ , ๐‘ž dead )|๐‘ โˆˆฮฃ} โˆช{(๐‘ž,๐‘ , ๐‘ž dead )|๐‘ โˆˆฮฃโˆง๐‘žโˆˆ๐‘„โˆง(๐‘ž,๐‘ , ๐‘ž โ€ฒ )โˆ‰๐›ฟ}

32 Non-deterministic finite automata (NFA)

33 Models of regular languages
โ€œConverts toโ€ GNFA โ€œConverts toโ€ RE DFA โ€œMinimizes toโ€ NFA โ€œConverts toโ€ โ€œConverts toโ€

34 L is the language L((a|b)*bab).
Try an example: L is the language L((a|b)*bab). b a b q0 q1 q2 q3 a,b

35 b a b a,b Letโ€™s run this nondeterministically on the string babab and
track what paths we can take: b a b q0 q1 q2 q3 a,b

36 / Letโ€™s run this nondeterministically on the string babab and track what paths we can take: b a b q0 q1 q2 q3 a,b

37 / / Letโ€™s run this nondeterministically on the string babab and track what paths we can take: b a b q0 q1 q2 q3 a,b

38 / / / Letโ€™s run this nondeterministically on the string babab and track what paths we can take: b a b q0 q1 q2 q3 a,b

39 / / / / Letโ€™s run this nondeterministically on the string babab and track what paths we can take: b a b q0 q1 q2 q3 a,b

40 If any possible path would accept, then the NFA accepts.
/ / / / / Letโ€™s run this nondeterministically on the string babab and track what paths we can take: If any possible path would accept, then the NFA accepts. b a b q0 q1 q2 q3 a,b

41 Formally, each NFA is also a 5-tuple:
A set of final states Formally, each NFA is also a 5-tuple: (๐‘„,ฮฃ,๐›ฟ, ๐‘ž 0 ,๐น) A starting state A finite set of states {q0,โ€ฆ} A transition relation An alphabet

42 ๐›ฟ:๐‘„ร—ฮฃร—๐‘„ A transition relation

43 ๐›ฟ:๐‘„ร—ฮฃร—๐‘„ ๐›ฟ:๐‘„ร—ฮฃโ†’๐’ซ(๐‘„) A transition relation

44 b ๐›ฟ a ๐‘ž 0 ๐‘ž 1 ๐‘ž 2 ๐‘ž 3 NFA transition table { ๐‘ž 0 } { ๐‘ž 0 , ๐‘ž 1 }
q0 q1 q2 q3 a,b NFA transition table b ๐›ฟ a ๐‘ž 0 { ๐‘ž 0 } { ๐‘ž 0 , ๐‘ž 1 } ๐‘ž 1 { ๐‘ž 2 } ๐‘ž 2 { ๐‘ž 3 } ๐‘ž 3

45 NFA extended transition table
q0 q1 q2 q3 NFA extended transition table a,b ๐›ฟ ฬ‚ b ab ba bab a aa ๐‘ž 0 { ๐‘ž 0 } { ๐‘ž 0 , ๐‘ž 1 } { ๐‘ž 0 } { ๐‘ž 0 , ๐‘ž 1 } { ๐‘ž 0 , ๐‘ž 2 } { ๐‘ž 0 , ๐‘ž 3 } ๐‘ž 1 { ๐‘ž 2 } { ๐‘ž 3 } โ€ฆ ๐‘ž 2 { ๐‘ž 3 } ๐‘ž 3

46 This is exactly the same as for a DFA, except now a relation.
Computing an NFAโ€™s extended transition relation as a least fixed point This is exactly the same as for a DFA, except now a relation. ๐›ฟ ฬ‚ ,where ๐‘“ ๐›ฟ,๐‘„ ( ๐›ฟ ฬ‚ )= ๐›ฟ ฬ‚ ๐‘“ ๐›ฟ,๐‘„ ( ๐›ฟ ฬ‚ )={( ๐‘ž ๐‘– , ๐‘  0 ๐‘  1 , ๐‘ž ๐‘— )|( ๐‘ž ๐‘– , ๐‘  0 , ๐‘ž ๐‘˜ )โˆˆ๐›ฟโˆง( ๐‘ž ๐‘˜ , ๐‘  1 , ๐‘ž ๐‘— )โˆˆ ๐›ฟ ฬ‚ } โˆช{( ๐‘ž ๐‘– ,๐œ–, ๐‘ž ๐‘– )| ๐‘ž ๐‘– โˆˆ๐‘„}

47 The Language L of an NFA:
and ๐›ฟ ฬ‚ (๐‘„,ฮฃ,๐›ฟ, ๐‘ž 0 ,๐น) ๐ฟ={๐‘ |( ๐›ฟ ฬ‚ ( ๐‘ž 0 ,๐‘ )โˆฉ๐น)โŠƒร˜}


Download ppt "CS 350 โ€” Fall 2018 gilray.org/classes/fall2018/cs350/"

Similar presentations


Ads by Google