Chapter 24

Turing Machines

[25/100%]
Show
LaTeX
Problem 584

Given a Turing machine M=({q,p,r},{Λ,0,1},P,q)\mathfrak {M}=(\left\{ q, p, r\right\} ,\left\{ \Lambda , 0,1\right\} , P, q) with the following program P={q,0→q,0,+1;q,1→q,1,+1;q,Λ→p,Λ,−1;p,0→p,1,−1;p,1→r,0,−1;r,0→r,0,−1;r,1→r,1,−1}P=\left\{ q, 0 \rightarrow q, 0,+1 ; q, 1 \rightarrow q, 1,+1 ; q, \Lambda \rightarrow p, \Lambda ,-1 ; p, 0 \rightarrow p, 1,-1 ; p, 1 \rightarrow r, 0,-1 ; r, 0 \rightarrow r, 0,-1 ; r, 1 \rightarrow r, 1,-1\right\}. What will the final configuration of this machine be when running on the input 1100? How many steps will be made? ⊛\circledast

?
Problem 585

There are three Turing machines Mi=(Q,Σ,Pi,q),i=1,2,3\mathfrak {M}_{i}=\left(Q, \Sigma , P_{i}, q\right), i=1,2,3, which share the tape alphabet Σ={Λ,a,b}\Sigma =\left\{ \Lambda , a, b\right\}, the set of states Q={q,p,r,s,t}Q=\left\{ q, p, r, s, t\right\}, and the initial state qq. Their programs PiP_{i} are given in the tables in Fig. 38 on the next page. Determine which of these machines transform every input word of the form a2nba^{2 n} b, n>0n>0, into the output banb a^{n}. ⊛\circledast

Fig. 38: Programs of the machines from problem 585.Fig. 38: Programs of the machines from problem 585.

Fig. 38: Programs of the machines from problem 585.Fig. 38: Programs of the machines from problem 585.

?
Problem 586

Let Σ\Sigma be an arbitrary alphabet not containing Λ\Lambda. We need to construct a Turing machine C\mathfrak {C} that swaps two arguments, more precisely, that transforms any input of the form xΛyx \Lambda y (xx and yy are words in the alphabet Σ)\Sigma ) into the output yΛxy \Lambda x with a standard final configuration.

Determine which of the following programs can be used for the machine C\mathfrak {C}. In the program texts, q0q_{0} is the initial state, α,β\alpha , \beta are arbitrary symbols from Σ\Sigma, and γ,δ\gamma , \delta are arbitrary symbols from Σ∪{u,v}\Sigma \cup \left\{ u, v\right\}, where u,vu, v are new symbols.

?
(a)

P1={q0,α→q1α,Λ,+1;q1α,β→q1α,β,+1;q1α,Λ→q2,α,+1;q2,α→q3α,Λ,−1;q2,Λ→q4,Λ,−1;q3α,β→q3α,β,−1;q3α,Λ→q0,α,+1;q4,α→q4,α,−1;q4,Λ→q5,Λ,−1;q5,α→q5,α,−1;q5,Λ→q6,Λ,+1};P_{1}=\left\{ q_{0}, \alpha \rightarrow q_{1}^{\alpha }, \Lambda ,+1 ; q_{1}^{\alpha }, \beta \rightarrow q_{1}^{\alpha }, \beta ,+1 ; q_{1}^{\alpha }, \Lambda \rightarrow q_{2}, \alpha ,+1 ; q_{2}, \alpha \rightarrow q_{3}^{\alpha }, \Lambda ,-1 ; q_{2}, \Lambda \rightarrow q_{4}, \Lambda ,-1 ; q_{3}^{\alpha }, \beta \rightarrow q_{3}^{\alpha }, \beta ,-1 ; q_{3}^{\alpha }, \Lambda \rightarrow q_{0}, \alpha ,+1 ; q_{4}, \alpha \rightarrow q_{4}, \alpha ,-1 ; q_{4}, \Lambda \rightarrow q_{5}, \Lambda ,-1 ; q_{5}, \alpha \rightarrow q_{5}, \alpha ,-1 ; q_{5}, \Lambda \rightarrow q_{6}, \Lambda ,+1\right\} ;

(b)

