# Automata and Computability. Solutions to Exercises

Save this PDF as:

Size: px
Start display at page:

## Transcription

1 Automata and Computability Solutions to Exercises Fall 25 Alexis Maciel Department of Computer Science Clarkson University Copyright c 25 Alexis Maciel

2 ii

3 Contents Preface vii Introduction 2 Finite Automata 3 2. Turing Machines Introduction to Finite Automata Formal Definition More Examples Closure Properties Nondeterministic Finite Automata Introduction Formal Definition Equivalence with DFA s Closure Properties Regular Expressions 4 4. Introduction Formal Definition More Examples Converting Regular Expressions into DFA s

4 iv CONTENTS 4.5 Converting DFA s into Regular Expressions Precise Description of the Algorithm Nonregular Languages 5 5. Some Examples The Pumping Lemma Context-Free Languages Introduction Formal Definition of CFG s More Examples Ambiguity and Parse Trees Non Context-Free Languages The Basic Idea A Pumping Lemma A Stronger Pumping Lemma More on Context-Free Languages Closure Properties Pushdown Automata Deterministic Algorithms for CFL s Turing Machines Introduction Formal Definition Variations on the Basic Turing Machine Equivalence with Programs Problems Concerning Formal Languages 77. Regular Languages CFL s

5 CONTENTS v Undecidability 8. An Unrecognizable Language Natural Undecidable Languages Reducibility and Additional Examples Rice s Theorem Natural Unrecognizable Languages

6 vi CONTENTS

7 Preface This document contains solutions to the exercises of the course notes Automata and Computability. These notes were written for the course CS345 Automata Theory and Formal Languages taught at Clarkson University. The course is also listed as MA345 and CS54. The solutions are organized according to the same chapters and sections as the notes. Here s some advice. Whether you are studying these notes as a student in a course or in self-directed study, your goal should be to understand the material well enough that you can do the exercises on your own. Simply studying the solutions is not the best way to achieve this. It is much better to spend a reasonable amount of time and effort trying to do the exercises yourself before looking at the solutions. If you can t do an exercise on your own, you should study the notes some more. If that doesn t work, seek help from another student or from your instructor. Look at the solutions only to check your answer once you think you know how to do an exercise. If you needed help doing an exercise, try redoing the same exercise later on your own. And do additional exercises. If your solution to an exercise is different from the official solution, take the time to figure out why. Did you make a mistake? Did you forget something? Did you discover another correct solution? If you re not sure, ask for help from another student or the instructor. If your solution turns out to be incorrect, fix it, after maybe getting some help, then try redoing the same exercise later on

9 Chapter Introduction There are no exercises in this chapter.

10 2 CHAPTER. INTRODUCTION

11 Chapter 2 Finite Automata 2. Turing Machines There are no exercises in this section. 2.2 Introduction to Finite Automata d d q - q d q 2 Missing edges go to a garbage state. In other words, the full DFA looks like this:

12 4 CHAPTER 2. FINITE AUTOMATA d d q - q d q 2 other -, other -, other q 3 any The transition label other means any character that s not a dash or a digit d d q - q d q 2... q 3 q 4 d d Missing edges go to a garbage state.

13 2.2. INTRODUCTION TO FINITE AUTOMATA underscore underscore q 3 letter, digit underscore, letter, digit other q letter q digit, other other q 2 any

14 6 CHAPTER 2. FINITE AUTOMATA q 4 d q 5 d q 6 d q 7 d q 8 d q 9 d q d q d q d q d 2 q 3 - q d 3 q d 4 q d 5 q d 6 q 7 - q d 26 q d 27 q d 28 q d 29 q 3

15 2.2. INTRODUCTION TO FINITE AUTOMATA starting_state() { return q } is_accepting(state s) { return true iff s is q } next_state(state s, char c) { if (s is q) if (c is underscore or letter) return q else return q2 else if (s is q) if (c is underscore, letter or digit) return q else return q2 else // s is q2 return q2 } The following assumes that the garbage state is labeled q 9. In the pseudocode algorithm, states are stored as integers. This is more convenient here. starting_state() { return } is_accepting(state s) { return true iff s is 8 }

16 8 CHAPTER 2. FINITE AUTOMATA next_state(state s, char c) { if (s in {,, 2} or {4, 5, 6, 7}) if (c is digit) return s + else return 9 else if (s is 3) if (c is digit) return 5 else if (c is dash) return 4 else return 9 else if (s is 8 or 9) return 9 } 2.3 Formal Definition The DFA is ({q, q, q 2,..., q 9 }, Σ, δ, q, {q 8 }) where Σ is the set of all characters that appear on a standard keyboard and δ is defined as follows: δ(q i, c) = δ(q 3, c) = qi+ q 9 q 4 q 5 q 9 δ(q 8, c) = q 9 for every c δ(q 9, c) = q 9 for every c if i / {3, 8, 9} and c is digit if i / {3, 8, 9} and c is not digit if c is dash if c is digit otherwise

17 2.3. FORMAL DEFINITION The DFA is ({q, q, q 2, q 3 }, Σ, δ, q, {q 2 }) where Σ is the set of all characters that appear on a standard keyboard and δ is defined as follows: δ(q, c) = δ(q i, c) = q q 2 q 3 q2 δ(q 3, c) = q 3 q 3 if c is dash if c is digit otherwise if i {, 2} and c is digit if i {, 2} and c is not digit for every c The DFA is ({q, q, q 2,..., q 5 }, Σ, δ, q, {q 2, q 4 }) where Σ is the set of all characters that appear on a standard keyboard and δ is defined as follows: q if c is dash q 2 if c is digit δ(q, c) = q 3 if c is decimal point q 5 otherwise q 2 if i {, 2} and c is digit δ(q i, c) = q 3 if i {, 2} and c is decimal point if i {, 2} and c is not digit or decimal point δ(q i, c) = q 5 q4 δ(q 5, c) = q 5 q 5 if i {3, 4} and c is digit if i {3, 4} and c is not digit for every c

18 CHAPTER 2. FINITE AUTOMATA 2.4 More Examples q q 2 q q 3 q In all cases, missing edges go to a garbage state. a) b) q q q 2,, q q q 2

19 2.4. MORE EXAMPLES c),,,,, q q q 2 q k q k In all cases, missing edges go to a garbage state. a), b) The idea is for the DFA to remember the last two symbols it has seen.

20 2 CHAPTER 2. FINITE AUTOMATA q ɛ q q q q q q c) Again, the idea is for the DFA to remember the last two symbols it has seen. We could simply change the accepting states of the previous DFA to {q, q }. But we can also simplify this DFA by assuming that strings of length less than two are preceded by. q q q q

21 2.4. MORE EXAMPLES 3 d) The idea is for the DFA to remember the last k symbols it has seen. But this is too difficult to draw clearly, so here s a formal description of the DFA: (Q, {,}, δ, q, F) where Q = {q w w {,} and w has length k} q = q w where w = k F = {q w w Q and w starts with a } and δ is defined as follows: δ(q au, b) = q ub where a Σ, u is a string of length k and b Σ In all cases, missing edges go to a garbage state. a), q q b), q q q 2

22 4 CHAPTER 2. FINITE AUTOMATA c), q q q 2 d), q q q 2 e), q q q 2 q k a) The idea is for the DFA to store the value, modulo 3, of the portion of the number it has seen so far, and then update that value for every additional digit that is read. To update the value, the current value is multiplied by, the new digit is added and the result is reduced modulo 3.

23 2.4. MORE EXAMPLES 5,3,6,9,4,7,3,6,9,3,6,9,4,7,4,7 q q q 2 2,5,8 2,5,8 2,5,8 (Note that this is exactly the same DFA we designed in an example of this section for the language of strings that have the property that the sum of their digits is a multiple of 3. This is because mod 3 = so that when we multiply the current value by and reduce modulo 3, we are really just multiplying by. Which implies that the strategy we described above is equivalent to simply adding the digits of the number, modulo 3.) b) We use the same strategy that was described in the first part, but this time, we reduce modulo k. Here s a formal description of the DFA: (Q, Σ, δ, q, F) where Q = {q, q, q 2,..., q k } Σ = {,,2,...,9} F = {q } and δ is defined as follows: for every i Q and c Σ, δ(q i, c) = q j where j = (i + c) mod k.

24 6 CHAPTER 2. FINITE AUTOMATA a) The idea is for the DFA to verify, for each input symbol, that the third digit is the sum of the first two plus any carry that was previously generated, as well as determine if a carry is generated. All that the DFA needs to remember is the value of the carry ( or ). The DFA accepts if no carry is generated when processing the last input symbol. Here s a formal description of the DFA, where state q 2 is a garbage state: (Q, Σ, δ, q, F) where Q = {q, q, q 2 } Σ = {[abc] a, b, c {,,2,...,9}} F = {q } and δ is defined as follows: q if d {, } and d + a + b = c δ(q d,[abc]) = q if d {, }, d + a + b and (d + a + b) mod = c otherwise q 2 Here s a transition diagram of the DFA that shows only one of the, transitions that come out of each state. [23] [56] [786] q q [24] b) Since the DFA is now reading the numbers from left to right, it can t compute the carries as it reads the numbers. So it will do the opposite: for each input symbol, the DFA will figure out what carry it

