# CMPSCI 601: Theory of Computation

### Actual (in-class) exam is Monday 31 March 2003

Solutions are in blue.

Directions: Each question is a statement that may be true or false. Please state whether it is true or false -- you will get five points for a correct boolean answer and there is no penalty for a wrong guess. Then justify your answer -- the remaining points will depend on the quality and validity of your justification. Problems with higher point values will tend to require longer justifications, but this will not always be the case.

Crib sheet: I will state some useful definitions after the questions -- these will also be available during the in-class exam.

Types of variables: Unless otherwise indicated, a variable A or B denotes a language, D denotes a DFA, G denotes a context-free grammar, M denotes a Turing machine, n denotes a number, and w denotes a string. Remember that N is the set of all numbers, which we may also think of as the set Sigma* of all strings.

• Question 1 (10): If A is r.e., and A is reducible to its own complement, then A is recursive.

This is TRUE. From the fact that A is reducible to A-bar, it follows that A-bar is also reducible to A. This is because if f is a total recursive function such that n is in A iff f(n) is in A-bar, it is immediate that for the same f, n is in A-bar iff f(n) is in A.

Since A-bar is reducible to the r.e. set A, A-bar is itself r.e., and because A is thus shown to be both r.e. and co-r.e., A is recursive.

• Question 2 (20): The set {M: L(M) &ne N and L(M) &ne &emptyset} is neither r.e. nor co-r.e.

This statement is TRUE. Call the given set B. We prove that both K and K-bar are reducible to B. Then since K is not co-r.e., B is not co-r.e., and since K-bar is not r.e., B is not r.e. either. The reductions closely mimic the two cases of the Rice-Myhill-Shapiro proof, one in lecture and the other on HW#3.

To reduce K to B, choose a machine M' such that M' is in B. The function f takes an input n and creates a machine Mf(n) as follows. Mf(n) takes input x, runs Mn on n, and then runs M' on x if that halts. So L(Mf(n)) is L(M') if n is in K and is empty otherwise. Thus n is in K iff f(n) is in B.

Reducing K-bar to B is the perhaps the most difficult task on this practice test. Kazu and I came up with two relatively simple constructions each in a short time, but neither is a obvious imitation of things we've seen.

• My construction of Mf(n): On input x, in parallel run Mn on n and run M' on x. Accept iff either one accepts. Then if n is in K L(Mf(n)) = N, and if not L(Mf(n)) is L(M'). So n is in K iff f(n) is not in B.
• Kazu's construction: On input x, if x is not equal to n accept, otherwise run Mn on n. If n is in K Mf(n) always accepts, but if n is not in K L(Mf(n)) = N - {n}, and thus f(n) is in B. Again, n is in K iff f(n) is not in B and we have reduced K-bar to B.

• Question 3 (10): The set {D: L(D) is empty} is recursive.

This is TRUE. The decision procedure for this language needs to look at the graph of the DFA D and decide whether there is any path from the start state to any final state, a series of graph-reachability questions that can certainly be answered by an always-halting TM.

• Question 4 (10): If A and B are both r.e., then A is reducible to B (A &le B).

This is FALSE. If A = K and B is recursive, then both sets are r.e. but we know A does not reduce to B because K is not recursive. Since there is an example where the premise is true but the conclusion is false, this is not a valid implication.

• Question 5 (15): The set {M: for all w: w in L(M) iff wR in L(M)} is recursive.

This is FALSE. One way to prove this is to quote the Rice-Myhill-Shapiro theorem. This language does have the property that if two machines M and M' are equivalent (if L(M) = L(M')), then either both are in it or neither is in it. There are examples of machines in it, such as those with empty L(M), and examples of machines not in it (for example, if L(M) = {01}). So the RMS theorem tells us this language is not recursive. Note that to get full credit for this argument, you must quote the theorem correctly and argue that all the hypotheses are satisfied -- this includes giving an example of a machine not in the language.

A direct proof is not much harder than this anyway. Let M' be a machine such that L(M) = {01}, so M' is not in the language. The empty-language machines are in this language. So given any number n, we can define Mf(n) to be the machine that on input x runs Mn on n and then runs M' on x. L(Mf(n)) is empty if n is not in K and equal to L(M') if n is in K, so f is a reduction from K to this language and thus this language is not recursive.

• Question 6 (15): The set FO-VALID, which is {&phi: &phi is true in all models of first-order logic} is recursive.

This is FALSE, because in fact FO-VALID is r.e.-complete. As I said in Lecture 15, this follows from our proofs in lecture that FO-VALID is equal to FO-THEOREM, and that FO-THEOREM is r.e.-complete. The key step in the latter proof is reducing K to FO-THEOREM by making f(n) a statement saying that it is provable from NT that there is a halting computation of Mn on input n.

• Question 7 (20): The formula "[forall x:(cube(x) implies small(x))] implies not[exists y:(cube(y) and medium(y))]" is true in all models of Tarski's World.

This is TRUE and is proved as follows using rules available in Fitch.

1. Assume "forall x: (cube(x) implies small(x))".
2. Let y be an arbitrary object.
3. Assume "cube(y)".
4. By forall-elimination from (1), get "cube(y) implies small(y)".
5. By MP from (3) and (4), get "small(y)".
6. By a TW size axiom, verifiable by AnaCon, get "forall z: not(small(z) and medium(z))".
7. By forall-elimination from (6), get "not(small(y) and medium(y))".
8. By boolean rules from (7), get "small(y) implies not(medium(y))".
9. By MP from (5) and (8), get "not(medium(y))".
10. By implies-intro from (3) through (9), get "cube(y) implies not(medium(y))".
11. By boolean rules from (10), get "not(cube(y) and medium(y))"
12. By forall-intro from (2) through (11), get "forall y: not(cube(y) and medium(y))".
13. By implies-intro from (1) through (12), declare victory.

### Crib Sheet:

• L(M) is the set of numbers n such that M halts on input n with output 1.
• L(D) is the set of strings w such that D running on w finishes in an accepting state.
• L(G) is the set of strings w such that w can be generated from G's start symbol according to G's rules.
• A language is r.e. if it is equal to L(M) for some Turing machine M.
• A language is recursive if it is equal to L(M) for some Turing machine M that always halts.
• A function f is total recursive if there is a Turing machine that always halts and gives output f(n) on any input n.
• A is reducible to B if there exists a total recursive function f such that for any n, n is in A iff f(n) is in B.
• A is r.e.-complete iff A is r.e. and for any language B, if B is r.e. then B is reducible to A.
• The language K = {n: n not in L(Mn} is r.e.-complete.
• The Bloop programming language is defined in terms of basic operations and bounded loops. The Floop programming language also has free loops.
• If w is any string, wR is w written backward.