Safe Haskell | None |
---|---|
Language | Haskell2010 |
AUTHOR
- Dr. Alistair Ward
DESCRIPTION
- Exports functions related to perfect powers.
- maybeSquareNumber :: Integral i => i -> Maybe i
- isPerfectPower :: Integral i => i -> Bool
Functions
maybeSquareNumber :: Integral i => i -> Maybe i Source #
- Returns
(Just . sqrt)
if the specified integer is a square number (AKA perfect square). - https://en.wikipedia.org/wiki/Square_number.
- http://mathworld.wolfram.com/SquareNumber.html.
(Math.Power.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.
Predicates
isPerfectPower :: Integral i => i -> Bool Source #
- 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.
- https://en.wikipedia.org/wiki/Perfect_power.
- http://mathworld.wolfram.com/PerfectPower.html.
- A generalisation of the concept of perfect squares, in which only the exponent '2' is significant.