Polynomial-time modular exponentiation #
Square-and-multiply computes a ^ e % m on binary naturals with a positive modulus. It folds over
the exponent's binary digits from the most significant one, squaring the accumulator and
multiplying by a at each 1 digit, reducing modulo m after every product. Every intermediate
value is below m, so the work is polynomial in the lengths of a, e and m.
Without a modulus, a ^ e has about e times as many digits as a, exponentially many in the
length of e; the statement therefore requires a positive modulus. The total function powMod
returns 1 at the modulus 0 instead, so it is polynomial-time on every input. This is where it
differs from core's Nat.powMod, which returns the unreduced power at the modulus 0. Powers
compose (Turing.MultiTapeTM.powMod_powMod), and powers of a unit are units
(Turing.MultiTapeTM.coprime_powMod).
Main definitions #
Turing.MultiTapeTM.powMod: modular exponentiation, returning1at the modulus0.
Main results #
Turing.MultiTapeTM.ComputableInPolyTime.binary_powMod: modular exponentiation of computed binary values with a positive modulus.Turing.MultiTapeTM.computableInPolyTime_powMod:powModof computed binary values, with no condition on the modulus.
References #
Modular exponentiation of computed binary values with a positive modulus, by square-and-multiply.
Total modular exponentiation #
Modular exponentiation x ^ e mod M. For the degenerate modulus M = 0 it returns 1
instead of the unreduced power, so that it is computable in polynomial time on every input.
powMod is computable in polynomial time.