- Dr. Alistair Ward
- Exports functions involving integral powers.
- Iteratively generate sequential squares, from the specified initial value,
based on the fact that
(x + 1)^2 = x^2 + 2 * x + 1.
- The initial value doesn't need to be either positive or integral.
(Just . sqrt)if the specified integer is a square number (AKA perfect square).
(square . sqrt)is expensive, so the modulus of the operand is tested first, in an attempt to prove it isn't a perfect square. The set of tests, and the valid moduli within each test, are ordered to maximize the rate of failure-detection.
- Raise an arbitrary number to the specified positive integral power, using modular arithmetic.
- Implements exponentiation as a sequence of either squares or multiplications by the base; http://en.wikipedia.org/wiki/Exponentiation_by_squaring.