CSE 105 THEORY OF COMPUTATION

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

Automata and Computability. Solutions to Exercises

Pushdown automata. Informatics 2A: Lecture 9. Alex Simpson. 3 October, School of Informatics University of Edinburgh als@inf.ed.ac.

Formal Languages and Automata Theory - Regular Expressions and Finite Automata -

CS154. Turing Machines. Turing Machine. Turing Machines versus DFAs FINITE STATE CONTROL AI N P U T INFINITE TAPE. read write move.

Model 2.4 Faculty member + student

Pushdown Automata. place the input head on the leftmost input symbol. while symbol read = b and pile contains discs advance head remove disc from pile

SRM UNIVERSITY FACULTY OF ENGINEERING & TECHNOLOGY SCHOOL OF COMPUTING DEPARTMENT OF SOFTWARE ENGINEERING COURSE PLAN

Automata and Formal Languages

Honors Class (Foundations of) Informatics. Tom Verhoeff. Department of Mathematics & Computer Science Software Engineering & Technology

Finite Automata. Reading: Chapter 2

C H A P T E R Regular Expressions regular expression

Introduction to Finite Automata

Regular Languages and Finite State Machines

Finite Automata. Reading: Chapter 2

Turing Machines: An Introduction

(IALC, Chapters 8 and 9) Introduction to Turing s life, Turing machines, universal machines, unsolvable problems.

Automata Theory. Şubat 2006 Tuğrul Yılmaz Ankara Üniversitesi

Regular Expressions and Automata using Haskell

Reading 13 : Finite State Automata and Regular Expressions

3515ICT Theory of Computation Turing Machines

CSE 135: Introduction to Theory of Computation Decidability and Recognizability

Automata on Infinite Words and Trees

CS 3719 (Theory of Computation and Algorithms) Lecture 4

Genetic programming with regular expressions

Compiler Construction

ÖVNINGSUPPGIFTER I SAMMANHANGSFRIA SPRÅK. 15 april Master Edition

Deterministic Finite Automata

CSC4510 AUTOMATA 2.1 Finite Automata: Examples and D efinitions Definitions

Overview of E0222: Automata and Computability

Computer Architecture Syllabus of Qualifying Examination

Regular Languages and Finite Automata

CAs and Turing Machines. The Basis for Universal Computation

Computational Models Lecture 8, Spring 2009

Informatique Fondamentale IMA S8

CS 341: Foundations of Computer Science II elearning Section Syllabus, Spring 2015

Finite Automata and Regular Languages

Automata and Formal Languages. Push Down Automata. Sipser pages Lecture 13. Tim Sheard 1

10CS35: Data Structures Using C

CS5236 Advanced Automata Theory

Lecture I FINITE AUTOMATA

Implementation of Recursively Enumerable Languages using Universal Turing Machine in JFLAP

Intrusion Detection via Static Analysis

Increasing Interaction and Support in the Formal Languages and Automata Theory Course

Scanner. tokens scanner parser IR. source code. errors

CS101 Lecture 11: Number Systems and Binary Numbers. Aaron Stevens 14 February 2011

CS 301 Course Information

Increasing Interaction and Support in the Formal Languages and Automata Theory Course

Course Manual Automata & Complexity 2015

24 Uses of Turing Machines

Basics of Counting. The product rule. Product rule example. 22C:19, Chapter 6 Hantao Zhang. Sample question. Total is 18 * 325 = 5850

The Halting Problem is Undecidable

Fast nondeterministic recognition of context-free languages using two queues

=

Push-down Automata and Context-free Grammars

Philadelphia University Faculty of Information Technology Department of Computer Science First Semester, 2007/2008.

Regular Expressions with Nested Levels of Back Referencing Form a Hierarchy

1. Nondeterministically guess a solution (called a certificate) 2. Check whether the solution solves the problem (called verification)

Introduction to Automata Theory. Reading: Chapter 1

Converting Finite Automata to Regular Expressions

