| Copyright | (c) 2011 Daniel Fischer |
|---|---|
| License | MIT |
| Maintainer | Daniel Fischer <daniel.is.fischer@googlemail.com> |
| Safe Haskell | None |
| Language | Haskell2010 |
Math.NumberTheory.Powers.Cubes
Description
Deprecated: Use Math.NumberTheory.Roots
Description: Deprecated
Functions dealing with cubes. Moderately efficient calculation of integer cube roots and testing for cubeness.
Synopsis
- integerCubeRoot :: Integral a => a -> a
- integerCubeRoot' :: Integral a => a -> a
- exactCubeRoot :: Integral a => a -> Maybe a
- isCube :: Integral a => a -> Bool
- isCube' :: Integral a => a -> Bool
- isPossibleCube :: Integral a => a -> Bool
Documentation
integerCubeRoot :: Integral a => a -> a #
For a given \( n \) calculate its integer cube root \( \lfloor \sqrt[3]{n} \rfloor \). Note that this is not symmetric about 0.
>>>map integerCubeRoot [7, 8, 9][1,2,2]>>>map integerCubeRoot [-7, -8, -9][-2,-2,-3]
integerCubeRoot' :: Integral a => a -> a Source #
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 a #
Calculate the exact integer cube root if it exists,
otherwise return Nothing.
>>>map exactCubeRoot [-9, -8, -7, 7, 8, 9][Nothing,Just (-2),Nothing,Nothing,Just 2,Nothing]
isCube :: Integral a => a -> Bool #
Test whether the argument is a perfect cube.
>>>map isCube [-9, -8, -7, 7, 8, 9][False,True,False,False,True,False]
isCube' :: Integral a => a -> Bool Source #
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 -> Bool Source #
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.