1. Home
  2. Explore
  3. Computer Science
  4. Turing Machines and Chocolate Computing

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Turing Machines and Chocolate Computing

Turing Machines and Computation

What a Turing machine is

A Turing machine is a simple mathematical model of computation. It was devised by Alan Turing to investigate what problems a machine could solve and what the fundamental limits of computation might be. The model was developed before modern electronic computers existed.

A Turing machine can be understood as a very simple computer with:

  • A memory in the form of a tape.

  • A read/write head that examines and changes the tape.

  • A state that records the machine’s current situation.

  • A finite set of instructions that determine what the machine does next.

A particular Turing machine has a fixed instruction table, so it performs a particular task. In principle, Turing machines can perform any computation that an ordinary computer can perform, although they may be much slower or less practical.

The central idea is that computation consists of following rules to manipulate symbols. The symbols do not have to be numbers or electronic signals: they can be represented by almost anything, provided the rules for handling them are clear.


Components of a Turing machine

The tape

The tape acts as the machine’s memory. It is divided into cells, each of which holds a symbol. In the idealized model, the tape is unbounded: it can provide as much working space as a computation needs. Some definitions allow the tape to extend infinitely in both directions; others allow it to extend in only one direction.

The tape begins with an input pattern of symbols. The cells beyond the input are assumed to contain the blank symbol. A blank may be represented by a special symbol or by an empty cell.

The tape is infinite in the model because no one can know in advance how much space every possible computation might require. In a practical simulation, a computer only needs to allocate as much tape as the particular computation uses.

The tape alphabet

The tape alphabet is the finite collection of symbols the machine is allowed to use. It includes:

  • Symbols that may appear in the initial input.

  • Symbols that the machine may write while computing.

  • A designated blank symbol.

The alphabet can be chosen to suit the task. It might contain binary digits, decimal digits, or other symbols. The physical objects used to represent the symbols are irrelevant as long as each symbol can be identified consistently.

For example, chocolate buttons of different colors could represent different symbols. A blank could be represented by an empty cell on the tape. The same abstract machine could instead be represented with marks on paper, counters, figures, or people holding symbol cards.

The read/write head

The read/write head points to one cell at a time. At each step, it reads the symbol in that cell and may:

  1. Write a symbol in the cell, possibly leaving the original symbol unchanged.

  2. Move one cell to the left or right.

  3. Change the machine’s state.

It is equivalent to imagine that the tape moves beneath a stationary head, but when building a physical version it is often easier to imagine the head moving along the tape.

The state register

The state records which stage of the machine’s process is currently active. A Turing machine has a finite set of possible states, including a designated start state and a halting state.

A state is not the same as a symbol on the tape. Tape symbols represent stored data; states represent the machine’s current control situation. In a physical demonstration, different colors can represent different states.

The instruction table

The instruction table is a finite collection of rules. Each rule describes what to do for a particular combination of:

  • The current state.

  • The symbol under the head.

The rule specifies the symbol to write, the direction to move, and the next state. It can be understood as a set of if–then instructions: if the machine is in a specified state and reads a specified symbol, then it performs the specified action.

A compact mathematical description of a rule is

