Outline CS21 Decidability and Tractability Lecture 4 January 14, 2019 FA and Regular Exressions Non-regular languages: Puming Lemma Pushdown Automata Context-Free Grammars and Languages January 14, 2019 CS21 Lecture 4 1 January 14, 2019 CS21 Lecture 4 2 Theorem: a language L is recognized by a FA if and only if L is described by a regular exression. Must rove two directions: ( ) L is recognized by a FA imlies L is described by a regular exression ( ) L is described by a regular exression imlies L is recognized by a FA. ( ) L is recognized by a FA imlies L is described by a regular exression Proof: given FA M that recognizes L, we will 1. build an equivalent machine Generalized Nondeterministic Finite Automaton (GNFA) 2. convert the GNFA into a regular exression January 14, 2019 CS21 Lecture 4 3 January 14, 2019 CS21 Lecture 4 4 GNFA definition: it is a NFA, but may have regular exressions labeling its transitions GNFA accets string w Σ* if can be written w = w 1 w 2 w 3 w k where each w i Σ*, and there is a ath from the start state to an accet state in which the i th transition traversed is labeled with R for which w i L(R) Recall ste 1: build an equivalent GNFA Our FA M is a GNFA. We will require normal form for GNFA to make the roof easier: single accet state q accet that has all ossible incoming arrows every state has all ossible outgoing arrows; excetion: start state q 0 has no self-loo January 14, 2019 CS21 Lecture 4 5 January 14, 2019 CS21 Lecture 4 6 1
converting our FA M into GNFA in normal form: On to ste 2: convert the GNFA into a regular exression 0 0,11 ε if normal-form GNFA has two states: ε R M ε the regular exression R labeling the single transition describes the language recognized by the GNFA January 14, 2019 CS21 Lecture 4 7 January 14, 2019 CS21 Lecture 4 8 if GNFA has more than 2 states: how to reair the transitions: for every air of states q i and q j do q i R 4 q j (R 1 )(R 2 )*(R 3 ) (R 4 ) select one ; delete it; reair transitions so that machine still recognizes same language. reeat until only 2 states. R 1 q i q j R 2 R 3 January 14, 2019 CS21 Lecture 4 9 January 14, 2019 CS21 Lecture 4 10 summary: FA M k-state GNFA (k-1)-state GNFA (k-2)-state GNFA 2-state GNFA R want to rove that this rocedure is correct, i.e. L(R) = language recognized by M FA M equivalent to k-state GNFA i-state GNFA equivalent to (i-1)-state GNFA (we will rove ) 2-state GFNA equivalent to R Claim: i-state GNFA G equivalent to (i-1)- state GNFA G (obtained by removing ) Proof: if G accets string w, then it does so by entering states: q 0, q 1, q 2, q 3,, q accet if none are then G accets w (see slide) else, break state sequence into runs of : q 0 q 1 q i q j q accet transition from q i to q j in G allows all strings taking G from q i to q j using (see slide) thus G accets w January 14, 2019 CS21 Lecture 4 11 January 14, 2019 CS21 Lecture 4 12 2
q i R 4 q j (R 1 )(R 2 )*(R 3 ) (R 4 ) q i R 4 q j (R 1 )(R 2 )*(R 3 ) (R 4 ) R 1 R 3 q i q j R 1 R 3 q i q j R 2 R 2 January 14, 2019 CS21 Lecture 4 13 January 14, 2019 CS21 Lecture 4 14 Proof (continued): if G accets string w, then every transition from q i to q j traversed in G corresonds to either a transition from q i to q j in G or transitions from q i to q j via in G In both cases G accets w. Conclude: G and G recognize the same language. January 14, 2019 CS21 Lecture 4 15 Theorem: a language L is recognized by a FA iff L is described by a regular exr. Languages recognized by a FA are called regular languages. Rehrasing what we know so far: regular languages closed under 3 oerations NFA recognize exactly the regular languages regular exressions describe exactly the regular languages January 14, 2019 CS21 Lecture 4 16 Limits on the ower of FA Is every language describable by a sufficiently comlex regular exression? If someone asks you to design a FA for a language that seems hard, how do you know when to give u? Is this language regular? {w : w has an equal # of 01 and 10 substrings} January 14, 2019 CS21 Lecture 4 17 Limits on the ower of FA Intuition: FA can only remember finite amount of information. They cannot count languages that entail counting should be non-regular Intuition not enough: {w : w has an equal # of 01 and 10 substrings} = 0Σ*0 1Σ*1 but {w: w has an equal # of 0 and 1 substrings} is not regular! January 14, 2019 CS21 Lecture 4 18 3
Limits on the ower of FA How do you rove that there is no Finite Automaton recognizing a given language? Non-regular languages Puming Lemma: Let L be a regular language. There exists an integer ( uming length ) for which every w L with w can be written as w = xyz such that 1. for every i 0, xy i z L, and 2. y > 0, and 3. xy. January 14, 2019 CS21 Lecture 4 19 January 14, 2019 CS21 Lecture 4 20 Non-regular languages Using the Puming Lemma to rove L is not regular: assume L is regular then there exists a uming length select a string w L of length at least argue that for every way of writing w = xyz that satisfies (2) and (3) of the Lemma, uming on y yields a string not in L. contradiction. January 14, 2019 CS21 Lecture 4 21 Theorem: L = {0 n 1 n : n 0} is not regular. Proof: let be the uming length for L choose w = 0 1 w = xyz, with y > 0 and xy. January 14, 2019 CS21 Lecture 4 22 3 ossibilities: in each case, uming on y gives a string not in language L. Theorem: L = {w: w has an equal # of 0s and 1s} is not regular. Proof: let be the uming length for L choose w = 0 1 w = xyz, with y > 0 and xy. January 14, 2019 CS21 Lecture 4 23 January 14, 2019 CS21 Lecture 4 24 4
3 ossibilities: first 2 cases, uming on y gives a string not in language L; 3 rd case a roblem! recall condition 3: xy since w = 0 1 we know more about how it can be divided, and this case cannot arise: so we do get a contradiction. conclude that L is not regular. January 14, 2019 CS21 Lecture 4 25 January 14, 2019 CS21 Lecture 4 26 Theorem: L = {0 i 1 j : i > j} is not regular. Proof: let be the uming length for L choose w = 0 +1 1 w = 000000000 01111111 1 +1 w = xyz, with y > 0 and xy. 1 ossibility: uming on y gives strings in the language (?) this seems like a roblem Lemma states that for every i 0, xy i z L xy 0 z not in L. So L not regular. January 14, 2019 CS21 Lecture 4 27 January 14, 2019 CS21 Lecture 4 28 Proof of the Puming Lemma Let M be a FA that recognizes L. Set = number of states of M. Consider w L with w. On inut w, M must go through at least +1 states. There must be a reeated state (among first +1). x y January 14, 2019 CS21 Lecture 4 29 z M FA Summary A roblem is a language A comutation receives an inut and either accets, rejects, or loos forever. A comutation recognizes a language (it may also decide the language). Finite Automata erform simle comutations that read the inut from left to right and emloy a finite memory. January 14, 2019 CS21 Lecture 4 30 5
FA Summary The languages recognized by FA are the regular languages. The regular languages are closed under union, concatenation, and star. Nondeterministic Finite Automata may have several choices at each ste. NFAs recognize exactly the same languages that FAs do. FA Summary Regular exressions are languages built u from the oerations union, concatenation, and star. Regular exressions describe exactly the same languages that FAs (and NFAs) recognize. Some languages are not regular. This can be roved using the Puming Lemma. January 14, 2019 CS21 Lecture 4 31 January 14, 2019 CS21 Lecture 4 32 6