Intro to Theory of Computation

Slides:



Advertisements
Similar presentations
Theory of Computation CS3102 – Spring 2014 A tale of computers, math, problem solving, life, love and tragic death Nathan Brunelle Department of Computer.
Advertisements

CSCI 3130: Formal languages and automata theory Tutorial 5
8/27/2009 Sofya Raskhodnikova Intro to Theory of Computation L ECTURE 2 Theory of Computation Finite Automata Operations on languages Nondeterminism L2.1.
Pushdown Automata CPSC 388 Ellen Walker Hiram College.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
CSCI 2670 Introduction to Theory of Computing September 13, 2005.
CS21 Decidability and Tractability
Introduction to Computability Theory
1 Introduction to Computability Theory Lecture7: PushDown Automata (Part 1) Prof. Amos Israeli.
CFG => PDA Sipser 2 (pages ). CS 311 Fall Formally… A pushdown automaton is a sextuple M = (Q, Σ, Γ, δ, q 0, F), where – Q is a finite set.
1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY (For next time: Read Chapter 1.3 of the book)
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.
CS 310 – Fall 2006 Pacific University CS310 Pumping Lemma Sections:1.4 page 77 September 27, 2006.
CS 310 – Fall 2006 Pacific University CS310 Pushdown Automata Sections: 2.2 page 109 October 9, 2006.
CS5371 Theory of Computation Lecture 5: Automata Theory III (Non-regular Language, Pumping Lemma, Regular Expression)
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2009 with acknowledgement.
CS5371 Theory of Computation Lecture 6: Automata Theory IV (Regular Expression = NFA = DFA)
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
Today Chapter 1: RE = Regular Languages, nonregular languages RL pumping lemma Chapter 2: Context-Free Languages (CFLs)
Today Chapter 2: (Pushdown automata) Non-CF languages CFL pumping lemma Closure properties of CFL.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
CSCI 2670 Introduction to Theory of Computing September 21, 2005.
Pushdown Automata (PDAs)
Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.
CS 203: Introduction to Formal Languages and Automata
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2010 with acknowledgement.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
CSCI 3130: Formal languages and automata theory Tutorial 3 Chin.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
Regular Languages Chapter 1 Giorgi Japaridze Theory of Computability.
CSCI 2670 Introduction to Theory of Computing September 22, 2004.
Recap: Nondeterministic Finite Automaton (NFA) A deterministic finite automaton (NFA) is a 5-tuple (Q, , ,s,F) where: Q is a finite set of elements called.
CSE 105 theory of computation
Foundations of Computing Science
CSE 105 theory of computation
CSE 105 theory of computation
PROPERTIES OF REGULAR LANGUAGES
Pushdown Automata PDAs
Lecture 17 Oct 25, 2011 Section 2.1 (push-down automata)
Pushdown Automata.
Intro to Theory of Computation
Intro to Theory of Computation
Intro to Theory of Computation
Lecture5 Non-regular languages
Intro to Theory of Computation
Regular Expression We shall build expressions from the symbols using simple operations include concatenation, union and kleen closure. Several intuitive.
Context-Free Grammars
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
Pumping Lemma September 29, 2006
CS21 Decidability and Tractability
Definition Moves of the PDA Languages of the PDA Deterministic PDA’s
Chapter 1 Regular Language - 02
Intro to Theory of Computation
CSE 105 theory of computation
Pushdown automata The Chinese University of Hong Kong Fall 2011
CSE 105 theory of computation
CHAPTER 1 Regular Languages
CSCI 2670 Introduction to Theory of Computing
Intro to Theory of Computation
Intro to Theory of Computation
Intro to Theory of Computation
Intro to Theory of Computation
Intro to Theory of Computation
CSE 105 theory of computation
Presentation transcript:

Intro to Theory of Computation LECTURE 6 Last time: NFAs to regular expressions Pumping lemma Today: Proving a language is not regular Pushdown automata (PDAs) CS 464 Homework 2 due Homework 3 out Sofya Raskhodnikova 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

Sofya Raskhodnikova; based on slides by Nick Hopper THE PUMPING LEMMA Let L be a regular language with |L| =  Then there exists a length p such that if w  L and |w| ≥ p then w can be split into three parts w=xyz where: 1. |y| > 0 2. |xy| ≤ p 3. xyiz  L for all i ≥ 0 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

