Chapter 11 a Hierarchy of Formal Languages and Automata
Total Page:16
File Type:pdf, Size:1020Kb
✐ ✐ “15529˙CH11˙Linz” — 2011/1/12 — 10:03 — page 277 — #1 ✐ ✐ © Jones & Bartlett Learning, LLC © Jones & Bartlett Learning, LLC NOT FOR SALE OR DISTRIBUTION NOT FOR SALE OR DISTRIBUTION © Jones & Bartlett Learning, LLC © Jones & Bartlett Learning, LLC NOT FOR SALEChapter OR DISTRIBUTION 11NOT FOR SALE OR DISTRIBUTION A Hierarchy of © Jones & Bartlett Learning, LLC © Jones & Bartlett Learning, LLC NOT FOR SALE OR DISTRIBUTIONFormal LanguagesNOT FOR SALE OR DISTRIBUTION and Automata © Jones & Bartlett Learning, LLC © Jones & Bartlett Learning, LLC NOT FOR SALE OR DISTRIBUTION NOT FOR SALE OR DISTRIBUTION © Jones & Bartlett Learning, LLC © Jones & Bartlett Learning, LLC NOT FOR SALE OR DISTRIBUTION NOT FOR SALE OR DISTRIBUTION © Jones & Bartlett Learning, LLC © Jones & Bartlett Learning, LLC NOT FOR SALE OR DISTRIBUTIONe now return our attention to ourNOT main FOR interest, SALE the studyOR DISTRIBUTION of formal languages. Our immediate goal will be to examine the languages W associated with Turing machines and some of their restrictions. Be- cause Turing machines can perform any kind of algorithmic com- putation, we expect to find that the family of languages associated with © Jones & Bartlett Learning, LLC them isquite broad.© It Jones includesnot & Bartlett only regular Learning, and context-free LLC lan- guages, but also the various examples we have encountered that lie outside NOT FOR SALE OR DISTRIBUTIONthese families. The nontrivialNOT FOR question SALE is whether OR DISTRIBUTION there are any languages that are not accepted by some Turing machine. We will answer this ques- tion first by showing that there are more languages than Turing machines, so that there must be some languages for which there are no Turing ma- © Joneschines. & Bartlett The proof Learning, is short and LLC elegant, but nonconstructive,© Jones and gives & Bartlett little Learning, LLC insight into the problem. For this reason, we will establish the existence NOT FORof SALE languagesnot OR DISTRIBUTION recognizable by Turing machinesthroughNOT more FOR explicit SALE OR DISTRIBUTION examplesthat actually allow usto identify one such language. Another avenue of investigation will be to look at the relation between Turing ma- chinesand certain typesof grammarsand to establisha connection between © Jones & Bartlett Learning,these grammars LLC and regular and context-free© Jones grammars. & Bartlett This Learning, leads to a LLC hierarchy of grammars and through it to a method for classifying language NOT FOR SALE OR DISTRIBUTION NOT FOR SALE OR DISTRIBUTION 277 © Jones & Bartlett Learning, LLC © Jones & Bartlett Learning, LLC ✐ © Jones & Bartlett Learning, LLC. NOT FOR SALE OR DISTRIBUTION. ✐ NOT FOR SALE OR DISTRIBUTION NOT FOR SALE OR DISTRIBUTION ✐ ✐ ✐ ✐ “15529˙CH11˙Linz” — 2011/1/12 — 10:03 — page 278 — #2 ✐ ✐ © Jones & Bartlett Learning, LLC © Jones & Bartlett Learning, LLC NOT FOR SALE OR DISTRIBUTION NOT FOR SALE OR DISTRIBUTION 278 Chapter 11 A Hierarchy of Formal Languages and Automata © Jonesfamilies. & Bartlett Some set-theoreticLearning, LLC diagrams illustrate the relationships© Jones between & Bartlett Learning, LLC variouslanguage familiesclearly. NOT FOR StrictlySALE speaking,OR DISTRIBUTION many of the arguments in this chapterNOT are FOR valid SALE only OR DISTRIBUTION for languages that do not include the empty string. This restriction arises from the fact that Turing machines, as we have defined them, cannot accept the empty string. To avoid having to rephrase the definition or having to © Jones & Bartlett Learning,add a repeated LLC disclaimer, we make the tacit© Jones assumption & Bartlett that the languagesLearning, LLC discussed in this chapter, unless otherwise stated, do not contain λ.Itisa NOT FOR SALE ORtrivial DISTRIBUTION matter to restate everything so thatNOTλ isincluded, FOR SALE but weOR will DISTRIBUTION leave thisto the reader. © Jones & Bartlett Learning, LLC11.1 Recursive© and Jones Recursively & Bartlett Learning, Enumerable LLC NOT FOR SALE OR DISTRIBUTION LanguagesNOT FOR SALE OR DISTRIBUTION We start with some terminology for the languages associated with Turing machines. In doing so, we must make the important distinction between languagesfor which there existsanaccepting Turing machine and languages © Jonesfor & which Bartlett there existsLearning, a membership LLC algorithm. Because a© Turing Jones machine & Bartlett Learning, LLC NOT FORdoes SALE not necessarily OR DISTRIBUTION halt on input that it does not accept,NOT the first FOR does SALE not OR DISTRIBUTION imply the second. Definition 11.1 © Jones & Bartlett Learning,A language L LLCissaidto be recursively enumerable© Jones &if thereBartlett exists Learning, a Turing LLC NOT FOR SALE ORmachine DISTRIBUTION that acceptsit. NOT FOR SALE OR DISTRIBUTION Thisdefinition impliesonly that there existsaTuring machine M, such that, for every w ∈ L, ∗ © Jones & Bartlett Learning, LLC © Jonesq0w M &x Bartlett1qf x2, Learning, LLC NOT FOR SALE OR DISTRIBUTION NOT FOR SALE OR DISTRIBUTION with qf a final state. The definition says nothing about what happens for w not in L; it may be that the machine haltsin a nonfinal stateor that it never haltsand goesinto an infinite loop. We can be more demanding and ask that the machine tell us whether or not any given input is in its © Joneslanguage. & Bartlett Learning, LLC © Jones & Bartlett Learning, LLC NOT FOR SALE OR DISTRIBUTION NOT FOR SALE OR DISTRIBUTION Definition 11.2 A language L on Σ issaidto be recursive if there exists a Turing machine M that accepts L and that haltson every w in Σ+. In other words, a © Jones & Bartlett Learning,language is recursiveLLC if and only if there© exists Jones a membership & Bartlett algorithm Learning, for LLC NOT FOR SALE OR it.DISTRIBUTION NOT FOR SALE OR DISTRIBUTION © Jones & Bartlett Learning, LLC © Jones & Bartlett Learning, LLC ✐ © Jones & Bartlett Learning, LLC. NOT FOR SALE OR DISTRIBUTION. ✐ NOT FOR SALE OR DISTRIBUTION NOT FOR SALE OR DISTRIBUTION ✐ ✐ ✐ ✐ “15529˙CH11˙Linz” — 2011/1/12 — 10:03 — page 279 — #3 ✐ ✐ © Jones & Bartlett Learning, LLC © Jones & Bartlett Learning, LLC NOT FOR SALE OR DISTRIBUTION NOT FOR SALE OR DISTRIBUTION 11.1 Recursive and Recursively Enumerable Languages 279 © Jones & BartlettIf a language Learning, is recursive, LLC then there exists an easily© Jones constructed & Bartlett enu- Learning, LLC meration procedure. Suppose that M isa Turing machine that determines NOT FORmembership SALE OR in DISTRIBUTION a recursive language L. We first constructNOT another FOR TuringSALE OR DISTRIBUTION machine, say M, that generatesall stringsinΣ + in proper order, let us say w1,w2, .... As these strings are generated, they become the input to M, which is modified so that it writes strings on its tape only if they are in L. © Jones & Bartlett Learning,That thereLLC is also an enumeration© procedure Jones for& everyBartlett recursively Learning, enu- LLC merable language is not as easy to see. We cannot use the previous argument NOT FOR SALE OR DISTRIBUTION NOT FOR SALE OR DISTRIBUTION as it stands, because if some wj isnot in L, the machine M, when started with wj on itstape, may never halt and therefore never get to the strings in L that follow wj in the enumeration. To make surethat thisdoesnot happen, the computation isperformed in a different way. We firstget M © Jones & Bartlett Learning, LLC to generate w1 and let©M Jonesexecute & one Bartlett move on Learning, it. Then we letLLCM generate NOT FOR SALE OR DISTRIBUTIONw2 and let M executeNOT one move FOR on wSALE2, followed OR byDISTRIBUTION the second move on w1. After this, we generate w3 and do one step on w3, the second step on w2, the third step on w1, and so on. The order of performance is depicted in Figure 11.1. From this, it is clear that M will never get into an infinite loop. Since any w ∈ L isgenerated by M and accepted by M in a finite © Jonesnumber & Bartlett of steps, Learning, every string LLC in L iseventually produced© byJonesM. & Bartlett Learning, LLC NOT FOR SALEIt is easy OR to DISTRIBUTION see that every language for which an enumerationNOT FOR procedure SALE OR DISTRIBUTION exists is recursively enumerable. We simply compare the given input string against successive strings generated by the enumeration procedure. If w ∈ L, we will eventually get a match, and the process can be terminated. Definitions11.1 and 11.2 give usvery little insight into the nature of © Jones & Bartlett Learning,either recursive LLC or recursively enumerable© Jones languages. & Bartlett These definitions Learning, at- LLC tach names to language families associated with Turing machines, but shed NOT FOR SALE OR DISTRIBUTIONno light on the nature of representativeNOT languages FOR in SALE these families. OR DISTRIBUTION Nor do they tell us much about the relationships between these languages or their connection to the language familieswe have encountered before. We are therefore immediately faced with questions such as “Are there languages that are recursively enumerable but not recursive?” and “Are there lan- © Jones & Bartlett Learning, LLC guages, describable somehow,© Jones that & are Bartlett not recursively Learning, enumerable?” LLC While NOT FOR SALE OR DISTRIBUTIONwe will be able to supplyNOT some FOR answers, SALE we willOR not DISTRIBUTION be able to produce very explicit examples to illustrate these questions, especially the second one. © Jones & Bartlett Learning, LLC © Jones & Bartlett Learning, LLC w w w w . Figure 11.1NOT FOR SALE OR1 DISTRIBUTION2 3 4 NOT FOR SALE OR DISTRIBUTION First move ... Second