Presentation is loading. Please wait.

Presentation is loading. Please wait.

Conversions between NFAs and REs

Similar presentations


Presentation on theme: "Conversions between NFAs and REs"— Presentation transcript:

1 Conversions between NFAs and REs
CS 350 — Fall 2018 gilray.org/classes/fall2018/cs350/

2 Converting REs to NFAs

3 q0 q1 ℒ(Ø) ℒ(𝜖) q0 a q0 q1 ℒ(a)

4 |𝐹|=1 As we build up a corresponding NFA
for an RE, we want to enforce that: |𝐹|=1

5 ℒ( 𝑒 0 ) 𝑒 0

6 ℒ( 𝑒 0 𝑒 1 ) 𝑒 0 𝑒 1

7 ℒ( 𝑒 0 𝑒 1 ) 𝑒 0 𝜖 𝑒 1

8 ℒ( 𝑒 0 𝑒 1 )=ℒ( 𝑄 ′ , Σ ′ , 𝛿 ′ , 𝑞 00 ,{ 𝑞 1𝐹 })
where ℒ( 𝑒 0 )=ℒ( 𝑄 0 , Σ 0 , 𝛿 0 , 𝑞 00 ,{ 𝑞 0𝐹 }) ℒ( 𝑒 1 )=ℒ( 𝑄 1 , Σ 1 , 𝛿 1 , 𝑞 10 ,{ 𝑞 1𝐹 }) 𝑄 ′ = 𝑄 0 ∪ 𝑄 1 Σ ′ = Σ 0 ∪ Σ 1 𝛿 ′ = 𝛿 0 ∪ 𝛿 1 ∪{( 𝑞 0𝐹 ,𝜖, 𝑞 10 )}

9 ℒ( 𝑒 0 | 𝑒 1 ) 𝑒 0 𝑒 1

10 ℒ( 𝑒 0 | 𝑒 1 ) 𝑒 0 𝜖 𝜖 𝑒 1 𝜖 𝜖

11 ℒ( 𝑒 0 | 𝑒 1 )=ℒ( 𝑄 ′ , Σ ′ , 𝛿 ′ , 𝑞 0 ,{ 𝑞 𝐹 })
where ℒ( 𝑒 0 )=ℒ( 𝑄 0 , Σ 0 , 𝛿 0 , 𝑞 00 ,{ 𝑞 0𝐹 }) ℒ( 𝑒 1 )=ℒ( 𝑄 1 , Σ 1 , 𝛿 1 , 𝑞 10 ,{ 𝑞 1𝐹 }) 𝑄 ′ = 𝑄 0 ∪ 𝑄 1 ∪{ 𝑞 0 , 𝑞 𝐹 } Σ ′ = Σ 0 ∪ Σ 1 𝛿 ′ = 𝛿 0 ∪ 𝛿 1 ∪{( 𝑞 0 ,𝜖, 𝑞 00 ),( 𝑞 0 ,𝜖, 𝑞 10 ), ( 𝑞 0𝐹 ,𝜖, 𝑞 𝐹 ),( 𝑞 1𝐹 ,𝜖, 𝑞 𝐹 )}

12 ℒ( 𝑒 0 ∗ ) 𝑒 0

13 ℒ( 𝑒 0 ∗ ) 𝑒 0 𝜖 𝜖

14 𝛿 ′ = 𝛿 0 ∪ 𝛿 1 ∪{( 𝑞 𝐹 ,𝜖, 𝑞 00 ),( 𝑞 0𝐹 ,𝜖, 𝑞 𝐹 )}
ℒ( 𝑒 0 ∗ )=ℒ( 𝑄 ′ , Σ ′ , 𝛿 ′ , 𝑞 𝐹 ,{ 𝑞 𝐹 }) where ℒ( 𝑒 0 )=ℒ( 𝑄 0 , Σ 0 , 𝛿 0 , 𝑞 00 ,{ 𝑞 0𝐹 }) 𝑄 ′ = 𝑄 0 ∪ 𝑄 1 ∪{ 𝑞 𝐹 } Σ ′ = Σ 0 ∪ Σ 1 𝛿 ′ = 𝛿 0 ∪ 𝛿 1 ∪{( 𝑞 𝐹 ,𝜖, 𝑞 00 ),( 𝑞 0𝐹 ,𝜖, 𝑞 𝐹 )}

