January 20, 2016CS21 Lecture 71 CS21 Decidability and Tractability Lecture 7 January 20, 2016.

Slides:



Advertisements
Similar presentations
Context-Free and Noncontext-Free Languages
Advertisements

Theory of Computation CS3102 – Spring 2014 A tale of computers, math, problem solving, life, love and tragic death Nathan Brunelle Department of Computer.
Nathan Brunelle Department of Computer Science University of Virginia Theory of Computation CS3102 – Spring 2014 A tale.
CS 3240: Languages and Computation Properties of Context-Free Languages.
CS21 Decidability and Tractability
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
Turing machines Sipser 2.3 and 3.1 (pages )
Turing machines Sipser 2.3 and 3.1 (pages )
Lecture 15UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 15.
CS5371 Theory of Computation
CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x.
1 Module 33 Non-context free languages –Intuition and Examples CFL Pumping Lemma –Comparison to regular language pumping lemma –What it means –Proof overview.
Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
Chap 2 Context-Free Languages. Context-free Grammars is not regular Context-free grammar : eg. G 1 : A  0A1substitution rules A  Bproduction rules B.
Courtesy Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
Transparency No. P2C5-1 Formal Language and Automata Theory Part II Chapter 5 The Pumping Lemma and Closure properties for Context-free Languages.
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture 4 Context-free grammars Jan Maluszynski, IDA, 2007
Fall 2004COMP 3351 NPDA’s Accept Context-Free Languages.
January 14, 2015CS21 Lecture 51 CS21 Decidability and Tractability Lecture 5 January 14, 2015.
CS5371 Theory of Computation Lecture 9: Automata Theory VII (Pumping Lemma, Non-CFL)
Transparency No. P2C5-1 Formal Language and Automata Theory Part II Chapter 5 The Pumping Lemma and Closure properties for Context-free Languages.
January 23, 2015CS21 Lecture 81 CS21 Decidability and Tractability Lecture 8 January 23, 2015.
CS 3240 – Chapter 8.  Is a n b n c n context-free? CS Properties of Context-Free Languages2.
January 15, 2014CS21 Lecture 61 CS21 Decidability and Tractability Lecture 6 January 16, 2015.
1 Background Information for the Pumping Lemma for Context-Free Languages Definition: Let G = (V, T, P, S) be a CFL. If every production in P is of the.
Homework #7 Solutions. #1. Use the pumping lemma for CFL’s to show L = {a i b j a i b j | i, j > 0} is not a CFL. Proof by contradiction using the Pumping.
Today Chapter 2: (Pushdown automata) Non-CF languages CFL pumping lemma Closure properties of CFL.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
1 Computer Language Theory Chapter 2: Context-Free Languages.
CSE 3813 Introduction to Formal Languages and Automata Chapter 8 Properties of Context-free Languages These class notes are based on material from our.
The Pumping Lemma for Context Free Grammars. Chomsky Normal Form Chomsky Normal Form (CNF) is a simple and useful form of a CFG Every rule of a CNF grammar.
Context-free Languages
Context-free Languages Chapter 2. Ambiguity.
CSCI 2670 Introduction to Theory of Computing September 22, 2005.
Context-Free and Noncontext-Free Languages Chapter 13 1.
1 L= { w c w R : w  {a, b}* } is accepted by the PDA below. Use a construction like the one for intersection for regular languages to design a PDA that.
Pushdown Automata Chapters Generators vs. Recognizers For Regular Languages: –regular expressions are generators –FAs are recognizers For Context-free.
Cs3102: Theory of Computation Class 8: Non-Context-Free Languages Spring 2010 University of Virginia David Evans.
Closure Properties Lemma: Let A 1 and A 2 be two CF languages, then the union A 1  A 2 is context free as well. Proof: Assume that the two grammars are.
Non-CF Languages The language L = { a n b n c n | n  0 } does not appear to be context-free. Informal: A PDA can compare #a’s with #b’s. But by the time.
Context-Free and Noncontext-Free Languages Chapter 13.
Pumping Lemma for CFLs. Theorem 7.17: Let G be a CFG in CNF and w a string in L(G). Suppose we have a parse tree for w. If the length of the longest path.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University 2006.
Critique this PDA for L= { u u R v v R : u ∈ {0,1}* and v ∈ {0,1}+ } u0εu0 u1εu1 uεεvε v00vε v11vε vεεfε sεεtε t0εt0 t1εt1 t00tε t11tε tεεuε After you.
CSCI 2670 Introduction to Theory of Computing September 23, 2004.
Chapter 8 Properties of Context-free Languages These class notes are based on material from our textbook, An Introduction to Formal Languages and Automata,
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 2 Context-Free Languages Some slides are in courtesy.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
 2004 SDU Lecture8 NON-Context-free languages.  2004 SDU 2 Are all languages context free? Ans: No. # of PDAs on  < # of languages on  Pumping lemma:
