Applicble Anlysis nd Discrete Mthemtics vilble online t http://pefmth.etf.rs Appl. Anl. Discrete Mth. 4 (2010), 23 31. doi:10.2298/aadm100201012k NUMERICAL ANALYSIS MEETS NUMBER THEORY: USING ROOTFINDING METHODS TO CALCULATE INVERSES MOD p n Michel P. Knpp, Christos Xenophontos We show how clssicl rootfinding methods from numericl nlysis cn be used to clculte inverses of units modulo prime powers. 1. INTRODUCTION In this rticle we explore very interesting ppliction of tools from numericl nlysis to number theory. As the title suggests, we will see how one cn use clssicl rootfinding methods, such s Newton s method, to clculte the reciprocl of n integer modulo p n, where p is prime number. We first encountered this ide in [3], where Newton s method ws used to find the reciprocl of finite segment p-dic number (lso referred to s Hensel code; see [3] for more detils). In our experience, mny people who specilize in either number theory or numericl nlysis do not study the other subject, nd so we hve ttempted to keep our exposition t uniformly low level so tht specilists in either field my benefit from this rticle. We define frctions modulo p n in the usul wy s follows. If, b nd α re integers nd is not divisible by p, then we sy tht α b (mod p n ) if α b (mod p n ). Using this definition, the reciprocl 1 of n integer modulo pn is solution of the congruence x 1 (mod p n ). In other words, it is n inverse of modulo p n. 2000 Mthemtics Subject Clssifiction. 11A07 (65-01). Keywords nd Phrses. Newton s method, inverses modulo p n, secnt method. 23
24 Michel P. Knpp, Christos Xenophontos The ide of using Newton s method to perform division (or clculte inverses) dtes bck to the erly dys of computing, since one cn ctully pproximte the reciprocl of number by performing only the opertions of multipliction nd ddition. The ide behind itertive rootfinding methods such s Newton s method is s follows. Suppose tht we hve function f(x) for which we wish to find zero in n intervl [, b]. To ccomplish this, let x 0 [, b] be n initil guess for the zero, nd let g(x) be n itertion function. Then we clculte further pproximtions through the formul (1) x i+1 = g(x i ), i = 0, 1,... If the initil guess x 0 nd the itertion function g(x) re suitbly chosen, then the sequence x 0, x 1, x 2,... should converge to zero of f(x) in [, b]. If this does in fct occur, then we cn tlk bout the rte t which the sequence converges to zero of f(x). Roughly speking, if the rte of convergence of method is m (i.e. the method converges with order m), then fter ech itertion the number of correct significnt digits in the pproximtion increses by fctor of pproximtely m. For exmple, if our pproximtion converges qudrticlly (i.e. with order 2), then the number of correct significnt digits pproximtely doubles with ech itertion. Now let us see wht this hs to do with congruences modulo p n. In this sitution, the role of significnt digits will be plyed by smller powers of p. We will strt with n inverse of modulo p, nd then find inverses of modulo higher powers of p until we hve n inverse modulo p n. The connection between digits nd powers of p cn be found by looking t the bse p representtion of numbers. It is well-known tht ny positive integer α hs bse p representtion α = c 0 + c 1 p + c 2 p 2 + + c k p k, where 0 c i p 1 for ech i. Ech coefficient c i is digit in the bse p representtion of α. To find number which is congruent to α modulo p r, we cn simply truncte the bse p expnsion of α fter the first r digits. Thus, if r < n then we my think of n inverse of modulo p r s giving the correct first r digits of n inverse of modulo p n. We note here tht our Theorems 1, 3 nd 4 hed re not truly originl. In fct, they re simple consequences of more powerful theorems bout itertive methods. However, we feel tht our proofs re worthwhile becuse they re quite simple nd void ny hevy mchinery. 2. NEWTON S METHOD (FOR DIVISION MOD p n ) The itertion function for Newton s method is g(x) = x f(x)/f (x), whence eqution (1) becomes (2) x i+1 = x i f(x i) f (x i ), i = 0, 1,...
Numericl nlysis meets number theory: using rootfinding... 25 Under suitble ssumptions on f, f nd x 0 (see for exmple Theorem 3.2 on pge 100 of [1]), the bove itertion converges to zero of f(x) in [, b] t qudrtic rte. So to clculte 1, we let f(x) = 1, nd solve f(x) = 0 using Newton s x Method. In this cse itertion (2) becomes (3) x i+1 = x i (2 x i ), i = 0, 1,... Like Newton s method for rel numbers, we cn show tht Newton s method lso converges qudrticlly for congruences. This is proven in the following theorem. Although we re using different lnguge, this is essentilly the sme s the min theorem of [3]. We believe tht our proof is simpler, however. Theorem 1. Let α > 0 nd suppose tht x i is n inverse of modulo p α. Then x i+1 given by (3) is n inverse of modulo p 2α. Proof. To prove this, we know tht x i 1 (mod p α ), nd therefore cn write x i = sp α + 1 for some integer s. Then we hve x i+1 = x i (2 x i ) = s 2 p 2α + 1 1 (mod p 2α ). Hence x i+1 is n inverse of modulo p 2α, s desired. So if we cn find n inverse of modulo p to use s n initil guess, then we cn use Newton s method to find inverses of modulo p 2, p 4, p 8 nd so on. If the prime p is smll, then we cn often find n inverse of modulo p by inspection. If p is lrger, then we cn use Fermt s Little Theorem to find our initil guess. Theorem 2. (Fermt s Little Theorem) Suppose tht p is prime nd tht is n integer not divisible by p. Then p 1 1 (mod p). An esy consequence of this theorem is tht if p does not divide, then p 2 is n inverse of modulo p. We cn evlute p 2 modulo p by the technique of repeted squring. For exmple, to find the inverse of 29 modulo 53, we need to evlute 29 51 modulo 53. To do this, we hve 29 1 29 (mod 53) 29 2 46 (mod 53) 29 4 46 2 49 (mod 53) 29 8 49 2 16 (mod 53) 29 16 16 2 44 (mod 53) 29 32 44 2 28 (mod 53).
26 Michel P. Knpp, Christos Xenophontos Thus we obtin 29 51 = 29 32 29 16 29 2 29 1 (28)(44)(46)(29) 11 (mod 53), nd so 1 11 (mod 53). 29 Let us now illustrte the use of Newton s method in the context of the present pper vi n exmple. Exmple 1. Let p = 5, = 3 nd n = 8. We wish to find n integer congruent to 1 3 modulo 5 8 using the Newton itertion (3). As our initil guess, we choose x 0 = 2 since 3(2) 1 (mod 5) nd so 2 1 3 (mod 5). Then we hve from (3) tht x 1 = 2 (2 3 2) = 8 17 = 2 + 3(5) (mod 5 2 ). Note tht 3(17) = 51 1 (mod 5 2 ), nd so 17 1 3 (mod 52 ) s indicted by Theorem 1. Iterting twice more gives us x 2 417 = 2 + 3(5) + 1(5) 2 + 3(5) 3 (mod 5 4 ) x 3 260417 = 2 + 3(5) + 1(5) 2 + 3(5) 3 + 1(5) 4 + 3(5) 5 + 1(5) 6 + 3(5) 7 (mod 5 8 ), nd so we see tht 260417 1 3 (mod 58 ). 3. THE SECANT METHOD (FOR DIVISION MOD p n ) Another well-known rootfinding method is the secnt method, whose itertion is given by (4) x i+1 = x i f(x i)(x i x i 1 ) f(x i ) f(x i 1 ), i = 1, 2,... Note tht we now need two initil guesses x 0 nd x 1, but we no longer need the derivtive 1 of f(x). Since there is no such thing s free lunch, the trde-off is tht the order of convergence drops down to the golden rtio φ = (1 + 5)/2. In fct, we will show tht fter ech itertion, insted of doubling (like in Newton s method), the number of correct digits increses by fctor of pproximtely φ. For our function f(x) = 1, eqution (4) becomes x (5) x i+1 = x i + x i 1 x i x i 1. To estblish the rte of convergence when using the secnt method for congruences we hve the following theorem. 1 This is importnt when the derivtive of the function f(x) is difficult to obtin; however, this is not the cse here.
Numericl nlysis meets number theory: using rootfinding... 27 Theorem 3. Suppose tht x i 1 1 (mod pα ) nd tht x i 1 (mod pβ ). Then, with x i+1 given by (5), we hve x i+1 1 (mod pα+β ). Proof. To prove this, note tht since we hve x i 1 1 (mod p α ) nd x i 1 (mod p β ), there exist integers s nd t such tht Then we hve s desired. x i 1 = sp α + 1 nd x i = tp β + 1. x i+1 = x i + x i 1 (x i )(x i 1 ) = stp α+β + 1 1 (mod p α+β ), So if x 1 nd x 2 re both inverses of modulo p 1, we cn show by induction tht x i is the inverse of modulo p Fi, where F i is the i th Fiboncci number. Since it is well-known tht F i gets closer nd closer to φ n / 5 s n gets lrge, we find tht the secnt method hs order of convergence φ. Another wy to see this is by introducing the errors ε i+1 = x i+1 1/, ε i = x i 1/, ε i 1 = x i 1 1/. Then (5) gives the reltion (6) ε i+1 = ε i ε i 1. Assuming tht the rte of convergence of the secnt method is r, we hve (7) ε i+1 Aε r i ε i Aε r i 1 ε1/r i A ε i 1, 1/r for some positive constnt A. Thus, by (6) nd (7) we get ε i+1 C 1 A ε1/r 1/r i where B, C re positive constnts. Hence, ε 1+1/r i ε i Bε 1+1/r i, A B εr i, from which it follows tht 1 + 1/r = r, or equivlently tht the order of convergence of the secnt method is given by the positive root of the eqution r 2 r 1 = 0, i.e. r = φ = (1 + 5)/2 1.6. It is worth noticing tht lthough the generl formul (4) for the itertion requires tht our initil guesses x 0 nd x 1 be different, this is not required in either formul (5) or Theorem 3. Thus we cn tke x 0 nd x 1 to both be inverses of modulo p, nd in fct cn even tke them to be the sme number. Let us illustrte the bove ides vi n exmple.
28 Michel P. Knpp, Christos Xenophontos Exmple 2. Let p = 7, = 5 nd n = 8, i.e. we wish to find n integer congruent to 1 5 modulo 7 8 using the itertion (5). We choose x 0 = x 1 = 3, since 5 3 1 (mod 7). We hve from (5) x 2 = 3 + 3 5 3 3 10 = 3 + 1(7) (mod 7 2 ) x 3 = 10 + 3 5 10 3 206 = 3 + 1(7) + 4(7) 2 (mod 7 3 ) x 4 6723 = 3 + 1(7) + 4(7) 2 + 5(7) 3 + 2(7) 4 (mod 7 5 ) x 5 4611841 = = 3 + 1(7) + 4(7) 2 + 5(7) 3 + 2(7) 4 + 1(7) 5 + 4(7) 6 + 5(7) 7 (mod 7 8 ) nd so we see tht 4611841 1 5 (mod 78 ). 4. FIXED POINT ITERATION AND HIGH ORDER CONVERGENT METHODS The generl itertion formul (1) ctully defines lrger clss of itertive methods, clled fixed point methods: insted of solving f(x) = 0 we solve g(x) = x (for suitbly chosen g(x)). The dvntge of this pproch is tht it cn be esily generlized to higher dimensions nd nlyzed using plethor of fmous fixed point theorems. Newton s method is specil cse of fixed point itertion, s cn be redily seen by eqution (2). Under suitble ssumptions on g (see Theorems 3.5 nd 3.7 on pges 121 124 of [1]), itertion (1) converges to α for ny initil guess x 0 sufficiently close to α, t rte r such tht (8) g(α) = α, g (α) = g (α) = g (α) = = g (r 1) (α) = 0 but g (r) (α) 0. With this in mind, one cn construct itertion functions g such tht (8) holds for some r, hence obtining method which converges t tht rte. In our cse, Newton s method cn be written s fixed point itertion with g(x) = x(2 x). Since we ( lredy know tht this is qudrticlly convergent 1 method, we expect tht g = ) 1 ( ) ( ), 1 g = 0, nd g 1 0, nd this is esily seen to be the cse. Now suppose we wnted to construct n itertive method for finding the zero of f(x) = 1, with higher convergence rte. To this end, define u(x) = x f(x)/f (x) nd E 2 (x) = x u(x). Then, Newton s method corresponds to solving Trub [5] derived the following reltion x n+1 = E 2 (x n ), n = 0, 1, 2,... (9) E r+1 (x) = E r (x) u(x) r E r(x), r = 2, 3,...
Numericl nlysis meets number theory: using rootfinding... 29 to produce sequence of generlized itertive formuls, of order r + 1, for solving non-liner equtions, known s Schröder s method of the first kind [4]. In prticulr, if f(x) = 1, then introducing z = 1 x yields x = (1 z)/ x nd u = z(z 1)/, so tht E 2 (x) = x(1 + (1 z)) = 1 z For rbitrry r 2, ssume tht (1 + z) = 1 z2 = 1 (1 x)2. (10) E r (x) = 1 zr Then, pplying (9) we obtin = 1 (1 x)r. E r+1 = 1 zr z(z 1) z r 1 = 1 (1 zr+1 ) = ( 1 1 (1 x) r+1 ). Therefore, we see tht by induction, (10) holds true for rbitrry r 2. As result, n itertive method of order r ( 2) for finding n inverse of modulo prime numbers is given by (11) x i+1 = E r (x i ) x i+1 = 1 ( 1 (1 xi ) r), i = 0, 1, 2,... For exmple, for r = 2 we obtin (3) nd for r = 3 we obtin (12) x i+1 = x i [1 + (1 x i )(2 x i )]. The following exmple illustrtes the use of itertion (12). Exmple 3. As in Exmple 1, let p = 5, = 3 nd n = 8. We wish to find n integer congruent to 1 3 modulo 58 using the itertion (12). We expect tht 2 itertions will suffice here, s opposed to 3 itertions which were needed in Exmple 1, since this method converges cubiclly. Indeed, with x 0 = 2, x 1 = 2 [1 + (1 3 2)(2 3 2)] = 42 42 = 2 + 3(5) + 1(5) 2 (mod 5 3 ) x 2 = 42 [1 + (1 3 42)(2 3 42)] = 651042 651042 (mod 5 9 ). Note tht since 651042 is n inverse of 3 modulo 5 9, it is lso n inverse of 3 modulo 5 8. Noting tht 651042 260417 (mod 5 8 ), we see tht 260417 = 2 + 3(5) + 1(5) 2 + 3(5) 3 + 1(5) 4 + 3(5) 5 + 1(5) 6 + 3(5) 7 is the smllest inverse of 3 modulo 5 8. An ssertion similr to Theorem 1, cn be stted for the generlized method (11): Theorem 4. Let α > 0 nd suppose tht x i is n inverse of modulo p α. Then x i+1 given by (11) is n inverse of modulo p rα.
30 Michel P. Knpp, Christos Xenophontos Proof. As before, we hve x i = sp α + 1, for some integer s. Hence we hve x i+1 = E r (x i ) = 1 (1 x i ) r = 1 (1 sp α 1) r = 1 ( 1) r s r p αr 1 (mod p rα ). Our next exmple illustrtes the use of itertion (11) with r = 4, i.e. (13) x i+1 = 1 ( 1 (1 xi ) 4), nd compres the performnce of ll methods presented in this rticle. Exmple 4. Let p = 2, = 3 nd n = 16. We wish to find n integer congruent to 1 3 modulo 2 16 using itertion (13). As our initil guess we choose x 0 = 1, since 3 1 1 (mod 2). For comprison purposes, we will lso show the nswers obtined using itertions (3), (5) nd (12) for (5) we need second initil guess, nd we tke x 1 = 1. Using itertion (13) we hve x 1 11 = 1 + (2) + (2) 3 (mod 2 4 ) x 2 43691 = 1 + (2) + (2) 3 + (2) 5 + (2) 7 + (2) 9 + (2) 11 + (2) 13 + (2) 15 (mod 2 16 ) nd so we see tht in just two itertions we obtin 43691 1 3 (mod 216 ). For itertion (3) we obtin x 1 3 (mod 2 2 ), x 2 11 (mod 2 4 ), x 3 171 (mod 2 8 ), x 4 43691 (mod 2 16 ), while for itertion (5) we get x 2 3 (mod 2 2 ), x 3 3 (mod 2 3 ), x 4 1 (mod 2 5 ), x 5 171 (mod 2 8 ) x 6 2731 (mod 2 13 ), x 7 699051 (mod 2 21 ), from which we obtin 43691 1 3 (mod 216 ), since 699051 43691 (mod 2 16 ). Finlly, for itertion (12), we hve x 1 2 (mod 2 3 ), x 2 171 (mod 2 9 ), x 3 44739243 (mod 2 27 ), from which we get 43691 1 3 (mod 216 ), since 44739243 43691 (mod 2 16 ). Therefore, we see tht the secnt method, which converges t the rte (1+ 5)/2 1.6, requires 7 itertions, the qudrticlly convergent Newton s method requires 4 itertions, while the cubiclly nd qurticlly convergent itertions (12) nd (13), require 3 nd 2 itertions, respectively. These results demonstrte how the higher order methods cn produce the desired inverse in significntly smller number of itertions. Acknowledgements. We would like to thnk Robert Benedetto nd Lis Oberbroeckling for some very helpful discussions bout the rtes of convergence of p-dic itertive methods.
Numericl nlysis meets number theory: using rootfinding... 31 We lso thnk the nonymous referee whose useful comments gretly improved Section 4. The first uthor ws prtilly supported by NSF grnt DMS-0344082 during the preprtion of this pper. REFERENCES 1. J. Epperson: An Introduction to Numericl Methods nd Anlysis. Wiley nd Sons, 2002. 2. E. V. Krishnmurthy: Economicl itertive nd rnge trnsformtion schemes for division. IEEE Trns. Comput., C-20 (1971), 470 472. 3. E. V. Krishnmurthy, V. K. Murthy: Fst Itertive Division of p-dic Numbers. IEEE Trnsctions on Computers, 32 (1983), 396 398. 4. E. Schröder: Über unendlich viele Algorithmen zur Auflösung der Gleichunger. Mth. Annl., 2 (1870), 317 365. 5. J. F. Trub: Itertive Methods for Solution of Equtions. Prentice Hll, Englewood Cliffs, New Jersey, 1964. Mthemticl Sciences Deprtment, (Received August 2, 2009) Loyol University Mrylnd, (Revised Februry 1, 2010) 4501 N. Chrles Street, Bltimore, MD 21210 USA E-mil: mpknpp@loyol.edu Deprtment of Mthemtics nd Sttistics, University of Cyprus, P.O. Box 20537, 1678 Nicosi Cyprus