Loops that read their input, within space #
Turing.MultiTapeTM.ComputableInSpace does not charge the read-only input, but the loops of
Turing.MultiTapeTM.ComputableInSpace.iterate and
Turing.MultiTapeTM.ComputableInSpace.iterateUntil take a step function of the state alone, so a
round cannot look at the input. The loop of this module can: a round reads the input bit at a
position computed from the state (Turing.MultiTapeTM.queryRound), and the loop runs until a test
on the state holds. It is computable within the space of the start state and of the states it
passes through, plus the logarithm of the length of the input for the position counter of the
underlying query machine (Turing.QueryMachine.computableInSpaceFrom), which the caller no longer
declares.
The rule comes in two forms. queryLoop asks for the number of rounds and a bound on the iterates,
which suits loops with a closed form. queryLoop_of_invariant asks for an invariant of the states
indexed by a variant that decreases in every round, in the style of a total-correctness rule: the
invariant bounds the states and determines the result at the first state where the test holds.
The result is the final state and is charged to the budget, so the rule composes with the other
budget rules of ComputableInSpace and with the space tactic. A budget logarithmic in the length
of the input gives logarithmic space (Turing.MultiTapeTM.ComputableInSpace.computableInLogSpace).
Main definitions #
Turing.MultiTapeTM.queryRound: a round that reads one input bit.
Main results #
Turing.MultiTapeTM.ComputableInSpace.queryLoop: iterating a round that reads the input until a test holds, within the space of the states plus the logarithm of the length of the input.Turing.MultiTapeTM.ComputableInSpace.queryLoop_of_invariant: the same from an invariant with a decreasing variant, which gives termination, the bound on the states and the result.Turing.MultiTapeTM.ComputableInSpace.computableInLogSpace: a logarithmic budget gives logarithmic space.
A budget logarithmic in the length of the encoded input gives logarithmic space: the same machine, without the bound on the length of the value.
Iterating a round that reads the input until a test holds. From the state start a, a
round reads the input bit at the position query s and moves to next, until done. If the
start state is computable within the budget S, the parts of a round within space linear in the
encoded state, and the states of the loop have encodings of length O(S + log n) for inputs of
length n, then the final state is computable within space O(S + log n). The number of rounds
n a, the first at which the test holds, need not be computable, and the input is not charged.
A loop that reads the input, from an invariant with a variant. As
Turing.MultiTapeTM.ComputableInSpace.queryLoop, with the number of rounds and the bound on the
iterates replaced by an invariant Inv a m s of the states s on the input a, indexed by a
variant m: it holds at the start, a round from a state where the test fails keeps it with a
smaller variant, it bounds the encoded state by O(S + log n), and where the test holds it
determines the state as f a. Then f is computable within space O(S + log n).