Since CFL is closed under intersection with regular languages, we can do

Similar documents
Please give details of your answer. A direct answer without explanation is not counted.

CSE 105 THEORY OF COMPUTATION

CpSc 421 Final Exam December 15, 2006

October 6, Equivalence of Pushdown Automata with Context-Free Gramm

Homework. Context Free Languages. Announcements. Before We Start. Languages. Plan for today. Final Exam Dates have been announced.

Homework Assignment 6 Answers

CISC4090: Theory of Computation

CS 301. Lecture 18 Decidable languages. Stephen Checkoway. April 2, 2018

Context-Free Languages (Pre Lecture)

Fundamentele Informatica II

CS500 Homework #2 Solutions

Languages, regular languages, finite automata

2.1 Solution. E T F a. E E + T T + T F + T a + T a + F a + a

Theory Bridge Exam Example Questions

CSE 105 THEORY OF COMPUTATION

Section 1 (closed-book) Total points 30

CSE 355 Test 2, Fall 2016

CS154 Final Examination

Pushdown Automata. Pushdown Automata. Pushdown Automata. Pushdown Automata. Pushdown Automata. Pushdown Automata. The stack

Harvard CS 121 and CSCI E-207 Lecture 10: CFLs: PDAs, Closure Properties, and Non-CFLs

CSE 211. Pushdown Automata. CSE 211 (Theory of Computation) Atif Hasan Rahman

CSE 105 THEORY OF COMPUTATION

Pushdown automata. Twan van Laarhoven. Institute for Computing and Information Sciences Intelligent Systems Radboud University Nijmegen

Theory of Computation

Homework 8. a b b a b a b. two-way, read/write

Pushdown Automata (2015/11/23)

This lecture covers Chapter 6 of HMU: Pushdown Automata

Pushdown Automata: Introduction (2)

MTH401A Theory of Computation. Lecture 17

(pp ) PDAs and CFGs (Sec. 2.2)

Notes for Comp 497 (Comp 454) Week 12 4/19/05. Today we look at some variations on machines we have already seen. Chapter 21

MA/CSSE 474 Theory of Computation

Automata and Computability. Solutions to Exercises

Pumping Lemma for CFLs

Accept or reject. Stack

1 More finite deterministic automata

PS2 - Comments. University of Virginia - cs3102: Theory of Computation Spring 2010

Automata and Computability. Solutions to Exercises

UNIT-VI PUSHDOWN AUTOMATA

9.2 Multiplication Properties of Radicals

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Ogden s Lemma for CFLs

Context-Free Languages

Closure under the Regular Operations

NPDA, CFG equivalence

Further discussion of Turing machines

Properties of Context-Free Languages. Closure Properties Decision Properties

CS 341 Homework 16 Languages that Are and Are Not Context-Free

Note: In any grammar here, the meaning and usage of P (productions) is equivalent to R (rules).

1. Draw a parse tree for the following derivation: S C A C C A b b b b A b b b b B b b b b a A a a b b b b a b a a b b 2. Show on your parse tree u,

Final Exam Comments. UVa - cs302: Theory of Computation Spring < Total

CSE 311: Foundations of Computing. Lecture 23: Finite State Machine Minimization & NFAs

Nondeterministic finite automata

CS 21 Decidability and Tractability Winter Solution Set 3

Computational Models: Class 5

Computability Theory

CSE 105 Theory of Computation

Homework. Turing Machines. Announcements. Plan for today. Now our picture looks like. Languages

Your Name: UVa Id:

Turing Machines Part III

More About Turing Machines. Programming Tricks Restrictions Extensions Closure Properties

Comment: The induction is always on some parameter, and the basis case is always an integer or set of integers.

Lecture 2: Connecting the Three Models

Equivalence of Regular Expressions and FSMs

Mathematics 96 (3581) CA (Class Addendum) 1: Commutativity Mt. San Jacinto College Menifee Valley Campus Spring 2013

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata (cont )

CpSc 421 Homework 9 Solution

Discrete Structures Proofwriting Checklist

10. The GNFA method is used to show that

CS5371 Theory of Computation. Lecture 9: Automata Theory VII (Pumping Lemma, Non-CFL, DPDA PDA)

CS154 Final Examination

Theory of Computation (IV) Yijia Chen Fudan University

Equivalence of CFG s and PDA s

