Turing machines

Turing Machine Computations

Reading preferences

Optional display controls need JavaScript. All reading content and navigation work without it.

Source file content/turing-machines/machines-computations/machines-computations.tex

Source file content/turing-machines/machines-computations/introduction.tex

Introduction

What does it mean for a function, say, from \Natsource to \Natsource to be computable? Among the first answers, and the most well known one, is that a function is computable if it can be computed by a Turing machine. This notion was set out by Alan Turing in 1936. Turing machines are an example of a model of computation---they are a mathematically precise way of defining the idea of a “computational procedure.” What exactly that means is debated, but it is widely agreed that Turing machines are one way of specifying computational procedures. Even though the term “Turing machine” evokes the image of a physical machine with moving parts, strictly speaking a Turing machine is a purely mathematical construct, and as such it idealizes the idea of a computational procedure. For instance, we place no restriction on either the time or memory requirements of a Turing machine: Turing machines can compute something even if the computation would require more storage space or more steps than there are atoms in the universe.

Explain

It is perhaps best to think of a Turing machine as a program for a special kind of imaginary mechanism. This mechanism consists of a tape and a read-write head. In our version of Turing machines, the tape is infinite in one direction (to the right), and it is divided into squares, each of which may contain a symbol from a finite alphabet. Such alphabets can contain any number of different symbols, but we will mainly make do with three: \TMendtapesource, 0\TMblanksource, and 1\TMstrokesource. When the mechanism is started, the tape is empty (i.e., each square contains the symbol 0\TMblanksource) except for the leftmost square, which contains \TMendtapesource, and a finite number of squares which contain the input. At any time, the mechanism is in one of a finite number of states. At the outset, the head scans the leftmost square and in a specified initial state. At each step of the mechanism's run, the content of the square currently scanned together with the state the mechanism is in and the Turing machine program determine what happens next. The Turing machine program is given by a partial function which takes as input a state qqsource and a symbol σ\sigmasource and outputs a triple q,σ,D\tuple{q', \sigma', D}source. Whenever the mechanism is in state qqsource and reads symbol σ\sigmasource, it replaces the symbol on the current square with σ\sigma'source, the head moves left, right, or stays put according to whether DDsource is L\TMleftsource, R\TMrightsource, or N\TMstaysource, and the mechanism goes into state qq'source.

For instance, consider the situation in link to figure A Turing machine executing its program.

Turing machine figure

Figure containing three visual snapshots of a Turing machine executing the transitions described in the following paragraph.

Source transcription

Turing machine execution snapshots. Three stacked tape-and-head snapshots illustrate the example run described by the surrounding source prose. Three successive tape snapshots. The first has a left end marker, then three stroke symbols, a blank symbol, and four more stroke symbols. The head scans the third square from the left in state q one. In the second snapshot it writes a blank symbol, stays on that square, and enters state q two. In the third snapshot it leaves the blank symbol unchanged, moves one square right, and enters state q three. Illustrates three successive snapshots of the example tape, head, and state described immediately after the figure captionA Turing machine executing its program.

The visible part of the tape of the Turing machine contains the end-of-tape symbol \TMendtapesource on the leftmost square, followed by three 11source's, a 00source, and four more 11source's. The head is reading the third square from the left, which contains a 11source, and is in state q1q_1source---we say “the machine is reading a 11source in state q1q_1source.” If the program of the Turing machine returns, for input q1,1\tuple{q_1, 1}source, the triple q2,0,N\tuple{q_2, 0, \TMstay}source, the machine would now replace the 11source on the third square with a 00source, leave the read/write head where it is, and switch to state q2q_2source. If then the program returns q3,0,R\tuple{q_3, 0, \TMright}source for input q2,0\tuple{q_2, 0}source, the machine would now overwrite the 00source with another 00source (effectively, leaving the content of the tape under the read/write head unchanged), move one square to the right, and enter state q3q_3source. And so on.

We say that the machine halts when it encounters some state, qnq_nsource, and symbol, σ\sigmasource such that there is no instruction for qn,σ\tuple{q_n, \sigma}source, i.e., the transition function for input qn,σ\tuple{q_n,\sigma}source is undefined. In other words, the machine has no instruction to carry out, and at that point, it ceases operation. Halting is sometimes represented by a specific halt state hhsource. This will be demonstrated in more detail later on.

Digress

The beauty of Turing's paper, “On computable numbers,” is that he presents not only a formal definition, but also an argument that the definition captures the intuitive notion of computability. From the definition, it should be clear that any function computable by a Turing machine is computable in the intuitive sense. Turing offers three types of argument that the converse is true, i.e., that any function that we would naturally regard as computable is computable by such a machine. They are (in Turing's words):

  1. A direct appeal to intuition.

  2. A proof of the equivalence of two definitions (in case the new definition has a greater intuitive appeal).

  3. Giving examples of large classes of numbers which are computable.

Our goal is to try to define the notion of computability “in principle,” i.e., without taking into account practical limitations of time and space. Of course, with the broadest definition of computability in place, one can then go on to consider computation with bounded resources; this forms the heart of the subject known as “computational complexity.”

History

Alan Turing invented Turing machines in 1936. While his interest at the time was the decidability of first-order logic, the paper has been described as a definitive paper on the foundations of computer design. In the paper, Turing focuses on computable real numbers, i.e., real numbers whose decimal expansions are computable; but he notes that it is not hard to adapt his notions to computable functions on the natural numbers, and so on. Notice that this was a full five years before the first working general purpose computer was built in 1941 (by the German Konrad Zuse in his parent's living room), seven years before Turing and his colleagues at Bletchley Park built the code-breaking Colossus (1943), nine years before the American ENIAC (1945), twelve years before the first British general purpose computer---the Manchester Small-Scale Experimental Machine---was built in Manchester (1948), and thirteen years before the Americans first tested the BINAC (1949). The Manchester SSEM has the distinction of being the first stored-program computer---previous machines had to be rewired by hand for each new task.

Source file content/turing-machines/machines-computations/representing-tms.tex

Representing Turing Machines

Explain

Turing machines can be represented visually by state diagrams. The diagrams are composed of state cells connected by arrows. Unsurprisingly, each state cell represents a state of the machine. Each arrow represents an instruction that can be carried out from that state, with the specifics of the instruction written above or below the appropriate arrow. Consider the following machine, which has only two internal states, q0q_0source and q1q_1source, and one instruction:

Turing machine state diagram

Minimal state diagram with one transition from the initial state to a second state. State diagram. Purpose: Introduces how one arrow encodes reading a blank, writing a stroke, moving right, and entering the target state. Initial state: state q sub zero. States: state q sub zero, state q sub one. Transition one: from state q sub zero, when reading blank symbol, write stroke symbol, move right, and enter state q sub one. States with no outgoing transition shown are state q sub one

state diagram transition tablefrom statereadwritemovenext statestate q sub zeroblank symbolstroke symbolmove rightstate q sub one\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$}; \path (A) edge node {\TMtrans{\TMblank}{\TMstroke}{\TMright}} (B); \end{tikzpicture}source

Recall that the Turing machine has a read/write head and a tape with the input written on it. The instruction can be read as if reading a 0\TMblanksource in state q0q_0source, write a 1\TMstrokesource, move right, and move to state q1q_1source. This is equivalent to the transition function mapping q0,0\tuple{q_0, \TMblank}source to q1,1,R\tuple{q_1, \TMstroke, \TMright}source.

Turing machine example

Even Machine: The following Turing machine halts if, and only if, there are an even number of 1\TMstrokesource's on the tape (under the assumption that all 1\TMstrokesource's come before the first 0\TMblanksource on the tape).

Turing machine state diagram

State diagram for the even machine, alternating states on strokes and looping right forever on a blank in the odd state. State diagram. Purpose: Recognizes even unary length by alternating between two states on strokes. Initial state: state q sub zero. States: state q sub zero, state q sub one. Transition one: from state q sub zero, when reading stroke symbol, write stroke symbol, move right, and enter state q sub one. Transition two: from state q sub one, when reading blank symbol, write blank symbol, move right, and enter state q sub one. Transition three: from state q sub one, when reading stroke symbol, write stroke symbol, move right, and enter state q sub zero. Every displayed state has at least one outgoing transition

state diagram transition tablefrom statereadwritemovenext statestate q sub zerostroke symbolstroke symbolmove rightstate q sub onestate q sub oneblank symbolblank symbolmove rightstate q sub onestate q sub onestroke symbolstroke symbolmove rightstate q sub zero\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$}; \path (A) edge [bend left] node {\TMtrans{\TMstroke}{\TMstroke}{\TMright}} (B) (B) edge [loop above] node {\TMtrans{\TMblank}{\TMblank}{\TMright}} (B) edge [bend left] node {\TMtrans{\TMstroke}{\TMstroke}{\TMright}} (A); \end{tikzpicture}source

The state diagram corresponds to the following transition function:

δ(q0,1)=q1,1,R,δ(q1,1)=q0,1,R,δ(q1,0)=q1,0,R\delta(q_0, \TMstroke) & = \tuple{q_1, \TMstroke, \TMright},\\ \delta(q_1, \TMstroke) & = \tuple{q_0, \TMstroke, \TMright},\\ \delta(q_1, \TMblank) & = \tuple{q_1, \TMblank, \TMright}source

