Presentation is loading. Please wait.

Presentation is loading. Please wait.

Intro to Theory of Computation

Similar presentations


Presentation on theme: "Intro to Theory of Computation"— Presentation transcript:

1 Intro to Theory of Computation
LECTURE 4 Last time: Equivalence of NFAs and DFAs Closure properties of regular languages Today: Finish closure properties Equivalence of NFAs, DFAs and regular expressions CS 332 Sofya Raskhodnikova 8/24/2019 Sofya Raskhodnikova; based on slides by Nick Hopper

2 Operations on languages
Regular Operations on languages Complement: A = { w | w  A } Union: A  B = { w | w  A or w  B } Union: A  B = { w | w  A or w  B } Intersection: A  B = { w | w  A and w  B } Reverse: AR = { w1 …wk | wk …w1  A } Concatenation: A  B = { vw | v  A and w  B } Concatenation: A  B = { vw | v  A and w  B } Star: A* = { w1 …wk | k ≥ 0 and each wi  A } Star: A* = { w1 …wk | k ≥ 0 and each wi  A } 8/24/2019 Sofya Raskhodnikova; based on slides by Nick Hopper

3 Closure properties of the class of regular languages
THEOREM. The class of regular languages is closed under all 6 operations. If A and B are regular, applying any of these operation yields a regular language. 8/24/2019 Sofya Raskhodnikova; based on slides by Nick Hopper

4 Sofya Raskhodnikova; based on slides by Nick Hopper
Star operation Star: A* = { w1 …wk | k ≥ 0 and each wi  A } Theorem. If A is regular, A* is also regular. ε ε L(M)=A ε 8/24/2019 Sofya Raskhodnikova; based on slides by Nick Hopper

5 The class of regular languages is closed under
Regular operations Union: A  B = { w | w  A or w  B } Union: A  B = { w | w  A or w  B } Concatenation: A  B = { vw | v  A and w  B } Star: A* = { w1 …wk | k ≥ 0 and each wi  A } Other operations Complement: A = { w | w  A } Intersection: A  B = { w | w  A and w  B } Reverse: AR = { w1 …wk | wk …w1  A } 8/24/2019 Sofya Raskhodnikova; based on slides by Nick Hopper

6 Sofya Raskhodnikova; based on slides by Nick Hopper
Regular expressions In a regular expression, we can use Constants: ε ,  , a set Σ, members of Σ. Regular operations: *,  , ∪ Examples: 0*1* (01)* 0*1*(ε 0) L(R) = the language regular expression R describes = { w | w has a run of 0s followed by a run of 1s} = the set of all strings over the alphabet Σ={0,1} 8/24/2019 Sofya Raskhodnikova; based on slides by Nick Hopper

7 Sofya Raskhodnikova; based on slides by Nick Hopper
Precedence *  ∪ EXAMPLE 𝑹 𝟏 𝑹 𝟐 ∗ ∪ 𝑹 𝟑 𝑹 𝟒 = (𝑹 𝟏 ( 𝑹 𝟐 ∗ ))∪( 𝑹 𝟑 𝑹 𝟒 ) 8/24/2019 Sofya Raskhodnikova; based on slides by Nick Hopper

