A Turing Machine is a tuple where:
- is an alphabet (finite set of atomic symbols)
- is a finite set of states
- is the set of symbols that can be stored on the tape (we assume )
- is the initial state
- are terminating states
- is the transition function
The transition function maps a (state, symbol) to (state, symbol, direction). The direction tells us which way the head must be moved.
Initially the tape stores the input word, the head in the first symbol of the input string, and the machine in the state .
As the computation proceeds, the situations of the machine (or configuration) is described by a triple of: the current state, contents of the state, and the position of the head in the tape.
The word is accepted if the TM reaches and rejected if it reaches . Machine can also loop forever.
Example
The following machine recognises the language , that is, the language of strings that contain a number of s which is a power of .
Informal description:
- If head is on blank when we start, reject.
- Starting on first , move to end of string (first blank symbol), changing every other into .
- If tape contained just one , accept.
- If the number of s was odd, reject.
- Return head to beginning of input.
- Repeat.
The idea is that each iteration changes half of the s into . If the number of ones is a power of , we will eventually end up with just one and accept the input.
Power of TM
TMs are strictly more powerful than PDA. TMs can be associated with Type-0 languages in the Chomsky hierarchy. These are called recursively-enumerable languages.
However there are languages that are not recognisable, even by a TM. (The Halting Problem)
TMs as partial functions
TMs implement partial functions, they map words to (word, boolean) tuples. Since TMs can get caught in continuous loops, it’s possible for a TM to not return an output for a given word. (hence why they are only partial functions)
Turing computable
A function that can be implemented by a TM is called Turing computable.
Link to original
TMs are the theoretical basis of imperative programming.
Variants of Turing Machines
- Non-deterministic transitions: transition function returns a set: for the same state / symbol read, there may be several alternative transitions. One of them will be chosen non-deterministically.
- Multiple tapes: machine may have several tapes and corresponding read / write heads. Transition function defines which is the next state, depending on tuple of symbols read on the tapes, and indicates which symbol should be written in each tape.
- Tape with starting point, but unlimited to the right.
- Instead of a tape where it is possible to read and write, one can define a reading tape (for inputs), writing tape (for outputs) and a working tape (for r/w).
All these variants of TMs are computationally equivalent.
Universal TM
The Universal Turing Machine is a Turing machine that is capable of reading the “code” of a Turing machine along with its input, and simulates the execution of the machine on this input.
To do this, we need a way to ‘encode’ TMs.
- We can encode a TM on to a tape:
- This allows a TM to take another TM as input.
- can simulate
- can attempt to establish properties of (e.g. if it halts)
- is called the Universal Turing Machine
Encoding Turing Machines
We can give a code to each Turing machine.
- Assume the machine has states , where each is a number, is the initial state, and the last states are final.
- Assume the input alphabet is and the tape alphabet is ( is the blank symbol). A binary alphabet is sufficient to encode any kind of data.
- The transition function is represented as a table, or equivalently a list of -tuples of the form , where represents the current state, symbol on tape under head, new state, symbol written, direction of movement (written as ).
The full description of the machine is hence then where:
- is the list representing transition function
- is the number of states
- is the number of final states
The original machine can be recovered from the code. A code is a word, and as such it can be used as input for a Turing machine.
It is then possible to define a Turing machine such that, when the code of a machine is written on the tape, together with input word for , decodes it and simulates the behaviour of the machine on .
The machine is the universal Turing machine.
