Archive for February, 2008

360 ARITHMETIC 45.3 L4. Output A (which is

Monday, February 18th, 2008

360 ARITHMETIC 45.3 L4. Output A (which is the value of the next partial quotient). Replace the co- efficients (an, a,-~, . . . , ac) by (–a~, -al,. . , -a,) and return to Ll. (This step replaces f(z) by a polynomial whose roots are reciprocals of those of f.) For example, starting with f(s) = x3 -2, the algorithm will output 1 (changing f(z) to x3 -3s -33: - 1); then 3 (changing f(z) to 10~~ -62 -62 -1); etc. 14. [A&!.%!] (A. Hurwitz, 1891.) Show that the following rules make it possible to find the regular continued fraction expansion of 2X, given the partial quotients of X: 2/2a, b, c, . . . / = /a, 2b + 2/c,. . . //; 2/ 2a + 1, b, c, . . . / = /a, 1,l + 2/b -1, c, . . . //. Use this idea to find the regular continued fraction expansion of ie, given the expansion of e in (13). b 15. [?&?I] (R. W. Gosper.) Generalizing exercise 14, design an algorithm that com- putes the continued fraction Xc + /XI, X2, . . . / for (az + b)/(cz + d), given the con- tinued fraction xc +/XI, x2, . . . / f or x, and given integers a, b, c, d with ad # bc. Make your algorithm an on-line coroutine that outputs as many Xk as possible before in- putting each x3. Demonstrate how your algorithm computes (9 7% + 39)/(-62x -25) when 5 = -1 + /5,1,1,1,2,1,2/. 16. [HMs0] (L. Euler, 1731.) Let fc(z) = (e* -e-*)/(eZ + e- ) = tanhz, and let fn+r(z) = l/fn(z) -(2n + 1)/z. Prove that, for all n, fn(z) is an analytic function of the complex variable z in a neighborhood of the origin, and it satisfies the differential equation f;(z) = 1 -fn(z)2 -2nf,(z)/z. Use this fact to prove that tanh z = /z-l, 32-l) 52-l, 7z- , . . . /. Then apply Hurwitz s rule (exercise 14) to prove that e–lln = / 1, (2m + 1)n -1, I/, m 2 0. (This notation denotes the infinite continued fraction / 1, n -1, 1, 1, 3n -1, 1, 1, 5n -1, 1, . /.) Also find the regular continued fraction expansion of e- fn when n > 0 is odd. b 17. [M.%?s] (a) Prove that /XI, -x2/ = /ZI -1,1,x2 -l/. (b) Generalize this identity, obtaining a formula for /XI, -x2, 23, -x4,. . . , x2,+1, -xzn/ in which all partial quotients are positive integers when the x s are large positive integers. (c) The result of exercise 16 implies that tan 1 = /l, -3,5, -7,. . . /. Find the regular continued fraction expansion of tan 1. 18. [M40] Develop a computer program to find as many partial quotients of x as possible, when x is a real number given with high precision. Use your program to calculate the first one thousand or so partial quotients of Euler s constant 7, based on D. W. Sweeney s 3566-place value [Math. Comp. 17 (1963), 170-1781. (According to the theory in the text, we expect to get about 0.97 partial quotients per decimal digit. Cf. Algorithm 4.5.2L and the article by J. W. Wrench, Jr. and D. Shanks, Math. Comp. 20 (1966), 444-447.) 19. [MZ?O] Prove that F(x) = log,(l + x) satisfies Eq. (24). 20. [HiVZ O] Derive (36) from (35).

4.5.3 ANALYSIS OF EUCLID S (Web site construction) ALGORITHM 359 11. [A&?01

Sunday, February 17th, 2008

4.5.3 ANALYSIS OF EUCLID S ALGORITHM 359 11. [A&?01 (J. Lagrange.) Let X = .& + /Al,Az, . . . /, Y = BCJ + /&?I, &, . . . / be the regular continued fraction representations of two real numbers X and Y, in the sense of exercise 10. Show that these representations Iln the sense that &+k = &+k for some m and n and for all y if we have X = (qY + r)/(sY + t) for some integers q, r, s, t with(qt -rsl = 1. (This theorem is the analog, for continued fraction representations, of the simple result that X and Y in the decimal system eventually agree if and only if for some integers q, r, and s.) b 12. [A&o] A quadratic irrationality is a number of the form (a -U)/V, where D, U, and V are integers, D > 0, V # 0, and D is not a perfect square. We may assume without loss of generality that V is a divisor of D -U2, for otherwise the number may be rewritten as (m -UlVl)/VlVl. a) Prove that the regular continued fraction expansion (in the sense of exercise 10) of a quadratic irrationality X = (a -U)/V is obtained by the following formulas: v-0 = v, A0 = 1×1, iY0 = u+Aov; &+I = (D -U, )/K, An+1 = 1@+ Un)/Vn+1J, U n+1–An+lK+l -Un. [Note: An algorithm based on this process has many applications to the solution of quadratic equations in integers; see, for example, H. Davenport, The Higher Arithmetic (London: Hutchinson, 1952); W. J. LeVeque, Topics in Number Theory (Reading, Mass.: Addison-Wesley, 1956); and see also Section 4.5.4. By exercise 1.2.4-35, we have An+1 = 1(1×6] + U,)/V,+lJ when K+I > 0, and A,+1 = l(lfij + 1+ &)/K+lJ when V n+l < 0; hence such an algorithm need only work with the positive integer [fi].] b) Prove that 0 < U, < ~6, 0 < V,, < 2fi, f or all n > N, where N is some in- teger depending on X; hence the regular continued fraction representation of every quadratic irrationality is eventually periodic. [Hint: Show that (—a -U)/V = &+/A,…, A, -Vn/(fi+UJ, and use Eq. (5) to prove that (a+ Un)/Vn is positive when n is large.] c) Letting p, = Qn+l(Ao, AI,. . . , An) and qn = Qn(A1,. . . ,An), prove the identity VP: + 2Upnqn + ((U -D)/V)q: = (-l) +lK+~. d) Prove that the regular continued fraction representation of an irrational number X is eventually periodic if and only if X is a quadratic irrationality. (This is the continued fraction analog of the fact that the decimal expansion of a real number X is eventually periodic if and only if X is rational.) 13. [M40] (J. Lagrange, 1797.) Let f(z) = u~z +…+uo, a, > 0, be a polynomial with integer coefficients, having no rational roots, and having exactly one real root 6 > 1. Design a computer program to find the first thousand or so partial quotients of [, using the following algorithm (which essentially involves only addition): Ll. Set A c 1. L2. For k = 0, 1, . . . , n -1 (in this prder) and for j = n -1, . . . , Ic (in this order), set aj +- uj+l + aj. (This step replaces f(s) by g(s) = f(z + l), a polynomial whose roots are one less than those of f.) L3. If a, + a,-1 + . . . + uo < 0, set A c A + 1 and return to L2.

358 ARITHMETIC 4.5.3 2. [M.8] Evaluate the matrix (Affordable web hosting)

Saturday, February 16th, 2008

358 ARITHMETIC 4.5.3 2. [M.8] Evaluate the matrix product 3. [A&Y] What is the value of 4. [A420] Prove Eq. (8). 5. [HM25] Let xi, x2, . . . be a sequence of real numbers that are each greater than some positive real number E. Prove that the infinite continued fraction /xl, 22,. . . / = lim,,, /xl,. . . , xn/ exists. Show also that 1×1, x2,. . . / need not exist if we assume only that x3 > 0 for all j. 6. [MZS ] Prove that the regular continued fraction expansion of a number is unique in the following sense: If Bi, B2, . . . are positive integers, then the infinite continued fraction /BI, B2, . . . / is an irrational number X between 0 and 1 whose regular con- tinued fraction has A, = B, for all n 2 1; and if BI, . . . , B, are positive integers with B, > 1, then the regular continued fraction for X = /B1,. . . , Bm/ has A, = B, for 1 5 n 2 m. 7. [M96] Find all permutations p(l)p(2). . . p(n) of the integers {1,2,. . . , n} such that Qn(xl, x2,. . , xn) = Qn(xp(l), zp(2), . , x~(~)) holds for all XI, x2, . . . , xn. 8. [.W?O] Show that -l/Xn = /An,. . . , AI, -Xl, whenever X, is defined, in the regular continued fraction process. 9. [MZZ] Show that continued fractions satisfy the following identities: a) /xl,. . . , xn/ = /xl,. . . ,Xk + /Xk+l,. . . , ?A//, l

Cedant web hosting - 4.5.3 ANALYSIS OF EUCLID S ALGORITHM 357 (1975), 20-281,

Friday, February 15th, 2008

4.5.3 ANALYSIS OF EUCLID S ALGORITHM 357 (1975), 20-281, who established that 7, = y Inn + C + O(n-1/6+e), see D. E. Knuth, Computers and Math. with Appiic. 2 (1976), 137-139. Thus the conjecture (48) is fully proved. The average running time for Euclid s algorithm on multiple-precision in- tegers, using classical algorithms for arithmetic, was shown to be of order (I+ log(m=4u, v)lgcd(u, 4)) 1% mink v> by G. E. Collins, in SIAM J. Computing 3 (1974), l-10. Summary. We have found that the worst case of Euclid s algorithm occurs when its inputs u and v are consecutive Fibonacci numbers (Theorem F); the number of division steps when v = n will never exceed r4.8 log,o N -0.321. We have determined the frequency of the values of various partial quotients, showing, for example, that the division step finds [u/v] = 1 about 41 percent of the time (Theorem E). And, finally, the theorems of Heilbronn and Porter prove that the average number T, of division steps when v = n is approximately ((12 In 2)/r ) In n z 1.9405 log,, n, minus a correction term based on the divisors of n as shown in Eq. (53). EXERCISES b 1. [20] Since the quotient [v/vJ is equal to unity over 40 percent of the time in Algorithm 4.5.2A, it may be advantageous on some computers to make a test for this case and to avoid the division when the quotient is unity. Is the following MIX program for Euclid s algorithm more efficient than Program 4.5.2A? LDX u rX+-u. JMP 2F 1H STX V v c rX. SUB v rAtu-vu. CMPA V SFtAx 5 rAX + rA. JL 2F Is u-v < v? DIV V rX c rAXmodv. 2H LDA V rA+v. mz IB Done if rX = 0. m

356 ARITHMETIC 4.5.3 For example, M (0.843)(4.605 -0.347 (Hosting web)

Friday, February 15th, 2008

356 ARITHMETIC 4.5.3 For example, M (0.843)(4.605 -0.347 -0.173 -0.322 -0.064) + 1.47 Fz 4.59; the exact value of TIOOis 4.56. We can also estimate the average number of division steps when u and v are both uniformly distributed between 1 and N, by calculating (55) Assuming formula (53), exercise 27 shows that this sum has the form 7 In N + O(l), and empirical calculations with the same numbers used to derive Eq. 4.5.2-45 show good agreement with the formula 12ln2 ~ In N + 0.06. (57) 79 Of course we have not yet proved anything about T, and r, in general; so far we have only been considering plausible reasons why the above formulas ought to hold. Fortunately it is now possible to supply rigorous proofs, based on a careful analysis by several mathematicians. The leading coefficient (12 In 2)/ 7r2 in the above formulas was established first, in independent studies by John D. Dixon and Hans A. Heilbronn. Dixon [J. Number Theory 2 (1970), 414-4221 developed the theory of the F,(z) dis- tributions to show that individual partial quotients are essentially independent of each other in an appropriate sense, and proved that for all positive E we have IT(m, n) - ((12 In 2)/.rr2) lnnl < (lnn)(1/2)f except for exp(-c(c)(log N)E/2)N2 values of m and n in the range 1 5 m < 12 5 N, where C(E) > 0. Heilbronn s approach was completely different, working entirely with integers instead of con- tinuous variables. His idea, which is presented in slightly modified form in exer- cises 33 and 34, is based on the fact that r, can be related to the number of ways to represent n in a certain manner. Furthermore, his paper [Number Theory and Analysis, ed. by Paul Tur6n (New York: Plenum, 1969), 87-961 shows that the distribution of individual partial quotients 1, 2, . . . that we have discussed above actually applies to the entire collection of partial quotients belonging to the frac- tions having a given denominator; this is a sharper form of Theorem E. A still sharper result was obtained several years later by J. W. Porter [Mathematika 22

4.5.3 ANALYSIS OF EUCLID S ALGORITHM (Web hosting faq) 355 where in(z)

Thursday, February 14th, 2008

4.5.3 ANALYSIS OF EUCLID S ALGORITHM 355 where in(z) is defined in (31). Now fn(x)= & + own), (51) using the facts we have derived earlier (see exercise 23); hence the average value of lnX, is very well approximated by 1 lnx O ueAu -dx=-2-du In s0 1+x In2 s0 l+e-U = -A c (-l) +l lW uemkU du k>l =-A lAff-L.+& -… ( =-A 1+;+;+…-2 ;+I-+$+ . . . ( ( >> =- & 1+;+;+*– ( > = -7r2/(12 In 2). By (49) we therefore expect to have the approximate formula –t7r2/(121n2) z -1nN; that is, t should be approximately equal to ((12ln 2)/7r2) In N. This constant (12 In 2)/T2 = 0.842765913. . . agrees perfectly with the empirical formula (48) obtained earlier, so we have good reason to believe that the formula 12ln2 7n Fz F Inn+ 1.47 (52) indicates the true asymptotic behavior of r12 as n + co. If we assume that (52) is valid, we obtain the formula 12ln2 T nM-Inn -zh(d)/d + 1.47, (53) IT2 dn > where A(d) is von Mangoldt s function defined by the rules if n = p for p prime and r 2 1; otherwise. (54)

Make a web site - 354 ARITHMETIC 4.5.3 It follows that (47) Here

Wednesday, February 13th, 2008

354 ARITHMETIC 4.5.3 It follows that (47) Here is a table of rn for the same values of n considered above: n = 95 96 97 98 99 100 101 102 103 104 105 7, = 5.4 5.3 5.3 5.6 5.2 5.2 5.4 5.3 5.4 5.3 5.6 n = 996 997 998 999 1000 1001 … 9999 10000 10001 7, = 7.2 7.3 7.3 7.3 7.3 7.4 .** 9.21 9.21 9.22 72,= 49999 50000 50001 … 99999 100000 100001 7, = 10.58 10.57 10.59 … 11.170 11.172 11.172 Clearly 7, is much more well-behaved than T,, and it should be more susceptible to analysis. Inspection of a table of 7, for small 72 reveals some curious anomalies; for example, 750 = 7100 and 760 = ~120. But as n grows, the values of T, behave quite regularly indeed, as the above table indicates, and they show no significant relation to the factorization properties of n. If the reader will plot the values of rn versus Inn on graph paper, for the values of 7, given above, he will see that the values lie very nearly on a straight line, and that the formula T, M 0.843lnn + 1.47 (48) is a very good approximation. We can account for this behavior if we study the regular continued fraction process a little further. Note that in Euclid s algorithm as expressed in (15) we have Since uk+i = vk; therefore if u = uo and V = VOare relatively prime, and if there are t division steps, we have x,x1 . . .X,-l = l/U. Setting U = N and V = m < N, we find that lnXo+lnX1+…+lnXt-r =-1nN. (49) We know the approximate distribution of X0, X1, X2, . . . , so we can use this equation to estimate t = T(N, m) = T(m, N) -1. Returning to the formulas preceding Theorem W, we find that the average value of lnX,, when X0 is a real number uniformly distributed in [ 0, l), is s 0 1 In z F:(z) da: = s 0 1 ln 5 f&) W(l + 4, (50)

Web hosting unlimited bandwidth - 4.5.3 ANALYSIS OF EUCLID S ALGORITHM 353 a) As

Wednesday, February 13th, 2008

4.5.3 ANALYSIS OF EUCLID S ALGORITHM 353 a) As mentioned earlier, the last quotient is always 2 or more. Furthermore, we have the obvious identity /a… , zn-1, zn + 1/ = 1×1, *. * ,2,-l, %, I/, (44 and this shows how partial fractions whose last quotient is unity are related to regular continued fractions. b) The values in the right-hand columns have a simple relationship to the values in the left-hand columns; can the reader see the correspondence before reading any further? The relevant identity is 1 -/zr, X2,. . . 1&J = /&Xl -19×2 ,…, &J; (45) see exercise 9. c) There is symmetry between left and right in the first two columns: If /AI,&… ,A,/ occurs, so does /At,. . . ,A2,Al/. This will always be the case (see exercise 26). d) If we examine all of the quotients in the table, we find that there are 96 in all, of which 8 = 40.6 percent are equal to 1, & = 21.9 percent are equal to 2, & = 8.3 percent are equal to 3; this agrees reasonably well with the probabilities listed above. The number of division steps. Let us now return to our original problem and investigate T,, the average number of division steps when v = n. (See Eq. (19).) Here are some sample values of T,: n= 95 96 97 98 99 100 101 102 103 104 105 Tn = 5.0 4.4 5.3 4.8 4.7 4.6 5.3 4.6 5.3 4.7 4.6 n = 996 997 998 999 1000 1001 ..a 9999 10000 10001 Tn = 6.5 7.3 7.0 6.8 6.4 6.7 ..a 8.6 8.3 9.1 n= 49999 50000 50001 *** 99999 100000 100001 Tn = 10.6 9.7 10.0 *a* 10.7 10.3 11.0 Note the somewhat erratic behavior; T, tends to be higher than its neighbors when n is prime, and it is correspondingly lower when n has many divisors. (In this list, 97, 101, 103, 997, and 49999 are primes; 10001 = 73 . 137, 50001 = 3.7.2381, 99999 = 3.3.41.271, and 100001 = 11.9091.) It is not difficult to understand why this happens: if gcd(u, V) = d, Euclid s algorithm applied to u and v behaves essentially the same as if it were applied to u/d and v/d. Therefore, when v = n has several divisors, there are many choices of u for which n behaves as if it were smaller. Accordingly let us consider another quantity, rn, which is the average num- ber of division steps when 2, = n and when u is relatively prime to n. Thus 7, = –& c T(m, n). (46) O~m

352 ARITHMETIC 4.5.3 Theorem E. Let n and (Virtual web hosting)

Tuesday, February 12th, 2008

352 ARITHMETIC 4.5.3 Theorem E. Let n and k be positive integers, and let pk(a, n) be the probability that the (k + 1)st quotient Ak+l in Euclid s algorithm is equal to a, when 2, = n and u is chosen at random. Then lim pk(a, n) = Fk n+co where Fk(z) is the distribution function (21). Proof. The set I of all X in [ 0,l) for which Ak+l = a is a union of disjoint intervals, and so is the set J of all X for which Ak+l # a. Lemma M therefore applies, with K the set of all X for which Ak+l is undefined. Furthermore, Fk(l/u) -Fk(l/(u + 1)) is the probability that l/(u + 1) < X, 2 l/u, which is p(I), the probability that Ak+l = a. 1 As a consequence of Theorems E and W, we can say that a quotient equal to a occurs with the approximate probability lg(l + l/a) - k(l + ll(a + 1,) =k@ + l) l((~ + v - 1)). Thus a quotient of 1 occurs about lg(f) = 41.504 percent of the time; a quotient of 2 occurs about lg($) = 16.992 percent of the time; a quotient of 3 occurs about lg($$) = 9.311 percent of the time; a quotient of 4 occurs about lg(g) = 5.890 percent of the time. Actually, if Euclid s algorithm produces the quotients Al, AZ, . . . , At, the nature of the proofs above will guarantee this behavior only for Ak when k is comparatively small with respect to t; the values At-l, At-z, . . . are not covered by this proof. But we can in fact show that the distribution of the last quotients At-l, At-z, . . . is essentially the same as the first. For example, consider the regular continued fraction expansions for the set of all proper fractions whose denominator is 29: &J = 1291 & =/3,1,1,&a/ &$ = /1,1,14/ g = /1,3,7/ &=/14,2/ &=/3,4,2/ i$ = /1,1,4,3/ $3 = / 1,3,L 5/ i$=/g,w +$=/2,1,9/ g = / 1, 1,2,2, a/ g = /1,4,1,4/ 2% = 17941 j-$ =/2,1,1,1,3/ # =/1,1,1,1,1,3/ @i =/1,6,4/ & = /5,1,4/ &j = /2,2,2,2/ % = /111,1,9/ j$ = / 1,&l, 2/ &=/4,1,5/ #=/2,4,3/ %I$= / 1,2,4,2/ g = / 1,13,2/ Jg = 14971 +j = / 2,14/ g = /1,2,1,1,1,2/ 3 = /1,28/ Several things can be observed in this table.

Bulletproof web design - 4.5.3 ANALYSIS OF EUCLID S ALGORITHM 351 Lemma M.

Monday, February 11th, 2008

4.5.3 ANALYSIS OF EUCLID S ALGORITHM 351 Lemma M. Let J1, Jz, . . . be pairwise disjoint isltervals contained in the interval [ 0,l IJ u Ik, J= u J/c, K = (0, 11 (I u J). ;k>l k>l Assume that K4as measure zero. Let P, be the set (O/n, l/n,. . . , (n -1)/n}. Then / lim III nPntI = p(I). n–+00 n (43) Here ~(1) is the qebesgue measure of I, namely, ck> 1 length(&); and III fl P,ll denotes the number of elements in the set 1 n P,. - Proof. Let IN 4= U l 0, find N large enough so that P( IN) -I- P( JN) 2 1 -E, and let KN=K u u Ik u u Jk. k>N k>N If I is an intervdl, having any of the forms (a, b) or [a, b) or (a, b] or [a, b], it is clear that ~(1) 4 b -a and v-44–l I lImPnIl 2 v-44+1. Now let TV = II& n Pm/l, sn = [[JN n Pnll, t, = IIKN n %(I; we have Hence = 1 -t 5 1 - /.L(JN) + X 5 p(I) j-z + E. This holds for al/ n and for all E; hence limn+,a, Tn/n = p(l). 1 I Exercise 25 hows that Lemma M is not trivial, in the sense that some rather restrictive hypot 1 eses are needed to prove (43). quotients. Now we can put Theorem W and Lemma M some solid facts about Euclid s algorithm.