Explain

The above machine halts only when the input is an even number of strokes. Otherwise, the machine (theoretically) continues to operate indefinitely. For any machine and input, it is possible to trace through the configurations of the machine in order to determine the output. We will give a formal definition of configurations later. For now, we can intuitively think of configurations as a series of diagrams showing the state of the machine at any point in time during operation. Configurations show the content of the tape, the state of the machine and the location of the read/write head.

Let us trace through the configurations of the even machine if it is started with an input of four 1\TMstrokesource's. In this case, we expect that the machine will halt. We will then run the machine on an input of three 1\TMstrokesource's, where the machine will run forever.

The machine starts in state q0q_0source, scanning the leftmost 1\TMstrokesource. We can represent the initial state of the machine as follows:

101110\TMendtape \TMstroke_0 \TMstroke \TMstroke \TMstroke \TMblank \ldotssource

The above configuration is straightforward. As can be seen, the machine starts in state one, scanning the leftmost 1\TMstrokesource. This is represented by a subscript of the state name on the first 1\TMstrokesource. The applicable instruction at this point is δ(q0,1)=q1,1,R\delta(q_0, \TMstroke) = \tuple{q_1, \TMstroke, \TMright}source, and so the machine moves right on the tape and changes to state q1q_1source.

111110\TMendtape \TMstroke \TMstroke_1 \TMstroke \TMstroke \TMblank \ldotssource

Since the machine is now in state q1q_1source scanning a 1\TMstrokesource, we have to “follow” the instruction δ(q1,1)=q0,1,R\delta(q_1, \TMstroke) = \tuple{q_0, \TMstroke, \TMright}source. This results in the configuration

111010\TMendtape \TMstroke \TMstroke \TMstroke_0 \TMstroke \TMblank \ldotssource

As the machine continues, the rules are applied again in the same order, resulting in the following two configurations:

111110\TMendtape \TMstroke \TMstroke \TMstroke \TMstroke_1 \TMblank \ldotssource
111100\TMendtape \TMstroke \TMstroke \TMstroke \TMstroke \TMblank_0 \ldotssource

The machine is now in state q0q_0source scanning a 0\TMblanksource. Based on the transition diagram, we can easily see that there is no instruction to be carried out, and thus the machine has halted. This means that the input has been accepted.

Suppose next we start the machine with an input of three 1\TMstrokesource's. The first few configurations are similar, as the same instructions are carried out, with only a small difference of the tape input:

10110\TMendtape \TMstroke_0 \TMstroke \TMstroke \TMblank \ldotssource
11110\TMendtape \TMstroke \TMstroke_1 \TMstroke \TMblank \ldotssource
11100\TMendtape \TMstroke \TMstroke \TMstroke_0 \TMblank \ldotssource
11101\TMendtape \TMstroke \TMstroke \TMstroke \TMblank_1 \ldotssource

The machine has now traversed past all the 1\TMstrokesource's, and is reading a 0\TMblanksource in state q1q_1source. As shown in the diagram, there is an instruction of the form δ(q1,0)=q1,0,R\delta(q_1, \TMblank) =\tuple{q_1, \TMblank, \TMright}source. Since the tape is filled with 0\TMblanksource indefinitely to the right, the machine will continue to execute this instruction forever, staying in state q1q_1source and moving ever further to the right. The machine will never halt, and does not accept the input.

Explain

It is important to note that not all machines will halt. If halting means that the machine runs out of instructions to execute, then we can create a machine that never halts simply by ensuring that there is an outgoing arrow for each symbol at each state. The even machine can be modified to run indefinitely by adding an instruction for scanning a 0\TMblanksource at q0q_0source.

Turing machine example

Turing machine state diagram

Nonhalting variant of the even machine with an added blank loop in the even state. State diagram. Purpose: Adds a blank loop in the even state so every relevant state-symbol pair has a transition and the machine never halts. Initial state: state q sub zero. States: state q sub zero, state q sub one. Transition one: from state q sub zero, when reading stroke symbol, write stroke symbol, move right, and enter state q sub one. Transition two: from state q sub zero, when reading blank symbol, write blank symbol, move right, and enter state q sub zero. Transition three: from state q sub one, when reading blank symbol, write blank symbol, move right, and enter state q sub one. Transition four: from state q sub one, when reading stroke symbol, write stroke symbol, move right, and enter state q sub zero. Every displayed state has at least one outgoing transition

state diagram transition tablefrom statereadwritemovenext statestate q sub zerostroke symbolstroke symbolmove rightstate q sub onestate q sub zeroblank symbolblank symbolmove rightstate q sub zerostate q sub oneblank symbolblank symbolmove rightstate q sub onestate q sub onestroke symbolstroke symbolmove rightstate q sub zero\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$}; \path (A) edge [bend left] node {\TMtrans{\TMstroke}{\TMstroke}{\TMright}} (B) edge [loop above] node {\TMtrans{\TMblank}{\TMblank}{\TMright}} (A) (B) edge [loop above] node {\TMtrans{\TMblank}{\TMblank}{\TMright}} (B) edge [bend left] node {\TMtrans{\TMstroke}{\TMstroke}{\TMright}} (A); \end{tikzpicture}source

Explain

Machine tables are another way of representing Turing machines. Machine tables have the tape alphabet displayed on the xxsource-axis, and the set of machine states across the yysource-axis. Inside the table, at the intersection of each state and symbol, is written the rest of the instruction---the new state, new symbol, and direction of movement. Machine tables make it easy to determine in what state, and for what symbol, the machine halts. Whenever there is a gap in the table is a possible point for the machine to halt. Unlike state diagrams and instruction sets, where the points at which the machine halts are not always immediately obvious, any halting points are quickly identified by finding the gaps in the machine table.

Turing machine example

The machine table for the even machine is:

Turing machine transition table

Machine table with rows for states and columns for blank, stroke, and left-end symbols; its empty cells mark undefined transitions.

stateread symbolresultstate q zeroblank symbolundefined transition, haltstate q zerostroke symbolwrite stroke symbol, move right, enter state q onestate q zeroleft end markerundefined transition, haltstate q oneblank symbolwrite blank symbol, move right, enter state q onestate q onestroke symbolwrite stroke symbol, move right, enter state q zerostate q oneleft end markerundefined transition, halt\centering \begin{tabular}{lllll} \cline{2-4} \multicolumn{1}{l|}{} & \multicolumn{1}{c|}{$\TMblank$} & \multicolumn{1}{c|}{$\TMstroke$} & \multicolumn{1}{c|}{$\TMendtape$} & \\ \cline{1-4} \multicolumn{1}{|l|}{$q_0$} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{\TMtrans{\TMstroke}{q_1}{\TMright}} & \multicolumn{1}{l|}{\phantom{\TMtrans{\TMstroke}{q_1}{\TMright}}} & \\ \cline{1-4} \multicolumn{1}{|l|}{$q_1$} & \multicolumn{1}{l|}{\TMtrans{\TMblank}{q_1}{\TMright}} & \multicolumn{1}{l|}{\TMtrans{\TMstroke}{q_0}{\TMright}} & \multicolumn{1}{l|}{\phantom{\TMtrans{\TMstroke}{q_1}{\TMright}}} & \\ \cline{1-4} \end{tabular}source

As we can see, the machine halts when scanning a 0\TMblanksource in state q0q_0source.

Explain

So far we have only considered machines that read and accept input. However, Turing machines have the capacity to both read and write. An example of such a machine (although there are many, many examples) is a doubler. A doubler, when started with a block of nnsource 1\TMstrokesource's on the tape, outputs a block of 2n2nsource 1\TMstrokesource's.

Turing machine example

Before building a doubler machine, it is important to come up with a strategy for solving the problem. Since the machine (as we have formulated it) cannot remember how many 1\TMstrokesource's it has read, we need to come up with a way to keep track of all the 1\TMstrokesource's on the tape. One such way is to separate the output from the input with a 0\TMblanksource. The machine can then erase the first 1\TMstrokesource from the input, traverse over the rest of the input, leave a 0\TMblanksource, and write two new 1\TMstrokesource's. The machine will then go back and find the second 1\TMstrokesource in the input, and double that one as well. For each one 1\TMstrokesource of input, it will write two 1\TMstrokesource's of output. By erasing the input as the machine goes, we can guarantee that no 1\TMstrokesource is missed or doubled twice. When the entire input is erased, there will be 2n2nsource 1\TMstrokesource's left on the tape. The state diagram of the resulting Turing machine is depicted in link to figure A doubler machine.

Turing machine figure

Figure containing the doubler state diagram.

Source transcription

Turing machine state diagram