25 2.4. MORE EXAMPLES 7 needs from the rest of the numbers. For example, if the first symbol that the DFA sees is [23], the DFA will know that there should be no carry generated from the rest of the numbers. But if the symbol is [24], the DFA needs the rest of the number to generate a carry. And if a carry needs to be generated, the next symbol will have to be something like [56] but not [358]. The states of the DFA will be used to remember the carry that is needed from the rest of the numbers. The DFA will accept if no carry is needed for the first position of the numbers (which is given by the last symbol of the input string). Here s a formal description of the DFA, where state q 2 is a garbage state: (Q, Σ, δ, q, F) where Q = {q, q, q 2 } Σ = {[abc] a, b, c {,,2,...,9}} F = {q } and δ is defined as follows: qd δ(q,[abc]) = δ(q,[abc]) = q 2 δ(q 2,[abc]) = q 2, q d q 2 if d {, } and d + a + b = c otherwise if d {, }, d + a + b and (d + a + b) mod = c otherwise for every [abc] Σ Here s a transition diagram of the DFA that shows only one of the, transitions that come out of each state.

26 8 CHAPTER 2. FINITE AUTOMATA [23] [786] [24] q q [56] 2.5 Closure Properties In each case, all we have to do is switch the acceptance status of each state. But we need to remember to do it for the garbage states too. a) q q q 2,

27 2.5. CLOSURE PROPERTIES 9 b),, q q q 2, c),,,,, q q q 2 q k q k, It is important to include in the pair construction the garbage states of the DFA s for the simpler languages. (This is actually not needed for intersections but it is critical for unions.) In each case, we give the DFA s for the two simpler languages followed by the DFA obtained by the pair construction.

28 2 CHAPTER 2. FINITE AUTOMATA a),,, q q q 2 q 3 q q, q q q 2 q 3, q q q 2 q 3,,

29 2.5. CLOSURE PROPERTIES 2 b), q q q 2 q q q 2,

30 22 CHAPTER 2. FINITE AUTOMATA q q q 2 q q q 2 q 2 q 2 q 22, c), q q q 2

31 2.5. CLOSURE PROPERTIES 23 q q q 2, q q q 2 q q q 2 q 2 q 2 q 22,

32 24 CHAPTER 2. FINITE AUTOMATA d), q q q 2 q q q q q 2 q q q 2

33 2.5. CLOSURE PROPERTIES In both cases, missing edges go to a garbage state. a) q q q 2 q 3 q 4 # b) The dashed state and edge could be deleted. q q q 2 q 3 q 4

34 26 CHAPTER 2. FINITE AUTOMATA

35 Chapter 3 Nondeterministic Finite Automata 3. Introduction a), q q q 2

36 28 CHAPTER 3. NONDETERMINISTIC FINITE AUTOMATA b), q q q 3 q 2 c), q, q q 2 d), q,,, q q 2 q k e) q q

37 3.2. FORMAL DEFINITION Formal Definition The NFA is (Q, {,}, δ, q, F) where Q = {q, q, q 2, q 3 } F = {q 3 } and δ is defined by the following table δ ɛ q q q, q q q 2 q 2 q 2 q 3 q 3 q The NFA is (Q, {,}, δ, q, F) where Q = {q, q, q 2, q 3 } F = {q 3 } and δ is defined by the following table: δ ɛ q q q q q 2 q q 2 q 3 q q 3 q 3 q 3

38 3 CHAPTER 3. NONDETERMINISTIC FINITE AUTOMATA q q q q q q q q q q q q q 2 q 3 q q q 2 q 3 q 3 q 3 q 3 The NFA accepts because the last two sequences end in the accepting state.

39 3.2. FORMAL DEFINITION ɛ ɛ ɛ ɛ q q q q q q q q q q q ɛ ɛ ɛ ɛ q q q 2 q q q q q q q q ɛ ɛ ɛ ɛ q q q q q q q q 2 q q q ɛ ɛ ɛ ɛ q q q 2 q q q q q 2 q q q ɛ ɛ q q q q q q q q 2 q 3 ɛ ɛ q q q 2 q q q q q 2 q 3 q q q 2 q 3 q 3 q 3 q 3 The NFA accepts because the last three sequences end in the accepting state.

40 32 CHAPTER 3. NONDETERMINISTIC FINITE AUTOMATA 3.3 Equivalence with DFA s q q q q q q q 2 q 3 q q q 3 q q q 2 q 3 q q 3 q 3

41 3.3. EQUIVALENCE WITH DFA S a) δ b) q q q q q, q 2 q 2 q, q 2 q q, q 2 The start state is {}. The accepting state is {q, q 2 }. (State {q 2 } is unreachable from the start state.) Missing transitions go to the garbage state ( ). δ q q, q q, q 2 q q 3 q 2 q 3 q 3 q, q q, q, q 3 q, q 2 q, q 2 q, q q, q 2, q 3 q, q, q 3 q, q, q 3 q, q 2 q, q 2, q 3 q, q q, q 2, q 3 The start state is {q }. The accepting states are {q, q, q 3 } and {q, q 2, q 3 }. (States {q }, {q 2 } and {q 3 } are unreachable from the start

42 34 CHAPTER 3. NONDETERMINISTIC FINITE AUTOMATA c) state.) δ q q q, q q q 2 q 2 q 2 q, q q, q 2 q, q, q 2 q, q 2 q q, q q, q, q 2 q, q 2 q, q, q 2 d) The start state is {q }. The accepting states are {q, q 2 } and {q, q, q 2 }. (States {q } and {q 2 } are unreachable from the start state.) δ q q q q q The start state is {q }. The accepting state is {q }. Missing transitions go to the garbage state ( ). (The given NFA was almost a DFA. All that was missing was a garbage state and that s precisely what the algorithm added.)

43 3.3. EQUIVALENCE WITH DFA S a) δ q q q q q, q 2 q 2 q, q 2 q q, q 2 The start state is E({q }) = {q }. The accepting state is {q, q 2 }. (State {q 2 } is unreachable from the start state.) Missing transitions go to the garbage state ( ). b) δ q q, q, q 2 q, q, q 2 q q 3 q 2 q 3 q 3 q, q, q 2 q, q, q 2, q 3 q, q, q 2, q 3 q, q, q 2, q 3 q, q, q 2, q 3 q, q, q 2, q 3 The start state is E({q }) = {q, q, q 2 }. The accepting state is {q, q, q 2, q 3 }. (States {q }, {q }, {q 2 } and {q 3 } are unreachable from the start state.)

44 36 CHAPTER 3. NONDETERMINISTIC FINITE AUTOMATA 3.4 Closure Properties Suppose that M i = (Q i, Σ, δ i, q i, F i ), for i =, 2. Without loss of generality, assume that Q and Q 2 are disjoint. Then N = (Q, Σ, δ, q, F) where Q = Q Q 2 q = q F = F 2 and δ is defined as follows: {q2 } if q F δ(q, ɛ) = otherwise δ(q, a) = {δ i (q, a)}, if q Q i and a Σ Suppose that M = (Q, Σ, δ, q, F ). Let q be a state not in Q. Then N = (Q, Σ, δ, q, F) where Q = Q {q } F = F {q } and δ is defined as follows: {q } if q F {q } δ(q, ɛ) = otherwise δ(q, a) = {δ (q, a)}, if q q and a Σ. a) In the second to last paragraph of the proof, if k =, then it is claimed that w = x with x A. We know x is accepted by N, but there is no reason why that can t be because x leads back to the start state instead of leading to one of the original accepting states of M.

45 3.4. CLOSURE PROPERTIES 37 b) Consider the following DFA for the language of strings that contain at least one :, M If we used this idea, we would get the following NFA:, N ɛ This NFA accepts strings that contain only s. These strings are not in the language L(M). Therefore, L(N) L(M) This can be shown by modifying the construction that was used for the star operation. The only change is that a new start state should not be added. The argument that this construction works is almost the same as before. If w A +, then w = x x k with k and each x i A. This implies that N can accept w by going through M k times, each time reading one x i and then returning to the start state of M by using one of the new ɛ transitions (except after x k ). Conversely, if w is accepted by N, then it must be that N uses the new ɛ looping back transitions k times, for some number k, breaking w up into x x k+, with each x i A. This implies that w A +. Therefore, L(N) = A +.

46 38 CHAPTER 3. NONDETERMINISTIC FINITE AUTOMATA Suppose that L is regular and that it is recognized by a DFA M that looks like this: M This DFA can be turned into an equivalent NFA N with a single accepting state as follows: N ɛ ɛ That is, we add a new accepting state, an ɛ transition from each of the old accepting states to the new one, and we make the old accepting states non-accepting. We can show that L(N) = L(M) as follows. If w is accepted by M, then w leads to an old accepting, which implies that N can accept w by using one of the new transitions. If w is accepted by N, then the reading of w must finish with one of the new transitions. This implies that in M, w leads to one of the old accepting states, so w is accepted by M Suppose that L is recognized by a DFA M. Transform N into an equivalent NFA with a single accepting state. (The previous exercise says that this can

47 3.4. CLOSURE PROPERTIES 39 be done.) Now reverse every transition in N: if a transition labeled a goes from q to q 2, make it go from q 2 to q. In addition, make the accepting state become the start state, and switch the accepting status of the new and old start states. Call the result N. We claim that N recognizes L. If w = w w n is accepted by N, it must be that there is a path through N labeled w. But then, this means that there was a path labeled w n w through N. Therefore, w is the reverse of a string in L, which means that w L. It is easy to see that the reverse is also true.

