IntegerRoots I¶
intfact.spad line 201 [edit on github]
The IntegerRoots package computes square roots and n
th roots of integers efficiently.
- approxNthRoot: (I, NonNegativeInteger) -> I
approxRoot(n, r)
returns an approximationx
ton^(1/r)
such that-1 < x - n^(1/r) < 1
- approxSqrt: I -> I
approxSqrt(n)
returns an approximationx
tosqrt(n)
such that-1 < x - sqrt(n) < 1
. Returns 0 ifn
is negative. A variable precision Newton iteration is used. The running time isO( log(n)^2 )
.
- perfectNthPower?: (I, NonNegativeInteger) -> Boolean
perfectNthPower?(n, r)
returnstrue
ifn
is anr
th power andfalse
otherwise
- perfectNthRoot: (I, NonNegativeInteger) -> Union(I, failed)
perfectNthRoot(n, r)
returns ther
th root ofn
ifn
is anr
th power and returns “failed” otherwise
- perfectNthRoot: I -> Record(base: I, exponent: NonNegativeInteger)
perfectNthRoot(n)
returns[x, r]
, wheren = x\^r
andr
is the largest integer such thatn
is a perfectr
th power
- perfectSqrt: I -> Union(I, failed)
perfectSqrt(n)
returns the square root ofn
ifn
is a perfect square and returns “failed” otherwise
- perfectSquare?: I -> Boolean
perfectSquare?(n)
returnstrue
ifn
is a perfect square andfalse
otherwise