Intro to Theory of Computationsxr48/cmpsc464/lecture-notes/... · 1/21/2016 Sofya Raskhodnikova;...
Transcript of Intro to Theory of Computationsxr48/cmpsc464/lecture-notes/... · 1/21/2016 Sofya Raskhodnikova;...
1/20/2016
Sofya Raskhodnikova
Intro to Theory of Computation
LECTURE 4Last time:
• Equivalence of NFAs and DFAs
Today:
• Closure properties of regular
languages
• Equivalence of NFAs, DFAs
and regular expressions
Sofya Raskhodnikova; based on slides by Nick Hopper L4.1
Operations on languages
1/20/2016 Sofya Raskhodnikova; based on slides by Nick Hopper
Union: A B = { w | w A or w B }
Intersection: A B = { w | w A and w B }
Complement: A = { w | w A }
Reverse: AR = { w1 …wk | wk …w1 A }
Concatenation: A B = { vw | v A and w B }
Star: A* = { w1 …wk | k ≥ 0 and each wi A }
Regular
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 }
L3.2
I-clicker problem (frequency: AC)
Let L be the set of words in English.
Then 𝑳 ∩ 𝑳𝑹 is
A. The set of English words in alphabetical order,
followed the same words in reverse alphabetical order.
B. {𝑤 ∣ 𝑤 is an English word or an English word written
backwords}.
C. {𝑤 ∣ 𝑤 is an English word that is a palindrom}.
D. None of the above.
Closure properties of the class of
regular languages
1/20/2016 Sofya Raskhodnikova; based on slides by Nick Hopper
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.
L3.4
Closure under reverse
1/20/2016 Sofya Raskhodnikova; based on slides by Nick Hopper
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.
ε ε ε
L3.5
New construction for A B
1/20/2016 Sofya Raskhodnikova; based on slides by Nick Hopper
ε
ε
Construct an NFA M:
L(MA)=A
L(MB)=B
L3.6
Concatenation operation
1/20/2016 Sofya Raskhodnikova; based on slides by Nick Hopper
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
L3.7
Concatenation operation
1/21/2016 Sofya Raskhodnikova; based on slides by Nick Hopper
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
L3.8
Star operation
1/20/2016
Sofya Raskhodnikova; based on slides by Nick Hopper
Star: A* = { w1 …wk | k ≥ 0 and each wi A }
Theorem. If A is regular, A* is also regular.
L(M)=Aε
ε
ε
L3.9
The class of regular languages is
closed under
1/20/2016 Sofya Raskhodnikova; based on slides by Nick Hopper
Union: A B = { w | w A or w B }
Intersection: A B = { w | w A and w B }
Complement: A = { w | w A }
Reverse: AR = { w1 …wk | wk …w1 A }
Regular operations
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
L3.10
Regular expressions
1/20/2016 Sofya Raskhodnikova; based on slides by Nick Hopper L4.11
• 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
= the set of all strings over the alphabet Σ={0,1}
= { w | w has a run of 0s followed by a run of 1s}
* ∪
Precedence
R2R1*(
EXAMPLE
R1*R2 R3 = ( ) )R3
1/20/2016 Sofya Raskhodnikova; based on slides by Nick Hopper L4.12
{ w | w has exactly one character 1 }
0*10*
1)
2)
3)
Regular expressions: examples
{ 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)
1/20/2016 Sofya Raskhodnikova; based on slides by Nick Hopper L4.13
Regular expressions to NFAs
1/20/2016 Sofya Raskhodnikova; based on slides by Nick Hopper
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.
L4.14
R =
R = ε
R =
I-clicker problem (frequency: AC)
What should the induction hypothesis be?
A. Suppose some regular expression of length 𝑘 can be
converted an NFA, for some 𝑘 ∈ ℕ.
B. Suppose all regular expressions of length 𝑘 can be
converted an NFA, for some 𝑘 ∈ ℕ.
C. Suppose all regular expressions of length at most k can
be converted an NFA, for some 𝑘 ∈ ℕ.
D. None of the above.
Regular expression to NFA
L4.161/20/2016 Sofya Raskhodnikova; based on slides by Nick Hopper
Transform (1(0 1))* to an NFA
1ε 1,0
ε
NFAs to regular expressions
1/20/2016 Sofya Raskhodnikova; based on slides by Nick Hopper
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.
L4.17
0
1
001*0
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
L4.181/20/2016 Sofya Raskhodnikova; based on slides by Nick Hopper
R(qs,q) = a*b
R(qa,q) = Ø
R(q,qs) = Ø
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
q
a b
aa*bqs qa
Generalized NFAs