Machines with random access to their input, in logarithmic space #
A query machine (Turing.QueryMachine) reads its input by position: from a state s it asks
for the input bit at position query s, receives it (none past the end of the input), moves to
next (s, b) and emits emit (s, b), until halted s; it then emits finish s. The state is
abstract, so query machines are a convenient way to describe logarithmic-space algorithms that
jump around in their input: counters, tuples of elements, indices into tables.
Such a machine runs within logarithmic space when its states have logarithmic encodings and its
parts are computable within space linear in the encoded state
(Turing.QueryMachine.computableInLogSpace), and more generally within the space of its states,
once that is at least logarithmic (Turing.QueryMachine.computableInSpace). The proof is a
multi-pass fold over the input (Turing.MultiTapeTM.ComputableTidilyInTimeAndSpace.multiPassFold):
each pass simulates one step, scanning the whole input with a binary position counter to fetch the
queried bit, so that only the state, the counter and the fetched bit are ever stored
Sipser, Section 8.4.
Implementation notes #
Christian Reitwiessner's read machines (Turing.ReadMachine) are the same kind of model, simulated
by step machines that move a head one cell at a time. A query machine differs in two ways that
the algorithms built on it need: a read past the end of the input returns none rather than
false, so that a machine can find the end of its input (as a check of the shape of an encoded
input must), and a final word is emitted at the halt. Its logarithmic-space bound is proved
directly from the multi-pass fold.
Main definitions #
Turing.QueryMachine: a machine with random access to its input.Turing.QueryMachine.encStateRead: the encoding of a state with the bit it reads.Turing.QueryMachine.run,Turing.QueryMachine.output: its run and its output.
Main results #
Turing.QueryMachine.computableInSpace: a query machine whose states along its runs have lengthO(S), for a boundSat least logarithmic in the input, and whose parts are computable in linear space, computes a function in spaceO(S).Turing.QueryMachine.computableInLogSpace: a query machine with logarithmic states and parts computable in linear space computes a function in logarithmic space.Turing.QueryMachine.output_add_of_halted: increasing the clock after halting preserves output.
References #
A query machine: from the state s it reads the input bit at position query s (none
past the end of the input), moves to next (s, b) and emits emit (s, b), until halted s; at
the end it emits finish s.
- init : σ
The initial state.
- query : σ → ℕ
The position of the input bit read in a state.
The next state, given the bit read.
The word emitted by a step, given the bit read.
- halted : σ → Bool
Whether the machine has halted.
The word emitted at the end.
Instances For
The encoding of the arguments of next and emit: a state paired with the bit read, which is
none past the end of the input. The state is framed and the optional bit takes at most two
bits, so the encoded length is 2 * (encS s).length + 1 plus at most 2.
Instances For
The input bit read in a state, none past the end of the input.
Instances For
A step on the input w; halted states are fixed.
Instances For
The state after t steps on the input w.
Instances For
The output of a run halted by step t: emissions stop at the first halted state, then the
final word is appended. Once the run has halted, increasing t leaves the output unchanged.
Instances For
Before the first halt, every scheduled step contributes its emission.
The passes of the simulation #
The state of a pass of the simulation: the state of the machine, the position in the input, and the bit fetched so far.
Instances For
Scanning one input bit: count the position, and fetch the bit if it is the queried one.
Instances For
The word emitted at the end of a pass: that of the simulated step.
Instances For
The end of a pass: the simulated step, with the counter and the fetched bit reset.
Instances For
Another pass follows while the machine has not halted.
Instances For
The final word.
Instances For
The parts of the simulation, in linear space #
Logarithmic space #
Query machines run in the space of their states. Let a query machine halt on every encoded
input enc a, first after time a steps, with output encOut (f a). If its states along these
runs have encodings of length O(S a), where S a is at least logarithmic in the length of the
input, and its query, transition, emission, halting test and final word are computable
within space linear in the encoded state, then f is computable within space O(S a). The input
is not charged, so S may be much smaller than the length of the input.
Query machines run in logarithmic space. Let a query machine halt on every encoded input
enc a, first after time a steps, with output encOut (f a). If its states along these runs
have encodings of logarithmic length in the length of the input, and its query, transition,
emission, halting test and final word are computable within space linear in the encoded
state, then f is computable in logarithmic space.