Streamed sums modulo a computed modulus #
Cslib.Complexity.CountingSimulation.modSum r modulus count c adds the terms r (c, 0), …,
r (c, count c - 1) to an accumulator one at a time, reducing modulo modulus c after each
addition. The terms are visited by the binary-index fold Cslib.GenericRAM.IndexFold, which keeps
only the index, the context c and the accumulator, so the workspace does not grow with the
number of terms.
This is the outer loop of the deterministic counting simulation of #1833: the context is the input
and the clock, the terms are the residues of the contractions of the networks of the movement
schedules, and the modulus is a power of two above the count being recovered
(Nat.foldl_range_add_mod_eq_of_lt).
The resource bound (Cslib.Complexity.CountingSimulation.exists_computableInO_modSum) is a native
multi-tape certificate: if the number of terms and the modulus are computable in polynomial time,
the terms lie below the modulus, and a certificate computes the term at every summed index within
time R c and space Q c, then the streamed sum is computable within time
(count c + 1) * (poly + R c) and space poly + Q c, for a polynomial in the encoded length of the
context. Neither R nor Q needs to be polynomial.
Main definitions #
Cslib.Complexity.CountingSimulation.modSumStep: one round of the streamed sum.Cslib.Complexity.CountingSimulation.modSum: the streamed sum modulo the modulus.
Main results #
Cslib.Complexity.CountingSimulation.modSum_eq_sum_mod: the streamed sum is the sum of the terms modulo the modulus.Cslib.Complexity.CountingSimulation.exists_computableInO_modSum: its time and space bounds.
One round of the streamed sum at index p.1, with context p.2.1 and accumulator p.2.2:
below the number of terms, add the term and reduce modulo the modulus; otherwise leave the state
unchanged.
The state of the streamed sum after j ≤ count c rounds: the index j, the unchanged context
and the residue of the first j terms.
Resource bound of the streamed sum. Suppose the number of terms and the modulus are
computable in polynomial time, the modulus is positive, every summed term lies below it, and a
native certificate computes the terms within time R c and space Q c at the summed indices.
Then the streamed sum is computable within time (count c + 1) * (a * (n + 1) ^ d + R c) and space
a * (n + 1) ^ d + Q c, where n is the encoded length of the context and a, d are constants:
the workspace holds one binary index, the context and an accumulator below the modulus.