arithmoi-0.4.0.3: Efficient basic number-theoretic functions. Primes, powers, integer logarithms.

PortabilityNon-portable (GHC extensions)
StabilityProvisional
MaintainerDaniel Fischer <daniel.is.fischer@googlemail.com>
Safe HaskellSafe-Infered

Math.NumberTheory.Powers.Cubes

Description

Functions dealing with cubes. Moderately efficient calculation of integer cube roots and testing for cubeness.

Synopsis

Documentation

integerCubeRoot :: Integral a => a -> aSource

Calculate the integer cube root of an integer n, that is the largest integer r such that r^3 <= n. Note that this is not symmetric about 0, for example integerCubeRoot (-2) = (-2) while integerCubeRoot 2 = 1.

integerCubeRoot' :: Integral a => a -> aSource

Calculate the integer cube root of a nonnegative integer n, that is, the largest integer r such that r^3 <= n. The precondition n >= 0 is not checked.

exactCubeRoot :: Integral a => a -> Maybe aSource

Returns Nothing if the argument is not a cube, Just r if n == r^3.

isCube :: Integral a => a -> BoolSource

Test whether an integer is a cube.

isCube' :: Integral a => a -> BoolSource

Test whether a nonnegative integer is a cube. Before integerCubeRoot is calculated, a few tests of remainders modulo small primes weed out most non-cubes. For testing many numbers, most of which aren't cubes, this is much faster than let r = cubeRoot n in r*r*r == n. The condition n >= 0 is not checked.

isPossibleCube :: Integral a => a -> BoolSource

Test whether a nonnegative number is possibly a cube. Only about 0.08% of all numbers pass this test. The precondition n >= 0 is not checked.