Polynomial-time loops over a range of indices #
Many polynomial-time functions are easiest to describe one index at a time: the
encodings of these entries, one after another; the number of indices at which a
test passes; the least such index; the largest of these values. A loop over the
indices 0, 1, …, n - 1 is given by a rule E, which reads pair z (1^i) (the
loop's input z and the index i in unary) and outputs what the loop
contributes at index i. The loops read the count and the input from one string
pair (1^n) z. Counts, indices and values are written in unary, as strings of
trues whose length is the number.
The one construction is concatenation over a range (catRange_mem_FP): if
the rule is polynomial-time, then so is running it on every index below the
count and concatenating the outputs. No bound on the loop's state has to be
supplied, because a polynomial-time rule has polynomially long outputs and the
loop runs at most as often as its argument is long. The rest are corollaries:
the count may be any polynomial-time function of the input
(flatMap_range_mem_FP), and the encoding of a list (listEncFn_mem_FP), a
count (countOver_mem_FP), a bounded search (findFirst_mem_FP), a maximum
(maxFn_mem_FP) and a function given one output bit at a time
(bitwise_mem_FP) are all polynomial-time.
Main results #
catRange_mem_FP— concatenation over a range is polynomial-timeflatMap_range_mem_FP— the same, over a range given by a polynomial-time countlistEncFn_mem_FP,listEncFn_eq_bitstringEncode— writing the encoding of a list from a rule for its entriescountOver_mem_FP,length_countOver— the total output length, in unaryfindFirst_mem_FP,length_findFirst_eq— the least index at which the rule outputs anythingmaxFn_mem_FP,maxFn_eq— the greatest output lengthbitwise_mem_FP— a function given by its length and a rule for each bit
Concatenation #
On pair (1^n) x, concatenation over a range runs the rule on pair x (1^i)
for each i < n.
The length of a concatenation over a range is the sum of the output lengths.
Concatenation over a polynomial-time range. If E and m are
polynomial-time, then so is z ↦ E ⟨z, 1^0⟩ E ⟨z, 1^1⟩ ⋯ E ⟨z, 1^(|m z| - 1)⟩.
Encoding a list #
The list encoder writes the list. If the count is the length of l and
the rule writes the encoding of each entry of l, then the encoder writes the
encoding of l.
Counting #
The count is the sum of the output lengths.
Searching #
The search counts the indices j at which the rule has output nothing on the
indices up to j.
The maximum #
One bit at a time #
A function described bit by bit is polynomial-time. If the output length
is computable in unary and each output bit is computable from the input and the
position in unary, the function itself is in FP.