Presentation is loading. Please wait.

Presentation is loading. Please wait.

Instructor: Aaron Roth

Similar presentations


Presentation on theme: "Instructor: Aaron Roth"— Presentation transcript:

1 Instructor: Aaron Roth aaroth@cis.upenn.edu
CIS 262 Automata, Computability, and Complexity Spring Instructor: Aaron Roth Lecture: February 11, 2019

2 Course Logistics Midterm Date: Wednesday, February 27. (In class)

3 NFAs with e-transitions
A number consists of one or more digits 0..9 (but first digit is not 0) and can be optionally preceded by + or - q0 q1 e, +, - 1..9 q2 0..9 Meaning of e-transition: state may change without consuming any input symbol Acceptance as before: a string is accepted as long as some execution succeeds

4 e-NFAs Transition function D : Q x [ S U { e } ]  2Q
Such transitions do not increase expressiveness: An NFA with e-transitions can be compiled into an equivalent DFA by modifying the subset construction e-transitions can allow more natural/succinct description Read the textbook for details

5 Constructions on Automata/Languages
L1 = { w | w ends with a }, where S = { a, b } q0 q1 a b DFA M1: L2 = { w | w contains at least one b } s0 s1 b a a, b DFA M2: L = { w | w ends with a and contains at least one b } L = L1 intersect L2 Can we construct DFA for L from DFAs M1 and M2

6 Product Construction Example
q0 q1 a b s0 s1 b a a, b DFA M2: DFA M1: Goal: Construct DFA M that accepts w iff both M1 and M2 accept w What state should M maintain ? M should simultaneously execute both M1 and M2 on its input: state of M = ( state of M1 , state of M2 )

7 Product Construction DFA M2: DFA M1:
q0 q1 a b s0 s1 b a a, b DFA M2: DFA M1: a ( q0 , s0 ) ( q1 , s0 ) a M accepts w iff both M1 and M2 accept w L(M) = L(M1) intersect L(M2) b b a ( q0 , s1 ) ( q1 , s1 ) b a b

8 Product Construction DFA M1 = (Q1, S, q01, F1, d1)
Goal: Construct DFA M that accepts w iff both M1 and M2 accept w Can we define states/transitions of M in terms of states/transitions of M1 and M2 ? M should simultaneously execute both M1 and M2 on its input: state of M = ( state of M1 , state of M2 )

9 Product Construction DFA M1 = (Q1, S, q01, F1, d1)
Set of states of M: Q = Q1 x Q2 = { (q1,q2) | q1 in Q1 and q2 in Q2 } Initial state of M: q0 = (q01 , q02 ) Transition function of M: d((q1,q2), s) = (d1(q1, s), d2 (q2, s)) Set of final states of M: F = F1 x F2 = {(q1,q2) | q1 in F1 and q2 in F2 }

10 Product Construction: Correctness
DFA M1 = (Q1, S, q01, F1, d1) DFA M2 = (Q2, S, q02, F2, d2) DFA M = (Q1 x Q2, S, (q01 , q02), F1 x F2, d), where d((q1,q2), s) = (d1(q1, s), d2(q2, s)) Prove: L(M) = L(M1) intersect L(M2) M is constructed so that state of M after processing any input w records states of both M1 and M2 after processing w What’s the precise claim that can be proved by induction on string w? Claim: For all strings w, d*(q0, w) = (d1*(q01, w), d2*(q02, w)) Prove claim by induction on w It follows that M accepts w if and only if both M1 and M2 do

11 Product Construction: Complexity
DFA M1 = (Q1, S, q01, F1, d1) DFA M2 = (Q2, S, q02, F2, d2) DFA M = (Q1 x Q2, S, (q01 , q02), F1 x F2, d), where d((q1,q2), s) = (d1(q1, s), d2(q2, s)) How many states does M have ? Product of number of states of M1 and M2: |Q| = |Q1|x|Q2|

12 Closure under Intersection
Theorem: The class of regular languages is closed under intersection That is: if two languages L1 and L2 are both regular, then so is their intersection Proof: Consider regular languages L1 and L2 By definition of regular languages, there exist DFAs M1 and M2 such that L(M1) = L1 and L(M2)= L2 Using the product construction just described, construct DFA M such that L(M) = L(M1) intersect L(M2) = L1 intersect L2 By definition, L = L1 intersect L2, is a regular language. QED

13 Closure Properties of Language Classes
What does it mean: a class X of languages is closed under operation OP ? Examples of X: regular, decidable, recursively enumerable, P, NP … Each such class corresponds to a set of problems with some shared characteristics (e.g. how efficiently they can be solved) Examples of OP: intersection, union, complement, and many more operations defined on sets/languages X is closed under OP : if we choose two languages L1 and L2 both belonging to class X, and apply the operation OP to them, the result is guaranteed to be in X X is not closed under OP: there exist languages L1 and L2 both in X, but the result of applying the operation OP to them is not in the class X

14 Why Study Closure Properties ?
We know: regular languages are closed under intersection If we are designing a high-level language for specifying regular languages in intuitive manner (e.g., regular expressions, coming up…), it’s ok to add the intersection operator to such a language If we know that regular languages are not closed under some specific operation, say OP, then it does not make sense to add OP to regular expressions Theoretical insights: understanding which operations a class of languages is closed under (and which it’s not) gives understanding of its structure

