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 source to source 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: source, source, and source. When the mechanism is started, the tape is empty (i.e., each square contains the symbol source) except for the leftmost square, which contains source, 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 source and a symbol source and outputs a triple source. Whenever the mechanism is in state source and reads symbol source, it replaces the symbol on the current square with source, the head moves left, right, or stays put according to whether source is source, source, or source, and the mechanism goes into state 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 source on the leftmost square, followed by three source's, a source, and four more source's. The head is reading the third square from the left, which contains a source, and is in state source---we say “the machine is reading a source in state source.” If the program of the Turing machine returns, for input source, the triple source, the machine would now replace the source on the third square with a source, leave the read/write head where it is, and switch to state source. If then the program returns source for input source, the machine would now overwrite the source with another source (effectively, leaving the content of the tape under the read/write head unchanged), move one square to the right, and enter state source. And so on.
We say that the machine halts when it encounters some state, source, and symbol, source such that there is no instruction for source, i.e., the transition function for input 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 source. 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):
A direct appeal to intuition.
A proof of the equivalence of two definitions (in case the new definition has a greater intuitive appeal).
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, source and source, 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
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 source in state source, write a source, move right, and move to state source. This is equivalent to the transition function mapping source to source.
Turing machine example
Even Machine: The following Turing machine halts if, and only if, there are an even number of source's on the tape (under the assumption that all source's come before the first source 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
The state diagram corresponds to the following transition function:
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 source's. In this case, we expect that the machine will halt. We will then run the machine on an input of three source's, where the machine will run forever.
The machine starts in state source, scanning the leftmost source. We can represent the initial state of the machine as follows:
The above configuration is straightforward. As can be seen, the machine starts in state one, scanning the leftmost source. This is represented by a subscript of the state name on the first source. The applicable instruction at this point is source, and so the machine moves right on the tape and changes to state source.
Since the machine is now in state source scanning a source, we have to “follow” the instruction source. This results in the configuration
As the machine continues, the rules are applied again in the same order, resulting in the following two configurations:
The machine is now in state source scanning a source. 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 source's. The first few configurations are similar, as the same instructions are carried out, with only a small difference of the tape input:
The machine has now traversed past all the source's, and is reading a source in state source. As shown in the diagram, there is an instruction of the form source. Since the tape is filled with source indefinitely to the right, the machine will continue to execute this instruction forever, staying in state source 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 source at source.
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
Explain
Machine tables are another way of representing Turing machines. Machine tables have the tape alphabet displayed on the source-axis, and the set of machine states across the source-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.
As we can see, the machine halts when scanning a source in state source.
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 source source's on the tape, outputs a block of source source'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 source's it has read, we need to come up with a way to keep track of all the source's on the tape. One such way is to separate the output from the input with a source. The machine can then erase the first source from the input, traverse over the rest of the input, leave a source, and write two new source's. The machine will then go back and find the second source in the input, and double that one as well. For each one source of input, it will write two source's of output. By erasing the input as the machine goes, we can guarantee that no source is missed or doubled twice. When the entire input is erased, there will be source source'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
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 source that accepts, i.e., halts on, any string of source's and source's where the number of source's is the same as the number of source's and all the source's precede all the source's, and rejects, i.e., does not halt on, any string where the number of source's is not equal to the number of source's or the source's do not precede all the source's. (E.g., the machine should accept source, and source, but reject both source and source.)
Unsolved Turing machine exercise
Design a Turing-machine with alphabet source that takes as input any string source of source's and source's and duplicates them to produce an output of the form source. (E.g. input source should result in output source).
Unsolved Turing machine exercise
Alphabetical?: Design a Turing-machine with alphabet source that when given as input a finite sequence of source's and source's checks to see if all the source's appear to the left of all the source'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 source that takes as input a finite sequence of source's and source's rearranges them so that all the source's are to the left of all the source's. (e.g., the sequence source should become the sequence source, and the sequence source should become the sequence source).
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 source is a tuple source consisting of
The partial function source is also called the transition function of source.
Explain
We assume that the tape is infinite in one direction only. For this reason it is useful to designate a special symbol source 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 source if source is defined. Some textbooks do this, we do not. You can simply be careful when constructing your Turing machine that it never overwrites source. Moreover, there are cases where allowing such overwriting provides some convenient flexibility.
Turing machine example
Even Machine: The even machine is formally the quadruple source where
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 source computes on a given input.
Turing machine definition
[Configuration] A configuration of Turing machine source is a triple source where
Intuitively, the sequence source is the content of the tape (symbols of all squares from the leftmost square to the last non-blank or previously visited square), source is the number of the square the read/write head is scanning (beginning with source being the number of the leftmost square), and source 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 source.
Turing machine definition
[Initial configuration] The initial configuration of source for input source is
Explain
The source symbol is for concatenation---the input string begins immediately to the left end marker.
Turing machine definition
We say that a configuration source yields the configuration source in one step (according to source), iff
Turing machine definition
A run of source on input source is a sequence source of configurations of source, where source is the initial configuration of source for input source, and each source yields source in one step.
We say that source halts on input source after source steps if source, the sourceth symbol of source is source, and source is undefined. In that case, the output of source for input source is source, where source is a string of symbols not ending in source such that source for some source. (source is a sequence of source source's.)
Explain
According to this definition, the output source of source always ends in a symbol other than source, or, if at time source the entire tape is filled with source (except for the leftmost source), source 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 source. If source, let source be the empty sequence if source, and otherwise the sequence consisting of exactly source source's.
Turing machine definition
[Computation] A Turing machine source computes the function source iff source halts on input
with output source.
Unsolved Turing machine exercise
Give a definition for when a Turing machine source computes the function source.
Turing machine example
Addition: Let's build a machine that computes the function source. This requires a machine that starts with two blocks of source's of length source and source on the tape, and halts with one block consisting of source source's. The two input blocks of source's are separated by a source, so one method would be to write a stroke on the square containing the source, and erase the last source.
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
captionA machine computing source
Unsolved Turing machine exercise
Trace through the configurations of the machine from link to example Addition machine for input source. What happens if the machine computes source?
Explain
In link to example Doubler machine, we gave an example of a Turing machine that takes as input a sequence of source's and halts with a sequence of twice as many source's on the tape---the doubler machine. However, because the output contains source's to the left of the doubled block of source's, it does not actually compute the function source, 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 source. Instead of erasing the input and writing two source's at the far right for every source in the input as the machine from link to example Doubler machine does, this machine adds a single source to the right for every source in the input. It has to keep track of where the input ends, so it leaves a source between the input and the added strokes, which it fills with a source at the very end. And we have to “remember” where we are in the input, so we temporarily replace a source in the input block by a source.
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
captionA machine computing source
Turing machine example
A second possibility for computing source 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 source's followed by a block of source's (and the head positioned anywhere in the block of source's), it erases the source'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 source's with a source symbol, which gets deleted at the end. We've started numbering the states at source, so they can be added to the doubler machine. All you'll need is an additional instruction source, i.e., an arrow from source to source labelled source. (There is one subtle problem: the resulting machine does not work for input source. 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.
captionMoving a block of source'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 source, i.e., on an empty tape? How would you fix the machine so that in this case the machine halts with output source? (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 source and source, where source, computes the function source.
Unsolved Turing machine exercise
Equality: Design a Turing machine to compute the following function:
Unsolved Turing machine exercise
Design a Turing machine to compute the function source where source and source are positive integers represented on the tape by strings of source's separated by a source. You may use additional symbols in the alphabet of the machine.
The function source selects the smallest value from its arguments, so source, source, and source, and so on.
Turing machine definition
A Turing machine source computes the partial function source iff,
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 source, such that source.
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 source 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 source 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
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 source.
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
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 source---such machines are guaranteed to halt, if they halt at all, in state source. 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 source, or to attempt to move left from square source. (Our definition states that the head simply stays on square source 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 source.
Turing machine definition
A Turing machine source is disciplined iff
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 source, and adding an instruction source for any pair source where the original source is undefined. It is true, although tedious to prove, that any Turing machine source can be turned into a disciplined Turing machine source which halts on the same inputs and produces the same output. For instance, if the Turing machine halts and is not on square source, 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
captionA disciplined addition machine
Turing machine proposition
For every Turing machine source, there is a disciplined Turing machine source which halts with output source if source halts with output source, and does not halt if source does not halt. In particular, any function source computable by a Turing machine is also computable by a disciplined Turing machine.
Unsolved Turing machine exercise
Give a disciplined machine that computes source.
Unsolved Turing machine exercise
Find a disciplined machine which, when started on input source produces output source.
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 source and source? We now use the configuration of the tape after source has halted as the input configuration of a run of machine source. To get a single Turing machine source that does this, do the following:
Renumber (or relabel) all the states source of source so that source and source have no states in common (source).
The tape alphabet is source.
The start state is source.
The transition function is the function source given by:
The resulting machine uses the instructions of source when it is in a state source, the instructions of source when it is in a state source. When it is in a state source and is scanning a symbol source for which source has no transition (i.e., source would have halted), it enters the start state of source (and leaves the tape contents and head position as it is).
Note that unless the machine source is disciplined, we don't know where the tape head is when source halts, so the halting configuration of source need not have the head scanning square source. 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 source's of length source and source, halts with a single block of source source'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
Instead of halting in state source, 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
It is now easy to double the input---all we have to do is connect the doubler machine onto state source. This requires renaming the states of the doubler machine so that they start at source instead of source---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
captionCombining adder and doubler machines
Turing machine proposition
If source and source are disciplined and compute the functions source and source, respectively, then source is disciplined and computes source.
Proof
Since source is disciplined, when it halts with output source, the head is scanning square source. If we now enter the start state of source, the machine will halt with output source, again scanning square source. The other conditions of link to definition Disciplined Turing machine are also satisfied.
Unsolved Turing machine exercise
Give a disciplined Turing machine computing source by taking the machine source from link to exercise Disciplined successor machine and construct source.
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, source and source. 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 source “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 source reading symbol source, 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 source and new state-symbol-direction triples source, the action of the Turing machine may not be uniquely determined---the instruction relation may contain both source and 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 source by deleting every transition source---then instead of attempting to move left on source the machine halts.Footnote: This doesn't quite work, since nothing prevents us from writing and reading source on squares other than square source (see link to example Mover machine). We can get around that by adding a second 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 source and source.
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 source (or the “positive” squares of a two-way infinite tape) and the odd squares for the squares of tape source (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
- TR032-SAR-003: At the outset, the head scans the leftmost square and is in a specified initial state. source
- TR032-SAR-004: The machine starts in state q zero, scanning the leftmost stroke. source
- TR032-SAR-005: Whenever there is a gap in the table, there is a possible point for the machine to halt. source
- TR032-SAR-006: The machine takes as input a finite sequence of capital A and capital B symbols and rearranges them so that all capital A symbols are to the left of all capital B symbols. source
- TR032-SAR-015: Some textbooks impose this restriction; this text does not. source
- TR032-SAR-001: Route this imported section under the canonical Turing Machines part and Turing Machine Computations chapter while retaining the literal source metadata in provenance. source
- TR032-SAR-008: Keep the sentence period outside the navigable formula. source
- TR032-SAR-007: The input string begins immediately to the right of the left end marker. source
- TR032-SAR-009: We also have not prohibited Turing machines from erasing the tape end marker on square zero or from attempting to move left from square zero. source
- TR032-SAR-010: In the first case use delta of q and sigma only when q belongs to Q and that value of delta is defined; retain the separate third case for an undefined value. source
- TR032-SAR-011: Give a disciplined Turing machine computing f of x equals x plus two by taking the specified successor machine and constructing its sequential combination with itself. source
- TR032-SAR-012: We allow arbitrary finite alphabets; a more restricted definition might allow only two tape symbols. We allow writing and moving at the same time; other definitions allow only one of those actions. We allow writing without moving; other definitions omit that instruction. We assume a tape infinite only to the right; other definitions allow both directions. source
- TR032-SAR-013: We say a machine halts when its transition function is undefined; other definitions require a designated halting state. source
- TR032-SAR-002: Use the canonical Turing Machines chapter route; retain the stale comment header only in provenance. source
- TR032-SAR-014: Anything that could be done by an effective procedure could be done by a Turing machine. source