bu cs 332 theory of computation
play

BU CS 332 Theory of Computation Lecture 7: Reading: More on CFGs - PowerPoint PPT Presentation

BU CS 332 Theory of Computation Lecture 7: Reading: More on CFGs Sipser Ch 2.1 2.3 Pushdown Automata Mark Bun February 12, 2020 Context Free Grammar (Formal) A CFG is a 4 tuple is a finite set of variables is a


  1. BU CS 332 – Theory of Computation Lecture 7: Reading: • More on CFGs Sipser Ch 2.1 ‐ 2.3 • Pushdown Automata Mark Bun February 12, 2020

  2. Context ‐ Free Grammar (Formal) A CFG is a 4 ‐ tuple • is a finite set of variables • is a finite set of terminal symbols (disjoint from ) • is a finite set of production rules of the form , ∗ where and • is the start symbol 2/12/2020 CS332 ‐ Theory of Computation 2

  3. Context ‐ Free Grammar Example Grammar Parse Tree | | | Derivation 2/12/2020 CS332 ‐ Theory of Computation 3

  4. Context ‐ Free Languages Questions about CFLs 1. Which languages are not context ‐ free? 𝑀 is a context ‐ free 2. How do we recognize language if it is the whether 𝑥 ∈ 𝑀 ? language of some CFG 3. What are the closure properties of CFLs? 2/12/2020 CS332 ‐ Theory of Computation 4

  5. Pumping Lemma for context ‐ free languages Let be a context ‐ free language. Then there exists a “pumping length” such that For every where , can be split into five parts where: 1. 2. 𝑗  𝑗 3. for all 2/12/2020 CS332 ‐ Theory of Computation 5

  6. Pumping Lemma example � � � Claim: is not context ‐ free Proof: Assume is context ‐ free with pumping length 1. Find with 2. Show that cannot be pumped If = with | | , then… Case 1: both contain only one kind of symbol Case 2: Either or contains two kinds of symbols 2/12/2020 CS332 ‐ Theory of Computation 6

  7. Pumping Lemma example � � � Claim: is not context ‐ free Proof: Assume is context ‐ free with pumping length 1. Find with 2. Show that cannot be pumped If = with | | , then… Case 1: both contain only one kind of symbol 2/12/2020 CS332 ‐ Theory of Computation 7

  8. 2/12/2020 CS332 ‐ Theory of Computation 8

  9. Pumping Lemma example � � � Claim: is not context ‐ free Proof: Assume is context ‐ free with pumping length 1. Find with 2. Show that cannot be pumped If = with | | , then… Case 2: Either or contains two kinds of symbols 2/12/2020 CS332 ‐ Theory of Computation 9

  10. Pumping Lemma: Proof idea Let be a context ‐ free language. If is long enough, then every parse tree for has a repeated variable. 2/12/2020 CS332 ‐ Theory of Computation 10

  11. Pumping Lemma Proof What does “long enough” mean? (How do we choose the pumping length ?) • Let be a CFG for • Suppose the right ‐ hand side of every rule in uses at most symbols � �� • Let Claim: If with , then the smallest parse tree for has height at least 2/12/2020 CS332 ‐ Theory of Computation 11

  12. Pumping Lemma Proof Claim: If with , then the smallest parse tree for has height at least • By the pigeonhole principle, there is a path down the parse tree with a repeated variable 𝑆 • Choose two such occurrences within the bottom 𝑊 � 1 levels 2/12/2020 CS332 ‐ Theory of Computation 12

  13. Context ‐ Free Languages Questions about CFLs 1. Which languages are not context ‐ free? 𝑀 is a context ‐ free 2. How do we recognize language if it is the whether 𝑥 ∈ 𝑀 ? language of some CFG 3. What are the closure properties of CFLs? 2/12/2020 CS332 ‐ Theory of Computation 13

  14. Pushdown Automata 2/12/2020 CS332 ‐ Theory of Computation 14

  15. Regular Expressions : Finite Automata :: Context ‐ Free Languages : ??? 2/12/2020 CS332 ‐ Theory of Computation 15

  16. Pushdown Automata 𝑏 𝑐 𝑏 𝑏 Finite Automata (FAs): Input … Machine with a finite amount of unstructured memory Finite control 𝑏 𝑐 𝑏 𝑏 Input Pushdown Automata (PDAs): … Machine with unbounded structured memory in the form of a stack Finite 𝑦 control 𝑦 Memory: Infinite Stack 𝑧 2/12/2020 CS332 ‐ Theory of Computation 16

  17. Pushdown Automaton (the idea) • Nondeterministic finite automaton + stack • Stack has unlimited size, but machine can only manipulate (push, pop, read) symbol at the top 𝑏 𝑐 𝑏 𝑏 Input … Finite 𝑦 control 𝑦 Memory: Infinite Stack 𝑧 Transitions of the form: 𝑏 , 𝑦 → 𝑦′ 2/12/2020 CS332 ‐ Theory of Computation 17

  18. Example: Even Palindromes � ∗ 𝑏 𝑐 𝑐 𝑐 𝑐 𝑏 Input … Finite control Memory: Infinite Stack 2/12/2020 CS332 ‐ Theory of Computation 18

  19. Example: Even Palindromes � ∗ 𝑏 𝑐 𝑐 𝑐 𝑐 𝑏 Input … Finite control Algorithmic Description 1. Place the marker $ on the stack Memory: Infinite Stack 2. Nondeterministically, either a) Read a character and push it to the stack, or b) Go to the next step 3. Nondeterministically, either a) Pop the stack if it matches the next character or b) Go to the next step 4. Accept if the top of the stack is $ 2/12/2020 CS332 ‐ Theory of Computation 19

  20. Example: Even Palindromes 𝑏 , 𝜁 → 𝑏 𝜁 , 𝜁 → $ 𝑐 , 𝜁 → 𝑐 0 𝜁 , 𝜁 → 𝜁 𝜁 , $ → 𝜁 𝑏 , 𝑏 → 𝜁 𝑐 , 𝑐 → 𝜁 𝑔 2/12/2020 CS332 ‐ Theory of Computation 20

  21. Pushdown Automaton (formal) A PDA is a 6 ‐ tuple (sorry) � • is a finite set of states • is the input alphabet • is the stack alphabet • : � is the transition function � � • � is the start state • is the set of final states accepts a string if, starting from 0 and an empty stack, there exists a path to an accept state that can be followed by reading all of . 2/12/2020 CS332 ‐ Theory of Computation 21

  22. Example: Even Palindromes 𝑏 , 𝜁 → 𝑏 𝜁 , 𝜁 → $ 𝑐 , 𝜁 → 𝑐 0 𝜁 , 𝜁 → 𝜁 𝜁 , $ → 𝜁 𝑏 , 𝑏 → 𝜁 𝑔 𝑐 , 𝑐 → 𝜁 𝜀 : 𝑅 � Σ � � Γ � → 𝑄 𝑅 � Γ � 𝜀 𝑞 , 𝑐 , 𝜁 � 𝜀 𝑟 , 𝑏 , 𝑏 � 𝜀 𝑟 , 𝑏 , 𝑐 � 2/12/2020 CS332 ‐ Theory of Computation 22

Recommend


More recommend