15 Closure under Union Theorem: The class of regular languages is closed under union How to prove this ? Consider two regular languages L1 and L2 By definition of regular languages, there exist DFAs M1 and M2 such that L(M1) = L1 and L(M2)= L2 Goal: To prove that L = L1 U L2 is regular Suffices to construct a DFA M such that L(M) = L1 U L2 Can we modify the product construction for intersection to construct such a desired DFA ?

16 Closure under Union DFA M1 = (Q1, S, q01, F1, d1)
Set of states of M: Q = Q1 x Q2 = { (q1,q2) | q1 in Q1 and q2 in Q2 } Initial state of M: q0 = (q01 , q02 ) Transition function of M: d((q1,q2), s) = (d1(q1, s), d2 (q2, s)) Set of final states of M: F = {(q1,q2) | q1 in F1 or q2 in F2 } = ( F1 x Q2) U (Q1 x F2) M accepts w if and only if either M1 or M2 accepts w

17 Concatenation of Languages
Concatenation of strings: u.v Concatenation of languages: L1 . L2 = { u.v | u in L1 and v in L2 } That is, a string w is in L1 . L2 if w can be split into (not necessarily equal) parts such that first part is in L1 and second is in L2 Example: L1 = { w | w ends with a } L2 = { w | w contains only b’s } What is L1 . L2 ? Set of strings w such that there is an a symbol followed by only b’s i.e. strings of the form … a b … b

18 Closure under Concatenation
Theorem: The class of regular languages is closed under concatenation Consider two regular languages L1 and L2 By definition of regular languages, there exist DFAs M1 and M2 such that L(M1) = L1 and L(M2)= L2 Goal: To prove that L = L1 . L2 is regular Suffices to construct a DFA M such that L(M) = L1 . L2

19 Towards Concatenation Construction
Given input w, M needs to check if it is possible to split w into two parts such that first is accepted by M1 and second accepted by M2 Intuitively, M should first act like M1, and when M1 is in a final state, switch to the initial state of M2, process the rest of the input acting like M2, and declare success if M2 is in its final state at end Challenge: when to switch ? When M1 is in a final state, need to guess whether to switch to M2 or continue to act like M1 ! In L(M1) In L(M2) ?? In L(M1) In L(M2) ??

20 Concatenation Construction
M1 M2

21 Concatenation Construction
Retain states and transitions of both machines + add e-transitions from final states of M1 to the initial state of M2 M1 M2 e e

22 Concatenation Construction
M1 M2 e DFA M1 = (Q1, S, q01, F1, d1) DFA M2 = (Q2, S, q02, F2, d2) Set of states of e-NFA M: Q = Q1 U Q2 (assuming Q1 and Q2 are disjoint) Initial state of M: q0 = q01 Set of final states of M: F = F2 Transition function of M: D(q, s) = { d1 (q, s) } if q is in Q1 and { d2(q, s) } otherwise D(q, e) = { q02 } if q is in F1 and { } otherwise

23 Concatenation Construction
M1 M2 e Why is the construction correct ? Consider an input w such that there is a way to split w = u.v with u in L(M1) and v in L(M2) Then, there is an accepting run of M on w: switch to M2’s initial state using e-transition after processing u Suppose M accepts w. Then there must at least one successful run. This run ends up in a final state of M2, so must have switched to initial state of M2 using an e-transition at some point: the prefix of input processed till then is accepted by M1 and rest by M2 Thus, L(M) = L(M1) . L(M2)

24 Recap: Concatenation Construction
M1 M2 e The e-NFA M can be converted to an equivalent DFA M’ using the subset construction Note states of M’ are sets of states of M: in a way, M’ tries all possible ways to split the input Bottomline: Regular languages are closed under concatenation Note: M1 and M2 don’t have to be DFAs, even when they are NFAs (with e-transitions) same construction yields M with L(M)=L(M1).L(M2) In L(M1) In L(M2) ??

25 Iteration: Kleene* Operation
L* = { w | w can be split into multiple parts s.t. each part is in L } L* = Repeated concatenation = { e } U L U L.L U L.L.L U … Empty string e is always in L* (by defn, setting number of parts = 0) Example: L = { w | count(w,a)= 2 } What is L* ? { w | count(w,a) is even } In L In L In L

26 Closure under Kleene-*
Theorem: The class of regular languages is closed under Kleene-* Consider a regular language L, and let M be DFA (or NFA) accepting it Goal: To construct NFA M’ that accepts L* Given an input w, M’ needs to check if there is a way to split w into multiple parts such that each part is accepted by M Informally, start executing M on w, when the current state is an accepting state, decide nondeterministically to switch to the initial state (i.e. restart M) using e-transition

27 Kleene-* Construction
M M’ e e Is L(M’) = L(M)* ? Almost, but not quite, in particular, may reject e, which is in L(M)*

28 Kleene-* Construction
M M’ e e Is L(M’) = L(M)* ? No ! Figure out why

29 Kleene-* Construction
M M’ e e e Now the construction is correct: L(M’) = L(M)*

30 Kleene-* Construction
Given DFA/NFA M, we construct an e-NFA M’ States of M’ = States of M + new state q’0 Initial state of M’ = q’0 Final states of M’ = Final states of M + q’0 Retain all original transitions of M Add e-transition from each final state (including q’0) to state q0


Download ppt "Instructor: Aaron Roth"

Similar presentations


Ads by Google