Bottom-up parsing Pumping Theorem for CFLs MA/CSSE 474 Theory of Computation.
CS 154 Formal Languages and Computability March 15 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
Complexity and Computability Theory I Lecture #12 Instructor: Rina Zviel-Girshin Lea Epstein.
Lecture 11  2004 SDU Lecture7 Pushdown Automaton.
Context-Free and Noncontext-Free Languages Chapter 13.
Theory of Computation Pushdown Automata pda Lecture #10.
PDAs Accept Context-Free Languages
Lecture 17 Oct 25, 2011 Section 2.1 (push-down automata)
NPDAs Accept Context-Free Languages
Context-Free Grammars
COSC 3340: Introduction to Theory of Computation
CS21 Decidability and Tractability
CS21 Decidability and Tractability
CS21 Decidability and Tractability
COSC 3340: Introduction to Theory of Computation
CS21 Decidability and Tractability
Decidability and Tractability
CS21 Decidability and Tractability
Pumping Theorem for CFLs
Presentation transcript:

January 20, 2016CS21 Lecture 71 CS21 Decidability and Tractability Lecture 7 January 20, 2016

CS21 Lecture 72 Outline non context-free languages deterministic PDAs deciding CFLs

January 20, 2016CS21 Lecture 73 Pumping Lemma for CFLs CFL Pumping Lemma: Let L be a CFL. There exists an integer p (“pumping length”) for which every w  L with |w|  p can be written as w = uvxyz such that 1.for every i  0, uv i xy i z  L, and 2.|vy| > 0, and 3.|vxy|  p.

January 20, 2016CS21 Lecture 74 CFL Pumping Lemma Example Theorem: the following language is not context-free: L = {a n b n c n : n ≥ 0}. Proof: –let p be the pumping length for L –choose w = a p b p c p w = aaaa…abbbb…bcccc…c –w = uvxyz, with |vy| > 0 and |vxy|  p.

January 20, 2016CS21 Lecture 75 CFL Pumping Lemma Example –possibilities: w = aaaa…aaabbb…bbcccc…c (if v, y each contain only one type of symbol, then pumping on them produces a string not in the language) uv x yz

January 20, 2016CS21 Lecture 76 CFL Pumping Lemma Example –possibilities: w = aaaa…abbbb…bccccc…c (if v or y contain more than one type of symbol, then pumping on them might produce a string with equal numbers of a’s, b’s, and c’s – if vy contains equal numbers of a’s, b’s, and c’s. But they will be out of order.) uv x yz

January 20, 2016CS21 Lecture 77 CFL Pumping Lemma Example Theorem: the following language is not context-free: L = {xx : x  {0,1} * }. Proof: –let p be the pumping length for L –try w = 0 p 10 p 1 –can this be pumped?

January 20, 2016CS21 Lecture 78 CFL Pumping Lemma Example L = {xx : x  {0,1} * }. –try w = 0 2p 1 2p 0 2p 1 2p –w = uvxyz, with |vy| > 0 and |vxy|  p. –case: vxy in first half. then uv 2 xy 2 z = 0??...?1??...? –case: vxy in second half. then uv 2 xy 2 z = ??...?0??...?1 –case: vxy straddles midpoint then uv 0 xy 0 z = uxz = 0 2p 1 i 0 j 1 2p with i ≠ 2p or j ≠ 2p

January 20, 2016CS21 Lecture 79 CFL Pumping Lemma Proof: consider a parse tree for a very long string w  L: S ABC... ADS CSAAB AC SS ADDC BA BA a b aa b bb ab ba bbb long path some non-terminal must repeat on long path

January 20, 2016CS21 Lecture 710 CFL Pumping Lemma Schematic proof: uvxyz S A Auvyz S A A uvyz S A A vxy A