Sofya Raskhodnikova; based on slides by Nick Hopper GENERAL STRATEGY Proof by contradiction: assume L is regular. Then there is a pumping length p. Find a string w ∈ L with |w| ≥ p. Show that no matter how you choose xyz, w cannot be pumped! Conclude that L is not regular. 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

Pumping lemma as a game YOU pick the language 𝑳 to be proved nonregular. ADVERSARY picks 𝒑, but doesn't reveal to YOU what 𝒑 is; YOU must devise a play for all possible 𝒑's. YOU pick 𝒘∈ L, which should depend on 𝒑 and which must be of length at least 𝒑. ADVERSARY divides 𝒘 into 𝒙, 𝒚, 𝒛, obeying PL conditions: 𝒚 is not empty and falls within the first 𝒑 characters of 𝒘. Again, ADVERSARY does not tell YOU what 𝒙, 𝒚, 𝒛 are. YOU win by picking 𝒊, which may be a function of 𝒑, 𝒙, 𝒚, 𝐳, such that 𝒙 𝒚 𝒊 𝒛 is not in L. 11/10/2018

I-clicker problem (frequency: AC) Prove C = { 0i1j | 𝑖 > 𝑗≥ 0} is not regular. What string can you choose in your next move? 00011 0 𝑝 1 𝑝 0 𝑝/2 1 𝑝/2−1 0 𝑝+1 1 𝑝 More than one choice above works. Proof: Assume … pumping length p {madam, dad, but, tub, book}

Sofya Raskhodnikova; based on slides by Nick Hopper USING THE PUMPING LEMMA: PUMPING DOWN Prove C = { 0i1j | 𝑖 > 𝑗≥ 0} is not regular. Proof: Assume … pumping length p Find a w ∈ C of length at least p 0P+11P Show that w cannot be pumped: p+1 p w= 00…0011…11 𝑦 must be in this part xyyz = 00…00011…11 xz = 0…0011…11 > p+1 ≤ p P P 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

Sofya Raskhodnikova; based on slides by Nick Hopper USING THE PUMPING LEMMA: PUMPING DOWN Prove C = { 0i1j | 𝑖 > 𝑗≥ 0} is not regular. Proof: Assume … pumping length p Find a w ∈ C of length at least p 0P+11P If w = 𝑥𝑦𝑧 with |𝑥𝑦| ≥ p then 𝑦 = 0J for some J≥1. Then xy0z = xz = 0P+1-J1P  C Contradiction! xz = 0…0011…11 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

there exist xyz=w, where WHAT THE PUMPING LEMMA DOESN’T SAY - I For every p, w  L with |w| ≥ p there exist xyz=w, where 1. |y| > 0 2. |xy| ≤ p 3. xyiz  L for all i ≥ 0 Let L = 1*. L is regular. The string 10 cannot be pumped with p=1. You need to show that no matter what p is chosen, L has a string w, |w| ≥ p, that cannot be pumped. 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

WHAT THE PUMPING LEMMA DOESN’T SAY - II For every xyz=w, where: 2. |xy| ≤ p 3. xyiz  L for all i ≥ 0 Example: Let L = 10*1*. Picking w = 10P1P; x=ε; y=10; z=0P-11P does not contradict pumping lemma! (You can pick x=1, y=0, z=0P-11P.) 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