Six-state doubler diagram that repeatedly erases one input stroke, appends two output strokes, and returns left for the next cycle. State diagram. Purpose: Doubles a unary block by erasing each input stroke and writing two output strokes. Initial state: state q sub zero. States: state q sub zero, state q sub one, state q sub two, state q sub three, state q sub four, state q sub five. Transition one: from state q sub zero, when reading stroke symbol, write blank symbol, move right, and enter state q sub one. Transition two: from state q sub one, when reading stroke symbol, write stroke symbol, move right, and enter state q sub one. Transition three: from state q sub one, when reading blank symbol, write blank symbol, move right, and enter state q sub two. Transition four: from state q sub two, when reading stroke symbol, write stroke symbol, move right, and enter state q sub two. Transition five: from state q sub two, when reading blank symbol, write stroke symbol, move right, and enter state q sub three. Transition six: from state q sub three, when reading blank symbol, write stroke symbol, move left, and enter state q sub three. Transition seven: from state q sub three, when reading stroke symbol, write stroke symbol, move left, and enter state q sub four. Transition eight: from state q sub four, when reading stroke symbol, write stroke symbol, move left, and enter state q sub four. Transition nine: from state q sub four, when reading blank symbol, write blank symbol, move left, and enter state q sub five. Transition ten: from state q sub five, when reading stroke symbol, write stroke symbol, move left, and enter state q sub five. Transition eleven: from state q sub five, when reading blank symbol, write blank symbol, move right, and enter state q sub zero. Every displayed state has at least one outgoing transition

state diagram transition tablefrom statereadwritemovenext statestate q sub zerostroke symbolblank symbolmove rightstate q sub onestate q sub onestroke symbolstroke symbolmove rightstate q sub onestate q sub oneblank symbolblank symbolmove rightstate q sub twostate q sub twostroke symbolstroke symbolmove rightstate q sub twostate q sub twoblank symbolstroke symbolmove rightstate q sub threestate q sub threeblank symbolstroke symbolmove leftstate q sub threestate q sub threestroke symbolstroke symbolmove leftstate q sub fourstate q sub fourstroke symbolstroke symbolmove leftstate q sub fourstate q sub fourblank symbolblank symbolmove leftstate q sub fivestate q sub fivestroke symbolstroke symbolmove leftstate q sub fivestate q sub fiveblank symbolblank symbolmove rightstate q sub zero\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm, semithick] \tikzstyle{every state}=[fill=none,draw=black,text=black] \node[initial,state] (1) {$q_0$}; \node[state] (2) [right of=1] {$q_1$}; \node[state] (3) [right of=2] {$q_2$}; \node[state] (4) [below of=3] {$q_3$}; \node[state] (5) [left of=4] {$q_4$}; \node[state] (6) [left of=5] {$q_5$}; \path (1) edge node {\TMtrans{\TMstroke}{\TMblank}{\TMright}} (2) (2) edge [loop above] node {\TMtrans{\TMstroke}{\TMstroke}{\TMright}} (2) edge node {\TMtrans{\TMblank}{\TMblank}{\TMright}} (3) (3) edge [loop above] node {\TMtrans{\TMstroke}{\TMstroke}{\TMright}} (3) edge node {\TMtrans{\TMblank}{\TMstroke}{\TMright}} (4) (4) edge [loop below] node {\TMtrans{\TMblank}{\TMstroke}{\TMleft}} (4) edge node {\TMtrans{\TMstroke}{\TMstroke}{\TMleft}} (5) (5) edge [loop below] node {\TMtrans{\TMstroke}{\TMstroke}{\TMleft}} (5) edge node {\TMtrans{\TMblank}{\TMblank}{\TMleft}} (6) (6) edge [loop below] node {\TMtrans{\TMstroke}{\TMstroke}{\TMleft}} (6) edge node {\TMtrans{\TMblank}{\TMblank}{\TMright}} (1); \end{tikzpicture}source

captionA doubler machine

Unsolved Turing machine exercise

Choose an arbitrary input and trace through the configurations of the doubler machine in link to example Doubler machine.

Unsolved Turing machine exercise

Design a Turing-machine with alphabet {,0,A,B}\{\TMendtape,\TMblank, A, B\}source that accepts, i.e., halts on, any string of AAsource's and BBsource's where the number of AAsource's is the same as the number of BBsource's and all the AAsource's precede all the BBsource's, and rejects, i.e., does not halt on, any string where the number of AAsource's is not equal to the number of BBsource's or the AAsource's do not precede all the BBsource's. (E.g., the machine should accept AABBAABBsource, and AAABBBAAABBBsource, but reject both AABAABsource and AABBAABBAABBAABBsource.)

Unsolved Turing machine exercise

Design a Turing-machine with alphabet {,0,A,B}\{\TMendtape,\TMblank, A, B\}source that takes as input any string α\alphasource of AAsource's and BBsource's and duplicates them to produce an output of the form αα\alpha\alphasource. (E.g. input ABBAABBAsource should result in output ABBAABBAABBAABBAsource).

Unsolved Turing machine exercise

Alphabetical?: Design a Turing-machine with alphabet {,0,A,B}\{\TMendtape,\TMblank, A, B\}source that when given as input a finite sequence of AAsource's and BBsource's checks to see if all the AAsource's appear to the left of all the BBsource's or not. The machine should leave the input string on the tape, and either halt if the string is “alphabetical”, or loop forever if the string is not.

Unsolved Turing machine exercise

Alphabetizer: Design a Turing-machine with alphabet {,0,A,B}\{\TMendtape,\TMblank, A, B\}source that takes as input a finite sequence of AAsource's and BBsource's rearranges them so that all the AAsource's are to the left of all the BBsource's. (e.g., the sequence BABAABABAAsource should become the sequence AAABBAAABBsource, and the sequence ABBABBABBABBsource should become the sequence AABBBBAABBBBsource).

Source file content/turing-machines/machines-computations/turing-machines.tex

Turing Machines

Explain

The formal definition of what constitutes a Turing machine looks abstract, but is actually simple: it merely packs into one mathematical structure all the information needed to specify the workings of a Turing machine. This includes (1) which states the machine can be in, (2) which symbols are allowed to be on the tape, (3) which state the machine should start in, and (4) what the instruction set of the machine is.

Turing machine definition

[Turing machine] A Turing machine MMsource is a tuple Q,Σ,q0,δ\langle Q, \Sigma, q_0, \delta\ranglesource consisting of

  1. a finite set of states QQsource,

  2. a finite alphabet Σ\Sigmasource which includes \TMendtapesource and 0\TMblanksource,

  3. an initial state q0Qq_0 \in Qsource,

  4. a finite instruction set δ:Q×ΣQ×Σ×{L,R,N}\delta\colon Q \times \Sigma \pto Q \times \Sigma \times \{\TMleft, \TMright, \TMstay\}source.

The partial function δ\deltasource is also called the transition function of MMsource.

Explain

