Integer square root
In number theory, the integer square root (isqrt) of a positive integer n is the positive integer m which is the greatest integer less than or equal to the square root of n,
For example, isqrt(27) = 5 because
and
.
Contents |
[edit] Algorithm
One way of calculating
and isqrt(n) is to use Newton's method to find a solution for the equation x2 − n = 0, giving the recursive formula
The sequence {xk} converges quadratically to
as
. It can be proven that if x0 = n is chosen as the initial guess, one can stop as soon as
- | xk + 1 − xk | < 1
to ensure that 
[edit] Domain of computation
Although
is irrational for almost all n, the sequence {xk} contains only rational terms when x0 is rational. Thus, with this method it is unnecessary to exit the field of rational numbers in order to calculate isqrt(n), a fact which has some theoretical advantages.
[edit] Stopping criterion
One can prove that c = 1 is the largest possible number for which the stopping criterion
ensures
in the algorithm above.
Since actual computer calculations involve roundoff errors, a stopping constant less than 1 should be used, e.g.
[edit] See also
[edit] External links
|
|||||||||||||||||||||||||||||



