Jump to content

Integer square root

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by MathMartin (talk | contribs) at 16:41, 28 December 2004 (+Category:Algorithms). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

In mathematics and 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,

Algorithm

To calculate , and in particular, isqrt(n), one can use Newton's method for the equation which gives us the recursive formula

One can choose for example as initial guess.

The sequence converges quadratically to as It can be proved (the proof is not trivial) that one can stop as soon as

< 1

to ensure that

Domain of computation

Let us note that even if is irrational for most n, the sequence contains only rational terms. Thus, with Newton's method one never needs to exit the field of rational numbers in order to calculate isqrt(n), a fact which has some theoretical advantages in number theory.

Stopping criterium

One can prove that is the largest possible number for which the stopping criterium

< c

ensures in the algorithm above.

Since actual computer calculations involve roundoff errors, one needs to use c < 1 in the stopping criterium, e.g.,

< 0.5.

See also