Turing Machine Simulator: Program the Foundations of Computation

simulator intermediate ~15 min
Loading simulation...
Halted — computed unary increment: 4 → 5 in 23 steps

A 5-state Turing machine increments the unary number 1111 to 11111, demonstrating basic arithmetic on a single tape in 23 steps.

Formula

TM = (Q, Σ, Γ, δ, q₀, q_accept, q_reject)
δ : Q × Γ → Q × Γ × {L, R}
BB(n) > any computable function for large n

The Tape, the Head, the Rules

Alan Turing's 1936 paper introduced the simplest possible model of a general-purpose computer: an infinite tape of cells, a read/write head, and a finite table of rules. At each step, the machine reads the current cell, consults the transition table based on its current state and the symbol read, writes a new symbol, moves left or right, and enters a new state. This austere mechanism captures the full power of computation.

Universal Computation

Turing's most profound insight was that a single machine can simulate any other. By encoding a Turing machine's transition table as data on the tape, a universal Turing machine reads and executes that program step by step. This is the theoretical foundation of the stored-program computer — the architecture underlying every laptop, phone, and server today.

The Limits of Computation

Not everything is computable. Turing proved that no algorithm can determine, in general, whether an arbitrary Turing machine will halt or loop forever. This halting problem is the first in a vast landscape of undecidable problems. The Busy Beaver function — which asks how many steps the longest-halting n-state machine takes — grows faster than any computable function, illustrating the staggering complexity hiding inside tiny programs.

From Theory to Practice

Every programming language, every compiler, every operating system is ultimately a realization of Turing's model. Complexity classes like P and NP are defined in terms of Turing machine running times. The model remains the gold standard for reasoning about what is computable, what is efficient, and what is fundamentally impossible, making it as relevant today as it was in 1936.

FAQ

What is a Turing machine?

A Turing machine is a mathematical model of computation defined by Alan Turing in 1936. It consists of an infinite tape divided into cells, a head that reads and writes symbols, a state register, and a transition table. Despite its simplicity, it can compute anything that any computer can compute — this is the Church-Turing thesis.

What is the halting problem?

The halting problem asks whether a given Turing machine will eventually halt on a given input. Turing proved in 1936 that no algorithm can solve this problem in general — it is undecidable. This result establishes fundamental limits on what can be computed and is one of the most important theorems in computer science.

What is a universal Turing machine?

A universal Turing machine (UTM) takes as input the description of any Turing machine M and an input x, and simulates M on x. It is the theoretical precursor to stored-program computers — the idea that a single machine can run any program given its description as data.

How does a Turing machine relate to real computers?

Real computers are finite approximations of Turing machines — they have bounded memory instead of infinite tape. Any computation a real computer performs can be modeled by a Turing machine, and vice versa (given enough memory). This equivalence underpins all of theoretical computer science.

Sources

Embed

<iframe src="https://homo-deus.com/lab/automata-theory/turing-machine/embed" width="100%" height="400" frameborder="0"></iframe>
View source on GitHub