Same-level unary modular collection, sums and products #
unaryModularList collects polynomially many binary oracle values in order, reducing each
before appending it. The loop invariant bounds the index, list length and every stored entry
under every supported reply of an arbitrary stateful handler. unaryModularList_mem therefore
retains one fixed counting oracle at the original level.
unaryModularSum and unaryModularProduct reuse this list and the certified binary arithmetic
programs. The reduced list and its sum and product have polynomial encoded lengths because the
count is unary and the modulus is binary. At modulus zero the evaluators give the ordinary
natural sum and product.
Adapted from LeanCanny.CountingHierarchy.UnaryModularList and
UnaryModularAggregation at lean-canny commit 970f28a5ecefc1327402ade16c068aa4b1b2c183.
A plain polynomial-time callback yields a polynomial-time modular list. No positive-modulus hypothesis is needed: at modulus zero its values are unchanged.
All stateful handlers obey the storage bound, because each returned oracle value is reduced before it is appended to the output list.
Reducing the summands before adding gives the actual sum modulo p, including p = 0.
At unary arity, a plain polynomial-time summand gives a plain polynomial-time modular sum.
Polynomially many modular summands use one fixed oracle at the original function level. The unary count bounds the collected list; no exponential index enumeration is used.
The total sum evaluator casts to the actual finite sum, for every modulus.
At positive modulus, a unary number of factors uses one fixed oracle at the original function level. The intermediate product has at most the sum of the binary factor lengths.
The evaluator casts to the actual finite product at every modulus.