Computation of Square Roots
Total Page:16
File Type:pdf, Size:1020Kb
AM1 LLC U11891 1 (at present unknown) method of extracting the square Computing Square Roots 2 root of numbers approximately." "His method for computing square roots was similar to that used by the 1 June 2005 3 Babylonians." One of the Babylonian methods used James A. Crawford was essentially the same as the method known as “Newton’s Method” in more modern times, and we will http://www.am1.us/ examine this technique in Section 4.2. A second method attributed to the Babylonians is known as the “ladder method” and we will examine that method in Section 4.6. 1 Introduction In the first century AD, the Greek 4 Aside from the basic trigonometric and logarithm mathematician Heron of Alexandria also made use of functions, the square-root (SQRT) function is one of Newton’s Method for computing square roots. There the first functions that we encounter in school that can be no question but that the ancient Pythagoreans forces us to deal with irrational numbers. As a student were keenly aware of square roots since of computation, greater insight into mathematics can 2 2 be had by knowing more about what is behind the √x (1) c = a + b function on a $7.99 Casio calculator. This memorandum takes a brief look at methods for in which a,b, and c are the sides of the right-triangle calculating the square root of a positive real value. shown in Figure 1. One of the primary motivations for studying the square root function here is to uncover methods that Figure 1 Basic Right-Triangle Used for can be easily implemented in semi-custom VLSI Pythagorean Theorem circuitry. For simplicity sake, attention within this paper will be limited to base-10 floating-point numbers even though VLSI implementations are normally binary in c nature. Some computational techniques are better b suited to the base-2 number system than others, but we defer such considerations to other texts that deal with this subject in depth. The square root computational methods that will a be examined are: One of the very first electronic computers in the world named the ENIAC used the “sum of odd Sums of odd integers integers” method to compute5 square root as described Continued fractions in Section 3.1. Numbers with a fractional portion were Long-hand division simply pre-multiplied by an even power of 10 in order Newton’s type-1 to circumvent the technique’s limitation to purely Double-step Newton’s type-1 integer values. Newton’s type-2 A brief search of the Internet reveals that many Secant societies like India and China also have a rich history Muir’s of computation regarding the square root function, and Ladder (Theon) interested readers are encouraged to utilize that Taylor series resource to do their own research on this topic. Chebyshev economized series Rational series Cordic Bisection 2 A Touch of History It is always valuable to have some awareness of 2 C. B. Boyer, A History of Mathematics, 1968 history when it comes to long-standing concepts such 3 “Archimedes and the Square Root of 3”, as the square root. http://www.mathpages.com/home/kmath038.htm "It1 would seem that [Archimedes] had some 4 http://www.merriampark.com/bigsqrt.htm 5 1 W.W Rouse Ball, Short Account of The History of http://www4.wittenberg.edu/academics/mathcomp/bjsdi Mathematics, 1908 r/ENIACSquareRoot.htm 1 June 2005 U11891 Computing Sqrt.doc Version 1.0 2005 J.A. Crawford AM1 LLC U11891 2 In the case of A = 2, this formula converges to within 2 3 Interesting Facts 10-9 after 10 iterations. Before we jump into serious computation of the Another simple recursion for the square root SQRT function, it is interesting to look at a few can be found by starting with the identify examples that surprisingly pertain to square roots. 2 (5) (1+ x) = A 3.1 Sums of Odd Integers Upon expanding this out we obtain The sum of the first N odd integers produces a sum equal to N2. On the surface, this is a very surprising result but nevertheless true. The first few (6) x(2 + x) = A −1 cases of If we ªboldlyº assume that we can divide the right-hand N side by (2+x) in order to refine our estimate for x, we 2 (2) ∑(2ii −1) = N obtain the recursion ii=1 A −1 follow as shown below: (7) xi+1 = 2 + xi 1 + 3 = 4 1 + 3 + 5 = 9 and upon repeated application of this recursion, we 1 + 3 + 5 + 7 = 16 can formulate the continued fraction expression given 1 + 3 + 5 + 7 + 9 = 25 by The underlying mathematics responsible for A −1 this result6 is based upon the simple arithmetic series (8) x = A −1 result in which 2 + A −1 2 + N N A −1 (3) a + nd = Na + N +1 d 2 + ∑( ) ( ) A −1 n=1 2 2 + A −1 2 + Selecting a= -1 and d=2 provides the result given by 2 +... (2). Although this result does not directly lend itself to an algorithm for computing non-integer square roots, it with the final result given as √A= 1 + x. is still an intriguing result, and as noted in Section 2, it This ad-hoc recursion is interesting, but the was the basis for computing square roots in the ENIAC heavy reliance upon division makes it fairly unattractive computer. for square root computation because it converges rather slowly as shown in Figure 2 and Figure 3. It is also fun to note that if we had started with 3.2 Continued Fractions a slightly different identity of A second interesting result7 for the square root 2 of a value A is provided by the continued fraction form 1 where √A = 1 + r in which (9) x + = A 2 1 (4) r = 1 A + the appropriate recursion would have been 1 A + 1 1 A + A − A +... 4 (10) xi+1 = 1+ xi and the final root given by √A= x + 0.50. 6 [1], page 30 It is very interesting that this simple continued 7 [2], page 104 fraction method works as well as it does, and it seems 1 June 2005 U11891 Computing Sqrt.doc Version 1.0 2005 J.A. Crawford AM1 LLC U11891 3 plausible that other forms are also possible. 4 Computational Methods for Square Root Figure 2 Convergence of Continued Fraction A wide range of computational methods for SQRT Method (8) Versus A and Number of Iterations 8 are provided in the sections that follow. Non-rigorous Convergence of Continued Fraction Method attention is also provided to the convergence question 1 for each method as well. 0.1 0.01 4.1 Long-Hand Grade School 3 1 .10 Method 4 1 .10 Most of us learned a long-hand method for r computing the square root function at one point or o r 5 r 1 .10 E another in school, but with little or no explanation for 6 why the method worked. The method shares many 1 .10 visual similarities with long-hand division. First we will 7 1 .10 present the method, and then justification will be 8 provided for why this method works. 1 .10 9 1 .10 9 10 4.1.1 Long-Hand SQRT Method 1 .10 0 10 20 30 40 Assume that we wish to compute the square Iteration root of a positive base-10 value represented by A=2 n1n2n3.n4n5n6 where each ni represents an integer A=10 between 0 and 9. For the case where a= 652.341, n2= A=0.10 5 for example. A=5 The long-hand method consists of the following steps: Figure 3 Convergence Range for Continued Fraction Method 8) • Step 1: Group the number in "twos" from the Continued Fraction Method decimal place. (If you have a number with an odd 10 number of digits, the group to the far left will only 1 be a group of 1 digit.) 0.1 • Step 2: Start with the first group of two (the group on the left). This group may be a group of only one 0.01 number if your number has an odd number of digits. 3 1 10 Find the greatest square less than or equal to that 4 1 .10 group of digits and its square root will be your first r . 5 o 1 10 approximation of the entire square root. r r 6 E 1 .10 • Step 3: Subtract the current approximation squared 7 1 .10 and bring down the next group of numbers behind 8 it. This is your next number to work with. 1 .10 9 • Step 4: Double the current approximation of the 1 .10 root. 10 1 10 • Step 5: Find the "ones" digit of the doubled number 11 1 .10 that would result in a number which divides into the 12 1 .10 3 number you are currently working with- with the 1 .10 0.01 0.1 1 10 100 smallest possible remainder. This is the next A 15 Iterations number in your approximation of the square root. 30 Iterations 100 Iterations 8 See Section 3.2 of [6] for additional discussion 9 http://jwilson.coe.uga.edu/EMT668/EMAT6680.F99/Ch allen/squareroot/sqrt.html 1 June 2005 U11891 Computing Sqrt.doc Version 1.0 2005 J.A. Crawford AM1 LLC U11891 4 • Step 6: Multiply the "ones" digit by the doubled 4.1.2 Justification for Long-Hand number plus the "ones" digit. Subtract this number 10 from the number you are currently working with SQRT Method The square root of a number A is the number and bring down the next group of numbers behind 2 it.