δ(q,a)=(q′,b,D),\delta(q,a)=(q',b,D),δ(q,a)=(q′,b,D),

where qqq is the current state, aaa is the symbol being read, q′q'q′ is the next state, bbb is the symbol written, and DDD is the direction of movement.

The transition table may have no rule for a particular state-and-symbol combination. In that case, the machine halts. A machine may also halt by entering a specifically designated stop state.

The tape may be unbounded, but the alphabet, the state set, and the instruction table are all finite.


How a Turing machine computes

A computation begins with an initial tape, an initial head position, and the start state. The machine repeatedly applies the instruction that matches its current state and the symbol under the head. Each step can alter the tape, move the head, and change the state.

The computation ends when the machine reaches a stop state or has no applicable rule. The resulting tape, head position, or halting state can be interpreted as the output, depending on how the machine has been designed.

Thus, a Turing machine can be viewed as an input/output device:

  • Input: The initial arrangement of symbols on the tape.

  • Processing: Repeated execution of the instruction rules.

  • Output: The result left on the tape or otherwise indicated when the machine halts.


Representing numbers

A machine can operate on numbers only after the numbers have been encoded as tape symbols. Many representations are possible, including binary and decimal notation. A particularly simple representation is unary.

Unary notation

In unary notation, a number is represented by a repeated mark. For example, if the symbol 111 is used as the mark, then

5=111115 = 111115=11111

and

3=111.3 = 111.3=111.

The number is represented by the count of marks, rather than by place value. A blank symbol can separate two numbers on the tape, so the unary input for two followed by three could be written as

11  B  111,11\;B\;111,11B111,

where BBB denotes a blank separator.

Unary notation is easy to demonstrate because counting and addition can be performed by adding or moving marks. Its disadvantage is that it uses many symbols to represent large numbers.


Example: adding two unary numbers

Suppose the tape contains two unary numbers separated by one blank:

11  B  111.11\;B\;111.11B111.

The goal is to leave their sum on the tape. One method is to transfer a mark from the beginning of the first number into the blank separator:

  1. Change the first mark of the first number into a blank.

  2. Move right to the separator.

  3. Replace the separator with a mark.

The mark has effectively been moved from the first number to the gap between the numbers. Repeating the process until the first number has no marks joins the two groups of marks. The result is

11111,11111,11111,

which represents five.

A Turing machine implements this procedure by using different states to distinguish situations, such as “at the start of the first number” and “moving across the second number.” Its transition rules specify when to change a symbol, when to move, and when to halt.

The key point is that the algorithm is not the same thing as its physical representation. The same rules could be carried out using symbols on paper, chocolate buttons, or another agreed set of objects.


Example: adding two to a unary number

To add two to a unary number, the machine can scan to the end of the existing marks and then write two additional marks.

For example, starting with

111111111111

the machine finds the end of the number and changes the next two blank cells into marks, producing

111111.111111.111111.

A simple design uses states for two stages:

  1. Scan to the end: Move right over the existing marks until the first blank is reached.

  2. Add two marks: Write a mark in that blank cell, move right, and write a second mark.

The machine then halts. To return the head to the beginning of the number before halting, extra states can make it move left across the marks until it reaches the blank just before the number. It can then move right once to point at the first mark.

This illustrates how a machine’s states can be used to organize a multi-step task. A group of rules that carries out a recurring function, such as scanning to an endpoint or returning to the beginning, can be treated as a reusable conceptual module, even though the actual machine has one finite instruction table.


Example: doubling a binary number

Binary notation represents numbers using the symbols 000 and 111. In binary, appending a 000 to the right of a number doubles its value. For instance,

101⟶1010101 \longrightarrow 1010101⟶1010

because 1012101_21012​ represents five and 101021010_210102​ represents ten.

A Turing machine that doubles a binary number can therefore:

  1. Move right across the binary digits until it reaches a blank.

  2. Write a 000 in that blank cell.

  3. Optionally move back to a required stopping position.

  4. Halt.

This task requires a tape alphabet containing at least the symbols 000, 111, and the blank symbol. It demonstrates that a Turing machine can use more than two symbols.


Algorithms and instruction diagrams

A Turing machine’s instruction table can also be represented as a state-transition diagram. States are shown as nodes, and arrows show possible transitions. Each arrow indicates the condition for the transition and the actions performed, such as writing a symbol or moving the head.

A table and a transition diagram express the same rules in different forms. Both describe the machine’s behavior through conditional instructions.

When designing a machine, it is useful to decide on the algorithm before constructing the table:

  1. Specify how the input is represented.

  2. Describe the desired result.

  3. Break the task into stages.

  4. Choose states that identify which stage is underway.

  5. Write the rules that carry out each stage.

  6. Check that every intended situation has an applicable rule and that the machine eventually halts.

Different algorithms can produce the same numerical result while leaving the tape or head in different final arrangements. For example, an addition algorithm might preserve the original starting position of the result, while another might leave the head at the opposite end. These choices affect the machine’s instruction table.


Computation is not tied to electronic computers

A Turing machine is an abstract model, but its steps can be carried out by a person following instructions. In a physical demonstration:

  • A line of people or objects can represent tape cells.

  • Each person or object can display the symbol stored in that cell.

  • A pointer, person, or movable marker can represent the head.

  • A colored card or other marker can represent the current state.

  • A written instruction table can provide the rules.

This shows that computation is not inherently about silicon or electronics. It is about the systematic manipulation of symbols according to rules. Electronic computers are highly efficient ways to perform such manipulations, but the underlying idea can be represented with many different materials.


Computational power and the structure of programs

A Turing machine has the basic control ideas found in programming:

  • Sequence: Instructions are carried out one after another.

  • Selection: The next action depends on the current state and symbol, like a conditional choice.

  • Repetition: The machine can return to earlier states and repeat a process.

Together, these ideas allow a Turing machine to express general algorithms. Its fixed instruction table can be viewed as a program dedicated to one task.

The Turing-machine model is important because it describes a fundamental limit of what computers can calculate. A Turing machine can perform any computation that can be carried out algorithmically, in the sense captured by the model of effective computation. Ordinary modern computers can perform such computations too; their practical differences include speed, memory limits, and physical implementation. Some problems, however, are not computable by any Turing machine, so no ordinary computer can solve them in general.


The universal Turing machine

A universal Turing machine is a Turing machine that can simulate other Turing machines. Instead of having its task permanently built into a separate instruction table, it receives an encoded description of another machine and the input for that machine.

The tape can contain:

  • An encoded version of the simulated machine’s instruction table.

  • The simulated machine’s input.

  • A representation of its current state.

  • A representation of the position of its simulated head.

The universal machine repeatedly consults the encoded instructions, determines which rule applies to the simulated state and symbol, and updates the encoded tape and head position. In this way, it carries out the same computation that the described machine would perform.

This idea separates a program from the machine that executes it. A single universal machine can perform different tasks when given different program descriptions and inputs. This is the foundation of the stored-program idea used by general-purpose computers: the instructions, as well as the data, can be represented in memory.

A practical computer program can also simulate a Turing machine by storing its tape, state, and instruction table. Since a real computer has finite memory, such a simulation can only represent a finite portion of the idealized infinite tape at any one time, but it can extend that representation as needed for a particular computation.


Key takeaways

  • A Turing machine consists of an unbounded tape, a finite alphabet, a read/write head, a finite set of states, and a finite instruction table.

  • The machine follows rules based on its current state and the symbol under its head.

  • The tape serves as memory, while the state records the machine’s current control situation.

  • Symbols can be represented by any suitable physical objects; computation is fundamentally about rule-governed symbol manipulation.

  • Unary notation makes simple operations such as addition easy to demonstrate, while binary notation provides a compact representation of numbers.

  • Turing machines express sequence, selection, and repetition, allowing them to carry out general computations.

  • A universal Turing machine can simulate any other Turing machine by interpreting an encoded program and input.

  • The model explains both the broad capabilities of computers and the existence of problems that no computer can solve algorithmically.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent