Turing Machines, Busy Beaver version. #
A variant on the definition of the TM0 model in Mathlib: while the statements the
TM
can make in the usual TM0
are split into two categories (either write at the
current position or move left/right), we want to combine the two to stick to the
BB
convention: first write at the current position and then move left/right.
Note that this Turing Machine model also works with states of type Option Γ
. This
is because in the busy beaver context, the turing machines also have an addition
"halting" state
See also https://git.sr.ht/~vigoux/busybeaver for a different approach to formalising these objects.
A Turing machine "statement" is just a command to write a symbol on the tape (at the current position) and then move left or right
- write :: (
- symbol : Γ
- dir : Dir
- )
Instances For
Equations
- Turing.BusyBeaver.instInhabitedStmt = { default := { symbol := default, dir := default } }
A Post-Turing machine with symbol type Γ
and label type Λ
is a function which, given the current state q : Λ
and
the tape head a : Γ
, either halts (returns none
) or returns
a new state q' : Option Λ
and a Stmt
describing what to do: a
command to write a symbol and move left or right. Notice that there
are two ways of halting at a given (state, head)
pair: either
the machine halts immediatly (i.e. the function returns none
),
or the machine moves to the "halting state", i.e. none : Option Λ
and performs one last action.
Typically, both Λ
and Γ
are required to be inhabited; the default value
for Γ
is the "blank" tape value, and the default value of Λ
is
the initial state.
Equations
- Turing.BusyBeaver.Machine Γ Λ = (Λ → Γ → Option (Option Λ × Turing.BusyBeaver.Stmt Γ))
Instances For
Equations
The configuration state of a Turing machine during operation
consists of a label (machine state), and a tape.
The tape is represented in the form (a, L, R)
, meaning the tape
looks like L.rev ++ [a] ++ R
with the machine currently reading
the a
. The lists are automatically extended with blanks as the
machine moves around.
- q : Option Λ
The current machine state.
- tape : Tape Γ
The current state of the tape: current symbol, left and right parts.
Instances For
Execution semantics of the Turing machine.
Equations
- One or more equations did not get rendered due to their size.
- Turing.BusyBeaver.step M { q := none, tape := tape } = none
Instances For
The statement Reaches M s₁ s₂
means that s₂
is obtained
starting from s₁
after a finite number of steps from s₂
.
Equations
- Turing.BusyBeaver.Reaches M = Relation.ReflTransGen fun (a b : Turing.BusyBeaver.Cfg Γ Λ) => b ∈ Turing.BusyBeaver.step M a
Instances For
The initial configuration.
Equations
- Turing.BusyBeaver.init l = { q := default, tape := Turing.Tape.mk₁ l }
Instances For
Evaluate a Turing machine on initial input to a final state, if it terminates.
Equations
- Turing.BusyBeaver.eval M l = Part.map (fun (c : Turing.BusyBeaver.Cfg Γ Λ) => c.tape.right₀) (Turing.eval (Turing.BusyBeaver.step M) (Turing.BusyBeaver.init l))
Instances For
The predicate that a Turing machine M
has reached a halting state after
n
steps.
For n = 0
this is the predicate that M
has already halted.
In the BB setup, halting state can be attained in two manners:
- The machine can reach a configutation
s
that has no transitions to other states, i.e.step M s = none
- The machine can reach a "halting state configuration"
s
, i.e.s.q = none
.