8 Sofya Raskhodnikova; based on slides by Nick Hopper
Regular expressions: examples 1) 2) 3) { w | w has exactly one character 1, any # of 0s} 0*10* { w | w has length ≥ 3 and its 3rd symbol is 0 } (01)(01) 0 (01)* { w | every odd position of w is a 1 } (1(01))* (ε  1) 8/24/2019 Sofya Raskhodnikova; based on slides by Nick Hopper

9 Regular expressions to NFAs
Theorem. Every regular expression has an equivalent NFA. Proof: Induction on the length of regular expression R. Base case: length 1 Inductive step: follows from closure of the class of regular languages under the regular operations. R = ε R =  R =  8/24/2019 Sofya Raskhodnikova; based on slides by Nick Hopper

10 Exercise What should the induction hypothesis be?
Suppose some regular expression of length 𝑘 can be converted an NFA, for some 𝑘∈ℕ. Suppose each regular expression of length 𝑘 can be converted an NFA, for some 𝑘∈ℕ. Suppose each regular expression of length at most k can be converted an NFA, for some 𝑘∈ℕ. None of the above. {madam, dad, but, tub, book}

11 Regular expression to NFA
Transform (1(0  1))* to an NFA ε 1 1,0 ε 8/24/2019 Sofya Raskhodnikova; based on slides by Nick Hopper

12 NFAs to regular expressions
Theorem. Every NFA has an equivalent regular expression. Proof idea: Transform NFA to a regular expression by removing states and relabeling the arrows with regular expressions. 01*0 1 8/24/2019 Sofya Raskhodnikova; based on slides by Nick Hopper

13 Exercise What is the regular expression that generates all strings that take this machine from 𝒒 𝒔 to 𝒒 𝒂 ? 𝑎 𝑏 ∗ 𝑐∪𝑑 𝑎 𝑏 ∗ 𝑐∩𝑑 𝑎𝑏𝑐∪𝑑 𝑎 𝑏 ∗ 𝑐𝑑 ∗ None of the above. 𝒃 𝒂 𝒄 qs q qa 𝒅 {madam, dad, but, tub, book}

14 Sofya Raskhodnikova; based on slides by Nick Hopper
Generalized NFAs Each transition is labeled with a regular expression Unique and distinct start and accept states No transitions to the start state No transitions from the accept state 8/24/2019 Sofya Raskhodnikova; based on slides by Nick Hopper

15 G accepts w if ∃q0,q1,…,qk, w1,…,wk: wi is generated by R(qi-1,qi)
Generalized NFAs a  b a*b a qs q qa G accepts w if ∃q0,q1,…,qk, w1,…,wk: wi is generated by R(qi-1,qi) w = w1w2…wk q0=qs, qk=qa R(qs,q) = a*b R(qa,q) = Ø R(q,qs) = Ø

16 NFA to GNFA NFA ε ε ε ε Add a new start state with no incoming arrows.
Make a unique accept state with no outgoing arrows. 8/24/2019 Sofya Raskhodnikova; based on slides by Nick Hopper

17 GNF to regular expression
ε ε ε NFA While machine has more than 2 states: Pick an internal state, rip it out and relabel the arrows with regular expressions to account for the missing state. 8/24/2019 Sofya Raskhodnikova; based on slides by Nick Hopper

18 q1 b a ε q2 a,b ε (a*b)(ab)* a*b q0 q3 R(q0,q3) = (a*b)(ab)*

19 Sofya Raskhodnikova; based on slides by Nick Hopper
bb a q1 q2 a ε b ε b a ε q3 8/24/2019 Sofya Raskhodnikova; based on slides by Nick Hopper

20 Sofya Raskhodnikova; based on slides by Nick Hopper
bb a q1 q2 a  ba a ε b b ε a ε 8/24/2019 Sofya Raskhodnikova; based on slides by Nick Hopper

21 Sofya Raskhodnikova; based on slides by Nick Hopper
bb  (a  ba)b*a bb = R(q1,q1) a q1 q2 a  ba ε b  (a  ba)b* b ε 8/24/2019 Sofya Raskhodnikova; based on slides by Nick Hopper

22 Sofya Raskhodnikova; based on slides by Nick Hopper
bb  (a  ba)b*a = R(q1,q1) q1 ε b  (a  ba)b* = R(q1,qa) qs qa (bb  (a  ba)b*a)*(b  (a  ba)b*) 8/24/2019 Sofya Raskhodnikova; based on slides by Nick Hopper

23 Sofya Raskhodnikova; based on slides by Nick Hopper
Conversion procedures DFA NFA definition Regular Language Regular Expression 8/24/2019 Sofya Raskhodnikova; based on slides by Nick Hopper

24 Sofya Raskhodnikova; based on slides by Nick Hopper
REGULAR OR NOT? Design an NFA for the language: {0𝑛1𝑛 | 0 < 𝑛≤ 2} 0𝑛1𝑛 0 < 𝑛≤ 𝑘} {0𝑛1𝑛 | 𝑛 > 0}? n (For R a regexp, R2 means RR, and Rn means RR…R) 8/24/2019 Sofya Raskhodnikova; based on slides by Nick Hopper


Download ppt "Intro to Theory of Computation"

Similar presentations


Ads by Google