We assume that the tape is infinite in one direction only. For this reason it is useful to designate a special symbol \TMendtapesource as a marker for the left end of the tape. This makes it easier for Turing 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 δ(q,)=q,,x\delta(q,\TMendtape) = \tuple{q', \TMendtape, x}source if δ(q,)\delta(q,\TMendtape)source is defined. Some textbooks do this, we do not. You can simply be careful when constructing your Turing machine that it never overwrites \TMendtapesource. Moreover, there are cases where allowing such overwriting provides some convenient flexibility.

Turing machine example

Even Machine: The even machine is formally the quadruple Q,Σ,q0,δ\tuple{Q, \Sigma, q_0, \delta}source where

Q={q0,q1}Σ={,0,1},δ(q0,1)=q1,1,R,δ(q1,1)=q0,1,R,δ(q1,0)=q1,0,R.Q & = \{ q_0, q_1 \} \\ \Sigma & = \{ \TMendtape, \TMblank, \TMstroke \}, \\ \delta(q_0, \TMstroke) & = \tuple{q_1, \TMstroke, \TMright},\\ \delta(q_1, \TMstroke) & = \tuple{q_0, \TMstroke, \TMright},\\ \delta(q_1, \TMblank) & = \tuple{q_1, \TMblank, \TMright}.source

Source file content/turing-machines/machines-computations/configuration.tex

Configurations and Computations

Explain

Recall tracing through the configurations of the even machine earlier. The imaginary mechanism consisting of tape, read/write head, and Turing machine program is really just an intuitive way of visualizing what a Turing machine computation is. Formally, we can define the computation of a Turing machine on a given input as a sequence of 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 MMsource computes on a given input.

Turing machine definition

[Configuration] A configuration of Turing machine M=Q,Σ,q0,δM = \tuple{Q, \Sigma, q_0, \delta}source is a triple C,m,q\tuple{C, m, q}source where

  1. CΣ*C \in \Sigma^*source is a finite sequence of symbols from Σ\Sigmasource,

  2. mm \in \Natsource is a number <len(C)< \len{C}source, and

  3. qQq \in Qsource

Intuitively, the sequence CCsource is the content of the tape (symbols of all squares from the leftmost square to the last non-blank or previously visited square), mmsource is the number of the square the read/write head is scanning (beginning with 00source being the number of the leftmost square), and qqsource is the current state of the machine.

Explain

The potential input for a Turing machine is a sequence of symbols, usually a sequence that encodes a number in some form. The initial configuration of the Turing machine is that configuration in which we start the Turing machine to work on that input: the tape contains the tape end marker immediately followed by the input written on the squares to the right, the read/write head is scanning the leftmost square of the input (i.e., the square to the right of the left end marker), and the mechanism is in the designated start state q0q_0source.

Turing machine definition

[Initial configuration] The initial configuration of MMsource for input IΣ*I \in \Sigma^*source is

I,1,q0\tuple{\TMendtape \frown I, 1, q_0}source

Explain

The \frownsource symbol is for concatenation---the input string begins immediately to the left end marker.

Turing machine definition

We say that a configuration C,m,q\tuple{C, m, q}source yields the configuration C,m,q\tuple{C', m', q'}source in one step (according to MMsource), iff

  1. the mmsource-th symbol of CCsource is σ\sigmasource,

  2. the instruction set of MMsource specifies δ(q,σ)=q,σ,D\delta(q, \sigma) = \tuple{q', \sigma', D}source,

  3. the mmsource-th symbol of CC'source is σ\sigma'source, and

    1. D=LD = Lsource and m=m1m' = m - 1source if m>0m>0source, otherwise m=0m'=0source, or

    2. D=RD = Rsource and m=m+1m' = m + 1source, or

    3. D=ND = Nsource and m=mm' = msource,

  4. if m=len(C)m' = \len{C}source, then len(C)=len(C)+1\len{C'} = \len{C} + 1source and the mm'source-th symbol of CC'source is 0\TMblanksource. Otherwise len(C)=len(C)\len{C'}=\len{C}source.

  5. for all iisource such that i<len(C)i < \len{C}source and imi \neq msource, C(i)=C(i)C'(i) = C(i)source,

Turing machine definition

A run of MMsource on input IIsource is a sequence CiC_isource of configurations of MMsource, where C0C_0source is the initial configuration of MMsource for input IIsource, and each CiC_isource yields Ci+1C_{i+1}source in one step.

We say that MMsource halts on input IIsource after kksource steps if Ck=C,m,qC_k = \tuple{C, m, q}source, the mmsourceth symbol of CCsource is σ\sigmasource, and δ(q,σ)\delta(q, \sigma)source is undefined. In that case, the output of MMsource for input IIsource is OOsource, where OOsource is a string of symbols not ending in 0\TMblanksource such that C=O0jC = \TMendtape \concat O \concat \TMblank^jsource for some jj \in \Natsource. (0j\TMblank^jsource is a sequence of jjsource 0\TMblanksource's.)

Explain

According to this definition, the output OOsource of MMsource always ends in a symbol other than 0\TMblanksource, or, if at time kksource the entire tape is filled with 0\TMblanksource (except for the leftmost \TMendtapesource), OOsource is the empty string.

Source file content/turing-machines/machines-computations/unary-numbers.tex

Unary Representation of Numbers

Explain

Turing machines work on sequences of symbols written on their tape. Depending on the alphabet a Turing machine uses, these sequences of symbols can represent various inputs and outputs. Of particular interest, of course, are Turing machines which compute arithmetical functions, i.e., functions of natural numbers. A simple way to represent positive integers is by coding them as sequences of a single symbol 1\TMstrokesource. If nn \in \Natsource, let 1n\TMstroke^nsource be the empty sequence if n=0n = 0source, and otherwise the sequence consisting of exactly nnsource 1\TMstrokesource's.

Turing machine definition

[Computation] A Turing machine MMsource computes the function f:kf\colon \Nat^k \to \Natsource iff MMsource halts on input

1n101n2001nk\TMstroke^{n_1} \TMblank \TMstroke^{n_2} \TMblank \dots \TMblank \TMstroke^{n_k}source

with output 1f(n1,,nk)\TMstroke^{f(n_1, \dots, n_k)}source.

Unsolved Turing machine exercise

Give a definition for when a Turing machine MMsource computes the function f:kmf\colon \Nat^k \to \Nat^msource.

Turing machine example

Addition: Let's build a machine that computes the function f(n,m)=n+mf(n,m) = n + msource. This requires a machine that starts with two blocks of 1\TMstrokesource's of length nnsource and mmsource on the tape, and halts with one block consisting of n+mn+msource 1\TMstrokesource's. The two input blocks of 1\TMstrokesource's are separated by a 0\TMblanksource, so one method would be to write a stroke on the square containing the 0\TMblanksource, and erase the last 1\TMstrokesource.

Turing machine figure

Figure containing the unary addition state diagram.

Source transcription

Turing machine state diagram

Three-state addition diagram that fills the separator blank and erases the final stroke. State diagram. Purpose: Adds two unary numbers by filling their separator and erasing the final stroke. Initial state: state q sub zero. States: state q sub zero, state q sub one, state q sub two. Transition one: from state q sub zero, when reading blank symbol, write stroke symbol, stay put, and enter state q sub one. Transition two: from state q sub zero, when reading stroke symbol, write stroke symbol, move right, and enter state q sub one. Transition three: from state q sub one, when reading stroke symbol, write stroke symbol, move right, and enter state q sub one. Transition four: from state q sub one, when reading blank symbol, write blank symbol, move left, and enter state q sub two. Transition five: from state q sub two, when reading stroke symbol, write blank symbol, stay put, and enter state q sub two. Every displayed state has at least one outgoing transition

state diagram transition tablefrom statereadwritemovenext statestate q sub zeroblank symbolstroke symbolstay putstate q sub onestate q sub zerostroke symbolstroke symbolmove rightstate q sub onestate q sub onestroke symbolstroke symbolmove rightstate q sub onestate q sub oneblank symbolblank symbolmove leftstate q sub twostate q sub twostroke symbolblank symbolstay putstate q sub two\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) [right of=B] {$q_2$}; \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}source

captionA machine computing f(x,y)=x+yf(x,y) = x+ysource

Unsolved Turing machine exercise

Trace through the configurations of the machine from link to example Addition machine for input 3,2\tuple{3,2}source. What happens if the machine computes 0+00+0source?

Explain

In link to example Doubler machine, we gave an example of a Turing machine that takes as input a sequence of 1\TMstrokesource's and halts with a sequence of twice as many 1\TMstrokesource's on the tape---the doubler machine. However, because the output contains 0\TMblanksource's to the left of the doubled block of 1\TMstrokesource's, it does not actually compute the function f(x)=2xf(x) = 2xsource, as you might have assumed. We'll describe two ways of fixing that.

Turing machine example

The machine in link to figure Machine computing doubling computes the function f(x)=2xf(x) = 2xsource. Instead of erasing the input and writing two 1\TMstrokesource's at the far right for every 1\TMstrokesource in the input as the machine from link to example Doubler machine does, this machine adds a single 1\TMstrokesource to the right for every 1\TMstrokesource in the input. It has to keep track of where the input ends, so it leaves a 0\TMblanksource between the input and the added strokes, which it fills with a 1\TMstrokesource at the very end. And we have to “remember” where we are in the input, so we temporarily replace a 1\TMstrokesource in the input block by a 0\TMblanksource.

Turing machine figure

Figure containing the corrected doubler state diagram.

Source transcription

Turing machine state diagram

Nine-state doubler diagram that marks progress, appends strokes, returns left, and removes temporary separators. State diagram. Purpose: Computes doubling while maintaining a contiguous output block. Initial state: state q sub zero. States: state q sub zero, state q sub one, state q sub two, state q sub three, state q sub four, state q sub five, state q sub six, state q sub seven, state q sub eight. Transition one: from state q sub zero, when reading stroke symbol, write blank symbol, move right, and enter state q sub one. Transition two: from state q sub one, when reading stroke symbol, write stroke symbol, move right, and enter state q sub one. Transition three: from state q sub one, when reading blank symbol, write blank symbol, move right, and enter state q sub two. Transition four: from state q sub two, when reading stroke symbol, write stroke symbol, move right, and enter state q sub two. Transition five: from state q sub two, when reading blank symbol, write stroke symbol, move left, and enter state q sub three. Transition six: from state q sub three, when reading stroke symbol, write stroke symbol, move left, and enter state q sub three. Transition seven: from state q sub three, when reading blank symbol, write blank symbol, move left, and enter state q sub four. Transition eight: from state q sub four, when reading stroke symbol, write stroke symbol, move left, and enter state q sub five. Transition nine: from state q sub five, when reading stroke symbol, write stroke symbol, move left, and enter state q sub five. Transition ten: from state q sub five, when reading blank symbol, write stroke symbol, move right, and enter state q sub zero. Transition eleven: from state q sub four, when reading blank symbol, write stroke symbol, move right, and enter state q sub six. Transition twelve: from state q sub six, when reading blank symbol, write stroke symbol, move right, and enter state q sub seven. Transition thirteen: from state q sub seven, when reading stroke symbol, write stroke symbol, move right, and enter state q sub seven. Transition fourteen: from state q sub seven, when reading blank symbol, write blank symbol, move left, and enter state q sub eight. Transition fifteen: from state q sub eight, when reading stroke symbol, write blank symbol, stay put, and enter state q sub eight. Every displayed state has at least one outgoing transition

state diagram transition tablefrom statereadwritemovenext statestate q sub zerostroke symbolblank symbolmove rightstate q sub onestate q sub onestroke symbolstroke symbolmove rightstate q sub onestate q sub oneblank symbolblank symbolmove rightstate q sub twostate q sub twostroke symbolstroke symbolmove rightstate q sub twostate q sub twoblank symbolstroke symbolmove leftstate q sub threestate q sub threestroke symbolstroke symbolmove leftstate q sub threestate q sub threeblank symbolblank symbolmove leftstate q sub fourstate q sub fourstroke symbolstroke symbolmove leftstate q sub fivestate q sub fivestroke symbolstroke symbolmove leftstate q sub fivestate q sub fiveblank symbolstroke symbolmove rightstate q sub zerostate q sub fourblank symbolstroke symbolmove rightstate q sub sixstate q sub sixblank symbolstroke symbolmove rightstate q sub sevenstate q sub sevenstroke symbolstroke symbolmove rightstate q sub sevenstate q sub sevenblank symbolblank symbolmove leftstate q sub eightstate q sub eightstroke symbolblank symbolstay putstate q sub eight\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm, semithick] \tikzstyle{every state}=[fill=none,draw=black,text=black] \node[initial,state] (0) {$q_0$}; \node[state] (1) [above of=0] {$q_1$}; \node[state] (2) [above of=1] {$q_2$}; \node[state] (3) [right of=2] {$q_3$}; \node[state] (4) [below of=3] {$q_4$}; \node[state] (5) [below of=4] {$q_5$}; \node[state] (6) [above right of=4] {$q_6$}; \node[state] (7) [below of=6] {$q_7$}; \node[state] (8) [below of=7] {$q_8$}; \path (0) edge node {\TMtrans{\TMstroke}{\TMblank}{\TMright}} (1) (1) edge [loop left] node {\TMtrans{\TMstroke}{\TMstroke}{\TMright}} (1) edge node {\TMtrans{\TMblank}{\TMblank}{\TMright}} (2) (2) edge [loop above] node {\TMtrans{\TMstroke}{\TMstroke}{\TMright}} (2) edge node {\TMtrans{\TMblank}{\TMstroke}{\TMleft}} (3) (3) edge [loop above] node {\TMtrans{\TMstroke}{\TMstroke}{\TMleft}} (3) edge node[left] {\TMtrans{\TMblank}{\TMblank}{\TMleft}} (4) (4) edge node[left] {\TMtrans{\TMstroke}{\TMstroke}{\TMleft}} (5) (5) edge [loop below] node {\TMtrans{\TMstroke}{\TMstroke}{\TMleft}} (5) edge node {\TMtrans{\TMblank}{\TMstroke}{\TMright}} (0) (4) edge node[sloped] {\TMtrans{\TMblank}{\TMstroke}{\TMright}} (6) (6) edge node {\TMtrans{\TMblank}{\TMstroke}{\TMright}} (7) (7) edge [loop right] node {\TMtrans{\TMstroke}{\TMstroke}{\TMright}} (7) edge node {\TMtrans{\TMblank}{\TMblank}{\TMleft}} (8) (8) edge [loop right] node {\TMtrans{\TMstroke}{\TMblank}{\TMstay}} (8); \end{tikzpicture}source