P2={q0,α→q0,α,+1;q0,Λ→q1,u,+1;q1,α→q1,α,+1;q1,Λ→q2,v,0;q2,γ→q3γ,Λ,−1;q3γ,δ→q3δ,γ,−1;q3α,Λ→q9α,Λ,+1;q3u,Λ→q6,Λ,+1;q6,α→q6,α,+1;q6,v→q7,Λ,−1;q7,α→q7,α,−1;q7,Λ→q8,Λ,+1;q9α,δ→q9α,δ,+1;q9α,Λ→q2,α,0};P_{2}=\left\{ q_{0}, \alpha \rightarrow q_{0}, \alpha ,+1 ; q_{0}, \Lambda \rightarrow q_{1}, u,+1 ; q_{1}, \alpha \rightarrow q_{1}, \alpha ,+1 ; q_{1}, \Lambda \rightarrow q_{2}, v, 0 ; q_{2}, \gamma \rightarrow q_{3}^{\gamma }, \Lambda ,-1 ; q_{3}^{\gamma }, \delta \rightarrow q_{3}^{\delta }, \gamma ,-1 ; q_{3}^{\alpha }, \Lambda \rightarrow q_{9}^{\alpha }, \Lambda ,+1 ; q_{3}^{u}, \Lambda \rightarrow q_{6}, \Lambda ,+1 ; q_{6}, \alpha \rightarrow q_{6}, \alpha ,+1 ; q_{6}, v \rightarrow q_{7}, \Lambda ,-1 ; q_{7}, \alpha \rightarrow q_{7}, \alpha ,-1 ; q_{7}, \Lambda \rightarrow q_{8}, \Lambda ,+1 ; q_{9}^{\alpha }, \delta \rightarrow q_{9}^{\alpha }, \delta ,+1 ; q_{9}^{\alpha }, \Lambda \rightarrow q_{2}, \alpha , 0\right\} ;

(c)

P3={q0,α→q0,α,+1;q0,Λ→q1,u,−1;q1,α→q1,α,−1;q1,Λ→q2,Λ,+1;q2,α→q3α,v,+1;q3γ,δ→q3δ,γ,+1;q3γ,Λ→q6,γ,0;q6,α→q7α,Λ,−1;q6,u→q8,Λ,−1;q7α,δ→q7α,δ,−1;q7α,Λ→q9α,Λ,+1;q8,α→q8,α,−1;q8,u→q8,Λ,−1;q8,v→q8,Λ,−1;q8,Λ→q4,Λ,+1;q9α,δ→q3δ,α,+1}P_{3}=\left\{ q_{0}, \alpha \rightarrow q_{0}, \alpha ,+1 ; q_{0}, \Lambda \rightarrow q_{1}, u,-1 ; q_{1}, \alpha \rightarrow q_{1}, \alpha ,-1 ; q_{1}, \Lambda \rightarrow q_{2}, \Lambda ,+1 ; q_{2}, \alpha \rightarrow q_{3}^{\alpha }, v,+1 ; q_{3}^{\gamma }, \delta \rightarrow q_{3}^{\delta }, \gamma ,+1 ; q_{3}^{\gamma }, \Lambda \rightarrow q_{6}, \gamma , 0 ; q_{6}, \alpha \rightarrow q_{7}^{\alpha }, \Lambda ,-1 ; q_{6}, u \rightarrow q_{8}, \Lambda ,-1 ; q_{7}^{\alpha }, \delta \rightarrow q_{7}^{\alpha }, \delta ,-1 ; q_{7}^{\alpha }, \Lambda \rightarrow q_{9}^{\alpha }, \Lambda ,+1 ; q_{8}, \alpha \rightarrow q_{8}, \alpha ,-1 ; q_{8}, u \rightarrow q_{8}, \Lambda ,-1 ; q_{8}, v \rightarrow q_{8}, \Lambda ,-1 ; q_{8}, \Lambda \rightarrow q_{4}, \Lambda ,+1 ; q_{9}^{\alpha }, \delta \rightarrow q_{3}^{\delta }, \alpha ,+1\right\}. ⊛\circledast

Problem 587

Construct a Turing machine that, for each input word of the form anbka^{n} b^{k}, produces the result a⌊(n+k)/2⌋b⌊(n+k)/2⌋a^{\lfloor (n+k) / 2\rfloor } b^{\lfloor (n+k) / 2\rfloor }. How the machine behaves on other inputs is irrelevant. Estimate the running time of the constructed machine. ⊛\circledast

?
Problem 588

Construct a Turing machine that, for each input word of the form 0n1k0^{n} 1^{k}, where n>k>0n>k>0, produces the result 0, and for all other words produces the result 1. Estimate the running time of the constructed machine. ⊛\circledast

?
Problem 589

Construct a Turing machine that transforms any input word w∈{a,b}∗w \in \left\{ a, b\right\}^{*} into the output anΛbma^{n} \Lambda b^{m}, where nn is the number of letters aa and mm is the number of letters bb in the word ww. In other words, the letters of the word are sorted and then separated. Estimate the running time of the constructed machine. ⊛\circledast

