IntegerRoots I¶
intfact.spad line 201 [edit on github]
The IntegerRoots package computes square roots and nth roots of integers efficiently.
- approxNthRoot: (I, NonNegativeInteger) -> I
approxRoot(n, r)returns an approximationxton^(1/r)such that-1 < x - n^(1/r) < 1
- approxSqrt: I -> I
approxSqrt(n)returns an approximationxtosqrt(n)such that-1 < x - sqrt(n) < 1. Returns 0 ifnis negative. A variable precision Newton iteration is used. The running time isO( log(n)^2 ).
- perfectNthPower?: (I, NonNegativeInteger) -> Boolean
perfectNthPower?(n, r)returnstrueifnis anrth power andfalseotherwise
- perfectNthRoot: (I, NonNegativeInteger) -> Union(I, failed)
perfectNthRoot(n, r)returns therth root ofnifnis anrth power and returns “failed” otherwise
- perfectNthRoot: I -> Record(base: I, exponent: NonNegativeInteger)
perfectNthRoot(n)returns[x, r], wheren = x\^randris the largest integer such thatnis a perfectrth power
- perfectSqrt: I -> Union(I, failed)
perfectSqrt(n)returns the square root ofnifnis a perfect square and returns “failed” otherwise
- perfectSquare?: I -> Boolean
perfectSquare?(n)returnstrueifnis a perfect square andfalseotherwise