cse 105 theory of computation
DESCRIPTION
CSE 105 Theory of Computation. Alexander Tsiatas Spring 2012. Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons Attribution- NonCommercial - ShareAlike 3.0 Unported License. Based on a work at http://peerinstruction4cs.org. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: CSE 105 Theory of Computation](https://reader035.vdocuments.site/reader035/viewer/2022062314/5681488b550346895db5a2c8/html5/thumbnails/1.jpg)
CSE 105Theory of
Computation
Alexander TsiatasSpring 2012
Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.Based on a work at http://peerinstruction4cs.org.Permissions beyond the scope of this license may be available at http://peerinstruction4cs.org.
![Page 2: CSE 105 Theory of Computation](https://reader035.vdocuments.site/reader035/viewer/2022062314/5681488b550346895db5a2c8/html5/thumbnails/2.jpg)
From Preliminary Exam 1
• Regular languages are closed under union.
• If L1 and L2 are regular, then is L1 U L2 regular?
– a) true– b) false
![Page 3: CSE 105 Theory of Computation](https://reader035.vdocuments.site/reader035/viewer/2022062314/5681488b550346895db5a2c8/html5/thumbnails/3.jpg)
From Preliminary Exam 1
• Regular languages are closed under union.
• If L1 U L2 is regular, are L1 and L2 both regular?
– a) true– b) false
![Page 4: CSE 105 Theory of Computation](https://reader035.vdocuments.site/reader035/viewer/2022062314/5681488b550346895db5a2c8/html5/thumbnails/4.jpg)
From Preliminary Exam 1
• Direction Matters.
• “If P, then Q” does NOT mean “if Q, then P”.– It does mean “If not Q, then not P”, which is how
we use the pumping lemma to prove that languages are not regular.
• Direction Matters even more, later in the course.
![Page 5: CSE 105 Theory of Computation](https://reader035.vdocuments.site/reader035/viewer/2022062314/5681488b550346895db5a2c8/html5/thumbnails/5.jpg)
CONTEXT-FREE GRAMMARSCFGS
Back to your [English/Spanish/French/…] class
![Page 6: CSE 105 Theory of Computation](https://reader035.vdocuments.site/reader035/viewer/2022062314/5681488b550346895db5a2c8/html5/thumbnails/6.jpg)
Context-free Grammars (CFG)
• Context-free grammars are one way that scholars have tried to model how language, and our brain’s models of language, might be structured– Key concept: representing and generating infinite
complexity, with just a few simple rules
![Page 7: CSE 105 Theory of Computation](https://reader035.vdocuments.site/reader035/viewer/2022062314/5681488b550346895db5a2c8/html5/thumbnails/7.jpg)
What is the language of this CFG?
S → 0SS → 0
a) {0}b) {0, 00, 000, …}c) {ε, 0, 00, 000, …}d) None of the above
![Page 8: CSE 105 Theory of Computation](https://reader035.vdocuments.site/reader035/viewer/2022062314/5681488b550346895db5a2c8/html5/thumbnails/8.jpg)
The LANGUAGE of a CFG
• The set of strings that can be generated following the given production rules.
• Every string generated is in the language, and every string that cannot be generated is not in the language.
![Page 9: CSE 105 Theory of Computation](https://reader035.vdocuments.site/reader035/viewer/2022062314/5681488b550346895db5a2c8/html5/thumbnails/9.jpg)
What is the language of this CFG?
S → 0SS → 1SS → ε
a) Same as the regular expression 0*1*b) Same as the regular expression 0* U 1*c) Same as the regular expression (0 U 1)*d) None of the above
![Page 10: CSE 105 Theory of Computation](https://reader035.vdocuments.site/reader035/viewer/2022062314/5681488b550346895db5a2c8/html5/thumbnails/10.jpg)
What is the language of this CFG?S → T0TT → TTT → 0T1T → 1T0T → 0T → ε
a) All strings of 0’s and 1’sb) All strings of 0’s and 1’s with at least one 0 in itc) All strings of 0’s and 1’s with at least two 0’s in itd) All strings of 0’s and 1’s that have the same number of 0’s and 1’se) All strings of 0’s and 1’s that have more 0’s than 1’s
![Page 11: CSE 105 Theory of Computation](https://reader035.vdocuments.site/reader035/viewer/2022062314/5681488b550346895db5a2c8/html5/thumbnails/11.jpg)
Are CFG’s more powerful than DFA’s?
• In other words: is there a CFG G such that the language of G is not regular?
a) Yesb) No
![Page 12: CSE 105 Theory of Computation](https://reader035.vdocuments.site/reader035/viewer/2022062314/5681488b550346895db5a2c8/html5/thumbnails/12.jpg)
Demonstrating the power of CFG’s
• The language L = {0n 1n | n ≥ 0} is NOT regular. (Why not?)
• Which of these grammars describes the language L?
a) S → AB A → 0A | ε B → 1B | ε
d) S → 01S01 | ε
b) S → AB A → 0A1 | ε B → 0B1 | ε
c) S → 0S1 | ε
e) There is no CFG that describes L.
![Page 13: CSE 105 Theory of Computation](https://reader035.vdocuments.site/reader035/viewer/2022062314/5681488b550346895db5a2c8/html5/thumbnails/13.jpg)
Why do we care about CFG’s?
• You write a Java program but forget a semicolon. How does the compiler catch it?
• You type (5+81(*24) in your fancy TI-89 calculator. How does it not blow up?
• You want to recursively define a tree datatype in O’Caml. How do you do this?
• You pull out your iPhone and ask Siri “When is the Sungod festival this year?” How does Siri have any hope of figuring out what you’re asking?
![Page 14: CSE 105 Theory of Computation](https://reader035.vdocuments.site/reader035/viewer/2022062314/5681488b550346895db5a2c8/html5/thumbnails/14.jpg)
Why do we care about CFG’s?
• All of those situations (and more!) can be handled using CFG’s and parsing a string to see if it can be generated by a CFG.
• Programming languages are often specified as a grammar.
• There are programs (yacc) that can build parsers out of grammars.
• Doesn’t tell you anything about the meaning of the string. This is why they are “context-free” languages.
![Page 15: CSE 105 Theory of Computation](https://reader035.vdocuments.site/reader035/viewer/2022062314/5681488b550346895db5a2c8/html5/thumbnails/15.jpg)
Sometimes a string can be parsed two different ways.
S → NP VPNP → CN | CN PPVP → CV | CV PPPP → P CNCN → A NCV → V | V NPA → a | theN → boy | girl | flowerV → touches | likes | seesP → with
S = SentenceNP = Noun-PhraseVP = Verb-PhrasePP = Prep-PhraseCN = Complex-NounCV = Complex-VerbA = ArticleN = NounV = VerbP = Preposition
![Page 16: CSE 105 Theory of Computation](https://reader035.vdocuments.site/reader035/viewer/2022062314/5681488b550346895db5a2c8/html5/thumbnails/16.jpg)
Parse Tree
• “The girl touches the boy with the flower.”(a) (b)
S → NP VPNP → CN | CN PPVP → CV | CV PPPP → P CNCN → A NCV → V | V NPA → a | theN → boy | girl | flowerV → touches | likes | seesP → with
![Page 17: CSE 105 Theory of Computation](https://reader035.vdocuments.site/reader035/viewer/2022062314/5681488b550346895db5a2c8/html5/thumbnails/17.jpg)
Parse Tree 2
• “The girl touches the boy with the flower.”(a) (b)
S → NP VPNP → CN | CN PPVP → CV | CV PPPP → P CNCN → A NCV → V | V NPA → a | theN → boy | girl | flowerV → touches | likes | seesP → with
![Page 18: CSE 105 Theory of Computation](https://reader035.vdocuments.site/reader035/viewer/2022062314/5681488b550346895db5a2c8/html5/thumbnails/18.jpg)
Ambiguity