Computing square roots
Calculators
Pocket calculatorss typically implement good routines to compute the exponential function and the natural logarithm, and then compute the square root of x using the identity
-
The same identity is exploited when computing square roots with logarithm tables or slide rules.
Babylonian method
A commonly used algorithm for approximating √x is known as the "Babylonian method" and is based on Newton's method. It proceeds as follows:
- start with an arbitrary positive start value r (the closer to the root the better)
- replace r by the average of r and x/r
- go to 2
This is a quadratically convergent algorithm, which means that the number of correct digits of r roughly doubles with each step.
This algorithm works equally well in the p-adic numbers, but cannot be used to identify real square roots with p-adic square roots; it is easy, for example, to construct a sequence of rational numbers by this method which converges to +3 in the reals, but to -3 in the 2-adics.
An exact "long-division like" algorithm
This method, while much slower than the Babylonian method, has the advantage that it is exact: if the given number has a rational square root, then the algorithm terminates and produces the correct square root after finitely many steps. It can thus be used to check whether a given integer is a square number.
Write the number in decimal and divide it into pairs of digits starting from the decimal
point. The numbers are laid out similar to the long division algorithm and the final square root will appear above the original number.
For each iteration:
- Bring down the most significant pair of digits not yet used and append them to any remainder. This is the current value referred to in steps 2 and 3.
- If denotes the part of the result found so far, determine the greatest digit that does not make exceed the current value. Place the new digit on the quotient line.
- Subtract from the current value to form a new remainder.
- If the remainder is zero and there are no more digits to bring down the algorithm has terminated. Otherwise continue with step 1.
Example: What is the square root of 152.2756?
____1__2._3__4_
| 01 52.27 56 1
x 01 1*1=1 1
____ __
00 52 22
2x 00 44 22*2=44 2
_______ ___
08 27 243
24x 07 29 243*3=729 3
_______ ____
98 56 2464
246x 98 56 2464*4=9856 4
_______
00 00 Algorithm terminates: answer is 12.34
Although demonstrated here for base 10 numbers, the procedure works for
any