?
Problem 590

Let the alphabet Σ\Sigma not contain the symbols Λ\Lambda and *. Construct a Turing machine program that moves the last word on the tape, in the alphabet Σ\Sigma, from left to right to the place on the tape marked *. More precisely, from the tape αΛwΛn∗\alpha \Lambda w \Lambda^{n} * one should obtain αΛΛnw\alpha \Lambda \Lambda^{n} w, where w∈Σ∗w \in \Sigma^{*}. ⊛\circledast

?
Problem 591

Construct a Turing machine performing the following task: given an input consisting of one or more words w1Λ…Λwnw_{1} \Lambda \ldots \Lambda w_{n} in the alphabet Σ\Sigma (possibly n=1n=1), construct an output by doubling the last of the words: w1Λ…ΛwnΛwnw_{1} \Lambda \ldots \Lambda w_{n} \Lambda w_{n}. ⊛\circledast

?
Problem 592

Prove that for any constant k>1k>1 one can construct a Turing machine that solves problem 591 in time at most n2/k+O(n)n^{2} / k+O(n), where nn is the total length of the input words. ⊛\circledast

?
Problem 593

Construct a Turing machine that compares two input words in the alphabet {a,b,c}\left\{ a, b, c\right\} lexicographically. This Turing machine must compute the dictionary function: ⊛\circledast

f(x,y)={a, if x<y,b, if x=y,c, 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 594

Construct Turing machine programs that compute the following dictionary 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 the 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 of 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 φ\varphi: φ(a)=a,φ(b)=cb\varphi (a)=a, \varphi (b)=c b, φ(c)=ε;\varphi (c)=\varepsilon ;

(f)

removal of all single letters aa standing in 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 aa, bb, and cc in the word form an increasing arithmetic progression. ⊛\circledast

Problem 595

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

?
Problem 596

Construct a Turing machine that, given the unary representation of three numbers, that is, an input of the form ∣n+1Λ∣k+1Λ∣m+1\left.\left.\left.\right|^{n+1} \Lambda \right|^{k+1} \Lambda \right|^{m+1}, produces the result 0 if 0<n<k+m0<n<k+m, and 1 otherwise. Estimate the running time of the constructed machine. ⊛\circledast

?
Problem 597

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

?
(a)

x+yx+y;

(b)

x÷yx \div y;

(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: id⁡m\operatorname {id}_{m}, where mm is a predetermined constant. ⊛\circledast

Problem 598

Given Turing machines with standard final configuration Mi\mathfrak {M}_{i}, each of which computes a dictionary function fi(x)f_{i}(x) in time ti(x)t_{i}(x), i=1,…,ni=1, \ldots , n. Describe 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}(\mathfrak {M}_{1}, \mathfrak {M}_{2}, \mathfrak {M}_{3}), 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}(\mathfrak {M}_{1}, \mathfrak {M}_{2}), 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). ⊛\circledast

Problem 599

Given the following Turing machines with standard final configuration: - copy⁡(a)\operatorname {copy}(a) — copies the input, using the symbol aa as a separator between the original and the copy: w↦waww \mapsto w a w; - replace⁡(a,b)\operatorname {replace}(a, b) — replaces the leftmost occurrence of the symbol aa with bb; if there is no symbol aa, the input is unchanged; - add⁡\operatorname {add} — adds two numbers written in the unary number system; - mult⁡\operatorname {mult} — multiplies two numbers written in the unary number system; - nop⁡\operatorname {nop} — does not change the input.

Determine which arithmetic functions are computed (in the unary number system) by the following Turing machines, constructed by the methods of problem 598 on the previous page:

?
(a)

copy⁡(∗);par⁡(∗,copy⁡(Λ),copy⁡(Λ));par⁡(∗,mult⁡,add⁡);replace⁡(∗\operatorname {copy}(*) ; \operatorname {par}(*, \operatorname {copy}(\Lambda ), \operatorname {copy}(\Lambda )) ; \operatorname {par}(*, \operatorname {mult}, \operatorname {add}) ; \operatorname {replace}(*, Λ\Lambda); add⁡\operatorname {add};

(b)

copy⁡(∗);par⁡(∗,copy⁡(Λ),copy⁡(Λ));par⁡(∗,mult⁡,add⁡);par⁡(∗\operatorname {copy}(*) ; \operatorname {par}(*, \operatorname {copy}(\Lambda ), \operatorname {copy}(\Lambda )) ; \operatorname {par}(*, \operatorname {mult}, \operatorname {add}) ; \operatorname {par}(*, (copy⁡(Λ);add⁡),nop⁡);replace⁡(∗,Λ);add⁡;\operatorname {copy}(\Lambda ) ; \operatorname {add}), \operatorname {nop}) ; \operatorname {replace}(*, \Lambda ) ; \operatorname {add} ;

