Unary clocks of linear length from time-constructible bounds #
A time-constructible bound T is computed in binary within O(T n) steps
(Cslib.Complexity.TimeConstructible). Some constructions need a clock in unary instead: a run of
true cells on a work tape that a machine consumes one cell per step. The exact conversion of
T n from binary to unary (Turing.MultiTapeTM.ComputableInO.natToUnary) writes its result on the
output tape; this file prepares a clock on a work tape instead.
Rounding up to a power of two keeps the clock a single doubling counter. The binary word of
T n has Nat.size (T n) digits, and doubling a unary counter once per digit writes
c * 2 ^ Nat.size (T n) cells. The i-th doubling costs O(c * 2 ^ i), so the doublings cost
O(c * 2 ^ Nat.size (T n)) = O(T n + 1) together. The rounded clock lies between
c * (T n + 1) and c * (2 * T n + 1) (Nat.two_pow_size_le).
Cslib.Complexity.TimeConstructible.exists_prepare_unaryClock packages this as one deterministic
machine that writes the clock on its last work tape within O(T n) steps, leaving every other
work tape blank, its input head at the start and nothing emitted. This mirrors the polynomial
budget of MultiTape.Plumbing.PrepareClock.
The same conversion gives any polynomial-time function F of n and T n in unary
(Cslib.Complexity.TimeConstructible.computableInO_unary_of_polyTime), within time
O(n + T n + F (n, T n)): the arithmetic in binary costs O(n + T n) on the values
(Turing.MultiTapeTM.ComputableInPolyTime.natPair_inO), and only the conversion to unary pays for
the size of the result. For example, a quantity quadratic in n + T n, such as the number of moves
of a game played on words of length linear in n + T n, is written in unary within time
O((n + T n + 1) ^ 2).
Main results #
Cslib.Complexity.TimeConstructible.computableInO_unaryClock: the clock word ofc * 2 ^ Nat.size (T n)true bits within time and spaceO(T n).Cslib.Complexity.TimeConstructible.exists_prepare_unaryClock: a unary clock ofc * 2 ^ Nat.size (T n)cells withinO(T n)steps.Cslib.Complexity.TimeConstructible.computableInO_unary_of_polyTime: a polynomial-time function ofnandT n, in unary, within time and spaceO(n + T n + F (n, T n)).
The unary clock word of c * 2 ^ Nat.size (T n) true bits, within time and space
O(T n).
A polynomial-time function of n and T n, in unary. For a time-constructible T and a
function F of two binary naturals computable in polynomial time, F (n, T n) is computed in unary
from any word of length n within time and space O(n + T n + F (n, T n)). The length of the word
and T n are computed in binary within O(n + T n), F costs O(n + T n) on their values
(Turing.MultiTapeTM.ComputableInPolyTime.natPair_inO), and the conversion of the result to unary
(Turing.MultiTapeTM.ComputableInO.natToUnary) costs O(F (n, T n)).
A unary clock of linear length. For a time-constructible T and a constant c, one
deterministic machine with finitely many states writes c * 2 ^ Nat.size (T n) true cells on its
last work tape within C * T n + C steps, on every input of length n. It halts with every other
work tape blank, all heads at their starting cells and nothing emitted. The clock has between
c * (T n + 1) and c * (2 * T n + 1) cells (Nat.lt_size_self, Nat.two_pow_size_le).