captionA machine computing f(x)=2xf(x) = 2xsource

Turing machine example

A second possibility for computing f(x)=2xf(x) = 2xsource is to keep the original doubler machine, but add states and instructions at the end which move the doubled block of strokes to the far left of the tape. The machine in link to figure Moving a block of strokes to the left does just this last part: started on a tape consisting of a block of 0\TMblanksource's followed by a block of 1\TMstrokesource's (and the head positioned anywhere in the block of 0\TMblanksource's), it erases the 1\TMstrokesource's one at a time and writes them at the beginning of the tape. In order to be able to tell when it is done, it first marks the end of the block of 1\TMstrokesource's with a \TMendtapesource symbol, which gets deleted at the end. We've started numbering the states at q6q_6source, so they can be added to the doubler machine. All you'll need is an additional instruction δ(q0,0)=q6,0,N\delta(q_0, \TMblank) = \tuple{q_6,\TMblank,\TMstay}source, i.e., an arrow from q0q_0source to q6q_6source labelled 0,0,N\TMtrans{\TMblank}{\TMblank}{\TMstay}source. (There is one subtle problem: the resulting machine does not work for input x=0x=0source. We'll leave this as an exercise.)

Turing machine figure

Figure containing the mover state diagram.

Source transcription

Turing machine state diagram

Nine-state mover diagram that marks the right boundary, transfers strokes left one at a time, and deletes the temporary marker. State diagram. Purpose: Moves a block of strokes left and removes the temporary right boundary marker. Initial state: state q sub six. States: state q sub six, state q sub seven, state q sub eight, state q sub nine, state q sub ten, state q sub eleven, state q sub twelve, state q sub thirteen, state q sub fourteen. Transition one: from state q sub six, when reading blank symbol, write blank symbol, move right, and enter state q sub seven. Transition two: from state q sub seven, when reading blank symbol, write blank symbol, move right, and enter state q sub seven. Transition three: from state q sub seven, when reading stroke symbol, write stroke symbol, move right, and enter state q sub eight. Transition four: from state q sub eight, when reading stroke symbol, write stroke symbol, move right, and enter state q sub eight. Transition five: from state q sub eight, when reading blank symbol, write left end marker, move left, and enter state q sub nine. Transition six: from state q sub nine, when reading stroke symbol, write stroke symbol, move left, and enter state q sub nine. Transition seven: from state q sub nine, when reading blank symbol, write blank symbol, move right, and enter state q sub ten. Transition eight: from state q sub ten, when reading stroke symbol, write blank symbol, move left, and enter state q sub eleven. Transition nine: from state q sub eleven, when reading blank symbol, write blank symbol, move left, and enter state q sub eleven. Transition ten: from state q sub eleven, when reading left end marker, write left end marker, move right, and enter state q sub twelve. Transition eleven: from state q sub eleven, when reading stroke symbol, write stroke symbol, move right, and enter state q sub twelve. Transition twelve: from state q sub twelve, when reading blank symbol, write stroke symbol, move right, and enter state q sub thirteen. Transition thirteen: from state q sub thirteen, when reading blank symbol, write blank symbol, move right, and enter state q sub thirteen. Transition fourteen: from state q sub thirteen, when reading stroke symbol, write blank symbol, move left, and enter state q sub eleven. Transition fifteen: from state q sub thirteen, when reading left end marker, write blank symbol, stay put, and enter state q sub fourteen. States with no outgoing transition shown are state q sub fourteen

Turing machine transition table

Two-line transition label on one mover edge, allowing the same state change after reading either the left-end marker or a stroke.

state diagram transition tablefrom statereadwritemovenext statestate q sub sixblank symbolblank symbolmove rightstate q sub sevenstate q sub sevenblank symbolblank symbolmove rightstate q sub sevenstate q sub sevenstroke symbolstroke symbolmove rightstate q sub eightstate q sub eightstroke symbolstroke symbolmove rightstate q sub eightstate q sub eightblank symbolleft end markermove leftstate q sub ninestate q sub ninestroke symbolstroke symbolmove leftstate q sub ninestate q sub nineblank symbolblank symbolmove rightstate q sub tenstate q sub tenstroke symbolblank symbolmove leftstate q sub elevenstate q sub elevenblank symbolblank symbolmove leftstate q sub elevenstate q sub elevenleft end markerleft end markermove rightstate q sub twelvestate q sub elevenstroke symbolstroke symbolmove rightstate q sub twelvestate q sub twelveblank symbolstroke symbolmove rightstate q sub thirteenstate q sub thirteenblank symbolblank symbolmove rightstate q sub thirteenstate q sub thirteenstroke symbolblank symbolmove leftstate q sub elevenstate q sub thirteenleft end markerblank symbolstay putstate q sub fourteen\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm, semithick] \tikzstyle{every state}=[fill=none,draw=black,text=black] \node[initial,state] (6) {$q_6$}; \node[state] (7) [right of=6] {$q_7$}; \node[state] (8) [right of=7] {$q_8$}; \node[state] (9) [below of=8] {$q_9$}; \node[state] (10) [left of=9] {$q_{10}$}; \node[state] (11) [left of=10] {$q_{11}$}; \node[state] (12) [below of=11] {$q_{12}$}; \node[state] (13) [right of=12] {$q_{13}$}; \node[state] (14) [right of=13] {$q_{14}$}; \path (6) edge node {\TMtrans{\TMblank}{\TMblank}{\TMright}} (7) (7) edge [loop above] node {\TMtrans{\TMblank}{\TMblank}{\TMright}} (7) edge node {\TMtrans{\TMstroke}{\TMstroke}{\TMright}} (8) (8) edge [loop above] node {\TMtrans{\TMstroke}{\TMstroke}{\TMright}} (8) edge node {\TMtrans{\TMblank}{\TMendtape}{\TMleft}} (9) (9) edge [loop right] node {\TMtrans{\TMstroke}{\TMstroke}{\TMleft}} (9) edge node {\TMtrans{\TMblank}{\TMblank}{\TMright}} (10) (10) edge node[above] {\TMtrans{\TMstroke}{\TMblank}{\TMleft}} (11) (11) edge [loop above] node {\TMtrans{\TMblank}{\TMblank}{\TMleft}} (11) edge node[left] {\begin{tabular}{@{}l@{}} \TMtrans{\TMendtape}{\TMendtape}{\TMright}\\ \TMtrans{\TMstroke}{\TMstroke}{\TMright} \end{tabular}} (12) (12) edge node[] {\TMtrans{\TMblank}{\TMstroke}{\TMright}} (13) (13) edge [loop below] node {\TMtrans{\TMblank}{\TMblank}{\TMright}} (13) edge node[sloped] {\TMtrans{\TMstroke}{\TMblank}{\TMleft}} (11) (13) edge node {\TMtrans{\TMendtape}{\TMblank}{\TMstay}} (14); \end{tikzpicture}source