CHOOSING WISELY Let BALANCED = { w | w has an equal # of 1s and 0s } Assume … there is a p Find a w ∈ BALANCED of length at least p (01)P 0P1P Show that w cannot be pumped: If w = xyz with |xy| ≤ p then y = 0J for some J>0. Then xyyz = 0P+J1P  BALANCED 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

REUSING A PROOF Pumping a language can be lots of work… Let’s try to reuse that work! {0n1n | n ≥ 0} = BALANCED ∩ 0*1* If BALANCED is regular then so is {0n1n| n ≥ 0} 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

USING CLOSURE Prove: A is not regular ∩ A C = B (Not regular) any of {∘, ∪, ∩} or, for one language, {¬, R, *} If A is regular, then A ∩ C (= B) is regular. But B is not regular so neither is A. 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

USING CLOSURE: example Prove A = {0i1j | i ≠ j} is not regular using B = {0n1n | n≥0} ¬ A = B ∪ { strings that mix 0s and 1s } ¬A ∩ 0*1* = B 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

NON-REGULAR LANGUAGES PUMPING NON-REGULAR LANGUAGES Let F = {aibjck | i, j, k ≥ 0 and i=1 ⇒ j=k} F has pumping length 2! i = 0 i = 1 i = 2 i > 2 HW3: prove that F is not regular. A non-regular language may still satisfy the pumping lemma. 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

Sofya Raskhodnikova; based on slides by Nick Hopper 464 so far MODEL OF A PROBLEM: LANGUAGE MODEL OF A PROGRAM: DFA EQUIVALENT MODELS: NFA, REGEXP PROBLEMS THAT A DFA CAN’T SOLVE ARE WE DONE? 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

Sofya Raskhodnikova; based on slides by Nick Hopper NONE OF THESE ARE REGULAR Σ = {0, 1}, L = { 0n1n | n ≥ 0 } Σ = {a, b, c, …, z}, L = { w | w = wR } Σ = { (, ) }, L = { balanced strings of parens } We can write a C or JAVA program for any of them! 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

Sofya Raskhodnikova; based on slides by Nick Hopper PUSHDOWN AUTOMATA (PDA) FINITE STATE CONTROL INPUT STACK (Last in, first out) 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

string pop push 0011 0011 011 11 1 STACK $ $ $ ε,ε → $ 0,ε → 0 0011 0011 011 11 1,0 → ε ε,$ → ε 1 1,0 → ε STACK $ $ $

PDA to recognize L = { 0n1n | n ≥ 0 } string pop push ε,ε → $ 0,ε → 0 001 001 01 1 1,0 → ε ε,$ → ε 1,0 → ε STACK $ $ $ PDA to recognize L = { 0n1n | n ≥ 0 }

P(Q  Γε) is the set of subsets of Q  Γε and Σε = Σ  {ε} Formal Definition A PDA is a 6-tuple P = (Q, Σ, Γ, , q0, F) Q is a finite set of states Σ is the alphabet Γ is the stack alphabet  : Q  Σε  Γε → P(Q  Γε) is the transition function q0  Q is the start state F  Q is the set of accept states P(Q  Γε) is the set of subsets of Q  Γε and Σε = Σ  {ε} Note: A PDA is defined to be nondeterministic. 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

Formal Definition A PDA is a 6-tuple P = (Q, Σ, Γ, , q0, F) Q is a finite set of states Σ is the alphabet Γ is the stack alphabet  : Q  Σε  Γε → P(Q  Γε) is the transition function q0  Q is the start state F  Q is the set of accept states A PDA starts with an empty stack. It accepts a string if at least one of its computational branches reads all the input and gets into an accept state at the end of it. 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

An example PDA q0 q1 q3 q2 Q = {q0, q1, q2, q3} Σ = {0,1} Γ = {$,0} ε,ε → $ q0 q1 0,ε → 0 1,0 → ε ε,$ → ε q3 q2 1,0 → ε Q = {q0, q1, q2, q3} Σ = {0,1} Γ = {$,0}  : Q  Σε  Γε → P(Q  Γε) (q1,1,0) = { (q2,ε) } (q2,1,1) = 

PDA: algorithmic description ε,ε → $ q0 q1 0,ε → 0 Place the marker symbol $ onto the stack. Nondeterministically keep reading a 0 and pushing it onto the stack or read a 1, pop a 0 and go to the next step. Nondeterministically keep reading a 1 and popping a 0 or go to the next step. If the top of the stack is $, enter the accept state. (Then PDA accepts if the input has been read). 1,0 → ε ε,$ → ε q3 q2 1,0 → ε

I-clicker problem (frequency: AC) What strings are accepted by this PDA? Only 𝜺 Palindromes Even-length palindromes All strings that start and end with the same letter None of the above Σ = {a, b, c, …, z} ε,ε → $ ,ε →  q0 q1 ε,ε → ε ε,$ → ε q3 q2 , → ε {madam, dad, but, tub, book}

Give an ALGORITHMIC description Σ = {a, b, c, …, z} q0 q1 ε,ε → $ ,ε →  q0 q1 Place the marker symbol $ onto the stack. Nondeterministically keep reading a character and pushing it onto the stack or go to the next step. Nondeterministically keep reading and popping a matching character or go to the next step. If the top of the stack is $, enter the accept state. ε,ε → ε ε,$ → ε q3 q2 , → ε

Build a PDA to recognize L = { aibjck | i, j, k ≥ 0 and (i = j or i = k) } c,ε → ε b,a → ε q0 ε,$ → ε q3 q2 ε,ε → $ ε,ε → ε q6 q1 q4 q5 ε,ε → ε ε,ε → ε ε,$ → ε a,ε → a b,ε → ε c,a → ε