Summing and counting over a range with a stored counter #
Turing.MultiTapeTM.ComputableInSpace.countWith counts the indices i < m a that satisfy a
predicate p (i, a) of a stored index and the input, where p is in the context form of
Turing.MultiTapeTM.ComputableInSpace.loopWith. The registers are the bound, the index and the
count, so the space is that of the bound and of p, plus the logarithm of the length of the
input, for any number of indices. Majority and existence over the range are corollaries.
Main results #
Turing.MultiTapeTM.ComputableInSpace.sumWith: a sum of natural weights when the budget also covers the length of their total.Turing.MultiTapeTM.ComputableInSpace.countWith: the number of indices below a computed bound that satisfy a predicate in context form.Turing.MultiTapeTM.ComputableInSpace.majorityWith: whether more than half of them do.Turing.MultiTapeTM.ComputableInSpace.anyWith: whether one of them does.
Summing with a stored counter. The range bound and each term are computed on the read-only input, with the current binary index available to the term computation. The budget also bounds the encoded total. All terms are natural, so partial sums meet the same bound.
Counting with a stored counter. If the bound m is computable within S, and the
predicate p takes a stored index and the input within the length of the index plus S, then the
number of indices i < m a with p (i, a) is computable within S + log₂ n on inputs of length
n.
Majority over a range. Whether more than half of the indices i < m a satisfy
p (i, a), within S + log₂ n.
Existence over a range. Whether some index i < m a satisfies p (i, a), within
S + log₂ n.