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
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
The statement Reaches M s₁ s₂ means that s₂ is obtained
starting from s₁ after a finite number of steps from s₂.
Equations
- M.Reaches = Relation.ReflTransGen fun (a b : Turing.BusyBeaver.Cfg Γ Λ) => b ∈ M.step a
Instances For
The initial configuration.
Equations
- Turing.BusyBeaver.Machine.init l = { q := some default, tape := Turing.Tape.mk₁ l }
Instances For
Evaluate a Turing machine on initial input to a final state, if it terminates.
Equations
- M.eval l = Part.map (fun (c : Turing.BusyBeaver.Cfg Γ Λ) => c.tape.right₀) (Turing.eval M.step (Turing.BusyBeaver.Machine.init l))
Instances For
M.IsHaltingInput l is the predicate that M is a halting configuration for M.
Equations
- M.IsHaltingInput l = (M.eval l).Dom
Instances For
The predicate that a machine starting at configuration s stops after at most n steps, i.e.
reaches a configuration from which there are no defined transitions.