Professional Documents
Culture Documents
FALLSEM2018-19 - MAT5009 - TH - TT531 - VL2018191004951 - Reference Material I - 09 - Squre Root - GCD
FALLSEM2018-19 - MAT5009 - TH - TT531 - VL2018191004951 - Reference Material I - 09 - Squre Root - GCD
Dr. Arunachalam V
Associate Professor, SENSE
Square Root
• Paper and pencil method
• It decomposes an integer m of the form + , taking two digits of m at a
time, and finding one digit of s for each two digits of m.
• It is based on the following idea.
• If = + is the current decomposition, then taking two more digits of
the argument, we have a decomposition of the form 100 + = 100 +
100 + ′ with 0 ≤ ′ < 100. Since 10 + = 100 + 20 + , a
good approximation to the next digit t can be found by dividing 10r by 2s.
Square Root algorithm
= 9; = 10 = − 1 /4 = 2
= 123 × 10 × + 45 × 10 × + 67 × 10 × + 89 × 10 ×
, ′ ← + ; + = 123 × 10 + 45 = 12345
Since the number has 5 digits, square root must be more than 100
100 = 100 00 , by trail and error method = 111 = 24
, ← × + ,2 ′ ;
× + = 24 × 10 + 67 = 2467; 2 = 222
, ← 2467 , 222 ;
← 247 − 1 × 10 × 222 = 25
= 125; = 45 ( , )←( , )
• The binary algorithm is based on the fact that if a and b are both
odd, then a − b is even, and we can remove a factor of two since
gcd(a, b) is odd.
• Sorenson’s k-ary reduction is a generalization of that idea: given a
and b odd, we try to find small integers u, v such that ua − vb is
divisible by a large power of two.
• Theorem 1.6.1 : If a, b > 0, m > 1 with gcd(a,m) = gcd(b,m) = 1,
there exist u, v, 0 < |u|, v < such that ua = vb mod m.
• Algorithm ReducedRatMod finds such a pair (u, v); it is a simple
variation of the extended Euclidean algorithm; indeed, the ui are
quotients in the continued fraction expansion of c/m.
• Given two integers a, b of say n words, Algorithm ReducedRatMod with
= returns two integers u, v such that vb − ua is a multiple of .
• Since u, v have at most one word each, a' = (vb − ua)/ has at most n − 1
words — plus possibly one bit — therefore with b' = b mod a' we obtain
gcd(a, b) = gcd(a', b'), where both a' and b' have about one word less than
max(a, b).
• This gives an LSB variant of the double-digit (MSB) algorithm.
Extended GCD
2,0 ← 10,5
= 5; =0
= 5; = −1; =3
Reference
1. Chapter 1.6.1 and 1.6.2 of Richard P Brent and Paul Zimmerman,
“Modern Computer Arithmetic”, Cambridge University Press 2010.
Next Class
BASE CONVERSION ALGORITHMS