Busy beaver
InductiveHead movement#✓fully proved
A head movement is one of exactly two directions: left or right.
inductive Move where
| left
| right
deriving DecidableEq
Used by 15
DefinitionHead displacement#✓fully proved
The displacement of a head movement is \(-1\) for a move to the left and \(1\) for a move to the right.
def Move.shift : Move → ℤ
| .left => -1
| .right => 1
inductive Move where
| left
| right
deriving DecidableEq
CSLibExt/Computability/BusyBeaver.lean:55
Uses 1 · Used by 6
AbbreviationBusy Beaver machine#✓fully proved
A Busy Beaver machine with \(n\) working states is a transition table that assigns to each of the \(n\) working states and each read symbol in \(\{0, 1\}\) a symbol in \(\{0, 1\}\) to write, a head movement (left or right), and a next state, which is either one of the \(n\) working states or the halt state.
The write and move of a halting transition are still performed, and the halting step counts toward the runtime.
abbrev Machine (n : ℕ) :=
Fin n → Fin 2 → Fin 2 × Move × Option (Fin n)
inductive Move where
| left
| right
deriving DecidableEq
CSLibExt/Computability/BusyBeaver.lean:55
Uses 1 · Used by 30
StructureBusy Beaver machine configuration#✓fully proved
A configuration of an \(n\)-state machine consists of a current state, which is either one of the \(n\) working states or the halt state, an integer head position, and a tape assigning a symbol in \(\{0, 1\}\) to every integer cell.
Used by 13
DefinitionOne step of a Busy Beaver machine#✓fully proved
Let \(M\) be a machine with \(n\) working states and let \(c\) be a configuration with head position \(h\). If \(c\) is halted, the step leaves \(c\) unchanged. Otherwise let \(q\) be the current state, let \(a\) be the symbol in cell \(h\), and let \(M(q, a) = (b, d, q')\). The step writes \(b\) in cell \(h\), leaving every other cell unchanged, moves the head to \(h - 1\) if \(d\) is left and to \(h + 1\) if \(d\) is right, and passes to the state \(q'\), which may be the halt state.
def step {n : ℕ} (M : Machine n) (c : Config n) : Config n :=
match c.state with
| none => c
| some q =>
let a := M q (c.tape c.head)
⟨a.2.2, c.head + a.2.1.shift, Function.update c.tape c.head a.1⟩
abbrev Machine (n : ℕ) :=
Fin n → Fin 2 → Fin 2 × Move × Option (Fin n)
CSLibExt/Computability/BusyBeaver.lean:75
structure Config (n : ℕ) where
state : Option (Fin n)
head : ℤ
tape : ℤ → Fin 2
CSLibExt/Computability/BusyBeaver.lean:80
Uses 4 · Used by 6
DefinitionInitial state#✓fully proved
For a machine with \(n\) working states, the initial state is state \(0\) when \(n > 0\), and the halt state when \(n = 0\).
DefinitionInitial configuration of a Busy Beaver machine#✓fully proved
The initial configuration of a machine with \(n\) working states is in the initial state (state \(0\), or the halt state when \(n = 0\)), with the head at position \(0\) and every tape cell blank, that is, holding the symbol \(0\).
def initial (n : ℕ) : Config n :=
⟨initialState n, 0, fun _ => 0⟩
structure Config (n : ℕ) where
state : Option (Fin n)
head : ℤ
tape : ℤ → Fin 2
CSLibExt/Computability/BusyBeaver.lean:80
def initialState (n : ℕ) : Option (Fin n) :=
if h : 0 < n then some ⟨0, h⟩ else none
CSLibExt/Computability/BusyBeaver.lean:123
Uses 2 · Used by 6
DefinitionConfiguration after \(t\) steps#✓fully proved
For a Busy Beaver machine \(M\) and \(t \in \mathbb{N}\), the configuration of \(M\) after \(t\) steps is the result of applying the one-step map of \(M\) \(t\) times to the initial configuration on the blank tape.
def run {n : ℕ} (M : Machine n) (t : ℕ) : Config n :=
(step M)^[t] (initial n)
abbrev Machine (n : ℕ) :=
Fin n → Fin 2 → Fin 2 × Move × Option (Fin n)
CSLibExt/Computability/BusyBeaver.lean:75
structure Config (n : ℕ) where
state : Option (Fin n)
head : ℤ
tape : ℤ → Fin 2
CSLibExt/Computability/BusyBeaver.lean:80
def step {n : ℕ} (M : Machine n) (c : Config n) : Config n :=
match c.state with
| none => c
| some q =>
let a := M q (c.tape c.head)
⟨a.2.2, c.head + a.2.1.shift, Function.update c.tape c.head a.1⟩
CSLibExt/Computability/BusyBeaver.lean:86
def initial (n : ℕ) : Config n :=
⟨initialState n, 0, fun _ => 0⟩
CSLibExt/Computability/BusyBeaver.lean:127
Uses 4 · Used by 9
DefinitionHalting within \(t\) steps#✓fully proved
A Busy Beaver machine \(M\) with \(n\) working states halts within \(t\) steps when the configuration reached after running \(M\) for \(t\) steps from the initial blank-tape configuration is in the halt state.
def HaltsWithin {n : ℕ} (M : Machine n) (t : ℕ) : Prop :=
(run M t).state = none
abbrev Machine (n : ℕ) :=
Fin n → Fin 2 → Fin 2 × Move × Option (Fin n)
CSLibExt/Computability/BusyBeaver.lean:75
def run {n : ℕ} (M : Machine n) (t : ℕ) : Config n :=
(step M)^[t] (initial n)
CSLibExt/Computability/BusyBeaver.lean:131
Uses 3 · Used by 6
DefinitionHalting on the blank tape#✓fully proved
A Busy Beaver machine \(M\) halts when there is a number of steps \(t\) such that \(M\) halts within \(t\) steps, that is, when \(M\) started from the initial blank-tape configuration eventually reaches the halt state.
def Halts {n : ℕ} (M : Machine n) : Prop :=
∃ t, HaltsWithin M t
abbrev Machine (n : ℕ) :=
Fin n → Fin 2 → Fin 2 × Move × Option (Fin n)
CSLibExt/Computability/BusyBeaver.lean:75
def HaltsWithin {n : ℕ} (M : Machine n) (t : ℕ) : Prop :=
(run M t).state = none
CSLibExt/Computability/BusyBeaver.lean:141
Uses 2 · Used by 9
DefinitionHalting time#✓fully proved
For an \(n\)-state machine \(M\) that halts on the blank tape, its halting time is the least \(t\) such that \(M\), started on the blank tape, is in the halt state after \(t\) steps.
noncomputable def haltTime {n : ℕ} (M : Machine n) (h : Halts M) : ℕ :=
@Nat.find _ (fun t => Classical.propDecidable _) h
abbrev Machine (n : ℕ) :=
Fin n → Fin 2 → Fin 2 × Move × Option (Fin n)
CSLibExt/Computability/BusyBeaver.lean:75
def Halts {n : ℕ} (M : Machine n) : Prop :=
∃ t, HaltsWithin M t
CSLibExt/Computability/BusyBeaver.lean:145
Uses 3 · Used by 3
TheoremHead displacement bound#✓fully proved
For every \(n\)-state Busy Beaver machine \(M\) and every \(t \in \mathbb{N}\), if \(h \in \mathbb{Z}\) is the head position after \(M\) has run for \(t\) steps from the initial configuration on the blank tape, then \(|h| \le t\).
theorem abs_head_le {n : ℕ} (M : Machine n) (t : ℕ) :
|(run M t).head| ≤ t
abbrev Machine (n : ℕ) :=
Fin n → Fin 2 → Fin 2 × Move × Option (Fin n)
CSLibExt/Computability/BusyBeaver.lean:75
def run {n : ℕ} (M : Machine n) (t : ℕ) : Config n :=
(step M)^[t] (initial n)
CSLibExt/Computability/BusyBeaver.lean:131
Uses 7 · Used by 1
TheoremCells far from the origin stay blank#✓fully proved
Let \(M\) be a machine with \(n\) working states, started in cell \(0\) on the blank tape. For every \(t \in \mathbb{N}\) and every cell \(i \in \mathbb{Z}\) with \(|i| > t\), the symbol in cell \(i\) after \(t\) steps is \(0\).
theorem tape_eq_zero_of_abs_gt {n : ℕ} (M : Machine n) (t : ℕ)
{i : ℤ} (hi : t < |i|) : (run M t).tape i = 0
abbrev Machine (n : ℕ) :=
Fin n → Fin 2 → Fin 2 × Move × Option (Fin n)
CSLibExt/Computability/BusyBeaver.lean:75
def run {n : ℕ} (M : Machine n) (t : ℕ) : Config n :=
(step M)^[t] (initial n)
CSLibExt/Computability/BusyBeaver.lean:131
Uses 8 · Used by 2
DefinitionNumber of ones after \(t\) steps#✓fully proved
For a Busy Beaver machine \(M\) and \(t \in \mathbb{N}\), the number of ones of \(M\) after \(t\) steps is the number of cells \(i \in \mathbb{Z}\) with \(-t \le i \le t\) that hold the symbol \(1\) in the configuration of \(M\) after \(t\) steps, started on the blank tape.
Every one on the tape after \(t\) steps lies in this window, since the head moves at most one cell per step.
def onesAt {n : ℕ} (M : Machine n) (t : ℕ) : ℕ :=
((Finset.Icc (-(t : ℤ)) t).filter fun i => (run M t).tape i = 1).card
abbrev Machine (n : ℕ) :=
Fin n → Fin 2 → Fin 2 × Move × Option (Fin n)
CSLibExt/Computability/BusyBeaver.lean:75
def run {n : ℕ} (M : Machine n) (t : ℕ) : Config n :=
(step M)^[t] (initial n)
CSLibExt/Computability/BusyBeaver.lean:131
TheoremAfter \(t\) steps, every one lies within distance \(t\) of the origin#✓fully proved
For every Busy Beaver machine \(M\), every \(t \in \mathbb{N}\) and every cell \(i \in \mathbb{Z}\), if cell \(i\) holds the symbol \(1\) after \(M\) runs for \(t\) steps from the initial blank-tape configuration, then \(-t \le i \le t\).
theorem mem_window_of_tape_eq_one {n : ℕ} (M : Machine n) (t : ℕ) {i : ℤ}
(hi : (run M t).tape i = 1) : i ∈ Finset.Icc (-(t : ℤ)) t
abbrev Machine (n : ℕ) :=
Fin n → Fin 2 → Fin 2 × Move × Option (Fin n)
CSLibExt/Computability/BusyBeaver.lean:75
def run {n : ℕ} (M : Machine n) (t : ℕ) : Config n :=
(step M)^[t] (initial n)
CSLibExt/Computability/BusyBeaver.lean:131
Uses 4 · Used by 1
TheoremThe number of ones grows by at most one per step#✓fully proved
For every Busy Beaver machine \(M\) and every \(t \in \mathbb{N}\), the number of ones of \(M\) after \(t + 1\) steps is at most the number of ones of \(M\) after \(t\) steps plus \(1\).
theorem onesAt_succ_le {n : ℕ} (M : Machine n) (t : ℕ) :
onesAt M (t + 1) ≤ onesAt M t + 1
abbrev Machine (n : ℕ) :=
Fin n → Fin 2 → Fin 2 × Move × Option (Fin n)
CSLibExt/Computability/BusyBeaver.lean:75
def onesAt {n : ℕ} (M : Machine n) (t : ℕ) : ℕ :=
((Finset.Icc (-(t : ℤ)) t).filter fun i => (run M t).tape i = 1).card
CSLibExt/Computability/BusyBeaver.lean:243
Uses 9 · Used by 1
TheoremAt most \(t\) ones after \(t\) steps#✓fully proved
For every Busy Beaver machine \(M\) and every \(t \in \mathbb{N}\), the number of ones of \(M\) after \(t\) steps is at most \(t\).
theorem onesAt_le_steps {n : ℕ} (M : Machine n) (t : ℕ) :
onesAt M t ≤ t
abbrev Machine (n : ℕ) :=
Fin n → Fin 2 → Fin 2 × Move × Option (Fin n)
CSLibExt/Computability/BusyBeaver.lean:75
def onesAt {n : ℕ} (M : Machine n) (t : ℕ) : ℕ :=
((Finset.Icc (-(t : ℤ)) t).filter fun i => (run M t).tape i = 1).card
CSLibExt/Computability/BusyBeaver.lean:243
Uses 5 · Used by 1
DefinitionRuntime of a Busy Beaver machine#✓fully proved
For a machine \(M\) with \(n\) working states, the runtime of \(M\) is its halting time on the blank tape if \(M\) halts, and \(0\) if \(M\) does not halt. This is the quantity whose maximum over all \(n\)-state machines is the shift function \(S(n)\).
noncomputable def stepsOf {n : ℕ} (M : Machine n) : ℕ :=
@dite ℕ (Halts M) (Classical.propDecidable _) (fun h => haltTime M h)
(fun _ => 0)
abbrev Machine (n : ℕ) :=
Fin n → Fin 2 → Fin 2 × Move × Option (Fin n)
CSLibExt/Computability/BusyBeaver.lean:75
def Halts {n : ℕ} (M : Machine n) : Prop :=
∃ t, HaltsWithin M t
CSLibExt/Computability/BusyBeaver.lean:145
noncomputable def haltTime {n : ℕ} (M : Machine n) (h : Halts M) : ℕ :=
@Nat.find _ (fun t => Classical.propDecidable _) h
CSLibExt/Computability/BusyBeaver.lean:164
Uses 3 · Used by 3
DefinitionScore of a machine#✓fully proved
For a Busy Beaver machine \(M\): if \(M\) halts on the blank tape, with halting time \(T\), its score is the number of ones of \(M\) after \(T\) steps; if \(M\) does not halt, its score is \(0\).
noncomputable def scoreOf {n : ℕ} (M : Machine n) : ℕ :=
@dite ℕ (Halts M) (Classical.propDecidable _)
(fun h => onesAt M (haltTime M h)) (fun _ => 0)
abbrev Machine (n : ℕ) :=
Fin n → Fin 2 → Fin 2 × Move × Option (Fin n)
CSLibExt/Computability/BusyBeaver.lean:75
def Halts {n : ℕ} (M : Machine n) : Prop :=
∃ t, HaltsWithin M t
CSLibExt/Computability/BusyBeaver.lean:145
def onesAt {n : ℕ} (M : Machine n) (t : ℕ) : ℕ :=
((Finset.Icc (-(t : ℤ)) t).filter fun i => (run M t).tape i = 1).card
CSLibExt/Computability/BusyBeaver.lean:243
noncomputable def haltTime {n : ℕ} (M : Machine n) (h : Halts M) : ℕ :=
@Nat.find _ (fun t => Classical.propDecidable _) h
CSLibExt/Computability/BusyBeaver.lean:164
Uses 4 · Used by 3
DefinitionBusy Beaver shift function#✓fully proved
For \(n \in \mathbb{N}\), Rado's shift function \(S(n)\) is the largest halting time of an \(n\)-state two-symbol machine that halts when started on the blank tape; machines that do not halt contribute \(0\).
noncomputable def busyBeaverSteps (n : ℕ) : ℕ :=
(Finset.univ : Finset (Machine n)).sup stepsOf
abbrev Machine (n : ℕ) :=
Fin n → Fin 2 → Fin 2 × Move × Option (Fin n)
CSLibExt/Computability/BusyBeaver.lean:75
noncomputable def stepsOf {n : ℕ} (M : Machine n) : ℕ :=
@dite ℕ (Halts M) (Classical.propDecidable _) (fun h => haltTime M h)
(fun _ => 0)
CSLibExt/Computability/BusyBeaver.lean:337
Uses 3 · Used by 7
DefinitionBusy Beaver score function#✓fully proved
For \(n \in \mathbb{N}\), Rado's score function \(\Sigma(n)\) is the largest number of ones left on the tape, at its halting time, by an \(n\)-state two-symbol machine that halts when started on the blank tape; machines that do not halt contribute \(0\).
noncomputable def busyBeaverOnes (n : ℕ) : ℕ :=
(Finset.univ : Finset (Machine n)).sup scoreOf
abbrev Machine (n : ℕ) :=
Fin n → Fin 2 → Fin 2 × Move × Option (Fin n)
CSLibExt/Computability/BusyBeaver.lean:75
noncomputable def scoreOf {n : ℕ} (M : Machine n) : ℕ :=
@dite ℕ (Halts M) (Classical.propDecidable _)
(fun h => onesAt M (haltTime M h)) (fun _ => 0)
CSLibExt/Computability/BusyBeaver.lean:343
Uses 3 · Used by 5
TheoremThe Busy Beaver score is at most the shift#✓fully proved
For every \(n \in \mathbb{N}\), Rado's score function \(\Sigma\) and Rado's shift function \(S\) satisfy \(\Sigma(n) \le S(n)\): the largest number of ones left on the tape by a halting \(n\)-state two-symbol machine started on the blank tape is at most the largest halting time of such a machine.
theorem busyBeaverOnes_le_steps (n : ℕ) :
busyBeaverOnes n ≤ busyBeaverSteps n
noncomputable def busyBeaverOnes (n : ℕ) : ℕ :=
(Finset.univ : Finset (Machine n)).sup scoreOf
CSLibExt/Computability/BusyBeaver.lean:354
noncomputable def busyBeaverSteps (n : ℕ) : ℕ :=
(Finset.univ : Finset (Machine n)).sup stepsOf
CSLibExt/Computability/BusyBeaver.lean:349
TheoremThe shift function is attained#✓fully proved
Let \(S(n)\) be Rado's shift function, the largest runtime of an \(n\)-state machine, where the runtime of a machine is its halting time on the blank tape if it halts and \(0\) otherwise. For every \(n\), some \(n\)-state machine \(M\) has runtime equal to \(S(n)\). Thus \(S(n)\) is the halting time of a halting \(n\)-state machine, or \(S(n) = 0\).
theorem exists_stepsOf_eq (n : ℕ) :
∃ M : Machine n, stepsOf M = busyBeaverSteps n
abbrev Machine (n : ℕ) :=
Fin n → Fin 2 → Fin 2 × Move × Option (Fin n)
CSLibExt/Computability/BusyBeaver.lean:75
noncomputable def stepsOf {n : ℕ} (M : Machine n) : ℕ :=
@dite ℕ (Halts M) (Classical.propDecidable _) (fun h => haltTime M h)
(fun _ => 0)
CSLibExt/Computability/BusyBeaver.lean:337
noncomputable def busyBeaverSteps (n : ℕ) : ℕ :=
(Finset.univ : Finset (Machine n)).sup stepsOf
CSLibExt/Computability/BusyBeaver.lean:349
Uses 4
TheoremThe score function is attained#✓fully proved
Let \(\Sigma(n)\) be the busy beaver score function, the largest score of an \(n\)-state machine, where the score of a machine is the number of ones on its final tape if it halts on the blank tape and \(0\) otherwise. For every \(n\), some \(n\)-state machine \(M\) has score equal to \(\Sigma(n)\). Thus \(\Sigma(n)\) is the number of ones left by a halting \(n\)-state machine, or \(\Sigma(n) = 0\).
theorem exists_scoreOf_eq (n : ℕ) :
∃ M : Machine n, scoreOf M = busyBeaverOnes n
abbrev Machine (n : ℕ) :=
Fin n → Fin 2 → Fin 2 × Move × Option (Fin n)
CSLibExt/Computability/BusyBeaver.lean:75
noncomputable def scoreOf {n : ℕ} (M : Machine n) : ℕ :=
@dite ℕ (Halts M) (Classical.propDecidable _)
(fun h => onesAt M (haltTime M h)) (fun _ => 0)
CSLibExt/Computability/BusyBeaver.lean:343
noncomputable def busyBeaverOnes (n : ℕ) : ℕ :=
(Finset.univ : Finset (Machine n)).sup scoreOf
CSLibExt/Computability/BusyBeaver.lean:354
Uses 4
DefinitionEmbedding a machine into one more state#✓fully proved
An \(n\)-state machine \(M\) is embedded into \(n + 1\) states as follows. In a working state \(q < n\) reading a symbol \(s\), the new machine writes the symbol, makes the move and enters the next state that \(M\) prescribes in state \(q\) on \(s\), halting when \(M\) halts. In the new state \(n\) it writes \(0\), moves left and halts, whatever it reads.
No transition enters state \(n\). So for \(n \ge 1\), where the machine starts in state \(0 < n\), the new state is never reached; for \(n = 0\) the new state is the start state.
def embedMachine {n : ℕ} (M : Machine n) : Machine (n + 1) :=
fun q s =>
if h : q.val < n then
let a := M ⟨q.val, h⟩ s
(a.1, a.2.1, a.2.2.map Fin.castSucc)
else (0, Move.left, none)
abbrev Machine (n : ℕ) :=
Fin n → Fin 2 → Fin 2 × Move × Option (Fin n)
CSLibExt/Computability/BusyBeaver.lean:75
inductive Move where
| left
| right
deriving DecidableEq
CSLibExt/Computability/BusyBeaver.lean:55
Uses 2 · Used by 1
DefinitionEmbedding a configuration into one more state#✓fully proved
For a configuration \(c\) of an \(n\)-state machine, its embedding is the configuration for \(n + 1\) states with the same head position and the same tape as \(c\). Its state is the state of \(c\), where a working state \(q \in \{0, \dots, n - 1\}\) stays \(q\) and the halt state stays the halt state.
def embedConfig {n : ℕ} (c : Config n) : Config (n + 1) :=
⟨c.state.map Fin.castSucc, c.head, c.tape⟩
structure Config (n : ℕ) where
state : Option (Fin n)
head : ℤ
tape : ℤ → Fin 2
CSLibExt/Computability/BusyBeaver.lean:80
Uses 1
TheoremA one-state machine that stays in its state on a blank never halts#✓fully proved
Let \(M\) be a Busy Beaver machine with a single working state \(0\). If the transition of \(M\) from state \(0\) on reading the blank symbol \(0\) has next state \(0\), then \(M\) does not halt.
Such a machine marches in one direction forever: at every step the head is on a previously unvisited blank cell.
theorem not_halts_of_one_state_march (M : Machine 1)
(hnext : (M 0 0).2.2 = some 0) : ¬ Halts M
abbrev Machine (n : ℕ) :=
Fin n → Fin 2 → Fin 2 × Move × Option (Fin n)
CSLibExt/Computability/BusyBeaver.lean:75
def Halts {n : ℕ} (M : Machine n) : Prop :=
∃ t, HaltsWithin M t
CSLibExt/Computability/BusyBeaver.lean:145
Uses 11 · Used by 1
TheoremOne-state machines halt within one step#✓fully proved
Every halting one-state machine halts within one step.
theorem haltsWithin_one_of_halts (M : Machine 1) (h : Halts M) :
HaltsWithin M 1
abbrev Machine (n : ℕ) :=
Fin n → Fin 2 → Fin 2 × Move × Option (Fin n)
CSLibExt/Computability/BusyBeaver.lean:75
def Halts {n : ℕ} (M : Machine n) : Prop :=
∃ t, HaltsWithin M t
CSLibExt/Computability/BusyBeaver.lean:145
def HaltsWithin {n : ℕ} (M : Machine n) (t : ℕ) : Prop :=
(run M t).state = none
CSLibExt/Computability/BusyBeaver.lean:141
Uses 11
DefinitionMachine code#✓fully proved
The code of a machine \(M\) with \(n\) working states is the natural number that encodes the pair \((n, i)\) under a fixed pairing bijection \(\mathbb{N} \times \mathbb{N} \to \mathbb{N}\), where \(i\) is the index of \(M\) in a fixed enumeration of the finitely many machines with \(n\) working states.
noncomputable def machineCode {n : ℕ} (M : Machine n) : ℕ :=
Nat.pair n (Fintype.equivFinOfCardEq (α := Machine n) rfl M).val
abbrev Machine (n : ℕ) :=
Fin n → Fin 2 → Fin 2 × Move × Option (Fin n)
CSLibExt/Computability/BusyBeaver.lean:75
Uses 2 · Used by 2
DefinitionSentence codes#✓fully proved
The sentence code with tag \(a\) and payload \(p\) is the natural number \(4p + a\). The tags in use are \(0\) (the coded machine halts), \(1\) (the coded machine does not halt), \(2\) (the false sentence), and \(3\) with payload the pairing code of \(n\) and \(B\) (every halting \(n\)-state machine halts within \(B\) steps).
Sentences are natural numbers rather than propositions, so provability does not collapse under propositional extensionality.
def sentenceCode (tag payload : ℕ) : ℕ :=
4 * payload + tag
Used by 4
DefinitionHalting sentence of a machine#✓fully proved
For an \(n\)-state machine \(M\), the halting sentence of \(M\) is the sentence code with tag \(0\) and payload the code of \(M\). It stands for "\(M\) halts on the blank tape"; this meaning comes from soundness hypotheses on a theory, not from the code itself.
noncomputable def haltsSentence {n : ℕ} (M : Machine n) : ℕ :=
sentenceCode 0 (machineCode M)
abbrev Machine (n : ℕ) :=
Fin n → Fin 2 → Fin 2 × Move × Option (Fin n)
CSLibExt/Computability/BusyBeaver.lean:75
def sentenceCode (tag payload : ℕ) : ℕ :=
4 * payload + tag
CSLibExt/Computability/BusyBeaver.lean:756
noncomputable def machineCode {n : ℕ} (M : Machine n) : ℕ :=
Nat.pair n (Fintype.equivFinOfCardEq (α := Machine n) rfl M).val
CSLibExt/Computability/BusyBeaver.lean:747
Uses 3 · Used by 6
DefinitionNon-halting sentence of a machine#✓fully proved
For a Busy Beaver machine \(M\), the non-halting sentence of \(M\) is the sentence code with tag \(1\) whose payload is the code of \(M\); it stands for "\(M\) does not halt on the blank tape".
noncomputable def notHaltsSentence {n : ℕ} (M : Machine n) : ℕ :=
sentenceCode 1 (machineCode M)
abbrev Machine (n : ℕ) :=
Fin n → Fin 2 → Fin 2 × Move × Option (Fin n)
CSLibExt/Computability/BusyBeaver.lean:75
def sentenceCode (tag payload : ℕ) : ℕ :=
4 * payload + tag
CSLibExt/Computability/BusyBeaver.lean:756
noncomputable def machineCode {n : ℕ} (M : Machine n) : ℕ :=
Nat.pair n (Fintype.equivFinOfCardEq (α := Machine n) rfl M).val
CSLibExt/Computability/BusyBeaver.lean:747
Uses 3 · Used by 6
DefinitionThe false sentence#✓fully proved
The false sentence is the sentence code with tag \(2\) and payload \(0\), that is, the natural number \(2\).
def falseSentence : ℕ :=
sentenceCode 2 0
def sentenceCode (tag payload : ℕ) : ℕ :=
4 * payload + tag
CSLibExt/Computability/BusyBeaver.lean:756
Uses 1 · Used by 2
DefinitionRuntime-bound sentence#✓fully proved
For natural numbers \(n\) and \(B\), the runtime-bound sentence is the sentence code with tag \(3\) and payload \(\langle n, B \rangle\), the pairing of \(n\) and \(B\); as a number it equals \(4 \langle n, B \rangle + 3\).
Its intended reading is "every halting \(n\)-state machine halts within \(B\) steps"; this meaning is assigned only through separate soundness hypotheses.
def boundSentence (n B : ℕ) : ℕ :=
sentenceCode 3 (Nat.pair n B)
def sentenceCode (tag payload : ℕ) : ℕ :=
4 * payload + tag
CSLibExt/Computability/BusyBeaver.lean:756
Uses 1 · Used by 2
StructureFormal theory#✓fully proved
A formal theory is given by a provability predicate on sentence codes, which are natural numbers: for each natural number it specifies whether that sentence code is provable in the theory.
The theory is an abstract parameter, with ZFC as the intended instance. No meaning is attached to sentence codes here; the halting, non-halting, false and runtime-bound sentences receive their meaning through separate soundness hypotheses.
structure FormalTheory where
/-- Provability of a sentence code in the theory. -/
Provable : ℕ → Prop
Used by 9
DefinitionConsistent formal theory#✓fully proved
A formal theory \(T\) is consistent when \(T\) does not prove the false sentence.
def Consistent (T : FormalTheory) : Prop :=
¬ T.Provable falseSentence
structure FormalTheory where
/-- Provability of a sentence code in the theory. -/
Provable : ℕ → Prop
CSLibExt/Computability/BusyBeaver.lean:798
def falseSentence : ℕ :=
sentenceCode 2 0
CSLibExt/Computability/BusyBeaver.lean:768
Uses 2 · Used by 1
DefinitionSoundness for halting sentences#✓fully proved
A formal theory \(T\) is sound for halting sentences when, for every \(n\) and every Busy Beaver machine \(M\) with \(n\) states, if \(T\) proves the halting sentence of \(M\) then \(M\) halts on the blank tape, and if \(T\) proves the non-halting sentence of \(M\) then \(M\) does not halt on the blank tape.
def SoundForHalting (T : FormalTheory) : Prop :=
(∀ {n : ℕ} (M : Machine n), T.Provable (haltsSentence M) → Halts M) ∧
(∀ {n : ℕ} (M : Machine n),
T.Provable (notHaltsSentence M) → ¬ Halts M)
structure FormalTheory where
/-- Provability of a sentence code in the theory. -/
Provable : ℕ → Prop
CSLibExt/Computability/BusyBeaver.lean:798
abbrev Machine (n : ℕ) :=
Fin n → Fin 2 → Fin 2 × Move × Option (Fin n)
CSLibExt/Computability/BusyBeaver.lean:75
noncomputable def haltsSentence {n : ℕ} (M : Machine n) : ℕ :=
sentenceCode 0 (machineCode M)
CSLibExt/Computability/BusyBeaver.lean:760
def Halts {n : ℕ} (M : Machine n) : Prop :=
∃ t, HaltsWithin M t
CSLibExt/Computability/BusyBeaver.lean:145
noncomputable def notHaltsSentence {n : ℕ} (M : Machine n) : ℕ :=
sentenceCode 1 (machineCode M)
CSLibExt/Computability/BusyBeaver.lean:764
Uses 5 · Used by 1
DefinitionTheories deciding halting at a state count#✓fully proved
A formal theory \(T\) decides halting for \(n\)-state machines when, for every \(n\)-state machine \(M\), \(T\) proves the halting sentence of \(M\) or \(T\) proves the non-halting sentence of \(M\).
def DecidesHalting (T : FormalTheory) (n : ℕ) : Prop :=
∀ M : Machine n,
T.Provable (haltsSentence M) ∨ T.Provable (notHaltsSentence M)
structure FormalTheory where
/-- Provability of a sentence code in the theory. -/
Provable : ℕ → Prop
CSLibExt/Computability/BusyBeaver.lean:798
abbrev Machine (n : ℕ) :=
Fin n → Fin 2 → Fin 2 × Move × Option (Fin n)
CSLibExt/Computability/BusyBeaver.lean:75
noncomputable def haltsSentence {n : ℕ} (M : Machine n) : ℕ :=
sentenceCode 0 (machineCode M)
CSLibExt/Computability/BusyBeaver.lean:760
noncomputable def notHaltsSentence {n : ℕ} (M : Machine n) : ℕ :=
sentenceCode 1 (machineCode M)
CSLibExt/Computability/BusyBeaver.lean:764
Uses 4 · Used by 5
DefinitionFirst undecidable number of states#✓fully proved
For a formal theory \(T\), the first undecidable number of states is the least \(n\) such that \(T\) does not decide halting for all \(n\)-state machines, that is, there is an \(n\)-state machine \(M\) for which \(T\) proves neither the halting sentence nor the non-halting sentence of \(M\). It is \(0\) when there is no such \(n\).
For ZFC this is catalogue constant 14a; the junk value \(0\) covers a theory that decides halting at every number of states.
noncomputable def firstUndecidable (T : FormalTheory) : ℕ :=
sInf {n | ¬ DecidesHalting T n}
structure FormalTheory where
/-- Provability of a sentence code in the theory. -/
Provable : ℕ → Prop
CSLibExt/Computability/BusyBeaver.lean:798
def DecidesHalting (T : FormalTheory) (n : ℕ) : Prop :=
∀ M : Machine n,
T.Provable (haltsSentence M) ∨ T.Provable (notHaltsSentence M)
CSLibExt/Computability/BusyBeaver.lean:816
Uses 2 · Used by 1
TheoremDecidability through five states and the first undecidable size#✓fully proved
If a formal theory \(T\) decides halting for \(n\)-state machines for every \(n \le 5\), and fails to decide halting for \(n\)-state machines for some \(n\), then the first undecidable size of \(T\) is at least \(6\).
This is the shape of the catalogue lower bound from the determination of the five-state Busy Beaver value.
theorem six_le_firstUndecidable_of_decides_le_five {T : FormalTheory}
(h5 : ∀ n ≤ 5, DecidesHalting T n)
(hex : ∃ n, ¬ DecidesHalting T n) :
6 ≤ firstUndecidable T
structure FormalTheory where
/-- Provability of a sentence code in the theory. -/
Provable : ℕ → Prop
CSLibExt/Computability/BusyBeaver.lean:798
def DecidesHalting (T : FormalTheory) (n : ℕ) : Prop :=
∀ M : Machine n,
T.Provable (haltsSentence M) ∨ T.Provable (notHaltsSentence M)
CSLibExt/Computability/BusyBeaver.lean:816
noncomputable def firstUndecidable (T : FormalTheory) : ℕ :=
sInf {n | ¬ DecidesHalting T n}
CSLibExt/Computability/BusyBeaver.lean:824
Uses 3
TheoremA consistency-search machine blocks decidability at its size#✓fully proved
Let \(T\) be a formal theory and \(M\) a Busy Beaver machine with \(n\) working states. Suppose that \(M\) halts if and only if \(T\) proves the false sentence, that \(M\) halts whenever \(T\) proves the halting sentence of \(M\), that \(T\) is consistent, and that \(T\) does not prove the non-halting sentence of \(M\). Then \(T\) does not decide halting for all machines with \(n\) working states.
The last hypothesis is the Gödel second-incompleteness content when \(T\) is ZFC.
theorem not_decides_of_consistency_machine {T : FormalTheory} {n : ℕ}
(M : Machine n) (hM : Halts M ↔ T.Provable falseSentence)
(hsound : T.Provable (haltsSentence M) → Halts M)
(hcons : Consistent T)
(hnot : ¬ T.Provable (notHaltsSentence M)) :
¬ DecidesHalting T n
structure FormalTheory where
/-- Provability of a sentence code in the theory. -/
Provable : ℕ → Prop
CSLibExt/Computability/BusyBeaver.lean:798
abbrev Machine (n : ℕ) :=
Fin n → Fin 2 → Fin 2 × Move × Option (Fin n)
CSLibExt/Computability/BusyBeaver.lean:75
def Halts {n : ℕ} (M : Machine n) : Prop :=
∃ t, HaltsWithin M t
CSLibExt/Computability/BusyBeaver.lean:145
def falseSentence : ℕ :=
sentenceCode 2 0
CSLibExt/Computability/BusyBeaver.lean:768
noncomputable def haltsSentence {n : ℕ} (M : Machine n) : ℕ :=
sentenceCode 0 (machineCode M)
CSLibExt/Computability/BusyBeaver.lean:760
def Consistent (T : FormalTheory) : Prop :=
¬ T.Provable falseSentence
CSLibExt/Computability/BusyBeaver.lean:803
noncomputable def notHaltsSentence {n : ℕ} (M : Machine n) : ℕ :=
sentenceCode 1 (machineCode M)
CSLibExt/Computability/BusyBeaver.lean:764
def DecidesHalting (T : FormalTheory) (n : ℕ) : Prop :=
∀ M : Machine n,
T.Provable (haltsSentence M) ∨ T.Provable (notHaltsSentence M)
CSLibExt/Computability/BusyBeaver.lean:816
TheoremDecidability of halting passes to fewer states#✓fully proved
Let \(T\) be a formal theory such that, for every \(m\) and every Busy Beaver machine \(M\) with \(m\) working states, if \(T\) proves the halting sentence of the embedding of \(M\) into \(m + 1\) states then \(T\) proves the halting sentence of \(M\), and if \(T\) proves the non-halting sentence of the embedding of \(M\) into \(m + 1\) states then \(T\) proves the non-halting sentence of \(M\). Then for every \(n\), if \(T\) decides halting for machines with \(n + 1\) working states, it decides halting for machines with \(n\) working states.
The transport hypotheses are where a real theory would rewrite a proof about the embedded machine into a proof about the original machine; they are stated explicitly because provability of one sentence code does not formally imply provability of another.
theorem decidesHalting_of_succ {T : FormalTheory}
(htransport : ∀ {n : ℕ} (M : Machine n),
(T.Provable (haltsSentence (embedMachine M)) →
T.Provable (haltsSentence M)) ∧
(T.Provable (notHaltsSentence (embedMachine M)) →
T.Provable (notHaltsSentence M)))
{n : ℕ} (h : DecidesHalting T (n + 1)) :
DecidesHalting T n
structure FormalTheory where
/-- Provability of a sentence code in the theory. -/
Provable : ℕ → Prop
CSLibExt/Computability/BusyBeaver.lean:798
abbrev Machine (n : ℕ) :=
Fin n → Fin 2 → Fin 2 × Move × Option (Fin n)
CSLibExt/Computability/BusyBeaver.lean:75
noncomputable def haltsSentence {n : ℕ} (M : Machine n) : ℕ :=
sentenceCode 0 (machineCode M)
CSLibExt/Computability/BusyBeaver.lean:760
def embedMachine {n : ℕ} (M : Machine n) : Machine (n + 1) :=
fun q s =>
if h : q.val < n then
let a := M ⟨q.val, h⟩ s
(a.1, a.2.1, a.2.2.map Fin.castSucc)
else (0, Move.left, none)
CSLibExt/Computability/BusyBeaver.lean:418
noncomputable def notHaltsSentence {n : ℕ} (M : Machine n) : ℕ :=
sentenceCode 1 (machineCode M)
CSLibExt/Computability/BusyBeaver.lean:764
def DecidesHalting (T : FormalTheory) (n : ℕ) : Prop :=
∀ M : Machine n,
T.Provable (haltsSentence M) ∨ T.Provable (notHaltsSentence M)
CSLibExt/Computability/BusyBeaver.lean:816
StructureProof-checker presentation of a ZFC-like theory#✓fully proved
A ZFC-like presentation consists of a formal theory \(T\), given by a provability predicate on sentence codes in \(\mathbb{N}\), together with a Boolean proof checker \(\mathrm{check}(p, s)\) on pairs of natural numbers, such that the following hold. A sentence code \(s\) is provable in \(T\) if and only if \(\mathrm{check}(p, s)\) is true for some \(p \in \mathbb{N}\). \(T\) is sound for halting: for every machine \(M\), if \(T\) proves the halting sentence of \(M\) then \(M\) halts on the blank tape, and if \(T\) proves the non-halting sentence of \(M\) then \(M\) does not halt. For every machine \(M\), if \(M\) has halted within \(t\) steps for some \(t\), then \(T\) proves the halting sentence of \(M\). Write \(S(n)\) for the Busy Beaver shift function, the largest halting time of a halting machine with \(n\) working states, and call the bound sentence for \(n\) and \(B\) the sentence code saying that every halting machine with \(n\) working states halts within \(B\) steps. For every \(n \le 5\), \(T\) proves the bound sentence for \(n\) and \(S(n)\). Whenever \(T\) proves the bound sentence for \(n\) and \(B\), every halting machine with \(n\) working states halts within \(B\) steps. Whenever \(T\) proves the bound sentence for \(n\) and \(B\) and a machine \(M\) with \(n\) working states has not halted within \(B\) steps, \(T\) proves the non-halting sentence of \(M\).
No concrete syntax or proof checker for ZFC is given, and no presentation of ZFC is constructed; the intended instance is ZFC with its standard proof checker. The state counts for consistency-search machines in the literature depend on specific checker implementations and are not asserted for arbitrary presentations.
Cslib.BusyBeaver.ZFCPresentation · 28 lines
structure ZFCPresentation where
/-- The presented theory. -/
theory : FormalTheory
/-- The proof checker: `check p s` says `p` proves sentence `s`. -/
check : ℕ → ℕ → Bool
/-- Provability is existence of a checked proof. -/
provable_iff : ∀ s : ℕ,
theory.Provable s ↔ ∃ p : ℕ, check p s = true
/-- Soundness for halting sentences. -/
soundForHalting : SoundForHalting theory
/-- Finite halting computations are verifiable. -/
verifies_halting : ∀ {n : ℕ} (M : Machine n) (t : ℕ),
HaltsWithin M t → theory.Provable (haltsSentence M)
/-- The computed Busy Beaver bounds through five states are
provable. -/
verifies_bounds : ∀ n ≤ 5,
theory.Provable (boundSentence n (busyBeaverSteps n))
/-- A proved runtime bound applies to the machines it quantifies
over. -/
sound_bounds : ∀ (n B : ℕ),
theory.Provable (boundSentence n B) →
∀ M : Machine n, Halts M → HaltsWithin M B
/-- A proved runtime bound together with a finite non-halting run
yields a proof of the non-halting sentence. This packages finite
run verification and modus ponens inside the theory. -/
notHalts_of_bound : ∀ {n : ℕ} (M : Machine n) (B : ℕ),
theory.Provable (boundSentence n B) → ¬ HaltsWithin M B →
theory.Provable (notHaltsSentence M)
structure FormalTheory where
/-- Provability of a sentence code in the theory. -/
Provable : ℕ → Prop
CSLibExt/Computability/BusyBeaver.lean:798
theory : FormalTheory
CSLibExt/Computability/BusyBeaver.lean:902
check : ℕ → ℕ → Bool
CSLibExt/Computability/BusyBeaver.lean:904
def SoundForHalting (T : FormalTheory) : Prop :=
(∀ {n : ℕ} (M : Machine n), T.Provable (haltsSentence M) → Halts M) ∧
(∀ {n : ℕ} (M : Machine n),
T.Provable (notHaltsSentence M) → ¬ Halts M)
CSLibExt/Computability/BusyBeaver.lean:809
abbrev Machine (n : ℕ) :=
Fin n → Fin 2 → Fin 2 × Move × Option (Fin n)
CSLibExt/Computability/BusyBeaver.lean:75
def HaltsWithin {n : ℕ} (M : Machine n) (t : ℕ) : Prop :=
(run M t).state = none
CSLibExt/Computability/BusyBeaver.lean:141
noncomputable def haltsSentence {n : ℕ} (M : Machine n) : ℕ :=
sentenceCode 0 (machineCode M)
CSLibExt/Computability/BusyBeaver.lean:760
def boundSentence (n B : ℕ) : ℕ :=
sentenceCode 3 (Nat.pair n B)
CSLibExt/Computability/BusyBeaver.lean:773
noncomputable def busyBeaverSteps (n : ℕ) : ℕ :=
(Finset.univ : Finset (Machine n)).sup stepsOf
CSLibExt/Computability/BusyBeaver.lean:349
def Halts {n : ℕ} (M : Machine n) : Prop :=
∃ t, HaltsWithin M t
CSLibExt/Computability/BusyBeaver.lean:145
noncomputable def notHaltsSentence {n : ℕ} (M : Machine n) : ℕ :=
sentenceCode 1 (machineCode M)
CSLibExt/Computability/BusyBeaver.lean:764
Uses 9 · Used by 1
TheoremZFC-like theories decide halting through five states#✓fully proved
For every ZFC-like presentation \(Z\) and every \(n \le 5\), the theory presented by \(Z\) decides halting for \(n\)-state machines: for every \(n\)-state machine it proves the machine's halting sentence or its non-halting sentence.
Proof idea: let \(S\) be Rado's shift function; \(Z\) proves the runtime bound \(S(n)\) for halting \(n\)-state machines. Run each machine for \(S(n)\) steps; if it has halted, the computation verifies, and if it has not, the bound derives its non-halting sentence.
theorem ZFCPresentation.decidesHalting_le_five (Z : ZFCPresentation) :
∀ n ≤ 5, DecidesHalting Z.theory n
structure ZFCPresentation where
/-- The presented theory. -/
theory : FormalTheory
/-- The proof checker: `check p s` says `p` proves sentence `s`. -/
check : ℕ → ℕ → Bool
/-- Provability is existence of a checked proof. -/
provable_iff : ∀ s : ℕ,
theory.Provable s ↔ ∃ p : ℕ, check p s = true
/-- Soundness for halting sentences. -/
soundForHalting : SoundForHalting theory
/-- Finite halting computations are verifiable. -/
verifies_halting : ∀ {n : ℕ} (M : Machine n) (t : ℕ),
⋯
CSLibExt/Computability/BusyBeaver.lean:900
def DecidesHalting (T : FormalTheory) (n : ℕ) : Prop :=
∀ M : Machine n,
T.Provable (haltsSentence M) ∨ T.Provable (notHaltsSentence M)
CSLibExt/Computability/BusyBeaver.lean:816
Uses 9
TheoremThree-state Busy Beaver shift value#●ready to prove
Rado's shift function \(S\) satisfies \(S(3) = 21\): among the two-symbol Busy Beaver machines with \(3\) working states that halt when started on the blank tape, the largest halting time is \(21\).
theorem_wanted busyBeaverSteps_three_wanted :
busyBeaverSteps 3 = 21
noncomputable def busyBeaverSteps (n : ℕ) : ℕ :=
(Finset.univ : Finset (Machine n)).sup stepsOf
CSLibExt/Computability/BusyBeaver.lean:349
Sources
- Lin--Radó (1965), determination of
S(3) = 21.
Uses 1
TheoremThree-state Busy Beaver score value#●ready to prove
Rado's score function \(\Sigma\) satisfies \(\Sigma(3) = 6\): among the two-symbol Busy Beaver machines with \(3\) working states that halt when started on the blank tape, the largest number of ones left on the tape at the halting time is \(6\).
theorem_wanted busyBeaverOnes_three_wanted :
busyBeaverOnes 3 = 6
noncomputable def busyBeaverOnes (n : ℕ) : ℕ :=
(Finset.univ : Finset (Machine n)).sup scoreOf
CSLibExt/Computability/BusyBeaver.lean:354
Sources
- Lin--Radó (1965), determination of
Σ(3) = 6.
Uses 1
TheoremFour-state Busy Beaver shift value#●ready to prove
Rado's shift function \(S\) satisfies \(S(4) = 107\): among the two-symbol Busy Beaver machines with \(4\) working states that halt when started on the blank tape, the largest halting time is \(107\).
theorem_wanted busyBeaverSteps_four_wanted :
busyBeaverSteps 4 = 107
noncomputable def busyBeaverSteps (n : ℕ) : ℕ :=
(Finset.univ : Finset (Machine n)).sup stepsOf
CSLibExt/Computability/BusyBeaver.lean:349
Sources
- Brady (1983), determination of
S(4) = 107.
Uses 1
TheoremFour-state Busy Beaver score value#●ready to prove
Rado's score function \(\Sigma\) satisfies \(\Sigma(4) = 13\): among the two-symbol Busy Beaver machines with \(4\) working states that halt when started on the blank tape, the largest number of ones left on the tape at the halting time is \(13\).
theorem_wanted busyBeaverOnes_four_wanted :
busyBeaverOnes 4 = 13
noncomputable def busyBeaverOnes (n : ℕ) : ℕ :=
(Finset.univ : Finset (Machine n)).sup scoreOf
CSLibExt/Computability/BusyBeaver.lean:354
Sources
- Brady (1983), determination of
Σ(4) = 13.
Uses 1
TheoremFive-state Busy Beaver shift value#●ready to prove
Rado's shift function \(S\) satisfies \(S(5) = 47176870\): among the two-symbol Busy Beaver machines with \(5\) working states that halt when started on the blank tape, the largest halting time is \(47176870\).
theorem_wanted busyBeaverSteps_five_wanted :
busyBeaverSteps 5 = 47176870
noncomputable def busyBeaverSteps (n : ℕ) : ℕ :=
(Finset.univ : Finset (Machine n)).sup stepsOf
CSLibExt/Computability/BusyBeaver.lean:349
Sources
- Busy Beaver Challenge (2025), determination of
S(5) = 47176870.
Uses 1
TheoremFive-state Busy Beaver score value#●ready to prove
Rado's score function \(\Sigma\) satisfies \(\Sigma(5) = 4098\): among the two-symbol Busy Beaver machines with \(5\) working states that halt when started on the blank tape, the largest number of ones left on the tape at the halting time is \(4098\).
theorem_wanted busyBeaverOnes_five_wanted :
busyBeaverOnes 5 = 4098
noncomputable def busyBeaverOnes (n : ℕ) : ℕ :=
(Finset.univ : Finset (Machine n)).sup scoreOf
CSLibExt/Computability/BusyBeaver.lean:354
Sources
- Busy Beaver Challenge (2025), determination of
Σ(5) = 4098.
Uses 1
Loading dependency explorer…
The dependency explorer needs JavaScript and its graph data.