AUTHOR
- Dr. Alistair Ward
DESCRIPTION
- Exports functions involving integral powers.
- square :: Num n => n -> n
- squaresFrom :: Num n => n -> [(n, n)]
- maybeSquareNumber :: Integral i => i -> Maybe i
- cube :: Num n => n -> n
- cubeRoot :: Double -> Double
- raiseModulo :: (Integral i, Integral power) => i -> power -> i -> i
- isPerfectPower :: Integral i => i -> Bool
Functions
squaresFrom :: Num n => n -> [(n, n)]Source
- 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.
maybeSquareNumber :: Integral i => i -> Maybe iSource
- Returns
(Just . sqrt)
if the specified integer is a square number (AKA perfect square). - http://en.wikipedia.org/wiki/Square_number.
- http://mathworld.wolfram.com/SquareNumber.html.
-
(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.
- http://en.wikipedia.org/wiki/Modular_exponentiation.
Predicates
isPerfectPower :: Integral i => i -> BoolSource
- An integer
(> 1)
which can be expressed as an integral power(> 1)
of a smaller natural number. - CAVEAT: zero and one are normally excluded from this set.
- http://en.wikipedia.org/wiki/Perfect_power.
- http://mathworld.wolfram.com/PerfectPower.html.