CSE 555 MIDTERM EXAMINATION SOLUTIONS TAKE-HOME: OUT 02/21 NOON, DUE 02/25 NOON The completed test is to be submitted electronically to colbourn@asu.edu before the deadline, or time-stamped by the main office in CIDSE and placed in Prof. Colbourn s physical mailbox. Answer every question, whether or not you think your answer is complete or correct. You can use any materials desired, but this is an individual effort, so limit your discussions with fellow students, and under no circumstances should written work be shared. Part of the exercise of doing the questions is understanding the questions. Read each carefully so as not to waste time. All questions are equally weighted (but not necessarily equally difficult.) 1. Question 1. Consider the statement w x y z[(w + x = y) ((y = z) ((w + x z))]. We operate in the universe of natural numbers with two relations, equal and plus, having their natural interpretations. (a) When w, x, y, z are provided as input in binary, encoded in a 16-letter alphabet whose letters are the 2 4 binary vectors of length four, devise a DFA that accepts precisely when (w + x = y) ((y = z) ((w + x z)). Here is a DFA for a + b = c with inputs encoded as binary vectors of length 3 with the first bit from a, the second from b, and the third from c. Note that it has not reversed the language, so it is using borrows rather than carries. State Input 000 001 010 011 100 101 110 111 q 0 start, accept q 0 q b q d q 0 q d q 0 q d q d q b q d q d q b q d q d q 0 q 0 q b q d q d q d q d q d q d q d q d q d Many students now simplified the formula. I do not see how to do so unless you prove a rule of implication in the theory, or establish that the DFA is equivalent. Now I use this DFA to make one for (w + x = y) ((y = z) ((w + x z)), with inputs encoded as binary vectors of length four with the bits of w, x, y, and z in that order. I name the states as pqr where p indicates the state (0, b, d) of the DFA for w + x = y, q indicates the state (0, b, d) of the DFA for w + x = z, and r indicates the state (e, n) of the DFA for y = z. 1
2 TAKE-HOME: OUT 02/21 NOON, DUE 02/25 NOON State Input 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 00e 00e 0bn b0n bbe dde d0n 0dn 00e dde d0n 0dn 00e dde ddn ddn dde 0be 0de 0dn bdn bde dbe ddn 0bn 0de dde d0n 0dn 00e d0e dbn d0n dbe 0de 0de 0dn bdn bde dde ddn 0dn 0de dde ddn 0dn 0de dde ddn ddn dde b0e d0e dbn d0n dbe bde b0n ddn d0e dde d0n 0dn 00e 0de 0dn bdn bde bbe dde ddn ddn dde bbe bdn dbn dde dde d0n 0dn 00e 00e 0bn b0n bbe bde dde ddn ddn dde bde bdn ddn dde dde ddn 0dn 0de 0de 0dn bdn bde d0e d0e dbn d0n dbe dde d0n ddn d0e dde d0n ddn d0e dde ddn ddn dde dbe dde ddn ddn dde dbe ddn dbn dde dde d0n ddn d0e d0e dbn d0n dbe dde dde ddn ddn dde dde ddn ddn dde dde ddn ddn dde dde ddn ddn dde 00n 00n 0bn b0n bbn ddn d0n 0dn 00n ddn d0n 0dn 00n ddn ddn ddn ddn 0bn 0dn 0dn bdn bdn dbn ddn 0bn 0dn ddn d0n 0dn 00n d0n dbn d0n dbn 0dn 0dn 0dn bdn bdn ddn ddn 0dn 0dn ddn ddn 0dn 0dn ddn ddn ddn ddn b0n d0n dbn d0n dbn bdn b0n ddn d0n ddn d0n 0dn 00n 0dn 0dn bdn bdn bbn ddn ddn ddn ddn bbn bdn dbn ddn ddn d0n 0dn 00n 00n 0bn b0n bbn bdn ddn ddn ddn ddn bdn bdn ddn ddn ddn ddn 0dn 0dn 0dn 0dn bdn bdn d0n d0n dbn d0n dbn ddn d0n ddn d0n ddn d0n ddn d0n ddn ddn ddn ddn dbn ddn ddn ddn ddn dbn ddn dbn ddn ddn d0n ddn d0n d0n dbn d0n dbn ddn ddn ddn ddn ddn ddn ddn ddn ddn ddn ddn ddn ddn ddn ddn ddn ddn
CSE 555 MIDTERM EXAMINATION SOLUTIONS 3 The start state is 00e. To accept we must have (w+x = y) ((y = z) ((w+x z)) so we accept whenever we are in state 00e, 0bn, or 0dn. Having formed the DFA, we can apply DFA minimization to make it much simpler. In particular, once we are in a state pqr with p = d, we can never get to an accepting state, so we can collapse these six states into one state. Carrying through DFA minimization completely, we get the DFA: State Input 0000 0010 0100 0110 1000 1010 1100 1110 0001 0011 0101 0111 1001 1011 1101 1111 q 0 start, accept q 0 q b q d q 0 q d q 0 q d q d q b q d q d q b q d q d q 0 q 0 q b q d q d q d q d q d q d q d q d q d This should look familiar. I did not use any rules of implication in the theory (which I have not proved) to do this. (b) Transform the quantifications into nondeterminism and show the NFA produced for w x y z[(w + x = y) ((y = z) ((w + x z))]. Then state whether the statement is true or false, and why. I write ψ 3 = z[(w + x = y) ((y = z) ((w + x z))] as z [(w + x = y) ((y = z) ((w + x z))] to get a DFA for ψ 3, which looks very familiar! State Input 000 001 010 011 100 101 110 111 q 0 start, accept q 0 q b q d q 0 q d q 0 q d q d q b q d q d q b q d q d q 0 q 0 q b q d q d q d q d q d q d q d q d q d For ψ 2 = y[ψ 3 ], I make the NFA: I convert it to a DFA: State Input 00 01 10 11 ε s start 0, b, d 0 accept 0, b 0, d 0, d d b d b, d 0, d 0, b d d d d d State Input 00 01 10 11 c: 0b accept 0bd 0bd 0d 0d d: 0d accept 0bd 0d 0d d e: 0bd start, accept 0bd 0bd 0d 0bd f: d d d d d I write ψ 1 = x[ψ 2 ] as x [ψ 2 ] and form an NFA for x [ψ 2 ] as follows:
4 TAKE-HOME: OUT 02/21 NOON, DUE 02/25 NOON State Input 0 1 ε s start d,e d d,e d,f e e d,e f accept f f Now convert it to a DFA and complement: State Input 0 1 j: de start, accept de def k: def def def This is the DFA for ψ 1 = x[ψ 2 ]. Now write φ = ψ 0 = w[ψ 1 ] as w [ψ 1 ]. To make an NFA for w [ψ 1 ] first convert the complement of the DFA just given to an NFA: State Input [] ε s start j,k j j,k k accept k Now convert it to a DFA and complement the final states to get the DFA for φ: State Input [] jk start,accept jk This machine accepts every string including the the empty string, so the statement is true (and proved). 2. Question 2. FINITE LG = { G : the language generated by linear grammar G is finite}. Show that FINITE LG is decidable. Let the longest right hand side of a rule have n terminals in it, and suppose that there are m variables. The language is infinite if and only if it contains a string of length at least nm + 1 by the pigeonhole principle. So enumerate strings of length mn + 1 and for each check whether it is in the language (A CF G is decidable). If none is, accept; otherwise reject. Alternatively: Convert the grammar to Chomsky normal form. Now eliminate all variables that are not productive in that they can never produce a string of terminals, and eliminate all rules that contain them. Then eliminate all variables that can never be produced starting with S, and eliminate rules that contain them. Then check whether any variable is recursive (appears in a cycle). It does not work to simply check whether a grammar has a cycle in the variables, even if the grammar is in CNF. The grammar {S A, A B, B A} has a finite language. So does the grammar {S aa a, A ab, B aa}
CSE 555 MIDTERM EXAMINATION SOLUTIONS 5 3. Question 3. REGULAR T M = { M : the language recognized by Turing machine M is regular}. (a) Show that REGULAR T M is not decidable. Apply Rice s theorem. Or do the (b) part first and then draw the conclusion. (b) Determine whether REGULAR T M is co-turing recognizable, Turing-recognizable, or neither. Explain your answer carefully. We show that A T M m REGULAR T M, and that A T M m REGULAR T M, which will prove that it is neither. A T M m REGULAR T M : On input M, w : Form a TM R as follows: On input x: If x is of the form 0 n 1 n, accept. Otherwise run M on w and accept if M accepts w. Output R. Then R accepts a regular language if and only if M accepts w. A T M m REGULAR T M : On input M, w : Form a TM S as follows: On input x: If x is not of the form 0 n 1 n, reject. Otherwise run M on w and accept if M accepts w. Output S. Then S accepts a regular language if and only if M does not accept w. 4. Question 4. Show how to use the recursion theorem to produce two different Turing machines M and N so that when M is run on any input, it prints N, and when N is run on any input, it prints M. N = On input x: Obtain own description N. Form a TM M by behaves just like N but then moves the head to the left hand end of the tape before it halts. Erase tape and write M on the tape left to right, leaving the tape head on the last nonblank cell M = On input x: Obtain own description M. Form a TM N by behaves just like M but having written the configuration,
6 TAKE-HOME: OUT 02/21 NOON, DUE 02/25 NOON leaves the head on the last nonblank cell. Erase tape and write N on the tape left to right, then moving the tape head on the first cell One idea is to get the machine to add or subtract some useless operation, like moving the tape head as we have done above. 5. Question 5. We have focussed on deterministic Turing machines. (a) Justify this by showing that there is a computable function t : Σ Σ so that whenever M is a nondeterministic Turing machine, t( M ) = M where M is a deterministic Turing machine with L(M) = L(M ) (and if x does not properly encode a nondeterministic Turing machine, then t(x) does not properly encode a deterministic Turing machine). The gist of this is to argue that Sipser s Theorems 3.13 and 3.16 not only establish the equivalence, which is not enough for what we need, but also give algorithms for producing the equivalent deterministic TM. (b) Can you show that the language of encodings of nondeterministic Turing machines with minimal length descriptions is not recognizable? Explain. This is the same enumeration argument as for MIN T M.