Simultaneous exponentiation by squaring

ID: simultaneous-exponentiation-by-squaring

Several powers with one nonnegative exponent can share a single exponent-halving loop. For bases , maintain accumulators , current bases and a remaining exponent , with loop invariants . For an odd , multiply every accumulator by its current base; square every current base and halve . The equalities are preserved in parallel, and the nonnegative loop variant strictly decreases. For a fixed number of bases this uses arithmetic operations and one loop, while keeping each base in the intended numeric type.

New to topics? Read the docs here!