Section 4.2

Examples of Turing Machines

[17/41%]
Show
LaTeX
Example 4.3

Show that A={wwR∣w∈{0,1}∗}A=\left\{ w w^{R} \mid w \in \left\{ 0,1\right\}^{*}\right\} is Turing-acceptable.

?
Example 4.4

Show that the following function is Turing-computable:

f(x)={w if x=wwR for some w∈{0,1}∗↑ otherwise  f(x)= \begin{cases} w & \text{ if } x=w w^{R} \text{ for some } w \in \left\{ 0,1\right\} ^{*} \\ \uparrow & \text{ otherwise }\end{cases}
?
Example 4.5

Show that {wwR∣w∈{0,1}∗}\left\{ w w^{R} \mid w \in \left\{ 0,1\right\}^{*}\right\} is Turing-decidable.

?
Example 4.6

Show that the function π22(n1,n2)=n2\pi_{2}^{2}\left(n_{1}, n_{2}\right)=n_{2}, for n1,n2∈Nn_{1}, n_{2} \in \mathbf{N}, is Turing-computable.

?
Example 4.7

Find a Turing machine that computes the function

sub⁡(n,m)={n−m if n≥m≥0,0 if m>n≥0. \operatorname {sub}(n, m)= \begin{cases} n-m & \text{ if } n \geq m \geq 0, \\ 0 & \text{ if } m>n \geq 0.\end{cases}
?
Example 4.8

For 1≤i≤k1 \leq i \leq k, show that function πik(x1,x2,⋯ ,xk)=xi\pi_{i}^{k}\left(x_{1}, x_{2}, \cdots , x_{k}\right)=x_{i} on natural numbers is Turing-computable.

?
Example 4.9

Show that, for any 1≤i≤k+11 \leq i \leq k+1, the function

insert⁡ik(x1,x2,⋯ ,xk,y)=(x1,…,xi−1,y,xi,…,xk) \operatorname {insert}_{i}^{k}\left(x_{1}, x_{2}, \cdots , x_{k}, y\right)=\left(x_{1}, \ldots , x_{i-1}, y, x_{i}, \ldots , x_{k}\right)

on strings over {a,b}\left\{ a, b\right\} is Turing-computable.

?
Problem 4.2.1

For each of the following DTM's, trace the machine and show the computation on the given inputs:

?
(a)

The DTM MAM_{A} of Example 4.3 on inputs 0100 and 01010.

(b)

The DTM of Example 4.5 on inputs 0110 and 01010.

(c)

The DTM of Example 4.6 on inputs (3,0)(3,0) and (0,3)(0,3).

(d)

The DTM MM of Example 4.9, with k=3k=3 and i=2i=2, from configuration (q1, BaaBBab Bbba Baba)(q_{1}, \mathrm{~ B} a a \mathrm{BB} a b \mathrm{~ B} b b a \mathrm{~ B} a b a) to (q1, Baa Ba Bab Bbba Bab‾q_{1}, \mathrm{~ B} a a \mathrm{~ B} a \mathrm{~ B} a b \mathrm{~ B} b b a \mathrm{~ B} a \underline{b}).

Problem 4.2.2

Construct DTM's for procedures RR and TT of Example 4.9.

?
Problem 4.2.3

Construct DTM's to decide the following languages:

?
(a)

{ww∣w∈{0,1}∗}\left\{ w w \mid w \in \left\{ 0,1\right\}^{*}\right\}.

(b)

{wwRw∣w∈{0,1}∗}\left\{ w w^{R} w \mid w \in \left\{ 0,1\right\}^{*}\right\}.

(c)

{ambnck∣m≥n≥k≥0}\left\{ a^{m} b^{n} c^{k} \mid m \geq n \geq k \geq 0\right\}.

(d)

{ambncn+m∣n,m≥0}\left\{ a^{m} b^{n} c^{n+m} \mid n, m \geq 0\right\}.

(e)

{w∈{a,b}∗∣#a(w)>#b(w)}\left\{ w \in \left\{ a, b\right\}^{*} \mid \#_{a}(w)>\#_{b}(w)\right\}, where #a(w)\#_{a}(w) denotes the number of occurrences of letter aa in string ww.

(f)

{an1ban2b⋯bank∣ni=nj for some 1≤i<j≤k}\left\{ a^{n_{1}} b a^{n_{2}} b \cdots b a^{n_{k}} \mid n_{i}=n_{j}\text{ for some }1 \leq i<j \leq k\right\}.

Problem 4.2.4

Construct DTM's to compute the following functions:

?
(a)

f(m,n)=max⁡{m,n}f(m, n)=\max \left\{ m, n\right\} over natural numbers m,nm, n.

(b)

f(n1,n2,…,nk)=max⁡{n1,…,nk}f\left(n_{1}, n_{2}, \ldots , n_{k}\right)=\max \left\{ n_{1}, \ldots , n_{k}\right\} over natural numbers n1,…n_{1}, \ldots, nkn_{k}, where kk is a fixed positive integer.

(c)

insert k(x1,…,xk,y,i)=insert⁡ik(x1,…,xk,y){ }^{k}\left(x_{1}, \ldots , x_{k}, y, i\right)=\operatorname {insert}_{i}^{k}\left(x_{1}, \ldots , x_{k}, y\right), where x1,…,xkx_{1}, \ldots , x_{k} and yy are strings in {0,1}∗\left\{ 0,1\right\}^{*} and ii is a natural number represented by 1i1^{i}.

(d)

mult⁡(n,m)=nm\operatorname {mult}(n, m)=n m on natural numbers n,m≥0n, m \geq 0.

(e)

quot⁡(n,m)=⌊nm⌋\operatorname {quot}(n, m)=\left\lfloor \frac{n}{m}\right\rfloor on natural numbers n≥0n \geq 0 and m≥1m \geq 1.

(f)

lg⁡(n)=⌈log⁡2n⌉\lg (n)=\left\lceil \log_{2} n\right\rceil on natural number nn.

Problem 4.2.5

For any given DTM MM, construct a new DTM M′M^{\prime } such that M′M^{\prime } accepts exactly the same set of strings as that of MM (i.e., L(M)=L(M′)L(M)=L\left(M^{\prime }\right)) but when M′M^{\prime } halts its tape is always empty (i.e., the final configuration is always (h,BB)(h, \mathrm{BB})).

?
Problem 4.2.6

Consider the regular language L={0n110n21⋯10nk∣k≥5, n1,…,nk≥0,nj≡nj+1( mod 5), where j=(k mod 5)+1}L=\left\{ 0^{n_{1}} 10^{n_{2}} 1 \cdots 10^{n_{k}} \mid k \geq 5\text{, }n_{1}, \ldots , n_{k} \geq 0, n_{j} \equiv n_{j+1}(\bmod 5)\text{, where }j=(k \bmod 5)+1\right\}.

?
(a)

Find a read-only DTM MM accepting LL. [Hint: MM make two passes over the input. In the first pass, it checks that k≥5k \geq 5 and finds j=(k mod 5)+1j=(k \bmod 5)+1. In the second pass, it checks that nj≡nj+1( mod 5)n_{j} \equiv n_{j+1}(\bmod 5).]

(b)

Find all possible crossing sequences of MM on any input.

(c)

For any two crossing sequences S1,S2S_{1}, S_{2} of MM, and for any symbol a∈{0,1, B}a \in \left\{ 0,1, \mathrm{~ B}\right\}, determine whether S1⇌aS2S_{1} \stackrel{a}{\rightleftharpoons } S_{2}. Based on this relation between crossing sequences, construct an NFA M′M^{\prime } that accepts LL.

(d)

Can you find an NFA with a smaller state set than M′M^{\prime } that accepts LL?

Problem 4.2.7

In the proof of Theorem 4.10, we observe that if the DTM MM visits, during its computation on input xx, some blank cells to the right of the input, then the NFA M′M^{\prime } needs to move, after reading all input symbols, to other states by ε\varepsilon-moves to decide whether it accepts the input. Show that this is not necessary. That is, we can eliminate all ε\varepsilon-moves in δ′\delta^{\prime } and change the set FF of the final states to include all crossing sequences SS which contain ⟨h,R⟩\langle h, R\rangle as the last pair such that S⇌ BS1⇌ BS2⇌ B…⇌ B(⟨h,R⟩)S \stackrel{\mathrm{~ B}}{\rightleftharpoons } S_{1} \stackrel{\mathrm{~ B}}{\rightleftharpoons } S_{2} \stackrel{\mathrm{~ B}}{\rightleftharpoons } \ldots \stackrel{\mathrm{~ B}}{\rightleftharpoons }(\langle h, R\rangle ). Explain how to determine the final set FF.

?
Problem 4.2.8

We consider an extension of read-only DTM's. A one-pebble, read-only DTM (or, simply, one-pebble DTM) is a read-only DTM MM with the additional capability that it can mark a specific cell of the input tape by putting a pebble on it. The machine MM has only one pebble, and so at any time the tape can have at most one marked symbol. More precisely, a one-pebble DTM MM is a DTM M=(Q,Σ,Γ,δ,s∗)M=\left(Q, \Sigma , \Gamma , \delta , s^{*}\right), where Q=Q1∪{q∗∣q∈Q1}Q=Q_{1} \cup \left\{ q^{*} \mid q \in Q_{1}\right\} for some finite set Q1,Γ=Σ∪{B}∪{a∗∣a∈Σ or a=B},s∈Q1Q_{1}, \Gamma =\Sigma \cup \left\{ \mathrm{B}\right\} \cup \left\{ a^{*} \mid a \in \Sigma \text{ or }a=\mathrm{B}\right\} , s \in Q_{1}, and δ\delta satisfies the following properties: For any q∈Q1q \in Q_{1} and a∈Σ∪{ B}a \in \Sigma \cup \left\{ \mathrm{~ B}\right\},

  1. δ(q,a)=(p,a,D)\delta (q, a)=(p, a, D) for some p∈Q1p \in Q_{1} and D∈{L,R}D \in \left\{ L, R\right\}.

  2. δ(q,a∗)\delta \left(q, a^{*}\right) is either (p,a∗,D)\left(p, a^{*}, D\right) or (p∗,a,D)\left(p^{*}, a, D\right) for some p∈Q1p \in Q_{1} and D∈{L,R}D \in \left\{ L, R\right\}.

  3. δ(q∗,a)\delta \left(q^{*}, a\right) is either (p∗,a,D)\left(p^{*}, a, D\right) or (p,a∗,D)\left(p, a^{*}, D\right) for some p∈Q1p \in Q_{1} and D∈{L,R}D \in \left\{ L, R\right\}.

  4. δ(q∗,a∗)\delta \left(q^{*}, a^{*}\right) is undefined. (In the above, the superscript * denotes the pebble. So, a state q∗q^{*} indicates that MM is holding the pebble at its finite control, and all tape symbols are unmarked; and a state q∈Q1q \in Q_{1} indicates that the pebble is in an input cell. Note that property (i) indicates that MM cannot mark a cell if it does not hold the pebble in its finite control now.)

  5. Construct a one-pebble DTM MM such that on each input xx of length n≥2,Mn \geq 2, M halts in exactly n2n^{2} moves.

  6. Show that for each read-only DTM MM, there exist two constants cc and dd such that if MM halts on an input xx of length n≥1n \geq 1, then it must halt within cn+dc n+d moves.

  7. Show that for each one-pebble DTM MM, there exist two constants cc and dd such that if MM halts on an input xx of length n≥1n \geq 1, then it must halt within cn2+dc n^{2}+d moves.

  8. Show that if LL is a regular language, then there is a one-pebble DTM MM that accepts the language SQRT⁡(L)\operatorname {SQRT}(L). (Recall that SQRT(L)\mathrm{SQRT}(L) is defined in Example 2.44 as {x∣(∃y)∣y∣=∣x∣2,xy∈L}\left\{ x\left|(\exists y)\right| y\left|=|x|^{2}, x y \in \right. L\right\}.)

?
Problem 4.2.9

In this exercise, we prove that the language accepted by a one-pebble DTM must be regular. Assume that M=(Q,Σ,Γ,δ,s∗)M=\left(Q, \Sigma , \Gamma , \delta , s^{*}\right) is a one-pebble DTM with Q=Q1∪{q∗∣q∈Q1}Q=Q_{1} \cup \left\{ q^{*} \mid q \in Q_{1}\right\}. Also assume that MM operates on an input xx and visits cells C0,C1,…,CnC_{0}, C_{1}, \ldots , C_{n}, with symbol sis_{i} in cell CiC_{i}, for i=0,1,…,ni=0,1, \ldots , n (i.e., s0s1⋯sn=Bx B⋯ Bs_{0} s_{1} \cdots s_{n}=\mathrm{B} x \mathrm{~ B} \cdots \mathrm{~ B}). For each i,0≤i≤ni, 0 \leq i \leq n, define a partial function fi:Q1→Q1f_{i}: Q_{1} \rightarrow Q_{1} as follows: If δ(q,si∗)=(p,si∗,D)\delta \left(q, s_{i}^{*}\right)=\left(p, s_{i}^{*}, D\right) for some p∈Q1p \in Q_{1} and D∈{L,R}D \in \left\{ L, R\right\}, then fi(q)f_{i}(q) is the next state r∈Q1(r≠h)r \in Q_{1} (r \neq h) at which MM returns to cell CiC_{i}. Otherwise, fi(q)f_{i}(q) is undefined. That is, the function fif_{i} encodes the states of MM when it visits cell CiC_{i} with the pebble in cell CiC_{i} (similar to a crossing sequence of a read-only DTM). Note that fif_{i} depends on both machine MM and input xx.

?
(a)

Consider the language L1L_{1} over the alphabet (Σ∪{B})×F(\Sigma \cup \left\{ \mathrm{B}\right\} ) \times F, where FF is the set of all partial functions from Q1Q_{1} to Q1Q_{1}, with w=[s0,g0][s1,g1]⋯[sn,gn]∈L1w= \left[s_{0}, g_{0}\right]\left[s_{1}, g_{1}\right] \cdots \left[s_{n}, g_{n}\right] \in L_{1} if and only if for all i=0,…,ni=0, \ldots , n, gi=fig_{i}=f_{i}, with respect to machine MM and string s0s1⋯sns_{0} s_{1} \cdots s_{n}. (Note: If ∣Q1∣=m\left|Q_{1}\right|=m then there are at most mm+1m^{m+1} symbols in FF, each encodes one partial function from Q1Q_{1} to Q1Q_{1}.) Show that there is a read-only DTM M1M_{1} that accepts L1L_{1}; that is, show that a read-only DTM can check whether each symbol gig_{i} stored at the second track of cell CiC_{i} encodes correctly the function fif_{i}. [Hint: M1M_{1} cannot simulate MM step-by-step to check whether the values fi(q)f_{i}(q) are correct, because M1M_{1} does not have a pebble and so once it leaves cell CiC_{i}, it cannot remember where it is. Instead, M1M_{1} needs only to check the consistency of the function fif_{i} with its neighbors fi−1f_{i-1} and fi+1f_{i+1}, similar to the problem of checking the consistency of neighboring crossing sequences in Theorem 4.10.]

(b)

Let L2L_{2} be the language over the alphabet (Σ∪{B})×F(\Sigma \cup \left\{ \mathrm{B}\right\} ) \times F such that w=[s0,g0][s1,g1]⋯[sn,gn]∈L2w=\left[s_{0}, g_{0}\right]\left[s_{1}, g_{1}\right] \cdots \left[s_{n}, g_{n}\right] \in L_{2} if (1) w∈L1w \in L_{1} defined in part (a) above, and (2) the one-pebble DTM MM accepts the input t0t1⋯tnt_{0} t_{1} \cdots t_{n}, where ti=sit_{i}=s_{i} if si≠Bs_{i} \neq \mathrm{B} and ti=εt_{i}=\varepsilon if si=Bs_{i}=\mathrm{B}. Show that there is a read-only DTM M2M_{2} accepting L2L_{2}. [Hint: M2M_{2} uses the information gig_{i} to simulate MM as follows: If MM holds the pebble in its state (i.e., if MM is in a state q∗q^{*}), then M2M_{2} simulates MM step-by-step. If MM puts down the pebble in Cell CiC_{i}, then M2M_{2} uses gig_{i} at the second track to determine the state it will change to when it returns to cell CiC_{i}.]

(c)

Show that if MM is a one-pebble DTM, then L(M)L(M) is regular. [Hint: Show that the language L(M)L(M) is the image of a homomorphism ϕ\phi on L2L_{2}; see Example 2.35.]

Problem 4.2.10

We consider another extension of read-only DTM's. A DTM MM is called a read/erase-only DTM if it can, at each move, only read an input symbol and/or erase it (i.e., replace the original symbol by BB). That is, a DTM M=(Q,Σ,Γ,δ,s)M=(Q, \Sigma , \Gamma , \delta , s) is a read/erase-only DTM if Γ=Σ∪{B}\Gamma =\Sigma \cup \left\{ \mathrm{B}\right\}, and the transition function δ\delta satisfies the following property: For any q∈Qq \in Q and a∈Σ∪{ B},δ(q,a)a \in \Sigma \cup \left\{ \mathrm{~ B}\right\} , \delta (q, a) is either (p,a,D)(p, a, D) or (p, B,D)(p, \mathrm{~ B}, D) for some p∈Qp \in Q and D∈{L,R}D \in \left\{ L, R\right\}.

?
(a)

Show that there exists a read/erase-only DTM that accepts the language L={anbncn∣n≥0}L=\left\{ a^{n} b^{n} c^{n} \mid n \geq 0\right\}.

(b)

Show that there exists a Turing-decidable language that is not accepted by any read/erase-only DTM.