P-adic Reconstruction Paul S. Wang* Kent State University Department of Mathematical Sciences Kent Ohio U.S.A. 44242 of Rational Numbers M.J.T. Guy University of Cambridge Computer Laboratory Corn Exchange Street Cambridge, England CB2 3QG J.H. Davenport Emmanuel College Cambridge England CB2 3AP I. Introduction clearly satisfies In a recent paper, Wang [1981] introduces a p-adic algorithm for the construction of partial fraction decompositions. This differs from the usual p-adic algorithms for factorisation or the computation of greatest common divisors ([Wang, 1978], [Wang, 1980], [Moore & Norman, 1981]) in that the p-adic image is used to reconstruct rational numbers, rather than integers. In order to generate these rational numbers, Wang [1981] gives an algorithm RATCONVERT (p. 216) to deduce the rational u/v such that uv -I = c (mod m), with luJ, IvI < J(m/2). In this paper we prove that RATCONVERT always reconstructs such a number, if it exists. As Wang points out, the representation, if it exists, is unique. Such a number need not exist: e.g. modulo 9 we have that 0/I = 0/2 = O, I/I = 2/2 = I, 2/I = 2, I/2 = 5, -I/I = -2/2 = 8, -2/I = 7, -I/2 = 4, leaving 3 and 6 without any such representation. v3/v2 5. c (mod m). We have to prove that any solution to a/b = c satisfying the size constraint la~, Ibl < ./(m/2) will be generated by this algorithm. 3. Continued Fractions. The algorithm can be viewed another way: as the calculation of approximations to c/m, since -Vl/V 2 = c/m - v3/(mv2). The numbers q computed in step [3] are, in fact, the successive terms in the continued fraction approximation to c/m (see [Hardy & Wright, 1979] Theorem 161 or Knuth [1981] pp. 339-343): I C m ql + 1 q2 + I 2. The Algorithm q3 Wang's algorithm slightly) : is (we adapt the + "'" " notation After one iteration of step [33, we have u I : O, u 2 : I and -Ul/U 2 is the first approximation (0) to [I] u:= (I, O, m), v:: (0, I, c) c/m, and second [2] While J(m/2) ~ v 3 do approximation Algorithm [3] {q:: RATCONVERT(c ,m) Lu3/v3], [4] If ~v21 ~ J(m/2) [5] Return r:: u-qv, u:: v, v:: v I = I, v 2 = q1' and -Vl/V 2 is the (I/qi) to c/re. The definition of v I, v 2 in terms of the previous values of Ul, u2, Vl, v 2 and r} q is then error() then (after convention) (v3,v 2) allowing just Pn+1 = qPn+Pn-1 for the for computing our different standard sign iteration a convergent in terms [Wang ensures that v 2 is positive, but we do not need this complication] of its two immediate predecessors. Hence we have that Throughout hold: convergents the the iteration, the following equations ulm + u2c : u 3, vlm + v2c = v 3. If the algorithm terminates with a solution, then it sequence of -Vl/V 2 is the sequence of to c/m. Conversely, suppose that a/b = c (mod m), with lal, Ibl < J(m/2). Then a+dm = bc for some integer d, so that d _ C _ b a _ = _ - m bm. Hence d/b is an approximation lal, Ib~ < J(m/2), the error is I al I--I_< Ibml J(m/2) 1 ...... We can now a p p e a l 184 (p. 153): I f is is Running <--2bY(m/2) - Hardy & W r i g h t IP I--xl Iq then p/q (d, b, a) 1 _< bm to to c/m, and, since I I 2b 2 . [1979] Theorem Time 1 a convergent [to indeed generated and 2q 2 Czechoslovak x ] . Hence t h e t r i p l e by t h e a l g o r i t h m , and The users of with Option Academy Astronomical acquainted a Kalina of S c i e n c e s Institute 6, B u d e c s k a , so the algorithm is guaranteed to find a rational in the appropriate range which corresponds to c mod m, if such a value exists. Lisp/360 under Sharing Zden~k <--- - REDUCE interactively 120 23 P r a g u e algebraic many systems advantages of are using 4. References diaglog versions We Hardy & Wright,1979 Hardy, G.H. & Wright,E.M., An Introduction to the Theory of Numbers (5th. ed.). Clarendon Press, Oxford, 1979. Knuth,198 la Knuth,D.E., The Art of Computer Programming, Vol. II, Semi-numerical Algorithms. Second Edition, Addison-Wesley, 1981. Moore & Norman,1981 Moore,P.M.A. & Norman,A.C., Implementing a Polynomial Factorization and GCD Package. Proceedings of the 1 9 8 1 ACM Symposium on Symbolic and Algebraic Computation, ACM Inc., New York, 1981, pp. 109-116. Wang, 1978 Wang,P.S., An Improved Multivariable Polynomial Factorising Algorithm. Math. Comp. 32(1978) pp. 1215-1231. Zbl. 388.10035. REDUCE Time Wang, 1981 Wang,P.S., A p-adic Algorithm for Univariate Partial Fractions. Proceedings of the 1981 ACM Symposium on Symbolic and Algebraic Computation, ACM Inc., New York, 1981, pp. 212217. * R e s e a r c h s u p p o r t e d in p a r t by g r a n t s f r o m the N a t i o n a l S c i e n c e F o u n d a t i o n ( N S F - M C S 8 0 - 0 2 4 1 4 ) and the D e p a r t m e n t of E n e r g y (DE A S O 2 E R 7 6 0 2 0 7 5 - A 0 1 0 ) . in use Sharing Therefore, to m a k e version The made Symbolic Lisp and who detailed a computing to a d o p t use of a more widely a n d we Conversational System algebraic the /COSYMS/. so called system initial of the Lisp REDUCE. and re- interpreter. a special Command section. REDUCE interactive Those more I/O our the on L i s p / 3 6 0 , activations a new in system and REDUCE. controls involved Hearn decided taken a n d the Monitor peated we oriented is b a s e d algebraic system Manipulation Monitor, The of systems. C. possible aim was a user COSYMS the A. Option centre. dialog these of Professor Lisp/360 with Wang, 1980 Wang,P.S., The EEZ-GCD Algorithm. SIGSAM Bulletin 14(1980) 2 pp. 50-60. Zbl. 445.68026. have of Analyser is generated options. are interested information from may the obtain author.