48 4 CHAPTER 3. NONDETERMINISTIC FINITE AUTOMATA

49 Chapter 4 Regular Expressions 4. Introduction a) ( ɛ)dd. b) ( ɛ)dd ( ɛ)d.dd. c) _(_ L D) (L D)(_ L D) L(_ L D). d) D 7 D D 3 D 4 D 3 D 3 D Formal Definition There are no exercises in this section. 4.3 More Examples Σ Σ.

50 42 CHAPTER 4. REGULAR EXPRESSIONS a) Σ. b) ΣΣ. c) Σ k Σ a) ( )Σ. b) Σ ( ). c) Σ Σ. d) Σ Σ k a) Σ Σ. b). c) Σ Σ Σ. d). e) (Σ ) k Σ a) ɛ Σ Σ. b) ɛ Σ ΣΣ. c) (ɛ Σ) k Σ k Σ. Another solution: ( k i= Σi ) Σ k Σ. a) Σ Σ Σ.

51 4.4. CONVERTING REGULAR EXPRESSIONS INTO DFA S b) Σ Σ Σ Σ Σ Σ. c) One way to go about this is to focus on the first two s that occur in the string and then list the ways in which the in the string can relate to those two s. Here s what you get: d) Let E = ( ) and D = ( ). The regular expression E describes the language of strings with an even number of s while D describes the language of strings with an odd number of s. Then the language of strings that contain at least two s and an even number of s can be described as follows: a) () # +. b) () +. E E E E D D D E D D D E. 4.4 Converting Regular Expressions into DFA s a) ɛ ɛ ɛ ɛ ɛ ɛ

52 44 CHAPTER 4. REGULAR EXPRESSIONS b) ɛ ɛ ɛ ɛ ɛ ɛ ɛ ɛ ɛ

53 4.4. CONVERTING REGULAR EXPRESSIONS INTO DFA S 45 c) ɛ ɛ ɛ ɛ ɛ ɛ ɛ d) ɛ ɛ ɛ

54 46 CHAPTER 4. REGULAR EXPRESSIONS 4.5 Converting DFA s into Regular Expressions a) We first add a new accepting state: q q q 2 ɛ ɛ We then remove state q : q q 2 ɛ ɛ We remove state q 2 : ( ) q ɛ ( ) The final regular expression is ( ( ) ) (ɛ ( ) )

55 4.6. PRECISE DESCRIPTION OF THE ALGORITHM 47 b) Since the NFA has only one accepting state, there is no need to add a new one. We then notice that state q 2 cannot be used to travel between the other two states. So we can just remove it: q q The final regular expression is ( + ) Precise Description of the Algorithm The GNFA is (Q, {,}, δ, q, F) where Q = {q, q, q 3 } F = {q 3 } and δ is defined by the following table: δ q q q 3 q q q The GNFA is (Q, {,,2}, δ, q, F) where Q = {q, q 2, q 3 } F = {q 3 }

56 48 CHAPTER 4. REGULAR EXPRESSIONS and δ is defined by the following table: δ q q 2 q 3 q 2 2 ɛ q q We first add a new accepting state:, q q q 2 ɛ Then, we notice that state q 2 cannot be used to travel between any two states. So we can just remove it: q q ɛ We then remove state q :

57 4.6. PRECISE DESCRIPTION OF THE ALGORITHM 49 + q + The final regular expression is ( + ) +.

58 5 CHAPTER 4. REGULAR EXPRESSIONS

59 Chapter 5 Nonregular Languages 5. Some Examples 5... Suppose that L = { n 2n n } is regular. Let M be a DFA that recognizes L and let n be the number of states of M. Consider the string w = n 2n. As M reads the s in w, M goes through a sequence of states r, r, r 2,..., r n. Because this sequence is of length n+, there must be a repetition in the sequence. Suppose that r i = r j with i < j. Then the computation of M on w looks like this: j i r i r i n j 2n This implies that the string i n j 2n = n (j i) 2n is also accepted. But since this string has less than n s, it does not belong to L. This contradicts

60 52 CHAPTER 5. NONREGULAR LANGUAGES the fact that M recognizes L. regular. Therefore, M cannot exist and L is not Suppose that L = { i j i 2 j} is regular. Let M be a DFA that recognizes L and let n be the number of states of M. Consider the string w = 2n n. As M reads the first n s in w, M goes through a sequence of states r, r, r 2,..., r n. Because this sequence is of length n +, there must be a repetition in the sequence. Suppose that r i = r j with i < j. Then the computation of M on w looks like this: j i r i r i 2n j n Now consider going twice around the loop. This implies that the string i 2(j i) 2n j n = 2n+(j i) n is also accepted. But since this string has more than 2n s, it does not belong to L. This contradicts the fact that M recognizes L. Therefore, M cannot exist and L is not regular Suppose that L = {x x x {,} } is regular. Let M be a DFA that recognizes L and let n be the number of states of M. Consider the string w = n n. As M reads the first n s of w, M goes through a sequence of states r, r, r 2,..., r n. Because this sequence is of length n +, there must be a repetition in the sequence. Suppose that r i = r j with i < j. Then the computation of M on w looks like this:

61 5.2. THE PUMPING LEMMA 53 j i r i r i n j n This implies that the string i n j n = n (j i) n is also accepted. But this string does not belong to L. This contradicts the fact that M recognizes L. Therefore, M cannot exist and L is not regular. 5.2 The Pumping Lemma Let L = { i j i j}. Suppose that L is regular. Let p be the pumping length. Consider the string w = p p. Clearly, w L and w p. Therefore, according to the Pumping Lemma, w can be written as x yz where. x y p. 2. y ɛ. 3. x y k z L, for every k. Condition () implies that y contains only s. Condition (2) implies that y contains at least one. Therefore, the string x y 2 z does not belong to L because it contains more s than s. This contradicts Condition (3) and implies that L is not regular Let L = { i # j # i+j }. Suppose that L is regular. Let p be the pumping length. Consider the string w = p # p # 2p. Clearly, w L and w p. Therefore, according to the Pumping Lemma, w can be written as x yz where. x y p.

62 54 CHAPTER 5. NONREGULAR LANGUAGES 2. y ɛ. 3. x y k z L, for every k. Since x y p, we have that y contains only s from the first part of the string. Therefore, x y 2 z = p+ y # p # 2p. Because y, this string cannot belong to L. This contradicts the Pumping Lemma and shows that L is not regular Let L be the language described in the exercise. Suppose that L is regular. Let p be the pumping length. Consider the string w = p ## p+. Clearly, w L and w p. Therefore, according to the Pumping Lemma, w can be written as x yz where. x y p. 2. y ɛ. 3. x y k z L, for every k. Since x y p, we have that y contains only s from the first part of the string. Therefore, x y 2 z = p+ y ## p+. Since y, this string does not belong to L because the sum of the first two numbers no longer equals the third. This contradicts the Pumping Lemma and shows that L is not regular What is wrong with this proof is that we cannot assume that p =. All that the Pumping Lemma says is that p is positive. We cannot assume anything else about p. For example, if we get a contradiction for the case p =, then we haven t really contradicted the Pumping Lemma because it may be that p has another value.

63 Chapter 6 Context-Free Languages 6. Introduction a) b) I SN S ɛ N DN D D 9 R SN SN.N S ɛ N DN ɛ N DN D 9

64 56 CHAPTER 6. CONTEXT-FREE LANGUAGES c) I _R LR R _R LR DR ɛ R R LR R DR L a z A Z D Formal Definition of CFG s There are no exercises in this section. 6.3 More Examples a) S S b) S S S ɛ c) S S ɛ d) Here s one solution: S ZS ɛ Z ɛ

65 6.4. AMBIGUITY AND PARSE TREES Here s another one: S S T T T ɛ S S #T T T # S (S)S [S]S {S}S ɛ A string of properly nested parentheses is either () or a string of the form (u)v where u and v are either empty or strings of properly nested parentheses. S (S)S ()S (S) () 6.4 Ambiguity and Parse Trees

66 58 CHAPTER 6. CONTEXT-FREE LANGUAGES

67 Chapter 7 Non Context-Free Languages 7. The Basic Idea 7... Let L denote that language and suppose that L is context-free. Let G be a CFG that generates L. Let w = a n b n c n where n = b V +. By the argument developed in this section, any derivation of w in G contains a repeated variable. Assume that the repetition is of the nested type. Then uv k x y k z L for every k. And, as shown at the end of the section, we can ensure that v and y are not both empty. There are now three cases to consider. First, suppose that either v or y contains more than one type of symbol. Then uv 2 x y 2 z / L because that string is not even in a b c. Second, suppose that v and y each contain only one type of symbol but no c s. Then uv 2 x y 2 z contains more a s or b s than c s. Therefore, uv 2 x y 2 z / L. Third, suppose that v and y each contain only one type of symbol including some c s. Then v and y cannot contain both a s or b s. This implies that uv x y z contains less c s than a s or less c s than b s. Therefore,