Bottom-Up Parsing. An Introductory Example

6.080/6.089 GITCS Feb 12, Lecture 3

CMPSCI 250: Introduction to Computation. Lecture #19: Regular Expressions and Their Languages David Mix Barrington 11 April 2013

Automata, languages, and grammars

Lecture summary for Theory of Computation

a 11 x 1 + a 12 x a 1n x n = b 1 a 21 x 1 + a 22 x a 2n x n = b 2.

CS103B Handout 17 Winter 2007 February 26, 2007 Languages and Regular Expressions

MACM 101 Discrete Mathematics I

6.3 Conditional Probability and Independence

On Winning Conditions of High Borel Complexity in Pushdown Games

Formal Grammars and Languages

Regular Languages and Finite Automata

PES Institute of Technology-BSC QUESTION BANK

Pushdown Automata. International PhD School in Formal Languages and Applications Rovira i Virgili University Tarragona, Spain

Turing Machines, Part I

Computability Theory

Introduction to Logic in Computer Science: Autumn 2006

T Reactive Systems: Introduction and Finite State Automata

ω-automata Automata that accept (or reject) words of infinite length. Languages of infinite words appear:

Course Syllabus. Also listed as CS U1 Automata Theory (

1 Definition of a Turing machine

NP-Completeness and Cook s Theorem

The Model Checker SPIN

THE TURING DEGREES AND THEIR LACK OF LINEAR ORDER

1 Approximating Set Cover

Math Workshop October 2010 Fractions and Repeating Decimals

Chapter 7 Uncomputability

26 Integers: Multiplication, Division, and Order

Basic Concepts of Set Theory, Functions and Relations

Computer Science Theory. From the course description:

SOLUTIONS TO ASSIGNMENT 1 MATH 576

Exponents and Radicals

Discrete Mathematics and Probability Theory Fall 2009 Satish Rao, David Tse Note 2

CSE140: Midterm 1 Solution and Rubric

Cartesian Products and Relations

Software Model Checking: Theory and Practice

Transcription:

CSE 105 THEORY OF COMPUTATION Fall 2016 http://cseweb.ucsd.edu/classes/fa16/cse105-abc/

Today's learning goals Sipser Ch 2 Define push down automata Trace the computation of a push down automaton Design a push down automaton recognizing a given language Compare class of regular languages and class of CFLs

Context-free language Sipser p. 104 The language of a CFG (V, Σ, R, S) is { w in Σ * Starting with the Start variable and applying one or more rules, can get to w} Notation: Terminology: sequence of rule applications is derivation

Regular languages vs. CFL Context-free languages Regular languages

Designing CFGs Sipser p. 104 Given a language L over Σ, to prove L is a context-free language need to build a CFG that generates it. How? Express L as union of simpler languages If L is regular, design DFA and convert into CFG Exploit any recursive structure in L.

Example Design a CFG recognizing the language {a n b m n m} On Thursday, we showed that the language {a n b n n 0} is a CFL. How can we use its CFG for this example? A. Use the same CFG but reverse the role of variables and terminals. B. Use the same set of variables, terminals, and start state, but reverse the RHS and LHS of each rule. C. We can't use it directly: the two sets are not related. D. We can't use it directly: the class of CFLs is not closed under complementation. E. I don't know.

Example Design a CFG recognizing the language {a n b m n m} = {a n b m n > m} U {a n b m n < m} Simpler problem: Design a CFG generating the language {a n b m n > m}

Example Design a CFG recognizing the language {a n b m n m} = {a n b m n > m} U {a n b m n < m} Simpler problem: Design a CFG generating the language {a n b m n > m} G 1 = ( {S 1 }, {a,b}, R, S 1 ) with rules S 1 à as 1 b as 1 a

Example Design a CFG recognizing the language {a n b m n m} = {a n b m n > m} U {a n b m n < m} CFG generating the language {a n b m n > m} is G 1 = ( {S 1 }, {a,b}, R, S 1 ) with rules S 1 à as 1 b as 1 a CFG generating the language {a n b m n < m} is G 2 = ( {S 2 }, {a,b}, R, S 2 ) with rules S 2 à as 2 b S 2 b b

Example For {a n b m n > m}: G 1 = ( {S 1 }, {a,b}, R, S 1 ) with S 1 à as 1 b as 1 a For {a n b m n < m}: G 2 = ( {S 2 }, {a,b}, R, S 2 ) with S 2 à as 2 b S 2 b b What is CFG generating {a n b m n m}? A. G 1 U G 2 B. ( {S 1, S 2 }, {a,b}, R, S 1 ) with S 1 à as 1 b as 1 a, S 2 à as 2 b S 2 b b C. ( {S 1, S 2 }, {a,b}, R, S 2 ) with S 1 à as 1 b as 1 as 2, S 2 à as 2 b S 2 b b D. ( {S, S 1, S 2 }, {a,b}, R, S) with S à S 1 S 2, S 1 à as 1 b as 1 a, S 2 à as 2 b S 2 b b E. I don't know.

An alternative Sipser p. 109 NFA + stack

Pushdown automata Sipser p. 109 NFA + stack At each step 1. Transition to new state based on current state, letter read, and top letter of stack. 2. (Possibly) push or pop a letter to (or from) top of stack

Pushdown automata Sipser p. 109 NFA + stack Accept a string if there is some sequence of states and some sequence of stack contents which processes the entire input string and ends in an accepting state.

State diagram for PDA Sipser p. 109 If hand-drawn or in Sipser State transition labelled a, b à c means "when machine reads an a from the input and the top symbol of the stack is a b, it may replace the b with a c." In JFLAP: use ; instead of à

State diagram for PDA Sipser p. 109 If hand-drawn or in Sipser State transition labelled a, b à c means "when machine reads an a from the input and the top symbol of the stack is a b, it may replace the b with a c." What edge label would indicate "Read a 0, don't pop anything from stack, don t push anything to the stack"? A. 0, ε à ε B. ε, 0 à ε C. ε, ε à 0 D. ε à ε, 0 E. I don't know.

Useful trick What would ε, ε à $ mean? A. Without reading any input or popping any symbol from stack, push $ B. If the input string and stack are both empty strings, push $ C. At the end of reading the input string, push $ to top of stack D. I don't know.

Useful trick What would ε, ε à $ mean? A. Without reading any input or popping any symbol from stack, push $ B. If the input string and stack are both empty strings, push $ C. At the end of reading the input string, push $ to top of stack D. I don't know. Why is this useful? Commonly used from initial state (at start of computation) to record top of stack with a special symbol) we'll see applications soon!

Formal definition of PDA Sipser Def 2.13 p. 111

Designing a PDA L = { 0 i 1 i+1 i 0 } Informal description of PDA: Read symbols from the input. As each 0 is read, push it onto the stack. As soon as 1s are seen, pop a 0 off the stack for each 1 read. If the stack becomes empty and there is exactly one 1 left to read, read that 1 and accept the input. If the stack becomes empty and there are either zero or more than one 1s left to read, or if the 1s are finished while the stack still contains 0s, or if any 0s appear in the input following 1s, reject the input.

Designing/Tracing a PDA L = { 0 i 1 i+1 i 0 } What are the contents of the stack after processing 001? A. (TOP) $00 B. (TOP) 00$ C. (TOP) 0$ D. (TOP) 100$ E. I don't know.

Designing/Tracing a PDA L = { 0 i 1 i+1 i 0 } Which of the following strings are not accepted by this PDA? A. 0 B. 1 C. 01 D. 011 E. I don't know.

Designing/Tracing a PDA L = { 0 i 1 i+1 i 0 } Which of these CFGs generate L? Assume V = set of variables mentioned in rules; Σ={0,1}, S start A. S à ε 0S1 B. S à ε 0S11 C. S à T1 0S1, T à ε D. S à ε 0T1, T à ε 0T1 E. I don't know.

PDAs and CFGs are equivalently expressive Theorem 2.20: A language is context-free if and only some nondeterministic PDA recognizes it. Consequences - Quick proof that every regular language is context free - To prove closure of class of CFLs under a given operation, can choose two modes of proof (via CFGs or PDAs) depending on which is easier

Example L = { a i b j c k i=j or i=k, with i,j,k 0 } Which of the following strings are not in L? A. b B. abc C. abbcc D. aabcc E. I don't know.

Example L = { a i b j c k i=j or i=k, with i,j,k 0 } To design a CFG that generates L L = { a i b j c k i=j, with i,j,k 0 } U { a i b j c k i=k, with i,j,k 0 }

Example L = { a i b j c k i=j or i=k, with i,j,k 0 } To design a CFG that generates L L = { a i b j c k i=j, with i,j,k 0 } U { a i b j c k i=k, with i,j,k 0 } S à Sc T T à atb ε

Example L = { a i b j c k i=j or i=k, with i,j,k 0 } To design a CFG that generates L L = { a i b j c k i=j, with i,j,k 0 } U { a i b j c k i=k, with i,j,k 0 } S à T asc T à Tb ε

Designing a PDA L = { a i b j c k i=j or i=k, with i,j,k 0 } Informal description of PDA: How would you design an algorithm that, given a string, decides if it is in this set? - What information do you need to track? - How much memory do you need? - Are you using non-determinism?

Designing a PDA L = { a i b j c k i=j or i=k, with i,j,k 0 } Informal description of PDA: The PDA pushes a $ to indicate the top of the stack, then starts reading a's, pushing each one on to the stack. The PDA guesses when it's reached the end of the a's and whether to match the number of a's to the number of b's or the number of c's. If trying to match number of b's with number of a's: PDA pops off a's for each b read. If there are more a's on the stack but no more b's being read, reject. When the end of the stack ($) is reached, the number of a's matches the number of b's. If this is the end of the input or if any number of c's is read at this point, accept; otherwise, reject. If trying to match the number of c's with number of a's: first read any number of b's without changing stack contents and then nondeterministically guess when to start reading c's. For each c read, pop one a off the stack. When the end of the stack ($) is reached the number of a's and c's so far match.

Designing a PDA L = { a i b j c k i=j or i=k, with i,j,k 0 } Formal definition of PDA:

Conventions for PDAs Can "test for end of stack" without providing details We can always push the end-of-stack symbol, $, at the start. Can "test for end of input" without providing details Can transform PDA to one where accepting states are only those reachable when there are no more input symbols. Don't always need to provide a state transition diagram!

Overview??? Context-free languages Regular languages

Other classes of languages? Are all strings context-free? A. Yes, because every string is finite. B. Yes, because the set of all strings is regular. C. No, because the computation could get stuck. D. No, because the type is wrong. E. I don't know.

Other classes of languages? Are all sets of strings over fixed alphabet Σ context-free? A. Yes, because the class of CFL is a strict superset of RL. B. Yes, because the set of all strings is regular. C. No, because we can apply the Pumping Lemma. D. No, because the diagonalization argument applies again. E. I don't know.

Informal intuition Which specific language is not context-free? A. { 0 n 1 m 0 n m,n 0 } B. { 0 n 1 n 0 n n 0 } C. { 0 n 1 2n n 0 } D. { 0 n 1 2m m,n 0 } E. I don't know.

Examples of non-context-free languages { a n b n c n 0 n } Sipser Ex 2.36 {a i b j c k 0 i j k } Sipser Ex 2.37 { w w w is in {0,1} * } Sipser Ex 2.38 To prove Pumping lemma for CFLs

Closure properties of.. The class of regular languages is closed under Union Concatenation Star Complementation Intersection Difference Reversal The class of context-free languages is closed under Union Concatenation Star Reversal The class CFL is not closed under Intersection Complement Difference