Download presentation
Presentation is loading. Please wait.
1
Intro to Theory of Computation
LECTURE 4 Last time: Equivalence of NFAs and DFAs Today: Closure properties of regular languages Equivalence of NFAs, DFAs and regular expressions CS 464 Sofya Raskhodnikova 11/19/2018 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 } 11/19/2018 Sofya Raskhodnikova; based on slides by Nick Hopper
3
I-clicker problem (frequency: AC)
Let L be the set of words in English. Then 𝑳 ∩𝑳 𝑹 is The set of English words in alphabetical order, followed the same words in reverse alphabetical order. {𝑤∣𝑤 is an English word or an English word written backwords}. {𝑤∣𝑤 is an English word that is a palindrom}. None of the above. {madam, dad, but, tub, book}
4
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. 11/19/2018 Sofya Raskhodnikova; based on slides by Nick Hopper
5
Sofya Raskhodnikova; based on slides by Nick Hopper
Closure under reverse Theorem. The reverse of a regular language is also regular Proof: Let L be a regular language and M be a DFA that recognizes it. Construct an NFA 𝑴 ′ recognizing LR: Define 𝑴 ′ as M with the arrows reversed. Make the start state of M be the accept state in 𝑴 ′ . Make a new start state that goes to all accept states of M by ε-transitions. ε ε ε 11/19/2018 Sofya Raskhodnikova; based on slides by Nick Hopper
6
New construction for A B
Construct an NFA M: L(MA)=A ε ε L(MB)=B 11/19/2018 Sofya Raskhodnikova; based on slides by Nick Hopper
7
Concatenation operation
Concatenation: A B = { vw | v A and w B } Theorem. If A and B are regular, A B is also regular. Proof: Given DFAs M1 and M2, construct NFA by connecting all accept states in M1 to the start state in M2. ε L(M1)=A L(M2)=B ε 11/19/2018 Sofya Raskhodnikova; based on slides by Nick Hopper
8
Concatenation operation
Concatenation: A B = { vw | v A and w B } Theorem. If A and B are regular, A B is also regular. Proof: Given DFAs M1 and M2, construct NFA by connecting all accept states in M1 to the start state in M2. Make all states in M1 non-accepting. ε L(M1)=A L(M2)=B ε 11/19/2018 Sofya Raskhodnikova; based on slides by Nick Hopper
9
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 ε 11/19/2018 Sofya Raskhodnikova; based on slides by Nick Hopper
10
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 } 11/19/2018 Sofya Raskhodnikova; based on slides by Nick Hopper
11
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* (01)* 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} 11/19/2018 Sofya Raskhodnikova; based on slides by Nick Hopper
12
Sofya Raskhodnikova; based on slides by Nick Hopper
Precedence * ∪ EXAMPLE R1*R2 R3 = ( ( R1* ) R2 ) R3 11/19/2018 Sofya Raskhodnikova; based on slides by Nick Hopper
13
Sofya Raskhodnikova; based on slides by Nick Hopper
Regular expressions: examples 1) 2) 3) { w | w has exactly one character 1 } 0*10* { w | w has length ≥ 3 and its 3rd symbol is 0 } (01)(01) 0 (01)* { w | every odd position of w is a 1 } (1(01))* (ε 1) 11/19/2018 Sofya Raskhodnikova; based on slides by Nick Hopper
14
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 = 11/19/2018 Sofya Raskhodnikova; based on slides by Nick Hopper
15
I-clicker problem (frequency: AC)
What should the induction hypothesis be? Suppose some regular expression of length 𝑘 can be converted an NFA, for some 𝑘∈ℕ. Suppose all regular expressions of length 𝑘 can be converted an NFA, for some 𝑘∈ℕ. Suppose all regular expressions of length at most k can be converted an NFA, for some 𝑘∈ℕ. None of the above. {madam, dad, but, tub, book}
16
Regular expression to NFA
Transform (1(0 1))* to an NFA ε 1 1,0 ε 11/19/2018 Sofya Raskhodnikova; based on slides by Nick Hopper
17
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 11/19/2018 Sofya Raskhodnikova; based on slides by Nick Hopper
18
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 11/19/2018 Sofya Raskhodnikova; based on slides by Nick Hopper
19
G accepts w if it finds q0q1…qk, w1…wk: wi is generated by R(qi,qi+1)
Generalized NFAs a b a*b a qs q qa G accepts w if it finds q0q1…qk, w1…wk: wi is generated by R(qi,qi+1) w = w1w2…wk q0=qs, qk=qa R(qs,q) = a*b R(qa,q) = Ø R(q,qs) = Ø
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.