captionMoving a block of 1\TMstrokesource's to the left

Unsolved Turing machine exercise

In link to example Mover machine we described a machine consisting of a combination of the doubler machine from link to figure Machine computing doubling and the mover machine from link to figure Moving a block of strokes to the left. What happens if you start this combined machine on input x=0x=0source, i.e., on an empty tape? How would you fix the machine so that in this case the machine halts with output 2x=02x=0source? (You should be able to do this by adding one state and one transition.)

Unsolved Turing machine exercise

Subtraction: Design a Turing machine that when given an input of two non-empty strings of strokes of length nnsource and mmsource, where n>mn > msource, computes the function f(n,m)=nmf(n,m) = n - msource.

Unsolved Turing machine exercise

Equality: Design a Turing machine to compute the following function:

equality(n,m)={1if~n=m0if~nm\fn{equality}(n,m) = \begin{cases} \text{1} & \text{if~$n = m$} \\ \text{0} & \text{if~$n \neq m$} \end{cases}source

where nnsource and mZ+m \in \PosIntsource.

Unsolved Turing machine exercise

Design a Turing machine to compute the function min(x,y)\min(x,y)source where xxsource and yysource are positive integers represented on the tape by strings of 1\TMstrokesource's separated by a 0\TMblanksource. You may use additional symbols in the alphabet of the machine.

The function min\minsource selects the smallest value from its arguments, so min(3,5)=3\min(3,5)=3source, min(20,16)=16\min(20,16)=16source, and min(4,4)=4\min(4,4)=4source, and so on.

Turing machine definition

A Turing machine MMsource computes the partial function f:kf\colon \Nat^k \pto \Natsource iff,

  1. MMsource halts on input 1n1001nk\TMstroke^{n_1}\concat\TMblank\concat \dots \concat\TMblank\concat\TMstroke^{n_k}source with output 1m\TMstroke^{m}source if f(n1,,nk)=mf(n_1, \dots, n_k) = msource.

  2. MMsource does not halt at all, or with an output that is not a single block of 1\TMstrokesource's if f(n1,,nk)f(n_1, \dots, n_k)source is undefined.

Source file content/turing-machines/machines-computations/halting-states.tex

Halting States

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 halting state hhsource, such that hQh \in Qsource.

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 hhsource where it halts. Some machines have two halting states, one that accepts input and one that rejects input.

Turing machine example

Halting States. To elucidate this concept, let us begin with an alteration of the even machine. Instead of having the machine halt in state q0q_0source if the input is even, we can add an instruction to send the machine into a halting state.

Turing machine state diagram

Even-machine state diagram with a dedicated accepting halt state reached on a blank in the even state. State diagram. Purpose: Sends even input to an accepting halt state while odd input continues right on blanks. Initial state: state q sub zero. States: state q sub zero, state q sub one, state h. Transition one: from state q sub zero, when reading stroke symbol, write stroke symbol, move right, and enter state q sub one. Transition two: from state q sub zero, when reading blank symbol, write blank symbol, stay put, and enter state h. Transition three: from state q sub one, when reading blank symbol, write blank symbol, move right, and enter state q sub one. Transition four: from state q sub one, when reading stroke symbol, write stroke symbol, move right, and enter state q sub zero. States with no outgoing transition shown are state h

state diagram transition tablefrom statereadwritemovenext statestate q sub zerostroke symbolstroke symbolmove rightstate q sub onestate q sub zeroblank symbolblank symbolstay putstate hstate q sub oneblank symbolblank symbolmove rightstate q sub onestate q sub onestroke symbolstroke symbolmove rightstate q sub zero\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 of=A] {$h$}; \path (A) edge [bend left] node {\TMtrans{\TMstroke}{\TMstroke}{R}} (B) edge node {\TMtrans{\TMblank}{\TMblank}{N}} (C) (B) edge [loop above] node {\TMtrans{\TMblank}{\TMblank}{R}} (B) edge [bend left] node {\TMtrans{\TMstroke}{\TMstroke}{R}} (A); \end{tikzpicture}source

Let us further expand the example. When the machine determines that the input is odd, it never halts. We can alter the machine to include a reject state by replacing the looping instruction with an instruction to go to a reject state rrsource.

Turing machine state diagram

Even-machine state diagram with distinct accept and reject terminal states. State diagram. Purpose: Sends even input to an accept state and odd input to a reject state. Initial state: state q sub zero. States: state q sub zero, state q sub one, state h, state r. Transition one: from state q sub zero, when reading stroke symbol, write stroke symbol, move right, and enter state q sub one. Transition two: from state q sub zero, when reading blank symbol, write blank symbol, stay put, and enter state h. Transition three: from state q sub one, when reading blank symbol, write blank symbol, stay put, and enter state r. Transition four: from state q sub one, when reading stroke symbol, write stroke symbol, move right, and enter state q sub zero. States with no outgoing transition shown are state h, state r

state diagram transition tablefrom statereadwritemovenext statestate q sub zerostroke symbolstroke symbolmove rightstate q sub onestate q sub zeroblank symbolblank symbolstay putstate hstate q sub oneblank symbolblank symbolstay putstate rstate q sub onestroke symbolstroke symbolmove rightstate q sub zero\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 of=A] {$h$}; \node[state] (D) [below of=B] {$r$}; \path (A) edge [bend left] node {\TMtrans{\TMstroke}{\TMstroke}{R}} (B) edge node {\TMtrans{\TMblank}{\TMblank}{N}} (C) (B) edge node {\TMtrans{\TMblank}{\TMblank}{N}} (D) edge [bend left] node {\TMtrans{\TMstroke}{\TMstroke}{R}} (A); \end{tikzpicture}source

Explain

Adding a dedicated halting state can be advantageous in cases like this, where it makes explicit when the machine accepts/rejects certain inputs. However, it is important to note that no computing power is gained by adding a dedicated halting state. Similarly, a less formal notion of halting has its own advantages. The definition of halting used so far in this chapter makes the proof of the Halting Problem intuitive and easy to demonstrate. For this reason, we continue with our original definition.

Source file content/turing-machines/machines-computations/disciplined-machines.tex

Disciplined Machines

Explain

In section link to section Halting States, we considered Turing machines that have a single, designated halting state hhsource---such machines are guaranteed to halt, if they halt at all, in state hhsource. 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 00source, or to attempt to move left from square 00source. (Our definition states that the head simply stays on square 00source 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 11source.

Turing machine definition

A Turing machine MMsource is disciplined iff

  1. it has a designated single halting state hhsource,

  2. it halts, if it halts at all, while scanning square 11source,

  3. it never erases the \TMendtapesource symbol on square 00source, and

  4. it never attempts to move left from square 00source.

Explain

We have already discussed that any Turing machine can be changed into one with the same behavior but with a designated halting state. This is done simply by adding a new state hhsource, and adding an instruction δ(q,σ)=h,σ,N\delta(q, \sigma) = \tuple{h, \sigma, N}source for any pair q,σ\tuple{q,\sigma}source where the original δ\deltasource is undefined. It is true, although tedious to prove, that any Turing machine MMsource can be turned into a disciplined Turing machine MM'source which halts on the same inputs and produces the same output. For instance, if the Turing machine halts and is not on square 11source, 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.

Turing machine example

In link to figure Disciplined addition machine, we turn the addition machine from link to example Addition machine into a disciplined machine.

Turing machine figure

Figure containing the disciplined addition state diagram.

Source transcription

Turing machine state diagram

State diagram for disciplined addition, including cleanup to the left marker and entry into the halting state. State diagram. Purpose: Adds cleanup and a unique halt state to unary addition. Initial state: state q sub zero. States: state q sub zero, state q sub one, state q sub two, state q sub three, state h. Transition one: from state q sub zero, when reading blank symbol, write stroke symbol, stay put, and enter state q sub one. Transition two: from state q sub zero, when reading stroke symbol, write stroke symbol, move right, and enter state q sub one. Transition three: from state q sub one, when reading stroke symbol, write stroke symbol, move right, and enter state q sub one. Transition four: from state q sub one, when reading blank symbol, write blank symbol, move left, and enter state q sub two. Transition five: from state q sub two, when reading stroke symbol, write blank symbol, move left, and enter state q sub three. Transition six: from state q sub three, when reading stroke symbol, write stroke symbol, move left, and enter state q sub three. Transition seven: from state q sub three, when reading left end marker, write left end marker, move right, and enter state h. States with no outgoing transition shown are state h

state diagram transition tablefrom statereadwritemovenext statestate q sub zeroblank symbolstroke symbolstay putstate q sub onestate q sub zerostroke symbolstroke symbolmove rightstate q sub onestate q sub onestroke symbolstroke symbolmove rightstate q sub onestate q sub oneblank symbolblank symbolmove leftstate q sub twostate q sub twostroke symbolblank symbolmove leftstate q sub threestate q sub threestroke symbolstroke symbolmove leftstate q sub threestate q sub threeleft end markerleft end markermove rightstate h\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}source

