## Practice Problems for Exam 1

### Turing Machines

1. Implement a Turing machine that, given an input number n in binary representation, increments n by 1.

2. Implement a Turing machine that decides the language
L = {ww^R | w belongs to Sigma*},
where w^R denotes "the reverse of w", and Sigma is an alphabet.

3. Consider a variant version of Turing machines that can insert and delete characters in and from their inputs.
1. Give a formal definition of these Insert-Delete Turing Machine "IDTM".
2. Show that IDTMs are equivalent to TMs. That is, IDTMs and TMs can simulate each other.

4. Construct the state diagram with transitions of a Turing machine that, given an input number n in binary representation, accepts n iff n is odd.

5. Implement a Turing machine that, given an input number n in binary representation, multiplies the number by 2.

### Decidable and Semi-decidable Languages

1. Let L be a decidable language. Show that there are infinitely many different Turing machines that decide L.

2. Show that FINITEcfg = {< A > | A is a CFG and L(A) is finite} is decidable.

3. Show that INFINITEcfg = {< A > | A is a CFG and L(A) is infinite} is decidable.

4. Show that MAQtm = {< M > | M is a TM} is decidable. That is, show that there is a TM K that accepts an input number n if n encodes a TM; and rejects n otherwise.

5. Show that, if a language L is semi-decidable, then there is an enumerator M that enumerates L without ever repeating an element of L.

6. Show that a language L is recursive iff there is a TM M that enumerates L in such a way that the strings in L are output by M in length-increasing fashion.

### Undecidable Languages

1. Show that ALLcfg = {< A > | A is a CFG and L(A) = Sigma*} is undecidable.

2. Show that INTERSECTIONcfg = {< A,B > | A and B are CFG's and the intersection of L(A) and L(B) is empty} is undecidable.

### Countable vs. Uncountable Sets

1. Show that the set MAQtm = {< M > | M is a TM} is countable.
2. Let Sigma be an alphabet. Show that the set of languages over the alphabet Sigma is uncountable.

### Primitive and MU Recursive Functions

Show that the following functions are PRIMITIVE recursive:
1. DIV(n,m) := "k, where k is the integer quotient of n divided by m."
2. SUMg(n) := "g(0) + g(1) + ... + g(n)", where g is primitive recursive.
3. PRODg(n) := "g(0) * g(1) * ... * g(n)", where g is primitive recursive.