@[extern lean_nat_powmod]
Computes b ^ e % m by square-and-multiply, reducing modulo m at each step so
that no intermediate value exceeds the square of the larger of b and m.
Because Nat.mod satisfies n % 0 = n, powMod b e 0 is b ^ e. That case is
the exception to the bound above: there the intermediates are as large as the
result.
powMod is not definitionally equal to b ^ e % m. Concrete exponents reduce in
O(log e) steps under decide, which b ^ e % m could not, and simp evaluates
closed terms with the Nat.reducePowMod simproc. For symbolic reasoning, rewrite
with powMod_def, which is deliberately not @[simp]: it would turn a cheap
powMod goal into an intractable b ^ e % m one.
Examples: