En Turingmaskine er en matematisk model for en simpel symbolmanipulerende maskine som trods sin enkle opbygning kan udføre ikke-trivielle beregninger og simulere logikken i enhver computer. Turingmaskiner blev først beskrevet af Alan Turing i 1936. De spiller en central rolle inden for datalogien i teorierne vedrørende beregnelighed og beregningers kompleksitet og generelt i matematisk logik.

En Turingmaskine kan være en specifik Turingmaskine som er konstrueret til at løse et bestemt problem, eller det kan være en universel Turingmaskine som kan læse en kodet beskrivelse af en vilkårlig Turingmaskine og dennes inputdata, og derefter udføre dens beregninger.

## Uformel beskrivelse

Turingmaskinens koncept er baseret på ideen om, at en person udfører en veldefineret procedure, ved at ændre på indholdet af et uendeligt bånd, der er inddelt i kvadrater, som hver kan indeholde ét ud af en endelig mængde symboler. Personen skal huske én ud af en endelig mængde af tilstande, og proceduren er formuleret som meget basale skridt på formen: "Hvis din tilstand er 42 og symbolet du ser er et '0', så udskift dette med et '1', ryk et symbol til højre på båndet, og som din nye tilstand; gå i tilstand 17."

Mere præcist består en Turingmaskine af:

1. Et BÅND som er inddelt i celler på en række. Hver celle indeholder et symbol fra et endeligt alfabet. Alfabetet indeholder et specielt blank-symbol (her skrevet som 'B') og et eller flere andre symboler. Celler som endnu ikke er tilskrevet noget, forudsættes at indeholde det blanke symbol.
2. Et HOVED som kan læse og skrive symboler på båndet og rykke sig til højre og venstre på båndet, en celle af gangen.
3. En TABEL ("action table", or transition function) of instructions (usually quintuples or 5-tuples but sometimes 4-tuples) that, given the state the machine is currently in and the symbol it is reading on the tape tells the machine to do the following in sequence (for the 5-tuple models): (i) either erase or write a symbol, and then (ii) move the head ('L' for one step left or 'R' for one step right), and then (iii) assume the same or a new state as prescribed. In the 4-tuple models the TABLE tells the machine to (ia) erase or to write a symbol or (ib) move the head left or right, and then (ii) assume the same or a new state as prescribed, but not both actions (ia) and (ib) in the same instruction. In some models, if there is no entry in the table for the current combination of symbol and state then the machine will halt; other models require all entries to be filled.
4. Et tilstandsregister that stores the state of the Turing table. The number of different states is always finite and there is one special start state with which the state register is initialized. Turing defined this as a "note of instructions" to preserve the computation of the "computer" (a person) who is working in a "desultory manner":
"This note is the counterpart of the 'state of mind'."(Undecidable, p. 139)

Bemærk at enhver del af maskinen -- dens tilstands- og symbolmængde -- dens mulige skridt -- skrivning, sletning og bevægelse af hoved -- er endelig, diskret og skelnelig; det er det uendelige bånd som giver den en ubegrænset mængde lagerplads.

## Examples of Turing machines

To see examples of the following models, see Turing machine examples:

1. Turing's very first machine
2. Copy routine
3. 3-state busy beaver

## Formal definition of single-tape Turing machine

En Turingmaskine er en 7-tuple $(Q,\Sigma ,\Gamma ,\delta ,q_{0},q_{accept},q_{afvis})\,$ , hvor $Q,\Sigma ,\Gamma \,$  er endelige mængder.

1. $Q\,$  er mængden af tilstande,
2. $\Sigma \,$  er inputalfabetet, uden det specielle blanke symbol $^{\sqcup }$ .
3. $\Gamma \,$  er båndalfabetet, $\Sigma \subseteq \Gamma \,$  og ${\sqcup }\in \Gamma \,$ ,
4. $\delta :Q\times \Gamma \rightarrow Q\times \Gamma \times \{L,R\}$  er transitionsfunktionen,
5. $q_{0}\in Q$  er starttilstanden,
6. $q_{accept}\in Q$  er accepttilstanden, og
7. $q_{afvis}\in Q$  er den afvisende tilstand, $q_{afvis}\neq q_{accept}$

A nutshell formal description of a "Turing machine":

"A Turing machine is a finite-state machine associated with an external storage or memory medium." (Minsky (1967) p. 117)
"A Turing machine is essentially a finite-state sequential machine that has the ability to communicate with an external store of information"(Booth (1967), p. 354)

The finite state machine is represented by the state-table together with its state register. The "external storage medium" is the tape. The input to the state machine is the scanned symbol on the tape. The output of the state machine is a symbol to print or the erase command and tape motion-command left or right.

Hopcroft and Ullman (1979, p. 148) formally define a (one-tape) Turing machine as a 7-tuple $M=\langle Q,\Gamma ,b,\Sigma ,\delta ,q_{0},F\rangle$  where

• $Q$  is a finite set of states
• $\Gamma$  is a finite set of the tape alphabet/symbols
• $b\in \Gamma$  is the blank symbol (the only symbol allowed to occur on the tape infinitely often at any step during the computation)
• $\Sigma$ , a subset of $\Gamma$  not including b is the set of input symbols
• $\delta :Q\times \Gamma \rightarrow Q\times \Gamma \times \{L,R\}$  is a partial function called the transition function, where L is left shift, R is right shift.
• $q_{0}\in Q$  is the initial state
• $F\subseteq Q$  is the set of final or accepting states

The 7-tuple for the 3-state busy beaver looks like this (see more about this busy beaver at Turing machine examples):

Q = { A, B, C, HALT }
Γ = { 0, 1 }
b = 0 = "blank"
Σ = { }, empty set
δ = see state-table below
q0 = A = initial state
F = the one element set of final states {HALT}

State table for 3 state, 2 symbol busy beaver:

 Current state A: Current state B: Current state C: Write symbol: Move tape: Next state: Write symbol: Move tape: Next state: Write symbol: Move tape: Next state: tape symbol is 0: 1 R B 1 L A 1 L B tape symbol is 1: 1 L C 1 R B 1 N HALT

This specification is insufficient, however. van Emde Boas (1990) observes that:

"The set-theoretical object [his formal seven-tuple description similar to the above] provides only partial information on how the machine will behave and what its computations will look like" (p. 6).

Examples readily demonstrate that, as well as the behavior of the components of the informal description, the form of the input and output "parameters", and the position of the head at the start must be specified as well. For example, Turing (1936) places his "figures" "1" and "0" on alternate squares. Other models form the input as tight-packed unary 1's with blanks between the various strings, yet others place strings of 0's, each spaced by 1, on truly blank tape, etc.; the output may or may not appear in a similar manner. Thus to fully "describe" a "computation" of a Turing machine Stone (1972) states it is necessary to state the following:

"1. The tape alphabet
"2. The form in which the parameters are presented on the tape
"3. The initial state of the Turing machine
"4. The form in which answers will be represented on the tape when the Turing machine halts
"5. The machine program" (Stone, p. 10)

### Turing instructions -- quintuples (5-tuples)