(c)

copy⁡(∗);par⁡(∗,(copy⁡(Λ);mult⁡),nop⁡);par⁡(∗,(copy⁡(Λ);add⁡)\operatorname {copy}(*) ; \operatorname {par}(*,(\operatorname {copy}(\Lambda ) ; \operatorname {mult}), \operatorname {nop}) ; \operatorname {par}(*,(\operatorname {copy}(\Lambda ) ; \operatorname {add}), nop⁡\operatorname {nop}); \operatorname {replace}$$(*, \Lambda ); add⁡\operatorname {add}.

Problem 600

Given the Turing machines with standard final configuration from problem 599 on the preceding page, as well as the following: - id⁡i\operatorname {id}_{i} — returns the ii-th argument, or the empty word if the number of arguments is less than ii; - pos⁡i\operatorname {pos}_{i} — checks whether the ii-th argument is positive (numbers are written in unary), returning the empty word if it equals zero, or | if it is positive; - dec⁡\operatorname {dec} — decreases the argument by one if it is positive, otherwise leaves the input unchanged (numbers are written in unary). Determine which arithmetic functions (in the unary system) are computed by each of the Turing machines whose programs are shown schematically in Fig. 39 on the next page (see problem 598 on the preceding page). ⊛\circledast

?
Problem 601

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} ⊛\circledast

Problem 602

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 — the head returns to whichever neighboring cell it came from into the current one;

(b)

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

(c)

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

(d)

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

(e)

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

(f)

q,a→p,insert⁡bq, a \rightarrow p, \operatorname {insert} b — the current cell and all cells to its right are shifted one position to the right, and the symbol bb is written into the freed cell; the head ends up in the new cell;

(g)

q,a→pq, a \rightarrow p, restore, ss — the symbol aa is replaced by the symbol that was in the cell in the initial configuration. ⊛\circledast

Problem 603

Construct a Turing machine for problem 591 on p. 185, without enlarging the original alphabet Σ\Sigma. ⊛\circledast

?
Problem 604

Implement the following Turing machines without extending the alphabet:

?
(a)

erase the second half of the word, leaving the central symbol if the length was odd;

(b)

add two numbers written in binary. ⊛\circledast

Problem 605

One of the approaches to simulating a two-way tape on a one-way tape consists in storing the contents of the non-negative half of the tape M\mathfrak {M} in the cells with odd numbers, and the contents of the left half in the 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} implementing this approach. ⊛\circledast

?
Problem 606

Prove that every arithmetic function f(x)f(x) computable on some Turing machine M=(Q,Σ,P,q0)\mathfrak {M}=\left(Q, \Sigma , P, q_{0}\right) in the unary number system can also be computed on a Turing machine N\mathfrak {N} whose tape alphabet contains only two symbols: Λ\Lambda and ∣\mid. Hint. To simulate one symbol aia_{i} of the alphabet Σ\Sigma, use a block of several consecutive cells containing the word ∣iΛk−i\left.\right|^{i} \Lambda^{k-i}, where Σ={a0,…,ak}\Sigma =\left\{ a_{0}, \ldots , a_{k}\right\}. Replace each command of M\mathfrak {M} with a group of commands processing the corresponding block of cells. ⊛\circledast

?
Problem 607

A kk-tape Turing machine has kk tapes, each with its own head moving along it. A command of a kk-tape Turing machine has the form

q,a1,a2,…,ak→p,b1,b2,…,bk,s1,s2,…,sk, q, a_{1}, a_{2}, \ldots , a_{k} \rightarrow p, b_{1}, b_{2}, \ldots , b_{k}, s_{1}, s_{2}, \ldots , s_{k},

where q,p∈Qq, p \in Q are states, a1,…,aka_{1}, \ldots , a_{k} are the symbols observed by the heads on the corresponding tapes, b1,…,bkb_{1}, \ldots , b_{k} are the symbols written by the heads on the corresponding tapes, s1,…,sks_{1}, \ldots , s_{k} are the directions of the head shifts on the corresponding tapes. The input data is written on the first tape, and the rest are empty in the initial configuration. The result is also placed on the first tape.

Prove that any function computable on a kk-tape Turing machine can also be computed on an ordinary Turing machine. By how much does the computation time increase in this case? ⊛\circledast

?
Problem 608

Show that palindromes (symmetric words) can be recognized on a two-tape Turing machine in time proportional to their length. ⊛\circledast

?