15 Show the NFA for L((a|b)*c*).
Try an example: Show the NFA for L((a|b)*c*).

16 Show the NFA for L((a|b)*c*).
Try an example: Show the NFA for L((a|b)*c*). a q0 q1 b q2 q3

17 Show the NFA for L((a|b)*c*).
Try an example: Show the NFA for L((a|b)*c*). a q0 q1 𝜖 𝜖 q4 q5 b q2 q3 𝜖 𝜖

18 Show the NFA for L((a|b)*c*).
Try an example: Show the NFA for L((a|b)*c*). 𝜖 a q0 q1 𝜖 𝜖 q6 𝜖 q4 q5 b q2 q3 𝜖 𝜖

19 Show the NFA for L((a|b)*c*).
Try an example: Show the NFA for L((a|b)*c*). 𝜖 a q0 q1 𝜖 𝜖 q6 𝜖 q4 q5 b q2 q3 𝜖 𝜖 𝜖 c q9 q7 q8 𝜖

20 Show the NFA for L((a|b)*c*).
Try an example: Show the NFA for L((a|b)*c*). 𝜖 a q0 q1 𝜖 𝜖 q6 𝜖 q4 q5 b q2 q3 𝜖 𝜖 𝜖 𝜖 c q9 q8 𝜖 q7

21 Converting NFAs/DFAs to REs (intuitions, examples)

22 Idea 1: Permit whole REs on (G)NFA edges
Idea 2: Repeatedly remove one state until a RE can simply be read off the (G)NFA.

23 Idea 1: Permit whole REs on (G)NFA edges
Idea 2: Repeatedly remove one state until a RE can simply be read off the (G)NFA. q0 a c q2 q3 b q1 d e

24 Idea 1: Permit whole REs on (G)NFA edges
Idea 2: Repeatedly remove one state until a RE can simply be read off the (G)NFA. q0 ae*(c|d) q0 a c q2 q3 q3 b q1 d q1 be*(c|d) e

25 Alternative paths may have their REs disjoined:
Basic simplification rules: Disjunction e0 q0 q1 e1 Alternative paths may have their REs disjoined: e0 | e1 q0 q1

26 Sequential paths may have their REs juxtaposed:
Basic simplification rules: Juxtaposition q2 e1 q0 q1 e0 q3 e2 Sequential paths may have their REs juxtaposed: q2 q0 e0e1 q3 e0e2

27 Self-loops can be replaced by an edge with a kleene-star of the RE:
Basic simplification rules: Star e1 q0 q1 q2 e0 e2 Self-loops can be replaced by an edge with a kleene-star of the RE: q0 q1 q1’ q2 e0 e1* e2 q0 q2 e0e1*e2

28 Try an example: b q0 q2 b a a q1 b

29 Try an example: b q0 q2 b ab*a

30 Try an example: q0 q2 b|ab*a b

31 Try an example: q0 q’0 q2 b* b|ab*a

32 Thus possible regexes are: b*(b|ab*a)
Try an example: q0 q2 b*(b|ab*a) Thus possible regexes are: b*(b|ab*a) Or: b+|b*ab*a

33 Try an example: a q0 q2 a b b b b q1 a q3 a

34 Try an example: aa q0 ba ab b b bb q1 a q3 a

35 Try an example: aa q0 ba ab bb bb ba q3 ab aa

36 Try an example: aa|bb q0 ab|ba q3 aa|bb

37 Try an example: aa|bb|(ab|ba)(aa|bb)*(ab|ba)
q0 So an answer is: (aa|bb|(ab|ba)(aa|bb)*(ab|ba))*

38 Models of regular languages
“Converts to” GNFA “Converts to” RE DFA “Minimizes to” NFA “Converts to” “Converts to”


Download ppt "Conversions between NFAs and REs"

Similar presentations


Ads by Google