68 6 CHAPTER 7. NON CONTEXT-FREE LANGUAGES uv x y z / L. In all three cases, we have a contradiction. context-free. This proves that L is not 7.2 A Pumping Lemma Let L denote that language and suppose that L is context-free. Let p be the pumping length. Consider the string w = p p p. Clearly, w L and w p. Therefore, according to the Pumping Lemma, w can be written as uvx yz where. v y ɛ. 2. uv k x y k z L, for every k. There are two cases to consider. First, suppose that either v or y contains more than one type of symbol. Then uv 2 x y 2 z / L because that string is not even in. Second, suppose that v and y each contain only one type of symbol. The string w consists of three blocks of p symbols and v and y can touch at most two of those blocks. Therefore, uv 2 x y 2 z = p+i p+j p+k where at least one of i, j, k is greater than and at least one of i, j, k is equal to. This implies that uv 2 x y 2 z / L. In both cases, we have that uv 2 x y 2 z / L. proves that L is not context-free. This is a contradiction and Let L denote that language and suppose that L is context-free. Let p be the pumping length. Consider the string w = a p b p c p. Clearly, w L and w p. Therefore, according to the Pumping Lemma, w can be written as uvx yz where

69 7.2. A PUMPING LEMMA 6. v y ɛ. 2. uv k x y k z L, for every k. There are three cases to consider. First, suppose that either v or y contains more than one type of symbol. Then uv 2 x y 2 z / L because that string is not even in a b c. In the other two cases, v and y each contain only one type of symbol. The second case is when v consists of a s. Then, since y cannot contain both b s and c s, uv 2 x y 2 z contains more a s than b s or more a s than c s. This implies that uv 2 x y 2 z / L. The third case is when v does not contain any a s. Then y can t either. This implies that uv x y z contains less b s than a s or less c s than a s. Therefore, uv x y z / L. In all cases, we have that uv k x y k z / L for some k. This is a contradiction and proves that L is not context-free Let L denote that language and suppose that L is context-free. Let p be the pumping length. Consider the string w = p # p # 2p. Clearly, w L and w p. Therefore, according to the Pumping Lemma, w can be written as uvx yz where. v y ɛ. 2. uv k x y k z L, for every k. There are several cases to consider. First, suppose that either v or y contains a #. Then uv 2 x y 2 z / L because it contains too many # s. For the remaining cases, assume that neither v nor y contains a #. Note that w consists of three blocks of s separated by # s. This implies that v and y are each completely contained within one block and that v and y cannot contain s from all three blocks.

70 62 CHAPTER 7. NON CONTEXT-FREE LANGUAGES The second case is when v and y don t contain any s from the third block. Then uv 2 x y 2 z = p+i # p+ j # 2p where at least one of i, j is greater than. This implies that uv 2 x y 2 z / L. The third case is when v and y don t contain any s from the first two blocks. Then uv 2 x y 2 z = p # p # 2p+i where i >. This implies that uv 2 x y 2 z / L. The fourth case is when v consists of s the first block and y consists of s the third block. Then uv 2 x y 2 z = p+i # p # 2p+j where both i, j are greater than. This implies that uv 2 x y 2 z / L because the first block is larger than the second block. The fifth and final case is when v consists of s the second block and y consists of s the third block. Then uv x y z = p # p i # 2p j where both i, j are greater than. This implies that uv 2 x y 2 z / L because the second block is smaller than the first block. In all cases, we have a contradiction. This proves that L is not context-free. 7.3 A Stronger Pumping Lemma Let L denote that language and suppose that L is context-free. Let p be the pumping length. Consider the string w = p 2p p. Clearly, w L and w p. Therefore, according to the Pumping Lemma, w can be written as uvx yz where. vx y p. 2. v y ɛ. 3. uv k x y k z L, for every k. The string w consists of three blocks of symbols. Since v x y p, v and y are completely contained within two consecutive blocks. Suppose that v

71 7.3. A STRONGER PUMPING LEMMA 63 and y are both contained within a single block. Then uv 2 x y 2 z has additional symbols of one type but not the other. Therefore, this string is not in L. Now suppose that v and y touch two consecutive blocks, the first two, for example. Then uv x y z = i j p p where < i, j < p. This string is clearly not in L. The same is true for the other blocks. Therefore, in all cases, we have that w cannot be pumped. This contradicts the Pumping Lemma and proves that L is not context-free Let L denote that language and suppose that L is context-free. Let p be the pumping length. Consider the string w = p # p # p2. Clearly, w L and w p. Therefore, according to the Pumping Lemma, w can be written as uvx yz where. v y ɛ. 2. uv k x y k z L, for every k. There are several cases to consider. First, suppose that either v or y contains a #. Then uv 2 x y 2 z / L because it contains too many # s. For the remaining cases, assume that neither v or y contains a #. Note that w consists of three blocks of s separated by # s. This implies that v and y are each completely contained within one block and that v and y cannot touch all three blocks. The second case is when v and y are contained within the first two blocks. Then uv 2 x y 2 z = p+i # p+j # p2 where at least one of i, j is greater than. This implies that uv 2 x y 2 z / L. The third case is when v and y are both within the third block. Then uv 2 x y 2 z = p # p # p2 +i where i >. This implies that uv 2 x y 2 z / L. The fourth case is when v consists of s from the first block and y consists of s from the third block. This case cannot occur since vx y p.

72 64 CHAPTER 7. NON CONTEXT-FREE LANGUAGES The fifth and final case is when v consists of s from the second block and y consists of s from the third block. Then uv 2 x y 2 z = p # p+i # p2 +j where both i, j are greater than. Now, p(p + i) p(p + ) = p 2 + p. On the other hand, p 2 + j < p 2 + p since j = y < vx y p. Therefore, p(p + i) p 2 + j. This implies that uv 2 x y 2 z / L. In all cases, we have a contradiction. This proves that L is not context-free.

73 Chapter 8 More on Context-Free Languages 8. Closure Properties Here s a CFG for the language {a i b j c k i j or j k}: S T C A U T atb A B (a i b j, i j) U buc B C (b j c k, j k) A aa ɛ (a ) C cc ɛ (c ) A aa a (a + ) B bb b (b + ) C cc c (c + ) Now, the complement of {a n b n c n n } is a b c {a i b j c k i j or j k}. The language on the left is regular and, therefore, context-free. We have just shown that the language on the right is context-free. Therefore, the

74 66 CHAPTER 8. MORE ON CONTEXT-FREE LANGUAGES complement of {a n b n c n n } is context-free because the union of two CFL s is always context-free Suppose that w = x y where x = y but x y. Focus on one of the positions where x and y differ. It must be the case that x = u au 2 and y = v bv 2, where u = v, u 2 = v 2, a, b {,} and a b. This implies that w = u au 2 v bv 2. Now, notice that u 2 v = v 2 + u. We can then split u 2 v differently, as s s 2 where s = u and s 2 = v 2. This implies that w = u as s 2 bv 2 where u = s and s 2 = v 2. The idea behind a CFG that derives w is to generate u as followed by s 2 bv 2. Here s the result: S T T T T T AT A (us, u = s ) T AT A (us, u = s ) A Now, the complement of {ww w {,} } is {w {,} w is odd} {x y x, y {,}, x = y but x y} The language on the left is regular and, therefore, context-free. We have just shown that the language on the right is context-free. Therefore, the complement of {ww w {,} } is context-free because the union of two CFL s is always context-free.

75 8.2. PUSHDOWN AUTOMATA Pushdown Automata One possible solution is an algorithm that simulates the CFG for this language: push S on the stack while (stack not empty) if (top of stack is S) replace S by T (put at the top of the stack) else if (top of stack is T) replace T by either T, T or nothing else // top of stack is or if (end of input) reject read next char c if (c equals top of stack) pop stack else reject if (end of input) accept else reject

76 68 CHAPTER 8. MORE ON CONTEXT-FREE LANGUAGES Another solution is a more direct algorithm: if (end of input) accept read next char c while (c is ) push on the stack if (end of input) // some s but no s reject read next char c while (c is ) if (stack empty) reject // too many s pop stack if (end of input) if (stack empty) accept else reject // too many s read next char c reject // s after s 8.3 Deterministic Algorithms for CFL s Let L be the language of strings of the form ww. We know that L is not context-free. If L was a DCFL, then L would be also be a DCFL because that class is closed under complementation. This would contradict the fact that L is not even context-free.

