Two-symbol Turing machines and the busy beaver (maximum shifts) function
DefinitionFCP_BusyBeaverAn -state, -symbol Turing machine is given by a transition table: for each state and each symbol 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 , and the tape contents.
A machine halts in steps from a configuration if it performs exactly transitions, the last of which halts it. The busy beaver function (maximum shifts) is the supremum of the halting times of the -state machines started on the all-blank tape in state with the head at position ; the set of such halting times is finite, so the supremum is attained for , and .
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.BusyBeaverRead-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 , a machine is a record containing a single transition function that takes a state (an element of the -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 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 or according to the direction, and either enters the new state or reports that no configuration results (halting). The -fold iterate of stepping, starting from a configuration , returns the configuration after steps, or nothing if the machine has halted at some earlier point; after zero steps it returns itself.
Halting in steps from means: the -fold iterate returns nothing, and for every the -fold iterate returns a configuration. Since the -fold iterate always returns a configuration, this forces .
The initial configuration (defined when ) is state , head position , and the tape identically false.
Finally is the supremum, taken in the natural numbers, of the set of all such that there exist a machine with states and a proof that , for which that machine halts in exactly steps from the initial configuration. For this set is empty and the supremum of the empty set of naturals is . The quantity measured is the number of transitions performed (maximum shifts), not the number of non-blank symbols left on the tape.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the mission captain (proposal self-audit).