Instructor: Aaron Roth

Slides:



Advertisements
Similar presentations
Lecture 24 MAS 714 Hartmut Klauck
Advertisements

1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
Finite Automata Great Theoretical Ideas In Computer Science Anupam Gupta Danny Sleator CS Fall 2010 Lecture 20Oct 28, 2010Carnegie Mellon University.
1 Introduction to Computability Theory Lecture4: Regular Expressions Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
Lecture 3UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 3.
Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state.
CS5371 Theory of Computation
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Regular.
Fall 2004COMP 3351 Single Final State for NFA. Fall 2004COMP 3352 Any NFA can be converted to an equivalent NFA with a single final state.
1 Single Final State for NFAs and DFAs. 2 Observation Any Finite Automaton (NFA or DFA) can be converted to an equivalent NFA with a single final state.
Lecture 3 Goals: Formal definition of NFA, acceptance of a string by an NFA, computation tree associated with a string. Algorithm to convert an NFA to.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
1 A Single Final State for Finite Accepters. 2 Observation Any Finite Accepter (NFA or DFA) can be converted to an equivalent NFA with a single final.
Formal Language Finite set of alphabets Σ: e.g., {0, 1}, {a, b, c}, { ‘{‘, ‘}’ } Language L is a subset of strings on Σ, e.g., {00, 110, 01} a finite language,
CMSC 330: Organization of Programming Languages Theory of Regular Expressions Finite Automata.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
CS 203: Introduction to Formal Languages and Automata
Finite Automata Great Theoretical Ideas In Computer Science Victor Adamchik Danny Sleator CS Spring 2010 Lecture 20Mar 30, 2010Carnegie Mellon.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
Regular Expressions CS 130: Theory of Computation HMU textbook, Chapter 3.
Complexity and Computability Theory I Lecture #5 Rina Zviel-Girshin Leah Epstein Winter
1 Chapter 2 Finite Automata (part a) Hokkaido, Japan.
CIS 262 Automata, Computability, and Complexity Fall Instructor: Aaron Roth
CIS Automata and Formal Languages – Pei Wang
CSE 105 theory of computation
PROPERTIES OF REGULAR LANGUAGES
CSE 105 theory of computation
CSE 105 theory of computation
CSE 105 theory of computation
Single Final State for NFA
Chapter 2 FINITE AUTOMATA.
CSE 105 theory of computation
Decision Properties of Regular Languages
Cpt S 317: Spring 2009 Reading: Chapters 1-4
Closure Properties for Regular Languages
Properties of Regular Languages
CS 154, Lecture 3: DFANFA, Regular Expressions.
COSC 3340: Introduction to Theory of Computation
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
Chapter 4 Properties of Regular Languages
Instructor: Aaron Roth
Instructor: Aaron Roth
Instructor: Aaron Roth
Instructor: Aaron Roth
Instructor: Aaron Roth
Instructor: Aaron Roth
Instructor: Aaron Roth
Instructor: Aaron Roth
CSE 105 theory of computation
CSE 105 theory of computation
Chapter 1 Regular Language
Instructor: Aaron Roth
Instructor: Aaron Roth
Instructor: Aaron Roth
Instructor: Aaron Roth
Instructor: Aaron Roth
CSE 105 theory of computation
CSC312 Automata Theory Kleene’s Theorem Lecture # 12
CSE 105 theory of computation
Instructor: Aaron Roth
Instructor: Aaron Roth
Instructor: Aaron Roth
CSE 105 theory of computation
CSE 105 theory of computation
CSE 105 theory of computation
Presentation transcript:

Instructor: Aaron Roth aaroth@cis.upenn.edu CIS 262 Automata, Computability, and Complexity Spring 2019 http://www.seas.upenn.edu/~cse262/ Instructor: Aaron Roth aaroth@cis.upenn.edu Lecture: February 11, 2019

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

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

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

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

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 )

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

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 )

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 }

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

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|

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

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

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

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 ?

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

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

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

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) ??

Concatenation Construction M1 M2

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

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

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)

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) ??

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

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

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)*

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

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

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