Chapter 20

Turing Machines

[16/94%]
Show
LaTeX
Problem 302

Construct a Turing machine that performs the following task: given an input consisting of one or more words w1Λ…Λwnw_{1} \Lambda \ldots \Lambda w_{n} over the alphabet Σ\Sigma (possibly n=1n=1), produce an output that doubles the last of the words: w1Λ…ΛwnΛwnw_{1} \Lambda \ldots \Lambda w_{n} \Lambda w_{n}.

?
Problem 303

Construct a Turing machine that compares two input words over the alphabet {a,b,c}\left\{ a, b, c\right\} lexicographically. It must compute the dictionary-order function:

f(x,y)={a, if x<yb, if x=yc, if y<x f(x, y)= \begin{cases} a, & \text{ if } x<y \\ b, & \text{ if } x=y \\ c, & \text{ if } y<x \end{cases}
?
Problem 304

Construct programs of Turing machines that compute the following word functions in the alphabet Σ={a,b,c}\Sigma =\left\{ a, b, c\right\}:

?
(a)

cyclic permutation of letters: f(xw)=wx,x∈Σf(x w)=w x, x \in \Sigma;

(b)

cyclic permutation of words: f(w1,…,wn)=(w2,…,wn,w1)f\left(w_{1}, \ldots , w_{n}\right)=\left(w_{2}, \ldots , w_{n}, w_{1}\right);

(c)

"reversal" of a sequence of words: f(w1,…,wn)=(wn,…,w1)f\left(w_{1}, \ldots , w_{n}\right)=\left(w_{n}, \ldots , w_{1}\right);

(d)

doubling each letter: f(x1…xn)=x1x1…xnxnf\left(x_{1} \ldots x_{n}\right)=x_{1} x_{1} \ldots x_{n} x_{n};

(e)

finding the image under the homomorphism φ:φ(a)=a,φ(b)=cb,φ(c)=ε\varphi : \varphi (a)=a, \varphi (b)=c b, \varphi (c)=\varepsilon;

(f)

removal of all single letters aa standing at even positions;

(g)

checking whether two words contain the same number of letters aa (the result equals 1 if the answer is "yes", 0 if "no");

(h)

checking whether a word is a palindrome (that is, symmetric);

(i)

checking whether the word contains two runs of letters aa of the same length;

(j)

checking whether the counts of letters a,ba, b and cc in the word form an increasing arithmetic progression.

Problem 305

Construct a Turing machine to convert the representation of a number from binary to unary, input alphabet {0,1}\left\{ 0,1\right\}.

?
Problem 306

Construct programs of one-way Turing machines that compute the following arithmetic functions in the unary system:

?
(a)

x+yx+y;

(b)

⌊x−y⌋\lfloor x-y\rfloor

(c)

xyx y

(d)

comparison x<yx<y;

(e)

exponentiation: xyx^{y};

(f)

square root: ⌊x⌋\lfloor \sqrt{x}\rfloor;

(g)

logarithm: ⌊log⁡2x⌋;\left\lfloor \log_{2} x\right\rfloor ;

(h)

integer division: ⌊x/y⌋\lfloor x / y\rfloor;

(i)

remainder: x mod yx \bmod y;

(j)

the function selecting the mm-th argument: idm,m\mathrm{id}_{m}, m — a predetermined constant.

Problem 307

Given Turing machines with a standard terminal configuration Mi\mathfrak {M}_{i}, each of which computes a word function fi(x)f_{i}(x) in time ti(x)t_{i}(x), i=1,…,ni=1, \ldots , n. Indicate how to construct, and estimate the running time of,

?
(a)

the machine M1;…;Mn\mathfrak {M}_{1} ; \ldots ; \mathfrak {M}_{n}, computing the function g1(x)=fn(…f1(x)…)g_{1}(x)=f_{n}\left(\ldots f_{1}(x) \ldots \right);

(b)

the machine par⁡(a,M1,…,Mn)\operatorname {par}\left(a, \mathfrak {M}_{1}, \ldots , \mathfrak {M}_{n}\right), computing the function

g2(x1ax2a…axn)=f1(x1)af2(x2)a…afn(xn); g_{2}\left(x_{1} a x_{2} a \ldots a x_{n}\right)=f_{1}\left(x_{1}\right) a f_{2}\left(x_{2}\right) a \ldots a f_{n}\left(x_{n}\right) ;
(c)

the machine if⁡(M1,M2,M3)\operatorname {if}\left(\mathfrak {M}_{1}, \mathfrak {M}_{2}, \mathfrak {M}_{3}\right), computing the function

g3(x)={M2(x), if M1(x) is nonempty, M3(x), if M1(x) is empty;  g_{3}(x)= \begin{cases} \mathfrak {M}_{2}(x), & \text{ if } \mathfrak {M}_{1}(x) \text{ is nonempty, } \\ \mathfrak {M}_{3}(x), & \text{ if } \mathfrak {M}_{1}(x) \text{ is empty; } \end{cases}
(d)

the machine while⁡(M1,M2)\operatorname {while}\left(\mathfrak {M}_{1}, \mathfrak {M}_{2}\right), computing the function g4(x)=xqg_{4}(x)=x_{q}, where qq is the smallest natural number for which M1(xq)\mathfrak {M}_{1}\left(x_{q}\right) is empty, with x0=xx_{0}=x and xj+1=M2(xj)x_{j+1}=\mathfrak {M}_{2}\left(x_{j}\right). Assume that ∣xj∣⩽L(x)\left|x_{j}\right| \leqslant L(x) and ti(xj)⩽Ti(x)t_{i}\left(x_{j}\right) \leqslant T_{i}(x).

Problem 308

Using the Turing machines from the previous problems, construct programs of Turing machines that compute the following functions:

?
(a)

f1(x,y)={x2y3, if x<y,⌊(x+y)/2⌋, otherwise; f_{1}(x, y)= \begin{cases} x^{2} y^{3}, & \text{ if } x<y, \\ \lfloor (x+y) / 2\rfloor , & \text{ otherwise; } \end{cases}

(b)

f2(x,y)={⌊x⌋, if x+1⩾y,2(x+y), otherwise; f_{2}(x, y)= \begin{cases} \lfloor \sqrt{x}\rfloor , & \text{ if } x+1 \geqslant y, \\ 2(x+y), & \text{ otherwise; } \end{cases}

(c)

f3(x,y)={⌊log⁡2(1+⌊x/y⌋)⌋, if x>2y,xy, otherwise; f_{3}(x, y)= \begin{cases} \left\lfloor \log_{2}(1+\lfloor x / y\rfloor )\right\rfloor , & \text{ if } x>2 y, \\ x y, & \text{ otherwise; } \end{cases}

(d)

f4(x,y)={⌊x⌋, if 2x⩾y,x mod y, otherwise. f_{4}(x, y)= \begin{cases} \lfloor \sqrt{x}\rfloor , & \text{ if } 2 x \geqslant y, \\ x \bmod y, & \text{ otherwise. } \end{cases}

Problem 309

Show how the execution of the following commands can be organized on an ordinary Turing machine:

?
(a)

q,a→p,bq, a \rightarrow p, b, return — return the head to whichever of the neighboring cells it came from into the current one;

(b)

q,a→p,bq, a \rightarrow p, b, zero — return the head to cell zero;

(c)

q,a→p,bq, a \rightarrow p, b, mirror — move the head to cell −i-i, if it was in the cell numbered ii;

(d)

q,a→p,bq, a \rightarrow p, b, double — move the head to cell 2i2 i, if it was in the cell numbered ii;

(e)

q,a→p,bq, a \rightarrow p, b, next — move the head to the nearest cell to the right of the current one that contains aa (if one exists, otherwise the head stays in place);

(f)

q,a→p,insert⁡bq, a \rightarrow p, \operatorname {insert} b — shift the current cell and all cells to the right of it one position to the right and write the symbol bb into the freed cell; the head ends up in the new cell;

(g)

q,a→pq, a \rightarrow p, restore, ss — replace the symbol aa with the one that was in the cell in the initial configuration.

Problem 310

Implement the Turing machine from Examples 111 on p. 409 and 112 on p. 410 without extending the alphabet.

Example 111: a Turing machine over the alphabet Σ={a,b,c}\Sigma =\left\{ a,b,c\right\} computing the function f(w1w2)=w1f\left(w_{1}w_{2}\right)=w_{1} for words with ∣w1∣−∣w2∣∈{0,1}\left|w_{1}\right|-\left|w_{2}\right| \in \left\{ 0,1\right\} (i.e. erase the second half of the word, keeping the middle symbol if the length is odd), implemented by extending the alphabet with primed symbols a′,b′,c′a^{\prime }, b^{\prime }, c^{\prime }.

Example 112: a Turing machine over the alphabet Σ={0,1}\Sigma =\left\{ 0,1\right\} that adds two nonempty binary numbers given on the tape, implemented by extending the alphabet with primed symbols 0′,1′0^{\prime }, 1^{\prime }.

?
Problem 311

Complete the construction of the Turing machine from Theorem 156 on p. 413.

Theorem 156: For every Turing machine M=(Q,Σ,P,q0)\mathfrak {M}=(Q, \Sigma , P, q_{0}) one can construct a Σ\Sigma-equivalent Turing machine N\mathfrak {N} having a standard terminal configuration (i.e. one in which, at the moment of halting, the head is in cell zero and the tape holds only the result, with no leftover marker symbols).

?
Problem 312

A different approach, compared to the construction of Theorem 157 on p. 417, to simulating a two-way tape on a one-way tape consists in storing the contents of the nonnegative half of the tape of M\mathfrak {M} in cells with odd numbers, and the contents of the left half — in cells with even numbers. That is, the new tape will have the form β(0)=#,β(2x+1)=α(x)\beta (0)=\# , \beta (2 x+1)=\alpha (x) and β(2x)=α(−x)\beta (2 x)=\alpha (-x) for x>0x>0. Construct a program for a one-way machine N\mathfrak {N} that implements this approach.

Theorem 157: For every Turing machine M=(Q,Σ,P,q0)\mathfrak {M}=(Q, \Sigma , P, q_{0}) there exists a Σ\Sigma-equivalent one-way Turing machine N\mathfrak {N} having a standard terminal configuration. (The construction given in the proof of Theorem 157 folds the two-way tape in half using two-tier symbols, so that cell ii of N\mathfrak {N}'s tape stores a pair consisting of the symbol from cell i+1⩾0i+1 \geqslant 0 of M\mathfrak {M}'s tape on top and the symbol from cell −i⩽0-i \leqslant 0 on the bottom; this problem asks for an alternative, non-two-tier encoding achieving the same goal.)

?
Problem 313

Prove that the one-way Turing machine N\mathfrak {N}, constructed in Theorem 157 on p. 417, correctly simulates the original machine M\mathfrak {M}.

Theorem 157: For every Turing machine M=(Q,Σ,P,q0)\mathfrak {M}=(Q, \Sigma , P, q_{0}) there exists a Σ\Sigma-equivalent one-way Turing machine N\mathfrak {N} having a standard terminal configuration. (The construction in the proof uses two-tier symbols to fold the two-way tape of M\mathfrak {M} in half: cell ii of N\mathfrak {N}'s tape holds a pair whose top is M\mathfrak {M}'s cell i+1i+1 and whose bottom is M\mathfrak {M}'s cell −i-i, so nonnegative and negative cells of M\mathfrak {M}'s tape are interleaved onto N\mathfrak {N}'s single-direction tape.)

?
Problem 314

Show how to extract the output words from the tape code ρ(α)\rho (\alpha ) (Theorem 159 on p. 426).

For a one-way tape α\alpha over alphabet Σ={a0,a1,…,ak}\Sigma =\left\{ a_{0}, a_{1}, \ldots , a_{k}\right\} (with a0=Λa_{0}=\Lambda), holding at each moment a sequence #ai1ai2…ainΛΛ…\# a_{i_{1}} a_{i_{2}} \ldots a_{i_{n}} \Lambda \Lambda \ldots, the tape code is ρ(α)=∑j=1∞α(j)⋅kj−1\rho (\alpha )=\sum_{j=1}^{\infty } \alpha (j) \cdot k^{j-1}, i.e. reading the sequence of symbol indices as the digits of a number in base kk (only finitely many terms are nonzero). Theorem 159: every Turing-computable word function is program-computable — the proof simulates a Turing machine M\mathfrak {M} by a labeled program Π\Pi that stores M\mathfrak {M}'s configuration (q,i,α)(q, i, \alpha ) using a variable rr holding the tape code ρ(α)\rho (\alpha ); at the end, the resulting tape code must be decoded back into the sequence of output words, which is exactly what this problem asks for.

?
Problem 315

Show how, on a Turing machine, to construct the unary representation of the input, and to recover the output from the unary representation (Theorem 160 on p. 429), without extending the alphabet.

Theorem 160: If a word function f:Ω∗→Ω∗f:\Omega^{*} \rightarrow \Omega^{*} is computable on a Turing machine M=(Q,Σ,P,q0)\mathfrak {M}=(Q, \Sigma , P, q_{0}) with Ω⊆Σ\Omega \subseteq \Sigma, then it is computable on a one-way Turing machine N=(Q′,Σ′,P′,q0′)\mathfrak {N}=(Q^{\prime }, \Sigma^{\prime }, P^{\prime }, q_{0}^{\prime }) with no alphabet extension, i.e. Σ′=Ω∪{Λ,#}\Sigma^{\prime }=\Omega \cup \left\{ \Lambda , \# \right\}. (The proof builds N\mathfrak {N} by first converting the input into the unary representation of its tape code ρ(α0)\rho (\alpha_{0}), then running a machine N1\mathfrak {N}_{1} computing the same function on that unary representation — as given by Theorem 158 — and finally recovering the output word from the unary representation of the resulting tape code; this problem asks for these two conversion steps.)

?
Problem 316

Show how to simulate on a Turing machine the operation of a labeled program in the binary system (Theorem 158 on p. 422).

Theorem 158: Every program-computable function ff is Turing-computable without extending the alphabet. (The proof simulates a labeled program Π\Pi with variables x1,…,xkx_{1}, \ldots , x_{k} by a one-way Turing machine whose configuration (qα,0,κ)(q_{\alpha }, 0, \kappa ) mirrors Π\Pi's configuration (α,σ)(\alpha , \sigma ), storing the unary representations of σ(x1),…,σ(xk)\sigma (x_{1}), \ldots , \sigma (x_{k}) on the tape, separated by blanks; the number system chosen there is unary, and this problem asks to show that the binary system also works.)

?
Problem 317

Construct a universal Turing machine, implementing items 1)-21) from Theorem 161 on p. 430.

Theorem 161: For every alphabet Σ\Sigma there exists a Σ\Sigma-universal Turing machine U\mathfrak {U}, i.e. a machine such that for every Turing machine M=(Q,Σ,P,q0)\mathfrak {M}=(Q,\Sigma ,P,q_{0}) there is an input cMc_{\mathfrak {M}} (encoding M\mathfrak {M}'s program) for which U(cM,x)=M(x)\mathfrak {U}(c_{\mathfrak {M}}, x) = \mathfrak {M}(x) for every input xx.

?