CFGs and PDAs are Equivalent. We provide algorithms to convert a CFG to a PDA and vice versa.

CSE 105 THEORY OF COMPUTATION

How to Pop a Deep PDA Matters

Fundamentele Informatica 3 Antwoorden op geselecteerde opgaven uit Hoofdstuk 7 en Hoofdstuk 8

Solutions to Old Final Exams (For Fall 2007)

The Pumping Lemma. for all n 0, u 1 v n u 2 L (i.e. u 1 u 2 L, u 1 vu 2 L [but we knew that anyway], u 1 vvu 2 L, u 1 vvvu 2 L, etc.

CpSc 421 Final Exam December 6, 2008

CS5371 Theory of Computation. Lecture 5: Automata Theory III (Non-regular Language, Pumping Lemma, Regular Expression)

NP, polynomial-time mapping reductions, and NP-completeness

Turing Machine Variants

The Post Correspondence Problem

CISC 4090 Theory of Computation

I have read and understand all of the instructions below, and I will obey the University Code on Academic Integrity.

E.g. The set RE of regular expressions is given by the following rules:

Lecture Notes on Inductive Definitions

T (s, xa) = T (T (s, x), a). The language recognized by M, denoted L(M), is the set of strings accepted by M. That is,

CpSc 421 Homework 1 Solutions

input tape head moves current state a a

Undecidable Problems and Reducibility

ECS 120: Theory of Computation UC Davis Phillip Rogaway February 16, Midterm Exam

Computational Models Lecture 5

Theory of Computation

Computability Theory

Thus, X is connected by Problem 4. Case 3: X = (a, b]. This case is analogous to Case 2. Case 4: X = (a, b). Choose ε < b a

Math 308 Midterm Answers and Comments July 18, Part A. Short answer questions

6.045: Automata, Computability, and Complexity Or, Great Ideas in Theoretical Computer Science Spring, Class 8 Nancy Lynch

Miscellaneous. Closure Properties Decision Properties

Transcription:

Exercise 7.3.1 Show that the operation cycle preserves context-free languages, where cycle is defined by: cycle(l) = {xy yx L} Informally, cycle(l) allows all strings constructed as follows: take a string w from L, and choose an arbitrary position in the middle. Take the second part (this is x), then wrap around and concatenate the first part (this is y). For example, if abcd L, then all of the following strings are in cycle(l): abcd, bcda, cdab, dabc. Solution We will prove this by PDA construction. Given a PDA P for L, we ll create PDA P c for cycle(l). Both accept by empty stack. P c simulates an accepting computation in P, but it starts in the middle and simulates P on x, then wraps around and simulates P on y. The difficulty lies in the stack. When P c begins consuming x, it is missing the stack symbols that P would have from consuming y. To resolve this, we allow P c to guess the top stack symbol and pop it by pushing a negated version. Later, when simulating P on y, we confirm these guesses: instead of pushing symbols, we confirm and pop the guesses. We use a stack marker # to delimit the guessed symbols from the rest of the stack. Start by guessing the top symbol (the first one we ll pop) left by y. Place a copy above and below the marker. Then begin consuming x by simulating P normally on the portion above the stack above the marker. Eventually we return to the marker, meaning we popped the symbol we guessed (note: it is now recorded below the marker). Here is an example where we guess that y left A as the top stack symbol: Start configuration Z 0 Mark the stack #Z 0 Guess top symbol A#AZ 0 Arbitrary build up DEF A#AZ 0... Eventually pop A #AZ 0 On return to the marker, one thing we can do is guess the next symbol to pop and repeat the step described above: Guess B B#BAZ 0...... Eventually pop B #BAZ 0 Guess C C#CBAZ 0...... Eventually pop C #CBAZ 0 Another option when returning to the marker is to guess that we have finished consuming x this means we must have emptied the stack left by y, so it is time to start consuming y and verifying that it builds the stack we guessed.

The general idea is that instead of pushing symbols onto the stack, we ll pop the previous guesses, checking that they match up. There are several technical details to this phase. First, we must encode the top stack symbol for the simulation of P into the state, since we are now using the stack itself to hold guesses. For example, in the beginning of this phase P would be reading Z 0 so we transition from state p to p Z0 to indicate that we are reading Z 0. If we push a C by popping the C below the marker, we ll transition to state p C to record the the top symbol (C is no longer on the stack). Second, when pushing a symbol in this phase, there are two options. If we guess that the symbol we re pushing will eventually be popped during this phase, we push it on top of the marker and simulate P normally above the marker. If we guess that the symbol we re pushing will be the last one pushed at this position, then we verify the previous guess by popping the symbol below the marker (assuming they match up). Here is an example: Begining of phase p Z0 #CBAZ 0 Arbitrary buildup p Z0 XY Z#CBAZ 0... p Z0... Eventually return p Z0 #CBAZ 0 Push a C p C #BAZ 0... p C... Push a B p B #AZ 0... p B... Push an A p A #Z 0 Accept! p A You might notice that there are even more technical details. The example I ve shown pops the symbol below the marker in one step. We can simulate this with three steps: (1) pop the marker, (2) pop the symbol and (3) replace the marker. Likewise, a transition in δ may push multiple symbols we can pop multiple symbols by breaking this into several steps using intermediate states. Comments An English description with less detail than this was sufficient. You ll notice that even this solution did not cover every technical detail. This was a very difficult question and only a few students got full credit, so don t be too concerned if you did poorly. Some comments about the grading, from which you can extract some general lessons: Students who demonstrated clear understanding of the problem and gave a plausible approach to solving it were awarded the most partial credit, even if that approach was not correct. Many students submitted solutions with elements of the correct solution but it was obvious they got hints either from office hours or other students and understood very little about the solution. These students received little credit.

CS 381 Homework 10 Solutions 2. Show that half is not closed for CFL s. Let L = { a n b n c i dd 3i d n>0, i>0 } Since CFL is closed under intersection with regular languages, we can do half(l) a*b*c*d which splits L into two halves: a n b n c i d and d 3i d In order for these to be of equal length, i = n, So half(l) a*b*c*d = a n b n c n d, which we know is not a CFL. Therefore half(l) is not closed for CFLs. Note: There are many choices for L which will work.

CS381, Homework #10 Solutions Question 3 (7.3.4) Show that shuffle(l, R) is context free, where L is a CFL and R is a regular language This can be shown via a machine construction. First assume that L can be represented by a one-state PDA P which accepts by empty stack. Here, P = ({q p }, Σ, Γ, δ p, q p, Z 0 ). R is represented by a DFA D = (Q d, Σ, δ d, q 0, F d ). Now, for production in δ p (q p, α, β) = (q p, γ), define a new production for each state s Q d, such that: δ (s, α, β) = (s, γ) Now for transition in δ d (q, α) = γ, define a new production: δ (q, α, S) = (γ, S) Now finally define transition functions for all final states f F d : δ(f, ɛ, ɛ) = (f final, ɛ) This transition says that whenever we re in a final state in our DFA D, and we have an empty stack on our PDA P, then we should transition to a final state in the new PDA, because the acceptance criteria for both languages have been met. Now the final PDA, P = (Q d {f final }, Σ, Γ, δ, q 0, {f final }). So the states of this new PDA are the states of D, and the transition function allows us to change state in D, and accept everything that would be accepted by P. Give a counterexample to show that if L 1 and L 2 are both CFL s, then the shuffle(l 1, L 2 ) need not be a CFL. If we make L 1 = a n b n, and L 2 = c n d n, then by taking shuffle(l 1, L 2 ) a c b d, we can produce a n c m b n d m, a language which clearly is not context free. Since context free languages are closed under intersection with regular sets, it must be that shuffle is not context free. A common mistake that people made here was assuming that if they had some a n in each language, that it was necessarily the same n in the final language. That is not sufficient to show that the output might not be a CFL, because unless the terms are interwovel like they are here, it is possible to write a CFL for say a n b n c m d m. Declaring m = n to be a special case proves nothing, it just happens by coincidence. 1

CS381 Homework 10: Problem 4 Question 4 We start with a machine with contents 01 n 01 m 0 and want to finish with contents 01 nm 0 with some possible zeroes at the end. Note: Multiplication is just repeated addition. In other words: n m = m + m + m +... + m }{{} n times Therefore, with the pointer starting at the first 0, for each 1 we see we: Go to the next 0 We copy the string of 1 s we see to the end of the string (passed the 0) We delete the 1 we were looking at The resulting tape should look like 0 n+2 1 m 01 nm, so we just have to delete everything in front of the 01 nm term and add a zero after it, and we are done. 1