cse 105
play

CSE 105 THEORY OF COMPUTATION Fall 2016 - PowerPoint PPT Presentation

CSE 105 THEORY OF COMPUTATION Fall 2016 http://cseweb.ucsd.edu/classes/fa16/cse105-abc/ T oday's learning goals Sipser Ch 1.4, 2.1 CFG Design PDA Design Equivalence between CFG and PDA Non-context-free languages CFG Design


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

  2. T oday's learning goals Sipser Ch 1.4, 2.1 • CFG Design • PDA Design • Equivalence between CFG and PDA • Non-context-free languages

  3. CFG Design ● Design a CFG for the language L = {a n b m | m > n ≥ 0 } – ● G=({S,T},{a,b},R,S) where R is the set of rules S → T | ??? – What rule is missing? T → bT | b – A) S → aS B) S → abS C) S → aSb D) S → aabbb E) I don’t know

  4. CFG Design ● Design a CFG for the language L = {a 2n ba n | n ≥ 0 } – ● G=({S,T},{a,b},R,S) where R is the set of rules S → T | ??? – What rule is missing? T → b – A) S → aaSa B) S → aSba C) S → aSb D) S → aSa E) I don’t know

  5. CFG Design ● Design a CFG for the language L = {a i b j a k | i=j or j=k } – ● G=({S,T,U,V},{a,b},R,S) where R is the set of rules S → UT | TV – What rule is missing? A) T → aT a | b U → aUb | ε – B) T → aT | a C) T → aT | ε V → bVa | ε – D) T → aT | bT | ε T → ??? – E) I don’t know

  6. CFG Design ● Design a CFG for the language L = {a i b j a k | i=j or j=k } – ● G=({S,T,U,V},{a,b},R,S) where R is the set of rules Is this grammar ambiguous? S → UT | TV – A) No, the grammar is unambiguous B) Yes, but it can be transformed into U → aUb | ε – an equivalent unambiguous grammar V → bVa | ε C) Yes, and there is no equivalent – unambiguous grammar T → aT | ε – D) I don’t know

  7. PDA Design ● Can we design a PDA for the same language? L = {a i b j a k | i=j or j=k } – ● Can you design a deterministic PDA?

  8. PDAs and CFGs are equivalently expressive Theorem 2.20 : A language is context-free if and only if 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

  9. Intersection ● Consider the languages X = {a i b j a k | i=j and k>1 } – Y = {a i b j a k | j=k and i>1 } – W = X U Y – Z = X ∩ Y = {a i b j a k | i = j = k >1} – Which languages are context-free? A) X,Y B) X,Y,W C) X,Y,W,Z (all) D) None E) I don’t know

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

  11. Non-context-free languages ● {a i b j a k | i= j =k } ● {a i b j a k | i<j<k } ● { ww | w in {a,b}*} ● Proof: Pumping Lemma for Context-Free languages See textbook if interested – We will not cover this in homework or tests –

  12. ??? ??? Context-free languages Context-free languages Regular Regular languages languages

  13. Beyond Push Down Automata ● Can you defjne a more powerful automaton that is able to recognize L3={a i b j a k | i=j=k }? ● Can you recognize L3 with a 2PDA (Push Down Automaton with 2 stacks)? ● Can you recognize L4={a i b j a k b h | i=j=k=h } with a 3PDA (Push Down Automaton with 3 stacks? ● Can you recognize L4 with a 2PDA

  14. T uring machines • Unlimited input • Unlimited (read/write) memory • Unlimited time

  15. T uring machine computation • Read/write head starts at leftmost position on tape • Input string written on leftmost squares of tape, rest is blank • Computation proceeds according to transition function: • Given current state of machine, and current symbol being read • the machine • transitions to new state • writes a symbol to its current position (overwriting existing symbol) • moves the tape head L or R • Computation ends if and when it enters either the accept or the reject state.

  16. Formal defjnition of TM q reject ≠ q accept q reject ≠ q accept

  17. Reminders • Finish reading Sipser Chapter 2. Start Chapter 3 • HW5 due Monday Oct 31 • Review for Exam 2 • T uesday Nov 1 TBA • Exam 2 Wednesday Nov 2 (one week from today) • New seating chart: see Piazza (tonight) • New study guide: see Piazza (tonight) • Haskell 3 on CFG is out. Due Nov 7.

Recommend


More recommend