Deterministic Multi-Tape Turing Machines #
Defines deterministic Turing machines with a read-only input tape, k work tapes and one write-only
output tape.
The tapes contain symbols from Option Symbol for a finite alphabet Symbol (where none is the
blank symbol).
Design #
The multi-tape Turing machine uses a read-only input tape, k work tapes and a write-only output
tape.
The input head can move freely on the input, but any move attempt beyond one cell outside the input
results in no movement.
The transition function can optionally output one symbol, which models the write-only output tape.
Because of these restrictions, we ignore the input and output tapes for space usage of the machine.
The space usage is defined as the total number of cells the work tape heads visited during
execution.
Restricting the movement of the input head is not essential, but useful because it allows us to easily bound the number of possible configurations of a space-bounded machine. Most textbooks have this restriction.
Instead of considering the cells visited by the work tape heads, some textbooks
(including [AB09]) only consider the number of cells that contain
a non-blank symbol at some point in the execution or the number of cells written to. This allows
work tape heads to freely move at no cost as long as they do not write. It is
important to note that this causes DSPACE(1) to include DSPACE(log log n), a class that
contains e.g. the non-regular language {0^n 1^n | n ∈ ℕ} (it is accepted by a TM that writes a
single marker on the work tape and then counts the number of symbols by work tape head movement
without writing).
Defining space usage via "cells visited" thus yields the more fine-grained "complexity world" in
which DSPACE(1) is exactly the class of regular languages.
This definition is adapted from the one in [Pap94], chapter 2.3 including the sub-linear space modifications from chapter 2.5 with the following changes:
- We allow Turing machines to choose to not write on a tape. This is equivalent to writing the read symbol again but makes it easier to reason about the semantics.
- Our tapes are infinite in both directions instead of just to the right. This definition is equivalent (see [AB09], Claim 1.4). It saves us from having to add a "start marker" to the alphabet.
- We only have a single halting state. The different ways to halt (accepting, rejecting, etc) can be distinguished based on the output.
- The way to prevent the input head to move outside the input is enforced by the interpretation and not by a restriction on the transition function. The two definitions are equivalent, but not restricting the transition function makes it easier to define a universal machine.
Important Declarations #
We define a number of structures and concepts related to multi-tape Turing machine computation:
MultiTapeTM: the TM itselfspaceUsed: the number of work tape cells touched by the heads until a certain stepTransitionRelation: the transition relation from one configuration to the nextspaceUsed: the number of tape cells touched by work tape heads, our main space measureComputesInTimeAndSpace: a proof that a specific TM computes an output from an input in a certain number of steps and using a certain number of tape cellsComputesFunInTimeAndSpace: a machine computes a function between specified encodings, respecting time and space bounds on each actual input.ComputableInTimeAndSpace: such a machine exists with binary alphabet and finitely many states.ComputableInTimeAndSpaceOfLength: the specialization to bounds on encoded input length.DecidableInTimeAndSpace: a proof that a TM decides a language within a certain time and space bound.
There are two ways to talk about the behaviour of a multi-tape Turing machine, and they are proven to be equivalent.
MultiTapeTM.runFrom: the configuration reached after a given number of execution stepsRelatesInSteps tm.TransitionRelation cfg cfg' t: a proof thattmtransforms the configurationcfgintocfg'in exactlytsteps
References #
A multi-tape Turing machine with k work tapes over the alphabet of Option Symbol (where none
is the blank tape symbol). Note that it is not required that Symbol or State are finite
to keep the definition more general. The restriction will be introduced once we start talking about
computability by Turing machines in general.
- q₀ : State
initial state
transition function, mapping a state, the current input symbol and a tuple of work head symbols to a movement for the input head, actions on the work tape, optionally a symbol to output and the successor state
Instances For
Stepping a Turing Machine #
This section defines the step function that lets the machine transition from one configuration to
the next, and the configuration reached after a number of steps. Configurations themselves are
defined in Cslib.Computability.Machines.Turing.MultiTape.Configuration.
The step function corresponding to a MultiTapeTM.
Equations
- Turing.MultiTapeTM.step cfg = match cfg.state with | none => cfg | some q => (tm.tr q cfg.inputSymbol cfg.workTapeSymbols).apply cfg
Instances For
The symbol (optionally) output when executing one step starting from configuration cfg.
Equations
- Turing.MultiTapeTM.outputSymbol cfg = match cfg.state with | none => none | some q => (tm.tr q cfg.inputSymbol cfg.workTapeSymbols).output
Instances For
The initial configuration corresponding to an input string.
Equations
- Turing.MultiTapeTM.initCfg input = Turing.Cfg.init tm.q₀ input
Instances For
The configuration reached by running the Turing machine for t steps from cfg.
If the Turing machine halts, it will stay at the halting configuration.
Equations
Instances For
Running a + b steps equals running b steps from the configuration reached after a.
If a function f that maps the configurations of one TM to those of another one commutes with
their step function, then it also commutes with their runFrom function.
Every halted run has a first halting time no later than the supplied one.
The work-tape head moves by at most one cell in a single step.
Now we define space usage and add some helper lemmas.
The set of positions visited by the head of work tape i in the computation starting from
configuration cfg up to step t.
Equations
- Turing.MultiTapeTM.visitedByTapeHead cfg t i = Finset.image (fun (t' : ℕ) => (Turing.MultiTapeTM.runFrom cfg t').workTapePos i) (Finset.range (t + 1))
Instances For
The number of work tape cells touched by the head of tape i in the computation starting from
configuration cfg up to step t.
Equations
- Turing.MultiTapeTM.spaceUsedByTape cfg t i = (Turing.MultiTapeTM.visitedByTapeHead cfg t i).card
Instances For
The number of work tape cells touched by a computation starting from configuration
cfg up to step t.
Equations
- Turing.MultiTapeTM.spaceUsed cfg t = ∑ i : Fin k, Turing.MultiTapeTM.spaceUsedByTape cfg t i
Instances For
Each tape's space usage is bounded by the total space used.
The space used up to step t is the space touched by the configurations up to step t.
The TransitionRelation corresponding to a MultiTapeTM k Symbol
is defined by the step function,
which maps a configuration to its next configuration.
Equations
- Turing.MultiTapeTM.TransitionRelation c₁ c₂ = (Turing.MultiTapeTM.step c₁ = c₂)
Instances For
One step appends the symbol (optionally) emitted by that step to the output tape.
The output does not change after the machine has halted.
A proof that the Turing machine tm on input input outputs output in at most t steps
and uses exactly s space.
Note that this does not require the alphabet or state set to be finite.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A machine computes f between the supplied encodings, with bounds depending on the input.
The machine's alphabet and state type need not be finite.
Equations
- tm.ComputesFunInTimeAndSpace encIn encOut f t s = ∀ (a : α), ∃ t' ≤ t a, ∃ s' ≤ s a, tm.ComputesInTimeAndSpace (encIn a) (encOut (f a)) t' s'
Instances For
A function is computable within the input-indexed bounds by a machine with binary alphabet and finitely many states.
Equations
- One or more equations did not get rendered due to their size.
Instances For
There exists a binary Turing machine with finitely many states that, for every input a,
computes encOut (f a) from encIn a in at most t (encIn a).length steps,
using at most s (encIn a).length work-tape cells.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Resource bounds can be weakened independently on every input.
Computability is monotone in the resource bounds.
This lemma translates between the relational notion and the iterated step notion. The latter can be more convenient especially for deterministic machines as we have here.
The Turing machine tm halts after exactly t steps on input input
if its state is none at step t and non-none at step t - 1.
Note that every Turing machine hast to perform at least one step to halt.
Equations
- One or more equations did not get rendered due to their size.
Instances For
If a Turing machine halts, the time step is uniquely determined.
If a deterministic machine repeats a non-halting configuration, it never halts,
because the sequence between the two configurations will loop forever.
Note that this can be applied to two arbitrary and different time steps t and t + Δ
using tm.runFrom_add.