/ OpenLogic Public

## Commit

Browse the repository at this point in the history
require TM output at sq. 1; definition of disciplined machine (issue #…
…191)
rzach committed Jul 10, 2021
1 parent f73393b commit a03d24c
Showing 10 changed files with 352 additions and 80 deletions.
87 changes: 69 additions & 18 deletions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Expand Up @@ -21,15 +21,47 @@
creating several simple Turing machines and combining them into one
machine that can solve the problem. This point is especially important
when tackling the Halting Problem in the next section.

How do we combine Turing machines $M = \tuple{Q, \Sigma, q_0, \delta}$
and~$M' = \tuple{Q', \Sigma', q_0', \delta'}$? We now use the
configuration of the tape after $M$~has halted as the input
configuration of a run of machine~$M'$. To get a single Turing
machine $M \frown M'$ that does this, do the following:
\begin{enumerate}
\item Renumber (or relabel) all the states~$Q'$ of~$M'$ so that $M$
and~$M'$ have no states in common ($Q \cap Q' = \emptyset$).
\item The states of $M \frown M'$ are $Q \cup Q'$.
\item The tape alphabet is $\Sigma \cup \Sigma'$.
\item The start state is~$q_0$.
\item The transition function is the function $\delta''$ given by:
$\delta''(q,\sigma) = \begin{cases} \delta(q,\sigma) & \text{if q \in Q}\\ \delta'(q,\sigma) & \text{if q \in Q'}\\ \tuple{q_0', \sigma, \TMstay} & \text{if q \in Q and \delta(q,\sigma) undefined} \end{cases}$
\end{enumerate}
The resulting machine uses the instructions of~$M$ when it is in a
state $q \in Q$, the instructions of~$M'$ when it is in a state~$q \in Q'$. When it is in a state $q \in Q$ and is scanning a symbol~$\sigma$
for which $M$ has no transition (i.e., $M$ would have halted), it
enters the start state of~$M'$ (and leaves the tape contents and head
position as it is).

Note that unless the machine~$M$ is disciplined, we don't know where
the tape head is when $M$~halts, so the halting configuration of~$M$
need not have the head scanning square~$1$. When combining machines,
it's important to keep this in mind.
\end{explain}

\begin{ex}
\emph{Combining Machines:} Design a machine that computes the function
$f(m,n) = 2(m+n)$.

