Homework 3

CMU 15-251
Spring 2015
Homework 3 — Writing session on Wednesday February 4
On this first page of the homework, we make some definitions that may be referred to in the
subsequent problems. Let M be a Turing machine where Q is the state set, t is the blank symbol,
and Γ is the tape alphabet.1 To understand how M ’s computation proceeds we generally need
to keep track of three things: (i) the state M is in; (ii) the contents of the tape; (iii) where the
tape head is. These three things are collectively known as the “configuration” of the TM. More
formally: a configuration for M is defined to be a string uqv ∈ (Γ ∪ Q)∗ , where u, v ∈ Γ∗ and q ∈ Q.
This represents that the tape has contents · · · tttuvttt · · · , the head is pointing at the leftmost
symbol of v, and the state is q. We say the configuration is accepting if q is M ’s accept state and
that it’s rejecting if q is M ’s reject state.
Technicality alert: We also have some technicalities: The string u may not start with t and
the string v may not end with t. This is so that the configuration is always unique. Also, if v = it means the head is pointing at the t immediately to the right of u.
For example, suppose M is the first TM shown in Lecture 5, with the input being aaba. In the
computation of M (aaba), the initial configuration is q0 aaba; here u = , q = q0 , and v = aaba.
The next configuration after that is qa aba. The final configuration for the computation M (aaba)
is qacc ttba; this is an “accepting” configuration. As another example, in Lecture 5’s machine for
deciding 0n 1n , when the input is 00001011, the configuration after two steps is #0qright 001011.
Suppose that M is computing and reaches a certain configuration α (which is not accepting or
rejecting). Knowing just this configuration and M ’s transition function δ, one can determine the
configuration β that M will reach at the next step of the computation. (You will be asked to make
this precise in Problem 1.) We write
α `M β
and say that “α yields β (in M )”. If it’s obvious what M we’re talking about, we just write α ` β.
To return to the first TM example from Lecture 5, we have for example
q0 aaba `M qa aba.
We can now formally define TM computation just like we did with DFA computation. Formally,
given an input x ∈ Σ∗ we say that M (x) halts if there exists a sequence of configurations (called
the computation trace) α0 , α1 , . . . , αT such that:
(i) α0 = q0 x, where q0 is M ’s initial state;
(ii) αt `M αt+1 for all t = 0, 1, 2, . . . , T − 1;
(iii) αT is either an accepting configuration (in which case we say M (x) accepts) or a rejecting
configuration (in which case we say M (x) rejects).
Otherwise, we say M (x) loops.
1
Supernerd note: we will always assume Q and Γ are disjoint sets.
1
1. (SOLO)
(a) Suppose M = (Q, Σ, Γ, δ, q0 , qaccept , qreject ) is a Turing machine. We want you to formally
define α `M β. More precisely, suppose α = uqv, where q ∈ Q\{qaccept , qreject }. Precisely
describe β. (Hints: You will want to introduce some notation for the first symbol of v,
if it exists. You’ll probably want to divide into two cases based on whether the head
is going to go left or right. Finally, you may want to use the functions LTrim and
RTrim, defined on strings z ∈ Γ∗ , where LTrim(z) is z with any leading t’s deleted, and
RTrim(z) is z with any trailing t’s deleted.)
(b) Let M denote the below Turing machine, which has input alphabet Σ = {a} and tape
alphabet Γ = {a, t}.
We want you to prove that M accepts the empty string using the definition on the
previous page. More precisely, we want you to write out the computation trace
α0 `M α1 `M · · · `M αT
for M (). You do not have to justify it; just make sure to get T and α0 , . . . , αT correct!
2. (SOLO) For each language below, draw a TM that decides the language. As usual, you can
use any finite tape alphabet Γ containing Σ and t; just be sure to specify what it is. In
addition, explain briefly in prose how the TM works, and the “meaning” of each state.
(a) L = {an : n is a nonnegative integer power of 2}, where Σ = {a}.
(b) L = {x ∈ {a, b}∗ : x has the same number of a’s and b’s}.
3. (SOLO) For each set below, determine if it is countable or not. Prove your answers.
(a) The set of all finite subsets of {0, 1}∗ .
(b) S = {a1 a2 a3 . . . ∈ {0, 1}∞ | ∀n ≥ 1 the string a1 . . . an contains more 1’s than 0’s.}.
(c) Σ∗ , where Σ is an alphabet that is allowed to be countably infinite (e.g., Σ = N).
4. (GROUP) Let T be an uncountable subset of positive real numbers. Let N be a positive
real number. Show that there exists a finite subset S ⊆ T such that the numbers in S add
up to at least N .
2
5. (GROUP) Determine whether the following languages are decidable or not. You may “use
the Church–Turing Thesis” when proving your answers.
(a) T = {hM i | Turing machine M accepts finitely many strings}.
(b) U = {hM i | Turing machine M contains a pointless state}. Here a Turing machine state
is said to be “pointless” if it is never reached for any input.
(c) V = {(hM i, w) | M visits more than 251 distinct cells on its tape when processing w}.
6. (GROUP) Suppose we change the definition of a TM so that the transition function has the
form
δ : Q × Γ → Q × Γ × {R, S},
where the meaning of S is “stay”. That is, at each step, the tape head can move one cell to
the right or stay in the same position. Suppose M is a TM of this new kind, and suppose
also that M is a decider. Show that L(M ) is a regular language.
7. (OPEN) The G programming language works as following. There are always three “registers”, called a, b, c, each of which can hold any natural number. A program in G consists
of a finite sequence of n ≥ 1 instructions, S0 , S1 , . . . , Sn−1 . (Since there is going to be a
GOTO within each instruction, it might be better to think of them simply as “states”.) Each
instruction can be one of 11 types:
(i) a++ and goto Sj
(increments register a by 1)
(ii) a-- and goto Sj
(decrements register a by 1 if nonzero; else leaves a = 0)
(iii) if a = 0 then goto Sj else goto Sk
(iv) b++ and goto Sj
(v) b-- and goto Sj
(vi) if b = 0 then goto Sj else goto Sk
(vii) c++ and goto Sj
(viii) c-- and goto Sj
(ix) if c = 0 then goto Sj else goto Sk
(x) halt & accept
(xi) halt & reject
The input to a G program is a natural number, which always goes into register a; the other
registers are always initialized to 0. Computation always starts with S0 and proceeds in the
obvious way. Note that a G program on a given input may either accept, reject, or loop.
N
Brief interlude: Let’s define an “encoding function” E : {0, 1}∗ →
as follows:
E(x) = binvalue(1x) − 1, where binvalue(w) denotes the number whose binary expansion
is w. E.g., E(10) = 5, E(001) = 8, E() = 0, etc. It is not hard to see that E is a bijection; you may freely use this fact. Using this bijection, you can think of a G program as
taking strings in {0, 1}∗ as input rather than natural numbers.
3
Show that it is possible to simulate any Turing machine M (with input alphabet {0, 1} and
tape alphabet {0, 1, t}) by a G program P . By “simulate” we mean that for all x ∈ Σ∗ ,
whether M (x) accepts, rejects, or loops should be the same as whether P (E(x)) accepts,
rejects, or loops.
As a warmup, try to do this in a version of the G language which allows four registers, or five
registers, or six registers.
Can you simulate any Turing machine in a version of G where only two registers are allowed?
If only one register is allowed?
4