„Benutzer:DerSpezialist/Ganzzahlige Quadratwurzel“ – Versionsunterschied
→External links: Removing external link to an article with broken code. None of the "binary integer" square root C code examples actually work. |
|||
Zeile 12: | Zeile 12: | ||
The [[sequence]] <math>\{ x_k \}</math> [[Limit (mathematics)|converges]] [[Rate of convergence|quadratically]] to <math>\sqrt{n}</math> as <math>k\to \infty</math>. It can be proven that if <math>x_{0} = n</math> is chosen as the initial guess, one can stop as soon as |
The [[sequence]] <math>\{ x_k \}</math> [[Limit (mathematics)|converges]] [[Rate of convergence|quadratically]] to <math>\sqrt{n}</math> as <math>k\to \infty</math>. It can be proven that if <math>x_{0} = n</math> is chosen as the initial guess, one can stop as soon as |
||
:<math>| x_{k+1}-x_{k}| < 1</math> |
:<math>| x_{k+1}-x_{k}| < 1</math> |
||
to ensure that <math>\lfloor x_{k+1} \rfloor=\lfloor \sqrt n \rfloor.</math> |
to ensure that <math>\lfloor x_{k+1} \rfloor=\lfloor \sqrt n \rfloor.</math> However, it is usually more efficient to choose a better initial guess for n. |
||
==Domain of computation== |
==Domain of computation== |
Version vom 8. Februar 2012, 08:42 Uhr
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, because and .
Algorithm
One way of calculating and is to use Newton's method to find a solution for the equation , giving the recursive formula
The sequence converges quadratically to as . It can be proven that if is chosen as the initial guess, one can stop as soon as
to ensure that However, it is usually more efficient to choose a better initial guess for n.
Domain of computation
Although is irrational for almost all , the sequence contains only rational terms when is rational. Thus, with this method it is unnecessary to exit the field of rational numbers in order to calculate , a fact which has some theoretical advantages.
Stopping criterion
One can prove that 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.