Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Two-symbol Turing machines and the busy beaver (maximum shifts) function

Definition
FCP_BusyBeaver

by LG · Sep 15, 2026 · Mathlib 0df444a (Lean v4.33.1)

logictheoretical-computer-science

An nnn-state, 222-symbol Turing machine is given by a transition table: for each state qqq and each symbol sss read, it prescribes the symbol to write, the direction to move, and either the next state or the instruction to halt. A configuration is a state, a head position on a bi-infinite tape indexed by Z\mathbb{Z}Z, and the tape contents.

A machine halts in ttt steps from a configuration if it performs exactly ttt transitions, the last of which halts it. The busy beaver function BB(n)\mathrm{BB}(n)BB(n) (maximum shifts) is the supremum of the halting times of the nnn-state machines started on the all-blank tape in state 000 with the head at position 000; the set of such halting times is finite, so the supremum is attained for n≥1n \ge 1n≥1, and BB(0)=0\mathrm{BB}(0) = 0BB(0)=0.

Definition code
import Mathlib

namespace FCP.BusyBeaver

/-- An `n`-state, 2-symbol Turing machine: for each state and each symbol read it prescribes the
symbol to write, the direction to move (`true` = right, `false` = left) and either the next
state, or `none`, meaning the machine halts on performing this transition. -/
structure TM (n : ℕ) where
  trans : Fin n → Bool → Bool × Bool × Option (Fin n)

/-- A configuration: the current state, the head position on a bi-infinite tape indexed by `ℤ`,
and the tape contents. -/
structure Config (n : ℕ) where
  state : Fin n
  head : ℤ
  tape : ℤ → Bool

/-- One transition of the machine: it writes, moves, and either enters a new state or halts
(`none`). -/
def step {n : ℕ} (M : TM n) (c : Config n) : Option (Config n) :=
  match M.trans c.state (c.tape c.head) with
  | (_w, _d, none) => none
  | (w, d, some s) =>
      some ⟨s, if d then c.head + 1 else c.head - 1, Function.update c.tape c.head w⟩

/-- The configuration reached from `c` after `t` transitions, or `none` if the machine has
already halted. -/
def run {n : ℕ} (M : TM n) (c : Config n) : ℕ → Option (Config n)
  | 0 => some c
  | t + 1 => (run M c t).bind (step M)

/-- `HaltsIn M c t` says that started from `c` the machine performs exactly `t` transitions, the
last of which halts it. -/
def HaltsIn {n : ℕ} (M : TM n) (c : Config n) (t : ℕ) : Prop :=
  run M c t = none ∧ ∀ s < t, run M c s ≠ none

/-- The all-blank starting configuration, with the head at position `0` in state `0`. -/
def init {n : ℕ} (h : 0 < n) : Config n := ⟨⟨0, h⟩, 0, fun _ => false⟩

/-- The busy beaver function (maximum shifts): `BB n` is the largest number of transitions that
an `n`-state, 2-symbol machine can perform before halting, when started on the blank tape.
`BB 0 = 0`, since there are no `0`-state machines that can start. -/
noncomputable def BB (n : ℕ) : ℕ :=
  sSup {t : ℕ | ∃ (M : TM n) (h : 0 < n), HaltsIn M (init h) t}

end FCP.BusyBeaver
Source
Formal Conjectures library (Google DeepMind), Apache-2.0, https://github.com/google-deepmind/formal-conjectures (FormalConjectures/BusyBeaver.lean); https://wiki.bbchallenge.org/wiki/Main_Page
Read-back

What the Lean code literally says, in plain math · Aristotle by Harmonic (non-blind: same agent that drafted the statements)

Non-blind read-back. This read-back was not written by an independent blind auditor: it was written by the same agent that drafted the Lean statement, with full knowledge of the intended meaning and of the source material. It is therefore not independent testimony and must not be mistaken for it; a reviewer who wants genuine blind testimony should commission it separately.

For a natural number nnn, a machine is a record containing a single transition function that takes a state (an element of the nnn-element index set) and a Boolean symbol, and returns a triple: a Boolean to write, a Boolean direction (interpreted as 'right' when true and 'left' when false), and an optional next state — the absence of a next state meaning the machine halts on performing this transition. The transition function is total, so every state/symbol pair has a prescribed behaviour.

A configuration is a record consisting of a current state, an integer head position, and a tape, i.e. a function from Z\mathbb{Z}Z to Booleans.

One step reads the symbol under the head, writes the prescribed symbol at the head position (updating the tape at that single position), moves the head by +1+1+1 or −1-1−1 according to the direction, and either enters the new state or reports that no configuration results (halting). The ttt-fold iterate of stepping, starting from a configuration ccc, returns the configuration after ttt steps, or nothing if the machine has halted at some earlier point; after zero steps it returns ccc itself.

Halting in ttt steps from ccc means: the ttt-fold iterate returns nothing, and for every s<ts < ts<t the sss-fold iterate returns a configuration. Since the 000-fold iterate always returns a configuration, this forces t≥1t \ge 1t≥1.

The initial configuration (defined when n>0n > 0n>0) is state 000, head position 000, and the tape identically false.

Finally BB(n)\mathrm{BB}(n)BB(n) is the supremum, taken in the natural numbers, of the set of all ttt such that there exist a machine with nnn states and a proof that n>0n > 0n>0, for which that machine halts in exactly ttt steps from the initial configuration. For n=0n = 0n=0 this set is empty and the supremum of the empty set of naturals is 000. The quantity measured is the number of transitions performed (maximum shifts), not the number of non-blank symbols left on the tape.

Human review
  • Endorsed by Shuze Chen · Sep 17, 2026

  • Endorsed by LG · Sep 17, 2026

    Confirmed by the mission captain (proposal self-audit).

  • Endorsed by loader3229 · Nov 22, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me