In order to build this machine, we can combine two machines we are already
familiar with: the addition machine, and the doubler. We begin by drawing
a state diagram for the addition machine.
\emph{Combining Machines:} We'll design a machine which, when started
on input consisting of two blocks of~$\TMstroke$'s of length $n$
and~$m$, halts with a single block of $2(m+n)$ $\TMstroke$'s on the
tape. In order to build this machine, we can combine two machines we
begin by drawing a state diagram for the addition machine.
$\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm, semithick] Expand All @@ -39,18 +71,18 @@ \node[state] (B) [right of=A] {q_1}; \node[state] (C) [right of=B] {q_2}; \path (A) edge node {\TMtrans{\TMblank}{\TMstroke}{\TMright}} (B) \path (A) edge node {\TMtrans{\TMblank}{\TMstroke}{\TMstay}} (B) edge [loop above] node {\TMtrans{\TMstroke}{\TMstroke}{\TMright}} (B) (B) edge [loop above] node {\TMtrans{\TMstroke}{\TMstroke}{\TMright}} (B) edge node {\TMtrans{\TMblank}{\TMblank}{\TMleft}} (C) (C) edge [loop above] node {\TMtrans{\TMstroke}{\TMblank}{\TMstay}} (C); \end{tikzpicture}$
Instead of halting at state $q_2$, we want to continue operation in
order to double the output. Recall that the doubler machine erases
the first stroke in the input and writes two strokes in a separate
the first stroke of the output of the addition machine.
Instead of halting in state~$q_2$, we want to continue operation in
order to double the output. Recall that the doubler machine erases the
first stroke in the input and writes two strokes in a separate output.
first stroke of the output of the addition machine.
$\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm, semithick] Expand All @@ -62,7 +94,7 @@ \node[state] (D) [below left of=C] {q_3}; \node[state] (E) [below left of=D] {q_4}; \path (A) edge node {\TMtrans{\TMblank}{\TMstroke}{\TMright}} (B) \path (A) edge node {\TMtrans{\TMblank}{\TMstroke}{\TMstay}} (B) edge [loop above] node {\TMtrans{\TMstroke}{\TMstroke}{\TMright}} (B) (B) edge [loop above] node {\TMtrans{\TMstroke}{\TMstroke}{\TMright}} (B) edge node {\TMtrans{\TMblank}{\TMblank}{\TMleft}} (C) Expand All @@ -72,10 +104,10 @@ \end{tikzpicture}$
It is now easy to double the input---all we have to do is connect the
doubler machine onto state $q_4$. This requires renaming the states
of the doubler machine so that they start at $q_4$ instead of
$q_0$---this way we don't end up with two starting states. The final
diagram should look as in \olref{fig:combined}.
doubler machine onto state~$q_4$. This requires renaming the states of
the doubler machine so that they start at~$q_4$ instead
of~$q_0$---this way we don't end up with two starting states. The
final diagram should look as in \olref{fig:combined}.
\begin{figure}
$\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm, Expand All @@ -92,7 +124,7 @@ \node[state] (5) [left of=4] {q_8}; \node[state] (6) [left of=5] {q_9}; \path (A) edge node {\TMtrans{\TMblank}{\TMstroke}{\TMright}} (B) \path (A) edge node {\TMtrans{\TMblank}{\TMstroke}{\TMstay}} (B) edge [loop above] node {\TMtrans{\TMstroke}{\TMstroke}{\TMright}} (B) (B) edge [loop above] node {\TMtrans{\TMstroke}{\TMstroke}{\TMright}} (B) edge node {\TMtrans{\TMblank}{\TMblank}{\TMleft}} (C) Expand All @@ -117,4 +149,23 @@ \end{figure} \end{ex} \begin{prop} If M and M' are disciplined and compute the functions f\colon \Nat^k \to \Nat and f'\colon \Nat \to \Nat, respectively, then M \frown M' is disciplined and computes~\comp{f}{f'}. \end{prop} \begin{proof} Since M is disciplined, when it halts with output~f(n_1,\dots,n_k) = m, the head is scanning square~1. If we now enter the start state of~M', the machine will halt with output f(m), again scanning square~1. The other conditions of \olref[dis]{defn:disciplined} are also satisfied. \end{proof} \begin{prob} Give a disciplined Turing machine computing f(x) = x+2 by taking the machine~M from \cref{tur:mac:dis:prob:disc-succ} and construct M \frown M. \end{prob} \end{document} 27 changes: 13 additions & 14 deletions This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Expand Up @@ -18,8 +18,8 @@ \emph{configurations}---and a configuration in turn is a sequence of symbols (corresponding to the contents of the tape at a given point in the computation), a number indicating the position of the read/write head, and a state. Using these, we can define what the Turing machine M computes on a given input. head, and a state. Using these, we can define what the Turing machine~M computes on a given input. \end{explain} \begin{defn}[Configuration] Expand Down Expand Up @@ -56,15 +56,14 @@ \end{defn} \begin{explain} The~\frown symbol is for \emph{concatenation}---we want to ensure that there are no blanks between the left end marker and the beginning of the input. The~\frown symbol is for \emph{concatenation}---the input string begins immediately to the left end marker. \end{explain} \begin{defn} We say that a configuration \tuple{C, m, q} \emph{yields the configuration \tuple{C', m', q'} in one step} (according to~M), iff configuration \tuple{C', m', q'} in one step} (according to~M), iff \begin{enumerate} \item the m-th symbol of C is \sigma, \item the instruction set of M specifies \delta(q, \sigma) = Expand All @@ -82,24 +81,24 @@ \end{enumerate} \end{defn} \begin{defn} \begin{defn}\ollabel{defn:run-output} A \emph{run of M on input~I} is a sequence C_i of configurations of M, where C_0 is the initial configuration of M for input~I, and each C_i yields C_{i+1} in one step. We say that M \emph{halts on input I after k steps} if C_k = \tuple{C, m, q}, the mth symbol of C is~\sigma, and \delta(q, \tuple{C, m, q}, the mth symbol of~C is~\sigma, and \delta(q, \sigma) is undefined. In that case, the \emph{output} of~M for input I is~O, where O is a string of symbols not beginning or ending in~\TMblank such that C = \TMendtape \concat \TMblank^i \concat O \concat \TMblank^j for some~i, j \in \Nat. input~I is~O, where O is a string of symbols not ending in~\TMblank such that C = \TMendtape \concat O \concat \TMblank^j for some~i, j \in \Nat. \end{defn} \begin{explain} According to this definition, the output~O of~M always begins and According to this definition, the output~O of~M always ends in a symbol other than~\TMblank, or, if at time~k the entire tape is filled with~\TMblank (except for the leftmost~\TMendtape), O is the empty string. O~is the empty string. \end{explain} \end{document} 90 changes: 90 additions & 0 deletions This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters @@ -0,0 +1,90 @@ % Part: turing-machines % Chapter: machines-computations % Section: well-behaved-machines \documentclass[../../../include/open-logic-section]{subfiles} \begin{document} \olfileid{tur}{mac}{dis} \olsection{Disciplined Machines} \begin{explain} In section \olref[hal]{sec}, we considered Turing machines that have a single, designated halting state~h---such machines are guaranteed to halt, if they halt at all, in state~h. In this way, machines with a single halting state are more disciplined'' than we allow Turing machines in general to be. There are other restrictions we might impose on the behavior of Turing machines. For instance, we also have not prohibited Turing machines from ever erasing the tape-end marker on square~0, or to attempt to move left from square~0. (Our definition states that the head simply stays on square~0 in this case; other definitions have the machine halt.) It is likewise sometimes desirable to be able to assume that a Turing machine, if it halts at all, halts on square~1. \end{explain} \begin{defn}\ollabel{defn:disciplined} A Turing machine~M is \emph{disciplined} iff \begin{enumerate} \item it has a designated single halting state~h, \item it halts, if it halts at all, while scanning square~1, \item it never erases the \TMendtape symbol on square~0, and \item it never attempts to move left from square~0. \end{enumerate} \end{defn} \begin{explain} We have already discussed that any Turing machine can be changed into one with the same behavor but with a designated halting state. This is done simply by adding a new state~h, and adding an instruction \delta(q, \sigma) = \tuple{h, \sigma, N} for any pair \tuple{q,\sigma} where the original \delta~is undefined. It is true, although tedious to prove, that any Turing machine~M can be turned into a disciplined Turing machine~M' which halts on the same inputs and produces the same output. For instance, if the Turing machine halts and is not on square~1, we can add some instructions to make the head move left until it finds the tape-end marker, then move one square to the right, then halt. We'll leave you to think about how the other conditions can be dealt with. \end{explain} \begin{ex} In \olref{fig:adder-disc}, we turn the addition machine from \olref[una]{ex:adder} into a disciplined machine. \begin{figure}\[ \begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm, semithick] \tikzstyle{every state}=[fill=none,draw=black,text=black] \node[initial,state] (A) {q_0}; \node[state] (B) [right of=A] {q_1}; \node[state] (C) [below right of=B] {q_2}; \node[state] (D) [below left of=C] {q_3}; \node[state] (H) [left of=D] {h}; \path (A) edge node {\TMtrans{\TMblank}{\TMstroke}{\TMstay}} (B) edge [loop below] node {\TMtrans{\TMstroke}{\TMstroke}{\TMright}} (B) (B) edge [loop below] node {\TMtrans{\TMstroke}{\TMstroke}{\TMright}} (B) edge node {\TMtrans{\TMblank}{\TMblank}{\TMleft}} (C) (C) edge node {\TMtrans{\TMstroke}{\TMblank}{\TMleft}} (D) (D) edge [loop above] node {\TMtrans{\TMstroke}{\TMstroke}{\TMleft}} (D) edge node {\TMtrans{\TMendtape}{\TMendtape}{\TMright}} (H); \end{tikzpicture}$\caption{A disciplined addition machine}
\end{figure}
\end{ex}

\begin{prop}\ollabel{prop:disciplined} For evevery Turing machine~$M$,
there is a disciplined Turing machine~$M'$ which halts with output~$O$
if $M$~halts with output~$O$, and does not halt if $M$~does not halt.
In particular, and function $f\colon\Nat^n \to \Nat$ computable by a
Turing machine is computable by a disciplined Turing machine.
\end{prop}

\begin{prob}\label{tur:mac:dis:prob:disc-succ}
Give a disciplined machine that computes $f(x) = x+1$.
\end{prob}

\end{document}
16 changes: 8 additions & 8 deletions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Expand Up @@ -6,27 +6,27 @@

\begin{document}

\olfileid{tur}{tur}{tur}
\olfileid{tur}{mac}{hal}
\olsection{Halting States}

\begin{explain}
Although we have defined our machines to halt only when there
is no instruction to carry out, common representations of Turing
machines have a dedicated \emph{halting state}, $h$, such that
machines have a dedicated \emph{halting state}~$h$, such that
$h \in Q$.

The idea behind a halting state is simple: when the machine has
finished operation (it is ready to accept input, or has finished writing
the output), it goes into a state $h$ where it halts. Some
machines have two halting states, one that accepts input and one
that rejects input.
finished operation (it is ready to accept input, or has finished
writing the output), it goes into a state~$h$ where it halts. Some
machines have two halting states, one that accepts input and one that
rejects input.
\end{explain}

\begin{ex}\emph{Halting States}.
To elucidate this concept, let us begin with an alteration of the
even machine. Instead of having the machine halt in state $q_0$
even machine. Instead of having the machine halt in state~$q_0$
if the input is even, we can add an instruction to send the machine
into a halt state.
into a halting state.
$\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm, semithick] Expand Down 2 changes: 2 additions & 0 deletions This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Expand Up @@ -19,6 +19,8 @@ \olimport{halting-states} \olimport{disciplined-machines} \olimport{combining-machines} \olimport{variants} Expand Down 8 changes: 4 additions & 4 deletions This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Expand Up @@ -6,7 +6,7 @@ \begin{document} \olfileid{tms}{tms}{rep} \olfileid{tur}{mac}{rep} \olsection{Representing Turing Machines} \begin{explain} Expand Down Expand Up @@ -195,7 +195,7 @@ \multicolumn{1}{l|}{\phantom{\TMtrans{\TMstroke}{q_1}{\TMright}}} & \\ \cline{1-4} \end{tabular}$
As we can see, the machine halts when scanning a blank in state~$q_0$.
As we can see, the machine halts when scanning a~$\TMblank$ in state~$q_0$.
\end{ex}

\begin{explain}
Expand Down Expand Up @@ -256,11 +256,11 @@

\begin{prob}
Choose an arbitary input and trace through the configurations of the
doubler machine in \olref[tms][tms][rep]{ex:doubler}.
doubler machine in \olref[tur][mac][rep]{ex:doubler}.
\end{prob}

\begin{prob}
The double machine in \olref[tms][tms][rep]{ex:doubler} writes its
The double machine in \olref[tur][mac][rep]{ex:doubler} writes its
output to the right of the input. Come up with a new method for
solving the doubler problem which generates its output immediately to
the right of the end-of-tape marker. Build a machine that executes
Expand Down
2 changes: 1 addition & 1 deletion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Expand Up @@ -41,7 +41,7 @@
machine programs to tell when they're in danger'' of running off the
tape. We could assume that this symbol is never overwritten, i.e.,
that $\delta(q,\TMendtape) = \tuple{q', \TMendtape, x}$ if
$\delta(q,\TMendtape)$ is defined. Some textbook do this, we do not.
$\delta(q,\TMendtape)$ is defined. Some textbooks do this, we do not.
You can simply be careful when constructing your Turing machine that
it nevery overwrites~$\TMendtape$. Moreover, there are cases where
allowing such overwriting provides some convenient flexibility.
Expand Down