77 Chapter 9 Turing Machines 9. Introduction 9... The idea is to repeatedly cross off one a, one b and one c.. If the input is empty, accept. 2. Scan the input to verify that it is of the form a b c. If not, reject. 3. Return the head to the beginning of the memory. 4. Cross off the first a. 5. Move right to the first b and cross it off. If no b can be found, reject. 6. Move right to the first c and cross it off. If no c can be found, reject. 7. Repeat Steps 2 to 5 until all the a s have been crossed off. When that happens, scan right to verify that all other symbols have been crossed off. If so, accept. Otherwise, reject The idea is to first find the middle of the string and then proceed as we did in this section for the language {w#w}. In what follows, when we

78 7 CHAPTER 9. TURING MACHINES mark a symbol with an L, we change it into either L or L. Similarly for marking with an R.. If the input is empty, accept. 2. Mark the first unmarked symbol with an L. 3. Move right to the last unmarked symbol. If none can be found, reject (because the input is of odd length). Otherwise, mark it with an R and move left. 4. Repeat Steps 2 and 3 until all the symbols have been marked. The input is now of the form uv where u = v, all the symbols of u are marked with an L and all the symbols of v are marked with an R. 5. Verify that u = v by following Steps 2 to 5 of the TM for the language {w#w}.

79 9.2. FORMAL DEFINITION Formal Definition We will cross off an a by replacing it with an x. For b and c, we will use y and z, respectively. Missing transitions go to the rejecting state. x R a,y R b,z R a x, R b y, R c z, L q q q 2 q 3 y R z,b,y,a L R q 4 y,z R R q accept 9.3 Variations on the Basic Turing Machine Suppose that M is a Turing machine with doubly infinite memory. We construct a basic Turing machine M that simulates M as follows.

80 72 CHAPTER 9. TURING MACHINES. Let w be the input string. Shift w one position to the right. Place a # before and after w so the tape contains #w#. 2. Move the head to the first symbol of w and run M. 3. Whenever M moves to the rightmost #, replace it with a blank and write a # in the next position. Return to the blank and continue running M. 4. Whenever M moves to the leftmost #, shift the entire contents of the memory (up to the rightmost #) one position to the right. Write a # and a blank in the first two positions, put the head on that blank and continue running M. 5. Repeat Steps 2 to 4 until M halts. Accept if M accepts. Otherwise, reject Suppose that L and L 2 are decidable languages. Let M and M 2 be TM s that decide these languages. Here s a TM that decides L :. Run M on the input. 2. If M accepts, reject. If M rejects, accept. Here s a TM that decides L L 2 :. Copy the input to a second tape. 2. Run M on the first tape. 3. If M accepts, accept. 4. Otherwise, run M 2 on the second tape. 5. If M 2 accepts, accept. Otherwise, reject,

81 9.3. VARIATIONS ON THE BASIC TURING MACHINE Here s a TM that decides L L 2 :. Copy the input to a second tape. 2. Run M on the first tape. 3. If M rejects, reject. 4. Otherwise, run M 2 on the second tape. 5. If M 2 accepts, accept. Otherwise, reject, Here s a TM that decides L L 2 :. If the input is empty, run M on the first tape and M 2 on a blank second tape. If both accept, accept. Otherwise, reject. 2. Mark the first symbol of the input. (With an underline, for example.) 3. Copy the beginning of the input, up to but not including the marked symbol, to a second tape. Copy the rest of the input to a third tape. 4. Run M on the second tape and M 2 on the third tape. 5. If both accept, accept. 6. Otherwise, move the mark to the next symbol of the input. 7. While the mark has not reached a blank space, repeat Steps 3 to Delete the mark from the first tape. Run M on the first tape and M 2 on a blank second tape. If both accept, accept. Otherwise, reject.. Verify that the input is of the form x# y#z where x, y and z are strings of digits of the same length. If not, reject. 2. Write a # in the first position of tapes 2, 3 and Copy x, y and z to tapes 2, 3 and 4, respectively.

82 74 CHAPTER 9. TURING MACHINES 4. Set the carry to. (Remember the carry with the states of the TM.) 5. Scan those numbers simultaneously from right to left, using the initial # to know when to stop. For each position, compute the sum n of the carry and the digits of x and y (using the transition function). If n mod is not equal to the digit of z, reject. Set the carry to n/. 6. If the carry is, accept. Otherwise, reject. 9.4 Equivalence with Programs Here s a TM for the copy instruction:. Move the memory head to location i. 2. Copy 32 bits starting at that memory location to an extra tape. 3. Move the memory head to location j. 4. Copy the 32 bits from the extra tape to the 32 bits that start at the current memory location. Here s a TM for the add instruction:. Move the memory head to location i. 2. Copy 32 bits starting at that memory location to a second extra tape. 3. Move the memory head to location j. 4. Add the 32 bits from the second extra tape to the 32 bits that start at the current memory location. (This can be done by adapting the solution to an exercise from the previous section.) Discard any leftover carry. Here s a TM for the jump-if instruction:. Move the memory head to location i.

83 9.4. EQUIVALENCE WITH PROGRAMS Scan the 32 bits that start at that memory location. If they re all, transition to the first state of the group of states that implement the other instruction. Otherwise, continue to the next instruction Suppose that L is a decidable language. Let M be a TM that decides this language. Here s a TM that decides L. (Note that this is a high-level description.) Let w be the input and let n be the length of w If w is empty, accept For each k in {, 2,..., n} For every partition of w into k substrings s[],..., s[k] Run M on each s[i] If M accepts all of them, accept Reject

84 76 CHAPTER 9. TURING MACHINES

85 Chapter Problems Concerning Formal Languages. Regular Languages... If M is a DFA with input alphabet Σ, then L(M) = Σ if and only if L(M) =. This leads to the following algorithm for ALL DFA :. Verify that the input string is of the form M where M is a DFA. If not, reject. 2. Construct a DFA M for the complement of L(M). (This can be done by simply switching the acceptance status of every state in M.) 3. Test if L(M ) = by using the emptiness algorithm. 4. Accept if that algorithm accepts. Otherwise, reject...2. The key observation here is that L(R ) L(R 2 ) if and only if L(R ) L(R 2 ) =. Since L(R ) L(R 2 ) = L(R ) L(R 2 ), this language is regular. This leads to the following algorithm for SUBSET REX :

86 78 CHAPTER. PROBLEMS CONCERNING FORMAL LANGUAGES. Verify that the input string is of the form R, R 2 where R and R 2 are regular expressions. If not, reject. 2. Construct a DFA M for the language L(R ) L(R 2 ). (This can be done by converting R and R 2 to DFA s and then combining these DFA s using the constructions for closure under complementation and intersection.) 3. Test if L(M) = by using the emptiness algorithm. 4. Accept if that algorithm accepts. Otherwise, reject...3. Let L ODD denote the language of strings of odd length. If M is a DFA, then M accepts at least one string of odd length if and only if L(M) L ODD. Since L ODD is regular, this leads to the following algorithm:. Verify that the input string is of the form M where M is a DFA. If not, reject. 2. Construct a DFA M for the language L(M) L ODD. (This can be done by combining M with a DFA for L ODD using the construction for closure under interesction.) 3. Test if L(M ) = by using the emptiness algorithm. 4. Reject if that algorithm accepts. Otherwise, accept..2 CFL s.2.. Here s an algorithm:. Verify that the input string is of the form G where G is a CFG. If not, reject. 2. Determine if G derives ɛ by using an algorithm for A CFG. 3. Accept if that algorithm accepts. Otherwise, reject.

87 .2. CFL S Let L ODD denote the language of strings of odd length. If G is a CFG, then G derives at least one string of odd length if and only if L(G) L ODD. This leads to the following algorithm:. Verify that the input string is of the form G where G is a CFG. If not, reject. 2. Construct a CFG G for the language L(G) L ODD. (This can be done by converting G into a PDA, combining it with a DFA for L ODD as outlined in Section 8.2, and converting the resulting PDA into a CFG.) 3. Test if L(G ) = by using the emptiness algorithm. 4. Reject if that algorithm accepts. Otherwise, accept.

88 8 CHAPTER. PROBLEMS CONCERNING FORMAL LANGUAGES

89 Chapter Undecidability. An Unrecognizable Language... Suppose, by contradiction, that L is recognized by some Turing machine M. In other words, for every string w, M accepts w if and only if w L. In particular, M accepts M if and only if M L But the definition of L tells us that M L if and only if M does not accept M This is a contradiction. Therefore, M cannot exist and L is not recognizable..2 Natural Undecidable Languages.2.. Here s a Turing machine that recognizes D:

90 82 CHAPTER. UNDECIDABILITY. Let w be the input string. Find i such that w = s i. 2. Generate the encoding of machine M i. 3. Simulate M i on s i. 4. If M accepts, accept. Otherwise, reject..3 Reducibility and Additional Examples.3.. Suppose that algorithm R decides BUMPS_OFF_LEFT TM. We use this algorithm to design an algorithm S for the acceptance problem:. Verify that the input string is of the form M, w where M is a Turing machine and w is a string over the input alphabet of M. If not, reject. 2. Without loss of generality, suppose that # is a symbol not in the tape alphabet of M. (Otherwise, pick some other symbol.) Construct the following Turing machine M : (a) Let x be the input string. Shift x one position to the right. Place a # before x so the tape contains #x. (b) Move the head to the first symbol of x and run M. (c) Whenever M moves the head to the #, move the head back one position to the right. (d) If M accepts, move the head to the # and move left again. 3. Run R on M, w. 4. If R accepts, accept. Otherwise, reject. To prove that S decides A TM, first suppose that M accepts w. Then when M runs on w, it attempts to move left from the first position of its tape (where the # is). This implies that R accepts M, w and that S accepts M, w, which is what we want.

91 .3. REDUCIBILITY AND ADDITIONAL EXAMPLES 83 Second, suppose that M does not accept w. Then when M runs on w, it never attempts to move left from the first position of its tape. This implies that R rejects M, w and that S rejects M, w. Therefore, S decides A TM. Since A TM is undecidable, this is a contradiction. Therefore, R does not exist and BUMPS_OFF_LEFT TM is undecidable Suppose that algorithm R decides ENTERS_STATE TM. We use this algorithm to design an algorithm S for the acceptance problem:. Verify that the input string is of the form M, w where M is a Turing machine and w is a string over the input alphabet of M. If not, reject. 2. Run R on M, w, q accept, where q accept is the accepting state of M. 3. If R accepts, accept. Otherwise, reject. It s easy to see that S decides A TM because M accepts w if and only if M enters its accepting state while running on w. Since A TM is undecidable, this is a contradiction. Therefore, R does not exist and ENTERS_STATE TM is undecidable Suppose that algorithm R decides ACCEPTSɛ TM. We use this algorithm to design an algorithm S for the acceptance problem:. Verify that the input string is of the form M, w where M is a Turing machine and w is a string over the input alphabet of M. If not, reject. 2. Construct the following Turing machine M : (a) Let x be the input string. If x ɛ, reject. (b) Run M on w. (c) If M accepts, accept. Otherwise, reject. 3. Run R on M. 4. If R accepts, accept. Otherwise, reject.

92 84 CHAPTER. UNDECIDABILITY To prove that S decides A TM, first suppose that M accepts w. Then L(M ) = {ɛ}, which implies that R accepts M and that S accepts M, w, which is what we want. On the other hand, suppose that M does not accept w. Then L(M ) =, which implies that R rejects M and that S rejects M, w, which is again what we want. Since A TM is undecidable, this is a contradiction. Therefore, R does not exist and ACCEPTSɛ TM is undecidable Suppose that algorithm R decides HALTS_ON_ALL TM. We use this algorithm to design an algorithm S for HALT TM :. Verify that the input string is of the form M, w where M is a Turing machine and w is a string over the input alphabet of M. If not, reject. 2. Construct the following Turing machine M : (a) Run M on w. (b) If M accepts, accept. Otherwise, reject. 3. Run R on M. 4. If R accepts, accept. Otherwise, reject. Note that M ignores its input and always runs M on w. This implies that if M halts on w, then M halts on every input, R accepts M and S accepts M, w. On the other hand, if M doesn t halt on w, then M doesn t halts on any input, R rejects M and S rejects M, w. This shows that S decides HALT TM. However, we know that HALT TM is undecidable. So this is a contradiction, which implies that R does not exist and HALTS_ON_ALL TM is undecidable Suppose that algorithm R decides EQ CFG. We use this algorithm to design an algorithm S for ALL CFG :

93 .3. REDUCIBILITY AND ADDITIONAL EXAMPLES 85. Verify that the input string is of the form G where G is a CFG. If not, reject. 2. Let Σ be the alphabet of G and construct a CFG G that generates Σ. 3. Run R on G, G. 4. If R accepts, accept. Otherwise, reject. This algorithm accepts G if and only if L(G) = L(G ) = Σ. Therefore, S decides ALL CFG, which contradicts the fact that ALL CFG. Therefore, R does not exist and EQ CFG is undecidable Yes, the proof of the theorem still works, as long as we make two changes. First, Step 4 in the description of S should be changed to the following: If R accepts, reject. Otherwise, accept. Second, the paragraph that follows the description of S as follows: Suppose that M accepts w. Then L(M ) = { n n n }, which implies that R rejects M and that S accepts M, w. On the other hand, suppose that M does not accept w. Then L(M ) =, which implies that R accepts M and that S rejects M, w. Therefore, S decides A TM Suppose that algorithm R decides INFINITE TM. We use this algorithm to design an algorithm S for A TM :. Verify that the input string is of the form M, w where M is a Turing machine and w is a string over the input alphabet of M. If not, reject. 2. Construct the following Turing machine M : (a) Run M on w.

### 6.045: Automata, Computability, and Complexity Or, Great Ideas in Theoretical Computer Science Spring, 2010. Class 4 Nancy Lynch

6.045: Automata, Computability, and Complexity Or, Great Ideas in Theoretical Computer Science Spring, 2010 Class 4 Nancy Lynch Today Two more models of computation: Nondeterministic Finite Automata (NFAs)

### Homework Five Solution CSE 355

Homework Five Solution CSE 355 Due: 17 April 01 Please note that there is more than one way to answer most of these questions. The following only represents a sample solution. Problem 1: Linz 8.1.13 and

### FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION REDUCIBILITY ( LECTURE 16) SLIDES FOR 15-453 SPRING 2011 1 / 20 THE LANDSCAPE OF THE CHOMSKY HIERARCHY ( LECTURE 16) SLIDES FOR 15-453 SPRING 2011 2 / 20 REDUCIBILITY

### CS154. Turing Machines. Turing Machine. Turing Machines versus DFAs FINITE STATE CONTROL AI N P U T INFINITE TAPE. read write move.

CS54 Turing Machines Turing Machine q 0 AI N P U T IN TAPE read write move read write move Language = {0} q This Turing machine recognizes the language {0} Turing Machines versus DFAs TM can both write

### Formal Languages and Automata Theory - Regular Expressions and Finite Automata -

Formal Languages and Automata Theory - Regular Expressions and Finite Automata - Samarjit Chakraborty Computer Engineering and Networks Laboratory Swiss Federal Institute of Technology (ETH) Zürich March

### Automata and Languages

Automata and Languages Computational Models: An idealized mathematical model of a computer. A computational model may be accurate in some ways but not in others. We shall be defining increasingly powerful

### Theory of Computation Prof. Kamala Krithivasan Department of Computer Science and Engineering Indian Institute of Technology, Madras

Theory of Computation Prof. Kamala Krithivasan Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture No. # 31 Recursive Sets, Recursively Innumerable Sets, Encoding

### Chapter 2. Finite Automata. 2.1 The Basic Model

Chapter 2 Finite Automata 2.1 The Basic Model Finite automata model very simple computational devices or processes. These devices have a constant amount of memory and process their input in an online manner.

### Pushdown automata. Informatics 2A: Lecture 9. Alex Simpson. 3 October, 2014. School of Informatics University of Edinburgh als@inf.ed.ac.

Pushdown automata Informatics 2A: Lecture 9 Alex Simpson School of Informatics University of Edinburgh als@inf.ed.ac.uk 3 October, 2014 1 / 17 Recap of lecture 8 Context-free languages are defined by context-free

### Turing Machines: An Introduction

CIT 596 Theory of Computation 1 We have seen several abstract models of computing devices: Deterministic Finite Automata, Nondeterministic Finite Automata, Nondeterministic Finite Automata with ɛ-transitions,

### CS 341 Homework 9 Languages That Are and Are Not Regular

CS 341 Homework 9 Languages That Are and Are Not Regular 1. Show that the following are not regular. (a) L = {ww R : w {a, b}*} (b) L = {ww : w {a, b}*} (c) L = {ww' : w {a, b}*}, where w' stands for w

### Theory of Computation

Theory of Computation For Computer Science & Information Technology By www.thegateacademy.com Syllabus Syllabus for Theory of Computation Regular Expressions and Finite Automata, Context-Free Grammar s

### CSE 135: Introduction to Theory of Computation Decidability and Recognizability

CSE 135: Introduction to Theory of Computation Decidability and Recognizability Sungjin Im University of California, Merced 04-28, 30-2014 High-Level Descriptions of Computation Instead of giving a Turing

### Reading 13 : Finite State Automata and Regular Expressions

CS/Math 24: Introduction to Discrete Mathematics Fall 25 Reading 3 : Finite State Automata and Regular Expressions Instructors: Beck Hasti, Gautam Prakriya In this reading we study a mathematical model

### Please note that there is more than one way to answer most of these questions. The following only represents a sample solution.

HOMEWORK THREE SOLUTION CSE 355 DUE: 10 MARCH 2011 Please note that there is more than one way to answer most of these questions. The following only represents a sample solution. (1) 2.4 and 2.5 (b),(c),(e),(f):

### Computing Functions with Turing Machines

CS 30 - Lecture 20 Combining Turing Machines and Turing s Thesis Fall 2008 Review Languages and Grammars Alphabets, strings, languages Regular Languages Deterministic Finite and Nondeterministic Automata

### Finite Automata and Formal Languages

Finite Automata and Formal Languages TMV026/DIT321 LP4 2011 Lecture 14 May 19th 2011 Overview of today s lecture: Turing Machines Push-down Automata Overview of the Course Undecidable and Intractable Problems

### 3515ICT Theory of Computation Turing Machines

Griffith University 3515ICT Theory of Computation Turing Machines (Based loosely on slides by Harald Søndergaard of The University of Melbourne) 9-0 Overview Turing machines: a general model of computation

### (IALC, Chapters 8 and 9) Introduction to Turing s life, Turing machines, universal machines, unsolvable problems.

3130CIT: Theory of Computation Turing machines and undecidability (IALC, Chapters 8 and 9) Introduction to Turing s life, Turing machines, universal machines, unsolvable problems. An undecidable problem

### CS 3719 (Theory of Computation and Algorithms) Lecture 4

CS 3719 (Theory of Computation and Algorithms) Lecture 4 Antonina Kolokolova January 18, 2012 1 Undecidable languages 1.1 Church-Turing thesis Let s recap how it all started. In 1990, Hilbert stated a

### the lemma. Keep in mind the following facts about regular languages:

CPS 2: Discrete Mathematics Instructor: Bruce Maggs Assignment Due: Wednesday September 2, 27 A Tool for Proving Irregularity (25 points) When proving that a language isn t regular, a tool that is often

### Pushdown Automata. place the input head on the leftmost input symbol. while symbol read = b and pile contains discs advance head remove disc from pile

Pushdown Automata In the last section we found that restricting the computational power of computing devices produced solvable decision problems for the class of sets accepted by finite automata. But along

### Regular Expressions and Automata using Haskell

Regular Expressions and Automata using Haskell Simon Thompson Computing Laboratory University of Kent at Canterbury January 2000 Contents 1 Introduction 2 2 Regular Expressions 2 3 Matching regular expressions

### The Halting Problem is Undecidable

185 Corollary G = { M, w w L(M) } is not Turing-recognizable. Proof. = ERR, where ERR is the easy to decide language: ERR = { x { 0, 1 }* x does not have a prefix that is a valid code for a Turing machine

### Automata Theory CS F-15 Undecidiability

Automata Theory CS411-2015F-15 Undecidiability David Galles Department of Computer Science University of San Francisco 15-0: Universal TM Turing Machines are Hard Wired Addition machine only adds 0 n 1

### A TM. Recall the A TM language: A TM = { M, w M is a TM and M accepts w.} is undecidable. Theorem: The language. p.2/?

p.1/? Reducibility We say that a problem Q reduces to problem P if we can use P to solve Q. In the context of decidability we have the following templates : If A reduces to B and B is decidable, then so

### Practice Problems for Final Exam: Solutions CS 341: Foundations of Computer Science II Prof. Marvin K. Nakayama

Practice Problems for Final Exam: Solutions CS 341: Foundations of Computer Science II Prof. Marvin K. Nakayama 1. Short answers: (a) Define the following terms and concepts: i. Union, intersection, set

### Computational Models Lecture 8, Spring 2009

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown Univ. p. 1 Computational Models Lecture 8, Spring 2009 Encoding of TMs Universal Turing Machines The Halting/Acceptance

### Homework Four Solution CSE 355

Homework Four Solution CSE 355 Due: 29 March 2012 Please note that there is more than one way to answer most of these questions. The following only represents a sample solution. Problem 1: Linz 5.1.23

### Automata and Formal Languages

Automata and Formal Languages Winter 2009-2010 Yacov Hel-Or 1 What this course is all about This course is about mathematical models of computation We ll study different machine models (finite automata,

### Model 2.4 Faculty member + student

Model 2.4 Faculty member + student Course syllabus for Formal languages and Automata Theory. Faculty member information: Name of faculty member responsible for the course Office Hours Office Number Email

### CHAPTER 3 Numbers and Numeral Systems

CHAPTER 3 Numbers and Numeral Systems Numbers play an important role in almost all areas of mathematics, not least in calculus. Virtually all calculus books contain a thorough description of the natural,

### Finite Automata. Reading: Chapter 2

Finite Automata Reading: Chapter 2 1 Finite Automaton (FA) Informally, a state diagram that comprehensively captures all possible states and transitions that a machine can take while responding to a stream

### SRM UNIVERSITY FACULTY OF ENGINEERING & TECHNOLOGY SCHOOL OF COMPUTING DEPARTMENT OF SOFTWARE ENGINEERING COURSE PLAN

Course Code : CS0355 SRM UNIVERSITY FACULTY OF ENGINEERING & TECHNOLOGY SCHOOL OF COMPUTING DEPARTMENT OF SOFTWARE ENGINEERING COURSE PLAN Course Title : THEORY OF COMPUTATION Semester : VI Course : June

### 1 Definition of a Turing machine

Introduction to Algorithms Notes on Turing Machines CS 4820, Spring 2012 April 2-16, 2012 1 Definition of a Turing machine Turing machines are an abstract model of computation. They provide a precise,

### Deterministic Push-Down Store Automata

Deterministic Push-Down tore Automata 1 Context-Free Languages A B C D... A w 0 w 1 D...E The languagea n b n : a b ab 2 Finite-tate Automata 3 Pushdown Automata Pushdown automata (pda s) is an fsa with

University of Virginia - cs3102: Theory of Computation Spring 2010 Final Exam - Comments Problem 1: Definitions. (Average 7.2 / 10) For each term, provide a clear, concise, and precise definition from

### Computability Theory

CSC 438F/2404F Notes (S. Cook and T. Pitassi) Fall, 2014 Computability Theory This section is partly inspired by the material in A Course in Mathematical Logic by Bell and Machover, Chap 6, sections 1-10.

### Context-Free Grammars

Context-Free Grammars Describing Languages We've seen two models for the regular languages: Automata accept precisely the strings in the language. Regular expressions describe precisely the strings in

### Chapter 7 Uncomputability

Chapter 7 Uncomputability 190 7.1 Introduction Undecidability of concrete problems. First undecidable problem obtained by diagonalisation. Other undecidable problems obtained by means of the reduction

### Honors Class (Foundations of) Informatics. Tom Verhoeff. Department of Mathematics & Computer Science Software Engineering & Technology

Honors Class (Foundations of) Informatics Tom Verhoeff Department of Mathematics & Computer Science Software Engineering & Technology www.win.tue.nl/~wstomv/edu/hci c 2011, T. Verhoeff @ TUE.NL 1/20 Information

### INSTITUTE OF AERONAUTICAL ENGINEERING

INSTITUTE OF AERONAUTICAL ENGINEERING DUNDIGAL 500 043, HYDERABAD COMPUTER SCIENCE AND ENGINEERING TUTORIAL QUESTION BANK Name : FORMAL LANGUAGES AND AUTOMATA THEORY Code : A40509 Class : II B. Tech II

### Lecture 2: The Complexity of Some Problems

IAS/PCMI Summer Session 2000 Clay Mathematics Undergraduate Program Basic Course on Computational Complexity Lecture 2: The Complexity of Some Problems David Mix Barrington and Alexis Maciel July 18, 2000

### Automata on Infinite Words and Trees

Automata on Infinite Words and Trees Course notes for the course Automata on Infinite Words and Trees given by Dr. Meghyn Bienvenu at Universität Bremen in the 2009-2010 winter semester Last modified:

### Homework Three Solution CSE 355

Homework Three Solution CSE 355 Due: 06 March 2012 Please note that there is more than one way to answer most of these questions. The following only represents a sample solution. Problem 1: Linz 4.1.13

### Scanner. tokens scanner parser IR. source code. errors

Scanner source code tokens scanner parser IR errors maps characters into tokens the basic unit of syntax x = x + y; becomes = + ; character string value for a token is a lexeme

### Deterministic Finite Automata

1 Deterministic Finite Automata Definition: A deterministic finite automaton (DFA) consists of 1. a finite set of states (often denoted Q) 2. a finite set Σ of symbols (alphabet) 3. a transition function

### C H A P T E R Regular Expressions regular expression

7 CHAPTER Regular Expressions Most programmers and other power-users of computer systems have used tools that match text patterns. You may have used a Web search engine with a pattern like travel cancun

### Compiler Construction

Compiler Construction Regular expressions Scanning Görel Hedin Reviderad 2013 01 23.a 2013 Compiler Construction 2013 F02-1 Compiler overview source code lexical analysis tokens intermediate code generation

### Introduction to Automata Theory. Reading: Chapter 1

Introduction to Automata Theory Reading: Chapter 1 1 What is Automata Theory? Study of abstract computing devices, or machines Automaton = an abstract computing device Note: A device need not even be a

### Finite Automata. Reading: Chapter 2

Finite Automata Reading: Chapter 2 1 Finite Automata Informally, a state machine that comprehensively captures all possible states and transitions that a machine can take while responding to a stream (or

### Computing basics. Ruurd Kuiper

Computing basics Ruurd Kuiper October 29, 2009 Overview (cf Schaum Chapter 1) Basic computing science is about using computers to do things for us. These things amount to processing data. The way a computer

### We give a basic overview of the mathematical background required for this course.

1 Background We give a basic overview of the mathematical background required for this course. 1.1 Set Theory We introduce some concepts from naive set theory (as opposed to axiomatic set theory). The

### Notes on Complexity Theory Last updated: August, 2011. Lecture 1

Notes on Complexity Theory Last updated: August, 2011 Jonathan Katz Lecture 1 1 Turing Machines I assume that most students have encountered Turing machines before. (Students who have not may want to look

### Regular Expressions with Nested Levels of Back Referencing Form a Hierarchy

Regular Expressions with Nested Levels of Back Referencing Form a Hierarchy Kim S. Larsen Odense University Abstract For many years, regular expressions with back referencing have been used in a variety

### 6.080/6.089 GITCS Feb 12, 2008. Lecture 3

6.8/6.89 GITCS Feb 2, 28 Lecturer: Scott Aaronson Lecture 3 Scribe: Adam Rogal Administrivia. Scribe notes The purpose of scribe notes is to transcribe our lectures. Although I have formal notes of my

### Definition: String concatenation. Definition: String. Definition: Language (cont.) Definition: Language

CMSC 330: Organization of Programming Languages Regular Expressions and Finite Automata Introduction That s it for the basics of Ruby If you need other material for your project, come to office hours or

### COLORED GRAPHS AND THEIR PROPERTIES

COLORED GRAPHS AND THEIR PROPERTIES BEN STEVENS 1. Introduction This paper is concerned with the upper bound on the chromatic number for graphs of maximum vertex degree under three different sets of coloring

### (Refer Slide Time: 1:41)

Discrete Mathematical Structures Dr. Kamala Krithivasan Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture # 10 Sets Today we shall learn about sets. You must

### Implementation of Recursively Enumerable Languages using Universal Turing Machine in JFLAP

International Journal of Information and Computation Technology. ISSN 0974-2239 Volume 4, Number 1 (2014), pp. 79-84 International Research Publications House http://www. irphouse.com /ijict.htm Implementation

### Context-Free Grammars (CFG)

Context-Free Grammars (CFG) SITE : http://www.sir.blois.univ-tours.fr/ mirian/ Automata Theory, Languages and Computation - Mírian Halfeld-Ferrari p. 1/2 An informal example Language of palindromes: L

### MAT2400 Analysis I. A brief introduction to proofs, sets, and functions

MAT2400 Analysis I A brief introduction to proofs, sets, and functions In Analysis I there is a lot of manipulations with sets and functions. It is probably also the first course where you have to take

### Turing Machines, Part I

Turing Machines, Part I Languages The \$64,000 Question What is a language? What is a class of languages? Computer Science Theory 2 1 Now our picture looks like Context Free Languages Deterministic Context

### Increasing Interaction and Support in the Formal Languages and Automata Theory Course

Increasing Interaction and Support in the Formal Languages and Automata Theory Course [Extended Abstract] Susan H. Rodger rodger@cs.duke.edu Jinghui Lim Stephen Reading ABSTRACT The introduction of educational

### Regular Languages and Finite State Machines

Regular Languages and Finite State Machines Plan for the Day: Mathematical preliminaries - some review One application formal definition of finite automata Examples 1 Sets A set is an unordered collection

### Introduction to Turing Machines

Automata Theory, Languages and Computation - Mírian Halfeld-Ferrari p. 1/2 Introduction to Turing Machines SITE : http://www.sir.blois.univ-tours.fr/ mirian/ Automata Theory, Languages and Computation

CS5236 Advanced Automata Theory Frank Stephan Semester I, Academic Year 2012-2013 Advanced Automata Theory is a lecture which will first review the basics of formal languages and automata theory and then

### Structural properties of oracle classes

Structural properties of oracle classes Stanislav Živný Computing Laboratory, University of Oxford, Wolfson Building, Parks Road, Oxford, OX1 3QD, UK Abstract Denote by C the class of oracles relative

### CS 103X: Discrete Structures Homework Assignment 3 Solutions

CS 103X: Discrete Structures Homework Assignment 3 s Exercise 1 (20 points). On well-ordering and induction: (a) Prove the induction principle from the well-ordering principle. (b) Prove the well-ordering

### CAs and Turing Machines. The Basis for Universal Computation

CAs and Turing Machines The Basis for Universal Computation What We Mean By Universal When we claim universal computation we mean that the CA is capable of calculating anything that could possibly be calculated*.

### This section demonstrates some different techniques of proving some general statements.

Section 4. Number Theory 4.. Introduction This section demonstrates some different techniques of proving some general statements. Examples: Prove that the sum of any two odd numbers is even. Firstly you

### Inf1A: Deterministic Finite State Machines

Lecture 2 InfA: Deterministic Finite State Machines 2. Introduction In this lecture we will focus a little more on deterministic Finite State Machines. Also, we will be mostly concerned with Finite State

### 6.080 / 6.089 Great Ideas in Theoretical Computer Science Spring 2008

MIT OpenCourseWare http://ocw.mit.edu 6.080 / 6.089 Great Ideas in Theoretical Computer Science Spring 2008 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

### Regular Expressions. Languages. Recall. A language is a set of strings made up of symbols from a given alphabet. Computer Science Theory 2

Regular Expressions Languages Recall. A language is a set of strings made up of symbols from a given alphabet. Computer Science Theory 2 1 String Recognition Machine Given a string and a definition of

### Lecture 2: Universality

CS 710: Complexity Theory 1/21/2010 Lecture 2: Universality Instructor: Dieter van Melkebeek Scribe: Tyson Williams In this lecture, we introduce the notion of a universal machine, develop efficient universal

### Overview of E0222: Automata and Computability

Overview of E0222: Automata and Computability Deepak D Souza Department of Computer Science and Automation Indian Institute of Science, Bangalore. August 3, 2011 What this course is about What we study

### (Refer Slide Time 1.50)

Discrete Mathematical Structures Dr. Kamala Krithivasan Department of Computer Science and Engineering Indian Institute of Technology, Madras Module -2 Lecture #11 Induction Today we shall consider proof

### Theory of Computation Chapter 2: Turing Machines

Theory of Computation Chapter 2: Turing Machines Guan-Shieng Huang Feb. 24, 2003 Feb. 19, 2006 0-0 Turing Machine δ K 0111000a 01bb 1 Definition of TMs A Turing Machine is a quadruple M = (K, Σ, δ, s),

### Genetic programming with regular expressions

Genetic programming with regular expressions Børge Svingen Chief Technology Officer, Open AdExchange bsvingen@openadex.com 2009-03-23 Pattern discovery Pattern discovery: Recognizing patterns that characterize

### Motivation. Automata = abstract computing devices. Turing studied Turing Machines (= computers) before there were any real computers

Motivation Automata = abstract computing devices Turing studied Turing Machines (= computers) before there were any real computers We will also look at simpler devices than Turing machines (Finite State

### Formal Grammars and Languages

Formal Grammars and Languages Tao Jiang Department of Computer Science McMaster University Hamilton, Ontario L8S 4K1, Canada Bala Ravikumar Department of Computer Science University of Rhode Island Kingston,

### I. GROUPS: BASIC DEFINITIONS AND EXAMPLES

I GROUPS: BASIC DEFINITIONS AND EXAMPLES Definition 1: An operation on a set G is a function : G G G Definition 2: A group is a set G which is equipped with an operation and a special element e G, called

### Memoization/Dynamic Programming. The String reconstruction problem. CS125 Lecture 5 Fall 2016

CS125 Lecture 5 Fall 2016 Memoization/Dynamic Programming Today s lecture discusses memoization, which is a method for speeding up algorithms based on recursion, by using additional memory to remember

### Introduction to Algorithms Review information for Prelim 1 CS 4820, Spring 2010 Distributed Wednesday, February 24

Introduction to Algorithms Review information for Prelim 1 CS 4820, Spring 2010 Distributed Wednesday, February 24 The final exam will cover seven topics. 1. greedy algorithms 2. divide-and-conquer algorithms

### A Formalization of the Turing Test Evgeny Chutchev

A Formalization of the Turing Test Evgeny Chutchev 1. Introduction The Turing test was described by A. Turing in his paper [4] as follows: An interrogator questions both Turing machine and second participant

### MODULAR ARITHMETIC. a smallest member. It is equivalent to the Principle of Mathematical Induction.

MODULAR ARITHMETIC 1 Working With Integers The usual arithmetic operations of addition, subtraction and multiplication can be performed on integers, and the result is always another integer Division, on

### COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

Binary numbers The reason humans represent numbers using decimal (the ten digits from 0,1,... 9) is that we have ten fingers. There is no other reason than that. There is nothing special otherwise about

### Properties of Regular Languages

Properties of Regular Languages SITE : http://www.info.blois.univ-tours.fr/ mirian/ Automata Theory, Languages and Computation - Mírian Halfeld-Ferrari p. 1/3 Algebraic Laws for Regular Expressions Two

### 24 Uses of Turing Machines

Formal Language and Automata Theory: CS2004 24 Uses of Turing Machines 24 Introduction We have previously covered the application of Turing Machine as a recognizer and decider In this lecture we will discuss

### WRITING PROOFS. Christopher Heil Georgia Institute of Technology

WRITING PROOFS Christopher Heil Georgia Institute of Technology A theorem is just a statement of fact A proof of the theorem is a logical explanation of why the theorem is true Many theorems have this

### Mathematical Induction

Mathematical Induction (Handout March 8, 01) The Principle of Mathematical Induction provides a means to prove infinitely many statements all at once The principle is logical rather than strictly mathematical,

CS787: Advanced Algorithms Lecture 14: Online algorithms We now shift focus to a different kind of algorithmic problem where we need to perform some optimization without knowing the input in advance. Algorithms

### (Refer Slide Time: 2:03)

Control Engineering Prof. Madan Gopal Department of Electrical Engineering Indian Institute of Technology, Delhi Lecture - 11 Models of Industrial Control Devices and Systems (Contd.) Last time we were

### Turing Machine and the Conceptual Problems of Computational Theory

Research Inventy: International Journal of Engineering And Science Vol.4, Issue 4 (April 204), PP 53-60 Issn (e): 2278-472, Issn (p):239-6483, www.researchinventy.com Turing Machine and the Conceptual

### ELEMENTARY NUMBER THEORY AND METHODS OF PROOF

CHAPTER 4 ELEMENTARY NUMBER THEORY AND METHODS OF PROOF Copyright Cengage Learning. All rights reserved. SECTION 4.4 Direct Proof and Counterexample IV: Division into Cases and the Quotient-Remainder Theorem

### Classical Information and Bits

p. 1/24 Classical Information and Bits The simplest variable that can carry information is the bit, which can take only two values, 0 or 1. Any ensemble, description, or set of discrete values can be quantified

### Relations Graphical View

Relations Slides by Christopher M. Bourke Instructor: Berthe Y. Choueiry Introduction Recall that a relation between elements of two sets is a subset of their Cartesian product (of ordered pairs). A binary

### Squares and Square Roots

SQUARES AND SQUARE ROOTS 89 Squares and Square Roots CHAPTER 6 6.1 Introduction You know that the area of a square = side side (where side means the length of a side ). Study the following table. Side