/
18.404/6.840   Lecture 5 18.404/6.840   Lecture 5

18.404/6.840 Lecture 5 - PowerPoint Presentation

jalin
jalin . @jalin
Follow
64 views
Uploaded On 2024-01-29

18.404/6.840 Lecture 5 - PPT Presentation

Last time Context free grammars CFGs Context free languages CFLs Pushdown automata PDA Converting CFGs to PDAs Today Sipser 23 31 Proving languages not Context Free ID: 1042668

lemma cfl cfls pumping cfl lemma pumping cfls turing input show reject context contradiction languages closed runs machines proving

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "18.404/6.840 Lecture 5" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

1. 18.404/6.840 Lecture 5Last time: - Context free grammars (CFGs) - Context free languages (CFLs)- Pushdown automata (PDA)- Converting CFGs to PDAsToday: (Sipser §2.3, §3.1) - Proving languages not Context Free- Turing machines- T-recognizable and T-decidable languages1

2. Equivalence of CFGs and PDAsRecall Theorem: is a CFL iff some PDA recognizes Done. Need to know the fact, not the proofCorollaries:Every regular language is a CFL.If is a CFL and is regular then is a CFL.Proof sketch of (2): While reading the input, the finite control of the PDA for simulates the DFA for .Note 1: If and are CFLs then may not be a CFL (will show today).Therefore the class of CFLs is not closed under . Note 2: The class of CFLs is closed under (see Pset 2). 2

3. Proving languages not Context FreeLet . We will show that isn’t a CFL.Pumping Lemma for CFLs: For every CFL , there is a such that if and then where 1) for all 2) 3) Informally: All long strings in are pumpable and stay in .                    3

4. Pumping Lemma – Proof Pumping Lemma for CFLs: For every CFL , there is a such that if and then where 1) for all 2) 3)        EProof by picture:    ERR   RGenerates    ER Generates  Long tall parse tree “cutting and pasting” argumentRR4

5. Pumping Lemma – Proof detailsFor where , we have where: 1) for all …cutting and pasting 2) …start with the smallest parse tree for 3) …pick the lowest repetition of a variable E E+TLet the length of the longest right hand side of a rule (E E+T) the max branching of the parse treeLet the height of the parse tree for . A tree of height and max branching has at most leaves.So .Let where # variables in the grammar.So if then and so .Thus at least variables occur in the longest path.So some variable must repeat on a path.        ERRuse  set  want  5

6. Example 1 of Proving Non-CFLet Show: is not a CFLProof by Contradiction:Assume (to get a contradiction) that is a CFL .The CFL pumping lemma gives as above. Let . Pumping lemma says that can divide satisfying the 3 conditions.Condition 3 () implies that cannot contain both 0s and 2s.So has unequal numbers of 0s, 1s, and 2s. Thus , violating Condition 1. Contradiction! Therefore our assumption ( is a CFL) is false. We conclude that is not a CFL .         Pumping Lemma for CFLs: For every CFL , there is a such that if and then where 1) for all 2) 3)  Check-in 5.1Check-in 5.1 Let (equal #s of 0s and 1s) Let (equal #s of 1s and 2s) Observe that PDAs can recognize and . What can we now conclude? a) The class of CFLs is not closed under intersection. b) The Pumping Lemma shows that is not a CFL . c) The class of CFLs is closed under complement. 6

7. Example 2 of Proving Non-CFLet .Show: is not a CFL.Assume (for contradiction) that is a CFL.The CFL pumping lemma gives as above. Need to choose . Which ?Try . But can be pumped and stay inside . Bad choice of .Try . Show cannot be pumped satisfying the 3 conditions.Condition 3 implies that does not overlap two runs of 0s or two runs of 1s.Therefore, in , two runs of 0s or two runs of 1s have unequal length.So violating Condition 1. Contradiction! Thus is not a CFL. Pumping Lemma for CFLs: For every CFL , there is a such that if and then where 1) for all 2) 3)                7

8. Turing Machines (TMs)Head can read and writeHead is two way (can move left or right)Tape is infinite (to the right)Infinitely many blanks “˽“ follow inputCan accept or reject any time (not only at end of input)Finitecontrolababb. . .read/write input tapehead˽˽8

9. TM – example TM recognizing Scan right until ˽ while checking if input is in , reject if not. Return head to left end.Scan right, crossing off single a, b, and c. If the last one of each symbol, accept.If the last one of some symbol but not others, reject.If all symbols remain, return to left end and repeat from (3). acceptheadFinitecontrolinput tapeaaabbcccb˽˽Check-in 5.2Check-in 5.2How do we get the effect of “crossing off” with a Turing machine?a) We add that feature to the model.b) We use a tape alphabet , , , , , , ˽ }.c) All Turing machines come with an eraser. 9

10. TM – Formal DefinitionDefn: A Turing Machine (TM) is a 7-tuple input alphabet tape alphabet () {L, R} (L = Left, R = Right) R  On input a TM may halt (enter or )or may run forever (“loop”). So has 3 possible outcomes for each input : Accept (enter ) Reject by halting (enter ) Reject by looping (running forever) Check-in 5.3Check-in 5.3This Turing machine model is deterministic. How would we change it to be nondeterministic?a) Add a second transition function. b) Change to be {L, R} c) Change the tape alphabet to be infinite. 10

11. TM Recognizers and DecidersLet be a TM. Then accepts . Say that recognizes if . Defn: is Turing-recognizable if for some TM .Defn: TM is a decider if halts on all inputs.Say that decides if and is a decider.Defn: is Turing-decidable if for some TM decider . T-recognizableT-decidableCFLsregular11

12. Quick review of todayProved the CFL Pumping Lemma as a tool for showing that languages are not context free.Defined Turing machines (TMs).Defined TM deciders (halt on all inputs).T-recognizable and T-decidable languages.12

13. MIT OpenCourseWarehttps://ocw.mit.edu18.404J Theory of ComputationFall 2020For information about citing these materials or our Terms of Use, visit: https://ocw.mit.edu/terms.