captionA disciplined addition machine

Turing machine proposition

For every Turing machine MMsource, there is a disciplined Turing machine MM'source which halts with output OOsource if MMsource halts with output OOsource, and does not halt if MMsource does not halt. In particular, any function f:nf\colon\Nat^n \to \Natsource computable by a Turing machine is also computable by a disciplined Turing machine.

Unsolved Turing machine exercise

Give a disciplined machine that computes f(x)=x+1f(x) = x+1source.

Unsolved Turing machine exercise

Find a disciplined machine which, when started on input 1n\TMstroke^nsource produces output 1n01n\TMstroke^n \concat \TMblank \concat \TMstroke^nsource.

Source file content/turing-machines/machines-computations/combining-machines.tex

Combining Turing Machines

Explain

The examples of Turing machines we have seen so far have been fairly simple in nature. But in fact, any problem that can be solved with any modern programming language can also be solved with Turing machines. To build more complex Turing machines, it is important to convince ourselves that we can combine them, so we can build machines to solve more complex problems by breaking the procedure into simpler parts. If we can find a natural way to break a complex problem down into constituent parts, we can tackle the problem in several stages, 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=Q,Σ,q0,δM = \tuple{Q, \Sigma, q_0, \delta}source and M=Q,Σ,q0,δM' = \tuple{Q', \Sigma', q_0', \delta'}source? We now use the configuration of the tape after MMsource has halted as the input configuration of a run of machine MM'source. To get a single Turing machine MMM \frown M'source that does this, do the following:

  1. Renumber (or relabel) all the states QQ'source of MM'source so that MMsource and MM'source have no states in common (QQ=Q \cap Q' = \emptysetsource).

  2. The states of MMM \frown M'source are QQQ \cup Q'source.

  3. The tape alphabet is ΣΣ\Sigma \cup \Sigma'source.

  4. The start state is q0q_0source.

  5. The transition function is the function δ\delta''source given by:

    δ(q,σ)={δ(q,σ)if qQ and δ(q,σ) is definedδ(q,σ)if qQq0,σ,Nif qQ and δ(q,σ) is undefined\delta''(q,\sigma) = \begin{cases} \delta(q,\sigma) & \text{if $q \in Q$ and $\delta(q,\sigma)$ is defined}\\ \delta'(q,\sigma) & \text{if $q \in Q'$}\\ \tuple{q_0', \sigma, \TMstay} & \text{if $q \in Q$ and $\delta(q,\sigma)$ is undefined} \end{cases}source

The resulting machine uses the instructions of MMsource when it is in a state qQq \in Qsource, the instructions of MM'source when it is in a state qQq \in Q'source. When it is in a state qQq \in Qsource and is scanning a symbol σ\sigmasource for which MMsource has no transition (i.e., MMsource would have halted), it enters the start state of MM'source (and leaves the tape contents and head position as it is).

Note that unless the machine MMsource is disciplined, we don't know where the tape head is when MMsource halts, so the halting configuration of MMsource need not have the head scanning square 11source. When combining machines, it's important to keep this in mind.

Turing machine example

Combining Machines: We'll design a machine which, when started on input consisting of two blocks of 1\TMstrokesource's of length nnsource and mmsource, halts with a single block of 2(m+n)2(m+n)source 1\TMstrokesource's on the tape. 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.

Turing machine state diagram

State diagram for the addition phase used in the combined construction. State diagram. Purpose: Runs the unary addition phase. Initial state: state q sub zero. States: state q sub zero, state q sub one, state q sub two. Transition one: from state q sub zero, when reading blank symbol, write stroke symbol, stay put, and enter state q sub one. Transition two: from state q sub zero, when reading stroke symbol, write stroke symbol, move right, and enter state q sub one. Transition three: from state q sub one, when reading stroke symbol, write stroke symbol, move right, and enter state q sub one. Transition four: from state q sub one, when reading blank symbol, write blank symbol, move left, and enter state q sub two. Transition five: from state q sub two, when reading stroke symbol, write blank symbol, stay put, and enter state q sub two. Every displayed state has at least one outgoing transition

state diagram transition tablefrom statereadwritemovenext statestate q sub zeroblank symbolstroke symbolstay putstate q sub onestate q sub zerostroke symbolstroke symbolmove rightstate q sub onestate q sub onestroke symbolstroke symbolmove rightstate q sub onestate q sub oneblank symbolblank symbolmove leftstate q sub twostate q sub twostroke symbolblank symbolstay putstate q sub two\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) [right of=B] {$q_2$}; \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}source

Instead of halting in state q2q_2source, 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. Let's add an instruction to make sure the tape head is reading the first stroke of the output of the addition machine.

Turing machine state diagram

Extends the addition phase so its head returns toward the left end before the next machine starts. State diagram. Purpose: Runs unary addition and then returns the head to the start of the output. Initial state: state q sub zero. States: state q sub zero, state q sub one, state q sub two, state q sub three, state q sub four. Transition one: from state q sub zero, when reading blank symbol, write stroke symbol, stay put, and enter state q sub one. Transition two: from state q sub zero, when reading stroke symbol, write stroke symbol, move right, and enter state q sub one. Transition three: from state q sub one, when reading stroke symbol, write stroke symbol, move right, and enter state q sub one. Transition four: from state q sub one, when reading blank symbol, write blank symbol, move left, and enter state q sub two. Transition five: from state q sub two, when reading stroke symbol, write blank symbol, move left, and enter state q sub three. Transition six: from state q sub three, when reading stroke symbol, write stroke symbol, move left, and enter state q sub three. Transition seven: from state q sub three, when reading left end marker, write left end marker, move right, and enter state q sub four. States with no outgoing transition shown are state q sub four

state diagram transition tablefrom statereadwritemovenext statestate q sub zeroblank symbolstroke symbolstay putstate q sub onestate q sub zerostroke symbolstroke symbolmove rightstate q sub onestate q sub onestroke symbolstroke symbolmove rightstate q sub onestate q sub oneblank symbolblank symbolmove leftstate q sub twostate q sub twostroke symbolblank symbolmove leftstate q sub threestate q sub threestroke symbolstroke symbolmove leftstate q sub threestate q sub threeleft end markerleft end markermove rightstate q sub four\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) [right of=B] {$q_2$}; \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}{\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 node {\TMtrans{\TMstroke}{\TMblank}{\TMleft}} (D) (D) edge [loop left] node {\TMtrans{\TMstroke}{\TMstroke}{\TMleft}} (D) edge node[left, xshift=-2mm] {\TMtrans{\TMendtape}{\TMendtape}{\TMright}} (E); \end{tikzpicture}source

It is now easy to double the input---all we have to do is connect the doubler machine onto state q4q_4source. This requires renaming the states of the doubler machine so that they start at q4q_4source instead of q0q_0source---this way we don't end up with two starting states. The final diagram should look as in link to figure Combining adder and doubler machines.

Turing machine figure

Figure containing the final state diagram that combines the addition and doubling phases.

Source transcription

Turing machine state diagram

Final combined state diagram: addition and head repositioning feed directly into a renamed doubler. State diagram. Purpose: Runs addition, repositions the head, and continues into a renamed doubler phase. Initial state: state q sub zero. States: state q sub zero, state q sub one, state q sub two, state q sub three, state q sub four, state q sub five, state q sub six, state q sub seven, state q sub eight, state q sub nine. Transition one: from state q sub zero, when reading blank symbol, write stroke symbol, stay put, and enter state q sub one. Transition two: from state q sub zero, when reading stroke symbol, write stroke symbol, move right, and enter state q sub one. Transition three: from state q sub one, when reading stroke symbol, write stroke symbol, move right, and enter state q sub one. Transition four: from state q sub one, when reading blank symbol, write blank symbol, move left, and enter state q sub two. Transition five: from state q sub two, when reading stroke symbol, write blank symbol, move left, and enter state q sub three. Transition six: from state q sub three, when reading stroke symbol, write stroke symbol, move left, and enter state q sub three. Transition seven: from state q sub three, when reading left end marker, write left end marker, move right, and enter state q sub four. Transition eight: from state q sub four, when reading stroke symbol, write blank symbol, move right, and enter state q sub five. Transition nine: from state q sub five, when reading stroke symbol, write stroke symbol, move right, and enter state q sub five. Transition ten: from state q sub five, when reading blank symbol, write blank symbol, move right, and enter state q sub six. Transition eleven: from state q sub six, when reading stroke symbol, write stroke symbol, move right, and enter state q sub six. Transition twelve: from state q sub six, when reading blank symbol, write stroke symbol, move right, and enter state q sub seven. Transition thirteen: from state q sub seven, when reading blank symbol, write stroke symbol, move left, and enter state q sub seven. Transition fourteen: from state q sub seven, when reading stroke symbol, write stroke symbol, move left, and enter state q sub eight. Transition fifteen: from state q sub eight, when reading stroke symbol, write stroke symbol, move left, and enter state q sub eight. Transition sixteen: from state q sub eight, when reading blank symbol, write blank symbol, move left, and enter state q sub nine. Transition seventeen: from state q sub nine, when reading stroke symbol, write stroke symbol, move left, and enter state q sub nine. Transition eighteen: from state q sub nine, when reading blank symbol, write blank symbol, move right, and enter state q sub four. Every displayed state has at least one outgoing transition

state diagram transition tablefrom statereadwritemovenext statestate q sub zeroblank symbolstroke symbolstay putstate q sub onestate q sub zerostroke symbolstroke symbolmove rightstate q sub onestate q sub onestroke symbolstroke symbolmove rightstate q sub onestate q sub oneblank symbolblank symbolmove leftstate q sub twostate q sub twostroke symbolblank symbolmove leftstate q sub threestate q sub threestroke symbolstroke symbolmove leftstate q sub threestate q sub threeleft end markerleft end markermove rightstate q sub fourstate q sub fourstroke symbolblank symbolmove rightstate q sub fivestate q sub fivestroke symbolstroke symbolmove rightstate q sub fivestate q sub fiveblank symbolblank symbolmove rightstate q sub sixstate q sub sixstroke symbolstroke symbolmove rightstate q sub sixstate q sub sixblank symbolstroke symbolmove rightstate q sub sevenstate q sub sevenblank symbolstroke symbolmove leftstate q sub sevenstate q sub sevenstroke symbolstroke symbolmove leftstate q sub eightstate q sub eightstroke symbolstroke symbolmove leftstate q sub eightstate q sub eightblank symbolblank symbolmove leftstate q sub ninestate q sub ninestroke symbolstroke symbolmove leftstate q sub ninestate q sub nineblank symbolblank symbolmove rightstate q sub four\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) [right of=B] {$q_2$}; \node[state] (D) [below left of=C] {$q_3$}; \node[state] (E) [below left of=D] {$q_4$}; \node[state] (2) [right of=E] {$q_5$}; \node[state] (3) [right of=2] {$q_6$}; \node[state] (4) [below of=3] {$q_7$}; \node[state] (5) [left of=4] {$q_8$}; \node[state] (6) [left of=5] {$q_9$}; \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 node {\TMtrans{\TMstroke}{\TMblank}{\TMleft}} (D) (D) edge [loop left] node {\TMtrans{\TMstroke}{\TMstroke}{\TMleft}} (D) edge node[left, xshift=-2mm] {\TMtrans{\TMendtape}{\TMendtape}{\TMright}} (E) (E) edge node {\TMtrans{\TMstroke}{\TMblank}{\TMright}} (2) (2) edge [loop above] node {\TMtrans{\TMstroke}{\TMstroke}{\TMright}} (2) edge node {\TMtrans{\TMblank}{\TMblank}{\TMright}} (3) (3) edge [loop above] node {\TMtrans{\TMstroke}{\TMstroke}{\TMright}} (3) edge node {\TMtrans{\TMblank}{\TMstroke}{\TMright}} (4) (4) edge [loop below] node {\TMtrans{\TMblank}{\TMstroke}{\TMleft}} (4) edge node {\TMtrans{\TMstroke}{\TMstroke}{\TMleft}} (5) (5) edge [loop below] node {\TMtrans{\TMstroke}{\TMstroke}{\TMleft}} (5) edge node {\TMtrans{\TMblank}{\TMblank}{\TMleft}} (6) (6) edge [loop below] node {\TMtrans{\TMstroke}{\TMstroke}{\TMleft}} (6) edge node {\TMtrans{\TMblank}{\TMblank}{\TMright}} (E); \end{tikzpicture}source

