Nathan Brunelle Department of Computer Science University of Virginia www.cs.virginia.edu/~njb2b/theory Theory of Computation CS3102 – Spring 2014 A tale.

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.
Chapter 5 Pushdown Automata
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
Pushdown Automata Chapter 12. Recognizing Context-Free Languages We need a device similar to an FSM except that it needs more power. The insight: Precisely.
Formal Languages: Review Alphabet: a finite set of symbols String: a finite sequence of symbols Language: a set of strings String length: number of symbols.
Nathan Brunelle Department of Computer Science University of Virginia Theory of Computation CS3102 – Spring 2014 A tale.
Nathan Brunelle Department of Computer Science University of Virginia Theory of Computation CS3102 – Spring 2014 A tale.
Pushdown Automata Part II: PDAs and CFG Chapter 12.
1 Introduction to Computability Theory Lecture12: Decidable Languages Prof. Amos Israeli.
Introduction to Computability Theory
1 Introduction to Computability Theory Lecture7: PushDown Automata (Part 1) Prof. Amos Israeli.
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.
Transparency No. P2C3-1 Formal Language and Automata Theory Chapter 3 Pushdown Automata and Context-Free Languages.
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture 4 Context-free grammars Jan Maluszynski, IDA, 2007
Deterministic FA/ PDA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 4 Updated by Marek Perkowski.
CS 490: Automata and Language Theory Daniel Firpo Spring 2003.
Normal forms for Context-Free Grammars
Today Chapter 2: (Pushdown automata) Non-CF languages CFL pumping lemma Closure properties of CFL.
1 Pushdown Automata PDAs. 2 Pushdown Automaton -- PDA Input String Stack States.
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.
Nathan Brunelle Department of Computer Science University of Virginia Theory of Computation CS3102 – Spring 2014 A tale.
Context-Free Grammars: Review Basic idea: set of production rules induces a language Finite set of variables: V = {V 1, V 2,..., V k } Finite set of terminals:
Final Exam Review Cummulative Chapters 0, 1, 2, 3, 4, 5 and 7.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
Nathan Brunelle Department of Computer Science University of Virginia Theory of Computation CS3102 – Spring 2014 A tale.
Theory of Computation CS3102 – Spring 2014 A tale of computers, math, problem solving, life, love and tragic death Nathan Brunelle Department of Computer.
CSCI 2670 Introduction to Theory of Computing September 21, 2005.
Chapter 7 PDA and CFLs.
Pushdown Automata CS 130: Theory of Computation HMU textbook, Chap 6.
Pushdown Automata (PDAs)
Design contex-free grammars that generate: L 1 = { u v : u ∈ {a,b}*, v ∈ {a, c}*, and |u| ≤ |v| ≤ 3 |u| }. L 2 = { a p b q c p a r b 2r : p, q, r ≥ 0 }
1 Let L= { w= u v : u  {a, b}*, v  {c, d}* and |u|= |v|} 1.Design a context-free grammar that generates L. 2.Use your grammar and the construction from.
Context-free Languages Chapter 2. Ambiguity.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 11 Midterm Exam 2 -Context-Free Languages Mälardalen University 2005.
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.
Context-Free and Noncontext-Free Languages Chapter 13 1.
Pushdown Accepters & Context-Free Grammars Sipser, Theorem 2.12 Denning, Chapter 8.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2010 with acknowledgement.
Context-Free and Noncontext-Free Languages Chapter 13.
CSCI 2670 Introduction to Theory of Computing October 13, 2005.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
Formal Languages Alphabet: a finite set of symbols String: a finite sequence of symbols Language: a (possibly  ) set of strings String length: number.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 2 Context-Free Languages Some slides are in courtesy.
Algorithms for hard problems Automata and tree automata Juris Viksna, 2015.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen Department of Computer Science University of Texas-Pan American.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
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.
Grammar Set of variables Set of terminal symbols Start variable Set of Production rules.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
Lecture 6: Context-Free Languages
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
1 Chapter Pushdown Automata. 2 Section 12.2 Pushdown Automata A pushdown automaton (PDA) is a finite automaton with a stack that has stack operations.
CS 154 Formal Languages and Computability March 15 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
Theory of Computation Automata Theory Dr. Ayman Srour.
Theory of Languages and Automata By: Mojtaba Khezrian.
CS6800 Advance Theory of Computation Spring 2016 Nasser Alsaedi
CSE 105 theory of computation
Deterministic FA/ PDA Sequential Machine Theory Prof. K. J. Hintz
CSE 105 theory of computation
PDAs Accept Context-Free Languages
Chapter 2 Context-Free Language - 01
CSE 105 theory of computation
CSE 105 theory of computation
CSE 105 theory of computation
CSE 105 theory of computation
CSE 105 theory of computation
Presentation transcript:

Nathan Brunelle Department of Computer Science University of Virginia Theory of Computation CS3102 – Spring 2014 A tale of computers, math, problem solving, life, love and tragic death

Midterm Take home!+ Date: After Spring break! Released: March 19 5pm Due: March 23 7pm Rules: Open book, open notes, open Wikipedia (no other web sites, no use of friends) You may download any time during the window, but turn in the exam within 24 hours of download You have 6 contiguous hours to work on the exam It will be near impossible to complete unless you’ve already done many problem set problems

Context-Free Grammars Basic idea: set of production rules induces a language Finite set of variables: V = {V 1, V 2,..., V k } Finite set of terminals: Σ = {t 1, t 2,..., t j } Finite set of productions: R Start symbol: S Productions: V i   where V i  V and  (V  Σ)* Applying V i   to  V i  yields:      Note: productions do not depend on “context” - hence the name “context free”!