Definitions in literature sometimes differ slightly, to make arguments or proofs easier or clearer, but this is always done in such a way that the resulting machine has the same computational power. For example, changing the set $\{L,R\}$  to $\{L,R,N\}$ , where N ("None" or "No-operation) would allow the machine to stay on the same tape cell instead of moving left or right, does not increase the machine's computational power.

The most common convention represents each "Turing instruction" in a "Turing table" by one of nine 5-tuples, per the convention of Turing/Davis (Turing (1936 in Undecidable, p. 126-127 and Davis (2000) p. 152):

(definition 1): (qi, Sj, Sk/E/N, L/R/N, qm)
( current state qi , symbol scanned Sj , print symbol Sk PSk/erase E/none N , move_tape_one_ square L/right R/None N , new state qm )

Other authors (Minsky (1967) p. 119, Hopcroft and Ullman (1979) p. 158, Stone (1972) p. 9) adopt a different convention, with new state qm listed immediately after the scanned symbol Sj:

(definition 2): (qi, Sj, qm, Sk/E/N, L/R/N)
( current state qi, symbol scanned Sj , new state qm , print symbol Sk PSk/erase E/none N , move_tape_one_square left L/none N/right R )

For remainder of this article we will use "definition 1" i.e. the Turing/Davis convention.

Example: state table for the 3-state 2-symbol busy beaver reduced to 5-tuples:

(A, 0, 1, R, B) means "If the state register contains state A and the tape-head is scanning symbol 0, then do in sequence: (i) Print 1, then (ii) move tape Right one square, then lastly (iii) assume state B.
 Current state Scanned symbol Print symbol Move Tape Final (i.e. next) state 5-tuples A 0 1 R B (A, 0, 1, R, B) A 1 1 L C (A, 1, 1, L, C) B 0 1 L A (B, 0, 1, L, A) B 1 1 R B (B, 1, 1, R, B) C 0 1 L B (C, 0, 1, L, B) C 1 1 N H (C, 1, 1, N, H)

In the following table, Turing's original model allowed only the first three lines that he called N1, N2, N3 (cf Turing in Undecidable, p. 126). He allowed for erasure of the "scanned square" by naming a 0th symbol S0 = "erase" or "blank", etc. However, he did not allow for non-printing, so every instruction-line includes "print symbol Sk" or "erase" (cf footnote 12 in Post (1947), Undecidable p. 300). The abbreviations are Turing's (Undecidable p.119). Subsequent to Turing's original paper in 1936-1937, machine-models have allowed all nine possible five-tuples:

 Current m-configuration (Turing state) Tape symbol Print-operation Tape-motion Final m-configuration (Turing state) 5-tuple 5-tuple comments 4-tuple N1 qi Sj Print(Sk) Left L qm (qi, Sj, Sk, L, qm) "blank" = S0, 1=S1, etc. N2 qi Sj Print(Sk) Right R qm (qi, Sj, Sk, R, qm) "blank" = S0, 1=S1, etc. N3 qi Sj Print(Sk) None N qm (qi, Sj, Sk, N, qm) "blank" = S0, 1=S1, etc. (qi, Sj, Sk, qm) 4 qi Sj None N Left L qm (qi, Sj, N, L, qm) (qi, Sj, L, qm) 5 qi Sj None N Left R qm (qi, Sj, N, R, qm) (qi, Sj, R, qm) 6 qi Sj None N None N qm (qi, Sj, N, N, qm) Direct "jump" (qi, Sj, N, qm) 7 qi Sj Erase Left L qm (qi, Sj, E, L, qm) 8 qi Sj Erase Right R qm (qi, Sj, E, R, qm) 9 qi Sj Erase None N qm (qi, Sj, E, N, qm) (qi, Sj, E, qm)

We can construct any Turing table (list of instructions) from the above nine 5-tuples. For technical reasons usually we can dispense with the three non-printing or "N" instructions (4, 5, 6). For examples see Turing machine examples.

Less frequently we encounter the use of 4-tuples -- these represent a further atomization of the Turing instructions (cf Post (1947), Boolos & Jeffrey (1974, 1999), Davis-Sigal-Weyuker (1994)); also see more at Post-Turing machine.

### The "state"

The word "state" used in context of Turing machines can be a source of confusion. Most commentators after Turing have used "state" to mean the name/designator of the current instruction to be performed -- i.e. the contents of the state register. But Turing (1936) made a strong distinction between a record of what he called the machine's "m-configuration", and the machine's (or person's) "state of progress" through the computation. What Turing called "the state formula" includes both the current instruction and all the symbols on the tape. As indicated by (boldface added):

"Thus the state of progress of the computation at any stage is completely determined by the note of instructions and the symbols on the tape. That is, the state of the system may be described by a single expression (sequence of symbols) consisting of the symbols on the tape followed by Δ (which we suppose not to appear elsewhere) and then by the note of instructions. This expression is called the 'state formula' (Undecidable, p.139-140)

Earlier in his paper Turing carried this even further: he gives an example where he places a symbol of the current "m-configuration" -- the instruction's label -- beneath the scanned square, together with all the symbols on the tape (Undecidable, p.121); this he calls "the complete configuration" (Undecidable, p. 118). To print the "complete configuration" on one line he places the state-label/m-configuration to the left of the scanned symbol.

We see a variant of this in Kleene (1952) where Kleene shows how to write the Gödel number of a machine's "situation": he places the "m-configuration" symbol q4 over the scanned square in roughly the center of the 6 non-blank squares on the tape (see the Turing-tape figure in this article) and puts it to the right of the scanned square. But Kleene refers to "q4" itself as "the machine state" (Kleene, p. 374-375). Hopcroft and Ullman call this composite the "instantaneous description" and follow the Turing convention of putting the "current state" (instruction-label, m-configuration) to the left of the scanned symbol (p.149).

Example: total state of 3-state 2-symbol busy beaver after 3 "moves" (taken from example "run" in the figure below):

1A1

This means: after three moves the tape has ...000110000... on it, the head is scanning the right-most 1, and the state is A. Blanks (in this case represented by "0"s) can be part of the total state as shown here: B01 ; the tape has a single 1 on it, but the head is scanning the 0 ("blank") to its left and the state is B.

Thus when we speak of "state" in the context of Turing machines we should clarify whether we are describing: (i) the current instruction, or (ii) the list of symbols on the tape together with the current instruction, or (iii) the list of symbols on the tape together with the current instruction placed to the left of the scanned symbol or to the right of the scanned symbol.

Hodges -- Turing's biographer -- has observed this confusion, and his commentary on it appears in a footnote (cf Hodges (1983) p. 107).

### Turing machine "state" diagrams

The TABLE for the 3-state busy beaver ("P" = print/write a "1"):

 Current state A: Current state B: Current state C: Write symbol: Move tape: Next state: Write symbol: Move tape: Next state: Write symbol: Move tape: Next state: tape symbol is 0: P R B P L A P L B tape symbol is 1: P L C P R B P N HALT
Fil:State diagram 3 state busy beaver 2B.gif
The "3-state busy beaver" Turing Machine in a finite state representation. Each circle represents a "state" of the TABLE -- an "m-configuration" or "instruction". "Direction" of a state transition is shown by an arrow. The label (e.g.. 0/P,R) near the outgoing state (at the "tail" of the arrow) specifies the scanned symbol that causes a particular transition (e.g. 0) followed by a slash /, followed by the subsequent "behaviors" of the machine, e.g. "P Print" then move tape "R Right". No general accepted format exists. The convention shown is after McClusky (1965), Booth (1965), Hill and Peterson (1974).

To the right: the above TABLE as expressed as a "state transition" diagram".

Usually large TABLES are better left as tables (Booth, p. 74). They are more readily simulated by computer in tabular form (Booth, p. 74). However, certain concepts -- e.g. machines with "reset" states and machines with repeating patterns (cf Hill and Peterson p. 244ff) -- can be more readily seen when viewed as a drawing.

Whether a drawing represents an improvement on its TABLE must be decided by the reader for the particular context. See Finite state machine for more.

Fil:State diagram 3 state busy beaver 4 .JPG
The evolution of the busy-beaver's computation starts at the top and proceeds to the bottom.

The reader should again be cautioned that such diagrams represent a snapshot of their TABLE frozen in time, not the course ("trajectory") of a computation through time and/or space. While every time the busy beaver machine "runs" it will always follow the same state-trajectory, this is not true for the "copy" machine that can be provided with variable input "parameters".

The diagram "Progress of the computation" shows the 3-state busy beaver's "state" (instruction) progress through its computation from start to finish. On the far right is the Turing "complete configuration" (Kleene "stuation", Hopcroft-Ullman "instantaneous description") at each step. If we were to stop the machine and clear to blank both the "state register" and entire tape, these "configurations" could be used to rekindle a computation anywhere in its progress (cf Turing (1936) Undecidable pp. 139-140).

## Models equivalent to the Turing machine model

Many machines that might be thought to have more computational capability than a simple universal Turing machine can be shown to have no more power (Hopcroft and Ullman p. 159, cf Minsky (1967)). They might compute faster, perhaps, or use less memory, or their instruction set might be smaller, but they cannot compute more powerfully (i.e. more mathematical functions). (Recall that the Church-Turing thesis hypothesizes this to be true: that anything that can be “computed” can be computed by some Turing machine.)

A Turing machine is equivalent to a pushdown automaton made more powerful by relaxing the last-in-first-out requirement of its stack. (Interestingly, this seemingly minor relaxation enables the Turing machine to perform such a wide variety of computations that it can serve as a model for the computational capabilities of all modern computer software.)

At the other extreme, some very simple models turn out to be Turing-equivalent, i.e. to have the same computational power as the Turing machine model.

Common equivalent models are the multi-tape Turing machine, machines with input and output, and the non-deterministic Turing machine (NDTM) as opposed to the deterministic Turing machine (DTM) for which the action table has at most one entry for each combination of symbol and state.

For more on this topic see Turing machine equivalents, in particular Register machine and Post-Turing machine.

For practical and didactical intentions the equivalent register machine can be used as a usual assembly programming language.

## Choice c-machines, Oracle o-machines

Early in his paper (1936) Turing makes a distinction between an "automatic machine" -- its "motion ... completely determined by the configuration" and a "choice machine":

"...whose motion is only partially determined by the configuration .... When such a machine reaches one of these ambiguous configurations, it cannot go on until some arbitrary choice has been made by an external operator. This would be the case if we were using machines to deal with axiomatic systems" (p. 118 Undecidable)

Turing (1936) does not elaborate further.

An oracle machine or o-machine is a Turing a-machine that pauses its computation at state "o" while, to complete its calculation, it "awaits the decision" of "the oracle" -- an unspecified entity "apart from saying that it cannot be a machine" (Turing (1939), Undecidable p. 166-168). The concept is now actively used by mathematicians.

## Universal Turing machines

"It is possible to invent a single machine which can be used to compute any computable sequence. If this machine U is supplied with the tape on the beginning of which is written the string of quintuples separated by semicolons of some computing machine M, then U will compute the same sequence as M" (italics added, Turing in Undecidable p. 128).

We now take this remarkable finding for granted. But at the time (1936) it was astonishing. The model of computation that Turing called his "universal machine" -- "U" for short -- is considered by some (cf Davis (2000)) to have been the fundamental theoretical breakthrough that led to the notion of the stored program computer. For much more see the article Universal Turing machine.

"Turing's paper ... contains, in essence, the invention of the modern computer and some of the programming techniques that accompanied it" (Minsky (1967), p. 104).

## Comparison with real machines

It is often said that Turing machines, unlike simpler automata, are as powerful as real machines, and are able to execute any operation that a real program can. What is missed in this statement is that almost any particular program running on a particular machine is in fact nothing but a deterministic finite automaton, since the machine it runs on can only be in finitely many configurations. Turing machines would actually only be equivalent to a machine that had an unlimited amount of storage space. We might ask, then, why Turing machines are useful models of real computers. There are a number of ways to answer this:

1. Anything a real computer can compute, a Turing machine can also compute. For example: "A Turing machine can simulate any type of subroutine found in programming languages, including recursive procedures and any of the known parameter-passing mechanisms" (Hopcroft and Ullman p. 157). Thus, a statement about the limitations of Turing machines will also apply to real computers.
2. The difference lies only with the ability of a Turing machine to manipulate an unbounded amount of data. However, given a finite amount of time, a Turing machine (like a real machine) can only manipulate a finite amount of data.
3. Like a Turing machine, a real machine can have its storage space enlarged as needed, by acquiring more disks or other storage media. If the supply of these runs short, the Turing machine may become less useful as a model. But the fact is that neither Turing machines nor real machines need astronomical amounts of storage space in order to perform useful computation. The processing time required is usually much more of a problem.
4. Real machines are much more complex than a Turing machine. For example, a Turing machine describing an algorithm may have a few hundred states, while the equivalent deterministic finite automaton on a given real machine has quadrillions. This makes the DFA representation infeasible to analyze.
5. Turing machines describe algorithms independent of how much memory they utilize. There is a limit to the memory possessed by any current machine, but this limit can rise arbitrarily in time. Turing machines allow us to make statements about algorithms which will (theoretically) hold forever, regardless of advances in conventional computing machine architecture.
6. Turing machines simplify the statement of algorithms. Algorithms running on Turing-equivalent abstract machines are usually more general than their counterparts running on real machines, because they have arbitrary-precision data types available and never have to deal with unexpected conditions (including, but not limited to, running out of memory).

One way in which Turing machines are a poor model for programs is that many real programs, such as operating systems and word processors, are written to receive unbounded input over time, and therefore do not halt. Turing machines do not model such ongoing computation well (but can still model portions of it, such as individual procedures).

### Limitations of Turing machines in computational complexity theory

A limitation of Turing Machines is that they do not model the strengths of a particular arrangement well. For instance, modern stored-program computers are actually instances of a more specific form of abstract machine known as the random access stored program machine or RASP machine model. Like the Universal Turing machine the RASP stores its "program" in "memory" external to its finite-state machine's "instructions". Unlike the Universal Turing Machine, the RASP has an infinite number of distinguishable, numbered but unbounded "registers" -- memory "cells" that can contain any integer (cf Elgot and Robinson (1964), Hartmanis (1971), and in particular Cook-Rechow (1973); references at random access machine). The RASP's finite-state machine is equipped with the capability for indirect addressing (e.g. the contents of one register can "point to" the address of any other, arbitrary register); thus the RASP's "program" can address any register in the register-sequence. The upshot of this distinction is that there are computational optimizations that can be performed based on the memory indices, which are not possible in a general Turing Machine; thus when Turing Machines are used as the basis for bounding running times, a 'false lower bound' can be proven on certain algorithms' running times (due to the false simplifying assumption of a Turing Machine). An example of this is binary search, which violates the Turing machine's linear Ω(n) lower bound on searching an ordered list. See more at Computational complexity theory.