Binary natural powers with a runtime exponent #
The base and exponent are binary naturals. Repeated multiplication keeps the immutable base and one accumulator; the iteration counter is binary. The space bound charges the possible output length, proportional to the exponent times the binary length of the base, and the binary length of the exponent. No unary charge for the base is introduced.
Main results #
Turing.MultiTapeTM.ComputableInSpace.natPow: power with both arguments supplied at runtime.Turing.MultiTapeTM.ComputableInSpace.budget_natPow_variable: compute a power within a caller's budget that covers this output-length bound.
A runtime exponent is evaluated by repeated multiplication within the possible output length plus the binary counter length. The bound is valid also at base or exponent zero.
A power with a computed exponent stays within a budget covering both arguments and the
possible output length. Unlike budget_natPow, the exponent here is an input-dependent value.
Powers of a fixed base fit in any workspace budget that covers the exponent's value.
A binary power of two fits in any budget that bounds the value of its exponent.