captionCombining adder and doubler machines

Turing machine proposition

If MMsource and MM'source are disciplined and compute the functions f:kf\colon \Nat^k \to \Natsource and f:f'\colon \Nat \to \Natsource, respectively, then MMM \frown M'source is disciplined and computes ff\comp{f}{f'}source.

Proof

Since MMsource is disciplined, when it halts with output f(n1,,nk)=mf(n_1,\dots,n_k) = msource, the head is scanning square 11source. If we now enter the start state of MM'source, the machine will halt with output f(m)f'(m)source, again scanning square 11source. The other conditions of link to definition Disciplined Turing machine are also satisfied.

Unsolved Turing machine exercise

Give a disciplined Turing machine computing f(x)=x+2f(x) = x+2source by taking the machine MMsource from link to exercise Disciplined successor machine and construct MMM \frown Msource.

Source file content/turing-machines/machines-computations/variants.tex

Variants of Turing Machines

There are in fact many possible ways to define Turing machines, of which ours is only one. In some ways, our definition is more liberal than others. We allow arbitrary finite alphabets, a more restricted definition might allow only two tape symbols, 1\TMstrokesource and 0\TMblanksource. We allow the machine to write a symbol to the tape and move at the same time, other definitions allow either writing or moving. We allow the possibility of writing without moving the tape head, other definitions leave out the N\TMstaysource “instruction.” In other ways, our definition is more restrictive. We assumed that the tape is infinite in one direction only, other definitions allow the tape to be infinite both to the left and the right. In fact, one can even allow any number of separate tapes, or even an infinite grid of squares. We represent the instruction set of the Turing machine by a transition function; other definitions use a transition relation where the machine has more than one possible instruction in any given situation.

This last relaxation of the definition is particularly interesting. In our definition, when the machine is in state qqsource reading symbol σ\sigmasource, δ(q,σ)\delta(q, \sigma)source determines what the new symbol, state, and tape head position is. But if we allow the instruction set to be a relation between current state-symbol pairs q,σ\tuple{q, \sigma}source and new state-symbol-direction triples q,σ,D\tuple{q', \sigma', D}source, the action of the Turing machine may not be uniquely determined---the instruction relation may contain both q,σ,q,σ,D\tuple{q, \sigma, q', \sigma', D}source and q,σ,q,σ,D\tuple{q, \sigma, q'', \sigma'', D'}source. In this case we have a non-deterministic Turing machine. These play an important role in computational complexity theory.

There are also different conventions for when a Turing machine halts: we say it halts when the transition function is undefined, other definitions require the machine to be in a special designated halting state. We have explained in link to section Halting States why requiring a designated halting state is not a restriction which impacts what Turing machines can compute. Since the tapes of our Turing machines are infinite in one direction only, there are cases where a Turing machine can't properly carry out an instruction: if it reads the leftmost square and is supposed to move left. According to our definition, it just stays put instead of “falling off”, but we could have defined it so that it halts when that happens. This definition is also equivalent: we could simulate the behavior of a Turing machine that halts when it attempts to move left from square 00source by deleting every transition δ(q,)=q,σ,L\delta(q,\TMendtape) = \tuple{q',\sigma,\TMleft}source---then instead of attempting to move left on \TMendtapesource the machine halts.Footnote: This doesn't quite work, since nothing prevents us from writing and reading \TMendtapesource on squares other than square 00source (see link to example Mover machine). We can get around that by adding a second \TMendtape'source symbol to use instead for such a purpose.

There are also different ways of representing numbers (and hence the input-output function computed by a Turing machine): we use unary representation, but you can also use binary representation. This requires two symbols in addition to 0\TMblanksource and \TMendtapesource.

Now here is an interesting fact: none of these variations matters as to which functions are Turing computable. If a function is Turing computable according to one definition, it is Turing computable according to all of them.

We won't go into the details of verifying this. Here's just one example: we gain no additional computing power by allowing a tape that is infinite in both directions, or multiple tapes. The reason is, roughly, that a Turing machine with a single one-way infinite tape can simulate multiple or two-way infinite tapes. E.g., using additional states and instructions, we can “translate” a program for a machine with multiple tapes or two-way infinite tape into one with a single one-way infinite tape. The translated machine can use the even squares for the squares of tape 11source (or the “positive” squares of a two-way infinite tape) and the odd squares for the squares of tape 22source (or the “negative” squares).

Source file content/turing-machines/machines-computations/church-turing-thesis.tex

The Church--Turing Thesis

Turing machines are supposed to be a precise replacement for the concept of an effective procedure. Turing thought that anyone who grasped both the concept of an effective procedure and the concept of a Turing machine would have the intuition that anything that could be done via an effective procedure could be done by Turing machine. This claim is given support by the fact that all the other proposed precise replacements for the concept of an effective procedure turn out to be extensionally equivalent to the concept of a Turing machine ---that is, they can compute exactly the same set of functions. This claim is called the Church--Turing thesis.

Turing machine definition

[Church--Turing thesis] The Church--Turing Thesis states that anything computable via an effective procedure is Turing computable.

The Church--Turing thesis is appealed to in two ways. The first kind of use of the Church--Turing thesis is an excuse for laziness. Suppose we have a description of an effective procedure to compute something, say, in “pseudo-code.” Then we can invoke the Church--Turing thesis to justify the claim that the same function is computed by some Turing machine, even if we have not in fact constructed it.

The other use of the Church--Turing thesis is more philosophically interesting. It can be shown that there are functions which cannot be computed by Turing machines. From this, using the Church--Turing thesis, one can conclude that it cannot be effectively computed, using any procedure whatsoever. For if there were such a procedure, by the Church--Turing thesis, it would follow that there would be a Turing machine for it. So if we can prove that there is no Turing machine that computes it, there also can't be an effective procedure. In particular, the Church--Turing thesis is invoked to claim that the so-called halting problem not only cannot be solved by Turing machines, it cannot be effectively solved at all.

Source disclosures