January 20, 2016CS21 Lecture 711 CFL Pumping Lemma Schematic proof: uvxyz S A Auz S A uz S A x

January 20, 2016CS21 Lecture 712 CFL Pumping Lemma –how large should pumping length p be? –need to ensure other conditions: |vy| > 0 |vxy| ≤ p –b = max # symbols on rhs of any production (assume b ≥ 2) –if parse tree has height ≤ h, then string generated has length ≤ b h (so length > b h implies height > h)

January 20, 2016CS21 Lecture 713 CFL Pumping Lemma –let m be the # of nonterminals in the grammar –to ensure path of length at least m+2, require |w| ≥ p = b m+2 –since |w| > b m+1, any parse tree for w has height > m+1 –let T be the smallest parse tree for w –longest root-leaf path must consist of ≥ m+1 non-terminals and 1 terminal.

January 20, 2016CS21 Lecture 714 CFL Pumping Lemma –must be a repeated non- terminal A on long path –select a repetition among the lowest m+1 non-terminals on path. –pictures show that for every i  0, uv i xy i z  L uvxyz S A A –is |vy| > 0 ? smallest parse tree T ensures –is |vxy| ≤ p? red path has length ≤ m+2, so ≤ b m+2 = p leaves

January 20, 2016CS21 Lecture 715 Deterministic PDA A NPDA is a 6-tuple (Q, Σ, , δ, q 0, F) where: –δ:Q x (Σ  {ε}) x (   {ε}) →  (Q x (   {ε})) is a function called the transition function A deterministic PDA has only one option at every step: –for every state q  Q, a  Σ, and t  , exactly 1 element in δ(q, a, t), or –exactly 1 element in δ(q, ε, t), and δ(q, a, t) empty for all a  Σ

January 20, 2016CS21 Lecture 716 Deterministic PDA A technical detail: we will give our deterministic machine the ability to detect end of input string –add special symbol ■ to alphabet –require input tape to contain x■ language recognized by a deterministic PDA is called a deterministic CFL (DCFL)

January 20, 2016CS21 Lecture 717 Example deterministic PDA L = {0 n 1 n : n  0} (unpictured transitions go to a “reject” state and stay there) ε, ε → $ ■, $ → ε 1, 0 → ε 0, ε → 0 1, 0 → ε Σ = {0, 1}  = {0, 1, $}

January 20, 2016CS21 Lecture 718 Deterministic PDA Theorem: DCFLs are closed under complement (complement of L in Σ* is (Σ* - L) ) Proof attempt: –swap accept/non-accept states –problem: might enter infinite loop before reading entire string –machine for complement must accept in these cases, and read to end of string

January 20, 2016CS21 Lecture 719 Example of problem 0, ε → ε 1, ε → ε ε, ε → $ Language of this DPDA is 0  * ■, ε → ε ε, ε → $

January 20, 2016CS21 Lecture 720 Example of problem 0, ε → ε 1, ε → ε ε, ε → $ Language of this DPDA is {  } ■, ε → ε ε, ε → $

January 20, 2016CS21 Lecture 721 Deterministic PDA Proof: –convert machine into “normal form” always reads to end of input always enters either an accept state or single distinguished “reject” state –step 1: keep track of when we have read to end of input –step 2: eliminate infinite loops

January 20, 2016CS21 Lecture 722 Deterministic PDA step 1: keep track of when we have read to end of input ■, ? → ? q0q0 q1q1 q3q3 q2q2 q0’q0’ q1’q1’ q3’q3’ q2’q2’

January 20, 2016CS21 Lecture 723 Deterministic PDA step 1: keep track of when we have read to end of input ■, ? → ? q0q0 q1q1 q3q3 q2q2 q0’q0’ q1’q1’ q3’q3’ q2’q2’ for accept state q’: replace outgoing “ε, ? → ?” transition with self-loop with same label

January 20, 2016CS21 Lecture 724 Deterministic PDA step 2: eliminate infinite loops –add new “reject” states r’ r a, t →t (for all a, t) ε, t → t (for all t) ■, t → t (for all t)

January 20, 2016CS21 Lecture 725 Deterministic PDA step 2: eliminate infinite loops –on input x, if infinite loop, then: stack height time i0i0 i1i1 i2i2 i3i3 infinite sequence i 0 < i 1 < i 2 < … such that for all k, stack height never decreases below ht(i k ) after time i k