Theory of Computation, Homework 3 Sample Solution 3.8 b.) The following machine M will do: M = "On input string : 1. Scan the tape and mark the first 1 which has not been marked. If no unmarked 1 is found, go to step 5. Otherwise, move the head back to the front of the tape. 2. Scan the tape and mark the first 0 which has not been marked. If no unmarked 0 is found, reject. 3. Move on to mark the next unmarked 0. If no such unmarked 0 is found, reject. 4. Move the head back to the front of the tape and go to step 1. 5. Move the head back to the front of the tape. Scan the tape to see if there is any unmarked 0 found. If yes, reject. Otherwise, accept. c.) This machine is identical to 3.8b) if we switch reject with accept. M = "On input string : 1. Scan the tape and mark the first 1 which has not been marked. If no unmarked 1 is found, go to step 5. Otherwise, move the head back to the front of the tape. 2. Scan the tape and mark the first 0 which has not been marked. If no unmarked 0 is found, accept. 3. Move on to mark the next unmarked 0. If no such unmarked 0 is found, accept. 4. Move the head back to the front of the tape and go to step 1. 5. Move the head back to the front of the tape. Scan the tape to see if there is any unmarked 0 found. If yes, accept. Otherwise, reject.
3.12 Let be a Turing machine with left reset and be an ordinary Turing machine. If can simulate all the operations that can perform, recognizes the class of Turingrecognizable language. Obviously, can simulate of without problems. How simulates of is described as follows. 1. overwrite with a marked 2. reset to the left-hand end 3. shift the whole tape one cell to the right but keep the mark in the same position 4. reset to the left-hand end 5. scan right to find the marked symbol; the next move will treat the marked symbol as a normal symbol. We assume the following during the shifting for Step 3: a. We use states to remember the symbol to be shifted right. b. The first symbol of the tape after the shift is a symbol not used by the original M. c. If the current symbol is c and the next symbol is the marked b, after the shifting, c becomes marked but b is not marked. d. The shifting stops when we see a blank symbol.
3.15 b.) Let and be two decidable languages and and be the corresponding TMs. The aim is to construct a TM based on and such that the concatenation is also decidable. Since a given input concatenation of strings and has finite possible partitions, a nondeterministic TM is chosen to simplifies the description. NTM On input 1. Nondeterministically split into and 2. run on and on 3. accept if both accepts and accepts ; reject otherwise Obviously, the NTM accepts an input iff there exists a split of such that accepts and accepts. Besides, eventually halts because and are both deciders. Therefore, is decidable since there exists an NTM which decides. c.) Let be a decidable language and be the corresponding TM. The aim is to construct a TM based on such that is also decidable. Since a given input has finite possible combinations of strings where and, a nondeterministic TM is chosen to simplify the description. NTM On input 1. accept if 2. if, nondeterministically split into, where is not empty. 3. run on for all i. 4. accept if accepts all, ; reject otherwise Obviously, the NTM accepts an input iff or there exists a combination of such that accepts. Besides, eventually halts because is a decider. Therefore, is decidable since there exists an NTM which decides.
d.) Let be a decidable language and be the corresponding TM. The aim is to construct a TM based on such that, the complement of, is also decidable. The resulting TM is described as follows. TM On input 1. run on 2. accept if rejects 3. reject if accepts Obviously, accepts an input iff rejects. Besides, eventually halts because is a decider. Therefore, is decidable since there exists a TM which decides. e.) Let and be two decidable languages and and be the corresponding TMs. The aim is to construct a TM based on and such that the intersection is also decidable. The resulting TM is described as follows. On input 4. run and on 1. accept if both and accepts ; reject otherwise Obviously, the NTM accepts an input iff is accepted by and. Besides, eventually halts because and are both deciders. Therefore, is decidable since there exists a TM which decides.
3.16 b.) Let and be two Turing-recognizable languages and and be the corresponding TMs. The aim is to construct a TM based on and such that the concatenation is also Turing-recognizable. Since a given input concatenation of strings and has finite possible partitions, a nondeterministic TM is chosen to simplify the description. NTM On input 1. Nondeterministically split into and 2. run on input 3. reject if halts and rejects 4. run on input 5. accept if accepts ; reject if halts and rejects Obviously, the NTM recognizes an input iff there exists a partition of such that accepts and accepts. However, may loop forever on some input because and are not deciders. Therefore, which recognizes. is Turing-recognizable since there exists an NTM c.) Let be a Turing-recognizable language and be the corresponding TM. The aim is to construct a TM based on such that is also Turing-recognizable. Since a given input has finite possible combinations of strings where,, a nondeterministic TM is chosen to simplify the description. NTM On input 1. accept if 2. if nondeterministically split into, where is not empty. 3. run on for all i. 4. accept if accepts all, ; 5. reject if halts and rejects for any Obviously, the NTM recognizes an input iff or there exists a combination of such that accepts. However, may loop forever on some input because is not a decider. Therefore, is Turing-recognizable since there exists an NTM which recognizes.
d.) Let and be two Turing-recognizable languages and and be the corresponding TMs. The aim is to construct a TM based on and such that the intersection is also Turing-recognizable. The resulting TM is described as follows. On input 1. run on 2. rejects if halts and rejects 3. run on 4. accept if accepts ; reject if halts and rejects Obviously, the TM recognizes an input iff is accepted by and then. However, may loop forever on some input because and both are not deciders. Therefore, is Turing-recognizable since there exists a TM which recognizes. 4.4 Since is just a special case of, it is possible to adapt TM S for as follows. TM S = "On input, where is a CFG and is an empty string: 1. Convert G to an equivalent grammar in Chomsky normal form. 2. If S -> is a production rule in Chomsky normal form, accept; if not, reject." 4.10 To decide is to determine if there exist strings generated by with lengths at least the pumping length. Let be a CFG for and design a TM that decides The construction of TM is as follows, deciding : TM = On input: < > 1. convert to Chomsky normal form 2. calculate the pumping length p = from, where is the number of variables in (in Chomsky normal form, each rule has 0 or two variables at the right, so the pumping length is that is computable) 3. accept if produces a string of length at least because the string can be pumped to generate infinitely other strings 4. otherwise, reject For step 3, it is decidable since it is possible to construct a DFA such that the regular language recognized by is the set of strings of lengths at least. Let be which is a CFL from Problem 2.18a and be the CFG of Then TM in Theorem 4.8 can decide. If TM accepts, produces no strings of lengths at least. If not, produces a string of length at least p.
4.12 If. Therefore, we can first construct two equivalent DFA and recognizing and and then run TM in theorem 4.5 to decide if the two DFA are equivalent. TM = "On input < >: 1. construct the equivalent NFA and for and 4.24 2. construct the equivalent DFA and for the and 3. construct a DFA, accepting. 4. run TM to decide if and are equivalent 5. accept if TM accepts; reject if TM rejects Let be a CFL containing all the palindromes, be the regular language accepted by and be. The goal is that is decidable iff the emptiness of is also decidable. Since is a CFL from Problem 2.18, its emptiness can be decided by TM in theorem 4.8. Let be the CFG of The decider is constructed as follows. TM = "On input where is a DFA accepting some palindrome: 1. Let be a CFL containing all the palindromes 2. Let be the regular language accepted by 3. derive the CFG for 4. run TM to decide 5. accept if TM accepts; reject if TM rejects.
4.28 Let us prove it by contradiction. Suppose that every decider is in A. Since A is Turingrecognizable, A is also enumerable. Let be the i th decider in A. We may construct the following decider as follows: On input, (1) decide the order number of, i.e, =, the index of be ; (2) accept if rejects; rejects if accepts. Apparently, is a decider as (1)-(2) halts. is different from any in A, which is a contradiction to the assumption that every decider is in A. To show that is different from any in A, let be the list of all the strings in an canonical order of string (length than dictionary order). Then can be derived by applying the diagonalization method as illustrated by the following table. The table below demonstrates an example. reject accept accept... accept accept accept... reject accept reject.................. accept reject accept...... Obviously, is different from any language decided by whose description appears in.