Ambiguity Def: A grammar is ambiguous if some string in its language has two non-isomorphic derivations. Theorem: Some context-free grammars are ambiguous. Ex: G 1 :S  SS | a |  Derivation 1: S  SS  aa Derivation 2: S  SS  SSS  aa Def: A context-free language is inherently ambiguous if every context-free grammar for it is ambiguous. Theorem: Some context-free languages are inherently ambiguous (i.e., no non-ambiguous CFG exists). Ex: {a i b j c k | i=j or j=k} Prove this for EC! Fault of the grammar Fault of the language!

Example : design a context-free grammar that generates all valid regular expressions. Idea: embedd the RE rules in a grammar. G:S  a for each a  L S  (S) | SS | S* | S+S S  S*  (S)*  (S+S)*  (a+b)* S  SS  SSSS  abS*b  aba*a Q: Is G ambiguous?

Pushdown Automata Basic idea: a pushdown automaton is a finite automaton that can optionally write to an unbounded stack. Finite set of states: Q = {q 0, q 1, q 3,..., q k } Input alphabet:  Stack alphabet:  Transition function:  : Q  (  {  })   2 Q   Initial state:q 0  Q Final states:F  Q Pushdown automaton is M=(Q, , , , q 0, F) Note: pushdown automata are non-deterministic! (why?) q0q0 qiqi qjqj q1q1 qkqk

Pushdown Automata A pushdown automaton can use its stack as an unbounded but access-controlled (last-in/first-out or LIFO) storage. A PDA accesses its stack using “push” and “pop” Stack & input alphabets may differ. Input read head only goes 1-way. Acceptance can be by final state or by empty-stack. Note: a PDA can be made deterministic by restricting its transition function to unique next moves:  : Q  (  {  })   Q   M Input a b a stack

Pushdown Automata a‘s ε, ↓$ end b‘s a, ↓a start b, ↑a ε, ↑$ b, ↑a $ a a stack aaabbb Input a

Pushdown Automata a‘s ε, ↓$ end b‘s a, ↓a b, ↓b start ε ε, ↑$ $ a b stack abbbba Input b a, ↑ a b, ↑ b (note I only show the accepting path)

Closure Properties of CFLs Theorem: The context-free languages are closed under union. Hint: Derive a new grammar for the union. Let G 1 =(V 1, Σ,R 1, S 1 ), G 2 =(V 2, Σ,R 2, S 2 ) Then G 1+2 =(V 1 +V 2 +{S}, Σ, R 1 + R 2 +{S→ S 1 | S 2 }, S) S→ S 1 | S 2 S 1 →… S 2 →…

Closure Properties of CFLs Theorem: The CFLs are closed under Kleene closure. Hint: Derive a new grammar for the Kleene closure. Let G =(V, Σ,R, S) Then G * =(V, Σ,R+ {S → SS|ε}, S) S → SS|ε|…

Closure Properties of CFLs Theorem: The CFLs are closed under  with regular langs. Hint: Simulate PDA and FA in parallel. Let FSA M fsa =(Q f, ,  f, q f, F f ), PDA M pda =(Q p, , ,  p, q p, F p ) Then M ∩ =(Q f ×Q p, ,  (q f,q p ), F f ×F p )  Q f ×Q p  (  {  })   2 Q   s.t.  q f, q p,  f  q f,  p  q p,  M pda a b a stack M fsa ×

Closure Properties of CFLs Theorem: The CFLs are not closed under intersection. Hint: Find a counter example. L={a n b n c n } is not context free (Involves pumping lemma of CFLs, we’ll get to it) Let L 1 ={a i b j c j }, L 2 ={a i b i c j } L 1 ∩L 1 = L

Closure Properties of CFLs Theorem: The CFLs are not closed under complementation. Hint: Use De Morgan’s law. Assume FSORC that CFLs are closed under complementation. Since we know that they are closed under union we can find

Decidable PDA / CFG Problems Given an arbitrary pushdown automata M the following problems are decidable (i.e., have algorithms): Q 1 : Is L(M) = Ø ? Q 5 : Is L(G) = Ø ? Q 2 :Is L(M) finite ? Q 6 :Is L(G) finite ? Q 3 :Is L(M) infinite ? Q 7 :Is L(G) infinite ? Q 4 : Is w  L(M) ? Q 8 : Is w  L(G) ? ≡ (or CFG G) Extra-credit: prove each!

Theorem: the following are undecidable (i.e., there exist no algorithms to answer these questions): Q: Is PDA M minimal ? Q: Are PDAs M 1 and M 2 equivalent ? Q: Is CFG G minimal ? Q: Is CFG G ambiguous ? Q: Is L(G 1 ) = L(G 2 ) ? Q: Is L(G 1 )  L(G 2 ) = Ø ? Q: Is CFL L inherently ambiguous ? Undecidable PDA / CFG Problems ≡ Extra-credit: prove each!

PDA Enhancements Theorem: 2-way PDAs are more powerful than 1-way PDAs. Hint: Find an example non-CFL accepted by a 2-way PDA. Theorem: 2-stack PDAs are more powerful than 1-stack PDAs. Hint: Find an example non-CFL accepted by a 2-stack PDA. Theorem: 1-queue PDAs are more powerful than 1-stack PDAs. Hint: Find an example non-CFL accepted by a 1-queue PDA. Theorem: 2-head PDAs are more powerful than 1-head PDAs. Hint: Find an example non-CFL accepted by a 2-head PDA. Theorem: Non-determinism increases the power of PDAs. Hint: Find a CFL not accepted by any deterministic PDA. Extra-credit: prove each!