# IntegerRoots I¶

The IntegerRoots package computes square roots and `n`th roots of integers efficiently.

approxNthRoot: (I, NonNegativeInteger) -> I

`approxRoot(n, r)` returns an approximation `x` to `n^(1/r)` such that `-1 < x - n^(1/r) < 1`

approxSqrt: I -> I

`approxSqrt(n)` returns an approximation `x` to `sqrt(n)` such that `-1 < x - sqrt(n) < 1`. Returns 0 if `n` is negative. A variable precision Newton iteration is used. The running time is `O( log(n)^2 )`.

perfectNthPower?: (I, NonNegativeInteger) -> Boolean

`perfectNthPower?(n, r)` returns `true` if `n` is an `r`th power and `false` otherwise

perfectNthRoot: (I, NonNegativeInteger) -> Union(I, failed)

`perfectNthRoot(n, r)` returns the `r`th root of `n` if `n` is an `r`th power and returns “failed” otherwise

perfectNthRoot: I -> Record(base: I, exponent: NonNegativeInteger)

`perfectNthRoot(n)` returns `[x, r]`, where `n = x\^r` and `r` is the largest integer such that `n` is a perfect `r`th power

perfectSqrt: I -> Union(I, failed)

`perfectSqrt(n)` returns the square root of `n` if `n` is a perfect square and returns “failed” otherwise

perfectSquare?: I -> Boolean

`perfectSquare?(n)` returns `true` if `n` is a perfect square and `false` otherwise