Theory of Computation Peer Instruction Lecture Slides by

Theory of Computation Peer Instruction Lecture Slides by Dr. Cynthia Lee, UCSD are licensed under a Creative Commons Attribution-Non. Commercial-Share. Alike 3. 0 Unported License. Based on a work at www. peerinstruction 4 cs. org. 1

If a language isn’t regular, it just might be one of the… CONTEXT-FREE LANGUAGES PDA

Understanding Pushdown Automata The edge from q 0 to q 1 does what? a) Lets you go to q 1 without reading any input (on epsilon) b) Lets you go to q 1 on epsilon or ‘$’ c) Lets you go to q 1 on ‘$’

Understanding Pushdown Automata In addition to what we said in the last question, the edge from q 0 to q 1 does what else? a) b) c) d) Pushes one entry onto the stack (epsilon) Pushes one entry onto the stack (‘$’) Pushes two entries onto the stack (epsilon and ‘$’) Pops two entries off the stack (epsilon and ‘$’)

Tracing in a Pushdown Automaton Input “aabb” into this PDA. After “aa” has been read, what is on the stack? top of stack a) b) c) d) e) b b a a 0 ϵ ϵ ϵ bottom of stack

Language of a Pushdown Automaton Which is the best description of the language of the given PDA? a) { w | number of b’s in w >= number of a’s in w} b) {w | w = anbn+1 for some n>=0} c) { w | w = anbn+2 for some n>=0} d) { w | w = anb 2 n for some n>=0} e) {w | w = 0 anb 2 n 0 for some n>=0}

Tracing in a Pushdown Automaton • Which string is NOT accepted by this PDA? a) b) c) d) e) aabb abbbc abbccc aabcc None or more than one of the above

Tracing in a Pushdown Automaton top of stack • Which choice depicts a stack state that occurs at some point during the successful* processing of the string “aaabbbc” on the given PDA? bottom of stack a) a a a b b b c b) # a c) a # d) # λ e) None of the above * Ignore all nondeterministic paths that end in rejecting/getting stuck.

Why did we push ‘#’ onto the stack? a) b) c) d) e) We didn’t have to, because we already “counted” the a’s by pushing them on the stack It’s something we do because of convention, but it isn’t necessary to correctness We did it to make sure that we didn’t cause a crash/error by trying to pop something off an empty stack It is necessary to correctness None or more than one of the above

CFLs! THE CLASS OF CONTEXT-FREE LANGUAGES

Which Venn diagram best represents the classes of languages we have studied? (a) (b) CFLs RLs (c) RLs (d) CFLs = RLs (e) None of the above RLs CFLs Note: CFLs = Context. Free Languages, RLs = Regular Languages

What methods can we use to prove/disprove each of these? (a) (b) CFLs RLs (c) RLs (d) CFLs = RLs CFLs Note: CFLs = Context. Free Languages, RLs = Regular Languages

Famous People: Noam Chomsky • In this class, you know him as the namesake of “Chomsky Normal Form” • A linguist who has taught at MIT for 55 years • Famous for: Developed theories of conetxt-free grammars for analysis of human language – A mathematical model of language – Discoveries crossed over into Computer Science • Perhaps now equally well known for his outspoken criticism of US foreign policy and his radical political views – Anarchist – Vehement war critic, war on drugs critic – Co-wrote Manufacturing Consent, argues that the media in our society is harming democracy and promoting corporations and consumerism

Proving that languages that are NOT context-free CONTEXT-FREE PUMPING LEMMA

Limits of Context-Free Languages • What are the limitations of Context-Free languages • What are the limitations of PDA? – Stack size has no limit (infinite stack) – …. BUT, there’s only one of them – Stack can only be accessed at the top • What does that mean intuitively? When would you need more than one stack? Context-Free Regular Not Context-Free

PDA Language is 0 n 12 n Can we change this so it is 0 n 12 n 0 n?

Classic Not-Context-Free Language • anbncn for some n>=0 • INTUITIVELY, the problem is that a PDA recognizing this language would try to: – Push on the stack to count the ‘a’ section, then – Pop off the stack to match the ‘b’ section, then – You’ve “forgotton” n, now you can’t count the ‘c’ section • Aside: what could you do with a second stack? • THIS IS NOT A PROOF!! – Maybe there is a completely different way to approach this problem using PDA, which we just didn’t think of yet – But, turns out, there is no way to do this, and we can actually prove that

Aside: Recognizing anbncn for some n>=0 using a second stack

CFL Pumping Lemma

Proving {aibjck | 0<=i<=j<=k} is not Context-Free • s = apb pc p • i = ? ? ? – Can’t solve it with just one i! – For the case analysis in this proof, we need to use i=0 for some cases of how the string is sliced up, and i=2 for other cases of how the string is sliced up – Is that legal? ? ? • Yes. • The Pumping Lemma Game shows us why…

The REGULAR LANGUAGES Pumping Lemma Game Your Script Pumping Lemma’s Script • “I’m giving you a language L that I’m assuming is regular. ” • “Thanks. For the language L that you’ve given me, I pick this nice pumping length I call p. ” • “Excellent. I’m giving you this string s that I made using your p. It is in L and |s| >= p. I think you’ll really like it. ” • “Great string, thanks. I’ve cut s up into parts xyz for you. I won’t tell you what they are exactly, but I will say this: |y| > 0 and |xy| <= p. Also, you can remove y, or copy it as many times as you like, and the new string will still be in L, I promise!” • “Hm. I followed your directions for xyz, but when I [copy y N times or delete y], the new string is NOT is L! What happened? ” • “Well, then L wasn’t a regular language. Thanks for playing. ”

The CONTEXT-FREE LANGUAGES Pumping Lemma Game Your Script Pumping Lemma’s Script • “I’m giving you a language L that I’m assuming is context-free. ” • “Thanks. For the language L that you’ve given me, I pick this nice pumping length I call p. ” • “Excellent. I’m giving you this string s that I made using your p. It is in L and |s| >= p. I think you’ll really like it. ” • “Great string, thanks. I’ve cut s up into parts uvxyz for you. I won’t tell you what they are exactly, but I will say this: |vy| > 0 and |vxy| <= p. Also, you can remove v and y, or copy them as many times as you like (as in uvixyiz), and the new string will still be in L, I promise!” • “Hm. I followed your directions for uvxyz, but when I [copy vy N times or delete vy], the new string is NOT is L! What happened? ” • “Well, then L wasn’t a context-free language. Thanks for playing. ”

Review review… MIDTERM REVIEW

From last year’s midterm: 5. To prove a language is not regular, which method can be used? a) Show several DFAs or NFAs that almost, but not quite, recognize the language, and then conclude that no DFA or NFA can recognize the language. b) Use the Pumping Lemma for regular languages. c) Show a CFG that recognizes the language, and then conclude that the language is context-free, not regular. d) (b) and (c) e) None of the above.

(a) TRUE or (b) FALSE The following proof is valid: • A = {w | w=an for n>=0} is a regular language, and B = {w | w=bn for n>=0} is a regular language because we can produce DFA’s MA and MB for A and B, respectively (see drawings). Regular languages are closed under concatenation, therefore language AB = {w | w=anbn for n>=0} is a regular language. (valid in this case means the flow of logic is sound, even though may not do a great job of stating GIVEN/WANT TO SHOW, etc)
- Slides: 25